package cn.iocoder.yudao.module.crm.service.refund.listener; import cn.iocoder.yudao.module.bpm.api.event.BpmProcessInstanceStatusEvent; import cn.iocoder.yudao.module.crm.dal.dataobject.refund.CrmRefundDO; import cn.iocoder.yudao.module.crm.dal.mysql.refund.CrmRefundMapper; import cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum; import cn.iocoder.yudao.module.crm.service.refund.CrmRefundService; import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; import org.springframework.context.ApplicationListener; import org.springframework.stereotype.Component; /** * 退费审批的结果监听器实现类 * * 通过 businessKey(退费单ID)匹配,而不是固定的流程定义 Key, * 这样可以支持分类下任意 Key 的流程模型。 */ @Component @Slf4j public class CrmRefundStatusListener implements ApplicationListener { @Resource private CrmRefundService refundService; @Resource private CrmRefundMapper refundMapper; @Override public void onApplicationEvent(BpmProcessInstanceStatusEvent event) { // 通过 businessKey 查询退费单 Long refundId; try { refundId = Long.parseLong(event.getBusinessKey()); } catch (NumberFormatException e) { return; // businessKey 不是数字,忽略 } CrmRefundDO refund = refundMapper.selectById(refundId); if (refund == null) { return; // 不是退费单,忽略 } // 只有审批中状态的退费单才处理 if (!CrmAuditStatusEnum.PROCESS.getStatus().equals(refund.getAuditStatus())) { log.warn("[onApplicationEvent] 退费单({}) 不处于审批中状态,当前状态: {}", refundId, refund.getAuditStatus()); return; } log.info("[onApplicationEvent] 退费单({}) 审批状态更新: {}", refundId, event.getStatus()); // 更新审批状态 refundService.updateRefundAuditStatus(refundId, event.getStatus()); } }