|
|
@@ -1,6 +1,7 @@
|
|
|
package com.roma.romaapi.service;
|
|
|
|
|
|
import com.roma.romaapi.dao.ApiDao;
|
|
|
+import com.roma.romaapi.dao.PageDao;
|
|
|
import com.roma.romaapi.utils.CommonUtil;
|
|
|
import com.roma.romaapi.utils.JWTUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -8,9 +9,7 @@ import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import com.roma.romaapi.utils.SecurityUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Objects;
|
|
|
+import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
@Service
|
|
|
@@ -21,6 +20,8 @@ public class ApiService {
|
|
|
@Autowired
|
|
|
private ApiDao apiDao;
|
|
|
@Autowired
|
|
|
+ PageDao pageDao; // 引入dao层
|
|
|
+ @Autowired
|
|
|
SecurityUtils securityUtils;
|
|
|
@Autowired
|
|
|
JWTUtil jwtUtil;
|
|
|
@@ -98,4 +99,79 @@ public class ApiService {
|
|
|
map.put("sysErrorCode","50000");
|
|
|
return map;
|
|
|
}
|
|
|
+
|
|
|
+ // 获取全部菜单
|
|
|
+ public List permissionList() {
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ List<Map<String, Object>> menuData = pageDao.getAllMenuForList(); // 获取全部菜单数据
|
|
|
+ List<Map<String, Object>> treeMenu = this.treeMenu(menuData); // 生成树结构
|
|
|
+
|
|
|
+ return treeMenu;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 新建权限
|
|
|
+ public void addPermissions(Map maps) {
|
|
|
+ System.out.println("权限数据----------------"+maps);
|
|
|
+ }
|
|
|
+
|
|
|
+// public List pageList() {
|
|
|
+// List<Map<String, Object>> pageList = pageDao.getAllPageList(); // 获取全部页面数据
|
|
|
+//
|
|
|
+// return pageList;
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // 转换tree结构数据
|
|
|
+ private List<Map<String, Object>> treeMenu(List<Map<String, Object>> renderMenu){
|
|
|
+ // 处理的数据存在
|
|
|
+ List<Map<String, Object>> pList = new ArrayList<Map<String, Object>>();// eTree
|
|
|
+ // 获取父节点
|
|
|
+ for (Map<String, Object> tmp : renderMenu) {
|
|
|
+ Object parentId = tmp.get("parent_id");
|
|
|
+ String stringParentId = parentId.toString();// 上级id
|
|
|
+ Object dataId = tmp.get("id");
|
|
|
+ String stringDataId = dataId.toString();// 主键id
|
|
|
+ if (stringParentId.equals("0")) {
|
|
|
+ // 组装子节点,开始循环去获取子节点
|
|
|
+ List<?> children = menuChild(stringDataId, renderMenu);
|
|
|
+ if(children == null || children.size() == 0) {
|
|
|
+ tmp.put("leaf", true); // 如果不存在子元素
|
|
|
+ } else {
|
|
|
+ tmp.put("children", children); // 存在子元素,则添加
|
|
|
+ }
|
|
|
+
|
|
|
+ pList.add(tmp);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return pList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理子节点
|
|
|
+ * @param id
|
|
|
+ * @param data
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<?> menuChild(String id, List<Map<String, Object>> data) {
|
|
|
+ List<Object> lists = new ArrayList<Object>();
|
|
|
+ for (Map<String, Object> map : data) {
|
|
|
+ Object parentId = map.get("parent_id");
|
|
|
+ String stringParentId = parentId.toString(); // 上级id
|
|
|
+ Object dataId = map.get("id");
|
|
|
+ String stringDataId = dataId.toString(); // 主键id
|
|
|
+ if (stringParentId.equals(id)) {
|
|
|
+ // 组装子节点,开始循环去获取子节点
|
|
|
+ List<?> children = menuChild(stringDataId, data);
|
|
|
+ if(children == null || children.size() == 0) {
|
|
|
+ map.put("leaf", true); // 如果不存在子元素
|
|
|
+ } else {
|
|
|
+ map.put("children", children); // 存在子元素,则添加
|
|
|
+ }
|
|
|
+ lists.add(map);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return lists;
|
|
|
+ }
|
|
|
}
|