Commit 479d664a63f050bc9324b7c44c9f32bafaf7d25e

Authored by jason
1 parent 5c2fcdce

仿钉钉流程设计- code review 修改

yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/definition/vo/model/simple/BpmSimpleModelNodeVO.java
@@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple; @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple;
2 2
3 import cn.iocoder.yudao.framework.common.validation.InEnum; 3 import cn.iocoder.yudao.framework.common.validation.InEnum;
4 import cn.iocoder.yudao.module.bpm.enums.definition.BpmSimpleModelNodeType; 4 import cn.iocoder.yudao.module.bpm.enums.definition.BpmSimpleModelNodeType;
  5 +import com.fasterxml.jackson.annotation.JsonIgnore;
5 import com.fasterxml.jackson.annotation.JsonInclude; 6 import com.fasterxml.jackson.annotation.JsonInclude;
6 import io.swagger.v3.oas.annotations.media.Schema; 7 import io.swagger.v3.oas.annotations.media.Schema;
7 import jakarta.validation.constraints.NotEmpty; 8 import jakarta.validation.constraints.NotEmpty;
@@ -46,6 +47,7 @@ public class BpmSimpleModelNodeVO { @@ -46,6 +47,7 @@ public class BpmSimpleModelNodeVO {
46 * 附加节点 Id, 该节点不从前端传入。 由程序生成. 由于当个节点无法完成功能。 需要附加节点来完成。 47 * 附加节点 Id, 该节点不从前端传入。 由程序生成. 由于当个节点无法完成功能。 需要附加节点来完成。
47 * 例如: 会签时需要按拒绝人数来终止流程。 需要 userTask + ServiceTask 两个节点配合完成。 serviceTask 由后端生成。 48 * 例如: 会签时需要按拒绝人数来终止流程。 需要 userTask + ServiceTask 两个节点配合完成。 serviceTask 由后端生成。
48 */ 49 */
  50 + @JsonIgnore
49 private String attachNodeId; 51 private String attachNodeId;
50 // Map<String, Integer> formPermissions; 表单权限;仅发起、审批、抄送节点会使用 52 // Map<String, Integer> formPermissions; 表单权限;仅发起、审批、抄送节点会使用
51 // Integer approveMethod; 审批方式;仅审批节点会使用 53 // Integer approveMethod; 审批方式;仅审批节点会使用
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmSimpleNodeService.java renamed to yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/custom/delegate/CopyUserDelegate.java
1 -package cn.iocoder.yudao.module.bpm.service.task; 1 +package cn.iocoder.yudao.module.bpm.framework.flowable.core.custom.delegate;
2 2
3 import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateInvoker; 3 import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateInvoker;
  4 +import cn.iocoder.yudao.module.bpm.service.task.BpmProcessInstanceCopyService;
4 import jakarta.annotation.Resource; 5 import jakarta.annotation.Resource;
5 import org.flowable.bpmn.model.FlowElement; 6 import org.flowable.bpmn.model.FlowElement;
6 import org.flowable.engine.delegate.DelegateExecution; 7 import org.flowable.engine.delegate.DelegateExecution;
  8 +import org.flowable.engine.delegate.JavaDelegate;
7 import org.springframework.stereotype.Service; 9 import org.springframework.stereotype.Service;
8 10
9 import java.util.Set; 11 import java.util.Set;
10 12
11 /** 13 /**
12 - * 仿钉钉快搭各个节点 Service 14 + * 处理抄送用户的代理
13 * 15 *
14 * @author jason 16 * @author jason
15 */ 17 */
16 @Service 18 @Service
17 -public class BpmSimpleNodeService { 19 +public class CopyUserDelegate implements JavaDelegate {
18 20
19 @Resource 21 @Resource
20 private BpmTaskCandidateInvoker taskCandidateInvoker; 22 private BpmTaskCandidateInvoker taskCandidateInvoker;
21 @Resource 23 @Resource
22 private BpmProcessInstanceCopyService processInstanceCopyService; 24 private BpmProcessInstanceCopyService processInstanceCopyService;
23 25
24 - /**  
25 - * 仿钉钉快搭抄送  
26 - *  
27 - * @param execution 执行的任务(ScriptTask)  
28 - */  
29 - public Boolean copy(DelegateExecution execution) { 26 + @Override
  27 + public void execute(DelegateExecution execution) {
30 // TODO @芋艿:可能要考虑,系统抄送,没有 taskId 的情况。 28 // TODO @芋艿:可能要考虑,系统抄送,没有 taskId 的情况。
31 Set<Long> userIds = taskCandidateInvoker.calculateUsers(execution); 29 Set<Long> userIds = taskCandidateInvoker.calculateUsers(execution);
32 FlowElement currentFlowElement = execution.getCurrentFlowElement(); 30 FlowElement currentFlowElement = execution.getCurrentFlowElement();
33 processInstanceCopyService.createProcessInstanceCopy(userIds, execution.getProcessInstanceId(), 31 processInstanceCopyService.createProcessInstanceCopy(userIds, execution.getProcessInstanceId(),
34 currentFlowElement.getId(), currentFlowElement.getName()); 32 currentFlowElement.getId(), currentFlowElement.getName());
35 - return Boolean.TRUE;  
36 } 33 }
37 34
38 } 35 }
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/expression/MultiInstanceServiceTaskExpression.java renamed to yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/custom/delegate/MultiInstanceServiceTaskDelegate.java
1 -package cn.iocoder.yudao.module.bpm.framework.flowable.core.expression; 1 +package cn.iocoder.yudao.module.bpm.framework.flowable.core.custom.delegate;
2 2
3 import cn.hutool.core.lang.Assert; 3 import cn.hutool.core.lang.Assert;
4 import cn.hutool.core.util.BooleanUtil; 4 import cn.hutool.core.util.BooleanUtil;
@@ -12,12 +12,12 @@ import org.flowable.engine.delegate.JavaDelegate; @@ -12,12 +12,12 @@ import org.flowable.engine.delegate.JavaDelegate;
12 import org.springframework.stereotype.Component; 12 import org.springframework.stereotype.Component;
13 13
14 /** 14 /**
15 - * 处理会签 Service Task 代理表达式 15 + * 处理会签 Service Task 代理
16 * 16 *
17 * @author jason 17 * @author jason
18 */ 18 */
19 @Component 19 @Component
20 -public class MultiInstanceServiceTaskExpression implements JavaDelegate { 20 +public class MultiInstanceServiceTaskDelegate implements JavaDelegate {
21 21
22 @Resource 22 @Resource
23 private BpmProcessInstanceService processInstanceService; 23 private BpmProcessInstanceService processInstanceService;
@@ -35,4 +35,5 @@ public class MultiInstanceServiceTaskExpression implements JavaDelegate { @@ -35,4 +35,5 @@ public class MultiInstanceServiceTaskExpression implements JavaDelegate {
35 BpmCommentTypeEnum.REJECT.formatComment("会签任务拒绝人数满足条件")); 35 BpmCommentTypeEnum.REJECT.formatComment("会签任务拒绝人数满足条件"));
36 } 36 }
37 } 37 }
  38 +
