From b4da1aed298e15d4bdd56fe6042e2f53beaf9bce Mon Sep 17 00:00:00 2001 From: "qianhao.xu" Date: Mon, 16 Jun 2025 10:38:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=81=9C=E6=9C=BA=E5=8E=9F=E5=9B=A0TOP3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MES/dev/DeviceDowntimeRecordController.cs | 11 ++--- .../MES/dev/DeviceDowntimeRecordService.cs | 42 +++++++++++++++++++ .../IService/IDeviceDowntimeRecordService.cs | 2 + 3 files changed, 50 insertions(+), 5 deletions(-) diff --git a/DOAN.Admin.WebApi/Controllers/MES/dev/DeviceDowntimeRecordController.cs b/DOAN.Admin.WebApi/Controllers/MES/dev/DeviceDowntimeRecordController.cs index 657030f..4ca135e 100644 --- a/DOAN.Admin.WebApi/Controllers/MES/dev/DeviceDowntimeRecordController.cs +++ b/DOAN.Admin.WebApi/Controllers/MES/dev/DeviceDowntimeRecordController.cs @@ -134,11 +134,12 @@ namespace DOAN.Admin.WebApi.Controllers //TODO 停机原因TOP3 - //public IActionResult actionResult GetDeviceDowntimeRecordReasonTop3() - //{ - // //TODO 停机原因TOP3 - // return ToResponse(new ApiResult((int)ResultCode.SUCCESS, "停机原因TOP3")); - //} + public IActionResult GetDeviceDowntimeRecordReasonTop3() + { + + EchartsOptions response = _DeviceDowntimeRecordService.GetDeviceDowntimeRecordReasonTop3(10); + return SUCCESS(response); + } diff --git a/DOAN.Service/MES/dev/DeviceDowntimeRecordService.cs b/DOAN.Service/MES/dev/DeviceDowntimeRecordService.cs index e2c8c95..370c90f 100644 --- a/DOAN.Service/MES/dev/DeviceDowntimeRecordService.cs +++ b/DOAN.Service/MES/dev/DeviceDowntimeRecordService.cs @@ -180,5 +180,47 @@ namespace DOAN.Service.MES.dev }; return echartsOptions; } + + + public EchartsOptions GetDeviceDowntimeRecordReasonTop3(int top) + { + var result= Context.Queryable() + .Where(x => x.FaultReason != null) + .GroupBy(x => x.FaultReason) + .Select(x => new + { + FaultReason = x.FaultReason, + TotalDowntime = SqlFunc.AggregateSum(x.ConsumeTime.Value) + }) + .OrderByDescending(x => x.TotalDowntime) + .Take(top) + .MergeTable() + .Select(x => new EchartsSeriesData + { + Name = x.FaultReason, + Value = x.TotalDowntime + }) + .ToList(); + var echartsOptions = new EchartsOptions + { + Title = new EchartsTitle("设备停机时间统计", "按月统计停机时间"), + YAxis = new EchartsYAxis + { + Type = "category", + Data = result.Select(x => x.Name).ToList(), + }, + + 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 c1975fb..34cacf2 100644 --- a/DOAN.Service/MES/dev/IService/IDeviceDowntimeRecordService.cs +++ b/DOAN.Service/MES/dev/IService/IDeviceDowntimeRecordService.cs @@ -24,5 +24,7 @@ namespace DOAN.Service.MES.dev.IService EchartsOptions GetDeviceDowntimeRecordMonthBarChart(); + EchartsOptions GetDeviceDowntimeRecordReasonTop3(int top); + } }