package com.backendsys.utils;

import java.util.*;

@SuppressWarnings({"rawtypes", "unchecked"})
public class UserUtils {
    // [UserUtils] 提取多个用户角色中的 module_ids，合并成一个数组 modules: []
    public static List<String> extractModuleCodes(Object roles) {
        Set<String> modulesSet = new LinkedHashSet<>();
        List<Map<String, Object>> roleList = (List<Map<String, Object>>) roles;
        for (Map<String, Object> role : roleList) {
            String moduleCode = (String) role.get("module_ids");
            if (moduleCode != null) {
                String[] modules = moduleCode.split(",");
                modulesSet.addAll(Arrays.asList(modules));
            }
        }
        try {
            return new ArrayList<>(modulesSet);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
