From 47b42159fbe69fb2b4dbc13c75dd45abd00a55ae Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期五, 13 二月 2026 11:10:34 +0800
Subject: [PATCH] fix: 查询日期缺少时分秒

---
 src/main/resources/mapper/sales/SalesLedgerProductMapper.xml       |   10 +++-
 src/main/java/com/ruoyi/stock/mapper/StockInventoryMapper.java     |    5 +-
 src/main/resources/mapper/stock/StockInventoryMapper.xml           |   14 ++++---
 src/main/java/com/ruoyi/sales/mapper/SalesLedgerProductMapper.java |    9 ++--
 src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java     |   30 +++++---------
 5 files changed, 34 insertions(+), 34 deletions(-)

diff --git a/src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java b/src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java
index 0f4425c..84d1934 100644
--- a/src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java
+++ b/src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java
@@ -1032,28 +1032,20 @@
 
     @Override
     public List<MapDto> salesPurchaseStorageProductCount() {
-        LocalDate now = LocalDate.now();
-        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+        LocalDateTime now = LocalDateTime.now();
+        LocalDateTime currentMonthStart = now.with(TemporalAdjusters.firstDayOfMonth()).with(LocalTime.MIN);
+        LocalDateTime lastMonth = now.minusMonths(1);
+        LocalDateTime lastMonthStart = lastMonth.with(TemporalAdjusters.firstDayOfMonth()).with(LocalTime.MIN);
+        LocalDateTime lastMonthEnd = lastMonth.with(TemporalAdjusters.lastDayOfMonth()).with(LocalTime.MAX);
 
-        String currentMonthStart = now.with(TemporalAdjusters.firstDayOfMonth()).format(dtf);
-        String currentMonthNow = now.format(dtf);
-
-        LocalDate lastMonth = now.minusMonths(1);
-        String lastMonthStart = lastMonth.with(TemporalAdjusters.firstDayOfMonth()).format(dtf);
-        String lastMonthEnd = lastMonth.with(TemporalAdjusters.lastDayOfMonth()).format(dtf);
-
-        // 閿�鍞�
-        int currentSales = salesLedgerProductMapper.selectProductCountByTypeAndDate(1, currentMonthStart,
-                currentMonthNow);
+        //  閿�鍞�
+        int currentSales = salesLedgerProductMapper.selectProductCountByTypeAndDate(1, currentMonthStart, now);
         int lastSales = salesLedgerProductMapper.selectProductCountByTypeAndDate(1, lastMonthStart, lastMonthEnd);
-
-        // 閲囪喘
-        int currentPurchase = salesLedgerProductMapper.selectProductCountByTypeAndDate(2, currentMonthStart,
-                currentMonthNow);
+        //  閲囪喘
+        int currentPurchase = salesLedgerProductMapper.selectProductCountByTypeAndDate(2, currentMonthStart, now);
         int lastPurchase = salesLedgerProductMapper.selectProductCountByTypeAndDate(2, lastMonthStart, lastMonthEnd);
-
-        // 鍌ㄥ瓨
-        int currentStorage = stockInventoryMapper.selectStorageProductCountByDate(currentMonthStart, currentMonthNow);
+        //  鍌ㄥ瓨
+        int currentStorage = stockInventoryMapper.selectStorageProductCountByDate(currentMonthStart, now);
         int lastStorage = stockInventoryMapper.selectStorageProductCountByDate(lastMonthStart, lastMonthEnd);
 
         List<MapDto> list = new ArrayList<>();
diff --git a/src/main/java/com/ruoyi/sales/mapper/SalesLedgerProductMapper.java b/src/main/java/com/ruoyi/sales/mapper/SalesLedgerProductMapper.java
index 94e9892..686fc2e 100644
--- a/src/main/java/com/ruoyi/sales/mapper/SalesLedgerProductMapper.java
+++ b/src/main/java/com/ruoyi/sales/mapper/SalesLedgerProductMapper.java
@@ -11,6 +11,7 @@
 import org.apache.ibatis.annotations.Param;
 
 import java.math.BigDecimal;
+import java.time.LocalDateTime;
 import java.util.List;
 import java.util.Map;
 
@@ -21,7 +22,7 @@
  * @date 2025-05-08
  */
 public interface SalesLedgerProductMapper extends MyBaseMapper<SalesLedgerProduct> {
-     List<SalesLedgerProduct> selectProduct() ;
+    List<SalesLedgerProduct> selectProduct();
 
     List<SalesLedgerProduct> selectSalesLedgerProductList(@Param("salesLedgerProduct") SalesLedgerProduct salesLedgerProduct);
 
@@ -29,9 +30,9 @@
 
     IPage<SalesLedgerProductDto> listPage(Page page, @Param("req") SalesLedgerProductDto salesLedgerProduct);
 
-    IPage<SalesLedgerProductDto> listPagePurchaseLedger(Page page,@Param("req") SalesLedgerProductDto salesLedgerProduct);
+    IPage<SalesLedgerProductDto> listPagePurchaseLedger(Page page, @Param("req") SalesLedgerProductDto salesLedgerProduct);
 
-    IPage<ProcurementBusinessSummaryDto> procurementBusinessSummaryListPage(Page page,@Param("req") ProcurementBusinessSummaryDto procurementBusinessSummaryDto);
+    IPage<ProcurementBusinessSummaryDto> procurementBusinessSummaryListPage(Page page, @Param("req") ProcurementBusinessSummaryDto procurementBusinessSummaryDto);
 
     List<LossProductModelDto> selectProductBomStructure(@Param("salesLedegerId") Long salesLedegerId);
 
@@ -39,7 +40,7 @@
 
     List<Map<String, Object>> selectRawMaterialPurchaseAnalysis();
 
-    int selectProductCountByTypeAndDate(@Param("type") Integer type, @Param("startDate") String startDate, @Param("endDate") String endDate);
+    int selectProductCountByTypeAndDate(@Param("type") Integer type, @Param("startDate") LocalDateTime startDate, @Param("endDate") LocalDateTime endDate);
 
     BigDecimal selectRawMaterialExpense();
 }
diff --git a/src/main/java/com/ruoyi/stock/mapper/StockInventoryMapper.java b/src/main/java/com/ruoyi/stock/mapper/StockInventoryMapper.java
index e58db7c..0d345df 100644
--- a/src/main/java/com/ruoyi/stock/mapper/StockInventoryMapper.java
+++ b/src/main/java/com/ruoyi/stock/mapper/StockInventoryMapper.java
@@ -12,6 +12,7 @@
 
 import java.math.BigDecimal;
 import java.time.LocalDate;
+import java.time.LocalDateTime;
 import java.util.List;
 import java.util.Map;
 
@@ -41,11 +42,11 @@
 
     BigDecimal selectTotal();
 
-    int selectStorageProductCountByDate(@Param("startDate") String startDate, @Param("endDate") String endDate);
+    int selectStorageProductCountByDate(@Param("startDate") LocalDateTime startDate, @Param("endDate") LocalDateTime endDate);
 
     List<Map<String, Object>> selectDailyStockInCounts(@Param("rootCategoryId") Long rootCategoryId, @Param("startDate") String startDate, @Param("endDate") String endDate);
 
     List<Map<String, Object>> selectDailyStockOutCounts(@Param("rootCategoryId") Long rootCategoryId, @Param("startDate") String startDate, @Param("endDate") String endDate);
 
-    BigDecimal selectTotalByDate( @Param("now") LocalDate now);
+    BigDecimal selectTotalByDate(@Param("now") LocalDate now);
 }
