FinishTaskList.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using WCS.Service.Entity;
  5. using WCS.Service.Extensions;
  6. using WCS.Service.Log;
  7. namespace WCS.Service.Helpers
  8. {
  9. /// <summary>
  10. /// 处理完成任务记录集合
  11. /// </summary>
  12. /// <typeparam name="T"></typeparam>
  13. public class FinishTaskList<T>
  14. {
  15. /// <summary>
  16. /// 完成
  17. /// </summary>
  18. public T FinishCode { get; set; }
  19. /// <summary>
  20. /// 对应设备信息
  21. /// </summary>
  22. public StationDevice Station { get; set; }
  23. }
  24. public static class FinishTaskListExtensions
  25. {
  26. /// <summary>
  27. /// 入库可用任务数是否有效
  28. /// </summary>
  29. /// <param name="finishes"></param>
  30. /// <exception cref="WarnException"></exception>
  31. public static void Valid(this List<FinishTaskList<string>> finishes)
  32. {
  33. var maxGoodsnum = finishes.Select(v => v.Station.Data2.Goodsnum).OrderByDescending(v => v).FirstOrDefault();
  34. if (finishes.Count != maxGoodsnum) throw new WarnException($"可用货物数{finishes.Count},实际货物数{maxGoodsnum}");
  35. if (!finishes.Any()) throw new DoException("没有任务");
  36. }
  37. /// <summary>
  38. /// 入库可用任务数是否有效
  39. /// </summary>
  40. /// <param name="finishes"></param>
  41. /// <exception cref="WarnException"></exception>
  42. public static List<I_WCS_GetInTaskResponseItem> GetWMSInTask(this List<FinishTaskList<string>> finishes)
  43. {
  44. if (!finishes.Any()) throw new DoException("没有任务");
  45. var items = finishes.ToArray();
  46. var now = DateTime.Now;
  47. var infos = items.Length switch
  48. {
  49. 1 => WMS.I_WCS_GetInTask(items[0].FinishCode, items[0].Station.Entity.CODE),
  50. 2 => WMS.I_WCS_GetInTask(items[0].FinishCode, items[0].Station.Entity.CODE, items[1].FinishCode, items[1].Station.Entity.CODE),
  51. _ => throw new WarnException($"一组任务数量最大为2,当前{items.Length}"),
  52. };
  53. var time = DateTime.Now;
  54. InfoLog.INFO_TIMING($"扫码入库接口调用,耗时{(time - now).TotalMilliseconds},{now}-----{time}");
  55. return infos;
  56. }
  57. }
  58. }