合流入库.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using DBHelper;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using WCS.Core;
  8. using WCS.Entity;
  9. using WCS.Entity.Protocol;
  10. using WCS.Service.Extensions;
  11. using WCS.Service.Helpers;
  12. using WCS.Service.Log;
  13. namespace WCS.Service.Works.Station
  14. {
  15. [WorkTitle(typeof(ProductHandler), "合流入库")]
  16. internal class 合流入库 : DeviceWork<Device<IStation520, IStation521, IStation523>>
  17. {
  18. protected override void Do(Device<IStation520, IStation521, IStation523> dev)
  19. {
  20. if (Ltc.Do(dev, v => v.Data2.VoucherNo != v.Data.VoucherNo)) throw new WarnException($"等待任务执行--凭证号不一致");
  21. if (Ltc.Do(dev, v => v.Data3.Status.HasFlag(StationStatus.运行状态位))) throw new WarnException($"设备运行中");
  22. if (Ltc.Do(dev, v => v.Data2.Status.HasFlag(IstationStatus.光电状态) == false)) return;
  23. if (Ltc.Do(dev, v => v.Data2.Tasknum < 10000)) return;
  24. var bcr = dev.Entity.BCR();
  25. var barcode = bcr.Content.Trim('\r');
  26. if (barcode == "")
  27. {
  28. InfoLog.INFO_WarnDb($"{dev.Entity.CODE}--扫码失败,内容为空", dev.Entity.CODE, WCS_EXCEPTIONTYPE.设备异常);
  29. return;
  30. };
  31. var res = WMS.GetSingleOrDouble(barcode,dev.Entity.CODE);
  32. if (res == null) throw new WarnException($"{dev.Entity.CODE}: WMS未返回结果");
  33. DB.Do(db =>
  34. {
  35. var task = db.Default.Set<WCS_TASK>().FirstOrDefault(v => v.ID == dev.Data2.Tasknum);
  36. if(task == null) throw new Exception($"任务号不存在");
  37. dev.Data.Tasknum = dev.Data2.Tasknum;
  38. dev.Data.Goodsnum = res.Root.ToShort();
  39. if (dev.Entity.CODE == "3163")
  40. {
  41. dev.Data.Goodsend = Device.Find(task.ADDRNEXT).GetPath("SRM").CODE.ToShort();
  42. }
  43. dev.Data.VoucherNo++;
  44. });
  45. }
  46. protected override bool SelectDevice(WCS_DEVICE dev)
  47. {
  48. return new string[] { "3047","3163" }.Contains(dev.CODE);
  49. }
  50. }
  51. }