Merge branch 'Test_IRC_Net8' of https://gitea.frp.extimaging.com/XCKJ/irc-netcore-api into Test_IRC_Net8
continuous-integration/drone/push Build is passing
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -986,19 +986,28 @@
|
||||
ExploreRecommendService
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:IRaCIS.Core.Application.Service.FileService.CreateOfficialResumeZip(System.Int32,System.Guid[])">
|
||||
<member name="M:IRaCIS.Core.Application.Service.FileService.GetOfficialResume(IRaCIS.Core.Application.Service.GetDoctorPathCommand,IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.Attachment})">
|
||||
<summary>
|
||||
打包医生官方简历
|
||||
New 医生首页 多选 获取多个医生信息+文件路径列表 医生压缩包名称 doctorCode + "_" + doctorName _(时间戳或者随机的Guid)
|
||||
</summary>
|
||||
<param name="language"></param>
|
||||
<param name="doctorIds"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IRaCIS.Core.Application.Service.FileService.CreateDoctorsAllAttachmentZip(System.Guid[])">
|
||||
<member name="M:IRaCIS.Core.Application.Service.FileService.GetTrialDoctorOfficialResume(IRaCIS.Core.Application.Service.GetDoctorPathCommand,IRaCIS.Application.Interfaces.IDoctorService,IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.Attachment})">
|
||||
<summary>
|
||||
打包医生的所有附件
|
||||
New 项目入组 勾选获取简历路径
|
||||
</summary>
|
||||
<param name="doctorIds"></param>
|
||||
<param name="command"></param>
|
||||
<param name="_doctorService"></param>
|
||||
<param name="_attachmentrepository"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IRaCIS.Core.Application.Service.FileService.GetDoctorAttachment(IRaCIS.Core.Application.Service.GetDoctoreAttachPathCommand,IRaCIS.Application.Interfaces.IDoctorService,IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.Attachment})">
|
||||
<summary>
|
||||
new 医生详情 勾选或者下载文件路径
|
||||
</summary>
|
||||
<param name="command"></param>
|
||||
<param name="_doctorService"></param>
|
||||
<param name="_attachmentrepository"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:IRaCIS.Core.Application.Service.InternationalizationService">
|
||||
|
||||
@@ -2,203 +2,122 @@
|
||||
using IRaCIS.Core.Application.Helper;
|
||||
using IRaCIS.Core.Infrastructure;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using System.Text;
|
||||
|
||||
namespace IRaCIS.Core.Application.Service
|
||||
{
|
||||
public class FileService(
|
||||
IDoctorService _doctorService,
|
||||
IAttachmentService _attachmentService,
|
||||
IWebHostEnvironment _hostEnvironment) : IFileService
|
||||
|
||||
[ApiExplorerSettings(GroupName = "Common")]
|
||||
public class FileService : BaseService
|
||||
{
|
||||
private string defaultUploadFilePath = FileStoreHelper.GetIRaCISRootPath(_hostEnvironment);
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 打包医生官方简历
|
||||
/// New 医生首页 多选 获取多个医生信息+文件路径列表 医生压缩包名称 doctorCode + "_" + doctorName _(时间戳或者随机的Guid)
|
||||
/// </summary>
|
||||
/// <param name="language"></param>
|
||||
/// <param name="doctorIds"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<string> CreateOfficialResumeZip(int language, Guid[] doctorIds)
|
||||
[HttpPost]
|
||||
public async Task<IResponseOutput<List<DoctorDownloadInfo>>> GetOfficialResume(GetDoctorPathCommand command,
|
||||
[FromServices] IRepository<Attachment> _attachmentrepository)
|
||||
{
|
||||
|
||||
//准备下载文件的临时路径
|
||||
var guidStr = Guid.NewGuid().ToString();
|
||||
|
||||
string uploadFolderPath = Path.Combine(FileStoreHelper.GetIRaCISRootDataFolder(_hostEnvironment), "UploadFile");
|
||||
|
||||
|
||||
|
||||
var tempSavePath = Path.Combine(uploadFolderPath, "temp", guidStr); //待压缩的文件夹,将需要下载的文件拷贝到此文件夹
|
||||
if (!Directory.Exists(tempSavePath))
|
||||
{
|
||||
Directory.CreateDirectory(tempSavePath);
|
||||
}
|
||||
|
||||
//找到服务器简历路径 循环拷贝简历到临时路径
|
||||
foreach (var doctorId in doctorIds)
|
||||
{
|
||||
var doctor = await _doctorService.GetBasicInfo(doctorId);
|
||||
var doctorName = doctor.FirstName + "_" + doctor.LastName;
|
||||
|
||||
//找官方简历存在服务器的相对路径
|
||||
var sourceCvPath = await _attachmentService.GetDoctorOfficialCV(language, doctorId);
|
||||
if (!string.IsNullOrWhiteSpace(sourceCvPath))
|
||||
var list = await _attachmentrepository.Where(t => command.DoctorIdList.Contains(t.DoctorId) && command.Language == t.Language).GroupBy(t => new { Name = t.Doctor.FirstName + "_" + t.Doctor.LastName, ReviewerCode = t.Doctor.ReviewerCode, t.DoctorId })
|
||||
.Select(g => new DoctorDownloadInfo()
|
||||
{
|
||||
//服务器简历文件实际路径
|
||||
//var sourceCvFullPath = HostingEnvironment.MapPath(sourceCvPath);
|
||||
var sourceCvPathTemp = sourceCvPath.Substring(1, sourceCvPath.Length - 1);//.Replace('/','\\');
|
||||
string sourceCvFullPath = Path.Combine(defaultUploadFilePath, sourceCvPathTemp);
|
||||
Id = g.Key.DoctorId,
|
||||
Name = g.Key.Name,
|
||||
ReviewerCode = g.Key.ReviewerCode,
|
||||
FileList = g.Select(t => new DownloadFileInfo() { FileName = t.FileName, Path = t.Path }).ToList()
|
||||
}).ToListAsync();
|
||||
|
||||
var arr = sourceCvPath.Split('.');
|
||||
string extensionName = arr[arr.Length - 1]; //得到扩展名
|
||||
return ResponseOutput.Ok(list);
|
||||
|
||||
//需要拷贝到的路径
|
||||
var doctorPath = Path.Combine(tempSavePath, doctor.ReviewerCode.ToString() + "_" + doctorName + "." + extensionName);
|
||||
|
||||
if (File.Exists(sourceCvFullPath))
|
||||
{
|
||||
File.Copy(sourceCvFullPath, doctorPath, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//创建ZIP
|
||||
DateTime now = DateTime.Now;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append(now.Year).Append(now.Month.ToString().PadLeft(2, '0')).Append(now.Day.ToString().PadLeft(2, '0'))
|
||||
.Append(now.Hour.ToString().PadLeft(2, '0')).Append(now.Minute.ToString().PadLeft(2, '0'))
|
||||
.Append(now.Second.ToString().PadLeft(2, '0')).Append(now.Millisecond.ToString().PadLeft(3, '0'));
|
||||
|
||||
string targetZipPath = Path.Combine(uploadFolderPath, "CV_" + sb.ToString() + ".zip");
|
||||
ZipHelper.CreateZip(tempSavePath, targetZipPath);
|
||||
|
||||
//返回Zip路径
|
||||
return Path.Combine("/IRaCISData/UploadFile/", "CV_" + sb.ToString() + ".zip");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 打包医生的所有附件
|
||||
/// New 项目入组 勾选获取简历路径
|
||||
/// </summary>
|
||||
/// <param name="doctorIds"></param>
|
||||
/// <param name="command"></param>
|
||||
/// <param name="_doctorService"></param>
|
||||
/// <param name="_attachmentrepository"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<string> CreateDoctorsAllAttachmentZip(Guid[] doctorIds)
|
||||
[HttpPost]
|
||||
public async Task<IResponseOutput<List<DoctorDownloadInfo>>> GetTrialDoctorOfficialResume(GetDoctorPathCommand command,
|
||||
[FromServices] IDoctorService _doctorService,
|
||||
[FromServices] IRepository<Attachment> _attachmentrepository)
|
||||
{
|
||||
#region 老版本 存储在服务器
|
||||
//准备下载文件的临时路径
|
||||
var guidStr = Guid.NewGuid().ToString();
|
||||
//string uploadFolderPath = HostingEnvironment.MapPath("/UploadFile/");
|
||||
string uploadFolderPath = Path.Combine(FileStoreHelper.GetIRaCISRootDataFolder(_hostEnvironment), "UploadFile");
|
||||
var tempSavePath = Path.Combine(uploadFolderPath, "temp", guidStr); //待压缩的文件夹,将需要下载的文件拷贝到此文件夹
|
||||
if (!Directory.Exists(tempSavePath))
|
||||
{
|
||||
Directory.CreateDirectory(tempSavePath);
|
||||
}
|
||||
|
||||
|
||||
foreach (var doctorId in doctorIds)
|
||||
{
|
||||
//获取医生基本信息
|
||||
var doctor = await _doctorService.GetBasicInfo(doctorId);
|
||||
var doctorName = doctor.FirstName + "_" + doctor.LastName;
|
||||
var doctorCode = doctor.ReviewerCode;
|
||||
|
||||
var doctorDestPath = Path.Combine(tempSavePath, doctorCode + "_" + doctorName);
|
||||
if (!Directory.Exists(doctorDestPath))
|
||||
var list = await _attachmentrepository.Where(t => command.DoctorIdList.Contains(t.DoctorId) && command.Language == t.Language && t.IsOfficial && t.Type.Equals("Resume")).GroupBy(t => new { Name = t.Doctor.FirstName + "_" + t.Doctor.LastName, ReviewerCode = t.Doctor.ReviewerCode, t.DoctorId })
|
||||
.Select(g => new DoctorDownloadInfo()
|
||||
{
|
||||
Directory.CreateDirectory(doctorDestPath);
|
||||
}
|
||||
Id = g.Key.DoctorId,
|
||||
Name = g.Key.Name,
|
||||
ReviewerCode = g.Key.ReviewerCode,
|
||||
FileList = g.Select(t => new DownloadFileInfo() { FileName = t.FileName, Path = t.Path }).ToList()
|
||||
}).ToListAsync();
|
||||
|
||||
//服务器上传后的源路径
|
||||
string doctorFileSourcePath = Path.Combine(uploadFolderPath, doctorId.ToString());
|
||||
|
||||
if (Directory.Exists(doctorFileSourcePath))
|
||||
{
|
||||
CopyDirectory(doctorFileSourcePath, doctorDestPath);
|
||||
}
|
||||
}
|
||||
string target = Guid.NewGuid().ToString();
|
||||
string targetPath = Path.Combine(uploadFolderPath, target + ".zip");
|
||||
ZipHelper.CreateZip(tempSavePath, targetPath);
|
||||
return Path.Combine("/IRaCISData/UploadFile/", target + ".zip");
|
||||
#endregion
|
||||
return ResponseOutput.Ok(list);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public async Task<string> CreateZipPackageByAttachment(Guid doctorId, Guid[] attachmentIds)
|
||||
{
|
||||
var doctor = await _doctorService.GetBasicInfo(doctorId);
|
||||
var doctorName = doctor.FirstName + "_" + doctor.LastName;
|
||||
|
||||
Guid temp = Guid.NewGuid();
|
||||
//string root = HostingEnvironment.MapPath("/UploadFile/"); //文件根目录
|
||||
string root = Path.Combine(defaultUploadFilePath, "UploadFile");
|
||||
|
||||
var tempPath = Path.Combine(root, "temp", temp.ToString(), doctor.ReviewerCode + doctorName); //待压缩的文件夹,将需要下载的文件拷贝到此文件夹
|
||||
var packagePath = Path.Combine(root, "temp", temp.ToString()); //打包目录
|
||||
if (!Directory.Exists(tempPath))
|
||||
{
|
||||
Directory.CreateDirectory(tempPath);
|
||||
}
|
||||
var attachemnts = (await _attachmentService.GetAttachments(doctorId)).Where(a => attachmentIds.Contains(a.Id));
|
||||
|
||||
foreach (var item in attachemnts)
|
||||
{
|
||||
var arr = item.Path.Trim().Split('/');
|
||||
var myPath = string.Empty;
|
||||
var myFile = string.Empty;
|
||||
//需要改进
|
||||
if (arr.Length > 0)
|
||||
{
|
||||
myFile = arr[arr.Length - 1];
|
||||
foreach (var arrItem in arr)
|
||||
{
|
||||
if (arrItem != string.Empty && !"UploadFile".Equals(arrItem))
|
||||
{
|
||||
myPath += (arrItem + "/");
|
||||
}
|
||||
}
|
||||
myPath = myPath.TrimEnd('/');
|
||||
}
|
||||
var sourcePath = Path.Combine(root, myPath);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(sourcePath) && File.Exists(sourcePath))
|
||||
{
|
||||
File.Copy(sourcePath, Path.Combine(tempPath, myFile), true);
|
||||
}
|
||||
}
|
||||
string target = Guid.NewGuid().ToString();
|
||||
string targetPath = Path.Combine(root, target + ".zip");
|
||||
ZipHelper.CreateZip(packagePath, targetPath);
|
||||
|
||||
return Path.Combine("/IRaCISData/UploadFile/", target + ".zip");
|
||||
}
|
||||
|
||||
private static void CopyDirectory(string srcPath, string destPath)
|
||||
/// <summary>
|
||||
/// new 医生详情 勾选或者下载文件路径
|
||||
/// </summary>
|
||||
/// <param name="command"></param>
|
||||
/// <param name="_doctorService"></param>
|
||||
/// <param name="_attachmentrepository"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<IResponseOutput<DoctorDownloadInfo>> GetDoctorAttachment(GetDoctoreAttachPathCommand command,
|
||||
[FromServices] IDoctorService _doctorService,
|
||||
[FromServices] IRepository<Attachment> _attachmentrepository)
|
||||
{
|
||||
|
||||
DirectoryInfo dir = new DirectoryInfo(srcPath);
|
||||
FileSystemInfo[] fileInfoArray = dir.GetFileSystemInfos(); //获取目录下(不包含子目录)的文件和子目录
|
||||
foreach (FileSystemInfo fileInfo in fileInfoArray)
|
||||
{
|
||||
if (fileInfo is DirectoryInfo) //判断是否文件夹
|
||||
var find = await _attachmentrepository.Where(t => command.DoctorId == t.DoctorId && command.AttachmentIdList.Contains(t.Id)).GroupBy(t => new { Name = t.Doctor.FirstName + "_" + t.Doctor.LastName, ReviewerCode = t.Doctor.ReviewerCode, t.DoctorId })
|
||||
.Select(g => new DoctorDownloadInfo()
|
||||
{
|
||||
if (!Directory.Exists(destPath + "\\" + fileInfo.Name))
|
||||
{
|
||||
Directory.CreateDirectory(destPath + "\\" + fileInfo.Name); //目标目录下不存在此文件夹即创建子文件夹
|
||||
}
|
||||
CopyDirectory(fileInfo.FullName, destPath + "\\" + fileInfo.Name); //递归调用复制子文件夹
|
||||
}
|
||||
else
|
||||
{
|
||||
File.Copy(fileInfo.FullName, destPath + "\\" + fileInfo.Name, true); //不是文件夹即复制文件,true表示可以覆盖同名文件
|
||||
}
|
||||
}
|
||||
Id = g.Key.DoctorId,
|
||||
Name = g.Key.Name,
|
||||
ReviewerCode = g.Key.ReviewerCode,
|
||||
FileList = g.Select(t => new DownloadFileInfo() { FileName = t.FileName, Path = t.Path }).ToList()
|
||||
}).FirstOrDefaultAsync();
|
||||
|
||||
return ResponseOutput.Ok(find);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#region DTO
|
||||
public class DoctorDownloadInfo
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string ReviewerCode { get; set; }
|
||||
|
||||
public List<DownloadFileInfo> FileList { get; set; }
|
||||
}
|
||||
public class DownloadFileInfo
|
||||
{
|
||||
public string FileName { get; set; }
|
||||
|
||||
public string Path { get; set; }
|
||||
}
|
||||
|
||||
public class GetDoctorPathCommand
|
||||
{
|
||||
public int Language { get; set; }
|
||||
|
||||
public List<Guid> DoctorIdList { get; set; }
|
||||
}
|
||||
|
||||
public class GetDoctoreAttachPathCommand
|
||||
{
|
||||
public Guid DoctorId { get; set; }
|
||||
public List<Guid> AttachmentIdList { get; set; }
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user