Commit 2de0fb48ea9c6b6b89ae182aac0328e447f80927
1 parent
fe0bde84
CRM:【线索】 线索如果不存在或者已经转化,抛出异常
Showing
2 changed files
with
33 additions
and
17 deletions
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 { | @@ -14,6 +14,8 @@ public interface ErrorCodeConstants { | ||
| 14 | 14 | ||
| 15 | // ========== 线索管理 1-020-001-000 ========== | 15 | // ========== 线索管理 1-020-001-000 ========== |
| 16 | ErrorCode CLUE_NOT_EXISTS = new ErrorCode(1_020_001_000, "线索不存在"); | 16 | ErrorCode CLUE_NOT_EXISTS = new ErrorCode(1_020_001_000, "线索不存在"); |
| 17 | + ErrorCode ANY_CLUE_NOT_EXISTS = new ErrorCode(1_020_001_001, "线索【{}】不存在"); | ||
| 18 | + ErrorCode ANY_CLUE_ALREADY_TRANSLATED = new ErrorCode(1_020_001_002, "线索【{}】已经转化过了,请勿重复转化"); | ||
| 17 | 19 | ||
| 18 | // ========== 商机管理 1-020-002-000 ========== | 20 | // ========== 商机管理 1-020-002-000 ========== |
| 19 | ErrorCode BUSINESS_NOT_EXISTS = new ErrorCode(1_020_002_000, "商机不存在"); | 21 | ErrorCode BUSINESS_NOT_EXISTS = new ErrorCode(1_020_002_000, "商机不存在"); |
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; | @@ -27,9 +27,12 @@ import org.springframework.validation.annotation.Validated; | ||
| 27 | import java.util.Collection; | 27 | import java.util.Collection; |
| 28 | import java.util.List; | 28 | import java.util.List; |
| 29 | import java.util.Objects; | 29 | import java.util.Objects; |
| 30 | +import java.util.Set; | ||
| 31 | +import java.util.stream.Collectors; | ||
| 30 | 32 | ||
| 31 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 33 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 32 | -import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CLUE_NOT_EXISTS; | 34 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; |
| 35 | +import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*; | ||
| 33 | import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.USER_NOT_EXISTS; | 36 | import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.USER_NOT_EXISTS; |
| 34 | 37 | ||
| 35 | /** | 38 | /** |
| @@ -132,23 +135,34 @@ public class CrmClueServiceImpl implements CrmClueService { | @@ -132,23 +135,34 @@ public class CrmClueServiceImpl implements CrmClueService { | ||
| 132 | @Transactional(rollbackFor = Exception.class) | 135 | @Transactional(rollbackFor = Exception.class) |
| 133 | public void translateCustomer(CrmClueTransformReqVO reqVO, Long userId) { | 136 | public void translateCustomer(CrmClueTransformReqVO reqVO, Long userId) { |
| 134 | // 校验线索都存在 | 137 | // 校验线索都存在 |
| 135 | - List<CrmClueDO> clues = getClueList(reqVO.getIds(), userId); | ||
| 136 | - if (CollUtil.isEmpty(clues)) { | ||
| 137 | - throw exception(CLUE_NOT_EXISTS); | 138 | + Set<Long> clueIds = reqVO.getIds(); |
| 139 | + List<CrmClueDO> clues = getClueList(clueIds, userId); | ||
| 140 | + if (CollUtil.isEmpty(clues) || ObjectUtil.notEqual(clues.size(), clueIds.size())) { | ||
| 141 | + // 提示不存在的线索编号 | ||
| 142 | + clueIds.removeAll(convertSet(clues, CrmClueDO::getId)); | ||
| 143 | + throw exception(ANY_CLUE_NOT_EXISTS, clueIds.stream().map(String::valueOf).collect(Collectors.joining(","))); | ||
| 144 | + } | ||
| 145 | + | ||
| 146 | + // 过滤出未转化的客户 | ||
| 147 | + List<CrmClueDO> unTransformClues = clues.stream() | ||
| 148 | + .filter(clue -> ObjectUtil.notEqual(Boolean.TRUE, clue.getTransformStatus())).toList(); | ||
| 149 | + // 传入的线索中包含已经转化的情况,抛出业务异常 | ||
| 150 | + if (ObjectUtil.notEqual(clues.size(), unTransformClues.size())) { | ||
| 151 | + // 提示已经转化的线索编号 | ||
| 152 | + clueIds.removeAll(convertSet(unTransformClues, CrmClueDO::getId)); | ||
| 153 | + throw exception(ANY_CLUE_ALREADY_TRANSLATED, clueIds.stream().map(String::valueOf).collect(Collectors.joining(","))); | ||
| 138 | } | 154 | } |
| 139 | - // TODO @min:如果已经转化,则不能重复转化 | ||
| 140 | - | ||
| 141 | - // 遍历线索(过滤掉已转化的线索),创建对应的客户 | ||
| 142 | - clues.stream().filter(clue -> ObjectUtil.notEqual(Boolean.TRUE, clue.getTransformStatus())) | ||
| 143 | - .forEach(clue -> { | ||
| 144 | - // 1. 创建客户 | ||
| 145 | - CrmCustomerSaveReqVO customerSaveReqVO = BeanUtils.toBean(clue, CrmCustomerSaveReqVO.class).setId(null); | ||
| 146 | - Long customerId = customerService.createCustomer(customerSaveReqVO, userId); | ||
| 147 | - // TODO @puhui999:如果有跟进记录,需要一起转过去; | ||
| 148 | - // 2. 更新线索 | ||
| 149 | - clueMapper.updateById(new CrmClueDO().setId(clue.getId()) | ||
| 150 | - .setTransformStatus(Boolean.TRUE).setCustomerId(customerId)); | ||
| 151 | - }); | 155 | + |
| 156 | + // 遍历线索(未转化的线索),创建对应的客户 | ||
| 157 | + unTransformClues.forEach(clue -> { | ||
| 158 | + // 1. 创建客户 | ||
| 159 | + CrmCustomerSaveReqVO customerSaveReqVO = BeanUtils.toBean(clue, CrmCustomerSaveReqVO.class).setId(null); | ||
| 160 | + Long customerId = customerService.createCustomer(customerSaveReqVO, userId); | ||
| 161 | + // TODO @puhui999:如果有跟进记录,需要一起转过去; | ||
| 162 | + // 2. 更新线索 | ||
| 163 | + clueMapper.updateById(new CrmClueDO().setId(clue.getId()) | ||
| 164 | + .setTransformStatus(Boolean.TRUE).setCustomerId(customerId)); | ||
| 165 | + }); | ||
| 152 | } | 166 | } |
| 153 | 167 | ||
| 154 | private void validateRelationDataExists(CrmClueSaveReqVO reqVO) { | 168 | private void validateRelationDataExists(CrmClueSaveReqVO reqVO) { |