FinishTaskList.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using WCS.Service.Entity;
  4. using WCS.Service.Extensions;
  5. using WCS.Service.Log;
  6. namespace WCS.Service.Helpers
  7. {
  8. /// <summary>
  9. /// 处理完成任务记录集合
  10. /// </summary>
  11. /// <typeparam name="T"></typeparam>
  12. public class FinishTaskList<T>
  13. {
  14. public FinishTaskList(T finishCode, StationDevice station)
  15. {
  16. FinishCode = finishCode;
  17. Station = station;
  18. }
  19. /// <summary>
  20. /// 完成
  21. /// </summary>
  22. public T FinishCode { get; set; }
  23. /// <summary>
  24. /// 对应设备信息
  25. /// </summary>
  26. public StationDevice Station { get; set; }
  27. }
  28. /// <summary>
  29. /// 处理完成任务记录集合
  30. /// </summary>
  31. /// <typeparam name="T"></typeparam>
  32. public class FinishTaskList<T, T1>
  33. {
  34. public FinishTaskList(T finishCode, T1 station)
  35. {
  36. FinishCode = finishCode;
  37. Station = station;
  38. }
  39. /// <summary>
  40. /// 完成
  41. /// </summary>
  42. public T FinishCode { get; set; }
  43. /// <summary>
  44. /// 对应设备信息
  45. /// </summary>
  46. public T1 Station { get; set; }
  47. }
  48. public static class FinishTaskListExtensions
  49. {
  50. /// <summary>
  51. /// 入库可用任务数是否有效
  52. /// </summary>
  53. /// <param name="finishes"></param>
  54. /// <exception cref="WarnException"></exception>
  55. public static bool Valid(this List<FinishTaskList<string>> finishes, string code)
  56. {
  57. var res = true;
  58. var maxGoodsnum = finishes.Select(v => v.Station.Data2.Goodsnum).OrderByDescending(v => v).FirstOrDefault();
  59. if (finishes.Count != maxGoodsnum)
  60. {
  61. InfoLog.INFO_WarnDb($"可用货物数{finishes.Count},实际货物数{maxGoodsnum}", code, WCS.Entity.WCS_EXCEPTIONTYPE.逻辑异常);
  62. res = false;
  63. };
  64. if (!finishes.Any())
  65. {
  66. InfoLog.INFO_WarnDb("没有任务", code, WCS.Entity.WCS_EXCEPTIONTYPE.逻辑异常);
  67. res = false;
  68. }
  69. return res;
  70. }
  71. /// <summary>
  72. /// 入库可用任务数是否有效
  73. /// </summary>
  74. /// <param name="finishes"></param>
  75. /// <exception cref="WarnException"></exception>
  76. public static List<I_WCS_GetInTaskResponseItem> GetWMSInTask(this List<FinishTaskList<string>> finishes)
  77. {
  78. if (!finishes.Any()) throw new DoException("没有任务");
  79. var items = finishes.ToArray();
  80. var infos = items.Length switch
  81. {
  82. 1 => WMS.I_WCS_GetInTask(items[0].FinishCode, items[0].Station.Entity.CODE),
  83. 2 => WMS.I_WCS_GetInTask(items[0].FinishCode, items[0].Station.Entity.CODE, items[1].FinishCode, items[1].Station.Entity.CODE),
  84. _ => throw new WarnException($"一组任务数量最大为2,当前{items.Length}"),
  85. };
  86. return infos;
  87. }
  88. }
  89. }