mirror of
				https://github.com/YunaiV/ruoyi-vue-pro.git
				synced 2025-10-31 10:37:41 +08:00 
			
		
		
		
	crm:code review 数据权限
This commit is contained in:
		| @ -35,6 +35,7 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils. | |||||||
| import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSetByFlatMap; | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSetByFlatMap; | ||||||
| import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; | import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; | ||||||
| import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; | import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; | ||||||
|  | import static java.util.Collections.singletonList; | ||||||
|  |  | ||||||
| @Tag(name = "管理后台 - CRM 客户") | @Tag(name = "管理后台 - CRM 客户") | ||||||
| @RestController | @RestController | ||||||
| @ -114,6 +115,7 @@ public class CrmCustomerController { | |||||||
|     @OperateLog(type = EXPORT) |     @OperateLog(type = EXPORT) | ||||||
|     public void exportCustomerExcel(@Valid CrmCustomerPageReqVO pageVO, |     public void exportCustomerExcel(@Valid CrmCustomerPageReqVO pageVO, | ||||||
|                                     HttpServletResponse response) throws IOException { |                                     HttpServletResponse response) throws IOException { | ||||||
|  |         // TODO @puhui999:看看复用 getCustomerPage 方法;然后可以禁用下分页; | ||||||
|         List<CrmCustomerDO> list = customerService.getCustomerPage(pageVO, getLoginUserId()).getList(); |         List<CrmCustomerDO> list = customerService.getCustomerPage(pageVO, getLoginUserId()).getList(); | ||||||
|         // 导出 Excel |         // 导出 Excel | ||||||
|         List<CrmCustomerExcelVO> datas = CrmCustomerConvert.INSTANCE.convertList02(list); |         List<CrmCustomerExcelVO> datas = CrmCustomerConvert.INSTANCE.convertList02(list); | ||||||
| @ -167,7 +169,8 @@ public class CrmCustomerController { | |||||||
|     public CommonResult<Boolean> distributeCustomer(@RequestParam(value = "ids") List<Long> ids, |     public CommonResult<Boolean> distributeCustomer(@RequestParam(value = "ids") List<Long> ids, | ||||||
|                                                     @RequestParam(value = "ownerUserId") Long ownerUserId) { |                                                     @RequestParam(value = "ownerUserId") Long ownerUserId) { | ||||||
|         // 校验负责人是否存在 |         // 校验负责人是否存在 | ||||||
|         adminUserApi.validateUserList(java.util.Collections.singletonList(ownerUserId)); |         // TODO @puhui999:这个校验,是不是可以收到 validateUserList | ||||||
|  |         adminUserApi.validateUserList(singletonList(ownerUserId)); | ||||||
|         // 领取公海数据 |         // 领取公海数据 | ||||||
|         customerService.receiveCustomer(ids, ownerUserId); |         customerService.receiveCustomer(ids, ownerUserId); | ||||||
|         return success(true); |         return success(true); | ||||||
|  | |||||||
| @ -61,6 +61,6 @@ public interface CrmPermissionConvert { | |||||||
|                 id -> new CrmPermissionDO().setId(id).setLevel(updateReqVO.getLevel())); |                 id -> new CrmPermissionDO().setId(id).setLevel(updateReqVO.getLevel())); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     List<CrmPermissionDO> convertList(List<CrmPermissionCreateReqBO> createBOs); |     List<CrmPermissionDO> convertList(List<CrmPermissionCreateReqBO> list); | ||||||
|  |  | ||||||
| } | } | ||||||
|  | |||||||
| @ -213,7 +213,6 @@ public class CrmCustomerServiceImpl implements CrmCustomerService { | |||||||
|         if (customer.getOwnerUserId() != null) { |         if (customer.getOwnerUserId() != null) { | ||||||
|             throw exception(CUSTOMER_OWNER_EXISTS, customer.getName()); |             throw exception(CUSTOMER_OWNER_EXISTS, customer.getName()); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private void validateCustomerIsLocked(CrmCustomerDO customer, Boolean pool) { |     private void validateCustomerIsLocked(CrmCustomerDO customer, Boolean pool) { | ||||||
| @ -228,54 +227,6 @@ public class CrmCustomerServiceImpl implements CrmCustomerService { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     // TODO @puhui999:合并到 receiveCustomer 里 |  | ||||||
|     @Override |  | ||||||
|     @Transactional(rollbackFor = Exception.class) |  | ||||||
|     public void receive(Long id, Long userId) { |  | ||||||
|         // 1. 校验存在 |  | ||||||
|         CrmCustomerDO customer = customerMapper.selectById(id); |  | ||||||
|         if (customer == null) { |  | ||||||
|             throw exception(CUSTOMER_NOT_EXISTS); |  | ||||||
|         } |  | ||||||
|         // 1.2. 校验是否为公海数据 |  | ||||||
|         if (customer.getOwnerUserId() != null) { |  | ||||||
|             throw exception(CUSTOMER_NOT_IN_POOL); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         // 2. 领取公海数据-设置负责人 |  | ||||||
|         customerMapper.updateById(new CrmCustomerDO().setId(customer.getId()).setOwnerUserId(userId)); |  | ||||||
|         // 3. 创建负责人数据权限 |  | ||||||
|         crmPermissionService.createPermission(new CrmPermissionCreateReqBO().setBizType(CrmBizTypeEnum.CRM_CUSTOMER.getType()) |  | ||||||
|                 .setBizId(customer.getId()).setUserId(userId).setLevel(CrmPermissionLevelEnum.OWNER.getLevel())); // 设置当前操作的人为负责人 |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     @Override |  | ||||||
|     @Transactional(rollbackFor = Exception.class) |  | ||||||
|     @CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#id", level = CrmPermissionLevelEnum.OWNER) |  | ||||||
|     public void putCustomerPool(Long id) { |  | ||||||
|         // 1. 校验存在 |  | ||||||
|         CrmCustomerDO customer = customerMapper.selectById(id); |  | ||||||
|         if (customer == null) { |  | ||||||
|             throw exception(CUSTOMER_NOT_EXISTS); |  | ||||||
|         } |  | ||||||
|         // TODO puhui999:校验合并到 validateCustomerOwnerExists、validateCustomerIsLocked |  | ||||||
|         // 1.2. 校验是否为公海数据 |  | ||||||
|         if (customer.getOwnerUserId() == null) { |  | ||||||
|             throw exception(CUSTOMER_IN_POOL); |  | ||||||
|         } |  | ||||||
|         // 1.3. 校验客户是否锁定 |  | ||||||
|         if (customer.getLockStatus()) { |  | ||||||
|             throw exception(CUSTOMER_LOCKED_PUT_POOL_FAIL); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         // 2. 设置负责人为 NULL |  | ||||||
|         // TODO @puhui999:updateById 这么操作,是无法设置 null 的; |  | ||||||
|         customerMapper.updateById(new CrmCustomerDO().setId(customer.getId()).setOwnerUserId(null)); |  | ||||||
|         // 3. 删除负责人数据权限 |  | ||||||
|         crmPermissionService.deletePermission(CrmBizTypeEnum.CRM_CUSTOMER.getType(), customer.getId(), |  | ||||||
|                 CrmPermissionLevelEnum.OWNER.getLevel()); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public List<CrmCustomerDO> getCustomerList() { |     public List<CrmCustomerDO> getCustomerList() { | ||||||
|         return customerMapper.selectList(); |         return customerMapper.selectList(); | ||||||
|  | |||||||
| @ -61,6 +61,7 @@ public interface CrmPermissionService { | |||||||
|      * 批量删除数据权限 |      * 批量删除数据权限 | ||||||
|      * |      * | ||||||
|      * @param ids 权限编号 |      * @param ids 权限编号 | ||||||
|  |      * @param userId 用户编号 | ||||||
|      */ |      */ | ||||||
|     void deletePermissionBatch(Collection<Long> ids, Long userId); |     void deletePermissionBatch(Collection<Long> ids, Long userId); | ||||||
|  |  | ||||||
|  | |||||||
| @ -19,7 +19,6 @@ import javax.annotation.Resource; | |||||||
| import java.util.Collection; | import java.util.Collection; | ||||||
| import java.util.Collections; | import java.util.Collections; | ||||||
| import java.util.List; | import java.util.List; | ||||||
| import java.util.Set; |  | ||||||
|  |  | ||||||
| import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | ||||||
| import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; | ||||||
| @ -141,8 +140,8 @@ public class CrmPermissionServiceImpl implements CrmPermissionService { | |||||||
|         if (CollUtil.isEmpty(permissions)) { |         if (CollUtil.isEmpty(permissions)) { | ||||||
|             throw exception(CRM_PERMISSION_NOT_EXISTS); |             throw exception(CRM_PERMISSION_NOT_EXISTS); | ||||||
|         } |         } | ||||||
|         Set<Long> bizIds = convertSet(permissions, CrmPermissionDO::getBizId); |         // 校验:数据权限的模块数据编号是一致的不可能存在两个 | ||||||
|         if (bizIds.size() > 1) { // 情况一:数据权限的模块数据编号是一致的不可能存在两个 |         if (convertSet(permissions, CrmPermissionDO::getBizId).size() > 1) { | ||||||
|             throw exception(CRM_PERMISSION_DELETE_FAIL); |             throw exception(CRM_PERMISSION_DELETE_FAIL); | ||||||
|         } |         } | ||||||
|         // 校验操作人是否为负责人 |         // 校验操作人是否为负责人 | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 YunaiV
					YunaiV