Merge branch 'develop' of https://gitee.com/zh8790/ruoyi-vue-pro_develop into develop
# Conflicts: # yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerServiceImpl.java
This commit is contained in:
commit
0253846fdf
@ -92,6 +92,8 @@
|
||||
|
||||
如果你想把【完整版】的功能,迁移到【精简版】,可以参考 [《迁移功能到精简版》](https://doc.iocoder.cn/migrate-module/) 文档。
|
||||
|
||||
如果你想把【完整版】的功能,迁移到【精简版】,可以参考 [《迁移功能到精简版》](https://doc.iocoder.cn/migrate-module/) 文档。
|
||||
|
||||
## 😎 开源协议
|
||||
|
||||
**为什么推荐使用本项目?**
|
||||
|
@ -40,6 +40,12 @@ public interface ErrorCodeConstants {
|
||||
ErrorCode CUSTOMER_LOCKED_PUT_POOL_FAIL = new ErrorCode(1_020_006_005, "客户【{}】放入公海失败,原因:客户已锁定");
|
||||
ErrorCode CUSTOMER_UPDATE_OWNER_USER_FAIL = new ErrorCode(1_020_006_006, "更新客户【{}】负责人失败, 原因:系统异常");
|
||||
|
||||
ErrorCode CUSTOMER_UNLOCK_STATUS_NO_REPETITION = new ErrorCode(1_020_006_001, "无需重复操作锁定/解锁状态");
|
||||
|
||||
ErrorCode CUSTOMER_NO_DEPARTMENT_FOUND = new ErrorCode(1_020_006_002, "操作失败,请先绑定部门再进行操作");
|
||||
|
||||
ErrorCode CUSTOMER_EXCEED_LOCK_LIMIT = new ErrorCode(1_020_006_003, "操作失败,超出锁定规则上限");
|
||||
|
||||
// ========== 权限管理 1_020_007_000 ==========
|
||||
ErrorCode CRM_PERMISSION_NOT_EXISTS = new ErrorCode(1_020_007_000, "数据权限不存在");
|
||||
ErrorCode CRM_PERMISSION_DENIED = new ErrorCode(1_020_007_001, "{}操作失败,原因:没有权限");
|
||||
|
@ -159,8 +159,8 @@ public class CrmCustomerController {
|
||||
@Operation(summary = "锁定/解锁客户")
|
||||
@OperateLog(enable = false) // TODO 关闭原有日志记录
|
||||
@PreAuthorize("@ss.hasPermission('crm:customer:update')")
|
||||
public CommonResult<Boolean> lockCustomer(@Valid @RequestBody CrmCustomerUpdateReqVO updateReqVO) {
|
||||
customerService.lockCustomer(updateReqVO);
|
||||
public CommonResult<Boolean> lockCustomer(@Valid @RequestBody CrmCustomerLockReqVO lockReqVO) {
|
||||
customerService.lockCustomer(lockReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,18 @@
|
||||
package cn.iocoder.yudao.module.crm.controller.admin.customer.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Schema(description = "管理后台 - CRM 客户锁定/解锁 Request VO")
|
||||
@Data
|
||||
public class CrmCustomerLockReqVO {
|
||||
|
||||
@Schema(description = "客户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "13563")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "客户锁定状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "0")
|
||||
private Boolean lockStatus;
|
||||
|
||||
|
||||
|
||||
}
|
@ -5,10 +5,16 @@ import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Schema(description = "管理后台 - 客户限制配置创建 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class CrmCustomerLimitConfigCreateReqVO extends CrmCustomerLimitConfigBaseVO {
|
||||
|
||||
|
||||
@Schema(description = "规则适用人群")
|
||||
private Long userId;
|
||||
|
||||
}
|
||||
|
@ -79,4 +79,6 @@ public interface CrmCustomerConvert {
|
||||
|
||||
List<CrmCustomerQueryAllRespVO> convertQueryAll(List<CrmCustomerDO> crmCustomerDO);
|
||||
|
||||
CrmCustomerDO convert(CrmCustomerLockReqVO lockReqVO);
|
||||
|
||||
}
|
||||
|
@ -3,10 +3,14 @@ package cn.iocoder.yudao.module.crm.dal.mysql.customer;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigCreateReqVO;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigPageReqVO;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerLimitConfigDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 客户限制配置 Mapper
|
||||
*
|
||||
@ -21,4 +25,16 @@ public interface CrmCustomerLimitConfigMapper extends BaseMapperX<CrmCustomerLim
|
||||
.orderByDesc(CrmCustomerLimitConfigDO::getId));
|
||||
}
|
||||
|
||||
default CrmCustomerLimitConfigDO selectByLimitConfig(CrmCustomerLimitConfigCreateReqVO reqVO){
|
||||
LambdaQueryWrapperX<CrmCustomerLimitConfigDO> queryWrapper = new LambdaQueryWrapperX<>();
|
||||
queryWrapper.apply("FIND_IN_SET({0}, user_ids) > 0", reqVO.getUserId());
|
||||
queryWrapper.eq(CrmCustomerLimitConfigDO::getType, reqVO.getType());
|
||||
// 将部门ID列表转换成逗号分隔的字符串
|
||||
String deptIdsString = reqVO.getDeptIds().stream()
|
||||
.map(String::valueOf)
|
||||
.collect(Collectors.joining(","));
|
||||
queryWrapper.apply("FIND_IN_SET({0}, dept_ids) > 0", deptIdsString);
|
||||
return selectOne(queryWrapper);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -53,4 +53,9 @@ public interface CrmCustomerLimitConfigService {
|
||||
*/
|
||||
PageResult<CrmCustomerLimitConfigDO> getCustomerLimitConfigPage(CrmCustomerLimitConfigPageReqVO pageReqVO);
|
||||
|
||||
/**
|
||||
* 查询当前登录人客户限制配置
|
||||
*/
|
||||
CrmCustomerLimitConfigDO selectByLimitConfig(CrmCustomerLimitConfigCreateReqVO configReqVO);
|
||||
|
||||
}
|
||||
|
@ -90,4 +90,9 @@ public class CrmCustomerLimitConfigServiceImpl implements CrmCustomerLimitConfig
|
||||
adminUserApi.validateUserList(userIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CrmCustomerLimitConfigDO selectByLimitConfig(CrmCustomerLimitConfigCreateReqVO configReqVO) {
|
||||
return customerLimitConfigMapper.selectByLimitConfig(configReqVO);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,10 +1,7 @@
|
||||
package cn.iocoder.yudao.module.crm.service.customer;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerCreateReqVO;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerPageReqVO;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerTransferReqVO;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.*;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
@ -85,9 +82,9 @@ public interface CrmCustomerService {
|
||||
/**
|
||||
* 锁定/解锁客户
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
* @param lockReqVO 更新信息
|
||||
*/
|
||||
void lockCustomer(@Valid CrmCustomerUpdateReqVO updateReqVO);
|
||||
void lockCustomer(@Valid CrmCustomerLockReqVO lockReqVO);
|
||||
|
||||
// ==================== 公海相关操作 ====================
|
||||
|
||||
|
@ -7,8 +7,11 @@ import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerCreat
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerPageReqVO;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerTransferReqVO;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.*;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigCreateReqVO;
|
||||
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;
|
||||
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;
|
||||
@ -16,9 +19,11 @@ import cn.iocoder.yudao.module.crm.framework.permission.core.annotations.CrmPerm
|
||||
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;
|
||||
import com.mzt.logapi.starter.annotation.LogRecord;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@ -28,9 +33,13 @@ import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||
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.ErrorCodeConstants.CUSTOMER_EXCEED_LOCK_LIMIT;
|
||||
import static cn.iocoder.yudao.module.crm.enums.customer.CrmCustomerLimitConfigTypeEnum.CUSTOMER_LOCK_LIMIT;
|
||||
import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.CRM_CUSTOMER;
|
||||
import static java.util.Collections.singletonList;
|
||||
|
||||
/**
|
||||
@ -47,6 +56,8 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
|
||||
|
||||
@Resource
|
||||
private CrmPermissionService crmPermissionService;
|
||||
@Resource
|
||||
private CrmCustomerLimitConfigService crmCustomerLimitConfigService;
|
||||
|
||||
@Resource
|
||||
private AdminUserApi adminUserApi;
|
||||
@ -163,14 +174,47 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
|
||||
|
||||
@Override
|
||||
@LogRecord(type = CRM_CUSTOMER, subType = "锁定/解锁客户", bizNo = "{{#updateReqVO.id}}", success = "锁定了客户")
|
||||
public void lockCustomer(CrmCustomerUpdateReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateCustomerExists(updateReqVO.getId());
|
||||
// TODO @Joey:可以校验下,如果已经对应的锁定状态,报个业务异常;原因是:后续这个业务会记录操作日志,会记录多了;
|
||||
// TODO @芋艿:业务完善,增加锁定上限;
|
||||
public void lockCustomer(CrmCustomerLockReqVO lockReqVO) {
|
||||
// 校验当前客户是否存在
|
||||
validateCustomerExists(lockReqVO.getId());
|
||||
|
||||
CrmCustomerDO customerDO = customerMapper.selectById(lockReqVO.getId());
|
||||
|
||||
// 校验当前是否重复操作锁定/解锁状态
|
||||
if (customerDO.getLockStatus().equals(lockReqVO.getLockStatus())) {
|
||||
throw exception(CUSTOMER_UNLOCK_STATUS_NO_REPETITION);
|
||||
}
|
||||
|
||||
// 获取当前登录信息,开始校验锁定上限
|
||||
AdminUserRespDTO userRespDTO = adminUserApi.getUser(getLoginUserId());
|
||||
|
||||
if (userRespDTO.getDeptId() == null || userRespDTO.getId() == null) {
|
||||
// 如有入参为空,提示业务异常
|
||||
throw exception(CUSTOMER_NO_DEPARTMENT_FOUND);
|
||||
}
|
||||
|
||||
// 开始校验规则限制
|
||||
List<Long> userDeptIds = Collections.singletonList(userRespDTO.getDeptId());
|
||||
|
||||
CrmCustomerLimitConfigCreateReqVO configReqVO = new CrmCustomerLimitConfigCreateReqVO();
|
||||
configReqVO.setUserId(userRespDTO.getId());
|
||||
configReqVO.setDeptIds(userDeptIds);
|
||||
configReqVO.setType(CUSTOMER_LOCK_LIMIT.getCode());
|
||||
|
||||
CrmCustomerLimitConfigDO crmCustomerLimitConfigDO = crmCustomerLimitConfigService.selectByLimitConfig(configReqVO);
|
||||
|
||||
// 统计当前用户已锁定客户数量
|
||||
List<CrmCustomerDO> crmCustomerDOS = customerMapper.selectList("owner_user_id", getLoginUserId());
|
||||
long customerLockCount = crmCustomerDOS.stream().filter(CrmCustomerDO::getLockStatus).count();
|
||||
|
||||
// 锁定操作的时候校验当前用户可锁定客户的上限
|
||||
if (crmCustomerLimitConfigDO != null && lockReqVO.getLockStatus() && customerLockCount >= crmCustomerLimitConfigDO.getMaxCount()) {
|
||||
// 超出锁定数量上限,提示业务异常
|
||||
throw exception(CUSTOMER_EXCEED_LOCK_LIMIT);
|
||||
}
|
||||
|
||||
// 更新
|
||||
CrmCustomerDO updateObj = CrmCustomerConvert.INSTANCE.convert(updateReqVO);
|
||||
CrmCustomerDO updateObj = CrmCustomerConvert.INSTANCE.convert(lockReqVO);
|
||||
customerMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user