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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. using Newtonsoft.Json;
  2. using PlcSiemens.Core.Extension;
  3. using ServiceCenter.Extensions;
  4. using ServiceCenter.Logs;
  5. using ServiceCenter.SqlSugars;
  6. using SqlSugar;
  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.Model.WMS;
  14. using WCS.WorkEngineering.Worlds;
  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. try
  29. {
  30. var devCode = obj.Entity.Code switch
  31. {
  32. "18" => "22",
  33. "38" => "41",
  34. "58" => "61",
  35. "118" => "122",
  36. "138" => "141",
  37. "158" => "161",
  38. _ => throw new ArgumentOutOfRangeException()
  39. };
  40. var dev = new Device<IStation520>(Device.All.First(x => x.Code == devCode), World);
  41. dev.Data.Mode = StationMode.Automatic;
  42. //从DB83中获取待处理条码组
  43. var pendingBcrList = obj.Data2.GetBcrCodeList().Where(x => !x.IsNullOrEmpty());
  44. //从DB525获取已处理条码组
  45. var cacheBcrList = obj.Data3.GetBcrCodeList();
  46. //筛选出未处理条码组
  47. var codes = pendingBcrList.Where(x => !cacheBcrList.Contains(x));
  48. World.Log($"扫码器:{JsonConvert.SerializeObject(pendingBcrList)}");
  49. World.Log($"缓存信息:{JsonConvert.SerializeObject(cacheBcrList)}");
  50. //循环处理所有缓存条码组中没有的条码
  51. foreach (var bcrCode in codes)
  52. {
  53. WCS_TaskInfo taskInfo = null;
  54. fjSysConfig config = new fjSysConfig();
  55. SqlSugarHelper.Do(_db =>
  56. {
  57. var db = _db.Default;
  58. var task = db.Queryable<WCS_TaskInfo>().NoLock().First(x => x.BarCode == bcrCode && x.Status == TaskStatus.NewBuild);
  59. if (task == null)
  60. {
  61. World.Log($"{bcrCode}:找不到匹配的任务", LogLevelEnum.High);
  62. var errorInfo = new BaseErrorInfo()
  63. {
  64. BusName = "主线分流",
  65. BarCode = bcrCode,
  66. Message = "找不到匹配的任务",
  67. Count = 1,
  68. AddTime = DateTime.Now,
  69. Memo = obj.Entity.Code
  70. };
  71. errorInfo.AddBaseErrorInfo(db);
  72. return;
  73. }
  74. var config1 = db.Queryable<fjSysConfig>().NoLock().First(x => x.Code == $"{task.WarehouseCode}-Flow");
  75. if (config1 == null)
  76. {
  77. config.Code = "4";
  78. }
  79. config = config1;
  80. taskInfo = task;
  81. });
  82. if (taskInfo == null)
  83. {
  84. continue;
  85. }
  86. var srmCode = taskInfo.WarehouseCode.WarehouseToSrm();
  87. var path = DevicePath.GetPath(obj.Entity.Code, srmCode);
  88. if (path == null || path is { Points.Count: < 2 })
  89. {
  90. var msg = $"{bcrCode}:路径错误,当前位置{obj.Entity.Code},目标位置:{srmCode}";
  91. World.Log(msg, LogLevelEnum.High);
  92. var errorInfo = new BaseErrorInfo()
  93. {
  94. BusName = "主线分流",
  95. BarCode = bcrCode,
  96. Message = msg,
  97. Count = 1,
  98. AddTime = DateTime.Now,
  99. Memo = obj.Entity.Code
  100. };
  101. errorInfo.AddBaseErrorInfo();
  102. continue;
  103. }
  104. var next = path.Points[1].Code;
  105. #region 计算应该去哪个分拣库
  106. //应该要去的分拣库
  107. if (taskInfo.WarehouseCode.Contains("N"))
  108. {
  109. next = config.SContent switch
  110. {
  111. "1" => "418",
  112. "2" => "818",
  113. "3" => "1218",
  114. _ => next
  115. };
  116. }
  117. else if (taskInfo.WarehouseCode.Contains("S"))
  118. {
  119. next = config.SContent switch
  120. {
  121. "1" => "618",
  122. "2" => "1018",
  123. "3" => "1418",
  124. _ => next
  125. };
  126. }
  127. #endregion 计算应该去哪个分拣库
  128. if (taskInfo == null) continue;
  129. //开始赋值
  130. obj.Data3.GetType().GetProperty($"TaskNumber{obj.Data3.NextIndex}")
  131. .SetValue(obj.Data3, taskInfo.ID);
  132. obj.Data3.GetType().GetProperty($"TaskNumber{obj.Data3.NextIndex}")
  133. .SetValue(obj.Data3, taskInfo.ID);
  134. obj.Data3.GetType().GetProperty($"GoodsEnd{obj.Data3.NextIndex}")
  135. .SetValue(obj.Data3, next.ToShort());
  136. obj.Data3.GetType().GetProperty($"GoodsEnd{obj.Data3.NextIndex}")
  137. .SetValue(obj.Data3, next.ToShort());
  138. obj.Data3.GetType().GetProperty($"BcrCode{obj.Data3.NextIndex}").SetValue(obj.Data3, bcrCode);
  139. if (obj.Data3.NextIndex >= 49)
  140. {
  141. obj.Data3.NextIndex = 0;
  142. }
  143. else
  144. {
  145. obj.Data3.NextIndex++;
  146. }
  147. }
  148. dev.Data.Mode = StationMode.Automatic;
  149. }
  150. catch (Exception e)
  151. {
  152. World.Log($"{e.Message}:---{e.StackTrace}", LogLevelEnum.High);
  153. }
  154. }
  155. public override bool Select(Device dev)
  156. {
  157. var codes = new List<string>();
  158. if (WorkStart.WareHouses.Contains("FJ1")) codes.AddRange(new List<string>() { "18", "118" });
  159. if (WorkStart.WareHouses.Contains("FJ2")) codes.AddRange(new List<string>() { "38", "58" });
  160. if (WorkStart.WareHouses.Contains("FJ3")) codes.AddRange(new List<string>() { "138", "158" });
  161. return codes.Contains(dev.Code);
  162. return false;
  163. }
  164. }
  165. /// <summary>
  166. /// 主线分流
  167. /// </summary>
  168. public class MainlineDiversion
  169. {
  170. /// <summary>
  171. /// 任务号
  172. /// </summary>
  173. public int TaskId { get; set; }
  174. /// <summary>
  175. /// 仓库号
  176. /// </summary>
  177. public string WarehouseCode { get; set; }
  178. }
  179. }