From e931414b55817aed617a7ffca7538fd1f9315169 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sun, 9 Jan 2022 00:53:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E6=B5=81=E7=A8=8B=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E7=9A=84=E5=AE=A1=E6=89=B9=E5=8A=9F=E8=83=BD=E7=9A=84?= =?UTF-8?q?=20API=20=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/task/BpmTaskController.java | 13 +++---- .../task/vo/task/BpmTaskCompleteReqVO.java | 29 +++++++++++++++ .../controller/task/vo/task/TaskReqVO.java | 17 --------- .../bpm/enums/BpmErrorCodeConstants.java | 6 +++- .../task/BpmProcessInstanceService.java | 8 +++++ .../bpm/service/task/BpmTaskService.java | 17 ++++----- .../impl/BpmProcessInstanceServiceImpl.java | 9 ++--- .../service/task/impl/BpmTaskServiceImpl.java | 35 ++++++++++++------- 8 files changed, 80 insertions(+), 54 deletions(-) create mode 100644 yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/vo/task/BpmTaskCompleteReqVO.java delete mode 100644 yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/vo/task/TaskReqVO.java diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/BpmTaskController.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/BpmTaskController.java index c486309a3..e2245663b 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/BpmTaskController.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/BpmTaskController.java @@ -42,17 +42,18 @@ public class BpmTaskController { return success(taskService.getDoneTaskPage(getLoginUserId(), pageVO)); } + @PutMapping("/complete") + @ApiOperation(value = "完成任务", notes = "审批通过 or 不通过") + public CommonResult completeTask(@Valid @RequestBody BpmTaskCompleteReqVO reqVO) { + taskService.completeTask(reqVO); + return success(true); + } + @PostMapping("/task-steps") public CommonResult getTaskSteps(@RequestBody TaskQueryReqVO taskQuery) { return success(taskService.getTaskSteps(taskQuery)); } - @PostMapping("/complete") - public CommonResult complete(@RequestBody TaskReqVO taskReq) { - taskService.completeTask(taskReq); - return success(true); - } - @GetMapping("/process/history-steps") public CommonResult> getHistorySteps(@RequestParam("id") String processInstanceId) { return success(taskService.getHistorySteps(processInstanceId)); diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/vo/task/BpmTaskCompleteReqVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/vo/task/BpmTaskCompleteReqVO.java new file mode 100644 index 000000000..36a635834 --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/vo/task/BpmTaskCompleteReqVO.java @@ -0,0 +1,29 @@ +package cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.task; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; +import java.util.Map; + +@ApiModel("流程任务的 Done 已办的分页 Request VO") +@Data +public class BpmTaskCompleteReqVO { + + @ApiModelProperty(value = "任务编号", required = true, example = "1024") + @NotEmpty(message = "任务编号不能为空") + private String id; + + @ApiModelProperty(value = "是否通过", required = true, example = "true", notes = "true 通过;false 不通过") + @NotNull(message = "是否通过不能为空") + private Boolean pass; + + @ApiModelProperty(value = "审批意见", required = true, example = "不错不错!") + @NotEmpty(message = "审批意见不能为空") + private String comment; + +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/vo/task/TaskReqVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/vo/task/TaskReqVO.java deleted file mode 100644 index 4c038dd34..000000000 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/vo/task/TaskReqVO.java +++ /dev/null @@ -1,17 +0,0 @@ -package cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.task; - -import lombok.Data; -import lombok.ToString; - -import java.util.Map; - -@Data -@ToString -public class TaskReqVO { - - private String taskId; - - private Map variables; - - private String comment; -} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/BpmErrorCodeConstants.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/BpmErrorCodeConstants.java index f5d36c5e9..0aaf030cf 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/BpmErrorCodeConstants.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/BpmErrorCodeConstants.java @@ -33,7 +33,11 @@ public interface BpmErrorCodeConstants { ErrorCode PROCESS_DEFINITION_IS_SUSPENDED = new ErrorCode(1009003002, "流程定义处于挂起状态"); // ========== 流程实例 1-009-004-000 ========== - ErrorCode PROCESS_INSTANCE_CANCEL_FAIL_NOT_EXISTS = new ErrorCode(1009004000, "流程取消失败,流程不处于运行中"); + ErrorCode PROCESS_INSTANCE_NOT_EXISTS = new ErrorCode(1009004000, "流程实例不存在"); + ErrorCode PROCESS_INSTANCE_CANCEL_FAIL_NOT_EXISTS = new ErrorCode(1009004001, "流程取消失败,流程不处于运行中"); + + // ========== 流程实例 1-009-005-000 ========== + ErrorCode TASK_COMPLETE_FAIL_NOT_EXISTS = new ErrorCode(1009004000, "审批任务失败,原因:该任务不处于未审批"); // ========== 动态表单模块 1-009-010-000 ========== ErrorCode FORM_NOT_EXISTS = new ErrorCode(1009010000, "动态表单不存在"); diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/BpmProcessInstanceService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/BpmProcessInstanceService.java index 068ee5eb1..e598b4968 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/BpmProcessInstanceService.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/BpmProcessInstanceService.java @@ -47,6 +47,14 @@ public interface BpmProcessInstanceService { PageResult getMyProcessInstancePage(Long userId, @Valid BpmProcessInstanceMyPageReqVO pageReqVO); + /** + * 获得流程实例 + * + * @param id 流程实例的编号 + * @return 流程实例 + */ + ProcessInstance getProcessInstance(String id); + /** * 获得流程实例列表 * diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/BpmTaskService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/BpmTaskService.java index d3f7d3a4b..86063a09a 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/BpmTaskService.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/BpmTaskService.java @@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import org.activiti.engine.task.Task; +import javax.validation.Valid; import java.util.List; import java.util.Map; @@ -70,29 +71,24 @@ public interface BpmTaskService { void updateTaskAssign(String id, Long userId); /** - * 签收任务 + * 完成任务(审批通过 / 不通过) * - * @param id 任务编号 + * @param taskReq 完成请求 */ - void claimTask(String id); - - /** - * 工作流,完成 userTask, 完成用户任务 一般传入参数 1。是否同意(variables). 2. 评论(comment) - * variables 变量名 和 评论 由前台传入 - * @param taskReq 任务参数 - */ - void completeTask(TaskReqVO taskReq); + void completeTask(@Valid BpmTaskCompleteReqVO taskReq); /** * 根据任务id, 查询已经完成的用户任务,未完成的用户任务 * @param taskQuery 查询参数 一般 taskId */ + @Deprecated TaskHandleVO getTaskSteps(TaskQueryReqVO taskQuery); /** * 根据流程实例id, 查询历史用户任务,包括已完成,未完成 * @param processInstanceId 流程实例id */ + @Deprecated List getHistorySteps(String processInstanceId); /** @@ -101,4 +97,5 @@ public interface BpmTaskService { * @return {@link FileResp} 返回文件 */ FileResp getHighlightImg(String processInstanceId); + } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/impl/BpmProcessInstanceServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/impl/BpmProcessInstanceServiceImpl.java index 1552fd9cb..652b606d6 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/impl/BpmProcessInstanceServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/impl/BpmProcessInstanceServiceImpl.java @@ -166,13 +166,8 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService return runtimeService.createProcessInstanceQuery().processInstanceIds(ids).list(); } - /** - * 获得流程实例 - * - * @param id 流程实例的编号 - * @return 流程实例 - */ - private ProcessInstance getProcessInstance(String id) { + @Override + public ProcessInstance getProcessInstance(String id) { return runtimeService.createProcessInstanceQuery().processInstanceId(id).singleResult(); } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/impl/BpmTaskServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/impl/BpmTaskServiceImpl.java index dbc728072..84713a4d3 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/impl/BpmTaskServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/impl/BpmTaskServiceImpl.java @@ -41,7 +41,7 @@ import java.io.IOException; import java.io.InputStream; import java.util.*; -import static cn.iocoder.yudao.adminserver.modules.bpm.enums.BpmErrorCodeConstants.HIGHLIGHT_IMG_ERROR; +import static cn.iocoder.yudao.adminserver.modules.bpm.enums.BpmErrorCodeConstants.*; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; @@ -157,20 +157,24 @@ public class BpmTaskServiceImpl implements BpmTaskService { } @Override - public void claimTask(String id) { + @Transactional(rollbackFor = Exception.class) + public void completeTask(BpmTaskCompleteReqVO reqVO) { + // 校验任务存在 + Task task = getTask(reqVO.getId()); + if (task == null) { + throw exception(TASK_COMPLETE_FAIL_NOT_EXISTS); + } + // 校验流程实例存在 + ProcessInstance instance = processInstanceService.getProcessInstance(task.getProcessInstanceId()); + if (instance == null) { + throw exception(PROCESS_INSTANCE_NOT_EXISTS); + } - } + // 完成(审批)任务 + taskService.complete(task.getId(), instance.getProcessVariables()); - @Override - @Transactional - public void completeTask(TaskReqVO taskReq) { -// final Task task = taskRuntime.task(taskReq.getTaskId()); -// -// taskService.addComment(taskReq.getTaskId(), task.getProcessInstanceId(), taskReq.getComment()); -// -// taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(taskReq.getTaskId()) -// .withVariables(taskReq.getVariables()) -// .build()); + // TODO 芋艿:添加评论 +// taskService.addComment(task.getId(), task.getProcessInstanceId(), reqVO.getComment()); } @Override @@ -347,4 +351,9 @@ public class BpmTaskServiceImpl implements BpmTaskService { } return highLightedFlowIds; } + + private Task getTask(String id) { + return taskService.createTaskQuery().taskId(id).singleResult(); + } + }