CrazyIter_Bin 1 éve
szülő
commit
ce9ea97140

+ 2 - 2
TEAMModelOS.FunctionV4/CosmosDB/CommonTrigger.cs

@@ -109,10 +109,10 @@ namespace TEAMModelOS.FunctionV4
                                         await TriggerArt.Trigger(_coreAPIHttpService, _serviceBus, _azureStorage, _dingDing, client, element, data, _azureRedis, _configuration, _httpTrigger);
                                         break;
                                     case "ExamImport":
-                                        await TriggerExamImport.Trigger(_coreAPIHttpService, _azureCosmos, _serviceBus, _azureStorage, _dingDing, client, element, data, _httpClient, _configuration);
+                                        await TriggerExamImport.Trigger(_coreAPIHttpService, _azureCosmos, _serviceBus, _azureStorage, _dingDing, client, element, data, _httpClient, _configuration, _azureRedis);
                                         break;
                                     case "QuotaImport":
-                                        await TriggerQuotaImport.Trigger(_coreAPIHttpService, _azureCosmos, _serviceBus, _azureStorage, _dingDing, client, element, data, _httpClient, _configuration);
+                                        await TriggerQuotaImport.Trigger(_coreAPIHttpService, _azureCosmos, _serviceBus, _azureStorage, _dingDing, client, element, data, _httpClient, _configuration, _azureRedis);
                                         break;
                                 }
                             }

+ 4 - 1
TEAMModelOS.FunctionV4/CosmosDB/TriggerExamImport.cs

@@ -19,7 +19,7 @@ namespace TEAMModelOS.FunctionV4.CosmosDB
     public class TriggerExamImport
     {
         public static async Task Trigger(CoreAPIHttpService _coreAPIHttpService, AzureCosmosFactory _azureCosmos, AzureServiceBusFactory _serviceBus, AzureStorageFactory _azureStorage, DingDing _dingDing,
-            CosmosClient client, JsonElement input, TriggerData data, IHttpClientFactory _httpClient, IConfiguration _configuration)
+            CosmosClient client, JsonElement input, TriggerData data, IHttpClientFactory _httpClient, IConfiguration _configuration,AzureRedisFactory _azureRedis)
         { 
             ExamImport examImport= input.ToObject<ExamImport>();
             if (examImport != null) {
@@ -166,6 +166,9 @@ namespace TEAMModelOS.FunctionV4.CosmosDB
                 }
                 foreach (var item in overallEducationChanged) { 
                     await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS,Constant.Student).UpsertItemAsync(item,new PartitionKey(item.code));
+                    string key = $"OverallEducation:{item.schoolCode}:{item.periodId}:{item.year}:{item.semesterId}:{item.classId}";
+                    await _azureRedis.GetRedisClient(8).HashSetAsync(key, item.studentId, item.ToJsonString());
+                    await _azureRedis.GetRedisClient(8).KeyExpireAsync(key, new TimeSpan(180 * 24, 0, 0));
                 }
             }
         }

+ 5 - 2
TEAMModelOS.FunctionV4/CosmosDB/TriggerQuotaImport.cs

@@ -21,7 +21,7 @@ namespace TEAMModelOS.FunctionV4.CosmosDB
     public class TriggerQuotaImport
     {
         public static async Task Trigger(CoreAPIHttpService _coreAPIHttpService, AzureCosmosFactory _azureCosmos, AzureServiceBusFactory _serviceBus, AzureStorageFactory _azureStorage, DingDing _dingDing,
-           CosmosClient client, JsonElement input, TriggerData data, IHttpClientFactory _httpClient, IConfiguration _configuration)
+           CosmosClient client, JsonElement input, TriggerData data, IHttpClientFactory _httpClient, IConfiguration _configuration,AzureRedisFactory _azureRedis)
         {
             QuotaImport quotaImport = input.ToObject<QuotaImport>();
             if (quotaImport != null)
@@ -229,7 +229,10 @@ namespace TEAMModelOS.FunctionV4.CosmosDB
                     }
                 }
                 foreach (var item in overallEducationChanged) { 
-                   await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS,Constant.Student).UpsertItemAsync(item,new PartitionKey (item.code));
+                    await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS,Constant.Student).UpsertItemAsync(item,new PartitionKey (item.code));
+                    string key = $"OverallEducation:{item.schoolCode}:{item.periodId}:{item.year}:{item.semesterId}:{item.classId}";
+                    await _azureRedis.GetRedisClient(8).HashSetAsync(key, item.studentId, item.ToJsonString());
+                    await _azureRedis.GetRedisClient(8).KeyExpireAsync(key, new TimeSpan(180 * 24, 0, 0));
                 }
             }
         }

