feat(仪表盘): 添加任务历史、库位状态和当前任务统计图表

refactor(库存交易): 使用AutoMapper简化库存交易记录创建逻辑
This commit is contained in:
zhougf committed 2025-10-01 03:22:33 +08:00
1 parent d89f6ffb3e
commit 3cba19da98
5 files changed
+563 -203

No files matched your search

+138 -4
View File
@@ -131,17 +131,30 @@ namespace HHWMS.Web.Controllers
[AllowAnonymous]
public IActionResult GetLocationChart()
{
var statusMap = new Dictionary<string, string> // 如果是字符串类型,键改为string
{
{ LocationStatus.有货, "有货" },
{ LocationStatus.空仓位, "空仓位" },
{ LocationStatus.空容器, "空容器" },
{ LocationStatus.任务锁, "任务锁" },
// 补充其他状态的映射关系
};
var data = new List<ChartData>();
var locations = Wtm.DC.Set<Location>().AsEnumerable()
.GroupBy(x => x.Status).ToList()
.Select(x => new { status = x.Key, count = x.Count() });
var locations = Wtm.DC.Set<Location>()
.DPWhere(Wtm,x => x.ZoneId)
.AsEnumerable()
.GroupBy(x => x.ContainerStatus).ToList()
.Select(x => new { status = statusMap.TryGetValue(x.Key, out var chineseName)
? chineseName
: x.Key.ToString(), count = x.Count() });
foreach (var item in locations)
{
data.Add(new ChartData
{
Value = item.count,
Category = item.status.ToString(),
Series = "locations"
Series = "库位状态"
});
}
@@ -189,6 +202,127 @@ namespace HHWMS.Web.Controllers
{
return JsonMore(UserSessionManager.AllSignined().ToList());
}
[AllowAnonymous]
public IActionResult GetTaskHistoryChart()
{
var data = new List<ChartData>();
// 获取一周内的日期
var today = DateTime.Today;
var weekStart = today.AddDays(-6);
// 查询一周内的出入库任务历史
var taskHis = Wtm.DC.Set<TaskHeaderHistory>()
.DPWhere(Wtm,x => x.ZoneId)
.Where(x => x.CreateTime >= weekStart && x.CreateTime <= today.AddDays(1))
.Select(x => new
{
TaskType = x.TaskType,
Date = x.CreateTime.ToString(),
})
.ToList();
var taskHistory = taskHis
.GroupBy(x => new { Date = x.Date.Substring(0,10), Type = x.TaskType })
.Select(g => new { Date = g.Key.Date, Type = g.Key.Type, Count = g.Count() })
.ToList();
// 生成每天的数据
for (var date = weekStart; date <= today; date = date.AddDays(1))
{
// 入库任务
var inCount = taskHistory
.Where(x => x.Date == date.ToString("yyyy-MM-dd") && x.Type == TaskTypeEnum.入库)
.Sum(x => x.Count);
data.Add(new ChartData
{
Category = date.ToString("MM-dd"),
Value = inCount,
Series = "入库任务"
});
// 出库任务
var outCount = taskHistory
.Where(x => x.Date == date.ToString("yyyy-MM-dd") && x.Type == TaskTypeEnum.出库)
.Sum(x => x.Count);
data.Add(new ChartData
{
Category = date.ToString("MM-dd"),
Value = outCount,
Series = "出库任务"
});
// 移库任务
var moveCount = taskHistory
.Where(x => x.Date == date.ToString("yyyy-MM-dd") && x.Type == TaskTypeEnum.移库)
.Sum(x => x.Count);
data.Add(new ChartData
{
Category = date.ToString("MM-dd"),
Value = moveCount,
Series = "移库任务"
});
}
var rv = data.ToChartData();
return Json(rv);
}
[AllowAnonymous]
public IActionResult GetContainerChart()
{
var data = new List<ChartData>();
// 查询不同类型的容器数量
var containers = Wtm.DC.Set<Container>()
.DPWhere(Wtm,x => x.ZoneId)
.AsEnumerable()
.GroupBy(x => x.Type)
.Select(g => new { Type = g.Key, Count = g.Count() })
.ToList();
foreach (var container in containers)
{
data.Add(new ChartData
{
Category = container.Type,
Value = container.Count,
Series = "容器类型"
});
}
var rv = data.ToChartData();
return Json(rv);
}
[AllowAnonymous]
public IActionResult GetCurrentTaskChart()
{
var data = new List<ChartData>();
// 查询当前任务状态
var tasks = Wtm.DC.Set<TaskHeader>()
.DPWhere(Wtm,x => x.ZoneId)
.AsEnumerable()
.GroupBy(x => x.TaskType)
.Select(g => new { Type = g.Key, Count = g.Count() })
.ToList();
foreach (var task in tasks)
{
data.Add(new ChartData
{
Category = task.Type.ToString(),
Value = task.Count,
Series = "当前任务"
});
}
var rv = data.ToChartData();
return Json(rv);
}
}
}