Search in sources :

Example 71 with LambdaQueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project kms by mahonelau.

the class SysPermissionController method queryTreeList.

/**
 * 获取全部的权限树
 *
 * @return
 */
@RequestMapping(value = "/queryTreeList", method = RequestMethod.GET)
public Result<Map<String, Object>> queryTreeList() {
    Result<Map<String, Object>> result = new Result<>();
    // 全部权限ids
    List<String> ids = new ArrayList<>();
    try {
        LambdaQueryWrapper<SysPermission> query = new LambdaQueryWrapper<SysPermission>();
        query.eq(SysPermission::getDelFlag, CommonConstant.DEL_FLAG_0);
        query.orderByAsc(SysPermission::getSortNo);
        List<SysPermission> list = sysPermissionService.list(query);
        for (SysPermission sysPer : list) {
            ids.add(sysPer.getId());
        }
        List<TreeModel> treeList = new ArrayList<>();
        getTreeModelList(treeList, list, null);
        Map<String, Object> resMap = new HashMap<String, Object>();
        // 全部树节点数据
        resMap.put("treeList", treeList);
        // 全部树ids
        resMap.put("ids", ids);
        result.setResult(resMap);
        result.setSuccess(true);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
    return result;
}
Also used : Result(org.jeecg.common.api.vo.Result) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) TreeModel(org.jeecg.modules.system.model.TreeModel) SysPermission(org.jeecg.modules.system.entity.SysPermission) JSONObject(com.alibaba.fastjson.JSONObject)

Example 72 with LambdaQueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project kms by mahonelau.

the class SysPermissionController method getUserPermissionByToken.

// update_end author:sunjianlei date:20200108 for: 新增批量根据父ID查询子级菜单的接口 -------------
// /**
// * 查询用户拥有的菜单权限和按钮权限(根据用户账号)
// *
// * @return
// */
// @RequestMapping(value = "/queryByUser", method = RequestMethod.GET)
// public Result<JSONArray> queryByUser(HttpServletRequest req) {
// Result<JSONArray> result = new Result<>();
// try {
// String username = req.getParameter("username");
// List<SysPermission> metaList = sysPermissionService.queryByUser(username);
// JSONArray jsonArray = new JSONArray();
// this.getPermissionJsonArray(jsonArray, metaList, null);
// result.setResult(jsonArray);
// result.success("查询成功");
// } catch (Exception e) {
// result.error500("查询失败:" + e.getMessage());
// log.error(e.getMessage(), e);
// }
// return result;
// }
/**
 * 查询用户拥有的菜单权限和按钮权限
 *
 * @return
 */
@RequestMapping(value = "/getUserPermissionByToken", method = RequestMethod.GET)
public Result<?> getUserPermissionByToken() {
    Result<JSONObject> result = new Result<JSONObject>();
    try {
        // 直接获取当前用户不适用前端token
        LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        if (oConvertUtils.isEmpty(loginUser)) {
            return Result.error("请登录系统!");
        }
        List<SysPermission> metaList = new ArrayList<>();
        // 改为从数据库读取角色数据queryByUser
        metaList = sysPermissionService.queryByUser(loginUser.getUsername());
        // update-begin-author:taoyan date:20200211 for: TASK #3368 【路由缓存】首页的缓存设置有问题,需要根据后台的路由配置来实现是否缓存
        if (!PermissionDataUtil.hasIndexPage(metaList)) {
            SysPermission indexMenu = sysPermissionService.list(new LambdaQueryWrapper<SysPermission>().eq(SysPermission::getName, "首页")).get(0);
            metaList.add(0, indexMenu);
        }
        // update-end-author:taoyan date:20200211 for: TASK #3368 【路由缓存】首页的缓存设置有问题,需要根据后台的路由配置来实现是否缓存
        JSONObject json = new JSONObject();
        JSONArray menujsonArray = new JSONArray();
        this.getPermissionJsonArray(menujsonArray, metaList, null);
        JSONArray authjsonArray = new JSONArray();
        this.getAuthJsonArray(authjsonArray, metaList);
        // 查询所有的权限
        LambdaQueryWrapper<SysPermission> query = new LambdaQueryWrapper<SysPermission>();
        query.eq(SysPermission::getDelFlag, CommonConstant.DEL_FLAG_0);
        query.eq(SysPermission::getMenuType, CommonConstant.MENU_TYPE_2);
        // query.eq(SysPermission::getStatus, "1");
        List<SysPermission> allAuthList = sysPermissionService.list(query);
        JSONArray allauthjsonArray = new JSONArray();
        this.getAllAuthJsonArray(allauthjsonArray, allAuthList);
        // 路由菜单
        json.put("menu", menujsonArray);
        // 按钮权限(用户拥有的权限集合)
        json.put("auth", authjsonArray);
        // 全部权限配置集合(按钮权限,访问权限)
        json.put("allAuth", allauthjsonArray);
        result.setResult(json);
        result.success("查询成功");
    } catch (Exception e) {
        result.error500("查询失败:" + e.getMessage());
        log.error(e.getMessage(), e);
    }
    return result;
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) JSONArray(com.alibaba.fastjson.JSONArray) SysPermission(org.jeecg.modules.system.entity.SysPermission) LoginUser(org.jeecg.common.system.vo.LoginUser) Result(org.jeecg.common.api.vo.Result) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Example 73 with LambdaQueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project kms by mahonelau.

the class SysPermissionController method getSystemSubmenu.

/**
 * 查询子菜单
 * @param parentId
 * @return
 */
