|
@@ -3263,75 +3263,84 @@ namespace TEAMModelOS.Function
|
|
|
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;
|
|
|
+ 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();
|
|
|
+ _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;
|
|
|
|
|
|
- string location = Environment.GetEnvironmentVariable("Option:Location");
|
|
|
- var client = _azureCosmos.GetCosmosClient();
|
|
|
- string lang = (location.Contains("China")) ? "zh-cn" : "zh-tw";
|
|
|
+ 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();
|
|
|
|
|
|
- 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)
|
|
|
+ string location = Environment.GetEnvironmentVariable("Option:Location");
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
+ 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}' ");
|
|
|
+ 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") }))
|
|
|
{
|
|
|
- foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
+ using var json = await JsonDocument.ParseAsync(jc.Content);
|
|
|
+ if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
{
|
|
|
- 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))
|
|
|
+ foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
{
|
|
|
- mailUsers.Add(user);
|
|
|
+ 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)
|
|
|
- {
|
|
|
- //熱身賽開始 Mail發送
|
|
|
- foreach (dynamic user in mailUsers)
|
|
|
+ await _dingDing.SendBotMsg($"統測活動訊息寄送 type:{type} 寄送人數:{mailUsers.Count}", GroupNames.研發C組);
|
|
|
+ //寄發Email
|
|
|
+ if (mailUsers.Count > 0)
|
|
|
{
|
|
|
- if (!string.IsNullOrWhiteSpace(tid)) //※無模板ID不發
|
|
|
+ //熱身賽開始 Mail發送
|
|
|
+ foreach (dynamic user in mailUsers)
|
|
|
{
|
|
|
- await _coreAPIHttpService.SendMail(new Dictionary<string, object> { { "to", user.email }, { "tid", tid }, { "vars", new { name = user.name } } }, location, _configuration);
|
|
|
+ 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($"統測活動訊息寄送錯誤: {ex.Message}", GroupNames.研發C組);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private async Task RefreshBlob(string name, string u)
|