导表测试
parent
a217002298
commit
0ca9eb0b54
|
@ -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<IActionResult> DownloadCommonFile(string code, [FromServices] IRepository<CommonDocument> _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));
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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<TrialMaintenanceDTO> TrialUserList { get; set; } = new List<TrialMaintenanceDTO>();
|
||||
}
|
||||
|
|
|
@ -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<IActionResult> TrialUserListExport(Guid trialId, [FromServices] IRepository<CommonDocument> _commonDocumentRepository)
|
||||
{
|
||||
|
||||
|
@ -68,15 +71,29 @@ namespace IRaCIS.Application.Services
|
|||
}
|
||||
|
||||
|
||||
var exportInfo = new TrialUserExportDTO()
|
||||
{
|
||||
TrialInfo = await _trialRepository.ProjectTo<TrialSelectDTO>(_mapper.ConfigurationProvider).FirstOrDefaultAsync(),
|
||||
TrialUserList = await _trialUseRepository.Where(t => t.TrialId == trialId).IgnoreQueryFilters().ProjectTo<TrialMaintenanceDTO>(_mapper.ConfigurationProvider).ToListAsync()
|
||||
};
|
||||
var exportInfo = await _trialRepository.Where(t => t.Id == trialId).IgnoreQueryFilters().ProjectTo<TrialUserExportDTO>(_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
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -200,7 +200,8 @@ namespace IRaCIS.Core.Application.Service
|
|||
CreateMap<TrialExternalUserConfirm, TrialSiteUserSurvey>();
|
||||
|
||||
|
||||
|
||||
CreateMap<Trial, TrialUserExportDTO>();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue