Pārlūkot izejas kodu

feat(sys): 添加权限列表查询组员下拉接口及优化客户数据权限查询逻辑

- 在 AdminUserRoleController 中新增 /role/userList 接口,返回用户角色列表数据
- 修改 userAdd 接口返回插入记录 ID,提升调用便捷性
- 将分页查询接口 /role/pageListData 的请求方式改为 POST,符合数据过滤需求
- RoleUserBO 增加 roleId 字段,完善用户角色信息
- 优化 SysCustomerDataPrivateService 中省市用户及组列表逻辑,避免空参数导致查询异常
- 调整 SysCustomerDataPublicService 城市 ID 相关判空逻辑,提高健壮性
- 优化 SysCustomerUserCommonService 数据构建流程,调整全选项插入顺序避免重复
- SysUserRoleRelationService 增加查询用户下拉数据方法,支持去重和用户状态过滤
- 各处新增权限校验调用,保障接口安全性
zhangxf 1 mēnesi atpakaļ
vecāks
revīzija
7c5d245da1

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

@@ -63,6 +63,15 @@ public class AdminUserRoleController {
     }
 
 
+    @Operation(summary = "权限列表查询组员下拉接口")
+    @GetMapping(value = "/role/userList")
+    public ApiResult<List<RoleUserBO>> queryUserData() {
+        sysCustomerDataPermissionService.adminPermission();
+        List<RoleUserBO> userList = sysUserRoleRelationService.queryUserData();
+        return ApiResult.data(userList);
+    }
+
+
     @Operation(summary = "表格查询接口")
     @GetMapping(value = "/role/tableData")
     public ApiResult<List<UserRoleRelationBO>> queryTableData() {
@@ -73,10 +82,9 @@ public class AdminUserRoleController {
 
     @Operation(summary = "设置角色用户数据接口")
     @PostMapping(value = "/role/userAdd")
-    public ApiResult<Void> userAdd(@RequestBody UserRoleRelationInsertDTO dto) {
+    public ApiResult<Long> userAdd(@RequestBody UserRoleRelationInsertDTO dto) {
         sysCustomerDataPermissionService.adminPermission();
-        sysUserRoleRelationService.adminInsert(dto);
-        return ApiResult.success();
+        return ApiResult.data(sysUserRoleRelationService.adminInsert(dto));
     }
 
     @Operation(summary = "删除角色用户数据接口")
@@ -89,7 +97,7 @@ public class AdminUserRoleController {
 
 
     @Operation(summary = "列表分页查询接口")
-    @GetMapping(value = "/role/pageListData")
+    @PostMapping(value = "/role/pageListData")
     public ApiResult<PageResult<UserRoleRelationPageListBO>> queryListByPage(@RequestBody UserRoleRelationDTO dto) {
         sysCustomerDataPermissionService.adminPermission();
         PageResult<UserRoleRelationPageListBO> tableData = sysUserRoleRelationService.queryTableListByPage(dto);

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

@@ -34,4 +34,7 @@ public class RoleUserBO implements Serializable {
 
     @Schema(description = "sys_group表主id")
     private Long groupId;
+
+    @Schema(description = "角色id")
+    private Long roleId;
 }

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

@@ -90,22 +90,24 @@ public class SysCustomerDataPrivateService {
         if (dto.getGroupId() != null) {
             groupIds.add(dto.getGroupId());
         }
-        List<Long> cityIds = 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());
-            }
+        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 (CollUtil.isEmpty(groupIds)) {
+                    groupIds.addAll(
+                            bindUserBOS.stream()
+                                    .map(BindUserBO::getGroupId).distinct().toList());
+                }
             }
         }
-
         if (CollUtil.isEmpty(userIds) || CollUtil.isEmpty(groupIds)) {
             return new PageResult<SysCustomerDataPrivateBO>()
                     .setCurrent(1)
@@ -133,7 +135,7 @@ public class SysCustomerDataPrivateService {
                         // 城市id(不为空时)
                         .eq(Objects.nonNull(dto.getCityId()), SysCustomerDataEntity::getCityId, dto.getCityId())
                         // 城市id(为空时)
-                        .in(Objects.isNull(dto.getCityId()), SysCustomerDataEntity::getCityId, cityIds)
+                        .in(Objects.isNull(dto.getCityId())&&CollUtil.isNotEmpty(cityIds), SysCustomerDataEntity::getCityId, cityIds)
                         .in(SysCustomerDataEntity::getClaimUserGroupId, groupIds)
                         //必须是已认领的,不认领的是不能出现在我的客户里面的,所有必须加这个过滤,不管是存量还是首单客户都要加这个参数
                         .eq(SysCustomerDataEntity::getClaimStatus, 1)

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

@@ -90,7 +90,7 @@ public class SysCustomerDataPublicService {
                         // 城市id(不为空时)
                         .eq(Objects.nonNull(dto.getCityId()), SysCustomerDataEntity::getCityId, dto.getCityId())
                         // 城市id(为空时)
-                        .in(Objects.isNull(dto.getCityId()), SysCustomerDataEntity::getCityId, sysCustomerUserCommonService.queryUserCityIds(dto.getProvinceId()))
+                        .in(Objects.isNull(dto.getCityId())&&dto.getProvinceId()!=null, SysCustomerDataEntity::getCityId, sysCustomerUserCommonService.queryUserCityIds(dto.getProvinceId()))
                         //认领状态
                         .eq(SysCustomerDataEntity::getClaimStatus, 0)
                         // 排序

+ 13 - 11
src/main/java/com/jtzx/crm/module/sys/service/SysCustomerUserCommonService.java

@@ -646,6 +646,14 @@ public class SysCustomerUserCommonService {
                                            List<Long> cityIds,
                                            Boolean allStatus) {
         List<SelectBO> regionData = Lists.newArrayList();
+        SelectBO selectBO = SelectBO.builder()
+                .name("全部")
+                .sortCode(0)
+                .selectStatus(true)
+                .build();
+        if (allStatus) {
+            regionData.add(selectBO);
+        }
         //省份
         List<DictProvinceRegionEntity> regionEntityList = dictProvinceRegionMapper.selectByIds(provinceIds);
         //城市
@@ -653,14 +661,7 @@ public class SysCustomerUserCommonService {
         regionEntityList.stream()
                 .sorted(Comparator.comparing(DictProvinceRegionEntity::getSortCode))
                 .forEach(province -> {
-                    SelectBO selectBO = SelectBO.builder()
-                            .name("全部")
-                            .sortCode(0)
-                            .selectStatus(true)
-                            .build();
-                    if (allStatus) {
-                        regionData.add(selectBO);
-                    }
+
 
                     SelectBO provinceBO = SelectBO.builder().build();
                     provinceBO.setId(province.getId());
@@ -668,14 +669,15 @@ public class SysCustomerUserCommonService {
                     provinceBO.setSortCode(province.getSortCode());
                     provinceBO.setSelectStatus(false);
                     List<SelectBO> subData = Lists.newArrayList();
+                    if (allStatus) {
+                        subData.add(selectBO);
+                    }
                     AtomicInteger sortCode = new AtomicInteger(0);
                     dictCityRegionEntities.stream()
                             .filter(x -> x.getParentCode().equals(province.getCode()))
                             .sorted(Comparator.comparing(DictCityRegionEntity::getCode))
                             .forEach(city -> {
-                                if (allStatus) {
-                                    subData.add(selectBO);
-                                }
+
                                 SelectBO cityBo = SelectBO.builder().build();
                                 cityBo.setId(city.getId());
                                 cityBo.setName(city.getName());

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

@@ -241,6 +241,52 @@ public class SysUserRoleRelationService {
                 .setRecords(result);
     }
 
+    /**
+     * 查询用户下拉数据列表
+     * @return
+     */
+    public List<RoleUserBO> queryUserData() {
+        List<RoleUserBO> result = Lists.newArrayList();
+        //查询关系数据
+        List<SysUserRoleRelationEntity> relationEntityList = sysUserRoleRelationMapper.selectList(
+                new LambdaQueryWrapper<>(SysUserRoleRelationEntity.class)
+                        .ne(SysUserRoleRelationEntity::getRoleValue, "Member")
+                        .orderByDesc(SysUserRoleRelationEntity::getCreatedAt)
+        );
+        if (CollUtil.isNotEmpty(relationEntityList)) {
+            List<Long> userIds =
+                    relationEntityList.stream()
+                            .map(SysUserRoleRelationEntity::getUserId)
+                            .distinct().toList();
+            //查询用户
+            List<SysUserEntity> sysUserEntityList =
+                    sysUserMapper.selectList(
+                            new LambdaQueryWrapper<>(SysUserEntity.class)
+                                    .in(SysUserEntity::getId, userIds)
+                                    .eq(SysUserEntity::getStatus, 1)
+                    );
+            relationEntityList.forEach(record -> {
+                if (CollUtil.isNotEmpty(sysUserEntityList)) {
+                    sysUserEntityList.stream()
+                            .filter(x -> x.getId().equals(record.getUserId()))
+                            .findFirst()
+                            .ifPresent(user -> {
+                                RoleUserBO bo = RoleUserBO.builder().build();
+                                bo.setId(record.getId());
+                                bo.setUserId(record.getUserId());
+                                bo.setUserName(sysUserMapper.selectById(record.getUserId()).getUserName());
+                                bo.setGroupId(record.getGroupId());
+                                bo.setRoleId(record.getRoleId());
+                                bo.setUserName(user.getUserName());
+                                bo.setAccount(user.getPin());
+                                result.add(bo);
+                            });
+                }
+            });
+        }
+        return result;
+    }
+
     /**
      * 查询权限表格数据
      */