Browse Source

update .调整课例数据。备份。

CrazyIter_Bin 3 years ago
parent
commit
5ed2f768a1

+ 10 - 7
TEAMModelOS.FunctionV4/ServiceBus/ActiveTaskTopic.cs

@@ -509,7 +509,13 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
                 //名单变动修改学生投票关联信息
                 await ActivityService.FixActivity(client, _dingDing, groupChange, "Vote");
                 //名单变动修改学生评测关联信息
-                await ActivityService.FixActivity(client, _dingDing, groupChange, "Exam");              
+                await ActivityService.FixActivity(client, _dingDing, groupChange, "Exam");
+                //名单变动修改学生研修关联信息
+                await ActivityService.FixActivity(client, _dingDing, groupChange, "Study");
+                //名单变动修改学生简易评测关联信息
+                await ActivityService.FixActivity(client, _dingDing, groupChange, "ExamLite");
+                //名单变动修改学生作业活动信息
+                await ActivityService.FixActivity(client, _dingDing, groupChange, "Homework");
                 //TODO学习活动
                 //await FixActivity(client, stuListChange, "Learn");
 
@@ -517,12 +523,9 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
                 {
                     //课程名单变动修改学生课程关联信息
                     await ActivityService.FixStuCourse(client, _dingDing, groupChange);
-                    //名单变动修改学生研修关联信息
-                    await ActivityService.FixActivity(client, _dingDing, groupChange, "Study");
-                    //名单变动修改学生简易评测关联信息
-                    await ActivityService.FixActivity(client, _dingDing, groupChange, "ExamLite");
-                    //名单变动修改学生作业活动信息
-                    await ActivityService.FixActivity(client, _dingDing, groupChange, "Homework");
+                    //名单变动修改课例关联信息
+                    await ActivityService.FixLessonRecord(client, _dingDing, groupChange);
+
                 }
             }
             catch (Exception ex)

+ 1 - 0
TEAMModelOS.SDK/Models/Cosmos/Common/Inner/CourseChange.cs

@@ -28,5 +28,6 @@ namespace TEAMModelOS.SDK.Models.Cosmos.Common
         public string scope { get; set; }
         public string school { get; set; }
         public string creatorId { get; set; }
+        public string status { get; set; }
     }
 }

+ 10 - 0
TEAMModelOS.SDK/Models/Service/ActivityService.cs

@@ -540,6 +540,16 @@ namespace TEAMModelOS.SDK
                 }
             }
         }
+
+        public  static async  Task FixLessonRecord(CosmosClient client, DingDing dingDing, GroupChange groupChange)
+        {
+            if (groupChange.status.Equals("delete")) {
+                string sql = "select value(c) from c where (c.status<>404 or IS_DEFINED(c.status) = false ) and  array_length(c.groupIds)>0  ";
+               
+            }
+          
+        }
+
         public static async Task<string> SaveStuActivity(CosmosClient client, DingDing _dingDing, List<StuActivity> stuActivities, List<StuActivity> tmdActivities, List<StuActivity> tchActivities)
         {
             try

+ 36 - 6
TEAMModelOS/Controllers/Both/LessonRecordController.cs

@@ -246,17 +246,19 @@ namespace TEAMModelOS.Controllers
             }
             if (!request.TryGetProperty("scope", out JsonElement _scope)) return BadRequest();
             StringBuilder sql = new StringBuilder();
-            sql.Append("select value(count(1)) from c   ");
+            sql.Append("select c.id,c.groupIds,c.courseId from c   ");
             Dictionary<string ,object> dict =  GetLessonCond(request);
             AzureCosmosQuery cosmosDbQuery = SQLHelper.GetSQL(dict, sql);
             string tbname = "";
             string code = "";
+            string school = null;
             List<string> autoTch = new List<string>();
             if (_scope.GetString().Equals("school"))
             {
                 if (!request.TryGetProperty("school", out JsonElement _school)) return BadRequest();
                 if (!string.IsNullOrEmpty($"{_school}"))
                 {
+                    school = $"{_school}";
                     code = $"LessonRecord-{_school}";
                     tbname = "School";
                     List<string> ids = new List<string>();
@@ -329,12 +331,40 @@ namespace TEAMModelOS.Controllers
                 }
                 sqlShow = $" and (array_contains(c.show,'student') or array_contains(c.show,'all')  {autoSql} ) ";
             }
-            cosmosDbQuery.QueryText = cosmosDbQuery.QueryText.Replace("where", $" where (c.status<>404 or IS_DEFINED(c.status) = false ) {sqlShow}  and  ");
-            await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname).GetItemQueryIterator<int>(queryDefinition: cosmosDbQuery.CosmosQueryDefinition, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey(code) }))
+            cosmosDbQuery.QueryText = cosmosDbQuery.QueryText.Replace("where", $" where (c.status<>404 or IS_DEFINED(c.status) = false ) and  array_length(c.groupIds)>0 {sqlShow}  and  ");
+            List<LessonRecord> records = new List<LessonRecord>();
+            await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname).GetItemQueryIterator<LessonRecord>(queryDefinition: cosmosDbQuery.CosmosQueryDefinition, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey(code) }))
             {
-                count = item;
+                records.Add(item);
+            }
+            if (records.Any()) {
+                var groupIds= records.SelectMany(x => x.groupIds).ToHashSet();
+                if (groupIds.Any()) {
+                    var groups = await GroupListService.GetGroupListListids(_azureCosmos.GetCosmosClient(), _dingDing, groupIds.ToList(), school," c.id ");
+                    //获取已经被删除的名单。
+                    var idsExp =  groupIds.Except(groups.Select(x => x.id));
+                    if (idsExp.Any()) {
+
+                   
+                        foreach(var item in records)
+                        {
+                            int countRmv = item.groupIds.RemoveAll(x => idsExp.Contains(x));
+                            if (countRmv > 0)
+                            {
+                                try {
+                                    LessonRecord record = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname).ReadItemAsync<LessonRecord>(item.id, new PartitionKey(code));
+                                    record.groupIds = item.groupIds;
+                                    await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname).ReplaceItemAsync<LessonRecord>(record, item.id, new PartitionKey(code));
+                                } catch (CosmosException ex) when (ex.Status == 404) {
+                                    continue;
+                                }
+                            }
+                        }
+                    }
+                }
             }
-            return Ok(new { count=count });
+            count = records.Count;
+            return Ok(new { count=count, records });
         }
       
         /// <summary>
@@ -465,7 +495,7 @@ namespace TEAMModelOS.Controllers
                     }
                     sqlShow = $" and (array_contains(c.show,'student') or array_contains(c.show,'all')  {autoSql} ) ";
                 }
-                cosmosDbQuery.QueryText = cosmosDbQuery.QueryText.Replace("where", $" where (c.status<>404 or IS_DEFINED(c.status) = false ) {sqlShow} and  ");
+                cosmosDbQuery.QueryText = cosmosDbQuery.QueryText.Replace("where", $" where (c.status<>404 or IS_DEFINED(c.status) = false ) and  array_length(c.groupIds)>0  {sqlShow} and  ");
                 await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname)
                    .GetItemQueryStreamIterator(queryDefinition: cosmosDbQuery.CosmosQueryDefinition, continuationToken: continuationToken,
                    requestOptions: new QueryRequestOptions() { MaxItemCount = pageCount, PartitionKey = new PartitionKey(code) }))