343 lines
13 KiB
C#
343 lines
13 KiB
C#
using CMS_CORE_Library.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web.Http;
|
|
using Thermo.Active.Model.DTOModels.ThProd;
|
|
using Thermo.Active.NC;
|
|
using Thermo.Active.Utils;
|
|
using static Thermo.Active.Model.Constants;
|
|
|
|
namespace Thermo.Active.Controllers.WebApi
|
|
{
|
|
[RoutePrefix("api/prod")]
|
|
public class ProdController : aBaseApiController //ApiController
|
|
{
|
|
#if false
|
|
/// <summary>
|
|
/// Oggetto adapter condiviso da WebAPI
|
|
/// </summary>
|
|
protected static NcAdapter ncAdapter = new NcAdapter();
|
|
|
|
#endif
|
|
|
|
/// <summary>
|
|
/// Request mode SETUP
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[Route("mode/manual"), HttpPut]
|
|
[WebApiAuthorize(FunctionAccess = FUNCTIONALITY_NAMES.RECIPE_MANAGER, Action = ACTIONS.READ)]
|
|
public IHttpActionResult RequestManual()
|
|
{
|
|
// Try connection
|
|
CmsError libraryError = ncAdapter.Connect();
|
|
if (libraryError.IsError())
|
|
{
|
|
ThermoActiveLogger.LogError($"NC Not connected! | RequestManual | {libraryError.exception}");
|
|
return BadRequest(libraryError.localizationKey);
|
|
}
|
|
|
|
// scrivo sul PLC il comando strobe richiesta AUTO!
|
|
libraryError = ncAdapter.StrobeMode(Model.DTOModels.ThProd.Mode.MANUAL);
|
|
if (libraryError.IsError())
|
|
{
|
|
ThermoActiveLogger.LogError($"RequestManual error | {libraryError.exception}");
|
|
return BadRequest(libraryError.localizationKey);
|
|
}
|
|
|
|
// ritorno solo fatto!
|
|
return Ok();
|
|
}
|
|
#if true
|
|
/// <summary>
|
|
/// Request mode AUTO
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[Route("mode/auto"), HttpPut]
|
|
[WebApiAuthorize(FunctionAccess = FUNCTIONALITY_NAMES.RECIPE_MANAGER, Action = ACTIONS.READ)]
|
|
public IHttpActionResult RequestAuto()
|
|
{
|
|
// Try connection
|
|
CmsError libraryError = ncAdapter.Connect();
|
|
if (libraryError.IsError())
|
|
{
|
|
ThermoActiveLogger.LogError($"NC Not connected! | RequestAuto | {libraryError.exception}");
|
|
return BadRequest(libraryError.localizationKey);
|
|
}
|
|
|
|
// scrivo sul PLC il comando strobe richiesta AUTO!
|
|
libraryError = ncAdapter.StrobeMode(Model.DTOModels.ThProd.Mode.AUTO);
|
|
if (libraryError.IsError())
|
|
{
|
|
ThermoActiveLogger.LogError($"RequestAuto error | {libraryError.exception}");
|
|
return BadRequest(libraryError.localizationKey);
|
|
}
|
|
|
|
// ritorno solo fatto!
|
|
return Ok();
|
|
}
|
|
#endif
|
|
/// <summary>
|
|
/// Request mode SETUP
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[Route("mode/setup"), HttpPut]
|
|
[WebApiAuthorize(FunctionAccess = FUNCTIONALITY_NAMES.RECIPE_MANAGER, Action = ACTIONS.READ)]
|
|
public IHttpActionResult RequestSetup()
|
|
{
|
|
// Try connection
|
|
CmsError libraryError = ncAdapter.Connect();
|
|
if (libraryError.IsError())
|
|
{
|
|
ThermoActiveLogger.LogError($"NC Not connected! | RequestSetup | {libraryError.exception}");
|
|
return BadRequest(libraryError.localizationKey);
|
|
}
|
|
|
|
// scrivo sul PLC il comando strobe richiesta AUTO!
|
|
libraryError = ncAdapter.StrobeMode(Model.DTOModels.ThProd.Mode.SETUP);
|
|
if (libraryError.IsError())
|
|
{
|
|
ThermoActiveLogger.LogError($"RequestSetup error | {libraryError.exception}");
|
|
return BadRequest(libraryError.localizationKey);
|
|
}
|
|
|
|
// ritorno solo fatto!
|
|
return Ok();
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Set item as scrap
|
|
/// </summary>
|
|
/// <param name="num">item NUM</param>
|
|
/// <param name="isScrap">scrap flag (true/false)</param>
|
|
/// <returns></returns>
|
|
[Route("setScrap"), HttpPut]
|
|
[WebApiAuthorize(FunctionAccess = FUNCTIONALITY_NAMES.RECIPE_MANAGER, Action = ACTIONS.READ)]
|
|
public IHttpActionResult SetScrap(int num, bool isScrap)
|
|
{
|
|
// Try connection
|
|
CmsError libraryError = ncAdapter.Connect();
|
|
if (libraryError.IsError())
|
|
{
|
|
ThermoActiveLogger.LogError($"NC Not connected! | SetScrap | {libraryError.exception}");
|
|
return BadRequest(libraryError.localizationKey);
|
|
}
|
|
|
|
// scrivo sul DB che il pezzo è SCRAPPED
|
|
libraryError = ncAdapter.SetScrap(num, isScrap);
|
|
if (libraryError.IsError())
|
|
{
|
|
ThermoActiveLogger.LogError($"SetScrap error | {libraryError.exception}");
|
|
return BadRequest(libraryError.localizationKey);
|
|
}
|
|
|
|
// ritorno solo fatto!
|
|
return Ok();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Request start production
|
|
/// </summary>
|
|
/// <param name="requestQty">item NUM</param>
|
|
/// <param name="newWorkOrder">scrap flag (true/false)</param>
|
|
/// <returns></returns>
|
|
[Route("start"), HttpPut]
|
|
[WebApiAuthorize(FunctionAccess = FUNCTIONALITY_NAMES.RECIPE_MANAGER, Action = ACTIONS.READ)]
|
|
public IHttpActionResult StartProd(int requestQty, bool newWorkOrder)
|
|
{
|
|
// Try connection
|
|
CmsError libraryError = ncAdapter.Connect();
|
|
if (libraryError.IsError())
|
|
{
|
|
ThermoActiveLogger.LogError($"NC Not connected! | StartProd | {libraryError.exception}");
|
|
return BadRequest(libraryError.localizationKey);
|
|
}
|
|
|
|
// legacy method
|
|
short numCicliRisc = 0;
|
|
|
|
// scrivo sul PLC pezzi richiesti, cicli riscaldo + comando strobe reset se encessario!
|
|
libraryError = ncAdapter.UpdateProdInfoData((short)requestQty, newWorkOrder, numCicliRisc);
|
|
if (libraryError.IsError())
|
|
{
|
|
ThermoActiveLogger.LogError($"StartProd error | {libraryError.exception}");
|
|
return BadRequest(libraryError.localizationKey);
|
|
}
|
|
// se new workorder --> registro nuova data x start lotto!
|
|
if (newWorkOrder)
|
|
{
|
|
ncAdapter.lottoStart = DateTime.Now;
|
|
}
|
|
|
|
// scrivo sul PLC il comando strobe richiesta AUTO!
|
|
libraryError = ncAdapter.StrobeMode(Mode.AUTO);
|
|
if (libraryError.IsError())
|
|
{
|
|
ThermoActiveLogger.LogError($"RequestAuto error | {libraryError.exception}");
|
|
return BadRequest(libraryError.localizationKey);
|
|
}
|
|
|
|
// ritorno solo fatto!
|
|
return Ok();
|
|
}
|
|
/// <summary>
|
|
/// Request start production
|
|
/// </summary>
|
|
/// <param name="requestQty">item NUM</param>
|
|
/// <param name="newWorkOrder">scrap flag (true/false)</param>
|
|
/// <param name="numCicliRisc">warmup cycle requested (0=none)</param>
|
|
/// <returns></returns>
|
|
[Route("startFull"), HttpPut]
|
|
[WebApiAuthorize(FunctionAccess = FUNCTIONALITY_NAMES.RECIPE_MANAGER, Action = ACTIONS.READ)]
|
|
public IHttpActionResult StartProdFull(int requestQty, bool newWorkOrder, int numCicliRisc)
|
|
{
|
|
// Try connection
|
|
CmsError libraryError = ncAdapter.Connect();
|
|
if (libraryError.IsError())
|
|
{
|
|
ThermoActiveLogger.LogError($"NC Not connected! | StartProd | {libraryError.exception}");
|
|
return BadRequest(libraryError.localizationKey);
|
|
}
|
|
|
|
// scrivo sul PLC pezzi richiesti, cicli riscaldo + comando strobe reset se encessario!
|
|
libraryError = ncAdapter.UpdateProdInfoData((short)requestQty, newWorkOrder, (short)numCicliRisc);
|
|
if (libraryError.IsError())
|
|
{
|
|
ThermoActiveLogger.LogError($"StartProd error | {libraryError.exception}");
|
|
return BadRequest(libraryError.localizationKey);
|
|
}
|
|
// se new workorder --> registro nuova data x start lotto!
|
|
if (newWorkOrder)
|
|
{
|
|
ncAdapter.lottoStart = DateTime.Now;
|
|
}
|
|
|
|
// scrivo sul PLC il comando strobe richiesta AUTO!
|
|
libraryError = ncAdapter.StrobeMode(Mode.AUTO);
|
|
if (libraryError.IsError())
|
|
{
|
|
ThermoActiveLogger.LogError($"RequestAuto error | {libraryError.exception}");
|
|
return BadRequest(libraryError.localizationKey);
|
|
}
|
|
|
|
// ritorno solo fatto!
|
|
return Ok();
|
|
}
|
|
/// <summary>
|
|
/// Request production current data
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[Route("get"), HttpGet]
|
|
public IHttpActionResult GetProd()
|
|
{
|
|
// Try connection
|
|
CmsError libraryError = ncAdapter.Connect();
|
|
if (libraryError.IsError())
|
|
{
|
|
ThermoActiveLogger.LogError($"NC Not connected! | GetProd | {libraryError.exception}");
|
|
return BadRequest(libraryError.localizationKey);
|
|
}
|
|
|
|
// scrivo sul PLC il comando strobe richiesta AUTO!
|
|
libraryError = ncAdapter.ReadProdInfoData(out DTOProdInfo prodInfoDat);
|
|
if (libraryError.IsError())
|
|
{
|
|
ThermoActiveLogger.LogError($"GetProd error | {libraryError.exception}");
|
|
return BadRequest(libraryError.localizationKey);
|
|
}
|
|
|
|
// ritorno solo fatto!
|
|
return Ok(prodInfoDat);
|
|
}
|
|
/// <summary>
|
|
/// Request gauges current data
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[Route("gauges"), HttpGet]
|
|
public IHttpActionResult GetGauges()
|
|
{
|
|
// Try connection
|
|
CmsError libraryError = ncAdapter.Connect();
|
|
if (libraryError.IsError())
|
|
{
|
|
ThermoActiveLogger.LogError($"NC Not connected! | GetGauges | {libraryError.exception}");
|
|
return BadRequest(libraryError.localizationKey);
|
|
}
|
|
|
|
// leggo dati gauges
|
|
libraryError = ncAdapter.ReadGaugeData(out Dictionary<string, DTOThermoProd> currentLiveProd);
|
|
if (libraryError.IsError())
|
|
{
|
|
ThermoActiveLogger.LogError($"GetGauges error | {libraryError.exception}");
|
|
return BadRequest(libraryError.localizationKey);
|
|
}
|
|
|
|
// ritorno solo fatto!
|
|
return Ok(currentLiveProd);
|
|
}
|
|
/// <summary>
|
|
/// Request production data from indexStart record for numRecord items (DESCENDING)
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[Route("history"), HttpGet]
|
|
public IHttpActionResult GetHistory(int indexStart, int numRecord)
|
|
{
|
|
List<DTOProdInfo> prodInfoDTO = new List<DTOProdInfo>();
|
|
// SOLO SE indice > 0
|
|
if (indexStart >= 0)
|
|
{
|
|
// Try connection
|
|
CmsError libraryError = ncAdapter.Connect();
|
|
if (libraryError.IsError())
|
|
{
|
|
ThermoActiveLogger.LogError($"NC Not connected! | GetHistory | {libraryError.exception}");
|
|
return BadRequest(libraryError.localizationKey);
|
|
}
|
|
|
|
// recupero da DB i record richiesti
|
|
libraryError = ncAdapter.GetHistProdInfoDataDesc(out List<ThermoModels.ProdInfoModel> prodInfoDataList, indexStart, numRecord);
|
|
|
|
if (libraryError.IsError())
|
|
{
|
|
ThermoActiveLogger.LogError($"GetHistory error | {libraryError.exception}");
|
|
return BadRequest(libraryError.localizationKey);
|
|
}
|
|
|
|
// converto da datiPLC a DTOProdInfo...
|
|
foreach (var item in prodInfoDataList)
|
|
{
|
|
prodInfoDTO.Add(new DTOProdInfo(item));
|
|
}
|
|
}
|
|
// ritorno solo fatto!
|
|
return Ok(prodInfoDTO);
|
|
}
|
|
/// <summary>
|
|
/// Request Prod Panel data
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[Route("prodPanel"), HttpGet]
|
|
public IHttpActionResult GetProdPanel()
|
|
{
|
|
// Try connection
|
|
CmsError libraryError = ncAdapter.Connect();
|
|
if (libraryError.IsError())
|
|
{
|
|
ThermoActiveLogger.LogError($"NC Not connected! | GetProdPanel | {libraryError.exception}");
|
|
return BadRequest(libraryError.localizationKey);
|
|
}
|
|
|
|
// recupero dati produzione
|
|
libraryError = ncAdapter.ReadProdPanel(out DTOThermoPanelProd currentProdPanel);
|
|
if (libraryError.IsError())
|
|
{
|
|
ThermoActiveLogger.LogError($"GetProdPanel error | {libraryError.exception}");
|
|
return BadRequest(libraryError.localizationKey);
|
|
}
|
|
|
|
// ritorno solo fatto!
|
|
return Ok(currentProdPanel);
|
|
}
|
|
}
|
|
} |