Commit e519b41244de11cee715468c202e6c4f591393b4

Authored by YunaiV
2 parents 86050d41 18de22dc

Merge branch 'feature/crm' of https://gitee.com/SummerQing/ruoyi-vue-pro into feature/crm

# Conflicts:
#	yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/ErrorCodeConstants.java
#	yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/CrmCustomerController.java
#	yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerServiceImpl.java
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_ALREADY_DEAL = new ErrorCode(1_020_006_003, "客户已交易");
  40 + // TODO @wanwan:这 2 个单独配置段噢
37 ErrorCode CUSTOMER_POOL_CONFIG_ERROR = new ErrorCode(1_020_006_001, "客户公海规则设置不正确"); 41 ErrorCode CUSTOMER_POOL_CONFIG_ERROR = new ErrorCode(1_020_006_001, "客户公海规则设置不正确");
38 ErrorCode CUSTOMER_LIMIT_CONFIG_NOT_EXISTS = new ErrorCode(1_020_006_002, "客户限制配置不存在"); 42 ErrorCode CUSTOMER_LIMIT_CONFIG_NOT_EXISTS = new ErrorCode(1_020_006_002, "客户限制配置不存在");
39 43
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.pojo.CommonResult; 8 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
5 import cn.iocoder.yudao.framework.common.pojo.PageResult; 9 import cn.iocoder.yudao.framework.common.pojo.PageResult;
6 import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; 10 import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
@@ -21,6 +25,7 @@ import io.swagger.v3.oas.annotations.Operation; @@ -21,6 +25,7 @@ import io.swagger.v3.oas.annotations.Operation;
21 import io.swagger.v3.oas.annotations.Parameter; 25 import io.swagger.v3.oas.annotations.Parameter;
22 import io.swagger.v3.oas.annotations.tags.Tag; 26 import io.swagger.v3.oas.annotations.tags.Tag;
23 import org.springframework.security.access.prepost.PreAuthorize; 27 import org.springframework.security.access.prepost.PreAuthorize;
  28 +import org.springframework.util.CollectionUtils;
24 import org.springframework.validation.annotation.Validated; 29 import org.springframework.validation.annotation.Validated;
25 import org.springframework.web.bind.annotation.*; 30 import org.springframework.web.bind.annotation.*;
26 31
@@ -33,6 +38,7 @@ import java.util.List; @@ -33,6 +38,7 @@ import java.util.List;
33 import java.util.Map; 38 import java.util.Map;
34 import java.util.Set; 39 import java.util.Set;
35 40
  41 +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.error;
36 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; 42 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
37 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; 43 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
38 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; 44 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
@@ -178,4 +184,28 @@ public class CrmCustomerController { @@ -178,4 +184,28 @@ public class CrmCustomerController {
178 return success(true); 184 return success(true);
179 } 185 }
180 186
  187 + @PutMapping("/receive")
  188 + @Operation(summary = "根据客户id领取公海任务")
  189 + @PreAuthorize("@ss.hasPermission('crm:customer:receive')")
  190 + public CommonResult<String> receiveByIds(List<Long> cIds){
  191 + // 判断是否为空
  192 + if(CollectionUtils.isEmpty(cIds))
  193 + return error(GlobalErrorCodeConstants.BAD_REQUEST.getCode(),GlobalErrorCodeConstants.BAD_REQUEST.getMsg());
  194 + // 领取公海任务
  195 + customerService.receive(cIds);
  196 + return success("领取成功");
  197 + }
  198 +
  199 + @PutMapping("/distributeByIds")
  200 + @Operation(summary = "分配公海给对应负责人")
  201 + @PreAuthorize("@ss.hasPermission('crm:customer:distributeByIds')")
  202 + public CommonResult<String> distributeByIds(Long ownerId,List<Long>cIds){
  203 + //判断参数不能为空
  204 + if(ownerId==null || CollectionUtils.isEmpty(cIds))
  205 + return error(GlobalErrorCodeConstants.BAD_REQUEST.getCode(),GlobalErrorCodeConstants.BAD_REQUEST.getMsg());
  206 + customerService.distributeByIds(cIds,ownerId);
  207 + return success("分配成功");
  208 + }
  209 +
  210 +
