处理字符串超长限制
parent
4d23680e5b
commit
ed8791c9d7
|
@ -108,17 +108,17 @@ namespace IRaCIS.Core.API
|
||||||
options.SwaggerEndpoint($"swagger/Management/swagger.json", "管理模块");
|
options.SwaggerEndpoint($"swagger/Management/swagger.json", "管理模块");
|
||||||
options.SwaggerEndpoint($"swagger/Image/swagger.json", "影像模块");
|
options.SwaggerEndpoint($"swagger/Image/swagger.json", "影像模块");
|
||||||
options.SwaggerEndpoint($"swagger/Reading/swagger.json", "读片模块");
|
options.SwaggerEndpoint($"swagger/Reading/swagger.json", "读片模块");
|
||||||
|
|
||||||
|
|
||||||
//路径配置,设置为空,表示直接在根域名(localhost:8001)访问该文件,
|
//路径配置,设置为空,表示直接在根域名(localhost:8001)访问该文件,
|
||||||
//注意localhost:8001/swagger是访问不到的,去launchSettings.json把launchUrl去掉,如果你想换一个路径,直接写名字即可,比如直接写c.Route = "doc";
|
//注意localhost:8001/swagger是访问不到的,去launchSettings.json把launchUrl去掉,如果你想换一个路径,直接写名字即可,比如直接写c.Route = "doc";
|
||||||
//options.RoutePrefix = string.Empty;
|
//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;
|
options.RoutePrefix = string.Empty;
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ namespace IRaCIS.Core.Application.Filter
|
||||||
context.Result = new JsonResult(ResponseOutput.NotOk("并发更新,当前不允许该操作" + context.Exception.Message));
|
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));
|
context.Result = new JsonResult(ResponseOutput.NotOk(context.Exception.Message,ApiResponseCodeEnum.BusinessValidationFailed));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
using IRaCIS.Core.Domain.Models;
|
using IRaCIS.Core.Domain.Models;
|
||||||
using IRaCIS.Core.Domain.Share;
|
using IRaCIS.Core.Domain.Share;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
@ -8,7 +7,6 @@ using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
|
||||||
|
|
||||||
namespace IRaCIS.Core.Infra.EFCore.Common
|
namespace IRaCIS.Core.Infra.EFCore.Common
|
||||||
{
|
{
|
||||||
|
|
|
@ -17,28 +17,31 @@ using Microsoft.EntityFrameworkCore.ValueGeneration;
|
||||||
using UserTypeGroup = IRaCIS.Core.Domain.Models.UserTypeGroup;
|
using UserTypeGroup = IRaCIS.Core.Domain.Models.UserTypeGroup;
|
||||||
using IRaCIS.Core.Infra.EFCore.Common;
|
using IRaCIS.Core.Infra.EFCore.Common;
|
||||||
using IRaCIS.Core.Infra.EFCore.Common.Dto;
|
using IRaCIS.Core.Infra.EFCore.Common.Dto;
|
||||||
|
using EntityFramework.Exceptions.Common;
|
||||||
|
using IRaCIS.Core.Infrastructure;
|
||||||
|
using System.Data;
|
||||||
|
|
||||||
namespace IRaCIS.Core.Infra.EFCore
|
namespace IRaCIS.Core.Infra.EFCore
|
||||||
{
|
{
|
||||||
public class IRaCISDBContext : DbContext
|
public class IRaCISDBContext : DbContext
|
||||||
{
|
{
|
||||||
public readonly IUserInfo _userInfo;
|
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.AddConsole(); });
|
||||||
// 调试窗口
|
// 调试窗口
|
||||||
public static readonly ILoggerFactory MyLoggerFactory = LoggerFactory.Create(builder => { builder.AddDebug(); });
|
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)
|
) : base(options)
|
||||||
{
|
{
|
||||||
_userInfo = userInfo;
|
_userInfo = userInfo;
|
||||||
//this._auditingData = auditingData;
|
|
||||||
//_configuration = configuration;
|
_logger = _Logger;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -476,13 +479,64 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||||
AddAudit().GetAwaiter();
|
AddAudit().GetAwaiter();
|
||||||
return base.SaveChanges();
|
return base.SaveChanges();
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
public override async Task<int> SaveChangesAsync(CancellationToken cancellationToken = new CancellationToken())
|
public override async Task<int> SaveChangesAsync(CancellationToken cancellationToken = new CancellationToken())
|
||||||
{
|
{
|
||||||
// 采用触发器的方式 设置 CreateUserId CreateTime UpdateTime UpdateUserId 稽查实体里面没有这四个字段的值 因为先后顺序的原因
|
// 采用触发器的方式 设置 CreateUserId CreateTime UpdateTime UpdateUserId 稽查实体里面没有这四个字段的值 因为先后顺序的原因
|
||||||
SetCommonEntityAuditInfo();
|
SetCommonEntityAuditInfo();
|
||||||
await AddAudit();
|
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
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
public virtual DbSet<TaskAllocationRule> TaskAllocationRule { get; set; }
|
public virtual DbSet<TaskAllocationRule> TaskAllocationRule { get; set; }
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="EFCore.BulkExtensions" Version="6.5.6" />
|
<PackageReference Include="EFCore.BulkExtensions" Version="6.5.6" />
|
||||||
<PackageReference Include="EntityFrameworkCore.Exceptions.SqlServer" Version="6.0.3.1" />
|
<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.Abstractions" Version="2.2.0" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
|
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="7.0.2" />
|
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="7.0.2" />
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace IRaCIS.Core.Infrastructure
|
||||||
|
{
|
||||||
|
public class DBSaveFailedException : Exception
|
||||||
|
{
|
||||||
|
|
||||||
|
public DBSaveFailedException()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public DBSaveFailedException( string message) : base(message)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue