|
@@ -69,6 +69,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.core.io.ByteArrayResource;
|
|
|
import org.springframework.core.io.Resource;
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
+import org.springframework.http.ContentDisposition;
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
import org.springframework.http.MediaType;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
@@ -92,12 +93,14 @@ import java.math.BigInteger;
|
|
|
import java.math.MathContext;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.net.URLEncoder;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
|
import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
|
|
|
|
@Service
|
|
@@ -124,6 +127,7 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
private final WbsFormElementMapper wbsFormElementMapper;
|
|
|
private final TrialCyAccessoriesClient trialCyAccessoriesClient;
|
|
|
private final WbsTreeContractStatisticsClient wbsTreeContractStatisticsClient;
|
|
|
+ private final FormulaDataBlockMapper formulaDataBlockMapper;
|
|
|
|
|
|
|
|
|
|
|
@@ -4486,7 +4490,7 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
String templatePath = "/mnt/sdc/Users/hongchuangyanfa/Desktop/excel/gcdcTemplate.xlsx";
|
|
|
//String templatePath = "C:\\upload\\excel\\gcdc.xlsx";
|
|
|
// 查询数据
|
|
|
- String sql = "select * from m_wbs_tree_contract where contract_id = " + contractId +
|
|
|
+ String sql = "select *,CONCAT(ancestors_p_id, ',', p_key_id) AS ancestors_p_id from m_wbs_tree_contract where contract_id = " + contractId +
|
|
|
" and is_deleted = 0 and type = 1 and node_type != 6 and p_id != 0";
|
|
|
List<WbsTreeContract> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(WbsTreeContract.class));
|
|
|
|
|
@@ -4510,8 +4514,8 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
.collect(Collectors.toMap(
|
|
|
WbsTreeContract::getPKeyId,
|
|
|
unit -> list.stream()
|
|
|
- .filter(item -> item.getAncestors() != null &&
|
|
|
- item.getAncestors().contains(unit.getPKeyId().toString()))
|
|
|
+ .filter(item -> item.getAncestorsPId() != null &&
|
|
|
+ item.getAncestorsPId().contains(unit.getPKeyId().toString()))
|
|
|
.collect(Collectors.toList())
|
|
|
));
|
|
|
|
|
@@ -4519,15 +4523,17 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
for (Map.Entry<Long, List<WbsTreeContract>> entry : unitProjectMap.entrySet()) {
|
|
|
Long unitId = entry.getKey();
|
|
|
List<WbsTreeContract> unitProjects = entry.getValue();
|
|
|
-
|
|
|
- // 获取单位工程名称
|
|
|
- String unitName = unitProjects.stream()
|
|
|
- .filter(item -> item.getPKeyId().equals(unitId))
|
|
|
- .findFirst()
|
|
|
- .map(WbsTreeContract::getNodeName)
|
|
|
- .orElse("未知单位工程");
|
|
|
+ String sql1="Select * from m_wbs_tree_contract where p_key_id="+unitId;
|
|
|
+ WbsTreeContract unitNode=jdbcTemplate.queryForObject(sql1,new BeanPropertyRowMapper<>(WbsTreeContract.class));
|
|
|
+ unitProjects.add(unitNode);
|
|
|
+// // 获取单位工程名称
|
|
|
+// String unitName = unitProjects.stream()
|
|
|
+// .filter(item -> item.getPKeyId().equals(unitId))
|
|
|
+// .findFirst()
|
|
|
+// .map(WbsTreeContract::getNodeName)
|
|
|
+// .orElse("未知单位工程");
|
|
|
// 创建安全的sheet名称
|
|
|
- String safeUnitName = unitName.replaceAll("[\\\\/*\\[\\]:?]", "_");
|
|
|
+ String safeUnitName = unitNode.getNodeName().replaceAll("[\\\\/*\\[\\]:?]", "_");
|
|
|
if (safeUnitName.length() > 31) {
|
|
|
safeUnitName = safeUnitName.substring(0, 31);
|
|
|
}
|
|
@@ -4553,8 +4559,8 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
}
|
|
|
|
|
|
//保存文件到本地(本地测试放开,正式环境不需要)
|
|
|
-// String outputPath = "C:\\upload\\excel\\111.xlsx";
|
|
|
-// saveWorkbookToFile(workbook, outputPath);
|
|
|
+ //String outputPath = "C:\\upload\\excel\\111.xlsx";
|
|
|
+ //saveWorkbookToFile(workbook, outputPath);
|
|
|
|
|
|
// 同时返回给浏览器下载
|
|
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
@@ -4564,13 +4570,12 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
ByteArrayResource resource = new ByteArrayResource(outputStream.toByteArray());
|
|
|
|
|
|
|
|
|
- // 对中文文件名进行URL编码
|
|
|
- String filename = "划分导出(请勿修改隐藏列).xlsx";
|
|
|
- String encodedFilename = URLEncoder.encode(filename, "UTF-8")
|
|
|
- .replaceAll("\\+", "%20"); // 替换+号为%20,确保兼容性
|
|
|
-
|
|
|
+ // 设置响应头
|
|
|
+ String fileName = "工程划分(请勿删除或修隐藏列).xlsx";
|
|
|
+ String encodedFileName = URLEncoder.encode(fileName, StandardCharsets.UTF_8.toString())
|
|
|
+ .replaceAll("\\+", "%20");
|
|
|
return ResponseEntity.ok()
|
|
|
- .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + encodedFilename + "\"; filename*=utf-8''" + encodedFilename)
|
|
|
+ .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename*=" + encodedFileName)
|
|
|
.contentType(MediaType.APPLICATION_OCTET_STREAM)
|
|
|
.contentLength(resource.contentLength())
|
|
|
.body(resource);
|
|
@@ -4601,6 +4606,7 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
List<WbsTreeContract> wbsTreeContractList = new ArrayList<>();
|
|
|
int totalCount = 0;
|
|
|
int successCount = 0;
|
|
|
+ Map<Long, String>map=new HashMap<>();
|
|
|
try (InputStream inputStream = file.getInputStream();
|
|
|
XSSFWorkbook workbook = new XSSFWorkbook(inputStream)) {
|
|
|
|
|
@@ -4624,13 +4630,16 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
if (isValidCell(pkeyCell) && isValidCell(codeCell)) {
|
|
|
String pkeyId = getCellValue(pkeyCell);
|
|
|
String partitionCode = getCellValue(codeCell);
|
|
|
-
|
|
|
+ if(map.containsKey(Long.parseLong(pkeyId))){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
if (StringUtils.isNotBlank(pkeyId) && StringUtils.isNotBlank(partitionCode)) {
|
|
|
totalCount++;
|
|
|
WbsTreeContract wbsTreeContract = new WbsTreeContract();
|
|
|
wbsTreeContract.setPKeyId(Long.parseLong(pkeyId.trim()));
|
|
|
wbsTreeContract.setPartitionCode(partitionCode.trim());
|
|
|
wbsTreeContractList.add(wbsTreeContract);
|
|
|
+ map.put(wbsTreeContract.getPKeyId(),wbsTreeContract.getPartitionCode());
|
|
|
successCount++;
|
|
|
}
|
|
|
}
|
|
@@ -4655,6 +4664,7 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
return R.status(false);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
public Boolean getIsImport(Long projectId, Long contractId) {
|
|
|
Object o = bladeRedis.get("import:projectId:" + projectId + "contractId:" + contractId);
|
|
@@ -4682,8 +4692,42 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
|
|
|
@Override
|
|
|
public R moveNode(MoveNodeDTO dto) {
|
|
|
- List<WbsTreeContract> list= wbsTreeContractMapper.getWbsTreeContractsByPKeyIds(dto.getLeftPkeyIds());
|
|
|
+ if(dto.getLeftPkeyIds().isEmpty()){
|
|
|
+ throw new ServiceException("请选择需要移动的节点");
|
|
|
+ }
|
|
|
+ if(dto.getRightPkeyId()==null){
|
|
|
+ throw new ServiceException("请选择要移动到哪个节点");
|
|
|
+ }
|
|
|
+ List<WbsTreeContract> list= wbsTreeContractMapper.getWbsTreeContractsByPKeyIds(dto.getLeftPkeyIds());
|
|
|
+ WbsTreeContract moveFatherNode = this.getById(list.get(0).getPId());
|
|
|
WbsTreeContract fatherContract = this.getById(dto.getRightPkeyId());
|
|
|
+
|
|
|
+ String sql="SELECT * from m_formula_data_block WHERE sw_id = "+moveFatherNode.getId()+" and contract_id ="+moveFatherNode.getContractId()+" and type =0";
|
|
|
+ List<FormulaDataBlock> formulaDataBlocks1 = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(FormulaDataBlock.class));
|
|
|
+
|
|
|
+ String sql1="SELECT * from m_formula_data_block WHERE sw_id = "+fatherContract.getId()+" and contract_id ="+fatherContract.getContractId()+" and type =0";
|
|
|
+ List<FormulaDataBlock> formulaDataBlocks2 = jdbcTemplate.query(sql1, new BeanPropertyRowMapper<>(FormulaDataBlock.class));
|
|
|
+ List<ElementBlock> elementBlocks1=new ArrayList<>();
|
|
|
+ List<ElementBlock> elementBlocks2=new ArrayList<>();
|
|
|
+ if(formulaDataBlocks2.size()>0){
|
|
|
+ if(formulaDataBlocks1.size()>0){
|
|
|
+ elementBlocks1= JSON.parseArray(formulaDataBlocks1.get(0).getVal(), ElementBlock.class);
|
|
|
+ elementBlocks2= JSON.parseArray(formulaDataBlocks2.get(0).getVal(), ElementBlock.class);
|
|
|
+ elementBlocks2.addAll(elementBlocks1);
|
|
|
+ formulaDataBlocks2.get(0).setVal(JSON.toJSONString(elementBlocks2));
|
|
|
+ formulaDataBlockMapper.updateById(formulaDataBlocks2.get(0));
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ if(formulaDataBlocks1.size()>0){
|
|
|
+ elementBlocks1= JSON.parseArray(formulaDataBlocks1.get(0).getVal(), ElementBlock.class);
|
|
|
+ FormulaDataBlock insert = new FormulaDataBlock();
|
|
|
+ insert.setContractId(Long.parseLong(fatherContract.getContractId()));
|
|
|
+ insert.setType(0);
|
|
|
+ insert.setSwId(fatherContract.getId());
|
|
|
+ insert.setVal(JSON.toJSONString(elementBlocks1));
|
|
|
+ formulaDataBlockMapper.insert(insert);
|
|
|
+ }
|
|
|
+ }
|
|
|
for (WbsTreeContract contract : list) {
|
|
|
String oldancestorsPId = contract.getAncestorsPId();
|
|
|
String oldancestors = contract.getAncestors();
|
|
@@ -4704,6 +4748,8 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
}
|
|
|
this.wbsTreeContractMapper.updateWbsTreeAncestors(contract);
|
|
|
}
|
|
|
+ String ids = dto.getLeftPkeyIds().stream().map(id -> id + "").collect(Collectors.joining(","));
|
|
|
+ this.wbsTreeContractStatisticsClient.updateAncestors(ids);
|
|
|
return R.success("操作成功");
|
|
|
}
|
|
|
|
|
@@ -4828,13 +4874,14 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
Row row = sheet.createRow(rowNum);
|
|
|
|
|
|
// 解析祖级节点
|
|
|
- String[] ancestors = leafNode.getAncestors().split(",");
|
|
|
+ String[] ancestors = leafNode.getAncestorsPId().split(",");
|
|
|
|
|
|
// 转换为 List<Long>
|
|
|
List<Long> ancestorIds = Arrays.stream(ancestors)
|
|
|
.map(Long::parseLong)
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
+ ancestorIds.add(leafNode.getPKeyId());
|
|
|
// 根据叶子节点类型填充各级工程数据
|
|
|
fillEngineeringDataByLeafType(row, unitProjects, ancestorIds, mergeMap, rowNum, centerStyle, leafNode.getNodeType());
|
|
|
|
|
@@ -4849,6 +4896,7 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
private List<WbsTreeContract> findLeafNodesByPriority(List<WbsTreeContract> projects) {
|
|
|
// 按照节点类型优先级:子分项(5) -> 分项(4) -> 子分部(3) -> 分部(2) -> 单位工程(18)
|
|
|
List<WbsTreeContract> leafNodes = new ArrayList<>();
|
|
|
+ Set<Long> ancestorIds= new HashSet<>();
|
|
|
|
|
|
// 1. 先找子分项工程 (节点类型5)
|
|
|
leafNodes = projects.stream()
|
|
@@ -4856,39 +4904,90 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
if (!leafNodes.isEmpty()) {
|
|
|
- return leafNodes;
|
|
|
+ sortLeafNodes(leafNodes);
|
|
|
}
|
|
|
+ ancestorIds= leafNodes.stream()
|
|
|
+ .map(WbsTreeContract::getAncestorsPId)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .flatMap(ancestors -> Arrays.stream(ancestors.split(",")))
|
|
|
+ .map(String::trim)
|
|
|
+ .filter(id -> !id.isEmpty())
|
|
|
+ .map(Long::parseLong)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
|
|
|
// 2. 如果没有子分项,找分项工程 (节点类型4)
|
|
|
- leafNodes = projects.stream()
|
|
|
- .filter(item -> item.getNodeType() == 4)
|
|
|
+ Set<Long> finalAncestorIds = ancestorIds;
|
|
|
+ List<WbsTreeContract> items=projects.stream()
|
|
|
+ .filter(item -> item.getNodeType() == 4 && !finalAncestorIds.contains(item.getPKeyId()))
|
|
|
.collect(Collectors.toList());
|
|
|
-
|
|
|
- if (!leafNodes.isEmpty()) {
|
|
|
- return leafNodes;
|
|
|
- }
|
|
|
+ if(!items.isEmpty()&&items.size()>0){
|
|
|
+ leafNodes.addAll(items);
|
|
|
+ }
|
|
|
+ ancestorIds = leafNodes.stream()
|
|
|
+ .map(WbsTreeContract::getAncestorsPId)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .flatMap(ancestors -> Arrays.stream(ancestors.split(",")))
|
|
|
+ .map(String::trim)
|
|
|
+ .filter(id -> !id.isEmpty())
|
|
|
+ .map(Long::parseLong)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
|
|
|
// 3. 如果没有分项,找子分部工程 (节点类型3)
|
|
|
- leafNodes = projects.stream()
|
|
|
- .filter(item -> item.getNodeType() == 3)
|
|
|
+ Set<Long> finalAncestorIds1 = ancestorIds;
|
|
|
+ List<WbsTreeContract> subDivisional = projects.stream()
|
|
|
+ .filter(item -> item.getNodeType() == 3&& !finalAncestorIds1.contains(item.getPKeyId()))
|
|
|
.collect(Collectors.toList());
|
|
|
-
|
|
|
- if (!leafNodes.isEmpty()) {
|
|
|
- return leafNodes;
|
|
|
- }
|
|
|
-
|
|
|
+ if(!subDivisional.isEmpty()&&subDivisional.size()>0){
|
|
|
+ leafNodes.addAll(subDivisional);
|
|
|
+ }
|
|
|
+ ancestorIds = leafNodes.stream()
|
|
|
+ .map(WbsTreeContract::getAncestorsPId)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .flatMap(ancestors -> Arrays.stream(ancestors.split(",")))
|
|
|
+ .map(String::trim)
|
|
|
+ .filter(id -> !id.isEmpty())
|
|
|
+ .map(Long::parseLong)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+ Set<Long> finalAncestorIds2 = ancestorIds;
|
|
|
// 4. 如果没有子分部,找分部工程 (节点类型2)
|
|
|
- leafNodes = projects.stream()
|
|
|
- .filter(item -> item.getNodeType() == 2)
|
|
|
+ List<WbsTreeContract> divisional = projects.stream()
|
|
|
+ .filter(item -> item.getNodeType() == 2&& !finalAncestorIds2.contains(item.getPKeyId()))
|
|
|
.collect(Collectors.toList());
|
|
|
+ if(!divisional.isEmpty()&&divisional.size()>0){
|
|
|
+ leafNodes.addAll(divisional);
|
|
|
+ }
|
|
|
+ ancestorIds = leafNodes.stream()
|
|
|
+ .map(WbsTreeContract::getAncestorsPId)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .flatMap(ancestors -> Arrays.stream(ancestors.split(",")))
|
|
|
+ .map(String::trim)
|
|
|
+ .filter(id -> !id.isEmpty())
|
|
|
+ .map(Long::parseLong)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+ Set<Long> finalAncestorIds3 = ancestorIds;
|
|
|
|
|
|
- if (!leafNodes.isEmpty()) {
|
|
|
- return leafNodes;
|
|
|
+ // 5. 最后找单位工程 (节点类型18)
|
|
|
+ List<WbsTreeContract> unit = projects.stream()
|
|
|
+ .filter(item -> item.getNodeType() == 18&&!finalAncestorIds3.contains(item.getPKeyId()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if(!unit.isEmpty()&&unit.size()>0){
|
|
|
+ leafNodes.addAll(unit);
|
|
|
}
|
|
|
+ return sortLeafNodes(leafNodes);
|
|
|
+ }
|
|
|
|
|
|
- // 5. 最后找单位工程 (节点类型18)
|
|
|
- return projects.stream()
|
|
|
- .filter(item -> item.getNodeType() == 18)
|
|
|
+ // 排序方法:先按pId排序,pId相同则按sort排序(null值排在最后)
|
|
|
+ private List<WbsTreeContract> sortLeafNodes(List<WbsTreeContract> nodes) {
|
|
|
+ return nodes.stream()
|
|
|
+ .sorted(Comparator
|
|
|
+ .comparing(WbsTreeContract::getPId)
|
|
|
+ .thenComparing(
|
|
|
+ Comparator.comparing(
|
|
|
+ WbsTreeContract::getSort,
|
|
|
+ Comparator.nullsLast(Comparator.naturalOrder())
|
|
|
+ )
|
|
|
+ )
|
|
|
+ )
|
|
|
.collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
@@ -5176,29 +5275,34 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
|
|
|
// 合并单列并设置样式(检查是否已存在)
|
|
|
private void mergeSingleColumnIfNotExists(Sheet sheet, int col, int startRow, int endRow, CellStyle style, Set<String> mergedRegions) {
|
|
|
- String regionKey = col + ":" + startRow + ":" + endRow;
|
|
|
-
|
|
|
- if (!mergedRegions.contains(regionKey)) {
|
|
|
- CellRangeAddress mergedRegion = new CellRangeAddress(startRow, endRow, col, col);
|
|
|
-
|
|
|
- // 检查是否已经存在相同的合并区域
|
|
|
- boolean alreadyExists = false;
|
|
|
- for (int i = 0; i < sheet.getNumMergedRegions(); i++) {
|
|
|
- CellRangeAddress existingRegion = sheet.getMergedRegion(i);
|
|
|
- if (existingRegion.getFirstColumn() == col &&
|
|
|
- existingRegion.getFirstRow() == startRow &&
|
|
|
- existingRegion.getLastRow() == endRow) {
|
|
|
- alreadyExists = true;
|
|
|
- break;
|
|
|
+ try {
|
|
|
+ String regionKey = col + ":" + startRow + ":" + endRow;
|
|
|
+
|
|
|
+ if (!mergedRegions.contains(regionKey)) {
|
|
|
+ CellRangeAddress mergedRegion = new CellRangeAddress(startRow, endRow, col, col);
|
|
|
+
|
|
|
+ // 检查是否已经存在相同的合并区域
|
|
|
+ boolean alreadyExists = false;
|
|
|
+ for (int i = 0; i < sheet.getNumMergedRegions(); i++) {
|
|
|
+ CellRangeAddress existingRegion = sheet.getMergedRegion(i);
|
|
|
+ if (existingRegion.getFirstColumn() == col &&
|
|
|
+ existingRegion.getFirstRow() == startRow &&
|
|
|
+ existingRegion.getLastRow() == endRow) {
|
|
|
+ alreadyExists = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- if (!alreadyExists) {
|
|
|
- sheet.addMergedRegion(mergedRegion);
|
|
|
- setMergedRegionStyle(sheet, mergedRegion, style);
|
|
|
- mergedRegions.add(regionKey);
|
|
|
+ if (!alreadyExists) {
|
|
|
+ sheet.addMergedRegion(mergedRegion);
|
|
|
+ setMergedRegionStyle(sheet, mergedRegion, style);
|
|
|
+ mergedRegions.add(regionKey);
|
|
|
+ }
|
|
|
}
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
// 判断是否是名称列
|