From fc6a7680582069f9e2329186cb48d7f454fdd64f Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sun, 9 Jan 2022 09:08:14 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=B5=81=E7=A8=8B=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E7=9A=84=E5=AE=A1=E6=89=B9=E7=BB=93=E6=9E=9C=EF=BC=8C?= =?UTF-8?q?=E6=8B=86=E6=88=90=20approve=20=E5=92=8C=20reject=20=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/task/BpmTaskController.java | 15 ++++++--- ...eteReqVO.java => BpmTaskApproveReqVO.java} | 8 ++--- .../task/vo/task/BpmTaskRejectReqVO.java | 21 ++++++++++++ .../BpmProcessInstanceDeleteReasonEnum.java | 19 +++++++++++ .../task/BpmProcessInstanceResultEnum.java | 2 +- .../service/oa/LeaveApplyEndProcessor.java | 2 +- .../task/BpmProcessInstanceService.java | 18 +++++++++++ .../bpm/service/task/BpmTaskService.java | 13 ++++++-- .../impl/BpmProcessInstanceServiceImpl.java | 15 +++++++-- .../service/task/impl/BpmTaskServiceImpl.java | 32 +++++++++++++++++-- .../BpmProcessInstanceEventListener.java | 5 ++- yudao-admin-ui/src/api/bpm/task.js | 23 +++++++++++++ .../src/views/bpm/processInstance/create.vue | 13 ++++---- .../src/views/bpm/processInstance/index.vue | 8 ++--- yudao-admin-ui/src/views/bpm/task/todo.vue | 17 +++++++++- 15 files changed, 177 insertions(+), 34 deletions(-) rename yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/vo/task/{BpmTaskCompleteReqVO.java => BpmTaskApproveReqVO.java} (70%) create mode 100644 yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/vo/task/BpmTaskRejectReqVO.java create mode 100644 yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/task/BpmProcessInstanceDeleteReasonEnum.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 e2245663b..92b9248c8 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,10 +42,17 @@ 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); + @PutMapping("/approve") + @ApiOperation("通过任务") + public CommonResult approveTask(@Valid @RequestBody BpmTaskApproveReqVO reqVO) { + taskService.approveTask(reqVO); + return success(true); + } + + @PutMapping("/reject") + @ApiOperation("不通过任务") + public CommonResult rejectTask(@Valid @RequestBody BpmTaskRejectReqVO reqVO) { + taskService.rejectTask(reqVO); return success(true); } 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/BpmTaskApproveReqVO.java similarity index 70% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/vo/task/BpmTaskCompleteReqVO.java rename to yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/vo/task/BpmTaskApproveReqVO.java index 36a635834..356581a96 100644 --- 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/BpmTaskApproveReqVO.java @@ -10,18 +10,14 @@ import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; import java.util.Map; -@ApiModel("流程任务的 Done 已办的分页 Request VO") +@ApiModel("通过流程任务的 Request VO") @Data -public class BpmTaskCompleteReqVO { +public class BpmTaskApproveReqVO { @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/BpmTaskRejectReqVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/vo/task/BpmTaskRejectReqVO.java new file mode 100644 index 000000000..4ad498357 --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/vo/task/BpmTaskRejectReqVO.java @@ -0,0 +1,21 @@ +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 javax.validation.constraints.NotEmpty; + +@ApiModel("不通过流程任务的 Request VO") +@Data +public class BpmTaskRejectReqVO { + + @ApiModelProperty(value = "任务编号", required = true, example = "1024") + @NotEmpty(message = "任务编号不能为空") + private String id; + + @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/enums/task/BpmProcessInstanceDeleteReasonEnum.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/task/BpmProcessInstanceDeleteReasonEnum.java new file mode 100644 index 000000000..2c979ee4b --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/task/BpmProcessInstanceDeleteReasonEnum.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.adminserver.modules.bpm.enums.task; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * 流程实例的删除原因 + * + * @author 芋道源码 + */ +@Getter +@AllArgsConstructor +public enum BpmProcessInstanceDeleteReasonEnum { + + REJECT_TASK("驳回任务"); + + private final String reason; + +} 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 aa89266b7..01916f51a 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 @@ -13,7 +13,7 @@ import lombok.Getter; public enum BpmProcessInstanceResultEnum { PROCESS(1, "处理中"), - PASS(2, "通过"), + APPROVE(2, "通过"), REJECT(3, "不通过"), CANCEL(4, "已取消"); diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/oa/LeaveApplyEndProcessor.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/oa/LeaveApplyEndProcessor.java index e67749be1..068dc4253 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/oa/LeaveApplyEndProcessor.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/oa/LeaveApplyEndProcessor.java @@ -29,7 +29,7 @@ public class LeaveApplyEndProcessor implements ExecutionListener { OALeaveDO updateDo = new OALeaveDO(); updateDo.setId(Long.valueOf(businessKey)); if (Objects.equals(approved, true)) { - updateDo.setStatus(BpmProcessInstanceResultEnum.PASS.getResult()); + updateDo.setStatus(BpmProcessInstanceResultEnum.APPROVE.getResult()); } else { updateDo.setStatus(BpmProcessInstanceResultEnum.REJECT.getResult()); } 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 e598b4968..96d751a01 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 @@ -4,6 +4,8 @@ import cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.instance.BpmP 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; +import cn.iocoder.yudao.adminserver.modules.bpm.enums.task.BpmProcessInstanceDeleteReasonEnum; +import cn.iocoder.yudao.adminserver.modules.bpm.enums.task.BpmProcessInstanceResultEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import org.activiti.engine.runtime.ProcessInstance; @@ -37,6 +39,22 @@ public interface BpmProcessInstanceService { */ void cancelProcessInstance(Long userId, @Valid BpmProcessInstanceCancelReqVO cancelReqVO); + /** + * 删除流程实例 + * + * @param id 流程编号 + * @param reason 删除原因。可选 {@link BpmProcessInstanceDeleteReasonEnum} + */ + void deleteProcessInstance(String id, String reason); + + /** + * 更新流程实例的结果 + * + * @param id 流程编号 + * @param result 结果,{@link BpmProcessInstanceResultEnum} + */ + void updateProcessInstanceResult(String id, Integer result); + /** * 获得流程实例的分页 * 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 86063a09a..8ecbf9fe7 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 @@ -71,11 +71,18 @@ public interface BpmTaskService { void updateTaskAssign(String id, Long userId); /** - * 完成任务(审批通过 / 不通过) + * 通过任务 * - * @param taskReq 完成请求 + * @param reqVO 通过请求 */ - void completeTask(@Valid BpmTaskCompleteReqVO taskReq); + void approveTask(@Valid BpmTaskApproveReqVO reqVO); + + /** + * 不通过任务 + * + * @param reqVO 不通过请求 + */ + void rejectTask(@Valid BpmTaskRejectReqVO reqVO); /** * 根据任务id, 查询已经完成的用户任务,未完成的用户任务 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 652b606d6..7082924a2 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 @@ -140,9 +140,18 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService // 通过删除流程实例,实现流程实例的取消 runtimeService.deleteProcessInstance(cancelReqVO.getId(), cancelReqVO.getReason()); // 更新流程实例的拓展表为取消状态 - processInstanceExtMapper.updateByProcessInstanceId(cancelReqVO.getId(), - new BpmProcessInstanceExtDO().setStatus(BpmProcessInstanceStatusEnum.FINISH.getStatus()) - .setResult(BpmProcessInstanceResultEnum.CANCEL.getResult())); + updateProcessInstanceResult(cancelReqVO.getId(), BpmProcessInstanceResultEnum.CANCEL.getResult()); + } + + @Override + public void deleteProcessInstance(String id, String reason) { + runtimeService.deleteProcessInstance(id, reason); + } + + @Override + public void updateProcessInstanceResult(String id, Integer result) { + processInstanceExtMapper.updateByProcessInstanceId(id, new BpmProcessInstanceExtDO() + .setStatus(BpmProcessInstanceStatusEnum.FINISH.getStatus()).setResult(result)); } @Override 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 84713a4d3..e155349fa 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 @@ -5,6 +5,8 @@ import cn.hutool.core.io.IoUtil; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.task.*; import cn.iocoder.yudao.adminserver.modules.bpm.convert.task.BpmTaskConvert; +import cn.iocoder.yudao.adminserver.modules.bpm.enums.task.BpmProcessInstanceDeleteReasonEnum; +import cn.iocoder.yudao.adminserver.modules.bpm.enums.task.BpmProcessInstanceResultEnum; import cn.iocoder.yudao.adminserver.modules.bpm.service.task.BpmProcessInstanceService; import cn.iocoder.yudao.adminserver.modules.bpm.service.task.BpmTaskService; import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; @@ -37,6 +39,7 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.util.ObjectUtils; import javax.annotation.Resource; +import javax.validation.Valid; import java.io.IOException; import java.io.InputStream; import java.util.*; @@ -158,7 +161,7 @@ public class BpmTaskServiceImpl implements BpmTaskService { @Override @Transactional(rollbackFor = Exception.class) - public void completeTask(BpmTaskCompleteReqVO reqVO) { + public void approveTask(BpmTaskApproveReqVO reqVO) { // 校验任务存在 Task task = getTask(reqVO.getId()); if (task == null) { @@ -170,8 +173,31 @@ public class BpmTaskServiceImpl implements BpmTaskService { throw exception(PROCESS_INSTANCE_NOT_EXISTS); } - // 完成(审批)任务 - taskService.complete(task.getId(), instance.getProcessVariables()); + // 完成任务,审批通过 + taskService.complete(task.getId(), instance.getProcessVariables()); // TODO 芋艿:variables 的选择 + + // TODO 芋艿:添加评论 +// taskService.addComment(task.getId(), task.getProcessInstanceId(), reqVO.getComment()); + } + + @Override + public void rejectTask(@Valid BpmTaskRejectReqVO 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); + } + + // 删除流程实例,以实现驳回任务时,取消整个审批流程 + processInstanceService.deleteProcessInstance(instance.getId(), BpmProcessInstanceDeleteReasonEnum.REJECT_TASK.getReason()); + // 更新流程实例为不通过 + processInstanceService.updateProcessInstanceResult(instance.getProcessInstanceId(), + BpmProcessInstanceResultEnum.REJECT.getResult()); // TODO 芋艿:添加评论 // taskService.addComment(task.getId(), task.getProcessInstanceId(), reqVO.getComment()); 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 62d2b069b..2d4279518 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 @@ -1,6 +1,7 @@ package cn.iocoder.yudao.adminserver.modules.bpm.service.task.listener; import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.task.BpmProcessInstanceExtDO; +import cn.iocoder.yudao.adminserver.modules.bpm.enums.task.BpmProcessInstanceResultEnum; import cn.iocoder.yudao.adminserver.modules.bpm.service.task.BpmProcessInstanceService; import org.activiti.engine.delegate.event.ActivitiEvent; import org.activiti.engine.delegate.event.ActivitiEventListener; @@ -31,7 +32,9 @@ public class BpmProcessInstanceEventListener implements ActivitiEventListener { // 正常完成 if (event.getType() == ActivitiEventType.PROCESS_COMPLETED || event.getType() == ActivitiEventType.PROCESS_COMPLETED_WITH_ERROR_END_EVENT) { - // TODO 芋艿:更新 + // 正常完成,说明所有流程任务都是审批通过 + processInstanceService.updateProcessInstanceResult(event.getProcessInstanceId(), + BpmProcessInstanceResultEnum.APPROVE.getResult()); } } diff --git a/yudao-admin-ui/src/api/bpm/task.js b/yudao-admin-ui/src/api/bpm/task.js index 2c8f93e9b..623291575 100644 --- a/yudao-admin-ui/src/api/bpm/task.js +++ b/yudao-admin-ui/src/api/bpm/task.js @@ -8,3 +8,26 @@ export function getTodoTaskPage(query) { }) } +export function completeTask(data) { + return request({ + url: '/bpm/task/complete', + method: 'PUT', + data: data + }) +} + +export function approveTask(data) { + return request({ + url: '/bpm/task/approve', + method: 'PUT', + data: data + }) +} + +export function rejectTask(data) { + return request({ + url: '/bpm/task/reject', + method: 'PUT', + data: data + }) +} diff --git a/yudao-admin-ui/src/views/bpm/processInstance/create.vue b/yudao-admin-ui/src/views/bpm/processInstance/create.vue index bd4310565..d265bc9ee 100644 --- a/yudao-admin-ui/src/views/bpm/processInstance/create.vue +++ b/yudao-admin-ui/src/views/bpm/processInstance/create.vue @@ -41,15 +41,14 @@ + +
+ 流程图 +
+ +
- -
- 流程图 -
- -
- diff --git a/yudao-admin-ui/src/views/bpm/processInstance/index.vue b/yudao-admin-ui/src/views/bpm/processInstance/index.vue index d96215242..a339ffdb7 100644 --- a/yudao-admin-ui/src/views/bpm/processInstance/index.vue +++ b/yudao-admin-ui/src/views/bpm/processInstance/index.vue @@ -64,11 +64,11 @@ diff --git a/yudao-admin-ui/src/views/bpm/task/todo.vue b/yudao-admin-ui/src/views/bpm/task/todo.vue index ce54183cf..ac39f7a21 100644 --- a/yudao-admin-ui/src/views/bpm/task/todo.vue +++ b/yudao-admin-ui/src/views/bpm/task/todo.vue @@ -37,6 +37,8 @@ @@ -50,7 +52,7 @@