From 6f4d0efdff42599d4d128344b9ad7135cb67bc09 Mon Sep 17 00:00:00 2001 From: chenlin Date: Thu, 22 Jan 2026 14:30:44 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E5=81=9C=E6=9C=BA=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MES/report/ReportController.cs | 19 ++++++-- DOAN.Model/MES/report/MonthProuctModel.cs | 24 ++++++++++ .../MES/report/IService/IReportService.cs | 1 + DOAN.Service/MES/report/ReportService.cs | 48 +++++++++++++++++++ 4 files changed, 89 insertions(+), 3 deletions(-) diff --git a/DOAN.Admin.WebApi/Controllers/MES/report/ReportController.cs b/DOAN.Admin.WebApi/Controllers/MES/report/ReportController.cs index b9955ca..7f0620d 100644 --- a/DOAN.Admin.WebApi/Controllers/MES/report/ReportController.cs +++ b/DOAN.Admin.WebApi/Controllers/MES/report/ReportController.cs @@ -8,7 +8,7 @@ using Microsoft.AspNetCore.Mvc; namespace DOAN.WebApi.Controllers { - [Verify] + //[Verify] [Route("mes/reportManagement/report")] [ApiExplorerSettings(GroupName = "MES")] public class ReportController : BaseController @@ -27,19 +27,32 @@ namespace DOAN.WebApi.Controllers /// /// [HttpGet("listMonth")] - //[ActionPermissionFilter(Permission = "productManagement:proplanachievementrate:list")] public IActionResult QueryMonthProuct([FromQuery] MonthProuctDto parm) { var response = _ProPlanAchievementrateVersion2Service.GetQueryMonthProucth(parm); return SUCCESS(response); } + /// + /// 设备开机率 + /// + /// [HttpGet("devicePoweronRate")] - //[ActionPermissionFilter(Permission = "productManagement:proplanachievementrate:list")] public IActionResult DevicePoweronRate() { var response = _ReportService.DevicePoweronRate(DateTime.Today); return SUCCESS(response); } + + /// + /// 设备停机率 + /// + /// + [HttpGet("deviceDowntimeRate")] + public IActionResult DeviceDowntimeRate() + { + var response = _ReportService.DeviceDowntimeRate(DateTime.Today); + return SUCCESS(response); + } } } diff --git a/DOAN.Model/MES/report/MonthProuctModel.cs b/DOAN.Model/MES/report/MonthProuctModel.cs index bc6680e..e186796 100644 --- a/DOAN.Model/MES/report/MonthProuctModel.cs +++ b/DOAN.Model/MES/report/MonthProuctModel.cs @@ -66,4 +66,28 @@ namespace DOAN.Model.MES.report /// public double PoweronRate { get; set; } } + + public class DeviceDowntimeRateModel + { + /// + /// 产线编码 + /// + public string LineCode { get; set; } + /// + /// 产线名称 + /// + public string LineName { get; set; } + /// + /// 运行时长 + /// + public double PlanHours { get; set; } + /// + /// 停机时长 + /// + public double DowntimeHours { get; set; } + /// + /// 停机率 + /// + public double DowntimeRate { get; set; } + } } diff --git a/DOAN.Service/MES/report/IService/IReportService.cs b/DOAN.Service/MES/report/IService/IReportService.cs index 896cbe4..1005c35 100644 --- a/DOAN.Service/MES/report/IService/IReportService.cs +++ b/DOAN.Service/MES/report/IService/IReportService.cs @@ -15,5 +15,6 @@ namespace DOAN.Service.MES.report.IService public interface IReportService : IBaseService { List DevicePoweronRate(DateTime dateTime); + List DeviceDowntimeRate(DateTime dateTime); } } diff --git a/DOAN.Service/MES/report/ReportService.cs b/DOAN.Service/MES/report/ReportService.cs index 117df6e..53a11b4 100644 --- a/DOAN.Service/MES/report/ReportService.cs +++ b/DOAN.Service/MES/report/ReportService.cs @@ -28,6 +28,7 @@ using DOAN.Model.MES.group; using System.Xml.Linq; using Aliyun.OSS; using AlibabaCloud.SDK.Dingtalkdoc_1_0.Models; +using DOAN.Model.MES.andon; namespace DOAN.Service.MES.report { @@ -105,5 +106,52 @@ namespace DOAN.Service.MES.report return list; } + + public List DeviceDowntimeRate(DateTime dateTime) + { + List list = new List(); + var dt = dateTime.ToString("yyyy-MM-dd"); + + list = Context.Queryable() + .InnerJoin((a, b) => a.LineCode == b.Code) + .Where((a, b) => a.WorkorderDate.Value.ToString("yyyy-MM-dd") == dt) + .Select((a, b) => + new DeviceDowntimeRateModel + { + LineCode = b.Code, + LineName = b.Name, + PlanHours = SqlFunc.Round((a.Beat * a.DeliveryNum ?? 0) / 3600.0,2) + }).ToList(); + + var response = Context.Queryable() + .Where(t=>t.FaultDict== "设备异常" && t.StartTime.HasValue && t.EndTime.HasValue && t.EndTime.Value.ToString("yyyy-MM-dd") ==dt) + .Select(it => new + { + it.LineCode, + it.StartTime, + it.EndTime, + DowntimeHours = (it.EndTime.Value - it.StartTime.Value).TotalHours, + }).ToList(); + + var groupList = response.GroupBy(it => it.LineCode).Select(it => new + { + LineCode = it.Key, + DowntimeHours = it.ToList().Sum(t=>t.DowntimeHours) + }).ToList(); + + var result = list.GroupJoin(groupList, + l => l.LineCode, + g => g.LineCode, + (l, gList) => new DeviceDowntimeRateModel + { + LineCode = l.LineCode, + LineName = l.LineName, + PlanHours = l.PlanHours, + DowntimeHours = gList.FirstOrDefault()?.DowntimeHours ?? l.PlanHours, // 如果没有停机时间则为计划时间 + DowntimeRate= Math.Round((gList.FirstOrDefault()?.DowntimeHours ?? l.PlanHours) / l.PlanHours, 2) + }).ToList(); + + return result; + } } }