38 } 39 }
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/expression/CompleteByRejectCountExpression.java renamed to yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/custom/expression/CompleteByRejectCountExpression.java
1 -package cn.iocoder.yudao.module.bpm.framework.flowable.core.expression; 1 +package cn.iocoder.yudao.module.bpm.framework.flowable.core.custom.expression;
2 2
3 import cn.hutool.core.lang.Assert; 3 import cn.hutool.core.lang.Assert;
4 import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants; 4 import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants;
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/SimpleModelUtils.java
@@ -44,8 +44,6 @@ public class SimpleModelUtils { @@ -44,8 +44,6 @@ public class SimpleModelUtils {
44 */ 44 */
45 public static final String JOIN_GATE_WAY_NODE_ID_SUFFIX = "_join"; 45 public static final String JOIN_GATE_WAY_NODE_ID_SUFFIX = "_join";
46 46
47 - public static final String BPMN_SIMPLE_COPY_EXECUTION_SCRIPT = "#{bpmSimpleNodeService.copy(execution)}";  
48 -  
49 /** 47 /**
50 * 所有审批人同意的表达式 48 * 所有审批人同意的表达式
51 */ 49 */
@@ -371,7 +369,7 @@ public class SimpleModelUtils { @@ -371,7 +369,7 @@ public class SimpleModelUtils {
371 serviceTask.setId(id); 369 serviceTask.setId(id);
372 serviceTask.setName("会签服务任务"); 370 serviceTask.setName("会签服务任务");
373 serviceTask.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION); 371 serviceTask.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION);
374 - serviceTask.setImplementation("${multiInstanceServiceTaskExpression}"); 372 + serviceTask.setImplementation("${multiInstanceServiceTaskDelegate}");
375 serviceTask.setAsynchronous(false); 373 serviceTask.setAsynchronous(false);
376 addExtensionElement(serviceTask, SERVICE_TASK_ATTACH_USER_TASK_ID, node.getId()); 374 addExtensionElement(serviceTask, SERVICE_TASK_ATTACH_USER_TASK_ID, node.getId());
377 node.setAttachNodeId(id); 375 node.setAttachNodeId(id);
@@ -417,9 +415,8 @@ public class SimpleModelUtils { @@ -417,9 +415,8 @@ public class SimpleModelUtils {
417 ServiceTask serviceTask = new ServiceTask(); 415 ServiceTask serviceTask = new ServiceTask();
418 serviceTask.setId(node.getId()); 416 serviceTask.setId(node.getId());
419 serviceTask.setName(node.getName()); 417 serviceTask.setName(node.getName());
420 - // TODO @jason:建议用 delegateExpression;原因是,直接走 bpmSimpleNodeService.copy(execution) 的话,万一后续抄送改实现,可能比较麻烦。最好是搞个独立的 bean,然后它去调用抄 bpmSimpleNodeService;  
421 - serviceTask.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION);  
422 - serviceTask.setImplementation(BPMN_SIMPLE_COPY_EXECUTION_SCRIPT); 418 + serviceTask.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION);
  419 + serviceTask.setImplementation("${copyUserDelegate}");
423 420
424 // 添加抄送候选人元素 421 // 添加抄送候选人元素
425 addCandidateElements(MapUtil.getInt(node.getAttributes(), BpmnModelConstants.USER_TASK_CANDIDATE_STRATEGY), 422 addCandidateElements(MapUtil.getInt(node.getAttributes(), BpmnModelConstants.USER_TASK_CANDIDATE_STRATEGY),
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmProcessInstanceCopyServiceImpl.java
@@ -47,7 +47,7 @@ public class BpmProcessInstanceCopyServiceImpl implements BpmProcessInstanceCopy @@ -47,7 +47,7 @@ public class BpmProcessInstanceCopyServiceImpl implements BpmProcessInstanceCopy
47 // TODO @芋艿:这里多加了一个 name; 47 // TODO @芋艿:这里多加了一个 name;
48 @Override 48 @Override
49 public void createProcessInstanceCopy(Collection<Long> userIds, String processInstanceId, String taskId, String taskName) { 49 public void createProcessInstanceCopy(Collection<Long> userIds, String processInstanceId, String taskId, String taskName) {
50 - // 1.1 校验任务存在 暂时去掉这个校验. 因为任务可能仿钉钉快搭的抄送节点(ScriptTask) TODO jason:抄送节点,会没有来源的 taskId 么? @芋艿 是否校验一下 传递进来的 id 不为空就行 50 + // 1.1 校验任务存在 暂时去掉这个校验. 因为任务可能仿钉钉快搭的抄送节点(UserTask) TODO jason:抄送节点,会没有来源的 taskId 么? @芋艿 是否校验一下 传递进来的 id 不为空就行
51 // Task task = taskService.getTask(taskId); 51 // Task task = taskService.getTask(taskId);
52 // if (ObjectUtil.isNull(task)) { 52 // if (ObjectUtil.isNull(task)) {
53 // throw exception(ErrorCodeConstants.TASK_NOT_EXISTS); 53 // throw exception(ErrorCodeConstants.TASK_NOT_EXISTS);