修改主数据按钮查询权限接口,VciBaseUtil中增加校验当前用户是否为配置的超管用户方法
已修改8个文件
81 ■■■■■ 文件已修改
Source/UBCS/ubcs-service-api/ubcs-util-api/pom.xml 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Source/UBCS/ubcs-service-api/ubcs-util-api/src/main/java/com/vci/ubcs/starter/web/util/VciBaseUtil.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Source/UBCS/ubcs-service/ubcs-system/src/main/java/com/vci/ubcs/system/feign/SysClient.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Source/UBCS/ubcs-service/ubcs-system/src/main/java/com/vci/ubcs/system/mapper/MenuMapper.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Source/UBCS/ubcs-service/ubcs-system/src/main/java/com/vci/ubcs/system/service/IMenuService.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Source/UBCS/ubcs-service/ubcs-system/src/main/java/com/vci/ubcs/system/service/impl/MenuServiceImpl.java 32 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Source/UBCS/ubcs-service/ubcs-system/src/main/java/com/vci/ubcs/system/service/impl/RoleMenuServiceImpl.java 10 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Source/UBCS/ubcs-service/ubcs-system/src/main/resources/mapper/MenuMapper.xml 13 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Source/UBCS/ubcs-service-api/ubcs-util-api/pom.xml
@@ -54,5 +54,11 @@
            <groupId>org.springblade</groupId>
            <artifactId>blade-starter-log</artifactId>
        </dependency>
        <dependency>
            <groupId>com.vci.ubcs</groupId>
            <artifactId>ubcs-system-api</artifactId>
            <version>3.0.1.RELEASE</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>
</project>
Source/UBCS/ubcs-service-api/ubcs-util-api/src/main/java/com/vci/ubcs/starter/web/util/VciBaseUtil.java
@@ -17,8 +17,10 @@
import com.vci.ubcs.starter.web.pagemodel.SessionInfo;
import com.vci.ubcs.starter.web.toolmodel.DateConverter;
import com.vci.ubcs.starter.web.wrapper.VciQueryWrapperForDO;
import com.vci.ubcs.system.cache.NacosConfigCache;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.utils.Func;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ResourceUtils;
@@ -52,6 +54,15 @@
    public VciBaseUtil() {
    }
    /**
     * 检查是否为配置的超管租户和用户
     * @return false不是超管,true是超管
     */
    public static Boolean checkAdminTenant(){
        return NacosConfigCache.getAdminUserInfo().getTenantId().equals(AuthUtil.getTenantId())
            && NacosConfigCache.getAdminUserInfo().getUserName().equals(AuthUtil.getUserName());
    }
    public static String getPk() {
        return String.valueOf(getPKLong(1,1));
    }
Source/UBCS/ubcs-service/ubcs-system/src/main/java/com/vci/ubcs/system/feign/SysClient.java
@@ -21,6 +21,7 @@
import com.vci.ubcs.system.vo.DeptVO;
import com.vci.ubcs.system.vo.RoleVO;
import lombok.AllArgsConstructor;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tenant.annotation.NonDS;
import org.springblade.core.tool.api.R;
import org.springframework.web.bind.annotation.*;
@@ -81,7 +82,7 @@
    @Override
    @GetMapping(MENU_BUTTON)
    public R<List<Menu>> getMenuButtonByType(String btmType) {
        return R.data(menuService.getMenuButtonByType(btmType));
        return R.data(menuService.getMenuButtonByType(btmType, AuthUtil.getUserId()));
    }
    @Override
Source/UBCS/ubcs-service/ubcs-system/src/main/java/com/vci/ubcs/system/mapper/MenuMapper.java
@@ -125,12 +125,13 @@
     * @return
     */
    List<Menu> allMenu();
    /**
     * 根据业务类型查询菜单的子按钮
     *
     * @return
     */
    List<Menu> selectMenuChildByBtnType(String btmType);
    List<Menu> selectMenuChildByBtnType(String btmType,List<String> roleIds);
    /**
     * 权限配置菜单
Source/UBCS/ubcs-service/ubcs-system/src/main/java/com/vci/ubcs/system/service/IMenuService.java
@@ -168,11 +168,10 @@
    /**
     * 获取菜单下面的按钮
     *
     * @param btmType 业务类型
     * @return List<Menu>
     */
    List<Menu> getMenuButtonByType(String btmType);
    List<Menu> getMenuButtonByType(String btmType,Long userId);
    /**
     * 根据code和用户id查询菜单信息
Source/UBCS/ubcs-service/ubcs-system/src/main/java/com/vci/ubcs/system/service/impl/MenuServiceImpl.java
@@ -16,11 +16,13 @@
 */
