CrazyIter_Bin 2 年之前
父節點
當前提交
39030f6772

+ 9 - 1
TEAMModelOS.FunctionV4/ServiceBus/ActiveTaskTopic.cs

@@ -407,10 +407,18 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
                 {
                     List<Study> studies = new List<Study>();
                     await foreach (var item in client.GetContainer("TEAMModelOS", "Common")
-                       .GetItemQueryIterator<Study>(queryText: $"select value(c) from c    where c.owner<>'area'  ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Study-{school}") }))
+                       .GetItemQueryIterator<Study>(queryText: $"select value(c) from c    where c.owner<>'area'  ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Study-{school.school}") }))
                     {
                         studies.Add(item);
                     }
+                    if (school.teachers.Any()) {
+                        string trainSql = $"select value(c) from c where c.id in ({string.Join(",", school.teachers.Select(x =>$"'{x}'"))}) ";
+                        await foreach (var item in client.GetContainer("TEAMModelOS", Constant.Teacher)
+                      .GetItemQueryIterator<TeacherTrain>(queryText: trainSql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"TeacherTrain-{school.school}") }))
+                        {
+                            trains.Add(item);
+                        }
+                    }
                     await StatisticsService.GetStatisticsTeacher(trains, setting, area, client, studies);
                 }
                 area.updateTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();

+ 3 - 3
TEAMModelOS.SDK/Models/Service/StatisticsService.cs

@@ -51,11 +51,11 @@ namespace TEAMModelOS.SDK
         public class TeacherTrainChangeMsg {
 
             public string areaId { get; set; }
-            public List<TeacherTrainChangeMsgSchoolTeachers> schools{ get; set; }
+            public List<TeacherTrainChangeMsgSchoolTeachers> schools { get; set; } = new List<TeacherTrainChangeMsgSchoolTeachers>();
         }
         public class TeacherTrainChangeMsgSchoolTeachers { 
             public string school { get; set; }
-            public List<string> teachers { get; set; }
+            public List<string> teachers { get; set; } = new List<string>();
         }
         public static async Task DoChange(TeacherTrainChange change, AzureCosmosFactory _azureCosmos)
         {
@@ -252,7 +252,7 @@ namespace TEAMModelOS.SDK
             //}
  
 
-            returnTrains = updateTeacherTrains;
+            returnTrains .AddRange(updateTeacherTrains) ;
             // await GetStatisticsTeacher(teacherTrains, setting, area, client, studies);
             //await foreach (var tarain in GetStatisticsTeacher(teacherTrains, setting, area, client))
             //{

+ 25 - 17
TEAMModelOS/Controllers/Normal/AbilityStatisticsController.cs

@@ -377,30 +377,38 @@ namespace TEAMModelOS.Controllers
                 List<School> schools = new List<School>();
                 await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<School>(queryText: $"select value(c) from c where c.areaId='{area.id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
                 {
-
                     schools.Add(item);
                 }
-              
                 int countArea = 0;
                 int appraiseArea = 0;
                 List<SchoolInfos> schoolInfos = new List<SchoolInfos>();
                 TeacherTrainChangeMsg msg  = new TeacherTrainChangeMsg() { areaId=area.id};
-                foreach (var school in schools)
+                List<Task> tasks = new List<Task>();
+                List<string> updateTeach = new List<string>();
+                schools.ForEach(  school =>
                 {
-                    schoolInfos.Add(new SchoolInfos { schoolId = school.id, schoolName = school.name, picture = school.picture });
-                    (List<TeacherTrain> trains, List<RGroupList> yxtrain, List < TeacherTrain >   updateTeacherTrains)= await StatisticsService.StatisticsSchoolQuik(_coreAPIHttpService, school.id, setting, area, client, _dingDing, null);
-                    teacherTrains.AddRange( trains);
-                    schoolInfos.ForEach(y => {
-                        var list =yxtrain.Find(z => z.school.Equals(y.schoolId));
-                        if (list != null)
+                    tasks.Add(Task.Run(async () =>
+                    {
+                        schoolInfos.Add(new SchoolInfos { schoolId = school.id, schoolName = school.name, picture = school.picture });
+                        (List<TeacherTrain> trains, List<RGroupList> yxtrain, List<TeacherTrain> updateTeacherTrains) = 
+                        await StatisticsService.StatisticsSchoolQuik(_coreAPIHttpService, school.id, setting, area, client, _dingDing, null);
+                        teacherTrains.AddRange(trains);
+                        schoolInfos.ForEach(y =>
                         {
-                            y.trainCount = list.members.Count;
+                            var list = yxtrain.Find(z => z.school.Equals(y.schoolId));
+                            if (list != null)
+                            {
+                                y.trainCount = list.members.Count;
+                            }
+                        });
+                        if (updateTeacherTrains.IsNotEmpty())
+                        {
+                            updateTeach.AddRange(updateTeacherTrains.Select(z => z.id));
+                            msg.schools.Add(new TeacherTrainChangeMsgSchoolTeachers { school = school.id, teachers = updateTeacherTrains.Select(z => z.id).ToList() });
                         }
-                    });
-                    if (updateTeacherTrains.IsNotEmpty()) {
-                        msg.schools.Add(  new TeacherTrainChangeMsgSchoolTeachers { school = school.id, teachers = updateTeacherTrains.Select(z => z.id).ToList() });
-                    }
-                }
+                    }));
+                });
+                await Task.WhenAll(tasks);
                 bool isnew=false;
                 if (msg.schools.IsNotEmpty())
                 {
@@ -475,11 +483,11 @@ namespace TEAMModelOS.Controllers
                         isnew= true;
                     }
                 }
-                return Ok(new { teacherTrains = dynamics, setting, schools = schoolInfos, totalTime, hgcount, teacherCount = countArea, appraiseCount = appraiseArea, isnew ,area.updateTime});
+                return Ok(new { teacherTrains = dynamics, setting, schools = schoolInfos, totalTime, hgcount, teacherCount = countArea, appraiseCount = appraiseArea, isnew ,area.updateTime, updateTeach });
             }
             catch (Exception ex)
             {
-                await _dingDing.SendBotMsg($"OS,{_option.Location},UpsertSubmitScore/UpsertSubmitScore()\n{ex.Message}\n{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
+                await _dingDing.SendBotMsg($"OS,{_option.Location},StatisticsAreaQuick()\n{ex.Message}\n{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
                 return BadRequest(new { ex.Message, ex.StackTrace });
 
             }