bpm:跟进最新功能(驳回、加减签)
parent
3f32c4488e
commit
110b3476a8
|
@ -0,0 +1,309 @@
|
||||||
|
package cn.iocoder.yudao.framework.flowable.core.util;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import org.flowable.bpmn.converter.BpmnXMLConverter;
|
||||||
|
import org.flowable.bpmn.model.Process;
|
||||||
|
import org.flowable.bpmn.model.*;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 流程模型转操作工具类
|
||||||
|
*/
|
||||||
|
public class BpmnModelUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据节点,获取入口连线
|
||||||
|
*
|
||||||
|
* @param source 起始节点
|
||||||
|
* @return 入口连线列表
|
||||||
|
*/
|
||||||
|
public static List<SequenceFlow> getElementIncomingFlows(FlowElement source) {
|
||||||
|
if (source instanceof FlowNode) {
|
||||||
|
return ((FlowNode) source).getIncomingFlows();
|
||||||
|
}
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据节点,获取出口连线
|
||||||
|
*
|
||||||
|
* @param source 起始节点
|
||||||
|
* @return 出口连线列表
|
||||||
|
*/
|
||||||
|
public static List<SequenceFlow> getElementOutgoingFlows(FlowElement source) {
|
||||||
|
if (source instanceof FlowNode) {
|
||||||
|
return ((FlowNode) source).getOutgoingFlows();
|
||||||
|
}
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取流程元素信息
|
||||||
|
*
|
||||||
|
* @param model bpmnModel 对象
|
||||||
|
* @param flowElementId 元素 ID
|
||||||
|
* @return 元素信息
|
||||||
|
*/
|
||||||
|
public static FlowElement getFlowElementById(BpmnModel model, String flowElementId) {
|
||||||
|
Process process = model.getMainProcess();
|
||||||
|
return process.getFlowElement(flowElementId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得 BPMN 流程中,指定的元素们
|
||||||
|
*
|
||||||
|
* @param model
|
||||||
|
* @param clazz 指定元素。例如说,{@link UserTask}、{@link Gateway} 等等
|
||||||
|
* @return 元素们
|
||||||
|
*/
|
||||||
|
public static <T extends FlowElement> List<T> getBpmnModelElements(BpmnModel model, Class<T> clazz) {
|
||||||
|
List<T> result = new ArrayList<>();
|
||||||
|
model.getProcesses().forEach(process -> {
|
||||||
|
process.getFlowElements().forEach(flowElement -> {
|
||||||
|
if (flowElement.getClass().isAssignableFrom(clazz)) {
|
||||||
|
result.add((T) flowElement);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 比较 两个bpmnModel 是否相同
|
||||||
|
* @param oldModel 老的bpmn model
|
||||||
|
* @param newModel 新的bpmn model
|
||||||
|
*/
|
||||||
|
public static boolean equals(BpmnModel oldModel, BpmnModel newModel) {
|
||||||
|
// 由于 BpmnModel 未提供 equals 方法,所以只能转成字节数组,进行比较
|
||||||
|
return Arrays.equals(getBpmnBytes(oldModel), getBpmnBytes(newModel));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 把 bpmnModel 转换成 byte[]
|
||||||
|
* @param model bpmnModel
|
||||||
|
*/
|
||||||
|
public static byte[] getBpmnBytes(BpmnModel model) {
|
||||||
|
if (model == null) {
|
||||||
|
return new byte[0];
|
||||||
|
}
|
||||||
|
BpmnXMLConverter converter = new BpmnXMLConverter();
|
||||||
|
return converter.convertToXML(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ========== 遍历相关的方法 ==========
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 找到 source 节点之前的所有用户任务节点
|
||||||
|
*
|
||||||
|
* @param source 起始节点
|
||||||
|
* @param hasSequenceFlow 已经经过的连线的 ID,用于判断线路是否重复
|
||||||
|
* @param userTaskList 已找到的用户任务节点
|
||||||
|
* @return 用户任务节点 数组
|
||||||
|
*/
|
||||||
|
public static List<UserTask> getPreviousUserTaskList(FlowElement source, Set<String> hasSequenceFlow, List<UserTask> userTaskList) {
|
||||||
|
userTaskList = userTaskList == null ? new ArrayList<>() : userTaskList;
|
||||||
|
hasSequenceFlow = hasSequenceFlow == null ? new HashSet<>() : hasSequenceFlow;
|
||||||
|
// 如果该节点为开始节点,且存在上级子节点,则顺着上级子节点继续迭代
|
||||||
|
if (source instanceof StartEvent && source.getSubProcess() != null) {
|
||||||
|
userTaskList = getPreviousUserTaskList(source.getSubProcess(), hasSequenceFlow, userTaskList);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 根据类型,获取入口连线
|
||||||
|
List<SequenceFlow> sequenceFlows = getElementIncomingFlows(source);
|
||||||
|
if (sequenceFlows == null) {
|
||||||
|
return userTaskList;
|
||||||
|
}
|
||||||
|
// 循环找到目标元素
|
||||||
|
for (SequenceFlow sequenceFlow : sequenceFlows) {
|
||||||
|
// 如果发现连线重复,说明循环了,跳过这个循环
|
||||||
|
if (hasSequenceFlow.contains(sequenceFlow.getId())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// 添加已经走过的连线
|
||||||
|
hasSequenceFlow.add(sequenceFlow.getId());
|
||||||
|
// 类型为用户节点,则新增父级节点
|
||||||
|
if (sequenceFlow.getSourceFlowElement() instanceof UserTask) {
|
||||||
|
userTaskList.add((UserTask) sequenceFlow.getSourceFlowElement());
|
||||||
|
}
|
||||||
|
// 类型为子流程,则添加子流程开始节点出口处相连的节点
|
||||||
|
if (sequenceFlow.getSourceFlowElement() instanceof SubProcess) {
|
||||||
|
// 获取子流程用户任务节点
|
||||||
|
List<UserTask> childUserTaskList = findChildProcessUserTaskList((StartEvent) ((SubProcess) sequenceFlow.getSourceFlowElement()).getFlowElements().toArray()[0], null, null);
|
||||||
|
// 如果找到节点,则说明该线路找到节点,不继续向下找,反之继续
|
||||||
|
if (CollUtil.isNotEmpty(childUserTaskList)) {
|
||||||
|
userTaskList.addAll(childUserTaskList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 继续迭代
|
||||||
|
userTaskList = getPreviousUserTaskList(sequenceFlow.getSourceFlowElement(), hasSequenceFlow, userTaskList);
|
||||||
|
}
|
||||||
|
return userTaskList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 迭代获取子流程用户任务节点
|
||||||
|
*
|
||||||
|
* @param source 起始节点
|
||||||
|
* @param hasSequenceFlow 已经经过的连线的 ID,用于判断线路是否重复
|
||||||
|
* @param userTaskList 需要撤回的用户任务列表
|
||||||
|
* @return 用户任务节点
|
||||||
|
*/
|
||||||
|
public static List<UserTask> findChildProcessUserTaskList(FlowElement source, Set<String> hasSequenceFlow, List<UserTask> userTaskList) {
|
||||||
|
hasSequenceFlow = hasSequenceFlow == null ? new HashSet<>() : hasSequenceFlow;
|
||||||
|
userTaskList = userTaskList == null ? new ArrayList<>() : userTaskList;
|
||||||
|
|
||||||
|
// 根据类型,获取出口连线
|
||||||
|
List<SequenceFlow> sequenceFlows = getElementOutgoingFlows(source);
|
||||||
|
if (sequenceFlows == null) {
|
||||||
|
return userTaskList;
|
||||||
|
}
|
||||||
|
// 循环找到目标元素
|
||||||
|
for (SequenceFlow sequenceFlow : sequenceFlows) {
|
||||||
|
// 如果发现连线重复,说明循环了,跳过这个循环
|
||||||
|
if (hasSequenceFlow.contains(sequenceFlow.getId())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// 添加已经走过的连线
|
||||||
|
hasSequenceFlow.add(sequenceFlow.getId());
|
||||||
|
// 如果为用户任务类型,且任务节点的 Key 正在运行的任务中存在,添加
|
||||||
|
if (sequenceFlow.getTargetFlowElement() instanceof UserTask) {
|
||||||
|
userTaskList.add((UserTask) sequenceFlow.getTargetFlowElement());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// 如果节点为子流程节点情况,则从节点中的第一个节点开始获取
|
||||||
|
if (sequenceFlow.getTargetFlowElement() instanceof SubProcess) {
|
||||||
|
List<UserTask> childUserTaskList = findChildProcessUserTaskList((FlowElement) (((SubProcess) sequenceFlow.getTargetFlowElement()).getFlowElements().toArray()[0]), hasSequenceFlow, null);
|
||||||
|
// 如果找到节点,则说明该线路找到节点,不继续向下找,反之继续
|
||||||
|
if (CollUtil.isNotEmpty(childUserTaskList)) {
|
||||||
|
userTaskList.addAll(childUserTaskList);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 继续迭代
|
||||||
|
userTaskList = findChildProcessUserTaskList(sequenceFlow.getTargetFlowElement(), hasSequenceFlow, userTaskList);
|
||||||
|
}
|
||||||
|
return userTaskList;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 迭代从后向前扫描,判断目标节点相对于当前节点是否是串行
|
||||||
|
* 不存在直接回退到子流程中的情况,但存在从子流程出去到父流程情况
|
||||||
|
*
|
||||||
|
* @param source 起始节点
|
||||||
|
* @param target 目标节点
|
||||||
|
* @param visitedElements 已经经过的连线的 ID,用于判断线路是否重复
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public static boolean isSequentialReachable(FlowElement source, FlowElement target, Set<String> visitedElements) {
|
||||||
|
visitedElements = visitedElements == null ? new HashSet<>() : visitedElements;
|
||||||
|
// 不能是开始事件和子流程
|
||||||
|
if (source instanceof StartEvent && isInEventSubprocess(source)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 根据类型,获取入口连线
|
||||||
|
List<SequenceFlow> sequenceFlows = getElementIncomingFlows(source);
|
||||||
|
if (CollUtil.isEmpty(sequenceFlows)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// 循环找到目标元素
|
||||||
|
for (SequenceFlow sequenceFlow : sequenceFlows) {
|
||||||
|
// 如果发现连线重复,说明循环了,跳过这个循环
|
||||||
|
if (visitedElements.contains(sequenceFlow.getId())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// 添加已经走过的连线
|
||||||
|
visitedElements.add(sequenceFlow.getId());
|
||||||
|
// 这条线路存在目标节点,这条线路完成,进入下个线路
|
||||||
|
FlowElement sourceFlowElement = sequenceFlow.getSourceFlowElement();
|
||||||
|
if (target.getId().equals(sourceFlowElement.getId())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// 如果目标节点为并行网关,则不继续
|
||||||
|
if (sourceFlowElement instanceof ParallelGateway) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// 否则就继续迭代
|
||||||
|
if (!isSequentialReachable(sourceFlowElement, target, visitedElements)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断当前节点是否属于不同的子流程
|
||||||
|
*
|
||||||
|
* @param flowElement 被判断的节点
|
||||||
|
* @return true 表示属于子流程
|
||||||
|
*/
|
||||||
|
private static boolean isInEventSubprocess(FlowElement flowElement) {
|
||||||
|
FlowElementsContainer flowElementsContainer = flowElement.getParentContainer();
|
||||||
|
while (flowElementsContainer != null) {
|
||||||
|
if (flowElementsContainer instanceof EventSubProcess) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flowElementsContainer instanceof FlowElement) {
|
||||||
|
flowElementsContainer = ((FlowElement) flowElementsContainer).getParentContainer();
|
||||||
|
} else {
|
||||||
|
flowElementsContainer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据正在运行的任务节点,迭代获取子级任务节点列表,向后找
|
||||||
|
*
|
||||||
|
* @param source 起始节点
|
||||||
|
* @param runTaskKeyList 正在运行的任务 Key,用于校验任务节点是否是正在运行的节点
|
||||||
|
* @param hasSequenceFlow 已经经过的连线的 ID,用于判断线路是否重复
|
||||||
|
* @param userTaskList 需要撤回的用户任务列表
|
||||||
|
* @return 子级任务节点列表
|
||||||
|
*/
|
||||||
|
public static List<UserTask> iteratorFindChildUserTasks(FlowElement source, List<String> runTaskKeyList,
|
||||||
|
Set<String> hasSequenceFlow, List<UserTask> userTaskList) {
|
||||||
|
hasSequenceFlow = hasSequenceFlow == null ? new HashSet<>() : hasSequenceFlow;
|
||||||
|
userTaskList = userTaskList == null ? new ArrayList<>() : userTaskList;
|
||||||
|
// 如果该节点为开始节点,且存在上级子节点,则顺着上级子节点继续迭代
|
||||||
|
if (source instanceof StartEvent && source.getSubProcess() != null) {
|
||||||
|
userTaskList = iteratorFindChildUserTasks(source.getSubProcess(), runTaskKeyList, hasSequenceFlow, userTaskList);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 根据类型,获取出口连线
|
||||||
|
List<SequenceFlow> sequenceFlows = getElementOutgoingFlows(source);
|
||||||
|
if (sequenceFlows == null) {
|
||||||
|
return userTaskList;
|
||||||
|
}
|
||||||
|
// 循环找到目标元素
|
||||||
|
for (SequenceFlow sequenceFlow : sequenceFlows) {
|
||||||
|
// 如果发现连线重复,说明循环了,跳过这个循环
|
||||||
|
if (hasSequenceFlow.contains(sequenceFlow.getId())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// 添加已经走过的连线
|
||||||
|
hasSequenceFlow.add(sequenceFlow.getId());
|
||||||
|
// 如果为用户任务类型,且任务节点的 Key 正在运行的任务中存在,添加
|
||||||
|
if (sequenceFlow.getTargetFlowElement() instanceof UserTask && runTaskKeyList.contains((sequenceFlow.getTargetFlowElement()).getId())) {
|
||||||
|
userTaskList.add((UserTask) sequenceFlow.getTargetFlowElement());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// 如果节点为子流程节点情况,则从节点中的第一个节点开始获取
|
||||||
|
if (sequenceFlow.getTargetFlowElement() instanceof SubProcess) {
|
||||||
|
List<UserTask> childUserTaskList = iteratorFindChildUserTasks((FlowElement) (((SubProcess) sequenceFlow.getTargetFlowElement()).getFlowElements().toArray()[0]), runTaskKeyList, hasSequenceFlow, null);
|
||||||
|
// 如果找到节点,则说明该线路找到节点,不继续向下找,反之继续
|
||||||
|
if (CollUtil.isNotEmpty(childUserTaskList)) {
|
||||||
|
userTaskList.addAll(childUserTaskList);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 继续迭代
|
||||||
|
userTaskList = iteratorFindChildUserTasks(sequenceFlow.getTargetFlowElement(), runTaskKeyList, hasSequenceFlow, userTaskList);
|
||||||
|
}
|
||||||
|
return userTaskList;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,14 +1,7 @@
|
||||||
package cn.iocoder.yudao.framework.flowable.core.util;
|
package cn.iocoder.yudao.framework.flowable.core.util;
|
||||||
|
|
||||||
import org.flowable.bpmn.converter.BpmnXMLConverter;
|
|
||||||
import org.flowable.bpmn.model.BpmnModel;
|
|
||||||
import org.flowable.bpmn.model.FlowElement;
|
|
||||||
import org.flowable.common.engine.impl.identity.Authentication;
|
import org.flowable.common.engine.impl.identity.Authentication;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Flowable 相关的工具方法
|
* Flowable 相关的工具方法
|
||||||
*
|
*
|
||||||
|
@ -26,49 +19,6 @@ public class FlowableUtils {
|
||||||
Authentication.setAuthenticatedUserId(null);
|
Authentication.setAuthenticatedUserId(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ========== BPMN 相关的工具方法 ==========
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获得 BPMN 流程中,指定的元素们
|
|
||||||
*
|
|
||||||
* @param model
|
|
||||||
* @param clazz 指定元素。例如说,{@link org.flowable.bpmn.model.UserTask}、{@link org.flowable.bpmn.model.Gateway} 等等
|
|
||||||
* @return 元素们
|
|
||||||
*/
|
|
||||||
public static <T extends FlowElement> List<T> getBpmnModelElements(BpmnModel model, Class<T> clazz) {
|
|
||||||
List<T> result = new ArrayList<>();
|
|
||||||
model.getProcesses().forEach(process -> {
|
|
||||||
process.getFlowElements().forEach(flowElement -> {
|
|
||||||
if (flowElement.getClass().isAssignableFrom(clazz)) {
|
|
||||||
result.add((T) flowElement);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 比较 两个bpmnModel 是否相同
|
|
||||||
* @param oldModel 老的bpmn model
|
|
||||||
* @param newModel 新的bpmn model
|
|
||||||
*/
|
|
||||||
public static boolean equals(BpmnModel oldModel, BpmnModel newModel) {
|
|
||||||
// 由于 BpmnModel 未提供 equals 方法,所以只能转成字节数组,进行比较
|
|
||||||
return Arrays.equals(getBpmnBytes(oldModel), getBpmnBytes(newModel));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 把 bpmnModel 转换成 byte[]
|
|
||||||
* @param model bpmnModel
|
|
||||||
*/
|
|
||||||
public static byte[] getBpmnBytes(BpmnModel model) {
|
|
||||||
if (model == null) {
|
|
||||||
return new byte[0];
|
|
||||||
}
|
|
||||||
BpmnXMLConverter converter = new BpmnXMLConverter();
|
|
||||||
return converter.convertToXML(model);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ========== Execution 相关的工具方法 ==========
|
// ========== Execution 相关的工具方法 ==========
|
||||||
|
|
||||||
public static String formatCollectionVariable(String activityId) {
|
public static String formatCollectionVariable(String activityId) {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package cn.iocoder.yudao.module.bpm.api.task;
|
package cn.iocoder.yudao.module.bpm.api.task;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||||
import cn.iocoder.yudao.module.bpm.api.task.dto.BpmProcessInstanceCreateReqDTO;
|
import cn.iocoder.yudao.module.bpm.api.task.dto.BpmProcessInstanceCreateReqDTO;
|
||||||
import cn.iocoder.yudao.module.bpm.enums.ApiConstants;
|
import cn.iocoder.yudao.module.bpm.enums.ApiConstants;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
@ -21,7 +22,7 @@ public interface BpmProcessInstanceApi {
|
||||||
@PostMapping(PREFIX + "/create")
|
@PostMapping(PREFIX + "/create")
|
||||||
@Operation(summary = "创建流程实例(提供给内部),返回实例编号")
|
@Operation(summary = "创建流程实例(提供给内部),返回实例编号")
|
||||||
@Parameter(name = "userId", description = "用户编号", required = true, example = "1")
|
@Parameter(name = "userId", description = "用户编号", required = true, example = "1")
|
||||||
String createProcessInstance(@RequestParam("userId") Long userId,
|
CommonResult<String> createProcessInstance(@RequestParam("userId") Long userId,
|
||||||
@Valid @RequestBody BpmProcessInstanceCreateReqDTO reqDTO);
|
@Valid @RequestBody BpmProcessInstanceCreateReqDTO reqDTO);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import cn.iocoder.yudao.framework.common.exception.ErrorCode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bpm 错误码枚举类
|
* Bpm 错误码枚举类
|
||||||
*
|
* <p>
|
||||||
* bpm 系统,使用 1-009-000-000 段
|
* bpm 系统,使用 1-009-000-000 段
|
||||||
*/
|
*/
|
||||||
public interface ErrorCodeConstants {
|
public interface ErrorCodeConstants {
|
||||||
|
@ -43,8 +43,17 @@ public interface ErrorCodeConstants {
|
||||||
ErrorCode PROCESS_INSTANCE_CANCEL_FAIL_NOT_SELF = new ErrorCode(1_009_004_002, "流程取消失败,该流程不是你发起的");
|
ErrorCode PROCESS_INSTANCE_CANCEL_FAIL_NOT_SELF = new ErrorCode(1_009_004_002, "流程取消失败,该流程不是你发起的");
|
||||||
|
|
||||||
// ========== 流程任务 1-009-005-000 ==========
|
// ========== 流程任务 1-009-005-000 ==========
|
||||||
ErrorCode TASK_COMPLETE_FAIL_NOT_EXISTS = new ErrorCode(1_009_005_000, "审批任务失败,原因:该任务不处于未审批");
|
ErrorCode TASK_OPERATE_FAIL_ASSIGN_NOT_SELF = new ErrorCode(1_009_005_001, "操作失败,原因:该任务的审批人不是你");
|
||||||
ErrorCode TASK_COMPLETE_FAIL_ASSIGN_NOT_SELF = new ErrorCode(1_009_005_001, "审批任务失败,原因:该任务的审批人不是你");
|
ErrorCode TASK_NOT_EXISTS = new ErrorCode(1_009_005_002, "流程任务不存在");
|
||||||
|
ErrorCode TASK_IS_PENDING = new ErrorCode(1_009_005_003, "当前任务处于挂起状态,不能操作");
|
||||||
|
ErrorCode TASK_TARGET_NODE_NOT_EXISTS = new ErrorCode(1_009_005_004, " 目标节点不存在");
|
||||||
|
ErrorCode TASK_RETURN_FAIL_SOURCE_TARGET_ERROR = new ErrorCode(1_009_005_006, "回退任务失败,目标节点是在并行网关上或非同一路线上,不可跳转");
|
||||||
|
ErrorCode TASK_DELEGATE_FAIL_USER_REPEAT = new ErrorCode(1_009_005_007, "任务委派失败,委派人和当前审批人为同一人");
|
||||||
|
ErrorCode TASK_DELEGATE_FAIL_USER_NOT_EXISTS = new ErrorCode(1_009_005_008, "任务委派失败,被委派人不存在");
|
||||||
|
ErrorCode TASK_ADD_SIGN_USER_NOT_EXIST = new ErrorCode(1_009_005_009, "任务加签:选择的用户不存在");
|
||||||
|
ErrorCode TASK_ADD_SIGN_TYPE_ERROR = new ErrorCode(1_009_005_010, "任务加签:当前任务已经{},不能{}");
|
||||||
|
ErrorCode TASK_ADD_SIGN_USER_REPEAT = new ErrorCode(1_009_005_011, "任务加签失败,加签人与现有审批人[{}]重复");
|
||||||
|
ErrorCode TASK_SUB_SIGN_NO_PARENT = new ErrorCode(1_009_005_011, "任务减签失败,被减签的任务必须是通过加签生成的任务");
|
||||||
|
|
||||||
// ========== 流程任务分配规则 1-009-006-000 ==========
|
// ========== 流程任务分配规则 1-009-006-000 ==========
|
||||||
ErrorCode TASK_ASSIGN_RULE_EXISTS = new ErrorCode(1_009_006_000, "流程({}) 的任务({}) 已经存在分配规则");
|
ErrorCode TASK_ASSIGN_RULE_EXISTS = new ErrorCode(1_009_006_000, "流程({}) 的任务({}) 已经存在分配规则");
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
package cn.iocoder.yudao.module.bpm.enums.task;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 流程任务 -- comment类型枚举
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
|
public enum BpmCommentTypeEnum {
|
||||||
|
|
||||||
|
APPROVE(1, "通过", ""),
|
||||||
|
REJECT(2, "不通过", ""),
|
||||||
|
CANCEL(3, "已取消", ""),
|
||||||
|
BACK(4, "退回", ""),
|
||||||
|
DELEGATE(5, "委派", ""),
|
||||||
|
ADD_SIGN(6, "加签", "[{}]{}给了[{}],理由为:{}"),
|
||||||
|
SUB_SIGN(7, "减签", "[{}]操作了【减签】,审批人[{}]的任务被取消"),
|
||||||
|
;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 操作类型
|
||||||
|
*/
|
||||||
|
private final Integer type;
|
||||||
|
/**
|
||||||
|
* 操作名字
|
||||||
|
*/
|
||||||
|
private final String name;
|
||||||
|
/**
|
||||||
|
* 操作描述
|
||||||
|
*/
|
||||||
|
private final String comment;
|
||||||
|
|
||||||
|
}
|
|
@ -4,6 +4,9 @@ import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 流程实例的结果
|
* 流程实例的结果
|
||||||
*
|
*
|
||||||
|
@ -20,11 +23,35 @@ public enum BpmProcessInstanceResultEnum {
|
||||||
|
|
||||||
// ========== 流程任务独有的状态 ==========
|
// ========== 流程任务独有的状态 ==========
|
||||||
|
|
||||||
BACK(5, "退回/驳回");
|
BACK(5, "驳回"), // 退回
|
||||||
|
DELEGATE(6, "委派"),
|
||||||
|
/**
|
||||||
|
* 【加签】源任务已经审批完成,但是它使用了后加签,后加签的任务未完成,源任务就会是这个状态
|
||||||
|
* 相当于是 通过 APPROVE 的特殊状态
|
||||||
|
* 例如:A审批, A 后加签了 B,并且审批通过了任务,但是 B 还未审批,则当前任务状态为“待后加签任务完成”
|
||||||
|
*/
|
||||||
|
SIGN_AFTER(7, "待后加签任务完成"),
|
||||||
|
/**
|
||||||
|
* 【加签】源任务未审批,但是向前加签了,所以源任务状态变为“待前加签任务完成”
|
||||||
|
* 相当于是 处理中 PROCESS 的特殊状态
|
||||||
|
* 例如:A 审批, A 前加签了 B,B 还未审核
|
||||||
|
*/
|
||||||
|
SIGN_BEFORE(8, "待前加签任务完成"),
|
||||||
|
/**
|
||||||
|
* 【加签】后加签任务被创建时的初始状态
|
||||||
|
* 相当于是 处理中 PROCESS 的特殊状态
|
||||||
|
* 因为需要源任务先完成,才能到后加签的人来审批,所以加了一个状态区分
|
||||||
|
*/
|
||||||
|
WAIT_BEFORE_TASK(9, "待前置任务完成");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 能被减签的状态
|
||||||
|
*/
|
||||||
|
public static final List<Integer> CAN_SUB_SIGN_STATUS_LIST = Arrays.asList(PROCESS.result, WAIT_BEFORE_TASK.result);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 结果
|
* 结果
|
||||||
*
|
* <p>
|
||||||
* 如果新增时,注意 {@link #isEndResult(Integer)} 是否需要变更
|
* 如果新增时,注意 {@link #isEndResult(Integer)} 是否需要变更
|
||||||
*/
|
*/
|
||||||
private final Integer result;
|
private final Integer result;
|
||||||
|
@ -35,14 +62,16 @@ public enum BpmProcessInstanceResultEnum {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 判断该结果是否已经处于 End 最终结果
|
* 判断该结果是否已经处于 End 最终结果
|
||||||
*
|
* <p>
|
||||||
* 主要用于一些结果更新的逻辑,如果已经是最终结果,就不再进行更新
|
* 主要用于一些结果更新的逻辑,如果已经是最终结果,就不再进行更新
|
||||||
*
|
*
|
||||||
* @param result 结果
|
* @param result 结果
|
||||||
* @return 是否
|
* @return 是否
|
||||||
*/
|
*/
|
||||||
public static boolean isEndResult(Integer result) {
|
public static boolean isEndResult(Integer result) {
|
||||||
return ObjectUtils.equalsAny(result, APPROVE.getResult(), REJECT.getResult(), CANCEL.getResult(), BACK.getResult());
|
return ObjectUtils.equalsAny(result, APPROVE.getResult(), REJECT.getResult(),
|
||||||
|
CANCEL.getResult(), BACK.getResult(),
|
||||||
|
SIGN_AFTER.getResult());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
package cn.iocoder.yudao.module.bpm.enums.task;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 流程任务 -- 加签类型枚举类型
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
|
public enum BpmTaskAddSignTypeEnum {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 向前加签,需要前置任务审批完成,才回到原审批人
|
||||||
|
*/
|
||||||
|
BEFORE("before", "向前加签"),
|
||||||
|
/**
|
||||||
|
* 向后加签,需要后置任务全部审批完,才会通过原审批人节点
|
||||||
|
*/
|
||||||
|
AFTER("after", "向后加签"),
|
||||||
|
/**
|
||||||
|
* 创建后置加签时的过度状态,用于控制向后加签生成的任务状态
|
||||||
|
*/
|
||||||
|
AFTER_CHILDREN_TASK("afterChildrenTask", "向后加签生成的子任务");
|
||||||
|
|
||||||
|
private final String type;
|
||||||
|
|
||||||
|
private final String desc;
|
||||||
|
|
||||||
|
public static String formatDesc(String type) {
|
||||||
|
for (BpmTaskAddSignTypeEnum value : values()) {
|
||||||
|
if (value.type.equals(type)) {
|
||||||
|
return value.desc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -86,18 +86,6 @@
|
||||||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Job 定时任务相关 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>cn.iocoder.cloud</groupId>
|
|
||||||
<artifactId>yudao-spring-boot-starter-job</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- 消息队列相关 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>cn.iocoder.cloud</groupId>
|
|
||||||
<artifactId>yudao-spring-boot-starter-mq</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- 服务保障相关 TODO 芋艿:暂时去掉 -->
|
<!-- 服务保障相关 TODO 芋艿:暂时去掉 -->
|
||||||
<!-- <dependency>-->
|
<!-- <dependency>-->
|
||||||
<!-- <groupId>cn.iocoder.cloud</groupId>-->
|
<!-- <groupId>cn.iocoder.cloud</groupId>-->
|
||||||
|
|
|
@ -1,20 +1,23 @@
|
||||||
package cn.iocoder.yudao.module.bpm.api.task;
|
package cn.iocoder.yudao.module.bpm.api.task;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||||
import cn.iocoder.yudao.module.bpm.api.task.dto.BpmProcessInstanceCreateReqDTO;
|
import cn.iocoder.yudao.module.bpm.api.task.dto.BpmProcessInstanceCreateReqDTO;
|
||||||
import cn.iocoder.yudao.module.bpm.service.task.BpmProcessInstanceService;
|
import cn.iocoder.yudao.module.bpm.service.task.BpmProcessInstanceService;
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
|
|
||||||
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Flowable 流程实例 Api 实现类
|
* Flowable 流程实例 Api 实现类
|
||||||
*
|
*
|
||||||
* @author 芋道源码
|
* @author 芋道源码
|
||||||
* @author jason
|
* @author jason
|
||||||
*/
|
*/
|
||||||
@Service
|
@RestController
|
||||||
@Validated
|
@Validated
|
||||||
public class BpmProcessInstanceApiImpl implements BpmProcessInstanceApi {
|
public class BpmProcessInstanceApiImpl implements BpmProcessInstanceApi {
|
||||||
|
|
||||||
|
@ -22,7 +25,8 @@ public class BpmProcessInstanceApiImpl implements BpmProcessInstanceApi {
|
||||||
private BpmProcessInstanceService processInstanceService;
|
private BpmProcessInstanceService processInstanceService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String createProcessInstance(Long userId, @Valid BpmProcessInstanceCreateReqDTO reqDTO) {
|
public CommonResult<String> createProcessInstance(Long userId, @Valid BpmProcessInstanceCreateReqDTO reqDTO) {
|
||||||
return processInstanceService.createProcessInstance(userId, reqDTO);
|
return success(processInstanceService.createProcessInstance(userId, reqDTO));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,4 +74,52 @@ public class BpmTaskController {
|
||||||
return success(true);
|
return success(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/return-list")
|
||||||
|
@Operation(summary = "获取所有可回退的节点", description = "用于【流程详情】的【回退】按钮")
|
||||||
|
@Parameter(name = "taskId", description = "当前任务ID", required = true)
|
||||||
|
@PreAuthorize("@ss.hasPermission('bpm:task:update')")
|
||||||
|
public CommonResult<List<BpmTaskSimpleRespVO>> getReturnList(@RequestParam("taskId") String taskId) {
|
||||||
|
return success(taskService.getReturnTaskList(taskId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/return")
|
||||||
|
@Operation(summary = "回退任务", description = "用于【流程详情】的【回退】按钮")
|
||||||
|
@PreAuthorize("@ss.hasPermission('bpm:task:update')")
|
||||||
|
public CommonResult<Boolean> returnTask(@Valid @RequestBody BpmTaskReturnReqVO reqVO) {
|
||||||
|
taskService.returnTask(getLoginUserId(), reqVO);
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/delegate")
|
||||||
|
@Operation(summary = "委派任务", description = "用于【流程详情】的【委派】按钮。和向前【加签】有点像,唯一区别是【委托】没有单独创立任务")
|
||||||
|
@PreAuthorize("@ss.hasPermission('bpm:task:update')")
|
||||||
|
public CommonResult<Boolean> delegateTask(@Valid @RequestBody BpmTaskDelegateReqVO reqVO) {
|
||||||
|
taskService.delegateTask(getLoginUserId(), reqVO);
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/create-sign")
|
||||||
|
@Operation(summary = "加签", description = "before 前加签,after 后加签")
|
||||||
|
@PreAuthorize("@ss.hasPermission('bpm:task:update')")
|
||||||
|
public CommonResult<Boolean> createSignTask(@Valid @RequestBody BpmTaskAddSignReqVO reqVO) {
|
||||||
|
taskService.createSignTask(getLoginUserId(), reqVO);
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/delete-sign")
|
||||||
|
@Operation(summary = "减签")
|
||||||
|
@PreAuthorize("@ss.hasPermission('bpm:task:update')")
|
||||||
|
public CommonResult<Boolean> deleteSignTask(@Valid @RequestBody BpmTaskSubSignReqVO reqVO) {
|
||||||
|
taskService.deleteSignTask(getLoginUserId(), reqVO);
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("children-list")
|
||||||
|
@Operation(summary = "获取能被减签的任务")
|
||||||
|
@Parameter(name = "parentId", description = "父级任务 ID", required = true)
|
||||||
|
@PreAuthorize("@ss.hasPermission('bpm:task:update')")
|
||||||
|
public CommonResult<List<BpmTaskSubSignRespVO>> getChildrenTaskList(@RequestParam("parentId") String parentId) {
|
||||||
|
return success(taskService.getChildrenTaskList(parentId));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
package cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotEmpty;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
// TODO @海洋:类名,应该是 create 哈
|
||||||
|
@Schema(description = "管理后台 - 加签流程任务的 Request VO")
|
||||||
|
@Data
|
||||||
|
public class BpmTaskAddSignReqVO {
|
||||||
|
|
||||||
|
@Schema(description = "需要加签的任务 ID")
|
||||||
|
@NotEmpty(message = "任务编号不能为空")
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
@Schema(description = "加签的用户 ID")
|
||||||
|
@NotEmpty(message = "加签用户 ID 不能为空")
|
||||||
|
private Set<Long> userIdList;
|
||||||
|
|
||||||
|
@Schema(description = "加签类型,before 向前加签,after 向后加签")
|
||||||
|
@NotEmpty(message = "加签类型不能为空")
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
@Schema(description = "加签原因")
|
||||||
|
@NotEmpty(message = "加签原因不能为空")
|
||||||
|
private String reason;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
package cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotEmpty;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
@Schema(description = "管理后台 - 委派流程任务的 Request VO")
|
||||||
|
@Data
|
||||||
|
public class BpmTaskDelegateReqVO {
|
||||||
|
|
||||||
|
@Schema(description = "任务编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
||||||
|
@NotEmpty(message = "任务编号不能为空")
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
@Schema(description = "被委派人 ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||||
|
@NotNull(message = "被委派人 ID 不能为空")
|
||||||
|
private Long delegateUserId;
|
||||||
|
|
||||||
|
@Schema(description = "委派原因", requiredMode = Schema.RequiredMode.REQUIRED, example = "做不了决定,需要你先帮忙瞅瞅")
|
||||||
|
@NotEmpty(message = "委派原因不能为空")
|
||||||
|
private String reason;
|
||||||
|
|
||||||
|
}
|
|
@ -5,6 +5,8 @@ import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Schema(description = "管理后台 - 流程任务的 Response VO")
|
@Schema(description = "管理后台 - 流程任务的 Response VO")
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@ -19,6 +21,14 @@ public class BpmTaskRespVO extends BpmTaskDonePageItemRespVO {
|
||||||
*/
|
*/
|
||||||
private User assigneeUser;
|
private User assigneeUser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 父任务ID
|
||||||
|
*/
|
||||||
|
private String parentTaskId;
|
||||||
|
|
||||||
|
@Schema(description = "子任务(由加签生成)", requiredMode = Schema.RequiredMode.REQUIRED, example = "childrenTask")
|
||||||
|
private List<BpmTaskRespVO> children;
|
||||||
|
|
||||||
@Schema(description = "用户信息")
|
@Schema(description = "用户信息")
|
||||||
@Data
|
@Data
|
||||||
public static class User {
|
public static class User {
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
package cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotEmpty;
|
||||||
|
|
||||||
|
@Schema(description = "管理后台 - 回退流程任务的 Request VO")
|
||||||
|
@Data
|
||||||
|
public class BpmTaskReturnReqVO {
|
||||||
|
|
||||||
|
@Schema(description = "任务编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
||||||
|
@NotEmpty(message = "任务编号不能为空")
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
@Schema(description = "回退到的任务 Key", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||||
|
@NotEmpty(message = "回退到的任务 Key 不能为空")
|
||||||
|
private String targetDefinitionKey;
|
||||||
|
|
||||||
|
@Schema(description = "回退意见", requiredMode = Schema.RequiredMode.REQUIRED, example = "我就是想驳回")
|
||||||
|
@NotEmpty(message = "回退意见不能为空")
|
||||||
|
private String reason;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
package cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Schema(description = "管理后台 - 流程任务的精简 Response VO")
|
||||||
|
@Data
|
||||||
|
public class BpmTaskSimpleRespVO {
|
||||||
|
|
||||||
|
@Schema(description = "任务定义的标识", requiredMode = Schema.RequiredMode.REQUIRED, example = "Activity_one")
|
||||||
|
private String definitionKey;
|
||||||
|
|
||||||
|
@Schema(description = "任务名词", requiredMode = Schema.RequiredMode.REQUIRED, example = "经理审批")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotEmpty;
|
||||||
|
|
||||||
|
// TODO @海洋:类名,应该是 delete 哈
|
||||||
|
@Schema(description = "管理后台 - 减签流程任务的 Request VO")
|
||||||
|
@Data
|
||||||
|
public class BpmTaskSubSignReqVO {
|
||||||
|
|
||||||
|
@Schema(description = "被减签的任务 ID")
|
||||||
|
@NotEmpty(message = "任务编号不能为空")
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
@Schema(description = "加签原因")
|
||||||
|
@NotEmpty(message = "加签原因不能为空")
|
||||||
|
private String reason;
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Schema(description = "管理后台 - 减签流程任务的 Response VO")
|
||||||
|
@Data
|
||||||
|
public class BpmTaskSubSignRespVO {
|
||||||
|
@Schema(description = "审核的用户信息", requiredMode = Schema.RequiredMode.REQUIRED, example = "小李")
|
||||||
|
private BpmTaskRespVO.User assigneeUser;
|
||||||
|
@Schema(description = "任务 ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "12312")
|
||||||
|
private String id;
|
||||||
|
@Schema(description = "任务名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "经理审批")
|
||||||
|
private String name;
|
||||||
|
}
|
|
@ -1,27 +1,34 @@
|
||||||
package cn.iocoder.yudao.module.bpm.convert.task;
|
package cn.iocoder.yudao.module.bpm.convert.task;
|
||||||
|
|
||||||
import cn.hutool.core.date.LocalDateTimeUtil;
|
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||||
|
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
|
||||||
import cn.iocoder.yudao.framework.common.util.date.DateUtils;
|
import cn.iocoder.yudao.framework.common.util.date.DateUtils;
|
||||||
import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
|
import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
|
||||||
import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task.BpmTaskDonePageItemRespVO;
|
import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task.*;
|
||||||
import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task.BpmTaskRespVO;
|
|
||||||
import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task.BpmTaskTodoPageItemRespVO;
|
|
||||||
import cn.iocoder.yudao.module.bpm.dal.dataobject.task.BpmTaskExtDO;
|
import cn.iocoder.yudao.module.bpm.dal.dataobject.task.BpmTaskExtDO;
|
||||||
import cn.iocoder.yudao.module.bpm.service.message.dto.BpmMessageSendWhenTaskCreatedReqDTO;
|
import cn.iocoder.yudao.module.bpm.service.message.dto.BpmMessageSendWhenTaskCreatedReqDTO;
|
||||||
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
|
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
|
||||||
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
|
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
|
||||||
|
import org.flowable.bpmn.model.FlowElement;
|
||||||
import org.flowable.common.engine.impl.db.SuspensionState;
|
import org.flowable.common.engine.impl.db.SuspensionState;
|
||||||
import org.flowable.engine.history.HistoricProcessInstance;
|
import org.flowable.engine.history.HistoricProcessInstance;
|
||||||
import org.flowable.engine.runtime.ProcessInstance;
|
import org.flowable.engine.runtime.ProcessInstance;
|
||||||
import org.flowable.task.api.Task;
|
import org.flowable.task.api.Task;
|
||||||
import org.flowable.task.api.history.HistoricTaskInstance;
|
import org.flowable.task.api.history.HistoricTaskInstance;
|
||||||
|
import org.flowable.task.service.impl.persistence.entity.TaskEntityImpl;
|
||||||
import org.mapstruct.*;
|
import org.mapstruct.*;
|
||||||
import org.mapstruct.factory.Mappers;
|
import org.mapstruct.factory.Mappers;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMultiMap;
|
||||||
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bpm 任务 Convert
|
* Bpm 任务 Convert
|
||||||
*
|
*
|
||||||
|
@ -47,8 +54,6 @@ public interface BpmTaskConvert {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Mapping(source = "suspended", target = "suspensionState", qualifiedByName = "convertSuspendedToSuspensionState")
|
@Mapping(source = "suspended", target = "suspensionState", qualifiedByName = "convertSuspendedToSuspensionState")
|
||||||
// @Mapping(target = "claimTime", expression = "java(bean.getClaimTime()==null?null: LocalDateTime.ofInstant(bean.getClaimTime().toInstant(),ZoneId.systemDefault()))")
|
|
||||||
// @Mapping(target = "createTime", expression = "java(bean.getCreateTime()==null?null:LocalDateTime.ofInstant(bean.getCreateTime().toInstant(),ZoneId.systemDefault()))")
|
|
||||||
BpmTaskTodoPageItemRespVO convert1(Task bean);
|
BpmTaskTodoPageItemRespVO convert1(Task bean);
|
||||||
|
|
||||||
@Named("convertSuspendedToSuspensionState")
|
@Named("convertSuspendedToSuspensionState")
|
||||||
|
@ -107,8 +112,6 @@ public interface BpmTaskConvert {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Mapping(source = "taskDefinitionKey", target = "definitionKey")
|
@Mapping(source = "taskDefinitionKey", target = "definitionKey")
|
||||||
// @Mapping(target = "createTime", expression = "java(bean.getCreateTime() == null ? null : LocalDateTime.ofInstant(bean.getCreateTime().toInstant(), ZoneId.systemDefault()))")
|
|
||||||
// @Mapping(target = "endTime", expression = "java(bean.getEndTime() == null ? null : LocalDateTime.ofInstant(bean.getEndTime().toInstant(), ZoneId.systemDefault()))")
|
|
||||||
BpmTaskRespVO convert3(HistoricTaskInstance bean);
|
BpmTaskRespVO convert3(HistoricTaskInstance bean);
|
||||||
|
|
||||||
BpmTaskRespVO.User convert3(AdminUserRespDTO bean);
|
BpmTaskRespVO.User convert3(AdminUserRespDTO bean);
|
||||||
|
@ -142,4 +145,57 @@ public interface BpmTaskConvert {
|
||||||
return reqDTO;
|
return reqDTO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default List<BpmTaskSimpleRespVO> convertList(List<? extends FlowElement> elementList) {
|
||||||
|
return CollectionUtils.convertList(elementList, element -> new BpmTaskSimpleRespVO()
|
||||||
|
.setName(element.getName())
|
||||||
|
.setDefinitionKey(element.getId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
//此处不用 mapstruct 映射,因为 TaskEntityImpl 还有很多其他属性,这里我们只设置我们需要的
|
||||||
|
//使用 mapstruct 会将里面嵌套的各个属性值都设置进去,会出现意想不到的问题
|
||||||
|
default TaskEntityImpl convert(TaskEntityImpl task,TaskEntityImpl parentTask){
|
||||||
|
task.setCategory(parentTask.getCategory());
|
||||||
|
task.setDescription(parentTask.getDescription());
|
||||||
|
task.setTenantId(parentTask.getTenantId());
|
||||||
|
task.setName(parentTask.getName());
|
||||||
|
task.setParentTaskId(parentTask.getId());
|
||||||
|
task.setProcessDefinitionId(parentTask.getProcessDefinitionId());
|
||||||
|
task.setProcessInstanceId(parentTask.getProcessInstanceId());
|
||||||
|
task.setTaskDefinitionKey(parentTask.getTaskDefinitionKey());
|
||||||
|
task.setTaskDefinitionId(parentTask.getTaskDefinitionId());
|
||||||
|
task.setPriority(parentTask.getPriority());
|
||||||
|
task.setCreateTime(new Date());
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
default List<BpmTaskSubSignRespVO> convertList(List<BpmTaskExtDO> bpmTaskExtDOList,
|
||||||
|
Map<Long, AdminUserRespDTO> userMap,
|
||||||
|
Map<String, Task> idTaskMap){
|
||||||
|
return CollectionUtils.convertList(bpmTaskExtDOList, task -> {
|
||||||
|
BpmTaskSubSignRespVO bpmTaskSubSignRespVO = new BpmTaskSubSignRespVO()
|
||||||
|
.setId(task.getTaskId()).setName(task.getName());
|
||||||
|
// 后加签任务不会直接设置 assignee ,所以不存在 assignee 的情况,则去取 owner
|
||||||
|
Task sourceTask = idTaskMap.get(task.getTaskId());
|
||||||
|
String assignee = ObjectUtil.defaultIfBlank(sourceTask.getOwner(),sourceTask.getAssignee());
|
||||||
|
MapUtils.findAndThen(userMap,NumberUtils.parseLong(assignee),
|
||||||
|
assignUser-> bpmTaskSubSignRespVO.setAssigneeUser(convert3(assignUser)));
|
||||||
|
return bpmTaskSubSignRespVO;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 转换任务为父子级
|
||||||
|
*
|
||||||
|
* @param sourceList 原始数据
|
||||||
|
* @return 转换后的父子级数组
|
||||||
|
*/
|
||||||
|
default List<BpmTaskRespVO> convertChildrenList(List<BpmTaskRespVO> sourceList) {
|
||||||
|
List<BpmTaskRespVO> childrenTaskList = filterList(sourceList, r -> StrUtil.isNotEmpty(r.getParentTaskId()));
|
||||||
|
Map<String, List<BpmTaskRespVO>> parentChildrenTaskListMap = convertMultiMap(childrenTaskList, BpmTaskRespVO::getParentTaskId);
|
||||||
|
for (BpmTaskRespVO bpmTaskRespVO : sourceList) {
|
||||||
|
bpmTaskRespVO.setChildren(parentChildrenTaskListMap.get(bpmTaskRespVO.getId()));
|
||||||
|
}
|
||||||
|
return filterList(sourceList, r -> StrUtil.isEmpty(r.getParentTaskId()));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package cn.iocoder.yudao.module.bpm.dal.mysql.task;
|
package cn.iocoder.yudao.module.bpm.dal.mysql.task;
|
||||||
|
|
||||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||||
|
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||||
import cn.iocoder.yudao.module.bpm.dal.dataobject.task.BpmTaskExtDO;
|
import cn.iocoder.yudao.module.bpm.dal.dataobject.task.BpmTaskExtDO;
|
||||||
|
import cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceResultEnum;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
@ -19,8 +21,19 @@ public interface BpmTaskExtMapper extends BaseMapperX<BpmTaskExtDO> {
|
||||||
return selectList(BpmTaskExtDO::getTaskId, taskIds);
|
return selectList(BpmTaskExtDO::getTaskId, taskIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO @海:BpmProcessInstanceResultEnum.CAN_SUB_SIGN_STATUS_LIST) 应该作为条件,mapper 不要有业务
|
||||||
|
default List<BpmTaskExtDO> selectProcessListByTaskIds(Collection<String> taskIds) {
|
||||||
|
return selectList(new LambdaQueryWrapperX<BpmTaskExtDO>()
|
||||||
|
.in(BpmTaskExtDO::getTaskId, taskIds)
|
||||||
|
.in(BpmTaskExtDO::getResult, BpmProcessInstanceResultEnum.CAN_SUB_SIGN_STATUS_LIST));
|
||||||
|
}
|
||||||
|
|
||||||
default BpmTaskExtDO selectByTaskId(String taskId) {
|
default BpmTaskExtDO selectByTaskId(String taskId) {
|
||||||
return selectOne(BpmTaskExtDO::getTaskId, taskId);
|
return selectOne(BpmTaskExtDO::getTaskId, taskId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default void updateBatchByTaskIdList(List<String> taskIdList, BpmTaskExtDO updateObj) {
|
||||||
|
update(updateObj, new LambdaQueryWrapper<BpmTaskExtDO>().in(BpmTaskExtDO::getTaskId, taskIdList));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
package cn.iocoder.yudao.module.bpm.framework.web.config;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.swagger.config.YudaoSwaggerAutoConfiguration;
|
||||||
|
import org.springdoc.core.GroupedOpenApi;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bpm 模块的 web 组件的 Configuration
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
@Configuration(proxyBeanMethods = false)
|
||||||
|
public class BpmWebConfiguration {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bpm 模块的 API 分组
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public GroupedOpenApi bpmGroupedOpenApi() {
|
||||||
|
return YudaoSwaggerAutoConfiguration.buildGroupedOpenApi("bpm");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
/**
|
||||||
|
* bpm 模块的 web 配置
|
||||||
|
*/
|
||||||
|
package cn.iocoder.yudao.module.bpm.framework.web;
|
|
@ -12,6 +12,7 @@ import javax.validation.Valid;
|
||||||
* @author yunlongn
|
* @author yunlongn
|
||||||
*/
|
*/
|
||||||
public interface BpmModelService {
|
public interface BpmModelService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得流程模型分页
|
* 获得流程模型分页
|
||||||
*
|
*
|
||||||
|
@ -74,4 +75,12 @@ public interface BpmModelService {
|
||||||
*/
|
*/
|
||||||
BpmnModel getBpmnModel(String id);
|
BpmnModel getBpmnModel(String id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得流程定义编号对应的 BPMN Model
|
||||||
|
*
|
||||||
|
* @param processDefinitionId 流程定义编号
|
||||||
|
* @return BPMN Model
|
||||||
|
*/
|
||||||
|
BpmnModel getBpmnModelByDefinitionId(String processDefinitionId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -233,6 +233,11 @@ public class BpmModelServiceImpl implements BpmModelService {
|
||||||
return converter.convertToBpmnModel(new BytesStreamSource(bpmnBytes), true, true);
|
return converter.convertToBpmnModel(new BytesStreamSource(bpmnBytes), true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BpmnModel getBpmnModelByDefinitionId(String processDefinitionId) {
|
||||||
|
return repositoryService.getBpmnModel(processDefinitionId);
|
||||||
|
}
|
||||||
|
|
||||||
private void checkKeyNCName(String key) {
|
private void checkKeyNCName(String key) {
|
||||||
if (!ValidationUtils.isXmlNCName(key)) {
|
if (!ValidationUtils.isXmlNCName(key)) {
|
||||||
throw exception(MODEL_KEY_VALID);
|
throw exception(MODEL_KEY_VALID);
|
||||||
|
@ -283,5 +288,4 @@ public class BpmModelServiceImpl implements BpmModelService {
|
||||||
processDefinitionService.updateProcessDefinitionState(oldDefinition.getId(), SuspensionState.SUSPENDED.getStateCode());
|
processDefinitionService.updateProcessDefinitionState(oldDefinition.getId(), SuspensionState.SUSPENDED.getStateCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.framework.common.util.object.PageUtils;
|
import cn.iocoder.yudao.framework.common.util.object.PageUtils;
|
||||||
import cn.iocoder.yudao.framework.flowable.core.util.FlowableUtils;
|
import cn.iocoder.yudao.framework.flowable.core.util.BpmnModelUtils;
|
||||||
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.process.BpmProcessDefinitionListReqVO;
|
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.process.BpmProcessDefinitionListReqVO;
|
||||||
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.process.BpmProcessDefinitionPageItemRespVO;
|
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.process.BpmProcessDefinitionPageItemRespVO;
|
||||||
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.process.BpmProcessDefinitionPageReqVO;
|
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.process.BpmProcessDefinitionPageReqVO;
|
||||||
|
@ -200,7 +200,7 @@ public class BpmProcessDefinitionServiceImpl implements BpmProcessDefinitionServ
|
||||||
BpmnModel newModel = buildBpmnModel(createReqDTO.getBpmnBytes());
|
BpmnModel newModel = buildBpmnModel(createReqDTO.getBpmnBytes());
|
||||||
BpmnModel oldModel = getBpmnModel(oldProcessDefinition.getId());
|
BpmnModel oldModel = getBpmnModel(oldProcessDefinition.getId());
|
||||||
// 对比字节变化
|
// 对比字节变化
|
||||||
if (!FlowableUtils.equals(oldModel, newModel)) {
|
if (!BpmnModelUtils.equals(oldModel, newModel)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// 最终发现都一致,则返回 true
|
// 最终发现都一致,则返回 true
|
||||||
|
|
|
@ -7,7 +7,7 @@ import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||||
import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
|
import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
|
||||||
import cn.iocoder.yudao.framework.datapermission.core.annotation.DataPermission;
|
import cn.iocoder.yudao.framework.datapermission.core.annotation.DataPermission;
|
||||||
import cn.iocoder.yudao.framework.flowable.core.util.FlowableUtils;
|
import cn.iocoder.yudao.framework.flowable.core.util.BpmnModelUtils;
|
||||||
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.rule.BpmTaskAssignRuleCreateReqVO;
|
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.rule.BpmTaskAssignRuleCreateReqVO;
|
||||||
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.rule.BpmTaskAssignRuleRespVO;
|
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.rule.BpmTaskAssignRuleRespVO;
|
||||||
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.rule.BpmTaskAssignRuleUpdateReqVO;
|
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.rule.BpmTaskAssignRuleUpdateReqVO;
|
||||||
|
@ -15,8 +15,8 @@ import cn.iocoder.yudao.module.bpm.convert.definition.BpmTaskAssignRuleConvert;
|
||||||
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmTaskAssignRuleDO;
|
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmTaskAssignRuleDO;
|
||||||
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmUserGroupDO;
|
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmUserGroupDO;
|
||||||
import cn.iocoder.yudao.module.bpm.dal.mysql.definition.BpmTaskAssignRuleMapper;
|
import cn.iocoder.yudao.module.bpm.dal.mysql.definition.BpmTaskAssignRuleMapper;
|
||||||
import cn.iocoder.yudao.module.bpm.enums.definition.BpmTaskAssignRuleTypeEnum;
|
|
||||||
import cn.iocoder.yudao.module.bpm.enums.DictTypeConstants;
|
import cn.iocoder.yudao.module.bpm.enums.DictTypeConstants;
|
||||||
|
import cn.iocoder.yudao.module.bpm.enums.definition.BpmTaskAssignRuleTypeEnum;
|
||||||
import cn.iocoder.yudao.module.bpm.framework.flowable.core.behavior.script.BpmTaskAssignScript;
|
import cn.iocoder.yudao.module.bpm.framework.flowable.core.behavior.script.BpmTaskAssignScript;
|
||||||
import cn.iocoder.yudao.module.system.api.dept.DeptApi;
|
import cn.iocoder.yudao.module.system.api.dept.DeptApi;
|
||||||
import cn.iocoder.yudao.module.system.api.dept.PostApi;
|
import cn.iocoder.yudao.module.system.api.dept.PostApi;
|
||||||
|
@ -114,7 +114,7 @@ public class BpmTaskAssignRuleServiceImpl implements BpmTaskAssignRuleService {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
// 获得用户任务,只有用户任务才可以设置分配规则
|
// 获得用户任务,只有用户任务才可以设置分配规则
|
||||||
List<UserTask> userTasks = FlowableUtils.getBpmnModelElements(model, UserTask.class);
|
List<UserTask> userTasks = BpmnModelUtils.getBpmnModelElements(model, UserTask.class);
|
||||||
if (CollUtil.isEmpty(userTasks)) {
|
if (CollUtil.isEmpty(userTasks)) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package cn.iocoder.yudao.module.bpm.service.oa;
|
package cn.iocoder.yudao.module.bpm.service.oa;
|
||||||
|
|
||||||
import cn.hutool.core.date.DateUtil;
|
|
||||||
import cn.hutool.core.date.LocalDateTimeUtil;
|
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.module.bpm.api.task.BpmProcessInstanceApi;
|
import cn.iocoder.yudao.module.bpm.api.task.BpmProcessInstanceApi;
|
||||||
|
@ -57,7 +56,7 @@ public class BpmOALeaveServiceImpl implements BpmOALeaveService {
|
||||||
processInstanceVariables.put("day", day);
|
processInstanceVariables.put("day", day);
|
||||||
String processInstanceId = processInstanceApi.createProcessInstance(userId,
|
String processInstanceId = processInstanceApi.createProcessInstance(userId,
|
||||||
new BpmProcessInstanceCreateReqDTO().setProcessDefinitionKey(PROCESS_KEY)
|
new BpmProcessInstanceCreateReqDTO().setProcessDefinitionKey(PROCESS_KEY)
|
||||||
.setVariables(processInstanceVariables).setBusinessKey(String.valueOf(leave.getId())));
|
.setVariables(processInstanceVariables).setBusinessKey(String.valueOf(leave.getId()))).getCheckedData();
|
||||||
|
|
||||||
// 将工作流的编号,更新到 OA 请假单中
|
// 将工作流的编号,更新到 OA 请假单中
|
||||||
leaveMapper.updateById(new BpmOALeaveDO().setId(leave.getId()).setProcessInstanceId(processInstanceId));
|
leaveMapper.updateById(new BpmOALeaveDO().setId(leave.getId()).setProcessInstanceId(processInstanceId));
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package cn.iocoder.yudao.module.bpm.service.task;
|
package cn.iocoder.yudao.module.bpm.service.task;
|
||||||
|
|
||||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||||
import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task.*;
|
import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task.*;
|
||||||
|
import cn.iocoder.yudao.module.bpm.dal.dataobject.task.BpmTaskExtDO;
|
||||||
import org.flowable.task.api.Task;
|
import org.flowable.task.api.Task;
|
||||||
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
|
@ -23,7 +23,6 @@ public interface BpmTaskService {
|
||||||
*
|
*
|
||||||
* @param userId 用户编号
|
* @param userId 用户编号
|
||||||
* @param pageReqVO 分页请求
|
* @param pageReqVO 分页请求
|
||||||
*
|
|
||||||
* @return 流程任务分页
|
* @return 流程任务分页
|
||||||
*/
|
*/
|
||||||
PageResult<BpmTaskTodoPageItemRespVO> getTodoTaskPage(Long userId, BpmTaskTodoPageReqVO pageReqVO);
|
PageResult<BpmTaskTodoPageItemRespVO> getTodoTaskPage(Long userId, BpmTaskTodoPageReqVO pageReqVO);
|
||||||
|
@ -33,7 +32,6 @@ public interface BpmTaskService {
|
||||||
*
|
*
|
||||||
* @param userId 用户编号
|
* @param userId 用户编号
|
||||||
* @param pageReqVO 分页请求
|
* @param pageReqVO 分页请求
|
||||||
*
|
|
||||||
* @return 流程任务分页
|
* @return 流程任务分页
|
||||||
*/
|
*/
|
||||||
PageResult<BpmTaskDonePageItemRespVO> getDoneTaskPage(Long userId, BpmTaskDonePageReqVO pageReqVO);
|
PageResult<BpmTaskDonePageItemRespVO> getDoneTaskPage(Long userId, BpmTaskDonePageReqVO pageReqVO);
|
||||||
|
@ -42,19 +40,17 @@ public interface BpmTaskService {
|
||||||
* 获得流程任务 Map
|
* 获得流程任务 Map
|
||||||
*
|
*
|
||||||
* @param processInstanceIds 流程实例的编号数组
|
* @param processInstanceIds 流程实例的编号数组
|
||||||
*
|
|
||||||
* @return 流程任务 Map
|
* @return 流程任务 Map
|
||||||
*/
|
*/
|
||||||
default Map<String, List<Task>> getTaskMapByProcessInstanceIds(List<String> processInstanceIds) {
|
default Map<String, List<Task>> getTaskMapByProcessInstanceIds(List<String> processInstanceIds) {
|
||||||
return CollectionUtils.convertMultiMap(getTasksByProcessInstanceIds(processInstanceIds),
|
return CollectionUtils.convertMultiMap(getTasksByProcessInstanceIds(processInstanceIds),
|
||||||
Task::getProcessInstanceId);
|
Task::getProcessInstanceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得流程任务列表
|
* 获得流程任务列表
|
||||||
*
|
*
|
||||||
* @param processInstanceIds 流程实例的编号数组
|
* @param processInstanceIds 流程实例的编号数组
|
||||||
*
|
|
||||||
* @return 流程任务列表
|
* @return 流程任务列表
|
||||||
*/
|
*/
|
||||||
List<Task> getTasksByProcessInstanceIds(List<String> processInstanceIds);
|
List<Task> getTasksByProcessInstanceIds(List<String> processInstanceIds);
|
||||||
|
@ -63,11 +59,19 @@ public interface BpmTaskService {
|
||||||
* 获得指令流程实例的流程任务列表,包括所有状态的
|
* 获得指令流程实例的流程任务列表,包括所有状态的
|
||||||
*
|
*
|
||||||
* @param processInstanceId 流程实例的编号
|
* @param processInstanceId 流程实例的编号
|
||||||
*
|
|
||||||
* @return 流程任务列表
|
* @return 流程任务列表
|
||||||
*/
|
*/
|
||||||
List<BpmTaskRespVO> getTaskListByProcessInstanceId(String processInstanceId);
|
List<BpmTaskRespVO> getTaskListByProcessInstanceId(String processInstanceId);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过任务 ID 集合,获取任务扩展表信息集合
|
||||||
|
*
|
||||||
|
* @param taskIdList 任务 ID 集合
|
||||||
|
* @return 任务列表
|
||||||
|
*/
|
||||||
|
List<BpmTaskExtDO> getTaskListByTaskIdList(List<String> taskIdList);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过任务
|
* 通过任务
|
||||||
*
|
*
|
||||||
|
@ -128,4 +132,53 @@ public interface BpmTaskService {
|
||||||
*/
|
*/
|
||||||
void updateTaskExtAssign(Task task);
|
void updateTaskExtAssign(Task task);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前任务的可回退的流程集合
|
||||||
|
*
|
||||||
|
* @param taskId 当前的任务 ID
|
||||||
|
* @return 可以回退的节点列表
|
||||||
|
*/
|
||||||
|
List<BpmTaskSimpleRespVO> getReturnTaskList(String taskId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将任务回退到指定的 targetDefinitionKey 位置
|
||||||
|
*
|
||||||
|
* @param userId 用户编号
|
||||||
|
* @param reqVO 回退的任务key和当前所在的任务ID
|
||||||
|
*/
|
||||||
|
void returnTask(Long userId, BpmTaskReturnReqVO reqVO);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将指定任务委派给其他人处理,等接收人处理后再回到原审批人手中审批
|
||||||
|
*
|
||||||
|
* @param userId 用户编号
|
||||||
|
* @param reqVO 被委派人和被委派的任务编号理由参数
|
||||||
|
*/
|
||||||
|
void delegateTask(Long userId, BpmTaskDelegateReqVO reqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 任务加签
|
||||||
|
*
|
||||||
|
* @param userId 被加签的用户和任务 ID,加签类型
|
||||||
|
* @param reqVO 当前用户 ID
|
||||||
|
*/
|
||||||
|
void createSignTask(Long userId, BpmTaskAddSignReqVO reqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 任务减签名
|
||||||
|
*
|
||||||
|
* @param userId 当前用户ID
|
||||||
|
* @param reqVO 被减签的任务 ID,理由
|
||||||
|
*/
|
||||||
|
void deleteSignTask(Long userId, BpmTaskSubSignReqVO reqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取指定任务的子任务和审批人信息
|
||||||
|
*
|
||||||
|
* @param parentId 指定任务ID
|
||||||
|
* @return 子任务列表
|
||||||
|
*/
|
||||||
|
List<BpmTaskSubSignRespVO> getChildrenTaskList(String parentId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,45 +2,63 @@ package cn.iocoder.yudao.module.bpm.service.task;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.util.ArrayUtil;
|
import cn.hutool.core.util.ArrayUtil;
|
||||||
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.framework.common.util.date.DateUtils;
|
import cn.iocoder.yudao.framework.common.util.date.DateUtils;
|
||||||
import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
|
import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
|
||||||
import cn.iocoder.yudao.framework.common.util.object.PageUtils;
|
import cn.iocoder.yudao.framework.common.util.object.PageUtils;
|
||||||
|
import cn.iocoder.yudao.framework.flowable.core.util.BpmnModelUtils;
|
||||||
|
import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils;
|
||||||
import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task.*;
|
import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task.*;
|
||||||
import cn.iocoder.yudao.module.bpm.convert.task.BpmTaskConvert;
|
import cn.iocoder.yudao.module.bpm.convert.task.BpmTaskConvert;
|
||||||
import cn.iocoder.yudao.module.bpm.dal.dataobject.task.BpmTaskExtDO;
|
import cn.iocoder.yudao.module.bpm.dal.dataobject.task.BpmTaskExtDO;
|
||||||
import cn.iocoder.yudao.module.bpm.dal.mysql.task.BpmTaskExtMapper;
|
import cn.iocoder.yudao.module.bpm.dal.mysql.task.BpmTaskExtMapper;
|
||||||
|
import cn.iocoder.yudao.module.bpm.enums.task.BpmCommentTypeEnum;
|
||||||
import cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceDeleteReasonEnum;
|
import cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceDeleteReasonEnum;
|
||||||
import cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceResultEnum;
|
import cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceResultEnum;
|
||||||
|
import cn.iocoder.yudao.module.bpm.enums.task.BpmTaskAddSignTypeEnum;
|
||||||
|
import cn.iocoder.yudao.module.bpm.service.definition.BpmModelService;
|
||||||
import cn.iocoder.yudao.module.bpm.service.message.BpmMessageService;
|
import cn.iocoder.yudao.module.bpm.service.message.BpmMessageService;
|
||||||
import cn.iocoder.yudao.module.system.api.dept.DeptApi;
|
import cn.iocoder.yudao.module.system.api.dept.DeptApi;
|
||||||
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
|
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
|
||||||
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
||||||
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
|
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.flowable.bpmn.model.BpmnModel;
|
||||||
|
import org.flowable.bpmn.model.FlowElement;
|
||||||
|
import org.flowable.bpmn.model.UserTask;
|
||||||
import org.flowable.engine.HistoryService;
|
import org.flowable.engine.HistoryService;
|
||||||
|
import org.flowable.engine.ManagementService;
|
||||||
|
import org.flowable.engine.RuntimeService;
|
||||||
import org.flowable.engine.TaskService;
|
import org.flowable.engine.TaskService;
|
||||||
import org.flowable.engine.history.HistoricProcessInstance;
|
import org.flowable.engine.history.HistoricProcessInstance;
|
||||||
import org.flowable.engine.runtime.ProcessInstance;
|
import org.flowable.engine.runtime.ProcessInstance;
|
||||||
|
import org.flowable.task.api.DelegationState;
|
||||||
import org.flowable.task.api.Task;
|
import org.flowable.task.api.Task;
|
||||||
|
import org.flowable.task.api.TaskInfo;
|
||||||
import org.flowable.task.api.TaskQuery;
|
import org.flowable.task.api.TaskQuery;
|
||||||
import org.flowable.task.api.history.HistoricTaskInstance;
|
import org.flowable.task.api.history.HistoricTaskInstance;
|
||||||
import org.flowable.task.api.history.HistoricTaskInstanceQuery;
|
import org.flowable.task.api.history.HistoricTaskInstanceQuery;
|
||||||
|
import org.flowable.task.service.impl.persistence.entity.TaskEntity;
|
||||||
|
import org.flowable.task.service.impl.persistence.entity.TaskEntityImpl;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.transaction.support.TransactionSynchronization;
|
import org.springframework.transaction.support.TransactionSynchronization;
|
||||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
|
||||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
|
|
||||||
import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.*;
|
import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.*;
|
||||||
|
import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.TASK_TARGET_NODE_NOT_EXISTS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 流程任务实例 Service 实现类
|
* 流程任务实例 Service 实现类
|
||||||
|
@ -56,23 +74,32 @@ public class BpmTaskServiceImpl implements BpmTaskService {
|
||||||
private TaskService taskService;
|
private TaskService taskService;
|
||||||
@Resource
|
@Resource
|
||||||
private HistoryService historyService;
|
private HistoryService historyService;
|
||||||
|
@Resource
|
||||||
|
private RuntimeService runtimeService;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private BpmProcessInstanceService processInstanceService;
|
private BpmProcessInstanceService processInstanceService;
|
||||||
|
@Resource
|
||||||
|
private BpmModelService bpmModelService;
|
||||||
|
@Resource
|
||||||
|
private BpmMessageService messageService;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private AdminUserApi adminUserApi;
|
private AdminUserApi adminUserApi;
|
||||||
@Resource
|
@Resource
|
||||||
private DeptApi deptApi;
|
private DeptApi deptApi;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private BpmTaskExtMapper taskExtMapper;
|
private BpmTaskExtMapper taskExtMapper;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private BpmMessageService messageService;
|
private ManagementService managementService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageResult<BpmTaskTodoPageItemRespVO> getTodoTaskPage(Long userId, BpmTaskTodoPageReqVO pageVO) {
|
public PageResult<BpmTaskTodoPageItemRespVO> getTodoTaskPage(Long userId, BpmTaskTodoPageReqVO pageVO) {
|
||||||
// 查询待办任务
|
// 查询待办任务
|
||||||
TaskQuery taskQuery = taskService.createTaskQuery().taskAssignee(String.valueOf(userId)) // 分配给自己
|
TaskQuery taskQuery = taskService.createTaskQuery().taskAssignee(String.valueOf(userId)) // 分配给自己
|
||||||
.orderByTaskCreateTime().desc(); // 创建时间倒序
|
.orderByTaskCreateTime().desc(); // 创建时间倒序
|
||||||
if (StrUtil.isNotBlank(pageVO.getName())) {
|
if (StrUtil.isNotBlank(pageVO.getName())) {
|
||||||
taskQuery.taskNameLike("%" + pageVO.getName() + "%");
|
taskQuery.taskNameLike("%" + pageVO.getName() + "%");
|
||||||
}
|
}
|
||||||
|
@ -90,21 +117,21 @@ public class BpmTaskServiceImpl implements BpmTaskService {
|
||||||
|
|
||||||
// 获得 ProcessInstance Map
|
// 获得 ProcessInstance Map
|
||||||
Map<String, ProcessInstance> processInstanceMap =
|
Map<String, ProcessInstance> processInstanceMap =
|
||||||
processInstanceService.getProcessInstanceMap(convertSet(tasks, Task::getProcessInstanceId));
|
processInstanceService.getProcessInstanceMap(convertSet(tasks, Task::getProcessInstanceId));
|
||||||
// 获得 User Map
|
// 获得 User Map
|
||||||
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(
|
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(
|
||||||
convertSet(processInstanceMap.values(), instance -> Long.valueOf(instance.getStartUserId())));
|
convertSet(processInstanceMap.values(), instance -> Long.valueOf(instance.getStartUserId())));
|
||||||
// 拼接结果
|
// 拼接结果
|
||||||
return new PageResult<>(BpmTaskConvert.INSTANCE.convertList1(tasks, processInstanceMap, userMap),
|
return new PageResult<>(BpmTaskConvert.INSTANCE.convertList1(tasks, processInstanceMap, userMap),
|
||||||
taskQuery.count());
|
taskQuery.count());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageResult<BpmTaskDonePageItemRespVO> getDoneTaskPage(Long userId, BpmTaskDonePageReqVO pageVO) {
|
public PageResult<BpmTaskDonePageItemRespVO> getDoneTaskPage(Long userId, BpmTaskDonePageReqVO pageVO) {
|
||||||
// 查询已办任务
|
// 查询已办任务
|
||||||
HistoricTaskInstanceQuery taskQuery = historyService.createHistoricTaskInstanceQuery().finished() // 已完成
|
HistoricTaskInstanceQuery taskQuery = historyService.createHistoricTaskInstanceQuery().finished() // 已完成
|
||||||
.taskAssignee(String.valueOf(userId)) // 分配给自己
|
.taskAssignee(String.valueOf(userId)) // 分配给自己
|
||||||
.orderByHistoricTaskInstanceEndTime().desc(); // 审批时间倒序
|
.orderByHistoricTaskInstanceEndTime().desc(); // 审批时间倒序
|
||||||
if (StrUtil.isNotBlank(pageVO.getName())) {
|
if (StrUtil.isNotBlank(pageVO.getName())) {
|
||||||
taskQuery.taskNameLike("%" + pageVO.getName() + "%");
|
taskQuery.taskNameLike("%" + pageVO.getName() + "%");
|
||||||
}
|
}
|
||||||
|
@ -122,19 +149,19 @@ public class BpmTaskServiceImpl implements BpmTaskService {
|
||||||
|
|
||||||
// 获得 TaskExtDO Map
|
// 获得 TaskExtDO Map
|
||||||
List<BpmTaskExtDO> bpmTaskExtDOs =
|
List<BpmTaskExtDO> bpmTaskExtDOs =
|
||||||
taskExtMapper.selectListByTaskIds(convertSet(tasks, HistoricTaskInstance::getId));
|
taskExtMapper.selectListByTaskIds(convertSet(tasks, HistoricTaskInstance::getId));
|
||||||
Map<String, BpmTaskExtDO> bpmTaskExtDOMap = convertMap(bpmTaskExtDOs, BpmTaskExtDO::getTaskId);
|
Map<String, BpmTaskExtDO> bpmTaskExtDOMap = convertMap(bpmTaskExtDOs, BpmTaskExtDO::getTaskId);
|
||||||
// 获得 ProcessInstance Map
|
// 获得 ProcessInstance Map
|
||||||
Map<String, HistoricProcessInstance> historicProcessInstanceMap =
|
Map<String, HistoricProcessInstance> historicProcessInstanceMap =
|
||||||
processInstanceService.getHistoricProcessInstanceMap(
|
processInstanceService.getHistoricProcessInstanceMap(
|
||||||
convertSet(tasks, HistoricTaskInstance::getProcessInstanceId));
|
convertSet(tasks, HistoricTaskInstance::getProcessInstanceId));
|
||||||
// 获得 User Map
|
// 获得 User Map
|
||||||
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(
|
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(
|
||||||
convertSet(historicProcessInstanceMap.values(), instance -> Long.valueOf(instance.getStartUserId())));
|
convertSet(historicProcessInstanceMap.values(), instance -> Long.valueOf(instance.getStartUserId())));
|
||||||
// 拼接结果
|
// 拼接结果
|
||||||
return new PageResult<>(
|
return new PageResult<>(
|
||||||
BpmTaskConvert.INSTANCE.convertList2(tasks, bpmTaskExtDOMap, historicProcessInstanceMap, userMap),
|
BpmTaskConvert.INSTANCE.convertList2(tasks, bpmTaskExtDOMap, historicProcessInstanceMap, userMap),
|
||||||
taskQuery.count());
|
taskQuery.count());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -169,33 +196,242 @@ public class BpmTaskServiceImpl implements BpmTaskService {
|
||||||
Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(convertSet(userMap.values(), AdminUserRespDTO::getDeptId));
|
Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(convertSet(userMap.values(), AdminUserRespDTO::getDeptId));
|
||||||
|
|
||||||
// 拼接数据
|
// 拼接数据
|
||||||
return BpmTaskConvert.INSTANCE.convertList3(tasks, bpmTaskExtDOMap, processInstance, userMap, deptMap);
|
List<BpmTaskRespVO> result = BpmTaskConvert.INSTANCE.convertList3(tasks, bpmTaskExtDOMap, processInstance, userMap, deptMap);
|
||||||
|
return BpmTaskConvert.INSTANCE.convertChildrenList(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<BpmTaskExtDO> getTaskListByTaskIdList(List<String> taskIdList) {
|
||||||
|
return taskExtMapper.selectListByTaskIds(taskIdList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void approveTask(Long userId, @Valid BpmTaskApproveReqVO reqVO) {
|
public void approveTask(Long userId, @Valid BpmTaskApproveReqVO reqVO) {
|
||||||
// 校验任务存在
|
// 1.1 校验任务存在
|
||||||
Task task = checkTask(userId, reqVO.getId());
|
Task task = validateTask(userId, reqVO.getId());
|
||||||
// 校验流程实例存在
|
// 1.2 校验流程实例存在
|
||||||
ProcessInstance instance = processInstanceService.getProcessInstance(task.getProcessInstanceId());
|
ProcessInstance instance = processInstanceService.getProcessInstance(task.getProcessInstanceId());
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
throw exception(PROCESS_INSTANCE_NOT_EXISTS);
|
throw exception(PROCESS_INSTANCE_NOT_EXISTS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 情况一:被委派的任务,不调用 complete 去完成任务
|
||||||
|
if (DelegationState.PENDING.equals(task.getDelegationState())) {
|
||||||
|
approveDelegateTask(reqVO, task);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 情况二:后加签的任务
|
||||||
|
if (BpmTaskAddSignTypeEnum.AFTER.getType().equals(task.getScopeType())) {
|
||||||
|
// 后加签处理
|
||||||
|
approveAfterSignTask(task, reqVO);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 情况三:自己审批的任务,调用 complete 去完成任务
|
||||||
// 完成任务,审批通过
|
// 完成任务,审批通过
|
||||||
taskService.complete(task.getId(), instance.getProcessVariables());
|
taskService.complete(task.getId(), instance.getProcessVariables());
|
||||||
|
|
||||||
// 更新任务拓展表为通过
|
// 更新任务拓展表为通过
|
||||||
taskExtMapper.updateByTaskId(
|
taskExtMapper.updateByTaskId(
|
||||||
new BpmTaskExtDO().setTaskId(task.getId()).setResult(BpmProcessInstanceResultEnum.APPROVE.getResult())
|
new BpmTaskExtDO().setTaskId(task.getId()).setResult(BpmProcessInstanceResultEnum.APPROVE.getResult())
|
||||||
.setReason(reqVO.getReason()));
|
.setReason(reqVO.getReason()));
|
||||||
|
// 处理加签任务
|
||||||
|
handleParentTask(task);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 审批通过存在“后加签”的任务。
|
||||||
|
* <p>
|
||||||
|
* 注意:该任务不能马上完成,需要一个中间状态(SIGN_AFTER),并激活剩余所有子任务(PROCESS)为可审批处理
|
||||||
|
*
|
||||||
|
* @param task 当前任务
|
||||||
|
* @param reqVO 前端请求参数
|
||||||
|
*/
|
||||||
|
private void approveAfterSignTask(Task task, BpmTaskApproveReqVO reqVO) {
|
||||||
|
// 1. 有向后加签,则该任务状态临时设置为 ADD_SIGN_AFTER 状态
|
||||||
|
taskExtMapper.updateByTaskId(
|
||||||
|
new BpmTaskExtDO().setTaskId(task.getId()).setResult(BpmProcessInstanceResultEnum.SIGN_AFTER.getResult())
|
||||||
|
.setReason(reqVO.getReason()).setEndTime(LocalDateTime.now()));
|
||||||
|
|
||||||
|
// 2. 激活子任务
|
||||||
|
List<String> childrenTaskIdList = getChildrenTaskIdList(task.getId());
|
||||||
|
for (String childrenTaskId : childrenTaskIdList) {
|
||||||
|
taskService.resolveTask(childrenTaskId);
|
||||||
|
}
|
||||||
|
// 2.1 更新任务扩展表中子任务为进行中
|
||||||
|
taskExtMapper.updateBatchByTaskIdList(childrenTaskIdList,
|
||||||
|
new BpmTaskExtDO().setResult(BpmProcessInstanceResultEnum.PROCESS.getResult()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理当前任务的父任务,主要处理“加签”的情况
|
||||||
|
*
|
||||||
|
* @param task 当前任务
|
||||||
|
*/
|
||||||
|
private void handleParentTask(Task task) {
|
||||||
|
String parentTaskId = task.getParentTaskId();
|
||||||
|
if (StrUtil.isBlank(parentTaskId)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 1. 判断当前任务的父任务是否还有子任务
|
||||||
|
Long childrenTaskCount = getChildrenTaskCount(parentTaskId);
|
||||||
|
if (childrenTaskCount > 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 2. 获取父任务
|
||||||
|
Task parentTask = validateTaskExist(parentTaskId);
|
||||||
|
|
||||||
|
// 3. 处理加签情况
|
||||||
|
String scopeType = parentTask.getScopeType();
|
||||||
|
if(!validateSignType(scopeType)){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 3.1 情况一:处理向前加签
|
||||||
|
if (BpmTaskAddSignTypeEnum.BEFORE.getType().equals(scopeType)) {
|
||||||
|
// 3.1.1 如果是向前加签的任务,则调用 resolveTask 指派父任务,将 owner 重新赋值给父任务的 assignee,这样它就可以被审批
|
||||||
|
taskService.resolveTask(parentTaskId);
|
||||||
|
// 3.1.2 更新任务拓展表为处理中
|
||||||
|
taskExtMapper.updateByTaskId(
|
||||||
|
new BpmTaskExtDO().setTaskId(parentTask.getId()).setResult(BpmProcessInstanceResultEnum.PROCESS.getResult()));
|
||||||
|
} else if (BpmTaskAddSignTypeEnum.AFTER.getType().equals(scopeType)) {
|
||||||
|
// 3.2 情况二:处理向后加签
|
||||||
|
handleParentTaskForAfterSign(parentTask);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. 子任务已处理完成,清空 scopeType 字段,修改 parentTask 信息,方便后续可以继续向前后向后加签
|
||||||
|
// 再查询一次的原因是避免报错:Task was updated by another transaction concurrently
|
||||||
|
// 因为前面处理后可能会导致 parentTask rev 字段被修改,需要重新获取最新的
|
||||||
|
parentTask = getTask(parentTaskId);
|
||||||
|
if (parentTask == null) {
|
||||||
|
// 为空的情况是:已经通过 handleAfterSign 方法将任务完成了,所以 ru_task 表会查不到数据
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
clearTaskScopeTypeAndSave(parentTask);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理后加签任务
|
||||||
|
*
|
||||||
|
* @param parentTask 当前审批任务的父任务
|
||||||
|
*/
|
||||||
|
// TODO @海:这个逻辑,怎么感觉可以是 parentTask 的 parent,再去调用 handleParentTask 方法;可以微信聊下;
|
||||||
|
private void handleParentTaskForAfterSign(Task parentTask) {
|
||||||
|
String parentTaskId = parentTask.getId();
|
||||||
|
// 1. 更新 parentTask 的任务拓展表为通过,并调用 complete 完成自己
|
||||||
|
BpmTaskExtDO currentTaskExt = taskExtMapper.selectByTaskId(parentTask.getId());
|
||||||
|
BpmTaskExtDO currentTaskExtUpdateObj = new BpmTaskExtDO().setTaskId(parentTask.getId())
|
||||||
|
.setResult(BpmProcessInstanceResultEnum.APPROVE.getResult());
|
||||||
|
if (currentTaskExt.getEndTime() == null) {
|
||||||
|
// 1.1 有这个判断是因为,以前没设置过结束时间,才去设置
|
||||||
|
currentTaskExtUpdateObj.setEndTime(LocalDateTime.now());
|
||||||
|
}
|
||||||
|
taskExtMapper.updateByTaskId(currentTaskExtUpdateObj);
|
||||||
|
// 1.2 完成自己(因为它已经没有子任务,所以也可以完成)
|
||||||
|
taskService.complete(parentTaskId);
|
||||||
|
|
||||||
|
// 2. 如果有父级,递归查询上级任务是否都已经完成
|
||||||
|
if (StrUtil.isEmpty(parentTask.getParentTaskId())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 2.1 判断整条链路的任务是否完成
|
||||||
|
// 例如从 A 任务加签了一个 B 任务,B 任务又加签了一个 C 任务,C 任务加签了 D 任务
|
||||||
|
// 此时,D 任务完成,要一直往上找到祖先任务 A调用 complete 方法完成 A 任务
|
||||||
|
boolean allChildrenTaskFinish = true;
|
||||||
|
while (StrUtil.isNotBlank(parentTask.getParentTaskId())) {
|
||||||
|
parentTask = validateTaskExist(parentTask.getParentTaskId());
|
||||||
|
BpmTaskExtDO parentTaskExt = taskExtMapper.selectByTaskId(parentTask.getId());
|
||||||
|
if (parentTaskExt == null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
boolean currentTaskFinish = BpmProcessInstanceResultEnum.isEndResult(parentTaskExt.getResult());
|
||||||
|
// 2.2 如果 allChildrenTaskFinish 已经被赋值为 false,则不会再赋值为 true,因为整个链路没有完成
|
||||||
|
if (allChildrenTaskFinish) {
|
||||||
|
allChildrenTaskFinish = currentTaskFinish;
|
||||||
|
}
|
||||||
|
// 2.3 任务已完成则不处理
|
||||||
|
if (currentTaskFinish) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3 处理非完成状态的任务
|
||||||
|
// 3.1 判断当前任务的父任务是否还有子任务
|
||||||
|
Long childrenTaskCount = getChildrenTaskCount(parentTaskExt.getTaskId());
|
||||||
|
if (childrenTaskCount > 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// 3.2 没有子任务,判断当前任务状态是否为 ADD_SIGN_BEFORE 待前加签任务完成
|
||||||
|
if (BpmProcessInstanceResultEnum.SIGN_BEFORE.getResult().equals(parentTaskExt.getResult())) {
|
||||||
|
// 3.3 需要修改该任务状态为处理中
|
||||||
|
taskService.resolveTask(parentTaskExt.getTaskId());
|
||||||
|
parentTaskExt.setResult(BpmProcessInstanceResultEnum.PROCESS.getResult());
|
||||||
|
taskExtMapper.updateByTaskId(parentTaskExt);
|
||||||
|
}
|
||||||
|
// 3.4 清空 scopeType 字段,用于任务没有子任务时使用该方法,方便任务可以再次被不同的方式加签
|
||||||
|
parentTask = validateTaskExist(parentTaskExt.getTaskId());
|
||||||
|
clearTaskScopeTypeAndSave(parentTask);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. 完成最后的顶级祖先任务
|
||||||
|
if (allChildrenTaskFinish) {
|
||||||
|
taskService.complete(parentTask.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清空 scopeType 字段,用于任务没有子任务时使用该方法,方便任务可以再次被不同的方式加签
|
||||||
|
*
|
||||||
|
* @param task 需要被清空的任务
|
||||||
|
*/
|
||||||
|
private void clearTaskScopeTypeAndSave(Task task) {
|
||||||
|
TaskEntityImpl taskImpl = (TaskEntityImpl) task;
|
||||||
|
taskImpl.setScopeType(null);
|
||||||
|
taskService.saveTask(task);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取子任务个数
|
||||||
|
*
|
||||||
|
* @param parentTaskId 父任务 ID
|
||||||
|
* @return 剩余子任务个数
|
||||||
|
*/
|
||||||
|
private Long getChildrenTaskCount(String parentTaskId) {
|
||||||
|
String tableName = managementService.getTableName(TaskEntity.class);
|
||||||
|
String sql = "SELECT COUNT(1) from " + tableName + " WHERE PARENT_TASK_ID_=#{parentTaskId}";
|
||||||
|
return taskService.createNativeTaskQuery().sql(sql).parameter("parentTaskId", parentTaskId).count();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 审批被委派的任务
|
||||||
|
*
|
||||||
|
* @param reqVO 前端请求参数,包含当前任务ID,审批意见等
|
||||||
|
* @param task 当前被审批的任务
|
||||||
|
*/
|
||||||
|
private void approveDelegateTask(BpmTaskApproveReqVO reqVO, Task task) {
|
||||||
|
// 1. 添加审批意见
|
||||||
|
AdminUserRespDTO currentUser = adminUserApi.getUser(WebFrameworkUtils.getLoginUserId()).getCheckedData();
|
||||||
|
AdminUserRespDTO sourceApproveUser = adminUserApi.getUser(NumberUtils.parseLong(task.getOwner())).getCheckedData();
|
||||||
|
Assert.notNull(sourceApproveUser, "委派任务找不到原审批人,需要检查数据");
|
||||||
|
String comment = StrUtil.format("[{}]完成委派任务,任务重新回到[{}]手中,审批意见为:{}", currentUser.getNickname(),
|
||||||
|
sourceApproveUser.getNickname(), reqVO.getReason());
|
||||||
|
taskService.addComment(reqVO.getId(), task.getProcessInstanceId(),
|
||||||
|
BpmCommentTypeEnum.DELEGATE.getType().toString(), comment);
|
||||||
|
|
||||||
|
// 2.1 调用 resolveTask 完成任务。
|
||||||
|
// 底层调用 TaskHelper.changeTaskAssignee(task, task.getOwner()):将 owner 设置为 assignee
|
||||||
|
taskService.resolveTask(task.getId());
|
||||||
|
// 2.2 更新任务拓展表为【处理中】
|
||||||
|
taskExtMapper.updateByTaskId(
|
||||||
|
new BpmTaskExtDO().setTaskId(task.getId()).setResult(BpmProcessInstanceResultEnum.PROCESS.getResult())
|
||||||
|
.setReason(reqVO.getReason()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void rejectTask(Long userId, @Valid BpmTaskRejectReqVO reqVO) {
|
public void rejectTask(Long userId, @Valid BpmTaskRejectReqVO reqVO) {
|
||||||
Task task = checkTask(userId, reqVO.getId());
|
Task task = validateTask(userId, reqVO.getId());
|
||||||
// 校验流程实例存在
|
// 校验流程实例存在
|
||||||
ProcessInstance instance = processInstanceService.getProcessInstance(task.getProcessInstanceId());
|
ProcessInstance instance = processInstanceService.getProcessInstance(task.getProcessInstanceId());
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
|
@ -207,14 +443,14 @@ public class BpmTaskServiceImpl implements BpmTaskService {
|
||||||
|
|
||||||
// 更新任务拓展表为不通过
|
// 更新任务拓展表为不通过
|
||||||
taskExtMapper.updateByTaskId(
|
taskExtMapper.updateByTaskId(
|
||||||
new BpmTaskExtDO().setTaskId(task.getId()).setResult(BpmProcessInstanceResultEnum.REJECT.getResult())
|
new BpmTaskExtDO().setTaskId(task.getId()).setResult(BpmProcessInstanceResultEnum.REJECT.getResult())
|
||||||
.setEndTime(LocalDateTime.now()).setReason(reqVO.getReason()));
|
.setEndTime(LocalDateTime.now()).setReason(reqVO.getReason()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateTaskAssignee(Long userId, BpmTaskUpdateAssigneeReqVO reqVO) {
|
public void updateTaskAssignee(Long userId, BpmTaskUpdateAssigneeReqVO reqVO) {
|
||||||
// 校验任务存在
|
// 校验任务存在
|
||||||
Task task = checkTask(userId, reqVO.getId());
|
Task task = validateTask(userId, reqVO.getId());
|
||||||
// 更新负责人
|
// 更新负责人
|
||||||
updateTaskAssignee(task.getId(), reqVO.getAssigneeUserId());
|
updateTaskAssignee(task.getId(), reqVO.getAssigneeUserId());
|
||||||
}
|
}
|
||||||
|
@ -230,21 +466,22 @@ public class BpmTaskServiceImpl implements BpmTaskService {
|
||||||
* @param userId 用户 id
|
* @param userId 用户 id
|
||||||
* @param taskId task id
|
* @param taskId task id
|
||||||
*/
|
*/
|
||||||
private Task checkTask(Long userId, String taskId) {
|
private Task validateTask(Long userId, String taskId) {
|
||||||
Task task = getTask(taskId);
|
Task task = validateTaskExist(taskId);
|
||||||
if (task == null) {
|
|
||||||
throw exception(TASK_COMPLETE_FAIL_NOT_EXISTS);
|
|
||||||
}
|
|
||||||
if (!Objects.equals(userId, NumberUtils.parseLong(task.getAssignee()))) {
|
if (!Objects.equals(userId, NumberUtils.parseLong(task.getAssignee()))) {
|
||||||
throw exception(TASK_COMPLETE_FAIL_ASSIGN_NOT_SELF);
|
throw exception(TASK_OPERATE_FAIL_ASSIGN_NOT_SELF);
|
||||||
}
|
}
|
||||||
return task;
|
return task;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createTaskExt(Task task) {
|
public void createTaskExt(Task task) {
|
||||||
BpmTaskExtDO taskExtDO =
|
BpmTaskExtDO taskExtDO = BpmTaskConvert.INSTANCE.convert2TaskExt(task)
|
||||||
BpmTaskConvert.INSTANCE.convert2TaskExt(task).setResult(BpmProcessInstanceResultEnum.PROCESS.getResult());
|
.setResult(BpmProcessInstanceResultEnum.PROCESS.getResult());
|
||||||
|
// 向后加签生成的任务,状态不能为进行中,需要等前面父任务完成
|
||||||
|
if (BpmTaskAddSignTypeEnum.AFTER_CHILDREN_TASK.getType().equals(task.getScopeType())) {
|
||||||
|
taskExtDO.setResult(BpmProcessInstanceResultEnum.WAIT_BEFORE_TASK.getResult());
|
||||||
|
}
|
||||||
taskExtMapper.insert(taskExtDO);
|
taskExtMapper.insert(taskExtDO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -292,21 +529,31 @@ public class BpmTaskServiceImpl implements BpmTaskService {
|
||||||
@Override
|
@Override
|
||||||
public void updateTaskExtAssign(Task task) {
|
public void updateTaskExtAssign(Task task) {
|
||||||
BpmTaskExtDO taskExtDO =
|
BpmTaskExtDO taskExtDO =
|
||||||
new BpmTaskExtDO().setAssigneeUserId(NumberUtils.parseLong(task.getAssignee())).setTaskId(task.getId());
|
new BpmTaskExtDO().setAssigneeUserId(NumberUtils.parseLong(task.getAssignee())).setTaskId(task.getId());
|
||||||
taskExtMapper.updateByTaskId(taskExtDO);
|
taskExtMapper.updateByTaskId(taskExtDO);
|
||||||
// 发送通知。在事务提交时,批量执行操作,所以直接查询会无法查询到 ProcessInstance,所以这里是通过监听事务的提交来实现。
|
// 发送通知。在事务提交时,批量执行操作,所以直接查询会无法查询到 ProcessInstance,所以这里是通过监听事务的提交来实现。
|
||||||
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
|
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
|
||||||
@Override
|
@Override
|
||||||
public void afterCommit() {
|
public void afterCommit() {
|
||||||
ProcessInstance processInstance =
|
if (StrUtil.isNotEmpty(task.getAssignee())) {
|
||||||
processInstanceService.getProcessInstance(task.getProcessInstanceId());
|
ProcessInstance processInstance =
|
||||||
AdminUserRespDTO startUser = adminUserApi.getUser(Long.valueOf(processInstance.getStartUserId())).getCheckedData();
|
processInstanceService.getProcessInstance(task.getProcessInstanceId());
|
||||||
messageService.sendMessageWhenTaskAssigned(
|
AdminUserRespDTO startUser = adminUserApi.getUser(Long.valueOf(processInstance.getStartUserId())).getCheckedData();
|
||||||
BpmTaskConvert.INSTANCE.convert(processInstance, startUser, task));
|
messageService.sendMessageWhenTaskAssigned(
|
||||||
|
BpmTaskConvert.INSTANCE.convert(processInstance, startUser, task));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Task validateTaskExist(String id) {
|
||||||
|
Task task = getTask(id);
|
||||||
|
if (task == null) {
|
||||||
|
throw exception(TASK_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
private Task getTask(String id) {
|
private Task getTask(String id) {
|
||||||
return taskService.createTaskQuery().taskId(id).singleResult();
|
return taskService.createTaskQuery().taskId(id).singleResult();
|
||||||
}
|
}
|
||||||
|
@ -315,4 +562,409 @@ public class BpmTaskServiceImpl implements BpmTaskService {
|
||||||
return historyService.createHistoricTaskInstanceQuery().taskId(id).singleResult();
|
return historyService.createHistoricTaskInstanceQuery().taskId(id).singleResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<BpmTaskSimpleRespVO> getReturnTaskList(String taskId) {
|
||||||
|
// 1. 校验当前任务 task 存在
|
||||||
|
Task task = validateTaskExist(taskId);
|
||||||
|
// 根据流程定义获取流程模型信息
|
||||||
|
BpmnModel bpmnModel = bpmModelService.getBpmnModelByDefinitionId(task.getProcessDefinitionId());
|
||||||
|
FlowElement source = BpmnModelUtils.getFlowElementById(bpmnModel, task.getTaskDefinitionKey());
|
||||||
|
if (source == null) {
|
||||||
|
throw exception(TASK_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2.1 查询该任务的前置任务节点的 key 集合
|
||||||
|
List<UserTask> previousUserList = BpmnModelUtils.getPreviousUserTaskList(source, null, null);
|
||||||
|
if (CollUtil.isEmpty(previousUserList)) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
// 2.2 过滤:只有串行可到达的节点,才可以回退。类似非串行、子流程无法退回
|
||||||
|
previousUserList.removeIf(userTask -> !BpmnModelUtils.isSequentialReachable(source, userTask, null));
|
||||||
|
return BpmTaskConvert.INSTANCE.convertList(previousUserList);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void returnTask(Long userId, BpmTaskReturnReqVO reqVO) {
|
||||||
|
// 1.1 当前任务 task
|
||||||
|
Task task = validateTask(userId, reqVO.getId());
|
||||||
|
if (task.isSuspended()) {
|
||||||
|
throw exception(TASK_IS_PENDING);
|
||||||
|
}
|
||||||
|
// 1.2 校验源头和目标节点的关系,并返回目标元素
|
||||||
|
FlowElement targetElement = validateTargetTaskCanReturn(task.getTaskDefinitionKey(), reqVO.getTargetDefinitionKey(), task.getProcessDefinitionId());
|
||||||
|
|
||||||
|
// 2. 调用 flowable 框架的回退逻辑
|
||||||
|
returnTask0(task, targetElement, reqVO);
|
||||||
|
|
||||||
|
// 3. 更新任务扩展表
|
||||||
|
taskExtMapper.updateByTaskId(new BpmTaskExtDO().setTaskId(task.getId())
|
||||||
|
.setResult(BpmProcessInstanceResultEnum.BACK.getResult())
|
||||||
|
.setEndTime(LocalDateTime.now()).setReason(reqVO.getReason()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 回退流程节点时,校验目标任务节点是否可回退
|
||||||
|
*
|
||||||
|
* @param sourceKey 当前任务节点 Key
|
||||||
|
* @param targetKey 目标任务节点 key
|
||||||
|
* @param processDefinitionId 当前流程定义 ID
|
||||||
|
* @return 目标任务节点元素
|
||||||
|
*/
|
||||||
|
private FlowElement validateTargetTaskCanReturn(String sourceKey, String targetKey, String processDefinitionId) {
|
||||||
|
// 1.1 获取流程模型信息
|
||||||
|
BpmnModel bpmnModel = bpmModelService.getBpmnModelByDefinitionId(processDefinitionId);
|
||||||
|
// 1.3 获取当前任务节点元素
|
||||||
|
FlowElement source = BpmnModelUtils.getFlowElementById(bpmnModel, sourceKey);
|
||||||
|
// 1.3 获取跳转的节点元素
|
||||||
|
FlowElement target = BpmnModelUtils.getFlowElementById(bpmnModel, targetKey);
|
||||||
|
if (target == null) {
|
||||||
|
throw exception(TASK_TARGET_NODE_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2.2 只有串行可到达的节点,才可以回退。类似非串行、子流程无法退回
|
||||||
|
if (!BpmnModelUtils.isSequentialReachable(source, target, null)) {
|
||||||
|
throw exception(TASK_RETURN_FAIL_SOURCE_TARGET_ERROR);
|
||||||
|
}
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行回退逻辑
|
||||||
|
*
|
||||||
|
* @param currentTask 当前回退的任务
|
||||||
|
* @param targetElement 需要回退到的目标任务
|
||||||
|
* @param reqVO 前端参数封装
|
||||||
|
*/
|
||||||
|
public void returnTask0(Task currentTask, FlowElement targetElement, BpmTaskReturnReqVO reqVO) {
|
||||||
|
// 1. 获得所有需要回撤的任务 taskDefinitionKey,用于稍后的 moveActivityIdsToSingleActivityId 回撤
|
||||||
|
// 1.1 获取所有正常进行的任务节点 Key
|
||||||
|
List<Task> taskList = taskService.createTaskQuery().processInstanceId(currentTask.getProcessInstanceId()).list();
|
||||||
|
List<String> runTaskKeyList = convertList(taskList, Task::getTaskDefinitionKey);
|
||||||
|
// 1.2 通过 targetElement 的出口连线,计算在 runTaskKeyList 有哪些 key 需要被撤回
|
||||||
|
// 为什么不直接使用 runTaskKeyList 呢?因为可能存在多个审批分支,例如说:A -> B -> C 和 D -> F,而只要 C 撤回到 A,需要排除掉 F
|
||||||
|
List<UserTask> returnUserTaskList = BpmnModelUtils.iteratorFindChildUserTasks(targetElement, runTaskKeyList, null, null);
|
||||||
|
List<String> returnTaskKeyList = convertList(returnUserTaskList, UserTask::getId);
|
||||||
|
|
||||||
|
// 2. 给当前要被回退的 task 数组,设置回退意见
|
||||||
|
taskList.forEach(task -> {
|
||||||
|
// 需要排除掉,不需要设置回退意见的任务
|
||||||
|
if (!returnTaskKeyList.contains(task.getTaskDefinitionKey())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
taskService.addComment(task.getId(), currentTask.getProcessInstanceId(),
|
||||||
|
BpmCommentTypeEnum.BACK.getType().toString(), reqVO.getReason());
|
||||||
|
});
|
||||||
|
|
||||||
|
// 3. 执行驳回
|
||||||
|
runtimeService.createChangeActivityStateBuilder()
|
||||||
|
.processInstanceId(currentTask.getProcessInstanceId())
|
||||||
|
.moveActivityIdsToSingleActivityId(returnTaskKeyList, // 当前要跳转的节点列表( 1 或多)
|
||||||
|
reqVO.getTargetDefinitionKey()) // targetKey 跳转到的节点(1)
|
||||||
|
.changeState();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void delegateTask(Long userId, BpmTaskDelegateReqVO reqVO) {
|
||||||
|
// 1.1 校验任务
|
||||||
|
Task task = validateTaskCanDelegate(userId, reqVO);
|
||||||
|
// 1.2 校验目标用户存在
|
||||||
|
AdminUserRespDTO delegateUser = adminUserApi.getUser(reqVO.getDelegateUserId()).getCheckedData();
|
||||||
|
if (delegateUser == null) {
|
||||||
|
throw exception(TASK_DELEGATE_FAIL_USER_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 添加审批意见
|
||||||
|
AdminUserRespDTO currentUser = adminUserApi.getUser(userId).getCheckedData();
|
||||||
|
String comment = StrUtil.format("[{}]将任务委派给[{}],委派理由为:{}", currentUser.getNickname(),
|
||||||
|
delegateUser.getNickname(), reqVO.getReason());
|
||||||
|
String taskId = reqVO.getId();
|
||||||
|
taskService.addComment(taskId, task.getProcessInstanceId(),
|
||||||
|
BpmCommentTypeEnum.DELEGATE.getType().toString(), comment);
|
||||||
|
|
||||||
|
// 3.1 设置任务所有人 (owner) 为原任务的处理人 (assignee)
|
||||||
|
taskService.setOwner(taskId, task.getAssignee());
|
||||||
|
// 3.2 执行委派,将任务委派给 receiveId
|
||||||
|
taskService.delegateTask(taskId, reqVO.getDelegateUserId().toString());
|
||||||
|
// 3.3 更新任务拓展表为【委派】
|
||||||
|
taskExtMapper.updateByTaskId(
|
||||||
|
new BpmTaskExtDO().setTaskId(task.getId()).setResult(BpmProcessInstanceResultEnum.DELEGATE.getResult())
|
||||||
|
.setReason(reqVO.getReason()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验任务委派参数
|
||||||
|
*
|
||||||
|
* @param userId 用户编号
|
||||||
|
* @param reqVO 任务编号,接收人ID
|
||||||
|
* @return 当前任务信息
|
||||||
|
*/
|
||||||
|
private Task validateTaskCanDelegate(Long userId, BpmTaskDelegateReqVO reqVO) {
|
||||||
|
// 校验任务
|
||||||
|
Task task = validateTask(userId, reqVO.getId());
|
||||||
|
// 校验当前审批人和被委派人不是同一人
|
||||||
|
if (task.getAssignee().equals(reqVO.getDelegateUserId().toString())) {
|
||||||
|
throw exception(TASK_DELEGATE_FAIL_USER_REPEAT);
|
||||||
|
}
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void createSignTask(Long userId, BpmTaskAddSignReqVO reqVO) {
|
||||||
|
// 1. 获取和校验任务
|
||||||
|
TaskEntityImpl taskEntity = validateAddSign(userId, reqVO);
|
||||||
|
List<AdminUserRespDTO> userList = adminUserApi.getUserList(reqVO.getUserIdList()).getCheckedData();
|
||||||
|
if (CollUtil.isEmpty(userList)) {
|
||||||
|
throw exception(TASK_ADD_SIGN_USER_NOT_EXIST);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 处理当前任务
|
||||||
|
// 2.1 开启计数功能,主要用于为了让表 ACT_RU_TASK 中的 SUB_TASK_COUNT_ 字段记录下总共有多少子任务,后续可能有用
|
||||||
|
taskEntity.setCountEnabled(true);
|
||||||
|
if (reqVO.getType().equals(BpmTaskAddSignTypeEnum.BEFORE.getType())) {
|
||||||
|
// 2.2 向前加签,设置 owner,置空 assign。等子任务都完成后,再调用 resolveTask 重新将 owner 设置为 assign
|
||||||
|
// 原因是:不能和向前加签的子任务一起审批,需要等前面的子任务都完成才能审批
|
||||||
|
taskEntity.setOwner(taskEntity.getAssignee());
|
||||||
|
taskEntity.setAssignee(null);
|
||||||
|
// 2.3 更新扩展表状态
|
||||||
|
taskExtMapper.updateByTaskId(
|
||||||
|
new BpmTaskExtDO().setTaskId(taskEntity.getId())
|
||||||
|
.setResult(BpmProcessInstanceResultEnum.SIGN_BEFORE.getResult())
|
||||||
|
.setReason(reqVO.getReason()));
|
||||||
|
}
|
||||||
|
// 2.4 记录加签方式,完成任务时需要用到判断
|
||||||
|
taskEntity.setScopeType(reqVO.getType());
|
||||||
|
// 2.5 保存当前任务修改后的值
|
||||||
|
taskService.saveTask(taskEntity);
|
||||||
|
|
||||||
|
// 3. 创建加签任务
|
||||||
|
createSignTask(convertList(reqVO.getUserIdList(), String::valueOf), taskEntity);
|
||||||
|
|
||||||
|
// 4. 记录加签 comment,拼接结果为: [当前用户]向前加签/向后加签给了[多个用户],理由为:reason
|
||||||
|
AdminUserRespDTO currentUser = adminUserApi.getUser(userId).getCheckedData();
|
||||||
|
String comment = StrUtil.format(BpmCommentTypeEnum.ADD_SIGN.getComment(), currentUser.getNickname(),
|
||||||
|
BpmTaskAddSignTypeEnum.formatDesc(reqVO.getType()), String.join(",", convertList(userList, AdminUserRespDTO::getNickname)), reqVO.getReason());
|
||||||
|
taskService.addComment(reqVO.getId(), taskEntity.getProcessInstanceId(),
|
||||||
|
BpmCommentTypeEnum.ADD_SIGN.getType().toString(), comment);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验任务的加签是否一致
|
||||||
|
* <p>
|
||||||
|
* 1. 如果存在“向前加签”的任务,则不能“向后加签”
|
||||||
|
* 2. 如果存在“向后加签”的任务,则不能“向前加签”
|
||||||
|
*
|
||||||
|
* @param userId 当前用户 ID
|
||||||
|
* @param reqVO 请求参数,包含任务 ID 和加签类型
|
||||||
|
* @return 当前任务
|
||||||
|
*/
|
||||||
|
private TaskEntityImpl validateAddSign(Long userId, BpmTaskAddSignReqVO reqVO) {
|
||||||
|
TaskEntityImpl taskEntity = (TaskEntityImpl) validateTask(userId, reqVO.getId());
|
||||||
|
// 向前加签和向后加签不能同时存在
|
||||||
|
if (StrUtil.isNotBlank(taskEntity.getScopeType())
|
||||||
|
&& ObjectUtil.notEqual(BpmTaskAddSignTypeEnum.AFTER_CHILDREN_TASK.getType(), taskEntity.getScopeType())
|
||||||
|
&& ObjectUtil.notEqual(taskEntity.getScopeType(), reqVO.getType())) {
|
||||||
|
throw exception(TASK_ADD_SIGN_TYPE_ERROR,
|
||||||
|
BpmTaskAddSignTypeEnum.formatDesc(taskEntity.getScopeType()), BpmTaskAddSignTypeEnum.formatDesc(reqVO.getType()));
|
||||||
|
}
|
||||||
|
// 同一个 key 的任务,审批人不重复
|
||||||
|
List<Task> taskList = taskService.createTaskQuery().processInstanceId(taskEntity.getProcessInstanceId())
|
||||||
|
.taskDefinitionKey(taskEntity.getTaskDefinitionKey()).list();
|
||||||
|
List<Long> currentAssigneeList = convertList(taskList, task -> NumberUtils.parseLong(task.getAssignee()));
|
||||||
|
// 保留交集在 currentAssigneeList 中
|
||||||
|
currentAssigneeList.retainAll(reqVO.getUserIdList());
|
||||||
|
if (CollUtil.isNotEmpty(currentAssigneeList)) {
|
||||||
|
List<AdminUserRespDTO> userList = adminUserApi.getUserList(currentAssigneeList).getCheckedData();
|
||||||
|
throw exception(TASK_ADD_SIGN_USER_REPEAT, String.join(",", convertList(userList, AdminUserRespDTO::getNickname)));
|
||||||
|
}
|
||||||
|
return taskEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建加签子任务
|
||||||
|
*
|
||||||
|
* @param addSingUserIdList 被加签的用户 ID
|
||||||
|
* @param taskEntity 被加签的任务
|
||||||
|
*/
|
||||||
|
private void createSignTask(List<String> addSingUserIdList, TaskEntityImpl taskEntity) {
|
||||||
|
if (CollUtil.isEmpty(addSingUserIdList)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 创建加签人的新任务,全部基于 taskEntity 为父任务来创建
|
||||||
|
for (String addSignId : addSingUserIdList) {
|
||||||
|
if (StrUtil.isBlank(addSignId)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
createSignTask(taskEntity, addSignId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建加签子任务
|
||||||
|
*
|
||||||
|
* @param parentTask 父任务
|
||||||
|
* @param assignee 子任务的执行人
|
||||||
|
*/
|
||||||
|
private void createSignTask(TaskEntityImpl parentTask, String assignee) {
|
||||||
|
// 1. 生成子任务
|
||||||
|
TaskEntityImpl task = (TaskEntityImpl) taskService.newTask(IdUtil.fastSimpleUUID());
|
||||||
|
task = BpmTaskConvert.INSTANCE.convert(task, parentTask);
|
||||||
|
if (BpmTaskAddSignTypeEnum.BEFORE.getType().equals(parentTask.getScopeType())) {
|
||||||
|
// 2.1 前加签,设置审批人
|
||||||
|
task.setAssignee(assignee);
|
||||||
|
} else {
|
||||||
|
// 2.2.1 设置 owner 不设置 assignee 是因为不能同时审批,需要等父任务完成
|
||||||
|
task.setOwner(assignee);
|
||||||
|
// 2.2.2 设置向后加签任务的 scopeType 为 afterChildrenTask,用于设置任务扩展表的状态
|
||||||
|
task.setScopeType(BpmTaskAddSignTypeEnum.AFTER_CHILDREN_TASK.getType());
|
||||||
|
}
|
||||||
|
// 2. 保存子任务
|
||||||
|
taskService.saveTask(task);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void deleteSignTask(Long userId, BpmTaskSubSignReqVO reqVO) {
|
||||||
|
// 1.1 校验 task 可以被减签
|
||||||
|
Task task = validateSubSign(reqVO.getId());
|
||||||
|
// 1.2 校验取消人存在
|
||||||
|
AdminUserRespDTO cancelUser = null;
|
||||||
|
if (StrUtil.isNotBlank(task.getAssignee())) {
|
||||||
|
cancelUser = adminUserApi.getUser(NumberUtils.parseLong(task.getAssignee())).getCheckedData();
|
||||||
|
}
|
||||||
|
if (cancelUser == null && StrUtil.isNotBlank(task.getOwner())) {
|
||||||
|
cancelUser = adminUserApi.getUser(NumberUtils.parseLong(task.getOwner())).getCheckedData();
|
||||||
|
}
|
||||||
|
Assert.notNull(cancelUser, "任务中没有所有者和审批人,数据错误");
|
||||||
|
|
||||||
|
// 2. 删除任务和对应子任务
|
||||||
|
// 2.1 获取所有需要删除的任务 ID ,包含当前任务和所有子任务
|
||||||
|
List<String> allTaskIdList = getAllChildTaskIds(task.getId());
|
||||||
|
// 2.2 删除任务和所有子任务
|
||||||
|
taskService.deleteTasks(allTaskIdList);
|
||||||
|
// 2.3 修改扩展表状态为取消
|
||||||
|
AdminUserRespDTO user = adminUserApi.getUser(userId).getCheckedData();
|
||||||
|
taskExtMapper.updateBatchByTaskIdList(allTaskIdList, new BpmTaskExtDO().setResult(BpmProcessInstanceResultEnum.CANCEL.getResult())
|
||||||
|
.setReason(StrUtil.format("由于{}操作[减签],任务被取消", user.getNickname())));
|
||||||
|
|
||||||
|
// 3. 记录日志到父任务中。先记录日志是因为,通过 handleParentTask 方法之后,任务可能被完成了,并且不存在了,会报异常,所以先记录
|
||||||
|
String comment = StrUtil.format(BpmCommentTypeEnum.SUB_SIGN.getComment(), user.getNickname(), cancelUser.getNickname());
|
||||||
|
taskService.addComment(task.getParentTaskId(), task.getProcessInstanceId(),
|
||||||
|
BpmCommentTypeEnum.SUB_SIGN.getType().toString(), comment);
|
||||||
|
|
||||||
|
// 4. 处理当前任务的父任务
|
||||||
|
handleParentTask(task);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验任务是否能被减签
|
||||||
|
*
|
||||||
|
* @param id 任务ID
|
||||||
|
* @return 任务信息
|
||||||
|
*/
|
||||||
|
private Task validateSubSign(String id) {
|
||||||
|
Task task = validateTaskExist(id);
|
||||||
|
|
||||||
|
// 必须有 scopeType
|
||||||
|
String scopeType = task.getScopeType();
|
||||||
|
if (StrUtil.isEmpty(scopeType)) {
|
||||||
|
throw exception(TASK_SUB_SIGN_NO_PARENT);
|
||||||
|
}
|
||||||
|
// 并且值为 向前和向后加签
|
||||||
|
if (!validateSignType(scopeType)) {
|
||||||
|
throw exception(TASK_SUB_SIGN_NO_PARENT);
|
||||||
|
}
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断当前类型是否为加签
|
||||||
|
* @param scopeType 任务的 scopeType
|
||||||
|
* @return 当前 scopeType 为加签则返回 true
|
||||||
|
*/
|
||||||
|
private boolean validateSignType(String scopeType){
|
||||||
|
return StrUtil.equalsAny(scopeType,BpmTaskAddSignTypeEnum.BEFORE.getType(),scopeType, BpmTaskAddSignTypeEnum.AFTER.getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取所有要被取消的删除的任务 ID 集合
|
||||||
|
*
|
||||||
|
* @param parentTaskId 父级任务ID
|
||||||
|
* @return 所有任务ID
|
||||||
|
*/
|
||||||
|
public List<String> getAllChildTaskIds(String parentTaskId) {
|
||||||
|
List<String> allChildTaskIds = new ArrayList<>();
|
||||||
|
// 1. 递归获取子级
|
||||||
|
Stack<String> stack = new Stack<>();
|
||||||
|
// 1.1 将根任务ID入栈
|
||||||
|
stack.push(parentTaskId);
|
||||||
|
//控制遍历的次数不超过 Byte.MAX_VALUE,避免脏数据造成死循环
|
||||||
|
int count = 0;
|
||||||
|
// TODO @海:< 的前后空格,要注意哈;
|
||||||
|
while (!stack.isEmpty() && count<Byte.MAX_VALUE) {
|
||||||
|
// 1.2 弹出栈顶任务ID
|
||||||
|
String taskId = stack.pop();
|
||||||
|
// 1.3 将任务ID添加到结果集合中
|
||||||
|
allChildTaskIds.add(taskId);
|
||||||
|
// 1.4 获取该任务的子任务列表
|
||||||
|
// TODO @海:有个更高效的写法;一次性去 in 一层;不然每个节点,都去查询一次 db, 太浪费了;每次 in,最终就是 O(h) 查询,而不是 O(n) 查询;
|
||||||
|
List<String> childrenTaskIdList = getChildrenTaskIdList(taskId);
|
||||||
|
if (CollUtil.isNotEmpty(childrenTaskIdList)) {
|
||||||
|
for (String childTaskId : childrenTaskIdList) {
|
||||||
|
// 1.5 将子任务ID入栈,以便后续处理
|
||||||
|
stack.push(childTaskId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
return allChildTaskIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取指定父级任务的所有子任务 ID 集合
|
||||||
|
*
|
||||||
|
* @param parentTaskId 父任务 ID
|
||||||
|
* @return 所有子任务的 ID 集合
|
||||||
|
*/
|
||||||
|
private List<String> getChildrenTaskIdList(String parentTaskId) {
|
||||||
|
return convertList(getChildrenTaskList0(parentTaskId), Task::getId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取指定父级任务的所有子任务 ID 集合
|
||||||
|
*
|
||||||
|
* @param parentTaskId 父任务 ID
|
||||||
|
* @return 所有子任务的 ID 集合
|
||||||
|
*/
|
||||||
|
private List<Task> getChildrenTaskList0(String parentTaskId) {
|
||||||
|
String tableName = managementService.getTableName(TaskEntity.class);
|
||||||
|
// taskService.createTaskQuery() 没有 parentId 参数,所以写 sql 查询
|
||||||
|
String sql = "select ID_,OWNER_,ASSIGNEE_ from " + tableName + " where PARENT_TASK_ID_=#{parentTaskId}";
|
||||||
|
return taskService.createNativeTaskQuery().sql(sql).parameter("parentTaskId", parentTaskId).list();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<BpmTaskSubSignRespVO> getChildrenTaskList(String parentId) {
|
||||||
|
// 1. 只查询进行中的任务 后加签的任务,可能不存在 assignee,所以还需要查询 owner
|
||||||
|
List<Task> taskList = getChildrenTaskList0(parentId);
|
||||||
|
if (CollUtil.isEmpty(taskList)) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
List<String> childrenTaskIdList = convertList(taskList, Task::getId);
|
||||||
|
|
||||||
|
// 2.1 将 owner 和 assignee 统一到一个集合中
|
||||||
|
List<Long> userIds = convertListByFlatMap(taskList, control ->
|
||||||
|
Stream.of(NumberUtils.parseLong(control.getAssignee()), NumberUtils.parseLong(control.getOwner()))
|
||||||
|
.filter(Objects::nonNull));
|
||||||
|
// 2.2 组装数据
|
||||||
|
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(userIds);
|
||||||
|
List<BpmTaskExtDO> taskExtList = taskExtMapper.selectProcessListByTaskIds(childrenTaskIdList);
|
||||||
|
Map<String, Task> idTaskMap = convertMap(taskList, TaskInfo::getId);
|
||||||
|
return BpmTaskConvert.INSTANCE.convertList(taskExtList, userMap, idTaskMap);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ public interface AdminUserApi {
|
||||||
@GetMapping(PREFIX + "/list")
|
@GetMapping(PREFIX + "/list")
|
||||||
@Operation(summary = "通过用户 ID 查询用户们")
|
@Operation(summary = "通过用户 ID 查询用户们")
|
||||||
@Parameter(name = "ids", description = "部门编号数组", example = "1,2", required = true)
|
@Parameter(name = "ids", description = "部门编号数组", example = "1,2", required = true)
|
||||||
CommonResult<List<AdminUserRespDTO>> getUsers(@RequestParam("ids") Collection<Long> ids);
|
CommonResult<List<AdminUserRespDTO>> getUserList(@RequestParam("ids") Collection<Long> ids);
|
||||||
|
|
||||||
@GetMapping(PREFIX + "/list-by-dept-id")
|
@GetMapping(PREFIX + "/list-by-dept-id")
|
||||||
@Operation(summary = "获得指定部门的用户数组")
|
@Operation(summary = "获得指定部门的用户数组")
|
||||||
|
@ -49,7 +49,7 @@ public interface AdminUserApi {
|
||||||
* @return 用户 Map
|
* @return 用户 Map
|
||||||
*/
|
*/
|
||||||
default Map<Long, AdminUserRespDTO> getUserMap(Collection<Long> ids) {
|
default Map<Long, AdminUserRespDTO> getUserMap(Collection<Long> ids) {
|
||||||
List<AdminUserRespDTO> users = getUsers(ids).getCheckedData();
|
List<AdminUserRespDTO> users = getUserList(ids).getCheckedData();
|
||||||
return CollectionUtils.convertMap(users, AdminUserRespDTO::getId);
|
return CollectionUtils.convertMap(users, AdminUserRespDTO::getId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ public class AdminUserApiImpl implements AdminUserApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommonResult<List<AdminUserRespDTO>> getUsers(Collection<Long> ids) {
|
public CommonResult<List<AdminUserRespDTO>> getUserList(Collection<Long> ids) {
|
||||||
List<AdminUserDO> users = userService.getUserList(ids);
|
List<AdminUserDO> users = userService.getUserList(ids);
|
||||||
return success(UserConvert.INSTANCE.convertList4(users));
|
return success(UserConvert.INSTANCE.convertList4(users));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue