diff --git a/MP.Data/Controllers/MpIocController.cs b/MP.Data/Controllers/MpIocController.cs index 2ad11b1d..2434b81b 100644 --- a/MP.Data/Controllers/MpIocController.cs +++ b/MP.Data/Controllers/MpIocController.cs @@ -597,9 +597,9 @@ namespace MP.Data.Controllers public List MacchineGetAll() { List dbResult = new List(); - using (MoonProContext localDbCtx = new MoonProContext(_configuration)) + using (MoonProContext dbCtx = new MoonProContext(_configuration)) { - dbResult = localDbCtx + dbResult = dbCtx .DbSetMacchine .ToList(); } @@ -609,14 +609,25 @@ namespace MP.Data.Controllers public MacchineModel? MacchineGetByIdx(string IdxMacchina) { MacchineModel dbResult = null; - using (MoonProContext localDbCtx = new MoonProContext(_configuration)) + using (MoonProContext dbCtx = new MoonProContext(_configuration)) { - dbResult = localDbCtx + dbResult = dbCtx .DbSetMacchine .FirstOrDefault(x => x.IdxMacchina == IdxMacchina); } return dbResult; } + public async Task MacchineGetByIdxAsync(string IdxMacchina) + { + MacchineModel dbResult = null; + using (MoonProContext dbCtx = new MoonProContext(_configuration)) + { + dbResult = await dbCtx + .DbSetMacchine + .FirstOrDefaultAsync(x => x.IdxMacchina == IdxMacchina); + } + return dbResult; + } /// /// Elenco da tabella Macchine @@ -667,21 +678,21 @@ namespace MP.Data.Controllers /// public bool MacchineUpsert(MacchineModel entity) { - using (MoonProContext localDbCtx = new MoonProContext(_configuration)) + using (MoonProContext dbCtx = new MoonProContext(_configuration)) { // Recuperiamo l'entità tracciata dal context - var trackedEntity = localDbCtx.DbSetMacchine.FirstOrDefault(x => x.IdxMacchina == entity.IdxMacchina); + var trackedEntity = dbCtx.DbSetMacchine.FirstOrDefault(x => x.IdxMacchina == entity.IdxMacchina); if (trackedEntity != null) { // Aggiorna i valori dell'entità tracciata con quelli della nuova - localDbCtx.Entry(trackedEntity).CurrentValues.SetValues(entity); + dbCtx.Entry(trackedEntity).CurrentValues.SetValues(entity); } else { - localDbCtx.DbSetMacchine.Update(entity); + dbCtx.DbSetMacchine.Update(entity); } - return localDbCtx.SaveChanges() > 0; + return dbCtx.SaveChanges() > 0; } } @@ -691,21 +702,21 @@ namespace MP.Data.Controllers /// public async Task MacchineUpsertAsync(MacchineModel entity) { - using (MoonProContext localDbCtx = new MoonProContext(_configuration)) + using (MoonProContext dbCtx = new MoonProContext(_configuration)) { // Recuperiamo l'entità tracciata dal context - var trackedEntity = await localDbCtx.DbSetMacchine.FirstOrDefaultAsync(x => x.IdxMacchina == entity.IdxMacchina); + var trackedEntity = await dbCtx.DbSetMacchine.FirstOrDefaultAsync(x => x.IdxMacchina == entity.IdxMacchina); if (trackedEntity != null) { // Aggiorna i valori dell'entità tracciata con quelli della nuova - localDbCtx.Entry(trackedEntity).CurrentValues.SetValues(entity); + dbCtx.Entry(trackedEntity).CurrentValues.SetValues(entity); } else { - localDbCtx.DbSetMacchine.Update(entity); + dbCtx.DbSetMacchine.Update(entity); } - return await localDbCtx.SaveChangesAsync() > 0; + return await dbCtx.SaveChangesAsync() > 0; } } diff --git a/MP.IOC/Components/Compo/ParetoDetail.razor.cs b/MP.IOC/Components/Compo/ParetoDetail.razor.cs index 45e46d93..843169a3 100644 --- a/MP.IOC/Components/Compo/ParetoDetail.razor.cs +++ b/MP.IOC/Components/Compo/ParetoDetail.razor.cs @@ -14,7 +14,19 @@ namespace MP.IOC.Components.Compo public List ParetoList { get; set; } = null!; [Parameter] - public string Title { get; set; } = null!; + public string Title + { + get => _title; + set + { + if (_title != value) + { + _title = value; + currSelect = ""; + } + } + } + private string _title { get; set; } = null!; #endregion Public Properties diff --git a/MP.IOC/Components/Pages/CallStats.razor.cs b/MP.IOC/Components/Pages/CallStats.razor.cs index d56668aa..08767393 100644 --- a/MP.IOC/Components/Pages/CallStats.razor.cs +++ b/MP.IOC/Components/Pages/CallStats.razor.cs @@ -127,6 +127,7 @@ namespace MP.IOC.Components.Pages currTsId = $"TS_{reqKey}"; currTitle = $"Pareto | {reqKey}"; currData = ParetoDay[reqKey]; + tsDataDetail = new(); } } diff --git a/MP.IOC/Controllers/IOBController.cs b/MP.IOC/Controllers/IOBController.cs index 1c58ef23..5fa06060 100644 --- a/MP.IOC/Controllers/IOBController.cs +++ b/MP.IOC/Controllers/IOBController.cs @@ -840,7 +840,7 @@ namespace MP.IOC.Controllers if (string.IsNullOrEmpty(id)) return BadRequest("Missing ID"); string answ = ""; - if (cnt == null) + if (string.IsNullOrEmpty(cnt)) { cnt = "0"; } diff --git a/MP.IOC/Data/MpDataService.cs b/MP.IOC/Data/MpDataService.cs index 434495af..62e209a8 100644 --- a/MP.IOC/Data/MpDataService.cs +++ b/MP.IOC/Data/MpDataService.cs @@ -571,7 +571,7 @@ namespace MP.IOC.Data inputComandoMapo answ = new inputComandoMapo(); // verifico se esista la macchina altrimenti la creo... REDIS compliant - verificaIdxMacchina(idxMacchina); + await verificaIdxMacchinaAsync(idxMacchina); // continuo processing... string CodArticolo = datiMacc["CodArticolo"]; @@ -654,7 +654,7 @@ namespace MP.IOC.Data answ = await scriviRigaEventoAsync(newRecEv); //currTask = scriviRigaEvento(idxMacchina, idxTipoEv, codArticolo, valEsteso, 0, "-", dtEve, DateTime.Now); // forzo RESET dati macchina... - ResetDatiMacchina(idxMacchina); + await ResetDatiMacchinaAsync(idxMacchina); } catch (Exception exc) { @@ -811,39 +811,6 @@ namespace MP.IOC.Data return result; } - public async Task> POdlGetByMaccArtAsync(string idxMacchina, string codArticolo, string codGruppo, bool onlyFree) - { - List result = new List(); - - var currKey = $"{Utils.redisPOdlByMaccArt}:{idxMacchina}"; - if (!string.IsNullOrEmpty(codArticolo)) - { - currKey += $":A{codArticolo}"; - } - if (!string.IsNullOrEmpty(codGruppo)) - { - currKey += $":G{codGruppo}"; - } - currKey += onlyFree ? $":FREE" : ":ALL"; - RedisValue rawData = await redisDb.StringGetAsync(currKey); - if (rawData.HasValue) - { - result = JsonConvert.DeserializeObject>($"{rawData}") ?? new(); - } - else - { - result = await IocDbController.POdlGetByMaccArtAsync(idxMacchina, codArticolo, codGruppo, onlyFree); - // serializzo e salvo... - rawData = JsonConvert.SerializeObject(result); - await redisDb.StringSetAsync(currKey, rawData, getRandTOut(redisLongTimeCache)); - } - if (result == null) - { - result = new List(); - } - return result; - } - /// /// Eliminazione di un dossier /// @@ -1447,6 +1414,32 @@ namespace MP.IOC.Data return result; } + public async Task> ListValuesFilt(string tabName, string fieldName) + { + List resultList = new List(); + string tag = ""; + tag += string.IsNullOrEmpty(tabName) ? "" : $"{tabName}:"; + tag += string.IsNullOrEmpty(fieldName) ? "" : $"{fieldName}:"; + var currKey = $"{Utils.redisConfFlux}:{tag}"; + RedisValue rawData = await redisDb.StringGetAsync(currKey); + if (rawData.HasValue) + { + resultList = JsonConvert.DeserializeObject>($"{rawData}") ?? new(); + } + else + { + resultList = await IocDbController.ListValuesFilt(tabName, fieldName); + // serializzo e salvo... + rawData = JsonConvert.SerializeObject(resultList); + await redisDb.StringSetAsync(currKey, rawData, getRandTOut(redisLongTimeCache)); + } + if (resultList == null) + { + resultList = new(); + } + return resultList; + } + /// /// Elenco completo valori Macchine 2 Slave /// @@ -2431,6 +2424,39 @@ namespace MP.IOC.Data return result; } + public async Task> POdlGetByMaccArtAsync(string idxMacchina, string codArticolo, string codGruppo, bool onlyFree) + { + List result = new List(); + + var currKey = $"{Utils.redisPOdlByMaccArt}:{idxMacchina}"; + if (!string.IsNullOrEmpty(codArticolo)) + { + currKey += $":A{codArticolo}"; + } + if (!string.IsNullOrEmpty(codGruppo)) + { + currKey += $":G{codGruppo}"; + } + currKey += onlyFree ? $":FREE" : ":ALL"; + RedisValue rawData = await redisDb.StringGetAsync(currKey); + if (rawData.HasValue) + { + result = JsonConvert.DeserializeObject>($"{rawData}") ?? new(); + } + else + { + result = await IocDbController.POdlGetByMaccArtAsync(idxMacchina, codArticolo, codGruppo, onlyFree); + // serializzo e salvo... + rawData = JsonConvert.SerializeObject(result); + await redisDb.StringSetAsync(currKey, rawData, getRandTOut(redisLongTimeCache)); + } + if (result == null) + { + result = new List(); + } + return result; + } + /// /// Recupero PODL da IdxODL /// @@ -2599,7 +2625,7 @@ namespace MP.IOC.Data // 2018.10.26 controllo dtEve e dtCurr if (dtEve == null || dtCurr == null) { - Log.Info(string.Format("procInput: valori nulli date: idxMacchina: {0} | valore: {1} | dtEve: {2} | dtCurr:{3}", idxMacchina, valore, dtEve, dtCurr)); + Log.Warn(string.Format("procInput: valori nulli date: idxMacchina: {0} | valore: {1} | dtEve: {2} | dtCurr:{3}", idxMacchina, valore, dtEve, dtCurr)); } else if (dtEve.Length < 17 || dtCurr.Length < 17) { @@ -2663,7 +2689,7 @@ namespace MP.IOC.Data // se ho deltaClass loggo if (deltaClass != "") { - Log.Info("Correzione " + deltaClass); + Log.Debug("Correzione " + deltaClass); } } catch (Exception exc) @@ -2677,7 +2703,7 @@ namespace MP.IOC.Data if (idxMacchina != "" && valore != "") { // se abilitato registro evento sul DB - if (idxMacchina != "" && sLogEnab(idxMacchina)) + if (!string.IsNullOrEmpty(idxMacchina) && await sLogEnabAsync(idxMacchina)) { int cntVal = 0; int.TryParse(contatore, out cntVal); @@ -3757,6 +3783,38 @@ namespace MP.IOC.Data return answ; } + /// + /// Restituisce il valore booleano se la macchina sia abilitata all'inserimento COMPLETO nel + /// Signal Log + /// + /// + /// + public async Task sLogEnabAsync(string idxMacchina) + { + bool answ = false; + // ORA recupero da memoria redis... + try + { + var currHash = Utils.RedKeyDatiMacc(idxMacchina, MpIoNS); + RedisValue rawData = await redisDb.HashGetAsync(currHash, (RedisValue)"sLogEnabled"); + // se è vuoto... leggo da DB e popolo! + if (!rawData.HasValue) + { + await ResetDatiMacchinaAsync(idxMacchina); + // riprovo + rawData = await redisDb.HashGetAsync(currHash, (RedisValue)"sLogEnabled"); + } + + // provo conversione + bool.TryParse($"{rawData}", out answ); + } + catch (Exception exc) + { + Log.Error($"Errore sLogEnabAsync | idxMacchina {idxMacchina}:{Environment.NewLine}{exc}"); + } + return answ; + } + /// /// Restitusice elenco KVP dei campi della State Machine ingressi nel formato /// currKey: cState_nVal (current MICRO-STATE + "_" + new Value) @@ -4171,32 +4229,6 @@ namespace MP.IOC.Data return resultList; } - public async Task> ListValuesFilt(string tabName, string fieldName) - { - List resultList = new List(); - string tag = ""; - tag += string.IsNullOrEmpty(tabName) ? "" : $"{tabName}:"; - tag += string.IsNullOrEmpty(fieldName) ? "" : $"{fieldName}:"; - var currKey = $"{Utils.redisConfFlux}:{tag}"; - RedisValue rawData = await redisDb.StringGetAsync(currKey); - if (rawData.HasValue) - { - resultList = JsonConvert.DeserializeObject>($"{rawData}") ?? new(); - } - else - { - resultList = await IocDbController.ListValuesFilt(tabName, fieldName); - // serializzo e salvo... - rawData = JsonConvert.SerializeObject(resultList); - await redisDb.StringSetAsync(currKey, rawData, getRandTOut(redisLongTimeCache)); - } - if (resultList == null) - { - resultList = new(); - } - return resultList; - } - /// /// Svuota la cache redis x l'elenco delle righe di confFlux x una macchina (se presenti) /// @@ -4889,6 +4921,60 @@ namespace MP.IOC.Data } } + /// + /// cerca codice in anagrafica macchine ed eventualmente inserisce nuova macchina + /// + /// + private async Task verificaIdxMacchinaAsync(string IdxMacchina) + { + bool needDB = false; + try + { + // esecuzione in REDIS...cerco status macchina... + if ((await mDatiMacchineAsync(IdxMacchina)).Count == 0) + { + needDB = true; + } + } + catch { } + + if (needDB) + { + // verifico se esiste su DB + var dbRec = await IocDbController.MacchineGetByIdxAsync(IdxMacchina); + if (dbRec == null) + { + MacchineModel newRec = new MacchineModel() + { + IdxMacchina = IdxMacchina, + CodMacchina = "0000", + Nome = IdxMacchina, + Descrizione = "Macchina non codificata", + Note = "-", + locazione = "", + RecipeArchivePath = "", + RecipePath = "" + }; + await IocDbController.MacchineUpsertAsync(newRec); + + // verifico ci sia un microstato macchina... + var recMSM = await IocDbController.MicroStatoMacchinaGetByIdxMaccAsync(IdxMacchina); + if (recMSM.Count == 0) + { + // inserisco nuovo stato... + MicroStatoMacchinaModel msRec = new MicroStatoMacchinaModel() + { + IdxMacchina = IdxMacchina, + IdxMicroStato = 0, + InizioStato = DateTime.Now, + Value = "00" + }; + await IocDbController.MicroStatoMacchinaUpsertAsync(msRec); + } + } + } + } + #endregion Private Methods #if false