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

菜单usr代码

上级 1b27b217
...@@ -14,13 +14,11 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -14,13 +14,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -48,6 +46,10 @@ public class ClientAuthenticationResource ...@@ -48,6 +46,10 @@ public class ClientAuthenticationResource
* 统一资源标识 * 统一资源标识
*/ */
private String UniResTag="UNIRES"; private String UniResTag="UNIRES";
/**
* 菜单项标识
*/
private String AppMenuTag="APPMENU";
@Autowired @Autowired
@Qualifier("IBZUSERService") @Qualifier("IBZUSERService")
...@@ -107,6 +109,7 @@ public class ClientAuthenticationResource ...@@ -107,6 +109,7 @@ public class ClientAuthenticationResource
JSONObject permissionObj=new JSONObject(); JSONObject permissionObj=new JSONObject();
//数据能力
String opprivSQL="SELECT\n" + String opprivSQL="SELECT\n" +
"\tT2.pssysmoduleid as sysmodule,\n" + "\tT2.pssysmoduleid as sysmodule,\n" +
"\tT2.psdataentityid as dataentity,\n" + "\tT2.psdataentityid as dataentity,\n" +
...@@ -128,8 +131,7 @@ public class ClientAuthenticationResource ...@@ -128,8 +131,7 @@ public class ClientAuthenticationResource
"\t)\n" + "\t)\n" +
"AND T1.PERMISSIONTYPE = #{et.param1} "; "AND T1.PERMISSIONTYPE = #{et.param1} ";
//统一资源
String uniResSQL="SELECT\n" + String uniResSQL="SELECT\n" +
"\tt2.SYS_PSSYSUNIRESID,\n" + "\tt2.SYS_PSSYSUNIRESID,\n" +
"\tt2.SYS_PSSYSUNIRESNAME,\n" + "\tt2.SYS_PSSYSUNIRESNAME,\n" +
...@@ -148,24 +150,68 @@ public class ClientAuthenticationResource ...@@ -148,24 +150,68 @@ public class ClientAuthenticationResource
"\t)\n" + "\t)\n" +
"AND T1.PERMISSIONTYPE = #{et.param1} "; "AND T1.PERMISSIONTYPE = #{et.param1} ";
//应用菜单
String appMenuSQL="SELECT\n" +
"\tt2.PSAPPPMENUITEMID as MENUITEMID,\n" +
"\tt2.SYS_PSAPPMENUITEMNAME AS MENUITEMNAME \n" +
"FROM\n" +
"\tibzrole_permission T\n" +
"INNER JOIN ibzpermission T1 ON T.SYS_PERMISSIONID = T1.SYS_PERMISSIONID\n" +
"INNER JOIN ibzpsappmenuitem T2 on T1.SYS_PERMISSIONID=t2.SYS_PSAPPMENUITEMID\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 = #{et.param0}\n" +
"\t)\n" +
"AND T1.PERMISSIONTYPE = #{et.param1} ";
Map opprivParam=new HashMap(); Map opprivParam=new HashMap();
opprivParam.put("param0",user.getUserid()); opprivParam.put("param0",user.getUserid());
opprivParam.put("param1",OPPriTag); opprivParam.put("param1",OPPriTag);
List<JSONObject> entitiesList= permissionService.select(opprivSQL,opprivParam); //查询用户权限下的菜单数据
Map uniresParam=new HashMap(); Map uniresParam=new HashMap();
uniresParam.put("param0",user.getUserid()); uniresParam.put("param0",user.getUserid());
uniresParam.put("param1",UniResTag); uniresParam.put("param1",UniResTag);
List<JSONObject> uniResList= permissionService.select(uniResSQL,uniresParam); //查询用户权限下的菜单数据 Map appMenuParam=new HashMap();
appMenuParam.put("param0",user.getUserid());
appMenuParam.put("param1",AppMenuTag);
List<JSONObject> entitiesList= permissionService.select(opprivSQL,opprivParam); //查询用户权限下数据能力
List<JSONObject> uniResList= permissionService.select(uniResSQL,uniresParam); //查询用户权限下的统一资源
List<JSONObject> appMenuItemList= permissionService.select(appMenuSQL,appMenuParam); //查询用户权限下的菜单项
JSONObject entities=getEntitiesList(entitiesList); JSONObject entities=getEntitiesList(entitiesList);
JSONArray uniRes=getUniRes(uniResList); JSONArray uniRes=getUniRes(uniResList);
JSONArray appMenuItem=getAppMenuItem(appMenuItemList);
permissionObj.put("entities",entities); permissionObj.put("entities",entities);
permissionObj.put("unires",uniRes); permissionObj.put("unires",uniRes);
permissionObj.put("appmenu",appMenuItem);
user.setPermissionList(permissionObj); user.setPermissionList(permissionObj);
} }
/**
* 获取应用菜单
* @param menuItemList
* @return
*/
private JSONArray getAppMenuItem(List<JSONObject> menuItemList) {
JSONArray menuItemArr=new JSONArray();
for(int a=0;a<menuItemList.size();a++){
JSONObject menuItem=menuItemList.get(a);
JSONObject newMenuItem=new JSONObject();
newMenuItem.put("menuitemid",menuItem.getString("MENUITEMID"));
newMenuItem.put("menuitemname",menuItem.getString("MENUITEMNAME"));
menuItemArr.add(newMenuItem);
}
return menuItemArr;
}
/** /**
* 获取统一资源 * 获取统一资源
* @param uniResList * @param uniResList
......
package cn.ibizlab.api.rest.extensions; package cn.ibizlab.api.rest.extensions;
import cn.ibizlab.core.uaa.domain.SYS_PERMISSION; import cn.ibizlab.core.uaa.domain.SYS_PERMISSION;
import cn.ibizlab.core.uaa.domain.SYS_PSAPPMENUITEM;
import cn.ibizlab.core.uaa.domain.SYS_PSDEOPPRIV; import cn.ibizlab.core.uaa.domain.SYS_PSDEOPPRIV;
import cn.ibizlab.core.uaa.domain.SYS_PSSYSUNIRES; import cn.ibizlab.core.uaa.domain.SYS_PSSYSUNIRES;
import cn.ibizlab.core.uaa.service.ISYS_PERMISSIONService; import cn.ibizlab.core.uaa.service.ISYS_PERMISSIONService;
import cn.ibizlab.core.uaa.service.ISYS_PSAPPMENUITEMService;
import cn.ibizlab.core.uaa.service.ISYS_PSDEOPPRIVService; import cn.ibizlab.core.uaa.service.ISYS_PSDEOPPRIVService;
import cn.ibizlab.core.uaa.service.ISYS_PSSYSUNIRESService; import cn.ibizlab.core.uaa.service.ISYS_PSSYSUNIRESService;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
...@@ -16,10 +18,8 @@ import org.springframework.validation.annotation.Validated; ...@@ -16,10 +18,8 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import java.util.ArrayList; import java.sql.Timestamp;
import java.util.HashMap; import java.util.*;
import java.util.List;
import java.util.Map;
/** /**
* 为业务系统提供权限相关服务 * 为业务系统提供权限相关服务
...@@ -37,6 +37,10 @@ public class PermissionFeignService { ...@@ -37,6 +37,10 @@ public class PermissionFeignService {
* 统一资源标识 * 统一资源标识
*/ */
private String UniResTag="UNIRES"; private String UniResTag="UNIRES";
/**
* 菜单项标识
*/
private String AppMenuTag="APPMENU";
/** /**
* 实体行为操作标识 * 实体行为操作标识
*/ */
...@@ -55,12 +59,15 @@ public class PermissionFeignService { ...@@ -55,12 +59,15 @@ public class PermissionFeignService {
@Autowired @Autowired
private ISYS_PSSYSUNIRESService pssysuniresService; private ISYS_PSSYSUNIRESService pssysuniresService;
@Autowired
private ISYS_PSAPPMENUITEMService psappmenuitemService;
/** /**
* 拿到业务系统传过来的权限和菜单数据,存入uaa的权限表中 * 拿到业务系统传过来的权限和菜单数据,存入uaa的权限表中
*/ */
@PostMapping("/uaa/permission/save") @PostMapping("/uaa/permission/save")
public Map<String, JsonNode> pushSystemPermissionData(@RequestBody Map<String,Object> map, @Validated @NotBlank(message = "systemid不允许为空")@RequestParam("systemid")String systemId){ public JSONObject pushSystemPermissionData(@RequestBody Map<String,Object> map, @Validated @NotBlank(message = "systemid不允许为空")@RequestParam("systemid")String systemId){
try {
//如果map值不为null说明要更新数据,则先将表中该系统标识下的所有数据进行逻辑删除 //如果map值不为null说明要更新数据,则先将表中该系统标识下的所有数据进行逻辑删除
Map param=new HashMap(); Map param=new HashMap();
param.put("param0",systemId); param.put("param0",systemId);
...@@ -69,25 +76,126 @@ public class PermissionFeignService { ...@@ -69,25 +76,126 @@ public class PermissionFeignService {
permissionService.execute(sql,param); permissionService.execute(sql,param);
} }
List<SYS_PSDEOPPRIV> opprivList=new ArrayList<>();//数据能力 List<SYS_PSDEOPPRIV> opprivList=new ArrayList<>();//数据能力
List<SYS_PERMISSION> permission_list=new ArrayList<>();//权限 List<SYS_PERMISSION> permission_list=new ArrayList<>();//资源
List<SYS_PSSYSUNIRES> unires_list=new ArrayList<>();//统一资源 List<SYS_PSSYSUNIRES> unires_list=new ArrayList<>();//统一资源
List<SYS_PSAPPMENUITEM> menu_list=new ArrayList<>();//资源-菜单项集合
if(map.containsKey("permission")){ if(map.containsKey("permission")){
JSONObject paramsObj = new JSONObject(map); JSONObject paramsObj = new JSONObject(map);
JSONObject capabilityPermissionObj = paramsObj.getJSONObject("permission"); JSONObject capabilityPermissionObj = paramsObj.getJSONObject("permission");
parseDECapability(capabilityPermissionObj,systemId,permission_list,opprivList); parseDECapability(capabilityPermissionObj,systemId,permission_list,opprivList);
parseUniRes(capabilityPermissionObj,systemId,permission_list,unires_list); parseUniRes(capabilityPermissionObj,systemId,permission_list,unires_list);
parseAppMenus(capabilityPermissionObj,systemId,permission_list,menu_list);
} }
if(opprivList.size()>0){ if(opprivList.size()>0){
opprivService.saveOrUpdateBatch(opprivList);//批量保存数据能力 opprivService.saveOrUpdateBatch(opprivList);//批量保存数据能力
} }
if(unires_list.size()>0){
pssysuniresService.saveOrUpdateBatch(unires_list);//批量保存统一资源
}
if(menu_list.size()>0){
psappmenuitemService.saveOrUpdateBatch(menu_list);//批量保存统一资源
}
if(permission_list.size()>0){ if(permission_list.size()>0){
permissionService.saveOrUpdateBatch(permission_list);//批量保存权限资源 permissionService.saveOrUpdateBatch(permission_list);//批量保存权限资源
} }
if(unires_list.size()>0){ } catch (Exception e) {
pssysuniresService.saveOrUpdateBatch(unires_list);//批量保存统一资源 return error("资源同步失败,失败原因为:"+e);
} }
return null; return success("资源同步成功");
}
/**
* 存储菜单资源
* @param capabilityPermissionObj
* @param systemId
* @param permission_list
* @param menu_list
*/
private void parseAppMenus(JSONObject capabilityPermissionObj, String systemId, List<SYS_PERMISSION> permission_list, List<SYS_PSAPPMENUITEM> menu_list) {
if(capabilityPermissionObj!=null) {
JSONArray appMenuArr = capabilityPermissionObj.getJSONArray("appmenus");
if(appMenuArr.size()>0){
for(int a=0;a<appMenuArr.size();a++){
JSONObject App=appMenuArr.getJSONObject(a);
String appId=App.getString("appid");
String appName=App.getString("appname");
if(App.containsKey("appmenu") && App.getJSONArray("appmenu").size()>0){
JSONArray AppMenuArr=App.getJSONArray("appmenu");
for(int b=0;b<AppMenuArr.size();b++){
JSONObject appMenu=AppMenuArr.getJSONObject(b);
String appMenuId=appMenu.getString("menuid");
String appMenuName=appMenu.getString("menuname");
if(appMenu.containsKey("menuitem")&& appMenu.getJSONArray("menuitem").size()>0){
JSONArray menuItemArr=appMenu.getJSONArray("menuitem");
parseMenuItems( menuItemArr , "", systemId, appId, appName, appMenuId, appMenuName, permission_list, menu_list);
}
}
}
}
}
}
}
/**
* 解析菜单项集合
* @param menuItemArr
* @param systemId
* @param permission_list
* @param menu_list
*/
private void parseMenuItems(JSONArray menuItemArr ,String parentMenuItemId, String systemId, String appId, String appName, String appMenuId,String appMenuName, List<SYS_PERMISSION> permission_list, List<SYS_PSAPPMENUITEM> menu_list){
for(int a=0;a<menuItemArr.size();a++){
JSONObject menuItem=menuItemArr.getJSONObject(a);
String menuItemId=menuItem.getString("id");
String menuItemName=menuItem.getString("name");
if(menuItem.containsKey("items") && menuItem.getJSONArray("items").size()>0){
JSONArray tempMenuItems=menuItem.getJSONArray("items");
parseMenuItems(tempMenuItems,menuItemId,systemId,appId,appName,appMenuId,appMenuName,permission_list,menu_list);
}
saveMenuItem(menuItemId,menuItemName,parentMenuItemId,systemId,appId,appName,appMenuId,appMenuName,permission_list,menu_list);
}
}
/**
* 保存菜单项
* @param menuItemId
* @param menuItemName
* @param parentMenuItemId
* @param systemId
* @param appId
* @param appName
* @param appMenuId
* @param appMenuName
* @param permission_list
* @param menu_list
*/
private void saveMenuItem(String menuItemId,String menuItemName , String parentMenuItemId, String systemId, String appId, String appName, String appMenuId,String appMenuName, List<SYS_PERMISSION> permission_list, List<SYS_PSAPPMENUITEM> menu_list){
String sysPermissionId=DigestUtils.md5DigestAsHex(String.format("%s%s%s%s",systemId,appId,appMenuId,menuItemId).getBytes());
SYS_PERMISSION sys_permission =new SYS_PERMISSION();
sys_permission.setPermissionid(sysPermissionId);
sys_permission.setPermissionname(menuItemName);
sys_permission.setPssystemid(systemId);
sys_permission.setPermissiontype(AppMenuTag);
sys_permission.setEnable(1);
sys_permission.setCreatedate(new Timestamp(new Date().getTime()));
sys_permission.setUpdatedate(new Timestamp(new Date().getTime()));
permission_list.add(sys_permission);
//存菜单项表
SYS_PSAPPMENUITEM psAppMenuItem=new SYS_PSAPPMENUITEM();
psAppMenuItem.setAppmenuitemid(sysPermissionId);
psAppMenuItem.setAppmenuitemname(menuItemName);
psAppMenuItem.setPsappid(appId);
psAppMenuItem.setPsappname(appName);
psAppMenuItem.setPsappmenuid(appMenuId);
psAppMenuItem.setPsappmenuname(appMenuName);
psAppMenuItem.setPssystemid(systemId);
psAppMenuItem.setPsappmenuitemid(menuItemId);
psAppMenuItem.setPsapppmenuitemid(parentMenuItemId);
psAppMenuItem.setCreatedate(new Timestamp(new Date().getTime()));
psAppMenuItem.setUpdatedate(new Timestamp(new Date().getTime()));
menu_list.add(psAppMenuItem);
} }
/** /**
...@@ -122,12 +230,16 @@ public class PermissionFeignService { ...@@ -122,12 +230,16 @@ public class PermissionFeignService {
sys_permission.setPssystemid(systemId); sys_permission.setPssystemid(systemId);
sys_permission.setPermissiontype(UniResTag); sys_permission.setPermissiontype(UniResTag);
sys_permission.setEnable(1); sys_permission.setEnable(1);
sys_permission.setCreatedate(new Timestamp(new Date().getTime()));
sys_permission.setUpdatedate(new Timestamp(new Date().getTime()));
permission_list.add(sys_permission); permission_list.add(sys_permission);
SYS_PSSYSUNIRES sys_pssysunires=new SYS_PSSYSUNIRES(); SYS_PSSYSUNIRES sys_pssysunires=new SYS_PSSYSUNIRES();
sys_pssysunires.setUniresid(uniResId); sys_pssysunires.setUniresid(uniResId);
sys_pssysunires.setUniresname(uniResName); sys_pssysunires.setUniresname(uniResName);
sys_pssysunires.setUnirescode(uniResCode); sys_pssysunires.setUnirescode(uniResCode);
sys_pssysunires.setCreatedate(new Timestamp(new Date().getTime()));
sys_pssysunires.setUpdatedate(new Timestamp(new Date().getTime()));
unires_list.add(sys_pssysunires); unires_list.add(sys_pssysunires);
} }
...@@ -167,9 +279,10 @@ public class PermissionFeignService { ...@@ -167,9 +279,10 @@ public class PermissionFeignService {
for(int b=0;b<deActionArray.size();b++) { for(int b=0;b<deActionArray.size();b++) {
JSONObject deSource = deActionArray.getJSONObject(b); JSONObject deSource = deActionArray.getJSONObject(b);
String deActionType=deSource.getString("type"); String deActionType=deSource.getString("type");
if(permissionType.equalsIgnoreCase(DEActionType) && !StringUtils.isEmpty(deActionType) && !deActionType.equalsIgnoreCase("BUILTIN")) { //数据查询与自定义行为不生成预置范围相关数据
if( (permissionType.equalsIgnoreCase(DEActionType) && !deActionType.equalsIgnoreCase("BUILTIN")) || (permissionType.equalsIgnoreCase(DataSetTag)) ) {
JSONObject dataRange =new JSONObject(); JSONObject dataRange =new JSONObject();
createDataRange(entity,deSource,dataRange,permissionType,systemId,ability_list,opprivList);//自定义用户行为 createDataRange(entity,deSource,dataRange,permissionType,systemId,ability_list,opprivList);
} }
else{ else{
for(int c=0;c<preDefinedDataRange.size();c++){ for(int c=0;c<preDefinedDataRange.size();c++){
...@@ -219,6 +332,8 @@ public class PermissionFeignService { ...@@ -219,6 +332,8 @@ public class PermissionFeignService {
sys_permission.setPermissionid(permissionId); sys_permission.setPermissionid(permissionId);
sys_permission.setPermissiontype(OPPriTag); sys_permission.setPermissiontype(OPPriTag);
sys_permission.setEnable(1); sys_permission.setEnable(1);
sys_permission.setUpdatedate(new Timestamp(new Date().getTime()));
sys_permission.setCreatedate(new Timestamp(new Date().getTime()));
ability_list.add(sys_permission); ability_list.add(sys_permission);
//存数据操作能力表 //存数据操作能力表
...@@ -235,8 +350,23 @@ public class PermissionFeignService { ...@@ -235,8 +350,23 @@ public class PermissionFeignService {
psDEOppriv.setPsdedatarangeid(dataRangeId); psDEOppriv.setPsdedatarangeid(dataRangeId);
psDEOppriv.setPsdedatarangename(dataRangeName); psDEOppriv.setPsdedatarangename(dataRangeName);
psDEOppriv.setPssourcetype(permissionType); psDEOppriv.setPssourcetype(permissionType);
psDEOppriv.setCreatedate(new Timestamp(new Date().getTime()));
psDEOppriv.setUpdatedate(new Timestamp(new Date().getTime()));
opprivList.add(psDEOppriv); opprivList.add(psDEOppriv);
} }
private JSONObject success(String msg){
JSONObject obj =new JSONObject();
obj.put("code",1);
obj.put("msg",msg);
return obj;
}
private JSONObject error(String msg){
JSONObject obj =new JSONObject();
obj.put("code",0);
obj.put("msg",msg);
return obj;
}
} }
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册