Update cachhe x salvataggio contapezzi + metodo x savePzIncr (da migrare)
This commit is contained in:
+28
-12
@@ -58,7 +58,6 @@ namespace MP.Core
|
||||
public const string redisPOdlByOdl = redisXdlData + "POdlByOdl";
|
||||
public const string redisPOdlByPOdl = redisXdlData + "POdlByPOdl";
|
||||
public const string redisPOdlList = redisXdlData + "POdlList";
|
||||
public const string redisPzCount = redisBaseAddr + "Cache:PzCount";
|
||||
public const string redisRecipeConf = redisBaseAddr + "Cache:Recipe:Conf";
|
||||
public const string redisStatoCom = redisBaseAddr + "Cache:StatoCom";
|
||||
public const string redisStatoMacch = redisBaseAddr + "Cache:StatoMacch";
|
||||
@@ -123,19 +122,12 @@ namespace MP.Core
|
||||
/// Hash dati STATUS x la macchina specificata
|
||||
/// </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 dtMaccHash(string idxMacchina)
|
||||
public static RedisKey dtMaccHash(string idxMacchina, string baseAddr = null)
|
||||
{
|
||||
return (RedisKey)$"{redisBaseAddr}DtMac:{idxMacchina}";
|
||||
}
|
||||
/// <summary>
|
||||
/// Hash dati Macchine Multi SM Ingressi
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina">Macchina PRINCIPALE</param>
|
||||
/// <returns></returns>
|
||||
public static RedisKey msmiHash(string idxMacchina)
|
||||
{
|
||||
return (RedisKey)$"{redisBaseAddr}hMSMI:{idxMacchina}";
|
||||
var prefix = (baseAddr ?? redisBaseAddr).TrimEnd(':');
|
||||
return (RedisKey)$"{prefix}:DtMac:{idxMacchina}";
|
||||
}
|
||||
|
||||
public static string FormDurata(double durataMinuti)
|
||||
@@ -176,6 +168,18 @@ namespace MP.Core
|
||||
return endRounded;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Hash dati Macchine Multi SM Ingressi
|
||||
/// </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 msmiHash(string idxMacchina, string baseAddr = null)
|
||||
{
|
||||
var prefix = (baseAddr ?? redisBaseAddr).TrimEnd(':');
|
||||
return (RedisKey)$"{prefix}:hMSMI:{idxMacchina}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Nome della variabile HASH da utilizzare (dato CodModulo / Server / DB impiegato
|
||||
/// dafunzionalita' DbConfig) + idxMacchina richiesto...
|
||||
@@ -196,6 +200,18 @@ namespace MP.Core
|
||||
return (RedisKey)$"MP:Data:{keyName}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Hash dati countapezzi 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 redisPzCount(string idxMacchina, string baseAddr = null)
|
||||
{
|
||||
var prefix = (baseAddr ?? redisBaseAddr).TrimEnd(':');
|
||||
return (RedisKey)$"{prefix}:Cache:PzCount:{idxMacchina}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Formato RedisKey delal chaive richeista (completa)
|
||||
/// </summary>
|
||||
|
||||
@@ -492,6 +492,37 @@ namespace MP.Data.Controllers
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco ODL data macchina e periodo
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <param name="dtStart"></param>
|
||||
/// <param name="dtEnd"></param>
|
||||
/// <returns></returns>
|
||||
public List<ODLExpModel> OdlListByMaccPeriodo(string idxMacchina, DateTime dtStart, DateTime dtEnd)
|
||||
{
|
||||
List<ODLExpModel> dbResult = new List<ODLExpModel>();
|
||||
using (var dbCtx = new MoonProContext(_configuration))
|
||||
{
|
||||
try
|
||||
{
|
||||
var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina);
|
||||
var DataFrom = new SqlParameter("@dataFrom", dtStart);
|
||||
var DataTo = new SqlParameter("@dataTo", dtEnd);
|
||||
dbResult = dbCtx
|
||||
.DbSetODLExp
|
||||
.FromSqlRaw("EXEC stp_ODL_getByMacchinaPeriodo @IdxMacchina, @dataFrom, @dataTo", IdxMacchina, DataFrom, DataTo)
|
||||
.AsNoTracking()
|
||||
.ToList();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante OdlListByMaccPeriodo{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stato prod macchina
|
||||
/// </summary>
|
||||
|
||||
@@ -221,13 +221,46 @@ namespace MP.IOC.Controllers
|
||||
try
|
||||
{
|
||||
answ = DService.processInput(id, valore, dtEve, dtCurr, cnt);
|
||||
return Ok(answ);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Errore in processInput{Environment.NewLine}{exc}");
|
||||
answ = "NO";
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, "NO");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SALVA in blocco un incremento pezzi x macchina restituendo il valore appena inviato o,
|
||||
/// se mancasse chaive redis, del valore da DB
|
||||
///
|
||||
/// GET: IOB/savePzCountInc/5?qty=10
|
||||
/// </summary>
|
||||
/// <param name="id">codice macchina</param>
|
||||
/// <param name="qty">num peziz da salvare in blocco</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("savePzCountInc/{id}")]
|
||||
public async Task<IActionResult> SavePzCountInc(string id, string qty)
|
||||
{
|
||||
if (string.IsNullOrEmpty(id)) return BadRequest("Missing ID");
|
||||
|
||||
// Multi: gestione carattere "|" trasformato in "#"
|
||||
id = id.Replace("|", "#");
|
||||
|
||||
string answ = "";
|
||||
DateTime dataOraEvento = DateTime.Now;
|
||||
// salvo SEMPRE log x questo tipo di dati!
|
||||
Log.Info($"Salvataggio incremento contapezzi | id: {id} | pezzi: {qty}");
|
||||
try
|
||||
{
|
||||
answ = await DService.saveCaricoPezzi(id, qty);
|
||||
return Ok(answ);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Errore in savePzCountInc{Environment.NewLine}{exc}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, "NO");
|
||||
}
|
||||
return Ok(answ);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -416,7 +416,7 @@ namespace MP.IOC.Data
|
||||
verificaIdxMacchina(idxMacchina);
|
||||
|
||||
// continuo processing...
|
||||
string CodArticolo = datiMacc["CodArticolo"];
|
||||
string CodArticolo = datiMacc["codArticolo"];
|
||||
if (string.IsNullOrEmpty(CodArticolo))
|
||||
{
|
||||
var allDatiMacch = IocDbController.DatiMacchineGetAll();
|
||||
@@ -494,7 +494,7 @@ namespace MP.IOC.Data
|
||||
};
|
||||
// salva e processa
|
||||
answ = scriviRigaEvento(newRecEv);
|
||||
//answ = scriviRigaEvento(idxMacchina, idxTipoEv, CodArticolo, valEsteso, 0, "-", dtEve, DateTime.Now);
|
||||
//answ = scriviRigaEvento(idxMacchina, idxTipoEv, codArticolo, valEsteso, 0, "-", dtEve, DateTime.Now);
|
||||
// forzo RESET dati macchina...
|
||||
ResetDatiMacchina(idxMacchina);
|
||||
}
|
||||
@@ -523,7 +523,7 @@ namespace MP.IOC.Data
|
||||
}
|
||||
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}");
|
||||
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();
|
||||
@@ -2079,7 +2079,7 @@ namespace MP.IOC.Data
|
||||
int answ = -1;
|
||||
try
|
||||
{
|
||||
string currKey = $"{Utils.redisPzCount}:{idxMacchina}";
|
||||
var currKey = Utils.redisPzCount(idxMacchina, MpIoNS);
|
||||
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
||||
if (rawData.HasValue)
|
||||
{
|
||||
@@ -2455,7 +2455,7 @@ namespace MP.IOC.Data
|
||||
// se il conteggio è >= 0 SALVO come nuovo conteggio...
|
||||
if (newCounter >= 0)
|
||||
{
|
||||
string currKey = $"{Utils.redisPzCount}:{idxMacchina}";
|
||||
var currKey = Utils.redisPzCount(idxMacchina, MpIoNS);
|
||||
RedisValue rawData = redisDb.StringGet(currKey);
|
||||
if (!rawData.HasValue)
|
||||
{
|
||||
@@ -2488,6 +2488,177 @@ namespace MP.IOC.Data
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Processa registrazione EVENTO CONTEGGIO PEZZI x una data macchina IOB
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina">Macchina</param>
|
||||
/// <param name="qty">Pezzi da registrare</param>
|
||||
/// <returns></returns>
|
||||
public async Task<string> saveCaricoPezzi(string idxMacchina, string qty)
|
||||
{
|
||||
// default: 0, non registrato x cautela...
|
||||
string answ = "0";
|
||||
// controllo per proseguire
|
||||
if (!string.IsNullOrEmpty(idxMacchina) && !string.IsNullOrEmpty(qty))
|
||||
{
|
||||
int numPzIncr = -1;
|
||||
int.TryParse(qty, out numPzIncr);
|
||||
// se il conteggio è >= 0 SALVO evento...
|
||||
if (numPzIncr >= 0)
|
||||
{
|
||||
// recupero info tra cui ODL corrente
|
||||
Dictionary<string, string> datiMacc = mDatiMacchine(idxMacchina);
|
||||
//var currData = await GetCurrOdlAsync(idxMacchina);
|
||||
// registro evento 120 --> contapezzi in blocco !!!HARD CODED!!! !!!FIXME!!!
|
||||
int idxEvento = 120;
|
||||
DateTime adesso = DateTime.Now;
|
||||
string codArticolo = "ND";
|
||||
if (datiMacc.ContainsKey("codArticolo"))
|
||||
{
|
||||
codArticolo = datiMacc["codArticolo"];
|
||||
}
|
||||
|
||||
// creo evento
|
||||
EventListModel newRecEv = new EventListModel()
|
||||
{
|
||||
CodArticolo = codArticolo,
|
||||
IdxMacchina = idxMacchina,
|
||||
IdxTipo = idxEvento,
|
||||
InizioStato = adesso,
|
||||
MatrOpr = 0,
|
||||
pallet = "-",
|
||||
Value = qty
|
||||
};
|
||||
// salva e processa
|
||||
var resp = scriviRigaEvento(newRecEv);
|
||||
// registro in risposta che è andato tutto bene... ovvero la qty richiesta...
|
||||
answ = qty;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string errore = $"Errore: mancano parametri macchina/incremento: idxMacchina {idxMacchina} | qty {qty}";
|
||||
Log.Error(errore);
|
||||
answ = errore;
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Effettua calcolo data-ora di riferimento per il server a partire da
|
||||
/// </summary>
|
||||
/// <param name="dtEve"></param>
|
||||
/// <param name="dtCurr"></param>
|
||||
/// <returns></returns>
|
||||
public DateTime GetSrvDtEvent(string dtEve, string dtCurr)
|
||||
{
|
||||
DateTime dataOraEvento = DateTime.Now;
|
||||
// 2017.09.14 trimmo eventualmente lo zero finale dalle date SE supera i millisecondi...
|
||||
dtEve = dtEve.Length > 17 ? dtEve.Substring(0, 17) : dtEve;
|
||||
dtCurr = dtCurr.Length > 17 ? dtCurr.Substring(0, 17) : dtCurr;
|
||||
DateTime dtEvento, dtCorrente;
|
||||
// controllo: se ho valori dt x evento e orario DIVERSI per acquisitore IOB calcolo
|
||||
// dataOraEvento corretto
|
||||
if (dtEve != dtCurr)
|
||||
{
|
||||
Int64 delta = 0;
|
||||
try
|
||||
{
|
||||
// se ho meno decimali x evento rispetto dtCorrente...
|
||||
if (dtEve.Length < dtCurr.Length)
|
||||
{
|
||||
dtEve = dtEve.PadRight(dtCurr.Length, '0');
|
||||
}
|
||||
delta = Convert.ToInt64(dtCurr) - Convert.ToInt64(dtEve);
|
||||
// se meno di 60'000 ms ...
|
||||
if (delta < 59999)
|
||||
{
|
||||
dataOraEvento = dataOraEvento.AddMilliseconds(-delta);
|
||||
}
|
||||
else
|
||||
{
|
||||
// in questo caso elimino i MS dalle stringhe e converto i datetime....
|
||||
CultureInfo provider = CultureInfo.InvariantCulture;
|
||||
string format = "yyyyMMddHHmmssfff";
|
||||
dtEvento = DateTime.ParseExact(dtEve, format, provider);
|
||||
dtCorrente = DateTime.ParseExact(dtCurr, format, provider);
|
||||
TimeSpan deltaTS = dtCorrente.Subtract(dtEvento);
|
||||
dataOraEvento = dataOraEvento.Add(-deltaTS);
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"getSrvDtEvent | Errore calcolo ora corrente da IOB remoto | dtEve: {dtEve} | dtCurr: {dtCurr}{Environment.NewLine}" +
|
||||
$"{exc}");
|
||||
}
|
||||
}
|
||||
|
||||
return dataOraEvento;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Processa registrazione EVENTO CONTEGGIO PEZZI x una data macchina IOB
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina">Macchina</param>
|
||||
/// <param name="qty">Pezzi da registrare</param>
|
||||
/// <param name="dtEve">DataOra evento</param>
|
||||
/// <param name="dtCurr">DataOra corrente</param>
|
||||
/// <returns></returns>
|
||||
public string saveCaricoPezzi(string idxMacchina, string qty, string dtEve = "", string dtCurr = "")
|
||||
{
|
||||
// default: 0, non registrato x cautela...
|
||||
string answ = "0";
|
||||
// Verifica se evento realtime oppure ho data specificata x processing @dtEve
|
||||
DateTime adesso = DateTime.Now;
|
||||
DateTime dtEvent = adesso;
|
||||
bool rtimeProc = string.IsNullOrEmpty(dtEve);
|
||||
if (!rtimeProc)
|
||||
{
|
||||
dtEvent = GetSrvDtEvent(dtEve, dtCurr);
|
||||
}
|
||||
// controllo per proseguire
|
||||
if (!string.IsNullOrEmpty(idxMacchina) && !string.IsNullOrEmpty(qty))
|
||||
{
|
||||
int numPzIncr = -1;
|
||||
int.TryParse(qty, out numPzIncr);
|
||||
// se il conteggio è >= 0 SALVO evento...
|
||||
if (numPzIncr >= 0)
|
||||
{
|
||||
|
||||
var listOdl = IocDbController.OdlListByMaccPeriodo(idxMacchina, dtEvent, dtEvent.AddSeconds(1));
|
||||
if (listOdl != null && listOdl.Count > 0)
|
||||
{
|
||||
string codArticolo = listOdl.FirstOrDefault()?.CodArticolo ?? "ND";
|
||||
// registro evento 120 --> contapezzi in blocco !!!HARD CODED!!! !!!FIXME!!!
|
||||
int idxEvento = 120;
|
||||
// creo evento
|
||||
EventListModel newRecEv = new EventListModel()
|
||||
{
|
||||
CodArticolo = codArticolo,
|
||||
IdxMacchina = idxMacchina,
|
||||
IdxTipo = idxEvento,
|
||||
InizioStato = dtEvent,
|
||||
MatrOpr = 0,
|
||||
pallet = "-",
|
||||
Value = qty
|
||||
};
|
||||
// salva e processa
|
||||
var resp = scriviRigaEvento(newRecEv);
|
||||
// registro in risposta che è andato tutto bene... ovvero la qty richiesta...
|
||||
answ = qty;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string errore = $"Errore: mancano parametri macchina/incremento: idxMacchina {idxMacchina} | qty {qty}";
|
||||
Log.Error(errore);
|
||||
answ = errore;
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Processa registrazione di un counter x una data macchina IOB
|
||||
/// </summary>
|
||||
@@ -2507,7 +2678,7 @@ namespace MP.IOC.Data
|
||||
// se il conteggio è >= 0 SALVO come nuovo conteggio...
|
||||
if (newCounter >= 0)
|
||||
{
|
||||
string currKey = $"{Utils.redisPzCount}:{idxMacchina}";
|
||||
var currKey = Utils.redisPzCount(idxMacchina, MpIoNS);
|
||||
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
||||
if (!rawData.HasValue)
|
||||
{
|
||||
@@ -2979,7 +3150,7 @@ namespace MP.IOC.Data
|
||||
// salvo 1:1 i valori... STATO
|
||||
result.Add("IdxMicroStato", $"{rowResult.IdxMicroStato}");
|
||||
result.Add("IdxStato", $"{rowResult.IdxStato}");
|
||||
result.Add("CodArticolo", $"{rowResult.CodArticolo}");
|
||||
result.Add("codArticolo", $"{rowResult.CodArticolo}");
|
||||
result.Add("insEnabled", $"{rowResult.InsEnabled}");
|
||||
result.Add("sLogEnabled", $"{rowResult.SLogEnabled}");
|
||||
result.Add("pallet", $"{rowResult.Pallet}");
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Version>6.16.2604.1312</Version>
|
||||
<Version>6.16.2604.1315</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<body>
|
||||
<i>Modulo MP-IOC </i>
|
||||
<h4>Versione: 6.16.2604.1312</h4>
|
||||
<h4>Versione: 6.16.2604.1315</h4>
|
||||
<br /> Note di rilascio:
|
||||
<ul>
|
||||
<li>
|
||||
|
||||
@@ -1 +1 @@
|
||||
6.16.2604.1312
|
||||
6.16.2604.1315
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<item>
|
||||
<version>6.16.2604.1312</version>
|
||||
<version>6.16.2604.1315</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