From 26e8ca037033a601d2662b7c8ae48cc9290e6044 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Sat, 30 May 2026 09:18:19 +0200 Subject: [PATCH] Fix gestione reparti/operatore --- MP.Data/Controllers/MpSpecController.cs | 88 +++++++++---------- .../Components/Reparti/ListMacchine.razor.cs | 4 +- .../Components/Reparti/ListOperatori.razor.cs | 4 +- .../Components/Reparti/ListReparti.razor.cs | 18 ++-- MP.SPEC/Data/MpDataService.cs | 60 ++++++------- MP.SPEC/MP.SPEC.csproj | 2 +- MP.SPEC/Pages/RepOper.razor | 2 +- MP.SPEC/Pages/RepOper.razor.cs | 6 +- MP.SPEC/Resources/ChangeLog.html | 2 +- MP.SPEC/Resources/VersNum.txt | 2 +- MP.SPEC/Resources/manifest.xml | 2 +- Refactor_Plan.md | 3 +- 12 files changed, 97 insertions(+), 96 deletions(-) diff --git a/MP.Data/Controllers/MpSpecController.cs b/MP.Data/Controllers/MpSpecController.cs index 45e911b3..a0b20991 100644 --- a/MP.Data/Controllers/MpSpecController.cs +++ b/MP.Data/Controllers/MpSpecController.cs @@ -1175,21 +1175,19 @@ namespace MP.Data.Controllers /// /// /// - public bool Grp2MaccDelete(Gruppi2MaccModel rec2del) + public async Task Grp2MaccDeleteAsync(Gruppi2MaccModel rec2del) { bool answ = false; - using (var dbCtx = new MoonProContext(options)) + using var dbCtx = new MoonProContext(options); + var dbRec = await dbCtx + .DbSetGrp2Macc + .Where(x => x.CodGruppo == rec2del.CodGruppo && x.IdxMacchina == rec2del.IdxMacchina) + .FirstOrDefaultAsync(); + if (dbRec != null) { - var dbRec = dbCtx - .DbSetGrp2Macc - .Where(x => x.CodGruppo == rec2del.CodGruppo && x.IdxMacchina == rec2del.IdxMacchina) - .FirstOrDefault(); - if (dbRec != null) - { - dbCtx.DbSetGrp2Macc.Remove(dbRec); - int numDone = dbCtx.SaveChanges(); - answ = numDone != 0; - } + dbCtx.DbSetGrp2Macc.Remove(dbRec); + int numDone = await dbCtx.SaveChangesAsync(); + answ = numDone != 0; } return answ; } @@ -1199,22 +1197,20 @@ namespace MP.Data.Controllers /// /// /// - public bool Grp2MaccInsert(Gruppi2MaccModel upsRec) + public async Task Grp2MaccInsertAsync(Gruppi2MaccModel upsRec) { bool answ = false; - using (var dbCtx = new MoonProContext(options)) + using var dbCtx = new MoonProContext(options); + var dbRec = await dbCtx + .DbSetGrp2Macc + .Where(x => x.CodGruppo == upsRec.CodGruppo && x.IdxMacchina == upsRec.IdxMacchina) + .FirstOrDefaultAsync(); + if (dbRec == null) { - var dbRec = dbCtx - .DbSetGrp2Macc - .Where(x => x.CodGruppo == upsRec.CodGruppo && x.IdxMacchina == upsRec.IdxMacchina) - .FirstOrDefault(); - if (dbRec == null) - { - dbCtx.DbSetGrp2Macc.Add(upsRec); - // salvo - int numDone = dbCtx.SaveChanges(); - answ = numDone != 0; - } + await dbCtx.DbSetGrp2Macc.AddAsync(upsRec); + // salvo + int numDone = await dbCtx.SaveChangesAsync(); + answ = numDone != 0; } return answ; } @@ -1224,21 +1220,19 @@ namespace MP.Data.Controllers /// /// /// - public bool Grp2OperDelete(Gruppi2OperModel rec2del) + public async Task Grp2OperDeleteAsync(Gruppi2OperModel rec2del) { bool answ = false; - using (var dbCtx = new MoonProContext(options)) - { - var dbRec = dbCtx + using var dbCtx = new MoonProContext(options); + var dbRec = await dbCtx .DbSetGrp2Oper .Where(x => x.CodGruppo == rec2del.CodGruppo && x.MatrOpr == rec2del.MatrOpr) - .FirstOrDefault(); - if (dbRec != null) - { - dbCtx.DbSetGrp2Oper.Remove(dbRec); - int numDone = dbCtx.SaveChanges(); - answ = numDone != 0; - } + .FirstOrDefaultAsync(); + if (dbRec != null) + { + dbCtx.DbSetGrp2Oper.Remove(dbRec); + int numDone = await dbCtx.SaveChangesAsync(); + answ = numDone != 0; } return answ; } @@ -1248,22 +1242,20 @@ namespace MP.Data.Controllers /// /// /// - public bool Grp2OperInsert(Gruppi2OperModel upsRec) + public async Task Grp2OperInsertAsync(Gruppi2OperModel upsRec) { bool answ = false; - using (var dbCtx = new MoonProContext(options)) - { - var dbRec = dbCtx + using var dbCtx = new MoonProContext(options); + var dbRec = await dbCtx .DbSetGrp2Oper .Where(x => x.CodGruppo == upsRec.CodGruppo && x.MatrOpr == upsRec.MatrOpr) - .FirstOrDefault(); - if (dbRec == null) - { - dbCtx.DbSetGrp2Oper.Add(upsRec); - // salvo - int numDone = dbCtx.SaveChanges(); - answ = numDone != 0; - } + .FirstOrDefaultAsync(); + if (dbRec == null) + { + await dbCtx.DbSetGrp2Oper.AddAsync(upsRec); + // salvo + int numDone = await dbCtx.SaveChangesAsync(); + answ = numDone != 0; } return answ; } diff --git a/MP.SPEC/Components/Reparti/ListMacchine.razor.cs b/MP.SPEC/Components/Reparti/ListMacchine.razor.cs index f8a2d32c..cd163788 100644 --- a/MP.SPEC/Components/Reparti/ListMacchine.razor.cs +++ b/MP.SPEC/Components/Reparti/ListMacchine.razor.cs @@ -100,7 +100,7 @@ namespace MP.SPEC.Components.Reparti CodGruppo = CodGruppoCurr, IdxMacchina = currRec.IdxMacchina }; - MDService.Grp2MaccInsert(rec2del); + await MDService.Grp2MaccInsertAsync(rec2del); await EC_RecChange.InvokeAsync(false); } @@ -115,7 +115,7 @@ namespace MP.SPEC.Components.Reparti CodGruppo = CodGruppoCurr, IdxMacchina = currRec.IdxMacchina }; - MDService.Grp2MaccDelete(rec2del); + await MDService.Grp2MaccDeleteAsync(rec2del); await EC_RecChange.InvokeAsync(false); } diff --git a/MP.SPEC/Components/Reparti/ListOperatori.razor.cs b/MP.SPEC/Components/Reparti/ListOperatori.razor.cs index a6cedabb..2ca7dcab 100644 --- a/MP.SPEC/Components/Reparti/ListOperatori.razor.cs +++ b/MP.SPEC/Components/Reparti/ListOperatori.razor.cs @@ -101,7 +101,7 @@ namespace MP.SPEC.Components.Reparti CodGruppo = CodGruppoCurr, MatrOpr = currRec.MatrOpr }; - MDService.Grp2OperInsert(rec2del); + await MDService.Grp2OperInsertAsync(rec2del); await EC_RecChange.InvokeAsync(false); } @@ -116,7 +116,7 @@ namespace MP.SPEC.Components.Reparti CodGruppo = CodGruppoCurr, MatrOpr = currRec.MatrOpr }; - MDService.Grp2OperDelete(rec2del); + await MDService.Grp2OperDeleteAsync(rec2del); await EC_RecChange.InvokeAsync(false); } diff --git a/MP.SPEC/Components/Reparti/ListReparti.razor.cs b/MP.SPEC/Components/Reparti/ListReparti.razor.cs index 0707f871..1582c6fa 100644 --- a/MP.SPEC/Components/Reparti/ListReparti.razor.cs +++ b/MP.SPEC/Components/Reparti/ListReparti.razor.cs @@ -14,6 +14,9 @@ namespace MP.SPEC.Components.Reparti [Parameter] public List? AllRecords { get; set; } = null; + [Parameter] + public string CodGruppoSel { get; set; } = null!; + [Parameter] public EventCallback EC_RecordSel { get; set; } @@ -24,11 +27,6 @@ namespace MP.SPEC.Components.Reparti #region Protected Properties - protected bool IsSuperAdmin - { - get => HasRole(AppAuthService.RoleSuperAdmin); - } - [Inject] protected IJSRuntime JSRuntime { get; set; } = null!; @@ -62,6 +60,11 @@ namespace MP.SPEC.Components.Reparti protected override void OnParametersSet() { isLoading = true; + // verifico se ho gruppo sel... + if (!string.IsNullOrEmpty(CodGruppoSel) && AllRecords != null && AllRecords.Any()) + { + SelRecord = AllRecords.FirstOrDefault(x => x.CodGruppo == CodGruppoSel); + } UpdateTable(); isLoading = false; } @@ -116,6 +119,11 @@ namespace MP.SPEC.Components.Reparti get => EditRec == null ? "Aggiungi Reparto" : "Chiudi/Annulla"; } + private bool IsSuperAdmin + { + get => HasRole(AppAuthService.RoleSuperAdmin); + } + #endregion Private Properties #region Private Methods diff --git a/MP.SPEC/Data/MpDataService.cs b/MP.SPEC/Data/MpDataService.cs index cb599b90..e7ba4a1a 100644 --- a/MP.SPEC/Data/MpDataService.cs +++ b/MP.SPEC/Data/MpDataService.cs @@ -1065,16 +1065,16 @@ namespace MP.SPEC.Data /// /// /// - public bool Grp2MaccDelete(Gruppi2MaccModel rec2del) + public async Task Grp2MaccDeleteAsync(Gruppi2MaccModel rec2del) { - using var activity = ActivitySource.StartActivity("Grp2MaccDelete"); + using var activity = ActivitySource.StartActivity("Grp2MaccDeleteAsync"); bool result = false; - result = dbController.Grp2MaccDelete(rec2del); + result = await dbController.Grp2MaccDeleteAsync(rec2del); // elimino cache redis... - ResetMacGrpCache(); - activity?.SetTag("data.source", "DB+REDIS"); + await ResetMacGrpCache(); + activity?.SetTag("data.source", "DB"); activity?.Stop(); - LogTrace($"Grp2MaccDelete | CodGruppo {rec2del.CodGruppo} | IdxMacc {rec2del.IdxMacchina} | {activity?.Duration.TotalMilliseconds}ms"); + LogTrace($"Grp2MaccDeleteAsync | CodGruppo {rec2del.CodGruppo} | IdxMacc {rec2del.IdxMacchina} | {activity?.Duration.TotalMilliseconds}ms"); return result; } @@ -1083,16 +1083,16 @@ namespace MP.SPEC.Data /// /// /// - public bool Grp2MaccInsert(Gruppi2MaccModel upsRec) + public async Task Grp2MaccInsertAsync(Gruppi2MaccModel upsRec) { - using var activity = ActivitySource.StartActivity("Grp2MaccInsert"); + using var activity = ActivitySource.StartActivity("Grp2MaccInsertAsync"); bool result = false; - result = dbController.Grp2MaccInsert(upsRec); + result = await dbController.Grp2MaccInsertAsync(upsRec); // elimino cache redis... - ResetMacGrpCache(); - activity?.SetTag("data.source", "DB+REDIS"); + await ResetMacGrpCache(); + activity?.SetTag("data.source", "DB"); activity?.Stop(); - LogTrace($"Grp2MaccInsert | CodGruppo {upsRec.CodGruppo} | IdxMacc {upsRec.IdxMacchina} | {activity?.Duration.TotalMilliseconds}ms"); + LogTrace($"Grp2MaccInsertAsync | CodGruppo {upsRec.CodGruppo} | IdxMacc {upsRec.IdxMacchina} | {activity?.Duration.TotalMilliseconds}ms"); return result; } @@ -1101,16 +1101,16 @@ namespace MP.SPEC.Data /// /// /// - public bool Grp2OperDelete(Gruppi2OperModel rec2del) + public async Task Grp2OperDeleteAsync(Gruppi2OperModel rec2del) { - using var activity = ActivitySource.StartActivity("Grp2OperDelete"); + using var activity = ActivitySource.StartActivity("Grp2OperDeleteAsync"); bool result = false; - result = dbController.Grp2OperDelete(rec2del); + result = await dbController.Grp2OperDeleteAsync(rec2del); // elimino cache redis... - ResetOprGrpCache(); - activity?.SetTag("data.source", "DB+REDIS"); + await ResetOprGrpCache(); + activity?.SetTag("data.source", "DB"); activity?.Stop(); - LogTrace($"Grp2OperDelete | CodGruppo {rec2del.CodGruppo} | MatrOpr {rec2del.MatrOpr} | {activity?.Duration.TotalMilliseconds}ms"); + LogTrace($"Grp2OperDeleteAsync | CodGruppo {rec2del.CodGruppo} | MatrOpr {rec2del.MatrOpr} | {activity?.Duration.TotalMilliseconds}ms"); return result; } @@ -1119,16 +1119,16 @@ namespace MP.SPEC.Data /// /// /// - public bool Grp2OperInsert(Gruppi2OperModel upsRec) + public async Task Grp2OperInsertAsync(Gruppi2OperModel upsRec) { - using var activity = ActivitySource.StartActivity("Grp2OperInsert"); + using var activity = ActivitySource.StartActivity("Grp2OperInsertAsync"); bool result = false; - result = dbController.Grp2OperInsert(upsRec); + result = await dbController.Grp2OperInsertAsync(upsRec); // elimino cache redis... - ResetOprGrpCache(); - activity?.SetTag("data.source", "DB+REDIS"); + await ResetOprGrpCache(); + activity?.SetTag("data.source", "DB"); activity?.Stop(); - LogTrace($"Grp2OperInsert | CodGruppo {upsRec.CodGruppo} | MatrOpr {upsRec.MatrOpr} | {activity?.Duration.TotalMilliseconds}ms"); + LogTrace($"Grp2OperInsertAsync | CodGruppo {upsRec.CodGruppo} | MatrOpr {upsRec.MatrOpr} | {activity?.Duration.TotalMilliseconds}ms"); return result; } @@ -2579,19 +2579,19 @@ namespace MP.SPEC.Data /// /// Reset macchine e gruppi /// - private void ResetMacGrpCache() + private async Task ResetMacGrpCache() { - ExecFlushRedisPattern($"{Utils.redisAnagGruppi}:*"); - ExecFlushRedisPattern($"{Utils.redisMacList}:*"); + await FlushCacheByTagsAsync(new List { Utils.redisAnagGruppi, Utils.redisMacList }); } /// /// Reset cache operatori e gruppi /// - private void ResetOprGrpCache() + private async Task ResetOprGrpCache() { - ExecFlushRedisPattern($"{Utils.redisAnagGruppi}:*"); - ExecFlushRedisPattern($"{Utils.redisOprList}:*"); + //ExecFlushRedisPattern($"{Utils.redisAnagGruppi}:*"); + //ExecFlushRedisPattern($"{Utils.redisOprList}:*"); + await FlushCacheByTagsAsync(new List { Utils.redisAnagGruppi, Utils.redisOprList }); } #endregion Private Methods diff --git a/MP.SPEC/MP.SPEC.csproj b/MP.SPEC/MP.SPEC.csproj index 10ab6e68..b0dddc59 100644 --- a/MP.SPEC/MP.SPEC.csproj +++ b/MP.SPEC/MP.SPEC.csproj @@ -5,7 +5,7 @@ enable enable MP.SPEC - 8.16.2605.3007 + 8.16.2605.3009 1800a78a-6ff1-40f9-b490-87fb8bfc1394 en diff --git a/MP.SPEC/Pages/RepOper.razor b/MP.SPEC/Pages/RepOper.razor index 6e30fd89..22084e57 100644 --- a/MP.SPEC/Pages/RepOper.razor +++ b/MP.SPEC/Pages/RepOper.razor @@ -37,7 +37,7 @@
- +
@if (ShowDetail) { diff --git a/MP.SPEC/Pages/RepOper.razor.cs b/MP.SPEC/Pages/RepOper.razor.cs index 7ff923d2..0dda2fc3 100644 --- a/MP.SPEC/Pages/RepOper.razor.cs +++ b/MP.SPEC/Pages/RepOper.razor.cs @@ -89,10 +89,10 @@ namespace MP.SPEC.Pages private async Task ReloadDataAsync() { isLoading = true; - ListMacchine?.Clear(); - ListReparti?.Clear(); - if (string.IsNullOrEmpty(CodGruppo)) + //ListMacchine?.Clear(); + if (string.IsNullOrEmpty(CodGruppo) || true) { + ListReparti?.Clear(); var rawList = await MDService.ElencoRepartiDtoAsync(); if (string.IsNullOrEmpty(SearchVal)) { diff --git a/MP.SPEC/Resources/ChangeLog.html b/MP.SPEC/Resources/ChangeLog.html index 2f246f77..67011e00 100644 --- a/MP.SPEC/Resources/ChangeLog.html +++ b/MP.SPEC/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MAPOSPEC -

Versione: 8.16.2605.3007

+

Versione: 8.16.2605.3009


Note di rilascio:
  • diff --git a/MP.SPEC/Resources/VersNum.txt b/MP.SPEC/Resources/VersNum.txt index a025c228..77349332 100644 --- a/MP.SPEC/Resources/VersNum.txt +++ b/MP.SPEC/Resources/VersNum.txt @@ -1 +1 @@ -8.16.2605.3007 +8.16.2605.3009 diff --git a/MP.SPEC/Resources/manifest.xml b/MP.SPEC/Resources/manifest.xml index f5b17fe1..8818602e 100644 --- a/MP.SPEC/Resources/manifest.xml +++ b/MP.SPEC/Resources/manifest.xml @@ -1,6 +1,6 @@ - 8.16.2605.3007 + 8.16.2605.3009 https://nexus.steamware.net/repository/SWS/MP-SPEC/stable/LAST/MP.SPEC.zip https://nexus.steamware.net/repository/SWS/MP-SPEC/stable/LAST/ChangeLog.html false diff --git a/Refactor_Plan.md b/Refactor_Plan.md index 5be856a1..ed85dfe8 100644 --- a/Refactor_Plan.md +++ b/Refactor_Plan.md @@ -46,7 +46,7 @@ Migrare la logica di caching manuale (Redis + DB) verso l'utilizzo di `IFusionCa - `OdlListGetFiltAsync` - `OperatoriGetFiltAsync` - `ParametriGetFiltAsync` -- `PODL_getDictOdlPodlAsync` (Parziale/Ibrido) +- `PODL_getDictOdlPodlAsync` (Migrato con gestione manuale L1/L2) - `POdlGetByOdlAsync` - `POdlToKitListGetFiltAsync` - `StatoMacchinaAsync` @@ -87,3 +87,4 @@ Migrare la logica di caching manuale (Redis + DB) verso l'utilizzo di `IFusionCa - *Mitigazione*: `FusionCache` gestisce la serializzazione, ma รจ necessario assicurarsi che i tipi di ritorno siano compatibili con le aspettative dei chiamanti. +