Commit f589881de57297e72d4f0067596f36e86cc6c466

Authored by YunaiV
1 parent e519b412

code review:客户的分配和领取

yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/CrmCustomerController.java
1 package cn.iocoder.yudao.module.crm.controller.admin.customer; 1 package cn.iocoder.yudao.module.crm.controller.admin.customer;
2 2
3 import cn.hutool.core.collection.CollUtil; 3 import cn.hutool.core.collection.CollUtil;
4 -import cn.hutool.core.util.NumberUtil;  
5 -import cn.hutool.core.util.ObjectUtil;  
6 -import cn.iocoder.yudao.framework.common.exception.ErrorCode;  
7 import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants; 4 import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants;
8 import cn.iocoder.yudao.framework.common.pojo.CommonResult; 5 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
9 import cn.iocoder.yudao.framework.common.pojo.PageResult; 6 import cn.iocoder.yudao.framework.common.pojo.PageResult;
@@ -185,17 +182,20 @@ public class CrmCustomerController { @@ -185,17 +182,20 @@ public class CrmCustomerController {
185 } 182 }
186 183
187 @PutMapping("/receive") 184 @PutMapping("/receive")
188 - @Operation(summary = "根据客户id领取公海任务") 185 + @Operation(summary = "领取公海客户")
  186 + // TODO @xiaqing:1)receiveCustomer 方法名字;2)cIds 改成 ids,要加下 @RequestParam,还有 swagger 注解;3)参数非空,使用 validator 校验;4)返回 true 即可;
189 @PreAuthorize("@ss.hasPermission('crm:customer:receive')") 187 @PreAuthorize("@ss.hasPermission('crm:customer:receive')")
190 - public CommonResult<String> receiveByIds(List<Long> cIds){ 188 + public CommonResult<String> receiveByIds(List<Long> cIds){
191 // 判断是否为空 189 // 判断是否为空
192 if(CollectionUtils.isEmpty(cIds)) 190 if(CollectionUtils.isEmpty(cIds))
193 return error(GlobalErrorCodeConstants.BAD_REQUEST.getCode(),GlobalErrorCodeConstants.BAD_REQUEST.getMsg()); 191 return error(GlobalErrorCodeConstants.BAD_REQUEST.getCode(),GlobalErrorCodeConstants.BAD_REQUEST.getMsg());
194 // 领取公海任务 192 // 领取公海任务
  193 + // TODO @xiaqing:userid,通过 controller 传递给 service,不要在 service 里面获取,无状态
195 customerService.receive(cIds); 194 customerService.receive(cIds);
196 return success("领取成功"); 195 return success("领取成功");
197 } 196 }
198 197
  198 + // TODO @xiaqing:1)distributeCustomer 方法名;2)cIds 同上;3)参数校验,同上;4)ownerId 改成 ownerUserId,和别的模块统一;5)返回 true 即可;
