From 8c958f28018f53b3bf90cf271dc0f228287bf18d Mon Sep 17 00:00:00 2001 From: luozukai Date: Fri, 18 Jan 2019 19:29:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=AE=A1=E6=89=B9=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../flowable/ContractTaskFinishHandler.java | 22 ++- .../src/main/resources/application-dev.yml | 4 +- .../src/main/resources/application-prod.yml | 2 + .../src/main/resources/application-test.yml | 2 + .../domain/po/WxPropertyContract.java | 11 ++ .../mapper/WxPropertyContractMapper.java | 2 +- .../com/iformall/service/WxFlowService.java | 7 + .../service/impl/DataTowerServiceImpl.java | 4 +- .../service/impl/WxFlowServiceImpl.java | 160 ++++++++++++++---- .../impl/WxRentContractServiceImpl.java | 5 +- .../mapper/WxPropertyContractMapper.xml | 8 +- 11 files changed, 174 insertions(+), 53 deletions(-) diff --git a/mallinkAdmin/src/main/java/com/iformall/flowable/ContractTaskFinishHandler.java b/mallinkAdmin/src/main/java/com/iformall/flowable/ContractTaskFinishHandler.java index 5bb2c81e3..df6b63e25 100644 --- a/mallinkAdmin/src/main/java/com/iformall/flowable/ContractTaskFinishHandler.java +++ b/mallinkAdmin/src/main/java/com/iformall/flowable/ContractTaskFinishHandler.java @@ -1,12 +1,15 @@ package com.iformall.flowable; -import com.iformall.domain.po.WxRentContract; import com.iformall.enums.EnumRentContractAppStatus; -import com.iformall.service.WxRentContractService; +import com.iformall.service.WxFlowService; +import com.iformall.service.impl.WxFlowServiceImpl; +import org.apache.commons.lang3.StringUtils; import org.flowable.engine.delegate.TaskListener; import org.flowable.task.service.delegate.DelegateTask; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import java.util.List; +import java.util.Map; /** * 合同审批完成,修改状态 @@ -14,15 +17,20 @@ import org.springframework.stereotype.Component; @Component(value="contractTaskFinishListener") public class ContractTaskFinishHandler implements TaskListener { @Autowired - private WxRentContractService wxRentContractService; + private WxFlowService wxFlowService; @Override public void notify(DelegateTask delegateTask) { Long businessId = (Long)delegateTask.getVariable("businessId"); - WxRentContract wxRentContract = new WxRentContract(); - wxRentContract.setId(businessId); - wxRentContract.setApplyStatus(EnumRentContractAppStatus.FINISH.getCode()); - wxRentContractService.updateApplyStatus(wxRentContract); + List> variables = (List)delegateTask.getVariable("variables"); + Integer flowType = (Integer)delegateTask.getVariable("businessType"); + + Integer contractType = 0; + String str = WxFlowServiceImpl.getVariableByKey(variables,"contractType"); + if(StringUtils.isNotBlank(str)){ + contractType = Integer.parseInt(str); + } + wxFlowService.updateBusinessStatus(businessId,flowType,contractType,EnumRentContractAppStatus.FINISH.getCode()); } } diff --git a/mallinkAdmin/src/main/resources/application-dev.yml b/mallinkAdmin/src/main/resources/application-dev.yml index 2a40736d2..9a44be55a 100644 --- a/mallinkAdmin/src/main/resources/application-dev.yml +++ b/mallinkAdmin/src/main/resources/application-dev.yml @@ -22,8 +22,8 @@ spring: connectionProperties: "druid.stat.mergeSql=true;druid.stat.slowSqlMillis=6000" #jackson: #date-format: yyyy-MM-dd HH:mm:ss - flowable: - async-executor-activate: false + flowable: + async-executor-activate: false # REDIS redis: diff --git a/mallinkAdmin/src/main/resources/application-prod.yml b/mallinkAdmin/src/main/resources/application-prod.yml index ea4b08fe5..4e3fe8273 100644 --- a/mallinkAdmin/src/main/resources/application-prod.yml +++ b/mallinkAdmin/src/main/resources/application-prod.yml @@ -46,6 +46,8 @@ spring: auth: true starttls: enable: true + flowable: + async-executor-activate: false aws: clientRegion: cn-northwest-1 diff --git a/mallinkAdmin/src/main/resources/application-test.yml b/mallinkAdmin/src/main/resources/application-test.yml index ff190301e..73665ba7c 100644 --- a/mallinkAdmin/src/main/resources/application-test.yml +++ b/mallinkAdmin/src/main/resources/application-test.yml @@ -46,6 +46,8 @@ spring: auth: true starttls: enable: true + flowable: + async-executor-activate: false aws: clientRegion: cn-northwest-1 diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxPropertyContract.java b/mallinkService/src/main/java/com/iformall/domain/po/WxPropertyContract.java index f333a860e..a6605445d 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxPropertyContract.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxPropertyContract.java @@ -17,6 +17,9 @@ public class WxPropertyContract implements Serializable { @Id protected Long id; + + // 审核状态,0未审核 1审核中 2审核完成 3驳回 4合同作废 + private Integer applyStatus; @Transient protected List ids; @@ -150,6 +153,14 @@ public class WxPropertyContract implements Serializable { @io.swagger.annotations.ApiModelProperty(value = "起租结束时间", name = "rentalEndDate") private Date endDate; + public Integer getApplyStatus() { + return applyStatus; + } + + public void setApplyStatus(Integer applyStatus) { + this.applyStatus = applyStatus; + } + public Long getMerchantId() { return merchantId; } diff --git a/mallinkService/src/main/java/com/iformall/mapper/WxPropertyContractMapper.java b/mallinkService/src/main/java/com/iformall/mapper/WxPropertyContractMapper.java index 6d744a394..eaac4f2a9 100644 --- a/mallinkService/src/main/java/com/iformall/mapper/WxPropertyContractMapper.java +++ b/mallinkService/src/main/java/com/iformall/mapper/WxPropertyContractMapper.java @@ -36,7 +36,7 @@ public interface WxPropertyContractMapper extends CommonMapper getRentContractList(Map params); - + void updateApplyStatus(WxPropertyContract wxPropertyContract); } diff --git a/mallinkService/src/main/java/com/iformall/service/WxFlowService.java b/mallinkService/src/main/java/com/iformall/service/WxFlowService.java index d2cc5ac71..dc003f0d8 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxFlowService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxFlowService.java @@ -11,6 +11,13 @@ import java.util.Map; */ public interface WxFlowService { + /** + * 更新业务数据状态 + * @param businessId + * @param flowType + */ + void updateBusinessStatus(Long businessId,Integer flowType,Integer contractType,Integer applyStatus); + ResultData getTaskStatusList(Long businessId,String tenantId); /** diff --git a/mallinkService/src/main/java/com/iformall/service/impl/DataTowerServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/DataTowerServiceImpl.java index 6fb24e432..ff3523ed8 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/DataTowerServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/DataTowerServiceImpl.java @@ -510,7 +510,9 @@ public class DataTowerServiceImpl implements DataTowerService { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); List days = DateUtils.dateToWeek(new Date()); String oneWeekStartdate = sdf.format(days.get(0)); - String oneWeekSystemTime = sdf.format(days.get(days.size()-1)); + String oneWeekEndDate = sdf.format(days.get(days.size()-1)); + params.put("startdate", oneWeekStartdate + " 00:00:00"); + params.put("enddate", oneWeekEndDate + " 23:59:59"); List> oneWeekHistorylist = wxCarCmdLogMapper.queryHistory(params); Map oneWeekCollect = oneWeekHistorylist.stream().collect(Collectors.toMap(m -> { diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxFlowServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxFlowServiceImpl.java index 1af1d755f..6cffd1917 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxFlowServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxFlowServiceImpl.java @@ -4,15 +4,13 @@ import com.github.pagehelper.PageInfo; import com.iformall.common.ErrorCode; import com.iformall.common.Result; import com.iformall.common.ResultData; -import com.iformall.domain.po.MallUserInfo; -import com.iformall.domain.po.WxFlowRecord; -import com.iformall.domain.po.WxMsgValidationcode; -import com.iformall.domain.po.WxRentContract; +import com.iformall.domain.po.*; import com.iformall.enums.EnumFlowKey; import com.iformall.enums.EnumFlowRecordStatus; import com.iformall.enums.EnumMsgModelType; import com.iformall.enums.EnumRentContractAppStatus; import com.iformall.exception.MallinkException; +import com.iformall.mapper.WxPropertyContractMapper; import com.iformall.mapper.WxRentContractMapper; import com.iformall.service.*; import com.iformall.utils.Constant; @@ -62,6 +60,8 @@ public class WxFlowServiceImpl implements WxFlowService { private WxMsgValidationcodeService wxMsgValidationcodeService; @Autowired private WxRentContractMapper wxRentContractMapper; + @Autowired + private WxPropertyContractMapper wxPropertyContractMapper; /** * 获取流程key,1合同 2账单 @@ -77,6 +77,28 @@ public class WxFlowServiceImpl implements WxFlowService { return null; } + /** + * 更新业务数据状态 + * @param businessId + * @param flowType + */ + @Override + public void updateBusinessStatus(Long businessId,Integer flowType,Integer contractType,Integer applyStatus){ + if(1 == flowType){ + WxRentContract rent = new WxRentContract(); + rent.setId(businessId); + rent.setApplyStatus(applyStatus); + wxRentContractService.updateApplyStatus(rent); + + // 1租赁2点位wx_rent_contract 3物业wx_property_contract + if(contractType == 3){ + WxPropertyContract wxPropertyContract = new WxPropertyContract(); + wxPropertyContract.setId(businessId); + wxPropertyContractMapper.updateApplyStatus(wxPropertyContract); + } + } + } + @Override @Transactional(propagation = Propagation.REQUIRED,rollbackFor = {Exception.class}) public ResultData start(Map params,Long userId,String userName,String tenantId) { @@ -84,6 +106,7 @@ public class WxFlowServiceImpl implements WxFlowService { Long businessId = Long.parseLong((String)params.get("businessId")); Integer flowType = (Integer)params.get("businessType"); List> taskAssignee = (List)params.get("taskAssignee"); + List> variables = (List)params.get("variables"); // 查询合同信息 WxRentContract wxRentContract = wxRentContractMapper.selectByPrimaryKey(businessId); @@ -104,15 +127,18 @@ public class WxFlowServiceImpl implements WxFlowService { map.put("flowType",flowType); map.put("taskAssignee",taskAssignee); map.put("contractNumber",wxRentContract.getContractNumber()); + map.put("variables",variables); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(getFlowKeyByType(flowType), map); logger.debug("流程启动,流程id:{}",processInstance.getId()); // 合同审核状态改为审核中 - WxRentContract rent = new WxRentContract(); - rent.setId(businessId); - rent.setApplyStatus(EnumRentContractAppStatus.APPLYING.getCode()); - wxRentContractService.updateApplyStatus(rent); + Integer contractType = 0; + String str = getVariableByKey(variables,"contractType"); + if(StringUtils.isNotBlank(str)){ + contractType = Integer.parseInt(str); + } + updateBusinessStatus(businessId,flowType,contractType,EnumRentContractAppStatus.APPLYING.getCode()); // 保存wx_flow_record表审批记录 WxFlowRecord wxFlowRecord = new WxFlowRecord(); @@ -161,6 +187,10 @@ public class WxFlowServiceImpl implements WxFlowService { taskInfoMap.put("taskId",task.getId()); taskInfoMap.put("businessId",mapInfo.get("businessId")); taskInfoMap.put("contractNumber",mapInfo.get("contractNumber")); + List> variables = (List)mapInfo.get("variables"); //定制variables,回传 + for (Map m:variables) { + taskInfoMap.putAll(m); + } result.add(taskInfoMap); } PageInfo> pageInfo = new PageInfo<>(result,pageSize); @@ -202,7 +232,7 @@ public class WxFlowServiceImpl implements WxFlowService { Map mapInfo = taskService.getVariables(task.getId()); List> taskAssigneeList = (List)mapInfo.get("taskAssignee"); - for (int i = 0; i < taskAssigneeList.size()-1; i++) { + for (int i = 0; i < taskAssigneeList.size(); i++) { Map assignee = taskAssigneeList.get(i); if(task.getTaskDefinitionKey().equals(assignee.get("taskKey"))){ //设置当前节点代办人信息 @@ -262,8 +292,6 @@ public class WxFlowServiceImpl implements WxFlowService { Map mapInfo = taskService.getVariables(task.getId()); Long businessId = (Long)mapInfo.get("businessId"); Integer flowType = (Integer)mapInfo.get("flowType"); - MallUserInfo starter = (MallUserInfo)mapInfo.get("starter"); - taskService.complete(taskId); //保存wx_flow_record表审批记录 @@ -280,37 +308,60 @@ public class WxFlowServiceImpl implements WxFlowService { wxFlowRecord.setTaskKey(taskKey); wxFlowRecordService.saveOrUpdate(wxFlowRecord); + // 判断流程是否结束,并发送短信通知 + isEndAndSendMsg(mapInfo,taskKey,processInstanceId,tenantId,userName); + + return new ResultData(); + } + + /** + * 判断流程是否结束,并发送短信通知 + * @param taskKey + * @param processInstanceId + * @param tenantId + */ + public void isEndAndSendMsg(Map mapInfo,String taskKey,String processInstanceId,String tenantId,String userName){ // 发送短信 Map msgReplaceMap = new HashedMap(); WxMsgValidationcode wxMsgValidationcode = new WxMsgValidationcode(); wxMsgValidationcode.setTenantId(tenantId); wxMsgValidationcode.setType(EnumMsgModelType.FLOW.getCode()); - // 判断流程是否结束 + MallUserInfo starter = (MallUserInfo)mapInfo.get("starter"); + List> taskAssigneeList = (List)mapInfo.get("taskAssignee"); + Long businessId = (Long)mapInfo.get("businessId"); + + // 判断下个节点是否有设置审批人,没有,直接通过,有,发短信通知 if(!isEnded(processInstanceId)){ - String assignee = ""; - // 给代办人发送通知短信 - List mallUserInfoList = getUserByProcessInstanceId(processInstanceId); - for (MallUserInfo mallUserInfo:mallUserInfoList) { - msgReplaceMap.put("userName",mallUserInfo.getName()); + if(hasAssignee(taskAssigneeList,taskKey,processInstanceId)){ + // 给代办人发送通知短信 + String assignee = ""; + List mallUserInfoList = getUserByProcessInstanceId(processInstanceId); + for (MallUserInfo mallUserInfo:mallUserInfoList) { + msgReplaceMap.put("userName",mallUserInfo.getName()); + msgReplaceMap.put("page",Constant.adminPage); + msgReplaceMap.put("modelName","代办通知"); + + assignee += mallUserInfo.getName()+" "; + wxMsgValidationcode.setPhone(mallUserInfo.getPhone()); + wxMsgValidationcodeService.sendWorkFlowNodify(wxMsgValidationcode,msgReplaceMap); + } + + // 给发起人发送短信 + msgReplaceMap = new HashedMap(); + msgReplaceMap.put("userName",userName); msgReplaceMap.put("page",Constant.adminPage); - msgReplaceMap.put("modelName","代办通知"); + msgReplaceMap.put("modelName","审批通知"); + msgReplaceMap.put("contract",businessId+""); + msgReplaceMap.put("toUserName",assignee.trim()); - assignee += mallUserInfo.getName()+" "; - wxMsgValidationcode.setPhone(mallUserInfo.getPhone()); + wxMsgValidationcode = new WxMsgValidationcode(); + wxMsgValidationcode.setPhone(starter.getPhone()); wxMsgValidationcodeService.sendWorkFlowNodify(wxMsgValidationcode,msgReplaceMap); + }else{ + //todo 需要测下三节点 + //继续递归判断 + isEndAndSendMsg(mapInfo,taskKey,processInstanceId,tenantId,userName); } - - // 给发起人发送短信 - msgReplaceMap = new HashedMap(); - msgReplaceMap.put("userName",userName); - msgReplaceMap.put("page",Constant.adminPage); - msgReplaceMap.put("modelName","审批通知"); - msgReplaceMap.put("contract",businessId+""); - msgReplaceMap.put("toUserName",assignee.trim()); - - wxMsgValidationcode = new WxMsgValidationcode(); - wxMsgValidationcode.setPhone(starter.getPhone()); - wxMsgValidationcodeService.sendWorkFlowNodify(wxMsgValidationcode,msgReplaceMap); }else{ // 给发起人发送审批通过消息 msgReplaceMap = new HashedMap(); @@ -322,8 +373,31 @@ public class WxFlowServiceImpl implements WxFlowService { wxMsgValidationcode.setPhone(starter.getPhone()); wxMsgValidationcodeService.sendWorkFlowNodify(wxMsgValidationcode,msgReplaceMap); } + } - return new ResultData(); + /** + * 判断下个节点是否有设置审批人,没有,直接通过 + * @param + * @param taskKey + * @param processInstanceId + */ + public boolean hasAssignee(List> taskAssigneeList,String taskKey,String processInstanceId){ + boolean has = true; + for (int i = 0; i < taskAssigneeList.size(); i++) { + Map taskAssignee = taskAssigneeList.get(i); + if(taskAssignee.get("taskKey").equals(taskKey)){ + if(i != taskAssigneeList.size() -1){ + Map nextTaskAssignee = taskAssigneeList.get(i+1); + if(StringUtils.isBlank(nextTaskAssignee.get("assignee"))){ + Task task = taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult(); + taskService.complete(task.getId()); + has = false; + break; + } + } + } + } + return has; } @Override @@ -337,6 +411,7 @@ public class WxFlowServiceImpl implements WxFlowService { Long businessId = (Long)mapInfo.get("businessId"); Integer flowType = (Integer)mapInfo.get("flowType"); MallUserInfo starter = (MallUserInfo)mapInfo.get("starter"); + List> variables = (List)mapInfo.get("variables"); String taskName; String taskKey; @@ -350,10 +425,12 @@ public class WxFlowServiceImpl implements WxFlowService { runtimeService.deleteProcessInstance(processInstanceId, "驳回"); // 修改合同审核状态为驳回 - WxRentContract wxRentContract = new WxRentContract(); - wxRentContract.setId(businessId); - wxRentContract.setApplyStatus(EnumRentContractAppStatus.REJECT.getCode()); - wxRentContractService.updateApplyStatus(wxRentContract); + Integer contractType = 0; + String str = getVariableByKey(variables,"contractType"); + if(StringUtils.isNotBlank(str)){ + contractType = Integer.parseInt(str); + } + updateBusinessStatus(businessId,flowType,contractType,EnumRentContractAppStatus.REJECT.getCode()); //保存wx_flow_record表审批记录 WxFlowRecord wxFlowRecord = new WxFlowRecord(); @@ -498,4 +575,13 @@ public class WxFlowServiceImpl implements WxFlowService { } } + public static String getVariableByKey(List> variables,String key){ + for (Map map:variables) { + if(map.get("key").equals(key)){ + return map.get("value"); + } + } + return null; + } + } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java index a47c117c1..2cf1f1652 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java @@ -13,7 +13,6 @@ import com.iformall.enums.*; import com.iformall.exception.MallinkException; import com.iformall.mapper.*; import com.iformall.service.WxFlowRecordService; -import com.iformall.service.WxFlowService; import com.iformall.service.WxMerchantService; import com.iformall.service.WxRentContractService; import com.iformall.utils.Constant; @@ -29,7 +28,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; - import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.*; @@ -274,7 +272,8 @@ public class WxRentContractServiceImpl implements WxRentContractService { logger.error("更新租赁合同信息失败,e:" + e.getMessage()); throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage()); } - return new ResultData(Result.SUCCESS, "更新租赁合同信息成功"); +// return new ResultData(Result.SUCCESS, "更新租赁合同信息成功"); + return new ResultData(Result.SUCCESS, "保存租赁合同信息成功", wxRentContract); } diff --git a/mallinkService/src/main/resources/mapper/WxPropertyContractMapper.xml b/mallinkService/src/main/resources/mapper/WxPropertyContractMapper.xml index f711197a9..bc421658a 100644 --- a/mallinkService/src/main/resources/mapper/WxPropertyContractMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxPropertyContractMapper.xml @@ -32,6 +32,8 @@ + + @@ -40,7 +42,7 @@ `deposit`,`pay_date`,`is_del`,`merchant_name`,`brand`,`business_id`, `shop_type`,`shop_id`,`updatetime`,`createtime`,`rent_area`, `link_person`,`link_phone`,`pay_account`,`filename`,`lease`,`rent_contract_id`, - `start_date`,`end_date` + `start_date`,`end_date`,`apply_status` @@ -166,5 +168,7 @@ - + + update wx_property_contract set apply_status=#{applyStatus} where id=#{id} +