Просмотр исходного кода

feat(sys): 完善省市数据查询及客户管理相关功能

- 新增查询开通省市及对应城市列表的接口和服务方法,支持省市及城市数据结构返回
- 将公海客户查询联系人接口改为POST请求,优化请求参数传递方式
- 导入客户数据接口新增业务异常抛出,强化异常处理
- 为sys_customer_oper_log表和相关BO添加操作数据类型字段,用于区分客户及联系人操作日志
- 优化私域客户列表查询条件,防止空集合引起查询异常,增强查询稳定性
- 增加客户数据操作日志记录,操作内容中增加操作数据类型字段标识
- 修正客户联系人更新逻辑,先插入操作日志再更新数据库,确保日志完整性
- 优化客户权限查询中省市小组人员数据的去重及排序逻辑,防止重复添加“全部”选项
- 扩展客户相关BO,新增学段、地址、省份和城市字段,丰富客户信息展示
- 优化部分查询和排序逻辑,提升性能和代码风格一致性
- 调整服务层代码结构,增加实体到BO的转换方法,提升代码复用性和可维护性
zhangxf 1 месяц назад
Родитель
Сommit
13604cf47c

+ 7 - 0
src/main/java/com/jtzx/crm/module/api/web/sys/AdminDictProvinceRegionController.java

@@ -70,4 +70,11 @@ public class AdminDictProvinceRegionController {
         dictProvinceRegionService.DeleteProvinceStatus(id);
         return ApiResult.success();
     }
+
+    @Operation(summary = "查询开通的省市数据")
+    @GetMapping("/region/queryProvinceAndCity")
+    public ApiResult<List<DictProvinceRegionBO>> queryProvinceAndCity() {
+        sysCustomerDataPermissionService.adminPermission();
+        return ApiResult.data(dictProvinceRegionService.queryProvinceAndCity());
+    }
 }

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

@@ -112,7 +112,7 @@ public class CustomerDataPublicController {
     }
 
     @Operation(summary = "公海客户查询联系人数据接口")
