UserMachineDataHelper.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. }
  40. else
  41. {
  42. db.UserMachineData.Add(PopData);
  43. }
  44. db.SaveChanges();
  45. // if (total >= 20)
  46. // {
  47. // total = 0;
  48. // db.SaveChanges();
  49. // }
  50. if (string.IsNullOrEmpty(result)) result = "success";
  51. }
  52. else
  53. {
  54. // db.SaveChanges();
  55. op = false;
  56. }
  57. }
  58. catch (Exception ex)
  59. {
  60. ErrorMsg msg = new ErrorMsg();
  61. msg.Obj = PopData;
  62. msg.Time = DateTime.Now;
  63. msg.ErrorContent = ex.ToString();
  64. function.WriteLog(Newtonsoft.Json.JsonConvert.SerializeObject(msg), "Pop:UserMachineData:Error");
  65. result = "有异常,请查看Pop:UserMachineData:Error队列";
  66. }
  67. }
  68. db.Dispose();
  69. return result;
  70. }
  71. }
  72. }