Update processo registrazione ULog
This commit is contained in:
@@ -316,6 +316,105 @@ namespace MP_IO.Controllers
|
||||
return answ;
|
||||
}
|
||||
|
||||
|
||||
// GET: IOB/ulog/SIMUL_03?flux=PROG&valore=P0001&dtEve=20161223180600000&dtCurr=20161223180600000&cnt=999&matrOpr=0=0&label=&valNum
|
||||
public string ulog(string id, string flux, string valore, string dtEve, string dtCurr, string cnt, string matrOpr, string label, string valNum)
|
||||
{
|
||||
string answ = "";
|
||||
// formato yyyymmddHHMMSSnnn ovvero da anno a millisecondi
|
||||
if (cnt == null)
|
||||
{
|
||||
cnt = "0";
|
||||
}
|
||||
|
||||
DateTime dataOraEvento = DateTime.Now;
|
||||
if (memLayer.ML.CRI("_logLevel") > 6)
|
||||
{
|
||||
logger.lg.scriviLog($"ulog | Valori letti: idxMacchina: {id} | flux: {flux} valore: {valore} | matrOpr: {matrOpr} | label: {label} | valNum: {valNum}", tipoLog.INFO);
|
||||
}
|
||||
try
|
||||
{
|
||||
DataLayer DataLayerObj = new DataLayer();
|
||||
int count = 0;
|
||||
int nMatrOpr = 0;
|
||||
int nValNum = 0;
|
||||
Int32.TryParse(cnt, out count);
|
||||
Int32.TryParse(matrOpr, out nMatrOpr);
|
||||
Int32.TryParse(valNum, out nValNum);
|
||||
answ = DataLayerObj.processUserLog(id, flux, valore, dtEve, dtCurr, count, nMatrOpr, label, nValNum);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
logger.lg.scriviLog($"Errore in ulog{Environment.NewLine}{exc}");
|
||||
answ = "NO";
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
/// <summary>
|
||||
/// Processa una chiamata POST per l'invio di una List Json 1+ UserAction (contiene controlli, scarti, dichiarazioni)
|
||||
/// POST: IOB/ulogJson/SIMUL_03
|
||||
/// </summary>
|
||||
/// <param name="id">ID dell'IOB</param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public string ulogJson(string id)
|
||||
{
|
||||
int insDone = 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(
|
||||
Request.InputStream, System.Text.Encoding.UTF8, true, 4096, true))
|
||||
{
|
||||
content = reader.ReadToEnd();
|
||||
}
|
||||
//Rest
|
||||
System.Web.HttpContext.Current.Request.InputStream.Position = 0;
|
||||
// se ho dati...
|
||||
if (content != "")
|
||||
{
|
||||
DataLayer DataLayerObj = new DataLayer();
|
||||
// procedo a deserializzare in blocco l'oggetto...
|
||||
ulogJsonPayload receivedData = new ulogJsonPayload();
|
||||
try
|
||||
{
|
||||
// deserializzo.
|
||||
receivedData = JsonConvert.DeserializeObject<ulogJsonPayload>(content);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
logger.lg.scriviLog($"Errore in fase deserializzazione ulogJson{Environment.NewLine}{exc}");
|
||||
answ = "NO";
|
||||
}
|
||||
// se ho qualcosa da processare...
|
||||
if (receivedData != null)
|
||||
{
|
||||
// per ogni valore --> salvo!
|
||||
try
|
||||
{
|
||||
foreach (var item in receivedData.fluxData)
|
||||
{
|
||||
// formato datetime come yyyyMMddHHmmssfff -->es: 20181223180600000
|
||||
answ = DataLayerObj.processUserLog(id, item.flux, item.valore, item.dtEve.ToString("yyyyMMddHHmmssfff"), item.dtCurr.ToString("yyyyMMddHHmmssfff"), item.cnt, item.matrOpr, item.label, item.valNum);
|
||||
}
|
||||
// se vuoto --> OK!
|
||||
if (string.IsNullOrEmpty(answ))
|
||||
{
|
||||
answ = $"OK {insDone} processed";
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
logger.lg.scriviLog($"Errore in fase invio valori ulogJson{Environment.NewLine}{exc}");
|
||||
answ = "NO";
|
||||
}
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Chiude ODL precedente ed avvia uno nuovo (duplicandolo e sitemando quantità RIMANENTE), e CONFERMA produzione...
|
||||
///
|
||||
@@ -1356,75 +1455,6 @@ namespace MP_IO.Controllers
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Processa una chiamata POST per l'invio di una List Json 1+ UserAction (contiene controlli, scarti, dichiarazioni)
|
||||
/// POST: IOB/recordUserAction/SIMUL_03
|
||||
/// </summary>
|
||||
/// <param name="id">ID dell'IOB</param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public string recordUserAction(string id)
|
||||
{
|
||||
string answ = "";
|
||||
if (string.IsNullOrWhiteSpace(id))
|
||||
{
|
||||
answ = "Missing IOB";
|
||||
}
|
||||
else
|
||||
{
|
||||
// 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(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...
|
||||
userAction azione = new userAction();
|
||||
try
|
||||
{
|
||||
// deserializzo.
|
||||
azione = JsonConvert.DeserializeObject<userAction>(content);
|
||||
// se != null --> salvo!
|
||||
if (azione != null)
|
||||
{
|
||||
// salvo
|
||||
DataLayer DataLayerObj = new DataLayer();
|
||||
if (azione.listaDic != null)
|
||||
{
|
||||
foreach (var recDic in azione.listaDic)
|
||||
{
|
||||
DataLayerObj.taDiarioDich.insertQuery(recDic.tagCode, id, DateTime.Now, recDic.matrOpr, recDic.valString);
|
||||
}
|
||||
}
|
||||
if (azione.listRCon != null)
|
||||
{
|
||||
foreach (var recCon in azione.listRCon)
|
||||
{
|
||||
DataLayerObj.taRC.insertQuery(id, recCon.matrOpr, recCon.esitoOk, recCon.note, DateTime.Now);
|
||||
}
|
||||
|
||||
}
|
||||
if (azione.listRSca != null)
|
||||
{
|
||||
foreach (var recSca in azione.listRSca)
|
||||
{
|
||||
DataLayerObj.taRS.insertQuery(id, DateTime.Now, recSca.causale, recSca.qta, recSca.note, recSca.matrOpr);
|
||||
}
|
||||
}
|
||||
answ = "OK";
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
logger.lg.scriviLog($"Errore in recordUserAction{Environment.NewLine}{exc}");
|
||||
answ = "NO";
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ namespace MP_SITE.WebUserControls
|
||||
|
||||
#region Protected Methods
|
||||
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
protected override void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
_resoconti = new resoconti();
|
||||
if (!Page.IsPostBack)
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace MP_SITE.WebUserControls
|
||||
{
|
||||
#region Protected Methods
|
||||
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
protected override void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
// blocco button della pagina corrente...
|
||||
if (Page.Title.Contains("Stato"))
|
||||
|
||||
@@ -76,6 +76,11 @@ namespace MoonProTablet.WebUserControls
|
||||
/// </summary>
|
||||
public bool enableSchedaTecnica = memLayer.ML.cdvb("enableSchedaTecnica");
|
||||
|
||||
/// <summary>
|
||||
/// Verifica chiave enableRiattrezzaggio in tab Config
|
||||
/// </summary>
|
||||
public bool enableRiattrezzaggio = memLayer.ML.cdvb("enableRiattrezzaggio");
|
||||
|
||||
/// <summary>
|
||||
/// Abilitazione gestione SplitODL
|
||||
/// </summary>
|
||||
|
||||
@@ -57,28 +57,6 @@ namespace MoonProTablet.WebUserControls
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifica chiave enableRiattrezzaggio in tab Config
|
||||
/// </summary>
|
||||
protected bool enableRiattrezzaggio
|
||||
{
|
||||
get
|
||||
{
|
||||
return memLayer.ML.cdvb("enableRiattrezzaggio");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifica chiave enableSchedaTecn in tab Config
|
||||
/// </summary>
|
||||
protected bool enableSchedaTecnica
|
||||
{
|
||||
get
|
||||
{
|
||||
return memLayer.ML.cdvb("enableSchedaTecnica");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restituisce il codice IdxMacchina dell'altra tavola (se multi) altrimenti la stessa macchina...
|
||||
/// </summary>
|
||||
|
||||
+109
-3
@@ -2235,7 +2235,7 @@ namespace MapoDb
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
logger.lg.scriviLog(string.Format("Errore calcolo ms evento/ora corrente da device remoto:{0}dtEve : {1}{0}dtCurr: {2}{0}{3}", Environment.NewLine, dtEve, dtCurr, exc), tipoLog.EXCEPTION);
|
||||
logger.lg.scriviLog(string.Format("processFluxLog | Errore calcolo ms evento/ora corrente da device remoto:{0}dtEve : {1}{0}dtCurr: {2}{0}{3}", Environment.NewLine, dtEve, dtCurr, exc), tipoLog.EXCEPTION);
|
||||
}
|
||||
}
|
||||
// inizio processing vero e proprio INPUT...
|
||||
@@ -2252,20 +2252,126 @@ namespace MapoDb
|
||||
}
|
||||
else
|
||||
{
|
||||
string errore = "Errore: parametri macchina/valore vuoti";
|
||||
string errore = "processFluxLog | Errore: parametri macchina/valore vuoti";
|
||||
logger.lg.scriviLog(errore, tipoLog.INFO);
|
||||
answ = errore;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string errore = "Errore: mancano parametri macchina/valore";
|
||||
string errore = "processFluxLog | Errore: mancano parametri macchina/valore";
|
||||
logger.lg.scriviLog(errore, tipoLog.INFO);
|
||||
answ = errore;
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Processa registrazione UserLog da IOB
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina">Macchina</param>
|
||||
/// <param name="flux">Flusso: DI/RC/RC</param>
|
||||
/// <param name="valore">valore = note/valString</param>
|
||||
/// <param name="dtEve">data evento</param>
|
||||
/// <param name="dtCurr">data corrente</param>
|
||||
/// <param name="contatore">contatore invio</param>
|
||||
/// <param name="matrOpr">Matricola Operatore</param>
|
||||
/// <param name="label">label = causale scarto / tagCode</param>
|
||||
/// <param name="valNum">valNum = esitoOk (0/1) / Quantità di scarto associata</param>
|
||||
/// <returns></returns>
|
||||
public string processUserLog(string idxMacchina, string flux, string valore, string dtEve, string dtCurr, int contatore, int matrOpr, string label, int valNum)
|
||||
{
|
||||
// instanzio un nuovo oggetto MapoDb
|
||||
MapoDb connDb = new MapoDb();
|
||||
// scrivo keep alive!!! (se necessario, altrimenti è in cache...)
|
||||
connDb.scriviKeepAlive(idxMacchina, DateTime.Now);
|
||||
// 2017.09.14 trimmo eventualmente lo zero finale dalle date SE supera i millisecondi...
|
||||
dtEve = dtEve.Length > 17 ? dtEve.Substring(0, 17) : dtEve;
|
||||
dtCurr = dtCurr.Length > 17 ? dtCurr.Substring(0, 17) : dtCurr;
|
||||
// registro conteggio impiego chiamate REDIS
|
||||
if (memLayer.ML.CRB("IOB_RedEnab"))
|
||||
{
|
||||
saveCallRec("processUserLog");
|
||||
}
|
||||
string answ = "";
|
||||
DateTime dataOraEvento = DateTime.Now;
|
||||
DateTime dtEvento, dtCorrente;
|
||||
// controllo: se ho valori dt x evento e orario DIVERSI per acquisitore IOB calcolo dataOraEvento corretto
|
||||
if (dtEve != dtCurr)
|
||||
{
|
||||
Int64 delta = 0;
|
||||
try
|
||||
{
|
||||
// se ho meno decimali x evento rispetto dtCorrente...
|
||||
if (dtEve.Length < dtCurr.Length)
|
||||
{
|
||||
dtEve = dtEve.PadRight(dtCurr.Length, '0');
|
||||
}
|
||||
delta = Convert.ToInt64(dtCurr) - Convert.ToInt64(dtEve);
|
||||
// se meno di 60'000 ms ...
|
||||
if (delta < 59999)
|
||||
{
|
||||
dataOraEvento = dataOraEvento.AddMilliseconds(-delta);
|
||||
}
|
||||
else
|
||||
{
|
||||
// in questo caso elimino i MS dalle stringhe e converto i datetime....
|
||||
CultureInfo provider = CultureInfo.InvariantCulture;
|
||||
string format = "yyyyMMddHHmmssfff";
|
||||
dtEvento = DateTime.ParseExact(dtEve, format, provider);
|
||||
dtCorrente = DateTime.ParseExact(dtCurr, format, provider);
|
||||
Int64 tiks = dtCorrente.Ticks - dtEvento.Ticks;
|
||||
dataOraEvento = dataOraEvento.AddTicks(-tiks);
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
logger.lg.scriviLog(string.Format("processUserLog | Errore calcolo ms evento/ora corrente da device remoto:{0}dtEve : {1}{0}dtCurr: {2}{0}{3}", Environment.NewLine, dtEve, dtCurr, exc), tipoLog.EXCEPTION);
|
||||
}
|
||||
}
|
||||
// inizio processing vero e proprio INPUT...
|
||||
if (string.IsNullOrEmpty(idxMacchina))
|
||||
{
|
||||
string errore = "processUserLog | Errore: macchina mancante";
|
||||
logger.lg.scriviLog(errore, tipoLog.INFO);
|
||||
answ = errore;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string.IsNullOrEmpty(flux))
|
||||
{
|
||||
string errore = "processUserLog | Errore: parametro flux vuoto";
|
||||
logger.lg.scriviLog(errore, tipoLog.INFO);
|
||||
answ = errore;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 2020.01.31 nuovo OBJ
|
||||
DataLayer DLMan = new DataLayer();
|
||||
// in base al flusso decido dove e cosa scrivere...
|
||||
switch (flux)
|
||||
{
|
||||
case "DI":
|
||||
DLMan.taDiarioDich.insertQuery(label, idxMacchina, dataOraEvento, matrOpr, valore);
|
||||
break;
|
||||
case "RC":
|
||||
bool esitoOk = valNum != 0;
|
||||
DLMan.taRC.insertQuery(idxMacchina, matrOpr, esitoOk, valore, dataOraEvento);
|
||||
break;
|
||||
case "RS":
|
||||
DLMan.taRS.insertQuery(idxMacchina, dataOraEvento, label, valNum, valore, matrOpr);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// registro in risposta che è andato tutto bene...
|
||||
answ = "OK";
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Processa input da IOB eventualmente registrando i segnali inviati
|
||||
/// </summary>
|
||||
|
||||
+42
-38
@@ -467,6 +467,47 @@ namespace MapoSDK
|
||||
#endregion Public Properties
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Tracciato UserLog in formato JSON valido
|
||||
/// </summary>
|
||||
public class ulogData : evData
|
||||
{
|
||||
#region Public Properties
|
||||
|
||||
/// <summary>
|
||||
/// Nome del flusso (RC/RS/DI)
|
||||
/// </summary>
|
||||
public string flux { get; set; } = "DI";
|
||||
/// <summary>
|
||||
/// Operatore di riferimento
|
||||
/// </summary>
|
||||
public int matrOpr { get; set; } = 0;
|
||||
/// <summary>
|
||||
/// [OPZIONALE] label = causale scarto / tagCode
|
||||
/// </summary>
|
||||
public string label { get; set; } = "";
|
||||
/// <summary>
|
||||
/// [OPZIONALE] valNum = esitoOk (0/1) / Quantità di scarto associata
|
||||
/// </summary>
|
||||
public int valNum { get; set; } = 0;
|
||||
|
||||
#endregion Public Properties
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Array valori tipo flogData inviati come JSon
|
||||
/// </summary>
|
||||
public class ulogJsonPayload
|
||||
{
|
||||
#region Public Properties
|
||||
|
||||
public List<ulogData> fluxData { get; set; }
|
||||
|
||||
#endregion Public Properties
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raccolta dati di storici sintetici per Macchina e Variabile
|
||||
/// </summary>
|
||||
@@ -720,44 +761,7 @@ namespace MapoSDK
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Classe gestione UserAction x dichiarazioni utente inviate tramite MP-IO
|
||||
/// </summary>
|
||||
public class userAction
|
||||
{
|
||||
public List<recControllo> listRCon { get; set; } = null;
|
||||
public List<recScarto> listRSca { get; set; } = null;
|
||||
public List<recDich> listaDic { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Classe definizione registrazione controlli
|
||||
/// </summary>
|
||||
public class recControllo
|
||||
{
|
||||
public int matrOpr { get; set; } = 0;
|
||||
public bool esitoOk { get; set; } = false;
|
||||
public string note { get; set; } = "";
|
||||
}
|
||||
/// <summary>
|
||||
/// Classe definizione registrazione scarti
|
||||
/// </summary>
|
||||
public class recScarto
|
||||
{
|
||||
public int matrOpr { get; set; } = 0;
|
||||
public string causale { get; set; } = "00";
|
||||
public int qta { get; set; } = 0;
|
||||
public string note { get; set; } = "";
|
||||
}
|
||||
/// <summary>
|
||||
/// Classe definizione registrazione scarti
|
||||
/// </summary>
|
||||
public class recDich
|
||||
{
|
||||
public int matrOpr { get; set; } = 0;
|
||||
public string tagCode { get; set; } = "Nota";
|
||||
public string valString { get; set; } = "";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Struttura conf memorie PLC (inizialmente SIEMENS)
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user