소스 검색

新增每个学校活动最早年份

zhouj1203@hotmail.com 4 년 전
부모
커밋
f682f3bafd
2개의 변경된 파일64개의 추가작업 그리고 12개의 파일을 삭제
  1. 14 0
      TEAMModelOS.SDK/Models/Table/SchoolYear.cs
  2. 50 12
      TEAMModelOS/Controllers/Common/ExamController.cs

+ 14 - 0
TEAMModelOS.SDK/Models/Table/SchoolYear.cs

@@ -0,0 +1,14 @@
+using Microsoft.Azure.Cosmos.Table;
+using System;
+using System.Collections.Generic;
+using System.Text;
+using TEAMModelOS.SDK.Context.Attributes.Azure;
+
+namespace TEAMModelOS.SDK.Models.Table
+{
+    [TableName(Name = "SchoolYear")]
+    public class SchoolYear : TableEntity
+    {
+        public int year { get; set; }
+    }
+}

+ 50 - 12
TEAMModelOS/Controllers/Common/ExamController.cs

@@ -21,6 +21,7 @@ using TEAMModelOS.SDK.Extension;
 using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
 using TEAMModelOS.SDK.Helper.Common.StringHelper;
 using TEAMModelOS.SDK.Models.Cosmos.Common;
+using TEAMModelOS.SDK.Models.Table;
 
 namespace TEAMModelOS.Controllers
 {
@@ -98,7 +99,7 @@ namespace TEAMModelOS.Controllers
                     }
                     if (request.scope.Equals("private"))
                     {
-                        
+
                         //处理发布对象为自选名单(个人)
                         List<StuList> stuLists = new List<StuList>();
                         await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<StuList>(queryText: $"select value(c) from c where c.id = '{request.classes[i]}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"StuList") }))
@@ -183,7 +184,8 @@ namespace TEAMModelOS.Controllers
                     {
                         request.size = await _azureStorage.GetBlobContainerClient(request.school).GetBlobsSize($"exam/{request.id}");
                     }
-                    else {
+                    else
+                    {
                         request.size = await _azureStorage.GetBlobContainerClient(request.creatorId).GetBlobsSize($"exam/{request.id}");
                     }
                     int n = 0;
@@ -266,7 +268,7 @@ namespace TEAMModelOS.Controllers
                 //string school_code = code.ToString().Substring(typeof(ExamClassResult).Name.Length + 1);
                 var response = await client.GetContainer("TEAMModelOS", "Common").DeleteItemStreamAsync(id.ToString(), new PartitionKey($"Exam-{code}"));
                 //删除blob 相关资料
-                await _azureStorage.GetBlobServiceClient().DelectBlobs(code.ToString(),$"exam/{id}");
+                await _azureStorage.GetBlobServiceClient().DelectBlobs(code.ToString(), $"exam/{id}");
                 List<ExamClassResult> examClassResults = new List<ExamClassResult>();
                 await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<ExamClassResult>(queryText: $"select c.id from c where c.examId = '{id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamClassResult-{code}") }))
                 {
@@ -320,6 +322,39 @@ namespace TEAMModelOS.Controllers
             try
             {
                 if (!requert.TryGetProperty("code", out JsonElement code)) return BadRequest();
+                var client = _azureCosmos.GetCosmosClient();
+                List<SchoolYear> years = await _azureStorage.FindListByDict<SchoolYear>(new Dictionary<string, object>() { { "RowKey", code}, { "PartitionKey", "Exam" } });
+                int year = 0;
+                if (years.Count > 0)
+                {
+                    year = years[0].year;
+                }
+                else
+                {
+                    long ct = 0;
+                    await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(queryText: "SELECT  top 1  c.createTime FROM c order by c.createTime  ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Exam-{code}") }))
+                    {
+
+                        using var json = await JsonDocument.ParseAsync(item.ContentStream);
+                        if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
+                        {
+                            var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
+                            while (accounts.MoveNext())
+                            {
+                                JsonElement account = accounts.Current;
+                                ct = account.GetProperty("createTime").GetInt64();
+                            }
+                        }
+                    }
+                    year = DateTimeOffset.FromUnixTimeMilliseconds(ct).Year;
+                    SchoolYear sy = new()
+                    {
+                        RowKey = code.ToString(),
+                        PartitionKey = "Exam",
+                        year = year
+                    };
+                    await _azureStorage.Save<SchoolYear>(sy);
+                }
                 var query = $"select c.id,c.name,c.code,c.period,c.startTime,c.endTime,c.stuCount,c.type,c.progress,c.examType,c.createTime,c.source, c.subjects, c.grades, c.scope,c.classes,c.sRate,c.lostStu from c ";
                 if (requert.TryGetProperty("classIds", out JsonElement classIds))
                 {
@@ -359,7 +394,7 @@ namespace TEAMModelOS.Controllers
                         topcout = data;
                     }
                 }
