😎1、增加MiniExcel和MiniWord组件 2、清理代码
This commit is contained in:
parent
0882423486
commit
661f22b7b6
@ -30,6 +30,8 @@
|
||||
<PackageReference Include="Magicodes.IE.Word" Version="2.7.5.2" />
|
||||
<PackageReference Include="MailKit" Version="4.8.0" />
|
||||
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.4.6" />
|
||||
<PackageReference Include="MiniExcel" Version="1.34.2" />
|
||||
<PackageReference Include="MiniWord" Version="0.8.0" />
|
||||
<PackageReference Include="MQTTnet" Version="4.3.7.1207" />
|
||||
<PackageReference Include="MySqlBackup.NET.MySqlConnector" Version="2.3.8" />
|
||||
<PackageReference Include="NewLife.Redis" Version="6.0.2024.1006" />
|
||||
|
||||
@ -405,4 +405,50 @@ public static class RepositoryExtension
|
||||
}
|
||||
return updateable;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量列表in查询
|
||||
/// </summary>
|
||||
/// <typeparam name="T1"></typeparam>
|
||||
/// <typeparam name="T2"></typeparam>
|
||||
/// <param name="queryable"></param>
|
||||
/// <param name="exp"></param>
|
||||
/// <param name="queryList"></param>
|
||||
/// <param name="stoppingToken"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<List<T1>> BulkListQuery<T1, T2>(this ISugarQueryable<T1> queryable,
|
||||
Expression<Func<T1, SingleColumnEntity<T2>, bool>> exp,
|
||||
IEnumerable<T2> queryList,
|
||||
CancellationToken stoppingToken) where T1 : class, new()
|
||||
{
|
||||
// 创建临时表 (用真表兼容性好,表名随机)
|
||||
var tableName = "Temp" + SnowFlakeSingle.Instance.NextId();
|
||||
try
|
||||
{
|
||||
var type = queryable.Context.DynamicBuilder().CreateClass(tableName, new SugarTable())
|
||||
.CreateProperty("ColumnName", typeof(string), new SugarColumn() { IsPrimaryKey = true }) // 主键不要自增
|
||||
.BuilderType();
|
||||
// 创建表
|
||||
queryable.Context.CodeFirst.InitTables(type);
|
||||
var insertData = queryList.Select(it => new SingleColumnEntity<T2>() { ColumnName = it }).ToList();
|
||||
// 插入临时表
|
||||
queryable.Context.Fastest<SingleColumnEntity<T2>>()
|
||||
.AS(tableName)
|
||||
.BulkCopy(insertData);
|
||||
var queryTemp = queryable.Context.Queryable<SingleColumnEntity<T2>>()
|
||||
.AS(tableName);
|
||||
|
||||
var systemData = await queryable
|
||||
.InnerJoin(queryTemp, exp)
|
||||
.ToListAsync(stoppingToken);
|
||||
|
||||
queryable.Context.DbMaintenance.DropTable(tableName);
|
||||
return systemData;
|
||||
}
|
||||
catch (Exception error)
|
||||
{
|
||||
queryable.Context.DbMaintenance.DropTable(tableName);
|
||||
throw Oops.Oh(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
70
Admin.NET/Admin.NET.Core/Utils/MiniExcelUtil.cs
Normal file
70
Admin.NET/Admin.NET.Core/Utils/MiniExcelUtil.cs
Normal file
@ -0,0 +1,70 @@
|
||||
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
|
||||
//
|
||||
// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
|
||||
//
|
||||
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
|
||||
|
||||
using MiniExcelLibs;
|
||||
|
||||
namespace Admin.NET.Core;
|
||||
|
||||
public static class MiniExcelUtil
|
||||
{
|
||||
private const string _sheetName = "ImportTemplate";
|
||||
private const string _directory = "export";
|
||||
|
||||
/// <summary>
|
||||
/// 导出模板Excel
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static async Task<IActionResult> ExportExcelTemplate<T>(string fileName = null) where T : class, new()
|
||||
{
|
||||
var values = Array.Empty<T>();
|
||||
// 在内存中当开辟空间
|
||||
var memoryStream = new MemoryStream();
|
||||
// 将数据写到内存当中
|
||||
await memoryStream.SaveAsAsync(values, sheetName: _sheetName);
|
||||
// 从0的位置开始写入
|
||||
memoryStream.Seek(0, SeekOrigin.Begin);
|
||||
return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
|
||||
{
|
||||
FileDownloadName = $"{(string.IsNullOrEmpty(fileName) ? typeof(T).Name : fileName)}.xlsx"
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取导入数据Excel
|
||||
/// </summary>
|
||||
/// <param name="file"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<IEnumerable<T>> GetImportExcelData<T>([Required] IFormFile file) where T : class, new()
|
||||
{
|
||||
using MemoryStream stream = new MemoryStream();
|
||||
await file.CopyToAsync(stream);
|
||||
var res = await stream.QueryAsync<T>(sheetName: _sheetName);
|
||||
return res.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取导出数据excel地址
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static async Task<string> GetExportDataExcelUrl<T>(IEnumerable<T> exportData) where T : class, new()
|
||||
{
|
||||
var fileName = string.Format("{0}.xlsx", YitIdHelper.NextId());
|
||||
try
|
||||
{
|
||||
var path = Path.Combine(App.WebHostEnvironment.WebRootPath, _directory);
|
||||
if (!Directory.Exists(path))
|
||||
Directory.CreateDirectory(path);
|
||||
var filePath = Path.Combine(path, fileName);
|
||||
await MiniExcel.SaveAsAsync(filePath, exportData, overwriteFile: true);
|
||||
}
|
||||
catch (Exception error)
|
||||
{
|
||||
throw Oops.Oh("出现错误:" + error);
|
||||
}
|
||||
var host = CommonUtil.GetLocalhost();
|
||||
return $"{host}/{_directory}/{fileName}";
|
||||
}
|
||||
}
|
||||
@ -2,7 +2,7 @@
|
||||
"name": "admin.net.pro",
|
||||
"type": "module",
|
||||
"version": "2.4.33",
|
||||
"lastBuildTime": "2024.10.27",
|
||||
"lastBuildTime": "2024.10.29",
|
||||
"description": "Admin.NET 站在巨人肩膀上的 .NET 通用权限开发框架",
|
||||
"author": "zuohuaijun",
|
||||
"license": "MIT",
|
||||
|
||||
@ -127,7 +127,13 @@ import { hiprint } from 'vue-plugin-hiprint';
|
||||
import providers from './providers';
|
||||
import PrintPreview from './preview.vue';
|
||||
import printDataDefault from './print-data';
|
||||
import { IPaperType } from './type';
|
||||
// import { IPaperType } from './type';
|
||||
|
||||
interface IPaperType {
|
||||
type: string;
|
||||
width: number;
|
||||
height: number;
|
||||
}
|
||||
|
||||
var props = defineProps({
|
||||
modeIndex: {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user