Browse Source

自动同步创客信息完善了

lcl 6 months ago
parent
commit
27f5e70a13
1 changed files with 55 additions and 51 deletions
  1. 55 51
      AppStart/Helper/SycnJavaUsersService.cs

+ 55 - 51
AppStart/Helper/SycnJavaUsersService.cs

@@ -63,67 +63,71 @@ namespace MySystem
                 string RealName = user.Username;
                 string HeadPhoto = user.Avatar;
 
-                Users add = db.Users.FirstOrDefault(m => m.Id == id);
-                if(add == null)
+                if(Mobile.Length == 11)
                 {
-                    Users edit = db.Users.FirstOrDefault(m => m.Mobile == Mobile);
-                    if(edit != null)
+                    IQueryable<Users> dels = db.Users.Where(m => m.Mobile.StartsWith(Mobile));
+                    foreach(Users del in dels)
                     {
-                        db.Users.Remove(edit);
+                        db.Users.Remove(del);
                     }
                     db.SaveChanges();
-                    add = db.Users.Add(new Users()
+
+                    Users add = db.Users.FirstOrDefault(m => m.Id == id);
+                    if(add == null)
                     {
-                        Id = id,
-                        ParentUserId = pid,
-                        ParentNav = pidPath,
-                        CreateDate = CreateDate,
-                        MakerCode = MakerCode,
-                        Mobile = Mobile,
-                        RealName = RealName,
-                        HeadPhoto = HeadPhoto,
-                    }).Entity;
-                }
-                else
-                {
-                    add.ParentUserId = pid;
-                    add.ParentNav = pidPath;
-                    add.CreateDate = CreateDate;
-                    add.MakerCode = MakerCode;
-                    add.Mobile = Mobile;
-                    add.RealName = RealName;
-                    add.HeadPhoto = HeadPhoto;
-                }
-                db.SaveChanges();
+                        add = db.Users.Add(new Users()
+                        {
+                            Id = id,
+                            ParentUserId = pid,
+                            ParentNav = pidPath,
+                            CreateDate = CreateDate,
+                            MakerCode = MakerCode,
+                            Mobile = Mobile,
+                            RealName = RealName,
+                            HeadPhoto = HeadPhoto,
+                        }).Entity;
+                    }
+                    else
+                    {
+                        add.ParentUserId = pid;
+                        add.ParentNav = pidPath;
+                        add.CreateDate = CreateDate;
+                        add.MakerCode = MakerCode;
+                        add.Mobile = Mobile;
+                        add.RealName = RealName;
+                        add.HeadPhoto = HeadPhoto;
+                    }
+                    db.SaveChanges();
 
-                UserForMobile userformobile = db.UserForMobile.FirstOrDefault(m => m.Mobile == Mobile);
-                if(userformobile == null)
-                {
-                    db.UserForMobile.Add(new UserForMobile()
+                    UserForMobile userformobile = db.UserForMobile.FirstOrDefault(m => m.Mobile == Mobile);
+                    if(userformobile == null)
                     {
-                        Mobile = Mobile,
-                        UserId = add.Id
-                    });
-                }
-                else
-                {
-                    userformobile.UserId = add.Id;
-                }
+                        db.UserForMobile.Add(new UserForMobile()
+                        {
+                            Mobile = Mobile,
+                            UserId = add.Id
+                        });
+                    }
+                    else
+                    {
+                        userformobile.UserId = add.Id;
+                    }
 
-                UserForMakerCode userformakercode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
-                if(userformakercode == null)
-                {
-                    db.UserForMakerCode.Add(new UserForMakerCode()
+                    UserForMakerCode userformakercode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
+                    if(userformakercode == null)
                     {
-                        MakerCode = MakerCode,
-                        UserId = add.Id
-                    });
-                }
-                else
-                {
-                    userformakercode.UserId = add.Id;
+                        db.UserForMakerCode.Add(new UserForMakerCode()
+                        {
+                            MakerCode = MakerCode,
+                            UserId = add.Id
+                        });
+                    }
+                    else
+                    {
+                        userformakercode.UserId = add.Id;
+                    }
+                    db.SaveChanges();
                 }
-                db.SaveChanges();
             }
             javaUser.Dispose();
             db.Dispose();