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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 TaskStatus = WCS.Entity.TaskStatus;
  15. namespace WCS.WorkEngineering.Systems
  16. {
  17. /// <summary>
  18. /// 满轮主线预写入目标地址
  19. /// </summary>
  20. [BelongTo(typeof(SortingMainLineWorld))]
  21. [Description("满轮主线预写入目标地址")]
  22. public class 满轮主线预写入目标地址 : DeviceSystem<Device<IStation523, IBCR83, IStation525>>
  23. {
  24. protected override bool ParallelDo => true;
  25. protected override bool SaveLogsToFile => true;
  26. public override void Do(Device<IStation523, IBCR83, IStation525> obj)
  27. {
  28. //待处理条码组
  29. var pendingBcrList = obj.Data2.GetBcrCodeList().Where(x => !x.IsNullOrEmpty());
  30. //缓存条码组
  31. var cacheBcrList = obj.Data3.GetBcrCodeList();
  32. var codes = pendingBcrList.Where(x => !cacheBcrList.Contains(x));
  33. World.Log($"扫码器:{JsonConvert.SerializeObject(pendingBcrList)}");
  34. World.Log($"缓存信息:{JsonConvert.SerializeObject(cacheBcrList)}");
  35. //循环处理所有缓存条码组中没有的条码
  36. foreach (var bcrCode in codes)
  37. {
  38. //取出预分配地址,并计算相关信息
  39. var key = $"AllocationWarehouseSort:{bcrCode}";
  40. var value = RedisHub.WMS.Get(key);
  41. if (value == null)
  42. {
  43. World.Log($"{bcrCode}:找不到分库记录", LogLevelEnum.High);
  44. continue;
  45. }
  46. var mainlineDiversion = JsonConvert.DeserializeObject<MainlineDiversion>(value);
  47. var srmCode = mainlineDiversion.WarehouseCode.WarehouseToSrm();
  48. var path = DevicePath.GetPath(obj.Entity.Code, srmCode);
  49. if (path == null || path is { Points.Count: < 2 })
  50. {
  51. World.Log($"{bcrCode}:路径错误,当前位置{obj.Entity.Code},目标位置:{srmCode}", LogLevelEnum.High);
  52. continue;
  53. }
  54. var next = path.Points[1].Code;
  55. WCS_TaskInfo taskInfo = null;
  56. try
  57. {
  58. SqlSugarHelper.Do(_db =>
  59. {
  60. var db = _db.Default;
  61. var task = db.Queryable<WCS_TaskInfo>().NoLock().Single(x => x.BarCode == bcrCode && x.ID == mainlineDiversion.TaskId && x.Status == TaskStatus.NewBuild);
  62. if (task == null)
  63. {
  64. World.Log($"{bcrCode}:找不到匹配任务--{value}", LogLevelEnum.High);
  65. return;
  66. }
  67. //if ((obj.Entity.Code == "18" && task.WarehouseCode == "1N") ||
  68. // (obj.Entity.Code == "118" && task.WarehouseCode == "1S") ||
  69. // (obj.Entity.Code == "38" && task.WarehouseCode == "2N") ||
  70. // (obj.Entity.Code == "138" && task.WarehouseCode == "2S") ||
  71. // (obj.Entity.Code == "58" && task.WarehouseCode == "3N") ||
  72. // (obj.Entity.Code == "158" && task.WarehouseCode == "3S"))
  73. //{
  74. // task.Status = TaskStatus.WaitingToExecute;
  75. // task.EditWho = "WCS";
  76. // task.StartTime = DateTime.Now;
  77. //}
  78. //task.EditTime = DateTime.Now;
  79. //db.UpdateableRowLock(task).ExecuteCommand();
  80. //task.AddWCS_TASK_DTL(db, obj.Entity.Code, next, "任务完成预分流");
  81. taskInfo = task;
  82. });
  83. }
  84. catch (Exception e)
  85. {
  86. World.Log($"{bcrCode}:----{e.Message}-{value}", LogLevelEnum.High);
  87. continue;
  88. }
  89. if (taskInfo == null) continue;
  90. //开始赋值
  91. obj.Data3.GetType().GetProperty($"BcrCode{obj.Data3.NextIndex}").SetValue(obj.Data3, bcrCode);
  92. obj.Data3.GetType().GetProperty($"BcrCode{obj.Data3.NextIndex}").SetValue(obj.Data3, bcrCode);
  93. obj.Data3.GetType().GetProperty($"TaskNumber{obj.Data3.NextIndex}").SetValue(obj.Data3, taskInfo.ID);
  94. obj.Data3.GetType().GetProperty($"TaskNumber{obj.Data3.NextIndex}").SetValue(obj.Data3, taskInfo.ID);
  95. obj.Data3.GetType().GetProperty($"GoodsEnd{obj.Data3.NextIndex}").SetValue(obj.Data3, next.ToShort());
  96. obj.Data3.GetType().GetProperty($"GoodsEnd{obj.Data3.NextIndex}").SetValue(obj.Data3, next.ToShort());
  97. if (obj.Data3.NextIndex >= 49)
  98. {
  99. obj.Data3.NextIndex = 0;
  100. }
  101. else
  102. {
  103. obj.Data3.NextIndex++;
  104. }
  105. }
  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. }