From 2de0fb48ea9c6b6b89ae182aac0328e447f80927 Mon Sep 17 00:00:00 2001 From: min Date: Sat, 13 Jan 2024 23:25:55 +0800 Subject: [PATCH] =?UTF-8?q?CRM=EF=BC=9A=E3=80=90=E7=BA=BF=E7=B4=A2?= =?UTF-8?q?=E3=80=91=20=E7=BA=BF=E7=B4=A2=E5=A6=82=E6=9E=9C=E4=B8=8D?= =?UTF-8?q?=E5=AD=98=E5=9C=A8=E6=88=96=E8=80=85=E5=B7=B2=E7=BB=8F=E8=BD=AC?= =?UTF-8?q?=E5=8C=96=EF=BC=8C=E6=8A=9B=E5=87=BA=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/crm/enums/ErrorCodeConstants.java | 2 + .../crm/service/clue/CrmClueServiceImpl.java | 46 ++++++++++++------- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/ErrorCodeConstants.java b/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/ErrorCodeConstants.java index 84df67c13..90ba53ce6 100644 --- a/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/ErrorCodeConstants.java +++ b/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/ErrorCodeConstants.java @@ -14,6 +14,8 @@ public interface ErrorCodeConstants { // ========== 线索管理 1-020-001-000 ========== ErrorCode CLUE_NOT_EXISTS = new ErrorCode(1_020_001_000, "线索不存在"); + ErrorCode ANY_CLUE_NOT_EXISTS = new ErrorCode(1_020_001_001, "线索【{}】不存在"); + ErrorCode ANY_CLUE_ALREADY_TRANSLATED = new ErrorCode(1_020_001_002, "线索【{}】已经转化过了,请勿重复转化"); // ========== 商机管理 1-020-002-000 ========== ErrorCode BUSINESS_NOT_EXISTS = new ErrorCode(1_020_002_000, "商机不存在"); diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/clue/CrmClueServiceImpl.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/clue/CrmClueServiceImpl.java index e40731616..5ed633aac 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/clue/CrmClueServiceImpl.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/clue/CrmClueServiceImpl.java @@ -27,9 +27,12 @@ import org.springframework.validation.annotation.Validated; import java.util.Collection; import java.util.List; import java.util.Objects; +import java.util.Set; +import java.util.stream.Collectors; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CLUE_NOT_EXISTS; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; +import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*; import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.USER_NOT_EXISTS; /** @@ -132,23 +135,34 @@ public class CrmClueServiceImpl implements CrmClueService { @Transactional(rollbackFor = Exception.class) public void translateCustomer(CrmClueTransformReqVO reqVO, Long userId) { // 校验线索都存在 - List clues = getClueList(reqVO.getIds(), userId); - if (CollUtil.isEmpty(clues)) { - throw exception(CLUE_NOT_EXISTS); + Set clueIds = reqVO.getIds(); + List clues = getClueList(clueIds, userId); + if (CollUtil.isEmpty(clues) || ObjectUtil.notEqual(clues.size(), clueIds.size())) { + // 提示不存在的线索编号 + clueIds.removeAll(convertSet(clues, CrmClueDO::getId)); + throw exception(ANY_CLUE_NOT_EXISTS, clueIds.stream().map(String::valueOf).collect(Collectors.joining(","))); } - // TODO @min:如果已经转化,则不能重复转化 - // 遍历线索(过滤掉已转化的线索),创建对应的客户 - clues.stream().filter(clue -> ObjectUtil.notEqual(Boolean.TRUE, clue.getTransformStatus())) - .forEach(clue -> { - // 1. 创建客户 - CrmCustomerSaveReqVO customerSaveReqVO = BeanUtils.toBean(clue, CrmCustomerSaveReqVO.class).setId(null); - Long customerId = customerService.createCustomer(customerSaveReqVO, userId); - // TODO @puhui999:如果有跟进记录,需要一起转过去; - // 2. 更新线索 - clueMapper.updateById(new CrmClueDO().setId(clue.getId()) - .setTransformStatus(Boolean.TRUE).setCustomerId(customerId)); - }); + // 过滤出未转化的客户 + List unTransformClues = clues.stream() + .filter(clue -> ObjectUtil.notEqual(Boolean.TRUE, clue.getTransformStatus())).toList(); + // 传入的线索中包含已经转化的情况,抛出业务异常 + if (ObjectUtil.notEqual(clues.size(), unTransformClues.size())) { + // 提示已经转化的线索编号 + clueIds.removeAll(convertSet(unTransformClues, CrmClueDO::getId)); + throw exception(ANY_CLUE_ALREADY_TRANSLATED, clueIds.stream().map(String::valueOf).collect(Collectors.joining(","))); + } + + // 遍历线索(未转化的线索),创建对应的客户 + unTransformClues.forEach(clue -> { + // 1. 创建客户 + CrmCustomerSaveReqVO customerSaveReqVO = BeanUtils.toBean(clue, CrmCustomerSaveReqVO.class).setId(null); + Long customerId = customerService.createCustomer(customerSaveReqVO, userId); + // TODO @puhui999:如果有跟进记录,需要一起转过去; + // 2. 更新线索 + clueMapper.updateById(new CrmClueDO().setId(clue.getId()) + .setTransformStatus(Boolean.TRUE).setCustomerId(customerId)); + }); } private void validateRelationDataExists(CrmClueSaveReqVO reqVO) {