yaowanxin
昨天 3a76f9efb61f7bdbf96dfa429214ee0c8322a539
src/main/java/com/ruoyi/account/service/impl/AccountExpenseServiceImpl.java
@@ -9,19 +9,20 @@
import com.ruoyi.account.dto.AccountDto2;
import com.ruoyi.account.dto.AccountDto3;
import com.ruoyi.account.mapper.AccountExpenseMapper;
import com.ruoyi.account.mapper.AccountFileMapper;
import com.ruoyi.account.mapper.AccountIncomeMapper;
import com.ruoyi.account.pojo.AccountExpense;
import com.ruoyi.account.pojo.AccountIncome;
import com.ruoyi.account.service.AccountExpenseService;
import com.ruoyi.account.service.AccountIncomeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.dto.DateQueryDto;
import com.ruoyi.project.system.domain.SysDictData;
import com.ruoyi.project.system.mapper.SysDictDataMapper;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
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;
@@ -36,6 +37,8 @@
    private AccountExpenseMapper accountExpenseMapper;
    private AccountIncomeMapper accountIncomeMapper;
    private SysDictDataMapper sysDictDataMapper;
    //分页查询
@@ -88,26 +91,65 @@
    //财务报表年查询
    @Override
    public AccountDto3 reportExpense() {
        AccountDto3 accountDto3 = new AccountDto3();
    public  List<AccountDto3> reportExpense() {
        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)
        List<String> months = new ArrayList<>();
        Map<String, List<AccountDto2>> map = new HashMap<>();
        for (int i = 1; i <= 12; i++) {
            months.add(i + "月");
            // 当月第一天:年份为当前年,月份为i,日期为1
            LocalDate firstDay = LocalDate.of(currentYear, i, 1);
            DateQueryDto dateQueryDto = new DateQueryDto();
            dateQueryDto.setEntryDateStart(firstDay.format(formatter));
            // 当月最后一天:第一天的月份的最后一天
            dateQueryDto.setEntryDateEnd(firstDay.plusMonths(1).minusDays(1).format(formatter));
            List<AccountDto2> report = accountExpenseMapper.report(dateQueryDto);
            map.put(i + "月",report);
        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);
                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()));
            }
            accountDto3.setAccount(account);//类型
            accountDto3s.add(accountDto3);
        }
        accountDto3.setMonth(months);
        accountDto3.setAccountType(map);
        return accountDto3;
        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;
    }