From 0204bc614e3132ce94d3fb1de9d330e9250f233c Mon Sep 17 00:00:00 2001
From: huangxiaoqiang <huangxiaoqiang@hnkhzn.com>
Date: 星期六, 15 十一月 2025 14:10:09 +0800
Subject: [PATCH] 新增大屏显示,优化WMS首页数据展示,后端数据推送接口新加库存差异比较

---
 项目代码/WMS/WIDESEA_WMSServer/WIDESEA_StorageBasicServices/Stock/StockInfoService.cs |   33 ++++++++++++++++++++++++++-------
 1 files changed, 26 insertions(+), 7 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_StorageBasicServices/Stock/StockInfoService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_StorageBasicServices/Stock/StockInfoService.cs"
index 86b075c..ef5112f 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_StorageBasicServices/Stock/StockInfoService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_StorageBasicServices/Stock/StockInfoService.cs"
@@ -457,17 +457,33 @@
             DateTime firstDayOfMonth = new DateTime(utcNow.Year, utcNow.Month, 1);
             DateTime lastDayOfMonth = firstDayOfMonth.AddMonths(1).AddSeconds(-1);
 
+            // 璁$畻涓婃湀鏃堕棿鑼冨洿
+            DateTime firstDayOfLastMonth = new DateTime(utcNow.Year, utcNow.Month, 1).AddMonths(-1);
+            DateTime lastDayOfLastMonth = firstDayOfLastMonth.AddMonths(1).AddSeconds(-1);
+
             // 璁$畻褰撳ぉ鏃堕棿鑼冨洿
             DateTime todayStart = utcNow.Date;
             DateTime todayEnd = todayStart.AddDays(1).AddTicks(-1);
+
+            // 璁$畻鏄ㄦ棩鏃堕棿鑼冨洿
+            DateTime startOfPreviousDay = utcNow.AddDays(-1).Date;  // 鍓嶄竴澶╃殑 00:00:00
+            DateTime endOfPreviousDay = startOfPreviousDay.AddDays(1).AddSeconds(-1);
 
             // 鏌ヨ褰撴湀鏁版嵁
             var currentMonthInStocks = stocks.Where(x => x.CreateDate >= firstDayOfMonth && x.CreateDate <= lastDayOfMonth).Sum(x => x.Quantity);
             var currentMonthOutStocks = orderdetail.Where(x => x.CreateDate >= firstDayOfMonth && x.CreateDate <= lastDayOfMonth).Sum(x => x.OutboundQuantity);
 
-            // 鏌ヨ褰撴棩鏁版嵁
+            //鏌ヨ涓婃湀鏁版嵁
+            var currentMonthInStocksLastMonth = stocks.Where(x => x.CreateDate >= firstDayOfLastMonth && x.CreateDate <= lastDayOfLastMonth).Sum(x => x.Quantity);
+            var currentMonthOutStocksLastMonth = orderdetail.Where(x => x.CreateDate >= firstDayOfLastMonth && x.CreateDate <= lastDayOfLastMonth).Sum(x => x.OutboundQuantity);
+
+            // 鏌ヨ浠婃棩鏁版嵁
             var currentDayInStocks = stocks.Where(x => x.CreateDate >= todayStart && x.CreateDate <= todayEnd).Sum(x => x.Quantity);
             var currentDayOutStocks = orderdetail.Where(x => x.CreateDate >= todayStart && x.CreateDate <= todayEnd).Sum(x => x.OutboundQuantity);
+
+            // 鏌ヨ鏄ㄥぉ鏃ユ暟鎹�
+            var currentDayInStocksLast = stocks.Where(x => x.CreateDate >= startOfPreviousDay && x.CreateDate <= endOfPreviousDay).Sum(x => x.Quantity);
+            var currentDayOutStocksLast = orderdetail.Where(x => x.CreateDate >= startOfPreviousDay && x.CreateDate <= endOfPreviousDay).Sum(x => x.OutboundQuantity);
 
             // 鐢熸垚鏈�杩�7澶╃殑鍑哄叆搴撴暟鎹�
             var last7Days = Enumerable.Range(0, 7)
@@ -483,7 +499,7 @@
             var inboundData = last7Days.Select(date => new
             {
                 Date = date.ToString("MM-dd"),
-                Value = stocks.Where(x => x.CreateDate.Date == date).Sum(x => x.Quantity)
+                Value = stocks.Where(x => x.CreateDate.Date == date).Sum(x => x.Quantity),
             }).ToList();
 
             var outboundData = last7Days.Select(date => new
@@ -504,19 +520,23 @@
                 metrics = new List<object>{
                 new {
                     name = "浠婃棩杩涘簱閲�",
-                    value = currentDayInStocks
+                    value = currentDayInStocks,
+                    compare =currentDayInStocks-currentDayInStocksLast,
                 },
                 new {
                     name = "浠婃棩鍑哄簱閲�",
-                    value = currentDayOutStocks
+                    value = currentDayOutStocks,
+                    compare =currentDayOutStocks-currentDayOutStocksLast,
                 },
                 new {
                     name = "鏈湀杩涘簱閲�",
-                    value = currentMonthInStocks
+                    value = currentMonthInStocks,
+                    compare =currentMonthInStocks-currentMonthInStocksLastMonth,
                 },
                 new {
                     name = "鏈湀鍑哄簱閲�",
-                    value = currentMonthOutStocks
+                    value = currentMonthOutStocks,
+                    compare = currentMonthOutStocks - currentMonthOutStocksLastMonth,
                 },
                 new {
                     name = "搴撳瓨鎬婚噺",
@@ -558,6 +578,5 @@
             return content.Error("绯荤粺閿欒锛岃鑱旂郴绠$悊鍛�");
         }
     }
-
     #endregion
 }
\ No newline at end of file

--
Gitblit v1.9.3