package cn.com.lzt.contractsale.controller; import cn.com.lzt.common.controller.BaseLztController; import cn.com.lzt.common.util.DictUtil; import cn.com.lzt.common.util.LztUtil; import cn.com.lzt.common.view.JsonDataModelAndView; import cn.com.lzt.contractsale.entity.ContractSaleEntity; import cn.com.lzt.contractsale.page.ContractSalePage; import cn.com.lzt.contractsale.service.ContractSaleServiceI; import cn.com.lzt.contractsaleitem.entity.ContractSaleItemEntity; import cn.com.lzt.project.entity.ProjectEntity; import cn.com.lzt.project.service.ProjectServiceI; import cn.com.lzt.tools.DecimalUtils; import cn.com.lzt.workflow.service.WorkflowServiceI; import com.xcgl.utils.OrderNumTools; import com.xcgl.utils.XcglDateUtils; import com.xcgl.weixin.entity.WXAjaxJson; import org.apache.commons.lang.xwork.StringUtils; import org.apache.log4j.Logger; import org.jeecgframework.core.beanvalidator.BeanValidators; import org.jeecgframework.core.common.exception.BusinessException; import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery; import org.jeecgframework.core.common.model.json.AjaxJson; import org.jeecgframework.core.common.model.json.DataGrid; import org.jeecgframework.core.constant.Globals; import org.jeecgframework.core.util.*; import org.jeecgframework.poi.excel.ExcelImportUtil; import org.jeecgframework.poi.excel.entity.ExportParams; import org.jeecgframework.poi.excel.entity.ImportParams; import org.jeecgframework.poi.excel.entity.vo.NormalExcelConstants; import org.jeecgframework.tag.core.easyui.TagUtil; import org.jeecgframework.tag.vo.datatable.SortDirection; import org.jeecgframework.web.system.pojo.base.TSUser; import org.jeecgframework.web.system.service.SystemService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartHttpServletRequest; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.util.UriComponentsBuilder; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.validation.ConstraintViolation; import javax.validation.Validator; import java.io.IOException; import java.net.URI; import java.text.ParseException; import java.util.*; /** * @Title: Controller * @Description: 销售合同 * @author onlineGenerator * @date 2019-05-09 17:25:32 * @version V1.0 * */ @Controller @RequestMapping("/contractSaleController") public class ContractSaleController extends BaseLztController { /** * Logger for this class */ private static final Logger logger = Logger.getLogger(ContractSaleController.class); @Autowired private ContractSaleServiceI contractSaleService; @Autowired private SystemService systemService; @Autowired private Validator validator; @Autowired private WorkflowServiceI workflowService; @Autowired private ProjectServiceI projectServiceI; /** * 销售合同列表 页面跳转 * * @return */ @RequestMapping(params = "list") public ModelAndView list(HttpServletRequest request) { return new ModelAndView("cn/com/lzt/contractsale/contractSaleList"); } /** * easyui AJAX请求数据 * * @param request * @param response * @param dataGrid * @param user */ @RequestMapping(params = "datagrid") public void datagrid(ContractSaleEntity contractSale,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) { String containAdd = request.getParameter("containAdd"); String zone = request.getParameter("zone") ; CriteriaQuery cq = new CriteriaQuery(ContractSaleEntity.class, dataGrid); String contractCode = request.getParameter("code"); String contractName = request.getParameter("name"); String contractDescription = request.getParameter("description"); //清除项目名称,此名称设置为了简称 contractSale.setProjectname(null); contractSale.setType(Globals.CONTRACT_TYPE_SALE); //查询条件组装器 if(StringUtils.isNotBlank(contractCode)){ //模糊查询 cq.like("code", "%"+contractCode+"%"); contractSale.setCode(null); } if(StringUtils.isNotBlank(contractName)){ //模糊查询 cq.like("name", "%"+contractName+"%"); contractSale.setName(null); } if(StringUtils.isNotBlank(contractDescription)){ //模糊查询 cq.like("description", "%"+contractDescription+"%"); contractSale.setDescription(null); } if(StringUtils.isNotEmpty(zone)) { List projectid = systemService.findListbySql("select id from t_b_project where zone = '"+zone+"'"); if(projectid.size() > 0) { cq.in("projectid", projectid.toArray()); }else { cq.eq("projectid", "##"); } } String endDateMonth = request.getParameter("endDateMonth"); if(StringUtils.isNotBlank(endDateMonth)){ try { Date endMonth = DateUtils.parseDate(endDateMonth,"yyyy-MM"); Calendar c = Calendar.getInstance(); c.setTime(endMonth); c.set(Calendar.DAY_OF_MONTH,1); Date endDateBegin = c.getTime(); c.add(Calendar.MONTH,1); c.add(Calendar.MILLISECOND,-1); Date endDateEnd = c.getTime(); cq.ge("enddate",endDateBegin); cq.le("enddate",endDateEnd); } catch (ParseException e) { e.printStackTrace(); } } //查询条件组装器 org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, contractSale); try{ String isproject = request.getParameter("isproject"); if(StringUtils.isNotEmpty(isproject)) { //增加权限处理 TSUser user = ResourceUtil.getSessionUser(); // 所属项目及兼职项目id List projectList = projectServiceI.getProjectsByUserid(user.getId()); cq.in("projectid", projectList.toArray()); } //自定义追加查询条件 }catch (Exception e) { throw new BusinessException(e.getMessage()); } cq.add(); this.contractSaleService.getDataGridReturn(cq, true); if(StringUtils.isNotEmpty(containAdd) && containAdd.equals("1")) { String addAmountSql = "select contractid,sum(ifnull(addamount,0)) as addamount from t_b_contract_sale where type = '"+Globals.CONTRACT_TYPE_SALE_ADDING+"' group by contractid"; List> amountRes = systemService.findForJdbc(addAmountSql); HashMap addMap = new HashMap(); for(Map value:amountRes) { if(value.get("contractid") != null) addMap.put(value.get("contractid").toString(),Double.valueOf(value.get("addamount").toString())); } List result = dataGrid.getResults(); for(ContractSaleEntity contract: result) { if(addMap.containsKey(contract.getId())) { contract.setTotaladd(addMap.get(contract.getId())); }else { contract.setTotaladd(DecimalUtils.ZERO); } contract.setTotaladdandamount(contract.getTotalamount()+contract.getTotaladd()); } } dataGrid.setFooter("code:合计,totaladdandamount"); TagUtil.datagrid(response, dataGrid); } /** * 删除销售合同 * * @return */ @RequestMapping(params = "doDel") @ResponseBody public AjaxJson doDel(ContractSaleEntity contractSale, HttpServletRequest request) { AjaxJson j = new AjaxJson(); contractSale = systemService.getEntity(ContractSaleEntity.class, contractSale.getId()); String message = "销售合同删除成功"; try{ contractSaleService.delMain(contractSale); systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO); }catch(Exception e){ e.printStackTrace(); message = "销售合同删除失败"; throw new BusinessException(e.getMessage()); } j.setMsg(message); return j; } /** * 批量删除销售合同 * * @return */ @RequestMapping(params = "doBatchDel") @ResponseBody public AjaxJson doBatchDel(String ids,HttpServletRequest request){ AjaxJson j = new AjaxJson(); String message = "销售合同删除成功"; try{ for(String id:ids.split(",")){ ContractSaleEntity contractSale = systemService.getEntity(ContractSaleEntity.class, id ); contractSaleService.delMain(contractSale); systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO); } }catch(Exception e){ e.printStackTrace(); message = "销售合同删除失败"; throw new BusinessException(e.getMessage()); } j.setMsg(message); return j; } /** * 添加销售合同 * * @param ids * @return */ @RequestMapping(params = "doAdd") @ResponseBody public AjaxJson doAdd(ContractSaleEntity contractSale,ContractSalePage contractSalePage, HttpServletRequest request) { List contractSaleItemList = contractSalePage.getContractSaleItemList(); AjaxJson j = new AjaxJson(); contractSale.setName(contractSale.getName().trim()); String message = "添加成功"; try{ //设置合同初始状态为已签订 contractSale.setBusstatus(Globals.CONTRACT_STATUS_SIGN); //设置合同类型为外包合同 if(StringUtils.isEmpty(contractSale.getType())) { contractSale.setType(Globals.CONTRACT_TYPE_SALE); } //清除合同名中的空格,可能是由于从其他文件复制文本导致 contractSale.setName(contractSale.getName().trim()); contractSale.setTotalincome(DecimalUtils.ZERO); contractSale.setTotalinvoice(DecimalUtils.ZERO); //如果合同编码为空,则按照编码规则设置默认编码(合同编码可编辑,用户签订合同时,合同上可能已经有编码) if(StringUtil.isEmpty(contractSale.getCode())) { contractSale.setCode(OrderNumTools.generateNextBillCode(Globals.CODE_PREFIX_CONTRACT_SALE,"t_b_contract_sale","code",4)); } contractSaleService.addMain(contractSale, contractSaleItemList); systemService.addLog(message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO); }catch(Exception e){ e.printStackTrace(); message = "销售合同添加失败"; throw new BusinessException(e.getMessage()); } j.setMsg(message); return j; } /** * 更新销售合同 * * @param ids * @return */ @RequestMapping(params = "doUpdate") @ResponseBody public AjaxJson doUpdate(ContractSaleEntity contractSale,ContractSalePage contractSalePage, HttpServletRequest request) { //清除合同名中的空格,可能是由于从其他文件复制文本导致 contractSale.setName(contractSale.getName().trim()); List contractSaleItemList = contractSalePage.getContractSaleItemList(); AjaxJson j = new AjaxJson(); String message = "更新成功"; try{ contractSaleService.updateMain(contractSale, contractSaleItemList); systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO); }catch(Exception e){ e.printStackTrace(); message = "更新销售合同失败"; throw new BusinessException(e.getMessage()); } j.setMsg(message); return j; } /** * 销售合同新增页面跳转 * * @return */ @RequestMapping(params = "goAdd") public ModelAndView goAdd(ContractSaleEntity contractSale, HttpServletRequest req) { if (StringUtil.isNotEmpty(contractSale.getId())) { contractSale = contractSaleService.getEntity(ContractSaleEntity.class, contractSale.getId()); contractSale.setType(Globals.CONTRACT_TYPE_SALE); }else { contractSale.setPaytype("Quarterly"); contractSale.setType(Globals.CONTRACT_TYPE_SALE); contractSale.setCanExe(Globals.YES); } req.setAttribute("contractSalePage", contractSale); return new ModelAndView("cn/com/lzt/contractsale/contractSale-add"); } /** * 销售合同编辑页面跳转 * * @return */ @RequestMapping(params = "goUpdate") public ModelAndView goUpdate(ContractSaleEntity contractSale, HttpServletRequest req) { if (StringUtil.isNotEmpty(contractSale.getId())) { contractSale = contractSaleService.getEntity(ContractSaleEntity.class, contractSale.getId()); req.setAttribute("contractSalePage", contractSale); } return new ModelAndView("cn/com/lzt/contractsale/contractSale-update"); } /** * 加载明细列表[服务明细] * * @return */ @RequestMapping(params = "contractSaleItemList") public ModelAndView contractSaleItemList(ContractSaleEntity contractSale, HttpServletRequest req) { //=================================================================================== //获取参数 String id0 = contractSale.getId(); String oralContractId = req.getParameter("oralContractId"); //=================================================================================== try{ String hql0 = "from ContractSaleItemEntity where 1 = 1 AND cONTRACTID =? "; //查询-服务明细 if(StringUtils.isNotEmpty(id0)) { List contractSaleItemEntityList = systemService.findHql(hql0,id0); req.setAttribute("contractSaleItemList", contractSaleItemEntityList); }else if(StringUtils.isNotEmpty(oralContractId)) { List contractSaleItemEntityList = systemService.findHql(hql0,oralContractId); req.setAttribute("contractSaleItemList", contractSaleItemEntityList); } }catch(Exception e){ logger.info(e.getMessage()); } return new ModelAndView("cn/com/lzt/contractsaleitem/contractSaleItemList"); } /** * 导出excel * * @param request * @param response */ @RequestMapping(params = "exportXls") public String exportXls(ContractSaleEntity contractSale,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid,ModelMap map) { CriteriaQuery cq = new CriteriaQuery(ContractSaleEntity.class, dataGrid); String contractCode = request.getParameter("code"); String contractName = request.getParameter("name"); String contractDescription = request.getParameter("description"); contractSale.setType(Globals.CONTRACT_TYPE_SALE); //查询条件组装器 if(StringUtils.isNotBlank(contractCode)){ //模糊查询 cq.like("code", "%"+contractCode+"%"); contractSale.setCode(null); } if(StringUtils.isNotBlank(contractName)){ //模糊查询 cq.like("name", "%"+contractName+"%"); contractSale.setName(null); } if(StringUtils.isNotBlank(contractDescription)){ //模糊查询 cq.like("description", "%"+contractDescription+"%"); contractSale.setDescription(null); } //查询条件组装器 org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, contractSale); try{ String isproject = request.getParameter("isproject"); if(StringUtils.isNotEmpty(isproject)) { //增加权限处理 TSUser user = ResourceUtil.getSessionUser(); // 所属项目及兼职项目id List projectList = projectServiceI.getProjectsByUserid(user.getId()); cq.in("projectid", projectList.toArray()); } //自定义追加查询条件 }catch (Exception e) { throw new BusinessException(e.getMessage()); } cq.addOrder("startdate", SortDirection.desc); cq.add(); List list=this.contractSaleService.getListByCriteriaQuery(cq, false); // 增加:补充协议金额 String addAmountSql = "select contractid,sum(ifnull(addamount,0)) as addamount from t_b_contract_sale where type = '"+Globals.CONTRACT_TYPE_SALE_ADDING+"' group by contractid"; List> amountRes = systemService.findForJdbc(addAmountSql); HashMap addMap = new HashMap(); for(Map value:amountRes) { if(value.get("contractid") != null) addMap.put(value.get("contractid").toString(),Double.valueOf(value.get("addamount").toString())); } for(ContractSaleEntity contract: list) { if(addMap.containsKey(contract.getId())) { contract.setTotaladd(addMap.get(contract.getId())); }else { contract.setTotaladd(DecimalUtils.ZERO); } contract.setTotaladdandamount(contract.getTotalamount()+contract.getTotaladd()); } map.put(NormalExcelConstants.FILE_NAME,"销售合同"+DateUtils.yyyymmddhhmmss.format(new Date())); map.put(NormalExcelConstants.CLASS,ContractSaleEntity.class); map.put(NormalExcelConstants.PARAMS,new ExportParams("销售合同列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(), "导出信息")); map.put(NormalExcelConstants.DATA_LIST,list); return NormalExcelConstants.JEECG_EXCEL_VIEW; } /** * 通过excel导入数据 * @param request * @param * @return */ @RequestMapping(params = "importExcel", method = RequestMethod.POST) @ResponseBody public AjaxJson importExcel(HttpServletRequest request, HttpServletResponse response) { AjaxJson j = new AjaxJson(); MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; Map fileMap = multipartRequest.getFileMap(); for (Map.Entry entity : fileMap.entrySet()) { MultipartFile file = entity.getValue();// 获取上传文件对象 ImportParams params = new ImportParams(); params.setTitleRows(2); params.setHeadRows(2); params.setNeedSave(true); try { List list = ExcelImportUtil.importExcel(file.getInputStream(), ContractSalePage.class, params); ContractSaleEntity entity1=null; for (ContractSalePage page : list) { entity1=new ContractSaleEntity(); MyBeanUtils.copyBeanNotNull2Bean(page,entity1); contractSaleService.addMain(entity1, page.getContractSaleItemList()); } j.setMsg("文件导入成功!"); } catch (Exception e) { j.setMsg("文件导入失败!"); logger.error(ExceptionUtil.getExceptionMessage(e)); }finally{ try { file.getInputStream().close(); } catch (IOException e) { e.printStackTrace(); } } } return j; } /** * 导出excel 使模板 */ @RequestMapping(params = "exportXlsByT") public String exportXlsByT(ModelMap map) { map.put(NormalExcelConstants.FILE_NAME,"销售合同"); map.put(NormalExcelConstants.CLASS,ContractSalePage.class); map.put(NormalExcelConstants.PARAMS,new ExportParams("销售合同列表", "导出人:"+ ResourceUtil.getSessionUser().getRealName(), "导出信息")); map.put(NormalExcelConstants.DATA_LIST,new ArrayList()); return NormalExcelConstants.JEECG_EXCEL_VIEW; } /** * 导入功能跳转 * * @return */ @RequestMapping(params = "upload") public ModelAndView upload(HttpServletRequest req) { req.setAttribute("controller_name", "contractSaleController"); return new ModelAndView("common/upload/pub_excel_upload"); } @RequestMapping(method = RequestMethod.GET) @ResponseBody public List list() { List listContractSales=contractSaleService.getList(ContractSaleEntity.class); return listContractSales; } @RequestMapping(value = "/{id}", method = RequestMethod.GET) @ResponseBody public ResponseEntity get(@PathVariable("id") String id) { ContractSaleEntity task = contractSaleService.get(ContractSaleEntity.class, id); if (task == null) { return new ResponseEntity(HttpStatus.NOT_FOUND); } return new ResponseEntity(task, HttpStatus.OK); } @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public ResponseEntity create(@RequestBody ContractSalePage contractSalePage, UriComponentsBuilder uriBuilder) { //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息. Set> failures = validator.validate(contractSalePage); if (!failures.isEmpty()) { return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST); } //保存 List contractSaleItemList = contractSalePage.getContractSaleItemList(); ContractSaleEntity contractSale = new ContractSaleEntity(); try{ MyBeanUtils.copyBeanNotNull2Bean(contractSale,contractSalePage); }catch(Exception e){ logger.info(e.getMessage()); } contractSaleService.addMain(contractSale, contractSaleItemList); //按照Restful风格约定,创建指向新任务的url, 也可以直接返回id或对象. String id = contractSalePage.getId(); URI uri = uriBuilder.path("/rest/contractSaleController/" + id).build().toUri(); HttpHeaders headers = new HttpHeaders(); headers.setLocation(uri); return new ResponseEntity(headers, HttpStatus.CREATED); } @RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity update(@RequestBody ContractSalePage contractSalePage) { //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息. Set> failures = validator.validate(contractSalePage); if (!failures.isEmpty()) { return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST); } //保存 List contractSaleItemList = contractSalePage.getContractSaleItemList(); ContractSaleEntity contractSale = new ContractSaleEntity(); try{ MyBeanUtils.copyBeanNotNull2Bean(contractSale,contractSalePage); }catch(Exception e){ logger.info(e.getMessage()); } contractSaleService.updateMain(contractSale, contractSaleItemList); //按Restful约定,返回204状态码, 无内容. 也可以返回200状态码. return new ResponseEntity(HttpStatus.NO_CONTENT); } @RequestMapping(value = "/{id}", method = RequestMethod.DELETE) @ResponseStatus(HttpStatus.NO_CONTENT) public void delete(@PathVariable("id") String id) { ContractSaleEntity contractSale = contractSaleService.get(ContractSaleEntity.class, id); contractSaleService.delMain(contractSale); } @RequestMapping(params = "goView") public ModelAndView goView(ContractSaleEntity contract, HttpServletRequest request) { String taskId = request.getParameter("taskId"); //【我发起的流程】-【详情】中查看业务数据时,只看单据信息,不预览审批流程 if(StringUtils.isEmpty(taskId)) { contract = contractSaleService.getEntity(ContractSaleEntity.class, contract.getId()); request.setAttribute("contractSalePage", contract); request.setAttribute("viewFlag", "1"); return new ModelAndView("cn/com/lzt/contractsale/contractSale-update"); } request.setAttribute("url", "contractSaleController.do?goUpdate&load=detail&id="+workflowService.getBpmDataId(taskId)); Map taskDetails = workflowService.getTaskDetails(taskId); request.setAttribute("busititle", "销售合同详细信息"); request.setAttribute("id", workflowService.getBpmDataId(taskId)); request.setAttribute("bpmLogList", taskDetails.get("bpmLogList")); request.setAttribute("taskId", taskDetails.get("taskId")); request.setAttribute("taskName", taskDetails.get("taskName")); request.setAttribute("task", taskDetails.get("task")); request.setAttribute("transitionList", taskDetails.get("transitionList")); request.setAttribute("nextCodeCount", taskDetails.get("nextCodeCount")); request.setAttribute("bpmLogListCount", taskDetails.get("bpmLogListCount")); request.setAttribute("bpmLogNewList", taskDetails.get("bpmLogNewList")); request.setAttribute("bpmLogNewListCount", taskDetails.get("bpmLogNewListCount")); request.setAttribute("histListNode", taskDetails.get("histListNode")); request.setAttribute("histListSize", taskDetails.get("histListSize")); request.setAttribute("turnbackTaskId", taskDetails.get("turnbackTaskId")); request.setAttribute("height", "678px"); return new ModelAndView("cn/com/lzt/workflow/task-option"); } @RequestMapping(params = "goUpdateMobile") public ModelAndView goUpdateMobile(ContractSaleEntity contract, HttpServletRequest req) { if (StringUtil.isNotEmpty(contract.getId())) { contract = contractSaleService.getEntity(ContractSaleEntity.class, contract.getId()); ContractSaleEntity contractPage = new ContractSaleEntity(); try { MyBeanUtils.copyBeanNotNull2Bean(contract, contractPage); }catch (Exception e) { logger.error(e.getMessage()); } if(StringUtil.isNotEmpty(contractPage.getProjectid())) { contractPage.setProjectname(((ProjectEntity)systemService.getEntity(ProjectEntity.class, contractPage.getProjectid())).getAbbreviation()); } //重新设置字典,前台得到名称 contractPage.setPaytype(DictUtil.formatToTypeName(contractPage.getPaytype(),"paymode")); contractPage.setServicecontent(DictUtil.formatToTypeName(contractPage.getServicecontent(),"servicetype")); req.setAttribute("entity", contractPage); } Map data = LztUtil.copyReqAttributes(new String[]{ "entity"}); return new JsonDataModelAndView(WXAjaxJson.success(data)); } /** * 选择合同列表界面 * 应用场景:支付申请时,先选择合同 * */ @RequestMapping(params = "selectlist") public ModelAndView selectlist(HttpServletRequest request) { return new ModelAndView("cn/com/lzt/contractsale/selectContractList"); } /** * 选择合同列表加载数据 * 应用场景:支付申请时,先选择合同 * */ @RequestMapping(params = "selRefDatagridByUser") public void selRefDatagridByUser(ContractSaleEntity contractSale,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) { CriteriaQuery cq = new CriteriaQuery(ContractSaleEntity.class, dataGrid); TSUser user = ResourceUtil.getSessionUser(); //@TODO 查询用户所属角色,财务、行政角色可以查询所有合同 //@TODO 先查询出所有此用户所属项目,包括所属项目和兼职项目 String roleSql = "select rolecode from t_s_role where id in (select roleid from t_s_role_user where userid = ?)"; List> roleMapList = systemService.findForJdbc(roleSql, user.getId()); String roles = ""; if(roleMapList != null && roleMapList.size()>0) { for (Map roleMap :roleMapList) { roles += (roleMap.get("rolecode").toString()+","); } } if(roles.indexOf("admin") == -1 && (roles.indexOf("P_XMNQ,") > -1 //项目内勤 || roles.indexOf("P_XMJL,") > -1)/*项目经理*/) { // 所属项目及兼职项目id List projectList = projectServiceI.getProjectsByUserid(user.getId()); cq.in("projectid", projectList.toArray()); } String contractCode = request.getParameter("code"); String contractName = request.getParameter("name"); String contractDescription = request.getParameter("description"); String projectname = request.getParameter("projectname"); String customername = request.getParameter("customername"); contractSale.setType(Globals.CONTRACT_TYPE_SALE); //查询条件组装器 if(StringUtils.isNotBlank(contractCode)){ //模糊查询 cq.like("code", "%"+contractCode+"%"); contractSale.setCode(null); } if(StringUtils.isNotBlank(contractName)){ //模糊查询 cq.like("name", "%"+contractName+"%"); contractSale.setName(null); } if(StringUtils.isNotBlank(contractDescription)){ //模糊查询 cq.like("description", "%"+contractDescription+"%"); contractSale.setDescription(null); } if(StringUtils.isNotBlank(projectname)){ //模糊查询 cq.like("projectname", "%"+projectname+"%"); contractSale.setProjectname(null); } if(StringUtils.isNotBlank(customername)){ //模糊查询 cq.like("customername", "%"+customername+"%"); contractSale.setCustomername(null); } contractSale.setBpmStatus(Globals.BPM_STATUS_FINISHED.toString()); //contractSale.setBusstatus(Globals.CONTRACT_STATUS_ACTIVE); contractSale.setType(Globals.CONTRACT_TYPE_SALE); contractSale.setCanExe(Globals.YES); cq.add(); //查询条件组装器 org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, contractSale); try{ //自定义追加查询条件 }catch (Exception e) { throw new BusinessException(e.getMessage()); } this.contractSaleService.getDataGridReturn(cq, true); TagUtil.datagrid(response, dataGrid); // // String contractCode = request.getParameter("code"); // String contractName = request.getParameter("name"); // String contractDescription = request.getParameter("description"); // String contractProject = request.getParameter("projectid"); // String contractCustomer = request.getParameter("customerid"); // String contractStartDate_begin = request.getParameter("startdate_begin"); // String contractStartDate_end = request.getParameter("startdate_end"); // StringBuffer sbCondition = new StringBuffer(); // //默认查询条件 // sbCondition.append(" bpmStatus = '") // .append(Globals.BPM_STATUS_FINISHED) // .append("' and busstatus = '") // .append(Globals.CONTRCAT_STATUS_ACTIVE) // .append("' ") // .append(" and type = '") // .append(Globals.CONTRCAT_TYPE_SALE) // .append("' ");; // // //查询条件组装器 // //模糊查询 // if(StringUtils.isNotBlank(contractCode)){ // sbCondition.append(" and code like '").append(contractCode).append("'"); // } // if(StringUtils.isNotBlank(contractName)){ // sbCondition.append(" and name like '").append(contractName).append("'"); // } // if(StringUtils.isNotBlank(contractDescription)){ // sbCondition.append(" and description like '").append(contractDescription).append("'"); // } // String hql0 = "from ContractSaleEntity where "+sbCondition.toString() +" order by startdate desc"; // List contractList = systemService.findHql(hql0); // dataGrid.setResults(contractList); // TagUtil.datagrid(response, dataGrid); } /** * 销售合同列表 :运营部使用 * * @return */ @RequestMapping(params = "list4Shangwu") public ModelAndView list4Yunying(HttpServletRequest request) { return new ModelAndView("cn/com/lzt/contractsale/contractSaleList4Shangwu"); } /** * 销售合同列表 :运营部使用 * * @return */ @RequestMapping(params = "list4Jishu") public ModelAndView list4Project(HttpServletRequest request) { return new ModelAndView("cn/com/lzt/contractsale/contractSaleList4Jishu"); } /** * 销售合同列表 页面跳转 * * @return */ @RequestMapping(params = "listmodify") public ModelAndView listmodify(HttpServletRequest request) { String readOnly = "false"; if(StringUtils.isNotEmpty(request.getParameter("readOnly"))); readOnly = request.getParameter("readOnly"); request.setAttribute("readOnly", readOnly); request.setAttribute("contractid", request.getParameter("contractid")); return new ModelAndView("cn/com/lzt/contractsale/contractSaleModifyList"); } /** * easyui AJAX请求数据 * * @param request * @param response * @param dataGrid * @param user */ @RequestMapping(params = "datagridModify") public void datagridModify(ContractSaleEntity contractSale,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) { CriteriaQuery cq = new CriteriaQuery(ContractSaleEntity.class, dataGrid); String contractCode = request.getParameter("code"); String contractName = request.getParameter("name"); String contractDescription = request.getParameter("description"); contractSale.setType(Globals.CONTRACT_TYPE_SALE_ADDING); //查询条件组装器 if(StringUtils.isNotBlank(contractCode)){ //模糊查询 cq.like("code", "%"+contractCode+"%"); contractSale.setCode(null); } if(StringUtils.isNotBlank(contractName)){ //模糊查询 cq.like("name", "%"+contractName+"%"); contractSale.setName(null); } if(StringUtils.isNotBlank(contractDescription)){ //模糊查询 cq.like("description", "%"+contractDescription+"%"); contractSale.setDescription(null); } //查询条件组装器 org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, contractSale); try{ //自定义追加查询条件 }catch (Exception e) { throw new BusinessException(e.getMessage()); } cq.add(); this.contractSaleService.getDataGridReturn(cq, true); TagUtil.datagrid(response, dataGrid); } /** * 销售合同新增页面跳转 * * @return */ @RequestMapping(params = "goModifyAdd") public ModelAndView goAddModify(ContractSaleEntity contractSale, HttpServletRequest req) { if (StringUtil.isNotEmpty(contractSale.getId())) { contractSale = contractSaleService.getEntity(ContractSaleEntity.class, contractSale.getId()); contractSale.setType(Globals.CONTRACT_TYPE_SALE_ADDING); req.setAttribute("contractSalePage", contractSale); }else { ContractSaleEntity oralContractSale = contractSaleService.getEntity(ContractSaleEntity.class, contractSale.getContractid()); contractSale.setContractname(oralContractSale.getName()); contractSale.setStartdate(oralContractSale.getStartdate()); contractSale.setEnddate(oralContractSale.getEnddate()); contractSale.setNextbiddingdate(oralContractSale.getNextbiddingdate()); contractSale.setServicecontent(oralContractSale.getServicecontent()); contractSale.setProjectid(oralContractSale.getProjectid()); contractSale.setProjectname(oralContractSale.getProjectname()); contractSale.setCustomerid(oralContractSale.getCustomerid()); contractSale.setCustomername(oralContractSale.getCustomername()); contractSale.setPaytype(oralContractSale.getPaytype()); contractSale.setType(Globals.CONTRACT_TYPE_SALE_ADDING); req.setAttribute("contractSalePage", contractSale); } return new ModelAndView("cn/com/lzt/contractsale/contractSaleModify-add"); } /** * 销售合同编辑页面跳转 * * @return */ @RequestMapping(params = "goModifyUpdate") public ModelAndView goUpdateModify(ContractSaleEntity contractSale, HttpServletRequest req) { if (StringUtil.isNotEmpty(contractSale.getId())) { contractSale = contractSaleService.getEntity(ContractSaleEntity.class, contractSale.getId()); ContractSaleEntity oralContractSale = contractSaleService.getEntity(ContractSaleEntity.class, contractSale.getContractid()); contractSale.setContractname(oralContractSale.getName()); req.setAttribute("contractSalePage", contractSale); } return new ModelAndView("cn/com/lzt/contractsale/contractSaleModify-update"); } /** * 外包合同续签页面跳转 * * @return */ @RequestMapping(params = "goRenew") public ModelAndView goRenew(ContractSaleEntity contract, HttpServletRequest req) { String oralContractId = contract.getId(); if (StringUtil.isNotEmpty(oralContractId)) { try { ContractSaleEntity contractOral = contractSaleService.getEntity(ContractSaleEntity.class, contract.getId()); contract = new ContractSaleEntity(); MyBeanUtils.copyBeanNotNull2Bean(contractOral,contract); //设置续签后的起止日期 int contractDays = XcglDateUtils.differentDays(contract.getStartdate(), contract.getEnddate()); Date startdate = XcglDateUtils.addDateDay(contract.getEnddate(), 1); Date enddate = XcglDateUtils.addDateDay(startdate, contractDays); //清空部分数据,设置默认值***** contract.setId(null); contract.setSigndate(null); contract.setStartdate(startdate); contract.setEnddate(enddate); contract.setTotalincome(DecimalUtils.ZERO); contract.setTotalinvoice(DecimalUtils.ZERO); contract.setBpmStatus(Globals.BPM_STATUS_Normal.toString()); contract.setBusstatus(Globals.CONTRACT_STATUS_SIGN); contract.setCreateBy(null); contract.setCreateDate(null); contract.setCreateName(null); contract.setUpdateBy(null); contract.setUpdateDate(null); contract.setUpdateName(null); contract.setCode(null); contract.setAddamount(null); contract.setTotaladdandamount(contract.getTotalamount()); } catch (Exception e) { logger.error(e.getMessage()); } req.setAttribute("oralContractId", oralContractId); req.setAttribute("contractSalePage", contract); } return new ModelAndView("cn/com/lzt/contractsale/contractSale-renew"); } }