提交 58f417d1 编写于 作者: laizhilong's avatar laizhilong

添加统一资源树,并给应用菜单添加根节点‘系统’

上级 ba57e004
......@@ -3,11 +3,11 @@
<card class='view-card view-no-caption view-no-toolbar' :dis-hover="true" :padding="0" :bordered="false">
<div class="content-container pickup-view">
<div class="translate-contant">
<!--菜单分配-->
<div class="center" :style="{width : '50%',border:'0px solid red' }">
<!--应用菜单-->
<div class="center" :style="{width : '33%',border:'0px solid red' }">
<context-menu-container class='design-tree-container' >
<div >
<div class="text">菜单分配</div>
<div class="text">应用菜单</div>
<div class="roll">
<el-tree
class="tre"
......@@ -25,11 +25,11 @@
</div>
</context-menu-container>
</div>
<!--权限分配-->
<div class="center" :style="{width : '50%',border:'0px solid red' }">
<!--数据能力-->
<div class="center" :style="{width : '33%',border:'0px solid red' }">
<context-menu-container class='design-tree-container' >
<div >
<div class="text">权限分配</div>
<div class="text">数据能力</div>
<div class="roll">
<el-tree
class="tre"
......@@ -47,6 +47,28 @@
</div>
</context-menu-container>
</div>
<!--统一资源-->
<div class="center" :style="{width : '33%',border:'0px solid red' }">
<context-menu-container class='design-tree-container' >
<div >
<div class="text">统一资源</div>
<div class="roll">
<el-tree
class="tre"
:data="this.ZYdata"
ref="ZYtree"
show-checkbox
node-key="id"
:default-expanded-keys="this.ZYdataexpandedKeys"
highlight-current
:props="this.defaultProps"
@check-change="handleCheckChange"
>
</el-tree>
</div>
</div>
</context-menu-container>
</div>
</div>
<div>
<!--操作按钮-->
......@@ -84,14 +106,19 @@
export default class SYS_PERMISSIONMPickupView extends Vue{
/*菜单分配数据*/
/*应用菜单数据*/
protected CDdata: any = [];
/*菜单分配数据默认展开节点*/
/*应用菜单数据默认展开节点*/
protected CDdataexpandedKeys:any =[];
/*权限分配数据*/
/*数据能力数据*/
protected QXdata: any = [];
/*权限分配数据默认展开节点*/
/*数据能力数据默认展开节点*/
protected QXdataexpandedKeys:any =[];
/*统一资源数据*/
protected ZYdata: any = [];
/*统一资源数据默认展开节点*/
protected ZYdataexpandedKeys:any =[];
/**
* 树显示说明:子树为节点对象的children,节点标签为节点对象的label
*/
......@@ -146,7 +173,7 @@
private initTree(){
const _this = this;
// get全部菜单和权限的请求路径
const url = `sys_permissions/getallMenuAndPermission`;
const url = `sys_permissions/getallMenuAndPermissionAndUnires`;
this.$http.get(url).then((response: any)=>{
if (!response || response.status !== 200) {
this.$Notice.error({ title: '错误', desc: response.message });
......@@ -155,7 +182,7 @@
// 给树赋值,数据结构在后台已经按照eltree格式化
_this.CDdata = response.data[0];
_this.QXdata = response.data[1];
console.log(this.CDdata)
_this.ZYdata = response.data[2];
// 树视图默认展开一级节点
if (_this.CDdata && _this.CDdata.length>0){
_this.CDdata.forEach((item:any, index:any)=> {
......@@ -171,6 +198,13 @@
}
})
}
if (_this.ZYdata && _this.ZYdata.length>0){
_this.ZYdata.forEach((item:any, index:any)=> {
if (item[index].id){
_this.ZYdataexpandedKeys.push(item[index]);
}
})
}
}
}).catch((e) => {
console.log(e);
......@@ -181,14 +215,15 @@
* 处理选中节点
*/
protected handleCheckChange() {
console.log("SYS_PERMISSIONMPickupView执行了handleCheckChange")
// console.log("SYS_PERMISSIONMPickupView执行了handleCheckChange")
// 两棵树
const CDtree: any = this.$refs.CDtree;
const QXtree: any = this.$refs.QXtree;
const ZYtree: any = this.$refs.ZYtree;
// 获取选中状态的节点
const arr = CDtree.getCheckedNodes().concat(QXtree.getCheckedNodes());
const arr = CDtree.getCheckedNodes().concat(QXtree.getCheckedNodes()).concat(ZYtree.getCheckedNodes());
this.selectData = arr;
// console.log("选中的node:" + arr);
// console.log("选中的node:" + JSON.stringify(this.selectData));
}
/**
......@@ -208,7 +243,7 @@
this.selectData.forEach((item: any) => {
let _itemTemp: any = JSON.parse(JSON.stringify(item));
let _item:any = {};
if (_itemTemp.sys_permissionId) {// 一级菜单
if (_itemTemp.sys_permissionId) {// 应用菜单
_item.srfdataaccaction = _itemTemp.sys_permissionId;
_item.srfkey = _itemTemp.sys_permissionId;
_item.sys_permission = _itemTemp.sys_permissionId;
......@@ -218,7 +253,7 @@
Object.assign(_item, { _select: false })
this.viewSelections.push(_item);
}else{
if(!_itemTemp.children){// 是末节点则为库中存在的权限数据,添加到viewSelections
if(!_itemTemp.children){// 数据能力或者统一资源
_item.srfdataaccaction = _itemTemp.id;
_item.srfkey = _itemTemp.id;
_item.sys_permission = _itemTemp.id;
......
......@@ -23,15 +23,15 @@ public class UAACoreService {
private ISYS_PERMISSIONService isys_permissionService;
@Autowired
private ISYS_PSAPPMENUITEMService isys_psappmenuitemService;
/**
* 获取用户菜单
* 获取应用菜单
*
* @return
*/
public JSONArray getAppMenu() {
// 用户所在系统id,R7的AuthenticationUser中已经没有systemid了
// String systemid= AuthenticationUser.getAuthenticationUser().getSystemid();
String systemid = null;
StringBuilder nPermissionSQL = new StringBuilder();
nPermissionSQL.append("SELECT ");
......@@ -48,34 +48,31 @@ public class UAACoreService {
nPermissionSQL.append(" t1.PSSYSTEMID as systemid ");
nPermissionSQL.append(" FROM IBZPERMISSION t");
nPermissionSQL.append(" INNER JOIN IBZPSAPPMENUITEM t1 ON t.SYS_PERMISSIONID = t1.SYS_PSAPPMENUITEMID and t.enable =1");
List<JSONObject> permissions = isys_psappmenuitemService.select(nPermissionSQL.toString(), null);
// 清空sql,获取应用菜单所处系统
nPermissionSQL.delete(0, nPermissionSQL.length());
nPermissionSQL.append("select temp.systemid from ( ");
nPermissionSQL.append(" SELECT ");
nPermissionSQL.append(" t.SYS_PERMISSIONID as sys_permissionid, ");
nPermissionSQL.append(" t.SYS_PERMISSIONNAME as sys_permissionname, ");
// nPermissionSQL.append(" t1.PERMISSIONID as permissionid, ");
nPermissionSQL.append(" t1.PSAPPMENUITEMID as permissionid, ");
// nPermissionSQL.append(" t1.P_PERMISSIONID as p_permissionid, ");
nPermissionSQL.append(" t1.PSAPPPMENUITEMID as p_permissionid, ");
nPermissionSQL.append(" t1.PSAPPID as psappid, ");
nPermissionSQL.append(" t1.PSAPPNAME as psappname, ");
nPermissionSQL.append(" t1.PSAPPMENUID as psappmenuid, ");
nPermissionSQL.append(" t1.PSAPPMENUNAME as psappmenuname, ");
nPermissionSQL.append(" t1.PSSYSTEMID as systemid ");
nPermissionSQL.append(" FROM IBZPERMISSION t INNER JOIN IBZPSAPPMENUITEM t1 ON t.SYS_PERMISSIONID = t1.SYS_PSAPPMENUITEMID and t.enable =1");
nPermissionSQL.append(" )temp group by temp.systemid");
List<JSONObject> systems = isys_psappmenuitemService.select(nPermissionSQL.toString(), null);
StringBuilder permissionSQL = new StringBuilder();
permissionSQL.append("SELECT ");
permissionSQL.append(" t.SYS_PERMISSIONID as sys_permissionid,");
permissionSQL.append(" t.SYS_PERMISSIONNAME as sys_permissionname,");
// permissionSQL.append(" t1.PERMISSIONID as permissionid, ");
permissionSQL.append(" t1.PSAPPMENUITEMID as psappmenuitemid, ");
// permissionSQL.append(" t1.P_PERMISSIONID as p_permissionid, ");
permissionSQL.append(" t1.PSAPPPMENUITEMID as psapppmenuitemid, ");
permissionSQL.append(" t1.PSAPPID as psappid,");
permissionSQL.append(" t1.PSAPPNAME as psappname,");
permissionSQL.append(" t1.PSAPPMENUID as psappmenuid,");
permissionSQL.append(" t1.PSAPPMENUNAME as psappmenuname,");
permissionSQL.append(" t1.PSSYSTEMID as systemid");
permissionSQL.append(" FROM IBZPERMISSION t");
permissionSQL.append(" INNER JOIN IBZPSAPPMENUITEM t1 ON t.SYS_PERMISSIONID = t1.SYS_PSAPPMENUITEMID and t.systemid='" + systemid + "' and t.enable =1");
List<JSONObject> permissions;
if (StringUtils.isEmpty(systemid)) {
permissions = isys_psappmenuitemService.select(nPermissionSQL.toString(),null);
} else {
permissions = isys_psappmenuitemService.select(permissionSQL.toString(),null);
}
JSONArray treeNode = new JSONArray();
if (permissions.size() > 0) {
treeNode = this.transferAppMenuToELTree(permissions);
if (permissions.size() > 0 && systems.size() > 0) {
treeNode = this.transferAppMenuToELTree(permissions, systems);
}
return treeNode;
......@@ -84,13 +81,14 @@ public class UAACoreService {
/**
* 用于将资源表中菜单数据转换成饿了么树格式数据
*
* @param
* @param permissions
* @param systems
* @return
*/
private JSONArray transferAppMenuToELTree(List<JSONObject> appMenuDatas) {
private JSONArray transferAppMenuToELTree(List<JSONObject> permissions, List<JSONObject> systems) {
Map<String, String> appKeyMap = new HashMap<>();
Map<String, String> appMenuKeyMap = new HashMap<>();
JSONObject groupByMenuObj = this.groupByAppMenu(appMenuDatas, appKeyMap, appMenuKeyMap);//将数据库数据进行分组
JSONObject groupByMenuObj = this.groupByAppMenu(permissions, systems, appKeyMap, appMenuKeyMap);//将数据库数据进行分组
JSONArray elTreeObj = transferAppMenuToELTree(groupByMenuObj, appKeyMap, appMenuKeyMap);//将分组后的数据转换成饿了么树格式数据
return elTreeObj;
}
......@@ -98,62 +96,86 @@ public class UAACoreService {
/**
* 将数据库中的菜单数据进行分组
*
* @param dbdata
* @param permissions
* @param systems
* @param appKeyMap
* @param appMenuKeyMap
* @return
*/
private JSONObject groupByAppMenu(List<JSONObject> dbdata, Map<String, String> appKeyMap, Map<String, String> appMenuKeyMap) {
JSONObject permission_app = new JSONObject(); //顶级模块数据
for (JSONObject obj : dbdata) {
String str_app = String.format("IBIZAPP-%s", obj.get("psappid"));
String str_appName = String.format("%s", obj.get("psappname"));
String str_appMenu = String.format("IBIZMENU-%s", obj.get("psappmenuid"));
String str_appMenuName = String.format("%s", obj.get("psappmenuname"));
String systemId = String.format("%s", obj.get("systemid"));
// String sys_permissionId = DigestUtils.md5DigestAsHex(String.format("%s%s", systemId, obj.get("permissionid")).getBytes());
String permissionId = String.format("%s", obj.get("permissionid"));
String sys_permissionId = String.format("%s", obj.get("sys_permissionid"));
String p_sys_permissionId = "";
if (!StringUtils.isEmpty(obj.get("p_permissionid"))) {
// p_sys_permissionId = DigestUtils.md5DigestAsHex(String.format("%s%s", systemId, obj.get("p_permissionid")).getBytes());
p_sys_permissionId = String.format("%s",obj.get("p_permissionid"));
}
private JSONObject groupByAppMenu(List<JSONObject> permissions, List<JSONObject> systems, Map<String, String> appKeyMap, Map<String, String> appMenuKeyMap) {
JSONObject permission_system = new JSONObject(); //顶级系统数据
for (JSONObject system : systems) {
String systemid = system.getString("systemid");
JSONObject permission_app = new JSONObject(); //次级应用数据
for (JSONObject obj : permissions) {
String str_app = String.format("IBIZAPP-%s", obj.get("psappid"));
String str_appName = String.format("%s", obj.get("psappname"));
String str_appMenu = String.format("IBIZMENU-%s", obj.get("psappmenuid"));
String str_appMenuName = String.format("%s", obj.get("psappmenuname"));
String str_systemid = String.format("%s", obj.get("systemid"));
// String sys_permissionId = DigestUtils.md5DigestAsHex(String.format("%s%s", systemId, obj.get("permissionid")).getBytes());
String permissionId = String.format("%s", obj.get("permissionid"));
String sys_permissionId = String.format("%s", obj.get("sys_permissionid"));
String p_sys_permissionId = "";
if (!StringUtils.isEmpty(obj.get("p_permissionid"))) {
// p_sys_permissionId = DigestUtils.md5DigestAsHex(String.format("%s%s", systemId, obj.get("p_permissionid")).getBytes());
p_sys_permissionId = String.format("%s", obj.get("p_permissionid"));
}
// 根据systemid进行操作
if (systemid.equals(str_systemid)) {
JSONObject cur_system = new JSONObject();
JSONObject cur_app = new JSONObject();
JSONArray cur_app_menu = new JSONArray();
if (permission_system.containsKey(str_systemid))// 系统合并
cur_system = permission_system.getJSONObject(str_systemid);
JSONObject cur_app = new JSONObject();
JSONArray cur_app_menu = new JSONArray();
if (permission_app.containsKey(str_app))//合并前端应用
cur_app = permission_app.getJSONObject(str_app);
if (permission_app.containsKey(str_app))//合并前端应用
cur_app = permission_app.getJSONObject(str_app);
if (cur_app.containsKey(str_appMenu))//合并菜单
cur_app_menu = cur_app.getJSONArray(str_appMenu);
if (cur_app.containsKey(str_appMenu))//合并菜单
cur_app_menu = cur_app.getJSONArray(str_appMenu);
JSONObject permission = new JSONObject();
permission.put("id", permissionId);
permission.put("sys_permissionId", sys_permissionId);
permission.put("pid", p_sys_permissionId);
permission.put("label", obj.get("sys_permissionname"));
JSONObject permission = new JSONObject();
permission.put("id", permissionId);
permission.put("sys_permissionId", sys_permissionId);
permission.put("pid", p_sys_permissionId);
permission.put("label", obj.get("sys_permissionname"));
cur_app_menu.add(permission);
cur_app.put(str_appMenu, cur_app_menu);
cur_system.put(str_app, cur_app);
cur_app_menu.add(permission);
cur_app.put(str_appMenu, cur_app_menu);
permission_app.put(str_app, cur_app);
permission_app.put(str_app, cur_app);
permission_system.put(str_systemid, cur_system);
//应用名称映射表
if (!appKeyMap.containsKey(str_app))
appKeyMap.put(str_app, str_appName);
// 构造树节点名称集合
if (!appKeyMap.containsKey(str_systemid)) {// 系统
appKeyMap.put(str_systemid, str_systemid);
}
if (!appKeyMap.containsKey(str_app)) {// 应用
appKeyMap.put(str_app, str_appName);
}
if (!appMenuKeyMap.containsKey(str_appMenu)) {// 应用菜单
appMenuKeyMap.put(str_appMenu, str_appMenuName);
}
//应用菜单名称映射表
if (!appMenuKeyMap.containsKey(str_appMenu))
appMenuKeyMap.put(str_appMenu, str_appMenuName);
}
}
}
return permission_app;
// return permission_app;
return permission_system;
}
/**
* 将以分组的树节点转换成饿了么格式的树
* 格式为:系统->应用->应用菜单->菜单项
*
* @param sysApps
* @return
......@@ -231,8 +253,9 @@ public class UAACoreService {
return key;
}
/**
* 获取数据操作标识
* 获取数据能力
*
* @return
*/
......@@ -251,12 +274,11 @@ public class UAACoreService {
permissionsSql.append(" t1.PSDEDATARANGEID as psdedatarangeid, ");
permissionsSql.append(" t1.PSDEDATARANGENAME as psdedatarangename,");
permissionsSql.append(" t1.PSSYSTEMID as systemid ");
permissionsSql.append(" FROM IBZPERMISSION t");
permissionsSql.append(" INNER JOIN IBZPSDEOPPRIV t1 ON t.SYS_PERMISSIONID = t1.SYS_PSDEOPPRIVID");
List<JSONObject> permissions = isys_permissionService.select(permissionsSql.toString(),null);
permissionsSql.append(" FROM IBZPERMISSION t INNER JOIN IBZPSDEOPPRIV t1 ON t.SYS_PERMISSIONID = t1.SYS_PSDEOPPRIVID and t.enable=1");
List<JSONObject> permissions = isys_permissionService.select(permissionsSql.toString(), null);
// 清空sql,获取权限所处系统
permissionsSql.delete(0,permissionsSql.length());
// 清空sql,获取数据能力所处系统
permissionsSql.delete(0, permissionsSql.length());
permissionsSql.append("select temp.systemid from ( ");
permissionsSql.append(" select ");
permissionsSql.append(" t.SYS_PERMISSIONID as sys_permissionid, ");
......@@ -270,13 +292,12 @@ public class UAACoreService {
permissionsSql.append(" t1.PSDEDATARANGEID as psdedatarangeid, ");
permissionsSql.append(" t1.PSDEDATARANGENAME as psdedatarangename,");
permissionsSql.append(" t1.PSSYSTEMID as systemid ");
permissionsSql.append(" FROM IBZPERMISSION t");
permissionsSql.append(" INNER JOIN IBZPSDEOPPRIV t1 ON t.SYS_PERMISSIONID = t1.SYS_PSDEOPPRIVID");
permissionsSql.append(" )temp group by temp.SYSTEMID");
List<JSONObject> systems = isys_permissionService.select(permissionsSql.toString(),null);
permissionsSql.append(" FROM IBZPERMISSION t INNER JOIN IBZPSDEOPPRIV t1 ON t.SYS_PERMISSIONID = t1.SYS_PSDEOPPRIVID and t.enable=1");
permissionsSql.append(" )temp group by temp.systemid");
List<JSONObject> systems = isys_permissionService.select(permissionsSql.toString(), null);
if (permissions.size() > 0) {
treeNode = this.transferDataCapabilityToELTree(permissions,systems);
if (permissions.size() > 0 && systems.size() > 0) {
treeNode = this.transferDataCapabilityToELTree(permissions, systems);
}
return treeNode;
......@@ -286,30 +307,31 @@ public class UAACoreService {
/**
* 用于将资源表中数据能力数据转换成饿了么树格式数据
*
* @param deCapabilityDatas
* @param permissions
* @param systems
* @return
*/
public JSONArray transferDataCapabilityToELTree(List<JSONObject> deCapabilityDatas,List<JSONObject> systems) {
public JSONArray transferDataCapabilityToELTree(List<JSONObject> permissions, List<JSONObject> systems) {
Map<String, String> opprivTreeNameMap = new HashMap<>();
JSONObject groupByMenuObj = groupByDataCapability(deCapabilityDatas, systems, opprivTreeNameMap);//将数据库数据进行分组
JSONObject groupByMenuObj = groupByDataCapability(permissions, systems, opprivTreeNameMap);//将数据库数据进行分组
JSONArray elTreeObj = transferDataCapabilityToELTree(groupByMenuObj, opprivTreeNameMap);//将分组后的数据转换成饿了么树格式数据
return elTreeObj;
}
/**
* 将数据库中的数据能力数据进行分组
* 格式为:系统-模块-实体-数据集/实体行为-数据能力
* @param deCapabilityDatas
* 格式为:系统->模块->实体->数据集/实体行为->数据能力
*
* @param permissions
* @param systems
* @return
*/
private JSONObject groupByDataCapability(List<JSONObject> deCapabilityDatas, List<JSONObject> systems, Map<String, String> opprivTreeNameMap) {
private JSONObject groupByDataCapability(List<JSONObject> permissions, List<JSONObject> systems, Map<String, String> opprivTreeNameMap) {
JSONObject permission_system = new JSONObject(); //顶级系统数据
for (JSONObject system : systems) {
String systemid = system.getString("systemid");
JSONObject permission_moudle = new JSONObject(); //次级模块数据
for (JSONObject obj : deCapabilityDatas) {
for (JSONObject obj : permissions) {
JSONObject jobj = new JSONObject();
jobj.putAll(obj);
......@@ -320,19 +342,19 @@ public class UAACoreService {
String str_entity_name = jobj.getString("psdataentityname");// 实体名称
String str_dataset = jobj.getString("pssourceid");// 数据集,实体行为标识
String str_dataset_name = jobj.getString("pssourcename");// 数据集,实体行为名称
String str_datarange = jobj.getString("psdedatarangeid");// 实体数据范围标识
String str_datarange_name = jobj.getString("psdedatarangename");// 实体数据范围名称
// String str_datarange = jobj.getString("psdedatarangeid");// 实体数据范围标识
// String str_datarange_name = jobj.getString("psdedatarangename");// 实体数据范围名称
String str_permissionid = jobj.getString("sys_permissionid");// 实体数据操作名称
String str_permissionname = jobj.getString("sys_permissionname");// 实体数据操作标识
// 根据systemid进行操作
if (systemid.equals(str_systemid)){
if (systemid.equals(str_systemid)) {
JSONObject cur_system = new JSONObject();
JSONObject cur_moudle = new JSONObject();
JSONObject cur_entity = new JSONObject();
// JSONObject cur_dataset = new JSONObject();
// JSONObject cur_dataset = new JSONObject();
JSONArray cur_dataset = new JSONArray();
JSONArray cur_data_range = new JSONArray();
// JSONArray cur_data_range = new JSONArray();
if (permission_system.containsKey(str_systemid))// 系统合并
cur_system = permission_system.getJSONObject(str_systemid);
......@@ -346,23 +368,22 @@ public class UAACoreService {
if (cur_entity.containsKey(str_dataset))//数据集,实体行为合并
cur_dataset = cur_entity.getJSONArray(str_dataset);
// if (cur_dataset.containsKey(str_datarange))//数据范围合并
// cur_data_range = cur_dataset.getJSONArray(str_datarange);
// if (cur_dataset.containsKey(str_datarange))//数据范围合并
// cur_data_range = cur_dataset.getJSONArray(str_datarange);
JSONObject permission = new JSONObject();
permission.put("id", str_permissionid);
permission.put("label", str_permissionname);
// cur_data_range.add(permission);
// cur_dataset.put(str_datarange, cur_data_range);
// cur_data_range.add(permission);
//
// cur_dataset.put(str_datarange, cur_data_range);
cur_dataset.add(permission);
cur_entity.put(str_dataset, cur_dataset);
cur_moudle.put(str_entity, cur_entity);
cur_system.put(str_moudle,cur_moudle);
cur_system.put(str_moudle, cur_moudle);
permission_moudle.put(str_moudle, cur_moudle);
permission_system.put(str_systemid,cur_system);
permission_system.put(str_systemid, cur_system);
//构造树节点名称集合
if (!opprivTreeNameMap.containsKey(str_systemid)) {// 系统
......@@ -374,12 +395,14 @@ public class UAACoreService {
if (!opprivTreeNameMap.containsKey(str_entity)) {// 实体
opprivTreeNameMap.put(str_entity, str_entity_name);
}
if (!opprivTreeNameMap.containsKey(str_dataset)) {// 数据集实体行为
if (!opprivTreeNameMap.containsKey(str_dataset)) {// 数据集,实体行为
opprivTreeNameMap.put(str_dataset, str_dataset_name);
}
// if (!opprivTreeNameMap.containsKey(str_datarange_name)) {// 数据范围
// opprivTreeNameMap.put(str_datarange, str_datarange_name);
// }
}
}
......@@ -431,4 +454,157 @@ public class UAACoreService {
return array;
}
/**
* 获取统一资源
*
* @return
*/
public JSONArray getUnires() {
JSONArray treeNode = new JSONArray();
StringBuilder permissionsSql = new StringBuilder();
permissionsSql.append("select ");
permissionsSql.append(" t.SYS_PERMISSIONID as sys_permissionid, ");
permissionsSql.append(" t.SYS_PERMISSIONNAME as sys_permissionname, ");
permissionsSql.append(" t1.SYS_PSSYSUNIRESID as uniresid, ");
permissionsSql.append(" t1.SYS_PSSYSUNIRESNAME as uniresname, ");
permissionsSql.append(" t1.UNIRESCODE as unirescode,");
permissionsSql.append(" t.SYSTEMID as systemid ");
permissionsSql.append(" FROM ibzpermission t INNER JOIN IBZPSSYSUNIRES t1 ON t.SYS_PERMISSIONID = t1.SYS_PSSYSUNIRESID and t.enable=1");
List<JSONObject> permissions = isys_permissionService.select(permissionsSql.toString(), null);
// 清空sql,获取统一资源所处系统
permissionsSql.delete(0, permissionsSql.length());
permissionsSql.append("select temp.systemid from ( ");
permissionsSql.append(" select ");
permissionsSql.append(" t.SYS_PERMISSIONID as sys_permissionid, ");
permissionsSql.append(" t.SYS_PERMISSIONNAME as sys_permissionname, ");
permissionsSql.append(" t1.SYS_PSSYSUNIRESID as uniresid, ");
permissionsSql.append(" t1.SYS_PSSYSUNIRESNAME as uniresname, ");
permissionsSql.append(" t1.UNIRESCODE as unirescode, ");
permissionsSql.append(" t.SYSTEMID as systemid ");
permissionsSql.append(" FROM ibzpermission t INNER JOIN IBZPSSYSUNIRES t1 ON t.SYS_PERMISSIONID = t1.SYS_PSSYSUNIRESID and t.enable=1");
permissionsSql.append(" )temp group by temp.systemid");
List<JSONObject> systems = isys_permissionService.select(permissionsSql.toString(), null);
if (permissions.size() > 0 && systems.size() > 0) {
treeNode = this.transferDataUniresToELTree(permissions, systems);
}
return treeNode;
}
/**
* 用于将资源表中统一资源数据转换成饿了么树格式数据
*
* @param permissions
* @param systems
* @return
*/
private JSONArray transferDataUniresToELTree(List<JSONObject> permissions, List<JSONObject> systems) {
Map<String, String> uniresTreeNameMap = new HashMap<>();
JSONObject groupByUniresObj = groupByDataUnires(permissions, systems, uniresTreeNameMap);//将数据库数据进行分组
JSONArray elTreeObj = transferDataUniresToELTree(groupByUniresObj, uniresTreeNameMap);//将分组后的数据转换成饿了么树格式数据
return elTreeObj;
}
/**
* 将数据库中的数据能力数据进行分组
* 格式为:系统->统一资源
*
* @param permissions
* @param systems
* @param uniresTreeNameMap
* @return
*/
private JSONObject groupByDataUnires(List<JSONObject> permissions, List<JSONObject> systems, Map<String, String> uniresTreeNameMap) {
JSONObject permission_system = new JSONObject(); //顶级系统数据
for (JSONObject system : systems) {
String systemid = system.getString("systemid");
for (JSONObject obj : permissions) {
JSONObject jobj = new JSONObject();
jobj.putAll(obj);
String str_systemid = jobj.getString("systemid");// 系统标识
String str_uniresid = jobj.getString("uniresid");// 统一资源标识
String str_uniresname = jobj.getString("uniresname");// 统一资源名称
String str_unirescode = jobj.getString("unirescode");// 资源代码
String str_permissionid = jobj.getString("sys_permissionid");// 实体数据操作名称
String str_permissionname = jobj.getString("sys_permissionname");// 实体数据操作标识
// 根据systemid进行操作
if (systemid.equals(str_systemid)) {
JSONArray cur_system = new JSONArray();
if (permission_system.containsKey(str_systemid))// 系统合并
cur_system = permission_system.getJSONArray(str_systemid);
JSONObject cur_unires = new JSONObject();
cur_unires.put("id", str_permissionid);
cur_unires.put("label", str_permissionname);
cur_system.add(cur_unires);
permission_system.put(str_systemid, cur_system);
//构造树节点名称集合
if (!uniresTreeNameMap.containsKey(str_systemid)) {// 系统
uniresTreeNameMap.put(str_systemid, str_systemid);
}
if (!uniresTreeNameMap.containsKey(str_uniresid)) {// 资源
uniresTreeNameMap.put(str_uniresid, str_uniresname);
}
}
}
}
return permission_system;
}
/**
* 权限树递归
*
* @param childNode
* @param uniresTreeNameMap
* @return
*/
private JSONArray transferDataUniresToELTree(JSONObject childNode, Map<String, String> uniresTreeNameMap) {
JSONArray array = new JSONArray();
Set<String> keys = childNode.keySet();
for (String key : keys) {
Object obj = childNode.get(key);
if (obj instanceof JSONObject) {
JSONArray childArr = transferDataCapabilityToELTree(childNode.getJSONObject(key), uniresTreeNameMap); //递归遍历输出下级节点信息
JSONObject childNodeObj = new JSONObject();
childNodeObj.put("id", key);
childNodeObj.put("label", uniresTreeNameMap.get(key));
childNodeObj.put("children", childArr);
array.add(childNodeObj);
} else {
if (obj instanceof JSONArray) {
JSONArray permissionArr = new JSONArray();
JSONArray jsonArray = childNode.getJSONArray(key);
for (int a = 0; a < jsonArray.size(); a++) { //最后一层
JSONObject permissionObj = jsonArray.getJSONObject(a);
JSONObject transPermissionObj = new JSONObject();
transPermissionObj.put("id", permissionObj.getString("id"));
transPermissionObj.put("label", permissionObj.getString("label"));
permissionArr.add(transPermissionObj);
}
JSONObject childNodeObj = new JSONObject();
childNodeObj.put("id", key);
childNodeObj.put("label", uniresTreeNameMap.get(key));
childNodeObj.put("children", permissionArr);
array.add(childNodeObj);
}
}
}
return array;
}
}
......@@ -15,17 +15,19 @@ public class UAACoreResource {
private UAACoreService uaaCoreService;
/**
* 获取全部权限列表或菜单列表
* 获取全部菜单列表和数据能力列表和统一资源列表
*
* @return
*/
@GetMapping(value = "/sys_permissions/getallMenuAndPermission")
@GetMapping(value = "/sys_permissions/getallMenuAndPermissionAndUnires")
public ResponseEntity<JSONArray> getAllPermission() {
JSONArray treeNode = new JSONArray();
// 获取菜单
// 获取应用菜单
treeNode.add(uaaCoreService.getAppMenu());
//获取数据能力
// 获取数据能力
treeNode.add(uaaCoreService.getDEOppriv());
// 获取统一资源
treeNode.add(uaaCoreService.getUnires());
return ResponseEntity.ok().body(treeNode);
}
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册