This commit is contained in:
parent
bc41d7362b
commit
a4f44c4d8e
|
|
@ -5,6 +5,7 @@ import com.hxkj.admin.LikeAdminThreadLocal;
|
|||
import com.hxkj.admin.config.aop.Log;
|
||||
import com.hxkj.admin.service.ISystemMenuService;
|
||||
import com.hxkj.admin.validate.system.SystemMenuParam;
|
||||
import com.hxkj.admin.vo.system.SystemAuthVo;
|
||||
import com.hxkj.admin.vo.system.SystemMenuVo;
|
||||
import com.hxkj.common.core.AjaxResult;
|
||||
import com.hxkj.common.validator.annotation.IDMust;
|
||||
|
|
@ -12,6 +13,7 @@ import org.springframework.validation.annotation.Validated;
|
|||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 系统菜单管理
|
||||
|
|
@ -36,6 +38,19 @@ public class SystemMenuController {
|
|||
return AjaxResult.success(lists);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取权限节点
|
||||
*
|
||||
* @author fzr
|
||||
* @return Object
|
||||
*/
|
||||
@GetMapping("/auth")
|
||||
public Object auth() {
|
||||
Integer roleId = LikeAdminThreadLocal.getRoleId();
|
||||
List<SystemAuthVo> lists = iSystemMenuService.selectAuthByRoleId(roleId);
|
||||
return AjaxResult.success(lists);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取菜单列表
|
||||
*
|
||||
|
|
|
|||
|
|
@ -2,8 +2,11 @@ package com.hxkj.admin.service;
|
|||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.hxkj.admin.validate.system.SystemMenuParam;
|
||||
import com.hxkj.admin.vo.system.SystemAuthVo;
|
||||
import com.hxkj.admin.vo.system.SystemMenuVo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 系统菜单服务接口类
|
||||
*/
|
||||
|
|
@ -17,6 +20,14 @@ public interface ISystemMenuService {
|
|||
*/
|
||||
JSONArray selectMenuByRoleId(Integer roleId);
|
||||
|
||||
/**
|
||||
* 根据角色获取权限
|
||||
*
|
||||
* @author fzr
|
||||
* @return JSONArray
|
||||
*/
|
||||
List<SystemAuthVo> selectAuthByRoleId(Integer roleId);
|
||||
|
||||
/**
|
||||
* 菜单列表
|
||||
*
|
||||
|
|
|
|||
|
|
@ -8,12 +8,11 @@ import com.hxkj.admin.config.AdminConfig;
|
|||
import com.hxkj.admin.service.ISystemMenuService;
|
||||
import com.hxkj.admin.service.ISystemRoleMenuService;
|
||||
import com.hxkj.admin.validate.system.SystemMenuParam;
|
||||
import com.hxkj.admin.vo.system.SystemAuthVo;
|
||||
import com.hxkj.admin.vo.system.SystemMenuVo;
|
||||
import com.hxkj.common.entity.system.SystemMenu;
|
||||
import com.hxkj.common.mapper.system.SystemMenuMapper;
|
||||
import com.hxkj.common.utils.ArrayUtil;
|
||||
import com.hxkj.common.utils.RedisUtil;
|
||||
import com.hxkj.common.utils.TimeUtil;
|
||||
import com.hxkj.common.utils.*;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
|
@ -21,6 +20,7 @@ import javax.annotation.Resource;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class SystemMenuServiceImpl implements ISystemMenuService {
|
||||
|
|
@ -65,6 +65,64 @@ public class SystemMenuServiceImpl implements ISystemMenuService {
|
|||
return ArrayUtil.listToTree(jsonArray, "id", "pid", "children");
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据角色ID获取权限
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @return JSONArray
|
||||
*/
|
||||
@Override
|
||||
public List<SystemAuthVo> selectAuthByRoleId(Integer roleId) {
|
||||
List<Integer> menuIds = iSystemRoleMenuService.selectMenuIdsByRoleId(roleId);
|
||||
|
||||
QueryWrapper<SystemMenu> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.in("menu_type", Arrays.asList("C", "A"));
|
||||
queryWrapper.orderByDesc(Arrays.asList("menu_sort", "id"));
|
||||
if (menuIds.size() > 0) {
|
||||
queryWrapper.in("id", menuIds);
|
||||
}
|
||||
|
||||
List<SystemMenu> systemMenus = systemMenuMapper.selectList(queryWrapper);
|
||||
JSONArray jsonArray = JSONArray.parseArray(JSONArray.toJSONString(systemMenus));
|
||||
JSONArray menuJson = ArrayUtil.listToTree(jsonArray, "id", "pid", "children");
|
||||
|
||||
List<SystemAuthVo> authVos = new ArrayList<>();
|
||||
for (Object object : menuJson.toArray()) {
|
||||
Map<String, String> map = ToolsUtil.objectToMap(object);
|
||||
|
||||
SystemAuthVo systemAuthVo = new SystemAuthVo();
|
||||
systemAuthVo.setPath(map.get("component"));
|
||||
|
||||
List<String> auths = new ArrayList<>();
|
||||
if (StringUtil.isNotEmpty(map.get("children"))) {
|
||||
// 第一层
|
||||
for (Map<String, String> m : ToolsUtil.stringToList(map.get("children"))) {
|
||||
if (!m.get("perms").equals("")) {
|
||||
auths.add(m.get("perms"));
|
||||
}
|
||||
|
||||
// 第二层
|
||||
if (!m.get("children").equals("")) {
|
||||
for (Map<String, String> tow : ToolsUtil.stringToList(m.get("children"))) {
|
||||
if (!tow.get("perms").equals("")) {
|
||||
auths.add(tow.get("perms"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!map.get("perms").equals("")) {
|
||||
auths.add(map.get("perms"));
|
||||
}
|
||||
|
||||
systemAuthVo.setAuth(auths);
|
||||
authVos.add(systemAuthVo);
|
||||
}
|
||||
|
||||
return authVos;
|
||||
}
|
||||
|
||||
/**
|
||||
* 菜单列表
|
||||
*
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
package com.hxkj.admin.vo.system;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 权限Vo
|
||||
*/
|
||||
@Data
|
||||
public class SystemAuthVo implements Serializable {
|
||||
|
||||
private String path;
|
||||
private Object auth;
|
||||
|
||||
}
|
||||
|
|
@ -22,6 +22,7 @@ public class SystemMenu implements Serializable {
|
|||
private String menuIcon;
|
||||
private Integer menuSort;
|
||||
private String perms;
|
||||
private String component;
|
||||
private Integer isDisable;
|
||||
private Long createTime;
|
||||
private Long updateTime;
|
||||
|
|
|
|||
|
|
@ -156,6 +156,23 @@ public class ToolsUtil {
|
|||
return JSON.parseObject(json, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* JSON转map
|
||||
*
|
||||
* @author fzr
|
||||
* @param object 对象
|
||||
* @return Map<String, String>
|
||||
*/
|
||||
public static Map<String, String> objectToMap(Object object){
|
||||
Type type = new TypeToken<Map<String, String>>() {}.getType();
|
||||
return JSON.parseObject(JSONObject.toJSONString(object), type);
|
||||
}
|
||||
|
||||
public static List<Map<String, String>> stringToList(String s) {
|
||||
Type type = new TypeToken<List<Map<String, String>>>() {}.getType();
|
||||
return JSON.parseObject(s, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* map合并
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue