|
@@ -103,6 +103,7 @@ 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
|
|
@@ -4479,10 +4480,10 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
|
|
|
@Override
|
|
|
public ResponseEntity<Resource> exportTree(Long contractId, HttpServletResponse response) throws IOException, InvalidFormatException {
|
|
|
- String templatePath = "/mnt/sdc/Users/hongchuangyanfa/Desktop/excel/gcdcTemplate.xlsx";
|
|
|
- //String templatePath = "C:\\upload\\excel\\gcdc.xlsx";
|
|
|
+ //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));
|
|
|
|
|
@@ -4820,6 +4821,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()
|
|
@@ -4827,41 +4829,75 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
if (!leafNodes.isEmpty()) {
|
|
|
- return sortLeafNodes(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 sortLeafNodes(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 sortLeafNodes(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 (!leafNodes.isEmpty()) {
|
|
|
- return sortLeafNodes(leafNodes);
|
|
|
- }
|
|
|
+ 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;
|
|
|
|
|
|
// 5. 最后找单位工程 (节点类型18)
|
|
|
- leafNodes = projects.stream()
|
|
|
- .filter(item -> item.getNodeType() == 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);
|
|
|
}
|
|
|
|