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

4
src/main/resources/application.yml

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