CrazyIter_Bin 3 rokov pred
rodič
commit
b397ea93a3

+ 2 - 2
TEAMModelOS.SDK/DI/CoreAPI/CoreAPIHttpService.cs

@@ -31,7 +31,7 @@ namespace TEAMModelOS.SDK.Models.Service
 
         {
             var url = _configuration.GetValue<string>("HaBookAuth:CoreAPI");
-            url = "https://api2-rc.teammodel.cn";
+            //url = "https://api2-rc.teammodel.cn";
             url = $"{url}/oauth2/implicit";
             var clientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
             var clientSecret = _configuration.GetValue<string>("HaBookAuth:CoreService:clientSecret");
@@ -85,7 +85,7 @@ namespace TEAMModelOS.SDK.Models.Service
         public async Task<CoreUser> GetUserInfo(Dictionary<string, string> data, string location, IConfiguration _configuration)
         {
             var url = _configuration.GetValue<string>("HaBookAuth:CoreAPI");
-            url = "https://api2-rc.teammodel.cn";
+            //url = "https://api2-rc.teammodel.cn";
             url = $"{url}/oauth2/getuserinfo";
             var clientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
             var clientSecret = _configuration.GetValue<string>("HaBookAuth:CoreService:clientSecret");

+ 69 - 9
TEAMModelOS/Controllers/Third/ScController.cs

@@ -330,28 +330,88 @@ namespace TEAMModelOS.Controllers.Third
                     areaTeacher = await _azureStorage.FindListByDict<ScTeacher>(new Dictionary<string, object>() { { "PartitionKey", $"ScTeacher" }, { "areaId", $"{areaId}" } });
                     if (areaTeacher.IsNotEmpty())
                     {
-                        //未保存再数据库的、。
-                        teachers.FindAll(x => !areaTeacher.Select(x => x.RowKey).Contains($"{x.PXID}"));
-                        
-                        areaTeacher.FindAll(x => string.IsNullOrEmpty(x.tmdid));
+                        List<ScTeacher> unbindtmdid = new List<ScTeacher>();
+                        //未保存在数据库的。
+                        var saveTeachers= teachers.FindAll(x => !areaTeacher.Select(x => x.RowKey).Contains($"{x.PXID}"));
+                        if (saveTeachers.IsNotEmpty()) {
+                            saveTeachers = await _azureStorage.SaveAll(saveTeachers);
+                            unbindtmdid.AddRange(saveTeachers);
+                        }
+                       
+                        var unbind= areaTeacher.FindAll(x => string.IsNullOrEmpty(x.tmdid));
+                        if (unbind.IsNotEmpty()) {
+                            unbindtmdid.AddRange(unbind);
+                        }
+
+                        //处理没有醍摩豆id
+                       var tids= unbindtmdid.Select(x => $"{x.TID}").ToHashSet();
+                        if (tids.Count() > 0) {
+                            List<DbBind> binds = new List<DbBind>();
+                            string sql = $"SELECT c.id,b.userid,b.data FROM c join b in c.binds  where b.userid in ({string.Join(",", tids.Select(x => $"'{x}'"))})";
+                            await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<DbBind>
+                                (queryText: sql , requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
+                            {
+                                binds.Add(item);
+                            }
+                            if (binds.IsNotEmpty()) {
+                                List<ScTeacher> update = new List<ScTeacher>();
+                                binds.ForEach(x => {
+                                   var exs= unbindtmdid.FindAll(z => z.TID.Equals(x.userid));
+                                    if (exs.IsNotEmpty()) {
+                                        exs.ForEach(y => {
+                                            y.tmdid = x.id;
+                                        });
+                                        update.AddRange(exs);
+                                    }
+                                });
+                                update = await _azureStorage.SaveOrUpdateAll(update);
+                            }
+                        }
                     }
                     else
                     {
-
-                        teachers= await _azureStorage.SaveAll(teachers);
+                        //处理没有醍摩豆id
+                        var tids = teachers.Select(x => $"{x.TID}").ToHashSet();
+                        if (tids.Count() > 0)
+                        {
+                            List<DbBind> binds = new List<DbBind>();
+                            string sql = $"SELECT c.id,b.userid,b.data FROM c join b in c.binds  where b.userid in ({string.Join(",", tids.Select(x => $"'{x}'"))})";
+                            await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<DbBind>
+                                (queryText: sql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
+                            {
+                                binds.Add(item);
+                            }
+                            if (binds.IsNotEmpty())
+                            {
+                                
+                                binds.ForEach(x => {
+                                    var exs = teachers.FindAll(z => z.TID.Equals(x.userid));
+                                    if (exs.IsNotEmpty())
+                                    {
+                                        exs.ForEach(y => {
+                                            y.tmdid = x.id;
+                                        });
+                                    }
+                                });
+                            }
+                        }
+                        teachers = await _azureStorage.SaveAll(teachers);
                     }
                 }
-                
             }
             return Ok(new {
                 projects, msg=$"Table中已经有:{tbschools.Count}个学校,省平台获取到:{schools.Count}个学校,本次保存有:{saveschools?.Count},没有被保存的学校:{unsave.Count},创建失败的学校有:{schoolsfailed.Count()},创建成功的的学校有:{schoolsScucess.Count()}",
                 schoolsfailed,
                 failedmsg,
                 schoolsScucess,
-               tbsch= tbschools.Select(x=>new { x.schoolname,x.schoolCode})
+                tbsch= tbschools.Select(x=>new { x.schoolname,x.schoolCode})
             });
         }
-
+        public class  DbBind{
+            public string id { get; set; }
+            public string userid { get; set; }
+            public List<string> data { get; set; }
+        }
         /// <summary>
         /// 检查醍摩豆id存在多个学校的情况
         /// </summary>