package cn.iocoder.yudao.module.crm.service.quotation.listener; import cn.iocoder.yudao.module.bpm.api.event.BpmProcessInstanceStatusEvent; import cn.iocoder.yudao.module.crm.dal.dataobject.quotation.CrmSaleQuotationDO; import cn.iocoder.yudao.module.crm.dal.mysql.quotation.CrmSaleQuotationMapper; import cn.iocoder.yudao.module.crm.enums.quotation.CrmSaleQuotationStatusEnum; import cn.iocoder.yudao.module.crm.service.quotation.CrmSaleQuotationService; 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 CrmSaleQuotationStatusListener implements ApplicationListener { @Resource private CrmSaleQuotationService saleQuotationService; @Resource private CrmSaleQuotationMapper saleQuotationMapper; @Override public void onApplicationEvent(BpmProcessInstanceStatusEvent event) { // 通过 businessKey 查询报价单 Long quotationId; try { quotationId = Long.parseLong(event.getBusinessKey()); } catch (NumberFormatException e) { return; // businessKey 不是数字,忽略 } CrmSaleQuotationDO quotation = saleQuotationMapper.selectById(quotationId); if (quotation == null) { return; // 不是报价单,忽略 } // 只有审批中状态的报价单才处理 if (!CrmSaleQuotationStatusEnum.PROCESS.getStatus().equals(quotation.getStatus())) { log.warn("[onApplicationEvent] 报价单({}) 不处于审批中状态,当前状态: {}", quotationId, quotation.getStatus()); return; } log.info("[onApplicationEvent] 报价单({}) 审批状态更新: {}", quotationId, event.getStatus()); saleQuotationService.updateSaleQuotationAuditStatus(quotationId, event.getStatus()); } }