소스 검색

参数修改

zhouj1203@hotmail.com 3 년 전
부모
커밋
c966f403b1
2개의 변경된 파일61개의 추가작업 그리고 44개의 파일을 삭제
  1. 60 43
      TEAMModelFunction/MonitorServicesBus.cs
  2. 1 1
      TEAMModelOS.SDK/Models/Service/LessonService.cs

+ 60 - 43
TEAMModelFunction/MonitorServicesBus.cs

@@ -28,7 +28,7 @@ namespace TEAMModelFunction
 {
 {
     public class MonitorServicesBus
     public class MonitorServicesBus
     {
     {
-        
+
         private readonly AzureCosmosFactory _azureCosmos;
         private readonly AzureCosmosFactory _azureCosmos;
         private readonly DingDing _dingDing;
         private readonly DingDing _dingDing;
         private readonly AzureStorageFactory _azureStorage;
         private readonly AzureStorageFactory _azureStorage;
@@ -49,7 +49,7 @@ namespace TEAMModelFunction
             _configuration = configuration;
             _configuration = configuration;
         }
         }
         [FunctionName("Exam")]
         [FunctionName("Exam")]
-         public async Task ExamFunc([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "exam", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
+        public async Task ExamFunc([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "exam", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
         {
         {
             try
             try
             {
             {
@@ -159,8 +159,9 @@ namespace TEAMModelFunction
                 homework.progress = progress.ToString();
                 homework.progress = progress.ToString();
                 await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(homework, id.ToString(), new PartitionKey($"{code}"));
                 await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(homework, id.ToString(), new PartitionKey($"{code}"));
             }
             }
-            catch (CosmosException  ) { 
-                
+            catch (CosmosException)
+            {
+
             }
             }
             catch (Exception ex)
             catch (Exception ex)
             {
             {
@@ -216,7 +217,7 @@ namespace TEAMModelFunction
             }
             }
 
 
         }
         }
-        
+
         /// <summary>
         /// <summary>
         /// 根据容器的根目录刷新redis并获取redis的最新使用情况
         /// 根据容器的根目录刷新redis并获取redis的最新使用情况
         /// </summary>
         /// </summary>
@@ -239,8 +240,8 @@ namespace TEAMModelFunction
                     string u = !string.IsNullOrEmpty(uls[0]) ? uls[0] : uls[1];
                     string u = !string.IsNullOrEmpty(uls[0]) ? uls[0] : uls[1];
                     string name = $"{_name}";
                     string name = $"{_name}";
                     string lockKey = $"Blob:Lock:{name}:{u}";
                     string lockKey = $"Blob:Lock:{name}:{u}";
-                    bool exist= await _azureRedis.GetRedisClient(8).KeyExistsAsync(lockKey);
-                   
+                    bool exist = await _azureRedis.GetRedisClient(8).KeyExistsAsync(lockKey);
+
                     if (!exist)
                     if (!exist)
                     {   ///key不存在则正常进行计算
                     {   ///key不存在则正常进行计算
                         bool condition = false;
                         bool condition = false;
@@ -254,17 +255,19 @@ namespace TEAMModelFunction
                         var rds = await CheckLockKey(lockKey, action);
                         var rds = await CheckLockKey(lockKey, action);
                         condition = rds.condition;
                         condition = rds.condition;
                         exist = rds.exist;
                         exist = rds.exist;
-                        if (condition || !exist) {
+                        if (condition || !exist)
+                        {
                             await RefreshBlob(name, u);
                             await RefreshBlob(name, u);
                         }
                         }
-                        
+
                         //使用  CancellationToken 
                         //使用  CancellationToken 
                         //while (condition || !exist)
                         //while (condition || !exist)
                         //{
                         //{
 
 
                         //}
                         //}
                     }
                     }
-                    else {
+                    else
+                    {
                         ///key存在则,则刷新key对应的值
                         ///key存在则,则刷新key对应的值
                         TimeSpan timeSpan = new TimeSpan(DateTimeOffset.UtcNow.AddMinutes(5).Ticks);
                         TimeSpan timeSpan = new TimeSpan(DateTimeOffset.UtcNow.AddMinutes(5).Ticks);
                         timeSpan = timeSpan - new TimeSpan(DateTimeOffset.UtcNow.Ticks);
                         timeSpan = timeSpan - new TimeSpan(DateTimeOffset.UtcNow.Ticks);
@@ -281,7 +284,8 @@ namespace TEAMModelFunction
             }
             }
         }
         }
 
 
-        private async Task<(bool condition,bool exist)> CheckLockKey(string lockKey,long  nowTime) {
+        private async Task<(bool condition, bool exist)> CheckLockKey(string lockKey, long nowTime)
+        {
             //Redis的最新时间
             //Redis的最新时间
             long newestTime = 0;
             long newestTime = 0;
             RedisValue value = await _azureRedis.GetRedisClient(8).StringGetAsync(lockKey);
             RedisValue value = await _azureRedis.GetRedisClient(8).StringGetAsync(lockKey);
@@ -298,7 +302,8 @@ namespace TEAMModelFunction
                 return (false, true);
                 return (false, true);
             }
             }
             //说明key存在
             //说明key存在
-            else {
+            else
+            {
                 //说明Redis记录了最新的时间戳
                 //说明Redis记录了最新的时间戳
                 if (nowTime != newestTime)
                 if (nowTime != newestTime)
                 {
                 {
@@ -312,7 +317,8 @@ namespace TEAMModelFunction
                 }
                 }
             }
             }
         }
         }
-        private async Task RefreshBlob(string  name ,string  u) {
+        private async Task RefreshBlob(string name, string u)
+        {
             long statr = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
             long statr = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
             var client = _azureStorage.GetBlobContainerClient(name);
             var client = _azureStorage.GetBlobContainerClient(name);
             var size = await client.GetBlobsSize(u);
             var size = await client.GetBlobsSize(u);
@@ -329,9 +335,10 @@ namespace TEAMModelFunction
             }
             }
             await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", new RedisValue(name), new RedisValue($"{blobsize}"));
             await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", new RedisValue(name), new RedisValue($"{blobsize}"));
             long end = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
             long end = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
-            long dis = (end - statr)/1000;
+            long dis = (end - statr) / 1000;
             long timeout = 10;
             long timeout = 10;
-            if (dis> timeout) {
+            if (dis > timeout)
+            {
                 await _dingDing.SendBotMsg($"ServiceBus,RefreshBlob:空间计算已经超过{timeout}秒\n容器名:{name}\n文件夹:{u}\n计算时长:{dis}", GroupNames.醍摩豆服務運維群組);
                 await _dingDing.SendBotMsg($"ServiceBus,RefreshBlob:空间计算已经超过{timeout}秒\n容器名:{name}\n文件夹:{u}\n计算时长:{dis}", GroupNames.醍摩豆服務運維群組);
             }
             }
         }
         }
