diff --git a/WebDoorCreator.API/Controllers/OrderController.cs b/WebDoorCreator.API/Controllers/OrderController.cs index 5bd8ac4..d6771da 100644 --- a/WebDoorCreator.API/Controllers/OrderController.cs +++ b/WebDoorCreator.API/Controllers/OrderController.cs @@ -10,34 +10,70 @@ namespace WebDoorCreator.API.Controllers [ApiController] public class OrderController : ControllerBase { - public OrderController(IConfiguration configuration, QueueDataService DataService) + public OrderController(IConfiguration configuration, WebDoorCreatorService DataService) { Log.Info("Starting OrderController"); _configuration = configuration; - QDataServ = DataService; + WDCService = DataService; Log.Info("Avviato OrderController"); } - // GET: api/Alive + /// + /// GET: api/Order + /// + /// [HttpGet] public string Get() { return "OK"; - } + } /// - /// Order detail for cost evaluation - /// - /// - /// + /// GET: api/Order/GetCurrent + /// Recupera ordini degli ultimi 6 mesi dato cliente e stato + /// + /// + [HttpGet("GetCurrent")] + public async Task> GetCurrent(int id, int ordStatus) + { + List answ = new List(); + DateTime dtEnd = DateTime.Now; + DateTime dtStart = dtEnd.AddMonths(-1); + var rawData = await WDCService.OrderStatusGetFilt(id, ordStatus, dtStart, dtEnd); + if (rawData != null) + { + answ = rawData.Select(x => x.OrderId).ToList(); + } + return answ; + } + /// + /// Order detail for cost evaluation + /// + /// + /// [HttpGet("OrderDetail")] public async Task OrderDetail(int OrderId) { - OrderDetailsDTO answ = new OrderDetailsDTO(); + OrderDetailsDTO answ = new OrderDetailsDTO() + { + OrderId = OrderId + }; + // recupero info ordine + var rawOrder = await WDCService.OrderGetByKey(OrderId); + if (rawOrder != null) + { + answ.OrderDescript = rawOrder.OrderDescript; + answ.OrderExtCode = rawOrder.OrderExtCode; + // recupero info customer + + // recuper elenco porte... + //answ. = rawOrder.OrderDescript; + } + // popolo con dati specifica... return answ; } private static IConfiguration _configuration = null!; private static Logger Log = LogManager.GetCurrentClassLogger(); - private QueueDataService QDataServ { get; set; } = null!; + private WebDoorCreatorService WDCService { get; set; } = null!; } } diff --git a/WebDoorCreator.API/Program.cs b/WebDoorCreator.API/Program.cs index ece0173..001680e 100644 --- a/WebDoorCreator.API/Program.cs +++ b/WebDoorCreator.API/Program.cs @@ -57,6 +57,7 @@ builder.Services.AddStackExchangeRedisExtensions((options) }); builder.Services.AddSingleton(); +builder.Services.AddSingleton(); builder.Services.AddSingleton(redisMultiplexer); var app = builder.Build(); diff --git a/WebDoorCreator.Core/Constants.cs b/WebDoorCreator.Core/Constants.cs index 242f592..b09caac 100644 --- a/WebDoorCreator.Core/Constants.cs +++ b/WebDoorCreator.Core/Constants.cs @@ -43,6 +43,7 @@ namespace WebDoorCreator.Core public const string rKeyGraphicParameters = $"{redisBaseAddr}:Cache:GraphicParameters"; public const string rKeyListValues = $"{redisBaseAddr}:Cache:ListValues"; public const string rKeyDoorLast = $"{redisBaseAddr}:Cache:DoorList"; + public const string rKeyDoorsByOrder = $"{redisBaseAddr}:Cache:DoorsByOrder"; public const string rKeyOrderDetail = $"{redisBaseAddr}:Cache:OrderDetail"; public const string rKeyOrderStatus = $"{redisBaseAddr}:Cache:OrderStatus"; public const string rKeyRoles = $"{redisBaseAddr}:Cache:Roles"; diff --git a/WebDoorCreator.Data/Controllers/WebDoorCreatorController.cs b/WebDoorCreator.Data/Controllers/WebDoorCreatorController.cs index 5a4f426..8374b6e 100644 --- a/WebDoorCreator.Data/Controllers/WebDoorCreatorController.cs +++ b/WebDoorCreator.Data/Controllers/WebDoorCreatorController.cs @@ -2,6 +2,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using NLog; +using System.ComponentModel.Design; using System.Data; using WebDoorCreator.Data.DbModels; using WebDoorCreator.Data.DTO; @@ -770,6 +771,31 @@ namespace WebDoorCreator.Data.Controllers return fatto; } + public OrderModel OrderGetByKey(int orderId) + { + OrderModel dbResult = new OrderModel(); + using (var dbCtx = new WDCDataContext(_configuration)) + { + try + { + var rawData = dbCtx + .DbSetOrders + .Where(x => x.OrderId==orderId) + .AsNoTracking() + .FirstOrDefault(); + if(rawData!=null) + { + dbResult = rawData; + } + } + catch (Exception exc) + { + Log.Error($"Error in OrderGetByKey:{Environment.NewLine}{exc}"); + } + } + return dbResult; + } + /// /// Remove order /// diff --git a/WebDoorCreator.Data/Services/WebDoorCreatorService.cs b/WebDoorCreator.Data/Services/WebDoorCreatorService.cs index a2d0580..ccead86 100644 --- a/WebDoorCreator.Data/Services/WebDoorCreatorService.cs +++ b/WebDoorCreator.Data/Services/WebDoorCreatorService.cs @@ -620,7 +620,7 @@ namespace WebDoorCreator.Data.Services string source = "DB"; List? dbResult = new List(); // cerco da cache - string currKey = $"{Constants.rKeyOrderDetail}:{orderId}"; + string currKey = $"{Constants.rKeyDoorsByOrder}:{orderId}"; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); string? rawData = await redisDb.StringGetAsync(currKey); @@ -1321,10 +1321,10 @@ namespace WebDoorCreator.Data.Services /// public async Task OrderDetailFlushCache(int OrderId) { - RedisValue pattern = new RedisValue($"{Constants.rKeyOrderDetail}:*"); + RedisValue pattern = new RedisValue($"{Constants.rKeyDoorsByOrder}:*"); if (OrderId > 0) { - pattern = new RedisValue($"{Constants.rKeyOrderDetail}:{OrderId}"); + pattern = new RedisValue($"{Constants.rKeyDoorsByOrder}:{OrderId}"); } bool answ = await ExecFlushRedisPattern(pattern); return answ; @@ -1396,6 +1396,44 @@ namespace WebDoorCreator.Data.Services Log.Debug($"OrderStatusGetFilt | {source} in: {ts.TotalMilliseconds} ms"); return dbResult; } + public async Task OrderGetByKey(int orderId) + { + string source = "DB"; + + OrderModel? dbResult = new OrderModel(); + // cerco da cache + string currKey = $"{Constants.rKeyOrderDetail}:{orderId}";; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + string? rawData = await redisDb.StringGetAsync(currKey); + if (!string.IsNullOrEmpty(rawData)) + { + source = "REDIS"; + var tempResult = JsonConvert.DeserializeObject(rawData); + if (tempResult == null) + { + dbResult = new OrderModel(); + } + else + { + dbResult = tempResult; + } + } + else + { + dbResult = dbController.OrderGetByKey(orderId); + rawData = JsonConvert.SerializeObject(dbResult, JSSettings); + await redisDb.StringSetAsync(currKey, rawData, LongCache); + } + if (dbResult == null) + { + dbResult = new OrderModel(); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"OrderGetByKey | {source} in: {ts.TotalMilliseconds} ms"); + return dbResult; + } /// /// Updating an order status