CrazyIter_Bin 3 gadi atpakaļ
vecāks
revīzija
88b8139c25

+ 1 - 1
TEAMModelOS.SDK/Models/Service/GroupListService.cs

@@ -1010,7 +1010,7 @@ namespace TEAMModelOS.SDK
 
                 if (tmdids.IsNotEmpty()) {
                     ///获取真实的名称 
-                    var content = new StringContent(tmdids.Select(x => x.id).ToJsonString(), Encoding.UTF8, "application/json");
+                    var content = new StringContent(tmdids.Select(x => x.id).ToHashSet().ToJsonString(), Encoding.UTF8, "application/json");
                     string json = null;
                     try
                     {

+ 184 - 82
TEAMModelOS/Controllers/XTest/TestController.cs

@@ -758,6 +758,109 @@ namespace TEAMModelOS.Controllers
             await table.SaveOrUpdateAll(teachersUp);
             return Ok();
         }
+        [HttpPost("get-teacher-ability-files")]
+        public async Task<IActionResult> GetScteacher(JsonElement json) {
+
+            List<string> teachers = new List<string>();
+            string schoolSql = "SELECT value  c.id FROM c join a in c.schools where a.areaId='870a5a6b-1ab3-461a-bdeb-baec19780ddb' and c.code='Base' ";
+            await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher)
+                .GetItemQueryIterator<string>(schoolSql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base") }))
+            {
+                teachers.Add(item);
+            }
+            string tr =$"SELECT value(c) FROM c  where c.id in ({string.Join(",", teachers.Select(x=>$"'{x}'"))}) and c.onlineTime!=0  and c.onlineTime<20 and  c.pk='TeacherTrain' ";
+            List<TeacherTrain> teacherTrains = new List<TeacherTrain>();
+            await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher)
+                .GetItemQueryIterator<TeacherTrain>(tr, requestOptions: new QueryRequestOptions {  }))
+            {
+                if (!item.tmdid.Equals("1528783259")) {
+                    teacherTrains.Add(item);
+                }
+            }
+            foreach (var item in teacherTrains)
+            {
+                if (item.onlineTime > 15)
+                {
+                    TeacherFile teacherFile = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemAsync<TeacherFile>(item.id, new PartitionKey($"TeacherFile-{item.code.Replace("TeacherTrain-", "")}"));
+                    foreach (var x in item.currency.teacherAilities)
+                    {
+                        if (x.onlineTime < 320)
+                        {
+                            string sql = $" 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") }))
+                            {
+                                abilityTasks.Add(y);
+                            }
+                            double limit = 0;
+                            abilityTasks.ForEach(x =>
+                            {
+                                x.children.ForEach(y =>
+                                {
+                                    y.rnodes.ForEach(r =>
+                                    {
+                                         
+                                        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;
+                                        }
+                                        else
+                                        {
+                                            valuePairs.Add(r.hash, new RecordFileAbility
+                                            {
+                                                fileRecord =
+                                                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;
+                                        }
+                                    });
+                                });
+                            });
+
+                            foreach (var ps in valuePairs)
+                            {
+                                var fils = teacherFile.fileRecords.Find(x => x.hash.Equals(ps.Key));
+                                if (fils != null)
+                                {
+                                    ps.Value.fileAbilities.ForEach(x =>
+                                    {
+                                        var a = fils.files.Find(z => z.nodeId.Equals(x.nodeId) && z.abilityId.Equals(x.abilityId));
+                                        if (a == null)
+                                        {
+                                            fils.files.Add(new FileAbility { url = x.url, abilityId = x.abilityId, taskId = x.taskId, nodeId = x.nodeId });
+                                        }
+                                    });
+                                }
+                                else
+                                {
+                                    teacherFile.fileRecords.Add(new FileRecord
+                                    {
+                                        hash = ps.Value.fileRecord.hash,
+                                        size = ps.Value.fileRecord.size,
+                                        duration = ps.Value.fileRecord.duration,
+                                        view = (int)ps.Value.fileRecord.view,
+                                        type = ps.Value.fileRecord.type,
+                                        done = true,
+                                        files = ps.Value.fileAbilities
+                                    });
+                                }
+                            }
+
+                        }
+                    }
+                    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));
+                }
+            }
+            return Ok(teacherTrains);
+        }
+
         [HttpPost("fix-teacher-ability-files")]
         public async Task<IActionResult> TestScteacher(JsonElement json) {
             if (!json.TryGetProperty("ids", out JsonElement _ids)) return BadRequest();
@@ -782,92 +885,91 @@ namespace TEAMModelOS.Controllers
                 if (schools.Contains(item.code)) {
                     ids.Add(item);
                 }
-             
             }
             var grp = ids.GroupBy(g => g.code).Select(x => new { key = x.Key, list = x.ToList() });
           
