|
|
@ -5,6 +5,8 @@ using AgileObjects.AgileMapper; |
|
|
|
using Microsoft.AspNetCore.Http; |
|
|
|
using Microsoft.AspNetCore.Http; |
|
|
|
using Newtonsoft.Json; |
|
|
|
using Newtonsoft.Json; |
|
|
|
using Newtonsoft.Json.Linq; |
|
|
|
using Newtonsoft.Json.Linq; |
|
|
|
|
|
|
|
using OfficeOpenXml.Style; |
|
|
|
|
|
|
|
using OfficeOpenXml; |
|
|
|
using SqlSugar; |
|
|
|
using SqlSugar; |
|
|
|
using Tiobon.Core.Common; |
|
|
|
using Tiobon.Core.Common; |
|
|
|
using Tiobon.Core.Common.Caches; |
|
|
|
using Tiobon.Core.Common.Caches; |
|
|
@ -19,6 +21,12 @@ using Tiobon.Core.IRepository.Base; |
|
|
|
using Tiobon.Core.IServices.BASE; |
|
|
|
using Tiobon.Core.IServices.BASE; |
|
|
|
using Tiobon.Core.Model; |
|
|
|
using Tiobon.Core.Model; |
|
|
|
using Tiobon.Core.Model.Models; |
|
|
|
using Tiobon.Core.Model.Models; |
|
|
|
|
|
|
|
using SixLabors.ImageSharp; |
|
|
|
|
|
|
|
using System.Reflection; |
|
|
|
|
|
|
|
using Microsoft.EntityFrameworkCore.Metadata.Internal; |
|
|
|
|
|
|
|
using System.Collections.Generic; |
|
|
|
|
|
|
|
using System.Collections; |
|
|
|
|
|
|
|
using Amazon.Runtime.Internal.Transform; |
|
|
|
|
|
|
|
|
|
|
|
namespace Tiobon.Core.Services.BASE; |
|
|
|
namespace Tiobon.Core.Services.BASE; |
|
|
|
|
|
|
|
|
|
|
@ -788,34 +796,153 @@ public class BaseServices<TEntity, TEntityDto, TInsertDto, TEditDto> : IBaseServ |
|
|
|
return new ServicePageResult<TEntityDto>(filter.pageNum, total, filter.pageSize, entitys); |
|
|
|
return new ServicePageResult<TEntityDto>(filter.pageNum, total, filter.pageSize, entitys); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
public async Task<ServiceResult<long>> ExportExcel(QueryBody body) |
|
|
|
public async Task<ServiceResult<string>> ExportExcel(QueryExport body) |
|
|
|
{ |
|
|
|
{ |
|
|
|
//sql = @$"SELECT field, |
|
|
|
QueryBody filter = new QueryBody(); |
|
|
|
// [dbo].[FLangKeyToValue] (mkey, {body.langId}, label) |
|
|
|
filter.pageNum = 1; |
|
|
|
// label, |
|
|
|
filter.pageSize = 1000000; |
|
|
|
// required, |
|
|
|
filter.langId = body.langId; |
|
|
|
// editable, |
|
|
|
var data = await QueryFilterPage(filter); |
|
|
|
// rowNum, |
|
|
|
|
|
|
|
// colNum, |
|
|
|
|
|
|
|
// elementType, |
|
|
|
|
|
|
|
// dbo.FS_GetdataSourceBySet |
|
|
|
|
|
|
|
// (dataSource, APIDataSourceType, Ghrs_PageSettingEdit.APIDataSourceID) |
|
|
|
|
|
|
|
// dataSource, |
|
|
|
|
|
|
|
// defaultHidden, |
|
|
|
|
|
|
|
// isPrimaryKey, |
|
|
|
|
|
|
|
// isSingleColumn |
|
|
|
|
|
|
|
// FROM Ghrs_PageSettingEdit |
|
|
|
|
|
|
|
// WHERE IsEnable = 1 |
|
|
|
|
|
|
|
// AND pageNo = '{body.menuName}' |
|
|
|
|
|
|
|
// AND elementType NOT IN ('FnKey', 'PageGroup');"; |
|
|
|
|
|
|
|
//dt = await Db.Ado.GetDataTableAsync(sql); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var data = await BaseDal.QueryFilterPage(body); |
|
|
|
|
|
|
|
var fileId = await ReportHelper.SendFile(data.result.DT_TableDataT1.AsQueryable(), $"测试测试", null, null, null, null); |
|
|
|
|
|
|
|
return ServiceResult<long>.OprateSuccess("导出成功", fileId); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string sql = $@"SELECT *
|
|
|
|
|
|
|
|
FROM Ghrs_PageSettingQuery |
|
|
|
|
|
|
|
WHERE IsEnable = 1 |
|
|
|
|
|
|
|
AND PageNo = '{body.menuName}' |
|
|
|
|
|
|
|
AND defaultHidden = 'false' |
|
|
|
|
|
|
|
ORDER BY SortNo ASC";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var columns = await Db.Ado.SqlQueryAsync<QueryExportColumn>(sql); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var fieldDescs = new Dictionary<string, string>(); |
|
|
|
|
|
|
|
if (body.exportSet.ExFields.Any()) |
|
|
|
|
|
|
|
body.exportSet.ExFields.ForEach(x => |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (columns.Any(o => o.field == x)) |
|
|
|
|
|
|
|
fieldDescs.Add(x, columns.FirstOrDefault(o => o.field == x)?.label); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
fieldDescs = columns.ToDictionary(item => item.field, item => item.label); |
|
|
|
|
|
|
|
var dt = ToDataTable(data.result.DT_TableDataT1, fieldDescs, null); |
|
|
|
|
|
|
|
// 获取所有列名 |
|
|
|
|
|
|
|
var dtColumns = dt.Columns; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var id = SnowFlakeSingle.instance.getID(); |
|
|
|
|
|
|
|
var physicsPath = $"{Environment.CurrentDirectory}{Path.DirectorySeparatorChar}wwwroot"; |
|
|
|
|
|
|
|
var path = $"{$"{Path.DirectorySeparatorChar}files{Path.DirectorySeparatorChar}export{Path.DirectorySeparatorChar}{id}{Path.DirectorySeparatorChar}"}"; |
|
|
|
|
|
|
|
if (!Directory.Exists(physicsPath + path)) |
|
|
|
|
|
|
|
Directory.CreateDirectory(physicsPath + path); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
path = path + body.exportSet.TitleName + ".xlsx"; |
|
|
|
|
|
|
|
NPOIHelper.ExportExcel(dt, null, "sheet1", physicsPath + path); |
|
|
|
|
|
|
|
return ServiceResult<string>.OprateSuccess("导出成功", path); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
|
|
|
/// 列名按照前端显示顺序导出 |
|
|
|
|
|
|
|
/// </summary> |
|
|
|
|
|
|
|
/// <param name="columns"></param> |
|
|
|
|
|
|
|
/// <param name="ExportFields"></param> |
|
|
|
|
|
|
|
/// <returns></returns> |
|
|
|
|
|
|
|
public static (List<string>, List<string>) Sort(Dictionary<string, string> columns, List<string> ExportFields) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
List<string> fields = new List<string>(); |
|
|
|
|
|
|
|
List<string> colunms = new List<string>(); |
|
|
|
|
|
|
|
if (ExportFields == null || ExportFields.Count == 0) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return (columns.Keys.ToList(), columns.Values.ToList()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var field in ExportFields) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
foreach (var item in columns) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (item.Key == field) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
fields.Add(item.Key); |
|
|
|
|
|
|
|
colunms.Add(item.Value); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return (fields, colunms); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public static DataTable ToDataTable(List<TEntityDto> list, Dictionary<string, string> fieldDescs = null, params string[] propertyName) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
var (fields, colunms) = Sort(fieldDescs, null); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<string> propertyNameList = new List<string>(); |
|
|
|
|
|
|
|
if (propertyName != null) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
propertyNameList.AddRange(propertyName); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
DataTable result = new DataTable(); |
|
|
|
|
|
|
|
if (list.Count > 0) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
PropertyInfo[] propertys = list[0].GetType().GetProperties(); |
|
|
|
|
|
|
|
for (int i = 0; i < fields.Count; i++) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
foreach (PropertyInfo pi in propertys) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (propertyNameList.Count == 0) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
//if (DBNull.Value.Equals(pi.PropertyType)) |
|
|
|
|
|
|
|
//{ |
|
|
|
|
|
|
|
// // pi.PropertyType = DateTime; |
|
|
|
|
|
|
|
//} |
|
|
|
|
|
|
|
Type colType = pi.PropertyType; |
|
|
|
|
|
|
|
if (colType.IsGenericType && colType.GetGenericTypeDefinition() == typeof(Nullable<>)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
colType = colType.GetGenericArguments()[0]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (fields[i] == pi.Name) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
result.Columns.Add(colunms[i], colType); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//result.Columns.Add(pi.Name, pi.PropertyType); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (propertyNameList.Contains(pi.Name)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (fields[i] == pi.Name) |
|
|
|
|
|
|
|
result.Columns.Add(fields[i], pi.PropertyType); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
for (int i = 0; i < list.Count; i++) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
ArrayList tempList = new ArrayList(); |
|
|
|
|
|
|
|
for (int j = 0; j < fields.Count; j++) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
foreach (PropertyInfo pi in propertys) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (fields[j] == pi.Name) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (propertyNameList.Count == 0) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
object obj = pi.GetValue(list[i], null); |
|
|
|
|
|
|
|
tempList.Add(obj); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (propertyNameList.Contains(pi.Name)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
object obj = pi.GetValue(list[i], null); |
|
|
|
|
|
|
|
tempList.Add(obj); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
object[] array = tempList.ToArray(); |
|
|
|
|
|
|
|
result.LoadDataRow(array, true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return result; |
|
|
|
|
|
|
|
} |
|
|
|
public async virtual Task<ServiceResult<ExcelData>> ImportExcel(IFormFile file) |
|
|
|
public async virtual Task<ServiceResult<ExcelData>> ImportExcel(IFormFile file) |
|
|
|
{ |
|
|
|
{ |
|
|
|
//long id = SnowFlakeSingle.instance.getID(); |
|
|
|
//long id = SnowFlakeSingle.instance.getID(); |
|
|
|