package cn.iocoder.yudao.module.aftersales.service.compensation.listener; import cn.iocoder.yudao.module.aftersales.service.compensation.AfterSaleCompensationService; import cn.iocoder.yudao.module.bpm.api.event.BpmProcessInstanceStatusEvent; import cn.iocoder.yudao.module.bpm.api.event.BpmProcessInstanceStatusEventListener; import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; /** * 售后赔付单审批状态监听器 * * 监听 BPM 审批结果,回写赔付单审核状态,使赔付审批统一在「协同办公 - 我的流程」中流转。 */ @Component @Slf4j public class AfterSaleCompensationStatusListener extends BpmProcessInstanceStatusEventListener { private static final String PROCESS_DEFINITION_KEY = "compensation_approve"; @Resource private AfterSaleCompensationService compensationService; @Override protected String getProcessDefinitionKey() { return PROCESS_DEFINITION_KEY; } @Override protected void onEvent(BpmProcessInstanceStatusEvent event) { Long compensationId; try { compensationId = Long.parseLong(event.getBusinessKey()); } catch (NumberFormatException e) { log.warn("[onEvent] businessKey({}) 不是有效的赔付单编号", event.getBusinessKey()); return; } log.info("[onEvent] 收到赔付单审批事件,compensationId={}, status={}", compensationId, event.getStatus()); try { compensationService.updateCompensationAuditStatus(compensationId, event.getStatus(), event.getReason()); } catch (Exception e) { log.error("[onEvent] 回写赔付单审批状态失败,compensationId={}", compensationId, e); } } }