package cn.iocoder.yudao.module.mes.service.wm.stocktaking.task.listener;
|
|
import cn.iocoder.yudao.module.bpm.api.event.BpmProcessInstanceStatusEvent;
|
import cn.iocoder.yudao.module.bpm.api.event.BpmProcessInstanceStatusEventListener;
|
import cn.iocoder.yudao.module.mes.service.wm.stocktaking.task.MesWmStockTakingTaskService;
|
import jakarta.annotation.Resource;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.stereotype.Component;
|
|
/**
|
* MES 盘点结果审批状态监听器
|
*
|
* 审批对象是盘点任务下的盘点结果,业务上以盘点任务记录审批状态,
|
* 因此 businessKey 为盘点任务编号,回写的也是该任务。
|
*/
|
@Component
|
@Slf4j
|
public class MesWmStockTakingTaskStatusListener extends BpmProcessInstanceStatusEventListener {
|
|
private static final String PROCESS_DEFINITION_KEY = "stock_taking_result_approve";
|
|
@Resource
|
private MesWmStockTakingTaskService stockTakingTaskService;
|
|
@Override
|
protected String getProcessDefinitionKey() {
|
return PROCESS_DEFINITION_KEY;
|
}
|
|
@Override
|
protected void onEvent(BpmProcessInstanceStatusEvent event) {
|
Long taskId;
|
try {
|
taskId = Long.parseLong(event.getBusinessKey());
|
} catch (NumberFormatException e) {
|
log.warn("[onEvent] businessKey({}) 不是有效的盘点任务编号", event.getBusinessKey());
|
return;
|
}
|
log.info("[onEvent] 收到盘点结果审批事件,taskId={}, status={}", taskId, event.getStatus());
|
try {
|
stockTakingTaskService.updateStockTakingResultAuditStatus(taskId, event.getStatus(), event.getReason());
|
} catch (Exception e) {
|
log.error("[onEvent] 回写盘点结果审批状态失败,taskId={}", taskId, e);
|
}
|
}
|
|
}
|