Commit 2b5deeb5 authored by taabe's avatar taabe

修改树节点对象,添加节点类型字段

parent 5c0be843
...@@ -2,81 +2,115 @@ package com.yeejoin.amos.boot.biz.common.utils; ...@@ -2,81 +2,115 @@ package com.yeejoin.amos.boot.biz.common.utils;
import java.util.List; import java.util.List;
/**
* @author DELL
*/
public class MenuFrom { public class MenuFrom {
public String id; public String id;
public String key; public String key;
public String value; public String value;
public String title; public String title;
public String label; public String label;
public String name; public String name;
public String parentId; public String parentId;
public Boolean isLeaf=true; public Boolean isLeaf = true;
public List<MenuFrom> children; public List<MenuFrom> children;
public String getKey() {
return key; /**
} * 节点类型
public void setKey(String key) { */
this.key = key; public String nodeType;
}
public String getTitle() { public MenuFrom(String id, String value, String key, String title, String label, String name, String parentId,
return title; String nodeType) {
} super();
public void setTitle(String title) { this.id = id;
this.title = title; this.value = value;
} this.key = key;
public String getLabel() { this.title = title;
return label; this.label = label;
} this.name = name;
public void setLabel(String label) { this.parentId = parentId;
this.label = label; this.nodeType = nodeType;
} }
public String getName() {
return name; public MenuFrom(String key, String name, String parentId, String nodeType) {
} super();
public void setName(String name) { this.id = key;
this.name = name; this.value = key;
} this.key = key;
public String getParentId() { this.title = name;
return parentId; this.label = name;
} this.name = name;
public void setParentId(String parentId) { this.parentId = parentId;
this.parentId = parentId; this.nodeType = nodeType;
} }
public Boolean getIsLeaf() {
return isLeaf; public MenuFrom() {
} super();
public void setIsLeaf(Boolean isLeaf) { }
this.isLeaf = isLeaf;
} public String getKey() {
public List<MenuFrom> getChildren() { return key;
return children; }
}
public void setChildren(List<MenuFrom> children) { public void setKey(String key) {
this.children = children; this.key = key;
} }
public MenuFrom(String id,String value,String key, String title, String label, String name, String parentId) {
super(); public String getTitle() {
this.id = id; return title;
this.value = value; }
this.key = key;
this.title = title; public void setTitle(String title) {
this.label = label; this.title = title;
this.name = name; }
this.parentId = parentId;
} public String getLabel() {
return label;
public MenuFrom(String key, String name, String parentId) { }
super();
this.id = key; public void setLabel(String label) {
this.value = key; this.label = label;
this.key = key; }
this.title = name;
this.label = name; public String getName() {
this.name = name; return name;
this.parentId = parentId; }
public void setName(String name) {
this.name = name;
}
public String getParentId() {
return parentId;
}
public void setParentId(String parentId) {
this.parentId = parentId;
}
public Boolean getIsLeaf() {
return isLeaf;
}
public void setIsLeaf(Boolean isLeaf) {
this.isLeaf = isLeaf;
}
public List<MenuFrom> getChildren() {
return children;
}
public void setChildren(List<MenuFrom> children) {
this.children = children;
}
public String getNodeType() {
return nodeType;
}
public void setNodeType(String nodeType) {
this.nodeType = nodeType;
} }
public MenuFrom() {
super();
}
} }
package com.yeejoin.amos.boot.biz.common.utils; package com.yeejoin.amos.boot.biz.common.utils;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* 生成树工具类 * 生成树工具类
* @return *
* <PRE> * @return <PRE>
* author tw * author tw
* date 2021/6/10 * date 2021/6/10
* </PRE> * </PRE>
*/ */
public class TreeParser{ public class TreeParser {
/** /**
* @param topId 父id * @param topId 父id
* @param entityList 数据集合 * @param entityList 数据集合
* @param packageURL 集合对象包名+类名 * @param packageURL 集合对象包名+类名
* @param IDMethodName 集合对象获取树id 方法名 * @param IDMethodName 集合对象获取树id 方法名
* @param IDHierarchy 集合对象获取树id 来源于自己 还是父级( 1自己,2 父级 ,3 父级的父级) * @param IDHierarchy 集合对象获取树id 来源于自己 还是父级( 1自己,2 父级 ,3 父级的父级)
* @param NAMEMethodName 集合对象获取树name 方法名 * @param NAMEMethodName 集合对象获取树name 方法名
* @param PARENTIDMethodName 集合对象获取树父id 方法名 * @param PARENTIDMethodName 集合对象获取树父id 方法名
* @param List<FirefightersTreeDto> * @param List<FirefightersTreeDto>
* @return java.util.List<com.yeejoin.amos.boot.module.jcs.api.vo.Menu> * @return java.util.List<com.yeejoin.amos.boot.module.jcs.api.vo.Menu>
* <PRE> * <PRE>
* author tw * author tw
* date 2021/6/10 * date 2021/6/10
* </PRE> * </PRE>
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static List<Menu> getTree(Long topId, @SuppressWarnings("rawtypes") Collection entityList,String packageURL,String IDMethodName,int IDHierarchy, String NAMEMethodName,String PARENTIDMethodName,List<FirefightersTreeDto> list) throws Exception{ public static List<Menu> getTree(Long topId, @SuppressWarnings("rawtypes") Collection entityList, String packageURL, String IDMethodName, int IDHierarchy, String NAMEMethodName, String PARENTIDMethodName, List<FirefightersTreeDto> list) throws Exception {
List<Menu> resultList=new ArrayList<>(); List<Menu> resultList = new ArrayList<>();
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
Class clazz= Class.forName(packageURL); Class clazz = Class.forName(packageURL);
Method IDMethodNameme = null; Method IDMethodNameme = null;
switch (IDHierarchy) { case 1: switch (IDHierarchy) {
IDMethodNameme = clazz.getDeclaredMethod(IDMethodName); case 1:
break; IDMethodNameme = clazz.getDeclaredMethod(IDMethodName);
case 2: break;
IDMethodNameme = clazz.getSuperclass().getDeclaredMethod(IDMethodName); case 2:
break; IDMethodNameme = clazz.getSuperclass().getDeclaredMethod(IDMethodName);
case 3: break;
IDMethodNameme = clazz.getSuperclass().getSuperclass().getDeclaredMethod(IDMethodName); case 3:
break; IDMethodNameme = clazz.getSuperclass().getSuperclass().getDeclaredMethod(IDMethodName);
default: break;
IDMethodNameme = clazz.getDeclaredMethod(IDMethodName); default:
break; IDMethodNameme = clazz.getDeclaredMethod(IDMethodName);
} break;
}
Method NAMEMethodNameme = clazz.getDeclaredMethod(NAMEMethodName);
Method PARENTIDMethodNameme = clazz.getDeclaredMethod(PARENTIDMethodName); Method NAMEMethodNameme = clazz.getDeclaredMethod(NAMEMethodName);
Method PARENTIDMethodNameme = clazz.getDeclaredMethod(PARENTIDMethodName);
//获取顶层元素集合 //获取顶层元素集合
Long parentId; Long parentId;
for (Object ob : entityList) { for (Object ob : entityList) {
Object entity = clazz.cast(ob); Object entity = clazz.cast(ob);
parentId=PARENTIDMethodNameme.invoke(entity)!=null? Long.valueOf(String.valueOf(PARENTIDMethodNameme.invoke(entity))):null; parentId = PARENTIDMethodNameme.invoke(entity) != null ? Long.valueOf(String.valueOf(PARENTIDMethodNameme.invoke(entity))) : null;
if(parentId==null||topId==parentId){ if (parentId == null || topId == parentId) {
String codeString= String.valueOf(IDMethodNameme.invoke(entity)); String codeString = String.valueOf(IDMethodNameme.invoke(entity));
Integer num=0; Integer num = 0;
if(list!=null&&list.size()>0) { if (list != null && list.size() > 0) {
for (FirefightersTreeDto map : list) { for (FirefightersTreeDto map : list) {
if(map.getJobTitleCode().equals(codeString) ){ if (map.getJobTitleCode().equals(codeString)) {
num=Integer.valueOf((String) map.getNum()); num = Integer.valueOf((String) map.getNum());
break; break;
} }
}; }
;
}
Menu menu = new Menu(Long.valueOf(codeString), String.valueOf(NAMEMethodNameme.invoke(entity)), parentId, num);
resultList.add(menu);
} }
Menu menu=new Menu(Long.valueOf(codeString), String.valueOf(NAMEMethodNameme.invoke(entity)), parentId,num); }
resultList.add(menu);
}
}
//获取每个顶层元素的子数据集合 //获取每个顶层元素的子数据集合
for (Menu entity : resultList) { for (Menu entity : resultList) {
entity.setChildren(getSub(entity.getId(), entityList, packageURL, IDMethodName,IDHierarchy, NAMEMethodName, PARENTIDMethodName,list)); entity.setChildren(getSub(entity.getId(), entityList, packageURL, IDMethodName, IDHierarchy, NAMEMethodName, PARENTIDMethodName, list));
} }
return resultList; return resultList;
} }
/** /**
* 获取子数据集合 * 获取子数据集合
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private static List<Menu> getSub(Long topId, @SuppressWarnings("rawtypes") Collection entityList,String packageURL,String IDMethodName,int IDHierarchy,String NAMEMethodName,String PARENTIDMethodName ,List<FirefightersTreeDto> list) throws Exception{ private static List<Menu> getSub(Long topId, @SuppressWarnings("rawtypes") Collection entityList, String packageURL, String IDMethodName, int IDHierarchy, String NAMEMethodName, String PARENTIDMethodName, List<FirefightersTreeDto> list) throws Exception {
List<Menu> childList=new ArrayList<>(); List<Menu> childList = new ArrayList<>();
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
Class clazz= Class.forName(packageURL); Class clazz = Class.forName(packageURL);
Method IDMethodNameme = null; Method IDMethodNameme = null;
switch (IDHierarchy) { switch (IDHierarchy) {
case 1: case 1:
IDMethodNameme = clazz.getDeclaredMethod(IDMethodName); IDMethodNameme = clazz.getDeclaredMethod(IDMethodName);
break; break;
case 2: case 2:
IDMethodNameme = clazz.getSuperclass().getDeclaredMethod(IDMethodName); IDMethodNameme = clazz.getSuperclass().getDeclaredMethod(IDMethodName);
break; break;
case 3: case 3:
IDMethodNameme = clazz.getSuperclass().getSuperclass().getDeclaredMethod(IDMethodName); IDMethodNameme = clazz.getSuperclass().getSuperclass().getDeclaredMethod(IDMethodName);
break; break;
default: default:
IDMethodNameme = clazz.getDeclaredMethod(IDMethodName); IDMethodNameme = clazz.getDeclaredMethod(IDMethodName);
break; break;
} }
Method NAMEMethodNameme = clazz.getDeclaredMethod(NAMEMethodName); Method NAMEMethodNameme = clazz.getDeclaredMethod(NAMEMethodName);
Method PARENTIDMethodNameme = clazz.getDeclaredMethod(PARENTIDMethodName); Method PARENTIDMethodNameme = clazz.getDeclaredMethod(PARENTIDMethodName);
Long parentId; Long parentId;
//子集的直接子对象 //子集的直接子对象
for (Object ob : entityList) { for (Object ob : entityList) {
Object entity = clazz.cast(ob); Object entity = clazz.cast(ob);
parentId=PARENTIDMethodNameme.invoke(entity)!=null? Long.valueOf(String.valueOf(PARENTIDMethodNameme.invoke(entity))):null; parentId = PARENTIDMethodNameme.invoke(entity) != null ? Long.valueOf(String.valueOf(PARENTIDMethodNameme.invoke(entity))) : null;
if(parentId==null) { if (parentId == null) {
if(topId==parentId){ if (topId == parentId) {
String codeString= String.valueOf(IDMethodNameme.invoke(entity)); String codeString = String.valueOf(IDMethodNameme.invoke(entity));
Integer num=0; Integer num = 0;
if(list!=null&&list.size()>0) { if (list != null && list.size() > 0) {
for (FirefightersTreeDto map : list) { for (FirefightersTreeDto map : list) {
if(map.getJobTitleCode().equals(codeString) ){ if (map.getJobTitleCode().equals(codeString)) {
num=Integer.valueOf((String) map.getNum()); num = Integer.valueOf((String) map.getNum());
break; break;
} }
}; }
;
}
Menu menu=new Menu(Long.valueOf(codeString), String.valueOf(NAMEMethodNameme.invoke(entity)), parentId,num); }
childList.add(menu); Menu menu = new Menu(Long.valueOf(codeString), String.valueOf(NAMEMethodNameme.invoke(entity)), parentId, num);
} childList.add(menu);
}else { }
if(topId.longValue()==parentId.longValue()){ } else {
if (topId.longValue() == parentId.longValue()) {
String codeString= String.valueOf(IDMethodNameme.invoke(entity));
Integer num=0; String codeString = String.valueOf(IDMethodNameme.invoke(entity));
if(list!=null&&list.size()>0) { Integer num = 0;
for (FirefightersTreeDto map : list) { if (list != null && list.size() > 0) {
if(map.getJobTitleCode().equals(codeString) ){ for (FirefightersTreeDto map : list) {
num=Integer.valueOf((String) map.getNum()); if (map.getJobTitleCode().equals(codeString)) {
break; num = Integer.valueOf((String) map.getNum());
} break;
}; }
}
} ;
Menu menu=new Menu(Long.valueOf(codeString), String.valueOf(NAMEMethodNameme.invoke(entity)), parentId,num);
childList.add(menu); }
} Menu menu = new Menu(Long.valueOf(codeString), String.valueOf(NAMEMethodNameme.invoke(entity)), parentId, num);
} childList.add(menu);
}
} }
}
//子集的间接子对象 //子集的间接子对象
for (Menu entity : childList) { for (Menu entity : childList) {
entity.setChildren(getSub(entity.getId(), entityList, packageURL, IDMethodName,IDHierarchy, NAMEMethodName, PARENTIDMethodName,list)); entity.setChildren(getSub(entity.getId(), entityList, packageURL, IDMethodName, IDHierarchy, NAMEMethodName, PARENTIDMethodName, list));
} }
//递归退出条件 //递归退出条件
if(childList.size()==0){ if (childList.size() == 0) {
return null; return null;
} }
return childList; return childList;
} }
/** /**
* @param topId 父id * @param topId 父id
* @param entityList 数据集合 * @param entityList 数据集合
* @param packageURL 集合对象包名+类名 * @param packageURL 集合对象包名+类名
* @param IDMethodName 集合对象获取树id 方法名 * @param IDMethodName 集合对象获取树id 方法名
* @param IDHierarchy 集合对象获取树id 来源于自己 还是父级( 1自己,2 父级 ,3 父级的父级) * @param IDHierarchy 集合对象获取树id 来源于自己 还是父级( 1自己,2 父级 ,3 父级的父级)
* @param NAMEMethodName 集合对象获取树name 方法名 * @param NAMEMethodName 集合对象获取树name 方法名
* @param PARENTIDMethodName 集合对象获取树父id 方法名 * @param PARENTIDMethodName 集合对象获取树父id 方法名
* @return java.util.List<com.yeejoin.amos.boot.module.jcs.api.vo.Menu> * @return java.util.List<com.yeejoin.amos.boot.module.jcs.api.vo.Menu>
* <PRE> * <PRE>
* author tw * author tw
* date 2021/6/10 * date 2021/6/10
* </PRE> * </PRE>
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static List<MenuFrom> getTreexin(String topId, @SuppressWarnings("rawtypes") Collection entityList,String packageURL,String IDMethodName,int IDHierarchy, String NAMEMethodName,String PARENTIDMethodName ) throws Exception{ public static List<MenuFrom> getTreexin(String topId, @SuppressWarnings("rawtypes") Collection entityList,
List<MenuFrom> resultList=new ArrayList<>(); String packageURL, String IDMethodName, int IDHierarchy,
String NAMEMethodName, String PARENTIDMethodName,
String nodeTypeMethodName) throws Exception {
List<MenuFrom> resultList = new ArrayList<>();
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
Class clazz= Class.forName(packageURL); Class clazz = Class.forName(packageURL);
Method IDMethodNameme = null; Method IDMethodNameme = null;
switch (IDHierarchy) { case 1: switch (IDHierarchy) {
IDMethodNameme = clazz.getDeclaredMethod(IDMethodName); case 1:
break; IDMethodNameme = clazz.getDeclaredMethod(IDMethodName);
case 2: break;
IDMethodNameme = clazz.getSuperclass().getDeclaredMethod(IDMethodName); case 2:
break; IDMethodNameme = clazz.getSuperclass().getDeclaredMethod(IDMethodName);
case 3: break;
IDMethodNameme = clazz.getSuperclass().getSuperclass().getDeclaredMethod(IDMethodName); case 3:
break; IDMethodNameme = clazz.getSuperclass().getSuperclass().getDeclaredMethod(IDMethodName);
default: break;
IDMethodNameme = clazz.getDeclaredMethod(IDMethodName); default:
break; IDMethodNameme = clazz.getDeclaredMethod(IDMethodName);
} break;
}
Method NAMEMethodNameme = clazz.getDeclaredMethod(NAMEMethodName);
Method PARENTIDMethodNameme = clazz.getDeclaredMethod(PARENTIDMethodName); Method NAMEMethodNameme = clazz.getDeclaredMethod(NAMEMethodName);
//获取顶层元素集合 Method PARENTIDMethodNameme = clazz.getDeclaredMethod(PARENTIDMethodName);
String parentId; Method nodeTypeMethod = null;
for (Object ob : entityList) { if (!ValidationUtil.isEmpty(nodeTypeMethodName)) {
nodeTypeMethod = clazz.getDeclaredMethod(nodeTypeMethodName);
Object entity = clazz.cast(ob); }
//获取顶层元素集合
parentId=PARENTIDMethodNameme.invoke(entity)!=null? String.valueOf(PARENTIDMethodNameme.invoke(entity)):null; String parentId;
for (Object ob : entityList) {
if(parentId==null||parentId.equals(topId)){
MenuFrom menu=new MenuFrom(String.valueOf(IDMethodNameme.invoke(entity)),String.valueOf(IDMethodNameme.invoke(entity)),String.valueOf(IDMethodNameme.invoke(entity)), String.valueOf(NAMEMethodNameme.invoke(entity)),String.valueOf(NAMEMethodNameme.invoke(entity)), String.valueOf(NAMEMethodNameme.invoke(entity)),parentId); Object entity = clazz.cast(ob);
resultList.add(menu);
} parentId = PARENTIDMethodNameme.invoke(entity) != null ? String.valueOf(PARENTIDMethodNameme.invoke(entity)) : null;
}
if (parentId == null || parentId.equals(topId)) {
MenuFrom menu = new MenuFrom(String.valueOf(IDMethodNameme.invoke(entity)),
String.valueOf(IDMethodNameme.invoke(entity)), String.valueOf(IDMethodNameme.invoke(entity)),
String.valueOf(NAMEMethodNameme.invoke(entity)),
String.valueOf(NAMEMethodNameme.invoke(entity)),
String.valueOf(NAMEMethodNameme.invoke(entity)), parentId,
String.valueOf(nodeTypeMethod == null ? "0" : nodeTypeMethod.invoke(entity)));
resultList.add(menu);
}
}
//获取每个顶层元素的子数据集合 //获取每个顶层元素的子数据集合
for (MenuFrom entity : resultList) { for (MenuFrom entity : resultList) {
List<MenuFrom> list=getSubxin(entity.getKey(), entityList, packageURL, IDMethodName,IDHierarchy, NAMEMethodName, PARENTIDMethodName); List<MenuFrom> list = getSubxin(entity.getKey(), entityList, packageURL, IDMethodName, IDHierarchy,
if(list!=null&&list.size()>0) { NAMEMethodName, PARENTIDMethodName, nodeTypeMethodName);
entity.setIsLeaf(false); if (list != null && list.size() > 0) {
} entity.setIsLeaf(false);
entity.setChildren(list); }
} entity.setChildren(list);
}
return resultList;
} return resultList;
}
/**
* 获取子数据集合 /**
*/ * 获取子数据集合
*/
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private static List<MenuFrom> getSubxin(String topId, @SuppressWarnings("rawtypes") Collection entityList,String packageURL,String IDMethodName,int IDHierarchy,String NAMEMethodName,String PARENTIDMethodName ) throws Exception{ private static List<MenuFrom> getSubxin(String topId, @SuppressWarnings("rawtypes") Collection entityList,
List<MenuFrom> childList=new ArrayList<>(); String packageURL, String IDMethodName, int IDHierarchy,
@SuppressWarnings("rawtypes") String NAMEMethodName, String PARENTIDMethodName,
Class clazz= Class.forName(packageURL); String nodeTypeMethodName) throws Exception {
Method IDMethodNameme = null; List<MenuFrom> childList = new ArrayList<>();
switch (IDHierarchy) { @SuppressWarnings("rawtypes")
case 1: Class clazz = Class.forName(packageURL);
IDMethodNameme = clazz.getDeclaredMethod(IDMethodName); Method IDMethodNameme = null;
break; switch (IDHierarchy) {
case 2: case 1:
IDMethodNameme = clazz.getSuperclass().getDeclaredMethod(IDMethodName); IDMethodNameme = clazz.getDeclaredMethod(IDMethodName);
break; break;
case 3: case 2:
IDMethodNameme = clazz.getSuperclass().getSuperclass().getDeclaredMethod(IDMethodName); IDMethodNameme = clazz.getSuperclass().getDeclaredMethod(IDMethodName);
break; break;
default: case 3:
IDMethodNameme = clazz.getDeclaredMethod(IDMethodName); IDMethodNameme = clazz.getSuperclass().getSuperclass().getDeclaredMethod(IDMethodName);
break; break;
} default:
Method NAMEMethodNameme = clazz.getDeclaredMethod(NAMEMethodName); IDMethodNameme = clazz.getDeclaredMethod(IDMethodName);
Method PARENTIDMethodNameme = clazz.getDeclaredMethod(PARENTIDMethodName); break;
String parentId; }
Method NAMEMethodNameme = clazz.getDeclaredMethod(NAMEMethodName);
Method PARENTIDMethodNameme = clazz.getDeclaredMethod(PARENTIDMethodName);
Method nodeTypeMethod = null;
if (!ValidationUtil.isEmpty(nodeTypeMethodName)) {
nodeTypeMethod = clazz.getDeclaredMethod(nodeTypeMethodName);
}
String parentId;
//子集的直接子对象 //子集的直接子对象
for (Object ob : entityList) { for (Object ob : entityList) {
Object entity = clazz.cast(ob); Object entity = clazz.cast(ob);
parentId=PARENTIDMethodNameme.invoke(entity)!=null? String.valueOf(PARENTIDMethodNameme.invoke(entity)):null; parentId = PARENTIDMethodNameme.invoke(entity) != null ? String.valueOf(PARENTIDMethodNameme.invoke(entity)) : null;
if(parentId==null) { if (parentId == null) {
if(parentId==topId){ if (parentId == topId) {
MenuFrom menu=new MenuFrom(String.valueOf(IDMethodNameme.invoke(entity)),String.valueOf(IDMethodNameme.invoke(entity)),String.valueOf(IDMethodNameme.invoke(entity)), String.valueOf(NAMEMethodNameme.invoke(entity)),String.valueOf(NAMEMethodNameme.invoke(entity)), String.valueOf(NAMEMethodNameme.invoke(entity)),parentId); MenuFrom menu = new MenuFrom(String.valueOf(IDMethodNameme.invoke(entity)),
childList.add(menu); String.valueOf(IDMethodNameme.invoke(entity)), String.valueOf(IDMethodNameme.invoke(entity)),
} String.valueOf(NAMEMethodNameme.invoke(entity)),
}else { String.valueOf(NAMEMethodNameme.invoke(entity)),
if(topId!=null&&topId.equals(parentId)){ String.valueOf(NAMEMethodNameme.invoke(entity)), parentId,
MenuFrom menu=new MenuFrom(String.valueOf(IDMethodNameme.invoke(entity)),String.valueOf(IDMethodNameme.invoke(entity)),String.valueOf(IDMethodNameme.invoke(entity)), String.valueOf(NAMEMethodNameme.invoke(entity)),String.valueOf(NAMEMethodNameme.invoke(entity)), String.valueOf(NAMEMethodNameme.invoke(entity)),parentId); String.valueOf(nodeTypeMethod == null ? "0" : nodeTypeMethod.invoke(entity)));
menu.setIsLeaf(false); childList.add(menu);
childList.add(menu); }
} } else {
} if (topId != null && topId.equals(parentId)) {
MenuFrom menu = new MenuFrom(String.valueOf(IDMethodNameme.invoke(entity)),
} String.valueOf(IDMethodNameme.invoke(entity)),
String.valueOf(IDMethodNameme.invoke(entity)),
String.valueOf(NAMEMethodNameme.invoke(entity)),
String.valueOf(NAMEMethodNameme.invoke(entity)),
String.valueOf(NAMEMethodNameme.invoke(entity)), parentId,
String.valueOf(nodeTypeMethod == null ? "0" : nodeTypeMethod.invoke(entity)));
menu.setIsLeaf(false);
childList.add(menu);
}
}
}
//子集的间接子对象 //子集的间接子对象
for (MenuFrom entity : childList) { for (MenuFrom entity : childList) {
entity.setChildren(getSubxin(entity.getKey(), entityList, packageURL, IDMethodName,IDHierarchy, NAMEMethodName, PARENTIDMethodName)); entity.setChildren(getSubxin(entity.getKey(), entityList, packageURL, IDMethodName, IDHierarchy,
} NAMEMethodName, PARENTIDMethodName, nodeTypeMethodName));
}
//递归退出条件 //递归退出条件
if(childList.size()==0){ if (childList.size() == 0) {
return null; return null;
} }
return childList; return childList;
} }
} }
...@@ -21,4 +21,10 @@ public class FireTeamListDto { ...@@ -21,4 +21,10 @@ public class FireTeamListDto {
@ApiModelProperty(value = "父级id") @ApiModelProperty(value = "父级id")
private Long parent; private Long parent;
@ApiModelProperty(value = "树节点类型(1:单位,0:队伍)")
private String nodeType;
@ApiModelProperty(value = "树节点id")
private Long id;
} }
...@@ -26,10 +26,12 @@ ...@@ -26,10 +26,12 @@
cb_fire_team a cb_fire_team a
WHERE WHERE
a.is_delete = 0 a.is_delete = 0
<if test='par.parent!=null'>and a.parent = #{par.parent}</if> <if test='par.parent != null'>and a.parent = #{par.parent}</if>
<if test='par.typeCode!=null'>and a.type_code = #{par.typeCode}</if> <if test='par.typeCode != null'>and a.type_code = #{par.typeCode}</if>
<if test='par.companyCode!=null'>and a.company_code = #{par.companyCode}</if> <if test='par.companyCode != null'>and a.company_code = #{par.companyCode}</if>
<if test='par.name!=null'>and a.name like concat('%', #{par.name}, '%')</if> <if test='par.name != null'>and a.name like concat('%', #{par.name}, '%')</if>
<if test='par.nodeType != null and par.nodeType == "1"'>and a.company = #{par.id}</if>
<if test='par.nodeType != null and par.nodeType == "0"'>and a.parent = #{par.id}</if>
</select> </select>
<select id="listFireTeamDto" resultType="com.yeejoin.amos.boot.module.common.api.dto.FireTeamDto"> <select id="listFireTeamDto" resultType="com.yeejoin.amos.boot.module.common.api.dto.FireTeamDto">
......
...@@ -211,8 +211,9 @@ public class DataDictionaryController extends BaseController { ...@@ -211,8 +211,9 @@ public class DataDictionaryController extends BaseController {
return ResponseHelper.buildResponse(obj); return ResponseHelper.buildResponse(obj);
}else{ }else{
Collection<DataDictionary> list=iDataDictionaryService.list(queryWrapper); Collection<DataDictionary> list=iDataDictionaryService.list(queryWrapper);
List<MenuFrom> menus =TreeParser.getTreexin(null, list, DataDictionary.class.getName(),"getCode",0, "getName", "getParent"); List<MenuFrom> menus =TreeParser.getTreexin(null, list, DataDictionary.class.getName(),"getCode",0,
MenuFrom Me= new MenuFrom( "-1", "-1", "-1", "危化品库", "危化品库", "危化品库", "-1"); "getName", "getParent", "getNodeType");
MenuFrom Me= new MenuFrom( "-1", "-1", "-1", "危化品库", "危化品库", "危化品库", "-1", null);
Me.setIsLeaf(false); Me.setIsLeaf(false);
Me.setChildren(menus); Me.setChildren(menus);
redisUtils.set(RedisKey.DATA_DICTIONARY_CODE+type, JSON.toJSON(Me),time); redisUtils.set(RedisKey.DATA_DICTIONARY_CODE+type, JSON.toJSON(Me),time);
...@@ -240,7 +241,8 @@ public class DataDictionaryController extends BaseController { ...@@ -240,7 +241,8 @@ public class DataDictionaryController extends BaseController {
}else{ }else{
Collection<DataDictionary> list=iDataDictionaryService.list(queryWrapper); Collection<DataDictionary> list=iDataDictionaryService.list(queryWrapper);
List<MenuFrom> menus = null; List<MenuFrom> menus = null;
menus = TreeParser.getTreexin(null, list, DataDictionary.class.getName(),"getCode",0, "getName", "getParent"); menus = TreeParser.getTreexin(null, list, DataDictionary.class.getName(),"getCode",0, "getName",
"getParent", "getNodeType");
redisUtils.set(RedisKey.DATA_DICTIONARY_CODE_XIN+type, JSON.toJSON(menus),time); redisUtils.set(RedisKey.DATA_DICTIONARY_CODE_XIN+type, JSON.toJSON(menus),time);
objectObjectHashMap.put(type,menus); objectObjectHashMap.put(type,menus);
} }
......
...@@ -30,7 +30,7 @@ public class EquipmentServiceImpl { ...@@ -30,7 +30,7 @@ public class EquipmentServiceImpl {
List<Map<String, Object>> fireSystemMapList = (List<Map<String, Object>>) response.getResult(); List<Map<String, Object>> fireSystemMapList = (List<Map<String, Object>>) response.getResult();
List<MenuFrom> fireSystemDtoList = Lists.newArrayList(); List<MenuFrom> fireSystemDtoList = Lists.newArrayList();
fireSystemMapList.forEach(system -> { fireSystemMapList.forEach(system -> {
MenuFrom menuFrom = new MenuFrom((String) system.get("id"), (String) system.get("name"), "0"); MenuFrom menuFrom = new MenuFrom((String) system.get("id"), (String) system.get("name"), "0", "0");
fireSystemDtoList.add(menuFrom); fireSystemDtoList.add(menuFrom);
}); });
return fireSystemDtoList; return fireSystemDtoList;
...@@ -45,7 +45,8 @@ public class EquipmentServiceImpl { ...@@ -45,7 +45,8 @@ public class EquipmentServiceImpl {
List<Map<String, Object>> buildingMapList = (List<Map<String, Object>>) response.getResult(); List<Map<String, Object>> buildingMapList = (List<Map<String, Object>>) response.getResult();
List<MenuFrom> buildingTreeList = Lists.newArrayList(); List<MenuFrom> buildingTreeList = Lists.newArrayList();
buildingMapList.forEach(building -> { buildingMapList.forEach(building -> {
MenuFrom menuFrom = new MenuFrom((String) building.get("id"), "全部建筑", (String) building.get("parentId")); MenuFrom menuFrom = new MenuFrom((String) building.get("id"), "全部建筑", (String) building.get("parentId"),
"0");
List<Map<String, Object>> children = (List<Map<String, Object>>) building.get("children"); List<Map<String, Object>> children = (List<Map<String, Object>>) building.get("children");
menuFrom.setChildren(parseTree(menuFrom, children)); menuFrom.setChildren(parseTree(menuFrom, children));
menuFrom.setIsLeaf(false); menuFrom.setIsLeaf(false);
...@@ -58,7 +59,8 @@ public class EquipmentServiceImpl { ...@@ -58,7 +59,8 @@ public class EquipmentServiceImpl {
List<MenuFrom> menuFromList = Lists.newArrayList(); List<MenuFrom> menuFromList = Lists.newArrayList();
if (!ValidationUtil.isEmpty(children)) { if (!ValidationUtil.isEmpty(children)) {
children.forEach(child -> { children.forEach(child -> {
MenuFrom menuFrom = new MenuFrom((String) child.get("id"), (String) child.get("name"), (String) child.get("parentId")); MenuFrom menuFrom = new MenuFrom((String) child.get("id"), (String) child.get("name"),
(String) child.get("parentId"), "0");
if (!ValidationUtil.isEmpty(child.get("children"))) { if (!ValidationUtil.isEmpty(child.get("children"))) {
parseTree(menuFrom, (List<Map<String, Object>>) child.get("children")); parseTree(menuFrom, (List<Map<String, Object>>) child.get("children"));
} else { } else {
......
...@@ -14,7 +14,6 @@ import com.yeejoin.amos.boot.module.common.api.dto.FireTeamListDto; ...@@ -14,7 +14,6 @@ import com.yeejoin.amos.boot.module.common.api.dto.FireTeamListDto;
import com.yeejoin.amos.boot.module.common.api.entity.FireTeam; import com.yeejoin.amos.boot.module.common.api.entity.FireTeam;
import com.yeejoin.amos.boot.module.common.api.entity.OrgUsr; import com.yeejoin.amos.boot.module.common.api.entity.OrgUsr;
import com.yeejoin.amos.boot.module.common.api.mapper.FireTeamMapper; import com.yeejoin.amos.boot.module.common.api.mapper.FireTeamMapper;
import com.yeejoin.amos.boot.module.common.api.mapper.OrgUsrMapper;
import com.yeejoin.amos.boot.module.common.api.service.IFireTeamService; import com.yeejoin.amos.boot.module.common.api.service.IFireTeamService;
import com.yeejoin.amos.boot.module.common.biz.service.impl.OrgUsrServiceImpl; import com.yeejoin.amos.boot.module.common.biz.service.impl.OrgUsrServiceImpl;
import com.yeejoin.amos.boot.module.jcs.api.feign.EquipFeignClient; import com.yeejoin.amos.boot.module.jcs.api.feign.EquipFeignClient;
...@@ -29,7 +28,6 @@ import java.util.Collection; ...@@ -29,7 +28,6 @@ import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream;
/** /**
* 消防队伍 服务实现类 * 消防队伍 服务实现类
...@@ -112,7 +110,7 @@ public class FireTeamServiceImpl extends BaseService<FireTeamDto, FireTeam, Fire ...@@ -112,7 +110,7 @@ public class FireTeamServiceImpl extends BaseService<FireTeamDto, FireTeam, Fire
* @return * @return
*/ */
public List<MenuFrom> getCompanyTeamTree() throws Exception { public List<MenuFrom> getCompanyTeamTree() throws Exception {
MenuFrom root = new MenuFrom("-1", "消防队伍", null); MenuFrom root = new MenuFrom("-1", "消防队伍", null, null);
// 机场单位 // 机场单位
List<OrgUsr> companyDeptList = orgUsrService.selectCompanyDepartmentMsg(); List<OrgUsr> companyDeptList = orgUsrService.selectCompanyDepartmentMsg();
List<MenuFrom> companyDeptMenuList = Lists.newArrayList(); List<MenuFrom> companyDeptMenuList = Lists.newArrayList();
...@@ -120,7 +118,8 @@ public class FireTeamServiceImpl extends BaseService<FireTeamDto, FireTeam, Fire ...@@ -120,7 +118,8 @@ public class FireTeamServiceImpl extends BaseService<FireTeamDto, FireTeam, Fire
if (ValidationUtil.isEmpty(o.getParentId())) { if (ValidationUtil.isEmpty(o.getParentId())) {
o.setParentId("-1"); o.setParentId("-1");
} }
companyDeptMenuList.add(new MenuFrom(o.getSequenceNbr().toString(), o.getBizOrgName(), o.getParentId())); companyDeptMenuList.add(new MenuFrom(o.getSequenceNbr().toString(), o.getBizOrgName(), o.getParentId(),
"1"));
}); });
// 消防队伍 // 消防队伍
List<MenuFrom> teamMenuList = Lists.newArrayList(); List<MenuFrom> teamMenuList = Lists.newArrayList();
...@@ -130,12 +129,12 @@ public class FireTeamServiceImpl extends BaseService<FireTeamDto, FireTeam, Fire ...@@ -130,12 +129,12 @@ public class FireTeamServiceImpl extends BaseService<FireTeamDto, FireTeam, Fire
// 将单位下没有上级队伍的队伍直接挂在单位下(方便组成树结构) // 将单位下没有上级队伍的队伍直接挂在单位下(方便组成树结构)
team.setParent(team.getCompany()); team.setParent(team.getCompany());
} }
teamMenuList.add(new MenuFrom(team.getSequenceNbr().toString(), team.getName(), team.getParent().toString())); teamMenuList.add(new MenuFrom(team.getSequenceNbr().toString(), team.getName(),
team.getParent().toString(), "1"));
}); });
companyDeptMenuList.addAll(teamMenuList); companyDeptMenuList.addAll(teamMenuList);
List<MenuFrom> menuList = TreeParser.getTreexin("-1", companyDeptMenuList, MenuFrom.class.getName(), "getKey", List<MenuFrom> menuList = TreeParser.getTreexin("-1", companyDeptMenuList, MenuFrom.class.getName(), "getKey",
1, "getName", 1, "getName", "getParentId", "getNodeType");
"getParentId");
root.setChildren(menuList); root.setChildren(menuList);
return Lists.newArrayList(root); return Lists.newArrayList(root);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment