瀏覽代碼

[BI]取得IOT資料時追加IP分析地理位置-架構調整:SDK移除地理位置JSON檔,改以各應用端取得地理位置資料後傳入

jeff 3 月之前
父節點
當前提交
6621eb6379

+ 14 - 1
TEAMModelBI/Controllers/BITest/TestController.cs

@@ -2061,9 +2061,22 @@ namespace TEAMModelBI.Controllers.BITest
         {
             string ip = (jsonElement.TryGetProperty("ip", out JsonElement _ip)) ? _ip.ToString() : string.Empty;
             string lang = (jsonElement.TryGetProperty("lang", out JsonElement _lang)) ? _lang.ToString() : "zh-tw";
+
+            List<regionrow> region_gl = new List<regionrow>();
+            using (StreamReader r = new StreamReader("JsonFile/Region/region_gl.json"))
+            {
+                string json_g = r.ReadToEnd();
+                region_gl = JsonSerializer.Deserialize<List<regionrow>>(json_g);
+            }
+            List<regionrow> region_cn = new List<regionrow>();
+            using (StreamReader r = new StreamReader("JsonFile/Region/region_cn.json"))
+            {
+                string json_c = r.ReadToEnd();
+                region_cn = JsonSerializer.Deserialize<List<regionrow>>(json_c);
+            }
             List<string> ipToGeoList = new List<string>();
             IotTeachingData.Geo geo = new IotTeachingData.Geo();
-            (geo, ipToGeoList) = BIProdAnalysis.getGeoFromIp(_city, ip);
+            (geo, ipToGeoList) = BIProdAnalysis.getGeoFromIp(_city, ip, region_gl, region_cn);
             return Ok(new { state = 200, geo, geoFromIp = ipToGeoList });
         }
 

+ 14 - 1
TEAMModelBI/Controllers/RepairApi/SchoolRepController.cs

@@ -28,6 +28,7 @@ using TEAMModelOS.SDK.Models.Service.BIStatsWay;
 using StackExchange.Redis;
 using System.Text.RegularExpressions;
 using TEAMModelOS.SDK.DI.IPIP;
+using static TEAMModelOS.SDK.Extension.GeoRegion;
 
 namespace TEAMModelBI.Controllers.RepairApi
 {
@@ -589,6 +590,18 @@ namespace TEAMModelBI.Controllers.RepairApi
             string month = (jsonElement.TryGetProperty("month", out JsonElement _month)) ? $"{_month}" : string.Empty;
             string day = (jsonElement.TryGetProperty("day", out JsonElement _day)) ? $"{_day}" : string.Empty;
             var redisClinet2 = _azureRedis.GetRedisClient(2);
+            List<regionrow> _region_gl = new List<regionrow>();
+            using (StreamReader r = new StreamReader("JsonFile/Region/region_gl.json"))
+            {
+                string json_g = r.ReadToEnd();
+                _region_gl = JsonSerializer.Deserialize<List<regionrow>>(json_g);
+            }
+            List<regionrow> _region_cn = new List<regionrow>();
+            using (StreamReader r = new StreamReader("JsonFile/Region/region_cn.json"))
+            {
+                string json_c = r.ReadToEnd();
+                _region_cn = JsonSerializer.Deserialize<List<regionrow>>(json_c);
+            }
             var keys = new HashSet<RedisKey>();
             int nextCursor = 0;
             do
@@ -624,7 +637,7 @@ namespace TEAMModelBI.Controllers.RepairApi
                     {
                         string m = date.Substring(0, 2);
                         string d = date.Substring(2, 2);
-                        await BIProdAnalysis.BICreatDailyAnalData(_azureRedis, _azureCosmosClient, _azureCosmosClientCsv2, _azureCosmosClientCsv2Read, _dingDing, _city, _option.Location, y, m, d);
+                        await BIProdAnalysis.BICreatDailyAnalData(_azureRedis, _azureCosmosClient, _azureCosmosClientCsv2, _azureCosmosClientCsv2Read, _dingDing, _city, _option.Location, y, m, d, _region_gl, _region_cn);
                         resultKeys.Add($"{key}");
                     }
                 }

