LayerPackingBoxInfo.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace wms.service.Help.LayerPacking.model
  5. {
  6. /// <summary>
  7. /// 箱信息
  8. /// </summary>
  9. public class LayerPackingBoxInfo
  10. {
  11. /// <summary>
  12. /// 箱ID
  13. /// </summary>
  14. [Obsolete]
  15. public string BoxId { get; set; }
  16. /// <summary>
  17. /// 箱产品
  18. /// </summary>
  19. public List<LayerPackingLayerInfo> Layers { get; set; }
  20. /// <summary>
  21. /// 所有产品
  22. /// </summary>
  23. public List<LayerPackingProduct> TotalProduct => Layers.SelectMany(l => l.Products).ToList();
  24. /// <summary>
  25. /// 箱总扭转值
  26. /// </summary>
  27. public decimal TotalTorsion => Layers.Sum(l => l.TotalTorsion);
  28. /// <summary>
  29. /// 箱总焊点盘数
  30. /// </summary>
  31. public int SolderProductCount => Layers.Sum(l => l.SolderProductCount);
  32. /// <summary>
  33. /// 箱总焊点数
  34. /// </summary>
  35. public decimal TotalSolderJoints => Layers.Sum(l => l.TotalSolderJoints);
  36. /// <summary>
  37. /// 成箱时间
  38. /// </summary>
  39. public DateTime PackingTime { get; set; }
  40. /// <summary>
  41. /// 最小箱目标
  42. /// </summary>
  43. public decimal MinBoxTarget { get; set; }
  44. /// <summary>
  45. /// 最大箱目标
  46. /// </summary>
  47. public decimal MaxBoxTarget { get; set; }
  48. /// <summary>
  49. /// 箱目标
  50. /// </summary>
  51. public decimal BoxTarget { get; set; }
  52. /// <summary>
  53. /// 装箱时的产品池平均值
  54. /// </summary>
  55. public decimal ProductPoolAverage { get; set; }
  56. /// <summary>
  57. /// 构造函数
  58. /// </summary>
  59. public LayerPackingBoxInfo()
  60. {
  61. Layers = new List<LayerPackingLayerInfo>();
  62. PackingTime = DateTime.Now;
  63. }
  64. /// <summary>
  65. /// 判断当前箱是否有效
  66. /// </summary>
  67. /// <param name="constraints"></param>
  68. /// <returns></returns>
  69. public bool IsValid(LayerPackingConstraints constraints)
  70. {
  71. var total = TotalTorsion;
  72. bool torsionValid = total >= constraints.MinBoxTotal && total <= constraints.MaxBoxTotal && Layers.All(l => l.IsValid(constraints));
  73. if (!torsionValid) return false;
  74. var constraintType = constraints.GetSolderConstraintType();
  75. return constraintType switch
  76. {
  77. SolderConstraintType.NoConstraint => true,
  78. SolderConstraintType.OnlyProductCount => SolderProductCount <= constraints.SolderMaxCount,
  79. SolderConstraintType.BothConstraints => SolderProductCount <= constraints.SolderMaxCount && TotalSolderJoints <= constraints.PerSolderMaxCount,
  80. _ => true,
  81. };
  82. }
  83. /// <summary>
  84. /// 箱极值对是否有效
  85. /// </summary>
  86. /// <param name="highThreshold">大极值阈值</param>
  87. /// <param name="lowThreshold">小极值阈值</param>
  88. /// <returns></returns>
  89. public bool HasValidExtremePairs(decimal highThreshold, decimal lowThreshold)
  90. {
  91. return Layers.All(l => l.HasValidExtremePair(highThreshold, lowThreshold));
  92. }
  93. /// <summary>
  94. /// 获取偏差
  95. /// </summary>
  96. /// <param name="target"></param>
  97. /// <returns></returns>
  98. public decimal GetDeviationFromTarget(decimal target)
  99. {
  100. return Math.Abs(TotalTorsion - target);
  101. }
  102. /// <summary>
  103. /// 获取产品总数
  104. /// </summary>
  105. /// <returns></returns>
  106. public int GetTotalProductCount()
  107. {
  108. return Layers.Sum(l => l.Products.Count);
  109. }
  110. }
  111. }