月生产完成率
This commit is contained in:
parent
146747a1ed
commit
6a3725f625
@ -56,7 +56,7 @@ namespace DOAN.WebApi.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 生产完成率
|
/// 日生产完成率
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet("productionCompletionRate")]
|
[HttpGet("productionCompletionRate")]
|
||||||
@ -65,5 +65,16 @@ namespace DOAN.WebApi.Controllers
|
|||||||
var response = _ReportService.ProductionCompletionRate(DateTime.Today);
|
var response = _ReportService.ProductionCompletionRate(DateTime.Today);
|
||||||
return SUCCESS(response);
|
return SUCCESS(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 月生产完成率
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet("monthlyProductionCompletionRate")]
|
||||||
|
public IActionResult MonthlyProductionCompletionRate()
|
||||||
|
{
|
||||||
|
var response = _ReportService.MonthlyProductionCompletionRate(DateTime.Today);
|
||||||
|
return SUCCESS(response);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,5 +18,7 @@ namespace DOAN.Service.MES.report.IService
|
|||||||
List<DeviceDowntimeRateModel> DeviceDowntimeRate(DateTime dateTime);
|
List<DeviceDowntimeRateModel> DeviceDowntimeRate(DateTime dateTime);
|
||||||
|
|
||||||
List<ProductionCompletionRate> ProductionCompletionRate(DateTime dateTime);
|
List<ProductionCompletionRate> ProductionCompletionRate(DateTime dateTime);
|
||||||
|
|
||||||
|
List<ProductionCompletionRate> MonthlyProductionCompletionRate(DateTime dateTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,35 +1,12 @@
|
|||||||
using AlibabaCloud.SDK.Dingtalkdoc_1_0.Models;
|
using Aliyun.OSS;
|
||||||
using Aliyun.OSS;
|
|
||||||
using DOAN.Model;
|
|
||||||
using DOAN.Model.Dto;
|
|
||||||
using DOAN.Model.MES;
|
|
||||||
using DOAN.Model.MES.andon;
|
using DOAN.Model.MES.andon;
|
||||||
using DOAN.Model.MES.base_;
|
using DOAN.Model.MES.base_;
|
||||||
using DOAN.Model.MES.group;
|
using DOAN.Model.MES.group;
|
||||||
using DOAN.Model.MES.product;
|
using DOAN.Model.MES.product;
|
||||||
using DOAN.Model.MES.product.Dto;
|
|
||||||
using DOAN.Model.MES.report;
|
using DOAN.Model.MES.report;
|
||||||
using DOAN.Repository;
|
|
||||||
using DOAN.Service.MES.product.IService;
|
|
||||||
using DOAN.Service.MES.report.IService;
|
using DOAN.Service.MES.report.IService;
|
||||||
using Infrastructure;
|
|
||||||
using Infrastructure.Attribute;
|
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.Data;
|
||||||
using System.Globalization;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Xml.Linq;
|
|
||||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
|
||||||
|
|
||||||
namespace DOAN.Service.MES.report
|
namespace DOAN.Service.MES.report
|
||||||
{
|
{
|
||||||
@ -224,6 +201,75 @@ namespace DOAN.Service.MES.report
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<ProductionCompletionRate> MonthlyProductionCompletionRate(DateTime dateTime)
|
||||||
|
{
|
||||||
|
(DateTime FirstDay, DateTime LastDay) Handlemonth = GetFirstAndLastDayOfMonth(dateTime);
|
||||||
|
List<ProductionCompletionRate> list = new List<ProductionCompletionRate>();
|
||||||
|
|
||||||
|
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>= 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<ProductionCompletionModel>(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)
|
private string GetStatusName(int status)
|
||||||
{
|
{
|
||||||
if (status == 1)
|
if (status == 1)
|
||||||
@ -237,5 +283,15 @@ namespace DOAN.Service.MES.report
|
|||||||
else
|
else
|
||||||
return "";
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user