CrazyIter_Bin 2 년 전
부모
커밋
1e746786b9

+ 11 - 7
TEAMModelOS.FunctionV4/ServiceBus/ActiveTaskTopic.cs

@@ -760,14 +760,16 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
 
      
        
-        private async Task GenArtStudentPdf(JsonElement json, string msg) {
+        private async Task GenArtStudentPdf(JsonElement json , string msg) {
             try
-            {
-                json.TryGetProperty("studentPdfs", out JsonElement _studentPdfs);
-                json.TryGetProperty("artResults", out JsonElement _artResults);
-                json.TryGetProperty("schoolCode", out JsonElement _schoolCode);
-                List<ArtStudentPdf> studentPdfs = _studentPdfs.Deserialize<List<ArtStudentPdf>>();
-                List<StudentArtResult> artResults = _artResults.Deserialize<List<StudentArtResult>>();
+            {  
+                json.TryGetProperty("studentIds", out JsonElement _studentIds);
+                json.TryGetProperty("artId", out JsonElement _artId);
+                json.TryGetProperty("schoolCode", out JsonElement _schoolId);
+                json.TryGetProperty("headLang", out JsonElement headLang);
+                List<string> studentIds= _studentIds.ToObject<List<string>>();
+                 string _schoolCode=$"{_schoolId}";
+                (List<ArtStudentPdf> studentPdfs, List<StudentArtResult> artResults) = await ArtService.GenStuArtPDF(studentIds,$"{_artId}",   $"{_schoolId}", $"{headLang}", _azureCosmos, _coreAPIHttpService, _dingDing);
                 List<Task<string>> uploads = new List<Task<string>>();
                 studentPdfs.ForEach(x => {
                     x.blob = $"art/{x.artId}/report/{x.studentId}.json";
@@ -794,6 +796,7 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
                 {
                     var screenshot = new ScreenshotDto
                     {
+                        msgId=Guid.NewGuid().ToString(),
                         width = 1080,
                         height = 1920,
                         urls = urls,
@@ -811,6 +814,7 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
                         var lists = urls.Skip((i) * psize).Take(psize).ToList();
                         var screenshot = new ScreenshotDto
                         {
+                            msgId = Guid.NewGuid().ToString(),
                             width = 1080,
                             height = 1920,
                             urls = lists,

+ 12 - 8
TEAMModelOS.SDK/Models/Service/ArtService.cs

@@ -78,9 +78,15 @@ namespace TEAMModelOS.SDK.Models.Service
             }
             return nodes;
         }
-
-        public async static Task<List<ArtStudentPdf>> GenArtPDF(List<string> studentIds, string _artId,string _schoolId,string head_lang ,AzureCosmosFactory _azureCosmos, 
-            IWebHostEnvironment _environment, CoreAPIHttpService _coreAPIHttpService, DingDing _dingDing, AzureServiceBusFactory _serviceBus, IConfiguration _configuration) {
+        public async static Task GenArtPDF (List<string> studentIds, string _artId, string _schoolId, string head_lang, AzureCosmosFactory _azureCosmos,
+           IWebHostEnvironment _environment, CoreAPIHttpService _coreAPIHttpService, DingDing _dingDing, AzureServiceBusFactory _serviceBus, IConfiguration _configuration)
+        {
+            var messageBlobPDF = new ServiceBusMessage(new { studentIds = studentIds, artId= _artId, schoolCode = $"{_schoolId}", headLang= head_lang, bizType = "ArtStudentPdf" }.ToJsonString());
+            var GenPdfQueue = _configuration.GetValue<string>("Azure:ServiceBus:GenPdfQueue");
+            await _serviceBus.GetServiceBusClient().SendMessageAsync(GenPdfQueue, messageBlobPDF);
+        }
+        public async static Task<(List<ArtStudentPdf> studentPdfs, List<StudentArtResult> artResults)> GenStuArtPDF(List<string> studentIds, string _artId,string _schoolId,string head_lang ,AzureCosmosFactory _azureCosmos, 
+              CoreAPIHttpService _coreAPIHttpService, DingDing _dingDing) {
             var client = _azureCosmos.GetCosmosClient();
 
             string query = $" select value c from c where c.school  = '{_schoolId}' ";
@@ -95,7 +101,7 @@ namespace TEAMModelOS.SDK.Models.Service
                 artResults.Add(item);
             }
             School school = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemAsync<School>($"{_schoolId}", new PartitionKey("Base"));
-            string path = Path.Combine(_environment.ContentRootPath, $"Lang/{head_lang}.json");
+            string path = Path.Combine("", $"Lang/{head_lang}.json");
             string comment1 = "";
             string comment2 = "";
             string comment3 = "";
@@ -452,10 +458,8 @@ namespace TEAMModelOS.SDK.Models.Service
                 studentPdfs.Add(studentPdf);
             });
             // _ = _httpTrigger.RequestHttpTrigger(new { studentPdfs = studentPdfs, artResults, schoolCode = $"{_schoolId}" }, _option.Location, "gen-art-pdf");
-            var messageBlobPDF = new ServiceBusMessage(new { studentPdfs = studentPdfs, artResults, schoolCode = $"{_schoolId}", bizType = "ArtStudentPdf" }.ToJsonString());
-            var GenPdfQueue = _configuration.GetValue<string>("Azure:ServiceBus:GenPdfQueue");
-            await _serviceBus.GetServiceBusClient().SendMessageAsync(GenPdfQueue, messageBlobPDF);
-            return studentPdfs;
+           
+            return (studentPdfs, artResults);
         }
         private static  JsonDocument readFileJson(string path)
         {

+ 3 - 12
TEAMModelOS/Controllers/School/ArtReviewController.cs

@@ -102,22 +102,13 @@ namespace TEAMModelOS.Controllers
             {
                 return BadRequest();
             }
-
             List<string> studentIds = new List<string>();
             if (request.TryGetProperty("studentIds", out JsonElement _studentIds) && _studentIds.ValueKind.Equals(JsonValueKind.Array))
             {
                 studentIds = _studentIds.ToObject<List<string>>();
             }
-
-
-            var messageBlobPDF = new ServiceBusMessage(new { studentIds = studentIds, artId= $"{_artId}", head_lang, schoolCode = $"{_schoolId}", bizType = "ArtStudentPdf" }.ToJsonString());
-            var GenPdfQueue = _configuration.GetValue<string>("Azure:ServiceBus:GenPdfQueue");
-            await _serviceBus.GetServiceBusClient().SendMessageAsync(GenPdfQueue, messageBlobPDF);
-            var client = _azureCosmos.GetCosmosClient();
-
-          
-            //List<ArtStudentPdf> studentPdfs = await ArtService.GenArtPDF(artResults, $"{_artId}", $"{_schoolId}", head_lang, _azureCosmos, _environment, _coreAPIHttpService, _dingDing, _serviceBus, _configuration);
-            return Ok(new { /*count = studentPdfs.Count(), studentIds = studentPdfs.Select(z => z.studentId)*/ });
+            await ArtService.GenArtPDF(studentIds, $"{_artId}", $"{_schoolId}", head_lang, _azureCosmos, _environment, _coreAPIHttpService, _dingDing, _serviceBus, _configuration);
+            return Ok(new {code=0,msg="加入PDF报告生成队列中。" });
         }
         /// <summary>
         /// 
@@ -397,7 +388,7 @@ namespace TEAMModelOS.Controllers
                                     await client.GetContainer(Constant.TEAMModelOS, Constant.Student).ReplaceItemAsync(rs, rs.id, new PartitionKey(rs.code));
                                 }
                                 if (artResults.Any()) {
-                                    List<ArtStudentPdf> studentPdfs = await ArtService.GenArtPDF(artResults.Select(z=>z.studentId).ToList(), $"{_artId}", $"{school}", head_lang, _azureCosmos, _environment, _coreAPIHttpService, _dingDing, _serviceBus, _configuration);
+                                    await ArtService.GenArtPDF(artResults.Select(z=>z.studentId).ToList(), $"{_artId}", $"{school}", head_lang, _azureCosmos, _environment, _coreAPIHttpService, _dingDing, _serviceBus, _configuration);
                                 }
                                 return Ok(new { results = studentArtResults, status = 1 });
                             }