|
|
|
@@ -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<String, Object> 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<Map<String,String>> taskAssignee = (List)params.get("taskAssignee"); |
|
|
|
List<Map<String,String>> 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<Map<String,String>> variables = (List)mapInfo.get("variables"); //定制variables,回传 |
|
|
|
for (Map<String,String> m:variables) { |
|
|
|
taskInfoMap.putAll(m); |
|
|
|
} |
|
|
|
result.add(taskInfoMap); |
|
|
|
} |
|
|
|
PageInfo<Map<String,Object>> pageInfo = new PageInfo<>(result,pageSize); |
|
|
|
@@ -202,7 +232,7 @@ public class WxFlowServiceImpl implements WxFlowService { |
|
|
|
Map<String,Object> mapInfo = taskService.getVariables(task.getId()); |
|
|
|
List<Map<String,String>> taskAssigneeList = (List)mapInfo.get("taskAssignee"); |
|
|
|
|
|
|
|
for (int i = 0; i < taskAssigneeList.size()-1; i++) { |
|
|
|
for (int i = 0; i < taskAssigneeList.size(); i++) { |
|
|
|
Map<String,String> assignee = taskAssigneeList.get(i); |
|
|
|
if(task.getTaskDefinitionKey().equals(assignee.get("taskKey"))){ |
|
|
|
//设置当前节点代办人信息 |
|
|
|
@@ -262,8 +292,6 @@ public class WxFlowServiceImpl implements WxFlowService { |
|
|
|
Map<String,Object> 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<String,Object> mapInfo,String taskKey,String processInstanceId,String tenantId,String userName){ |
|
|
|
// 发送短信 |
|
|
|
Map<String,String> msgReplaceMap = new HashedMap(); |
|
|
|
WxMsgValidationcode wxMsgValidationcode = new WxMsgValidationcode(); |
|
|
|
wxMsgValidationcode.setTenantId(tenantId); |
|
|
|
wxMsgValidationcode.setType(EnumMsgModelType.FLOW.getCode()); |
|
|
|
// 判断流程是否结束 |
|
|
|
MallUserInfo starter = (MallUserInfo)mapInfo.get("starter"); |
|
|
|
List<Map<String,String>> taskAssigneeList = (List)mapInfo.get("taskAssignee"); |
|
|
|
Long businessId = (Long)mapInfo.get("businessId"); |
|
|
|
|
|
|
|
// 判断下个节点是否有设置审批人,没有,直接通过,有,发短信通知 |
|
|
|
if(!isEnded(processInstanceId)){ |
|
|
|
String assignee = ""; |
|
|
|
// 给代办人发送通知短信 |
|
|
|
List<MallUserInfo> mallUserInfoList = getUserByProcessInstanceId(processInstanceId); |
|
|
|
for (MallUserInfo mallUserInfo:mallUserInfoList) { |
|
|
|
msgReplaceMap.put("userName",mallUserInfo.getName()); |
|
|
|
if(hasAssignee(taskAssigneeList,taskKey,processInstanceId)){ |
|
|
|
// 给代办人发送通知短信 |
|
|
|
String assignee = ""; |
|
|
|
List<MallUserInfo> 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<Map<String,String>> taskAssigneeList,String taskKey,String processInstanceId){ |
|
|
|
boolean has = true; |
|
|
|
for (int i = 0; i < taskAssigneeList.size(); i++) { |
|
|
|
Map<String,String> taskAssignee = taskAssigneeList.get(i); |
|
|
|
if(taskAssignee.get("taskKey").equals(taskKey)){ |
|
|
|
if(i != taskAssigneeList.size() -1){ |
|
|
|
Map<String,String> 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<Map<String,String>> 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<Map<String,String>> variables,String key){ |
|
|
|
for (Map<String,String> map:variables) { |
|
|
|
if(map.get("key").equals(key)){ |
|
|
|
return map.get("value"); |
|
|
|
} |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
} |