首页>代码>spring+Struts2+mybatis+bootstrap整合开发元亨地产员工提成结算管理系统>/yuanheng1/YuanHeng3/src/com/yuanheng/action/ContractAction.java
package com.yuanheng.action;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;
import org.json.JSONObject;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import com.google.gson.Gson;
import com.opensymphony.xwork2.ActionSupport;
import com.yuanheng.pojo.Contract;
import com.yuanheng.pojo.ReturnedMoney;
import com.yuanheng.pojo.Shop;
import com.yuanheng.pojo.Staff;
import com.yuanheng.service.ContractService;
import com.yuanheng.service.ReturnedMoneyService;
import com.yuanheng.service.ShopService;
import com.yuanheng.service.StaffService;
import com.yuanheng.util.Constants;

public class ContractAction extends ActionSupport implements SessionAware,ServletResponseAware {
	private Map<String , Object> session = new HashMap<String , Object>();
	private javax.servlet.http.HttpServletResponse response;
	private List<Contract> contractList;
	private ContractService contractService;
	private ReturnedMoney  returnedMoney;
	private ReturnedMoneyService returnedMoneyService;
	private Contract contract;
	private Staff staff;
	private int page;
	private String pageUrl;
	private int pageSize = Constants.PAGE_SIZE;
	private List<ReturnedMoney> rMoney;
	private List<Shop> shops;
	private ShopService shopService;
	private StaffService staffService;
	private List<Staff> staffs;
	private Shop shop;
	
	
	public Shop getShop() {
		return shop;
	}

	public void setShop(Shop shop) {
		this.shop = shop;
	}

	public javax.servlet.http.HttpServletResponse getResponse() {
		return response;
	}

	public void setResponse(javax.servlet.http.HttpServletResponse response) {
		this.response = response;
	}
	
	

	
	public ReturnedMoneyService getReturnedMoneyService() {
		return returnedMoneyService;
	}

	public void setReturnedMoneyService(ReturnedMoneyService returnedMoneyService) {
		this.returnedMoneyService = returnedMoneyService;
	}

	public StaffService getStaffService() {
		return staffService;
	}

	public void setStaffService(StaffService staffService) {
		this.staffService = staffService;
	}

	public List<Staff> getStaffs() {
		return staffs;
	}

	public void setStaffs(List<Staff> staffs) {
		this.staffs = staffs;
	}

	public List<Shop> getShops() {
		return shops;
	}

	public void setShops(List<Shop> shops) {
		this.shops = shops;
	}

	public ShopService getShopService() {
		return shopService;
	}

	public void setShopService(ShopService shopService) {
		this.shopService = shopService;
	}

	public ReturnedMoney getReturnedMoney() {
		return returnedMoney;
	}

	public void setReturnedMoney(ReturnedMoney returnedMoney) {
		this.returnedMoney = returnedMoney;
	}

	public List<ReturnedMoney> getrMoney() {
		return rMoney;
	}

	public void setrMoney(List<ReturnedMoney> rMoney) {
		this.rMoney = rMoney;
	}

	public Staff getStaff() {
		return staff;
	}

	public void setStaff(Staff staff) {
		this.staff = staff;
	}

	public List<Contract> getContractList() {
		return contractList;
	}

	public void setContractList(List<Contract> contractList) {
		this.contractList = contractList;
	}

	public ContractService getContractService() {
		return contractService;
	}

	public void setContractService(ContractService contractService) {
		this.contractService = contractService;
	}

	public Contract getContract() {
		return contract;
	}

