|
@@ -38,6 +38,11 @@ using System.Text.RegularExpressions;
|
|
|
using MathNet.Numerics.Distributions;
|
|
|
using System.Drawing.Drawing2D;
|
|
|
using Microsoft.Azure.Amqp.Framing;
|
|
|
+using TEAMModelOS.SDK.DI.IPIP;
|
|
|
+using Azure;
|
|
|
+using Microsoft.AspNetCore.Http.HttpResults;
|
|
|
+using System.Net;
|
|
|
+using System.Dynamic;
|
|
|
|
|
|
|
|
|
namespace TEAMModelBI.Controllers.BICommon
|
|
@@ -333,7 +338,7 @@ namespace TEAMModelBI.Controllers.BICommon
|
|
|
//取得學校ID列表
|
|
|
Dictionary<string, string> schAreaDic = new Dictionary<string, string>();
|
|
|
Dictionary<string, string> schNameDic = new Dictionary<string, string>();
|
|
|
- List<string> teacherCodes = new List<string>();
|
|
|
+ //List<string> teacherCodes = new List<string>();
|
|
|
List<string> areaIds = areaInfos.Select(a => a.id).ToList();
|
|
|
string sqlSch = $"SELECT c.id, c.name, c.areaId FROM c WHERE ARRAY_CONTAINS({JsonSerializer.Serialize(areaIds)}, c.areaId)";
|
|
|
///實體校
|
|
@@ -342,15 +347,8 @@ namespace TEAMModelBI.Controllers.BICommon
|
|
|
string schId = item.GetProperty("id").ToString();
|
|
|
string schName = item.GetProperty("name").ToString();
|
|
|
string areaId = item.GetProperty("areaId").ToString();
|
|
|
- if (!schAreaDic.ContainsKey(schId))
|
|
|
- {
|
|
|
- schAreaDic.Add(schId, areaId);
|
|
|
- schNameDic.Add(schId, schName);
|
|
|
- }
|
|
|
- if (!teacherCodes.Contains($"Teacher-{schId}"))
|
|
|
- {
|
|
|
- teacherCodes.Add($"Teacher-{schId}");
|
|
|
- }
|
|
|
+ if (!schAreaDic.ContainsKey(schId)) schAreaDic.Add(schId, areaId);
|
|
|
+ if (!schNameDic.ContainsKey(schId)) schNameDic.Add(schId, schName);
|
|
|
}
|
|
|
///虛擬校
|
|
|
await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, Constant.School).GetItemQueryIteratorSql<JsonElement>(queryText: sqlSch, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"VirtualBase") }))
|
|
@@ -358,39 +356,28 @@ namespace TEAMModelBI.Controllers.BICommon
|
|
|
string schId = item.GetProperty("id").ToString();
|
|
|
string schName = item.GetProperty("name").ToString();
|
|
|
string areaId = item.GetProperty("areaId").ToString();
|
|
|
- if (!schAreaDic.ContainsKey(schId))
|
|
|
- {
|
|
|
- schAreaDic.Add(schId, areaId);
|
|
|
- if (!schNameDic.ContainsKey(schId)) schNameDic.Add(schId, schName);
|
|
|
- }
|
|
|
+ if (!schAreaDic.ContainsKey(schId)) schAreaDic.Add(schId, areaId);
|
|
|
+ if (!schNameDic.ContainsKey(schId)) schNameDic.Add(schId, schName);
|
|
|
}
|
|
|
- //有無Email篩檢
|
|
|
- List<string> tmidFilterList = new List<string>();
|
|
|
+ //取得歸戶學校教師數
|
|
|
+ Dictionary<string, int> schTeacherCntDic = new Dictionary<string, int>();
|
|
|
+ List<string> filterScid = schNameDic.Select(s => s.Key).ToList();
|
|
|
+ string sqlEx = $"SELECT c.id, c.schoolCode, c.schoolCodeW FROM c WHERE ((ARRAY_CONTAINS({JsonSerializer.Serialize(filterScid)}, c.schoolCode) OR ARRAY_CONTAINS({JsonSerializer.Serialize(filterScid)}, c.schoolCodeW)))";
|
|
|
if (hasMail)
|
|
|
{
|
|
|
- List<string> tmidListIes = new List<string>();
|
|
|
- string sqlTchHasMailIes = $"SELECT DISTINCT c.id FROM c WHERE c.pk = 'Teacher' AND c.status = 'join' AND ARRAY_CONTAINS({JsonSerializer.Serialize(teacherCodes)}, c.code)";
|
|
|
- await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, Constant.School).GetItemQueryIteratorSql<JsonElement>(queryText: sqlTchHasMailIes, requestOptions: null))
|
|
|
- {
|
|
|
- string tmid = item.GetProperty("id").ToString();
|
|
|
- tmidListIes.Add(tmid);
|
|
|
- }
|
|
|
- string sqlEx = $"SELECT c.id FROM c WHERE IS_DEFINED(c.mail) AND NOT IS_NULL(c.mail) AND c.mail != '' AND ARRAY_CONTAINS({JsonSerializer.Serialize(tmidListIes)}, c.id) ";
|
|
|
- await foreach (var item in cosmosClientCsv2.GetContainer("Core", "ID2").GetItemQueryIteratorSql<JsonElement>(queryText: sqlEx, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"base-ex") }))
|
|
|
- {
|
|
|
- string tmid = item.GetProperty("id").ToString();
|
|
|
- tmidFilterList.Add(tmid);
|
|
|
- }
|
|
|
+ sqlEx += " AND (IS_DEFINED(c.mail) AND NOT IS_NULL(c.mail) AND c.mail != '')";
|
|
|
}
|
|
|
- //取得學校教師數
|
|
|
- Dictionary<string, int> schTeacherCntDic = new Dictionary<string, int>();
|
|
|
- string sqlTmidFilter = (tmidFilterList.Count > 0) ? $" AND ARRAY_CONTAINS({JsonSerializer.Serialize(tmidFilterList)}, c.id) " : string.Empty;
|
|
|
- string sqlTch = $"SELECT REPLACE(c.code, 'Teacher-', '') as schoolId, COUNT(c.id) AS tchCnt FROM c WHERE c.pk = 'Teacher' AND c.status = 'join' AND ARRAY_CONTAINS({JsonSerializer.Serialize(teacherCodes)}, c.code) {sqlTmidFilter} GROUP BY c.code";
|
|
|
- await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, Constant.School).GetItemQueryIteratorSql<JsonElement>(queryText: sqlTch, requestOptions: null))
|
|
|
+ await foreach (var item in cosmosClientCsv2.GetContainer("Core", "ID2").GetItemQueryIteratorSql<JsonElement>(queryText: sqlEx, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"base-ex") }))
|
|
|
{
|
|
|
- string schId = item.GetProperty("schoolId").ToString();
|
|
|
- int tchCnt = item.GetProperty("tchCnt").GetInt32();
|
|
|
- schTeacherCntDic.Add(schId, tchCnt);
|
|
|
+ string tmid = item.GetProperty("id").ToString();
|
|
|
+ string schoolCode = (item.TryGetProperty("schoolCode", out JsonElement _schoolCode)) ? _schoolCode.ToString() : string.Empty;
|
|
|
+ string schoolCodeW = (item.TryGetProperty("schoolCodeW", out JsonElement _schoolCodeW)) ? _schoolCodeW.ToString() : string.Empty;
|
|
|
+ string schId = (!string.IsNullOrWhiteSpace(schoolCode)) ? schoolCode : (!string.IsNullOrWhiteSpace(schoolCodeW)) ? schoolCodeW : string.Empty;
|
|
|
+ if(filterScid.Contains(schId))
|
|
|
+ {
|
|
|
+ if (!schTeacherCntDic.ContainsKey(schId)) schTeacherCntDic.Add(schId, 0);
|
|
|
+ schTeacherCntDic[schId]++;
|
|
|
+ }
|
|
|
}
|
|
|
//資料整理1 有教師則記入
|
|
|
foreach (KeyValuePair<string, int> item in schTeacherCntDic)
|
|
@@ -469,14 +456,14 @@ namespace TEAMModelBI.Controllers.BICommon
|
|
|
//取得ID帳號中所有的歸戶學校ID
|
|
|
List<string> coreSchIds = new List<string>();
|
|
|
Dictionary<string, List<string>> schTmidDic = new Dictionary<string, List<string>>(); //學校ID > TMID 字典
|
|
|
- string sqlEx = "SELECT c.id, c.schoolCode, c.schoolCodeW FROM c WHERE IS_DEFINED(c.schoolCode) AND NOT IS_NULL(c.schoolCode) AND IS_DEFINED(c.schoolCodeW) AND NOT IS_NULL(c.schoolCodeW)";
|
|
|
- if (hasMail) sqlEx += " AND IS_DEFINED(c.mail) AND NOT IS_NULL(c.mail) ";
|
|
|
+ string sqlEx = "SELECT c.id, c.schoolCode, c.schoolCodeW FROM c WHERE ((IS_DEFINED(c.schoolCode) AND NOT IS_NULL(c.schoolCode)) OR (IS_DEFINED(c.schoolCodeW) AND NOT IS_NULL(c.schoolCodeW)))";
|
|
|
+ if (hasMail) sqlEx += " AND (IS_DEFINED(c.mail) AND NOT IS_NULL(c.mail)) ";
|
|
|
await foreach (var item in cosmosClientCsv2.GetContainer("Core", "ID2").GetItemQueryIteratorSql<JsonElement>(queryText: sqlEx, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"base-ex") }))
|
|
|
{
|
|
|
string tmid = item.GetProperty("id").ToString();
|
|
|
- string shortCode = (item.TryGetProperty("shortCode", out JsonElement _shortCode)) ? _shortCode.ToString() : string.Empty;
|
|
|
+ string schoolCode = (item.TryGetProperty("schoolCode", out JsonElement _schoolCode)) ? _schoolCode.ToString() : string.Empty;
|
|
|
string schoolCodeW = (item.TryGetProperty("schoolCodeW", out JsonElement _schoolCodeW)) ? _schoolCodeW.ToString() : string.Empty;
|
|
|
- string schId = (!string.IsNullOrWhiteSpace(shortCode)) ? shortCode : (!string.IsNullOrWhiteSpace(schoolCodeW)) ? schoolCodeW : string.Empty;
|
|
|
+ string schId = (!string.IsNullOrWhiteSpace(schoolCode)) ? schoolCode : (!string.IsNullOrWhiteSpace(schoolCodeW)) ? schoolCodeW : string.Empty;
|
|
|
if (!string.IsNullOrWhiteSpace(schId))
|
|
|
{
|
|
|
if(!coreSchIds.Contains(schId)) coreSchIds.Add(schId);
|
|
@@ -1237,17 +1224,27 @@ namespace TEAMModelBI.Controllers.BICommon
|
|
|
string data = (jsonElement.TryGetProperty("data", out JsonElement _data)) ? _data.ToString() : string.Empty; //額外資料
|
|
|
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
|
|
|
-
|
|
|
- if (target == null || string.IsNullOrWhiteSpace(type) || string.IsNullOrWhiteSpace(method) || string.IsNullOrWhiteSpace(title) || string.IsNullOrWhiteSpace(body) || string.IsNullOrWhiteSpace(sender)) return BadRequest();
|
|
|
+ //必須項檢驗
|
|
|
+ bool hasMail = false;
|
|
|
+ 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();
|
|
|
+ hasMail = true;
|
|
|
+ }
|
|
|
string eventKey = "bi-gen-notify";
|
|
|
string eventId = $"{eventKey}_{_snowflakeId.NextId()}";
|
|
|
string eventName = "BI send notification";
|
|
|
- var result = await SendMessageCore(target, type, method, subject, title, body, data, sender, hubName, template, send, eventId, eventName);
|
|
|
+ var result = await SendMessageCore(target, type, method, subject, title, body, data, sender, hubName, template, send, eventId, eventName, hasMail);
|
|
|
|
|
|
return Ok(new { state = RespondCode.Ok, result });
|
|
|
}
|
|
|
///寄發訊息核心邏輯
|
|
|
- private async Task<object> SendMessageCore(SendMessageParam target, string type, string method, string subject, string title, string body, string data, string sender, string hubName, string template, long send, string eventId = "", string eventName = "")
|
|
|
+ private async Task<object> SendMessageCore(SendMessageParam target, string type, string method, string subject, string title, string body, string data, string sender, string hubName, string template, long send, string eventId = "", string eventName = "", bool hasMail = false)
|
|
|
{
|
|
|
#region target 內容例
|
|
|
//{
|
|
@@ -1279,12 +1276,14 @@ namespace TEAMModelBI.Controllers.BICommon
|
|
|
// ]
|
|
|
//}
|
|
|
#endregion
|
|
|
+ var cosmosClientIes = _azureCosmos.GetCosmosClient();
|
|
|
var cosmosClientCsv2 = _azureCosmos.GetCosmosClient(name: "CoreServiceV2");
|
|
|
+ var (_tmdId, _tmdName, _, _, _, _) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
|
|
|
|
|
|
- List<string> tmids_area = await GetTmidByAreaId(target.area);
|
|
|
- List<string> tmids_geo = await GetTmidByGeo(target.geo);
|
|
|
- List<string> tmids_unit = await GetTmidByUnitId(target.unit);
|
|
|
- List<string> tmids_school = await GetTmidBySchoolId(target.school);
|
|
|
+ List<string> tmids_area = await GetTmidByAreaId(target.area, hasMail);
|
|
|
+ List<string> tmids_geo = await GetTmidByGeo(target.geo, hasMail);
|
|
|
+ List<string> tmids_unit = await GetTmidByUnitId(target.unit, hasMail);
|
|
|
+ List<string> tmids_school = await GetTmidBySchoolId(target.school, hasMail);
|
|
|
List<string> tmids_direct = target.tmid;
|
|
|
|
|
|
List<string> tmids = new List<string>(); //聯集化
|
|
@@ -1294,6 +1293,10 @@ namespace TEAMModelBI.Controllers.BICommon
|
|
|
tmids = tmids.Union(tmids_school).ToList();
|
|
|
tmids = tmids.Union(tmids_direct).ToList();
|
|
|
tmids = tmids.Distinct().ToList(); //唯一化
|
|
|
+//#if DEBUG //測試模式時限制TMID帳號,正式站佈署時不生效
|
|
|
+// List<string> filterTmid = new List<string>() { "1522758684", "1595321354", "1629875867" }; //"1522758684", "1595321354"
|
|
|
+// tmids = tmids.Intersect(filterTmid).ToList();
|
|
|
+//#endif
|
|
|
|
|
|
//取得TMID資料
|
|
|
List<IdInfo> tmidInfos = new List<IdInfo>();
|
|
@@ -1324,7 +1327,18 @@ namespace TEAMModelBI.Controllers.BICommon
|
|
|
List<string> tmIds = tmidInfos.Select(i => i.id).ToList();
|
|
|
if(send.Equals(0)) //立即寄送
|
|
|
{
|
|
|
+ //訊息寄送
|
|
|
HttpResponseMessage response = CallPushNotifyApi(tmIds, title, body, sender, hubName, template, data, eventId, eventName);
|
|
|
+ //寄送訊息DB記入
|
|
|
+ if(response.IsSuccessStatusCode)
|
|
|
+ {
|
|
|
+ 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 = response.StatusCode, content = await response.Content.ReadAsStringAsync() };
|
|
|
return result;
|
|
|
}
|
|
@@ -1336,15 +1350,58 @@ namespace TEAMModelBI.Controllers.BICommon
|
|
|
}
|
|
|
else if(type.Equals("mail")) //Email
|
|
|
{
|
|
|
+ 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();
|
|
|
//呼叫Email API [未]
|
|
|
///模板設定
|
|
|
- if(_option.Location.Contains("Global"))
|
|
|
+ if (_option.Location.Contains("Global"))
|
|
|
{
|
|
|
- if (string.IsNullOrWhiteSpace(template)) template = "d-f1c5abd8247f4be79ceaecdd327e9a68"; //若未指定模板ID,用預設模板
|
|
|
+ if (string.IsNullOrWhiteSpace(template))
|
|
|
+ template = defaultTemplate; //若未指定模板ID,用預設模板
|
|
|
+ }
|
|
|
+ if(string.IsNullOrWhiteSpace(template)) //無模板ID,就不執行
|
|
|
+ {
|
|
|
+ var result = new { status = HttpStatusCode.BadRequest };
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ //Email寄送
|
|
|
+ bool sendMail = false;
|
|
|
+ if (send.Equals(0)) //立即寄送
|
|
|
+ {
|
|
|
+ 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")) //短訊
|
|
|
{
|
|
@@ -1357,7 +1414,7 @@ namespace TEAMModelBI.Controllers.BICommon
|
|
|
return new { };
|
|
|
}
|
|
|
//取得學區所屬學校教師
|
|
|
- private async Task<List<string>> GetTmidByAreaId(List<string> areaIds)
|
|
|
+ private async Task<List<string>> GetTmidByAreaId(List<string> areaIds, bool hasMail)
|
|
|
{
|
|
|
var cosmosClientIes = _azureCosmos.GetCosmosClient();
|
|
|
//取得學校ID列表
|
|
@@ -1369,26 +1426,36 @@ namespace TEAMModelBI.Controllers.BICommon
|
|
|
string schId = item.GetProperty("id").ToString();
|
|
|
schIds.Add(schId);
|
|
|
}
|
|
|
- List<string> teacherCodes = schIds.Select(s => $"Teacher-{s}").ToList();
|
|
|
- //取得學校教師ID列表
|
|
|
- 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)";
|
|
|
- await foreach (var item in cosmosClientIes.GetContainer(Constant.TEAMModelOS, Constant.School).GetItemQueryIteratorSql<JsonElement>(queryText: sqlTch, requestOptions: null))
|
|
|
+ ///虛擬校
|
|
|
+ await foreach (var item in cosmosClientIes.GetContainer(Constant.TEAMModelOS, Constant.School).GetItemQueryIteratorSql<JsonElement>(queryText: sqlSch, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"VirtualBase") }))
|
|
|
{
|
|
|
- string tmid = item.GetProperty("id").ToString();
|
|
|
- tmids.Add(tmid);
|
|
|
+ string schId = item.GetProperty("id").ToString();
|
|
|
+ if(!schIds.Contains(schId)) schIds.Add(schId);
|
|
|
}
|
|
|
+ //結果輸出
|
|
|
+ List<string> tmids = new List<string>();
|
|
|
+ tmids = await GetTmidBySchoolId(schIds, hasMail);
|
|
|
+
|
|
|
+ //List<string> teacherCodes = schIds.Select(s => $"Teacher-{s}").ToList();
|
|
|
+ ////取得學校教師ID列表
|
|
|
+ //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)";
|
|
|
+ //await foreach (var item in cosmosClientIes.GetContainer(Constant.TEAMModelOS, Constant.School).GetItemQueryIteratorSql<JsonElement>(queryText: sqlTch, requestOptions: null))
|
|
|
+ //{
|
|
|
+ // string tmid = item.GetProperty("id").ToString();
|
|
|
+ // tmids.Add(tmid);
|
|
|
+ //}
|
|
|
return tmids;
|
|
|
}
|
|
|
//取得地理資訊所屬TMID
|
|
|
- private async Task<List<string>> GetTmidByGeo(List<Geo> geos)
|
|
|
+ private async Task<List<string>> GetTmidByGeo(List<Geo> geos, bool hasMail)
|
|
|
{
|
|
|
List<string> tmids = new List<string>();
|
|
|
foreach (Geo geo in geos)
|
|
|
{
|
|
|
if(!string.IsNullOrWhiteSpace(geo.type) && geo.type.Equals("tmid"))
|
|
|
{
|
|
|
- var (geoInfos, _) = await GetDataByGeo("tmid", "tmid", true, geo.countryId, geo.provinceId, geo.cityId);
|
|
|
+ var (geoInfos, _) = await GetDataByGeo("tmid", "tmid", true, geo.countryId, geo.provinceId, geo.cityId, hasMail);
|
|
|
foreach (var geoInfo in geoInfos)
|
|
|
{
|
|
|
if (!tmids.Contains(geoInfo.id)) tmids.Add(geoInfo.id);
|
|
@@ -1396,7 +1463,7 @@ namespace TEAMModelBI.Controllers.BICommon
|
|
|
}
|
|
|
else if(!string.IsNullOrWhiteSpace(geo.type) && geo.type.Equals("school"))
|
|
|
{
|
|
|
- var (geoInfos, _) = await GetDataByGeo("school", "tmid", true, geo.countryId, geo.provinceId, geo.cityId);
|
|
|
+ var (geoInfos, _) = await GetDataByGeo("school", "tmid", true, geo.countryId, geo.provinceId, geo.cityId, hasMail);
|
|
|
foreach (var geoInfo in geoInfos)
|
|
|
{
|
|
|
if (!tmids.Contains(geoInfo.id)) tmids.Add(geoInfo.id);
|
|
@@ -1407,30 +1474,41 @@ namespace TEAMModelBI.Controllers.BICommon
|
|
|
}
|
|
|
|
|
|
//取得學校機構所屬學校教師
|
|
|
- private async Task<List<string>> GetTmidByUnitId(List<string> units)
|
|
|
+ private async Task<List<string>> GetTmidByUnitId(List<string> units, bool hasMail = false)
|
|
|
{
|
|
|
if (units.Count.Equals(0)) return new List<string>();
|
|
|
|
|
|
- var cosmosClientIes = _azureCosmos.GetCosmosClient();
|
|
|
+ //var cosmosClientIes = _azureCosmos.GetCosmosClient();
|
|
|
var coreCosmosClientCn = _azureCosmos.GetCosmosClient(name: "CoreServiceV2CnRead");
|
|
|
- //取得IES5學校ID
|
|
|
- string iesSql = "SELECT c.id, c.type FROM c WHERE 1=1 ";
|
|
|
- string iesWhere = string.Empty;
|
|
|
- //IES學校ID取得、學校類型取得
|
|
|
- List<string> iesSchIds = new List<string>();
|
|
|
- Dictionary<string, string> schTypeDic = new Dictionary<string, string>(); //IES5學校ID與學校類型對照表
|
|
|
- List<string> teacherCodes = new List<string>(); //用來取得老師資料的分區鍵
|
|
|
- string sqlSch = $"{iesSql}{iesWhere}";
|
|
|
- await foreach (var item in cosmosClientIes.GetContainer(Constant.TEAMModelOS, Constant.School).GetItemQueryIteratorSql<JsonElement>(queryText: sqlSch, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Base") }))
|
|
|
+ var cosmosClientCsv2 = _azureCosmos.GetCosmosClient(name: "CoreServiceV2");
|
|
|
+ List<string> tmids = new List<string>();
|
|
|
+ List<string> coreSchIds = new List<string>();
|
|
|
+ Dictionary<string, List<string>> schTmidDic = new Dictionary<string, List<string>>(); //學校ID > TMID 字典
|
|
|
+ //取得有歸戶的所有TMID
|
|
|
+ string sqlEx = "SELECT c.id, c.schoolCode, c.schoolCodeW FROM c WHERE ((IS_DEFINED(c.schoolCode) AND NOT IS_NULL(c.schoolCode)) OR (IS_DEFINED(c.schoolCodeW) AND NOT IS_NULL(c.schoolCodeW)))";
|
|
|
+ if (hasMail) sqlEx += " AND (IS_DEFINED(c.mail) AND NOT IS_NULL(c.mail)) ";
|
|
|
+ await foreach (var item in cosmosClientCsv2.GetContainer("Core", "ID2").GetItemQueryIteratorSql<JsonElement>(queryText: sqlEx, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"base-ex") }))
|
|
|
{
|
|
|
- string schId = item.GetProperty("id").ToString();
|
|
|
- int schType = item.GetProperty("type").GetInt32();
|
|
|
- iesSchIds.Add(schId);
|
|
|
- if (!schTypeDic.ContainsKey(schId)) schTypeDic.Add(schId, schType.ToString());
|
|
|
+ string tmid = item.GetProperty("id").ToString();
|
|
|
+ string schoolCode = (item.TryGetProperty("schoolCode", out JsonElement _schoolCode)) ? _schoolCode.ToString() : string.Empty;
|
|
|
+ string schoolCodeW = (item.TryGetProperty("schoolCodeW", out JsonElement _schoolCodeW)) ? _schoolCodeW.ToString() : string.Empty;
|
|
|
+ string schId = (!string.IsNullOrWhiteSpace(schoolCode)) ? schoolCode : (!string.IsNullOrWhiteSpace(schoolCodeW)) ? schoolCodeW : string.Empty;
|
|
|
+ if (!string.IsNullOrWhiteSpace(schId))
|
|
|
+ {
|
|
|
+ if (!coreSchIds.Contains(schId)) coreSchIds.Add(schId);
|
|
|
+ if (schTmidDic.ContainsKey(schId))
|
|
|
+ {
|
|
|
+ if (!schTmidDic[schId].Contains(tmid)) schTmidDic[schId].Add(tmid);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ schTmidDic.Add(schId, new List<string>() { tmid });
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
//取得Core學校ID及類型
|
|
|
string coreSql = "SELECT c.shortCode, c.unitType FROM c";
|
|
|
- string coreWhere = $" WHERE ARRAY_CONTAINS({JsonSerializer.Serialize(iesSchIds)}, c.shortCode) ";
|
|
|
+ string coreWhere = $" WHERE ARRAY_CONTAINS({JsonSerializer.Serialize(coreSchIds)}, c.shortCode) ";
|
|
|
string coreWhereUnittype = string.Empty;
|
|
|
if (units.Contains("1"))
|
|
|
{
|
|
@@ -1461,85 +1539,79 @@ namespace TEAMModelBI.Controllers.BICommon
|
|
|
await foreach (var item in coreCosmosClientCn.GetContainer("Core", "School").GetItemQueryIteratorSql<JsonElement>(queryText: sqlCore, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"base") }))
|
|
|
{
|
|
|
string shortCode = item.GetProperty("shortCode").ToString();
|
|
|
- string unitType = item.GetProperty("unitType").ToString();
|
|
|
- if (!teacherCodes.Contains($"Teacher-{shortCode}")) teacherCodes.Add($"Teacher-{shortCode}");
|
|
|
+ string unitType = (item.TryGetProperty("unitType", out JsonElement _unitType)) ? _unitType.ToString() : string.Empty;
|
|
|
if (!coreSchUnitTypeDic.ContainsKey(shortCode)) coreSchUnitTypeDic.Add(shortCode, unitType);
|
|
|
}
|
|
|
//學校類型轉換
|
|
|
- Dictionary<string, string> finalSchUnitTypeDic = new Dictionary<string, string>();
|
|
|
- foreach (KeyValuePair<string, string> item in coreSchUnitTypeDic)
|
|
|
- {
|
|
|
- string schId = item.Key;
|
|
|
- string coreUnitType = (coreSchUnitTypeDic.ContainsKey(schId)) ? coreSchUnitTypeDic[schId] : string.Empty;
|
|
|
- string iesUnitType = (schTypeDic.ContainsKey(schId)) ? schTypeDic[schId] : string.Empty;
|
|
|
- string unitTypeF = string.Empty; //機構類型(最終判斷)
|
|
|
- if (!string.IsNullOrWhiteSpace(coreUnitType))
|
|
|
- {
|
|
|
- switch (coreUnitType)
|
|
|
- {
|
|
|
- case "1": //基礎教育機構
|
|
|
- case "8": //學前教育
|
|
|
- unitTypeF = "1"; // => 基礎教育機構(K-小學)
|
|
|
- break;
|
|
|
- case "2": //中等教育機構
|
|
|
- unitTypeF = "2"; // => 中等教育機構(國中、高中/職)
|
|
|
- break;
|
|
|
-
|
|
|
- case "3": //高等教育機構
|
|
|
- unitTypeF = "3"; // => 高等教育機構(大學、研究所)
|
|
|
- break;
|
|
|
- case "4": //政府單位機構
|
|
|
- case "5": //NGO機構
|
|
|
- case "6": //企業機構
|
|
|
- case "7": //其他
|
|
|
- case "9": //特殊教育
|
|
|
- unitTypeF = "4"; // => 其他
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- else if (!string.IsNullOrWhiteSpace(iesUnitType))
|
|
|
- {
|
|
|
- switch (iesUnitType) //1 普教,2 高职教
|
|
|
- {
|
|
|
- case "1": //國教(K-12)
|
|
|
- unitTypeF = "1"; // => 基礎教育機構(K-小學)
|
|
|
- break;
|
|
|
- case "2": //大專院校
|
|
|
- unitTypeF = "3"; // => 高等教育機構(大學、研究所)
|
|
|
- break;
|
|
|
- default: //未設定
|
|
|
- unitTypeF = "4"; // => 其他
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- finalSchUnitTypeDic.Add(schId, unitTypeF);
|
|
|
- }
|
|
|
- //取得學校所屬老師TMID
|
|
|
- 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)";
|
|
|
- await foreach (var item in cosmosClientIes.GetContainer(Constant.TEAMModelOS, Constant.School).GetItemQueryIteratorSql<JsonElement>(queryText: sqlTch, requestOptions: null))
|
|
|
+ //Dictionary<string, string> finalSchUnitTypeDic = new Dictionary<string, string>();
|
|
|
+ //foreach (KeyValuePair<string, string> item in coreSchUnitTypeDic)
|
|
|
+ //{
|
|
|
+ // string schId = item.Key;
|
|
|
+ // string coreUnitType = (coreSchUnitTypeDic.ContainsKey(schId)) ? coreSchUnitTypeDic[schId] : string.Empty;
|
|
|
+ // string unitTypeF = string.Empty; //機構類型(最終判斷)
|
|
|
+ // if (!string.IsNullOrWhiteSpace(coreUnitType))
|
|
|
+ // {
|
|
|
+ // switch (coreUnitType)
|
|
|
+ // {
|
|
|
+ // case "1": //基礎教育機構
|
|
|
+ // case "8": //學前教育
|
|
|
+ // unitTypeF = "1"; // => 基礎教育機構(K-小學)
|
|
|
+ // break;
|
|
|
+ // case "2": //中等教育機構
|
|
|
+ // unitTypeF = "2"; // => 中等教育機構(國中、高中/職)
|
|
|
+ // break;
|
|
|
+
|
|
|
+ // case "3": //高等教育機構
|
|
|
+ // unitTypeF = "3"; // => 高等教育機構(大學、研究所)
|
|
|
+ // break;
|
|
|
+ // case "4": //政府單位機構
|
|
|
+ // case "5": //NGO機構
|
|
|
+ // case "6": //企業機構
|
|
|
+ // case "7": //其他
|
|
|
+ // case "9": //特殊教育
|
|
|
+ // unitTypeF = "4"; // => 其他
|
|
|
+ // break;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
+ // finalSchUnitTypeDic.Add(schId, unitTypeF);
|
|
|
+ //}
|
|
|
+ //結果輸出
|
|
|
+ List<string> filterSchIds = coreSchUnitTypeDic.Keys.ToList();
|
|
|
+ var schTmidLists = schTmidDic.Where(s => filterSchIds.Contains(s.Key)).Select(s => s.Value).ToList();
|
|
|
+ foreach(List<string> schTmid in schTmidLists)
|
|
|
{
|
|
|
- string tmid = item.GetProperty("id").ToString();
|
|
|
- tmids.Add(tmid);
|
|
|
+ tmids.AddRange(schTmid);
|
|
|
}
|
|
|
- return tmids;
|
|
|
+ tmids = tmids.Distinct().ToList();
|
|
|
|
|
|
+ return tmids;
|
|
|
}
|
|
|
- //取得學校所屬學校教師
|
|
|
- private async Task<List<string>> GetTmidBySchoolId(List<string> schIds)
|
|
|
+ //取得歸戶學校的TMID
|
|
|
+ private async Task<List<string>> GetTmidBySchoolId(List<string> schIds, bool hasMail = false)
|
|
|
{
|
|
|
- var cosmosClientIes = _azureCosmos.GetCosmosClient();
|
|
|
- //取得學校ID列表
|
|
|
- List<string> teacherCodes = schIds.Select(s => $"Teacher-{s}").ToList();
|
|
|
- //取得學校教師ID列表
|
|
|
+ var cosmosClientCsv2 = _azureCosmos.GetCosmosClient(name: "CoreServiceV2");
|
|
|
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)";
|
|
|
- await foreach (var item in cosmosClientIes.GetContainer(Constant.TEAMModelOS, Constant.School).GetItemQueryIteratorSql<JsonElement>(queryText: sqlTch, requestOptions: null))
|
|
|
+ string sqlEx = $"SELECT c.id, c.schoolCode, c.schoolCodeW FROM c WHERE ((ARRAY_CONTAINS({JsonSerializer.Serialize(schIds)}, c.schoolCode) OR ARRAY_CONTAINS({JsonSerializer.Serialize(schIds)}, c.schoolCodeW))) ";
|
|
|
+ if (hasMail) sqlEx += " AND (IS_DEFINED(c.mail) AND NOT IS_NULL(c.mail) AND c.mail != '')";
|
|
|
+ await foreach (var item in cosmosClientCsv2.GetContainer("Core", "ID2").GetItemQueryIteratorSql<JsonElement>(queryText: sqlEx, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"base-ex") }))
|
|
|
{
|
|
|
string tmid = item.GetProperty("id").ToString();
|
|
|
- tmids.Add(tmid);
|
|
|
+ string schoolCode = (item.TryGetProperty("schoolCode", out JsonElement _schoolCode)) ? _schoolCode.ToString() : string.Empty;
|
|
|
+ string schoolCodeW = (item.TryGetProperty("schoolCodeW", out JsonElement _schoolCodeW)) ? _schoolCodeW.ToString() : string.Empty;
|
|
|
+ string schId = (!string.IsNullOrWhiteSpace(schoolCode)) ? schoolCode : (!string.IsNullOrWhiteSpace(schoolCodeW)) ? schoolCodeW : string.Empty;
|
|
|
+ if(schIds.Contains(schId)) tmids.Add(tmid);
|
|
|
}
|
|
|
+ ////取得學校ID列表
|
|
|
+ //List<string> teacherCodes = schIds.Select(s => $"Teacher-{s}").ToList();
|
|
|
+ ////取得學校教師ID列表
|
|
|
+ //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)";
|
|
|
+ //await foreach (var item in cosmosClientIes.GetContainer(Constant.TEAMModelOS, Constant.School).GetItemQueryIteratorSql<JsonElement>(queryText: sqlTch, requestOptions: null))
|
|
|
+ //{
|
|
|
+ // string tmid = item.GetProperty("id").ToString();
|
|
|
+ // tmids.Add(tmid);
|
|
|
+ //}
|
|
|
return tmids;
|
|
|
}
|
|
|
|
|
@@ -1558,10 +1630,6 @@ namespace TEAMModelBI.Controllers.BICommon
|
|
|
NotifyData notify = new NotifyData();
|
|
|
notify.hubName = hubName;
|
|
|
notify.sender = sender;
|
|
|
-//#if DEBUG //測試模式時限制TMID帳號,正式站佈署時不生效
|
|
|
-// List<string> filterTmid = new List<string>() { "1522758684", "1595321354" };
|
|
|
-// tmIds = tmIds.Intersect(filterTmid).ToList();
|
|
|
-//#endif
|
|
|
notify.tags = tmIds.Select(s => $"{s}_{sender}").ToList();
|
|
|
notify.title = title;
|
|
|
notify.body = body;
|
|
@@ -1583,15 +1651,153 @@ namespace TEAMModelBI.Controllers.BICommon
|
|
|
return responseMessage;
|
|
|
}
|
|
|
|
|
|
- //BI訊息推送DB記入
|
|
|
- private async Task<BINotice> CrtBiNoticeData(BINotice bINotice)
|
|
|
+ private async Task CallSendMailApiAsync(string email, string subject, string title, string body, string template, string image)
|
|
|
+ {
|
|
|
+ dynamic mailVars = new ExpandoObject();
|
|
|
+ mailVars.sub = subject;
|
|
|
+ mailVars.title = title;
|
|
|
+ mailVars.body = body;
|
|
|
+ if (!string.IsNullOrWhiteSpace(image))
|
|
|
+ mailVars.image = image;
|
|
|
+ await _coreAPIHttpService.SendMail(new Dictionary<string, object> { { "to", email }, { "tid", template }, { "vars", mailVars } }, _option.Location, _configuration);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 取得訊息寄送紀錄
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="msgType"></param>
|
|
|
+ /// <param name="selType"></param>
|
|
|
+ /// <param name="theme">標題(title)</param>
|
|
|
+ /// <param name="content">內文</param>
|
|
|
+ /// <param name="source">發送源(HiTeach、IES、Sokrates、Auth、Event)</param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpPost("get-notice-history")]
|
|
|
+#if !DEBUG
|
|
|
+ [AuthToken(Roles = "admin")]
|
|
|
+#endif
|
|
|
+ public async Task<List<BINotice>> GetBINoticeHistory(JsonElement jsonElement)
|
|
|
{
|
|
|
- var cosmosClientIes = _azureCosmos.GetCosmosClient(); //IES
|
|
|
- bINotice.id = Guid.NewGuid().ToString();
|
|
|
- BINotice result = await cosmosClientIes.GetContainer(Constant.TEAMModelOS, "Common").CreateItemAsync<BINotice>(bINotice, new PartitionKey("BINotice"));
|
|
|
+ string msgType = (jsonElement.TryGetProperty("msgType", out JsonElement _msgType)) ? _msgType.ToString() : string.Empty; //發送類型 mail:郵件、notify:端外、sms:簡訊
|
|
|
+ string selType = (jsonElement.TryGetProperty("selType", out JsonElement _selType)) ? _selType.ToString() : string.Empty; //挑選方式 single:個別 multi:批次
|
|
|
+ string theme = (jsonElement.TryGetProperty("theme", out JsonElement _theme)) ? _theme.ToString() : string.Empty; //標題(title)
|
|
|
+ string content = (jsonElement.TryGetProperty("content", out JsonElement _content)) ? _content.ToString() : string.Empty; //內文
|
|
|
+ string source = (jsonElement.TryGetProperty("source", out JsonElement _source)) ? _source.ToString() : string.Empty; //发送消息来源 HiTeach、IES、Sokrates、Auth、Event
|
|
|
+ string createId = (jsonElement.TryGetProperty("createId", out JsonElement _createId)) ? _createId.ToString() : string.Empty;
|
|
|
+ Geo geo = (jsonElement.TryGetProperty("geo", out JsonElement _geo)) ? _geo.ToObject<Geo>() : null;
|
|
|
+ List<string> unitType = (jsonElement.TryGetProperty("unitType", out JsonElement _unitType)) ? _unitType.ToObject<List<string>>() : null;
|
|
|
+ List<string> school = (jsonElement.TryGetProperty("school", out JsonElement _school)) ? _school.ToObject<List<string>>() : null;
|
|
|
+ List<string> crowdIds = (jsonElement.TryGetProperty("crowdIds", out JsonElement _crowdIds)) ? _crowdIds.ToObject<List<string>>() : null; //寄送對象(tmid列表)
|
|
|
+ long sendTimeFrom = (jsonElement.TryGetProperty("sendTimeFrom", out JsonElement _sendTimeFrom)) ? _sendTimeFrom.GetInt64() : 0;
|
|
|
+ long sendTimeTo = (jsonElement.TryGetProperty("sendTimeTo", out JsonElement _sendTimeTo)) ? _sendTimeTo.GetInt64() : 0;
|
|
|
+
|
|
|
+ var cosmosClientIes = _azureCosmos.GetCosmosClient();
|
|
|
+ List<BINotice> result = new List<BINotice> ();
|
|
|
+ string sqlWhere = string.Empty;
|
|
|
+ if(!string.IsNullOrWhiteSpace(msgType))
|
|
|
+ sqlWhere += $" AND c.msgType = '{msgType}' ";
|
|
|
+ if (!string.IsNullOrWhiteSpace(selType))
|
|
|
+ sqlWhere += $" AND c.selType = '{selType}' ";
|
|
|
+ if (!string.IsNullOrWhiteSpace(theme))
|
|
|
+ sqlWhere += $" AND CONTAINS(c.theme, '{theme}') ";
|
|
|
+ if (!string.IsNullOrWhiteSpace(content))
|
|
|
+ sqlWhere += $" AND CONTAINS(c.content, '{content}') ";
|
|
|
+ if (!string.IsNullOrWhiteSpace(source))
|
|
|
+ sqlWhere += $" AND c.source = '{source}' ";
|
|
|
+ if (geo != null)
|
|
|
+ {
|
|
|
+ if(geo.type.Equals("tmid"))
|
|
|
+ sqlWhere += $" AND cs.mode = 'tmidGeo' ";
|
|
|
+ else if(geo.type.Equals("school"))
|
|
|
+ sqlWhere += $" AND cs.mode = 'schGeo' ";
|
|
|
+ if (!string.IsNullOrWhiteSpace(geo.countryId))
|
|
|
+ sqlWhere += $" AND cs.countryId = '{geo.countryId}' ";
|
|
|
+ if (!string.IsNullOrWhiteSpace(geo.provinceId))
|
|
|
+ sqlWhere += $" AND cs.provinceId = '{geo.provinceId}' ";
|
|
|
+ if (!string.IsNullOrWhiteSpace(geo.cityId))
|
|
|
+ sqlWhere += $" AND cs.cityId = '{geo.cityId}' ";
|
|
|
+ if (!string.IsNullOrWhiteSpace(geo.distId))
|
|
|
+ sqlWhere += $" AND cs.distId = '{geo.distId}' ";
|
|
|
+ }
|
|
|
+ if (school != null && school.Count > 0)
|
|
|
+ sqlWhere += $" AND ARRAY_CONTAINS({JsonSerializer.Serialize(school)}, cs.school) ";
|
|
|
+ if (crowdIds != null && crowdIds.Count > 0)
|
|
|
+ sqlWhere += $" AND EXISTS( SELECT VALUE 1 FROM crowdId IN c.crowdIds WHERE ARRAY_CONTAINS({JsonSerializer.Serialize(crowdIds)}, crowdId) ) ";
|
|
|
+ if (unitType != null && unitType.Count > 0)
|
|
|
+ sqlWhere += $" AND ARRAY_CONTAINS({JsonSerializer.Serialize(unitType)}, cs.unitType) ";
|
|
|
+ if (sendTimeFrom > 0)
|
|
|
+ sqlWhere += $" AND c.sendTime >= {sendTimeFrom} ";
|
|
|
+ if (sendTimeTo > 0)
|
|
|
+ sqlWhere += $" AND c.sendTime <= {sendTimeTo} ";
|
|
|
+ string sql = $"SELECT c.msgType, c.selType, c.hubName, c.subject, c.template, c.search, c.data, c.type, c.theme, c.content, c.crowd, c.crowdIds, c.createId, c.sendTime, c.createTime, c.source FROM c JOIN cs IN c.search WHERE 1=1 {sqlWhere}";
|
|
|
+ await foreach (var item in cosmosClientIes.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIteratorSql<BINotice>(queryText: sql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"BINotice") }))
|
|
|
+ {
|
|
|
+ result.Add(item);
|
|
|
+ }
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ //將訊息寄送轉換為訊息寄送DB紀錄架構
|
|
|
+ private BINotice TransMsgRequestToBINotice(string msgType, string method, string subject, string title, string body, string sender, string hubName, SendMessageParam target, List<string> tmids, string data)
|
|
|
+ {
|
|
|
+ List<PickParam> searchParams = new List<PickParam>();
|
|
|
+ ///學區
|
|
|
+ if (target.area.Count > 0)
|
|
|
+ {
|
|
|
+ foreach (string areaId in target.area)
|
|
|
+ {
|
|
|
+ searchParams.Add(new PickParam() { mode = "area", areaId = areaId });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ///地理資訊
|
|
|
+ if (target.geo.Count > 0)
|
|
|
+ {
|
|
|
+ foreach (Geo geo in target.geo)
|
|
|
+ {
|
|
|
+ PickParam pickParam = new PickParam() { mode = (geo.type.Equals("tmid")) ? "tmidGeo" : "schGeo" };
|
|
|
+ if (!string.IsNullOrWhiteSpace(geo.countryId)) pickParam.countryId = geo.countryId;
|
|
|
+ if (!string.IsNullOrWhiteSpace(geo.provinceId)) pickParam.provinceId = geo.provinceId;
|
|
|
+ if (!string.IsNullOrWhiteSpace(geo.cityId)) pickParam.cityId = geo.cityId;
|
|
|
+ if (!string.IsNullOrWhiteSpace(geo.distId)) pickParam.distId = geo.distId;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ///教育機構
|
|
|
+ if (target.unit.Count > 0)
|
|
|
+ {
|
|
|
+ foreach (string unitType in target.unit)
|
|
|
+ {
|
|
|
+ searchParams.Add(new PickParam() { mode = "unit", unitType = unitType });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ///學校
|
|
|
+ if (target.school.Count > 0)
|
|
|
+ {
|
|
|
+ foreach (string schId in target.school)
|
|
|
+ {
|
|
|
+ searchParams.Add(new PickParam() { mode = "school", school = schId });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ///TMID
|
|
|
+ if (target.tmid.Count > 0)
|
|
|
+ {
|
|
|
+ searchParams.Add(new PickParam() { mode = "tmid", tmId = target.tmid });
|
|
|
+ }
|
|
|
+ BINotice bINotice = new BINotice()
|
|
|
+ {
|
|
|
+ msgType = msgType,
|
|
|
+ selType = method,
|
|
|
+ search = searchParams,
|
|
|
+ crowdIds = tmids,
|
|
|
+ theme = title,
|
|
|
+ content = body,
|
|
|
+ subject = subject,
|
|
|
+ createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
|
|
|
+ source = sender,
|
|
|
+ hubName = hubName,
|
|
|
+ data = data
|
|
|
+ };
|
|
|
+ return bINotice;
|
|
|
+ }
|
|
|
+
|
|
|
private string GetDictionaryKeyByValue(Dictionary<string, string> dic, string value)
|
|
|
{
|
|
|
string result = string.Empty;
|