Переглянути джерело

😎增加记录经纬度

zuohuaijun 2 роки тому
батько
коміт
78dd7848e3

+ 1 - 0
Admin.NET/Admin.NET.Core/Admin.NET.Core.csproj

@@ -25,6 +25,7 @@
     <PackageReference Include="Furion.Extras.ObjectMapper.Mapster" Version="4.9.2.7" />
     <PackageReference Include="Furion.Pure" Version="4.9.2.7" />
     <PackageReference Include="IPTools.China" Version="1.6.0" />
+    <PackageReference Include="IPTools.International" Version="1.6.0" />
     <PackageReference Include="Lazy.Captcha.Core" Version="2.0.6" />
     <PackageReference Include="Magicodes.IE.Excel" Version="2.7.5.1" />
     <PackageReference Include="Magicodes.IE.Pdf" Version="2.7.5.1" />

+ 2 - 2
Admin.NET/Admin.NET.Core/Logging/DatabaseLoggingWriter.cs

@@ -186,9 +186,9 @@ public class DatabaseLoggingWriter : IDatabaseLoggingWriter, IDisposable
     {
         try
         {
-            var ipInfo = IpTool.Search(ip);
+            var ipInfo = IpTool.SearchWithI18N(ip); // 国际化查询,默认中文 中文zh-CN、英文en
             var addressList = new List<string>() { ipInfo.Country, ipInfo.Province, ipInfo.City, ipInfo.NetworkOperator };
-            return (string.Join("|", addressList.Where(it => it != "0").ToList()), ipInfo.Longitude, ipInfo.Latitude); // 去掉0并用|连接
+            return (string.Join(" ", addressList.Where(u => u != "0" && !string.IsNullOrWhiteSpace(u)).ToList()), ipInfo.Longitude, ipInfo.Latitude); // 去掉0及空并用空格连接
         }
         catch
         {

+ 86 - 89
Admin.NET/Admin.NET.Core/Service/Region/SysRegionService.cs

@@ -6,9 +6,6 @@
 //
 // 任何基于本项目二次开发而产生的一切法律纠纷和责任,均与作者无关
 
-using AngleSharp;
-using AngleSharp.Html.Dom;
-
 namespace Admin.NET.Core.Service;
 
 /// <summary>
@@ -151,91 +148,91 @@ public class SysRegionService : IDynamicApiController, ITransient
     {
         await _sysRegionRep.DeleteAsync(u => u.Id > 0);
 
-        var context = BrowsingContext.New(AngleSharp.Configuration.Default.WithDefaultLoader());
-        var dom = await context.OpenAsync(_url);
-
-        // 省级
-        var itemList = dom.QuerySelectorAll("table.provincetable tr.provincetr td a");
-        foreach (IHtmlAnchorElement item in itemList)
-        {
-            var region = await _sysRegionRep.InsertReturnEntityAsync(new SysRegion
-            {
-                Pid = 0,
-                Name = item.TextContent,
-                Remark = item.Href,
-                Level = 1,
-            });
-
-            // 市级
-            if (string.IsNullOrEmpty(item.Href))
-                continue;
-            var dom1 = await context.OpenAsync(item.Href);
-            var itemList1 = dom1.QuerySelectorAll("table.citytable tr.citytr td a");
-            for (var i1 = 0; i1 < itemList1.Length; i1 += 2)
-            {
-                var item1 = (IHtmlAnchorElement)itemList1[i1 + 1];
-                var region1 = await _sysRegionRep.InsertReturnEntityAsync(new SysRegion
-                {
-                    Pid = region.Id,
-                    Name = item1.TextContent,
-                    Code = itemList1[i1].TextContent,
-                    Remark = item1.Href,
-                    Level = 2,
-                });
-
-                // 区县级
-                if (string.IsNullOrEmpty(item1.Href))
-                    continue;
-                var dom2 = await context.OpenAsync(item1.Href);
-                var itemList2 = dom2.QuerySelectorAll("table.countytable tr.countytr td a");
-                for (var i2 = 0; i2 < itemList2.Length; i2 += 2)
-                {
-                    var item2 = (IHtmlAnchorElement)itemList2[i2 + 1];
-                    var region2 = await _sysRegionRep.InsertReturnEntityAsync(new SysRegion
-                    {
-                        Pid = region1.Id,
-                        Name = item2.TextContent,
-                        Code = itemList2[i2].TextContent,
-                        Remark = item2.Href,
-                        Level = 3,
-                    });
-
-                    // 街道级
-                    if (string.IsNullOrEmpty(item2.Href))
-                        continue;
-                    var dom3 = await context.OpenAsync(item2.Href);
-                    var itemList3 = dom3.QuerySelectorAll("table.towntable tr.towntr td a");
-                    for (var i3 = 0; i3 < itemList3.Length; i3 += 2)
-                    {
-                        var item3 = (IHtmlAnchorElement)itemList3[i3 + 1];
-                        var region3 = await _sysRegionRep.InsertReturnEntityAsync(new SysRegion
-                        {
-                            Pid = region2.Id,
-                            Name = item3.TextContent,
-                            Code = itemList3[i3].TextContent,
-                            Remark = item3.Href,
-                            Level = 4,
-                        });
-
-                        // 村级
-                        if (string.IsNullOrEmpty(item3.Href))
-                            continue;
-                        var dom4 = await context.OpenAsync(item3.Href);
-                        var itemList4 = dom4.QuerySelectorAll("table.villagetable tr.villagetr td");
-                        for (var i4 = 0; i4 < itemList4.Length; i4 += 3)
-                        {
-                            await _sysRegionRep.InsertAsync(new SysRegion
-                            {
-                                Pid = region3.Id,
-                                Name = itemList4[i4 + 2].TextContent,
-                                Code = itemList4[i4].TextContent,
-                                CityCode = itemList4[i4 + 1].TextContent,
-                                Level = 5,
-                            });
-                        }
-                    }
-                }
-            }
-        }
+        //var context = BrowsingContext.New(AngleSharp.Configuration.Default.WithDefaultLoader());
+        //var dom = await context.OpenAsync(_url);
+
+        //// 省级
+        //var itemList = dom.QuerySelectorAll("table.provincetable tr.provincetr td a");
+        //foreach (IHtmlAnchorElement item in itemList)
+        //{
+        //    var region = await _sysRegionRep.InsertReturnEntityAsync(new SysRegion
+        //    {
+        //        Pid = 0,
+        //        Name = item.TextContent,
+        //        Remark = item.Href,
+        //        Level = 1,
+        //    });
+
+        //    // 市级
+        //    if (string.IsNullOrEmpty(item.Href))
+        //        continue;
+        //    var dom1 = await context.OpenAsync(item.Href);
+        //    var itemList1 = dom1.QuerySelectorAll("table.citytable tr.citytr td a");
+        //    for (var i1 = 0; i1 < itemList1.Length; i1 += 2)
+        //    {
+        //        var item1 = (IHtmlAnchorElement)itemList1[i1 + 1];
+        //        var region1 = await _sysRegionRep.InsertReturnEntityAsync(new SysRegion
+        //        {
+        //            Pid = region.Id,
+        //            Name = item1.TextContent,
+        //            Code = itemList1[i1].TextContent,
+        //            Remark = item1.Href,
+        //            Level = 2,
+        //        });
+
+        //        // 区县级
+        //        if (string.IsNullOrEmpty(item1.Href))
+        //            continue;
+        //        var dom2 = await context.OpenAsync(item1.Href);
+        //        var itemList2 = dom2.QuerySelectorAll("table.countytable tr.countytr td a");
+        //        for (var i2 = 0; i2 < itemList2.Length; i2 += 2)
+        //        {
+        //            var item2 = (IHtmlAnchorElement)itemList2[i2 + 1];
+        //            var region2 = await _sysRegionRep.InsertReturnEntityAsync(new SysRegion
+        //            {
+        //                Pid = region1.Id,
+        //                Name = item2.TextContent,
+        //                Code = itemList2[i2].TextContent,
+        //                Remark = item2.Href,
+        //                Level = 3,
+        //            });
+
+        //            // 街道级
+        //            if (string.IsNullOrEmpty(item2.Href))
+        //                continue;
+        //            var dom3 = await context.OpenAsync(item2.Href);
+        //            var itemList3 = dom3.QuerySelectorAll("table.towntable tr.towntr td a");
+        //            for (var i3 = 0; i3 < itemList3.Length; i3 += 2)
+        //            {
+        //                var item3 = (IHtmlAnchorElement)itemList3[i3 + 1];
+        //                var region3 = await _sysRegionRep.InsertReturnEntityAsync(new SysRegion
+        //                {
+        //                    Pid = region2.Id,
+        //                    Name = item3.TextContent,
+        //                    Code = itemList3[i3].TextContent,
+        //                    Remark = item3.Href,
+        //                    Level = 4,
+        //                });
+
+        //                // 村级
+        //                if (string.IsNullOrEmpty(item3.Href))
+        //                    continue;
+        //                var dom4 = await context.OpenAsync(item3.Href);
+        //                var itemList4 = dom4.QuerySelectorAll("table.villagetable tr.villagetr td");
+        //                for (var i4 = 0; i4 < itemList4.Length; i4 += 3)
+        //                {
+        //                    await _sysRegionRep.InsertAsync(new SysRegion
+        //                    {
+        //                        Pid = region3.Id,
+        //                        Name = itemList4[i4 + 2].TextContent,
+        //                        Code = itemList4[i4].TextContent,
+        //                        CityCode = itemList4[i4 + 1].TextContent,
+        //                        Level = 5,
+        //                    });
+        //                }
+        //            }
+        //        }
+        //    }
+        //}
     }
 }

+ 7 - 0
Admin.NET/Admin.NET.Web.Core/Startup.cs

@@ -13,6 +13,7 @@ using Furion;
 using Furion.SpecificationDocument;
 using Furion.VirtualFileServer;
 using IGeekFan.AspNetCore.Knife4jUI;
+using IPTools.Core;
 using Microsoft.AspNetCore.Builder;
 using Microsoft.AspNetCore.Hosting;
 using Microsoft.AspNetCore.HttpOverrides;
@@ -163,6 +164,12 @@ public class Startup : AppStartup
 
         // 控制台logo
         services.AddConsoleLogo();
+
+        // 将IP地址数据库文件完全加载到内存,提升查询速度(以空间换时间,内存将会增加60-70M)
+        IpToolSettings.LoadInternationalDbToMemory = true;
+        // 设置默认查询器China和International
+        //IpToolSettings.DefalutSearcherType = IpSearcherType.China;
+        IpToolSettings.DefalutSearcherType = IpSearcherType.International;
     }
 
     public void Configure(IApplicationBuilder app, IWebHostEnvironment env)

