Commit b41d469d46cd0dcbb22d6ae68a7c4dfcc0ccc301
1 parent
77d7bcc7
crm-客户管理:新增客户放入公海和领取公海客户
Showing
7 changed files
with
138 additions
and
117 deletions
yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/ErrorCodeConstants.java
| @@ -37,6 +37,9 @@ public interface ErrorCodeConstants { | @@ -37,6 +37,9 @@ public interface ErrorCodeConstants { | ||
| 37 | ErrorCode CUSTOMER_OWNER_EXISTS = new ErrorCode(1_020_006_001, "客户已存在所属负责人"); | 37 | ErrorCode CUSTOMER_OWNER_EXISTS = new ErrorCode(1_020_006_001, "客户已存在所属负责人"); |
| 38 | ErrorCode CUSTOMER_LOCKED = new ErrorCode(1_020_006_002, "客户状态已锁定"); | 38 | ErrorCode CUSTOMER_LOCKED = new ErrorCode(1_020_006_002, "客户状态已锁定"); |
| 39 | ErrorCode CUSTOMER_ALREADY_DEAL = new ErrorCode(1_020_006_003, "客户已交易"); | 39 | ErrorCode CUSTOMER_ALREADY_DEAL = new ErrorCode(1_020_006_003, "客户已交易"); |
| 40 | + ErrorCode CUSTOMER_NOT_IN_POOL = new ErrorCode(1_020_006_004, "客户领取失败,原因:不是公海客户"); | ||
| 41 | + ErrorCode CUSTOMER_IN_POOL = new ErrorCode(1_020_006_005, "客户放入公海失败,原因:已经是公海客户"); | ||
| 42 | + ErrorCode CUSTOMER_LOCKED_PUT_POOL_FAIL = new ErrorCode(1_020_006_006, "客户放入公海失败,原因:客户已锁定"); | ||
| 40 | // TODO @wanwan:这 2 个单独配置段噢 | 43 | // TODO @wanwan:这 2 个单独配置段噢 |
| 41 | ErrorCode CUSTOMER_POOL_CONFIG_ERROR = new ErrorCode(1_020_006_001, "客户公海规则设置不正确"); | 44 | ErrorCode CUSTOMER_POOL_CONFIG_ERROR = new ErrorCode(1_020_006_001, "客户公海规则设置不正确"); |
| 42 | ErrorCode CUSTOMER_LIMIT_CONFIG_NOT_EXISTS = new ErrorCode(1_020_006_002, "客户限制配置不存在"); | 45 | ErrorCode CUSTOMER_LIMIT_CONFIG_NOT_EXISTS = new ErrorCode(1_020_006_002, "客户限制配置不存在"); |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/CrmCustomerController.java
| @@ -8,8 +8,6 @@ import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | @@ -8,8 +8,6 @@ import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | ||
| 8 | import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.*; | 8 | import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.*; |
| 9 | import cn.iocoder.yudao.module.crm.convert.customer.CrmCustomerConvert; | 9 | import cn.iocoder.yudao.module.crm.convert.customer.CrmCustomerConvert; |
| 10 | import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; | 10 | import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; |
| 11 | -import cn.iocoder.yudao.module.crm.framework.core.annotations.CrmPermission; | ||
| 12 | -import cn.iocoder.yudao.module.crm.framework.enums.CrmPermissionLevelEnum; | ||
| 13 | import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService; | 11 | import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService; |
| 14 | import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService; | 12 | import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService; |
| 15 | import cn.iocoder.yudao.module.system.api.dept.DeptApi; | 13 | import cn.iocoder.yudao.module.system.api.dept.DeptApi; |
| @@ -103,23 +101,21 @@ public class CrmCustomerController { | @@ -103,23 +101,21 @@ public class CrmCustomerController { | ||
| 103 | return success(CrmCustomerConvert.INSTANCE.convert(customer, userMap, deptMap)); | 101 | return success(CrmCustomerConvert.INSTANCE.convert(customer, userMap, deptMap)); |
| 104 | } | 102 | } |
| 105 | 103 | ||
| 106 | - // TODO @puhui999:领取公海客户,是不是放到客户那更合适哈? | ||
| 107 | @PutMapping("/receive") | 104 | @PutMapping("/receive") |
| 108 | - @Operation(summary = "领取公海数据") | ||
| 109 | - @PreAuthorize("@ss.hasPermission('crm:permission:update')") | ||
| 110 | - public CommonResult<Boolean> receive(@RequestParam("bizType") Integer bizType, @RequestParam("bizId") Long bizId) { | ||
| 111 | - permissionService.receiveBiz(bizType, bizId, getLoginUserId()); | 105 | + @Operation(summary = "领取客户公海数据") |
| 106 | + @Parameter(name = "id", description = "客户编号", required = true, example = "1024") | ||
| 107 | + @PreAuthorize("@ss.hasPermission('crm:customer:update')") | ||
| 108 | + public CommonResult<Boolean> receive(@RequestParam("id") Long id) { | ||
| 109 | + customerService.receive(id, getLoginUserId()); | ||
| 112 | return success(true); | 110 | return success(true); |
| 113 | } | 111 | } |
| 114 | 112 | ||
| 115 | - // TODO @puhui999:是不是放到客户那更合适哈? | ||
| 116 | @PutMapping("/put-pool") | 113 | @PutMapping("/put-pool") |
| 117 | @Operation(summary = "数据放入公海") | 114 | @Operation(summary = "数据放入公海") |
| 118 | - @PreAuthorize("@ss.hasPermission('crm:permission:update')") | ||
| 119 | - @CrmPermission(bizTypeValue = "#bizType", bizId = "#bizId" | ||
| 120 | - , level = CrmPermissionLevelEnum.OWNER) | ||
| 121 | - public CommonResult<Boolean> putPool(@RequestParam(value = "bizType") Integer bizType, @RequestParam("bizId") Long bizId) { | ||
| 122 | - permissionService.putPool(bizType, bizId, getLoginUserId()); | 115 | + @Parameter(name = "id", description = "客户编号", required = true, example = "1024") |
| 116 | + @PreAuthorize("@ss.hasPermission('crm:customer:update')") | ||
| 117 | + public CommonResult<Boolean> putPool(@RequestParam("id") Long id) { | ||
| 118 | + customerService.putPool(id); | ||
| 123 | return success(true); | 119 | return success(true); |
| 124 | } | 120 | } |
| 125 | 121 |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/permission/CrmPermissionMapper.java
| @@ -5,7 +5,6 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | @@ -5,7 +5,6 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | ||
| 5 | import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO; | 5 | import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO; |
| 6 | import org.apache.ibatis.annotations.Mapper; | 6 | import org.apache.ibatis.annotations.Mapper; |
| 7 | 7 | ||
| 8 | -import java.util.Collection; | ||
| 9 | import java.util.List; | 8 | import java.util.List; |
| 10 | 9 | ||
| 11 | /** | 10 | /** |
| @@ -35,10 +34,10 @@ public interface CrmPermissionMapper extends BaseMapperX<CrmPermissionDO> { | @@ -35,10 +34,10 @@ public interface CrmPermissionMapper extends BaseMapperX<CrmPermissionDO> { | ||
| 35 | .eq(CrmPermissionDO::getUserId, userId)); | 34 | .eq(CrmPermissionDO::getUserId, userId)); |
| 36 | } | 35 | } |
| 37 | 36 | ||
| 38 | - default List<CrmPermissionDO> selectListByBizTypeAndBizIdsAndLevel(Integer bizType, Collection<Long> bizIds, Integer level) { | 37 | + default List<CrmPermissionDO> selectListByBizTypeAndBizIdAndLevel(Integer bizType, Long bizId, Integer level) { |
| 39 | return selectList(new LambdaQueryWrapperX<CrmPermissionDO>() | 38 | return selectList(new LambdaQueryWrapperX<CrmPermissionDO>() |
| 40 | .eq(CrmPermissionDO::getBizType, bizType) | 39 | .eq(CrmPermissionDO::getBizType, bizType) |
| 41 | - .in(CrmPermissionDO::getBizId, bizIds) | 40 | + .eq(CrmPermissionDO::getBizId, bizId) |
| 42 | .eq(CrmPermissionDO::getLevel, level)); | 41 | .eq(CrmPermissionDO::getLevel, level)); |
| 43 | } | 42 | } |
| 44 | 43 |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerService.java
| @@ -86,21 +86,38 @@ public interface CrmCustomerService { | @@ -86,21 +86,38 @@ public interface CrmCustomerService { | ||
| 86 | void lockCustomer(@Valid CrmCustomerUpdateReqVO updateReqVO); | 86 | void lockCustomer(@Valid CrmCustomerUpdateReqVO updateReqVO); |
| 87 | 87 | ||
| 88 | // TODO @xiaqing:根据 controller 的建议,改下 | 88 | // TODO @xiaqing:根据 controller 的建议,改下 |
| 89 | + | ||
| 89 | /** | 90 | /** |
| 90 | * 领取公海客户 | 91 | * 领取公海客户 |
| 91 | * | 92 | * |
| 92 | * @param ids 要领取的客户 id | 93 | * @param ids 要领取的客户 id |
| 93 | */ | 94 | */ |
| 94 | - void receive(List<Long>ids); | 95 | + void receive(List<Long> ids); |
| 95 | 96 | ||
| 96 | // TODO @xiaqing:根据 controller 的建议,改下 | 97 | // TODO @xiaqing:根据 controller 的建议,改下 |
| 98 | + | ||
| 97 | /** | 99 | /** |
| 98 | * 分配公海客户 | 100 | * 分配公海客户 |
| 99 | * | 101 | * |
| 100 | - * @param cIds 要分配的客户 id | 102 | + * @param cIds 要分配的客户 id |
| 101 | * @param ownerId 分配的负责人id | 103 | * @param ownerId 分配的负责人id |
| 102 | * @author xiaqing | 104 | * @author xiaqing |
| 103 | */ | 105 | */ |
| 104 | - void distributeByIds(List<Long>cIds,Long ownerId); | 106 | + void distributeByIds(List<Long> cIds, Long ownerId); |
| 107 | + | ||
| 108 | + /** | ||
| 109 | + * 领取公海客户 | ||
| 110 | + * | ||
| 111 | + * @param id 编号 | ||
| 112 | + * @param userId 用户编号 | ||
| 113 | + */ | ||
| 114 | + void receive(Long id, Long userId); | ||
| 115 | + | ||
| 116 | + /** | ||
| 117 | + * 客户放入公海 | ||
| 118 | + * | ||
| 119 | + * @param id 客户编号 | ||
| 120 | + */ | ||
| 121 | + void putPool(Long id); | ||
| 105 | 122 | ||
| 106 | } | 123 | } |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerServiceImpl.java
| @@ -135,8 +135,9 @@ public class CrmCustomerServiceImpl implements CrmCustomerService { | @@ -135,8 +135,9 @@ public class CrmCustomerServiceImpl implements CrmCustomerService { | ||
| 135 | 135 | ||
| 136 | @Override | 136 | @Override |
| 137 | @Transactional(rollbackFor = Exception.class) | 137 | @Transactional(rollbackFor = Exception.class) |
| 138 | + @CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#reqVO.id", level = CrmPermissionLevelEnum.OWNER) | ||
| 138 | public void transferCustomer(CrmCustomerTransferReqVO reqVO, Long userId) { | 139 | public void transferCustomer(CrmCustomerTransferReqVO reqVO, Long userId) { |
| 139 | - // 1. 校验合同是否存在 | 140 | + // 1. 校验客户是否存在 |
| 140 | validateCustomer(reqVO.getId()); | 141 | validateCustomer(reqVO.getId()); |
| 141 | 142 | ||
| 142 | // 2. 数据权限转移 | 143 | // 2. 数据权限转移 |
| @@ -169,6 +170,50 @@ public class CrmCustomerServiceImpl implements CrmCustomerService { | @@ -169,6 +170,50 @@ public class CrmCustomerServiceImpl implements CrmCustomerService { | ||
| 169 | transferCustomerOwner(cIds,ownerId); | 170 | transferCustomerOwner(cIds,ownerId); |
| 170 | } | 171 | } |
| 171 | 172 | ||
| 173 | + @Override | ||
| 174 | + @Transactional(rollbackFor = Exception.class) | ||
| 175 | + public void receive(Long id, Long userId) { | ||
| 176 | + // 1. 校验存在 | ||
| 177 | + CrmCustomerDO customer = customerMapper.selectById(id); | ||
| 178 | + if (customer == null) { | ||
| 179 | + throw exception(CUSTOMER_NOT_EXISTS); | ||
| 180 | + } | ||
| 181 | + // 1.2. 校验是否为公海数据 | ||
| 182 | + if (customer.getOwnerUserId() != null) { | ||
| 183 | + throw exception(CUSTOMER_NOT_IN_POOL); | ||
| 184 | + } | ||
| 185 | + | ||
| 186 | + // 2. 领取公海数据-设置负责人 | ||
| 187 | + customerMapper.updateById(new CrmCustomerDO().setId(customer.getId()).setOwnerUserId(userId)); | ||
| 188 | + // 3. 创建负责人数据权限 | ||
| 189 | + crmPermissionService.createPermission(new CrmPermissionCreateReqBO().setBizType(CrmBizTypeEnum.CRM_CUSTOMER.getType()) | ||
| 190 | + .setBizId(customer.getId()).setUserId(userId).setLevel(CrmPermissionLevelEnum.OWNER.getLevel())); // 设置当前操作的人为负责人 | ||
| 191 | + } | ||
| 192 | + | ||
| 193 | + @Override | ||
| 194 | + @CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#id", level = CrmPermissionLevelEnum.OWNER) | ||
| 195 | + public void putPool(Long id) { | ||
| 196 | + // 1. 校验存在 | ||
| 197 | + CrmCustomerDO customer = customerMapper.selectById(id); | ||
| 198 | + if (customer == null) { | ||
| 199 | + throw exception(CUSTOMER_NOT_EXISTS); | ||
| 200 | + } | ||
| 201 | + // 1.2. 校验是否为公海数据 | ||
| 202 | + if (customer.getOwnerUserId() == null) { | ||
| 203 | + throw exception(CUSTOMER_IN_POOL); | ||
| 204 | + } | ||
| 205 | + // 1.3. 校验客户是否锁定、 | ||
| 206 | + if (customer.getLockStatus()) { | ||
| 207 | + throw exception(CUSTOMER_LOCKED_PUT_POOL_FAIL); | ||
| 208 | + } | ||
| 209 | + | ||
| 210 | + // 2. 公海数据-设置负责人 NULL | ||
| 211 | + customerMapper.updateById(new CrmCustomerDO().setId(customer.getId()).setOwnerUserId(null)); | ||
| 212 | + // 3. 删除负责人数据权限 | ||
| 213 | + crmPermissionService.deletePermission(CrmBizTypeEnum.CRM_CUSTOMER.getType(), customer.getId(), | ||
| 214 | + CrmPermissionLevelEnum.OWNER.getLevel()); | ||
| 215 | + } | ||
| 216 | + | ||
| 172 | private void transferCustomerOwner(List <Long> cIds, Long ownerId){ | 217 | private void transferCustomerOwner(List <Long> cIds, Long ownerId){ |
| 173 | // 先一次性校验完成客户是否可用 | 218 | // 先一次性校验完成客户是否可用 |
| 174 | // TODO @xiaqing:批量一次性加载客户列表,然后去逐个校验; | 219 | // TODO @xiaqing:批量一次性加载客户列表,然后去逐个校验; |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/permission/CrmPermissionService.java
| @@ -4,6 +4,7 @@ package cn.iocoder.yudao.module.crm.service.permission; | @@ -4,6 +4,7 @@ package cn.iocoder.yudao.module.crm.service.permission; | ||
| 4 | import cn.iocoder.yudao.module.crm.controller.admin.permission.vo.CrmPermissionUpdateReqVO; | 4 | import cn.iocoder.yudao.module.crm.controller.admin.permission.vo.CrmPermissionUpdateReqVO; |
| 5 | import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO; | 5 | import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO; |
| 6 | import cn.iocoder.yudao.module.crm.framework.enums.CrmBizTypeEnum; | 6 | import cn.iocoder.yudao.module.crm.framework.enums.CrmBizTypeEnum; |
| 7 | +import cn.iocoder.yudao.module.crm.framework.enums.CrmPermissionLevelEnum; | ||
| 7 | import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateReqBO; | 8 | import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateReqBO; |
| 8 | import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionTransferReqBO; | 9 | import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionTransferReqBO; |
| 9 | 10 | ||
| @@ -34,6 +35,13 @@ public interface CrmPermissionService { | @@ -34,6 +35,13 @@ public interface CrmPermissionService { | ||
| 34 | void updatePermission(CrmPermissionUpdateReqVO updateReqVO); | 35 | void updatePermission(CrmPermissionUpdateReqVO updateReqVO); |
| 35 | 36 | ||
| 36 | /** | 37 | /** |
| 38 | + * 数据权限转移 | ||
| 39 | + * | ||
| 40 | + * @param crmPermissionTransferReqBO 数据权限转移请求 | ||
| 41 | + */ | ||
| 42 | + void transferPermission(@Valid CrmPermissionTransferReqBO crmPermissionTransferReqBO); | ||
| 43 | + | ||
| 44 | + /** | ||
| 37 | * 删除数据权限 | 45 | * 删除数据权限 |
| 38 | * | 46 | * |
| 39 | * @param ids 编号 | 47 | * @param ids 编号 |
| @@ -41,14 +49,13 @@ public interface CrmPermissionService { | @@ -41,14 +49,13 @@ public interface CrmPermissionService { | ||
| 41 | void deletePermission(Collection<Long> ids); | 49 | void deletePermission(Collection<Long> ids); |
| 42 | 50 | ||
| 43 | /** | 51 | /** |
| 44 | - * 获取用户数据权限通过 数据类型 x 某个数据 x 用户编号 | 52 | + * 删除数据权限 |
| 45 | * | 53 | * |
| 46 | * @param bizType 数据类型,关联 {@link CrmBizTypeEnum} | 54 | * @param bizType 数据类型,关联 {@link CrmBizTypeEnum} |
| 47 | * @param bizId 数据编号,关联 {@link CrmBizTypeEnum} 对应模块 DO#getId() | 55 | * @param bizId 数据编号,关联 {@link CrmBizTypeEnum} 对应模块 DO#getId() |
| 48 | - * @param userId 用户编号,AdminUser#id | ||
| 49 | - * @return Crm 数据权限 | 56 | + * @param level 数据权限级别,关联 {@link CrmPermissionLevelEnum} |
| 50 | */ | 57 | */ |
| 51 | - CrmPermissionDO getPermissionByBizTypeAndBizIdAndUserId(Integer bizType, Long bizId, Long userId); | 58 | + void deletePermission(Integer bizType, Long bizId, Integer level); |
| 52 | 59 | ||
| 53 | /** | 60 | /** |
| 54 | * 获取用户数据权限通过 权限编号 x 用户编号 | 61 | * 获取用户数据权限通过 权限编号 x 用户编号 |
| @@ -69,22 +76,12 @@ public interface CrmPermissionService { | @@ -69,22 +76,12 @@ public interface CrmPermissionService { | ||
| 69 | List<CrmPermissionDO> getPermissionByBizTypeAndBizId(Integer bizType, Long bizId); | 76 | List<CrmPermissionDO> getPermissionByBizTypeAndBizId(Integer bizType, Long bizId); |
| 70 | 77 | ||
| 71 | /** | 78 | /** |
| 72 | - * 获取数据权限列表,通过 数据类型 x 某个数据 | 79 | + * 获得数据权限列表 |
| 73 | * | 80 | * |
| 74 | - * @param bizType 数据类型,关联 {@link CrmBizTypeEnum} | ||
| 75 | - * @param bizIds 数据编号,关联 {@link CrmBizTypeEnum} 对应模块 DO#getId() | ||
| 76 | - * @param level 权限级别 | ||
| 77 | - * @return Crm 数据权限列表 | 81 | + * @param ids 数据权限编号列表 |
| 82 | + * @return 数据权限列表 | ||
| 78 | */ | 83 | */ |
| 79 | - List<CrmPermissionDO> getPermissionByBizTypeAndBizIdsAndLevel(Integer bizType, Collection<Long> bizIds, Integer level); | ||
| 80 | - | ||
| 81 | List<CrmPermissionDO> getPermissionListByIds(Collection<Long> ids); | 84 | List<CrmPermissionDO> getPermissionListByIds(Collection<Long> ids); |
| 82 | - /** | ||
| 83 | - * 数据权限转移 | ||
| 84 | - * | ||
| 85 | - * @param crmPermissionTransferReqBO 数据权限转移请求 | ||
| 86 | - */ | ||
| 87 | - void transferPermission(@Valid CrmPermissionTransferReqBO crmPermissionTransferReqBO); | ||
| 88 | 85 | ||
| 89 | /** | 86 | /** |
| 90 | * 获取用户参与的模块数据列表 | 87 | * 获取用户参与的模块数据列表 |
| @@ -95,22 +92,4 @@ public interface CrmPermissionService { | @@ -95,22 +92,4 @@ public interface CrmPermissionService { | ||
| 95 | */ | 92 | */ |
| 96 | List<CrmPermissionDO> getPermissionListByBizTypeAndUserId(Integer bizType, Long userId); | 93 | List<CrmPermissionDO> getPermissionListByBizTypeAndUserId(Integer bizType, Long userId); |
| 97 | 94 | ||
| 98 | - /** | ||
| 99 | - * 领取公海数据 | ||
| 100 | - * | ||
| 101 | - * @param bizType 数据类型,关联 {@link CrmBizTypeEnum} | ||
| 102 | - * @param bizId 数据编号,关联 {@link CrmBizTypeEnum} 对应模块 DO#getId() | ||
| 103 | - * @param userId 用户编号,AdminUser#id | ||
| 104 | - */ | ||
| 105 | - void receiveBiz(Integer bizType, Long bizId, Long userId); | ||
| 106 | - | ||
| 107 | - /** | ||
| 108 | - * 数据放入公海 | ||
| 109 | - * | ||
| 110 | - * @param bizType 数据类型,关联 {@link CrmBizTypeEnum} | ||
| 111 | - * @param bizId 数据编号,关联 {@link CrmBizTypeEnum} 对应模块 DO#getId() | ||
| 112 | - * @param userId 用户编号,AdminUser#id | ||
| 113 | - */ | ||
| 114 | - void putPool(Integer bizType, Long bizId, Long userId); | ||
| 115 | - | ||
| 116 | } | 95 | } |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/permission/CrmPermissionServiceImpl.java
| @@ -21,6 +21,7 @@ import java.util.Collections; | @@ -21,6 +21,7 @@ import java.util.Collections; | ||
| 21 | import java.util.List; | 21 | import java.util.List; |
| 22 | 22 | ||
| 23 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 23 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 24 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; | ||
| 24 | import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*; | 25 | import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*; |
| 25 | import static cn.iocoder.yudao.module.crm.framework.enums.CrmPermissionLevelEnum.isOwner; | 26 | import static cn.iocoder.yudao.module.crm.framework.enums.CrmPermissionLevelEnum.isOwner; |
| 26 | 27 | ||
| @@ -63,52 +64,6 @@ public class CrmPermissionServiceImpl implements CrmPermissionService { | @@ -63,52 +64,6 @@ public class CrmPermissionServiceImpl implements CrmPermissionService { | ||
| 63 | 64 | ||
| 64 | @Override | 65 | @Override |
| 65 | @Transactional(rollbackFor = Exception.class) | 66 | @Transactional(rollbackFor = Exception.class) |
| 66 | - public void deletePermission(Collection<Long> ids) { | ||
| 67 | - // 校验存在 | ||
| 68 | - validateCrmPermissionExists(ids); | ||
| 69 | - | ||
| 70 | - // 删除 | ||
| 71 | - crmPermissionMapper.deleteBatchIds(ids); | ||
| 72 | - } | ||
| 73 | - | ||
| 74 | - @Override | ||
| 75 | - public CrmPermissionDO getPermissionByBizTypeAndBizIdAndUserId(Integer bizType, Long bizId, Long userId) { | ||
| 76 | - return crmPermissionMapper.selectByBizTypeAndBizIdByUserId(bizType, bizId, userId); | ||
| 77 | - } | ||
| 78 | - | ||
| 79 | - @Override | ||
| 80 | - public CrmPermissionDO getPermissionByIdAndUserId(Long id, Long userId) { | ||
| 81 | - return crmPermissionMapper.selectByIdAndUserId(id, userId); | ||
| 82 | - } | ||
| 83 | - | ||
| 84 | - @Override | ||
| 85 | - public List<CrmPermissionDO> getPermissionByBizTypeAndBizId(Integer bizType, Long bizId) { | ||
| 86 | - return crmPermissionMapper.selectByBizTypeAndBizId(bizType, bizId); | ||
| 87 | - } | ||
| 88 | - | ||
| 89 | - @Override | ||
| 90 | - public List<CrmPermissionDO> getPermissionByBizTypeAndBizIdsAndLevel(Integer bizType, Collection<Long> bizIds, Integer level) { | ||
| 91 | - return crmPermissionMapper.selectListByBizTypeAndBizIdsAndLevel(bizType, bizIds, level); | ||
| 92 | - } | ||
| 93 | - | ||
| 94 | - @Override | ||
| 95 | - public List<CrmPermissionDO> getPermissionListByIds(Collection<Long> ids) { | ||
| 96 | - if (CollUtil.isEmpty(ids)) { | ||
| 97 | - return Collections.emptyList(); | ||
| 98 | - } | ||
| 99 | - return crmPermissionMapper.selectBatchIds(ids); | ||
| 100 | - } | ||
| 101 | - | ||
| 102 | - private void validateCrmPermissionExists(Collection<Long> ids) { | ||
| 103 | - List<CrmPermissionDO> permissionList = crmPermissionMapper.selectBatchIds(ids); | ||
| 104 | - // 校验存在 | ||
| 105 | - if (ObjUtil.notEqual(permissionList.size(), ids.size())) { | ||
| 106 | - throw exception(CRM_PERMISSION_NOT_EXISTS); | ||
| 107 | - } | ||
| 108 | - } | ||
| 109 | - | ||
| 110 | - @Override | ||
| 111 | - @Transactional(rollbackFor = Exception.class) | ||
| 112 | public void transferPermission(CrmPermissionTransferReqBO transferReqBO) { | 67 | public void transferPermission(CrmPermissionTransferReqBO transferReqBO) { |
| 113 | // 1. 校验数据权限-是否是负责人,只有负责人才可以转移 | 68 | // 1. 校验数据权限-是否是负责人,只有负责人才可以转移 |
| 114 | CrmPermissionDO oldPermission = crmPermissionMapper.selectByBizTypeAndBizIdByUserId(transferReqBO.getBizType(), | 69 | CrmPermissionDO oldPermission = crmPermissionMapper.selectByBizTypeAndBizIdByUserId(transferReqBO.getBizType(), |
| @@ -149,30 +104,57 @@ public class CrmPermissionServiceImpl implements CrmPermissionService { | @@ -149,30 +104,57 @@ public class CrmPermissionServiceImpl implements CrmPermissionService { | ||
| 149 | } | 104 | } |
| 150 | 105 | ||
| 151 | @Override | 106 | @Override |
| 152 | - public List<CrmPermissionDO> getPermissionListByBizTypeAndUserId(Integer bizType, Long userId) { | ||
| 153 | - return crmPermissionMapper.selectListByBizTypeAndUserId(bizType, userId); | 107 | + @Transactional(rollbackFor = Exception.class) |
| 108 | + public void deletePermission(Collection<Long> ids) { | ||
| 109 | + // 校验存在 | ||
| 110 | + validateCrmPermissionExists(ids); | ||
| 111 | + | ||
| 112 | + // 删除 | ||
| 113 | + crmPermissionMapper.deleteBatchIds(ids); | ||
| 154 | } | 114 | } |
| 155 | 115 | ||
| 156 | @Override | 116 | @Override |
| 157 | @Transactional(rollbackFor = Exception.class) | 117 | @Transactional(rollbackFor = Exception.class) |
| 158 | - public void receiveBiz(Integer bizType, Long bizId, Long userId) { | ||
| 159 | - //CrmPermissionDO permission = crmPermissionMapper.selectByBizTypeAndBizIdByUserId(bizType, bizId, CrmPermissionDO.POOL_USER_ID); | ||
| 160 | - //if (permission == null) { // 不存在则模块数据也不存在 | ||
| 161 | - // throw exception(CRM_PERMISSION_MODEL_NOT_EXISTS, CrmBizTypeEnum.getNameByType(bizType)); | ||
| 162 | - //} | ||
| 163 | - // | ||
| 164 | - //crmPermissionMapper.updateById(new CrmPermissionDO().setId(permission.getId()).setUserId(userId)); | ||
| 165 | - // TODO puhui999: 领取数据后需要创建一个负责人数据权限 | 118 | + public void deletePermission(Integer bizType, Long bizId, Integer level) { |
| 119 | + List<CrmPermissionDO> permissions = crmPermissionMapper.selectListByBizTypeAndBizIdAndLevel(bizType, bizId, level); | ||
| 120 | + // 校验存在 | ||
| 121 | + if (CollUtil.isEmpty(permissions)) { | ||
| 122 | + throw exception(CRM_PERMISSION_NOT_EXISTS); | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + // 删除数据权限 | ||
| 126 | + crmPermissionMapper.deleteBatchIds(convertSet(permissions, CrmPermissionDO::getId)); | ||
| 166 | } | 127 | } |
| 167 | 128 | ||
| 168 | @Override | 129 | @Override |
| 169 | - @Transactional(rollbackFor = Exception.class) | ||
| 170 | - public void putPool(Integer bizType, Long bizId, Long userId) { | ||
| 171 | - CrmPermissionDO permission = crmPermissionMapper.selectByBizTypeAndBizIdByUserId(bizType, bizId, userId); | ||
| 172 | - if (permission == null) { // 不存在则模块数据也不存在 | ||
| 173 | - throw exception(CRM_PERMISSION_MODEL_NOT_EXISTS, CrmBizTypeEnum.getNameByType(bizType)); | 130 | + public CrmPermissionDO getPermissionByIdAndUserId(Long id, Long userId) { |
| 131 | + return crmPermissionMapper.selectByIdAndUserId(id, userId); | ||
| 132 | + } | ||
| 133 | + | ||
| 134 | + @Override | ||
| 135 | + public List<CrmPermissionDO> getPermissionByBizTypeAndBizId(Integer bizType, Long bizId) { | ||
| 136 | + return crmPermissionMapper.selectByBizTypeAndBizId(bizType, bizId); | ||
| 137 | + } | ||
| 138 | + | ||
| 139 | + @Override | ||
| 140 | + public List<CrmPermissionDO> getPermissionListByIds(Collection<Long> ids) { | ||
| 141 | + if (CollUtil.isEmpty(ids)) { | ||
| 142 | + return Collections.emptyList(); | ||
| 143 | + } | ||
| 144 | + return crmPermissionMapper.selectBatchIds(ids); | ||
| 145 | + } | ||
| 146 | + | ||
| 147 | + private void validateCrmPermissionExists(Collection<Long> ids) { | ||
| 148 | + List<CrmPermissionDO> permissionList = crmPermissionMapper.selectBatchIds(ids); | ||
| 149 | + // 校验存在 | ||
| 150 | + if (ObjUtil.notEqual(permissionList.size(), ids.size())) { | ||
| 151 | + throw exception(CRM_PERMISSION_NOT_EXISTS); | ||
| 174 | } | 152 | } |
| 175 | - // TODO puhui999: 数据放入公海后删除负责人的数据权限,完事数据负责人设置为 null | 153 | + } |
| 154 | + | ||
| 155 | + @Override | ||
| 156 | + public List<CrmPermissionDO> getPermissionListByBizTypeAndUserId(Integer bizType, Long userId) { | ||
| 157 | + return crmPermissionMapper.selectListByBizTypeAndUserId(bizType, userId); | ||
| 176 | } | 158 | } |
| 177 | 159 | ||
| 178 | } | 160 | } |