diff --git a/IRaCIS.Core.API/Progranm.cs b/IRaCIS.Core.API/Progranm.cs index 33c2d6fc8..62e075ff6 100644 --- a/IRaCIS.Core.API/Progranm.cs +++ b/IRaCIS.Core.API/Progranm.cs @@ -33,6 +33,7 @@ using Newtonsoft.Json; using Microsoft.AspNetCore.Diagnostics; using IRaCIS.Core.Application.MassTransit.Command; using IRaCIS.Core.Application.MassTransit.Consumer; +using DocumentFormat.OpenXml.InkML; AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); AppContext.SetSwitch("Npgsql.DisableDateTimeInfinityConversions", true); @@ -124,6 +125,8 @@ builder.Services.AddOptions().Configure(_configuratio builder.Services.AddOptions().Configure(_configuration.GetSection("EncrypteResponseConfig")); builder.Services.AddOptions().Configure(_configuration.GetSection("SystemPacsConfig")); +builder.Services.Configure(_configuration.GetSection("IRaCISBasicConfig")); + //动态WebApi + UnifiedApiResultFilter 省掉控制器代码 builder.Services.AddDynamicWebApiSetup(); diff --git a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml index 21ad9d7aa..2bf6dcab9 100644 --- a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml +++ b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml @@ -1404,6 +1404,7 @@ 格式化日期和时间 + @@ -1421,6 +1422,7 @@ 标识 标识 + Json对象 diff --git a/IRaCIS.Core.Application/Service/ImageAndDoc/ImageShareService.cs b/IRaCIS.Core.Application/Service/ImageAndDoc/ImageShareService.cs index 47c2c9f21..2422493ce 100644 --- a/IRaCIS.Core.Application/Service/ImageAndDoc/ImageShareService.cs +++ b/IRaCIS.Core.Application/Service/ImageAndDoc/ImageShareService.cs @@ -61,7 +61,7 @@ namespace IRaCIS.Core.Application.Services //配置文件读取过期时间 - var days = AppSettings.ImageShareExpireDays; + var days = AppSettings.IRaCISBasicConfig.ImageShareExpireDays; imageShareCommand.ExpireTime = DateTime.Now.AddDays(days); diff --git a/IRaCIS.Core.Application/Service/Inspection/FrontAuditConfigService.cs b/IRaCIS.Core.Application/Service/Inspection/FrontAuditConfigService.cs index e1c3e5653..e48d7d026 100644 --- a/IRaCIS.Core.Application/Service/Inspection/FrontAuditConfigService.cs +++ b/IRaCIS.Core.Application/Service/Inspection/FrontAuditConfigService.cs @@ -439,6 +439,7 @@ namespace IRaCIS.Core.Application.Service /// 格式化日期和时间 /// /// + /// /// /// private async Task SetDataInspectionDateType(List identificationList, string identification, string jsonStr) @@ -629,6 +630,7 @@ namespace IRaCIS.Core.Application.Service /// /// 标识 /// 标识 + /// /// Json对象 /// private async Task SetEnum(Guid trialId, List identificationList, string identification, string jsonStr) diff --git a/IRaCIS.Core.Application/TestService.cs b/IRaCIS.Core.Application/TestService.cs index f6d75b024..7f2b67c54 100644 --- a/IRaCIS.Core.Application/TestService.cs +++ b/IRaCIS.Core.Application/TestService.cs @@ -118,6 +118,13 @@ namespace IRaCIS.Application.Services public IResponseOutput TestJson() { + var trial=new Trial(); + + trial.ExperimentName = null; + + _trialRepository.AddAsync(trial,true); + + return ResponseOutput.Ok(new TestModel(), IRCEmailPasswordHelper.GenerateRandomPassword(10)); } diff --git a/IRaCIS.Core.Domain/_Config/_AppSettings.cs b/IRaCIS.Core.Domain/_Config/_AppSettings.cs index 9091c6e27..2bca1cdfe 100644 --- a/IRaCIS.Core.Domain/_Config/_AppSettings.cs +++ b/IRaCIS.Core.Domain/_Config/_AppSettings.cs @@ -94,38 +94,27 @@ namespace IRaCIS.Core.Domain.Share public List ApiPathList { get; set; } } + public class IRaCISBasicConfigOption + { + public string DoctorCodePrefix { get; set; } + public string UserCodePrefix { get; set; } + public string QCChallengeCodePrefix { get; set; } + public string DicomStudyCodePrefix { get; set; } + public string TaskStudyCodePrefix { get; set; } + public string NoneDicomStudyCodePrefix { get; set; } + public int ImageShareExpireDays { get; set; } + public string SystemSiteCodePrefix { get; set; } + public string BlindTaskPrefix { get; set; } + public string DefaultPassword { get; set; } + } /// /// 项目基础配置规则 /// - public class AppSettings + public static class AppSettings { - public static string DoctorCodePrefix { get; set; } - public static string UserCodePrefix { get; set; } - - - public static string QCChallengeCodePrefix { get; set; } - - public static string DicomStudyCodePrefix { get; set; } - - public static string TaskStudyCodePrefix { get; set; } - - public static string NoneDicomStudyCodePrefix { get; set; } - - - - public static int ImageShareExpireDays { get; set; } = 7; - - - public static string SystemSiteCodePrefix { get; set; } - - public static string BlindTaskPrefix { get; set; } - - /// - /// 用户默认密码 - /// - public static readonly string DefaultPassword = "123456"; - + + public static IRaCISBasicConfigOption IRaCISBasicConfig { get; set; } static AppSettings() { @@ -137,19 +126,11 @@ namespace IRaCIS.Core.Domain.Share }) .Build(); - DoctorCodePrefix = configuration.GetSection("IRaCISBasicConfig").GetValue("DoctorCodePrefix"); - UserCodePrefix = configuration.GetSection("IRaCISBasicConfig").GetValue("UserCodePrefix"); - QCChallengeCodePrefix = configuration.GetSection("IRaCISBasicConfig").GetValue("QCChallengeCodePrefix"); - NoneDicomStudyCodePrefix = configuration.GetSection("IRaCISBasicConfig").GetValue("NoneDicomStudyCodePrefix"); - DicomStudyCodePrefix = configuration.GetSection("IRaCISBasicConfig").GetValue("DicomStudyCodePrefix"); - DefaultPassword = configuration.GetSection("IRaCISBasicConfig").GetValue("DefaultPassword"); - SystemSiteCodePrefix = configuration.GetSection("IRaCISBasicConfig").GetValue("SystemSiteCodePrefix"); - TaskStudyCodePrefix = configuration.GetSection("IRaCISBasicConfig").GetValue("TaskStudyCodePrefix"); - - ImageShareExpireDays = configuration.GetSection("IRaCISBasicConfig").GetValue("ImageShareExpireDays"); - - BlindTaskPrefix = configuration.GetSection("IRaCISBasicConfig").GetValue("BlindTaskPrefix"); + // 手动绑定配置 + var appSettings = new IRaCISBasicConfigOption(); + configuration.GetSection("IRaCISBasicConfig").Bind(appSettings); + IRaCISBasicConfig = appSettings; } @@ -159,40 +140,33 @@ namespace IRaCIS.Core.Domain.Share switch (typeStr) { case nameof(Doctor): - - return DoctorCodePrefix + codeInt.ToString("D4"); + return IRaCISBasicConfig.DoctorCodePrefix + codeInt.ToString("D4"); case nameof(User): - - return UserCodePrefix + codeInt.ToString("D4"); + return IRaCISBasicConfig.UserCodePrefix + codeInt.ToString("D4"); case nameof(QCChallenge): - - return QCChallengeCodePrefix + codeInt.ToString("D5"); + return IRaCISBasicConfig.QCChallengeCodePrefix + codeInt.ToString("D5"); case nameof(NoneDicomStudy): - - return NoneDicomStudyCodePrefix + codeInt.ToString("D5"); + return IRaCISBasicConfig.NoneDicomStudyCodePrefix + codeInt.ToString("D5"); case nameof(DicomStudy): - - return DicomStudyCodePrefix + codeInt.ToString("D5"); + return IRaCISBasicConfig.DicomStudyCodePrefix + codeInt.ToString("D5"); case nameof(TaskStudy): - - return TaskStudyCodePrefix + codeInt.ToString("D5"); + return IRaCISBasicConfig.TaskStudyCodePrefix + codeInt.ToString("D5"); case nameof(VisitTask): - return "W" + codeInt.ToString("D5"); case nameof(Site): - - return SystemSiteCodePrefix + codeInt.ToString("D4"); + return IRaCISBasicConfig.SystemSiteCodePrefix + codeInt.ToString("D4"); default: return string.Empty; } + } } diff --git a/IRaCIS.Core.Infra.EFCore/Interceptor/AuditEntityInterceptor.cs b/IRaCIS.Core.Infra.EFCore/Interceptor/AuditEntityInterceptor.cs index b1a694174..6f49c3b84 100644 --- a/IRaCIS.Core.Infra.EFCore/Interceptor/AuditEntityInterceptor.cs +++ b/IRaCIS.Core.Infra.EFCore/Interceptor/AuditEntityInterceptor.cs @@ -52,6 +52,12 @@ public class AuditEntityInterceptor(IUserInfo _userInfo, ILogger (u.State == EntityState.Modified || u.State == EntityState.Added)) .Where(x => !typeof(DataInspection).IsAssignableFrom(x.Entity.GetType())).ToList()) { + // 检查属性是否为string类型,并且值为null + foreach (var property in entry.Properties.Where(t=>t.Metadata.ClrType==typeof(string) && t.CurrentValue == null)) + { + property.CurrentValue = string.Empty; + } + switch (entry.State) { diff --git a/IRaCIS.Core.Test/IRaCIS.Core.Test.csproj b/IRaCIS.Core.Test/IRaCIS.Core.Test.csproj index a63626c74..d59ab4636 100644 --- a/IRaCIS.Core.Test/IRaCIS.Core.Test.csproj +++ b/IRaCIS.Core.Test/IRaCIS.Core.Test.csproj @@ -22,6 +22,14 @@ + + + + + + + + diff --git a/IRaCIS.Core.Test/Program.cs b/IRaCIS.Core.Test/Program.cs index 38ddd3d4e..3849be577 100644 --- a/IRaCIS.Core.Test/Program.cs +++ b/IRaCIS.Core.Test/Program.cs @@ -11,6 +11,7 @@ using System.Text; partial class Program { + static void Main() { //发布的目录和项目的目录有区别的 diff --git a/IRaCIS.Core.Test/模板使用说明 b/IRaCIS.Core.Test/模板使用说明 new file mode 100644 index 000000000..de575fa28 --- /dev/null +++ b/IRaCIS.Core.Test/模板使用说明 @@ -0,0 +1,34 @@ +优化背景: + 1、之前我们的从数据库自动生成实体对照模型,依赖于T4模板,同时T4模板里面的获取数据库表、列名的方法都是自己写的,其实没必要,官方有反向生成工具,也是用的T4模板,现在可以自定义了 + 2、如果我们想用pgsql orcal mysql,按照之前的方法就要针对这些数据库进行适配,太麻烦 + 3、本身不同数据库官方提供了不同反向工程的库,利用命令行就可以根据数据库的定义生成实体 + Microsoft.EntityFrameworkCore.SqlServer mssql + Npgsql.EntityFrameworkCore.PostgreSQL pgsql + Pomelo.EntityFrameworkCore.MySql mysql + Oracle.EntityFrameworkCore Oracle + 4、微软官方针对这些不同的库,生成实体的T4模板是一样的,而且也提供了自定义模板的功能,我们可以在官方模板的基础上进行自定义,以适配属于我们项目的实体生成 + 1)继承我们自己的审计基类 + 2)生成的时候过滤Id 以及我们自己的审计字段 + +程序包管理控制台命令行工具使用: + +参数说明: +-o 模型输出目录 +-c 指定数据库上下文名字 +-d 使用数据注解 不指定,默认是fluentAPI +-t 指定要生成的表名 +-p 指定项目名字 + +备注: 因为是从数据库反向生成实体,所以会默认生成dbcontext ,每次生成想要的实体后,删除指定的名称context即可 + 针对字符串类型,我们避免string字段 数据库存储null string? 数据库才存储null(除非有合理的理由),这样可以避免代码里面用string 变量,总是要判断是否为null + 同时在保存数据库实体的时候,在赋值审计字段的时候,针对string 类型的变量,如果当前值是null,设置为""字符串,也可以避免实体定义的每个string 变量赋值默认值,有时候会忘记 + +Scaffold-DbContext "连接字符串" 数据库提供程序包 -Project 项目名称 -OutputDir 输出目录 -Context "生成的上下文名称" -DataAnnotations -Tables 表1, 表2 + +方式1: +Scaffold-DbContext "Server=106.14.89.110,1435;Database=Test_IRC;User ID=sa;Password=xc@123456;TrustServerCertificate=true" Microsoft.EntityFrameworkCore.SqlServer -Project IRaCIS.Core.Test -OutputDir ModelFolder -Context "testContext" -DataAnnotations -Tables Subject, SubjectVisit + +方式2: 多个表 -t Subject -t SubjectVisit +dotnet ef dbcontext scaffold "Server=106.14.89.110,1435;Database=Test_IRC;User ID=sa;Password=xc@123456;TrustServerCertificate=true" Microsoft.EntityFrameworkCore.SqlServer -p IRaCIS.Core.Test -d -o ModelFolder -c "IRaCISDBContext" -t Subject + +