2026-07-02 6e312c64c056acf479a6dd8393dd42a80b69b7d4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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<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 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());
    }
 
}