瀏覽代碼

新增字段

zj 2 年之前
父節點
當前提交
83e192748f

+ 1 - 0
TEAMModelOS.SDK/Models/Cosmos/Common/ArtEvaluation.cs

@@ -75,6 +75,7 @@ namespace TEAMModelOS.SDK.Models.Cosmos.Common
     }
     public class Acs {
         public string acId { get; set; }
+        public string name { get; set; }
         public string subject { get; set; }
         public int? isOrder { get; set; } = 0;
         public int? type { get; set; } = 0;

+ 2 - 0
TEAMModelOS.SDK/Models/Cosmos/Common/ArtRecord.cs

@@ -12,6 +12,8 @@ namespace TEAMModelOS.SDK.Models.Cosmos.Common
         {
             pk = "ArtRecord";
         }
+        public string artId { get; set; }
+        public string quotaId { get; set; }
         public string acId { get; set; }
         public string subject { get; set; }
         public string stuId { get; set; }

+ 94 - 22
TEAMModelOS/Controllers/Common/ExamController.cs

@@ -26,6 +26,10 @@ using System.Net.Http;
 using TEAMModelOS.SDK.DI.CoreAPI;
 using Microsoft.AspNetCore.Hosting;
 using static TEAMModelOS.SDK.SchoolService;
+using Azure.Core;
+using DocumentFormat.OpenXml.Spreadsheet;
+using DocumentFormat.OpenXml.Wordprocessing;
+using Item = TEAMModelOS.SDK.Models.Cosmos.Common.Item;
 
 namespace TEAMModelOS.Controllers
 {
@@ -47,7 +51,7 @@ namespace TEAMModelOS.Controllers
         private readonly NotificationService _notificationService;
         private readonly CoreAPIHttpService _coreAPIHttpService;
         private readonly IWebHostEnvironment _environment;
-        public ExamController(IWebHostEnvironment environment,CoreAPIHttpService coreAPIHttpService, AzureCosmosFactory azureCosmos, AzureServiceBusFactory serviceBus, SnowflakeId snowflakeId, DingDing dingDing,
+        public ExamController(IWebHostEnvironment environment, CoreAPIHttpService coreAPIHttpService, AzureCosmosFactory azureCosmos, AzureServiceBusFactory serviceBus, SnowflakeId snowflakeId, DingDing dingDing,
             IOptionsSnapshot<Option> option, AzureStorageFactory azureStorage, AzureRedisFactory azureRedis, NotificationService notificationService, IConfiguration configuration)
         {
             _azureCosmos = azureCosmos;
@@ -238,7 +242,8 @@ namespace TEAMModelOS.Controllers
                         }
                         exam = await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(request, request.id, new PartitionKey($"{request.code}"));
                     }
-                    else {
+                    else
+                    {
                         if (request.startTime > now)
                         {
                             request.progress = "pending";
@@ -562,8 +567,8 @@ namespace TEAMModelOS.Controllers
 
 
         [ProducesDefaultResponseType]
-/*        [Authorize(Roles = "IES")]
-        [AuthToken(Roles = "teacher,admin")]*/
+        /*        [Authorize(Roles = "IES")]
+                [AuthToken(Roles = "teacher,admin")]*/
         [HttpPost("find-by-analysis")]
         public async Task<IActionResult> FindByAnalysis(JsonElement request)
         {
@@ -649,7 +654,7 @@ namespace TEAMModelOS.Controllers
                 {
                     stringBuilder.Append($" and c.owner= '{owner}' ");
                 }
-                
+
                 if (request.TryGetProperty("year", out JsonElement yy) && !string.IsNullOrWhiteSpace($"{yy}"))
                 {
                     int end = yy.GetInt32() + 1;
@@ -725,10 +730,10 @@ namespace TEAMModelOS.Controllers
                         {
                             exams.Add(obj.ToObject<ExamInfo>());
                         }
-                    }                   
+                    }
                 }
-                var groups = exams.Where(e => null != e.examType && !string.IsNullOrWhiteSpace(e.examType.id)).GroupBy(x =>x.examType.name).Select(y => new { key = y.Key,count = y.ToList().Count}).ToList();
-                return Ok(new { examInfo, token = token, year,count = exams.Count, groups });
+                var groups = exams.Where(e => null != e.examType && !string.IsNullOrWhiteSpace(e.examType.id)).GroupBy(x => x.examType.name).Select(y => new { key = y.Key, count = y.ToList().Count }).ToList();
+                return Ok(new { examInfo, token = token, year, count = exams.Count, groups });
             }
             catch (Exception e)
             {
@@ -1131,6 +1136,7 @@ namespace TEAMModelOS.Controllers
                     }
                     else
                     {
+
                         if ($"{scope}".Equals(Constant.ScopeStudent))
                         {
                             StuActivity activity = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Student").ReadItemAsync<StuActivity>(id.ToString(), new PartitionKey($"Activity-{school}-{userId}"));
@@ -1163,7 +1169,67 @@ namespace TEAMModelOS.Controllers
                 await _dingDing.SendBotMsg($"OS,{_option.Location},exam/upsertRecord()\n{e.Message}\n{e.StackTrace}\n\n{id.GetString()}", GroupNames.醍摩豆服務運維群組);
                 return BadRequest();
             }
+        }
+        private async Task getArtInfoAsync(CosmosClient client, string artId, string school, double score, string acId, string subject, string quotaId, string rId, string userid, string picture, string name)
+        {
+            var aresponse = await client.GetContainer("TEAMModelOS", "Common").ReadItemStreamAsync(artId, new PartitionKey($"Art-{school}"));
+            ArtEvaluation art;
+            StudentArtResult artResult;
+            if (aresponse.Status == 200)
+            {
+                using var json = await JsonDocument.ParseAsync(aresponse.ContentStream);
+                art = json.ToObject<ArtEvaluation>();
+                var response = await client.GetContainer("TEAMModelOS", "Student").ReadItemStreamAsync(rId, new PartitionKey($"ArtResult-{artId}"));
+                if (response.Status == 200)
+                {
+                    using var json_1 = await JsonDocument.ParseAsync(response.ContentStream);
+                    artResult = json_1.ToObject<StudentArtResult>();
+                    bool flage = artResult.results.Exists(a => a.taskId == acId);
+                    if (flage)
+                    {
+                        artResult.results.ForEach(r =>
+                        {
+                            r.score = score;
+                        });
+                    }
+                    else
+                    {
+                        ArtQuotaResult quotaResult = new()
+                        {
+                            taskId = acId,
+                            subjectId = subject,
+                            quotaId = quotaId,
+                            score = score,
+                        };
+                        artResult.results.Add(quotaResult);
+                    }
 
+                    await client.GetContainer("TEAMModelOS", "Student").ReplaceItemAsync(artResult, artResult.id, new PartitionKey($"{artResult.code}"));
+                }
+                else
+                {
+                    artResult = new StudentArtResult
+                    {
+                        id = rId,
+                        pk = "ArtResult",
+                        code = $"ArtResult-{artId}",
+                        studentId = userid,
+                        picture = picture,
+                        studentName = name,
+                        artId = artId,
+                        classIds = art.classes,
+                    };
+                    ArtQuotaResult quotaResult = new()
+                    {
+                        taskId = acId,
+                        subjectId = subject,
+                        quotaId = quotaId,
+                        score = score
+                    };
+                    artResult.results.Add(quotaResult);
+                    await client.GetContainer("TEAMModelOS", "Student").CreateItemAsync(artResult, new PartitionKey($"{artResult.code}"));
+                }
+            }
         }
 
         [ProducesDefaultResponseType]
@@ -1207,7 +1273,7 @@ namespace TEAMModelOS.Controllers
                         examClassResults.Add(item);
                     }
                 }
-                
+
                 ExamClassResult classResult = new ExamClassResult();
                 List<Task<ItemResponse<StuActivity>>> tasks = new List<Task<ItemResponse<StuActivity>>>();
                 //ExamInfo classResult = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ExamInfo>(id.ToString(), new PartitionKey($"{code}"));
@@ -1734,13 +1800,14 @@ namespace TEAMModelOS.Controllers
                     fp = s.filed;
                 }
                 List<List<double>> wno = new();
