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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. using Newtonsoft.Json;
  2. using PlcSiemens.Core.Extension;
  3. using ServiceCenter.Extensions;
  4. using ServiceCenter.Logs;
  5. using ServiceCenter.SqlSugars;
  6. using System.ComponentModel;
  7. using WCS.Core;
  8. using WCS.Entity;
  9. using WCS.Entity.Protocol.BCR;
  10. using WCS.Entity.Protocol.Station;
  11. using WCS.WorkEngineering.Extensions;
  12. using WCS.WorkEngineering.Worlds;
  13. using TaskStatus = WCS.Entity.TaskStatus;
  14. namespace WCS.WorkEngineering.Systems
  15. {
  16. /// <summary>
  17. /// 满轮主线预写入目标地址
  18. /// </summary>
  19. [BelongTo(typeof(SortingMainLineWorld))]
  20. [Description("满轮主线预写入目标地址")]
  21. public class 满轮主线预写入目标地址 : DeviceSystem<Device<IStation523, IBCR83, IStation525>>
  22. {
  23. protected override bool ParallelDo => true;
  24. public override void Do(Device<IStation523, IBCR83, IStation525> obj)
  25. {
  26. try
  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. WCS_TaskInfo taskInfo = null;
  52. SqlSugarHelper.Do(_db =>
  53. {
  54. var db = _db.Default;
  55. var task = db.Queryable<WCS_TaskInfo>().NoLock().First(x => x.BarCode == bcrCode && x.Status == TaskStatus.NewBuild);
  56. if (task == null)
  57. {
  58. World.Log($"{bcrCode}:找不到匹配的任务", LogLevelEnum.High);
  59. return;
  60. }
  61. taskInfo = task;
  62. });
  63. if (taskInfo == null)
  64. {
  65. continue;
  66. }
  67. var srmCode = taskInfo.WarehouseCode.WarehouseToSrm();
  68. var path = DevicePath.GetPath(obj.Entity.Code, srmCode);
  69. if (path == null || path is { Points.Count: < 2 })
  70. {
  71. World.Log($"{bcrCode}:路径错误,当前位置{obj.Entity.Code},目标位置:{srmCode}", LogLevelEnum.High);
  72. continue;
  73. }
  74. var next = path.Points[1].Code;
  75. if (taskInfo == null) continue;
  76. //开始赋值
  77. obj.Data3.GetType().GetProperty($"TaskNumber{obj.Data3.NextIndex}")
  78. .SetValue(obj.Data3, taskInfo.ID);
  79. obj.Data3.GetType().GetProperty($"TaskNumber{obj.Data3.NextIndex}")
  80. .SetValue(obj.Data3, taskInfo.ID);
  81. obj.Data3.GetType().GetProperty($"GoodsEnd{obj.Data3.NextIndex}")
  82. .SetValue(obj.Data3, next.ToShort());
  83. obj.Data3.GetType().GetProperty($"GoodsEnd{obj.Data3.NextIndex}")
  84. .SetValue(obj.Data3, next.ToShort());
  85. obj.Data3.GetType().GetProperty($"BcrCode{obj.Data3.NextIndex}").SetValue(obj.Data3, bcrCode);
  86. if (obj.Data3.NextIndex >= 49)
  87. {
  88. obj.Data3.NextIndex = 0;
  89. }
  90. else
  91. {
  92. obj.Data3.NextIndex++;
  93. }
  94. }
  95. dev.Data.Mode = StationMode.Automatic;
  96. }
  97. catch (Exception e)
  98. {
  99. World.Log($"{e.Message}:---{e.StackTrace}", LogLevelEnum.High);
  100. }
  101. }
  102. public override bool Select(Device dev)
  103. {
  104. if (WorkStart.WareHouses.Contains("FJ1")) return dev.Code is "18" or "118";
  105. else if (WorkStart.WareHouses.Contains("FJ2")) return dev.Code is "38" or "58";
  106. else if (WorkStart.WareHouses.Contains("FJ3")) return dev.Code is "138" or "158";
  107. return false;
  108. }
  109. }
  110. /// <summary>
  111. /// 主线分流
  112. /// </summary>
  113. public class MainlineDiversion
  114. {
  115. /// <summary>
  116. /// 任务号
  117. /// </summary>
  118. public int TaskId { get; set; }
  119. /// <summary>
  120. /// 仓库号
  121. /// </summary>
  122. public string WarehouseCode { get; set; }
  123. }
  124. }