9055eaf73c
- aggiunta pagina operatori - completato fix
147 lines
4.9 KiB
C#
147 lines
4.9 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
using MP.Core.Objects;
|
|
using MP.Data.DbModels;
|
|
using MP.Data.Repository.Production;
|
|
using MP.Data.Repository.System;
|
|
using Newtonsoft.Json;
|
|
using NLog;
|
|
using StackExchange.Redis;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using ZiggyCreatures.Caching.Fusion;
|
|
|
|
namespace MP.Data.Services
|
|
{
|
|
/// <summary>
|
|
/// Classe accesso dati ordini
|
|
/// </summary>
|
|
public class OrderDataSrv : BaseServ
|
|
{
|
|
#region Private Fields
|
|
|
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
|
private readonly IProductionRepository _productionRepository;
|
|
private readonly ISystemRepository _systemRepository;
|
|
private bool _disposed = false;
|
|
private string redisBaseKey = "MP:ALL:Cache";
|
|
|
|
#endregion
|
|
|
|
#region Public Constructors
|
|
|
|
public OrderDataSrv(
|
|
IConfiguration configuration,
|
|
IConnectionMultiplexer redConn,
|
|
IFusionCache cache,
|
|
IProductionRepository productionRepository,
|
|
ISystemRepository systemRepository
|
|
) : base(configuration, cache, redConn)
|
|
{
|
|
_productionRepository = productionRepository;
|
|
_systemRepository = systemRepository;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// Recupero elenco config
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<List<ConfigModel>> ConfigGetAll()
|
|
{
|
|
string source = "DB";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
List<ConfigModel>? result = new List<ConfigModel>();
|
|
// cerco in _redisConn...
|
|
string currKey = $"{redisBaseKey}:Conf";
|
|
RedisValue rawData = await _redisDb.StringGetAsync(currKey);
|
|
//if (!string.IsNullOrEmpty($"{rawData}"))
|
|
if (rawData.HasValue)
|
|
{
|
|
result = JsonConvert.DeserializeObject<List<ConfigModel>>($"{rawData}");
|
|
source = "REDIS";
|
|
}
|
|
else
|
|
{
|
|
result = await _systemRepository.ConfigGetAllAsync();
|
|
// serializzo e salvo...
|
|
rawData = JsonConvert.SerializeObject(result);
|
|
_redisDb.StringSet(currKey, rawData, LongCache);
|
|
}
|
|
if (result == null)
|
|
{
|
|
result = new List<ConfigModel>();
|
|
}
|
|
sw.Stop();
|
|
Log.Debug($"ConfigGetAllAsync | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco ODL filtrati x articolo e macchina
|
|
/// </summary>
|
|
/// <param name="CodArt">Cod articolo</param>
|
|
/// <param name="IdxMacchina">Macchina selezionata</param>
|
|
/// <returns></returns>
|
|
public async Task<List<ODLExpModel>> ListODLFilt(string CodArt, string IdxMacchina = "*")
|
|
{
|
|
// setup parametri costanti
|
|
bool inCorso = false;
|
|
string keyRichPart = "*";
|
|
string Reparto = "*";
|
|
DateTime startDate = new DateTime(2000, 1, 1);
|
|
DateTime endDate = DateTime.Today.AddDays(1);
|
|
string source = "DB";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
List<ODLExpModel>? result = new List<ODLExpModel>();
|
|
// cerco in _redisConn...
|
|
string currKey = $"{redisBaseKey}:ODL:{IdxMacchina}:{CodArt}";
|
|
RedisValue rawData = await _redisDb.StringGetAsync(currKey);
|
|
//if (!string.IsNullOrEmpty($"{rawData}"))
|
|
if (rawData.HasValue)
|
|
{
|
|
result = JsonConvert.DeserializeObject<List<ODLExpModel>>($"{rawData}");
|
|
source = "REDIS";
|
|
}
|
|
else
|
|
{
|
|
result = await _productionRepository.ListODLFiltAsync(inCorso, CodArt, keyRichPart, Reparto, IdxMacchina, startDate, endDate);
|
|
// serializzp e salvo...
|
|
rawData = JsonConvert.SerializeObject(result);
|
|
await _redisDb.StringSetAsync(currKey, rawData, LongCache);
|
|
}
|
|
if (result == null)
|
|
{
|
|
result = new List<ODLExpModel>();
|
|
}
|
|
sw.Stop();
|
|
Log.Debug($"ListODLFiltAsync | CodArt: {CodArt} | IdxMacchina: {IdxMacchina} | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
|
return result;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Methods
|
|
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
if (!_disposed)
|
|
{
|
|
// Free unmanaged resources here
|
|
_disposed = true;
|
|
}
|
|
|
|
// Call base class implementation.
|
|
base.Dispose(disposing);
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
}
|
|
} |