CrazyIter_Bin 3 years ago
parent
commit
b06faec7ca
1 changed files with 102 additions and 43 deletions
  1. 102 43
      TEAMModelOS/Controllers/XTest/TestController.cs

+ 102 - 43
TEAMModelOS/Controllers/XTest/TestController.cs

@@ -224,66 +224,125 @@ namespace TEAMModelOS.Controllers
         [HttpPost("servicebus")]
         [HttpPost("servicebus")]
         public async Task<IActionResult> Servicebus(ItemCondDto jsonMsg1)
         public async Task<IActionResult> Servicebus(ItemCondDto jsonMsg1)
         {
         {
-            string msg = "[{\"key\":\"xnygxx\",\"filed\":\"fc476b99-c871-4469-aaae-de951c44ae11\",\"scope\":\"school\"}]";
+            string msg = "{\"standard\":\"standard3\",\"tmdids\":[\"1639458944\"],\"school\":\"pjsazx\",\"update\":[\"TeacherAility\"],\"statistics\":0}";
             try
             try
             {
             {
-               
+
+                TeacherTrainChange change = msg.ToObject<TeacherTrainChange>();
+                if (change.update == null || change.update.Count <= 0 || change.tmdids.IsEmpty())
+                {
+                  
+                }
                 var client = _azureCosmos.GetCosmosClient();
                 var client = _azureCosmos.GetCosmosClient();
-                
-                List<ItemCondDto> itemCondDtos = msg.ToObject<List<ItemCondDto>>();
-                foreach (var itemCondDto in itemCondDtos)
+                string insql = $"where c.id in ({string.Join(",", change.tmdids.Select(x => $"'{x}'"))})";
+                string selsql = $"select value(c) from c {insql} ";
+                List<TeacherTrain> teacherTrains = new List<TeacherTrain>();
+                await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<TeacherTrain>(queryText: selsql,
+                      requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"TeacherTrain-{change.school}") }))
                 {
                 {
-                    if (itemCondDto.scope.Equals("school"))
+                    teacherTrains.Add(item);
+                }
+
+                if (change.statistics != 1)
+                {
+
+                    List<Task<ItemResponse<TeacherTrain>>> task = new List<Task<ItemResponse<TeacherTrain>>>();
+                    teacherTrains.ForEach(x => {
+                        x.update.UnionWith(change.update);
+                        task.Add(client.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<TeacherTrain>(x, x.id, new PartitionKey($"TeacherTrain-{change.school}")));
+                    });
+                    await task.TaskPage(5);
+                    var unchange = change.tmdids.Except(teacherTrains.Select(x => x.id));
+                    if (unchange != null)
                     {
                     {
-                        ItemCond itemCond = null;
-                        List<ItemInfo> items = new List<ItemInfo>();
-                        var queryslt = $"SELECT c.gradeIds,c.subjectId,c.periodId,c.type,c.level,c.field ,c.scope FROM c where   c.periodId='{itemCondDto.filed}' and c.pid= null  ";
-                        await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<ItemInfo>(queryText: queryslt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Item-{itemCondDto.key}") }))
-                        {
-                            items.Add(item);
-                        }
-                        itemCond = new ItemCond()
-                        {
-                            id = $"{itemCondDto.filed}",
-                            code = $"ItemCond-{itemCondDto.key}",
-                            pk = "ItemCond",
-                            ttl = -1,
-                            count = items.Count,
-                            grades = new List<GradeCount>(),
-                            subjects = new List<SubjectCount>()
-                        };
-                        items.ForEach(z =>
-                        {
-                            ItemService.CountItemCond(z, null, itemCond);
+                        task.Clear();
+                        unchange.ToList().ForEach(x => {
+                            TeacherTrain teacherTrain = new TeacherTrain
+                            {
+                                pk = "TeacherTrain",
+                                id = x,
+                                code = $"TeacherTrain-{change.school}",
+                                tmdid = x,
+                                school = change.school,
+                                update = new HashSet<string> {  StatisticsService.TeacherAility,
+                        StatisticsService.TeacherClass, StatisticsService.OfflineRecord }
+                            };
+                            teacherTrain.update.UnionWith(change.update);
+                            task.Add(client.GetContainer(Constant.TEAMModelOS, "Teacher").UpsertItemAsync<TeacherTrain>(teacherTrain, new PartitionKey($"TeacherTrain-{change.school}")));
                         });
                         });
-                        await _azureRedis.GetRedisClient(8).HashSetAsync($"ItemCond:{itemCondDto.key}", $"{itemCondDto.filed}", itemCond.ToJsonString());
+                        await task.TaskPage(1);
+                    }
+                }
+                else
+                {
+                    Area area = null;
+                    string sql = $"select value(c) from c where c.standard='{change.standard}'";
+                    await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<Area>(queryText: sql,
+                          requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-Area") }))
+                    {
+                        area = item;
                     }
                     }
-                    else
+                    AreaSetting setting = null;
+                    if (area != null)
                     {
                     {
-                        ItemCond itemCond = null;
-                        List<ItemInfo> items = new List<ItemInfo>();
-                        var queryslt = $"SELECT c.gradeIds,c.subjectId,c.periodId,c.type,c.level,c.field ,c.scope FROM c where c.pid= null  ";
-                        await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<ItemInfo>(queryText: queryslt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Item-{itemCondDto.filed}") }))
+                        try
                         {
                         {
-                            items.Add(item);
+                            //优先找校级
+                            setting = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<AreaSetting>(change.school, new PartitionKey("AreaSetting"));
                         }
                         }
-                        itemCond = new ItemCond() { id = $"{itemCondDto.filed}", code = $"ItemCond", pk = "ItemCond", ttl = -1, count = items.Count };
-                        items.ForEach(z =>
+                        catch (CosmosException)
                         {
                         {
-                            ItemService.CountItemCond(z, null, itemCond);
+                            try
+                            {
+                                setting = await client.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemAsync<AreaSetting>(area.id, new PartitionKey("AreaSetting"));
+                            }
+                            catch (CosmosException)
+                            {
+                                setting = null;
+                            }
+                        }
+                    }
+                    if (setting == null)
+                    {
+                        setting = new AreaSetting
+                        {
+                            allTime = 50,
+                            classTime = 5,
+                            submitTime = 15,
+                            onlineTime = 20,
+                            offlineTime = 10,
+                            lessonMinutes = 45,
+                        };
+                    }
+                    List<Task<TeacherTrain>> task = new List<Task<TeacherTrain>>();
+                    teacherTrains.ForEach(x => {
+                        x.update.UnionWith(change.update);
+                        task.Add(StatisticsService.StatisticsTeacher(x, setting, area, client, null));
+                    });
+                    await task.TaskPage(1);
+                    var unchange = change.tmdids.Except(teacherTrains.Select(x => x.id));
+                    if (unchange != null)
+                    {
+                        task.Clear();
+                        unchange.ToList().ForEach(x => {
+                            task.Add(StatisticsService.StatisticsTeacher(new TeacherTrain
+                            {
+                                pk = "TeacherTrain",
+                                id = x,
+                                code = $"TeacherTrain-{change.school}",
+                                tmdid = x,
+                                school = change.school,
+                                update = new HashSet<string> {  StatisticsService.TeacherAility,
+                                StatisticsService.TeacherClass, StatisticsService.OfflineRecord }
+                            }, setting, area, client, null));
                         });
                         });
-                        await _azureRedis.GetRedisClient(8).HashSetAsync($"ItemCond:ItemCond", $"{itemCondDto.filed}", itemCond.ToJsonString());
+                        await task.TaskPage(1);
                     }
                     }
                 }
                 }
-
-            }
-            catch (CosmosException ex)
-            {
-                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,ItemCond()\n{ex.Message}\n{ex.StackTrace}\n{msg}", GroupNames.醍摩豆服務運維群組);
             }
             }
             catch (Exception ex)
             catch (Exception ex)
             {
             {
-                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,ItemCond()\n{ex.Message}\n{ex.StackTrace}\n{msg}", GroupNames.醍摩豆服務運維群組);
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-研修数据变更,重新统计-TeacherTrainChange\n{msg}\n{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
             }
             }
             return Ok();
             return Ok();
         }
         }