添加bg确认节点后的listener,用来更改xispeak的完成状态字段
This commit is contained in:
+59
@@ -0,0 +1,59 @@
|
|||||||
|
package org.jeecg.xispeak.listener;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.flowable.engine.delegate.TaskListener;
|
||||||
|
import org.flowable.task.service.delegate.DelegateTask;
|
||||||
|
import org.jeecg.modules.bg.xispeak.constant.XiSpeakConstant;
|
||||||
|
import org.jeecg.modules.bg.xispeak.entity.BgXiSpeak;
|
||||||
|
import org.jeecg.modules.bg.xispeak.service.IBgXiSpeakService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.jeecg.xispeak.XiSpeakConfig;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Component("AfterBgWorkerFinalApproveListener")
|
||||||
|
@RequiredArgsConstructor(onConstructor_ = @Autowired)
|
||||||
|
public class AfterBgWorkerFinalApproveListener implements TaskListener {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
private final XiSpeakConfig xiSpeakConfig;
|
||||||
|
private final IBgXiSpeakService bgXiSpeakService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void notify(DelegateTask delegateTask) {
|
||||||
|
// 💡 优化 2: 安全获取变量,使用 Objects.toString 防止流程变量缺失导致 NPE 崩溃
|
||||||
|
Object businessKeyObj = delegateTask.getVariable(xiSpeakConfig.getXiSpeak().getBusinessKey());
|
||||||
|
String rawBusinessKey = Objects.toString(businessKeyObj, "").trim();
|
||||||
|
|
||||||
|
if (rawBusinessKey.isEmpty()) {
|
||||||
|
log.warn("【xispeak最终审批监听器】未查询到对应业务表单 id,跳过更新。TaskId: {}", delegateTask.getId());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 💡 优化 3: 极致性能!告别先查后改。直接 new 一个只带 ID 的干净实体进行局部更新
|
||||||
|
BgXiSpeak updateEntity = new BgXiSpeak();
|
||||||
|
updateEntity.setId(rawBusinessKey); // 假设你的主键是 String 类型
|
||||||
|
updateEntity.setCompletionStatus(XiSpeakConstant.CompletionStatus.FINISHED);
|
||||||
|
|
||||||
|
// 执行更新
|
||||||
|
boolean success = bgXiSpeakService.updateById(updateEntity);
|
||||||
|
|
||||||
|
if (success) {
|
||||||
|
log.info("【xispeak最终审批监听器】成功将业务表单 [id={}] 的状态更新为已完成", rawBusinessKey);
|
||||||
|
} else {
|
||||||
|
// 如果数据库里根本没这条记录,updateById 会返回 false
|
||||||
|
log.warn("【xispeak最终审批监听器】更新失败,数据库中不存在 id 为 {} 的业务数据", rawBusinessKey);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
// 💡 优化 4: 增加异常捕获,避免因为业务表更新失败导致整个工作流引擎在推进时抛出未捕获异常
|
||||||
|
log.error("【xispeak最终审批监听器】更新业务表单异常, businessKey: " + rawBusinessKey, e);
|
||||||
|
throw e; // 如果希望流程为此阻断、回滚,再将其抛出
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user