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-05 14:34:14 +08:00
commit bceffcad6a
8 changed files with 85 additions and 82 deletions

View File

@ -483,7 +483,7 @@ namespace IRaCIS.Core.API.Controllers
if(incommand.VisitTaskId!=null && incommand.VisitTaskId !=Guid.Empty)
{
await _noneDicomStudyFileRepository.AddAsync(new NoneDicomStudyFile() { FileName = item.FileName, Path = item.FilePath, OriginNoneDicomStudyId=noneDicomStudyId.Value, FileType = item.FileType, FileSize = item.FileFize });
await _noneDicomStudyFileRepository.AddAsync(new NoneDicomStudyFile() { FileName = item.FileName, Path = item.FilePath, OriginNoneDicomStudyId=noneDicomStudyId.Value, VisitTaskId=incommand.VisitTaskId, FileType = item.FileType, FileSize = item.FileFize });
}
else

View File

@ -760,14 +760,6 @@ namespace IRaCIS.Application.Services
return ResponseOutput.NotOk(_localizer["User_Disabled"], new LoginReturnDTO());
}
//超过90天没修改密码
if (_verifyConfig.CurrentValue.IsNeedChangePassWord && loginUser.LastChangePassWordTime != null && DateTime.Now.AddDays(-_verifyConfig.CurrentValue.ChangePassWordDays) > loginUser.LastChangePassWordTime.Value)
{
loginUser.LoginState = 1;
}
//登录成功 清除缓存
await _fusionCache.SetAsync(cacheKey, 0, TimeSpan.FromMinutes(lockoutMinutes));
var ipinfo = _searcher.Search(_userInfo.IP);
@ -781,8 +773,12 @@ namespace IRaCIS.Application.Services
{
loginUser.LoginState = 2;
}
}
//超过90天没修改密码
if (_verifyConfig.CurrentValue.IsNeedChangePassWord && loginUser.LastChangePassWordTime != null && DateTime.Now.AddDays(-_verifyConfig.CurrentValue.ChangePassWordDays) > loginUser.LastChangePassWordTime.Value)
{
loginUser.LoginState = 1;
}
await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, LoginUserId = loginUser.Id, OptUserId = loginUser.Id, OptType = UserOptType.Login }, true);

View File

