LayerPackingBoxInfo.cs 3.6 KB

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