+ 3 - 0
Admin.NET/Admin.NET.Web.Entry/Admin.NET.Web.Entry.csproj

@@ -77,6 +77,9 @@
 	</ItemGroup>
 
 	<ItemGroup>
+	  <None Update="GeoLite2-City.mmdb">
+	    <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+	  </None>
 	  <None Update="ip2region.db">
 	    <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
 	  </None>

BIN
Admin.NET/Admin.NET.Web.Entry/GeoLite2-City.mmdb


+ 3 - 1
Web/src/views/system/log/exlog/index.vue

@@ -47,6 +47,8 @@
 				<el-table-column prop="realName" label="真实姓名" width="100" align="center" show-overflow-tooltip />
 				<el-table-column prop="remoteIp" label="IP地址" width="120" align="center" show-overflow-tooltip />
 				<el-table-column prop="location" label="登录地点" width="150" align="center" show-overflow-tooltip />
+				<el-table-column prop="longitude" label="经度" min-width="100" align="center" show-overflow-tooltip />
+				<el-table-column prop="latitude" label="纬度" min-width="100" align="center" show-overflow-tooltip />
 				<el-table-column prop="browser" label="浏览器" width="160" align="center" show-overflow-tooltip />
 				<el-table-column prop="os" label="操作系统" width="120" align="center" show-overflow-tooltip />
 				<el-table-column prop="status" label="状态" width="70" align="center" show-overflow-tooltip>
