优化基础配置和模板
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
2127c47d00
commit
fff6ef5fe2
|
@ -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<ObjectStoreServiceOptions>(_configuratio
|
|||
builder.Services.AddOptions().Configure<EncreptResponseOption>(_configuration.GetSection("EncrypteResponseConfig"));
|
||||
builder.Services.AddOptions().Configure<SystemPacsConfig>(_configuration.GetSection("SystemPacsConfig"));
|
||||
|
||||
builder.Services.Configure<IRaCISBasicConfigOption>(_configuration.GetSection("IRaCISBasicConfig"));
|
||||
|
||||
|
||||
//动态WebApi + UnifiedApiResultFilter 省掉控制器代码
|
||||
builder.Services.AddDynamicWebApiSetup();
|
||||
|
|
|
@ -1404,6 +1404,7 @@
|
|||
格式化日期和时间
|
||||
</summary>
|
||||
<param name="identificationList"></param>
|
||||
<param name="identification"></param>
|
||||
<param name="jsonStr"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
|
@ -1421,6 +1422,7 @@
|
|||
</summary>
|
||||
<param name="trialId">标识</param>
|
||||
<param name="identificationList">标识</param>
|
||||
<param name="identification"></param>
|
||||
<param name="jsonStr">Json对象</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
|
|
|
@ -61,7 +61,7 @@ namespace IRaCIS.Core.Application.Services
|
|||
|
||||
//配置文件读取过期时间
|
||||
|
||||
var days = AppSettings.ImageShareExpireDays;
|
||||
var days = AppSettings.IRaCISBasicConfig.ImageShareExpireDays;
|
||||
|
||||
|
||||
imageShareCommand.ExpireTime = DateTime.Now.AddDays(days);
|
||||
|
|
|
@ -439,6 +439,7 @@ namespace IRaCIS.Core.Application.Service
|
|||
/// 格式化日期和时间
|
||||
/// </summary>
|
||||
/// <param name="identificationList"></param>
|
||||
/// <param name="identification"></param>
|
||||
/// <param name="jsonStr"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<string> SetDataInspectionDateType(List<string> identificationList, string identification, string jsonStr)
|
||||
|
@ -629,6 +630,7 @@ namespace IRaCIS.Core.Application.Service
|
|||
/// </summary>
|
||||
/// <param name="trialId">标识</param>
|
||||
/// <param name="identificationList">标识</param>
|
||||
/// <param name="identification"></param>
|
||||
/// <param name="jsonStr">Json对象</param>
|
||||
/// <returns></returns>
|
||||
private async Task<string> SetEnum(Guid trialId, List<string> identificationList, string identification, string jsonStr)
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
@ -94,38 +94,27 @@ namespace IRaCIS.Core.Domain.Share
|
|||
public List<string> 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; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 项目基础配置规则
|
||||
/// </summary>
|
||||
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; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户默认密码
|
||||
/// </summary>
|
||||
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<string>("DoctorCodePrefix");
|
||||
UserCodePrefix = configuration.GetSection("IRaCISBasicConfig").GetValue<string>("UserCodePrefix");
|
||||
QCChallengeCodePrefix = configuration.GetSection("IRaCISBasicConfig").GetValue<string>("QCChallengeCodePrefix");
|
||||
NoneDicomStudyCodePrefix = configuration.GetSection("IRaCISBasicConfig").GetValue<string>("NoneDicomStudyCodePrefix");
|
||||
DicomStudyCodePrefix = configuration.GetSection("IRaCISBasicConfig").GetValue<string>("DicomStudyCodePrefix");
|
||||
DefaultPassword = configuration.GetSection("IRaCISBasicConfig").GetValue<string>("DefaultPassword");
|
||||
SystemSiteCodePrefix = configuration.GetSection("IRaCISBasicConfig").GetValue<string>("SystemSiteCodePrefix");
|
||||
TaskStudyCodePrefix = configuration.GetSection("IRaCISBasicConfig").GetValue<string>("TaskStudyCodePrefix");
|
||||
|
||||
ImageShareExpireDays = configuration.GetSection("IRaCISBasicConfig").GetValue<int>("ImageShareExpireDays");
|
||||
|
||||
BlindTaskPrefix = configuration.GetSection("IRaCISBasicConfig").GetValue<string>("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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -52,6 +52,12 @@ public class AuditEntityInterceptor(IUserInfo _userInfo, ILogger<AuditEntityInte
|
|||
foreach (var entry in context.ChangeTracker.Entries().Where(u => (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)
|
||||
{
|
||||
|
||||
|
|
|
@ -22,6 +22,14 @@
|
|||
<None Remove="OK\**" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="模板使用说明" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="模板使用说明" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -11,6 +11,7 @@ using System.Text;
|
|||
|
||||
partial class Program
|
||||
{
|
||||
|
||||
static void Main()
|
||||
{
|
||||
//发布的目录和项目的目录有区别的
|
||||
|
|
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue