344 lines
14 KiB
C#
344 lines
14 KiB
C#
using AppData;
|
|
using Newtonsoft.Json;
|
|
using NKC_SDK;
|
|
using SteamWare;
|
|
using System;
|
|
using System.IO;
|
|
using System.Web.Http;
|
|
|
|
namespace NKC_WF.Controllers
|
|
{
|
|
public class SheetController : ApiController
|
|
{
|
|
#region Public Constructors
|
|
|
|
public SheetController()
|
|
{
|
|
dfWrkStart = memLayer.ML.CRB("dateFix_WrkStart");
|
|
dfWrkEnd = memLayer.ML.CRB("dateFix_WrkEnd");
|
|
dfUnlStart = memLayer.ML.CRB("dateFix_UnlStart");
|
|
dfUnlEnd = memLayer.ML.CRB("dateFix_UnlEnd");
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// Restituisce un array di sheet da lavorare (quindi NON ancora scaricati, anche di + BUNK)
|
|
/// GET: api/Sheet
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public SheetWorkList Get()
|
|
{
|
|
// fisso su macchina 0 (NON esistente)
|
|
string machineName = "NE00";
|
|
SheetWorkList answ = null;
|
|
try
|
|
{
|
|
answ = ComLib.prodGetSheetWorkList(machineName);
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Instance.Error($"EXCEPTION api/Sheet | get{Environment.NewLine}{exc}");
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ottengo elenco specifico dato cod MACCHINA (es NE01)
|
|
/// GET: api/Sheet/NE01
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public SheetWorkList Get(string id)
|
|
{
|
|
SheetWorkList answ = null;
|
|
try
|
|
{
|
|
answ = ComLib.prodGetSheetWorkList(id);
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Instance.Error($"EXCEPTION api/Sheet | get({id}){Environment.NewLine}{exc}");
|
|
}
|
|
Log.Instance.Trace($"api/Sheet | get({id}) | answ: {answ}");
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Processa una chiamata POST per l'invio in blocco status BUNK
|
|
/// POST: api/Bunk
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public string Post()
|
|
{
|
|
int BunkId = 0;
|
|
int BatchId = 0;
|
|
string answ = "";
|
|
// questa classe è derivata da Controller.Response... x cui recupero lo stream in altro modo...
|
|
string content = "";
|
|
System.Web.HttpContext.Current.Request.InputStream.Position = 0;
|
|
using (var reader = new StreamReader(System.Web.HttpContext.Current.Request.InputStream, System.Text.Encoding.UTF8, true, 4096, true))
|
|
{
|
|
content = reader.ReadToEnd();
|
|
}
|
|
//Rest
|
|
System.Web.HttpContext.Current.Request.InputStream.Position = 0;
|
|
// procedo a deserializzare in blocco l'oggetto...
|
|
try
|
|
{
|
|
// deserializzo.
|
|
SheetWorkList sheetUpdated = JsonConvert.DeserializeObject<SheetWorkList>(content);
|
|
if (sheetUpdated != null)
|
|
{
|
|
// 2020.01.16 salvo su mongoDb la risposta...
|
|
ComLib.man.saveProdAnsw(sheetUpdated);
|
|
|
|
if (sheetUpdated.SheetList != null)
|
|
{
|
|
// salvo macchina
|
|
machine = sheetUpdated.Machine;
|
|
foreach (var currSheet in sheetUpdated.SheetList)
|
|
{
|
|
// se non nullo...
|
|
if (currSheet != null)
|
|
{
|
|
// verifico il fixSheet
|
|
ProdSheetExt fixSheet = checkFixSheet(currSheet);
|
|
DLMan.taSHL.updateDate(fixSheet.SheetId, fixSheet.Printing.DtStart, fixSheet.Printing.DtEnd, fixSheet.Machining.DtStart, fixSheet.Machining.DtEnd, fixSheet.Unloading.DtStart, fixSheet.Unloading.DtEnd, (int)fixSheet.Status);
|
|
// SE machining completato --> status a LAVORATO x item!
|
|
if (fixSheet.Machining.DtEnd != null)
|
|
{
|
|
// hard coded su multiax
|
|
DLMan.taIL.updateSheetStatus(fixSheet.SheetId, 1, sheetUpdated.Machine);
|
|
}
|
|
// segnalo avanzamento su redis x pagina unload
|
|
ComLib.advaceSheetRevByBunk(fixSheet.BunkId);
|
|
BunkId = fixSheet.BunkId;
|
|
answ = "OK";
|
|
}
|
|
}
|
|
}
|
|
var tabBunks = DLMan.taSTL.getByKey(BunkId);
|
|
if (tabBunks.Count > 0)
|
|
{
|
|
BatchId = tabBunks[0].BatchID;
|
|
}
|
|
// ricalcolo stato BUNK
|
|
ComLib.updateBatchPosition(BatchId);
|
|
// INVALIDO eventuale valore BUNK in REDIS...
|
|
ComLib.resetRedisBunkData(machine);
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
answ = "NO";
|
|
}
|
|
Log.Instance.Trace($"api/Sheet | post() | machine: {machine} | BatchId: {BatchId} | answ: {answ}");
|
|
return answ;
|
|
}
|
|
|
|
/// <summary> Effettua la chiamata di update x SINGOLO foglio
|
|
///
|
|
///
|
|
/// *********************************** METODI PUT
|
|
///
|
|
/// per abilitare è necessario agire sulla conf di IIS:
|
|
///
|
|
/// - modificare il file applicationHost.config che si trova in C:\Windows\System32\inetsrv\config
|
|
/// - disinstallare webDav oppure commentare le righe <!-- <add name="WebDAVModule" /> -->
|
|
/// <!-- <add name="WebDAVModule" image="%windir%\System32\inetsrv\webdav.dll" /> --> <!--
|
|
/// <add name="WebDAV" path="*"
|
|
/// verb="PROPFIND,PROPPATCH,MKCOL,PUT,COPY,DELETE,MOVE,LOCK,UNLOCK" modules="WebDAVModule"
|
|
/// /r esourceType="Unspecified"// requireAccess="None" /> -->
|
|
/// - aggiungere PUT/DELETE a handler: <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit"
|
|
/// path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE" modules="IsapiModule"
|
|
/// scriptProcessor="%w indir/%//\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll"
|
|
/// preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" /> <add
|
|
/// name="ExtensionlessUrlHandler-Integrated-4.0" path="*."
|
|
/// verb="GET,HEAD,POST,DEBUG,PUT,DELETE" ///t
|
|
/// ype="System.Web.Handlers.TransferRequestHandler"
|
|
/// preCondition="integratedMode,runtimeVersionv4.0" responseBufferLimit="0" />
|
|
///
|
|
/// *************************************/ </summary> <param name="sheetUpdated">Oggetto con
|
|
/// Elenco fogli da aggiornare</param>
|
|
/// PUT: api/Sheet/machine_ID
|
|
[HttpPut]
|
|
public void Put(SheetWorkList sheetUpdated)
|
|
{
|
|
// NB. decodifico direttamente come oggetto, vedere qui:
|
|
// https://weblog.west-wind.com/posts/2013/dec/13/accepting-raw-request-body-content-with-aspnet-web-api https://weblog.west-wind.com/posts/2017/sep/14/accepting-raw-request-body-content-in-aspnet-core-api-controllers
|
|
int BunkId = 0;
|
|
int BatchId = 0;
|
|
if (sheetUpdated != null)
|
|
{
|
|
// 2020.01.16 salvo su mongoDb la risposta...
|
|
ComLib.man.saveProdAnsw(sheetUpdated);
|
|
|
|
if (sheetUpdated.SheetList != null)
|
|
{
|
|
foreach (var currSheet in sheetUpdated.SheetList)
|
|
{
|
|
// se non nullo...
|
|
if (currSheet != null)
|
|
{
|
|
DLMan.taSHL.updateDate(currSheet.SheetId, currSheet.Printing.DtStart, currSheet.Printing.DtEnd, currSheet.Machining.DtStart, currSheet.Machining.DtEnd, currSheet.Unloading.DtStart, currSheet.Unloading.DtEnd, (int)currSheet.Status);
|
|
// SE machining completato --> status a LAVORATO!
|
|
if (currSheet.Machining.DtEnd != null)
|
|
{
|
|
// hard coded su multiax
|
|
DLMan.taIL.updateSheetStatus(currSheet.SheetId, 1, sheetUpdated.Machine);
|
|
}
|
|
// segnalo avanzamento su redis x pagina unload
|
|
ComLib.advaceSheetRevByBunk(currSheet.BunkId);
|
|
// calcolo Batch
|
|
BunkId = currSheet.BunkId;
|
|
}
|
|
}
|
|
var tabBunks = DLMan.taSTL.getByKey(BunkId);
|
|
if (tabBunks.Count > 0)
|
|
{
|
|
BatchId = tabBunks[0].BatchID;
|
|
}
|
|
}
|
|
// ricalcolo stato BUNK
|
|
ComLib.updateBatchPosition(BatchId);
|
|
// INVALIDO eventuale valore BUNK in REDIS...
|
|
ComLib.resetRedisBunkData(sheetUpdated.Machine);
|
|
}
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Fields
|
|
|
|
/// <summary>
|
|
/// oggetto static/singleton per fare chiamate sul datalayer
|
|
/// </summary>
|
|
protected DataLayer DLMan = new DataLayer();
|
|
|
|
/// <summary>
|
|
/// COdice macchina (HARD CODED)
|
|
/// </summary>
|
|
protected string machine = "WRK001";
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Private Fields
|
|
|
|
/// <summary>
|
|
/// Forza fix date al momento ricezione UnlEnd valido
|
|
/// </summary>
|
|
private bool dfUnlEnd = false;
|
|
|
|
/// <summary>
|
|
/// Forza fix date al momento ricezione UnlStart valido
|
|
/// </summary>
|
|
private bool dfUnlStart = false;
|
|
|
|
/// <summary>
|
|
/// Forza fix date al momento ricezione WrkEnd valido
|
|
/// </summary>
|
|
private bool dfWrkEnd = false;
|
|
|
|
/// <summary>
|
|
/// Forza fix date al momento ricezione WrkStart valido
|
|
/// </summary>
|
|
private bool dfWrkStart = false;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Methods
|
|
|
|
/// <summary>
|
|
/// Verifica sheet loggando le eventuali anomalie sulle date e sistemando quelle mancanti in
|
|
/// base a setup
|
|
/// </summary>
|
|
/// <param name="CurrSheet">Sheet da verificare ed eventualmente sistemare</param>
|
|
/// <returns></returns>
|
|
private ProdSheetExt checkFixSheet(ProdSheetExt CurrSheet)
|
|
{
|
|
var fixSheet = CurrSheet;
|
|
// controllo SOLO SE se non sia ne in attesa ne completato...
|
|
if (!fixSheet.Waiting || !fixSheet.Done)
|
|
{
|
|
// calcolo SE sia in errore secondo i 4 punti di controllo work/unload
|
|
if (fixSheet.Unloading.OkE)
|
|
{
|
|
// loggo
|
|
LogSheetError(fixSheet);
|
|
|
|
if (dfUnlEnd)
|
|
{
|
|
// sistemo...
|
|
fixSheet.Unloading.DtStart = fixSheet.Unloading.OkS ? fixSheet.Unloading.DtStart : fixSheet.Unloading.DtEnd;
|
|
fixSheet.Machining.DtEnd = fixSheet.Machining.OkE ? fixSheet.Machining.DtEnd : fixSheet.Unloading.DtEnd;
|
|
fixSheet.Machining.DtStart = fixSheet.Machining.OkS ? fixSheet.Machining.DtStart : fixSheet.Unloading.DtEnd;
|
|
fixSheet.Printing.DtEnd = fixSheet.Printing.OkE ? fixSheet.Printing.DtEnd : fixSheet.Unloading.DtEnd;
|
|
fixSheet.Printing.DtStart = fixSheet.Printing.OkS ? fixSheet.Printing.DtStart : fixSheet.Unloading.DtEnd;
|
|
}
|
|
}
|
|
else if (fixSheet.Unloading.OkS && (!fixSheet.Printing.Done || !fixSheet.Machining.Done))
|
|
{
|
|
// loggo
|
|
LogSheetError(fixSheet);
|
|
|
|
if (dfUnlStart)
|
|
{
|
|
// sistemo...
|
|
fixSheet.Machining.DtEnd = fixSheet.Machining.OkE ? fixSheet.Machining.DtEnd : fixSheet.Unloading.DtEnd;
|
|
fixSheet.Machining.DtStart = fixSheet.Machining.OkS ? fixSheet.Machining.DtStart : fixSheet.Unloading.DtEnd;
|
|
fixSheet.Printing.DtEnd = fixSheet.Printing.OkE ? fixSheet.Printing.DtEnd : fixSheet.Unloading.DtEnd;
|
|
fixSheet.Printing.DtStart = fixSheet.Printing.OkS ? fixSheet.Printing.DtStart : fixSheet.Unloading.DtEnd;
|
|
}
|
|
}
|
|
else if (fixSheet.Machining.OkE && (!fixSheet.Printing.Done || !fixSheet.Machining.Done))
|
|
{
|
|
// loggo
|
|
LogSheetError(fixSheet);
|
|
|
|
if (dfWrkEnd)
|
|
{
|
|
// sistemo...
|
|
fixSheet.Machining.DtStart = fixSheet.Machining.OkS ? fixSheet.Machining.DtStart : fixSheet.Unloading.DtEnd;
|
|
fixSheet.Printing.DtEnd = fixSheet.Printing.OkE ? fixSheet.Printing.DtEnd : fixSheet.Unloading.DtEnd;
|
|
fixSheet.Printing.DtStart = fixSheet.Printing.OkS ? fixSheet.Printing.DtStart : fixSheet.Unloading.DtEnd;
|
|
}
|
|
}
|
|
else if (fixSheet.Machining.OkS && !fixSheet.Printing.Done)
|
|
{
|
|
// loggo
|
|
LogSheetError(fixSheet);
|
|
|
|
if (dfWrkStart)
|
|
{
|
|
// sistemo...
|
|
fixSheet.Printing.DtEnd = fixSheet.Printing.OkE ? fixSheet.Printing.DtEnd : fixSheet.Unloading.DtEnd;
|
|
fixSheet.Printing.DtStart = fixSheet.Printing.OkS ? fixSheet.Printing.DtStart : fixSheet.Unloading.DtEnd;
|
|
}
|
|
}
|
|
}
|
|
|
|
return fixSheet;
|
|
}
|
|
|
|
private void LogSheetError(ProdSheetExt cSheet)
|
|
{
|
|
// loggo
|
|
Log.Instance.Error($"Sheet Date error | SheetId: {cSheet.SheetId} | Print: {prtDate(cSheet.Printing)} | Work: {prtDate(cSheet.Machining)} | Unload: {prtDate(cSheet.Unloading)}");
|
|
}
|
|
|
|
private string prtDate(WorkData wrkRec)
|
|
{
|
|
string dtSta = wrkRec.DtStart == null ? "NULL" : $"{wrkRec.DtStart:yyyy.MM.dd HH:mm:ss}";
|
|
string dtEnd = wrkRec.DtEnd == null ? "NULL" : $"{wrkRec.DtEnd:yyyy.MM.dd HH:mm:ss}";
|
|
return $"{dtSta} ... {dtEnd}";
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |