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 WmsInboundStatusListener 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, "INBOUND", event.getStatus());
|
} catch (Exception e) {
|
log.error("[onApplicationEvent] 更新入库单审批状态失败,orderId={}", orderId, e);
|
}
|
}
|
|
}
|