Commit b06432b8f8c1157e6cb68d2eeb9ba656ca762a42

Authored by xiaqing
1 parent ecf72896

增加客户的公海领取和分配

yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/ErrorCodeConstants.java
@@ -34,6 +34,10 @@ public interface ErrorCodeConstants { @@ -34,6 +34,10 @@ public interface ErrorCodeConstants {
34 34
35 // ========== 客户管理 1_020_006_000 ========== 35 // ========== 客户管理 1_020_006_000 ==========
36 ErrorCode CUSTOMER_NOT_EXISTS = new ErrorCode(1_020_006_000, "客户不存在"); 36 ErrorCode CUSTOMER_NOT_EXISTS = new ErrorCode(1_020_006_000, "客户不存在");
  37 + ErrorCode CUSTOMER_OWNER_EXISTS = new ErrorCode(1_020_006_001, "客户已存在所属负责人");
  38 + ErrorCode CUSTOMER_LOCKED = new ErrorCode(1_020_006_002, "客户状态已锁定");
  39 + ErrorCode CUSTOMER_DEALED = new ErrorCode(1_020_006_003, "客户已交易");
  40 +
37 41
38 // ========== 权限管理 1_020_007_000 ========== 42 // ========== 权限管理 1_020_007_000 ==========
39 ErrorCode CRM_PERMISSION_NOT_EXISTS = new ErrorCode(1_020_007_000, "数据权限不存在"); 43 ErrorCode CRM_PERMISSION_NOT_EXISTS = new ErrorCode(1_020_007_000, "数据权限不存在");
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/CrmCustomerController.java
@@ -3,6 +3,8 @@ package cn.iocoder.yudao.module.crm.controller.admin.customer; @@ -3,6 +3,8 @@ package cn.iocoder.yudao.module.crm.controller.admin.customer;
3 import cn.hutool.core.collection.CollUtil; 3 import cn.hutool.core.collection.CollUtil;
4 import cn.hutool.core.util.NumberUtil; 4 import cn.hutool.core.util.NumberUtil;
5 import cn.hutool.core.util.ObjectUtil; 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;
6 import cn.iocoder.yudao.framework.common.pojo.CommonResult; 8 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
7 import cn.iocoder.yudao.framework.common.pojo.PageResult; 9 import cn.iocoder.yudao.framework.common.pojo.PageResult;
8 import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; 10 import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
@@ -21,6 +23,7 @@ import io.swagger.v3.oas.annotations.Operation; @@ -21,6 +23,7 @@ import io.swagger.v3.oas.annotations.Operation;
21 import io.swagger.v3.oas.annotations.Parameter; 23 import io.swagger.v3.oas.annotations.Parameter;
22 import io.swagger.v3.oas.annotations.tags.Tag; 24 import io.swagger.v3.oas.annotations.tags.Tag;
23 import org.springframework.security.access.prepost.PreAuthorize; 25 import org.springframework.security.access.prepost.PreAuthorize;
  26 +import org.springframework.util.CollectionUtils;
24 import org.springframework.validation.annotation.Validated; 27 import org.springframework.validation.annotation.Validated;
25 import org.springframework.web.bind.annotation.*; 28 import org.springframework.web.bind.annotation.*;
26 29
@@ -32,6 +35,7 @@ import java.util.*; @@ -32,6 +35,7 @@ import java.util.*;
32 import java.util.stream.Collectors; 35 import java.util.stream.Collectors;
33 import java.util.stream.Stream; 36 import java.util.stream.Stream;
34 37
  38 +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.error;
35 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; 39 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
36 import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; 40 import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
37 import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; 41 import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
@@ -152,4 +156,28 @@ public class CrmCustomerController { @@ -152,4 +156,28 @@ public class CrmCustomerController {
152 return success(true); 156 return success(true);
153 } 157 }
154 158
  159 + @PutMapping("/receive")
  160 + @Operation(summary = "根据客户id领取公海任务")
  161 + @PreAuthorize("@ss.hasPermission('crm:customer:receive')")
  162 + public CommonResult<String> receiveByIds(List<Long> cIds){
  163 + // 判断是否为空
  164 + if(CollectionUtils.isEmpty(cIds))
  165 + return error(GlobalErrorCodeConstants.BAD_REQUEST.getCode(),GlobalErrorCodeConstants.BAD_REQUEST.getMsg());
  166 + // 领取公海任务
  167 + customerService.receive(cIds);
  168 + return success("领取成功");
  169 + }
  170 +
  171 + @PutMapping("/distributeByIds")
  172 + @Operation(summary = "分配公海给对应负责人")
  173 + @PreAuthorize("@ss.hasPermission('crm:customer:distributeByIds')")
  174 + public CommonResult<String> distributeByIds(Long ownerId,List<Long>cIds){
  175 + //判断参数不能为空
  176 + if(ownerId==null || CollectionUtils.isEmpty(cIds))
  177 + return error(GlobalErrorCodeConstants.BAD_REQUEST.getCode(),GlobalErrorCodeConstants.BAD_REQUEST.getMsg());
  178 +
  179 + return success("分配成功");
  180 + }
  181 +
  182 +
155 } 183 }
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerService.java
@@ -85,4 +85,20 @@ public interface CrmCustomerService { @@ -85,4 +85,20 @@ public interface CrmCustomerService {
85 */ 85 */
86 void lockCustomer(@Valid CrmCustomerUpdateReqVO updateReqVO); 86 void lockCustomer(@Valid CrmCustomerUpdateReqVO updateReqVO);
87 87
  88 + /**
  89 + * 描述 :接受公海客户
  90 + * Author :xiaqing
  91 + * Date :2023-11-07 22:47:40
  92 + */
  93 + void receive(List<Long>ids);
  94 +
  95 + /**
  96 + *
  97 + *功能描述: 分配负责人
  98 + * @param cIds 要分配的客户id
  99 + * @param ownerId 分配的负责人id
  100 + * @author xiaqing
  101 + * @date 2023-11-08 10:40:22
  102 + */
  103 + void distributeByIds(List<Long>cIds,Long ownerId);
88 } 104 }
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerServiceImpl.java
@@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.crm.service.customer; @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.crm.service.customer;
3 import cn.hutool.core.collection.CollUtil; 3 import cn.hutool.core.collection.CollUtil;
4 import cn.hutool.core.collection.ListUtil; 4 import cn.hutool.core.collection.ListUtil;
5 import cn.iocoder.yudao.framework.common.pojo.PageResult; 5 import cn.iocoder.yudao.framework.common.pojo.PageResult;
  6 +import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