@@ -77,7 +79,7 @@
 				layout="total, sizes, prev, pager, next, jumper"
 			/>
 		</el-card>
-		<el-dialog v-model="state.dialogVisible" draggable width="1000px">
+		<el-dialog v-model="state.dialogVisible" draggable fullscreen>
 			<template #header>
 				<div style="color: #fff">
 					<el-icon size="16" style="margin-right: 3px; display: inline; vertical-align: middle"> <ele-Document /> </el-icon>

+ 4 - 2
Web/src/views/system/log/oplog/index.vue

@@ -46,7 +46,9 @@
 				<el-table-column prop="account" label="账号名称" width="100" align="center" show-overflow-tooltip />
 				<el-table-column prop="realName" label="真实姓名" width="100" align="center" show-overflow-tooltip />
 				<el-table-column prop="remoteIp" label="IP地址" min-width="120" align="center" show-overflow-tooltip />
-				<el-table-column prop="location" label="登录地点" min-width="120" align="center" show-overflow-tooltip />
+				<el-table-column prop="location" label="登录地点" min-width="150" align="center" show-overflow-tooltip />
+				<el-table-column prop="longitude" label="经度" min-width="100" align="center" show-overflow-tooltip />
+				<el-table-column prop="latitude" label="纬度" min-width="100" align="center" show-overflow-tooltip />
 				<el-table-column prop="browser" label="浏览器" min-width="150" align="center" show-overflow-tooltip />
 				<el-table-column prop="os" label="操作系统" width="120" align="center" show-overflow-tooltip />
 				<el-table-column prop="status" label="状态" width="70" align="center" show-overflow-tooltip>
