DataCollectionSysyem.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. AddWho = "WCS",
  33. WAREHOUSE = ServiceHub.WarehouseName,
  34. CONTENT = JsonConvert.SerializeObject(ConvList, null, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }),
  35. };
  36. var a = TypeConversionHelper.SerializeRedisValue(ConvList);
  37. //对bytes进行数据压缩
  38. //plcData.CONTENT = bytes.Compress();
  39. db.Default.Insertable(plcData).ExecuteCommand();
  40. });
  41. return true;
  42. }
  43. }
  44. }