199 @PutMapping("/distributeByIds") 199 @PutMapping("/distributeByIds")
200 @Operation(summary = "分配公海给对应负责人") 200 @Operation(summary = "分配公海给对应负责人")
201 @PreAuthorize("@ss.hasPermission('crm:customer:distributeByIds')") 201 @PreAuthorize("@ss.hasPermission('crm:customer:distributeByIds')")
@@ -207,5 +207,4 @@ public class CrmCustomerController { @@ -207,5 +207,4 @@ public class CrmCustomerController {
207 return success("分配成功"); 207 return success("分配成功");
208 } 208 }
209 209
210 -  
211 } 210 }
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerService.java
@@ -85,20 +85,22 @@ public interface CrmCustomerService { @@ -85,20 +85,22 @@ public interface CrmCustomerService {
85 */ 85 */
86 void lockCustomer(@Valid CrmCustomerUpdateReqVO updateReqVO); 86 void lockCustomer(@Valid CrmCustomerUpdateReqVO updateReqVO);
87 87
  88 + // TODO @xiaqing:根据 controller 的建议,改下
88 /** 89 /**
89 - * 描述 :接受公海客户  
90 - * Author :xiaqing  
91 - * Date :2023-11-07 22:47:40 90 + * 领取公海客户
  91 + *
  92 + * @param ids 要领取的客户 id
92 */ 93 */
93 void receive(List<Long>ids); 94 void receive(List<Long>ids);
94 95
  96 + // TODO @xiaqing:根据 controller 的建议,改下
95 /** 97 /**
  98 + * 分配公海客户
96 * 99 *
97 - *功能描述: 分配负责人  
98 - * @param cIds 要分配的客户id 100 + * @param cIds 要分配的客户 id
99 * @param ownerId 分配的负责人id 101 * @param ownerId 分配的负责人id
100 * @author xiaqing 102 * @author xiaqing
101 - * @date 2023-11-08 10:40:22  
102 */ 103 */
103 void distributeByIds(List<Long>cIds,Long ownerId); 104 void distributeByIds(List<Long>cIds,Long ownerId);
  105 +
104 } 106 }
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerServiceImpl.java
@@ -21,16 +21,10 @@ import org.springframework.transaction.annotation.Transactional; @@ -21,16 +21,10 @@ import org.springframework.transaction.annotation.Transactional;
21 import org.springframework.validation.annotation.Validated; 21 import org.springframework.validation.annotation.Validated;
22 22
23 import javax.annotation.Resource; 23 import javax.annotation.Resource;
24 -import java.util.Collections;  
25 -import java.util.ArrayList;  
26 -import java.util.Collection;  
27 -import java.util.List;  
28 -import java.util.Objects;  
29 -import java.util.Set; 24 +import java.util.*;
30 25
31 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; 26 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
32 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; 27 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
33 -import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CUSTOMER_NOT_EXISTS;  
34 import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*; 28 import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*;
35 29
36 /** 30 /**
@@ -178,7 +172,8 @@ public class CrmCustomerServiceImpl implements CrmCustomerService { @@ -178,7 +172,8 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
178 } 172 }
179 173
180 private void transferCustomerOwner(List <Long> cIds, Long ownerId){ 174 private void transferCustomerOwner(List <Long> cIds, Long ownerId){
181 - //先一次性校验完成客户是否可用 175 + // 先一次性校验完成客户是否可用
  176 + // TODO @xiaqing:批量一次性加载客户列表,然后去逐个校验;
182 for (Long cId : cIds) { 177 for (Long cId : cIds) {
183 //校验是否存在 178 //校验是否存在
184 validateCustomerExists(cId); 179 validateCustomerExists(cId);
@@ -189,13 +184,14 @@ public class CrmCustomerServiceImpl implements CrmCustomerService { @@ -189,13 +184,14 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
189 //todo 校验成交状态 184 //todo 校验成交状态
190 validCustomerDeal(cId); 185 validCustomerDeal(cId);
191 } 186 }
  187 + // TODO @xiaqing:每个客户更新的时候,where 条件,加上 owner_user_id is null,防止并发问题;
192 List<CrmCustomerDO> updateDos = new ArrayList <>(); 188 List<CrmCustomerDO> updateDos = new ArrayList <>();
193 for (Long cId : cIds){ 189 for (Long cId : cIds){
194 CrmCustomerDO customerDO = new CrmCustomerDO(); 190 CrmCustomerDO customerDO = new CrmCustomerDO();
195 customerDO.setId(cId); 191 customerDO.setId(cId);
196 customerDO.setOwnerUserId(SecurityFrameworkUtils.getLoginUserId()); 192 customerDO.setOwnerUserId(SecurityFrameworkUtils.getLoginUserId());
197 } 193 }
198 - //统一修改状态 194 + // 统一修改状态
199 customerMapper.updateBatch(updateDos); 195 customerMapper.updateBatch(updateDos);
200 } 196 }
201 197
@@ -213,9 +209,8 @@ public class CrmCustomerServiceImpl implements CrmCustomerService { @@ -213,9 +209,8 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
213 209
214 private void validCustomerDeal(Long id) { 210 private void validCustomerDeal(Long id) {
215 if (customerMapper.selectById(id).getDealStatus() ==true) { 211 if (customerMapper.selectById(id).getDealStatus() ==true) {
216 - throw exception(CUSTOMER_DEALED); 212 + throw exception(CUSTOMER_ALREADY_DEAL);
217 } 213 }
218 } 214 }
219 215
220 -  
221 } 216 }