CrazyIter_Bin 2 gadi atpakaļ
vecāks
revīzija
a1ab79f763

+ 27 - 3
TEAMModelOS.FunctionV4/ServiceBus/ActiveTaskTopic.cs

@@ -752,9 +752,9 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
                     //处理教师线下研修报告的生成。
                     //处理教师线下研修报告的生成。
                     await GenOfflineRecordPdf(element, msg);
                     await GenOfflineRecordPdf(element, msg);
                     break;
                     break;
-                //case bool when element.TryGetProperty("bizType", out JsonElement _bizType) && $"{_bizType}".Equals("ArtStudentPdf"):
-                //    await GenArtStudentPdf(element, msg);
-                //    break;
+                case bool when element.TryGetProperty("bizType", out JsonElement _bizType) && $"{_bizType}".Equals("ArtStudentPdf"):
+                    await GenArtStudentPdf(element, msg);
+                    break;
             }
             }
         }
         }
 
 
@@ -770,6 +770,26 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
                 List<string> studentIds= _studentIds.ToObject<List<string>>();
                 List<string> studentIds= _studentIds.ToObject<List<string>>();
                  string _schoolCode=$"{_schoolId}";
                  string _schoolCode=$"{_schoolId}";
                 (List<ArtStudentPdf> studentPdfs, List<StudentArtResult> artResults) = await ArtService.GenStuArtPDF(studentIds,$"{_artId}",   $"{_schoolId}", $"{headLang}", _azureCosmos, _coreAPIHttpService, _dingDing);
                 (List<ArtStudentPdf> studentPdfs, List<StudentArtResult> artResults) = await ArtService.GenStuArtPDF(studentIds,$"{_artId}",   $"{_schoolId}", $"{headLang}", _azureCosmos, _coreAPIHttpService, _dingDing);
+                foreach (var artResult in artResults)
+                {
+                    if (artResult.pdf == null || string.IsNullOrWhiteSpace(artResult.pdf.blob) || string.IsNullOrWhiteSpace(artResult.pdf.url))
+                    {
+                        artResult.pdf = new Attachment
+                        {
+                            // name = $"{artResult.studentId}.pdf",
+                            extension = "pdf",
+                            type = "doc",
+                            cnt = artResult.school,
+                            prime = false,//此处的作用是判断是否已经生成OK.
+                        };
+                    }
+                    else {
+                        artResult.pdf.prime = false;//此处的作用是判断是否已经生成OK.
+                    }
+                    await _azureRedis.GetRedisClient(8).HashSetAsync($"ArtPDF:{_artId}", artResult.studentId, artResult.ToJsonString());
+                }
+                //2个小时。
+                await _azureRedis.GetRedisClient(8).KeyExpireAsync($"ArtPDF:{_artId}",new TimeSpan(2,0,0));
                 List<Task<string>> uploads = new List<Task<string>>();
                 List<Task<string>> uploads = new List<Task<string>>();
                 studentPdfs.ForEach(x => {
                 studentPdfs.ForEach(x => {
                     x.blob = $"art/{x.artId}/report/{x.studentId}.json";
                     x.blob = $"art/{x.artId}/report/{x.studentId}.json";
@@ -806,6 +826,8 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
                         pagesize = 5,
                         pagesize = 5,
                         env = env
                         env = env
                     };
                     };
+                    var message = new ServiceBusMessage(screenshot.ToJsonString());
+                    await _serviceBus.GetServiceBusClient().SendMessageAsync("screenpdf", message);
                 }
                 }
                 else {
                 else {
                     int pages = (urls.Count + psize) / psize;
                     int pages = (urls.Count + psize) / psize;
@@ -824,6 +846,8 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
                             pagesize = 5,
                             pagesize = 5,
                             env = env
                             env = env
                         };
                         };
+                        var message= new ServiceBusMessage(screenshot.ToJsonString());
+                        await _serviceBus.GetServiceBusClient().SendMessageAsync("screenpdf", message);
                     }
                     }
                 }
                 }
             }
             }

+ 1 - 1
TEAMModelOS.SDK/Models/Cosmos/School/Inner/Period.cs

