Aggiunta metodi ulog
This commit is contained in:
@@ -534,6 +534,77 @@ namespace MP.IOC.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Processa una chiamata GET x salvare UserLog
|
||||
/// GET: IOB/ulog/SIMUL_03?flux=PROG&valore=P0001&dtEve=20161223180600000&dtCurr=20161223180600000&cnt=999&matrOpr=0=0&label=&valNum
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="flux"></param>
|
||||
/// <param name="valore"></param>
|
||||
/// <param name="dtEve"></param>
|
||||
/// <param name="dtCurr"></param>
|
||||
/// <param name="cnt"></param>
|
||||
/// <param name="matrOpr"></param>
|
||||
/// <param name="label"></param>
|
||||
/// <param name="valNum"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("ulog/{id}")]
|
||||
public async Task<IActionResult> ULog(string id, string flux, string valore, string dtEve, string dtCurr, string cnt, string matrOpr, string label, string valNum)
|
||||
{
|
||||
if (string.IsNullOrEmpty(id)) return BadRequest("Missing ID");
|
||||
|
||||
// Multi: gestione carattere "|" trasformato in "#"
|
||||
id = id.Replace("|", "#");
|
||||
string answ = "";
|
||||
// formato yyyymmddHHMMSSnnn ovvero da anno a millisecondi
|
||||
if (string.IsNullOrEmpty(cnt))
|
||||
{
|
||||
cnt = "0";
|
||||
}
|
||||
|
||||
DateTime dataOraEvento = DateTime.Now;
|
||||
try
|
||||
{
|
||||
int count = 0;
|
||||
int nMatrOpr = 0;
|
||||
int nValNum = 0;
|
||||
Int32.TryParse(cnt, out count);
|
||||
Int32.TryParse(matrOpr, out nMatrOpr);
|
||||
Int32.TryParse(valNum, out nValNum);
|
||||
answ = await DService.ProcessUserLogAsync(id, flux, valore, dtEve, dtCurr, count, nMatrOpr, label, nValNum);
|
||||
return Ok(answ);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Errore in ulog{Environment.NewLine}{exc}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, "NO");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Processa una chiamata POST per l'invio di una List Json 1+ UserAction (contiene
|
||||
/// controlli, scarti, dichiarazioni)
|
||||
/// POST: IOB/ulogJson/SIMUL_03
|
||||
/// </summary>
|
||||
/// <param name="id">ID dell'IOB</param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("ulogJson/{id}")]
|
||||
public async Task<IActionResult> ulogJson(string id, [FromBody] string content = "")
|
||||
{
|
||||
string answ = "-";
|
||||
// se ho dati...
|
||||
if (content != "")
|
||||
{
|
||||
answ = await processULogJsonAsync(id, content);
|
||||
return Ok(answ);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Error($"Errore in ULogJson - no content");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, "NO");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Processa una chiamata POST per l'invio di una List Json di UNO O PIU' oggetti objItem
|
||||
/// POST: IOB/upsertObjItems/SIMUL_03
|
||||
@@ -716,6 +787,54 @@ namespace MP.IOC.Controllers
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Effettua processing UserLog
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="content"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<string> processULogJsonAsync(string id, string content)
|
||||
{
|
||||
string answ = "";
|
||||
int insDone = 0;
|
||||
// procedo a deserializzare in blocco l'oggetto...
|
||||
ULogJsonPayloadDto receivedData = new ULogJsonPayloadDto();
|
||||
try
|
||||
{
|
||||
// deserializzo.
|
||||
receivedData = JsonConvert.DeserializeObject<ULogJsonPayloadDto>(content) ?? new();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Errore in fase deserializzazione ulogJson{Environment.NewLine}{exc}");
|
||||
answ = "NO";
|
||||
}
|
||||
// se ho qualcosa da processare...
|
||||
if (receivedData != null)
|
||||
{
|
||||
// per ogni valore --> salvo!
|
||||
try
|
||||
{
|
||||
foreach (var item in receivedData.fluxData)
|
||||
{
|
||||
// formato datetime come yyyyMMddHHmmssfff -->es: 20181223180600000
|
||||
answ = await DService.ProcessUserLogAsync(id, item.flux, item.valore, item.dtEve.ToString("yyyyMMddHHmmssfff"), item.dtCurr.ToString("yyyyMMddHHmmssfff"), item.cnt, item.matrOpr, item.label, item.valNum);
|
||||
}
|
||||
// se vuoto --> OK!
|
||||
if (string.IsNullOrEmpty(answ))
|
||||
{
|
||||
answ = $"OK {insDone} processed";
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Errore in fase invio valori ulogJson{Environment.NewLine}{exc}");
|
||||
answ = "NO";
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
#endregion Private Methods
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user