@RequestMapping(value = "/getSystemSubmenu", method = RequestMethod.GET)
public Result<List<SysPermissionTree>> getSystemSubmenu(@RequestParam("parentId") String parentId) {
    Result<List<SysPermissionTree>> result = new Result<>();
    try {
        LambdaQueryWrapper<SysPermission> query = new LambdaQueryWrapper<SysPermission>();
        query.eq(SysPermission::getParentId, parentId);
        query.eq(SysPermission::getDelFlag, CommonConstant.DEL_FLAG_0);
        query.orderByAsc(SysPermission::getSortNo);
        List<SysPermission> list = sysPermissionService.list(query);
        List<SysPermissionTree> sysPermissionTreeList = new ArrayList<SysPermissionTree>();
        for (SysPermission sysPermission : list) {
            SysPermissionTree sysPermissionTree = new SysPermissionTree(sysPermission);
            sysPermissionTreeList.add(sysPermissionTree);
        }
        result.setResult(sysPermissionTreeList);
        result.setSuccess(true);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
    return result;
}
Also used : SysPermission(org.jeecg.modules.system.entity.SysPermission) SysPermissionTree(org.jeecg.modules.system.model.SysPermissionTree) Result(org.jeecg.common.api.vo.Result) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Example 74 with LambdaQueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project kms by mahonelau.

the class SysPermissionController method getSystemSubmenuBatch.

/*update_end author:wuxianquan date:20190908 for:先查询一级菜单,当用户点击展开菜单时加载子菜单 */
// update_begin author:sunjianlei date:20200108 for: 新增批量根据父ID查询子级菜单的接口 -------------
/**
 * 查询子菜单
 *
 * @param parentIds 父ID(多个采用半角逗号分割)
 * @return 返回 key-value 的 Map
 */
@GetMapping("/getSystemSubmenuBatch")
public Result getSystemSubmenuBatch(@RequestParam("parentIds") String parentIds) {
    try {
        LambdaQueryWrapper<SysPermission> query = new LambdaQueryWrapper<>();
        List<String> parentIdList = Arrays.asList(parentIds.split(","));
        query.in(SysPermission::getParentId, parentIdList);
        query.eq(SysPermission::getDelFlag, CommonConstant.DEL_FLAG_0);
        query.orderByAsc(SysPermission::getSortNo);
        List<SysPermission> list = sysPermissionService.list(query);
        Map<String, List<SysPermissionTree>> listMap = new HashMap<>();
        for (SysPermission item : list) {
            String pid = item.getParentId();
            if (parentIdList.contains(pid)) {
                List<SysPermissionTree> mapList = listMap.get(pid);
                if (mapList == null) {
                    mapList = new ArrayList<>();
                }
                mapList.add(new SysPermissionTree(item));
                listMap.put(pid, mapList);
            }
        }
        return Result.ok(listMap);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        return Result.error("批量查询子菜单失败:" + e.getMessage());
    }
}
Also used : LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) SysPermission(org.jeecg.modules.system.entity.SysPermission) SysPermissionTree(org.jeecg.modules.system.model.SysPermissionTree)

Example 75 with LambdaQueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project kms by mahonelau.

the class SysRoleController method queryTreeList.

/**
 * 用户角色授权功能,查询菜单权限树
 * @param request
 * @return
 */
@RequestMapping(value = "/queryTreeList", method = RequestMethod.GET)
public Result<Map<String, Object>> queryTreeList(HttpServletRequest request) {
    Result<Map<String, Object>> result = new Result<>();
    // 全部权限ids
    List<String> ids = new ArrayList<>();
    try {
        LambdaQueryWrapper<SysPermission> query = new LambdaQueryWrapper<SysPermission>();
        query.eq(SysPermission::getDelFlag, CommonConstant.DEL_FLAG_0);
        query.orderByAsc(SysPermission::getSortNo);
        List<SysPermission> list = sysPermissionService.list(query);
        for (SysPermission sysPer : list) {
            ids.add(sysPer.getId());
        }
        List<TreeModel> treeList = new ArrayList<>();
        getTreeModelList(treeList, list, null);
        Map<String, Object> resMap = new HashMap<String, Object>();
        // 全部树节点数据
        resMap.put("treeList", treeList);
        // 全部树ids
        resMap.put("ids", ids);
        result.setResult(resMap);
        result.setSuccess(true);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
    return result;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Result(org.jeecg.common.api.vo.Result) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) TreeModel(org.jeecg.modules.system.model.TreeModel) SysPermission(org.jeecg.modules.system.entity.SysPermission) JSONObject(com.alibaba.fastjson.JSONObject) Map(java.util.Map) HashMap(java.util.HashMap) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)381 Transactional (org.springframework.transaction.annotation.Transactional)60 JSONObject (com.alibaba.fastjson.JSONObject)52 Result (org.jeecg.common.api.vo.Result)50 ArrayList (java.util.ArrayList)42 List (java.util.List)30 Map (java.util.Map)29 Collectors (java.util.stream.Collectors)26 Service (org.springframework.stereotype.Service)24 LoginUser (org.jeecg.common.system.vo.LoginUser)22 SysPermission (org.jeecg.modules.system.entity.SysPermission)22 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)22 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)21 IPage (com.baomidou.mybatisplus.core.metadata.IPage)20 HashMap (java.util.HashMap)20 SysUser (org.jeecg.modules.system.entity.SysUser)20 ApiOperation (io.swagger.annotations.ApiOperation)19 ServiceException (cn.lili.common.exception.ServiceException)18 ServiceImpl (com.baomidou.mybatisplus.extension.service.impl.ServiceImpl)18 Autowired (org.springframework.beans.factory.annotation.Autowired)18