@@ -45,7 +45,7 @@ namespace TEAMModelOS.SDK.Models
         //{ "special","特殊教育"},
         //{ "special","特殊教育"},
         //{ "edu-bureau","教育局"},
         //{ "edu-bureau","教育局"},
         //{ "elecedu-dept","电教部门"},
         //{ "elecedu-dept","电教部门"},
-        public List<string> type { get; set; }= new List<string>();
+       // public List<string> type { get; set; }= new List<string>();
         public string periodType { get; set; }
         public string periodType { get; set; }
     }
     }
 
 

+ 2 - 0
TEAMModelOS.SDK/Models/Cosmos/Student/StudentArtResult.cs

@@ -23,6 +23,8 @@ namespace TEAMModelOS.SDK.Models
         public List<ArtSubjectScore> subjectScores { get; set; } = new List<ArtSubjectScore>();
         public List<ArtSubjectScore> subjectScores { get; set; } = new List<ArtSubjectScore>();
         public List<ArtQuotaResult> results { get; set; } = new List<ArtQuotaResult>();
         public List<ArtQuotaResult> results { get; set; } = new List<ArtQuotaResult>();
         public string blob { get; set; }
         public string blob { get; set; }
+
+        public Attachment pdf { get; set; }= new Attachment();
     }
     }
     public class ArtSubjectScore {
     public class ArtSubjectScore {
         public string subjectId { get; set; }
         public string subjectId { get; set; }

+ 3 - 3
TEAMModelOS.SDK/Models/Service/ArtService.cs

@@ -78,13 +78,13 @@ namespace TEAMModelOS.SDK.Models.Service
             }
             }
             return nodes;
             return nodes;
         }
         }
-        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)
+        public async static Task GenArtPDF (List<string> studentIds, string _artId, string _schoolId, string head_lang,AzureServiceBusFactory _serviceBus, IConfiguration _configuration)
         {
         {
-            var messageBlobPDF = new ServiceBusMessage(new { studentIds = studentIds, artId= _artId, schoolCode = $"{_schoolId}", headLang= head_lang, bizType = "ArtStudentPdf" }.ToJsonString());
+            var messageBlobPDF = new ServiceBusMessage(new { studentIds, artId= _artId, schoolCode = $"{_schoolId}", headLang= head_lang, bizType = "ArtStudentPdf" }.ToJsonString());
             var GenPdfQueue = _configuration.GetValue<string>("Azure:ServiceBus:GenPdfQueue");
             var GenPdfQueue = _configuration.GetValue<string>("Azure:ServiceBus:GenPdfQueue");
             await _serviceBus.GetServiceBusClient().SendMessageAsync(GenPdfQueue, messageBlobPDF);
             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, 
         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) {
               CoreAPIHttpService _coreAPIHttpService, DingDing _dingDing) {
             var client = _azureCosmos.GetCosmosClient();
             var client = _azureCosmos.GetCosmosClient();

+ 27 - 13
TEAMModelOS/Controllers/Both/LessonRecordController.cs

@@ -213,7 +213,7 @@ namespace TEAMModelOS.Controllers
         [AuthToken(Roles = "admin,teacher")]
         [AuthToken(Roles = "admin,teacher")]
         public async Task<IActionResult> DeleteLessonRecord(JsonElement request)
         public async Task<IActionResult> DeleteLessonRecord(JsonElement request)
         {
         {
-            string lessonId;
+            
             string school;
             string school;
             string tbname;
             string tbname;
             string code;
             string code;
@@ -241,19 +241,33 @@ namespace TEAMModelOS.Controllers
                     {
                     {
                         return BadRequest() ;
                         return BadRequest() ;
                     }
                     }
-                    lessonId = $"{_delete_id}";
-                    Azure.Response response = await client.GetContainer(Constant.TEAMModelOS, tbname).ReadItemStreamAsync(lessonId, new PartitionKey(code));
-                    if (response.Status == 200)
+                    List<string> lessonIds = new List<string>();
+                    //string   lessonId = $"{_delete_id}";
+                    if (_delete_id.ValueKind.Equals(JsonValueKind.Array))
                     {
                     {
-                        LessonRecord lessonRecord ;
-                        var doc = JsonDocument.Parse(response.ContentStream);
-                        lessonRecord = doc.RootElement.ToObject<LessonRecord>();
-                        lessonRecord.status =404;
-                        await client.GetContainer(Constant.TEAMModelOS, tbname).ReplaceItemAsync(lessonRecord, lessonRecord.id, new PartitionKey(lessonRecord.code));
-                        var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                        var messageChange = new ServiceBusMessage(request.ToJsonString());
-                        messageChange.ApplicationProperties.Add("name", "LessonRecordEvent");
-                        await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageChange);
+                        lessonIds.AddRange(_delete_id.ToObject<List<string>>());
+                    }
+                    else {
+                        lessonIds.Add($"{_delete_id}");
+                    }
+                    if (lessonIds.IsNotEmpty())
+                    {
+                        foreach (var lessonId in lessonIds) {
+                            Azure.Response response = await client.GetContainer(Constant.TEAMModelOS, tbname).ReadItemStreamAsync(lessonId, new PartitionKey(code));
+                            if (response.Status == 200)
+                            {
+                                LessonRecord lessonRecord;
+                                var doc = JsonDocument.Parse(response.ContentStream);
+                                lessonRecord = doc.RootElement.ToObject<LessonRecord>();
+                                lessonRecord.status = 404;
+                                await client.GetContainer(Constant.TEAMModelOS, tbname).ReplaceItemAsync(lessonRecord, lessonRecord.id, new PartitionKey(lessonRecord.code));
+                                var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
+                                var messageChange = new ServiceBusMessage(request.ToJsonString());
+                                messageChange.ApplicationProperties.Add("name", "LessonRecordEvent");
+                                await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageChange);
+                                
+                            }
+                        }
                         return Ok(new { status = 200 });
                         return Ok(new { status = 200 });
                     }
                     }
                     else { return BadRequest(); }
                     else { return BadRequest(); }

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

@@ -6,8 +6,10 @@ using HTEXLib.COMM.Helpers;
 using Microsoft.AspNetCore.Hosting;
 using Microsoft.AspNetCore.Hosting;
 using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;
 using Microsoft.AspNetCore.Mvc;
+using Microsoft.Azure.Amqp.Framing;
 using Microsoft.Extensions.Configuration;
 using Microsoft.Extensions.Configuration;
 using Microsoft.Extensions.Options;
 using Microsoft.Extensions.Options;
+using StackExchange.Redis;
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.ComponentModel.DataAnnotations;
 using System.ComponentModel.DataAnnotations;
@@ -66,6 +68,58 @@ namespace TEAMModelOS.Controllers
             _converter = converter;
             _converter = converter;
             _httpTrigger = httpTrigger;
             _httpTrigger = httpTrigger;
         }
         }
