mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 23:31:52 +08:00
完善客户锁定/解锁接口,校验锁定上限
This commit is contained in:
parent
a8c14614ab
commit
9bac10c6f7
@ -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, "{}操作失败,原因:没有权限");
|
||||
|
@ -134,8 +134,8 @@ public class CrmCustomerController {
|
||||
@PutMapping("/lock")
|
||||
@Operation(summary = "锁定/解锁客户")
|
||||
@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);
|
||||
|
||||
// ==================== 公海相关操作 ====================
|
||||
|
||||
|
@ -2,12 +2,11 @@ package cn.iocoder.yudao.module.crm.service.customer;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
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.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;
|
||||
@ -15,6 +14,7 @@ import cn.iocoder.yudao.module.crm.framework.core.annotations.CrmPermission;
|
||||
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 jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@ -23,7 +23,10 @@ import org.springframework.validation.annotation.Validated;
|
||||
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.ErrorCodeConstants.CUSTOMER_EXCEED_LOCK_LIMIT;
|
||||
import static cn.iocoder.yudao.module.crm.enums.customer.CrmCustomerLimitConfigTypeEnum.CUSTOMER_LOCK_LIMIT;
|
||||
import static java.util.Collections.singletonList;
|
||||
|
||||
/**
|
||||
@ -43,6 +46,8 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
|
||||
|
||||
@Resource
|
||||
private AdminUserApi adminUserApi;
|
||||
@Resource
|
||||
private CrmCustomerLimitConfigService crmCustomerLimitConfigService;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@ -142,14 +147,47 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
|
||||
}
|
||||
|
||||
@Override
|
||||
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