diff --git a/IRaCIS.Core.API/Controllers/DownLoadController.cs b/IRaCIS.Core.API/Controllers/DownLoadController.cs index 7fd779621..a2884d90c 100644 --- a/IRaCIS.Core.API/Controllers/DownLoadController.cs +++ b/IRaCIS.Core.API/Controllers/DownLoadController.cs @@ -5,10 +5,11 @@ using IRaCIS.Core.Domain.Models; using IRaCIS.Core.Infra.EFCore; using MediatR; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc; - +using Microsoft.AspNetCore.StaticFiles; using System; using System.IO; using System.Linq; @@ -57,7 +58,7 @@ namespace IRaCIS.Core.API.Controllers //} - + [AllowAnonymous] [HttpGet("CommonDocument/DownloadCommonDoc")] public async Task DownloadCommonFile(string code, [FromServices] IRepository _commonDocumentRepository) { @@ -77,9 +78,9 @@ namespace IRaCIS.Core.API.Controllers throw new Exception("服务器本地不存在该路径文件"); } + new FileExtensionContentTypeProvider().Mappings.TryGetValue(Path.GetExtension(filePath), out var contentType); + return File(System.IO.File.OpenRead(filePath), contentType ?? "application/octet-stream", doc.Name); - var stream = System.IO.File.OpenRead(filePath); - return File(stream, "application/octet-stream", Path.GetFileName(doc.Name)); } diff --git a/IRaCIS.Core.Application/Service/TrialSiteUser/DTO/UserTrialViewModel.cs b/IRaCIS.Core.Application/Service/TrialSiteUser/DTO/UserTrialViewModel.cs index 96cc180c2..40554eccf 100644 --- a/IRaCIS.Core.Application/Service/TrialSiteUser/DTO/UserTrialViewModel.cs +++ b/IRaCIS.Core.Application/Service/TrialSiteUser/DTO/UserTrialViewModel.cs @@ -2,6 +2,7 @@ using IRaCIS.Core.Infrastructure.Extention; using IRaCIS.Core.Domain.Share; using Magicodes.ExporterAndImporter.Core; +using MiniExcelLibs.Attributes; namespace IRaCIS.Application.Contracts { @@ -37,17 +38,24 @@ namespace IRaCIS.Application.Contracts public class TrialMaintenanceDTO : UserTrialCommand { - [ValueMapping(text: "退出", true)] - [ValueMapping(text: "加入", false)] + //[ValueMapping(text: "退出", true)] + //[ValueMapping(text: "加入", false)] + [ExcelFormat("yyyy-mm-dd hh:mm:ss")] public bool IsDeleted { get; set; } - [ExporterHeader(Format = "yyyy-mm-dd hh:mm:ss")] + public string State => IsDeleted ? "退出" : "加入"; + + //[ExporterHeader(Format = "yyyy-mm-dd hh:mm:ss")] + [ExcelFormat("yyyy-mm-dd hh:mm:ss")] public DateTime? DeletedTime { get; set; } + [ExcelFormat("yyyy-mm-dd")] public DateTime? RemoveTime { get; set; } + [ExcelFormat("yyyy-mm-dd ")] public DateTime? JoinTime { get; set; } + [ExcelFormat("yyyy-mm-dd hh:mm:ss")] public DateTime CreateTime { get; set; } public string Phone { get; set; } = String.Empty; @@ -70,10 +78,9 @@ namespace IRaCIS.Application.Contracts } - public class TrialUserExportDTO + public class TrialUserExportDTO: TrialSelectDTO { public DateTime CurrentTime { get; set; } = DateTime.Now; - public TrialSelectDTO TrialInfo { get; set; } public List TrialUserList { get; set; } = new List(); } diff --git a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialMaintenanceService.cs b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialMaintenanceService.cs index a536c5a18..b7c71efbf 100644 --- a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialMaintenanceService.cs +++ b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialMaintenanceService.cs @@ -9,6 +9,8 @@ using Magicodes.ExporterAndImporter.Core; using Magicodes.ExporterAndImporter.Excel; using Magicodes.ExporterAndImporter.Excel.AspNetCore; using Microsoft.AspNetCore.Hosting; +using MiniExcelLibs; +using Microsoft.AspNetCore.Authorization; namespace IRaCIS.Application.Services { @@ -48,6 +50,7 @@ namespace IRaCIS.Application.Services [HttpGet] + [AllowAnonymous] public async Task TrialUserListExport(Guid trialId, [FromServices] IRepository _commonDocumentRepository) { @@ -68,15 +71,29 @@ namespace IRaCIS.Application.Services } - var exportInfo = new TrialUserExportDTO() - { - TrialInfo = await _trialRepository.ProjectTo(_mapper.ConfigurationProvider).FirstOrDefaultAsync(), - TrialUserList = await _trialUseRepository.Where(t => t.TrialId == trialId).IgnoreQueryFilters().ProjectTo(_mapper.ConfigurationProvider).ToListAsync() - }; + var exportInfo = await _trialRepository.Where(t => t.Id == trialId).IgnoreQueryFilters().ProjectTo(_mapper.ConfigurationProvider).FirstOrDefaultAsync(); //模板路径 var tplPath = filePath; + + #region MiniExcel + + var memoryStream = new MemoryStream(); + + MiniExcel.SaveAsByTemplate(memoryStream, tplPath, exportInfo); + + memoryStream.Seek(0, SeekOrigin.Begin); + return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") + { + FileDownloadName = $"{doc.Name}_{DateTime.Now.ToString("yyyy-MM-dd:hh:mm:ss")}.xlsx" + }; + + #endregion + + + #region Magicodes + //创建Excel导出对象 IExportFileByTemplate exporter = new ExcelExporter(); @@ -84,8 +101,10 @@ namespace IRaCIS.Application.Services var result = await exporter.ExportBytesByTemplate(exportInfo, tplPath); - return new XlsxFileResult(bytes: result, fileDownloadName: $"{doc.Name}_{DateTime.Now.ToString("yyyy-MM-dd:hh:mm:ss")}.xlsx"); + #endregion + + } diff --git a/IRaCIS.Core.Application/Service/TrialSiteUser/_MapConfig.cs b/IRaCIS.Core.Application/Service/TrialSiteUser/_MapConfig.cs index ceb2c34ab..2dfbe8615 100644 --- a/IRaCIS.Core.Application/Service/TrialSiteUser/_MapConfig.cs +++ b/IRaCIS.Core.Application/Service/TrialSiteUser/_MapConfig.cs @@ -200,7 +200,8 @@ namespace IRaCIS.Core.Application.Service CreateMap(); - + CreateMap(); + }