CrazyIter_Bin 3 лет назад
Родитель
Сommit
4a2dbcd3ae

+ 7 - 7
TEAMModelOS.SDK/Models/Service/FixDataService.cs

@@ -30,7 +30,7 @@ namespace TEAMModelOS.SDK.Models.Service
             var dict = data.GetProperty("dict").ToObject<Dictionary<string, object>>();
             string queryText = $"SELECT VALUE c FROM c WHERE c.id IN ({string.Join(",", ids.Select(o => $"'{o}'"))})";
             List<Student> students = new List<Student>();
-            await foreach (var item in client.GetContainer("TEAMModelOS", "Student")
+            await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student")
                             .GetItemQueryIterator<Student>(
                                 queryText: queryText,
                                 requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{code}") })) {
@@ -53,7 +53,7 @@ namespace TEAMModelOS.SDK.Models.Service
                         default:
                             break;
                     }
-                  await  client.GetContainer("TEAMModelOS", "Student").ReplaceItemAsync<Student>(item, item.id, new PartitionKey(item.code));
+                  await  client.GetContainer(Constant.TEAMModelOS, "Student").ReplaceItemAsync<Student>(item, item.id, new PartitionKey(item.code));
                     students.Add(item);
                 }
             }
@@ -79,7 +79,7 @@ namespace TEAMModelOS.SDK.Models.Service
                 }
             }
             List<School> schools = new List<School>();
-            await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<School>(queryText: "select value(c) from c", requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base") })) {
+            await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<School>(queryText: "select value(c) from c", requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base") })) {
                 schools.Add(item);
             }
             foreach (var school in schools) {
@@ -95,11 +95,11 @@ namespace TEAMModelOS.SDK.Models.Service
                 tb = "School";
             }
             List<string> ids = new List<string>();
-            await foreach (var item in client.GetContainer("TEAMModelOS", tb).GetItemQueryIterator<Bloblog>(queryDefinition: new QueryDefinition("select c.id from c "), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Bloblog-{name}") }))
+            await foreach (var item in client.GetContainer(Constant.TEAMModelOS, tb).GetItemQueryIterator<Bloblog>(queryDefinition: new QueryDefinition("select c.id from c "), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Bloblog-{name}") }))
             {
                 ids.Add(item.id);
             }
-            await client.GetContainer("TEAMModelOS", tb).DeleteItemsStreamAsync(ids, $"Bloblog-{name}");
+            await client.GetContainer(Constant.TEAMModelOS, tb).DeleteItemsStreamAsync(ids, $"Bloblog-{name}");
             long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
             foreach (var prefix in prefixs)
             {
@@ -123,7 +123,7 @@ namespace TEAMModelOS.SDK.Models.Service
                                 url += ".HTEX";
                             }
                             Bloblog bloblog = new Bloblog { id = Guid.NewGuid().ToString(), code = $"Bloblog-{name}", pk = "Bloblog", time = now, url = url, size = urlsSize != null && urlsSize.HasValue ? urlsSize.Value : 0, type = prefix };
-                            await client.GetContainer("TEAMModelOS", tb).UpsertItemAsync(bloblog, new Azure.Cosmos.PartitionKey(bloblog.code));
+                            await client.GetContainer(Constant.TEAMModelOS, tb).UpsertItemAsync(bloblog, new Azure.Cosmos.PartitionKey(bloblog.code));
                         }
                     }
                 }
@@ -136,7 +136,7 @@ namespace TEAMModelOS.SDK.Models.Service
                         {
                             var urlsSize = await ContainerClient.GetBlobsSize(item);
                             Bloblog bloblog = new Bloblog { id = Guid.NewGuid().ToString(), code = $"Bloblog-{name}", pk = "Bloblog", time = now, url = item, size = urlsSize != null && urlsSize.HasValue ? urlsSize.Value : 0, type = prefix };
-                            await client.GetContainer("TEAMModelOS", tb).UpsertItemAsync(bloblog, new Azure.Cosmos.PartitionKey(bloblog.code));
+                            await client.GetContainer(Constant.TEAMModelOS, tb).UpsertItemAsync(bloblog, new Azure.Cosmos.PartitionKey(bloblog.code));
                         }
                     }
                 }

+ 33 - 36
TEAMModelOS.SDK/Models/Service/StuListService.cs

