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
c4688d887c
commit
b2b2b497b1
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user