瀏覽代碼

Merge branch 'TPE/develop' of http://163.228.141.122:3000/TEAMMODEL/TEAMModelOS into TPE/develop

jeff 8 月之前
父節點
當前提交
8f63e323b4
共有 1 個文件被更改,包括 25 次插入37 次删除
  1. 25 37
      TEAMModelOS.Function/IESServiceBusTrigger.cs

+ 25 - 37
TEAMModelOS.Function/IESServiceBusTrigger.cs

@@ -2998,6 +2998,10 @@ namespace TEAMModelOS.Function
             _logger.LogInformation("Message Body: {body}", message.Body);
             _logger.LogInformation("Message Body: {body}", message.Body);
             _logger.LogInformation("Message Content-Type: {contentType}", message.ContentType);
             _logger.LogInformation("Message Content-Type: {contentType}", message.ContentType);
             var jsonMsg = JsonDocument.Parse(message.Body).RootElement;
             var jsonMsg = JsonDocument.Parse(message.Body).RootElement;
+            jsonMsg.TryGetProperty("jointEventId", out JsonElement jointEventId);
+            jsonMsg.TryGetProperty("jointScheduleId", out JsonElement jointScheduleId);
+            jsonMsg.TryGetProperty("progress", out JsonElement progress);
+            var table = _azureStorage.GetCloudTableClient().GetTableReference("ChangeRecord");
             try
             try
             {
             {
                 //多國語字典
                 //多國語字典
@@ -3014,19 +3018,9 @@ namespace TEAMModelOS.Function
                 //        langDic.Add(langCode, jsonObject);
                 //        langDic.Add(langCode, jsonObject);
                 //    }
                 //    }
                 //}
                 //}
-
-                jsonMsg.TryGetProperty("jointEventId", out JsonElement jointEventId);
-                jsonMsg.TryGetProperty("jointScheduleId", out JsonElement jointScheduleId);
-                jsonMsg.TryGetProperty("progress", out JsonElement progress);
-
-                var table = _azureStorage.GetCloudTableClient().GetTableReference("ChangeRecord");
-                string PartitionKey = string.Format("{0}{1}{2}{3}{4}{5}{6}", "JointEvent", "-", $"{jointEventId}", "-", "schedule", "-", $"{progress}"); //主key: JointEvent-{jointEventId}-schedule-{progress}  RowKey: {jointScheduleId}
-                List<ChangeRecord> records = await table.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", $"{jointScheduleId}" }, { "PartitionKey", PartitionKey } });
-                
                 bool updFlg = false;
                 bool updFlg = false;
                 string code = "JointEvent";
                 string code = "JointEvent";
                 var client = _azureCosmos.GetCosmosClient();
                 var client = _azureCosmos.GetCosmosClient();
-
                 JointEvent jointEvent = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<JointEvent>(jointEventId.ToString(), new PartitionKey($"{code}"));
                 JointEvent jointEvent = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<JointEvent>(jointEventId.ToString(), new PartitionKey($"{code}"));
                 if (jointEvent != null)
                 if (jointEvent != null)
                 {
                 {
@@ -3047,8 +3041,6 @@ namespace TEAMModelOS.Function
                         switch (jointEventSchedule.progress)
                         switch (jointEventSchedule.progress)
                         {
                         {
                             case "pending":
                             case "pending":
-                                //pending訊息紀錄刪除
-                                if (records.Count > 0) await table.DeleteSingle<ChangeRecord>(PartitionKey, jointEventSchedule.id);
                                 //going訊息寄送
                                 //going訊息寄送
                                 var msg = new ServiceBusMessage(new { jointEventId = $"{jointEventId}", jointScheduleId = $"{jointScheduleId}", progress = "going" }.ToJsonString());
                                 var msg = new ServiceBusMessage(new { jointEventId = $"{jointEventId}", jointScheduleId = $"{jointScheduleId}", progress = "going" }.ToJsonString());
                                 msg.ApplicationProperties.Add("name", "JointEventSchedule");
                                 msg.ApplicationProperties.Add("name", "JointEventSchedule");
@@ -3079,8 +3071,6 @@ namespace TEAMModelOS.Function
                                 }
                                 }
                                 break;
                                 break;
                             case "going":
                             case "going":
-                                //going訊息紀錄刪除
-                                if (records.Count > 0) await table.DeleteSingle<ChangeRecord>(PartitionKey, jointEventSchedule.id);
                                 //pending訊息紀錄刪除
                                 //pending訊息紀錄刪除
                                 string pkey = string.Format("{0}{1}{2}{3}{4}{5}{6}", "JointEvent", "-", $"{jointEventId}", "-", "schedule", "-", "pending");
                                 string pkey = string.Format("{0}{1}{2}{3}{4}{5}{6}", "JointEvent", "-", $"{jointEventId}", "-", "schedule", "-", "pending");
                                 await table.DeleteSingle<ChangeRecord>(pkey, jointEventSchedule.id);
                                 await table.DeleteSingle<ChangeRecord>(pkey, jointEventSchedule.id);
@@ -3093,11 +3083,11 @@ namespace TEAMModelOS.Function
                                 {
                                 {
                                     long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageEnd, DateTimeOffset.FromUnixTimeMilliseconds(jointEventSchedule.endTime));
                                     long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageEnd, DateTimeOffset.FromUnixTimeMilliseconds(jointEventSchedule.endTime));
                                     try { 
                                     try { 
-                                        await _serviceBus.GetServiceBusClient().CancelMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), records[0].sequenceNumber);
+                                        await _serviceBus.GetServiceBusClient().CancelMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), recordsEnd[0].sequenceNumber);
                                     }
                                     }
                                     catch (ServiceBusException e) { }
                                     catch (ServiceBusException e) { }
                                     recordsEnd[0].sequenceNumber = end;
                                     recordsEnd[0].sequenceNumber = end;
