using AutoMapper; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using ProductionLineMonitor.Application.Services.HomeService; using ProductionLineMonitor.Application.Services.HomeService.Dtos; using ProductionLineMonitor.Application.Services.HomeService.Models; using ProductionLineMonitor.Core.Dtos; using ProductionLineMonitor.Core.IRepositories; using ProductionLineMonitor.Core.Models; using ProductionLineMonitor.Core.Services; using ProductionLineMonitor.Core.Utils; using ProductionLineMonitor.Web.Services; using ProductionLineMonitor.Web.Services.LineService; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Security.Cryptography.Xml; using System.Threading; using System.Threading.Tasks; namespace ProductionLineMonitor.Web.Controllers { public class HomeController : BaseController { private readonly IUnitOfWork _unitOfWork; private readonly IHomeService _homeService; public HomeController(IUnitOfWork unitOfWork, IHomeService homeService) { _unitOfWork = unitOfWork; _homeService = homeService; } [HttpGet] public IActionResult Index() { return View(); } [HttpGet] public IActionResult GetModuleTypeOverview() { return Ok(_homeService.GetModuleTypeOverview()); } [HttpGet] public IActionResult GetModuleTypeOverviewByMark(string mark, int year, int month) { return Ok(_homeService.GetModuleTypeOverview(mark, year, month)); } [HttpPost("/Home/UpdateRemark")] public IActionResult UpdateRemark([FromBody] UpdateRemarkDto dto) { var monthModule = _homeService.GetMonthModuleTypes(dto.Year, dto.Month).FirstOrDefault(x => x.Id == dto.Id); if (monthModule == null) { return Ok(ResultDto.Fail("月机种不存在")); } if (dto.Remark.Length > 300) { return Ok(ResultDto.Fail("Remark长度不能超过300")); } MonthModuleTypeCreateAndUpdateDto monthModuleTypeCreateAndUpdateDto = new MonthModuleTypeCreateAndUpdateDto(); monthModuleTypeCreateAndUpdateDto.Id = monthModule.Id; monthModuleTypeCreateAndUpdateDto.Year = monthModule.Year; monthModuleTypeCreateAndUpdateDto.Month = monthModule.Month; monthModuleTypeCreateAndUpdateDto.Mark = monthModule.Mark; monthModuleTypeCreateAndUpdateDto.PlanCapacity = monthModule.PlanCapacity; monthModuleTypeCreateAndUpdateDto.LastModuleCapacity = monthModule.LastModuleCapacity; monthModuleTypeCreateAndUpdateDto.ModuleType = monthModule.ModuleType; monthModuleTypeCreateAndUpdateDto.Remark = dto.Remark; _homeService.UpdateMonthModuleTypeV1(monthModuleTypeCreateAndUpdateDto); return Ok(ResultDto.Success()); } [HttpGet("/MonthModule")] public IActionResult GetMonthModule() { return View(); } [HttpPost("/MonthModule/CreateMonthModuleType")] public IActionResult CreateMonthModuleType([FromBody]MonthModuleTypeCreateAndUpdateDto dto) { return Ok(_homeService.CreateMonthModuleTypeV1(dto)); } [HttpPost("/MonthModule/UpdateMonthModuleType")] public IActionResult UpdateMonthModuleType([FromBody] MonthModuleTypeCreateAndUpdateDto dto) { return Ok(_homeService.UpdateMonthModuleTypeV1(dto)); } [HttpPost("/MonthModule/DeleteMonthModuleType")] public IActionResult DeleteMonthModuleType([FromBody] MonthModuleTypeCreateAndUpdateDto dto) { return Ok(_homeService.DeleteMonthModuleType(dto)); } [HttpGet("/MonthModule/GetMonthModuleTypes")] public IActionResult GetMonthModuleTypes(string mark, int year, int month) { return Ok(_homeService.GetMonthModuleTypesByMark(mark, year, month)); } [HttpGet("/MonthModule/GetMonthModuleTypes/{id}")] public IActionResult GetMonthModuleTypesById([FromRoute] string id, int year, int month) { var monthModule = _homeService.GetMonthModuleTypes(year, month).FirstOrDefault(x => x.Id == id); if (monthModule == null) { return Ok(ResultDto.Fail("月机种不存在")); } return Ok(ResultDto.Success(monthModule)); } [HttpGet("/MonthModule/Difference")] public IActionResult Difference() { return View(); } [HttpGet("/MonthModule/Difference/MonthOverview")] public IActionResult Difference( string mark, int year, int month, string moduleType, string lines) { List lst = new List(); if (!string.IsNullOrEmpty(lines)) { IList temps = mark switch { "2F" => _unitOfWork.ProductionLineRepository.GetList(x => x.Floor == 2 && x.MakeClassification == "EPD").ToList(), "1F" => _unitOfWork.ProductionLineRepository.GetList(x => x.Floor == 1 && x.MakeClassification == "EPD").ToList(), "FPL" => _unitOfWork.ProductionLineRepository.GetList(x => x.Floor == 1 && x.MakeClassification == "FPL").ToList(), _ => new List(), }; string[] ls = lines.Split(","); foreach (string line in ls) { lst.AddRange(temps.Where(x => x.Line.ToString() == line)); } } var view = new MonthOverview(mark, year, month, moduleType, lst); return Ok(view); } [HttpGet("/v1/MonthModule/Difference")] public IActionResult DifferenceV1() { return View(); } [HttpGet("/v1/MonthModule/Difference/MonthOverview")] public IActionResult DifferenceV1( string mark, int year, int month, string moduleType, string lines, string moduleTypes, int line) { List lst = new List(); if (!string.IsNullOrEmpty(lines)) { IList temps = mark switch { "2F" => _unitOfWork.ProductionLineRepository.GetList(x => x.Floor == 2 && x.MakeClassification == "EPD").ToList(), "1F" => _unitOfWork.ProductionLineRepository.GetList(x => x.Floor == 1 && x.MakeClassification == "EPD").ToList(), "FPL" => _unitOfWork.ProductionLineRepository.GetList(x => x.Floor == 1 && x.MakeClassification == "FPL").ToList(), _ => new List(), }; string[] ls = lines.Split(","); foreach (string l in ls) { lst.AddRange(temps.Where(x => x.Line.ToString() == l)); } } string[] ms = moduleTypes.Split(","); var view = new MonthOverview(year, month, moduleType, lst, ms, line); return Ok(view); } [HttpGet("/v1/MonthModule/Difference/Keyin")] public IActionResult DifferenceKeyin( string mark, int year, int month, string lines) { DateTime startTime = Convert.ToDateTime($"{year}-{month - 1}-21 08:00:00"); DateTime endTime = Convert.ToDateTime($"{year}-{month}-21 08:00:00"); int floor = -1; switch (mark) { case "2F": floor = 2; break; case "1F": floor = 1; break; default: break; } string[] ls = lines.Split(","); List lst = new List(); foreach (var item in ls) { int line = Convert.ToInt32(item); lst.AddRange(MesApiService.GetAlarmByKeyIn(floor, line, startTime, endTime)); } lst = lst.OrderByDescending(o => o.AffectTime).ToList(); return Ok(lst); } [HttpGet("/Home/V1")] public IActionResult IndexV1() { //var outs = MesApiService.GetOutPutPerHours("AOIData#7#07-2AOI01", "2023-06-01", "2023-12-28"); //int max = outs.Sum(x => x.OutPut); return View(); } [HttpGet] public IActionResult GetModuleTypeOverviewByMarkV1(string mark, int year, int month) { if (mark == null) { return Ok(); } return Ok(_homeService.GetModuleTypeOverviewV1(mark, year, month)); } } }