人员导出 加条件修改

Uat_Study
hang 2022-04-11 13:37:49 +08:00
parent 74dcd12285
commit 1844a15879
8 changed files with 180 additions and 123 deletions

View File

@ -0,0 +1,59 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using MiniExcelLibs;
namespace IRaCIS.Core.Application.Service;
public static class ExcelExportHelper
{
//MiniExcel_Export
public static async Task<IActionResult> DataExportAsync(string code, object data, IRepository<CommonDocument> _commonDocumentRepository, IWebHostEnvironment _hostEnvironment)
{
var doc = _commonDocumentRepository.AsQueryable(true).FirstOrDefault(t => t.Code == code);
if (doc == null)
{
throw new Exception("当前code 没要找到对应的导出模板文件");
}
var rootPath = Directory.GetParent(_hostEnvironment.ContentRootPath.TrimEnd('\\'))?.FullName;
var filePath = Path.Combine(rootPath, doc.Path.Trim('/'));
if (!System.IO.File.Exists(filePath))
{
throw new Exception("服务器本地不存在该路径文件");
}
//模板路径
var tplPath = filePath;
#region MiniExcel
var memoryStream = new MemoryStream();
await MiniExcel.SaveAsByTemplateAsync(memoryStream, tplPath, data);
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();
////根据模板导出
//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
}
}

View File

