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 Details

IRC_NewDev
he 2024-09-03 15:52:01 +08:00
commit 1e91c08ae3
13 changed files with 357 additions and 171 deletions

View File

@ -304,8 +304,8 @@ namespace IRaCIS.Api.Controllers
var client = new Client(new AlibabaCloud.OpenApiClient.Models.Config() var client = new Client(new AlibabaCloud.OpenApiClient.Models.Config()
{ {
AccessKeyId = ossOptions.accessKeyId, AccessKeyId = ossOptions.AccessKeyId,
AccessKeySecret = ossOptions.accessKeySecret, AccessKeySecret = ossOptions.AccessKeySecret,
//AccessKeyId = "LTAI5tJV76pYX5yPg1N9QVE8", //AccessKeyId = "LTAI5tJV76pYX5yPg1N9QVE8",
//AccessKeySecret = "roRNLa9YG1of4pYruJGCNKBXEWTAWa", //AccessKeySecret = "roRNLa9YG1of4pYruJGCNKBXEWTAWa",
@ -316,25 +316,25 @@ namespace IRaCIS.Api.Controllers
// 将<YOUR_ROLE_SESSION_NAME>设置为自定义的会话名称例如oss-role-session。 // 将<YOUR_ROLE_SESSION_NAME>设置为自定义的会话名称例如oss-role-session。
assumeRoleRequest.RoleSessionName = $"session-name-{NewId.NextGuid()}"; assumeRoleRequest.RoleSessionName = $"session-name-{NewId.NextGuid()}";
// 将<YOUR_ROLE_ARN>替换为拥有上传文件到指定OSS Bucket权限的RAM角色的ARN。 // 将<YOUR_ROLE_ARN>替换为拥有上传文件到指定OSS Bucket权限的RAM角色的ARN。
assumeRoleRequest.RoleArn = ossOptions.roleArn; assumeRoleRequest.RoleArn = ossOptions.RoleArn;
//assumeRoleRequest.RoleArn = "acs:ram::1899121822495495:role/webdirect"; //assumeRoleRequest.RoleArn = "acs:ram::1899121822495495:role/webdirect";
assumeRoleRequest.DurationSeconds = ossOptions.durationSeconds; assumeRoleRequest.DurationSeconds = ossOptions.DurationSeconds;
var runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions(); var runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions();
var response = client.AssumeRoleWithOptions(assumeRoleRequest, runtime); var response = client.AssumeRoleWithOptions(assumeRoleRequest, runtime);
var credentials = response.Body.Credentials; var credentials = response.Body.Credentials;
var tempToken = new AliyunOSSTempToken() var tempToken = new AliyunOSSTempToken()
{ {
accessKeyId = credentials.AccessKeyId, AccessKeyId = credentials.AccessKeyId,
accessKeySecret = credentials.AccessKeySecret, AccessKeySecret = credentials.AccessKeySecret,
expiration = credentials.Expiration, Expiration = credentials.Expiration,
securityToken = credentials.SecurityToken, SecurityToken = credentials.SecurityToken,
region = ossOptions.region, Region = ossOptions.Region,
bucketName = ossOptions.bucketName, BucketName = ossOptions.BucketName,
endPoint = ossOptions.endPoint, EndPoint = ossOptions.EndPoint,
viewEndpoint = ossOptions.viewEndpoint, ViewEndpoint = ossOptions.ViewEndpoint,
}; };

View File

@ -1,55 +1,35 @@
using IRaCIS.Core.Domain.Share; using IRaCIS.Core.Domain.Share;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Serialization; using Newtonsoft.Json.Serialization;
using System; using System;
using System.Globalization; using System.Globalization;
using System.Threading.Tasks; using System.Reflection;
namespace IRaCIS.Core.API._ServiceExtensions.NewtonsoftJson namespace IRaCIS.Core.API
{ {
public class CustomJsonResult : JsonResult
{
public CustomJsonResult(object value) : base(value) { }
public override void ExecuteResult(ActionContext context)
{
var converter = context.HttpContext.RequestServices.GetService<JSONTimeZoneConverter>();
var isEn_US = CultureInfo.CurrentCulture.Name == StaticData.CultureInfo.en_US; //public class CustomContractResolver : DefaultContractResolver
string dateFormat; //{
// protected override JsonContract CreateContract(Type objectType)
// {
// var contract = base.CreateContract(objectType);
if (!isEn_US) // // 检查类是否有 LowercaseJsonAttribute 标记
{ // if (objectType.GetCustomAttribute<LowerCamelCaseJsonAttribute>() != null)
// Chinese date format // {
dateFormat = "yyyy-MM-dd HH:mm:ss"; // contract.NamingStrategy = new IRCCamelCaseNamingStrategy();
} // }
else
{
// Default or English date format
dateFormat = "MM/dd/yyyy HH:mm:ss";
}
var serializerSettings = new JsonSerializerSettings // return contract;
{ // }
DateFormatString = dateFormat, //}
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
ContractResolver = new NullToEmptyStringResolver(),
DateTimeZoneHandling = DateTimeZoneHandling.RoundtripKind,
};
serializerSettings.Converters.Add(converter);
var json = JsonConvert.SerializeObject(Value, serializerSettings);
context.HttpContext.Response.ContentType = "application/json";
context.HttpContext.Response.WriteAsync(json);
}
}
#region 废弃
public class MyDateTimeConverter : JsonConverter<DateTime> public class MyDateTimeConverter : JsonConverter<DateTime>
{ {
public override DateTime ReadJson(JsonReader reader, Type objectType, DateTime existingValue, bool hasExistingValue, JsonSerializer serializer) public override DateTime ReadJson(JsonReader reader, Type objectType, DateTime existingValue, bool hasExistingValue, JsonSerializer serializer)
@ -115,11 +95,5 @@ namespace IRaCIS.Core.API._ServiceExtensions.NewtonsoftJson
} }
} }
#endregion
} }

View File

@ -9,6 +9,8 @@ using Newtonsoft.Json;
using Newtonsoft.Json.Converters; using Newtonsoft.Json.Converters;
using System; using System;
using System.Globalization; using System.Globalization;
using System.Text.Json;
using Newtonsoft.Json.Serialization;
namespace IRaCIS.Core.API namespace IRaCIS.Core.API
{ {
@ -26,6 +28,14 @@ namespace IRaCIS.Core.API
builder.AddNewtonsoftJson(options => builder.AddNewtonsoftJson(options =>
{ {
//大驼峰
//options.SerializerSettings.ContractResolver = new DefaultContractResolver();
//小驼峰
//options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
// 忽略循环引用 // 忽略循环引用
options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;

View File

@ -1,8 +1,10 @@
using Newtonsoft.Json; using IRaCIS.Core.Infrastructure.NewtonsoftJson;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization; using Newtonsoft.Json.Serialization;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection;
namespace IRaCIS.Core.API namespace IRaCIS.Core.API
{ {
@ -30,8 +32,20 @@ namespace IRaCIS.Core.API
protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization) protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
{ {
// 检查类是否有 LowerCamelCaseJsonAttribute 标记 有的话,属性名小写
if (type.GetCustomAttribute<LowerCamelCaseJsonAttribute>() != null)
{
base.NamingStrategy= new LowerCamelCaseNamingStrategy();
}
else
{
base.NamingStrategy = null;
}
IList<JsonProperty> properties = base.CreateProperties(type, memberSerialization); IList<JsonProperty> properties = base.CreateProperties(type, memberSerialization);
var list= type.GetProperties() var list= type.GetProperties()
.Select(p => .Select(p =>
{ {

View File

@ -16,33 +16,33 @@
"ObjectStoreUse": "AliyunOSS", "ObjectStoreUse": "AliyunOSS",
"AliyunOSS": { "AliyunOSS": {
"regionId": "cn-shanghai", "RegionId": "cn-shanghai",
"internalEndpoint": "https://oss-cn-shanghai-internal.aliyuncs.com", "InternalEndpoint": "https://oss-cn-shanghai-internal.aliyuncs.com",
"endPoint": "https://oss-cn-shanghai.aliyuncs.com", "EndPoint": "https://oss-cn-shanghai.aliyuncs.com",
"accessKeyId": "LTAI5tJV76pYX5yPg1N9QVE8", "AccessKeyId": "LTAI5tJV76pYX5yPg1N9QVE8",
"accessKeySecret": "roRNLa9YG1of4pYruJGCNKBXEWTAWa", "AccessKeySecret": "roRNLa9YG1of4pYruJGCNKBXEWTAWa",
"bucketName": "zy-irc-test-store", "BucketName": "zy-irc-test-store",
"roleArn": "acs:ram::1899121822495495:role/webdirect", "RoleArn": "acs:ram::1899121822495495:role/webdirect",
"viewEndpoint": "https://zy-irc-test-store.oss-cn-shanghai.aliyuncs.com", "ViewEndpoint": "https://zy-irc-test-store.oss-cn-shanghai.aliyuncs.com",
"region": "oss-cn-shanghai", "Region": "oss-cn-shanghai",
"durationSeconds": 7200 "DurationSeconds": 7200
}, },
"MinIO": { "MinIO": {
"endPoint": "hir-oss.test.extimaging.com", "EndPoint": "hir-oss.test.extimaging.com",
"port": "443", "Port": "443",
"useSSL": true, "UseSSL": true,
"accessKey": "fbStsVYCIPKHQneeqMwD", "AccessKey": "fbStsVYCIPKHQneeqMwD",
"secretKey": "TzgvyA3zGXMUnpilJNUlyMYHfosl1hBMl6lxPmjy", "SecretKey": "TzgvyA3zGXMUnpilJNUlyMYHfosl1hBMl6lxPmjy",
"bucketName": "irc-test", "BucketName": "irc-test",
"viewEndpoint": "https://hir-oss.test.extimaging.com/irc-test" "ViewEndpoint": "https://hir-oss.test.extimaging.com/irc-test"
}, },
"AWS": { "AWS": {
"endPoint": "s3.us-east-1.amazonaws.com", "EndPoint": "s3.us-east-1.amazonaws.com",
"useSSL": true, "UseSSL": true,
"accessKey": "AKIAZQ3DRSOHFPJJ6FEU", "AccessKey": "AKIAZQ3DRSOHFPJJ6FEU",
"secretKey": "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", "SecretKey": "l+yjtvV7Z4jiwm/7xCYv30UeUj/SvuqqYzAwjJHf",
"bucketName": "ei-irc-test-store", "BucketName": "ei-irc-test-store",
"viewEndpoint": "https://ei-irc-test-store.s3.amazonaws.com/" "ViewEndpoint": "https://ei-irc-test-store.s3.amazonaws.com/"
} }
}, },

View File

@ -19,43 +19,46 @@ using Minio.ApiEndpoints;
using System.Reactive.Linq; using System.Reactive.Linq;
using IRaCIS.Core.Domain.Share; using IRaCIS.Core.Domain.Share;
using static MassTransit.ValidationResultExtensions; using static MassTransit.ValidationResultExtensions;
using IRaCIS.Core.Infrastructure.NewtonsoftJson;
namespace IRaCIS.Core.Application.Helper namespace IRaCIS.Core.Application.Helper
{ {
[LowerCamelCaseJson]
public class MinIOOptions : AWSOptions public class MinIOOptions : AWSOptions
{ {
public int port { get; set; } public int Port { get; set; }
} }
[LowerCamelCaseJson]
public class AWSOptions public class AWSOptions
{ {
public string endPoint { get; set; } public string EndPoint { get; set; }
public bool useSSL { get; set; } public bool UseSSL { get; set; }
public string accessKey { get; set; } public string AccessKey { get; set; }
public string secretKey { get; set; } public string SecretKey { get; set; }
public string bucketName { get; set; } public string BucketName { get; set; }
public string viewEndpoint { get; set; } public string ViewEndpoint { get; set; }
} }
public class AliyunOSSOptions public class AliyunOSSOptions
{ {
public string regionId { get; set; } public string RegionId { get; set; }
public string accessKeyId { get; set; } public string AccessKeyId { get; set; }
public string accessKeySecret { get; set; } public string AccessKeySecret { get; set; }
public string internalEndpoint { get; set; } public string InternalEndpoint { get; set; }
public string endPoint { get; set; } public string EndPoint { get; set; }
public string bucketName { get; set; } public string BucketName { get; set; }
public string roleArn { get; set; } public string RoleArn { get; set; }
public string region { get; set; } public string Region { get; set; }
public string viewEndpoint { get; set; } public string ViewEndpoint { get; set; }
public int durationSeconds { get; set; } public int DurationSeconds { get; set; }
@ -87,17 +90,27 @@ namespace IRaCIS.Core.Application.Helper
} }
[LowerCamelCaseJson]
public class AliyunOSSTempToken public class AliyunOSSTempToken
{ {
public string accessKeyId { get; set; } public string AccessKeyId { get; set; }
public string accessKeySecret { get; set; } public string AccessKeySecret { get; set; }
public string securityToken { get; set; }
public string expiration { get; set; }
public string EndPoint { get; set; }
public string BucketName { get; set; }
public string Region { get; set; }
public string ViewEndpoint { get; set; }
public string SecurityToken { get; set; }
public string Expiration { get; set; }
public string region { get; set; }
public string bucketName { get; set; }
public string endPoint { get; set; }
public string viewEndpoint { get; set; }
} }
@ -163,12 +176,12 @@ namespace IRaCIS.Core.Application.Helper
{ {
var aliConfig = ObjectStoreServiceOptions.AliyunOSS; var aliConfig = ObjectStoreServiceOptions.AliyunOSS;
var _ossClient = new OssClient(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? aliConfig.endPoint : aliConfig.internalEndpoint, aliConfig.accessKeyId, aliConfig.accessKeySecret); var _ossClient = new OssClient(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? aliConfig.EndPoint : aliConfig.InternalEndpoint, aliConfig.AccessKeyId, aliConfig.AccessKeySecret);
// 上传文件 // 上传文件
var result = _ossClient.PutObject(aliConfig.bucketName, ossRelativePath, memoryStream); var result = _ossClient.PutObject(aliConfig.BucketName, ossRelativePath, memoryStream);
} }
else if (ObjectStoreServiceOptions.ObjectStoreUse == "MinIO") else if (ObjectStoreServiceOptions.ObjectStoreUse == "MinIO")
@ -176,12 +189,12 @@ namespace IRaCIS.Core.Application.Helper
var minIOConfig = ObjectStoreServiceOptions.MinIO; var minIOConfig = ObjectStoreServiceOptions.MinIO;
var minioClient = new MinioClient().WithEndpoint($"{minIOConfig.endPoint}:{minIOConfig.port}") var minioClient = new MinioClient().WithEndpoint($"{minIOConfig.EndPoint}:{minIOConfig.Port}")
.WithCredentials(minIOConfig.accessKey, minIOConfig.secretKey).WithSSL(minIOConfig.useSSL) .WithCredentials(minIOConfig.AccessKey, minIOConfig.SecretKey).WithSSL(minIOConfig.UseSSL)
.Build(); .Build();
var putObjectArgs = new PutObjectArgs() var putObjectArgs = new PutObjectArgs()
.WithBucket(minIOConfig.bucketName) .WithBucket(minIOConfig.BucketName)
.WithObject(ossRelativePath) .WithObject(ossRelativePath)
.WithStreamData(memoryStream) .WithStreamData(memoryStream)
.WithObjectSize(memoryStream.Length); .WithObjectSize(memoryStream.Length);
@ -193,12 +206,12 @@ namespace IRaCIS.Core.Application.Helper
var minIOConfig = ObjectStoreServiceOptions.AWS; var minIOConfig = ObjectStoreServiceOptions.AWS;
var minioClient = new MinioClient().WithEndpoint($"{minIOConfig.endPoint}") var minioClient = new MinioClient().WithEndpoint($"{minIOConfig.EndPoint}")
.WithCredentials(minIOConfig.accessKey, minIOConfig.secretKey).WithSSL(minIOConfig.useSSL) .WithCredentials(minIOConfig.AccessKey, minIOConfig.SecretKey).WithSSL(minIOConfig.UseSSL)
.Build(); .Build();
var putObjectArgs = new PutObjectArgs() var putObjectArgs = new PutObjectArgs()
.WithBucket(minIOConfig.bucketName) .WithBucket(minIOConfig.BucketName)
.WithObject(ossRelativePath) .WithObject(ossRelativePath)
.WithStreamData(memoryStream) .WithStreamData(memoryStream)
.WithObjectSize(memoryStream.Length); .WithObjectSize(memoryStream.Length);
@ -247,10 +260,10 @@ namespace IRaCIS.Core.Application.Helper
{ {
var aliConfig = ObjectStoreServiceOptions.AliyunOSS; var aliConfig = ObjectStoreServiceOptions.AliyunOSS;
var _ossClient = new OssClient(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? aliConfig.endPoint : aliConfig.internalEndpoint, aliConfig.accessKeyId, aliConfig.accessKeySecret); var _ossClient = new OssClient(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? aliConfig.EndPoint : aliConfig.InternalEndpoint, aliConfig.AccessKeyId, aliConfig.AccessKeySecret);
// 上传文件 // 上传文件
var result = _ossClient.PutObject(aliConfig.bucketName, ossRelativePath, localFilePath); var result = _ossClient.PutObject(aliConfig.BucketName, ossRelativePath, localFilePath);
} }
else if (ObjectStoreServiceOptions.ObjectStoreUse == "MinIO") else if (ObjectStoreServiceOptions.ObjectStoreUse == "MinIO")
@ -258,12 +271,12 @@ namespace IRaCIS.Core.Application.Helper
var minIOConfig = ObjectStoreServiceOptions.MinIO; var minIOConfig = ObjectStoreServiceOptions.MinIO;
var minioClient = new MinioClient().WithEndpoint($"{minIOConfig.endPoint}:{minIOConfig.port}") var minioClient = new MinioClient().WithEndpoint($"{minIOConfig.EndPoint}:{minIOConfig.Port}")
.WithCredentials(minIOConfig.accessKey, minIOConfig.secretKey).WithSSL(minIOConfig.useSSL) .WithCredentials(minIOConfig.AccessKey, minIOConfig.SecretKey).WithSSL(minIOConfig.UseSSL)
.Build(); .Build();
var putObjectArgs = new PutObjectArgs() var putObjectArgs = new PutObjectArgs()
.WithBucket(minIOConfig.bucketName) .WithBucket(minIOConfig.BucketName)
.WithObject(ossRelativePath) .WithObject(ossRelativePath)
.WithFileName(localFilePath); .WithFileName(localFilePath);
@ -274,12 +287,12 @@ namespace IRaCIS.Core.Application.Helper
var minIOConfig = ObjectStoreServiceOptions.AWS; var minIOConfig = ObjectStoreServiceOptions.AWS;
var minioClient = new MinioClient().WithEndpoint($"{minIOConfig.endPoint}") var minioClient = new MinioClient().WithEndpoint($"{minIOConfig.EndPoint}")
.WithCredentials(minIOConfig.accessKey, minIOConfig.secretKey).WithSSL(minIOConfig.useSSL) .WithCredentials(minIOConfig.AccessKey, minIOConfig.SecretKey).WithSSL(minIOConfig.UseSSL)
.Build(); .Build();
var putObjectArgs = new PutObjectArgs() var putObjectArgs = new PutObjectArgs()
.WithBucket(minIOConfig.bucketName) .WithBucket(minIOConfig.BucketName)
.WithObject(ossRelativePath) .WithObject(ossRelativePath)
.WithFileName(localFilePath); .WithFileName(localFilePath);
@ -306,10 +319,10 @@ namespace IRaCIS.Core.Application.Helper
{ {
var aliConfig = ObjectStoreServiceOptions.AliyunOSS; var aliConfig = ObjectStoreServiceOptions.AliyunOSS;
var _ossClient = new OssClient(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? aliConfig.endPoint : aliConfig.internalEndpoint, aliConfig.accessKeyId, aliConfig.accessKeySecret); var _ossClient = new OssClient(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? aliConfig.EndPoint : aliConfig.InternalEndpoint, aliConfig.AccessKeyId, aliConfig.AccessKeySecret);
// 上传文件 // 上传文件
var result = _ossClient.GetObject(aliConfig.bucketName, ossRelativePath); var result = _ossClient.GetObject(aliConfig.BucketName, ossRelativePath);
// 将下载的文件流保存到本地文件 // 将下载的文件流保存到本地文件
using (var fs = File.OpenWrite(localFilePath)) using (var fs = File.OpenWrite(localFilePath))
@ -323,12 +336,12 @@ namespace IRaCIS.Core.Application.Helper
{ {
var minIOConfig = ObjectStoreServiceOptions.MinIO; var minIOConfig = ObjectStoreServiceOptions.MinIO;
var minioClient = new MinioClient().WithEndpoint($"{minIOConfig.endPoint}:{minIOConfig.port}") var minioClient = new MinioClient().WithEndpoint($"{minIOConfig.EndPoint}:{minIOConfig.Port}")
.WithCredentials(minIOConfig.accessKey, minIOConfig.secretKey).WithSSL(minIOConfig.useSSL) .WithCredentials(minIOConfig.AccessKey, minIOConfig.SecretKey).WithSSL(minIOConfig.UseSSL)
.Build(); .Build();
var getObjectArgs = new GetObjectArgs() var getObjectArgs = new GetObjectArgs()
.WithBucket(minIOConfig.bucketName) .WithBucket(minIOConfig.BucketName)
.WithObject(ossRelativePath) .WithObject(ossRelativePath)
.WithFile(localFilePath); .WithFile(localFilePath);
@ -339,12 +352,12 @@ namespace IRaCIS.Core.Application.Helper
{ {
var minIOConfig = ObjectStoreServiceOptions.AWS; var minIOConfig = ObjectStoreServiceOptions.AWS;
var minioClient = new MinioClient().WithEndpoint($"{minIOConfig.endPoint}") var minioClient = new MinioClient().WithEndpoint($"{minIOConfig.EndPoint}")
.WithCredentials(minIOConfig.accessKey, minIOConfig.secretKey).WithSSL(minIOConfig.useSSL) .WithCredentials(minIOConfig.AccessKey, minIOConfig.SecretKey).WithSSL(minIOConfig.UseSSL)
.Build(); .Build();
var getObjectArgs = new GetObjectArgs() var getObjectArgs = new GetObjectArgs()
.WithBucket(minIOConfig.bucketName) .WithBucket(minIOConfig.BucketName)
.WithObject(ossRelativePath) .WithObject(ossRelativePath)
.WithFile(localFilePath); .WithFile(localFilePath);
@ -378,10 +391,10 @@ namespace IRaCIS.Core.Application.Helper
{ {
var aliConfig = ObjectStoreServiceOptions.AliyunOSS; var aliConfig = ObjectStoreServiceOptions.AliyunOSS;
var _ossClient = new OssClient(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? aliConfig.endPoint : aliConfig.internalEndpoint, aliConfig.accessKeyId, aliConfig.accessKeySecret); var _ossClient = new OssClient(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? aliConfig.EndPoint : aliConfig.InternalEndpoint, aliConfig.AccessKeyId, aliConfig.AccessKeySecret);
// 生成签名URL。 // 生成签名URL。
var req = new GeneratePresignedUriRequest(aliConfig.bucketName, ossRelativePath, SignHttpMethod.Get) var req = new GeneratePresignedUriRequest(aliConfig.BucketName, ossRelativePath, SignHttpMethod.Get)
{ {
// 设置签名URL过期时间默认值为3600秒。 // 设置签名URL过期时间默认值为3600秒。
Expiration = DateTime.Now.AddHours(1), Expiration = DateTime.Now.AddHours(1),
@ -395,13 +408,13 @@ namespace IRaCIS.Core.Application.Helper
{ {
var minIOConfig = ObjectStoreServiceOptions.MinIO; var minIOConfig = ObjectStoreServiceOptions.MinIO;
var minioClient = new MinioClient().WithEndpoint($"{minIOConfig.endPoint}:{minIOConfig.port}") var minioClient = new MinioClient().WithEndpoint($"{minIOConfig.EndPoint}:{minIOConfig.Port}")
.WithCredentials(minIOConfig.accessKey, minIOConfig.secretKey).WithSSL(minIOConfig.useSSL) .WithCredentials(minIOConfig.AccessKey, minIOConfig.SecretKey).WithSSL(minIOConfig.UseSSL)
.Build(); .Build();
var args = new PresignedGetObjectArgs() var args = new PresignedGetObjectArgs()
.WithBucket(minIOConfig.bucketName) .WithBucket(minIOConfig.BucketName)
.WithObject(ossRelativePath) .WithObject(ossRelativePath)
.WithExpiry(3600) .WithExpiry(3600)
/*.WithHeaders(reqParams)*/; /*.WithHeaders(reqParams)*/;
@ -420,12 +433,12 @@ namespace IRaCIS.Core.Application.Helper
{ {
var minIOConfig = ObjectStoreServiceOptions.AWS; var minIOConfig = ObjectStoreServiceOptions.AWS;
var minioClient = new MinioClient().WithEndpoint($"{minIOConfig.endPoint}") var minioClient = new MinioClient().WithEndpoint($"{minIOConfig.EndPoint}")
.WithCredentials(minIOConfig.accessKey, minIOConfig.secretKey).WithSSL(minIOConfig.useSSL) .WithCredentials(minIOConfig.AccessKey, minIOConfig.SecretKey).WithSSL(minIOConfig.UseSSL)
.Build(); .Build();
var args = new PresignedGetObjectArgs() var args = new PresignedGetObjectArgs()
.WithBucket(minIOConfig.bucketName) .WithBucket(minIOConfig.BucketName)
.WithObject(ossRelativePath) .WithObject(ossRelativePath)
.WithExpiry(3600); .WithExpiry(3600);
@ -462,7 +475,7 @@ namespace IRaCIS.Core.Application.Helper
{ {
var aliConfig = ObjectStoreServiceOptions.AliyunOSS; var aliConfig = ObjectStoreServiceOptions.AliyunOSS;
var _ossClient = new OssClient(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? aliConfig.endPoint : aliConfig.internalEndpoint, aliConfig.accessKeyId, aliConfig.accessKeySecret); var _ossClient = new OssClient(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? aliConfig.EndPoint : aliConfig.InternalEndpoint, aliConfig.AccessKeyId, aliConfig.AccessKeySecret);
try try
@ -472,7 +485,7 @@ namespace IRaCIS.Core.Application.Helper
do do
{ {
// 使用 prefix 模拟目录结构,设置 MaxKeys 和 NextMarker // 使用 prefix 模拟目录结构,设置 MaxKeys 和 NextMarker
objectListing = _ossClient.ListObjects(new ListObjectsRequest(aliConfig.bucketName) objectListing = _ossClient.ListObjects(new ListObjectsRequest(aliConfig.BucketName)
{ {
Prefix = prefix, Prefix = prefix,
MaxKeys = 1000, MaxKeys = 1000,
@ -484,7 +497,7 @@ namespace IRaCIS.Core.Application.Helper
// 删除获取到的文件 // 删除获取到的文件
if (keys.Count > 0) if (keys.Count > 0)
{ {
_ossClient.DeleteObjects(new DeleteObjectsRequest(aliConfig.bucketName, keys, false)); _ossClient.DeleteObjects(new DeleteObjectsRequest(aliConfig.BucketName, keys, false));
} }
// 设置 NextMarker 以获取下一页的数据 // 设置 NextMarker 以获取下一页的数据
@ -504,12 +517,12 @@ namespace IRaCIS.Core.Application.Helper
var minIOConfig = ObjectStoreServiceOptions.MinIO; var minIOConfig = ObjectStoreServiceOptions.MinIO;
var minioClient = new MinioClient().WithEndpoint($"{minIOConfig.endPoint}:{minIOConfig.port}") var minioClient = new MinioClient().WithEndpoint($"{minIOConfig.EndPoint}:{minIOConfig.Port}")
.WithCredentials(minIOConfig.accessKey, minIOConfig.secretKey).WithSSL(minIOConfig.useSSL) .WithCredentials(minIOConfig.AccessKey, minIOConfig.SecretKey).WithSSL(minIOConfig.UseSSL)
.Build(); .Build();
var listArgs = new ListObjectsArgs().WithBucket(minIOConfig.bucketName).WithPrefix(prefix).WithRecursive(true); var listArgs = new ListObjectsArgs().WithBucket(minIOConfig.BucketName).WithPrefix(prefix).WithRecursive(true);
@ -518,7 +531,7 @@ namespace IRaCIS.Core.Application.Helper
if (objects.Count > 0) if (objects.Count > 0)
{ {
var objArgs = new RemoveObjectsArgs() var objArgs = new RemoveObjectsArgs()
.WithBucket(minIOConfig.bucketName) .WithBucket(minIOConfig.BucketName)
.WithObjects(objects); .WithObjects(objects);
// 删除对象 // 删除对象

View File

@ -78,11 +78,12 @@ namespace IRaCIS.Core.Application.Service.ImageAndDoc.DTO
public string TaskBlindName { get; set; } public string TaskBlindName { get; set; }
public string TaskName { get; set; } public string TaskName { get; set; }
public Guid? SourceSubjectVisitId { get; set; }
public bool IsImageFilter { get; set; } public bool IsImageFilter { get; set; }
public string CriterionModalitys { get; set; } public string CriterionModalitys { get; set; }
public Guid? SourceSubjectVisitId { get; set; }
public List<DicomStudyBasicInfo> DicomStudyList { get; set; } public List<DicomStudyBasicInfo> DicomStudyList { get; set; }

View File

@ -385,6 +385,18 @@ namespace IRaCIS.Core.Application.Contracts
} }
public class IRUploadStudyQuery : SortInput
{
[NotDefault]
public Guid SubjectId { get; set; }
[NotDefault]
public Guid TrialReadingCriterionId { get; set; }
[NotDefault]
public string SubjectCode { get; set; }
}
public class IRUploadTaskDicomStudyDto : DicomStudyBasicInfo public class IRUploadTaskDicomStudyDto : DicomStudyBasicInfo
{ {
@ -403,6 +415,47 @@ namespace IRaCIS.Core.Application.Contracts
public int UploadedFileCount { get; set; } public int UploadedFileCount { get; set; }
} }
public class TaskDicomStudyDTO: DicomStudyBasicInfo
{
public Guid SubjectId { get; set; }
public string SubjectCode { get; set; }
public string TaskBlindName { get; set; }
public string TaskName { get; set; }
public Guid? SourceSubjectVisitId { get; set; }
public int UploadedSeriesCount { get; set; }
public int UploadedInstanceCount { get; set; }
public List<string> UploadedSopInstanceUidList { get; set; }
}
public class TaskNoneDicomStudyDTO : NoneDicomStudyBasicInfo
{
public int UploadedFileCount { get; set; }
public Guid SubjectId { get; set; }
public string SubjectCode { get; set; }
public string TaskBlindName { get; set; }
public string TaskName { get; set; }
public Guid? SourceSubjectVisitId { get; set; }
}
public class CRCUploadedStudyQuqry public class CRCUploadedStudyQuqry

View File

@ -1,5 +1,4 @@
using DocumentFormat.OpenXml.Office2010.Ink; using FellowOakDicom;
using FellowOakDicom;
using IRaCIS.Core.Application.Contracts; using IRaCIS.Core.Application.Contracts;
using IRaCIS.Core.Application.Filter; using IRaCIS.Core.Application.Filter;
using IRaCIS.Core.Application.Helper; using IRaCIS.Core.Application.Helper;
@ -9,13 +8,14 @@ using IRaCIS.Core.Domain.Share;
using IRaCIS.Core.Infrastructure; using IRaCIS.Core.Infrastructure;
using IRaCIS.Core.Infrastructure.Extention; using IRaCIS.Core.Infrastructure.Extention;
using MassTransit; using MassTransit;
using MassTransit.Initializers;
using MathNet.Numerics; using MathNet.Numerics;
using Medallion.Threading; using Medallion.Threading;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion.Internal;
using Newtonsoft.Json; using Newtonsoft.Json;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Immutable;
using System.Data; using System.Data;
using System.IO.Compression; using System.IO.Compression;
using System.Linq; using System.Linq;
@ -43,6 +43,8 @@ namespace IRaCIS.Core.Application.Service.ImageAndDoc
IRepository<TaskSeries> _taskSeriesRepository, IRepository<TaskSeries> _taskSeriesRepository,
IRepository<TaskInstance> _taskInstanceRepository, IRepository<TaskInstance> _taskInstanceRepository,
IRepository<ReadingQuestionCriterionTrial> _readingQuestionCriterionTrialRepository, IRepository<ReadingQuestionCriterionTrial> _readingQuestionCriterionTrialRepository,
IRepository<NoneDicomStudy> _noneDicomStudyReposiotry,
IRepository<NoneDicomStudyFile> _noneDicomStudyFileReposiotry,
IDistributedLockProvider _distributedLockProvider) : BaseService, IDownloadAndUploadService IDistributedLockProvider _distributedLockProvider) : BaseService, IDownloadAndUploadService
{ {
@ -98,14 +100,13 @@ namespace IRaCIS.Core.Application.Service.ImageAndDoc
/// <summary> /// <summary>
/// 获取该受试者任务上传列表(展示已上传情况) /// 获取该受试者任务上传列表(展示已上传情况)
/// </summary> /// </summary>
/// <param name="subjectId"></param>
/// <param name="trialReadingCriterionId"></param>
/// <returns></returns> /// <returns></returns>
public async Task<IResponseOutput<List<SubjectImageUploadDTO>>> GetSubjectImageUploadList(Guid subjectId, Guid trialReadingCriterionId) [HttpPost]
public async Task<IResponseOutput<List<SubjectImageUploadDTO>>> GetSubjectImageUploadList(IRUploadStudyQuery inQuery)
{ {
await SubejctRandomReadingTaskNameDeal(subjectId, trialReadingCriterionId); await SubejctRandomReadingTaskNameDeal(inQuery.SubjectId, inQuery.TrialReadingCriterionId);
var query = _visitTaskRepository.Where(t => t.SubjectId == subjectId && t.TrialReadingCriterionId == trialReadingCriterionId && t.SourceSubjectVisitId != null var query = _visitTaskRepository.Where(t => t.SubjectId == inQuery.SubjectId && t.TrialReadingCriterionId == inQuery.TrialReadingCriterionId && t.SourceSubjectVisitId != null
&& t.DoctorUserId == _userInfo.Id && t.TaskState == TaskState.Effect) && t.DoctorUserId == _userInfo.Id && t.TaskState == TaskState.Effect)
.Select(u => new SubjectImageUploadDTO() .Select(u => new SubjectImageUploadDTO()
{ {
@ -165,7 +166,7 @@ namespace IRaCIS.Core.Application.Service.ImageAndDoc
}) })
; ;
var list = await query.ToListAsync(); var list = await query.Where(t => t.SubjectCode == inQuery.SubjectCode).ToListAsync();
return ResponseOutput.Ok(list); return ResponseOutput.Ok(list);
} }
@ -468,12 +469,18 @@ namespace IRaCIS.Core.Application.Service.ImageAndDoc
[HttpDelete] [HttpDelete]
public async Task<IResponseOutput> DeleteTaskStudy(Guid visitTaskId) public async Task<IResponseOutput> DeleteTaskStudy(Guid visitTaskId, bool isDicom, Guid? noneDicomStudyId)
{
if (isDicom)
{ {
await _taskStudyRepository.BatchDeleteNoTrackingAsync(t => t.VisitTaskId == visitTaskId); await _taskStudyRepository.BatchDeleteNoTrackingAsync(t => t.VisitTaskId == visitTaskId);
await _taskSeriesRepository.BatchDeleteNoTrackingAsync(t => t.VisitTaskId == visitTaskId); await _taskSeriesRepository.BatchDeleteNoTrackingAsync(t => t.VisitTaskId == visitTaskId);
await _taskInstanceRepository.BatchDeleteNoTrackingAsync(t => t.VisitTaskId == visitTaskId); await _taskInstanceRepository.BatchDeleteNoTrackingAsync(t => t.VisitTaskId == visitTaskId);
}
else
{
await _noneDicomStudyFileReposiotry.BatchDeleteNoTrackingAsync(t => t.VisitTaskId == visitTaskId && t.NoneDicomStudyId == noneDicomStudyId);
}
return ResponseOutput.Ok(); return ResponseOutput.Ok();
} }
@ -895,13 +902,15 @@ namespace IRaCIS.Core.Application.Service.ImageAndDoc
} }
#region 按照任务为维度 展示上传的列表 废弃
/// <summary> /// <summary>
/// IR 影像上传任务列表 --old 20240903 界面调整,现在先废弃 /// IR 影像上传任务列表 --old 20240903 界面调整,现在先废弃
/// </summary> /// </summary>
/// <param name="inQuery"></param> /// <param name="inQuery"></param>
/// <returns></returns> /// <returns></returns>
[HttpPost] [HttpPost]
public async Task<List<SubjectUploadTaskInfo>> GetIRUploadTaskList(CRCUploadTaskQuery inQuery) public async Task<List<SubjectUploadTaskInfo>> GetIRUploadTaskList_Old(CRCUploadTaskQuery inQuery)
{ {
var query = _visitTaskRepository.Where(t => t.SubjectId == inQuery.SubjectId && t.TrialReadingCriterionId == inQuery.TrialReadingCriterionId var query = _visitTaskRepository.Where(t => t.SubjectId == inQuery.SubjectId && t.TrialReadingCriterionId == inQuery.TrialReadingCriterionId
&& t.SourceSubjectVisitId != null && t.DoctorUserId == _userInfo.Id && t.TaskState == TaskState.Effect) && t.SourceSubjectVisitId != null && t.DoctorUserId == _userInfo.Id && t.TaskState == TaskState.Effect)
@ -913,12 +922,12 @@ namespace IRaCIS.Core.Application.Service.ImageAndDoc
return list; return list;
} }
/// <summary> /// <summary>
/// IR 上传任务 dicom 列表 后处理的数据不能排序 /// IR 上传任务 dicom 列表 后处理的数据不能排序 --old 20240903 界面调整,现在先废弃
/// </summary> /// </summary>
/// <param name="inQuery"></param> /// <param name="inQuery"></param>
/// <returns></returns> /// <returns></returns>
[HttpPost] [HttpPost]
public async Task<List<IRUploadTaskDicomStudyDto>> GetIRUploadTaskDicomStudyList(CRCUploadTaskStudyQuery inQuery) public async Task<List<IRUploadTaskDicomStudyDto>> GetIRUploadTaskDicomStudyList_Old(CRCUploadTaskStudyQuery inQuery)
{ {
var list = await _visitTaskRepository.Where(t => t.Id == inQuery.VisitTaskId) var list = await _visitTaskRepository.Where(t => t.Id == inQuery.VisitTaskId)
.SelectMany(t => t.SourceSubjectVisit.StudyList) .SelectMany(t => t.SourceSubjectVisit.StudyList)
@ -951,12 +960,12 @@ namespace IRaCIS.Core.Application.Service.ImageAndDoc
} }
/// <summary> /// <summary>
/// IR 上传任务 nonedicom 列表 后处理的数据不能排序 /// IR 上传任务 nonedicom 列表 后处理的数据不能排序 --old 20240903 界面调整,现在先废弃
/// </summary> /// </summary>
/// <param name="inQuery"></param> /// <param name="inQuery"></param>
/// <returns></returns> /// <returns></returns>
[HttpPost] [HttpPost]
public async Task<List<IRUploadTaskNoneDicomStudyDto>> GetIRUploadTaskNoneDicomStudyList(CRCUploadTaskStudyQuery inQuery) public async Task<List<IRUploadTaskNoneDicomStudyDto>> GetIRUploadTaskNoneDicomStudyList_Old(CRCUploadTaskStudyQuery inQuery)
{ {
var list = await _visitTaskRepository.Where(t => t.Id == inQuery.VisitTaskId) var list = await _visitTaskRepository.Where(t => t.Id == inQuery.VisitTaskId)
.SelectMany(t => t.SourceSubjectVisit.StudyList) .SelectMany(t => t.SourceSubjectVisit.StudyList)
@ -978,9 +987,70 @@ namespace IRaCIS.Core.Application.Service.ImageAndDoc
return list; return list;
} }
#endregion
#region IR 上传 列表dicom 上以任务为维度非dicom 以检查为维度
/// <summary>
/// IR 上传任务 nonedicom 列表 后处理的数据UploadedFileCount不能排序 --new
/// </summary>
/// <param name="inQuery"></param>
/// <returns></returns>
[HttpPost]
public async Task<List<TaskNoneDicomStudyDTO>> GetIRUploadTaskNoneDicomStudyList(IRUploadStudyQuery inQuery)
{
var query = from u in _visitTaskRepository.Where(t => t.SubjectId == inQuery.SubjectId && t.TrialReadingCriterionId == inQuery.TrialReadingCriterionId
&& t.SourceSubjectVisitId != null && t.DoctorUserId == _userInfo.Id && t.TaskState == TaskState.Effect)
join ns in _noneDicomStudyReposiotry.Where(t => t.SubjectId == inQuery.SubjectId) on u.SourceSubjectVisitId equals ns.SubjectVisitId
select new TaskNoneDicomStudyDTO()
{
SubjectId = u.SubjectId,
SubjectCode = u.IsSelfAnalysis == true ? u.BlindSubjectCode : u.Subject.Code,
TaskBlindName = u.TaskBlindName,
TaskName = u.TaskName,
SourceSubjectVisitId = u.SourceSubjectVisitId,
Id = ns.Id,
Description = ns.Description,
ImageDate = ns.ImageDate,
BodyPart = ns.BodyPart,
FileCount = ns.FileCount,
Modality = ns.Modality,
StudyCode = ns.StudyCode,
};
var list = await query.Where(t => t.SubjectCode == inQuery.SubjectCode).SortToListAsync(inQuery);
var noneDicomStudyIdList = list.Select(t => t.Id).ToList();
var taskNoneDicomStudyList = _visitTaskRepository.Where(t => noneDicomStudyIdList.Contains(t.Id))
.SelectMany(t => t.TaskNoneDicomStudyFileList).Where(t => noneDicomStudyIdList.Contains((Guid)t.VisitTaskId))
.Select(u => new
{
u.OriginNoneDicomStudyId,
})
.ToList();
foreach (var item in list)
{
item.UploadedFileCount = taskNoneDicomStudyList.Where(t => t.OriginNoneDicomStudyId == item.Id).Count();
}
return list;
}
#endregion
/// <summary> /// <summary>
/// IQC 获取CRC 上传到某一个访视的的检查信息 (原始影像信息 包含dicom 非dicom) /// IQC 获取CRC 上传到某一个访视的的检查信息 (原始影像信息 包含dicom 非dicom)
/// </summary> /// </summary>

View File

@ -576,7 +576,6 @@ namespace IRaCIS.Core.Application.Service
else else
{ {
para = $"{JsonData["item"].ToString()}"; para = $"{JsonData["item"].ToString()}";
ForeignKeyText = "UserName";
if (_frontAuditConfigRepository._dbContext.Database.IsSqlServer()) if (_frontAuditConfigRepository._dbContext.Database.IsSqlServer())
{ {

View File

@ -9,6 +9,7 @@ using IRaCIS.Core.Application.Service;
using IRaCIS.Core.Application.ViewModel; using IRaCIS.Core.Application.ViewModel;
using IRaCIS.Core.Domain.Share; using IRaCIS.Core.Domain.Share;
using IRaCIS.Core.Infrastructure; using IRaCIS.Core.Infrastructure;
using IRaCIS.Core.Infrastructure.NewtonsoftJson;
using MassTransit; using MassTransit;
using Medallion.Threading; using Medallion.Threading;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
@ -104,6 +105,25 @@ namespace IRaCIS.Application.Services
return ResponseOutput.Ok(); return ResponseOutput.Ok();
} }
[LowerCamelCaseJson]
public class TestModel
{
public Guid TestId { get; set; }
public string TestName { get; set; }
}
public class TestModel2
{
public Guid TestId { get; set; }
}
public IResponseOutput TestJson()
{
return ResponseOutput.Ok(new TestModel(), new TestModel2());
}
public string TestHoliday(DateTime startdate,DateTime endDate) public string TestHoliday(DateTime startdate,DateTime endDate)
{ {
@ -522,7 +542,7 @@ namespace IRaCIS.Application.Services
{ {
var aliConfig = oSSService.ObjectStoreServiceOptions.AliyunOSS; var aliConfig = oSSService.ObjectStoreServiceOptions.AliyunOSS;
var _ossClient = new OssClient(aliConfig.endPoint, aliConfig.accessKeyId, aliConfig.accessKeySecret); var _ossClient = new OssClient(aliConfig.EndPoint, aliConfig.AccessKeyId, aliConfig.AccessKeySecret);
var rootPath = FileStoreHelper.GetIRaCISRootDataFolder(_hostEnvironment); var rootPath = FileStoreHelper.GetIRaCISRootDataFolder(_hostEnvironment);
@ -539,7 +559,7 @@ namespace IRaCIS.Application.Services
do do
{ {
// 使用 prefix 模拟目录结构,设置 MaxKeys 和 NextMarker // 使用 prefix 模拟目录结构,设置 MaxKeys 和 NextMarker
var objectListing = _ossClient.ListObjects(new ListObjectsRequest(aliConfig.bucketName) var objectListing = _ossClient.ListObjects(new ListObjectsRequest(aliConfig.BucketName)
{ {
Prefix = relativePath, Prefix = relativePath,
MaxKeys = 1000, MaxKeys = 1000,

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace IRaCIS.Core.Infrastructure.NewtonsoftJson
{
[AttributeUsage(AttributeTargets.Class)]
public class LowerCamelCaseJsonAttribute : Attribute
{
}
}

View File

@ -0,0 +1,18 @@
using Newtonsoft.Json.Serialization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace IRaCIS.Core.Infrastructure.NewtonsoftJson
{
public class LowerCamelCaseNamingStrategy : NamingStrategy
{
protected override string ResolvePropertyName(string name)
{
// 将属性名的首字母转换为小写
return char.ToLower(name[0]) + name.Substring(1);
}
}
}