diff --git a/DOAN.Admin.WebApi/Controllers/MES/report/ReportController.cs b/DOAN.Admin.WebApi/Controllers/MES/report/ReportController.cs index 7f0620d..16391dc 100644 --- a/DOAN.Admin.WebApi/Controllers/MES/report/ReportController.cs +++ b/DOAN.Admin.WebApi/Controllers/MES/report/ReportController.cs @@ -54,5 +54,16 @@ namespace DOAN.WebApi.Controllers var response = _ReportService.DeviceDowntimeRate(DateTime.Today); return SUCCESS(response); } + + /// + /// 生产完成率 + /// + /// + [HttpGet("productionCompletionRate")] + public IActionResult ProductionCompletionRate() + { + var response = _ReportService.ProductionCompletionRate(DateTime.Today); + return SUCCESS(response); + } } } diff --git a/DOAN.Model/MES/report/MonthProuctModel.cs b/DOAN.Model/MES/report/MonthProuctModel.cs index e186796..eacb50a 100644 --- a/DOAN.Model/MES/report/MonthProuctModel.cs +++ b/DOAN.Model/MES/report/MonthProuctModel.cs @@ -90,4 +90,34 @@ namespace DOAN.Model.MES.report /// public double DowntimeRate { get; set; } } + + public class ProductionCompletionModel + { + public string WorkOrder { get; set; } + public int Count { get; set; } + public DateTime TimePeriod { get; set; } + } + + public class ProductionCompletionRate + { + public string WorkOrder { get; set; } + public string GroupName { get; set; } + public string Model { get; set; } + public string WorkTimePeriod { get; set; } + public int DeliveryNum { get; set; } + public int CompletionNum { get; set; } + public double CompletionRate { get; set; } + public string Status { get; set; } + public List List { get; set; } + + public DateTime? StartTime { get; set; } + public DateTime? EndTime { get; set; } + } + + public class PlanModel + { + public string StartTime { get; set; } + public int PlanNum { get; set; } + public int CompletionNum { get; set; } + } } diff --git a/DOAN.Service/MES/product/ProPlanAchievementrateVersion2Service.cs b/DOAN.Service/MES/product/ProPlanAchievementrateVersion2Service.cs index 5a0ba2f..ccbbbcb 100644 --- a/DOAN.Service/MES/product/ProPlanAchievementrateVersion2Service.cs +++ b/DOAN.Service/MES/product/ProPlanAchievementrateVersion2Service.cs @@ -576,8 +576,7 @@ namespace DOAN.Service.MES.product { (DateTime FirstDay, DateTime LastDay) Handlemonth = GetFirstAndLastDayOfMonth(parm.SearchYearMonth); var predicate = Expressionable.Create() - .And(it => it.RecordDate >= Handlemonth.FirstDay && it.RecordDate <= Handlemonth.LastDay) - ; + .And(it => it.RecordDate >= Handlemonth.FirstDay && it.RecordDate <= Handlemonth.LastDay); var response = Context.Queryable() .Where(predicate.ToExpression()) diff --git a/DOAN.Service/MES/report/IService/IReportService.cs b/DOAN.Service/MES/report/IService/IReportService.cs index 1005c35..a817195 100644 --- a/DOAN.Service/MES/report/IService/IReportService.cs +++ b/DOAN.Service/MES/report/IService/IReportService.cs @@ -16,5 +16,7 @@ namespace DOAN.Service.MES.report.IService { List DevicePoweronRate(DateTime dateTime); List DeviceDowntimeRate(DateTime dateTime); + + List ProductionCompletionRate(DateTime dateTime); } } diff --git a/DOAN.Service/MES/report/ReportService.cs b/DOAN.Service/MES/report/ReportService.cs index 53a11b4..c048cfc 100644 --- a/DOAN.Service/MES/report/ReportService.cs +++ b/DOAN.Service/MES/report/ReportService.cs @@ -1,34 +1,35 @@ -using System; -using SqlSugar; -using Infrastructure.Attribute; -using Infrastructure.Extensions; +using AlibabaCloud.SDK.Dingtalkdoc_1_0.Models; +using Aliyun.OSS; using DOAN.Model; using DOAN.Model.Dto; +using DOAN.Model.MES; +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 System.Linq; -using Microsoft.AspNetCore.Http; +using DOAN.Service.MES.report.IService; using Infrastructure; -using static System.Runtime.InteropServices.JavaScript.JSType; +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 NPOI.HSSF.Record; -using JinianNet.JNTemplate; -using DOAN.Model.MES; -using DOAN.Model.MES.report; -using DOAN.Service.MES.report.IService; -using DOAN.Model.MES.base_; -using DOAN.Model.MES.group; +using System.Linq; using System.Xml.Linq; -using Aliyun.OSS; -using AlibabaCloud.SDK.Dingtalkdoc_1_0.Models; -using DOAN.Model.MES.andon; +using static System.Runtime.InteropServices.JavaScript.JSType; namespace DOAN.Service.MES.report { @@ -153,5 +154,90 @@ namespace DOAN.Service.MES.report return result; } + + public List ProductionCompletionRate(DateTime dateTime) + { + //dateTime = new DateTime(2025, 11, 2); + List list = new List(); + + var dt = dateTime.ToString("yyyy-MM-dd"); + + 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.ToString("yyyy-MM-dd") == dt && b.ScheduleDate.Value.ToString("yyyy-MM-dd") == dt) + .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 = @dt + GROUP BY FLOOR( UNIX_TIMESTAMP( d.created_time ) / 600 ),r.workorder + ORDER BY TimePeriod"; + + var workDetailList = Context.Ado.SqlQuery(sql, new { dt = dt, }); + + list = woList.Select(t => new ProductionCompletionRate + { + WorkOrder = t.Workorder, + GroupName = t.GroupName, + WorkTimePeriod = $"{t.StartTime}-{t.EndTime}", + 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(); + var mod = new PlanModel + { + StartTime = $"{8 + i}:00", + PlanNum = t.DeliveryNum / 8, + CompletionNum = productionCompletionModel.Count, + }; + } + 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) + return "未开始"; + else if (status == 2) + return "开始"; + else if (status == 3) + return "完成"; + else if (status == 4) + return "暂停"; + else + return ""; + } } }