6 import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.*; 7 import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.*;
7 import cn.iocoder.yudao.module.crm.convert.customer.CrmCustomerConvert; 8 import cn.iocoder.yudao.module.crm.convert.customer.CrmCustomerConvert;
8 import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; 9 import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
@@ -18,12 +19,13 @@ import org.springframework.transaction.annotation.Transactional; @@ -18,12 +19,13 @@ import org.springframework.transaction.annotation.Transactional;
18 import org.springframework.validation.annotation.Validated; 19 import org.springframework.validation.annotation.Validated;
19 20
20 import javax.annotation.Resource; 21 import javax.annotation.Resource;
  22 +import java.util.ArrayList;
21 import java.util.Collection; 23 import java.util.Collection;
22 import java.util.List; 24 import java.util.List;
23 import java.util.Objects; 25 import java.util.Objects;
24 26
25 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; 27 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
26 -import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CUSTOMER_NOT_EXISTS; 28 +import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*;
27 29
28 /** 30 /**
29 * 客户 Service 实现类 31 * 客户 Service 实现类
@@ -142,4 +144,56 @@ public class CrmCustomerServiceImpl implements CrmCustomerService { @@ -142,4 +144,56 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
142 customerMapper.updateById(updateObj); 144 customerMapper.updateById(updateObj);
143 } 145 }
144 146
  147 + @Override
  148 + @Transactional(rollbackFor = Exception.class)
  149 + public void receive(List <Long> ids) {
  150 + transferCustomerOwner(ids,SecurityFrameworkUtils.getLoginUserId());
  151 + }
  152 +
  153 + @Override
  154 + public void distributeByIds(List <Long> cIds, Long ownerId) {
  155 + transferCustomerOwner(cIds,ownerId);
  156 + }
  157 +
  158 + private void transferCustomerOwner(List <Long> cIds, Long ownerId){
  159 + //先一次性校验完成客户是否可用
  160 + for (Long cId : cIds) {
  161 + //校验是否存在
  162 + validateCustomerExists(cId);
  163 + //todo 校验是否已有负责人
  164 + validCustomerOwnerExist(cId);
  165 + //todo 校验是否锁定
  166 + validCustomerIsLocked(cId);
  167 + //todo 校验成交状态
  168 + validCustomerDeal(cId);
  169 + }
  170 + List<CrmCustomerDO> updateDos = new ArrayList <>();
  171 + for (Long cId : cIds){
  172 + CrmCustomerDO customerDO = new CrmCustomerDO();
  173 + customerDO.setId(cId);
  174 + customerDO.setOwnerUserId(SecurityFrameworkUtils.getLoginUserId());
  175 + }
  176 + //统一修改状态
  177 + customerMapper.updateBatch(updateDos);
  178 + }
  179 +
  180 + private void validCustomerOwnerExist(Long id) {
  181 + if (customerMapper.selectById(id).getOwnerUserId()!=null) {
  182 + throw exception(CUSTOMER_OWNER_EXISTS);
  183 + }
  184 + }
  185 +
  186 + private void validCustomerIsLocked(Long id) {
  187 + if (customerMapper.selectById(id).getLockStatus() ==true) {
  188 + throw exception(CUSTOMER_LOCKED);
  189 + }
  190 + }
  191 +
  192 + private void validCustomerDeal(Long id) {
  193 + if (customerMapper.selectById(id).getDealStatus() ==true) {
  194 + throw exception(CUSTOMER_DEALED);
  195 + }
  196 + }
  197 +
  198 +
145 } 199 }