-                                    await table.SaveOrUpdate<ChangeRecord>(records[0]);
+                                    await table.SaveOrUpdate<ChangeRecord>(recordsEnd[0]);
                                 }
                                 }
                                 else
                                 else
                                 {
                                 {
@@ -3255,9 +3245,6 @@ namespace TEAMModelOS.Function
                                 }
                                 }
                                 break;
                                 break;
                             case "finish":
                             case "finish":
-                                //刪除going訊息
-                                string pkeyEnd = string.Format("{0}{1}{2}{3}{4}{5}{6}", "JointEvent", "-", $"{jointEventId}", "-", "schedule", "-", "going");
-                                await table.DeleteSingle<ChangeRecord>(pkeyEnd, jointEventSchedule.id);
                                 break;
                                 break;
                         }
                         }
                     }
                     }
@@ -3269,11 +3256,14 @@ namespace TEAMModelOS.Function
             }
             }
             catch (Exception ex)
             catch (Exception ex)
             {
             {
-
                 await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,JointEventScheduleBus()\n{ex.Message}\n{ex.StackTrace}\n\n{jsonMsg.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
                 await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,JointEventScheduleBus()\n{ex.Message}\n{ex.StackTrace}\n\n{jsonMsg.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
             }
             }
             finally
             finally
-            {   // Complete the message
+            {
+                //自身訊息紀錄刪除
+                string PartitionKey = string.Format("{0}{1}{2}{3}{4}{5}{6}", "JointEvent", "-", $"{jointEventId}", "-", "schedule", "-", $"{progress}"); //主key: JointEvent-{jointEventId}-schedule-{progress}  RowKey: {jointScheduleId}
+                await table.DeleteSingle<ChangeRecord>(PartitionKey, $"{jointScheduleId}");
+                // Complete the message
                 await messageActions.CompleteMessageAsync(message);
                 await messageActions.CompleteMessageAsync(message);
             }
             }
 
 
@@ -3296,19 +3286,16 @@ namespace TEAMModelOS.Function
             _logger.LogInformation("Message Body: {body}", message.Body);
             _logger.LogInformation("Message Body: {body}", message.Body);
             _logger.LogInformation("Message Content-Type: {contentType}", message.ContentType);
             _logger.LogInformation("Message Content-Type: {contentType}", message.ContentType);
             var jsonMsg = JsonDocument.Parse(message.Body).RootElement;
             var jsonMsg = JsonDocument.Parse(message.Body).RootElement;
-
+            jsonMsg.TryGetProperty("jointEventId", out JsonElement jointEventId);
+            jsonMsg.TryGetProperty("jointScheduleId", out JsonElement jointScheduleId);
+            jsonMsg.TryGetProperty("type", out JsonElement type);
+            string location = Environment.GetEnvironmentVariable("Option:Location");
+            var client = _azureCosmos.GetCosmosClient();
+            var table = _azureStorage.GetCloudTableClient().GetTableReference("ChangeRecord");
+            string lang = (location.Contains("China")) ? "zh-cn" : "zh-tw";
+            long time = (jsonMsg.TryGetProperty("time", out JsonElement _time)) ? _time.GetInt64() : new DateTimeOffset(DateTime.UtcNow).ToUnixTimeMilliseconds();
             try
             try
             {
             {
-                jsonMsg.TryGetProperty("jointEventId", out JsonElement jointEventId);
-                jsonMsg.TryGetProperty("jointScheduleId", out JsonElement jointScheduleId);
-                jsonMsg.TryGetProperty("type", out JsonElement type);
-                long time = (jsonMsg.TryGetProperty("time", out JsonElement _time)) ? _time.GetInt64() : new DateTimeOffset(DateTime.UtcNow).ToUnixTimeMilliseconds();
-
-                string location = Environment.GetEnvironmentVariable("Option:Location");
-                var client = _azureCosmos.GetCosmosClient();
-                var table = _azureStorage.GetCloudTableClient().GetTableReference("ChangeRecord");
-                string lang = (location.Contains("China")) ? "zh-cn" : "zh-tw";
-
                 StringBuilder sqlStr = new StringBuilder($"SELECT DISTINCT c.creatorId, c.creatorName, c.creatorEmail FROM c WHERE c.jointEventId = '{jointEventId}' ");
                 StringBuilder sqlStr = new StringBuilder($"SELECT DISTINCT c.creatorId, c.creatorName, c.creatorEmail FROM c WHERE c.jointEventId = '{jointEventId}' ");
                 string tid = string.Empty;
                 string tid = string.Empty;
                 switch (type.ToString())
                 switch (type.ToString())
@@ -3366,17 +3353,18 @@ namespace TEAMModelOS.Function
                         }
                         }
                     }
                     }
                 }
                 }
