满轮主线预写入目标地址.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. using Newtonsoft.Json;
  2. using PlcSiemens.Core.Extension;
  3. using ServiceCenter.Extensions;
  4. using ServiceCenter.Logs;
  5. using ServiceCenter.Redis;
  6. using ServiceCenter.SqlSugars;
  7. using System.ComponentModel;
  8. using WCS.Core;
  9. using WCS.Entity;
  10. using WCS.Entity.Protocol.BCR;
  11. using WCS.Entity.Protocol.Station;
  12. using WCS.WorkEngineering.Extensions;
  13. using WCS.WorkEngineering.Worlds;
  14. using wms.service.Service;
  15. using TaskStatus = WCS.Entity.TaskStatus;
  16. namespace WCS.WorkEngineering.Systems
  17. {
  18. /// <summary>
  19. /// 满轮主线预写入目标地址
  20. /// </summary>
  21. [BelongTo(typeof(SortingMainLineWorld))]
  22. [Description("满轮主线预写入目标地址")]
  23. public class 满轮主线预写入目标地址 : DeviceSystem<Device<IStation523, IBCR83, IStation525>>
  24. {
  25. protected override bool ParallelDo => true;
  26. public override void Do(Device<IStation523, IBCR83, IStation525> obj)
  27. {
  28. var devCode = obj.Entity.Code switch
  29. {
  30. "18" => "22",
  31. "38" => "41",
  32. "58" => "61",
  33. "118" => "122",
  34. "138" => "141",
  35. "158" => "161",
  36. _ => throw new ArgumentOutOfRangeException()
  37. };
  38. var dev = new Device<IStation520>(Device.All.First(x => x.Code == devCode), World);
  39. dev.Data.Mode = StationMode.Automatic;
  40. //从DB83中获取待处理条码组
  41. var pendingBcrList = obj.Data2.GetBcrCodeList().Where(x => !x.IsNullOrEmpty());
  42. //从DB525获取已处理条码组
  43. var cacheBcrList = obj.Data3.GetBcrCodeList();
  44. //筛选出未处理条码组
  45. var codes = pendingBcrList.Where(x => !cacheBcrList.Contains(x));
  46. World.Log($"扫码器:{JsonConvert.SerializeObject(pendingBcrList)}");
  47. World.Log($"缓存信息:{JsonConvert.SerializeObject(cacheBcrList)}");
  48. //循环处理所有缓存条码组中没有的条码
  49. foreach (var bcrCode in codes)
  50. {
  51. ////取出预分配地址,并计算相关信息
  52. //var key = $"AllocationWarehouseSort:{bcrCode}";
  53. //var value = RedisHub.WMS.Get(key);
  54. //if (value == null)
  55. //{
  56. // World.Log($"{bcrCode}:找不到分库记录", LogLevelEnum.High);
  57. // continue;
  58. //}
  59. //var mainlineDiversion = JsonConvert.DeserializeObject<MainlineDiversion>(value);
  60. WCS_TaskInfo taskInfo = null;
  61. try
  62. {
  63. SqlSugarHelper.Do(_db =>
  64. {
  65. var db = _db.Default;
  66. var task = db.Queryable<WCS_TaskInfo>().NoLock().Single(x => x.BarCode == bcrCode && x.Status == TaskStatus.NewBuild);
  67. if (task == null)
  68. {
  69. World.Log($"{bcrCode}:找不到匹配的新建任务", LogLevelEnum.High);
  70. return;
  71. }
  72. taskInfo = task;
  73. });
  74. }
  75. catch (Exception e)
  76. {
  77. World.Log($"{bcrCode}:----{e.Message}", LogLevelEnum.High);
  78. continue;
  79. }
  80. var srmCode = taskInfo.WarehouseCode.WarehouseToSrm();
  81. var path = DevicePath.GetPath(obj.Entity.Code, srmCode);
  82. if (path == null || path is { Points.Count: < 2 })
  83. {
  84. World.Log($"{bcrCode}:路径错误,当前位置{obj.Entity.Code},目标位置:{srmCode}", LogLevelEnum.High);
  85. continue;
  86. }
  87. var next = path.Points[1].Code;
  88. if (taskInfo == null) continue;
  89. //开始赋值
  90. obj.Data3.GetType().GetProperty($"BcrCode{obj.Data3.NextIndex}").SetValue(obj.Data3, bcrCode);
  91. obj.Data3.GetType().GetProperty($"BcrCode{obj.Data3.NextIndex}").SetValue(obj.Data3, bcrCode);
  92. obj.Data3.GetType().GetProperty($"TaskNumber{obj.Data3.NextIndex}").SetValue(obj.Data3, taskInfo.ID);
  93. obj.Data3.GetType().GetProperty($"TaskNumber{obj.Data3.NextIndex}").SetValue(obj.Data3, taskInfo.ID);
  94. obj.Data3.GetType().GetProperty($"GoodsEnd{obj.Data3.NextIndex}").SetValue(obj.Data3, next.ToShort());
  95. obj.Data3.GetType().GetProperty($"GoodsEnd{obj.Data3.NextIndex}").SetValue(obj.Data3, next.ToShort());
  96. if (obj.Data3.NextIndex >= 49)
  97. {
  98. obj.Data3.NextIndex = 0;
  99. }
  100. else
  101. {
  102. obj.Data3.NextIndex++;
  103. }
  104. }
  105. dev.Data.Mode = StationMode.Automatic;
  106. }
  107. public override bool Select(Device dev)
  108. {
  109. return dev.Code is "18" or "118" or "38" or "58" or "138" or "158";
  110. }
  111. }
  112. /// <summary>
  113. /// 主线分流
  114. /// </summary>
  115. public class MainlineDiversion
  116. {
  117. /// <summary>
  118. /// 任务号
  119. /// </summary>
  120. public int TaskId { get; set; }
  121. /// <summary>
  122. /// 仓库号
  123. /// </summary>
  124. public string WarehouseCode { get; set; }
  125. }
  126. }