| | |
| | | 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; |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Component |
| | | @Slf4j |
| | | public class WmsOutboundStatusListener implements ApplicationListener<BpmProcessInstanceStatusEvent> { |
| | | public class WmsOutboundStatusListener extends cn.iocoder.yudao.module.bpm.api.event.BpmProcessInstanceStatusEventListener { |
| | | |
| | | /** |
| | | * 销售出库审批流程定义 Key |
| | | */ |
| | | private static final String PROCESS_DEFINITION_KEY = "wms_outbound_approve"; |
| | | |
| | | @Resource |
| | | private WmsApprovalService approvalService; |
| | | |
| | | @Override |
| | | public void onApplicationEvent(BpmProcessInstanceStatusEvent event) { |
| | | // 通过 businessKey 查询出库单 |
| | | protected String getProcessDefinitionKey() { |
| | | return PROCESS_DEFINITION_KEY; |
| | | } |
| | | |
| | | @Override |
| | | protected void onEvent(BpmProcessInstanceStatusEvent event) { |
| | | Long orderId; |
| | | try { |
| | | orderId = Long.parseLong(event.getBusinessKey()); |
| | | } catch (NumberFormatException e) { |
| | | return; // businessKey 不是数字,忽略 |
| | | log.warn("[onEvent] businessKey({}) 不是有效的数字", event.getBusinessKey()); |
| | | return; |
| | | } |
| | | |
| | | log.info("[onApplicationEvent] 收到BPM审批事件,businessKey={}, status={}", |
| | | log.info("[onEvent] 收到BPM审批事件,businessKey={}, status={}", |
| | | event.getBusinessKey(), event.getStatus()); |
| | | |
| | | // 调用审批服务更新状态 |
| | | try { |
| | | approvalService.updateAuditStatus(orderId, "OUTBOUND", event.getStatus()); |
| | | } catch (Exception e) { |
| | | log.error("[onApplicationEvent] 更新出库单审批状态失败,orderId={}", orderId, e); |
| | | log.error("[onEvent] 更新出库单审批状态失败,orderId={}", orderId, e); |
| | | } |
| | | } |
| | | |