From e5178e19fcb66b8d8d49e4632691d91083290514 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Wed, 15 Apr 2026 08:23:10 +0200 Subject: [PATCH] Aggiunta metodi FixDayOdl (con/senza conf pezzi) --- MP.Core/Utils.cs | 1 + MP.Data/Controllers/MpIocController.cs | 100 +++++++++++++++++++++++++ MP.IOC/Controllers/IOBController.cs | 87 +++++++++++++++++++++ MP.IOC/Data/MpDataService.cs | 60 +++++++++++++++ MP.IOC/MP.IOC.csproj | 2 +- MP.IOC/Resources/ChangeLog.html | 2 +- MP.IOC/Resources/VersNum.txt | 2 +- MP.IOC/Resources/manifest.xml | 2 +- 8 files changed, 252 insertions(+), 4 deletions(-) diff --git a/MP.Core/Utils.cs b/MP.Core/Utils.cs index e4dc6965..f8ea0399 100644 --- a/MP.Core/Utils.cs +++ b/MP.Core/Utils.cs @@ -46,6 +46,7 @@ namespace MP.Core public const string redisOdlByBatch = redisXdlData + "OdlByBatch"; public const string redisOdlCurrByMac = redisXdlData + "OdlByMac"; + public const string redisOdlLastByMac = redisXdlData + "LastOdlByMac"; public const string redisOdlList = redisXdlData + "OdlList"; diff --git a/MP.Data/Controllers/MpIocController.cs b/MP.Data/Controllers/MpIocController.cs index 1f353559..0f7d8b7a 100644 --- a/MP.Data/Controllers/MpIocController.cs +++ b/MP.Data/Controllers/MpIocController.cs @@ -572,6 +572,77 @@ namespace MP.Data.Controllers return dbResult; } + /// + /// Generazione automatica ODL + /// + /// + /// + public async Task OdlAutoDayGenAsync(string idxMacchina, DateTime dataInizio, DateTime dataFine, string codArticolo) + { + bool answ = false; + using (var dbCtx = new MoonProContext(_configuration)) + { + try + { + var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina); + var DataInizio = new SqlParameter("@DataInizio", dataInizio); + var DataFine = new SqlParameter("@DataFine", dataFine); + var CodArticolo = new SqlParameter("@CodArticolo", codArticolo); + + var result = dbCtx + .Database + .ExecuteSqlRaw("EXEC stp_ODL_AutoDayGener @IdxMacchina, @DataInizio, @DataFine, @CodArticolo", IdxMacchina, DataInizio, DataFine, CodArticolo); + + // indico eseguito! + answ = result > 0; + } + catch (Exception exc) + { + Log.Error($"Eccezione durante stp_ODL_AutoDayGener{Environment.NewLine}{exc}"); + } + } + return answ; + } + + /// + /// Generazione automatica ODL completa + /// + /// + /// + public async Task OdlAutoDayGenFullAsync(string idxMacchina, DateTime dataInizio, DateTime dataFine, string codArticolo, int? pzPODL, int? pzPallet, string? keyRichiesta, int? tcAssegnato, string? codGruppo, bool flgCreaPODL, bool flgCheckTC) + { + bool answ = false; + using (var dbCtx = new MoonProContext(_configuration)) + { + try + { + var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina); + var DataInizio = new SqlParameter("@DataInizio", dataInizio); + var DataFine = new SqlParameter("@DataFine", dataFine); + var CodArticolo = new SqlParameter("@CodArticolo", codArticolo); + var PzPODL = new SqlParameter("@PzPODL", pzPODL); + var PzPallet = new SqlParameter("@PzPallet", pzPallet); + var KeyRichiesta = new SqlParameter("@KeyRichiesta", keyRichiesta); + var TCAssegnato = new SqlParameter("@TCAssegnato", tcAssegnato); + var CodGruppo = new SqlParameter("@CodGruppo", codGruppo); + var FlgCreaPODL = new SqlParameter("@flgCreaPODL", flgCreaPODL); + var FlgCheckTC = new SqlParameter("@flgCheckTC", flgCheckTC); + + var result = dbCtx + .Database + .ExecuteSqlRaw("EXEC stp_ODL_AutoDayGenerFull @IdxMacchina, @DataInizio, @DataFine, @CodArticolo, @PzPODL, @PzPallet, @KeyRichiesta, @TCAssegnato, @CodGruppo, @flgCreaPODL, @flgCheckTC", IdxMacchina, DataInizio, DataFine, CodArticolo, PzPODL, PzPallet, KeyRichiesta, TCAssegnato, CodGruppo, FlgCreaPODL, FlgCheckTC); + + // indico eseguito! + answ = result > 0; + } + catch (Exception exc) + { + Log.Error($"Eccezione durante stp_ODL_AutoDayGenerFull{Environment.NewLine}{exc}"); + } + } + return answ; + } + /// /// ODL corrente macchina /// @@ -629,6 +700,35 @@ namespace MP.Data.Controllers return answ; } + /// + /// ODL corrente macchina + /// + /// + /// + public async Task OdlLastByMaccAsync(string idxMacchina) + { + ODLExpModel answ = new(); + using (var dbCtx = new MoonProContext(_configuration)) + { + try + { + var pIdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina); + // attenzione: se la stored resituisce una tabella, il primo elemento va recuperato in RAM!!! + var dbRes = (await dbCtx.DbSetODLExp + .FromSqlRaw("EXEC stp_ODL_getLastByMacchina @IdxMacchina", pIdxMacchina) + .AsNoTracking() + .ToListAsync()) // Esegue la query e scarica i risultati in memoria + .FirstOrDefault(); // Prende il primo elemento dalla lista in RAM + answ = dbRes ?? new(); + } + catch (Exception exc) + { + Log.Error($"Eccezione durante OdlCurrByMaccAsync{Environment.NewLine}{exc}"); + } + } + return answ; + } + /// /// Elenco ODL data macchina e periodo /// diff --git a/MP.IOC/Controllers/IOBController.cs b/MP.IOC/Controllers/IOBController.cs index 72545cde..ecb33e00 100644 --- a/MP.IOC/Controllers/IOBController.cs +++ b/MP.IOC/Controllers/IOBController.cs @@ -74,6 +74,93 @@ namespace MP.IOC.Controllers } } + /// + /// Sistema ODL giornalieri x impianto indicato, andando a generare 1 ODL giornaliero x ogni + /// giornata dall'ultimo ODL aperto alla data corrente + /// es: http://url_site/MP/IO/IOB/fixDailyOdl/SIMUL_03 + /// + /// + /// + [HttpGet("fixDailyOdl/{id}")] + public async Task FixDailyOdl(string id) + { + if (string.IsNullOrEmpty(id)) return BadRequest("Missing ID"); + + // Multi: gestione carattere "|" trasformato in "#" + id = id.Replace("|", "#"); + + string answ = ""; + // chiamo metodo redis/db... + try + { + // recupero ultimo ODL macchina... + var lastOdlStarted = await DService.GetLastOdlAsync(id); + if (lastOdlStarted != null && lastOdlStarted.DataInizio.HasValue) + { + // calcolo data ultimo avviato e chiedo dal giorno dopo... + DateTime dtFrom = lastOdlStarted.DataInizio.Value.AddDays(1); + DateTime dtTo = DateTime.Today; + if (dtTo >= dtFrom) + { + string codArt = lastOdlStarted.CodArticolo; + // chiamo la stored x sistemare gli ODL + bool fatto = await DService.OdlAutoDayGenAsync(id, dtFrom, dtTo, codArt); + answ = fatto ? "OK" : "KO"; + } + } + return Ok(answ); + } + catch (Exception exc) + { + Log.Error($"Errore in FixDailyOdl{Environment.NewLine}{exc}"); + return StatusCode(StatusCodes.Status500InternalServerError, "NO"); + } + } + + /// + /// Sistema ODL giornalieri x impianto indicato, andando a generare 1 ODL giornaliero x ogni + /// giornata dall'ultimo ODL aperto alla data corrente + conferma pezzi (es TFT x ODL + /// giornalieri energia) + /// es: http://url_site/MP/IO/IOB/fixDailyOdlConfPzCount/SIMUL_03 + /// + /// + /// + [HttpGet("fixDailyOdlConfPzCount/{id}")] + public async Task FixDailyOdlConfPzCount(string id) + { + if (string.IsNullOrEmpty(id)) return BadRequest("Missing ID"); + + // Multi: gestione carattere "|" trasformato in "#" + id = id.Replace("|", "#"); + + string answ = ""; + // chiamo metodo redis/db... + try + { + // recupero ultimo ODL macchina... + var lastOdlStarted = await DService.GetLastOdlAsync(id); + if (lastOdlStarted != null && lastOdlStarted.DataInizio.HasValue) + { + // calcolo data ultimo avviato e chiedo dal giorno dopo... + DateTime dtFrom = lastOdlStarted.DataInizio.Value.AddDays(1); + DateTime dtTo = DateTime.Today; + if (dtTo >= dtFrom) + { + string codArt = lastOdlStarted.CodArticolo; + // chiamo la stored x sistemare gli ODL + bool fatto = await DService.OdlAutoDayGenFullAsync(id, dtFrom, dtTo, codArt, null, null, null, null, null, true, false); + answ = fatto ? "OK" : "KO"; + } + } + return Ok(answ); + } + catch (Exception exc) + { + Log.Error($"Errore in FixDailyOdlConfPzCount{Environment.NewLine}{exc}"); + return StatusCode(StatusCodes.Status500InternalServerError, "NO"); + } + } + /// /// Invio record flog direttamente via URL GET /// GET: IOB/flog/SIMUL_03?flux=PROG&valore=P0001&dtEve=20161223180600000&dtCurr=20161223180600000&cnt=999&disabKA=false diff --git a/MP.IOC/Data/MpDataService.cs b/MP.IOC/Data/MpDataService.cs index a9dc130e..dc968b57 100644 --- a/MP.IOC/Data/MpDataService.cs +++ b/MP.IOC/Data/MpDataService.cs @@ -1038,6 +1038,31 @@ namespace MP.IOC.Data return answ; } + /// + /// Restituisce il valore dell'ultimo ODL + /// + /// + /// + public async Task GetLastOdlAsync(string idxMacchina) + { + ODLExpModel result = new ODLExpModel(); + string currKey = $"{Utils.redisOdlLastByMac}:{idxMacchina}"; + // cerco in redis dato valore sel macchina... + RedisValue rawData = redisDb.StringGet(currKey); + if (rawData.HasValue) + { + result = JsonConvert.DeserializeObject($"{rawData}") ?? new(); + } + else + { + result = await IocDbController.OdlLastByMaccAsync(idxMacchina); + // serializzo e salvo... + rawData = JsonConvert.SerializeObject(result); + redisDb.StringSet(currKey, rawData, getRandTOut(redisLongTimeCache)); + } + return result; + } + /// /// Effettua calcolo data-ora di riferimento per il server a partire da /// @@ -1668,6 +1693,41 @@ namespace MP.IOC.Data return answ; } + /// + /// Generazione autoOdl + /// + /// + /// + /// + /// + /// + public async Task OdlAutoDayGenAsync(string idxMacchina, DateTime dataInizio, DateTime dataFine, string codArticolo) + { + var result = await IocDbController.OdlAutoDayGenAsync(idxMacchina, dataInizio, dataFine, codArticolo); + return result; + } + + /// + /// Generazione autoOdl + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + public async Task OdlAutoDayGenFullAsync(string idxMacchina, DateTime dataInizio, DateTime dataFine, string codArticolo, int? pzPODL, int? pzPallet, string? keyRichiesta, int? tcAssegnato, string? codGruppo, bool flgCreaPODL, bool flgCheckTC) + { + var result = await IocDbController.OdlAutoDayGenFullAsync(idxMacchina, dataInizio, dataFine, codArticolo, pzPODL, pzPallet, keyRichiesta, tcAssegnato, codGruppo, flgCreaPODL, flgCheckTC); + return result; + } + /// /// Elenco ODL dato batch selezionato /// diff --git a/MP.IOC/MP.IOC.csproj b/MP.IOC/MP.IOC.csproj index 5b0d20f2..071040c1 100644 --- a/MP.IOC/MP.IOC.csproj +++ b/MP.IOC/MP.IOC.csproj @@ -4,7 +4,7 @@ net8.0 enable enable - 6.16.2604.1507 + 6.16.2604.1508 diff --git a/MP.IOC/Resources/ChangeLog.html b/MP.IOC/Resources/ChangeLog.html index be54a679..0ba6521c 100644 --- a/MP.IOC/Resources/ChangeLog.html +++ b/MP.IOC/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MP-IOC -

Versione: 6.16.2604.1507

+

Versione: 6.16.2604.1508


Note di rilascio:
  • diff --git a/MP.IOC/Resources/VersNum.txt b/MP.IOC/Resources/VersNum.txt index 218b56ab..01e27f4e 100644 --- a/MP.IOC/Resources/VersNum.txt +++ b/MP.IOC/Resources/VersNum.txt @@ -1 +1 @@ -6.16.2604.1507 +6.16.2604.1508 diff --git a/MP.IOC/Resources/manifest.xml b/MP.IOC/Resources/manifest.xml index 8c5e9df3..3c817840 100644 --- a/MP.IOC/Resources/manifest.xml +++ b/MP.IOC/Resources/manifest.xml @@ -1,6 +1,6 @@ - 6.16.2604.1507 + 6.16.2604.1508 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