From 6a3725f6251b3723e5f57acd91f6e514964bc54a Mon Sep 17 00:00:00 2001 From: chenlin Date: Sat, 24 Jan 2026 09:19:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=88=E7=94=9F=E4=BA=A7=E5=AE=8C=E6=88=90?= =?UTF-8?q?=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MES/report/ReportController.cs | 13 ++- .../MES/report/IService/IReportService.cs | 2 + DOAN.Service/MES/report/ReportService.cs | 104 ++++++++++++++---- 3 files changed, 94 insertions(+), 25 deletions(-) diff --git a/DOAN.Admin.WebApi/Controllers/MES/report/ReportController.cs b/DOAN.Admin.WebApi/Controllers/MES/report/ReportController.cs index 16391dc..640c727 100644 --- a/DOAN.Admin.WebApi/Controllers/MES/report/ReportController.cs +++ b/DOAN.Admin.WebApi/Controllers/MES/report/ReportController.cs @@ -56,7 +56,7 @@ namespace DOAN.WebApi.Controllers } /// - /// 生产完成率 + /// 日生产完成率 /// /// [HttpGet("productionCompletionRate")] @@ -65,5 +65,16 @@ namespace DOAN.WebApi.Controllers var response = _ReportService.ProductionCompletionRate(DateTime.Today); return SUCCESS(response); } + + /// + /// 月生产完成率 + /// + /// + [HttpGet("monthlyProductionCompletionRate")] + public IActionResult MonthlyProductionCompletionRate() + { + var response = _ReportService.MonthlyProductionCompletionRate(DateTime.Today); + return SUCCESS(response); + } } } diff --git a/DOAN.Service/MES/report/IService/IReportService.cs b/DOAN.Service/MES/report/IService/IReportService.cs index a817195..851bf69 100644 --- a/DOAN.Service/MES/report/IService/IReportService.cs +++ b/DOAN.Service/MES/report/IService/IReportService.cs @@ -18,5 +18,7 @@ namespace DOAN.Service.MES.report.IService List DeviceDowntimeRate(DateTime dateTime); List ProductionCompletionRate(DateTime dateTime); + + List MonthlyProductionCompletionRate(DateTime dateTime); } } diff --git a/DOAN.Service/MES/report/ReportService.cs b/DOAN.Service/MES/report/ReportService.cs index c5305cf..63ec1fb 100644 --- a/DOAN.Service/MES/report/ReportService.cs +++ b/DOAN.Service/MES/report/ReportService.cs @@ -1,35 +1,12 @@ -using AlibabaCloud.SDK.Dingtalkdoc_1_0.Models; -using Aliyun.OSS; -using DOAN.Model; -using DOAN.Model.Dto; -using DOAN.Model.MES; +using Aliyun.OSS; using DOAN.Model.MES.andon; using DOAN.Model.MES.base_; using DOAN.Model.MES.group; using DOAN.Model.MES.product; -using DOAN.Model.MES.product.Dto; using DOAN.Model.MES.report; -using DOAN.Repository; -using DOAN.Service.MES.product.IService; using DOAN.Service.MES.report.IService; -using Infrastructure; using Infrastructure.Attribute; -using Infrastructure.Extensions; -using JinianNet.JNTemplate; -using Mapster; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; -using NPOI.HSSF.Record; -using NPOI.SS.Formula.Functions; -using NPOI.SS.UserModel; -using NPOI.XSSF.UserModel; -using SqlSugar; -using System; using System.Data; -using System.Globalization; -using System.Linq; -using System.Xml.Linq; -using static System.Runtime.InteropServices.JavaScript.JSType; namespace DOAN.Service.MES.report { @@ -224,6 +201,75 @@ namespace DOAN.Service.MES.report return list; } + public List MonthlyProductionCompletionRate(DateTime dateTime) + { + (DateTime FirstDay, DateTime LastDay) Handlemonth = GetFirstAndLastDayOfMonth(dateTime); + List list = new List(); + + var woList = Context.Queryable() + .LeftJoin((a, b) => a.GroupCode == b.GroupCode) + .LeftJoin((a, b, c) => b.FkShift == c.Id) + .LeftJoin((a, b, c, d) => a.GroupCode == d.GroupCode) + .Where((a, b, c, d) => a.WorkorderDate.Value>= Handlemonth.FirstDay && a.WorkorderDate.Value<= Handlemonth.LastDay + && b.ScheduleDate.Value>= Handlemonth.FirstDay && b.ScheduleDate.Value<= Handlemonth.LastDay) + .Select((a, b, c, d) => + new + { + a.Workorder, + a.GroupCode, + a.DeliveryNum, + a.LineCode, + a.Status, + c.StartTime, + c.EndTime, + d.GroupName + }).ToList(); + + string year = dateTime.Year.ToString("D4"); + string month = dateTime.Month.ToString("D2"); + string day = "01"; + + string sql = $@"SELECT FROM_UNIXTIME( FLOOR( UNIX_TIMESTAMP( d.created_time ) / 3600 ) * 3600 ) AS TimePeriod, + r.workorder as WorkOrder, COUNT(*) AS Count + FROM pro_workorder AS r + RIGHT JOIN pro_reportwork_detail_{year}{month}{day} AS d ON r.workorder = d.workorder + WHERE r.workorder_date >= @firstDay and r.workorder_date<=@lastDay + GROUP BY FLOOR( UNIX_TIMESTAMP( d.created_time ) / 600 ),r.workorder + ORDER BY TimePeriod"; + + var workDetailList = Context.Ado.SqlQuery(sql, new { firstDay = Handlemonth.FirstDay, lastDay= Handlemonth.LastDay }); + + list = woList.Select(t => new ProductionCompletionRate + { + WorkOrder = t.Workorder, + GroupName = t.GroupName, + WorkTimePeriod = $"{t.StartTime?.ToString("HH:mm")}-{t.EndTime?.ToString("HH:mm")}", + DeliveryNum = t.DeliveryNum ?? 0, + Status = GetStatusName(t.Status ?? 0), + StartTime = t.StartTime, + EndTime = t.EndTime + }).ToList(); + + list.ForEach(t => + { + var productionCompletionList = workDetailList.Where(wd => wd.WorkOrder == t.WorkOrder).ToList(); + var hours = (t.EndTime - t.StartTime).Value.TotalHours; + for (int i = 0; i < hours; i++) + { + var productionCompletionModel = productionCompletionList.Where(t => t.TimePeriod.Hour == (8 + i)).FirstOrDefault(); + t.List.Add(new PlanModel + { + StartTime = $"{8 + i}:00", + PlanNum = t.DeliveryNum / 8, + CompletionNum = productionCompletionModel?.Count ?? 0, + }); + } + t.CompletionNum = productionCompletionList.Sum(t => t.Count); + t.CompletionRate = Math.Round(t.CompletionNum * 100.0 / t.DeliveryNum, 2); + }); + + return list; + } private string GetStatusName(int status) { if (status == 1) @@ -237,5 +283,15 @@ namespace DOAN.Service.MES.report else return ""; } + + private (DateTime FirstDay, DateTime LastDay) GetFirstAndLastDayOfMonth(DateTime date) + { + DateTime firstDay = new DateTime(date.Year, date.Month, 1); + int lastDay = DateTime.DaysInMonth(date.Year, date.Month); + DateTime lastDayDate = new DateTime(date.Year, date.Month, lastDay); + + return (firstDay, lastDayDate); + } + } }