|
@@ -1,10 +1,15 @@
|
|
|
package cn.iocoder.yudao.module.crm.service.customer;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.lang.Assert;
|
|
|
+import cn.hutool.extra.spring.SpringUtil;
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
-import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.*;
|
|
|
+import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerLockReqVO;
|
|
|
+import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerPageReqVO;
|
|
|
+import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerSaveReqVO;
|
|
|
+import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerTransferReqVO;
|
|
|
import cn.iocoder.yudao.module.crm.convert.customer.CrmCustomerConvert;
|
|
|
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
|
|
|
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerLimitConfigDO;
|
|
@@ -12,9 +17,11 @@ import cn.iocoder.yudao.module.crm.dal.mysql.customer.CrmCustomerMapper;
|
|
|
import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum;
|
|
|
import cn.iocoder.yudao.module.crm.enums.permission.CrmPermissionLevelEnum;
|
|
|
import cn.iocoder.yudao.module.crm.framework.permission.core.annotations.CrmPermission;
|
|
|
+import cn.iocoder.yudao.module.crm.framework.permission.core.util.CrmPermissionUtils;
|
|
|
import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService;
|
|
|
import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateReqBO;
|
|
|
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
|
|
+import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
|
|
|
import com.mzt.logapi.context.LogRecordContext;
|
|
|
import com.mzt.logapi.service.impl.DiffParseFunction;
|
|
|
import com.mzt.logapi.starter.annotation.LogRecord;
|
|
@@ -24,12 +31,14 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
-import java.util.*;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Collection;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*;
|
|
|
-import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.CRM_CUSTOMER;
|
|
|
-import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.TRANSFER_CUSTOMER_LOG_SUCCESS;
|
|
|
+import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.*;
|
|
|
import static cn.iocoder.yudao.module.crm.enums.customer.CrmCustomerLimitConfigTypeEnum.CUSTOMER_LOCK_LIMIT;
|
|
|
import static cn.iocoder.yudao.module.crm.enums.customer.CrmCustomerLimitConfigTypeEnum.CUSTOMER_OWNER_LIMIT;
|
|
|
import static java.util.Collections.singletonList;
|
|
@@ -56,8 +65,9 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- @LogRecord(type = CRM_CUSTOMER, subType = "创建客户", bizNo = "{{#customerId}}", success = "创建了客户") // TODO @puhui999:创建了客户【客户名】,要记录进去;不然在展示操作日志的全列表,看不清楚是哪个客户哈;
|
|
|
- public Long createCustomer(CrmCustomerCreateReqVO createReqVO, Long userId) {
|
|
|
+ @LogRecord(type = CRM_CUSTOMER_TYPE, subType = CRM_CUSTOMER_CREATE_SUB_TYPE, bizNo = "{{#customer.id}}", success = CRM_CUSTOMER_CREATE_SUCCESS)
|
|
|
+ public Long createCustomer(CrmCustomerSaveReqVO createReqVO, Long userId) {
|
|
|
+ createReqVO.setId(null);
|
|
|
// 1. 校验拥有客户是否到达上限
|
|
|
validateCustomerExceedOwnerLimit(createReqVO.getOwnerUserId(), 1);
|
|
|
|
|
@@ -72,17 +82,19 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
|
|
|
permissionService.createPermission(new CrmPermissionCreateReqBO().setBizType(CrmBizTypeEnum.CRM_CUSTOMER.getType())
|
|
|
.setBizId(customer.getId()).setUserId(userId).setLevel(CrmPermissionLevelEnum.OWNER.getLevel())); // 设置当前操作的人为负责人
|
|
|
|
|
|
- // 4. 记录操作日志
|
|
|
- LogRecordContext.putVariable("customerId", customer.getId());
|
|
|
+ // 4. 记录操作日志上下文
|
|
|
+ LogRecordContext.putVariable("customer", customer);
|
|
|
return customer.getId();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- @LogRecord(type = CRM_CUSTOMER, subType = "更新客户", bizNo = "{{#updateReqVO.id}}", success = "更新了客户{_DIFF{#updateReqVO}}", extra = "{{#extra}}")
|
|
|
+ @LogRecord(type = CRM_CUSTOMER_TYPE, subType = CRM_CUSTOMER_UPDATE_SUB_TYPE, bizNo = "{{#updateReqVO.id}}", success = CRM_CUSTOMER_UPDATE_SUCCESS)
|
|
|
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#updateReqVO.id", level = CrmPermissionLevelEnum.WRITE)
|
|
|
- public void updateCustomer(CrmCustomerUpdateReqVO updateReqVO) {
|
|
|
- // TODO @puhui999:更新的时候,要把 updateReqVO 负责人设置为空,避免修改。
|
|
|
+ public void updateCustomer(CrmCustomerSaveReqVO updateReqVO) {
|
|
|
+ Assert.notNull(updateReqVO.getId(), "客户编号不能为空");
|
|
|
+ // 更新的时候,要把 updateReqVO 负责人设置为空,避免修改。
|
|
|
+ updateReqVO.setOwnerUserId(null);
|
|
|
// 1. 校验存在
|
|
|
CrmCustomerDO oldCustomer = validateCustomerExists(updateReqVO.getId());
|
|
|
|
|
@@ -90,21 +102,18 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
|
|
|
CrmCustomerDO updateObj = CrmCustomerConvert.INSTANCE.convert(updateReqVO);
|
|
|
customerMapper.updateById(updateObj);
|
|
|
|
|
|
- // 3. 记录操作日志
|
|
|
- LogRecordContext.putVariable(DiffParseFunction.OLD_OBJECT, BeanUtils.toBean(oldCustomer, CrmCustomerUpdateReqVO.class));
|
|
|
- // TODO 扩展信息测试 @puhui999:看着没啥问题,可以删除啦;
|
|
|
- HashMap<String, Object> extra = new HashMap<>();
|
|
|
- extra.put("tips", "随便记录一点啦");
|
|
|
- LogRecordContext.putVariable("extra", extra);
|
|
|
+ // 3. 记录操作日志上下文
|
|
|
+ LogRecordContext.putVariable(DiffParseFunction.OLD_OBJECT, BeanUtils.toBean(oldCustomer, CrmCustomerSaveReqVO.class));
|
|
|
+ LogRecordContext.putVariable("customerName", oldCustomer.getName());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- @LogRecord(type = CRM_CUSTOMER, subType = "删除客户", bizNo = "{{#id}}", success = "删除了客户")
|
|
|
+ @LogRecord(type = CRM_CUSTOMER_TYPE, subType = CRM_CUSTOMER_DELETE_SUB_TYPE, bizNo = "{{#id}}", success = CRM_CUSTOMER_DELETE_SUCCESS)
|
|
|
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#id", level = CrmPermissionLevelEnum.OWNER)
|
|
|
public void deleteCustomer(Long id) {
|
|
|
// 校验存在
|
|
|
- validateCustomerExists(id);
|
|
|
+ CrmCustomerDO customer = validateCustomerExists(id);
|
|
|
// TODO @puhui999:如果有联系人、商机,则不允许删除;
|
|
|
|
|
|
// 删除
|
|
@@ -112,48 +121,14 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
|
|
|
// 删除数据权限
|
|
|
permissionService.deletePermission(CrmBizTypeEnum.CRM_CUSTOMER.getType(), id);
|
|
|
// TODO @puhui999:删除跟进记录
|
|
|
- }
|
|
|
-
|
|
|
- private CrmCustomerDO validateCustomerExists(Long id) {
|
|
|
- CrmCustomerDO customerDO = customerMapper.selectById(id);
|
|
|
- if (customerDO == null) {
|
|
|
- throw exception(CUSTOMER_NOT_EXISTS);
|
|
|
- }
|
|
|
- return customerDO;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- @CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#id", level = CrmPermissionLevelEnum.READ)
|
|
|
- public CrmCustomerDO getCustomer(Long id) {
|
|
|
- return customerMapper.selectById(id);
|
|
|
- }
|
|
|
|
|
|
- @Override
|
|
|
- public List<CrmCustomerDO> getCustomerList(Collection<Long> ids) {
|
|
|
- if (CollUtil.isEmpty(ids)) {
|
|
|
- return Collections.emptyList();
|
|
|
- }
|
|
|
- return customerMapper.selectBatchIds(ids);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public PageResult<CrmCustomerDO> getCustomerPage(CrmCustomerPageReqVO pageReqVO, Long userId) {
|
|
|
- return customerMapper.selectPage(pageReqVO, userId);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 校验客户是否存在
|
|
|
- *
|
|
|
- * @param customerId 客户 id
|
|
|
- */
|
|
|
- @Override
|
|
|
- public void validateCustomer(Long customerId) {
|
|
|
- validateCustomerExists(customerId);
|
|
|
+ // 记录操作日志上下文
|
|
|
+ LogRecordContext.putVariable("customerName", customer.getName());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- @LogRecord(type = CRM_CUSTOMER, subType = "转移客户", bizNo = "{{#reqVO.id}}", success = TRANSFER_CUSTOMER_LOG_SUCCESS)
|
|
|
+ @LogRecord(type = CRM_CUSTOMER_TYPE, subType = CRM_CUSTOMER_TRANSFER_SUB_TYPE, bizNo = "{{#reqVO.id}}", success = CRM_CUSTOMER_TRANSFER_SUCCESS)
|
|
|
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#reqVO.id", level = CrmPermissionLevelEnum.OWNER)
|
|
|
public void transferCustomer(CrmCustomerTransferReqVO reqVO, Long userId) {
|
|
|
// 1.1 校验客户是否存在
|
|
@@ -168,20 +143,17 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
|
|
|
customerMapper.updateOwnerUserIdById(reqVO.getId(), reqVO.getNewOwnerUserId());
|
|
|
|
|
|
// 3. TODO 记录转移日志
|
|
|
+ // 记录操作日志上下文
|
|
|
LogRecordContext.putVariable("crmCustomer", customer);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- // TODO @puhui999:看看这个能不能根据条件,写操作日志;
|
|
|
- // TODO 如果是 锁定,则 subType 为 锁定客户;success 为 将客户【】锁定
|
|
|
- // TODO 如果是 解锁,则 subType 为 解锁客户;success 为 将客户【】解锁
|
|
|
- @LogRecord(type = CRM_CUSTOMER, subType = "锁定/解锁客户", bizNo = "{{#updateReqVO.id}}", success = "锁定了客户")
|
|
|
- // TODO @puhui999:数据权限
|
|
|
+ @LogRecord(type = CRM_CUSTOMER_TYPE, subType = CRM_CUSTOMER_LOCK_SUB_TYPE, bizNo = "{{#lockReqVO.id}}", success = CRM_CUSTOMER_LOCK_SUCCESS)
|
|
|
+ @CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#lockReqVO.id", level = CrmPermissionLevelEnum.OWNER)
|
|
|
public void lockCustomer(CrmCustomerLockReqVO lockReqVO, Long userId) {
|
|
|
// 1.1 校验当前客户是否存在
|
|
|
- validateCustomerExists(lockReqVO.getId());
|
|
|
+ CrmCustomerDO customer = validateCustomerExists(lockReqVO.getId());
|
|
|
// 1.2 校验当前是否重复操作锁定/解锁状态
|
|
|
- CrmCustomerDO customer = customerMapper.selectById(lockReqVO.getId());
|
|
|
if (customer.getLockStatus().equals(lockReqVO.getLockStatus())) {
|
|
|
throw exception(customer.getLockStatus() ? CUSTOMER_LOCK_FAIL_IS_LOCK : CUSTOMER_UNLOCK_FAIL_IS_UNLOCK);
|
|
|
}
|
|
@@ -192,52 +164,16 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
|
|
|
|
|
|
// 2. 更新锁定状态
|
|
|
customerMapper.updateById(BeanUtils.toBean(lockReqVO, CrmCustomerDO.class));
|
|
|
- }
|
|
|
|
|
|
- /**
|
|
|
- * 校验用户拥有的客户数量,是否到达上限
|
|
|
- *
|
|
|
- * @param userId 用户编号
|
|
|
- * @param newCount 附加数量
|
|
|
- */
|
|
|
- private void validateCustomerExceedOwnerLimit(Long userId, int newCount) {
|
|
|
- List<CrmCustomerLimitConfigDO> limitConfigs = customerLimitConfigService.getCustomerLimitConfigListByUserId(
|
|
|
- CUSTOMER_OWNER_LIMIT.getType(), userId);
|
|
|
- if (CollUtil.isEmpty(limitConfigs)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- Long ownerCount = customerMapper.selectCountByDealStatusAndOwnerUserId(null, userId);
|
|
|
- Long dealOwnerCount = customerMapper.selectCountByDealStatusAndOwnerUserId(true, userId);
|
|
|
- limitConfigs.forEach(limitConfig -> {
|
|
|
- long nowCount = limitConfig.getDealCountEnabled() ? ownerCount : ownerCount - dealOwnerCount;
|
|
|
- if (nowCount + newCount > limitConfig.getMaxCount()) {
|
|
|
- throw exception(CUSTOMER_OWNER_EXCEED_LIMIT);
|
|
|
- }
|
|
|
- });
|
|
|
+ // 3. 记录操作日志上下文. tips: 因为这里使用的是老的状态所以记录时反着记录,也就是 lockStatus 为 true 那么就是解锁反之为锁定
|
|
|
+ LogRecordContext.putVariable("crmCustomer", customer);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 校验用户锁定的客户数量,是否到达上限
|
|
|
- *
|
|
|
- * @param userId 用户编号
|
|
|
- */
|
|
|
- private void validateCustomerExceedLockLimit(Long userId) {
|
|
|
- List<CrmCustomerLimitConfigDO> limitConfigs = customerLimitConfigService.getCustomerLimitConfigListByUserId(
|
|
|
- CUSTOMER_LOCK_LIMIT.getType(), userId);
|
|
|
- if (CollUtil.isEmpty(limitConfigs)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- Long lockCount = customerMapper.selectCountByLockStatusAndOwnerUserId(true, userId);
|
|
|
- Integer maxCount = CollectionUtils.getMaxValue(limitConfigs, CrmCustomerLimitConfigDO::getMaxCount);
|
|
|
- assert maxCount != null;
|
|
|
- if (lockCount >= maxCount) {
|
|
|
- throw exception(CUSTOMER_LOCK_EXCEED_LIMIT);
|
|
|
- }
|
|
|
- }
|
|
|
+ // ==================== 公海相关操作 ====================
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- @LogRecord(type = CRM_CUSTOMER, subType = "客户放入公海", bizNo = "{{#id}}", success = "将客户放入了公海") // TODO @puhui999:将客户【】放入了公海
|
|
|
+ @LogRecord(type = CRM_CUSTOMER_TYPE, subType = CRM_CUSTOMER_POOL_SUB_TYPE, bizNo = "{{#id}}", success = CRM_CUSTOMER_POOL_SUCCESS)
|
|
|
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#id", level = CrmPermissionLevelEnum.OWNER)
|
|
|
public void putCustomerPool(Long id) {
|
|
|
// 1. 校验存在
|
|
@@ -259,16 +195,18 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
|
|
|
permissionService.deletePermission(CrmBizTypeEnum.CRM_CUSTOMER.getType(), customer.getId(),
|
|
|
CrmPermissionLevelEnum.OWNER.getLevel());
|
|
|
// TODO @puhui999:联系人的负责人,也要设置为 null;这块和领取是对应的;因为领取后,负责人也要关联过来;
|
|
|
+
|
|
|
+ // 记录操作日志上下文
|
|
|
+ LogRecordContext.putVariable("customerName", customer.getName());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- // TODO @puhui999:权限校验
|
|
|
+ public void receiveCustomer(List<Long> ids, Long ownerUserId, Boolean isReceive) {
|
|
|
+ if (!isReceive && !CrmPermissionUtils.isCrmAdmin()) { // 只有管理员可以分配
|
|
|
+ throw exception(CRM_PERMISSION_DENIED, CrmBizTypeEnum.CRM_CUSTOMER.getName());
|
|
|
+ }
|
|
|
|
|
|
- // TODO @puhui999:如果是分配,操作日志是 “将客户【】分配给【】”
|
|
|
- // TODO @puhui999:如果是领取,操作日志是“领取客户【】”;
|
|
|
- // TODO @puhui999:如果是多条,则需要记录多条操作日志;不然 bizId 不好关联
|
|
|
- public void receiveCustomer(List<Long> ids, Long ownerUserId) {
|
|
|
// 1.1 校验存在
|
|
|
List<CrmCustomerDO> customers = customerMapper.selectBatchIds(ids);
|
|
|
if (customers.size() != ids.size()) {
|
|
@@ -303,6 +241,55 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
|
|
|
// 2.3 创建负责人数据权限
|
|
|
permissionService.createPermissionBatch(createPermissions);
|
|
|
// TODO @芋艿:要不要处理关联的联系人???
|
|
|
+
|
|
|
+ // 3. 记录操作日志
|
|
|
+ AdminUserRespDTO user = null;
|
|
|
+ if (!isReceive) {
|
|
|
+ user = adminUserApi.getUser(ownerUserId);
|
|
|
+ }
|
|
|
+ for (CrmCustomerDO customer : customers) {
|
|
|
+ getSelf().receiveCustomerLog(customer, user == null ? null : user.getNickname());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @LogRecord(type = CRM_CUSTOMER_TYPE, subType = CRM_CUSTOMER_RECEIVE_SUB_TYPE, bizNo = "{{#customer.id}}", success = CRM_CUSTOMER_RECEIVE_SUCCESS)
|
|
|
+ public void receiveCustomerLog(CrmCustomerDO customer, String ownerUserName) {
|
|
|
+ // 记录操作日志上下文
|
|
|
+ LogRecordContext.putVariable("customer", customer);
|
|
|
+ LogRecordContext.putVariable("ownerUserName", ownerUserName);
|
|
|
+ }
|
|
|
+
|
|
|
+ //======================= 查询相关 =======================
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#id", level = CrmPermissionLevelEnum.READ)
|
|
|
+ public CrmCustomerDO getCustomer(Long id) {
|
|
|
+ return customerMapper.selectById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<CrmCustomerDO> getCustomerList(Collection<Long> ids) {
|
|
|
+ if (CollUtil.isEmpty(ids)) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ return customerMapper.selectBatchIds(ids);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PageResult<CrmCustomerDO> getCustomerPage(CrmCustomerPageReqVO pageReqVO, Long userId) {
|
|
|
+ return customerMapper.selectPage(pageReqVO, userId);
|
|
|
+ }
|
|
|
+
|
|
|
+ //======================= 校验相关 =======================
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验客户是否存在
|
|
|
+ *
|
|
|
+ * @param customerId 客户 id
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void validateCustomer(Long customerId) {
|
|
|
+ validateCustomerExists(customerId);
|
|
|
}
|
|
|
|
|
|
private void validateCustomerOwnerExists(CrmCustomerDO customer, Boolean pool) {
|
|
@@ -314,11 +301,19 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
|
|
|
throw exception(CUSTOMER_IN_POOL, customer.getName());
|
|
|
}
|
|
|
// 负责人已存在
|
|
|
- if (customer.getOwnerUserId() != null) {
|
|
|
+ if (!pool && customer.getOwnerUserId() != null) {
|
|
|
throw exception(CUSTOMER_OWNER_EXISTS, customer.getName());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private CrmCustomerDO validateCustomerExists(Long id) {
|
|
|
+ CrmCustomerDO customerDO = customerMapper.selectById(id);
|
|
|
+ if (customerDO == null) {
|
|
|
+ throw exception(CUSTOMER_NOT_EXISTS);
|
|
|
+ }
|
|
|
+ return customerDO;
|
|
|
+ }
|
|
|
+
|
|
|
private void validateCustomerIsLocked(CrmCustomerDO customer, Boolean pool) {
|
|
|
if (customer.getLockStatus()) {
|
|
|
throw exception(pool ? CUSTOMER_LOCKED_PUT_POOL_FAIL : CUSTOMER_LOCKED, customer.getName());
|
|
@@ -331,9 +326,55 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public List<CrmCustomerDO> getCustomerList() {
|
|
|
- return customerMapper.selectList();
|
|
|
+ /**
|
|
|
+ * 校验用户拥有的客户数量,是否到达上限
|
|
|
+ *
|
|
|
+ * @param userId 用户编号
|
|
|
+ * @param newCount 附加数量
|
|
|
+ */
|
|
|
+ private void validateCustomerExceedOwnerLimit(Long userId, int newCount) {
|
|
|
+ List<CrmCustomerLimitConfigDO> limitConfigs = customerLimitConfigService.getCustomerLimitConfigListByUserId(
|
|
|
+ CUSTOMER_OWNER_LIMIT.getType(), userId);
|
|
|
+ if (CollUtil.isEmpty(limitConfigs)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Long ownerCount = customerMapper.selectCountByDealStatusAndOwnerUserId(null, userId);
|
|
|
+ Long dealOwnerCount = customerMapper.selectCountByDealStatusAndOwnerUserId(true, userId);
|
|
|
+ limitConfigs.forEach(limitConfig -> {
|
|
|
+ long nowCount = limitConfig.getDealCountEnabled() ? ownerCount : ownerCount - dealOwnerCount;
|
|
|
+ if (nowCount + newCount > limitConfig.getMaxCount()) {
|
|
|
+ throw exception(CUSTOMER_OWNER_EXCEED_LIMIT);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验用户锁定的客户数量,是否到达上限
|
|
|
+ *
|
|
|
+ * @param userId 用户编号
|
|
|
+ */
|
|
|
+ private void validateCustomerExceedLockLimit(Long userId) {
|
|
|
+ List<CrmCustomerLimitConfigDO> limitConfigs = customerLimitConfigService.getCustomerLimitConfigListByUserId(
|
|
|
+ CUSTOMER_LOCK_LIMIT.getType(), userId);
|
|
|
+ if (CollUtil.isEmpty(limitConfigs)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Long lockCount = customerMapper.selectCountByLockStatusAndOwnerUserId(true, userId);
|
|
|
+ Integer maxCount = CollectionUtils.getMaxValue(limitConfigs, CrmCustomerLimitConfigDO::getMaxCount);
|
|
|
+ assert maxCount != null;
|
|
|
+ if (lockCount >= maxCount) {
|
|
|
+ throw exception(CUSTOMER_LOCK_EXCEED_LIMIT);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获得自身的代理对象,解决 AOP 生效问题
|
|
|
+ *
|
|
|
+ * @return 自己
|
|
|
+ */
|
|
|
+ private CrmCustomerServiceImpl getSelf() {
|
|
|
+ return SpringUtil.getBean(getClass());
|
|
|
}
|
|
|
|
|
|
}
|