+ 1 - 1
TEAMModelOS.FunctionV4/HttpTrigger/IESHttpTrigger.cs

@@ -85,7 +85,7 @@ namespace TEAMModelOS.FunctionV4
             string data = await new StreamReader(req.Body).ReadToEndAsync();
             var json = JsonDocument.Parse(data).RootElement;
             var response = req.CreateResponse(HttpStatusCode.OK);
-            var responseData = await OpenApiService.UpsertStudentPortrait(_azureCosmos, _dingDing, json);
+            var responseData = await OpenApiService.UpsertStudentPortrait(_azureCosmos, _dingDing,_azureRedis, json);
             await response.WriteAsJsonAsync(new {data = responseData });
             return response;
         }

+ 1 - 1
TEAMModelOS.FunctionV4/ServiceBus/ActiveTaskTopic.cs

@@ -1478,7 +1478,7 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
                                     //await _dingDing.SendBotMsg($"{_option.Location},课堂id:{_lessonId} blob刷新完成!", GroupNames.醍摩豆服務運維群組);
                                     await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = "records", name = $"{blobname}" }, _serviceBus, _configuration, _azureRedis);
                                     msgs.Add(update);
-                                    DoLessonStudentRecord(_dingDing, _snowflakeId, lessonRecord, scope, client, school, tmdid, teacher, _serviceBus, _azureStorage, _configuration, lessonBase);
+                                    DoLessonStudentRecord(_dingDing, _snowflakeId, lessonRecord, scope, client, school, tmdid, teacher, _serviceBus, _azureStorage, _configuration, lessonBase,_azureRedis);
 
                                 }
                                 catch (Exception ex)

+ 9 - 4
TEAMModelOS.SDK/Models/Service/LessonService.cs

@@ -169,7 +169,7 @@ namespace TEAMModelOS.SDK.Models.Service
             return dict;
         }
         public static async void DoLessonStudentRecord(DingDing _dingding, SnowflakeId snowflakeId, LessonRecord lessonRecord, string scope, CosmosClient client, string school, string tmdid,
-            Teacher teacher,   AzureServiceBusFactory _serviceBus, AzureStorageFactory _azureStorage, IConfiguration _configuration, LessonBase lessonBase)
+            Teacher teacher,   AzureServiceBusFactory _serviceBus, AzureStorageFactory _azureStorage, IConfiguration _configuration, LessonBase lessonBase,AzureRedisFactory _azureRedis)
         {
 
             try
@@ -226,7 +226,7 @@ namespace TEAMModelOS.SDK.Models.Service
                      dataSemester= SchoolService.GetSemester(period);
                 }
                 List <Task<ItemResponse<StudentScoreRecord>>> records = new List<Task<ItemResponse<StudentScoreRecord>>>();
-                List<Task<ItemResponse<OverallEducation>>> overallEducations   = new List<Task<ItemResponse<OverallEducation>>>();
+                 HashSet <OverallEducation> overallEducations   = new HashSet<OverallEducation>();
                 stuids.ToList().ForEach(async x => {
                     var record = lessonStudentRecords.Find(l => l.stuid.Equals(x.id) && l.code.Equals($"StudentScoreRecord") && l.school.Equals(x.school));
                     ClientSummaryList clientSummaryList = lessonBase.report.clientSummaryList.Find(c => c.seatID == x.seatID);
@@ -376,7 +376,7 @@ namespace TEAMModelOS.SDK.Models.Service
                                  );
                             }
                         }
