Aggiunta metodo GetIdlePeriod
This commit is contained in:
@@ -483,7 +483,6 @@ namespace MP.IOC.Controllers
|
||||
return Ok(answ);
|
||||
}
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Restituisce il valore dello stato di IDLE della macchina, quindi SOLO SE NON é in lavoro
|
||||
/// e già convertito in minuti...
|
||||
@@ -492,38 +491,43 @@ namespace MP.IOC.Controllers
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("getIdlePeriod/{id}")]
|
||||
public int GetIdlePeriod(string id)
|
||||
public async Task<IActionResult> GetIdlePeriod(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("|", "#");
|
||||
int answ = 0;
|
||||
DataLayer DataLayerObj = new DataLayer();
|
||||
DS_applicazione.StatoMacchineDataTable currData = null;
|
||||
// chiamo metodo redis/db...
|
||||
|
||||
// chiamo metodo x avere stato macchina...
|
||||
try
|
||||
{
|
||||
currData = DataLayerObj.currSMTab(id);
|
||||
if (currData.Count > 0)
|
||||
var mseData = await DService.MseGetAllAsync();
|
||||
if (mseData.Count > 0)
|
||||
{
|
||||
// recupero da redis elenco stati
|
||||
DS_applicazione.AnagraficaStatiDataTable anagStati = DataLayerObj.AnagraficaStati();
|
||||
DS_applicazione.AnagraficaStatiRow currStato = anagStati.FindByIdxStato(currData[0].IdxStato);
|
||||
// calcolo SE sia idle... OVVERO SEMAFORO NON VERDE!!!
|
||||
if (currStato.Semaforo != "sVe")
|
||||
var currRec = mseData.FirstOrDefault(x => x.IdxMacchina == id);
|
||||
if (currRec != null)
|
||||
{
|
||||
// calcolo durata...
|
||||
answ = (int)DateTime.Now.Subtract(currData[0].InizioStato).TotalMinutes;
|
||||
// recupero da redis elenco stati
|
||||
var anagStati = await DService.AnagStatiGetAllAsync();
|
||||
var currStato = anagStati.FirstOrDefault(x => x.IdxStato == currRec.IdxStato);
|
||||
// calcolo SE sia idle... OVVERO SEMAFORO NON VERDE!!!
|
||||
if (currStato != null && currStato.Semaforo != "sVe")
|
||||
{
|
||||
// calcolo durata...
|
||||
answ = (int)(currRec.Durata ?? 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
logger.lg.scriviLog($"Eccezione in recupero getIdlePeriod{Environment.NewLine}{exc}", tipoLog.EXCEPTION);
|
||||
Log.Error($"Errore in GetIdlePeriod{Environment.NewLine}{exc}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, "NO");
|
||||
}
|
||||
return answ;
|
||||
return Ok(answ);
|
||||
}
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Recupera codice numerico ODL/PODL dato CodXdl, in pratica la parte finale SENZA ODL/PODL
|
||||
/// Funzione per impianti che accettano solo INT in scrittura:
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using MP.Core.Conf;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using MP.Core.Conf;
|
||||
using MP.Core.DTO;
|
||||
using MP.Core.Objects;
|
||||
using MP.Data;
|
||||
@@ -263,6 +264,66 @@ namespace MP.IOC.Data
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restituisce l'anagrafica STATI per intero
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<List<AnagStatiModel>> AnagStatiGetAllAsync()
|
||||
{
|
||||
List<AnagStatiModel> dbResult = new List<AnagStatiModel>();
|
||||
// cerco in redis...
|
||||
var currKey = Utils.redisAnagStati;
|
||||
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
||||
if (rawData.HasValue)
|
||||
{
|
||||
dbResult = JsonConvert.DeserializeObject<List<AnagStatiModel>>($"{rawData}") ?? new();
|
||||
}
|
||||
else
|
||||
{
|
||||
dbResult = await IocDbController.AnagStatiGetAllAsync();
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(dbResult);
|
||||
await redisDb.StringSetAsync(currKey, rawData, getRandTOut(redisLongTimeCache));
|
||||
}
|
||||
return dbResult;
|
||||
}
|
||||
/// <summary>
|
||||
/// MS max age x dato MSE
|
||||
/// </summary>
|
||||
private int maxAge = 2000;
|
||||
/// <summary>
|
||||
/// Elenco da tabella MappaStatoExplModel
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<List<MappaStatoExplModel>> MseGetAllAsync(bool forceDb = false)
|
||||
{
|
||||
Stopwatch sw = new Stopwatch();
|
||||
string source = "DB";
|
||||
sw.Start();
|
||||
List<MappaStatoExplModel>? result = new List<MappaStatoExplModel>();
|
||||
// cerco in _redisConn...
|
||||
RedisValue rawData = await redisDb.StringGetAsync(Constants.redisMseKey);
|
||||
if (rawData.HasValue && !forceDb)
|
||||
{
|
||||
result = JsonConvert.DeserializeObject<List<MappaStatoExplModel>>($"{rawData}") ?? new();
|
||||
source = "REDIS";
|
||||
}
|
||||
else
|
||||
{
|
||||
result = await IocDbController.MseGetAllAsync(maxAge);
|
||||
// serializzp e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(Constants.redisMseKey, rawData, getRandTOut(redisShortTimeCache / 2));
|
||||
}
|
||||
if (result == null)
|
||||
{
|
||||
result = new List<MappaStatoExplModel>();
|
||||
}
|
||||
sw.Stop();
|
||||
Log.Debug($"MseGetAllAsync | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<List<ListValuesModel>> AnagStatiComm()
|
||||
{
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
|
||||
Reference in New Issue
Block a user