Commit b2b2b497b1ab7a87163e851b33df8384dc1a7259
1 parent
c4688d88
BPM:完善 task 委托的实现
Showing
4 changed files
with
29 additions
and
36 deletions
yudao-module-bpm/yudao-module-bpm-api/src/main/java/cn/iocoder/yudao/module/bpm/enums/task/BpmCommentTypeEnum.java
| 1 | package cn.iocoder.yudao.module.bpm.enums.task; | 1 | package cn.iocoder.yudao.module.bpm.enums.task; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.util.StrUtil; | ||
| 3 | import lombok.AllArgsConstructor; | 4 | import lombok.AllArgsConstructor; |
| 4 | import lombok.Getter; | 5 | import lombok.Getter; |
| 5 | 6 | ||
| @@ -15,10 +16,11 @@ public enum BpmCommentTypeEnum { | @@ -15,10 +16,11 @@ public enum BpmCommentTypeEnum { | ||
| 15 | APPROVE("1", "审批通过", ""), // 理由:直接使用用户的评论 | 16 | APPROVE("1", "审批通过", ""), // 理由:直接使用用户的评论 |
| 16 | REJECT("2", "不通过", ""), | 17 | REJECT("2", "不通过", ""), |
| 17 | CANCEL("3", "已取消", ""), | 18 | CANCEL("3", "已取消", ""), |
| 18 | - BACK("4", "退回", ""), // 理由:直接使用用户的评论 | ||
| 19 | - DELEGATE("5", "委派", ""), | ||
| 20 | - ADD_SIGN("6", "加签", "[{}]{}给了[{}],理由为:{}"), | ||
| 21 | - SUB_SIGN("7", "减签", "[{}]操作了【减签】,审批人[{}]的任务被取消"), | 19 | + BACK("4", "退回", "{}"), // 直接使用用户填写的原因 |
| 20 | + DELEGATE_START("5", "委派发起", "[{}]将任务委派给[{}],委派理由为:{}"), | ||
| 21 | + DELEGATE_END("6", "委派完成", "[{}]将任务委派给[{}],委派理由为:{}"), | ||
| 22 | + ADD_SIGN("7", "加签", "[{}]{}给了[{}],理由为:{}"), | ||
| 23 | + SUB_SIGN("8", "减签", "[{}]操作了【减签】,审批人[{}]的任务被取消"), | ||
| 22 | ; | 24 | ; |
| 23 | 25 | ||
| 24 | /** | 26 | /** |
| @@ -36,4 +38,8 @@ public enum BpmCommentTypeEnum { | @@ -36,4 +38,8 @@ public enum BpmCommentTypeEnum { | ||
| 36 | */ | 38 | */ |
| 37 | private final String comment; | 39 | private final String comment; |
| 38 | 40 | ||
| 41 | + public String formatComment(Object... params) { | ||
| 42 | + return StrUtil.format(comment, params); | ||
| 43 | + } | ||
| 44 | + | ||
| 39 | } | 45 | } |
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 { | @@ -18,9 +18,7 @@ public enum BpmTaskStatustEnum { | ||
| 18 | REJECT(3, "审批不通过"), | 18 | REJECT(3, "审批不通过"), |
| 19 | CANCEL(4, "已取消"), | 19 | CANCEL(4, "已取消"), |
| 20 | 20 | ||
| 21 | - // ========== 流程任务独有的状态 ========== | ||
| 22 | - | ||
| 23 | - BACK(5, "已驳回"), // 退回 | 21 | + RETURN(5, "已退回"), |
| 24 | DELEGATE(6, "委派中"), | 22 | DELEGATE(6, "委派中"), |
| 25 | 23 | ||
| 26 | /** | 24 | /** |
| @@ -64,7 +62,7 @@ public enum BpmTaskStatustEnum { | @@ -64,7 +62,7 @@ public enum BpmTaskStatustEnum { | ||
| 64 | public static boolean isEndStatus(Integer status) { | 62 | public static boolean isEndStatus(Integer status) { |
| 65 | return ObjectUtils.equalsAny(status, | 63 | return ObjectUtils.equalsAny(status, |
| 66 | APPROVE.getStatus(), REJECT.getStatus(), CANCEL.getStatus(), | 64 | APPROVE.getStatus(), REJECT.getStatus(), CANCEL.getStatus(), |
| 67 | - BACK.getStatus(), APPROVING.getStatus()); | 65 | + RETURN.getStatus(), APPROVING.getStatus()); |
| 68 | } | 66 | } |
| 69 | 67 | ||
| 70 | } | 68 | } |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/vo/task/BpmTaskDelegateReqVO.java
| 1 | package cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task; | 1 | package cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task; |
| 2 | 2 | ||
| 3 | import io.swagger.v3.oas.annotations.media.Schema; | 3 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | -import lombok.Data; | ||
| 5 | - | ||
| 6 | import jakarta.validation.constraints.NotEmpty; | 4 | import jakarta.validation.constraints.NotEmpty; |
| 7 | import jakarta.validation.constraints.NotNull; | 5 | import jakarta.validation.constraints.NotNull; |
| 6 | +import lombok.Data; | ||
| 8 | 7 | ||
| 9 | @Schema(description = "管理后台 - 委派流程任务的 Request VO") | 8 | @Schema(description = "管理后台 - 委派流程任务的 Request VO") |
| 10 | @Data | 9 | @Data |
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 { | @@ -285,21 +285,16 @@ public class BpmTaskServiceImpl implements BpmTaskService { | ||
| 285 | private void approveDelegateTask(BpmTaskApproveReqVO reqVO, Task task) { | 285 | private void approveDelegateTask(BpmTaskApproveReqVO reqVO, Task task) { |
| 286 | // 1. 添加审批意见 | 286 | // 1. 添加审批意见 |
| 287 | AdminUserRespDTO currentUser = adminUserApi.getUser(WebFrameworkUtils.getLoginUserId()); | 287 | AdminUserRespDTO currentUser = adminUserApi.getUser(WebFrameworkUtils.getLoginUserId()); |
| 288 | - AdminUserRespDTO sourceApproveUser = adminUserApi.getUser(NumberUtils.parseLong(task.getOwner())); | ||
| 289 | - Assert.notNull(sourceApproveUser, "委派任务找不到原审批人,需要检查数据"); | ||
| 290 | - String comment = StrUtil.format("[{}]完成委派任务,任务重新回到[{}]手中,审批意见为:{}", currentUser.getNickname(), | ||
| 291 | - sourceApproveUser.getNickname(), reqVO.getReason()); | ||
| 292 | - taskService.addComment(reqVO.getId(), task.getProcessInstanceId(), | ||
| 293 | - BpmCommentTypeEnum.DELEGATE.getType().toString(), comment); | 288 | + AdminUserRespDTO ownerUser = adminUserApi.getUser(NumberUtils.parseLong(task.getOwner())); // 发起委托的用户 |
| 289 | + Assert.notNull(ownerUser, "委派任务找不到原审批人,需要检查数据"); | ||
| 290 | + taskService.addComment(reqVO.getId(), task.getProcessInstanceId(), BpmCommentTypeEnum.DELEGATE_END.getType(), | ||
| 291 | + BpmCommentTypeEnum.DELEGATE_END.formatComment(currentUser.getNickname(), ownerUser.getNickname(), reqVO.getReason())); | ||
| 294 | 292 | ||
| 295 | // 2.1 调用 resolveTask 完成任务。 | 293 | // 2.1 调用 resolveTask 完成任务。 |
| 296 | // 底层调用 TaskHelper.changeTaskAssignee(task, task.getOwner()):将 owner 设置为 assignee | 294 | // 底层调用 TaskHelper.changeTaskAssignee(task, task.getOwner()):将 owner 设置为 assignee |
| 297 | taskService.resolveTask(task.getId()); | 295 | taskService.resolveTask(task.getId()); |
| 298 | - // 2.2 更新任务拓展表为【处理中】 | ||
| 299 | -// taskExtMapper.updateByTaskId( | ||
| 300 | -// new BpmTaskExtDO().setTaskId(task.getId()).setResult(BpmProcessInstanceResultEnum.RUNNING.getResult()) | ||
| 301 | -// .setReason(reqVO.getReason())); | ||
| 302 | - updateTaskStatus(task.getId(), BpmTaskStatustEnum.RUNNING.getStatus()); | 296 | + // 2.2 更新 task 状态 + 原因 |
| 297 | + updateTaskStatusAndReason(task.getId(), BpmTaskStatustEnum.RUNNING.getStatus(), reqVO.getReason()); | ||
| 303 | } | 298 | } |
| 304 | 299 | ||
| 305 | @Override | 300 | @Override |
| @@ -352,8 +347,8 @@ public class BpmTaskServiceImpl implements BpmTaskService { | @@ -352,8 +347,8 @@ public class BpmTaskServiceImpl implements BpmTaskService { | ||
| 352 | * @param status 状态 | 347 | * @param status 状态 |
| 353 | * @param reason 理由(审批通过、审批不通过的理由) | 348 | * @param reason 理由(审批通过、审批不通过的理由) |
| 354 | */ | 349 | */ |
| 355 | - private void updateTaskStatus(String id, Integer status, String reason) { | ||
| 356 | - taskService.setVariableLocal(id, BpmConstants.TASK_VARIABLE_STATUS, status); | 350 | + private void updateTaskStatusAndReason(String id, Integer status, String reason) { |
| 351 | + updateTaskStatus(id, status); | ||
| 357 | taskService.setVariableLocal(id, BpmConstants.TASK_VARIABLE_REASON, reason); | 352 | taskService.setVariableLocal(id, BpmConstants.TASK_VARIABLE_REASON, reason); |
| 358 | } | 353 | } |
| 359 | 354 | ||
| @@ -585,10 +580,10 @@ public class BpmTaskServiceImpl implements BpmTaskService { | @@ -585,10 +580,10 @@ public class BpmTaskServiceImpl implements BpmTaskService { | ||
| 585 | return; | 580 | return; |
| 586 | } | 581 | } |
| 587 | // 2.1 添加评论 | 582 | // 2.1 添加评论 |
| 588 | - taskService.addComment(task.getId(), currentTask.getProcessInstanceId(), | ||
| 589 | - BpmCommentTypeEnum.BACK.getType(), reqVO.getReason()); | 583 | + taskService.addComment(task.getId(), currentTask.getProcessInstanceId(), BpmCommentTypeEnum.BACK.getType(), |
| 584 | + BpmCommentTypeEnum.BACK.formatComment(reqVO.getReason())); | ||
| 590 | // 2.2 更新 task 状态 + 原因 | 585 | // 2.2 更新 task 状态 + 原因 |
| 591 | - updateTaskStatus(task.getId(), BpmTaskStatustEnum.BACK.getStatus(), reqVO.getReason()); | 586 | + updateTaskStatusAndReason(task.getId(), BpmTaskStatustEnum.RETURN.getStatus(), reqVO.getReason()); |
| 592 | }); | 587 | }); |
| 593 | 588 | ||
| 594 | // 3. 执行驳回 | 589 | // 3. 执行驳回 |
| @@ -602,6 +597,7 @@ public class BpmTaskServiceImpl implements BpmTaskService { | @@ -602,6 +597,7 @@ public class BpmTaskServiceImpl implements BpmTaskService { | ||
| 602 | @Override | 597 | @Override |
| 603 | @Transactional(rollbackFor = Exception.class) | 598 | @Transactional(rollbackFor = Exception.class) |
| 604 | public void delegateTask(Long userId, BpmTaskDelegateReqVO reqVO) { | 599 | public void delegateTask(Long userId, BpmTaskDelegateReqVO reqVO) { |
| 600 | + String taskId = reqVO.getId(); | ||
| 605 | // 1.1 校验任务 | 601 | // 1.1 校验任务 |
| 606 | Task task = validateTaskCanDelegate(userId, reqVO); | 602 | Task task = validateTaskCanDelegate(userId, reqVO); |
| 607 | // 1.2 校验目标用户存在 | 603 | // 1.2 校验目标用户存在 |
| @@ -612,21 +608,15 @@ public class BpmTaskServiceImpl implements BpmTaskService { | @@ -612,21 +608,15 @@ public class BpmTaskServiceImpl implements BpmTaskService { | ||
| 612 | 608 | ||
| 613 | // 2. 添加审批意见 | 609 | // 2. 添加审批意见 |
| 614 | AdminUserRespDTO currentUser = adminUserApi.getUser(userId); | 610 | AdminUserRespDTO currentUser = adminUserApi.getUser(userId); |
| 615 | - String comment = StrUtil.format("[{}]将任务委派给[{}],委派理由为:{}", currentUser.getNickname(), | ||
| 616 | - delegateUser.getNickname(), reqVO.getReason()); | ||
| 617 | - String taskId = reqVO.getId(); | ||
| 618 | - taskService.addComment(taskId, task.getProcessInstanceId(), | ||
| 619 | - BpmCommentTypeEnum.DELEGATE.getType().toString(), comment); | 611 | + taskService.addComment(taskId, task.getProcessInstanceId(), BpmCommentTypeEnum.DELEGATE_START.getType(), |
| 612 | + BpmCommentTypeEnum.DELEGATE_START.formatComment(currentUser.getNickname(), delegateUser.getNickname(), reqVO.getReason())); | ||
| 620 | 613 | ||
| 621 | // 3.1 设置任务所有人 (owner) 为原任务的处理人 (assignee) | 614 | // 3.1 设置任务所有人 (owner) 为原任务的处理人 (assignee) |
| 622 | taskService.setOwner(taskId, task.getAssignee()); | 615 | taskService.setOwner(taskId, task.getAssignee()); |
| 623 | // 3.2 执行委派,将任务委派给 receiveId | 616 | // 3.2 执行委派,将任务委派给 receiveId |
| 624 | taskService.delegateTask(taskId, reqVO.getDelegateUserId().toString()); | 617 | taskService.delegateTask(taskId, reqVO.getDelegateUserId().toString()); |
| 625 | - // 3.3 更新任务拓展表为【委派】 | ||
| 626 | -// taskExtMapper.updateByTaskId( | ||
| 627 | -// new BpmTaskExtDO().setTaskId(task.getId()).setResult(BpmProcessInstanceResultEnum.DELEGATE.getResult()) | ||
| 628 | -// .setReason(reqVO.getReason())); | ||
| 629 | - updateTaskStatus(taskId, BpmTaskStatustEnum.DELEGATE.getStatus()); | 618 | + // 3.3 更新 task 状态 + 原因 |
| 619 | + updateTaskStatusAndReason(taskId, BpmTaskStatustEnum.DELEGATE.getStatus(), reqVO.getReason()); | ||
| 630 | } | 620 | } |
| 631 | 621 | ||
| 632 | /** | 622 | /** |