Commit f4c92089e58c50e4bbba545bac8927b13fd50117
1 parent
388e07c8
CRM-客户:添加分页数据场景过滤
Showing
4 changed files
with
62 additions
and
4 deletions
yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/customer/CrmCustomerSceneEnum.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.crm.enums.customer; | |
| 2 | + | |
| 3 | +import cn.hutool.core.util.ObjUtil; | |
| 4 | +import cn.iocoder.yudao.framework.common.core.IntArrayValuable; | |
| 5 | +import lombok.AllArgsConstructor; | |
| 6 | +import lombok.Getter; | |
| 7 | + | |
| 8 | +import java.util.Arrays; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * CRM 客户等级 | |
| 12 | + * | |
| 13 | + * @author Wanwan | |
| 14 | + */ | |
| 15 | +@Getter | |
| 16 | +@AllArgsConstructor | |
| 17 | +public enum CrmCustomerSceneEnum implements IntArrayValuable { | |
| 18 | + | |
| 19 | + OWNER(1, "我负责的客户"), | |
| 20 | + FOLLOW(2, "我关注的客户"); | |
| 21 | + | |
| 22 | + public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(CrmCustomerSceneEnum::getType).toArray(); | |
| 23 | + | |
| 24 | + /** | |
| 25 | + * 场景类型 | |
| 26 | + */ | |
| 27 | + private final Integer type; | |
| 28 | + /** | |
| 29 | + * 场景名称 | |
| 30 | + */ | |
| 31 | + private final String name; | |
| 32 | + | |
| 33 | + public static boolean isOwner(Integer type) { | |
| 34 | + return ObjUtil.equal(OWNER.getType(), type); | |
| 35 | + } | |
| 36 | + | |
| 37 | + public static boolean isFollow(Integer type) { | |
| 38 | + return ObjUtil.equal(FOLLOW.getType(), type); | |
| 39 | + } | |
| 40 | + | |
| 41 | + @Override | |
| 42 | + public int[] array() { | |
| 43 | + return ARRAYS; | |
| 44 | + } | |
| 45 | + | |
| 46 | +} | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/CrmCustomerPageReqVO.java
| 1 | 1 | package cn.iocoder.yudao.module.crm.controller.admin.customer.vo; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageParam; |
| 4 | +import cn.iocoder.yudao.module.crm.enums.customer.CrmCustomerSceneEnum; | |
| 4 | 5 | import io.swagger.v3.oas.annotations.media.Schema; |
| 5 | 6 | import lombok.Data; |
| 6 | 7 | import lombok.EqualsAndHashCode; |
| ... | ... | @@ -27,5 +28,10 @@ public class CrmCustomerPageReqVO extends PageParam { |
| 27 | 28 | @Schema(description = "客户来源", example = "1") |
| 28 | 29 | private Integer source; |
| 29 | 30 | |
| 30 | - // TODO @芋艿:场景; | |
| 31 | + /** | |
| 32 | + * 场景类型,关联 {@link CrmCustomerSceneEnum} | |
| 33 | + */ | |
| 34 | + @Schema(description = "场景类型", example = "1") | |
| 35 | + private Integer sceneType; | |
| 36 | + | |
| 31 | 37 | } | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/core/aop/CrmPermissionAspect.java
| ... | ... | @@ -59,9 +59,9 @@ public class CrmPermissionAspect { |
| 59 | 59 | @Before("@annotation(crmPermission)") |
| 60 | 60 | public void doBefore(JoinPoint joinPoint, CrmPermission crmPermission) throws NoSuchMethodException { |
| 61 | 61 | // TODO 芋艿:临时,方便大家调试 |
| 62 | - //if (true) { | |
| 63 | - // return; | |
| 64 | - //} | |
| 62 | + if (true) { | |
| 63 | + return; | |
| 64 | + } | |
| 65 | 65 | KeyValue<Long, Integer> bizIdAndBizType = getBizIdAndBizType(joinPoint, crmPermission); |
| 66 | 66 | Integer bizType = bizIdAndBizType.getValue(); // 模块类型 |
| 67 | 67 | Long bizId = bizIdAndBizType.getKey(); // 模块数据编号 | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerServiceImpl.java
| ... | ... | @@ -3,11 +3,13 @@ package cn.iocoder.yudao.module.crm.service.customer; |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.hutool.core.util.ObjUtil; |
| 5 | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | |
| 6 | 7 | import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.*; |
| 7 | 8 | import cn.iocoder.yudao.module.crm.convert.customer.CrmCustomerConvert; |
| 8 | 9 | import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; |
| 9 | 10 | import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO; |
| 10 | 11 | import cn.iocoder.yudao.module.crm.dal.mysql.customer.CrmCustomerMapper; |
| 12 | +import cn.iocoder.yudao.module.crm.enums.customer.CrmCustomerSceneEnum; | |
| 11 | 13 | import cn.iocoder.yudao.module.crm.framework.core.annotations.CrmPermission; |
| 12 | 14 | import cn.iocoder.yudao.module.crm.framework.enums.CrmBizTypeEnum; |
| 13 | 15 | import cn.iocoder.yudao.module.crm.framework.enums.CrmPermissionLevelEnum; |
| ... | ... | @@ -100,6 +102,10 @@ public class CrmCustomerServiceImpl implements CrmCustomerService { |
| 100 | 102 | // 1.2 获取当前用户能看的分页数据 |
| 101 | 103 | List<CrmPermissionDO> permissions = crmPermissionService.getPermissionListByBizTypeAndUserId( |
| 102 | 104 | CrmBizTypeEnum.CRM_CUSTOMER.getType(), userId); |
| 105 | + // 1.3 TODO 场景数据过滤 | |
| 106 | + if (CrmCustomerSceneEnum.isOwner(pageReqVO.getSceneType())) { // 场景一:我负责的数据 | |
| 107 | + permissions = CollectionUtils.filterList(permissions, item -> CrmPermissionLevelEnum.isOwner(item.getLevel())); | |
| 108 | + } | |
| 103 | 109 | Set<Long> ids = convertSet(permissions, CrmPermissionDO::getBizId); |
| 104 | 110 | if (CollUtil.isEmpty(ids)) { // 没得说明没有什么给他看的 |
| 105 | 111 | return PageResult.empty(); | ... | ... |