Merge branch 'Release/AggiuntaMetodiIoc_06'
This commit is contained in:
@@ -78,6 +78,7 @@ namespace MP.Core
|
||||
|
||||
public const string redisTipoArt = redisBaseAddr + "Cache:TipoArt";
|
||||
|
||||
public const string redisVetoSplitOdl = redisBaseAddr + "Cache:VetoOdlMacc";
|
||||
public const string redisVocabolario = redisBaseAddr + "Cache:Vocabolario";
|
||||
|
||||
public const string redisXdlData = redisBaseAddr + "Cache:XDL:";
|
||||
|
||||
@@ -96,6 +96,140 @@ namespace MP.Data.Controllers
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Apre in automatico un nuovo PODL/ODL chiudendo l'attuale (aperto)
|
||||
/// </summary>
|
||||
/// <param name="idxOdl">Idx ODL corrente</param>
|
||||
/// <param name="MatrOpr">Matricola operatore</param>
|
||||
/// <param name="idxMacchina">idx macchina da confermare</param>
|
||||
/// <param name="tCRich">TempoCiclo richiesto in attrezzaggio</param>
|
||||
/// <param name="pzPallet"># pz pallet</param>
|
||||
/// <param name="note">note ODL</param>
|
||||
/// <param name="startNewOdl">bool per avvio nuovo ODL (def: true)</param>
|
||||
/// <param name="qtyRich">Qty da produrre, deve essere >0</param>
|
||||
/// <param name="keyRich">KeyRich esterno, se vuoto uso vecchia, se KIT sovrascritto con KeyKit</param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> AutoStartOdlAsync(int idxOdl, int MatrOpr, string idxMacchina, decimal tCRich, int pzPallet, string note, bool startNewOdl, int qtyRich, string keyRich)
|
||||
{
|
||||
bool answ = false;
|
||||
try
|
||||
{
|
||||
using (var dbCtx = new MoonProContext(_configuration))
|
||||
{
|
||||
var IdxOdl = new SqlParameter("@idxOdl ", idxOdl);
|
||||
var MatrApp = new SqlParameter("@MatrApp ", MatrOpr);
|
||||
var IdxMacchina = new SqlParameter("@idxMacchina", idxMacchina);
|
||||
var TCRich = new SqlParameter("@TCRichAttr", tCRich);
|
||||
var PzPallet = new SqlParameter("@PzPallet", pzPallet);
|
||||
var Note = new SqlParameter("@Note", note);
|
||||
var StartNewOdl = new SqlParameter("@StartNewOdl", startNewOdl);
|
||||
var QtyRich = new SqlParameter("@QtyRich", qtyRich);
|
||||
var KeyRichiesta = new SqlParameter("@KeyRichiesta", keyRich);
|
||||
|
||||
var result = await dbCtx
|
||||
.Database
|
||||
.ExecuteSqlRawAsync("EXEC stp_ODL_AutoStart @idxOdl, @MatrApp, @idxMacchina, @TCRichAttr, @PzPallet, @Note, @StartNewOdl, @QtyRich, @KeyRichiesta", IdxOdl, MatrApp, IdxMacchina, TCRich, PzPallet, Note, StartNewOdl, QtyRich, KeyRichiesta);
|
||||
|
||||
// indico eseguito!
|
||||
answ = result > 0;
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione in ConfermaProdMacchina:{Environment.NewLine}{exc}");
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Effettua conferma prod macchina dell'intero periodo da confermare (ultima conferma - dtEvent)
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina">idx macchina da confermare</param>
|
||||
/// <param name="modoConfProd">0=periodo, 1 = giorno, 2 = turno</param>
|
||||
/// <param name="numPzConfermati">qta pezzi BUONI da confermare</param>
|
||||
/// <param name="numPzScarto">qta pezzi SCARTO da confermare</param>
|
||||
/// <param name="DataOraApp">DataOra in cui registrare approvazione</param>
|
||||
/// <param name="MatrOpr">Matricola operatore</param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> ConfermaProdMacchinaAsync(string idxMacchina, int modoConfProd, int numPzConfermati, int numPzScarto, DateTime DataOraApp, int MatrOpr)
|
||||
{
|
||||
bool answ = false;
|
||||
try
|
||||
{
|
||||
var rigaProd = await StatoProdMacchinaAsync(idxMacchina, DateTime.Now);
|
||||
using (var dbCtx = new MoonProContext(_configuration))
|
||||
{
|
||||
var IdxMacchina = new SqlParameter("@idxMacchina", idxMacchina);
|
||||
var MatrApp = new SqlParameter("@MatrApp ", MatrOpr);
|
||||
var DataFrom = new SqlParameter("@dataFrom ", rigaProd.DataFrom);
|
||||
var DataTo = new SqlParameter("@dataTo", DataOraApp);
|
||||
var PezziConf = new SqlParameter("@pezziConf", numPzConfermati);
|
||||
var PezziScar = new SqlParameter("@pezziScar", numPzScarto);
|
||||
var TipoConf = new SqlParameter("@TipoConf", modoConfProd);
|
||||
var DtOraApp = new SqlParameter("@DataOraApp", DataOraApp);
|
||||
var TestConferma = new SqlParameter("@TestConferma", true);
|
||||
|
||||
var result = await dbCtx
|
||||
.Database
|
||||
.ExecuteSqlRawAsync("EXEC stp_ConfermaProduzCompleta @idxMacchina, @MatrApp, @dataFrom, @dataTo, @pezziConf, @pezziScar, @TipoConf, @DataOraApp, @TestConferma ", IdxMacchina, MatrApp, DataFrom, DataTo, PezziConf, PezziScar, TipoConf, DtOraApp, TestConferma);
|
||||
|
||||
// indico eseguito!
|
||||
answ = result > 0;
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione in ConfermaProdMacchina:{Environment.NewLine}{exc}");
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Effettua conferma prod macchina dell'intero periodo da confermare (ultima conferma - dtEvent)
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina">idx macchina da confermare</param>
|
||||
/// <param name="modoConfProd">0=periodo, 1 = giorno, 2 = turno</param>
|
||||
/// <param name="numPzConfermati">qta pezzi BUONI da confermare</param>
|
||||
/// <param name="numPzLasciati">qta pezzi LASCIATI da confermare</param>
|
||||
/// <param name="numPzScarto">qta pezzi SCARTO da confermare</param>
|
||||
/// <param name="DataOraApp">DataOra in cui registrare approvazione</param>
|
||||
/// <param name="MatrOpr">Matricola operatore</param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> ConfermaProdMacchinaFullAsync(string idxMacchina, int modoConfProd, int numPzConfermati, int numPzLasciati, int numPzScarto, DateTime DataOraApp, int MatrOpr)
|
||||
{
|
||||
bool answ = false;
|
||||
try
|
||||
{
|
||||
var rigaProd = await StatoProdMacchinaAsync(idxMacchina, DateTime.Now);
|
||||
using (var dbCtx = new MoonProContext(_configuration))
|
||||
{
|
||||
var IdxMacchina = new SqlParameter("@idxMacchina", idxMacchina);
|
||||
var MatrApp = new SqlParameter("@MatrApp ", MatrOpr);
|
||||
var DataFrom = new SqlParameter("@dataFrom ", rigaProd.DataFrom);
|
||||
var DataTo = new SqlParameter("@dataTo", DataOraApp);
|
||||
var PezziConf = new SqlParameter("@pezziConf", numPzConfermati);
|
||||
var PezziLasc = new SqlParameter("@pezziLasciati", numPzLasciati);
|
||||
var PezziScar = new SqlParameter("@pezziScar", numPzScarto);
|
||||
var TipoConf = new SqlParameter("@TipoConf", modoConfProd);
|
||||
var DtOraApp = new SqlParameter("@DataOraApp", DataOraApp);
|
||||
var TestConferma = new SqlParameter("@TestConferma", true);
|
||||
var Force = new SqlParameter("@Force", false);
|
||||
|
||||
var result = await dbCtx
|
||||
.Database
|
||||
.ExecuteSqlRawAsync("EXEC stp_ConfermaProduzCompletaFull @idxMacchina, @MatrApp, @dataFrom, @dataTo, @pezziConf, @pezziLasciati, @pezziScar, @TipoConf, @DataOraApp, @TestConferma,@Force", IdxMacchina, MatrApp, DataFrom, DataTo, PezziConf, PezziLasc, PezziScar, TipoConf, DtOraApp, TestConferma, Force);
|
||||
|
||||
// indico eseguito!
|
||||
answ = result > 0;
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione in ConfermaProdMacchinaAsync:{Environment.NewLine}{exc}");
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Record ConfFlux dato macchina (oppure tutti se vuoto)
|
||||
/// </summary>
|
||||
@@ -326,6 +460,65 @@ namespace MP.Data.Controllers
|
||||
}
|
||||
return fatto;
|
||||
}
|
||||
/// <summary>
|
||||
/// Fix ODL per macchine SLAVE
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <param name="numDayPrev"></param>
|
||||
/// <param name="doInsert"></param>
|
||||
/// <returns></returns>
|
||||
public bool OdlFixMachineSlave(string idxMacchina, int numDayPrev, int doInsert)
|
||||
{
|
||||
bool fatto = false;
|
||||
using (var dbCtx = new MoonProContext(_configuration))
|
||||
{
|
||||
try
|
||||
{
|
||||
var IdxMacc = new SqlParameter("@IdxMacchina", idxMacchina);
|
||||
var NumDayPrev = new SqlParameter("@NumDayPrev", numDayPrev);
|
||||
var DoInsert = new SqlParameter("@DoInsert", doInsert);
|
||||
var result = dbCtx
|
||||
.Database
|
||||
.ExecuteSqlRaw("EXEC stp_ODL_fixMachineSlave @IdxMacchina, @NumDayPrev, @DoInsert", IdxMacc, NumDayPrev, DoInsert);
|
||||
fatto = result != 0;
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante OdlFixMachineSlave{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
return fatto;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fix ODL per macchine SLAVE Async
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <param name="numDayPrev"></param>
|
||||
/// <param name="doInsert"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> OdlFixMachineSlaveAsync(string idxMacchina, int numDayPrev, int doInsert)
|
||||
{
|
||||
bool fatto = false;
|
||||
using (var dbCtx = new MoonProContext(_configuration))
|
||||
{
|
||||
try
|
||||
{
|
||||
var IdxMacc = new SqlParameter("@IdxMacchina", idxMacchina);
|
||||
var NumDayPrev = new SqlParameter("@NumDayPrev", numDayPrev);
|
||||
var DoInsert = new SqlParameter("@DoInsert", doInsert);
|
||||
var result = await dbCtx
|
||||
.Database
|
||||
.ExecuteSqlRawAsync("EXEC stp_ODL_fixMachineSlave @IdxMacchina, @NumDayPrev, @DoInsert", IdxMacc, NumDayPrev, DoInsert);
|
||||
fatto = result != 0;
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante OdlFixMachineSlaveAsync{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
return fatto;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Chiamata x stored recupero FluxLog x macchina (first)
|
||||
@@ -597,9 +790,9 @@ namespace MP.Data.Controllers
|
||||
public List<MacchineModel> MacchineGetAll()
|
||||
{
|
||||
List<MacchineModel> dbResult = new List<MacchineModel>();
|
||||
using (MoonProContext localDbCtx = new MoonProContext(_configuration))
|
||||
using (MoonProContext dbCtx = new MoonProContext(_configuration))
|
||||
{
|
||||
dbResult = localDbCtx
|
||||
dbResult = dbCtx
|
||||
.DbSetMacchine
|
||||
.ToList();
|
||||
}
|
||||
@@ -609,14 +802,25 @@ namespace MP.Data.Controllers
|
||||
public MacchineModel? MacchineGetByIdx(string IdxMacchina)
|
||||
{
|
||||
MacchineModel dbResult = null;
|
||||
using (MoonProContext localDbCtx = new MoonProContext(_configuration))
|
||||
using (MoonProContext dbCtx = new MoonProContext(_configuration))
|
||||
{
|
||||
dbResult = localDbCtx
|
||||
dbResult = dbCtx
|
||||
.DbSetMacchine
|
||||
.FirstOrDefault(x => x.IdxMacchina == IdxMacchina);
|
||||
}
|
||||
return dbResult;
|
||||
}
|
||||
public async Task<MacchineModel?> MacchineGetByIdxAsync(string IdxMacchina)
|
||||
{
|
||||
MacchineModel dbResult = null;
|
||||
using (MoonProContext dbCtx = new MoonProContext(_configuration))
|
||||
{
|
||||
dbResult = await dbCtx
|
||||
.DbSetMacchine
|
||||
.FirstOrDefaultAsync(x => x.IdxMacchina == IdxMacchina);
|
||||
}
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco da tabella Macchine
|
||||
@@ -667,21 +871,21 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public bool MacchineUpsert(MacchineModel entity)
|
||||
{
|
||||
using (MoonProContext localDbCtx = new MoonProContext(_configuration))
|
||||
using (MoonProContext dbCtx = new MoonProContext(_configuration))
|
||||
{
|
||||
// Recuperiamo l'entità tracciata dal context
|
||||
var trackedEntity = localDbCtx.DbSetMacchine.FirstOrDefault(x => x.IdxMacchina == entity.IdxMacchina);
|
||||
var trackedEntity = dbCtx.DbSetMacchine.FirstOrDefault(x => x.IdxMacchina == entity.IdxMacchina);
|
||||
|
||||
if (trackedEntity != null)
|
||||
{
|
||||
// Aggiorna i valori dell'entità tracciata con quelli della nuova
|
||||
localDbCtx.Entry(trackedEntity).CurrentValues.SetValues(entity);
|
||||
dbCtx.Entry(trackedEntity).CurrentValues.SetValues(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
localDbCtx.DbSetMacchine.Update(entity);
|
||||
dbCtx.DbSetMacchine.Update(entity);
|
||||
}
|
||||
return localDbCtx.SaveChanges() > 0;
|
||||
return dbCtx.SaveChanges() > 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -691,28 +895,29 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> MacchineUpsertAsync(MacchineModel entity)
|
||||
{
|
||||
using (MoonProContext localDbCtx = new MoonProContext(_configuration))
|
||||
using (MoonProContext dbCtx = new MoonProContext(_configuration))
|
||||
{
|
||||
// Recuperiamo l'entità tracciata dal context
|
||||
var trackedEntity = await localDbCtx.DbSetMacchine.FirstOrDefaultAsync(x => x.IdxMacchina == entity.IdxMacchina);
|
||||
var trackedEntity = await dbCtx.DbSetMacchine.FirstOrDefaultAsync(x => x.IdxMacchina == entity.IdxMacchina);
|
||||
|
||||
if (trackedEntity != null)
|
||||
{
|
||||
// Aggiorna i valori dell'entità tracciata con quelli della nuova
|
||||
localDbCtx.Entry(trackedEntity).CurrentValues.SetValues(entity);
|
||||
dbCtx.Entry(trackedEntity).CurrentValues.SetValues(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
localDbCtx.DbSetMacchine.Update(entity);
|
||||
dbCtx.DbSetMacchine.Update(entity);
|
||||
}
|
||||
return await localDbCtx.SaveChangesAsync() > 0;
|
||||
bool fatto = await dbCtx.SaveChangesAsync() > 0;
|
||||
return fatto;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco da tabella Macchine
|
||||
/// </summary>
|
||||
/// <param name="codGruppo"></param>
|
||||
/// <param name="IdxMacc"></param>
|
||||
/// <returns></returns>
|
||||
public List<MicroStatoMacchinaModel> MicroStatoMacchinaGetByIdxMacc(string IdxMacc)
|
||||
{
|
||||
@@ -727,6 +932,24 @@ namespace MP.Data.Controllers
|
||||
return dbResult;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Elenco da tabella Macchine
|
||||
/// </summary>
|
||||
/// <param name="IdxMacc"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<MicroStatoMacchinaModel>> MicroStatoMacchinaGetByIdxMaccAsync(string IdxMacc)
|
||||
{
|
||||
List<MicroStatoMacchinaModel> dbResult = new List<MicroStatoMacchinaModel>();
|
||||
using (var dbCtx = new MoonProContext(_configuration))
|
||||
{
|
||||
dbResult = await dbCtx
|
||||
.DbSetMicroStatoMacc
|
||||
.Where(x => x.IdxMacchina == IdxMacc)
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
return dbResult;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aggiornamento record Microstato macchina
|
||||
@@ -1100,7 +1323,38 @@ namespace MP.Data.Controllers
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione in RicalcMse:{Environment.NewLine}{exc}");
|
||||
Log.Error($"Eccezione in RecalcMse:{Environment.NewLine}{exc}");
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
/// <summary>
|
||||
/// Effettua ricalcolo MSE x macchina indicata
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina">idx macchina da confermare</param>
|
||||
/// <param name="maxAgeSec">Num massimo secondi di "vecchiaia" del dato</param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> RecalcMseAsync(string idxMacchina, int maxAgeSec)
|
||||
{
|
||||
bool answ = false;
|
||||
try
|
||||
{
|
||||
var rigaProd = await StatoProdMacchinaAsync(idxMacchina, DateTime.Now);
|
||||
using (var dbCtx = new MoonProContext(_configuration))
|
||||
{
|
||||
var MaxAgeSec = new SqlParameter("@maxAgeSec ", maxAgeSec);
|
||||
var IdxMacchina = new SqlParameter("@idxMacchina", idxMacchina);
|
||||
|
||||
var result = await dbCtx
|
||||
.Database
|
||||
.ExecuteSqlRawAsync("EXEC stp_MSE_recalc @maxAgeSec, @idxMacchina ", MaxAgeSec, IdxMacchina);
|
||||
|
||||
// indico eseguito!
|
||||
answ = result > 0;
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione in RecalcMseAsync:{Environment.NewLine}{exc}");
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace MP.IOC.Components.Compo
|
||||
public List<StatDataDTO> ParetoList { get; set; } = null!;
|
||||
|
||||
[Parameter]
|
||||
public string Title { get; set; } = null!;
|
||||
public string Title { get; set; } = "";
|
||||
|
||||
#endregion Public Properties
|
||||
|
||||
@@ -29,6 +29,11 @@ namespace MP.IOC.Components.Compo
|
||||
{
|
||||
grandTotal = 1;
|
||||
}
|
||||
if (_title != Title)
|
||||
{
|
||||
_title = Title;
|
||||
currSelect = "";
|
||||
}
|
||||
UpdateTable();
|
||||
}
|
||||
|
||||
@@ -44,15 +49,18 @@ namespace MP.IOC.Components.Compo
|
||||
private string currSelect = "";
|
||||
private double grandTotal = 1;
|
||||
private List<StatDataDTO> ListPaged = new();
|
||||
|
||||
private int numRecPage = 10;
|
||||
|
||||
private int pageNum = 1;
|
||||
|
||||
private int totalCount = 0;
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Private Properties
|
||||
|
||||
private string _title { get; set; } = null!;
|
||||
|
||||
#endregion Private Properties
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private string CheckSelect(string curKey)
|
||||
|
||||
@@ -127,6 +127,7 @@ namespace MP.IOC.Components.Pages
|
||||
currTsId = $"TS_{reqKey}";
|
||||
currTitle = $"Pareto | {reqKey}";
|
||||
currData = ParetoDay[reqKey];
|
||||
tsDataDetail = new();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -326,6 +326,37 @@ namespace MP.IOC.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Chiude ODL precedente ed avvia uno nuovo (duplicandolo e sitemando quantità RIMANENTE),
|
||||
/// e CONFERMA produzione...
|
||||
///
|
||||
/// GET: IOB/forceSplitOdl/SIMUL_03
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns>Esito chiamata (OK/vuoto)</returns>
|
||||
|
||||
[HttpGet("forceSplitOdl/{id}")]
|
||||
public async Task<IActionResult> ForceSplitOdl(string id)
|
||||
{
|
||||
if (string.IsNullOrEmpty(id)) return BadRequest("Missing ID");
|
||||
|
||||
// Multi: gestione carattere "|" trasformato in "#"
|
||||
id = id.Replace("|", "#");
|
||||
|
||||
string answ = "";
|
||||
|
||||
try
|
||||
{
|
||||
answ = await DService.AutoStartOdlAsync(id, true, true, 100, 0, "");
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Errore in ForceSplitOdl{Environment.NewLine}{exc}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, "NO");
|
||||
}
|
||||
return Ok(answ);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recupera ArtNum dato CodXdl (per impianti che accettano solo INT in scrittura):
|
||||
/// GET: IOB/getArtNum/SIMUL_03?CodXdl=ABC123
|
||||
@@ -779,20 +810,19 @@ namespace MP.IOC.Controllers
|
||||
|
||||
// Multi: gestione carattere "|" trasformato in "#"
|
||||
id = id.Replace("|", "#");
|
||||
string answ = "";
|
||||
Dictionary<string, string> valori = new();
|
||||
try
|
||||
{
|
||||
await DService.ScriviKeepAliveAsync(id, DateTime.Now);
|
||||
// leggo da REDIS eventuale elenco task x macchina...
|
||||
Dictionary<string, string> valori = await DService.GetTask2ExeMacchinaAsync(id);
|
||||
answ = JsonConvert.SerializeObject(valori);
|
||||
valori = await DService.GetTask2ExeMacchinaAsync(id);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Errore in GetTask2Exe{Environment.NewLine}{exc}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, "NO");
|
||||
}
|
||||
return Ok(answ);
|
||||
return Ok(valori);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -840,7 +870,7 @@ namespace MP.IOC.Controllers
|
||||
if (string.IsNullOrEmpty(id)) return BadRequest("Missing ID");
|
||||
|
||||
string answ = "";
|
||||
if (cnt == null)
|
||||
if (string.IsNullOrEmpty(cnt))
|
||||
{
|
||||
cnt = "0";
|
||||
}
|
||||
|
||||
+590
-108
@@ -246,6 +246,70 @@ namespace MP.IOC.Data
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aggiunge un set di task x macchina all'elenco di quelli salvati (in modalità upsert)
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <param name="taskKey"></param>
|
||||
/// <param name="taskVal"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> AddTask4MacListAsync(string idxMacchina, Dictionary<Enums.taskType, string> taskDict)
|
||||
{
|
||||
bool answ = false;
|
||||
bool needSaveParams = false;
|
||||
var currHash = Utils.RedKeyTask2ExeMacc(idxMacchina, MpIoNS);
|
||||
var currSavedParHash = Utils.RedKeySavedTask2ExeMacc(idxMacchina, MpIoNS);
|
||||
Dictionary<string, string> currTask = new Dictionary<string, string>();
|
||||
Dictionary<string, string> savedTask = new Dictionary<string, string>();
|
||||
|
||||
// leggo valori attuali...
|
||||
currTask = await mTaskMacchinaAsync(idxMacchina);
|
||||
// verifico processing dei ricevuti
|
||||
foreach (var item in taskDict)
|
||||
{
|
||||
if (currTask.ContainsKey($"{item.Key}"))
|
||||
{
|
||||
currTask[$"{item.Key}"] = item.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
currTask.Add($"{item.Key}", item.Value);
|
||||
}
|
||||
Log.Trace($"Task ADD | hash: {currHash} | idxMacchina: {idxMacchina} | taskKey: {item.Key} | taskVal: {item.Value}");
|
||||
|
||||
// verifico in base al tipo di tName se fare backup...
|
||||
switch (item.Key)
|
||||
{
|
||||
case Enums.taskType.setArt:
|
||||
case Enums.taskType.setComm:
|
||||
case Enums.taskType.setPzComm:
|
||||
case Enums.taskType.setProg:
|
||||
// leggo tName SALVATI attuali...
|
||||
savedTask = mSavedTaskMacchina(idxMacchina);
|
||||
savedTask[item.Key.ToString()] = item.Value;
|
||||
needSaveParams = true;
|
||||
break;
|
||||
|
||||
case Enums.taskType.endProd:
|
||||
// salvo un DICT vuoto x resettare
|
||||
savedTask = new Dictionary<string, string>();
|
||||
needSaveParams = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
// salvo!
|
||||
answ = await RedisSetHashDictAsync(currHash, currTask);
|
||||
|
||||
if (needSaveParams)
|
||||
{
|
||||
answ = await RedisSetHashDictAsync(currSavedParHash, savedTask);
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Insert record allarme
|
||||
/// </summary>
|
||||
@@ -549,6 +613,308 @@ namespace MP.IOC.Data
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Effettua split ODL
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina">macchina</param>
|
||||
/// <param name="doConfirm">effettuare conferma qty</param>
|
||||
/// <param name="qtyFromLast">imposta la qty prox ODL da ODL che si chiude</param>
|
||||
/// <param name="matrOpr">matricola operatore</param>
|
||||
/// <param name="roundStep">Round Step quantità prox ODL (corrente come riferimento)</param>
|
||||
/// <param name="keyRichiesta">Cod ext da associare all'ODL</param>
|
||||
/// <returns></returns>
|
||||
public async Task<string> AutoStartOdlAsync(string idxMacchina, bool doConfirm, bool qtyFromLast, int matrOpr, int roundStep = 100, string keyRichiesta = "")
|
||||
{
|
||||
string answ = "KO";
|
||||
DateTime adesso = DateTime.Now;
|
||||
|
||||
// verifico NON CI SIA un veto a NUOVI split...
|
||||
string redKey = $"{Utils.redisVetoSplitOdl}:{idxMacchina}";
|
||||
var rawData = await redisDb.StringGetAsync(redKey);
|
||||
if (rawData.HasValue)
|
||||
{
|
||||
Log.Info($"VETO ATTIVO | Richiesto forceSplitOdl per impianto {idxMacchina} | impossibile procedere");
|
||||
}
|
||||
else
|
||||
{
|
||||
// registro VETO x altri split... 5 minuti
|
||||
await redisDb.StringSetAsync(redKey, $"Inizio SPLIT-ODL {adesso}", TimeSpan.FromMinutes(5));
|
||||
// setup dati da config
|
||||
bool confRett = false;
|
||||
int modoConfProd = -1;
|
||||
bool slaveConfirmPzProd = false;
|
||||
var configData = await ConfigGetAllAsync();
|
||||
if (configData != null)
|
||||
{
|
||||
var currRec = configData.FirstOrDefault(x => x.Chiave == "confRett");
|
||||
if (currRec != null)
|
||||
{
|
||||
bool.TryParse(currRec.Valore, out confRett);
|
||||
}
|
||||
currRec = configData.FirstOrDefault(x => x.Chiave == "modoConfProd");
|
||||
if (currRec != null)
|
||||
{
|
||||
int.TryParse(currRec.Valore, out modoConfProd);
|
||||
}
|
||||
currRec = configData.FirstOrDefault(x => x.Chiave == "SlaveConfirmPzProd");
|
||||
if (currRec != null)
|
||||
{
|
||||
bool.TryParse(currRec.Valore, out slaveConfirmPzProd);
|
||||
}
|
||||
}
|
||||
// calcolo la qta da gestire
|
||||
int qtyConf = 0;
|
||||
int qtyNew = 0;
|
||||
int qtyScarto = 0;
|
||||
if (doConfirm)
|
||||
{
|
||||
try
|
||||
{
|
||||
var rigaProd = await IocDbController.PezziProdMacchinaAsync(idxMacchina);
|
||||
var statoProd = await IocDbController.StatoProdMacchinaAsync(idxMacchina, adesso);
|
||||
qtyConf = rigaProd.pezziNonConfermati;
|
||||
qtyScarto = statoProd.Pz2RecScarto;
|
||||
// calcolo nuovi pezzi da confermare
|
||||
if (qtyFromLast)
|
||||
{
|
||||
roundStep = roundStep == 0 ? 1 : roundStep;
|
||||
double ratio = (double)qtyConf / roundStep;
|
||||
qtyNew = (int)Math.Round(Math.Ceiling(ratio) * roundStep, 0);
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"AutoStartOdlAsync | Errore recupero pezzi da confermare | idxMacchina {idxMacchina}{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
|
||||
// chiamo metodo redis/db...
|
||||
try
|
||||
{
|
||||
// recupero ODL corrente
|
||||
var currData = await IocDbController.OdlCurrByMaccAsync(idxMacchina);
|
||||
if (currData != null && currData.IdxOdl > 0)
|
||||
{
|
||||
// preparo var x master/slave
|
||||
bool isMachMaster = await IobIsMasterAsync(idxMacchina);
|
||||
List<Macchine2SlaveModel> slaveList = new();
|
||||
if (isMachMaster)
|
||||
{
|
||||
List<Macchine2SlaveModel> allSlaveList = await IocDbController.Macchine2SlaveAsync();
|
||||
slaveList = allSlaveList.Where(x => x.IdxMacchina == idxMacchina).ToList();
|
||||
}
|
||||
|
||||
// registro un evento di inizio attrezzaggio (idxTipoEv = 2)
|
||||
int idxEvento = 2;
|
||||
Log.Info($"Invio evento ODL-SPLIT per macchina {idxMacchina} | ev: {idxEvento} | art: {currData.CodArticolo} | qty conf: {qtyConf} | sty sca: {qtyScarto} | new qty: {qtyNew}");
|
||||
|
||||
// creo evento
|
||||
EventListModel newRecEv = new EventListModel()
|
||||
{
|
||||
CodArticolo = currData.CodArticolo,
|
||||
IdxMacchina = idxMacchina,
|
||||
IdxTipo = idxEvento,
|
||||
InizioStato = adesso,
|
||||
MatrOpr = matrOpr,
|
||||
pallet = "",
|
||||
Value = "ODL-SPLIT"
|
||||
};
|
||||
inputComandoMapo resCmd = await scriviRigaEventoBarcodeAsync(newRecEv);
|
||||
|
||||
// era 100, messo 50...
|
||||
int wTime = 50;
|
||||
|
||||
// eventuale conferma produzione
|
||||
if (doConfirm)
|
||||
{
|
||||
await Task.Delay(wTime);
|
||||
adesso = DateTime.Now;
|
||||
// chiamo conferma produzione...
|
||||
try
|
||||
{
|
||||
string chiamata = confRett ? "confermaProdMacchinaFull" : "confermaProdMacchina";
|
||||
Log.Info($"Chiamata a {chiamata} con parametri {currData.IdxMacchina} |{matrOpr} | {DateTime.Now.AddDays(-10)} | {DateTime.Now} | {qtyConf} | 0 | {qtyScarto} | {DateTime.Now} | false");
|
||||
string idxMacchinaSel = currData.IdxMacchina;
|
||||
bool fatto = false;
|
||||
if (confRett)
|
||||
{
|
||||
// confermo al netto dei pezzi lasciati...
|
||||
fatto = await IocDbController.ConfermaProdMacchinaFullAsync(idxMacchinaSel, modoConfProd, qtyConf, 0, qtyScarto, adesso, matrOpr);
|
||||
if (slaveConfirmPzProd)
|
||||
{
|
||||
foreach (var machine in slaveList)
|
||||
{
|
||||
await IocDbController.ConfermaProdMacchinaFullAsync(machine.IdxMacchinaSlave, modoConfProd, qtyConf, 0, qtyScarto, adesso, matrOpr);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fatto = await IocDbController.ConfermaProdMacchinaAsync(idxMacchinaSel, modoConfProd, qtyConf, qtyScarto, adesso, matrOpr);
|
||||
if (slaveConfirmPzProd)
|
||||
{
|
||||
foreach (var machine in slaveList)
|
||||
{
|
||||
await IocDbController.ConfermaProdMacchinaAsync(idxMacchinaSel, modoConfProd, qtyConf, qtyScarto, adesso, matrOpr);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!fatto)
|
||||
{
|
||||
Log.Error($"ERRORE in chiamata {chiamata}");
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione in ConfermaProduzione{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
// 2025.02.19 portato da 100 a 1000 ms attesa x evitare che ODL sia avviato PRIMA della conferma
|
||||
// attendo 1000 msec x chiudere ODL
|
||||
await Task.Delay(1000);
|
||||
// chiamo splitOdl
|
||||
await IocDbController.AutoStartOdlAsync(currData.IdxOdl, 0, idxMacchina, currData.TCRichAttr, currData.PzPallet, $"Nuovo ODL da forceSplitOdl.autoStart", true, qtyNew, keyRichiesta);
|
||||
|
||||
// elimino eventuale ODL precedente...
|
||||
string currKey = $"{Utils.redisOdlCurrByMac}:{idxMacchina}";
|
||||
await redisDb.KeyDeleteAsync(currKey);
|
||||
|
||||
// ricalcola ODL macchina
|
||||
var newOdl = await GetCurrOdlAsync(idxMacchina);
|
||||
// attendo 1000 msec
|
||||
await Task.Delay(1000);
|
||||
|
||||
adesso = DateTime.Now;
|
||||
// registro fine ODL (idxTipoEv = 1)
|
||||
idxEvento = 1;
|
||||
Log.Info($"Invio evento FINE ODL-SPLIT | idx: {idxMacchina} | ev: {idxEvento} | art: {currData.CodArticolo}");
|
||||
// costruisco nuovo evento
|
||||
newRecEv = new EventListModel()
|
||||
{
|
||||
CodArticolo = currData.CodArticolo,
|
||||
IdxMacchina = idxMacchina,
|
||||
IdxTipo = idxEvento,
|
||||
InizioStato = adesso,
|
||||
MatrOpr = matrOpr,
|
||||
pallet = "",
|
||||
Value = "ODL-START"
|
||||
};
|
||||
resCmd = await scriviRigaEventoBarcodeAsync(newRecEv);
|
||||
// invio eventi setup a macchina....
|
||||
string setArtVal = $"{currData.CodArticolo}";
|
||||
string setPzCommVal = $"{qtyNew}";
|
||||
string setCommVal = $"ODL{newOdl}";
|
||||
if (!string.IsNullOrEmpty(keyRichiesta))
|
||||
{
|
||||
setCommVal = $"{keyRichiesta} ODL{newOdl}";
|
||||
}
|
||||
try
|
||||
{
|
||||
// invio task caricamento dati ODL
|
||||
Dictionary<taskType, string> updDict = new Dictionary<taskType, string>();
|
||||
updDict.Add(taskType.setArt, setArtVal);
|
||||
updDict.Add(taskType.setComm, setCommVal);
|
||||
updDict.Add(taskType.setPzComm, setPzCommVal);
|
||||
#if false
|
||||
addTask4Machine(idxMacchina, taskType.setArt, setArtVal);
|
||||
addTask4Machine(idxMacchina, taskType.setComm, setCommVal);
|
||||
addTask4Machine(idxMacchina, taskType.setPzComm, setPzCommVal);
|
||||
|
||||
updateMachineParameter(idxMacchina, "setArt", setArtVal);
|
||||
updateMachineParameter(idxMacchina, "setComm", setCommVal);
|
||||
updateMachineParameter(idxMacchina, "setPzComm", setPzCommVal);
|
||||
#endif
|
||||
// recupero set attuale parametri
|
||||
var currMachPar = await MachineParamListAsync(idxMacchina);
|
||||
List<ObjItemDTO> list2upd = new();
|
||||
// aggiorno i valori interessati tra quelli nel dizionario
|
||||
foreach (var item in updDict)
|
||||
{
|
||||
var cRec = currMachPar.FirstOrDefault(x => x.uid == $"{item.Key}");
|
||||
if (cRec != null)
|
||||
{
|
||||
list2upd.Add(cRec);
|
||||
}
|
||||
}
|
||||
// aggiungo task di setParameters x la commessa...
|
||||
updDict.Add(taskType.setParameter, setCommVal);
|
||||
// salvo
|
||||
await AddTask4MacListAsync(idxMacchina, updDict);
|
||||
await MachineParamUpsertAsync(idxMacchina, list2upd);
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
// chiamo refresh MSE
|
||||
await IocDbController.RecalcMseAsync(idxMacchina, 0);
|
||||
// resetto stato macchina...
|
||||
var kStatoMacc = $"{Utils.redisStatoMacch}:{idxMacchina}";
|
||||
await redisDb.KeyDeleteAsync(kStatoMacc);
|
||||
answ = "OK";
|
||||
Log.Info($"Effettuato reset e ricalcoli x split ODL per macchina {idxMacchina}");
|
||||
// se è una master richiamo fix x child...
|
||||
if (isMachMaster)
|
||||
{
|
||||
Dictionary<taskType, string> updDict = new Dictionary<taskType, string>();
|
||||
string ts = "";
|
||||
string outData = "";
|
||||
await IocDbController.OdlFixMachineSlaveAsync(idxMacchina, 30, 1);
|
||||
foreach (var machine in slaveList)
|
||||
{
|
||||
// invio chiusura attrezzaggio
|
||||
ts = string.Format("{0:yyMMdd}T{0:HHmmss.fff}Z", DateTime.Now);
|
||||
outData = $"TS:{ts}|MATR:{matrOpr}|ODL:{newOdl}";
|
||||
|
||||
updDict.Clear();
|
||||
updDict.Add(taskType.setArt, setArtVal);
|
||||
updDict.Add(taskType.setComm, setCommVal);
|
||||
updDict.Add(taskType.setPzComm, setPzCommVal);
|
||||
|
||||
|
||||
#if false
|
||||
addTask4Machine(machine.IdxMacchinaSlave, taskType.fixStopSetup, outData);
|
||||
addTask4Machine(machine.IdxMacchinaSlave, taskType.forceResetPzCount, outData);
|
||||
// invio task caricamento dati ODL
|
||||
addTask4Machine(machine.IdxMacchinaSlave, taskType.setArt, setArtVal);
|
||||
addTask4Machine(machine.IdxMacchinaSlave, taskType.setComm, setCommVal);
|
||||
addTask4Machine(machine.IdxMacchinaSlave, taskType.setPzComm, setPzCommVal);
|
||||
|
||||
updateMachineParameter(machine.IdxMacchinaSlave, "setArt", setArtVal);
|
||||
updateMachineParameter(machine.IdxMacchinaSlave, "setComm", setCommVal);
|
||||
updateMachineParameter(machine.IdxMacchinaSlave, "setPzComm", setPzCommVal);
|
||||
#endif
|
||||
|
||||
// recupero set attuale parametri
|
||||
var currMachPar = await MachineParamListAsync(machine.IdxMacchinaSlave);
|
||||
List<ObjItemDTO> list2upd = new();
|
||||
// aggiorno i valori interessati tra quelli nel dizionario
|
||||
foreach (var item in updDict)
|
||||
{
|
||||
var cRec = currMachPar.FirstOrDefault(x => x.uid == $"{item.Key}");
|
||||
if (cRec != null)
|
||||
{
|
||||
list2upd.Add(cRec);
|
||||
}
|
||||
}
|
||||
// aggiungo task di setParameters x la commessa...
|
||||
updDict.Add(taskType.fixStopSetup, outData);
|
||||
updDict.Add(taskType.forceResetPzCount, outData);
|
||||
updDict.Add(taskType.setParameter, setCommVal);
|
||||
// salvo
|
||||
await AddTask4MacListAsync(machine.IdxMacchinaSlave, updDict);
|
||||
await MachineParamUpsertAsync(machine.IdxMacchinaSlave, list2upd);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione in forceSplitOdl{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
|
||||
public string CalcRecipe(RecipeModel currRecipe)
|
||||
{
|
||||
return mongoController.CalcRecipe(currRecipe);
|
||||
@@ -571,7 +937,7 @@ namespace MP.IOC.Data
|
||||
inputComandoMapo answ = new inputComandoMapo();
|
||||
|
||||
// verifico se esista la macchina altrimenti la creo... REDIS compliant
|
||||
verificaIdxMacchina(idxMacchina);
|
||||
await verificaIdxMacchinaAsync(idxMacchina);
|
||||
|
||||
// continuo processing...
|
||||
string CodArticolo = datiMacc["CodArticolo"];
|
||||
@@ -654,7 +1020,7 @@ namespace MP.IOC.Data
|
||||
answ = await scriviRigaEventoAsync(newRecEv);
|
||||
//currTask = scriviRigaEvento(idxMacchina, idxTipoEv, codArticolo, valEsteso, 0, "-", dtEve, DateTime.Now);
|
||||
// forzo RESET dati macchina...
|
||||
ResetDatiMacchina(idxMacchina);
|
||||
await ResetDatiMacchinaAsync(idxMacchina);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
@@ -811,39 +1177,6 @@ namespace MP.IOC.Data
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<List<PODLExpModel>> POdlGetByMaccArtAsync(string idxMacchina, string codArticolo, string codGruppo, bool onlyFree)
|
||||
{
|
||||
List<PODLExpModel> result = new List<PODLExpModel>();
|
||||
|
||||
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<List<PODLExpModel>>($"{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<PODLExpModel>();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Eliminazione di un dossier
|
||||
/// </summary>
|
||||
@@ -1349,19 +1682,8 @@ namespace MP.IOC.Data
|
||||
/// <returns></returns>
|
||||
public async Task<Dictionary<string, string>> GetTask2ExeMacchinaAsync(string idxMacchina)
|
||||
{
|
||||
// hard coded dimensione vettore DatiMacchine
|
||||
Dictionary<string, string> answ = new Dictionary<string, string>();
|
||||
// ORA recupero da memoria redis...
|
||||
try
|
||||
{
|
||||
var currHash = Utils.RedKeyTask2ExeMacc(idxMacchina, MpIoNS);
|
||||
answ = await RedisGetHashDictAsync(currHash);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Info(string.Format("Errore in GetTask2ExeMacchinaAsync | idxMacchina {2}:{0}{1}", Environment.NewLine, exc, idxMacchina));
|
||||
}
|
||||
return answ;
|
||||
var currHash = Utils.RedKeyTask2ExeMacc(idxMacchina, MpIoNS);
|
||||
return await RedisGetHashDictAsync(currHash);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1412,6 +1734,31 @@ namespace MP.IOC.Data
|
||||
return val != null && (val == "1" || val.ToLower() == "true");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restituisce il valore booleano se la macchina sia master
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> IobIsMasterAsync(string idxMacchina)
|
||||
{
|
||||
var key = Utils.RedKeyDatiMacc(idxMacchina, MpIoNS);
|
||||
|
||||
// 1. Tentativo ottimizzato: leggiamo solo il campo che ci serve
|
||||
// Supponendo che tu usi StackExchange.Redis direttamente o un wrapper
|
||||
string? val = await redisDb.HashGetAsync(key, "Master");
|
||||
|
||||
// 2. Se non c'è in cache, carichiamo/resettiamo tutto
|
||||
if (val == null)
|
||||
{
|
||||
//var data = ResetDatiMacchina(idxMacchina);
|
||||
var data = await ResetDatiMacchinaAsync(idxMacchina);
|
||||
data.TryGetValue("Master", out val);
|
||||
}
|
||||
|
||||
// 3. Parsing sicuro
|
||||
return val != null && (val == "1" || val.ToLower() == "true");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="IdxOdl">idxMacc odl da cercare</param>
|
||||
@@ -1447,6 +1794,32 @@ namespace MP.IOC.Data
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<List<ListValuesModel>> ListValuesFilt(string tabName, string fieldName)
|
||||
{
|
||||
List<ListValuesModel> resultList = new List<ListValuesModel>();
|
||||
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<List<ListValuesModel>>($"{rawData}") ?? new();
|
||||
}
|
||||
else
|
||||
{
|
||||
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();
|
||||
}
|
||||
return resultList;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco completo valori Macchine 2 Slave
|
||||
/// </summary>
|
||||
@@ -2049,10 +2422,24 @@ namespace MP.IOC.Data
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Info(string.Format("Errore in mTaskMacchina | idxMacchina {2}:{0}{1}", Environment.NewLine, exc, idxMacchina));
|
||||
Log.Error(string.Format("Errore in mTaskMacchina | idxMacchina {2}:{0}{1}", Environment.NewLine, exc, idxMacchina));
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
/// <summary>
|
||||
/// Restitusice elenco KVP dei TASK (da passare a IOB-WIN) per l'impianto indicato
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<Dictionary<string, string>> mTaskMacchinaAsync(string idxMacchina)
|
||||
{
|
||||
// hard coded dimensione vettore DatiMacchine
|
||||
Dictionary<string, string> answ = new Dictionary<string, string>();
|
||||
// ORA recupero da memoria redis...
|
||||
var currHash = Utils.RedKeyTask2ExeMacc(idxMacchina, MpIoNS);
|
||||
answ = await RedisGetHashDictAsync(currHash);
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generazione autoOdl
|
||||
@@ -2431,6 +2818,39 @@ namespace MP.IOC.Data
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<List<PODLExpModel>> POdlGetByMaccArtAsync(string idxMacchina, string codArticolo, string codGruppo, bool onlyFree)
|
||||
{
|
||||
List<PODLExpModel> result = new List<PODLExpModel>();
|
||||
|
||||
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<List<PODLExpModel>>($"{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<PODLExpModel>();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recupero PODL da IdxODL
|
||||
/// </summary>
|
||||
@@ -2599,7 +3019,7 @@ namespace MP.IOC.Data
|
||||
// 2018.10.26 controllo dtEve e dtCurr
|
||||
if (dtEve == null || dtCurr == null)
|
||||
{
|
||||
Log.Info(string.Format("procInput: valori nulli date: idxMacchina: {0} | valore: {1} | dtEve: {2} | dtCurr:{3}", idxMacchina, valore, dtEve, dtCurr));
|
||||
Log.Warn(string.Format("procInput: valori nulli date: idxMacchina: {0} | valore: {1} | dtEve: {2} | dtCurr:{3}", idxMacchina, valore, dtEve, dtCurr));
|
||||
}
|
||||
else if (dtEve.Length < 17 || dtCurr.Length < 17)
|
||||
{
|
||||
@@ -2663,7 +3083,7 @@ namespace MP.IOC.Data
|
||||
// se ho deltaClass loggo
|
||||
if (deltaClass != "")
|
||||
{
|
||||
Log.Info("Correzione " + deltaClass);
|
||||
Log.Debug("Correzione " + deltaClass);
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
@@ -2677,7 +3097,7 @@ namespace MP.IOC.Data
|
||||
if (idxMacchina != "" && valore != "")
|
||||
{
|
||||
// se abilitato registro evento sul DB
|
||||
if (idxMacchina != "" && sLogEnab(idxMacchina))
|
||||
if (!string.IsNullOrEmpty(idxMacchina) && await sLogEnabAsync(idxMacchina))
|
||||
{
|
||||
int cntVal = 0;
|
||||
int.TryParse(contatore, out cntVal);
|
||||
@@ -3129,17 +3549,7 @@ namespace MP.IOC.Data
|
||||
|
||||
public async Task<bool> RedisKeyPresentAsync(RedisKey key)
|
||||
{
|
||||
bool result = false;
|
||||
try
|
||||
{
|
||||
result = await redisDb.KeyExistsAsync(key);
|
||||
}
|
||||
catch (Exception arg)
|
||||
{
|
||||
Log.Error($"Errore in redKeyPresent per la currKey {key}:{Environment.NewLine}{arg}");
|
||||
}
|
||||
|
||||
return result;
|
||||
return await redisDb.KeyExistsAsync(key);
|
||||
}
|
||||
|
||||
public bool RedisKeyPresentSz(string key)
|
||||
@@ -3698,29 +4108,16 @@ namespace MP.IOC.Data
|
||||
{
|
||||
string nomeVar = string.Format("KeepAlive:{0}", IdxMacchina);
|
||||
// cerco se ho keep alive in redis,
|
||||
bool keyPresent = false;
|
||||
DateTime adesso = DateTime.Now;
|
||||
var currKey = Utils.RedKeyHash(nomeVar);
|
||||
try
|
||||
{
|
||||
keyPresent = await RedisKeyPresentAsync(currKey);
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
bool keyPresent = await RedisKeyPresentAsync(currKey);
|
||||
// se NON presente salvo in REDIS con TTL 10 sec e sul DB...
|
||||
if (!keyPresent)
|
||||
{
|
||||
await redisDb.StringSetAsync(currKey, adesso.ToString("s"), TimeSpan.FromSeconds(10));
|
||||
try
|
||||
{
|
||||
Log.Trace($"Scrittura keep alive! IdxMacchina: {IdxMacchina}");
|
||||
// effettuo scrittura sul DB
|
||||
await IocDbController.KeepAliveUpsertAsync(IdxMacchina, DateTime.Now, oraMacchina);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Errore in scrittura keep alive!{Environment.NewLine}oraMacchina: {oraMacchina} - IdxMacchina: {IdxMacchina}{Environment.NewLine}{exc}");
|
||||
}
|
||||
await redisDb.StringSetAsync(currKey, adesso.ToString("s"), TimeSpan.FromSeconds(20));
|
||||
Log.Trace($"Scrittura keep alive! IdxMacchina: {IdxMacchina}");
|
||||
// effettuo scrittura sul DB
|
||||
await IocDbController.KeepAliveUpsertAsync(IdxMacchina, DateTime.Now, oraMacchina);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3757,6 +4154,38 @@ namespace MP.IOC.Data
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restituisce il valore booleano se la macchina sia abilitata all'inserimento COMPLETO nel
|
||||
/// Signal Log
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> sLogEnabAsync(string idxMacchina)
|
||||
{
|
||||
bool answ = false;
|
||||
// ORA recupero da memoria redis...
|
||||
try
|
||||
{
|
||||
var currHash = Utils.RedKeyDatiMacc(idxMacchina, MpIoNS);
|
||||
RedisValue rawData = await redisDb.HashGetAsync(currHash, (RedisValue)"sLogEnabled");
|
||||
// se è vuoto... leggo da DB e popolo!
|
||||
if (!rawData.HasValue)
|
||||
{
|
||||
await ResetDatiMacchinaAsync(idxMacchina);
|
||||
// riprovo
|
||||
rawData = await redisDb.HashGetAsync(currHash, (RedisValue)"sLogEnabled");
|
||||
}
|
||||
|
||||
// provo conversione
|
||||
bool.TryParse($"{rawData}", out answ);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Errore sLogEnabAsync | idxMacchina {idxMacchina}:{Environment.NewLine}{exc}");
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restitusice elenco KVP dei campi della State Machine ingressi nel formato
|
||||
/// currKey: cState_nVal (current MICRO-STATE + "_" + new Value)
|
||||
@@ -4171,32 +4600,6 @@ namespace MP.IOC.Data
|
||||
return resultList;
|
||||
}
|
||||
|
||||
public async Task<List<ListValuesModel>> ListValuesFilt(string tabName, string fieldName)
|
||||
{
|
||||
List<ListValuesModel> resultList = new List<ListValuesModel>();
|
||||
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<List<ListValuesModel>>($"{rawData}") ?? new();
|
||||
}
|
||||
else
|
||||
{
|
||||
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();
|
||||
}
|
||||
return resultList;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Svuota la cache redis x l'elenco delle righe di confFlux x una macchina (se presenti)
|
||||
/// </summary>
|
||||
@@ -4618,6 +5021,32 @@ namespace MP.IOC.Data
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scrive una riga di evento manuale (barcode) nel db + check cambio stato DiarioDiBordo
|
||||
/// </summary>
|
||||
/// <param name="newRec">codice macchina</param>
|
||||
/// <returns></returns>
|
||||
private async Task<inputComandoMapo> scriviRigaEventoBarcodeAsync(EventListModel newRec)
|
||||
{
|
||||
bool inserito = false;
|
||||
try
|
||||
{
|
||||
// inserisco evento
|
||||
inserito = await IocDbController.EvListInsertAsync(newRec);
|
||||
// faccio controllo per eventuale cambio stato da tab transizioni...
|
||||
checkCambiaStatoBatch(tipoInputEvento.barcode, newRec.IdxMacchina, newRec.InizioStato ?? DateTime.Now, newRec.IdxTipo, newRec.CodArticolo, newRec.Value, newRec.MatrOpr, newRec.pallet);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Errore in scriviRigaEvento | IdxMacchina {newRec.IdxMacchina} | IdxTipo {newRec.IdxTipo} | codArticolo {newRec.CodArticolo} | Value {newRec.Value} | MatrOpr {newRec.MatrOpr} | Pallet {newRec.pallet} | dTime {newRec.InizioStato}{Environment.NewLine}{exc}");
|
||||
}
|
||||
// formatto output
|
||||
inputComandoMapo answ = new inputComandoMapo();
|
||||
answ.outValue = inserito.ToString();
|
||||
answ.needStatusRefresh = true;
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restituisce il valore booleano se la macchina sia abilitata all'inserimento COMPLETO nel
|
||||
/// Signal Log
|
||||
@@ -4719,7 +5148,6 @@ namespace MP.IOC.Data
|
||||
{
|
||||
answ = currRec.Valore;
|
||||
}
|
||||
|
||||
return answ;
|
||||
}
|
||||
|
||||
@@ -4889,6 +5317,60 @@ namespace MP.IOC.Data
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// cerca codice in anagrafica macchine ed eventualmente inserisce nuova macchina
|
||||
/// </summary>
|
||||
/// <param name="IdxMacchina"></param>
|
||||
private async Task verificaIdxMacchinaAsync(string IdxMacchina)
|
||||
{
|
||||
bool needDB = false;
|
||||
try
|
||||
{
|
||||
// esecuzione in REDIS...cerco status macchina...
|
||||
if ((await mDatiMacchineAsync(IdxMacchina)).Count == 0)
|
||||
{
|
||||
needDB = true;
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
|
||||
if (needDB)
|
||||
{
|
||||
// verifico se esiste su DB
|
||||
var dbRec = await IocDbController.MacchineGetByIdxAsync(IdxMacchina);
|
||||
if (dbRec == null)
|
||||
{
|
||||
MacchineModel newRec = new MacchineModel()
|
||||
{
|
||||
IdxMacchina = IdxMacchina,
|
||||
CodMacchina = "0000",
|
||||
Nome = IdxMacchina,
|
||||
Descrizione = "Macchina non codificata",
|
||||
Note = "-",
|
||||
locazione = "",
|
||||
RecipeArchivePath = "",
|
||||
RecipePath = ""
|
||||
};
|
||||
await IocDbController.MacchineUpsertAsync(newRec);
|
||||
|
||||
// verifico ci sia un microstato macchina...
|
||||
var recMSM = await IocDbController.MicroStatoMacchinaGetByIdxMaccAsync(IdxMacchina);
|
||||
if (recMSM.Count == 0)
|
||||
{
|
||||
// inserisco nuovo stato...
|
||||
MicroStatoMacchinaModel msRec = new MicroStatoMacchinaModel()
|
||||
{
|
||||
IdxMacchina = IdxMacchina,
|
||||
IdxMicroStato = 0,
|
||||
InizioStato = DateTime.Now,
|
||||
Value = "00"
|
||||
};
|
||||
await IocDbController.MicroStatoMacchinaUpsertAsync(msRec);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Private Methods
|
||||
|
||||
#if false
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Version>6.16.2604.1618</Version>
|
||||
<Version>6.16.2604.1709</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<body>
|
||||
<i>Modulo MP-IOC </i>
|
||||
<h4>Versione: 6.16.2604.1618</h4>
|
||||
<h4>Versione: 6.16.2604.1709</h4>
|
||||
<br /> Note di rilascio:
|
||||
<ul>
|
||||
<li>
|
||||
|
||||
@@ -1 +1 @@
|
||||
6.16.2604.1618
|
||||
6.16.2604.1709
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<item>
|
||||
<version>6.16.2604.1618</version>
|
||||
<version>6.16.2604.1709</version>
|
||||
<url>https://nexus.steamware.net/repository/SWS/MP-IOC/stable/LAST/MP.IOC.zip</url>
|
||||
<changelog>https://nexus.steamware.net/repository/SWS/MP-IOC/stable/LAST/ChangeLog.html</changelog>
|
||||
<mandatory>false</mandatory>
|
||||
|
||||
@@ -15,10 +15,10 @@
|
||||
],
|
||||
"Clusters": {
|
||||
"cluster-old": {
|
||||
"Destinations": { "old1": { "Address": "https://iis01.egalware.com/MP/IO/IOB/" } }
|
||||
"Destinations": { "old1": { "Address": "https://maposrv.egalware.com/MP/IO/IOB/" } }
|
||||
},
|
||||
"cluster-new": {
|
||||
"Destinations": { "new1": { "Address": "https://iis01.egalware.com/MP/IOC/api/IOB/" } }
|
||||
"Destinations": { "new1": { "Address": "https://maposrv.egalware.com/MP/IOC/api/IOB/" } }
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user