liu
2026-10-23 5421b8af862890dcf187c2ad5ece55423959ba85
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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);
        }
    }
 
}