mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-07-25 00:15:06 +08:00
BPM:完善 task 转派的实现
This commit is contained in:
@ -118,14 +118,6 @@ public class BpmTaskController {
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@PutMapping("/update-assignee")
|
||||
@Operation(summary = "更新任务的负责人", description = "用于【流程详情】的【转派】按钮")
|
||||
@PreAuthorize("@ss.hasPermission('bpm:task:update')")
|
||||
public CommonResult<Boolean> updateTaskAssignee(@Valid @RequestBody BpmTaskUpdateAssigneeReqVO reqVO) {
|
||||
taskService.updateTaskAssignee(getLoginUserId(), reqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/list-by-return")
|
||||
@Operation(summary = "获取所有可回退的节点", description = "用于【流程详情】的【回退】按钮")
|
||||
@Parameter(name = "taskId", description = "当前任务ID", required = true)
|
||||
@ -145,13 +137,21 @@ public class BpmTaskController {
|
||||
}
|
||||
|
||||
@PutMapping("/delegate")
|
||||
@Operation(summary = "委派任务", description = "用于【流程详情】的【委派】按钮。和向前【加签】有点像,唯一区别是【委托】没有单独创立任务")
|
||||
@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("/transfer")
|
||||
@Operation(summary = "转派任务", description = "用于【流程详情】的【转派】按钮")
|
||||
@PreAuthorize("@ss.hasPermission('bpm:task:update')")
|
||||
public CommonResult<Boolean> transferTask(@Valid @RequestBody BpmTaskTransferReqVO reqVO) {
|
||||
taskService.transferTask(getLoginUserId(), reqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@PutMapping("/create-sign")
|
||||
@Operation(summary = "加签", description = "before 前加签,after 后加签")
|
||||
@PreAuthorize("@ss.hasPermission('bpm:task:update')")
|
||||
|
@ -6,9 +6,9 @@ import lombok.Data;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
@Schema(description = "管理后台 - 流程任务的更新负责人的 Request VO")
|
||||
@Schema(description = "管理后台 - 流程任务的转办 Request VO")
|
||||
@Data
|
||||
public class BpmTaskUpdateAssigneeReqVO {
|
||||
public class BpmTaskTransferReqVO {
|
||||
|
||||
@Schema(description = "任务编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
||||
@NotEmpty(message = "任务编号不能为空")
|
||||
@ -18,4 +18,8 @@ public class BpmTaskUpdateAssigneeReqVO {
|
||||
@NotNull(message = "新审批人的用户编号不能为空")
|
||||
private Long assigneeUserId;
|
||||
|
||||
@Schema(description = "转办原因", requiredMode = Schema.RequiredMode.REQUIRED, example = "做不了决定,需要你先帮忙瞅瞅")
|
||||
@NotEmpty(message = "转办原因不能为空")
|
||||
private String reason;
|
||||
|
||||
}
|
@ -87,15 +87,7 @@ public interface BpmTaskService {
|
||||
* @param userId 用户编号
|
||||
* @param reqVO 分配请求
|
||||
*/
|
||||
void updateTaskAssignee(Long userId, BpmTaskUpdateAssigneeReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 将流程任务分配给指定用户
|
||||
*
|
||||
* @param id 流程任务编号
|
||||
* @param userId 用户编号
|
||||
*/
|
||||
void updateTaskAssignee(String id, Long userId);
|
||||
void transferTask(Long userId, BpmTaskTransferReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 创建 Task 拓展记录
|
||||
|
@ -179,7 +179,7 @@ public class BpmTaskServiceImpl implements BpmTaskService {
|
||||
|
||||
// 情况三:审批普通的任务。大多数情况下,都是这样
|
||||
// 3.1 更新 task 状态、原因
|
||||
updateTaskStatus(task.getId(), BpmTaskStatustEnum.APPROVE.getStatus());
|
||||
updateTaskStatusAndReason(task.getId(), BpmTaskStatustEnum.APPROVE.getStatus(), reqVO.getReason());
|
||||
// 3.2 添加评论
|
||||
taskService.addComment(task.getId(), task.getProcessInstanceId(),
|
||||
BpmCommentTypeEnum.APPROVE.getType(), reqVO.getReason());
|
||||
@ -317,19 +317,6 @@ public class BpmTaskServiceImpl implements BpmTaskService {
|
||||
// .setEndTime(LocalDateTime.now()).setReason(reqVO.getReason()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTaskAssignee(Long userId, BpmTaskUpdateAssigneeReqVO reqVO) {
|
||||
// 校验任务存在
|
||||
Task task = validateTask(userId, reqVO.getId());
|
||||
// 更新负责人
|
||||
updateTaskAssignee(task.getId(), reqVO.getAssigneeUserId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTaskAssignee(String id, Long userId) {
|
||||
taskService.setAssignee(id, String.valueOf(userId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新流程任务的 status 状态
|
||||
*
|
||||
@ -599,41 +586,54 @@ public class BpmTaskServiceImpl implements BpmTaskService {
|
||||
public void delegateTask(Long userId, BpmTaskDelegateReqVO reqVO) {
|
||||
String taskId = reqVO.getId();
|
||||
// 1.1 校验任务
|
||||
Task task = validateTaskCanDelegate(userId, reqVO);
|
||||
Task task = validateTask(userId, reqVO.getId());
|
||||
if (task.getAssignee().equals(reqVO.getDelegateUserId().toString())) { // 校验当前审批人和被委派人不是同一人
|
||||
throw exception(TASK_DELEGATE_FAIL_USER_REPEAT);
|
||||
}
|
||||
// 1.2 校验目标用户存在
|
||||
AdminUserRespDTO delegateUser = adminUserApi.getUser(reqVO.getDelegateUserId());
|
||||
if (delegateUser == null) {
|
||||
throw exception(TASK_DELEGATE_FAIL_USER_NOT_EXISTS);
|
||||
}
|
||||
|
||||
// 2. 添加审批意见
|
||||
// 2. 添加委托意见
|
||||
AdminUserRespDTO currentUser = adminUserApi.getUser(userId);
|
||||
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
|
||||
// 3.2 执行委派,将任务委派给 delegateUser
|
||||
taskService.delegateTask(taskId, reqVO.getDelegateUserId().toString());
|
||||
// 3.3 更新 task 状态 + 原因
|
||||
updateTaskStatusAndReason(taskId, BpmTaskStatustEnum.DELEGATE.getStatus(), reqVO.getReason());
|
||||
// 3.3 更新 task 状态。
|
||||
// 为什么不更新原因?因为原因目前主要给审批通过、不通过时使用
|
||||
updateTaskStatus(taskId, BpmTaskStatustEnum.DELEGATE.getStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验任务委派参数
|
||||
*
|
||||
* @param userId 用户编号
|
||||
* @param reqVO 任务编号,接收人ID
|
||||
* @return 当前任务信息
|
||||
*/
|
||||
private Task validateTaskCanDelegate(Long userId, BpmTaskDelegateReqVO reqVO) {
|
||||
// 校验任务
|
||||
@Override
|
||||
public void transferTask(Long userId, BpmTaskTransferReqVO reqVO) {
|
||||
String taskId = reqVO.getId();
|
||||
// 1.1 校验任务
|
||||
Task task = validateTask(userId, reqVO.getId());
|
||||
// 校验当前审批人和被委派人不是同一人
|
||||
if (task.getAssignee().equals(reqVO.getDelegateUserId().toString())) {
|
||||
throw exception(TASK_DELEGATE_FAIL_USER_REPEAT);
|
||||
if (task.getAssignee().equals(reqVO.getAssigneeUserId().toString())) { // 校验当前审批人和被转派人不是同一人
|
||||
throw exception(TASK_TRANSFER_FAIL_USER_REPEAT);
|
||||
}
|
||||
return task;
|
||||
// 1.2 校验目标用户存在
|
||||
AdminUserRespDTO assigneeUser = adminUserApi.getUser(reqVO.getAssigneeUserId());
|
||||
if (assigneeUser == null) {
|
||||
throw exception(TASK_TRANSFER_FAIL_USER_NOT_EXISTS);
|
||||
}
|
||||
|
||||
// 2. 添加委托意见
|
||||
AdminUserRespDTO currentUser = adminUserApi.getUser(userId);
|
||||
taskService.addComment(taskId, task.getProcessInstanceId(), BpmCommentTypeEnum.TRANSFER.getType(),
|
||||
BpmCommentTypeEnum.TRANSFER.formatComment(currentUser.getNickname(), assigneeUser.getNickname(), reqVO.getReason()));
|
||||
|
||||
// 3.1 设置任务所有人 (owner) 为原任务的处理人 (assignee)
|
||||
taskService.setOwner(taskId, task.getAssignee());
|
||||
// 3.2 执行转派(审批人),将任务转派给 assigneeUser
|
||||
// 委托( delegate)和转派(transfer)的差别,就在这块的调用!!!!
|
||||
taskService.setAssignee(taskId, reqVO.getAssigneeUserId().toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user