WifiChangeBindHelper.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4. using System.Linq;
  5. using System.Data;
  6. using MySystem;
  7. using MySystem.PxcModels;
  8. using Library;
  9. using LitJson;
  10. public class WifiChangeBindHelper
  11. {
  12. public readonly static WifiChangeBindHelper Instance = new WifiChangeBindHelper();
  13. private WifiChangeBindHelper()
  14. {
  15. }
  16. public void Start()
  17. {
  18. Thread th = new Thread(DoWorks);
  19. th.IsBackground = true;
  20. th.Start();
  21. }
  22. private void DoWorks()
  23. {
  24. while (true)
  25. {
  26. try
  27. {
  28. string content = RedisDbconn.Instance.RPop<string>("kxs_changebindwifi_list");
  29. if(!string.IsNullOrEmpty(content))
  30. {
  31. DoSomething(content);
  32. }
  33. else
  34. {
  35. Thread.Sleep(60000);
  36. }
  37. }
  38. catch (Exception ex)
  39. {
  40. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "WIFI换绑异常");
  41. }
  42. }
  43. }
  44. public void DoSomething(string content)
  45. {
  46. string[] data = content.Split(new string[] { "#cut#" }, StringSplitOptions.None);
  47. JsonData jsonObj = JsonMapper.ToObject(data[1]);
  48. string oldSn = jsonObj["oldSn"].ToString();
  49. string newSn = jsonObj["newSn"].ToString();
  50. WebCMSEntities db = new WebCMSEntities();
  51. WifiTradeRecord edit = db.WifiTradeRecord.FirstOrDefault(m => m.SnNo == oldSn);
  52. if(edit != null)
  53. {
  54. edit.Remark = oldSn;
  55. edit.SnNo = newSn;
  56. db.SaveChanges();
  57. }
  58. db.Dispose();
  59. }
  60. }