HomeController.cs 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. using AutoMapper;
  2. using Microsoft.AspNetCore.Authorization;
  3. using Microsoft.AspNetCore.Mvc;
  4. using Microsoft.AspNetCore.Mvc.RazorPages;
  5. using Microsoft.EntityFrameworkCore;
  6. using Microsoft.Extensions.Logging;
  7. using ProductionLineMonitor.Application.Services.HomeService;
  8. using ProductionLineMonitor.Application.Services.HomeService.Dtos;
  9. using ProductionLineMonitor.Application.Services.HomeService.Models;
  10. using ProductionLineMonitor.Core.Dtos;
  11. using ProductionLineMonitor.Core.IRepositories;
  12. using ProductionLineMonitor.Core.Models;
  13. using ProductionLineMonitor.Core.Services;
  14. using ProductionLineMonitor.Core.Utils;
  15. using ProductionLineMonitor.Web.Services;
  16. using ProductionLineMonitor.Web.Services.LineService;
  17. using System;
  18. using System.Collections.Generic;
  19. using System.Diagnostics;
  20. using System.Linq;
  21. using System.Security.Cryptography.Xml;
  22. using System.Threading;
  23. using System.Threading.Tasks;
  24. namespace ProductionLineMonitor.Web.Controllers
  25. {
  26. public class HomeController : BaseController
  27. {
  28. private readonly IUnitOfWork _unitOfWork;
  29. private readonly IHomeService _homeService;
  30. public HomeController(IUnitOfWork unitOfWork, IHomeService homeService)
  31. {
  32. _unitOfWork = unitOfWork;
  33. _homeService = homeService;
  34. }
  35. [HttpGet]
  36. public IActionResult Index()
  37. {
  38. return View();
  39. }
  40. [HttpGet]
  41. public IActionResult GetModuleTypeOverview()
  42. {
  43. return Ok(_homeService.GetModuleTypeOverview());
  44. }
  45. [HttpGet]
  46. public IActionResult GetModuleTypeOverviewByMark(string mark, int year, int month)
  47. {
  48. return Ok(_homeService.GetModuleTypeOverview(mark, year, month));
  49. }
  50. [HttpPost("/Home/UpdateRemark")]
  51. public IActionResult UpdateRemark([FromBody] UpdateRemarkDto dto)
  52. {
  53. var monthModule = _homeService.GetMonthModuleTypes(dto.Year, dto.Month).FirstOrDefault(x => x.Id == dto.Id);
  54. if (monthModule == null)
  55. {
  56. return Ok(ResultDto<MonthModuleType>.Fail("月机种不存在"));
  57. }
  58. if (dto.Remark.Length > 300)
  59. {
  60. return Ok(ResultDto<MonthModuleType>.Fail("Remark长度不能超过300"));
  61. }
  62. MonthModuleTypeCreateAndUpdateDto monthModuleTypeCreateAndUpdateDto = new MonthModuleTypeCreateAndUpdateDto();
  63. monthModuleTypeCreateAndUpdateDto.Id = monthModule.Id;
  64. monthModuleTypeCreateAndUpdateDto.Year = monthModule.Year;
  65. monthModuleTypeCreateAndUpdateDto.Month = monthModule.Month;
  66. monthModuleTypeCreateAndUpdateDto.Mark = monthModule.Mark;
  67. monthModuleTypeCreateAndUpdateDto.PlanCapacity = monthModule.PlanCapacity;
  68. monthModuleTypeCreateAndUpdateDto.LastModuleCapacity = monthModule.LastModuleCapacity;
  69. monthModuleTypeCreateAndUpdateDto.ModuleType = monthModule.ModuleType;
  70. monthModuleTypeCreateAndUpdateDto.Remark = dto.Remark;
  71. _homeService.UpdateMonthModuleTypeV1(monthModuleTypeCreateAndUpdateDto);
  72. return Ok(ResultDto<MonthModuleType>.Success());
  73. }
  74. [HttpGet("/MonthModule")]
  75. public IActionResult GetMonthModule()
  76. {
  77. return View();
  78. }
  79. [HttpPost("/MonthModule/CreateMonthModuleType")]
  80. public IActionResult CreateMonthModuleType([FromBody]MonthModuleTypeCreateAndUpdateDto dto)
  81. {
  82. return Ok(_homeService.CreateMonthModuleTypeV1(dto));
  83. }
  84. [HttpPost("/MonthModule/UpdateMonthModuleType")]
  85. public IActionResult UpdateMonthModuleType([FromBody] MonthModuleTypeCreateAndUpdateDto dto)
  86. {
  87. return Ok(_homeService.UpdateMonthModuleTypeV1(dto));
  88. }
  89. [HttpPost("/MonthModule/DeleteMonthModuleType")]
  90. public IActionResult DeleteMonthModuleType([FromBody] MonthModuleTypeCreateAndUpdateDto dto)
  91. {
  92. return Ok(_homeService.DeleteMonthModuleType(dto));
  93. }
  94. [HttpGet("/MonthModule/GetMonthModuleTypes")]
  95. public IActionResult GetMonthModuleTypes(string mark, int year, int month)
  96. {
  97. return Ok(_homeService.GetMonthModuleTypesByMark(mark, year, month));
  98. }
  99. [HttpGet("/MonthModule/GetMonthModuleTypes/{id}")]
  100. public IActionResult GetMonthModuleTypesById([FromRoute] string id, int year, int month)
  101. {
  102. var monthModule = _homeService.GetMonthModuleTypes(year, month).FirstOrDefault(x => x.Id == id);
  103. if (monthModule == null)
  104. {
  105. return Ok(ResultDto<MonthModuleType>.Fail("月机种不存在"));
  106. }
  107. return Ok(ResultDto<MonthModuleType>.Success(monthModule));
  108. }
  109. [HttpGet("/MonthModule/Difference")]
  110. public IActionResult Difference()
  111. {
  112. return View();
  113. }
  114. [HttpGet("/MonthModule/Difference/MonthOverview")]
  115. public IActionResult Difference(
  116. string mark, int year, int month, string moduleType, string lines)
  117. {
  118. List<ProductionLine> lst = new List<ProductionLine>();
  119. if (!string.IsNullOrEmpty(lines))
  120. {
  121. IList<ProductionLine> temps = mark switch
  122. {
  123. "2F" => _unitOfWork.ProductionLineRepository.GetList(x => x.Floor == 2 && x.MakeClassification == "EPD").ToList(),
  124. "1F" => _unitOfWork.ProductionLineRepository.GetList(x => x.Floor == 1 && x.MakeClassification == "EPD").ToList(),
  125. "FPL" => _unitOfWork.ProductionLineRepository.GetList(x => x.Floor == 1 && x.MakeClassification == "FPL").ToList(),
  126. _ => new List<ProductionLine>(),
  127. };
  128. string[] ls = lines.Split(",");
  129. foreach (string line in ls)
  130. {
  131. lst.AddRange(temps.Where(x => x.Line.ToString() == line));
  132. }
  133. }
  134. var view = new MonthOverview(mark, year, month, moduleType, lst);
  135. return Ok(view);
  136. }
  137. [HttpGet("/v1/MonthModule/Difference")]
  138. public IActionResult DifferenceV1()
  139. {
  140. return View();
  141. }
  142. [HttpGet("/v1/MonthModule/Difference/MonthOverview")]
  143. public IActionResult DifferenceV1(
  144. string mark, int year, int month, string moduleType, string lines, string moduleTypes, int line)
  145. {
  146. List<ProductionLine> lst = new List<ProductionLine>();
  147. if (!string.IsNullOrEmpty(lines))
  148. {
  149. IList<ProductionLine> temps = mark switch
  150. {
  151. "2F" => _unitOfWork.ProductionLineRepository.GetList(x => x.Floor == 2 && x.MakeClassification == "EPD").ToList(),
  152. "1F" => _unitOfWork.ProductionLineRepository.GetList(x => x.Floor == 1 && x.MakeClassification == "EPD").ToList(),
  153. "FPL" => _unitOfWork.ProductionLineRepository.GetList(x => x.Floor == 1 && x.MakeClassification == "FPL").ToList(),
  154. _ => new List<ProductionLine>(),
  155. };
  156. string[] ls = lines.Split(",");
  157. foreach (string l in ls)
  158. {
  159. lst.AddRange(temps.Where(x => x.Line.ToString() == l));
  160. }
  161. }
  162. string[] ms = moduleTypes.Split(",");
  163. var view = new MonthOverview(year, month, moduleType, lst, ms, line);
  164. return Ok(view);
  165. }
  166. [HttpGet("/v1/MonthModule/Difference/Keyin")]
  167. public IActionResult DifferenceKeyin(
  168. string mark, int year, int month, string lines)
  169. {
  170. DateTime startTime = Convert.ToDateTime($"{year}-{month - 1}-21 08:00:00");
  171. DateTime endTime = Convert.ToDateTime($"{year}-{month}-21 08:00:00");
  172. int floor = -1;
  173. switch (mark)
  174. {
  175. case "2F":
  176. floor = 2;
  177. break;
  178. case "1F":
  179. floor = 1;
  180. break;
  181. default:
  182. break;
  183. }
  184. string[] ls = lines.Split(",");
  185. List<ProductionLineMonitor.Web.Services.LineService.KeyInInfo> lst
  186. = new List<ProductionLineMonitor.Web.Services.LineService.KeyInInfo>();
  187. foreach (var item in ls)
  188. {
  189. int line = Convert.ToInt32(item);
  190. lst.AddRange(MesApiService.GetAlarmByKeyIn(floor, line, startTime, endTime));
  191. }
  192. lst = lst.OrderByDescending(o => o.AffectTime).ToList();
  193. return Ok(lst);
  194. }
  195. [HttpGet("/Home/V1")]
  196. public IActionResult IndexV1()
  197. {
  198. //var outs = MesApiService.GetOutPutPerHours("AOIData#7#07-2AOI01", "2023-06-01", "2023-12-28");
  199. //int max = outs.Sum(x => x.OutPut);
  200. return View();
  201. }
  202. [HttpGet]
  203. public IActionResult GetModuleTypeOverviewByMarkV1(string mark, int year, int month)
  204. {
  205. if (mark == null)
  206. {
  207. return Ok();
  208. }
  209. return Ok(_homeService.GetModuleTypeOverviewV1(mark, year, month));
  210. }
  211. }
  212. }