-                var client = _azureCosmos.GetCosmosClient();
+
                 List<ExamInfo> examInfo = new List<ExamInfo>();
                 await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(queryText: query, continuationToken: token, requestOptions: new QueryRequestOptions() { MaxItemCount = topcout, PartitionKey = new PartitionKey($"Exam-{code}") }))
                 {
@@ -431,7 +466,7 @@ namespace TEAMModelOS.Controllers
                                          score = listExamInfo.FirstOrDefault(c => c.id == o.id).scores,
                                      }
                 );*/
-                return Ok(new { examInfo, token = continuationToken });
+                return Ok(new { examInfo, token = continuationToken, year });
             }
             catch (Exception e)
             {
@@ -1459,7 +1494,7 @@ namespace TEAMModelOS.Controllers
                     {
                         attr.Add(new { stuId = rcd.Name.ToString(), info = value });
                     }
-                   
+
 
 
                 }
@@ -1618,15 +1653,17 @@ namespace TEAMModelOS.Controllers
                 var stuAns = await redisClient.HashGetAsync($"Exam:Scoring:{id}-{subjectId}", sId.ToString());
                 var value = JsonDocument.Parse(stuAns.ToString());
                 value.RootElement.TryGetProperty("ans", out JsonElement blob);
-                await redisClient.HashSetAsync($"Exam:Scoring:{id}-{subjectId}", sId.ToString(), new {ans = blob ,score = score, tmdId = tId, mark = mark }.ToJsonString());
-                if (recs.Count == count.GetInt32()) {
+                await redisClient.HashSetAsync($"Exam:Scoring:{id}-{subjectId}", sId.ToString(), new { ans = blob, score = score, tmdId = tId, mark = mark }.ToJsonString());
+                if (recs.Count == count.GetInt32())
+                {
                     await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<ExamClassResult>(
                     queryText: $"select value(c) from c where c.examId = '{id}' and c.subjectId = '{subjectId}'",
                     requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamClassResult-{code}") }))
                     {
                         classResults.Add(item);
                     }
-                    foreach (ExamClassResult exam in classResults) {
+                    foreach (ExamClassResult exam in classResults)
+                    {
                         foreach (dynamic re in recs)
                         {
                             var cs = JsonSerializer.Serialize(re);
@@ -1636,15 +1673,16 @@ namespace TEAMModelOS.Controllers
                             ans.TryGetProperty("score", out JsonElement sc);
                             ans.TryGetProperty("mark", out JsonElement marks);
                             int index = exam.studentIds.IndexOf(stuId.ToString());
-                            if (index != -1) {
+                            if (index != -1)
+                            {
                                 exam.studentScores[index] = sc.ToObject<List<double>>();
                                 exam.mark[index] = marks.ToString();
                             }
-                            
+
                         }
                         await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(exam, exam.id, new PartitionKey($"{exam.code}"));
                     }
-                    
+
                 }
 
                 return Ok(new { code = 200 });