From 843435ad3bd25abe45710b2a6da1201fd30c4010 Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli (W11-AI)" Date: Tue, 2 Jun 2026 20:02:38 +0200 Subject: [PATCH] Continua revisione codice assisted --- MP.Data/DataServiceCollectionExtensions.cs | 1 + MP.Data/Repository/Anag/AnagRepository.cs | 7 +- MP.Data/Repository/Anag/IAnagRepository.cs | 4 +- .../Repository/Dossier/DossierRepository.cs | 12 ++ .../Repository/Dossier/IDossierRepository.cs | 2 + MP.Data/Services/ListSelectDataSrv.cs | 4 +- MP.SPEC/Data/MpDataService.cs | 163 +++++++++--------- 7 files changed, 99 insertions(+), 94 deletions(-) diff --git a/MP.Data/DataServiceCollectionExtensions.cs b/MP.Data/DataServiceCollectionExtensions.cs index 5985cf22..44116d5c 100644 --- a/MP.Data/DataServiceCollectionExtensions.cs +++ b/MP.Data/DataServiceCollectionExtensions.cs @@ -78,6 +78,7 @@ namespace MP.Data // ---------- Start Altro ---------- // Singleton services.TryAddSingleton(); + services.TryAddScoped(); services.TryAddSingleton(); services.TryAddSingleton(); services.TryAddSingleton(); diff --git a/MP.Data/Repository/Anag/AnagRepository.cs b/MP.Data/Repository/Anag/AnagRepository.cs index 3fbfce71..a4a00cf8 100644 --- a/MP.Data/Repository/Anag/AnagRepository.cs +++ b/MP.Data/Repository/Anag/AnagRepository.cs @@ -431,14 +431,13 @@ namespace MP.Data.Repository.Anag } /// - /// Recupero dizionario traduzioni da cache o DB - + /// Recupero dizionario traduzioni /// /// Codice lingua /// Dizionario di traduzioni - public async Task> VocabolarioGetLangAsync(string lingua) + public Dictionary VocabolarioGetLang(string lingua) { - await using var dbCtx = await CreateContextAsync(); + using var dbCtx = _ctxFactory.CreateDbContextAsync().GetAwaiter().GetResult(); var rawList = dbCtx .DbSetVocabolario .AsNoTracking() diff --git a/MP.Data/Repository/Anag/IAnagRepository.cs b/MP.Data/Repository/Anag/IAnagRepository.cs index 953fdd32..7b943098 100644 --- a/MP.Data/Repository/Anag/IAnagRepository.cs +++ b/MP.Data/Repository/Anag/IAnagRepository.cs @@ -191,11 +191,11 @@ namespace MP.Data.Repository.Anag Task> PODL_getDictOdlPodlAsync(List missingIds); /// - /// Recupero dizionario traduzioni da cache o DB + /// Recupero dizionario traduzioni /// /// Codice lingua /// Dizionario di traduzioni - Task> VocabolarioGetLangAsync(string lingua); + Dictionary VocabolarioGetLang(string lingua); #endregion Public Methods } diff --git a/MP.Data/Repository/Dossier/DossierRepository.cs b/MP.Data/Repository/Dossier/DossierRepository.cs index 91f26562..4fcf2319 100644 --- a/MP.Data/Repository/Dossier/DossierRepository.cs +++ b/MP.Data/Repository/Dossier/DossierRepository.cs @@ -104,6 +104,18 @@ namespace MP.Data.Repository.Dossier return await dbCtx.SaveChangesAsync() > 0; } + /// + public async Task> ArticleWithDossierAsync() + { + await using var dbCtx = new MoonPro_FluxContext(_configuration); + return await dbCtx + .DbSetDossiers + .AsNoTracking() + .Select(i => i.CodArticolo) + .Distinct() + .ToListAsync(); + } + #endregion } } diff --git a/MP.Data/Repository/Dossier/IDossierRepository.cs b/MP.Data/Repository/Dossier/IDossierRepository.cs index 3f6852bd..73164af9 100644 --- a/MP.Data/Repository/Dossier/IDossierRepository.cs +++ b/MP.Data/Repository/Dossier/IDossierRepository.cs @@ -19,6 +19,8 @@ namespace MP.Data.Repository.Dossier Task DossiersUpdateValoreAsync(DossierModel editRec); + Task> ArticleWithDossierAsync(); + #endregion } } diff --git a/MP.Data/Services/ListSelectDataSrv.cs b/MP.Data/Services/ListSelectDataSrv.cs index 689827e2..af6b8aef 100644 --- a/MP.Data/Services/ListSelectDataSrv.cs +++ b/MP.Data/Services/ListSelectDataSrv.cs @@ -1,8 +1,8 @@ using Microsoft.Extensions.Configuration; -using MP.Core.Objects; using MP.Data.DbModels; using MP.Data.Repository.Anag; using MP.Data.Repository.Production; +using MP.Data.Repository.System; using Newtonsoft.Json; using NLog; using StackExchange.Redis; @@ -10,7 +10,7 @@ using System; using System.Collections.Generic; using System.Data; using System.Diagnostics; -using System.Text; +using System.Linq; using System.Threading.Tasks; namespace MP.Data.Services diff --git a/MP.SPEC/Data/MpDataService.cs b/MP.SPEC/Data/MpDataService.cs index e000ad5a..fb8b75b2 100644 --- a/MP.SPEC/Data/MpDataService.cs +++ b/MP.SPEC/Data/MpDataService.cs @@ -7,6 +7,10 @@ using MP.Data.Controllers; using MP.Data.DbModels; using MP.Data.MgModels; using MP.Data.Repository.Anag; +using MP.Data.Repository.Dossier; +using MP.Data.Repository.FluxLog; +using MP.Data.Repository.Production; +using MP.Data.Repository.System; using MP.Data.Services; using Newtonsoft.Json; using NLog; @@ -22,48 +26,33 @@ namespace MP.SPEC.Data #region Public Constructors private readonly IAnagRepository _anagRepository; + private readonly ISystemRepository _systemRepository; + private readonly IDossierRepository _dossierRepository; + private readonly IFluxLogRepository _fluxLogRepository; + private readonly IProductionRepository _productionRepository; - public MpDataService(IConfiguration configuration, IFusionCache cache, IAnagRepository anagRepository) + public MpDataService(IConfiguration configuration, IFusionCache cache, IAnagRepository anagRepository, ISystemRepository systemRepository, IDossierRepository dossierRepository, IFluxLogRepository fluxLogRepository, IProductionRepository productionRepository) { // salvataggio oggetti _configuration = configuration; _cache = cache; _anagRepository = anagRepository; + _systemRepository = systemRepository; + _dossierRepository = dossierRepository; + _fluxLogRepository = fluxLogRepository; + _productionRepository = productionRepository; // Verifica conf trace... traceEnabled = _configuration.GetValue("Otel:EnableTracing", false); slowLogThresh = _configuration.GetValue("ServerConf:slowLogThresh", 1); Log.Info($"MpDataService | INIT | Trace enabled: {traceEnabled}"); // setup compoenti REDIS - redisConn = ConnectionMultiplexer.Connect(_configuration.GetConnectionString("Redis") ?? "localhost:6379"); - redisConnAdmin = ConnectionMultiplexer.Connect(_configuration.GetConnectionString("RedisAdmin") ?? "localhost:6379"); - redisDb = redisConn.GetDatabase(); - // leggo cache lungo/cordo periodo - int.TryParse(_configuration.GetValue("ServerConf:redisShortTimeCache"), out redisShortTimeCache); - int.TryParse(_configuration.GetValue("ServerConf:redisLongTimeCache"), out redisLongTimeCache); - - // setup MsgPipe - BroadastMsgPipe = new MessagePipe(redisConn, Constants.BROADCAST_M_PIPE); - Log.Info("MpDataService | Redis OK"); - - // conf DB - string connStr = _configuration.GetConnectionString("MP.Data") ?? ""; - if (string.IsNullOrEmpty(connStr)) - { - Log.Error("DbController: ConnString empty!"); - } - else - { - dbController = new MpSpecController(configuration); - Log.Info("DbController OK"); - } - // conf x lettura dati da area REDIS di MP-IO MpIoNS = _configuration.GetValue("ServerConf:MpIoNS") ?? ""; // conf mongo... - connStr = _configuration.GetConnectionString("mdbConnString") ?? ""; - if (string.IsNullOrEmpty(connStr)) + string mongoConnStr = _configuration.GetConnectionString("mdbConnString") ?? ""; + if (string.IsNullOrEmpty(mongoConnStr)) { Log.Error("MongoController: ConnString empty!"); } @@ -246,8 +235,9 @@ namespace MP.SPEC.Data ); } +#if false /// - /// Elenco Codice articolo con dati dossier gestiti + /// Elenco codice articoli che abbiano dati Dossier /// /// public async Task> ArticleWithDossierAsync() @@ -256,10 +246,11 @@ namespace MP.SPEC.Data operationName: "ArticleWithDossierAsync", cacheKey: Utils.redisArtByDossier, expiration: GetRandTOut(redisLongTimeCache), - fetchFunc: async () => await dbController.ArticleWithDossierAsync() ?? new List(), + fetchFunc: async () => await _dossierRepository.ArticleWithDossierAsync() ?? new List(), tagList: [Utils.redisArtByDossier] ); } +#endif /// /// Conteggio articoli data ricerca @@ -444,7 +435,7 @@ namespace MP.SPEC.Data operationName: "ConfigGetAllAsync", cacheKey: Utils.redisConfAll, expiration: GetRandTOut(redisLongTimeCache * 2), - fetchFunc: async () => await dbController.ConfigGetAllAsync() ?? new List(), + fetchFunc: async () => await _systemRepository.ConfigGetAllAsync() ?? new List(), tagList: [Utils.redisConfAll] ); } @@ -494,7 +485,7 @@ namespace MP.SPEC.Data { using var activity = ActivitySource.StartActivity("ConfigUpdateAsync"); string source = "DB"; - var updRes = await dbController.ConfigUpdateAsync(updRec); + var updRes = await _systemRepository.ConfigUpdateAsync(updRec); await FlushFusionCacheConfig(); activity?.SetTag("data.source", source); activity?.Stop(); @@ -547,7 +538,7 @@ namespace MP.SPEC.Data { using var activity = ActivitySource.StartActivity("DossiersDeleteRecordAsync"); bool result = false; - result = await dbController.DossiersDeleteRecordAsync(selRecord); + result = await _dossierRepository.DossiersDeleteRecordAsync(selRecord); // elimino cache... await FlushFusionCacheAsync(Utils.redisDossByMac); activity?.SetTag("data.source", "DB"); @@ -572,7 +563,7 @@ namespace MP.SPEC.Data operationName: "DossiersGetLastFiltAsync", cacheKey: currKey, expiration: GetRandTOut(redisLongTimeCache * 5), - fetchFunc: async () => await dbController.DossiersGetLastFiltAsync(IdxMacchina, CodArticolo, DtStart, DtEnd, MaxRec) ?? new List(), + fetchFunc: async () => await _dossierRepository.DossiersGetLastFiltAsync(IdxMacchina, CodArticolo, DtStart, DtEnd, MaxRec) ?? new List(), tagList: [Utils.redisDossByMac] ); } @@ -587,7 +578,7 @@ namespace MP.SPEC.Data using var activity = ActivitySource.StartActivity("DossiersInsertAsync"); string source = "DB"; // aggiorno record sul DB - bool answ = await dbController.DossiersInsertAsync(currDoss); + bool answ = await _dossierRepository.DossiersInsertAsync(currDoss); answ = await FlushFusionCacheAsync(Utils.redisDossByMac); activity?.SetTag("data.source", source); activity?.Stop(); @@ -609,7 +600,7 @@ namespace MP.SPEC.Data bool answ = false; Log.Info($"Richiesta snapshot per idxMaccSel {IdxMacchina} | periodo {dtMin} --> {dtMax}"); // chiamo stored x salvare parametri - await dbController.DossiersTakeParamsSnapshotLastAsync(IdxMacchina, dtMin, dtMax); + await _dossierRepository.DossiersTakeParamsSnapshotLastAsync(IdxMacchina, dtMin, dtMax); // elimino cache... answ = await FlushFusionCacheAsync(Utils.redisDossByMac); activity?.SetTag("data.source", source); @@ -628,7 +619,7 @@ namespace MP.SPEC.Data using var activity = ActivitySource.StartActivity("DossiersUpdateValoreAsync"); string source = "DB"; // aggiorno record sul DB - bool answ = await dbController.DossiersUpdateValoreAsync(currDoss); + bool answ = await _dossierRepository.DossiersUpdateValoreAsync(currDoss); answ = await FlushFusionCacheAsync(Utils.redisDossByMac); activity?.SetTag("data.source", source); activity?.Stop(); @@ -677,7 +668,7 @@ namespace MP.SPEC.Data operationName: "ElencoLinkAsync", cacheKey: Utils.redisLinkMenu, expiration: GetRandTOut(redisLongTimeCache), - fetchFunc: async () => await dbController.ElencoLinkAsync() ?? new List(), + fetchFunc: async () => await _systemRepository.ElencoLinkAsync() ?? new List(), tagList: [Utils.redisLinkMenu] ); } @@ -745,7 +736,7 @@ namespace MP.SPEC.Data { using var activity = ActivitySource.StartActivity("EvListInsertAsync"); string source = "DB"; - var result = await dbController.EvListInsertAsync(newRec); + var result = await _systemRepository.EvListInsertAsync(newRec); activity?.SetTag("data.source", source); activity?.Stop(); LogTrace($"EvListInsertAsync | Read from {source}: {activity?.Duration.TotalMilliseconds}ms"); @@ -785,7 +776,7 @@ namespace MP.SPEC.Data { using var activity = ActivitySource.StartActivity("FluxLogDataReduxAsync"); string source = "DB"; - List procStats = await dbController.FluxLogDataReduxAsync(idxMaccSel, fluxList, currPeriodo, valMode, intReq, maxItem); + List procStats = await _fluxLogRepository.FluxLogDataReduxAsync(idxMaccSel, fluxList, currPeriodo, valMode, intReq, maxItem); // effettuo merge statistiche... await ProcDedupStatMergeAsync(procStats); // svuoto cache @@ -840,7 +831,7 @@ namespace MP.SPEC.Data operationName: "FluxLogGetLastFiltAsync", cacheKey: currKey, expiration: TimeSpan.FromSeconds(redisCacheSec), - fetchFunc: async () => await dbController.FluxLogGetLastFiltAsync(DtMax, DtMin, IdxMacchina, CodFlux, MaxRec) ?? new List(), + fetchFunc: async () => await _fluxLogRepository.FluxLogGetLastFiltAsync(DtMax, DtMin, IdxMacchina, CodFlux, MaxRec) ?? new List(), tagList: [Utils.redisFluxLogFilt] ); } @@ -856,7 +847,7 @@ namespace MP.SPEC.Data operationName: "FluxLogParetoAsync", cacheKey: redKey, expiration: GetRandTOut(redisLongTimeCache), - fetchFunc: async () => await dbController.FluxLogParetoAsync(idxMacchina, dtFrom, dtTo) ?? new List(), + fetchFunc: async () => await _fluxLogRepository.FluxLogParetoAsync(idxMacchina, dtFrom, dtTo) ?? new List(), tagList: [Utils.redisParetoFLKey] ); } @@ -875,7 +866,7 @@ namespace MP.SPEC.Data { using var activity = ActivitySource.StartActivity("ForceDbMaintAsync"); string source = "DB"; - await dbController.ForceDbMaintAsync(doExec, doUpdStat, doSave, minPgCnt, minAvgFrag, maxAvgFragReb); + await _systemRepository.ForceDbMaintAsync(doExec, doUpdStat, doSave, minPgCnt, minAvgFrag, maxAvgFragReb); // svuoto cache await FlushFusionCacheFluxLog(); activity?.SetTag("data.source", source); @@ -921,7 +912,7 @@ namespace MP.SPEC.Data { using var activity = ActivitySource.StartActivity("Grp2MaccDeleteAsync"); bool result = false; - result = await dbController.Grp2MaccDeleteAsync(rec2del); + result = await _productionRepository.Grp2MaccDeleteAsync(rec2del); // elimino cache redis... await FlushFusionCacheMacGrp(); activity?.SetTag("data.source", "DB"); @@ -939,7 +930,7 @@ namespace MP.SPEC.Data { using var activity = ActivitySource.StartActivity("Grp2MaccInsertAsync"); bool result = false; - result = await dbController.Grp2MaccInsertAsync(upsRec); + result = await _productionRepository.Grp2MaccInsertAsync(upsRec); // elimino cache redis... await FlushFusionCacheMacGrp(); activity?.SetTag("data.source", "DB"); @@ -957,7 +948,7 @@ namespace MP.SPEC.Data { using var activity = ActivitySource.StartActivity("Grp2OperDeleteAsync"); bool result = false; - result = await dbController.Grp2OperDeleteAsync(rec2del); + result = await _productionRepository.Grp2OperDeleteAsync(rec2del); // elimino cache redis... await FlushFusionCacheOprGrp(); activity?.SetTag("data.source", "DB"); @@ -975,7 +966,7 @@ namespace MP.SPEC.Data { using var activity = ActivitySource.StartActivity("Grp2OperInsertAsync"); bool result = false; - result = await dbController.Grp2OperInsertAsync(upsRec); + result = await _productionRepository.Grp2OperInsertAsync(upsRec); // elimino cache redis... await FlushFusionCacheOprGrp(); activity?.SetTag("data.source", "DB"); @@ -1005,7 +996,7 @@ namespace MP.SPEC.Data using var activity = ActivitySource.StartActivity("IstKitDeleteAsync"); string source = "DB"; // salvo - bool fatto = await dbController.IstKitDeleteAsync(currRecord); + bool fatto = await _productionRepository.IstKitDeleteAsync(currRecord); // svuoto cache await FlushFusionCacheKit(); activity?.SetTag("data.source", source); @@ -1027,7 +1018,7 @@ namespace MP.SPEC.Data operationName: "IstKitFiltAsync", cacheKey: currKey, expiration: GetRandTOut(redisLongTimeCache), - fetchFunc: async () => await dbController.IstKitFiltAsync(keyKit, keyExtOrd) ?? new List(), + fetchFunc: async () => await _productionRepository.IstKitFiltAsync(keyKit, keyExtOrd) ?? new List(), tagList: [Utils.redisKitInst] ); } @@ -1042,7 +1033,7 @@ namespace MP.SPEC.Data using var activity = ActivitySource.StartActivity("IstKitInsertByWKSAsync"); string source = "DB"; // salvo - bool fatto = await dbController.IstKitInsertByWKSAsync(CodArtParent, KeyFilt); + bool fatto = await _productionRepository.IstKitInsertByWKSAsync(CodArtParent, KeyFilt); // svuoto cache await FlushFusionCacheKit(); activity?.SetTag("data.source", source); @@ -1060,7 +1051,7 @@ namespace MP.SPEC.Data using var activity = ActivitySource.StartActivity("IstKitUpsertAsync"); string source = "DB"; // salvo - bool fatto = await dbController.IstKitUpsertAsync(currRecord); + bool fatto = await _productionRepository.IstKitUpsertAsync(currRecord); // svuoto cache await FlushFusionCacheKit(); activity?.SetTag("data.source", source); @@ -1081,7 +1072,7 @@ namespace MP.SPEC.Data operationName: "ListGiacenzeAsync", cacheKey: currKey, expiration: GetRandTOut(redisShortTimeCache), - fetchFunc: async () => await dbController.ListGiacenzeAsync(IdxOdl) ?? new List(), + fetchFunc: async () => await _productionRepository.ListGiacenzeAsync(IdxOdl) ?? new List(), tagList: [Utils.redisGiacenzaList] ); } @@ -1100,7 +1091,7 @@ namespace MP.SPEC.Data operationName: "ListPODL_ByCodArtAsync", cacheKey: currKey, expiration: GetRandTOut(redisLongTimeCache), - fetchFunc: async () => await dbController.ListPODL_ByCodArtAsync(CodArticolo, OnlyAvail) ?? new(), + fetchFunc: async () => await _productionRepository.ListPODL_ByCodArtAsync(CodArticolo, OnlyAvail) ?? new(), tagList: [Utils.redisPOdlByCodArt] ); } @@ -1119,9 +1110,9 @@ namespace MP.SPEC.Data operationName: "MacchineGetFiltAsync", cacheKey: redisKey, expiration: GetRandTOut(redisLongTimeCache), - fetchFunc: async () => - await dbController.MacchineGetFiltAsync(codGruppo) - ?? new List(), + fetchFunc: async () => + await _productionRepository.MacchineGetFiltAsync(codGruppo) + ?? new List(), tagList: [Utils.redisMacList] ); } @@ -1183,7 +1174,7 @@ namespace MP.SPEC.Data operationName: "MacchineWithFluxAsync", cacheKey: currKey, expiration: GetRandTOut(redisLongTimeCache), - fetchFunc: async () => await dbController.MacchineWithFluxAsync(dtStart, dtEnd) ?? new List(), + fetchFunc: async () => await _productionRepository.MacchineWithFluxAsync(dtStart, dtEnd) ?? new List(), tagList: [Utils.redisMacByFlux] ); } @@ -1198,7 +1189,7 @@ namespace MP.SPEC.Data expiration: GetRandTOut(redisShortTimeCache), fetchFunc: async () => { - var rawData = await dbController.OdlGetCurrentAsync(); + var rawData = await _productionRepository.OdlGetCurrentAsync(); var dbResult = rawData .Select(x => x.IdxMacchina) .Distinct() @@ -1254,7 +1245,7 @@ namespace MP.SPEC.Data operationName: "MseGetAllAsync", cacheKey: Constants.redisMseKey, expiration: TimeSpan.FromSeconds(1), - fetchFunc: async () => await dbController.MseGetAllAsync(2000) ?? new(), + fetchFunc: async () => await _productionRepository.MseGetAllAsync(2000) ?? new(), tagList: [Constants.redisMseKey] ); } @@ -1284,7 +1275,7 @@ namespace MP.SPEC.Data operationName: "OdlByBatchAsync", cacheKey: Utils.redisOdlByBatch, expiration: GetRandTOut(redisLongTimeCache), - fetchFunc: async () => await dbController.OdlByBatchAsync(BatchSel), + fetchFunc: async () => await _productionRepository.OdlByBatchAsync(BatchSel), tagList: [Utils.redisOdlByBatch] ); } @@ -1301,7 +1292,7 @@ namespace MP.SPEC.Data operationName: "OdlByKeyAsync", cacheKey: currKey, expiration: GetRandTOut(redisLongTimeCache), - fetchFunc: async () => await dbController.OdlByKeyAsync(IdxOdl), + fetchFunc: async () => await _productionRepository.OdlByKeyAsync(IdxOdl), tagList: [Utils.redisOdlByKey] ); } @@ -1333,7 +1324,7 @@ namespace MP.SPEC.Data int.TryParse(vModo, out modoConfProd); } // chiamo metodo conferma! - fatto = await dbController.ODLCloseAsync(idxOdl, idxMacchina, matrOpr, confPezzi, confRett, modoConfProd); + fatto = await _productionRepository.ODLCloseAsync(idxOdl, idxMacchina, matrOpr, confPezzi, confRett, modoConfProd); await FlushFusionCacheAsync(Utils.redisOdlByKey); @@ -1361,7 +1352,7 @@ namespace MP.SPEC.Data operationName: "OdlListGetFiltAsync", cacheKey: currKey, expiration: GetRandTOut(redisShortTimeCache), - fetchFunc: async () => await dbController.ListODLFiltAsync(inCorso, codArt, keyRichPart, Reparto, IdxMacchina, startDate, endDate) ?? new(), + fetchFunc: async () => await _productionRepository.ListODLFiltAsync(inCorso, codArt, keyRichPart, Reparto, IdxMacchina, startDate, endDate) ?? new(), tagList: [Utils.redisOdlList] ); } @@ -1378,7 +1369,7 @@ namespace MP.SPEC.Data operationName: "OdlStatsAsync", cacheKey: currKey, expiration: GetRandTOut(redisShortTimeCache), - fetchFunc: async () => await dbController.OdlGetStatAsync(IdxOdl) ?? new(), + fetchFunc: async () => await _productionRepository.OdlGetStatAsync(IdxOdl) ?? new(), tagList: [Utils.redisOdlStats] ); } @@ -1397,7 +1388,7 @@ namespace MP.SPEC.Data operationName: "OperatoriGetFiltAsync", cacheKey: currKey, expiration: GetRandTOut(redisLongTimeCache), - fetchFunc: async () => await dbController.OperatoriGetFiltAsync(codGruppo) ?? new List(), + fetchFunc: async () => await _productionRepository.OperatoriGetFiltAsync(codGruppo) ?? new List(), tagList: [Utils.redisOprList] ); } @@ -1414,7 +1405,7 @@ namespace MP.SPEC.Data operationName: "ParametriGetFiltAsync", cacheKey: currKey, expiration: GetRandTOut(redisShortTimeCache), - fetchFunc: async () => await dbController.ParametriGetFiltAsync(IdxMacchina) ?? new(), + fetchFunc: async () => await _productionRepository.ParametriGetFiltAsync(IdxMacchina) ?? new(), tagList: [Utils.redisFluxByMac] ); } @@ -1455,7 +1446,7 @@ namespace MP.SPEC.Data if (missingIds.Any()) { // Riceviamo direttamente un Dictionary ottimizzato da EF Core - Dictionary dbResults = await dbController.PODL_getDictOdlPodlAsync(missingIds); + Dictionary dbResults = await _productionRepository.PODL_getDictOdlPodlAsync(missingIds); // STEP 3: Scriviamo i risultati in cache e li uniamo al dizionario finale foreach (var kvp in dbResults) @@ -1497,7 +1488,7 @@ namespace MP.SPEC.Data { using var activity = ActivitySource.StartActivity("POdlDeleteRecord"); string source = "DB+REDIS"; - var dbResult = await dbController.PODLDeleteRecordAsync(currRec); + var dbResult = await _productionRepository.PODLDeleteRecordAsync(currRec); // elimino cache redis... await FlushFusionCachePOdl(); activity?.SetTag("data.source", source); @@ -1515,7 +1506,7 @@ namespace MP.SPEC.Data { using var activity = ActivitySource.StartActivity("POdlDoSetup"); string source = "DB+REDIS"; - var dbResult = await dbController.PODL_startSetup(currRec, 0, 1, 1, "", DateTime.Now); + var dbResult = await _productionRepository.PODL_startSetup(currRec, 0, 1, 1, "", DateTime.Now); // elimino cache redis... await FlushFusionCachePOdl(); activity?.SetTag("data.source", source); @@ -1536,7 +1527,7 @@ namespace MP.SPEC.Data operationName: "POdlGetByKey", cacheKey: currKey, expiration: TimeSpan.FromMinutes(redisLongTimeCache), - fetchFunc: async () => await dbController.PODL_getByKeyAsync(idxPODL) ?? new(), + fetchFunc: async () => await _productionRepository.PODL_getByKeyAsync(idxPODL) ?? new(), tagList: [Utils.redisPOdlByPOdl] ); } @@ -1553,7 +1544,7 @@ namespace MP.SPEC.Data operationName: "POdlGetByOdlAsync", cacheKey: currKey, expiration: TimeSpan.FromMinutes(redisLongTimeCache), - fetchFunc: async () => await dbController.PODL_getByOdlAsync(idxODL) ?? new(), + fetchFunc: async () => await _productionRepository.PODL_getByOdlAsync(idxODL) ?? new(), tagList: [Utils.redisPOdlByOdl] ); } @@ -1567,7 +1558,7 @@ namespace MP.SPEC.Data using var activity = ActivitySource.StartActivity("PodlIstKitDeleteAsync"); bool fatto = false; // salvo - fatto = await dbController.PodlIstKitDeleteAsync(IdxPODL); + fatto = await _productionRepository.PodlIstKitDeleteAsync(IdxPODL); // svuoto cache await FlushFusionCachePOdl(); activity?.SetTag("data.source", "DB"); @@ -1586,7 +1577,7 @@ namespace MP.SPEC.Data operationName: "POdlListByKitParentAsync", cacheKey: currKey, expiration: GetRandTOut(redisShortTimeCache), - fetchFunc: async () => await dbController.ListPODL_ByKitParentAsync(IdxPodlParent) ?? new(), + fetchFunc: async () => await _productionRepository.ListPODL_ByKitParentAsync(IdxPodlParent) ?? new(), tagList: [Utils.redisPOdlList] ); } @@ -1608,7 +1599,7 @@ namespace MP.SPEC.Data operationName: "POdlListGetFiltAsync", cacheKey: currKey, expiration: GetRandTOut(redisShortTimeCache), - fetchFunc: async () => await dbController.ListPODLFiltAsync(lanciato, keyRichPart, idxMacchina, codGruppo, startDate, endDate) ?? new List(), + fetchFunc: async () => await _productionRepository.ListPODLFiltAsync(lanciato, keyRichPart, idxMacchina, codGruppo, startDate, endDate) ?? new List(), tagList: [Utils.redisPOdlList] ); } @@ -1632,7 +1623,7 @@ namespace MP.SPEC.Data cacheKey: redisKey, expiration: GetRandTOut(redisShortTimeCache * 5), fetchFunc: async () => - await dbController.ListPODL_KitFiltAsync( + await _productionRepository.ListPODL_KitFiltAsync( lanciato, keyRichPart, idxMacchina, @@ -1655,7 +1646,7 @@ namespace MP.SPEC.Data using var activity = ActivitySource.StartActivity("POdlUpdateRecipe"); string source = "DB"; bool answ = false; - answ = await dbController.PODL_updateRecipe(idxPODL, recipeName); + answ = await _productionRepository.PODL_updateRecipe(idxPODL, recipeName); // reset redis... await FlushFusionCachePOdl(); activity?.SetTag("data.source", source); @@ -1673,7 +1664,7 @@ namespace MP.SPEC.Data { using var activity = ActivitySource.StartActivity("POdlUpdateRecord"); string source = "DB"; - var dbResult = await dbController.PODLUpdateRecordAsync(currRec); + var dbResult = await _productionRepository.PODLUpdateRecordAsync(currRec); // elimino cache redis... await FlushFusionCachePOdl(); activity?.SetTag("data.source", source); @@ -1778,7 +1769,7 @@ namespace MP.SPEC.Data operationName: "StatoMacchinaAsync", cacheKey: currKey, expiration: GetRandTOut(redisLongTimeCache), - fetchFunc: async () => await dbController.StatoMacchinaAsync(idxMacchina) ?? new(), + fetchFunc: async () => await _productionRepository.StatoMacchinaAsync(idxMacchina) ?? new(), tagList: [Utils.redisStatoMacch] ); } @@ -1793,7 +1784,7 @@ namespace MP.SPEC.Data string source = "DB"; bool fatto = false; // salvo - fatto = await dbController.TemplateKitDeleteAsync(currRecord); + fatto = await _productionRepository.TemplateKitDeleteAsync(currRecord); await FlushFusionCacheAsync(Utils.redisKitTempl); activity?.SetTag("data.source", source); activity?.Stop(); @@ -1815,7 +1806,7 @@ namespace MP.SPEC.Data operationName: "TemplateKitFiltAsync", cacheKey: currKey, expiration: GetRandTOut(redisLongTimeCache), - fetchFunc: async () => await dbController.TemplateKitFiltAsync(codParent, codChild) ?? new List(), + fetchFunc: async () => await _productionRepository.TemplateKitFiltAsync(codParent, codChild) ?? new List(), tagList: [Utils.redisKitTempl] ); } @@ -1831,7 +1822,7 @@ namespace MP.SPEC.Data string source = "DB"; bool fatto = false; // salvo - fatto = await dbController.TemplateKitUpsertAsync(currRecord, codAzienda); + fatto = await _productionRepository.TemplateKitUpsertAsync(currRecord, codAzienda); await FlushFusionCacheAsync(Utils.redisKitTempl); activity?.SetTag("data.source", source); activity?.Stop(); @@ -1854,7 +1845,7 @@ namespace MP.SPEC.Data { // Se ForceDb è true, saltiamo il GetOrFetchAsync per forzare il fetch dal DB // e aggiornare la cache. - var result = await dbController.TksScoreAsync(KeyFilt, MaxResult) ?? new List(); + var result = await _productionRepository.TksScoreAsync(KeyFilt, MaxResult) ?? new List(); await _cache.SetAsync(currKey, result, TimeSpan.FromMinutes(redisLongTimeCache), tags: [Utils.redisKitScore]); return result; } @@ -1863,7 +1854,7 @@ namespace MP.SPEC.Data operationName: "TksScoreAsync", cacheKey: currKey, expiration: TimeSpan.FromMinutes(redisLongTimeCache), - fetchFunc: async () => await dbController.TksScoreAsync(KeyFilt, MaxResult) ?? new List(), + fetchFunc: async () => await _productionRepository.TksScoreAsync(KeyFilt, MaxResult) ?? new List(), tagList: [Utils.redisKitScore] ); } @@ -1887,7 +1878,7 @@ namespace MP.SPEC.Data // Se non c'è, passa a L2 (Redis) o invoca la factory per caricarlo. var dizionarioLingua = _cache.GetOrSet>( cacheKey, - _ => dbController.VocabolarioGetLang(linguaKey), + _ => _anagRepository.VocabolarioGetLang(linguaKey), options => options .SetDuration(TimeSpan.FromHours(8)) // Durata logica della cache .SetFailSafe(true, TimeSpan.FromHours(1)) // Se Redis/DB è giù, usa i vecchi dati L1 @@ -1913,7 +1904,7 @@ namespace MP.SPEC.Data string source = "DB"; bool fatto = false; // salvo - fatto = await dbController.WipKitDeleteAsync(currRecord); + fatto = await _productionRepository.WipKitDeleteAsync(currRecord); // svuoto cache await FlushFusionCacheAsync(Utils.redisKitWip); activity?.SetTag("data.source", source); @@ -1932,7 +1923,7 @@ namespace MP.SPEC.Data string source = "DB"; bool fatto = false; // salvo - fatto = await dbController.WipKitDeleteOlderAsync(DateLimit); + fatto = await _productionRepository.WipKitDeleteOlderAsync(DateLimit); // svuoto cache KitWip await FlushFusionCacheAsync(Utils.redisKitWip); activity?.SetTag("data.source", source); @@ -1953,7 +1944,7 @@ namespace MP.SPEC.Data operationName: "WipKitFiltAsync", cacheKey: currKey, expiration: TimeSpan.FromMinutes(redisLongTimeCache), - fetchFunc: async () => await dbController.WipKitFiltAsync(KeyFilt) ?? new List(), + fetchFunc: async () => await _productionRepository.WipKitFiltAsync(KeyFilt) ?? new List(), tagList: [Utils.redisKitWip] ); } @@ -1968,7 +1959,7 @@ namespace MP.SPEC.Data string source = "DB"; bool fatto = false; // salvo - fatto = await dbController.WipKitUpsertAsync(currRecord); + fatto = await _productionRepository.WipKitUpsertAsync(currRecord); // svuoto cache KitWip await FlushFusionCacheAsync(Utils.redisKitWip); activity?.SetTag("data.source", source);