tuqin
2026-11-03 9494075e6d9d2a4b2b884b4ed740dee0c434734c
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
package cn.iocoder.yudao.module.trade.service.domestic.listener;
 
import cn.iocoder.yudao.module.bpm.api.event.BpmProcessInstanceStatusEvent;
import cn.iocoder.yudao.module.trade.dal.dataobject.domestic.TradeDomesticOrderDO;
import cn.iocoder.yudao.module.trade.dal.mysql.domestic.TradeDomesticOrderMapper;
import cn.iocoder.yudao.module.trade.enums.TradeDomesticOrderStatusEnum;
import cn.iocoder.yudao.module.trade.service.domestic.TradeDomesticOrderService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
 
/**
 * 内贸订单审批的结果监听器
 *
 * 通过 businessKey(内贸订单ID)匹配。
 *
 * @author mom
 */
@Component
@Slf4j
public class TradeDomesticOrderStatusListener implements ApplicationListener<BpmProcessInstanceStatusEvent> {
 
    @Resource
    private TradeDomesticOrderService orderService;
    @Resource
    private TradeDomesticOrderMapper orderMapper;
 
    @Override
    public void onApplicationEvent(BpmProcessInstanceStatusEvent event) {
        Long orderId;
        try {
            orderId = Long.parseLong(event.getBusinessKey());
        } catch (NumberFormatException e) {
            return; // businessKey 不是数字,忽略
        }
 
        TradeDomesticOrderDO order = orderMapper.selectById(orderId);
        if (order == null) {
            return; // 不是内贸订单,忽略
        }
        if (!TradeDomesticOrderStatusEnum.APPROVING.getStatus().equals(order.getStatus())) {
            log.warn("[onApplicationEvent] 内贸订单({}) 不处于审批中状态,当前状态: {}", orderId, order.getStatus());
            return;
        }
 
        log.info("[onApplicationEvent] 内贸订单({}) 审批状态更新: {}", orderId, event.getStatus());
        orderService.updateOrderAuditStatus(orderId, event.getStatus());
    }
 
}