Browse Source

update 操作。

CrazyIter_Bin 3 years ago
parent
commit
38e3e82e4b

+ 0 - 29
TEAMModelOS.FunctionV4/ServiceBus/ActiveTaskTopic.cs

@@ -1073,35 +1073,6 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
                                             }
                                         }
                                     }
-                                    #region
-                                    //start处理历史数据
-                                    var blobclient = _azureStorage.GetBlobContainerClient(blobname);
-                                    List<BlobItem> blobItems = new List<BlobItem>();
-                                    HashSet<string> ids = new HashSet<string>();
-                                    string path = $"records";
-                                    await foreach (BlobItem item in blobclient.GetBlobsAsync(BlobTraits.None, BlobStates.None, path))
-                                    {
-                                        var p = item.Name.Split("/");
-                                        if (p.Length > 2)
-                                        {
-                                            ids.Add(p[1]);
-                                        }
-                                    }
-                                    List<string> lessonIds = new List<string>();
-                                    string sql = "select value(c.id) from c ";
-                                    await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname)
-                                        .GetItemQueryIterator<string>(queryText: sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey(code) }))
-                                    {
-                                        lessonIds.Add(item);
-                                    }
-                                    var notdata = ids.Except(lessonIds);
-                                    var notblob = lessonIds.Except(ids).ToList();
-                                    List<string> paths = notdata.Select(x => $"records/{x}").ToList();
-                                    await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname).DeleteItemsStreamAsync(notblob, code);
-                                    await _azureStorage.GetBlobServiceClient().DeleteBlobs(_dingDing, blobname, paths);
-                                    //end 处理历史数据
-                                    #endregion
-                                    //await client.GetContainer(Constant.TEAMModelOS, tbname).DeleteItemAsync<LessonRecord>(lessonId, new PartitionKey(code));
                                     await _azureStorage.GetBlobServiceClient().DeleteBlobs(_dingDing, blobname, new List<string> { $"records/{_lessonId}" });
                                     await client.GetContainer(Constant.TEAMModelOS, tbname).DeleteItemStreamAsync(lessonRecord.id,new PartitionKey ($"Bloblog-{blobname}"));
                                     var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", root = "records", name = $"{blobname}" }.ToJsonString()); ;

+ 25 - 17
TEAMModelOS/Controllers/XTest/TestController.cs

@@ -777,6 +777,13 @@ namespace TEAMModelOS.Controllers
                     teacherTrains.Add(item);
                 }
             }
+            string sql = $" select distinct  value(b.id ) from c join b in c.children  where  c.code='AbilityTask-standard10'  ";
+            List<string> nodeIdsDB = new List<string>();
+            await foreach (var y in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Normal).GetItemQueryIterator<string>
+                  (sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"AbilityTask-standard10") }))
+            {
+                nodeIdsDB.Add(y);
+            }
             List<string> right=new List<string>();
             List<string> left=new List<string>();
             foreach (var item in teacherTrains)
@@ -786,34 +793,32 @@ namespace TEAMModelOS.Controllers
                     TeacherFile teacherFile = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemAsync<TeacherFile>(item.id, new PartitionKey($"TeacherFile-{item.code.Replace("TeacherTrain-", "")}"));
                     var nodeIds=  teacherFile.fileRecords.SelectMany(x => x.files).Select(x => x.nodeId).ToHashSet();
                     bool expect = false;
-                    if (nodeIds.Any()) {
-                        string sql = $" select distinct  value(b.id ) from c join b in c.children  where  c.code='AbilityTask-standard10'  and b.id in ({string.Join(",",nodeIds.Select(x=>$"'{x}'"))})";
-                        List<string> nodeIdsDB = new List<string>();
-                        await foreach (var y in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Normal).GetItemQueryIterator<string>
-                              (sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"AbilityTask-standard10") }))
-                        {
-                            nodeIdsDB.Add(y);
-                        }
+                    if (nodeIds.Any()) 
+                    {
                         var exp=  nodeIds.Except(nodeIdsDB);
-                        if (exp.Any()) {
+                        if (exp.Any()) 
+                        {
                             expect = true;
+                            List<FileAbility> dels = new List<FileAbility>();
+                            teacherFile.fileRecords.ForEach(x => {
+                                x.files.RemoveAll(z => exp.Contains(z.nodeId));
+                            });
                         }
                     }
                     if (expect)
                     {
                         left.Add(item.id);
-                        /*
                         foreach (var x in item.currency.teacherAilities)
                         {
-                            string sql = $" select value(c) from c  where c.abilityId='{x.id}' and c.code='AbilityTask-standard10'";
+                            string sqls = $" select value(c) from c  where c.abilityId='{x.id}' and c.code='AbilityTask-standard10'";
                             List<AbilityTask> abilityTasks = new List<AbilityTask>();
                             Dictionary<string, RecordFileAbility> valuePairs = new Dictionary<string, RecordFileAbility>();
                             await foreach (var y in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Normal).GetItemQueryIterator<AbilityTask>
-                                  (sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"AbilityTask-standard10") }))
+                                  (sqls, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"AbilityTask-standard10") }))
                             {
                                 abilityTasks.Add(y);
                             }
-                            double limit = 0;
+                            //   double limit = 0;
                             abilityTasks.ForEach(x =>
                             {
                                 x.children.ForEach(y =>
@@ -824,8 +829,11 @@ namespace TEAMModelOS.Controllers
                                         if (valuePairs.ContainsKey(r.hash))
                                         {
                                             valuePairs.TryGetValue(r.hash, out var value);
-                                            value.fileAbilities.Add(new FileAbility { url = r.link, abilityId = x.abilityId, taskId = x.id, nodeId = y.id });
-                                            limit = limit + r.duration;
+                                            var ablt=  value.fileAbilities.Find(z => z.abilityId.Equals(x.abilityId) && z.taskId.Equals(x.id)  && z.nodeId.Equals(y.id) );
+                                            if (ablt == null) {
+                                                value.fileAbilities.Add(new FileAbility { url = r.link, abilityId = x.abilityId, taskId = x.id, nodeId = y.id });
+                                               // limit = limit + r.duration;
+                                            }
                                         }
                                         else
                                         {
@@ -835,7 +843,7 @@ namespace TEAMModelOS.Controllers
                                                 new FileRecord { hash = r.hash, size = r.size.Value, duration = r.duration, view = (int)r.duration, type = r.type, done = true },
                                                 fileAbilities = new List<FileAbility> { new FileAbility { url = r.link, abilityId = x.abilityId, taskId = x.id, nodeId = y.id } }
                                             });
-                                            limit = limit + r.duration;
+                                           // limit = limit + r.duration;
                                         }
                                     });
                                 });
@@ -873,7 +881,7 @@ namespace TEAMModelOS.Controllers
                         teacherFile = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReplaceItemAsync<TeacherFile>(teacherFile, teacherFile.id, new PartitionKey(teacherFile.code));
                         item.update.Add(StatisticsService.TeacherAbility);
                         await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReplaceItemAsync<TeacherTrain>(item, item.id, new PartitionKey(item.code));
-                        */
+                       
                     }
                     else {
                         right.Add(item.id);