【fix sonar】SysPermissionController文件
This commit is contained in:
+106
-121
@@ -22,6 +22,7 @@ import com.jero.modules.system.model.SysPermissionTree;
|
||||
import com.jero.modules.system.model.TreeModel;
|
||||
import com.jero.modules.system.service.*;
|
||||
import com.jero.modules.system.util.PermissionDataUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@@ -178,29 +179,6 @@ public class SysPermissionController {
|
||||
return Result.error("批量查询子菜单失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
// 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.error("查询失败:" + e.getMessage());
|
||||
// log.error(e.getMessage(), e);
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
|
||||
/**
|
||||
* 查询用户拥有的菜单权限和按钮权限
|
||||
@@ -228,7 +206,6 @@ public class SysPermissionController {
|
||||
LambdaQueryWrapper<SysPermission> query = new LambdaQueryWrapper<>();
|
||||
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);
|
||||
@@ -513,44 +490,45 @@ public class SysPermissionController {
|
||||
}
|
||||
String tempPid = permission.getParentId();
|
||||
JSONObject json = getPermissionJsonObject(permission);
|
||||
if(json==null) {
|
||||
continue;
|
||||
}
|
||||
if (parentJson == null && oConvertUtils.isEmpty(tempPid)) {
|
||||
jsonArray.add(json);
|
||||
if (!permission.isLeaf()) {
|
||||
getPermissionJsonArray(jsonArray, metaList, json);
|
||||
}
|
||||
} else if (parentJson != null && oConvertUtils.isNotEmpty(tempPid) && tempPid.equals(parentJson.getString("id"))) {
|
||||
// 类型( 0:一级菜单 1:子菜单 2:按钮 )
|
||||
if (permission.getMenuType().equals(CommonConstant.MENU_TYPE_2)) {
|
||||
JSONObject metaJson = parentJson.getJSONObject("meta");
|
||||
if (metaJson.containsKey(PERMISSION_LIST)) {
|
||||
metaJson.getJSONArray(PERMISSION_LIST).add(json);
|
||||
} else {
|
||||
JSONArray permissionList = new JSONArray();
|
||||
permissionList.add(json);
|
||||
metaJson.put(PERMISSION_LIST, permissionList);
|
||||
}
|
||||
// 类型( 0:一级菜单 1:子菜单 2:按钮 )
|
||||
} else if (permission.getMenuType().equals(CommonConstant.MENU_TYPE_1) || permission.getMenuType().equals(CommonConstant.MENU_TYPE_0)) {
|
||||
if (parentJson.containsKey(CHILDREN)) {
|
||||
parentJson.getJSONArray(CHILDREN).add(json);
|
||||
} else {
|
||||
JSONArray children = new JSONArray();
|
||||
children.add(json);
|
||||
parentJson.put(CHILDREN, children);
|
||||
}
|
||||
|
||||
if (!permission.isLeaf()) {
|
||||
getPermissionJsonArray(jsonArray, metaList, json);
|
||||
}
|
||||
}
|
||||
putParentJson(jsonArray, metaList, parentJson, permission, json);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void putParentJson(JSONArray jsonArray, List<SysPermission> metaList, JSONObject parentJson, SysPermission permission, JSONObject json) {
|
||||
// 类型( 0:一级菜单 1:子菜单 2:按钮 )
|
||||
if (permission.getMenuType().equals(CommonConstant.MENU_TYPE_2)) {
|
||||
JSONObject metaJson = parentJson.getJSONObject("meta");
|
||||
if (metaJson.containsKey(PERMISSION_LIST)) {
|
||||
metaJson.getJSONArray(PERMISSION_LIST).add(json);
|
||||
} else {
|
||||
JSONArray permissionList = new JSONArray();
|
||||
permissionList.add(json);
|
||||
metaJson.put(PERMISSION_LIST, permissionList);
|
||||
}
|
||||
// 类型( 0:一级菜单 1:子菜单 2:按钮 )
|
||||
} else if (permission.getMenuType().equals(CommonConstant.MENU_TYPE_1) || permission.getMenuType().equals(CommonConstant.MENU_TYPE_0)) {
|
||||
if (parentJson.containsKey(CHILDREN)) {
|
||||
parentJson.getJSONArray(CHILDREN).add(json);
|
||||
} else {
|
||||
JSONArray children = new JSONArray();
|
||||
children.add(json);
|
||||
parentJson.put(CHILDREN, children);
|
||||
}
|
||||
|
||||
if (!permission.isLeaf()) {
|
||||
getPermissionJsonArray(jsonArray, metaList, json);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据菜单配置生成路由json
|
||||
* @param permission
|
||||
@@ -560,86 +538,93 @@ public class SysPermissionController {
|
||||
JSONObject json = new JSONObject();
|
||||
// 类型(0:一级菜单 1:子菜单 2:按钮)
|
||||
if (permission.getMenuType().equals(CommonConstant.MENU_TYPE_2)) {
|
||||
//json.put("action", permission.getPerms());
|
||||
//json.put("type", permission.getPermsType());
|
||||
//json.put("describe", permission.getName());
|
||||
return new JSONObject();
|
||||
} else if (permission.getMenuType().equals(CommonConstant.MENU_TYPE_0) || permission.getMenuType().equals(CommonConstant.MENU_TYPE_1)) {
|
||||
json.put("id", permission.getId());
|
||||
if (permission.isRoute()) {
|
||||
json.put("route", "1");// 表示生成路由
|
||||
} else {
|
||||
json.put("route", "0");// 表示不生成路由
|
||||
}
|
||||
|
||||
if (isWWWHttpUrl(permission.getUrl())) {
|
||||
json.put("path", MD5Util.MD5Encode(permission.getUrl(), "utf-8"));
|
||||
} else {
|
||||
json.put("path", permission.getUrl());
|
||||
}
|
||||
|
||||
// 重要规则:路由name (通过URL生成路由name,路由name供前端开发,页面跳转使用)
|
||||
if (oConvertUtils.isNotEmpty(permission.getComponentName())) {
|
||||
json.put("name", permission.getComponentName());
|
||||
} else {
|
||||
json.put("name", urlToRouteName(permission.getUrl()));
|
||||
}
|
||||
|
||||
// 是否隐藏路由,默认都是显示的
|
||||
if (permission.isHidden()) {
|
||||
json.put("hidden", true);
|
||||
}
|
||||
// 聚合路由
|
||||
if (permission.isAlwaysShow()) {
|
||||
json.put("alwaysShow", true);
|
||||
}
|
||||
putJson(permission, json);
|
||||
json.put("component", permission.getComponent());
|
||||
JSONObject meta = new JSONObject();
|
||||
// 由用户设置是否缓存页面 用布尔值
|
||||
if (permission.isKeepAlive()) {
|
||||
meta.put("keepAlive", true);
|
||||
} else {
|
||||
meta.put("keepAlive", false);
|
||||
}
|
||||
|
||||
/*update_begin author:wuxianquan date:20190908 for:往菜单信息里添加外链菜单打开方式 */
|
||||
//外链菜单打开方式
|
||||
if (permission.isInternalOrExternal()) {
|
||||
meta.put("internalOrExternal", true);
|
||||
} else {
|
||||
meta.put("internalOrExternal", false);
|
||||
}
|
||||
/* update_end author:wuxianquan date:20190908 for: 往菜单信息里添加外链菜单打开方式*/
|
||||
|
||||
meta.put("title", permission.getName());
|
||||
|
||||
//update-begin--Author:scott Date:20201015 for:路由缓存问题,关闭了tab页时再打开就不刷新 #842
|
||||
String component = permission.getComponent();
|
||||
if(oConvertUtils.isNotEmpty(permission.getComponentName()) || oConvertUtils.isNotEmpty(component)){
|
||||
meta.put("componentName", oConvertUtils.getString(permission.getComponentName(),component.substring(component.lastIndexOf("/")+1)));
|
||||
}
|
||||
//update-end--Author:scott Date:20201015 for:路由缓存问题,关闭了tab页时再打开就不刷新 #842
|
||||
|
||||
if (oConvertUtils.isEmpty(permission.getParentId())) {
|
||||
// 一级菜单跳转地址
|
||||
json.put("redirect", permission.getRedirect());
|
||||
if (oConvertUtils.isNotEmpty(permission.getIcon())) {
|
||||
meta.put("icon", permission.getIcon());
|
||||
}
|
||||
} else {
|
||||
if (oConvertUtils.isNotEmpty(permission.getIcon())) {
|
||||
meta.put("icon", permission.getIcon());
|
||||
}
|
||||
}
|
||||
if (isWWWHttpUrl(permission.getUrl())) {
|
||||
meta.put("url", permission.getUrl());
|
||||
}
|
||||
JSONObject meta = putMeta(permission, json);
|
||||
json.put("meta", meta);
|
||||
}
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private JSONObject putMeta(SysPermission permission, JSONObject json) {
|
||||
JSONObject meta = new JSONObject();
|
||||
// 由用户设置是否缓存页面 用布尔值
|
||||
if (permission.isKeepAlive()) {
|
||||
meta.put("keepAlive", true);
|
||||
} else {
|
||||
meta.put("keepAlive", false);
|
||||
}
|
||||
|
||||
/*update_begin author:wuxianquan date:20190908 for:往菜单信息里添加外链菜单打开方式 */
|
||||
//外链菜单打开方式
|
||||
if (permission.isInternalOrExternal()) {
|
||||
meta.put("internalOrExternal", true);
|
||||
} else {
|
||||
meta.put("internalOrExternal", false);
|
||||
}
|
||||
/* update_end author:wuxianquan date:20190908 for: 往菜单信息里添加外链菜单打开方式*/
|
||||
|
||||
meta.put("title", permission.getName());
|
||||
|
||||
//update-begin--Author:scott Date:20201015 for:路由缓存问题,关闭了tab页时再打开就不刷新 #842
|
||||
String component = permission.getComponent();
|
||||
if(oConvertUtils.isNotEmpty(permission.getComponentName()) || oConvertUtils.isNotEmpty(component)){
|
||||
meta.put("componentName", oConvertUtils.getString(permission.getComponentName(),component.substring(component.lastIndexOf("/")+1)));
|
||||
}
|
||||
//update-end--Author:scott Date:20201015 for:路由缓存问题,关闭了tab页时再打开就不刷新 #842
|
||||
|
||||
if (oConvertUtils.isEmpty(permission.getParentId())) {
|
||||
// 一级菜单跳转地址
|
||||
json.put("redirect", permission.getRedirect());
|
||||
if (oConvertUtils.isNotEmpty(permission.getIcon())) {
|
||||
meta.put("icon", permission.getIcon());
|
||||
}
|
||||
} else {
|
||||
if (oConvertUtils.isNotEmpty(permission.getIcon())) {
|
||||
meta.put("icon", permission.getIcon());
|
||||
}
|
||||
}
|
||||
if (isWWWHttpUrl(permission.getUrl())) {
|
||||
meta.put("url", permission.getUrl());
|
||||
}
|
||||
return meta;
|
||||
}
|
||||
|
||||
private void putJson(SysPermission permission, JSONObject json) {
|
||||
if (permission.isRoute()) {
|
||||
json.put("route", "1");// 表示生成路由
|
||||
} else {
|
||||
json.put("route", "0");// 表示不生成路由
|
||||
}
|
||||
|
||||
if (isWWWHttpUrl(permission.getUrl())) {
|
||||
json.put("path", MD5Util.MD5Encode(permission.getUrl(), "utf-8"));
|
||||
} else {
|
||||
json.put("path", permission.getUrl());
|
||||
}
|
||||
|
||||
// 重要规则:路由name (通过URL生成路由name,路由name供前端开发,页面跳转使用)
|
||||
if (oConvertUtils.isNotEmpty(permission.getComponentName())) {
|
||||
json.put("name", permission.getComponentName());
|
||||
} else {
|
||||
json.put("name", urlToRouteName(permission.getUrl()));
|
||||
}
|
||||
|
||||
// 是否隐藏路由,默认都是显示的
|
||||
if (permission.isHidden()) {
|
||||
json.put("hidden", true);
|
||||
}
|
||||
// 聚合路由
|
||||
if (permission.isAlwaysShow()) {
|
||||
json.put("alwaysShow", true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否外网URL 例如: http://localhost:8080/jero-boot/swagger-ui.html#/ 支持特殊格式: {{
|
||||
* window._CONFIG['domianURL'] }}/druid/ {{ JS代码片段 }},前台解析会自动执行JS代码片段
|
||||
|
||||
Reference in New Issue
Block a user