	public void setContract(Contract contract) {
		this.contract = contract;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public String getPageUrl() {
		return pageUrl;
	}

	public void setPageUrl(String pageUrl) {
		this.pageUrl = pageUrl;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public Map<String, Object> getSession() {
		return session;
	}

private static final long serialVersionUID = 1L;
	
	@Override
	public void setSession(Map<String, Object> session) {
		// TODO Auto-generated method stub
		this.session = session;
	}
	
	@Override
	public void setServletResponse(HttpServletResponse response) {
		// TODO Auto-generated method stub
		this.response = response;
	}	
	
	/**
	 * 调到添加合同页面
	 * @return
	 * @throws IOException
	 */
	public String addContract() throws IOException {
		staffs = staffService.selectList();
		shops = shopService.selectList();
		this.session.put(Constants.STAFFS_SESSION_NAME, staffs);
		this.session.put(Constants.HINT_SESSION_NAME, shops.size());
		this.session.put(Constants.SHOP_SESSION_NAME, shops);
		return SUCCESS;
	}
	
	/**
	 * 通过门店选取员工
	 * @throws IOException
	 */
	public void shopStaff() throws IOException {
		List<Staff> shopStaffs = new ArrayList<Staff>();
		shopStaffs = staffService.shopIdSelectStaff(shop.getShopId());
		Gson gson =  new Gson();
		String shopSaff = gson.toJson(shopStaffs);
		this.response.setContentType("text/html;charset=utf-8");
		this.response.getWriter().print(shopSaff);
	}
	
	public void StaffNamexs() throws IOException {
		Staff shopStaffs = new Staff();
		shopStaffs = staffService.selectOne(staff.getStaffId());
		Gson gson =  new Gson();
		String shopSaff = gson.toJson(shopStaffs);
		this.response.setContentType("text/html;charset=utf-8");
		this.response.getWriter().print(shopSaff);
	}
	
	/**
	 * 保存合同页面信息
	 * @return
	 * @throws IOException
	 */
	public String addContractSave() throws IOException {
		System.out.println("查看提交时候有没有调用这个方法");
		this.response.setContentType("text/html;charset=utf-8");
		HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
				.getRequest();
		String qdryjgh[] = request.getParameterValues("qdryjgh");
		String qdryjmc[] = request.getParameterValues("qdryjmc");
		String qdryjje[] = request.getParameterValues("qdryjje");
		String qdrqdsj[] = request.getParameterValues("qdrqdsj");
		String qdrlx[] = request.getParameterValues("qdrlx");
		if (qdryjgh == null ) {
			contract.setRepeal(1);
			System.out.println("这个是合同的基本信息:"+contract);
			this.contractService.insertOne(this.contract);	
		}else{
		for (int i = 0; i < qdryjgh.length; i++) {
			ReturnedMoney rMoney2 = new ReturnedMoney();
			//转换数据
			Long[] staffId = new Long[qdryjgh.length];
			staffId[i] = Long.valueOf(qdryjgh[i]);
			
			Double[] staffMoney = new Double[qdryjje.length];
			staffMoney[i] = Double.valueOf(qdryjje[i]);
			
			int[] staffTtpe = new int[qdrlx.length];
			staffTtpe[i] = Integer.valueOf(qdrlx[i]);
			//赋值
			rMoney2.setStaffId(staffId[i]);
			rMoney2.setReturnedMoneyName(qdryjmc[i]);
			rMoney2.setTime(qdrqdsj[i]);
			rMoney2.setStaffType(staffTtpe[i]);
			rMoney2.setStaffMoney(staffMoney[i]);
			rMoney2.setContractNumber(contract.getContractNumber());
			returnedMoneyService.insertOne(rMoney2);
		}
		
		contract.setRepeal(1);
		System.out.println("这个是合同的基本信息:"+contract);
		this.contractService.insertOne(this.contract);	
		}
		return SUCCESS;
	} 
	
	/**
	 * 合同分页
	 * @return
	 */
	public String contractList(){
		String condition = "";
		if(this.contract == null){
			this.contract = new Contract();
		}
		if(this.contract == null || this.contract.getContractId() == 0){
			condition = "order by contractId desc ";
		}else{
			condition = "order by contractId desc ";
		}
		if(this.page == 0){
			this.page = 1;
		}
		int rowCount = this.contractService.selectRowCount(condition);
		this.contractList = this.contractService.selectListByCondition(condition, this.page, this.pageSize);
		int pageCount = rowCount % this.pageSize == 0 ? rowCount / this.pageSize : rowCount / this.pageSize + 1 ;
		this.pageUrl = "";
		String previousUrl = "";
		String nextUrl = "";
		String lastUrl = "";
		String firstUrl = "";
		if(pageCount > 0){
			if(this.page == 1){
				lastUrl = "<a href='contractList.action?page="+ pageCount + "'>最后一页</a>&nbsp;&nbsp;";
				nextUrl = "<a href='contractList.action?page=" + (this.page + 1) +  "'>下一页</a>&nbsp;&nbsp;";
				firstUrl = "<a>第一页</a>&nbsp;&nbsp;";
				previousUrl = "<a>上一页</a>&nbsp;&nbsp;";
			}else if(this.page == pageCount){
				firstUrl = "<a href='contractList.action?page=1'>第一页</a>&nbsp;&nbsp;";
				previousUrl = "<a href='contractList.action?page=" + (this.page - 1) +  "'>上一页</a>&nbsp;&nbsp;";
				lastUrl = "<a>最后一页</a>&nbsp;&nbsp;";
				nextUrl = "<a>下一页</a>&nbsp;&nbsp;";
			}else{
				firstUrl = "<a href='contractList.action?page=1'>第一页</a>&nbsp;&nbsp;";
				previousUrl = "<a href='contractList.action?page=" + (this.page - 1) + "'>上一页</a>&nbsp;&nbsp;";
				lastUrl = "<a href='contractList.action?page="+ pageCount + "'>最后一页</a>&nbsp;&nbsp;";
				nextUrl = "<a href='contractList.action?page=" + (this.page + 1) + "'>下一页</a>&nbsp;&nbsp;";
			}
			this.pageUrl = "当前第" + this.page + "页,共" + pageCount + "页&nbsp;&nbsp;";
		}
		this.pageUrl = this.pageUrl + firstUrl + previousUrl + nextUrl + lastUrl;
		this.session.put(Constants.PAGEURL_SESSION_NAME, pageUrl);
		this.session.put(Constants.CONTRACT_SESSION_NAME, contractList);
		return SUCCESS;
	}
	
	/**
	 * 更新合同页面
	 * @return
	 */
	public String contractUpdate(){
		List<ReturnedMoney> returnedMoneyList = new ArrayList<ReturnedMoney>();
		this.contract = this.contractService.selectOne(contract.getContractNumber());
		returnedMoneyList = this.returnedMoneyService.contractNumberselectList(contract.getContractNumber());
		this.session.put(Constants.CONTRACT_SESSION_NAME,contract );
		this.session.put(Constants.RETURNEDMONEY_SESSION_NAME,returnedMoneyList );
		return "success";
		
	}
	/**
	 * 更新保存合同页面信息
	 * @return
	 */
	public String contractUpdateSave()throws IOException {
		System.out.println("查看提交时候有没有调用这个方法");
		this.response.setContentType("text/html;charset=utf-8");
		HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
				.getRequest();
		String qdryjgh[] = request.getParameterValues("qdryjgh");
		String qdryjmc[] = request.getParameterValues("qdryjmc");
		String qdryjje[] = request.getParameterValues("qdryjje");
		String qdrqdsj[] = request.getParameterValues("qdrqdsj");
		String qdrlx[] = request.getParameterValues("qdrlx");
		if (qdryjgh == null ) {
			contract.setRepeal(1);
			System.out.println("这个是合同的基本信息:"+contract);
			this.contractService.insertOne(this.contract);	
		}else{
			returnedMoneyService.deleteContract(contract.getContractNumber());
			for (int i = 0; i < qdryjgh.length; i++) {
				ReturnedMoney rMoney2 = new ReturnedMoney();
				//转换数据
				Long[] staffId = new Long[qdryjgh.length];
				staffId[i] = Long.valueOf(qdryjgh[i]);
				
				Double[] staffMoney = new Double[qdryjje.length];
				staffMoney[i] = Double.valueOf(qdryjje[i]);
				
				int[] staffTtpe = new int[qdrlx.length];
				staffTtpe[i] = Integer.valueOf(qdrlx[i]);
				//赋值
				rMoney2.setStaffId(staffId[i]);
				rMoney2.setReturnedMoneyName(qdryjmc[i]);
				rMoney2.setTime(qdrqdsj[i]);
				rMoney2.setStaffType(staffTtpe[i]);
				rMoney2.setStaffMoney(staffMoney[i]);
				rMoney2.setContractNumber(contract.getContractNumber());
				System.out.println(rMoney2);
				returnedMoneyService.insertOne(rMoney2);
			}
		}
		this.contractService.updateOne(contract);
		return "success";
	}
	
	/**
	 * 删除合同信息
	 * @return
	 */
	public String contractDelete(){
		this.contractService.deleteOne(this.contract.getContractId());
		return "success";
	}
	
	/**
	 * 通过合同编号模糊查询合同信息
	 * @return
	 */
	public String selectByKeywordContract(){
		String keyword = this.contract.getContractNumber();
		this.contractList= this.contractService.selectByKeyword(keyword);
		this.session.put(Constants.CONTRACT_SESSION_NAME, contractList);
		return "success";
	}
	
}
最近下载更多
fesfefe  LV13 2024年2月5日
171337601  LV9 2022年4月18日
HONG SIR  LV8 2022年3月10日
wanglinddad  LV55 2021年12月14日
dwadawd  LV7 2021年5月17日
zhangjilu  LV18 2020年8月28日
大丁丁  LV5 2020年6月26日
xuweisong2010  LV28 2020年6月11日
一世轻歌  LV11 2020年6月5日
一三四  LV2 2020年5月20日
最近浏览更多
fesfefe  LV13 2024年1月28日
WBelong  LV8 2023年12月27日
政政123456  LV3 2023年10月22日
vilychan  LV2 2023年9月8日
阳光男孩阿葵 2023年7月14日
暂无贡献等级
171337601  LV9 2023年6月28日
tianyuboy111  LV3 2023年5月20日
喝喝XYZo  LV2 2023年4月17日
康日澜  LV9 2023年4月12日
泓鼎168  LV20 2023年3月31日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友