+ 6 - 0
TEAMModelBI/TEAMModelBI.csproj

@@ -61,6 +61,12 @@
 			<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
 		</None>
 	</ItemGroup>
+	<ItemGroup>
+		<None Update="JsonFile/Region/*.json">
+			<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+			<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
+		</None>
+	</ItemGroup>
 	<PropertyGroup>
 		<SpaRoot>ClientApp\</SpaRoot>
 		<DefaultItemExcludes>$(DefaultItemExcludes);$(SpaRoot)node_modules\**</DefaultItemExcludes>

+ 15 - 1
TEAMModelOS.Function/IESTimerTrigger.cs

@@ -12,6 +12,8 @@ using TEAMModelOS.SDK.Models;
 using HTEX.Lib.ETL.Lesson;
 using System.Linq;
 using TEAMModelOS.SDK.DI.IPIP;
+using static TEAMModelOS.SDK.Extension.GeoRegion;
+using System.Text.Json;
 
 namespace TEAMModelOS.Function
 {
@@ -144,8 +146,20 @@ namespace TEAMModelOS.Function
             var m = datetime.Month >= 10 ? $"{datetime.Month}" : $"0{datetime.Month}";
             var d = datetime.Day >= 10 ? $"{datetime.Day}" : $"0{datetime.Day}";
             string? local = Environment.GetEnvironmentVariable("Option:Location");
+            List<regionrow> region_gl = new List<regionrow>();
+            using (StreamReader r = new StreamReader("JsonFile/Region/region_gl.json"))
+            {
+                string json_g = r.ReadToEnd();
+                region_gl = JsonSerializer.Deserialize<List<regionrow>>(json_g);
+            }
+            List<regionrow> region_cn = new List<regionrow>();
+            using (StreamReader r = new StreamReader("JsonFile/Region/region_cn.json"))
+            {
+                string json_c = r.ReadToEnd();
+                region_cn = JsonSerializer.Deserialize<List<regionrow>>(json_c);
+            }
             //生成學校IOT數據
-            await BIProdAnalysis.BICreatDailyAnalData(_azureRedis, _azureCosmosClient, _azureCosmosClientCsv2, _azureCosmosClientCsv2CnRead, _dingDing, _city, local, y, m, d);
+            await BIProdAnalysis.BICreatDailyAnalData(_azureRedis, _azureCosmosClient, _azureCosmosClientCsv2, _azureCosmosClientCsv2CnRead, _dingDing, _city, local, y, m, d, region_gl, region_cn);
             //刪除三個月以前的Redis數據 [待做]
         }
     }

File diff suppressed because it is too large
+ 13614 - 0
TEAMModelOS.Function/JsonFile/Region/region_cn.json


File diff suppressed because it is too large
+ 1880 - 0
TEAMModelOS.Function/JsonFile/Region/region_en.json


File diff suppressed because it is too large
+ 1896 - 0
TEAMModelOS.Function/JsonFile/Region/region_gl.json


+ 4 - 0
TEAMModelOS.Function/TEAMModelOS.Function.csproj

@@ -67,6 +67,10 @@
 	  <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
 	  <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
 	</None>
+	<None Update="JsonFile\Region\*.json">
+	  <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+	  <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
+	</None>
   </ItemGroup>
   <ItemGroup>
     <Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext" />

+ 5 - 11
TEAMModelOS.SDK/Extension/GeoRegion.cs

