FinishTaskList.cs 2.4 KB

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