CRM: 完善数据权限

This commit is contained in:
puhui999 2023-12-11 16:48:21 +08:00
parent 63431082e5
commit c234f5b5f8
8 changed files with 54 additions and 22 deletions

View File

@ -38,8 +38,11 @@ public interface CrmBusinessMapper extends BaseMapperX<CrmBusinessDO> {
default PageResult<CrmBusinessDO> selectPage(CrmBusinessPageReqVO pageReqVO, Long userId) { default PageResult<CrmBusinessDO> selectPage(CrmBusinessPageReqVO pageReqVO, Long userId) {
MPJLambdaWrapperX<CrmBusinessDO> query = new MPJLambdaWrapperX<>(); MPJLambdaWrapperX<CrmBusinessDO> query = new MPJLambdaWrapperX<>();
// 拼接数据权限的查询条件 // 拼接数据权限的查询条件
CrmQueryWrapperUtils.appendPermissionCondition(query, CrmBizTypeEnum.CRM_BUSINESS.getType(), CrmBusinessDO::getId, boolean condition = CrmQueryWrapperUtils.appendPermissionCondition(query, CrmBizTypeEnum.CRM_BUSINESS.getType(),
userId, pageReqVO.getSceneType(), Boolean.FALSE); CrmBusinessDO::getId, userId, pageReqVO.getSceneType(), Boolean.FALSE);
if (!condition) {
return PageResult.empty();
}
// 拼接自身的查询条件 // 拼接自身的查询条件
query.selectAll(CrmBusinessDO.class) query.selectAll(CrmBusinessDO.class)
.likeIfPresent(CrmBusinessDO::getName, pageReqVO.getName()) .likeIfPresent(CrmBusinessDO::getName, pageReqVO.getName())

View File

@ -30,8 +30,11 @@ public interface CrmClueMapper extends BaseMapperX<CrmClueDO> {
default PageResult<CrmClueDO> selectPage(CrmCluePageReqVO pageReqVO, Long userId) { default PageResult<CrmClueDO> selectPage(CrmCluePageReqVO pageReqVO, Long userId) {
MPJLambdaWrapperX<CrmClueDO> query = new MPJLambdaWrapperX<>(); MPJLambdaWrapperX<CrmClueDO> query = new MPJLambdaWrapperX<>();
// 拼接数据权限的查询条件 // 拼接数据权限的查询条件
CrmQueryWrapperUtils.appendPermissionCondition(query, CrmBizTypeEnum.CRM_LEADS.getType(), CrmClueDO::getId, boolean condition = CrmQueryWrapperUtils.appendPermissionCondition(query, CrmBizTypeEnum.CRM_LEADS.getType(),
userId, pageReqVO.getSceneType(), pageReqVO.getPool()); CrmClueDO::getId, userId, pageReqVO.getSceneType(), pageReqVO.getPool());
if (!condition) {
return PageResult.empty();
}
// 拼接自身的查询条件 // 拼接自身的查询条件
query.selectAll(CrmClueDO.class) query.selectAll(CrmClueDO.class)
.likeIfPresent(CrmClueDO::getName, pageReqVO.getName()) .likeIfPresent(CrmClueDO::getName, pageReqVO.getName())

View File

@ -43,8 +43,11 @@ public interface CrmContactMapper extends BaseMapperX<CrmContactDO> {
default PageResult<CrmContactDO> selectPage(CrmContactPageReqVO pageReqVO, Long userId) { default PageResult<CrmContactDO> selectPage(CrmContactPageReqVO pageReqVO, Long userId) {
MPJLambdaWrapperX<CrmContactDO> query = new MPJLambdaWrapperX<>(); MPJLambdaWrapperX<CrmContactDO> query = new MPJLambdaWrapperX<>();
// 拼接数据权限的查询条件 // 拼接数据权限的查询条件
CrmQueryWrapperUtils.appendPermissionCondition(query, CrmBizTypeEnum.CRM_CONTACT.getType(), CrmContactDO::getId, boolean condition = CrmQueryWrapperUtils.appendPermissionCondition(query, CrmBizTypeEnum.CRM_CONTACT.getType(),
userId, pageReqVO.getSceneType(), Boolean.FALSE); CrmContactDO::getId, userId, pageReqVO.getSceneType(), Boolean.FALSE);
if (!condition) {
return PageResult.empty();
}
// 拼接自身的查询条件 // 拼接自身的查询条件
query.selectAll(CrmContactDO.class) query.selectAll(CrmContactDO.class)
.likeIfPresent(CrmContactDO::getName, pageReqVO.getName()) .likeIfPresent(CrmContactDO::getName, pageReqVO.getName())

View File

@ -40,9 +40,13 @@ public interface CrmContractMapper extends BaseMapperX<CrmContractDO> {
default PageResult<CrmContractDO> selectPage(CrmContractPageReqVO pageReqVO, Long userId) { default PageResult<CrmContractDO> selectPage(CrmContractPageReqVO pageReqVO, Long userId) {
MPJLambdaWrapperX<CrmContractDO> mpjLambdaWrapperX = new MPJLambdaWrapperX<>(); MPJLambdaWrapperX<CrmContractDO> mpjLambdaWrapperX = new MPJLambdaWrapperX<>();
// 构建数据权限连表条件 // 拼接数据权限的查询条件
CrmQueryWrapperUtils.appendPermissionCondition(mpjLambdaWrapperX, CrmBizTypeEnum.CRM_CONTACT.getType(), CrmContractDO::getId, boolean condition = CrmQueryWrapperUtils.appendPermissionCondition(mpjLambdaWrapperX, CrmBizTypeEnum.CRM_CONTACT.getType(),
userId, pageReqVO.getSceneType(), Boolean.FALSE); CrmContractDO::getId, userId, pageReqVO.getSceneType(), Boolean.FALSE);
if (!condition) {
return PageResult.empty();
}
// 拼接自身的查询条件
mpjLambdaWrapperX.selectAll(CrmContractDO.class) mpjLambdaWrapperX.selectAll(CrmContractDO.class)
.likeIfPresent(CrmContractDO::getNo, pageReqVO.getNo()) .likeIfPresent(CrmContractDO::getNo, pageReqVO.getNo())
.likeIfPresent(CrmContractDO::getName, pageReqVO.getName()) .likeIfPresent(CrmContractDO::getName, pageReqVO.getName())

View File

@ -30,8 +30,11 @@ public interface CrmCustomerMapper extends BaseMapperX<CrmCustomerDO> {
default PageResult<CrmCustomerDO> selectPage(CrmCustomerPageReqVO pageReqVO, Long userId) { default PageResult<CrmCustomerDO> selectPage(CrmCustomerPageReqVO pageReqVO, Long userId) {
MPJLambdaWrapperX<CrmCustomerDO> query = new MPJLambdaWrapperX<>(); MPJLambdaWrapperX<CrmCustomerDO> query = new MPJLambdaWrapperX<>();
// 拼接数据权限的查询条件 // 拼接数据权限的查询条件
CrmQueryWrapperUtils.appendPermissionCondition(query, CrmBizTypeEnum.CRM_CUSTOMER.getType(), CrmCustomerDO::getId, boolean condition = CrmQueryWrapperUtils.appendPermissionCondition(query, CrmBizTypeEnum.CRM_CUSTOMER.getType(),
userId, pageReqVO.getSceneType(), pageReqVO.getPool()); CrmCustomerDO::getId, userId, pageReqVO.getSceneType(), pageReqVO.getPool());
if (!condition) {
return PageResult.empty();
}
// 拼接自身的查询条件 // 拼接自身的查询条件
query.selectAll(CrmCustomerDO.class) query.selectAll(CrmCustomerDO.class)
.likeIfPresent(CrmCustomerDO::getName, pageReqVO.getName()) .likeIfPresent(CrmCustomerDO::getName, pageReqVO.getName())

View File

@ -39,8 +39,11 @@ public interface CrmReceivableMapper extends BaseMapperX<CrmReceivableDO> {
default PageResult<CrmReceivableDO> selectPage(CrmReceivablePageReqVO pageReqVO, Long userId) { default PageResult<CrmReceivableDO> selectPage(CrmReceivablePageReqVO pageReqVO, Long userId) {
MPJLambdaWrapperX<CrmReceivableDO> query = new MPJLambdaWrapperX<>(); MPJLambdaWrapperX<CrmReceivableDO> query = new MPJLambdaWrapperX<>();
// 拼接数据权限的查询条件 // 拼接数据权限的查询条件
CrmQueryWrapperUtils.appendPermissionCondition(query, CrmBizTypeEnum.CRM_RECEIVABLE.getType(), CrmReceivableDO::getId, boolean condition = CrmQueryWrapperUtils.appendPermissionCondition(query, CrmBizTypeEnum.CRM_RECEIVABLE.getType(),
userId, pageReqVO.getSceneType(), Boolean.FALSE); CrmReceivableDO::getId, userId, pageReqVO.getSceneType(), Boolean.FALSE);
if (!condition) {
return PageResult.empty();
}
// 拼接自身的查询条件 // 拼接自身的查询条件
query.selectAll(CrmReceivableDO.class) query.selectAll(CrmReceivableDO.class)
.eqIfPresent(CrmReceivableDO::getNo, pageReqVO.getNo()) .eqIfPresent(CrmReceivableDO::getNo, pageReqVO.getNo())

View File

@ -38,8 +38,11 @@ public interface CrmReceivablePlanMapper extends BaseMapperX<CrmReceivablePlanDO
default PageResult<CrmReceivablePlanDO> selectPage(CrmReceivablePlanPageReqVO pageReqVO, Long userId) { default PageResult<CrmReceivablePlanDO> selectPage(CrmReceivablePlanPageReqVO pageReqVO, Long userId) {
MPJLambdaWrapperX<CrmReceivablePlanDO> query = new MPJLambdaWrapperX<>(); MPJLambdaWrapperX<CrmReceivablePlanDO> query = new MPJLambdaWrapperX<>();
// 拼接数据权限的查询条件 // 拼接数据权限的查询条件
CrmQueryWrapperUtils.appendPermissionCondition(query, CrmBizTypeEnum.CRM_RECEIVABLE_PLAN.getType(), CrmReceivablePlanDO::getId, boolean condition = CrmQueryWrapperUtils.appendPermissionCondition(query, CrmBizTypeEnum.CRM_RECEIVABLE_PLAN.getType(),
userId, pageReqVO.getSceneType(), Boolean.FALSE); CrmReceivablePlanDO::getId, userId, pageReqVO.getSceneType(), Boolean.FALSE);
if (!condition) {
return PageResult.empty();
}
// 拼接自身的查询条件 // 拼接自身的查询条件
query.selectAll(CrmReceivablePlanDO.class) query.selectAll(CrmReceivablePlanDO.class)
.eqIfPresent(CrmReceivablePlanDO::getCustomerId, pageReqVO.getCustomerId()) .eqIfPresent(CrmReceivablePlanDO::getCustomerId, pageReqVO.getCustomerId())

View File

@ -33,9 +33,10 @@ public class CrmQueryWrapperUtils {
* @param userId 用户编号 * @param userId 用户编号
* @param sceneType 场景类型 * @param sceneType 场景类型
* @param pool 公海 * @param pool 公海
* @return 是否 需要执行查询不需要查询调用方法直接返回空
*/ */
// TODO @puhui999bizId 直接传递会不会简单点 回复还是需要 SFunction 因为分页连表时不知道 bizId 是多少 // TODO @puhui999bizId 直接传递会不会简单点 回复还是需要 SFunction 因为分页连表时不知道 bizId 是多少
public static <T extends MPJLambdaWrapper<?>, S> void appendPermissionCondition(T query, Integer bizType, SFunction<S, ?> bizId, public static <T extends MPJLambdaWrapper<?>, S> boolean appendPermissionCondition(T query, Integer bizType, SFunction<S, ?> bizId,
Long userId, Integer sceneType, Boolean pool) { Long userId, Integer sceneType, Boolean pool) {
// 1. 构建数据权限连表条件 // 1. 构建数据权限连表条件
if (ObjUtil.notEqual(validateAdminUser(userId), Boolean.TRUE)) { // 管理员不需要数据权限 if (ObjUtil.notEqual(validateAdminUser(userId), Boolean.TRUE)) { // 管理员不需要数据权限
@ -59,10 +60,10 @@ public class CrmQueryWrapperUtils {
// 2.3 场景三下属负责的数据 // 2.3 场景三下属负责的数据
if (CrmSceneTypeEnum.isSubordinate(sceneType)) { if (CrmSceneTypeEnum.isSubordinate(sceneType)) {
List<AdminUserRespDTO> subordinateUsers = getAdminUserApi().getUserListBySubordinate(userId); List<AdminUserRespDTO> subordinateUsers = getAdminUserApi().getUserListBySubordinate(userId);
// TODO @puhui999如果为空不拼接就是查询了所有数据呀 if (CollUtil.isEmpty(subordinateUsers)) {
if (CollUtil.isNotEmpty(subordinateUsers)) { return false;
query.in("owner_user_id", convertSet(subordinateUsers, AdminUserRespDTO::getId));
} }
query.in("owner_user_id", convertSet(subordinateUsers, AdminUserRespDTO::getId));
} }
// 3. 拼接公海的查询条件 // 3. 拼接公海的查询条件
@ -71,6 +72,8 @@ public class CrmQueryWrapperUtils {
} else { // 情况二不是公海 } else { // 情况二不是公海
query.isNotNull("owner_user_id"); query.isNotNull("owner_user_id");
} }
return true;
} }
/** /**
@ -95,8 +98,6 @@ public class CrmQueryWrapperUtils {
return AdminUserApiHolder.ADMIN_USER_API; return AdminUserApiHolder.ADMIN_USER_API;
} }
// TODO @puhui999需要实现
/** /**
* 校验用户是否是管理员 * 校验用户是否是管理员
* *
@ -104,6 +105,15 @@ public class CrmQueryWrapperUtils {
* @return / * @return /
*/ */
private static boolean validateAdminUser(Long userId) { private static boolean validateAdminUser(Long userId) {
// TODO 查询权限配置表用户的角色信息
//CrmPermissionConfig permissionConfig = crmPermissionConfigService.getPermissionConfigByUserId(userId);
//if (permissionConfig == null) {
// return false;
//}
//// 校验是否为管理员
//if (permissionConfig.getIsAdmin()){
// return true;
//}
return false; return false;
} }