123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- 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<MonthModuleType>.Fail("月机种不存在"));
- }
- if (dto.Remark.Length > 300)
- {
- return Ok(ResultDto<MonthModuleType>.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<MonthModuleType>.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<MonthModuleType>.Fail("月机种不存在"));
- }
- return Ok(ResultDto<MonthModuleType>.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<ProductionLine> lst = new List<ProductionLine>();
- if (!string.IsNullOrEmpty(lines))
- {
- IList<ProductionLine> 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<ProductionLine>(),
- };
- 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<ProductionLine> lst = new List<ProductionLine>();
- if (!string.IsNullOrEmpty(lines))
- {
- IList<ProductionLine> 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<ProductionLine>(),
- };
- 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<ProductionLineMonitor.Web.Services.LineService.KeyInInfo> lst
- = new List<ProductionLineMonitor.Web.Services.LineService.KeyInInfo>();
- 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));
- }
- }
- }
|