diff --git a/MP.Core/Utils.cs b/MP.Core/Utils.cs index aa94c020..e2923703 100644 --- a/MP.Core/Utils.cs +++ b/MP.Core/Utils.cs @@ -62,6 +62,7 @@ namespace MP.Core public const string redisParetoFLKey = redisBaseAddr + "Cache:ParetoFL"; public const string redisPOdlByCodArt = redisXdlData + "POdlByCodArt"; + public const string redisPOdlByMaccArt = redisXdlData + "POdlByMaccArt"; public const string redisPOdlByOdl = redisXdlData + "POdlByOdl"; public const string redisPOdlByPOdl = redisXdlData + "POdlByPOdl"; public const string redisPOdlList = redisXdlData + "POdlList"; diff --git a/MP.Data/Controllers/MpIocController.cs b/MP.Data/Controllers/MpIocController.cs index 41483f33..2ad11b1d 100644 --- a/MP.Data/Controllers/MpIocController.cs +++ b/MP.Data/Controllers/MpIocController.cs @@ -73,6 +73,29 @@ namespace MP.Data.Controllers return dbResult; } + /// + /// Restitusice elenco ultimi articoli per macchina + /// + /// + /// + /// + /// + public async Task> ArticoliGetLastByMaccAsync(string idxMacc) + { + List dbResult = new List(); + using (var dbCtx = new MoonProContext(_configuration)) + { + var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacc); + + dbResult = await dbCtx + .DbSetArticoli + .FromSqlRaw("exec dbo.stp_ART_getLastByMacch @idxMacchina", IdxMacchina) + .AsNoTracking() + .ToListAsync(); + } + return dbResult; + } + /// /// Record ConfFlux dato macchina (oppure tutti se vuoto) /// @@ -189,17 +212,17 @@ namespace MP.Data.Controllers bool fatto = false; using (var dbCtx = new MoonProContext(_configuration)) { - var IdxMacchina = new SqlParameter("@pIdxMacchina", idxMacchina); + var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina); var InizioStato = new SqlParameter("@InizioStato", inizioStato); var IdxStato = new SqlParameter("@IdxStato", idxStato); - var CodArticolo = new SqlParameter("@CodArticolo", codArt); + var CodArticolo = new SqlParameter("@codArticolo", codArt); var Value = new SqlParameter("@Value", value); var MatrOpr = new SqlParameter("@MatrOpr", matrOpr); var Pallet = new SqlParameter("@pallet", pallet); var result = dbCtx .Database - .ExecuteSqlRaw("exec dbo.stp_DDB_InsStatoBatch @pIdxMacchina, @InizioStato, @IdxStato, @CodArticolo, @Value, @MatrOpr, @pallet", IdxMacchina, InizioStato, IdxStato, CodArticolo, Value, MatrOpr, Pallet); + .ExecuteSqlRaw("exec dbo.stp_DDB_InsStatoBatch @IdxMacchina, @InizioStato, @IdxStato, @codArticolo, @Value, @MatrOpr, @pallet", IdxMacchina, InizioStato, IdxStato, CodArticolo, Value, MatrOpr, Pallet); // indico eseguito! fatto = result > 0; @@ -245,7 +268,6 @@ namespace MP.Data.Controllers using (var dbCtx = new MoonPro_FluxContext(_configuration)) { var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacc); - dbResult = await dbCtx .DbSetDossiers .FromSqlRaw("exec dbo.stp_DOSS_getLastByMacch @idxMacchina", IdxMacchina) @@ -507,6 +529,31 @@ namespace MP.Data.Controllers return dbResult; } + /// + /// Elenco valori ammessi x tabella/colonna con filtro parametrico + /// + /// Filtro tabella (se "" tutto) + /// Filtro colonna (se "" tutto) + /// + public async Task> ListValuesFilt(string tabName, string fieldName) + { + List dbResult = new List(); + using (var dbCtx = new MoonProContext(_configuration)) + { + var query = dbCtx.DbSetListValues + .AsNoTracking() + .AsQueryable(); + + if (!string.IsNullOrEmpty(tabName)) + query = query.Where(x => x.TableName == tabName); + if (!string.IsNullOrEmpty(fieldName)) + query = query.Where(x => x.FieldName == fieldName); + + dbResult = await query.ToListAsync(); + } + return dbResult; + } + /// /// Intera tabella relazione master/slave in machine (gestione setup master --> slave) /// @@ -784,11 +831,11 @@ namespace MP.Data.Controllers 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 CodArticolo = new SqlParameter("@codArticolo", codArticolo); var result = dbCtx .Database - .ExecuteSqlRaw("EXEC stp_ODL_AutoDayGener @IdxMacchina, @DataInizio, @DataFine, @CodArticolo", IdxMacchina, DataInizio, DataFine, CodArticolo); + .ExecuteSqlRaw("EXEC stp_ODL_AutoDayGener @IdxMacchina, @DataInizio, @DataFine, @codArticolo", IdxMacchina, DataInizio, DataFine, CodArticolo); // indico eseguito! answ = result > 0; @@ -816,18 +863,18 @@ namespace MP.Data.Controllers 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 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 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); + .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; @@ -940,12 +987,12 @@ namespace MP.Data.Controllers { try { - var IdxMacchina = new SqlParameter("@pIdxMacchina", idxMacchina); + var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina); var DataFrom = new SqlParameter("@dataFrom", dtStart); var DataTo = new SqlParameter("@dataTo", dtEnd); dbResult = dbCtx .DbSetODLExp - .FromSqlRaw("EXEC stp_ODL_getByMacchinaPeriodo @pIdxMacchina, @dataFrom, @dataTo", IdxMacchina, DataFrom, DataTo) + .FromSqlRaw("EXEC stp_ODL_getByMacchinaPeriodo @IdxMacchina, @dataFrom, @dataTo", IdxMacchina, DataFrom, DataTo) .AsNoTracking() .ToList(); } @@ -999,6 +1046,33 @@ namespace MP.Data.Controllers return dbResult; } + /// + /// Recupero elenco PODL EXPL filtrati x macchina, articolo... + /// + /// + /// + /// + /// True = aperti (=senza ODL) + /// + public async Task> POdlGetByMaccArtAsync(string idxMacchina, string codArticolo, string codGruppo, bool onlyFree) + { + List dbResult = new List(); + using (var dbCtx = new MoonProContext(_configuration)) + { + var pIdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina); + var pCodArticolo = new SqlParameter("@CodArticolo", codArticolo); + var pCodGruppo = new SqlParameter("@CodGruppo", codGruppo); + var pOnlyFree = new SqlParameter("@onlyFree", onlyFree); + + dbResult = await dbCtx + .DbSetPODLExp + .FromSqlRaw("EXEC stp_PODL_getByMaccArt @IdxMacchina, @CodArticolo, @CodGruppo, @onlyFree", pIdxMacchina, pCodArticolo, pCodGruppo, pOnlyFree) + .AsNoTracking() + .ToListAsync(); + } + return dbResult; + } + /// /// Effettua ricalcolo MSE x macchina indicata /// @@ -1295,11 +1369,11 @@ namespace MP.Data.Controllers List dbResult = new List(); using (var dbCtx = new MoonProContext(_configuration)) { - var IdxMacchina = new SqlParameter("@pIdxMacchina", idxMacchina); + var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina); var IdxTipo = new SqlParameter("@IdxTipo", idxTipo); dbResult = dbCtx .DbSetSMES - .FromSqlRaw("exec dbo.stp_TS_getByIdxMacchIdxTipoEv @pIdxMacchina, @IdxTipo", IdxMacchina, IdxTipo) + .FromSqlRaw("exec dbo.stp_TS_getByIdxMacchIdxTipoEv @IdxMacchina, @IdxTipo", IdxMacchina, IdxTipo) .AsNoTracking() .AsEnumerable() .ToList(); @@ -1317,11 +1391,11 @@ namespace MP.Data.Controllers List dbResult = new List(); using (var dbCtx = new MoonProContext(_configuration)) { - var IdxMacchina = new SqlParameter("@pIdxMacchina", idxMacchina); + var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina); var IdxTipo = new SqlParameter("@IdxTipo", idxTipo); dbResult = dbCtx .DbSetSMES - .FromSqlRaw("exec dbo.stp_TS_getUserForcedTrans @pIdxMacchina, @IdxTipo", IdxMacchina, IdxTipo) + .FromSqlRaw("exec dbo.stp_TS_getUserForcedTrans @IdxMacchina, @IdxTipo", IdxMacchina, IdxTipo) .AsNoTracking() .AsEnumerable() .ToList(); @@ -1360,11 +1434,11 @@ namespace MP.Data.Controllers StatoProdModel dbResult = new StatoProdModel(); using (var dbCtx = new MoonProContext(_configuration)) { - var IdxMacchina = new SqlParameter("@pIdxMacchina", idxMacchina); + var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina); var DataOra = new SqlParameter("@DataOra ", dtReq); var rawData = dbCtx .DbSetStatoProd - .FromSqlRaw("EXEC stp_StatoProd_getByMacchina @pIdxMacchina, @DataOra ", IdxMacchina, DataOra) + .FromSqlRaw("EXEC stp_StatoProd_getByMacchina @IdxMacchina, @DataOra ", IdxMacchina, DataOra) .AsNoTracking() .AsEnumerable() .ToList(); @@ -1385,11 +1459,11 @@ namespace MP.Data.Controllers StatoProdModel dbResult = new StatoProdModel(); using (var dbCtx = new MoonProContext(_configuration)) { - var IdxMacchina = new SqlParameter("@pIdxMacchina", idxMacchina); + var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina); var DataOra = new SqlParameter("@DataOra ", dtReq); dbResult = (await dbCtx .DbSetStatoProd - .FromSqlRaw("EXEC stp_StatoProd_getByMacchina @pIdxMacchina, @DataOra ", IdxMacchina, DataOra) + .FromSqlRaw("EXEC stp_StatoProd_getByMacchina @IdxMacchina, @DataOra ", IdxMacchina, DataOra) .AsNoTracking() .ToListAsync()) .FirstOrDefault(); @@ -1415,6 +1489,30 @@ namespace MP.Data.Controllers return dbResult; } + /// + /// Intera vista v_MSFD in modo ASYNC + /// + /// + public async Task> VMSFDGetAllAsync() + { + List dbResult = new List(); + using (var dbCtx = new MoonProContext(_configuration)) + { + try + { + dbResult = await dbCtx + .DbSetMSFD + .AsNoTracking() + .OrderBy(x => x.IdxMacchina) + .ToListAsync(); + } + catch (Exception exc) + { + } + } + return dbResult; + } + /// /// Vista v_MSFD x singola macchina (da stored) - singolo record /// @@ -1425,11 +1523,11 @@ namespace MP.Data.Controllers List dbResult = new List(); using (var dbCtx = new MoonProContext(_configuration)) { - var IdxMacchina = new SqlParameter("@pIdxMacchina", idxMacc); + var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacc); dbResult = dbCtx .DbSetMSFD - .FromSqlRaw("exec dbo.stp_MSFD_getMacc @pIdxMacchina", IdxMacchina) + .FromSqlRaw("exec dbo.stp_MSFD_getMacc @IdxMacchina", IdxMacchina) .AsNoTracking() .AsEnumerable() .ToList(); @@ -1447,13 +1545,18 @@ namespace MP.Data.Controllers List dbResult = new List(); using (var dbCtx = new MoonProContext(_configuration)) { - var IdxMacchina = new SqlParameter("@pIdxMacchina", idxMacc); - - dbResult = await dbCtx - .DbSetMSFD - .FromSqlRaw("exec dbo.stp_MSFD_getMacc @pIdxMacchina", IdxMacchina) - .AsNoTracking() - .ToListAsync(); + var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacc); + try + { + dbResult = await dbCtx + .DbSetMSFD + .FromSqlRaw("exec dbo.stp_MSFD_getMacc @IdxMacchina", IdxMacchina) + .AsNoTracking() + .ToListAsync(); + } + catch (Exception exc) + { + } } return dbResult; } @@ -1468,11 +1571,11 @@ namespace MP.Data.Controllers List dbResult = new List(); using (var dbCtx = new MoonProContext(_configuration)) { - var IdxMacchina = new SqlParameter("@pIdxMacchina", idxMacc); + var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacc); dbResult = dbCtx .DbSetMSFD - .FromSqlRaw("exec dbo.stp_MSFD_getMulti @pIdxMacchina", IdxMacchina) + .FromSqlRaw("exec dbo.stp_MSFD_getMulti @IdxMacchina", IdxMacchina) .AsNoTracking() .AsEnumerable() .ToList(); diff --git a/MP.Data/DbModels/Anag/DecNumArticoliModel.cs b/MP.Data/DbModels/Anag/DecNumArticoliModel.cs index f2d3d8fa..5037fdbd 100644 --- a/MP.Data/DbModels/Anag/DecNumArticoliModel.cs +++ b/MP.Data/DbModels/Anag/DecNumArticoliModel.cs @@ -3,7 +3,7 @@ using System.ComponentModel.DataAnnotations.Schema; namespace MP.Data.DbModels.Anag { - [Table("AlarmLog")] + [Table("DecNumArticoli")] public class DecNumArticoliModel { [Key] diff --git a/MP.Data/DbModels/AnagArticoliModel.cs b/MP.Data/DbModels/AnagArticoliModel.cs index e1a94480..663d7e75 100644 --- a/MP.Data/DbModels/AnagArticoliModel.cs +++ b/MP.Data/DbModels/AnagArticoliModel.cs @@ -14,6 +14,9 @@ namespace MP.Data.DbModels public string CodArticolo { get; set; } public string DescArticolo { get; set; } public string Disegno { get; set; } + public string CurrRev { get; set; } + public string ProdRev { get; set; } + public bool FlagIsNew { get; set; } public string Tipo { get; set; } public string Azienda { get; set; } diff --git a/MP.Data/DbModels/VMSFDModel.cs b/MP.Data/DbModels/VMSFDModel.cs index 698e5a75..c7a7dcdb 100644 --- a/MP.Data/DbModels/VMSFDModel.cs +++ b/MP.Data/DbModels/VMSFDModel.cs @@ -1,5 +1,5 @@ -using System; -using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; namespace MP.Data.DbModels { @@ -8,31 +8,51 @@ namespace MP.Data.DbModels // public partial class VMSFDModel { + [Column("idxmacchina")] public string IdxMacchina { get; set; } = "ND"; + [Column("codmacchina")] public string Codmacchina { get; set; } = "000"; + [Column("palletChange")] public bool PalletChange { get; set; } = false; + [Column("CodArticolo_A"), MaxLength(50)] public string CodArticoloA { get; set; } = "ND"; + [Column("CodArticolo_B"), MaxLength(50)] public string CodArticoloB { get; set; } = "ND"; + [Column("simplePallet")] public bool SimplePallet { get; set; } = true; + [Column("insEnabled")] public bool InsEnabled { get; set; } = true; + [Column("sLogEnabled")] public bool SLogEnabled { get; set; } = false; + public int IsManual { get; set; } = 0; public int IdxFamigliaIngresso { get; set; } public int Multi { get; set; } public int BitFilt { get; set; } public int MaxVal { get; set; } + + [Column("BSR")] public int Bsr { get; set; } + public bool ExplodeBit { get; set; } public int NumBit { get; set; } + public int IdxMicroStato { get; set; } public int IdxFamiglia { get; set; } public int IdxStato { get; set; } + + [Column("lastVal")] public string LastVal { get; set; } + [MaxLength(50)] public string CodArticolo { get; set; } public double TempoCicloBase { get; set; } public int PzPalletProd { get; set; } public int MatrOpr { get; set; } + + [Column("pallet")] public string Pallet { get; set; } + + [MaxLength(250)] public string CodMaccArticolo { get; set; } } } diff --git a/MP.Data/MoonProContext.cs b/MP.Data/MoonProContext.cs index 25ffff79..975aaedd 100644 --- a/MP.Data/MoonProContext.cs +++ b/MP.Data/MoonProContext.cs @@ -448,54 +448,6 @@ namespace MP.Data entity.HasNoKey(); entity.ToView("v_MSFD"); - - entity.Property(e => e.Bsr).HasColumnName("BSR"); - - entity.Property(e => e.CodArticolo) - .IsRequired() - .HasMaxLength(50); - - entity.Property(e => e.CodArticoloA) - .IsRequired() - .HasMaxLength(50) - .HasColumnName("CodArticolo_A"); - - entity.Property(e => e.CodArticoloB) - .IsRequired() - .HasMaxLength(50) - .HasColumnName("CodArticolo_B"); - - entity.Property(e => e.CodMaccArticolo) - .IsRequired() - .HasMaxLength(103); - - entity.Property(e => e.Codmacchina) - .IsRequired() - .HasMaxLength(50) - .HasColumnName("codmacchina"); - - entity.Property(e => e.IdxMacchina) - .IsRequired() - .HasMaxLength(50) - .HasColumnName("idxmacchina"); - - entity.Property(e => e.InsEnabled).HasColumnName("insEnabled"); - - entity.Property(e => e.LastVal) - .IsRequired() - .HasMaxLength(50) - .HasColumnName("lastVal"); - - entity.Property(e => e.Pallet) - .IsRequired() - .HasMaxLength(20) - .HasColumnName("pallet"); - - entity.Property(e => e.PalletChange).HasColumnName("palletChange"); - - entity.Property(e => e.SLogEnabled).HasColumnName("sLogEnabled"); - - entity.Property(e => e.SimplePallet).HasColumnName("simplePallet"); }); modelBuilder.Entity(entity => diff --git a/MP.Data/MoonPro_FluxContext.cs b/MP.Data/MoonPro_FluxContext.cs index bf060309..117777b7 100644 --- a/MP.Data/MoonPro_FluxContext.cs +++ b/MP.Data/MoonPro_FluxContext.cs @@ -140,6 +140,13 @@ namespace MP.Data entity.HasKey(e => new { e.IdxMacchina, e.CodFlux }); }); + modelBuilder.Entity(entity => + { + entity.HasKey(e => new { e.IdxMacchina, e.CodFlux }); + + }); + + OnModelCreatingPartial(modelBuilder); } diff --git a/MP.IOC/Controllers/IOBController.cs b/MP.IOC/Controllers/IOBController.cs index 5333055f..1c58ef23 100644 --- a/MP.IOC/Controllers/IOBController.cs +++ b/MP.IOC/Controllers/IOBController.cs @@ -564,6 +564,159 @@ namespace MP.IOC.Controllers return Ok(answ); } + /// + /// Recupera elenco articoli USATI per ultimi: + /// - quelli dei PODL correnti + /// - quelli degli ultimi n (DOSS_LastArt in config) ODL lavorati + /// + /// GET: IOB/getArtByMacc + /// + /// Json contenente lista oggetti ARTICOLI serializzati + [HttpGet("getLastArtByMacc/{id}")] + public async Task GetLastArtByMacc(string id) + { + if (string.IsNullOrEmpty(id)) return BadRequest("Missing ID"); + // Multi: gestione carattere "|" trasformato in "#" + id = id.Replace("|", "#"); + string answ = ""; + try + { + // recupero dati macchina... + var elencoArt = await DService.ArticoliGetLastByMaccAsync(id); + answ = JsonConvert.SerializeObject(elencoArt); + } + catch (Exception exc) + { + Log.Error($"Errore in GetLastArtByMacc{Environment.NewLine}{exc}"); + return StatusCode(StatusCodes.Status500InternalServerError, "NO"); + } + return Ok(answ); + } + + /// + /// Recupera DATI dell'ultimo dossier dato articolo: + /// + /// GET: IOB/getLastDossArt/cod_articolo + /// + /// codice articolo, se vuoto --> non fa nulla + /// Json contenente lista oggetti DOSSIER serializzati + [HttpGet("getLastDossByMacc/{id}")] + public async Task GetLastDossByMacc(string id) + { + if (string.IsNullOrEmpty(id)) return BadRequest("Missing ID"); + // Multi: gestione carattere "|" trasformato in "#" + id = id.Replace("|", "#"); + string answ = ""; + + try + { + // recupero dati macchina... + var elencoDoss = await DService.DossierLastByMachAsync(id); + answ = JsonConvert.SerializeObject(elencoDoss); + } + catch (Exception exc) + { + Log.Error($"Errore in GetLastDossByMacc{Environment.NewLine}{exc}"); + return StatusCode(StatusCodes.Status500InternalServerError, "NO"); + } + return Ok(answ); + } + + /// + /// Recupera elenco ListValues data tabella: /// + /// GET: IOB/getListValByTable + /// + /// nome tabella x cui filtrare risultati, se "" mostra tutto + /// Json contenente lista oggetti ListValue serializzati + [HttpGet("getListValByTable/{id}")] + public async Task GetListValByTable(string id) + { + if (string.IsNullOrEmpty(id)) return BadRequest("Missing ID"); + // Multi: gestione carattere "|" trasformato in "#" + id = id.Replace("|", "#"); + + string answ = ""; + try + { + // recupero dati macchina... + var elencoOdl = DService.ListValuesFilt(id, ""); + answ = JsonConvert.SerializeObject(elencoOdl); + } + catch (Exception exc) + { + Log.Error($"Errore in GetListValByTable{Environment.NewLine}{exc}"); + return StatusCode(StatusCodes.Status500InternalServerError, "NO"); + } + return Ok(answ); + } + + /// + /// restituisce elenco parametri correnti come una List Json di oggetti objItem + /// GET: IOB/getObjItems/SIMUL_03 + /// + /// ID dell'IOB + /// + [HttpGet("getObjItems/{id}")] + public async Task GetObjItems(string id) + { + if (string.IsNullOrEmpty(id)) return BadRequest("Missing ID"); + // Multi: gestione carattere "|" trasformato in "#" + id = id.Replace("|", "#"); + + string answ = ""; + + // procedo a recuperare l'oggetto... + List currParams = new List(); + try + { + // deserializzo + var rawData = await DService.MachineParamListAsync(id); + currParams = rawData.OrderBy(x => x.displOrdinal) + .ThenBy(x => x.description) + .ToList(); + // se != null --> salvo! + if (currParams != null) + { + answ = JsonConvert.SerializeObject(currParams); + } + } + catch (Exception exc) + { + Log.Error($"Errore in GetObjItems{Environment.NewLine}{exc}"); + return StatusCode(StatusCodes.Status500InternalServerError, "NO"); + } + return Ok(answ); + } + + [HttpGet("getObjItems2Write/{id}")] + public async Task GetObjItems2Write(string id) + { + if (string.IsNullOrEmpty(id)) return BadRequest("Missing ID"); + // Multi: gestione carattere "|" trasformato in "#" + id = id.Replace("|", "#"); + + string answ = ""; + + // procedo a recuperare l'oggetto... + List currParams = new List(); + try + { + // deserializzo + currParams = await DService.MachineParamListPendingWriteAsync(id); + // se != null --> salvo! + if (currParams != null) + { + answ = JsonConvert.SerializeObject(currParams); + } + } + catch (Exception exc) + { + Log.Error($"Errore in GetObjItems2Write{Environment.NewLine}{exc}"); + return StatusCode(StatusCodes.Status500InternalServerError, "NO"); + } + return Ok(answ); + } + /// /// Recupera TASK richiesto x macchina: /// GET: IOB/getOptPar/SIMUL_03 @@ -591,6 +744,28 @@ namespace MP.IOC.Controllers return Ok(answ); } + [HttpGet("getPOdlNext/{id}")] + public async Task GetPOdlNext(string id) + { + if (string.IsNullOrEmpty(id)) return BadRequest("Missing ID"); + // Multi: gestione carattere "|" trasformato in "#" + id = id.Replace("|", "#"); + + string answ = ""; + try + { + // recupero dati macchina... + var elencoOdl = await DService.POdlGetByMaccArtAsync(id, "", "", true); + answ = JsonConvert.SerializeObject(elencoOdl); + } + catch (Exception exc) + { + Log.Error($"Errore in GetPOdlNext{Environment.NewLine}{exc}"); + return StatusCode(StatusCodes.Status500InternalServerError, "NO"); + } + return Ok(answ); + } + /// /// Recupera TASK richiesto x macchina: /// GET: IOB/getTask2Exe/SIMUL_03 @@ -1044,6 +1219,120 @@ namespace MP.IOC.Controllers } } + /// + /// Processa una chiamata POST per l'invio di una List Json di oggetti objItem + /// POST: IOB/setObjItems/SIMUL_03 + /// + /// ID dell'IOB + /// + [HttpPost("setObjItems/{id}")] + public async Task SetObjItems(string id, [FromBody] List currParams) + { + if (string.IsNullOrEmpty(id)) return BadRequest("Missing ID"); + + // Multi: gestione carattere "|" trasformato in "#" + id = id.Replace("|", "#"); + + string answ = ""; + + try + { + // se != null --> salvo! + if (currParams != null) + { + bool fatto = await DService.MachineParamListSetAsync(id, currParams); + answ = fatto ? "OK" : "KO"; + } + } + catch (Exception exc) + { + Log.Error($"Errore in GetObjItems2Write{Environment.NewLine}{exc}"); + return StatusCode(StatusCodes.Status500InternalServerError, "NO"); + } + return Ok(answ); + } + + /// + /// restituisce elenco parametri CHE RICHIEDONO scrittura su PLC come una List Json di + /// oggetti objItem + /// GET: IOB/getObjItems2Write/SIMUL_03 + /// + /// ID dell'IOB + /// + /// + /// Recupera DATI PODL NEXT (=NON AVVIATI) x macchina: (copia di getCurrPODL) + /// + /// GET: IOB/getPOdlNext/SIMUL_03 + /// + /// id macchina, se "" mostra tutto + /// Json contenente lista oggetti PODL serializzati +#if false + /// + /// Recupera DATI PODL x macchina e codice PODL: + /// + /// GET: IOB/getPODL/SIMUL_03?idxPODL=123 + /// + /// + /// idx del PDL da avviare + /// Json contenente lista oggetti PODL serializzati + public string getPODL(string id, int idxPODL) + { + // attenzione! poiché nell'URL il carattere "#" viene filtrato ci aspettiamo il + // carattere "|" che poi trasformiamo ora in "#" + if (!string.IsNullOrEmpty(id)) + { + id = id.Replace("|", "#"); + } + string answ = ""; + + // init obj DataLayer + DataLayer DataLayerObj = new DataLayer(); + try + { + // recupero dati da chaive, ignorando info macchina... + var elencoOdl = DataLayerObj.taPODL.getByKey(idxPODL); + answ = JsonConvert.SerializeObject(elencoOdl); + } + catch + { } + return answ; + } + + /// + /// Recupera DATI PODL Running/Actual (AVVIATO e in corso) x macchina: + /// + /// GET: IOB/getPOdlAct/SIMUL_03 + /// + /// id macchina, se "" mostra tutto + /// Json contenente lista 1 oggetto PODL serializzato, se presente + public string getPOdlAct(string id) + { + // attenzione! poiché nell'URL il carattere "#" viene filtrato ci aspettiamo il + // carattere "|" che poi trasformiamo ora in "#" + if (!string.IsNullOrEmpty(id)) + { + id = id.Replace("|", "#"); + } + string answ = ""; + + // init obj DataLayer + DataLayer DataLayerObj = new DataLayer(); + try + { + // recupero IdxOdl corrente + string sIdxOdl = DataLayerObj.currODL(id); + int IdxOdl = 0; + int.TryParse(sIdxOdl, out IdxOdl); + // recupero Podl running x macchina ... + DS_ProdTempi.PromesseODLDataTable elencoOdl = DataLayerObj.taPODL.getByIdxOdl(IdxOdl); + answ = JsonConvert.SerializeObject(elencoOdl); + } + catch + { } + return answ; + } +#endif + /// /// Processa una chiamata GET x salvare UserLog /// GET: IOB/ulog/SIMUL_03?flux=PROG&valore=P0001&dtEve=20161223180600000&dtCurr=20161223180600000&cnt=999&matrOpr=0=0&label=&valNum @@ -1276,7 +1565,7 @@ namespace MP.IOC.Controllers DateTime adesso = DateTime.Now; try { - List currParams = DService.MachineParamList(idxMacc); + List currParams = await DService.MachineParamListAsync(idxMacc); // ora per ogni valore RICEVUTO costruisco un oggetto in innovazioni da // inviare...x salvare in stato parametri... List innovazioni = new List(); diff --git a/MP.IOC/Data/MpDataService.cs b/MP.IOC/Data/MpDataService.cs index 7ffbd6ab..434495af 100644 --- a/MP.IOC/Data/MpDataService.cs +++ b/MP.IOC/Data/MpDataService.cs @@ -396,6 +396,42 @@ namespace MP.IOC.Data return fatto; } + /// + /// Elenco ultimi articoli data amcchina + /// + /// + /// + public async Task> ArticoliGetLastByMaccAsync(string idxMacc) + { + List? result = new List(); + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + string readType = "DB"; + string currKey = $"{Utils.redisArtList}:Last:{idxMacc}"; + // cerco in redis dato valore sel macchina... + RedisValue rawData = redisDb.StringGet(currKey); + if (rawData.HasValue) + { + result = JsonConvert.DeserializeObject>($"{rawData}"); + readType = "REDIS"; + } + else + { + result = await IocDbController.ArticoliGetLastByMaccAsync(idxMacc); + // serializzo e salvo... + rawData = JsonConvert.SerializeObject(result); + redisDb.StringSet(currKey, rawData, getRandTOut(redisLongTimeCache)); + } + if (result == null) + { + result = new List(); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"ArticoliGetLastByMaccAsync | Read from {readType}: {ts.TotalMilliseconds}ms"); + return result; + } + /// /// Restitusice elenco articoli cercati /// @@ -745,6 +781,69 @@ namespace MP.IOC.Data redisConn.Dispose(); } + /// + /// Restituisce l'elenco delle date dei dossier x una macchina (se presenti) Impiegata anche + /// cache redis + /// + /// + /// + public async Task> DossierLastByMachAsync(string idxMacchina) + { + List result = new List(); + + var currKey = $"{Utils.redisDossByMacLast}:{idxMacchina}"; + RedisValue rawData = await redisDb.StringGetAsync(currKey); + if (rawData.HasValue) + { + result = JsonConvert.DeserializeObject>($"{rawData}") ?? new(); + } + else + { + result = await IocDbController.DossGetLastByMaccAsync(idxMacchina); + // serializzo e salvo... + rawData = JsonConvert.SerializeObject(result); + await redisDb.StringSetAsync(currKey, rawData, getRandTOut(redisLongTimeCache)); + } + if (result == null) + { + result = new List(); + } + 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 /// @@ -966,7 +1065,11 @@ namespace MP.IOC.Data if (listaDoss.Count > 0) { // primo giorno DOPO ultima registrazione - dtFrom = listaDoss.OrderByDescending(x => x).FirstOrDefault().AddDays(1); + dtFrom = listaDoss + .Select(x => x.DtRif) + .OrderByDescending(x => x) + .FirstOrDefault() + .AddDays(1); } else { @@ -975,7 +1078,10 @@ namespace MP.IOC.Data if (listaFL.Count > 0) { // giorno successivo a prima registrazione - dtFrom = listaFL.OrderBy(x => x).FirstOrDefault().AddDays(1); + dtFrom = listaFL + .OrderBy(x => x) + .FirstOrDefault() + .AddDays(1); } } string caller = $"takeFlogSnapshot({idxMacc})"; @@ -1297,6 +1403,7 @@ namespace MP.IOC.Data // 2. Se non c'è in cache, carichiamo/resettiamo tutto if (val == null) { + //var data = ResetDatiMacchina(idxMacchina); var data = await ResetDatiMacchinaAsync(idxMacchina); data.TryGetValue("insEnabled", out val); } @@ -1374,6 +1481,7 @@ namespace MP.IOC.Data Log.Debug($"Macchine2SlaveGetAll | Read from {readType}: {ts.TotalMilliseconds}ms"); return result; } + /// /// Elenco completo valori Macchine 2 Slave /// @@ -1623,6 +1731,20 @@ namespace MP.IOC.Data return result; } + /// + /// Lista parametri correnti che necessitano di write della macchina (ex getCurrObjItems) + /// + /// + /// + public async Task> MachineParamListPendingWriteAsync(string idxMacchina) + { + List? result = new List(); + // recupero tutti i parametri + var allData = await MachineParamListAsync(idxMacchina); + result = allData.Where(x => x.writable && !string.IsNullOrEmpty(x.reqValue)).ToList(); + return result; + } + /// /// Esegue aggiornamento MachineParamList (ex CurrObjItems) /// @@ -4049,35 +4171,28 @@ namespace MP.IOC.Data return resultList; } - /// - /// Restituisce l'elenco delle date dei dossier x una macchina (se presenti) Impiegata anche - /// cache redis - /// - /// - /// - private async Task> DossierLastByMachAsync(string idxMacchina) + public async Task> ListValuesFilt(string tabName, string fieldName) { - List resultList = new List(); - - var currKey = $"{Utils.redisDossByMacLast}:{idxMacchina}"; + 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(); + resultList = JsonConvert.DeserializeObject>($"{rawData}") ?? new(); } else { - var dbData = await IocDbController.DossGetLastByMaccAsync(idxMacchina); - resultList = dbData - .Select(x => x.DtRif) - .ToList(); + 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 List(); + resultList = new(); } return resultList; } @@ -4347,38 +4462,50 @@ namespace MP.IOC.Data Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); string readType = "DB"; + var dbResults = await IocDbController.VMSFDGetByMaccAsync(idxMacc); +#if false + // recupero tutte e filtro a mano... + var dbResults = await IocDbController.VMSFDGetAllAsync(); +#endif // converto in formato dizionario... if (dbResults != null && dbResults.Count > 0) { - var rowResult = dbResults[0]; - // salvo 1:1 i valori... STATO - result.Add("IdxMicroStato", $"{rowResult.IdxMicroStato}"); - result.Add("IdxStato", $"{rowResult.IdxStato}"); - result.Add("CodArticolo", $"{rowResult.CodArticolo}"); - result.Add("insEnabled", $"{rowResult.InsEnabled}"); - result.Add("sLogEnabled", $"{rowResult.SLogEnabled}"); - result.Add("pallet", $"{rowResult.Pallet}"); - result.Add("CodArticolo_A", $"{rowResult.CodArticoloA}"); - result.Add("CodArticolo_B", $"{rowResult.CodArticoloB}"); - result.Add("TempoCicloBase", $"{rowResult.TempoCicloBase}"); - result.Add("PzPalletProd", $"{rowResult.PzPalletProd}"); - result.Add("MatrOpr", $"{rowResult.MatrOpr}"); - result.Add("lastVal", $"{rowResult.LastVal}"); - result.Add("TCBase", $"{rowResult.TempoCicloBase}"); + //var rowResult = dbResults[0]; + var rowResult = dbResults.FirstOrDefault(); +#if false + var rowResult = dbResults.FirstOrDefault(x => x.IdxMacchina == idxMacc); +#endif + if (rowResult != null) + { + // salvo 1:1 i valori... STATO + result.Add("IdxMicroStato", $"{rowResult.IdxMicroStato}"); + result.Add("IdxStato", $"{rowResult.IdxStato}"); + result.Add("CodArticolo", $"{rowResult.CodArticolo}"); + result.Add("insEnabled", $"{rowResult.InsEnabled}"); + result.Add("sLogEnabled", $"{rowResult.SLogEnabled}"); + result.Add("pallet", $"{rowResult.Pallet}"); + result.Add("CodArticolo_A", $"{rowResult.CodArticoloA}"); + result.Add("CodArticolo_B", $"{rowResult.CodArticoloB}"); + result.Add("TempoCicloBase", $"{rowResult.TempoCicloBase}"); + result.Add("PzPalletProd", $"{rowResult.PzPalletProd}"); + result.Add("MatrOpr", $"{rowResult.MatrOpr}"); + result.Add("lastVal", $"{rowResult.LastVal}"); + result.Add("TCBase", $"{rowResult.TempoCicloBase}"); - //...e SETUP - result.Add("CodMacc", $"{rowResult.Codmacchina}"); - result.Add("IdxFamIn", $"{rowResult.IdxFamigliaIngresso}"); - result.Add("Multi", $"{rowResult.Multi}"); - result.Add("BitFilt", $"{rowResult.BitFilt}"); - result.Add("MaxVal", $"{rowResult.MaxVal}"); - result.Add("BSR", $"{rowResult.Bsr}"); - result.Add("ExplodeBit", $"{rowResult.ExplodeBit}"); - result.Add("NumBit", $"{rowResult.NumBit}"); - result.Add("IdxFamMacc", $"{rowResult.IdxFamiglia}"); - result.Add("simplePallet", $"{rowResult.SimplePallet}"); - result.Add("palletChange", $"{rowResult.PalletChange}"); + //...e SETUP + result.Add("CodMacc", $"{rowResult.Codmacchina}"); + result.Add("IdxFamIn", $"{rowResult.IdxFamigliaIngresso}"); + result.Add("Multi", $"{rowResult.Multi}"); + result.Add("BitFilt", $"{rowResult.BitFilt}"); + result.Add("MaxVal", $"{rowResult.MaxVal}"); + result.Add("BSR", $"{rowResult.Bsr}"); + result.Add("ExplodeBit", $"{rowResult.ExplodeBit}"); + result.Add("NumBit", $"{rowResult.NumBit}"); + result.Add("IdxFamMacc", $"{rowResult.IdxFamiglia}"); + result.Add("simplePallet", $"{rowResult.SimplePallet}"); + result.Add("palletChange", $"{rowResult.PalletChange}"); + } } // cerco info Master/slave... var m2sTab = await Macchine2SlaveGetAllAsync(); @@ -4402,8 +4529,6 @@ namespace MP.IOC.Data return result; } - - /// /// Resetta (rileggendo) i dati della State Machine ingressi nel formato /// currKey: cState_nVal (current MICRO-STATE + "_" + new Value) diff --git a/MP.IOC/MP.IOC.csproj b/MP.IOC/MP.IOC.csproj index b97afade..c8fcf7b9 100644 --- a/MP.IOC/MP.IOC.csproj +++ b/MP.IOC/MP.IOC.csproj @@ -4,7 +4,7 @@ net8.0 enable enable - 6.16.2604.1608 + 6.16.2604.1612 diff --git a/MP.IOC/Resources/ChangeLog.html b/MP.IOC/Resources/ChangeLog.html index 61354818..b3ccad27 100644 --- a/MP.IOC/Resources/ChangeLog.html +++ b/MP.IOC/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MP-IOC -

Versione: 6.16.2604.1608

+

Versione: 6.16.2604.1612


Note di rilascio:
  • diff --git a/MP.IOC/Resources/VersNum.txt b/MP.IOC/Resources/VersNum.txt index df2a6ad6..c468233b 100644 --- a/MP.IOC/Resources/VersNum.txt +++ b/MP.IOC/Resources/VersNum.txt @@ -1 +1 @@ -6.16.2604.1608 +6.16.2604.1612 diff --git a/MP.IOC/Resources/manifest.xml b/MP.IOC/Resources/manifest.xml index 9dae35f9..025c377c 100644 --- a/MP.IOC/Resources/manifest.xml +++ b/MP.IOC/Resources/manifest.xml @@ -1,6 +1,6 @@ - 6.16.2604.1608 + 6.16.2604.1612 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