From 2dda3e31620753f646b021e0823ad34f3bc8ee59 Mon Sep 17 00:00:00 2001 From: xiaochanghai Date: Mon, 11 Nov 2024 14:00:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=AF=BC=E5=87=BAExcel?= =?UTF-8?q?=E5=AF=BC=E5=87=BA=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Tiobon.CodeGenerator.csproj | 2 +- .../Controllers/DbFirst/MigrateController.cs | 60 +++++++++---------- .../Controllers/Ghrh/Ghrh_ResumeController.cs | 14 +++++ Tiobon.Core.Api/Tiobon.Core.xml | 8 +++ .../Extensions/IQueryableExtensions.cs | 8 ++- Tiobon.Core.Common/Seed/DBSeed.cs | 5 +- Tiobon.Core.Common/Tiobon.Core.Common.csproj | 4 +- Tiobon.Core.DataAccess/ReportHelper.cs | 39 ++++++------ .../Tiobon.Core.DataAccess.csproj | 3 +- .../Ghrh/IGhrh_ResumeServices.cs | 5 +- .../View/Ghrh/Ghrh_Resume.Dto.View.cs | 5 +- .../Extend/ResumeTemplateGroupColumn.cs | 2 + .../Ghrh/Ghrh_ResumeServices.cs | 59 +++++++++++++++++- 13 files changed, 150 insertions(+), 64 deletions(-) diff --git a/Tiobon.CodeGenerator/Tiobon.CodeGenerator.csproj b/Tiobon.CodeGenerator/Tiobon.CodeGenerator.csproj index 2a46aeb0..918d1713 100644 --- a/Tiobon.CodeGenerator/Tiobon.CodeGenerator.csproj +++ b/Tiobon.CodeGenerator/Tiobon.CodeGenerator.csproj @@ -26,7 +26,7 @@ - + diff --git a/Tiobon.Core.Api/Controllers/DbFirst/MigrateController.cs b/Tiobon.Core.Api/Controllers/DbFirst/MigrateController.cs index 90647eff..0587622a 100644 --- a/Tiobon.Core.Api/Controllers/DbFirst/MigrateController.cs +++ b/Tiobon.Core.Api/Controllers/DbFirst/MigrateController.cs @@ -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; diff --git a/Tiobon.Core.Api/Controllers/Ghrh/Ghrh_ResumeController.cs b/Tiobon.Core.Api/Controllers/Ghrh/Ghrh_ResumeController.cs index d25b0b4f..9301b8b8 100644 --- a/Tiobon.Core.Api/Controllers/Ghrh/Ghrh_ResumeController.cs +++ b/Tiobon.Core.Api/Controllers/Ghrh/Ghrh_ResumeController.cs @@ -186,4 +186,18 @@ public class Ghrh_ResumeController : BaseController> QueryResult(long id, int langId) => await _service.QueryResult(id, langId); #endregion + + #region 查询 + /// + /// 根据条件查询数据 + /// + /// 条件 + /// status + /// + [HttpPost, Route("Export/{status}")] + public async Task> ExportByStatus([FromBody] QueryBody body, string status) + { + return await _service.Export(body, $"Status ='{status}'"); + } + #endregion } \ No newline at end of file diff --git a/Tiobon.Core.Api/Tiobon.Core.xml b/Tiobon.Core.Api/Tiobon.Core.xml index d0a0f92c..5596c195 100644 --- a/Tiobon.Core.Api/Tiobon.Core.xml +++ b/Tiobon.Core.Api/Tiobon.Core.xml @@ -1322,6 +1322,14 @@ + + + 根据条件查询数据 + + 条件 + status + + 教育背景(Controller) diff --git a/Tiobon.Core.Common/Extensions/IQueryableExtensions.cs b/Tiobon.Core.Common/Extensions/IQueryableExtensions.cs index 7319f767..f49733f2 100644 --- a/Tiobon.Core.Common/Extensions/IQueryableExtensions.cs +++ b/Tiobon.Core.Common/Extensions/IQueryableExtensions.cs @@ -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 /// /// /// - public static void IntoFileFromLinqExcel(this IQueryable db, string fname, string splitstr, List exportFields, List exportFieldsWidth, string headText = "", string totalText = "", bool isNeedItemNo = false) where T : class + public static void IntoFileFromLinqExcel(this IQueryable db, string fname, string splitstr, List exportFields, Dictionary exportDicFields = null, List 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 fieldDescs = GetFieldDesc(); - 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)) diff --git a/Tiobon.Core.Common/Seed/DBSeed.cs b/Tiobon.Core.Common/Seed/DBSeed.cs index 440e5066..cde60246 100644 --- a/Tiobon.Core.Common/Seed/DBSeed.cs +++ b/Tiobon.Core.Common/Seed/DBSeed.cs @@ -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 diff --git a/Tiobon.Core.Common/Tiobon.Core.Common.csproj b/Tiobon.Core.Common/Tiobon.Core.Common.csproj index 36b9ae10..04ed971e 100644 --- a/Tiobon.Core.Common/Tiobon.Core.Common.csproj +++ b/Tiobon.Core.Common/Tiobon.Core.Common.csproj @@ -19,15 +19,15 @@ + - - + diff --git a/Tiobon.Core.DataAccess/ReportHelper.cs b/Tiobon.Core.DataAccess/ReportHelper.cs index 8d9514b3..da0a5882 100644 --- a/Tiobon.Core.DataAccess/ReportHelper.cs +++ b/Tiobon.Core.DataAccess/ReportHelper.cs @@ -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 /// /// /// - public static async Task SendFile(IQueryable list, string modelName, List exportFields, List exportFieldsWidth, string sort = null, string headText = "", string totalText = "", bool isNeedItemNo = false) where T : class + public static async Task SendFile(IQueryable list, string modelName, List exportFields, Dictionary exportDicFields = null, List 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 SendFile(DataTable list, string modelName, Dictionary fieldDescs, List exportFieldsWidth, string sort = null, string headText = "", string totalText = "", bool isNeedItemNo = false) diff --git a/Tiobon.Core.DataAccess/Tiobon.Core.DataAccess.csproj b/Tiobon.Core.DataAccess/Tiobon.Core.DataAccess.csproj index 0e7e6858..5b8bb499 100644 --- a/Tiobon.Core.DataAccess/Tiobon.Core.DataAccess.csproj +++ b/Tiobon.Core.DataAccess/Tiobon.Core.DataAccess.csproj @@ -28,7 +28,8 @@ - + + diff --git a/Tiobon.Core.IServices/Ghrh/IGhrh_ResumeServices.cs b/Tiobon.Core.IServices/Ghrh/IGhrh_ResumeServices.cs index b67eed08..5ec0b0d9 100644 --- a/Tiobon.Core.IServices/Ghrh/IGhrh_ResumeServices.cs +++ b/Tiobon.Core.IServices/Ghrh/IGhrh_ResumeServices.cs @@ -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 Submit(long id, string status, ResumeFormColumnSubmit resume); Task> QueryResult(long id, int langId); + + Task> Export(QueryBody filter, string condition, bool? IsEnable = true); } } \ No newline at end of file diff --git a/Tiobon.Core.Model/View/Ghrh/Ghrh_Resume.Dto.View.cs b/Tiobon.Core.Model/View/Ghrh/Ghrh_Resume.Dto.View.cs index feee2882..ef6d2d60 100644 --- a/Tiobon.Core.Model/View/Ghrh/Ghrh_Resume.Dto.View.cs +++ b/Tiobon.Core.Model/View/Ghrh/Ghrh_Resume.Dto.View.cs @@ -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 TagList { get; set; } public List EduBG { get; set; } public List WorkExp { get; set; } diff --git a/Tiobon.Core.Model/ViewModels/Extend/ResumeTemplateGroupColumn.cs b/Tiobon.Core.Model/ViewModels/Extend/ResumeTemplateGroupColumn.cs index d964ae3d..c852a5f8 100644 --- a/Tiobon.Core.Model/ViewModels/Extend/ResumeTemplateGroupColumn.cs +++ b/Tiobon.Core.Model/ViewModels/Extend/ResumeTemplateGroupColumn.cs @@ -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; } } diff --git a/Tiobon.Core.Services/Ghrh/Ghrh_ResumeServices.cs b/Tiobon.Core.Services/Ghrh/Ghrh_ResumeServices.cs index d1853aa0..b27f4d75 100644 --- a/Tiobon.Core.Services/Ghrh/Ghrh_ResumeServices.cs +++ b/Tiobon.Core.Services/Ghrh/Ghrh_ResumeServices.cs @@ -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 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.OprateSuccess("查询成功", Data); } #endregion + + #region 导出Excel + public async Task> 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.OprateSuccess(name + ".xlsx", physicsPath1); + return result; + } + #endregion } \ No newline at end of file