TeamApplyHelper.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using Library;
  2. using MySystem.Models;
  3. using System;
  4. using System.Linq;
  5. namespace MySystem
  6. {
  7. public class TeamApplyHelper
  8. {
  9. public readonly static TeamApplyHelper Instance = new TeamApplyHelper();
  10. private TeamApplyHelper()
  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. TeamApply PopData = new TeamApply();
  21. try
  22. {
  23. //获取apserver待同步的数据,执行入库
  24. PopData = RedisDbconn.Instance.RPop<TeamApply>("Pop:TeamApply");
  25. if (PopData != null)
  26. {
  27. TeamApply checkExist = db.TeamApply.FirstOrDefault(m => m.Id == PopData.Id);
  28. if (checkExist != null)
  29. {
  30. checkExist = PopData;
  31. }
  32. else
  33. {
  34. db.TeamApply.Add(PopData);
  35. }
  36. if (total >= 20)
  37. {
  38. total = 0;
  39. db.SaveChanges();
  40. }
  41. if (string.IsNullOrEmpty(result)) result = "success";
  42. }
  43. else
  44. {
  45. db.SaveChanges();
  46. op = false;
  47. }
  48. }
  49. catch (Exception ex)
  50. {
  51. ErrorMsg msg = new ErrorMsg();
  52. msg.Obj = PopData;
  53. msg.Time = DateTime.Now;
  54. msg.ErrorContent = ex.ToString();
  55. LogHelper.Instance.WriteLog(Newtonsoft.Json.JsonConvert.SerializeObject(msg), "Pop:TeamApply:Error");
  56. result = "有异常,请查看Pop:TeamApply:Error队列";
  57. }
  58. }
  59. db.Dispose();
  60. return result;
  61. }
  62. }
  63. }