新增导出Excel导出接口

master
xiaochanghai 7 months ago
parent 5f67f27b75
commit 2dda3e3162
  1. 2
      Tiobon.CodeGenerator/Tiobon.CodeGenerator.csproj
  2. 60
      Tiobon.Core.Api/Controllers/DbFirst/MigrateController.cs
  3. 14
      Tiobon.Core.Api/Controllers/Ghrh/Ghrh_ResumeController.cs
  4. 8
      Tiobon.Core.Api/Tiobon.Core.xml
  5. 8
      Tiobon.Core.Common/Extensions/IQueryableExtensions.cs
  6. 5
      Tiobon.Core.Common/Seed/DBSeed.cs
  7. 4
      Tiobon.Core.Common/Tiobon.Core.Common.csproj
  8. 39
      Tiobon.Core.DataAccess/ReportHelper.cs
  9. 3
      Tiobon.Core.DataAccess/Tiobon.Core.DataAccess.csproj
  10. 5
      Tiobon.Core.IServices/Ghrh/IGhrh_ResumeServices.cs
  11. 5
      Tiobon.Core.Model/View/Ghrh/Ghrh_Resume.Dto.View.cs
  12. 2
      Tiobon.Core.Model/ViewModels/Extend/ResumeTemplateGroupColumn.cs
  13. 59
      Tiobon.Core.Services/Ghrh/Ghrh_ResumeServices.cs

@ -26,7 +26,7 @@
<ItemGroup>
<PackageReference Include="Dapper" Version="2.1.35" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="MySql.Data" Version="8.3.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.6" />

@ -1,5 +1,5 @@
using Magicodes.ExporterAndImporter.Core;
using Magicodes.ExporterAndImporter.Excel;
//using Magicodes.ExporterAndImporter.Core;
//using Magicodes.ExporterAndImporter.Excel;
namespace Tiobon.Core.Controllers
{
@ -215,34 +215,34 @@ namespace Tiobon.Core.Controllers
};
// 取出数据,序列化,自己可以处理判空
IExporter exporter = new ExcelExporter();
var SysUserInfoList = await _sysUserInfoServices.Query(d => d.IsDeleted == false);
var result = await exporter.ExportAsByteArray(SysUserInfoList);
FileHelper.WriteFile(Path.Combine(_env.WebRootPath, "TiobonCore.Data.excel", "SysUserInfo.xlsx"), result);
var DepartmentList = await _departmentServices.Query(d => d.IsDeleted == false);
var DepartmentResult = await exporter.ExportAsByteArray(DepartmentList);
FileHelper.WriteFile(Path.Combine(_env.WebRootPath, "TiobonCore.Data.excel", "Department.xlsx"), DepartmentResult);
var RoleList = await _roleServices.Query(d => d.IsDeleted == false);
var RoleResult = await exporter.ExportAsByteArray(RoleList);
FileHelper.WriteFile(Path.Combine(_env.WebRootPath, "TiobonCore.Data.excel", "Role.xlsx"), RoleResult);
var UserRoleList = await _userRoleServices.Query(d => d.IsDeleted == false);
var UserRoleResult = await exporter.ExportAsByteArray(UserRoleList);
FileHelper.WriteFile(Path.Combine(_env.WebRootPath, "TiobonCore.Data.excel", "UserRole.xlsx"), UserRoleResult);
var PermissionList = await _permissionServices.Query(d => d.IsDeleted == false);
var PermissionResult = await exporter.ExportAsByteArray(PermissionList);
FileHelper.WriteFile(Path.Combine(_env.WebRootPath, "TiobonCore.Data.excel", "Permission.xlsx"), PermissionResult);
var ModulesList = await _moduleServices.Query(d => d.IsDeleted == false);
var ModulesResult = await exporter.ExportAsByteArray(ModulesList);
FileHelper.WriteFile(Path.Combine(_env.WebRootPath, "TiobonCore.Data.excel", "Modules.xlsx"), ModulesResult);
var RoleModulePermissionList = await _roleModulePermissionServices.Query(d => d.IsDeleted == false);
var RoleModulePermissionResult = await exporter.ExportAsByteArray(RoleModulePermissionList);
FileHelper.WriteFile(Path.Combine(_env.WebRootPath, "TiobonCore.Data.excel", "RoleModulePermission.xlsx"), RoleModulePermissionResult);
//IExporter exporter = new ExcelExporter();
//var SysUserInfoList = await _sysUserInfoServices.Query(d => d.IsDeleted == false);
//var result = await exporter.ExportAsByteArray(SysUserInfoList);
//FileHelper.WriteFile(Path.Combine(_env.WebRootPath, "TiobonCore.Data.excel", "SysUserInfo.xlsx"), result);
//var DepartmentList = await _departmentServices.Query(d => d.IsDeleted == false);
//var DepartmentResult = await exporter.ExportAsByteArray(DepartmentList);
//FileHelper.WriteFile(Path.Combine(_env.WebRootPath, "TiobonCore.Data.excel", "Department.xlsx"), DepartmentResult);
//var RoleList = await _roleServices.Query(d => d.IsDeleted == false);
//var RoleResult = await exporter.ExportAsByteArray(RoleList);
//FileHelper.WriteFile(Path.Combine(_env.WebRootPath, "TiobonCore.Data.excel", "Role.xlsx"), RoleResult);
//var UserRoleList = await _userRoleServices.Query(d => d.IsDeleted == false);
//var UserRoleResult = await exporter.ExportAsByteArray(UserRoleList);
//FileHelper.WriteFile(Path.Combine(_env.WebRootPath, "TiobonCore.Data.excel", "UserRole.xlsx"), UserRoleResult);
//var PermissionList = await _permissionServices.Query(d => d.IsDeleted == false);
//var PermissionResult = await exporter.ExportAsByteArray(PermissionList);
//FileHelper.WriteFile(Path.Combine(_env.WebRootPath, "TiobonCore.Data.excel", "Permission.xlsx"), PermissionResult);
//var ModulesList = await _moduleServices.Query(d => d.IsDeleted == false);
//var ModulesResult = await exporter.ExportAsByteArray(ModulesList);
//FileHelper.WriteFile(Path.Combine(_env.WebRootPath, "TiobonCore.Data.excel", "Modules.xlsx"), ModulesResult);
//var RoleModulePermissionList = await _roleModulePermissionServices.Query(d => d.IsDeleted == false);
//var RoleModulePermissionResult = await exporter.ExportAsByteArray(RoleModulePermissionList);
//FileHelper.WriteFile(Path.Combine(_env.WebRootPath, "TiobonCore.Data.excel", "RoleModulePermission.xlsx"), RoleModulePermissionResult);
data.Success = true;

