Commit 58c667f728d4217a95e2a43b10581fbb6861724e
1 parent
dc1c8247
feat: 任务前后置通知
Showing
5 changed files
with
72 additions
and
1 deletions
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/definition/vo/model/BpmModelMetaInfoVO.java
| ... | ... | @@ -88,6 +88,12 @@ public class BpmModelMetaInfoVO { |
| 88 | 88 | @Schema(description = "流程后置通知设置", example = "{}") |
| 89 | 89 | private HttpRequestSetting processAfterTriggerSetting; |
| 90 | 90 | |
| 91 | + @Schema(description = "任务前置通知设置", example = "{}") | |
| 92 | + private HttpRequestSetting taskBeforeTriggerSetting; | |
| 93 | + | |
| 94 | + @Schema(description = "任务后置通知设置", example = "{}") | |
| 95 | + private HttpRequestSetting taskAfterTriggerSetting; | |
| 96 | + | |
| 91 | 97 | @Schema(description = "流程 ID 规则") |
| 92 | 98 | @Data |
| 93 | 99 | @Valid | ... | ... |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/dal/dataobject/definition/BpmProcessDefinitionInfoDO.java
| ... | ... | @@ -199,4 +199,16 @@ public class BpmProcessDefinitionInfoDO extends BaseDO { |
| 199 | 199 | @TableField(typeHandler = JacksonTypeHandler.class) |
| 200 | 200 | private BpmModelMetaInfoVO.HttpRequestSetting processAfterTriggerSetting; |
| 201 | 201 | |
| 202 | + /** | |
| 203 | + * 任务前置通知设置 | |
| 204 | + */ | |
| 205 | + @TableField(typeHandler = JacksonTypeHandler.class) | |
| 206 | + private BpmModelMetaInfoVO.HttpRequestSetting taskBeforeTriggerSetting; | |
| 207 | + | |
| 208 | + /** | |
| 209 | + * 任务后置通知设置 | |
| 210 | + */ | |
| 211 | + @TableField(typeHandler = JacksonTypeHandler.class) | |
| 212 | + private BpmModelMetaInfoVO.HttpRequestSetting taskAfterTriggerSetting; | |
| 213 | + | |
| 202 | 214 | } | ... | ... |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/listener/BpmTaskEventListener.java
| ... | ... | @@ -47,7 +47,7 @@ public class BpmTaskEventListener extends AbstractFlowableEngineEventListener { |
| 47 | 47 | public static final Set<FlowableEngineEventType> TASK_EVENTS = ImmutableSet.<FlowableEngineEventType>builder() |
| 48 | 48 | .add(FlowableEngineEventType.TASK_CREATED) |
| 49 | 49 | .add(FlowableEngineEventType.TASK_ASSIGNED) |
| 50 | -// .add(FlowableEngineEventType.TASK_COMPLETED) // 由于审批通过时,已经记录了 task 的 status 为通过,所以不需要监听了。 | |
| 50 | + .add(FlowableEngineEventType.TASK_COMPLETED) // 由于审批通过时,已经记录了 task 的 status 为通过,这里仅处理任务后置通知。 | |
| 51 | 51 | .add(FlowableEngineEventType.ACTIVITY_CANCELLED) |
| 52 | 52 | .add(FlowableEngineEventType.TIMER_FIRED) // 监听审批超时 |
| 53 | 53 | .build(); |
| ... | ... | @@ -67,6 +67,11 @@ public class BpmTaskEventListener extends AbstractFlowableEngineEventListener { |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | @Override |
| 70 | + protected void taskCompleted(FlowableEngineEntityEvent event) { | |
| 71 | + taskService.processTaskCompleted((Task) event.getEntity()); | |
| 72 | + } | |
| 73 | + | |
| 74 | + @Override | |
| 70 | 75 | protected void activityCancelled(FlowableActivityCancelledEvent event) { |
| 71 | 76 | List<HistoricActivityInstance> activityList = taskService.getHistoricActivityListByExecutionId(event.getExecutionId()); |
| 72 | 77 | if (CollUtil.isEmpty(activityList)) { | ... | ... |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskService.java
| ... | ... | @@ -279,6 +279,13 @@ public interface BpmTaskService { |
| 279 | 279 | void processTaskAssigned(Task task); |
| 280 | 280 | |
| 281 | 281 | /** |
| 282 | + * 处理 Task 完成事件,目前是发送任务后置通知 | |
| 283 | + * | |
| 284 | + * @param task 任务实体 | |
| 285 | + */ | |
| 286 | + void processTaskCompleted(Task task); | |
| 287 | + | |
| 288 | + /** | |
| 282 | 289 | * 处理 Task 审批超时事件,可能会处理多个当前审批中的任务 |
| 283 | 290 | * |
| 284 | 291 | * @param processInstanceId 流程示例编号 | ... | ... |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java
| ... | ... | @@ -12,6 +12,7 @@ import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; |
| 12 | 12 | import cn.iocoder.yudao.framework.common.util.object.PageUtils; |
| 13 | 13 | import cn.iocoder.yudao.framework.datapermission.core.annotation.DataPermission; |
| 14 | 14 | import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils; |
| 15 | +import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelMetaInfoVO; | |
| 15 | 16 | import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task.*; |
| 16 | 17 | import cn.iocoder.yudao.module.bpm.convert.task.BpmTaskConvert; |
| 17 | 18 | import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmFormDO; |
| ... | ... | @@ -23,6 +24,7 @@ import cn.iocoder.yudao.module.bpm.enums.task.BpmTaskSignTypeEnum; |
| 23 | 24 | import cn.iocoder.yudao.module.bpm.enums.task.BpmTaskStatusEnum; |
| 24 | 25 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmTaskCandidateStrategyEnum; |
| 25 | 26 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnVariableConstants; |
| 27 | +import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmHttpRequestUtils; | |
| 26 | 28 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils; |
| 27 | 29 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.FlowableUtils; |
| 28 | 30 | import cn.iocoder.yudao.module.bpm.service.definition.BpmFormService; |
| ... | ... | @@ -1180,6 +1182,21 @@ public class BpmTaskServiceImpl implements BpmTaskService { |
| 1180 | 1182 | log.error("[processTaskCreated][taskId({}) 没有找到流程实例]", task.getId()); |
| 1181 | 1183 | return; |
| 1182 | 1184 | } |
| 1185 | + BpmProcessDefinitionInfoDO processDefinitionInfo = bpmProcessDefinitionService. | |
| 1186 | + getProcessDefinitionInfo(processInstance.getProcessDefinitionId()); | |
| 1187 | + if (processDefinitionInfo == null) { | |
| 1188 | + log.error("[processTaskCreated][processDefinitionId({}) 没有找到流程定义]", processInstance.getProcessDefinitionId()); | |
| 1189 | + return; | |
| 1190 | + } | |
| 1191 | + // 任务前置通知 | |
| 1192 | + if (ObjUtil.isNotNull(processDefinitionInfo.getTaskBeforeTriggerSetting())){ | |
| 1193 | + BpmModelMetaInfoVO.HttpRequestSetting setting = processDefinitionInfo.getTaskBeforeTriggerSetting(); | |
| 1194 | + BpmHttpRequestUtils.executeBpmHttpRequest(processInstance, | |
| 1195 | + setting.getUrl(), | |
| 1196 | + setting.getHeader(), | |
| 1197 | + setting.getBody(), | |
| 1198 | + true, setting.getResponse()); | |
| 1199 | + } | |
| 1183 | 1200 | BpmnModel bpmnModel = modelService.getBpmnModelByDefinitionId(processInstance.getProcessDefinitionId()); |
| 1184 | 1201 | FlowElement userTaskElement = BpmnModelUtils.getFlowElementById(bpmnModel, task.getTaskDefinitionKey()); |
| 1185 | 1202 | Integer approveType = BpmnModelUtils.parseApproveType(userTaskElement); |
| ... | ... | @@ -1392,6 +1409,30 @@ public class BpmTaskServiceImpl implements BpmTaskService { |
| 1392 | 1409 | } |
| 1393 | 1410 | |
| 1394 | 1411 | @Override |
| 1412 | + public void processTaskCompleted(Task task) { | |
| 1413 | + ProcessInstance processInstance = processInstanceService.getProcessInstance(task.getProcessInstanceId()); | |
| 1414 | + if (processInstance == null) { | |
| 1415 | + log.error("[processTaskCompleted][taskId({}) 没有找到流程实例]", task.getId()); | |
| 1416 | + return; | |
| 1417 | + } | |
| 1418 | + BpmProcessDefinitionInfoDO processDefinitionInfo = bpmProcessDefinitionService. | |
| 1419 | + getProcessDefinitionInfo(processInstance.getProcessDefinitionId()); | |
| 1420 | + if (processDefinitionInfo == null) { | |
| 1421 | + log.error("[processTaskCompleted][processDefinitionId({}) 没有找到流程定义]", processInstance.getProcessDefinitionId()); | |
| 1422 | + return; | |
| 1423 | + } | |
| 1424 | + // 任务前置通知 | |
| 1425 | + if (ObjUtil.isNotNull(processDefinitionInfo.getTaskAfterTriggerSetting())){ | |
| 1426 | + BpmModelMetaInfoVO.HttpRequestSetting setting = processDefinitionInfo.getTaskAfterTriggerSetting(); | |
| 1427 | + BpmHttpRequestUtils.executeBpmHttpRequest(processInstance, | |
| 1428 | + setting.getUrl(), | |
| 1429 | + setting.getHeader(), | |
| 1430 | + setting.getBody(), | |
| 1431 | + true, setting.getResponse()); | |
| 1432 | + } | |
| 1433 | + } | |
| 1434 | + | |
| 1435 | + @Override | |
| 1395 | 1436 | @Transactional(rollbackFor = Exception.class) |
| 1396 | 1437 | public void processTaskTimeout(String processInstanceId, String taskDefineKey, Integer handlerType) { |
| 1397 | 1438 | ProcessInstance processInstance = processInstanceService.getProcessInstance(processInstanceId); | ... | ... |