Continuo implementazione Repo/Serv spostati
This commit is contained in:
@@ -515,6 +515,7 @@ namespace EgwCoreLib.Lux.Data.Controllers
|
||||
return answ;
|
||||
}
|
||||
|
||||
#if true
|
||||
/// <summary>
|
||||
/// Assegnazione in blocco degli item agli ODL corrispondenti
|
||||
/// </summary>
|
||||
@@ -708,35 +709,7 @@ namespace EgwCoreLib.Lux.Data.Controllers
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco PODL non assegnati
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
internal async Task<List<ProductionODLModel>?> ProductionOdlUnassignAsync()
|
||||
{
|
||||
List<ProductionODLModel>? dbRestults = null;
|
||||
//using (DataLayerContext dbCtx = new DataLayerContext(_config))
|
||||
using (DataLayerContext dbCtx = new DataLayerContext())
|
||||
{
|
||||
try
|
||||
{
|
||||
dbRestults = await dbCtx
|
||||
.DbSetProdODL
|
||||
.Where(x => !x.DateAssign.HasValue)
|
||||
.Include(x => x.Item2OdlNav)
|
||||
//.ThenInclude(i => i.ProductionItemNav)
|
||||
//.ThenInclude(o => o.OrderRowNav)
|
||||
//.ThenInclude(o => o.OrderNav)
|
||||
.ToListAsync();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante ProductionOdlUnassignAsync{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
return dbRestults;
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Esegue merge dei dati nella tab profili del DB con le info accessorie...
|
||||
|
||||
@@ -48,7 +48,6 @@
|
||||
<PackageReference Include="NLog" />
|
||||
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" />
|
||||
<PackageReference Include="RestSharp" />
|
||||
<PackageReference Include="Scrutor" />
|
||||
<PackageReference Include="StackExchange.Redis" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -7,6 +7,13 @@ namespace EgwCoreLib.Lux.Data.Repository.Production
|
||||
{
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Metodo aggiunta record
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> AddAsync(ProductionODLModel entity);
|
||||
|
||||
/// <summary>
|
||||
/// Insert sul DB di un elenco ODL con calcolo della relativa KEY a cui poter, successivamente, collegare i record child (items)
|
||||
/// </summary>
|
||||
@@ -22,11 +29,24 @@ namespace EgwCoreLib.Lux.Data.Repository.Production
|
||||
/// <returns></returns>
|
||||
Task<ProductionODLModel?> GetByUidAsync(string uID);
|
||||
|
||||
/// <summary>
|
||||
/// Elenco PODL non assegnati
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<List<ProductionODLModel>> GetUnassignAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Elenco PODL non assegnati con struttura DTO appiattita
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<List<OdlAssignDto>> GetUnassignAsync();
|
||||
Task<List<OdlAssignDto>> GetUnassignOdlDtoAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Update generico record
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> UpdateAsync(ProductionODLModel entity);
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
|
||||
@@ -17,6 +17,12 @@ namespace EgwCoreLib.Lux.Data.Repository.Production
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public async Task<bool> AddAsync(ProductionODLModel entity)
|
||||
{
|
||||
await using var dbCtx = await CreateContextAsync();
|
||||
await dbCtx.DbSetProdODL.AddAsync(entity);
|
||||
return await dbCtx.SaveChangesAsync() > 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Insert sul DB di un elenco ODL con calcolo della relativa KEY a cui poter, successivamente, collegare i record child (items)
|
||||
@@ -75,13 +81,26 @@ namespace EgwCoreLib.Lux.Data.Repository.Production
|
||||
.FirstOrDefaultAsync(x => x.OdlTag == uID);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco PODL non assegnati
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<List<ProductionODLModel>> GetUnassignAsync()
|
||||
{
|
||||
await using var dbCtx = await CreateContextAsync();
|
||||
return await dbCtx.DbSetProdODL
|
||||
.Where(x => !x.DateAssign.HasValue)
|
||||
.AsNoTracking()
|
||||
.Include(x => x.Item2OdlNav)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco PODL non assegnati con struttura DTO appiattita
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<List<OdlAssignDto>> GetUnassignAsync()
|
||||
public async Task<List<OdlAssignDto>> GetUnassignOdlDtoAsync()
|
||||
{
|
||||
|
||||
await using var dbCtx = await CreateContextAsync();
|
||||
return await dbCtx.DbSetProdODL
|
||||
.Where(x => !x.DateAssign.HasValue)
|
||||
@@ -112,6 +131,27 @@ namespace EgwCoreLib.Lux.Data.Repository.Production
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update generico record
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> UpdateAsync(ProductionODLModel entity)
|
||||
{
|
||||
await using var dbCtx = await CreateContextAsync();
|
||||
var trackedEntity = dbCtx.DbSetProdODL.Local.FirstOrDefault(x => x.ProdODLID == entity.ProdODLID);
|
||||
|
||||
if (trackedEntity != null)
|
||||
{
|
||||
dbCtx.Entry(trackedEntity).CurrentValues.SetValues(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
dbCtx.DbSetProdODL.Update(entity);
|
||||
}
|
||||
return await dbCtx.SaveChangesAsync() > 0;
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -250,6 +250,7 @@ namespace EgwCoreLib.Lux.Data.Services
|
||||
return result;
|
||||
}
|
||||
|
||||
#if true
|
||||
/// <summary>
|
||||
/// Assegnazione in blocco degli item agli ODL corrispondenti
|
||||
/// </summary>
|
||||
@@ -289,6 +290,7 @@ namespace EgwCoreLib.Lux.Data.Services
|
||||
LogTrace($"{source} | trace: {activity?.TraceId} | {activity?.Duration.TotalMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Esegue salvataggio BOM sul DB
|
||||
|
||||
@@ -26,7 +26,38 @@ namespace EgwCoreLib.Lux.Data.Services.Production
|
||||
/// Elenco PODL non assegnati con struttura DTO appiattita
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<List<OdlAssignDto>> GetUnassignAsync();
|
||||
Task<List<OdlAssignDto>> GetUnassignOdlDtoAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Aggiorna record ProdOdl (se trovato) con BOM (raw) ricevuta
|
||||
/// </summary>
|
||||
/// <param name="uID"></param>
|
||||
/// <param name="bomRaw"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> UpdateBomAsync(string uID, string bomRaw);
|
||||
|
||||
/// <summary>
|
||||
/// Aggiorna record ProdOdl (se trovato) con ItemListRaw (raw) inviata x calcolo PROD
|
||||
/// </summary>
|
||||
/// <param name="uID"></param>
|
||||
/// <param name="itemListRaw"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> UpdateItemRawAsync(string uID, string itemListRaw);
|
||||
|
||||
/// <summary>
|
||||
/// Aggiorna record ProdOdl (se trovato) con RawMaterialList (raw) ricevuta da calcolo PROD
|
||||
/// </summary>
|
||||
/// <param name="uID"></param>
|
||||
/// <param name="materialListRaw"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> UpdateRawMaterialAsync(string uID, string materialListRaw);
|
||||
|
||||
/// <summary>
|
||||
/// Upsert intero record
|
||||
/// </summary>
|
||||
/// <param name="upsRec"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> UpsertAsync(ProductionODLModel upsRec);
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
|
||||
@@ -62,18 +62,137 @@ namespace EgwCoreLib.Lux.Data.Services.Production
|
||||
/// Elenco PODL non assegnati con struttura DTO appiattita
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<List<OdlAssignDto>> GetUnassignAsync()
|
||||
public async Task<List<OdlAssignDto>> GetUnassignOdlDtoAsync()
|
||||
{
|
||||
return await TraceAsync($"{_className}.GetUnassign", async (activity) =>
|
||||
{
|
||||
return await GetOrSetCacheAsync(
|
||||
$"{_redisBaseKey}:{_className}:unassign",
|
||||
async () => await _repo.GetUnassignAsync(),
|
||||
async () => await _repo.GetUnassignOdlDtoAsync(),
|
||||
UltraFastCache
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aggiorna record ProdOdl (se trovato) con BOM (raw) ricevuta
|
||||
/// </summary>
|
||||
/// <param name="uID"></param>
|
||||
/// <param name="bomRaw"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> UpdateBomAsync(string uID, string bomRaw)
|
||||
{
|
||||
return await TraceAsync($"{_className}.UpdateBom", async (activity) =>
|
||||
{
|
||||
var currRec = await _repo.GetByUidAsync(uID);
|
||||
|
||||
if (currRec == null)
|
||||
return false;
|
||||
|
||||
currRec.RawBoM = bomRaw;
|
||||
activity?.SetTag("db.operation", "UpdateBom");
|
||||
bool success = await _repo.UpdateAsync(currRec);
|
||||
|
||||
if (success)
|
||||
{
|
||||
await ClearCacheAsync($"{_redisBaseKey}:{_className}:*");
|
||||
}
|
||||
|
||||
return success;
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aggiorna record ProdOdl (se trovato) con ItemListRaw (raw) inviata x calcolo PROD
|
||||
/// </summary>
|
||||
/// <param name="uID"></param>
|
||||
/// <param name="itemListRaw"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> UpdateItemRawAsync(string uID, string itemListRaw)
|
||||
{
|
||||
return await TraceAsync($"{_className}.UpdateItemRaw", async (activity) =>
|
||||
{
|
||||
var currRec = await _repo.GetByUidAsync(uID);
|
||||
|
||||
if (currRec == null)
|
||||
return false;
|
||||
|
||||
currRec.RawItemRawList = itemListRaw;
|
||||
activity?.SetTag("db.operation", "UpdateItemRaw");
|
||||
bool success = await _repo.UpdateAsync(currRec);
|
||||
|
||||
if (success)
|
||||
{
|
||||
await ClearCacheAsync($"{_redisBaseKey}:{_className}:*");
|
||||
}
|
||||
|
||||
return success;
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aggiorna record ProdOdl (se trovato) con RawMaterialList (raw) ricevuta da calcolo PROD
|
||||
/// </summary>
|
||||
/// <param name="uID"></param>
|
||||
/// <param name="materialListRaw"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> UpdateRawMaterialAsync(string uID, string materialListRaw)
|
||||
{
|
||||
return await TraceAsync($"{_className}.UpdateRawMaterial", async (activity) =>
|
||||
{
|
||||
var currRec = await _repo.GetByUidAsync(uID);
|
||||
|
||||
if (currRec == null)
|
||||
return false;
|
||||
|
||||
currRec.RawMaterials = materialListRaw;
|
||||
activity?.SetTag("db.operation", "UpdateRawMaterial");
|
||||
bool success = await _repo.UpdateAsync(currRec);
|
||||
|
||||
if (success)
|
||||
{
|
||||
await ClearCacheAsync($"{_redisBaseKey}:{_className}:*");
|
||||
}
|
||||
|
||||
return success;
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aggiorna record ProdOdl (se trovato) con BOM (raw) ricevuta
|
||||
/// </summary>
|
||||
/// <param name="uID"></param>
|
||||
/// <param name="bomRaw"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> UpsertAsync(ProductionODLModel upsRec)
|
||||
{
|
||||
return await TraceAsync($"{_className}.Upsert", async (activity) =>
|
||||
{
|
||||
var currRec = await _repo.GetByUidAsync(upsRec.OdlTag);
|
||||
|
||||
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
|
||||
|
||||
#region Private Fields
|
||||
|
||||
Reference in New Issue
Block a user