ludc
2024-12-13 9d92bb1d5698690bfd06fb93c668d9ae73300426
Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/util/RightControlUtil.java
@@ -9,15 +9,12 @@
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
@Slf4j
@Component
public class RightControlUtil {
    @Resource
    private PlatformClientUtil platformClientUtil;
@@ -25,11 +22,17 @@
    // add by xchao 2012.09.20 统一归整管理员、开发者用户判断
    // 以便将来有可能修改管理员、开发者用户,对于判断依然有效
    private static String userAdminEnum = "user.admin";
    private String userNameAdmin = null;
    private static String userDeveloperEnum = "user.developer";
    private String userNameDeveloper = null;
    private String userNameRoot = null;
    private static String userRootEnum = "user.rooter";
    public boolean isAdmin(String userName){
        return userName.equals(getUserNameAdmin(userAdminEnum));
    }
@@ -70,6 +73,7 @@
        }
        return userNameAdmin;
    }
    /**
     * 获取配置的开发人员
     * @param key 配置key
@@ -168,7 +172,7 @@
            if (mapRight.containsKey(right.funcId)) {
                lstRight = mapRight.get(right.funcId);
            } else {
                lstRight = new ArrayList<RoleRightInfo>();
                lstRight = new ArrayList<>();
            }
            lstRight.add(right);
            mapRight.put(right.funcId, lstRight);
@@ -197,18 +201,8 @@
                else{
                    if (lstRight.size() > 0)
                        isHasRight = true;
//               for (int j = 0; j < lstRight.size(); j++) {
//                  long lRight = lstRight.get(j).getRightValue();
//                  if (lRight != 0){
//                     isHasRight = true;
//                     //System.out.println("      === 有授权");
//
//                     break;
//                  }
//               }
                }
            }
            if (!isHasRight) {
                continue;
            }
@@ -227,7 +221,6 @@
        return map;
    }
    public FunctionInfo[] getFunctionsByParentId(String parentId, String userName) {
        FunctionInfo[] funcObjs =  null;
        try {
@@ -241,6 +234,40 @@
            log.error(e.code, e.messages);
        }
        return funcObjs;
    }
    /**
     * 根据父主键和用户以及角色信息来返回菜单数据
     * @param parentId
     * @param userName
     * @param userRoleRights
     * @return
     */
    public List<FunctionInfo> getMenusByPIdAndPermission(String parentId, String userName,RoleRightInfo[] userRoleRights) {
        Map<String, List<RoleRightInfo>> mapRight = new LinkedHashMap<String, List<RoleRightInfo>>();
        for (int i = 0; i < userRoleRights.length; i++) {
            RoleRightInfo right = userRoleRights[i];
            List<RoleRightInfo> lstRight = null;
            if (mapRight.containsKey(right.funcId)) {
                lstRight = mapRight.get(right.funcId);
            } else {
                lstRight = new ArrayList<>();
            }
            lstRight.add(right);
            mapRight.put(right.funcId, lstRight);
        }
        FunctionInfo[] functionInfos = this.getFunctionsByParentId(parentId, userName);
        boolean isAllShow = isDeveloper(userName) || isAdmin(userName) || !isFunctionSwithOn();
        List<FunctionInfo> functionInfoList = Arrays.stream(functionInfos).filter(menu -> {
            // 只返回有效且是菜单的节点
            if ((menu.isValid && menu.functionType == 0) && (mapRight.containsKey(menu.id) || isAllShow)) {
                return true;
            }
            return false;
        }).collect(Collectors.toList());
        return functionInfoList;
    }
    /**
@@ -261,4 +288,5 @@
        return false;
    }
}