Преглед на файлове

处理学生名单变更后操作

CrazyIter_Bin преди 3 години
родител
ревизия
9f26563b58

+ 2 - 0
TEAMModelFunction/MonitorServicesBus.cs

@@ -218,6 +218,8 @@ namespace TEAMModelFunction
                 //await FixActivity(client, stuListChange, "Learn");
                 //TODO作业活动
                 // await FixActivity(client, stuListChange, "Homework");
+                //TODO课程
+                await StuListService.FixStuCourse(client, stuListChange);
             }
             catch (Exception ex)
             {

+ 27 - 9
TEAMModelOS.SDK/Models/Service/StuListService.cs

@@ -74,6 +74,25 @@ namespace TEAMModelFunction
                     };
                     await client.GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync(stucourse, new PartitionKey(stucourse.code));
                 }
+                foreach (Students students in stuListChange.stuleave) {
+                    try {
+
+                        await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemAsync<StuActivity>(activity.id, new PartitionKey($"Activity-{activity.school}-{students.id}"));
+                    } catch { 
+                        //仅处理未写入的数据。
+                    }
+                }
+                foreach (string tmdid in stuListChange.tmdhleave) {
+                    try
+                    {
+
+                        await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemAsync<StuActivity>(activity.id, new PartitionKey($"Activity-{tmdid}"));
+                    }
+                    catch
+                    {
+                        //仅处理未写入的数据。
+                    }
+                }
             }
         }
 
@@ -134,16 +153,15 @@ namespace TEAMModelFunction
                     await client.GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync(stucourse, new PartitionKey(stucourse.code));
                 }
                 //移除名单的。 在点击相关的课程,再去二次校验是否存在,不存在则再去删除。
-                //foreach (var delStu in stuListChange.stuleave)
-                //{
-                //    await client.GetContainer("TEAMModelOS", "Student").DeleteItemStreamAsync(course.id, new PartitionKey($"Course-{course.school}-{delStu.id}"));
-                //}
-                //foreach (var delTmd in stuListChange.tmdhleave)
-                //{
-                //    await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemStreamAsync(course.id, new PartitionKey($"Course-{delTmd}"));
-                //}
+                foreach (var delStu in stuListChange.stuleave)
+                {
+                    await client.GetContainer("TEAMModelOS", "Student").DeleteItemStreamAsync(course.id, new PartitionKey($"Course-{course.school}-{delStu.id}"));
+                }
+                foreach (var delTmd in stuListChange.tmdhleave)
+                {
+                    await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemStreamAsync(course.id, new PartitionKey($"Course-{delTmd}"));
+                }
             }
-
         }
 
     }

+ 36 - 14
TEAMModelOS/Controllers/Client/HiScanController.cs

@@ -129,20 +129,26 @@ namespace TEAMModelOS.Controllers.Core
                                     }
                                     if (count > 0) {
                                         //生成token
-                                        var  token = JwtAuthExtension.CreateAuthToken(_option.HostName, id, name?.ToString(), picture?.ToString(), _option.JwtSecretKey, roles: new[] { "teacher" }, schoolID: $"{schoolId}");
+                                        var  stoken = JwtAuthExtension.CreateAuthToken(_option.HostName, id, name?.ToString(), picture?.ToString(), _option.JwtSecretKey, roles: new[] { "teacher" }, schoolID: $"{schoolId}");
                                         //获取学校线下阅卷评测
                                         var sexams= await GetExam($"{schoolId}", "school", client);
-                                        schools.Add(new ScanSchool { name = $"schoolName", picture = $"{schoolPicture}", code = $"{schoolId}", status = $"{schoolStatus}" ,token=token, datas = sexams });
+                                        var container = _azureStorage.GetBlobContainerClient($"{schoolId}");
+                                        await container.CreateIfNotExistsAsync(PublicAccessType.None); //嘗試創建School容器,如存在則不做任何事,保障容器一定存在
+                                        var (sblob_uri, sblob_sas) =   _azureStorage.GetBlobContainerSAS($"{schoolId}", BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List | BlobContainerSasPermissions.Write);
+                                        schools.Add(new ScanSchool { name = $"schoolName", picture = $"{schoolPicture}", code = $"{schoolId}", status = $"{schoolStatus}" ,token= stoken, exams = sexams, bloburl=sblob_uri ,blobsas=sblob_sas});
                                     }
                                 }
                             }
                         }
+                        var ttoken = JwtAuthExtension.CreateAuthToken(_option.HostName, id, name?.ToString(), picture?.ToString(), _option.JwtSecretKey, roles: new[] { "teacher" });
+                        var (tblob_uri, tblob_sas) = _azureStorage.GetBlobContainerSAS(id, BlobContainerSasPermissions.Write | BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List | BlobContainerSasPermissions.Delete);
                         //获取个人线下阅卷评测
-                        var datas = await GetExam($"{id}", "private", client);
+                        var exams = await GetExam($"{id}", "private", client);
                         //換取AuthToken,提供給前端
