处理字符串超长限制

Test.EIImageViewer
hang 2023-06-14 09:33:30 +08:00
parent 4d23680e5b
commit ed8791c9d7
7 changed files with 86 additions and 17 deletions

View File

@ -108,17 +108,17 @@ namespace IRaCIS.Core.API
options.SwaggerEndpoint($"swagger/Management/swagger.json", "管理模块");
options.SwaggerEndpoint($"swagger/Image/swagger.json", "影像模块");
options.SwaggerEndpoint($"swagger/Reading/swagger.json", "读片模块");
//路径配置设置为空表示直接在根域名localhost:8001访问该文件,
//注意localhost:8001/swagger是访问不到的去launchSettings.json把launchUrl去掉如果你想换一个路径直接写名字即可比如直接写c.Route = "doc";
//options.RoutePrefix = string.Empty;
//options.IndexStream = () => Assembly.GetExecutingAssembly()
//.GetManifestResourceStream("IRaCIS.Core.API.wwwroot.swagger.ui.Index.html");
options.IndexStream = () => Assembly.GetExecutingAssembly()
.GetManifestResourceStream("IRaCIS.Core.API.wwwroot.swagger.ui.Index.html");
options.RoutePrefix = string.Empty;

View File

@ -25,7 +25,7 @@ namespace IRaCIS.Core.Application.Filter
context.Result = new JsonResult(ResponseOutput.NotOk("并发更新,当前不允许该操作" + context.Exception.Message));
}
if (context.Exception.GetType() == typeof(BusinessValidationFailedException))
if (context.Exception.GetType() == typeof(BusinessValidationFailedException) || context.Exception.GetType() == typeof(DBSaveFailedException))
{
context.Result = new JsonResult(ResponseOutput.NotOk(context.Exception.Message,ApiResponseCodeEnum.BusinessValidationFailed));
}

View File

@ -1,6 +1,5 @@
using IRaCIS.Core.Domain.Models;
using IRaCIS.Core.Domain.Share;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
@ -8,7 +7,6 @@ using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
namespace IRaCIS.Core.Infra.EFCore.Common
{

View File

@ -17,28 +17,31 @@ using Microsoft.EntityFrameworkCore.ValueGeneration;
using UserTypeGroup = IRaCIS.Core.Domain.Models.UserTypeGroup;
using IRaCIS.Core.Infra.EFCore.Common;
using IRaCIS.Core.Infra.EFCore.Common.Dto;
using EntityFramework.Exceptions.Common;
using IRaCIS.Core.Infrastructure;
using System.Data;
namespace IRaCIS.Core.Infra.EFCore
{
public class IRaCISDBContext : DbContext
{
public readonly IUserInfo _userInfo;
//private readonly IAuditingData _auditingData;
public readonly ILogger<IRaCISDBContext> _logger;
// 在控制台
//public static readonly ILoggerFactory MyLoggerFactory = LoggerFactory.Create(builder => { builder.AddConsole(); });
// 调试窗口
public static readonly ILoggerFactory MyLoggerFactory = LoggerFactory.Create(builder => { builder.AddDebug(); });
public IRaCISDBContext(DbContextOptions<IRaCISDBContext> options, IUserInfo userInfo
public IRaCISDBContext(DbContextOptions<IRaCISDBContext> options, IUserInfo userInfo, ILogger<IRaCISDBContext> _Logger
//IAuditingData auditingData
) : base(options)
{
_userInfo = userInfo;
//this._auditingData = auditingData;
//_configuration = configuration;
_logger = _Logger;
}
@ -476,13 +479,64 @@ namespace IRaCIS.Core.Infra.EFCore
AddAudit().GetAwaiter();
return base.SaveChanges();
}
#endregion
public override async Task<int> SaveChangesAsync(CancellationToken cancellationToken = new CancellationToken())
{
// 采用触发器的方式 设置 CreateUserId CreateTime UpdateTime UpdateUserId 稽查实体里面没有这四个字段的值 因为先后顺序的原因
SetCommonEntityAuditInfo();
await AddAudit();
return await base.SaveChangesAsync(cancellationToken);
var result = 0;
try
{
result = await base.SaveChangesAsync(cancellationToken);
}
catch (UniqueConstraintException ex)
{
_logger.LogError(ex.Message);
throw new DBSaveFailedException("该唯一键已经存在于数据库中。");
}
catch (TimeoutException ex)
{
_logger.LogError(ex.Message);
throw new DBSaveFailedException("数据库操作已经超时,请稍后重试。");
}
catch (CannotInsertNullException ex)
{
_logger.LogError(ex.Message);
throw new DBSaveFailedException("无法在非空列上插入空值。");
}
catch (MaxLengthExceededException ex)
{
_logger.LogError(ex.Message);
throw new DBSaveFailedException("字符串超过了数据库列的最大长度。");
}
catch (NumericOverflowException ex)
{
_logger.LogError(ex.Message);
throw new DBSaveFailedException("数值超过了数据类型的范围。");
}
catch (SyntaxErrorException ex)
{
_logger.LogError(ex.Message);
throw new DBSaveFailedException("SQL 查询中存在语法错误。");
}
return result;
}
@ -651,7 +705,7 @@ namespace IRaCIS.Core.Infra.EFCore
#endregion
#endregion
public virtual DbSet<TaskAllocationRule> TaskAllocationRule { get; set; }

View File

@ -28,7 +28,7 @@
<ItemGroup>
<PackageReference Include="EFCore.BulkExtensions" Version="6.5.6" />
<PackageReference Include="EntityFrameworkCore.Exceptions.SqlServer" Version="6.0.3.1" />
<PackageReference Include="EntityFrameworkCore.Triggered" Version="3.2.1" />
<PackageReference Include="EntityFrameworkCore.Triggered" Version="3.2.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="7.0.2" />

View File

@ -0,0 +1,17 @@
using System;
namespace IRaCIS.Core.Infrastructure
{
public class DBSaveFailedException : Exception
{
public DBSaveFailedException()
{
}
public DBSaveFailedException( string message) : base(message)
{
}
}
}