diff --git a/MP.Core/Utils.cs b/MP.Core/Utils.cs index 34c2b9a0..e7a050cb 100644 --- a/MP.Core/Utils.cs +++ b/MP.Core/Utils.cs @@ -58,7 +58,6 @@ namespace MP.Core public const string redisPOdlByOdl = redisXdlData + "POdlByOdl"; public const string redisPOdlByPOdl = redisXdlData + "POdlByPOdl"; public const string redisPOdlList = redisXdlData + "POdlList"; - public const string redisPzCount = redisBaseAddr + "Cache:PzCount"; public const string redisRecipeConf = redisBaseAddr + "Cache:Recipe:Conf"; public const string redisStatoCom = redisBaseAddr + "Cache:StatoCom"; public const string redisStatoMacch = redisBaseAddr + "Cache:StatoMacch"; @@ -123,19 +122,12 @@ namespace MP.Core /// Hash dati STATUS x la macchina specificata /// /// + /// Chiave override per i valori in caso di dati che accedono al dominio dati di un altra app (es: baseAddr x IO legacy) /// - public static RedisKey dtMaccHash(string idxMacchina) + public static RedisKey dtMaccHash(string idxMacchina, string baseAddr = null) { - return (RedisKey)$"{redisBaseAddr}DtMac:{idxMacchina}"; - } - /// - /// Hash dati Macchine Multi SM Ingressi - /// - /// Macchina PRINCIPALE - /// - public static RedisKey msmiHash(string idxMacchina) - { - return (RedisKey)$"{redisBaseAddr}hMSMI:{idxMacchina}"; + var prefix = (baseAddr ?? redisBaseAddr).TrimEnd(':'); + return (RedisKey)$"{prefix}:DtMac:{idxMacchina}"; } public static string FormDurata(double durataMinuti) @@ -176,6 +168,18 @@ namespace MP.Core return endRounded; } + /// + /// Hash dati Macchine Multi SM Ingressi + /// + /// + /// Chiave override per i valori in caso di dati che accedono al dominio dati di un altra app (es: baseAddr x IO legacy) + /// + public static RedisKey msmiHash(string idxMacchina, string baseAddr = null) + { + var prefix = (baseAddr ?? redisBaseAddr).TrimEnd(':'); + return (RedisKey)$"{prefix}:hMSMI:{idxMacchina}"; + } + /// /// Nome della variabile HASH da utilizzare (dato CodModulo / Server / DB impiegato /// dafunzionalita' DbConfig) + idxMacchina richiesto... @@ -196,6 +200,18 @@ namespace MP.Core return (RedisKey)$"MP:Data:{keyName}"; } + /// + /// Hash dati countapezzi macchina + /// + /// + /// Chiave override per i valori in caso di dati che accedono al dominio dati di un altra app (es: baseAddr x IO legacy) + /// + public static RedisKey redisPzCount(string idxMacchina, string baseAddr = null) + { + var prefix = (baseAddr ?? redisBaseAddr).TrimEnd(':'); + return (RedisKey)$"{prefix}:Cache:PzCount:{idxMacchina}"; + } + /// /// Formato RedisKey delal chaive richeista (completa) /// diff --git a/MP.Data/Controllers/MpIocController.cs b/MP.Data/Controllers/MpIocController.cs index 3bd7b368..e3d877a1 100644 --- a/MP.Data/Controllers/MpIocController.cs +++ b/MP.Data/Controllers/MpIocController.cs @@ -492,6 +492,37 @@ namespace MP.Data.Controllers return dbResult; } + /// + /// Elenco ODL data macchina e periodo + /// + /// + /// + /// + /// + public List OdlListByMaccPeriodo(string idxMacchina, DateTime dtStart, DateTime dtEnd) + { + List dbResult = new List(); + using (var dbCtx = new MoonProContext(_configuration)) + { + try + { + var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina); + var DataFrom = new SqlParameter("@dataFrom", dtStart); + var DataTo = new SqlParameter("@dataTo", dtEnd); + dbResult = dbCtx + .DbSetODLExp + .FromSqlRaw("EXEC stp_ODL_getByMacchinaPeriodo @IdxMacchina, @dataFrom, @dataTo", IdxMacchina, DataFrom, DataTo) + .AsNoTracking() + .ToList(); + } + catch (Exception exc) + { + Log.Error($"Eccezione durante OdlListByMaccPeriodo{Environment.NewLine}{exc}"); + } + } + return dbResult; + } + /// /// Stato prod macchina /// diff --git a/MP.IOC/Controllers/IOBController.cs b/MP.IOC/Controllers/IOBController.cs index f0a40359..ea9b203b 100644 --- a/MP.IOC/Controllers/IOBController.cs +++ b/MP.IOC/Controllers/IOBController.cs @@ -221,13 +221,46 @@ namespace MP.IOC.Controllers try { answ = DService.processInput(id, valore, dtEve, dtCurr, cnt); + return Ok(answ); } catch (Exception exc) { Log.Error($"Errore in processInput{Environment.NewLine}{exc}"); - answ = "NO"; + return StatusCode(StatusCodes.Status500InternalServerError, "NO"); + } + } + + /// + /// SALVA in blocco un incremento pezzi x macchina restituendo il valore appena inviato o, + /// se mancasse chaive redis, del valore da DB + /// + /// GET: IOB/savePzCountInc/5?qty=10 + /// + /// codice macchina + /// num peziz da salvare in blocco + /// + [HttpGet("savePzCountInc/{id}")] + public async Task SavePzCountInc(string id, string qty) + { + if (string.IsNullOrEmpty(id)) return BadRequest("Missing ID"); + + // Multi: gestione carattere "|" trasformato in "#" + id = id.Replace("|", "#"); + + string answ = ""; + DateTime dataOraEvento = DateTime.Now; + // salvo SEMPRE log x questo tipo di dati! + Log.Info($"Salvataggio incremento contapezzi | id: {id} | pezzi: {qty}"); + try + { + answ = await DService.saveCaricoPezzi(id, qty); + return Ok(answ); + } + catch (Exception exc) + { + Log.Error($"Errore in savePzCountInc{Environment.NewLine}{exc}"); + return StatusCode(StatusCodes.Status500InternalServerError, "NO"); } - return Ok(answ); } /// diff --git a/MP.IOC/Data/MpDataService.cs b/MP.IOC/Data/MpDataService.cs index dda354f2..54ee7f73 100644 --- a/MP.IOC/Data/MpDataService.cs +++ b/MP.IOC/Data/MpDataService.cs @@ -416,7 +416,7 @@ namespace MP.IOC.Data verificaIdxMacchina(idxMacchina); // continuo processing... - string CodArticolo = datiMacc["CodArticolo"]; + string CodArticolo = datiMacc["codArticolo"]; if (string.IsNullOrEmpty(CodArticolo)) { var allDatiMacch = IocDbController.DatiMacchineGetAll(); @@ -494,7 +494,7 @@ namespace MP.IOC.Data }; // salva e processa answ = scriviRigaEvento(newRecEv); - //answ = scriviRigaEvento(idxMacchina, idxTipoEv, CodArticolo, valEsteso, 0, "-", dtEve, DateTime.Now); + //answ = scriviRigaEvento(idxMacchina, idxTipoEv, codArticolo, valEsteso, 0, "-", dtEve, DateTime.Now); // forzo RESET dati macchina... ResetDatiMacchina(idxMacchina); } @@ -523,7 +523,7 @@ namespace MP.IOC.Data } 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}"); + 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(); @@ -2079,7 +2079,7 @@ namespace MP.IOC.Data int answ = -1; try { - string currKey = $"{Utils.redisPzCount}:{idxMacchina}"; + var currKey = Utils.redisPzCount(idxMacchina, MpIoNS); RedisValue rawData = await redisDb.StringGetAsync(currKey); if (rawData.HasValue) { @@ -2455,7 +2455,7 @@ namespace MP.IOC.Data // se il conteggio è >= 0 SALVO come nuovo conteggio... if (newCounter >= 0) { - string currKey = $"{Utils.redisPzCount}:{idxMacchina}"; + var currKey = Utils.redisPzCount(idxMacchina, MpIoNS); RedisValue rawData = redisDb.StringGet(currKey); if (!rawData.HasValue) { @@ -2488,6 +2488,177 @@ namespace MP.IOC.Data return answ; } + /// + /// Processa registrazione EVENTO CONTEGGIO PEZZI x una data macchina IOB + /// + /// Macchina + /// Pezzi da registrare + /// + public async Task saveCaricoPezzi(string idxMacchina, string qty) + { + // default: 0, non registrato x cautela... + string answ = "0"; + // controllo per proseguire + if (!string.IsNullOrEmpty(idxMacchina) && !string.IsNullOrEmpty(qty)) + { + int numPzIncr = -1; + int.TryParse(qty, out numPzIncr); + // se il conteggio è >= 0 SALVO evento... + if (numPzIncr >= 0) + { + // recupero info tra cui ODL corrente + Dictionary datiMacc = mDatiMacchine(idxMacchina); + //var currData = await GetCurrOdlAsync(idxMacchina); + // registro evento 120 --> contapezzi in blocco !!!HARD CODED!!! !!!FIXME!!! + int idxEvento = 120; + DateTime adesso = DateTime.Now; + string codArticolo = "ND"; + if (datiMacc.ContainsKey("codArticolo")) + { + codArticolo = datiMacc["codArticolo"]; + } + + // creo evento + EventListModel newRecEv = new EventListModel() + { + CodArticolo = codArticolo, + IdxMacchina = idxMacchina, + IdxTipo = idxEvento, + InizioStato = adesso, + MatrOpr = 0, + pallet = "-", + Value = qty + }; + // salva e processa + var resp = scriviRigaEvento(newRecEv); + // registro in risposta che è andato tutto bene... ovvero la qty richiesta... + answ = qty; + } + } + else + { + string errore = $"Errore: mancano parametri macchina/incremento: idxMacchina {idxMacchina} | qty {qty}"; + Log.Error(errore); + answ = errore; + } + 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 + /// + /// Macchina + /// Pezzi da registrare + /// DataOra evento + /// DataOra corrente + /// + public string saveCaricoPezzi(string idxMacchina, string qty, string dtEve = "", string dtCurr = "") + { + // default: 0, non registrato x cautela... + string answ = "0"; + // Verifica se evento realtime oppure ho data specificata x processing @dtEve + DateTime adesso = DateTime.Now; + DateTime dtEvent = adesso; + bool rtimeProc = string.IsNullOrEmpty(dtEve); + if (!rtimeProc) + { + dtEvent = GetSrvDtEvent(dtEve, dtCurr); + } + // controllo per proseguire + if (!string.IsNullOrEmpty(idxMacchina) && !string.IsNullOrEmpty(qty)) + { + int numPzIncr = -1; + int.TryParse(qty, out numPzIncr); + // se il conteggio è >= 0 SALVO evento... + if (numPzIncr >= 0) + { + + var listOdl = IocDbController.OdlListByMaccPeriodo(idxMacchina, dtEvent, dtEvent.AddSeconds(1)); + if (listOdl != null && listOdl.Count > 0) + { + string codArticolo = listOdl.FirstOrDefault()?.CodArticolo ?? "ND"; + // registro evento 120 --> contapezzi in blocco !!!HARD CODED!!! !!!FIXME!!! + int idxEvento = 120; + // creo evento + EventListModel newRecEv = new EventListModel() + { + CodArticolo = codArticolo, + IdxMacchina = idxMacchina, + IdxTipo = idxEvento, + InizioStato = dtEvent, + MatrOpr = 0, + pallet = "-", + Value = qty + }; + // salva e processa + var resp = scriviRigaEvento(newRecEv); + // registro in risposta che è andato tutto bene... ovvero la qty richiesta... + answ = qty; + } + } + } + else + { + string errore = $"Errore: mancano parametri macchina/incremento: idxMacchina {idxMacchina} | qty {qty}"; + Log.Error(errore); + answ = errore; + } + return answ; + } + + /// /// Processa registrazione di un counter x una data macchina IOB /// @@ -2507,7 +2678,7 @@ namespace MP.IOC.Data // se il conteggio è >= 0 SALVO come nuovo conteggio... if (newCounter >= 0) { - string currKey = $"{Utils.redisPzCount}:{idxMacchina}"; + var currKey = Utils.redisPzCount(idxMacchina, MpIoNS); RedisValue rawData = await redisDb.StringGetAsync(currKey); if (!rawData.HasValue) { @@ -2979,7 +3150,7 @@ namespace MP.IOC.Data // salvo 1:1 i valori... STATO result.Add("IdxMicroStato", $"{rowResult.IdxMicroStato}"); result.Add("IdxStato", $"{rowResult.IdxStato}"); - result.Add("CodArticolo", $"{rowResult.CodArticolo}"); + result.Add("codArticolo", $"{rowResult.CodArticolo}"); result.Add("insEnabled", $"{rowResult.InsEnabled}"); result.Add("sLogEnabled", $"{rowResult.SLogEnabled}"); result.Add("pallet", $"{rowResult.Pallet}"); diff --git a/MP.IOC/MP.IOC.csproj b/MP.IOC/MP.IOC.csproj index e5f2e02c..a51746fd 100644 --- a/MP.IOC/MP.IOC.csproj +++ b/MP.IOC/MP.IOC.csproj @@ -4,7 +4,7 @@ net8.0 enable enable - 6.16.2604.1312 + 6.16.2604.1315 diff --git a/MP.IOC/Resources/ChangeLog.html b/MP.IOC/Resources/ChangeLog.html index 7a3688b2..28015f6a 100644 --- a/MP.IOC/Resources/ChangeLog.html +++ b/MP.IOC/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MP-IOC -

Versione: 6.16.2604.1312

+

Versione: 6.16.2604.1315


Note di rilascio:
  • diff --git a/MP.IOC/Resources/VersNum.txt b/MP.IOC/Resources/VersNum.txt index ad641515..dea6c3f6 100644 --- a/MP.IOC/Resources/VersNum.txt +++ b/MP.IOC/Resources/VersNum.txt @@ -1 +1 @@ -6.16.2604.1312 +6.16.2604.1315 diff --git a/MP.IOC/Resources/manifest.xml b/MP.IOC/Resources/manifest.xml index 6dfdb563..ff0d7f24 100644 --- a/MP.IOC/Resources/manifest.xml +++ b/MP.IOC/Resources/manifest.xml @@ -1,6 +1,6 @@ - 6.16.2604.1312 + 6.16.2604.1315 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