Modifiche x metodo input (portato async)
This commit is contained in:
@@ -597,9 +597,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 +609,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 +678,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,21 +702,21 @@ 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;
|
||||
return await dbCtx.SaveChangesAsync() > 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,19 @@ namespace MP.IOC.Components.Compo
|
||||
public List<StatDataDTO> ParetoList { get; set; } = null!;
|
||||
|
||||
[Parameter]
|
||||
public string Title { get; set; } = null!;
|
||||
public string Title
|
||||
{
|
||||
get => _title;
|
||||
set
|
||||
{
|
||||
if (_title != value)
|
||||
{
|
||||
_title = value;
|
||||
currSelect = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
private string _title { get; set; } = null!;
|
||||
|
||||
#endregion Public Properties
|
||||
|
||||
|
||||
@@ -127,6 +127,7 @@ namespace MP.IOC.Components.Pages
|
||||
currTsId = $"TS_{reqKey}";
|
||||
currTitle = $"Pareto | {reqKey}";
|
||||
currData = ParetoDay[reqKey];
|
||||
tsDataDetail = new();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -840,7 +840,7 @@ namespace MP.IOC.Controllers
|
||||
if (string.IsNullOrEmpty(id)) return BadRequest("Missing ID");
|
||||
|
||||
string answ = "";
|
||||
if (cnt == null)
|
||||
if (string.IsNullOrEmpty(cnt))
|
||||
{
|
||||
cnt = "0";
|
||||
}
|
||||
|
||||
+150
-64
@@ -571,7 +571,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 +654,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 +811,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>
|
||||
@@ -1447,6 +1414,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>
|
||||
@@ -2431,6 +2424,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 +2625,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 +2689,7 @@ namespace MP.IOC.Data
|
||||
// se ho deltaClass loggo
|
||||
if (deltaClass != "")
|
||||
{
|
||||
Log.Info("Correzione " + deltaClass);
|
||||
Log.Debug("Correzione " + deltaClass);
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
@@ -2677,7 +2703,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);
|
||||
@@ -3757,6 +3783,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 +4229,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>
|
||||
@@ -4889,6 +4921,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
|
||||
|
||||
Reference in New Issue
Block a user