-                //將寄送訊息刪除
-                string tablePartitionKey = string.Format("{0}{1}{2}{3}{4}", "JointMessage", "-", $"{jointEventId}", "-", $"{type}"); //主key: JointMessage-{jointEventId}-{type}  RowKey: {jointScheduleId}
-                string tableRowKey = $"{jointScheduleId}";
-                await table.DeleteSingle<ChangeRecord>(tablePartitionKey, tableRowKey);
             }
             }
             catch (Exception ex)
             catch (Exception ex)
             {
             {
                 await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")} 統測活動Email寄送錯誤:\n{ex.Message}\n{ex.StackTrace}\n\n{jsonMsg.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
                 await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")} 統測活動Email寄送錯誤:\n{ex.Message}\n{ex.StackTrace}\n\n{jsonMsg.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
             }
             }
             finally
             finally
-            {   // Complete the message
+            {
+                //自身訊息紀錄刪除
+                string tablePartitionKey = string.Format("{0}{1}{2}{3}{4}", "JointMessage", "-", $"{jointEventId}", "-", $"{type}"); //主key: JointMessage-{jointEventId}-{type}  RowKey: {jointScheduleId}
+                string tableRowKey = $"{jointScheduleId}";
+                await table.DeleteSingle<ChangeRecord>(tablePartitionKey, tableRowKey);
+                // Complete the message
                 await messageActions.CompleteMessageAsync(message);
                 await messageActions.CompleteMessageAsync(message);
             }
             }
         }
         }