|
@@ -6,6 +6,8 @@ import org.springblade.common.utils.INodeEx;
|
|
|
import org.springblade.manager.vo.ArchiveTreeContractVO2;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
|
|
+import java.lang.reflect.Field;
|
|
|
+import java.lang.reflect.Method;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.LinkedHashMap;
|
|
|
import java.util.List;
|
|
@@ -143,7 +145,10 @@ public class ForestNodeMergerEx {
|
|
|
getTreeList(dstTree,dstList);
|
|
|
|
|
|
boolean bRootMatch = true;
|
|
|
- if (dstTree.getFromId() != srcTree.getFromId()) {
|
|
|
+
|
|
|
+ if (dstTree.getFromId() == null ) {
|
|
|
+ bRootMatch = false;
|
|
|
+ }else if (!dstTree.getFromId().equals(srcTree.getId())) {
|
|
|
bRootMatch = false;
|
|
|
}
|
|
|
|
|
@@ -161,7 +166,7 @@ public class ForestNodeMergerEx {
|
|
|
if (srcDstMap.get(src.getId())!= null) {
|
|
|
continue;
|
|
|
}
|
|
|
- if (src.getId() == srcTree.getId() && bRootMatch == false) {
|
|
|
+ if (src.getId().equals(srcTree.getId()) && bRootMatch == false) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
@@ -232,4 +237,76 @@ public class ForestNodeMergerEx {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ public static void assignPropertyValue(Object obj, String propertyName, Object value)
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ // 获取对象的Class类型
|
|
|
+ Class<?> clazz = obj.getClass();
|
|
|
+ // 通过属性名获取类的成员变量
|
|
|
+ Field field = clazz.getDeclaredField(propertyName);
|
|
|
+ // 设置私有成员变量可访问
|
|
|
+ field.setAccessible(true);
|
|
|
+ // 给对象的属性赋值
|
|
|
+ field.set(obj, value);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Object getPropertyValue(Object obj, String propertyName) {
|
|
|
+ try {
|
|
|
+ Class<?> clazz = obj.getClass();
|
|
|
+ Method getterMethod = clazz.getMethod(getGetterName(propertyName));
|
|
|
+ return getterMethod.invoke(obj);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 根据属性名生成getter方法名
|
|
|
+ private static String getGetterName(String propertyName) {
|
|
|
+ return "get" + propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public static <T extends INodeEx<T>> List<T> setPropertyfromId(List<T> NodeList, Map<String,String> propertyMap)
|
|
|
+ {
|
|
|
+ List<T> changeList = new ArrayList<>();
|
|
|
+ Map<Long,Long> oldNewMap = new LinkedHashMap<>();
|
|
|
+
|
|
|
+ for (T node: NodeList) {
|
|
|
+ if (node.getFromId() != null) {
|
|
|
+ oldNewMap.put(node.getFromId(),node.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for (T node: NodeList) {
|
|
|
+ if (node.getFromId() == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ boolean bSet = false;
|
|
|
+
|
|
|
+ for (String fieldName: propertyMap.keySet()) {
|
|
|
+ Object obj = getPropertyValue(node,fieldName);
|
|
|
+ if (obj != null ) {
|
|
|
+ Long newId = oldNewMap.get(obj);
|
|
|
+ if (newId != null ) {
|
|
|
+ assignPropertyValue(node,fieldName,newId);
|
|
|
+ bSet = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (bSet){
|
|
|
+ changeList.add(node);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return changeList;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|