生产完成率

This commit is contained in:
杨晓东 2026-01-23 13:31:28 +08:00
parent 470d3a7710
commit 7b81765c29
5 changed files with 147 additions and 19 deletions

View File

@ -54,5 +54,16 @@ namespace DOAN.WebApi.Controllers
var response = _ReportService.DeviceDowntimeRate(DateTime.Today);
return SUCCESS(response);
}
/// <summary>
/// 生产完成率
/// </summary>
/// <returns></returns>
[HttpGet("productionCompletionRate")]
public IActionResult ProductionCompletionRate()
{
var response = _ReportService.ProductionCompletionRate(DateTime.Today);
return SUCCESS(response);
}
}
}

View File

@ -90,4 +90,34 @@ namespace DOAN.Model.MES.report
/// </summary>
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<PlanModel> 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; }
}
}

View File

@ -576,8 +576,7 @@ namespace DOAN.Service.MES.product
{
(DateTime FirstDay, DateTime LastDay) Handlemonth = GetFirstAndLastDayOfMonth(parm.SearchYearMonth);
var predicate = Expressionable.Create<ProPlanAchievementrateVersion2>()
.And(it => it.RecordDate >= Handlemonth.FirstDay && it.RecordDate <= Handlemonth.LastDay)
;
.And(it => it.RecordDate >= Handlemonth.FirstDay && it.RecordDate <= Handlemonth.LastDay);
var response = Context.Queryable<ProPlanAchievementrateVersion2>()
.Where(predicate.ToExpression())

View File

@ -16,5 +16,7 @@ namespace DOAN.Service.MES.report.IService
{
List<DevicePoweronRateModel> DevicePoweronRate(DateTime dateTime);
List<DeviceDowntimeRateModel> DeviceDowntimeRate(DateTime dateTime);
List<ProductionCompletionRate> ProductionCompletionRate(DateTime dateTime);
}
}

View File

@ -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> ProductionCompletionRate(DateTime dateTime)
{
//dateTime = new DateTime(2025, 11, 2);
List<ProductionCompletionRate> list = new List<ProductionCompletionRate>();
var dt = dateTime.ToString("yyyy-MM-dd");
var woList = Context.Queryable<ProWorkorder>()
.LeftJoin<GroupSchedule>((a, b) => a.GroupCode == b.GroupCode)
.LeftJoin<GroupShift>((a, b, c) => b.FkShift == c.Id)
.LeftJoin<BaseGroup>((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<ProductionCompletionModel>(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 "";
}
}
}