@@ -77,7 +79,7 @@
 				layout="total, sizes, prev, pager, next, jumper"
 			/>
 		</el-card>
-		<el-dialog v-model="state.dialogVisible" draggable width="1000px">
+		<el-dialog v-model="state.dialogVisible" draggable fullscreen>
 			<template #header>
 				<div style="color: #fff">
 					<el-icon size="16" style="margin-right: 3px; display: inline; vertical-align: middle"> <ele-Document /> </el-icon>

+ 3 - 1
Web/src/views/system/log/vislog/index.vue

@@ -28,7 +28,9 @@
 				<el-table-column prop="account" label="账号名称" width="100" align="center" show-overflow-tooltip />
 				<el-table-column prop="realName" label="真实姓名" width="100" align="center" show-overflow-tooltip />
 				<el-table-column prop="remoteIp" label="IP地址" min-width="120" align="center" show-overflow-tooltip />
-				<el-table-column prop="location" label="登录地点" min-width="120" align="center" show-overflow-tooltip />
+				<el-table-column prop="location" label="登录地点" min-width="150" align="center" show-overflow-tooltip />
+				<el-table-column prop="longitude" label="经度" min-width="100" align="center" show-overflow-tooltip />
+				<el-table-column prop="latitude" label="纬度" min-width="100" align="center" show-overflow-tooltip />
 				<el-table-column prop="browser" label="浏览器" min-width="150" align="center" show-overflow-tooltip />
 				<el-table-column prop="os" label="操作系统" width="120" align="center" show-overflow-tooltip />
 				<el-table-column prop="status" label="状态" width="70" align="center" show-overflow-tooltip>