3 天以前 b852254d90e7d1955db31db154193ec8ee84d8b3
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
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.mes.service.wm.stocktaking.task.MesWmStockTakingTaskService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
 
/**
 * MES 盘点结果审批 BPM 状态监听器
 *
 * 监听盘点结果审批流程实例状态变更事件:审批通过后解冻库存并自动核销盘点差异置为已完成;
 * 驳回后任务保持盘点中可修改实盘重新提交;取消则解冻并置为已取消
 */
@Component
@Slf4j
public class MesWmStockTakingTaskResultStatusListener
        extends cn.iocoder.yudao.module.bpm.api.event.BpmProcessInstanceStatusEventListener {
 
    @Resource
    private MesWmStockTakingTaskService stockTakingTaskService;
 
    @Override
    protected String getProcessDefinitionKey() {
        return MesWmStockTakingTaskService.APPROVE_CATEGORY_CODE;
    }
 
    @Override
    protected void onEvent(BpmProcessInstanceStatusEvent event) {
        Long id;
        try {
            id = Long.parseLong(event.getBusinessKey());
        } catch (NumberFormatException e) {
            log.warn("[onEvent] businessKey({}) 不是有效的盘点任务编号", event.getBusinessKey());
            return;
        }
        log.info("[onEvent] 收到盘点结果审批事件,stockTakingTaskId={}, status={}", id, event.getStatus());
        try {
            stockTakingTaskService.updateStockTakingTaskResultAuditStatus(id, event.getStatus());
            log.info("[onEvent] 盘点任务({}) 结果审批状态更新完成", id);
        } catch (Exception e) {
            log.error("[onEvent] 更新盘点任务结果审批状态失败,stockTakingTaskId={}", id, e);
        }
    }
 
}