|
@@ -2997,6 +2997,10 @@ namespace TEAMModelOS.Function
|
|
|
_logger.LogInformation("Message Body: {body}", message.Body);
|
|
|
_logger.LogInformation("Message Content-Type: {contentType}", message.ContentType);
|
|
|
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
|
|
|
{
|
|
|
//多國語字典
|
|
@@ -3013,26 +3017,16 @@ namespace TEAMModelOS.Function
|
|
|
// 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;
|
|
|
string code = "JointEvent";
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
|
-
|
|
|
JointEvent jointEvent = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<JointEvent>(jointEventId.ToString(), new PartitionKey($"{code}"));
|
|
|
if (jointEvent != null)
|
|
|
{
|
|
|
JointEvent.JointEventSchedule jointEventSchedule = jointEvent.schedule.Where(s => s.id.Equals($"{jointScheduleId}")).FirstOrDefault();
|
|
|
if (jointEventSchedule != null)
|
|
|
{
|
|
|
- //資料處理
|
|
|
+ //DB資料處理
|
|
|
if (!jointEventSchedule.progress.Equals($"{progress}"))
|
|
|
{
|
|
|
jointEventSchedule.progress = $"{progress}";
|
|
@@ -3046,20 +3040,21 @@ namespace TEAMModelOS.Function
|
|
|
switch (jointEventSchedule.progress)
|
|
|
{
|
|
|
case "pending":
|
|
|
+ //going訊息寄送
|
|
|
var msg = new ServiceBusMessage(new { jointEventId = $"{jointEventId}", jointScheduleId = $"{jointScheduleId}", progress = "going" }.ToJsonString());
|
|
|
msg.ApplicationProperties.Add("name", "JointEventSchedule");
|
|
|
- if (records.Count > 0)
|
|
|
+ string PartitionKeyGo = string.Format("{0}{1}{2}{3}{4}{5}{6}", "JointEvent", "-", $"{jointEventId}", "-", "schedule", "-", "going");
|
|
|
+ List<ChangeRecord> recordsGo = await table.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", $"{jointScheduleId}" }, { "PartitionKey", PartitionKeyGo } });
|
|
|
+ if (recordsGo.Count > 0)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
- await _serviceBus.GetServiceBusClient().CancelMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), records[0].sequenceNumber);
|
|
|
- }
|
|
|
- catch (Exception)
|
|
|
- {
|
|
|
+ await _serviceBus.GetServiceBusClient().CancelMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), recordsGo[0].sequenceNumber);
|
|
|
}
|
|
|
+ catch (ServiceBusException e) { }
|
|
|
long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), msg, DateTimeOffset.FromUnixTimeMilliseconds(jointEventSchedule.startTime));
|
|
|
- records[0].sequenceNumber = start;
|
|
|
- await table.SaveOrUpdate<ChangeRecord>(records[0]);
|
|
|
+ recordsGo[0].sequenceNumber = start;
|
|
|
+ await table.SaveOrUpdate<ChangeRecord>(recordsGo[0]);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -3067,7 +3062,7 @@ namespace TEAMModelOS.Function
|
|
|
ChangeRecord changeRecord = new ChangeRecord
|
|
|
{
|
|
|
RowKey = jointEventSchedule.id,
|
|
|
- PartitionKey = PartitionKey,
|
|
|
+ PartitionKey = PartitionKeyGo,
|
|
|
sequenceNumber = start,
|
|
|
msgId = message.MessageId
|
|
|
};
|
|
@@ -3075,18 +3070,23 @@ namespace TEAMModelOS.Function
|
|
|
}
|
|
|
break;
|
|
|
case "going":
|
|
|
- //刪除pending訊息
|
|
|
+ //pending訊息紀錄刪除
|
|
|
string pkey = string.Format("{0}{1}{2}{3}{4}{5}{6}", "JointEvent", "-", $"{jointEventId}", "-", "schedule", "-", "pending");
|
|
|
await table.DeleteSingle<ChangeRecord>(pkey, jointEventSchedule.id);
|
|
|
//發送finish訊息
|
|
|
var messageEnd = new ServiceBusMessage(new { jointEventId = $"{jointEventId}", jointScheduleId = $"{jointScheduleId}", progress = "finish" }.ToJsonString());
|
|
|
messageEnd.ApplicationProperties.Add("name", "JointEventSchedule");
|
|
|
- if (records.Count > 0)
|
|
|
+ string PartitionKeyEnd = string.Format("{0}{1}{2}{3}{4}{5}{6}", "JointEvent", "-", $"{jointEventId}", "-", "schedule", "-", "finish");
|
|
|
+ List<ChangeRecord> recordsEnd = await table.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", $"{jointScheduleId}" }, { "PartitionKey", PartitionKeyEnd } });
|
|
|
+ if (recordsEnd.Count > 0)
|
|
|
{
|
|
|
long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageEnd, DateTimeOffset.FromUnixTimeMilliseconds(jointEventSchedule.endTime));
|
|
|
- await _serviceBus.GetServiceBusClient().CancelMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), records[0].sequenceNumber);
|
|
|
- records[0].sequenceNumber = end;
|
|
|
- await table.SaveOrUpdate<ChangeRecord>(records[0]);
|
|
|
+ try {
|
|
|
+ await _serviceBus.GetServiceBusClient().CancelMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), recordsEnd[0].sequenceNumber);
|
|
|
+ }
|
|
|
+ catch (ServiceBusException e) { }
|
|
|
+ recordsEnd[0].sequenceNumber = end;
|
|
|
+ await table.SaveOrUpdate<ChangeRecord>(recordsEnd[0]);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -3094,85 +3094,156 @@ namespace TEAMModelOS.Function
|
|
|
ChangeRecord changeRecord = new ChangeRecord
|
|
|
{
|
|
|
RowKey = jointEventSchedule.id,
|
|
|
- PartitionKey = PartitionKey,
|
|
|
+ PartitionKey = PartitionKeyEnd,
|
|
|
sequenceNumber = end,
|
|
|
msgId = messageEnd.MessageId
|
|
|
};
|
|
|
await table.Save<ChangeRecord>(changeRecord);
|
|
|
}
|
|
|
//寄發Email
|
|
|
- ///取得收信者Email ※ jointCourse.creatorEmail
|
|
|
- //List<dynamic> users = new List<dynamic>();
|
|
|
- //if (jointEventSchedule.type.Equals("exam"))
|
|
|
- //{
|
|
|
- // //一般競賽 ※決賽 名單架構確定後再取
|
|
|
- // if (jointEventSchedule.examType.Equals("regular"))
|
|
|
- // {
|
|
|
- // await foreach (var jc in client.GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetItemQueryStreamIteratorSql(queryText: $"SELECT DISTINCT c.creatorId, c.creatorName, c.creatorEmail FROM c WHERE c.jointEventId = '{jointEvent.id}' ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"JointCourse") }))
|
|
|
- // {
|
|
|
- // using var json = await JsonDocument.ParseAsync(jc.Content);
|
|
|
- // if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
- // {
|
|
|
- // foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
- // {
|
|
|
- // EmailUser user = new EmailUser();
|
|
|
- // user.tmid = (obj.TryGetProperty("creatorId", out JsonElement _creatorId)) ? _creatorId.GetString() : string.Empty;
|
|
|
- // user.name = (obj.TryGetProperty("creatorName", out JsonElement _creatorName)) ? _creatorName.GetString() : string.Empty;
|
|
|
- // user.email = (obj.TryGetProperty("creatorEmail", out JsonElement _creatorEmail)) ? _creatorEmail.GetString() : string.Empty;
|
|
|
- // if (!string.IsNullOrWhiteSpace(user.tmid) && !string.IsNullOrWhiteSpace(user.email))
|
|
|
- // {
|
|
|
- // users.Add(user);
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
- //}
|
|
|
- //if (users.Count > 0)
|
|
|
- //{
|
|
|
- // //取得模板ID ※國際站就用繁體,大陸站就用簡體 [待定]
|
|
|
- // string location = Environment.GetEnvironmentVariable("Option:Location");
|
|
|
- // //string tid = (location.Contains("China")) ? "" : "d-833d40ac6397414b852b91e2fa45850a";
|
|
|
- // string tid = string.Empty;
|
|
|
- // string lang = (location.Contains("China")) ? "zh-cn" : "zh-tw";
|
|
|
- // //取得通知內文
|
|
|
- // string mailTitle = string.Empty;
|
|
|
- // string mailBody = string.Empty;
|
|
|
- // JObject jsonObject = langDic[lang];
|
|
|
- // if (jsonObject.TryGetValue("joint-schedule-start", out JToken msgToken))
|
|
|
- // {
|
|
|
- // JArray msgArray = (JArray)msgToken;
|
|
|
- // mailTitle = msgArray[0].ToString();
|
|
|
- // mailBody = $"{msgArray[1].ToString()}";
|
|
|
- // }
|
|
|
- // foreach (dynamic user in users)
|
|
|
- // {
|
|
|
- // if (!string.IsNullOrWhiteSpace(tid)) //※大陸站無模板,暫時不發
|
|
|
- // {
|
|
|
- // mailBody = mailBody.Replace("{tmdname}", user.name).Replace("{event}", jointEventSchedule.name);
|
|
|
- // await _coreAPIHttpService.SendMail(new Dictionary<string, object> { { "to", user.email }, { "tid", tid }, { "vars", new { name = user.name } } }, location, _configuration);
|
|
|
- // }
|
|
|
- // }
|
|
|
- //}
|
|
|
- break;
|
|
|
- case "finish":
|
|
|
- string pk = string.Format("{0}{1}{2}{3}{4}{5}{6}", "JointEvent", "-", $"{jointEventId}", "-", "schedule", "-", "going");
|
|
|
- await table.DeleteSingle<ChangeRecord>(pk, jointEventSchedule.id);
|
|
|
- //寄發Email [待模板ID]
|
|
|
- //熱身賽行程結束、決賽名單計算
|
|
|
- if(jointEventSchedule.type.Equals("exam") && jointEventSchedule.examType.Equals("regular"))
|
|
|
+ if(jointEventSchedule.type.Equals("exam"))
|
|
|
{
|
|
|
- string scope = "private"; //先寫死為個人
|
|
|
- List<string> jointGroupIds = jointEvent.groups.Select(g => g.id).ToList();
|
|
|
- if (jointGroupIds.Count > 0)
|
|
|
+ string type = string.Empty;
|
|
|
+ string tablePartitionKey = string.Empty;
|
|
|
+ string tableRowKey = string.Empty;
|
|
|
+ long emitTime = 0;
|
|
|
+ //熱身賽
|
|
|
+ if (jointEventSchedule.examType.Equals("regular"))
|
|
|
{
|
|
|
- foreach (string jointGroupId in jointGroupIds)
|
|
|
+ //熱身賽開始
|
|
|
+ type = "regularExamStart";
|
|
|
+ emitTime = jointEventSchedule.startTime;
|
|
|
+ var messageRegularSt = new ServiceBusMessage(new { jointEventId = $"{jointEventId}", jointScheduleId = $"{jointEventSchedule.id}", type = type, time = emitTime }.ToJsonString());
|
|
|
+ messageRegularSt.ApplicationProperties.Add("name", "JointMessage");
|
|
|
+ tablePartitionKey = string.Format("{0}{1}{2}{3}{4}", "JointMessage", "-", $"{jointEventId}", "-", $"{type}"); //主key: JointMessage-{jointEventId}-{type} RowKey: {jointScheduleId}
|
|
|
+ tableRowKey = $"{jointEventSchedule.id}";
|
|
|
+ List<ChangeRecord> recordRegularSt = await table.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", tableRowKey }, { "PartitionKey", tablePartitionKey } });
|
|
|
+ if (recordRegularSt.Count > 0)
|
|
|
+ {
|
|
|
+ long sr = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageRegularSt, DateTimeOffset.FromUnixTimeMilliseconds(emitTime));
|
|
|
+ await _serviceBus.GetServiceBusClient().CancelMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), recordRegularSt[0].sequenceNumber);
|
|
|
+ recordRegularSt[0].sequenceNumber = sr;
|
|
|
+ await table.SaveOrUpdate<ChangeRecord>(recordRegularSt[0]);
|
|
|
+ }
|
|
|
+ else
|
|
|
{
|
|
|
- List<JointEventGroupDb> addResult = await JointService.CreatePassJointCourseBySchedule(client, $"{jointEventId}", jointGroupId, jointEventSchedule.id, scope);
|
|
|
+ long sr = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageRegularSt, DateTimeOffset.FromUnixTimeMilliseconds(emitTime));
|
|
|
+ ChangeRecord changeRecord = new ChangeRecord
|
|
|
+ {
|
|
|
+ RowKey = tableRowKey,
|
|
|
+ PartitionKey = tablePartitionKey,
|
|
|
+ sequenceNumber = sr,
|
|
|
+ msgId = messageRegularSt.MessageId
|
|
|
+ };
|
|
|
+ await table.Save<ChangeRecord>(changeRecord);
|
|
|
+ }
|
|
|
+ //熱身賽即將結束
|
|
|
+ type = "regularExamEndSoon";
|
|
|
+ DateTimeOffset dateTimeEnd = DateTimeOffset.FromUnixTimeMilliseconds(jointEventSchedule.endTime);
|
|
|
+ dateTimeEnd = dateTimeEnd.AddDays(-1);
|
|
|
+ DateTimeOffset emitTimeOffset = new DateTimeOffset(dateTimeEnd.Year, dateTimeEnd.Month, dateTimeEnd.Day, 0, 0, 0, DateTimeOffset.UtcNow.Offset);
|
|
|
+ emitTime = emitTimeOffset.ToUnixTimeMilliseconds();
|
|
|
+ var messageRegularSo = new ServiceBusMessage(new { jointEventId = $"{jointEventId}", jointScheduleId = $"{jointEventSchedule.id}", type = type, time = emitTime }.ToJsonString());
|
|
|
+ messageRegularSo.ApplicationProperties.Add("name", "JointMessage");
|
|
|
+ tablePartitionKey = string.Format("{0}{1}{2}{3}{4}", "JointMessage", "-", $"{jointEventId}", "-", $"{type}"); //主key: JointMessage-{jointEventId}-{type} RowKey: {jointScheduleId}
|
|
|
+ tableRowKey = $"{jointEventSchedule.id}";
|
|
|
+ List<ChangeRecord> recordRegularSo = await table.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", tableRowKey }, { "PartitionKey", tablePartitionKey } });
|
|
|
+ if (recordRegularSo.Count > 0)
|
|
|
+ {
|
|
|
+ long sr = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageRegularSo, DateTimeOffset.FromUnixTimeMilliseconds(emitTime));
|
|
|
+ try
|
|
|
+ {
|
|
|
+ await _serviceBus.GetServiceBusClient().CancelMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), recordRegularSo[0].sequenceNumber);
|
|
|
+ }
|
|
|
+ catch (ServiceBusException e) { }
|
|
|
+ recordRegularSo[0].sequenceNumber = sr;
|
|
|
+ await table.SaveOrUpdate<ChangeRecord>(recordRegularSo[0]);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ long sr = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageRegularSo, DateTimeOffset.FromUnixTimeMilliseconds(emitTime));
|
|
|
+ ChangeRecord changeRecord = new ChangeRecord
|
|
|
+ {
|
|
|
+ RowKey = tableRowKey,
|
|
|
+ PartitionKey = tablePartitionKey,
|
|
|
+ sequenceNumber = sr,
|
|
|
+ msgId = messageRegularSt.MessageId
|
|
|
+ };
|
|
|
+ await table.Save<ChangeRecord>(changeRecord);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //決賽
|
|
|
+ else if(jointEventSchedule.examType.Equals("custom"))
|
|
|
+ {
|
|
|
+ //決賽開始
|
|
|
+ type = "customExamStart";
|
|
|
+ emitTime = jointEventSchedule.startTime;
|
|
|
+ var messageCustomSt = new ServiceBusMessage(new { jointEventId = $"{jointEventId}", jointScheduleId = $"{jointEventSchedule.id}", type = type, time = emitTime }.ToJsonString());
|
|
|
+ messageCustomSt.ApplicationProperties.Add("name", "JointMessage");
|
|
|
+ tablePartitionKey = string.Format("{0}{1}{2}{3}{4}", "JointMessage", "-", $"{jointEventId}", "-", $"{type}"); //主key: JointMessage-{jointEventId}-{type} RowKey: {jointScheduleId}
|
|
|
+ tableRowKey = $"{jointEventSchedule.id}";
|
|
|
+ List<ChangeRecord> recordCustomSt = await table.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", tableRowKey }, { "PartitionKey", tablePartitionKey } });
|
|
|
+ if (recordCustomSt.Count > 0)
|
|
|
+ {
|
|
|
+ long sr = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageCustomSt, DateTimeOffset.FromUnixTimeMilliseconds(emitTime));
|
|
|
+ try
|
|
|
+ {
|
|
|
+ await _serviceBus.GetServiceBusClient().CancelMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), recordCustomSt[0].sequenceNumber);
|
|
|
+ }
|
|
|
+ catch (ServiceBusException e) { }
|
|
|
+ recordCustomSt[0].sequenceNumber = sr;
|
|
|
+ await table.SaveOrUpdate<ChangeRecord>(recordCustomSt[0]);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ long sr = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageCustomSt, DateTimeOffset.FromUnixTimeMilliseconds(emitTime));
|
|
|
+ ChangeRecord changeRecord = new ChangeRecord
|
|
|
+ {
|
|
|
+ RowKey = tableRowKey,
|
|
|
+ PartitionKey = tablePartitionKey,
|
|
|
+ sequenceNumber = sr,
|
|
|
+ msgId = messageCustomSt.MessageId
|
|
|
+ };
|
|
|
+ await table.Save<ChangeRecord>(changeRecord);
|
|
|
+ }
|
|
|
+ //決賽即將結束
|
|
|
+ type = "customExamEndSoon";
|
|
|
+ DateTimeOffset dateTimeEnd = DateTimeOffset.FromUnixTimeMilliseconds(jointEventSchedule.endTime);
|
|
|
+ dateTimeEnd = dateTimeEnd.AddDays(-1);
|
|
|
+ DateTimeOffset emitTimeOffset = new DateTimeOffset(dateTimeEnd.Year, dateTimeEnd.Month, dateTimeEnd.Day, 0, 0, 0, DateTimeOffset.UtcNow.Offset);
|
|
|
+ emitTime = emitTimeOffset.ToUnixTimeMilliseconds();
|
|
|
+ var messageCustomSo = new ServiceBusMessage(new { jointEventId = $"{jointEventId}", jointScheduleId = $"{jointEventSchedule.id}", type = type, time = emitTime }.ToJsonString());
|
|
|
+ messageCustomSo.ApplicationProperties.Add("name", "JointMessage");
|
|
|
+ tablePartitionKey = string.Format("{0}{1}{2}{3}{4}", "JointMessage", "-", $"{jointEventId}", "-", $"{type}"); //主key: JointMessage-{jointEventId}-{type} RowKey: {jointScheduleId}
|
|
|
+ tableRowKey = $"{jointEventSchedule.id}";
|
|
|
+ List<ChangeRecord> recordCustomSo = await table.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", tableRowKey }, { "PartitionKey", tablePartitionKey } });
|
|
|
+ if (recordCustomSo.Count > 0)
|
|
|
+ {
|
|
|
+ long sr = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageCustomSo, DateTimeOffset.FromUnixTimeMilliseconds(emitTime));
|
|
|
+ try
|
|
|
+ {
|
|
|
+ await _serviceBus.GetServiceBusClient().CancelMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), recordCustomSo[0].sequenceNumber);
|
|
|
+ }
|
|
|
+ catch (ServiceBusException e) { }
|
|
|
+ recordCustomSo[0].sequenceNumber = sr;
|
|
|
+ await table.SaveOrUpdate<ChangeRecord>(recordCustomSo[0]);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ long sr = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageCustomSo, DateTimeOffset.FromUnixTimeMilliseconds(emitTime));
|
|
|
+ ChangeRecord changeRecord = new ChangeRecord
|
|
|
+ {
|
|
|
+ RowKey = tableRowKey,
|
|
|
+ PartitionKey = tablePartitionKey,
|
|
|
+ sequenceNumber = sr,
|
|
|
+ msgId = messageCustomSo.MessageId
|
|
|
+ };
|
|
|
+ await table.Save<ChangeRecord>(changeRecord);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ break;
|
|
|
+ case "finish":
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
@@ -3187,12 +3258,116 @@ namespace TEAMModelOS.Function
|
|
|
await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,JointEventScheduleBus()\n{ex.Message}\n{ex.StackTrace}\n\n{jsonMsg.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
|
|
|
}
|
|
|
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);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 統測活動訊息寄送
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="message"></param>
|
|
|
+ /// <param name="messageActions"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [Function("JointEventSendMessage")]
|
|
|
+ public async Task JointEventSendMessageFunc(
|
|
|
+ [ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "jointmessage", Connection = "Azure:ServiceBus:ConnectionString")]
|
|
|
+ ServiceBusReceivedMessage message,
|
|
|
+ ServiceBusMessageActions messageActions,
|
|
|
+ ExecutionContext context)
|
|
|
+ {
|
|
|
+ _logger.LogInformation("Message ID: {id}", message.MessageId);
|
|
|
+ _logger.LogInformation("Message Body: {body}", message.Body);
|
|
|
+ _logger.LogInformation("Message Content-Type: {contentType}", message.ContentType);
|
|
|
+ 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
|
|
|
+ {
|
|
|
+ StringBuilder sqlStr = new StringBuilder($"SELECT DISTINCT c.creatorId, c.creatorName, c.creatorEmail FROM c WHERE c.jointEventId = '{jointEventId}' ");
|
|
|
+ string tid = string.Empty;
|
|
|
+ switch (type.ToString())
|
|
|
+ {
|
|
|
+ //熱身賽開始
|
|
|
+ case "regularExamStart":
|
|
|
+ sqlStr.Append($" AND c.type = 'regular' ");
|
|
|
+ tid = (location.Contains("China")) ? "" : "d-ba5d29036f81460c841fadaac7d35b6b"; //熱身賽開始
|
|
|
+ break;
|
|
|
+ //熱身賽即將結束
|
|
|
+ case "regularExamEndSoon":
|
|
|
+ sqlStr.Append($" AND c.type = 'regular' ");
|
|
|
+ tid = (location.Contains("China")) ? "" : "d-359ec5e40e244aceb4d04f42e52af29d"; //熱身賽即將結束
|
|
|
+ break;
|
|
|
+ //決賽開始
|
|
|
+ case "customExamStart":
|
|
|
+ sqlStr.Append($" AND c.type = 'custom' ");
|
|
|
+ break;
|
|
|
+ //決賽即將結束
|
|
|
+ case "customExamEndSoon":
|
|
|
+ sqlStr.Append($" AND c.type = 'custom' ");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ //取得收信者
|
|
|
+ List<dynamic> mailUsers = new List<dynamic>();
|
|
|
+ await foreach (var jc in client.GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetItemQueryStreamIteratorSql(queryText: sqlStr.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"JointCourse") }))
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(jc.Content);
|
|
|
+ if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
+ {
|
|
|
+ foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
+ {
|
|
|
+ EmailUser user = new EmailUser();
|
|
|
+ user.tmid = (obj.TryGetProperty("creatorId", out JsonElement _creatorId)) ? _creatorId.GetString() : string.Empty;
|
|
|
+ user.name = (obj.TryGetProperty("creatorName", out JsonElement _creatorName)) ? _creatorName.GetString() : string.Empty;
|
|
|
+ user.email = (obj.TryGetProperty("creatorEmail", out JsonElement _creatorEmail)) ? _creatorEmail.GetString() : string.Empty;
|
|
|
+ if (!string.IsNullOrWhiteSpace(user.tmid) && !string.IsNullOrWhiteSpace(user.email))
|
|
|
+ {
|
|
|
+ mailUsers.Add(user);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //寄發Email
|
|
|
+ if (mailUsers.Count > 0)
|
|
|
+ {
|
|
|
+ if(location.Contains("-Test")) await _dingDing.SendBotMsg($"寄送活動Email type:{type.ToString()} 寄送人數:{mailUsers.Count}人", GroupNames.研發C組);
|
|
|
+
|
|
|
+ //熱身賽開始 Mail發送
|
|
|
+ foreach (dynamic user in mailUsers)
|
|
|
+ {
|
|
|
+ if (!string.IsNullOrWhiteSpace(tid)) //※無模板ID不發
|
|
|
+ {
|
|
|
+ await _coreAPIHttpService.SendMail(new Dictionary<string, object> { { "to", user.email }, { "tid", tid }, { "vars", new { name = user.name } } }, location, _configuration);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")} 統測活動Email寄送錯誤:\n{ex.Message}\n{ex.StackTrace}\n\n{jsonMsg.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
|
|
|
+ }
|
|
|
+ finally
|
|
|
+ {
|
|
|
+ //自身訊息紀錄刪除
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private async Task RefreshBlob(string name, string u)
|
|
|
{
|
|
|
long statr = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|