123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584 |
- 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<Result<CapaDto>>();
- if (root != null)
- if (root.Data != null)
- {
- dto = root.Data;
- }
- }
- return dto;
- }
- /// <summary>
- /// 获取生产计划
- /// </summary>
- public static List<Application.Services.LineService.Dtos.ProductionPlanDto> GetProductionPlans(int floor, int line, string date)
- {
- List<Application.Services.LineService.Dtos.ProductionPlanDto> productionPlans = new List<Application.Services.LineService.Dtos.ProductionPlanDto>();
- 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<Result<List<Application.Services.LineService.Dtos.ProductionPlanDto>>>();
- 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<Application.Services.LineService.Dtos.ProductionPlanDtoV1> GetProductionPlansV1(int floor, int line, string date)
- {
- List<Application.Services.LineService.Dtos.ProductionPlanDtoV1> productionPlans = new List<Application.Services.LineService.Dtos.ProductionPlanDtoV1>();
- 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<Result<List<Application.Services.LineService.Dtos.ProductionPlanDtoV1>>>();
- 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;
- }
-
- /// <summary>
- /// 获取 key in 数据
- /// </summary>
- public static List<KeyInInfo> GetKeyInInfos(int floor, int line, string date)
- {
- List<KeyInInfo> keyInInfos = new List<KeyInInfo>();
- 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<Result<List<KeyInInfo>>>();
- if (root != null && root.Code == CodeEnum.Success)
- if (root.Data != null)
- {
- keyInInfos = root.Data.ToList();
- }
- }
- return keyInInfos.OrderBy(o => o.StartTime).ToList();
- }
- /// <summary>
- /// 读取key in 故障
- /// </summary>
- public static List<MachineFaultDto> GetKeyInFaults(int floor, int line, string date, string type)
- {
- List<MachineFaultDto> faultRecords = new List<MachineFaultDto>();
- 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<Result<List<MachineFaultDto>>>();
- 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();
- }
- /// <summary>
- /// 获取小时产能
- /// </summary>
- public static List<MachineDayOutPutPerHour> GetOutPutPerHours(string topic, string date)
- {
- List<MachineDayOutPutPerHour> outPutPerHours = new List<MachineDayOutPutPerHour>();
- 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<Result<List<MachineDayOutPutPerHour>>>();
- 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;
- }
- /// <summary>
- /// 读取故障
- /// </summary>
- public static List<MachineFaultDto> GetFaults(string topic, string date)
- {
- List<MachineFaultDto> faultRecords = new List<MachineFaultDto>();
- 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<Result<List<MachineFaultDto>>>();
- 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<Application.Services.HomeService.Dtos.ProductionPlanDto> 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<Result<List<Application.Services.HomeService.Dtos.ProductionPlanDto>>>();
- if (root.Code == CodeEnum.Success)
- {
- return root.Data;
- }
- }
- return new List<Application.Services.HomeService.Dtos.ProductionPlanDto>();
- }
- public static List<Application.Services.HomeService.Dtos.ProductionPlanDtoV1> 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<Result<List<Application.Services.HomeService.Dtos.ProductionPlanDtoV1>>>();
- if (root.Code == CodeEnum.Success)
- {
- return root.Data;
- }
- }
- return new List<Application.Services.HomeService.Dtos.ProductionPlanDtoV1>();
- }
- public static List<MachineDayOutPutPerHour> 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<Result<List<MachineDayOutPutPerHour>>>();
- if (root.Code == CodeEnum.Success)
- {
- return root.Data;
- }
- }
- return new List<MachineDayOutPutPerHour>();
- }
- public static List<MonthModuleTypeDto> 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<Result<List<MonthModuleTypeDto>>>();
- if (root.Code == 0)
- {
- return root.Data;
- }
- }
- return new List<MonthModuleTypeDto>();
- }
- public static List<MonthModuleType> GetMonthModuleTypeDtosByMark(int year, int month, string mark)
- {
- #region 测试
- //List<MonthModuleType> monthModuleTypes = new List<MonthModuleType>();
- //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<Result<List<MonthModuleType>>>();
- if (root.Code == 0)
- {
- return root.Data;
- }
- }
- return new List<MonthModuleType>();
- }
- public static List<MonthModuleType> 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<Result<List<MonthModuleType>>>();
- if (root.Code == 0)
- {
- return root.Data;
- }
- }
- return new List<MonthModuleType>();
- }
- 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<ResultDto>();
- 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<ResultDto>();
- 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<ResultDto>();
- return root;
- }
- return ResultDto.Fail("接口调用失败!");
- }
- public static List<KeyInInfo> GetKeyInInfoTop5(int floor, int line, DateTime startDate, DateTime endDate)
- {
- List<KeyInInfo> keyInInfos = new List<KeyInInfo>();
- 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<Result<List<KeyInInfo>>>();
- 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<ElectricEnergyMeterDataDto> GetElectricEnergyMeters(string topic)
- {
- IEnumerable<ElectricEnergyMeterDataDto> dtos = new List<ElectricEnergyMeterDataDto>();
- 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<Result<List<ElectricEnergyMeterDataDto>>>();
- if (root != null && root.Code == CodeEnum.Success)
- if (root.Data != null)
- {
- dtos = root.Data.ToList();
- }
- }
- return dtos;
- }
- public static IEnumerable<KeyInInfo> GetAlarmByKeyIn(int floor, int line, DateTime startTime, DateTime endTime)
- {
- IEnumerable<KeyInInfo> dtos = new List<KeyInInfo>();
- 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<Result<List<KeyInInfo>>>();
- if (root != null && root.Code == CodeEnum.Success)
- if (root.Data != null)
- {
- dtos = root.Data.ToList();
- }
- }
- return dtos;
- }
- public static IEnumerable<EnergyConsumptionDto> GetDayEnergyConsumptions(string topic, string startDate, string endDate)
- {
- IEnumerable<EnergyConsumptionDto> dtos = new List<EnergyConsumptionDto>();
- 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<Result<List<EnergyConsumptionDto>>>();
- if (root != null && root.Code == CodeEnum.Success)
- if (root.Data != null)
- {
- dtos = root.Data.ToList();
- }
- }
- return dtos;
- }
- public static IEnumerable<HourElectricEnergy> GetHourElectricEnergys(string topic, string date, int shift)
- {
- IEnumerable<HourElectricEnergy> dtos = new List<HourElectricEnergy>();
- 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<Result<List<HourElectricEnergy>>>();
- if (root != null && root.Code == CodeEnum.Success)
- if (root.Data != null)
- {
- dtos = root.Data.ToList();
- }
- }
- return dtos;
- }
- public static IEnumerable<ElectricEnergyMeterDataDto> GetPowerByEqpAndMonth(string topic, string startDate, string endDate)
- {
- IEnumerable<ElectricEnergyMeterDataDto> dtos = new List<ElectricEnergyMeterDataDto>();
- 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<Result<List<ElectricEnergyMeterDataDto>>>();
- if (root != null && root.Code == CodeEnum.Success)
- if (root.Data != null)
- {
- dtos = root.Data.ToList();
- }
- }
- return dtos;
- }
- }
- }
|