利用第三方服务转pdf
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
f97cfd58c0
commit
4ab4fbd599
|
@ -72,7 +72,9 @@
|
||||||
"ReadingRestTimeMin": 10,
|
"ReadingRestTimeMin": 10,
|
||||||
"IsNeedChangePassWord": true,
|
"IsNeedChangePassWord": true,
|
||||||
|
|
||||||
"ChangePassWordDays": 90
|
"ChangePassWordDays": 90,
|
||||||
|
|
||||||
|
"ThirdPdfUrl": "http://106.14.89.110:30088/api/v1/convert/file/pdf"
|
||||||
},
|
},
|
||||||
|
|
||||||
"SystemEmailSendConfig": {
|
"SystemEmailSendConfig": {
|
||||||
|
|
|
@ -34,6 +34,8 @@ public class ServiceVerifyConfigOption
|
||||||
[Description("修改密码的天数")]
|
[Description("修改密码的天数")]
|
||||||
public int ChangePassWordDays { get; set; }
|
public int ChangePassWordDays { get; set; }
|
||||||
|
|
||||||
|
public string ThirdPdfUrl { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SystemEmailSendConfig
|
public class SystemEmailSendConfig
|
||||||
|
|
|
@ -1,11 +1,18 @@
|
||||||
using System.Diagnostics;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using RestSharp;
|
||||||
|
using SharpCompress.Common;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace IRaCIS.Core.Application.Helper;
|
namespace IRaCIS.Core.Application.Helper;
|
||||||
|
|
||||||
public class FileConvertHelper
|
public class FileConvertHelper
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 镜像里面打入libreoffice 的方案
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="inputWordFilePath"></param>
|
||||||
|
/// <param name="outputPdfDir"></param>
|
||||||
static public void ConvertWordToPdf(string inputWordFilePath, string outputPdfDir)
|
static public void ConvertWordToPdf(string inputWordFilePath, string outputPdfDir)
|
||||||
{
|
{
|
||||||
// 设置 libreoffice 命令行参数
|
// 设置 libreoffice 命令行参数
|
||||||
|
@ -30,4 +37,88 @@ public class FileConvertHelper
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 返回文件字节数组
|
||||||
|
/// File.WriteAllBytes(outputFilePath, response.RawBytes); 直接将字节数组写入到本地某个路径
|
||||||
|
/// var stream = new MemoryStream(response.RawBytes); 直接变为内存流,给其他程序用也可以
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
static public async Task<byte[]> ThirdStirling_PDFWordToPdfAsync(string filePath)
|
||||||
|
{
|
||||||
|
|
||||||
|
var apiUrl = GetApiUrl();
|
||||||
|
|
||||||
|
var client = new RestClient(apiUrl);
|
||||||
|
|
||||||
|
var request = new RestRequest(apiUrl, Method.Post);
|
||||||
|
|
||||||
|
request.AddHeader("accept", "*/*");
|
||||||
|
|
||||||
|
// 直接上传文件,无需生成字节数组
|
||||||
|
request.AddFile("fileInput", filePath);
|
||||||
|
|
||||||
|
return await GetPDFByteArrayAsync(client, request);
|
||||||
|
}
|
||||||
|
|
||||||
|
static public async Task<byte[]> ThirdStirling_PDFWordToPdfAsync(byte[] fileBytes, string fileName)
|
||||||
|
{
|
||||||
|
|
||||||
|
var apiUrl = GetApiUrl();
|
||||||
|
var client = new RestClient(apiUrl);
|
||||||
|
|
||||||
|
var request = new RestRequest(apiUrl, Method.Post);
|
||||||
|
|
||||||
|
request.AddHeader("accept", "*/*");
|
||||||
|
|
||||||
|
// 添加文件流到请求
|
||||||
|
request.AddFile("fileInput", fileBytes, fileName);
|
||||||
|
|
||||||
|
return await GetPDFByteArrayAsync(client, request);
|
||||||
|
}
|
||||||
|
|
||||||
|
static private async Task<byte[]> GetPDFByteArrayAsync(RestClient client, RestRequest request)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// 发送请求并获取响应
|
||||||
|
var response = await client.ExecuteAsync(request);
|
||||||
|
|
||||||
|
// 检查请求是否成功
|
||||||
|
if (response.IsSuccessful)
|
||||||
|
{
|
||||||
|
return response.RawBytes ?? new byte[] { };
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine($"上传失败,错误代码: {response.StatusCode}, 错误消息: {response.ErrorMessage}");
|
||||||
|
|
||||||
|
return Array.Empty<byte>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine("发生异常: " + ex.Message);
|
||||||
|
|
||||||
|
return Array.Empty<byte>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static private string GetApiUrl()
|
||||||
|
{
|
||||||
|
|
||||||
|
var enviromentName = Environment.GetEnvironmentVariables()["ASPNETCORE_ENVIRONMENT"]?.ToString();
|
||||||
|
|
||||||
|
var configuration = new ConfigurationBuilder().AddJsonFile($"appsettings.{enviromentName}.json", false, false).Build();
|
||||||
|
|
||||||
|
// 手动绑定配置
|
||||||
|
var appSettings = new ServiceVerifyConfigOption();
|
||||||
|
configuration.GetSection("BasicSystemConfig").Bind(appSettings);
|
||||||
|
|
||||||
|
return appSettings.ThirdPdfUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12762,6 +12762,21 @@
|
||||||
<param name="userId"></param>
|
<param name="userId"></param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:IRaCIS.Core.Application.Helper.FileConvertHelper.ConvertWordToPdf(System.String,System.String)">
|
||||||
|
<summary>
|
||||||
|
镜像里面打入libreoffice 的方案
|
||||||
|
</summary>
|
||||||
|
<param name="inputWordFilePath"></param>
|
||||||
|
<param name="outputPdfDir"></param>
|
||||||
|
</member>
|
||||||
|
<member name="M:IRaCIS.Core.Application.Helper.FileConvertHelper.ThirdStirling_PDFWordToPdfAsync(System.String)">
|
||||||
|
<summary>
|
||||||
|
返回文件字节数组
|
||||||
|
File.WriteAllBytes(outputFilePath, response.RawBytes); 直接将字节数组写入到本地某个路径
|
||||||
|
var stream = new MemoryStream(response.RawBytes); 直接变为内存流,给其他程序用也可以
|
||||||
|
</summary>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
<member name="M:IRaCIS.Core.Application.Helper.FileStoreHelper.WriteFileAsync(System.IO.Stream,System.String)">
|
<member name="M:IRaCIS.Core.Application.Helper.FileStoreHelper.WriteFileAsync(System.IO.Stream,System.String)">
|
||||||
<summary>
|
<summary>
|
||||||
写文件导到磁盘
|
写文件导到磁盘
|
||||||
|
@ -12916,6 +12931,11 @@
|
||||||
加急阅片 IR 申请重阅 或者PM 申请重阅
|
加急阅片 IR 申请重阅 或者PM 申请重阅
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:IRaCIS.Core.Application.MassTransit.Consumer.UrgentIRApplyedReReadingConsumer.#ctor(IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.User},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.TrialUser},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.TaskMedicalReview},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.Trial},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.SubjectVisit},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.ReadingQuestionCriterionTrial},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.VisitTask},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.Dictionary},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.EmailNoticeConfig},Microsoft.Extensions.Options.IOptionsMonitor{IRaCIS.Core.Domain.Share.SystemEmailSendConfig})">
|
||||||
|
<summary>
|
||||||
|
加急阅片 IR 申请重阅 或者PM 申请重阅
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
<member name="T:IRaCIS.Core.Application.MassTransit.Consumer.UserSiteSurveySubmitedEventConsumer">
|
<member name="T:IRaCIS.Core.Application.MassTransit.Consumer.UserSiteSurveySubmitedEventConsumer">
|
||||||
<summary>
|
<summary>
|
||||||
用户提交 发送邮件 通知SPM 或者PM
|
用户提交 发送邮件 通知SPM 或者PM
|
||||||
|
@ -13042,17 +13062,17 @@
|
||||||
影像质控
|
影像质控
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="T:IRaCIS.Core.Application.MassTransit.Consumer.QCImageQuestionSchedule">
|
<member name="T:IRaCIS.Core.Application.MassTransit.Consumer.QCImageQuestionRecurringSchedule">
|
||||||
<summary>
|
<summary>
|
||||||
QC 影像质疑待处理
|
QC 影像质疑待处理
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="T:IRaCIS.Core.Application.MassTransit.Consumer.CRCImageQuestionSchedule">
|
<member name="T:IRaCIS.Core.Application.MassTransit.Consumer.CRCImageQuestionRecurringSchedule">
|
||||||
<summary>
|
<summary>
|
||||||
CRC 影像质疑
|
CRC 影像质疑
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="T:IRaCIS.Core.Application.MassTransit.Consumer.ImageQCSchedule">
|
<member name="T:IRaCIS.Core.Application.MassTransit.Consumer.ImageQCRecurringSchedule">
|
||||||
<summary>
|
<summary>
|
||||||
影像质控
|
影像质控
|
||||||
</summary>
|
</summary>
|
||||||
|
|
|
@ -1,14 +1,18 @@
|
||||||
using IRaCIS.Core.Domain;
|
using IRaCIS.Core.Application.Helper;
|
||||||
|
using IRaCIS.Core.Domain;
|
||||||
using IRaCIS.Core.Domain.Share;
|
using IRaCIS.Core.Domain.Share;
|
||||||
using MassTransit;
|
using MassTransit;
|
||||||
using MassTransit.Mediator;
|
using MassTransit.Mediator;
|
||||||
using MassTransit.Scheduling;
|
using MassTransit.Scheduling;
|
||||||
using Medallion.Threading;
|
using Medallion.Threading;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.StaticFiles;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
using RestSharp;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
@ -71,11 +75,76 @@ public class TestMasstransitService : BaseService
|
||||||
////发布后,不会立即进入消费者,消费者是另外的线程执行
|
////发布后,不会立即进入消费者,消费者是另外的线程执行
|
||||||
//await _mediatorScoped.Publish(new MasstransiTestCommand { value = "message at " + DateTime.Now.ToString() });
|
//await _mediatorScoped.Publish(new MasstransiTestCommand { value = "message at " + DateTime.Now.ToString() });
|
||||||
|
|
||||||
await _recurringMessageScheduler.ScheduleRecurringPublish(new QCImageQuestionSchedule() { CronExpression = "0/3 * * * * ? " }, new MasstransiTestCommand { value = "message at " + DateTime.Now.ToString() });
|
await _recurringMessageScheduler.ScheduleRecurringPublish(new QCImageQuestionRecurringSchedule() { CronExpression = "0/3 * * * * ? " }, new MasstransiTestCommand { value = "message at " + DateTime.Now.ToString() });
|
||||||
//await _scheduler.SchedulePublish(DateTime.Now.AddSeconds(10), new MasstransiTestCommand() { value = "message at " + DateTime.Now.ToString() });
|
//await _scheduler.SchedulePublish(DateTime.Now.AddSeconds(10), new MasstransiTestCommand() { value = "message at " + DateTime.Now.ToString() });
|
||||||
|
|
||||||
return ResponseOutput.Ok();
|
return ResponseOutput.Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<IResponseOutput> TestWordToPdf()
|
||||||
|
{
|
||||||
|
|
||||||
|
var dd = await FileConvertHelper.ThirdStirling_PDFWordToPdfAsync(@"C:\Users\hang\Desktop\test.docx");
|
||||||
|
|
||||||
|
string outputFilePath = @"C:\Users\hang\Desktop\test-byte4-output.pdf"; // 保存路径
|
||||||
|
File.WriteAllBytes(outputFilePath, dd); // 将响应字节数组写入文件
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//var envName = Environment.GetEnvironmentVariables()["ASPNETCORE_ENVIRONMENT"]?.ToString();
|
||||||
|
|
||||||
|
//// API 地址
|
||||||
|
//string apiUrl = "http://106.14.89.110:30088/api/v1/convert/file/pdf";
|
||||||
|
|
||||||
|
//// 模拟文件路径,假设你有一个内存流的文件,不指定实际文件
|
||||||
|
//string filePath = @"C:\Users\hang\Desktop\test.docx"; // 本地文件路径或者你可以直接使用流
|
||||||
|
|
||||||
|
//var fileBytes = File.ReadAllBytes(@"C:\Users\hang\Desktop\test.docx");
|
||||||
|
|
||||||
|
|
||||||
|
//try
|
||||||
|
//{
|
||||||
|
// // 创建 RestClient
|
||||||
|
// var client = new RestClient(apiUrl);
|
||||||
|
|
||||||
|
// // 创建 RestRequest,使用 POST 方法
|
||||||
|
// var request = new RestRequest(apiUrl, Method.Post);
|
||||||
|
// request.AddHeader("accept", "*/*");
|
||||||
|
|
||||||
|
// //new FileExtensionContentTypeProvider().Mappings.TryGetValue(Path.GetExtension(filePath), out var contentType);
|
||||||
|
|
||||||
|
// // 直接上传文件,无需生成字节数组
|
||||||
|
// //request.AddFile("fileInput", filePath, contentType);
|
||||||
|
|
||||||
|
// // 添加文件流到请求
|
||||||
|
// request.AddFile("fileInput", fileBytes, "test-byte.docx");
|
||||||
|
|
||||||
|
// // 发送请求并获取响应
|
||||||
|
// var response = await client.ExecuteAsync(request);
|
||||||
|
|
||||||
|
// // 检查请求是否成功
|
||||||
|
// if (response.IsSuccessful)
|
||||||
|
// {
|
||||||
|
// // 保存接收到的文件到本地
|
||||||
|
// string outputFilePath = @"C:\Users\hang\Desktop\test-byte3-output.pdf"; // 保存路径
|
||||||
|
// File.WriteAllBytes(outputFilePath, response.RawBytes); // 将响应字节数组写入文件
|
||||||
|
|
||||||
|
// //如果要文件流,就这样
|
||||||
|
// //var stream = new MemoryStream(response.RawBytes);
|
||||||
|
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// Console.WriteLine($"上传失败,错误代码: {response.StatusCode}, 错误消息: {response.ErrorMessage}");
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
//catch (Exception ex)
|
||||||
|
//{
|
||||||
|
// Console.WriteLine("发生异常: " + ex.Message);
|
||||||
|
//}
|
||||||
|
|
||||||
|
return ResponseOutput.Ok();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -11,9 +11,9 @@ namespace IRaCIS.Core.Application.MassTransit.Consumer;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class QCImageQuestionScheduleConsumer : IConsumer<QCImageQuestionSchedule>
|
public class QCImageQuestionScheduleConsumer : IConsumer<QCImageQuestionRecurringSchedule>
|
||||||
{
|
{
|
||||||
public Task Consume(ConsumeContext<QCImageQuestionSchedule> context)
|
public Task Consume(ConsumeContext<QCImageQuestionRecurringSchedule> context)
|
||||||
{
|
{
|
||||||
Console.WriteLine(DateTime.Now);
|
Console.WriteLine(DateTime.Now);
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ public abstract class IRCRecurringSchedule :
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// QC 影像质疑待处理
|
/// QC 影像质疑待处理
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class QCImageQuestionSchedule : IRCRecurringSchedule
|
public class QCImageQuestionRecurringSchedule : IRCRecurringSchedule
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ public class QCImageQuestionSchedule : IRCRecurringSchedule
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// CRC 影像质疑
|
/// CRC 影像质疑
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class CRCImageQuestionSchedule : IRCRecurringSchedule
|
public class CRCImageQuestionRecurringSchedule : IRCRecurringSchedule
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ public class CRCImageQuestionSchedule : IRCRecurringSchedule
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 影像质控
|
/// 影像质控
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ImageQCSchedule : IRCRecurringSchedule
|
public class ImageQCRecurringSchedule : IRCRecurringSchedule
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
|
@ -17,7 +17,7 @@
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="EntityFrameworkCore.Projectables.Abstractions" Version="3.0.4" />
|
<PackageReference Include="EntityFrameworkCore.Projectables.Abstractions" Version="3.0.4" />
|
||||||
<PackageReference Include="MassTransit" Version="8.2.5" />
|
<PackageReference Include="MassTransit" Version="8.3.0" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -25,9 +25,9 @@
|
||||||
<PackageReference Include="EntityFrameworkCore.Triggered" Version="3.2.2" />
|
<PackageReference Include="EntityFrameworkCore.Triggered" Version="3.2.2" />
|
||||||
<PackageReference Include="EntityFrameworkCore.Projectables" Version="3.0.4" />
|
<PackageReference Include="EntityFrameworkCore.Projectables" Version="3.0.4" />
|
||||||
<PackageReference Include="EntityFrameworkCore.Exceptions.SqlServer" Version="8.1.3" />
|
<PackageReference Include="EntityFrameworkCore.Exceptions.SqlServer" Version="8.1.3" />
|
||||||
<PackageReference Include="MassTransit" Version="8.2.5" />
|
<PackageReference Include="MassTransit" Version="8.3.0" />
|
||||||
<PackageReference Include="MassTransit.EntityFrameworkCore" Version="8.2.5" />
|
<PackageReference Include="MassTransit.EntityFrameworkCore" Version="8.3.0" />
|
||||||
<PackageReference Include="MassTransit.Hangfire" Version="8.2.5" />
|
<PackageReference Include="MassTransit.Hangfire" Version="8.3.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="8.0.8" />
|
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="8.0.8" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.8" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.8" />
|
||||||
|
|
Loading…
Reference in New Issue