CrazyIter_Bin 4 hónapja
szülő
commit
a09229e831

+ 2 - 2
TEAMModelOS.Extension/IES.Exam/IES.ExamServer/appsettings.json

@@ -17,10 +17,10 @@
   "Kestrel": {
   "Kestrel": {
     "Endpoints": {
     "Endpoints": {
       "Http": {
       "Http": {
-        "Url": "http://*:5000"
+        "Url": "http://*:6000"
       },
       },
       "Https": {
       "Https": {
-        "Url": "https://*:5001"
+        "Url": "https://*:6001"
       }
       }
     }
     }
   },
   },

+ 56 - 37
TEAMModelOS.SDK/Models/Service/EvaluationSyncInfoService.cs

@@ -90,17 +90,17 @@ namespace TEAMModelOS.SDK.Models.Service
                     evaluationSource.school = school;
                     evaluationSource.school = school;
                     ownerName = school.name;
                     ownerName = school.name;
                     ownerPicture = school.picture;
                     ownerPicture = school.picture;
-                    if (!string.IsNullOrWhiteSpace(ownerPicture))
-                    {
-                        //学校logo 下载到本地、
-                        HttpResponseMessage message = await _httpClientFactory.CreateClient().GetAsync(ownerPicture);
-                        if (message.IsSuccessStatusCode)
-                        {
-                            string base64Prefix = "data:image/jpeg;base64,";
-                            byte[] fileBytes = await message.Content.ReadAsByteArrayAsync();
-                            ownerPicture =$"{base64Prefix}{Convert.ToBase64String(fileBytes)}";
-                        }
-                    }
+                    //if (!string.IsNullOrWhiteSpace(ownerPicture))
+                    //{
+                    //    //学校logo 下载到本地、
+                    //    HttpResponseMessage message = await _httpClientFactory.CreateClient().GetAsync(ownerPicture);
+                    //    if (message.IsSuccessStatusCode)
+                    //    {
+                    //        string base64Prefix = "data:image/jpeg;base64,";
+                    //        byte[] fileBytes = await message.Content.ReadAsByteArrayAsync();
+                    //        ownerPicture =$"{base64Prefix}{Convert.ToBase64String(fileBytes)}";
+                    //    }
+                    //}
                 }
                 }
                 catch (Exception ex) {
                 catch (Exception ex) {
                     await _dingDing.SendBotMsg($"打包评测数据,获取学校信息报错,{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
                     await _dingDing.SendBotMsg($"打包评测数据,获取学校信息报错,{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
@@ -114,17 +114,17 @@ namespace TEAMModelOS.SDK.Models.Service
                     evaluationSource.teacher = teacher;
                     evaluationSource.teacher = teacher;
                     ownerName = teacher.name;
                     ownerName = teacher.name;
                     ownerPicture = teacher.picture;
                     ownerPicture = teacher.picture;
-                    if (!string.IsNullOrWhiteSpace(ownerPicture))
-                    {
-                        //学校logo 下载到本地、
-                        HttpResponseMessage message = await _httpClientFactory.CreateClient().GetAsync(ownerPicture);
-                        if (message.IsSuccessStatusCode)
-                        {
-                            string base64Prefix = "data:image/jpeg;base64,";
-                            byte[] fileBytes = await message.Content.ReadAsByteArrayAsync();
-                            ownerPicture =$"{base64Prefix}{Convert.ToBase64String(fileBytes)}";
-                        }
-                    }
+                    //if (!string.IsNullOrWhiteSpace(ownerPicture))
+                    //{
+                    //    //学校logo 下载到本地、
+                    //    HttpResponseMessage message = await _httpClientFactory.CreateClient().GetAsync(ownerPicture);
+                    //    if (message.IsSuccessStatusCode)
+                    //    {
+                    //        string base64Prefix = "data:image/jpeg;base64,";
+                    //        byte[] fileBytes = await message.Content.ReadAsByteArrayAsync();
+                    //        ownerPicture =$"{base64Prefix}{Convert.ToBase64String(fileBytes)}";
+                    //    }
+                    //}
                 }
                 }
                 catch (Exception ex) { 
                 catch (Exception ex) { 
                     await _dingDing.SendBotMsg($"打包评测数据,获取教师信息报错,{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
                     await _dingDing.SendBotMsg($"打包评测数据,获取教师信息报错,{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
@@ -142,7 +142,7 @@ namespace TEAMModelOS.SDK.Models.Service
                     scope = scope,
                     scope = scope,
                     type = type,
                     type = type,
                     pk="EvaluationSyncInfo",
                     pk="EvaluationSyncInfo",
-                    code="ActivitySyncInfo",
+                    code="EvaluationSyncInfo",
                     ownerId = ownerId,
                     ownerId = ownerId,
                     ownerPicture = ownerPicture,
                     ownerPicture = ownerPicture,
                     ownerName = ownerName,
                     ownerName = ownerName,
@@ -248,21 +248,27 @@ namespace TEAMModelOS.SDK.Models.Service
                                 {
                                 {
                                     var subject = art.subjects.Find(x => x.id.Equals(item.subject));
                                     var subject = art.subjects.Find(x => x.id.Equals(item.subject));
                                     var examResponse=  await azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Common).ReadItemStreamAsync(item.acId, new PartitionKey($"Exam-{ownerId}"));
                                     var examResponse=  await azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Common).ReadItemStreamAsync(item.acId, new PartitionKey($"Exam-{ownerId}"));
-
                                     if (examResponse.IsSuccessStatusCode) 
                                     if (examResponse.IsSuccessStatusCode) 
                                     {
                                     {
                                         ExamInfo exam = JsonDocument.Parse(examResponse.Content).RootElement.Deserialize<ExamInfo>() ;
                                         ExamInfo exam = JsonDocument.Parse(examResponse.Content).RootElement.Deserialize<ExamInfo>() ;
                                         var papers = exam.papers.FindAll(x => x.subjectId.Equals(item.subject));
                                         var papers = exam.papers.FindAll(x => x.subjectId.Equals(item.subject));
-                                        evaluationSyncInfo.subjects.Add(new IES.ExamServer.Models.SubjectExam
+                                        var subjectSync = evaluationSyncInfo.subjects.Find(x => x.examId.Equals(item.acId) && x.subjectId.Equals(item.subject));
+                                        if (subjectSync!=null)
                                         {
                                         {
-                                            subjectId=item.subject,
-                                            subjectName=subject.name,
-                                            examId=item.acId,
-                                            papers=papers?.Select(x => new SubjectExamPaper { paperId=x.id,paperName=x.name, blob=x.blob }).ToList(),
-                                        });
+                                            subjectSync.papers= papers?.Select(x => new SubjectExamPaper { paperId=x.id, paperName=x.name, blob=x.blob }).ToList();
+                                            subjectSync.subjectName=subject.name;
+                                        }
+                                        else {
+                                            evaluationSyncInfo.subjects.Add(new IES.ExamServer.Models.SubjectExam
+                                            {
+                                                subjectId=item.subject,
+                                                subjectName=subject.name,
+                                                examId=item.acId,
+                                                papers = papers?.Select(x => new SubjectExamPaper { paperId=x.id, paperName=x.name, blob=x.blob }).ToList()
+                                            });
+                                        }
                                         dataTime= dataTime<exam._ts*1000 ? exam._ts*1000 : dataTime;
                                         dataTime= dataTime<exam._ts*1000 ? exam._ts*1000 : dataTime;
                                         evaluationSource.artExams.Add(exam);
                                         evaluationSource.artExams.Add(exam);
-
                                         EvaluationExam evaluationExam = new EvaluationExam()
                                         EvaluationExam evaluationExam = new EvaluationExam()
                                         {
                                         {
                                             examId=exam.id,
                                             examId=exam.id,
@@ -294,13 +300,13 @@ namespace TEAMModelOS.SDK.Models.Service
                 long blobSize = 0;
                 long blobSize = 0;
                 long blobCount = 0;
                 long blobCount = 0;
                 
                 
-                if (!string.IsNullOrWhiteSpace(evaluationSyncInfo.shortCode))
+                if (string.IsNullOrWhiteSpace(evaluationSyncInfo.shortCode))
                 {
                 {
                     evaluationSyncInfo.shortCode = $"{MurmurHash3.Hash32(evaluationSyncInfo.id)}";
                     evaluationSyncInfo.shortCode = $"{MurmurHash3.Hash32(evaluationSyncInfo.id)}";
                 }
                 }
                 var listInfo = await GroupListService.GetMemberByListids(_coreAPIHttpService, azureCosmos.GetCosmosClient(), _dingDing, evaluationSyncInfo.grouplist, schoolCode);
                 var listInfo = await GroupListService.GetMemberByListids(_coreAPIHttpService, azureCosmos.GetCosmosClient(), _dingDing, evaluationSyncInfo.grouplist, schoolCode);
                 evaluationSyncInfo.studentCount =  listInfo.rmembers.Count();
                 evaluationSyncInfo.studentCount =  listInfo.rmembers.Count();
-                evaluationSyncInfo.paperCount =evaluationSyncInfo.subjects.Select(x => x.papers).Count();
+                evaluationSyncInfo.paperCount =evaluationSyncInfo.subjects.SelectMany(x => x.papers).Count();
                 var client = azureStorage.GetBlobContainerClient(ownerId);
                 var client = azureStorage.GetBlobContainerClient(ownerId);
                 foreach (var subject in evaluationSyncInfo.subjects)
                 foreach (var subject in evaluationSyncInfo.subjects)
                 {
                 {
@@ -310,7 +316,7 @@ namespace TEAMModelOS.SDK.Models.Service
                         List<BlobHashInfo> blobs = new List<BlobHashInfo>();
                         List<BlobHashInfo> blobs = new List<BlobHashInfo>();
                         try
                         try
                         {
                         {
-                            await foreach (BlobItem blobItem in client.GetBlobsAsync(BlobTraits.None, BlobStates.None, paper.blob))
+                            await foreach (BlobItem blobItem in client.GetBlobsAsync(BlobTraits.None, BlobStates.None, !string.IsNullOrWhiteSpace(paper.blob)&&  paper.blob.StartsWith("/")?paper.blob.Substring(1):paper.blob ))
                             {
                             {
                                 var lastModified = blobItem.Properties.LastModified;
                                 var lastModified = blobItem.Properties.LastModified;
                                 if (lastModified.HasValue)
                                 if (lastModified.HasValue)
@@ -426,6 +432,19 @@ namespace TEAMModelOS.SDK.Models.Service
                     //password = evaluationSyncInfo.password,
                     //password = evaluationSyncInfo.password,
                     //recordUrl = evaluationSyncInfo.recordUrl
                     //recordUrl = evaluationSyncInfo.recordUrl
                 };
                 };
+
+                if (!string.IsNullOrWhiteSpace(ownerPicture))
+                {
+                    //教师头像或学校logo 下载转为Base64
+                    HttpResponseMessage message = await _httpClientFactory.CreateClient().GetAsync(ownerPicture);
+                    if (message.IsSuccessStatusCode)
+                    {
+                        string base64Prefix = "data:image/jpeg;base64,";
+                        byte[] fileBytes = await message.Content.ReadAsByteArrayAsync();
+                        ownerPicture =$"{base64Prefix}{Convert.ToBase64String(fileBytes)}";
+                        evaluationClient.ownerPicture = ownerPicture;
+                    }
+                }
                 long dataSize = 0;
                 long dataSize = 0;
                 string sourceJson = evaluationSource.ToJsonString();
                 string sourceJson = evaluationSource.ToJsonString();
                 dataSize+=  Encoding.UTF8.GetByteCount(sourceJson);
                 dataSize+=  Encoding.UTF8.GetByteCount(sourceJson);
@@ -436,9 +455,9 @@ namespace TEAMModelOS.SDK.Models.Service
                 string evaluationSyncInfoSJson = evaluationSyncInfo.ToJsonString();
                 string evaluationSyncInfoSJson = evaluationSyncInfo.ToJsonString();
                 dataSize+= Encoding.UTF8.GetByteCount(evaluationSyncInfoSJson);
                 dataSize+= Encoding.UTF8.GetByteCount(evaluationSyncInfoSJson);
                 evaluationClient.dataSize = dataSize;
                 evaluationClient.dataSize = dataSize;
-                await azureStorage.GetBlobContainerClient(ownerId).UploadFileByContainer(sourceJson, $"exam/{id}/package", "source.json");
-                await azureStorage.GetBlobContainerClient(ownerId).UploadFileByContainer(groupListJson, $"exam/{id}/package", "grouplist.json");
-                await azureStorage.GetBlobContainerClient(ownerId).UploadFileByContainer(new { evaluationClient, evaluationExams }.ToJsonString(), $"exam/{id}/package", "evaluation.json");
+                await azureStorage.GetBlobContainerClient(ownerId).UploadFileByContainer(sourceJson, $"package/{id}/exam", "source.json");
+                await azureStorage.GetBlobContainerClient(ownerId).UploadFileByContainer(groupListJson, $"package/{id}/exam", "grouplist.json");
+                await azureStorage.GetBlobContainerClient(ownerId).UploadFileByContainer(new { evaluationClient, evaluationExams }.ToJsonString(), $"package/{id}/exam", "evaluation.json");
                 evaluationSyncInfo.dataSize = dataSize;
                 evaluationSyncInfo.dataSize = dataSize;
               
               
                 await azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Normal).UpsertItemAsync<EvaluationSyncInfo>(evaluationSyncInfo, new PartitionKey("EvaluationSyncInfo"));
                 await azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Normal).UpsertItemAsync<EvaluationSyncInfo>(evaluationSyncInfo, new PartitionKey("EvaluationSyncInfo"));

+ 2 - 0
TEAMModelOS/Controllers/Both/EvaluationSyncInfoController.cs

@@ -212,7 +212,9 @@ namespace TEAMModelOS.Controllers.Both
         /// <param name="request"></param>
         /// <param name="request"></param>
         /// <returns></returns>
         /// <returns></returns>
         [ProducesDefaultResponseType]
         [ProducesDefaultResponseType]
+#if !DEBUG
         [AuthToken(Roles = "teacher,admin")]
         [AuthToken(Roles = "teacher,admin")]
+#endif
         [HttpPost("package")]
         [HttpPost("package")]
 //#if !DEBUG
 //#if !DEBUG
 //        [Authorize(Roles = "IES")]
 //        [Authorize(Roles = "IES")]