Commit 492adfe8e582b7cfcc7450ba8517f81fa7f4813b
1 parent
455f8e49
crm:code review 数据权限
Showing
7 changed files
with
8 additions
and
54 deletions
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/CrmCustomerController.java
| @@ -35,6 +35,7 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils. | @@ -35,6 +35,7 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils. | ||
| 35 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSetByFlatMap; | 35 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSetByFlatMap; |
| 36 | import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; | 36 | import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; |
| 37 | import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; | 37 | import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; |
| 38 | +import static java.util.Collections.singletonList; | ||
| 38 | 39 | ||
| 39 | @Tag(name = "管理后台 - CRM 客户") | 40 | @Tag(name = "管理后台 - CRM 客户") |
| 40 | @RestController | 41 | @RestController |
| @@ -114,6 +115,7 @@ public class CrmCustomerController { | @@ -114,6 +115,7 @@ public class CrmCustomerController { | ||
| 114 | @OperateLog(type = EXPORT) | 115 | @OperateLog(type = EXPORT) |
| 115 | public void exportCustomerExcel(@Valid CrmCustomerPageReqVO pageVO, | 116 | public void exportCustomerExcel(@Valid CrmCustomerPageReqVO pageVO, |
| 116 | HttpServletResponse response) throws IOException { | 117 | HttpServletResponse response) throws IOException { |
| 118 | + // TODO @puhui999:看看复用 getCustomerPage 方法;然后可以禁用下分页; | ||
| 117 | List<CrmCustomerDO> list = customerService.getCustomerPage(pageVO, getLoginUserId()).getList(); | 119 | List<CrmCustomerDO> list = customerService.getCustomerPage(pageVO, getLoginUserId()).getList(); |
| 118 | // 导出 Excel | 120 | // 导出 Excel |
| 119 | List<CrmCustomerExcelVO> datas = CrmCustomerConvert.INSTANCE.convertList02(list); | 121 | List<CrmCustomerExcelVO> datas = CrmCustomerConvert.INSTANCE.convertList02(list); |
| @@ -167,7 +169,8 @@ public class CrmCustomerController { | @@ -167,7 +169,8 @@ public class CrmCustomerController { | ||
| 167 | public CommonResult<Boolean> distributeCustomer(@RequestParam(value = "ids") List<Long> ids, | 169 | public CommonResult<Boolean> distributeCustomer(@RequestParam(value = "ids") List<Long> ids, |
| 168 | @RequestParam(value = "ownerUserId") Long ownerUserId) { | 170 | @RequestParam(value = "ownerUserId") Long ownerUserId) { |
| 169 | // 校验负责人是否存在 | 171 | // 校验负责人是否存在 |
| 170 | - adminUserApi.validateUserList(java.util.Collections.singletonList(ownerUserId)); | 172 | + // TODO @puhui999:这个校验,是不是可以收到 validateUserList |
| 173 | + adminUserApi.validateUserList(singletonList(ownerUserId)); | ||
| 171 | // 领取公海数据 | 174 | // 领取公海数据 |
| 172 | customerService.receiveCustomer(ids, ownerUserId); | 175 | customerService.receiveCustomer(ids, ownerUserId); |
| 173 | return success(true); | 176 | return success(true); |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/permission/CrmPermissionConvert.java
| @@ -61,6 +61,6 @@ public interface CrmPermissionConvert { | @@ -61,6 +61,6 @@ public interface CrmPermissionConvert { | ||
| 61 | id -> new CrmPermissionDO().setId(id).setLevel(updateReqVO.getLevel())); | 61 | id -> new CrmPermissionDO().setId(id).setLevel(updateReqVO.getLevel())); |
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | - List<CrmPermissionDO> convertList(List<CrmPermissionCreateReqBO> createBOs); | 64 | + List<CrmPermissionDO> convertList(List<CrmPermissionCreateReqBO> list); |
| 65 | 65 | ||
| 66 | } | 66 | } |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerServiceImpl.java
| @@ -213,7 +213,6 @@ public class CrmCustomerServiceImpl implements CrmCustomerService { | @@ -213,7 +213,6 @@ public class CrmCustomerServiceImpl implements CrmCustomerService { | ||
| 213 | if (customer.getOwnerUserId() != null) { | 213 | if (customer.getOwnerUserId() != null) { |
| 214 | throw exception(CUSTOMER_OWNER_EXISTS, customer.getName()); | 214 | throw exception(CUSTOMER_OWNER_EXISTS, customer.getName()); |
| 215 | } | 215 | } |
| 216 | - | ||
| 217 | } | 216 | } |
| 218 | 217 | ||
| 219 | private void validateCustomerIsLocked(CrmCustomerDO customer, Boolean pool) { | 218 | private void validateCustomerIsLocked(CrmCustomerDO customer, Boolean pool) { |
| @@ -228,54 +227,6 @@ public class CrmCustomerServiceImpl implements CrmCustomerService { | @@ -228,54 +227,6 @@ public class CrmCustomerServiceImpl implements CrmCustomerService { | ||
| 228 | } | 227 | } |
| 229 | } | 228 | } |
| 230 | 229 | ||
| 231 | - // TODO @puhui999:合并到 receiveCustomer 里 | ||
| 232 | - @Override | ||
| 233 | - @Transactional(rollbackFor = Exception.class) | ||
| 234 | - public void receive(Long id, Long userId) { | ||
| 235 | - // 1. 校验存在 | ||
| 236 | - CrmCustomerDO customer = customerMapper.selectById(id); | ||
| 237 | - if (customer == null) { | ||
| 238 | - throw exception(CUSTOMER_NOT_EXISTS); | ||
| 239 | - } | ||
| 240 | - // 1.2. 校验是否为公海数据 | ||
| 241 | - if (customer.getOwnerUserId() != null) { | ||
| 242 | - throw exception(CUSTOMER_NOT_IN_POOL); | ||
| 243 | - } | ||
| 244 | - | ||
| 245 | - // 2. 领取公海数据-设置负责人 | ||
| 246 | - customerMapper.updateById(new CrmCustomerDO().setId(customer.getId()).setOwnerUserId(userId)); | ||
| 247 | - // 3. 创建负责人数据权限 | ||
| 248 | - crmPermissionService.createPermission(new CrmPermissionCreateReqBO().setBizType(CrmBizTypeEnum.CRM_CUSTOMER.getType()) | ||
| 249 | - .setBizId(customer.getId()).setUserId(userId).setLevel(CrmPermissionLevelEnum.OWNER.getLevel())); // 设置当前操作的人为负责人 | ||
| 250 | - } | ||
| 251 | - | ||
| 252 | - @Override | ||
| 253 | - @Transactional(rollbackFor = Exception.class) | ||
| 254 | - @CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#id", level = CrmPermissionLevelEnum.OWNER) | ||
| 255 | - public void putCustomerPool(Long id) { | ||
| 256 | - // 1. 校验存在 | ||
| 257 | - CrmCustomerDO customer = customerMapper.selectById(id); | ||
| 258 | - if (customer == null) { | ||
| 259 | - throw exception(CUSTOMER_NOT_EXISTS); | ||
| 260 | - } | ||
| 261 | - // TODO puhui999:校验合并到 validateCustomerOwnerExists、validateCustomerIsLocked | ||
| 262 | - // 1.2. 校验是否为公海数据 | ||
| 263 | - if (customer.getOwnerUserId() == null) { | ||
| 264 | - throw exception(CUSTOMER_IN_POOL); | ||
| 265 | - } | ||
| 266 | - // 1.3. 校验客户是否锁定 | ||
| 267 | - if (customer.getLockStatus()) { | ||
| 268 | - throw exception(CUSTOMER_LOCKED_PUT_POOL_FAIL); | ||
| 269 | - } | ||
| 270 | - | ||
| 271 | - // 2. 设置负责人为 NULL | ||
| 272 | - // TODO @puhui999:updateById 这么操作,是无法设置 null 的; | ||
| 273 | - customerMapper.updateById(new CrmCustomerDO().setId(customer.getId()).setOwnerUserId(null)); | ||
| 274 | - // 3. 删除负责人数据权限 | ||
| 275 | - crmPermissionService.deletePermission(CrmBizTypeEnum.CRM_CUSTOMER.getType(), customer.getId(), | ||
| 276 | - CrmPermissionLevelEnum.OWNER.getLevel()); | ||
| 277 | - } | ||
| 278 | - | ||
| 279 | @Override | 230 | @Override |
| 280 | public List<CrmCustomerDO> getCustomerList() { | 231 | public List<CrmCustomerDO> getCustomerList() { |
| 281 | return customerMapper.selectList(); | 232 | return customerMapper.selectList(); |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/permission/CrmPermissionService.java
| @@ -61,6 +61,7 @@ public interface CrmPermissionService { | @@ -61,6 +61,7 @@ public interface CrmPermissionService { | ||
| 61 | * 批量删除数据权限 | 61 | * 批量删除数据权限 |
| 62 | * | 62 | * |
| 63 | * @param ids 权限编号 | 63 | * @param ids 权限编号 |
| 64 | + * @param userId 用户编号 | ||
| 64 | */ | 65 | */ |
| 65 | void deletePermissionBatch(Collection<Long> ids, Long userId); | 66 | void deletePermissionBatch(Collection<Long> ids, Long userId); |
| 66 | 67 |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/permission/CrmPermissionServiceImpl.java
| @@ -19,7 +19,6 @@ import javax.annotation.Resource; | @@ -19,7 +19,6 @@ import javax.annotation.Resource; | ||
| 19 | import java.util.Collection; | 19 | import java.util.Collection; |
| 20 | import java.util.Collections; | 20 | import java.util.Collections; |
| 21 | import java.util.List; | 21 | import java.util.List; |
| 22 | -import java.util.Set; | ||
| 23 | 22 | ||
| 24 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 23 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 25 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; | 24 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; |
| @@ -141,8 +140,8 @@ public class CrmPermissionServiceImpl implements CrmPermissionService { | @@ -141,8 +140,8 @@ public class CrmPermissionServiceImpl implements CrmPermissionService { | ||
| 141 | if (CollUtil.isEmpty(permissions)) { | 140 | if (CollUtil.isEmpty(permissions)) { |
| 142 | throw exception(CRM_PERMISSION_NOT_EXISTS); | 141 | throw exception(CRM_PERMISSION_NOT_EXISTS); |
| 143 | } | 142 | } |
| 144 | - Set<Long> bizIds = convertSet(permissions, CrmPermissionDO::getBizId); | ||
| 145 | - if (bizIds.size() > 1) { // 情况一:数据权限的模块数据编号是一致的不可能存在两个 | 143 | + // 校验:数据权限的模块数据编号是一致的不可能存在两个 |
| 144 | + if (convertSet(permissions, CrmPermissionDO::getBizId).size() > 1) { | ||
| 146 | throw exception(CRM_PERMISSION_DELETE_FAIL); | 145 | throw exception(CRM_PERMISSION_DELETE_FAIL); |
| 147 | } | 146 | } |
| 148 | // 校验操作人是否为负责人 | 147 | // 校验操作人是否为负责人 |
yudao-module-crm/yudao-module-crm-biz/src/test/java/cn/iocoder/yudao/module/crm/service/businessstatus/CrmBusinessStatusServiceImplTest.java deleted
yudao-module-crm/yudao-module-crm-biz/src/test/java/cn/iocoder/yudao/module/crm/service/businessstatustype/CrmBusinessStatusTypeServiceImplTest.java deleted