2026-01-21 11:16:34 +08:00

110 lines
3.8 KiB
C#

using System;
using SqlSugar;
using Infrastructure.Attribute;
using Infrastructure.Extensions;
using DOAN.Model;
using DOAN.Model.Dto;
using DOAN.Model.MES.product;
using DOAN.Model.MES.product.Dto;
using DOAN.Repository;
using DOAN.Service.MES.product.IService;
using System.Linq;
using Microsoft.AspNetCore.Http;
using Infrastructure;
using static System.Runtime.InteropServices.JavaScript.JSType;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using NPOI.SS.Formula.Functions;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
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.Xml.Linq;
using Aliyun.OSS;
using AlibabaCloud.SDK.Dingtalkdoc_1_0.Models;
namespace DOAN.Service.MES.report
{
[AppService(ServiceType = typeof(IReportService), ServiceLifetime = LifeTime.Transient)]
public class ReportService : BaseService<BaseWorkRoute>, IReportService
{
public List<DevicePoweronRateModel> DevicePoweronRate(DateTime dateTime)
{
List<DevicePoweronRateModel> list = new List<DevicePoweronRateModel>();
var response = Context.Queryable<BaseWorkRoute>().ToList();
var dt = dateTime.ToString("yyyy-MM-dd");
var shiftList = Context.Queryable<GroupSchedule>()
.LeftJoin<GroupShift>((a, b) => a.FkShift == b.Id)
.LeftJoin<ProWorkorder>((a, b, c) => a.GroupCode == c.GroupCode && c.WorkorderDate.Value.ToString("yyyy-MM-dd") == dt)
.Where((a, b, c) => a.ScheduleDate.Value.ToString("yyyy-MM-dd") == dt)
.Select((a, b, c) =>
new
{
b.Name,
b.WorkHours,
b.StartTime,
b.EndTime,
c.LineCode
}).ToList();
var tempList = response.Select(it => new
{
LineCode = it.Code,
LineName = it.Name,
List = shiftList.Where(it2 => it2.LineCode == it.Code).Select(it2 => new { it2.Name, it2.StartTime, it2.EndTime }).ToList()
}).ToList();
tempList.ForEach(t =>
{
double poweronRate = 0;
double minutes = 0;
int shiftCount = 0;
t.List.ForEach(t2 =>
{
if (t2.EndTime.HasValue && t2.StartTime.HasValue)
{
if (t2.EndTime.Value.Hour == 16)
{
minutes += (t2.EndTime.Value - t2.StartTime.Value).TotalMinutes - 50;
shiftCount++;
}
else if (t2.EndTime.Value.Hour == 20)
{
minutes += (t2.EndTime.Value - t2.StartTime.Value).TotalMinutes - 80;
shiftCount++;
}
else if (t2.EndTime.Value.Hour == 22)
{
minutes += (t2.EndTime.Value - t2.StartTime.Value).TotalMinutes - 100;
shiftCount++;
}
}
});
if (shiftCount > 0)
{
poweronRate = Math.Round(minutes * 100.0 / (24 * 60 * shiftCount), 2);
}
list.Add(new DevicePoweronRateModel()
{
LineCode = t.LineCode,
LineName = t.LineName,
ShiftCount = shiftCount,
PoweronHours = minutes,
PoweronRate = poweronRate
});
});
return list;
}
}
}