package cn.iocoder.yudao.module.crm.service.cancellation.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.cancellation.CrmCancellationService;
|
import jakarta.annotation.Resource;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.stereotype.Component;
|
|
/**
|
* CRM 销户申请审批状态监听器
|
*
|
* 监听 BPM 审批结果,回写销户申请审核状态,使销户审批统一在「协同办公 - 我的流程」中流转。
|
*/
|
@Component
|
@Slf4j
|
public class CrmCancellationStatusListener extends BpmProcessInstanceStatusEventListener {
|
|
private static final String PROCESS_DEFINITION_KEY = "cancellation_approve";
|
|
@Resource
|
private CrmCancellationService cancellationService;
|
|
@Override
|
protected String getProcessDefinitionKey() {
|
return PROCESS_DEFINITION_KEY;
|
}
|
|
@Override
|
protected void onEvent(BpmProcessInstanceStatusEvent event) {
|
Long cancellationId;
|
try {
|
cancellationId = Long.parseLong(event.getBusinessKey());
|
} catch (NumberFormatException e) {
|
log.warn("[onEvent] businessKey({}) 不是有效的销户申请编号", event.getBusinessKey());
|
return;
|
}
|
log.info("[onEvent] 收到销户申请审批事件,cancellationId={}, status={}", cancellationId, event.getStatus());
|
try {
|
cancellationService.updateCancellationAuditStatus(cancellationId, event.getStatus(), event.getReason());
|
} catch (Exception e) {
|
log.error("[onEvent] 回写销户申请审批状态失败,cancellationId={}", cancellationId, e);
|
}
|
}
|
|
}
|