-                        var data = new { name, picture, id, schools , datas };
+                        var data = new { name, picture, id, schools , exams, bloburl= tblob_uri, blobsas = tblob_sas, token= ttoken };
                         await sseClient.SendEventAsync(data.ToJsonString());
                         return Ok(data);
+                        /////////////////////////////TODO 返回TMDID和学生的头像 名字 id  
                     }
                     else
                     {
@@ -160,43 +166,59 @@ namespace TEAMModelOS.Controllers.Core
             List<ExamData> corrects = new List<ExamData>();
             if (scope.Equals("school"))
             {
-                await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<Correct>(queryText: "SELECT  * FROM c where c.source='2' and c.progress='going' order by c.createTime  ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Correct-{code}") }))
+                //await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<Correct>(queryText: "SELECT  * FROM c where c.source='2' and c.progress='going' order by c.createTime  ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Correct-{code}") }))
+                await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<Correct>(queryText: "SELECT  * FROM c   order by c.createTime  ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Correct-{code}") }))
                 {
                     ExamInfo exam = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<ExamInfo>(item.id, new PartitionKey($"Exam-{code}"));
-                    (List<string> tmdids, List<Students> students)stulist  =await TriggerStuActivity.GetStuList(client, _dingDing, exam.classes, code);
 
-                    corrects.Add(new ExamData { exam = exam, correct = item,tmdids=stulist.tmdids,stulist=stulist.students });
+                    List<ExamClass> classes = new List<ExamClass>();
+                    foreach (var cls in exam.classes) {
+                        (List<string> tmdids, List<Students> students) stulist = await TriggerStuActivity.GetStuList(client, _dingDing, new List<string> { cls }, code);
+                        classes.Add(new ExamClass { classId = cls, tmdids = stulist.tmdids, stulist = stulist.students });
+                    }
+                    corrects.Add(new ExamData { exam = exam, correct = item, classes= classes });
 
                 }
             }
             else if(scope.Equals("private")){
-                await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<Correct>(queryText: "SELECT  * FROM c where c.source='2'  and c.progress='going' order by c.createTime  ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Correct-{code}") }))
+                // await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<Correct>(queryText: "SELECT  * FROM c where c.source='2'  and c.progress='going' order by c.createTime  ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Correct-{code}") }))
+                await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<Correct>(queryText: "SELECT  * FROM c   order by c.createTime  ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Correct-{code}") }))
                 {
-
                     ExamInfo exam = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<ExamInfo>(item.id, new PartitionKey($"Exam-{code}"));
-                    (List<string> tmdids, List<Students> students) stulist = await TriggerStuActivity.GetStuList(client, _dingDing, exam.classes, code);
-                    corrects.Add(new ExamData { exam = exam, correct = item, tmdids = stulist.tmdids, stulist = stulist.students });
+                    List<ExamClass> classes = new List<ExamClass>();
+                    foreach (var cls in exam.classes)
+                    {
+                        (List<string> tmdids, List<Students> students) stulist = await TriggerStuActivity.GetStuList(client, _dingDing, new List<string> { cls }, code);
+                        classes.Add(new ExamClass { classId = cls, tmdids = stulist.tmdids, stulist = stulist.students });
+                    }
+                    corrects.Add(new ExamData { exam = exam, correct = item, classes = classes });
                 }
             }
             return corrects;
         }
     }
 
-    public class ScanSchool 
-    { 
+    public class ScanSchool
+    {
+        public string blobsas { get; set; }
+        public string bloburl { get; set; }
         public string name { get; set; }
         public string picture { get; set; }
         public string code { get; set; }
         public string status { get; set; }
         public string token { get; set; }
        // public List<(Correct,ExamInfo, (List<string> tmdids, List<Students> stulist))> exams{ get; set; }
-        public List<ExamData> datas { get; set; }
+        public List<ExamData> exams { get; set; }
     }
 
     public class ExamData
     {
         public Correct correct { get; set; }
         public ExamInfo exam { get; set; }
+        public List<ExamClass> classes { get; set; }
+    }
+    public class ExamClass {
+        public string classId { get; set; }
         public List<string> tmdids { get; set; }
         public List<Students> stulist { get; set; }
     }

+ 3 - 3
TEAMModelOS/Controllers/School/CourseController.cs

@@ -183,15 +183,15 @@ namespace TEAMModelOS.Controllers
         [ProducesDefaultResponseType]
         //[AuthToken(Roles = "Teacher")]
         [HttpPost("upsert-list")]
-        public async Task<IActionResult> upsertList(JsonElement requert)
+        public async Task<IActionResult> upsertList(JsonElement json)
         {
             try
             {
                 
                 StuList stuList = new StuList();
-                if (!requert.TryGetProperty("stuList", out JsonElement student)) return BadRequest();
+                if (!json.TryGetProperty("stuList", out JsonElement student)) return BadRequest();
                 //if (!requert.TryGetProperty("code", out JsonElement code)) return BadRequest();
-                if (!requert.TryGetProperty("scope", out JsonElement scope)) return BadRequest();
+                if (!json.TryGetProperty("scope", out JsonElement scope)) return BadRequest();
                 stuList = student.ToObject<StuList>();
                 var client = _azureCosmos.GetCosmosClient();
                 string originCode = stuList.code;