Browse Source

Merge remote-tracking branch 'origin/master'

‘xugp 1 year ago
parent
commit
fe13ae78cf

+ 5 - 6
ims-service/ims-eval/src/main/java/com/ims/eval/controller/MenuOperationController.java

@@ -1,17 +1,16 @@
 package com.ims.eval.controller;
 
 
-import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
-import com.ims.eval.entity.custom.DoAction;
+import com.ims.eval.entity.custom.Menu;
 import com.ims.eval.entity.dto.result.R;
 import com.ims.eval.service.custom.MenuOperationService;
-import com.ims.eval.service.custom.WorkflowService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
+import java.util.List;
 
 /**
  * <p>
@@ -40,14 +39,14 @@ public class MenuOperationController {
 	 */
 	@PostMapping(value = "menuList")
 	public R menuList(@RequestParam(value = "parentId", required = false) String parentId) {
-		JSONArray json = null;
+		List<Menu> getTree = null;
 		try {
-			json = menuOperationService.menuList(parentId,request);
+			getTree = menuOperationService.getMenuTree(parentId,request);
 		} catch (Exception e) {
 			log.error("错误",e);
 			return R.error().customError("获取菜单获取失败");
 		}
-		return R.ok().data(json);
+		return R.ok().data(getTree);
 	}
 
 

+ 55 - 0
ims-service/ims-eval/src/main/java/com/ims/eval/entity/custom/Menu.java

@@ -0,0 +1,55 @@
+package com.ims.eval.entity.custom;
+
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class Menu {
+
+	private static final long serialVersionUID = 1L;
+
+
+	private String id;
+
+	private String menuNo;
+
+	private String icon;
+
+	private String parentIds;
+
+	private String delFlag;
+
+	private String type;
+
+	private String isCloseTree;
+
+	private String href;
+
+	private String iconCls;
+
+	private String permission;
+
+	private Boolean isNewRecord;
+
+	private Integer sort;
+
+	private String parentId;
+
+	private String isShow;
+
+	private String target;
+
+	private String createBy;
+
+	private String name;
+
+	private String objId;
+
+	private String remarks;
+
+	private List<Menu> children;
+
+
+
+}

+ 78 - 11
ims-service/ims-eval/src/main/java/com/ims/eval/service/custom/MenuOperationService.java

@@ -1,10 +1,11 @@
 package com.ims.eval.service.custom;
 
+import cn.hutool.core.collection.CollectionUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.ims.eval.config.ImaConfig;
-import com.ims.eval.entity.custom.DoAction;
+import com.ims.eval.entity.custom.Menu;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.*;
@@ -12,8 +13,10 @@ import org.springframework.stereotype.Service;
 import org.springframework.web.client.RestTemplate;
 
 import javax.servlet.http.HttpServletRequest;
