mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-23 07:41:53 +08:00
修改 bpm 流程不通过的 Listener 的逻辑
This commit is contained in:
parent
54e7c10a06
commit
7c62b1a211
@ -1,5 +1,6 @@
|
|||||||
package cn.iocoder.yudao.adminserver.modules.bpm.enums.task;
|
package cn.iocoder.yudao.adminserver.modules.bpm.enums.task;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
@ -12,8 +13,24 @@ import lombok.Getter;
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public enum BpmProcessInstanceDeleteReasonEnum {
|
public enum BpmProcessInstanceDeleteReasonEnum {
|
||||||
|
|
||||||
REJECT_TASK("不通过任务,原因:{}");
|
REJECT_TASK("不通过任务,原因:{}"); // 修改文案时,需要注意 isRejectReason 方法
|
||||||
|
|
||||||
private final String reason;
|
private final String reason;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 格式化理由
|
||||||
|
*
|
||||||
|
* @param args 参数
|
||||||
|
* @return 理由
|
||||||
|
*/
|
||||||
|
public String format(Object... args) {
|
||||||
|
return StrUtil.format(reason, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ========== 逻辑 ==========
|
||||||
|
|
||||||
|
public static boolean isRejectReason(String reason) {
|
||||||
|
return StrUtil.startWith(reason, "不通过任务,原因:");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import cn.iocoder.yudao.adminserver.modules.bpm.service.task.BpmProcessInstanceS
|
|||||||
import org.activiti.api.model.shared.event.RuntimeEvent;
|
import org.activiti.api.model.shared.event.RuntimeEvent;
|
||||||
import org.activiti.api.process.model.ProcessInstance;
|
import org.activiti.api.process.model.ProcessInstance;
|
||||||
import org.activiti.api.process.model.events.ProcessRuntimeEvent;
|
import org.activiti.api.process.model.events.ProcessRuntimeEvent;
|
||||||
|
import org.activiti.api.process.runtime.events.ProcessCancelledEvent;
|
||||||
import org.activiti.api.process.runtime.events.listener.ProcessEventListener;
|
import org.activiti.api.process.runtime.events.listener.ProcessEventListener;
|
||||||
import org.activiti.api.process.runtime.events.listener.ProcessRuntimeEventListener;
|
import org.activiti.api.process.runtime.events.listener.ProcessRuntimeEventListener;
|
||||||
import org.activiti.api.task.model.events.TaskRuntimeEvent;
|
import org.activiti.api.task.model.events.TaskRuntimeEvent;
|
||||||
@ -42,7 +43,8 @@ public class BpmProcessInstanceEventListener<T extends RuntimeEvent<?, ?>>
|
|||||||
}
|
}
|
||||||
// 取消时,更新拓展表为取消
|
// 取消时,更新拓展表为取消
|
||||||
if (event.getEventType() == ProcessRuntimeEvent.ProcessEvents.PROCESS_CANCELLED) {
|
if (event.getEventType() == ProcessRuntimeEvent.ProcessEvents.PROCESS_CANCELLED) {
|
||||||
processInstanceService.updateProcessInstanceExtCancel(event.getEntity());
|
processInstanceService.updateProcessInstanceExtCancel(event.getEntity(),
|
||||||
|
((ProcessCancelledEvent) event).getCause());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 完成时,更新拓展表为已完成
|
// 完成时,更新拓展表为已完成
|
||||||
|
@ -144,13 +144,15 @@ public interface BpmProcessInstanceService {
|
|||||||
* 更新 ProcessInstance 拓展记录为取消
|
* 更新 ProcessInstance 拓展记录为取消
|
||||||
*
|
*
|
||||||
* @param instance 流程任务
|
* @param instance 流程任务
|
||||||
|
* @param reason 取消原因
|
||||||
*/
|
*/
|
||||||
void updateProcessInstanceExtCancel(org.activiti.api.process.model.ProcessInstance instance);
|
void updateProcessInstanceExtCancel(org.activiti.api.process.model.ProcessInstance instance, String reason);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新 ProcessInstance 拓展记录为完成
|
* 更新 ProcessInstance 拓展记录为完成
|
||||||
*
|
*
|
||||||
* @param instance 流程任务
|
* @param instance 流程任务
|
||||||
|
* @param reason 原因
|
||||||
*/
|
*/
|
||||||
void updateProcessInstanceExtComplete(org.activiti.api.process.model.ProcessInstance instance);
|
void updateProcessInstanceExtComplete(org.activiti.api.process.model.ProcessInstance instance);
|
||||||
|
|
||||||
|
@ -241,7 +241,13 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateProcessInstanceExtCancel(org.activiti.api.process.model.ProcessInstance instance) {
|
public void updateProcessInstanceExtCancel(org.activiti.api.process.model.ProcessInstance instance, String reason) {
|
||||||
|
// 判断是否为 Reject 不通过。如果是,则不进行更新
|
||||||
|
if (BpmProcessInstanceDeleteReasonEnum.isRejectReason(reason)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新拓展表
|
||||||
BpmProcessInstanceExtDO instanceExtDO = BpmProcessInstanceConvert.INSTANCE.convert(instance)
|
BpmProcessInstanceExtDO instanceExtDO = BpmProcessInstanceConvert.INSTANCE.convert(instance)
|
||||||
.setEndTime(new Date()) // 由于 ProcessInstance 里没有办法拿到 endTime,所以这里设置
|
.setEndTime(new Date()) // 由于 ProcessInstance 里没有办法拿到 endTime,所以这里设置
|
||||||
.setStatus(BpmProcessInstanceStatusEnum.FINISH.getStatus())
|
.setStatus(BpmProcessInstanceStatusEnum.FINISH.getStatus())
|
||||||
@ -265,7 +271,7 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
|
|||||||
public void updateProcessInstanceExtReject(String id, String comment) {
|
public void updateProcessInstanceExtReject(String id, String comment) {
|
||||||
ProcessInstance processInstance = getProcessInstance(id);
|
ProcessInstance processInstance = getProcessInstance(id);
|
||||||
// 删除流程实例,以实现驳回任务时,取消整个审批流程
|
// 删除流程实例,以实现驳回任务时,取消整个审批流程
|
||||||
deleteProcessInstance(id, StrUtil.format(BpmProcessInstanceDeleteReasonEnum.REJECT_TASK.getReason(), comment));
|
deleteProcessInstance(id, StrUtil.format(BpmProcessInstanceDeleteReasonEnum.REJECT_TASK.format(comment)));
|
||||||
|
|
||||||
// 更新 status + result
|
// 更新 status + result
|
||||||
// 注意,不能和上面的逻辑更换位置。因为 deleteProcessInstance 会触发流程的取消,进而调用 updateProcessInstanceExtCancel 方法,
|
// 注意,不能和上面的逻辑更换位置。因为 deleteProcessInstance 会触发流程的取消,进而调用 updateProcessInstanceExtCancel 方法,
|
||||||
|
Loading…
Reference in New Issue
Block a user