Commit 67e548d54567777c60bfbde9f1213491bb87cdfa
1 parent
97948502
【代码评审】BPM:任务前置、后置通知
Showing
5 changed files
with
15 additions
and
33 deletions
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmProcessInstanceServiceImpl.java
| @@ -63,7 +63,6 @@ import org.springframework.context.annotation.Lazy; | @@ -63,7 +63,6 @@ import org.springframework.context.annotation.Lazy; | ||
| 63 | import org.springframework.stereotype.Service; | 63 | import org.springframework.stereotype.Service; |
| 64 | import org.springframework.transaction.annotation.Transactional; | 64 | import org.springframework.transaction.annotation.Transactional; |
| 65 | import org.springframework.validation.annotation.Validated; | 65 | import org.springframework.validation.annotation.Validated; |
| 66 | -import org.springframework.web.client.RestTemplate; | ||
| 67 | 66 | ||
| 68 | import java.util.*; | 67 | import java.util.*; |
| 69 | 68 | ||
| @@ -268,6 +267,7 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService | @@ -268,6 +267,7 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService | ||
| 268 | FlowElement flowElement = bpmnModel.getFlowElement(task.getTaskDefinitionKey()); | 267 | FlowElement flowElement = bpmnModel.getFlowElement(task.getTaskDefinitionKey()); |
| 269 | List<FlowNode> nextFlowNodes = BpmnModelUtils.getNextFlowNodes(flowElement, bpmnModel, processVariables); | 268 | List<FlowNode> nextFlowNodes = BpmnModelUtils.getNextFlowNodes(flowElement, bpmnModel, processVariables); |
| 270 | 269 | ||
| 270 | + // TODO @小北:还是可以优化下哈;“4. 组装节点信息” 只拼接出 candidateUserIds;之后,再第二次循环,查询用户和部门信息,进行拼接 | ||
| 271 | // 2. 收集所有节点的候选用户 ID | 271 | // 2. 收集所有节点的候选用户 ID |
| 272 | Set<Long> allCandidateUsers = new HashSet<>(); | 272 | Set<Long> allCandidateUsers = new HashSet<>(); |
| 273 | for (FlowNode node : nextFlowNodes) { | 273 | for (FlowNode node : nextFlowNodes) { |
| @@ -290,7 +290,7 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService | @@ -290,7 +290,7 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService | ||
| 290 | List<UserSimpleBaseVO> candidateUsers = new ArrayList<>(); | 290 | List<UserSimpleBaseVO> candidateUsers = new ArrayList<>(); |
| 291 | for (Long userId : candidateUserIds) { | 291 | for (Long userId : candidateUserIds) { |
| 292 | UserSimpleBaseVO user = BpmProcessInstanceConvert.INSTANCE.buildUser(userId, userMap, deptMap); | 292 | UserSimpleBaseVO user = BpmProcessInstanceConvert.INSTANCE.buildUser(userId, userMap, deptMap); |
| 293 | - if (user != null){ | 293 | + if (user != null) { |
| 294 | candidateUsers.add(user); | 294 | candidateUsers.add(user); |
| 295 | } | 295 | } |
| 296 | } | 296 | } |
| @@ -932,10 +932,7 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService | @@ -932,10 +932,7 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService | ||
| 932 | BpmModelMetaInfoVO.HttpRequestSetting setting = processDefinitionInfo.getProcessAfterTriggerSetting(); | 932 | BpmModelMetaInfoVO.HttpRequestSetting setting = processDefinitionInfo.getProcessAfterTriggerSetting(); |
| 933 | 933 | ||
| 934 | BpmHttpRequestUtils.executeBpmHttpRequest(instance, | 934 | BpmHttpRequestUtils.executeBpmHttpRequest(instance, |
| 935 | - setting.getUrl(), | ||
| 936 | - setting.getHeader(), | ||
| 937 | - setting.getBody(), | ||
| 938 | - true, setting.getResponse()); | 935 | + setting.getUrl(), setting.getHeader(), setting.getBody(), true, setting.getResponse()); |
| 939 | } | 936 | } |
| 940 | } | 937 | } |
| 941 | }); | 938 | }); |
| @@ -954,10 +951,7 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService | @@ -954,10 +951,7 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService | ||
| 954 | } | 951 | } |
| 955 | BpmModelMetaInfoVO.HttpRequestSetting setting = processDefinitionInfo.getProcessBeforeTriggerSetting(); | 952 | BpmModelMetaInfoVO.HttpRequestSetting setting = processDefinitionInfo.getProcessBeforeTriggerSetting(); |
| 956 | BpmHttpRequestUtils.executeBpmHttpRequest(instance, | 953 | BpmHttpRequestUtils.executeBpmHttpRequest(instance, |
| 957 | - setting.getUrl(), | ||
| 958 | - setting.getHeader(), | ||
| 959 | - setting.getBody(), | ||
| 960 | - true, setting.getResponse()); | 954 | + setting.getUrl(), setting.getHeader(), setting.getBody(), true, setting.getResponse()); |
| 961 | }); | 955 | }); |
| 962 | } | 956 | } |
| 963 | 957 |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java
| @@ -1176,7 +1176,6 @@ public class BpmTaskServiceImpl implements BpmTaskService { | @@ -1176,7 +1176,6 @@ public class BpmTaskServiceImpl implements BpmTaskService { | ||
| 1176 | } | 1176 | } |
| 1177 | updateTaskStatus(task.getId(), BpmTaskStatusEnum.RUNNING.getStatus()); | 1177 | updateTaskStatus(task.getId(), BpmTaskStatusEnum.RUNNING.getStatus()); |
| 1178 | 1178 | ||
| 1179 | - // 2. 处理自动通过的情况,例如说:1)无审批人时,是否自动通过、不通过;2)非【人工审核】时,是否自动通过、不通过 | ||
| 1180 | ProcessInstance processInstance = processInstanceService.getProcessInstance(task.getProcessInstanceId()); | 1179 | ProcessInstance processInstance = processInstanceService.getProcessInstance(task.getProcessInstanceId()); |
| 1181 | if (processInstance == null) { | 1180 | if (processInstance == null) { |
| 1182 | log.error("[processTaskCreated][taskId({}) 没有找到流程实例]", task.getId()); | 1181 | log.error("[processTaskCreated][taskId({}) 没有找到流程实例]", task.getId()); |
| @@ -1188,15 +1187,15 @@ public class BpmTaskServiceImpl implements BpmTaskService { | @@ -1188,15 +1187,15 @@ public class BpmTaskServiceImpl implements BpmTaskService { | ||
| 1188 | log.error("[processTaskCreated][processDefinitionId({}) 没有找到流程定义]", processInstance.getProcessDefinitionId()); | 1187 | log.error("[processTaskCreated][processDefinitionId({}) 没有找到流程定义]", processInstance.getProcessDefinitionId()); |
| 1189 | return; | 1188 | return; |
| 1190 | } | 1189 | } |
| 1191 | - // 任务前置通知 | 1190 | + |
| 1191 | + // 2. 任务前置通知 | ||
| 1192 | if (ObjUtil.isNotNull(processDefinitionInfo.getTaskBeforeTriggerSetting())){ | 1192 | if (ObjUtil.isNotNull(processDefinitionInfo.getTaskBeforeTriggerSetting())){ |
| 1193 | BpmModelMetaInfoVO.HttpRequestSetting setting = processDefinitionInfo.getTaskBeforeTriggerSetting(); | 1193 | BpmModelMetaInfoVO.HttpRequestSetting setting = processDefinitionInfo.getTaskBeforeTriggerSetting(); |
| 1194 | BpmHttpRequestUtils.executeBpmHttpRequest(processInstance, | 1194 | BpmHttpRequestUtils.executeBpmHttpRequest(processInstance, |
| 1195 | - setting.getUrl(), | ||
| 1196 | - setting.getHeader(), | ||
| 1197 | - setting.getBody(), | ||
| 1198 | - true, setting.getResponse()); | 1195 | + setting.getUrl(), setting.getHeader(), setting.getBody(), true, setting.getResponse()); |
| 1199 | } | 1196 | } |
| 1197 | + | ||
| 1198 | + // 3. 处理自动通过的情况,例如说:1)无审批人时,是否自动通过、不通过;2)非【人工审核】时,是否自动通过、不通过 | ||
| 1200 | BpmnModel bpmnModel = modelService.getBpmnModelByDefinitionId(processInstance.getProcessDefinitionId()); | 1199 | BpmnModel bpmnModel = modelService.getBpmnModelByDefinitionId(processInstance.getProcessDefinitionId()); |
| 1201 | FlowElement userTaskElement = BpmnModelUtils.getFlowElementById(bpmnModel, task.getTaskDefinitionKey()); | 1200 | FlowElement userTaskElement = BpmnModelUtils.getFlowElementById(bpmnModel, task.getTaskDefinitionKey()); |
| 1202 | Integer approveType = BpmnModelUtils.parseApproveType(userTaskElement); | 1201 | Integer approveType = BpmnModelUtils.parseApproveType(userTaskElement); |
| @@ -1421,14 +1420,12 @@ public class BpmTaskServiceImpl implements BpmTaskService { | @@ -1421,14 +1420,12 @@ public class BpmTaskServiceImpl implements BpmTaskService { | ||
| 1421 | log.error("[processTaskCompleted][processDefinitionId({}) 没有找到流程定义]", processInstance.getProcessDefinitionId()); | 1420 | log.error("[processTaskCompleted][processDefinitionId({}) 没有找到流程定义]", processInstance.getProcessDefinitionId()); |
| 1422 | return; | 1421 | return; |
| 1423 | } | 1422 | } |
| 1424 | - // 任务前置通知 | 1423 | + |
| 1424 | + // 任务后置通知 | ||
| 1425 | if (ObjUtil.isNotNull(processDefinitionInfo.getTaskAfterTriggerSetting())){ | 1425 | if (ObjUtil.isNotNull(processDefinitionInfo.getTaskAfterTriggerSetting())){ |
| 1426 | BpmModelMetaInfoVO.HttpRequestSetting setting = processDefinitionInfo.getTaskAfterTriggerSetting(); | 1426 | BpmModelMetaInfoVO.HttpRequestSetting setting = processDefinitionInfo.getTaskAfterTriggerSetting(); |
| 1427 | BpmHttpRequestUtils.executeBpmHttpRequest(processInstance, | 1427 | BpmHttpRequestUtils.executeBpmHttpRequest(processInstance, |
| 1428 | - setting.getUrl(), | ||
| 1429 | - setting.getHeader(), | ||
| 1430 | - setting.getBody(), | ||
| 1431 | - true, setting.getResponse()); | 1428 | + setting.getUrl(), setting.getHeader(), setting.getBody(), true, setting.getResponse()); |
| 1432 | } | 1429 | } |
| 1433 | } | 1430 | } |
| 1434 | 1431 |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/listener/BpmUserTaskListener.java
| @@ -52,10 +52,7 @@ public class BpmUserTaskListener implements TaskListener { | @@ -52,10 +52,7 @@ public class BpmUserTaskListener implements TaskListener { | ||
| 52 | listenerHandler.getBody().add(new BpmSimpleModelNodeVO.HttpRequestParam().setKey("taskId") | 52 | listenerHandler.getBody().add(new BpmSimpleModelNodeVO.HttpRequestParam().setKey("taskId") |
| 53 | .setType(BpmHttpRequestParamTypeEnum.FIXED_VALUE.getType()).setValue(delegateTask.getId())); | 53 | .setType(BpmHttpRequestParamTypeEnum.FIXED_VALUE.getType()).setValue(delegateTask.getId())); |
| 54 | BpmHttpRequestUtils.executeBpmHttpRequest(processInstance, | 54 | BpmHttpRequestUtils.executeBpmHttpRequest(processInstance, |
| 55 | - listenerHandler.getPath(), | ||
| 56 | - listenerHandler.getHeader(), | ||
| 57 | - listenerHandler.getBody(), | ||
| 58 | - false, null); | 55 | + listenerHandler.getPath(), listenerHandler.getHeader(), listenerHandler.getBody(), false, null); |
| 59 | 56 | ||
| 60 | // 3. 是否需要后续操作?TODO 芋艿:待定! | 57 | // 3. 是否需要后续操作?TODO 芋艿:待定! |
| 61 | } | 58 | } |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/trigger/http/BpmHttpCallbackTrigger.java
| @@ -45,10 +45,7 @@ public class BpmHttpCallbackTrigger extends BpmAbstractHttpRequestTrigger { | @@ -45,10 +45,7 @@ public class BpmHttpCallbackTrigger extends BpmAbstractHttpRequestTrigger { | ||
| 45 | .setKey("taskDefineKey") // 重要:回调请求 taskDefineKey 需要传给被调用方,用于回调执行 | 45 | .setKey("taskDefineKey") // 重要:回调请求 taskDefineKey 需要传给被调用方,用于回调执行 |
| 46 | .setType(BpmHttpRequestParamTypeEnum.FIXED_VALUE.getType()).setValue(setting.getCallbackTaskDefineKey())); | 46 | .setType(BpmHttpRequestParamTypeEnum.FIXED_VALUE.getType()).setValue(setting.getCallbackTaskDefineKey())); |
| 47 | BpmHttpRequestUtils.executeBpmHttpRequest(processInstance, | 47 | BpmHttpRequestUtils.executeBpmHttpRequest(processInstance, |
| 48 | - setting.getUrl(), | ||
| 49 | - setting.getHeader(), | ||
| 50 | - setting.getBody(), | ||
| 51 | - false, null); | 48 | + setting.getUrl(), setting.getHeader(), setting.getBody(), false, null); |
| 52 | } | 49 | } |
| 53 | 50 | ||
| 54 | } | 51 | } |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/trigger/http/BpmSyncHttpRequestTrigger.java
| @@ -40,10 +40,7 @@ public class BpmSyncHttpRequestTrigger extends BpmAbstractHttpRequestTrigger { | @@ -40,10 +40,7 @@ public class BpmSyncHttpRequestTrigger extends BpmAbstractHttpRequestTrigger { | ||
| 40 | // 2. 发起请求 | 40 | // 2. 发起请求 |
| 41 | ProcessInstance processInstance = processInstanceService.getProcessInstance(processInstanceId); | 41 | ProcessInstance processInstance = processInstanceService.getProcessInstance(processInstanceId); |
| 42 | BpmHttpRequestUtils.executeBpmHttpRequest(processInstance, | 42 | BpmHttpRequestUtils.executeBpmHttpRequest(processInstance, |
| 43 | - setting.getUrl(), | ||
| 44 | - setting.getHeader(), | ||
| 45 | - setting.getBody(), | ||
| 46 | - true, setting.getResponse()); | 43 | + setting.getUrl(), setting.getHeader(), setting.getBody(), true, setting.getResponse()); |
| 47 | } | 44 | } |
| 48 | 45 | ||
| 49 | } | 46 | } |