109 lines
3.8 KiB
C#
109 lines
3.8 KiB
C#
using EgwCoreLib.Lux.Data.DbModel.Sales;
|
|
using EgwCoreLib.Lux.Data.Services.Sales;
|
|
|
|
namespace Lux.API.Controllers
|
|
{
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public class ReportController : ControllerBase
|
|
{
|
|
/// <summary>
|
|
/// Costruttore metodo
|
|
/// </summary>
|
|
/// <param name="offService"></param>
|
|
public ReportController(IOfferService offService)
|
|
{
|
|
_offService = offService;
|
|
// Configurazione serializzatore JSON per risolvere errore di loop circolare
|
|
JSSettings = new JsonSerializerSettings()
|
|
{
|
|
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
|
|
};
|
|
}
|
|
|
|
private JsonSerializerSettings JSSettings;
|
|
|
|
private IOfferService _offService;
|
|
|
|
///// <summary>
|
|
///// Chiamata GET: restituisce file PNG (da file o da cache)
|
|
///// PUT: api/image/png/00000000-0000-0000-0000-000000000000
|
|
///// </summary>
|
|
///// <param name="id">id oggetto</param>
|
|
///// <returns></returns>
|
|
//[HttpGet("png/{id}")]
|
|
//public async Task<IActionResult> png(string id)
|
|
//{
|
|
// Stopwatch sw = new Stopwatch();
|
|
// sw.Start();
|
|
// string base64Encoded = "";
|
|
// byte[] decodedBytes = new byte[0];
|
|
// // ...se ricevo percorso --> leggo jwd/svg cablato
|
|
// if (!string.IsNullOrEmpty(id))
|
|
// {
|
|
// // bonifica nome svg da
|
|
// base64Encoded = _imgService.LoadPng(id, EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS.BEAM);
|
|
// // converto base64
|
|
// decodedBytes = Convert.FromBase64String(base64Encoded);
|
|
// }
|
|
// sw.Stop();
|
|
// Log.Info($"pngString | {sw.Elapsed.TotalMilliseconds:N3} ms");
|
|
// //return Ok(decodedString);
|
|
// return File(decodedBytes, "image/png");
|
|
//}
|
|
|
|
|
|
/// <summary>
|
|
/// Chiamata GET: riceve ELENCO Offerte dato periodo
|
|
/// GET: api/report/offert-list/?from=2026-01-01&to=2026-04-01
|
|
/// </summary>
|
|
/// <param name="id">id univoco img</param>
|
|
/// <returns></returns>
|
|
[HttpGet("offert-list")]
|
|
public async Task<IActionResult> Offert(DateTime from, DateTime to)
|
|
{
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
// recupera dal DB l'offerta con le righe relative
|
|
List<OfferModel> offData = await _offService.GetFiltAsync(from, to);
|
|
|
|
sw.Stop();
|
|
//_logger.LogInformation($"svgString | {sw.Elapsed.TotalMilliseconds:N3} ms");
|
|
string jsonRes = JsonConvert.SerializeObject(offData, JSSettings);
|
|
return Ok(jsonRes);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Chiamata GET: riceve OffertID, restituisce Json offerta + righe
|
|
/// GET: api/report/offert/1
|
|
/// </summary>
|
|
/// <param name="id">id univoco img</param>
|
|
/// <returns></returns>
|
|
[HttpGet("offert/{id}")]
|
|
public async Task<IActionResult> Offert(int id)
|
|
{
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
// recupera dal DB l'offerta con le righe relative
|
|
OfferModel? offData = await _offService.GetByIdAsync(id);
|
|
|
|
sw.Stop();
|
|
//_logger.LogInformation($"svgString | {sw.Elapsed.TotalMilliseconds:N3} ms");
|
|
string jsonRes = JsonConvert.SerializeObject(offData, JSSettings);
|
|
return Ok(jsonRes);
|
|
}
|
|
|
|
[HttpGet("version")]
|
|
public string version()
|
|
{
|
|
var version = Assembly
|
|
.GetExecutingAssembly()
|
|
.GetName()
|
|
.Version?
|
|
.ToString() ?? "unknown";
|
|
|
|
return version;
|
|
}
|
|
}
|
|
}
|