首页>代码>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> ";
nextUrl = "<a href='contractList.action?page=" + (this.page + 1) + "'>下一页</a> ";
firstUrl = "<a>第一页</a> ";
previousUrl = "<a>上一页</a> ";
}else if(this.page == pageCount){
firstUrl = "<a href='contractList.action?page=1'>第一页</a> ";
previousUrl = "<a href='contractList.action?page=" + (this.page - 1) + "'>上一页</a> ";
lastUrl = "<a>最后一页</a> ";
nextUrl = "<a>下一页</a> ";
}else{
firstUrl = "<a href='contractList.action?page=1'>第一页</a> ";
previousUrl = "<a href='contractList.action?page=" + (this.page - 1) + "'>上一页</a> ";
lastUrl = "<a href='contractList.action?page="+ pageCount + "'>最后一页</a> ";
nextUrl = "<a href='contractList.action?page=" + (this.page + 1) + "'>下一页</a> ";
}
this.pageUrl = "当前第" + this.page + "页,共" + pageCount + "页 ";
}
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";
}
}

最近下载
最近浏览