| | |
| | | import cn.iocoder.yudao.module.bpm.api.event.BpmProcessInstanceStatusEvent; |
| | | import cn.iocoder.yudao.module.bpm.api.event.BpmProcessInstanceStatusEventListener; |
| | | import cn.iocoder.yudao.module.erp.service.sale.ErpSaleOrderService; |
| | | import cn.iocoder.yudao.module.erp.service.sale.ErpSaleOrderServiceImpl; |
| | | import jakarta.annotation.Resource; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | /** |
| | | * 销售订单审批的结果的监听器实现类 |
| | | * 销售订单审批状态监听器 |
| | | * |
| | | * @author 芋道源码 |
| | | * 监听 BPM 流程实例状态变更事件,更新销售订单的审批状态(协同办公审批后回写) |
| | | * |
| | | * @author 超级管理员 |
| | | */ |
| | | @Component |
| | | @Slf4j |
| | | public class ErpSaleOrderStatusListener extends BpmProcessInstanceStatusEventListener { |
| | | |
| | | /** |
| | | * 销售订单审批流程定义 Key |
| | | */ |
| | | private static final String PROCESS_DEFINITION_KEY = "sale_order_approve"; |
| | | |
| | | @Resource |
| | | private ErpSaleOrderService saleOrderService; |
| | | |
| | | @Override |
| | | public String getProcessDefinitionKey() { |
| | | return ErpSaleOrderServiceImpl.BPM_PROCESS_DEFINITION_KEY; |
| | | protected String getProcessDefinitionKey() { |
| | | return PROCESS_DEFINITION_KEY; |
| | | } |
| | | |
| | | @Override |
| | | protected void onEvent(BpmProcessInstanceStatusEvent event) { |
| | | saleOrderService.updateSaleOrderAuditStatus(Long.parseLong(event.getBusinessKey()), event.getStatus()); |
| | | Long orderId; |
| | | try { |
| | | orderId = Long.parseLong(event.getBusinessKey()); |
| | | } catch (NumberFormatException e) { |
| | | log.warn("[onEvent] businessKey({}) 不是有效的销售订单编号", event.getBusinessKey()); |
| | | return; |
| | | } |
| | | |
| | | log.info("[onEvent] 收到BPM审批事件,orderId={}, status={}", orderId, event.getStatus()); |
| | | |
| | | try { |
| | | saleOrderService.updateSaleOrderAuditStatus(orderId, event.getStatus()); |
| | | log.info("[onEvent] 销售订单({}) 审批状态更新完成", orderId); |
| | | } catch (Exception e) { |
| | | log.error("[onEvent] 更新销售订单审批状态失败,orderId={}", orderId, e); |
| | | } |
| | | } |
| | | |
| | | } |