From f589881de57297e72d4f0067596f36e86cc6c466 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sun, 19 Nov 2023 00:05:06 +0800 Subject: [PATCH] =?UTF-8?q?code=20review=EF=BC=9A=E5=AE=A2=E6=88=B7?= =?UTF-8?q?=E7=9A=84=E5=88=86=E9=85=8D=E5=92=8C=E9=A2=86=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/customer/CrmCustomerController.java | 11 +++++------ .../service/customer/CrmCustomerService.java | 14 ++++++++------ .../customer/CrmCustomerServiceImpl.java | 17 ++++++----------- 3 files changed, 19 insertions(+), 23 deletions(-) diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/CrmCustomerController.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/CrmCustomerController.java index 1f4087486..8a34b599d 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/CrmCustomerController.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/CrmCustomerController.java @@ -1,9 +1,6 @@ package cn.iocoder.yudao.module.crm.controller.admin.customer; import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.util.NumberUtil; -import cn.hutool.core.util.ObjectUtil; -import cn.iocoder.yudao.framework.common.exception.ErrorCode; import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; @@ -185,17 +182,20 @@ public class CrmCustomerController { } @PutMapping("/receive") - @Operation(summary = "根据客户id领取公海任务") + @Operation(summary = "领取公海客户") + // TODO @xiaqing:1)receiveCustomer 方法名字;2)cIds 改成 ids,要加下 @RequestParam,还有 swagger 注解;3)参数非空,使用 validator 校验;4)返回 true 即可; @PreAuthorize("@ss.hasPermission('crm:customer:receive')") - public CommonResult receiveByIds(List cIds){ + public CommonResult receiveByIds(List cIds){ // 判断是否为空 if(CollectionUtils.isEmpty(cIds)) return error(GlobalErrorCodeConstants.BAD_REQUEST.getCode(),GlobalErrorCodeConstants.BAD_REQUEST.getMsg()); // 领取公海任务 + // TODO @xiaqing:userid,通过 controller 传递给 service,不要在 service 里面获取,无状态 customerService.receive(cIds); return success("领取成功"); } + // TODO @xiaqing:1)distributeCustomer 方法名;2)cIds 同上;3)参数校验,同上;4)ownerId 改成 ownerUserId,和别的模块统一;5)返回 true 即可; @PutMapping("/distributeByIds") @Operation(summary = "分配公海给对应负责人") @PreAuthorize("@ss.hasPermission('crm:customer:distributeByIds')") @@ -207,5 +207,4 @@ public class CrmCustomerController { return success("分配成功"); } - } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerService.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerService.java index a7ab871d5..6aa21477e 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerService.java +++ b/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 { */ void lockCustomer(@Valid CrmCustomerUpdateReqVO updateReqVO); + // TODO @xiaqing:根据 controller 的建议,改下 /** - * 描述 :接受公海客户 - * Author :xiaqing - * Date :2023-11-07 22:47:40 + * 领取公海客户 + * + * @param ids 要领取的客户 id */ void receive(Listids); + // TODO @xiaqing:根据 controller 的建议,改下 /** + * 分配公海客户 * - *功能描述: 分配负责人 - * @param cIds 要分配的客户id + * @param cIds 要分配的客户 id * @param ownerId 分配的负责人id * @author xiaqing - * @date 2023-11-08 10:40:22 */ void distributeByIds(ListcIds,Long ownerId); + } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerServiceImpl.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerServiceImpl.java index 04aff2714..ebb499128 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerServiceImpl.java +++ b/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; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; -import java.util.Collections; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Objects; -import java.util.Set; +import java.util.*; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; -import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CUSTOMER_NOT_EXISTS; import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*; /** @@ -178,7 +172,8 @@ public class CrmCustomerServiceImpl implements CrmCustomerService { } private void transferCustomerOwner(List cIds, Long ownerId){ - //先一次性校验完成客户是否可用 + // 先一次性校验完成客户是否可用 + // TODO @xiaqing:批量一次性加载客户列表,然后去逐个校验; for (Long cId : cIds) { //校验是否存在 validateCustomerExists(cId); @@ -189,13 +184,14 @@ public class CrmCustomerServiceImpl implements CrmCustomerService { //todo 校验成交状态 validCustomerDeal(cId); } + // TODO @xiaqing:每个客户更新的时候,where 条件,加上 owner_user_id is null,防止并发问题; List updateDos = new ArrayList <>(); for (Long cId : cIds){ CrmCustomerDO customerDO = new CrmCustomerDO(); customerDO.setId(cId); customerDO.setOwnerUserId(SecurityFrameworkUtils.getLoginUserId()); } - //统一修改状态 + // 统一修改状态 customerMapper.updateBatch(updateDos); } @@ -213,9 +209,8 @@ public class CrmCustomerServiceImpl implements CrmCustomerService { private void validCustomerDeal(Long id) { if (customerMapper.selectById(id).getDealStatus() ==true) { - throw exception(CUSTOMER_DEALED); + throw exception(CUSTOMER_ALREADY_DEAL); } } - }