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 的流程模型。 * * @author 芋道源码 */ @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 saleQuotation = saleQuotationMapper.selectById(quotationId); if (saleQuotation == null) { return; // 不是销售报价,忽略 } // 只有审批中状态的报价单才处理 if (!CrmSaleQuotationStatusEnum.PROCESS.getStatus().equals(saleQuotation.getStatus())) { log.warn("[onApplicationEvent] 销售报价单({}) 不处于审批中状态,当前状态: {}", quotationId, saleQuotation.getStatus()); return; } log.info("[onApplicationEvent] 销售报价单({}) 审批状态更新: {}", quotationId, event.getStatus()); // 更新审批状态 saleQuotationService.updateSaleQuotationAuditStatus(quotationId, event.getStatus()); } }