PrizeFlowRecordService.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System;
  2. using System.Collections.Generic;
  3. using Library;
  4. using LitJson;
  5. using System.Linq;
  6. using System.Threading;
  7. using MySystem.PxcModels;
  8. using System.Data;
  9. namespace MySystem
  10. {
  11. public class PrizeFlowRecordService
  12. {
  13. public readonly static PrizeFlowRecordService Instance = new PrizeFlowRecordService();
  14. private PrizeFlowRecordService()
  15. { }
  16. public void Start()
  17. {
  18. Thread th = new Thread(StartDo);
  19. th.IsBackground = true;
  20. th.Start();
  21. }
  22. public void StartDo()
  23. {
  24. while(true)
  25. {
  26. try
  27. {
  28. string content = RedisDbconn.Instance.RPop<string>("PrizeFlowQueue");
  29. if (!string.IsNullOrEmpty(content))
  30. {
  31. DoSomething(content);
  32. }
  33. else
  34. {
  35. Thread.Sleep(2000);
  36. }
  37. }
  38. catch(Exception ex)
  39. {
  40. function.WriteLog(DateTime.Now.ToString() + "\r\n" + ex.ToString(), "奖励返现流程入库异常");
  41. Thread.Sleep(600000);
  42. }
  43. }
  44. }
  45. public void DoSomething(string content)
  46. {
  47. PrizeFlowRecord item = Newtonsoft.Json.JsonConvert.DeserializeObject<PrizeFlowRecord>(content);
  48. WebCMSEntities db = new WebCMSEntities();
  49. db.PrizeFlowRecord.Add(item);
  50. db.SaveChanges();
  51. db.Dispose();
  52. }
  53. }
  54. }