using System; using System.Collections.Generic; using System.Threading; using System.Linq; using System.Data; using MySystem; using MySystem.PxcModels; using Library; public class TestHelper { public readonly static TestHelper Instance = new TestHelper(); private TestHelper() { } public void Start() { Thread th = new Thread(DoWorks); th.IsBackground = true; th.Start(); } private void DoWorks() { WebCMSEntities db = new WebCMSEntities(); // bool op = true; // while (op) // { // WebCMSEntities db = new WebCMSEntities(); // int StartId = RedisDbconn.Instance.Get("SetCertUserId"); // 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(); // if (list.Count > 0) // { // foreach (var sub in list) // { // Users user = db.Users.FirstOrDefault(m => m.Id == sub.Id && string.IsNullOrEmpty(m.CertId)); // if (user != null) // { // DataTable dt = dbconn.dtable("select CertId from TmpCert where MakerCode='" + user.MakerCode + "'"); // if (dt.Rows.Count > 0) // { // string CertId = dt.Rows[0]["CertId"].ToString(); // user.CertId = CertId; // } // RedisDbconn.Instance.Set("SetCertUserId", sub.Id); // } // } // db.SaveChanges(); // db.Dispose(); // } // else // { // op = false; // } // Thread.Sleep(10); // } // IQueryable users = db.Users.Where(m => m.AuthFlag == 1).OrderBy(m => m.Id); // foreach (Users user in users.ToList()) // { // 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/"); // path = path.Replace("//", "/"); // string resultpath = "/bsserver_com/static/ReferenceQrCode/" + function.MD5_16(user.Id.ToString() + "8745") + "Pic.png"; // MakeReferenceQrCodeService.Instance.MakeQRCode(function.getPath("/static/QrCodeBg.png"), function.getPath(path), function.getPath(resultpath), user); // resultpath = resultpath.Replace("bsserver_com/", ""); // user.ReferenceQrCode = resultpath; // db.SaveChanges(); // RedisDbconn.Instance.Set("Users:" + user.Id, user); // function.WriteLog(user.Id.ToString(), "生成邀请二维码"); // } // function.WriteLog("finish", "生成邀请二维码"); bool op = true; while (op) { int startId = RedisDbconn.Instance.Get("RemoveUserId"); List uids = db.Users.Select(m => m.Id).Where(m => m > startId && m > 1).OrderBy(m => m).Take(100).ToList(); if (uids.Count > 0) { foreach (int uid in uids) { DoUsers(db, uid); RedisDbconn.Instance.Set("RemoveUserId", uid); } Thread.Sleep(200); } else { op = false; } } db.Dispose(); } public void DoUsers(WebCMSEntities db, int uid) { Users user = db.Users.FirstOrDefault(m => m.Id == uid); if (user != null) { string Mobile = function.CheckNull(user.Mobile); if (!Mobile.Contains("*") && Mobile.Substring(0, 1) == "1" && Mobile.Length == 11) { string ParentNav = user.ParentNav; if (!string.IsNullOrEmpty(ParentNav)) { string NewParentNav = ""; int NewParentUserId = 1; string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(','); Array.Reverse(ParentNavList); int i = 0; foreach (string ParentId in ParentNavList) { int puid = int.Parse(ParentId); Users puser = db.Users.FirstOrDefault(m => m.Id == puid); if (puser != null) { Mobile = function.CheckNull(puser.Mobile); if (!Mobile.Contains("*") && Mobile.Substring(0, 1) == "1" && Mobile.Length == 11) { i += 1; NewParentNav = "," + ParentId + "," + NewParentNav; if (i == 1) { NewParentUserId = puid; } } } } if (string.IsNullOrEmpty(NewParentNav)) { NewParentNav = ",1,"; } user.ParentNav = NewParentNav; user.ParentUserId = NewParentUserId; } else { user.ParentNav = ",1,"; user.ParentUserId = 1; } db.SaveChanges(); } } } }