@@ -345,7 +352,8 @@ namespace TEAMModelFunction
         /// <param name="msg"></param>
         /// <param name="msg"></param>
         /// <returns></returns>
         /// <returns></returns>
         [FunctionName("TeacherTrainChange")]
         [FunctionName("TeacherTrainChange")]
-        public async Task TeacherTrainChangeFunc([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "teacher-train-change", Connection = "Azure:ServiceBus:ConnectionString")] string msg) {
+        public async Task TeacherTrainChangeFunc([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "teacher-train-change", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
+        {
             try
             try
             {
             {
                 // await _dingDing.SendBotMsg($"teacher-train-change\n{msg}",GroupNames.成都开发測試群組);
                 // await _dingDing.SendBotMsg($"teacher-train-change\n{msg}",GroupNames.成都开发測試群組);
@@ -465,7 +473,8 @@ namespace TEAMModelFunction
                     }
                     }
                 }
                 }
             }
             }
-            catch (CosmosException ex) {
+            catch (CosmosException ex)
+            {
                 await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-研修数据变更,重新统计-TeacherTrainChange\n{msg}\n{ex.Message}\n{ex.StackTrace}CosmosException{ex.Status}", GroupNames.成都开发測試群組);
                 await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-研修数据变更,重新统计-TeacherTrainChange\n{msg}\n{ex.Message}\n{ex.StackTrace}CosmosException{ex.Status}", GroupNames.成都开发測試群組);
             }
             }
             catch (Exception ex)
             catch (Exception ex)
@@ -504,13 +513,13 @@ namespace TEAMModelFunction
                 await ActivityService.FixActivity(client, _dingDing, groupChange, "Study");
                 await ActivityService.FixActivity(client, _dingDing, groupChange, "Study");
                 //名单变动修改学生简易评测关联信息
                 //名单变动修改学生简易评测关联信息
                 await ActivityService.FixActivity(client, _dingDing, groupChange, "ExamLite");
                 await ActivityService.FixActivity(client, _dingDing, groupChange, "ExamLite");
