人员导出 加条件修改
parent
74dcd12285
commit
1844a15879
|
@ -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
|
||||
|
||||
}
|
||||
}
|
|
@ -62,6 +62,8 @@ namespace IRaCIS.Core.Application.Contracts
|
|||
public TrialSiteSurveyView TrialSiteSurvey { get; set; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
public class TrialSiteUserSurveyAllQuery : PageInput
|
||||
{
|
||||
[NotDefault]
|
||||
|
@ -78,7 +80,6 @@ namespace IRaCIS.Core.Application.Contracts
|
|||
|
||||
public string FormWriterKeyInfo { get; set; } = string.Empty;
|
||||
|
||||
//public string UserKeyInfo { get; set; } = string.Empty;
|
||||
|
||||
public string UserName { get; set; } = string.Empty;
|
||||
|
||||
|
|
|
@ -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 Guid TrialId { get; set; }
|
||||
|
|
|
@ -211,13 +211,10 @@ namespace IRaCIS.Application.Contracts
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
public class TrialMaintenanceQuery : PageInput
|
||||
public class TrialMaintenanceExportQuery
|
||||
{
|
||||
public Guid TrialId { get; set; } = Guid.Empty;
|
||||
public string UserRealName { get; set; } = string.Empty;
|
||||
//public string UserType { get; set; } = string.Empty;
|
||||
|
||||
public Guid? UserTypeId { get; set; }
|
||||
|
||||
|
@ -226,11 +223,20 @@ namespace IRaCIS.Application.Contracts
|
|||
public string OrganizationName { get; set; } = String.Empty;
|
||||
|
||||
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; }
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,15 +1,11 @@
|
|||
using IRaCIS.Application.Contracts;
|
||||
using IRaCIS.Core.Infra.EFCore;
|
||||
using IRaCIS.Core.Application.Filter;
|
||||
using IRaCIS.Core.Domain.Share;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using IRaCIS.Core.Application.Contracts.DTO;
|
||||
using IRaCIS.Application.Interfaces;
|
||||
using Magicodes.ExporterAndImporter.Core;
|
||||
using Magicodes.ExporterAndImporter.Excel;
|
||||
using Magicodes.ExporterAndImporter.Excel.AspNetCore;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using MiniExcelLibs;
|
||||
using IRaCIS.Core.Application.Service;
|
||||
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
namespace IRaCIS.Application.Services
|
||||
|
@ -29,67 +25,36 @@ namespace IRaCIS.Application.Services
|
|||
/// <summary>
|
||||
/// 项目参与人员导出
|
||||
/// </summary>
|
||||
/// <param name="trialId"></param>
|
||||
/// <param name="param"></param>
|
||||
/// <param name="_commonDocumentRepository"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="Exception"></exception>
|
||||
[HttpGet]
|
||||
[HttpPost]
|
||||
[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)
|
||||
{
|
||||
throw new Exception("当前code 没要找到对应的导出模板文件");
|
||||
}
|
||||
var exportInfo = (await _trialRepository.Where(t => t.Id == param.TrialId).IgnoreQueryFilters().ProjectTo<TrialUserExportDTO>(_mapper.ConfigurationProvider).FirstOrDefaultAsync()).IfNullThrowException();
|
||||
|
||||
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))
|
||||
{
|
||||
throw new Exception("服务器本地不存在该路径文件");
|
||||
}
|
||||
return await ExcelExportHelper.DataExportAsync(StaticData.TrialUserList_Export, exportInfo, _commonDocumentRepository, _hostEnvironment);
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
using IRaCIS.Application.Contracts;
|
||||
using IRaCIS.Core.Domain.Share;
|
||||
using IRaCIS.Core.Infrastructure.ExpressionExtend;
|
||||
using IRaCIS.Core.Application.Filter;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using IRaCIS.Core.Application.Contracts.DTO;
|
||||
using IRaCIS.Core.Application.Contracts;
|
||||
using IRaCIS.Core.Application.Interfaces;
|
||||
using IRaCIS.Core.Application.Service;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using MiniExcelLibs;
|
||||
|
||||
namespace IRaCIS.Core.Application.Services
|
||||
{
|
||||
|
@ -29,56 +28,62 @@ namespace IRaCIS.Core.Application.Services
|
|||
}
|
||||
|
||||
|
||||
#region 导出列表
|
||||
|
||||
/// <summary>
|
||||
/// Site用户列表导出
|
||||
/// </summary>
|
||||
/// <param name="trialId"></param>
|
||||
/// <param name="isSiteUserNotAll">isAllSiteUser true : site用户列表,false :Site调研汇总表</param>
|
||||
/// <param name="param"></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="_trialSiteSurveyRepository"></param>
|
||||
/// <param name="_trialSiteUserSurveyRepository"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="Exception"></exception>
|
||||
[HttpGet, Route("{trialId:guid}/{isSiteUserNotAll:bool}")]
|
||||
[HttpGet, Route("{trialId:guid}")]
|
||||
[AllowAnonymous]
|
||||
public async Task<IActionResult> TrialSiteUserListExport(Guid trialId, bool isSiteUserNotAll,
|
||||
public async Task<IActionResult> TrialSiteUserSummaryListExport(Guid trialId,
|
||||
[FromServices] IRepository<CommonDocument> _commonDocumentRepository,
|
||||
[FromServices] IRepository<TrialSiteSurvey> _trialSiteSurveyRepository,
|
||||
[FromServices] IRepository<TrialSiteUserSurvey> _trialSiteUserSurveyRepository
|
||||
)
|
||||
{
|
||||
var code = isSiteUserNotAll ? "TrialSiteUserList_Export":"TrialSiteUserSummary_Export";
|
||||
|
||||
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("服务器本地不存在该路径文件");
|
||||
}
|
||||
|
||||
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)
|
||||
_trialSiteSurveyRepository.Where(t => t.TrialId == trialId)
|
||||
.GroupBy(t => t.SiteId)
|
||||
.Select(g => g.OrderByDescending(u => u.CreateTime).Select(t => t.Id).First());
|
||||
|
||||
|
@ -88,30 +93,19 @@ namespace IRaCIS.Core.Application.Services
|
|||
|
||||
data.TrialSiteUserList = await query.ToListAsync();
|
||||
|
||||
exportInfo = data;
|
||||
var 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
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -200,11 +200,17 @@ namespace IRaCIS.Core.Application.Service
|
|||
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)
|
||||
.ForMember(t => t.TrialSiteCode, u => u.MapFrom(c => c.TrialSite.TrialSiteCode))
|
||||
.ForMember(t => t.TrialSiteAliasName, u => u.MapFrom(c => c.TrialSite.TrialSiteAliasName))
|
||||
|
|
|
@ -67,6 +67,19 @@
|
|||
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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue