Преглед на файлове

提交630第二阶段app登录角色修改为配置

chenxiaofei преди 1 седмица
родител
ревизия
061f28eabd

+ 40 - 6
sckw-auth/src/main/java/com/sckw/auth/service/impl/AuthServiceImpl.java

@@ -1104,7 +1104,7 @@ public class AuthServiceImpl implements IAuthService {
             log.debug("开始加载APP角色权限配置,roleId: {}", roleId);
 
             // 3. 远程调用系统服务,获取APP角色权限相关的字典数据
-            // 字典类型由 DictTypeEnum.APP_ROLE_PERMISSION 定义,通常包含 value(角色类型枚举名) 和 label(关联的角色ID列表)
+            // 字典类型由 DictTypeEnum.APP_ROLE_PERMISSION 定义:value 存角色ID列表,label 存 AppRoleType 枚举名。
             List<SysDictResDto> dictList = systemService.queryDictDbByType(DictTypeEnum.APP_ROLE_PERMISSION.getType());
 
             // 4. 数据预处理与转换
@@ -1113,8 +1113,8 @@ public class AuthServiceImpl implements IAuthService {
             // 注意:若存在重复 Key,保留第一个出现的值 (first, second) -> first
             Map<String, SysDictResDto> dictMap = dictList.stream()
                     .filter(Objects::nonNull)
-                    .filter(item -> org.apache.commons.lang3.StringUtils.isNotBlank(item.getValue()))
-                    .collect(Collectors.toMap(SysDictResDto::getValue, item -> item, (first, second) -> first));
+                    .filter(item -> org.apache.commons.lang3.StringUtils.isNotBlank(item.getLabel()))
+                    .collect(Collectors.toMap(SysDictResDto::getLabel, item -> item, (first, second) -> first));
 
             // 5. 构建并返回角色配置对象
             AppRoleConfig config = AppRoleConfig.fromDict(roleId, dictMap);
@@ -1170,19 +1170,53 @@ public class AuthServiceImpl implements IAuthService {
             return new AppRoleConfig(Collections.emptySet());
         }
 
+        /**
+         * 根据角色ID和字典映射构建APP角色配置。
+         * <p>
+         * 该方法遍历字典项,查找value字段中包含当前roleId的配置项,
+         * 并将其label字段解析为对应的AppRoleType枚举值。
+         * </p>
+         *
+         * @param roleId   当前用户的角色ID
+         * @param dictMap  APP角色权限字典映射,Key为AppRoleType枚举名,Value为字典对象
+         * @return {@link AppRoleConfig} 包含匹配到的角色类型集合
+         */
         static AppRoleConfig fromDict(Long roleId, Map<String, SysDictResDto> dictMap) {
+            // 1. 参数校验:若角色ID为空或字典数据为空,直接返回空配置
             if (Objects.isNull(roleId) || dictMap == null || dictMap.isEmpty()) {
+                log.debug("构建APP角色配置失败:roleId为空或字典数据为空");
                 return empty();
             }
+
             String roleIdValue = String.valueOf(roleId);
+            log.debug("开始构建APP角色配置,roleId: {}", roleIdValue);
+
+            // 2. 流式处理字典数据,提取匹配的角色类型
             Set<AppRoleType> roleTypes = dictMap.values().stream()
+                    // 过滤掉null对象
                     .filter(Objects::nonNull)
-                    .filter(item -> matchRoleId(roleIdValue, item.getLabel()))
-                    .map(SysDictResDto::getValue)
+                    // 核心逻辑:判断字典项的value(角色ID列表字符串)是否包含当前roleId
+                    .filter(item -> {
+                        boolean matched = matchRoleId(roleIdValue, item.getValue());
+                        if (matched) {
+                            log.debug("字典项匹配成功 - Label: {}, Value: {}", item.getLabel(), item.getValue());
+                        }
+                        return matched;
+                    })
+                    // 获取字典项的Label,即AppRoleType的枚举名称
+                    .map(SysDictResDto::getLabel)
+                    // 将字符串转换为AppRoleType枚举对象
                     .map(AppRoleConfig::parseRoleType)
+                    // 过滤掉转换失败的Optional.empty()
                     .filter(Optional::isPresent)
+                    // 解包Optional获取枚举值
                     .map(Optional::get)
+                    // 收集为Set集合,去重
                     .collect(Collectors.toSet());
+
+            log.info("APP角色配置构建完成,roleId: {}, 匹配到的角色类型数量: {}, 类型列表: {}", 
+                    roleIdValue, roleTypes.size(), roleTypes);
+            
             return new AppRoleConfig(roleTypes);
         }
 
@@ -1206,7 +1240,7 @@ public class AuthServiceImpl implements IAuthService {
             }
             try {
                 return Optional.of(AppRoleType.valueOf(roleType.trim().toUpperCase(Locale.ROOT)));
-            } catch (IllegalArgumentException e) {
+            } catch (Exception e) {
                 log.warn("APP角色权限字典value配置错误,value:{}", roleType);
                 return Optional.empty();
             }

+ 3 - 3
sckw-auth/src/test/java/com/sckw/auth/service/impl/AuthServiceImplTest.java

@@ -18,8 +18,8 @@ public class AuthServiceImplTest {
     @Test
     public void appRoleConfigShouldMatchRoleIdFromDict() {
         Map<String, SysDictResDto> dictMap = new HashMap<>();
-        dictMap.put("SELLER", buildDict("SELLER", "1001,1002"));
-        dictMap.put("FINANCE", buildDict("FINANCE", "2001"));
+        dictMap.put("SELLER", buildDict("1001,1002", "SELLER"));
+        dictMap.put("FINANCE", buildDict("2001", "FINANCE"));
 
         AuthServiceImpl.AppRoleConfig appRoleConfig = AuthServiceImpl.AppRoleConfig.fromDict(1002L, dictMap);
 
@@ -33,7 +33,7 @@ public class AuthServiceImplTest {
     @Test
     public void appRoleConfigShouldNotMatchWhenRoleIdMissing() {
         Map<String, SysDictResDto> dictMap = new HashMap<>();
-        dictMap.put("PURCHASE", buildDict("PURCHASE", "3001"));
+        dictMap.put("PURCHASE", buildDict("3001", "PURCHASE"));
 
         AuthServiceImpl.AppRoleConfig appRoleConfig = AuthServiceImpl.AppRoleConfig.fromDict(9999L, dictMap);
 

+ 21 - 2
sckw-modules/sckw-system/src/main/java/com/sckw/system/dubbo/RemoteSystemServiceImpl.java

@@ -27,6 +27,7 @@ import com.sckw.system.service.KwsUserService;
 import com.sckw.system.service.SysAreaService;
 import jakarta.annotation.Resource;
 import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.dubbo.config.annotation.DubboService;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
@@ -44,6 +45,7 @@ import java.util.stream.Collectors;
  */
 @DubboService(group = "design", version = "1.0.0")
 @RequiredArgsConstructor
+@Slf4j
 public class RemoteSystemServiceImpl implements RemoteSystemService {
 
     @Autowired
@@ -140,20 +142,37 @@ public class RemoteSystemServiceImpl implements RemoteSystemService {
 
     /**
      * 根据字典类型直接查询数据库,不使用Redis缓存。
+     * 适用于需要获取最新字典数据或缓存失效的场景。
      *
      * @param type 字典类型
-     * @return 字典列表
+     * @return 字典列表,如果类型为空或未找到数据则返回空列表
      */
     @Override
     public List<SysDictResDto> queryDictDbByType(String type) {
+        // 参数校验:如果字典类型为空,直接返回空列表
         if (StringUtils.isBlank(type)) {
             return Collections.emptyList();
         }
+
+        // 记录调试日志,便于追踪查询请求
+        log.debug("开始从数据库查询字典数据,类型: {}", type);
+
+        // 直接从数据库查询指定类型的字典数据
         List<SysDict> sysDictList = sysDictDao.queryByType(type);
+
+        // 如果查询结果为空,记录日志并返回空列表
         if (CollectionUtils.isEmpty(sysDictList)) {
+            log.debug("数据库中未找到类型为 {} 的字典数据", type);
             return Collections.emptyList();
         }
-        return BeanUtils.copyToList(sysDictList, SysDictResDto.class);
+
+        // 将实体对象转换为DTO对象
+        List<SysDictResDto> result = BeanUtils.copyToList(sysDictList, SysDictResDto.class);
+        
+        // 记录成功日志,包含查询到的数据数量
+        log.debug("成功从数据库查询到类型为 {} 的字典数据,数量: {}", type, result.size());
+        
+        return result;
     }
 
     @Override

+ 71 - 72
sql/2026/06/2026_06_07_fleet_truck_max_transport_distance.sql

@@ -32,81 +32,80 @@ SET @app_role_permission_dict_id = (
 );
 
 -- label配置逗号分隔角色ID,例如 '1001,1002'
+-- sys_dict 手动ID起点
+SET @next_sys_dict_id = (SELECT COALESCE(MAX(id), 0) FROM sys_dict);
 
--- ===================== sys_dict 插入(零冲突版)=====================
-INSERT INTO sys_dict (
-    id, dict_id, value, label, type, description, sort, parent_id, remark,
-    status, create_by, create_time, update_by, update_time, del_flag, url
-)
-SELECT (SELECT COALESCE(MAX(id), 0) + 1 FROM sys_dict), @app_role_permission_dict_id, 'SELLER', '替换为销售角色ID,多个用逗号分隔', 'app_role_permission', '销售角色:显示订单统计、销售统计;底部导航走销售配置', 10, '0', NULL, 0, 0, NOW(), 0, NOW(), 0, NULL
-WHERE NOT EXISTS (SELECT 1 FROM sys_dict WHERE type = 'app_role_permission' AND value = 'SELLER' AND del_flag = 0);
-
-INSERT INTO sys_dict (
-    id, dict_id, value, label, type, description, sort, parent_id, remark,
-    status, create_by, create_time, update_by, update_time, del_flag, url
-)
-SELECT (SELECT COALESCE(MAX(id), 0) + 1 FROM sys_dict), @app_role_permission_dict_id, 'FINANCE', '替换为财务角色ID', 'app_role_permission', '财务角色:显示订单统计、钱包模块;底部导航走销售配置', 20, '0', NULL, 0, 0, NOW(), 0, NOW(), 0, NULL
-WHERE NOT EXISTS (SELECT 1 FROM sys_dict WHERE type = 'app_role_permission' AND value = 'FINANCE' AND del_flag = 0);
-
-INSERT INTO sys_dict (
-    id, dict_id, value, label, type, description, sort, parent_id, remark,
-    status, create_by, create_time, update_by, update_time, del_flag, url
-)
-SELECT (SELECT COALESCE(MAX(id), 0) + 1 FROM sys_dict), @app_role_permission_dict_id, 'PURCHASE', '替换为采购角色ID', 'app_role_permission', '采购角色:显示订单统计、钱包、地址;底部导航走采购配置', 30, '0', NULL, 0, 0, NOW(), 0, NOW(), 0, NULL
-WHERE NOT EXISTS (SELECT 1 FROM sys_dict WHERE type = 'app_role_permission' AND value = 'PURCHASE' AND del_flag = 0);
-
-INSERT INTO sys_dict (
-    id, dict_id, value, label, type, description, sort, parent_id, remark,
-    status, create_by, create_time, update_by, update_time, del_flag, url
-)
-SELECT (SELECT COALESCE(MAX(id), 0) + 1 FROM sys_dict), @app_role_permission_dict_id, 'DOOR_KEEPER', '替换为门卫角色ID', 'app_role_permission', '门卫角色:底部导航走门卫配置', 40, '0', NULL, 0, 0, NOW(), 0, NOW(), 0, NULL
-WHERE NOT EXISTS (SELECT 1 FROM sys_dict WHERE type = 'app_role_permission' AND value = 'DOOR_KEEPER' AND del_flag = 0);
-
-INSERT INTO sys_dict (
-    id, dict_id, value, label, type, description, sort, parent_id, remark,
-    status, create_by, create_time, update_by, update_time, del_flag, url
-)
-SELECT (SELECT COALESCE(MAX(id), 0) + 1 FROM sys_dict), @app_role_permission_dict_id, 'FORKLIFT_DRIVER', '替换为铲车司机角色ID', 'app_role_permission', '铲车司机角色:底部导航走铲车司机配置', 50, '0', NULL, 0, 0, NOW(), 0, NOW(), 0, NULL
-WHERE NOT EXISTS (SELECT 1 FROM sys_dict WHERE type = 'app_role_permission' AND value = 'FORKLIFT_DRIVER' AND del_flag = 0);
-
-INSERT INTO sys_dict (
-    id, dict_id, value, label, type, description, sort, parent_id, remark,
-    status, create_by, create_time, update_by, update_time, del_flag, url
-)
-SELECT (SELECT COALESCE(MAX(id), 0) + 1 FROM sys_dict), @app_role_permission_dict_id, 'BUYER', '替换为买家角色ID', 'app_role_permission', '买家角色:底部导航走买家配置', 60, '0', NULL, 0, 0, NOW(), 0, NOW(), 0, NULL
-WHERE NOT EXISTS (SELECT 1 FROM sys_dict WHERE type = 'app_role_permission' AND value = 'BUYER' AND del_flag = 0);
-
-INSERT INTO sys_dict (
-    id, dict_id, value, label, type, description, sort, parent_id, remark,
-    status, create_by, create_time, update_by, update_time, del_flag, url
-)
-SELECT (SELECT COALESCE(MAX(id), 0) + 1 FROM sys_dict), @app_role_permission_dict_id, 'DRIVER', '替换为司机角色ID', 'app_role_permission', '司机角色:底部导航走默认司机配置', 70, '0', NULL, 0, 0, NOW(), 0, NOW(), 0, NULL
-WHERE NOT EXISTS (SELECT 1 FROM sys_dict WHERE type = 'app_role_permission' AND value = 'DRIVER' AND del_flag = 0);
-
-INSERT INTO sys_dict (
-    id, dict_id, value, label, type, description, sort, parent_id, remark,
-    status, create_by, create_time, update_by, update_time, del_flag, url
-)
-SELECT (SELECT COALESCE(MAX(id), 0) + 1 FROM sys_dict), @app_role_permission_dict_id, 'LOGISTICS', '替换为物流角色ID', 'app_role_permission', '物流角色:底部导航走物流配置', 80, '0', NULL, 0, 0, NOW(), 0, NOW(), 0, NULL
-WHERE NOT EXISTS (SELECT 1 FROM sys_dict WHERE type = 'app_role_permission' AND value = 'LOGISTICS' AND del_flag = 0);
-
-INSERT INTO sys_dict (
-    id, dict_id, value, label, type, description, sort, parent_id, remark,
-    status, create_by, create_time, update_by, update_time, del_flag, url
-)
-SELECT (SELECT COALESCE(MAX(id), 0) + 1 FROM sys_dict), @app_role_permission_dict_id, 'SUPPLIER_ADMIN', '替换为供应商管理员角色ID', 'app_role_permission', '供应商管理员:企业类型为1时生效', 90, '0', NULL, 0, 0, NOW(), 0, NOW(), 0, NULL
-WHERE NOT EXISTS (SELECT 1 FROM sys_dict WHERE type = 'app_role_permission' AND value = 'SUPPLIER_ADMIN' AND del_flag = 0);
-
-INSERT INTO sys_dict (
-    id, dict_id, value, label, type, description, sort, parent_id, remark,
-    status, create_by, create_time, update_by, update_time, del_flag, url
-)
-SELECT (SELECT COALESCE(MAX(id), 0) + 1 FROM sys_dict), @app_role_permission_dict_id, 'LOGISTICS_ADMIN', '替换为物流商管理员角色ID', 'app_role_permission', '物流商管理员:企业类型为3时生效', 100, '0', NULL, 0, 0, NOW(), 0, NOW(), 0, NULL
-WHERE NOT EXISTS (SELECT 1 FROM sys_dict WHERE type = 'app_role_permission' AND value = 'LOGISTICS_ADMIN' AND del_flag = 0);
+-- ===================== sys_dict 插入:APP角色权限配置 =====================
+-- value = 角色ID,多个用英文逗号分隔
+-- label = AppRoleType编码
+-- type  = app_role_permission
 
 INSERT INTO sys_dict (
     id, dict_id, value, label, type, description, sort, parent_id, remark,
     status, create_by, create_time, update_by, update_time, del_flag, url
 )
-SELECT (SELECT COALESCE(MAX(id), 0) + 1 FROM sys_dict), @app_role_permission_dict_id, 'PURCHASE_ADMIN', '替换为采购商管理员角色ID', 'app_role_permission', '采购商管理员:企业类型为2时生效', 110, '0', NULL, 0, 0, NOW(), 0, NOW(), 0, NULL
-WHERE NOT EXISTS (SELECT 1 FROM sys_dict WHERE type = 'app_role_permission' AND value = 'PURCHASE_ADMIN' AND del_flag = 0);
+SELECT @next_sys_dict_id := @next_sys_dict_id + 1,
+       @app_role_permission_dict_id, '替换为销售角色ID,多个用英文逗号分隔', 'SELLER', 'app_role_permission',
+       '销售/供应商角色:显示订单统计、销售统计;底部导航走销售配置',
+       10, '0', NULL, 0, 0, NOW(), 0, NOW(), 0, NULL
+WHERE NOT EXISTS (SELECT 1 FROM sys_dict WHERE type = 'app_role_permission' AND label = 'SELLER' AND del_flag = 0);
+
+INSERT INTO sys_dict (id, dict_id, value, label, type, description, sort, parent_id, remark, status, create_by, create_time, update_by, update_time, del_flag, url)
+SELECT @next_sys_dict_id := @next_sys_dict_id + 1, @app_role_permission_dict_id, '替换为财务角色ID', 'FINANCE', 'app_role_permission',
+       '财务角色:显示订单统计、钱包模块;底部导航走销售配置',
+       20, '0', NULL, 0, 0, NOW(), 0, NOW(), 0, NULL
+WHERE NOT EXISTS (SELECT 1 FROM sys_dict WHERE type = 'app_role_permission' AND label = 'FINANCE' AND del_flag = 0);
+
+INSERT INTO sys_dict (id, dict_id, value, label, type, description, sort, parent_id, remark, status, create_by, create_time, update_by, update_time, del_flag, url)
+SELECT @next_sys_dict_id := @next_sys_dict_id + 1, @app_role_permission_dict_id, '替换为采购角色ID', 'PURCHASE', 'app_role_permission',
+       '采购角色:显示订单统计、钱包、地址;底部导航走采购配置',
+       30, '0', NULL, 0, 0, NOW(), 0, NOW(), 0, NULL
+WHERE NOT EXISTS (SELECT 1 FROM sys_dict WHERE type = 'app_role_permission' AND label = 'PURCHASE' AND del_flag = 0);
+
+INSERT INTO sys_dict (id, dict_id, value, label, type, description, sort, parent_id, remark, status, create_by, create_time, update_by, update_time, del_flag, url)
+SELECT @next_sys_dict_id := @next_sys_dict_id + 1, @app_role_permission_dict_id, '替换为门卫角色ID', 'DOOR_KEEPER', 'app_role_permission',
+       '门卫角色:底部导航走门卫配置',
+       40, '0', NULL, 0, 0, NOW(), 0, NOW(), 0, NULL
+WHERE NOT EXISTS (SELECT 1 FROM sys_dict WHERE type = 'app_role_permission' AND label = 'DOOR_KEEPER' AND del_flag = 0);
+
+INSERT INTO sys_dict (id, dict_id, value, label, type, description, sort, parent_id, remark, status, create_by, create_time, update_by, update_time, del_flag, url)
+SELECT @next_sys_dict_id := @next_sys_dict_id + 1, @app_role_permission_dict_id, '替换为叉车司机角色ID', 'FORKLIFT_DRIVER', 'app_role_permission',
+       '叉车司机角色:底部导航走叉车司机配置',
+       50, '0', NULL, 0, 0, NOW(), 0, NOW(), 0, NULL
+WHERE NOT EXISTS (SELECT 1 FROM sys_dict WHERE type = 'app_role_permission' AND label = 'FORKLIFT_DRIVER' AND del_flag = 0);
+
+INSERT INTO sys_dict (id, dict_id, value, label, type, description, sort, parent_id, remark, status, create_by, create_time, update_by, update_time, del_flag, url)
+SELECT @next_sys_dict_id := @next_sys_dict_id + 1, @app_role_permission_dict_id, '替换为买家角色ID', 'BUYER', 'app_role_permission',
+       '买家角色:底部导航走买家配置',
+       60, '0', NULL, 0, 0, NOW(), 0, NOW(), 0, NULL
+WHERE NOT EXISTS (SELECT 1 FROM sys_dict WHERE type = 'app_role_permission' AND label = 'BUYER' AND del_flag = 0);
+
+INSERT INTO sys_dict (id, dict_id, value, label, type, description, sort, parent_id, remark, status, create_by, create_time, update_by, update_time, del_flag, url)
+SELECT @next_sys_dict_id := @next_sys_dict_id + 1, @app_role_permission_dict_id, '替换为司机角色ID', 'DRIVER', 'app_role_permission',
+       '司机角色:底部导航走默认司机配置',
+       70, '0', NULL, 0, 0, NOW(), 0, NOW(), 0, NULL
+WHERE NOT EXISTS (SELECT 1 FROM sys_dict WHERE type = 'app_role_permission' AND label = 'DRIVER' AND del_flag = 0);
+
+INSERT INTO sys_dict (id, dict_id, value, label, type, description, sort, parent_id, remark, status, create_by, create_time, update_by, update_time, del_flag, url)
+SELECT @next_sys_dict_id := @next_sys_dict_id + 1, @app_role_permission_dict_id, '替换为物流角色ID', 'LOGISTICS', 'app_role_permission',
+       '物流角色:底部导航走物流配置',
+       80, '0', NULL, 0, 0, NOW(), 0, NOW(), 0, NULL
+WHERE NOT EXISTS (SELECT 1 FROM sys_dict WHERE type = 'app_role_permission' AND label = 'LOGISTICS' AND del_flag = 0);
+
+INSERT INTO sys_dict (id, dict_id, value, label, type, description, sort, parent_id, remark, status, create_by, create_time, update_by, update_time, del_flag, url)
+SELECT @next_sys_dict_id := @next_sys_dict_id + 1, @app_role_permission_dict_id, '替换为供应商管理员角色ID', 'SUPPLIER_ADMIN', 'app_role_permission',
+       '供应商管理员:企业类型为1时生效',
+       90, '0', NULL, 0, 0, NOW(), 0, NOW(), 0, NULL
+WHERE NOT EXISTS (SELECT 1 FROM sys_dict WHERE type = 'app_role_permission' AND label = 'SUPPLIER_ADMIN' AND del_flag = 0);
+
+INSERT INTO sys_dict (id, dict_id, value, label, type, description, sort, parent_id, remark, status, create_by, create_time, update_by, update_time, del_flag, url)
+SELECT @next_sys_dict_id := @next_sys_dict_id + 1, @app_role_permission_dict_id, '替换为物流商管理员角色ID', 'LOGISTICS_ADMIN', 'app_role_permission',
+       '物流商管理员:企业类型为3时生效',
+       100, '0', NULL, 0, 0, NOW(), 0, NOW(), 0, NULL
+WHERE NOT EXISTS (SELECT 1 FROM sys_dict WHERE type = 'app_role_permission' AND label = 'LOGISTICS_ADMIN' AND del_flag = 0);
+
+INSERT INTO sys_dict (id, dict_id, value, label, type, description, sort, parent_id, remark, status, create_by, create_time, update_by, update_time, del_flag, url)
+SELECT @next_sys_dict_id := @next_sys_dict_id + 1, @app_role_permission_dict_id, '替换为采购商管理员角色ID', 'PURCHASE_ADMIN', 'app_role_permission',
+       '采购商管理员:企业类型为2时生效',
+       110, '0', NULL, 0, 0, NOW(), 0, NOW(), 0, NULL
+WHERE NOT EXISTS (SELECT 1 FROM sys_dict WHERE type = 'app_role_permission' AND label = 'PURCHASE_ADMIN' AND del_flag = 0);