TestHelper.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4. using System.Linq;
  5. using System.Data;
  6. using MySystem;
  7. using MySystem.PxcModels;
  8. using Library;
  9. public class TestHelper
  10. {
  11. public readonly static TestHelper Instance = new TestHelper();
  12. private TestHelper()
  13. {
  14. }
  15. public void Start()
  16. {
  17. Thread th = new Thread(DoWorks);
  18. th.IsBackground = true;
  19. th.Start();
  20. }
  21. private void DoWorks()
  22. {
  23. WebCMSEntities db = new WebCMSEntities();
  24. // bool op = true;
  25. // while (op)
  26. // {
  27. // WebCMSEntities db = new WebCMSEntities();
  28. // int StartId = RedisDbconn.Instance.Get<int>("SetCertUserId");
  29. // var list = db.Users.Select(m => new { m.Id, m.CertId }).Where(m => m.Id > StartId && string.IsNullOrEmpty(m.CertId)).OrderBy(m => m.Id).Take(20).ToList();
  30. // if (list.Count > 0)
  31. // {
  32. // foreach (var sub in list)
  33. // {
  34. // Users user = db.Users.FirstOrDefault(m => m.Id == sub.Id && string.IsNullOrEmpty(m.CertId));
  35. // if (user != null)
  36. // {
  37. // DataTable dt = dbconn.dtable("select CertId from TmpCert where MakerCode='" + user.MakerCode + "'");
  38. // if (dt.Rows.Count > 0)
  39. // {
  40. // string CertId = dt.Rows[0]["CertId"].ToString();
  41. // user.CertId = CertId;
  42. // }
  43. // RedisDbconn.Instance.Set("SetCertUserId", sub.Id);
  44. // }
  45. // }
  46. // db.SaveChanges();
  47. // db.Dispose();
  48. // }
  49. // else
  50. // {
  51. // op = false;
  52. // }
  53. // Thread.Sleep(10);
  54. // }
  55. // IQueryable<Users> users = db.Users.Where(m => m.AuthFlag == 1).OrderBy(m => m.Id);
  56. // foreach (Users user in users.ToList())
  57. // {
  58. // string path = function.CreateQRCode2(ConfigurationManager.AppSettings["SourceHost"].ToString() + "p/user-inviteregist-1?Id=" + user.Id, function.MD5_16(user.Id.ToString() + "8745"), "/bsserver_com/static/ReferenceQrCode/");
  59. // path = path.Replace("//", "/");
  60. // string resultpath = "/bsserver_com/static/ReferenceQrCode/" + function.MD5_16(user.Id.ToString() + "8745") + "Pic.png";
  61. // MakeReferenceQrCodeService.Instance.MakeQRCode(function.getPath("/static/QrCodeBg.png"), function.getPath(path), function.getPath(resultpath), user);
  62. // resultpath = resultpath.Replace("bsserver_com/", "");
  63. // user.ReferenceQrCode = resultpath;
  64. // db.SaveChanges();
  65. // RedisDbconn.Instance.Set("Users:" + user.Id, user);
  66. // function.WriteLog(user.Id.ToString(), "生成邀请二维码");
  67. // }
  68. // function.WriteLog("finish", "生成邀请二维码");
  69. bool op = true;
  70. while (op)
  71. {
  72. int startId = RedisDbconn.Instance.Get<int>("RemoveUserId");
  73. List<int> uids = db.Users.Select(m => m.Id).Where(m => m > startId && m > 1).OrderBy(m => m).Take(100).ToList();
  74. if (uids.Count > 0)
  75. {
  76. foreach (int uid in uids)
  77. {
  78. DoUsers(db, uid);
  79. RedisDbconn.Instance.Set("RemoveUserId", uid);
  80. }
  81. Thread.Sleep(200);
  82. }
  83. else
  84. {
  85. op = false;
  86. }
  87. }
  88. db.Dispose();
  89. }
  90. public void DoUsers(WebCMSEntities db, int uid)
  91. {
  92. Users user = db.Users.FirstOrDefault(m => m.Id == uid);
  93. if (user != null)
  94. {
  95. string Mobile = function.CheckNull(user.Mobile);
  96. if (!Mobile.Contains("*") && Mobile.Substring(0, 1) == "1" && Mobile.Length == 11)
  97. {
  98. string ParentNav = user.ParentNav;
  99. if (!string.IsNullOrEmpty(ParentNav))
  100. {
  101. string NewParentNav = "";
  102. int NewParentUserId = 1;
  103. string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  104. Array.Reverse(ParentNavList);
  105. int i = 0;
  106. foreach (string ParentId in ParentNavList)
  107. {
  108. int puid = int.Parse(ParentId);
  109. Users puser = db.Users.FirstOrDefault(m => m.Id == puid);
  110. if (puser != null)
  111. {
  112. Mobile = function.CheckNull(puser.Mobile);
  113. if (!Mobile.Contains("*") && Mobile.Substring(0, 1) == "1" && Mobile.Length == 11)
  114. {
  115. i += 1;
  116. NewParentNav = "," + ParentId + "," + NewParentNav;
  117. if (i == 1)
  118. {
  119. NewParentUserId = puid;
  120. }
  121. }
  122. }
  123. }
  124. if (string.IsNullOrEmpty(NewParentNav))
  125. {
  126. NewParentNav = ",1,";
  127. }
  128. user.ParentNav = NewParentNav;
  129. user.ParentUserId = NewParentUserId;
  130. }
  131. else
  132. {
  133. user.ParentNav = ",1,";
  134. user.ParentUserId = 1;
  135. }
  136. db.SaveChanges();
  137. }
  138. }
  139. }
  140. }