UserMachineDataHelper.cs 3.0 KB

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