| | |
| | | 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.purchase.ErpPurchaseOrderService; |
| | | import cn.iocoder.yudao.module.erp.service.purchase.ErpPurchaseOrderServiceImpl; |
| | | import jakarta.annotation.Resource; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | /** |
| | | * 采购订单审批的结果的监听器实现类 |
| | | * 采购订单审批状态监听器 |
| | | * |
| | | * @author 芋道源码 |
| | | * 监听 BPM 流程实例状态变更事件,更新采购订单的审批状态(协同办公审批后回写) |
| | | * |
| | | * @author 超级管理员 |
| | | */ |
| | | @Component |
| | | @Slf4j |
| | | public class ErpPurchaseOrderStatusListener extends BpmProcessInstanceStatusEventListener { |
| | | |
| | | /** |
| | | * 采购订单审批流程定义 Key |
| | | */ |
| | | private static final String PROCESS_DEFINITION_KEY = "purchase_order_approve"; |
| | | |
| | | @Resource |
| | | private ErpPurchaseOrderService purchaseOrderService; |
| | | |
| | | @Override |
| | | public String getProcessDefinitionKey() { |
| | | return ErpPurchaseOrderServiceImpl.BPM_PROCESS_DEFINITION_KEY; |
| | | protected String getProcessDefinitionKey() { |
| | | return PROCESS_DEFINITION_KEY; |
| | | } |
| | | |
| | | @Override |
| | | protected void onEvent(BpmProcessInstanceStatusEvent event) { |
| | | purchaseOrderService.updatePurchaseOrderAuditStatus(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 { |
| | | purchaseOrderService.updatePurchaseOrderAuditStatus(orderId, event.getStatus()); |
| | | log.info("[onEvent] 采购订单({}) 审批状态更新完成", orderId); |
| | | } catch (Exception e) { |
| | | log.error("[onEvent] 更新采购订单审批状态失败,orderId={}", orderId, e); |
| | | } |
| | | } |
| | | |
| | | } |