|
@@ -39,6 +39,9 @@ using MathNet.Numerics.Distributions;
|
|
using System.Drawing.Drawing2D;
|
|
using System.Drawing.Drawing2D;
|
|
using Microsoft.Azure.Amqp.Framing;
|
|
using Microsoft.Azure.Amqp.Framing;
|
|
using TEAMModelOS.SDK.DI.IPIP;
|
|
using TEAMModelOS.SDK.DI.IPIP;
|
|
|
|
+using Azure;
|
|
|
|
+using Microsoft.AspNetCore.Http.HttpResults;
|
|
|
|
+using System.Net;
|
|
|
|
|
|
|
|
|
|
namespace TEAMModelBI.Controllers.BICommon
|
|
namespace TEAMModelBI.Controllers.BICommon
|
|
@@ -1238,8 +1241,16 @@ namespace TEAMModelBI.Controllers.BICommon
|
|
string data = (jsonElement.TryGetProperty("data", out JsonElement _data)) ? _data.ToString() : string.Empty; //額外資料
|
|
string data = (jsonElement.TryGetProperty("data", out JsonElement _data)) ? _data.ToString() : string.Empty; //額外資料
|
|
long send = (jsonElement.TryGetProperty("send", out JsonElement _send)) ? _send.GetInt64() : 0; //發送時間 0:立即發送
|
|
long send = (jsonElement.TryGetProperty("send", out JsonElement _send)) ? _send.GetInt64() : 0; //發送時間 0:立即發送
|
|
string template = (jsonElement.TryGetProperty("template", out JsonElement _template)) ? _template.ToString() : string.Empty; //模板ID
|
|
string template = (jsonElement.TryGetProperty("template", out JsonElement _template)) ? _template.ToString() : string.Empty; //模板ID
|
|
-
|
|
|
|
- if (target == null || string.IsNullOrWhiteSpace(type) || string.IsNullOrWhiteSpace(method) || string.IsNullOrWhiteSpace(title) || string.IsNullOrWhiteSpace(body) || string.IsNullOrWhiteSpace(sender)) return BadRequest();
|
|
|
|
|
|
+ //必須項檢驗
|
|
|
|
+ if (target == null || string.IsNullOrWhiteSpace(type) || string.IsNullOrWhiteSpace(method) || string.IsNullOrWhiteSpace(title) || string.IsNullOrWhiteSpace(body)) return BadRequest();
|
|
|
|
+ if(type.Equals("notify"))
|
|
|
|
+ {
|
|
|
|
+ if(string.IsNullOrWhiteSpace(sender)) return BadRequest();
|
|
|
|
+ }
|
|
|
|
+ else if(type.Equals("mail"))
|
|
|
|
+ {
|
|
|
|
+ if (string.IsNullOrWhiteSpace(subject)) return BadRequest();
|
|
|
|
+ }
|
|
string eventKey = "bi-gen-notify";
|
|
string eventKey = "bi-gen-notify";
|
|
string eventId = $"{eventKey}_{_snowflakeId.NextId()}";
|
|
string eventId = $"{eventKey}_{_snowflakeId.NextId()}";
|
|
string eventName = "BI send notification";
|
|
string eventName = "BI send notification";
|
|
@@ -1298,7 +1309,7 @@ namespace TEAMModelBI.Controllers.BICommon
|
|
tmids = tmids.Union(tmids_direct).ToList();
|
|
tmids = tmids.Union(tmids_direct).ToList();
|
|
tmids = tmids.Distinct().ToList(); //唯一化
|
|
tmids = tmids.Distinct().ToList(); //唯一化
|
|
#if DEBUG //測試模式時限制TMID帳號,正式站佈署時不生效
|
|
#if DEBUG //測試模式時限制TMID帳號,正式站佈署時不生效
|
|
- List<string> filterTmid = new List<string>() { "1522758684", "1595321354" };
|
|
|
|
|
|
+ List<string> filterTmid = new List<string>() { "1522758684" }; //"1522758684", "1595321354"
|
|
tmids = tmids.Intersect(filterTmid).ToList();
|
|
tmids = tmids.Intersect(filterTmid).ToList();
|
|
#endif
|
|
#endif
|
|
|
|
|
|
@@ -1336,7 +1347,7 @@ namespace TEAMModelBI.Controllers.BICommon
|
|
//寄送訊息DB記入
|
|
//寄送訊息DB記入
|
|
if(response.IsSuccessStatusCode)
|
|
if(response.IsSuccessStatusCode)
|
|
{
|
|
{
|
|
- BINotice bINotice = TransMsgRequestToBINotice("notify", method, subject, title, body, sender, hubName, target, tmIds, data);
|
|
|
|
|
|
+ BINotice bINotice = TransMsgRequestToBINotice(type, method, subject, title, body, sender, hubName, target, tmIds, data);
|
|
bINotice.id = Guid.NewGuid().ToString();
|
|
bINotice.id = Guid.NewGuid().ToString();
|
|
bINotice.createId = _tmdId;
|
|
bINotice.createId = _tmdId;
|
|
bINotice.sendTime = (send.Equals(0)) ? DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() : send; //先處理"及時寄送","定時寄送"待處理
|
|
bINotice.sendTime = (send.Equals(0)) ? DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() : send; //先處理"及時寄送","定時寄送"待處理
|
|
@@ -1354,30 +1365,58 @@ namespace TEAMModelBI.Controllers.BICommon
|
|
}
|
|
}
|
|
else if(type.Equals("mail")) //Email
|
|
else if(type.Equals("mail")) //Email
|
|
{
|
|
{
|
|
- string defaultTemplate = "d-f1c5abd8247f4be79ceaecdd327e9a68";
|
|
|
|
|
|
+ string defaultTemplate = "d-f1c5abd8247f4be79ceaecdd327e9a68"; //國際站預設模板 ※CN站還沒有
|
|
|
|
+ List<string> mailList = tmidInfos.Where(i => !string.IsNullOrWhiteSpace(i.mail)).Select(i => i.mail).ToList();
|
|
List<string> tmIds = tmidInfos.Where(i => !string.IsNullOrWhiteSpace(i.mail)).Select(i => i.id).ToList();
|
|
List<string> tmIds = tmidInfos.Where(i => !string.IsNullOrWhiteSpace(i.mail)).Select(i => i.id).ToList();
|
|
//呼叫Email API [未]
|
|
//呼叫Email API [未]
|
|
///模板設定
|
|
///模板設定
|
|
- if(_option.Location.Contains("Global"))
|
|
|
|
|
|
+ if (_option.Location.Contains("Global"))
|
|
{
|
|
{
|
|
if (string.IsNullOrWhiteSpace(template))
|
|
if (string.IsNullOrWhiteSpace(template))
|
|
template = defaultTemplate; //若未指定模板ID,用預設模板
|
|
template = defaultTemplate; //若未指定模板ID,用預設模板
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ if(string.IsNullOrWhiteSpace(template)) //無模板ID,就不執行
|
|
|
|
+ {
|
|
|
|
+ var result = new { status = HttpStatusCode.BadRequest };
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
//Email寄送
|
|
//Email寄送
|
|
- HttpResponseMessage response = CallPushNotifyApi(tmIds, title, body, sender, hubName, template, data, eventId, eventName);
|
|
|
|
- //寄送訊息DB記入
|
|
|
|
- if (response.IsSuccessStatusCode)
|
|
|
|
|
|
+ bool sendMail = false;
|
|
|
|
+ if (send.Equals(0)) //立即寄送
|
|
{
|
|
{
|
|
- BINotice bINotice = TransMsgRequestToBINotice("notify", method, subject, title, body, sender, hubName, target, tmIds, data);
|
|
|
|
- bINotice.id = Guid.NewGuid().ToString();
|
|
|
|
- bINotice.createId = _tmdId;
|
|
|
|
- bINotice.sendTime = (send.Equals(0)) ? DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() : send; //先處理"及時寄送","定時寄送"待處理
|
|
|
|
- await cosmosClientIes.GetContainer(Constant.TEAMModelOS, "Common").CreateItemAsync<BINotice>(bINotice, new PartitionKey("BINotice"));
|
|
|
|
|
|
+ List<string> imgArr = new List<string>();
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ JsonElement dataJobj = JsonSerializer.Deserialize<JsonElement>(data);
|
|
|
|
+ if(dataJobj.TryGetProperty("img", out JsonElement _img))
|
|
|
|
+ {
|
|
|
|
+ imgArr = _img.ToObject<List<string>>();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ catch (JsonException) { }
|
|
|
|
+ string image = (imgArr.Count > 0) ? imgArr[0] : string.Empty;
|
|
|
|
+ foreach(string email in mailList)
|
|
|
|
+ {
|
|
|
|
+ await CallSendMailApiAsync(email, subject, title, body, template, image);
|
|
|
|
+ sendMail = true;
|
|
|
|
+ }
|
|
|
|
+ //寄送訊息DB記入
|
|
|
|
+ if (sendMail)
|
|
|
|
+ {
|
|
|
|
+ BINotice bINotice = TransMsgRequestToBINotice(type, method, subject, title, body, sender, hubName, target, tmIds, data);
|
|
|
|
+ bINotice.id = Guid.NewGuid().ToString();
|
|
|
|
+ bINotice.createId = _tmdId;
|
|
|
|
+ bINotice.sendTime = (send.Equals(0)) ? DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() : send; //先處理"及時寄送","定時寄送"待處理
|
|
|
|
+ await cosmosClientIes.GetContainer(Constant.TEAMModelOS, "Common").CreateItemAsync<BINotice>(bINotice, new PartitionKey("BINotice"));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var result = new { status = HttpStatusCode.OK, content = string.Empty };
|
|
|
|
+ return result;
|
|
}
|
|
}
|
|
|
|
+ else //定時寄送 [待做]
|
|
|
|
+ {
|
|
|
|
|
|
- var result = new { };
|
|
|
|
- return result;
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
else if (type.Equals("sms")) //短訊
|
|
else if (type.Equals("sms")) //短訊
|
|
{
|
|
{
|
|
@@ -1612,15 +1651,16 @@ namespace TEAMModelBI.Controllers.BICommon
|
|
return responseMessage;
|
|
return responseMessage;
|
|
}
|
|
}
|
|
|
|
|
|
- private HttpResponseMessage CallSendMailApi(List<string> tmIds, string subject, string title, string body, string template, string data, string eventId = "", string eventName = "")
|
|
|
|
|
|
+ private async Task CallSendMailApiAsync(string email, string subject, string title, string body, string template, string image)
|
|
{
|
|
{
|
|
- //{
|
|
|
|
- // "sub":"a",
|
|
|
|
- // "title":"嘿嘿",
|
|
|
|
- // "body":"見鬼拉",
|
|
|
|
- // "image":"https://corestorageservice.blob.core.windows.net/public-marketing/S__43540491.png"
|
|
|
|
-
|
|
|
|
- //}
|
|
|
|
|
|
+ object mailVars = new
|
|
|
|
+ {
|
|
|
|
+ sub = subject,
|
|
|
|
+ title = title,
|
|
|
|
+ body = body,
|
|
|
|
+ image = image
|
|
|
|
+ };
|
|
|
|
+ await _coreAPIHttpService.SendMail(new Dictionary<string, object> { { "to", email }, { "tid", template }, { "vars", mailVars } }, _option.Location, _configuration);
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|