|
|
@@ -175,12 +175,44 @@ public class FinanceCheckinService {
|
|
|
.mapToLong(FinanceCheckin::getEarnedEnergy)
|
|
|
.sum();
|
|
|
|
|
|
+ // 收支统计
|
|
|
+ long totalIncome = all.stream()
|
|
|
+ .filter(c -> "income".equals(c.getType()) && c.getAmount() != null)
|
|
|
+ .mapToLong(FinanceCheckin::getAmount)
|
|
|
+ .sum();
|
|
|
+ long totalExpense = all.stream()
|
|
|
+ .filter(c -> "expense".equals(c.getType()) && c.getAmount() != null)
|
|
|
+ .mapToLong(FinanceCheckin::getAmount)
|
|
|
+ .sum();
|
|
|
+
|
|
|
+ // 本月统计
|
|
|
+ java.util.Calendar cal = java.util.Calendar.getInstance();
|
|
|
+ int year = cal.get(java.util.Calendar.YEAR);
|
|
|
+ int month = cal.get(java.util.Calendar.MONTH) + 1;
|
|
|
+ String monthPrefix = year + "-" + (month < 10 ? "0" : "") + month;
|
|
|
+ long monthIncome = all.stream()
|
|
|
+ .filter(c -> "income".equals(c.getType()) && c.getAmount() != null
|
|
|
+ && c.getCheckinDate() != null && c.getCheckinDate().toString().startsWith(monthPrefix))
|
|
|
+ .mapToLong(FinanceCheckin::getAmount)
|
|
|
+ .sum();
|
|
|
+ long monthExpense = all.stream()
|
|
|
+ .filter(c -> "expense".equals(c.getType()) && c.getAmount() != null
|
|
|
+ && c.getCheckinDate() != null && c.getCheckinDate().toString().startsWith(monthPrefix))
|
|
|
+ .mapToLong(FinanceCheckin::getAmount)
|
|
|
+ .sum();
|
|
|
+
|
|
|
Map<String, Object> stats = new HashMap<>();
|
|
|
stats.put("totalCheckins", totalCheckins);
|
|
|
stats.put("totalEnergy", totalEnergy);
|
|
|
+ stats.put("totalIncome", totalIncome);
|
|
|
+ stats.put("totalExpense", totalExpense);
|
|
|
+ stats.put("balance", totalIncome - totalExpense);
|
|
|
+ stats.put("monthIncome", monthIncome);
|
|
|
+ stats.put("monthExpense", monthExpense);
|
|
|
+ stats.put("monthBalance", monthIncome - monthExpense);
|
|
|
stats.put("dailyPlanCount", all.stream().filter(c -> "daily_plan".equals(c.getCheckinType())).count());
|
|
|
stats.put("savingCount", all.stream().filter(c -> "saving".equals(c.getCheckinType())).count());
|
|
|
- stats.put("expenseCount", all.stream().filter(c -> "expense".equals(c.getCheckinType())).count());
|
|
|
+ stats.put("expenseCount", all.stream().filter(c -> c.getCheckinType() != null && c.getCheckinType().contains("expense")).count());
|
|
|
stats.put("reviewCount", all.stream().filter(c -> "review".equals(c.getCheckinType())).count());
|
|
|
return stats;
|
|
|
}
|