@@ -17,45 +17,43 @@ namespace TEAMModelFunction
 {
     public class StuListService
     {
-        public static async Task FixActivity(CosmosClient client, DingDing _dingDing, StuListChange stuListChange, string type)
+        public static async Task FixActivity(CosmosClient client,DingDing _dingDing, StuListChange stuListChange, string type)
         {
-
+            
             try
             {
                 var query = $"SELECT distinct c.owner, c.id,c.code, c.classes,c.stuLists,c.subjects,c.progress,c.scope,c.startTime,c.school,c.creatorId,c.name,c.pk ,c.endTime   FROM c  where  c.pk='{type}' " +
                     $" and (( array_contains(c.classes,'{stuListChange.listid}')) or ( array_contains(c.stuLists,'{stuListChange.listid}')))";
-                //$"and A1 in('{stuListChange.listid}') ";
+                    //$"and A1 in('{stuListChange.listid}') ";
                 List<MQActivity> datas = new List<MQActivity>();
-                if (stuListChange.scope.Equals("school", StringComparison.OrdinalIgnoreCase) && !string.IsNullOrEmpty(stuListChange.school))
-                {
-                    await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<MQActivity>(queryText: query,
+                if (stuListChange.scope.Equals("school", StringComparison.OrdinalIgnoreCase) && !string.IsNullOrEmpty(stuListChange.school)) {
+                    await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIterator<MQActivity>(queryText: query,
                        requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"{type}-{stuListChange.school}") }))
                     {
                         datas.Add(item);
                     }
                     ///还要处理该学校每个老师发布的班级的
                     List<SchoolTeacher> teachers = new List<SchoolTeacher>();
-                    await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<SchoolTeacher>(queryText: $"SELECT c.id, c.name FROM c",
+                    await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<SchoolTeacher>(queryText: $"SELECT c.id, c.name FROM c",
                         requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Teacher-{stuListChange.school}") }))
                     {
                         teachers.Add(item);
                     }
-                    foreach (var techer in teachers)
-                    {
+                    foreach (var techer in teachers) {
                         var queryTech = $"SELECT distinct c.owner, c.id,c.code, c.classes,c.stuLists,c.subjects,c.progress,c.scope,c.startTime,c.school,c.creatorId,c.name,c.pk ,c.endTime   FROM c " +
                             $" where c.school='{stuListChange.school}'   and   c.pk='{type}'" +
                             $" and (( array_contains(c.classes,'{stuListChange.listid}')) or ( array_contains(c.stuLists,'{stuListChange.listid}')))";
-                        //  $" and A1 in('{stuListChange.listid}') ";
-                        await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<MQActivity>(queryText: queryTech,
+                      //  $" and A1 in('{stuListChange.listid}') ";
+                        await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIterator<MQActivity>(queryText: queryTech,
                             requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"{type}-{techer.id}") }))
                         {
                             datas.Add(item);
                         }
                     }
                 }
-                if (stuListChange.scope.Equals("private", StringComparison.OrdinalIgnoreCase) && !string.IsNullOrEmpty(stuListChange.creatorId))
+                if (stuListChange.scope.Equals("private", StringComparison.OrdinalIgnoreCase)&&!string.IsNullOrEmpty(stuListChange.creatorId))
                 {
-                    await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<MQActivity>(queryText: query,
+                    await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIterator<MQActivity>(queryText: query,
                         requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"{type}-{stuListChange.creatorId}") }))
                     {
                         datas.Add(item);
@@ -78,7 +76,7 @@ namespace TEAMModelFunction
                             id = activity.id,
                             scode = activity.code,
                             name = activity.name,
-                            code = $"Activity-{students.code.Replace("Base-", "")}-{students.id}",
+                            code = $"Activity-{students.code.Replace("Base-","")}-{students.id}",
                             scope = activity.scope,
                             school = activity.school,
                             creatorId = activity.creatorId,
@@ -94,7 +92,7 @@ namespace TEAMModelFunction
                             classIds = classes
                         };
                         await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-StuListService-FixActivity\n名单发生变更 新建活动中间表\n{stucourse.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
-                        await client.GetContainer("TEAMModelOS", "Student").UpsertItemAsync(stucourse, new PartitionKey(stucourse.code));
+                        await client.GetContainer(Constant.TEAMModelOS, "Student").UpsertItemAsync(stucourse, new PartitionKey(stucourse.code));
                     }//tmd新加入的
                     foreach (string tmdid in stuListChange.tmdjoin)
                     {
@@ -117,16 +115,16 @@ namespace TEAMModelFunction
                             createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
                             taskStatus = -1,
                             classIds = classes
-                        };
+                        }; 
                         await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-StuListService-FixActivity\n名单发生变更 新建活动中间表\n{stucourse.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
-                        await client.GetContainer("TEAMModelOS", "Student").UpsertItemAsync(stucourse, new PartitionKey(stucourse.code));
+                        await client.GetContainer(Constant.TEAMModelOS, "Student").UpsertItemAsync(stucourse, new PartitionKey(stucourse.code));
                     }
                     foreach (Students students in stuListChange.stuleave)
                     {
                         try
                         {
 
-                            await client.GetContainer("TEAMModelOS", "Student").DeleteItemAsync<StuActivity>(activity.id, new PartitionKey($"Activity-{students.code.Replace("Base-", "")}-{students.id}"));
+                            await client.GetContainer(Constant.TEAMModelOS, "Student").DeleteItemAsync<StuActivity>(activity.id, new PartitionKey($"Activity-{students.code.Replace("Base-", "")}-{students.id}"));
                         }
                         catch (CosmosException ex)
                         {
@@ -138,29 +136,28 @@ namespace TEAMModelFunction
                         try
                         {
 
-                            await client.GetContainer("TEAMModelOS", "Student").DeleteItemAsync<StuActivity>(activity.id, new PartitionKey($"Activity-{tmdid}"));
+                            await client.GetContainer(Constant.TEAMModelOS, "Student").DeleteItemAsync<StuActivity>(activity.id, new PartitionKey($"Activity-{tmdid}"));
                         }
-                        catch (CosmosException ex)
+                        catch(CosmosException ex )
                         {
                             //仅处理未写入的数据。
                         }
                     }
                 }
             }
-            catch (Exception ex)
-            {
+            catch(Exception ex ) {
                 await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-StuListService-FixActivity\n{ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
             }
         }
 
-        public static async Task FixStuCourse(CosmosClient client, DingDing _dingDing, StuListChange stuListChange)
+        public static async Task FixStuCourse(CosmosClient client,DingDing  _dingDing, StuListChange stuListChange)
         {
             //1.查找学校或教师的课程是否包含该名单的课程。
             var query = $"select distinct c.code,c.id,c.no,c.name,c.scope, c.creatorId,c.school from c join A0 in c.schedule where A0.stulist = '{stuListChange.listid}'";
             List<Course> courses = new List<Course>();
             if (stuListChange.scope.Equals("school") && !string.IsNullOrEmpty(stuListChange.school))
             {
-                await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<Course>(queryText: query,
+                await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<Course>(queryText: query,
                     requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Course-{stuListChange.school}") }))
                 {
                     courses.Add(item);
@@ -168,7 +165,7 @@ namespace TEAMModelFunction
             }
             if (stuListChange.scope.Equals("private") && !string.IsNullOrEmpty(stuListChange.creatorId))
             {
-                await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<Course>(queryText: query,
+                await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<Course>(queryText: query,
                     requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Course-{stuListChange.creatorId}") }))
                 {
                     courses.Add(item);
@@ -195,7 +192,7 @@ namespace TEAMModelFunction
                         createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
                     };
                     await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-StuListService-FixStuCourse\n名单发生变更 新建课程中间表\n{stucourse.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
-                    await client.GetContainer("TEAMModelOS", "Student").UpsertItemAsync(stucourse, new PartitionKey(stucourse.code));
+                    await client.GetContainer(Constant.TEAMModelOS, "Student").UpsertItemAsync(stucourse, new PartitionKey(stucourse.code));
                 }
                 //tmd新加入的
                 foreach (string tmdid in stuListChange.tmdjoin)
@@ -210,21 +207,21 @@ namespace TEAMModelFunction
                         school = course.school,
                         creatorId = course.creatorId,
                         pk = "StuCourse",
-                        stulist = new List<string> { stuListChange.listid },
+                        stulist= new List<string> { stuListChange .listid},
                         createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
                     };
                     await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-StuListService-FixStuCourse\n名单发生变更 新建课程中间表\n{stucourse.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
-                    await client.GetContainer("TEAMModelOS", "Student").UpsertItemAsync(stucourse, new PartitionKey(stucourse.code));
+                    await client.GetContainer(Constant.TEAMModelOS, "Student").UpsertItemAsync(stucourse, new PartitionKey(stucourse.code));
                 }
                 //移除名单的。 在点击相关的课程,再去二次校验是否存在,不存在则再去删除。
-                //foreach (var delStu in stuListChange.stuleave)
-                //{
-                //    await client.GetContainer("TEAMModelOS", "Student").DeleteItemStreamAsync(course.id, new PartitionKey($"StuCourse-{delStu.code.Replace("Base-", "")}-{delStu.id}"));
-                //}
-                //foreach (var delTmd in stuListChange.tmdhleave)
-                //{
-                //    await client.GetContainer("TEAMModelOS", "Student").DeleteItemStreamAsync(course.id, new PartitionKey($"StuCourse-{delTmd}"));
-                //}
+                foreach (var delStu in stuListChange.stuleave)
+                {
+                    await client.GetContainer(Constant.TEAMModelOS, "Student").DeleteItemStreamAsync(course.id, new PartitionKey($"Course-{delStu.code.Replace("Base-", "")}-{delStu.id}"));
+                }
+                foreach (var delTmd in stuListChange.tmdhleave)
+                {
+                    await client.GetContainer(Constant.TEAMModelOS, "Student").DeleteItemStreamAsync(course.id, new PartitionKey($"Course-{delTmd}"));
+                }
             }
         }
 

+ 17 - 17
TEAMModelOS.SDK/Models/Service/TriggerStuActivity.cs

@@ -24,7 +24,7 @@ namespace TEAMModelFunction
             MQActivity activity = null;
             try
             {
-                var aactivity = await client.GetContainer("TEAMModelOS", "Common").ReadItemStreamAsync(id, new Azure.Cosmos.PartitionKey(code));
+                var aactivity = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemStreamAsync(id, new Azure.Cosmos.PartitionKey(code));
                 using var da = await JsonDocument.ParseAsync(aactivity.ContentStream);
                 activity = da.ToObject<MQActivity>();
             }
@@ -86,7 +86,7 @@ namespace TEAMModelFunction
                             taskStatus = -1,
                             classIds = classes
                         };
-                        await client.GetContainer("TEAMModelOS", "Student").UpsertItemAsync(stucourse, new PartitionKey(stucourse.code));
+                        await client.GetContainer(Constant.TEAMModelOS, "Student").UpsertItemAsync(stucourse, new PartitionKey(stucourse.code));
                     }
                 }
             }
@@ -98,14 +98,14 @@ namespace TEAMModelFunction
                 {
                     foreach (var x in stuActivities)
                     {
-                        await client.GetContainer("TEAMModelOS", "Student").UpsertItemAsync(x, new PartitionKey(x.code));
+                        await client.GetContainer(Constant.TEAMModelOS, "Student").UpsertItemAsync(x, new PartitionKey(x.code));
                     }
                 }
                 if (tmdActivities.IsNotEmpty())
                 {
                     foreach (var x in tmdActivities)
                     {
-                        await client.GetContainer("TEAMModelOS", "Student").UpsertItemAsync(x, new PartitionKey(x.code));
+                        await client.GetContainer(Constant.TEAMModelOS, "Student").UpsertItemAsync(x, new PartitionKey(x.code));
                     }
                 }
             } catch (Exception ex) {
@@ -131,13 +131,13 @@ namespace TEAMModelFunction
                     string sql = string.Join(" , ", sqlList);
                     if (!string.IsNullOrEmpty(school))
                     {
-                        await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<ClassInfo>(queryText: $"select c.id,c.name ,c.periodId,c.year from c where c.id in ({sql})",
+                        await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<ClassInfo>(queryText: $"select c.id,c.name ,c.periodId,c.year from c where c.id in ({sql})",
                            requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Class-{school}") }))
                         {
 
                             classInfos.Add(item);
                         }
-                        await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<ClassInfo>(queryText: $"select c.id,c.name from c where c.id in ({sql})",
+                        await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<ClassInfo>(queryText: $"select c.id,c.name from c where c.id in ({sql})",
                           requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"StuList-{school}") }))
                         {
                             //item.from = "SchStuList";
@@ -145,7 +145,7 @@ namespace TEAMModelFunction
                         }
                     }
                     List<StuList> tchLists = new List<StuList>();
-                    await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<ClassInfo>(queryText: $"select c.id,c.name from c where c.id in ({sql})",
+                    await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<ClassInfo>(queryText: $"select c.id,c.name from c where c.id in ({sql})",
                         requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"StuList") }))
                     {
                        // item.from = "TchStuList";
@@ -180,19 +180,19 @@ namespace TEAMModelFunction
                 List<Student> students = new List<Student>();
                 if (!string.IsNullOrEmpty(school))
                 {
-                    await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<StuList>(queryText: $"select value(c) from c where c.id in ({sql})",
+                    await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<StuList>(queryText: $"select value(c) from c where c.id in ({sql})",
                     requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"StuList-{school}") }))
                     {
                         schList.Add(item);
                     }
