package cn.iocoder.yudao.module.srm.service.apply.listener; import cn.iocoder.yudao.module.bpm.api.event.BpmProcessInstanceStatusEvent; import cn.iocoder.yudao.module.bpm.api.event.BpmProcessInstanceStatusEventListener; import cn.iocoder.yudao.module.srm.service.apply.SrmSupplierApplyService; import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; /** * 供应商准入审批状态监听器 * * 监听 BPM 流程实例状态变更事件,更新准入申请的审批状态(协同办公审批后回写) */ @Component @Slf4j public class SrmSupplierApplyStatusListener extends BpmProcessInstanceStatusEventListener { /** * 供应商准入审批流程定义 Key */ private static final String PROCESS_DEFINITION_KEY = "supplier_apply_approve"; @Resource private SrmSupplierApplyService supplierApplyService; @Override protected String getProcessDefinitionKey() { return PROCESS_DEFINITION_KEY; } @Override protected void onEvent(BpmProcessInstanceStatusEvent event) { Long applyId; try { applyId = Long.parseLong(event.getBusinessKey()); } catch (NumberFormatException e) { log.warn("[onEvent] businessKey({}) 不是有效的准入申请编号", event.getBusinessKey()); return; } log.info("[onEvent] 收到BPM审批事件,applyId={}, status={}", applyId, event.getStatus()); try { supplierApplyService.updateSupplierApplyAuditStatus(applyId, event.getStatus()); log.info("[onEvent] 准入申请({}) 审批状态更新完成", applyId); } catch (Exception e) { log.error("[onEvent] 更新准入申请审批状态失败,applyId={}", applyId, e); } } }