拆分列表
This commit is contained in:
+95
@@ -22,6 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @Description: 文档对比信息表
|
||||
@@ -304,9 +305,103 @@ public class SarFileCompareInfoServiceImpl extends ServiceImpl<SarFileCompareInf
|
||||
sfVo.addTextRight(item);
|
||||
}
|
||||
}
|
||||
//修改标准目录顺序结构
|
||||
// List<SarFileCompareMenuVo> menuLeft = this.tree(sfVo.getMenuLeft());
|
||||
// List<SarFileCompareMenuVo> menuRight = this.tree(sfVo.getMenuRight());
|
||||
// sfVo.setMenuLeft(menuLeft);
|
||||
// sfVo.setMenuRight(menuRight);
|
||||
return sfVo;
|
||||
}
|
||||
|
||||
private List<SarFileCompareMenuVo> tree(List<SarFileCompareMenuVo> list) {
|
||||
List<SarFileCompareMenuVo> compareMenuVos = new ArrayList<>();
|
||||
//先删除name是总目录的数据
|
||||
list = list.get(0).getChildren();
|
||||
/**
|
||||
* 根节点:
|
||||
* 1、没有"."
|
||||
* 2、其他对象都不等于 最后一个"."之前的数据
|
||||
*/
|
||||
|
||||
//查询根节点是哪一级,也就是"."最少的那一层
|
||||
int least = 100;
|
||||
for (SarFileCompareMenuVo menuVo : list) {
|
||||
String name = menuVo.getName();
|
||||
int i = countCharacters(name);
|
||||
if (least > i){
|
||||
least = i;
|
||||
}
|
||||
}
|
||||
//把第一级放入compareMenuVos
|
||||
for (SarFileCompareMenuVo compareMenuVo : list) {
|
||||
String name = compareMenuVo.getName();
|
||||
int i = countCharacters(name);
|
||||
if (least == i){
|
||||
compareMenuVos.add(compareMenuVo);
|
||||
}
|
||||
}
|
||||
//遍历第一级,寻找第二级
|
||||
List<SarFileCompareMenuVo> two = new ArrayList<>();
|
||||
for (SarFileCompareMenuVo compareMenuVo : list) {
|
||||
String name = compareMenuVo.getName();
|
||||
int i = countCharacters(name);
|
||||
if (least + 1 == i){
|
||||
two.add(compareMenuVo);
|
||||
}
|
||||
}
|
||||
for (SarFileCompareMenuVo compareMenuVo : compareMenuVos) {
|
||||
String name = compareMenuVo.getName();
|
||||
int length = name.length();
|
||||
//找到所有以name为前缀的数据
|
||||
List<SarFileCompareMenuVo> menuVos = two.stream().filter(SarFileCompareMenuVo -> SarFileCompareMenuVo.getName().startsWith(name)).collect(Collectors.toList());
|
||||
compareMenuVo.setChildren(menuVos);
|
||||
}
|
||||
//遍历第二级,寻找第三级
|
||||
List<SarFileCompareMenuVo> three = new ArrayList<>();
|
||||
for (SarFileCompareMenuVo compareMenuVo : list) {
|
||||
String name = compareMenuVo.getName();
|
||||
int i = countCharacters(name);
|
||||
if (least + 2 == i){
|
||||
three.add(compareMenuVo);
|
||||
}
|
||||
}
|
||||
for (SarFileCompareMenuVo compareMenuVo : compareMenuVos) {
|
||||
List<SarFileCompareMenuVo> children = compareMenuVo.getChildren();
|
||||
for (SarFileCompareMenuVo child : children) {
|
||||
String name = child.getName();
|
||||
//找到所有以name为前缀的数据
|
||||
List<SarFileCompareMenuVo> menuVos = three.stream().filter(SarFileCompareMenuVo -> SarFileCompareMenuVo.getName().startsWith(name)).collect(Collectors.toList());
|
||||
child.setChildren(menuVos);
|
||||
}
|
||||
}
|
||||
//遍历第三级,寻找第四级
|
||||
List<SarFileCompareMenuVo> four = new ArrayList<>();
|
||||
for (SarFileCompareMenuVo compareMenuVo : list) {
|
||||
String name = compareMenuVo.getName();
|
||||
int i = countCharacters(name);
|
||||
if (least + 3 == i){
|
||||
four.add(compareMenuVo);
|
||||
}
|
||||
}
|
||||
for (SarFileCompareMenuVo compareMenuVo : compareMenuVos) {
|
||||
List<SarFileCompareMenuVo> children = compareMenuVo.getChildren();
|
||||
for (SarFileCompareMenuVo child : children) {
|
||||
List<SarFileCompareMenuVo> vos = child.getChildren();
|
||||
for (SarFileCompareMenuVo vo : vos) {
|
||||
String name = vo.getName();
|
||||
//找到所有以name为前缀的数据
|
||||
List<SarFileCompareMenuVo> menuVos = four.stream().filter(SarFileCompareMenuVo -> SarFileCompareMenuVo.getName().startsWith(name)).collect(Collectors.toList());
|
||||
vo.setChildren(menuVos);
|
||||
}
|
||||
}
|
||||
}
|
||||
return compareMenuVos;
|
||||
}
|
||||
|
||||
public int countCharacters(String str) {
|
||||
return Math.toIntExact(str.chars().filter(ch -> ch == '.').count());
|
||||
}
|
||||
|
||||
private List<SarFileCompareMenuVo> getMenuChildren(List<SarFileCompareMenu> menuList, String leftOrRight, String pid) {
|
||||
List<SarFileCompareMenuVo> list = new ArrayList<>();
|
||||
for (SarFileCompareMenu menu : menuList) {
|
||||
|
||||
Reference in New Issue
Block a user