HaoDaHelper.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Text;
  5. using System.Threading;
  6. using Common;
  7. using Infrastructure;
  8. using Model;
  9. using Services;
  10. public class HaoDaHelper
  11. {
  12. public readonly static HaoDaHelper Instance = new HaoDaHelper();
  13. private HaoDaHelper()
  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 = RedisServer.Cache.RPop<string>("hd:notice:order");
  26. if(!string.IsNullOrEmpty(content))
  27. {
  28. DoQueue(content);
  29. }
  30. else
  31. {
  32. Thread.Sleep(5000);
  33. }
  34. }
  35. }
  36. public void DoQueue(string content)
  37. {
  38. try
  39. {
  40. var item = Newtonsoft.Json.JsonConvert.DeserializeObject<HdTradeRecord>(content);
  41. var tradeService = App.GetService<IHdTradeRecordService>();
  42. tradeService.Add(item);
  43. }
  44. catch (Exception ex)
  45. {
  46. Function.WriteLog(DateTime.Now.ToString() + "\n" + ex, "好哒订单入库异常");
  47. }
  48. }
  49. }