Selaa lähdekoodia

处理删除,取消变更操作。排查课例创建出错的问题。

CrazyIter_Bin 3 vuotta sitten
vanhempi
commit
1e8c251f6e

+ 5 - 0
TEAMModelOS.FunctionV4/CosmosDB/TriggerCorrect.cs

@@ -28,6 +28,11 @@ namespace TEAMModelOS.FunctionV4
                 await client.GetContainer(Constant.TEAMModelOS, "Common").DeleteItemStreamAsync(tdata.id, new PartitionKey(tdata.code));
                 await client.GetContainer(Constant.TEAMModelOS, "Common").DeleteItemStreamAsync(tdata.id, new PartitionKey(tdata.code));
                 ActivityList data = input.ToObject<ActivityList>();
                 ActivityList data = input.ToObject<ActivityList>();
                 await ActivityService.DeleteActivity(_coreAPIHttpService, client, _dingDing, data);
                 await ActivityService.DeleteActivity(_coreAPIHttpService, client, _dingDing, data);
+                var table_cancel = _azureStorage.GetCloudTableClient().GetTableReference("ChangeRecord");
+                List<ChangeRecord> records = await table_cancel.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", tdata.id } });
+                foreach (var record in records) {
+                    await _serviceBus.GetServiceBusClient().cancelMessage(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), record.sequenceNumber);
+                }
                 return;
                 return;
             }
             }
             var adid = tdata.id;
             var adid = tdata.id;

+ 6 - 0
TEAMModelOS.FunctionV4/CosmosDB/TriggerExam.cs

@@ -32,6 +32,12 @@ namespace TEAMModelOS.FunctionV4
                     await client.GetContainer(Constant.TEAMModelOS, "Common").DeleteItemStreamAsync(data.id, new PartitionKey(data.code));
                     await client.GetContainer(Constant.TEAMModelOS, "Common").DeleteItemStreamAsync(data.id, new PartitionKey(data.code));
                     ActivityList activity = input.ToObject<ActivityList>();
                     ActivityList activity = input.ToObject<ActivityList>();
                     await ActivityService.DeleteActivity(_coreAPIHttpService, client, _dingDing, activity);
                     await ActivityService.DeleteActivity(_coreAPIHttpService, client, _dingDing, activity);
+                    var table_cancel = _azureStorage.GetCloudTableClient().GetTableReference("ChangeRecord");
+                    List<ChangeRecord> records = await table_cancel.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", data.id } });
+                    foreach (var record in records)
+                    {
+                        await _serviceBus.GetServiceBusClient().cancelMessage(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), record.sequenceNumber);
+                    }
                     return;
                     return;
                 }
                 }
                 ExamInfo info = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ExamInfo>(data.id, new Azure.Cosmos.PartitionKey($"{data.code}"));
                 ExamInfo info = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ExamInfo>(data.id, new Azure.Cosmos.PartitionKey($"{data.code}"));

+ 6 - 0
TEAMModelOS.FunctionV4/CosmosDB/TriggerExamLite.cs

@@ -30,6 +30,12 @@ namespace TEAMModelOS.FunctionV4
                     await client.GetContainer(Constant.TEAMModelOS, "Common").DeleteItemStreamAsync(tdata.id, new PartitionKey(tdata.code));
                     await client.GetContainer(Constant.TEAMModelOS, "Common").DeleteItemStreamAsync(tdata.id, new PartitionKey(tdata.code));
                     ActivityList data = input.ToObject<ActivityList>();
                     ActivityList data = input.ToObject<ActivityList>();
                     await ActivityService.DeleteActivity(_coreAPIHttpService, client, _dingDing, data);
                     await ActivityService.DeleteActivity(_coreAPIHttpService, client, _dingDing, data);
+                    var table_cancel = _azureStorage.GetCloudTableClient().GetTableReference("ChangeRecord");
+                    List<ChangeRecord> records = await table_cancel.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", tdata.id } });
+                    foreach (var record in records)
+                    {
+                        await _serviceBus.GetServiceBusClient().cancelMessage(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), record.sequenceNumber);
+                    }
                     return;
                     return;
                 }
                 }
                 var adid = tdata.id;
                 var adid = tdata.id;

+ 6 - 1
TEAMModelOS.FunctionV4/CosmosDB/TriggerHomework.cs

