fix: 方法,变量名词,注释规范
This commit is contained in:
parent
b13f71424b
commit
921f99d39d
|
@ -46,10 +46,10 @@ public interface ErrorCodeConstants {
|
|||
ErrorCode TASK_COMPLETE_FAIL_NOT_EXISTS = new ErrorCode(1_009_005_000, "审批任务失败,原因:该任务不处于未审批");
|
||||
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_NOT_ACTIVITY = new ErrorCode(1_009_005_003, "当前任务不属于活动状态,不能操作");
|
||||
ErrorCode TASK_SOURCE_TARGET_ERROR = new ErrorCode(1_009_005_004, " 当前节点相对于目标节点,不属于串行关系,无法回退");
|
||||
ErrorCode TASK_IS_PENDING = new ErrorCode(1_009_005_003, "当前任务处于挂起状态,不能操作");
|
||||
ErrorCode TASK_SOURCE_TARGET_ERROR = new ErrorCode(1_009_005_004, "目标节点是在并行网关上或非同一路线上,不可跳转");
|
||||
ErrorCode TASK_TARGET_NODE_NOT_EXISTS = new ErrorCode(1_009_005_005, " 目标节点不存在");
|
||||
ErrorCode TASK_ROLLBACK_FAIL = new ErrorCode(1_009_005_006, "回退任务失败,选择回退的节点没有需要回滚的任务!请重新选择其他任务节点");
|
||||
ErrorCode TASK_RETURN_FAIL = new ErrorCode(1_009_005_006, "回退任务失败,选择回退的节点没有需要回滚的任务!请重新选择其他任务节点");
|
||||
// ========== 流程任务分配规则 1-009-006-000 ==========
|
||||
ErrorCode TASK_ASSIGN_RULE_EXISTS = new ErrorCode(1_009_006_000, "流程({}) 的任务({}) 已经存在分配规则");
|
||||
ErrorCode TASK_ASSIGN_RULE_NOT_EXISTS = new ErrorCode(1_009_006_001, "流程任务分配规则不存在");
|
||||
|
|
|
@ -77,16 +77,17 @@ public class BpmTaskController {
|
|||
|
||||
@GetMapping("/get-return-list")
|
||||
@Operation(summary = "获取所有可回退的节点", description = "用于【流程详情】的【回退】按钮")
|
||||
@PreAuthorize("@ss.hasPermission('bpm:task:rollback')")
|
||||
public CommonResult<List<BpmTaskRollbackRespVO>> getReturnList(String taskId) {
|
||||
return success(taskService.findReturnTaskList(taskId));
|
||||
@Parameter(name = "taskId", description = "当前任务ID", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('bpm:task:return')")
|
||||
public CommonResult<List<BpmTaskSimpleRespVO>> getReturnList(@RequestParam("taskId") String taskId) {
|
||||
return success(taskService.getReturnTaskList(taskId));
|
||||
}
|
||||
|
||||
@PutMapping("/rollback")
|
||||
@PutMapping("/return")
|
||||
@Operation(summary = "回退任务", description = "用于【流程详情】的【回退】按钮")
|
||||
@PreAuthorize("@ss.hasPermission('bpm:task:rollback')")
|
||||
public CommonResult<Boolean> getReturnList(@Valid @RequestBody BpmTaskRollbackReqVO reqVO) {
|
||||
taskService.taskReturn(reqVO);
|
||||
@PreAuthorize("@ss.hasPermission('bpm:task:return')")
|
||||
public CommonResult<Boolean> returnTask(@Valid @RequestBody BpmTaskReturnReqVO reqVO) {
|
||||
taskService.returnTask(reqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,17 +7,17 @@ import javax.validation.constraints.NotEmpty;
|
|||
|
||||
@Schema(description = "管理后台 - 回退流程任务的 Request VO")
|
||||
@Data
|
||||
public class BpmTaskRollbackReqVO {
|
||||
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")
|
||||
@Schema(description = "回退到的任务 Key", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@NotEmpty(message = "回退到的任务Key不能为空")
|
||||
private String targetDefinitionKey;
|
||||
|
||||
@Schema(description = "回退意见")
|
||||
@Schema(description = "回退意见", example = "")
|
||||
private String reason;
|
||||
|
||||
}
|
|
@ -8,10 +8,10 @@ import lombok.Data;
|
|||
*/
|
||||
@Schema(description = "管理后台 - 流程任务的 可回退的节点 Response VO")
|
||||
@Data
|
||||
public class BpmTaskRollbackRespVO {
|
||||
public class BpmTaskSimpleRespVO {
|
||||
|
||||
@Schema(description = "任务定义的标识", requiredMode = Schema.RequiredMode.REQUIRED, example = "Activity_one")
|
||||
private String taskDefinitionKey;
|
||||
private String definitionKey;
|
||||
|
||||
@Schema(description = "任务名词", requiredMode = Schema.RequiredMode.REQUIRED, example = "经理审批")
|
||||
private String name;
|
|
@ -6,7 +6,7 @@ import cn.iocoder.yudao.framework.common.util.date.DateUtils;
|
|||
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.BpmTaskRespVO;
|
||||
import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task.BpmTaskRollbackRespVO;
|
||||
import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task.BpmTaskSimpleRespVO;
|
||||
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.service.message.dto.BpmMessageSendWhenTaskCreatedReqDTO;
|
||||
|
@ -141,9 +141,9 @@ public interface BpmTaskConvert {
|
|||
}
|
||||
|
||||
@Mapping(source = "taskDefinitionKey", target = "id")
|
||||
default List<BpmTaskRollbackRespVO> convertList(List<FlowElement> elementList) {
|
||||
return CollectionUtils.convertList(elementList, element -> new BpmTaskRollbackRespVO()
|
||||
default List<BpmTaskSimpleRespVO> convertList(List<FlowElement> elementList) {
|
||||
return CollectionUtils.convertList(elementList, element -> new BpmTaskSimpleRespVO()
|
||||
.setName(element.getName())
|
||||
.setTaskDefinitionKey(element.getId()));
|
||||
.setDefinitionKey(element.getId()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@ public interface BpmTaskService {
|
|||
*
|
||||
* @param userId 用户编号
|
||||
* @param pageReqVO 分页请求
|
||||
*
|
||||
* @return 流程任务分页
|
||||
*/
|
||||
PageResult<BpmTaskTodoPageItemRespVO> getTodoTaskPage(Long userId, BpmTaskTodoPageReqVO pageReqVO);
|
||||
|
@ -32,7 +31,6 @@ public interface BpmTaskService {
|
|||
*
|
||||
* @param userId 用户编号
|
||||
* @param pageReqVO 分页请求
|
||||
*
|
||||
* @return 流程任务分页
|
||||
*/
|
||||
PageResult<BpmTaskDonePageItemRespVO> getDoneTaskPage(Long userId, BpmTaskDonePageReqVO pageReqVO);
|
||||
|
@ -41,19 +39,17 @@ public interface BpmTaskService {
|
|||
* 获得流程任务 Map
|
||||
*
|
||||
* @param processInstanceIds 流程实例的编号数组
|
||||
*
|
||||
* @return 流程任务 Map
|
||||
*/
|
||||
default Map<String, List<Task>> getTaskMapByProcessInstanceIds(List<String> processInstanceIds) {
|
||||
return CollectionUtils.convertMultiMap(getTasksByProcessInstanceIds(processInstanceIds),
|
||||
Task::getProcessInstanceId);
|
||||
Task::getProcessInstanceId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得流程任务列表
|
||||
*
|
||||
* @param processInstanceIds 流程实例的编号数组
|
||||
*
|
||||
* @return 流程任务列表
|
||||
*/
|
||||
List<Task> getTasksByProcessInstanceIds(List<String> processInstanceIds);
|
||||
|
@ -62,7 +58,6 @@ public interface BpmTaskService {
|
|||
* 获得指令流程实例的流程任务列表,包括所有状态的
|
||||
*
|
||||
* @param processInstanceId 流程实例的编号
|
||||
*
|
||||
* @return 流程任务列表
|
||||
*/
|
||||
List<BpmTaskRespVO> getTaskListByProcessInstanceId(String processInstanceId);
|
||||
|
@ -128,16 +123,18 @@ public interface BpmTaskService {
|
|||
void updateTaskExtAssign(Task task);
|
||||
|
||||
/**
|
||||
* 获取当前人物的可回退的流程集合
|
||||
* 获取当前任务的可回退的流程集合
|
||||
*
|
||||
* @param taskId 当前的任务ID
|
||||
* @return 可以回退的节点列表
|
||||
*/
|
||||
List<BpmTaskRollbackRespVO> findReturnTaskList(String taskId);
|
||||
List<BpmTaskSimpleRespVO> getReturnTaskList(String taskId);
|
||||
|
||||
/**
|
||||
* 将任务回退到指定的 targetDefinitionKey 位置
|
||||
*
|
||||
* @param reqVO 回退的任务key和当前所在的任务ID
|
||||
*/
|
||||
void taskReturn(BpmTaskRollbackReqVO reqVO);
|
||||
void returnTask(BpmTaskReturnReqVO reqVO);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package cn.iocoder.yudao.module.bpm.service.task;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
|
@ -22,19 +21,13 @@ 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.dto.AdminUserRespDTO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.flowable.bpmn.constants.BpmnXMLConstants;
|
||||
import org.flowable.bpmn.model.BpmnModel;
|
||||
import org.flowable.bpmn.model.FlowElement;
|
||||
import org.flowable.bpmn.model.UserTask;
|
||||
import org.flowable.common.engine.api.FlowableException;
|
||||
import org.flowable.common.engine.api.FlowableObjectNotFoundException;
|
||||
import org.flowable.engine.HistoryService;
|
||||
import org.flowable.engine.RepositoryService;
|
||||
import org.flowable.engine.RuntimeService;
|
||||
import org.flowable.engine.TaskService;
|
||||
import org.flowable.engine.history.HistoricActivityInstance;
|
||||
import org.flowable.engine.history.HistoricProcessInstance;
|
||||
import org.flowable.engine.repository.ProcessDefinition;
|
||||
import org.flowable.engine.runtime.ProcessInstance;
|
||||
import org.flowable.task.api.Task;
|
||||
import org.flowable.task.api.TaskQuery;
|
||||
|
@ -333,9 +326,12 @@ public class BpmTaskServiceImpl implements BpmTaskService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<BpmTaskRollbackRespVO> findReturnTaskList(String taskId) {
|
||||
public List<BpmTaskSimpleRespVO> getReturnTaskList(String taskId) {
|
||||
// 当前任务 task
|
||||
Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
|
||||
Task task = getTask(taskId);
|
||||
if (null == task) {
|
||||
throw exception(TASK_NOT_EXISTS);
|
||||
}
|
||||
// 根据流程定义获取流程模型信息
|
||||
BpmnModel bpmnModel = bpmModelService.getBpmnModelByDefinitionId(task.getProcessDefinitionId());
|
||||
// 查询该任务的前置任务节点的key集合
|
||||
|
@ -348,7 +344,7 @@ public class BpmTaskServiceImpl implements BpmTaskService {
|
|||
List<FlowElement> elementList = new ArrayList<>();
|
||||
for (String activityId : historyTaksDefinitionKeySet) {
|
||||
FlowElement target = ModelUtils.getFlowElementById(bpmnModel, activityId);
|
||||
//不支持串行和子流程
|
||||
//非 串行和子流程则加入返回节点 elementList
|
||||
boolean isSequential = ModelUtils.isSequentialReachable(source, target, new HashSet<>());
|
||||
if (isSequential) {
|
||||
elementList.add(target);
|
||||
|
@ -378,13 +374,13 @@ public class BpmTaskServiceImpl implements BpmTaskService {
|
|||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public void taskReturn(BpmTaskRollbackReqVO reqVO) {
|
||||
public void returnTask(BpmTaskReturnReqVO reqVO) {
|
||||
// 当前任务 task
|
||||
Task task = validateRollback(reqVO.getId());
|
||||
Task task = validateReturnTask(reqVO.getId());
|
||||
// 校验源头和目标节点的关系,并返回目标元素
|
||||
FlowElement targetElement = validateRollbackProcessDefinition(task.getTaskDefinitionKey(), reqVO.getTargetDefinitionKey(), task.getProcessDefinitionId());
|
||||
FlowElement targetElement = validateReturnProcessDefinition(task.getTaskDefinitionKey(), reqVO.getTargetDefinitionKey(), task.getProcessDefinitionId());
|
||||
//调用flowable框架的回退逻辑
|
||||
this.handlerRollback(task, targetElement, reqVO);
|
||||
this.handlerReturn(task, targetElement, reqVO);
|
||||
// 更新任务扩展表
|
||||
taskExtMapper.updateByTaskId(
|
||||
new BpmTaskExtDO().setTaskId(task.getId()).setResult(BpmProcessInstanceResultEnum.BACK.getResult())
|
||||
|
@ -397,14 +393,14 @@ public class BpmTaskServiceImpl implements BpmTaskService {
|
|||
* @param taskId 当前任务ID
|
||||
* @return
|
||||
*/
|
||||
private Task validateRollback(String taskId) {
|
||||
private Task validateReturnTask(String taskId) {
|
||||
// 当前任务 task
|
||||
Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
|
||||
Task task = getTask(taskId);
|
||||
if (null == task) {
|
||||
throw exception(TASK_NOT_EXISTS);
|
||||
}
|
||||
if (task.isSuspended()) {
|
||||
throw exception(TASK_IS_NOT_ACTIVITY);
|
||||
throw exception(TASK_IS_PENDING);
|
||||
}
|
||||
return task;
|
||||
}
|
||||
|
@ -417,7 +413,7 @@ public class BpmTaskServiceImpl implements BpmTaskService {
|
|||
* @param processDefinitionId 当前流程定义ID
|
||||
* @return 目标元素
|
||||
*/
|
||||
private FlowElement validateRollbackProcessDefinition(String sourceKey, String targetKey, String processDefinitionId) {
|
||||
private FlowElement validateReturnProcessDefinition(String sourceKey, String targetKey, String processDefinitionId) {
|
||||
// 获取流程模型信息
|
||||
BpmnModel bpmnModel = bpmModelService.getBpmnModelByDefinitionId(processDefinitionId);
|
||||
// 获取当前任务节点元素
|
||||
|
@ -442,24 +438,24 @@ public class BpmTaskServiceImpl implements BpmTaskService {
|
|||
* @param targetElement 需要回退到的目标任务
|
||||
* @param reqVO 前端参数封装
|
||||
*/
|
||||
public void handlerRollback(Task task, FlowElement targetElement, BpmTaskRollbackReqVO reqVO) {
|
||||
public void handlerReturn(Task task, FlowElement targetElement, BpmTaskReturnReqVO reqVO) {
|
||||
// 获取所有正常进行的任务节点 Key,这些任务不能直接使用,需要找出其中需要撤回的任务
|
||||
List<Task> runTaskList = taskService.createTaskQuery().processInstanceId(task.getProcessInstanceId()).list();
|
||||
List<String> runTaskKeyList = convertList(runTaskList, Task::getTaskDefinitionKey);
|
||||
// 通过 targetElement 的出口连线,结合 runTaskList 比对,获取需要撤回的任务 key
|
||||
List<UserTask> rollbackUserTaskList = ModelUtils.iteratorFindChildUserTasks(targetElement, runTaskKeyList, null, null);
|
||||
List<UserTask> returnUserTaskList = ModelUtils.iteratorFindChildUserTasks(targetElement, runTaskKeyList, null, null);
|
||||
// 需退回任务 key
|
||||
List<String> rollbackTaskDefinitionKeyList = convertList(rollbackUserTaskList, UserTask::getId);
|
||||
List<String> returnTaskDefinitionKeyList = convertList(returnUserTaskList, UserTask::getId);
|
||||
|
||||
// 通过 key 和 runTaskList 中的key对比,拿到任务ID,设置设置回退意见
|
||||
List<String> currentTaskIds = new ArrayList<>();
|
||||
rollbackTaskDefinitionKeyList.forEach(currentId -> runTaskList.forEach(runTask -> {
|
||||
returnTaskDefinitionKeyList.forEach(currentId -> runTaskList.forEach(runTask -> {
|
||||
if (currentId.equals(runTask.getTaskDefinitionKey())) {
|
||||
currentTaskIds.add(runTask.getId());
|
||||
}
|
||||
}));
|
||||
if (CollUtil.isEmpty(currentTaskIds)) {
|
||||
throw exception(TASK_ROLLBACK_FAIL);
|
||||
throw exception(TASK_RETURN_FAIL);
|
||||
}
|
||||
// 设置回退意见
|
||||
for (String currentTaskId : currentTaskIds) {
|
||||
|
@ -468,7 +464,7 @@ public class BpmTaskServiceImpl implements BpmTaskService {
|
|||
// 1 对 1 或 多 对 1 情况,currentIds 当前要跳转的节点列表(1或多),targetKey 跳转到的节点(1)
|
||||
runtimeService.createChangeActivityStateBuilder()
|
||||
.processInstanceId(task.getProcessInstanceId())
|
||||
.moveActivityIdsToSingleActivityId(rollbackTaskDefinitionKeyList, reqVO.getTargetDefinitionKey())
|
||||
.moveActivityIdsToSingleActivityId(returnTaskDefinitionKeyList, reqVO.getTargetDefinitionKey())
|
||||
.changeState();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue