SourceDataToDb.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Security.Cryptography;
  5. using System.Threading;
  6. using Library;
  7. using LitJson;
  8. using MySystem;
  9. using MySystem.Models;
  10. public class SourceDataToDb
  11. {
  12. public readonly static SourceDataToDb Instance = new SourceDataToDb();
  13. private SourceDataToDb()
  14. { }
  15. public void Start()
  16. {
  17. Thread th = new Thread(DoWorks);
  18. th.IsBackground = true;
  19. th.Start();
  20. }
  21. public void DoWorks()
  22. {
  23. while (true)
  24. {
  25. string content = RedisDbconn.Instance.RPop<string>("DataToDbQueue");
  26. if (!string.IsNullOrEmpty(content))
  27. {
  28. try
  29. {
  30. string[] data = content.Split('|');
  31. string jsonString = data[2];
  32. int BrandId = int.Parse(data[1]);
  33. int Kind = int.Parse(data[0]);
  34. WebCMSEntities db = new WebCMSEntities();
  35. string key = "kxs_" + Kind + "_list_" + BrandId;
  36. JobMqMsg obj = RedisDbconn.Instance.GetList<JobMqMsg>("GetSpData", 1, 1000).FirstOrDefault(m => m.OrderString.Contains(key));
  37. if(obj != null)
  38. {
  39. PublicImportDataService.Instance.InsertData(key, content, obj, BrandId);
  40. }
  41. db.Dispose();
  42. }
  43. catch(Exception ex)
  44. {
  45. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "接收云长WIFI设备绑定异常");
  46. }
  47. }
  48. else
  49. {
  50. Thread.Sleep(5000);
  51. }
  52. }
  53. }
  54. }