Aggiunta metodo update objItems
This commit is contained in:
+17
-5
@@ -150,9 +150,9 @@ namespace MP.Core
|
||||
/// </summary>
|
||||
/// <param name="idxFamIn"></param>
|
||||
/// <returns></returns>
|
||||
public static RedisKey hSMI(int idxFamIn)
|
||||
public static RedisKey GetHashSMI(int idxFamIn)
|
||||
{
|
||||
return (RedisKey)$"{redisBaseAddr}hSMI:{idxFamIn}";
|
||||
return (RedisKey)$"{redisBaseAddr}GetHashSMI:{idxFamIn}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -174,7 +174,7 @@ namespace MP.Core
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <param name="baseAddr">Chiave override per i valori in caso di dati che accedono al dominio dati di un altra app (es: baseAddr x IO legacy)</param>
|
||||
/// <returns></returns>
|
||||
public static RedisKey msmiHash(string idxMacchina, string baseAddr = null)
|
||||
public static RedisKey RedKeyMsmi(string idxMacchina, string baseAddr = null)
|
||||
{
|
||||
var prefix = (baseAddr ?? redisBaseAddr).TrimEnd(':');
|
||||
return (RedisKey)$"{prefix}:hMSMI:{idxMacchina}";
|
||||
@@ -206,7 +206,7 @@ namespace MP.Core
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <param name="baseAddr">Chiave override per i valori in caso di dati che accedono al dominio dati di un altra app (es: baseAddr x IO legacy)</param>
|
||||
/// <returns></returns>
|
||||
public static RedisKey redisPzCount(string idxMacchina, string baseAddr = null)
|
||||
public static RedisKey RedKeyPzCount(string idxMacchina, string baseAddr = null)
|
||||
{
|
||||
var prefix = (baseAddr ?? redisBaseAddr).TrimEnd(':');
|
||||
return (RedisKey)$"{prefix}:Cache:PzCount:{idxMacchina}";
|
||||
@@ -234,12 +234,24 @@ namespace MP.Core
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <param name="baseAddr">Chiave override per i valori in caso di dati che accedono al dominio dati di un altra app (es: baseAddr x IO legacy)</param>
|
||||
/// <returns></returns>
|
||||
public static RedisKey taskMaccHash(string idxMacchina, string baseAddr = null)
|
||||
public static RedisKey RedKeyTask2ExeMacc(string idxMacchina, string baseAddr = null)
|
||||
{
|
||||
var prefix = (baseAddr ?? redisBaseAddr).TrimEnd(':');
|
||||
return (RedisKey)$"{prefix}:ExeTask:{idxMacchina}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Chiave x CurrObjItems macchina
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <param name="baseAddr">Chiave override per i valori in caso di dati che accedono al dominio dati di un altra app (es: baseAddr x IO legacy)</param>
|
||||
/// <returns></returns>
|
||||
public static RedisKey RedKeyCurrObjItems(string idxMacchina, string baseAddr = null)
|
||||
{
|
||||
var prefix = (baseAddr ?? redisBaseAddr).TrimEnd(':');
|
||||
return (RedisKey)$"{prefix}:CurrentParameters:{idxMacchina}";
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
@@ -121,7 +121,7 @@ namespace MP.IOC.Controllers
|
||||
answ = "";
|
||||
try
|
||||
{
|
||||
var fiHASH = Utils.hSMI(idxFamIn);
|
||||
var fiHASH = Utils.GetHashSMI(idxFamIn);
|
||||
string outVal = "";
|
||||
bool trovato = DService.RedisHashPresent(fiHASH);
|
||||
if (!trovato)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using MP.Core.DTO;
|
||||
using MP.IOC.Data;
|
||||
using Newtonsoft.Json;
|
||||
using NLog;
|
||||
@@ -121,6 +122,29 @@ namespace MP.IOC.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// GET elenco parametri correnti x IOB
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("getCurrObjItems/{id}")]
|
||||
public async Task<IActionResult> GetCurrObjItems(string id)
|
||||
{
|
||||
if (string.IsNullOrEmpty(id)) return BadRequest("Missing ID");
|
||||
|
||||
// Multi: gestione carattere "|" trasformato in "#"
|
||||
id = id.Replace("|", "#");
|
||||
|
||||
var rawData = await DService.MachineParamListAsync(id);
|
||||
List<ObjItemDTO> actValues = new List<ObjItemDTO>();
|
||||
// ordino!
|
||||
actValues = rawData
|
||||
.OrderBy(x => x.displOrdinal)
|
||||
.ThenBy(x => x.description)
|
||||
.ToList();
|
||||
return Ok(actValues);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recupera ODL corrente x macchina:
|
||||
/// GET: IOB/getCurrODL/SIMUL_03
|
||||
@@ -320,6 +344,43 @@ namespace MP.IOC.Controllers
|
||||
return Ok(answ);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Processa una chiamata POST per l'invio di una List Json di UNO O PIU' oggetti objItem
|
||||
/// POST: IOB/upsertObjItems/SIMUL_03
|
||||
/// </summary>
|
||||
/// <param name="id">ID dell'IOB</param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("upsertObjItems/{id}")]
|
||||
public async Task<IActionResult> UpsertObjItems(string id, [FromBody] List<ObjItemDTO> innovazioni)
|
||||
{
|
||||
if (string.IsNullOrEmpty(id)) return BadRequest("Missing ID");
|
||||
|
||||
// Multi: gestione carattere "|" trasformato in "#"
|
||||
id = id.Replace("|", "#");
|
||||
string answ = "NA";
|
||||
|
||||
try
|
||||
{
|
||||
// se != null --> salvo!
|
||||
if (innovazioni != null)
|
||||
{
|
||||
// salvo
|
||||
bool fatto = await DService.MachineParamUpsertAsync(id, innovazioni);
|
||||
answ = "OK";
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Errore in upsertObjItems{Environment.NewLine}{exc}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, "NO");
|
||||
}
|
||||
return Ok(answ);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifica versione corrente REST API
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("version")]
|
||||
public IActionResult Version()
|
||||
{
|
||||
|
||||
+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);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Version>6.16.2604.1316</Version>
|
||||
<Version>6.16.2604.1317</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<body>
|
||||
<i>Modulo MP-IOC </i>
|
||||
<h4>Versione: 6.16.2604.1316</h4>
|
||||
<h4>Versione: 6.16.2604.1317</h4>
|
||||
<br /> Note di rilascio:
|
||||
<ul>
|
||||
<li>
|
||||
|
||||
@@ -1 +1 @@
|
||||
6.16.2604.1316
|
||||
6.16.2604.1317
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<item>
|
||||
<version>6.16.2604.1316</version>
|
||||
<version>6.16.2604.1317</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>
|
||||
|
||||
Reference in New Issue
Block a user