| | |
| | | import cn.iocoder.yudao.module.bpm.api.event.BpmProcessInstanceStatusEvent; |
| | | import cn.iocoder.yudao.module.bpm.api.event.BpmProcessInstanceStatusEventListener; |
| | | import cn.iocoder.yudao.module.crm.service.invoice.CrmInvoiceService; |
| | | import cn.iocoder.yudao.module.crm.service.invoice.CrmInvoiceServiceImpl; |
| | | import jakarta.annotation.Resource; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | /** |
| | | * 开票审批的结果的监听器实现类 |
| | | * CRM 开票审批状态监听器 |
| | | * |
| | | * @author 超级管理员 |
| | | * 监听 BPM 审批结果,回写开票审核状态,使开票审批统一在「协同办公 - 我的流程」中流转。 |
| | | */ |
| | | @Component |
| | | @Slf4j |
| | | public class CrmInvoiceStatusListener extends BpmProcessInstanceStatusEventListener { |
| | | |
| | | private static final String PROCESS_DEFINITION_KEY = "crm-invoice-audit"; |
| | | |
| | | @Resource |
| | | private CrmInvoiceService invoiceService; |
| | | |
| | | @Override |
| | | public String getProcessDefinitionKey() { |
| | | return CrmInvoiceServiceImpl.BPM_PROCESS_DEFINITION_KEY; |
| | | protected String getProcessDefinitionKey() { |
| | | return PROCESS_DEFINITION_KEY; |
| | | } |
| | | |
| | | @Override |
| | | public void onEvent(BpmProcessInstanceStatusEvent event) { |
| | | invoiceService.updateInvoiceAuditStatus(Long.parseLong(event.getBusinessKey()), event.getStatus()); |
| | | protected void onEvent(BpmProcessInstanceStatusEvent event) { |
| | | Long invoiceId; |
| | | try { |
| | | invoiceId = Long.parseLong(event.getBusinessKey()); |
| | | } catch (NumberFormatException e) { |
| | | log.warn("[onEvent] businessKey({}) 不是有效的开票编号", event.getBusinessKey()); |
| | | return; |
| | | } |
| | | log.info("[onEvent] 收到开票审批事件,invoiceId={}, status={}", invoiceId, event.getStatus()); |
| | | try { |
| | | invoiceService.updateInvoiceAuditStatus(invoiceId, event.getStatus(), event.getReason()); |
| | | } catch (Exception e) { |
| | | log.error("[onEvent] 回写开票审批状态失败,invoiceId={}", invoiceId, e); |
| | | } |
| | | } |
| | | |
| | | } |