DataCollectionSysyem.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using Newtonsoft.Json;
  2. using ServiceCenter;
  3. using ServiceCenter.Helpers;
  4. using ServiceCenter.SqlSugars;
  5. using System.ComponentModel;
  6. using WCS.Core;
  7. using WCS.Entity;
  8. using WCS.Entity.Protocol.DataStructure;
  9. using WCS.Service.Worlds;
  10. using WCS.WorkEngineering.Extensions;
  11. namespace WCS.Service.Systems
  12. {
  13. /// <summary>
  14. /// 数据采集系统
  15. /// </summary>
  16. [BelongTo(typeof(DataCollectionWorld))]
  17. [Description("数据采集系统")]
  18. public class DataCollectionSysyem : ServiceSystem<bool, bool>
  19. {
  20. public List<Station> ConvList;
  21. public DataCollectionSysyem()
  22. {
  23. ConvList = World.Devices.Where(v => v.IsConv()).Select(v => new Station(v)).ToList();
  24. }
  25. protected override bool Do(bool obj)
  26. {
  27. SqlSugarHelper.Do(db =>
  28. {
  29. DeviceDataPack pack = new DeviceDataPack();
  30. pack.Frame = DateTime.Now;
  31. //pack.
  32. //byte[] bytes = System.Text.Encoding.Default.GetBytes(JsonConvert.SerializeObject(ConvList, null, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }));
  33. var plcData = new WCS_PlcData()
  34. {
  35. AddWho = "WCS",
  36. WAREHOUSE = ServiceHub.WarehouseName,
  37. CONTENT = JsonConvert.SerializeObject(ConvList, null, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }),
  38. };
  39. var a = TypeConversionHelper.SerializeRedisValue(ConvList);
  40. //对bytes进行数据压缩
  41. //plcData.CONTENT = bytes.Compress();
  42. db.Default.Insertable(plcData).ExecuteCommand();
  43. });
  44. return true;
  45. }
  46. }
  47. }