| | |
| | | import com.ruoyi.account.dto.AccountDto; |
| | | import com.ruoyi.account.dto.AccountDto2; |
| | | import com.ruoyi.account.dto.AccountDto3; |
| | | import com.ruoyi.account.dto.ReportDateDto; |
| | | import com.ruoyi.account.mapper.AccountExpenseMapper; |
| | | import com.ruoyi.account.mapper.AccountIncomeMapper; |
| | | import com.ruoyi.account.pojo.AccountExpense; |
| | |
| | | |
| | | //财务报表年查询 |
| | | @Override |
| | | public List<AccountDto3> reportExpense() { |
| | | public List<AccountDto3> reportExpense(ReportDateDto reportDateDto) { |
| | | List<AccountDto3> accountDto3s = new ArrayList<>(); |
| | | //先查询收入类型有哪些 |
| | | List<SysDictData> incomeTypes = sysDictDataMapper.selectDictDataByType("expense_types"); |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
| | | int currentYear = LocalDate.now().getYear(); // 获取当前年份(如2025) |
| | | // int currentYear = LocalDate.now().getYear(); // 获取当前年份(如2025) |
| | | for (SysDictData incomeType : incomeTypes) { |
| | | AccountDto3 accountDto3 = new AccountDto3(); |
| | | accountDto3.setTypeName(incomeType.getDictLabel());//类型 |
| | | List<BigDecimal> account=new ArrayList<>(); |
| | | for (int i = 1; i <= 12; i++) { |
| | | // 当月第一天:年份为当前年,月份为i,日期为1 |
| | | LocalDate firstDay = LocalDate.of(currentYear, i, 1); |
| | | LocalDate startDate = reportDateDto.getEntryDateStart(); |
| | | LocalDate endDate = reportDateDto.getEntryDateEnd(); |
| | | |
| | | // 初始化循环变量为起始日期 |
| | | LocalDate currentDate = startDate; |
| | | |
| | | // 循环:当前日期不超过结束日期时继续 |
| | | while (!currentDate.isAfter(endDate)) { |
| | | // 当月第一天 |
| | | LocalDate firstDay = currentDate.withDayOfMonth(1); |
| | | DateQueryDto dateQueryDto = new DateQueryDto(); |
| | | dateQueryDto.setEntryDateStart(firstDay.format(formatter)); |
| | | // 当月最后一天:第一天的月份的最后一天 |
| | | dateQueryDto.setEntryDateEnd(firstDay.plusMonths(1).minusDays(1).format(formatter)); |
| | | account.add(accountExpenseMapper.report1(dateQueryDto,incomeType.getDictValue())); |
| | | |
| | | // 当月最后一天 |
| | | LocalDate lastDay = firstDay.plusMonths(1).minusDays(1); |
| | | dateQueryDto.setEntryDateEnd(lastDay.format(formatter)); |
| | | |
| | | // 累加数据 |
| | | account.add(accountExpenseMapper.report1(dateQueryDto, incomeType.getDictValue())); |
| | | |
| | | // 月份加一(自动处理跨年,比如12月加1个月会变成下一年1月) |
| | | currentDate = currentDate.plusMonths(1); |
| | | } |
| | | accountDto3.setAccount(account);//类型 |
| | | accountDto3s.add(accountDto3); |