Aggiunta metodo getCurrODL
This commit is contained in:
@@ -69,21 +69,6 @@ namespace MP.IOC.Controllers
|
||||
//return StatusCode(503, "NO");
|
||||
return UnprocessableEntity("NO");
|
||||
}
|
||||
#if false
|
||||
if (string.IsNullOrEmpty(id)) return Ok("KO");
|
||||
|
||||
try
|
||||
{
|
||||
var result = DService.IobInsEnab(id) ? "OK" : "NO";
|
||||
// Logga solo l'esito se necessario
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Errore in enabled {id}: {exc.Message}");
|
||||
return Ok("NO");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -127,8 +112,7 @@ namespace MP.IOC.Controllers
|
||||
{
|
||||
if (string.IsNullOrEmpty(id)) return BadRequest("Missing ID");
|
||||
|
||||
// attenzione! poiché nell'URL il carattere "#" viene filtrato ci aspettiamo il
|
||||
// carattere "|" che poi trasformiamo ora in "#"
|
||||
// Multi: gestione carattere "|" trasformato in "#"
|
||||
id = id.Replace("|", "#");
|
||||
try
|
||||
{
|
||||
@@ -138,61 +122,38 @@ namespace MP.IOC.Controllers
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error(exc, "Errore durante il recupero del counter TC per la macchina {MachineId}", id);
|
||||
//return StatusCode(StatusCodes.Status500InternalServerError, "NO");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, "Errore interno | GetCounterTCRec");
|
||||
}
|
||||
}
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Recupera COUNTER x macchina:
|
||||
///
|
||||
/// GET: IOB/getCounter/5
|
||||
/// Recupera ODL corrente x macchina:
|
||||
/// GET: IOB/getCurrODL/SIMUL_03
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("getCounter/{id}")]
|
||||
public async Task<string> getCounter(string id)
|
||||
[HttpGet("getCurrODL/{id}")]
|
||||
public async Task<IActionResult> GetCurrODL(string id)
|
||||
{
|
||||
string answ = "";
|
||||
try
|
||||
{
|
||||
var pzCount = await _tabDService.pzCounter(id);
|
||||
answ = $"{pzCount}";
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Errore in counter TC (get){Environment.NewLine}{exc}");
|
||||
answ = "NO";
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
/// <summary>
|
||||
/// Recupera COUNTER x macchina dal CONTEGGIO dei TCRecorded:
|
||||
///
|
||||
/// GET: IOB/getCounterTCRec/5
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("getCounterTCRec/{id}")]
|
||||
public async Task<string> getCounterTCRec(string id)
|
||||
{
|
||||
// attenzione! poiché nell'URL il carattere "#" viene filtrato ci aspettiamo il
|
||||
// carattere "|" che poi trasformiamo ora in "#"
|
||||
if (string.IsNullOrEmpty(id)) return BadRequest("Missing ID");
|
||||
|
||||
// Multi: gestione carattere "|" trasformato in "#"
|
||||
id = id.Replace("|", "#");
|
||||
string answ = "";
|
||||
try
|
||||
{
|
||||
var pzCountTC = await _tabDService.pzCounterTC(id);
|
||||
answ = $"{pzCountTC}";
|
||||
var odl = await DService.GetCurrOdlAsync(id);
|
||||
answ = $"{odl}";
|
||||
return Ok(answ);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Errore in counter TC (get){Environment.NewLine}{exc}");
|
||||
answ = "NO";
|
||||
Log.Error(exc, "Errore GetCurrODL | macchina {MachineId}", id);
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, "NO");
|
||||
//return StatusCode(StatusCodes.Status500InternalServerError, "Errore interno | GetCurrODL");
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Recupera TASK richiesto x macchina:
|
||||
|
||||
@@ -761,6 +761,58 @@ namespace MP.IOC.Data
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restituisce il valore dell'ODL corrente (ODL deve esserci per gestione contapezzi, senza
|
||||
/// ODL NO invio/gestione ODL)
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<string> GetCurrOdlAsync(string idxMacchina)
|
||||
{
|
||||
string result = "";
|
||||
string currKey = $"{Utils.redisOdlCurrByMac}:{idxMacchina}";
|
||||
// cerco in redis dato valore sel macchina...
|
||||
RedisValue rawData = redisDb.StringGet(currKey);
|
||||
if (rawData.HasValue)
|
||||
{
|
||||
result = $"{rawData}";
|
||||
}
|
||||
else
|
||||
{
|
||||
result = await GetCurrOdlByProdAsync(idxMacchina);
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
redisDb.StringSet(currKey, rawData, getRandTOut(redisLongTimeCache));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restituisce il valore dell'ODL corrente (ODL deve esserci per gestione contapezzi, senza
|
||||
/// ODL NO invio/gestione ODL)
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <param name="forceDb">indica se forzare lettura da db (true) o meno</param>
|
||||
/// <returns></returns>
|
||||
public async Task<string> GetCurrOdlAsync(string idxMacchina, bool forceDb)
|
||||
{
|
||||
string answ = "";
|
||||
// se ho forceDB leggo dai dati prod...
|
||||
if (forceDb)
|
||||
{
|
||||
var datiProd = await StatoProdMacchinaAsync(idxMacchina, DateTime.Now, true);
|
||||
if (datiProd != null)
|
||||
{
|
||||
answ = datiProd.IdxOdl.ToString();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
answ = await GetCurrOdlAsync(idxMacchina);
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Init ricetta
|
||||
/// </summary>
|
||||
@@ -2194,6 +2246,26 @@ namespace MP.IOC.Data
|
||||
|
||||
#region Private Methods
|
||||
|
||||
/// <summary>
|
||||
/// Recupero info ODL corrente da dati prod macchina
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<string> GetCurrOdlByProdAsync(string idxMacchina)
|
||||
{
|
||||
string answ = "";
|
||||
// recupero stato...
|
||||
var datiProd = await StatoProdMacchinaAsync(idxMacchina, DateTime.Now);
|
||||
if (datiProd != null)
|
||||
{
|
||||
answ = datiProd.IdxOdl.ToString();
|
||||
}
|
||||
// ultimo controllo su idxOdl...
|
||||
answ = answ == "" ? "0" : answ;
|
||||
// restituisco!
|
||||
return answ;
|
||||
}
|
||||
|
||||
private async Task<bool> POdlFlushCache()
|
||||
{
|
||||
bool answ = false;
|
||||
@@ -2223,7 +2295,7 @@ namespace MP.IOC.Data
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <param name="dtReq"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<StatoProdModel> StatoProdMacchinaAsync(string idxMacchina, DateTime dtReq)
|
||||
private async Task<StatoProdModel> StatoProdMacchinaAsync(string idxMacchina, DateTime dtReq, bool forceDb = false)
|
||||
{
|
||||
int rndWait = rnd.Next(0, 2);
|
||||
await Task.Delay(rndWait);
|
||||
@@ -2234,7 +2306,7 @@ namespace MP.IOC.Data
|
||||
string currKey = $"{Utils.redisStatoProd}:{idxMacchina}:{dtReq:HHmm}";
|
||||
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
||||
//if (!string.IsNullOrEmpty($"{rawData}"))
|
||||
if (rawData.HasValue)
|
||||
if (rawData.HasValue && !forceDb)
|
||||
{
|
||||
result = JsonConvert.DeserializeObject<StatoProdModel>($"{rawData}");
|
||||
source = "REDIS";
|
||||
|
||||
Reference in New Issue
Block a user