MerchantParamSetHelper.cs 2.3 KB

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