-    @GetMapping(value = "/customer/person/query")
+    @PostMapping(value = "/customer/person/query")
     public ApiResult<List<SysCustomerPersonBO>> personQuery(@RequestBody @Valid CustomerPersonReqDTO dto) {
         List<SysCustomerPersonBO> sysCustomerPersonBOS = sysCustomerDataPublicService.adminListCustomerPerson(dto);
         return ApiResult.data(sysCustomerPersonBOS);
@@ -135,7 +135,7 @@ public class CustomerDataPublicController {
 
     @Operation(summary = "导入客户数据接口")
     @PostMapping(value = "/importCustomerData")
-    public ApiResult<Void> importCustomerData(@Parameter(description = "文件参数") @RequestPart MultipartFile file) {
+    public ApiResult<Void> importCustomerData(@Parameter(description = "文件参数") @RequestPart MultipartFile file) throws BusinessException{
         this.handleImportCustomerData(file);
         return ApiResult.success();
     }
@@ -145,7 +145,7 @@ public class CustomerDataPublicController {
      *
      * @param file
      */
-    public void handleImportCustomerData(MultipartFile file) {
+    public void handleImportCustomerData(MultipartFile file) throws BusinessException{
         try {
             InputStream inputStream = file.getInputStream();
             List<LinkedHashMap<Integer, Object>> allData = EasyExcel.read(inputStream)
@@ -175,7 +175,7 @@ public class CustomerDataPublicController {
      * @param allData
      * @return
      */
-    public List<AdminSysCustomerDataInsertOrUpdateDTO> getDTOList(List<LinkedHashMap<Integer, Object>> allData) {
+    public List<AdminSysCustomerDataInsertOrUpdateDTO> getDTOList(List<LinkedHashMap<Integer, Object>> allData) throws BusinessException {
         // 查询学段数据
         List<SysParamBaseDataEntity> sysParamBaseDataEntities = sysCustomerUserCommonService.queryParamBaseData(0);
         if (CollUtil.isEmpty(sysParamBaseDataEntities)) {

+ 5 - 0
src/main/java/com/jtzx/crm/module/sys/entity/SysCustomerOperLogEntity.java

@@ -85,4 +85,9 @@ public class SysCustomerOperLogEntity extends HelioBaseEntity<Long> {
     @Schema(description = "逻辑删除标识", title = "0=否 1=是")
     @TableField("del_flag")
     private Integer delFlag;
+
+
+    @Schema(description = "操作数据类型,0-客户,1-联系人")
+    @TableField("oper_data_type")
+    private Integer operDataType;
 }

+ 3 - 0
src/main/java/com/jtzx/crm/module/sys/model/response/DictProvinceRegionBO.java

@@ -12,6 +12,7 @@ import org.springframework.format.annotation.DateTimeFormat;
 
 import java.io.Serializable;
 import java.time.LocalDateTime;
+import java.util.List;
 
 
 /**
@@ -55,4 +56,6 @@ public class DictProvinceRegionBO implements Serializable {
     @Schema(description = "使用状态,0-未使用,1-已使用")
     private Integer useStatus;
 
+    @Schema(description = "城市数据")
+    private List<DictCityRegionBO> cityData;
 }

+ 12 - 0
src/main/java/com/jtzx/crm/module/sys/model/response/SysCustomerDataPublicBO.java

@@ -49,4 +49,16 @@ public class SysCustomerDataPublicBO implements Serializable {
 
     @Schema(description = "是否可删除,true-是,false-否")
     private Boolean delStatus;
+
+    @Schema(description = "学段id(param_base_data表主id)")
+    private Long stageId;
+
+    @Schema(description = "省份id(省份表主id)")
+    private Long provinceId;
+
+    @Schema(description = "城市id(城市表主id)")
+    private Long cityId;
+
+    @Schema(description = "地址")
+    private String address;
 }

+ 3 - 0
src/main/java/com/jtzx/crm/module/sys/model/response/SysCustomerOperLogBO.java

@@ -79,4 +79,7 @@ public class SysCustomerOperLogBO implements Serializable {
     @Schema(description = "操作内容")
     private String content;
 
+    @Schema(description = "操作数据类型,0-客户,1-联系人")
+    private Integer operDataType;
+
 }

+ 62 - 20
src/main/java/com/jtzx/crm/module/sys/service/DictProvinceRegionService.java

@@ -1,15 +1,17 @@
 package com.jtzx.crm.module.sys.service;
 
 import cc.uncarbon.framework.core.exception.BusinessException;
-import cc.uncarbon.framework.core.page.PageResult;
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.collection.CollUtil;
 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.DictCityRegionEntity;
 import com.jtzx.crm.module.sys.entity.DictProvinceRegionEntity;
+import com.jtzx.crm.module.sys.mapper.DictCityRegionMapper;
 import com.jtzx.crm.module.sys.mapper.DictProvinceRegionMapper;
 import com.jtzx.crm.module.sys.model.request.DictProvinceRegionDTO;
+import com.jtzx.crm.module.sys.model.response.DictCityRegionBO;
 import com.jtzx.crm.module.sys.model.response.DictProvinceRegionBO;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -17,6 +19,7 @@ import org.springframework.stereotype.Service;
 
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.Comparator;
 import java.util.List;
 
 
@@ -30,6 +33,8 @@ public class DictProvinceRegionService {
 
     private final DictProvinceRegionMapper dictProvinceRegionMapper;
 
+    private final DictCityRegionMapper dictCityRegionMapper;
+
 
     /**
      * 后台管理-查询所有的省份
@@ -56,6 +61,42 @@ public class DictProvinceRegionService {
         return this.entityList2BOs(list);
     }
 
+    /**
+     * 查询开通的省市数据
+     * @return
+     */
+    public List<DictProvinceRegionBO> queryProvinceAndCity() {
+
+        List<DictProvinceRegionBO> resultData = Lists.newArrayList();
+        List<DictProvinceRegionEntity> list = dictProvinceRegionMapper.selectList(
+                new QueryWrapper<DictProvinceRegionEntity>()
+                        .lambda()// 排序
+                        .eq(DictProvinceRegionEntity::getUseStatus, 1)
+                        .orderByAsc(DictProvinceRegionEntity::getSortCode)
+        );
+        List<String> provinceCodeList =
+                list.stream()
+                        .map(DictProvinceRegionEntity::getCode).toList();
+        List<DictCityRegionEntity> cityList =
+                dictCityRegionMapper.selectList(
+                        new QueryWrapper<DictCityRegionEntity>()
+                                .lambda()
+                                .in(DictCityRegionEntity::getParentCode, provinceCodeList)
+                );
+        list.forEach(province -> {
+            DictProvinceRegionBO provinceData = this.entity2BO(province);
+            List<DictCityRegionBO> cityData = Lists.newArrayList();
+            cityList.stream()
+                    .filter(city -> city.getParentCode().equals(province.getCode()))
+                    .sorted(Comparator.comparing(DictCityRegionEntity::getCode))
+                    .forEach(city -> cityData.add(this.cityEntity2BO(city)));
+            provinceData.setCityData(cityData);
+            resultData.add(provinceData);
+        });
+        return resultData;
+    }
+
+
     /**
      * 后台管理-查询未使用的省份
      */
@@ -74,14 +115,15 @@ public class DictProvinceRegionService {
      * 更新使用状态(相当于是参数设置中新增一个地区管理)
      */
     public void openProvinceStatus(DictProvinceRegionDTO dto) {
-        if(dto.getOldId()!=null){
-            dictProvinceRegionMapper.updateSortCode(dto.getOldId(),null,0);
+        if (dto.getOldId() != null) {
+            dictProvinceRegionMapper.updateSortCode(dto.getOldId(), null, 0);
         }
-        dictProvinceRegionMapper.updateSortCode(dto.getId(),dto.getSortCode(),1);
+        dictProvinceRegionMapper.updateSortCode(dto.getId(), dto.getSortCode(), 1);
     }
 
     /**
      * 更新使用状态(相当于是参数设置中删除一个地区管理)
+     *
      * @param id
      */
     public void DeleteProvinceStatus(Long id) {
@@ -123,11 +165,12 @@ public class DictProvinceRegionService {
 
     /**
      * 批量操作,前端排序
+     *
      * @param dtoList
      */
-    public void regionSort(List<DictProvinceRegionDTO> dtoList){
+    public void regionSort(List<DictProvinceRegionDTO> dtoList) {
         dictProvinceRegionMapper.selectList(null)
-                .forEach(e -> dictProvinceRegionMapper.updateSortCode(e.getId(),null,0));
+                .forEach(e -> dictProvinceRegionMapper.updateSortCode(e.getId(), null, 0));
 
         dtoList.forEach(dto -> dictProvinceRegionMapper.updateSortCode(dto.getId(), dto.getSortCode(), 1));
 
@@ -180,19 +223,18 @@ public class DictProvinceRegionService {
         return ret;
     }
 
-    /**
-     * 实体分页转 BO 分页
-     *
-     * @param entityPage 实体分页
-     * @return BO 分页
-     */
-    private PageResult<DictProvinceRegionBO> entityPage2BOPage(Page<DictProvinceRegionEntity> entityPage) {
-        return new PageResult<DictProvinceRegionBO>()
-                .setCurrent(entityPage.getCurrent())
-                .setSize(entityPage.getSize())
-                .setTotal(entityPage.getTotal())
-                .setRecords(this.entityList2BOs(entityPage.getRecords()));
-    }
 
+    private DictCityRegionBO cityEntity2BO(DictCityRegionEntity entity) {
+        if (entity == null) {
+            return null;
+        }
+
+        DictCityRegionBO bo = new DictCityRegionBO();
+        BeanUtil.copyProperties(entity, bo);
+
+        // 可以在此处为BO填充字段
+
+        return bo;
+    }
 
 }

+ 9 - 13
src/main/java/com/jtzx/crm/module/sys/service/SysCustomerDataPrivateService.java

@@ -108,13 +108,6 @@ public class SysCustomerDataPrivateService {
                 }
             }
         }
-        if (CollUtil.isEmpty(userIds) || CollUtil.isEmpty(groupIds)) {
-            return new PageResult<SysCustomerDataPrivateBO>()
-                    .setCurrent(1)
-                    .setSize(dto.getPageSize())
-                    .setTotal(0)
-                    .setRecords(Lists.newArrayList());
-        }
 
         Page<SysCustomerDataEntity> entityPage = sysCustomerDataMapper.selectPage(
                 new Page<>(dto.getPageNum(), dto.getPageSize()),
@@ -123,11 +116,11 @@ public class SysCustomerDataPrivateService {
                         // 名称
                         .like(CharSequenceUtil.isNotBlank(dto.getQueryStr()), SysCustomerDataEntity::getName, CharSequenceUtil.cleanBlank(dto.getQueryStr()))
                         //存量客户判断
-                        .in(dto.getTypeId() != null && dto.getTypeId().equals(2), SysCustomerDataEntity::getSuccessUserId, userIds)
+                        .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), SysCustomerDataEntity::getClaimUserId, userIds)
+                        .in(dto.getTypeId() != null && dto.getTypeId().equals(1)&& CollUtil.isNotEmpty(userIds), SysCustomerDataEntity::getClaimUserId, userIds)
                         // 学段id(param_base_data表主id)
                         .eq(Objects.nonNull(dto.getStageId()), SysCustomerDataEntity::getStageId, dto.getStageId())
                         // 省份id(省份表主id)
@@ -136,7 +129,7 @@ public class SysCustomerDataPrivateService {
                         .eq(Objects.nonNull(dto.getCityId()), SysCustomerDataEntity::getCityId, dto.getCityId())
                         // 城市id(为空时)
                         .in(Objects.isNull(dto.getCityId())&&CollUtil.isNotEmpty(cityIds), SysCustomerDataEntity::getCityId, cityIds)
-                        .in(SysCustomerDataEntity::getClaimUserGroupId, groupIds)
+                        .in(CollUtil.isNotEmpty(groupIds),SysCustomerDataEntity::getClaimUserGroupId, groupIds)
                         //必须是已认领的,不认领的是不能出现在我的客户里面的,所有必须加这个过滤,不管是存量还是首单客户都要加这个参数
                         .eq(SysCustomerDataEntity::getClaimStatus, 1)
                         // 排序
@@ -346,7 +339,10 @@ public class SysCustomerDataPrivateService {
                 entityList.stream()
                         .map(SysCustomerDataEntity::getClaimUserGroupId)
                         .filter(Objects::nonNull).distinct().toList();
-        List<SysGroupEntity> groupEntityList = sysGroupMapper.selectByIds(groupIds);
+        List<SysGroupEntity> groupEntityList = Lists.newArrayList();
+        if(CollUtil.isNotEmpty(groupIds)){
+            groupEntityList.addAll(sysGroupMapper.selectByIds(groupIds));
+        }
         //查询学段
         List<Long> stageIds =
                 entityList.stream()
@@ -365,7 +361,7 @@ public class SysCustomerDataPrivateService {
                                         SysCustomerFollowEntity::getClaimDatetime
                                 )
                                 .in(SysCustomerFollowEntity::getCustomerId, entityList.stream().map(SysCustomerDataEntity::getId).toList())
-                                .in(SysCustomerFollowEntity::getClaimUserGroupId, groupIds)
+                                .in(CollUtil.isNotEmpty(groupIds),SysCustomerFollowEntity::getClaimUserGroupId, groupIds)
                                 .in(SysCustomerFollowEntity::getClaimUserId, entityList.stream().map(SysCustomerDataEntity::getClaimUserGroupId).distinct().toList())
                 );
 

+ 0 - 21
src/main/java/com/jtzx/crm/module/sys/service/SysCustomerDataPublicService.java

@@ -223,27 +223,6 @@ public class SysCustomerDataPublicService {
         if (dto.getGroupId() != null) {
             groupIds.add(dto.getGroupId());
         }
-        SysCustomerSelectBO selectBO = sysCustomerUserCommonService.querySelectDataByType1(false,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,false, false);
     }
 

+ 26 - 3
src/main/java/com/jtzx/crm/module/sys/service/SysCustomerDataService.java

@@ -85,6 +85,7 @@ public class SysCustomerDataService {
                 .cityId(entity.getCityId())
                 .cityName(entity.getCityName())
                 .content(dto.getStr())
+                .operDataType(0)
                 .build();
         sysCustomerOperLogMapper.insert(logEntity);
         return entity.getId();
@@ -112,9 +113,6 @@ public class SysCustomerDataService {
                         .eq(SysUserGroupRelationEntity::getCityId, dto.getCityId())
                         .last("limit 1")
         );
-        BeanUtil.copyProperties(dto, entity);
-        sysCustomerDataMapper.updateById(entity);
-
         SysCustomerOperLogEntity logEntity = SysCustomerOperLogEntity.builder()
                 .customerId(entity.getId())
                 .customerName(entity.getName())
@@ -127,11 +125,15 @@ public class SysCustomerDataService {
                 .cityId(entity.getCityId())
                 .cityName(entity.getCityName())
                 .content(entity.compareTo(dto))
+                .operDataType(0)
                 .build();
         if (userGroupRelation != null) {
             logEntity.setOperUserGroupId(userGroupRelation.getGroupId());
         }
         sysCustomerOperLogMapper.insert(logEntity);
+
+        BeanUtil.copyProperties(dto, entity);
+        sysCustomerDataMapper.updateById(entity);
     }
 
     /**
@@ -166,6 +168,7 @@ public class SysCustomerDataService {
                     .cityId(entity.getCityId())
                     .cityName(entity.getCityName())
                     .content(entity.getStr())
+                    .operDataType(0)
                     .build();
             sysCustomerOperLogMapper.insert(logEntity);
             sysCustomerDataMapper.deleteById(id);
@@ -222,6 +225,7 @@ public class SysCustomerDataService {
                 .cityName(sysCustomerDataEntity.getCityName())
                 .content(sysCustomerDataEntity.getCustomString())
                 .operUserGroupId(sysCustomerDataEntity.getClaimUserGroupId())
+                .operDataType(0)
                 .build();
         sysCustomerOperLogMapper.insert(logEntity);
     }
@@ -262,6 +266,7 @@ public class SysCustomerDataService {
                 .cityName(sysCustomerDataEntity.getCityName())
                 .content(sysCustomerDataEntity.returnCustomString())
                 .operUserGroupId(sysCustomerDataEntity.getClaimUserGroupId())
+                .operDataType(0)
                 .build();
         sysCustomerOperLogMapper.insert(logEntity);
     }
@@ -310,6 +315,24 @@ public class SysCustomerDataService {
             sysCustomerDataEntity.setSuccessUserName(sysUserEntity.getUserName());
         }
         sysCustomerDataMapper.updateById(sysCustomerDataEntity);
+
+        //添加认领日志
+        SysCustomerOperLogEntity logEntity = SysCustomerOperLogEntity.builder()
+                .customerId(sysCustomerDataEntity.getId())
+                .customerName(sysCustomerDataEntity.getName())
+                .operUserId(UserContextHolder.getUserId())
+                .operName(UserContextHolder.getUserName())
+                .operAction(2)
+                .operDatetime(LocalDateTime.now())
+                .provinceId(sysCustomerDataEntity.getProvinceId())
+                .provinceName(sysCustomerDataEntity.getProvinceName())
+                .cityId(sysCustomerDataEntity.getCityId())
+                .cityName(sysCustomerDataEntity.getCityName())
+                .content(sysCustomerDataEntity.returnCustomString())
+                .operUserGroupId(sysCustomerDataEntity.getClaimUserGroupId())
+                .operDataType(0)
+                .build();
+        sysCustomerOperLogMapper.insert(logEntity);
     }
 
     /**

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

@@ -43,7 +43,7 @@ public class SysCustomerOperLogService {
     /**
      * 操作日志列表查询
      */
-    public SysCustomerOperLogDataBO adminList(AdminSysCustomerOperLogListDTO dto,List<Long> userIds,List<Long> groupIds, Boolean dateSelectStatus, Boolean groupSelectStatus) {
+    public SysCustomerOperLogDataBO adminList(AdminSysCustomerOperLogListDTO dto, List<Long> userIds, List<Long> groupIds, Boolean dateSelectStatus, Boolean groupSelectStatus) {
 
         Page<SysCustomerOperLogEntity> entityPage = sysCustomerOperLogMapper.selectPage(
                 new Page<>(dto.getPageNum(), dto.getPageSize()),
@@ -218,7 +218,6 @@ public class SysCustomerOperLogService {
         BeanUtil.copyProperties(entity, bo);
 
         // 可以在此处为BO填充字段
-
         return bo;
     }
 

+ 9 - 5
src/main/java/com/jtzx/crm/module/sys/service/SysCustomerPersonService.java

@@ -99,7 +99,7 @@ public class SysCustomerPersonService {
 
         //新增联系人日志
         SysCustomerOperLogEntity logEntity = SysCustomerOperLogEntity.builder()
-                .customerId(entity.getId())
+                .customerId(dto.getCustomerId())
                 .customerName(entity.getName())
                 .operUserId(UserContextHolder.getUserId())
                 .operName(UserContextHolder.getUserName())
@@ -109,6 +109,7 @@ public class SysCustomerPersonService {
                 .provinceName(sysCustomerDataEntity.getProvinceName())
                 .cityId(sysCustomerDataEntity.getCityId())
                 .cityName(sysCustomerDataEntity.getCityName())
+                .operDataType(1)
                 .content(dto.getStr())
                 .build();
         sysCustomerOperLogMapper.insert(logEntity);
@@ -122,7 +123,7 @@ public class SysCustomerPersonService {
     @Transactional(rollbackFor = Exception.class)
     public void adminUpdate(AdminSysCustomerPersonInsertOrUpdateDTO dto) {
         log.info("[后台管理-客户(学校)联系人数据-编辑] >> DTO={}", dto);
-        SysCustomerDataEntity entity = sysCustomerDataMapper.selectById(dto.getId());
+        SysCustomerDataEntity entity = sysCustomerDataMapper.selectById(dto.getCustomerId());
         if (entity == null) {
             throw new BusinessException(400, "无效客户(学校)数据ID");
         }
@@ -139,9 +140,7 @@ public class SysCustomerPersonService {
                         .last("limit 1")
         );
         SysCustomerPersonEntity sysCustomerPersonEntity = sysCustomerPersonMapper.selectById(dto.getId());
-        BeanUtil.copyProperties(dto, sysCustomerPersonEntity);
-        sysCustomerPersonEntity.setId(null);
-        sysCustomerPersonMapper.updateById(sysCustomerPersonEntity);
+
 
         SysCustomerOperLogEntity logEntity = SysCustomerOperLogEntity.builder()
                 .customerId(entity.getId())
@@ -155,11 +154,15 @@ public class SysCustomerPersonService {
                 .cityId(entity.getCityId())
                 .cityName(entity.getCityName())
                 .content(sysCustomerPersonEntity.compareTo(dto))
+                .operDataType(1)
                 .build();
         if (userGroupRelation != null) {
             logEntity.setOperUserGroupId(userGroupRelation.getGroupId());
         }
         sysCustomerOperLogMapper.insert(logEntity);
+
+        BeanUtil.copyProperties(dto, sysCustomerPersonEntity);
+        sysCustomerPersonMapper.updateById(sysCustomerPersonEntity);
     }
 
     /**
@@ -200,6 +203,7 @@ public class SysCustomerPersonService {
                 .cityId(entity.getCityId())
                 .cityName(entity.getCityName())
                 .content(sysCustomerPersonEntity.getStr())
+                .operDataType(1)
                 .build();
         if (userGroupRelation != null) {
             logEntity.setOperUserGroupId(userGroupRelation.getGroupId());

+ 71 - 43
src/main/java/com/jtzx/crm/module/sys/service/SysCustomerUserCommonService.java

@@ -46,6 +46,7 @@ public class SysCustomerUserCommonService {
 
     /**
      * 查询当前用户绑定的城市id集合,已处理权限(公海列表,我的客户页面查询列表使用),这两页面不需要区分小组长
+     *
      * @return
      */
     public List<Long> queryUserCityIds(Long provinceId) {
@@ -64,6 +65,7 @@ public class SysCustomerUserCommonService {
 
     /**
      * 查询当前用户绑定的城市id集合,已处理权限(客户跟进页面查询列表使用),这个页面需要区分小组长
+     *
      * @return
      */
     public List<Long> queryUserCityIds1(Long provinceId) {
@@ -82,6 +84,7 @@ public class SysCustomerUserCommonService {
 
     /**
      * 根据当前用户的一个(多个)城市id查询小组组长或全部小组绑定的人员信息,这个是带权限的,小组组长(绑定的小组下面的所有成员)或者管理员(所有组下面的成员)
+     *
      * @param cityIds
      * @return
      */
@@ -138,6 +141,7 @@ public class SysCustomerUserCommonService {
 
     /**
      * 根据非当前用户一个(多个)城市id一个(多个)小组id查询绑定的人员信息,这个是不带权限的
+     *
      * @param cityIds
      * @param groupIds
      * @return
@@ -197,6 +201,7 @@ public class SysCustomerUserCommonService {
     /**
      * 查询顶部筛选条件的省,市,小组,人员数据,适用于公海客户,我的(私域)客户页面的顶部筛选条件的查询
      * 根据身份权限查询用户的省市绑定用户信息(成员和小组组长权限相同),只区分管理员和非管理员权限
+     *
      * @return
      */
     public SysCustomerSelectBO querySelectDataByType1(Boolean allStatus, Boolean userStatus) {
@@ -223,6 +228,7 @@ public class SysCustomerUserCommonService {
     /**
      * 查询顶部筛选条件的省,市,小组,人员数据,适用于 客户跟进 页面的顶部筛选条件的查询
      * 根据身份权限查询用户的省市绑定用户信息,区分管理员,小组组长,普通成员角色权限
+     *
      * @return
      */
     public SysCustomerSelectBO querySelectDataByType2(Boolean allStatus, Boolean userStatus) {
@@ -252,6 +258,7 @@ public class SysCustomerUserCommonService {
 
     /**
      * 学段信息
+     *
      * @return
      */
     public List<SelectBO> handleStageData() {
@@ -278,6 +285,7 @@ public class SysCustomerUserCommonService {
 
     /**
      * 产品信息
+     *
      * @return
      */
     public List<SelectBO> handleProductData() {
@@ -305,6 +313,7 @@ public class SysCustomerUserCommonService {
 
     /**
      * 类型信息,首单客户,存量客户
+     *
      * @return
      */
     public List<SelectBO> handleTypeData() {
@@ -338,6 +347,7 @@ public class SysCustomerUserCommonService {
 
     /**
      * 处理管理员角色
+     *
      * @param provinceIds
      * @param cityIds
      * @param groupIds
@@ -367,6 +377,7 @@ public class SysCustomerUserCommonService {
 
     /**
      * 处理小组组长角色
+     *
      * @param provinceIds
      * @param cityIds
      * @return
@@ -398,6 +409,7 @@ public class SysCustomerUserCommonService {
 
     /**
      * 处理普通成员角色
+     *
      * @param provinceIds
      * @param cityIds
      * @param groupIds
@@ -429,6 +441,7 @@ public class SysCustomerUserCommonService {
 
     /**
      * 处理省市和和成员,小组
+     *
      * @param provinceIds
      * @param cityIds
      * @param groupIds
@@ -461,56 +474,66 @@ public class SysCustomerUserCommonService {
                                         SysUserGroupRelationEntity::getGroupId,
                                         SysUserGroupRelationEntity::getProvinceId,
                                         SysUserGroupRelationEntity::getCityId,
-                                        SysUserGroupRelationEntity::getUserId
+                                        SysUserGroupRelationEntity::getUserId,
+                                        SysUserGroupRelationEntity::getCreatedAt
                                 )
                                 .in(SysUserGroupRelationEntity::getProvinceId, provinceIds)
                                 .in(SysUserGroupRelationEntity::getCityId, cityIds)
                                 .orderByAsc(SysUserGroupRelationEntity::getProvinceId)
                 );
         if (userStatus) {
-            regionData.forEach(province ->
+            regionData.forEach(province -> {
+                if(CollUtil.isNotEmpty(province.getSubData())){
                     province.getSubData().forEach(city -> {
-                        if (CollUtil.isNotEmpty(groupIds) && CollUtil.isNotEmpty(groupRelationEntityList)) {
-
-                            groupRelationEntityList.stream()
-                                    .filter(x -> x.getProvinceId().equals(province.getId()))
-                                    .filter(x -> x.getCityId().equals(city.getId()))
-                                    .filter(x -> CollUtil.isNotEmpty(groupIds) && groupIds.contains(x.getGroupId()))
-                                    .sorted(Comparator.comparing(SysUserGroupRelationEntity::getCreatedAt))
-                                    .collect(Collectors.groupingBy(SysUserGroupRelationEntity::getGroupId, LinkedHashMap::new, Collectors.toList()))
-                                    .forEach((key, value) -> {
-                                        if (allStatus) {
-                                            BindUserBO userBO = BindUserBO.builder().build();
-                                            userBO.setProvinceId(province.getId());
-                                            userBO.setCityId(city.getId());
-                                            userBO.setGroupId(key);
-                                            userBO.setUsername("全部");
-                                            userBO.setSortCode(0);
-                                            userBO.setSelectStatus(true);
-                                            userData.add(userBO);
-                                        }
-                                        AtomicInteger sortCode = new AtomicInteger(0);
-                                        value.forEach(user -> {
-                                            if (CollUtil.isNotEmpty(userEntityList)) {
-                                                userEntityList.stream()
-                                                        .filter(x -> x.getId().equals(user.getUserId()))
-                                                        .findFirst()
-                                                        .ifPresent(e -> {
-                                                            BindUserBO userBO = BindUserBO.builder().build();
-                                                            userBO.setId(user.getUserId());
-                                                            userBO.setProvinceId(user.getProvinceId());
-                                                            userBO.setCityId(user.getCityId());
-                                                            userBO.setGroupId(user.getGroupId());
-                                                            userBO.setUsername(e.getUserName());
-                                                            userBO.setSelectStatus(false);
-                                                            userBO.setSortCode(sortCode.incrementAndGet());
-                                                            userData.add(userBO);
-                                                        });
-                                            }
-                                        });
-                                    });
-                        }
-                    }));
+                                if (CollUtil.isNotEmpty(groupIds) && CollUtil.isNotEmpty(groupRelationEntityList)) {
+
+                                    groupRelationEntityList.stream()
+                                            .filter(x -> x.getProvinceId().equals(province.getId()))
+                                            .filter(x -> x.getCityId().equals(city.getId()))
+                                            .filter(x -> CollUtil.isNotEmpty(groupIds) && groupIds.contains(x.getGroupId()))
+                                            .sorted(Comparator.comparing(SysUserGroupRelationEntity::getCreatedAt))
+                                            .collect(Collectors.groupingBy(SysUserGroupRelationEntity::getGroupId, LinkedHashMap::new, Collectors.toList()))
+                                            .forEach((key, value) -> {
+                                                if (allStatus) {
+                                                    if(CollUtil.isEmpty(userData) || userData.stream().map(BindUserBO::getUsername).noneMatch("全部"::equals)){
+                                                        BindUserBO userBO = BindUserBO.builder().build();
+                                                        userBO.setProvinceId(province.getId());
+                                                        userBO.setCityId(city.getId());
+                                                        userBO.setGroupId(key);
+                                                        userBO.setUsername("全部");
+                                                        userBO.setSortCode(0);
+                                                        userBO.setSelectStatus(true);
+                                                        userData.add(userBO);
+                                                    }
+                                                }
+                                                AtomicInteger sortCode = new AtomicInteger(0);
+                                                value.forEach(user -> {
+                                                    if (CollUtil.isNotEmpty(userEntityList)) {
+                                                        userEntityList.stream()
+                                                                .filter(x -> x.getId().equals(user.getUserId()))
+                                                                .findFirst()
+                                                                .ifPresent(e -> {
+                                                                    if(CollUtil.isEmpty(userData)||userData.stream().map(BindUserBO::getId).noneMatch(user.getUserId()::equals)){
+                                                                        BindUserBO userBO = BindUserBO.builder().build();
+                                                                        userBO.setId(user.getUserId());
+                                                                        userBO.setProvinceId(user.getProvinceId());
+                                                                        userBO.setCityId(user.getCityId());
+                                                                        userBO.setGroupId(user.getGroupId());
+                                                                        userBO.setUsername(e.getUserName());
+                                                                        userBO.setSelectStatus(false);
+                                                                        userBO.setSortCode(sortCode.incrementAndGet());
+                                                                        userData.add(userBO);
+                                                                    }
+                                                                });
+                                                    }
+                                                });
+                                            });
+                                }
+                            }
+                    );
+                }
+
+            });
         }
         selectBO.setMemberData(userData);
         return selectBO;
@@ -519,6 +542,7 @@ public class SysCustomerUserCommonService {
 
     /**
      * 处理普通成员数据
+     *
      * @param provinceIds
      * @param cityIds
      * @param groupIds
@@ -557,6 +581,7 @@ public class SysCustomerUserCommonService {
 
     /**
      * 处理管理员角色数据
+     *
      * @param provinceIds
      * @param cityIds
      * @param groupIds
@@ -602,6 +627,7 @@ public class SysCustomerUserCommonService {
 
     /**
      * 处理小组
+     *
      * @param groupIds
      * @return
      */
@@ -638,6 +664,7 @@ public class SysCustomerUserCommonService {
 
     /**
      * 处理省市
+     *
      * @param provinceIds
      * @param cityIds
      * @return
@@ -694,6 +721,7 @@ public class SysCustomerUserCommonService {
 
     /**
      * 查询参数配置的基础信息数据
+     *
      * @param type 类型:0-学段,1-产品,2-职务,3-跟进
      * @return
      */