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

This commit is contained in:
jason 2024-06-08 11:03:06 +08:00
parent 5c2fcdce15
commit 479d664a63
6 changed files with 18 additions and 21 deletions

View File

@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple;
import cn.iocoder.yudao.framework.common.validation.InEnum;
import cn.iocoder.yudao.module.bpm.enums.definition.BpmSimpleModelNodeType;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotEmpty;
@ -46,6 +47,7 @@ public class BpmSimpleModelNodeVO {
* 附加节点 Id, 该节点不从前端传入 由程序生成. 由于当个节点无法完成功能 需要附加节点来完成
* 例如 会签时需要按拒绝人数来终止流程 需要 userTask + ServiceTask 两个节点配合完成 serviceTask 由后端生成
*/
@JsonIgnore
private String attachNodeId;
// Map<String, Integer> formPermissions; 表单权限仅发起审批抄送节点会使用
// Integer approveMethod; 审批方式仅审批节点会使用

View File

@ -1,38 +1,35 @@
package cn.iocoder.yudao.module.bpm.service.task;
package cn.iocoder.yudao.module.bpm.framework.flowable.core.custom.delegate;
import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateInvoker;
import cn.iocoder.yudao.module.bpm.service.task.BpmProcessInstanceCopyService;
import jakarta.annotation.Resource;
import org.flowable.bpmn.model.FlowElement;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.JavaDelegate;
import org.springframework.stereotype.Service;
import java.util.Set;
/**
* 仿钉钉快搭各个节点 Service
* 处理抄送用户的代理
*
* @author jason
*/
@Service
public class BpmSimpleNodeService {
public class CopyUserDelegate implements JavaDelegate {
@Resource
private BpmTaskCandidateInvoker taskCandidateInvoker;
@Resource
private BpmProcessInstanceCopyService processInstanceCopyService;
/**
* 仿钉钉快搭抄送
*
* @param execution 执行的任务(ScriptTask)
*/
public Boolean copy(DelegateExecution execution) {
@Override
public void execute(DelegateExecution execution) {
// TODO @芋艿可能要考虑系统抄送没有 taskId 的情况
Set<Long> userIds = taskCandidateInvoker.calculateUsers(execution);
FlowElement currentFlowElement = execution.getCurrentFlowElement();
processInstanceCopyService.createProcessInstanceCopy(userIds, execution.getProcessInstanceId(),
currentFlowElement.getId(), currentFlowElement.getName());
return Boolean.TRUE;
}
}

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.module.bpm.framework.flowable.core.expression;
package cn.iocoder.yudao.module.bpm.framework.flowable.core.custom.delegate;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.BooleanUtil;
@ -12,12 +12,12 @@ import org.flowable.engine.delegate.JavaDelegate;
import org.springframework.stereotype.Component;
/**
* 处理会签 Service Task 代理表达式
* 处理会签 Service Task 代理
*
* @author jason
*/
@Component
public class MultiInstanceServiceTaskExpression implements JavaDelegate {
public class MultiInstanceServiceTaskDelegate implements JavaDelegate {
@Resource
private BpmProcessInstanceService processInstanceService;
@ -35,4 +35,5 @@ public class MultiInstanceServiceTaskExpression implements JavaDelegate {
BpmCommentTypeEnum.REJECT.formatComment("会签任务拒绝人数满足条件"));
}
}
}

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.module.bpm.framework.flowable.core.expression;
package cn.iocoder.yudao.module.bpm.framework.flowable.core.custom.expression;
import cn.hutool.core.lang.Assert;
import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants;

View File

@ -44,8 +44,6 @@ public class SimpleModelUtils {
*/
public static final String JOIN_GATE_WAY_NODE_ID_SUFFIX = "_join";
public static final String BPMN_SIMPLE_COPY_EXECUTION_SCRIPT = "#{bpmSimpleNodeService.copy(execution)}";
/**
* 所有审批人同意的表达式
*/
@ -371,7 +369,7 @@ public class SimpleModelUtils {
serviceTask.setId(id);
serviceTask.setName("会签服务任务");
serviceTask.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION);
serviceTask.setImplementation("${multiInstanceServiceTaskExpression}");
serviceTask.setImplementation("${multiInstanceServiceTaskDelegate}");
serviceTask.setAsynchronous(false);
addExtensionElement(serviceTask, SERVICE_TASK_ATTACH_USER_TASK_ID, node.getId());
node.setAttachNodeId(id);
@ -417,9 +415,8 @@ public class SimpleModelUtils {
ServiceTask serviceTask = new ServiceTask();
serviceTask.setId(node.getId());
serviceTask.setName(node.getName());
// TODO @jason建议用 delegateExpression原因是直接走 bpmSimpleNodeService.copy(execution) 的话万一后续抄送改实现可能比较麻烦最好是搞个独立的 bean然后它去调用抄 bpmSimpleNodeService
serviceTask.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION);
serviceTask.setImplementation(BPMN_SIMPLE_COPY_EXECUTION_SCRIPT);
serviceTask.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION);
serviceTask.setImplementation("${copyUserDelegate}");
// 添加抄送候选人元素
addCandidateElements(MapUtil.getInt(node.getAttributes(), BpmnModelConstants.USER_TASK_CANDIDATE_STRATEGY),

View File

@ -47,7 +47,7 @@ public class BpmProcessInstanceCopyServiceImpl implements BpmProcessInstanceCopy
// TODO @芋艿这里多加了一个 name
@Override
public void createProcessInstanceCopy(Collection<Long> userIds, String processInstanceId, String taskId, String taskName) {
// 1.1 校验任务存在 暂时去掉这个校验. 因为任务可能仿钉钉快搭的抄送节点(ScriptTask) TODO jason抄送节点会没有来源的 taskId @芋艿 是否校验一下 传递进来的 id 不为空就行
// 1.1 校验任务存在 暂时去掉这个校验. 因为任务可能仿钉钉快搭的抄送节点(UserTask) TODO jason抄送节点会没有来源的 taskId @芋艿 是否校验一下 传递进来的 id 不为空就行
// Task task = taskService.getTask(taskId);
// if (ObjectUtil.isNull(task)) {
// throw exception(ErrorCodeConstants.TASK_NOT_EXISTS);