修改 bpm 流程不通过的 Listener 的逻辑

This commit is contained in:
YunaiV 2022-01-22 22:44:42 +08:00
parent 54e7c10a06
commit 7c62b1a211
4 changed files with 32 additions and 5 deletions

View File

@ -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, "不通过任务,原因:");
}
} }

View File

@ -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;
} }
// 完成时更新拓展表为已完成 // 完成时更新拓展表为已完成

View File

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

View File

@ -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 方法