liu
2026-10-23 5421b8af862890dcf187c2ad5ece55423959ba85
yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/service/refund/listener/CrmRefundStatusListener.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,46 @@
package cn.iocoder.yudao.module.crm.service.refund.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.refund.CrmRefundService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
 * CRM é€€è´¹å•审批状态监听器
 *
 * ç›‘听 BPM å®¡æ‰¹ç»“果,回写退费单审核状态,使退费审批统一在「协同办公 - æˆ‘的流程」中流转。
 */
@Component
@Slf4j
public class CrmRefundStatusListener extends BpmProcessInstanceStatusEventListener {
    private static final String PROCESS_DEFINITION_KEY = "refund_approve";
    @Resource
    private CrmRefundService refundService;
    @Override
    protected String getProcessDefinitionKey() {
        return PROCESS_DEFINITION_KEY;
    }
    @Override
    protected void onEvent(BpmProcessInstanceStatusEvent event) {
        Long refundId;
        try {
            refundId = Long.parseLong(event.getBusinessKey());
        } catch (NumberFormatException e) {
            log.warn("[onEvent] businessKey({}) ä¸æ˜¯æœ‰æ•ˆçš„退费单编号", event.getBusinessKey());
            return;
        }
        log.info("[onEvent] æ”¶åˆ°é€€è´¹å•审批事件,refundId={}, status={}", refundId, event.getStatus());
        try {
            refundService.updateRefundAuditStatus(refundId, event.getStatus(), event.getReason());
        } catch (Exception e) {
            log.error("[onEvent] å›žå†™é€€è´¹å•审批状态失败,refundId={}", refundId, e);
        }
    }
}