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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. using Castle.Core.Internal;
  2. using Newtonsoft.Json;
  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.WorkEngineering.Extensions;
  11. using WCS.WorkEngineering.Protocol.BCR;
  12. using WCS.WorkEngineering.Protocol.Station;
  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().Where(x => !x.IsNullOrEmpty());
  32. var codes = pendingBcrList.Where(x => !cacheBcrList.Contains(x));
  33. //循环处理所有缓存条码组中没有的条码
  34. foreach (var bcrCode in codes)
  35. {
  36. //取出预分配地址,并计算相关信息
  37. var key = $"AllocationWarehouseSort:{bcrCode}";
  38. var value = RedisHub.WMS.Get(key);
  39. if (value == null)
  40. {
  41. World.Log($"{bcrCode}:找不到分库记录", LogLevelEnum.High);
  42. continue;
  43. }
  44. var mainlineDiversion = JsonConvert.DeserializeObject<MainlineDiversion>(value);
  45. var srmCode = mainlineDiversion.WarehouseCode.WarehouseToSrm();
  46. var next = DevicePath.GetPath(obj.Entity.Code, srmCode).Points[1].Code;
  47. //开始检查任务信息
  48. var db = new SqlSugarHelper();
  49. var task = db.Default.Queryable<WCS_TaskInfo>().Single(x => x.BarCode == bcrCode && x.ID == mainlineDiversion.TaskId && x.Status == TaskStatus.NewBuild);
  50. if (task == null)
  51. {
  52. World.Log($"{bcrCode}-{mainlineDiversion}:找不到匹配任务", LogLevelEnum.High);
  53. continue;
  54. }
  55. try
  56. {
  57. db.Connect.BeginTran();
  58. task.Status = TaskStatus.WaitingToExecute;
  59. task.EditWho = "WCS";
  60. task.EditTime = DateTime.Now;
  61. task.AddWCS_TASK_DTL(db, obj.Entity.Code, next.ToString(), "任务完成预分流");
  62. db.Default.Updateable(task).ExecuteCommand();
  63. db.Connect.CommitTran();
  64. task.UpdateRedisHash();
  65. }
  66. catch (Exception e)
  67. {
  68. db.Connect.RollbackTran();
  69. World.Log($"{bcrCode}-{mainlineDiversion}:----{e.Message}", LogLevelEnum.High);
  70. continue;
  71. }
  72. //开始赋值
  73. obj.Data3.GetType().GetProperty($"BcrCode{obj.Data3.NextIndex}").SetValue(obj.Data3, bcrCode);
  74. obj.Data3.GetType().GetProperty($"TaskNumber{obj.Data3.NextIndex}").SetValue(obj.Data3, task.ID);
  75. obj.Data3.GetType().GetProperty($"GoodsEnd{obj.Data3.NextIndex}").SetValue(obj.Data3, next.ToShort());
  76. if (obj.Data3.NextIndex >= 49)
  77. {
  78. obj.Data3.NextIndex = 0;
  79. }
  80. else
  81. {
  82. obj.Data3.NextIndex++;
  83. }
  84. RedisHub.WMS.Del(key);
  85. }
  86. }
  87. public override bool Select(Device dev)
  88. {
  89. return dev.Code == "18";
  90. }
  91. }
  92. /// <summary>
  93. /// 主线分流
  94. /// </summary>
  95. public class MainlineDiversion
  96. {
  97. /// <summary>
  98. /// 任务号
  99. /// </summary>
  100. public int TaskId { get; set; }
  101. /// <summary>
  102. /// 仓库号
  103. /// </summary>
  104. public string WarehouseCode { get; set; }
  105. }
  106. }