From dc07d77e2012cc88f50a8343277660c56fc09fdf Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Mon, 13 Apr 2026 16:26:39 +0200 Subject: [PATCH] Aggiunta metodo GetCurrOdlStart x IOC --- MP.Data/Controllers/MpIocController.cs | 56 +++ MP.Data/Controllers/MpTabController.cs | 2 +- MP.Data/Services/TabDataService.cs | 2 +- MP.IOC/Controllers/IOBController.cs | 32 ++ MP.IOC/Data/MpDataService.cs | 639 +++++++++++++------------ MP.IOC/MP.IOC.csproj | 2 +- MP.IOC/Resources/ChangeLog.html | 2 +- MP.IOC/Resources/VersNum.txt | 2 +- MP.IOC/Resources/manifest.xml | 2 +- 9 files changed, 427 insertions(+), 312 deletions(-) diff --git a/MP.Data/Controllers/MpIocController.cs b/MP.Data/Controllers/MpIocController.cs index e3d877a1..6e9e2e69 100644 --- a/MP.Data/Controllers/MpIocController.cs +++ b/MP.Data/Controllers/MpIocController.cs @@ -492,6 +492,62 @@ namespace MP.Data.Controllers return dbResult; } + /// + /// ODL corrente macchina + /// + /// + /// + public ODLExpModel OdlCurrByMacc(string idxMacchina) + { + ODLExpModel answ = new(); + using (var dbCtx = new MoonProContext(_configuration)) + { + try + { + var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina); + var dbRes = dbCtx + .DbSetODLExp + .FromSqlRaw("EXEC stp_ODL_getByMacchina @IdxMacchina", IdxMacchina) + .AsNoTracking() + .FirstOrDefault(); + answ = dbRes ?? new(); + } + catch (Exception exc) + { + Log.Error($"Eccezione durante OdlCurrByMacc{Environment.NewLine}{exc}"); + } + } + return answ; + } + + /// + /// ODL corrente macchina + /// + /// + /// + public async Task OdlCurrByMaccAsync(string idxMacchina) + { + ODLExpModel answ = new(); + using (var dbCtx = new MoonProContext(_configuration)) + { + try + { + var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina); + var dbRes = await dbCtx + .DbSetODLExp + .FromSqlRaw("EXEC stp_ODL_getByMacchina @IdxMacchina", IdxMacchina) + .AsNoTracking() + .FirstOrDefaultAsync(); + answ = dbRes ?? new(); + } + catch (Exception exc) + { + Log.Error($"Eccezione durante OdlCurrByMaccAsync{Environment.NewLine}{exc}"); + } + } + return answ; + } + /// /// Elenco ODL data macchina e periodo /// diff --git a/MP.Data/Controllers/MpTabController.cs b/MP.Data/Controllers/MpTabController.cs index bba5c444..012e19b4 100644 --- a/MP.Data/Controllers/MpTabController.cs +++ b/MP.Data/Controllers/MpTabController.cs @@ -1180,7 +1180,7 @@ namespace MP.Data.Controllers } catch (Exception exc) { - Log.Error($"Eccezione durante OdlCurrByMacc{Environment.NewLine}{exc}"); + Log.Error($"Eccezione durante OdlCurrByMaccAsync{Environment.NewLine}{exc}"); } } return dbResult; diff --git a/MP.Data/Services/TabDataService.cs b/MP.Data/Services/TabDataService.cs index 1b6311ba..b2f23468 100644 --- a/MP.Data/Services/TabDataService.cs +++ b/MP.Data/Services/TabDataService.cs @@ -1838,7 +1838,7 @@ namespace MP.Data.Services #if false Log.Debug($"OdlCurrByMacc | {source} | {idxMacchina} | {sw.Elapsed.TotalMilliseconds}ms"); #endif - string callName = $"OdlCurrByMacc.{source}"; + string callName = $"OdlCurrByMaccAsync.{source}"; int numRec = esCollect.RecordCall(callName, sw.Elapsed.TotalMilliseconds); if (numRec >= nRecLog) { diff --git a/MP.IOC/Controllers/IOBController.cs b/MP.IOC/Controllers/IOBController.cs index ea9b203b..4dd52ff3 100644 --- a/MP.IOC/Controllers/IOBController.cs +++ b/MP.IOC/Controllers/IOBController.cs @@ -147,6 +147,38 @@ namespace MP.IOC.Controllers } } + /// + /// Restituisce data-ora inizio dell'odl correntemente in lavorazione sulla macchina... + /// es: http://url_site/MP/IO/IOB/getCurrOdlStart/SIMUL_03 + /// + /// + /// + [HttpGet("getCurrOdlStart/{id}")] + public async Task GetCurrOdlStart(string id) + { + if (string.IsNullOrEmpty(id)) return BadRequest("Missing ID"); + + // Multi: gestione carattere "|" trasformato in "#" + id = id.Replace("|", "#"); + + DateTime answ = new DateTime(DateTime.Now.Year - 1, 12, 31); + // chiamo metodo redis/db... + try + { + var odlData = await DService.OdlCurrByMaccAsync(id); + if (odlData != null && odlData.DataInizio.HasValue) + { + answ = odlData.DataInizio.Value; + } + } + catch (Exception exc) + { + Log.Error($"Eccezione in recupero getCurrOdlStart{Environment.NewLine}{exc}"); + return StatusCode(StatusCodes.Status500InternalServerError, "NO"); + } + return Ok(answ.ToString("yyyy-MM-dd HH:mm:ss")); + } + /// /// Recupera TASK richiesto x macchina: /// GET: IOB/getOptPar/SIMUL_03 diff --git a/MP.IOC/Data/MpDataService.cs b/MP.IOC/Data/MpDataService.cs index 54ee7f73..2fa8d250 100644 --- a/MP.IOC/Data/MpDataService.cs +++ b/MP.IOC/Data/MpDataService.cs @@ -381,20 +381,6 @@ namespace MP.IOC.Data { return mongoController.CalcRecipe(currRecipe); } - /// - /// Restituisce il valore SPECIFICATO per la state machine ingressi - /// value: iTipoEv_nState (IdxTipoEv da trasmettere + New MICRO-STATE) - /// - /// - /// - /// - /// - private string valoreSMI(int idxFamIn, int idxMicroStato, int valoreIn) - { - var currHash = Utils.hSMI(idxFamIn); - string field = string.Format("{0}_{1}", idxMicroStato, valoreIn); - return RedisGetHashField(currHash, field); - } /// /// controlla se da il segnale di "microstato" deriva un evento da generare - modalità OFFLINE @@ -506,191 +492,6 @@ namespace MP.IOC.Data return answ; } - /// - /// Scrive una riga di evento nel db + check cambio stato DiarioDiBordo - /// - /// codice macchina - /// - private inputComandoMapo scriviRigaEvento(EventListModel newRec) - { - bool inserito = false; - try - { - // inserisco evento - inserito = IocDbController.EvListInsert(newRec); - // faccio controllo per eventuale cambio stato da tab transizioni... - checkCambiaStatoBatch(tipoInputEvento.hw, newRec.IdxMacchina, newRec.InizioStato ?? DateTime.Now, newRec.IdxTipo, newRec.CodArticolo, newRec.Value, newRec.MatrOpr, newRec.pallet); - } - catch (Exception exc) - { - Log.Error($"Errore in scriviRigaEvento | IdxMacchina {newRec.IdxMacchina} | IdxTipo {newRec.IdxTipo} | codArticolo {newRec.CodArticolo} | Value {newRec.Value} | MatrOpr {newRec.MatrOpr} | Pallet {newRec.pallet} | dTime {newRec.InizioStato}{Environment.NewLine}{exc}"); - } - // formatto output - inputComandoMapo answ = new inputComandoMapo(); - answ.outValue = inserito.ToString(); - answ.needStatusRefresh = true; - return answ; - } - - /// - /// verifica se sia necessario inserire un cambio di stato impianto (DiarioDi Bordo) in modalità batch - /// - /// - /// - /// - /// - /// - /// - /// - /// - private void checkCambiaStatoBatch(tipoInputEvento tipoInput, string IdxMacchina, DateTime InizioStato, int IdxTipo, string CodArt, string Value, int MatrOpr, string pallet) - { - //DS_applicazione.TransizioneStatiDataTable tabTransStati; - //DS_applicazione.TransizioneStatiRow rigaTransStati; - List listTransit = new List(); - TransizioneStatiModel? rigaTrans = null; - switch (tipoInput) - { - case tipoInputEvento.barcode: - // effettuo cambio stato INDIPENDENTEMENTE da stato precedente - listTransit = IocDbController.SMES_getUserForced(IdxMacchina, IdxTipo); - - if (listTransit.Count > 0) - { - rigaTrans = listTransit.FirstOrDefault(); - // solo se cambia stato... - if (rigaTrans != null && rigaTrans.IdxStato != rigaTrans.next_IdxStato) - { - IocDbController.DDB_InsStatoBatch(IdxMacchina, InizioStato, rigaTrans.next_IdxStato, CodArt, Value, MatrOpr, pallet); - // aggiorno MSE - IocDbController.RecalcMse(IdxMacchina, 0); - } - } - else - { - Log.Debug($"Non trovata riga per: BARCODE | IdxMacchina: {IdxMacchina} | IdxTipo: {IdxTipo} | CodArt: {CodArt} | Value: {Value} | MatrOpr: {MatrOpr} | pallet: {pallet}"); - } - break; - - case tipoInputEvento.hw: - // verifico se ci sia necessità di cambio stato - listTransit = IocDbController.SMES_getHwTransitions(IdxMacchina, IdxTipo); - if (listTransit.Count > 0) - { - rigaTrans = listTransit.FirstOrDefault(); - if (rigaTrans != null && rigaTrans.IdxStato != rigaTrans.next_IdxStato) - { - IocDbController.DDB_InsStatoBatch(IdxMacchina, InizioStato, rigaTrans.next_IdxStato, CodArt, Value, MatrOpr, pallet); - // aggiorno MSE - IocDbController.RecalcMse(IdxMacchina, 0); - } - } - else - { - Log.Debug($"Non trovata riga per: HW | IdxMacchina: {IdxMacchina} | IdxTipo: {IdxTipo} | CodArt: {CodArt} | Value: {Value} | MatrOpr: {MatrOpr} | pallet: {pallet}"); - } - - break; - } - } - -#if false - /// - /// controlla se da il segnale di "microstato" deriva un evento da generare - modalità OFFLINE - /// - /// idx macchina - /// valore ingresso - /// data-ora evento (server) - /// - public inputComandoMapo checkMicroStato(string idxMacchina, string valore, DateTime dtEve) - { - if (cMemLayer.CRI("_logLevel") > 6) - { - Log.Info(string.Format("{2}---------------------------{2}Richiesta verifica INPUT per Macchina {0}, seriale {1}", idxMacchina, valore, Environment.NewLine), tipoLog.INFO); - } - // formatto output - inputComandoMapo answ = new inputComandoMapo(); - DS_applicazione.TransizioneIngressiDataTable TabTransIn; - DS_applicazione.TransizioneIngressiRow rigaTransIn = null; - // verifico se esista la macchina altrimenti la creo... - verificaIdxMacchina(idxMacchina); - string CodArticolo = ""; - // recupero CodArticolo corretto - try - { - // 2017.07.10 forzo init x errori "sovrapposizioni" - taDatiMacchine = new DS_ProdTempiTableAdapters.DatiMacchineTableAdapter(); - CodArticolo = taDatiMacchine.getByIdx(idxMacchina)[0].CodArticolo_A; - } - catch (Exception exc) - { - Log.Info(string.Format("[ChkMiSt_4b] - Eccezione in recupero CodArticolo:{0}{1}", Environment.NewLine, exc), tipoLog.EXCEPTION); - } - // recupero next microstato - //int? valINT = Convert.ToInt32(valore); - int? valINT = 0; - try - { - // 2017.06.09 forzo init x errori "sovrapposizioni" - MapoDbObj.taTransIngr = new DS_applicazioneTableAdapters.TransizioneIngressiTableAdapter(); - valINT = int.Parse(valore, System.Globalization.NumberStyles.HexNumber); - TabTransIn = MapoDbObj.taTransIngr.getByIdxMacchinaValore(idxMacchina, valINT); - if (TabTransIn.Rows.Count > 0) - { - rigaTransIn = TabTransIn[0]; - } - } - catch (Exception exc) - { - Log.Info(string.Format("[ChkMiSt_5b] - Eccezione in recupero riga Trans ingressi per idxMacchina {3} e valore {2}:{0}{1}", Environment.NewLine, exc, valINT, idxMacchina), tipoLog.EXCEPTION); - } - int _logLevel = cMemLayer.CRI("_logLevel"); - // effettuo update vari - if (rigaTransIn != null) - { - try - { - if (_logLevel > 5) - { - Log.Info(string.Format("[ChkMiSt_6b] - Salvo Update Microstato:{0}macchina: {1} | valore seriale: {2} | next micro stato: {3}", Environment.NewLine, idxMacchina, valINT, rigaTransIn.next_IdxMicroStato), tipoLog.INFO); - } - // salvo nuovo microstato... - MapoDbObj.taMSM.updateQuery(rigaTransIn.next_IdxMicroStato, dtEve, valore, idxMacchina); - // controllo se c'è evento - if (rigaTransIn.IdxTipoEvento > 0) - { - if (_logLevel > 5) - { - Log.Info(string.Format("[ChkMiSt_7b] - Salvo evento:{0}macchina: {1} | tipoEvento: {2} | CodArticolo: {3}", Environment.NewLine, idxMacchina, rigaTransIn.IdxTipoEvento, CodArticolo), tipoLog.INFO); - } - answ = scriviRigaEvento(idxMacchina, rigaTransIn.IdxTipoEvento, CodArticolo, valore, 0, "-", dtEve, DateTime.Now); - if (_logLevel > 5) - { - Log.Info(string.Format("[ChkMiSt_b] -Macchina {0}, seriale(INT) {1}{2}---------------------------{2}", idxMacchina, valINT, Environment.NewLine), tipoLog.INFO); - } - } - } - catch (Exception exc) - { - Log.Info(string.Format("[ChkMiSt_8b] - Eccezione:{0}{1}", Environment.NewLine, exc), tipoLog.EXCEPTION); - } - } - return answ; - } - - /// - /// controlla se da il segnale di "microstato" deriva un evento da generare - /// - /// - /// - /// - public inputComandoMapo checkMicroStato(string idxMacchina, string valore) - { - // wrapper ad ora corrente... - return checkMicroStato(idxMacchina, valore, DateTime.Now); - } -#endif - public async Task> ConfigGetAllAsync() { Stopwatch stopWatch = new Stopwatch(); @@ -1127,6 +928,58 @@ namespace MP.IOC.Data return answ; } + /// + /// Effettua calcolo data-ora di riferimento per il server a partire da + /// + /// + /// + /// + public DateTime GetSrvDtEvent(string dtEve, string dtCurr) + { + DateTime dataOraEvento = 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; + 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); + TimeSpan deltaTS = dtCorrente.Subtract(dtEvento); + dataOraEvento = dataOraEvento.Add(-deltaTS); + } + } + catch (Exception exc) + { + Log.Error($"getSrvDtEvent | Errore calcolo ora corrente da IOB remoto | dtEve: {dtEve} | dtCurr: {dtCurr}{Environment.NewLine}" + + $"{exc}"); + } + } + + return dataOraEvento; + } + /// /// Restitusice elenco KVP dei TASK (da passare a IOB-WIN) per l'impianto indicato /// @@ -1593,6 +1446,37 @@ namespace MP.IOC.Data return fatto; } + public async Task OdlCurrByMaccAsync(string IdxMacchina) + { + ODLExpModel result = new(); + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + string readType = "DB"; + string currKey = $"{Utils.redisOdlList}:Current:{IdxMacchina}"; + // cerco in redis dato valore sel macchina... + RedisValue rawData = await redisDb.StringGetAsync(currKey); + if (rawData.HasValue) + { + result = JsonConvert.DeserializeObject($"{rawData}") ?? new(); + readType = "REDIS"; + } + else + { + result = await IocDbController.OdlCurrByMaccAsync(IdxMacchina); + // serializzo e salvo... + rawData = JsonConvert.SerializeObject(result); + redisDb.StringSet(currKey, rawData, TimeSpan.FromSeconds(redisShortTimeCache)); + } + if (result == null) + { + result = new(); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Trace($"OdlCurrByMaccAsync | Read from {readType}: {ts.TotalMilliseconds}ms"); + return result; + } + /// /// Record ODL da chaive /// @@ -2436,58 +2320,6 @@ namespace MP.IOC.Data return answ; } - /// - /// Processa registrazione di un counter x una data macchina IOB - /// - /// - /// contapezzi - /// - public string saveCounter(string idxMacchina, string counter) - { - string answ = "0"; - // inizio processing vero e proprio INPUT... - if (!string.IsNullOrEmpty(idxMacchina)) - { - if (!string.IsNullOrEmpty(counter)) - { - int newCounter = -1; - int.TryParse(counter, out newCounter); - // se il conteggio è >= 0 SALVO come nuovo conteggio... - if (newCounter >= 0) - { - var currKey = Utils.redisPzCount(idxMacchina, MpIoNS); - RedisValue rawData = redisDb.StringGet(currKey); - if (!rawData.HasValue) - { - // salvo per + tempo... - redisDb.StringSet(currKey, answ.ToString()); - answ = counter; - } - else - { - int currCount = pzCounterTc(idxMacchina); - answ = currCount.ToString(); - // salvo per meno tempo... - redisDb.StringSet(currKey, answ, TimeSpan.FromSeconds(5)); - } - } - } - else - { - string errore = "Errore: parametro counter vuoto"; - Log.Error(errore); - answ = errore; - } - } - else - { - string errore = "Errore: parametro macchina vuoto"; - Log.Info(errore); - answ = errore; - } - return answ; - } - /// /// Processa registrazione EVENTO CONTEGGIO PEZZI x una data macchina IOB /// @@ -2544,58 +2376,6 @@ namespace MP.IOC.Data return answ; } - /// - /// Effettua calcolo data-ora di riferimento per il server a partire da - /// - /// - /// - /// - public DateTime GetSrvDtEvent(string dtEve, string dtCurr) - { - DateTime dataOraEvento = 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; - 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); - TimeSpan deltaTS = dtCorrente.Subtract(dtEvento); - dataOraEvento = dataOraEvento.Add(-deltaTS); - } - } - catch (Exception exc) - { - Log.Error($"getSrvDtEvent | Errore calcolo ora corrente da IOB remoto | dtEve: {dtEve} | dtCurr: {dtCurr}{Environment.NewLine}" + - $"{exc}"); - } - } - - return dataOraEvento; - } - /// /// Processa registrazione EVENTO CONTEGGIO PEZZI x una data macchina IOB /// @@ -2624,7 +2404,6 @@ namespace MP.IOC.Data // se il conteggio è >= 0 SALVO evento... if (numPzIncr >= 0) { - var listOdl = IocDbController.OdlListByMaccPeriodo(idxMacchina, dtEvent, dtEvent.AddSeconds(1)); if (listOdl != null && listOdl.Count > 0) { @@ -2658,6 +2437,57 @@ namespace MP.IOC.Data return answ; } + /// + /// Processa registrazione di un counter x una data macchina IOB + /// + /// + /// contapezzi + /// + public string saveCounter(string idxMacchina, string counter) + { + string answ = "0"; + // inizio processing vero e proprio INPUT... + if (!string.IsNullOrEmpty(idxMacchina)) + { + if (!string.IsNullOrEmpty(counter)) + { + int newCounter = -1; + int.TryParse(counter, out newCounter); + // se il conteggio è >= 0 SALVO come nuovo conteggio... + if (newCounter >= 0) + { + var currKey = Utils.redisPzCount(idxMacchina, MpIoNS); + RedisValue rawData = redisDb.StringGet(currKey); + if (!rawData.HasValue) + { + // salvo per + tempo... + redisDb.StringSet(currKey, answ.ToString()); + answ = counter; + } + else + { + int currCount = pzCounterTc(idxMacchina); + answ = currCount.ToString(); + // salvo per meno tempo... + redisDb.StringSet(currKey, answ, TimeSpan.FromSeconds(5)); + } + } + } + else + { + string errore = "Errore: parametro counter vuoto"; + Log.Error(errore); + answ = errore; + } + } + else + { + string errore = "Errore: parametro macchina vuoto"; + Log.Info(errore); + answ = errore; + } + return answ; + } /// /// Processa registrazione di un counter x una data macchina IOB @@ -3018,6 +2848,68 @@ namespace MP.IOC.Data #region Private Methods + /// + /// verifica se sia necessario inserire un cambio di stato impianto (DiarioDi Bordo) in modalità batch + /// + /// + /// + /// + /// + /// + /// + /// + /// + private void checkCambiaStatoBatch(tipoInputEvento tipoInput, string IdxMacchina, DateTime InizioStato, int IdxTipo, string CodArt, string Value, int MatrOpr, string pallet) + { + //DS_applicazione.TransizioneStatiDataTable tabTransStati; + //DS_applicazione.TransizioneStatiRow rigaTransStati; + List listTransit = new List(); + TransizioneStatiModel? rigaTrans = null; + switch (tipoInput) + { + case tipoInputEvento.barcode: + // effettuo cambio stato INDIPENDENTEMENTE da stato precedente + listTransit = IocDbController.SMES_getUserForced(IdxMacchina, IdxTipo); + + if (listTransit.Count > 0) + { + rigaTrans = listTransit.FirstOrDefault(); + // solo se cambia stato... + if (rigaTrans != null && rigaTrans.IdxStato != rigaTrans.next_IdxStato) + { + IocDbController.DDB_InsStatoBatch(IdxMacchina, InizioStato, rigaTrans.next_IdxStato, CodArt, Value, MatrOpr, pallet); + // aggiorno MSE + IocDbController.RecalcMse(IdxMacchina, 0); + } + } + else + { + Log.Debug($"Non trovata riga per: BARCODE | IdxMacchina: {IdxMacchina} | IdxTipo: {IdxTipo} | CodArt: {CodArt} | Value: {Value} | MatrOpr: {MatrOpr} | pallet: {pallet}"); + } + break; + + case tipoInputEvento.hw: + // verifico se ci sia necessità di cambio stato + listTransit = IocDbController.SMES_getHwTransitions(IdxMacchina, IdxTipo); + if (listTransit.Count > 0) + { + rigaTrans = listTransit.FirstOrDefault(); + if (rigaTrans != null && rigaTrans.IdxStato != rigaTrans.next_IdxStato) + { + IocDbController.DDB_InsStatoBatch(IdxMacchina, InizioStato, rigaTrans.next_IdxStato, CodArt, Value, MatrOpr, pallet); + // aggiorno MSE + IocDbController.RecalcMse(IdxMacchina, 0); + } + } + else + { + Log.Debug($"Non trovata riga per: HW | IdxMacchina: {IdxMacchina} | IdxTipo: {IdxTipo} | CodArt: {CodArt} | Value: {Value} | MatrOpr: {MatrOpr} | pallet: {pallet}"); + } + + break; + } + } + /// /// Recupero info ODL corrente da dati prod macchina /// @@ -3234,6 +3126,32 @@ namespace MP.IOC.Data return answ; } + /// + /// Scrive una riga di evento nel db + check cambio stato DiarioDiBordo + /// + /// codice macchina + /// + private inputComandoMapo scriviRigaEvento(EventListModel newRec) + { + bool inserito = false; + try + { + // inserisco evento + inserito = IocDbController.EvListInsert(newRec); + // faccio controllo per eventuale cambio stato da tab transizioni... + checkCambiaStatoBatch(tipoInputEvento.hw, newRec.IdxMacchina, newRec.InizioStato ?? DateTime.Now, newRec.IdxTipo, newRec.CodArticolo, newRec.Value, newRec.MatrOpr, newRec.pallet); + } + catch (Exception exc) + { + Log.Error($"Errore in scriviRigaEvento | IdxMacchina {newRec.IdxMacchina} | IdxTipo {newRec.IdxTipo} | codArticolo {newRec.CodArticolo} | Value {newRec.Value} | MatrOpr {newRec.MatrOpr} | Pallet {newRec.pallet} | dTime {newRec.InizioStato}{Environment.NewLine}{exc}"); + } + // formatto output + inputComandoMapo answ = new inputComandoMapo(); + answ.outValue = inserito.ToString(); + answ.needStatusRefresh = true; + return answ; + } + /// /// Restituisce il valore booleano se la macchina sia abilitata all'inserimento COMPLETO nel /// Signal Log @@ -3342,6 +3260,117 @@ namespace MP.IOC.Data return answ; } + /// + /// Restituisce il valore SPECIFICATO per la state machine ingressi + /// value: iTipoEv_nState (IdxTipoEv da trasmettere + New MICRO-STATE) + /// + /// + /// + /// + /// + private string valoreSMI(int idxFamIn, int idxMicroStato, int valoreIn) + { + var currHash = Utils.hSMI(idxFamIn); + string field = string.Format("{0}_{1}", idxMicroStato, valoreIn); + return RedisGetHashField(currHash, field); + } + +#if false + /// + /// controlla se da il segnale di "microstato" deriva un evento da generare - modalità OFFLINE + /// + /// idx macchina + /// valore ingresso + /// data-ora evento (server) + /// + public inputComandoMapo checkMicroStato(string idxMacchina, string valore, DateTime dtEve) + { + if (cMemLayer.CRI("_logLevel") > 6) + { + Log.Info(string.Format("{2}---------------------------{2}Richiesta verifica INPUT per Macchina {0}, seriale {1}", idxMacchina, valore, Environment.NewLine), tipoLog.INFO); + } + // formatto output + inputComandoMapo answ = new inputComandoMapo(); + DS_applicazione.TransizioneIngressiDataTable TabTransIn; + DS_applicazione.TransizioneIngressiRow rigaTransIn = null; + // verifico se esista la macchina altrimenti la creo... + verificaIdxMacchina(idxMacchina); + string CodArticolo = ""; + // recupero CodArticolo corretto + try + { + // 2017.07.10 forzo init x errori "sovrapposizioni" + taDatiMacchine = new DS_ProdTempiTableAdapters.DatiMacchineTableAdapter(); + CodArticolo = taDatiMacchine.getByIdx(idxMacchina)[0].CodArticolo_A; + } + catch (Exception exc) + { + Log.Info(string.Format("[ChkMiSt_4b] - Eccezione in recupero CodArticolo:{0}{1}", Environment.NewLine, exc), tipoLog.EXCEPTION); + } + // recupero next microstato + //int? valINT = Convert.ToInt32(valore); + int? valINT = 0; + try + { + // 2017.06.09 forzo init x errori "sovrapposizioni" + MapoDbObj.taTransIngr = new DS_applicazioneTableAdapters.TransizioneIngressiTableAdapter(); + valINT = int.Parse(valore, System.Globalization.NumberStyles.HexNumber); + TabTransIn = MapoDbObj.taTransIngr.getByIdxMacchinaValore(idxMacchina, valINT); + if (TabTransIn.Rows.Count > 0) + { + rigaTransIn = TabTransIn[0]; + } + } + catch (Exception exc) + { + Log.Info(string.Format("[ChkMiSt_5b] - Eccezione in recupero riga Trans ingressi per idxMacchina {3} e valore {2}:{0}{1}", Environment.NewLine, exc, valINT, idxMacchina), tipoLog.EXCEPTION); + } + int _logLevel = cMemLayer.CRI("_logLevel"); + // effettuo update vari + if (rigaTransIn != null) + { + try + { + if (_logLevel > 5) + { + Log.Info(string.Format("[ChkMiSt_6b] - Salvo Update Microstato:{0}macchina: {1} | valore seriale: {2} | next micro stato: {3}", Environment.NewLine, idxMacchina, valINT, rigaTransIn.next_IdxMicroStato), tipoLog.INFO); + } + // salvo nuovo microstato... + MapoDbObj.taMSM.updateQuery(rigaTransIn.next_IdxMicroStato, dtEve, valore, idxMacchina); + // controllo se c'è evento + if (rigaTransIn.IdxTipoEvento > 0) + { + if (_logLevel > 5) + { + Log.Info(string.Format("[ChkMiSt_7b] - Salvo evento:{0}macchina: {1} | tipoEvento: {2} | CodArticolo: {3}", Environment.NewLine, idxMacchina, rigaTransIn.IdxTipoEvento, CodArticolo), tipoLog.INFO); + } + answ = scriviRigaEvento(idxMacchina, rigaTransIn.IdxTipoEvento, CodArticolo, valore, 0, "-", dtEve, DateTime.Now); + if (_logLevel > 5) + { + Log.Info(string.Format("[ChkMiSt_b] -Macchina {0}, seriale(INT) {1}{2}---------------------------{2}", idxMacchina, valINT, Environment.NewLine), tipoLog.INFO); + } + } + } + catch (Exception exc) + { + Log.Info(string.Format("[ChkMiSt_8b] - Eccezione:{0}{1}", Environment.NewLine, exc), tipoLog.EXCEPTION); + } + } + return answ; + } + + /// + /// controlla se da il segnale di "microstato" deriva un evento da generare + /// + /// + /// + /// + public inputComandoMapo checkMicroStato(string idxMacchina, string valore) + { + // wrapper ad ora corrente... + return checkMicroStato(idxMacchina, valore, DateTime.Now); + } +#endif /// /// cerca codice in anagrafica macchine ed eventualmente inserisce nuova macchina @@ -3394,8 +3423,6 @@ namespace MP.IOC.Data IocDbController.MicroStatoMacchinaUpsert(msRec); } } - - } } diff --git a/MP.IOC/MP.IOC.csproj b/MP.IOC/MP.IOC.csproj index a51746fd..3fb4df1a 100644 --- a/MP.IOC/MP.IOC.csproj +++ b/MP.IOC/MP.IOC.csproj @@ -4,7 +4,7 @@ net8.0 enable enable - 6.16.2604.1315 + 6.16.2604.1316 diff --git a/MP.IOC/Resources/ChangeLog.html b/MP.IOC/Resources/ChangeLog.html index 28015f6a..30c3867d 100644 --- a/MP.IOC/Resources/ChangeLog.html +++ b/MP.IOC/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MP-IOC -

Versione: 6.16.2604.1315

+

Versione: 6.16.2604.1316


Note di rilascio:
  • diff --git a/MP.IOC/Resources/VersNum.txt b/MP.IOC/Resources/VersNum.txt index dea6c3f6..3cb935d6 100644 --- a/MP.IOC/Resources/VersNum.txt +++ b/MP.IOC/Resources/VersNum.txt @@ -1 +1 @@ -6.16.2604.1315 +6.16.2604.1316 diff --git a/MP.IOC/Resources/manifest.xml b/MP.IOC/Resources/manifest.xml index ff0d7f24..e2a937a8 100644 --- a/MP.IOC/Resources/manifest.xml +++ b/MP.IOC/Resources/manifest.xml @@ -1,6 +1,6 @@ - 6.16.2604.1315 + 6.16.2604.1316 https://nexus.steamware.net/repository/SWS/MP-IOC/stable/LAST/MP.IOC.zip https://nexus.steamware.net/repository/SWS/MP-IOC/stable/LAST/ChangeLog.html false