调整流程任务的审批结果,拆成 approve 和 reject 接口

This commit is contained in:
YunaiV 2022-01-09 09:08:14 +08:00
parent e931414b55
commit fc6a768058
15 changed files with 177 additions and 34 deletions

View File

@ -42,10 +42,17 @@ public class BpmTaskController {
return success(taskService.getDoneTaskPage(getLoginUserId(), pageVO)); return success(taskService.getDoneTaskPage(getLoginUserId(), pageVO));
} }
@PutMapping("/complete") @PutMapping("/approve")
@ApiOperation(value = "完成任务", notes = "审批通过 or 不通过") @ApiOperation("通过任务")
public CommonResult<Boolean> completeTask(@Valid @RequestBody BpmTaskCompleteReqVO reqVO) { public CommonResult<Boolean> approveTask(@Valid @RequestBody BpmTaskApproveReqVO reqVO) {
taskService.completeTask(reqVO); taskService.approveTask(reqVO);
return success(true);
}
@PutMapping("/reject")
@ApiOperation("不通过任务")
public CommonResult<Boolean> rejectTask(@Valid @RequestBody BpmTaskRejectReqVO reqVO) {
taskService.rejectTask(reqVO);
return success(true); return success(true);
} }

View File

@ -10,18 +10,14 @@ import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.util.Map; import java.util.Map;
@ApiModel("流程任务的 Done 已办的分页 Request VO") @ApiModel("通过流程任务的 Request VO")
@Data @Data
public class BpmTaskCompleteReqVO { public class BpmTaskApproveReqVO {
@ApiModelProperty(value = "任务编号", required = true, example = "1024") @ApiModelProperty(value = "任务编号", required = true, example = "1024")
@NotEmpty(message = "任务编号不能为空") @NotEmpty(message = "任务编号不能为空")
private String id; private String id;
@ApiModelProperty(value = "是否通过", required = true, example = "true", notes = "true 通过false 不通过")
@NotNull(message = "是否通过不能为空")
private Boolean pass;
@ApiModelProperty(value = "审批意见", required = true, example = "不错不错!") @ApiModelProperty(value = "审批意见", required = true, example = "不错不错!")
@NotEmpty(message = "审批意见不能为空") @NotEmpty(message = "审批意见不能为空")
private String comment; private String comment;

View File

@ -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;
}

View File

@ -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;
}

View File

