Aggiunta metodo update objItems
This commit is contained in:
+166
-12
@@ -426,7 +426,7 @@ namespace MP.IOC.Data
|
||||
int valIOB = Convert.ToInt32(valINT);
|
||||
next_idxMS = idxMicroStato;
|
||||
// verifico esistenza tab SMI...
|
||||
var fiHASH = Utils.hSMI(idxFamIn);
|
||||
var fiHASH = Utils.GetHashSMI(idxFamIn);
|
||||
bool trovato = RedisHashPresent(fiHASH);
|
||||
if (!trovato)
|
||||
{
|
||||
@@ -992,7 +992,7 @@ namespace MP.IOC.Data
|
||||
// ORA recupero da memoria redis...
|
||||
try
|
||||
{
|
||||
var currHash = Utils.taskMaccHash(idxMacchina, MpIoNS);
|
||||
var currHash = Utils.RedKeyTask2ExeMacc(idxMacchina, MpIoNS);
|
||||
answ = await RedisGetHashDictAsync(currHash);
|
||||
}
|
||||
catch (Exception exc)
|
||||
@@ -1239,6 +1239,160 @@ namespace MP.IOC.Data
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Lista parametri correnti (ObjItemDTO) della macchina
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <returns></returns>
|
||||
public List<ObjItemDTO> MachineParamList(string idxMacchina)
|
||||
{
|
||||
// setup parametri costanti
|
||||
string source = "NA";
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
List<ObjItemDTO>? result = new List<ObjItemDTO>();
|
||||
// cerco in _redisConn...
|
||||
var currKey = Utils.RedKeyCurrObjItems(idxMacchina, MpIoNS);
|
||||
RedisValue rawData = redisDb.StringGet(currKey);
|
||||
if (rawData.HasValue && rawData.Length() > 2)
|
||||
{
|
||||
var rawVal = JsonConvert.DeserializeObject<List<ObjItemDTO>>($"{rawData}");
|
||||
// ordino!
|
||||
result = rawVal
|
||||
.OrderBy(x => x.displOrdinal)
|
||||
.ThenBy(x => x.description)
|
||||
.ToList();
|
||||
source = "REDIS";
|
||||
}
|
||||
if (result == null)
|
||||
{
|
||||
result = new List<ObjItemDTO>();
|
||||
source = "NONE";
|
||||
}
|
||||
sw.Stop();
|
||||
Log.Debug($"MachineParamList | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
/// Lista parametri correnti (ObjItemDTO) della macchina
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<ObjItemDTO>> MachineParamListAsync(string idxMacchina)
|
||||
{
|
||||
// setup parametri costanti
|
||||
string source = "NA";
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
List<ObjItemDTO>? result = new List<ObjItemDTO>();
|
||||
// cerco in _redisConn...
|
||||
var currKey = Utils.RedKeyCurrObjItems(idxMacchina, MpIoNS);
|
||||
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
||||
if (rawData.HasValue && rawData.Length() > 2)
|
||||
{
|
||||
var rawVal = JsonConvert.DeserializeObject<List<ObjItemDTO>>($"{rawData}");
|
||||
// ordino!
|
||||
result = rawVal
|
||||
.OrderBy(x => x.displOrdinal)
|
||||
.ThenBy(x => x.description)
|
||||
.ToList();
|
||||
source = "REDIS";
|
||||
}
|
||||
if (result == null)
|
||||
{
|
||||
result = new List<ObjItemDTO>();
|
||||
source = "NONE";
|
||||
}
|
||||
sw.Stop();
|
||||
Log.Debug($"MachineParamListAsync | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Effettua UPSERT elenco parametri correnti x IOB (se c'è UPDATE, se manca ADD)
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <param name="innovations"></param>
|
||||
/// <returns></returns>
|
||||
public bool MachineParamUpsert(string idxMacchina, List<ObjItemDTO> innovations)
|
||||
{
|
||||
bool answ = false;
|
||||
if (innovations != null)
|
||||
{
|
||||
Log.Info($"upsertCurrObjItems | idxMacchina: {idxMacchina} | {innovations.Count} innovations");
|
||||
// leggo i valori attuali...
|
||||
List<ObjItemDTO> actValues = MachineParamList(idxMacchina);
|
||||
// per ogni valore passatomi faccio insert o update rispetto elenco valori correnti
|
||||
// in REDIS
|
||||
foreach (var item in actValues)
|
||||
{
|
||||
// cerco nelle innovazioni SE CI SIA il valore...
|
||||
var trovato = innovations.Find(obj => obj.uid == item.uid);
|
||||
// se non trovato nelle innovazioni...
|
||||
if (trovato == null)
|
||||
{
|
||||
// lo ri-aggiungo x non perderlo
|
||||
innovations.Add(item);
|
||||
Log.Trace($"innovations | add | item.uid: {item.uid} | item.value: {item.value}");
|
||||
}
|
||||
// altrimenti aggiorno campo (non trasmesso) name e tengo il resto...
|
||||
else
|
||||
{
|
||||
trovato.name = item.name;
|
||||
Log.Info($"innovations | update | item.uid: {item.uid} | item.value: {item.value} --> {trovato.value} ");
|
||||
}
|
||||
}
|
||||
// serializzo e salvo
|
||||
string serVal = JsonConvert.SerializeObject(innovations);
|
||||
var currKey = Utils.RedKeyCurrObjItems(idxMacchina, MpIoNS);
|
||||
RedisValue rawData = redisDb.StringSet(currKey, serVal);
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Effettua UPSERT elenco parametri correnti x IOB (se c'è UPDATE, se manca ADD)
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <param name="innovations"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> MachineParamUpsertAsync(string idxMacchina, List<ObjItemDTO> innovations)
|
||||
{
|
||||
bool answ = false;
|
||||
if (innovations != null)
|
||||
{
|
||||
Log.Info($"upsertCurrObjItems | idxMacchina: {idxMacchina} | {innovations.Count} innovations");
|
||||
// leggo i valori attuali...
|
||||
List<ObjItemDTO> actValues = await MachineParamListAsync(idxMacchina);
|
||||
// per ogni valore passatomi faccio insert o update rispetto elenco valori correnti
|
||||
// in REDIS
|
||||
foreach (var item in actValues)
|
||||
{
|
||||
// cerco nelle innovazioni SE CI SIA il valore...
|
||||
var trovato = innovations.Find(obj => obj.uid == item.uid);
|
||||
// se non trovato nelle innovazioni...
|
||||
if (trovato == null)
|
||||
{
|
||||
// lo ri-aggiungo x non perderlo
|
||||
innovations.Add(item);
|
||||
Log.Trace($"innovations | add | item.uid: {item.uid} | item.value: {item.value}");
|
||||
}
|
||||
// altrimenti aggiorno campo (non trasmesso) name e tengo il resto...
|
||||
else
|
||||
{
|
||||
trovato.name = item.name;
|
||||
Log.Info($"innovations | update | item.uid: {item.uid} | item.value: {item.value} --> {trovato.value} ");
|
||||
}
|
||||
}
|
||||
// serializzo e salvo
|
||||
string serVal = JsonConvert.SerializeObject(innovations);
|
||||
var currKey = Utils.RedKeyCurrObjItems(idxMacchina, MpIoNS);
|
||||
RedisValue rawData = await redisDb.StringSetAsync(currKey, serVal);
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restituisce valore di una singola chiave del dizionario DatiMacchina
|
||||
/// </summary>
|
||||
@@ -1321,7 +1475,7 @@ namespace MP.IOC.Data
|
||||
// ORA recupero da memoria redis...
|
||||
try
|
||||
{
|
||||
var currHash = Utils.msmiHash(idxMacchina);
|
||||
var currHash = Utils.RedKeyMsmi(idxMacchina);
|
||||
answ = RedisGetHash(currHash);
|
||||
// se è vuoto... leggo da DB e popolo!
|
||||
if (answ.Length == 0)
|
||||
@@ -1348,7 +1502,7 @@ namespace MP.IOC.Data
|
||||
// ORA recupero da memoria redis...
|
||||
try
|
||||
{
|
||||
var currHash = Utils.taskMaccHash(idxMacchina, MpIoNS);
|
||||
var currHash = Utils.RedKeyTask2ExeMacc(idxMacchina, MpIoNS);
|
||||
answ = RedisGetHashDict(currHash);
|
||||
}
|
||||
catch (Exception exc)
|
||||
@@ -1963,7 +2117,7 @@ namespace MP.IOC.Data
|
||||
int answ = -1;
|
||||
try
|
||||
{
|
||||
var currKey = Utils.redisPzCount(idxMacchina, MpIoNS);
|
||||
var currKey = Utils.RedKeyPzCount(idxMacchina, MpIoNS);
|
||||
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
||||
if (rawData.HasValue)
|
||||
{
|
||||
@@ -2297,7 +2451,7 @@ namespace MP.IOC.Data
|
||||
/// <returns></returns>
|
||||
public KeyValuePair<string, string>[] resetMSMI(string idxMacchina)
|
||||
{
|
||||
var currHash = Utils.msmiHash(idxMacchina);
|
||||
var currHash = Utils.RedKeyMsmi(idxMacchina);
|
||||
//answ = RedisGetHash(currHash);
|
||||
// recupero records
|
||||
var tabMSMI = IocDbController.VMSFDGetMultiByMacc(idxMacchina);
|
||||
@@ -2456,7 +2610,7 @@ namespace MP.IOC.Data
|
||||
// se il conteggio è >= 0 SALVO come nuovo conteggio...
|
||||
if (newCounter >= 0)
|
||||
{
|
||||
var currKey = Utils.redisPzCount(idxMacchina, MpIoNS);
|
||||
var currKey = Utils.RedKeyPzCount(idxMacchina, MpIoNS);
|
||||
RedisValue rawData = redisDb.StringGet(currKey);
|
||||
if (!rawData.HasValue)
|
||||
{
|
||||
@@ -2508,7 +2662,7 @@ namespace MP.IOC.Data
|
||||
// se il conteggio è >= 0 SALVO come nuovo conteggio...
|
||||
if (newCounter >= 0)
|
||||
{
|
||||
var currKey = Utils.redisPzCount(idxMacchina, MpIoNS);
|
||||
var currKey = Utils.RedKeyPzCount(idxMacchina, MpIoNS);
|
||||
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
||||
if (!rawData.HasValue)
|
||||
{
|
||||
@@ -2614,7 +2768,7 @@ namespace MP.IOC.Data
|
||||
// ORA recupero da memoria redis...
|
||||
try
|
||||
{
|
||||
var currHash = Utils.hSMI(idxFamIn);
|
||||
var currHash = Utils.GetHashSMI(idxFamIn);
|
||||
answ = RedisGetHash(currHash);
|
||||
// se è vuoto... leggo da DB e popolo!
|
||||
if (answ.Length == 0)
|
||||
@@ -2737,7 +2891,7 @@ namespace MP.IOC.Data
|
||||
/// <returns></returns>
|
||||
public string ValoreSMI(int idxFamIn, int idxMicroStato, int valoreIn)
|
||||
{
|
||||
var currHash = Utils.hSMI(idxFamIn);
|
||||
var currHash = Utils.GetHashSMI(idxFamIn);
|
||||
string field = $"{idxMicroStato}_{valoreIn}";
|
||||
return RedisGetHashField(currHash, field);
|
||||
}
|
||||
@@ -3098,7 +3252,7 @@ namespace MP.IOC.Data
|
||||
/// <returns></returns>
|
||||
private KeyValuePair<string, string>[] resetSMI(int idxFamIn)
|
||||
{
|
||||
var currHash = Utils.hSMI(idxFamIn);
|
||||
var currHash = Utils.GetHashSMI(idxFamIn);
|
||||
// leggo da DB...
|
||||
var tabSMI = IocDbController.StateMachineIngressi(idxFamIn);
|
||||
|
||||
@@ -3270,7 +3424,7 @@ namespace MP.IOC.Data
|
||||
/// <returns></returns>
|
||||
private string valoreSMI(int idxFamIn, int idxMicroStato, int valoreIn)
|
||||
{
|
||||
var currHash = Utils.hSMI(idxFamIn);
|
||||
var currHash = Utils.GetHashSMI(idxFamIn);
|
||||
string field = string.Format("{0}_{1}", idxMicroStato, valoreIn);
|
||||
return RedisGetHashField(currHash, field);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user