Inizio migrazione metodi OfferRow

This commit is contained in:
Samuele Locatelli
2026-03-17 18:33:05 +01:00
parent 5b74509348
commit a6f42b827e
12 changed files with 290 additions and 124 deletions
@@ -294,6 +294,43 @@ namespace EgwCoreLib.Lux.Data.Controllers
return dbResult;
}
internal async Task<bool> OffersCheckExpired()
{
bool answ = false;
//using (DataLayerContext dbCtx = new DataLayerContext(_config))
using (DataLayerContext dbCtx = new DataLayerContext())
{
try
{
DateTime adesso = DateTime.Now;
// recupero offerta...
var listExpired = dbCtx
.DbSetOffer
.Where(x => x.ValidUntil < adesso && x.OffertState == OfferStates.Open)
.ToList();
// se trovo le aggiorno come stato
if (listExpired != null)
{
foreach (var item in listExpired)
{
item.OffertState = OfferStates.Expired;
dbCtx.Entry(item).State = EntityState.Modified;
}
// salvo TUTTI i cambiamenti...
var result = await dbCtx.SaveChangesAsync();
answ = result > 0;
}
}
catch (Exception exc)
{
Log.Error($"Eccezione durante OffersCheckExpired{Environment.NewLine}{exc}");
}
}
return answ;
}
#if true
/// <summary>
/// Recupera da DB riga offerta dato Primary ID
/// </summary>
@@ -367,41 +404,6 @@ namespace EgwCoreLib.Lux.Data.Controllers
return dbResult;
}
internal async Task<bool> OffersCheckExpired()
{
bool answ = false;
//using (DataLayerContext dbCtx = new DataLayerContext(_config))
using (DataLayerContext dbCtx = new DataLayerContext())
{
try
{
DateTime adesso = DateTime.Now;
// recupero offerta...
var listExpired = dbCtx
.DbSetOffer
.Where(x => x.ValidUntil < adesso && x.OffertState == OfferStates.Open)
.ToList();
// se trovo le aggiorno come stato
if (listExpired != null)
{
foreach (var item in listExpired)
{
item.OffertState = OfferStates.Expired;
dbCtx.Entry(item).State = EntityState.Modified;
}
// salvo TUTTI i cambiamenti...
var result = await dbCtx.SaveChangesAsync();
answ = result > 0;
}
}
catch (Exception exc)
{
Log.Error($"Eccezione durante OffersCheckExpired{Environment.NewLine}{exc}");
}
}
return answ;
}
/// Elimina riga e sposta eventuali righe successive...
/// </summary>
@@ -765,6 +767,7 @@ namespace EgwCoreLib.Lux.Data.Controllers
}
return answ;
}
#endif
/// <summary>
/// Esegue upsert del record offerta data la BOM ricevuta
@@ -1,5 +1,6 @@
using EgwCoreLib.Lux.Core.RestPayload;
using EgwCoreLib.Lux.Data.DbModel.Items;
using Newtonsoft.Json;
namespace EgwCoreLib.Lux.Data.Domains
{
@@ -7,6 +8,20 @@ namespace EgwCoreLib.Lux.Data.Domains
{
#region Public Methods
public static List<BomItemDTO> GetBomList(string itemBOM)
{
List<BomItemDTO> answ = new List<BomItemDTO>();
if (!string.IsNullOrEmpty(itemBOM) && itemBOM.Length > 2)
{
var bomList = JsonConvert.DeserializeObject<List<BomItemDTO>>(itemBOM);
if (bomList != null)
{
answ = bomList;
}
}
return answ;
}
/// <summary>
/// Esegue completamento e la validazione dei dati BOM da lista articoli + gruppi,
/// validando i dati stessi
@@ -0,0 +1,26 @@
using EgwCoreLib.Lux.Data.DbModel.Sales;
namespace EgwCoreLib.Lux.Data.Repository.Sales
{
public interface IOfferRowRepository : IBaseRepository
{
#region Public Methods
Task<bool> AddAsync(OfferRowModel entity);
Task<bool> DeleteAsync(OfferRowModel entity);
Task<OfferRowModel?> GetByUidAsync(string offerRowUid);
Task<OfferRowModel?> GetByIdAsync(int offerRowId);
Task<List<OfferRowModel>> GetByParentAsync(int offerId);
Task<bool> SaveRowsAsync(List<OfferRowModel> rows);
Task<bool> UpdateAsync(OfferRowModel entity);
#endregion Public Methods
}
}
@@ -0,0 +1,89 @@
using EgwCoreLib.Lux.Data.DbModel.Sales;
using Microsoft.EntityFrameworkCore;
namespace EgwCoreLib.Lux.Data.Repository.Sales
{
public class OfferRowRepository : BaseRepository, IOfferRowRepository
{
#region Public Constructors
public OfferRowRepository(IDbContextFactory<DataLayerContext> ctxFactory) : base(ctxFactory)
{
}
#endregion Public Constructors
#region Public Methods
public async Task<bool> AddAsync(OfferRowModel entity)
{
await using var dbCtx = await CreateContextAsync();
await dbCtx.DbSetOfferRow.AddAsync(entity);
return await dbCtx.SaveChangesAsync() > 0;
}
public async Task<bool> DeleteAsync(OfferRowModel entity)
{
await using var dbCtx = await CreateContextAsync();
dbCtx.DbSetOfferRow.Remove(entity);
return await dbCtx.SaveChangesAsync() > 0;
}
public async Task<OfferRowModel?> GetByUidAsync(string offerRowUid)
{
await using var dbCtx = await CreateContextAsync();
return await dbCtx.DbSetOfferRow
.Include(r => r.SellingItemNav)
.FirstOrDefaultAsync(x => x.OfferRowUID == offerRowUid);
}
public async Task<OfferRowModel?> GetByIdAsync(int offerRowId)
{
await using var dbCtx = await CreateContextAsync();
return await dbCtx.DbSetOfferRow
.Include(r => r.SellingItemNav)
.FirstOrDefaultAsync(x => x.OfferRowID == offerRowId);
}
public async Task<List<OfferRowModel>> GetByParentAsync(int offerId)
{
await using var dbCtx = await CreateContextAsync();
return await dbCtx.DbSetOfferRow
.Where(x => x.OfferID == offerId)
.Include(r => r.SellingItemNav)
.ToListAsync();
}
public async Task<bool> SaveRowsAsync(List<OfferRowModel> rows)
{
await using var dbCtx = await CreateContextAsync();
foreach (var row in rows)
dbCtx.Entry(row).State = EntityState.Modified;
return await dbCtx.SaveChangesAsync() > 0;
}
public async Task<bool> UpdateAsync(OfferRowModel entity)
{
await using var dbCtx = await CreateContextAsync();
// Recuperiamo l'entità tracciata dal context
var trackedEntity = dbCtx.DbSetOfferRow.Local.FirstOrDefault(x => x.OfferRowID == entity.OfferRowID);
if (trackedEntity != null)
{
// Aggiorna i valori dell'entità tracciata con quelli della nuova
dbCtx.Entry(trackedEntity).CurrentValues.SetValues(entity);
}
else
{
dbCtx.DbSetOfferRow.Update(entity);
}
return await dbCtx.SaveChangesAsync() > 0;
}
#endregion Public Methods
}
}
@@ -316,6 +316,23 @@ namespace EgwCoreLib.Lux.Data.Services
return result;
}
#if true
///// <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>
/// Elenco righe offerta specificata
/// </summary>
@@ -382,39 +399,6 @@ namespace EgwCoreLib.Lux.Data.Services
return result;
}
/// <summary>
/// Verifica offerte scadute, con update sul DB
/// </summary>
public async Task<bool> OffersCheckExpired()
{
using var activity = StartActivity();
string source = "DB+REDIS";
// calcolo
bool fatto = await dbController.OffersCheckExpired();
// 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>
/// 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>
@@ -434,41 +418,6 @@ namespace EgwCoreLib.Lux.Data.Services
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)
{
using var activity = StartActivity();
string source = "DB+REDIS";
List<string> answ = new List<string>();
try
{
// calcolo
answ = await dbController.OffertRowFixUidAsync(OffertID);
// svuoto cache...
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:Offers:*");
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OfferRows:*");
}
catch (Exception exc)
{
string exMsg = $"Eccezione durante OffertRowFixUidAsync";
LogTrace($"{exMsg}{Environment.NewLine}{exc}", LogLevel.Error);
// traccio errore
activity?.SetStatus(ActivityStatusCode.Error, exc.Message);
activity?.AddEvent(new ActivityEvent("exception", tags: new ActivityTagsCollection {
{ "exception.type", exc.GetType().Name },
{ "exception.message", exc.Message },
{ "exception.stacktrace", exc.StackTrace }
}));
}
activity?.SetTag("data.source", source);
LogTrace($"{source} | trace: {activity?.TraceId} | {activity?.Duration.TotalMilliseconds}ms");
return answ;
}
/// <summary>
/// Aggiornamento valore UID non calcolato + ritorno elenco UID da aggiornare
/// </summary>
@@ -504,6 +453,40 @@ namespace EgwCoreLib.Lux.Data.Services
return answ;
}
/// <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)
{
using var activity = StartActivity();
string source = "DB+REDIS";
List<string> answ = new List<string>();
try
{
// calcolo
answ = await dbController.OffertRowFixUidAsync(OffertID);
// svuoto cache...
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:Offers:*");
await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OfferRows:*");
}
catch (Exception exc)
{
string exMsg = $"Eccezione durante OffertRowFixUidAsync";
LogTrace($"{exMsg}{Environment.NewLine}{exc}", LogLevel.Error);
// traccio errore
activity?.SetStatus(ActivityStatusCode.Error, exc.Message);
activity?.AddEvent(new ActivityEvent("exception", tags: new ActivityTagsCollection {
{ "exception.type", exc.GetType().Name },
{ "exception.message", exc.Message },
{ "exception.stacktrace", exc.StackTrace }
}));
}
activity?.SetTag("data.source", source);
LogTrace($"{source} | trace: {activity?.TraceId} | {activity?.Duration.TotalMilliseconds}ms");
return answ;
}
/// <summary>
/// Effettua update stato await BOM/PRICE per l'offerta indicata
@@ -650,6 +633,25 @@ namespace EgwCoreLib.Lux.Data.Services
return dbResult;
}
#endif
/// <summary>
/// Verifica offerte scadute, con update sul DB
/// </summary>
public async Task<bool> OffersCheckExpired()
{
using var activity = StartActivity();
string source = "DB+REDIS";
// calcolo
bool fatto = await dbController.OffersCheckExpired();
// 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>
/// Converte il campo raw della BOM in lista oggetti da gestire
/// </summary>
@@ -970,7 +972,6 @@ namespace EgwCoreLib.Lux.Data.Services
return fatto;
}
/// <summary>
/// Elenco completo Fasi
/// </summary>
@@ -1649,20 +1650,6 @@ namespace EgwCoreLib.Lux.Data.Services
activity?.SetTag("host.name", Environment.MachineName);
return activity;
}
/// <summary>
/// Helper trace messaggio log (SE abilitato)
/// </summary>
/// <param name="traceMsg"></param>
protected new void LogTrace(string traceMsg, NLog.LogLevel? reqLevel = null, [CallerMemberName] string? methodName = null)
{
if (!_traceEnabled)
return;
reqLevel ??= NLog.LogLevel.Debug;
// Loggo!
Log.Log(reqLevel, $"{methodName} | {traceMsg}");
}
/// <summary>
/// Esegue flush memoria redis dato pat2Flush
@@ -1824,6 +1811,21 @@ namespace EgwCoreLib.Lux.Data.Services
return answ;
}
/// <summary>
/// Helper trace messaggio log (SE abilitato)
/// </summary>
/// <param name="traceMsg"></param>
protected new void LogTrace(string traceMsg, NLog.LogLevel? reqLevel = null, [CallerMemberName] string? methodName = null)
{
if (!_traceEnabled)
return;
reqLevel ??= NLog.LogLevel.Debug;
// Loggo!
Log.Log(reqLevel, $"{methodName} | {traceMsg}");
}
#endregion Protected Methods
#region Private Fields
@@ -0,0 +1,29 @@
using EgwCoreLib.Lux.Data.DbModel.Sales;
namespace EgwCoreLib.Lux.Data.Services.Sales
{
public interface IOfferRowService
{
#region Public Methods
Task<bool> CloneAsync(OfferRowModel rec2clone);
Task<bool> DeleteAsync(OfferRowModel model);
Task<List<string>> FixRowUidAsync(int OfferId);
Task<List<OfferRowModel>> GetAllAsync();
Task<List<OfferRowModel>> GetByParentAsync(int OfferId);
Task<bool> UpdateAwaitStateAsync(int OfferRowId, bool? awaitBom, bool? awaitPrice, bool flushCache = false);
Task<bool> UpdateFileDataAsync(OfferRowModel updRec);
Task<bool> UpdateSerStructAsync(int OfferRowID, string serStruct);
Task<bool> UpsertAsync(OfferRowModel upsRec);
#endregion Public Methods
}
}
+1 -1
View File
@@ -4,7 +4,7 @@
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<Version>1.1.2603.1717</Version>
<Version>1.1.2603.1718</Version>
</PropertyGroup>
<ItemGroup>
+3 -1
View File
@@ -5,6 +5,7 @@ using EgwCoreLib.Lux.Data.DbModel.Catalog;
using EgwCoreLib.Lux.Data.DbModel.Config;
using EgwCoreLib.Lux.Data.DbModel.Sales;
using EgwCoreLib.Lux.Data.DbModel.Utils;
using EgwCoreLib.Lux.Data.Domains;
using EgwCoreLib.Lux.Data.Services;
using EgwCoreLib.Lux.Data.Services.Config;
using EgwCoreLib.Lux.Data.Services.Sales;
@@ -1634,7 +1635,8 @@ namespace Lux.UI.Components.Compo
private void selectBom(OfferRowModel currRow)
{
EditRecord = currRow;
CurrBomList = DLService.OffertGetBomList(EditRecord);
//CurrBomList = DLService.OffertGetBomList(EditRecord);
CurrBomList = BomCalculator.GetBomList(EditRecord.ItemBOM);
if (CurrBomList.Any(x => x.ItemID == 0))
{
CurrBomList = DLService.BomFixItemId(CurrBomList);
+1 -1
View File
@@ -5,7 +5,7 @@
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>aspnet-Lux.UI-a758c101-a2f4-4e38-977d-1c4887dbbd50</UserSecretsId>
<Version>1.1.2603.1717</Version>
<Version>1.1.2603.1718</Version>
</PropertyGroup>
<ItemGroup>
+1 -1
View File
@@ -1,6 +1,6 @@
<body>
<i>LUX - Web Windows MES</i>
<h4>Versione: 1.1.2603.1717</h4>
<h4>Versione: 1.1.2603.1718</h4>
<br /> Note di rilascio:
<ul>
<li>
+1 -1
View File
@@ -1 +1 @@
1.1.2603.1717
1.1.2603.1718
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<item>
<version>1.1.2603.1717</version>
<version>1.1.2603.1718</version>
<url>http://nexus.steamware.net/repository/SWS/GPW/stable/GPW.UI.zip</url>
<changelog>http://nexus.steamware.net/repository/SWS/GPW/stable/ChangeLog.html</changelog>
<mandatory>false</mandatory>