-            foreach (var gp in grp) {
-                foreach (var tch in gp.list) {
-                    if (!string.IsNullOrWhiteSpace(tch.id)) {
-                       var id  =  ids.Find(x => x.id.Equals(tch.id))?.id;
-                        if (id != null) {
-                            TeacherFile teacherFile = new TeacherFile { id = id,pk= "TeacherFile",code= $"TeacherFile-{gp.key}",ttl=-1 };
-                            try {
-                                TeacherTrain teacherTrain = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemAsync<TeacherTrain>(id, new PartitionKey($"TeacherTrain-{gp.key}"));
-                                teacherTrain.update.Add("TeacherAbility");
-                                await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReplaceItemAsync<TeacherTrain>(teacherTrain,id, new PartitionKey($"TeacherTrain-{gp.key}"));
-                            } catch (Exception) { 
-                            }
-                            List<AbilitySub> abilitySubs = new List<AbilitySub>();
-                            string sql = "select value(c) from c ";
-                            try {
-                                await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetItemQueryIterator<AbilitySub>
-                             (sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"AbilitySub-{gp.key}-{id}") }))
-                                {
-                                    abilitySubs.Add(item);
-                                }
+            //foreach (var gp in grp) {
+            //    foreach (var tch in gp.list) {
+            //        if (!string.IsNullOrWhiteSpace(tch.id)) {
+            //           var id  =  ids.Find(x => x.id.Equals(tch.id))?.id;
+            //            if (id != null) {
+            //                TeacherFile teacherFile = new TeacherFile { id = id,pk= "TeacherFile",code= $"TeacherFile-{gp.key}",ttl=-1 };
+            //                try {
+            //                    TeacherTrain teacherTrain = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemAsync<TeacherTrain>(id, new PartitionKey($"TeacherTrain-{gp.key}"));
+            //                    teacherTrain.update.Add("TeacherAbility");
+            //                    await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReplaceItemAsync<TeacherTrain>(teacherTrain,id, new PartitionKey($"TeacherTrain-{gp.key}"));
+            //                } catch (Exception) { 
+            //                }
+            //                List<AbilitySub> abilitySubs = new List<AbilitySub>();
+            //                string sql = "select value(c) from c ";
+            //                try 
+            //                {
+            //                    await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetItemQueryIterator<AbilitySub>
+            //                        (sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"AbilitySub-{gp.key}-{id}") }))
+            //                    {
+            //                        abilitySubs.Add(item);
+            //                    }
                            
-                            Dictionary<string, RecordFileAbility> valuePairs = new Dictionary<string, RecordFileAbility>();
-                            var taskids=  abilitySubs.SelectMany(x => x.taskRcds).Select(x => x.id).ToHashSet();
-                            if (taskids.Any()) {
-
-                                List<AbilityTask> abilityTasks = new List<AbilityTask>();
-                                string taskSql = $"select distinct value(c) from c  join b in c.children where c.code='AbilityTask-standard10' and b.id in ({string.Join(",", taskids.Select(m=>$"'{m}'"))})";
-                                await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Normal).GetItemQueryIterator<AbilityTask>
-                                   (taskSql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"AbilityTask-standard10") }))
-                                {
-                                    abilityTasks.Add(item);
-                                }
-                                abilityTasks.ForEach(x => {
-                                    x.children.ForEach(y => {
-                                       var di= taskids.ToList().Find(z => z.Equals(y.id));
-                                        if (!string.IsNullOrWhiteSpace(id)) {
-                                            y.rnodes.ForEach(r => {
-                                                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 = r.id });
-                                                }
-                                                else {
-                                                    valuePairs.Add(r.hash, new RecordFileAbility
-                                                    {
-                                                        fileRecord =
-                                                        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=r.id } }
-                                                    });
-                                                }
-                                            });
-                                        }
-                                    });
-                                });
-                                }
-                                foreach (var item in valuePairs)
-                                {
-                                    teacherFile.fileRecords.Add(new FileRecord
-                                    {
-                                        hash = item.Value.fileRecord.hash,
-                                        size = item.Value.fileRecord.size,
-                                        duration = item.Value.fileRecord.duration,
-                                        view = (int)item.Value.fileRecord.view,
-                                        type = item.Value.fileRecord.type,
-                                        done = true,
-                                        files = item.Value.fileAbilities
-                                    });
-                                    
-                                 
-                                }
-                            }
-                            catch (Exception ex)
-                            {
-                                return BadRequest(new { ex = ex.Message, ms = ex.StackTrace });
-
-                            }
-                            teacherFiles.Add(teacherFile);
-                             await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).UpsertItemAsync(teacherFile, new PartitionKey(teacherFile.code));
-                        }
-                    }
-                }
-            }
+            //                    Dictionary<string, RecordFileAbility> valuePairs = new Dictionary<string, RecordFileAbility>();
+            //                    var taskids=  abilitySubs.SelectMany(x => x.taskRcds).Select(x => x.id).ToHashSet();
+            //                    if (taskids.Any()) 
+            //                    {
+
+            //                        List<AbilityTask> abilityTasks = new List<AbilityTask>();
+            //                        string taskSql = $"select distinct value(c) from c  join b in c.children where c.code='AbilityTask-standard10' and b.id in ({string.Join(",", taskids.Select(m=>$"'{m}'"))})";
+            //                        await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Normal).GetItemQueryIterator<AbilityTask>
+            //                            (taskSql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"AbilityTask-standard10") }))
+            //                        {
+            //                            abilityTasks.Add(item);
+            //                        }
+            //                        abilityTasks.ForEach(x => {
+            //                            x.children.ForEach(y => {
+            //                                var di= taskids.ToList().Find(z => z.Equals(y.id));
+            //                                if (!string.IsNullOrWhiteSpace(di)) {
+            //                                    y.rnodes.ForEach(r => {
+            //                                        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 = di });
+            //                                        }
+            //                                        else {
+            //                                            valuePairs.Add(r.hash, new RecordFileAbility
+            //                                            {
+            //                                                fileRecord =
+            //                                                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=di } }
+            //                                            });
+            //                                        }
+            //                                    });
+            //                                }
+            //                            });
+            //                        });
+            //                    }
+            //                    foreach (var item in valuePairs)
+            //                    {
+            //                        teacherFile.fileRecords.Add(new FileRecord
+            //                        {
+            //                            hash = item.Value.fileRecord.hash,
+            //                            size = item.Value.fileRecord.size,
+            //                            duration = item.Value.fileRecord.duration,
+            //                            view = (int)item.Value.fileRecord.view,
+            //                            type = item.Value.fileRecord.type,
+            //                            done = true,
+            //                            files = item.Value.fileAbilities
+            //                        });
+            //                    }
+            //                }
+            //                catch (Exception ex)
+            //                {
+            //                    return BadRequest(new { ex = ex.Message, ms = ex.StackTrace });
+
+            //                }
+            //                teacherFiles.Add(teacherFile);
+            //                await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).UpsertItemAsync(teacherFile, new PartitionKey(teacherFile.code));
+            //            }
+            //        }
+            //    }
+            //}
             
             return Ok(teacherFiles);
         }

