StoreStockChangeHelper.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using MySystem.Models;
  2. using System;
  3. using System.Linq;
  4. namespace MySystem
  5. {
  6. public class StoreStockChangeHelper
  7. {
  8. public readonly static StoreStockChangeHelper Instance = new StoreStockChangeHelper();
  9. private StoreStockChangeHelper()
  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. StoreStockChange PopData = new StoreStockChange();
  20. try
  21. {
  22. //获取apserver待同步的数据,执行入库
  23. PopData = TendisDbconn.Instance.RPop<StoreStockChange>("Pop:StoreStockChange");
  24. if (PopData != null)
  25. {
  26. // StoreStockChange checkExist = db.StoreStockChange.FirstOrDefault(m => m.Id == PopData.Id);
  27. // if (checkExist != null)
  28. // {
  29. // checkExist = PopData;
  30. // }
  31. // else
  32. // {
  33. db.StoreStockChange.Add(PopData);
  34. // }
  35. if (total >= 20)
  36. {
  37. total = 0;
  38. db.SaveChanges();
  39. }
  40. if (PopData.TransType == 11)
  41. {
  42. }
  43. if (string.IsNullOrEmpty(result)) result = "success";
  44. }
  45. else
  46. {
  47. db.SaveChanges();
  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. TendisDbconn.Instance.AddList("Pop:StoreStockChange:Error", msg);
  58. result = "有异常,请查看Pop:StoreStockChange:Error队列";
  59. }
  60. }
  61. db.Dispose();
  62. return result;
  63. }
  64. }
  65. }