|
@@ -1,7 +1,13 @@
|
|
package org.springblade.manager.service.impl;
|
|
package org.springblade.manager.service.impl;
|
|
|
|
|
|
|
|
+import cn.hutool.json.JSONString;
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
+import jodd.util.ArraysUtil;
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.AllArgsConstructor;
|
|
|
|
+import org.apache.commons.lang.StringEscapeUtils;
|
|
import org.apache.commons.lang.StringUtils;
|
|
import org.apache.commons.lang.StringUtils;
|
|
import org.springblade.business.entity.ConstructionLedger;
|
|
import org.springblade.business.entity.ConstructionLedger;
|
|
import org.springblade.business.feign.ConstructionLedgerFeignClient;
|
|
import org.springblade.business.feign.ConstructionLedgerFeignClient;
|
|
@@ -10,19 +16,27 @@ import org.springblade.core.log.exception.ServiceException;
|
|
import org.springblade.core.mp.base.BaseServiceImpl;
|
|
import org.springblade.core.mp.base.BaseServiceImpl;
|
|
import org.springblade.core.secure.utils.AuthUtil;
|
|
import org.springblade.core.secure.utils.AuthUtil;
|
|
import org.springblade.core.tool.node.ForestNodeMerger;
|
|
import org.springblade.core.tool.node.ForestNodeMerger;
|
|
|
|
+import org.springblade.core.tool.utils.BeanUtil;
|
|
import org.springblade.core.tool.utils.Func;
|
|
import org.springblade.core.tool.utils.Func;
|
|
import org.springblade.core.tool.utils.StringUtil;
|
|
import org.springblade.core.tool.utils.StringUtil;
|
|
import org.springblade.manager.dto.WbsTreeContractDTO;
|
|
import org.springblade.manager.dto.WbsTreeContractDTO;
|
|
import org.springblade.manager.entity.*;
|
|
import org.springblade.manager.entity.*;
|
|
|
|
+import org.springblade.manager.excel.WbsExcelUtil;
|
|
|
|
+import org.springblade.manager.mapper.ContractInfoMapper;
|
|
import org.springblade.manager.mapper.WbsTreeContractMapper;
|
|
import org.springblade.manager.mapper.WbsTreeContractMapper;
|
|
import org.springblade.manager.mapper.WbsTreePrivateMapper;
|
|
import org.springblade.manager.mapper.WbsTreePrivateMapper;
|
|
import org.springblade.manager.service.IWbsTreeContractService;
|
|
import org.springblade.manager.service.IWbsTreeContractService;
|
|
import org.springblade.manager.utils.DiffListUtil;
|
|
import org.springblade.manager.utils.DiffListUtil;
|
|
import org.springblade.manager.vo.WbsTreeContractTreeVO;
|
|
import org.springblade.manager.vo.WbsTreeContractTreeVO;
|
|
import org.springblade.manager.vo.WbsTreeContractTreeVO3;
|
|
import org.springblade.manager.vo.WbsTreeContractTreeVO3;
|
|
|
|
+import org.springblade.manager.vo.WbsTreeContractVO;
|
|
|
|
+import org.springblade.manager.vo.WbsTreeContractVO4;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.io.IOException;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -32,6 +46,8 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
|
|
|
private final ConstructionLedgerFeignClient constructionLedgerFeign;
|
|
private final ConstructionLedgerFeignClient constructionLedgerFeign;
|
|
private final WbsTreePrivateMapper wbsTreePrivateMapper;
|
|
private final WbsTreePrivateMapper wbsTreePrivateMapper;
|
|
|
|
+ private final ContractInfoMapper contractInfoMapper;
|
|
|
|
+ private final ContractInfoServiceImpl contractInfoService;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public List<WbsTreeContract> selectQueryCurrentNodeByAncestors(List<String> ids, String contractId) {
|
|
public List<WbsTreeContract> selectQueryCurrentNodeByAncestors(List<String> ids, String contractId) {
|
|
@@ -331,7 +347,270 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
return baseMapper.updateAllNodeTabById(aPrivate);
|
|
return baseMapper.updateAllNodeTabById(aPrivate);
|
|
}
|
|
}
|
|
|
|
|
|
- private List<WbsTreeContract> findAllNodeList(String wbsTreeIds, String projectId, String contractId, String wbsId) {
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public WbsTreeContractVO4 importWbsContract(MultipartFile excelFile, String contractId, Integer type) throws IOException {
|
|
|
|
+ File file = WbsExcelUtil.convert(excelFile);
|
|
|
|
+ String canonicalPath = file.getCanonicalPath();
|
|
|
|
+ try {
|
|
|
|
+ //解析excel
|
|
|
|
+ WbsExcelUtil excelUtil = new WbsExcelUtil();
|
|
|
|
+ ArrayList<Map<String, String>> result = excelUtil.readExcelToObjContract(canonicalPath);
|
|
|
|
+ //获取对应工程类别树信息
|
|
|
|
+ ArrayList<Map<String, String>> resultNow = excelUtil.getInfoByType(result, type);
|
|
|
|
+
|
|
|
|
+ if (resultNow.size() <= 0) {
|
|
|
|
+ throw new ServiceException("请选择一个工程类别进行匹配导入");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //匹配对应工程类别修改对应合同段节点名称
|
|
|
|
+ return this.updateContractNodeNames(resultNow, contractId);
|
|
|
|
+
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ } finally {
|
|
|
|
+ File file2 = new File(canonicalPath);
|
|
|
|
+ if (file2.isFile() && file2.exists()) {
|
|
|
|
+ file2.delete();
|
|
|
|
+ System.gc();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private WbsTreeContractVO4 updateContractNodeNames(ArrayList<Map<String, String>> resultNow, String contractId) {
|
|
|
|
+ //获取当前合同段树
|
|
|
|
+ List<WbsTreeContractVO> wbsTreeContractVOS = contractInfoMapper.tree2(null, null, contractId, null, null);
|
|
|
|
+ List<Map<Integer, String>> resultList = new ArrayList<>();
|
|
|
|
+
|
|
|
|
+ //构造map
|
|
|
|
+ String str = "\\s*|\r|\n|\t";
|
|
|
|
+ for (Map<String, String> map : resultNow) {
|
|
|
|
+ Map<Integer, String> maps = new HashMap<>();
|
|
|
|
+ map.forEach((k1, value1) -> {
|
|
|
|
+ String v1 = value1.replaceAll(str, "");
|
|
|
|
+ map.forEach((k2, value2) -> {
|
|
|
|
+ String v2 = value2.replaceAll(str, "");
|
|
|
|
+ if ("1".equals(k1) && "2".equals(k2)) {
|
|
|
|
+ maps.put(1, v1 + ":::" + v2);
|
|
|
|
+ } else if ("3".equals(k1) && "4".equals(k2)) {
|
|
|
|
+ maps.put(2, v1 + ":::" + v2);
|
|
|
|
+ } else if ("5".equals(k1) && "6".equals(k2)) {
|
|
|
|
+ maps.put(3, v1 + ":::" + v2);
|
|
|
|
+ } else if ("7".equals(k1) && "8".equals(k2)) {
|
|
|
|
+ maps.put(4, v1 + ":::" + v2);
|
|
|
|
+ } else if ("9".equals(k1) && "10".equals(k2)) {
|
|
|
|
+ maps.put(5, v1 + ":::" + v2);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+ resultList.add(maps);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<WbsTreeContractVO> successData = new ArrayList<>();
|
|
|
|
+ List<WbsTreeContractVO> failData = new ArrayList<>();
|
|
|
|
+
|
|
|
|
+ //解析mapList
|
|
|
|
+ for (Map<Integer, String> map : resultList) {
|
|
|
|
+ for (Map.Entry<Integer, String> entry : map.entrySet()) {
|
|
|
|
+ Integer k = entry.getKey();
|
|
|
|
+ String v = entry.getValue();
|
|
|
|
+ if (StringUtil.isEmpty(v.replaceAll(":::", ""))) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ String[] split = v.split(":::");
|
|
|
|
+ String nodeName = split[0];
|
|
|
|
+ String partitionCode = split[1];
|
|
|
|
+
|
|
|
|
+ for (WbsTreeContractVO nodeOld : wbsTreeContractVOS) {
|
|
|
|
+ if (nodeOld.getNodeType().equals(k)) {
|
|
|
|
+ String nodeNameOld = nodeOld.getNodeName();
|
|
|
|
+ String fullNameOld = nodeOld.getFullName();
|
|
|
|
+ List<WbsTreeContractVO> collect = successData.stream().filter(f -> DiffListUtil.getContains(f.getNodeName(), nodeName)).collect(Collectors.toList());
|
|
|
|
+ //匹配名称、别名
|
|
|
|
+ if (collect.size() == 0) {
|
|
|
|
+ if (DiffListUtil.getContains(nodeName, nodeNameOld) || DiffListUtil.getContains(nodeName, fullNameOld)) {
|
|
|
|
+ //匹配成功 修改名称、划分编号
|
|
|
|
+ nodeOld.setNodeName(nodeName);
|
|
|
|
+ nodeOld.setPartitionCode(partitionCode);
|
|
|
|
+ nodeOld.setIsImportIdentificationNode(1); //识别成功
|
|
|
|
+ successData.add(nodeOld);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<WbsTreeContractVO> collect1 = successData.stream().filter(f -> DiffListUtil.getContains(f.getNodeName(), nodeName)).collect(Collectors.toList());
|
|
|
|
+ List<WbsTreeContractVO> collect2 = failData.stream().filter(f -> DiffListUtil.getContains(f.getNodeName(), nodeName)).collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ if (collect1.size() == 0 && collect2.size() == 0) {
|
|
|
|
+ //未匹配成功 构建参数
|
|
|
|
+ WbsTreeContract wbsTreeContract = this.buildFailData(k, nodeName, partitionCode);
|
|
|
|
+ WbsTreeContractVO wbsTreeContractVO = BeanUtil.copyProperties(wbsTreeContract, WbsTreeContractVO.class);
|
|
|
|
+ failData.add(wbsTreeContractVO);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //修改节点信息
|
|
|
|
+ List<WbsTreeContract> wbsTreeContracts = BeanUtil.copyProperties(successData, WbsTreeContract.class);
|
|
|
|
+ this.saveOrUpdateBatch(wbsTreeContracts, 1000);
|
|
|
|
+
|
|
|
|
+ WbsTreeContractVO4 res = new WbsTreeContractVO4();
|
|
|
|
+
|
|
|
|
+ //导入识别匹配成功树
|
|
|
|
+ List<WbsTreeContractVO> successWbsTreeContractVOS = contractInfoService.buildWbsTreeByStream(successData);
|
|
|
|
+ res.setMatchedData(successWbsTreeContractVOS);
|
|
|
|
+
|
|
|
|
+ //构建导入识别匹配失败树failDataTree
|
|
|
|
+ List<WbsTreeContractVO> failDataTree = this.buildFailDataTree(resultList, failData, successData);
|
|
|
|
+ List<WbsTreeContractVO> failWbsTreeContractVOS = contractInfoService.buildWbsTreeByStream(failDataTree);
|
|
|
|
+ res.setUnmatchedData(failWbsTreeContractVOS);
|
|
|
|
+
|
|
|
|
+ return res;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private List<WbsTreeContractVO> buildFailDataTree(List<Map<Integer, String>> resultList, List<WbsTreeContractVO> failData, List<WbsTreeContractVO> successData) {
|
|
|
|
+
|
|
|
|
+ List<WbsTreeContractVO> resultData = new ArrayList<>();
|
|
|
|
+
|
|
|
|
+ for (Map<Integer, String> map : resultList) {
|
|
|
|
+
|
|
|
|
+ Long nodeParentIdLv1 = 0L;
|
|
|
|
+ Long nodeParentIdLv2 = 0L;
|
|
|
|
+ Long nodeParentIdLv3 = 0L;
|
|
|
|
+ Long nodeParentIdLv4 = 0L;
|
|
|
|
+ Long nodeParentIdLv5 = 0L;
|
|
|
|
+
|
|
|
|
+ //当前行,失败节点
|
|
|
|
+ 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;
|
|
|
|
+ }
|
|
|
|
+ String[] split = v.split(":::");
|
|
|
|
+ String nodeName = split[0];
|
|
|
|
+
|
|
|
|
+ //当前行,失败节点
|
|
|
|
+ for (WbsTreeContractVO failDatum : failData) {
|
|
|
|
+ if (nodeName.equals(failDatum.getNodeName())) {
|
|
|
|
+ failList.add(failDatum);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //当前行,成功节点
|
|
|
|
+ for (WbsTreeContractVO successDatum : successData) {
|
|
|
|
+ if (nodeName.equals(successDatum.getNodeName())) {
|
|
|
|
+ successList.add(successDatum);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //初始化父级id
|
|
|
|
+ for (WbsTreeContractVO successDatum : successList) {
|
|
|
|
+ if (nodeName.equals(successDatum.getNodeName())) {
|
|
|
|
+ if (successDatum.getNodeType() == 1) {
|
|
|
|
+ nodeParentIdLv1 = successDatum.getParentId();
|
|
|
|
+ } else if (successDatum.getNodeType() == 2) {
|
|
|
|
+ nodeParentIdLv2 = successDatum.getParentId();
|
|
|
|
+ } else if (successDatum.getNodeType() == 3) {
|
|
|
|
+ nodeParentIdLv3 = successDatum.getParentId();
|
|
|
|
+ } else if (successDatum.getNodeType() == 4) {
|
|
|
|
+ nodeParentIdLv4 = successDatum.getParentId();
|
|
|
|
+ } else if (successDatum.getNodeType() == 5) {
|
|
|
|
+ nodeParentIdLv5 = successDatum.getParentId();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //构建未成功节点的父级id
|
|
|
|
+ for (WbsTreeContractVO failDatum : failList) {
|
|
|
|
+ if (failDatum.getNodeType() == 1) {
|
|
|
|
+ failDatum.setParentId(nodeParentIdLv1);
|
|
|
|
+ } else if (failDatum.getNodeType() == 2) {
|
|
|
|
+ if (nodeParentIdLv2 == 0L) {
|
|
|
|
+ failDatum.setParentId(nodeParentIdLv1);
|
|
|
|
+ } else {
|
|
|
|
+ failDatum.setParentId(nodeParentIdLv2);
|
|
|
|
+ }
|
|
|
|
+ } else if (failDatum.getNodeType() == 3) {
|
|
|
|
+ if (nodeParentIdLv3 == 0L) {
|
|
|
|
+ if (nodeParentIdLv2 == 0L) {
|
|
|
|
+ failDatum.setParentId(nodeParentIdLv1);
|
|
|
|
+ } else {
|
|
|
|
+ failDatum.setParentId(nodeParentIdLv2);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ failDatum.setParentId(nodeParentIdLv3);
|
|
|
|
+ }
|
|
|
|
+ } else if (failDatum.getNodeType() == 4) {
|
|
|
|
+ if (nodeParentIdLv4 == 0L) {
|
|
|
|
+ if (nodeParentIdLv3 == 0L) {
|
|
|
|
+ if (nodeParentIdLv2 == 0L) {
|
|
|
|
+ failDatum.setParentId(nodeParentIdLv1);
|
|
|
|
+ } else {
|
|
|
|
+ failDatum.setParentId(nodeParentIdLv2);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ failDatum.setParentId(nodeParentIdLv3);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ failDatum.setParentId(nodeParentIdLv4);
|
|
|
|
+ }
|
|
|
|
+ } else if (failDatum.getNodeType() == 5) {
|
|
|
|
+ if (nodeParentIdLv5 == 0L) {
|
|
|
|
+ if (nodeParentIdLv4 == 0L) {
|
|
|
|
+ if (nodeParentIdLv3 == 0L) {
|
|
|
|
+ if (nodeParentIdLv2 == 0L) {
|
|
|
|
+ failDatum.setParentId(nodeParentIdLv1);
|
|
|
|
+ } else {
|
|
|
|
+ failDatum.setParentId(nodeParentIdLv2);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ failDatum.setParentId(nodeParentIdLv3);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ failDatum.setParentId(nodeParentIdLv4);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ failDatum.setParentId(nodeParentIdLv5);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //添加未成功节点
|
|
|
|
+ resultData.addAll(failData);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //添加父级节点
|
|
|
|
+ resultData.addAll(successData);
|
|
|
|
+
|
|
|
|
+ return resultData;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private WbsTreeContract buildFailData(Integer nodeType, String nodeName, String partitionCode) {
|
|
|
|
+ //获取当前节点的parentId
|
|
|
|
+ WbsTreeContract wbsTreeContract = new WbsTreeContract();
|
|
|
|
+ Long id = SnowFlakeUtil.getId();
|
|
|
|
+ wbsTreeContract.setPKeyId(id);
|
|
|
|
+ wbsTreeContract.setId(id);
|
|
|
|
+ wbsTreeContract.setNodeName(nodeName);
|
|
|
|
+ wbsTreeContract.setFullName(nodeName);
|
|
|
|
+ wbsTreeContract.setPartitionCode(partitionCode);
|
|
|
|
+ wbsTreeContract.setType(1);
|
|
|
|
+ wbsTreeContract.setNodeType(nodeType);
|
|
|
|
+ wbsTreeContract.setIsImportIdentificationNode(0); //识别失败
|
|
|
|
+ return wbsTreeContract;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private List<WbsTreeContract> findAllNodeList(String wbsTreeIds, String projectId, String contractId, String
|
|
|
|
+ wbsId) {
|
|
String[] ids = wbsTreeIds.split(",");
|
|
String[] ids = wbsTreeIds.split(",");
|
|
List<Long> idList = new ArrayList<>();
|
|
List<Long> idList = new ArrayList<>();
|
|
List<WbsTreeContract> list = new ArrayList<>();
|
|
List<WbsTreeContract> list = new ArrayList<>();
|