|
|
@@ -4,6 +4,9 @@ import com.roma.romaapi.dao.PageDao;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
@Service
|
|
|
@@ -15,4 +18,81 @@ public class PageService {
|
|
|
|
|
|
return ret;
|
|
|
}
|
|
|
+
|
|
|
+ // 整理返回菜单
|
|
|
+ public List menu(){
|
|
|
+ List<Map<String, Object>> menuData = pageDao.getMenuForList(); // 获取全部菜单数据
|
|
|
+
|
|
|
+ List<Map<String, Object>> renderMenu = this.renderMenu(menuData);// 根据选项渲染节点内容
|
|
|
+
|
|
|
+ List<Map<String, Object>> treeMenu = this.treeMenu(renderMenu); // 生成树结构
|
|
|
+
|
|
|
+ return renderMenu;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 渲染节点内容
|
|
|
+ private List<Map<String, Object>> renderMenu(List<Map<String, Object>> menuData){
|
|
|
+ List<Map<String, Object>> retList = new ArrayList<Map<String, Object>>();
|
|
|
+ for (int i = 0; i < menuData.size(); i++) {
|
|
|
+ Map map = menuData.get(i);
|
|
|
+ String menuType = (String) map.get("type");
|
|
|
+ Map tempMap = new HashMap<>();
|
|
|
+ switch (menuType) {
|
|
|
+ case "menu": // 菜单
|
|
|
+ tempMap.put("id", map.get("id"));
|
|
|
+ tempMap.put("parent_id", map.get("parent_id"));
|
|
|
+ tempMap.put("label", (String) map.get("label"));
|
|
|
+ tempMap.put("icon", (String) map.get("icon"));
|
|
|
+ tempMap.put("url", (String) map.get("url"));
|
|
|
+ tempMap.put("schemaApi", (String) map.get("path"));
|
|
|
+ tempMap.put("visible", 1);
|
|
|
+ retList.add(tempMap);
|
|
|
+ break;
|
|
|
+ case "dir":
|
|
|
+ tempMap.put("id", map.get("id"));
|
|
|
+ tempMap.put("parent_id", map.get("parent_id"));
|
|
|
+ tempMap.put("label", (String) map.get("label"));
|
|
|
+ tempMap.put("icon", (String) map.get("icon"));
|
|
|
+ tempMap.put("visible", 1);
|
|
|
+ retList.add(tempMap);
|
|
|
+ break;
|
|
|
+ case "link":
|
|
|
+ tempMap.put("id", map.get("id"));
|
|
|
+ tempMap.put("parent_id", map.get("parent_id"));
|
|
|
+ tempMap.put("label", (String) map.get("label"));
|
|
|
+ tempMap.put("icon", (String) map.get("icon"));
|
|
|
+ tempMap.put("link", (String) map.get("path"));
|
|
|
+ tempMap.put("visible", 1);
|
|
|
+ retList.add(tempMap);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return retList;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 转换tree结构数据
|
|
|
+ private List<Map<String, Object>> treeMenu(List<Map<String, Object>> renderMenu){
|
|
|
+ List<Map<String, Object>> retList = new ArrayList<Map<String, Object>>();
|
|
|
+ // 构建数据
|
|
|
+ System.out.print("dsdsadsd---tree");
|
|
|
+ for (int i = 0; i < renderMenu.size(); i++) {
|
|
|
+ Map map = renderMenu.get(i);
|
|
|
+ System.out.println(map.get("id"));
|
|
|
+ System.out.println(map.get("parent_id"));
|
|
|
+ Object parentId = map.get("parent_id");
|
|
|
+ String stringParentId = parentId.toString();
|
|
|
+ Integer intParentId = Integer.parseInt(stringParentId); // 上级id
|
|
|
+ Object dataId = map.get("id");
|
|
|
+ String stringDataId = dataId.toString();
|
|
|
+ Integer intDataId = Integer.parseInt(stringDataId); // 主键id
|
|
|
+
|
|
|
+System.out.println(map);
|
|
|
+// $id = $item[$primary_key];
|
|
|
+// $parent_id = $item[$parent_key];
|
|
|
+// $r[$parent_id][$id] = $item;
|
|
|
+ }
|
|
|
+
|
|
|
+ return retList;
|
|
|
+ }
|
|
|
}
|