Commit 78165f2161ddbdf631c0052c1b0c4ea327121f84
1 parent
b2621c88
CRM: 新增 CRM 分页查询工具类,实现通用构造 crm 数据类型数据分页查询条件
Showing
2 changed files
with
69 additions
and
1 deletions
yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/common/CrmSceneEnum.java
| @@ -17,7 +17,8 @@ import java.util.Arrays; | @@ -17,7 +17,8 @@ import java.util.Arrays; | ||
| 17 | public enum CrmSceneEnum implements IntArrayValuable { | 17 | public enum CrmSceneEnum implements IntArrayValuable { |
| 18 | 18 | ||
| 19 | OWNER(1, "我负责的"), | 19 | OWNER(1, "我负责的"), |
| 20 | - FOLLOW(2, "我关注的"); | 20 | + FOLLOW(2, "我关注的"), |
| 21 | + SUBORDINATE(3, "下属负责的"); | ||
| 21 | 22 | ||
| 22 | public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(CrmSceneEnum::getType).toArray(); | 23 | public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(CrmSceneEnum::getType).toArray(); |
| 23 | 24 | ||
| @@ -38,6 +39,10 @@ public enum CrmSceneEnum implements IntArrayValuable { | @@ -38,6 +39,10 @@ public enum CrmSceneEnum implements IntArrayValuable { | ||
| 38 | return ObjUtil.equal(FOLLOW.getType(), type); | 39 | return ObjUtil.equal(FOLLOW.getType(), type); |
| 39 | } | 40 | } |
| 40 | 41 | ||
| 42 | + public static boolean isSubordinate(Integer type) { | ||
| 43 | + return ObjUtil.equal(SUBORDINATE.getType(), type); | ||
| 44 | + } | ||
| 45 | + | ||
| 41 | @Override | 46 | @Override |
| 42 | public int[] array() { | 47 | public int[] array() { |
| 43 | return ARRAYS; | 48 | return ARRAYS; |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/util/CrmQueryPageUtils.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.crm.util; | ||
| 2 | + | ||
| 3 | +import cn.hutool.core.collection.CollUtil; | ||
| 4 | +import cn.hutool.core.util.ObjUtil; | ||
| 5 | +import cn.iocoder.yudao.module.crm.dal.dataobject.concerned.CrmConcernedDO; | ||
| 6 | +import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO; | ||
| 7 | +import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum; | ||
| 8 | +import cn.iocoder.yudao.module.crm.enums.common.CrmSceneEnum; | ||
| 9 | +import cn.iocoder.yudao.module.crm.framework.vo.CrmBasePageReqVO; | ||
| 10 | +import com.baomidou.mybatisplus.core.toolkit.support.SFunction; | ||
| 11 | +import com.github.yulichang.wrapper.MPJLambdaWrapper; | ||
| 12 | + | ||
| 13 | +import javax.annotation.Nullable; | ||
| 14 | +import java.util.Collection; | ||
| 15 | + | ||
| 16 | +/** | ||
| 17 | + * CRM 分页查询工具类 | ||
| 18 | + * | ||
| 19 | + * @author HUIHUI | ||
| 20 | + */ | ||
| 21 | +public class CrmQueryPageUtils { | ||
| 22 | + | ||
| 23 | + /** | ||
| 24 | + * 构造 crm 数据类型数据分页查询条件 | ||
| 25 | + * | ||
| 26 | + * @param queryMapper 连表查询对象 | ||
| 27 | + * @param reqVO 查询条件 | ||
| 28 | + * @param userId 用户编号 | ||
| 29 | + * @param bizType 数据类型 {@link CrmBizTypeEnum} | ||
| 30 | + * @param bizId 数据编号 | ||
| 31 | + * @param subordinateIds 下属用户编号,可为空 | ||
| 32 | + */ | ||
| 33 | + public static <T extends MPJLambdaWrapper<?>, V extends CrmBasePageReqVO, S> void builderQuery(T queryMapper, V reqVO, Long userId, | ||
| 34 | + Integer bizType, SFunction<S, ?> bizId, | ||
| 35 | + @Nullable Collection<Long> subordinateIds, | ||
| 36 | + Boolean isAdmin) { | ||
| 37 | + // 构建数据权限连表条件 | ||
| 38 | + if (ObjUtil.notEqual(isAdmin, Boolean.TRUE)) { // 管理员不需要数据权限 | ||
| 39 | + queryMapper.innerJoin(CrmPermissionDO.class, on -> | ||
| 40 | + on.eq(CrmPermissionDO::getBizType, bizType).eq(CrmPermissionDO::getBizId, bizId) | ||
| 41 | + .eq(CrmPermissionDO::getUserId, userId)); | ||
| 42 | + } | ||
| 43 | + if (ObjUtil.equal(reqVO.getPool(), Boolean.TRUE)) { // 情况一:公海 | ||
| 44 | + queryMapper.isNull("owner_user_id"); | ||
| 45 | + } else { // 情况二:不是公海 | ||
| 46 | + queryMapper.isNotNull("owner_user_id"); | ||
| 47 | + } | ||
| 48 | + // 场景数据过滤 | ||
| 49 | + if (CrmSceneEnum.isOwner(reqVO.getSceneType())) { // 场景一:我负责的数据 | ||
| 50 | + queryMapper.eq("owner_user_id", userId); | ||
| 51 | + } | ||
| 52 | + if (CrmSceneEnum.isFollow(reqVO.getSceneType())) { // 场景二:我关注的数据 | ||
| 53 | + queryMapper.innerJoin(CrmConcernedDO.class, on -> | ||
| 54 | + on.eq(CrmConcernedDO::getBizType, bizType).eq(CrmConcernedDO::getBizId, bizId) | ||
| 55 | + .eq(CrmConcernedDO::getUserId, userId)); | ||
| 56 | + } | ||
| 57 | + // TODO puhui999: 这里有一个疑问:如果下属负责的数据权限中没有自己的话还能看吗? | ||
| 58 | + if (CrmSceneEnum.isSubordinate(reqVO.getSceneType()) && CollUtil.isNotEmpty(subordinateIds)) { // 场景三:下属负责的数据 | ||
| 59 | + queryMapper.in("owner_user_id", subordinateIds); | ||
| 60 | + } | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | +} |