CRM: 完善回款审批逻辑

This commit is contained in:
puhui999 2024-02-23 14:37:03 +08:00
parent eddd0a8801
commit be2431b73b
6 changed files with 40 additions and 46 deletions

View File

@ -13,7 +13,7 @@ public interface ErrorCodeConstants {
ErrorCode CONTRACT_NOT_EXISTS = new ErrorCode(1_020_000_000, "合同不存在");
ErrorCode CONTRACT_UPDATE_FAIL_NOT_DRAFT = new ErrorCode(1_020_000_001, "合同更新失败,原因:合同不是草稿状态");
ErrorCode CONTRACT_SUBMIT_FAIL_NOT_DRAFT = new ErrorCode(1_020_000_002, "合同提交审核失败,原因:合同没处在未提交状态");
ErrorCode CONTRACT_UPDATE_AUDIT_STATUS_FAIL_NOT_PROCESS = new ErrorCode(1_020_000_003, "更新合同审核状态失败,原因:合同不是处理中状态");
ErrorCode CONTRACT_UPDATE_AUDIT_STATUS_FAIL_NOT_PROCESS = new ErrorCode(1_020_000_003, "更新合同审核状态失败,原因:合同不是审核中状态");
// ========== 线索管理 1-020-001-000 ==========
ErrorCode CLUE_NOT_EXISTS = new ErrorCode(1_020_001_000, "线索不存在");
@ -36,7 +36,7 @@ public interface ErrorCodeConstants {
ErrorCode RECEIVABLE_UPDATE_FAIL_EDITING_PROHIBITED = new ErrorCode(1_020_004_001, "更新回款失败,原因:禁止编辑");
ErrorCode RECEIVABLE_DELETE_FAIL = new ErrorCode(1_020_004_002, "删除回款失败,原因: 被回款计划所使用,不允许删除");
ErrorCode RECEIVABLE_SUBMIT_FAIL_NOT_DRAFT = new ErrorCode(1_020_004_003, "回款提交审核失败,原因:回款没处在未提交状态");
ErrorCode RECEIVABLE_UPDATE_AUDIT_STATUS_FAIL_NOT_PROCESS = new ErrorCode(1_020_004_004, "更新回款审核状态失败,原因:回款不是审核中状态");
// ========== 回款计划 1-020-005-000 ==========
ErrorCode RECEIVABLE_PLAN_NOT_EXISTS = new ErrorCode(1_020_005_000, "回款计划不存在");

View File

@ -10,7 +10,6 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
import cn.iocoder.yudao.module.bpm.api.task.BpmProcessInstanceApi;
import cn.iocoder.yudao.module.bpm.api.task.dto.BpmProcessInstanceCreateReqDTO;
import cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceResultEnum;
import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractPageReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractSaveReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractTransferReqVO;
@ -48,6 +47,7 @@ import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionU
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*;
import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.*;
import static cn.iocoder.yudao.module.crm.util.CrmAuditStatusUtils.convertBpmResultToAuditStatus;
/**
* CRM 合同 Service 实现类
@ -303,10 +303,7 @@ public class CrmContractServiceImpl implements CrmContractService {
}
// 2. 更新合同审批结果
Integer auditStatus = BpmProcessInstanceResultEnum.APPROVE.getResult().equals(bpmResult) ? CrmAuditStatusEnum.APPROVE.getStatus()
: BpmProcessInstanceResultEnum.REJECT.getResult().equals(bpmResult) ? CrmAuditStatusEnum.REJECT.getStatus()
: BpmProcessInstanceResultEnum.CANCEL.getResult();
Assert.notNull(auditStatus, "BPM 审批结果({}) 转换失败", bpmResult);
Integer auditStatus = convertBpmResultToAuditStatus(bpmResult);
contractMapper.updateById(new CrmContractDO().setId(id).setAuditStatus(auditStatus));
}

View File

@ -1,7 +1,6 @@
package cn.iocoder.yudao.module.crm.service.receivable;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.bpm.api.listener.dto.BpmResultListenerRespDTO;
import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.receivable.CrmReceivablePageReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.receivable.CrmReceivableSaveReqVO;
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
@ -36,9 +35,10 @@ public interface CrmReceivableService {
/**
* 更新回款流程审批结果
*
* @param event 审批结果
* @param id 回款编号
* @param bpmResult BPM 审批结果
*/
void updateReceivableAuditStatus(BpmResultListenerRespDTO event);
void updateReceivableAuditStatus(Long id, Integer bpmResult);
/**
* 删除回款

View File

@ -8,7 +8,6 @@ import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
import cn.iocoder.yudao.module.bpm.api.listener.dto.BpmResultListenerRespDTO;
import cn.iocoder.yudao.module.bpm.api.task.BpmProcessInstanceApi;
import cn.iocoder.yudao.module.bpm.api.task.dto.BpmProcessInstanceCreateReqDTO;
import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.receivable.CrmReceivablePageReqVO;
@ -31,6 +30,7 @@ import com.mzt.logapi.context.LogRecordContext;
import com.mzt.logapi.service.impl.DiffParseFunction;
import com.mzt.logapi.starter.annotation.LogRecord;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
@ -42,8 +42,7 @@ import java.util.Objects;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*;
import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.*;
import static cn.iocoder.yudao.module.crm.util.CrmAuditStatusUtils.convertAuditStatus;
import static cn.iocoder.yudao.module.crm.util.CrmAuditStatusUtils.isEndResult;
import static cn.iocoder.yudao.module.crm.util.CrmAuditStatusUtils.convertBpmResultToAuditStatus;
/**
* CRM 回款 Service 实现类
@ -52,6 +51,7 @@ import static cn.iocoder.yudao.module.crm.util.CrmAuditStatusUtils.isEndResult;
*/
@Service
@Validated
@Slf4j
public class CrmReceivableServiceImpl implements CrmReceivableService {
/**
@ -142,15 +142,19 @@ public class CrmReceivableServiceImpl implements CrmReceivableService {
}
@Override
public void updateReceivableAuditStatus(BpmResultListenerRespDTO event) {
// 判断下状态是否符合预期
if (!isEndResult(event.getResult())) {
return;
public void updateReceivableAuditStatus(Long id, Integer bpmResult) {
// 1.1 校验存在
CrmReceivableDO receivable = validateReceivableExists(id);
// 1.2 只有审批中可以更新审批结果
if (ObjUtil.notEqual(receivable.getAuditStatus(), CrmAuditStatusEnum.PROCESS.getStatus())) {
log.error("[updateReceivableAuditStatus][receivable({}) 不处于审批中,无法更新审批结果({})]",
receivable.getId(), bpmResult);
throw exception(RECEIVABLE_UPDATE_AUDIT_STATUS_FAIL_NOT_PROCESS);
}
convertAuditStatus(event);
// 更新回款审批状态
receivableMapper.updateById(new CrmReceivableDO().setId(Long.parseLong(event.getBusinessKey()))
.setAuditStatus(event.getResult()));
// 2. 更新回款审批状态
Integer auditStatus = convertBpmResultToAuditStatus(bpmResult);
receivableMapper.updateById(new CrmReceivableDO().setId(id).setAuditStatus(auditStatus));
}
// TODO @liuhongfeng缺一个取消回款的接口只有草稿审批中可以取消CrmAuditStatusEnum

View File

@ -1,21 +1,19 @@
package cn.iocoder.yudao.module.crm.service.receivable.listener;
import cn.iocoder.yudao.module.bpm.api.listener.BpmResultListenerApi;
import cn.iocoder.yudao.module.bpm.api.listener.dto.BpmResultListenerRespDTO;
import cn.iocoder.yudao.module.bpm.event.BpmProcessInstanceResultEvent;
import cn.iocoder.yudao.module.bpm.event.BpmProcessInstanceResultEventListener;
import cn.iocoder.yudao.module.crm.service.receivable.CrmReceivableService;
import cn.iocoder.yudao.module.crm.service.receivable.CrmReceivableServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;
// TODO @芋艿后续改成支持 RPC
/**
* 回款审批的结果的监听器实现类
*
* @author HUIHUI
*/
@Component
public class CrmReceivableResultListener implements BpmResultListenerApi {
public class CrmReceivableResultListener extends BpmProcessInstanceResultEventListener {
@Resource
private CrmReceivableService receivableService;
@ -26,8 +24,8 @@ public class CrmReceivableResultListener implements BpmResultListenerApi {
}
@Override
public void onEvent(BpmResultListenerRespDTO event) {
receivableService.updateReceivableAuditStatus(event);
public void onEvent(BpmProcessInstanceResultEvent event) {
receivableService.updateReceivableAuditStatus(Long.parseLong(event.getBusinessKey()), event.getResult());
}
}

View File

@ -1,8 +1,7 @@
package cn.iocoder.yudao.module.crm.util;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.lang.Assert;
import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
import cn.iocoder.yudao.module.bpm.api.listener.dto.BpmResultListenerRespDTO;
import cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceResultEnum;
import cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum;
@ -14,31 +13,27 @@ import cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum;
public class CrmAuditStatusUtils {
/**
* 流程审批状态转换
* BPM 审批结果转换
*
* @param event 业务流程实例的结果
* @param bpmResult BPM 审批结果
*/
public static void convertAuditStatus(BpmResultListenerRespDTO event) {
// 状态转换
if (ObjUtil.equal(event.getResult(), BpmProcessInstanceResultEnum.APPROVE.getResult())) {
event.setResult(CrmAuditStatusEnum.APPROVE.getStatus());
}
if (ObjUtil.equal(event.getResult(), BpmProcessInstanceResultEnum.REJECT.getResult())) {
event.setResult(CrmAuditStatusEnum.REJECT.getStatus());
}
if (ObjUtil.equal(event.getResult(), BpmProcessInstanceResultEnum.CANCEL.getResult())) {
event.setResult(CrmAuditStatusEnum.CANCEL.getStatus());
}
public static Integer convertBpmResultToAuditStatus(Integer bpmResult) {
Assert.isTrue(isEndResult(bpmResult), "BPM 审批结果({}) 转换失败, 流程状态不是最终结果", bpmResult);
Integer auditStatus = BpmProcessInstanceResultEnum.APPROVE.getResult().equals(bpmResult) ? CrmAuditStatusEnum.APPROVE.getStatus()
: BpmProcessInstanceResultEnum.REJECT.getResult().equals(bpmResult) ? CrmAuditStatusEnum.REJECT.getStatus()
: BpmProcessInstanceResultEnum.CANCEL.getResult();
Assert.notNull(auditStatus, "BPM 审批结果({}) 转换失败", bpmResult);
return auditStatus;
}
/**
* 判断该结果是否处于 End 最终结果
*
* @param result 结果
* @param bpmResult BPM 审批结果
* @return 是否
*/
public static boolean isEndResult(Integer result) {
return ObjectUtils.equalsAny(result, BpmProcessInstanceResultEnum.APPROVE.getResult(),
public static boolean isEndResult(Integer bpmResult) {
return ObjectUtils.equalsAny(bpmResult, BpmProcessInstanceResultEnum.APPROVE.getResult(),
BpmProcessInstanceResultEnum.REJECT.getResult(), BpmProcessInstanceResultEnum.CANCEL.getResult());
}