+
+        /// <summary>
+        /// 轮询获取报告生成进度。
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        [AuthToken(Roles = "teacher,admin")]
+        [HttpPost("gen-pdf-process")]
+        //[Authorize(Roles = "IES")]
+        public async Task<IActionResult> GenPDFProcess(JsonElement request) {
+
+            if (!request.TryGetProperty("artId", out JsonElement _artId))
+            {
+                return BadRequest();
+            }
+            List<RedisValue> studentIds = new List<RedisValue>();
+            if (request.TryGetProperty("studentIds", out JsonElement _studentIds) && _studentIds.ValueKind.Equals(JsonValueKind.Array))
+            {
+              var   studentIdS = _studentIds.ToObject<List<string>>();
+                studentIdS.ForEach(z => { studentIds.Add(z); }) ;
+            }
+            string key = $"ArtPDF:{_artId}";
+            List<StudentArtResult> results= new List<StudentArtResult>();
+            if (studentIds.IsNotEmpty())
+            {
+                var values = _azureRedis.GetRedisClient(8).HashGet(key, studentIds.ToArray());
+                if (values != null)
+                {
+                    foreach (var rcd in values)
+                    {
+                        var value = rcd.ToString().ToObject<StudentArtResult>();
+                        results.Add(value);
+                    }
+                }
+            }
+            else {
+                var values = _azureRedis.GetRedisClient(8).HashGetAll(key);
+                if (values != null)
+                {
+                    foreach (var rcd in values)
+                    {
+                        var value = rcd.Value.ToString().ToObject<StudentArtResult>();
+                        results.Add(value);
+                    }
+                }
+            }
+            var finish = results.Where(z => z.pdf != null && z.pdf.prime == true);
+            var finishData = finish.Select(z => new { z.studentId, z.artId, z.studentName, z.pdf.url, z.pdf.blob, z.pdf.createTime });
+            return Ok(new { total= results.Count ,finishCount= finish.Count(), finishData = finishData });
+        }
+
         /// <summary>
         /// <summary>
         /// 
         /// 
         /// </summary>
         /// </summary>
