|
|
|
@ -1,4 +1,11 @@ |
|
|
|
|
using Org.BouncyCastle.Utilities; |
|
|
|
|
using DinkToPdf; |
|
|
|
|
using DinkToPdf.Contracts; |
|
|
|
|
using Microsoft.AspNetCore.Hosting; |
|
|
|
|
using Microsoft.Extensions.Hosting; |
|
|
|
|
using MySqlX.XDevAPI.Common; |
|
|
|
|
using Org.BouncyCastle.Utilities; |
|
|
|
|
using SharpCompress.Common; |
|
|
|
|
using System.IO.Compression; |
|
|
|
|
using static Tiobon.Core.Model.Consts; |
|
|
|
|
|
|
|
|
|
namespace Tiobon.Core.Services; |
|
|
|
@ -38,6 +45,9 @@ public class Ghrh_ResumeServices : BaseServices<Ghrh_Resume, Ghrh_ResumeDto, Ins |
|
|
|
|
/// </summary> |
|
|
|
|
private readonly IGhrh_InterviewLogServices _ghrh_InterviewLogServices; |
|
|
|
|
private readonly IGhrh_HumanRequestServices _ghrh_HumanRequestServices; |
|
|
|
|
private readonly IWebHostEnvironment Env; |
|
|
|
|
private readonly IConverter _converter; |
|
|
|
|
private readonly IWebHostEnvironment _hostingEnvironment; |
|
|
|
|
public Ghrh_ResumeServices(ICaching caching, |
|
|
|
|
IBaseRepository<Ghrh_Resume> dal, |
|
|
|
|
IGhrh_ResumeEduBGServices ghre_ResumeEduBGServices, |
|
|
|
@ -50,7 +60,9 @@ public class Ghrh_ResumeServices : BaseServices<Ghrh_Resume, Ghrh_ResumeDto, Ins |
|
|
|
|
IGhrh_InterviewRecordServices ghre_InterviewRecordServices, |
|
|
|
|
IGhrh_InterviewLogServices ghrh_InterviewLogServices, |
|
|
|
|
IGhrh_HumanRequestServices ghrh_HumanRequestServices, |
|
|
|
|
IGhrh_ResumeWorkExpServices ghre_ResumeWorkExpServices) |
|
|
|
|
IConverter converter, |
|
|
|
|
IWebHostEnvironment hostingEnvironment, |
|
|
|
|
IGhrh_ResumeWorkExpServices ghre_ResumeWorkExpServices, IWebHostEnvironment env) |
|
|
|
|
{ |
|
|
|
|
this._dal = dal; |
|
|
|
|
base.BaseDal = dal; |
|
|
|
@ -66,6 +78,9 @@ public class Ghrh_ResumeServices : BaseServices<Ghrh_Resume, Ghrh_ResumeDto, Ins |
|
|
|
|
_ghrh_ResumeWorkExpServices = ghre_ResumeWorkExpServices; |
|
|
|
|
_ghrh_InterviewLogServices = ghrh_InterviewLogServices; |
|
|
|
|
_ghrh_HumanRequestServices = ghrh_HumanRequestServices; |
|
|
|
|
Env = env; |
|
|
|
|
_converter = converter; |
|
|
|
|
_hostingEnvironment = hostingEnvironment; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
@ -2364,6 +2379,136 @@ WHERE A.IsEnable = 1 AND C.IsEnable = 1"; |
|
|
|
|
} |
|
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
#region 简历下载 |
|
|
|
|
public async Task<ServiceResult<string>> Download(List<long> ids) |
|
|
|
|
{ |
|
|
|
|
string frontUrl = AppSettings.app(["Startup", "FrontUrl"]); |
|
|
|
|
string path = string.Empty; |
|
|
|
|
frontUrl += "/Advanced"; |
|
|
|
|
if (Env.IsDevelopment()) |
|
|
|
|
frontUrl = "http://localhost:9292"; |
|
|
|
|
//} |
|
|
|
|
|
|
|
|
|
if (ids.Count == 1) |
|
|
|
|
{ |
|
|
|
|
var entity = await base.QueryById(ids[0]); |
|
|
|
|
var returnData = await HttpHelper.GetAsync(frontUrl + "/api/Ghrh_ResumeTemplatePreview/" + ids[0]); |
|
|
|
|
var globalSettings = new GlobalSettings |
|
|
|
|
{ |
|
|
|
|
ColorMode = ColorMode.Color, |
|
|
|
|
Orientation = Orientation.Portrait, |
|
|
|
|
PaperSize = PaperKind.A4, |
|
|
|
|
DocumentTitle = "PDF Report", |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
var objectSettings = new ObjectSettings |
|
|
|
|
{ |
|
|
|
|
PagesCount = true, |
|
|
|
|
HtmlContent = returnData, |
|
|
|
|
WebSettings = { DefaultEncoding = "utf-8" }, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
var pdf = new HtmlToPdfDocument() |
|
|
|
|
{ |
|
|
|
|
GlobalSettings = globalSettings, |
|
|
|
|
Objects = { objectSettings } |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
var fileBytes = _converter.Convert(pdf); |
|
|
|
|
string pathHeader = "wwwroot/files/pdf_files"; |
|
|
|
|
if (!Directory.Exists(pathHeader)) |
|
|
|
|
Directory.CreateDirectory(pathHeader); |
|
|
|
|
var ms = new MemoryStream(fileBytes); |
|
|
|
|
var file = new FormFile(ms, 0, ms.Length, Path.GetFileNameWithoutExtension(pathHeader), Path.GetFileName(pathHeader)); |
|
|
|
|
|
|
|
|
|
var fileName = entity.StaffName + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".pdf"; |
|
|
|
|
await using (var fs = System.IO.File.Create(pathHeader + "/" + fileName)) |
|
|
|
|
{ |
|
|
|
|
await file.CopyToAsync(fs); |
|
|
|
|
fs.Flush(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
path = "/Advanced/files/pdf_files/" + fileName; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
var files = new List<string>(); |
|
|
|
|
string pathHeader = "/files/pdf_files/" + SnowFlakeSingle.Instance.NextId() + "/"; |
|
|
|
|
if (!Directory.Exists("wwwroot" + pathHeader)) |
|
|
|
|
Directory.CreateDirectory("wwwroot" + pathHeader); |
|
|
|
|
|
|
|
|
|
for (int i = 0; i < ids.Count; i++) |
|
|
|
|
{ |
|
|
|
|
var entity = await base.QueryById(ids[i]); |
|
|
|
|
var returnData = await HttpHelper.GetAsync(frontUrl + "/api/Ghrh_ResumeTemplatePreview/" + ids[0]); |
|
|
|
|
var globalSettings = new GlobalSettings |
|
|
|
|
{ |
|
|
|
|
ColorMode = ColorMode.Color, |
|
|
|
|
Orientation = Orientation.Portrait, |
|
|
|
|
PaperSize = PaperKind.A4, |
|
|
|
|
DocumentTitle = "PDF Report", |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
var objectSettings = new ObjectSettings |
|
|
|
|
{ |
|
|
|
|
PagesCount = true, |
|
|
|
|
HtmlContent = returnData, |
|
|
|
|
WebSettings = { DefaultEncoding = "utf-8" }, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
var pdf = new HtmlToPdfDocument() |
|
|
|
|
{ |
|
|
|
|
GlobalSettings = globalSettings, |
|
|
|
|
Objects = { objectSettings } |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
var fileBytes = _converter.Convert(pdf); |
|
|
|
|
|
|
|
|
|
var fileName = pathHeader + entity.StaffName + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".pdf"; |
|
|
|
|
files.Add(_hostingEnvironment.WebRootPath + fileName); |
|
|
|
|
var ms = new MemoryStream(fileBytes); |
|
|
|
|
var file = new FormFile(ms, 0, ms.Length, Path.GetFileNameWithoutExtension("wwwroot" + pathHeader), Path.GetFileName("wwwroot" + pathHeader)); |
|
|
|
|
|
|
|
|
|
await using (var fs = System.IO.File.Create("wwwroot" + fileName)) |
|
|
|
|
{ |
|
|
|
|
await file.CopyToAsync(fs); |
|
|
|
|
fs.Flush(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
path = $"/files/pdf_files/简历_{DateTime.Now.ToString("yyyyMMddHHmmss")}.zip"; |
|
|
|
|
CreateZip($"{_hostingEnvironment.WebRootPath}{path}", files.ToArray()); |
|
|
|
|
|
|
|
|
|
FileHelper.DeleteFolder($"{_hostingEnvironment.WebRootPath}{pathHeader}"); |
|
|
|
|
path = "/Advanced" + path; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ServiceResult<string>.OprateSuccess(path); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static void CreateZip(string zipPath, string[] filesToZip) |
|
|
|
|
{ |
|
|
|
|
if (File.Exists(zipPath)) |
|
|
|
|
{ |
|
|
|
|
throw new IOException("File already exists."); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
using (FileStream zipFile = new FileStream(zipPath, FileMode.Create)) |
|
|
|
|
{ |
|
|
|
|
using (ZipArchive zipArchive = new ZipArchive(zipFile, ZipArchiveMode.Create)) |
|
|
|
|
{ |
|
|
|
|
foreach (string file in filesToZip) |
|
|
|
|
{ |
|
|
|
|
if (File.Exists(file)) |
|
|
|
|
{ |
|
|
|
|
ZipArchiveEntry entry = zipArchive.CreateEntryFromFile(file, Path.GetFileName(file)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
#region 通用方法 |
|
|
|
|
/// <summary> |
|
|
|
|
/// 记录日志 |
|
|
|
|