ConsumerOrdersHelper.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using Library;
  2. using MySystem.PxcModels;
  3. using System;
  4. using System.Linq;
  5. namespace MySystem
  6. {
  7. public class ConsumerOrdersHelper
  8. {
  9. public readonly static ConsumerOrdersHelper Instance = new ConsumerOrdersHelper();
  10. private ConsumerOrdersHelper()
  11. { }
  12. public string Start()
  13. {
  14. bool op = true;
  15. WebCMSEntities db = new WebCMSEntities();
  16. string result = "";
  17. // int total = 0;
  18. while (op)
  19. {
  20. ConsumerOrders PopData = new ConsumerOrders();
  21. try
  22. {
  23. //获取apserver待同步的数据,执行入库
  24. PopData = RedisDbconn.Instance.RPop<ConsumerOrders>("Pop:ConsumerOrders");
  25. if (PopData != null)
  26. {
  27. ConsumerOrders checkExist = db.ConsumerOrders.FirstOrDefault(m => m.Id == PopData.Id);
  28. if (checkExist != null)
  29. {
  30. checkExist = PopData;
  31. db.SaveChanges();
  32. }
  33. else
  34. {
  35. ConsumerOrders item = db.ConsumerOrders.Add(PopData).Entity;
  36. db.SaveChanges();
  37. RedisDbconn.Instance.AddList("ConsumerOrders:Divi:" + PopData.MerchantId, item);
  38. RedisDbconn.Instance.AddList("ConsumerOrders:Divi:List", item.Id.ToString());
  39. }
  40. // if (total >= 20)
  41. // {
  42. // total = 0;
  43. // }
  44. if (string.IsNullOrEmpty(result)) result = "success";
  45. }
  46. else
  47. {
  48. op = false;
  49. }
  50. }
  51. catch (Exception ex)
  52. {
  53. ErrorMsg msg = new ErrorMsg();
  54. msg.Obj = PopData;
  55. msg.Time = DateTime.Now;
  56. msg.ErrorContent = ex.ToString();
  57. function.WriteLog(Newtonsoft.Json.JsonConvert.SerializeObject(msg), "Pop:ConsumerOrders:Error");
  58. result = "有异常,请查看Pop:ConsumerOrders:Error队列";
  59. }
  60. }
  61. db.Dispose();
  62. return result;
  63. }
  64. }
  65. }