181 } 211 }
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
@@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil; @@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil;
4 import cn.hutool.core.util.ObjUtil; 4 import cn.hutool.core.util.ObjUtil;
5 import cn.iocoder.yudao.framework.common.pojo.PageResult; 5 import cn.iocoder.yudao.framework.common.pojo.PageResult;
6 import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; 6 import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
  7 +import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
7 import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.*; 8 import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.*;
8 import cn.iocoder.yudao.module.crm.convert.customer.CrmCustomerConvert; 9 import cn.iocoder.yudao.module.crm.convert.customer.CrmCustomerConvert;
9 import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; 10 import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
@@ -21,6 +22,8 @@ import org.springframework.validation.annotation.Validated; @@ -21,6 +22,8 @@ import org.springframework.validation.annotation.Validated;
21 22
22 import javax.annotation.Resource; 23 import javax.annotation.Resource;
23 import java.util.Collections; 24 import java.util.Collections;
  25 +import java.util.ArrayList;
  26 +import java.util.Collection;
24 import java.util.List; 27 import java.util.List;
25 import java.util.Objects; 28 import java.util.Objects;
26 import java.util.Set; 29 import java.util.Set;
@@ -28,6 +31,7 @@ import java.util.Set; @@ -28,6 +31,7 @@ import java.util.Set;
28 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; 31 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
29 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; 32 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
30 import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CUSTOMER_NOT_EXISTS; 33 import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CUSTOMER_NOT_EXISTS;
  34 +import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*;
31 35
32 /** 36 /**
33 * 客户 Service 实现类 37 * 客户 Service 实现类
@@ -162,4 +166,56 @@ public class CrmCustomerServiceImpl implements CrmCustomerService { @@ -162,4 +166,56 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
162 customerMapper.updateById(updateObj); 166 customerMapper.updateById(updateObj);
163 } 167 }
164 168
  169 + @Override
  170 + @Transactional(rollbackFor = Exception.class)
  171 + public void receive(List <Long> ids) {
  172 + transferCustomerOwner(ids,SecurityFrameworkUtils.getLoginUserId());
  173 + }
  174 +
  175 + @Override
  176 + public void distributeByIds(List <Long> cIds, Long ownerId) {
  177 + transferCustomerOwner(cIds,ownerId);
  178 + }
  179 +
  180 + private void transferCustomerOwner(List <Long> cIds, Long ownerId){
  181 + //先一次性校验完成客户是否可用
  182 + for (Long cId : cIds) {
  183 + //校验是否存在
  184 + validateCustomerExists(cId);
  185 + //todo 校验是否已有负责人
  186 + validCustomerOwnerExist(cId);
  187 + //todo 校验是否锁定
  188 + validCustomerIsLocked(cId);
  189 + //todo 校验成交状态
  190 + validCustomerDeal(cId);
  191 + }
  192 + List<CrmCustomerDO> updateDos = new ArrayList <>();
  193 + for (Long cId : cIds){
  194 + CrmCustomerDO customerDO = new CrmCustomerDO();
  195 + customerDO.setId(cId);
  196 + customerDO.setOwnerUserId(SecurityFrameworkUtils.getLoginUserId());
  197 + }
  198 + //统一修改状态
  199 + customerMapper.updateBatch(updateDos);
  200 + }
  201 +
  202 + private void validCustomerOwnerExist(Long id) {
  203 + if (customerMapper.selectById(id).getOwnerUserId()!=null) {
  204 + throw exception(CUSTOMER_OWNER_EXISTS);
  205 + }
  206 + }
  207 +
  208 + private void validCustomerIsLocked(Long id) {
  209 + if (customerMapper.selectById(id).getLockStatus() ==true) {
  210 + throw exception(CUSTOMER_LOCKED);
  211 + }
  212 + }
  213 +
  214 + private void validCustomerDeal(Long id) {
  215 + if (customerMapper.selectById(id).getDealStatus() ==true) {
  216 + throw exception(CUSTOMER_DEALED);
  217 + }
  218 + }
  219 +
  220 +
165 } 221 }