-                foreach (ExamResult exam in results) {
+                foreach (ExamResult exam in results)
+                {
                     int num = 0;
                     //确定当前循环科目索引位置
                     int index = subId.IndexOf(exam.subjectId);
                     //根据索引找到试卷分数
                     List<double> points = papers[index].point;
-                    List<double> wn = await getWrongNum(exam, points,infoIds);
+                    List<double> wn = await getWrongNum(exam, points, infoIds);
                     wno.Add(wn);
                 }
                 if (papers.IsNotEmpty())
@@ -2913,7 +2980,8 @@ namespace TEAMModelOS.Controllers
                                             from = $"ies5:{_option.Location}:private",
                                             to = ids,
                                             label = $"{bizcode}_school",
-                                            body = new { 
+                                            body = new
+                                            {
                                                 location = _option.Location,
                                                 biz = bizcode,
                                                 tmdid = userid,
@@ -3264,13 +3332,15 @@ namespace TEAMModelOS.Controllers
                             List<string> sIds = account.GetProperty("studentIds").ToObject<List<string>>();
                             List<double> sum = account.GetProperty("sum").ToObject<List<double>>();
                             List<double> nsum = new();
-                            foreach (double s in sum) {
+                            foreach (double s in sum)
+                            {
                                 double ns = 0;
                                 if (s < 0)
                                 {
                                     ns = 0;
                                 }
-                                else {
+                                else
+                                {
                                     ns = s;
                                 }
                                 nsum.Add(ns);
@@ -3281,9 +3351,10 @@ namespace TEAMModelOS.Controllers
                     }
                 }
             }
-            List<(string id, string name, SDK.Models.Custom eType, string scope, string owner, long ctime, List<PaperSimple> points, List<ExamSubject> subject,string source)> exam = new();
-            if (eIds.Count == 0) {
-                return Ok(new {code = 404});
+            List<(string id, string name, SDK.Models.Custom eType, string scope, string owner, long ctime, List<PaperSimple> points, List<ExamSubject> subject, string source)> exam = new();
+            if (eIds.Count == 0)
+            {
+                return Ok(new { code = 404 });
             }
             await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryStreamIterator(
                    queryText: $"select c.id,c.name,c.examType,c.scope,c.owner,c.createTime,c.papers ,c.subjects,c.source from c where c.id in ({string.Join(",", eIds.Select(o => $"'{o}'"))})"))
@@ -3314,7 +3385,7 @@ namespace TEAMModelOS.Controllers
                             account.GetProperty("owner").GetString(), account.GetProperty("createTime").GetInt64(), ps, subs, account.GetProperty("source").GetString()));
                     }
                 }
