Commit 9bac10c6f77455e532995bb8f44ddbbc97321780
1 parent
a8c14614
完善客户锁定/解锁接口,校验锁定上限
Showing
10 changed files
with
111 additions
and
18 deletions
yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/ErrorCodeConstants.java
| ... | ... | @@ -40,6 +40,12 @@ public interface ErrorCodeConstants { |
| 40 | 40 | ErrorCode CUSTOMER_LOCKED_PUT_POOL_FAIL = new ErrorCode(1_020_006_005, "客户【{}】放入公海失败,原因:客户已锁定"); |
| 41 | 41 | ErrorCode CUSTOMER_UPDATE_OWNER_USER_FAIL = new ErrorCode(1_020_006_006, "更新客户【{}】负责人失败, 原因:系统异常"); |
| 42 | 42 | |
| 43 | + ErrorCode CUSTOMER_UNLOCK_STATUS_NO_REPETITION = new ErrorCode(1_020_006_001, "无需重复操作锁定/解锁状态"); | |
| 44 | + | |
| 45 | + ErrorCode CUSTOMER_NO_DEPARTMENT_FOUND = new ErrorCode(1_020_006_002, "操作失败,请先绑定部门再进行操作"); | |
| 46 | + | |
| 47 | + ErrorCode CUSTOMER_EXCEED_LOCK_LIMIT = new ErrorCode(1_020_006_003, "操作失败,超出锁定规则上限"); | |
| 48 | + | |
| 43 | 49 | // ========== 权限管理 1_020_007_000 ========== |
| 44 | 50 | ErrorCode CRM_PERMISSION_NOT_EXISTS = new ErrorCode(1_020_007_000, "数据权限不存在"); |
| 45 | 51 | ErrorCode CRM_PERMISSION_DENIED = new ErrorCode(1_020_007_001, "{}操作失败,原因:没有权限"); | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/CrmCustomerController.java
| ... | ... | @@ -134,8 +134,8 @@ public class CrmCustomerController { |
| 134 | 134 | @PutMapping("/lock") |
| 135 | 135 | @Operation(summary = "锁定/解锁客户") |
| 136 | 136 | @PreAuthorize("@ss.hasPermission('crm:customer:update')") |
| 137 | - public CommonResult<Boolean> lockCustomer(@Valid @RequestBody CrmCustomerUpdateReqVO updateReqVO) { | |
| 138 | - customerService.lockCustomer(updateReqVO); | |
| 137 | + public CommonResult<Boolean> lockCustomer(@Valid @RequestBody CrmCustomerLockReqVO lockReqVO) { | |
| 138 | + customerService.lockCustomer(lockReqVO); | |
| 139 | 139 | return success(true); |
| 140 | 140 | } |
| 141 | 141 | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/CrmCustomerLockReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.crm.controller.admin.customer.vo; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.Data; | |
| 5 | + | |
| 6 | +@Schema(description = "管理后台 - CRM 客户锁定/解锁 Request VO") | |
| 7 | +@Data | |
| 8 | +public class CrmCustomerLockReqVO { | |
| 9 | + | |
| 10 | + @Schema(description = "客户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "13563") | |
| 11 | + private Long id; | |
| 12 | + | |
| 13 | + @Schema(description = "客户锁定状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "0") | |
| 14 | + private Boolean lockStatus; | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | +} | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/limitconfig/CrmCustomerLimitConfigCreateReqVO.java
| ... | ... | @@ -5,10 +5,16 @@ import lombok.Data; |
| 5 | 5 | import lombok.EqualsAndHashCode; |
| 6 | 6 | import lombok.ToString; |
| 7 | 7 | |
| 8 | +import java.util.List; | |
| 9 | + | |
| 8 | 10 | @Schema(description = "管理后台 - 客户限制配置创建 Request VO") |
| 9 | 11 | @Data |
| 10 | 12 | @EqualsAndHashCode(callSuper = true) |
| 11 | 13 | @ToString(callSuper = true) |
| 12 | 14 | public class CrmCustomerLimitConfigCreateReqVO extends CrmCustomerLimitConfigBaseVO { |
| 13 | 15 | |
| 16 | + | |
| 17 | + @Schema(description = "规则适用人群") | |
| 18 | + private Long userId; | |
| 19 | + | |
| 14 | 20 | } | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/customer/CrmCustomerConvert.java
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/customer/CrmCustomerLimitConfigMapper.java
| ... | ... | @@ -3,10 +3,14 @@ package cn.iocoder.yudao.module.crm.dal.mysql.customer; |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | 4 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 5 | 5 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| 6 | +import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigCreateReqVO; | |
| 6 | 7 | import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigPageReqVO; |
| 7 | 8 | import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerLimitConfigDO; |
| 8 | 9 | import org.apache.ibatis.annotations.Mapper; |
| 9 | 10 | |
| 11 | +import java.util.Arrays; | |
| 12 | +import java.util.stream.Collectors; | |
| 13 | + | |
| 10 | 14 | /** |
| 11 | 15 | * 客户限制配置 Mapper |
| 12 | 16 | * |
| ... | ... | @@ -21,4 +25,16 @@ public interface CrmCustomerLimitConfigMapper extends BaseMapperX<CrmCustomerLim |
| 21 | 25 | .orderByDesc(CrmCustomerLimitConfigDO::getId)); |
| 22 | 26 | } |
| 23 | 27 | |
| 28 | + default CrmCustomerLimitConfigDO selectByLimitConfig(CrmCustomerLimitConfigCreateReqVO reqVO){ | |
| 29 | + LambdaQueryWrapperX<CrmCustomerLimitConfigDO> queryWrapper = new LambdaQueryWrapperX<>(); | |
| 30 | + queryWrapper.apply("FIND_IN_SET({0}, user_ids) > 0", reqVO.getUserId()); | |
| 31 | + queryWrapper.eq(CrmCustomerLimitConfigDO::getType, reqVO.getType()); | |
| 32 | + // 将部门ID列表转换成逗号分隔的字符串 | |
| 33 | + String deptIdsString = reqVO.getDeptIds().stream() | |
| 34 | + .map(String::valueOf) | |
| 35 | + .collect(Collectors.joining(",")); | |
| 36 | + queryWrapper.apply("FIND_IN_SET({0}, dept_ids) > 0", deptIdsString); | |
| 37 | + return selectOne(queryWrapper); | |
| 38 | + } | |
| 39 | + | |
| 24 | 40 | } | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerLimitConfigService.java
| ... | ... | @@ -53,4 +53,9 @@ public interface CrmCustomerLimitConfigService { |
| 53 | 53 | */ |
| 54 | 54 | PageResult<CrmCustomerLimitConfigDO> getCustomerLimitConfigPage(CrmCustomerLimitConfigPageReqVO pageReqVO); |
| 55 | 55 | |
| 56 | + /** | |
| 57 | + * 查询当前登录人客户限制配置 | |
| 58 | + */ | |
| 59 | + CrmCustomerLimitConfigDO selectByLimitConfig(CrmCustomerLimitConfigCreateReqVO configReqVO); | |
| 60 | + | |
| 56 | 61 | } | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerLimitConfigServiceImpl.java
| ... | ... | @@ -90,4 +90,9 @@ public class CrmCustomerLimitConfigServiceImpl implements CrmCustomerLimitConfig |
| 90 | 90 | adminUserApi.validateUserList(userIds); |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | + @Override | |
| 94 | + public CrmCustomerLimitConfigDO selectByLimitConfig(CrmCustomerLimitConfigCreateReqVO configReqVO) { | |
| 95 | + return customerLimitConfigMapper.selectByLimitConfig(configReqVO); | |
| 96 | + } | |
| 97 | + | |
| 93 | 98 | } | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerService.java
| 1 | 1 | package cn.iocoder.yudao.module.crm.service.customer; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | -import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerCreateReqVO; | |
| 5 | -import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerPageReqVO; | |
| 6 | -import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerTransferReqVO; | |
| 7 | -import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerUpdateReqVO; | |
| 4 | +import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.*; | |
| 8 | 5 | import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; |
| 9 | 6 | import jakarta.validation.Valid; |
| 10 | 7 | |
| ... | ... | @@ -85,9 +82,9 @@ public interface CrmCustomerService { |
| 85 | 82 | /** |
| 86 | 83 | * 锁定/解锁客户 |
| 87 | 84 | * |
| 88 | - * @param updateReqVO 更新信息 | |
| 85 | + * @param lockReqVO 更新信息 | |
| 89 | 86 | */ |
| 90 | - void lockCustomer(@Valid CrmCustomerUpdateReqVO updateReqVO); | |
| 87 | + void lockCustomer(@Valid CrmCustomerLockReqVO lockReqVO); | |
| 91 | 88 | |
| 92 | 89 | // ==================== 公海相关操作 ==================== |
| 93 | 90 | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerServiceImpl.java
| ... | ... | @@ -2,12 +2,11 @@ package cn.iocoder.yudao.module.crm.service.customer; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | -import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerCreateReqVO; | |
| 6 | -import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerPageReqVO; | |
| 7 | -import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerTransferReqVO; | |
| 8 | -import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerUpdateReqVO; | |
| 5 | +import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.*; | |
| 6 | +import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigCreateReqVO; | |
| 9 | 7 | import cn.iocoder.yudao.module.crm.convert.customer.CrmCustomerConvert; |
| 10 | 8 | import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; |
| 9 | +import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerLimitConfigDO; | |
| 11 | 10 | import cn.iocoder.yudao.module.crm.dal.mysql.customer.CrmCustomerMapper; |
| 12 | 11 | import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum; |
| 13 | 12 | import cn.iocoder.yudao.module.crm.enums.permission.CrmPermissionLevelEnum; |
| ... | ... | @@ -15,6 +14,7 @@ import cn.iocoder.yudao.module.crm.framework.core.annotations.CrmPermission; |
| 15 | 14 | import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService; |
| 16 | 15 | import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateReqBO; |
| 17 | 16 | import cn.iocoder.yudao.module.system.api.user.AdminUserApi; |
| 17 | +import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; | |
| 18 | 18 | import jakarta.annotation.Resource; |
| 19 | 19 | import org.springframework.stereotype.Service; |
| 20 | 20 | import org.springframework.transaction.annotation.Transactional; |
| ... | ... | @@ -23,7 +23,10 @@ import org.springframework.validation.annotation.Validated; |
| 23 | 23 | import java.util.*; |
| 24 | 24 | |
| 25 | 25 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 26 | +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; | |
| 26 | 27 | import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*; |
| 28 | +import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CUSTOMER_EXCEED_LOCK_LIMIT; | |
| 29 | +import static cn.iocoder.yudao.module.crm.enums.customer.CrmCustomerLimitConfigTypeEnum.CUSTOMER_LOCK_LIMIT; | |
| 27 | 30 | import static java.util.Collections.singletonList; |
| 28 | 31 | |
| 29 | 32 | /** |
| ... | ... | @@ -43,6 +46,8 @@ public class CrmCustomerServiceImpl implements CrmCustomerService { |
| 43 | 46 | |
| 44 | 47 | @Resource |
| 45 | 48 | private AdminUserApi adminUserApi; |
| 49 | + @Resource | |
| 50 | + private CrmCustomerLimitConfigService crmCustomerLimitConfigService; | |
| 46 | 51 | |
| 47 | 52 | @Override |
| 48 | 53 | @Transactional(rollbackFor = Exception.class) |
| ... | ... | @@ -142,14 +147,47 @@ public class CrmCustomerServiceImpl implements CrmCustomerService { |
| 142 | 147 | } |
| 143 | 148 | |
| 144 | 149 | @Override |
| 145 | - public void lockCustomer(CrmCustomerUpdateReqVO updateReqVO) { | |
| 146 | - // 校验存在 | |
| 147 | - validateCustomerExists(updateReqVO.getId()); | |
| 148 | - // TODO @Joey:可以校验下,如果已经对应的锁定状态,报个业务异常;原因是:后续这个业务会记录操作日志,会记录多了; | |
| 149 | - // TODO @芋艿:业务完善,增加锁定上限; | |
| 150 | + public void lockCustomer(CrmCustomerLockReqVO lockReqVO) { | |
| 151 | + // 校验当前客户是否存在 | |
| 152 | + validateCustomerExists(lockReqVO.getId()); | |
| 153 | + | |
| 154 | + CrmCustomerDO customerDO = customerMapper.selectById(lockReqVO.getId()); | |
| 155 | + | |
| 156 | + // 校验当前是否重复操作锁定/解锁状态 | |
| 157 | + if (customerDO.getLockStatus().equals(lockReqVO.getLockStatus())) { | |
| 158 | + throw exception(CUSTOMER_UNLOCK_STATUS_NO_REPETITION); | |
| 159 | + } | |
| 160 | + | |
| 161 | + // 获取当前登录信息,开始校验锁定上限 | |
| 162 | + AdminUserRespDTO userRespDTO = adminUserApi.getUser(getLoginUserId()); | |
| 163 | + | |
| 164 | + if (userRespDTO.getDeptId() == null || userRespDTO.getId() == null) { | |
| 165 | + // 如有入参为空,提示业务异常 | |
| 166 | + throw exception(CUSTOMER_NO_DEPARTMENT_FOUND); | |
| 167 | + } | |
| 168 | + | |
| 169 | + // 开始校验规则限制 | |
| 170 | + List<Long> userDeptIds = Collections.singletonList(userRespDTO.getDeptId()); | |
| 171 | + | |
| 172 | + CrmCustomerLimitConfigCreateReqVO configReqVO = new CrmCustomerLimitConfigCreateReqVO(); | |
| 173 | + configReqVO.setUserId(userRespDTO.getId()); | |
| 174 | + configReqVO.setDeptIds(userDeptIds); | |
| 175 | + configReqVO.setType(CUSTOMER_LOCK_LIMIT.getCode()); | |
| 176 | + | |
| 177 | + CrmCustomerLimitConfigDO crmCustomerLimitConfigDO = crmCustomerLimitConfigService.selectByLimitConfig(configReqVO); | |
| 178 | + | |
| 179 | + // 统计当前用户已锁定客户数量 | |
| 180 | + List<CrmCustomerDO> crmCustomerDOS = customerMapper.selectList("owner_user_id", getLoginUserId()); | |
| 181 | + long customerLockCount = crmCustomerDOS.stream().filter(CrmCustomerDO::getLockStatus).count(); | |
| 182 | + | |
| 183 | + // 锁定操作的时候校验当前用户可锁定客户的上限 | |
| 184 | + if (crmCustomerLimitConfigDO != null && lockReqVO.getLockStatus() && customerLockCount >= crmCustomerLimitConfigDO.getMaxCount()) { | |
| 185 | + // 超出锁定数量上限,提示业务异常 | |
| 186 | + throw exception(CUSTOMER_EXCEED_LOCK_LIMIT); | |
| 187 | + } | |
| 150 | 188 | |
| 151 | 189 | // 更新 |
| 152 | - CrmCustomerDO updateObj = CrmCustomerConvert.INSTANCE.convert(updateReqVO); | |
| 190 | + CrmCustomerDO updateObj = CrmCustomerConvert.INSTANCE.convert(lockReqVO); | |
| 153 | 191 | customerMapper.updateById(updateObj); |
| 154 | 192 | } |
| 155 | 193 | ... | ... |