-                        overallEducations.Add(client.GetContainer(Constant.TEAMModelOS, Constant.Student).UpsertItemAsync(overallEducation, partitionKey: new PartitionKey(overallEducation.code)));
+                        overallEducations.Add(overallEducation);
                     }
                     records.Add(client.GetContainer(Constant.TEAMModelOS, Constant.Student).UpsertItemAsync(record, partitionKey: new PartitionKey(record.code)));
                 });
@@ -466,7 +466,12 @@ namespace TEAMModelOS.SDK.Models.Service
                 }
                 if (overallEducations.Any())
                 {
-                    await Task.WhenAll(overallEducations);
+                    foreach (var item in overallEducations) {
+                        await client.GetContainer(Constant.TEAMModelOS, Constant.Student).UpsertItemAsync(item, partitionKey: new PartitionKey(item.code));
+                        string key = $"OverallEducation:{item.schoolCode}:{item.periodId}:{item.year}:{item.semesterId}:{item.classId}";
+                        await _azureRedis.GetRedisClient(8).HashSetAsync(key, item.studentId, item.ToJsonString());
+                        await _azureRedis.GetRedisClient(8).KeyExpireAsync(key,new TimeSpan(180 *24 ,0,0));
+                    }
                 }
             }
             catch (Exception ex)

+ 7 - 1
TEAMModelOS.SDK/Models/Service/OpenApiService.cs

@@ -1681,7 +1681,7 @@ namespace TEAMModelOS.SDK
         /// <param name="_dingDing"></param>
         /// <param name="json"></param>
         /// <returns></returns>
-        public static async Task<ResponseData<dynamic>> UpsertStudentPortrait(AzureCosmosFactory _azureCosmos, DingDing _dingDing,   JsonElement json,string school=null)
+        public static async Task<ResponseData<dynamic>> UpsertStudentPortrait(AzureCosmosFactory _azureCosmos, DingDing _dingDing,AzureRedisFactory _azureRedis ,  JsonElement json,string school=null)
         {
             try
             {
@@ -1980,6 +1980,9 @@ namespace TEAMModelOS.SDK
                                     foreach (var edu in newOverallEducations)
                                     {
                                         await client.GetContainer(Constant.TEAMModelOS, Constant.Student).CreateItemAsync(edu, new PartitionKey(edu.code));
+                                        string key = $"OverallEducation:{edu.schoolCode}:{edu.periodId}:{edu.year}:{edu.semesterId}:{edu.classId}";
+                                        await _azureRedis.GetRedisClient(8).HashSetAsync(key, edu.studentId, edu.ToJsonString());
+                                        await _azureRedis.GetRedisClient(8).KeyExpireAsync(key, new TimeSpan(180 * 24, 0, 0));
                                     }
                                 }
                                 if (overallEducations.Any())
@@ -1988,6 +1991,9 @@ namespace TEAMModelOS.SDK
                                     foreach (var edu in overallEducations)
                                     {
                                         await client.GetContainer(Constant.TEAMModelOS, Constant.Student).ReplaceItemAsync(edu, edu.id, new PartitionKey(edu.code));
+                                        string key = $"OverallEducation:{edu.schoolCode}:{edu.periodId}:{edu.year}:{edu.semesterId}:{edu.classId}";
+                                        await _azureRedis.GetRedisClient(8).HashSetAsync(key, edu.studentId, edu.ToJsonString());
+                                        await _azureRedis.GetRedisClient(8).KeyExpireAsync(key, new TimeSpan(180 * 24, 0, 0));
                                     }
                                 }
                             }

+ 1 - 1
TEAMModelOS/Controllers/OpenApi/Business/BizOverallEducationController.cs

@@ -61,7 +61,7 @@ namespace TEAMModelOS.Controllers
         public async Task<IActionResult> UpsertStudentPortrait(JsonElement jsonElement)
         {
             var (id, school) = HttpContext.GetApiTokenInfo();
-            var responseData = await OpenApiService.UpsertStudentPortrait(_azureCosmos, _dingDing,   jsonElement,school);
+            var responseData = await OpenApiService.UpsertStudentPortrait(_azureCosmos, _dingDing, _azureRedis,   jsonElement,school);
             return Ok(new { responseData });
         }