-            }            
+            }
             var scores = classResults.Select(x => new
             {
                 examId = x.eId,
@@ -3338,7 +3409,7 @@ namespace TEAMModelOS.Controllers
                     x.examId,
                     x.examName,
                     x.cname,
-                    studentId =  stuId.GetString(),
+                    studentId = stuId.GetString(),
                     x.owner,
                     x.createTime,
                     x.eType,
@@ -3349,7 +3420,8 @@ namespace TEAMModelOS.Controllers
                 });
                 return Ok(new { info });
             }
-            else {
+            else
+            {
                 var info = scores.Where(x => !string.IsNullOrEmpty(x.examName)).Select(x => new
                 {
                     x.examId,
@@ -3365,7 +3437,7 @@ namespace TEAMModelOS.Controllers
                     x.sum
                 });
                 return Ok(new { info });
-            };           
+            };
         }
 
         //阅卷信息统计
@@ -3632,7 +3704,7 @@ namespace TEAMModelOS.Controllers
             return (ansBlob, scores);
         }
 
-        private Task<List<double>> getWrongNum(ExamResult result, List<double> points,List<string> infoIds)
+        private Task<List<double>> getWrongNum(ExamResult result, List<double> points, List<string> infoIds)
         {
             int num = 0;
             List<double> wn = new List<double>();