|
|
@@ -203,7 +203,42 @@ public class ProfitAnalysisServiceImpl implements ProfitAnalysisService {
|
|
|
|
|
|
resultList.addAll(allAccountExpenses);
|
|
|
}
|
|
|
- return getTree(resultList);
|
|
|
+
|
|
|
+ List<ProfitAnalysisDto> tree = getTree(resultList);
|
|
|
+ String orderBy = profitAnalysisQueryDto.getOrderBy();
|
|
|
+ return sortListByField(tree, orderBy);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param tree
|
|
|
+ * @param orderBy
|
|
|
+ * @return 排序
|
|
|
+ */
|
|
|
+ private List<ProfitAnalysisDto> sortListByField(List<ProfitAnalysisDto> tree, String orderBy) {
|
|
|
+ if (tree == null || tree.isEmpty()) {
|
|
|
+ return tree;
|
|
|
+ }
|
|
|
+ if(StringUtils.isEmpty(orderBy)){
|
|
|
+ return tree;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 初始化比较器
|
|
|
+ Comparator<ProfitAnalysisDto> comparator = (dto1, dto2) -> {
|
|
|
+ BigDecimal applyAmount = dto1.getApplyAmount();// 假设字段名为applyAmount,根据实际情况调整
|
|
|
+ BigDecimal applyAmount1 = dto2.getApplyAmount();
|
|
|
+ return applyAmount.compareTo(applyAmount1);
|
|
|
+ };
|
|
|
+
|
|
|
+ // 根据排序方向调整比较器
|
|
|
+ if ("desc".equalsIgnoreCase(orderBy)) {
|
|
|
+ comparator = comparator.reversed();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 对列表进行排序
|
|
|
+ List<ProfitAnalysisDto> sortedList = new ArrayList<>(tree);
|
|
|
+ Collections.sort(sortedList, comparator);
|
|
|
+ return sortedList;
|
|
|
}
|
|
|
|
|
|
private BigDecimal aggregateChildAmounts(String expensesId, Map<String, ProfitAnalysisDto> map) {
|