-                
+
                 //TODO学习活动
                 //TODO学习活动
                 //await FixActivity(client, stuListChange, "Learn");
                 //await FixActivity(client, stuListChange, "Learn");
                 //名单变动修改学生作业活动信息
                 //名单变动修改学生作业活动信息
                 await ActivityService.FixActivity(client, _dingDing, groupChange, "Homework");
                 await ActivityService.FixActivity(client, _dingDing, groupChange, "Homework");
 
 
-                if (groupChange.type == null || !groupChange.type.Equals("research") || !groupChange.type.Equals("yxtrain")|| !groupChange.type.Equals("activity"))
+                if (groupChange.type == null || !groupChange.type.Equals("research") || !groupChange.type.Equals("yxtrain") || !groupChange.type.Equals("activity"))
                 {
                 {
                     //课程名单变动修改学生课程关联信息
                     //课程名单变动修改学生课程关联信息
                     await ActivityService.FixStuCourse(client, _dingDing, groupChange);
                     await ActivityService.FixStuCourse(client, _dingDing, groupChange);
@@ -531,7 +540,8 @@ namespace TEAMModelFunction
                 List<ItemCondDto> itemCondDtos = msg.ToObject<List<ItemCondDto>>();
                 List<ItemCondDto> itemCondDtos = msg.ToObject<List<ItemCondDto>>();
                 foreach (var itemCondDto in itemCondDtos)
                 foreach (var itemCondDto in itemCondDtos)
                 {
                 {
-                    if (itemCondDto.scope.Equals("school")) {
+                    if (itemCondDto.scope.Equals("school"))
+                    {
                         ItemCond itemCond = null;
                         ItemCond itemCond = null;
                         List<ItemInfo> items = new List<ItemInfo>();
                         List<ItemInfo> items = new List<ItemInfo>();
                         var queryslt = $"SELECT c.gradeIds,c.subjectId,c.periodId,c.type,c.level,c.field ,c.scope FROM c where   c.periodId='{itemCondDto.filed}' and c.pid= null  ";
                         var queryslt = $"SELECT c.gradeIds,c.subjectId,c.periodId,c.type,c.level,c.field ,c.scope FROM c where   c.periodId='{itemCondDto.filed}' and c.pid= null  ";
@@ -551,7 +561,8 @@ namespace TEAMModelFunction
                         };
                         };
                         items.ForEach(z =>
                         items.ForEach(z =>
                         {
                         {
-                            if (!string.IsNullOrEmpty(z.type)) {
+                            if (!string.IsNullOrEmpty(z.type))
+                            {
                                 ItemService.CountItemCond(z, null, itemCond);
                                 ItemService.CountItemCond(z, null, itemCond);
                             }
                             }
                         });
                         });
@@ -577,9 +588,9 @@ namespace TEAMModelFunction
                         await _azureRedis.GetRedisClient(8).HashSetAsync($"ItemCond:ItemCond", $"{itemCondDto.filed}", itemCond.ToJsonString());
                         await _azureRedis.GetRedisClient(8).HashSetAsync($"ItemCond:ItemCond", $"{itemCondDto.filed}", itemCond.ToJsonString());
                     }
                     }
                 }
                 }
-                 
+
             }
             }
-            catch (CosmosException ex )
+            catch (CosmosException ex)
             {
             {
                 await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,ItemCond()\n{ex.Message}\n{ex.StackTrace}\n{msg}", GroupNames.醍摩豆服務運維群組);
                 await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,ItemCond()\n{ex.Message}\n{ex.StackTrace}\n{msg}", GroupNames.醍摩豆服務運維群組);
             }
             }
