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