Code cleanup
This commit is contained in:
@@ -401,432 +401,6 @@ namespace EgwCoreLib.Lux.Data.Controllers
|
||||
return answ;
|
||||
}
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Elimina riga e sposta eventuali righe successive...
|
||||
/// </summary>
|
||||
/// <param name="rec2Del"></param>
|
||||
/// <returns></returns>
|
||||
internal async Task<bool> OrderRowDelete(OrderRowModel rec2Del)
|
||||
{
|
||||
bool answ = false;
|
||||
//using (DataLayerContext dbCtx = new DataLayerContext(_config))
|
||||
using (DataLayerContext dbCtx = new DataLayerContext())
|
||||
{
|
||||
try
|
||||
{
|
||||
// recupero offerta...
|
||||
var currRec = dbCtx
|
||||
.DbSetOrderRow
|
||||
.Where(x => x.OrderRowID == rec2Del.OrderRowID)
|
||||
.FirstOrDefault();
|
||||
|
||||
// se trovo procedo
|
||||
if (currRec != null)
|
||||
{
|
||||
// recupero indice attuale...
|
||||
int currRowNum = rec2Del.RowNum;
|
||||
// cerco righe successive
|
||||
var list2move = dbCtx
|
||||
.DbSetOrderRow
|
||||
.Where(x => x.OrderID == rec2Del.OrderID && x.RowNum > currRowNum)
|
||||
.ToList();
|
||||
// se ci sono aggiorno!
|
||||
if (list2move != null && list2move.Count > 0)
|
||||
{
|
||||
foreach (var item in list2move)
|
||||
{
|
||||
item.RowNum--;
|
||||
dbCtx.Entry(item).State = EntityState.Modified;
|
||||
}
|
||||
}
|
||||
// infine rimuovo riga
|
||||
dbCtx.DbSetOrderRow.Remove(currRec);
|
||||
}
|
||||
|
||||
// salvo TUTTI i cambiamenti...
|
||||
var result = await dbCtx.SaveChangesAsync();
|
||||
answ = result > 0;
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante OrderRowDelete{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aggiornamento valore UID non calcolato + ritorno elenco UID da aggiornare
|
||||
/// </summary>
|
||||
/// <param name="orderID"></param>
|
||||
/// <returns></returns>
|
||||
internal List<string> OrderRowFixUid(int orderID)
|
||||
{
|
||||
List<string> answ = new List<string>();
|
||||
//using (DataLayerContext dbCtx = new DataLayerContext(_config))
|
||||
using (DataLayerContext dbCtx = new DataLayerContext())
|
||||
{
|
||||
try
|
||||
{
|
||||
var currList = dbCtx
|
||||
.DbSetOrderRow
|
||||
.Where(x => x.OrderID == orderID)
|
||||
.ToList();
|
||||
// se trovato --> verifico valori differenti, aggiorno e restituisco da calcolare
|
||||
if (currList != null)
|
||||
{
|
||||
var list2fix = currList.Where(x => string.IsNullOrEmpty(x.OrderRowUID) || x.OrderRowUID != x.OrderRowCode).ToList();
|
||||
if (list2fix != null && list2fix.Count > 0)
|
||||
{
|
||||
// salvo elenco
|
||||
answ = list2fix.Select(x => x.OrderRowCode).ToList();
|
||||
// sistemo UID
|
||||
foreach (var item in list2fix)
|
||||
{
|
||||
item.OrderRowUID = item.OrderRowCode;
|
||||
dbCtx.Entry(item).State = EntityState.Modified;
|
||||
}
|
||||
// salvo...
|
||||
var result = dbCtx.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante OrderRowFixUid{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco righe Ordine specificato
|
||||
/// </summary>
|
||||
/// <param name="OrderID"></param>
|
||||
/// <returns></returns>
|
||||
internal List<OrderRowModel> OrderRowGetByOffer(int OrderID)
|
||||
{
|
||||
List<OrderRowModel> dbResult = new List<OrderRowModel>();
|
||||
//using (DataLayerContext dbCtx = new DataLayerContext(_config))
|
||||
using (DataLayerContext dbCtx = new DataLayerContext())
|
||||
{
|
||||
try
|
||||
{
|
||||
dbResult = dbCtx
|
||||
.DbSetOrderRow
|
||||
.Where(x => x.OrderID == OrderID)
|
||||
.Include(s => s.SellingItemNav)
|
||||
//.Include(d => d.DealerNav)
|
||||
.ToList();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante OrderRowGetByOffer{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco righe ordine dato stato richiesto
|
||||
/// </summary>
|
||||
/// <param name="reqState"></param>
|
||||
/// <returns></returns>
|
||||
internal List<OrderRowModel> OrderRowGetByState(OrderStates reqState, DateTime dtStart, DateTime dtEnd)
|
||||
{
|
||||
List<OrderRowModel> dbResult = new List<OrderRowModel>();
|
||||
//using (DataLayerContext dbCtx = new DataLayerContext(_config))
|
||||
using (DataLayerContext dbCtx = new DataLayerContext())
|
||||
{
|
||||
try
|
||||
{
|
||||
dbResult = dbCtx
|
||||
.DbSetOrderRow
|
||||
.Where(x => x.OrderRowState == reqState && x.Inserted >= dtStart && x.Inserted <= dtEnd)
|
||||
.Include(s => s.SellingItemNav)
|
||||
//.Include(d => d.DealerNav)
|
||||
.ToList();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante OrderRowGetByState{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco righe ordine dato periodo + stato richiesto MINIMO
|
||||
/// </summary>
|
||||
/// <param name="reqState"></param>
|
||||
/// <returns></returns>
|
||||
internal List<OrderRowModel> OrderRowGetByStateMin(OrderStates reqState, DateTime dtStart, DateTime dtEnd)
|
||||
{
|
||||
List<OrderRowModel> dbResult = new List<OrderRowModel>();
|
||||
//using (DataLayerContext dbCtx = new DataLayerContext(_config))
|
||||
using (DataLayerContext dbCtx = new DataLayerContext())
|
||||
{
|
||||
try
|
||||
{
|
||||
dbResult = dbCtx
|
||||
.DbSetOrderRow
|
||||
.Where(x => x.OrderRowState >= reqState && x.Inserted >= dtStart && x.Inserted <= dtEnd)
|
||||
.Include(s => s.SellingItemNav)
|
||||
//.Include(d => d.DealerNav)
|
||||
.ToList();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante OrderRowGetByStateMin{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Riga Ordine dato suo UID
|
||||
/// </summary>
|
||||
/// <param name="OrderRowUID"></param>
|
||||
/// <returns></returns>
|
||||
internal OrderRowModel OrderRowGetByUID(string OrderRowUID)
|
||||
{
|
||||
OrderRowModel? dbResult = null;
|
||||
//using (DataLayerContext dbCtx = new DataLayerContext(_config))
|
||||
using (DataLayerContext dbCtx = new DataLayerContext())
|
||||
{
|
||||
try
|
||||
{
|
||||
dbResult = dbCtx
|
||||
.DbSetOrderRow
|
||||
.Include(s => s.SellingItemNav)
|
||||
.FirstOrDefault(x => x.OrderRowUID == OrderRowUID);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante OrderRowGetByUID{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Effettua update stato await BOM/PRICE per l'Ordine indicato
|
||||
/// </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>
|
||||
/// <returns></returns>
|
||||
internal async Task<bool> OrderRowUpdateAwaitState(int orderRowID, bool? awaitBom, bool? awaitPrice)
|
||||
{
|
||||
bool answ = false;
|
||||
//using (DataLayerContext dbCtx = new DataLayerContext(_config))
|
||||
using (DataLayerContext dbCtx = new DataLayerContext())
|
||||
{
|
||||
try
|
||||
{
|
||||
// recupero righe ordine...
|
||||
var currRec = dbCtx
|
||||
.DbSetOrderRow
|
||||
.Where(x => x.OrderRowID == orderRowID)
|
||||
.FirstOrDefault();
|
||||
|
||||
// aggiorno parametri (se inviati)
|
||||
if (currRec != null)
|
||||
{
|
||||
currRec.AwaitBom = awaitBom ?? currRec.AwaitBom;
|
||||
currRec.AwaitPrice = awaitPrice ?? currRec.AwaitPrice;
|
||||
dbCtx.Entry(currRec).State = EntityState.Modified;
|
||||
}
|
||||
|
||||
// salvo i cambiamenti...
|
||||
var result = await dbCtx.SaveChangesAsync();
|
||||
answ = result > 0;
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante OrderRowUpdateAwaitState{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aggiorno sul DB i dati del file associato
|
||||
/// </summary>
|
||||
/// <param name="updRec"></param>
|
||||
/// <returns></returns>
|
||||
internal async Task<bool> OrderRowUpdateFileData(OrderRowModel updRec)
|
||||
{
|
||||
bool answ = false;
|
||||
//using (DataLayerContext dbCtx = new DataLayerContext(_config))
|
||||
using (DataLayerContext dbCtx = new DataLayerContext())
|
||||
{
|
||||
try
|
||||
{
|
||||
// recupero righe offerta...
|
||||
var currRec = dbCtx
|
||||
.DbSetOrderRow
|
||||
.Where(x => x.OrderRowID == updRec.OrderRowID)
|
||||
.FirstOrDefault();
|
||||
|
||||
// aggiorno parametri (se inviati)
|
||||
if (currRec != null)
|
||||
{
|
||||
currRec.FileName = updRec.FileName;
|
||||
currRec.FileResource = updRec.FileResource;
|
||||
currRec.FileSize = updRec.FileSize;
|
||||
currRec.SerStruct = updRec.SerStruct;
|
||||
dbCtx.Entry(currRec).State = EntityState.Modified;
|
||||
}
|
||||
|
||||
// salvo i cambiamenti...
|
||||
var result = await dbCtx.SaveChangesAsync();
|
||||
answ = result > 0;
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante OrderRowUpdateFileData{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Effettua update serStruct per l'Ordine indicato
|
||||
/// </summary>
|
||||
/// <param name="orderRowID">ID singola riga Ordine</param>
|
||||
/// <param name="serStruct">Valore serializzatoe</param>
|
||||
/// <returns></returns>
|
||||
internal async Task<bool> OrderRowUpdateSerStruct(int orderRowID, string serStruct)
|
||||
{
|
||||
bool answ = false;
|
||||
//using (DataLayerContext dbCtx = new DataLayerContext(_config))
|
||||
using (DataLayerContext dbCtx = new DataLayerContext())
|
||||
{
|
||||
try
|
||||
{
|
||||
// recupero righe offerta...
|
||||
var currRec = dbCtx
|
||||
.DbSetOrderRow
|
||||
.Where(x => x.OrderRowID == orderRowID)
|
||||
.FirstOrDefault();
|
||||
|
||||
// aggiorno parametri (se inviati)
|
||||
if (currRec != null)
|
||||
{
|
||||
currRec.SerStruct = serStruct;
|
||||
dbCtx.Entry(currRec).State = EntityState.Modified;
|
||||
}
|
||||
|
||||
// salvo i cambiamenti...
|
||||
var result = await dbCtx.SaveChangesAsync();
|
||||
answ = result > 0;
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante OrderRowUpdateSerStruct{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aggiorna stato riga ordine
|
||||
/// </summary>
|
||||
/// <param name="orderRowID"></param>
|
||||
/// <param name="reqState"></param>
|
||||
/// <returns></returns>
|
||||
internal async Task<bool> OrderRowUpdateState(int orderRowID, OrderStates reqState)
|
||||
{
|
||||
bool answ = false;
|
||||
//using (DataLayerContext dbCtx = new DataLayerContext(_config))
|
||||
using (DataLayerContext dbCtx = new DataLayerContext())
|
||||
{
|
||||
try
|
||||
{
|
||||
// recupero righe offerta...
|
||||
var currRec = dbCtx
|
||||
.DbSetOrderRow
|
||||
.Where(x => x.OrderRowID == orderRowID)
|
||||
.FirstOrDefault();
|
||||
|
||||
// aggiorno parametri (se inviati)
|
||||
if (currRec != null)
|
||||
{
|
||||
currRec.OrderRowState = reqState;
|
||||
dbCtx.Entry(currRec).State = EntityState.Modified;
|
||||
}
|
||||
|
||||
// salvo i cambiamenti...
|
||||
var result = await dbCtx.SaveChangesAsync();
|
||||
answ = result > 0;
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante OrderRowUpdateState{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add riga ordine
|
||||
/// </summary>
|
||||
/// <param name="updRec"></param>
|
||||
/// <returns></returns>
|
||||
internal async Task<bool> OrderRowUpsert(OrderRowModel updRec)
|
||||
{
|
||||
bool answ = false;
|
||||
//using (DataLayerContext dbCtx = new DataLayerContext(_config))
|
||||
using (DataLayerContext dbCtx = new DataLayerContext())
|
||||
{
|
||||
try
|
||||
{
|
||||
// recupero offerta...
|
||||
var currRec = dbCtx
|
||||
.DbSetOrderRow
|
||||
.Where(x => x.OrderRowID == updRec.OrderRowID)
|
||||
.FirstOrDefault();
|
||||
|
||||
// se non trovo aggiungo
|
||||
if (currRec == null)
|
||||
{
|
||||
dbCtx.DbSetOrderRow.Add(updRec);
|
||||
// se ci sono record successivi li devo spostare...
|
||||
var list2move = dbCtx
|
||||
.DbSetOrderRow
|
||||
.Where(x => x.OrderID == updRec.OrderID && x.RowNum >= updRec.RowNum)
|
||||
.ToList();
|
||||
if (list2move != null && list2move.Count > 0)
|
||||
{
|
||||
foreach (var item2move in list2move)
|
||||
{
|
||||
item2move.RowNum++;
|
||||
dbCtx.Entry(item2move).State = EntityState.Modified;
|
||||
}
|
||||
}
|
||||
}
|
||||
// altrimenti aggiorno
|
||||
else
|
||||
{
|
||||
dbCtx.Entry(currRec).CurrentValues.SetValues(updRec);
|
||||
}
|
||||
|
||||
// salvo TUTTI i cambiamenti...
|
||||
var result = await dbCtx.SaveChangesAsync();
|
||||
answ = result > 0;
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante OrderRowUpsert{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Add record del solo ProdEstimate
|
||||
/// </summary>
|
||||
|
||||
@@ -349,320 +349,6 @@ namespace EgwCoreLib.Lux.Data.Services
|
||||
return answ;
|
||||
}
|
||||
|
||||
#if false
|
||||
/// <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)
|
||||
{
|
||||
using var activity = StartActivity();
|
||||
string source = "DB+REDIS";
|
||||
// calcolo
|
||||
bool fatto = await dbController.OrderRowDelete(updRec);
|
||||
// svuoto cache...
|
||||
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:Orders:*");
|
||||
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OrderRows:*");
|
||||
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OrderRowsByState:*");
|
||||
activity?.SetTag("data.source", source);
|
||||
LogTrace($"{source} | trace: {activity?.TraceId} | {activity?.Duration.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)
|
||||
{
|
||||
using var activity = StartActivity();
|
||||
string source = "DB+REDIS";
|
||||
List<string> answ = new List<string>();
|
||||
// calcolo
|
||||
answ = dbController.OrderRowFixUid(OrderID);
|
||||
// svuoto cache...
|
||||
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:Orders:*");
|
||||
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OrderRows:*");
|
||||
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OrderRowsByState:*");
|
||||
activity?.SetTag("data.source", source);
|
||||
LogTrace($"{source} | trace: {activity?.TraceId} | {activity?.Duration.TotalMilliseconds}ms");
|
||||
return answ;
|
||||
}
|
||||
public async Task<List<string>> OrderRowFixImgType(int OrderID)
|
||||
{
|
||||
using var activity = StartActivity();
|
||||
string source = "DB+REDIS";
|
||||
List<string> answ = new List<string>();
|
||||
//// calcolo
|
||||
//answ = dbController.OrderRowFixImgType(OrderID);
|
||||
// svuoto cache...
|
||||
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:Orders:*");
|
||||
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OrderRows:*");
|
||||
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OrderRowsByState:*");
|
||||
activity?.SetTag("data.source", source);
|
||||
LogTrace($"{source} | trace: {activity?.TraceId} | {activity?.Duration.TotalMilliseconds}ms");
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco righe Ordine specificato
|
||||
/// </summary>
|
||||
/// <param name="OrderID"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<OrderRowModel>> OrderRowGetByOffer(int OrderID)
|
||||
{
|
||||
using var activity = StartActivity();
|
||||
string source = "DB";
|
||||
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>();
|
||||
}
|
||||
activity?.SetTag("data.source", source);
|
||||
LogTrace($"{source} | trace: {activity?.TraceId} | {activity?.Duration.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)
|
||||
{
|
||||
using var activity = StartActivity();
|
||||
string source = "DB";
|
||||
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>();
|
||||
}
|
||||
activity?.SetTag("data.source", source);
|
||||
LogTrace($"{source} | trace: {activity?.TraceId} | {activity?.Duration.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)
|
||||
{
|
||||
using var activity = StartActivity();
|
||||
string source = "DB";
|
||||
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>();
|
||||
}
|
||||
activity?.SetTag("data.source", source);
|
||||
LogTrace($"{source} | trace: {activity?.TraceId} | {activity?.Duration.TotalMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Riga Ordine dato suo UID
|
||||
/// </summary>
|
||||
/// <param name="OrderRowUID"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<OrderRowModel?> OrderRowGetByUID(string OrderRowUID)
|
||||
{
|
||||
using var activity = StartActivity();
|
||||
string source = "DB";
|
||||
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);
|
||||
}
|
||||
activity?.SetTag("data.source", source);
|
||||
LogTrace($"{source} | trace: {activity?.TraceId} | {activity?.Duration.TotalMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <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)
|
||||
{
|
||||
using var activity = StartActivity();
|
||||
string source = "DB+REDIS";
|
||||
// aggiorno
|
||||
bool fatto = await dbController.OrderRowUpdateAwaitState(orderRowID, awaitBom, awaitPrice);
|
||||
if (flushCache)
|
||||
{
|
||||
// svuoto cache...
|
||||
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OrderRows:*");
|
||||
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OrderRowsByState:*");
|
||||
}
|
||||
activity?.SetTag("data.source", source);
|
||||
LogTrace($"{source} | trace: {activity?.TraceId} | {activity?.Duration.TotalMilliseconds}ms");
|
||||
return fatto;
|
||||
}
|
||||
|
||||
public async Task<bool> OrderRowUpdateBom(int orderRowID, List<BomItemDTO> newBomList)
|
||||
{
|
||||
using var activity = StartActivity();
|
||||
string source = "DB+REDIS";
|
||||
bool fatto = false;
|
||||
//// calcolo
|
||||
//fatto = await dbController.OrderRowUpdateBom(OfferRowID, newBomList);
|
||||
// svuoto cache...
|
||||
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:Offers:*");
|
||||
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OfferRows:*");
|
||||
activity?.SetTag("data.source", source);
|
||||
LogTrace($"{source} | trace: {activity?.TraceId} | {activity?.Duration.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)
|
||||
{
|
||||
using var activity = StartActivity();
|
||||
string source = "DB+REDIS";
|
||||
// calcolo
|
||||
bool fatto = await dbController.OrderRowUpdateFileData(updRec);
|
||||
// svuoto cache...
|
||||
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:Orders:*");
|
||||
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OrderRows:*");
|
||||
activity?.SetTag("data.source", source);
|
||||
LogTrace($"{source} | trace: {activity?.TraceId} | {activity?.Duration.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)
|
||||
{
|
||||
using var activity = StartActivity();
|
||||
string source = "DB+REDIS";
|
||||
// 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:*");
|
||||
activity?.SetTag("data.source", source);
|
||||
LogTrace($"{source} | trace: {activity?.TraceId} | {activity?.Duration.TotalMilliseconds}ms");
|
||||
return fatto;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Effettua Add della riga Ordine
|
||||
/// </summary>
|
||||
/// <param name="updRec">Riga Ordine con i dati da aggiornare</param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> OrderRowUpsert(OrderRowModel updRec)
|
||||
{
|
||||
using var activity = StartActivity();
|
||||
string source = "DB+REDIS";
|
||||
// calcolo
|
||||
bool fatto = await dbController.OrderRowUpsert(updRec);
|
||||
// svuoto cache...
|
||||
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:Orders:*");
|
||||
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OrderRows:*");
|
||||
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OrderRowsByState:*");
|
||||
activity?.SetTag("data.source", source);
|
||||
LogTrace($"{source} | trace: {activity?.TraceId} | {activity?.Duration.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)
|
||||
{
|
||||
using var activity = StartActivity();
|
||||
string source = "DB+REDIS";
|
||||
// calcolo
|
||||
bool fatto = await dbController.OrderRowUpdateState(orderRowID, reqState);
|
||||
// svuoto cache...
|
||||
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:Orders:*");
|
||||
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OrderRows:*");
|
||||
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:ProdGroup:*");
|
||||
activity?.SetTag("data.source", source);
|
||||
LogTrace($"{source} | trace: {activity?.TraceId} | {activity?.Duration.TotalMilliseconds}ms");
|
||||
return fatto;
|
||||
}
|
||||
#endif
|
||||
/// <summary>
|
||||
/// Validazione record:
|
||||
/// - controllo state vs estimate
|
||||
|
||||
@@ -77,8 +77,6 @@ namespace Lux.UI.Components.Pages
|
||||
|
||||
[Inject]
|
||||
private DataLayerServices DLService { get; set; } = null!;
|
||||
[Inject]
|
||||
private IOrderRowService OrdRService { get; set; } = null!;
|
||||
|
||||
[Inject]
|
||||
private IGenValService GVService { get; set; } = default!;
|
||||
@@ -86,6 +84,9 @@ namespace Lux.UI.Components.Pages
|
||||
[Inject]
|
||||
private IJSRuntime JSRuntime { get; set; } = null!;
|
||||
|
||||
[Inject]
|
||||
private IOrderRowService OrdRService { get; set; } = null!;
|
||||
|
||||
[Inject]
|
||||
private IOrderService OrdService { get; set; } = null!;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user