Commit 0db7796c62fceb766abbde09893ffb601c240f59
1 parent
dff1ff90
仿钉钉流程设计- code review 修改
Showing
3 changed files
with
15 additions
and
19 deletions
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/listener/BpmTimerFiredEventListener.java
| @@ -80,7 +80,7 @@ public class BpmTimerFiredEventListener extends AbstractFlowableEngineEventListe | @@ -80,7 +80,7 @@ public class BpmTimerFiredEventListener extends AbstractFlowableEngineEventListe | ||
| 80 | BpmUserTaskTimeoutActionEnum userTaskTimeoutAction = BpmUserTaskTimeoutActionEnum.actionOf(timeoutAction); | 80 | BpmUserTaskTimeoutActionEnum userTaskTimeoutAction = BpmUserTaskTimeoutActionEnum.actionOf(timeoutAction); |
| 81 | if (userTaskTimeoutAction != null) { | 81 | if (userTaskTimeoutAction != null) { |
| 82 | // 查询超时未处理的任务 TODO 加签的情况会不会有问题 ??? | 82 | // 查询超时未处理的任务 TODO 加签的情况会不会有问题 ??? |
| 83 | - List<Task> taskList = bpmTaskService.getAssignedTaskListByConditions(processInstanceId, null, taskDefKey); | 83 | + List<Task> taskList = bpmTaskService.getTaskListByProcessInstanceIdAndAssigned(processInstanceId, null, taskDefKey); |
| 84 | taskList.forEach(task -> { | 84 | taskList.forEach(task -> { |
| 85 | // 自动提醒 | 85 | // 自动提醒 |
| 86 | if (userTaskTimeoutAction == BpmUserTaskTimeoutActionEnum.AUTO_REMINDER) { | 86 | if (userTaskTimeoutAction == BpmUserTaskTimeoutActionEnum.AUTO_REMINDER) { |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskService.java
| @@ -135,7 +135,7 @@ public interface BpmTaskService { | @@ -135,7 +135,7 @@ public interface BpmTaskService { | ||
| 135 | * @param executionId execution Id | 135 | * @param executionId execution Id |
| 136 | * @param taskDefineKey 任务定义 Key | 136 | * @param taskDefineKey 任务定义 Key |
| 137 | */ | 137 | */ |
| 138 | - List<Task> getAssignedTaskListByConditions(String processInstanceId, String executionId, String taskDefineKey); | 138 | + List<Task> getTaskListByProcessInstanceIdAndAssigned(String processInstanceId, String executionId, String taskDefineKey); |
| 139 | 139 | ||
| 140 | /** | 140 | /** |
| 141 | * 获取当前任务的可回退的 UserTask 集合 | 141 | * 获取当前任务的可回退的 UserTask 集合 |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java
| @@ -5,6 +5,7 @@ import cn.hutool.core.util.ArrayUtil; | @@ -5,6 +5,7 @@ import cn.hutool.core.util.ArrayUtil; | ||
| 5 | import cn.hutool.core.util.IdUtil; | 5 | import cn.hutool.core.util.IdUtil; |
| 6 | import cn.hutool.core.util.ObjectUtil; | 6 | import cn.hutool.core.util.ObjectUtil; |
| 7 | import cn.hutool.core.util.StrUtil; | 7 | import cn.hutool.core.util.StrUtil; |
| 8 | +import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants; | ||
| 8 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 9 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 9 | import cn.iocoder.yudao.framework.common.util.date.DateUtils; | 10 | import cn.iocoder.yudao.framework.common.util.date.DateUtils; |
| 10 | import cn.iocoder.yudao.framework.common.util.number.NumberUtils; | 11 | import cn.iocoder.yudao.framework.common.util.number.NumberUtils; |
| @@ -353,34 +354,30 @@ public class BpmTaskServiceImpl implements BpmTaskService { | @@ -353,34 +354,30 @@ public class BpmTaskServiceImpl implements BpmTaskService { | ||
| 353 | return; | 354 | return; |
| 354 | } else if (userTaskRejectHandlerType == BpmUserTaskRejectHandlerType.FINISH_PROCESS_BY_REJECT_RATIO) { | 355 | } else if (userTaskRejectHandlerType == BpmUserTaskRejectHandlerType.FINISH_PROCESS_BY_REJECT_RATIO) { |
| 355 | // 3.3 按拒绝人数比例终止流程 | 356 | // 3.3 按拒绝人数比例终止流程 |
| 356 | - // TODO @jason:建议抛出系统异常 | ||
| 357 | if (!flowElement.hasMultiInstanceLoopCharacteristics()) { | 357 | if (!flowElement.hasMultiInstanceLoopCharacteristics()) { |
| 358 | - throw exception(TASK_REJECT_HANDLER_TYPE_BY_REJECT_RATIO_ERROR); | 358 | + log.error("[rejectTask] 用户任务拒绝处理类型配置错误, 按拒绝人数终止流程只能用于会签任务"); |
| 359 | + throw exception(GlobalErrorCodeConstants.ERROR_CONFIGURATION); | ||
| 359 | } | 360 | } |
| 361 | + // 获取并行任务总数 | ||
| 360 | Execution execution = runtimeService.createExecutionQuery().processInstanceId(task.getProcessInstanceId()) | 362 | Execution execution = runtimeService.createExecutionQuery().processInstanceId(task.getProcessInstanceId()) |
| 361 | .executionId(task.getExecutionId()).singleResult(); | 363 | .executionId(task.getExecutionId()).singleResult(); |
| 362 | - // 获取并行任务总数 TODO @jason:这个注释,其实挪到 Execution execution 前面好,更有整体性。 | ||
| 363 | Integer nrOfInstances = runtimeService.getVariable(execution.getParentId(), "nrOfInstances", Integer.class); | 364 | Integer nrOfInstances = runtimeService.getVariable(execution.getParentId(), "nrOfInstances", Integer.class); |
| 364 | // 获取未完成任务列表 | 365 | // 获取未完成任务列表 |
| 365 | - List<Task> taskList = getAssignedTaskListByConditions(task.getProcessInstanceId(), null, | 366 | + List<Task> taskList = getTaskListByProcessInstanceIdAndAssigned(task.getProcessInstanceId(), null, |
| 366 | task.getTaskDefinitionKey()); | 367 | task.getTaskDefinitionKey()); |
| 367 | // 获取已经拒绝的任务数 | 368 | // 获取已经拒绝的任务数 |
| 368 | - int rejectNumber = 0; | ||
| 369 | - // TODO @jason: CollectionUtils.getSumValue() 替代 | ||
| 370 | - for (Task item : taskList) { | ||
| 371 | - if (Objects.equals(BpmTaskStatusEnum.REJECT.getStatus(), FlowableUtils.getTaskStatus(item))) { | ||
| 372 | - rejectNumber ++; | ||
| 373 | - } | ||
| 374 | - } | ||
| 375 | - // TODO @jason:如果这样的话,后续会不会在【已完成】里面查询不到哈?【重要!!!!】 | ||
| 376 | - // 拒绝任务后,任务分配人清空。但不能完成任务 | ||
| 377 | - taskService.setAssignee(task.getId(), ""); | 369 | + Integer rejectNumber = getSumValue(taskList, |
| 370 | + item -> Objects.equals(BpmTaskStatusEnum.REJECT.getStatus(), FlowableUtils.getTaskStatus(item)) ? 1 : 0, | ||
| 371 | + Integer::sum, 0); | ||
| 372 | +// // TODO @jason:如果这样的话,后续会不会在【已完成】里面查询不到哈?【重要!!!!】 | ||
| 373 | +// // 拒绝任务后,任务分配人清空。但不能完成任务 | ||
| 374 | +// taskService.setAssignee(task.getId(), ""); | ||
| 378 | // 不是所有人拒绝返回。 TODO 后续需要做按拒绝人数比例来判断 | 375 | // 不是所有人拒绝返回。 TODO 后续需要做按拒绝人数比例来判断 |
| 379 | if (!Objects.equals(nrOfInstances, rejectNumber)) { | 376 | if (!Objects.equals(nrOfInstances, rejectNumber)) { |
| 380 | return; | 377 | return; |
| 381 | } | 378 | } |
| 382 | } | 379 | } |
| 383 | - // 3.3 其他情况 终止流程。 TODO 后续可能会增加处理类型 | 380 | + // 3.4 其他情况 终止流程。 TODO 后续可能会增加处理类型 |
| 384 | processInstanceService.updateProcessInstanceReject(instance.getProcessInstanceId(), reqVO.getReason()); | 381 | processInstanceService.updateProcessInstanceReject(instance.getProcessInstanceId(), reqVO.getReason()); |
| 385 | } | 382 | } |
| 386 | 383 | ||
| @@ -482,9 +479,8 @@ public class BpmTaskServiceImpl implements BpmTaskService { | @@ -482,9 +479,8 @@ public class BpmTaskServiceImpl implements BpmTaskService { | ||
| 482 | return taskService.createTaskQuery().taskId(id).includeTaskLocalVariables().singleResult(); | 479 | return taskService.createTaskQuery().taskId(id).includeTaskLocalVariables().singleResult(); |
| 483 | } | 480 | } |
| 484 | 481 | ||
| 485 | - // TODO @jason:改成 getTaskListByProcessInstanceIdAndAssigned;其它条件就不写了。主要考虑,还是动名词 | ||
| 486 | @Override | 482 | @Override |
| 487 | - public List<Task> getAssignedTaskListByConditions(String processInstanceId, String executionId, String defineKey) { | 483 | + public List<Task> getTaskListByProcessInstanceIdAndAssigned(String processInstanceId, String executionId, String defineKey) { |
| 488 | Assert.notNull(processInstanceId, "processInstanceId 不能为空"); | 484 | Assert.notNull(processInstanceId, "processInstanceId 不能为空"); |
| 489 | TaskQuery taskQuery = taskService.createTaskQuery().taskAssigned().processInstanceId(processInstanceId).active() | 485 | TaskQuery taskQuery = taskService.createTaskQuery().taskAssigned().processInstanceId(processInstanceId).active() |
| 490 | .includeTaskLocalVariables(); | 486 | .includeTaskLocalVariables(); |