From 51922d7093b9c8f52417bfdd0fe9aa087d1fb5be Mon Sep 17 00:00:00 2001
From: xiazhengtongxue <133085197+xiazhengtongxue@users.noreply.github.com>
Date: 星期五, 01 五月 2026 18:31:01 +0800
Subject: [PATCH] feat: 优化仓库仪表盘界面并添加电池和空托盘统计功能
---
Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/Dashboard/DashboardController.cs | 205 +++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 167 insertions(+), 38 deletions(-)
diff --git a/Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/Dashboard/DashboardController.cs b/Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/Dashboard/DashboardController.cs
index f787d2a..cffe42d 100644
--- a/Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/Dashboard/DashboardController.cs
+++ b/Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/Dashboard/DashboardController.cs
@@ -2,6 +2,7 @@
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using WIDESEA_Common.LocationEnum;
+using WIDESEA_Common.StockEnum;
using WIDESEA_Core;
using WIDESEA_Model.Models;
@@ -71,10 +72,10 @@
}
/// <summary>
- /// 姣忔棩缁熻
+ /// 姣忔棩缁熻锛堟寜宸烽亾鍙峰垎缁勶紝鎸囧畾浠撳簱锛�
/// </summary>
[HttpGet("DailyStats"), AllowAnonymous]
- public async Task<WebResponseContent> DailyStats([FromQuery] int days = 30)
+ public async Task<WebResponseContent> DailyStats([FromQuery] int days = 10)
{
try
{
@@ -84,9 +85,16 @@
var startDate = DateTime.Today.AddDays(-days + 1);
var endDate = DateTime.Today; // 鍖呭惈浠婂ぉ
+ // 鎸囧畾瑕佺粺璁$殑浠撳簱锛堝贩閬撳彿锛�
+ var specifiedRoadways = new List<string>
+ {
+ "GWSC1", "CWSC1", "HCSC1", "ZJSC1", "FJSC1"
+ };
+
var query = await _db.Queryable<Dt_Task_Hty>()
.Where(t => t.InsertTime >= startDate && t.InsertTime <= endDate)
- .Select(t => new { t.InsertTime, t.TaskType })
+ .Where(t => specifiedRoadways.Contains(t.Roadway)) // 鍙煡璇㈡寚瀹氬贩閬撳彿鐨勬暟鎹�
+ .Select(t => new { t.InsertTime, t.TaskType, t.Roadway })
.ToListAsync();
// 鐢熸垚鏃ユ湡鑼冨洿
@@ -96,40 +104,57 @@
allDates.Add(date);
}
- // 鎸夋棩鏈熷垎缁勭粺璁�
+ // 鎸夊贩閬撳彿鍜屾棩鏈熷垎缁勭粺璁�
var groupedData = query
- .GroupBy(t => t.InsertTime.Date)
+ .GroupBy(t => new { t.Roadway, Date = t.InsertTime.Date })
.Select(g => new
{
- Date = g.Key,
+ Roadway = g.Key.Roadway,
+ Date = g.Key.Date,
Inbound = g.Count(t => t.TaskType >= 200 && t.TaskType < 300),
Outbound = g.Count(t => t.TaskType >= 100 && t.TaskType < 200)
})
- .ToDictionary(x => x.Date, x => x);
+ .ToList();
- // 琛ュ叏缂哄け鏃ユ湡
- var result = allDates.Select(date =>
+ // 鏋勫缓缁撴灉锛氭瘡涓寚瀹氫粨搴撳搴斾竴涓棩鏈熷垪琛�
+ var result = specifiedRoadways.Select(roadway =>
{
- if (groupedData.TryGetValue(date, out var data))
+ // 鑾峰彇璇ュ贩閬撳彿鐨勫垎缁勬暟鎹瓧鍏�
+ var roadwayData = groupedData
+ .Where(g => g.Roadway == roadway)
+ .ToDictionary(x => x.Date, x => x);
+
+ // 琛ュ叏缂哄け鏃ユ湡锛岀‘淇濇瘡澶╅兘鏈夋暟鎹紙榛樿涓�0锛�
+ var dailyStats = allDates.Select(date =>
{
- return new
+ if (roadwayData.TryGetValue(date, out var data))
{
- Date = date.ToString("MM-dd"),
- Inbound = data.Inbound,
- Outbound = data.Outbound
- };
- }
- else
+ return new
+ {
+ Date = date.ToString("MM-dd"),
+ Inbound = data.Inbound,
+ Outbound = data.Outbound
+ };
+ }
+ else
+ {
+ return new
+ {
+ Date = date.ToString("MM-dd"),
+ Inbound = 0,
+ Outbound = 0
+ };
+ }
+ })
+ .OrderBy(x => x.Date)
+ .ToList();
+
+ return new
{
- return new
- {
- Date = date.ToString("MM-dd"),
- Inbound = 0,
- Outbound = 0
- };
- }
+ Roadway = roadway,
+ DailyStats = dailyStats
+ };
})
- .OrderBy(x => x.Date)
.ToList();
return WebResponseContent.Instance.OK(null, result);
@@ -139,6 +164,7 @@
return WebResponseContent.Instance.Error($"姣忔棩缁熻鑾峰彇澶辫触: {ex.Message}");
}
}
+
/// <summary>
/// 姣忓懆缁熻
/// </summary>
@@ -189,14 +215,11 @@
return $"{monday.Year}-W{weekNum:D2}";
}
- /// <summary>
- /// 姣忔湀缁熻
- /// </summary>
/// <remarks>
/// 鎸夊勾鏈堢粺璁″叆绔欏拰鍑虹珯浠诲姟鏁伴噺
/// </remarks>
[HttpGet("MonthlyStats"), AllowAnonymous]
- public async Task<WebResponseContent> MonthlyStats([FromQuery] int months = 12)
+ public async Task<WebResponseContent> MonthlyStats(int months, string roadway)
{
try
{
@@ -205,8 +228,28 @@
var startDate = DateTime.Today.AddMonths(-months + 1);
startDate = new DateTime(startDate.Year, startDate.Month, 1);
- var monthlyStats = await _db.Queryable<Dt_Task_Hty>()
- .Where(t => t.InsertTime >= startDate)
+ // 浠撳簱鍚嶇О鏄犲皠
+ var roadwayNames = new Dictionary<string, string>
+ {
+
+ { "GWSC1", "楂樻俯1鍙蜂粨搴�" },
+ { "CWSC1", "甯告俯1鍙蜂粨搴�" },
+ { "HCSC1", "鍒嗗1鍙蜂粨搴�" },
+ { "FJSC1", "璐熸瀬鍗�1鍙蜂粨搴�" },
+ { "ZJSC1", "姝f瀬鍗�1鍙蜂粨搴�" },
+ };
+
+ // 鏋勫缓鏌ヨ
+ var query = _db.Queryable<Dt_Task_Hty>()
+ .Where(t => t.InsertTime >= startDate);
+
+ // 濡傛灉鎸囧畾浜嗛亾璺紝娣诲姞閬撹矾杩囨护鏉′欢
+ if (!string.IsNullOrEmpty(roadway))
+ {
+ query = query.Where(t => t.Roadway == roadway);
+ }
+
+ var monthlyStats = await query
.GroupBy(t => new { t.InsertTime.Year, t.InsertTime.Month })
.Select(t => new
{
@@ -252,7 +295,11 @@
{
Month = monthKey,
Inbound = stat.Inbound,
- Outbound = stat.Outbound
+ Outbound = stat.Outbound,
+ Roadway = roadway,
+ RoadwayName = !string.IsNullOrEmpty(roadway) && roadwayNames.ContainsKey(roadway)
+ ? roadwayNames[roadway]
+ : null
});
}
else
@@ -261,7 +308,11 @@
{
Month = monthKey,
Inbound = 0,
- Outbound = 0
+ Outbound = 0,
+ Roadway = roadway,
+ RoadwayName = !string.IsNullOrEmpty(roadway) && roadwayNames.ContainsKey(roadway)
+ ? roadwayNames[roadway]
+ : null
});
}
}
@@ -270,13 +321,9 @@
}
catch (Exception ex)
{
- // 璁板綍寮傚父鏃ュ織锛堝疄闄呴」鐩腑寤鸿浣跨敤鏃ュ織妗嗘灦锛�
- // _logger.LogError(ex, "姣忔湀缁熻鑾峰彇澶辫触");
-
return WebResponseContent.Instance.Error($"姣忔湀缁熻鑾峰彇澶辫触: {ex.Message}");
}
}
-
/// <summary>
/// 搴撳瓨搴撻緞鍒嗗竷
/// </summary>
@@ -369,5 +416,87 @@
return WebResponseContent.Instance.Error($"鍚勪粨搴撳簱瀛樺垎甯冭幏鍙栧け璐�: {ex.Message}");
}
}
+ /// <summary>
+ /// 鏌ヨ鍚勪粨搴撶數姹�/鏈夎揣鏁伴噺鍜岀┖鎵樼洏鏁伴噺
+ /// </summary>
+ /// <remarks>
+ /// 浠撳簱ID瑙勫垯锛�1=楂樻俯搴�, 2=甯告俯搴�, 3=鍖栨垚搴�, 6/7=鏋佸嵎搴�
+ /// <br/>
+ /// 缁熻瑙勫垯锛�
+ /// <br/>
+ /// - 楂樻俯/甯告俯/鍖栨垚搴擄細缁熻 鐢垫睜鏁伴噺(StockStatus=6) 鍜� 绌烘墭鐩樻暟閲�(StockStatus=22)
+ /// <br/>
+ /// - 鏋佸嵎搴�(6/7)锛氱粺璁� 鏈夎揣鏁伴噺(StockStatus鈮�22) 鍜� 绌烘墭鐩樻暟閲�(StockStatus=22)
+ /// <br/>
+ /// 閫氳繃杩斿洖鏁版嵁涓殑 StockStatus 鍜� Count 鍙互杩涗竴姝ユ煡璇㈡槑缁嗙數姹犮��
+ /// </remarks>
+ [HttpGet("StockAndTrayCount"), AllowAnonymous]
+ public async Task<WebResponseContent> StockAndTrayCount()
+ {
+ try
+ {
+ var warehouseIds = new[] { 1, 2, 3, 6, 7 };
+
+ var warehouseNames = new Dictionary<int, string>
+ {
+ { 1, "楂樻俯搴�" },
+ { 2, "甯告俯搴�" },
+ { 3, "鍖栨垚搴�" },
+ { 6, "鏋佸嵎搴�" },
+ { 7, "鏋佸嵎搴�" }
+ };
+
+ var result = new List<object>();
+
+ foreach (var warehouseId in warehouseIds)
+ {
+ var warehouseName = warehouseNames.GetValueOrDefault(warehouseId, $"浠撳簱{warehouseId}");
+
+ if (warehouseId == 6 || warehouseId == 7)
+ {
+ var totalCount = await _db.Queryable<Dt_StockInfo>()
+ .Where(s => s.WarehouseId == warehouseId)
+ .CountAsync();
+
+ var emptyTrayCount = await _db.Queryable<Dt_StockInfo>()
+ .Where(s => s.WarehouseId == warehouseId && s.StockStatus == (int)StockStatusEmun.绌烘墭鐩樺簱瀛�)
+ .CountAsync();
+
+ result.Add(new
+ {
+ WarehouseId = warehouseId,
+ WarehouseName = warehouseName,
+ HasGoodsCount = totalCount - emptyTrayCount,
+ EmptyTrayCount = emptyTrayCount,
+ });
+ }
+ else
+ {
+ var batteryCount = await _db.Queryable<Dt_StockInfo>()
+ .Where(s => s.WarehouseId == warehouseId && s.StockStatus == (int)StockStatusEmun.鍏ュ簱瀹屾垚)
+ .LeftJoin<Dt_StockInfoDetail>((s, d) => s.Id == d.StockId)
+ .CountAsync();
+
+ var emptyTrayCount = await _db.Queryable<Dt_StockInfo>()
+ .Where(s => s.WarehouseId == warehouseId && s.StockStatus == (int)StockStatusEmun.绌烘墭鐩樺簱瀛�)
+ .CountAsync();
+
+ result.Add(new
+ {
+ WarehouseId = warehouseId,
+ WarehouseName = warehouseName,
+ BatteryCount = batteryCount,
+ EmptyTrayCount = emptyTrayCount,
+ });
+ }
+ }
+
+ return WebResponseContent.Instance.OK(null, result);
+ }
+ catch (Exception ex)
+ {
+ return WebResponseContent.Instance.Error($"鐢垫睜鍜岀┖鎵樼洏鏁伴噺鏌ヨ澶辫触: {ex.Message}");
+ }
+ }
}
-}
+}
\ No newline at end of file
--
Gitblit v1.9.3