Aggiunta metodo EvListJson
This commit is contained in:
@@ -103,6 +103,122 @@ namespace MP.IOC.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Processa una chiamata POST per l'invio di un array Json di oggetti input (EVENTI)
|
||||
/// POST: IOB/evListJson/SIMUL_03
|
||||
/// </summary>
|
||||
/// <param name="id">ID dell'IOB</param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("evListJson/{id}")]
|
||||
public async Task<IActionResult> EvListJson(string id, [FromBody] string content = "")
|
||||
{
|
||||
if (string.IsNullOrEmpty(id)) return BadRequest("Missing ID");
|
||||
string answ = "-";
|
||||
try
|
||||
{
|
||||
// se ho dati...
|
||||
if (content != "")
|
||||
{
|
||||
answ = await processEvListJsonAsync(id, content);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Error($"Errore in EvListJson - no content");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, "NO");
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Errore in EvListJson{Environment.NewLine}{exc}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, "NO");
|
||||
}
|
||||
return Ok(answ);
|
||||
}
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Sistema Dossier/Snapshot giornalieri x impianto indicato, andando a generare 1 Dossier
|
||||
/// giornaliero x ogni giornata dall'ultimo registrato alla data corrente
|
||||
/// es: http://url_site/MP/IO/IOB/fixDailyDossier/SIMUL_03
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public string fixDailyDossier(string id)
|
||||
{
|
||||
string answ = "";
|
||||
// attenzione! poiché nell'URL il carattere "#" viene filtrato ci aspettiamo il
|
||||
// carattere "|" che poi trasformiamo ora in "#"
|
||||
id = id.Replace("|", "#");
|
||||
// effettuo processing
|
||||
try
|
||||
{
|
||||
DataLayer DataLayerObj = new DataLayer();
|
||||
// verifico se si possa processare, ovvero tab ConfFlux x macchina sia valorizzata...
|
||||
var confDataMach = DataLayerObj.confFluxMach(id);
|
||||
if (confDataMach.Count > 0)
|
||||
{
|
||||
// determino ultima data da processare (inizio oggi, a mezzanotte)
|
||||
DateTime dtTo = DateTime.Today;
|
||||
DateTime dtFrom = dtTo;
|
||||
// determino data di partenza, prima da dossier esistenti
|
||||
var listaDoss = DataLayerObj.dossierLastByMach(id);
|
||||
if (listaDoss.Count > 0)
|
||||
{
|
||||
// primo giorno DOPO ultima registrazione
|
||||
dtFrom = listaDoss.OrderByDescending(x => x).FirstOrDefault().AddDays(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
// ...o da fluxLog acquisiti...
|
||||
var listaFL = DataLayerObj.fluxLogFirstByMach(id);
|
||||
if (listaFL.Count > 0)
|
||||
{
|
||||
// giorno successivo a prima registrazione
|
||||
dtFrom = listaFL.OrderBy(x => x).FirstOrDefault().AddDays(1);
|
||||
}
|
||||
}
|
||||
string caller = $"takeFlogSnapshot({id})";
|
||||
DateTime dtStart = dtFrom.Date;
|
||||
DateTime dtEnd = dtFrom;
|
||||
// max 10 dossier alla volta (se non configurato diversamente)
|
||||
int maxAdd = memLayer.ML.CRI("IO_numDossMaxCreate");
|
||||
if (dtStart < dtTo)
|
||||
{
|
||||
// verifico di avere almeno 1 dossier da produrre ciclo fino ad esaurire le
|
||||
// date da processare
|
||||
while (dtStart < dtTo && maxAdd > 0)
|
||||
{
|
||||
// sistemo end
|
||||
dtEnd = dtStart.AddDays(1);
|
||||
// effettuo chiamata registrazione snapshot!
|
||||
answ = doSaveFLSnapshot(id, dtStart, dtEnd, caller);
|
||||
// incremento START...
|
||||
dtStart = dtEnd;
|
||||
// riduco il numero di chiamate ammesse x singolo task
|
||||
maxAdd--;
|
||||
}
|
||||
// reset cache dossier...
|
||||
DataLayerObj.dossierLastByMachReset(id);
|
||||
}
|
||||
else
|
||||
{
|
||||
answ = "NO more to add";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
answ = "NO ConfFluxData";
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
logger.lg.scriviLog($"Eccezione in recupero fixDailyDossier{Environment.NewLine}{exc}", tipoLog.EXCEPTION);
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Sistema ODL giornalieri x impianto indicato, andando a generare 1 ODL giornaliero x ogni
|
||||
/// giornata dall'ultimo ODL aperto alla data corrente
|
||||
@@ -609,12 +725,12 @@ namespace MP.IOC.Controllers
|
||||
DateTime dataOraEvento = DateTime.Now;
|
||||
try
|
||||
{
|
||||
answ = DService.processInput(id, valore, dtEve, dtCurr, cnt);
|
||||
answ = await DService.ProcessInputAsync(id, valore, dtEve, dtCurr, cnt);
|
||||
return Ok(answ);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Errore in processInput{Environment.NewLine}{exc}");
|
||||
Log.Error($"Errore in ProcessInputAsync{Environment.NewLine}{exc}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, "NO");
|
||||
}
|
||||
}
|
||||
@@ -1233,6 +1349,47 @@ namespace MP.IOC.Controllers
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Processing effettivo EvListJson
|
||||
/// </summary>
|
||||
/// <param name="idxMacc"></param>
|
||||
/// <param name="content"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<string> processEvListJsonAsync(string idxMacc, string content)
|
||||
{
|
||||
string answ = "";
|
||||
int insDone = 0;
|
||||
|
||||
// procedo a deserializzare in blocco l'oggetto...
|
||||
EvJsonPayloadDto receivedData = JsonConvert.DeserializeObject<EvJsonPayloadDto>(content) ?? new();
|
||||
|
||||
// se ho qualcosa da processare...
|
||||
if (receivedData != null)
|
||||
{
|
||||
// per ogni valore --> processo!
|
||||
try
|
||||
{
|
||||
foreach (var item in receivedData.eventList)
|
||||
{
|
||||
// formato datetime come yyyyMMddHHmmssfff -->es: 20181223180600000
|
||||
answ = await DService.ProcessInputAsync(idxMacc, item.valore, item.dtEve.ToString("yyyyMMddHHmmssfff"), item.dtCurr.ToString("yyyyMMddHHmmssfff"), item.cnt.ToString());
|
||||
insDone++;
|
||||
}
|
||||
// se vuoto --> OK!
|
||||
if (string.IsNullOrEmpty(answ))
|
||||
{
|
||||
answ = $"OK {insDone} processed";
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Errore in fase invio valori inputJson{Environment.NewLine}{exc}");
|
||||
answ = "NO";
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Effettua processing UserLog
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user