| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace wms.service.Extensions.LayerPacking.model
- {
- /// <summary>
- /// 箱信息
- /// </summary>
- public class LayerPackingBoxInfo
- {
- /// <summary>
- /// 箱ID
- /// </summary>
- [Obsolete]
- public string BoxId { get; set; }
- /// <summary>
- /// 箱产品
- /// </summary>
- public List<LayerPackingLayerInfo> Layers { get; set; }
- /// <summary>
- /// 箱总扭转值
- /// </summary>
- public decimal TotalTorsion => Layers.Sum(l => l.TotalTorsion);
- /// <summary>
- /// 箱总焊点盘数
- /// </summary>
- public int SolderProductCount => Layers.Sum(l => l.SolderProductCount);
- /// <summary>
- /// 箱总焊点数
- /// </summary>
- public decimal TotalSolderJoints => Layers.Sum(l => l.TotalSolderJoints);
- /// <summary>
- /// 成箱时间
- /// </summary>
- public DateTime PackingTime { get; set; }
- /// <summary>
- /// 最小箱目标
- /// </summary>
- public decimal MinBoxTarget { get; set; }
- /// <summary>
- /// 最大箱目标
- /// </summary>
- public decimal MaxBoxTarget { get; set; }
- /// <summary>
- /// 箱目标
- /// </summary>
- public decimal BoxTarget { get; set; }
- /// <summary>
- /// 装箱时的产品池平均值
- /// </summary>
- public decimal ProductPoolAverage { get; set; }
- /// <summary>
- /// 构造函数
- /// </summary>
- public LayerPackingBoxInfo()
- {
- Layers = new List<LayerPackingLayerInfo>();
- PackingTime = DateTime.Now;
- }
- /// <summary>
- /// 判断当前箱是否有效
- /// </summary>
- /// <param name="constraints"></param>
- /// <returns></returns>
- 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,
- };
- }
- /// <summary>
- /// 箱极值对是否有效
- /// </summary>
- /// <param name="highThreshold">大极值阈值</param>
- /// <param name="lowThreshold">小极值阈值</param>
- /// <returns></returns>
- public bool HasValidExtremePairs(decimal highThreshold, decimal lowThreshold)
- {
- return Layers.All(l => l.HasValidExtremePair(highThreshold, lowThreshold));
- }
- /// <summary>
- /// 获取偏差
- /// </summary>
- /// <param name="target"></param>
- /// <returns></returns>
- public decimal GetDeviationFromTarget(decimal target)
- {
- return Math.Abs(TotalTorsion - target);
- }
- /// <summary>
- /// 获取产品总数
- /// </summary>
- /// <returns></returns>
- public int GetTotalProductCount()
- {
- return Layers.Sum(l => l.Products.Count);
- }
- }
- }
|