huangjn před 3 roky
rodič
revize
8a5406bd4f

+ 50 - 4
blade-service/blade-business/src/main/java/org/springblade/business/controller/TreeContractFirstController.java

@@ -38,9 +38,7 @@ import org.springblade.business.entity.TreeContractFirst;
 import org.springblade.business.service.ITreeContractFirstService;
 import org.springblade.core.boot.ctrl.BladeController;
 
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -251,7 +249,55 @@ public class TreeContractFirstController extends BladeController {
 		//获取所有子节点
 		List<WbsTreeContract> childList = this.wbsTreeContractClient.queryCurrentNodeAllChild(Long.parseLong(currentNode.getContractId()), currentNode.getId());
 		if(childList != null && childList.size() != 0){
-			childList.forEach(child -> childIds.append(",").append(child.getPKeyId()));
+			//首先找到当前节点下的第一级子节点
+			Map<String,StringBuilder> idMap = new HashMap<>();
+			Map<String, WbsTreeContract> treeMap = new HashMap<>();
+			//一级子节点的primaryKeyId
+			StringBuilder oneChild = new StringBuilder();
+			childList.forEach(node -> {
+				treeMap.put(node.getPKeyId().toString(), node);
+				if(currentNode.getId().equals(node.getParentId())){
+					oneChild.append(",").append(node.getPKeyId());
+				}
+			});
+			idMap.put(currentNode.getPKeyId().toString(), oneChild);
+
+			String[] childArray =  oneChild.toString().split(",");
+			for(String childPKeyId : childArray){
+				//继续向下查询正确的子节点
+				this.foreachQueryChild(childPKeyId, idMap, treeMap, childList);
+			}
+
+			//执行 foreachQueryChild 后idMap中就是所有正确子节点的排布,将其全部拼接进 childIds 中
+			Set<String> primaryKeys = idMap.keySet();
+			for(String key : primaryKeys){
+				childIds.append(",").append(idMap.get(key));
+			}
+		}
+	}
+
+	private void foreachQueryChild(String primaryKeyId, Map<String,StringBuilder> idMap, Map<String, WbsTreeContract> treeMap, List<WbsTreeContract> childList){
+		if(childList.size() > 0){
+			//获取当前节点
+			WbsTreeContract node = treeMap.get(primaryKeyId);
+			if(node != null){
+				//一级子节点的primaryKeyId
+				StringBuilder oneChild = new StringBuilder();
+
+				childList.forEach(child -> {
+					if(node.getId().equals(child.getParentId())){
+						oneChild.append(",").append(child.getPKeyId());
+
+						//工序为6,不会再存在下级节点
+						if(!new Integer("6").equals(child.getDeptCategory())){
+							//其子节点继续向下
+							this.foreachQueryChild(child.getPKeyId().toString(), idMap, treeMap, childList);
+						}
+					}
+				});
+
+				idMap.put(node.getPKeyId().toString(), oneChild);
+			}
 		}
 	}