WifiUnBindHelper.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 WifiUnBindHelper
  11. {
  12. public readonly static WifiUnBindHelper Instance = new WifiUnBindHelper();
  13. private WifiUnBindHelper()
  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_unbindwifi_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. Utils.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 posSn = jsonObj["posSn"].ToString();
  49. WebCMSEntities db = new WebCMSEntities();
  50. IQueryable<WifiTradeRecord> list = db.WifiTradeRecord.Where(m => m.SnNo == posSn);
  51. foreach(WifiTradeRecord edit in list)
  52. {
  53. edit.DoMonths = edit.Duration + 1;
  54. edit.Status = -1;
  55. }
  56. db.SaveChanges();
  57. db.Dispose();
  58. }
  59. }