gaoluyang
3 天以前 8c65f898ed6e5b0c7a94c792c4562f6ec831dccd
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
package cn.iocoder.yudao.module.crm.service.receivable.listener;
 
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.receivable.CrmReceivableService;
import cn.iocoder.yudao.module.crm.service.receivable.CrmReceivableServiceImpl;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
 
/**
 * 回款审批结果监听器
 *
 * 流程审批通过:回款状态更新为审核通过,并回写回款计划已回款金额;
 * 流程驳回/取消:仅更新回款状态,不回写金额。
 *
 * @author 超级管理员
 */
@Component
@Slf4j
public class CrmReceivableStatusListener extends BpmProcessInstanceStatusEventListener {
 
    @Resource
    private CrmReceivableService receivableService;
 
    @Override
    protected String getProcessDefinitionKey() {
        return CrmReceivableServiceImpl.BPM_PROCESS_DEFINITION_KEY;
    }
 
    @Override
    protected void onEvent(BpmProcessInstanceStatusEvent event) {
        Long receivableId;
        try {
            receivableId = Long.parseLong(event.getBusinessKey());
        } catch (NumberFormatException | NullPointerException ex) {
            log.warn("[onEvent][回款审批事件的 businessKey({}) 不是回款编号,忽略]", event.getBusinessKey());
            return;
        }
        receivableService.updateReceivableAuditStatus(receivableId, event.getStatus());
    }
 
}