|
|
@@ -4730,8 +4730,8 @@ 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 *,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";
|
|
|
@@ -4754,8 +4754,21 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
// 按单位工程分组
|
|
|
Map<Long, List<WbsTreeContract>> unitProjectMap = list.stream()
|
|
|
.filter(item -> item.getNodeType() == 18)
|
|
|
- .sorted(Comparator.comparing(WbsTreeContract::getSort,
|
|
|
- Comparator.nullsLast(Comparator.naturalOrder()))) // null值排在最后面
|
|
|
+ .sorted(Comparator.comparing((WbsTreeContract unit) -> {
|
|
|
+ // 先按父节点的sort排序
|
|
|
+ if (unit.getPId() != null) {
|
|
|
+ // 查找父节点
|
|
|
+ Optional<WbsTreeContract> parent = list.stream()
|
|
|
+ .filter(p -> p.getPKeyId().equals(unit.getPId()))
|
|
|
+ .findFirst();
|
|
|
+ if (parent.isPresent()) {
|
|
|
+ return parent.get().getSort();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null; // 如果没有父节点,返回null
|
|
|
+ }, Comparator.nullsLast(Comparator.naturalOrder()))
|
|
|
+ .thenComparing(WbsTreeContract::getSort,
|
|
|
+ Comparator.nullsLast(Comparator.naturalOrder()))) // 再按自身的sort排序
|
|
|
.collect(Collectors.toMap(
|
|
|
WbsTreeContract::getPKeyId,
|
|
|
unit -> list.stream()
|
|
|
@@ -5370,10 +5383,6 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
.sorted(Comparator.comparing(WbsTreeContract::getSort,
|
|
|
Comparator.nullsLast(Comparator.naturalOrder())))
|
|
|
.collect(Collectors.toList());
|
|
|
-
|
|
|
- if (!leafNodes.isEmpty()) {
|
|
|
- sortLeafNodes(leafNodes);
|
|
|
- }
|
|
|
ancestorIds= leafNodes.stream()
|
|
|
.map(WbsTreeContract::getAncestorsPId)
|
|
|
.filter(Objects::nonNull)
|
|
|
@@ -5457,24 +5466,120 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
if(!unit.isEmpty()&&unit.size()>0){
|
|
|
leafNodes.addAll(unit);
|
|
|
}
|
|
|
- return sortLeafNodes(leafNodes);
|
|
|
+ return sortLeafNodes(leafNodes,projects);
|
|
|
}
|
|
|
|
|
|
// 排序方法:先按pId排序,pId相同则按sort排序(null值排在最后)
|
|
|
- private List<WbsTreeContract> sortLeafNodes(List<WbsTreeContract> nodes) {
|
|
|
+ // 排序方法:按照层级顺序排序(分部 -> 子分部 -> 分项 -> 子分项)
|
|
|
+ private List<WbsTreeContract> sortLeafNodes(List<WbsTreeContract> nodes, List<WbsTreeContract> projects) {
|
|
|
return nodes.stream()
|
|
|
- .sorted(Comparator
|
|
|
- .comparing(WbsTreeContract::getPId)
|
|
|
- .thenComparing(
|
|
|
- Comparator.comparing(
|
|
|
- WbsTreeContract::getSort,
|
|
|
- Comparator.nullsLast(Comparator.naturalOrder())
|
|
|
- )
|
|
|
- )
|
|
|
- )
|
|
|
+ .sorted((node1, node2) -> {
|
|
|
+ // 解析祖级节点ID
|
|
|
+ List<Long> ancestors1 = parseAncestors(node1.getAncestorsPId());
|
|
|
+ List<Long> ancestors2 = parseAncestors(node2.getAncestorsPId());
|
|
|
+
|
|
|
+ // 按照层级顺序比较
|
|
|
+ int result;
|
|
|
+
|
|
|
+ // 1. 先比较分部工程(nodeType=2)的sort
|
|
|
+ result = compareByNodeType(ancestors1, ancestors2, projects, 2);
|
|
|
+ if (result != 0) return result;
|
|
|
+
|
|
|
+ // 2. 再比较子分部工程(nodeType=3)的sort
|
|
|
+ result = compareByNodeType(ancestors1, ancestors2, projects, 3);
|
|
|
+ if (result != 0) return result;
|
|
|
+
|
|
|
+ // 3. 再比较分项工程(nodeType=4)的sort
|
|
|
+ result = compareByNodeType(ancestors1, ancestors2, projects, 4);
|
|
|
+ if (result != 0) return result;
|
|
|
+
|
|
|
+ // 4. 最后比较子分项工程(nodeType=5)的sort
|
|
|
+ result = compareByNodeType(ancestors1, ancestors2, projects, 5);
|
|
|
+ if (result != 0) return result;
|
|
|
+
|
|
|
+ // 5. 如果所有层级sort都相同,按当前节点sort排序
|
|
|
+ return compareSortValue(node1.getSort(), node2.getSort());
|
|
|
+ })
|
|
|
.collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 解析祖级节点ID
|
|
|
+ */
|
|
|
+ private List<Long> parseAncestors(String ancestorsPId) {
|
|
|
+ if (ancestorsPId == null || ancestorsPId.equals("null")) {
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ return Arrays.stream(ancestorsPId.split(","))
|
|
|
+ .map(String::trim)
|
|
|
+ .filter(id -> !id.isEmpty() && !id.equals("null"))
|
|
|
+ .map(Long::parseLong)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 按照指定节点类型比较sort值
|
|
|
+ */
|
|
|
+ private int compareByNodeType(List<Long> ancestors1, List<Long> ancestors2,
|
|
|
+ List<WbsTreeContract> projects, int nodeType) {
|
|
|
+ // 从祖级节点中查找指定类型的节点
|
|
|
+ WbsTreeContract node1 = findNodeByTypeInAncestors(ancestors1, projects, nodeType);
|
|
|
+ WbsTreeContract node2 = findNodeByTypeInAncestors(ancestors2, projects, nodeType);
|
|
|
+
|
|
|
+ // 获取sort值进行比较
|
|
|
+ Integer sort1 = node1 != null ? node1.getSort() : null;
|
|
|
+ Integer sort2 = node2 != null ? node2.getSort() : null;
|
|
|
+
|
|
|
+ return compareSortValue(sort1, sort2);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 在祖级节点中查找指定类型的节点
|
|
|
+ */
|
|
|
+ private WbsTreeContract findNodeByTypeInAncestors(List<Long> ancestors,
|
|
|
+ List<WbsTreeContract> projects, int nodeType) {
|
|
|
+ if (ancestors.isEmpty()) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 在祖级节点中查找指定类型的节点
|
|
|
+ for (Long ancestorId : ancestors) {
|
|
|
+ WbsTreeContract node = findNodeByIdAndType(projects, ancestorId, nodeType);
|
|
|
+ if (node != null) {
|
|
|
+ return node;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据ID和类型查找节点
|
|
|
+ */
|
|
|
+ private WbsTreeContract findNodeByIdAndType(List<WbsTreeContract> list, Long id, int nodeType) {
|
|
|
+ return list.stream()
|
|
|
+ .filter(item -> item.getPKeyId().equals(id) && item.getNodeType() == nodeType)
|
|
|
+ .findFirst()
|
|
|
+ .orElse(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 比较sort值(处理null值情况)
|
|
|
+ */
|
|
|
+ private int compareSortValue(Integer sort1, Integer sort2) {
|
|
|
+ if (sort1 == null && sort2 == null) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ if (sort1 == null) {
|
|
|
+ return 1; // null值排在后面
|
|
|
+ }
|
|
|
+ if (sort2 == null) {
|
|
|
+ return -1; // null值排在后面
|
|
|
+ }
|
|
|
+ return sort1.compareTo(sort2);
|
|
|
+ }
|
|
|
+
|
|
|
// 根据叶子节点类型填充工程数据
|
|
|
private void fillEngineeringDataByLeafType(Row row, List<WbsTreeContract> projects, List<Long> ancestorIds,
|
|
|
Map<Integer, List<CellRangeAddress>> mergeMap, int rowNum,
|