@@ -615,7 +626,7 @@ namespace TEAMModelFunction
                         {
                         {
                             SchoolProductSerial serialInfo = obj.ToObject<SchoolProductSerial>();
                             SchoolProductSerial serialInfo = obj.ToObject<SchoolProductSerial>();
                             SchoolProductSumData serialProd = serialsProductSumOrg.Where(sp => sp.prodCode == serialInfo.prodCode).FirstOrDefault();
                             SchoolProductSumData serialProd = serialsProductSumOrg.Where(sp => sp.prodCode == serialInfo.prodCode).FirstOrDefault();
-                            if(serialProd == null)
+                            if (serialProd == null)
                             {
                             {
                                 SchoolProductSumData serialProdAdd = new SchoolProductSumData();
                                 SchoolProductSumData serialProdAdd = new SchoolProductSumData();
                                 serialProdAdd.prodCode = serialInfo.prodCode;
                                 serialProdAdd.prodCode = serialInfo.prodCode;
@@ -625,7 +636,7 @@ namespace TEAMModelFunction
                             }
                             }
                             else
                             else
                             {
                             {
-                                if(!serialProd.ids.Contains(serialInfo.id))
+                                if (!serialProd.ids.Contains(serialInfo.id))
                                 {
                                 {
                                     serialProd.ids.Add(serialInfo.id);
                                     serialProd.ids.Add(serialInfo.id);
                                 }
                                 }
@@ -738,7 +749,7 @@ namespace TEAMModelFunction
         /// <param name="msg"></param>
         /// <param name="msg"></param>
         /// <returns></returns>
         /// <returns></returns>
         [FunctionName("CopyStandardFile")]
         [FunctionName("CopyStandardFile")]
-        public async Task BatchCopyBlobFunc([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "copy-standard-file", Connection = "Azure:ServiceBus:ConnectionString")] string msg) 
+        public async Task BatchCopyBlobFunc([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "copy-standard-file", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
         {
         {
             try
             try
             {
             {
@@ -780,16 +791,17 @@ namespace TEAMModelFunction
         /// <param name="msg"></param>
         /// <param name="msg"></param>
         /// <returns></returns>
         /// <returns></returns>
         [FunctionName("LessonRecordEvent")]
         [FunctionName("LessonRecordEvent")]
-        public async Task LessonRecordFunc([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "lesson-record-event", Connection = "Azure:ServiceBus:ConnectionString")] string msg) {
+        public async Task LessonRecordFunc([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "lesson-record-event", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
+        {
+
 
 
 
 
-            
 
 
-            JsonElement  data =  msg.ToObject<JsonElement>();
+            JsonElement data = msg.ToObject<JsonElement>();
             string scope = "";
             string scope = "";
             string tmdid = "";
             string tmdid = "";
             string lessonId;
             string lessonId;
-            string school ;
+            string school;
             string tbname;
             string tbname;
             string code;
             string code;
             string blobname;
             string blobname;
@@ -806,7 +818,7 @@ namespace TEAMModelFunction
                 tmdid = $"{_tmdid}";
                 tmdid = $"{_tmdid}";
                 lessonId = $"{_lessonId}";
                 lessonId = $"{_lessonId}";
                 updates = _grant_types.ToObject<List<LessonUpdate>>();
                 updates = _grant_types.ToObject<List<LessonUpdate>>();
-                
+
             }//创建课堂记录
             }//创建课堂记录
             else if (data.TryGetProperty("id", out JsonElement _id) && !string.IsNullOrEmpty($"{_id}")
             else if (data.TryGetProperty("id", out JsonElement _id) && !string.IsNullOrEmpty($"{_id}")
                 && data.TryGetProperty("tmdid", out JsonElement _tmdid) && !string.IsNullOrEmpty($"{_tmdid}")
                 && data.TryGetProperty("tmdid", out JsonElement _tmdid) && !string.IsNullOrEmpty($"{_tmdid}")
@@ -817,7 +829,7 @@ namespace TEAMModelFunction
                 scope = $"{_scope}";
                 scope = $"{_scope}";
                 tmdid = $"{_tmdid}";
                 tmdid = $"{_tmdid}";
                 lessonId = $"{_id}";
                 lessonId = $"{_id}";
-                updates.Add(new LessonUpdate { grant_type= "create" });
+                updates.Add(new LessonUpdate { grant_type = "create" });
             }//删除课堂记录
             }//删除课堂记录
             else if (data.TryGetProperty("delete_id", out JsonElement _delete_id) && !string.IsNullOrEmpty($"{_delete_id}")
             else if (data.TryGetProperty("delete_id", out JsonElement _delete_id) && !string.IsNullOrEmpty($"{_delete_id}")
                 && data.TryGetProperty("tmdid", out JsonElement _dtmdid) && !string.IsNullOrEmpty($"{_dtmdid}")
                 && data.TryGetProperty("tmdid", out JsonElement _dtmdid) && !string.IsNullOrEmpty($"{_dtmdid}")
@@ -835,12 +847,13 @@ namespace TEAMModelFunction
                 }
                 }
                 else { return; }
                 else { return; }
             }
             }
-            else {
+            else
+            {
                 return;
                 return;
             }
             }
-           
+
             var client = _azureCosmos.GetCosmosClient();
             var client = _azureCosmos.GetCosmosClient();
-            
+
             if ($"{scope}".Equals("school") && !string.IsNullOrEmpty($"{school}"))
             if ($"{scope}".Equals("school") && !string.IsNullOrEmpty($"{school}"))
             {
             {
                 blobname = $"{school}";
                 blobname = $"{school}";
@@ -862,18 +875,21 @@ namespace TEAMModelFunction
             try
             try
             {
             {
                 LessonRecord oldlessonRecord = null;
                 LessonRecord oldlessonRecord = null;
-                LessonRecord lessonRecord  = null;
+                LessonRecord lessonRecord = null;
                 Azure.Response response = await client.GetContainer(Constant.TEAMModelOS, tbname).ReadItemStreamAsync(lessonId, new PartitionKey(code));
                 Azure.Response response = await client.GetContainer(Constant.TEAMModelOS, tbname).ReadItemStreamAsync(lessonId, new PartitionKey(code));
-                if (response.Status == 200) {
+                if (response.Status == 200)
+                {
                     var doc = JsonDocument.Parse(response.ContentStream);
                     var doc = JsonDocument.Parse(response.ContentStream);
-                    lessonRecord= doc.RootElement.ToObject<LessonRecord>();
+                    lessonRecord = doc.RootElement.ToObject<LessonRecord>();
                     oldlessonRecord = doc.RootElement.ToObject<LessonRecord>();
                     oldlessonRecord = doc.RootElement.ToObject<LessonRecord>();
                 }
                 }
-                else {
+                else
+                {
                     lessonRecord = null;
                     lessonRecord = null;
                 }
                 }
-                
-                if (updates.IsNotEmpty()) {
+
+                if (updates.IsNotEmpty())
+                {
                     foreach (LessonUpdate update in updates)
                     foreach (LessonUpdate update in updates)
                     {
                     {
                         switch (update.grant_type)
                         switch (update.grant_type)
@@ -927,7 +943,8 @@ namespace TEAMModelFunction
                                     await client.GetContainer(Constant.TEAMModelOS, tbname).DeleteItemAsync<LessonRecord>(lessonId, new PartitionKey(code));
                                     await client.GetContainer(Constant.TEAMModelOS, tbname).DeleteItemAsync<LessonRecord>(lessonId, new PartitionKey(code));
                                     msgs.Add(update);
                                     msgs.Add(update);
                                 }
                                 }
-                                catch (CosmosException ex) {
+                                catch (CosmosException ex)
+                                {
                                     msgs.Add(update);
                                     msgs.Add(update);
                                 }
                                 }
                                 lessonRecord = null;
                                 lessonRecord = null;
@@ -1002,7 +1019,7 @@ namespace TEAMModelFunction
                     await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname).ReplaceItemAsync<LessonRecord>(lessonRecord, lessonId, new PartitionKey(code));
                     await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname).ReplaceItemAsync<LessonRecord>(lessonRecord, lessonId, new PartitionKey(code));
                     //计算课堂更新前后的差值
                     //计算课堂更新前后的差值
                     lessonDis = LessonService.DisLessonCount(oldlessonRecord, lessonRecord, lessonDis);
                     lessonDis = LessonService.DisLessonCount(oldlessonRecord, lessonRecord, lessonDis);
-                    await LessonService.FixLessonCount(client, _dingDing, lessonRecord, lessonDis);
+                    await LessonService.FixLessonCount(client, _dingDing, lessonRecord, oldlessonRecord, lessonDis);
                 }
                 }
             }
             }
             catch (Exception ex)
             catch (Exception ex)

+ 1 - 1
TEAMModelOS.SDK/Models/Service/LessonService.cs

@@ -107,9 +107,9 @@ namespace TEAMModelOS.SDK.Models.Service
 
 
         public static async Task FixLessonCount(CosmosClient client, DingDing _dingDing, LessonRecord record, LessonRecord oldRecord, LessonDis lessonDis)
         public static async Task FixLessonCount(CosmosClient client, DingDing _dingDing, LessonRecord record, LessonRecord oldRecord, LessonDis lessonDis)
         {
         {
+            LessonRecord data = null;
             try
             try
             {
             {
-                LessonRecord data = null;
                 if (record != null && oldRecord == null) {
                 if (record != null && oldRecord == null) {
                     data = record;
                     data = record;
                 }
                 }