@@ -107,7 +161,7 @@ namespace TEAMModelOS.Controllers
             {
             {
                 studentIds = _studentIds.ToObject<List<string>>();
                 studentIds = _studentIds.ToObject<List<string>>();
             }
             }
-            await ArtService.GenArtPDF(studentIds, $"{_artId}", $"{_schoolId}", head_lang, _azureCosmos, _environment, _coreAPIHttpService, _dingDing, _serviceBus, _configuration);
+            await ArtService.GenArtPDF(studentIds, $"{_artId}", $"{_schoolId}", head_lang,   _serviceBus, _configuration);
             return Ok(new {code=0,msg="加入PDF报告生成队列中。" });
             return Ok(new {code=0,msg="加入PDF报告生成队列中。" });
         }
         }
         /// <summary>
         /// <summary>
@@ -388,7 +442,7 @@ namespace TEAMModelOS.Controllers
                                     await client.GetContainer(Constant.TEAMModelOS, Constant.Student).ReplaceItemAsync(rs, rs.id, new PartitionKey(rs.code));
                                     await client.GetContainer(Constant.TEAMModelOS, Constant.Student).ReplaceItemAsync(rs, rs.id, new PartitionKey(rs.code));
                                 }
                                 }
                                 if (artResults.Any()) {
                                 if (artResults.Any()) {
-                                    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,   _serviceBus, _configuration);
                                 }
                                 }
                                 return Ok(new { results = studentArtResults, status = 1 });
                                 return Ok(new { results = studentArtResults, status = 1 });
                             }
                             }

+ 6 - 1
TEAMModelOS/Controllers/Third/Sc/ScController.cs

@@ -29,6 +29,7 @@ using System.Web;
 using static TEAMModelOS.Controllers.FixDataController;
 using static TEAMModelOS.Controllers.FixDataController;
 using static TEAMModelOS.SDK.SchoolService;
 using static TEAMModelOS.SDK.SchoolService;
 using Microsoft.AspNetCore.Hosting;
 using Microsoft.AspNetCore.Hosting;
+using Microsoft.Azure.Cosmos.Table;
 
 
 namespace TEAMModelOS.Controllers
 namespace TEAMModelOS.Controllers
 {
 {
@@ -568,7 +569,11 @@ namespace TEAMModelOS.Controllers
                     return Redirect(rurl.Append($"?status=1").ToString());
                     return Redirect(rurl.Append($"?status=1").ToString());
                 }
                 }
                 var table = _azureStorage.GetCloudTableClient().GetTableReference("ScYxpt");
                 var table = _azureStorage.GetCloudTableClient().GetTableReference("ScYxpt");
-                List<ScTeacher> scTeachers = await table.FindListByDict<ScTeacher>(new Dictionary<string, object> { { "PartitionKey", "ScTeacher" }, { "TID", scsso.tid }, { "RowKey", $"{scsso.Pxid}" } });
+
+                string qurey = $"PartitionKey {QueryComparisons.Equal} 'ScTeacher' and TID {QueryComparisons.Equal} {scsso.tid} and  RowKey {QueryComparisons.Equal} '{scsso.Pxid}'  ";
+                var result = await table.ExecuteQuerySegmentedAsync(new TableQuery<ScTeacher>().Where(qurey), null);
+                List<ScTeacher> scTeachers = result.Results;
+                // List<ScTeacher> scTeachers = await table.FindListByDict<ScTeacher>(new Dictionary<string, object> { { "PartitionKey", "ScTeacher" }, { "TID", scsso.tid }, { "RowKey", $"{scsso.Pxid}" } });
                 if (!scTeachers.IsNotEmpty())
                 if (!scTeachers.IsNotEmpty())
                 {
                 {
                     //没有同步省平台
                     //没有同步省平台