131 lines
5.4 KiB
C#
131 lines
5.4 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using ReportingServices.Dependency_Injections;
|
|
using ReportingServices.HelperClasses;
|
|
using ReportingServices.Models.ProductionReport;
|
|
using ReportingServices.ReportingObjects;
|
|
using System.Text.Json;
|
|
using System.Text.Json.Nodes;
|
|
using System.Web;
|
|
|
|
namespace ReportingServices.Controllers
|
|
{
|
|
public class ProductionReportController : Controller
|
|
{
|
|
private readonly IJsonFileHandler _jsonFileHandler;
|
|
private readonly IScrapeDatabaseRepository _scrapeDatabaseRepository;
|
|
private readonly IFabTimeReportingRepository _fabTimeReportingRepository;
|
|
private readonly int _reportIndex = (int)DateTime.Now.DayOfWeek;
|
|
private readonly string _dailyRptFileName = "wwwroot/Assets/DailyReportInfo.json";
|
|
private readonly string _toolFilter = "~R76%2C%20~R78%2C%20~R25%2C%20~R67%2C%20~R69%2C%20~R71%2C%20~R47%2C%20~R51%2C%20~R28";
|
|
|
|
public ProductionReportController(IJsonFileHandler jsonFileHandler, IScrapeDatabaseRepository scrapeDatabaseRepository, IFabTimeReportingRepository fabTimeReportingRepository)
|
|
{
|
|
_jsonFileHandler = jsonFileHandler;
|
|
_scrapeDatabaseRepository = scrapeDatabaseRepository;
|
|
_fabTimeReportingRepository = fabTimeReportingRepository;
|
|
}
|
|
|
|
|
|
public IActionResult Index()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
public IActionResult DailyReport()
|
|
{
|
|
DailyReport dailyReport = SetUpDailyReport();
|
|
|
|
return View(dailyReport);
|
|
}
|
|
|
|
public IActionResult EditDailyReport()
|
|
{
|
|
JsonNode node = _jsonFileHandler.LoadJSONFile<JsonNode>(_dailyRptFileName);
|
|
|
|
ManualReportEntries rpt = JsonSerializer.Deserialize<ManualReportEntries>(node[(int)DateTime.Now.DayOfWeek]["Entries"]);
|
|
|
|
return View(rpt);
|
|
}
|
|
|
|
[HttpPost]
|
|
public IActionResult EditDailyReport(ManualReportEntries rpt)
|
|
{
|
|
List<ManualReportEntriesByDay> report = _jsonFileHandler.LoadJSONFile<List<ManualReportEntriesByDay>>(_dailyRptFileName);
|
|
|
|
report[_reportIndex].Entries = rpt;
|
|
|
|
_jsonFileHandler.SaveJSONFile(report, _dailyRptFileName);
|
|
|
|
return RedirectToAction("DailyReport");
|
|
}
|
|
|
|
public async Task<List<ReactorOutsByRDS>> MovesTrendCaller()
|
|
{
|
|
string url = APIHelperFunctions.GenerateURLWithParameters(chart: "MOVESLOTLIST", areasLike: "CLEANROOM", operationsLike: "1UNLOAD");
|
|
|
|
List<ReactorOutsByRDS> outsByRDS = await _fabTimeReportingRepository.GetMovesTrendData(url);
|
|
|
|
return outsByRDS;
|
|
}
|
|
|
|
public async Task<List<EquipmentStateByDay>> ToolStateTrendCaller(string toolType)
|
|
{
|
|
string url = APIHelperFunctions.GenerateURLWithParameters(chart: "TOOLSTATE", periodLen: "24", capacityTypesLike: toolType, toolsLike: _toolFilter);
|
|
|
|
List<EquipmentStateByDay> toolAvailability = await _fabTimeReportingRepository.GetToolStateTrendData(url);
|
|
|
|
return toolAvailability;
|
|
}
|
|
|
|
public async Task<List<ToolStateCurrent>> ToolStatesCaller(string toolType)
|
|
{
|
|
string capacityFilter = toolType == "ASM" ? toolType + "%2CASM%2B" : toolType;
|
|
string startDate = HttpUtility.UrlEncode(APIHelperFunctions.GetDateWithOffsetAsAPIString(DateTime.Now.ToString(), 12.5f));
|
|
|
|
string url = APIHelperFunctions.GenerateURLWithParameters(chart: "ToolStateGantt", periodLen: "24",
|
|
capacityTypesLike: capacityFilter, toolsLike: _toolFilter, startDate: startDate);
|
|
|
|
List<ToolStateCurrent> toolStates = await _fabTimeReportingRepository.GetToolStateData(url);
|
|
|
|
return toolStates;
|
|
}
|
|
|
|
public DailyReport SetUpDailyReport()
|
|
{
|
|
DailyReport report = new();
|
|
|
|
Task<List<ReactorOutsByRDS>> task1 = MovesTrendCaller();
|
|
Task<List<EquipmentStateByDay>> task2 = ToolStateTrendCaller("ASM");
|
|
Task<List<EquipmentStateByDay>> task3 = ToolStateTrendCaller("EPP");
|
|
Task<List<EquipmentStateByDay>> task4 = ToolStateTrendCaller("HTR");
|
|
Task<List<ToolStateCurrent>> task5 = ToolStatesCaller("ASM");
|
|
Task<List<ToolStateCurrent>> task6 = ToolStatesCaller("EPP");
|
|
Task<List<ToolStateCurrent>> task7 = ToolStatesCaller("HTR");
|
|
|
|
report.SetOutsByDay(task1.Result);
|
|
|
|
List<ScrapByDay> scrap = _scrapeDatabaseRepository.GetScrapByDay(task1.Result);
|
|
|
|
report.SetScrapByDay(scrap);
|
|
report.AddToolAvailibilityByType("ASM", task2.Result);
|
|
report.AddToolAvailibilityByType("EPP", task3.Result);
|
|
report.AddToolAvailibilityByType("HTR", task4.Result);
|
|
report.AddToolStateByType("ASM", task5.Result);
|
|
report.AddToolStateByType("EPP", task6.Result);
|
|
report.AddToolStateByType("HTR", task7.Result);
|
|
report.ReverseLists();
|
|
|
|
List<ManualReportEntriesByDay> entries = _jsonFileHandler.LoadJSONFile<List<ManualReportEntriesByDay>>(_dailyRptFileName);
|
|
|
|
report.Entries = entries;
|
|
|
|
int[] singleLoadLocks = _scrapeDatabaseRepository.GetNumberOfSingleLoadLocks();
|
|
|
|
report.Entries[_reportIndex].Entries.SingleLoadLockASM = singleLoadLocks[0];
|
|
report.Entries[_reportIndex].Entries.SingleLoadLockHTR = singleLoadLocks[1];
|
|
|
|
return report;
|
|
}
|
|
}
|
|
}
|