| | |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.math.BigDecimal; |
| | | import java.time.DayOfWeek; |
| | | import java.time.LocalDate; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.ArrayList; |
| | |
| | | return accountDto3s; |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, List<String>> analysis() { |
| | | // 获取本周的时间范围 |
| | | LocalDate startOfWeek = LocalDate.now().with(DayOfWeek.MONDAY); |
| | | LocalDate endOfWeek = LocalDate.now().with(DayOfWeek.SUNDAY); |
| | | Map<String, List<String>> result = new HashMap<>(); |
| | | List<String> days = new ArrayList<>(); |
| | | List<String> totalIncomeList = new ArrayList<>(); |
| | | List<String> totalExpenseList = new ArrayList<>(); |
| | | List<String> netIncomeList = new ArrayList<>(); |
| | | // 根据时间范围循环查询每一天的总收入,总支出,净收入(总收入-总支出) |
| | | for (LocalDate date = startOfWeek; date.isBefore(endOfWeek) || date.isEqual(endOfWeek); date = date.plusDays(1)) { |
| | | BigDecimal totalIncome = accountIncomeMapper.selectList(Wrappers.<AccountIncome>lambdaQuery() |
| | | .eq(AccountIncome::getInputTime, date.toString())) |
| | | .stream() |
| | | .map(AccountIncome::getIncomeMoney) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | BigDecimal totalExpense = accountExpenseMapper.selectList(Wrappers.<AccountExpense>lambdaQuery() |
| | | .eq(AccountExpense::getInputTime, date.toString())) |
| | | .stream() |
| | | .map(AccountExpense::getExpenseMoney) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | BigDecimal netIncome = totalIncome.subtract(totalExpense); |
| | | days.add(date.toString()); |
| | | totalIncomeList.add(totalIncome.toString()); |
| | | totalExpenseList.add(totalExpense.toString()); |
| | | netIncomeList.add(netIncome.toString()); |
| | | } |
| | | result.put("days", days); // 天 |
| | | result.put("totalIncome", totalIncomeList); // 收入 |
| | | result.put("totalExpense", totalExpenseList); // 支出 |
| | | result.put("netIncome", netIncomeList); // 净收入 |
| | | |
| | | return result; |
| | | } |
| | | |
| | | |
| | | } |