CrazyIter_Bin 3 лет назад
Родитель
Сommit
140ba849f5

+ 4 - 2
TEAMModelOS.SDK/Models/Cosmos/School/TeacherImport.cs

@@ -19,7 +19,9 @@ namespace TEAMModelOS.SDK.Models
         public string name { get; set; }
         public string status { get; set; }
         public long time { get; set; }
-        //导入时的key
-        public string key { get; set; }
+        public string tmdid { get; set; }
+        public string phone { get; set; }
+        public string email { get; set; }
+        public string note { get; set; }
     }
 }

+ 97 - 16
TEAMModelOS/Controllers/School/SchoolController.cs

@@ -1551,7 +1551,21 @@ namespace TEAMModelOS.Controllers
                 case "upsert":
                     if (!request.TryGetProperty("teachers", out JsonElement _teachers) || !_teachers.ValueKind.Equals(JsonValueKind.Array)) { return BadRequest(); }
                     List<ImportTeacher> teachers = _teachers.ToObject<List<ImportTeacher>>();
-                    var keys = teachers.Where(x => !string.IsNullOrWhiteSpace(x.key)).Select(x => x.key);
+                    var tmdids = teachers.Where(x => !string.IsNullOrWhiteSpace(x.tmdid)).Select(z => z.tmdid);
+                    var phones = teachers.Where(x => !string.IsNullOrWhiteSpace(x.phone)).Select(z => z.phone);
+                    var emails = teachers.Where(x => !string.IsNullOrWhiteSpace(x.email)).Select(z => z.email);
+                    List<string> keys = new List<string>();
+                    if (tmdids.Any()) {
+                        keys.AddRange(tmdids);
+                    }
+                    if (phones.Any())
+                    {
+                        keys.AddRange(phones);
+                    }
+                    if (emails.Any())
+                    {
+                        keys.AddRange(emails);
+                    }
                     long time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
                     teachers.ForEach(x => { x.status = "import";x.time = time; });
                     if (keys.Any()) {
@@ -1580,23 +1594,46 @@ namespace TEAMModelOS.Controllers
                     }
                     if (coreUsers.Any())
                     {
-                        teachers.ForEach(t => {
-                            if (!string.IsNullOrWhiteSpace(t.key))
+                        foreach (var t in teachers) {
+                            if (!string.IsNullOrWhiteSpace(t.tmdid))
                             {
-                                CoreUser coreUser = coreUsers.Find(x => x.searchKey.Equals(t.key));
+                                CoreUser coreUser = coreUsers.Find(x => x.id.Equals(t.tmdid));
                                 if (coreUser != null)
                                 {
-                                    t.id = coreUser.id;
+                                    t.id = coreUser.id; 
+                                }
+                            }
+                            if (string.IsNullOrWhiteSpace(t.id))
+                            {
+                                if (!string.IsNullOrWhiteSpace(t.phone))
+                                {
+                                    CoreUser coreUser = coreUsers.Find(x => x.mobile.Equals(t.phone));
+                                    if (coreUser != null)
+                                    {
+                                        t.id = coreUser.id;
+                                    }
+                                }
+                            }
+                            if (string.IsNullOrWhiteSpace(t.id))
+                            {
+                                if (!string.IsNullOrWhiteSpace(t.email))
+                                {
+                                    CoreUser coreUser = coreUsers.Find(x => x.mail.Equals(t.email));
+                                    if (coreUser != null)
+                                    {
+                                        t.id = coreUser.id;
+                                    }
                                 }
                             }
-                            if (!string.IsNullOrWhiteSpace(t.id)) {
+                            if (!string.IsNullOrWhiteSpace(t.id))
+                            {
                                 SchoolTeacher teacher = idsInSchool.Find(x => x.id.Equals(t.id));
                                 if (teacher != null)
                                 {
                                     t.status = teacher.status;
                                 }
                             }
-                        });
+                        }
                     }
                     teacherImport = new TeacherImport {id = $"{_schoolId}", code = "TeacherImport", pk = "TeacherImport", teachers=teachers};
                     await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).UpsertItemAsync(teacherImport, new PartitionKey("TeacherImport"));
