Explorar o código

[BI]發送訊息 搜尋機構TMID API修正

jeff hai 3 meses
pai
achega
c84aa90164

+ 15 - 15
TEAMModelBI/Controllers/BICommon/BINoticeController.cs

@@ -42,6 +42,7 @@ using TEAMModelOS.SDK.DI.IPIP;
 using Azure;
 using Azure;
 using Microsoft.AspNetCore.Http.HttpResults;
 using Microsoft.AspNetCore.Http.HttpResults;
 using System.Net;
 using System.Net;
+using System.Dynamic;
 
 
 
 
 namespace TEAMModelBI.Controllers.BICommon
 namespace TEAMModelBI.Controllers.BICommon
@@ -455,14 +456,14 @@ namespace TEAMModelBI.Controllers.BICommon
             //取得ID帳號中所有的歸戶學校ID
             //取得ID帳號中所有的歸戶學校ID
             List<string> coreSchIds = new List<string>();
             List<string> coreSchIds = new List<string>();
             Dictionary<string, List<string>> schTmidDic = new Dictionary<string, List<string>>(); //學校ID > TMID 字典
             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") }))
             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 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 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 (!string.IsNullOrWhiteSpace(schId))
                 {
                 {
                     if(!coreSchIds.Contains(schId)) coreSchIds.Add(schId);
                     if(!coreSchIds.Contains(schId)) coreSchIds.Add(schId);
@@ -1484,14 +1485,14 @@ namespace TEAMModelBI.Controllers.BICommon
             List<string> coreSchIds = new List<string>();
             List<string> coreSchIds = new List<string>();
             Dictionary<string, List<string>> schTmidDic = new Dictionary<string, List<string>>(); //學校ID > TMID 字典
             Dictionary<string, List<string>> schTmidDic = new Dictionary<string, List<string>>(); //學校ID > TMID 字典
             //取得有歸戶的所有TMID
             //取得有歸戶的所有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") }))
             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 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 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 (!string.IsNullOrWhiteSpace(schId))
                 {
                 {
                     if (!coreSchIds.Contains(schId)) coreSchIds.Add(schId);
                     if (!coreSchIds.Contains(schId)) coreSchIds.Add(schId);
@@ -1652,13 +1653,12 @@ namespace TEAMModelBI.Controllers.BICommon
 
 
         private async Task CallSendMailApiAsync(string email, string subject, string title, string body, string template, string image)
         private async Task CallSendMailApiAsync(string email, string subject, string title, string body, string template, string image)
         {
         {
-            object mailVars = new
-            {
-                sub = subject,
-                title = title,
-                body = body,
-                image = 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);
             await _coreAPIHttpService.SendMail(new Dictionary<string, object> { { "to", email }, { "tid", template }, { "vars", mailVars } }, _option.Location, _configuration);
         }
         }
 
 

+ 3 - 2
TEAMModelOS/Controllers/XTest/TestController.cs

@@ -2575,10 +2575,11 @@ namespace TEAMModelOS.Controllers
             string tid = "d-f1c5abd8247f4be79ceaecdd327e9a68"; //"d-f1c5abd8247f4be79ceaecdd327e9a68":國際站預設模板  //"d-833d40ac6397414b852b91e2fa45850a":活動報名成功通知模板
             string tid = "d-f1c5abd8247f4be79ceaecdd327e9a68"; //"d-f1c5abd8247f4be79ceaecdd327e9a68":國際站預設模板  //"d-833d40ac6397414b852b91e2fa45850a":活動報名成功通知模板
             string name = "Jeff";
             string name = "Jeff";
             string location = "Global";
             string location = "Global";
-            string sub = "My subject";
+            string sub = "New subject";
             string title = "HiTeach 6";
             string title = "HiTeach 6";
+            string body = "HiTeach 發布了!";
             string image = "https://corestorageservice.blob.core.windows.net/public-marketing/S__43540491.png";
             string image = "https://corestorageservice.blob.core.windows.net/public-marketing/S__43540491.png";
-            object data = new { sub = sub, title = title, image = image };
+            object data = new { sub = sub, title = title, body = body };
             await _coreAPIHttpService.SendMail(new Dictionary<string, object> { { "to", mail }, { "tid", tid }, { "vars", data } }, location, _configuration);
             await _coreAPIHttpService.SendMail(new Dictionary<string, object> { { "to", mail }, { "tid", tid }, { "vars", data } }, location, _configuration);
 
 
             return Ok();
             return Ok();