@ -186,4 +186,18 @@ public class Ghrh_ResumeController : BaseController<IGhrh_ResumeServices, Ghrh_R
public async Task<ServiceResult<dynamic>> QueryResult(long id, int langId) => await _service.QueryResult(id, langId);
#endregion
#region 查询
/// <summary>
/// 根据条件查询数据
/// </summary>
/// <param name="body">条件</param>
/// <param name="status">status</param>
/// <returns></returns>
[HttpPost, Route("Export/{status}")]
public async Task<ServiceResult<string>> ExportByStatus([FromBody] QueryBody body, string status)
{
return await _service.Export(body, $"Status ='{status}'");
}
#endregion
}

@ -1322,6 +1322,14 @@
</summary>
<returns></returns>
</member>
<member name="M:Tiobon.Core.Api.Controllers.Ghrh_ResumeController.ExportByStatus(Tiobon.Core.Common.QueryBody,System.String)">
<summary>
根据条件查询数据
</summary>
<param name="body">条件</param>
<param name="status">status</param>
<returns></returns>
</member>
<member name="T:Tiobon.Core.Api.Controllers.Ghrh_ResumeEduBGController">
<summary>
教育背景(Controller)

@ -2,10 +2,10 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Reflection;
using OfficeOpenXml;
using OfficeOpenXml.Style;
using SixLabors.ImageSharp;
using Tiobon.Core.Common.Helper;
namespace Tiobon.Core.Common.Extensions;
@ -24,7 +24,7 @@ public static class IQueryableExtensions
/// <param name="headText"></param>
/// <param name="totalText"></param>
/// <param name="isNeedItemNo"></param>
public static void IntoFileFromLinqExcel<T>(this IQueryable<T> db, string fname, string splitstr, List<string> exportFields, List<int> exportFieldsWidth, string headText = "", string totalText = "", bool isNeedItemNo = false) where T : class
public static void IntoFileFromLinqExcel<T>(this IQueryable<T> db, string fname, string splitstr, List<string> exportFields, Dictionary<string, string> exportDicFields = null, List<int> exportFieldsWidth = null, string headText = "", string totalText = "", bool isNeedItemNo = false) where T : class
{
if (db.IsNull())
return;
@ -40,8 +40,10 @@ public static class IQueryableExtensions
File.Create(fname).Close();
//获取需要导出的字段
Dictionary<string, string> fieldDescs = GetFieldDesc<T>();
int dbCount = db.Count();
fieldDescs = exportDicFields;
int dbCount = db.Count();
ExcelPackage.LicenseContext = OfficeOpenXml.LicenseContext.Commercial;
//列名排序,返回有序列表
var (fields, colunms) = Sort(fieldDescs, exportFields);
using (FileStream stream = File.Create(fname))

@ -2,8 +2,7 @@
using Tiobon.Core.Common.Extensions;
using Tiobon.Core.Common.Helper;
using Tiobon.Core.Model.Models;
using Tiobon.Core.Model.Tenants;
using Magicodes.ExporterAndImporter.Excel;
using Tiobon.Core.Model.Tenants;
using Newtonsoft.Json;
using SqlSugar;
using System.Diagnostics;
@ -126,7 +125,7 @@ namespace Tiobon.Core.Common.Seed
Console.WriteLine($"Seeding database data (The Db Id:{MyContext.ConnId})...");
var importer = new ExcelImporter();
//var importer = new ExcelImporter();
#region TiobonArticle

@ -19,15 +19,15 @@
<ItemGroup>
<PackageReference Include="AgileObjects.AgileMapper" Version="1.8.1" />
<PackageReference Include="Dapper" Version="2.1.35" />
<PackageReference Include="EPPlus" Version="7.4.2" />
<PackageReference Include="JetBrains.Annotations" Version="2024.3.0" />
<PackageReference Include="Magicodes.IE.Excel" Version="2.7.4.5" />
<PackageReference Include="InitQ" Version="1.0.0.18" />
<PackageReference Include="log4net" Version="2.0.15" />
<PackageReference Include="Mapster" Version="7.4.0" />
<PackageReference Include="Mapster.Core" Version="1.2.1" />
<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.1" />
<PackageReference Include="MySql.Data" Version="8.3.0" />
<PackageReference Include="NPOI" Version="2.7.0" />
<PackageReference Include="PinYinConverterCore" Version="1.0.2" />

@ -5,7 +5,6 @@ using System.ComponentModel.DataAnnotations;
using System.Data;
using System.IO;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Text;
using System.Threading.Tasks;
using NPOI.HSSF.UserModel;
@ -40,37 +39,37 @@ public static class ReportHelper
/// <param name="headText"></param>
/// <param name="totalText"></param>
/// <param name="isNeedItemNo"></param>
public static async Task<long> SendFile<T>(IQueryable<T> list, string modelName, List<string> exportFields, List<int> exportFieldsWidth, string sort = null, string headText = "", string totalText = "", bool isNeedItemNo = false) where T : class
public static async Task<string> SendFile<T>(IQueryable<T> list, string modelName, List<string> exportFields, Dictionary<string, string> exportDicFields = null, List<int> exportFieldsWidth = null, string sort = null, string headText = "", string totalText = "", bool isNeedItemNo = false) where T : class
{
if (list == null)
throw new Exception("生成文件失败");
//生成文件至文件服务器
var fid = SnowFlakeSingle.Instance.NextId();
var path = $"{$"{Environment.CurrentDirectory}{Path.DirectorySeparatorChar}wwwroot{Path.DirectorySeparatorChar}files{Path.DirectorySeparatorChar}export{Path.DirectorySeparatorChar}{fid}{Path.DirectorySeparatorChar}"}";
//var fid = SnowFlakeSingle.Instance.NextId();
var path = $"{$"{Environment.CurrentDirectory}{Path.DirectorySeparatorChar}wwwroot{Path.DirectorySeparatorChar}files{Path.DirectorySeparatorChar}export{Path.DirectorySeparatorChar}"}";
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
var fname = $"{modelName}.xlsx";
list = string.IsNullOrEmpty(sort) ? list : list.OrderBy(sort);
list.IntoFileFromLinqExcel(path + fname, ",", exportFields, exportFieldsWidth, headText, totalText, isNeedItemNo);
//list = string.IsNullOrEmpty(sort) ? list : list.OrderBy(sort);
list.IntoFileFromLinqExcel(path + fname, ",", exportFields, exportDicFields, exportFieldsWidth, headText, totalText, isNeedItemNo);
using var _context = ContextFactory.CreateContext();
Ghre_Attachment fileAttachment = new Ghre_Attachment();
fileAttachment.Id = fid;
fileAttachment.AttachFileName = fname;
fileAttachment.CreateBy = App.User.ID;
fileAttachment.CreateTime = DateTime.Now;
fileAttachment.AttachmentName = fname;
fileAttachment.AttachFileExtension = "xlsx";
fileAttachment.AttachFileSize = 0;
fileAttachment.PhysicsPath = $"/files/export/{fid}/" + fname;
fileAttachment.AttachmentType = "xlsx";
await _context.Ghre_Attachment.AddAsync(fileAttachment);
await _context.SaveChangesAsync();
return fid;
//Ghre_Attachment fileAttachment = new Ghre_Attachment();
//fileAttachment.Id = fid;
//fileAttachment.AttachFileName = fname;
//fileAttachment.CreateBy = App.User.ID;
//fileAttachment.CreateTime = DateTime.Now;
//fileAttachment.AttachmentName = fname;
//fileAttachment.AttachFileExtension = "xlsx";
//fileAttachment.AttachFileSize = 0;
//fileAttachment.PhysicsPath = $"/files/export/{fid}/" + fname;
//fileAttachment.AttachmentType = "xlsx";
//await _context.Ghre_Attachment.AddAsync(fileAttachment);
//await _context.SaveChangesAsync();
return $"{$"/files/export/"}" + fname;
}
public static async Task<long> SendFile(DataTable list, string modelName, Dictionary<string, string> fieldDescs, List<int> exportFieldsWidth, string sort = null, string headText = "", string totalText = "", bool isNeedItemNo = false)

@ -28,7 +28,8 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.4" />
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="8.0.0" />
<PackageReference Include="NPOI" Version="2.7.0" />
<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" Version="3.0.1" />
<PackageReference Include="NPOI" Version="2.7.2" />
<PackageReference Include="Z.EntityFramework.Extensions.EFCore" Version="8.102.2.1" />
</ItemGroup>

@ -1,4 +1,5 @@
using Tiobon.Core.IServices.BASE;
using Tiobon.Core.Common;
using Tiobon.Core.IServices.BASE;
using Tiobon.Core.Model;
using Tiobon.Core.Model.Models;
using Tiobon.Core.Model.ViewModels.Extend;
@ -29,5 +30,7 @@ namespace Tiobon.Core.IServices
Task<ServiceResult> Submit(long id, string status, ResumeFormColumnSubmit resume);
Task<ServiceResult<dynamic>> QueryResult(long id, int langId);
Task<ServiceResult<string>> Export(QueryBody filter, string condition, bool? IsEnable = true);
}
}