@ -57,13 +57,9 @@ namespace IRaCIS.Core.Infra.EFCore
public class IRaCISDBContext : DbContext
{
private readonly ILogger<IRaCISDBContext> _logger;
public IRaCISDBContext(DbContextOptions<IRaCISDBContext> options, ILogger<IRaCISDBContext> logger
) : base(options)
public IRaCISDBContext(DbContextOptions<IRaCISDBContext> options) : base(options)
{
_logger = logger;
}
@ -163,68 +159,6 @@ namespace IRaCIS.Core.Infra.EFCore
#endregion
public override async Task<int> SaveChangesAsync(CancellationToken cancellationToken = new CancellationToken())
{
try
{
return await base.SaveChangesAsync(cancellationToken);
}
catch (UniqueConstraintException ex)
{
_logger.LogError(ex.InnerException is null ? ex.Message : ex.InnerException?.Message);
throw new DBSaveFailedException("该唯一键已经存在于数据库中。");
}
catch (TimeoutException ex)
{
_logger.LogError(ex.InnerException is null ? ex.Message : ex.InnerException?.Message);
throw new DBSaveFailedException("数据库操作已经超时,请稍后重试。");
}
catch (CannotInsertNullException ex)
{
_logger.LogError(ex.InnerException is null ? ex.Message : ex.InnerException?.Message);
throw new DBSaveFailedException("无法在非空列上插入空值。");
}
catch (MaxLengthExceededException ex)
{
_logger.LogError(ex.InnerException is null ? ex.Message : ex.InnerException?.Message);
throw new DBSaveFailedException("字符串超过了数据库列的最大长度。");
}
catch (NumericOverflowException ex)
{
_logger.LogError(ex.InnerException is null ? ex.Message : ex.InnerException?.Message);
throw new DBSaveFailedException("数值超过了数据类型的范围。");
}
catch (SyntaxErrorException ex)
{
_logger.LogError(ex.InnerException is null ? ex.Message : ex.InnerException?.Message);
throw new DBSaveFailedException("SQL 查询中存在语法错误。");
}
catch (ReferenceConstraintException ex)
{
_logger.LogError(ex.InnerException is null ? ex.Message : ex.InnerException?.Message);
throw new DBSaveFailedException("无法进行当前操作,当前数据不符合外键约束。");
}
catch (DbUpdateConcurrencyException ex)
{
_logger.LogError(ex.InnerException is null ? ex.Message : ex.InnerException?.Message);
throw new DBSaveFailedException("SQL 事务失败,请检查环境。");
}
}
#region Doctor
public virtual DbSet<Dictionary> Dictionary { get; set; }
public virtual DbSet<Doctor> Doctor { get; set; }

View File

@ -1,11 +1,15 @@
using IRaCIS.Core.Domain.Models;
using EntityFramework.Exceptions.Common;
using IRaCIS.Core.Domain.Models;
using IRaCIS.Core.Domain.Share;
using IRaCIS.Core.Infra.EFCore.Common;
using IRaCIS.Core.Infra.EFCore.Interceptor;
using Microsoft.AspNetCore.Mvc.Diagnostics;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.Extensions.Logging;
using System;
using System.Data;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
@ -13,7 +17,7 @@ using System.Threading.Tasks;
namespace IRaCIS.Core.Infra.EFCore;
public class AuditEntityInterceptor(IUserInfo _userInfo) : SaveChangesInterceptor
public class AuditEntityInterceptor(IUserInfo _userInfo, ILogger<AuditEntityInterceptor> _logger) : SaveChangesInterceptor
{
/// <summary>
@ -129,4 +133,63 @@ public class AuditEntityInterceptor(IUserInfo _userInfo) : SaveChangesIntercepto
}
}
private void LoggerDBContextException(DbContextErrorEventData eventData)
{
var ex = eventData.Exception;
if (ex is UniqueConstraintException)
{
_logger.LogError("该唯一键已经存在于数据库中:" + ex.InnerException?.Message ?? ex.Message);
}
else if (ex is TimeoutException)
{
_logger.LogError("数据库操作已经超时,请稍后重试:" + ex.InnerException?.Message ?? ex.Message);
}
else if (ex is CannotInsertNullException)
{
_logger.LogError("无法在非空列上插入空值:" + ex.InnerException is null ? ex.Message : ex.InnerException?.Message);
}
else if (ex is MaxLengthExceededException)
{
_logger.LogError("字符串超过了数据库列的最大长度:" + ex.InnerException is null ? ex.Message : ex.InnerException?.Message);
}
else if (ex is NumericOverflowException)
{
_logger.LogError("数值超过了数据类型的范围:" + ex.InnerException is null ? ex.Message : ex.InnerException?.Message);
}
else if (ex is SyntaxErrorException)
{
_logger.LogError("SQL 查询中存在语法错误:" + ex.InnerException is null ? ex.Message : ex.InnerException?.Message);
}
else if (ex is ReferenceConstraintException)
{
_logger.LogError("无法进行当前操作,当前数据不符合外键约束:" + ex.InnerException is null ? ex.Message : ex.InnerException?.Message);
}
else if (ex is DbUpdateConcurrencyException)
{
_logger.LogError("并发更新异常:" + ex.InnerException is null ? ex.Message : ex.InnerException?.Message);
}
else
{
_logger.LogError("SQL 事务失败,请检查环境:" + ex.InnerException is null ? ex.Message : ex.InnerException?.Message);
}
}
//在保存失败后处理异常并记录日志
public override Task SaveChangesFailedAsync(DbContextErrorEventData eventData, CancellationToken cancellationToken = default)
{
LoggerDBContextException(eventData);
return base.SaveChangesFailedAsync(eventData, cancellationToken);
}
public override void SaveChangesFailed(DbContextErrorEventData eventData)
{
LoggerDBContextException(eventData);
base.SaveChangesFailed(eventData);
}
}

View File

@ -8,6 +8,10 @@ using System.Threading;
using System.Threading.Tasks;
using IRaCIS.Core.Domain.Models;
using MassTransit;
using EntityFramework.Exceptions.Common;
using IRaCIS.Core.Infrastructure;
using System.Data;
using Microsoft.Extensions.Logging;
namespace IRaCIS.Core.Infra.EFCore.Interceptor
{
@ -57,5 +61,6 @@ namespace IRaCIS.Core.Infra.EFCore.Interceptor
await publishEndpoint.Publish(domainEvent);
}
}
}
}

View File

@ -87,4 +87,8 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.8" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\IRaCIS.Core.Infra.EFCore\IRaCIS.Core.Infra.EFCore.csproj" />
</ItemGroup>
</Project>

View File

@ -1,5 +1,6 @@

using Fluid;
using IRaCIS.Core.Infra.EFCore;
using IRaCIS.Core.Test.Template;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
@ -68,7 +69,7 @@ partial class Program
// 要生成的表名数组
var tableNames = new List<string> { "User", "Product", "Order" };
var tableNames = new List<string> { "Product"/*, "Order"*/ };
try
{
@ -79,7 +80,7 @@ partial class Program
var fileName=Path.GetFileNameWithoutExtension(templateFilePath);
//模板放入具体的文件夹
var folder = fileName == "Entity" ? "Entity" : fileName.Replace("Entity", "");
//var folder = fileName == "Entity" ? "Entity" : fileName.Replace("Entity", "");
foreach (var tableName in tableNames)
{
@ -101,7 +102,7 @@ partial class Program
//Console.WriteLine(template.Render(context));
string outputFilePath = Path.Combine(outPutTemplateFolderPath, folder, $"{fileName.Replace("Entity", tableName)}.cs");
string outputFilePath = Path.Combine(outPutTemplateFolderPath, /*folder,*/ $"{fileName.Replace("Entity", tableName)}.cs");
File.WriteAllText(outputFilePath, template.Render(context));
}