From dbf671285d9217f6ca84ee1e795aa9af386955e3 Mon Sep 17 00:00:00 2001
From: luofl <1442745593@qq.com>
Date: 星期四, 03 四月 2025 21:06:02 +0800
Subject: [PATCH] 1.租户数量趋势统计

---
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/ScreenController.java       |   56 ++++++------------
 ruoyi-system/src/main/java/com/ruoyi/system/service/TContractService.java          |    1 
 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/ScreenService.java        |   71 +++++++++++++++++++++--
 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TContractServiceImpl.java |    2 
 4 files changed, 86 insertions(+), 44 deletions(-)

diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/ScreenController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/ScreenController.java
index d188bfe..27aed4c 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/ScreenController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/ScreenController.java
@@ -69,40 +69,11 @@
         return R.ok(screenService.rentIncomeTrend());
     }
 
+
     @GetMapping("/getTenantCountTrend")
     @ApiOperation(value = "租户数量趋势统计")
     public R<List<TenantCountTrendVO>> getTenantCountTrend() {
-
-        String businessDeptId = SecurityUtils.getBusinessDeptId();
-        Date currentDate = new Date();
-        Date targetDate = DateUtils.addMonths(currentDate, -3 * 6);
-        Map<String, Date> startQuarterDate = DateUtils.getQuarterDate(targetDate);
-
-
-        Date targetDate2 = DateUtils.addMonths(currentDate, 0);
-        Map<String, Date> endQuarterDate = DateUtils.getQuarterDate(targetDate2);
-
-        List<TContract> contracts = contractService.list(new LambdaQueryWrapper<TContract>()
-                .eq(!"0".equals(businessDeptId),TContract::getBusinessDeptId, businessDeptId)
-                .isNotNull(TContract::getSignTime)
-                .between(TContract::getSignTime, startQuarterDate.get("first"), endQuarterDate.get("last"))
-                .orderByAsc(TContract::getSignTime));
-
-        DateTimeFormatter quarterFormatter = DateTimeFormatter.ofPattern("yyyy-MM");
-
-        List<TenantCountTrendVO> trendData = contracts.stream()
-                .collect(Collectors.groupingBy(contract -> {
-                    LocalDate date = contract.getSignTime().toLocalDate();
-                    int quarter = (date.getMonthValue() - 1) / 3 + 1;
-                    return YearQuarter.from(date.withMonth(quarter * 3 - 2));
-                }, TreeMap::new, Collectors.counting()))
-                .entrySet().stream()
-                .map(entry -> new TenantCountTrendVO(
-                        entry.getKey().format(quarterFormatter),
-                        entry.getValue()))
-                .collect(Collectors.toList());
-
-        return R.ok(trendData);
+        return screenService.getTenantCountTrend();
     }
 
 
@@ -152,8 +123,16 @@
 
         String businessDeptId = SecurityUtils.getBusinessDeptId();
         // 获取所有房屋信息
+        List<TContract> tContracts = contractService.list(new LambdaQueryWrapper<TContract>()
+                .eq(!"0".equals(businessDeptId), TContract::getBusinessDeptId, businessDeptId)
+                .eq(TContract::getPayType, 1));
+        List<String> houseIds = tContracts.stream().map(TContract::getHouseId).collect(Collectors.toList());
+        if (houseIds.isEmpty()){
+            return R.ok(new ArrayList<>());
+        }
         List<THouse> houses = houseService.list(new LambdaQueryWrapper<THouse>()
-                .eq(!"0".equals(businessDeptId),THouse::getBusinessDeptId, businessDeptId));
+                .eq(!"0".equals(businessDeptId),THouse::getBusinessDeptId, businessDeptId)
+                .in(THouse::getId, houseIds));
         List<HouseMapDistributionVO> result = new ArrayList<>();
         for (THouse house : houses) {
             HouseMapDistributionVO houseMapDistributionVO = new HouseMapDistributionVO();
@@ -164,6 +143,7 @@
             houseMapDistributionVO.setLatitude(house.getLatitude());
             TContract contract = contractService.getOne(new LambdaQueryWrapper<TContract>()
                     .eq(!"0".equals(businessDeptId),TContract::getBusinessDeptId, businessDeptId)
+                    .eq(TContract::getPayType, 1)
                     .gt(TContract::getEndTime, LocalDate.now())
                     .eq(TContract::getHouseId, house.getId())
                     .eq(TContract::getStatus, 4)
@@ -182,11 +162,11 @@
                 long monthsBetween = ChronoUnit.MONTHS.between(startTime, endTime);
                 BigDecimal payableFeesMoney = monthRent.multiply(new BigDecimal(monthsBetween));
 
-                BigDecimal paidAlready = tBills.stream()
-                        .map(TBill::getPayableFeesMoney)
+                BigDecimal payFeesMoney = tBills.stream()
+                        .map(TBill::getPayFeesMoney)
                         .reduce(BigDecimal::add)
                         .orElse(BigDecimal.ZERO);
-                String rentStatus = String.format("%.2f/%.2f", paidAlready, payableFeesMoney);
+                String rentStatus = String.format("%.2f/%.2f", payFeesMoney, payableFeesMoney);
                 houseMapDistributionVO.setRentStatus(rentStatus);
 
 
@@ -211,9 +191,9 @@
                     if ("4".equals(one.getPayFeesStatus())){
                         houseMapDistributionVO.setHouseStatus("4");
                     }
-                    BigDecimal payFeesMoney = one.getPayFeesMoney();
+                    BigDecimal payFeesMoney1 = one.getPayFeesMoney();
                     BigDecimal payableFeesMoney1 = one.getPayableFeesMoney();
-                    String rent = String.format("%.2f/%.2f", payFeesMoney, payableFeesMoney1);
+                    String rent = String.format("%.2f/%.2f", payFeesMoney1, payableFeesMoney1);
                     houseMapDistributionVO.setRent(rent);
                 }else {
                     houseMapDistributionVO.setRent("暂无");
@@ -221,7 +201,7 @@
             }else {
                 houseMapDistributionVO.setTenant("暂无");
                 houseMapDistributionVO.setRentStatus("暂无");
-                houseMapDistributionVO.setRent("暂无");
+                houseMapDistributionVO.setRent("欠费");
             }
             result.add(houseMapDistributionVO);
         }
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/TContractService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/TContractService.java
index d7a62b9..76018de 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/TContractService.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/TContractService.java
@@ -11,6 +11,7 @@
 import com.ruoyi.system.query.TContractQuery;
 import com.ruoyi.system.vo.BillVO;
 import com.ruoyi.system.vo.CheckAcceptRecordVO;
