using EgwCoreLib.Lux.Core.Generic;
using EgwCoreLib.Lux.Data.DbModel.Sales;
using Newtonsoft.Json;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using static EgwCoreLib.Lux.Core.Enums;
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;
///
/// Tipologia del raggruppamento secondo lavorabilità
///
public ProdGroupType GrpType { get; set; } = ProdGroupType.Undef;
///
/// Codice Gruppo calcolato dal tipo
///
[NotMapped]
public string GroupCode
{
get => $"G{(int)GrpType:00}";
}
///
/// 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;
}
}
///
/// Num parts complessivamente incluse
///
[NotMapped]
public int NumParts => WorkGroupList?.Sum(x => x.Value.NumParts) ?? 0;
///
/// Tempo stimato complessivo
///
[NotMapped]
public double TotalEstimTime => WorkGroupList?.Sum(x => x.Value.Time) ?? 0;
///
/// Elenco dei Plants riferiti
///
[NotMapped]
public List PlantList => WorkGroupList?
.Select(x => x.Key)
.Distinct()
.ToList() ?? new List();
///
/// Navigazione OrderRow
///
[ForeignKey("OrderRowID")]
public virtual OrderRowModel OrderRowNav { get; set; } = null!;
}
}