+ 23 - 23
TEAMModelOS/appsettings.Development.json

@@ -20,37 +20,37 @@
     //"HttpTrigger": "http://localhost:7071/api/"
   },
   "Azure": {
-    "Storage": {
-      "ConnectionString": "DefaultEndpointsProtocol=https;AccountName=teammodeltest;AccountKey=O2W2vadCqexDxWO+px+QK7y1sHwsYj8f/WwKLdOdG5RwHgW/Dupz9dDUb4c1gi6ojzQaRpFUeAAmOu4N9E+37A==;EndpointSuffix=core.chinacloudapi.cn"
-    },
-    "Cosmos": {
-      //"ConnectionString": "AccountEndpoint=https://teammodel.documents.azure.com:443/;AccountKey=opemBAZi0yATewIlhxDYoIEUqncT5qJh3pUBZsBkTqEkuLYTuu3VS7oaDGJlPp8ASwm5SVSrK2caJsjgmqRw9g==;"
-      "ConnectionString": "AccountEndpoint=https://cdhabookdep-free.documents.azure.cn:443/;AccountKey=JTUVk92Gjsx17L0xqxn0X4wX2thDPMKiw4daeTyV1HzPb6JmBeHdtFY1MF1jdctW1ofgzqkDMFOtcqS46by31A==;"
-      //"ConnectionString": "AccountEndpoint=https://teammodelos.documents.azure.cn:443/;AccountKey=clF73GwPECfP1lKZTCvs8gLMMyCZig1HODFbhDUsarsAURO7TcOjVz6ZFfPqr1HzYrfjCXpMuVD5TlEG5bFGGg==;"
-    },
-    "Redis": {
-      "ConnectionString": "52.130.252.100:6379,password=habook,ssl=false,abortConnect=False,writeBuffer=10240"
-    },
-    "ServiceBus": {
-      "ConnectionString": "Endpoint=sb://teammodelos.servicebus.chinacloudapi.cn/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=Sy4h4EQ8zP+7w/lOLi1X3tGord/7ShFHimHs1vC50Dc=",
-      "ActiveTask": "dep-active-task",
-      "ItemCondQueue": "dep-itemcond"
-    }
-
     //"Storage": {
-    //  "ConnectionString": "DefaultEndpointsProtocol=https;AccountName=teammodelos;AccountKey=Dl04mfZ9hE9cdPVO1UtqTUQYN/kz/dD/p1nGvSq4tUu/4WhiKcNRVdY9tbe8620nPXo/RaXxs+1F9sVrWRo0bg==;EndpointSuffix=core.chinacloudapi.cn"
+    //  "ConnectionString": "DefaultEndpointsProtocol=https;AccountName=teammodeltest;AccountKey=O2W2vadCqexDxWO+px+QK7y1sHwsYj8f/WwKLdOdG5RwHgW/Dupz9dDUb4c1gi6ojzQaRpFUeAAmOu4N9E+37A==;EndpointSuffix=core.chinacloudapi.cn"
     //},
     //"Cosmos": {
-    //  "ConnectionString": "AccountEndpoint=https://teammodelos.documents.azure.cn:443/;AccountKey=clF73GwPECfP1lKZTCvs8gLMMyCZig1HODFbhDUsarsAURO7TcOjVz6ZFfPqr1HzYrfjCXpMuVD5TlEG5bFGGg==;"
+    //  //"ConnectionString": "AccountEndpoint=https://teammodel.documents.azure.com:443/;AccountKey=opemBAZi0yATewIlhxDYoIEUqncT5qJh3pUBZsBkTqEkuLYTuu3VS7oaDGJlPp8ASwm5SVSrK2caJsjgmqRw9g==;"
+    //  "ConnectionString": "AccountEndpoint=https://cdhabookdep-free.documents.azure.cn:443/;AccountKey=JTUVk92Gjsx17L0xqxn0X4wX2thDPMKiw4daeTyV1HzPb6JmBeHdtFY1MF1jdctW1ofgzqkDMFOtcqS46by31A==;"
+    //  //"ConnectionString": "AccountEndpoint=https://teammodelos.documents.azure.cn:443/;AccountKey=clF73GwPECfP1lKZTCvs8gLMMyCZig1HODFbhDUsarsAURO7TcOjVz6ZFfPqr1HzYrfjCXpMuVD5TlEG5bFGGg==;"
     //},
     //"Redis": {
-    //  "ConnectionString": "CoreRedisCN.redis.cache.chinacloudapi.cn:6380,password=LyJWP1ORJdv+poXWofAF97lhCEQPg1wXWqvtzXGXQuE=,ssl=True,abortConnect=False"
+    //  "ConnectionString": "52.130.252.100:6379,password=habook,ssl=false,abortConnect=False,writeBuffer=10240"
     //},
     //"ServiceBus": {
-    //  "ConnectionString": "Endpoint=sb://coreiotservicebuscnpro.servicebus.chinacloudapi.cn/;SharedAccessKeyName=TEAMModelOS;SharedAccessKey=llRPBMDJG9w1Nnifj+pGhV0g4H2REcq0PjvX2qqpcOg=",
-    //  "ActiveTask": "active-task",
-    //  "ItemCondQueue": "itemcond"
+    //  "ConnectionString": "Endpoint=sb://teammodelos.servicebus.chinacloudapi.cn/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=Sy4h4EQ8zP+7w/lOLi1X3tGord/7ShFHimHs1vC50Dc=",
+    //  "ActiveTask": "dep-active-task",
+    //  "ItemCondQueue": "dep-itemcond"
     //}
+
+    "Storage": {
+      "ConnectionString": "DefaultEndpointsProtocol=https;AccountName=teammodelos;AccountKey=Dl04mfZ9hE9cdPVO1UtqTUQYN/kz/dD/p1nGvSq4tUu/4WhiKcNRVdY9tbe8620nPXo/RaXxs+1F9sVrWRo0bg==;EndpointSuffix=core.chinacloudapi.cn"
+    },
+    "Cosmos": {
+      "ConnectionString": "AccountEndpoint=https://teammodelos.documents.azure.cn:443/;AccountKey=clF73GwPECfP1lKZTCvs8gLMMyCZig1HODFbhDUsarsAURO7TcOjVz6ZFfPqr1HzYrfjCXpMuVD5TlEG5bFGGg==;"
+    },
+    "Redis": {
+      "ConnectionString": "CoreRedisCN.redis.cache.chinacloudapi.cn:6380,password=LyJWP1ORJdv+poXWofAF97lhCEQPg1wXWqvtzXGXQuE=,ssl=True,abortConnect=False"
+    },
+    "ServiceBus": {
+      "ConnectionString": "Endpoint=sb://coreiotservicebuscnpro.servicebus.chinacloudapi.cn/;SharedAccessKeyName=TEAMModelOS;SharedAccessKey=llRPBMDJG9w1Nnifj+pGhV0g4H2REcq0PjvX2qqpcOg=",
+      "ActiveTask": "active-task",
+      "ItemCondQueue": "itemcond"
+    }
   },
   "HaBookAuth": {
     "CoreId": {