using NPOI.SS.Formula.Functions; using NPOI.XWPF.UserModel; using ProductionLineMonitor.Application.Services; using ProductionLineMonitor.Application.Services.EnergyConsumptionService.Dtos; using ProductionLineMonitor.Application.Services.FaultService.Dtos; using ProductionLineMonitor.Application.Services.HomeService.Dtos; using ProductionLineMonitor.Application.Services.HomeService.Models; using ProductionLineMonitor.Application.Services.LineService.Dtos; using ProductionLineMonitor.Core.Dtos; using ProductionLineMonitor.Core.Utils; using ProductionLineMonitor.Web.Services.LineService; using System; using System.Collections.Generic; using System.Linq; using static Microsoft.EntityFrameworkCore.DbLoggerCategory; using CodeEnum = ProductionLineMonitor.Application.Services.CodeEnum; namespace ProductionLineMonitor.Web.Services { public class MesApiService { public static CapaDto GetCapaTT(int floor, int line, string moduleType) { CapaDto dto = new CapaDto(); QueryCapa query = new QueryCapa() { Device = moduleType, Floor = floor, Line = line, }; var rev = HttpHelper.Post( "http://eyzms.toc.eink.com:8088/MesApi/GetCapaByDevice", query.ToJson(), 20); if (rev.Item1 == true) { var root = rev.Item2.ToObject>(); if (root != null) if (root.Data != null) { dto = root.Data; } } return dto; } /// /// 获取生产计划 /// public static List GetProductionPlans(int floor, int line, string date) { List productionPlans = new List(); QueryPlanParam query = new QueryPlanParam() { Floor = floor, Line = line, Date = date }; var rev = HttpHelper.Post( "http://eyzms.toc.eink.com:8088/MesApi/GetScheduledProduction", query.ToJson(), 20); if (rev.Item1 == true) { var root = rev.Item2.ToObject>>(); if (root != null) if (root.Data != null) { productionPlans = root.Data.ToList(); foreach (var item in productionPlans) { item.PlanCapacity = item.PlanCapacity == -1 ? 0 : item.PlanCapacity; item.Capa = item.Capa == -1 ? 0 : item.Capa; item.TT = item.TT == -1 ? 0 : item.TT; } } } return productionPlans; } public static List GetProductionPlansV1(int floor, int line, string date) { List productionPlans = new List(); QueryPlanParam query = new QueryPlanParam() { Floor = floor, Line = line, Date = date }; var rev = HttpHelper.Post( "http://eyzms.toc.eink.com:8088/MesApi/GetScheduledProductionNew", query.ToJson(), 20); if (rev.Item1 == true) { var root = rev.Item2.ToObject>>(); if (root != null) if (root.Data != null) { productionPlans = root.Data.ToList(); foreach (var item in productionPlans) { item.PlanCapacity = item.PlanCapacity == -1 ? 0 : item.PlanCapacity; item.Capa = item.Capa == -1 ? 0 : item.Capa; item.TT = item.TT == -1 ? 0 : item.TT; } } } return productionPlans; } /// /// 获取 key in 数据 /// public static List GetKeyInInfos(int floor, int line, string date) { List keyInInfos = new List(); QueryPlanParam query = new QueryPlanParam() { Floor = floor, Line = line, Date = date }; var rev = HttpHelper.Post( "http://eyzms.toc.eink.com:8088/MesApi/GetExceptionsExceptBreakdown", query.ToJson(), 20); if (rev.Item1 == true) { var root = rev.Item2.ToObject>>(); if (root != null && root.Code == CodeEnum.Success) if (root.Data != null) { keyInInfos = root.Data.ToList(); } } return keyInInfos.OrderBy(o => o.StartTime).ToList(); } /// /// 读取key in 故障 /// public static List GetKeyInFaults(int floor, int line, string date, string type) { List faultRecords = new List(); QueryMachineKeyInFaultParam query = new QueryMachineKeyInFaultParam() { Floor = floor, Line = line, MachineType = type, Date = date }; var rev = HttpHelper.Post( "http://eyzms.toc.eink.com:8088/MesApi/GetKeyInDayException", query.ToJson(), 20); if (rev.Item1 == true) { var root = rev.Item2.ToObject>>(); if (root != null && root.Code == CodeEnum.Success) { if (root.Data != null) { faultRecords = root.Data.OrderBy(o => o.StartTime).ToList(); foreach (var item in faultRecords) { if (item.EndTime != null) { item.Duration = Math.Round((item.EndTime - item.StartTime).Value.TotalMinutes, 2); } } } } } return faultRecords.OrderBy(o => o.StartTime).ToList(); } /// /// 获取小时产能 /// public static List GetOutPutPerHours(string topic, string date) { List outPutPerHours = new List(); QueryMachineParam query = new QueryMachineParam() { Equiptopic = topic, Date = date }; var rev = HttpHelper.Post( "http://eyzms.toc.eink.com:8088/MesApi/GetOutput", query.ToJson(), 20); if (rev.Item1 == true) { var root = rev.Item2.ToObject>>(); if (root != null && root.Code == CodeEnum.Success) { if (root.Data != null) { outPutPerHours = root.Data.OrderBy(o => o.DataTime).ToList(); foreach (var item in outPutPerHours) { item.AutoRunTime /= 60; item.AlarmTime /= 60; item.IdleTime /= 60; item.IdleTimeDownstream /= 60; item.IdleTimeUpstream /= 60; item.IdleTimeSelf /= 60; item.LoadMATTime /= 60; } } } } return outPutPerHours; } /// /// 读取故障 /// public static List GetFaults(string topic, string date) { List faultRecords = new List(); QueryMachineParam query = new QueryMachineParam() { Equiptopic = topic, Date = date }; var rev = HttpHelper.Post( "http://eyzms.toc.eink.com:8088/MesApi/GetAlarm", query.ToJson(), 20); if (rev.Item1 == true) { var root = rev.Item2.ToObject>>(); if (root != null && root.Code == CodeEnum.Success) { if (root.Data != null) { faultRecords = root.Data.OrderBy(o => o.StartTime).ToList(); foreach (var item in faultRecords) { if (item.EndTime != null) { item.Duration = Math.Round((item.EndTime - item.StartTime).Value.TotalMinutes, 2); } } } } } return faultRecords; } public static List GetProductionPlanByTimelot( int floor, int line, string startDate, string endDate) { var dto = new { Floor = floor, Line = line, StartDate = startDate, EndDate = endDate }; var rev = HttpHelper.Post( "http://eyzms.toc.eink.com:8088/MesApi/GetScheduledProductionBytimeslot", dto.ToJson(), 20); if (rev.Item1 == true) { var root = rev.Item2.ToObject>>(); if (root.Code == CodeEnum.Success) { return root.Data; } } return new List(); } public static List GetProductionPlanByTimelotV1( int floor, int line, string startDate, string endDate) { var dto = new { Floor = floor, Line = line, StartDate = startDate, EndDate = endDate }; var rev = HttpHelper.Post( "http://eyzms.toc.eink.com:8088/MesApi/GetScheduledProductionBytimeslot", dto.ToJson(), 20); if (rev.Item1 == true) { var root = rev.Item2.ToObject>>(); if (root.Code == CodeEnum.Success) { return root.Data; } } return new List(); } public static List GetOutPutPerHours(string topic, string startDate, string endDate) { var dto = new { Topic = topic, StartDate = startDate, EndDate = endDate }; var rev = HttpHelper.Post( "http://eyzms.toc.eink.com:8088/MesApi/GetOutputByTimeSlot", dto.ToJson(), 20); if (rev.Item1 == true) { var root = rev.Item2.ToObject>>(); if (root.Code == CodeEnum.Success) { return root.Data; } } return new List(); } public static List GetMonthModuleTypeDtos(int year, int month) { var dto = new { Year = year, Month = month }; var rev = HttpHelper.Post( "http://eyzms.toc.eink.com:8088/MesApi/MonthDevice/GetMonthDevice", dto.ToJson(), 20); if (rev.Item1 == true) { var root = rev.Item2.ToObject>>(); if (root.Code == 0) { return root.Data; } } return new List(); } public static List GetMonthModuleTypeDtosByMark(int year, int month, string mark) { #region 测试 //List monthModuleTypes = new List(); //var a = new MonthModuleType() //{ // Id = Guid.NewGuid().ToString(), // LastModuleCapacity = 0, // Year = 2023, // Month = 7, // Mark = "2F", // PlanCapacity = 1000, // ModuleType = "TC097SC12", // Remark = "asdsadasd" //}; //monthModuleTypes.Add(a); //return monthModuleTypes; #endregion var dto = new { Year = year, Month = month, Mark = mark }; var rev = HttpHelper.Post( "http://eyzms.toc.eink.com:8088/MesApi/MonthDevice/GetMonthDeviceByMark", dto.ToJson(), 20); if (rev.Item1 == true) { var root = rev.Item2.ToObject>>(); if (root.Code == 0) { return root.Data; } } return new List(); } public static List GetMonthModuleTypes(int year, int month) { var dto = new { Year = year, Month = month }; var rev = HttpHelper.Post( "http://eyzms.toc.eink.com:8088/MesApi/MonthDevice/GetMonthDevice", dto.ToJson(), 20); if (rev.Item1 == true) { var root = rev.Item2.ToObject>>(); if (root.Code == 0) { return root.Data; } } return new List(); } public static ResultDto CreateMonthModuleType(MonthModuleTypeCreateAndUpdateDto dto) { var rev = HttpHelper.Post( "http://eyzms.toc.eink.com:8088/MesApi/MonthDevice/Create", dto.ToJson(), 20); if (rev.Item1 == true) { var root = rev.Item2.ToObject(); return root; } return ResultDto.Fail("接口调用失败!"); } public static ResultDto UpdateMonthModuleType(MonthModuleTypeCreateAndUpdateDto dto) { var rev = HttpHelper.Post( "http://eyzms.toc.eink.com:8088/MesApi/MonthDevice/Update", dto.ToJson(), 20); if (rev.Item1 == true) { var root = rev.Item2.ToObject(); return root; } return ResultDto.Fail("接口调用失败!"); } public static ResultDto DeleteMonthModuleType(MonthModuleTypeCreateAndUpdateDto dto) { var rev = HttpHelper.Post( "http://eyzms.toc.eink.com:8088/MesApi/MonthDevice/Delete", dto.ToJson(), 20); if (rev.Item1 == true) { var root = rev.Item2.ToObject(); return root; } return ResultDto.Fail("接口调用失败!"); } public static List GetKeyInInfoTop5(int floor, int line, DateTime startDate, DateTime endDate) { List keyInInfos = new List(); var dto = new { Floor = floor, Line = line, StartDate = startDate, EndDate = endDate }; var rev = HttpHelper.Post( "http://eyzms.toc.eink.com:8088/MesApi/GetExceptionsExceptBreakdown", dto.ToJson(), 20); if (rev.Item1 == true) { var root = rev.Item2.ToObject>>(); if (root != null && root.Code == CodeEnum.Success) if (root.Data != null) { keyInInfos = root.Data.ToList(); } } return keyInInfos.OrderBy(o => o.StartTime).ToList(); } public static IEnumerable GetElectricEnergyMeters(string topic) { IEnumerable dtos = new List(); var dto = new { Topic = topic }; var rev = HttpHelper.Post( "http://eyzms.toc.eink.com:8088/MesApi/EnergyInfo/GetPowerByEqp", dto.ToJson(), 20); if (rev.Item1 == true) { var root = rev.Item2.ToObject>>(); if (root != null && root.Code == CodeEnum.Success) if (root.Data != null) { dtos = root.Data.ToList(); } } return dtos; } public static IEnumerable GetAlarmByKeyIn(int floor, int line, DateTime startTime, DateTime endTime) { IEnumerable dtos = new List(); var dto = new { Floor = floor, Line = line, StartTime = startTime, EndTime = endTime }; var rev = HttpHelper.Post( "http://eyzms.toc.eink.com:8088/MesApi/ProductAndAlarm/GetAlarmByKeyIn", dto.ToJson(), 20); if (rev.Item1 == true) { var root = rev.Item2.ToObject>>(); if (root != null && root.Code == CodeEnum.Success) if (root.Data != null) { dtos = root.Data.ToList(); } } return dtos; } public static IEnumerable GetDayEnergyConsumptions(string topic, string startDate, string endDate) { IEnumerable dtos = new List(); var dto = new { Topic = topic, StartDate = startDate, EndDate = endDate }; var rev = HttpHelper.Post( "http://eyzms.toc.eink.com:8088/MesApi/EnergyInfo/GetPowerByEqpAndDay", dto.ToJson(), 20); if (rev.Item1 == true) { var root = rev.Item2.ToObject>>(); if (root != null && root.Code == CodeEnum.Success) if (root.Data != null) { dtos = root.Data.ToList(); } } return dtos; } public static IEnumerable GetHourElectricEnergys(string topic, string date, int shift) { IEnumerable dtos = new List(); var dto = new { Topic = topic, Date = date, Shift = shift }; var rev = HttpHelper.Post( "http://eyzms.toc.eink.com:8088/MesApi/EnergyInfo/GetPowerByEqpAndHour", dto.ToJson(), 20); if (rev.Item1 == true) { var root = rev.Item2.ToObject>>(); if (root != null && root.Code == CodeEnum.Success) if (root.Data != null) { dtos = root.Data.ToList(); } } return dtos; } public static IEnumerable GetPowerByEqpAndMonth(string topic, string startDate, string endDate) { IEnumerable dtos = new List(); var dto = new { Topic = topic, StartDate = startDate, EndDate = endDate }; var rev = HttpHelper.Post( "http://eyzms.toc.eink.com:8088/MesApi/EnergyInfo/GetPowerByEqpAndMonth", dto.ToJson(), 20); if (rev.Item1 == true) { var root = rev.Item2.ToObject>>(); if (root != null && root.Code == CodeEnum.Success) if (root.Data != null) { dtos = root.Data.ToList(); } } return dtos; } } }