45cb6b9f59
- aggiunta migrations - correzioni versione ef6 da ef8 - correzioni init varie
163 lines
5.3 KiB
C#
163 lines
5.3 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
using MP.Core.Conf;
|
|
using MP.Data.DbModels;
|
|
using Newtonsoft.Json;
|
|
using NLog;
|
|
using StackExchange.Redis;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Data;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace MP.Data.Services
|
|
{
|
|
/// <summary>
|
|
/// Classe accesso dati ordini
|
|
/// </summary>
|
|
public class OrderDataSrv : BaseServ
|
|
{
|
|
#region Public Constructors
|
|
|
|
public OrderDataSrv(IConfiguration configuration, IConnectionMultiplexer redConn) : base(configuration, redConn)
|
|
{
|
|
// conf DB
|
|
string connStr = _configuration.GetConnectionString("MP.All");
|
|
if (string.IsNullOrEmpty(connStr))
|
|
{
|
|
Log.Error("ConnString empty!");
|
|
}
|
|
else
|
|
{
|
|
dbController = new Controllers.MpSpecController(configuration);
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.AppendLine($"OrderDataSrv | MpSpecController OK");
|
|
Log.Info(sb.ToString());
|
|
}
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Properties
|
|
|
|
public static Controllers.MpSpecController dbController { get; set; } = null!;
|
|
|
|
#endregion Public Properties
|
|
|
|
#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 = dbController.ConfigGetAll();
|
|
// serializzo e salvo...
|
|
rawData = JsonConvert.SerializeObject(result);
|
|
_redisDb.StringSet(currKey, rawData, LongCache);
|
|
}
|
|
if (result == null)
|
|
{
|
|
result = new List<ConfigModel>();
|
|
}
|
|
sw.Stop();
|
|
Log.Debug($"ConfigGetAll | {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 Task.FromResult(dbController.ListODLFilt(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($"ListODLFilt | 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)
|
|
{
|
|
if (disposing)
|
|
{
|
|
// Free managed resources here
|
|
dbController.Dispose();
|
|
}
|
|
|
|
// Free unmanaged resources here
|
|
_disposed = true;
|
|
}
|
|
|
|
// Call base class implementation.
|
|
base.Dispose(disposing);
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
|
private bool _disposed = false;
|
|
private string redisBaseKey = "MP:ALL:Cache";
|
|
|
|
#endregion Private Fields
|
|
}
|
|
} |