@@ -1607,8 +1644,23 @@ namespace TEAMModelOS.Controllers
                     {
                         teacherImport = JsonDocument.Parse(response.Content).RootElement.ToObject<TeacherImport>();
                         var idsIn = teacherImport.teachers.Where(x => !string.IsNullOrWhiteSpace(x.id));
-                        var keyIn = teacherImport.teachers.Where(x => !string.IsNullOrWhiteSpace(x.key));
-                        List<string> skeys = keyIn.Any() ? keyIn.Select(x => x.key).ToList() : new List<string>();
+                        //id是空 其他不是空的
+                        var tmdidsi = teacherImport.teachers.Where(x => string.IsNullOrWhiteSpace(x.id) && !string.IsNullOrWhiteSpace(x.tmdid)).Select(z => z.tmdid);
+                        var phonesi = teacherImport.teachers.Where(x => string.IsNullOrWhiteSpace(x.id) && !string.IsNullOrWhiteSpace(x.phone)).Select(z => z.phone);
+                        var emailsi = teacherImport.teachers.Where(x => string.IsNullOrWhiteSpace(x.id) && !string.IsNullOrWhiteSpace(x.email)).Select(z => z.email);
+                        List<string> skeys = new List<string>();
+                        if (tmdidsi.Any())
+                        {
+                            skeys.AddRange(tmdidsi);
+                        }
+                        if (phonesi.Any())
+                        {
+                            skeys.AddRange(phonesi);
+                        }
+                        if (emailsi.Any())
+                        {
+                            skeys.AddRange(emailsi);
+                        }
                         if (idsIn.Any())
                         {
                             skeys.AddRange(idsIn.Select(x=>x.id));
@@ -1634,22 +1686,51 @@ namespace TEAMModelOS.Controllers
                         }
                         if (coreUsers.Any()) {
                             teacherImport.teachers.ForEach(t => {
-                                if (!string.IsNullOrWhiteSpace(t.key))
+                                if (!string.IsNullOrWhiteSpace(t.id))
                                 {
-                                    CoreUser coreUser = coreUsers.Find(x => x.searchKey.Equals(t.key));
+                                    CoreUser coreUser = coreUsers.Find(x => x.searchKey.Equals(t.id) || x.id.Equals(t.id));
                                     if (coreUser != null)
                                     {
                                         t.id = coreUser.id;
                                     }
+                                    else
+                                    {
+                                        t.id = null;
+                                    }
                                 }
-                                if (!string.IsNullOrWhiteSpace(t.id))
-                                {
-                                    CoreUser coreUser = coreUsers.Find(x => x.searchKey.Equals(t.id) || x.id.Equals(t.id));
-                                    if (coreUser != null)
+                                if (string.IsNullOrWhiteSpace(t.id)) {
+                                    if (!string.IsNullOrWhiteSpace(t.tmdid))
                                     {
-                                        t.id = coreUser.id;
+                                        CoreUser coreUser = coreUsers.Find(x => x.id.Equals(t.tmdid));
+                                        if (coreUser != null)
+                                        {
+                                            t.id = coreUser.id;
+                                        }
+                                    }
+                                    if (string.IsNullOrWhiteSpace(t.id))
+                                    {
+                                        if (!string.IsNullOrWhiteSpace(t.phone))
+                                        {
+                                            CoreUser coreUser = coreUsers.Find(x => x.mobile.Equals(t.phone));
+                                            if (coreUser != null)
+                                            {
+                                                t.id = coreUser.id;
+                                            }
+                                        }
+                                    }
+                                    if (string.IsNullOrWhiteSpace(t.id))
+                                    {
+                                        if (!string.IsNullOrWhiteSpace(t.email))
+                                        {
+                                            CoreUser coreUser = coreUsers.Find(x => x.mail.Equals(t.email));
+                                            if (coreUser != null)
+                                            {
+                                                t.id = coreUser.id;
+                                            }
+                                        }
                                     }
                                 }
+                                
                                 if (!string.IsNullOrWhiteSpace(t.id))
                                 {
                                     SchoolTeacher teacher = idsInSchool.Find(x => x.id.Equals(t.id));