From e547bc89adb71f1ead3da0a3f4593a310950e298 Mon Sep 17 00:00:00 2001 From: "qianhao.xu" Date: Mon, 16 Jun 2025 10:21:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=AF=8F=E6=9C=88=E5=81=9C=E6=9C=BA=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E6=9F=B1=E7=8A=B6=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MES/dev/DeviceDowntimeRecordController.cs | 27 ++++++++++ .../MES/dev/DeviceDowntimeRecordService.cs | 54 +++++++++++++++++++ .../IService/IDeviceDowntimeRecordService.cs | 3 ++ 3 files changed, 84 insertions(+) diff --git a/DOAN.Admin.WebApi/Controllers/MES/dev/DeviceDowntimeRecordController.cs b/DOAN.Admin.WebApi/Controllers/MES/dev/DeviceDowntimeRecordController.cs index 72dda92..237ad00 100644 --- a/DOAN.Admin.WebApi/Controllers/MES/dev/DeviceDowntimeRecordController.cs +++ b/DOAN.Admin.WebApi/Controllers/MES/dev/DeviceDowntimeRecordController.cs @@ -6,6 +6,7 @@ using DOAN.Admin.WebApi.Filters; using DOAN.Model.MES.dev; using Infrastructure.Converter; +using DOAN.Model.mes.echarts; namespace DOAN.Admin.WebApi.Controllers { @@ -114,6 +115,32 @@ namespace DOAN.Admin.WebApi.Controllers } + #region 设备停机时间BI + + + //TODO 每月停机时间柱状图 + + /// + /// 每月停机时间柱状图 + /// + /// + public IActionResult GetDeviceDowntimeRecordMonthBarChart() + { + + EchartsOptions response = _DeviceDowntimeRecordService.GetDeviceDowntimeRecordMonthBarChart(); + //TODO 每月停机时间柱状图 + return ToResponse(new ApiResult((int)ResultCode.SUCCESS, "每月停机时间柱状图")); + } + + + //TODO 停机原因TOP3 + + + + + #endregion + + } diff --git a/DOAN.Service/MES/dev/DeviceDowntimeRecordService.cs b/DOAN.Service/MES/dev/DeviceDowntimeRecordService.cs index 1bef797..e2c8c95 100644 --- a/DOAN.Service/MES/dev/DeviceDowntimeRecordService.cs +++ b/DOAN.Service/MES/dev/DeviceDowntimeRecordService.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using DOAN.Model; +using DOAN.Model.mes.echarts; using DOAN.Model.MES.dev; using DOAN.Model.MES.dev.Dto; using DOAN.Model.System; @@ -126,5 +127,58 @@ namespace DOAN.Service.MES.dev //return response; return Update(model, true); } + + + + public EchartsOptions GetDeviceDowntimeRecordMonthBarChart() + { + var result = Context.Queryable() + .Where(x => x.Downdate != null && x.ConsumeTime != null) + .GroupBy(x => new + { + Year = x.Downdate.Value.Year, + Month = x.Downdate.Value.Month + }) + .Select(x => new + { + Year = x.Downdate.Value.Year, + Month = x.Downdate.Value.Month, + TotalDowntime = SqlFunc.AggregateSum(x.ConsumeTime.Value) + }) + .OrderByDescending(x => x.Year) + .OrderByDescending(x => x.Month) + .Take(24) + .MergeTable() + .OrderBy(x => x.Year) + .OrderBy(x => x.Month) + .Select(x => new EchartsSeriesData + { + Name = $"{x.Year}-{x.Month.ToString().PadLeft(2, '0')}", + Value= x.TotalDowntime + }) + .ToList(); + + + var echartsOptions = new EchartsOptions + { + Title = new EchartsTitle("设备停机时间统计", "按月统计停机时间"), + XAxis = new EchartsXAxis + { + Type = "category", + Data = result.Select(x=>x.Name).ToList(), + }, + YAxis = new EchartsYAxis { Type = "value" }, + Series = new List + { + new EchartsSeries + { + Name = "停机时间", + Type = "bar", + Data = result + } + } + }; + return echartsOptions; + } } } diff --git a/DOAN.Service/MES/dev/IService/IDeviceDowntimeRecordService.cs b/DOAN.Service/MES/dev/IService/IDeviceDowntimeRecordService.cs index 2edb03e..c1975fb 100644 --- a/DOAN.Service/MES/dev/IService/IDeviceDowntimeRecordService.cs +++ b/DOAN.Service/MES/dev/IService/IDeviceDowntimeRecordService.cs @@ -3,6 +3,7 @@ using DOAN.Model.MES.dev; using DOAN.Model.MES.dev.Dto; using System.Collections.Generic; using DOAN.Model; +using DOAN.Model.mes.echarts; namespace DOAN.Service.MES.dev.IService { @@ -21,5 +22,7 @@ namespace DOAN.Service.MES.dev.IService int UpdateDeviceDowntimeRecord(DeviceDowntimeRecord parm); + EchartsOptions GetDeviceDowntimeRecordMonthBarChart(); + } }