Browse Source

azure function 调整代码

JAELYS 4 years ago
parent
commit
8d6b8b51c7
1 changed files with 59 additions and 59 deletions
  1. 59 59
      TEAMModelFunction/MonitorCosmosDB.cs

+ 59 - 59
TEAMModelFunction/MonitorCosmosDB.cs

@@ -22,7 +22,7 @@ namespace TEAMModelFunction
         private readonly AzureStorageFactory _azureStorage;
         private readonly DingDing _dingDing;
 
-        public MonitorCosmosDB(IHttpClientFactory clientFactory, AzureCosmosFactory azureCosmos,AzureServiceBusFactory azureServiceBus, AzureStorageFactory azureStorage, DingDing dingDing)
+        public MonitorCosmosDB(IHttpClientFactory clientFactory, AzureCosmosFactory azureCosmos, AzureServiceBusFactory azureServiceBus, AzureStorageFactory azureStorage, DingDing dingDing)
         {
             _clientFactory = clientFactory;
             _azureCosmos = azureCosmos;
@@ -48,7 +48,7 @@ namespace TEAMModelFunction
                 {
                     string pk = input.GetPropertyValue<string>("pk");
                     if (!string.IsNullOrWhiteSpace(pk))
-                    {                        
+                    {
                         long stime = input.GetPropertyValue<long>("startTime");
                         long etime = input.GetPropertyValue<long>("endTime");
                         string school = input.GetPropertyValue<string>("school");
@@ -106,6 +106,7 @@ namespace TEAMModelFunction
                                     case "going":
                                         if (examClassResults.Count == 0)
                                         {
+                                            // 初始化ExamClassResult
                                             for (int j = 0; j < info.subjects.Count; j++)
                                             {
                                                 for (int k = 0; k < info.targetClassIds.Count; k++)
@@ -117,9 +118,7 @@ namespace TEAMModelFunction
                                                         id = Guid.NewGuid().ToString(),
                                                         subjectId = info.subjects[j].id,
                                                         year = info.year,
-                                                        scope = info.scope,
-                                                        ttl = -1,
-                                                        pk = typeof(ExamClassResult).Name
+                                                        scope = info.scope
                                                     };
                                                     result.info.id = info.targetClassIds[k];
                                                     var sresponse = await client.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(info.targetClassIds[k], new Azure.Cosmos.PartitionKey($"Class-{info.school}"));
@@ -148,6 +147,7 @@ namespace TEAMModelFunction
 
                                                 }
                                             }
+                                            // 发送信息通知
                                             var messageEnd = new ServiceBusMessage(new { id = input.Id, progress = "finish", code = code }.ToJsonString());
                                             messageEnd.ApplicationProperties.Add("name", "Exam");
                                             if (records.Count > 0)
@@ -172,7 +172,8 @@ namespace TEAMModelFunction
                                                 //await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(changeRecord, new Azure.Cosmos.PartitionKey($"{changeRecord.code}"));
                                             }
                                         }
-                                        else {
+                                        else
+                                        {
                                             for (int j = 0; j < info.subjects.Count; j++)
                                             {
                                                 if (info.subjects[j].classCount == info.targetClassIds.Count)
@@ -186,63 +187,62 @@ namespace TEAMModelFunction
                                     case "finish":
                                         for (int j = 0; j < info.subjects.Count; j++)
                                         {
-                                            
-                                                ExamResult result = new ExamResult();
-                                                //人数总和
-                                                int Count = 0;
-                                                int m = 0;
-                                                List<ClassRange> classRanges = new List<ClassRange>();
-                                                foreach (ExamClassResult classResult in examClassResults)
+                                            ExamResult result = new ExamResult();
+                                            //人数总和
+                                            int Count = 0;
+                                            int m = 0;
+                                            List<ClassRange> classRanges = new List<ClassRange>();
+                                            foreach (ExamClassResult classResult in examClassResults)
+                                            {
+                                                if (classResult.subjectId.Equals(info.subjects[j].id))
                                                 {
-                                                    if (classResult.subjectId.Equals(info.subjects[j].id))
+                                                    foreach (List<double> scores in classResult.studentScores)
                                                     {
-                                                        foreach (List<double> scores in classResult.studentScores)
-                                                        {
-                                                            result.studentScores.Add(scores);
-                                                        }
-                                                        //处理班级信息
-                                                        ClassRange range = new ClassRange();
-                                                        range.id = classResult.info.id;
-                                                        range.name = classResult.info.name;
-                                                        List<int> ran = new List<int>();
-                                                        int stuCount = classResult.studentIds.Count;
-                                                        Count += stuCount;
-                                                        if (m == 0)
-                                                        {
-                                                            ran.Add(0);
-                                                            ran.Add(stuCount - 1);
-                                                        }
-                                                        else
-                                                        {
-                                                            ran.Add(Count - stuCount);
-                                                            ran.Add(Count - 1);
-                                                        }
-                                                        m++;
-                                                        range.range = ran;
-                                                        classRanges.Add(range);
-                                                        //处理学生ID
-                                                        foreach (string id in classResult.studentIds)
-                                                        {
-                                                            result.studentIds.Add(id);
-                                                        }
+                                                        result.studentScores.Add(scores);
+                                                    }
+                                                    //处理班级信息
+                                                    ClassRange range = new ClassRange();
+                                                    range.id = classResult.info.id;
+                                                    range.name = classResult.info.name;
+                                                    List<int> ran = new List<int>();
+                                                    int stuCount = classResult.studentIds.Count;
+                                                    Count += stuCount;
+                                                    if (m == 0)
+                                                    {
+                                                        ran.Add(0);
+                                                        ran.Add(stuCount - 1);
+                                                    }
+                                                    else
+                                                    {
+                                                        ran.Add(Count - stuCount);
+                                                        ran.Add(Count - 1);
+                                                    }
+                                                    m++;
+                                                    range.range = ran;
+                                                    classRanges.Add(range);
+                                                    //处理学生ID
+                                                    foreach (string id in classResult.studentIds)
+                                                    {
+                                                        result.studentIds.Add(id);
                                                     }
                                                 }
-                                                result.classes = classRanges;                                                
-                                                result.pk = typeof(ExamResult).Name;
-                                                result.code = "ExamResult-" + info.id;
-                                                result.school = info.school;
-                                                result.id = info.subjects[j].id;
-                                                result.examId = info.id;
-                                                result.subjectId = info.subjects[j].id;
-                                                result.year = info.year;
-                                                result.paper = info.papers[j];
-                                                //result.point = info.papers[j].point;
-                                                result.scope = info.scope;
-                                                result.name = info.name;
-                                                result.time = info.startTime;
-                                                result.ttl = -1;
-                                                await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Common").UpsertItemAsync(result, new Azure.Cosmos.PartitionKey($"ExamResult-{info.id}"));
-                                            
+                                            }
+                                            result.classes = classRanges;
+                                            result.pk = typeof(ExamResult).Name;
+                                            result.code = "ExamResult-" + info.id;
+                                            result.school = info.school;
+                                            result.id = info.subjects[j].id;
+                                            result.examId = info.id;
+                                            result.subjectId = info.subjects[j].id;
+                                            result.year = info.year;
+                                            result.paper = info.papers[j];
+                                            //result.point = info.papers[j].point;
+                                            result.scope = info.scope;
+                                            result.name = info.name;
+                                            result.time = info.startTime;
+                                            result.ttl = -1;
+                                            await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Common").UpsertItemAsync(result, new Azure.Cosmos.PartitionKey($"ExamResult-{info.id}"));
+
                                         }
                                         break;
                                 }