Commit be2431b73b48bbf040d86039106a3af536a3e805
1 parent
eddd0a88
CRM: 完善回款审批逻辑
Showing
6 changed files
with
40 additions
and
46 deletions
yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/ErrorCodeConstants.java
| ... | ... | @@ -13,7 +13,7 @@ public interface ErrorCodeConstants { |
| 13 | 13 | ErrorCode CONTRACT_NOT_EXISTS = new ErrorCode(1_020_000_000, "合同不存在"); |
| 14 | 14 | ErrorCode CONTRACT_UPDATE_FAIL_NOT_DRAFT = new ErrorCode(1_020_000_001, "合同更新失败,原因:合同不是草稿状态"); |
| 15 | 15 | ErrorCode CONTRACT_SUBMIT_FAIL_NOT_DRAFT = new ErrorCode(1_020_000_002, "合同提交审核失败,原因:合同没处在未提交状态"); |
| 16 | - ErrorCode CONTRACT_UPDATE_AUDIT_STATUS_FAIL_NOT_PROCESS = new ErrorCode(1_020_000_003, "更新合同审核状态失败,原因:合同不是处理中状态"); | |
| 16 | + ErrorCode CONTRACT_UPDATE_AUDIT_STATUS_FAIL_NOT_PROCESS = new ErrorCode(1_020_000_003, "更新合同审核状态失败,原因:合同不是审核中状态"); | |
| 17 | 17 | |
| 18 | 18 | // ========== 线索管理 1-020-001-000 ========== |
| 19 | 19 | ErrorCode CLUE_NOT_EXISTS = new ErrorCode(1_020_001_000, "线索不存在"); |
| ... | ... | @@ -36,7 +36,7 @@ public interface ErrorCodeConstants { |
| 36 | 36 | ErrorCode RECEIVABLE_UPDATE_FAIL_EDITING_PROHIBITED = new ErrorCode(1_020_004_001, "更新回款失败,原因:禁止编辑"); |
| 37 | 37 | ErrorCode RECEIVABLE_DELETE_FAIL = new ErrorCode(1_020_004_002, "删除回款失败,原因: 被回款计划所使用,不允许删除"); |
| 38 | 38 | ErrorCode RECEIVABLE_SUBMIT_FAIL_NOT_DRAFT = new ErrorCode(1_020_004_003, "回款提交审核失败,原因:回款没处在未提交状态"); |
| 39 | - | |
| 39 | + ErrorCode RECEIVABLE_UPDATE_AUDIT_STATUS_FAIL_NOT_PROCESS = new ErrorCode(1_020_004_004, "更新回款审核状态失败,原因:回款不是审核中状态"); | |
| 40 | 40 | |
| 41 | 41 | // ========== 回款计划 1-020-005-000 ========== |
| 42 | 42 | ErrorCode RECEIVABLE_PLAN_NOT_EXISTS = new ErrorCode(1_020_005_000, "回款计划不存在"); | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/CrmContractServiceImpl.java
| ... | ... | @@ -10,7 +10,6 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 10 | 10 | import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; |
| 11 | 11 | import cn.iocoder.yudao.module.bpm.api.task.BpmProcessInstanceApi; |
| 12 | 12 | import cn.iocoder.yudao.module.bpm.api.task.dto.BpmProcessInstanceCreateReqDTO; |
| 13 | -import cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceResultEnum; | |
| 14 | 13 | import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractPageReqVO; |
| 15 | 14 | import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractSaveReqVO; |
| 16 | 15 | 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 |
| 48 | 47 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; |
| 49 | 48 | import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*; |
| 50 | 49 | import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.*; |
| 50 | +import static cn.iocoder.yudao.module.crm.util.CrmAuditStatusUtils.convertBpmResultToAuditStatus; | |
| 51 | 51 | |
| 52 | 52 | /** |
| 53 | 53 | * CRM 合同 Service 实现类 |
| ... | ... | @@ -303,10 +303,7 @@ public class CrmContractServiceImpl implements CrmContractService { |
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | // 2. 更新合同审批结果 |
| 306 | - Integer auditStatus = BpmProcessInstanceResultEnum.APPROVE.getResult().equals(bpmResult) ? CrmAuditStatusEnum.APPROVE.getStatus() | |
| 307 | - : BpmProcessInstanceResultEnum.REJECT.getResult().equals(bpmResult) ? CrmAuditStatusEnum.REJECT.getStatus() | |
| 308 | - : BpmProcessInstanceResultEnum.CANCEL.getResult(); | |
| 309 | - Assert.notNull(auditStatus, "BPM 审批结果({}) 转换失败", bpmResult); | |
| 306 | + Integer auditStatus = convertBpmResultToAuditStatus(bpmResult); | |
| 310 | 307 | contractMapper.updateById(new CrmContractDO().setId(id).setAuditStatus(auditStatus)); |
| 311 | 308 | } |
| 312 | 309 | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/receivable/CrmReceivableService.java
| 1 | 1 | package cn.iocoder.yudao.module.crm.service.receivable; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | -import cn.iocoder.yudao.module.bpm.api.listener.dto.BpmResultListenerRespDTO; | |
| 5 | 4 | import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.receivable.CrmReceivablePageReqVO; |
| 6 | 5 | import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.receivable.CrmReceivableSaveReqVO; |
| 7 | 6 | import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; |
| ... | ... | @@ -36,9 +35,10 @@ public interface CrmReceivableService { |
| 36 | 35 | /** |
| 37 | 36 | * 更新回款流程审批结果 |
| 38 | 37 | * |
| 39 | - * @param event 审批结果 | |
| 38 | + * @param id 回款编号 | |
| 39 | + * @param bpmResult BPM 审批结果 | |
| 40 | 40 | */ |
| 41 | - void updateReceivableAuditStatus(BpmResultListenerRespDTO event); | |
| 41 | + void updateReceivableAuditStatus(Long id, Integer bpmResult); | |
| 42 | 42 | |
| 43 | 43 | /** |
| 44 | 44 | * 删除回款 | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/receivable/CrmReceivableServiceImpl.java
| ... | ... | @@ -8,7 +8,6 @@ import cn.hutool.core.util.ObjectUtil; |
| 8 | 8 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 9 | 9 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 10 | 10 | import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; |
| 11 | -import cn.iocoder.yudao.module.bpm.api.listener.dto.BpmResultListenerRespDTO; | |
| 12 | 11 | import cn.iocoder.yudao.module.bpm.api.task.BpmProcessInstanceApi; |
| 13 | 12 | import cn.iocoder.yudao.module.bpm.api.task.dto.BpmProcessInstanceCreateReqDTO; |
| 14 | 13 | import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.receivable.CrmReceivablePageReqVO; |
| ... | ... | @@ -31,6 +30,7 @@ import com.mzt.logapi.context.LogRecordContext; |
| 31 | 30 | import com.mzt.logapi.service.impl.DiffParseFunction; |
| 32 | 31 | import com.mzt.logapi.starter.annotation.LogRecord; |
| 33 | 32 | import jakarta.annotation.Resource; |
| 33 | +import lombok.extern.slf4j.Slf4j; | |
| 34 | 34 | import org.springframework.stereotype.Service; |
| 35 | 35 | import org.springframework.transaction.annotation.Transactional; |
| 36 | 36 | import org.springframework.validation.annotation.Validated; |
| ... | ... | @@ -42,8 +42,7 @@ import java.util.Objects; |
| 42 | 42 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 43 | 43 | import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*; |
| 44 | 44 | import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.*; |
| 45 | -import static cn.iocoder.yudao.module.crm.util.CrmAuditStatusUtils.convertAuditStatus; | |
| 46 | -import static cn.iocoder.yudao.module.crm.util.CrmAuditStatusUtils.isEndResult; | |
| 45 | +import static cn.iocoder.yudao.module.crm.util.CrmAuditStatusUtils.convertBpmResultToAuditStatus; | |
| 47 | 46 | |
| 48 | 47 | /** |
| 49 | 48 | * CRM 回款 Service 实现类 |
| ... | ... | @@ -52,6 +51,7 @@ import static cn.iocoder.yudao.module.crm.util.CrmAuditStatusUtils.isEndResult; |
| 52 | 51 | */ |
| 53 | 52 | @Service |
| 54 | 53 | @Validated |
| 54 | +@Slf4j | |
| 55 | 55 | public class CrmReceivableServiceImpl implements CrmReceivableService { |
| 56 | 56 | |
| 57 | 57 | /** |
| ... | ... | @@ -142,15 +142,19 @@ public class CrmReceivableServiceImpl implements CrmReceivableService { |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | @Override |
| 145 | - public void updateReceivableAuditStatus(BpmResultListenerRespDTO event) { | |
| 146 | - // 判断下状态是否符合预期 | |
| 147 | - if (!isEndResult(event.getResult())) { | |
| 148 | - return; | |
| 145 | + public void updateReceivableAuditStatus(Long id, Integer bpmResult) { | |
| 146 | + // 1.1 校验存在 | |
| 147 | + CrmReceivableDO receivable = validateReceivableExists(id); | |
| 148 | + // 1.2 只有审批中,可以更新审批结果 | |
| 149 | + if (ObjUtil.notEqual(receivable.getAuditStatus(), CrmAuditStatusEnum.PROCESS.getStatus())) { | |
| 150 | + log.error("[updateReceivableAuditStatus][receivable({}) 不处于审批中,无法更新审批结果({})]", | |
| 151 | + receivable.getId(), bpmResult); | |
| 152 | + throw exception(RECEIVABLE_UPDATE_AUDIT_STATUS_FAIL_NOT_PROCESS); | |
| 149 | 153 | } |
| 150 | - convertAuditStatus(event); | |
| 151 | - // 更新回款审批状态 | |
| 152 | - receivableMapper.updateById(new CrmReceivableDO().setId(Long.parseLong(event.getBusinessKey())) | |
| 153 | - .setAuditStatus(event.getResult())); | |
| 154 | + | |
| 155 | + // 2. 更新回款审批状态 | |
| 156 | + Integer auditStatus = convertBpmResultToAuditStatus(bpmResult); | |
| 157 | + receivableMapper.updateById(new CrmReceivableDO().setId(id).setAuditStatus(auditStatus)); | |
| 154 | 158 | } |
| 155 | 159 | |
| 156 | 160 | // TODO @liuhongfeng:缺一个取消回款的接口;只有草稿、审批中可以取消;CrmAuditStatusEnum | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/receivable/listener/CrmReceivableResultListener.java
| 1 | 1 | package cn.iocoder.yudao.module.crm.service.receivable.listener; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.module.bpm.api.listener.BpmResultListenerApi; | |
| 4 | -import cn.iocoder.yudao.module.bpm.api.listener.dto.BpmResultListenerRespDTO; | |
| 3 | +import cn.iocoder.yudao.module.bpm.event.BpmProcessInstanceResultEvent; | |
| 4 | +import cn.iocoder.yudao.module.bpm.event.BpmProcessInstanceResultEventListener; | |
| 5 | 5 | import cn.iocoder.yudao.module.crm.service.receivable.CrmReceivableService; |
| 6 | 6 | import cn.iocoder.yudao.module.crm.service.receivable.CrmReceivableServiceImpl; |
| 7 | 7 | import jakarta.annotation.Resource; |
| 8 | 8 | import org.springframework.stereotype.Component; |
| 9 | 9 | |
| 10 | -// TODO @芋艿:后续改成支持 RPC | |
| 11 | - | |
| 12 | 10 | /** |
| 13 | 11 | * 回款审批的结果的监听器实现类 |
| 14 | 12 | * |
| 15 | 13 | * @author HUIHUI |
| 16 | 14 | */ |
| 17 | 15 | @Component |
| 18 | -public class CrmReceivableResultListener implements BpmResultListenerApi { | |
| 16 | +public class CrmReceivableResultListener extends BpmProcessInstanceResultEventListener { | |
| 19 | 17 | |
| 20 | 18 | @Resource |
| 21 | 19 | private CrmReceivableService receivableService; |
| ... | ... | @@ -26,8 +24,8 @@ public class CrmReceivableResultListener implements BpmResultListenerApi { |
| 26 | 24 | } |
| 27 | 25 | |
| 28 | 26 | @Override |
| 29 | - public void onEvent(BpmResultListenerRespDTO event) { | |
| 30 | - receivableService.updateReceivableAuditStatus(event); | |
| 27 | + public void onEvent(BpmProcessInstanceResultEvent event) { | |
| 28 | + receivableService.updateReceivableAuditStatus(Long.parseLong(event.getBusinessKey()), event.getResult()); | |
| 31 | 29 | } |
| 32 | 30 | |
| 33 | 31 | } | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/util/CrmAuditStatusUtils.java
| 1 | 1 | package cn.iocoder.yudao.module.crm.util; |
| 2 | 2 | |
| 3 | -import cn.hutool.core.util.ObjUtil; | |
| 3 | +import cn.hutool.core.lang.Assert; | |
| 4 | 4 | import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; |
| 5 | -import cn.iocoder.yudao.module.bpm.api.listener.dto.BpmResultListenerRespDTO; | |
| 6 | 5 | import cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceResultEnum; |
| 7 | 6 | import cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum; |
| 8 | 7 | |
| ... | ... | @@ -14,31 +13,27 @@ import cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum; |
| 14 | 13 | public class CrmAuditStatusUtils { |
| 15 | 14 | |
| 16 | 15 | /** |
| 17 | - * 流程审批状态转换 | |
| 16 | + * BPM 审批结果转换 | |
| 18 | 17 | * |
| 19 | - * @param event 业务流程实例的结果 | |
| 18 | + * @param bpmResult BPM 审批结果 | |
| 20 | 19 | */ |
| 21 | - public static void convertAuditStatus(BpmResultListenerRespDTO event) { | |
| 22 | - // 状态转换 | |
| 23 | - if (ObjUtil.equal(event.getResult(), BpmProcessInstanceResultEnum.APPROVE.getResult())) { | |
| 24 | - event.setResult(CrmAuditStatusEnum.APPROVE.getStatus()); | |
| 25 | - } | |
| 26 | - if (ObjUtil.equal(event.getResult(), BpmProcessInstanceResultEnum.REJECT.getResult())) { | |
| 27 | - event.setResult(CrmAuditStatusEnum.REJECT.getStatus()); | |
| 28 | - } | |
| 29 | - if (ObjUtil.equal(event.getResult(), BpmProcessInstanceResultEnum.CANCEL.getResult())) { | |
| 30 | - event.setResult(CrmAuditStatusEnum.CANCEL.getStatus()); | |
| 31 | - } | |
| 20 | + public static Integer convertBpmResultToAuditStatus(Integer bpmResult) { | |
| 21 | + Assert.isTrue(isEndResult(bpmResult), "BPM 审批结果({}) 转换失败, 流程状态不是最终结果", bpmResult); | |
| 22 | + Integer auditStatus = BpmProcessInstanceResultEnum.APPROVE.getResult().equals(bpmResult) ? CrmAuditStatusEnum.APPROVE.getStatus() | |
| 23 | + : BpmProcessInstanceResultEnum.REJECT.getResult().equals(bpmResult) ? CrmAuditStatusEnum.REJECT.getStatus() | |
| 24 | + : BpmProcessInstanceResultEnum.CANCEL.getResult(); | |
| 25 | + Assert.notNull(auditStatus, "BPM 审批结果({}) 转换失败", bpmResult); | |
| 26 | + return auditStatus; | |
| 32 | 27 | } |
| 33 | 28 | |
| 34 | 29 | /** |
| 35 | 30 | * 判断该结果是否处于 End 最终结果 |
| 36 | 31 | * |
| 37 | - * @param result 结果 | |
| 32 | + * @param bpmResult BPM 审批结果 | |
| 38 | 33 | * @return 是否 |
| 39 | 34 | */ |
| 40 | - public static boolean isEndResult(Integer result) { | |
| 41 | - return ObjectUtils.equalsAny(result, BpmProcessInstanceResultEnum.APPROVE.getResult(), | |
| 35 | + public static boolean isEndResult(Integer bpmResult) { | |
| 36 | + return ObjectUtils.equalsAny(bpmResult, BpmProcessInstanceResultEnum.APPROVE.getResult(), | |
| 42 | 37 | BpmProcessInstanceResultEnum.REJECT.getResult(), BpmProcessInstanceResultEnum.CANCEL.getResult()); |
| 43 | 38 | } |
| 44 | 39 | ... | ... |