提交 38637162 编写于 作者: zhouweidong's avatar zhouweidong

统一资源

上级 0015db1f
......@@ -38,6 +38,10 @@ public class ClientAuthenticationResource
* 实体操作标识
*/
private String OPPriTag="OPPRIV";
/**
* 统一资源标识
*/
private String UniResTag="UNIRES";
@Autowired
@Qualifier("IBZUSERService")
......@@ -107,18 +111,59 @@ public class ClientAuthenticationResource
"\t)\n" +
"AND T1.PERMISSIONTYPE = '%s' ";
List<JSONObject> userPermission= permissionService.select(String.format(opprivSQL,user.getUserid(),OPPriTag)); //查询用户权限下的菜单数据
JSONObject userPermissionList=getUserPermissionList(userPermission);
permissionObj.put("userPermissionList",userPermissionList);
String uniResSQL="SELECT\n" +
"\tt2.SYS_PSSYSUNIRESID,\n" +
"\tt2.SYS_PSSYSUNIRESNAME,\n" +
"\tT2.UNIRESCODE \n" +
"FROM\n" +
"\tibzrole_permission T\n" +
"INNER JOIN ibzpermission T1 ON T.SYS_PERMISSIONID = T1.SYS_PERMISSIONID\n" +
"INNER JOIN IBZPSSYSUNIRES T2 on T1.SYS_PERMISSIONID=t2.SYS_PSSYSUNIRESID\n" +
"WHERE\n" +
"\tT.SYS_ROLEID IN (\n" +
"\t SELECT SYS_ROLEID\n" +
"\t FROM\n" +
"\t IBZUSER_ROLE t LEFT JOIN IBZUSER t1 ON t.SYS_USERID=T1.USERID\n" +
"\t WHERE\n" +
"\t T1.USERID = '%s'\n" +
"\t)\n" +
"AND T1.PERMISSIONTYPE = '%s' ";
List<JSONObject> entitiesList= permissionService.select(String.format(opprivSQL,user.getUserid(),OPPriTag)); //查询用户权限下的菜单数据
List<JSONObject> uniResList= permissionService.select(String.format(uniResSQL,user.getUserid(),UniResTag)); //查询用户权限下的菜单数据
JSONObject entities=getEntitiesList(entitiesList);
JSONArray uniRes=getUniRes(uniResList);
permissionObj.put("entities",entities);
permissionObj.put("unires",uniRes);
user.setPermisionList(permissionObj);
}
/**
* 获取统一资源
* @param uniResList
* @return
*/
private JSONArray getUniRes(List<JSONObject> uniResList) {
JSONArray uniResArr=new JSONArray();
for(int a=0;a<uniResList.size();a++){
JSONObject uniRes=uniResList.get(a);
JSONObject newUniRes=new JSONObject();
newUniRes.put("unirescode",uniRes.getString("UNIRESCODE"));
newUniRes.put("uniresname",uniRes.getString("SYS_PSSYSUNIRESNAME"));
uniResArr.add(newUniRes);
}
return uniResArr;
}
/**
* 拼接实体行为资源
* @param role_permissions
* @return
*/
private JSONObject getUserPermissionList(List<JSONObject> role_permissions) {
private JSONObject getEntitiesList(List<JSONObject> role_permissions) {
JSONObject permission_entity= new JSONObject();
for (Map rolePermission : role_permissions) {
......
......@@ -2,8 +2,10 @@ package cn.ibizlab.api.rest.extensions;
import cn.ibizlab.core.uaa.domain.SYS_PERMISSION;
import cn.ibizlab.core.uaa.domain.SYS_PSDEOPPRIV;
import cn.ibizlab.core.uaa.domain.SYS_PSSYSUNIRES;
import cn.ibizlab.core.uaa.service.ISYS_PERMISSIONService;
import cn.ibizlab.core.uaa.service.ISYS_PSDEOPPRIVService;
import cn.ibizlab.core.uaa.service.ISYS_PSSYSUNIRESService;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.JsonNode;
......@@ -30,6 +32,10 @@ public class PermissionFeignService {
* 实体操作标识
*/
private String OPPriTag="OPPRIV";
/**
* 统一资源标识
*/
private String UniResTag="UNIRES";
/**
* 实体行为操作标识
*/
......@@ -45,6 +51,9 @@ public class PermissionFeignService {
@Autowired
private ISYS_PSDEOPPRIVService opprivService;
@Autowired
private ISYS_PSSYSUNIRESService pssysuniresService;
/**
* 拿到业务系统传过来的权限和菜单数据,存入uaa的权限表中
*/
......@@ -54,23 +63,69 @@ public class PermissionFeignService {
if(map!=null){
permissionService.execute(String.format("UPDATE ibzpermission t SET t.enable=0 WHERE SYSTEMID='%s'",systemId));
}
List<SYS_PSDEOPPRIV> opprivList=new ArrayList<>();//菜单项集合
List<SYS_PERMISSION> ability_list=new ArrayList<>();//资源-操作能力集合
List<SYS_PSDEOPPRIV> opprivList=new ArrayList<>();//数据能力
List<SYS_PERMISSION> permission_list=new ArrayList<>();//权限
List<SYS_PSSYSUNIRES> unires_list=new ArrayList<>();//统一资源
if(map.containsKey("permission")){
JSONObject paramsObj = new JSONObject(map);
JSONObject capabilityPermissionObj = paramsObj.getJSONObject("permission");
parseDECapability(capabilityPermissionObj,systemId,ability_list,opprivList);
parseDECapability(capabilityPermissionObj,systemId,permission_list,opprivList);
parseUniRes(capabilityPermissionObj,systemId,permission_list,unires_list);
}
if(opprivList.size()>0){
opprivService.saveOrUpdateBatch(opprivList);//批量保存数据操作标识
opprivService.saveOrUpdateBatch(opprivList);//批量保存数据能力
}
if(permission_list.size()>0){
permissionService.saveOrUpdateBatch(permission_list);//批量保存权限资源
}
if(ability_list.size()>0){
permissionService.saveOrUpdateBatch(ability_list);//批量保存数据操作标识资源
if(unires_list.size()>0){
pssysuniresService.saveOrUpdateBatch(unires_list);//批量保存统一资源
}
return null;
}
/**
* 存储统一资源
* @param capabilityPermissionObj
*/
private void parseUniRes(JSONObject capabilityPermissionObj,String systemId,List<SYS_PERMISSION> permission_list,List<SYS_PSSYSUNIRES> unires_list) {
if(capabilityPermissionObj!=null){
JSONArray uniResArr=capabilityPermissionObj.getJSONArray("unires");
if(uniResArr.size()>0){
for(int a=0;a<uniResArr.size();a++){
JSONObject uniRes=uniResArr.getJSONObject(a);
createUniRes(uniRes,systemId,permission_list,unires_list);
}
}
}
}
/**
* 创建统一资源
* @param uniRes
*/
private void createUniRes(JSONObject uniRes ,String systemId,List<SYS_PERMISSION> permission_list,List<SYS_PSSYSUNIRES> unires_list) {
String uniResCode=uniRes.getString("unirescode");
String uniResName=uniRes.getString("uniresname");
String uniResId= DigestUtils.md5DigestAsHex(String.format("%s%s",systemId,uniResCode).getBytes());
SYS_PERMISSION sys_permission =new SYS_PERMISSION();
sys_permission.setPermissionid(uniResId);
sys_permission.setPermissionname(uniResName);
sys_permission.setPssystemid(systemId);
sys_permission.setPermissiontype(UniResTag);
sys_permission.setEnable(1);
permission_list.add(sys_permission);
SYS_PSSYSUNIRES sys_pssysunires=new SYS_PSSYSUNIRES();
sys_pssysunires.setSysPssysuniresid(uniResId);
sys_pssysunires.setSysPssysuniresname(uniResName);
sys_pssysunires.setUnirescode(uniResCode);
unires_list.add(sys_pssysunires);
}
/**
* 保存实体数据能力
* @param permission
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册