From 017a4a668610a554e554d910e547ae9f05537c0e Mon Sep 17 00:00:00 2001 From: xuhy <3313886187@qq.com> Date: 星期一, 31 三月 2025 10:30:26 +0800 Subject: [PATCH] Merge branch 'dev' of http://120.76.84.145:10101/gitblit/r/java/xizang --- ruoyi-system/src/main/java/com/ruoyi/system/service/impl/ScreenService.java | 112 +++++++++++++++++++++++++++++++++++++++---------------- 1 files changed, 79 insertions(+), 33 deletions(-) diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/ScreenService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/ScreenService.java index dd6307c..59f1cae 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/ScreenService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/ScreenService.java @@ -4,7 +4,6 @@ import com.ruoyi.system.model.TBill; import com.ruoyi.system.model.TContract; import com.ruoyi.system.model.THouse; -import com.ruoyi.system.service.ITStreetService; import com.ruoyi.system.service.TBillService; import com.ruoyi.system.service.TContractService; import com.ruoyi.system.service.THouseService; @@ -16,11 +15,8 @@ import org.springframework.stereotype.Service; import java.math.BigDecimal; -import java.util.Date; -import java.util.List; -import java.util.Map; -import java.util.Calendar; -import java.util.ArrayList; +import java.math.RoundingMode; +import java.util.*; /** * @author mitao @@ -32,7 +28,6 @@ private final THouseService tHouseService; private final TContractService tContractService; private final TBillService tBillService; - private final ITStreetService tStreetService; /** * 获取顶部统计数据 * @return @@ -41,37 +36,74 @@ ScreenTopStaticsDataVO vo = new ScreenTopStaticsDataVO(); //房屋总面积 List<THouse> houseList = tHouseService.list(); - Double totalArea = houseList.stream().map(item -> Double.parseDouble(item.getHouseArea())).reduce(0D, Double::sum); + Double totalArea = houseList.stream() + .map(item -> Double.parseDouble(item.getHouseArea())) + .reduce(0D, Double::sum); vo.setHouseTotalArea(totalArea); //已出租面积 - Double totalRentedArea = houseList.stream().filter(item -> !item.getLeaseStatus().equals("1")) - .map(item -> Double.parseDouble(item.getHouseArea())).reduce(0D, Double::sum); + Double totalRentedArea = houseList.stream() + .filter(item -> !item.getLeaseStatus().equals("1")) + .map(item -> Double.parseDouble(item.getHouseArea())) + .reduce(0D, Double::sum); vo.setHouseRentedArea(totalRentedArea); //总计应收租金 List<TBill> billList = tBillService.list(); - BigDecimal totalReceivableRent = billList.stream().filter(item -> !item.getPayFeesStatus().equals("5")) - .map(TBill::getPayableFeesMoney).reduce(BigDecimal.ZERO, BigDecimal::add); + BigDecimal totalReceivableRent = billList.stream() + .filter(item -> !item.getPayFeesStatus().equals("5")) + .map(TBill::getPayableFeesMoney) + .reduce(BigDecimal.ZERO, BigDecimal::add) + .divide(new BigDecimal("10000"),2, RoundingMode.HALF_UP); vo.setTotalReceivableRent(totalReceivableRent); //总计已收租金 - BigDecimal totalReceivedRent = billList.stream().map(TBill::getPayFeesMoney).reduce(BigDecimal.ZERO, BigDecimal::add); + BigDecimal totalReceivedRent = billList.stream() + .map(TBill::getPayFeesMoney) + .reduce(BigDecimal.ZERO, BigDecimal::add) + .divide(new BigDecimal("10000"),2, RoundingMode.HALF_UP); vo.setTotalReceivedRent(totalReceivedRent); //本月新增租户数 Integer newTenantCount = tContractService.getCurrentMonthRentCount(); vo.setNewTenantCount(newTenantCount); //总计租户数 系统租户列表里有生效合同绑定的租户总数。 - Long count = tContractService.lambdaQuery().in(TContract::getStatus, "4", "5", "6", "7", "8", "9").groupBy(TContract::getTenantId).count(); - vo.setTotalTenantCount(count.intValue()); + List<TContract> tContracts = tContractService.lambdaQuery() + .in(TContract::getStatus, "4", "5", "6", "7", "8", "9") + .list(); + long count = tContracts.stream() + .map(TContract::getTenantId) + .distinct() + .count(); + vo.setTotalTenantCount((int) count); Map<String, Date> quarterDate = DateUtils.getQuarterDate(new Date()); Date first = quarterDate.get("first"); Date last = quarterDate.get("last"); - List<TBill> currentQuarterBillList = tBillService.lambdaQuery().between(TBill::getPayableFeesTime, first, last).list(); + List<TBill> currentQuarterBillList = tBillService.lambdaQuery() + .between(TBill::getPayableFeesTime, first, last) + .list(); //本季度已交租金 - BigDecimal totalRentPaid = currentQuarterBillList.stream().map(TBill::getPayFeesMoney).reduce(BigDecimal.ZERO, BigDecimal::add); + BigDecimal totalRentPaid = currentQuarterBillList.stream() + .map(TBill::getPayFeesMoney) + .reduce(BigDecimal.ZERO, BigDecimal::add) + .divide(new BigDecimal("10000"),2, RoundingMode.HALF_UP); vo.setTotalRentPaid(totalRentPaid); //本季度应交租金 - BigDecimal totalRentShould = currentQuarterBillList.stream().filter(item -> !item.getPayFeesStatus().equals("5")) - .map(TBill::getPayableFeesMoney).reduce(BigDecimal.ZERO, BigDecimal::add); + BigDecimal totalRentShould = currentQuarterBillList.stream() + .filter(item -> !item.getPayFeesStatus().equals("5")) + .map(TBill::getPayableFeesMoney) + .reduce(BigDecimal.ZERO, BigDecimal::add) + .divide(new BigDecimal("10000"),2, RoundingMode.HALF_UP); vo.setTotalRentShould(totalRentShould); + //本季度欠费 + BigDecimal totalRentOwe = currentQuarterBillList.stream() + .map(TBill::getOutstandingMoney) + .reduce(BigDecimal.ZERO, BigDecimal::add) + .divide(BigDecimal.valueOf(10000L), 2, RoundingMode.HALF_UP); + vo.setTotalRentOwe(totalRentOwe); + //总计欠费 + List<TBill> allBillList = tBillService.lambdaQuery().le(TBill::getPayableFeesTime, last).list(); + BigDecimal totalRentOweAll = allBillList.stream() + .map(TBill::getOutstandingMoney) + .reduce(BigDecimal.ZERO, BigDecimal::add) + .divide(BigDecimal.valueOf(10000L), 2, RoundingMode.HALF_UP); + vo.setTotalRentOweAll(totalRentOweAll); return vo; } @@ -92,8 +124,9 @@ // 获取当前日期 Date currentDate = new Date(); - List<String> quarterLabels = new ArrayList<>(); - List<BigDecimal> incomeData = new ArrayList<>(); + List<String> quarterLabels = new ArrayList<>(); // 季度标签列表 + List<BigDecimal> incomeData = new ArrayList<>(); //收入数据列表 + List<BigDecimal> outstandingData = new ArrayList<>(); // 欠费数据列表 // 获取最近7个季度的数据 for (int i = 6; i >= 0; i--) { @@ -102,28 +135,41 @@ Map<String, Date> quarterDate = DateUtils.getQuarterDate(targetDate); Date quarterStart = quarterDate.get("first"); Date quarterEnd = quarterDate.get("last"); - - // 获取该季度的账单数据并计算总和 - BigDecimal quarterIncome = tBillService.lambdaQuery() - .between(TBill::getPayableFeesTime, quarterStart, quarterEnd) - .list() - .stream() - .map(TBill::getPayFeesMoney) - .reduce(BigDecimal.ZERO, BigDecimal::add); - + + // 获取该季度的账单数据 + List<TBill> quarterBills = tBillService.lambdaQuery() + .between(TBill::getPayableFeesTime, quarterStart, quarterEnd) + .list(); + + // 计算季度租金收入总和 + BigDecimal quarterIncome = quarterBills.stream() + .map(TBill::getPayFeesMoney) + .filter(Objects::nonNull) + .reduce(BigDecimal.ZERO, BigDecimal::add) + .divide(BigDecimal.valueOf(10000L), 2, RoundingMode.HALF_UP); + + // 计算季度欠费总和 + BigDecimal quarterOutstanding = quarterBills.stream() + .map(TBill::getOutstandingMoney) + .filter(Objects::nonNull) + .reduce(BigDecimal.ZERO, BigDecimal::add) + .divide(BigDecimal.valueOf(10000L), 2, RoundingMode.HALF_UP); + // 生成季度标签 (格式: YY-MM月) Calendar cal = Calendar.getInstance(); cal.setTime(quarterEnd); String label = String.format("%02d-%d月", - cal.get(Calendar.YEAR) % 100, - cal.get(Calendar.MONTH) + 1); - + cal.get(Calendar.YEAR) % 100, + cal.get(Calendar.MONTH) + 1); + quarterLabels.add(label); incomeData.add(quarterIncome); + outstandingData.add(quarterOutstanding); // 添加欠费数据 } vo.setQuarters(quarterLabels); vo.setIncomeData(incomeData); + vo.setOutstandingData(outstandingData); // 设置欠费数据到VO return vo; } -- Gitblit v1.7.1