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;
}
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;
}
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;
}
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());
}
}
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;
}
Aggregations