mitao
2024-06-19 e2622c1b801982d6b01d95442bab52061362eccd
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysRoleController.java
@@ -18,6 +18,7 @@
import com.ruoyi.system.domain.SysRoleMenu;
import com.ruoyi.system.domain.SysUserRole;
import com.ruoyi.system.domain.dto.RoleAddDto;
import com.ruoyi.system.domain.dto.RoleQuery;
import com.ruoyi.system.domain.dto.RoleUpdateDto;
import com.ruoyi.system.domain.vo.RoleInfoVo;
import com.ruoyi.system.mapper.SysMenuMapper;
@@ -26,12 +27,15 @@
import com.ruoyi.system.service.ISysRoleService;
import com.ruoyi.system.service.ISysUserRoleService;
import com.ruoyi.system.service.ISysUserService;
import io.seata.common.util.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
@@ -87,14 +91,16 @@
    }
    // @ApiOperation("获取所有角色信息根据公司id--分页")
    @GetMapping("/listPage")
    public AjaxResult listPage(Integer companyId,int pageNumber,int pageSize)
    @ApiOperation("获取角色列表")
    @PostMapping("/listPage")
    public AjaxResult listPage(@Validated @RequestBody RoleQuery query)
    {
        PageInfo<SysRole> pageInfo = new PageInfo<>(pageNumber, pageSize);
        PageInfo<SysRole> pageInfo = new PageInfo<>(query.getPageCurr(), query.getPageSize());
        PageInfo<SysRole> page = roleService.page(pageInfo,
                new LambdaQueryWrapper<SysRole>().ne(SysRole::getRoleId, 20));
                new LambdaQueryWrapper<SysRole>().ne(SysRole::getRoleId, 20)
                        .like(StringUtils.isNotBlank(query.getRoleName()), SysRole::getRoleName,
                                query.getRoleName()).eq(SysRole::getDelFlag, "0"));
        return AjaxResult.success(page);
    }
@@ -190,17 +196,29 @@
    public AjaxResult roleInfoFromUserId( @RequestParam Long userId)
    {
        SysUserRole one = sysUserRoleService.getOne(new LambdaQueryWrapper<SysUserRole>().eq(SysUserRole::getUserId, userId));
        if (Objects.isNull(one)) {
            return AjaxResult.success();
        }
        Long id =one.getRoleId();
        // 获取当前角色的菜单id
        List<Long> menusId = sysRoleMenuMapper.selectList(new LambdaQueryWrapper<SysRoleMenu>().eq(SysRoleMenu::getRoleId, id)).stream().map(SysRoleMenu::getMenuId).collect(Collectors.toList());
        if(menusId.size()==0){
            return AjaxResult.success(new ArrayList<>());
        }
        if(id!=1){
            menusId = menusId.stream().filter(e->e!=1074 && e!=1075 && e!=1193 && e!=1194).collect(Collectors.toList());
        }
        //获取当前的权限菜单
        List<SysMenus> all = menuMapper.getAllInIds(menusId);
        List<SysMenus> allUser = menuMapper.getAllInIds(menusId);
        // 查询所有权限菜单
        List<SysMenus> all = menuMapper.getAll();
        // 创建一个Map来存储all集合中的menuId
        Map<Long, Boolean> menuIdExistMap = allUser.stream()
                .collect(Collectors.toMap(SysMenus::getMenuId, aMenu -> true,
                        (oldValue, newValue) -> oldValue));
        // 遍历allUser集合,根据menuIdExistMap来设置isHave值
        for (SysMenus allMenu : all) {
            allMenu.setIsHave(menuIdExistMap.containsKey(allMenu.getMenuId()) ? 1 : 2);
        }
        // 第三级
        List<SysMenus> s3 = all.stream().filter(e -> e.getMenuType().equals("F")).collect(Collectors.toList());
        // 第二级
@@ -267,7 +285,7 @@
    @Log(title = "角色管理", businessType = BusinessType.DELETE)
    @ApiOperation("删除角色")
    @DeleteMapping("/{id}")
    @DeleteMapping("/del/{id}")
    public AjaxResult removeRole(
            @ApiParam(name = "id", value = "角色ID", required = true) @PathVariable Long id) {
        roleService.removeRole(id);