diff --git a/IRaCIS.Core.API/Controllers/ExtraController.cs b/IRaCIS.Core.API/Controllers/ExtraController.cs index 1ddc35683..9f6d3bcb2 100644 --- a/IRaCIS.Core.API/Controllers/ExtraController.cs +++ b/IRaCIS.Core.API/Controllers/ExtraController.cs @@ -216,7 +216,7 @@ namespace IRaCIS.Api.Controllers var ossOptions = serviceOption.AliyunOSS; - return ResponseOutput.Ok(new ObjectStoreDTO() { ObjectStoreUse = serviceOption.ObjectStoreUse, MinIO = serviceOption.MinIO ,AliyunOSS= serviceOption.AliyunOSS }); + return ResponseOutput.Ok(new ObjectStoreDTO() { ObjectStoreUse = serviceOption.ObjectStoreUse, MinIO = serviceOption.MinIO ,AliyunOSS= serviceOption.AliyunOSS,AWS=serviceOption.AWS }); #region 临时token 屏蔽 //IClientProfile profile = DefaultProfile.GetProfile(ossOptions.RegionId, ossOptions.AccessKeyId, ossOptions.AccessKeySecret); @@ -259,11 +259,11 @@ namespace IRaCIS.Api.Controllers } else if(Enum.TryParse(serviceOption.ObjectStoreUse, out var parsedValue) && parsedValue == ObjectStoreUse.MinIO) { - return ResponseOutput.Ok(new ObjectStoreDTO() { ObjectStoreUse=serviceOption.ObjectStoreUse,MinIO=serviceOption.MinIO}); + return ResponseOutput.Ok(new ObjectStoreDTO() { ObjectStoreUse=serviceOption.ObjectStoreUse,MinIO=serviceOption.MinIO, AWS = serviceOption.AWS }); } else { - return ResponseOutput.Ok(new ObjectStoreDTO() { ObjectStoreUse = serviceOption.ObjectStoreUse, MinIO = serviceOption.MinIO }); + return ResponseOutput.Ok(new ObjectStoreDTO() { ObjectStoreUse = serviceOption.ObjectStoreUse, MinIO = serviceOption.MinIO, AWS = serviceOption.AWS }); } } diff --git a/IRaCIS.Core.API/Controllers/UploadDownLoadController.cs b/IRaCIS.Core.API/Controllers/UploadDownLoadController.cs index 31dadf49c..9f5f903e2 100644 --- a/IRaCIS.Core.API/Controllers/UploadDownLoadController.cs +++ b/IRaCIS.Core.API/Controllers/UploadDownLoadController.cs @@ -566,7 +566,7 @@ namespace IRaCIS.Core.API.Controllers templateFileStream.Seek(0, SeekOrigin.Begin); - var ossRelativePath = oSSService.UploadToOSS(fileStream, "InspectionUpload/Check", $"{Guid.NewGuid()}_" + realFileName); + var ossRelativePath = await oSSService.UploadToOSSAsync(fileStream, "InspectionUpload/Check", $"{Guid.NewGuid()}_" + realFileName); await _repository.AddAsync(new InspectionFile() { FileName = realFileName, RelativePath = ossRelativePath, TrialId = trialId }); @@ -997,7 +997,7 @@ namespace IRaCIS.Core.API.Controllers throw new BusinessValidationFailedException(StaticData.International("UploadDownLoad_TemplateUploadData")); } - var ossRelativePath = oSSService.UploadToOSS(fileStream, "InspectionUpload/SiteSurvey", $"{Guid.NewGuid()}_"+ realFileName); + var ossRelativePath = await oSSService.UploadToOSSAsync(fileStream, "InspectionUpload/SiteSurvey", $"{Guid.NewGuid()}_"+ realFileName); await _inspectionFileRepository.AddAsync(new InspectionFile() { FileName = realFileName, RelativePath = ossRelativePath, TrialId = trialId }); diff --git a/IRaCIS.Core.API/_PipelineExtensions/Serilog/SerilogConfig.cs b/IRaCIS.Core.API/_PipelineExtensions/Serilog/SerilogConfig.cs index c5aab64f1..cccd58245 100644 --- a/IRaCIS.Core.API/_PipelineExtensions/Serilog/SerilogConfig.cs +++ b/IRaCIS.Core.API/_PipelineExtensions/Serilog/SerilogConfig.cs @@ -19,7 +19,7 @@ namespace IRaCIS.Core.API app.UseSerilogRequestLogging(opts => { - opts.MessageTemplate = "{TokenUserRealName} {TokenUserType} {ClientIp} {RequestIP} {Host} {Protocol} {RequestMethod} {RequestPath} {RequestBody} responded {StatusCode} in {Elapsed:0.0000} ms"; + opts.MessageTemplate = "{TokenUserRealName} {TokenUserTypeShortName} {ClientIp} {LocalIP} {Host} {Protocol} {RequestMethod} {RequestPath} {RequestBody} responded {StatusCode} in {Elapsed:0.0000} ms"; opts.EnrichDiagnosticContext = SerilogHelper.EnrichFromRequest; }); diff --git a/IRaCIS.Core.API/_PipelineExtensions/Serilog/SerilogHelper.cs b/IRaCIS.Core.API/_PipelineExtensions/Serilog/SerilogHelper.cs index 1bb30e7bd..9be804fbf 100644 --- a/IRaCIS.Core.API/_PipelineExtensions/Serilog/SerilogHelper.cs +++ b/IRaCIS.Core.API/_PipelineExtensions/Serilog/SerilogHelper.cs @@ -1,4 +1,5 @@ -using IRaCIS.Core.Infrastructure.Extention; +using IRaCIS.Core.Domain.Share; +using IRaCIS.Core.Infrastructure.Extention; using Microsoft.AspNetCore.Http; using Serilog; using System; @@ -20,7 +21,7 @@ namespace IRaCIS.Core.API diagnosticContext.Set("Host", request.Host); //这种获取的Ip不准 配置服务才行 - diagnosticContext.Set("RequestIP", httpContext.Connection.RemoteIpAddress.ToString()); + //diagnosticContext.Set("RequestIP", httpContext.Connection.RemoteIpAddress.ToString()); //这种方式可以,但是serilog提供了 就不用了 //diagnosticContext.Set("TestIP", httpContext.GetUserIp()); @@ -41,9 +42,9 @@ namespace IRaCIS.Core.API // Set the content-type of the Response at this point diagnosticContext.Set("ContentType", httpContext.Response.ContentType); - diagnosticContext.Set("TokenUserRealName", httpContext?.User?.FindFirst("realName")?.Value); + diagnosticContext.Set("TokenUserRealName", httpContext?.User?.FindFirst(JwtIRaCISClaimType.RealName)?.Value); - diagnosticContext.Set("TokenUserType", httpContext?.User?.FindFirst("userTypeEnumName")?.Value); + diagnosticContext.Set("TokenUserTypeShortName", httpContext?.User?.FindFirst(JwtIRaCISClaimType.UserTypeShortName)?.Value); // Retrieve the IEndpointFeature selected for the request var endpoint = httpContext.GetEndpoint(); diff --git a/IRaCIS.Core.API/_ServiceExtensions/Serilog/SerilogSetup.cs b/IRaCIS.Core.API/_ServiceExtensions/Serilog/SerilogSetup.cs index a27de1505..6cd35a1ae 100644 --- a/IRaCIS.Core.API/_ServiceExtensions/Serilog/SerilogSetup.cs +++ b/IRaCIS.Core.API/_ServiceExtensions/Serilog/SerilogSetup.cs @@ -26,24 +26,26 @@ namespace IRaCIS.Core.API //控制台 方便调试 问题 我们显示记录日志 时 获取上下文的ip 和用户名 用户类型 .WriteTo.Console(restrictedToMinimumLevel: LogEventLevel.Warning, - outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3} ] {LocalIP} {ClientIp} {TokenUserRealName} {TokenUserType} {Message:lj} {Properties:j}{NewLine} {Exception}") + outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {SourceContext:l} || {Message} || {Exception} ||end {NewLine}") + .WriteTo.File($"{AppContext.BaseDirectory}Serilogs/.log", rollingInterval: RollingInterval.Day, - outputTemplate: "{Timestamp:HH:mm:ss} || {Level} || {SourceContext:l} || {Message} ||{Exception} ||end {NewLine}"); + outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {SourceContext:l} || {Message} || {Exception} ||end {NewLine}"); + //.WriteTo.MSSqlServer("Data Source=DESKTOP-4TU9A6M;Initial Catalog=CoreFrame;User ID=sa;Password=123456", "logs", autoCreateSqlTable: true, restrictedToMinimumLevel: LogEventLevel.Information)//从左至右四个参数分别是数据库连接字符串、表名、如果表不存在是否创建、最低等级。Serilog会默认创建一些列。 - if (environment == "Production") - { - config.WriteTo.Email(new EmailConnectionInfo() - { - EmailSubject = "系统警告,请速速查看!",//邮件标题 - FromEmail = "test@extimaging.com",//发件人邮箱 - MailServer = "smtp.qiye.aliyun.com",//smtp服务器地址 - NetworkCredentials = new NetworkCredential("test@extimaging.com", "SHzyyl2021"),//两个参数分别是发件人邮箱与客户端授权码 - Port = 465,//端口号 - ToEmail = "872297557@qq.com"//收件人 - }, restrictedToMinimumLevel: LogEventLevel.Error, - outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff} [ {Level} {ClientIp} {ClientAgent} {TokenUserRealName} {TokenUserType} ] || [path: {RequestPath} arguments: {RequestBody}] {SourceContext:l} || {Message} || {Exception} ||end {NewLine})"); - } + //if (environment == "Production") + //{ + // config.WriteTo.Email(new EmailConnectionInfo() + // { + // EmailSubject = "系统警告,请速速查看!",//邮件标题 + // FromEmail = "test@extimaging.com",//发件人邮箱 + // MailServer = "smtp.qiye.aliyun.com",//smtp服务器地址 + // NetworkCredentials = new NetworkCredential("test@extimaging.com", "SHzyyl2021"),//两个参数分别是发件人邮箱与客户端授权码 + // Port = 465,//端口号 + // ToEmail = "872297557@qq.com"//收件人 + // }, restrictedToMinimumLevel: LogEventLevel.Error, + // outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff} [ {Level} {ClientIp} {ClientAgent} {TokenUserRealName} {TokenUserType} ] || [path: {RequestPath} arguments: {RequestBody}] {SourceContext:l} || {Message} || {Exception} ||end {NewLine})"); + //} //扩展方法 获取上下文的ip 用户名 用户类型 Log.Logger = config.Enrich.WithHttpContextInfo(serviceProvider).CreateLogger(); diff --git a/IRaCIS.Core.API/appsettings.Test_IRC.json b/IRaCIS.Core.API/appsettings.Test_IRC.json index edad727d5..15820fa89 100644 --- a/IRaCIS.Core.API/appsettings.Test_IRC.json +++ b/IRaCIS.Core.API/appsettings.Test_IRC.json @@ -18,7 +18,7 @@ "AliyunOSS": { "regionId": "cn-shanghai", - "endpoint": "https://oss-cn-shanghai.aliyuncs.com", + "endPoint": "https://oss-cn-shanghai.aliyuncs.com", "accessKeyId": "LTAI5tKvzs7ed3UfSpNk3xwQ", "accessKeySecret": "zTIceGEShlZDGnLrCFfIGFE7TXVRio", "bucketName": "zy-irc-test-store", @@ -28,12 +28,20 @@ }, "MinIO": { - "endpoint": "http://192.168.3.68", + "endPoint": "192.168.3.68", "port": "8001", "useSSL": false, "accessKey": "IDFkwEpWej0b4DtiuThL", "secretKey": "Lhuu83yMhVwu7c1SnjvGY6lq74jzpYqifK6Qtj4h", "bucketName": "test" + }, + + "AWS": { + "endPoint": "s3.us-east-1.amazonaws.com", + "useSSL": false, + "accessKey": "AKIAZQ3DRSOHFPJJ6FEU", + "secretKey": "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", + "bucketName": "ei-irc-test-store" } }, diff --git a/IRaCIS.Core.Application/Helper/OSSService.cs b/IRaCIS.Core.Application/Helper/OSSService.cs index 7cbe43924..869121703 100644 --- a/IRaCIS.Core.Application/Helper/OSSService.cs +++ b/IRaCIS.Core.Application/Helper/OSSService.cs @@ -3,6 +3,8 @@ using IRaCIS.Core.Application.Contracts; using IRaCIS.Core.Infrastructure; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Options; +using Minio.DataModel.Args; +using Minio; using NPOI.HPSF; using SharpCompress.Common; using System; @@ -13,13 +15,19 @@ using System.Linq; using System.Security.AccessControl; using System.Text; using System.Threading.Tasks; +using SkiaSharp; namespace IRaCIS.Core.Application.Helper { - public class MinIOOptions + public class MinIOOptions: AWSOptions { - public string endpoint { get; set; } public string port { get; set; } + + } + + public class AWSOptions + { + public string endPoint { get; set; } public bool useSSL { get; set; } public string accessKey { get; set; } public string secretKey { get; set; } @@ -48,6 +56,8 @@ namespace IRaCIS.Core.Application.Helper public AliyunOSSOptions AliyunOSS { get; set; } public MinIOOptions MinIO { get; set; } + public AWSOptions AWS { get; set; } + } public class ObjectStoreDTO @@ -58,6 +68,8 @@ namespace IRaCIS.Core.Application.Helper public MinIOOptions MinIO { get; set; } + public AWSOptions AWS { get; set; } + } public class AliyunOSSTempToken @@ -81,78 +93,105 @@ namespace IRaCIS.Core.Application.Helper AWS = 2, } - - - - - public interface IOSSService { - public string UploadToOSS(Stream fileStream, string oosFolderPath, string fileRealName); - public string UploadToOSS(string localFilePath, string oosFolderPath); + public Task UploadToOSSAsync(Stream fileStream, string oosFolderPath, string fileRealName); + public Task UploadToOSSAsync(string localFilePath, string oosFolderPath); - public void DownLoadFromOSS(string ossRelativePath, string localFilePath); + public Task DownLoadFromOSSAsync(string ossRelativePath, string localFilePath); - public AliyunOSSOptions _OSSConfig { get; set; } + public ObjectStoreServiceOptions ObjectStoreServiceOptions { get; set; } - public OssClient _ossClient { get; set; } } + + public class OSSService : IOSSService { - - public AliyunOSSOptions _OSSConfig { get; set; } - - public OssClient _ossClient { get; set; } - + public ObjectStoreServiceOptions ObjectStoreServiceOptions { get; set; } public OSSService(IOptionsMonitor options) { - var ossOptions = options.CurrentValue; - - _OSSConfig = ossOptions.AliyunOSS; - - _ossClient = new OssClient(_OSSConfig.endPoint, _OSSConfig.accessKeyId, _OSSConfig.accessKeySecret); - + ObjectStoreServiceOptions = options.CurrentValue; } /// - /// oosFolderPath 不要 "/ "开头 应该: TempFolder/ChildFolder + /// oosFolderPath 不要 "/ "开头 应该: TempFolder/ChildFolder /// /// /// /// /// - /// - public string UploadToOSS(Stream fileStream, string oosFolderPath,string fileRealName) + public async Task UploadToOSSAsync(Stream fileStream, string oosFolderPath, string fileRealName) { - var ossRelativePath = oosFolderPath + "/" + fileRealName; - try + using (var memoryStream = new MemoryStream()) { - using (var memoryStream = new MemoryStream()) + fileStream.Seek(0, SeekOrigin.Begin); + + fileStream.CopyTo(memoryStream); + + memoryStream.Seek(0, SeekOrigin.Begin); + + + if (ObjectStoreServiceOptions.ObjectStoreUse == "AliyunOSS") { - fileStream.Seek(0, SeekOrigin.Begin); + var aliConfig = ObjectStoreServiceOptions.AliyunOSS; + + var _ossClient = new OssClient(aliConfig.endPoint, aliConfig.accessKeyId, aliConfig.accessKeySecret); - fileStream.CopyTo(memoryStream); - memoryStream.Seek(0, SeekOrigin.Begin); // 上传文件 - var result = _ossClient.PutObject(_OSSConfig.bucketName, ossRelativePath, memoryStream); + var result = _ossClient.PutObject(aliConfig.bucketName, ossRelativePath, memoryStream); + } + else if (ObjectStoreServiceOptions.ObjectStoreUse == "MinIO") + { + var minIOConfig = ObjectStoreServiceOptions.MinIO; - return "/" + ossRelativePath; + var minioClient = new MinioClient().WithEndpoint($"{minIOConfig.endPoint}:{minIOConfig.port}") + .WithCredentials(minIOConfig.accessKey, minIOConfig.secretKey).WithSSL(minIOConfig.useSSL) + .Build(); + + var putObjectArgs = new PutObjectArgs() + .WithBucket(minIOConfig.bucketName) + .WithObject(ossRelativePath) + .WithStreamData(memoryStream); + + await minioClient.PutObjectAsync(putObjectArgs); + } + else if (ObjectStoreServiceOptions.ObjectStoreUse == "AWS") + { + var minIOConfig = ObjectStoreServiceOptions.AWS; + + + var minioClient = new MinioClient().WithEndpoint($"{minIOConfig.endPoint}") + .WithCredentials(minIOConfig.accessKey, minIOConfig.secretKey).WithSSL(minIOConfig.useSSL) + .Build(); + + var putObjectArgs = new PutObjectArgs() + .WithBucket(minIOConfig.bucketName) + .WithObject(ossRelativePath) + .WithStreamData(memoryStream); + + await minioClient.PutObjectAsync(putObjectArgs); + } + else + { + throw new BusinessValidationFailedException("未定义的存储介质类型"); + } } - catch (Exception ex) - { - throw new BusinessValidationFailedException("oss上传失败" + ex.Message); - } + + return "/" + ossRelativePath; + } + + /// /// oosFolderPath 不要 "/ "开头 应该: TempFolder/ChildFolder /// @@ -160,38 +199,122 @@ namespace IRaCIS.Core.Application.Helper /// /// /// - public string UploadToOSS(string localFilePath, string oosFolderPath) + public async Task UploadToOSSAsync(string localFilePath, string oosFolderPath) { var localFileName = Path.GetFileName(localFilePath); var ossRelativePath = oosFolderPath + "/" + localFileName; - try + if (ObjectStoreServiceOptions.ObjectStoreUse == "AliyunOSS") { + var aliConfig = ObjectStoreServiceOptions.AliyunOSS; + + var _ossClient = new OssClient(aliConfig.endPoint, aliConfig.accessKeyId, aliConfig.accessKeySecret); + // 上传文件 - var result = _ossClient.PutObject(_OSSConfig.bucketName, ossRelativePath, localFilePath); + var result = _ossClient.PutObject(aliConfig.bucketName, ossRelativePath, localFilePath); - return ossRelativePath; } - catch (Exception ex) + else if (ObjectStoreServiceOptions.ObjectStoreUse == "MinIO") { - throw new BusinessValidationFailedException("oss上传失败" + ex.Message); + var minIOConfig = ObjectStoreServiceOptions.MinIO; + + var minioClient = new MinioClient().WithEndpoint($"{minIOConfig.endPoint}:{minIOConfig.port}") + .WithCredentials(minIOConfig.accessKey, minIOConfig.secretKey).WithSSL(minIOConfig.useSSL) + .Build(); + + var putObjectArgs = new PutObjectArgs() + .WithBucket(minIOConfig.bucketName) + .WithObject(ossRelativePath) + .WithFileName(localFilePath); + + await minioClient.PutObjectAsync(putObjectArgs); } + else if (ObjectStoreServiceOptions.ObjectStoreUse == "AWS") + { + var minIOConfig = ObjectStoreServiceOptions.AWS; + + + var minioClient = new MinioClient().WithEndpoint($"{minIOConfig.endPoint}") + .WithCredentials(minIOConfig.accessKey, minIOConfig.secretKey).WithSSL(minIOConfig.useSSL) + .Build(); + + var putObjectArgs = new PutObjectArgs() + .WithBucket(minIOConfig.bucketName) + .WithObject(ossRelativePath) + .WithFileName(localFilePath); + + await minioClient.PutObjectAsync(putObjectArgs); + } + else + { + throw new BusinessValidationFailedException("未定义的存储介质类型"); + } + return "/" + ossRelativePath; + } - public void DownLoadFromOSS(string ossRelativePath, string localFilePath) + public async Task DownLoadFromOSSAsync(string ossRelativePath, string localFilePath) { + + ossRelativePath = ossRelativePath.TrimStart('/'); try { - var result = _ossClient.GetObject(_OSSConfig.bucketName, ossRelativePath); - // 将下载的文件流保存到本地文件 - using (var fs = File.OpenWrite(localFilePath)) + + if (ObjectStoreServiceOptions.ObjectStoreUse == "AliyunOSS") { - result.Content.CopyTo(fs); - fs.Close(); + var aliConfig = ObjectStoreServiceOptions.AliyunOSS; + + var _ossClient = new OssClient(aliConfig.endPoint, aliConfig.accessKeyId, aliConfig.accessKeySecret); + + // 上传文件 + var result = _ossClient.GetObject(aliConfig.bucketName, ossRelativePath); + + // 将下载的文件流保存到本地文件 + using (var fs = File.OpenWrite(localFilePath)) + { + result.Content.CopyTo(fs); + fs.Close(); + } + + } + else if (ObjectStoreServiceOptions.ObjectStoreUse == "MinIO") + { + var minIOConfig = ObjectStoreServiceOptions.MinIO; + + var minioClient = new MinioClient().WithEndpoint($"{minIOConfig.endPoint}:{minIOConfig.port}") + .WithCredentials(minIOConfig.accessKey, minIOConfig.secretKey).WithSSL(minIOConfig.useSSL) + .Build(); + + var getObjectArgs = new GetObjectArgs() + .WithBucket(minIOConfig.bucketName) + .WithObject(ossRelativePath) + .WithFile(localFilePath); + + await minioClient.GetObjectAsync(getObjectArgs); + + } + else if (ObjectStoreServiceOptions.ObjectStoreUse == "AWS") + { + var minIOConfig = ObjectStoreServiceOptions.AWS; + + var minioClient = new MinioClient().WithEndpoint($"{minIOConfig.endPoint}") + .WithCredentials(minIOConfig.accessKey, minIOConfig.secretKey).WithSSL(minIOConfig.useSSL) + .Build(); + + var getObjectArgs = new GetObjectArgs() + .WithBucket(minIOConfig.bucketName) + .WithObject(ossRelativePath) + .WithFile(localFilePath); + + await minioClient.GetObjectAsync(getObjectArgs); + } + else + { + throw new BusinessValidationFailedException("未定义的存储介质类型"); } } catch (Exception ex) @@ -201,6 +324,9 @@ namespace IRaCIS.Core.Application.Helper } + + + } diff --git a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml index 7f49a0446..163fe9223 100644 --- a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml +++ b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml @@ -84,17 +84,16 @@ - + - oosFolderPath 不要 "/ "开头 应该: TempFolder/ChildFolder + oosFolderPath 不要 "/ "开头 应该: TempFolder/ChildFolder - - + oosFolderPath 不要 "/ "开头 应该: TempFolder/ChildFolder @@ -1023,6 +1022,11 @@ 阅读片人 + + + 角色 + + 是否有签名 @@ -13927,12 +13931,6 @@ - - - 维护OSS 影像数据 - - - 维护临床数据 --一定要在同步表前同步数据才行 diff --git a/IRaCIS.Core.Application/Service/Common/InternationalizationService.cs b/IRaCIS.Core.Application/Service/Common/InternationalizationService.cs index 6f7870848..ab310ac26 100644 --- a/IRaCIS.Core.Application/Service/Common/InternationalizationService.cs +++ b/IRaCIS.Core.Application/Service/Common/InternationalizationService.cs @@ -10,6 +10,9 @@ using IRaCIS.Core.Application.Interfaces; using IRaCIS.Core.Application.ViewModel; using Microsoft.AspNetCore.Authorization; using IRaCIS.Core.Application.Helper; +using EasyCaching.Core; +using IRaCIS.Core.Domain.Share; +using OfficeOpenXml.FormulaParsing.Utilities; namespace IRaCIS.Core.Application.Service { @@ -19,12 +22,13 @@ namespace IRaCIS.Core.Application.Service [ApiExplorerSettings(GroupName = "Common")] public class InternationalizationService : BaseService, IInternationalizationService { - + private readonly IEasyCachingProvider _provider; private readonly IRepository _internationalizationRepository; - public InternationalizationService(IRepository internationalizationRepository) + public InternationalizationService(IRepository internationalizationRepository, IEasyCachingProvider provider) { _internationalizationRepository = internationalizationRepository; + _provider = provider; } /// @@ -35,17 +39,28 @@ namespace IRaCIS.Core.Application.Service [HttpGet] public async Task> GetFrontInternationalizationList() { + var cacheList= _provider.Get>(StaticData.InternationalData.Front).Value; - var list = await _internationalizationRepository.Where(t => t.InternationalizationType == 0).Select(t => new InternationalizationSimpleDto() + if(cacheList != null && cacheList.Count!=0) { - Code = t.Code, - Value = t.Value, - ValueCN = t.ValueCN, - FrontType = t.FrontType, - Description = t.Description, - }).ToListAsync(); + return cacheList; + } + else + { + var list = await _internationalizationRepository.Where(t => t.InternationalizationType == 0).Select(t => new InternationalizationSimpleDto() + { + Code = t.Code, + Value = t.Value, + ValueCN = t.ValueCN, + FrontType = t.FrontType, + Description = t.Description, + }).ToListAsync(); - return list; + _provider.Set>(StaticData.InternationalData.Front, list, TimeSpan.FromDays(1)); + + return list; + } + } /// @@ -72,9 +87,11 @@ namespace IRaCIS.Core.Application.Service await _internationalizationRepository.AddAsync(mapItem); } } - await _internationalizationRepository.SaveChangesAsync(); + //清理缓存 + _provider.Set>(StaticData.InternationalData.Front, new List(), TimeSpan.FromDays(1)); + return ResponseOutput.Ok(); } diff --git a/IRaCIS.Core.Application/TestService.cs b/IRaCIS.Core.Application/TestService.cs index 424bceafb..8481be5bf 100644 --- a/IRaCIS.Core.Application/TestService.cs +++ b/IRaCIS.Core.Application/TestService.cs @@ -17,11 +17,14 @@ using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using MiniExcelLibs; using Minio; +using Minio.DataModel.Args; using NPOI.HPSF; using NPOI.POIFS.Crypt; +using SharpCompress.Common; using Spire.Doc; using System.Linq.Expressions; using System.Reflection.Metadata; +using System.Security.AccessControl; using System.Security.Cryptography; using System.Text; using System.Text.RegularExpressions; @@ -66,80 +69,6 @@ namespace IRaCIS.Application.Services //_cache = cache; } - /// - /// 维护OSS 影像数据 - /// - /// - [AllowAnonymous] - [UnitOfWork] - public async Task OldLocalImageResizeJpg([FromServices] IOSSService oSSService, [FromServices] IRepository _repository, [FromServices] IWebHostEnvironment _hostEnvironment) - { - - var rootPath = FileStoreHelper.GetIRaCISRootDataFolder(_hostEnvironment); - - var studyList = _repository.Where(t => t.SeriesList.Any(t => t.ImageResizePath.Length < 10)).Select(t => new { t.TrialId, t.SiteId, t.SubjectId, t.SubjectVisitId, t.Id }).ToList(); - - foreach (var studyitem in studyList) - { - - var relativePath = $"{studyitem.TrialId}/{studyitem.SiteId}/{studyitem.SubjectId}/{studyitem.SubjectVisitId}/{StaticData.Folder.DicomFolder}/{studyitem.Id}/"; - - try - { - string nextMarker = null; - do - { - // 使用 prefix 模拟目录结构,设置 MaxKeys 和 NextMarker - var objectListing = oSSService._ossClient.ListObjects(new ListObjectsRequest(oSSService._OSSConfig.bucketName) - { - Prefix = relativePath, - MaxKeys = 1000, - Marker = nextMarker - }); - - var jpgInfoList = objectListing.ObjectSummaries - .Where(summary => summary.Key.EndsWith(".jpg")) - .Select(summary => - { - string fileName = summary.Key.Split('/').Last(); // 提取文件夹名 - return new - { - - Key = summary.Key, - InstanceId = Guid.TryParse( - fileName.Split('.')[0], - out Guid instanceId) - ? instanceId - : Guid.Empty - }; - }) - .Where(info => info.InstanceId != Guid.Empty) - .ToList(); - - foreach (var jpg in jpgInfoList) - { - var seriesId = _repository.Where(t => t.Id == jpg.InstanceId).Select(t => t.SeriesId).FirstOrDefault(); - - await _repository.BatchUpdateAsync(t => t.Id == seriesId, t => new DicomSeries() { ImageResizePath = "/" + jpg.Key }); - } - - // 设置 NextMarker 以获取下一页的数据 - nextMarker = objectListing.NextMarker; - - } while (!string.IsNullOrEmpty(nextMarker)); - } - catch (Exception ex) - { - Console.WriteLine($"Error: {ex.Message}"); - } - - await _repository.SaveChangesAsync(); - } - - - - return ResponseOutput.Ok(); - } public async Task TestEFcore8() @@ -157,22 +86,14 @@ namespace IRaCIS.Application.Services // 设置 Ne [AllowAnonymous] - public async Task TestMinIO([FromServices] IOptionsMonitor options) + public async Task TestMinIO([FromServices] IOSSService oSSService) { - await _repository.BatchUpdateAsync(t => t.Id == Guid.Empty, t => new Subject() { Id = Guid.Empty }); + await oSSService.UploadToOSSAsync("C:\\Users\\Administrator\\Desktop\\TrialSiteUserImportTemplate.xlsx", "myfolder"); - var minIO = options.CurrentValue.MinIO; + await oSSService.DownLoadFromOSSAsync("/myfolder/TrialSiteUserImportTemplate.xlsx", "C:\\Users\\Administrator\\Desktop\\aws.xlsx"); - - var minioClient = new MinioClient().WithEndpoint($"{minIO.endpoint}:{minIO.port}") - .WithCredentials(minIO.accessKey, minIO.secretKey) - .Build(); - - - - //ResponseOutput.Ok(options) - return await Task.FromResult(ResponseOutput.Ok(options)); + return ResponseOutput.Ok(); } [AllowAnonymous] @@ -204,7 +125,9 @@ namespace IRaCIS.Application.Services { - var rows = await MiniExcel.QueryAsync(@"C:\Users\Administrator\Desktop\Export\vue.xlsx"); + var rows = await MiniExcel.QueryAsync(@"C:\Users\Administrator\Desktop\i18n-new.xlsx"); + + rows = rows.Where(t => !string.IsNullOrEmpty(t.Code)).ToList(); foreach (var row in rows) { @@ -303,24 +226,6 @@ namespace IRaCIS.Application.Services - private static Dictionary _replacePatterns = new Dictionary() - { - { "test", "Atlanta Knight" }, - { "GAME_TIME", "7:30pm" }, - { "GAME_NUMBER", "161" }, - { "DATE", "October 18 2018" }, - }; - - private static string ReplaceFunc(string findStr) - { - if (_replacePatterns.ContainsKey(findStr)) - { - return _replacePatterns[findStr]; - } - return findStr; - } - - [AllowAnonymous] public async Task testwwwww([FromServices] IWebHostEnvironment env) { @@ -426,11 +331,7 @@ namespace IRaCIS.Application.Services - public string PostData(TestModel testModelList) - { - return String.Empty; - } - + #region 历史维护 /// /// 维护临床数据 --一定要在同步表前同步数据才行 /// @@ -470,6 +371,86 @@ namespace IRaCIS.Application.Services } + ///// + ///// 维护OSS 影像数据 + ///// + ///// + //[AllowAnonymous] + //[UnitOfWork] + //public async Task OldLocalImageResizeJpg([FromServices] IOSSService oSSService, [FromServices] IRepository _repository, [FromServices] IWebHostEnvironment _hostEnvironment) + //{ + + // var rootPath = FileStoreHelper.GetIRaCISRootDataFolder(_hostEnvironment); + + // var studyList = _repository.Where(t => t.SeriesList.Any(t => t.ImageResizePath.Length < 10)).Select(t => new { t.TrialId, t.SiteId, t.SubjectId, t.SubjectVisitId, t.Id }).ToList(); + + // foreach (var studyitem in studyList) + // { + + // var relativePath = $"{studyitem.TrialId}/{studyitem.SiteId}/{studyitem.SubjectId}/{studyitem.SubjectVisitId}/{StaticData.Folder.DicomFolder}/{studyitem.Id}/"; + + // try + // { + // string nextMarker = null; + // do + // { + // // 使用 prefix 模拟目录结构,设置 MaxKeys 和 NextMarker + // var objectListing = oSSService._ossClient.ListObjects(new ListObjectsRequest(oSSService._OSSConfig.bucketName) + // { + // Prefix = relativePath, + // MaxKeys = 1000, + // Marker = nextMarker + // }); + + // var jpgInfoList = objectListing.ObjectSummaries + // .Where(summary => summary.Key.EndsWith(".jpg")) + // .Select(summary => + // { + // string fileName = summary.Key.Split('/').Last(); // 提取文件夹名 + // return new + // { + + // Key = summary.Key, + // InstanceId = Guid.TryParse( + // fileName.Split('.')[0], + // out Guid instanceId) + // ? instanceId + // : Guid.Empty + // }; + // }) + // .Where(info => info.InstanceId != Guid.Empty) + // .ToList(); + + // foreach (var jpg in jpgInfoList) + // { + // var seriesId = _repository.Where(t => t.Id == jpg.InstanceId).Select(t => t.SeriesId).FirstOrDefault(); + + // await _repository.BatchUpdateAsync(t => t.Id == seriesId, t => new DicomSeries() { ImageResizePath = "/" + jpg.Key }); + // } + + // // 设置 NextMarker 以获取下一页的数据 + // nextMarker = objectListing.NextMarker; + + // } while (!string.IsNullOrEmpty(nextMarker)); + // } + // catch (Exception ex) + // { + // Console.WriteLine($"Error: {ex.Message}"); + // } + + // await _repository.SaveChangesAsync(); + // } + + + + // return ResponseOutput.Ok(); + //} + + + #endregion + + + } public class TestModel diff --git a/IRaCIS.Core.Domain/_Config/_StaticData.cs b/IRaCIS.Core.Domain/_Config/_StaticData.cs index d7616e7cd..0634a5323 100644 --- a/IRaCIS.Core.Domain/_Config/_StaticData.cs +++ b/IRaCIS.Core.Domain/_Config/_StaticData.cs @@ -176,7 +176,10 @@ public static class StaticData - + public static class InternationalData + { + public const string Front = "Front"; + } /// /// 匿名化配置 key