Commit c234f5b5f8f41c11b42f4e09357d77b902a82f84
1 parent
63431082
CRM: 完善数据权限
Showing
8 changed files
with
54 additions
and
22 deletions
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/business/CrmBusinessMapper.java
| ... | ... | @@ -38,8 +38,11 @@ public interface CrmBusinessMapper extends BaseMapperX<CrmBusinessDO> { |
| 38 | 38 | default PageResult<CrmBusinessDO> selectPage(CrmBusinessPageReqVO pageReqVO, Long userId) { |
| 39 | 39 | MPJLambdaWrapperX<CrmBusinessDO> query = new MPJLambdaWrapperX<>(); |
| 40 | 40 | // 拼接数据权限的查询条件 |
| 41 | - CrmQueryWrapperUtils.appendPermissionCondition(query, CrmBizTypeEnum.CRM_BUSINESS.getType(), CrmBusinessDO::getId, | |
| 42 | - userId, pageReqVO.getSceneType(), Boolean.FALSE); | |
| 41 | + boolean condition = CrmQueryWrapperUtils.appendPermissionCondition(query, CrmBizTypeEnum.CRM_BUSINESS.getType(), | |
| 42 | + CrmBusinessDO::getId, userId, pageReqVO.getSceneType(), Boolean.FALSE); | |
| 43 | + if (!condition) { | |
| 44 | + return PageResult.empty(); | |
| 45 | + } | |
| 43 | 46 | // 拼接自身的查询条件 |
| 44 | 47 | query.selectAll(CrmBusinessDO.class) |
| 45 | 48 | .likeIfPresent(CrmBusinessDO::getName, pageReqVO.getName()) | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/clue/CrmClueMapper.java
| ... | ... | @@ -30,8 +30,11 @@ public interface CrmClueMapper extends BaseMapperX<CrmClueDO> { |
| 30 | 30 | default PageResult<CrmClueDO> selectPage(CrmCluePageReqVO pageReqVO, Long userId) { |
| 31 | 31 | MPJLambdaWrapperX<CrmClueDO> query = new MPJLambdaWrapperX<>(); |
| 32 | 32 | // 拼接数据权限的查询条件 |
| 33 | - CrmQueryWrapperUtils.appendPermissionCondition(query, CrmBizTypeEnum.CRM_LEADS.getType(), CrmClueDO::getId, | |
| 34 | - userId, pageReqVO.getSceneType(), pageReqVO.getPool()); | |
| 33 | + boolean condition = CrmQueryWrapperUtils.appendPermissionCondition(query, CrmBizTypeEnum.CRM_LEADS.getType(), | |
| 34 | + CrmClueDO::getId, userId, pageReqVO.getSceneType(), pageReqVO.getPool()); | |
| 35 | + if (!condition) { | |
| 36 | + return PageResult.empty(); | |
| 37 | + } | |
| 35 | 38 | // 拼接自身的查询条件 |
| 36 | 39 | query.selectAll(CrmClueDO.class) |
| 37 | 40 | .likeIfPresent(CrmClueDO::getName, pageReqVO.getName()) | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/contact/CrmContactMapper.java
| ... | ... | @@ -43,8 +43,11 @@ public interface CrmContactMapper extends BaseMapperX<CrmContactDO> { |
| 43 | 43 | default PageResult<CrmContactDO> selectPage(CrmContactPageReqVO pageReqVO, Long userId) { |
| 44 | 44 | MPJLambdaWrapperX<CrmContactDO> query = new MPJLambdaWrapperX<>(); |
| 45 | 45 | // 拼接数据权限的查询条件 |
| 46 | - CrmQueryWrapperUtils.appendPermissionCondition(query, CrmBizTypeEnum.CRM_CONTACT.getType(), CrmContactDO::getId, | |
| 47 | - userId, pageReqVO.getSceneType(), Boolean.FALSE); | |
| 46 | + boolean condition = CrmQueryWrapperUtils.appendPermissionCondition(query, CrmBizTypeEnum.CRM_CONTACT.getType(), | |
| 47 | + CrmContactDO::getId, userId, pageReqVO.getSceneType(), Boolean.FALSE); | |
| 48 | + if (!condition) { | |
| 49 | + return PageResult.empty(); | |
| 50 | + } | |
| 48 | 51 | // 拼接自身的查询条件 |
| 49 | 52 | query.selectAll(CrmContactDO.class) |
| 50 | 53 | .likeIfPresent(CrmContactDO::getName, pageReqVO.getName()) | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/contract/CrmContractMapper.java
| ... | ... | @@ -40,9 +40,13 @@ public interface CrmContractMapper extends BaseMapperX<CrmContractDO> { |
| 40 | 40 | |
| 41 | 41 | default PageResult<CrmContractDO> selectPage(CrmContractPageReqVO pageReqVO, Long userId) { |
| 42 | 42 | MPJLambdaWrapperX<CrmContractDO> mpjLambdaWrapperX = new MPJLambdaWrapperX<>(); |
| 43 | - // 构建数据权限连表条件 | |
| 44 | - CrmQueryWrapperUtils.appendPermissionCondition(mpjLambdaWrapperX, CrmBizTypeEnum.CRM_CONTACT.getType(), CrmContractDO::getId, | |
| 45 | - userId, pageReqVO.getSceneType(), Boolean.FALSE); | |
| 43 | + // 拼接数据权限的查询条件 | |
| 44 | + boolean condition = CrmQueryWrapperUtils.appendPermissionCondition(mpjLambdaWrapperX, CrmBizTypeEnum.CRM_CONTACT.getType(), | |
| 45 | + CrmContractDO::getId, userId, pageReqVO.getSceneType(), Boolean.FALSE); | |
| 46 | + if (!condition) { | |
| 47 | + return PageResult.empty(); | |
| 48 | + } | |
| 49 | + // 拼接自身的查询条件 | |
| 46 | 50 | mpjLambdaWrapperX.selectAll(CrmContractDO.class) |
| 47 | 51 | .likeIfPresent(CrmContractDO::getNo, pageReqVO.getNo()) |
| 48 | 52 | .likeIfPresent(CrmContractDO::getName, pageReqVO.getName()) | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/customer/CrmCustomerMapper.java
| ... | ... | @@ -30,8 +30,11 @@ public interface CrmCustomerMapper extends BaseMapperX<CrmCustomerDO> { |
| 30 | 30 | default PageResult<CrmCustomerDO> selectPage(CrmCustomerPageReqVO pageReqVO, Long userId) { |
| 31 | 31 | MPJLambdaWrapperX<CrmCustomerDO> query = new MPJLambdaWrapperX<>(); |
| 32 | 32 | // 拼接数据权限的查询条件 |
| 33 | - CrmQueryWrapperUtils.appendPermissionCondition(query, CrmBizTypeEnum.CRM_CUSTOMER.getType(), CrmCustomerDO::getId, | |
| 34 | - userId, pageReqVO.getSceneType(), pageReqVO.getPool()); | |
| 33 | + boolean condition = CrmQueryWrapperUtils.appendPermissionCondition(query, CrmBizTypeEnum.CRM_CUSTOMER.getType(), | |
| 34 | + CrmCustomerDO::getId, userId, pageReqVO.getSceneType(), pageReqVO.getPool()); | |
| 35 | + if (!condition) { | |
| 36 | + return PageResult.empty(); | |
| 37 | + } | |
| 35 | 38 | // 拼接自身的查询条件 |
| 36 | 39 | query.selectAll(CrmCustomerDO.class) |
| 37 | 40 | .likeIfPresent(CrmCustomerDO::getName, pageReqVO.getName()) | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/receivable/CrmReceivableMapper.java
| ... | ... | @@ -39,8 +39,11 @@ public interface CrmReceivableMapper extends BaseMapperX<CrmReceivableDO> { |
| 39 | 39 | default PageResult<CrmReceivableDO> selectPage(CrmReceivablePageReqVO pageReqVO, Long userId) { |
| 40 | 40 | MPJLambdaWrapperX<CrmReceivableDO> query = new MPJLambdaWrapperX<>(); |
| 41 | 41 | // 拼接数据权限的查询条件 |
| 42 | - CrmQueryWrapperUtils.appendPermissionCondition(query, CrmBizTypeEnum.CRM_RECEIVABLE.getType(), CrmReceivableDO::getId, | |
| 43 | - userId, pageReqVO.getSceneType(), Boolean.FALSE); | |
| 42 | + boolean condition = CrmQueryWrapperUtils.appendPermissionCondition(query, CrmBizTypeEnum.CRM_RECEIVABLE.getType(), | |
| 43 | + CrmReceivableDO::getId, userId, pageReqVO.getSceneType(), Boolean.FALSE); | |
| 44 | + if (!condition) { | |
| 45 | + return PageResult.empty(); | |
| 46 | + } | |
| 44 | 47 | // 拼接自身的查询条件 |
| 45 | 48 | query.selectAll(CrmReceivableDO.class) |
| 46 | 49 | .eqIfPresent(CrmReceivableDO::getNo, pageReqVO.getNo()) | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/receivable/CrmReceivablePlanMapper.java
| ... | ... | @@ -38,8 +38,11 @@ public interface CrmReceivablePlanMapper extends BaseMapperX<CrmReceivablePlanDO |
| 38 | 38 | default PageResult<CrmReceivablePlanDO> selectPage(CrmReceivablePlanPageReqVO pageReqVO, Long userId) { |
| 39 | 39 | MPJLambdaWrapperX<CrmReceivablePlanDO> query = new MPJLambdaWrapperX<>(); |
| 40 | 40 | // 拼接数据权限的查询条件 |
| 41 | - CrmQueryWrapperUtils.appendPermissionCondition(query, CrmBizTypeEnum.CRM_RECEIVABLE_PLAN.getType(), CrmReceivablePlanDO::getId, | |
| 42 | - userId, pageReqVO.getSceneType(), Boolean.FALSE); | |
| 41 | + boolean condition = CrmQueryWrapperUtils.appendPermissionCondition(query, CrmBizTypeEnum.CRM_RECEIVABLE_PLAN.getType(), | |
| 42 | + CrmReceivablePlanDO::getId, userId, pageReqVO.getSceneType(), Boolean.FALSE); | |
| 43 | + if (!condition) { | |
| 44 | + return PageResult.empty(); | |
| 45 | + } | |
| 43 | 46 | // 拼接自身的查询条件 |
| 44 | 47 | query.selectAll(CrmReceivablePlanDO.class) |
| 45 | 48 | .eqIfPresent(CrmReceivablePlanDO::getCustomerId, pageReqVO.getCustomerId()) | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/util/CrmQueryWrapperUtils.java
| ... | ... | @@ -33,10 +33,11 @@ public class CrmQueryWrapperUtils { |
| 33 | 33 | * @param userId 用户编号 |
| 34 | 34 | * @param sceneType 场景类型 |
| 35 | 35 | * @param pool 公海 |
| 36 | + * @return 是否 (是:需要执行查询,否:不需要查询调用方法直接返回空) | |
| 36 | 37 | */ |
| 37 | 38 | // TODO @puhui999:bizId 直接传递会不会简单点 回复:还是需要 SFunction 因为分页连表时不知道 bizId 是多少 |
| 38 | - public static <T extends MPJLambdaWrapper<?>, S> void appendPermissionCondition(T query, Integer bizType, SFunction<S, ?> bizId, | |
| 39 | - Long userId, Integer sceneType, Boolean pool) { | |
| 39 | + public static <T extends MPJLambdaWrapper<?>, S> boolean appendPermissionCondition(T query, Integer bizType, SFunction<S, ?> bizId, | |
| 40 | + Long userId, Integer sceneType, Boolean pool) { | |
| 40 | 41 | // 1. 构建数据权限连表条件 |
| 41 | 42 | if (ObjUtil.notEqual(validateAdminUser(userId), Boolean.TRUE)) { // 管理员不需要数据权限 |
| 42 | 43 | query.innerJoin(CrmPermissionDO.class, on -> |
| ... | ... | @@ -59,10 +60,10 @@ public class CrmQueryWrapperUtils { |
| 59 | 60 | // 2.3 场景三:下属负责的数据 |
| 60 | 61 | if (CrmSceneTypeEnum.isSubordinate(sceneType)) { |
| 61 | 62 | List<AdminUserRespDTO> subordinateUsers = getAdminUserApi().getUserListBySubordinate(userId); |
| 62 | - // TODO @puhui999:如果为空,不拼接,就是查询了所有数据呀? | |
| 63 | - if (CollUtil.isNotEmpty(subordinateUsers)) { | |
| 64 | - query.in("owner_user_id", convertSet(subordinateUsers, AdminUserRespDTO::getId)); | |
| 63 | + if (CollUtil.isEmpty(subordinateUsers)) { | |
| 64 | + return false; | |
| 65 | 65 | } |
| 66 | + query.in("owner_user_id", convertSet(subordinateUsers, AdminUserRespDTO::getId)); | |
| 66 | 67 | } |
| 67 | 68 | |
| 68 | 69 | // 3. 拼接公海的查询条件 |
| ... | ... | @@ -71,6 +72,8 @@ public class CrmQueryWrapperUtils { |
| 71 | 72 | } else { // 情况二:不是公海 |
| 72 | 73 | query.isNotNull("owner_user_id"); |
| 73 | 74 | } |
| 75 | + | |
| 76 | + return true; | |
| 74 | 77 | } |
| 75 | 78 | |
| 76 | 79 | /** |
| ... | ... | @@ -95,8 +98,6 @@ public class CrmQueryWrapperUtils { |
| 95 | 98 | return AdminUserApiHolder.ADMIN_USER_API; |
| 96 | 99 | } |
| 97 | 100 | |
| 98 | - // TODO @puhui999:需要实现; | |
| 99 | - | |
| 100 | 101 | /** |
| 101 | 102 | * 校验用户是否是管理员 |
| 102 | 103 | * |
| ... | ... | @@ -104,6 +105,15 @@ public class CrmQueryWrapperUtils { |
| 104 | 105 | * @return 是/否 |
| 105 | 106 | */ |
| 106 | 107 | private static boolean validateAdminUser(Long userId) { |
| 108 | + // TODO 查询权限配置表用户的角色信息 | |
| 109 | + //CrmPermissionConfig permissionConfig = crmPermissionConfigService.getPermissionConfigByUserId(userId); | |
| 110 | + //if (permissionConfig == null) { | |
| 111 | + // return false; | |
| 112 | + //} | |
| 113 | + //// 校验是否为管理员 | |
| 114 | + //if (permissionConfig.getIsAdmin()){ | |
| 115 | + // return true; | |
| 116 | + //} | |
| 107 | 117 | return false; |
| 108 | 118 | } |
| 109 | 119 | ... | ... |