Update componente window x display corretto
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using EgwCoreLib.Lux.Core.Generic;
|
||||
using EgwCoreLib.Lux.Core.RestPayload;
|
||||
using EgwCoreLib.Lux.Core.RestPayload;
|
||||
using EgwCoreLib.Lux.Data.DbModel.Items;
|
||||
using EgwCoreLib.Lux.Data.DbModel.Job;
|
||||
using EgwCoreLib.Lux.Data.DbModel.Production;
|
||||
@@ -220,204 +219,6 @@ namespace EgwCoreLib.Lux.Data.Controllers
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Add record del solo ProdEstimate
|
||||
/// </summary>
|
||||
/// <param name="uID"></param>
|
||||
/// <param name="prodEstim"></param>
|
||||
#if false
|
||||
|
||||
internal async Task<bool> OrderRowUpsertProdEst(string uID, string prodEstim)
|
||||
{
|
||||
bool answ = false;
|
||||
//using (DataLayerContext dbCtx = new DataLayerContext(_config))
|
||||
using (DataLayerContext dbCtx = new DataLayerContext())
|
||||
{
|
||||
try
|
||||
{
|
||||
// recupero offerta...
|
||||
var currRec = dbCtx
|
||||
.DbSetOrderRow
|
||||
.Where(x => x.OrderRowUID == uID)
|
||||
.FirstOrDefault();
|
||||
|
||||
// se trovo aggiorno
|
||||
if (currRec != null)
|
||||
{
|
||||
// genero WLD x controllo
|
||||
var currWLD = new WorkLoadDetailDTO(currRec.OrderRowUID, currRec.ProdEstimate);
|
||||
|
||||
// faccio update in cascata dei record collegati x macchine e items
|
||||
var listMachDb = dbCtx
|
||||
.DbSetProdPlant
|
||||
.Select(x => x.ProdPlantCod)
|
||||
.ToList();
|
||||
List<string> listMaccCurr = currWLD.MachineCalcResults.Select(x => x.Name).OrderBy(x => x).ToList() ?? new List<string>();
|
||||
if (listMaccCurr != null && listMaccCurr.Any())
|
||||
{
|
||||
var listDiff = listMaccCurr.Except(listMachDb).ToList();
|
||||
if (listDiff.Any())
|
||||
{
|
||||
foreach (var macch in listDiff)
|
||||
{
|
||||
dbCtx
|
||||
.DbSetProdPlant
|
||||
.Add(new ProductionPlantModel() { ProdPlantCod = macch, ProdPlantDescript = macch });
|
||||
}
|
||||
}
|
||||
}
|
||||
// resetta assegnazioni prodgroup agli items...
|
||||
List<ProductionItemModel> listItem2upd = await dbCtx
|
||||
.DbSetProdItem
|
||||
.Where(x => x.OrderRowID == currRec.OrderRowID && x.ProdGroupID != null)
|
||||
.ToListAsync();
|
||||
if (listItem2upd != null && listItem2upd.Count > 0)
|
||||
{
|
||||
// li aggiorna tutti resettando ProdGroupID
|
||||
listItem2upd.ForEach(x => x.ProdGroupID = null);
|
||||
}
|
||||
|
||||
// elimina eventuali oggetti ProductionGroup precedenti
|
||||
List<ProductionGroupModel> listProdGroup2Rem = await dbCtx
|
||||
.DbSetProdGroup
|
||||
.Where(x => x.OrderRowID == currRec.OrderRowID)
|
||||
.ToListAsync();
|
||||
// rimuovo...
|
||||
if (listProdGroup2Rem != null && listProdGroup2Rem.Count > 0)
|
||||
{
|
||||
dbCtx.DbSetProdGroup.RemoveRange(listProdGroup2Rem);
|
||||
}
|
||||
|
||||
/*----------------------------------
|
||||
* Generazione ProdGroup
|
||||
* FixMe ToDo !!!
|
||||
*
|
||||
* rifare considerando le REALI combinazioni scaturite x questo specifico caso e
|
||||
* - ENUMERARE le combinazioni
|
||||
* - ogni combinazione sarà un caso specifico tra 0...N dove N è il totale delle macchine gestite
|
||||
* - i successivi calcoli di balance/stima saranno fatti x questo SPECIFICO ID GROUP così da fare prima... a sto punto GroupIP potrebbe essere un int 0...n oppure l'id del record... forse meglio il counter 0..n
|
||||
*
|
||||
* */
|
||||
int grpIdx = 1;
|
||||
// preparo x add nuovi ProductionGroup da analisi ritorno stime
|
||||
List<ProductionGroupModel> listProdGroup2Add = new List<ProductionGroupModel>();
|
||||
// 1: non lavorabili...
|
||||
if (currWLD.ListUnWorkable.Count > 0)
|
||||
{
|
||||
// calcolo il dizionario degli elementi...
|
||||
Dictionary<string, ProdMachineDetailDto> newWorkGroupList = new();
|
||||
ProdMachineDetailDto detProd = new ProdMachineDetailDto()
|
||||
{
|
||||
TagList = currWLD.ListUnWorkable
|
||||
};
|
||||
newWorkGroupList.Add("", detProd);
|
||||
string rawWGL = JsonConvert.SerializeObject(newWorkGroupList);
|
||||
ProductionGroupModel newRec = new ProductionGroupModel()
|
||||
{
|
||||
OrderRowID = currRec.OrderRowID,
|
||||
GrpIdx = grpIdx++,
|
||||
WorkGroupListRaw = rawWGL
|
||||
};
|
||||
listProdGroup2Add.Add(newRec);
|
||||
}
|
||||
|
||||
// dizionario x macchina delle parts LAVORABILI su impianto..
|
||||
var machineTags = currWLD.MachineCalcResults
|
||||
.ToDictionary(
|
||||
m => m.Name,
|
||||
m => m.PartList
|
||||
.Where(p => p.CalcResult == EgwCoreLib.Lux.Core.Enums.PartVerificationResult.MACHINABLE)
|
||||
.ToList()
|
||||
);
|
||||
|
||||
// ciclo x tutte le combinazioni di gruppi lavorabilità...
|
||||
foreach (var item in currWLD.LoadDetail)
|
||||
{
|
||||
// calcolo il dizionario degli elementi...
|
||||
Dictionary<string, ProdMachineDetailDto> newWorkGroupList = new();
|
||||
foreach (var machineName in item.Machines)
|
||||
{
|
||||
decimal effectiveTime = 0;
|
||||
// Recuperiamo i dati della macchina dal dizionario
|
||||
if (machineTags.TryGetValue(machineName, out var machineParts))
|
||||
{
|
||||
// Creiamo un set dei tag del gruppo per una ricerca veloce O(1)
|
||||
var groupTagsSet = item.Tags.ToHashSet();
|
||||
|
||||
// Sommiamo il tempo solo per i pezzi che appartengono a questo gruppo
|
||||
effectiveTime = machineParts
|
||||
.Where(p => groupTagsSet.Contains(p.Tag))
|
||||
.Sum(p => p.Time);
|
||||
}
|
||||
|
||||
ProdMachineDetailDto detProd = new ProdMachineDetailDto()
|
||||
{
|
||||
TagList = item.Tags,
|
||||
Time = effectiveTime // Tempo reale specifico per questa macchina/gruppo
|
||||
};
|
||||
newWorkGroupList.Add(machineName, detProd);
|
||||
}
|
||||
string rawWGL = JsonConvert.SerializeObject(newWorkGroupList);
|
||||
ProductionGroupModel newRec = new ProductionGroupModel()
|
||||
{
|
||||
OrderRowID = currRec.OrderRowID,
|
||||
GrpIdx = grpIdx++,
|
||||
WorkGroupListRaw = rawWGL
|
||||
};
|
||||
listProdGroup2Add.Add(newRec);
|
||||
}
|
||||
// aggiungo i record...
|
||||
dbCtx.DbSetProdGroup.AddRange(listProdGroup2Add);
|
||||
|
||||
// aggiorno info Estimation, tempi e stato
|
||||
currRec.ProdEstimate = prodEstim;
|
||||
if (!string.IsNullOrEmpty(prodEstim))
|
||||
{
|
||||
currRec.OrderRowState = OrderStates.Estimated;
|
||||
}
|
||||
var totEstim = listProdGroup2Add.Sum(x => x.TotalEstimTime);
|
||||
currRec.ProdEstimTime = totEstim;
|
||||
dbCtx.Entry(currRec).State = EntityState.Modified;
|
||||
}
|
||||
|
||||
// salvo TUTTI i cambiamenti...
|
||||
var result = await dbCtx.SaveChangesAsync();
|
||||
answ = result > 0;
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante OrderRowUpsertProdEst{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validazione record:
|
||||
/// - controllo state vs estimate
|
||||
/// - segnala il numero dei record aggiornati
|
||||
/// </summary>
|
||||
/// <param name="list2chk">Elenco record da verificare</param>
|
||||
internal async Task<int> OrderRowListValidate(List<OrderRowModel> list2chk)
|
||||
{
|
||||
int numDone = 0;
|
||||
// verifica preliminare: serve SSE stato e estimate non corrispondono...
|
||||
var list2fix = list2chk
|
||||
.Where(x => x.OrderRowState == OrderStates.Created && !string.IsNullOrEmpty(x.ProdEstimate))
|
||||
.ToList();
|
||||
if (list2fix.Any())
|
||||
{
|
||||
// per ogni record processo intera validazione
|
||||
foreach (var item in list2fix)
|
||||
{
|
||||
bool fatto = await OrderRowUpsertProdEst(item.OrderRowUID, item.ProdEstimate);
|
||||
numDone += fatto ? 1 : 0;
|
||||
}
|
||||
}
|
||||
return numDone;
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Elenco record Fasi da DB
|
||||
/// </summary>
|
||||
@@ -442,6 +243,7 @@ namespace EgwCoreLib.Lux.Data.Controllers
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Add record di un singolo ProdGroup da fase Balance
|
||||
/// </summary>
|
||||
@@ -515,7 +317,8 @@ namespace EgwCoreLib.Lux.Data.Controllers
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if true
|
||||
/// <summary>
|
||||
@@ -602,106 +405,6 @@ namespace EgwCoreLib.Lux.Data.Controllers
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Esegue merge dei dati nella tab profili del DB con le info accessorie...
|
||||
/// </summary>
|
||||
/// <param name="uID"></param>
|
||||
/// <param name="execEnvironment"></param>
|
||||
/// <param name="rawContent"></param>
|
||||
/// <returns></returns>
|
||||
internal async Task<bool> SaveProfileListAsync(string uID, Constants.EXECENVIRONMENTS execEnvironment, string rawContent)
|
||||
{
|
||||
bool answ = false;
|
||||
//using (DataLayerContext dbCtx = new DataLayerContext(_config))
|
||||
using (DataLayerContext dbCtx = new DataLayerContext())
|
||||
{
|
||||
// solo se ho qualcosa da controllare...
|
||||
if (!string.IsNullOrEmpty(rawContent))
|
||||
{
|
||||
// in primis recupero profili attuali
|
||||
var dbList = await dbCtx
|
||||
.DbSetConfProfile
|
||||
.ToListAsync();
|
||||
|
||||
// ciclo sul contenuto ricevuto, se mancasse aggiungo!
|
||||
List<string> list2check = JsonConvert.DeserializeObject<List<string>>(rawContent) ?? new List<string>();
|
||||
List<ProfileModel> rec2ins = new List<ProfileModel>();
|
||||
foreach (var item in list2check)
|
||||
{
|
||||
if (!dbList.Any(x => x.Code == item))
|
||||
{
|
||||
rec2ins.Add(new ProfileModel() { Code = item, Description = $"{item} - NEW" });
|
||||
}
|
||||
}
|
||||
|
||||
// se ho dati li inserisco...
|
||||
if (rec2ins.Count > 0)
|
||||
{
|
||||
dbCtx.DbSetConfProfile.AddRange(rec2ins);
|
||||
// salvo...
|
||||
int numDone = await dbCtx.SaveChangesAsync();
|
||||
answ = numDone > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Salvataggio info serializzate x soglie e dati opzionali sul DB
|
||||
/// </summary>
|
||||
/// <param name="uID"></param>
|
||||
/// <param name="execEnvironment"></param>
|
||||
/// <param name="rawThreshold"></param>
|
||||
/// <param name="rawData"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
internal async Task<bool> SaveProfileThreshAsync(string uID, Constants.EXECENVIRONMENTS execEnvironment, string rawThreshold, string rawData)
|
||||
{
|
||||
bool answ = false;
|
||||
//using (DataLayerContext dbCtx = new DataLayerContext(_config))
|
||||
using (DataLayerContext dbCtx = new DataLayerContext())
|
||||
{
|
||||
// solo se ho qualcosa da controllare...
|
||||
if (!string.IsNullOrEmpty(rawThreshold) || !string.IsNullOrEmpty(rawData))
|
||||
{
|
||||
// in primis recupero profilo da aggiornare
|
||||
var dbRec = await dbCtx
|
||||
.DbSetConfProfile
|
||||
.Where(x => x.Code == uID)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
// se ho record aggiorno...
|
||||
if (dbRec != null)
|
||||
{
|
||||
dbRec.ProfDataRaw = rawData;
|
||||
dbRec.ThreshDataRaw = rawThreshold;
|
||||
dbCtx.Entry(dbRec).State = EntityState.Modified;
|
||||
}
|
||||
// alrimenti creo + aggiorno
|
||||
else
|
||||
{
|
||||
dbCtx.DbSetConfProfile.Add(new ProfileModel()
|
||||
{
|
||||
Code = uID,
|
||||
Description = $"{uID} - NEW PROFILE",
|
||||
ProfDataRaw = rawData,
|
||||
ThreshDataRaw = rawThreshold
|
||||
});
|
||||
}
|
||||
// salvo...
|
||||
int numDone = await dbCtx.SaveChangesAsync();
|
||||
answ = numDone > 0;
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Elenco da DB delel stats aggregate dato periodo inizio/fine
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user