利用第三方服务转pdf
continuous-integration/drone/push Build is passing

This commit is contained in:
hang
2024-10-19 16:31:27 +08:00
parent f97cfd58c0
commit 4ab4fbd599
10 changed files with 201 additions and 17 deletions
@@ -1,14 +1,18 @@
using IRaCIS.Core.Domain;
using IRaCIS.Core.Application.Helper;
using IRaCIS.Core.Domain;
using IRaCIS.Core.Domain.Share;
using MassTransit;
using MassTransit.Mediator;
using MassTransit.Scheduling;
using Medallion.Threading;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.StaticFiles;
using Microsoft.Extensions.Options;
using RestSharp;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -71,11 +75,76 @@ public class TestMasstransitService : BaseService
////发布后,不会立即进入消费者,消费者是另外的线程执行
//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() });
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);
@@ -32,7 +32,7 @@ public abstract class IRCRecurringSchedule :
/// <summary>
/// QC 影像质疑待处理
/// </summary>
public class QCImageQuestionSchedule : IRCRecurringSchedule
public class QCImageQuestionRecurringSchedule : IRCRecurringSchedule
{
}
@@ -40,7 +40,7 @@ public class QCImageQuestionSchedule : IRCRecurringSchedule
/// <summary>
/// CRC 影像质疑
/// </summary>
public class CRCImageQuestionSchedule : IRCRecurringSchedule
public class CRCImageQuestionRecurringSchedule : IRCRecurringSchedule
{
}
@@ -48,7 +48,7 @@ public class CRCImageQuestionSchedule : IRCRecurringSchedule
/// <summary>
/// 影像质控
/// </summary>
public class ImageQCSchedule : IRCRecurringSchedule
public class ImageQCRecurringSchedule : IRCRecurringSchedule
{
}