Эх сурвалжийг харах

🤓增加导入导出方法及其他优化

zuohuaijun 2 жил өмнө
parent
commit
fd945b9c85

+ 1 - 1
Admin.NET/Admin.NET.Application/Configuration/Database.json

@@ -6,7 +6,7 @@
         "ConnectionConfigs": [
             {
                 "DbType": "Sqlite", // MySql、SqlServer、Sqlite、Oracle、PostgreSQL、Dm、Kdbndp、Oscar、MySqlConnector、Access、OpenGauss、QuestDB、HG、ClickHouse、GBase、Odbc、Custom
-                "ConnectionString": "DataSource=./Admin.NET.db", // 库连接字符串
+                "ConnectionString": "DataSource=./db/Admin.NET.db", // 库连接字符串
                 "EnableInitDb": true, // 启用库表初始化
                 "EnableInitSeed": true, // 启用种子初始化
                 "EnableDiffLog": false, // 启用库表差异日志

+ 1 - 2
Admin.NET/Admin.NET.Core/SqlSugar/SqlSugarSetup.cs

@@ -264,8 +264,7 @@ public static class SqlSugarSetup
             if (tAtt != null && tAtt.configId.ToString() != config.ConfigId) continue;
             if (tAtt == null && config.ConfigId != SqlSugarConst.ConfigId) continue;
 
-            var splitTable = entityType.GetCustomAttribute<SplitTableAttribute>();
-            if (splitTable == null)
+            if (entityType.GetCustomAttribute<SplitTableAttribute>() == null)
                 dbProvider.CodeFirst.InitTables(entityType);
             else
                 dbProvider.CodeFirst.SplitTables().InitTables(entityType);

+ 41 - 0
Admin.NET/Admin.NET.Core/Util/CommonUtil.cs

@@ -7,6 +7,8 @@
 // 软件按“原样”提供,不提供任何形式的明示或暗示的保证,包括但不限于对适销性、适用性和非侵权的保证。
 // 在任何情况下,作者或版权持有人均不对任何索赔、损害或其他责任负责,无论是因合同、侵权或其他方式引起的,与软件或其使用或其他交易有关。
 
+using Magicodes.ExporterAndImporter.Core;
+using Magicodes.ExporterAndImporter.Excel;
 using System.Xml;
 using System.Xml.Linq;
 using System.Xml.Serialization;
@@ -90,4 +92,43 @@ public static class CommonUtil
             return null;
         }
     }
+
+    /// <summary>
+    /// 导出模板Excel
+    /// </summary>
+    /// <param name="fileName"></param>
+    /// <param name="fileDto"></param>
+    /// <returns></returns>
+    public static async Task<IActionResult> ExportExcelTemplate(string fileName, dynamic fileDto)
+    {
+        fileName = $"{fileName}_{DateTime.Now.ToString("yyyyMMddHHmmss")}.xlsx";
+
+        IImporter importer = new ExcelImporter();
+        MethodInfo generateTemplateMethod = typeof(ExcelImporter).GetMethod("GenerateTemplate");
+        MethodInfo closedGenerateTemplateMethod = generateTemplateMethod.MakeGenericMethod(fileDto.GetType());
+        var res = await (Task<dynamic>)closedGenerateTemplateMethod.Invoke(importer, new object[] { Path.Combine(App.WebHostEnvironment.WebRootPath, fileName) });
+
+        return new FileStreamResult(new FileStream(res.FileName, FileMode.Open), "application/octet-stream") { FileDownloadName = fileName };
+    }
+
+    /// <summary>
+    /// 导入数据Excel
+    /// </summary>
+    /// <param name="file"></param>
+    /// <param name="dataDto"></param>
+    /// <returns></returns>
+    public static async Task<dynamic> ImportExcelData([Required] IFormFile file, dynamic dataDto)
+    {
+        var newFile = await App.GetRequiredService<SysFileService>().UploadFile(file, "");
+        var filePath = Path.Combine(App.WebHostEnvironment.WebRootPath, newFile.FilePath, newFile.Name);
+
+        IImporter importer = new ExcelImporter();
+        MethodInfo importMethod = typeof(ExcelImporter).GetMethod("Import");
+        MethodInfo closedImportMethod = importMethod.MakeGenericMethod(dataDto.GetType());
+        var res = await (Task<dynamic>)closedImportMethod.Invoke(importer, new object[] { filePath });
+        if (res == null || res.Exception != null)
+            throw Oops.Oh("导入异常:" + res.Exception);
+
+        return res.Data;
+    }
 }

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

@@ -17,7 +17,7 @@
   </ItemGroup>
 
   <ItemGroup>
-    <ProjectReference Include="..\Admin.NET.Application\Admin.NET.Application.csproj" />
+    <ProjectReference Include="..\..\..\项目列表\酒店管理\Code\Admin.NET\Daming.Hotel.Application\Daming.Hotel.Application.csproj" />
     <ProjectReference Include="..\Admin.NET.Core\Admin.NET.Core.csproj" />
   </ItemGroup>
 

+ 1 - 1
Web/src/layout/main/defaults.vue

@@ -42,7 +42,7 @@ const initScrollBarHeight = () => {
 		setTimeout(() => {
 			updateScrollbar();
 			layoutScrollbarRef.value.wrapRef.scrollTop = 0;
-			layoutMainRef.value!.layoutMainScrollbarRef.wrapRef.scrollTop = 0;
+			if (layoutMainRef.value != undefined) layoutMainRef.value.layoutMainScrollbarRef.wrapRef.scrollTop = 0;
 		}, 500);
 	});
 };