|
@@ -0,0 +1,131 @@
|
|
|
+using Microsoft.IdentityModel.Tokens;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Drawing.Drawing2D;
|
|
|
+using System.IdentityModel.Tokens.Jwt;
|
|
|
+using System.IO;
|
|
|
+using System.Text;
|
|
|
+using System.Text.Json;
|
|
|
+using TEAMModelOS.SDK.Extension;
|
|
|
+using TEAMModelOS.SDK.Models.Cosmos.BI;
|
|
|
+
|
|
|
+namespace TEAMModelBI.Models.Extension
|
|
|
+{
|
|
|
+ public static class GeoRegion
|
|
|
+ {
|
|
|
+ //取得國省市區地理資料架構
|
|
|
+ public static regiondata GetRegionData()
|
|
|
+ {
|
|
|
+ regiondata region = new regiondata();
|
|
|
+ //國際
|
|
|
+ var regionTw = new List<regionrow>();
|
|
|
+ using (StreamReader r = new StreamReader("JsonFile/Region/region_gl.json"))
|
|
|
+ {
|
|
|
+ string json = r.ReadToEnd();
|
|
|
+ regionTw = JsonSerializer.Deserialize<List<regionrow>>(json);
|
|
|
+ foreach (regionrow itemcy in regionTw)
|
|
|
+ {
|
|
|
+ //country
|
|
|
+ string countryCode = itemcy.code;
|
|
|
+ if (!region.country.ContainsKey(countryCode))
|
|
|
+ {
|
|
|
+ region.country.Add(countryCode, new regionbase() { code = countryCode, name = itemcy.name });
|
|
|
+ }
|
|
|
+ //province 無
|
|
|
+ //city
|
|
|
+ if (itemcy.children != null)
|
|
|
+ {
|
|
|
+ foreach (JsonElement itemcyChild in itemcy.children)
|
|
|
+ {
|
|
|
+ regionrow itemct = itemcyChild.ToObject<regionrow>();
|
|
|
+ string provinceCode = "tw"; //台灣的省代碼用"tw"
|
|
|
+ string cityCode = itemct.code;
|
|
|
+ if (!region.city.ContainsKey(countryCode)) region.city.Add(countryCode, new Dictionary<string, Dictionary<string, regionbase>>());
|
|
|
+ if (!region.city[countryCode].ContainsKey(provinceCode)) region.city[countryCode].Add(provinceCode, new Dictionary<string, regionbase>());
|
|
|
+ if (!region.city[countryCode][provinceCode].ContainsKey(cityCode)) region.city[countryCode][provinceCode].Add(cityCode, new regionbase() { code = cityCode, name = itemct.name });
|
|
|
+ //dist
|
|
|
+ if (itemct.children != null)
|
|
|
+ {
|
|
|
+ foreach (JsonElement itemctChild in itemct.children)
|
|
|
+ {
|
|
|
+ regionrow itemds = itemctChild.ToObject<regionrow>();
|
|
|
+ string distCode = itemds.code;
|
|
|
+ if (!region.dist.ContainsKey(countryCode)) region.dist.Add(countryCode, new Dictionary<string, Dictionary<string, Dictionary<string, regionbase>>>());
|
|
|
+ if (!region.dist[countryCode].ContainsKey(provinceCode)) region.dist[countryCode].Add(provinceCode, new Dictionary<string, Dictionary<string, regionbase>>());
|
|
|
+ if (!region.dist[countryCode][provinceCode].ContainsKey(cityCode)) region.dist[countryCode][provinceCode].Add(cityCode, new Dictionary<string, regionbase>());
|
|
|
+ if (!region.dist[countryCode][provinceCode][cityCode].ContainsKey(distCode)) region.dist[countryCode][provinceCode][cityCode].Add(distCode, new regionbase() { code = distCode, name = itemds.name });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //大陸
|
|
|
+ var regionCn = new List<regionrow>();
|
|
|
+ using (StreamReader r = new StreamReader("JsonFile/Region/region_cn.json"))
|
|
|
+ {
|
|
|
+ string json = r.ReadToEnd();
|
|
|
+ regionCn = JsonSerializer.Deserialize<List<regionrow>>(json);
|
|
|
+ //country
|
|
|
+ string countryCode = "CN";
|
|
|
+ string countryName = "中国";
|
|
|
+ if (!region.country.ContainsKey(countryCode))
|
|
|
+ {
|
|
|
+ region.country.Add(countryCode, new regionbase() { code = countryCode, name = countryName });
|
|
|
+ }
|
|
|
+ //province
|
|
|
+ foreach (regionrow itempv in regionCn)
|
|
|
+ {
|
|
|
+ string provinceCode = itempv.code.Replace("0000", "");
|
|
|
+ if (!region.province.ContainsKey(countryCode)) region.province.Add(countryCode, new Dictionary<string, regionbase>());
|
|
|
+ if (!region.province[countryCode].ContainsKey(provinceCode)) region.province[countryCode].Add(provinceCode, new regionbase() { code = provinceCode, name = itempv.name });
|
|
|
+ //city
|
|
|
+ if (itempv.children != null)
|
|
|
+ {
|
|
|
+ foreach (JsonElement itempvChild in itempv.children)
|
|
|
+ {
|
|
|
+ regionrow itemct = itempvChild.ToObject<regionrow>();
|
|
|
+ string cityCode = itemct.code;
|
|
|
+ if (!region.city.ContainsKey(countryCode)) region.city.Add(countryCode, new Dictionary<string, Dictionary<string, regionbase>>());
|
|
|
+ if (!region.city[countryCode].ContainsKey(provinceCode)) region.city[countryCode].Add(provinceCode, new Dictionary<string, regionbase>());
|
|
|
+ if (!region.city[countryCode][provinceCode].ContainsKey(cityCode)) region.city[countryCode][provinceCode].Add(cityCode, new regionbase() { code = cityCode, name = itemct.name });
|
|
|
+ //dist
|
|
|
+ if (itemct.children != null)
|
|
|
+ {
|
|
|
+ foreach (JsonElement itemctChild in itemct.children)
|
|
|
+ {
|
|
|
+ regionrow itemds = itemctChild.ToObject<regionrow>();
|
|
|
+ string distCode = itemds.code;
|
|
|
+ if (!region.dist.ContainsKey(countryCode)) region.dist.Add(countryCode, new Dictionary<string, Dictionary<string, Dictionary<string, regionbase>>>());
|
|
|
+ if (!region.dist[countryCode].ContainsKey(provinceCode)) region.dist[countryCode].Add(provinceCode, new Dictionary<string, Dictionary<string, regionbase>>());
|
|
|
+ if (!region.dist[countryCode][provinceCode].ContainsKey(cityCode)) region.dist[countryCode][provinceCode].Add(cityCode, new Dictionary<string, regionbase>());
|
|
|
+ if (!region.dist[countryCode][provinceCode][cityCode].ContainsKey(distCode)) region.dist[countryCode][provinceCode][cityCode].Add(distCode, new regionbase() { code = distCode, name = itemds.name });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return region;
|
|
|
+ }
|
|
|
+
|
|
|
+ public class regiondata
|
|
|
+ {
|
|
|
+ public Dictionary<string, regionbase> country { get; set; } = new();
|
|
|
+ public Dictionary<string, Dictionary<string, regionbase>> province { get; set; } = new();
|
|
|
+ public Dictionary<string, Dictionary<string, Dictionary<string, regionbase>>> city { get; set; } = new();
|
|
|
+ public Dictionary<string, Dictionary<string, Dictionary<string, Dictionary<string, regionbase>>>> dist { get; set; } = new();
|
|
|
+ }
|
|
|
+ public class regionbase
|
|
|
+ {
|
|
|
+ public string code { get; set; } //代碼
|
|
|
+ public string name { get; set; } //名稱
|
|
|
+ }
|
|
|
+ public class regionrow : regionbase
|
|
|
+ {
|
|
|
+ public List<object> children { get; set; }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+}
|