2560 lines
102 KiB
C#
2560 lines
102 KiB
C#
using EgwCoreLib.Lux.Core.Generic;
|
|
using EgwCoreLib.Lux.Core.RestPayload;
|
|
using EgwCoreLib.Lux.Data.Controllers;
|
|
using EgwCoreLib.Lux.Data.DbModel.Config;
|
|
using EgwCoreLib.Lux.Data.DbModel.Cost;
|
|
using EgwCoreLib.Lux.Data.DbModel.Items;
|
|
using EgwCoreLib.Lux.Data.DbModel.Production;
|
|
using EgwCoreLib.Lux.Data.DbModel.Sales;
|
|
using EgwCoreLib.Lux.Data.DbModel.Task;
|
|
using EgwCoreLib.Lux.Data.DbModel.Utils;
|
|
using EgwMultiEngineManager.Data;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Newtonsoft.Json;
|
|
using NLog;
|
|
using StackExchange.Redis;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.Design;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Resources;
|
|
using System.Security.Cryptography;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using static EgwCoreLib.Lux.Core.Enums;
|
|
using static System.Runtime.InteropServices.JavaScript.JSType;
|
|
|
|
namespace EgwCoreLib.Lux.Data.Services
|
|
{
|
|
public class DataLayerServices : BaseServ
|
|
{
|
|
#region Public Constructors
|
|
|
|
public DataLayerServices(IConfiguration configuration, IConnectionMultiplexer RedisConn) : base(configuration, RedisConn)
|
|
{
|
|
// conf DB
|
|
string connStr = BaseServ._config.GetConnectionString("Lux.All") ?? "";
|
|
if (string.IsNullOrEmpty(connStr))
|
|
{
|
|
Log.Error("ConnString empty!");
|
|
}
|
|
else
|
|
{
|
|
StringBuilder sb = new StringBuilder();
|
|
//dbController = new Controllers.LuxController(_config);
|
|
dbController = new LuxController();
|
|
sb.AppendLine($"LuxController OK");
|
|
dataSimController = new DataSimulatorController();
|
|
sb.AppendLine($"DataSimController OK");
|
|
sb.AppendLine($"LuxController OK");
|
|
Log.Info(sb.ToString());
|
|
}
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// Sistema gli item che mancassero di ItemID leggendo da DB
|
|
/// </summary>
|
|
/// <param name="listOrg"></param>
|
|
/// <returns></returns>
|
|
public List<BomItemDTO> BomFixItemId(List<BomItemDTO> listOrg)
|
|
{
|
|
List<BomItemDTO> listFix = listOrg;
|
|
// sistemo ItemID per gli item della BOM...
|
|
var listItemDB = dbController.ItemGetFilt("", ItemClassType.Bom);
|
|
// cerco i record da sistemare ed 1:1 li fixo...
|
|
foreach (var item in listFix.Where(x => x.ItemID == 0))
|
|
{
|
|
var dbRec = listItemDB.FirstOrDefault(x => x.ExtItemCode == item.ItemCode);
|
|
if ((dbRec != null))
|
|
{
|
|
item.ItemID = dbRec.ItemID;
|
|
}
|
|
}
|
|
return listFix;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco completo Config Envir
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<List<EnvirParamModel>> ConfEnvirParamGetAllAsync()
|
|
{
|
|
string source = "DB";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
List<EnvirParamModel>? result = new List<EnvirParamModel>();
|
|
// cerco in redis...
|
|
string currKey = $"{redisBaseKey}:ConfEnvir";
|
|
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
|
if (rawData.HasValue)
|
|
{
|
|
result = JsonConvert.DeserializeObject<List<EnvirParamModel>>($"{rawData}");
|
|
source = "REDIS";
|
|
}
|
|
else
|
|
{
|
|
result = await dbController.ConfEnvirParamGetAllAsync();
|
|
// serializzo e salvo con config x evitare loop...
|
|
rawData = JsonConvert.SerializeObject(result, JSSettings);
|
|
await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
|
|
}
|
|
if (result == null)
|
|
{
|
|
result = new List<EnvirParamModel>();
|
|
}
|
|
sw.Stop();
|
|
Log.Debug($"ConfEnvirParamGetAllAsync | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Esegue eliminazione + refresh cache
|
|
/// </summary>
|
|
/// <param name="selRec"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> ConfGlassDeleteAsync(GlassModel selRec)
|
|
{
|
|
bool result = await dbController.ConfGlassDeleteAsync(selRec);
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:ConfGlass");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco completo Config Glass
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<List<GlassModel>> ConfGlassGetAllAsync()
|
|
{
|
|
string source = "DB";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
List<GlassModel>? result = new List<GlassModel>();
|
|
// cerco in redis...
|
|
string currKey = $"{redisBaseKey}:ConfGlass";
|
|
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
|
if (rawData.HasValue)
|
|
{
|
|
result = JsonConvert.DeserializeObject<List<GlassModel>>($"{rawData}");
|
|
source = "REDIS";
|
|
}
|
|
else
|
|
{
|
|
result = await dbController.ConfGlassGetAllAsync();
|
|
// serializzo e salvo con config x evitare loop...
|
|
rawData = JsonConvert.SerializeObject(result, JSSettings);
|
|
await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
|
|
}
|
|
if (result == null)
|
|
{
|
|
result = new List<GlassModel>();
|
|
}
|
|
sw.Stop();
|
|
Log.Debug($"ConfGlassGetAllAsync | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Esegue Upsert del record ricevuto
|
|
/// </summary>
|
|
/// <param name="upsRec"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> ConfGlassUpsertAsync(GlassModel upsRec)
|
|
{
|
|
bool result = await dbController.ConfGlassUpsertAsync(upsRec);
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:ConfGlass");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Esegue eliminazione + refresh cache
|
|
/// </summary>
|
|
/// <param name="selRec"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> ConfProfileDeleteAsync(ProfileModel selRec)
|
|
{
|
|
bool result = await dbController.ConfProfileDeleteAsync(selRec);
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:ConfProfile");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco completo Config Profile
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[Obsolete("Superato da gestione profili direttametne dal Calc")]
|
|
public async Task<List<ProfileModel>> ConfProfileGetAllAsync()
|
|
{
|
|
string source = "DB";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
List<ProfileModel>? result = new List<ProfileModel>();
|
|
// cerco in redis...
|
|
string currKey = $"{redisBaseKey}:ConfProfile";
|
|
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
|
if (rawData.HasValue)
|
|
{
|
|
result = JsonConvert.DeserializeObject<List<ProfileModel>>($"{rawData}");
|
|
source = "REDIS";
|
|
}
|
|
else
|
|
{
|
|
result = await dbController.ConfProfileGetAllAsync();
|
|
// serializzo e salvo con config x evitare loop...
|
|
rawData = JsonConvert.SerializeObject(result, JSSettings);
|
|
await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
|
|
}
|
|
if (result == null)
|
|
{
|
|
result = new List<ProfileModel>();
|
|
}
|
|
sw.Stop();
|
|
Log.Debug($"ConfProfileGetAllAsync | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Esegue Upsert del record ricevuto
|
|
/// </summary>
|
|
/// <param name="upsRec"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> ConfProfileUpsertAsync(ProfileModel upsRec)
|
|
{
|
|
bool result = await dbController.ConfProfileUpsertAsync(upsRec);
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:ConfProfile");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Esegue eliminazione + refresh cache
|
|
/// </summary>
|
|
/// <param name="selRec"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> ConfWoodDeleteAsync(WoodModel selRec)
|
|
{
|
|
bool result = await dbController.ConfWoodDeleteAsync(selRec);
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:ConfWood");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco completo Config Wood
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<List<WoodModel>> ConfWoodGetAllAsync()
|
|
{
|
|
string source = "DB";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
List<WoodModel>? result = new List<WoodModel>();
|
|
// cerco in redis...
|
|
string currKey = $"{redisBaseKey}:ConfWood";
|
|
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
|
if (rawData.HasValue)
|
|
{
|
|
result = JsonConvert.DeserializeObject<List<WoodModel>>($"{rawData}");
|
|
source = "REDIS";
|
|
}
|
|
else
|
|
{
|
|
result = await dbController.ConfWoodGetAllAsync();
|
|
// serializzo e salvo con config x evitare loop...
|
|
rawData = JsonConvert.SerializeObject(result, JSSettings);
|
|
await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
|
|
}
|
|
if (result == null)
|
|
{
|
|
result = new List<WoodModel>();
|
|
}
|
|
sw.Stop();
|
|
Log.Debug($"ConfWoodGetAllAsync | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Esegue Upsert del record ricevuto
|
|
/// </summary>
|
|
/// <param name="upsRec"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> ConfWoodUpsertAsync(WoodModel upsRec)
|
|
{
|
|
bool result = await dbController.ConfWoodUpsertAsync(upsRec);
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:ConfWood");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco cost drivers
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<List<CostDriverModel>> CostDriverGetAllAsync()
|
|
{
|
|
string source = "DB";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
List<CostDriverModel>? result = new List<CostDriverModel>();
|
|
// cerco in redis...
|
|
string currKey = $"{redisBaseKey}:CostDrivers:ALL";
|
|
RedisValue rawData = redisDb.StringGet(currKey);
|
|
if (rawData.HasValue)
|
|
{
|
|
result = JsonConvert.DeserializeObject<List<CostDriverModel>>($"{rawData}");
|
|
source = "REDIS";
|
|
}
|
|
else
|
|
{
|
|
result = await dbController.CostDriverGetAllAsync();
|
|
// serializzo e salvo...
|
|
rawData = JsonConvert.SerializeObject(result);
|
|
redisDb.StringSet(currKey, rawData, UltraLongCache);
|
|
}
|
|
if (result == null)
|
|
{
|
|
result = new List<CostDriverModel>();
|
|
}
|
|
sw.Stop();
|
|
Log.Debug($"CostDriverGetAllAsync | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco completo Customers
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<CustomerModel> CustomersGetAll()
|
|
{
|
|
string source = "DB";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
List<CustomerModel>? result = new List<CustomerModel>();
|
|
// cerco in redis...
|
|
string currKey = $"{redisBaseKey}:Customers:ALL";
|
|
RedisValue rawData = redisDb.StringGet(currKey);
|
|
if (rawData.HasValue)
|
|
{
|
|
result = JsonConvert.DeserializeObject<List<CustomerModel>>($"{rawData}");
|
|
source = "REDIS";
|
|
}
|
|
else
|
|
{
|
|
result = dbController.CustomersGetAll();
|
|
// serializzo e salvo...
|
|
rawData = JsonConvert.SerializeObject(result);
|
|
redisDb.StringSet(currKey, rawData, UltraLongCache);
|
|
}
|
|
if (result == null)
|
|
{
|
|
result = new List<CustomerModel>();
|
|
}
|
|
sw.Stop();
|
|
Log.Debug($"CustomersGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco completo dealers
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<DealerModel> DealersGetAll()
|
|
{
|
|
string source = "DB";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
List<DealerModel>? result = new List<DealerModel>();
|
|
// cerco in redis...
|
|
string currKey = $"{redisBaseKey}:Dealers:ALL";
|
|
RedisValue rawData = redisDb.StringGet(currKey);
|
|
if (rawData.HasValue)
|
|
{
|
|
result = JsonConvert.DeserializeObject<List<DealerModel>>($"{rawData}");
|
|
source = "REDIS";
|
|
}
|
|
else
|
|
{
|
|
result = dbController.DealersGetAll();
|
|
// serializzo e salvo...
|
|
rawData = JsonConvert.SerializeObject(result);
|
|
redisDb.StringSet(currKey, rawData, LongCache);
|
|
}
|
|
if (result == null)
|
|
{
|
|
result = new List<DealerModel>();
|
|
}
|
|
sw.Stop();
|
|
Log.Debug($"DealersGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Reset completo cache sistema
|
|
/// </summary>
|
|
public bool FlushCache()
|
|
{
|
|
bool answ = false;
|
|
Stopwatch stopWatch = new Stopwatch();
|
|
stopWatch.Start();
|
|
RedisValue pattern = new RedisValue($"{redisBaseKey}:*");
|
|
answ = ExecFlushRedisPattern(pattern);
|
|
stopWatch.Stop();
|
|
Log.Debug($"FlushCache in {stopWatch.Elapsed.TotalMilliseconds} ms");
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Reset completo cache sistema modalità async
|
|
/// </summary>
|
|
public async Task<bool> FlushCacheAsync()
|
|
{
|
|
bool answ = false;
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
RedisValue pattern = new RedisValue($"{redisBaseKey}:*");
|
|
answ = await ExecFlushRedisPatternAsync(pattern);
|
|
sw.Stop();
|
|
Log.Debug($"FlushCacheAsync in {sw.Elapsed.TotalMilliseconds} ms");
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Reset cache sistema x Offerte modalità async
|
|
/// </summary>
|
|
public async Task<bool> FlushCacheOffersAsync()
|
|
{
|
|
bool answ = false;
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:Offers:*");
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OfferRows:*");
|
|
sw.Stop();
|
|
Log.Debug($"FlushCacheOffersAsync in {sw.Elapsed.TotalMilliseconds} ms");
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Reset cache sistema x Ordini modalità async
|
|
/// </summary>
|
|
public async Task<bool> FlushCacheOrdersAsync()
|
|
{
|
|
bool answ = false;
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:Orders:*");
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OrderRows:*");
|
|
sw.Stop();
|
|
Log.Debug($"FlushCacheOrdersAsync in {sw.Elapsed.TotalMilliseconds} ms");
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Esegue eliminazione + refresh cache
|
|
/// </summary>
|
|
/// <param name="selRec"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> GenClassDeleteAsync(GenClassModel selRec)
|
|
{
|
|
bool result = await dbController.GenClassDeleteAsync(selRec);
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:GenClass");
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:GenVal:*");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco completo GenClass
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<List<GenClassModel>> GenClassGetAllAsync()
|
|
{
|
|
string source = "DB";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
List<GenClassModel>? result = new List<GenClassModel>();
|
|
// cerco in redis...
|
|
string currKey = $"{redisBaseKey}:GenClass";
|
|
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
|
if (rawData.HasValue)
|
|
{
|
|
result = JsonConvert.DeserializeObject<List<GenClassModel>>($"{rawData}");
|
|
source = "REDIS";
|
|
}
|
|
else
|
|
{
|
|
result = await dbController.GenClassGetAllAsync();
|
|
// serializzo e salvo con config x evitare loop...
|
|
rawData = JsonConvert.SerializeObject(result, JSSettings);
|
|
await redisDb.StringSetAsync(currKey, rawData, LongCache);
|
|
}
|
|
if (result == null)
|
|
{
|
|
result = new List<GenClassModel>();
|
|
}
|
|
sw.Stop();
|
|
Log.Debug($"GenClassGetAllAsync | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Esegue Upsert del record ricevuto
|
|
/// </summary>
|
|
/// <param name="upsRec"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> GenClassUpsertAsync(GenClassModel upsRec)
|
|
{
|
|
bool result = await dbController.GenClassUpsertAsync(upsRec);
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:GenClass");
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:GenVal:*");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Esegue eliminazione + refresh cache
|
|
/// </summary>
|
|
/// <param name="selRec"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> GenValDeleteAsync(GenValueModel selRec)
|
|
{
|
|
bool result = await dbController.GenValDeleteAsync(selRec);
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:GenClass");
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:GenVal:*");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco valori x classe richiesta
|
|
/// </summary>
|
|
/// <param name="codClass"></param>
|
|
/// <returns></returns>
|
|
public async Task<List<GenValueModel>> GenValGetFiltAsync(string codClass)
|
|
{
|
|
string source = "DB";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
List<GenValueModel>? result = new List<GenValueModel>();
|
|
// cerco in redis...
|
|
string currKey = $"{redisBaseKey}:GenVal:{codClass}";
|
|
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
|
if (rawData.HasValue)
|
|
{
|
|
result = JsonConvert.DeserializeObject<List<GenValueModel>>($"{rawData}");
|
|
source = "REDIS";
|
|
}
|
|
else
|
|
{
|
|
result = await dbController.GenValGetFiltAsync(codClass);
|
|
// serializzo e salvo con config x evitare loop...
|
|
rawData = JsonConvert.SerializeObject(result, JSSettings);
|
|
await redisDb.StringSetAsync(currKey, rawData, LongCache);
|
|
}
|
|
if (result == null)
|
|
{
|
|
result = new List<GenValueModel>();
|
|
}
|
|
sw.Stop();
|
|
Log.Debug($"GenValGetFiltAsync | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Esegue spostamento nell'ordinamento relativo alla classe + refresh cache
|
|
/// </summary>
|
|
/// <param name="selRec"></param>
|
|
/// <param name="moveUp"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> GenValMoveAsync(GenValueModel selRec, bool moveUp)
|
|
{
|
|
bool result = await dbController.GenValMoveAsync(selRec, moveUp);
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:GenClass");
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:GenVal:*");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Esegue Upsert del record ricevuto
|
|
/// </summary>
|
|
/// <param name="upsRec"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> GenValUpsertAsync(GenValueModel upsRec)
|
|
{
|
|
bool result = await dbController.GenValUpsertAsync(upsRec);
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:GenClass");
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:GenVal:*");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Eliminazione record item
|
|
/// </summary>
|
|
/// <param name="rec2del"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> ItemDeleteAsync(ItemModel rec2del)
|
|
{
|
|
bool result = await dbController.ItemDeleteAsync(rec2del);
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:Item:*");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco item alternativi x sostituzione in preventivo, ovvero
|
|
/// - sono item "child" di un parent record
|
|
/// - condividono lo stesso parent record
|
|
/// </summary>
|
|
/// <param name="ItemId">ID ite corrente (valido quindi >0)</param>
|
|
/// <returns></returns>
|
|
public List<ItemModel> ItemGetAlt(int ItemId)
|
|
{
|
|
string source = "DB";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
List<ItemModel>? result = new List<ItemModel>();
|
|
// cerco in redis...
|
|
string currKey = $"{redisBaseKey}:Item:ListAlt:{ItemId}";
|
|
RedisValue rawData = redisDb.StringGet(currKey);
|
|
if (rawData.HasValue)
|
|
{
|
|
result = JsonConvert.DeserializeObject<List<ItemModel>>($"{rawData}");
|
|
source = "REDIS";
|
|
}
|
|
else
|
|
{
|
|
result = dbController.ItemGetAlt(ItemId);
|
|
// serializzo e salvo con config x evitare loop...
|
|
rawData = JsonConvert.SerializeObject(result, JSSettings);
|
|
redisDb.StringSet(currKey, rawData, FastCache);
|
|
}
|
|
if (result == null)
|
|
{
|
|
result = new List<ItemModel>();
|
|
}
|
|
sw.Stop();
|
|
Log.Debug($"ItemGetAlt | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco item da ricerca completa Async
|
|
/// </summary>
|
|
/// <param name="CodGroup"></param>
|
|
/// <param name="ItemType"></param>
|
|
/// <returns></returns>
|
|
public async Task<List<ItemModel>> ItemGetFiltAsync(string CodGroup, ItemClassType ItemType)
|
|
{
|
|
string source = "DB";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
List<ItemModel>? result = new List<ItemModel>();
|
|
// cerco in redis...
|
|
string groupTok = string.IsNullOrEmpty(CodGroup) ? "ALL" : CodGroup;
|
|
string currKey = $"{redisBaseKey}:Item:Filt:{groupTok}:{ItemType}";
|
|
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
|
if (rawData.HasValue)
|
|
{
|
|
result = JsonConvert.DeserializeObject<List<ItemModel>>($"{rawData}");
|
|
source = "REDIS";
|
|
}
|
|
else
|
|
{
|
|
result = await dbController.ItemGetFiltAsync(CodGroup, ItemType);
|
|
// serializzo e salvo con config x evitare loop...
|
|
rawData = JsonConvert.SerializeObject(result, JSSettings);
|
|
await redisDb.StringSetAsync(currKey, rawData, LongCache);
|
|
}
|
|
if (result == null)
|
|
{
|
|
result = new List<ItemModel>();
|
|
}
|
|
sw.Stop();
|
|
Log.Debug($"ItemGetFiltAsync | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco item da ricerca async
|
|
/// </summary>
|
|
/// <param name="term"></param>
|
|
/// <returns></returns>
|
|
public async Task<List<ItemModel>> ItemGetSearchAsync(string term)
|
|
{
|
|
string source = "DB";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
List<ItemModel>? result = new List<ItemModel>();
|
|
// cerco in redis...
|
|
string token = string.IsNullOrEmpty(term) ? "ALL" : term;
|
|
string currKey = $"{redisBaseKey}:Item:Search:{token}";
|
|
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
|
if (rawData.HasValue)
|
|
{
|
|
result = JsonConvert.DeserializeObject<List<ItemModel>>($"{rawData}");
|
|
source = "REDIS";
|
|
}
|
|
else
|
|
{
|
|
result = await dbController.ItemGetSearchAsync(term);
|
|
// serializzo e salvo con config x evitare loop...
|
|
rawData = JsonConvert.SerializeObject(result, JSSettings);
|
|
await redisDb.StringSetAsync(currKey, rawData, LongCache);
|
|
}
|
|
if (result == null)
|
|
{
|
|
result = new List<ItemModel>();
|
|
}
|
|
sw.Stop();
|
|
Log.Debug($"ItemGetSearchAsync | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco completo ItemGroup gestiti
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<List<ItemGroupModel>> ItemGroupGetAllAsync()
|
|
{
|
|
string source = "DB";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
List<ItemGroupModel>? result = new List<ItemGroupModel>();
|
|
// cerco in redis...
|
|
string currKey = $"{redisBaseKey}:ItemGroup:ALL";
|
|
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
|
if (rawData.HasValue)
|
|
{
|
|
result = JsonConvert.DeserializeObject<List<ItemGroupModel>>($"{rawData}");
|
|
source = "REDIS";
|
|
}
|
|
else
|
|
{
|
|
result = await dbController.ItemGroupGetAllAsync();
|
|
// serializzo e salvo con config x evitare loop...
|
|
rawData = JsonConvert.SerializeObject(result, JSSettings);
|
|
await redisDb.StringSetAsync(currKey, rawData, LongCache);
|
|
}
|
|
if (result == null)
|
|
{
|
|
result = new List<ItemGroupModel>();
|
|
}
|
|
sw.Stop();
|
|
Log.Debug($"ItemGroupGetAllAsync | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Esecuzione mass update di un set di item cui manca pezzo/quantità max
|
|
/// </summary>
|
|
/// <param name="list2upd"></param>
|
|
/// <param name="setCost"></param>
|
|
/// <param name="defMargin"></param>
|
|
/// <param name="defQtyMax"></param>
|
|
/// <param name="defUM">Valore UM da impostare per tutti</param>
|
|
/// <param name="roundVal"></param>
|
|
/// <param name="scaleFactor">Valore di scala da unità in ingresso x unità di costo (mm x mm x m --> m3)</param>
|
|
/// <returns></returns>
|
|
public async Task<bool> ItemMassUpdate(List<BomItemDTO> list2upd, double setCost, double defMargin, double defQtyMax, string defUM, int roundVal = 0, double scaleFactor = 1_000_000.0)
|
|
{
|
|
bool result = await dbController.ItemMassUpdate(list2upd, setCost, defMargin, defQtyMax, defUM, roundVal, scaleFactor);
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:Item:*");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Update / Insert record item
|
|
/// </summary>
|
|
/// <param name="currRec"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> ItemUpsertAsync(ItemModel currRec)
|
|
{
|
|
bool result = await dbController.ItemUpsertAsync(currRec);
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:Item:*");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Esegue eliminazione + refresh cache
|
|
/// </summary>
|
|
/// <param name="rec2del"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> JobStepDeleteAsync(JobStepModel rec2del)
|
|
{
|
|
bool result = await dbController.JobStepDeleteAsync(rec2del);
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:JobTaskList:*");
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:JobStep:*");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco JobStep dato JobID parent
|
|
/// </summary>
|
|
/// <param name="jobID"></param>
|
|
/// <returns></returns>
|
|
public async Task<List<JobStepModel>> JobStepGetAsync(int jobID)
|
|
{
|
|
string source = "DB";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
List<JobStepModel>? result = new List<JobStepModel>();
|
|
// cerco in redis...
|
|
string currKey = $"{redisBaseKey}:JobStep:{jobID}";
|
|
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
|
if (rawData.HasValue)
|
|
{
|
|
result = JsonConvert.DeserializeObject<List<JobStepModel>>($"{rawData}");
|
|
source = "REDIS";
|
|
}
|
|
else
|
|
{
|
|
result = await dbController.JobStepGetAsync(jobID);
|
|
// serializzo e salvo con config x evitare loop...
|
|
rawData = JsonConvert.SerializeObject(result, JSSettings);
|
|
await redisDb.StringSetAsync(currKey, rawData, LongCache);
|
|
}
|
|
if (result == null)
|
|
{
|
|
result = new List<JobStepModel>();
|
|
}
|
|
sw.Stop();
|
|
Log.Debug($"JobStepGetAsync | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Esegue Upsert del record ricevuto
|
|
/// </summary>
|
|
/// <param name="currRec"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> JobStepUpsertAsync(JobStepModel currRec)
|
|
{
|
|
bool result = await dbController.JobStepUpsertAsync(currRec);
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:JobTaskList:*");
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:JobStep:*");
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:Resources:*");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Esegue Upsert info Tag associati
|
|
/// </summary>
|
|
/// <param name="JobID"></param>
|
|
/// <param name="reqTagList"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> JobTask2TagsUpsertAsync(int JobID, List<string> reqTagList)
|
|
{
|
|
bool result = await dbController.JobTask2TagsUpsertAsync(JobID, reqTagList);
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:JobTaskList:*");
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:JobStep:*");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Esegue eliminazione + refresh cache
|
|
/// </summary>
|
|
/// <param name="rec2del"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> JobTaskDeleteAsync(JobTaskModel rec2del)
|
|
{
|
|
bool result = await dbController.JobTaskDeleteAsync(rec2del);
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:JobTaskList:*");
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:JobStep:*");
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:Resources:*");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco completo Job gestiti
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<List<JobTaskModel>> JobTaskGetAllAsync()
|
|
{
|
|
string source = "DB";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
List<JobTaskModel>? result = new List<JobTaskModel>();
|
|
// cerco in redis...
|
|
string currKey = $"{redisBaseKey}:JobTaskList:ALL";
|
|
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
|
if (rawData.HasValue)
|
|
{
|
|
result = JsonConvert.DeserializeObject<List<JobTaskModel>>($"{rawData}");
|
|
source = "REDIS";
|
|
}
|
|
else
|
|
{
|
|
result = await dbController.JobTaskGetAllAsync();
|
|
// serializzo e salvo con config x evitare loop...
|
|
rawData = JsonConvert.SerializeObject(result, JSSettings);
|
|
await redisDb.StringSetAsync(currKey, rawData, LongCache);
|
|
}
|
|
if (result == null)
|
|
{
|
|
result = new List<JobTaskModel>();
|
|
}
|
|
sw.Stop();
|
|
Log.Debug($"JobTaskGetAllAsync | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Esegue spostamento nell'ordinamento relativo alla classe + refresh cache
|
|
/// </summary>
|
|
/// <param name="selRec"></param>
|
|
/// <param name="moveUp"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> JobTaskMoveAsync(JobTaskModel selRec, bool moveUp)
|
|
{
|
|
bool result = await dbController.JobTaskMoveAsync(selRec, moveUp);
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:JobTaskList:*");
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:JobStep:*");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Esegue Upsert del record ricevuto
|
|
/// </summary>
|
|
/// <param name="currRec"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> JobTaskUpsertAsync(JobTaskModel currRec)
|
|
{
|
|
bool result = await dbController.JobTaskUpsertAsync(currRec);
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:JobTaskList:*");
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:JobStep:*");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Esegue clone completo dell'offerta indicata e svuota la cache
|
|
/// </summary>
|
|
/// <param name="rec2clone"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> OfferClone(OfferModel rec2clone)
|
|
{
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
// calcolo
|
|
bool fatto = await dbController.OfferClone(rec2clone);
|
|
// svuoto cache...
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:Offers:*");
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OfferRows:*");
|
|
sw.Stop();
|
|
Log.Debug($"OfferClone in {sw.Elapsed.TotalMilliseconds} ms");
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco completo offerte da DB
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<List<OfferModel>> OfferGetAll()
|
|
{
|
|
string source = "DB";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
List<OfferModel>? result = new List<OfferModel>();
|
|
// cerco in redis...
|
|
string currKey = $"{redisBaseKey}:Offers:ALL";
|
|
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
|
//if (!string.IsNullOrEmpty($"{rawData}"))
|
|
if (rawData.HasValue)
|
|
{
|
|
result = JsonConvert.DeserializeObject<List<OfferModel>>($"{rawData}");
|
|
source = "REDIS";
|
|
}
|
|
else
|
|
{
|
|
result = await dbController.OfferGetAll();
|
|
// serializzo e salvo con config x evitare loop...
|
|
rawData = JsonConvert.SerializeObject(result, JSSettings);
|
|
await redisDb.StringSetAsync(currKey, rawData, LongCache);
|
|
}
|
|
if (result == null)
|
|
{
|
|
result = new List<OfferModel>();
|
|
}
|
|
sw.Stop();
|
|
Log.Debug($"OfferGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco offerte da DB filtrate x periodo e stato
|
|
/// </summary>
|
|
/// <param name="inizio"></param>
|
|
/// <param name="fine"></param>
|
|
/// <returns></returns>
|
|
public async Task<List<OfferModel>> OfferGetFilt(DateTime inizio, DateTime fine)
|
|
{
|
|
string source = "DB";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
List<OfferModel>? result = new List<OfferModel>();
|
|
// cerco in redis...
|
|
string currKey = $"{redisBaseKey}:Offers:Filt:{inizio:yyMMdd-HHmm}:{fine:yyMMdd-HHmm}";
|
|
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
|
if (rawData.HasValue)
|
|
{
|
|
result = JsonConvert.DeserializeObject<List<OfferModel>>($"{rawData}");
|
|
source = "REDIS";
|
|
}
|
|
else
|
|
{
|
|
result = await dbController.OfferGetFilt(inizio, fine);
|
|
// serializzo e salvo con config x evitare loop...
|
|
rawData = JsonConvert.SerializeObject(result, JSSettings);
|
|
await redisDb.StringSetAsync(currKey, rawData, LongCache);
|
|
}
|
|
if (result == null)
|
|
{
|
|
result = new List<OfferModel>();
|
|
}
|
|
sw.Stop();
|
|
Log.Debug($"OfferGetFilt | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco righe offerta specificata
|
|
/// </summary>
|
|
/// <param name="OfferID"></param>
|
|
/// <returns></returns>
|
|
public async Task<List<OfferRowModel>> OfferRowGetByOffer(int OfferID)
|
|
{
|
|
string source = "DB";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
List<OfferRowModel>? result = new List<OfferRowModel>();
|
|
// cerco in redis...
|
|
string currKey = $"{redisBaseKey}:OfferRows:{OfferID}";
|
|
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
|
//if (!string.IsNullOrEmpty($"{rawData}"))
|
|
if (rawData.HasValue)
|
|
{
|
|
result = JsonConvert.DeserializeObject<List<OfferRowModel>>($"{rawData}");
|
|
source = "REDIS";
|
|
}
|
|
else
|
|
{
|
|
result = dbController.OfferRowGetByOffer(OfferID);
|
|
// serializzo e salvo...
|
|
rawData = JsonConvert.SerializeObject(result);
|
|
await redisDb.StringSetAsync(currKey, rawData, LongCache);
|
|
}
|
|
if (result == null)
|
|
{
|
|
result = new List<OfferRowModel>();
|
|
}
|
|
sw.Stop();
|
|
Log.Debug($"OfferRowGetByOffer | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Riga Offerta dato suo UID
|
|
/// </summary>
|
|
/// <param name="OfferRowUID"></param>
|
|
/// <returns></returns>
|
|
public async Task<OfferRowModel?> OfferRowGetByUID(string OfferRowUID)
|
|
{
|
|
string source = "DB";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
OfferRowModel? result = null;
|
|
// cerco in redis...
|
|
string currKey = $"{redisBaseKey}:OfferRows:ByUID:{OfferRowUID}";
|
|
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
|
//if (!string.IsNullOrEmpty($"{rawData}"))
|
|
if (rawData.HasValue)
|
|
{
|
|
result = JsonConvert.DeserializeObject<OfferRowModel>($"{rawData}");
|
|
source = "REDIS";
|
|
}
|
|
else
|
|
{
|
|
result = dbController.OfferRowGetByUID(OfferRowUID);
|
|
// serializzo e salvo...
|
|
rawData = JsonConvert.SerializeObject(result);
|
|
await redisDb.StringSetAsync(currKey, rawData, LongCache);
|
|
}
|
|
sw.Stop();
|
|
Log.Debug($"OfferRowGetByUID | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verifica offerte scadute, con update sul DB
|
|
/// </summary>
|
|
public async Task<bool> OffersCheckExpired()
|
|
{
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
// calcolo
|
|
bool fatto = await dbController.OffersCheckExpired();
|
|
// svuoto cache...
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:Offers:*");
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OfferRows:*");
|
|
sw.Stop();
|
|
Log.Debug($"OffersCheckExpired in {sw.Elapsed.TotalMilliseconds} ms");
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converte il campo raw della BOM in lista oggetti da gestire
|
|
/// </summary>
|
|
/// <param name="currRec"></param>
|
|
/// <returns></returns>
|
|
public List<BomItemDTO> OffertGetBomList(OfferRowModel currRec)
|
|
{
|
|
List<BomItemDTO> answ = new List<BomItemDTO>();
|
|
var bomList = JsonConvert.DeserializeObject<List<BomItemDTO>>(currRec.ItemBOM);
|
|
if (bomList != null)
|
|
{
|
|
answ = bomList;
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua eliminazione della Riga Offerta
|
|
/// </summary>
|
|
/// <param name="updRec">Riga Offerta coi dati da aggiornare</param>
|
|
/// <returns></returns>
|
|
public async Task<bool> OffertRowDelete(OfferRowModel updRec)
|
|
{
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
// calcolo
|
|
bool fatto = await dbController.OffertRowDelete(updRec);
|
|
// svuoto cache...
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:Offers:*");
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OfferRows:*");
|
|
sw.Stop();
|
|
Log.Debug($"OffertRowDelete in {sw.Elapsed.TotalMilliseconds} ms");
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua fix UID righe child dell'offerta indicata e restituisce elenco UID da chiamare x refresh
|
|
/// </summary>
|
|
/// <param name="updRec">Key</param>
|
|
/// <returns></returns>
|
|
public async Task<List<string>> OffertRowFixUid(int OffertID)
|
|
{
|
|
List<string> answ = new List<string>();
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
// calcolo
|
|
answ = dbController.OffertRowFixUid(OffertID);
|
|
// svuoto cache...
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:Offers:*");
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OfferRows:*");
|
|
sw.Stop();
|
|
Log.Debug($"OffertRowFixUid in {sw.Elapsed.TotalMilliseconds} ms");
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua update della BOM (e dei costi) di tutte le righe dell'offerta indicata
|
|
/// </summary>
|
|
/// <param name="OfferRowID">ID Riga Offerta da aggiornare</param>
|
|
/// <param name="newBomList">Bom aggiornata da salvare</param>
|
|
/// <returns></returns>
|
|
public async Task<bool> OffertRowUpdateBom(int OfferRowID, List<BomItemDTO> newBomList)
|
|
{
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
// calcolo
|
|
bool fatto = await dbController.OffertRowUpdateBom(OfferRowID, newBomList);
|
|
// svuoto cache...
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:Offers:*");
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OfferRows:*");
|
|
sw.Stop();
|
|
Log.Debug($"OffertRowUpdateBom in {sw.Elapsed.TotalMilliseconds} ms");
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua update delle info legate al file per la Riga Offerta
|
|
/// </summary>
|
|
/// <param name="updRec">Riga Offerta coi dati da aggiornare</param>
|
|
/// <returns></returns>
|
|
public async Task<bool> OffertRowUpdateFileData(OfferRowModel updRec)
|
|
{
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
// calcolo
|
|
bool fatto = await dbController.OffertRowUpdateFileData(updRec);
|
|
// svuoto cache...
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:Offers:*");
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OfferRows:*");
|
|
sw.Stop();
|
|
Log.Debug($"OffertRowUpdateFileData in {sw.Elapsed.TotalMilliseconds} ms");
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua update del valore serializzato della Riga Offerta
|
|
/// </summary>
|
|
/// <param name="OfferRowID">ID Riga Offerta da aggiornare</param>
|
|
/// <param name="serStruct">Serializzazione oggetto (es JWD)</param>
|
|
/// <returns></returns>
|
|
public async Task<bool> OffertRowUpdateSerStruct(int OfferRowID, string serStruct)
|
|
{
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
// calcolo
|
|
bool fatto = await dbController.OffertRowUpdateSerStruct(OfferRowID, serStruct);
|
|
// svuoto cache...
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:Offers:*");
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OfferRows:*");
|
|
sw.Stop();
|
|
Log.Debug($"OffertRowUpdateSerStruct in {sw.Elapsed.TotalMilliseconds} ms");
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua Upsert della Riga Offerta
|
|
/// </summary>
|
|
/// <param name="updRec">Riga Offerta coi dati da aggiornare</param>
|
|
/// <returns></returns>
|
|
public async Task<bool> OffertRowUpsert(OfferRowModel updRec)
|
|
{
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
// calcolo
|
|
bool fatto = await dbController.OffertRowUpsert(updRec);
|
|
if (fatto)
|
|
{
|
|
// sistemo UID...
|
|
await OffertRowFixUid(updRec.OfferID);
|
|
}
|
|
// svuoto cache...
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:Offers:*");
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OfferRows:*");
|
|
sw.Stop();
|
|
Log.Debug($"OffertRowUpsert in {sw.Elapsed.TotalMilliseconds} ms");
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua update stato await BOM/PRICE per l'offerta indicata
|
|
/// </summary>
|
|
/// <param name="offerRowID">ID singola Riga Offerta</param>
|
|
/// <param name="awaitBom">Se non nullo è il nuovo stato await BOM</param>
|
|
/// <param name="awaitPrice">Se non nullo è stato await Price</param>
|
|
/// <param name="flushCache">Indica se svuotare la cache</param>
|
|
/// <returns></returns>
|
|
public async Task<bool> OffertUpdateAwaitState(int offerRowID, bool? awaitBom, bool? awaitPrice, bool flushCache = false)
|
|
{
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
// aggiorno
|
|
bool fatto = await dbController.OffertUpdateAwaitState(offerRowID, awaitBom, awaitPrice);
|
|
if (flushCache)
|
|
{
|
|
// svuoto cache...
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OfferRows:*");
|
|
}
|
|
sw.Stop();
|
|
Log.Debug($"OffertUpdateAwaitState in {sw.Elapsed.TotalMilliseconds} ms");
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua update dei costi di tutte le righe dell'offerta indicata
|
|
/// </summary>
|
|
/// <param name="OfferID">Key</param>
|
|
/// <returns></returns>
|
|
public async Task<bool> OffertUpdateCost(int OfferID)
|
|
{
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
// calcolo
|
|
bool fatto = await dbController.OffertUpdateCost(OfferID);
|
|
// svuoto cache...
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:Offers:*");
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OfferRows:*");
|
|
sw.Stop();
|
|
Log.Debug($"OffertUpdateCost in {sw.Elapsed.TotalMilliseconds} ms");
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua Upsert complessivo record offerta
|
|
/// </summary>
|
|
/// <param name="updRec">Key</param>
|
|
/// <returns></returns>
|
|
public async Task<bool> OffertUpsert(OfferModel updRec)
|
|
{
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
// calcolo
|
|
bool fatto = await dbController.OffertUpsert(updRec);
|
|
// svuoto cache...
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:Offers:*");
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OfferRows:*");
|
|
sw.Stop();
|
|
Log.Debug($"OffertUpsert in {sw.Elapsed.TotalMilliseconds} ms");
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Restituisce record ordine + righe Ordine dato ID
|
|
/// </summary>
|
|
/// <param name="orderId"></param>
|
|
/// <param name="doForce"></param>
|
|
/// <returns></returns>
|
|
public async Task<OrderModel> OrderById(int orderId, bool doForce)
|
|
{
|
|
string source = "DB";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
OrderModel? result = new OrderModel();
|
|
// cerco in redis...
|
|
string currKey = $"{redisBaseKey}:Orders:ById:{orderId}";
|
|
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
|
if (rawData.HasValue && rawData.Length() > 2 && !doForce)
|
|
{
|
|
result = JsonConvert.DeserializeObject<OrderModel>($"{rawData}");
|
|
source = "REDIS";
|
|
}
|
|
else
|
|
{
|
|
result = await dbController.OrderById(orderId);
|
|
// serializzo e salvo con config x evitare loop...
|
|
rawData = JsonConvert.SerializeObject(result, JSSettings);
|
|
await redisDb.StringSetAsync(currKey, rawData, LongCache);
|
|
}
|
|
if (result == null)
|
|
{
|
|
result = new OrderModel();
|
|
}
|
|
sw.Stop();
|
|
Log.Debug($"OrderById | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Genera un nuovo record ordine:
|
|
/// - cloning completo di un offerta + TUTTE le relative righe di offerta + rif offerta
|
|
/// - generazione prodItems x etichette
|
|
/// </summary>
|
|
/// <param name="rec2clone"></param>
|
|
/// <returns></returns>
|
|
public async Task<OrderModel?> OrderFromOffer(OfferModel rec2clone)
|
|
{
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
// calcolo
|
|
OrderModel? newOrd = await dbController.OrderFromOffer(rec2clone);
|
|
if (newOrd != null)
|
|
{
|
|
// svuoto cache...
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:Orders:*");
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OrderRows:*");
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OrderRowsByState:*");
|
|
}
|
|
sw.Stop();
|
|
Log.Debug($"OrderFromOffer in {sw.Elapsed.TotalMilliseconds} ms");
|
|
return newOrd;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converte il campo raw della BOM in lista oggetti da gestire
|
|
/// </summary>
|
|
/// <param name="currRec"></param>
|
|
/// <returns></returns>
|
|
public List<BomItemDTO> OrderGetBomList(OrderRowModel currRec)
|
|
{
|
|
List<BomItemDTO> answ = new List<BomItemDTO>();
|
|
var bomList = JsonConvert.DeserializeObject<List<BomItemDTO>>(currRec.ItemBOM);
|
|
if (bomList != null)
|
|
{
|
|
answ = bomList;
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco ordini da DB filtrate x periodo e stato
|
|
/// </summary>
|
|
/// <param name="inizio"></param>
|
|
/// <param name="fine"></param>
|
|
/// <returns></returns>
|
|
public async Task<List<OrderModel>> OrderGetFilt(DateTime inizio, DateTime fine)
|
|
{
|
|
string source = "DB";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
List<OrderModel>? result = new List<OrderModel>();
|
|
// cerco in redis...
|
|
string currKey = $"{redisBaseKey}:Orders:Filt:{inizio:yyMMdd-HHmm}:{fine:yyMMdd-HHmm}";
|
|
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
|
if (rawData.HasValue)
|
|
{
|
|
result = JsonConvert.DeserializeObject<List<OrderModel>>($"{rawData}");
|
|
source = "REDIS";
|
|
}
|
|
else
|
|
{
|
|
result = await dbController.OrderGetFilt(inizio, fine);
|
|
// serializzo e salvo con config x evitare loop...
|
|
rawData = JsonConvert.SerializeObject(result, JSSettings);
|
|
await redisDb.StringSetAsync(currKey, rawData, LongCache);
|
|
}
|
|
if (result == null)
|
|
{
|
|
result = new List<OrderModel>();
|
|
}
|
|
sw.Stop();
|
|
Log.Debug($"OrderGetFilt | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua eliminazione della riga Ordine
|
|
/// </summary>
|
|
/// <param name="updRec">Riga ordine coi dati da aggiornare</param>
|
|
/// <returns></returns>
|
|
public async Task<bool> OrderRowDelete(OrderRowModel updRec)
|
|
{
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
// calcolo
|
|
bool fatto = await dbController.OrderRowDelete(updRec);
|
|
// svuoto cache...
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:Orders:*");
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OrderRows:*");
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OrderRowsByState:*");
|
|
sw.Stop();
|
|
Log.Debug($"OrderRowDelete in {sw.Elapsed.TotalMilliseconds} ms");
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua fix UID righe child dell'Ordine indicato e restituisce elenco UID da chiamare x refresh
|
|
/// </summary>
|
|
/// <param name="updRec">Key</param>
|
|
/// <returns></returns>
|
|
public async Task<List<string>> OrderRowFixUid(int OrderID)
|
|
{
|
|
List<string> answ = new List<string>();
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
// calcolo
|
|
answ = dbController.OrderRowFixUid(OrderID);
|
|
// svuoto cache...
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:Orders:*");
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OrderRows:*");
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OrderRowsByState:*");
|
|
sw.Stop();
|
|
Log.Debug($"OrderRowFixUid in {sw.Elapsed.TotalMilliseconds} ms");
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco righe Ordine specificato
|
|
/// </summary>
|
|
/// <param name="OrderID"></param>
|
|
/// <returns></returns>
|
|
public async Task<List<OrderRowModel>> OrderRowGetByOffer(int OrderID)
|
|
{
|
|
string source = "DB";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
List<OrderRowModel>? result = new List<OrderRowModel>();
|
|
// cerco in redis...
|
|
string currKey = $"{redisBaseKey}:OrderRows:{OrderID}";
|
|
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
|
//if (!string.IsNullOrEmpty($"{rawData}"))
|
|
if (rawData.HasValue)
|
|
{
|
|
result = JsonConvert.DeserializeObject<List<OrderRowModel>>($"{rawData}");
|
|
source = "REDIS";
|
|
}
|
|
else
|
|
{
|
|
result = dbController.OrderRowGetByOffer(OrderID);
|
|
// serializzo e salvo...
|
|
rawData = JsonConvert.SerializeObject(result);
|
|
await redisDb.StringSetAsync(currKey, rawData, LongCache);
|
|
}
|
|
if (result == null)
|
|
{
|
|
result = new List<OrderRowModel>();
|
|
}
|
|
sw.Stop();
|
|
Log.Debug($"OrderRowGetByOffer | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Fornisce OrderRow da stato
|
|
/// </summary>
|
|
/// <param name="reqState"></param>
|
|
/// <returns></returns>
|
|
public async Task<List<OrderRowModel>> OrderRowGetByState(OrderStates reqState, DateTime dtStart, DateTime dtEnd)
|
|
{
|
|
string source = "DB";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
List<OrderRowModel>? result = new List<OrderRowModel>();
|
|
// cerco in redis...
|
|
string currKey = $"{redisBaseKey}:OrderRows:ByState:{reqState}";
|
|
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
|
//if (!string.IsNullOrEmpty($"{rawData}"))
|
|
if (rawData.HasValue)
|
|
{
|
|
result = JsonConvert.DeserializeObject<List<OrderRowModel>>($"{rawData}");
|
|
source = "REDIS";
|
|
}
|
|
else
|
|
{
|
|
result = dbController.OrderRowGetByState(reqState, dtStart, dtEnd);
|
|
// serializzo e salvo...
|
|
rawData = JsonConvert.SerializeObject(result);
|
|
await redisDb.StringSetAsync(currKey, rawData, FastCache);
|
|
}
|
|
if (result == null)
|
|
{
|
|
result = new List<OrderRowModel>();
|
|
}
|
|
sw.Stop();
|
|
Log.Debug($"OrderRowGetByState | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Fornisce OrderRow da stato
|
|
/// </summary>
|
|
/// <param name="reqState"></param>
|
|
/// <returns></returns>
|
|
public async Task<List<OrderRowModel>> OrderRowGetByStateMin(OrderStates reqState, DateTime dtStart, DateTime dtEnd)
|
|
{
|
|
string source = "DB";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
List<OrderRowModel>? result = new List<OrderRowModel>();
|
|
// cerco in redis...
|
|
string currKey = $"{redisBaseKey}:OrderRows:ByStateMin:{reqState}";
|
|
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
|
//if (!string.IsNullOrEmpty($"{rawData}"))
|
|
if (rawData.HasValue)
|
|
{
|
|
result = JsonConvert.DeserializeObject<List<OrderRowModel>>($"{rawData}");
|
|
source = "REDIS";
|
|
}
|
|
else
|
|
{
|
|
result = dbController.OrderRowGetByStateMin(reqState, dtStart, dtEnd);
|
|
// serializzo e salvo...
|
|
rawData = JsonConvert.SerializeObject(result);
|
|
await redisDb.StringSetAsync(currKey, rawData, FastCache);
|
|
}
|
|
if (result == null)
|
|
{
|
|
result = new List<OrderRowModel>();
|
|
}
|
|
sw.Stop();
|
|
Log.Debug($"OrderRowGetByStateMin | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Riga Ordine dato suo UID
|
|
/// </summary>
|
|
/// <param name="OrderRowUID"></param>
|
|
/// <returns></returns>
|
|
public async Task<OrderRowModel?> OrderRowGetByUID(string OrderRowUID)
|
|
{
|
|
string source = "DB";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
OrderRowModel? result = null;
|
|
// cerco in redis...
|
|
string currKey = $"{redisBaseKey}:OrderRows:ByUID:{OrderRowUID}";
|
|
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
|
//if (!string.IsNullOrEmpty($"{rawData}"))
|
|
if (rawData.HasValue)
|
|
{
|
|
result = JsonConvert.DeserializeObject<OrderRowModel>($"{rawData}");
|
|
source = "REDIS";
|
|
}
|
|
else
|
|
{
|
|
result = dbController.OrderRowGetByUID(OrderRowUID);
|
|
// serializzo e salvo...
|
|
rawData = JsonConvert.SerializeObject(result);
|
|
await redisDb.StringSetAsync(currKey, rawData, LongCache);
|
|
}
|
|
sw.Stop();
|
|
Log.Debug($"OrderRowGetByUID | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Validazione record:
|
|
/// - controllo state vs estimate
|
|
/// - segnala il numero dei record aggiornati
|
|
/// </summary>
|
|
/// <param name="list2chk">Elenco record da verificare</param>
|
|
public async Task<int> OrderRowListValidate(List<OrderRowModel> list2chk)
|
|
{
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
// calcolo
|
|
int numDone = await dbController.OrderRowListValidate(list2chk);
|
|
// svuoto cache...
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:Orders:*");
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OrderRows:*");
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OrderRowsByState:*");
|
|
sw.Stop();
|
|
Log.Debug($"OrderRowListValidate in {sw.Elapsed.TotalMilliseconds} ms");
|
|
return numDone;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua update stato await BOM/PRICE per la riga Ordine indicata
|
|
/// </summary>
|
|
/// <param name="orderRowID">ID singola riga Ordine</param>
|
|
/// <param name="awaitBom">Se non nullo è il nuovo stato await BOM</param>
|
|
/// <param name="awaitPrice">Se non nullo è stato await Price</param>
|
|
/// <param name="flushCache">Indica se svuotare la cache</param>
|
|
/// <returns></returns>
|
|
public async Task<bool> OrderRowUpdateAwaitState(int orderRowID, bool? awaitBom, bool? awaitPrice, bool flushCache = false)
|
|
{
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
// aggiorno
|
|
bool fatto = await dbController.OrderRowUpdateAwaitState(orderRowID, awaitBom, awaitPrice);
|
|
if (flushCache)
|
|
{
|
|
// svuoto cache...
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OrderRows:*");
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OrderRowsByState:*");
|
|
}
|
|
sw.Stop();
|
|
Log.Debug($"OrderRowUpdateAwaitState in {sw.Elapsed.TotalMilliseconds} ms");
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua update delle info legate al file per la Riga Ordine
|
|
/// </summary>
|
|
/// <param name="updRec">Riga Offerta coi dati da aggiornare</param>
|
|
/// <returns></returns>
|
|
public async Task<bool> OrderRowUpdateFileData(OrderRowModel updRec)
|
|
{
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
// calcolo
|
|
bool fatto = await dbController.OrderRowUpdateFileData(updRec);
|
|
// svuoto cache...
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:Orders:*");
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OrderRows:*");
|
|
sw.Stop();
|
|
Log.Debug($"OrderRowUpdateFileData in {sw.Elapsed.TotalMilliseconds} ms");
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua update del valore serializzato della riga Ordine
|
|
/// </summary>
|
|
/// <param name="OrderRowID">ID Riga Ordine da aggiornare</param>
|
|
/// <param name="serStruct">Serializzazione oggetto (es JWD)</param>
|
|
/// <returns></returns>
|
|
public async Task<bool> OrderRowUpdateSerStruct(int OrderRowID, string serStruct)
|
|
{
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
// calcolo
|
|
bool fatto = await dbController.OrderRowUpdateSerStruct(OrderRowID, serStruct);
|
|
// svuoto cache...
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:Orders:*");
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OrderRows:*");
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OrderRowsByState:*");
|
|
sw.Stop();
|
|
Log.Debug($"OrderRowUpdateSerStruct in {sw.Elapsed.TotalMilliseconds} ms");
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Aggiorna stato riga ordine al valore richiesto
|
|
/// </summary>
|
|
/// <param name="orderRowID"></param>
|
|
/// <param name="reqState"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> OrderRowUpdateState(int orderRowID, OrderStates reqState)
|
|
{
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
// calcolo
|
|
bool fatto = await dbController.OrderRowUpdateState(orderRowID, reqState);
|
|
// svuoto cache...
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:Orders:*");
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OrderRows:*");
|
|
sw.Stop();
|
|
Log.Debug($"OrderRowUpdateState in {sw.Elapsed.TotalMilliseconds} ms");
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua Upsert della riga Ordine
|
|
/// </summary>
|
|
/// <param name="updRec">Riga Ordine con i dati da aggiornare</param>
|
|
/// <returns></returns>
|
|
public async Task<bool> OrderRowUpsert(OrderRowModel updRec)
|
|
{
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
// calcolo
|
|
bool fatto = await dbController.OrderRowUpsert(updRec);
|
|
// svuoto cache...
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:Orders:*");
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OrderRows:*");
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OrderRowsByState:*");
|
|
sw.Stop();
|
|
Log.Debug($"OrderRowUpsert in {sw.Elapsed.TotalMilliseconds} ms");
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Restituisce un dizionario di <CodFase,EventDto> da usare nel planner
|
|
/// </summary>
|
|
/// <param name="dtStart"></param>
|
|
/// <param name="dtEnd"></param>
|
|
/// <returns></returns>
|
|
public async Task<Dictionary<string, List<EventDto>>?> PlannerGetEvents(DateTime dtStart, DateTime dtEnd)
|
|
{
|
|
string source = "DB";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
Dictionary<string, List<EventDto>>? result = null;
|
|
// cerco in redis...
|
|
string currKey = $"{redisBaseKey}:PlannerData:{dtStart:yyyyMMdd}:{dtEnd:yyyyMMdd}";
|
|
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
|
//if (!string.IsNullOrEmpty($"{rawData}"))
|
|
if (rawData.HasValue && rawData.Length() > 2)
|
|
{
|
|
result = JsonConvert.DeserializeObject<Dictionary<string, List<EventDto>>>($"{rawData}");
|
|
source = "REDIS";
|
|
}
|
|
else
|
|
{
|
|
result = dataSimController.PlannerGetEvents(dtStart, dtEnd);
|
|
// serializzo e salvo...
|
|
rawData = JsonConvert.SerializeObject(result);
|
|
await redisDb.StringSetAsync(currKey, rawData, LongCache);
|
|
}
|
|
sw.Stop();
|
|
Log.Debug($"PlannerGetEvents | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua upsert complessivo Ordine
|
|
/// </summary>
|
|
/// <param name="updRec"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> OrderUpsert(OrderModel updRec)
|
|
{
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
// calcolo
|
|
bool fatto = await dbController.OrderUpsert(updRec);
|
|
// svuoto cache...
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:Orders:*");
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OrderRows:*");
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OrderRowsByState:*");
|
|
sw.Stop();
|
|
Log.Debug($"OrderUpsert in {sw.Elapsed.TotalMilliseconds} ms");
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco completo Fasi
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<List<PhaseModel>> PhasesGetAllAsync()
|
|
{
|
|
string source = "DB";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
List<PhaseModel>? result = new List<PhaseModel>();
|
|
// cerco in redis...
|
|
string currKey = $"{redisBaseKey}:Phases:ALL";
|
|
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
|
if (rawData.HasValue)
|
|
{
|
|
result = JsonConvert.DeserializeObject<List<PhaseModel>>($"{rawData}");
|
|
source = "REDIS";
|
|
}
|
|
else
|
|
{
|
|
result = await dbController.PhasesGetAllAsync();
|
|
// serializzo e salvo con config x evitare loop...
|
|
rawData = JsonConvert.SerializeObject(result, JSSettings);
|
|
await redisDb.StringSetAsync(currKey, rawData, LongCache);
|
|
}
|
|
if (result == null)
|
|
{
|
|
result = new List<PhaseModel>();
|
|
}
|
|
sw.Stop();
|
|
Log.Debug($"PhasesGetAllAsync | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupera ProdGroup dato POR
|
|
/// </summary>
|
|
/// <param name="OrderRowID"></param>
|
|
/// <returns></returns>
|
|
public async Task<List<ProductionGroupModel>> ProdGroupByOrderRow(int OrderRowID)
|
|
{
|
|
string source = "DB";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
List<ProductionGroupModel>? result = new List<ProductionGroupModel>();
|
|
// cerco in redis...
|
|
string currKey = $"{redisBaseKey}:ProdGroup:OrdRowId:{OrderRowID}";
|
|
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
|
if (rawData.HasValue && rawData.Length() > 2)
|
|
{
|
|
result = JsonConvert.DeserializeObject<List<ProductionGroupModel>>($"{rawData}");
|
|
source = "REDIS";
|
|
}
|
|
else
|
|
{
|
|
result = await dbController.ProdGroupByOrderRow(OrderRowID);
|
|
// serializzo e salvo con config x evitare loop...
|
|
rawData = JsonConvert.SerializeObject(result, JSSettings);
|
|
await redisDb.StringSetAsync(currKey, rawData, LongCache);
|
|
}
|
|
if (result == null)
|
|
{
|
|
result = new List<ProductionGroupModel>();
|
|
}
|
|
sw.Stop();
|
|
Log.Debug($"ProdGroupByOrderRow | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco record ProductionGroup dato Stato dell'OrderRow
|
|
/// </summary>
|
|
/// <param name="reqState"></param>
|
|
/// <returns></returns>
|
|
public async Task<List<ProductionGroupModel>> ProdGroupByOrderState(OrderStates reqState)
|
|
{
|
|
string source = "DB";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
List<ProductionGroupModel>? result = new List<ProductionGroupModel>();
|
|
// cerco in redis...
|
|
string currKey = $"{redisBaseKey}:ProdGroup:OrdRowState:{reqState}";
|
|
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
|
if (rawData.HasValue && rawData.Length() > 2)
|
|
{
|
|
result = JsonConvert.DeserializeObject<List<ProductionGroupModel>>($"{rawData}");
|
|
source = "REDIS";
|
|
}
|
|
else
|
|
{
|
|
result = await dbController.ProdGroupByOrderState(reqState);
|
|
// serializzo e salvo con config x evitare loop...
|
|
rawData = JsonConvert.SerializeObject(result, JSSettings);
|
|
await redisDb.StringSetAsync(currKey, rawData, LongCache);
|
|
}
|
|
if (result == null)
|
|
{
|
|
result = new List<ProductionGroupModel>();
|
|
}
|
|
sw.Stop();
|
|
Log.Debug($"ProdGroupByOrderState | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
|
return result;
|
|
}
|
|
|
|
#if false
|
|
public async Task<List<ProductionAssignModel>> ProdAssignByOrderRow(int OrderRowID)
|
|
{
|
|
string source = "DB";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
List<ProductionAssignModel>? result = new List<ProductionAssignModel>();
|
|
// cerco in redis...
|
|
string currKey = $"{redisBaseKey}:ProdAssign:OrdRowId:{OrderRowID}";
|
|
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
|
if (rawData.HasValue && rawData.Length() > 2)
|
|
{
|
|
result = JsonConvert.DeserializeObject<List<ProductionAssignModel>>($"{rawData}");
|
|
source = "REDIS";
|
|
}
|
|
else
|
|
{
|
|
result = await dbController.ProdAssignByOrderRow(OrderRowID);
|
|
// serializzo e salvo con config x evitare loop...
|
|
rawData = JsonConvert.SerializeObject(result, JSSettings);
|
|
await redisDb.StringSetAsync(currKey, rawData, LongCache);
|
|
}
|
|
if (result == null)
|
|
{
|
|
result = new List<ProductionAssignModel>();
|
|
}
|
|
sw.Stop();
|
|
Log.Debug($"ProdAssignByOrderRow | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verifica ed eventualmente crea ProdAssign dato elenco macchine
|
|
/// </summary>
|
|
/// <param name="OrderRowID"></param>
|
|
/// <param name="ListPlant"></param>
|
|
/// <returns></returns>
|
|
public async Task<List<ProductionAssignModel>> ProdAssignCheckExist(int OrderRowID, List<string> ListPlant)
|
|
{
|
|
string source = "DB";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
List<ProductionAssignModel>? result = new List<ProductionAssignModel>();
|
|
// cerco in redis...
|
|
string currKey = $"{redisBaseKey}:ProdAssign:OrdRowId:{OrderRowID}";
|
|
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
|
if (rawData.HasValue && rawData.Length() > 2)
|
|
{
|
|
result = JsonConvert.DeserializeObject<List<ProductionAssignModel>>($"{rawData}");
|
|
source = "REDIS";
|
|
}
|
|
else
|
|
{
|
|
result = await dbController.ProdAssignCheckExist(OrderRowID, ListPlant);
|
|
// serializzo e salvo con config x evitare loop...
|
|
rawData = JsonConvert.SerializeObject(result, JSSettings);
|
|
await redisDb.StringSetAsync(currKey, rawData, LongCache);
|
|
}
|
|
if (result == null)
|
|
{
|
|
result = new List<ProductionAssignModel>();
|
|
}
|
|
sw.Stop();
|
|
Log.Debug($"ProdAssignCheckExist | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
|
return result;
|
|
}
|
|
#endif
|
|
|
|
/// <summary>
|
|
/// Esegue assegnazione bulk dei ProdItem ad un unico ProdGroup parent
|
|
/// </summary>
|
|
/// <param name="OrderRowID"></param>
|
|
/// <returns></returns>
|
|
public async Task<int> ProdItemBulkAssignProdGroup(int OrderRowId, int ProdAssignId, Dictionary<string, double> itemsToAssign)
|
|
{
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
// calcolo
|
|
int fatto = await dbController.ProdItemBulkAssignProdGroup(OrderRowId, ProdAssignId, itemsToAssign);
|
|
// svuoto cache...
|
|
//await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:ProdItems:*");
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:ProdItems:OrdRowId:*");
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:ProdGroup:OrdRowId:*");
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OrderRows:*");
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OrderRowsByState:*");
|
|
sw.Stop();
|
|
Log.Debug($"ProdItemBulkAssignProdGroup in {sw.Elapsed.TotalMilliseconds} ms");
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco dei ProductionItem collegati ad una riga d'ordine
|
|
/// </summary>
|
|
/// <param name="OrderRowId"></param>
|
|
/// <returns></returns>
|
|
public async Task<List<ProductionItemModel>> ProdItemByOrderRow(int OrderRowId)
|
|
{
|
|
string source = "DB";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
List<ProductionItemModel>? result = new List<ProductionItemModel>();
|
|
// cerco in redis...
|
|
string currKey = $"{redisBaseKey}:ProdItems:OrdRowId:{OrderRowId}";
|
|
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
|
if (rawData.HasValue)
|
|
{
|
|
result = JsonConvert.DeserializeObject<List<ProductionItemModel>>($"{rawData}");
|
|
source = "REDIS";
|
|
}
|
|
else
|
|
{
|
|
result = await dbController.ProdItemByOrderRow(OrderRowId);
|
|
// serializzo e salvo con config x evitare loop...
|
|
rawData = JsonConvert.SerializeObject(result, JSSettings);
|
|
await redisDb.StringSetAsync(currKey, rawData, LongCache);
|
|
}
|
|
if (result == null)
|
|
{
|
|
result = new List<ProductionItemModel>();
|
|
}
|
|
sw.Stop();
|
|
Log.Debug($"ProdItemByOrderRow | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Reset assegnazioni x ProdItems dato orderRowID
|
|
/// </summary>
|
|
/// <param name="orderRowID"></param>
|
|
/// <returns></returns>
|
|
public async Task<int> ProdItemResetOrderAssign(int orderRowID)
|
|
{
|
|
int result = await dbController.ProdItemResetProdGroup(orderRowID);
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:ProdItems:OrdRowId:*");
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:ProdAssign:OrdRowId:*");
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OrderRows:*");
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OrderRowsByState:*");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco completo plant gestiti
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<List<ProductionPlantModel>> ProdPlantGetAllAsync()
|
|
{
|
|
string source = "DB";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
List<ProductionPlantModel>? result = new List<ProductionPlantModel>();
|
|
// cerco in redis...
|
|
string currKey = $"{redisBaseKey}:ProdPlantList";
|
|
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
|
if (rawData.HasValue)
|
|
{
|
|
result = JsonConvert.DeserializeObject<List<ProductionPlantModel>>($"{rawData}");
|
|
source = "REDIS";
|
|
}
|
|
else
|
|
{
|
|
result = await dbController.ProdPlantGetAllAsync();
|
|
// serializzo e salvo con config x evitare loop...
|
|
rawData = JsonConvert.SerializeObject(result, JSSettings);
|
|
await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
|
|
}
|
|
if (result == null)
|
|
{
|
|
result = new List<ProductionPlantModel>();
|
|
}
|
|
sw.Stop();
|
|
Log.Debug($"ProdPlantGetAllAsync | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
|
return result;
|
|
}
|
|
|
|
/// Esegue Delete del record ricevuto
|
|
/// </summary>
|
|
/// <param name="upsRec"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> ResourcesDeleteAsync(ResourceModel upsRec)
|
|
{
|
|
bool result = await dbController.ResourcesDeleteAsync(upsRec);
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:Resources:*");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco completo Risorse
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<List<ResourceModel>> ResourcesGetAllAsync()
|
|
{
|
|
string source = "DB";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
List<ResourceModel>? result = new List<ResourceModel>();
|
|
// cerco in redis...
|
|
string currKey = $"{redisBaseKey}:Resources:ALL";
|
|
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
|
if (rawData.HasValue)
|
|
{
|
|
result = JsonConvert.DeserializeObject<List<ResourceModel>>($"{rawData}");
|
|
source = "REDIS";
|
|
}
|
|
else
|
|
{
|
|
result = await dbController.ResourcesGetAllAsync();
|
|
// serializzo e salvo con config x evitare loop...
|
|
rawData = JsonConvert.SerializeObject(result, JSSettings);
|
|
await redisDb.StringSetAsync(currKey, rawData, LongCache);
|
|
}
|
|
if (result == null)
|
|
{
|
|
result = new List<ResourceModel>();
|
|
}
|
|
sw.Stop();
|
|
Log.Debug($"ResourcesGetAllAsync | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Esegue Upsert del record ricevuto
|
|
/// </summary>
|
|
/// <param name="upsRec"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> ResourcesUpsertAsync(ResourceModel upsRec)
|
|
{
|
|
bool result = await dbController.ResourcesUpsertAsync(upsRec);
|
|
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:Resources:*");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Esegue salvataggio BOM sul DB
|
|
/// </summary>
|
|
/// <param name="uID">UID dell'item offerta di cui si è ricevuto la BOM</param>
|
|
/// <param name="execEnvironment">Environment dell'item</param>
|
|
/// <param name="bomContent">BOM serializzata</param>
|
|
/// <returns></returns>
|
|
public async Task SaveBomAsync(string uID, Constants.EXECENVIRONMENTS execEnvironment, string bomContent)
|
|
{
|
|
// salvo sul DB il risultato della BOM
|
|
if (!string.IsNullOrEmpty(bomContent))
|
|
{
|
|
List<BomItemDTO>? bomList = null;
|
|
try
|
|
{
|
|
// deserializzo la Bom...
|
|
bomList = JsonConvert.DeserializeObject<List<BomItemDTO>>(bomContent);
|
|
}
|
|
catch { }
|
|
if (bomList != null)
|
|
{
|
|
// verifico 1:1 gli item ricevuti dalla BOM sul DB con eventuale insert in anagrafica dei nuovi
|
|
dbController.ItemUpsertFromBom(bomList);
|
|
// salvo la BOM nel record del DB relativo all'oggetto richiesto
|
|
dbController.OfferUpsertFromBom(uID, bomList);
|
|
}
|
|
}
|
|
await Task.Delay(1);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Esegue salvataggio HardwareModelList sul DB
|
|
/// </summary>
|
|
/// <param name="uID">UID dell'item offerta di cui si è ricevuto la BOM</param>
|
|
/// <param name="execEnvironment">Environment dell'item</param>
|
|
/// <param name="rawContent">HardwareModelList serializzata</param>
|
|
/// <returns></returns>
|
|
public async Task SaveHmlAsync(string uID, Constants.EXECENVIRONMENTS execEnvironment, string rawContent)
|
|
{
|
|
// salvo sul DB il risultato della BOM
|
|
if (!string.IsNullOrEmpty(rawContent))
|
|
{
|
|
try
|
|
{
|
|
// non effettuo salvataggio sul DB perché master del dato è esterno e lo lasceremo solo in cache REDIS
|
|
await Task.Delay(1);
|
|
}
|
|
catch { }
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Esegue salvataggio ProdBalance (di un gruppo lavorazioni per riga ordine) sul DB
|
|
/// </summary>
|
|
/// <param name="uID">UID dell'item offerta di cui si è ricevuto l'oggetto Balance'</param>
|
|
/// <param name="rGroup">Prod Group di riferimento</param>
|
|
/// <param name="execEnvironment">Environment dell'item</param>
|
|
/// <param name="balance">Stima Balance serializzata</param>
|
|
/// <returns></returns>
|
|
public async Task SaveProdBalanceAsync(string uID, string rGroup, Constants.EXECENVIRONMENTS execEnvironment, string balance)
|
|
{
|
|
// salvo sul DB il risultato della BOM
|
|
if (!string.IsNullOrEmpty(balance))
|
|
{
|
|
// salvo info balance nel record del DB relativo all'oggetto richiesto
|
|
await dbController.ProdGroupUpsertBalance(uID, rGroup, balance);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Esegue salvataggio ProdEstimate (per riga ordine) sul DB
|
|
/// </summary>
|
|
/// <param name="uID">UID dell'item offerta di cui si è ricevuto la ProdEstim</param>
|
|
/// <param name="execEnvironment">Environment dell'item</param>
|
|
/// <param name="prodEstim">Stima ProdEstimate serializzata</param>
|
|
/// <returns></returns>
|
|
public async Task SaveProdEstimateAsync(string uID, Constants.EXECENVIRONMENTS execEnvironment, string prodEstim)
|
|
{
|
|
// salvo sul DB il risultato della BOM
|
|
if (!string.IsNullOrEmpty(prodEstim))
|
|
{
|
|
// salvo info balance nel record del DB relativo all'oggetto richiesto
|
|
await dbController.OrderRowUpsertProdEst(uID, prodEstim);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// MockUp (fake) salvataggio ProfileList sul DB
|
|
/// </summary>
|
|
/// <param name="uID">UID ricezione (default tipicamente)</param>
|
|
/// <param name="execEnvironment">Environment dell'item</param>
|
|
/// <param name="rawContent">ProfileList serializzata</param>
|
|
/// <returns></returns>
|
|
public async Task SaveProfileListAsync(string uID, Constants.EXECENVIRONMENTS execEnvironment, string rawContent)
|
|
{
|
|
// salvo sul DB il risultato della BOM
|
|
if (!string.IsNullOrEmpty(rawContent))
|
|
{
|
|
try
|
|
{
|
|
// non effettuo salvataggio sul DB perché master del dato è esterno e lo lasceremo solo in cache REDIS
|
|
await Task.Delay(1);
|
|
}
|
|
catch { }
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// MockUp (fake) salvataggio ProfileThreshold sul DB
|
|
/// </summary>
|
|
/// <param name="uID">UID del profilo</param>
|
|
/// <param name="execEnvironment">Environment dell'item</param>
|
|
/// <param name="rawContent">ThresholdList serializzata</param>
|
|
/// <returns></returns>
|
|
public async Task SaveProfileThreshAsync(string uID, Constants.EXECENVIRONMENTS execEnvironment, string rawContent)
|
|
{
|
|
// salvo sul DB il risultato della BOM
|
|
if (!string.IsNullOrEmpty(rawContent))
|
|
{
|
|
try
|
|
{
|
|
// non effettuo salvataggio sul DB perché master del dato è esterno e lo lasceremo solo in cache REDIS
|
|
await Task.Delay(1);
|
|
}
|
|
catch { }
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Restituisce elenco SellingItem dato envir
|
|
/// </summary>
|
|
/// <param name="envir"></param>
|
|
/// <returns></returns>
|
|
public async Task<List<SellingItemModel>> SellingItemsByEnvir(EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS envir)
|
|
{
|
|
string source = "DB";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
List<SellingItemModel>? result = new List<SellingItemModel>();
|
|
// cerco in redis...
|
|
string currKey = $"{redisBaseKey}:SellingItem:{envir}";
|
|
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
|
if (rawData.HasValue && rawData.Length() > 2)
|
|
{
|
|
result = JsonConvert.DeserializeObject<List<SellingItemModel>>($"{rawData}");
|
|
source = "REDIS";
|
|
}
|
|
else
|
|
{
|
|
result = await dbController.SellingItemsByEnvir(envir);
|
|
// serializzo e salvo con config x evitare loop...
|
|
rawData = JsonConvert.SerializeObject(result, JSSettings);
|
|
await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
|
|
}
|
|
if (result == null)
|
|
{
|
|
result = new List<SellingItemModel>();
|
|
}
|
|
sw.Stop();
|
|
Log.Debug($"SellingItemsByEnvir | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
|
return result;
|
|
}
|
|
|
|
#if false
|
|
/// <summary>
|
|
/// Recupero nuovo record BOM diretto dal DB
|
|
/// </summary>
|
|
/// <param name="offerRowID"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
public OfferRowModel? OfferRowGetByOfferRowID(int offerRowID)
|
|
{
|
|
string source = "DB";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
OfferRowModel? result = null;
|
|
result = dbController.OfferRowGetByOfferRowID(offerRowID);
|
|
sw.Stop();
|
|
Log.Debug($"OfferRowGetByOfferRowID | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
|
return result;
|
|
}
|
|
#endif
|
|
|
|
/// <summary>
|
|
/// Elenco completo Tags disponibili
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<List<TagsModel>> TagsGetAllAsync()
|
|
{
|
|
string source = "DB";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
List<TagsModel>? result = new List<TagsModel>();
|
|
// cerco in redis...
|
|
string currKey = $"{redisBaseKey}:Tags:ALL";
|
|
RedisValue rawData = redisDb.StringGet(currKey);
|
|
if (rawData.HasValue)
|
|
{
|
|
result = JsonConvert.DeserializeObject<List<TagsModel>>($"{rawData}");
|
|
source = "REDIS";
|
|
}
|
|
else
|
|
{
|
|
result = await dbController.TagsGetAllAsync();
|
|
// serializzo e salvo...
|
|
rawData = JsonConvert.SerializeObject(result);
|
|
redisDb.StringSet(currKey, rawData, UltraLongCache);
|
|
}
|
|
if (result == null)
|
|
{
|
|
result = new List<TagsModel>();
|
|
}
|
|
sw.Stop();
|
|
Log.Debug($"TagsGetAllAsync | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
|
return result;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Fields
|
|
|
|
/// <summary>
|
|
/// Numero di operazioni parallele che si possono svolgere... (se 0 NON usa cicli paralleli)
|
|
/// </summary>
|
|
protected int numPar = 0;
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Protected Methods
|
|
|
|
/// <summary>
|
|
/// Esegue flush memoria redis dato pat2Flush
|
|
/// </summary>
|
|
/// <param name="pat2Flush"></param>
|
|
/// <returns></returns>
|
|
protected bool ExecFlushRedisPattern(RedisValue pat2Flush)
|
|
{
|
|
bool answ = false;
|
|
/*******************************
|
|
* Recupero elenco dei server da cui cancellare le chiavi:
|
|
* - prendo solo i server connessi
|
|
* - prendo solo NON repliche (= master)
|
|
* - me ne aspetto 1 in uscita cmq
|
|
*******************************/
|
|
var connServ = redisConn.GetEndPoints()
|
|
.Select(endpoint =>
|
|
{
|
|
var server = redisConn.GetServer(endpoint);
|
|
return server;
|
|
})
|
|
.Where(x => x.IsConnected && !x.IsReplica)
|
|
.FirstOrDefault();
|
|
if (connServ != null)
|
|
{
|
|
try
|
|
{
|
|
// sepattern è "*" elimino intero DB...
|
|
if ((pat2Flush.Equals(new RedisValue("*")) || pat2Flush == RedisValue.Null))
|
|
{
|
|
connServ.FlushDatabase(database: redisDb.Database);
|
|
}
|
|
else
|
|
{
|
|
var keys = connServ.Keys(database: redisDb.Database, pattern: pat2Flush, pageSize: 1000);
|
|
var batch = new List<RedisKey>();
|
|
foreach (var key in keys)
|
|
{
|
|
batch.Add(key);
|
|
|
|
// Flush in batches of 1000
|
|
if (batch.Count >= 1000)
|
|
{
|
|
foreach (var item in batch)
|
|
redisDb.KeyDelete(item);
|
|
|
|
batch.Clear();
|
|
}
|
|
}
|
|
|
|
// Flush remaining keys
|
|
foreach (var item in batch)
|
|
redisDb.KeyDelete(item);
|
|
}
|
|
|
|
#if false
|
|
var keyList = connServ.Keys(redisDb.Database, pattern);
|
|
if (numPar > 0)
|
|
{
|
|
var options = new ParallelOptions { MaxDegreeOfParallelism = numPar };
|
|
Parallel.ForEach(keyList, (item, token) =>
|
|
{
|
|
// cancello
|
|
redisDb.KeyDelete(item);
|
|
});
|
|
}
|
|
else
|
|
{
|
|
foreach (var item in keyList)
|
|
{
|
|
redisDb.KeyDelete(item);
|
|
}
|
|
}
|
|
#endif
|
|
answ = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante ExecFlushRedisPattern | pat2Flush: {pat2Flush}{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Log.Error($"Server REDIS master non trovato");
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Esegue flush memoria redis dato pat2Flush
|
|
/// </summary>
|
|
/// <param name="pat2Flush"></param>
|
|
/// <returns></returns>
|
|
protected async Task<bool> ExecFlushRedisPatternAsync(RedisValue pat2Flush)
|
|
{
|
|
bool answ = false;
|
|
/*******************************
|
|
* Recupero elenco dei server da cui cancellare le chaivi:
|
|
* - prendo solo i server connessi
|
|
* - prendo solo NON repliche (= master)
|
|
* - me ne aspetto 1 in uscita / prendo primo o default
|
|
*******************************/
|
|
var connServ = redisConn.GetEndPoints()
|
|
.Select(endpoint =>
|
|
{
|
|
var server = redisConn.GetServer(endpoint);
|
|
return server;
|
|
})
|
|
.Where(x => x.IsConnected && !x.IsReplica)
|
|
.FirstOrDefault();
|
|
if (connServ != null)
|
|
{
|
|
// ciclo (anche se me ne aspetto 1 solo)
|
|
// se pat2Flush è "*" elimino intero DB...
|
|
if ((pat2Flush.Equals(new RedisValue("*")) || pat2Flush == RedisValue.Null))
|
|
{
|
|
connServ.FlushDatabase(database: redisDb.Database);
|
|
}
|
|
else
|
|
{
|
|
try
|
|
{
|
|
var keys = connServ.Keys(database: redisDb.Database, pattern: pat2Flush, pageSize: 1000);
|
|
|
|
var deleteTasks = new List<Task>();
|
|
foreach (var key in keys)
|
|
{
|
|
deleteTasks.Add(redisDb.KeyDeleteAsync(key));
|
|
if (deleteTasks.Count >= 1000)
|
|
{
|
|
await Task.WhenAll(deleteTasks);
|
|
deleteTasks.Clear();
|
|
}
|
|
}
|
|
if (deleteTasks.Count > 0)
|
|
{
|
|
await Task.WhenAll(deleteTasks);
|
|
}
|
|
#if false
|
|
if (numPar > 0)
|
|
{
|
|
var options = new ParallelOptions { MaxDegreeOfParallelism = numPar };
|
|
await Parallel.ForEachAsync(keys, async (item, token) =>
|
|
{
|
|
// cancello
|
|
await redisDb.KeyDeleteAsync(item);
|
|
});
|
|
}
|
|
else
|
|
{
|
|
foreach (var item in keys)
|
|
{
|
|
await redisDb.KeyDeleteAsync(item);
|
|
}
|
|
}
|
|
#endif
|
|
answ = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante ExecFlushRedisPatternAsync | pat2Flush: {pat2Flush}{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Log.Error($"Server REDIS master non trovato");
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
|
private string redisBaseKey = "Lux:Cache";
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private static LuxController dbController { get; set; } = null!;
|
|
private static DataSimulatorController dataSimController { get; set; } = null!;
|
|
|
|
#endregion Private Properties
|
|
|
|
#if false
|
|
/// <summary>
|
|
/// Elenco item Child da ParentId (per sostituzione) async
|
|
/// </summary>
|
|
/// <param name="ItemId">ID corrente di cui cercare parent + fratelli</param>
|
|
/// <returns></returns>
|
|
public List<ItemModel> ItemGetChild(int ItemId)
|
|
{
|
|
string source = "DB";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
List<ItemModel>? result = new List<ItemModel>();
|
|
// cerco in redis...
|
|
string currKey = $"{redisBaseKey}:Item:ListChild:{ItemId}";
|
|
RedisValue rawData = redisDb.StringGet(currKey);
|
|
if (rawData.HasValue)
|
|
{
|
|
result = JsonConvert.DeserializeObject<List<ItemModel>>($"{rawData}");
|
|
source = "REDIS";
|
|
}
|
|
else
|
|
{
|
|
result = dbController.ItemGetChild(ItemId);
|
|
// serializzo e salvo con config x evitare loop...
|
|
rawData = JsonConvert.SerializeObject(result, JSSettings);
|
|
redisDb.StringSet(currKey, rawData, FastCache);
|
|
}
|
|
if (result == null)
|
|
{
|
|
result = new List<ItemModel>();
|
|
}
|
|
sw.Stop();
|
|
Log.Debug($"ItemGetChild | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
|
return result;
|
|
}
|
|
#endif
|
|
}
|
|
} |