From 2630ad8eaacbf2d86f969682507c470a1128d334 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 8 Jan 2022 22:11:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E6=B5=81=E7=A8=8B=E5=AE=9E?= =?UTF-8?q?=E4=BE=8B=E7=9A=84=E5=8F=96=E6=B6=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../task/BpmProcessInstanceController.http | 11 ++++++++ .../task/BpmProcessInstanceController.java | 8 ++++++ .../BpmProcessInstanceCancelReqVO.java | 23 ++++++++++++++++ .../task/BpmProcessInstanceExtMapper.java | 5 ++++ .../bpm/enums/BpmErrorCodeConstants.java | 3 +-- .../task/BpmProcessInstanceResultEnum.java | 2 +- .../task/BpmProcessInstanceService.java | 9 +++++++ .../impl/BpmProcessInstanceServiceImpl.java | 21 +++++++++++++-- .../service/task/impl/BpmTaskServiceImpl.java | 4 +-- .../BpmProcessInstanceEventListener.java | 10 +++---- yudao-admin-ui/src/api/bpm/processInstance.js | 11 ++++++++ .../src/views/bpm/processInstance/index.vue | 26 ++++++++++++++++--- 12 files changed, 115 insertions(+), 18 deletions(-) create mode 100644 yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/vo/instance/BpmProcessInstanceCancelReqVO.java diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/BpmProcessInstanceController.http b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/BpmProcessInstanceController.http index 6cc99c5f2..4775cbc24 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/BpmProcessInstanceController.http +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/BpmProcessInstanceController.http @@ -12,6 +12,17 @@ Authorization: Bearer {{token}} } } +### 请求 /bpm/process-instance/cancel 接口 => 成功 +DELETE {{baseUrl}}/bpm/process-instance/cancel +Content-Type: application/json +tenant-id: 1 +Authorization: Bearer {{token}} + +{ + "id": "b9220387-7088-11ec-bcae-a2380e71991a", + "reason": "我就取消" +} + ### 请求 /bpm/process-instance/my-page 接口 => 成功 GET {{baseUrl}}/bpm/process-instance/my-page tenant-id: 1 diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/BpmProcessInstanceController.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/BpmProcessInstanceController.java index 396d8f4e3..c948a6fef 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/BpmProcessInstanceController.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/BpmProcessInstanceController.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.adminserver.modules.bpm.controller.task; +import cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.instance.BpmProcessInstanceCancelReqVO; import cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.instance.BpmProcessInstanceCreateReqVO; import cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.instance.BpmProcessInstanceMyPageReqVO; import cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.instance.BpmProcessInstancePageItemRespVO; @@ -34,6 +35,13 @@ public class BpmProcessInstanceController { return success(processInstanceService.createProcessInstance(getLoginUserId(), createReqVO)); } + @DeleteMapping("/cancel") + @ApiOperation(value = "取消流程实例", notes = "撤回发起的流程") + public CommonResult cancelProcessInstance(@Valid @RequestBody BpmProcessInstanceCancelReqVO cancelReqVO) { + processInstanceService.cancelProcessInstance(getLoginUserId(), cancelReqVO); + return success(true); + } + @GetMapping("/my-page") @ApiOperation(value = "获得我的实例分页列表", notes = "在【我的流程】菜单中,进行调用") public CommonResult> getMyProcessInstancePage( diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/vo/instance/BpmProcessInstanceCancelReqVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/vo/instance/BpmProcessInstanceCancelReqVO.java new file mode 100644 index 000000000..74f0a86b4 --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/vo/instance/BpmProcessInstanceCancelReqVO.java @@ -0,0 +1,23 @@ +package cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.instance; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; +import java.util.Map; + +@ApiModel("流程实例的取消 Request VO") +@Data +public class BpmProcessInstanceCancelReqVO { + + @ApiModelProperty(value = "流程实例的编号", required = true, example = "1024") + @NotEmpty(message = "流程实例的编号不能为空") + private String id; + + @ApiModelProperty(value = "取消原因", required = true, example = "不请假了!") + @NotEmpty(message = "取消原因不能为空") + private String reason; + +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/mysql/task/BpmProcessInstanceExtMapper.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/mysql/task/BpmProcessInstanceExtMapper.java index fab9ab804..a0d28616b 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/mysql/task/BpmProcessInstanceExtMapper.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/mysql/task/BpmProcessInstanceExtMapper.java @@ -5,6 +5,7 @@ import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.task.BpmProcessIn import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import org.apache.ibatis.annotations.Mapper; @Mapper @@ -22,4 +23,8 @@ public interface BpmProcessInstanceExtMapper extends BaseMapperX().eq("process_instance_id", processInstanceId)); + } + } 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 0e78583b3..f5d36c5e9 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 @@ -10,7 +10,6 @@ import cn.iocoder.yudao.framework.common.exception.ErrorCode; public interface BpmErrorCodeConstants { // ========== 通用流程处理 模块 1-009-000-000 ========== - ErrorCode PROCESS_INSTANCE_NOT_EXISTS = new ErrorCode(1009000001, "流程实例不存在"); ErrorCode HIGHLIGHT_IMG_ERROR = new ErrorCode(1009000002, "获取高亮流程图异常"); // ========== OA 流程模块 1-009-001-000 ========== @@ -34,7 +33,7 @@ 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, "流程取消失败,流程不处于运行中"); // ========== 动态表单模块 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/enums/task/BpmProcessInstanceResultEnum.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/task/BpmProcessInstanceResultEnum.java index 6f5f10cc9..aa89266b7 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/task/BpmProcessInstanceResultEnum.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/task/BpmProcessInstanceResultEnum.java @@ -15,7 +15,7 @@ public enum BpmProcessInstanceResultEnum { PROCESS(1, "处理中"), PASS(2, "通过"), REJECT(3, "不通过"), - CANCEL(4, "撤销"); + CANCEL(4, "已取消"); /** * 结果 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 f176c7dbe..068ee5eb1 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 @@ -1,5 +1,6 @@ package cn.iocoder.yudao.adminserver.modules.bpm.service.task; +import cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.instance.BpmProcessInstanceCancelReqVO; import cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.instance.BpmProcessInstanceCreateReqVO; import cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.instance.BpmProcessInstanceMyPageReqVO; import cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.instance.BpmProcessInstancePageItemRespVO; @@ -28,6 +29,14 @@ public interface BpmProcessInstanceService { */ String createProcessInstance(Long userId, @Valid BpmProcessInstanceCreateReqVO createReqVO); + /** + * 取消流程实例 + * + * @param userId 用户编号 + * @param cancelReqVO 取消信息 + */ + void cancelProcessInstance(Long userId, @Valid BpmProcessInstanceCancelReqVO cancelReqVO); + /** * 获得流程实例的分页 * 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 45bd9e410..9228ab139 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 @@ -2,6 +2,7 @@ package cn.iocoder.yudao.adminserver.modules.bpm.service.task.impl; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.lang.Assert; +import cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.instance.BpmProcessInstanceCancelReqVO; import cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.instance.BpmProcessInstanceCreateReqVO; import cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.instance.BpmProcessInstanceMyPageReqVO; import cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.instance.BpmProcessInstancePageItemRespVO; @@ -37,8 +38,7 @@ import java.util.Map; import java.util.Set; import java.util.function.Consumer; -import static cn.iocoder.yudao.adminserver.modules.bpm.enums.BpmErrorCodeConstants.PROCESS_DEFINITION_IS_SUSPENDED; -import static cn.iocoder.yudao.adminserver.modules.bpm.enums.BpmErrorCodeConstants.PROCESS_DEFINITION_NOT_EXISTS; +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.convertList; @@ -127,6 +127,23 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService processInstanceExtMapper.insert(instanceExt); } + @Override + @Transactional(rollbackFor = Exception.class) + public void cancelProcessInstance(Long userId, BpmProcessInstanceCancelReqVO cancelReqVO) { + // 校验流程实例存在 + ProcessInstance instance = getProcessInstance(cancelReqVO.getId()); + if (instance == null) { + throw exception(PROCESS_INSTANCE_CANCEL_FAIL_NOT_EXISTS); + } + + // 通过删除流程实例,实现流程实例的取消 + runtimeService.deleteProcessInstance(cancelReqVO.getId(), cancelReqVO.getReason()); + // 更新流程实例的拓展表为取消状态 + processInstanceExtMapper.updateByProcessInstanceId(cancelReqVO.getId(), + new BpmProcessInstanceExtDO().setStatus(BpmProcessInstanceStatusEnum.FINISH.getStatus()) + .setResult(BpmProcessInstanceResultEnum.CANCEL.getResult())); + } + @Override public PageResult getMyProcessInstancePage(Long userId, BpmProcessInstanceMyPageReqVO pageReqVO) { 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 8204fc608..0cd7df96c 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 @@ -42,7 +42,6 @@ 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.PROCESS_INSTANCE_NOT_EXISTS; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; @@ -228,7 +227,8 @@ public class BpmTaskServiceImpl implements BpmTaskService { HistoricProcessInstance hpi = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult(); // 如果不存在实例。 说明数据异常 if (hpi == null) { - throw exception(PROCESS_INSTANCE_NOT_EXISTS); +// throw exception(PROCESS_INSTANCE_NOT_EXISTS); + throw new RuntimeException("不存在"); } // 如果有结束时间 返回model的流程图 if (!ObjectUtils.isEmpty(hpi.getEndTime())) { diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/listener/BpmProcessInstanceEventListener.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/listener/BpmProcessInstanceEventListener.java index 970a0b541..62d2b069b 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/listener/BpmProcessInstanceEventListener.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/listener/BpmProcessInstanceEventListener.java @@ -25,17 +25,13 @@ public class BpmProcessInstanceEventListener implements ActivitiEventListener { @Override public void onEvent(ActivitiEvent event) { - // 不处理 ActivitiEventType.PROCESS_STARTED 事件。原因:事件发布时,流程实例还没进行入库,就已经发布了 ActivitiEvent 事件 + // 不处理 ActivitiEventType.PROCESS_STARTED 事件。原因:事件发布时,流程实例还没进行入库,就已经发布了 ActivitiEvent 事件 + // 不处理 ActivitiEventType.PROCESS_CANCELLED 事件。原因:直接在 BpmTaskService#cancelProcessInstance 更新记录 // 正常完成 if (event.getType() == ActivitiEventType.PROCESS_COMPLETED || event.getType() == ActivitiEventType.PROCESS_COMPLETED_WITH_ERROR_END_EVENT) { - return; - } - // 取消 - if (event.getType() == ActivitiEventType.PROCESS_CANCELLED) { - // TODO - System.out.println(); + // TODO 芋艿:更新 } } diff --git a/yudao-admin-ui/src/api/bpm/processInstance.js b/yudao-admin-ui/src/api/bpm/processInstance.js index 8f080ca3e..f82c72d51 100644 --- a/yudao-admin-ui/src/api/bpm/processInstance.js +++ b/yudao-admin-ui/src/api/bpm/processInstance.js @@ -7,3 +7,14 @@ export function getMyProcessInstancePage(query) { params: query }) } + +export function cancelProcessInstance(id, reason) { + return request({ + url: '/bpm/process-instance/cancel', + method: 'DELETE', + data: { + id, + reason + } + }) +} diff --git a/yudao-admin-ui/src/views/bpm/processInstance/index.vue b/yudao-admin-ui/src/views/bpm/processInstance/index.vue index 12994c635..79c705d7b 100644 --- a/yudao-admin-ui/src/views/bpm/processInstance/index.vue +++ b/yudao-admin-ui/src/views/bpm/processInstance/index.vue @@ -103,8 +103,9 @@ @@ -162,8 +163,9 @@ import { deleteProcessInstanceExt, getProcessInstanceExt, getProcessInstanceExtPage, - exportProcessInstanceExtExcel + exportProcessInstanceExtExcel, cancelProcessInstance } from "@/api/bpm/processInstance"; +import {deleteErrorCode} from "@/api/system/errorCode"; export default { name: "ProcessInstanceExt", @@ -283,7 +285,23 @@ export default { this.getList(); }); }); - } + }, + /** 取消按钮操作 */ + handleCancel(row) { + const id = row.id; + this.$prompt('请输出取消原因?', "取消流程", { + type: 'warning', + confirmButtonText: "确定", + cancelButtonText: "取消", + inputPattern: /^[\s\S]*.*[^\s][\s\S]*$/, // 判断非空,且非空格 + inputErrorMessage: "取消原因不能为空", + }).then(({ value }) => { + return cancelProcessInstance(id, value); + }).then(() => { + this.getList(); + this.msgSuccess("取消成功"); + }) + }, } };