WmsApi.cs 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using ServiceCenter.Redis;
  2. using ServiceCenter.WebApi;
  3. using WCS.WorkEngineering.WebApi.Models.WMS.Request;
  4. using WCS.WorkEngineering.WebApi.Models.WMS.Response;
  5. using WCS.WorkEngineering.Worlds.Logs;
  6. namespace WCS.WorkEngineering.WebApi.Controllers
  7. {
  8. /// <summary>
  9. /// AGV相关接口控制器
  10. /// </summary>
  11. public static class WmsApi
  12. {
  13. private static string _WMSUrl = null!;
  14. private static string _wareHouseId = null!;
  15. /// <summary>
  16. /// WMS URL
  17. /// </summary>
  18. public static string WMSUrl
  19. {
  20. get
  21. {
  22. _WMSUrl ??= RedisHub.Default.Check("WMSUrl");
  23. if (string.IsNullOrEmpty(_WMSUrl))
  24. {
  25. throw new KnownException($"请在Redis配置WMSUrl", LogLevelEnum.High);
  26. }
  27. return _WMSUrl;
  28. }
  29. }
  30. /// <summary>
  31. /// 仓库编号
  32. /// </summary>
  33. public static string wareHouseId
  34. {
  35. get
  36. {
  37. _wareHouseId ??= RedisHub.Default.Check("wareHouseId");
  38. if (string.IsNullOrEmpty(_wareHouseId))
  39. {
  40. throw new KnownException($"请在Redis配置wareHouseId", LogLevelEnum.High);
  41. }
  42. return _wareHouseId;
  43. }
  44. }
  45. /// <summary>
  46. /// 分配货位
  47. /// </summary>
  48. /// <param name="wcsTaskNum">WMS任务ID</param>
  49. /// <param name="tunnel">巷道</param>
  50. /// <param name="device">设备号</param>
  51. /// <returns></returns>
  52. /// <exception cref="Exception"></exception>
  53. public static I_WCS_GetWareCellResponse GetLocalIn(int wcsTaskNum, string tunnel, string device)
  54. {
  55. var res = APICaller.CallApi2<I_WCS_GetWareCellResponse>(WMSUrl + "/api/Task/I_WCS_GetWareCell", new I_WCS_GetWareCellRequest
  56. {
  57. PickUpEquipmentNo = device,
  58. TunnelNum = tunnel.Last().ToString(),
  59. WCSTaskNum = wcsTaskNum.ToString(),
  60. });
  61. if (!res.ResType)
  62. {
  63. throw new KnownException(res.ResMessage, LogLevelEnum.High);
  64. }
  65. return res;
  66. }
  67. /// <summary>
  68. /// 向WMS获取入库任务 一次单卷
  69. /// </summary>
  70. /// <param name="barcode">产品条码</param>
  71. /// <param name="devCode">设备条码</param>
  72. /// <param name="getTunnel"></param>
  73. /// <returns></returns>
  74. /// <exception cref="Exception"></exception>
  75. public static I_WCS_GetInTaskResponse I_WCS_GetInTask(string barcode, string devCode, bool getTunnel = false)
  76. {
  77. var res = APICaller.CallApi<I_WCS_GetInTaskResponse>(WMSUrl + "/api/Task/I_WCS_GetInTask", new List<I_WCS_GetInTaskRequest>()
  78. {
  79. new I_WCS_GetInTaskRequest(){
  80. ContainerBarCode = barcode,
  81. WareHouseId = wareHouseId,
  82. EquipmentNo = devCode,
  83. Memo1 = getTunnel ? "1" : "" //1:分巷道 2:分货位
  84. }
  85. });
  86. if (!res.ResType) throw new KnownException(res.ResMessage, LogLevelEnum.High);
  87. return res;
  88. }
  89. }
  90. }