@@ -12,16 +12,13 @@ namespace TEAMModelOS.SDK.Extension
     public static class GeoRegion
     {
         //取得國省市區地理資料架構
-        public static regiondata GetRegionData()
+        public static regiondata GetRegionData(List<regionrow> region_gl, List<regionrow> region_cn)
         {
             regiondata region = new regiondata();
             //國際
-            var regionTw = new List<regionrow>();
-            using (StreamReader r = new StreamReader("JsonFile/Region/region_gl.json"))
+            if(region_gl.Count > 0)
             {
-                string json = r.ReadToEnd();
-                regionTw = JsonSerializer.Deserialize<List<regionrow>>(json);
-                foreach (regionrow itemcy in regionTw)
+                foreach (regionrow itemcy in region_gl)
                 {
                     //country
                     string countryCode = itemcy.code;
@@ -59,11 +56,8 @@ namespace TEAMModelOS.SDK.Extension
                 }
             }
             //大陸
-            var regionCn = new List<regionrow>();
-            using (StreamReader r = new StreamReader("JsonFile/Region/region_cn.json"))
+            if (region_cn.Count > 0)
             {
-                string json = r.ReadToEnd();
-                regionCn = JsonSerializer.Deserialize<List<regionrow>>(json);
                 //country
                 string countryCode = "CN";
                 string countryName = "中国";
@@ -72,7 +66,7 @@ namespace TEAMModelOS.SDK.Extension
                     region.country.Add(countryCode, new regionbase() { code = countryCode, name = countryName });
                 }
                 //province
-                foreach (regionrow itempv in regionCn)
+                foreach (regionrow itempv in region_cn)
                 {
                     string provinceCode = itempv.code.Replace("0000", "");
                     if (!region.province.ContainsKey(countryCode)) region.province.Add(countryCode, new Dictionary<string, regionbase>());

+ 8 - 7
TEAMModelOS.SDK/Models/Service/BI/BIProdAnalysis.cs

@@ -34,9 +34,9 @@ namespace TEAMModelOS.SDK.Models.Service.BI
         /// <param name="m">月(2位數)</param>
         /// <param name="d">日(2位數)</param>
         /// <returns></returns>
-        public static async Task BICreatDailyAnalData(AzureRedisFactory _azureRedis, CosmosClient _azureCosmosClient, CosmosClient _azureCosmosClientCsv2, CosmosClient _azureCosmosClientCsv2CnRead, DingDing _dingDing, City _city, string _location, string y, string m, string d)
+        public static async Task BICreatDailyAnalData(AzureRedisFactory _azureRedis, CosmosClient _azureCosmosClient, CosmosClient _azureCosmosClientCsv2, CosmosClient _azureCosmosClientCsv2CnRead, DingDing _dingDing, City _city, string _location, string y, string m, string d, List<regionrow> _region_gl, List<regionrow> _region_cn)
         {
-            List<IotTeachingData> IotTeachingDataList = await BIGetDailyRedisProdAnalData(_azureRedis, _azureCosmosClientCsv2, _dingDing, _city, _location, y, m, d); //取得Redis IOT 每日資訊
+            List<IotTeachingData> IotTeachingDataList = await BIGetDailyRedisProdAnalData(_azureRedis, _azureCosmosClientCsv2, _dingDing, _city, _location, y, m, d, _region_gl, _region_cn); //取得Redis IOT 每日資訊
             await CreatIes5ProdAnalData(_azureRedis, _azureCosmosClient, _azureCosmosClientCsv2CnRead, _dingDing, y, m, d, IotTeachingDataList); //生成學校CosmosDB年月日統計資料
             await CreatTmidProdAnalData(_azureRedis, _azureCosmosClient, _dingDing, y, m, d, IotTeachingDataList); //生成TMID CosmosDB年月日統計資料
             await CreatGeoProdAnalData(_azureRedis, _azureCosmosClient, _dingDing, y, m, d, IotTeachingDataList); //生成地理位置 CosmosDB年月日統計資料
@@ -51,7 +51,7 @@ namespace TEAMModelOS.SDK.Models.Service.BI
         /// <param name="m">月(2位數)</param>
         /// <param name="d">日(2位數)</param>
         /// <returns></returns>
-        public static async Task<List<IotTeachingData>> BIGetDailyRedisProdAnalData(AzureRedisFactory _azureRedis, CosmosClient _azureCosmosClientCsv2, DingDing _dingDing, City _city, string _location, string y, string m, string d)
+        public static async Task<List<IotTeachingData>> BIGetDailyRedisProdAnalData(AzureRedisFactory _azureRedis, CosmosClient _azureCosmosClientCsv2, DingDing _dingDing, City _city, string _location, string y, string m, string d, List<regionrow> _region_gl, List<regionrow> _region_cn)
         {
             List<IotTeachingData> IotTeachingDataList = new List<IotTeachingData>();
             try
@@ -118,7 +118,7 @@ namespace TEAMModelOS.SDK.Models.Service.BI
                             IotTeachingData.useTransMode = (tdata.Length > 42 && !string.IsNullOrWhiteSpace(tdata[42])) ? tdata[42] : "0"; //有使用透明模式
                             IotTeachingData.useMiniMode = (tdata.Length > 43 && !string.IsNullOrWhiteSpace(tdata[43])) ? tdata[43] : "0"; //有使用最小化模式 
                             if (!string.IsNullOrWhiteSpace(IotTeachingData.ip)) ///IP分析地理位置
-                                (IotTeachingData.geo, IotTeachingData.geoFromIp) = BIProdAnalysis.getGeoFromIp(_city, IotTeachingData.ip);
+                                (IotTeachingData.geo, IotTeachingData.geoFromIp) = BIProdAnalysis.getGeoFromIp(_city, IotTeachingData.ip, _region_gl, _region_cn);
                             IotTeachingDataList.Add(IotTeachingData);
                             if(!string.IsNullOrWhiteSpace(IotTeachingData.tmid))
                             {
@@ -1518,15 +1518,16 @@ namespace TEAMModelOS.SDK.Models.Service.BI
             }
         }
 
-        public static (Geo, List<string>) getGeoFromIp(City _city, string ip)
+        public static (Geo, List<string>) getGeoFromIp(City _city, string ip, List<regionrow> _region_gl, List<regionrow> _region_cn)
         {
             var ipInfo = _city.find(ip, "CN");
             //輸出定義
             List<string> ipToGeoList = (ipInfo != null) ? ipInfo.ToList() : new List<string>(); ///直接由IP取得的地理資訊
-            IotTeachingData.Geo geo = new IotTeachingData.Geo(); ///地理資訊
+            IotTeachingData.Geo geo = null; ///地理資訊
             if(ipInfo == null) return (geo, ipToGeoList);
+            else geo = new IotTeachingData.Geo();
             //國省市字典製作
-            regiondata regionData = GetRegionData(); //取得國省市區地理資訊架構
+            regiondata regionData = GetRegionData(_region_gl, _region_cn); //取得國省市區地理資訊架構
             List<string> comeRemoveStr = GeoRegion.comeRemoveStr;
             ///國字典製作
             var geoCountryIdNameDic = new Dictionary<string, string>();

+ 17 - 6
TEAMModelOS.SDK/Models/Service/JointService.cs

@@ -398,13 +398,24 @@ namespace TEAMModelOS.SDK.Models.Service
                                         {
                                             passGroupRow.jointExamId.Add(jointExamRow.id);
                                         }
-                                        //if (passGroupRow.jointExamId.Count.Equals(jointExamIdList.Count)) //[舊] 所有評量都完成 => pass
-                                        //{
-                                        //    passGroupRow.pass = true;
-                                        //}
-                                        if(passGroupRow.jointExamId.Count > 0) //[新] 有任一評量完成 => pass
+                                        //根據評量連動類型計算是否生成決賽評量
+                                        switch (jointEvent.examLinkType)
                                         {
-                                            passGroupRow.pass = true;
+                                            case "one": //有任一評量完成 => pass
+                                                if (passGroupRow.jointExamId.Count > 0)
+                                                {
+                                                    passGroupRow.pass = true;
+                                                }
+                                                break;
+                                            case "all": //所有評量都完成 => pass
+                                                if (passGroupRow.jointExamId.Count.Equals(jointExamIdList.Count))
+                                                {
+                                                    passGroupRow.pass = true;
+                                                }
+                                                break;
+                                            default:
+                                                passGroupRow.pass = true;
+                                                break;
                                         }
                                     }
                                 }

+ 0 - 7
TEAMModelOS.SDK/TEAMModelOS.SDK.csproj

@@ -56,11 +56,4 @@
 	<ItemGroup>
 	  <ProjectReference Include="..\TEAMModelOS.Extension\IES.Exam\IES.ExamLibrary\IES.ExamLibrary.csproj" />
 	</ItemGroup>
-	
-	<ItemGroup>
-	  <None Update="JsonFile/Region/*.json">
-		<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
-		<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
-	  </None>
-	</ItemGroup>
 </Project>