From b2b2b497b1ab7a87163e851b33df8384dc1a7259 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Mon, 18 Mar 2024 19:24:07 +0800 Subject: [PATCH] =?UTF-8?q?BPM=EF=BC=9A=E5=AE=8C=E5=96=84=20task=20?= =?UTF-8?q?=E5=A7=94=E6=89=98=E7=9A=84=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bpm/enums/task/BpmCommentTypeEnum.java | 14 +++++-- .../bpm/enums/task/BpmTaskStatustEnum.java | 6 +-- .../task/vo/task/BpmTaskDelegateReqVO.java | 3 +- .../bpm/service/task/BpmTaskServiceImpl.java | 42 +++++++------------ 4 files changed, 29 insertions(+), 36 deletions(-) diff --git a/yudao-module-bpm/yudao-module-bpm-api/src/main/java/cn/iocoder/yudao/module/bpm/enums/task/BpmCommentTypeEnum.java b/yudao-module-bpm/yudao-module-bpm-api/src/main/java/cn/iocoder/yudao/module/bpm/enums/task/BpmCommentTypeEnum.java index f2c2ded53..c48b4f439 100644 --- a/yudao-module-bpm/yudao-module-bpm-api/src/main/java/cn/iocoder/yudao/module/bpm/enums/task/BpmCommentTypeEnum.java +++ b/yudao-module-bpm/yudao-module-bpm-api/src/main/java/cn/iocoder/yudao/module/bpm/enums/task/BpmCommentTypeEnum.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.bpm.enums.task; +import cn.hutool.core.util.StrUtil; import lombok.AllArgsConstructor; import lombok.Getter; @@ -15,10 +16,11 @@ public enum BpmCommentTypeEnum { APPROVE("1", "审批通过", ""), // 理由:直接使用用户的评论 REJECT("2", "不通过", ""), CANCEL("3", "已取消", ""), - BACK("4", "退回", ""), // 理由:直接使用用户的评论 - DELEGATE("5", "委派", ""), - ADD_SIGN("6", "加签", "[{}]{}给了[{}],理由为:{}"), - SUB_SIGN("7", "减签", "[{}]操作了【减签】,审批人[{}]的任务被取消"), + BACK("4", "退回", "{}"), // 直接使用用户填写的原因 + DELEGATE_START("5", "委派发起", "[{}]将任务委派给[{}],委派理由为:{}"), + DELEGATE_END("6", "委派完成", "[{}]将任务委派给[{}],委派理由为:{}"), + ADD_SIGN("7", "加签", "[{}]{}给了[{}],理由为:{}"), + SUB_SIGN("8", "减签", "[{}]操作了【减签】,审批人[{}]的任务被取消"), ; /** @@ -36,4 +38,8 @@ public enum BpmCommentTypeEnum { */ private final String comment; + public String formatComment(Object... params) { + return StrUtil.format(comment, params); + } + } diff --git a/yudao-module-bpm/yudao-module-bpm-api/src/main/java/cn/iocoder/yudao/module/bpm/enums/task/BpmTaskStatustEnum.java b/yudao-module-bpm/yudao-module-bpm-api/src/main/java/cn/iocoder/yudao/module/bpm/enums/task/BpmTaskStatustEnum.java index ee06b0847..020ed3daf 100644 --- a/yudao-module-bpm/yudao-module-bpm-api/src/main/java/cn/iocoder/yudao/module/bpm/enums/task/BpmTaskStatustEnum.java +++ b/yudao-module-bpm/yudao-module-bpm-api/src/main/java/cn/iocoder/yudao/module/bpm/enums/task/BpmTaskStatustEnum.java @@ -18,9 +18,7 @@ public enum BpmTaskStatustEnum { REJECT(3, "审批不通过"), CANCEL(4, "已取消"), - // ========== 流程任务独有的状态 ========== - - BACK(5, "已驳回"), // 退回 + RETURN(5, "已退回"), DELEGATE(6, "委派中"), /** @@ -64,7 +62,7 @@ public enum BpmTaskStatustEnum { public static boolean isEndStatus(Integer status) { return ObjectUtils.equalsAny(status, APPROVE.getStatus(), REJECT.getStatus(), CANCEL.getStatus(), - BACK.getStatus(), APPROVING.getStatus()); + RETURN.getStatus(), APPROVING.getStatus()); } } diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/vo/task/BpmTaskDelegateReqVO.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/vo/task/BpmTaskDelegateReqVO.java index 2d1620661..cd1fce441 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/vo/task/BpmTaskDelegateReqVO.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/vo/task/BpmTaskDelegateReqVO.java @@ -1,10 +1,9 @@ package cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task; import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotNull; +import lombok.Data; @Schema(description = "管理后台 - 委派流程任务的 Request VO") @Data diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java index b0bc45e3f..915bc6162 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java @@ -285,21 +285,16 @@ public class BpmTaskServiceImpl implements BpmTaskService { private void approveDelegateTask(BpmTaskApproveReqVO reqVO, Task task) { // 1. 添加审批意见 AdminUserRespDTO currentUser = adminUserApi.getUser(WebFrameworkUtils.getLoginUserId()); - AdminUserRespDTO sourceApproveUser = adminUserApi.getUser(NumberUtils.parseLong(task.getOwner())); - Assert.notNull(sourceApproveUser, "委派任务找不到原审批人,需要检查数据"); - String comment = StrUtil.format("[{}]完成委派任务,任务重新回到[{}]手中,审批意见为:{}", currentUser.getNickname(), - sourceApproveUser.getNickname(), reqVO.getReason()); - taskService.addComment(reqVO.getId(), task.getProcessInstanceId(), - BpmCommentTypeEnum.DELEGATE.getType().toString(), comment); + AdminUserRespDTO ownerUser = adminUserApi.getUser(NumberUtils.parseLong(task.getOwner())); // 发起委托的用户 + Assert.notNull(ownerUser, "委派任务找不到原审批人,需要检查数据"); + taskService.addComment(reqVO.getId(), task.getProcessInstanceId(), BpmCommentTypeEnum.DELEGATE_END.getType(), + BpmCommentTypeEnum.DELEGATE_END.formatComment(currentUser.getNickname(), ownerUser.getNickname(), reqVO.getReason())); // 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.RUNNING.getResult()) -// .setReason(reqVO.getReason())); - updateTaskStatus(task.getId(), BpmTaskStatustEnum.RUNNING.getStatus()); + // 2.2 更新 task 状态 + 原因 + updateTaskStatusAndReason(task.getId(), BpmTaskStatustEnum.RUNNING.getStatus(), reqVO.getReason()); } @Override @@ -352,8 +347,8 @@ public class BpmTaskServiceImpl implements BpmTaskService { * @param status 状态 * @param reason 理由(审批通过、审批不通过的理由) */ - private void updateTaskStatus(String id, Integer status, String reason) { - taskService.setVariableLocal(id, BpmConstants.TASK_VARIABLE_STATUS, status); + private void updateTaskStatusAndReason(String id, Integer status, String reason) { + updateTaskStatus(id, status); taskService.setVariableLocal(id, BpmConstants.TASK_VARIABLE_REASON, reason); } @@ -585,10 +580,10 @@ public class BpmTaskServiceImpl implements BpmTaskService { return; } // 2.1 添加评论 - taskService.addComment(task.getId(), currentTask.getProcessInstanceId(), - BpmCommentTypeEnum.BACK.getType(), reqVO.getReason()); + taskService.addComment(task.getId(), currentTask.getProcessInstanceId(), BpmCommentTypeEnum.BACK.getType(), + BpmCommentTypeEnum.BACK.formatComment(reqVO.getReason())); // 2.2 更新 task 状态 + 原因 - updateTaskStatus(task.getId(), BpmTaskStatustEnum.BACK.getStatus(), reqVO.getReason()); + updateTaskStatusAndReason(task.getId(), BpmTaskStatustEnum.RETURN.getStatus(), reqVO.getReason()); }); // 3. 执行驳回 @@ -602,6 +597,7 @@ public class BpmTaskServiceImpl implements BpmTaskService { @Override @Transactional(rollbackFor = Exception.class) public void delegateTask(Long userId, BpmTaskDelegateReqVO reqVO) { + String taskId = reqVO.getId(); // 1.1 校验任务 Task task = validateTaskCanDelegate(userId, reqVO); // 1.2 校验目标用户存在 @@ -612,21 +608,15 @@ public class BpmTaskServiceImpl implements BpmTaskService { // 2. 添加审批意见 AdminUserRespDTO currentUser = adminUserApi.getUser(userId); - String comment = StrUtil.format("[{}]将任务委派给[{}],委派理由为:{}", currentUser.getNickname(), - delegateUser.getNickname(), reqVO.getReason()); - String taskId = reqVO.getId(); - taskService.addComment(taskId, task.getProcessInstanceId(), - BpmCommentTypeEnum.DELEGATE.getType().toString(), comment); + taskService.addComment(taskId, task.getProcessInstanceId(), BpmCommentTypeEnum.DELEGATE_START.getType(), + BpmCommentTypeEnum.DELEGATE_START.formatComment(currentUser.getNickname(), delegateUser.getNickname(), reqVO.getReason())); // 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())); - updateTaskStatus(taskId, BpmTaskStatustEnum.DELEGATE.getStatus()); + // 3.3 更新 task 状态 + 原因 + updateTaskStatusAndReason(taskId, BpmTaskStatustEnum.DELEGATE.getStatus(), reqVO.getReason()); } /**