@ -13,7 +13,7 @@ import lombok.Getter;
public enum BpmProcessInstanceResultEnum { public enum BpmProcessInstanceResultEnum {
PROCESS(1, "处理中"), PROCESS(1, "处理中"),
PASS(2, "通过"), APPROVE(2, "通过"),
REJECT(3, "不通过"), REJECT(3, "不通过"),
CANCEL(4, "已取消"); CANCEL(4, "已取消");

View File

@ -29,7 +29,7 @@ public class LeaveApplyEndProcessor implements ExecutionListener {
OALeaveDO updateDo = new OALeaveDO(); OALeaveDO updateDo = new OALeaveDO();
updateDo.setId(Long.valueOf(businessKey)); updateDo.setId(Long.valueOf(businessKey));
if (Objects.equals(approved, true)) { if (Objects.equals(approved, true)) {
updateDo.setStatus(BpmProcessInstanceResultEnum.PASS.getResult()); updateDo.setStatus(BpmProcessInstanceResultEnum.APPROVE.getResult());
} else { } else {
updateDo.setStatus(BpmProcessInstanceResultEnum.REJECT.getResult()); updateDo.setStatus(BpmProcessInstanceResultEnum.REJECT.getResult());
} }

View File

@ -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.BpmProcessInstanceCreateReqVO;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.instance.BpmProcessInstanceMyPageReqVO; 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.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.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import org.activiti.engine.runtime.ProcessInstance; import org.activiti.engine.runtime.ProcessInstance;
@ -37,6 +39,22 @@ public interface BpmProcessInstanceService {
*/ */
void cancelProcessInstance(Long userId, @Valid BpmProcessInstanceCancelReqVO cancelReqVO); 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);
/** /**
* 获得流程实例的分页 * 获得流程实例的分页
* *

View File

@ -71,11 +71,18 @@ public interface BpmTaskService {
void updateTaskAssign(String id, Long userId); 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, 查询已经完成的用户任务未完成的用户任务 * 根据任务id, 查询已经完成的用户任务未完成的用户任务

View File

@ -140,9 +140,18 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
// 通过删除流程实例实现流程实例的取消 // 通过删除流程实例实现流程实例的取消
runtimeService.deleteProcessInstance(cancelReqVO.getId(), cancelReqVO.getReason()); runtimeService.deleteProcessInstance(cancelReqVO.getId(), cancelReqVO.getReason());
// 更新流程实例的拓展表为取消状态 // 更新流程实例的拓展表为取消状态
processInstanceExtMapper.updateByProcessInstanceId(cancelReqVO.getId(), updateProcessInstanceResult(cancelReqVO.getId(), BpmProcessInstanceResultEnum.CANCEL.getResult());
new BpmProcessInstanceExtDO().setStatus(BpmProcessInstanceStatusEnum.FINISH.getStatus()) }
.setResult(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 @Override

View File

@ -5,6 +5,8 @@ import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.task.*; 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.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.BpmProcessInstanceService;
import cn.iocoder.yudao.adminserver.modules.bpm.service.task.BpmTaskService; import cn.iocoder.yudao.adminserver.modules.bpm.service.task.BpmTaskService;
import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; 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 org.springframework.util.ObjectUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.validation.Valid;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.*; import java.util.*;
@ -158,7 +161,7 @@ public class BpmTaskServiceImpl implements BpmTaskService {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void completeTask(BpmTaskCompleteReqVO reqVO) { public void approveTask(BpmTaskApproveReqVO reqVO) {
// 校验任务存在 // 校验任务存在
Task task = getTask(reqVO.getId()); Task task = getTask(reqVO.getId());
if (task == null) { if (task == null) {
@ -170,8 +173,31 @@ public class BpmTaskServiceImpl implements BpmTaskService {
throw exception(PROCESS_INSTANCE_NOT_EXISTS); 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 芋艿添加评论 // TODO 芋艿添加评论
// taskService.addComment(task.getId(), task.getProcessInstanceId(), reqVO.getComment()); // taskService.addComment(task.getId(), task.getProcessInstanceId(), reqVO.getComment());

View File

@ -1,6 +1,7 @@
package cn.iocoder.yudao.adminserver.modules.bpm.service.task.listener; 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.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 cn.iocoder.yudao.adminserver.modules.bpm.service.task.BpmProcessInstanceService;
import org.activiti.engine.delegate.event.ActivitiEvent; import org.activiti.engine.delegate.event.ActivitiEvent;
import org.activiti.engine.delegate.event.ActivitiEventListener; import org.activiti.engine.delegate.event.ActivitiEventListener;
@ -31,7 +32,9 @@ public class BpmProcessInstanceEventListener implements ActivitiEventListener {
// 正常完成 // 正常完成
if (event.getType() == ActivitiEventType.PROCESS_COMPLETED if (event.getType() == ActivitiEventType.PROCESS_COMPLETED
|| event.getType() == ActivitiEventType.PROCESS_COMPLETED_WITH_ERROR_END_EVENT) { || event.getType() == ActivitiEventType.PROCESS_COMPLETED_WITH_ERROR_END_EVENT) {
// TODO 芋艿更新 // 正常完成说明所有流程任务都是审批通过
processInstanceService.updateProcessInstanceResult(event.getProcessInstanceId(),
BpmProcessInstanceResultEnum.APPROVE.getResult());
} }
} }

View File

@ -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
})
}

View File

@ -41,15 +41,14 @@
</div> </div>
</el-col> </el-col>
</el-card> </el-card>
<el-card class="box-card">
<div slot="header" class="clearfix">
<span class="el-icon-picture-outline">流程图</span>
</div>
<my-process-viewer key="designer" v-model="bpmnXML" v-bind="bpmnControlForm" />
</el-card>
</div> </div>
<el-card class="box-card">
<div slot="header" class="clearfix">
<span class="el-icon-picture-outline">流程图</span>
</div>
<my-process-viewer key="designer" v-model="bpmnXML" v-bind="bpmnControlForm" />
</el-card>
</div> </div>
</template> </template>

View File

@ -64,11 +64,11 @@
<el-table-column label="状态" align="center" prop="status"> <el-table-column label="状态" align="center" prop="status">
<template slot-scope="scope"> <template slot-scope="scope">
<span> <span>
<el-tag type="primary" v-if="scope.row.result === 1"> <!-- 进行中 --> <el-tag type="primary" v-if="scope.row.status === 1"> <!-- 进行中 -->
{{ getDictDataLabel(DICT_TYPE.BPM_PROCESS_INSTANCE_STATUS, scope.row.result) }} {{ getDictDataLabel(DICT_TYPE.BPM_PROCESS_INSTANCE_STATUS, scope.row.status) }}
</el-tag> </el-tag>
<el-tag type="success" v-if="scope.row.result === 2"> <!-- 已结束 --> <el-tag type="success" v-if="scope.row.status === 2"> <!-- 已结束 -->
{{ getDictDataLabel(DICT_TYPE.BPM_PROCESS_INSTANCE_STATUS, scope.row.result) }} {{ getDictDataLabel(DICT_TYPE.BPM_PROCESS_INSTANCE_STATUS, scope.row.status) }}
</el-tag> </el-tag>
</span> </span>
</template> </template>

View File

@ -37,6 +37,8 @@
<template slot-scope="scope"> <template slot-scope="scope">
<!-- TODO 权限颜色 --> <!-- TODO 权限颜色 -->
<el-button size="mini" type="text" icon="el-icon-edit">审批</el-button> <el-button size="mini" type="text" icon="el-icon-edit">审批</el-button>
<el-button size="mini" type="text" icon="el-icon-edit" @click="audit(scope.row, true)">通过</el-button>
<el-button size="mini" type="text" icon="el-icon-edit" @click="audit(scope.row, false)">不通过</el-button>
<el-button size="mini" type="text" icon="el-icon-edit" v-if="scope.row.suspensionState === 2">激活</el-button> <el-button size="mini" type="text" icon="el-icon-edit" v-if="scope.row.suspensionState === 2">激活</el-button>
<el-button size="mini" type="text" icon="el-icon-edit" v-if="scope.row.suspensionState === 1">挂起</el-button> <el-button size="mini" type="text" icon="el-icon-edit" v-if="scope.row.suspensionState === 1">挂起</el-button>
</template> </template>
@ -50,7 +52,7 @@
</template> </template>
<script> <script>
import { getTodoTaskPage } from '@/api/bpm/task' import {approveTask, completeTask, getTodoTaskPage, rejectTask} from '@/api/bpm/task'
export default { export default {
name: "Todo", name: "Todo",
@ -124,6 +126,19 @@ export default {
this.resetForm("queryForm"); this.resetForm("queryForm");
this.handleQuery(); this.handleQuery();
}, },
audit(row, pass) {
if (pass) {
approveTask({
id: row.id,
comment: '通过'
})
} else {
rejectTask({
id: row.id,
comment: '不通过'
})
}
}
} }
}; };
</script> </script>