CrazyIter_Bin 2 years ago
parent
commit
d4987d98ab

+ 15 - 4
TEAMModelOS.FunctionV4/HttpTrigger/IESHttpTrigger.cs

@@ -5,6 +5,7 @@ using HTEXLib.Models;
 using Microsoft.Azure.Cosmos.Table;
 using Microsoft.Azure.Functions.Worker;
 using Microsoft.Azure.Functions.Worker.Http;
+using OpenXmlPowerTools;
 using StackExchange.Redis;
 using System;
 using System.Collections.Generic;
@@ -856,7 +857,7 @@ namespace TEAMModelOS.FunctionV4.HttpTrigger
         /// </summary>
         /// <param name="msg"></param>
         /// <returns></returns>
-        [Function("online-record")]
+        [Function("gen-art-pdf")]
         public async Task<HttpResponseData> GenArtPDF([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequestData req) {
             var response = req.CreateResponse(HttpStatusCode.OK);
             string data = await new StreamReader(req.Body).ReadToEndAsync();
@@ -866,7 +867,7 @@ namespace TEAMModelOS.FunctionV4.HttpTrigger
             List<ArtStudentPdf> studentPdfs = _studentPdfs.Deserialize<List<ArtStudentPdf>>();
             List<Task<string>> uploads = new List<Task<string>>();
             studentPdfs.ForEach(x => {
-                uploads.Add(_azureStorage.GetBlobContainerClient(x.schoolCode).UploadFileByContainer(x.ToJsonString(), "art", $"{x.artId}/report/{x.studentId}.json", true));
+                uploads.Add(_azureStorage.GetBlobContainerClient($"{_schoolCode}").UploadFileByContainer(x.ToJsonString(), "art", $"{x.artId}/report/{x.studentId}.json", true));
             });
             var uploadJsonUrls= await Task.WhenAll(uploads);
             var list =uploadJsonUrls.ToList();
@@ -881,7 +882,12 @@ namespace TEAMModelOS.FunctionV4.HttpTrigger
                     urls.Add(url);
                 }
             });
-            await _httpClient.PostAsJsonAsync("http://cdhabook.teammodel.cn:8805/screen/screenshot-pdf",
+            string env = "release";
+            if (Environment.GetEnvironmentVariable("Option:Location").Contains("Test",StringComparison.CurrentCultureIgnoreCase)||
+                Environment.GetEnvironmentVariable("Option:Location").Contains("Dep", StringComparison.CurrentCultureIgnoreCase)) {
+                env = "develop";
+            }
+            var httpResponse= await _httpClient.PostAsJsonAsync("http://cdhabook.teammodel.cn:8805/screen/screenshot-pdf",
                 new 
                 {
                     width = 1080,
@@ -890,9 +896,14 @@ namespace TEAMModelOS.FunctionV4.HttpTrigger
                     fileNameKey= "pdfpath",
                     cnt=$"{_schoolCode}",
                     root="art",
-                    pagesize=5
+                    pagesize=5,
+                    env = env
                 }
             );
+            if (httpResponse.StatusCode == HttpStatusCode.OK) {
+                JsonElement json_res = await httpResponse.Content.ReadFromJsonAsync<JsonElement>();
+            }
+            await  response.WriteAsJsonAsync(new { data =new { count= studentPdfs.Count } });
             return response;
         }
     }

+ 26 - 2
TEAMModelOS/Controllers/School/ArtReviewController.cs

@@ -1,6 +1,7 @@
 using Azure;
 using Azure.Cosmos;
 using DinkToPdf.Contracts;
+using DocumentFormat.OpenXml.Drawing.Charts;
 using HTEXLib.COMM.Helpers;
 using Microsoft.AspNetCore.Hosting;
 using Microsoft.AspNetCore.Http;
@@ -47,7 +48,8 @@ namespace TEAMModelOS.Controllers
         private readonly IConverter _converter;
         public IConfiguration _configuration { get; set; }
         private readonly CoreAPIHttpService _coreAPIHttpService;
-        public ArtReviewController(IConverter converter, CoreAPIHttpService coreAPIHttpService, AzureCosmosFactory azureCosmos, AzureServiceBusFactory serviceBus, SnowflakeId snowflakeId, DingDing dingDing,
+        private readonly HttpTrigger _httpTrigger;
+        public ArtReviewController(HttpTrigger httpTrigger,IConverter converter, CoreAPIHttpService coreAPIHttpService, AzureCosmosFactory azureCosmos, AzureServiceBusFactory serviceBus, SnowflakeId snowflakeId, DingDing dingDing,
            IOptionsSnapshot<Option> option, AzureStorageFactory azureStorage, AzureRedisFactory azureRedis, IConfiguration configuration, IWebHostEnvironment env)
         {
             _environment = env;
@@ -61,6 +63,7 @@ namespace TEAMModelOS.Controllers
             _azureRedis = azureRedis;
             _configuration = configuration;
             _converter = converter;
+            _httpTrigger= httpTrigger;
         }
         [HttpPost("get-parents")]
         public async Task<IActionResult> GetParents(JsonElement request) {
@@ -114,7 +117,7 @@ namespace TEAMModelOS.Controllers
             {
                 return BadRequest();
             }
-
+            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 comment1 = "";
             string comment2 = "";
@@ -261,12 +264,17 @@ namespace TEAMModelOS.Controllers
                     x.studentName = rmbs[0].name;
                 }
                 List<string> classNames = new List<string>();
+                HashSet<string> periodIds = new HashSet<string>();
                 x.classIds.ForEach(c =>
                 {
                     var gps = groups.FindAll(g => g.id.Equals(c));
                     if (gps.IsNotEmpty())
                     {
                         classNames.Add(gps[0].name);
+                        if (!string.IsNullOrWhiteSpace(gps[0].periodId))
+                        {
+                            periodIds.Add(gps[0].periodId);
+                        }
                     }
                 });
                 allSubjectArtQuotaPdfs.ForEach(x => x.level = level);
@@ -326,8 +334,23 @@ namespace TEAMModelOS.Controllers
                     }
                     comment.Append(comment3.Replace("{quotasLow}", string.Join("、", quota)));
                 }
+                string periodId = "";
+                string periodName = "";
+                string schoolName = "";
+                if (periodIds.Any()) {
+                    var ps=  school.period.FindAll(x => periodIds.Contains(x.id));
+                    if (ps.Any()) {
+                        periodName=String.Join(",", ps.Select(x=>x.name));
+                        periodId= String.Join(",", ps.Select(x => x.id));
+                    }
+                }
+
                 ArtStudentPdf studentPdf = new ArtStudentPdf
                 {
+                    schoolCode=school.id,
+                    schoolName=school.name,
+                    periodId = periodId,
+                    periodName = periodName,
                     studentId = x.studentId,
                     studentName = x.studentName,
                     picture = x.picture,
@@ -340,6 +363,7 @@ namespace TEAMModelOS.Controllers
                 };
                 studentPdfs.Add(studentPdf);
             });
+            _= _httpTrigger.RequestHttpTrigger(new { studentPdfs = studentPdfs , schoolCode =$"{_schoolId}"}, _option.Location, "gen-art-pdf");
             return Ok(new { studentPdfs = studentPdfs });
         }