10 天以前 8c14b50773a1e582b652c03f5a63bb2233d069b8
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
package cn.iocoder.yudao.module.mes.service.wms.approval.listener;
 
import cn.iocoder.yudao.module.bpm.api.event.BpmProcessInstanceStatusEvent;
import cn.iocoder.yudao.module.mes.service.wms.approval.WmsApprovalService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
 
/**
 * WMS 调拨单审批状态监听器
 *
 * 监听BPM审批结果,更新调拨单状态
 */
@Component
@Slf4j
public class WmsTransferStatusListener implements ApplicationListener<BpmProcessInstanceStatusEvent> {
 
    @Resource
    private WmsApprovalService approvalService;
 
    @Override
    public void onApplicationEvent(BpmProcessInstanceStatusEvent event) {
        // 通过 businessKey 查询调拨单
        Long orderId;
        try {
            orderId = Long.parseLong(event.getBusinessKey());
        } catch (NumberFormatException e) {
            return; // businessKey 不是数字,忽略
        }
 
        log.info("[onApplicationEvent] 收到BPM审批事件,businessKey={}, status={}",
                event.getBusinessKey(), event.getStatus());
 
        // 调用审批服务更新状态
        try {
            approvalService.updateAuditStatus(orderId, "TRANSFER", event.getStatus());
        } catch (Exception e) {
            log.error("[onApplicationEvent] 更新调拨单审批状态失败,orderId={}", orderId, e);
        }
    }
 
}