Files
lux/EgwCoreLib.Lux.Data/DbModel/Production/ProductionGroupModel.cs
T
2026-03-25 07:24:21 +01:00

137 lines
4.1 KiB
C#

using EgwCoreLib.Lux.Core.Generic;
namespace EgwCoreLib.Lux.Data.DbModel.Production
{
/// <summary>
/// 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
/// </summary>
[Table("production_group")]
public class ProductionGroupModel
{
[Key]
public int ProdGroupID { get; set; }
/// <summary>
/// Ordine cui fa riferimento
/// </summary>
public int OrderRowID { get; set; } = 0;
/// <summary>
/// Indice di raggruppamento secondo lavorabilità (Comb Dist 0..N impianti)
/// </summary>
public int GrpIdx { get; set; } = 0;
#if false
/// <summary>
/// Codice Gruppo calcolato dal tipo
/// </summary>
[NotMapped]
public string GroupCode
{
get => $"G{(int)GrpIdx:00}";
}
#endif
/// <summary>
/// Codice Gruppo calcolato dal tipo
/// </summary>
[NotMapped]
public string ReqUID
{
get => $"{OrderRowNav?.OrderRowUID ?? "NA"}:{GrpIdx}";
}
/// <summary>
/// Valore effettivo serializzato dei WorkgroupList
/// </summary>
public string WorkGroupListRaw { get; set; } = "";
/// <summary>
/// Elenco valori dei prod workgroup stimati gestito come JSON serializzato/deserializzato al volo
/// </summary>
[NotMapped]
public Dictionary<string, ProdMachineDetailDto> WorkGroupList
{
get
{
Dictionary<string, ProdMachineDetailDto> answ = new();
if (!string.IsNullOrEmpty(WorkGroupListRaw))
{
answ = JsonConvert.DeserializeObject<Dictionary<string, ProdMachineDetailDto>>(WorkGroupListRaw) ?? new();
}
return answ;
}
}
/// <summary>
/// Bar qty complessiva
/// </summary>
[NotMapped]
public int BarQty => WorkGroupList?.Sum(x => x.Value.BarQty) ?? 0;
/// <summary>
/// Num parts complessivamente incluse
/// </summary>
[NotMapped]
public int NumParts => WorkGroupList?.Sum(x => x.Value.NumParts) ?? 0;
/// <summary>
/// Tempo stimato complessivo
/// - se BarQty = 0 --> MAX
/// - se BarQty > 0 --> SUM
/// </summary>
[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;
}
}
/// <summary>
/// Elenco dei Plants riferiti nel gruppo
/// </summary>
[NotMapped]
public List<string> PlantList => WorkGroupList?
.Select(x => x.Key)
.Distinct()
.ToList() ?? new List<string>();
/// <summary>
/// Elenco Macchine in formato stringa join
/// </summary>
[NotMapped]
public string PlantListJoin
{
get => string.Join(", ", PlantList.Select(x => x).OrderBy(x => x).ToList());
}
/// <summary>
/// Navigazione OrderRow
/// </summary>
[ForeignKey("OrderRowID")]
public virtual OrderRowModel OrderRowNav { get; set; } = null!;
/// <summary>
/// Navigazione sugli items collegati
/// </summary>
public virtual ICollection<ProductionItemModel> ItemsNav { get; set; } = new HashSet<ProductionItemModel>();
}
}