Aggiunta metodo GetCurrOdlStart x IOC
This commit is contained in:
@@ -492,6 +492,62 @@ namespace MP.Data.Controllers
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ODL corrente macchina
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <returns></returns>
|
||||
public ODLExpModel OdlCurrByMacc(string idxMacchina)
|
||||
{
|
||||
ODLExpModel answ = new();
|
||||
using (var dbCtx = new MoonProContext(_configuration))
|
||||
{
|
||||
try
|
||||
{
|
||||
var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina);
|
||||
var dbRes = dbCtx
|
||||
.DbSetODLExp
|
||||
.FromSqlRaw("EXEC stp_ODL_getByMacchina @IdxMacchina", IdxMacchina)
|
||||
.AsNoTracking()
|
||||
.FirstOrDefault();
|
||||
answ = dbRes ?? new();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante OdlCurrByMacc{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ODL corrente macchina
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<ODLExpModel> OdlCurrByMaccAsync(string idxMacchina)
|
||||
{
|
||||
ODLExpModel answ = new();
|
||||
using (var dbCtx = new MoonProContext(_configuration))
|
||||
{
|
||||
try
|
||||
{
|
||||
var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina);
|
||||
var dbRes = await dbCtx
|
||||
.DbSetODLExp
|
||||
.FromSqlRaw("EXEC stp_ODL_getByMacchina @IdxMacchina", IdxMacchina)
|
||||
.AsNoTracking()
|
||||
.FirstOrDefaultAsync();
|
||||
answ = dbRes ?? new();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante OdlCurrByMaccAsync{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco ODL data macchina e periodo
|
||||
/// </summary>
|
||||
|
||||
@@ -1180,7 +1180,7 @@ namespace MP.Data.Controllers
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante OdlCurrByMacc{Environment.NewLine}{exc}");
|
||||
Log.Error($"Eccezione durante OdlCurrByMaccAsync{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
return dbResult;
|
||||
|
||||
@@ -1838,7 +1838,7 @@ namespace MP.Data.Services
|
||||
#if false
|
||||
Log.Debug($"OdlCurrByMacc | {source} | {idxMacchina} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
#endif
|
||||
string callName = $"OdlCurrByMacc.{source}";
|
||||
string callName = $"OdlCurrByMaccAsync.{source}";
|
||||
int numRec = esCollect.RecordCall(callName, sw.Elapsed.TotalMilliseconds);
|
||||
if (numRec >= nRecLog)
|
||||
{
|
||||
|
||||
@@ -147,6 +147,38 @@ namespace MP.IOC.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restituisce data-ora inizio dell'odl correntemente in lavorazione sulla macchina...
|
||||
/// es: http://url_site/MP/IO/IOB/getCurrOdlStart/SIMUL_03
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("getCurrOdlStart/{id}")]
|
||||
public async Task<IActionResult> GetCurrOdlStart(string id)
|
||||
{
|
||||
if (string.IsNullOrEmpty(id)) return BadRequest("Missing ID");
|
||||
|
||||
// Multi: gestione carattere "|" trasformato in "#"
|
||||
id = id.Replace("|", "#");
|
||||
|
||||
DateTime answ = new DateTime(DateTime.Now.Year - 1, 12, 31);
|
||||
// chiamo metodo redis/db...
|
||||
try
|
||||
{
|
||||
var odlData = await DService.OdlCurrByMaccAsync(id);
|
||||
if (odlData != null && odlData.DataInizio.HasValue)
|
||||
{
|
||||
answ = odlData.DataInizio.Value;
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione in recupero getCurrOdlStart{Environment.NewLine}{exc}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, "NO");
|
||||
}
|
||||
return Ok(answ.ToString("yyyy-MM-dd HH:mm:ss"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recupera TASK richiesto x macchina:
|
||||
/// GET: IOB/getOptPar/SIMUL_03
|
||||
|
||||
+333
-306
@@ -381,20 +381,6 @@ namespace MP.IOC.Data
|
||||
{
|
||||
return mongoController.CalcRecipe(currRecipe);
|
||||
}
|
||||
/// <summary>
|
||||
/// Restituisce il valore SPECIFICATO per la state machine ingressi
|
||||
/// value: iTipoEv_nState (IdxTipoEv da trasmettere + New MICRO-STATE)
|
||||
/// </summary>
|
||||
/// <param name="idxFamIn"></param>
|
||||
/// <param name="idxMicroStato"></param>
|
||||
/// <param name="valoreIn"></param>
|
||||
/// <returns></returns>
|
||||
private string valoreSMI(int idxFamIn, int idxMicroStato, int valoreIn)
|
||||
{
|
||||
var currHash = Utils.hSMI(idxFamIn);
|
||||
string field = string.Format("{0}_{1}", idxMicroStato, valoreIn);
|
||||
return RedisGetHashField(currHash, field);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// controlla se da il segnale di "microstato" deriva un evento da generare - modalità OFFLINE
|
||||
@@ -506,191 +492,6 @@ namespace MP.IOC.Data
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scrive una riga di evento nel db + check cambio stato DiarioDiBordo
|
||||
/// </summary>
|
||||
/// <param name="newRec">codice macchina</param>
|
||||
/// <returns></returns>
|
||||
private inputComandoMapo scriviRigaEvento(EventListModel newRec)
|
||||
{
|
||||
bool inserito = false;
|
||||
try
|
||||
{
|
||||
// inserisco evento
|
||||
inserito = IocDbController.EvListInsert(newRec);
|
||||
// faccio controllo per eventuale cambio stato da tab transizioni...
|
||||
checkCambiaStatoBatch(tipoInputEvento.hw, 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>
|
||||
/// verifica se sia necessario inserire un cambio di stato impianto (DiarioDi Bordo) in modalità batch
|
||||
/// </summary>
|
||||
/// <param name="tipoInput"></param>
|
||||
/// <param name="IdxMacchina"></param>
|
||||
/// <param name="InizioStato"></param>
|
||||
/// <param name="IdxTipo"></param>
|
||||
/// <param name="CodArt"></param>
|
||||
/// <param name="Value"></param>
|
||||
/// <param name="MatrOpr"></param>
|
||||
/// <param name="pallet"></param>
|
||||
private void checkCambiaStatoBatch(tipoInputEvento tipoInput, string IdxMacchina, DateTime InizioStato, int IdxTipo, string CodArt, string Value, int MatrOpr, string pallet)
|
||||
{
|
||||
//DS_applicazione.TransizioneStatiDataTable tabTransStati;
|
||||
//DS_applicazione.TransizioneStatiRow rigaTransStati;
|
||||
List<TransizioneStatiModel> listTransit = new List<TransizioneStatiModel>();
|
||||
TransizioneStatiModel? rigaTrans = null;
|
||||
switch (tipoInput)
|
||||
{
|
||||
case tipoInputEvento.barcode:
|
||||
// effettuo cambio stato INDIPENDENTEMENTE da stato precedente
|
||||
listTransit = IocDbController.SMES_getUserForced(IdxMacchina, IdxTipo);
|
||||
|
||||
if (listTransit.Count > 0)
|
||||
{
|
||||
rigaTrans = listTransit.FirstOrDefault();
|
||||
// solo se cambia stato...
|
||||
if (rigaTrans != null && rigaTrans.IdxStato != rigaTrans.next_IdxStato)
|
||||
{
|
||||
IocDbController.DDB_InsStatoBatch(IdxMacchina, InizioStato, rigaTrans.next_IdxStato, CodArt, Value, MatrOpr, pallet);
|
||||
// aggiorno MSE
|
||||
IocDbController.RecalcMse(IdxMacchina, 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Debug($"Non trovata riga per: BARCODE | IdxMacchina: {IdxMacchina} | IdxTipo: {IdxTipo} | CodArt: {CodArt} | Value: {Value} | MatrOpr: {MatrOpr} | pallet: {pallet}");
|
||||
}
|
||||
break;
|
||||
|
||||
case tipoInputEvento.hw:
|
||||
// verifico se ci sia necessità di cambio stato
|
||||
listTransit = IocDbController.SMES_getHwTransitions(IdxMacchina, IdxTipo);
|
||||
if (listTransit.Count > 0)
|
||||
{
|
||||
rigaTrans = listTransit.FirstOrDefault();
|
||||
if (rigaTrans != null && rigaTrans.IdxStato != rigaTrans.next_IdxStato)
|
||||
{
|
||||
IocDbController.DDB_InsStatoBatch(IdxMacchina, InizioStato, rigaTrans.next_IdxStato, CodArt, Value, MatrOpr, pallet);
|
||||
// aggiorno MSE
|
||||
IocDbController.RecalcMse(IdxMacchina, 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Debug($"Non trovata riga per: HW | IdxMacchina: {IdxMacchina} | IdxTipo: {IdxTipo} | CodArt: {CodArt} | Value: {Value} | MatrOpr: {MatrOpr} | pallet: {pallet}");
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// controlla se da il segnale di "microstato" deriva un evento da generare - modalità OFFLINE
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina">idx macchina</param>
|
||||
/// <param name="valore">valore ingresso</param>
|
||||
/// <param name="dtEve">data-ora evento (server)</param>
|
||||
/// <returns></returns>
|
||||
public inputComandoMapo checkMicroStato(string idxMacchina, string valore, DateTime dtEve)
|
||||
{
|
||||
if (cMemLayer.CRI("_logLevel") > 6)
|
||||
{
|
||||
Log.Info(string.Format("{2}---------------------------{2}Richiesta verifica INPUT per Macchina {0}, seriale {1}", idxMacchina, valore, Environment.NewLine), tipoLog.INFO);
|
||||
}
|
||||
// formatto output
|
||||
inputComandoMapo answ = new inputComandoMapo();
|
||||
DS_applicazione.TransizioneIngressiDataTable TabTransIn;
|
||||
DS_applicazione.TransizioneIngressiRow rigaTransIn = null;
|
||||
// verifico se esista la macchina altrimenti la creo...
|
||||
verificaIdxMacchina(idxMacchina);
|
||||
string CodArticolo = "";
|
||||
// recupero CodArticolo corretto
|
||||
try
|
||||
{
|
||||
// 2017.07.10 forzo init x errori "sovrapposizioni"
|
||||
taDatiMacchine = new DS_ProdTempiTableAdapters.DatiMacchineTableAdapter();
|
||||
CodArticolo = taDatiMacchine.getByIdx(idxMacchina)[0].CodArticolo_A;
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Info(string.Format("[ChkMiSt_4b] - Eccezione in recupero CodArticolo:{0}{1}", Environment.NewLine, exc), tipoLog.EXCEPTION);
|
||||
}
|
||||
// recupero next microstato
|
||||
//int? valINT = Convert.ToInt32(valore);
|
||||
int? valINT = 0;
|
||||
try
|
||||
{
|
||||
// 2017.06.09 forzo init x errori "sovrapposizioni"
|
||||
MapoDbObj.taTransIngr = new DS_applicazioneTableAdapters.TransizioneIngressiTableAdapter();
|
||||
valINT = int.Parse(valore, System.Globalization.NumberStyles.HexNumber);
|
||||
TabTransIn = MapoDbObj.taTransIngr.getByIdxMacchinaValore(idxMacchina, valINT);
|
||||
if (TabTransIn.Rows.Count > 0)
|
||||
{
|
||||
rigaTransIn = TabTransIn[0];
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Info(string.Format("[ChkMiSt_5b] - Eccezione in recupero riga Trans ingressi per idxMacchina {3} e valore {2}:{0}{1}", Environment.NewLine, exc, valINT, idxMacchina), tipoLog.EXCEPTION);
|
||||
}
|
||||
int _logLevel = cMemLayer.CRI("_logLevel");
|
||||
// effettuo update vari
|
||||
if (rigaTransIn != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_logLevel > 5)
|
||||
{
|
||||
Log.Info(string.Format("[ChkMiSt_6b] - Salvo Update Microstato:{0}macchina: {1} | valore seriale: {2} | next micro stato: {3}", Environment.NewLine, idxMacchina, valINT, rigaTransIn.next_IdxMicroStato), tipoLog.INFO);
|
||||
}
|
||||
// salvo nuovo microstato...
|
||||
MapoDbObj.taMSM.updateQuery(rigaTransIn.next_IdxMicroStato, dtEve, valore, idxMacchina);
|
||||
// controllo se c'è evento
|
||||
if (rigaTransIn.IdxTipoEvento > 0)
|
||||
{
|
||||
if (_logLevel > 5)
|
||||
{
|
||||
Log.Info(string.Format("[ChkMiSt_7b] - Salvo evento:{0}macchina: {1} | tipoEvento: {2} | CodArticolo: {3}", Environment.NewLine, idxMacchina, rigaTransIn.IdxTipoEvento, CodArticolo), tipoLog.INFO);
|
||||
}
|
||||
answ = scriviRigaEvento(idxMacchina, rigaTransIn.IdxTipoEvento, CodArticolo, valore, 0, "-", dtEve, DateTime.Now);
|
||||
if (_logLevel > 5)
|
||||
{
|
||||
Log.Info(string.Format("[ChkMiSt_b] -Macchina {0}, seriale(INT) {1}{2}---------------------------{2}", idxMacchina, valINT, Environment.NewLine), tipoLog.INFO);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Info(string.Format("[ChkMiSt_8b] - Eccezione:{0}{1}", Environment.NewLine, exc), tipoLog.EXCEPTION);
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// controlla se da il segnale di "microstato" deriva un evento da generare
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <param name="valore"></param>
|
||||
/// <returns></returns>
|
||||
public inputComandoMapo checkMicroStato(string idxMacchina, string valore)
|
||||
{
|
||||
// wrapper ad ora corrente...
|
||||
return checkMicroStato(idxMacchina, valore, DateTime.Now);
|
||||
}
|
||||
#endif
|
||||
|
||||
public async Task<List<ConfigModel>> ConfigGetAllAsync()
|
||||
{
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
@@ -1127,6 +928,58 @@ namespace MP.IOC.Data
|
||||
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>
|
||||
/// Restitusice elenco KVP dei TASK (da passare a IOB-WIN) per l'impianto indicato
|
||||
/// </summary>
|
||||
@@ -1593,6 +1446,37 @@ namespace MP.IOC.Data
|
||||
return fatto;
|
||||
}
|
||||
|
||||
public async Task<ODLExpModel> OdlCurrByMaccAsync(string IdxMacchina)
|
||||
{
|
||||
ODLExpModel result = new();
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
string readType = "DB";
|
||||
string currKey = $"{Utils.redisOdlList}:Current:{IdxMacchina}";
|
||||
// cerco in redis dato valore sel macchina...
|
||||
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
||||
if (rawData.HasValue)
|
||||
{
|
||||
result = JsonConvert.DeserializeObject<ODLExpModel>($"{rawData}") ?? new();
|
||||
readType = "REDIS";
|
||||
}
|
||||
else
|
||||
{
|
||||
result = await IocDbController.OdlCurrByMaccAsync(IdxMacchina);
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
redisDb.StringSet(currKey, rawData, TimeSpan.FromSeconds(redisShortTimeCache));
|
||||
}
|
||||
if (result == null)
|
||||
{
|
||||
result = new();
|
||||
}
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Trace($"OdlCurrByMaccAsync | Read from {readType}: {ts.TotalMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Record ODL da chaive
|
||||
/// </summary>
|
||||
@@ -2436,58 +2320,6 @@ namespace MP.IOC.Data
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Processa registrazione di un counter x una data macchina IOB
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <param name="counter">contapezzi</param>
|
||||
/// <returns></returns>
|
||||
public string saveCounter(string idxMacchina, string counter)
|
||||
{
|
||||
string answ = "0";
|
||||
// inizio processing vero e proprio INPUT...
|
||||
if (!string.IsNullOrEmpty(idxMacchina))
|
||||
{
|
||||
if (!string.IsNullOrEmpty(counter))
|
||||
{
|
||||
int newCounter = -1;
|
||||
int.TryParse(counter, out newCounter);
|
||||
// se il conteggio è >= 0 SALVO come nuovo conteggio...
|
||||
if (newCounter >= 0)
|
||||
{
|
||||
var currKey = Utils.redisPzCount(idxMacchina, MpIoNS);
|
||||
RedisValue rawData = redisDb.StringGet(currKey);
|
||||
if (!rawData.HasValue)
|
||||
{
|
||||
// salvo per + tempo...
|
||||
redisDb.StringSet(currKey, answ.ToString());
|
||||
answ = counter;
|
||||
}
|
||||
else
|
||||
{
|
||||
int currCount = pzCounterTc(idxMacchina);
|
||||
answ = currCount.ToString();
|
||||
// salvo per meno tempo...
|
||||
redisDb.StringSet(currKey, answ, TimeSpan.FromSeconds(5));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string errore = "Errore: parametro counter vuoto";
|
||||
Log.Error(errore);
|
||||
answ = errore;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string errore = "Errore: parametro macchina vuoto";
|
||||
Log.Info(errore);
|
||||
answ = errore;
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Processa registrazione EVENTO CONTEGGIO PEZZI x una data macchina IOB
|
||||
/// </summary>
|
||||
@@ -2544,58 +2376,6 @@ namespace MP.IOC.Data
|
||||
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>
|
||||
@@ -2624,7 +2404,6 @@ namespace MP.IOC.Data
|
||||
// se il conteggio è >= 0 SALVO evento...
|
||||
if (numPzIncr >= 0)
|
||||
{
|
||||
|
||||
var listOdl = IocDbController.OdlListByMaccPeriodo(idxMacchina, dtEvent, dtEvent.AddSeconds(1));
|
||||
if (listOdl != null && listOdl.Count > 0)
|
||||
{
|
||||
@@ -2658,6 +2437,57 @@ namespace MP.IOC.Data
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Processa registrazione di un counter x una data macchina IOB
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <param name="counter">contapezzi</param>
|
||||
/// <returns></returns>
|
||||
public string saveCounter(string idxMacchina, string counter)
|
||||
{
|
||||
string answ = "0";
|
||||
// inizio processing vero e proprio INPUT...
|
||||
if (!string.IsNullOrEmpty(idxMacchina))
|
||||
{
|
||||
if (!string.IsNullOrEmpty(counter))
|
||||
{
|
||||
int newCounter = -1;
|
||||
int.TryParse(counter, out newCounter);
|
||||
// se il conteggio è >= 0 SALVO come nuovo conteggio...
|
||||
if (newCounter >= 0)
|
||||
{
|
||||
var currKey = Utils.redisPzCount(idxMacchina, MpIoNS);
|
||||
RedisValue rawData = redisDb.StringGet(currKey);
|
||||
if (!rawData.HasValue)
|
||||
{
|
||||
// salvo per + tempo...
|
||||
redisDb.StringSet(currKey, answ.ToString());
|
||||
answ = counter;
|
||||
}
|
||||
else
|
||||
{
|
||||
int currCount = pzCounterTc(idxMacchina);
|
||||
answ = currCount.ToString();
|
||||
// salvo per meno tempo...
|
||||
redisDb.StringSet(currKey, answ, TimeSpan.FromSeconds(5));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string errore = "Errore: parametro counter vuoto";
|
||||
Log.Error(errore);
|
||||
answ = errore;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string errore = "Errore: parametro macchina vuoto";
|
||||
Log.Info(errore);
|
||||
answ = errore;
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Processa registrazione di un counter x una data macchina IOB
|
||||
@@ -3018,6 +2848,68 @@ namespace MP.IOC.Data
|
||||
|
||||
#region Private Methods
|
||||
|
||||
/// <summary>
|
||||
/// verifica se sia necessario inserire un cambio di stato impianto (DiarioDi Bordo) in modalità batch
|
||||
/// </summary>
|
||||
/// <param name="tipoInput"></param>
|
||||
/// <param name="IdxMacchina"></param>
|
||||
/// <param name="InizioStato"></param>
|
||||
/// <param name="IdxTipo"></param>
|
||||
/// <param name="CodArt"></param>
|
||||
/// <param name="Value"></param>
|
||||
/// <param name="MatrOpr"></param>
|
||||
/// <param name="pallet"></param>
|
||||
private void checkCambiaStatoBatch(tipoInputEvento tipoInput, string IdxMacchina, DateTime InizioStato, int IdxTipo, string CodArt, string Value, int MatrOpr, string pallet)
|
||||
{
|
||||
//DS_applicazione.TransizioneStatiDataTable tabTransStati;
|
||||
//DS_applicazione.TransizioneStatiRow rigaTransStati;
|
||||
List<TransizioneStatiModel> listTransit = new List<TransizioneStatiModel>();
|
||||
TransizioneStatiModel? rigaTrans = null;
|
||||
switch (tipoInput)
|
||||
{
|
||||
case tipoInputEvento.barcode:
|
||||
// effettuo cambio stato INDIPENDENTEMENTE da stato precedente
|
||||
listTransit = IocDbController.SMES_getUserForced(IdxMacchina, IdxTipo);
|
||||
|
||||
if (listTransit.Count > 0)
|
||||
{
|
||||
rigaTrans = listTransit.FirstOrDefault();
|
||||
// solo se cambia stato...
|
||||
if (rigaTrans != null && rigaTrans.IdxStato != rigaTrans.next_IdxStato)
|
||||
{
|
||||
IocDbController.DDB_InsStatoBatch(IdxMacchina, InizioStato, rigaTrans.next_IdxStato, CodArt, Value, MatrOpr, pallet);
|
||||
// aggiorno MSE
|
||||
IocDbController.RecalcMse(IdxMacchina, 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Debug($"Non trovata riga per: BARCODE | IdxMacchina: {IdxMacchina} | IdxTipo: {IdxTipo} | CodArt: {CodArt} | Value: {Value} | MatrOpr: {MatrOpr} | pallet: {pallet}");
|
||||
}
|
||||
break;
|
||||
|
||||
case tipoInputEvento.hw:
|
||||
// verifico se ci sia necessità di cambio stato
|
||||
listTransit = IocDbController.SMES_getHwTransitions(IdxMacchina, IdxTipo);
|
||||
if (listTransit.Count > 0)
|
||||
{
|
||||
rigaTrans = listTransit.FirstOrDefault();
|
||||
if (rigaTrans != null && rigaTrans.IdxStato != rigaTrans.next_IdxStato)
|
||||
{
|
||||
IocDbController.DDB_InsStatoBatch(IdxMacchina, InizioStato, rigaTrans.next_IdxStato, CodArt, Value, MatrOpr, pallet);
|
||||
// aggiorno MSE
|
||||
IocDbController.RecalcMse(IdxMacchina, 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Debug($"Non trovata riga per: HW | IdxMacchina: {IdxMacchina} | IdxTipo: {IdxTipo} | CodArt: {CodArt} | Value: {Value} | MatrOpr: {MatrOpr} | pallet: {pallet}");
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recupero info ODL corrente da dati prod macchina
|
||||
/// </summary>
|
||||
@@ -3234,6 +3126,32 @@ namespace MP.IOC.Data
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scrive una riga di evento nel db + check cambio stato DiarioDiBordo
|
||||
/// </summary>
|
||||
/// <param name="newRec">codice macchina</param>
|
||||
/// <returns></returns>
|
||||
private inputComandoMapo scriviRigaEvento(EventListModel newRec)
|
||||
{
|
||||
bool inserito = false;
|
||||
try
|
||||
{
|
||||
// inserisco evento
|
||||
inserito = IocDbController.EvListInsert(newRec);
|
||||
// faccio controllo per eventuale cambio stato da tab transizioni...
|
||||
checkCambiaStatoBatch(tipoInputEvento.hw, 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
|
||||
@@ -3342,6 +3260,117 @@ namespace MP.IOC.Data
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restituisce il valore SPECIFICATO per la state machine ingressi
|
||||
/// value: iTipoEv_nState (IdxTipoEv da trasmettere + New MICRO-STATE)
|
||||
/// </summary>
|
||||
/// <param name="idxFamIn"></param>
|
||||
/// <param name="idxMicroStato"></param>
|
||||
/// <param name="valoreIn"></param>
|
||||
/// <returns></returns>
|
||||
private string valoreSMI(int idxFamIn, int idxMicroStato, int valoreIn)
|
||||
{
|
||||
var currHash = Utils.hSMI(idxFamIn);
|
||||
string field = string.Format("{0}_{1}", idxMicroStato, valoreIn);
|
||||
return RedisGetHashField(currHash, field);
|
||||
}
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// controlla se da il segnale di "microstato" deriva un evento da generare - modalità OFFLINE
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina">idx macchina</param>
|
||||
/// <param name="valore">valore ingresso</param>
|
||||
/// <param name="dtEve">data-ora evento (server)</param>
|
||||
/// <returns></returns>
|
||||
public inputComandoMapo checkMicroStato(string idxMacchina, string valore, DateTime dtEve)
|
||||
{
|
||||
if (cMemLayer.CRI("_logLevel") > 6)
|
||||
{
|
||||
Log.Info(string.Format("{2}---------------------------{2}Richiesta verifica INPUT per Macchina {0}, seriale {1}", idxMacchina, valore, Environment.NewLine), tipoLog.INFO);
|
||||
}
|
||||
// formatto output
|
||||
inputComandoMapo answ = new inputComandoMapo();
|
||||
DS_applicazione.TransizioneIngressiDataTable TabTransIn;
|
||||
DS_applicazione.TransizioneIngressiRow rigaTransIn = null;
|
||||
// verifico se esista la macchina altrimenti la creo...
|
||||
verificaIdxMacchina(idxMacchina);
|
||||
string CodArticolo = "";
|
||||
// recupero CodArticolo corretto
|
||||
try
|
||||
{
|
||||
// 2017.07.10 forzo init x errori "sovrapposizioni"
|
||||
taDatiMacchine = new DS_ProdTempiTableAdapters.DatiMacchineTableAdapter();
|
||||
CodArticolo = taDatiMacchine.getByIdx(idxMacchina)[0].CodArticolo_A;
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Info(string.Format("[ChkMiSt_4b] - Eccezione in recupero CodArticolo:{0}{1}", Environment.NewLine, exc), tipoLog.EXCEPTION);
|
||||
}
|
||||
// recupero next microstato
|
||||
//int? valINT = Convert.ToInt32(valore);
|
||||
int? valINT = 0;
|
||||
try
|
||||
{
|
||||
// 2017.06.09 forzo init x errori "sovrapposizioni"
|
||||
MapoDbObj.taTransIngr = new DS_applicazioneTableAdapters.TransizioneIngressiTableAdapter();
|
||||
valINT = int.Parse(valore, System.Globalization.NumberStyles.HexNumber);
|
||||
TabTransIn = MapoDbObj.taTransIngr.getByIdxMacchinaValore(idxMacchina, valINT);
|
||||
if (TabTransIn.Rows.Count > 0)
|
||||
{
|
||||
rigaTransIn = TabTransIn[0];
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Info(string.Format("[ChkMiSt_5b] - Eccezione in recupero riga Trans ingressi per idxMacchina {3} e valore {2}:{0}{1}", Environment.NewLine, exc, valINT, idxMacchina), tipoLog.EXCEPTION);
|
||||
}
|
||||
int _logLevel = cMemLayer.CRI("_logLevel");
|
||||
// effettuo update vari
|
||||
if (rigaTransIn != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_logLevel > 5)
|
||||
{
|
||||
Log.Info(string.Format("[ChkMiSt_6b] - Salvo Update Microstato:{0}macchina: {1} | valore seriale: {2} | next micro stato: {3}", Environment.NewLine, idxMacchina, valINT, rigaTransIn.next_IdxMicroStato), tipoLog.INFO);
|
||||
}
|
||||
// salvo nuovo microstato...
|
||||
MapoDbObj.taMSM.updateQuery(rigaTransIn.next_IdxMicroStato, dtEve, valore, idxMacchina);
|
||||
// controllo se c'è evento
|
||||
if (rigaTransIn.IdxTipoEvento > 0)
|
||||
{
|
||||
if (_logLevel > 5)
|
||||
{
|
||||
Log.Info(string.Format("[ChkMiSt_7b] - Salvo evento:{0}macchina: {1} | tipoEvento: {2} | CodArticolo: {3}", Environment.NewLine, idxMacchina, rigaTransIn.IdxTipoEvento, CodArticolo), tipoLog.INFO);
|
||||
}
|
||||
answ = scriviRigaEvento(idxMacchina, rigaTransIn.IdxTipoEvento, CodArticolo, valore, 0, "-", dtEve, DateTime.Now);
|
||||
if (_logLevel > 5)
|
||||
{
|
||||
Log.Info(string.Format("[ChkMiSt_b] -Macchina {0}, seriale(INT) {1}{2}---------------------------{2}", idxMacchina, valINT, Environment.NewLine), tipoLog.INFO);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Info(string.Format("[ChkMiSt_8b] - Eccezione:{0}{1}", Environment.NewLine, exc), tipoLog.EXCEPTION);
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// controlla se da il segnale di "microstato" deriva un evento da generare
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <param name="valore"></param>
|
||||
/// <returns></returns>
|
||||
public inputComandoMapo checkMicroStato(string idxMacchina, string valore)
|
||||
{
|
||||
// wrapper ad ora corrente...
|
||||
return checkMicroStato(idxMacchina, valore, DateTime.Now);
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// cerca codice in anagrafica macchine ed eventualmente inserisce nuova macchina
|
||||
@@ -3394,8 +3423,6 @@ namespace MP.IOC.Data
|
||||
IocDbController.MicroStatoMacchinaUpsert(msRec);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Version>6.16.2604.1315</Version>
|
||||
<Version>6.16.2604.1316</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<body>
|
||||
<i>Modulo MP-IOC </i>
|
||||
<h4>Versione: 6.16.2604.1315</h4>
|
||||
<h4>Versione: 6.16.2604.1316</h4>
|
||||
<br /> Note di rilascio:
|
||||
<ul>
|
||||
<li>
|
||||
|
||||
@@ -1 +1 @@
|
||||
6.16.2604.1315
|
||||
6.16.2604.1316
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<item>
|
||||
<version>6.16.2604.1315</version>
|
||||
<version>6.16.2604.1316</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