package com.vci.ubcs.system.service.impl;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.vci.ubcs.starter.util.MybatisParameterUtil;
import com.vci.ubcs.starter.web.util.VciBaseUtil;
import com.vci.ubcs.system.cache.NacosConfigCache;
import com.vci.ubcs.system.cache.SysCache;
import com.vci.ubcs.system.dto.MenuDTO;
@@ -69,7 +71,6 @@
    private final ITopMenuSettingService topMenuSettingService;
    private final static String PARENT_ID = "parentId";
    private final static Integer MENU_CATEGORY = 1;
    private final NacosConfigCache nacosConfigCache;
    @Override
    public List<MenuVO> lazyList(Long parentId, Map<String, Object> param) {
@@ -96,7 +97,8 @@
        List<Menu> allMenus = baseMapper.allMenu();
        List<Menu> roleMenus;
        // 超级管理员并且不是顶部菜单请求则返回全部菜单
        if (AuthUtil.isAdministrator() && Func.isEmpty(topMenuId)) {
        // if (AuthUtil.isAdministrator() && Func.isEmpty(topMenuId)) {
        if (VciBaseUtil.checkAdminTenant() && Func.isEmpty(topMenuId)) {
            roleMenus = allMenus;
        }
        // 非超级管理员并且不是顶部菜单请求则返回对应角色权限菜单
@@ -139,7 +141,7 @@
    @Override
    public List<MenuVO> buttons(String roleId) {
        List<Menu> buttons = (AuthUtil.isAdministrator()) ? baseMapper.allButtons() : baseMapper.buttons(Func.toLongList(roleId));
        List<Menu> buttons = (VciBaseUtil.checkAdminTenant()) ? baseMapper.allButtons() : baseMapper.buttons(Func.toLongList(roleId));
        MenuWrapper menuWrapper = new MenuWrapper();
        return menuWrapper.listNodeVO(buttons);
    }
@@ -161,7 +163,7 @@
    @Override
    public List<TreeNode> grantTopTree(BladeUser user) {
        List<TreeNode> menuTree = user.getTenantId().equals(nacosConfigCache.getAdminUserInfo().getTenantId()) ? baseMapper.grantTopTree() : baseMapper.grantTopTreeByRole(Func.toLongList(user.getRoleId()));
        List<TreeNode> menuTree = user.getTenantId().equals(NacosConfigCache.getAdminUserInfo().getTenantId()) ? baseMapper.grantTopTree() : baseMapper.grantTopTreeByRole(Func.toLongList(user.getRoleId()));
        return ForestNodeMerger.merge(tenantPackageTree(menuTree, user.getTenantId()));
    }
@@ -224,12 +226,12 @@
    @Override
    public List<TreeNode> grantDataScopeTree(BladeUser user) {
        return ForestNodeMerger.merge(user.getTenantId().equals(nacosConfigCache.getAdminUserInfo().getTenantId()) ? baseMapper.grantDataScopeTree() : baseMapper.grantDataScopeTreeByRole(Func.toLongList(user.getRoleId())));
        return ForestNodeMerger.merge(user.getTenantId().equals(NacosConfigCache.getAdminUserInfo().getTenantId()) ? baseMapper.grantDataScopeTree() : baseMapper.grantDataScopeTreeByRole(Func.toLongList(user.getRoleId())));
    }
    @Override
    public List<TreeNode> grantApiScopeTree(BladeUser user) {
        return ForestNodeMerger.merge(user.getTenantId().equals(nacosConfigCache.getAdminUserInfo().getTenantId()) ? baseMapper.grantApiScopeTree() : baseMapper.grantApiScopeTreeByRole(Func.toLongList(user.getRoleId())));
        return ForestNodeMerger.merge(user.getTenantId().equals(NacosConfigCache.getAdminUserInfo().getTenantId()) ? baseMapper.grantApiScopeTree() : baseMapper.grantApiScopeTreeByRole(Func.toLongList(user.getRoleId())));
    }
    @Override
@@ -309,9 +311,19 @@
        return saveOrUpdate(menu);
    }
    /**
     * 获取菜单下面的按钮
     * @param btmType 业务类型
     * @return List<Menu>
     */
    @Override
    public List<Menu> getMenuButtonByType(String btmType) {
        return baseMapper.selectMenuChildByBtnType(btmType);
    @Cacheable(cacheNames = MENU_CACHE, key = "'auth:menuButton:' + #userId")
    public List<Menu> getMenuButtonByType(String btmType,Long userId) {
        List<String> roleIds = null;
        if(!VciBaseUtil.checkAdminTenant()){
            roleIds = Arrays.asList(AuthUtil.getUser().getRoleId().split(","));
        }
        return baseMapper.selectMenuChildByBtnType(btmType,roleIds);
    }
    /**
@@ -333,9 +345,7 @@
            .eq(Menu::getCategory,1) /*菜单类型不能为按钮*/
            .orderByAsc(Menu::getCode);  /*根据code排序与classify的btmtypeid对应*/
        // 超管不用根据角色来查询
        if(!AuthUtil.getTenantId().equals(NacosConfigCache.getAdminUserInfo().getTenantId())
            && !AuthUtil.getUserId().equals(NacosConfigCache.getAdminUserInfo().getUserId())
        ){
        if(!VciBaseUtil.checkAdminTenant()){
            if(Func.isBlank(userId.toString()) && Func.isBlank(AuthUtil.getUserId().toString())){
                throw new ServiceException("获取用户id失败");
            }
Source/UBCS/ubcs-service/ubcs-system/src/main/java/com/vci/ubcs/system/service/impl/RoleMenuServiceImpl.java
@@ -53,20 +53,14 @@
    private IUserClient userClient;
    /**
     * 根据用户id查询,被授权的菜单id
     * 根据用户id查询角色id,再查询被授权的菜单id
     * @param userId
     * @return
     */
    @Override
    public List<Long> getMenuIdByUserId(Long userId) {
        // 根据用户id查询菜单id
        R<User> userR = userClient.userInfoById((Func.isEmpty(userId) ? AuthUtil.getUserId():userId));
        if (!userR.isSuccess() || Func.isEmpty(userR.getData())) {
            throw new ServiceException("用户信息查询失败,原因:"+userR.getMsg());
        }
        // 当查询条件in大于一千条时
        List<String> roleIdList = Func.toStrList(userR.getData().getRoleId());
        List<String> roleIdList = Func.toStrList(AuthUtil.getUser().getRoleId());
        //构建查询菜单id的查询条件
        LambdaQueryWrapper<RoleMenu> roleMenuWrapper = Wrappers.<RoleMenu>query()
            .lambda().select(RoleMenu::getMenuId);
Source/UBCS/ubcs-service/ubcs-system/src/main/resources/mapper/MenuMapper.xml
@@ -483,11 +483,20 @@
    <select id="selectMenuChildByBtnType" resultMap="menuResultMap">
        select pm.*
        from pl_sys_menu ps, pl_sys_menu pm
            from pl_sys_menu ps, pl_sys_menu pm
        where pm.is_deleted = 0
          and ps.category = 1
          and ps.CODE = #{btmType}
          and ps.id = pm.parent_id order by pm.sort asc
          and ps.ID = pm.PARENT_ID
            <if test="roleIds != null and roleIds != ''">
                and ps.ID in (
                    SELECT menu_id FROM pl_org_role_menu WHERE role_id IN
                    <foreach collection="roleIds" index="index" item="item" open="(" separator="," close=")">
                        #{item}
                    </foreach>
                )
            </if>
        order by pm.sort asc
    </select>
</mapper>