@ -38,8 +38,11 @@ public class Ghrh_ResumeDto : Ghrh_Resume
public string MaritalStatusLabel { get; set; }
public string PoliticStatusLabel { get; set; }
public string UrgentRelationLabel { get; set; }
public string CertificateTypeLabel { get; set; }
public string RegisteredTypeLabel { get; set; }
public string UrgentRelationLabel { get; set; }
public List<string> TagList { get; set; }
public List<Ghrh_ResumeEduBGDto> EduBG { get; set; }
public List<Ghrh_ResumeWorkExpDto> WorkExp { get; set; }

@ -29,6 +29,8 @@ public class ResumeCondition
public class ResumeFormColumn1
{
public string ColumnName { get; set; }
public string ColumnNameDesc { get; set; }
public string GroupType { get; set; }
}

@ -1,15 +1,18 @@

using AgileObjects.AgileMapper;
using AgileObjects.AgileMapper.Extensions;
using DnsClient;
using MathNet.Numerics.Distributions;
using Microsoft.IdentityModel.Tokens;
using Newtonsoft.Json.Linq;
using Org.BouncyCastle.Utilities;
using SqlSugar;
using System.Dynamic;
using Tiobon.Core.Common;
using Tiobon.Core.Common.Caches;
using Tiobon.Core.Common.DB.Dapper.Extensions;
using Tiobon.Core.Common.Helper;
using Tiobon.Core.DataAccess;
using Tiobon.Core.IRepository.Base;
using Tiobon.Core.IServices;
using Tiobon.Core.Model;
@ -200,8 +203,10 @@ public class Ghrh_ResumeServices : BaseServices<Ghrh_Resume, Ghrh_ResumeDto, Ins
x.EducationLabel = await GetParaLabel("EducationalBGLevel", x.Education);
x.NationLabel = await GetParaLabel("A02", x.Nation);
x.MaritalStatusLabel = await GetParaLabel("A03", x.MaritalStatus);
x.PoliticStatusLabel = await GetParaLabel("A04", x.PoliticStatus);
x.PoliticStatusLabel = await GetParaLabel("A04", x.PoliticStatus);
x.UrgentRelationLabel = await GetParaLabel("SocialRelationType", x.UrgentRelation);
x.CertificateTypeLabel = await GetParaLabel("D51", x.CertificateType);
x.RegisteredTypeLabel = await GetParaLabel("A08", x.RegisteredType);
x.EduBG = eduBGs.Where(o => x.Id == o.ResumeId).ToList();
x.WorkExp = workExps.Where(o => x.Id == o.ResumeId).ToList();
@ -774,7 +779,7 @@ END";
{
var sql = @$"DECLARE @ResumeTemplateID BIGINT = {resumeTemplateID}
SELECT A.ColumnName, D.GroupType
SELECT A.ColumnName, A.ResumeInfoColumnName ColumnNameDesc, D.GroupType
FROM Ghrh_ResumeInfoColumn A
LEFT JOIN Ghrh_ResumeTemplateInfoGroupColumn B
ON B.ResumeInfoColumnID = A.ID
@ -1047,4 +1052,54 @@ END";
return ServiceResult<dynamic>.OprateSuccess("查询成功", Data);
}
#endregion
#region 导出Excel
public async Task<ServiceResult<string>> Export(QueryBody filter, string condition, bool? IsEnable = true)
{
filter.pageNum = 1;
filter.pageSize = 100000;
var data = await QueryFilterPage(filter, condition, IsEnable);
var formColumns = await QueryResumeFormColumn(1);
formColumns.ForEach(x =>
{
if (x.GroupType == "Base")
{
if (x.ColumnName == "TitleId")
x.ColumnName = "TitleName";
else if (x.ColumnName == "Gender")
x.ColumnName = "GenderLabel";
else if (x.ColumnName == "Education")
x.ColumnName = "EducationLabel";
else if (x.ColumnName == "Nation")
x.ColumnName = "NationLabel";
else if (x.ColumnName == "MaritalStatus")
x.ColumnName = "MaritalStatusLabel";
else if (x.ColumnName == "PoliticStatus")
x.ColumnName = "PoliticStatusLabel";
else if (x.ColumnName == "UrgentRelation")
x.ColumnName = "UrgentRelationLabel";
else if (x.ColumnName == "CertificateType")
x.ColumnName = "CertificateTypeLabel";
else if (x.ColumnName == "RegisteredType")
x.ColumnName = "RegisteredTypeLabel";
}
});
var menuName = string.Empty;
string sql = "select QueryProcedure, EditProcedure, IUDProcedure, MenuName from Ghrs_Menu where MenuNo='{0}'";
sql = string.Format(sql, filter.menuName);
var dt = await Db.Ado.GetDataTableAsync(sql);
if (dt.Rows.Count > 0)
{
menuName = dt.Rows[0]["MenuName"].ToString();
}
var dic = formColumns.Where(x => x.GroupType == "Base").ToDictionary(item => item.ColumnNameDesc, item => item.ColumnName);
var name = menuName + "_" + DateTimeHelper.ConvertToSecondString1(DateTime.Now);
var physicsPath1 = await ReportHelper.SendFile(data.result.DT_TableDataT1.AsQueryable(), name, null, dic, null, null, menuName);
var result = ServiceResult<string>.OprateSuccess(name + ".xlsx", physicsPath1);
return result;
}
#endregion
}
Loading…
Cancel
Save