MesApiService.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. using NPOI.SS.Formula.Functions;
  2. using NPOI.XWPF.UserModel;
  3. using ProductionLineMonitor.Application.Services;
  4. using ProductionLineMonitor.Application.Services.EnergyConsumptionService.Dtos;
  5. using ProductionLineMonitor.Application.Services.FaultService.Dtos;
  6. using ProductionLineMonitor.Application.Services.HomeService.Dtos;
  7. using ProductionLineMonitor.Application.Services.HomeService.Models;
  8. using ProductionLineMonitor.Application.Services.LineService.Dtos;
  9. using ProductionLineMonitor.Core.Dtos;
  10. using ProductionLineMonitor.Core.Utils;
  11. using ProductionLineMonitor.Web.Services.LineService;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Linq;
  15. using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
  16. using CodeEnum = ProductionLineMonitor.Application.Services.CodeEnum;
  17. namespace ProductionLineMonitor.Web.Services
  18. {
  19. public class MesApiService
  20. {
  21. public static CapaDto GetCapaTT(int floor, int line, string moduleType)
  22. {
  23. CapaDto dto = new CapaDto();
  24. QueryCapa query = new QueryCapa()
  25. {
  26. Device = moduleType,
  27. Floor = floor,
  28. Line = line,
  29. };
  30. var rev = HttpHelper.Post(
  31. "http://eyzms.toc.eink.com:8088/MesApi/GetCapaByDevice",
  32. query.ToJson(),
  33. 20);
  34. if (rev.Item1 == true)
  35. {
  36. var root = rev.Item2.ToObject<Result<CapaDto>>();
  37. if (root != null)
  38. if (root.Data != null)
  39. {
  40. dto = root.Data;
  41. }
  42. }
  43. return dto;
  44. }
  45. /// <summary>
  46. /// 获取生产计划
  47. /// </summary>
  48. public static List<Application.Services.LineService.Dtos.ProductionPlanDto> GetProductionPlans(int floor, int line, string date)
  49. {
  50. List<Application.Services.LineService.Dtos.ProductionPlanDto> productionPlans = new List<Application.Services.LineService.Dtos.ProductionPlanDto>();
  51. QueryPlanParam query = new QueryPlanParam()
  52. {
  53. Floor = floor,
  54. Line = line,
  55. Date = date
  56. };
  57. var rev = HttpHelper.Post(
  58. "http://eyzms.toc.eink.com:8088/MesApi/GetScheduledProduction",
  59. query.ToJson(),
  60. 20);
  61. if (rev.Item1 == true)
  62. {
  63. var root = rev.Item2.ToObject<Result<List<Application.Services.LineService.Dtos.ProductionPlanDto>>>();
  64. if (root != null)
  65. if (root.Data != null)
  66. {
  67. productionPlans = root.Data.ToList();
  68. foreach (var item in productionPlans)
  69. {
  70. item.PlanCapacity = item.PlanCapacity == -1 ? 0 : item.PlanCapacity;
  71. item.Capa = item.Capa == -1 ? 0 : item.Capa;
  72. item.TT = item.TT == -1 ? 0 : item.TT;
  73. }
  74. }
  75. }
  76. return productionPlans;
  77. }
  78. public static List<Application.Services.LineService.Dtos.ProductionPlanDtoV1> GetProductionPlansV1(int floor, int line, string date)
  79. {
  80. List<Application.Services.LineService.Dtos.ProductionPlanDtoV1> productionPlans = new List<Application.Services.LineService.Dtos.ProductionPlanDtoV1>();
  81. QueryPlanParam query = new QueryPlanParam()
  82. {
  83. Floor = floor,
  84. Line = line,
  85. Date = date
  86. };
  87. var rev = HttpHelper.Post(
  88. "http://eyzms.toc.eink.com:8088/MesApi/GetScheduledProductionNew",
  89. query.ToJson(),
  90. 20);
  91. if (rev.Item1 == true)
  92. {
  93. var root = rev.Item2.ToObject<Result<List<Application.Services.LineService.Dtos.ProductionPlanDtoV1>>>();
  94. if (root != null)
  95. if (root.Data != null)
  96. {
  97. productionPlans = root.Data.ToList();
  98. foreach (var item in productionPlans)
  99. {
  100. item.PlanCapacity = item.PlanCapacity == -1 ? 0 : item.PlanCapacity;
  101. item.Capa = item.Capa == -1 ? 0 : item.Capa;
  102. item.TT = item.TT == -1 ? 0 : item.TT;
  103. }
  104. }
  105. }
  106. return productionPlans;
  107. }
  108. /// <summary>
  109. /// 获取 key in 数据
  110. /// </summary>
  111. public static List<KeyInInfo> GetKeyInInfos(int floor, int line, string date)
  112. {
  113. List<KeyInInfo> keyInInfos = new List<KeyInInfo>();
  114. QueryPlanParam query = new QueryPlanParam()
  115. {
  116. Floor = floor,
  117. Line = line,
  118. Date = date
  119. };
  120. var rev = HttpHelper.Post(
  121. "http://eyzms.toc.eink.com:8088/MesApi/GetExceptionsExceptBreakdown",
  122. query.ToJson(),
  123. 20);
  124. if (rev.Item1 == true)
  125. {
  126. var root = rev.Item2.ToObject<Result<List<KeyInInfo>>>();
  127. if (root != null && root.Code == CodeEnum.Success)
  128. if (root.Data != null)
  129. {
  130. keyInInfos = root.Data.ToList();
  131. }
  132. }
  133. return keyInInfos.OrderBy(o => o.StartTime).ToList();
  134. }
  135. /// <summary>
  136. /// 读取key in 故障
  137. /// </summary>
  138. public static List<MachineFaultDto> GetKeyInFaults(int floor, int line, string date, string type)
  139. {
  140. List<MachineFaultDto> faultRecords = new List<MachineFaultDto>();
  141. QueryMachineKeyInFaultParam query = new QueryMachineKeyInFaultParam()
  142. {
  143. Floor = floor,
  144. Line = line,
  145. MachineType = type,
  146. Date = date
  147. };
  148. var rev = HttpHelper.Post(
  149. "http://eyzms.toc.eink.com:8088/MesApi/GetKeyInDayException",
  150. query.ToJson(), 20);
  151. if (rev.Item1 == true)
  152. {
  153. var root = rev.Item2.ToObject<Result<List<MachineFaultDto>>>();
  154. if (root != null && root.Code == CodeEnum.Success)
  155. {
  156. if (root.Data != null)
  157. {
  158. faultRecords = root.Data.OrderBy(o => o.StartTime).ToList();
  159. foreach (var item in faultRecords)
  160. {
  161. if (item.EndTime != null)
  162. {
  163. item.Duration = Math.Round((item.EndTime - item.StartTime).Value.TotalMinutes, 2);
  164. }
  165. }
  166. }
  167. }
  168. }
  169. return faultRecords.OrderBy(o => o.StartTime).ToList();
  170. }
  171. /// <summary>
  172. /// 获取小时产能
  173. /// </summary>
  174. public static List<MachineDayOutPutPerHour> GetOutPutPerHours(string topic, string date)
  175. {
  176. List<MachineDayOutPutPerHour> outPutPerHours = new List<MachineDayOutPutPerHour>();
  177. QueryMachineParam query = new QueryMachineParam()
  178. {
  179. Equiptopic = topic,
  180. Date = date
  181. };
  182. var rev = HttpHelper.Post(
  183. "http://eyzms.toc.eink.com:8088/MesApi/GetOutput",
  184. query.ToJson(),
  185. 20);
  186. if (rev.Item1 == true)
  187. {
  188. var root = rev.Item2.ToObject<Result<List<MachineDayOutPutPerHour>>>();
  189. if (root != null && root.Code == CodeEnum.Success)
  190. {
  191. if (root.Data != null)
  192. {
  193. outPutPerHours = root.Data.OrderBy(o => o.DataTime).ToList();
  194. foreach (var item in outPutPerHours)
  195. {
  196. item.AutoRunTime /= 60;
  197. item.AlarmTime /= 60;
  198. item.IdleTime /= 60;
  199. item.IdleTimeDownstream /= 60;
  200. item.IdleTimeUpstream /= 60;
  201. item.IdleTimeSelf /= 60;
  202. item.LoadMATTime /= 60;
  203. }
  204. }
  205. }
  206. }
  207. return outPutPerHours;
  208. }
  209. /// <summary>
  210. /// 读取故障
  211. /// </summary>
  212. public static List<MachineFaultDto> GetFaults(string topic, string date)
  213. {
  214. List<MachineFaultDto> faultRecords = new List<MachineFaultDto>();
  215. QueryMachineParam query = new QueryMachineParam()
  216. {
  217. Equiptopic = topic,
  218. Date = date
  219. };
  220. var rev = HttpHelper.Post(
  221. "http://eyzms.toc.eink.com:8088/MesApi/GetAlarm",
  222. query.ToJson(), 20);
  223. if (rev.Item1 == true)
  224. {
  225. var root = rev.Item2.ToObject<Result<List<MachineFaultDto>>>();
  226. if (root != null && root.Code == CodeEnum.Success)
  227. {
  228. if (root.Data != null)
  229. {
  230. faultRecords = root.Data.OrderBy(o => o.StartTime).ToList();
  231. foreach (var item in faultRecords)
  232. {
  233. if (item.EndTime != null)
  234. {
  235. item.Duration = Math.Round((item.EndTime - item.StartTime).Value.TotalMinutes, 2);
  236. }
  237. }
  238. }
  239. }
  240. }
  241. return faultRecords;
  242. }
  243. public static List<Application.Services.HomeService.Dtos.ProductionPlanDto> GetProductionPlanByTimelot(
  244. int floor, int line, string startDate, string endDate)
  245. {
  246. var dto = new { Floor = floor, Line = line, StartDate = startDate, EndDate = endDate };
  247. var rev = HttpHelper.Post(
  248. "http://eyzms.toc.eink.com:8088/MesApi/GetScheduledProductionBytimeslot",
  249. dto.ToJson(), 20);
  250. if (rev.Item1 == true)
  251. {
  252. var root = rev.Item2.ToObject<Result<List<Application.Services.HomeService.Dtos.ProductionPlanDto>>>();
  253. if (root.Code == CodeEnum.Success)
  254. {
  255. return root.Data;
  256. }
  257. }
  258. return new List<Application.Services.HomeService.Dtos.ProductionPlanDto>();
  259. }
  260. public static List<Application.Services.HomeService.Dtos.ProductionPlanDtoV1> GetProductionPlanByTimelotV1(
  261. int floor, int line, string startDate, string endDate)
  262. {
  263. var dto = new { Floor = floor, Line = line, StartDate = startDate, EndDate = endDate };
  264. var rev = HttpHelper.Post(
  265. "http://eyzms.toc.eink.com:8088/MesApi/GetScheduledProductionBytimeslot",
  266. dto.ToJson(), 20);
  267. if (rev.Item1 == true)
  268. {
  269. var root = rev.Item2.ToObject<Result<List<Application.Services.HomeService.Dtos.ProductionPlanDtoV1>>>();
  270. if (root.Code == CodeEnum.Success)
  271. {
  272. return root.Data;
  273. }
  274. }
  275. return new List<Application.Services.HomeService.Dtos.ProductionPlanDtoV1>();
  276. }
  277. public static List<MachineDayOutPutPerHour> GetOutPutPerHours(string topic, string startDate, string endDate)
  278. {
  279. var dto = new { Topic = topic, StartDate = startDate, EndDate = endDate };
  280. var rev = HttpHelper.Post(
  281. "http://eyzms.toc.eink.com:8088/MesApi/GetOutputByTimeSlot",
  282. dto.ToJson(), 20);
  283. if (rev.Item1 == true)
  284. {
  285. var root = rev.Item2.ToObject<Result<List<MachineDayOutPutPerHour>>>();
  286. if (root.Code == CodeEnum.Success)
  287. {
  288. return root.Data;
  289. }
  290. }
  291. return new List<MachineDayOutPutPerHour>();
  292. }
  293. public static List<MonthModuleTypeDto> GetMonthModuleTypeDtos(int year, int month)
  294. {
  295. var dto = new { Year = year, Month = month };
  296. var rev = HttpHelper.Post(
  297. "http://eyzms.toc.eink.com:8088/MesApi/MonthDevice/GetMonthDevice",
  298. dto.ToJson(), 20);
  299. if (rev.Item1 == true)
  300. {
  301. var root = rev.Item2.ToObject<Result<List<MonthModuleTypeDto>>>();
  302. if (root.Code == 0)
  303. {
  304. return root.Data;
  305. }
  306. }
  307. return new List<MonthModuleTypeDto>();
  308. }
  309. public static List<MonthModuleType> GetMonthModuleTypeDtosByMark(int year, int month, string mark)
  310. {
  311. #region 测试
  312. //List<MonthModuleType> monthModuleTypes = new List<MonthModuleType>();
  313. //var a = new MonthModuleType()
  314. //{
  315. // Id = Guid.NewGuid().ToString(),
  316. // LastModuleCapacity = 0,
  317. // Year = 2023,
  318. // Month = 7,
  319. // Mark = "2F",
  320. // PlanCapacity = 1000,
  321. // ModuleType = "TC097SC12",
  322. // Remark = "asdsadasd"
  323. //};
  324. //monthModuleTypes.Add(a);
  325. //return monthModuleTypes;
  326. #endregion
  327. var dto = new { Year = year, Month = month, Mark = mark };
  328. var rev = HttpHelper.Post(
  329. "http://eyzms.toc.eink.com:8088/MesApi/MonthDevice/GetMonthDeviceByMark",
  330. dto.ToJson(), 20);
  331. if (rev.Item1 == true)
  332. {
  333. var root = rev.Item2.ToObject<Result<List<MonthModuleType>>>();
  334. if (root.Code == 0)
  335. {
  336. return root.Data;
  337. }
  338. }
  339. return new List<MonthModuleType>();
  340. }
  341. public static List<MonthModuleType> GetMonthModuleTypes(int year, int month)
  342. {
  343. var dto = new { Year = year, Month = month };
  344. var rev = HttpHelper.Post(
  345. "http://eyzms.toc.eink.com:8088/MesApi/MonthDevice/GetMonthDevice",
  346. dto.ToJson(), 20);
  347. if (rev.Item1 == true)
  348. {
  349. var root = rev.Item2.ToObject<Result<List<MonthModuleType>>>();
  350. if (root.Code == 0)
  351. {
  352. return root.Data;
  353. }
  354. }
  355. return new List<MonthModuleType>();
  356. }
  357. public static ResultDto CreateMonthModuleType(MonthModuleTypeCreateAndUpdateDto dto)
  358. {
  359. var rev = HttpHelper.Post(
  360. "http://eyzms.toc.eink.com:8088/MesApi/MonthDevice/Create",
  361. dto.ToJson(), 20);
  362. if (rev.Item1 == true)
  363. {
  364. var root = rev.Item2.ToObject<ResultDto>();
  365. return root;
  366. }
  367. return ResultDto.Fail("接口调用失败!");
  368. }
  369. public static ResultDto UpdateMonthModuleType(MonthModuleTypeCreateAndUpdateDto dto)
  370. {
  371. var rev = HttpHelper.Post(
  372. "http://eyzms.toc.eink.com:8088/MesApi/MonthDevice/Update",
  373. dto.ToJson(), 20);
  374. if (rev.Item1 == true)
  375. {
  376. var root = rev.Item2.ToObject<ResultDto>();
  377. return root;
  378. }
  379. return ResultDto.Fail("接口调用失败!");
  380. }
  381. public static ResultDto DeleteMonthModuleType(MonthModuleTypeCreateAndUpdateDto dto)
  382. {
  383. var rev = HttpHelper.Post(
  384. "http://eyzms.toc.eink.com:8088/MesApi/MonthDevice/Delete",
  385. dto.ToJson(), 20);
  386. if (rev.Item1 == true)
  387. {
  388. var root = rev.Item2.ToObject<ResultDto>();
  389. return root;
  390. }
  391. return ResultDto.Fail("接口调用失败!");
  392. }
  393. public static List<KeyInInfo> GetKeyInInfoTop5(int floor, int line, DateTime startDate, DateTime endDate)
  394. {
  395. List<KeyInInfo> keyInInfos = new List<KeyInInfo>();
  396. var dto = new { Floor = floor, Line = line, StartDate = startDate, EndDate = endDate };
  397. var rev = HttpHelper.Post(
  398. "http://eyzms.toc.eink.com:8088/MesApi/GetExceptionsExceptBreakdown",
  399. dto.ToJson(),
  400. 20);
  401. if (rev.Item1 == true)
  402. {
  403. var root = rev.Item2.ToObject<Result<List<KeyInInfo>>>();
  404. if (root != null && root.Code == CodeEnum.Success)
  405. if (root.Data != null)
  406. {
  407. keyInInfos = root.Data.ToList();
  408. }
  409. }
  410. return keyInInfos.OrderBy(o => o.StartTime).ToList();
  411. }
  412. public static IEnumerable<ElectricEnergyMeterDataDto> GetElectricEnergyMeters(string topic)
  413. {
  414. IEnumerable<ElectricEnergyMeterDataDto> dtos = new List<ElectricEnergyMeterDataDto>();
  415. var dto = new { Topic = topic };
  416. var rev = HttpHelper.Post(
  417. "http://eyzms.toc.eink.com:8088/MesApi/EnergyInfo/GetPowerByEqp",
  418. dto.ToJson(),
  419. 20);
  420. if (rev.Item1 == true)
  421. {
  422. var root = rev.Item2.ToObject<Result<List<ElectricEnergyMeterDataDto>>>();
  423. if (root != null && root.Code == CodeEnum.Success)
  424. if (root.Data != null)
  425. {
  426. dtos = root.Data.ToList();
  427. }
  428. }
  429. return dtos;
  430. }
  431. public static IEnumerable<KeyInInfo> GetAlarmByKeyIn(int floor, int line, DateTime startTime, DateTime endTime)
  432. {
  433. IEnumerable<KeyInInfo> dtos = new List<KeyInInfo>();
  434. var dto = new { Floor = floor, Line = line, StartTime = startTime, EndTime = endTime };
  435. var rev = HttpHelper.Post(
  436. "http://eyzms.toc.eink.com:8088/MesApi/ProductAndAlarm/GetAlarmByKeyIn",
  437. dto.ToJson(),
  438. 20);
  439. if (rev.Item1 == true)
  440. {
  441. var root = rev.Item2.ToObject<Result<List<KeyInInfo>>>();
  442. if (root != null && root.Code == CodeEnum.Success)
  443. if (root.Data != null)
  444. {
  445. dtos = root.Data.ToList();
  446. }
  447. }
  448. return dtos;
  449. }
  450. public static IEnumerable<EnergyConsumptionDto> GetDayEnergyConsumptions(string topic, string startDate, string endDate)
  451. {
  452. IEnumerable<EnergyConsumptionDto> dtos = new List<EnergyConsumptionDto>();
  453. var dto = new { Topic = topic, StartDate = startDate, EndDate = endDate };
  454. var rev = HttpHelper.Post(
  455. "http://eyzms.toc.eink.com:8088/MesApi/EnergyInfo/GetPowerByEqpAndDay",
  456. dto.ToJson(),
  457. 20);
  458. if (rev.Item1 == true)
  459. {
  460. var root = rev.Item2.ToObject<Result<List<EnergyConsumptionDto>>>();
  461. if (root != null && root.Code == CodeEnum.Success)
  462. if (root.Data != null)
  463. {
  464. dtos = root.Data.ToList();
  465. }
  466. }
  467. return dtos;
  468. }
  469. public static IEnumerable<HourElectricEnergy> GetHourElectricEnergys(string topic, string date, int shift)
  470. {
  471. IEnumerable<HourElectricEnergy> dtos = new List<HourElectricEnergy>();
  472. var dto = new { Topic = topic, Date = date, Shift = shift };
  473. var rev = HttpHelper.Post(
  474. "http://eyzms.toc.eink.com:8088/MesApi/EnergyInfo/GetPowerByEqpAndHour",
  475. dto.ToJson(),
  476. 20);
  477. if (rev.Item1 == true)
  478. {
  479. var root = rev.Item2.ToObject<Result<List<HourElectricEnergy>>>();
  480. if (root != null && root.Code == CodeEnum.Success)
  481. if (root.Data != null)
  482. {
  483. dtos = root.Data.ToList();
  484. }
  485. }
  486. return dtos;
  487. }
  488. public static IEnumerable<ElectricEnergyMeterDataDto> GetPowerByEqpAndMonth(string topic, string startDate, string endDate)
  489. {
  490. IEnumerable<ElectricEnergyMeterDataDto> dtos = new List<ElectricEnergyMeterDataDto>();
  491. var dto = new { Topic = topic, StartDate = startDate, EndDate = endDate };
  492. var rev = HttpHelper.Post(
  493. "http://eyzms.toc.eink.com:8088/MesApi/EnergyInfo/GetPowerByEqpAndMonth",
  494. dto.ToJson(),
  495. 20);
  496. if (rev.Item1 == true)
  497. {
  498. var root = rev.Item2.ToObject<Result<List<ElectricEnergyMeterDataDto>>>();
  499. if (root != null && root.Code == CodeEnum.Success)
  500. if (root.Data != null)
  501. {
  502. dtos = root.Data.ToList();
  503. }
  504. }
  505. return dtos;
  506. }
  507. }
  508. }