Files

183 lines
5.8 KiB
C#

namespace EgwCoreLib.Lux.Data.Services.Production
{
public class ProductionOdlService : BaseServ, IProductionOdlService
{
#region Public Constructors
public ProductionOdlService(
IConfiguration config,
IConnectionMultiplexer redis,
IProductionOdlRepository repo) : base(config, redis)
{
_className = "ProdOdl";
_repo = repo;
}
#endregion Public Constructors
#region Public Methods
/// <inheritdoc />
public async Task<int> AssignProdItem2OdlAsync(List<ProductionODLModel> dbList, Dictionary<(int phaseId, int resId, string machine, int index), List<string>> dictParts)
{
return await TraceAsync($"{_className}.Upsert", async (activity) =>
{
string operation = "AssignProdItem2Odl";
var result = await _repo.AssignProdItem2OdlAsync(dbList, dictParts);
activity?.SetTag("db.operation", operation);
await ClearCacheAsync($"{_redisBaseKey}:{_className}");
return result;
});
}
/// <inheritdoc />
public async Task<List<ProductionODLModel>> CreateAsync(List<ProductionODLModel> listOdl2ins)
{
return await TraceAsync($"{_className}.Create", async (activity) =>
{
return await GetOrSetCacheAsync(
$"{_redisBaseKey}:{_className}:LAST",
async () => await _repo.CreateAsync(listOdl2ins),
UltraFastCache
);
});
}
/// <inheritdoc />
public async Task<ProductionODLModel?> GetByUidAsync(string uID)
{
return await TraceAsync($"{_className}.GetByUid", async (activity) =>
{
return await GetOrSetCacheAsync(
$"{_redisBaseKey}:{_className}:ByUid:{uID}",
async () => await _repo.GetByUidAsync(uID),
FastCache
);
});
}
/// <inheritdoc />
public async Task<List<OdlAssignDto>> GetUnassignOdlDtoAsync()
{
return await TraceAsync($"{_className}.GetUnassign", async (activity) =>
{
return await GetOrSetCacheAsync(
$"{_redisBaseKey}:{_className}:unassign",
async () => await _repo.GetUnassignOdlDtoAsync(),
UltraFastCache
);
});
}
/// <inheritdoc />
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;
});
}
/// <inheritdoc />
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;
});
}
/// <inheritdoc />
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;
});
}
/// <inheritdoc />
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
private readonly string _className;
private readonly IProductionOdlRepository _repo;
#endregion Private Fields
}
}