package com.idea.oa.apply.controller; import com.github.pagehelper.PageInfo; import com.rockstar.flow.exception.FlowException; import com.idea.oa.apply.model.ApplyPayment; import com.idea.oa.apply.model.inout.AddConfirmResultPayment; import com.idea.oa.apply.model.inout.ApplyPaymentIn; import com.idea.oa.apply.service.ApplyPaymentService; import com.idea.oa.apply.util.constant.ConstantFlowType; import com.idea.oa.flow2.model.FlowMain; import com.idea.oa.flow2.model.FlowMainPush; import com.idea.oa.flow2.model.in.FlowMainCcVo; import com.idea.oa.flow2.service.FlowMainCcService; import com.idea.oa.flow2.service.FlowMainPushService; import com.idea.oa.flow2.service.FlowMainService; import com.idea.oa.outsource.model.OutOrderPay; import com.idea.oa.outsource.service.OutOrderPayService; import com.rockstar.common.base.BaseController; import com.rockstar.common.domain.AjaxResult; import com.rockstar.frame.model.extend.DateTrans; import com.rockstar.frame.model.extend.TableSplitResult; import com.rockstar.frame.model.extend.Tablepar; import com.rockstar.shiro.util.ShiroUtils; import io.swagger.annotations.Api; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import java.util.Date; import java.util.List; import java.util.Map; /** * Created by zt */ @Controller @RequestMapping(value = "/ApplyPaymentController") @Api(value = "申请流程/分表_付款申请表") public class ApplyPaymentController extends BaseController { // @Autowired // private FlowService flowService; // @Autowired // private TaskService taskService; //主表 @Autowired private ApplyPaymentService modelService; @Autowired private FlowMainService flowMainService; // @Autowired // private FlowMainLogService flowMainLogService; @Autowired private FlowMainCcService flowMainCcService; @Autowired private FlowMainPushService flowMainPushService; @Autowired private OutOrderPayService outOrderPayService; // @Autowired // private ProActiService proActiService; @PostMapping(value = "findApplyPaymentListByInfo", produces = {"application/json;charset=UTF-8"}) @ResponseBody public TableSplitResult findApplyPaymentListByInfo(Tablepar tablepar, String name,String startTime,String endTime) { PageInfo page=modelService.findApplyPaymentListByInfo(tablepar, name, startTime, endTime); TableSplitResult result=new TableSplitResult<>(page.getPageNum(), page.getTotal(), page.getList()); return result; } @PostMapping(value = "findAllApplyPaymentListByInfo", produces = {"application/json;charset=UTF-8"}) @ResponseBody public List findAllApplyPaymentListByInfo(String name,String startTime,String endTime) { List result=modelService.findAllApplyPaymentListByInfo(name, startTime, endTime); return result; } /** * 添加审核结果 * 根据不同的状态值confirmResult判断是 1:审核通过,转下一步;2:退回发起人;3:退回上节点;4:结束流程; * * @param addConfirmResult * @return */ @PostMapping(value = "AddConfirmResultApplyPayment", produces = {"application/json;charset=UTF-8"}) @ResponseBody @Transactional public AjaxResult AddConfirmResultApplyPayment(AddConfirmResultPayment addConfirmResult) throws FlowException { System.out.println("AddConfirmResultApplyPayment"); System.out.println(addConfirmResult); if (addConfirmResult.getConfirmResult() == null) { return result(-1); } String deploymentid = ConstantFlowType.PAYMEN_DEPLOYMENTID; String constantFlowType = ConstantFlowType.PAYMEN; FlowMainPush flowMainPush = flowMainPushService.selectByPrimaryKey(addConfirmResult.getFlowMainPushId()); String isOkString=null; {//进行审核判断 // ApplyUseMoneyDetailExample example = new ApplyUseMoneyDetailExample(); // example.createCriteria().andUseMoneyIdEqualTo(flowMainPush.getFormId()); // List applyUseMoneyDetails = applyUseMoneyDetailService.selectByExample(example); // // 付款总金额 // BigDecimal feeMoneyTotal = new BigDecimal(0); // for (ApplyUseMoneyDetail applyUseMoneyDetail : applyUseMoneyDetails) { // BigDecimal feeMoney = applyUseMoneyDetail.getFeeMoney() == null ? new BigDecimal(0) : applyUseMoneyDetail.getFeeMoney(); // feeMoneyTotal = feeMoneyTotal.add(feeMoney, MathContext.DECIMAL32); // } // double feeMoneyTotalDouble = feeMoneyTotal.doubleValue(); // //添加判断条件 // HashMap conditionMap = new HashMap<>(); // conditionMap.put("billMoney", feeMoneyTotalDouble); isOkString=flowMainService.doConfirmResult(addConfirmResult,deploymentid,constantFlowType,flowMainPush,null); if (!"ok_end".equals(isOkString)&&!"ok_noEnd".equals(isOkString)) { return AjaxResult.error(isOkString); } } Boolean isEnd = false;//是否结束 Boolean isAgree = false;//是否同意 if (addConfirmResult.getConfirmResult().equals("4")) {//结束流程 isEnd = true; isAgree = false; } else if (addConfirmResult.getConfirmResult().equals("1")) {//1:审核通过,转下一步 if ("ok_end".equals(isOkString)) { isEnd = true; isAgree = true; } } //添加业务信息 if (!StringUtils.isEmpty(addConfirmResult.getPayRemark())||addConfirmResult.getPayTime()!=null) { ApplyPayment applyPayment = new ApplyPayment(); applyPayment.setId(flowMainPush.getFormId()); applyPayment.setPayTime(addConfirmResult.getPayTime()); applyPayment.setPayRemark(addConfirmResult.getPayRemark()); applyPayment.setUpdatedAt(new Date()); applyPayment.setUpdatedBy(ShiroUtils.getUser().getId()); modelService.updateByPrimaryKeySelective(applyPayment); } //添加业务信息(将请假信息中的修改掉,剩余年假,剩余调休,冻结年假,冻结调休都修改掉) if (isEnd&&isAgree) { // 添加付款台账支付明细 OutOrderPay outOrderPay = modelService.getApplyPaymentByFlowMainId(flowMainPush.getFormId()); outOrderPay.setSource("2"); outOrderPayService.insert(outOrderPay); } return result(1); } /** * 发起付款申请流程 * * @param record * @return */ @PostMapping(value = "addApplyPayment", produces = {"application/json;charset=UTF-8"}) @ResponseBody @Transactional public AjaxResult addApplyPayment(ApplyPaymentIn record) throws FlowException { System.out.println("addApplyPayment"); System.out.println(record); if (false) { return AjaxResult.error("这是一个错误测试信息"); } return myaddApplyPayment(record,null); } /** * 申请人重新发起申请 * * @param record * @return */ @PostMapping(value = "addApplyPaymentAgain", produces = {"application/json;charset=UTF-8"}) @ResponseBody @Transactional public AjaxResult addApplyPaymentAgain(ApplyPaymentIn record) throws FlowException { System.out.println("addApplyPaymentAgain"); if (StringUtils.isEmpty(record.getFlowMainId())){ return AjaxResult.error("没有传入flowMainId的值"); } System.out.println(record); // record.setRemark("重新发起申请[" + record.getFlowMainId() + "],"); {//修改重新发起前的表状态 FlowMain flowMain1 = new FlowMain(); flowMain1.setId(record.getFlowMainId()); flowMain1.setReturnStatus(1);//0/null无状态,1已撤回/已退回发起人并且已重新发起 flowMain1.setUpdatedAt(new Date()); flowMain1.setUpdatedBy(ShiroUtils.getUser().getId()); flowMainService.updateByPrimaryKeySelective(flowMain1); } return myaddApplyPayment(record,"重新发起申请[" + record.getFlowMainId() + "],"); } /** * 根据推送表的FlowMainPushId获取信息 * * @param flowMainPushId * @return */ @PostMapping(value = "getInfoByFlowMainPushId", produces = {"application/json;charset=UTF-8"}) @ResponseBody public ApplyPaymentIn getInfoByFlowMainPushId(String flowMainPushId) { ApplyPaymentIn myApplyPaymentIn = modelService.getInfoByFlowMainPushId(flowMainPushId); if (myApplyPaymentIn != null) { {//获取抄送人 List flowMainCcList = flowMainCcService.selectVoByFlowMainId(myApplyPaymentIn.getFlowMainId()); myApplyPaymentIn.setFlowMainCcList(flowMainCcList); } } return myApplyPaymentIn; } /** * 根据主表的FlowMainId获取信息 * * @param flowMainId * @return */ @PostMapping(value = "getInfoByFlowMainId", produces = {"application/json;charset=UTF-8"}) @ResponseBody public ApplyPaymentIn getInfoByFlowMainId(String flowMainId) { ApplyPaymentIn myApplyPaymentIn = modelService.getInfoByFlowMainId(flowMainId); if (myApplyPaymentIn != null) { {//获取抄送人 // FlowMainCcExample example = new FlowMainCcExample(); // example.createCriteria().andFlowMainIdEqualTo(myApplyUseMoneyIn.getFlowMainId()); // List flowMainCcList = flowMainCcService.selectByExample(example); List flowMainCcList = flowMainCcService.selectVoByFlowMainId(myApplyPaymentIn.getFlowMainId()); // HashSet set = new HashSet<>(); // for (FlowMainCc flowMainCc : flowMainCcList) { // set.add(flowMainCc.getCcUser()); // } // StringBuilder stringBuilder = new StringBuilder(); // if (!set.isEmpty()) { // for (String s : set) { // stringBuilder.append(s + ","); // } // } // myApplyUseMoneyIn.setCcList(stringBuilder.toString()); myApplyPaymentIn.setFlowMainCcList(flowMainCcList); } } return myApplyPaymentIn; } /** * 根据项目id获取所有已收款金额 */ @PostMapping(value = "getTotalMoneyByProId", produces = {"application/json;charset=UTF-8"}) @ResponseBody public AjaxResult getTotalMoneyByProId(String proId) { Double total = modelService.getTotalMoneyByProId(proId); return AjaxResult.success(total); } /** * 根据项目id获取所有已付款款金额 */ @PostMapping(value = "getTotalPayMoneyByProId", produces = {"application/json;charset=UTF-8"}) @ResponseBody public AjaxResult getTotalPayMoneyByProId(String proId) { Double total = modelService.getTotalPayMoneyByProId(proId); return AjaxResult.success(total); } /** * 改成根据订单编号查累计已付款款金额 */ @PostMapping(value = "getTotalPayMoneyByOrderNo", produces = {"application/json;charset=UTF-8"}) @ResponseBody public AjaxResult getTotalPayMoneyByOrderNo(String orderNo) { Double total = modelService.getTotalPayMoneyByOrderNo(orderNo); return AjaxResult.success(total); } /** * 发起付款申请流程 * * @param record * @return */ public AjaxResult myaddApplyPayment(ApplyPaymentIn record,String addSystemRemark) throws FlowException { // 存入付款申请 // record { record.setUpdatedAt(new Date()); record.setCreatedAt(record.getUpdatedAt()); record.setCreatedBy(ShiroUtils.getUser().getId()); record.setUpdatedBy(record.getCreatedBy()); record.setStatus(0); modelService.insert(record); } String applyTheme="关于" + record.getCustomerName() + "_" + record.getProjectName() + "_" + record.getSupplierName() + "_" + record.getPayName() + "的付款申请单"; AjaxResult ajaxResult = flowMainService.doFlowMain(applyTheme, record.getId(), addSystemRemark, record.getCcList(), ConstantFlowType.PAYMEN_PROCESSDEFINE, ConstantFlowType.PAYMEN_DEPLOYMENTID, null, ConstantFlowType.PAYMEN_NAME, ConstantFlowType.PAYMEN,ShiroUtils.getUser()); if (ajaxResult.get("code").equals(1688)) { return AjaxResult.success(); } return ajaxResult; } /** * 通用方法,加载到流程业务模块 * @return */ // public AjaxResult doFlowMain(String ApplyTheme,String recordId,String recordRemark,String recordCcList){ // // 存入流程主表 ok // FlowMain flowMain = new FlowMain(); // flowMain.setId(UUIDUtils.middleUUID()); // // 进入流程引擎,开始启动流程 // { // //启动流程引擎 // Map stringStringMap = proActiService.startTask(ConstantFlowType.PAYMEN_PROCESSDEFINE, ConstantFlowType.PAYMEN_DEPLOYMENTID, flowMain.getId(), ShiroUtils.getUser(), null); // if (stringStringMap == null) { // return AjaxResult.error("流程引擎开启失败,请查看原因!"); // } // // } // //存入流程日志表的id // String flowMainLogUuid = UUIDUtils.middleUUID(); // // { // //// 关于@客户名称@项目名称@供应商名称@付款名称的付款申请单 // flowMain.setApplyTheme(ApplyTheme); // flowMain.setFormId(recordId); // flowMain.setApplyUser(ShiroUtils.getUser().getId()); // flowMain.setDeptId(ShiroUtils.getUser().getDepartment()); // flowMain.setFlowStatus(1); // flowMain.setCcList(recordCcList); // flowMain.setFlowName(ConstantFlowType.PAYMEN_NAME); // flowMain.setFlowType(ConstantFlowType.PAYMEN); ////当前流程邮递操作人(frame_user)id 去除岗位的设定 // flowMain.setFlowPost(ShiroUtils.getUser().getId()); // {// 需要工作流引擎的支持 // flowMain.setFlowId(flowMain.getFlowId()); // flowMain.setTaskId(null); // } // flowMain.setReturnStatus(0); // flowMain.setLastMainLogId(flowMainLogUuid); // // flowMain.setUpdatedAt(new Date()); // flowMain.setCreatedAt(flowMain.getUpdatedAt()); // flowMain.setCreatedBy(ShiroUtils.getUser().getId()); // flowMain.setUpdatedBy(flowMain.getCreatedBy()); // flowMain.setGroupId(ShiroUtils.getUser().getGroupId()); // flowMain.setStatus(0); // if (!StringUtils.isEmpty(recordRemark)) { // flowMain.setRemark(recordRemark); // } // flowMainService.insertWithoutId(flowMain); // } // // // 存入流程日志表 ok // FlowMainLog flowMainLog = new FlowMainLog(); // { // flowMainLog.setId(flowMainLogUuid); // flowMainLog.setFlowMainId(flowMain.getId()); // flowMainLog.setFormId(recordId); // flowMainLog.setAuditUser(ShiroUtils.getUser().getId()); // flowMainLog.setAuditContent(null); // flowMainLog.setAuditResult(null); // //审批类型(0流程开始状态还是1流程审核状态还是2流程结束状态还是3申请人暂停状态4申请人结束状态 // flowMainLog.setAuditType("0"); // flowMainLog.setFlowType(ConstantFlowType.PAYMEN); // flowMainLog.setFlowPost(ShiroUtils.getUser().getId()); // {// 需要工作流引擎的支持 // flowMainLog.setFlowId(flowMain.getFlowId()); // flowMainLog.setTaskId(null); // } //// 下一环节操作人(审核人/委托人/退回申请人),列表例如:,张三,李四, //// 因为感觉用不到,暂时不放进去 //// flowMainLog.setNextPersons(); // flowMainLog.setUpMainLogId(null); // flowMainLog.setCcList(recordCcList); // // flowMainLog.setCreatedAt(new Date()); // flowMainLog.setCreatedBy(ShiroUtils.getUser().getId()); // flowMainLog.setGroupId(ShiroUtils.getUser().getGroupId()); // flowMainLog.setStatus(0); // flowMainLogService.insertWithoutId(flowMainLog); // } // // // // 存入抄送人信息 ok // if (!StringUtils.isEmpty(recordCcList)) { // String[] split = recordCcList.split(","); // for (String ccId : split) { // if (!StringUtils.isEmpty(ccId)) { // FlowMainCc flowMainCc = new FlowMainCc(); // flowMainCc.setFlowMainId(flowMain.getId()); // flowMainCc.setCcUser(ccId); // //选择抄送人时的记录表id(flow_main_log):例如:112122 // flowMainCc.setMainLogIds(flowMainLog.getId()); // // flowMainCc.setUpdatedAt(new Date()); // flowMainCc.setCreatedAt(flowMainCc.getUpdatedAt()); // flowMainCc.setCreatedBy(ShiroUtils.getUser().getId()); // flowMainCc.setUpdatedBy(flowMainCc.getCreatedBy()); // flowMainCc.setGroupId(ShiroUtils.getUser().getGroupId()); // flowMainCc.setStatus(0); // flowMainCcService.insert(flowMainCc); // } // } // // } // // 存入推送人 // //查看各个任务 // List listTask = taskService.createTaskQuery().processInstanceBusinessKey(flowMain.getId()).list(); // List TaskList = flowService.getTaskList(ConstantFlowType.PAYMEN_DEPLOYMENTID); // for (Task task : listTask) { // UserTask myUserTask = null; // { // String taskDefinitionKey = task.getTaskDefinitionKey(); // for (int i = 0; i < TaskList.size(); i++) { // if (TaskList.get(i).getId().equals(taskDefinitionKey)) { // myUserTask = TaskList.get(i); // break; // } // } // String pushUserKey = null; // Integer pushType = null; // if (myUserTask != null) { // pushUserKey = myUserTask.getCandidateGroups().get(0); // if (listTask.size() > 1) { // String[] s1 = pushUserKey.substring(0, pushUserKey.indexOf("-")).split("_"); // if (s1.length >= 5) { // String pushTypeNum = s1[4]; // if ("0".equals(pushTypeNum)) { // pushType = 2; // } else if ("1".equals(pushTypeNum)) { // pushType = 3; // } // // } // } else { // pushType = 1; // } // } // // // FlowMainPush flowMainPush = new FlowMainPush(); // flowMainPush.setFlowMainId(flowMain.getId()); // flowMainPush.setFormId(recordId); // {// 需要工作流引擎的支持 // flowMainPush.setPushUser(task.getAssignee());//推送人id' // flowMainPush.setPushUserKey(pushUserKey);//推送时彭总给的key值 // flowMainPush.setPushType(pushType);//推送类型1单流程推送,2串联推送,3并联推送 // flowMainPush.setPushRole(1);//'推送人身份:1本人审核,2被委托人(代理审核人审核权限)', // flowMainPush.setFlowType(ConstantFlowType.PAYMEN); // flowMainPush.setFlowPost(ShiroUtils.getUser().getId()); // flowMainPush.setFlowId(flowMain.getFlowId()); // flowMainPush.setTaskId(task.getId()); // } // flowMainPush.setUpMainLogId(flowMainLog.getId()); // flowMainPush.setUpdatedAt(new Date()); // flowMainPush.setCreatedAt(flowMainPush.getUpdatedAt()); // flowMainPush.setCreatedBy(ShiroUtils.getUser().getId()); // flowMainPush.setUpdatedBy(flowMainPush.getCreatedBy()); // flowMainPush.setGroupId(ShiroUtils.getUser().getGroupId()); // flowMainPush.setStatus(0); // flowMainPushService.insert(flowMainPush); // } // } // return result(1); // } // /** // * 添加审核结果 // * 根据不同的状态值confirmResult判断是 1:审核通过,转下一步;2:退回发起人;3:退回上节点;4:结束流程; // * // * @param addConfirmResult // * @return // */ // @PostMapping(value = "addConfirmResult", produces = {"application/json;charset=UTF-8"}) // @ResponseBody // public AjaxResult addConfirmResult(AddConfirmResult addConfirmResult) { // if (addConfirmResult.getConfirmResult() == null) { // return result(-1); // } // FlowMainPush flowMainPush = flowMainPushService.selectByPrimaryKey(addConfirmResult.getFlowMainPushId()); // FlowMain flowMain = flowMainService.selectByPrimaryKey(flowMainPush.getFlowMainId()); // //审核通过,转下一步 // if (addConfirmResult.getConfirmResult().equals(1)) { // {// 发起流程引擎操作 并查看下一节点的操作要求 // //1.如果当前角色是自己,就进行正常的审核流程 // //2.先查看当前角色是不是自己,不是自己就移动到自己的角色,然后再进行正常的审核流程 // // // } // { // //1修改主表状态 // //2添加日志 // //3判断是否存在串并联并修改推送状态 // //4添加新的推送人员 // } // // } else if (addConfirmResult.getConfirmResult().equals(2)) {//退回发起人 // {// 发起流程引擎操作 并查看下一节点的操作要求 // // } // { //1修改主表状态 // //2添加日志 // //3判断是否存在串并联并修改推送状态 // //4添加新的推送人员 // } // } else if (addConfirmResult.getConfirmResult().equals(3)) {//退回上节点 // {// 发起流程引擎操作 并查看下一节点的操作要求 // // } // { //1修改主表状态 // //2添加日志 // //3判断是否存在串并联并修改推送状态 // //4添加新的推送人员 // } // } else if (addConfirmResult.getConfirmResult().equals(4)) {//结束流程 // {// 发起流程引擎操作 并结束该流程 // // } // { // //1修改主表状态 // //2添加日志 // //3判断是否存在串并联并修改推送状态 // } // } // // return result(1); // } @PostMapping(value = "list", produces = {"application/json;charset=UTF-8"}) @ResponseBody public Object list(Tablepar tablepar, ApplyPayment model, DateTrans dt) { PageInfo page = modelService.list(tablepar, model, dt); TableSplitResult result = new TableSplitResult(page.getPageNum(), page.getTotal(), page.getList()); return result; } @PostMapping(value = "listAll", produces = {"application/json;charset=UTF-8"}) @ResponseBody public Object listAll(ApplyPayment model, DateTrans dt) { return modelService.listAll(model, dt); } @PostMapping(value = "add", produces = {"application/json;charset=UTF-8"}) @ResponseBody public AjaxResult add(ApplyPayment record) { record.setCreatedAt(new Date()); int result = modelService.insert(record); return result(result); } @PostMapping(value = "remove/{id}", produces = {"application/json;charset=UTF-8"}) @ResponseBody public AjaxResult remove(@PathVariable("id") String id) { int result = modelService.deleteByPrimaryKey(id); return result(result); } @PostMapping(value = "edit", produces = {"application/json;charset=UTF-8"}) @ResponseBody public AjaxResult editSave(ApplyPayment model) { int result = modelService.updateByPrimaryKeySelective(model); return result(result); } @PostMapping(value = "getById", produces = {"application/json;charset=UTF-8"}) @ResponseBody public ApplyPayment getById(String id) { return modelService.selectByPrimaryKey(id); } }