增加接口:根据用户id查询菜单
This commit is contained in:
@@ -244,4 +244,58 @@ public class FunctionController {
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户id查询菜单
|
||||
* @param userId
|
||||
* @param request
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@GetMapping(value = "/getMenuByUserId")
|
||||
@ApiOperation(value = "根据用户id查询菜单")
|
||||
public BaseResponseInfo getMenuByUserId(@RequestParam("userId") Long userId,
|
||||
HttpServletRequest request)throws Exception {
|
||||
BaseResponseInfo res = new BaseResponseInfo();
|
||||
try {
|
||||
JSONArray dataArray = new JSONArray();
|
||||
Long roleId = 0L;
|
||||
String fc = "";
|
||||
List<UserBusiness> roleList = userBusinessService.getBasicData(userId.toString(), "UserRole");
|
||||
if(roleList!=null && roleList.size()>0){
|
||||
String value = roleList.get(0).getValue();
|
||||
if(StringUtil.isNotEmpty(value)){
|
||||
String roleIdStr = value.replace("[", "").replace("]", "");
|
||||
roleId = Long.parseLong(roleIdStr);
|
||||
}
|
||||
}
|
||||
//当前用户所拥有的功能列表,格式如:[1][2][5]
|
||||
List<UserBusiness> funList = userBusinessService.getBasicData(roleId.toString(), "RoleFunctions");
|
||||
if(funList!=null && funList.size()>0){
|
||||
fc = funList.get(0).getValue();
|
||||
}
|
||||
List<Function> dataList = functionService.getRoleFunctionLeaf();
|
||||
if (dataList.size() != 0) {
|
||||
for (Function function : dataList) {
|
||||
if (fc.contains("[" + function.getId().toString() + "]")) {
|
||||
String page = function.getUrl();
|
||||
page = page.replace("/system/", "").replace("/bill/", "")
|
||||
.replace("/financial/", "").replace("/report/", "")
|
||||
.replace("/material/","");
|
||||
JSONObject item = new JSONObject();
|
||||
item.put("id", function.getId());
|
||||
item.put("page", page);
|
||||
dataArray.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
res.code = 200;
|
||||
res.data = dataArray;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
res.code = 500;
|
||||
res.data = "获取数据失败";
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user