Sfoglia il codice sorgente

fix(sys-customer): 优化客户数据权限和异常处理逻辑

- 公海客户列表接口添加异常抛出声明,完善数据验证与异常提示格式
- 导入客户数据时新增重复数据校验,避免重复导入
- 调整退还公共客户数据消费逻辑,取消原有限制条件
- 我的客户查询新增用户角色判断与默认UserId赋值,完善用户权限控制
- 跟进订单查询过滤条件中增加UserId参数,支持按用户过滤数据
- 修改预约待办列表,管理员条件下成员排序调整,管理员优先显示
- 私域客户管理中基于用户小组关系实现多维条件过滤,实现更细粒度权限控制
- 细化客户详情查询中用户权限校验,避免管理员查看不存在客户错误
- 跟进数据和日志查询新增用户权限判断,确保非管理员仅访问自身数据
- 调整部分条件查询排序逻辑,优化数据返回顺序
- 移除部分注释代码,提升代码可读性和维护性
zhangxf 13 ore fa
parent
commit
9804e3f275

+ 15 - 8
src/main/java/com/jtzx/crm/module/api/web/sys/CustomerDataPublicController.java

@@ -53,7 +53,7 @@ public class CustomerDataPublicController {
 
     @Operation(summary = "分页查询公海客户信息列表数据接口")
     @PostMapping(value = "/customer/list")
-    public ApiResult<PageResult<SysCustomerDataPublicBO>> list(@RequestBody @Valid AdminSysCustomerDataPublicListDTO dto) {
+    public ApiResult<PageResult<SysCustomerDataPublicBO>> list(@RequestBody @Valid AdminSysCustomerDataPublicListDTO dto) throws BusinessException {
         PageResult<SysCustomerDataPublicBO> pageResult = sysCustomerDataPublicService.adminList(dto);
         return ApiResult.data(pageResult);
     }
@@ -203,19 +203,19 @@ public class CustomerDataPublicController {
             dto.setName((String) rowData.get(0));
 
             if (rowData.get(1) == null) {
-                throw new BusinessException(rowData.get(0)+"/学段不能为空");
+                throw new BusinessException(rowData.get(0) + "/学段不能为空");
             }
             dto.setStageName((String) rowData.get(1));
             List<SysParamBaseDataEntity> stageList = sysParamBaseDataEntities.stream()
                     .filter(sysParamBaseDataEntity -> sysParamBaseDataEntity.getTitle().equals(rowData.get(1)))
                     .toList();
             if (CollUtil.isEmpty(stageList)) {
-                throw new BusinessException(rowData.get(0)+ "学段不存在,导入失败");
+                throw new BusinessException(rowData.get(0) + "学段不存在,导入失败");
             }
             dto.setStageId(stageList.getFirst().getId());
 
             if (rowData.get(2) == null) {
-                throw new BusinessException(rowData.get(0)+"省份不能为空");
+                throw new BusinessException(rowData.get(0) + "省份不能为空");
             }
             dto.setProvinceName((String) rowData.get(2));
             if (dto.getProvinceName().startsWith("北京")) {
@@ -245,18 +245,18 @@ public class CustomerDataPublicController {
                     .filter(dictProvinceRegionBO -> dictProvinceRegionBO.getName().equals(dto.getProvinceName()))
                     .toList();
             if (CollUtil.isEmpty(provinceList)) {
-                throw new BusinessException(rowData.get(0)+"省份不存在,导入失败");
+                throw new BusinessException(rowData.get(0) + "省份不存在,导入失败");
             }
             dto.setProvinceId(provinceList.getFirst().getId());
             if (rowData.get(3) == null) {
-                throw new BusinessException(rowData.get(0)+"城市不能为空");
+                throw new BusinessException(rowData.get(0) + "城市不能为空");
             }
             dto.setCityName((String) rowData.get(3));
             if (dto.getProvinceName().startsWith("北京") ||
                     dto.getProvinceName().startsWith("天津") ||
                     dto.getProvinceName().startsWith("上海") ||
                     dto.getProvinceName().startsWith("重庆")) {
-                if(!dto.getCityName().endsWith("区")){
+                if (!dto.getCityName().endsWith("区")) {
                     dto.setCityName(dto.getCityName() + "区");
                 }
             }
@@ -264,11 +264,18 @@ public class CustomerDataPublicController {
                     .filter(dictCityRegionBO -> dictCityRegionBO.getName().equals(dto.getCityName()))
                     .toList();
             if (CollUtil.isEmpty(cityList)) {
-                throw new BusinessException(rowData.get(0)+"城市不存在,导入失败");
+                throw new BusinessException(rowData.get(0) + "城市不存在,导入失败");
             }
             dto.setCityId(cityList.getFirst().getId());
 
             dto.setAddress((String) rowData.get(4));
+            if(CollUtil.isNotEmpty(dtoLists) &&
+                    dtoLists.stream().noneMatch(d -> d.getName().equals(dto.getName())
+                            && d.getStageName().equals(dto.getStageName())
+                            && d.getCityName().equals(dto.getCityName())
+                            && d.getProvinceName().equals(dto.getProvinceName()))){
+                throw new BusinessException(dto.getName()+"导入数据重复,导入失败");
+            }
             dtoLists.add(dto);
         }
         return dtoLists;

+ 21 - 4
src/main/java/com/jtzx/crm/module/sys/entity/SysCustomerPersonEntity.java

@@ -1,6 +1,7 @@
 package com.jtzx.crm.module.sys.entity;
 
 import cc.uncarbon.framework.crud.entity.HelioBaseEntity;
+import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.jtzx.crm.module.sys.model.request.AdminSysCustomerPersonInsertOrUpdateDTO;
@@ -92,14 +93,30 @@ public class SysCustomerPersonEntity extends HelioBaseEntity<Long> {
 
         // 4. 办公电话
         if (!Objects.equals(this.officePhoneNo, dto.getOfficePhoneNo())) {
-            original.append("办公电话【").append(this.officePhoneNo).append("】");
-            update.append("办公电话【").append(dto.getOfficePhoneNo()).append("】");
+            if(StrUtil.isEmpty(this.officePhoneNo)){
+                original.append("办公电话【").append("空").append("】");
+            }else {
+                original.append("办公电话【").append(this.officePhoneNo).append("】");
+            }
+            if(StrUtil.isEmpty(dto.getOfficePhoneNo())){
+                update.append("办公电话【").append("空").append("】");
+            }else {
+                update.append("办公电话【").append(dto.getOfficePhoneNo()).append("】");
+            }
         }
 
         // 5. 备注
         if (!Objects.equals(this.remark, dto.getRemark())) {
-            original.append("备注【").append(this.remark).append("】");
-            update.append("备注【").append(dto.getRemark()).append("】");
+            if(StrUtil.isEmpty(this.remark)){
+                original.append("备注【").append("空").append("】");
+            }else {
+                original.append("备注【").append(this.remark).append("】");
+            }
+            if(StrUtil.isEmpty(dto.getRemark())){
+                update.append("备注【").append("空").append("】");
+            }else {
+                update.append("备注【").append(dto.getRemark()).append("】");
+            }
         }
         if(!original.isEmpty() && !update.isEmpty()){
             return original + "," + update;

+ 2 - 1
src/main/java/com/jtzx/crm/module/sys/queue/ReturnPublicConsumer.java

@@ -42,7 +42,8 @@ public class ReturnPublicConsumer {
         Long id = sysCustomerDataEntity.getId();
         Long claimUserId = sysCustomerDataEntity.getClaimUserId();
         SysCustomerDataEntity customerData = sysCustomerDataMapper.selectById(id);
-        if (customerData != null && customerData.getClaimUserId()!=null && customerData.getClaimUserId().equals(claimUserId)) {
+//        if (customerData != null && customerData.getClaimUserId()!=null && customerData.getClaimUserId().equals(claimUserId)) {
+        if (customerData != null) {
             long count =
                     sysCustomerFollowMapper.selectCount(
                             new LambdaQueryWrapper<>(SysCustomerFollowEntity.class)

+ 7 - 9
src/main/java/com/jtzx/crm/module/sys/service/SysCustomerDataFollowOrderService.java

@@ -1,6 +1,7 @@
 package com.jtzx.crm.module.sys.service;
 
 
+import cc.uncarbon.framework.core.context.UserContextHolder;
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.date.DateField;
 import cn.hutool.core.date.DateTime;
@@ -43,7 +44,11 @@ public class SysCustomerDataFollowOrderService {
         resultData.setStatus2Count(0);
         resultData.setTotalCount(0);
         resultData.setDateList(Lists.newArrayList());
-
+        if (dto.getUserId() == null) {
+            if(!UserContextHolder.getUserContext().getRoles().contains("Admin")){
+                dto.setUserId(UserContextHolder.getUserId());
+            }
+        }
 
         String dateStr = DateUtil.format(LocalDateTime.now(), "yyyy-MM-dd");
         if (StrUtil.isNotEmpty(dto.getDatetime())) {
@@ -54,20 +59,13 @@ public class SysCustomerDataFollowOrderService {
 //        //当月结束时间
         DateTime endMonthDay = DateUtil.endOfMonth(DateUtil.parse(dateStr));
         // 筛选条件数据
-        resultData.setSelectData(sysCustomerDataFollowService.queryCustomerOrderSelectData(0, true,startMonthDay,endMonthDay));
+        resultData.setSelectData(sysCustomerDataFollowService.queryCustomerOrderSelectData(dto.getUserId(),0, true,startMonthDay,endMonthDay));
 
 
 
         //如果是 yyyy-MM 格式,则需要重新设置为当月开始时间和结束时间
         DateTime startDateTime = DateUtil.beginOfDay(DateUtil.parseDate(dateStr));
         DateTime endDateTime = DateUtil.endOfDay(DateUtil.parseDate(dateStr));
-        //如果是 yyyy-MM-dd 格式,则需要重新设置为当天开始时间和结束时间
-//        if (dateStr.length() == 10) {
-//            //当天开始时间
-//            startDateTime = DateUtil.beginOfDay(DateUtil.parseDate(dateStr));
-//            //当天结束时间
-//            endDateTime = DateUtil.endOfDay(DateUtil.parseDate(dateStr));
-//        }
         //数据列表
         resultData.setDataList(
                 sysCustomerDataFollowService.queryCustomerFollowOrderData(DateUtil.toLocalDateTime(startDateTime),

+ 74 - 47
src/main/java/com/jtzx/crm/module/sys/service/SysCustomerDataFollowService.java

@@ -46,6 +46,8 @@ public class SysCustomerDataFollowService {
 
     private final SysCustomerDataMapper sysCustomerDataMapper;
 
+    private final SysUserMapper sysUserMapper;
+
     private final SysCustomerUserCommonService sysCustomerUserCommonService;
 
     private final SysCustomerOperLogService sysCustomerOperLogService;
@@ -77,7 +79,7 @@ public class SysCustomerDataFollowService {
             //人员
             resultData.setMemberData(sysCustomerSelectBO.getMemberData());
         }
-        if (!UserContextHolder.getUserContext().getRoles().contains("Admin")) {
+        if (UserContextHolder.getUserContext().getRoles().contains("Admin")) {
             //查询赢单审核数据
             long count =
                     sysCustomerFollowAuditMapper.selectCount(
@@ -86,7 +88,7 @@ public class SysCustomerDataFollowService {
                                     .select(
                                             SysCustomerFollowAuditEntity::getFollowId
                                     )
-                                    .eq(SysCustomerFollowAuditEntity::getAuditUserId, UserContextHolder.getUserId())
+//                                    .eq(SysCustomerFollowAuditEntity::getAuditUserId, UserContextHolder.getUserId())
                                     .eq(SysCustomerFollowAuditEntity::getAuditStatus, 0)
                                     // 排序
                                     .orderByDesc(SysCustomerFollowAuditEntity::getCreatedAt)
@@ -157,8 +159,8 @@ public class SysCustomerDataFollowService {
      * 操作日志列表查询
      */
     public SysCustomerOperLogDataBO queryOperLogData(AdminSysCustomerOperLogListDTO dto) {
-        if(!UserContextHolder.getUserContext().getRoles().contains("Admin")){
-            throw new BusinessException(400,"无权操作");
+        if (!UserContextHolder.getUserContext().getRoles().contains("Admin")) {
+            throw new BusinessException(400, "无权操作");
         }
         List<Long> userIds = Lists.newArrayList();
         if (dto.getOperUserId() != null) {
@@ -168,27 +170,6 @@ public class SysCustomerDataFollowService {
         if (dto.getGroupId() != null) {
             groupIds.add(dto.getGroupId());
         }
-//        SysCustomerSelectBO selectBO = sysCustomerUserCommonService.querySelectDataByType2(true);
-//        if (selectBO != null && CollUtil.isNotEmpty(selectBO.getRegionData())) {
-//            List<Long> cityIds = Lists.newArrayList();
-//            selectBO.getRegionData()
-//                    .forEach(provinceRegion ->
-//                            provinceRegion.getSubData()
-//                                    .forEach(city -> cityIds.add(city.getId())));
-//            List<BindUserBO> bindUserBOS = sysCustomerUserCommonService.queryBindUserListByCityId(cityIds);
-//            if (CollUtil.isNotEmpty(bindUserBOS)) {
-//                if (CollUtil.isEmpty(userIds)) {
-//                    userIds.addAll(
-//                            bindUserBOS.stream()
-//                                    .map(BindUserBO::getId).toList());
-//                }
-//                if (CollUtil.isEmpty(groupIds)) {
-//                    groupIds.addAll(
-//                            bindUserBOS.stream()
-//                                    .map(BindUserBO::getGroupId).distinct().toList());
-//                }
-//            }
-//        }
         return sysCustomerOperLogService.adminList(dto, userIds, groupIds, true, true);
     }
 
@@ -198,7 +179,7 @@ public class SysCustomerDataFollowService {
      *
      * @return
      */
-    public SysCustomerFollowHistorySelectBO queryCustomerOrderSelectData(Integer orderType, Boolean orderStatus,
+    public SysCustomerFollowHistorySelectBO queryCustomerOrderSelectData(Long userId, Integer orderType, Boolean orderStatus,
                                                                          DateTime startDateTime, DateTime endDateTime) {
         SysCustomerFollowHistorySelectBO resultData = SysCustomerFollowHistorySelectBO.builder().build();
         List<BindUserBO> memberData = Lists.newArrayList();
@@ -212,8 +193,9 @@ public class SysCustomerDataFollowService {
                                         SysCustomerFollowEntity::getClaimUserName,
                                         SysCustomerFollowEntity::getOrderStatus
                                 )
+                                .eq(SysCustomerFollowEntity::getClaimUserId, userId)
                                 .eq(SysCustomerFollowEntity::getOrderType, orderType)
-                                .eq(SysCustomerFollowEntity::getFollowId,33) //只查询方案演示
+                                .eq(SysCustomerFollowEntity::getFollowId, 33) //只查询方案演示
                                 .ge(startDateTime != null, SysCustomerFollowEntity::getOrderDatetime, DateUtil.toLocalDateTime(startDateTime))
                                 .le(endDateTime != null, SysCustomerFollowEntity::getOrderDatetime, DateUtil.toLocalDateTime(endDateTime))
                                 .orderByDesc(SysCustomerFollowEntity::getCreatedAt)
@@ -266,6 +248,33 @@ public class SysCustomerDataFollowService {
         return resultData;
     }
 
+
+    public SysCustomerFollowHistorySelectBO queryCustomerFollowSelectCommonHistoryData(Long customerId, Long userId) {
+        if (userId == null) {
+            if (!UserContextHolder.getUserContext().getRoles().contains("Admin")) {
+                userId = UserContextHolder.getUserId();
+            }
+        }
+        List<SysCustomerFollowEntity> followEntityList =
+                sysCustomerFollowMapper.selectList(
+                        new LambdaQueryWrapper<>(SysCustomerFollowEntity.class)
+                                .select(
+                                        SysCustomerFollowEntity::getProductId,
+                                        SysCustomerFollowEntity::getProductName,
+                                        SysCustomerFollowEntity::getFollowId,
+                                        SysCustomerFollowEntity::getFollowName,
+                                        SysCustomerFollowEntity::getClaimUserId,
+                                        SysCustomerFollowEntity::getClaimUserName,
+                                        SysCustomerFollowEntity::getPositionId,
+                                        SysCustomerFollowEntity::getPositionName
+                                )
+                                .eq(customerId != null, SysCustomerFollowEntity::getCustomerId, customerId)
+                                .ne(userId != null, SysCustomerFollowEntity::getClaimUserId, userId)
+                                .orderByDesc(SysCustomerFollowEntity::getCreatedAt)
+                );
+        return this.handleCustomerFollowSelectCommonHistoryData(followEntityList);
+    }
+
     /**
      * 客户跟进顶部筛选条件数据公开方法
      *
@@ -273,11 +282,11 @@ public class SysCustomerDataFollowService {
      * @return
      */
     public SysCustomerFollowHistorySelectBO queryCustomerFollowSelectCommonData(Long customerId, Long userId) {
-        SysCustomerFollowHistorySelectBO resultData = SysCustomerFollowHistorySelectBO.builder().build();
-        List<SelectBO> productData = Lists.newArrayList();
-        List<SelectBO> followData = Lists.newArrayList();
-        List<BindUserBO> memberData = Lists.newArrayList();
-        List<SelectBO> positionData = Lists.newArrayList();
+        if (userId == null) {
+            if (!UserContextHolder.getUserContext().getRoles().contains("Admin")) {
+                userId = UserContextHolder.getUserId();
+            }
+        }
         //查询跟进数据
         List<SysCustomerFollowEntity> followEntityList =
                 sysCustomerFollowMapper.selectList(
@@ -293,9 +302,24 @@ public class SysCustomerDataFollowService {
                                         SysCustomerFollowEntity::getPositionName
                                 )
                                 .eq(customerId != null, SysCustomerFollowEntity::getCustomerId, customerId)
-                                .ne(userId != null, SysCustomerFollowEntity::getClaimUserId, userId)
+                                .eq(userId != null, SysCustomerFollowEntity::getClaimUserId, userId)
                                 .orderByDesc(SysCustomerFollowEntity::getCreatedAt)
                 );
+        return this.handleCustomerFollowSelectCommonHistoryData(followEntityList);
+    }
+
+    /**
+     * 处理客户跟进顶部筛选条件数据
+     *
+     * @param followEntityList
+     * @return
+     */
+    public SysCustomerFollowHistorySelectBO handleCustomerFollowSelectCommonHistoryData(List<SysCustomerFollowEntity> followEntityList) {
+        SysCustomerFollowHistorySelectBO resultData = SysCustomerFollowHistorySelectBO.builder().build();
+        List<SelectBO> productData = Lists.newArrayList();
+        List<SelectBO> followData = Lists.newArrayList();
+        List<BindUserBO> memberData = Lists.newArrayList();
+        List<SelectBO> positionData = Lists.newArrayList();
         if (CollUtil.isNotEmpty(followEntityList)) {
             followEntityList.forEach(
                     entity -> {
@@ -329,20 +353,12 @@ public class SysCustomerDataFollowService {
                         }
                     }
             );
-//            SelectBO bo = SelectBO.builder()
-//                    .name("全部")
-//                    .build();
-//            productData.addFirst(bo);
-//            followData.addFirst(bo);
-//            positionData.addFirst(bo);
-//            BindUserBO memberBO = BindUserBO.builder()
-//                    .username("全部")
-//                    .build();
-//            memberData.addFirst(memberBO);
         }
         resultData.setProductData(productData);
         resultData.setFollowData(followData);
-        resultData.setMemberData(memberData);
+        if (UserContextHolder.getUserContext().getRoles().contains("Admin")) {
+            resultData.setMemberData(memberData);
+        }
         resultData.setOrderStatusData(Lists.newArrayList());
         resultData.setPositionData(positionData);
         resultData.setDateData(DateSelectUtil.getDateData());
@@ -373,7 +389,7 @@ public class SysCustomerDataFollowService {
 
         SysCustomerDetailBO resultData = SysCustomerDetailBO.builder().build();
         resultData.setDataPageList(pageResult);
-        resultData.setSelectData(this.queryCustomerFollowSelectCommonData(dto.getCustomerId(), UserContextHolder.getUserId()));
+        resultData.setSelectData(this.queryCustomerFollowSelectCommonHistoryData(dto.getCustomerId(), UserContextHolder.getUserId()));
         return resultData;
     }
 
@@ -384,6 +400,11 @@ public class SysCustomerDataFollowService {
      * @param dto
      */
     public PageResult<SysCustomerFollowListBO> queryCustomerFollowDataCommonByPage(AdminSysCustomerFollowReqDTO dto) {
+        if (dto.getUserId() == null) {
+            if (!UserContextHolder.getUserContext().getRoles().contains("Admin")) {
+                dto.setUserId(UserContextHolder.getUserId());
+            }
+        }
         //查询跟进数据
         Page<SysCustomerFollowEntity> pageData =
                 sysCustomerFollowMapper.selectPage(
@@ -401,6 +422,7 @@ public class SysCustomerDataFollowService {
         return this.entityPage2BOPage(pageData);
     }
 
+
     /**
      * 查询预约待办数据
      *
@@ -409,6 +431,11 @@ public class SysCustomerDataFollowService {
     public List<SysCustomerFollowListBO> queryCustomerFollowOrderData(LocalDateTime startDateTime, LocalDateTime endDateTime,
                                                                       Long userId, Integer status, String queryStr,
                                                                       Integer orderType) {
+        if (userId == null) {
+            if (!UserContextHolder.getUserContext().getRoles().contains("Admin")) {
+                userId = UserContextHolder.getUserId();
+            }
+        }
         //查询跟进数据
         List<SysCustomerFollowEntity> listData =
                 sysCustomerFollowMapper.selectList(
@@ -418,7 +445,7 @@ public class SysCustomerDataFollowService {
                                 .ge(startDateTime != null, SysCustomerFollowEntity::getOrderDatetime, startDateTime)
                                 .le(endDateTime != null, SysCustomerFollowEntity::getOrderDatetime, endDateTime)
                                 .eq(SysCustomerFollowEntity::getOrderType, orderType)
-                                .eq(orderType == 0,SysCustomerFollowEntity::getFollowId,33) //只查询方案演示
+                                .eq(orderType == 0, SysCustomerFollowEntity::getFollowId, 33) //只查询方案演示
                                 .ne(orderType == 1, SysCustomerFollowEntity::getOrderStatus, 2)
                                 .and(StrUtil.isNotEmpty(queryStr), z ->
                                                 z.like(SysCustomerFollowEntity::getCustomerName, queryStr)
@@ -426,7 +453,7 @@ public class SysCustomerDataFollowService {
 //                                        .or().like(SysCustomerFollowEntity::getCustomerPersonName, queryStr)
 //                                        .or().like(SysCustomerFollowEntity::getPositionName, queryStr)
                                 )
-                                .orderByAsc(orderType == 0, SysCustomerFollowEntity::getOrderDatetime, SysCustomerFollowEntity::getCreatedAt)
+                                .orderByDesc(orderType == 0, SysCustomerFollowEntity::getOrderDatetime, SysCustomerFollowEntity::getCreatedAt)
                                 .orderByDesc(orderType == 1, SysCustomerFollowEntity::getCreatedAt)
                 );
         return this.entityList2BOs(listData);

+ 18 - 1
src/main/java/com/jtzx/crm/module/sys/service/SysCustomerDataFollowTodoService.java

@@ -8,7 +8,10 @@ import cn.hutool.core.date.DateTime;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.StrUtil;
 import com.google.common.collect.Lists;
+import com.jtzx.crm.module.sys.entity.SysUserEntity;
+import com.jtzx.crm.module.sys.mapper.SysUserMapper;
 import com.jtzx.crm.module.sys.model.request.AdminSysCustomerFollowTodoDTO;
+import com.jtzx.crm.module.sys.model.response.BindUserBO;
 import com.jtzx.crm.module.sys.model.response.SysCustomerFollowListBO;
 import com.jtzx.crm.module.sys.model.response.SysCustomerFollowTodoDataBO;
 import com.jtzx.crm.module.sys.model.response.SysCustomerFollowTodoDetailBO;
@@ -28,6 +31,7 @@ public class SysCustomerDataFollowTodoService {
 
     private final SysCustomerTodoService sysCustomerTodoService;
 
+    private final SysUserMapper sysUserMapper;
 
     /**
      * 预约登记列表数据查询
@@ -47,7 +51,20 @@ public class SysCustomerDataFollowTodoService {
         // 筛选条件数据
         resultData.setMemberData(Lists.newArrayList());
         if (UserContextHolder.getUserContext().getRoles().contains("Admin")) {
-            resultData.setMemberData(sysCustomerTodoService.queryMemberData(dateStr));
+
+            sysUserMapper.selectList(null).stream().sorted(Comparator.comparing(SysUserEntity::getCreatedAt)).forEach(e -> {
+                if (e.getId().equals(UserContextHolder.getUserContext().getUserId())) {
+                    resultData.getMemberData().addFirst(BindUserBO.builder()
+                            .id(e.getId())
+                            .username(e.getUserName())
+                            .build());
+                } else {
+                    resultData.getMemberData().add(BindUserBO.builder()
+                            .id(e.getId())
+                            .username(e.getUserName())
+                            .build());
+                }
+            });
         } else {
             dto.setUserId(UserContextHolder.getUserContext().getUserId());
         }

+ 96 - 103
src/main/java/com/jtzx/crm/module/sys/service/SysCustomerDataPrivateService.java

@@ -52,14 +52,14 @@ public class SysCustomerDataPrivateService {
 
     private final SysCustomerOperLogService sysCustomerOperLogService;
 
-    private final SysCustomerDataPermissionService permissionService;
+    private final SysUserGroupRelationMapper sysUserGroupRelationMapper;
 
     /**
      * 查询私域(我的)客户页面顶部筛选条件数据
      *
      * @return
      */
-    public SysCustomerPrivateSelectBO queryHeadSelectPrivateData() throws BusinessException{
+    public SysCustomerPrivateSelectBO queryHeadSelectPrivateData() throws BusinessException {
 //        permissionService.publicPrivateCustomerPermission();
         SysCustomerPrivateSelectBO resultData = SysCustomerPrivateSelectBO.builder().build();
         //类型
@@ -67,7 +67,7 @@ public class SysCustomerDataPrivateService {
         //学段信息
         resultData.setStageData(sysCustomerUserCommonService.handleStageData());
         //省市信息
-        SysCustomerSelectBO sysCustomerSelectBO = sysCustomerUserCommonService.querySelectDataByType1( true);
+        SysCustomerSelectBO sysCustomerSelectBO = sysCustomerUserCommonService.querySelectDataByType3(true);
         if (sysCustomerSelectBO != null) {
             resultData.setRegionData(sysCustomerSelectBO.getRegionData());
             resultData.setGroupData(sysCustomerSelectBO.getGroupData());
@@ -80,39 +80,61 @@ public class SysCustomerDataPrivateService {
     /**
      * 后台管理-我的客户(学校)分页列表
      */
-    public PageResult<SysCustomerDataPrivateBO> adminList(AdminSysCustomerDataPrivateListDTO dto) throws BusinessException{
-//        permissionService.publicPrivateCustomerPermission();
+    public PageResult<SysCustomerDataPrivateBO> adminList(AdminSysCustomerDataPrivateListDTO dto) throws BusinessException {
         List<Long> userIds = Lists.newArrayList();
+        List<Long> groupIds = Lists.newArrayList();
+        List<Long> provinceIds = Lists.newArrayList();
+        List<Long> cityIds = Lists.newArrayList();
+        if (!UserContextHolder.getUserContext().getRoles().contains("Admin")) {
+            userIds.add(UserContextHolder.getUserId());
+            //查询用户的小组信息
+            List<SysUserGroupRelationEntity> userGroupRelationList = sysUserGroupRelationMapper.selectList(
+                    new LambdaQueryWrapper<SysUserGroupRelationEntity>()
+                            .select(
+                                    SysUserGroupRelationEntity::getId,
+                                    SysUserGroupRelationEntity::getProvinceId,
+                                    SysUserGroupRelationEntity::getCityId,
+                                    SysUserGroupRelationEntity::getGroupId
+                            )
+                            .eq(SysUserGroupRelationEntity::getUserId, UserContextHolder.getUserId())
+            );
+            if (CollUtil.isEmpty(userGroupRelationList)) {
+                throw new BusinessException("用户小组信息不存在");
+            }
+            provinceIds.addAll(
+                    userGroupRelationList.stream()
+                            .map(SysUserGroupRelationEntity::getProvinceId)
+                            .filter(Objects::nonNull)
+                            .distinct().toList());
+            cityIds.addAll(
+                    userGroupRelationList.stream()
+                            .map(SysUserGroupRelationEntity::getCityId)
+                            .filter(Objects::nonNull)
+                            .distinct().toList());
+            groupIds.addAll(
+                    userGroupRelationList.stream()
+                            .map(SysUserGroupRelationEntity::getGroupId)
+                            .filter(Objects::nonNull)
+                            .distinct().toList());
+        }
         if (dto.getUserId() != null) {
+            userIds.clear();
             userIds.add(dto.getUserId());
-        }else {
-            if(!UserContextHolder.getUserContext().getRoles().contains("Admin")){
-                userIds.add(UserContextHolder.getUserId());
-            }
         }
-        List<Long> groupIds = Lists.newArrayList();
         if (dto.getGroupId() != null) {
+            groupIds.clear();
             groupIds.add(dto.getGroupId());
         }
-        List<Long> cityIds = Lists.newArrayList();
-        if (dto.getProvinceId() != null) {
-            cityIds.addAll(sysCustomerUserCommonService.queryUserCityIds(dto.getProvinceId()));
-            List<BindUserBO> bindUserBOS = sysCustomerUserCommonService.queryBindUserListByCityId(cityIds);
-            if (CollUtil.isNotEmpty(bindUserBOS)) {
-                if (CollUtil.isEmpty(userIds)) {
-                    userIds.addAll(
-                            bindUserBOS.stream()
-                                    .map(BindUserBO::getId).toList());
-                }
 
-                if (CollUtil.isEmpty(groupIds)) {
-                    groupIds.addAll(
-                            bindUserBOS.stream()
-                                    .map(BindUserBO::getGroupId).distinct().toList());
-                }
-            }
+        if (dto.getProvinceId() != null) {
+            provinceIds.clear();
+            provinceIds.add(dto.getProvinceId());
         }
 
+        if (dto.getCityId() != null) {
+            cityIds.clear();
+            cityIds.add(dto.getCityId());
+        }
         Page<SysCustomerDataEntity> entityPage = sysCustomerDataMapper.selectPage(
                 new Page<>(dto.getPageNum(), dto.getPageSize()),
                 new QueryWrapper<SysCustomerDataEntity>()
@@ -122,19 +144,20 @@ public class SysCustomerDataPrivateService {
                         //存量客户判断
                         .in(dto.getTypeId() != null && dto.getTypeId().equals(2) && CollUtil.isNotEmpty(userIds), SysCustomerDataEntity::getSuccessUserId, userIds)
                         //查询存量客户判断
-                        .eq(dto.getTypeId() != null && dto.getTypeId().equals(2) , SysCustomerDataEntity::getSuccessStatus, 1)
+                        .eq(dto.getTypeId() != null && dto.getTypeId().equals(2), SysCustomerDataEntity::getSuccessStatus, 1)
                         //首单客户判断
-                        .in(dto.getTypeId() != null && dto.getTypeId().equals(1)&& CollUtil.isNotEmpty(userIds), SysCustomerDataEntity::getClaimUserId, userIds)
-                        .in(dto.getTypeId()==null && CollUtil.isNotEmpty(userIds), SysCustomerDataEntity::getClaimUserId, userIds)
+                        .in(dto.getTypeId() != null && dto.getTypeId().equals(1) && CollUtil.isNotEmpty(userIds), SysCustomerDataEntity::getClaimUserId, userIds)
+                        .eq(dto.getTypeId() != null && dto.getTypeId().equals(1), SysCustomerDataEntity::getSuccessStatus, 0)
+                        .in(dto.getTypeId() == null && CollUtil.isNotEmpty(userIds), SysCustomerDataEntity::getClaimUserId, userIds)
                         // 学段id(param_base_data表主id)
                         .eq(Objects.nonNull(dto.getStageId()), SysCustomerDataEntity::getStageId, dto.getStageId())
                         // 省份id(省份表主id)
-                        .eq(Objects.nonNull(dto.getProvinceId()), SysCustomerDataEntity::getProvinceId, dto.getProvinceId())
+                        .in(CollUtil.isNotEmpty(provinceIds), SysCustomerDataEntity::getProvinceId, provinceIds)
                         // 城市id(不为空时)
-                        .eq(Objects.nonNull(dto.getCityId()), SysCustomerDataEntity::getCityId, dto.getCityId())
+                        .in(CollUtil.isNotEmpty(cityIds), SysCustomerDataEntity::getCityId, cityIds)
                         // 城市id(为空时)
-                        .in(Objects.isNull(dto.getCityId())&&CollUtil.isNotEmpty(cityIds), SysCustomerDataEntity::getCityId, cityIds)
-                        .in(CollUtil.isNotEmpty(groupIds),SysCustomerDataEntity::getClaimUserGroupId, groupIds)
+                        .in(Objects.isNull(dto.getCityId()) && CollUtil.isNotEmpty(cityIds), SysCustomerDataEntity::getCityId, cityIds)
+                        .in(CollUtil.isNotEmpty(groupIds), SysCustomerDataEntity::getClaimUserGroupId, groupIds)
                         //必须是已认领的,不认领的是不能出现在我的客户里面的,所有必须加这个过滤,不管是存量还是首单客户都要加这个参数
                         .eq(SysCustomerDataEntity::getClaimStatus, 1)
 
@@ -151,7 +174,7 @@ public class SysCustomerDataPrivateService {
      * @param dto
      */
     @Transactional(rollbackFor = Exception.class)
-    public void adminUpdateCustomerData(AdminSysCustomerDataInsertOrUpdateDTO dto) throws BusinessException{
+    public void adminUpdateCustomerData(AdminSysCustomerDataInsertOrUpdateDTO dto) throws BusinessException {
 //        permissionService.publicPrivateCustomerPermission();
         sysCustomerDataService.adminUpdate(dto);
     }
@@ -163,7 +186,7 @@ public class SysCustomerDataPrivateService {
      * @param customerId
      */
     @Transactional(rollbackFor = Exception.class)
-    public void returnCustomerPublicData(Long customerId) throws BusinessException{
+    public void returnCustomerPublicData(Long customerId) throws BusinessException {
         sysCustomerDataService.returnCustomerData(customerId);
     }
 
@@ -175,7 +198,7 @@ public class SysCustomerDataPrivateService {
      * @return
      */
     @Transactional(rollbackFor = Exception.class)
-    public void adminInsertCustomerPerson(AdminSysCustomerPersonInsertOrUpdateDTO dto) throws BusinessException{
+    public void adminInsertCustomerPerson(AdminSysCustomerPersonInsertOrUpdateDTO dto) throws BusinessException {
 //        permissionService.publicPrivateCustomerPermission();
         sysCustomerPersonService.adminInsert(dto);
     }
@@ -187,7 +210,7 @@ public class SysCustomerDataPrivateService {
      * @param dto
      */
     @Transactional(rollbackFor = Exception.class)
-    public void adminUpdateCustomerPerson(AdminSysCustomerPersonInsertOrUpdateDTO dto) throws BusinessException{
+    public void adminUpdateCustomerPerson(AdminSysCustomerPersonInsertOrUpdateDTO dto) throws BusinessException {
 //        permissionService.publicPrivateCustomerPermission();
         sysCustomerPersonService.adminUpdate(dto);
     }
@@ -198,7 +221,7 @@ public class SysCustomerDataPrivateService {
      * @param id
      */
     @Transactional(rollbackFor = Exception.class)
-    public void adminDeleteCustomerPerson(Long id) throws BusinessException{
+    public void adminDeleteCustomerPerson(Long id) throws BusinessException {
 //        permissionService.publicPrivateCustomerPermission();
         sysCustomerPersonService.adminDelete(id);
     }
@@ -207,7 +230,7 @@ public class SysCustomerDataPrivateService {
     /**
      * 查询我的客户联系人
      */
-    public List<SysCustomerPersonBO> adminListCustomerPerson(CustomerPersonReqDTO dto) throws BusinessException{
+    public List<SysCustomerPersonBO> adminListCustomerPerson(CustomerPersonReqDTO dto) throws BusinessException {
 //        permissionService.publicPrivateCustomerPermission();
 
         return sysCustomerPersonService.adminList(dto);
@@ -220,7 +243,7 @@ public class SysCustomerDataPrivateService {
      * @param customerId
      * @return
      */
-    public List<TransferUserReqBO> queryTransferUser(Long customerId) throws BusinessException{
+    public List<TransferUserReqBO> queryTransferUser(Long customerId) throws BusinessException {
 
 //        permissionService.publicPrivateCustomerPermission();
         return sysCustomerDataService.queryTransferUser(customerId);
@@ -231,7 +254,7 @@ public class SysCustomerDataPrivateService {
      *
      * @param dto
      */
-    public void transferUser(TransferUserReqDTO dto) throws BusinessException{
+    public void transferUser(TransferUserReqDTO dto) throws BusinessException {
 //        permissionService.publicPrivateCustomerPermission();
         sysCustomerDataService.transferUser(dto);
     }
@@ -242,25 +265,19 @@ public class SysCustomerDataPrivateService {
      *
      * @param dto
      */
-    public SysCustomerDetailBO queryCustomerDetail(AdminSysCustomerFollowReqDTO dto) throws BusinessException{
-//        permissionService.publicPrivateCustomerPermission();
-
+    public SysCustomerDetailBO queryCustomerDetail(AdminSysCustomerFollowReqDTO dto) throws BusinessException {
         SysCustomerDetailBO detailBO = SysCustomerDetailBO.builder().build();
-        dto.setUserId(UserContextHolder.getUserId());
-        if(UserContextHolder.getUserContext().getRoles().contains("Admin")){
-            SysCustomerDataEntity entity =
-                    sysCustomerDataMapper.selectOne(
-                            new LambdaQueryWrapper<>(SysCustomerDataEntity.class)
-                                    .select(
-                                            SysCustomerDataEntity::getId,
-                                            SysCustomerDataEntity::getClaimUserId
-                                    )
-                                    .eq(SysCustomerDataEntity::getId,dto.getCustomerId())
-                    );
-            if(entity == null){
-                throw new BusinessException(400, "参数错误,客户不存在");
-            }
-            dto.setUserId(entity.getClaimUserId());
+        SysCustomerDataEntity entity =
+                sysCustomerDataMapper.selectOne(
+                        new LambdaQueryWrapper<>(SysCustomerDataEntity.class)
+                                .select(
+                                        SysCustomerDataEntity::getId,
+                                        SysCustomerDataEntity::getClaimUserId
+                                )
+                                .eq(SysCustomerDataEntity::getId, dto.getCustomerId())
+                );
+        if (entity == null) {
+            throw new BusinessException(400, "参数错误,客户不存在");
         }
         //顶部筛选条件数据
         SysCustomerFollowHistorySelectBO publicCustomerSelectData = sysCustomerDataFollowService.queryCustomerFollowSelectCommonData(dto.getCustomerId(), dto.getUserId());
@@ -270,11 +287,11 @@ public class SysCustomerDataPrivateService {
         detailBO.setDataPageList(dataPageList);
         detailBO.setProductCount(0);
         //跟进状态查询
-        List<CustomerStatusOverViewBO> statusOverViewData = sysCustomerFollowService.queryStatusOverViewData(dto.getCustomerId(),dto.getUserId());
+        List<CustomerStatusOverViewBO> statusOverViewData = sysCustomerFollowService.queryStatusOverViewData(dto.getCustomerId(), dto.getUserId());
         detailBO.setStatusOverviewData(statusOverViewData);
 
         //跟进产品信息总览
-        List<CustomerProductOverViewBO> overViewBOS = sysCustomerFollowService.queryProductOverViewData(dto.getCustomerId(),dto.getUserId());
+        List<CustomerProductOverViewBO> overViewBOS = sysCustomerFollowService.queryProductOverViewData(dto.getCustomerId(), dto.getUserId());
         if (CollUtil.isNotEmpty(overViewBOS)) {
             int productCount = overViewBOS.stream().map(CustomerProductOverViewBO::getCount).reduce(0, Integer::sum);
             detailBO.setProductCount(productCount);
@@ -297,40 +314,14 @@ public class SysCustomerDataPrivateService {
      * 操作日志列表查询
      */
     public SysCustomerOperLogDataBO queryOperLogData(AdminSysCustomerOperLogListDTO dto) {
-//        permissionService.publicPrivateCustomerPermission();
         List<Long> userIds = Lists.newArrayList();
-        if (dto.getOperUserId() != null) {
-            userIds.add(dto.getOperUserId());
-        }else {
-            if(!UserContextHolder.getUserContext().getRoles().contains("Admin")){
-                userIds.add(UserContextHolder.getUserId());
-            }
+        if (!UserContextHolder.getUserContext().getRoles().contains("Admin")) {
+            userIds.add(UserContextHolder.getUserId());
         }
         List<Long> groupIds = Lists.newArrayList();
         if (dto.getGroupId() != null) {
             groupIds.add(dto.getGroupId());
         }
-//        SysCustomerSelectBO selectBO = sysCustomerUserCommonService.querySelectDataByType1( true);
-//        if (selectBO != null && CollUtil.isNotEmpty(selectBO.getRegionData())) {
-//            List<Long> cityIds = Lists.newArrayList();
-//            selectBO.getRegionData()
-//                    .forEach(provinceRegion ->
-//                            provinceRegion.getSubData()
-//                                    .forEach(city -> cityIds.add(city.getId())));
-//            List<BindUserBO> bindUserBOS = sysCustomerUserCommonService.queryBindUserListByCityId(cityIds);
-//            if (CollUtil.isNotEmpty(bindUserBOS)) {
-//                if (CollUtil.isEmpty(userIds)) {
-//                    userIds.addAll(
-//                            bindUserBOS.stream()
-//                                    .map(BindUserBO::getId).toList());
-//                }
-//                if (CollUtil.isEmpty(groupIds)) {
-//                    groupIds.addAll(
-//                            bindUserBOS.stream()
-//                                    .map(BindUserBO::getGroupId).distinct().toList());
-//                }
-//            }
-//        }
         return sysCustomerOperLogService.adminList(dto, userIds, groupIds, true, false);
     }
 
@@ -366,7 +357,7 @@ public class SysCustomerDataPrivateService {
                         .map(SysCustomerDataEntity::getClaimUserGroupId)
                         .filter(Objects::nonNull).distinct().toList();
         List<SysGroupEntity> groupEntityList = Lists.newArrayList();
-        if(CollUtil.isNotEmpty(groupIds)){
+        if (CollUtil.isNotEmpty(groupIds)) {
             groupEntityList.addAll(sysGroupMapper.selectByIds(groupIds));
         }
         //查询学段
@@ -387,11 +378,9 @@ public class SysCustomerDataPrivateService {
                                         SysCustomerFollowEntity::getClaimDatetime
                                 )
                                 .in(SysCustomerFollowEntity::getCustomerId, entityList.stream().map(SysCustomerDataEntity::getId).toList())
-                                .in(CollUtil.isNotEmpty(groupIds),SysCustomerFollowEntity::getClaimUserGroupId, groupIds)
-                                .eq(SysCustomerFollowEntity::getClaimUserId, UserContextHolder.getUserId())
+//                                .in(!UserContextHolder.getUserContext().getRoles().contains("Admin") && CollUtil.isNotEmpty(groupIds), SysCustomerFollowEntity::getClaimUserGroupId, groupIds)
+                                .eq(!UserContextHolder.getUserContext().getRoles().contains("Admin"), SysCustomerFollowEntity::getClaimUserId, UserContextHolder.getUserId())
                 );
-
-
         // 深拷贝
         List<SysCustomerDataPrivateBO> ret = new ArrayList<>(entityList.size());
         entityList.forEach(
@@ -410,15 +399,19 @@ public class SysCustomerDataPrivateService {
                                 .ifPresent(e -> bo.setStageName(e.getTitle()));
                     }
                     if (CollUtil.isNotEmpty(followEntityList)) {
-                        List<SysCustomerFollowEntity> userFollowEntityList =
-                                followEntityList.stream()
-                                        .filter(x -> x.getCustomerId().equals(entity.getId()))
-                                        .filter(x -> x.getClaimUserGroupId()!=null && x.getClaimUserGroupId().equals(entity.getClaimUserGroupId()))
-                                        .filter(x -> x.getClaimUserId().equals(entity.getClaimUserId()))
-                                        .sorted(Comparator.comparing(SysCustomerFollowEntity::getClaimDatetime).reversed())
-                                        .toList();
-                        if (CollUtil.isNotEmpty(userFollowEntityList)) {
-                            bo.setLastFollowDatetime(userFollowEntityList.getFirst().getClaimDatetime());
+                        SysCustomerFollowEntity customerFollow = followEntityList.stream()
+                                .filter(x -> x.getCustomerId().equals(entity.getId()))
+                                .max(Comparator.comparing(SysCustomerFollowEntity::getClaimDatetime))
+                                .orElse(null);
+                        if(!UserContextHolder.getUserContext().getRoles().contains("Admin")){
+                            customerFollow = followEntityList.stream()
+                                    .filter(x -> x.getCustomerId().equals(entity.getId()))
+                                    .filter(x -> x.getClaimUserId().equals(UserContextHolder.getUserId()))
+                                    .max(Comparator.comparing(SysCustomerFollowEntity::getClaimDatetime))
+                                    .orElse(null);
+                        }
+                        if (customerFollow!=null) {
+                            bo.setLastFollowDatetime(customerFollow.getClaimDatetime());
                         }
                     }
                     ret.add(bo);

+ 68 - 23
src/main/java/com/jtzx/crm/module/sys/service/SysCustomerDataPublicService.java

@@ -10,14 +10,17 @@ import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.text.CharSequenceUtil;
 import cn.hutool.core.util.PhoneUtil;
 import cn.hutool.core.util.StrUtil;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.google.common.collect.Lists;
 import com.jtzx.crm.module.sys.entity.SysCustomerDataEntity;
 import com.jtzx.crm.module.sys.entity.SysParamBaseDataEntity;
 import com.jtzx.crm.module.sys.entity.SysUserEntity;
+import com.jtzx.crm.module.sys.entity.SysUserGroupRelationEntity;
 import com.jtzx.crm.module.sys.mapper.SysCustomerDataMapper;
 import com.jtzx.crm.module.sys.mapper.SysParamBaseDataMapper;
+import com.jtzx.crm.module.sys.mapper.SysUserGroupRelationMapper;
 import com.jtzx.crm.module.sys.mapper.SysUserMapper;
 import com.jtzx.crm.module.sys.model.request.*;
 import com.jtzx.crm.module.sys.model.response.*;
@@ -44,6 +47,8 @@ public class SysCustomerDataPublicService {
 
     private final SysParamBaseDataMapper sysParamBaseDataMapper;
 
+    private final SysUserGroupRelationMapper sysUserGroupRelationMapper;
+
     private final SysCustomerUserCommonService sysCustomerUserCommonService;
 
     private final SysCustomerDataService sysCustomerDataService;
@@ -83,8 +88,46 @@ public class SysCustomerDataPublicService {
     /**
      * 后台管理-公海客户(学校)分页列表
      */
-    public PageResult<SysCustomerDataPublicBO> adminList(AdminSysCustomerDataPublicListDTO dto) {
-//        permissionService.publicPrivateCustomerPermission();
+    public PageResult<SysCustomerDataPublicBO> adminList(AdminSysCustomerDataPublicListDTO dto) throws BusinessException {
+
+        List<Long> provinceIds = Lists.newArrayList();
+        List<Long> cityIds = Lists.newArrayList();
+        if(!UserContextHolder.getUserContext().getRoles().contains("Admin")){
+            //查询用户的小组信息
+            List<SysUserGroupRelationEntity> userGroupRelationList = sysUserGroupRelationMapper.selectList(
+                    new LambdaQueryWrapper<SysUserGroupRelationEntity>()
+                            .select(
+                                    SysUserGroupRelationEntity::getId,
+                                    SysUserGroupRelationEntity::getProvinceId,
+                                    SysUserGroupRelationEntity::getCityId
+                            )
+                            .eq(SysUserGroupRelationEntity::getUserId, UserContextHolder.getUserId())
+            );
+            if(CollUtil.isEmpty(userGroupRelationList)){
+                throw new BusinessException("用户小组信息不存在");
+            }
+            provinceIds.addAll(
+            userGroupRelationList.stream()
+                    .map(SysUserGroupRelationEntity::getProvinceId)
+                    .filter(Objects::nonNull)
+                    .distinct().toList());
+            cityIds.addAll(
+                    userGroupRelationList.stream()
+                            .map(SysUserGroupRelationEntity::getCityId)
+                            .filter(Objects::nonNull)
+                            .distinct().toList());
+        }
+
+
+        if(dto.getProvinceId() != null){
+            provinceIds.clear();
+            provinceIds.add(dto.getProvinceId());
+        }
+        if(dto.getCityId() != null){
+            cityIds.clear();
+            cityIds.add(dto.getCityId());
+        }
+
         Page<SysCustomerDataEntity> entityPage = sysCustomerDataMapper.selectPage(
                 new Page<>(dto.getPageNum(), dto.getPageSize()),
                 new QueryWrapper<SysCustomerDataEntity>()
@@ -94,11 +137,9 @@ public class SysCustomerDataPublicService {
                         // 学段id(param_base_data表主id)
                         .eq(Objects.nonNull(dto.getStageId()), SysCustomerDataEntity::getStageId, dto.getStageId())
                         // 省份id(省份表主id)
-                        .eq(Objects.nonNull(dto.getProvinceId()), SysCustomerDataEntity::getProvinceId, dto.getProvinceId())
+                        .in(CollUtil.isNotEmpty(provinceIds), SysCustomerDataEntity::getProvinceId, provinceIds)
                         // 城市id(不为空时)
-                        .eq(Objects.nonNull(dto.getCityId()), SysCustomerDataEntity::getCityId, dto.getCityId())
-                        // 城市id(为空时)
-                        .in(Objects.isNull(dto.getCityId()) && dto.getProvinceId() != null, SysCustomerDataEntity::getCityId, sysCustomerUserCommonService.queryUserCityIds(dto.getProvinceId()))
+                        .in(CollUtil.isNotEmpty(cityIds), SysCustomerDataEntity::getCityId, cityIds)
                         //认领状态
                         .eq(SysCustomerDataEntity::getClaimStatus, 0)
                         // 排序
@@ -234,25 +275,26 @@ public class SysCustomerDataPublicService {
         if (sysUserEntity == null) {
             throw new BusinessException("用户不存在");
         }
-        dto.setUserId(null);
-
-        detailBO.setHistoryFollowStatus(sysUserEntity.getHistoryFollowStatus() == null ? 0 : sysUserEntity.getHistoryFollowStatus());
+        detailBO.setHistoryFollowStatus(sysUserEntity.getPublicFollowStatus() == null ? 0 : sysUserEntity.getPublicFollowStatus());
         if (UserContextHolder.getUserContext().getRoles().contains("Admin")) {
             detailBO.setHistoryFollowStatus(1);
         }
+
+        //顶部筛选条件数据
+        SysCustomerFollowHistorySelectBO publicCustomerSelectData = sysCustomerDataFollowService.queryCustomerFollowSelectCommonData(dto.getCustomerId(), dto.getUserId());
+        detailBO.setSelectData(publicCustomerSelectData);
+        //客户详情信息
+        PageResult<SysCustomerFollowListBO> dataPageList = sysCustomerDataFollowService.queryCustomerFollowDataCommonByPage(dto);
+        detailBO.setDataPageList(dataPageList);
+
         //历史跟进总览开关
         if (UserContextHolder.getUserContext().getRoles().contains("Admin") ||
-                sysUserEntity.getHistoryFollowStatus() != null && sysUserEntity.getHistoryFollowStatus() == 1) {
-            //顶部筛选条件数据
-            SysCustomerFollowHistorySelectBO publicCustomerSelectData = sysCustomerDataFollowService.queryCustomerFollowSelectCommonData(dto.getCustomerId(), null);
-            detailBO.setSelectData(publicCustomerSelectData);
-            //客户详情信息
-            PageResult<SysCustomerFollowListBO> dataPageList = sysCustomerDataFollowService.queryCustomerFollowDataCommonByPage(dto);
-            detailBO.setDataPageList(dataPageList);
+                sysUserEntity.getPublicFollowStatus() != null && sysUserEntity.getPublicFollowStatus() == 1) {
+
             //信息总览
-            detailBO.setProductOverviewData(sysCustomerFollowService.queryProductOverViewData(dto.getCustomerId(), null));
+//            detailBO.setProductOverviewData(sysCustomerFollowService.queryProductOverViewData(dto.getCustomerId(), null));
             //跟进记录总览
-            detailBO.setFollowOverViewData(sysCustomerFollowService.handleCustomerFollowOverViewData(dto.getCustomerId(), null));
+            detailBO.setFollowOverViewData(sysCustomerFollowService.handleCustomerFollowOverViewData(dto.getCustomerId(), dto.getUserId()));
         }
         return detailBO;
     }
@@ -344,16 +386,19 @@ public class SysCustomerDataPublicService {
         SysCustomerDataPublicBO bo = new SysCustomerDataPublicBO();
         BeanUtil.copyProperties(entity, bo);
         // 可以在此处为BO填充字段
-        bo.setUnUsedDayCount("1天");
+        bo.setUnUsedDayCount("0天");
         long days = DateUtil.betweenDay(DateUtil.date(),
                 DateUtil.parse(entity.getResetDatetime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))),
                 false);
-        //向上取整
-        double ceilDays = Math.ceil(days);
-        if ((int) ceilDays >= 1) {
+        if(days>0){
+            //向上取整
+//            double ceilDays = Math.ceil(days);
             bo.setUnUsedDayCount(days + "天");
+//            if ((int) ceilDays >= 1) {
+//                bo.setUnUsedDayCount(days + "天");
+//            }
+            bo.setDelStatus(true);
         }
-        bo.setDelStatus(true);
         return bo;
     }
 }

+ 14 - 16
src/main/java/com/jtzx/crm/module/sys/service/SysCustomerDataService.java

@@ -236,13 +236,6 @@ public class SysCustomerDataService {
     @Transactional(rollbackFor = Exception.class)
     public void claimCustomer(Long customerId) throws BusinessException {
 
-//        SysParamEntity sysParamEntity =
-//                sysParamMapper.selectOne(
-//                        new LambdaQueryWrapper<>(SysParamEntity.class)
-//                );
-//        if (sysParamEntity == null) {
-//            throw new BusinessException(400, "参数配置未设置");
-//        }
         SysUserEntity sysUserEntity = sysUserMapper.selectById(UserContextHolder.getUserId());
         if (sysUserEntity == null) {
             throw new BusinessException(400, "用户不存在");
@@ -258,7 +251,7 @@ public class SysCustomerDataService {
                                         )
                                         .eq(SysCustomerDataEntity::getClaimUserId, UserContextHolder.getUserId())
                         );
-                if (customerCount > 0 && customerCount > sysUserEntity.getHoldTopCount()) {
+                if (customerCount > 0 && customerCount >= sysUserEntity.getHoldTopCount()) {
                     throw new BusinessException(400, "认领数量已超过设定的持有数量上限,不能再进行认领操作");
                 }
             }
@@ -349,15 +342,20 @@ public class SysCustomerDataService {
                 throw new BusinessException(400, "认领人不正确,无权操作");
             }
         }
+
+        //判断是否有预约或待办
+        long orderTypeCount = sysCustomerFollowMapper.selectCount(
+                new LambdaQueryWrapper<>(SysCustomerFollowEntity.class)
+                        .select(SysCustomerFollowEntity::getCustomerId)
+                        .eq(SysCustomerFollowEntity::getCustomerId, customerId)
+                        .in(SysCustomerFollowEntity::getOrderType, Lists.newArrayList(0, 1))
+        );
+        if (orderTypeCount > 0) {
+            throw new BusinessException(400, "客户有预约或待办,不能退回公海");
+        }
+
         // 每日手动退回公海上限判断
         if (!UserContextHolder.getUserContext().getRoles().contains("Admin")) {
-//            SysParamEntity sysParamEntity =
-//                    sysParamMapper.selectOne(
-//                            new LambdaQueryWrapper<>(SysParamEntity.class)
-//                    );
-//            if (sysParamEntity == null) {
-//                throw new BusinessException(400, "参数配置未设置");
-//            }
             SysUserEntity sysUserEntity = sysUserMapper.selectById(UserContextHolder.getUserId());
             if (sysUserEntity == null) {
                 throw new BusinessException(400, "用户不存在");
@@ -434,7 +432,7 @@ public class SysCustomerDataService {
         if (groupRelationEntity == null) {
             throw new BusinessException(400, "用户未分配小组");
         }
-        sysCustomerDataEntity.setClaimDatetime(LocalDateTime.now());
+//        sysCustomerDataEntity.setClaimDatetime(LocalDateTime.now());
         sysCustomerDataEntity.setClaimUserGroupId(groupRelationEntity.getGroupId());
         sysCustomerDataEntity.setClaimUserName(sysUserEntity.getUserName());
         sysCustomerDataEntity.setClaimUserId(sysUserEntity.getId());

+ 1 - 1
src/main/java/com/jtzx/crm/module/sys/service/SysCustomerFollowAuditService.java

@@ -50,7 +50,7 @@ public class SysCustomerFollowAuditService {
         List<SysCustomerFollowAuditEntity> entityPage = sysCustomerFollowAuditMapper.selectList(
                 new QueryWrapper<SysCustomerFollowAuditEntity>()
                         .lambda()
-                        .eq(SysCustomerFollowAuditEntity::getAuditUserId, UserContextHolder.getUserId())
+//                        .eq(SysCustomerFollowAuditEntity::getAuditUserId, UserContextHolder.getUserId())
                         // 排序
                         .orderByDesc(SysCustomerFollowAuditEntity::getCreatedAt)
         );

+ 49 - 20
src/main/java/com/jtzx/crm/module/sys/service/SysCustomerFollowService.java

@@ -113,13 +113,13 @@ public class SysCustomerFollowService {
 //        }
         SysCustomerFollowEntity sysCustomerFollowEntity = sysCustomerFollowMapper.selectById(dto.getId());
         if (sysCustomerFollowEntity == null) {
-            throw new RuntimeException("预约数据不存在");
+            throw new BusinessException("预约数据不存在");
         }
         if (sysCustomerFollowEntity.getOrderStatus() != 0) {
-            throw new RuntimeException("预约不能取消");
+            throw new BusinessException("预约不能取消");
         }
         if (!sysCustomerFollowEntity.getClaimUserId().equals(UserContextHolder.getUserId())) {
-            throw new RuntimeException("非本人预约不能取消");
+            throw new BusinessException("非本人预约不能取消");
         }
         sysCustomerFollowEntity.setOrderStatus(2);
         sysCustomerFollowEntity.setCancelRemark(dto.getCancelRemark());
@@ -133,6 +133,13 @@ public class SysCustomerFollowService {
      * @return
      */
     public CustomerFollowOverViewBO handleCustomerFollowOverViewData(Long customerId, Long userId) {
+
+        if (userId == null) {
+            if(!UserContextHolder.getUserContext().getRoles().contains("Admin")){
+                userId = UserContextHolder.getUserId();
+            }
+        }
+
         CustomerFollowOverViewBO customerFollowOverViewBO = CustomerFollowOverViewBO.builder().build();
         customerFollowOverViewBO.setHistoryProductCount(0);
         customerFollowOverViewBO.setHistoryPersonCount(0);
@@ -190,6 +197,13 @@ public class SysCustomerFollowService {
      */
     public List<CustomerProductOverViewBO> queryProductOverViewData(Long customerId, Long userId) {
 
+        if (userId == null) {
+            if(!UserContextHolder.getUserContext().getRoles().contains("Admin")){
+                userId = UserContextHolder.getUserId();
+            }
+        }
+
+
         List<CustomerProductOverViewBO> productOverViewBOList = new ArrayList<>();
         List<SysCustomerFollowEntity> followEntityList =
                 sysCustomerFollowMapper.selectList(
@@ -241,6 +255,11 @@ public class SysCustomerFollowService {
      */
     public List<CustomerStatusOverViewBO> queryStatusOverViewData(Long customerId, Long userId) {
 
+        if (userId == null) {
+            if(!UserContextHolder.getUserContext().getRoles().contains("Admin")){
+                userId = UserContextHolder.getUserId();
+            }
+        }
         List<CustomerStatusOverViewBO> productOverViewBOList = new ArrayList<>();
         List<SysCustomerFollowEntity> followEntityList =
                 sysCustomerFollowMapper.selectList(
@@ -290,6 +309,11 @@ public class SysCustomerFollowService {
      * @return
      */
     public List<CustomerProductBO> queryCustomerProductData(Long customerId, Long userId) {
+        if (userId == null) {
+            if(!UserContextHolder.getUserContext().getRoles().contains("Admin")){
+                userId = UserContextHolder.getUserId();
+            }
+        }
         List<CustomerProductBO> productBOList = new ArrayList<>();
         List<SysCustomerFollowEntity> followEntityList =
                 sysCustomerFollowMapper.selectList(
@@ -349,6 +373,11 @@ public class SysCustomerFollowService {
      * @return
      */
     public List<SysCustomerFollowDataBO> handleOrderData(Long customerId, Long userId) {
+        if (userId == null) {
+            if(!UserContextHolder.getUserContext().getRoles().contains("Admin")){
+                userId = UserContextHolder.getUserId();
+            }
+        }
         List<SysCustomerFollowDataBO> orderList = Lists.newArrayList();
         List<SysCustomerFollowEntity> followEntityList =
                 sysCustomerFollowMapper.selectList(
@@ -388,7 +417,7 @@ public class SysCustomerFollowService {
                         .last("limit 1")
         );
         if (sysCustomerPersonEntity == null) {
-            throw new RuntimeException("参数错误,联系人不存在");
+            throw new BusinessException("参数错误,联系人不存在");
         }
         dto.setCustomerPersonName(sysCustomerPersonEntity.getName());
         //处理产品
@@ -401,7 +430,7 @@ public class SysCustomerFollowService {
                         .last("limit 1")
         );
         if (productDataEntity == null) {
-            throw new RuntimeException("参数错误,产品不存在");
+            throw new BusinessException("参数错误,产品不存在");
         }
         dto.setProductName(productDataEntity.getTitle());
         //处理跟进状态
@@ -414,7 +443,7 @@ public class SysCustomerFollowService {
                         .last("limit 1")
         );
         if (followDataEntity == null) {
-            throw new RuntimeException("参数错误,跟进状态不存在");
+            throw new BusinessException("参数错误,跟进状态不存在");
         }
         dto.setFollowName(followDataEntity.getTitle());
         //处理职务
@@ -427,7 +456,7 @@ public class SysCustomerFollowService {
                         .last("limit 1")
         );
         if (positionDataEntity == null) {
-            throw new RuntimeException("参数错误,职务不存在");
+            throw new BusinessException("参数错误,职务不存在");
         }
         dto.setPositionName(positionDataEntity.getTitle());
         //处理客户
@@ -449,7 +478,7 @@ public class SysCustomerFollowService {
                         .last("limit 1")
         );
         if (sysCustomerDataEntity == null) {
-            throw new RuntimeException("参数错误,客户不存在");
+            throw new BusinessException("参数错误,客户不存在");
         }
 //        dto.setClaimUserId(sysCustomerDataEntity.getClaimUserId());
 //        dto.setClaimUserName(sysCustomerDataEntity.getClaimUserName());
@@ -491,7 +520,7 @@ public class SysCustomerFollowService {
                                 .eq(SysUserRoleRelationEntity::getRoleValue, "Admin")
                 );
         if (CollUtil.isEmpty(adminUserList)) {
-            throw new RuntimeException("参数错误,管理员不存在");
+            throw new BusinessException("参数错误,管理员不存在");
         }
         List<Long> userIds =
                 adminUserList.stream()
@@ -503,7 +532,7 @@ public class SysCustomerFollowService {
                         .in(SysUserEntity::getId, userIds)
         );
         if (CollUtil.isEmpty(sysUserEntities)) {
-            throw new RuntimeException("参数错误,管理员不存在");
+            throw new BusinessException("参数错误,管理员不存在");
         }
         adminUserList.forEach(adminUser -> {
             SysCustomerFollowAuditEntity entity = this.getFollowAuditEntity(dto);
@@ -552,35 +581,35 @@ public class SysCustomerFollowService {
     public void checkParam(AdminSysCustomerFollowInsertOrUpdateDTO dto) throws BusinessException {
 
         if (dto.getCustomerId() == null) {
-            throw new RuntimeException("参数错误,客户不能为空");
+            throw new BusinessException("参数错误,客户不能为空");
         }
         if (dto.getProductId() == null) {
-            throw new RuntimeException("参数错误,产品不能为空");
+            throw new BusinessException("参数错误,产品不能为空");
         }
         if (dto.getFollowId() == null) {
-            throw new RuntimeException("参数错误,跟进状态不能为空");
+            throw new BusinessException("参数错误,跟进状态不能为空");
         }
         if (dto.getCustomerPersonId() == null) {
-            throw new RuntimeException("参数错误,联系人不能为空");
+            throw new BusinessException("参数错误,联系人不能为空");
         }
         if (dto.getPositionId() == null) {
-            throw new RuntimeException("参数错误,职务不能为空");
+            throw new BusinessException("参数错误,职务不能为空");
         }
         if (StrUtil.isEmpty(dto.getFollowContent())) {
-            throw new RuntimeException("参数错误,跟进内容不能为空");
+            throw new BusinessException("参数错误,跟进内容不能为空");
         }
 
         if (dto.getOrderType() != null && dto.getOrderDatetime() == null) {
-            throw new RuntimeException("参数错误,预约待办时间不能为空");
+            throw new BusinessException("参数错误,预约待办时间不能为空");
         }
 
         if (dto.getOrderDatetime() != null && dto.getOrderDatetime().isBefore(LocalDateTime.now())) {
-            throw new RuntimeException("参数错误,预约待办时间不能在当前时间之前");
+            throw new BusinessException("参数错误,预约待办时间不能在当前时间之前");
         }
 
         if (dto.getFollowId() == 33) {
-            if (dto.getOrderType() == null || dto.getOrderType() == 1) {
-                throw new RuntimeException("参数错误,方案演示时,预约待办类型不能为空或待办");
+            if (dto.getOrderType() == null || dto.getOrderType() != 1) {
+                throw new BusinessException("参数错误,方案演示时,预约待办类型不能为空或待办");
             }
         }
     }

+ 23 - 16
src/main/java/com/jtzx/crm/module/sys/service/SysCustomerOperLogService.java

@@ -75,8 +75,7 @@ public class SysCustomerOperLogService {
         if (dateSelectStatus != null && dateSelectStatus) {
             resultData.setDateData(DateSelectUtil.getDateData());
         }
-        // 操作人
-        List<BindUserBO> memberData = Lists.newArrayList();
+
         // 小组
         List<SelectBO> groupData = Lists.newArrayList();
 
@@ -90,23 +89,32 @@ public class SysCustomerOperLogService {
                                         SysCustomerOperLogEntity::getOperName,
                                         SysCustomerOperLogEntity::getOperUserGroupId
                                 )
-                                .eq(dto.getCustomerId()!=null,SysCustomerOperLogEntity::getCustomerId,dto.getCustomerId())
+                                .eq(dto.getCustomerId() != null, SysCustomerOperLogEntity::getCustomerId, dto.getCustomerId())
                                 .orderByDesc(SysCustomerOperLogEntity::getCreatedAt)
                 );
         if (CollUtil.isNotEmpty(logEntityList)) {
 
-            logEntityList.forEach(
-                    entity -> {
-                        if (memberData.stream().map(BindUserBO::getId).noneMatch(entity.getOperUserId()::equals)) {
-                            BindUserBO member = BindUserBO.builder()
-                                    .id(entity.getOperUserId())
-                                    .username(entity.getOperName())
-                                    .groupId(entity.getOperUserGroupId())
-                                    .build();
-                            memberData.add(member);
+            // 操作人
+            if(Boolean.TRUE.equals(dateSelectStatus) && Boolean.TRUE.equals(groupSelectStatus)){
+                List<BindUserBO> memberData = Lists.newArrayList();
+                logEntityList.forEach(
+                        entity -> {
+                            if (entity.getOperUserId() != null) {
+                                if (CollUtil.isEmpty(memberData) || memberData.stream().map(BindUserBO::getId).noneMatch(entity.getOperUserId()::equals)) {
+                                    BindUserBO member = BindUserBO.builder()
+                                            .id(entity.getOperUserId())
+                                            .username(entity.getOperName())
+                                            .groupId(entity.getOperUserGroupId())
+                                            .build();
+                                    memberData.add(member);
+                                }
+                            }
                         }
-                    }
-            );
+                );
+                // 操作人
+                resultData.setMemberData(memberData);
+            }
+
             // 小组
             if (groupSelectStatus != null && groupSelectStatus) {
                 List<Long> operUserGroupIdList =
@@ -134,8 +142,7 @@ public class SysCustomerOperLogService {
             }
 
         }
-        // 操作人
-        resultData.setMemberData(memberData);
+
         // 小组
         resultData.setGroupData(groupData);
         return resultData;

+ 0 - 46
src/main/java/com/jtzx/crm/module/sys/service/SysCustomerTodoService.java

@@ -2,19 +2,14 @@ package com.jtzx.crm.module.sys.service;
 
 import cc.uncarbon.framework.core.context.UserContextHolder;
 import cc.uncarbon.framework.core.exception.BusinessException;
-import cc.uncarbon.framework.crud.entity.HelioBaseEntity;
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.collection.CollUtil;
-import cn.hutool.core.date.DateTime;
-import cn.hutool.core.date.DateUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.google.common.collect.Lists;
 import com.jtzx.crm.module.sys.entity.SysCustomerTodoEntity;
 import com.jtzx.crm.module.sys.mapper.SysCustomerFollowMapper;
 import com.jtzx.crm.module.sys.mapper.SysCustomerTodoMapper;
 import com.jtzx.crm.module.sys.model.request.AdminSysCustomerTodoInsertOrUpdateDTO;
-import com.jtzx.crm.module.sys.model.response.BindUserBO;
-import com.jtzx.crm.module.sys.model.response.SysCustomerFollowHistorySelectBO;
 import com.jtzx.crm.module.sys.model.response.SysCustomerFollowListBO;
 import com.jtzx.crm.module.sys.model.response.SysCustomerTodoBO;
 import lombok.RequiredArgsConstructor;
@@ -43,47 +38,6 @@ public class SysCustomerTodoService {
     private final SysCustomerDataFollowService sysCustomerDataFollowService;
 
 
-    /**
-     * 待办页面查询顶部筛选条件数据
-     *
-     * @return
-     */
-    public List<BindUserBO> queryMemberData(String dateStr) {
-
-        DateTime startDateTime = DateUtil.beginOfMonth(DateUtil.parse(dateStr));
-        DateTime endDateTime = DateUtil.endOfMonth(DateUtil.parse(dateStr));
-        List<SysCustomerTodoEntity> todoEntityList =
-                sysCustomerTodoMapper.selectList(
-                        new LambdaQueryWrapper<>(SysCustomerTodoEntity.class)
-                                .select(
-                                        SysCustomerTodoEntity::getClaimUserId,
-                                        SysCustomerTodoEntity::getClaimUserName
-                                )
-                                .eq(SysCustomerTodoEntity::getOrderStatus, 0)
-                                .ge(SysCustomerTodoEntity::getOrderDatetime, DateUtil.toLocalDateTime(startDateTime))
-                                .le(SysCustomerTodoEntity::getOrderDatetime, DateUtil.toLocalDateTime(endDateTime))
-                                .orderByDesc(HelioBaseEntity::getCreatedAt)
-                );
-        List<BindUserBO> ret = Lists.newArrayList();
-        SysCustomerFollowHistorySelectBO sysCustomerFollowHistorySelectBO = sysCustomerDataFollowService.queryCustomerOrderSelectData(1, false, startDateTime, endDateTime);
-        if (sysCustomerFollowHistorySelectBO != null && CollUtil.isNotEmpty(sysCustomerFollowHistorySelectBO.getMemberData())) {
-            ret.addAll(sysCustomerFollowHistorySelectBO.getMemberData());
-        }
-        if (CollUtil.isNotEmpty(todoEntityList)) {
-            todoEntityList.forEach(
-                    entity -> {
-                        if (CollUtil.isEmpty(ret) || ret.stream().noneMatch(bo -> bo.getId().equals(entity.getClaimUserId()))) {
-                            BindUserBO bo = new BindUserBO();
-                            bo.setId(entity.getClaimUserId());
-                            bo.setUsername(entity.getClaimUserName());
-                            ret.add(bo);
-                        }
-                    }
-            );
-        }
-        return ret;
-    }
-
     /**
      * 根据条件查询待办列表
      *

+ 36 - 21
src/main/java/com/jtzx/crm/module/sys/service/SysCustomerUserCommonService.java

@@ -44,24 +44,6 @@ public class SysCustomerUserCommonService {
 
     private final SysUserRoleRelationMapper sysUserRoleRelationMapper;
 
-    /**
-     * 查询当前用户绑定的城市id集合,已处理权限(公海列表,我的客户页面查询列表使用),这两页面不需要区分小组长
-     *
-     * @return
-     */
-    public List<Long> queryUserCityIds(Long provinceId) {
-        List<Long> cityIds = Lists.newArrayList();
-        SysCustomerSelectBO selectBO = this.querySelectDataByType1(false);
-        if (CollUtil.isNotEmpty(selectBO.getRegionData())) {
-            selectBO.getRegionData().stream()
-                    .filter(x -> provinceId != null && provinceId.equals(x.getId()))
-                    .forEach(provinceRegion ->
-                            provinceRegion.getSubData()
-                                    .forEach(city -> cityIds.add(city.getId())));
-        }
-        return cityIds;
-    }
-
 
     /**
      * 查询当前用户绑定的城市id集合,已处理权限(客户跟进页面查询列表使用),这个页面需要区分小组长
@@ -232,12 +214,43 @@ public class SysCustomerUserCommonService {
         if (roles.contains("Member") || roles.contains("GroupManager")) {
             SysCustomerSelectBO sysCustomerSelectBO = this.handleMemberRole(provinceIds, cityIds, groupIds, userStatus);
             sysCustomerSelectBO.setMemberData(Lists.newArrayList());
-            return  sysCustomerSelectBO;
+            return sysCustomerSelectBO;
         }
         return SysCustomerSelectBO.builder().build();
     }
 
 
+    public SysCustomerSelectBO querySelectDataByType3(Boolean userStatus) {
+        //获取用户角色
+        List<String> roles = UserContextHolder.getUserContext().getRoles();
+        if (CollUtil.isEmpty(roles)) {
+            return SysCustomerSelectBO.builder().build();
+        }
+        List<Long> provinceIds = Lists.newArrayList();
+        List<Long> cityIds = Lists.newArrayList();
+        List<Long> groupIds = Lists.newArrayList();
+        //管理员
+        if (roles.contains("Admin")) {
+            List<SysGroupEntity> groupEntityList = sysGroupMapper.selectList(
+                    new LambdaQueryWrapper<>(SysGroupEntity.class)
+                            .select(
+                                    SysGroupEntity::getId
+                            )
+                            .orderByAsc(SysGroupEntity::getSortCode)
+            );
+            if (CollUtil.isNotEmpty(groupEntityList)) {
+                groupIds.addAll(
+                        groupEntityList.stream().map(SysGroupEntity::getId).filter(Objects::nonNull).distinct().toList());
+            }
+            return this.handleAdminRole(provinceIds, cityIds, groupIds, userStatus);
+        }
+        //普通成员或小组组长
+        if (roles.contains("Member") || roles.contains("GroupManager")) {
+            return this.handleMemberRole(provinceIds, cityIds, groupIds, userStatus);
+        }
+        return SysCustomerSelectBO.builder().build();
+    }
+
     /**
      * 查询顶部筛选条件的省,市,小组,人员数据,适用于 客户跟进 页面的顶部筛选条件的查询
      * 根据身份权限查询用户的省市绑定用户信息,区分管理员,小组组长,普通成员角色权限
@@ -274,7 +287,9 @@ public class SysCustomerUserCommonService {
         }
         //普通成员
         if (roles.contains("Member")) {
-            return this.handleMemberRole(provinceIds, cityIds, groupIds, userStatus);
+            SysCustomerSelectBO sysCustomerSelectBO = this.handleMemberRole(provinceIds, cityIds, groupIds, userStatus);
+            sysCustomerSelectBO.setMemberData(Lists.newArrayList());
+            return sysCustomerSelectBO;
         }
         return SysCustomerSelectBO.builder().build();
     }
@@ -501,7 +516,7 @@ public class SysCustomerUserCommonService {
                                 )
                                 .in(SysUserGroupRelationEntity::getProvinceId, provinceIds)
                                 .in(SysUserGroupRelationEntity::getCityId, cityIds)
-                                .in(CollUtil.isNotEmpty(groupIds),SysUserGroupRelationEntity::getGroupId,groupIds)
+                                .in(CollUtil.isNotEmpty(groupIds), SysUserGroupRelationEntity::getGroupId, groupIds)
                                 .orderByAsc(SysUserGroupRelationEntity::getProvinceId)
                 );
         if (userStatus) {