huangxiaoqiang
2025-11-15 0204bc614e3132ce94d3fb1de9d330e9250f233c
ÏîÄ¿´úÂë/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
}