using System; using System.Collections.Generic; using System.Linq; namespace wms.service.Extensions.LayerPacking.model { /// /// 箱信息 /// public class LayerPackingBoxInfo { /// /// 箱ID /// [Obsolete] public string BoxId { get; set; } /// /// 箱产品 /// public List Layers { get; set; } /// /// 箱总扭转值 /// public decimal TotalTorsion => Layers.Sum(l => l.TotalTorsion); /// /// 箱总焊点盘数 /// public int SolderProductCount => Layers.Sum(l => l.SolderProductCount); /// /// 箱总焊点数 /// public decimal TotalSolderJoints => Layers.Sum(l => l.TotalSolderJoints); /// /// 成箱时间 /// public DateTime PackingTime { get; set; } /// /// 最小箱目标 /// public decimal MinBoxTarget { get; set; } /// /// 最大箱目标 /// public decimal MaxBoxTarget { get; set; } /// /// 箱目标 /// public decimal BoxTarget { get; set; } /// /// 装箱时的产品池平均值 /// public decimal ProductPoolAverage { get; set; } /// /// 构造函数 /// public LayerPackingBoxInfo() { Layers = new List(); PackingTime = DateTime.Now; } /// /// 判断当前箱是否有效 /// /// /// public bool IsValid(LayerPackingConstraints constraints) { var total = TotalTorsion; bool torsionValid = total >= constraints.MinBoxTotal && total <= constraints.MaxBoxTotal && Layers.All(l => l.IsValid(constraints)); if (!torsionValid) return false; var constraintType = constraints.GetSolderConstraintType(); return constraintType switch { SolderConstraintType.NoConstraint => true, SolderConstraintType.OnlyProductCount => SolderProductCount <= constraints.SolderMaxCount, SolderConstraintType.BothConstraints => SolderProductCount <= constraints.SolderMaxCount && TotalSolderJoints <= constraints.PerSolderMaxCount, _ => true, }; } /// /// 箱极值对是否有效 /// /// 大极值阈值 /// 小极值阈值 /// public bool HasValidExtremePairs(decimal highThreshold, decimal lowThreshold) { return Layers.All(l => l.HasValidExtremePair(highThreshold, lowThreshold)); } /// /// 获取偏差 /// /// /// public decimal GetDeviationFromTarget(decimal target) { return Math.Abs(TotalTorsion - target); } /// /// 获取产品总数 /// /// public int GetTotalProductCount() { return Layers.Sum(l => l.Products.Count); } } }