Kaynağa Gözat

动态计算年级index

zhouj1203@hotmail.com 4 yıl önce
ebeveyn
işleme
a2e44375d4

+ 29 - 6
TEAMModelFunction/TriggerExam.cs

@@ -206,11 +206,31 @@ namespace TEAMModelFunction
                                         var sresponse = await client.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(cla, new Azure.Cosmos.PartitionKey($"Class-{info.school}"));
                                         if (sresponse.Status == 200)
                                         {
+
                                             using var json = await JsonDocument.ParseAsync(sresponse.ContentStream);
                                             Class classroom = json.ToObject<Class>();
+                                            School sc = await client.GetContainer("TEAMModelOS", "School").ReadItemAsync<School>(info.school, new Azure.Cosmos.PartitionKey("Base"));
+                                            foreach (Period period in sc.period)
+                                            {
+                                                if (period.id.Equals(classroom.periodId))
+                                                {
+                                                    foreach (Semester semester in period.semesters)
+                                                    {
+                                                        if (semester.start == 1)
+                                                        {
+                                                            int year = DateTimeOffset.UtcNow.Year;
+                                                            int month = DateTimeOffset.UtcNow.Month;
+                                                            int day = DateTimeOffset.UtcNow.Day;
+                                                            int time =  month > semester.month ?  0 :  1;
+                                                            int eyear = year - time;
+                                                            result.gradeId = (year - eyear).ToString();
+                                                        }
+                                                    }
+                                                }
+                                            }
                                             //result.info.id = classroom.id;
                                             result.info.name = classroom.name;
-                                            result.gradeId = classroom.gradeId;
+                                            //result.gradeId = classroom.year.ToString();
                                             //处理班级人数
                                             await foreach (var item in client.GetContainer("TEAMModelOS", "Student").GetItemQueryStreamIterator(queryText: $"select c.id from c where c.classId = '{classroom.id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Base-{info.school}") }))
                                             {
@@ -535,7 +555,8 @@ namespace TEAMModelFunction
                 int plcount = 0;
                 //存放并去重知识点
                 HashSet<string> kname = new HashSet<string>();
-                if (info.papers[no].knowledge.Count > 0) {
+                if (info.papers[no].knowledge.Count > 0)
+                {
                     info.papers[no].knowledge.ForEach(kno =>
                     {
                         kno.ForEach(k =>
@@ -631,7 +652,7 @@ namespace TEAMModelFunction
                         //await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(classResult, classResult.id, new Azure.Cosmos.PartitionKey($"{classResult.code}"));
                     }
                 }
-                
+
             }
             catch (Exception ex)
             {
@@ -672,7 +693,8 @@ namespace TEAMModelFunction
                             int phCount = 0;
                             int plCount = 0;
                             int pCount = 0;
-                            if (info.papers[no].field.Count > 0) {
+                            if (info.papers[no].field.Count > 0)
+                            {
                                 foreach (int str in info.papers[no].field)
                                 {
                                     if (str == knowledgeName[i])
@@ -720,7 +742,7 @@ namespace TEAMModelFunction
                                 pl.Add(plCount);
                                 double per = classResult.studentIds.Count > 0 ? Math.Round(score / classResult.studentIds.Count, 2) : 0;
                                 persent.Add(allScore > 0 ? per / allScore : 0);
-                            }                           
+                            }
                         }
                         classResult.fphc = ph;
                         classResult.fplc = pl;
@@ -858,7 +880,8 @@ namespace TEAMModelFunction
                         csRate.Add(classResult.studentIds.Count > 0 ? Math.Round(classSrate * 1.0 / classResult.studentIds.Count, 2) : 0 / allScore);
 
                     }
-                    else {
+                    else
+                    {
                         csRate.Add(0);
                     }
 

+ 23 - 7
TEAMModelOS/Controllers/Teacher/CommentController.cs

@@ -16,6 +16,8 @@ using TEAMModelOS.SDK.Helper.Common.StringHelper;
 using TEAMModelOS.Models;
 using Microsoft.Extensions.Options;
 using System.Text;
+using Azure.Messaging.ServiceBus;
+using Microsoft.Extensions.Configuration;
 
 namespace TEAMModelOS.Controllers
 {
@@ -24,18 +26,22 @@ namespace TEAMModelOS.Controllers
     //[Authorize(Roles = "IES5")]
     [Route("teacher/comment")]
     [ApiController]
-    public class CommentController :ControllerBase
+    public class CommentController : ControllerBase
     {
         private readonly AzureCosmosFactory _azureCosmos;
         private readonly DingDing _dingDing;
         private readonly Option _option;
         private readonly AzureStorageFactory _azureStorage;
-        public CommentController(AzureCosmosFactory azureCosmos, DingDing dingDing, IOptionsSnapshot<Option> option, AzureStorageFactory azureStorage)
+        public IConfiguration _configuration { get; set; }
+        private readonly AzureServiceBusFactory _serviceBus;
+        public CommentController(AzureCosmosFactory azureCosmos, DingDing dingDing, IOptionsSnapshot<Option> option, AzureStorageFactory azureStorage, AzureServiceBusFactory serviceBus, IConfiguration configuration)
         {
             _azureCosmos = azureCosmos;
             _dingDing = dingDing;
             _option = option?.Value;
             _azureStorage = azureStorage;
+            _serviceBus = serviceBus;
+            _configuration = configuration;
         }
 
         /// <summary>
@@ -100,7 +106,7 @@ namespace TEAMModelOS.Controllers
             //    }
             //}
 
-            return Ok();           
+            return Ok();
         }
         /// <summary>
         /// 更新保存教师评语罐头,如果评语列表为空则删除
@@ -126,7 +132,7 @@ namespace TEAMModelOS.Controllers
             //    {
             //        IdPk idPk = await _azureCosmos.DeleteAsync<Comment>(request.id, request.code);
             //    }
-                   
+
             //}
             ////return builder.Data(comment).build();
             return Ok();
@@ -163,7 +169,7 @@ namespace TEAMModelOS.Controllers
                         }
                     }
                 }
-                ExamClassResult classResult = new ExamClassResult();              
+                ExamClassResult classResult = new ExamClassResult();
                 List<List<string>> ans = answer.ToObject<List<List<string>>>();
                 List<List<string>> standard = new List<List<string>>();
                 List<double> points = new List<double>();
@@ -183,9 +189,11 @@ namespace TEAMModelOS.Controllers
                     /*string FileName = result.examId + "/" + result.subjectId + "/" + studentId + "mark";
                     string blob = await _azureStorage.UploadFileByContainer(school.ToString(), ans.ToJsonString(), "exam", FileName + "/" + "ans.json");*/
                     //result.studentAnswers[index].Add(blob);
-                    if (result.mark == null || result.mark.Count == 0) {
+                    if (result.mark == null || result.mark.Count == 0)
+                    {
                         List<string> annotation = new List<string>();
-                        foreach (string ids in result.studentIds) {
+                        foreach (string ids in result.studentIds)
+                        {
                             annotation.Add("");
                         }
                         result.mark = annotation;
@@ -193,7 +201,15 @@ namespace TEAMModelOS.Controllers
                     result.mark[index] = builder.ToString();
                     classResult = await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(result, result.id, new PartitionKey($"{result.code}"));
                 }
+                await Task.WhenAll(tasks);
+               /* //变更blob 大小
+                ExamInfo info = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<ExamInfo>(id.ToString(), new Azure.Cosmos.PartitionKey($"Exam-{school}"));
+                info.size = await _azureStorage.GetBlobContainerClient(school.ToString()).GetBlobsSize($"exam/{id}");
+                var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "annotation", root = $"exam/{id}", name = school }.ToJsonString());
 
+                messageBlob.ApplicationProperties.Add("name", "BlobRoot");
+                var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
+                await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);*/
                 return Ok(new { classResult });
             }
             catch (Exception e)