+import com.ruoyi.system.vo.ScreenRentIncomeTrendVO;
 
 import java.util.List;
 
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 12d5ea6..805e13c 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
@@ -1,5 +1,8 @@
 package com.ruoyi.system.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.ruoyi.common.core.domain.R;
+import com.ruoyi.common.enums.BillTypeEnum;
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.system.model.TBill;
@@ -11,18 +14,14 @@
 import com.ruoyi.system.vo.ScreenRentIncomeTrendVO;
 import com.ruoyi.system.vo.ScreenRentRankVO;
 import com.ruoyi.system.vo.ScreenTopStaticsDataVO;
+import com.ruoyi.system.vo.TenantCountTrendVO;
 import lombok.RequiredArgsConstructor;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
 import java.math.RoundingMode;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
+import java.util.*;
 
 /**
  * @author mitao
@@ -34,6 +33,7 @@
     private final THouseService tHouseService;
     private final TContractService tContractService;
     private final TBillService tBillService;
+    private final TContractService contractService;
     /**
      * 获取顶部统计数据
      * @return
@@ -177,6 +177,65 @@
         return vo;
     }
 
+    public R<List<TenantCountTrendVO>> getTenantCountTrend() {
+
+        // 获取当前日期
+        Date currentDate = new Date();
+        String businessDeptId = SecurityUtils.getBusinessDeptId();
+        List<TenantCountTrendVO> list = new ArrayList<>();
+        for (int i = 6; i >= 0; i--) {
+            Date targetDate = DateUtils.addMonths(currentDate, -3 * i);
+            Map<String, Date> quarterDate = DateUtils.getQuarterDate(targetDate);
+            Date quarterStart = quarterDate.get("first");
+            Date quarterEnd = quarterDate.get("last");
+            System.out.println("第" + (i + 1) + "季度的起止时间:" + quarterStart + " - " + quarterEnd);
+
+            List<TContract> contracts = contractService.list(new LambdaQueryWrapper<TContract>()
+                    .eq(!"0".equals(businessDeptId), TContract::getBusinessDeptId, businessDeptId)
+                    .eq(TContract::getPayType, 1)
+                    .isNotNull(TContract::getSignTime)
+                    .between(TContract::getSignTime, quarterStart, quarterEnd)
+                    .orderByAsc(TContract::getSignTime));
+
+
+            TenantCountTrendVO vo = new TenantCountTrendVO();
+            // 生成季度标签 (格式: 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);
+            vo.setDate(label);
+            long count = contracts.stream().map(TContract::getTenantId).distinct().count();
+            vo.setCount(count);
+            list.add(vo);
+        }
+        return R.ok(list);
+    }
+//
+//
+//
+//
+//
+//
+//
+//        DateTimeFormatter quarterFormatter = DateTimeFormatter.ofPattern("yyyy-MM");
+//
+//        List<TenantCountTrendVO> trendData = contracts.stream()
+//                .collect(Collectors.groupingBy(contract -> {
+//                    LocalDate date = contract.getSignTime().toLocalDate();
+//                    int quarter = (date.getMonthValue() - 1) / 3 + 1;
+//                    return YearQuarter.from(date.withMonth(quarter * 3 - 2));
+//                }, TreeMap::new, Collectors.counting()))
+//                .entrySet().stream()
+//                .map(entry -> new TenantCountTrendVO(
+//                        entry.getKey().format(quarterFormatter),
+//                        entry.getValue()))
+//                .collect(Collectors.toList());
+//
+//        return R.ok(trendData);
+//    }
+
 
 
 }
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TContractServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TContractServiceImpl.java
index f3d7f8b..b9e250b 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TContractServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TContractServiceImpl.java
@@ -31,6 +31,7 @@
 import com.ruoyi.system.service.TContractService;
 import com.ruoyi.system.vo.BillVO;
 import com.ruoyi.system.vo.CheckAcceptRecordVO;
+import com.ruoyi.system.vo.ScreenRentIncomeTrendVO;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -221,4 +222,5 @@
         pageInfo = this.baseMapper.page(pageInfo,query);
         return pageInfo;
     }
+
 }

--
Gitblit v1.7.1