-                    await foreach (var item in client.GetContainer("TEAMModelOS", "Student").GetItemQueryIterator<Student>(queryText: $"select value(c) from c where c.classId in ({sql})",
+                    await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<Student>(queryText: $"select value(c) from c where c.classId in ({sql})",
                         requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Base-{school}") }))
                     {
                         students.Add(item);
                     }
                 }
                 List<StuList> tchLists = new List<StuList>();
-                await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<StuList>(queryText: $"select value(c) from c where c.id in ({sql})",
+                await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<StuList>(queryText: $"select value(c) from c where c.id in ({sql})",
                     requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"StuList") }))
                 {
                     tchLists.Add(item);
@@ -230,7 +230,7 @@ namespace TEAMModelFunction
                     tmdids.ForEach(x => { inids.Add($"'{x}'"); });
                     var insql = string.Join(",", inids);
                     var queryslt = $"SELECT  value(c) FROM c where c.id in ({insql})";
-                    await foreach (var item in client.GetContainer("TEAMModelOS", "Student").GetItemQueryIterator<TmdInfo>(queryText: queryslt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
+                    await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<TmdInfo>(queryText: queryslt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
                     {
                         infos.Add(item);
                     }
@@ -245,7 +245,7 @@ namespace TEAMModelFunction
                         PartitionKey partitionKey = new PartitionKey($"Base-{gp.key.Replace("Base-", "")}");
                         var insqlstu = string.Join(",", inidstus);
                         var querystu = $"SELECT  c.id,c.code,c.name,c.picture,c.classId,c.year,c.schoolId FROM c where c.id in ({insqlstu})";
-                        await foreach (var item in client.GetContainer("TEAMModelOS", "Student").GetItemQueryIterator<StuInfo>(queryText: querystu, requestOptions: new QueryRequestOptions() { PartitionKey= partitionKey }))
+                        await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<StuInfo>(queryText: querystu, requestOptions: new QueryRequestOptions() { PartitionKey= partitionKey }))
                         {
                             stuInfos.Add(item);
                         }
@@ -347,19 +347,19 @@ namespace TEAMModelFunction
                 List<StuList> schList = new List<StuList>();
                 List<Student> students = new List<Student>();
                 if (!string.IsNullOrEmpty(school)) {
-                    await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<StuList>(queryText: $"select value(c) from c where c.id in ({sql})",
+                    await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<StuList>(queryText: $"select value(c) from c where c.id in ({sql})",
                     requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"StuList-{school}") }))
                     {
                         schList.Add(item);
                     }
-                    await foreach (var item in client.GetContainer("TEAMModelOS", "Student").GetItemQueryIterator<Student>(queryText: $"select value(c) from c where c.classId in ({sql})",
+                    await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<Student>(queryText: $"select value(c) from c where c.classId in ({sql})",
                         requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Base-{school}") }))
                     {
                         students.Add(item);
                     }
                 }
                 List<StuList> tchLists = new List<StuList>();
-                await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<StuList>(queryText: $"select value(c) from c where c.id in ({sql})",
+                await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<StuList>(queryText: $"select value(c) from c where c.id in ({sql})",
                     requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"StuList") }))
                 {
                     tchLists.Add(item);
@@ -405,7 +405,7 @@ namespace TEAMModelFunction
                     List<string> inidstus = new List<string>();
                     foreach (Students stu in studentss) {
                         var querystu = $"SELECT  c.id,c.code,c.name,c.picture,c.classId,c.year,c.schoolId FROM c where c.id = '{stu.id}'";
-                        await foreach (var item in client.GetContainer("TEAMModelOS", "Student").GetItemQueryIterator<StuInfo>(queryText: querystu, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"{stu.code}") }))
+                        await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<StuInfo>(queryText: querystu, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"{stu.code}") }))
                         {
                             stuInfos.Add(item);
                         }
