|
@@ -27,14 +27,12 @@ import org.springblade.manager.mapper.WbsTreeContractMapper;
|
|
|
import org.springblade.manager.mapper.WbsTreePrivateMapper;
|
|
|
import org.springblade.manager.service.IWbsTreeContractService;
|
|
|
import org.springblade.manager.utils.DiffListUtil;
|
|
|
-import org.springblade.manager.vo.WbsTreeContractTreeVO;
|
|
|
-import org.springblade.manager.vo.WbsTreeContractTreeVO3;
|
|
|
-import org.springblade.manager.vo.WbsTreeContractVO;
|
|
|
-import org.springblade.manager.vo.WbsTreeContractVO4;
|
|
|
+import org.springblade.manager.vo.*;
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
+import springfox.documentation.spring.web.json.Json;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
@@ -441,7 +439,7 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
WbsExcelUtil excelUtil = new WbsExcelUtil();
|
|
|
ArrayList<Map<String, String>> result = excelUtil.readExcelToObjContract(canonicalPath);
|
|
|
//匹配对应工程类别修改对应合同段节点名称
|
|
|
- return this.importSubmitWbsContractNodes(result, primaryKeyId, isSplicingNumber);
|
|
|
+ return this.importSubmitWbsContractNodes(result, primaryKeyId, 1); //TODO 1=默认拼接
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
@@ -550,7 +548,7 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
|
|
|
//解析resultList
|
|
|
List<WbsTreeContractVO> successData = new ArrayList<>();
|
|
|
- List<WbsTreeContractVO> failData = new ArrayList<>();
|
|
|
+ Set<ImportContractNodeVO> sets = new HashSet<>();
|
|
|
for (Map<Integer, String> map : resultList) {//行
|
|
|
for (Map.Entry<Integer, String> entry : map.entrySet()) {//列
|
|
|
Integer k = entry.getKey();
|
|
@@ -562,7 +560,13 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
String nodeName = split[0];
|
|
|
String partitionCode = split[1];
|
|
|
|
|
|
- int count = 0;
|
|
|
+ //excel中所有节点信息
|
|
|
+ ImportContractNodeVO obj = new ImportContractNodeVO();
|
|
|
+ obj.setNodeType(k);
|
|
|
+ obj.setNodeName(nodeName);
|
|
|
+ obj.setPartitionCode(partitionCode);
|
|
|
+ sets.add(obj);
|
|
|
+
|
|
|
for (WbsTreeContractVO nodeOld : wbsTreeContractVOS) {
|
|
|
if (nodeOld.getNodeType().equals(k)) {
|
|
|
String nodeNameOld = nodeOld.getNodeName();
|
|
@@ -598,7 +602,6 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
successData.add(wbsTreeContractVO2);
|
|
|
//重新赋值用于下方条件判断
|
|
|
nodeOld.setFullName(wbsTreeContractVO2.getFullName());
|
|
|
- count = 1;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
@@ -610,7 +613,6 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
&& !f.getPartitionCode().equals(partitionCode)).collect(Collectors.toList());
|
|
|
if (collect1.size() > 0) {
|
|
|
if (nodeName.equals(nodeOld.getFullName())) {
|
|
|
- count = 1;
|
|
|
break;
|
|
|
} else {
|
|
|
if ((nodeName.contains(nodeOld.getFullName()) && DiffListUtil.getSimilarityRatio(nodeName, nodeOld.getFullName()) != 100)
|
|
@@ -629,31 +631,31 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
baseMapper.insert(wbsTreeContract);
|
|
|
WbsTreeContractVO wbsTreeContractVO = BeanUtil.copyProperties(wbsTreeContract, WbsTreeContractVO.class);
|
|
|
successData.add(wbsTreeContractVO);
|
|
|
- count = 1;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- if (count == 1) {
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- List<WbsTreeContractVO> collect = successData.stream().filter(f -> f.getFullName().contains(nodeName)).collect(Collectors.toList());
|
|
|
- List<WbsTreeContractVO> collect1 = failData.stream().filter(f -> f.getFullName().contains(nodeName)).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- if (collect.size() == 0 && collect1.size() == 0) {
|
|
|
- //未匹配成功 构建参数
|
|
|
- WbsTreeContract wbsTreeContract = this.buildFailData(k, nodeName, partitionCode);
|
|
|
- WbsTreeContractVO wbsTreeContractVO = BeanUtil.copyProperties(wbsTreeContract, WbsTreeContractVO.class);
|
|
|
- failData.add(wbsTreeContractVO);
|
|
|
+ //所有失败节点
|
|
|
+ Iterator<ImportContractNodeVO> iterator = sets.iterator();
|
|
|
+ while (iterator.hasNext()) {
|
|
|
+ ImportContractNodeVO next = iterator.next();
|
|
|
+ for (WbsTreeContractVO successDatum : successData) {
|
|
|
+ if (successDatum.getFullName().equals(next.getNodeName())
|
|
|
+ && successDatum.getPartitionCode().equals(next.getPartitionCode())
|
|
|
+ && successDatum.getNodeType().equals(next.getNodeType())) {
|
|
|
+ iterator.remove();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ List<WbsTreeContractVO> failData = this.buildFailData(sets);
|
|
|
|
|
|
- Set<WbsTreeContractVO> listSet = new HashSet<>();
|
|
|
//把successData的节点的上级节点都添加进去
|
|
|
+ Set<WbsTreeContractVO> set = new HashSet<>();
|
|
|
if (successData.size() > 0) {
|
|
|
//通过ancestors获取所有上级节点
|
|
|
for (WbsTreeContractVO successDatum : successData) {
|
|
@@ -662,25 +664,20 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
for (Long parentId : parentIds) {
|
|
|
for (WbsTreeContractVO wbsTreeContractVO : wbsTreeContractVOS) {
|
|
|
if (parentId.equals(wbsTreeContractVO.getId())) {
|
|
|
- listSet.add(wbsTreeContractVO);
|
|
|
+ wbsTreeContractVO.setIsImportIdentificationNode(0);
|
|
|
+ set.add(wbsTreeContractVO);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ set.addAll(successData);
|
|
|
|
|
|
+ //构造数据
|
|
|
WbsTreeContractVO4 res = new WbsTreeContractVO4();
|
|
|
try {
|
|
|
- //重复导入时删除多余节点信息
|
|
|
- List<WbsTreeContract> wbsTreeContractDel = baseMapper.selectList(Wrappers.<WbsTreeContract>query().lambda().eq(WbsTreeContract::getContractId, wbsTreeContractRoot.getContractId()));
|
|
|
- List<Long> delIds = wbsTreeContractDel.stream().filter(f -> f.getNodeName().contains(("_copy_copy")) && f.getId().equals(f.getPKeyId())).collect(Collectors.toList())
|
|
|
- .stream().map(WbsTreeContract::getPKeyId).collect(Collectors.toList());
|
|
|
- if (delIds.size() > 0) {
|
|
|
- baseMapper.deleteByIds(delIds);
|
|
|
- }
|
|
|
-
|
|
|
//构建成功树
|
|
|
- List<WbsTreeContractVO> collect1 = listSet.stream().collect(
|
|
|
+ List<WbsTreeContractVO> collect1 = set.stream().collect(
|
|
|
Collectors.collectingAndThen(
|
|
|
Collectors.toCollection(() -> new TreeSet<>(
|
|
|
Comparator.comparing(o -> o.getId() + ";" + o.getFullName()))), ArrayList::new));
|
|
@@ -688,9 +685,9 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
List<WbsTreeContractVO> collect2 = successWbsTreeContractVOS.stream().sorted(Comparator.comparing(WbsTreeContract::getCreateTime, Comparator.reverseOrder())).collect(Collectors.toList());
|
|
|
res.setMatchedData(collect2);
|
|
|
|
|
|
- List<WbsTreeContractVO> successDataCopyToFail = WbsExcelBatchUtil.deepCopy(collect1);
|
|
|
//构建失败树
|
|
|
- List<WbsTreeContractVO> failDataTree = this.buildFailDataTree(resultList, failData, successDataCopyToFail, wbsTreeContractRoot.getParentId());
|
|
|
+ List<WbsTreeContractVO> successDataCopyToFail = WbsExcelBatchUtil.deepCopy(successData);
|
|
|
+ List<WbsTreeContractVO> failDataTree = this.buildFailDataTree(failData, successDataCopyToFail, wbsTreeContractRoot.getParentId());
|
|
|
List<WbsTreeContractVO> collect3 = failDataTree.stream().collect(
|
|
|
Collectors.collectingAndThen(
|
|
|
Collectors.toCollection(() -> new TreeSet<>(
|
|
@@ -699,6 +696,14 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
List<WbsTreeContractVO> collect4 = failWbsTreeContractVOS.stream().sorted(Comparator.comparing(WbsTreeContract::getCreateTime, Comparator.reverseOrder())).collect(Collectors.toList());
|
|
|
res.setUnmatchedData(collect4);
|
|
|
|
|
|
+ //重复导入时删除多余节点信息
|
|
|
+ List<WbsTreeContract> wbsTreeContractDel = baseMapper.selectList(Wrappers.<WbsTreeContract>query().lambda().eq(WbsTreeContract::getContractId, wbsTreeContractRoot.getContractId()));
|
|
|
+ List<Long> delIds = wbsTreeContractDel.stream().filter(f -> f.getNodeName().contains(("_copy_copy")) && f.getId().equals(f.getPKeyId())).collect(Collectors.toList())
|
|
|
+ .stream().map(WbsTreeContract::getPKeyId).collect(Collectors.toList());
|
|
|
+ if (delIds.size() > 0) {
|
|
|
+ baseMapper.deleteByIds(delIds);
|
|
|
+ }
|
|
|
+
|
|
|
return res;
|
|
|
} catch (IOException | ClassNotFoundException e) {
|
|
|
e.printStackTrace();
|
|
@@ -706,147 +711,70 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
- private List<WbsTreeContractVO> buildFailDataTree(List<Map<Integer, String>> resultList, List<WbsTreeContractVO> failData, List<WbsTreeContractVO> successData, Long id) {
|
|
|
- if (id == null) {
|
|
|
- id = 0L;
|
|
|
- }
|
|
|
+ private List<WbsTreeContractVO> buildFailDataTree(List<WbsTreeContractVO> failData, List<WbsTreeContractVO> successData, Long parentIdRoot) {
|
|
|
List<WbsTreeContractVO> resultData = new ArrayList<>();
|
|
|
- for (Map<Integer, String> map : resultList) {//行
|
|
|
- Long nodeParentIdLv1 = id;
|
|
|
- Long nodeParentIdLv2 = id;
|
|
|
- Long nodeParentIdLv3 = id;
|
|
|
- Long nodeParentIdLv4 = id;
|
|
|
- //当前行,失败节点
|
|
|
- List<WbsTreeContractVO> failList = new ArrayList<>();
|
|
|
- //当前行,成功节点
|
|
|
- List<WbsTreeContractVO> successList = new ArrayList<>();
|
|
|
-
|
|
|
- for (Map.Entry<Integer, String> entry : map.entrySet()) {//每行的列
|
|
|
- Integer k = entry.getKey();
|
|
|
- String v = entry.getValue();
|
|
|
- if (StringUtil.isEmpty(v.replaceAll(":::", ""))) {
|
|
|
- continue;
|
|
|
+ resultData.addAll(successData);
|
|
|
+ resultData.addAll(failData);
|
|
|
+
|
|
|
+ for (WbsTreeContractVO resultDatum : resultData) {
|
|
|
+ //根据划分id确定上级节点
|
|
|
+ List<String> codeParents = new ArrayList<>();
|
|
|
+ if (resultDatum.getNodeType() == 1) {
|
|
|
+ //根节点
|
|
|
+ resultDatum.setParentId(parentIdRoot);
|
|
|
+ codeParents.add(resultDatum.getPartitionCode());
|
|
|
+ } else {
|
|
|
+ if (resultDatum.getNodeType() > 1) {
|
|
|
+ String[] split = resultDatum.getPartitionCode().split("-");
|
|
|
+ codeParents.addAll(Arrays.asList(split).subList(0, split.length - 1));
|
|
|
}
|
|
|
- String[] split = v.split(":::");
|
|
|
- String nodeName = split[0];
|
|
|
- if (failData.size() > 0) {
|
|
|
- for (WbsTreeContractVO failDatum : failData) {
|
|
|
- if (k.equals(failDatum.getNodeType()) && nodeName.equals(failDatum.getFullName())) {
|
|
|
- failList.add(failDatum);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if (successData.size() > 0) {
|
|
|
- for (WbsTreeContractVO successDatum : successData) {
|
|
|
- if (k.equals(successDatum.getNodeType()) && nodeName.equals(successDatum.getFullName())) {
|
|
|
- successList.add(successDatum);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- //如果没有匹配成功的节点,那么就用excel所有节点参数构建新的失败树的上级id
|
|
|
- if (successList.size() == 0 && failList.size() > 0) {
|
|
|
- for (WbsTreeContractVO wbsTreeContractVO : failList) {
|
|
|
- if (wbsTreeContractVO.getNodeType() == 1) {
|
|
|
- nodeParentIdLv1 = wbsTreeContractVO.getId();
|
|
|
- } else if (wbsTreeContractVO.getNodeType() == 2) {
|
|
|
- nodeParentIdLv2 = wbsTreeContractVO.getId();
|
|
|
- } else if (wbsTreeContractVO.getNodeType() == 3) {
|
|
|
- nodeParentIdLv3 = wbsTreeContractVO.getId();
|
|
|
- } else if (wbsTreeContractVO.getNodeType() == 4) {
|
|
|
- nodeParentIdLv4 = wbsTreeContractVO.getId();
|
|
|
- }
|
|
|
+ String codeParent;
|
|
|
+ if (codeParents.size() > 1) {
|
|
|
+ //非第一级
|
|
|
+ codeParent = codeParents.stream().map(String::valueOf).collect(Collectors.joining("-"));
|
|
|
+ } else {
|
|
|
+ //第一级
|
|
|
+ codeParent = StringUtils.join(codeParents, "");
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- //如果有匹配成功的节点,那么就是要该节点作为构建失败树的上级id
|
|
|
- if (successList.size() > 0) {
|
|
|
- for (WbsTreeContractVO successDatum : successList) {
|
|
|
- if (successDatum.getNodeType() == 1) {
|
|
|
- nodeParentIdLv1 = successDatum.getId();
|
|
|
- } else if (successDatum.getNodeType() == 2) {
|
|
|
- nodeParentIdLv2 = successDatum.getId();
|
|
|
- } else if (successDatum.getNodeType() == 3) {
|
|
|
- nodeParentIdLv3 = successDatum.getId();
|
|
|
- } else if (successDatum.getNodeType() == 4) {
|
|
|
- nodeParentIdLv4 = successDatum.getId();
|
|
|
- }
|
|
|
+ //获取上级id,设置为parentId
|
|
|
+ String finalCodeParent = codeParent;
|
|
|
+ WbsTreeContractVO wbsTreeContractVO = resultData.stream().filter(f -> f.getPartitionCode().equals(finalCodeParent)).findAny().orElse(null);
|
|
|
+ if (wbsTreeContractVO != null) {
|
|
|
+ resultDatum.setParentId(wbsTreeContractVO.getId());
|
|
|
+ } else {
|
|
|
+ resultDatum.setParentId(parentIdRoot);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- //构建未成功节点的父级id
|
|
|
- if (failList.size() > 0) {
|
|
|
- for (WbsTreeContractVO failDatum : failList) {
|
|
|
- if (failDatum.getNodeType() == 1) {
|
|
|
- failDatum.setParentId(id);
|
|
|
-
|
|
|
- } else if (failDatum.getNodeType() == 2) {
|
|
|
- failDatum.setParentId(nodeParentIdLv1);
|
|
|
- nodeParentIdLv2 = failDatum.getId();
|
|
|
-
|
|
|
- } else if (failDatum.getNodeType() == 3) {
|
|
|
- if (nodeParentIdLv2.equals(id)) {
|
|
|
- failDatum.setParentId(id);
|
|
|
- } else {
|
|
|
- failDatum.setParentId(nodeParentIdLv2);
|
|
|
- nodeParentIdLv3 = failDatum.getId();
|
|
|
- }
|
|
|
-
|
|
|
- } else if (failDatum.getNodeType() == 4) {
|
|
|
- if (nodeParentIdLv3.equals(id)) {
|
|
|
- if (nodeParentIdLv2.equals(id)) {
|
|
|
- failDatum.setParentId(id);
|
|
|
- } else {
|
|
|
- failDatum.setParentId(nodeParentIdLv2);
|
|
|
- nodeParentIdLv4 = failDatum.getId();
|
|
|
- }
|
|
|
- } else {
|
|
|
- failDatum.setParentId(nodeParentIdLv3);
|
|
|
- nodeParentIdLv4 = failDatum.getId();
|
|
|
- }
|
|
|
-
|
|
|
- } else if (failDatum.getNodeType() == 5) {
|
|
|
- if (nodeParentIdLv4.equals(id)) {
|
|
|
- if (nodeParentIdLv3.equals(id)) {
|
|
|
- if (nodeParentIdLv2.equals(id)) {
|
|
|
- failDatum.setParentId(id);
|
|
|
- } else {
|
|
|
- failDatum.setParentId(nodeParentIdLv2);
|
|
|
- }
|
|
|
- } else {
|
|
|
- failDatum.setParentId(nodeParentIdLv3);
|
|
|
- }
|
|
|
- } else {
|
|
|
- failDatum.setParentId(nodeParentIdLv4);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //添加构建成功节点
|
|
|
- resultData.addAll(failList);
|
|
|
- if (failList.size() > 0) {
|
|
|
- resultData.addAll(successList);
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
return resultData;
|
|
|
}
|
|
|
|
|
|
- private WbsTreeContract buildFailData(Integer nodeType, String nodeName, String partitionCode) {
|
|
|
- WbsTreeContract wbsTreeContract = new WbsTreeContract();
|
|
|
- Long id = SnowFlakeUtil.getId();
|
|
|
- wbsTreeContract.setPKeyId(id);
|
|
|
- wbsTreeContract.setId(id);
|
|
|
- wbsTreeContract.setNodeName(nodeName);
|
|
|
- wbsTreeContract.setFullName(nodeName);
|
|
|
- wbsTreeContract.setImportMatchingInfo(nodeName);
|
|
|
- wbsTreeContract.setPartitionCode(partitionCode);
|
|
|
- wbsTreeContract.setType(1);
|
|
|
- wbsTreeContract.setNodeType(nodeType);
|
|
|
- wbsTreeContract.setIsImportIdentificationNode(0); //识别失败
|
|
|
- return wbsTreeContract;
|
|
|
+ private List<WbsTreeContractVO> buildFailData(Set<ImportContractNodeVO> sets) {
|
|
|
+ List<WbsTreeContractVO> list = new ArrayList<>();
|
|
|
+ Iterator<ImportContractNodeVO> iterator = sets.iterator();
|
|
|
+ while (iterator.hasNext()) {
|
|
|
+ ImportContractNodeVO next = iterator.next();
|
|
|
+ String nodeName = next.getNodeName();
|
|
|
+ String partitionCode = next.getPartitionCode();
|
|
|
+ Integer nodeType = next.getNodeType();
|
|
|
+
|
|
|
+ WbsTreeContractVO wbsTreeContract = new WbsTreeContractVO();
|
|
|
+ Long id = SnowFlakeUtil.getId();
|
|
|
+ wbsTreeContract.setPKeyId(id);
|
|
|
+ wbsTreeContract.setId(id);
|
|
|
+ wbsTreeContract.setNodeName(nodeName);
|
|
|
+ wbsTreeContract.setFullName(nodeName);
|
|
|
+ wbsTreeContract.setImportMatchingInfo(nodeName);
|
|
|
+ wbsTreeContract.setPartitionCode(partitionCode);
|
|
|
+ wbsTreeContract.setType(1);
|
|
|
+ wbsTreeContract.setNodeType(nodeType);
|
|
|
+ wbsTreeContract.setIsImportIdentificationNode(0); //识别失败
|
|
|
+ list.add(wbsTreeContract);
|
|
|
+ }
|
|
|
+ return list;
|
|
|
}
|
|
|
|
|
|
private List<WbsTreeContractVO> buildWbsTreeByStream(List<WbsTreeContractVO> wbsTreeVO2s, Long id) {
|