Browse Source

修复树构造空指针异常bug

master
liwenxuan 3 weeks ago
parent
commit
bef5c7ae77
  1. 107
      src/main/java/com/hxgk/lowcode/service/impl/AppmenusSerciceImpl.java
  2. 4
      src/main/resources/application.yml

107
src/main/java/com/hxgk/lowcode/service/impl/AppmenusSerciceImpl.java

@ -1,5 +1,6 @@
package com.hxgk.lowcode.service.impl;
import com.alibaba.fastjson2.JSON;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.hxgk.lowcode.mapper.AppmenusMapper;
import com.hxgk.lowcode.model.entity.Appmenus;
@ -8,6 +9,8 @@ import com.hxgk.lowcode.model.entity.CustomerFormView;
import com.hxgk.lowcode.model.entity.Tree;
import com.hxgk.lowcode.service.AppmenusService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.ILoggerFactory;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -16,10 +19,14 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static com.mysql.cj.conf.PropertyKey.logger;
@Service
@DS("tidbintranetappplatform")
public class AppmenusSerciceImpl implements AppmenusService {
@Autowired
static
Logger logger;
@Autowired
AppmenusMapper appmenusMapper;
@Override
@ -125,47 +132,81 @@ public class AppmenusSerciceImpl implements AppmenusService {
}
public static Tree findChildren(Tree rootTree,List<Tree> list){
/*System.out.println("11111111111111111111111111111111111111111111111111111111111111111111111111111111111");
System.out.println(JSON.toJSONString(rootTree));
System.out.println(JSON.toJSONString(list));*/
//这个方法是在找rootTree的所有子节点,然后返回rootTree
for (Tree tree : list) {
if(rootTree.getId().equals(tree.getParentId())){
String cfid = (String)tree.getTreeAttrs().get("customerFormId");
if(tree.getTreeAttrs().get("tableStructure")!=null && !tree.getTreeAttrs().get("tableStructure").toString().equals("")){
if(list.size()>0&&StringUtils.isNotBlank(rootTree.getId())){
for (Tree tree : list) {
if(rootTree.getId().equals(tree.getParentId())){
String cfid = (String)tree.getTreeAttrs().get("customerFormId");
if(tree.getTreeAttrs().get("tableStructure")!=null && !tree.getTreeAttrs().get("tableStructure").toString().equals("")){
/*System.out.println("子表子表子表子表子表子表子表子表子表子表子表子表-----------------"+tree.getLabel());
System.out.println(tree.getTreeAttrs().get("tableStructure").toString());*/
String tableStructure = tree.getTreeAttrs().get("tableStructure").toString();
tableStructure = tableStructure.replace("{","");
tableStructure = tableStructure.replace("}","");
tableStructure = tableStructure.replace("\"","");
String[] tableStructureArr = StringUtils.splitByWholeSeparator(tableStructure, ",");
ArrayList<Tree> treeArrayList = new ArrayList<>();
for(String item1:tableStructureArr){
String l = StringUtils.splitByWholeSeparator(item1, ":")[1];
Tree tree3 = new Tree();
tree3.setLabel("子表-"+l);
tree3.setParentId(tree.getId());
tree3.setId(cfid+":zibiaoid-"+l);
tree3.setValue(tree3.getId());
treeArrayList.add(tree3);
String tableStructure = tree.getTreeAttrs().get("tableStructure").toString();
tableStructure = tableStructure.replace("{","");
tableStructure = tableStructure.replace("}","");
tableStructure = tableStructure.replace("\"","");
String[] tableStructureArr = StringUtils.splitByWholeSeparator(tableStructure, ",");
ArrayList<Tree> treeArrayList = new ArrayList<>();
for(String item1:tableStructureArr){
String l = StringUtils.splitByWholeSeparator(item1, ":")[1];
Tree tree3 = new Tree();
tree3.setLabel("子表-"+l);
tree3.setParentId(tree.getId());
tree3.setId(cfid+":zibiaoid-"+l);
tree3.setValue(tree3.getId());
treeArrayList.add(tree3);
}
tree.setChildren(treeArrayList);
}
tree.setChildren(treeArrayList);
}
if(((Integer) tree.getTreeAttrs().get("isLock")==2)&&((Integer)tree.getTreeAttrs().get("type")==2)){
tree.setDisabled(false);
tree.setId((String)tree.getTreeAttrs().get("customerFormId"));
tree.setLabel("Form-"+tree.getLabel());
}else{
tree.setLabel("目录-"+tree.getLabel());
tree.setDisabled(true);
}
if(rootTree.getChildren() == null){
rootTree.setChildren(new ArrayList<>());
if(((Integer) tree.getTreeAttrs().get("isLock")==2)&&((Integer)tree.getTreeAttrs().get("type")==2)){
tree.setDisabled(false);
tree.setId((String)tree.getTreeAttrs().get("customerFormId"));
tree.setLabel("Form-"+tree.getLabel());
}else{
tree.setLabel("目录-"+tree.getLabel());
tree.setDisabled(true);
}
if(rootTree.getChildren() == null){
rootTree.setChildren(new ArrayList<>());
}
// 把这个节点tree作为新的根节点继续向下构造树,再把构造的结果作为rootTree的子节点
rootTree.getChildren().add(findChildren(tree,list));
}
// 把这个节点tree作为新的根节点继续向下构造树,再把构造的结果作为rootTree的子节点
rootTree.getChildren().add(findChildren(tree,list));
}
}else{
System.out.println("11111111111111111111111111111111111111111111111111111111111111111111111111111111111");
if(null!=rootTree){
System.out.println(JSON.toJSONString(rootTree));
}else{
System.out.println("rootTree 为 null");
}
if(null!=list){
System.out.println(JSON.toJSONString(list));
}else{
System.out.println("list 为 null");
}
/*if(null!=rootTree){
logger.error(JSON.toJSONString(rootTree));
}else{
logger.error("rootTree 为 null");
}
if(null!=list){
logger.error(JSON.toJSONString(list));
}else{
logger.error("list 为 null");
}*/
}
return rootTree;
}

4
src/main/resources/application.yml

@ -1,5 +1,5 @@
spring:
profiles:
active: prod
active: dev
server:
port: 39999
port: 8112
Loading…
Cancel
Save