diff --git a/HHWMS.Web/Areas/Api/IDataController.cs b/HHWMS.Web/Areas/Api/IDataController.cs new file mode 100644 index 0000000..da93c7e --- /dev/null +++ b/HHWMS.Web/Areas/Api/IDataController.cs @@ -0,0 +1,248 @@ +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using AutoMapper; +using HHWMS.Web.Models; +using HHWMS.Web.Support; +using HHWMS.Web.Support.PLC; +using HslCommunication; +using HslCommunication.Profinet.Siemens; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using WalkingTec.Mvvm.Core; +using Microsoft.Extensions.Caching.Memory; +using HslCommunication.Core; +using WalkingTec.Mvvm.Core.Extensions; + +namespace HHWMS.Web +{ + /// + /// 提供给WCS调用接口 + /// 调用方向 WCS --> WMS + /// + [Public] + [ActionDescription("HHWMS.DataApi")] + [ApiController] + [Route("api/[controller]/[action]"), ApiExplorerSettings(GroupName = "User")] + public class IDataController : ApiController + { + private readonly IUnitWork _unitWork; + private readonly IMapper _mapper; + private readonly IMemoryCache _cache; + + public IDataController(IUnitWork unitWork, IMapper mapper, IMemoryCache cache) + { + _unitWork = unitWork; + _mapper = mapper; + _cache = cache; + } + + [HttpGet] + public IActionResult GetTaskHistoryChart() + { + var data = new List(); + // 获取一周内的日期 + var today = DateTime.Today; + var weekStart = today.AddDays(-6); + + // 查询一周内的出入库任务历史 + var taskHis = Wtm.DC.Set() + .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 ApiResult(rv); + } + + [HttpGet] + public IActionResult GetContainerChart() + { + var data = new List(); + + // 查询不同类型的容器数量 + var containers = Wtm.DC.Set() + .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 ApiResult(rv); + } + + [HttpGet] + public IActionResult GetCurrentTaskChart() + { + var data = new List(); + + // 查询当前任务状态 + var tasks = Wtm.DC.Set() + .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 ApiResult(rv); + } + + [HttpGet] + public IActionResult GetLocationChart() + { + var statusMap = new Dictionary // 如果是字符串类型,键改为string + { + { LocationStatus.有货, "有货" }, + { LocationStatus.空仓位, "空仓位" }, + { LocationStatus.空容器, "空容器" }, + { LocationStatus.任务锁, "任务锁" }, + // 补充其他状态的映射关系 + }; + + var data = new List(); + var locations = Wtm.DC.Set() + .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 = "库位状态" + }); + } + + var rv = data.ToChartData(); + return ApiResult(rv); + } + + [HttpGet] + public IActionResult GetLocationHeatmap() + { + var statusMap = new Dictionary + { + { LocationStatus.空仓位, ("空仓位", "#E1E1E1") }, + { LocationStatus.有货, ("有货", "#409EFF") }, + { LocationStatus.满货, ("满货", "#E6A23C") }, + { LocationStatus.任务锁, ("任务锁", "#F56C6C") }, + { LocationStatus.空容器, ("空容器", "#67C23A") }, + }; + + var locations = Wtm.DC.Set() + .Where(x => x.ZoneId != 1027) + .OrderBy(x => x.RoadWay) + .ThenBy(x => x.Row) + .ThenBy(x => x.Line) + .ThenBy(x => x.Layer) + .ToList(); + + var groups = locations.GroupBy(x => new { x.RoadWay, x.Row }); + var result = new List(); + + foreach (var group in groups) + { + var heatmap = new HeatmapDto + { + Title = $"第{group.Key.RoadWay}巷道第{group.Key.Row}排", + RoadWay = group.Key.RoadWay, + Row = group.Key.Row, + Points = new List(), + MaxLine = group.Max(x => x.Line), + MaxLayer = group.Max(x => x.Layer) + }; + + foreach (var loc in group) + { + statusMap.TryGetValue(loc.ContainerStatus, out var statusInfo); + heatmap.Points.Add(new HeatmapPointDto + { + Line = loc.Line, + Layer = loc.Layer, + Status = statusInfo.name ?? loc.ContainerStatus ?? "未知", + Color = statusInfo.color ?? "#909399", + ContainerCode = loc.ContainerCode, + LocationCode = loc.Code + }); + } + result.Add(heatmap); + } + + return ApiResult(result); + } + + } +} \ No newline at end of file diff --git a/HHWMS.Web/Areas/Receipt/Controllers/ReceiptInController.cs b/HHWMS.Web/Areas/Receipt/Controllers/ReceiptInController.cs index 07eab00..64bd657 100644 --- a/HHWMS.Web/Areas/Receipt/Controllers/ReceiptInController.cs +++ b/HHWMS.Web/Areas/Receipt/Controllers/ReceiptInController.cs @@ -235,6 +235,19 @@ namespace HHWMS.Web.Controllers processName = x.ProcessName }) .ToList(); + if (processes.Count == 0) + { + processes = _unitWork.Find(x => x.ID > 0) + .OrderBy(x => x.Code) + .Select(x => new + { + value = x.ID.ToString(), + label = x.Name, + processCode = x.Code, + processName = x.Name + }) + .ToList(); + } return Json(new { Code = 200, Data = processes }); } catch (Exception ex) @@ -266,7 +279,7 @@ namespace HHWMS.Web.Controllers var orders = result.Data.Select(x => new { value = x.MoDetailId, - label = x.MoCode, + label = string.IsNullOrEmpty(x.MoCode) ? x.MoDetailId : x.MoCode, }) .ToList(); diff --git a/HHWMS.Web/Controllers/HomeController.cs b/HHWMS.Web/Controllers/HomeController.cs index 8193b83..9084c9c 100644 --- a/HHWMS.Web/Controllers/HomeController.cs +++ b/HHWMS.Web/Controllers/HomeController.cs @@ -44,6 +44,13 @@ namespace HHWMS.Web.Controllers return PartialView(); } + + [AllowAnonymous] + [ActionDescription("DataPage")] + public IActionResult DataPage() + { + return PartialView(); + } [AllowAnonymous] public IActionResult GetActionChart() diff --git a/HHWMS.Web/Models/HeatmapDto.cs b/HHWMS.Web/Models/HeatmapDto.cs new file mode 100644 index 0000000..b76155d --- /dev/null +++ b/HHWMS.Web/Models/HeatmapDto.cs @@ -0,0 +1,24 @@ +using System.Collections.Generic; + +namespace HHWMS.Web.Models +{ + public class HeatmapDto + { + public string Title { get; set; } + public int RoadWay { get; set; } + public int Row { get; set; } + public List Points { get; set; } + public int MaxLine { get; set; } + public int MaxLayer { get; set; } + } + + public class HeatmapPointDto + { + public int Line { get; set; } + public int Layer { get; set; } + public string Status { get; set; } + public string Color { get; set; } + public string ContainerCode { get; set; } + public string LocationCode { get; set; } + } +} diff --git a/HHWMS.Web/Properties/launchSettings.json b/HHWMS.Web/Properties/launchSettings.json index 3682a7e..5b54f76 100644 --- a/HHWMS.Web/Properties/launchSettings.json +++ b/HHWMS.Web/Properties/launchSettings.json @@ -23,7 +23,7 @@ "ASPNETCORE_ENVIRONMENT": "Development", "ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" }, - "applicationUrl": "http://localhost:5000/" + "applicationUrl": "http://0.0.0.0:5000/" } } } diff --git a/HHWMS.Web/Views/Home/DataPage.cshtml b/HHWMS.Web/Views/Home/DataPage.cshtml new file mode 100644 index 0000000..e9d8bfb --- /dev/null +++ b/HHWMS.Web/Views/Home/DataPage.cshtml @@ -0,0 +1,347 @@ +@model WalkingTec.Mvvm.Core.BaseVM +@using System.Text.Json + +
+
+ +
+ + + +
+ + + + + +
+
+
+ + + + +
+
+
+ + + + +
+
+
+ + + + +
+
+
+ 空仓位 +
+
+
+ 有货 +
+
+
+ 满货 +
+
+
+ 任务锁 +
+
+
+ 空容器 +
+
+ + +
+
+
+
+
+
+
+
+ + + + + + + + + + + + + + + + + + +