DataCollectionSysyem.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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.Station;
  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<Device<IStation520, IStation521>> ConvList;
  21. public DataCollectionSysyem()
  22. {
  23. ConvList = World.Devices.Where(v => v.IsConv()).Select(v => new Device<IStation520, IStation521>(v)).ToList();
  24. }
  25. protected override bool Do(bool obj)
  26. {
  27. SqlSugarHelper.Do(db =>
  28. {
  29. //byte[] bytes = System.Text.Encoding.Default.GetBytes(JsonConvert.SerializeObject(ConvList, null, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }));
  30. var plcData = new WCS_PlcData()
  31. {
  32. WAREHOUSE = ServiceHub.WarehouseName,
  33. CONTENT = JsonConvert.SerializeObject(ConvList, null, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }),
  34. };
  35. var a = TypeConversionHelper.SerializeRedisValue(ConvList);
  36. //对bytes进行数据压缩
  37. //plcData.CONTENT = bytes.Compress();
  38. db.Default.Insertable(plcData).ExecuteCommand(); ;
  39. });
  40. return true;
  41. }
  42. }
  43. }