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

This commit is contained in:
he
2024-10-21 11:49:38 +08:00
25 changed files with 491 additions and 149 deletions
@@ -34,6 +34,8 @@ public class ServiceVerifyConfigOption
[Description("修改密码的天数")]
public int ChangePassWordDays { get; set; }
public string ThirdPdfUrl { get; set; }
}
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;
public class FileConvertHelper
{
/// <summary>
/// 镜像里面打入libreoffice 的方案
/// </summary>
/// <param name="inputWordFilePath"></param>
/// <param name="outputPdfDir"></param>
static public void ConvertWordToPdf(string inputWordFilePath, string outputPdfDir)
{
// 设置 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;
}
}
@@ -48,9 +48,9 @@
<ItemGroup>
<PackageReference Include="AlibabaCloud.SDK.Sts20150401" Version="1.1.4" />
<PackageReference Include="AWSSDK.SecurityToken" Version="3.7.400.16" />
<PackageReference Include="AWSSDK.SecurityToken" Version="3.7.400.36" />
<PackageReference Include="Aliyun.OSS.SDK.NetCore" Version="2.14.1" />
<PackageReference Include="AWSSDK.S3" Version="3.7.402.7" />
<PackageReference Include="AWSSDK.S3" Version="3.7.405" />
<PackageReference Include="DocX" Version="3.0.1" />
<PackageReference Include="FreeSpire.Doc" Version="12.2.0" />
<PackageReference Include="Hangfire.Core" Version="1.8.14" />
@@ -60,13 +60,13 @@
<PackageReference Include="DistributedLock.SqlServer" Version="1.0.5" />
<PackageReference Include="fo-dicom" Version="5.1.3" />
<PackageReference Include="fo-dicom.Imaging.ImageSharp" Version="5.1.3" />
<PackageReference Include="fo-dicom.Codecs" Version="5.14.5" />
<PackageReference Include="fo-dicom.Codecs" Version="5.15.1" />
<PackageReference Include="IP2Region.Net" Version="2.0.2" />
<PackageReference Include="MailKit" Version="4.7.1.1" />
<PackageReference Include="Masa.Contrib.Service.MinimalAPIs" Version="1.0.0" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.10" />
<PackageReference Include="MimeKit" Version="4.7.1" />
<PackageReference Include="MiniExcel" Version="1.34.1" />
<PackageReference Include="MiniExcel" Version="1.34.2" />
<PackageReference Include="Minio" Version="6.0.3" />
<PackageReference Include="MiniWord" Version="0.8.0" />
<PackageReference Include="My.Extensions.Localization.Json" Version="3.3.0">
@@ -74,10 +74,10 @@
</PackageReference>
<PackageReference Include="NPOI" Version="2.7.1" />
<PackageReference Include="Panda.DynamicWebApi" Version="1.2.2" />
<PackageReference Include="RestSharp" Version="112.0.0" />
<PackageReference Include="RestSharp" Version="112.1.0" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.5" />
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="8.0.2" />
<PackageReference Include="ZiggyCreatures.FusionCache" Version="1.3.0" />
<PackageReference Include="ZiggyCreatures.FusionCache" Version="1.4.0" />
</ItemGroup>
<ItemGroup>
@@ -2273,6 +2273,20 @@
<param name="password"></param>
<returns></returns>
</member>
<member name="T:IRaCIS.Core.Application.Service.MinimalApiService.TestMinimalApiService">
<summary>
minimal api 测试
学习参考文档:http://fanrk.cn/%E6%8A%80%E6%9C%AF%E6%96%87%E6%A1%A3/MinimalApi/MinimalApi.html
组件参考文档:https://docs.masastack.com/framework/building-blocks/minimal-apis#section-69828ff0
</summary>
</member>
<member name="M:IRaCIS.Core.Application.Service.MinimalApiService.TestMinimalApiService.#ctor(IRaCIS.Core.Domain.Share.IUserInfo)">
<summary>
minimal api 测试
学习参考文档:http://fanrk.cn/%E6%8A%80%E6%9C%AF%E6%96%87%E6%A1%A3/MinimalApi/MinimalApi.html
组件参考文档:https://docs.masastack.com/framework/building-blocks/minimal-apis#section-69828ff0
</summary>
</member>
<member name="M:IRaCIS.Core.Application.Service.QCCommon.VerifyIsCRCSubmmitAsync(IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.SubjectVisit},IRaCIS.Core.Domain.Share.IUserInfo,System.Nullable{System.Guid})">
<summary>
验证CRC 是否已提交 已提交 就不允许进行任何操作,如果是IQC 那么还验证是否是当前任务领取人
@@ -12683,20 +12697,6 @@
<param name="outEnrollTime"></param>
<returns></returns>
</member>
<member name="T:IRaCIS.Core.Application.Service.TestMinimalApiService">
<summary>
minimal api 测试
学习参考文档:http://fanrk.cn/%E6%8A%80%E6%9C%AF%E6%96%87%E6%A1%A3/MinimalApi/MinimalApi.html
组件参考文档:https://docs.masastack.com/framework/building-blocks/minimal-apis#section-69828ff0
</summary>
</member>
<member name="M:IRaCIS.Core.Application.Service.TestMinimalApiService.#ctor(IRaCIS.Core.Domain.Share.IUserInfo)">
<summary>
minimal api 测试
学习参考文档:http://fanrk.cn/%E6%8A%80%E6%9C%AF%E6%96%87%E6%A1%A3/MinimalApi/MinimalApi.html
组件参考文档:https://docs.masastack.com/framework/building-blocks/minimal-apis#section-69828ff0
</summary>
</member>
<member name="M:IRaCIS.Core.Application.Service.TestService.DeleteConsistentDate(System.Guid,IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.TaskConsistentRule},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.ReadingConsistentClinicalDataPDF},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.ReadingConsistentClinicalData})">
<summary>
清理一致性分析任务
@@ -12762,6 +12762,21 @@
<param name="userId"></param>
<returns></returns>
</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)">
<summary>
写文件导到磁盘
@@ -12916,12 +12931,17 @@
加急阅片 IR 申请重阅 或者PM 申请重阅
</summary>
</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">
<summary>
用户提交 发送邮件 通知SPM 或者PM
</summary>
</member>
<member name="M:IRaCIS.Core.Application.MassTransit.Consumer.UserSiteSurveySubmitedEventConsumer.#ctor(IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.Trial},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.TrialSite},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.TrialSiteSurvey},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.EmailNoticeConfig},Microsoft.Extensions.Options.IOptionsMonitor{IRaCIS.Core.Domain.Share.SystemEmailSendConfig})">
<member name="M:IRaCIS.Core.Application.MassTransit.Consumer.UserSiteSurveySubmitedEventConsumer.#ctor(IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.Trial},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.TrialSite},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.TrialUser},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.TrialSiteSurvey},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.EmailNoticeConfig},Microsoft.Extensions.Options.IOptionsMonitor{IRaCIS.Core.Domain.Share.SystemEmailSendConfig})">
<summary>
用户提交 发送邮件 通知SPM 或者PM
</summary>
@@ -12931,7 +12951,7 @@
调研表初审通过,进行复审发送邮件
</summary>
</member>
<member name="M:IRaCIS.Core.Application.MassTransit.Consumer.SiteSurveySPMSubmitedEventConsumer.#ctor(IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.Trial},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.TrialSite},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.TrialSiteSurvey},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.EmailNoticeConfig},Microsoft.Extensions.Options.IOptionsMonitor{IRaCIS.Core.Domain.Share.SystemEmailSendConfig})">
<member name="M:IRaCIS.Core.Application.MassTransit.Consumer.SiteSurveySPMSubmitedEventConsumer.#ctor(IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.Trial},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.TrialUser},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.TrialSite},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.TrialSiteSurvey},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.EmailNoticeConfig},Microsoft.Extensions.Options.IOptionsMonitor{IRaCIS.Core.Domain.Share.SystemEmailSendConfig})">
<summary>
调研表初审通过,进行复审发送邮件
</summary>
@@ -12941,7 +12961,7 @@
调研表驳回发送邮件 之前已有,需要迁移过来
</summary>
</member>
<member name="M:IRaCIS.Core.Application.MassTransit.Consumer.SiteSurverRejectedEventConsumer.#ctor(IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.User},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.Trial},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.TrialSite},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.TrialSiteSurvey},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.EmailNoticeConfig},Microsoft.Extensions.Options.IOptionsMonitor{IRaCIS.Core.Domain.Share.SystemEmailSendConfig})">
<member name="M:IRaCIS.Core.Application.MassTransit.Consumer.SiteSurverRejectedEventConsumer.#ctor(IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.TrialUser},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.Trial},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.TrialSite},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.TrialSiteSurvey},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.EmailNoticeConfig},Microsoft.Extensions.Options.IOptionsMonitor{IRaCIS.Core.Domain.Share.SystemEmailSendConfig})">
<summary>
调研表驳回发送邮件 之前已有,需要迁移过来
</summary>
@@ -13042,17 +13062,17 @@
影像质控
</summary>
</member>
<member name="T:IRaCIS.Core.Application.MassTransit.Consumer.QCImageQuestionSchedule">
<member name="T:IRaCIS.Core.Application.MassTransit.Consumer.QCImageQuestionRecurringSchedule">
<summary>
QC 影像质疑待处理
</summary>
</member>
<member name="T:IRaCIS.Core.Application.MassTransit.Consumer.CRCImageQuestionSchedule">
<member name="T:IRaCIS.Core.Application.MassTransit.Consumer.CRCImageQuestionRecurringSchedule">
<summary>
CRC 影像质疑
</summary>
</member>
<member name="T:IRaCIS.Core.Application.MassTransit.Consumer.ImageQCSchedule">
<member name="T:IRaCIS.Core.Application.MassTransit.Consumer.ImageQCRecurringSchedule">
<summary>
影像质控
</summary>
@@ -30,6 +30,7 @@ namespace IRaCIS.Core.Application.MassTransit.Consumer;
public class UserSiteSurveySubmitedEventConsumer(
IRepository<Trial> _trialRepository,
IRepository<TrialSite> _trialSiteRepository,
IRepository<TrialUser> _trialUserRepository,
IRepository<TrialSiteSurvey> _trialSiteSurveyRepository,
IRepository<EmailNoticeConfig> _emailNoticeConfigrepository,
IOptionsMonitor<SystemEmailSendConfig> systemEmailConfig
@@ -46,7 +47,7 @@ public class UserSiteSurveySubmitedEventConsumer(
var trialId = siteSurveyInfo.TrialId;
var trialUserList = await _trialSiteSurveyRepository.Where(t => t.TrialId == siteSurveyInfo.TrialId).SelectMany(t => t.Trial.TrialUserList)
var trialUserList = await _trialUserRepository.Where(t => t.TrialId == siteSurveyInfo.TrialId)
.Where(t => t.User.UserTypeEnum == UserTypeEnum.SPM || t.User.UserTypeEnum == UserTypeEnum.CPM || t.User.UserTypeEnum == UserTypeEnum.ProjectManager || t.User.UserTypeEnum == UserTypeEnum.APM)
.Select(t => new { t.User.FullName, t.User.EMail, t.User.UserTypeEnum }).ToListAsync();
@@ -124,6 +125,7 @@ public class UserSiteSurveySubmitedEventConsumer(
/// </summary>
public class SiteSurveySPMSubmitedEventConsumer(
IRepository<Trial> _trialRepository,
IRepository<TrialUser> _trialUserRepository,
IRepository<TrialSite> _trialSiteRepository,
IRepository<TrialSiteSurvey> _trialSiteSurveyRepository,
IRepository<EmailNoticeConfig> _emailNoticeConfigrepository,
@@ -143,8 +145,7 @@ public class SiteSurveySPMSubmitedEventConsumer(
var messageToSend = new MimeMessage();
var trialUserList = _trialRepository.Where(t => t.Id == trialId)
.SelectMany(t => t.TrialUserList)
var trialUserList = _trialUserRepository.Where(t => t.TrialId == trialId)
.Where(t => t.User.UserTypeEnum == UserTypeEnum.SPM || t.User.UserTypeEnum == UserTypeEnum.CPM || t.User.UserTypeEnum == UserTypeEnum.ProjectManager || t.User.UserTypeEnum == UserTypeEnum.APM)
.Select(t => new { t.User.EMail, t.User.FullName, t.User.UserTypeEnum }).ToList();
@@ -199,7 +200,7 @@ public class SiteSurveySPMSubmitedEventConsumer(
/// 调研表驳回发送邮件 之前已有,需要迁移过来
/// </summary>
public class SiteSurverRejectedEventConsumer(
IRepository<User> _userRepository,
IRepository<TrialUser> _trialUserRepository,
IRepository<Trial> _trialRepository,
IRepository<TrialSite> _trialSiteRepository,
IRepository<TrialSiteSurvey> _trialSiteSurveyRepository,
@@ -232,8 +233,7 @@ public class SiteSurverRejectedEventConsumer(
//name = user.FullName;
var sPMOrCPMList = _trialRepository.Where(t => t.Id == trialId)
.SelectMany(t => t.TrialUserList)
var sPMOrCPMList = _trialUserRepository.Where(t => t.TrialId == trialId)
.Where(t => t.User.UserTypeEnum == UserTypeEnum.SPM || t.User.UserTypeEnum == UserTypeEnum.CPM)
.Select(t => new { t.User.EMail, t.User.FullName, t.User.UserTypeEnum }).ToList();
@@ -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
{
}
@@ -0,0 +1,132 @@
using IRaCIS.Core.Application.Helper;
using MassTransit;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.StaticFiles;
using RestSharp;
using SharpCompress.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace IRaCIS.Core.Application.Service.MinimalApiService
{
[ApiExplorerSettings(GroupName = "Institution")]
public class FileToPDFService(IWebHostEnvironment _hostEnvironment) : ServiceBase
{
[AllowAnonymous]
[RoutePattern(HttpMethod = "Post")]
public async Task<IResult> UploadFileAsync([FromForm] IFormFile file)
{
var tempFileName = NewId.NextGuid() + file.FileName;
var tempPDFName = Path.GetFileNameWithoutExtension(tempFileName) + ".pdf";
// 获取wwwroot目录
var wwwRootPath = Path.Combine(FileStoreHelper.GetIRaCISRootDataFolder(_hostEnvironment), "temp");
// 检查wwwroot/temp目录是否存在,不存在则创建
if (!Directory.Exists(wwwRootPath))
{
Directory.CreateDirectory(wwwRootPath);
}
// 文件保存路径
var pdfFilePath = Path.Combine(wwwRootPath, tempPDFName);
var tempFilePath = Path.Combine(wwwRootPath, tempFileName);
using var stream = File.OpenWrite(tempFilePath);
await file.CopyToAsync(stream);
FileConvertHelper.ConvertWordToPdf(tempFilePath, Path.GetDirectoryName(pdfFilePath));
var fileBytes = await File.ReadAllBytesAsync(pdfFilePath);
// 清理临时上传的文件和pdf
if (File.Exists(pdfFilePath))
{
File.Delete(pdfFilePath);
}
if (File.Exists(tempFilePath))
{
File.Delete(tempFilePath);
}
new FileExtensionContentTypeProvider().Mappings.TryGetValue(Path.GetExtension(tempPDFName), out var contentType);
return Results.File(fileBytes, contentType);
}
public async Task<IResult> GetPDFFileAsync(string fileUrl)
{
var tempFileName = NewId.NextGuid() + Path.GetFileName(fileUrl);
var tempPDFName = Path.GetFileNameWithoutExtension(tempFileName) + ".pdf";
// 获取wwwroot目录
var wwwRootPath = Path.Combine(FileStoreHelper.GetIRaCISRootDataFolder(_hostEnvironment), "temp");
// 检查wwwroot/temp目录是否存在,不存在则创建
if (!Directory.Exists(wwwRootPath))
{
Directory.CreateDirectory(wwwRootPath);
}
// 文件保存路径
var pdfFilePath = Path.Combine(wwwRootPath, tempPDFName);
var tempFilePath = Path.Combine(wwwRootPath, tempFileName);
//请求url获取文件
var client = new RestClient(fileUrl);
var request = new RestRequest(fileUrl, Method.Get);
var response = await client.ExecuteAsync(request);
// 检查响应是否成功
if (response.IsSuccessful)
{
// 将响应内容写入到本地文件
await File.WriteAllBytesAsync(tempFilePath, response.RawBytes);
FileConvertHelper.ConvertWordToPdf(tempFilePath, Path.GetDirectoryName(pdfFilePath));
var fileBytes = await File.ReadAllBytesAsync(pdfFilePath);
// 清理临时上传的文件和pdf
if (File.Exists(pdfFilePath))
{
File.Delete(pdfFilePath);
}
if (File.Exists(tempFilePath))
{
File.Delete(tempFilePath);
}
new FileExtensionContentTypeProvider().Mappings.TryGetValue(Path.GetExtension(tempPDFName), out var contentType);
return Results.File(fileBytes, contentType);
}
else
{
Console.WriteLine($"下载文件失败: {response.ErrorMessage}");
return Results.Problem("下载文件失败", statusCode: StatusCodes.Status500InternalServerError);
}
}
}
}
@@ -0,0 +1,57 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace IRaCIS.Core.Application.Service.MinimalApiService
{
/// <summary>
/// minimal api 测试
/// 学习参考文档:http://fanrk.cn/%E6%8A%80%E6%9C%AF%E6%96%87%E6%A1%A3/MinimalApi/MinimalApi.html
/// 组件参考文档:https://docs.masastack.com/framework/building-blocks/minimal-apis#section-69828ff0
/// </summary>
[ApiExplorerSettings(GroupName = "Institution")]
public class TestMinimalApiService(IUserInfo _userInfo) : ServiceBase
{
public Task<List<string>> GetProjectList1Async()
{
var list = new List<string>()
{
"Auth",
"DCC",
"PM"
};
return Task.FromResult(list);
}
[AllowAnonymous]
public IResponseOutput GetTest()
{
//throw new BusinessValidationFailedException("手动抛出的异常");
return ResponseOutput.Ok(_userInfo.IP);
}
public IResponseOutput GetTestI18n()
{
var isEn_US = CultureInfo.CurrentCulture.Name == StaticData.CultureInfo.en_US;
//CultureInfo.CurrentCulture = new CultureInfo(StaticData.CultureInfo.en_US);
//CultureInfo.CurrentUICulture = new CultureInfo(StaticData.CultureInfo.en_US);
return ResponseOutput.Ok(I18n.T("TaskAllocation_DoctorConfigExists"));
}
}
}
-43
View File
@@ -33,49 +33,6 @@ using System.Text;
namespace IRaCIS.Core.Application.Service
{
/// <summary>
/// minimal api 测试
/// 学习参考文档:http://fanrk.cn/%E6%8A%80%E6%9C%AF%E6%96%87%E6%A1%A3/MinimalApi/MinimalApi.html
/// 组件参考文档:https://docs.masastack.com/framework/building-blocks/minimal-apis#section-69828ff0
/// </summary>
[ApiExplorerSettings(GroupName = "Institution")]
public class TestMinimalApiService(IUserInfo _userInfo) : ServiceBase
{
public Task<List<string>> GetProjectList1Async()
{
var list = new List<string>()
{
"Auth",
"DCC",
"PM"
};
return Task.FromResult(list);
}
[AllowAnonymous]
public IResponseOutput GetTest()
{
//throw new BusinessValidationFailedException("手动抛出的异常");
return ResponseOutput.Ok(_userInfo.IP);
}
public IResponseOutput GetTestI18n()
{
var isEn_US = CultureInfo.CurrentCulture.Name == StaticData.CultureInfo.en_US;
//CultureInfo.CurrentCulture = new CultureInfo(StaticData.CultureInfo.en_US);
//CultureInfo.CurrentUICulture = new CultureInfo(StaticData.CultureInfo.en_US);
return ResponseOutput.Ok(I18n.T("TaskAllocation_DoctorConfigExists"));
}
}