158 lines
6.2 KiB
C#
158 lines
6.2 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;
|
|
using DOAN.Model.MES.andon;
|
|
|
|
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;
|
|
}
|
|
|
|
public List<DeviceDowntimeRateModel> DeviceDowntimeRate(DateTime dateTime)
|
|
{
|
|
List<DeviceDowntimeRateModel> list = new List<DeviceDowntimeRateModel>();
|
|
var dt = dateTime.ToString("yyyy-MM-dd");
|
|
|
|
list = Context.Queryable<ProWorkorder>()
|
|
.InnerJoin<BaseWorkRoute>((a, b) => a.LineCode == b.Code)
|
|
.Where((a, b) => a.WorkorderDate.Value.ToString("yyyy-MM-dd") == dt)
|
|
.Select((a, b) =>
|
|
new DeviceDowntimeRateModel
|
|
{
|
|
LineCode = b.Code,
|
|
LineName = b.Name,
|
|
PlanHours = SqlFunc.Round((a.Beat * a.DeliveryNum ?? 0) / 3600.0,2)
|
|
}).ToList();
|
|
|
|
var response = Context.Queryable<AndonFaultRecord>()
|
|
.Where(t=>t.FaultDict== "设备异常" && t.StartTime.HasValue && t.EndTime.HasValue && t.EndTime.Value.ToString("yyyy-MM-dd") ==dt)
|
|
.Select(it => new
|
|
{
|
|
it.LineCode,
|
|
it.StartTime,
|
|
it.EndTime,
|
|
DowntimeHours = (it.EndTime.Value - it.StartTime.Value).TotalHours,
|
|
}).ToList();
|
|
|
|
var groupList = response.GroupBy(it => it.LineCode).Select(it => new
|
|
{
|
|
LineCode = it.Key,
|
|
DowntimeHours = it.ToList().Sum(t=>t.DowntimeHours)
|
|
}).ToList();
|
|
|
|
var result = list.GroupJoin(groupList,
|
|
l => l.LineCode,
|
|
g => g.LineCode,
|
|
(l, gList) => new DeviceDowntimeRateModel
|
|
{
|
|
LineCode = l.LineCode,
|
|
LineName = l.LineName,
|
|
PlanHours = l.PlanHours,
|
|
DowntimeHours = gList.FirstOrDefault()?.DowntimeHours ?? l.PlanHours, // 如果没有停机时间则为计划时间
|
|
DowntimeRate= Math.Round((gList.FirstOrDefault()?.DowntimeHours ?? l.PlanHours) / l.PlanHours, 2)
|
|
}).ToList();
|
|
|
|
return result;
|
|
}
|
|
}
|
|
}
|