|
@@ -1015,15 +1015,15 @@ namespace TEAMModelBI.Controllers.BICommon
|
|
|
string eventKey = "bi-gen-notify";
|
|
|
string eventId = $"{eventKey}_{_snowflakeId.NextId()}";
|
|
|
string eventName = "BI send notification";
|
|
|
- var data = new {
|
|
|
- value = dataParam,
|
|
|
- action = action
|
|
|
- };
|
|
|
- await SendMessageCore(target, type, method, title, body, eventId, eventName, data);
|
|
|
+ DataInNotify data = new DataInNotify();
|
|
|
+ if(dataParam.ValueKind != JsonValueKind.Undefined) data.value = dataParam;
|
|
|
+ if (action.Count > 0) data.action = action;
|
|
|
+ await SendMessageCore(target, type, method, title, body, data, eventId, eventName);
|
|
|
+
|
|
|
return Ok(new { state = RespondCode.Ok });
|
|
|
}
|
|
|
///寄發訊息核心邏輯
|
|
|
- private async Task<IActionResult> SendMessageCore(SendMessageParam target, string type, string method, string title, string body, string eventId = "", string eventName = "", object data = null)
|
|
|
+ private async Task<IActionResult> SendMessageCore(SendMessageParam target, string type, string method, string title, string body, DataInNotify data, string eventId = "", string eventName = "")
|
|
|
{
|
|
|
#region target 內容例
|
|
|
//{
|
|
@@ -1087,21 +1087,29 @@ namespace TEAMModelBI.Controllers.BICommon
|
|
|
}
|
|
|
|
|
|
//寄發訊息
|
|
|
- if(type.Equals("notify")) //端內外通知
|
|
|
+ if (type.Equals("notify")) //端內外通知
|
|
|
{
|
|
|
List<string> tmIds = tmidInfos.Select(i => i.id).ToList();
|
|
|
- CallPushNotifyApi(tmIds, title, body, eventId, eventName, data);
|
|
|
+ HttpResponseMessage response = CallPushNotifyApi(tmIds, title, body, data, eventId, eventName);
|
|
|
+ var result = new { status = response.StatusCode, content = response.Content };
|
|
|
+ return Ok(new { state = RespondCode.Ok, result = result });
|
|
|
}
|
|
|
else if(type.Equals("mail")) //Email
|
|
|
{
|
|
|
List<string> tmIds = tmidInfos.Where(i => !string.IsNullOrWhiteSpace(i.mail)).Select(i => i.id).ToList();
|
|
|
+ //呼叫Email API [未]
|
|
|
+ var result = new { };
|
|
|
+ return Ok(new { state = RespondCode.Ok, result = result });
|
|
|
}
|
|
|
else if (type.Equals("sms")) //短訊
|
|
|
{
|
|
|
List<string> tmIds = tmidInfos.Where(i => !string.IsNullOrWhiteSpace(i.mobile)).Select(i => i.id).ToList();
|
|
|
+ //呼叫短訊API [未]
|
|
|
+ var result = new { };
|
|
|
+ return Ok(new { state = RespondCode.Ok, result = result });
|
|
|
}
|
|
|
|
|
|
- return Ok(new { state = RespondCode.Ok });
|
|
|
+ return Ok(new { state = RespondCode.Ok, result = new { } });
|
|
|
}
|
|
|
//取得學區所屬學校教師
|
|
|
private async Task<List<string>> GetTmidByAreaId(List<string> areaIds)
|
|
@@ -1178,11 +1186,6 @@ namespace TEAMModelBI.Controllers.BICommon
|
|
|
}
|
|
|
return tmids;
|
|
|
}
|
|
|
- //寄送通知核心程式(途中)
|
|
|
- private void sendMessageByApi()
|
|
|
- {
|
|
|
- //_coreAPIHttpService.PushNotify(idNameCodes, $"{bizcode}_school", Constant.NotifyType_IES5_Task, new Dictionary<string, object> { { "tmdname", name }, { "schoolName", schname }, { "schoolId", $"{school}" }, { "tmdid", userid } }, _option.Location, _configuration, _dingDing, _environment.ContentRootPath);
|
|
|
- }
|
|
|
|
|
|
//取得學校機構所屬學校教師
|
|
|
private async Task<List<string>> GetTmidByUnitId(List<string> units)
|
|
@@ -1292,18 +1295,7 @@ namespace TEAMModelBI.Controllers.BICommon
|
|
|
}
|
|
|
finalSchUnitTypeDic.Add(schId, unitTypeF);
|
|
|
}
|
|
|
- //由類型篩選學校ID [應該不需要,CoreV2的SQL已篩選過]
|
|
|
- //List<string> schIdsForSql = new List<string>();
|
|
|
- //foreach (KeyValuePair<string, string> item in finalSchUnitTypeDic)
|
|
|
- //{
|
|
|
- // string schId = item.Key;
|
|
|
- // if (units.Contains(item.Value))
|
|
|
- // {
|
|
|
- // schIdsForSql.Add(schId);
|
|
|
- // }
|
|
|
- //}
|
|
|
//取得學校所屬老師TMID
|
|
|
- //teacherCodes = schIdsForSql.Select(s => $"Teacher-{s}").ToList();
|
|
|
teacherCodes = finalSchUnitTypeDic.Select(s => $"Teacher-{s.Key}").ToList();
|
|
|
List<string> tmids = new List<string>();
|
|
|
string sqlTch = $"SELECT DISTINCT c.id FROM c WHERE c.pk = 'Teacher' AND c.status = 'join' AND ARRAY_CONTAINS({JsonSerializer.Serialize(teacherCodes)}, c.code)";
|
|
@@ -1342,12 +1334,12 @@ namespace TEAMModelBI.Controllers.BICommon
|
|
|
/// <param name="eventName"></param>
|
|
|
/// <param name="data"></param>
|
|
|
/// <returns></returns>
|
|
|
- private HttpResponseMessage CallPushNotifyApi(List<string> tmIds, string title, string body, string eventId = "", string eventName = "", object data = null)
|
|
|
+ private HttpResponseMessage CallPushNotifyApi(List<string> tmIds, string title, string body, DataInNotify data, string eventId = "", string eventName = "")
|
|
|
{
|
|
|
NotifyData notify = new NotifyData();
|
|
|
notify.hubName = "hita5";
|
|
|
notify.sender = "IES"; //先填IES 若之後有需求要標BI 再修正
|
|
|
-#if DEBUG
|
|
|
+#if DEBUG //測試模式時限制TMID帳號,正式站佈署時不生效
|
|
|
List<string> filterTmid = new List<string>() { "1522758684", "1595321354" };
|
|
|
tmIds = tmIds.Intersect(filterTmid).ToList();
|
|
|
#endif
|
|
@@ -1356,7 +1348,7 @@ namespace TEAMModelBI.Controllers.BICommon
|
|
|
notify.body = body;
|
|
|
notify.eventId = eventId;
|
|
|
notify.eventName = eventName;
|
|
|
- notify.data = (data != null) ? data.ToJsonString() : string.Empty;
|
|
|
+ notify.data = data.ToJsonString();
|
|
|
var clientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
|
|
|
var clientSecret = _configuration.GetValue<string>("HaBookAuth:CoreService:clientSecret");
|
|
|
var url = _configuration.GetValue<string>("HaBookAuth:CoreAPI");
|
|
@@ -1415,7 +1407,7 @@ namespace TEAMModelBI.Controllers.BICommon
|
|
|
public List<string> school { get; set; } = new(); //學校ID
|
|
|
public List<string> tmid { get; set; } = new(); //TMID
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
//取得學校機構ID及名稱
|
|
|
public Dictionary<string, string> getSchoolUnitName(string lang)
|
|
|
{
|
|
@@ -1472,6 +1464,14 @@ namespace TEAMModelBI.Controllers.BICommon
|
|
|
public string mail { get; set; }
|
|
|
public string mobile { get; set; }
|
|
|
}
|
|
|
+ /// <summary>
|
|
|
+ /// 呼叫端外通知API用 NotifyData.data格式
|
|
|
+ /// </summary>
|
|
|
+ private record DataInNotify
|
|
|
+ {
|
|
|
+ public object value { get; set; } = new();
|
|
|
+ public List<NotifyAction> action { get; set; } = new();
|
|
|
+ }
|
|
|
private record NotifyAction
|
|
|
{
|
|
|
public string type { get; set; } = "click";
|