@@ -413,7 +413,7 @@ namespace TEAMModelFunction
                     /*studentss.Select(x => x.id).ToList().ForEach(x => { inidstus.Add($"'{x}'"); });
                     var insqlstu = string.Join(",", inidstus);
                     var querystu = $"SELECT  c.id,c.code,c.name,c.picture,c.classId,c.year,c.schoolId FROM c where c.id in ({insqlstu})";
-                    await foreach (var item in client.GetContainer("TEAMModelOS", "Student").GetItemQueryIterator<StuInfo>(queryText: querystu, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{school}") }))
+                    await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<StuInfo>(queryText: querystu, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{school}") }))
                     {
                         stuInfos.Add(item);
                     }*/

+ 1 - 1
TEAMModelOS/Controllers/Client/SokrateController.cs

@@ -81,7 +81,7 @@ namespace TEAMModelOS.Controllers.Client
                 {
                     string school_code_blob = school_code.GetString().ToLower();
                     //檢測取得學校基本資料
-                    var responsesch = await client.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(school_code_blob, new PartitionKey($"Base"));
+                    var responsesch = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(school_code_blob, new PartitionKey($"Base"));
                     if (responsesch.Status == 200)
                     {
                         var (blob_uri_read, blob_sas_read) = _azureStorage.GetBlobContainerSAS(school_code_blob, BlobContainerSasPermissions.Read); //讀

+ 16 - 111
TEAMModelOS/Controllers/School/StudentCommonController.cs

@@ -22,13 +22,13 @@ namespace TEAMModelOS.Controllers
     //[Authorize(Roles = "IES5")]
     [Route("student")]
     [ApiController]
-    public class StudentCommonController : ControllerBase
+    public class StudentCommonController :ControllerBase
     {
         private readonly AzureCosmosFactory _azureCosmos;
         private readonly AzureRedisFactory _azureRedis;
         public StudentCommonController(AzureCosmosFactory azureCosmos, AzureRedisFactory azureRedis)
         {
-
+           
             _azureCosmos = azureCosmos;
             _azureRedis = azureRedis;
         }
@@ -84,14 +84,13 @@ namespace TEAMModelOS.Controllers
             }
             if (string.IsNullOrWhiteSpace(school))
             {
-                if (request.TryGetProperty("school", out JsonElement schooljson))
-                {
+                if (request.TryGetProperty("school", out JsonElement schooljson)) {
                     if (!schooljson.ValueKind.Equals(JsonValueKind.Undefined) && !schooljson.ValueKind.Equals(JsonValueKind.Null) && schooljson.ValueKind.Equals(JsonValueKind.String))
                     {
                         school = schooljson.GetString();
                     }
                 }
-
+               
             }
             /// tmdid, schoolid
             var userType = "tmdid";
@@ -111,7 +110,7 @@ namespace TEAMModelOS.Controllers
             }
             else
             {
-                containerId = "Student";
+                containerId = "Teacher";
                 PartitionKey = $"StuCourse-{id}";
             }
 
@@ -124,123 +123,29 @@ namespace TEAMModelOS.Controllers
             {
                 stus.Add(item);
             }
-            foreach (var cos in stus)
-            {
-                if (cos.scope.Equals("school"))
+            foreach (var cos in stus) {
+                if (cos.scope .Equals("school"))
                 {
-                    Course course = new();
-                    try
-                    {
+                    Course course;
+                    try {
                         course = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<Course>(cos.id, new Azure.Cosmos.PartitionKey(cos.scode));
-                    }
-                    catch (CosmosException ex) { course = null; }
-                    sc.Add(new CourseDto { course = course, stuCourse = cos });
+                    } catch (CosmosException ex) { course = null; }
+                    sc.Add( new CourseDto { course=course,stuCourse=cos}  );
                 }
-                else
-                {
-                    Course course = new();
+                else {
+                    Course course ;
                     try
                     {
-                        course = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<Course>(cos.id, new Azure.Cosmos.PartitionKey(cos.scode));
+                        course = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS,"Teacher").ReadItemAsync<Course>(cos.id, new Azure.Cosmos.PartitionKey(cos.scode));
                     }
                     catch (CosmosException ex) { course = null; }
                     sc.Add(new CourseDto { course = course, stuCourse = cos });
                 }
             }
-            //获取老师详细信息
-            HashSet<string> info = new HashSet<string>();
-            HashSet<string> room = new HashSet<string>();
-            foreach (CourseDto dto in sc)
-            {
-                if (dto.course != null)
-                {
-                    if (dto.course.schedule.Count > 0)
-                    {
-                        foreach (Schedule schedule in dto.course.schedule)
-                        {
-                            if (!string.IsNullOrEmpty(schedule.teacherId))
-                            {
-                                info.Add(schedule.teacherId);
-                            }
-                            if (!string.IsNullOrEmpty(schedule.room))
-                            {
-                                room.Add(schedule.room);
-                            }
-                        }
-                    }
-                }
-            }
-            //处理教师基础信息
-            List<(string id, string name)> teachers = new();
-            if (info.Count > 0)
-            {
-                await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryStreamIterator(
-                                    queryText: $"select c.id,c.name from c where c.id in ({ string.Join(",", info.Select(o => $"'{o}'"))})", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
-                {
-                    using var json = await JsonDocument.ParseAsync(item.ContentStream);
-                    if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
-                    {
-                        var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
-                        while (accounts.MoveNext())
-                        {
-                            JsonElement account = accounts.Current;
-                            teachers.Add((account.GetProperty("id").GetString(), account.GetProperty("name").GetString()));
-                        }
-                    }
-                }
-            }
-            //处理教室基础信息
-            List<(string id, string name)> rooms = new();
-            if (room.Count > 0)
-            {
-                await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(
-                                    queryText: $"select c.id,c.name from c where c.id in ({ string.Join(",", room.Select(o => $"'{o}'"))})", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Room-{school}") }))
-                {
-                    using var json = await JsonDocument.ParseAsync(item.ContentStream);
-                    if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
-                    {
-                        var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
-                        while (accounts.MoveNext())
-                        {
-                            JsonElement account = accounts.Current;
-                            rooms.Add((account.GetProperty("id").GetString(), account.GetProperty("name").GetString()));
-                        }
-                    }
-                }
-            }
-            var courses = sc.Select(s => new
-            {
-                course = s.course != null ? new
-                {
-                    id = s.course.id,
-                    name = s.course.name,
-                    code = s.course.code,
-                    creatorId = s.course.creatorId,
-                    no = s.course.no,
-                    period = s.course.period,
-                    school = s.course.school,
-                    scope = s.course.scope,
-                    pk = s.course.pk,
-                    subject = s.course.subject,
-                    schedule = s.course.schedule.Select(c => new
-                    {
-                        room = c.room,
-                        roomName = rooms.FirstOrDefault(t => t.id == c.room).name,
-                        classId = c.classId,
-                        notice = c.notice,
-                        teacherId = c.teacherId,
-                        teacherName = teachers.FirstOrDefault(t => t.id == c.teacherId).name,
-                        time = c.time,
-                        stulist = c.stulist
-                    })
-                } : null,
-                s.stuCourse
-            });
-            return Ok(new { courses });
+            return Ok(new { courses=sc });
         }
     }
-    public class CourseDto
-    {
+    public class CourseDto { 
         public StuCourse stuCourse { get; set; }
         public Course course { get; set; }
     }

+ 3 - 38
TEAMModelOS/Controllers/School/StudentController.cs

@@ -112,38 +112,8 @@ namespace TEAMModelOS.Controllers
                     case "remove":
                         //將學生基本資料內的classId、no、groupId及groupName寫入null
                         (List<string> studs, List<string> nonexistentIds, List<string> errorIds) retRemove = await removeStudentClassInfo(schoolId.GetString(), request.GetProperty("students").EnumerateArray());
+
                         return Ok(new { code = $"Base-{schoolId.GetString()}", ids = retRemove.studs, retRemove.nonexistentIds, retRemove.errorIds });
-                    case "avatar":
-                        if (request.TryGetProperty("avatar", out JsonElement _avatar) && _avatar.ValueKind.Equals(JsonValueKind.Array))
-                        {
-                            List<Avatar> avatars = _avatar.ToObject<List<Avatar>>();
-                            if (avatars.IsNotEmpty())
-                            {
-                                List<Student> studentsp = new List<Student>();
-                                string insql = string.Join(',', avatars.Select(x => $"'{x.studentId}'"));
-                                string sql = $"select value(c) from  c where c.id in ({insql}) ";
-                                await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Student")
-                                    .GetItemQueryIterator<Student>(sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Base-{schoolId}") }))
-                                {
-                                    studentsp.Add(item);
-                                }
-                                (string url, string sas) = _azureStorage.GetBlobContainerSAS99Year($"{schoolId}", BlobContainerSasPermissions.Read);
-                                foreach (Student student in studentsp)
-                                {
-                                    Avatar avatar = avatars.Find(x => x.studentId.Equals(student.id));
-                                    student.picture = avatar != null ? $"{avatar.picture}?{sas}" : null;
-                                    await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Student").ReplaceItemAsync<Student>(student, student.id, new PartitionKey(student.code));
-                                }
-                                return Ok(new { students = studentsp.Select(x=> new {x.id,x.picture,x.code,x.name }) });
-                            }
-                            else {
-                                return BadRequest();
-                            }
-                        }
-                        else {
-                            return BadRequest();
-                        }
-                        
                     default:
                         return BadRequest();
                 }
@@ -155,10 +125,7 @@ namespace TEAMModelOS.Controllers
             }
             return BadRequest();
         }
-        public record Avatar { 
-            public string studentId { get; set; }
-            public string picture { get; set; }
-        }
+
         /// <summary>
         /// 整理前端匯入的學生資訊
         /// </summary>
@@ -1272,8 +1239,6 @@ namespace TEAMModelOS.Controllers
                        .GetItemQueryIterator<Class>(queryText: queryText, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Class-{schoolId}") }))
                         {
                             dicClassInfo[item.id] = item;
-                            item.name = classNos[key].className;
-                            await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<Class>(item, item.id, new PartitionKey(item.code));
                         }
                     }
                     return dicClassInfo;
@@ -2048,7 +2013,7 @@ namespace TEAMModelOS.Controllers
                         tmdids.ForEach(x => { inids.Add($"'{x}'"); });
                         var insql = string.Join(",", inids);
                         var queryslt = $"SELECT c.id,c.name,c.picture FROM c where c.id in ({insql})";
-                        await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<TmdInfo>(queryText: queryslt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
+                        await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<TmdInfo>(queryText: queryslt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
                         {
                             tmdinfos.Add(item);
                         }

+ 34 - 59
TEAMModelOS/Controllers/XTest/DataMigrationController.cs

@@ -28,16 +28,14 @@ namespace TEAMModelOS.Controllers
     public class DataMigrationController : ControllerBase
     {
         ///Teacher表
-        ///     
-        ///     复制的数据  
-        ///     Base  ==>>Student   //IES5&教研中心
-        ///     迁移的数据   StuCourse  ==>> Student  //IES5
-        ///                  Activity   ==>> Student  //IES5
-        ///                  
-        ///                  AbilitySub ==>> Student  //IES5  教研中心
-        ///                  ClassVideo ==>> Student  //IES5  教研中心
-        ///                  Debate     ==>> Student  //IES5  教研中心
-        ///                  Appraise   ==>> Student  //IES5  教研中心
+        ///     复制的数据
+        ///     Base  ==>>Student
+        ///     迁移的数据   StuCourse  ==>> Student
+        ///                  Activity   ==>> Student
+        ///                  AbilitySub ==>> Student
+        ///                  ClassVideo ==>> Student
+        ///                  Debate     ==>> Student
+        ///                  Appraise   ==>> Student
         private readonly AzureStorageFactory _azureStorage;
         private readonly AzureRedisFactory _azureRedis;
         private readonly AzureCosmosFactory _azureCosmos;
@@ -56,24 +54,28 @@ namespace TEAMModelOS.Controllers
         /// <returns></returns>
         [ProducesDefaultResponseType]
         //[AuthToken(Roles = "teacher")]
-        [HttpGet("restore-tmd-course&activity")]
-        public async Task<IActionResult> RestoreTmdCourseAndActivity() {
+        [HttpPost("teacher-base")]
+        public async Task<IActionResult> TeacherBase(JsonElement data) {
             var client = _azureCosmos.GetCosmosClient();
-            List<StuActivity> activities = new List<StuActivity>();
-            List<StuCourse> stuCourses = new List<StuCourse>();
-            await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<StuActivity>(queryText: "select value(c) from c where c.pk='Activity'"))
-            {
-                await client.GetContainer(Constant.TEAMModelOS, "Student").UpsertItemAsync<StuActivity>(item, partitionKey: new PartitionKey(item.code));
-                activities.Add(item);
-            }
-            await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<StuCourse>(queryText: "select value(c) from c where c.pk='StuCourse'"))
-            {
-                await client.GetContainer(Constant.TEAMModelOS, "Student").UpsertItemAsync<StuCourse>(item, partitionKey: new PartitionKey(item.code));
-                stuCourses.Add(item);
+            List<Teacher> items = new List<Teacher>();
+            List<Task<Teacher>> update_teachers = new List<Task<Teacher>>();
+            await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<Teacher>(requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") })) {
+                items.Add(item);
+                if (item.size > 0)
+                {
+                    if (item.pk == null)
+                    {
+                        item.pk = "Teacher";
+                        await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(item, item.id, partitionKey: new PartitionKey("Base"));
+                    }
+                    await client.GetContainer(Constant.TEAMModelOS, "Student").UpsertItemAsync<Teacher>(item, partitionKey: new PartitionKey("Base"));
+                }
+                else {
+                    await client.GetContainer(Constant.TEAMModelOS, "Teacher").DeleteItemAsync<Teacher>(item.id, partitionKey: new PartitionKey("Base"));
+                }
             }
-            return Ok(new { activities , stuCourses });    
+            return Ok(items);
         }
-
         /// <summary>
         /// 迁移教师基础信息,并处理历史数据。
         /// </summary>
@@ -81,44 +83,17 @@ namespace TEAMModelOS.Controllers
         /// <returns></returns>
         [ProducesDefaultResponseType]
         //[AuthToken(Roles = "teacher")]
-        [HttpGet("restore-tmduser")]
-        public async Task<IActionResult> RestoreTmdUser()
+        [HttpPost("restore-tmduser")]
+        public async Task<IActionResult> RestoreTmdUser(JsonElement data)
         {
             var client = _azureCosmos.GetCosmosClient();
-            List<TmdUser> users = new List<TmdUser>();
-            await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<Teacher>(requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
+            List<Teacher> items = new List<Teacher>();
+            List<Task<Teacher>> update_teachers = new List<Task<Teacher>>();
+            await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<TmdUser>(requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
             {
-                ///修复历史数据
-                if (item.size > 0)
-                {
-                    if (item.pk == null)
-                    {
-                        item.pk = "Teacher";
-                        await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(item, item.id, partitionKey: new PartitionKey("Base"));
-                    }
-                    try {
-                        TmdUser user= await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemAsync<TmdUser>( item.id, partitionKey: new PartitionKey("Base"));
-                        item.schools.ForEach(x=>{
-                            if (user.schools.Find(y => y.schoolId.Equals(x.schoolId))==null) {
-                                user.schools.Add(new TmdUser.School { name=x.name,schoolId=x.schoolId,time=x.time,status=x.status});
-                            }
-                        });
-                        users.Add(user);
-                        await client.GetContainer(Constant.TEAMModelOS, "Student").ReplaceItemAsync<TmdUser>(user,user.id, partitionKey: new PartitionKey("Base"));
-                    } catch (CosmosException ex) {
-                        if (ex.Status == 404) {
-                            TmdUser user = item.ToJsonString().ToObject<TmdUser>();
-                            await client.GetContainer(Constant.TEAMModelOS, "Student").CreateItemAsync<TmdUser>(user, partitionKey: new PartitionKey("Base"));
-                            users.Add(user);
-                        }
-                    }
-                }
-                else
-                {
-                    await client.GetContainer(Constant.TEAMModelOS, "Teacher").DeleteItemAsync<Teacher>(item.id, partitionKey: new PartitionKey("Base"));
-                }
+                await client.GetContainer(Constant.TEAMModelOS, "Student").ReplaceItemAsync<TmdUser>(item,item.id, partitionKey: new PartitionKey("Base"));
             }
-            return Ok(new { users });
+            return Ok(items);
         }
     }
 }