test positivo creazione ordini fornitore

This commit is contained in:
Samuele Locatelli
2026-04-21 18:38:22 +02:00
parent c2d1d20730
commit 46148de703
5 changed files with 252 additions and 15 deletions
@@ -1,4 +1,5 @@
using EgwCoreLib.Lux.Data.Services.Catalog;
using EgwCoreLib.Lux.Data.Repository.Supplier;
using EgwCoreLib.Lux.Data.Services.Catalog;
using EgwCoreLib.Lux.Data.Services.Config;
using EgwCoreLib.Lux.Data.Services.Cost;
using EgwCoreLib.Lux.Data.Services.General;
@@ -7,6 +8,7 @@ using EgwCoreLib.Lux.Data.Services.Items;
using EgwCoreLib.Lux.Data.Services.Job;
using EgwCoreLib.Lux.Data.Services.Production;
using EgwCoreLib.Lux.Data.Services.Sales;
using EgwCoreLib.Lux.Data.Services.Supplier;
using EgwCoreLib.Lux.Data.Services.Utils;
using EgwCoreLib.Lux.Data.Services.Warehouse;
using Microsoft.Extensions.DependencyInjection.Extensions;
@@ -27,6 +29,7 @@ namespace EgwCoreLib.Lux.Data
services.TryAddSingleton<IRedisSubscriptionManager, RedisSubscriptionManager>();
// Repository Scoped
services.TryAddScoped<IBuyOrderRepository, BuyOrderRepository>();
services.TryAddScoped<IConfGlassRepository, ConfGlassRepository>();
services.TryAddScoped<IConfProfileRepository, ConfProfileRepository>();
services.TryAddScoped<IConfWoodRepository, ConfWoodRepository>();
@@ -60,6 +63,7 @@ namespace EgwCoreLib.Lux.Data
services.TryAddScoped<ITemplateRowRepository, TemplateRowRepository>();
// Servizi Scoped
services.TryAddScoped<IBuyOrderService, BuyOrderService>();
services.TryAddScoped<IConfGlassService, ConfGlassService>();
services.TryAddScoped<IConfProfileService, ConfProfileService>();
services.TryAddScoped<IConfWoodService, ConfWoodService>();
@@ -54,7 +54,6 @@
<ItemGroup>
<Folder Include="DbModel\Engine\" />
<Folder Include="Migrations\" />
<Folder Include="Services\Supplier\" />
</ItemGroup>
<ItemGroup>
@@ -0,0 +1,141 @@
using EgwCoreLib.Lux.Data.Repository.Supplier;
namespace EgwCoreLib.Lux.Data.Services.Supplier
{
public class BuyOrderService : BaseServ, IBuyOrderService
{
#region Public Constructors
public BuyOrderService(
IConfiguration config,
IConnectionMultiplexer redis,
IBuyOrderRepository repo) : base(config, redis)
{
_className = "BuyOrder";
_repo = repo;
}
#endregion Public Constructors
#region Public Methods
/// <inheritdoc />
public async Task<BuyOrderModel> GenerateFromSelectionAsync(Dictionary<string, List<int>> currSelDict)
{
return await TraceAsync($"{_className}.GetByIdAsync", async (activity) =>
{
return await GetOrSetCacheAsync(
$"{_redisBaseKey}:{_className}:LastGen",
async () => await _repo.GenerateFromSelectionAsync(currSelDict),
UltraFastCache
);
});
}
/// <inheritdoc />
public async Task<List<BuyOrderModel>> GetAllAsync()
{
return await TraceAsync($"{_className}.GetAllAsync", async (activity) =>
{
return await GetOrSetCacheAsync(
$"{_redisBaseKey}:{_className}:ALL",
async () => await _repo.GetAllAsync(),
UltraLongCache
);
});
}
/// <inheritdoc />
public async Task<BuyOrderModel?> GetByIdAsync(int orderId)
{
return await TraceAsync($"{_className}.GetByIdAsync", async (activity) =>
{
return await GetOrSetCacheAsync(
$"{_redisBaseKey}:{_className}:ById:{orderId}",
async () => await _repo.GetByIdAsync(orderId),
UltraLongCache
);
});
}
/// <inheritdoc />
public async Task<bool> UpsertAsync(BuyOrderModel upsRec)
{
return await TraceAsync($"{_className}.Upsert", async (activity) =>
{
var currRec = await _repo.GetByIdAsync(upsRec.BuyOrderID);
string operation = "UPDATE";
bool success = false;
if (currRec != null)
{
success = await _repo.UpdateAsync(upsRec);
}
else
{
operation = "INSERT";
success = await _repo.AddAsync(upsRec);
}
activity?.SetTag("db.operation", operation);
if (success)
{
await ClearCacheAsync($"{_redisBaseKey}:{_className}:*");
}
return success;
});
}
#endregion Public Methods
///// <inheritdoc />
//public async Task<List<MatReqModel>> GetUnprocAsync()
//{
// return await TraceAsync($"{_className}.GetUnprocAsync", async (activity) =>
// {
// return await GetOrSetCacheAsync(
// $"{_redisBaseKey}:{_className}:Unproc",
// async () => await _repo.GetFiltAsync(null, null, null, false),
// UltraLongCache
// );
// });
//}
///// <inheritdoc />
//public async Task<bool> ReconcileOrderRowsAsync(List<OrderRowModel> ListOrderRow, bool forceReset = false)
//{
// return await TraceAsync($"{_className}.ReconcileOrderRowsAsync", async (activity) =>
// {
// List<MatReqModel> listaSpesa = new();
// // ciclo sulle righe x trasformare BOM in fabbisogni...
// foreach (var currItem in ListOrderRow)
// {
// var newReq = await GetFabbisogniAsync(currItem, forceReset);
// listaSpesa.AddRange(newReq);
// }
// //bool success = await _repo.AddManyAsync(listaSpesa);
// bool success = await _repo.UpsertManyAsync(listaSpesa);
// activity?.SetTag("db.operation", "ReconcileOrderRowsAsync");
// if (success)
// {
// await ClearCacheAsync($"{_redisBaseKey}:{_className}:*");
// }
// return success;
// });
//}
#region Private Fields
private readonly string _className;
private readonly IBuyOrderRepository _repo;
#endregion Private Fields
}
}
@@ -0,0 +1,74 @@
namespace EgwCoreLib.Lux.Data.Services.Supplier
{
/// <summary>
/// Interfaccia per la gestione degli ordini.
/// </summary>
public interface IBuyOrderService
{
#region Public Methods
/// <summary>
/// Generazione di un nuovo BuyOrder + righe + associazione fabbisogni da dizionario</MatReqID>
/// </summary>
/// <param name="currSelDict">Dizionario selezione CodGroup, List<MatReqID></param>
/// <returns></returns>
Task<BuyOrderModel> GenerateFromSelectionAsync(Dictionary<string, List<int>> currSelDict);
///// <summary>
///// Elimina un ordine dal database.
///// </summary>
///// <param name="entity">L'ordine da eliminare.</param>
///// <returns>True se l'eliminazione ha successo, false altrimenti.</returns>
//Task<bool> DeleteAsync(BuyOrderModel entity);
/// <summary>
/// Recupera l'elenco di tutti gli ordini.
/// </summary>
/// <returns>L'elenco di tutti gli ordini con clienti, rivenditori e righe associate.</returns>
Task<List<BuyOrderModel>> GetAllAsync();
/// <summary>
/// Recupera un ordine per il suo identificatore.
/// </summary>
/// <param name="recId">L'identificatore dell'ordine.</param>
/// <returns>L'ordine corrispondente, o null se non esiste.</returns>
Task<BuyOrderModel?> GetByIdAsync(int recId);
/// <summary>
/// Upsert (add/update) per BuyOrder nel database.
/// </summary>
/// <param name="entity">L'ordine da inserire.</param>
/// <returns>True se l'inserimento ha successo, false altrimenti.</returns>
Task<bool> UpsertAsync(BuyOrderModel upsRec);
#endregion Public Methods
///// <summary>
///// Recupera gli ordini inseriti in un intervallo di date specifico.
///// </summary>
///// <param name="inizio">La data di inizio del periodo.</param>
///// <param name="fine">La data di fine del periodo.</param>
///// <returns>L'elenco degli ordini nell'intervallo specificato.</returns>
//Task<List<BuyOrderModel>> GetFiltAsync(DateTime inizio, DateTime fine);
///// <summary>
///// Recupera le righe dell'ordine per un ordine specifico.
///// </summary>
///// <param name="recId">L'identificatore dell'ordine.</param>
///// <returns>L'elenco delle righe dell'ordine.</returns>
//Task<List<BuyOrderRowModel>> GetRowsAsync(int recId);
///// <summary>
///// Aggiorna in batch le righe di un ordine.
///// </summary>
///// <param name="rows">L'elenco delle righe da aggiornare.</param>
///// <returns>True se l'aggiornamento ha successo, false altrimenti.</returns>
//Task<bool> SaveRowsAsync(List<BuyOrderRowModel> rows);
///// <summary>
///// Aggiorna un ordine esistente nel database.
///// </summary>
///// <param name="entity">L'ordine aggiornato.</param>
///// <returns>True se l'aggiornamento ha successo, false altrimenti.</returns>
//Task<bool> UpdateAsync(BuyOrderModel entity);
}
}
+32 -13
View File
@@ -1,7 +1,38 @@
using EgwCoreLib.Lux.Data.Services.Supplier;
namespace Lux.UI.Components.Pages
{
public partial class BuyOrder
{
#region Private Fields
private Dictionary<string, List<int>> CurrSelDict = new();
private List<int> CurrSelection = new();
#endregion Private Fields
#region Private Properties
[Inject]
private IBuyOrderService BOService { get; set; } = null;
#endregion Private Properties
#region Private Methods
/// <summary>
/// Crea un ordine di acquisto + relative righe...
/// </summary>
/// <param name="codGroup"></param>
/// <param name="listItemId"></param>
/// <returns></returns>
private Task CreateBuyOrder(KeyValuePair<string, List<int>> ReqInfo)
{
Dictionary<string, List<int>> dictReq = new Dictionary<string, List<int>>();
dictReq.Add(ReqInfo.Key, ReqInfo.Value);
return BOService.GenerateFromSelectionAsync(dictReq);
}
private void RecordUpdate(Dictionary<string, List<int>> newDictionary)
{
@@ -12,18 +43,6 @@ namespace Lux.UI.Components.Pages
.ToList();
}
private Dictionary<string, List<int>> CurrSelDict = new();
private List<int> CurrSelection = new();
/// <summary>
/// Crea un ordine di acquisto + relative righe...
/// </summary>
/// <param name="codGroup"></param>
/// <param name="listItemId"></param>
/// <returns></returns>
private async Task CreateBuyOrder(KeyValuePair<string, List<int>> ReqInfo)
{
}
#endregion Private Methods
}
}