Commit 3972fbd1d9bc03b3562fb94a98e28e52a7e22193

Authored by youkehai
1 parent 15539001

fix: 根据review结果修改

yudao-module-bpm/yudao-module-bpm-api/src/main/java/cn/iocoder/yudao/module/bpm/enums/ErrorCodeConstants.java
... ... @@ -50,9 +50,8 @@ public interface ErrorCodeConstants {
50 50 ErrorCode TASK_TARGET_NODE_NOT_EXISTS = new ErrorCode(1_009_005_004, " 目标节点不存在");
51 51 ErrorCode TASK_RETURN_FAIL_NO_RETURN_TASK = new ErrorCode(1_009_005_005, "回退任务失败,选择回退的节点没有需要回滚的任务!请重新选择其他任务节点");
52 52 ErrorCode TASK_RETURN_FAIL_SOURCE_TARGET_ERROR = new ErrorCode(1_009_005_006, "回退任务失败,目标节点是在并行网关上或非同一路线上,不可跳转");
53   - ErrorCode TASK_DELEGATE_APPROVE_FAIL = new ErrorCode(1_009_005_007, "任务审批失败:委派任务找不到原审批人");
54   - ErrorCode TASK_DELEGATE_USER_REPEAT = new ErrorCode(1_009_005_008, "任务委派失败,委派人和当前审批人为同一人");
55   - ErrorCode TASK_DELEGATE_RECEIVE_USER_NULL = new ErrorCode(1_009_005_009, "任务委派失败,接收人不存在");
  53 + ErrorCode TASK_DELEGATE_USER_REPEAT = new ErrorCode(1_009_005_007, "任务委派失败,委派人和当前审批人为同一人");
  54 + ErrorCode TASK_DELEGATE_USER_NULL = new ErrorCode(1_009_005_008, "任务委派失败,被委派人不存在");
56 55  
57 56 // ========== 流程任务分配规则 1-009-006-000 ==========
58 57 ErrorCode TASK_ASSIGN_RULE_EXISTS = new ErrorCode(1_009_006_000, "流程({}) 的任务({}) 已经存在分配规则");
... ...
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/BpmTaskController.java
... ... @@ -95,7 +95,7 @@ public class BpmTaskController {
95 95 @Operation(summary = "委派任务", description = "用于【流程详情】的【委派】按钮,和向前加签有点像,和向前加签的唯一的区别是没有单独创立任务")
96 96 @PreAuthorize("@ss.hasPermission('bpm:task:delegate')")
97 97 public CommonResult<Boolean> delegateTask(@Valid @RequestBody BpmTaskDelegateReqVO reqVO) {
98   - taskService.delegateTask(reqVO);
  98 + taskService.delegateTask(reqVO,getLoginUserId());
99 99 return success(true);
100 100 }
101 101  
... ...
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/vo/task/BpmTaskDelegateReqVO.java
... ... @@ -14,9 +14,9 @@ public class BpmTaskDelegateReqVO {
14 14 @NotEmpty(message = "任务编号不能为空")
15 15 private String id;
16 16  
17   - @Schema(description = "接收人ID", requiredMode = Schema.RequiredMode.REQUIRED,example = "1")
18   - @NotNull(message = "接收人ID不能为空")
19   - private Long receiveId;
  17 + @Schema(description = "被委派人ID", requiredMode = Schema.RequiredMode.REQUIRED,example = "1")
  18 + @NotNull(message = "被委派人ID不能为空")
  19 + private Long delegateUserId;
20 20  
21 21 @Schema(description = "委派原因", requiredMode = Schema.RequiredMode.REQUIRED,example = "做不了决定,需要你先帮忙瞅瞅")
22 22 @NotEmpty(message = "委派原因不能为空")
... ...
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskService.java
... ... @@ -140,7 +140,8 @@ public interface BpmTaskService {
140 140 /**
141 141 * 将指定任务委派给其他人处理,等接收人处理后再回到原审批人手中审批
142 142 *
143   - * @param reqVO 接收人和被委派的任务编号理由参数
  143 + * @param reqVO 被委派人和被委派的任务编号理由参数
  144 + * @param userId 委派人ID
144 145 */
145   - void delegateTask(BpmTaskDelegateReqVO reqVO);
  146 + void delegateTask(BpmTaskDelegateReqVO reqVO, Long userId);
146 147 }
... ...
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java
... ... @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.bpm.service.task;
2 2  
3 3 import cn.hutool.core.collection.CollUtil;
4 4 import cn.hutool.core.util.ArrayUtil;
5   -import cn.hutool.core.util.ObjectUtil;
6 5 import cn.hutool.core.util.StrUtil;
7 6 import cn.iocoder.yudao.framework.common.pojo.PageResult;
8 7 import cn.iocoder.yudao.framework.common.util.date.DateUtils;
... ... @@ -14,7 +13,6 @@ import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task.*;
14 13 import cn.iocoder.yudao.module.bpm.convert.task.BpmTaskConvert;
15 14 import cn.iocoder.yudao.module.bpm.dal.dataobject.task.BpmTaskExtDO;
16 15 import cn.iocoder.yudao.module.bpm.dal.mysql.task.BpmTaskExtMapper;
17   -import cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants;
18 16 import cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceDeleteReasonEnum;
19 17 import cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceResultEnum;
20 18 import cn.iocoder.yudao.module.bpm.service.definition.BpmModelService;
... ... @@ -41,6 +39,7 @@ import org.springframework.stereotype.Service;
41 39 import org.springframework.transaction.annotation.Transactional;
42 40 import org.springframework.transaction.support.TransactionSynchronization;
43 41 import org.springframework.transaction.support.TransactionSynchronizationManager;
  42 +import org.springframework.util.Assert;
44 43  
45 44 import javax.annotation.Resource;
46 45 import javax.validation.Valid;
... ... @@ -222,10 +221,9 @@ public class BpmTaskServiceImpl implements BpmTaskService {
222 221 AdminUserRespDTO currentUser = adminUserApi.getUser(WebFrameworkUtils.getLoginUserId());
223 222 //原审批人
224 223 AdminUserRespDTO sourceApproveUser = adminUserApi.getUser(NumberUtils.parseLong(task.getOwner()));
225   - if (sourceApproveUser == null) {
226   - throw exception(TASK_DELEGATE_APPROVE_FAIL);
227   - }
228   - String comment = String.format("[%s]完成委派任务,任务重新回到[%s]手中,审批意见为:%s", currentUser.getNickname(),
  224 + Assert.notNull(sourceApproveUser, "委派任务找不到原审批人,需要检查数据");
  225 + //添加审批意见
  226 + String comment = StrUtil.format("[{}]完成委派任务,任务重新回到[{}]手中,审批意见为:{}", currentUser.getNickname(),
229 227 sourceApproveUser.getNickname(), reqVO.getReason());
230 228 taskService.addComment(reqVO.getId(), task.getProcessInstanceId(), BpmProcessInstanceResultEnum.DELEGATE.getResult().toString(), comment);
231 229 //调用 resolveTask 完成任务,底层调用 TaskHelper.changeTaskAssignee(task, task.getOwner());
... ... @@ -486,23 +484,23 @@ public class BpmTaskServiceImpl implements BpmTaskService {
486 484  
487 485 @Override
488 486 @Transactional(rollbackFor = Exception.class)
489   - public void delegateTask(BpmTaskDelegateReqVO reqVO) {
  487 + public void delegateTask(BpmTaskDelegateReqVO reqVO,Long userId) {
490 488 // 校验任务
491 489 Task task = this.validateTaskDelegate(reqVO);
492 490 // 添加审批意见
493   - AdminUserRespDTO currentUser = adminUserApi.getUser(WebFrameworkUtils.getLoginUserId());
494   - AdminUserRespDTO receiveUser = adminUserApi.getUser(reqVO.getReceiveId());
495   - if (receiveUser == null) {
496   - throw exception(TASK_DELEGATE_RECEIVE_USER_NULL);
  491 + AdminUserRespDTO currentUser = adminUserApi.getUser(userId);
  492 + AdminUserRespDTO delegateUser = adminUserApi.getUser(reqVO.getDelegateUserId());
  493 + if (delegateUser == null) {
  494 + throw exception(TASK_DELEGATE_USER_NULL);
497 495 }
498   - String comment = String.format("[%s]将任务委派给[%s],委派理由为:%s", currentUser.getNickname(),
499   - receiveUser.getNickname(), reqVO.getReason());
  496 + String comment = StrUtil.format("[{}]将任务委派给[{}],委派理由为:{}", currentUser.getNickname(),
  497 + delegateUser.getNickname(), reqVO.getReason());
500 498 String taskId = reqVO.getId();
501 499 taskService.addComment(taskId, task.getProcessInstanceId(), BpmProcessInstanceResultEnum.DELEGATE.getResult().toString(), comment);
502 500 // 设置任务所有人 (owner) 为原任务的处理人 (assignee)
503 501 taskService.setOwner(taskId, task.getAssignee());
504 502 // 执行委派,将任务委派给 receiveId
505   - taskService.delegateTask(taskId, reqVO.getReceiveId().toString());
  503 + taskService.delegateTask(taskId, reqVO.getDelegateUserId().toString());
506 504 // 更新任务拓展表为【委派】
507 505 taskExtMapper.updateByTaskId(
508 506 new BpmTaskExtDO().setTaskId(task.getId()).setResult(BpmProcessInstanceResultEnum.DELEGATE.getResult())
... ... @@ -519,7 +517,7 @@ public class BpmTaskServiceImpl implements BpmTaskService {
519 517 // 校验任务
520 518 Task task = checkTask(WebFrameworkUtils.getLoginUserId(), reqVO.getId());
521 519 //校验当前审批人和被委派人不是同一人
522   - if (task.getAssignee().equals(reqVO.getReceiveId().toString())) {
  520 + if (task.getAssignee().equals(reqVO.getDelegateUserId().toString())) {
523 521 throw exception(TASK_DELEGATE_USER_REPEAT);
524 522 }
525 523 return task;
... ...