using EgwCoreLib.Lux.Core.Generic;
namespace EgwCoreLib.Lux.Data.DbModel.Production
{
///
/// Classe che rappresenta la suddivisione in gruppi di un POR
/// - nasce in fase di Balance
/// - serve x successive fasi di raggruppamento/split
/// - indipendente dall'assegnazione effettiva alle macchine
///
[Table("production_group")]
public class ProductionGroupModel
{
[Key]
public int ProdGroupID { get; set; }
///
/// Ordine cui fa riferimento
///
public int OrderRowID { get; set; } = 0;
///
/// Indice di raggruppamento secondo lavorabilità (Comb Dist 0..N impianti)
///
public int GrpIdx { get; set; } = 0;
#if false
///
/// Codice Gruppo calcolato dal tipo
///
[NotMapped]
public string GroupCode
{
get => $"G{(int)GrpIdx:00}";
}
#endif
///
/// Codice Gruppo calcolato dal tipo
///
[NotMapped]
public string ReqUID
{
get => $"{OrderRowNav?.OrderRowUID ?? "NA"}:{GrpIdx}";
}
///
/// Valore effettivo serializzato dei WorkgroupList
///
public string WorkGroupListRaw { get; set; } = "";
///
/// Elenco valori dei prod workgroup stimati gestito come JSON serializzato/deserializzato al volo
///
[NotMapped]
public Dictionary WorkGroupList
{
get
{
Dictionary answ = new();
if (!string.IsNullOrEmpty(WorkGroupListRaw))
{
answ = JsonConvert.DeserializeObject>(WorkGroupListRaw) ?? new();
}
return answ;
}
}
///
/// Bar qty complessiva
///
[NotMapped]
public int BarQty => WorkGroupList?.Sum(x => x.Value.BarQty) ?? 0;
///
/// Num parts complessivamente incluse
///
[NotMapped]
public int NumParts => WorkGroupList?.Max(x => x.Value.NumParts) ?? 0;
///
/// Tempo stimato complessivo
/// - se BarQty = 0 --> MAX
/// - se BarQty > 0 --> SUM
///
[NotMapped]
public decimal TotalEstimTime
{
get
{
decimal answ = 0;
if (WorkGroupList != null && WorkGroupList.Count > 0)
{
if (WorkGroupList?.FirstOrDefault().Value.BarQty > 0)
{
answ = WorkGroupList?.Sum(x => x.Value.Time) ?? 0;
}
else
{
answ = WorkGroupList?.Max(x => x.Value.Time) ?? 0;
}
}
return answ;
}
}
///
/// Elenco dei Plants riferiti nel gruppo
///
[NotMapped]
public List PlantList => WorkGroupList?
.Select(x => x.Key)
.Distinct()
.ToList() ?? new List();
///
/// Elenco Macchine in formato stringa join
///
[NotMapped]
public string PlantListJoin
{
get => string.Join(", ", PlantList.Select(x => x).OrderBy(x => x).ToList());
}
///
/// Navigazione OrderRow
///
[ForeignKey("OrderRowID")]
public virtual OrderRowModel OrderRowNav { get; set; } = null!;
///
/// Navigazione sugli items collegati
///
public virtual ICollection ItemsNav { get; set; } = new HashSet();
}
}