gaoluyang
6 天以前 8c65f898ed6e5b0c7a94c792c4562f6ec831dccd
yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/service/quotation/listener/CrmSaleQuotationStatusListener.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,52 @@
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<BpmProcessInstanceStatusEvent> {
    @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());
    }
}