| | |
| | | package cn.iocoder.yudao.module.mes.service.qc.seedquality.listener; |
| | | |
| | | import cn.iocoder.yudao.module.bpm.api.event.BpmProcessInstanceStatusEvent; |
| | | import cn.iocoder.yudao.module.bpm.api.event.BpmProcessInstanceStatusEventListener; |
| | | import cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceStatusEnum; |
| | | import cn.iocoder.yudao.module.mes.service.qc.seedquality.MesQcSeedQualityService; |
| | | import jakarta.annotation.Resource; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.context.ApplicationListener; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.Set; |
| | | |
| | | /** |
| | | * 种子质检本线领导审批状态监听器 |
| | | * 种子质检部门领导审批状态监听器 |
| | | * |
| | | * <p>流程定义 key:mes_seed_quality_line_approve;businessKey 格式:{质检线}#{生产批次号}。 |
| | | * 审批通过后本线进入复检,驳回后本线重新初检。 |
| | | * <p>加工部、销售部各使用独立流程定义;businessKey 格式:{质检线}#{生产批次号}。 |
| | | * 审批通过后本线进入公司质检待审,驳回后本线重新初检。 |
| | | */ |
| | | @Component |
| | | @Slf4j |
| | | public class MesQcSeedLineStatusListener extends BpmProcessInstanceStatusEventListener { |
| | | public class MesQcSeedLineStatusListener implements ApplicationListener<BpmProcessInstanceStatusEvent> { |
| | | |
| | | private static final String BPM_PROCESS_DEFINITION_KEY = "mes_seed_quality_line_approve"; |
| | | /** 加工部领导审批流程定义标识 */ |
| | | private static final String LINE_PROCESS_KEY = "mes_seed_quality_line_approve"; |
| | | /** 销售部领导审批流程定义标识 */ |
| | | private static final String SALES_LINE_PROCESS_KEY = "mes_seed_quality_sales_line_approve"; |
| | | private static final Set<String> PROCESS_KEYS = Set.of(LINE_PROCESS_KEY, SALES_LINE_PROCESS_KEY); |
| | | |
| | | @Resource |
| | | private MesQcSeedQualityService seedQualityService; |
| | | |
| | | @Override |
| | | protected String getProcessDefinitionKey() { |
| | | return BPM_PROCESS_DEFINITION_KEY; |
| | | } |
| | | |
| | | @Override |
| | | protected void onEvent(BpmProcessInstanceStatusEvent event) { |
| | | public void onApplicationEvent(BpmProcessInstanceStatusEvent event) { |
| | | if (!PROCESS_KEYS.contains(event.getProcessDefinitionKey())) { |
| | | return; |
| | | } |
| | | if (!BpmProcessInstanceStatusEnum.isProcessEndStatus(event.getStatus()) |
| | | || BpmProcessInstanceStatusEnum.CANCEL.getStatus().equals(event.getStatus())) { |
| | | return; |
| | |
| | | String businessKey = event.getBusinessKey(); |
| | | int index = businessKey == null ? -1 : businessKey.indexOf('#'); |
| | | if (index <= 0 || index == businessKey.length() - 1) { |
| | | log.warn("[onEvent][本线审批 businessKey({}) 格式无效,应为 质检线#批次号]", businessKey); |
| | | log.warn("[onApplicationEvent][部门审批 businessKey({}) 格式无效,应为 质检线#批次号]", businessKey); |
| | | return; |
| | | } |
| | | Integer qcLine; |
| | | try { |
| | | qcLine = Integer.valueOf(businessKey.substring(0, index)); |
| | | } catch (NumberFormatException ex) { |
| | | log.warn("[onEvent][本线审批 businessKey({}) 质检线无效]", businessKey); |
| | | log.warn("[onApplicationEvent][部门审批 businessKey({}) 质检线无效]", businessKey); |
| | | return; |
| | | } |
| | | String batchCode = businessKey.substring(index + 1); |
| | | boolean approved = BpmProcessInstanceStatusEnum.APPROVE.getStatus().equals(event.getStatus()); |
| | | log.info("[onEvent][本线审批完成,批次={} 质检线={} 结果={}]", batchCode, qcLine, event.getStatus()); |
| | | log.info("[onApplicationEvent][部门审批完成,批次={} 质检线={} 结果={}]", batchCode, qcLine, event.getStatus()); |
| | | seedQualityService.handleLineProcessResult(event.getId(), qcLine, batchCode, approved, event.getReason()); |
| | | } |
| | | } |