From f4c92089e58c50e4bbba545bac8927b13fd50117 Mon Sep 17 00:00:00 2001
From: puhui999 <puhui999@163.com>
Date: Wed, 8 Nov 2023 16:42:22 +0800
Subject: [PATCH] =?UTF-8?q?CRM-=E5=AE=A2=E6=88=B7=EF=BC=9A=E6=B7=BB?=
 =?UTF-8?q?=E5=8A=A0=E5=88=86=E9=A1=B5=E6=95=B0=E6=8D=AE=E5=9C=BA=E6=99=AF?=
 =?UTF-8?q?=E8=BF=87=E6=BB=A4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../enums/customer/CrmCustomerSceneEnum.java  | 46 +++++++++++++++++++
 .../customer/vo/CrmCustomerPageReqVO.java     |  8 +++-
 .../core/aop/CrmPermissionAspect.java         |  6 +--
 .../customer/CrmCustomerServiceImpl.java      |  6 +++
 4 files changed, 62 insertions(+), 4 deletions(-)
 create mode 100644 yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/customer/CrmCustomerSceneEnum.java

diff --git a/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/customer/CrmCustomerSceneEnum.java b/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/customer/CrmCustomerSceneEnum.java
new file mode 100644
index 000000000..1bb374081
--- /dev/null
+++ b/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/customer/CrmCustomerSceneEnum.java
@@ -0,0 +1,46 @@
+package cn.iocoder.yudao.module.crm.enums.customer;
+
+import cn.hutool.core.util.ObjUtil;
+import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+import java.util.Arrays;
+
+/**
+ * CRM 客户等级
+ *
+ * @author Wanwan
+ */
+@Getter
+@AllArgsConstructor
+public enum CrmCustomerSceneEnum implements IntArrayValuable {
+
+    OWNER(1, "我负责的客户"),
+    FOLLOW(2, "我关注的客户");
+
+    public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(CrmCustomerSceneEnum::getType).toArray();
+
+    /**
+     * 场景类型
+     */
+    private final Integer type;
+    /**
+     * 场景名称
+     */
+    private final String name;
+
+    public static boolean isOwner(Integer type) {
+        return ObjUtil.equal(OWNER.getType(), type);
+    }
+
+    public static boolean isFollow(Integer type) {
+        return ObjUtil.equal(FOLLOW.getType(), type);
+    }
+
+    @Override
+    public int[] array() {
+        return ARRAYS;
+    }
+
+}
diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/CrmCustomerPageReqVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/CrmCustomerPageReqVO.java
index c34980b36..5f8b9f28e 100644
--- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/CrmCustomerPageReqVO.java
+++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/CrmCustomerPageReqVO.java
@@ -1,6 +1,7 @@
 package cn.iocoder.yudao.module.crm.controller.admin.customer.vo;
 
 import cn.iocoder.yudao.framework.common.pojo.PageParam;
+import cn.iocoder.yudao.module.crm.enums.customer.CrmCustomerSceneEnum;
 import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
@@ -27,5 +28,10 @@ public class CrmCustomerPageReqVO extends PageParam {
     @Schema(description = "客户来源", example = "1")
     private Integer source;
 
-    // TODO @芋艿:场景;
+    /**
+     * 场景类型,关联 {@link CrmCustomerSceneEnum}
+     */
+    @Schema(description = "场景类型", example = "1")
+    private Integer sceneType;
+
 }
diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/core/aop/CrmPermissionAspect.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/core/aop/CrmPermissionAspect.java
index c306bd78a..251a921ff 100644
--- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/core/aop/CrmPermissionAspect.java
+++ b/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 {
     @Before("@annotation(crmPermission)")
     public void doBefore(JoinPoint joinPoint, CrmPermission crmPermission) throws NoSuchMethodException {
         // TODO 芋艿:临时,方便大家调试
-        //if (true) {
-        //    return;
-        //}
+        if (true) {
+            return;
+        }
         KeyValue<Long, Integer> bizIdAndBizType = getBizIdAndBizType(joinPoint, crmPermission);
         Integer bizType = bizIdAndBizType.getValue(); // 模块类型
         Long bizId = bizIdAndBizType.getKey(); // 模块数据编号
diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerServiceImpl.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerServiceImpl.java
index 56e958334..5d56211d6 100644
--- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerServiceImpl.java
+++ b/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;
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.ObjUtil;
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
+import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
 import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.*;
 import cn.iocoder.yudao.module.crm.convert.customer.CrmCustomerConvert;
 import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
 import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO;
 import cn.iocoder.yudao.module.crm.dal.mysql.customer.CrmCustomerMapper;
+import cn.iocoder.yudao.module.crm.enums.customer.CrmCustomerSceneEnum;
 import cn.iocoder.yudao.module.crm.framework.core.annotations.CrmPermission;
 import cn.iocoder.yudao.module.crm.framework.enums.CrmBizTypeEnum;
 import cn.iocoder.yudao.module.crm.framework.enums.CrmPermissionLevelEnum;
@@ -100,6 +102,10 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
         // 1.2 获取当前用户能看的分页数据
         List<CrmPermissionDO> permissions = crmPermissionService.getPermissionListByBizTypeAndUserId(
                 CrmBizTypeEnum.CRM_CUSTOMER.getType(), userId);
+        // 1.3 TODO 场景数据过滤
+        if (CrmCustomerSceneEnum.isOwner(pageReqVO.getSceneType())) { // 场景一:我负责的数据
+            permissions = CollectionUtils.filterList(permissions, item -> CrmPermissionLevelEnum.isOwner(item.getLevel()));
+        }
         Set<Long> ids = convertSet(permissions, CrmPermissionDO::getBizId);
         if (CollUtil.isEmpty(ids)) { // 没得说明没有什么给他看的
             return PageResult.empty();