-import java.util.LinkedHashMap;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -35,32 +38,31 @@ public class MenuOperationService {
 
 	/**
 	 * 获取权限菜单
+	 *
 	 * @param parentId
 	 * @return
 	 */
-	public JSONArray menuList(String parentId, HttpServletRequest request){
+	public JSONArray menuList(String parentId, HttpServletRequest request) {
 		HttpHeaders headers = new HttpHeaders();
 		headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
 		headers.add("Blade-Auth", request.getHeader("Blade-Auth"));
 		headers.add("code", request.getHeader("code"));
-
-
 		HttpEntity<Map> param = new HttpEntity<>(null, headers);
-		ResponseEntity<String> responseEntity2 = restTemplate.exchange(imaConfig.getGatewayUrl()+"ims-ext/sys/sysMenu/menuList?parentId={1}", HttpMethod.POST,param,String.class,parentId);
+		ResponseEntity<String> responseEntity2 = restTemplate.exchange(imaConfig.getGatewayUrl() + "ims-ext/sys/sysMenu/menuList?parentId={1}", HttpMethod.POST, param, String.class, parentId);
 		log.info("\n code:{}\n header:{}\n body:{}\n", responseEntity2.getStatusCodeValue(), responseEntity2.getHeaders(), responseEntity2.getBody());
-		if(200== responseEntity2.getStatusCodeValue()){
+		if (200 == responseEntity2.getStatusCodeValue()) {
 			return JSON.parseArray(responseEntity2.getBody());
 		}
 		return null;
 	}
 
 
-
 	/**
 	 * 获取用户权限
+	 *
 	 * @return
 	 */
-	public JSONObject getPrivilegesOfCurrentUserAll(HttpServletRequest request){
+	public JSONObject getPrivilegesOfCurrentUserAll(HttpServletRequest request) {
 		HttpHeaders headers = new HttpHeaders();
 		headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
 		headers.add("Blade-Auth", request.getHeader("Blade-Auth"));
@@ -68,13 +70,78 @@ public class MenuOperationService {
 
 
 		HttpEntity<Map> param = new HttpEntity<>(null, headers);
-		ResponseEntity<String> responseEntity2 = restTemplate.exchange(imaConfig.getGatewayUrl()+"ims-ext/sys/sysRole/getPrivilegesOfCurrentUserAll", HttpMethod.POST,param,String.class);
+		ResponseEntity<String> responseEntity2 = restTemplate.exchange(imaConfig.getGatewayUrl() + "ims-ext/sys/sysRole/getPrivilegesOfCurrentUserAll", HttpMethod.POST, param, String.class);
 		log.info("\n code:{}\n header:{}\n body:{}\n", responseEntity2.getStatusCodeValue(), responseEntity2.getHeaders(), responseEntity2.getBody());
-		if(200== responseEntity2.getStatusCodeValue()){
+		if (200 == responseEntity2.getStatusCodeValue()) {
 			return JSON.parseObject(responseEntity2.getBody());
 		}
 		return null;
 	}
 
 
+	/**
+	 * 获取菜单树结构
+	 *
+	 * @param parentId
+	 * @param request
+	 * @return
+	 */
+	public List<Menu> getMenuTree(String parentId, HttpServletRequest request) {
+		JSONArray arr = menuList(parentId, request);
+		if (null == arr) {
+			return null;
+		}
+		List<Menu> list = arr.toJavaList(Menu.class);
+		List<Menu> menuTr = convert(list);
+		return menuTr;
+	}
+
+
+	/**
+	 * 转换为有树形结构的列表
+	 *
+	 * @param source 源数据所有数据
+	 * @return
+	 */
+	public List<Menu> convert(List<Menu> source) {
+		if (CollectionUtil.isEmpty(source)) {
+			return new ArrayList<>();
+		}
+		List<Menu> result = new ArrayList<>();
+		List<String> idList = source.stream().map(Menu::getId).collect(Collectors.toList());
+		// 设置最外层顶级
+		for (Menu menuVO : source) {
+			// 判断所有列表里面父级未在集合中放置到一级
+			if (!idList.contains(menuVO.getParentId())) {
+				result.add(menuVO);
+			}
+		}
+		for (Menu menuVO : result) {
+			// 循环一级之后子级
+			getChildren(source, menuVO);
+		}
+		return result;
+	}
+
+
+	/**
+	 * 循环设置子级
+	 *
+	 * @param list         所有元素列表
+	 * @param treeSelectVO 父级元素
+	 * @return 父级元素
+	 */
+	public static Menu getChildren(List<Menu> list, Menu treeSelectVO) {
+		for (Menu Menu : list) {
+			if (treeSelectVO.getId().equals(Menu.getParentId())) {
+				List<Menu> children = CollectionUtil.isEmpty(treeSelectVO.getChildren()) ? new ArrayList<>() : treeSelectVO.getChildren();
+				children.add(getChildren(list, Menu));
+				treeSelectVO.setChildren(children);
+
+			}
+		}
+		return treeSelectVO;
+	}
+
+
 }