@ -62,6 +62,8 @@ namespace IRaCIS.Core.Application.Contracts
public TrialSiteSurveyView TrialSiteSurvey { get; set; } public TrialSiteSurveyView TrialSiteSurvey { get; set; }
} }
public class TrialSiteUserSurveyAllQuery : PageInput public class TrialSiteUserSurveyAllQuery : PageInput
{ {
[NotDefault] [NotDefault]
@ -78,7 +80,6 @@ namespace IRaCIS.Core.Application.Contracts
public string FormWriterKeyInfo { get; set; } = string.Empty; public string FormWriterKeyInfo { get; set; } = string.Empty;
//public string UserKeyInfo { get; set; } = string.Empty;
public string UserName { get; set; } = string.Empty; public string UserName { get; set; } = string.Empty;

View File

@ -22,6 +22,19 @@ namespace IRaCIS.Core.Application.Contracts.DTO
} }
public class SiteCRCExportQueryDTO
{
public Guid TrialId { get; set; } = Guid.Empty;
public string SiteName { get; set; } = String.Empty;
public string TrialSiteAliasName { get; set; } = String.Empty;
public bool? IsDeleted { get; set; }
public string TrialSiteCode { get; set; } = String.Empty;
public string UserKeyInfo { get; set; } = String.Empty;
}
public class TrialSiteCommand public class TrialSiteCommand
{ {
public Guid TrialId { get; set; } public Guid TrialId { get; set; }

View File

@ -211,13 +211,10 @@ namespace IRaCIS.Application.Contracts
public class TrialMaintenanceExportQuery
public class TrialMaintenanceQuery : PageInput
{ {
public Guid TrialId { get; set; } = Guid.Empty; public Guid TrialId { get; set; } = Guid.Empty;
public string UserRealName { get; set; } = string.Empty; public string UserRealName { get; set; } = string.Empty;
//public string UserType { get; set; } = string.Empty;
public Guid? UserTypeId { get; set; } public Guid? UserTypeId { get; set; }
@ -226,11 +223,20 @@ namespace IRaCIS.Application.Contracts
public string OrganizationName { get; set; } = String.Empty; public string OrganizationName { get; set; } = String.Empty;
public bool? IsDeleted { get; set; } public bool? IsDeleted { get; set; }
}
//public DateTime? RemoveTime { get; set; } public class TrialMaintenanceQuery : PageInput
{
public Guid TrialId { get; set; } = Guid.Empty;
public string UserRealName { get; set; } = string.Empty;
//public DateTime? JoinTime { get; set; } public Guid? UserTypeId { get; set; }
public string UserName { get; set; } = string.Empty;
public string OrganizationName { get; set; } = String.Empty;
public bool? IsDeleted { get; set; }
} }

View File

@ -1,15 +1,11 @@
using IRaCIS.Application.Contracts; using IRaCIS.Application.Contracts;
using IRaCIS.Core.Infra.EFCore;
using IRaCIS.Core.Application.Filter; using IRaCIS.Core.Application.Filter;
using IRaCIS.Core.Domain.Share; using IRaCIS.Core.Domain.Share;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using IRaCIS.Core.Application.Contracts.DTO; using IRaCIS.Core.Application.Contracts.DTO;
using IRaCIS.Application.Interfaces; using IRaCIS.Application.Interfaces;
using Magicodes.ExporterAndImporter.Core; using IRaCIS.Core.Application.Service;
using Magicodes.ExporterAndImporter.Excel;
using Magicodes.ExporterAndImporter.Excel.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using MiniExcelLibs;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
namespace IRaCIS.Application.Services namespace IRaCIS.Application.Services
@ -29,67 +25,36 @@ namespace IRaCIS.Application.Services
/// <summary> /// <summary>
/// 项目参与人员导出 /// 项目参与人员导出
/// </summary> /// </summary>
/// <param name="trialId"></param> /// <param name="param"></param>
/// <param name="_commonDocumentRepository"></param> /// <param name="_commonDocumentRepository"></param>
/// <returns></returns> /// <returns></returns>
/// <exception cref="Exception"></exception> /// <exception cref="Exception"></exception>
[HttpGet] [HttpPost]
[AllowAnonymous] [AllowAnonymous]
public async Task<IActionResult> TrialUserListExport(Guid trialId, [FromServices] IRepository<CommonDocument> _commonDocumentRepository) public async Task<IActionResult> TrialUserListExport(TrialMaintenanceExportQuery param, [FromServices] IRepository<CommonDocument> _commonDocumentRepository)
{ {
var doc = _commonDocumentRepository.AsQueryable(true).FirstOrDefault(t => t.Code == "TrialUserList_Export");
if (doc == null) var exportInfo = (await _trialRepository.Where(t => t.Id == param.TrialId).IgnoreQueryFilters().ProjectTo<TrialUserExportDTO>(_mapper.ConfigurationProvider).FirstOrDefaultAsync()).IfNullThrowException();
{
throw new Exception("当前code 没要找到对应的导出模板文件");
}
var rootPath = Directory.GetParent(_hostEnvironment.ContentRootPath.TrimEnd('\\'))?.FullName; exportInfo.TrialUserList = await _trialUseRepository.Where(t => t.TrialId == param.TrialId).IgnoreQueryFilters()
.WhereIf(param.UserTypeId != null, t => t.User.UserTypeId == param.UserTypeId)
.WhereIf(!string.IsNullOrWhiteSpace(param.UserName), t => t.User.UserName.Contains(param.UserName))
var filePath = Path.Combine(rootPath, doc.Path.Trim('/')); .WhereIf(param.IsDeleted != null, t => t.IsDeleted == param.IsDeleted)
.WhereIf(!string.IsNullOrWhiteSpace(param.OrganizationName),
t => t.User.OrganizationName.Contains(param.OrganizationName))
.WhereIf(!string.IsNullOrWhiteSpace(param.UserRealName),
t => (t.User.LastName + " / " + t.User.FirstName).Contains(param.UserRealName))
.ProjectTo<TrialMaintenanceDTO>(_mapper.ConfigurationProvider).ToListAsync();
if (!System.IO.File.Exists(filePath)) return await ExcelExportHelper.DataExportAsync(StaticData.TrialUserList_Export, exportInfo, _commonDocumentRepository, _hostEnvironment);
{
throw new Exception("服务器本地不存在该路径文件");
}
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();
////根据模板导出
//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
} }

View File

@ -1,13 +1,12 @@
using IRaCIS.Application.Contracts; using IRaCIS.Application.Contracts;
using IRaCIS.Core.Domain.Share; using IRaCIS.Core.Domain.Share;
using IRaCIS.Core.Infrastructure.ExpressionExtend;
using IRaCIS.Core.Application.Filter; using IRaCIS.Core.Application.Filter;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using IRaCIS.Core.Application.Contracts.DTO; using IRaCIS.Core.Application.Contracts.DTO;
using IRaCIS.Core.Application.Contracts; using IRaCIS.Core.Application.Contracts;
using IRaCIS.Core.Application.Interfaces; using IRaCIS.Core.Application.Interfaces;
using IRaCIS.Core.Application.Service;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using MiniExcelLibs;
namespace IRaCIS.Core.Application.Services namespace IRaCIS.Core.Application.Services
{ {
@ -29,93 +28,88 @@ namespace IRaCIS.Core.Application.Services
} }
#region 导出列表
/// <summary> /// <summary>
/// Site用户列表导出 /// Site用户列表导出
/// </summary> /// </summary>
/// <param name="trialId"></param> /// <param name="param"></param>
/// <param name="isSiteUserNotAll">isAllSiteUser true site用户列表false Site调研汇总表</param> /// <param name="_commonDocumentRepository"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
[HttpPost]
[AllowAnonymous]
public async Task<IActionResult> TrialSiteUserListExport(SiteCRCExportQueryDTO param, [FromServices] IRepository<CommonDocument> _commonDocumentRepository)
{
var exportInfo = (await _trialRepository.Where(t => t.Id == param.TrialId).IgnoreQueryFilters().ProjectTo<TrialSiteUserExportDto>(_mapper.ConfigurationProvider).FirstOrDefaultAsync()).IfNullThrowException();
exportInfo.TrialSiteUserList = await _trialSiteUserRepository.Where(t => t.TrialId == param.TrialId).IgnoreQueryFilters()
.WhereIf(param.IsDeleted != null, t => t.IsDeleted == param.IsDeleted)
.WhereIf(!string.IsNullOrWhiteSpace(param.SiteName), t => t.Site.SiteName.Contains(param.SiteName))
.WhereIf(!string.IsNullOrWhiteSpace(param.TrialSiteAliasName),
t => t.TrialSite.TrialSiteAliasName.Contains(param.TrialSiteAliasName))
.WhereIf(!string.IsNullOrWhiteSpace(param.TrialSiteCode),
t => t.TrialSite.TrialSiteCode.Contains(param.TrialSiteCode))
.WhereIf(_userInfo.UserTypeEnumInt == (int)UserTypeEnum.ClinicalResearchCoordinator,
t => t.UserId == _userInfo.Id)
.WhereIf(!string.IsNullOrWhiteSpace(param.UserKeyInfo), t => (t.User.LastName + " / " + t.User.FirstName).Contains(param.UserKeyInfo)
|| t.User.UserName.Contains(param.UserKeyInfo) || t.User.EMail.Contains(param.UserKeyInfo))
.ProjectTo<SiteUserExportDTO>(_mapper.ConfigurationProvider).ToListAsync();
return await ExcelExportHelper.DataExportAsync(StaticData.TrialSiteUserList_Export, exportInfo, _commonDocumentRepository, _hostEnvironment);
}
/// <summary>
/// Site用户汇总表导出
/// </summary>
/// <param name="_commonDocumentRepository"></param> /// <param name="_commonDocumentRepository"></param>
/// <param name="_trialSiteSurveyRepository"></param> /// <param name="_trialSiteSurveyRepository"></param>
/// <param name="_trialSiteUserSurveyRepository"></param> /// <param name="_trialSiteUserSurveyRepository"></param>
/// <returns></returns> /// <returns></returns>
/// <exception cref="Exception"></exception> /// <exception cref="Exception"></exception>
[HttpGet, Route("{trialId:guid}/{isSiteUserNotAll:bool}")] [HttpGet, Route("{trialId:guid}")]
[AllowAnonymous] [AllowAnonymous]
public async Task<IActionResult> TrialSiteUserListExport(Guid trialId, bool isSiteUserNotAll, public async Task<IActionResult> TrialSiteUserSummaryListExport(Guid trialId,
[FromServices] IRepository<CommonDocument> _commonDocumentRepository, [FromServices] IRepository<CommonDocument> _commonDocumentRepository,
[FromServices] IRepository<TrialSiteSurvey> _trialSiteSurveyRepository, [FromServices] IRepository<TrialSiteSurvey> _trialSiteSurveyRepository,
[FromServices] IRepository<TrialSiteUserSurvey> _trialSiteUserSurveyRepository [FromServices] IRepository<TrialSiteUserSurvey> _trialSiteUserSurveyRepository
) )
{ {
var code = isSiteUserNotAll ? "TrialSiteUserList_Export":"TrialSiteUserSummary_Export";
var doc = _commonDocumentRepository.AsQueryable(true).FirstOrDefault(t => t.Code == code); var data = (await _trialRepository.Where(t => t.Id == trialId).IgnoreQueryFilters().ProjectTo<TrialSiteUserSummaryExportDto>(_mapper.ConfigurationProvider).FirstOrDefaultAsync()).IfNullThrowException();
if (doc == null) var groupSelectIdQuery =
{ _trialSiteSurveyRepository.Where(t => t.TrialId == trialId)
throw new Exception("当前code 没要找到对应的导出模板文件"); .GroupBy(t => t.SiteId)
} .Select(g => g.OrderByDescending(u => u.CreateTime).Select(t => t.Id).First());
var rootPath = Directory.GetParent(_hostEnvironment.ContentRootPath.TrimEnd('\\')).FullName; var query = _trialSiteUserSurveyRepository
.Where(t => groupSelectIdQuery.Contains(t.TrialSiteSurveyId))
.ProjectTo<TrialSiteUserSummaryDto>(_mapper.ConfigurationProvider);
var filePath = Path.Combine(rootPath, doc.Path.Trim('/')); data.TrialSiteUserList = await query.ToListAsync();
if (!System.IO.File.Exists(filePath)) var exportInfo = data;
{
throw new Exception("服务器本地不存在该路径文件");
}
object exportInfo = default;
if (isSiteUserNotAll)
{
exportInfo = (await _trialRepository.Where(t => t.Id == trialId).IgnoreQueryFilters().ProjectTo<TrialSiteUserExportDto>(_mapper.ConfigurationProvider).FirstOrDefaultAsync()).IfNullThrowException();
}
else
{
var data = (await _trialRepository.Where(t => t.Id == trialId).IgnoreQueryFilters().ProjectTo<TrialSiteUserSummaryExportDto>(_mapper.ConfigurationProvider).FirstOrDefaultAsync()).IfNullThrowException();
var groupSelectIdQuery =
_trialSiteSurveyRepository.Where(t => t.TrialId == trialId && t.IsDeleted == false)
.GroupBy(t => t.SiteId)
.Select(g => g.OrderByDescending(u => u.CreateTime).Select(t => t.Id).First());
var query = _trialSiteUserSurveyRepository
.Where(t => groupSelectIdQuery.Contains(t.TrialSiteSurveyId))
.ProjectTo<TrialSiteUserSummaryDto>(_mapper.ConfigurationProvider);
data.TrialSiteUserList = await query.ToListAsync();
exportInfo = data;
}
return await ExcelExportHelper.DataExportAsync(StaticData.TrialSiteUserSummary_Export, exportInfo, _commonDocumentRepository, _hostEnvironment);
//模板路径
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
} }
#endregion
/// <summary>Pannel 进去 SiteTab </summary> /// <summary>Pannel 进去 SiteTab </summary>
[HttpPost] [HttpPost]

View File

@ -200,11 +200,17 @@ namespace IRaCIS.Core.Application.Service
CreateMap<TrialExternalUserConfirm, TrialSiteUserSurvey>(); CreateMap<TrialExternalUserConfirm, TrialSiteUserSurvey>();
CreateMap<Trial, TrialUserExportDTO>();
CreateMap<Trial, TrialSiteUserExportDto>(); CreateMap<Trial, TrialUserExportDTO>()
.ForMember(t=>t.TrialUserList,u=>u.Ignore());
CreateMap<Trial, TrialSiteUserExportDto>()
.ForMember(t => t.TrialSiteUserList, u => u.Ignore());
CreateMap<TrialSiteUser, SiteUserExportDTO>().IncludeMembers(t=>t.User) CreateMap<TrialSiteUser, SiteUserExportDTO>().IncludeMembers(t=>t.User)
.ForMember(t => t.TrialSiteCode, u => u.MapFrom(c => c.TrialSite.TrialSiteCode)) .ForMember(t => t.TrialSiteCode, u => u.MapFrom(c => c.TrialSite.TrialSiteCode))
.ForMember(t => t.TrialSiteAliasName, u => u.MapFrom(c => c.TrialSite.TrialSiteAliasName)) .ForMember(t => t.TrialSiteAliasName, u => u.MapFrom(c => c.TrialSite.TrialSiteAliasName))

View File

@ -67,6 +67,19 @@
public const string Anonymize_AddIRCInfoFiled = "Anonymize_AddIRCInfoFiled"; public const string Anonymize_AddIRCInfoFiled = "Anonymize_AddIRCInfoFiled";
#endregion
#region 项目人员导出
public const string TrialSiteUserList_Export = "TrialSiteUserList_Export";
public const string TrialSiteUserSummary_Export = "TrialSiteUserSummary_Export";
public const string TrialUserList_Export = "TrialUserList_Export";
#endregion #endregion
} }