@@ -30,7 +30,12 @@ namespace TEAMModelOS.FunctionV4
                     await client.GetContainer(Constant.TEAMModelOS, "Common").DeleteItemStreamAsync(tdata.id, new PartitionKey(tdata.code));
                     await client.GetContainer(Constant.TEAMModelOS, "Common").DeleteItemStreamAsync(tdata.id, new PartitionKey(tdata.code));
                     ActivityList data = input.ToObject<ActivityList>();
                     ActivityList data = input.ToObject<ActivityList>();
                     await ActivityService.DeleteActivity(_coreAPIHttpService, client, _dingDing, data);
                     await ActivityService.DeleteActivity(_coreAPIHttpService, client, _dingDing, data);
-
+                    var table_cancel = _azureStorage.GetCloudTableClient().GetTableReference("ChangeRecord");
+                    List<ChangeRecord> records = await table_cancel.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", tdata.id } });
+                    foreach (var record in records)
+                    {
+                        await _serviceBus.GetServiceBusClient().cancelMessage(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), record.sequenceNumber);
+                    }
                     return;
                     return;
                 }
                 }
                 var adid = tdata.id;
                 var adid = tdata.id;

+ 6 - 1
TEAMModelOS.FunctionV4/CosmosDB/TriggerStudy.cs

@@ -30,7 +30,12 @@ namespace TEAMModelOS.FunctionV4
                     await client.GetContainer(Constant.TEAMModelOS, "Common").DeleteItemStreamAsync(tdata.id, new PartitionKey(tdata.code));
                     await client.GetContainer(Constant.TEAMModelOS, "Common").DeleteItemStreamAsync(tdata.id, new PartitionKey(tdata.code));
                     ActivityList data = input.ToObject<ActivityList>();
                     ActivityList data = input.ToObject<ActivityList>();
                     await ActivityService.DeleteActivity(_coreAPIHttpService, client, _dingDing, data);
                     await ActivityService.DeleteActivity(_coreAPIHttpService, client, _dingDing, data);
-                    
+                    var table_cancel = _azureStorage.GetCloudTableClient().GetTableReference("ChangeRecord");
+                    List<ChangeRecord> records = await table_cancel.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", tdata.id } });
+                    foreach (var record in records)
+                    {
+                        await _serviceBus.GetServiceBusClient().cancelMessage(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), record.sequenceNumber);
+                    }
                     return;
                     return;
                 }
                 }
                 var adid = tdata.id;
                 var adid = tdata.id;

+ 6 - 1
TEAMModelOS.FunctionV4/CosmosDB/TriggerSurvey.cs

@@ -38,7 +38,12 @@ namespace TEAMModelOS.FunctionV4
                     await ActivityService.DeleteActivity(_coreAPIHttpService, client, _dingDing, data);
                     await ActivityService.DeleteActivity(_coreAPIHttpService, client, _dingDing, data);
                     _azureRedis.GetRedisClient(8).KeyDelete($"Survey:Record:{tdata.id}");
                     _azureRedis.GetRedisClient(8).KeyDelete($"Survey:Record:{tdata.id}");
                     _azureRedis.GetRedisClient(8).KeyDelete($"Survey:Submit:{tdata.id}");
                     _azureRedis.GetRedisClient(8).KeyDelete($"Survey:Submit:{tdata.id}");
-
+                    var table_cancel = _azureStorage.GetCloudTableClient().GetTableReference("ChangeRecord");
+                    List<ChangeRecord> records = await table_cancel.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", tdata.id } });
+                    foreach (var record in records)
+                    {
+                        await _serviceBus.GetServiceBusClient().cancelMessage(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), record.sequenceNumber);
+                    }
                     return;
                     return;
                 }
                 }
                 var adid = tdata.id;
                 var adid = tdata.id;

+ 6 - 0
TEAMModelOS.FunctionV4/CosmosDB/TriggerVote.cs

@@ -35,6 +35,12 @@ namespace TEAMModelOS.FunctionV4
                     await ActivityService. DeleteActivity(_coreAPIHttpService, client, _dingDing, data);
                     await ActivityService. DeleteActivity(_coreAPIHttpService, client, _dingDing, data);
                     _azureRedis.GetRedisClient(8).KeyDelete($"Vote:Record:{tdata.id}");
                     _azureRedis.GetRedisClient(8).KeyDelete($"Vote:Record:{tdata.id}");
                     _azureRedis.GetRedisClient(8).KeyDelete($"Vote:Count:{tdata.id}");
                     _azureRedis.GetRedisClient(8).KeyDelete($"Vote:Count:{tdata.id}");
+                    var table_cancel = _azureStorage.GetCloudTableClient().GetTableReference("ChangeRecord");
+                    List<ChangeRecord> records = await table_cancel.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", tdata.id } });
+                    foreach (var record in records)
+                    {
+                        await _serviceBus.GetServiceBusClient().cancelMessage(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), record.sequenceNumber);
+                    }
                     return;
                     return;
                 }
                 }
                 var table = _azureStorage.GetCloudTableClient().GetTableReference("ChangeRecord");
                 var table = _azureStorage.GetCloudTableClient().GetTableReference("ChangeRecord");

+ 30 - 26
TEAMModelOS.FunctionV4/ServiceBus/ActiveTaskTopic.cs

@@ -68,7 +68,7 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
             }
             }
             catch (CosmosException e)
             catch (CosmosException e)
             {
             {
-                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,ExamBus()-CosmosDB异常{e.Message}\n{e.Status}{e.StackTrace}", GroupNames.成都开发測試群組);
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,ExamBus()-CosmosDB异常{e.Message}\n{e.Status}{e.StackTrace}\n{msg}", GroupNames.成都开发測試群組);
             }
             }
             catch (Exception ex)
             catch (Exception ex)
             {
             {
@@ -92,7 +92,7 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
             }
             }
             catch (CosmosException e)
             catch (CosmosException e)
             {
             {
-                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,VoteBus()-CosmosDB异常{e.Message}\n{e.Status}{e.StackTrace}", GroupNames.成都开发測試群組);
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,VoteBus()-CosmosDB异常{e.Message}\n{e.Status}{e.StackTrace}\n{msg}", GroupNames.成都开发測試群組);
             }
             }
             catch (Exception ex)
             catch (Exception ex)
             {
             {
@@ -116,7 +116,7 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
             }
             }
             catch (CosmosException e)
             catch (CosmosException e)
             {
             {
-                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,Correct()-CosmosDB异常{e.Message}\n{e.Status}{e.StackTrace}", GroupNames.成都开发測試群組);
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,Correct()-CosmosDB异常{e.Message}\n{e.Status}{e.StackTrace}\n{msg}", GroupNames.成都开发測試群組);
             }
             }
             catch (Exception ex)
             catch (Exception ex)
             {
             {
@@ -141,7 +141,7 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
             }
             }
             catch (CosmosException e)
             catch (CosmosException e)
             {
             {
-                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,SurveyBus()-CosmosDB异常{e.StackTrace}{e.Message}\n{e.Status}", GroupNames.成都开发測試群組);
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,SurveyBus()-CosmosDB异常{e.StackTrace}{e.Message}\n{e.Status}\n{msg}", GroupNames.成都开发測試群組);
             }
             }
             catch (Exception ex)
             catch (Exception ex)
             {
             {
@@ -164,7 +164,7 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
             }
             }
             catch (CosmosException e)
             catch (CosmosException e)
             {
             {
-                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,Homework()-CosmosDB异常{e.StackTrace}{e.Message}{e.StackTrace}\n{e.Status}", GroupNames.成都开发測試群組);
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,Homework()-CosmosDB异常{e.StackTrace}{e.Message}{e.StackTrace}\n{e.Status}\n{msg}", GroupNames.成都开发測試群組);
             }
             }
             catch (Exception ex)
             catch (Exception ex)
             {
             {
@@ -190,7 +190,7 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
             }
             }
             catch (CosmosException e)
             catch (CosmosException e)
             {
             {
-                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,Study()-CosmosDB异常{e.StackTrace}{e.Message}\n{e.Status}", GroupNames.成都开发測試群組);
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,Study()-CosmosDB异常{e.StackTrace}{e.Message}\n{e.Status}\n{msg}", GroupNames.成都开发測試群組);
             }
             }
             catch (Exception ex)
             catch (Exception ex)
             {
             {
@@ -214,7 +214,7 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
             }
             }
             catch (CosmosException e)
             catch (CosmosException e)
             {
             {
-                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,ExamLite()-CosmosDB异常{e.StackTrace}{e.Message}\n{e.Status}", GroupNames.成都开发測試群組);
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,ExamLite()-CosmosDB异常{e.StackTrace}{e.Message}\n{e.Status}\n{msg}", GroupNames.成都开发測試群組);
             }
             }
             catch (Exception ex)
             catch (Exception ex)
             {
             {
@@ -1091,27 +1091,31 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
                                     List<GroupListDto> groupLists = groups?.FindAll(x => !string.IsNullOrEmpty(x.periodId) && x.year > 0 && !string.IsNullOrEmpty(x.school));
                                     List<GroupListDto> groupLists = groups?.FindAll(x => !string.IsNullOrEmpty(x.periodId) && x.year > 0 && !string.IsNullOrEmpty(x.school));
                                     if (groupLists.IsNotEmpty() && !string.IsNullOrWhiteSpace(lessonRecord.periodId))
                                     if (groupLists.IsNotEmpty() && !string.IsNullOrWhiteSpace(lessonRecord.periodId))
                                     {
                                     {
-                                        School schoolObj = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(lessonRecord.school, new PartitionKey("Base"));
-
-                                        //年级算法
-                                        int? Count = schoolObj.period.Find(x => x.id.Equals(lessonRecord.periodId)).grades?.Count;
-                                        if (Count.HasValue)
-                                        {
-                                            int Month = DateTimeOffset.UtcNow.Month;
-                                            int Year = DateTimeOffset.UtcNow.Year;
-                                            foreach (int year in groupLists.Select(x => x.year))
+                                        try {
+                                            School schoolObj = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(lessonRecord.school, new PartitionKey("Base"));
+                                            //年级算法
+                                            var period = schoolObj.period.Find(x => x.id.Equals(lessonRecord.periodId));
+                                            int? Count = period?.grades?.Count;
+                                            if (Count.HasValue)
                                             {
                                             {
-                                                int grade;
-                                                if (Month >= 1 && Month <= 6)
-                                                {
-                                                    grade = (Year - year + 1) / Count.Value;
-                                                }
-                                                else
+                                                int Month = DateTimeOffset.UtcNow.Month;
+                                                int Year = DateTimeOffset.UtcNow.Year;
+                                                foreach (int year in groupLists.Select(x => x.year))
                                                 {
                                                 {
-                                                    grade = (Year - year) / Count.Value;
+                                                    int grade;
+                                                    if (Month >= 1 && Month <= 6)
+                                                    {
+                                                        grade = (Year - year + 1) / Count.Value;
+                                                    }
+                                                    else
+                                                    {
+                                                        grade = (Year - year) / Count.Value;
+                                                    }
+                                                    grades.Add($"{grade}");
                                                 }
                                                 }
-                                                grades.Add($"{grade}");
                                             }
                                             }
+                                        } catch (CosmosException ex) when (ex.Status == 404) { 
+                                            
                                         }
                                         }
                                     }
                                     }
                                     lessonRecord.grade.AddRange(grades);
                                     lessonRecord.grade.AddRange(grades);
@@ -1399,7 +1403,6 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
                         try
                         try
                         {
                         {
                             ItemResponse<StuCourse> stuCourse = await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemAsync<StuCourse>(courseChange.id, new PartitionKey($"StuCourse-{courseChange.school}-{stu.id}"));
                             ItemResponse<StuCourse> stuCourse = await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemAsync<StuCourse>(courseChange.id, new PartitionKey($"StuCourse-{courseChange.school}-{stu.id}"));
-
                             if (stuCourse.Value.stulist.Contains(delList))
                             if (stuCourse.Value.stulist.Contains(delList))
                             {
                             {
                                 stuCourse.Value.stulist.Remove(delList);
                                 stuCourse.Value.stulist.Remove(delList);
@@ -1418,7 +1421,8 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
                         }
                         }
                         catch (CosmosException ex)
                         catch (CosmosException ex)
                         {
                         {
-                            await _dingDing.SendBotMsg($"OS,{ Environment.GetEnvironmentVariable("Option:Location")},CourseServiceBus -CosmosDB异常\n{ex.Message}{ex.StackTrace}", GroupNames.成都开发測試群組);
+                            continue;
+                           // await _dingDing.SendBotMsg($"OS,{ Environment.GetEnvironmentVariable("Option:Location")},CourseServiceBus -CosmosDB异常\n{ex.Message}{ex.StackTrace}", GroupNames.成都开发測試群組);
                         }
                         }
                     }
                     }
                     foreach (var tmd in delTmdidsCls)
                     foreach (var tmd in delTmdidsCls)

+ 1 - 1
TEAMModelOS.SDK/DI/AzureServiceBus/AzureServiceBusExtensions.cs

@@ -69,7 +69,7 @@ namespace TEAMModelOS.SDK.DI
                 return false;
                 return false;
             }
             }
         }
         }
-
+        
         /// <summary>
         /// <summary>
         /// 發送信息至對列或主題(指定時間排程)
         /// 發送信息至對列或主題(指定時間排程)
         /// </summary>       
         /// </summary>