|
@@ -38,6 +38,8 @@ using System.Text.RegularExpressions;
|
|
using MathNet.Numerics.Distributions;
|
|
using MathNet.Numerics.Distributions;
|
|
using System.Drawing.Drawing2D;
|
|
using System.Drawing.Drawing2D;
|
|
using Microsoft.Azure.Amqp.Framing;
|
|
using Microsoft.Azure.Amqp.Framing;
|
|
|
|
+using System.Data.SqlTypes;
|
|
|
|
+using System.Xml.Linq;
|
|
|
|
|
|
|
|
|
|
namespace TEAMModelBI.Controllers.BICommon
|
|
namespace TEAMModelBI.Controllers.BICommon
|
|
@@ -915,8 +917,10 @@ namespace TEAMModelBI.Controllers.BICommon
|
|
{
|
|
{
|
|
var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
var cosmosClientCsv2 = _azureCosmos.GetCosmosClient(name: "CoreServiceV2");
|
|
var cosmosClientCsv2 = _azureCosmos.GetCosmosClient(name: "CoreServiceV2");
|
|
|
|
+ var cosmosClientCsv2Cn = _azureCosmos.GetCosmosClient(name: "CoreServiceV2CnRead");
|
|
bool isChina = (_option.Location.Contains("China")) ? true : false;
|
|
bool isChina = (_option.Location.Contains("China")) ? true : false;
|
|
if (isChina) countryId = "CN";
|
|
if (isChina) countryId = "CN";
|
|
|
|
+ List<TmidInfo> tmidExInfos = new List<TmidInfo>(); //TMID資訊
|
|
List<AreaInfo> geoInfos = new(); //輸出:地理位置為單位
|
|
List<AreaInfo> geoInfos = new(); //輸出:地理位置為單位
|
|
List<AreaInfo> tmidInfos = new(); //輸出:TMID為單位
|
|
List<AreaInfo> tmidInfos = new(); //輸出:TMID為單位
|
|
regiondata regionData = GetRegionData(); //取得國省市區地理資訊架構
|
|
regiondata regionData = GetRegionData(); //取得國省市區地理資訊架構
|
|
@@ -927,172 +931,415 @@ namespace TEAMModelBI.Controllers.BICommon
|
|
string provinceName = string.Empty;
|
|
string provinceName = string.Empty;
|
|
string cityName = string.Empty;
|
|
string cityName = string.Empty;
|
|
string distName = string.Empty;
|
|
string distName = string.Empty;
|
|
-
|
|
|
|
- //取得搜尋的國省市名稱
|
|
|
|
- ///國字典製作
|
|
|
|
- if (string.IsNullOrWhiteSpace(countryId))
|
|
|
|
- {
|
|
|
|
- geoIdNameDic = new Dictionary<string, string>();
|
|
|
|
- foreach (KeyValuePair<string, regionbase> item in regionData.country)
|
|
|
|
- {
|
|
|
|
- geoIdNameDic.Add(item.Value.code, item.Value.name);
|
|
|
|
- }
|
|
|
|
- geoCountryIdNameDicEn = new Dictionary<string, string>();
|
|
|
|
- foreach (KeyValuePair<string, regionbase> item in regionDataEn.country)
|
|
|
|
- {
|
|
|
|
- geoCountryIdNameDicEn.Add(item.Value.code, item.Value.name);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- countryName = (regionData.country.ContainsKey(countryId)) ? regionData.country[countryId].name : string.Empty;
|
|
|
|
- }
|
|
|
|
- ///省字典製作
|
|
|
|
- if (!isChina)
|
|
|
|
|
|
+ string sqlWhere = string.Empty;
|
|
|
|
+ string groupKey = "country";
|
|
|
|
+ if (type.Equals("tmid"))
|
|
{
|
|
{
|
|
- provinceId = string.Empty;
|
|
|
|
- if (countryId.Equals("TW"))
|
|
|
|
|
|
+ //取得ID資訊
|
|
|
|
+ sqlWhere = $" (NOT IS_NULL(c.country) AND c.country != '') ";
|
|
|
|
+ ///國
|
|
|
|
+ if (!string.IsNullOrWhiteSpace(countryId))
|
|
{
|
|
{
|
|
- geoIdNameDic = new Dictionary<string, string>();
|
|
|
|
- foreach (KeyValuePair<string, regionbase> item in regionData.city[countryId][countryId.ToLower()])
|
|
|
|
- {
|
|
|
|
- geoIdNameDic.Add(item.Value.code, item.Value.name);
|
|
|
|
- }
|
|
|
|
|
|
+ groupKey = (!isChina) ? "city" : "province";
|
|
|
|
+ sqlWhere += $" AND c.country = '{countryId}' ";
|
|
}
|
|
}
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- geoIdNameDic = new Dictionary<string, string>();
|
|
|
|
- foreach (KeyValuePair<string, regionbase> item in regionData.province[countryId])
|
|
|
|
|
|
+ ///省
|
|
|
|
+ if (!string.IsNullOrWhiteSpace(provinceId))
|
|
{
|
|
{
|
|
- geoIdNameDic.Add(item.Value.code, item.Value.name);
|
|
|
|
|
|
+ groupKey = "city";
|
|
|
|
+ sqlWhere += $" AND c.province = '{provinceId}' ";
|
|
}
|
|
}
|
|
- }
|
|
|
|
- ///市字典製作
|
|
|
|
- if (regionData.province.ContainsKey(countryId) && !string.IsNullOrWhiteSpace(provinceId))
|
|
|
|
- {
|
|
|
|
- provinceName = (regionData.province[countryId].ContainsKey(provinceId)) ? regionData.province[countryId][provinceId].name : string.Empty;
|
|
|
|
- geoIdNameDic = new Dictionary<string, string>();
|
|
|
|
- foreach (KeyValuePair<string, regionbase> item in regionData.city[countryId][provinceId])
|
|
|
|
|
|
+ ///市
|
|
|
|
+ if (!string.IsNullOrWhiteSpace(cityId))
|
|
{
|
|
{
|
|
- geoIdNameDic.Add(item.Value.code, item.Value.name);
|
|
|
|
|
|
+ groupKey = "name";
|
|
|
|
+ sqlWhere += $" AND c.city = '{cityId}' ";
|
|
}
|
|
}
|
|
- }
|
|
|
|
- ///校 or TMID
|
|
|
|
- if (!isChina)
|
|
|
|
- {
|
|
|
|
- if (regionData.city.ContainsKey(countryId))
|
|
|
|
|
|
+ if (!string.IsNullOrWhiteSpace(sqlWhere))
|
|
{
|
|
{
|
|
- if (countryId.ToLower().Equals("tw"))
|
|
|
|
|
|
+ string sqlTmidEx = $"SELECT * FROM c WHERE {sqlWhere}";
|
|
|
|
+ await foreach (var item in cosmosClientCsv2.GetContainer("Core", "ID2").GetItemQueryIteratorSql<JsonElement>(queryText: sqlTmidEx, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"base-ex") }))
|
|
{
|
|
{
|
|
- if (!string.IsNullOrWhiteSpace(cityId) && regionData.city[countryId][countryId.ToLower()].ContainsKey(cityId))
|
|
|
|
|
|
+ TmidInfo tmidExInfoTmp = item.ToObject<TmidInfo>();
|
|
|
|
+ //地理位置名稱
|
|
|
|
+ ///國
|
|
|
|
+ if(!string.IsNullOrWhiteSpace(tmidExInfoTmp.country))
|
|
{
|
|
{
|
|
- cityName = regionData.city[countryId][countryId.ToLower()][cityId].name;
|
|
|
|
|
|
+ var countryInfo = regionData.country.FirstOrDefault(c => c.Key.Equals(tmidExInfoTmp.country));
|
|
|
|
+ if (!countryInfo.Equals(default(KeyValuePair<string, regionbase>)))
|
|
|
|
+ {
|
|
|
|
+ tmidExInfoTmp.countryName = countryInfo.Value.name;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ ///省
|
|
|
|
+ if (!string.IsNullOrWhiteSpace(tmidExInfoTmp.province) && regionData.province.ContainsKey(tmidExInfoTmp.country))
|
|
|
|
+ {
|
|
|
|
+ var provinceDic = regionData.province[tmidExInfoTmp.country];
|
|
|
|
+ var provinceInfo = provinceDic.FirstOrDefault(p => p.Key.Equals(tmidExInfoTmp.province));
|
|
|
|
+ if (!provinceInfo.Equals(default(KeyValuePair<string, regionbase>)))
|
|
|
|
+ {
|
|
|
|
+ tmidExInfoTmp.provinceName = provinceInfo.Value.name;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ ///市
|
|
|
|
+ if (!string.IsNullOrWhiteSpace(tmidExInfoTmp.city) && regionData.city.ContainsKey(tmidExInfoTmp.country))
|
|
|
|
+ {
|
|
|
|
+ if (regionData.city[tmidExInfoTmp.country].ContainsKey("tw"))
|
|
|
|
+ {
|
|
|
|
+ var cityDic = regionData.city[tmidExInfoTmp.country]["tw"];
|
|
|
|
+ var cityInfo = cityDic.FirstOrDefault(c => c.Key.Equals(tmidExInfoTmp.country));
|
|
|
|
+ if (!cityInfo.Equals(default(KeyValuePair<string, regionbase>)))
|
|
|
|
+ {
|
|
|
|
+ tmidExInfoTmp.cityName = cityInfo.Value.name;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else if(!string.IsNullOrWhiteSpace(tmidExInfoTmp.province) && regionData.city[tmidExInfoTmp.country].ContainsKey(tmidExInfoTmp.province))
|
|
|
|
+ {
|
|
|
|
+ var cityDic = regionData.city[tmidExInfoTmp.country][tmidExInfoTmp.province];
|
|
|
|
+ var cityInfo = cityDic.FirstOrDefault(c => c.Key.Equals(tmidExInfoTmp.country));
|
|
|
|
+ if (!cityInfo.Equals(default(KeyValuePair<string, regionbase>)))
|
|
|
|
+ {
|
|
|
|
+ tmidExInfoTmp.cityName = cityInfo.Value.name;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+ tmidExInfos.Add(tmidExInfoTmp);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- if (regionData.city.ContainsKey(countryId) &&
|
|
|
|
- !string.IsNullOrWhiteSpace(provinceId) && regionData.city[countryId].ContainsKey(provinceId) &&
|
|
|
|
- !string.IsNullOrWhiteSpace(cityId) && regionData.city[countryId][provinceId].ContainsKey(cityId)
|
|
|
|
- )
|
|
|
|
- {
|
|
|
|
- cityName = regionData.city[countryId][provinceId][cityId].name;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- //SQL文製作
|
|
|
|
- string groupKey = "country";
|
|
|
|
- string countryKeyName = (type.Equals("tmid")) ? "c.country" : "c.region";
|
|
|
|
- string sqlWhere = $" (NOT IS_NULL({countryKeyName}) AND {countryKeyName} != '') ";
|
|
|
|
- ///國
|
|
|
|
- if (!string.IsNullOrWhiteSpace(countryId))
|
|
|
|
- {
|
|
|
|
- groupKey = (!isChina) ? "city" : "province";
|
|
|
|
- }
|
|
|
|
- if (type.Equals("tmid"))
|
|
|
|
- {
|
|
|
|
- if (!string.IsNullOrWhiteSpace(countryId))
|
|
|
|
|
|
+ //輸出項整理
|
|
|
|
+ foreach (TmidInfo tmidInfo in tmidExInfos)
|
|
{
|
|
{
|
|
- string tmpSql = $" {countryKeyName} = '{countryId}' ";
|
|
|
|
- if (!string.IsNullOrWhiteSpace(countryName))
|
|
|
|
|
|
+ ///tmidInfos
|
|
|
|
+ AreaInfo tmidInfoRow = new AreaInfo() { id = tmidInfo.id, name = tmidInfo.name };
|
|
|
|
+ tmidInfos.Add(tmidInfoRow);
|
|
|
|
+ ///geoInfos
|
|
|
|
+ string geoId = tmidInfo.country;
|
|
|
|
+ string geoName = tmidInfo.countryName;
|
|
|
|
+ switch (groupKey)
|
|
{
|
|
{
|
|
- comeRemoveStr.ForEach(c => { countryName = countryName.Replace(c, ""); });
|
|
|
|
- tmpSql += $" OR CONTAINS({countryKeyName}, '{countryName}') ";
|
|
|
|
|
|
+ case "province":
|
|
|
|
+ geoId = tmidInfo.province;
|
|
|
|
+ geoName = tmidInfo.provinceName;
|
|
|
|
+ if (geoName.Equals("荆州市")) geoName = "荆州市"; //例外處理
|
|
|
|
+ else comeRemoveStr.ForEach(c => { geoName = geoName.Replace(c, ""); }); //常規處理
|
|
|
|
+ break;
|
|
|
|
+ case "city":
|
|
|
|
+ geoId = tmidInfo.city;
|
|
|
|
+ geoName = tmidInfo.cityName;
|
|
|
|
+ if (geoName.Equals("荆州市")) geoName = "荆州市"; //例外處理
|
|
|
|
+ else comeRemoveStr.ForEach(c => { geoName = geoName.Replace(c, ""); }); //常規處理
|
|
|
|
+ break;
|
|
|
|
+ case "name":
|
|
|
|
+ geoId = tmidInfo.schoolCode;
|
|
|
|
+ if (string.IsNullOrWhiteSpace(geoId)) geoId = tmidInfo.schoolCodeW;
|
|
|
|
+ geoName = string.Empty;
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
- if (!string.IsNullOrWhiteSpace(sqlWhere)) sqlWhere += $" AND";
|
|
|
|
- sqlWhere += $" ({tmpSql}) ";
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- if (!string.IsNullOrWhiteSpace(countryName))
|
|
|
|
- {
|
|
|
|
- if (!string.IsNullOrWhiteSpace(sqlWhere)) sqlWhere += $" AND";
|
|
|
|
- comeRemoveStr.ForEach(c => { countryName = countryName.Replace(c, ""); });
|
|
|
|
- sqlWhere += $" CONTAINS({countryKeyName}, '{countryName}') ";
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- ///省
|
|
|
|
- if (!string.IsNullOrWhiteSpace(provinceId))
|
|
|
|
- {
|
|
|
|
- groupKey = "city";
|
|
|
|
- }
|
|
|
|
- if (type.Equals("tmid"))
|
|
|
|
- {
|
|
|
|
- if (!string.IsNullOrWhiteSpace(provinceId))
|
|
|
|
- {
|
|
|
|
- string tmpSql = $" c.province = '{provinceId}' ";
|
|
|
|
- if (!string.IsNullOrWhiteSpace(provinceName))
|
|
|
|
|
|
+ //輸出 [待做]
|
|
|
|
+ if (!string.IsNullOrWhiteSpace(geoId))
|
|
{
|
|
{
|
|
- comeRemoveStr.ForEach(c => { provinceName = provinceName.Replace(c, ""); });
|
|
|
|
- tmpSql += $" OR CONTAINS(c.province, '{provinceName}') ";
|
|
|
|
|
|
+ AreaInfo geoInfo = geoInfos.Where(g => g.id.Equals(geoId)).FirstOrDefault();
|
|
|
|
+ if (geoInfo == null)
|
|
|
|
+ {
|
|
|
|
+ AreaInfo geoInfoCrt = new AreaInfo();
|
|
|
|
+ geoInfoCrt.id = geoId;
|
|
|
|
+ geoInfoCrt.name = (_option.Location.Contains("Global")) ? "無法取得名稱" : "无法取得名称";
|
|
|
|
+ if (!string.IsNullOrWhiteSpace(geoName)) geoInfoCrt.name = geoName;
|
|
|
|
+ geoInfos.Add(geoInfoCrt);
|
|
|
|
+ geoInfo = geoInfos.Where(g => g.id.Equals(geoInfoCrt.id)).FirstOrDefault();
|
|
|
|
+ }
|
|
|
|
+ geoInfo.scCnt++;
|
|
|
|
+ List<TmidInfo> tmidInfoSelected = tmidExInfos.Where(g => g.schoolCode.Equals(schId) || g.schoolCodeW.Equals(schId)).ToList();
|
|
|
|
+ geoInfo.tchCnt += tmidInfoSelected.Count;
|
|
|
|
+ if (showList && (groupKey.Equals("country") || groupKey.Equals("province") || groupKey.Equals("city")))
|
|
|
|
+ {
|
|
|
|
+ AreaSchoolInfo sch = new AreaSchoolInfo() { id = schId, name = schName, tchCnt = tmidInfoSelected.Count };
|
|
|
|
+ geoInfo.lists.Add(sch);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- if (!string.IsNullOrWhiteSpace(sqlWhere)) sqlWhere += $" AND";
|
|
|
|
- sqlWhere += $" ({tmpSql}) ";
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- else
|
|
|
|
|
|
+ else if (type.Equals("school"))
|
|
{
|
|
{
|
|
- if (!string.IsNullOrWhiteSpace(provinceName))
|
|
|
|
|
|
+ List<string> schIds = new List<string>(); //要取得的學校ID
|
|
|
|
+ //取得ID資訊
|
|
|
|
+ sqlWhere = $" ((NOT IS_NULL(c.schoolCode) AND c.schoolCode != '') OR (NOT IS_NULL(c.schoolCodeW) AND c.schoolCodeW != ''))";
|
|
|
|
+ if (!string.IsNullOrWhiteSpace(sqlWhere))
|
|
{
|
|
{
|
|
- if (!string.IsNullOrWhiteSpace(sqlWhere)) sqlWhere += $" AND";
|
|
|
|
- comeRemoveStr.ForEach(c => { provinceName = provinceName.Replace(c, ""); });
|
|
|
|
- sqlWhere += $" CONTAINS(c.province, '{provinceName}') ";
|
|
|
|
|
|
+ string sqlTmidEx = $"SELECT * FROM c WHERE {sqlWhere}";
|
|
|
|
+ await foreach (var item in cosmosClientCsv2.GetContainer("Core", "ID2").GetItemQueryIteratorSql<JsonElement>(queryText: sqlTmidEx, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"base-ex") }))
|
|
|
|
+ {
|
|
|
|
+ TmidInfo tmidEx = item.ToObject<TmidInfo>();
|
|
|
|
+ tmidExInfos.Add(tmidEx);
|
|
|
|
+ if(!string.IsNullOrWhiteSpace(tmidEx.schoolCode) && !schIds.Contains(tmidEx.schoolCode))
|
|
|
|
+ {
|
|
|
|
+ schIds.Add(tmidEx.schoolCode);
|
|
|
|
+ }
|
|
|
|
+ if (!string.IsNullOrWhiteSpace(tmidEx.schoolCodeW) && !schIds.Contains(tmidEx.schoolCodeW))
|
|
|
|
+ {
|
|
|
|
+ schIds.Add(tmidEx.schoolCode);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- }
|
|
|
|
-
|
|
|
|
- ///市
|
|
|
|
- if (!string.IsNullOrWhiteSpace(cityId))
|
|
|
|
- {
|
|
|
|
- groupKey = "name";
|
|
|
|
- }
|
|
|
|
- if (type.Equals("tmid"))
|
|
|
|
- {
|
|
|
|
- if (!string.IsNullOrWhiteSpace(cityId))
|
|
|
|
|
|
+ //取得學校資訊
|
|
|
|
+ if(schIds.Count > 0)
|
|
{
|
|
{
|
|
- string tmpSql = (!isChina) ? $" c.province = '{cityId}' " : $" c.city = '{cityId}' ";
|
|
|
|
- if (!string.IsNullOrWhiteSpace(cityName))
|
|
|
|
|
|
+ sqlWhere = $" (NOT IS_NULL(c.countryId) AND c.countryId != '') ";
|
|
|
|
+ ///國
|
|
|
|
+ if (!string.IsNullOrWhiteSpace(countryId))
|
|
|
|
+ {
|
|
|
|
+ groupKey = (!isChina) ? "city" : "province";
|
|
|
|
+ sqlWhere += $" AND c.countryId = '{countryId}' ";
|
|
|
|
+ }
|
|
|
|
+ ///省
|
|
|
|
+ if (!string.IsNullOrWhiteSpace(provinceId))
|
|
{
|
|
{
|
|
- comeRemoveStr.ForEach(c => { cityName = cityName.Replace(c, ""); });
|
|
|
|
- tmpSql += (!isChina) ? $" OR CONTAINS(c.province, '{cityName}') " : $" OR CONTAINS(c.city, '{cityName}') ";
|
|
|
|
|
|
+ groupKey = "city";
|
|
|
|
+ sqlWhere += $" AND c.provinceId = '{provinceId}' ";
|
|
|
|
+ }
|
|
|
|
+ ///市
|
|
|
|
+ if (!string.IsNullOrWhiteSpace(cityId))
|
|
|
|
+ {
|
|
|
|
+ groupKey = "name";
|
|
|
|
+ sqlWhere += $" AND c.cityId = '{cityId}' ";
|
|
|
|
+ }
|
|
|
|
+ sqlWhere += $" AND ARRAY_CONTAINS({JsonSerializer.Serialize(schIds)}, c.shortCode)";
|
|
|
|
+ string sqlSch = $"SELECT c.id, c.code, c.shortCode, c.name, c.countryId, c.countryName, c.provinceId, c.provinceName, c.cityId, c.cityName, c.distId, c.distName FROM c WHERE {sqlWhere} ";
|
|
|
|
+ await foreach (var item in cosmosClientCsv2Cn.GetContainer("Core", "School").GetItemQueryIteratorSql<JsonElement>(queryText: sqlSch, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"base") }))
|
|
|
|
+ {
|
|
|
|
+ string schId = item.GetProperty("id").ToString();
|
|
|
|
+ string schName = item.GetProperty("name").ToString();
|
|
|
|
+ string geoId = Convert.ToString(item.GetProperty("countryId"));
|
|
|
|
+ string geoName = Convert.ToString(item.GetProperty("countryName"));
|
|
|
|
+ switch (groupKey)
|
|
|
|
+ {
|
|
|
|
+ case "province":
|
|
|
|
+ geoId = Convert.ToString(item.GetProperty("provinceId"));
|
|
|
|
+ geoName = Convert.ToString(item.GetProperty("provinceName"));
|
|
|
|
+ if (geoName.Equals("荆州市")) geoName = "荆州市"; //例外處理
|
|
|
|
+ else comeRemoveStr.ForEach(c => { geoName = geoName.Replace(c, ""); }); //常規處理
|
|
|
|
+ break;
|
|
|
|
+ case "city":
|
|
|
|
+ geoId = Convert.ToString(item.GetProperty("cityId"));
|
|
|
|
+ geoName = Convert.ToString(item.GetProperty("cityName"));
|
|
|
|
+ if (geoName.Equals("荆州市")) geoName = "荆州市"; //例外處理
|
|
|
|
+ else comeRemoveStr.ForEach(c => { geoName = geoName.Replace(c, ""); }); //常規處理
|
|
|
|
+ break;
|
|
|
|
+ case "name":
|
|
|
|
+ geoId = Convert.ToString(item.GetProperty("shortCode"));
|
|
|
|
+ geoName = Convert.ToString(item.GetProperty("name"));
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ //輸出
|
|
|
|
+ if (!string.IsNullOrWhiteSpace(geoId))
|
|
|
|
+ {
|
|
|
|
+ AreaInfo geoInfo = geoInfos.Where(g => g.id.Equals(geoId)).FirstOrDefault();
|
|
|
|
+ if (geoInfo == null)
|
|
|
|
+ {
|
|
|
|
+ AreaInfo geoInfoCrt = new AreaInfo();
|
|
|
|
+ geoInfoCrt.id = geoId;
|
|
|
|
+ geoInfoCrt.name = (_option.Location.Contains("Global")) ? "無法取得名稱" : "无法取得名称";
|
|
|
|
+ if(!string.IsNullOrWhiteSpace(geoName)) geoInfoCrt.name = geoName;
|
|
|
|
+ geoInfos.Add(geoInfoCrt);
|
|
|
|
+ geoInfo = geoInfos.Where(g => g.id.Equals(geoInfoCrt.id)).FirstOrDefault();
|
|
|
|
+ }
|
|
|
|
+ geoInfo.scCnt++;
|
|
|
|
+ List<TmidInfo> tmidInfoSelected = tmidExInfos.Where(g => g.schoolCode.Equals(schId) || g.schoolCodeW.Equals(schId)).ToList();
|
|
|
|
+ geoInfo.tchCnt += tmidInfoSelected.Count;
|
|
|
|
+ if (showList && (groupKey.Equals("country") || groupKey.Equals("province") || groupKey.Equals("city")))
|
|
|
|
+ {
|
|
|
|
+ AreaSchoolInfo sch = new AreaSchoolInfo() { id = schId, name = schName, tchCnt = tmidInfoSelected.Count };
|
|
|
|
+ geoInfo.lists.Add(sch);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- if (!string.IsNullOrWhiteSpace(sqlWhere)) sqlWhere += $" AND";
|
|
|
|
- sqlWhere += $" ({tmpSql}) ";
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ //輸出
|
|
|
|
+ if (output.Equals("tmid"))
|
|
|
|
+ {
|
|
|
|
+ return (tmidInfos, groupKey);
|
|
|
|
+ }
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- if (!string.IsNullOrWhiteSpace(cityName))
|
|
|
|
- {
|
|
|
|
- if (!string.IsNullOrWhiteSpace(sqlWhere)) sqlWhere += $" AND";
|
|
|
|
- comeRemoveStr.ForEach(c => { cityName = cityName.Replace(c, ""); });
|
|
|
|
- sqlWhere += $" CONTAINS(c.city, '{cityName}') ";
|
|
|
|
- }
|
|
|
|
|
|
+ return (geoInfos, groupKey);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ //取得搜尋的國省市名稱
|
|
|
|
+ ///國字典製作
|
|
|
|
+ //if (string.IsNullOrWhiteSpace(countryId))
|
|
|
|
+ //{
|
|
|
|
+ // geoIdNameDic = new Dictionary<string, string>();
|
|
|
|
+ // foreach (KeyValuePair<string, regionbase> item in regionData.country)
|
|
|
|
+ // {
|
|
|
|
+ // geoIdNameDic.Add(item.Value.code, item.Value.name);
|
|
|
|
+ // }
|
|
|
|
+ // geoCountryIdNameDicEn = new Dictionary<string, string>();
|
|
|
|
+ // foreach (KeyValuePair<string, regionbase> item in regionDataEn.country)
|
|
|
|
+ // {
|
|
|
|
+ // geoCountryIdNameDicEn.Add(item.Value.code, item.Value.name);
|
|
|
|
+ // }
|
|
|
|
+ //}
|
|
|
|
+ //else
|
|
|
|
+ //{
|
|
|
|
+ // countryName = (regionData.country.ContainsKey(countryId)) ? regionData.country[countryId].name : string.Empty;
|
|
|
|
+ //}
|
|
|
|
+ ///省字典製作
|
|
|
|
+ //if (!isChina)
|
|
|
|
+ //{
|
|
|
|
+ // provinceId = string.Empty;
|
|
|
|
+ // if (countryId.Equals("TW"))
|
|
|
|
+ // {
|
|
|
|
+ // geoIdNameDic = new Dictionary<string, string>();
|
|
|
|
+ // foreach (KeyValuePair<string, regionbase> item in regionData.city[countryId][countryId.ToLower()])
|
|
|
|
+ // {
|
|
|
|
+ // geoIdNameDic.Add(item.Value.code, item.Value.name);
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+ //}
|
|
|
|
+ //else
|
|
|
|
+ //{
|
|
|
|
+ // geoIdNameDic = new Dictionary<string, string>();
|
|
|
|
+ // foreach (KeyValuePair<string, regionbase> item in regionData.province[countryId])
|
|
|
|
+ // {
|
|
|
|
+ // geoIdNameDic.Add(item.Value.code, item.Value.name);
|
|
|
|
+ // }
|
|
|
|
+ //}
|
|
|
|
+ ///市字典製作
|
|
|
|
+ //if (regionData.province.ContainsKey(countryId) && !string.IsNullOrWhiteSpace(provinceId))
|
|
|
|
+ //{
|
|
|
|
+ // provinceName = (regionData.province[countryId].ContainsKey(provinceId)) ? regionData.province[countryId][provinceId].name : string.Empty;
|
|
|
|
+ // geoIdNameDic = new Dictionary<string, string>();
|
|
|
|
+ // foreach (KeyValuePair<string, regionbase> item in regionData.city[countryId][provinceId])
|
|
|
|
+ // {
|
|
|
|
+ // geoIdNameDic.Add(item.Value.code, item.Value.name);
|
|
|
|
+ // }
|
|
|
|
+ //}
|
|
|
|
+ ///校 or TMID
|
|
|
|
+ //if (!isChina)
|
|
|
|
+ //{
|
|
|
|
+ // if (regionData.city.ContainsKey(countryId))
|
|
|
|
+ // {
|
|
|
|
+ // if (countryId.ToLower().Equals("tw"))
|
|
|
|
+ // {
|
|
|
|
+ // if (!string.IsNullOrWhiteSpace(cityId) && regionData.city[countryId][countryId.ToLower()].ContainsKey(cityId))
|
|
|
|
+ // {
|
|
|
|
+ // cityName = regionData.city[countryId][countryId.ToLower()][cityId].name;
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+ //}
|
|
|
|
+ //else
|
|
|
|
+ //{
|
|
|
|
+ // if (regionData.city.ContainsKey(countryId) &&
|
|
|
|
+ // !string.IsNullOrWhiteSpace(provinceId) && regionData.city[countryId].ContainsKey(provinceId) &&
|
|
|
|
+ // !string.IsNullOrWhiteSpace(cityId) && regionData.city[countryId][provinceId].ContainsKey(cityId)
|
|
|
|
+ // )
|
|
|
|
+ // {
|
|
|
|
+ // cityName = regionData.city[countryId][provinceId][cityId].name;
|
|
|
|
+ // }
|
|
|
|
+ //}
|
|
|
|
+ //SQL文製作
|
|
|
|
+ //string groupKey = "country";
|
|
|
|
+ //string countryKeyName = (type.Equals("tmid")) ? "c.country" : "c.region";
|
|
|
|
+ //string sqlWhere = $" (NOT IS_NULL({countryKeyName}) AND {countryKeyName} != '') ";
|
|
|
|
+ ///國
|
|
|
|
+ //if (!string.IsNullOrWhiteSpace(countryId))
|
|
|
|
+ //{
|
|
|
|
+ // groupKey = (!isChina) ? "city" : "province";
|
|
|
|
+ //}
|
|
|
|
+ //if (type.Equals("tmid"))
|
|
|
|
+ //{
|
|
|
|
+ // if (!string.IsNullOrWhiteSpace(countryId))
|
|
|
|
+ // {
|
|
|
|
+ // string tmpSql = $" {countryKeyName} = '{countryId}' ";
|
|
|
|
+ // if (!string.IsNullOrWhiteSpace(countryName))
|
|
|
|
+ // {
|
|
|
|
+ // comeRemoveStr.ForEach(c => { countryName = countryName.Replace(c, ""); });
|
|
|
|
+ // tmpSql += $" OR CONTAINS({countryKeyName}, '{countryName}') ";
|
|
|
|
+ // }
|
|
|
|
+ // if (!string.IsNullOrWhiteSpace(sqlWhere)) sqlWhere += $" AND";
|
|
|
|
+ // sqlWhere += $" ({tmpSql}) ";
|
|
|
|
+ // }
|
|
|
|
+ //}
|
|
|
|
+ //else
|
|
|
|
+ //{
|
|
|
|
+ // if (!string.IsNullOrWhiteSpace(countryName))
|
|
|
|
+ // {
|
|
|
|
+ // if (!string.IsNullOrWhiteSpace(sqlWhere)) sqlWhere += $" AND";
|
|
|
|
+ // comeRemoveStr.ForEach(c => { countryName = countryName.Replace(c, ""); });
|
|
|
|
+ // sqlWhere += $" CONTAINS({countryKeyName}, '{countryName}') ";
|
|
|
|
+ // }
|
|
|
|
+ //}
|
|
|
|
+
|
|
|
|
+ ///省
|
|
|
|
+ //if (!string.IsNullOrWhiteSpace(provinceId))
|
|
|
|
+ //{
|
|
|
|
+ // groupKey = "city";
|
|
|
|
+ //}
|
|
|
|
+ //if (type.Equals("tmid"))
|
|
|
|
+ //{
|
|
|
|
+ // if (!string.IsNullOrWhiteSpace(provinceId))
|
|
|
|
+ // {
|
|
|
|
+ // string tmpSql = $" c.province = '{provinceId}' ";
|
|
|
|
+ // if (!string.IsNullOrWhiteSpace(provinceName))
|
|
|
|
+ // {
|
|
|
|
+ // comeRemoveStr.ForEach(c => { provinceName = provinceName.Replace(c, ""); });
|
|
|
|
+ // tmpSql += $" OR CONTAINS(c.province, '{provinceName}') ";
|
|
|
|
+ // }
|
|
|
|
+ // if (!string.IsNullOrWhiteSpace(sqlWhere)) sqlWhere += $" AND";
|
|
|
|
+ // sqlWhere += $" ({tmpSql}) ";
|
|
|
|
+ // }
|
|
|
|
+ //}
|
|
|
|
+ //else
|
|
|
|
+ //{
|
|
|
|
+ // if (!string.IsNullOrWhiteSpace(provinceName))
|
|
|
|
+ // {
|
|
|
|
+ // if (!string.IsNullOrWhiteSpace(sqlWhere)) sqlWhere += $" AND";
|
|
|
|
+ // comeRemoveStr.ForEach(c => { provinceName = provinceName.Replace(c, ""); });
|
|
|
|
+ // sqlWhere += $" CONTAINS(c.province, '{provinceName}') ";
|
|
|
|
+ // }
|
|
|
|
+ //}
|
|
|
|
+
|
|
|
|
+ ///市
|
|
|
|
+ //if (!string.IsNullOrWhiteSpace(cityId))
|
|
|
|
+ //{
|
|
|
|
+ // groupKey = "name";
|
|
|
|
+ //}
|
|
|
|
+ //if (type.Equals("tmid"))
|
|
|
|
+ //{
|
|
|
|
+ // if (!string.IsNullOrWhiteSpace(cityId))
|
|
|
|
+ // {
|
|
|
|
+ // string tmpSql = (!isChina) ? $" c.province = '{cityId}' " : $" c.city = '{cityId}' ";
|
|
|
|
+ // if (!string.IsNullOrWhiteSpace(cityName))
|
|
|
|
+ // {
|
|
|
|
+ // comeRemoveStr.ForEach(c => { cityName = cityName.Replace(c, ""); });
|
|
|
|
+ // tmpSql += (!isChina) ? $" OR CONTAINS(c.province, '{cityName}') " : $" OR CONTAINS(c.city, '{cityName}') ";
|
|
|
|
+ // }
|
|
|
|
+ // if (!string.IsNullOrWhiteSpace(sqlWhere)) sqlWhere += $" AND";
|
|
|
|
+ // sqlWhere += $" ({tmpSql}) ";
|
|
|
|
+ // }
|
|
|
|
+ //}
|
|
|
|
+ //else
|
|
|
|
+ //{
|
|
|
|
+ // if (!string.IsNullOrWhiteSpace(cityName))
|
|
|
|
+ // {
|
|
|
|
+ // if (!string.IsNullOrWhiteSpace(sqlWhere)) sqlWhere += $" AND";
|
|
|
|
+ // comeRemoveStr.ForEach(c => { cityName = cityName.Replace(c, ""); });
|
|
|
|
+ // sqlWhere += $" CONTAINS(c.city, '{cityName}') ";
|
|
|
|
+ // }
|
|
|
|
+ //}
|
|
|
|
+
|
|
//結果取得
|
|
//結果取得
|
|
///TMID類型
|
|
///TMID類型
|
|
if (type.Equals("tmid"))
|
|
if (type.Equals("tmid"))
|
|
@@ -1183,9 +1430,10 @@ namespace TEAMModelBI.Controllers.BICommon
|
|
{
|
|
{
|
|
//取得學校ID列表
|
|
//取得學校ID列表
|
|
sqlWhere = $" WHERE {sqlWhere}";
|
|
sqlWhere = $" WHERE {sqlWhere}";
|
|
- string sqlSch = $"SELECT c.id, c.name, c.region as country, c.province, c.city, c.dist FROM c {sqlWhere} ";
|
|
|
|
|
|
+ string sqlSch = $"SELECT c.id, c.code, c.shortCode, c.name, c.region as country, c.province, c.city, c.dist FROM c {sqlWhere} ";
|
|
|
|
+
|
|
///實體校
|
|
///實體校
|
|
- await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, Constant.School).GetItemQueryIteratorSql<JsonElement>(queryText: sqlSch, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Base") }))
|
|
|
|
|
|
+ await foreach (var item in cosmosClientCsv2Cn.GetContainer("Core", "School").GetItemQueryIteratorSql<JsonElement>(queryText: sqlSch, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"base") }))
|
|
{
|
|
{
|
|
string schId = item.GetProperty("id").ToString();
|
|
string schId = item.GetProperty("id").ToString();
|
|
string schName = item.GetProperty("name").ToString();
|
|
string schName = item.GetProperty("name").ToString();
|
|
@@ -1977,6 +2225,27 @@ namespace TEAMModelBI.Controllers.BICommon
|
|
else return tw;
|
|
else return tw;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// TMID基本進階資訊(base-ex)
|
|
|
|
+ /// </summary>
|
|
|
|
+ private class TmidInfo
|
|
|
|
+ {
|
|
|
|
+ public string id { get; set; }
|
|
|
|
+ public string name { get; set; }
|
|
|
|
+ public string mobile { get; set; }
|
|
|
|
+ public string mail { get; set; }
|
|
|
|
+ public string countryCode { get; set; }
|
|
|
|
+ public string country { get; set; }
|
|
|
|
+ public string countryName { get; set; }
|
|
|
|
+ public string province { get; set; }
|
|
|
|
+ public string provinceName { get; set; }
|
|
|
|
+ public string city { get; set; }
|
|
|
|
+ public string cityName { get; set; }
|
|
|
|
+ public string dist { get; set; }
|
|
|
|
+ public string distName { get; set; }
|
|
|
|
+ public string schoolCode { get; set; }
|
|
|
|
+ public string schoolCodeW { get; set; }
|
|
|
|
+ }
|
|
/// <summary>
|
|
/// <summary>
|
|
/// 學區、地理位置、機構類型 回傳信息
|
|
/// 學區、地理位置、機構類型 回傳信息
|
|
/// </summary>
|
|
/// </summary>
|