diff --git a/MP-TAB-SERV/Components/OdlMan.razor.cs b/MP-TAB-SERV/Components/OdlMan.razor.cs index c605e701..6c7395cf 100644 --- a/MP-TAB-SERV/Components/OdlMan.razor.cs +++ b/MP-TAB-SERV/Components/OdlMan.razor.cs @@ -74,7 +74,7 @@ namespace MP_TAB_SERV.Components showAll = value; var pUpd = Task.Run(async () => { - await ReloadData(); + await ReloadData(true); }); pUpd.Wait(); } @@ -110,15 +110,17 @@ namespace MP_TAB_SERV.Components if (RecMSE != null) { IdxMaccSel = RecMSE.IdxMacchina; - await ReloadData(); + await ReloadData(true); } checkAll(); } + protected PzProdModel? prodMacchina = null; + protected override async Task OnParametersSetAsync() { isMulti = MServ.DictMacchMulti[RecMSE?.IdxMacchina] == 1; - await ReloadData(); + await ReloadData(false); } protected async Task SetMacc(string selIdxMacc) @@ -151,6 +153,7 @@ namespace MP_TAB_SERV.Components private bool isInAttr = false; private bool isInProd = false; private bool isMulti = false; + private bool isSlave = false; private bool isProcessing = false; private int numDayOdl = 5; @@ -179,7 +182,16 @@ namespace MP_TAB_SERV.Components private bool needConfProd { - get => (RecMSE != null && RecMSE.PezziProd > RecMSE.PezziConf); + get + { + bool answ = true; + if (prodMacchina != null) + { + answ = prodMacchina.pezziNonConfermati > 0 && !isSlave; + } + //(RecMSE != null && RecMSE.PezziProd > RecMSE.PezziConf); + return answ; + } } private int numPz2Conf @@ -240,13 +252,24 @@ namespace MP_TAB_SERV.Components } private static Logger Log = LogManager.GetCurrentClassLogger(); - private async Task ReloadData() + private async Task ReloadData(bool forceReload) { Log.Trace("OdlMan.ReloadData"); + if (forceReload) + { + isSlave = MServ.ListM2S + .Where(x => x.IdxMacchinaSlave.Equals(RecMSE?.IdxMacchina, StringComparison.InvariantCultureIgnoreCase)) + .ToList().Count > 0; + } if (!string.IsNullOrEmpty(IdxMaccSel)) { ListODL = await TabDServ.VSOdlGetUnused(idxMaccParent, ShowAll, numDayOdl); Log.Trace($"found {ListODL.Count} rec"); + if (forceReload) + { + var rawData = await TabDServ.PezziProdMacchina(IdxMaccSel); + prodMacchina = rawData.FirstOrDefault() ?? new PzProdModel(); + } } } diff --git a/MP-TAB-SERV/Shared/MainLayout.razor.cs b/MP-TAB-SERV/Shared/MainLayout.razor.cs index f7ada6bd..c20d5162 100644 --- a/MP-TAB-SERV/Shared/MainLayout.razor.cs +++ b/MP-TAB-SERV/Shared/MainLayout.razor.cs @@ -116,6 +116,10 @@ namespace MP_TAB_SERV.Shared // fix MSFD... var allMSFD = await TDataService.VMSFDGetAll(); MStor.SetMsfd(allMSFD); + // fix slave + var macSlave = await TDataService.Macchine2Slave(); + MStor.SetM2S(macSlave); + // fix elenco eventi var allEvents = await TDataService.AnagEventiGetAll(); MStor.SetEventi(allEvents); diff --git a/MP.Data/Controllers/MpTabController.cs b/MP.Data/Controllers/MpTabController.cs index 2443c599..5ab28b2e 100644 --- a/MP.Data/Controllers/MpTabController.cs +++ b/MP.Data/Controllers/MpTabController.cs @@ -646,6 +646,24 @@ namespace MP.Data.Controllers return fatto; } + /// + /// Intera tabella relazione master/slave in machine (gestione setup master --> slave) + /// + /// + public List Macchine2Slave() + { + List dbResult = new List(); + using (var dbCtx = new MoonProContext(_configuration)) + { + dbResult = dbCtx + .DbSetM2S + .AsNoTracking() + .OrderBy(x => x.IdxMacchina) + .ToList(); + } + return dbResult; + } + /// /// MicroStato macchina (da key) /// @@ -719,6 +737,26 @@ namespace MP.Data.Controllers return fatto; } + /// + /// Stato prod macchina + /// + /// + /// + public List PezziProdMacchina(string idxMacchina) + { + List dbResult = new List(); + using (var dbCtx = new MoonProContext(_configuration)) + { + var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina); + dbResult = dbCtx + .DbSetPzProd + .FromSqlRaw("EXEC stp_PzProd_getByMacchina @IdxMacchina", IdxMacchina) + .AsNoTracking() + .ToList(); + } + return dbResult; + } + /// /// Restituisce elenco RC filtrato /// @@ -942,6 +980,23 @@ namespace MP.Data.Controllers return answ; } + public bool SetDerogaSt(StCheckOverride deroga) + { + bool fatto = false; +#if false + try + { + string keyDerogaST = memLayer.ML.redHash($"DerogaSt:{user_std.UtSn.utente}:{deroga.IdxST:000}"); + string rawData = JsonConvert.SerializeObject(deroga); + memLayer.ML.setRSV(keyDerogaST, rawData, 60 * 2); + fatto = true; + } + catch + { } +#endif + return fatto; + } + /// /// Intera tabella state machine eventi 2 stati /// @@ -1053,6 +1108,7 @@ namespace MP.Data.Controllers } return fatto; } + public bool ST_CheckUpsert(int idxOdl, int idxST, int oggetto, int num, string valueRead, string extCode, bool checkOk, string userMod, bool forced) { bool fatto = false; @@ -1076,27 +1132,6 @@ namespace MP.Data.Controllers return fatto; } - /// - /// Recupero Righe pending da ODL - /// - /// - /// - public List STAR_pendByOdl(int idxODL) - { - List dbResult = new List(); - using (var dbCtx = new MoonProContext(_configuration)) - { - var IdxODL = new SqlParameter("@IdxODL", idxODL); - - dbResult = dbCtx - .DbSetStActRow - .FromSqlRaw("exec dbo.stp_ST_AR_getPendingOdl @IdxODL", IdxODL) - .AsNoTracking() - //.AsEnumerable() - .ToList(); - } - return dbResult; - } /// /// Recupero Righe (Actual) della scheda tecnica da GRUPPO + ODL /// @@ -1147,6 +1182,28 @@ namespace MP.Data.Controllers return dbResult; } + /// + /// Recupero Righe pending da ODL + /// + /// + /// + public List STAR_pendByOdl(int idxODL) + { + List dbResult = new List(); + using (var dbCtx = new MoonProContext(_configuration)) + { + var IdxODL = new SqlParameter("@IdxODL", idxODL); + + dbResult = dbCtx + .DbSetStActRow + .FromSqlRaw("exec dbo.stp_ST_AR_getPendingOdl @IdxODL", IdxODL) + .AsNoTracking() + //.AsEnumerable() + .ToList(); + } + return dbResult; + } + /// /// Intera tabella state machine ingressi 2 eventi data famiglia /// @@ -1292,23 +1349,6 @@ namespace MP.Data.Controllers return dbResult; } - public bool SetDerogaSt(StCheckOverride deroga) - { - bool fatto = false; -#if false - try - { - string keyDerogaST = memLayer.ML.redHash($"DerogaSt:{user_std.UtSn.utente}:{deroga.IdxST:000}"); - string rawData = JsonConvert.SerializeObject(deroga); - memLayer.ML.setRSV(keyDerogaST, rawData, 60 * 2); - fatto = true; - } - catch - { } -#endif - return fatto; - } - /// /// Elenco causali scarto /// @@ -1373,6 +1413,7 @@ namespace MP.Data.Controllers } return dbResult; } + #endregion Public Methods #region Private Fields diff --git a/MP.Data/Services/SharedMemService.cs b/MP.Data/Services/SharedMemService.cs index 4797d009..c5a84399 100644 --- a/MP.Data/Services/SharedMemService.cs +++ b/MP.Data/Services/SharedMemService.cs @@ -65,6 +65,13 @@ namespace MP.Data.Services /// public List ListStati { get; set; } = new List(); + /// + /// Lista macchine master2slave stati + /// + public List ListM2S { get; set; } = new List(); + + + /// /// Lista completa stati /// @@ -194,11 +201,17 @@ namespace MP.Data.Services public void SetMsfd(List newList) { ListMSFD = newList ?? new List(); - // salvo dizionario + // salvo dizionario MULTI DictMacchMulti = ListMSFD.ToDictionary(x => x.IdxMacchina, x => x.Multi); Log.Info("SharedMemService | SetMsfd executed!"); } + public void SetM2S(List newList) + { + ListM2S = newList ?? new List(); + Log.Info("SharedMemService | SetM2S executed!"); + } + public void SetStati(List allStati) { ListStati = allStati ?? new List(); diff --git a/MP.Data/Services/TabDataService.cs b/MP.Data/Services/TabDataService.cs index 458980aa..2328d68e 100644 --- a/MP.Data/Services/TabDataService.cs +++ b/MP.Data/Services/TabDataService.cs @@ -854,6 +854,42 @@ namespace MP.Data.Services return answ; } + /// + /// Intera tabella relazione master/slave in machine (gestione setup master --> slave) + /// + /// + public async Task> Macchine2Slave() + { + // setup parametri costanti + string source = "DB"; + Stopwatch sw = new Stopwatch(); + sw.Start(); + List result = new List(); + // cerco in redis... + string currKey = $"{redisBaseKey}:Mach2Slave"; + RedisValue rawData = await redisDb.StringGetAsync(currKey); + //if (!string.IsNullOrEmpty($"{rawData}")) + if (rawData.HasValue) + { + result = JsonConvert.DeserializeObject>($"{rawData}"); + source = "REDIS"; + } + else + { + result = dbTabController.Macchine2Slave(); + // serializzp e salvo... + rawData = JsonConvert.SerializeObject(result); + await redisDb.StringSetAsync(currKey, rawData, UltraFastCache); + } + if (result == null) + { + result = new List(); + } + sw.Stop(); + Log.Debug($"Macchine2Slave | {source} | {sw.Elapsed.TotalMilliseconds}ms"); + return result; + } + /// /// Lista parametri correnti (ObjItemDTO) della macchina /// @@ -997,6 +1033,43 @@ namespace MP.Data.Services return answ; } + /// + /// Stato prod macchina + /// + /// + /// + public async Task> PezziProdMacchina(string idxMacchina) + { + // setup parametri costanti + string source = "DB"; + Stopwatch sw = new Stopwatch(); + sw.Start(); + List result = new List(); + // cerco in redis... + string currKey = $"{redisBaseKey}:PzProd:{idxMacchina}"; + RedisValue rawData = await redisDb.StringGetAsync(currKey); + //if (!string.IsNullOrEmpty($"{rawData}")) + if (rawData.HasValue) + { + result = JsonConvert.DeserializeObject>($"{rawData}"); + source = "REDIS"; + } + else + { + result = dbTabController.PezziProdMacchina(idxMacchina); + // serializzp e salvo... + rawData = JsonConvert.SerializeObject(result); + await redisDb.StringSetAsync(currKey, rawData, UltraFastCache); + } + if (result == null) + { + result = new List(); + } + sw.Stop(); + Log.Debug($"PezziProdMacchina | {source} | {sw.Elapsed.TotalMilliseconds}ms"); + return result; + } + /// /// Restituisce elenco RC filtrato /// @@ -1406,7 +1479,6 @@ namespace MP.Data.Services return answ; } - public async Task ST_CheckUpsert(int idxOdl, int idxST, int oggetto, int num, string valueRead, string extCode, bool checkOk, string userMod, bool forced) { bool answ = false; @@ -1463,41 +1535,6 @@ namespace MP.Data.Services return fatto; } - /// - /// Recupero Righe pending da ODL - /// - /// - /// - public List STAR_pendByOdl(int idxODL) - { - // setup parametri costanti - string source = "DB"; - Stopwatch sw = new Stopwatch(); - sw.Start(); - List? result = new List(); - // cerco in redis... - string currKey = $"{redisBaseKey}:STAR:Pend:{idxODL}"; - RedisValue rawData = redisDb.StringGet(currKey); - if (rawData.HasValue) - { - result = JsonConvert.DeserializeObject>($"{rawData}"); - source = "REDIS"; - } - else - { - result = dbTabController.STAR_pendByOdl(idxODL); - // serializzp e salvo... - rawData = JsonConvert.SerializeObject(result); - redisDb.StringSet(currKey, rawData, TimeSpan.FromSeconds(5)); - } - if (result == null) - { - result = new List(); - } - sw.Stop(); - Log.Debug($"STAR_pendByOdl | {source} | {sw.Elapsed.TotalMilliseconds}ms"); - return result; - } /// /// Recupero Righe (Actual) della scheda tecnica da GRUPPO + ODL /// @@ -1575,6 +1612,42 @@ namespace MP.Data.Services return result; } + /// + /// Recupero Righe pending da ODL + /// + /// + /// + public List STAR_pendByOdl(int idxODL) + { + // setup parametri costanti + string source = "DB"; + Stopwatch sw = new Stopwatch(); + sw.Start(); + List? result = new List(); + // cerco in redis... + string currKey = $"{redisBaseKey}:STAR:Pend:{idxODL}"; + RedisValue rawData = redisDb.StringGet(currKey); + if (rawData.HasValue) + { + result = JsonConvert.DeserializeObject>($"{rawData}"); + source = "REDIS"; + } + else + { + result = dbTabController.STAR_pendByOdl(idxODL); + // serializzp e salvo... + rawData = JsonConvert.SerializeObject(result); + redisDb.StringSet(currKey, rawData, TimeSpan.FromSeconds(5)); + } + if (result == null) + { + result = new List(); + } + sw.Stop(); + Log.Debug($"STAR_pendByOdl | {source} | {sw.Elapsed.TotalMilliseconds}ms"); + return result; + } + /// /// Stato macchina ///