|
@@ -337,7 +337,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)";
|
|
|
///實體校
|
|
@@ -346,15 +346,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") }))
|
|
@@ -362,39 +355,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)
|
|
@@ -1242,6 +1224,7 @@ namespace TEAMModelBI.Controllers.BICommon
|
|
|
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
|
|
|
//必須項檢驗
|
|
|
+ bool hasMail = false;
|
|
|
if (target == null || string.IsNullOrWhiteSpace(type) || string.IsNullOrWhiteSpace(method) || string.IsNullOrWhiteSpace(title) || string.IsNullOrWhiteSpace(body)) return BadRequest();
|
|
|
if(type.Equals("notify"))
|
|
|
{
|
|
@@ -1250,16 +1233,17 @@ namespace TEAMModelBI.Controllers.BICommon
|
|
|
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 內容例
|
|
|
//{
|
|
@@ -1295,10 +1279,10 @@ namespace TEAMModelBI.Controllers.BICommon
|
|
|
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>(); //聯集化
|
|
@@ -1308,10 +1292,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" }; //"1522758684", "1595321354"
|
|
|
-// tmids = tmids.Intersect(filterTmid).ToList();
|
|
|
-//#endif
|
|
|
+#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>();
|
|
@@ -1429,7 +1413,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列表
|
|
@@ -1441,26 +1425,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);
|
|
@@ -1468,7 +1462,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);
|
|
@@ -1479,30 +1473,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) 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) ";
|
|
|
+ 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 shortCode = (item.TryGetProperty("shortCode", out JsonElement _shortCode)) ? _shortCode.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;
|
|
|
+ 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"))
|
|
|
{
|
|
@@ -1533,85 +1538,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;
|
|
|
}
|
|
|
|