扫码入库.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. using PlcSiemens.Core.Extension;
  2. using ServiceCenter.Extensions;
  3. using ServiceCenter.Logs;
  4. using ServiceCenter.SqlSugars;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.ComponentModel;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using WCS.Core;
  12. using WCS.Entity;
  13. using WCS.Entity.Protocol.BCR;
  14. using WCS.Entity.Protocol.Station;
  15. using WCS.WorkEngineering.Extensions;
  16. using WCS.WorkEngineering.Worlds;
  17. namespace WCS.WorkEngineering.Systems.重绕区
  18. {
  19. /// <summary>
  20. /// 扫码入库
  21. /// </summary>
  22. [BelongTo(typeof(RewindWorld))]
  23. [Description("扫码入库")]
  24. public class 扫码入库 : DeviceSystem<Device<IStation520, IStation521, IStation523, IBCR81>>
  25. {
  26. protected override bool ParallelDo => true;
  27. public override void Do(Device<IStation520, IStation521, IStation523, IBCR81> obj)
  28. {
  29. if (obj.Data.VoucherNo != obj.Data2.VoucherNo)
  30. {
  31. World.Log($"凭证号不一致,DB520:{obj.Data.VoucherNo}-DB521:{obj.Data2.VoucherNo}");
  32. return;
  33. }
  34. if (obj.Data3.Status.HasFlag(StationStatus.Run))
  35. {
  36. World.Log("设备运行中");
  37. return;
  38. }
  39. if (!obj.Data3.Status.HasFlag(StationStatus.OT_Status))
  40. {
  41. World.Log("站台货物信息与实际占用不一致");
  42. return;
  43. }
  44. if (!obj.Data3.Status.HasFlag(StationStatus.PH_Status))
  45. {
  46. World.Log("无光电");
  47. return;
  48. }
  49. if (obj.Data2.Request != 1)
  50. {
  51. World.Log("无请求");
  52. return;
  53. }
  54. SqlSugarHelper.Do(db =>
  55. {
  56. WCS_TaskInfo task = null;
  57. try
  58. {
  59. //获取托盘条码
  60. var barcode = obj.Data4.GetBCRCode();
  61. if (barcode.IsNullOrWhiteSpace())
  62. {
  63. World.Log("扫码失败,内容为空", LogLevelEnum.Mid);
  64. return;
  65. }
  66. else if (!barcode.Contains("TPB"))
  67. {
  68. World.Log($"扫码异常{barcode},请检查扫码器", LogLevelEnum.Mid);
  69. return;
  70. }
  71. SqlSugarHelper.Do(_db =>
  72. {
  73. var db = _db.Default;
  74. //找到对应的任务
  75. var taskInfo = db.Queryable<WCS_TaskInfo>().First(v => v.BarCode == barcode && v.Type == TaskType.EnterDepot && v.Status < Entity.TaskStatus.Finish);
  76. if (taskInfo == null) return;
  77. if (taskInfo.Status != Entity.TaskStatus.WaitingToExecute) return;
  78. {
  79. taskInfo.Status = Entity.TaskStatus.ConveyorExecution;
  80. taskInfo.EditTime = DateTime.Now;
  81. db.UpdateableRowLock(taskInfo).UpdateColumns(x => new { x.Status, x.EditTime }).ExecuteCommand();
  82. taskInfo.AddWCS_TASK_DTL(db, obj.Entity.Code, $"任务{taskInfo.ID}扫码成功,条码{taskInfo.BarCode}");
  83. task = taskInfo;
  84. }
  85. });
  86. }
  87. catch (Exception ex)
  88. {
  89. throw new KnownException(ex.Message, LogLevelEnum.High);
  90. }
  91. if (task == null) return;
  92. obj.Data.TaskNumber = task.ID;
  93. obj.Data.GoodsStart = obj.Entity.Code.ToShort();
  94. obj.Data.GoodsEnd = obj.Entity.Code switch
  95. {
  96. "9125" => 9126.ToShort(),
  97. "9136" => 9137.ToShort(),
  98. "9147" => 9148.ToShort(),
  99. _ => 9999
  100. };
  101. obj.Data.VoucherNo++;
  102. });
  103. }
  104. public override bool Select(Device dev)
  105. {
  106. return dev.Code is "9125";
  107. }
  108. }
  109. }