diff --git a/src/main/resources/mapper/sales/SalesLedgerProductMapper.xml b/src/main/resources/mapper/sales/SalesLedgerProductMapper.xml
index 4adf09e..671fcf5 100644
--- a/src/main/resources/mapper/sales/SalesLedgerProductMapper.xml
+++ b/src/main/resources/mapper/sales/SalesLedgerProductMapper.xml
@@ -196,11 +196,15 @@
     </select>
 
     <select id="selectProductCountByTypeAndDate" resultType="int">
-        SELECT COUNT(*)
+        SELECT IFNULL(COUNT(*), 0)
         FROM sales_ledger_product
         WHERE type = #{type}
-        AND register_date &gt;= #{startDate}
-        AND register_date &lt;= #{endDate}
+        <if test="startDate != null">
+            AND register_date &gt;= #{startDate}
+        </if>
+        <if test="endDate != null">
+            AND register_date &lt;= #{endDate}
+        </if>
     </select>
 
     <select id="selectRawMaterialExpense" resultType="java.math.BigDecimal">
diff --git a/src/main/resources/mapper/stock/StockInventoryMapper.xml b/src/main/resources/mapper/stock/StockInventoryMapper.xml
index 7fe1f4f..9db56f9 100644
--- a/src/main/resources/mapper/stock/StockInventoryMapper.xml
+++ b/src/main/resources/mapper/stock/StockInventoryMapper.xml
@@ -199,14 +199,16 @@
     </select>
 
     <select id="selectStorageProductCountByDate" resultType="int">
-        SELECT COUNT(*)
-        FROM (SELECT create_time
+        SELECT SUM(total_count)
+        FROM (SELECT COUNT(*) as total_count
               FROM stock_inventory
+              WHERE create_time &gt;= #{startDate}
+                AND create_time &lt;= #{endDate}
               UNION ALL
-              SELECT create_time
-              FROM stock_uninventory) combined
-        WHERE create_time &gt;= #{startDate}
-          AND create_time &lt;= #{endDate}
+              SELECT COUNT(*) as total_count
+              FROM stock_uninventory
+              WHERE create_time &gt;= #{startDate}
+                AND create_time &lt;= #{endDate}) AS combined_counts
     </select>
 
     <select id="selectDailyStockInCounts" resultType="java.util.Map">

--
Gitblit v1.9.3