mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2025-01-19 03:30:06 +08:00
BPM:完善 task 转派的实现
This commit is contained in:
parent
b2b2b497b1
commit
bc4427aca5
@ -53,7 +53,9 @@ public interface ErrorCodeConstants {
|
||||
ErrorCode TASK_ADD_SIGN_USER_NOT_EXIST = new ErrorCode(1_009_005_009, "任务加签:选择的用户不存在");
|
||||
ErrorCode TASK_ADD_SIGN_TYPE_ERROR = new ErrorCode(1_009_005_010, "任务加签:当前任务已经{},不能{}");
|
||||
ErrorCode TASK_ADD_SIGN_USER_REPEAT = new ErrorCode(1_009_005_011, "任务加签失败,加签人与现有审批人[{}]重复");
|
||||
ErrorCode TASK_SUB_SIGN_NO_PARENT = new ErrorCode(1_009_005_011, "任务减签失败,被减签的任务必须是通过加签生成的任务");
|
||||
ErrorCode TASK_SUB_SIGN_NO_PARENT = new ErrorCode(1_009_005_012, "任务减签失败,被减签的任务必须是通过加签生成的任务");
|
||||
ErrorCode TASK_TRANSFER_FAIL_USER_REPEAT = new ErrorCode(1_009_005_013, "任务转办失败,转办人和当前审批人为同一人");
|
||||
ErrorCode TASK_TRANSFER_FAIL_USER_NOT_EXISTS = new ErrorCode(1_009_005_014, "任务转办失败,转办人不存在");
|
||||
|
||||
// ========== 流程任务分配规则 1-009-006-000 TODO 芋艿:这里要改下 ==========
|
||||
ErrorCode TASK_CREATE_FAIL_NO_CANDIDATE_USER = new ErrorCode(1_009_006_003, "操作失败,原因:找不到任务的审批人!");
|
||||
|
@ -18,9 +18,10 @@ public enum BpmCommentTypeEnum {
|
||||
CANCEL("3", "已取消", ""),
|
||||
BACK("4", "退回", "{}"), // 直接使用用户填写的原因
|
||||
DELEGATE_START("5", "委派发起", "[{}]将任务委派给[{}],委派理由为:{}"),
|
||||
DELEGATE_END("6", "委派完成", "[{}]将任务委派给[{}],委派理由为:{}"),
|
||||
ADD_SIGN("7", "加签", "[{}]{}给了[{}],理由为:{}"),
|
||||
SUB_SIGN("8", "减签", "[{}]操作了【减签】,审批人[{}]的任务被取消"),
|
||||
DELEGATE_END("6", "委派完成", "[{}]完成委派任务,任务重新回到[{}]手中,审批建议为:{}"),
|
||||
TRANSFER("7", "转派", "[{}]将任务转派给[{}],转派理由为:{}"),
|
||||
ADD_SIGN("8", "加签", "[{}]{}给了[{}],理由为:{}"),
|
||||
SUB_SIGN("9", "减签", "[{}]操作了【减签】,审批人[{}]的任务被取消"),
|
||||
;
|
||||
|
||||
/**
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user