|
@@ -1726,6 +1726,91 @@ namespace TEAMModelOS.Controllers.Common
|
|
}
|
|
}
|
|
return Ok(new { errCode = "", err = "", result = result });
|
|
return Ok(new { errCode = "", err = "", result = result });
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// 手動寄發統測活動Email
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <param name="request"></param>
|
|
|
|
+ /// <returns></returns>
|
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
|
+ [Authorize(Roles = "IES")]
|
|
|
|
+#if !DEBUG
|
|
|
|
+ [AuthToken(Roles = "teacher")]
|
|
|
|
+#endif
|
|
|
|
+ [HttpPost("send-email")]
|
|
|
|
+ public async Task<IActionResult> JointEventSendMessage(JsonElement request)
|
|
|
|
+ {
|
|
|
|
+ string location = _option.Location;
|
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
|
+ long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
|
+ string jointEventId = (request.TryGetProperty("jointEventId", out JsonElement _jointEventId)) ? _jointEventId.ToString() : string.Empty;
|
|
|
|
+ if (string.IsNullOrWhiteSpace(jointEventId)) return BadRequest();
|
|
|
|
+ string scheduleId = (request.TryGetProperty("scheduleId", out JsonElement _scheduleId)) ? _scheduleId.ToString() : string.Empty;
|
|
|
|
+ if (string.IsNullOrWhiteSpace(scheduleId)) return BadRequest();
|
|
|
|
+ string tmid = (request.TryGetProperty("tmid", out JsonElement _tmid)) ? _tmid.ToString() : string.Empty;
|
|
|
|
+ string mode = (request.TryGetProperty("mode", out JsonElement _mode)) ? _mode.ToString() : string.Empty; //start:開始 end:結束
|
|
|
|
+ //取得活動本體
|
|
|
|
+ JointEvent jointEvent = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<JointEvent>(jointEventId, new PartitionKey("JointEvent"));
|
|
|
|
+ if (jointEvent == null)
|
|
|
|
+ {
|
|
|
|
+ return Ok(new { errCode = "3", err = "Invalid jointEventId." });
|
|
|
|
+ }
|
|
|
|
+ //取得活動Schedule
|
|
|
|
+ JointEventSchedule jointEventSchedule = jointEvent.schedule.Where(s => s.id.Equals(scheduleId)).FirstOrDefault();
|
|
|
|
+ if (jointEventSchedule == null)
|
|
|
|
+ {
|
|
|
|
+ return Ok(new { errCode = "5", err = "Invalid scheduleId." });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<dynamic> mailUsers = new List<dynamic>();
|
|
|
|
+ string tid = string.Empty; //模板ID
|
|
|
|
+ //決賽即將開始
|
|
|
|
+ if (jointEventSchedule.type.Equals("exam") && jointEventSchedule.examType.Equals("custom") && mode.Equals("start"))
|
|
|
|
+ {
|
|
|
|
+ tid = "d-c20f4e51c9f94ddcb7090238567c7a66";
|
|
|
|
+ StringBuilder sqlStr = new StringBuilder($"SELECT DISTINCT c.creatorId, c.creatorName, c.creatorEmail FROM c WHERE c.jointEventId = '{jointEventId}' ");
|
|
|
|
+ sqlStr.Append($" AND c.type = 'custom' ");
|
|
|
|
+ if(!string.IsNullOrWhiteSpace(tmid))
|
|
|
|
+ {
|
|
|
|
+ sqlStr.Append($" AND c.creatorId = '{tmid}' ");
|
|
|
|
+ }
|
|
|
|
+ //取得收信者
|
|
|
|
+ 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 寄送人數:{mailUsers.Count}人", GroupNames.研發C組);
|
|
|
|
+ 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);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return Ok(new { mailUsers });
|
|
|
|
+ }
|
|
|
|
+
|
|
public class JointExamIdCollector
|
|
public class JointExamIdCollector
|
|
{
|
|
{
|
|
public string jointEventId { get; set; }
|
|
public string jointEventId { get; set; }
|
|
@@ -1781,5 +1866,12 @@ namespace TEAMModelOS.Controllers.Common
|
|
public List<object> schedule { get; set; } = new List<object>(); //已完成的行程
|
|
public List<object> schedule { get; set; } = new List<object>(); //已完成的行程
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ private class EmailUser
|
|
|
|
+ {
|
|
|
|
+ public string tmid { get; set; }
|
|
|
|
+ public string name { get; set; }
|
|
|
|
+ public string email { get; set; }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|