后端国际化支持,日志记录的信息和返回前端的国际化不一致
parent
ffa6d62d3d
commit
ab34c947ca
|
@ -8,6 +8,7 @@ using Panda.DynamicWebApi;
|
||||||
using Panda.DynamicWebApi.Attributes;
|
using Panda.DynamicWebApi.Attributes;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using IRaCIS.Core.Domain.Share;
|
using IRaCIS.Core.Domain.Share;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
namespace IRaCIS.Core.Application
|
namespace IRaCIS.Core.Application
|
||||||
{
|
{
|
||||||
|
@ -17,7 +18,8 @@ namespace IRaCIS.Core.Application
|
||||||
|
|
||||||
#region 非泛型版本
|
#region 非泛型版本
|
||||||
|
|
||||||
[Authorize, DynamicWebApi, UnifiedApiResultFilter]
|
[TypeFilter(typeof(UnifiedApiResultFilter))]
|
||||||
|
[Authorize, DynamicWebApi]
|
||||||
public class BaseService : IBaseService, IDynamicWebApi
|
public class BaseService : IBaseService, IDynamicWebApi
|
||||||
{
|
{
|
||||||
public IMapper _mapper { get; set; }
|
public IMapper _mapper { get; set; }
|
||||||
|
@ -83,8 +85,8 @@ namespace IRaCIS.Core.Application
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TypeFilter(typeof(UnifiedApiResultFilter))]
|
||||||
[Authorize, DynamicWebApi, UnifiedApiResultFilter]
|
[Authorize, DynamicWebApi]
|
||||||
public class BaseServiceTest<T> : IBaseServiceTest<T>, IDynamicWebApi where T : Entity
|
public class BaseServiceTest<T> : IBaseServiceTest<T>, IDynamicWebApi where T : Entity
|
||||||
{
|
{
|
||||||
public IMapper _mapper { get; set; }
|
public IMapper _mapper { get; set; }
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using IRaCIS.Core.Infrastructure;
|
using IRaCIS.Core.Domain.Share;
|
||||||
|
using IRaCIS.Core.Infrastructure;
|
||||||
using IRaCIS.Core.Infrastructure.Extention;
|
using IRaCIS.Core.Infrastructure.Extention;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Mvc.Filters;
|
using Microsoft.AspNetCore.Mvc.Filters;
|
||||||
|
@ -34,7 +35,10 @@ namespace IRaCIS.Core.Application.Filter
|
||||||
{
|
{
|
||||||
var error = context.Exception as BusinessValidationFailedException;
|
var error = context.Exception as BusinessValidationFailedException;
|
||||||
|
|
||||||
context.Result = new JsonResult(ResponseOutput.NotOk(context.Exception.Message, error!.Code));
|
context.Result = new JsonResult(ResponseOutput.NotOk(context.Exception.Message, error!.Code,localizedInfo: $"[{error!.LocalizedKey}]:{StaticData.Log_Locoalize_Dic[error!.LocalizedKey]}"));
|
||||||
|
|
||||||
|
//warning 级别记录
|
||||||
|
//_logger.LogWarning($"[{error!.LocalizedKey}]:{StaticData.Log_Locoalize_Dic[error!.LocalizedKey]}");
|
||||||
}
|
}
|
||||||
else if(context.Exception.GetType() == typeof(QueryBusinessObjectNotExistException))
|
else if(context.Exception.GetType() == typeof(QueryBusinessObjectNotExistException))
|
||||||
{
|
{
|
||||||
|
@ -44,12 +48,10 @@ namespace IRaCIS.Core.Application.Filter
|
||||||
{
|
{
|
||||||
context.Result = new JsonResult(ResponseOutput.NotOk(_localizer["Project_ExceptionContactDeveloper"] + (context.Exception.InnerException is null ? (context.Exception.Message /*+ context.Exception.StackTrace*/)
|
context.Result = new JsonResult(ResponseOutput.NotOk(_localizer["Project_ExceptionContactDeveloper"] + (context.Exception.InnerException is null ? (context.Exception.Message /*+ context.Exception.StackTrace*/)
|
||||||
: (context.Exception.InnerException?.Message /*+ context.Exception.InnerException?.StackTrace*/)), ApiResponseCodeEnum.ProgramException));
|
: (context.Exception.InnerException?.Message /*+ context.Exception.InnerException?.StackTrace*/)), ApiResponseCodeEnum.ProgramException));
|
||||||
|
|
||||||
|
_logger.LogError(context.Exception.InnerException is null ? (context.Exception.Message + context.Exception.StackTrace) : (context.Exception.InnerException?.Message + context.Exception.InnerException?.StackTrace));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
_logger.LogError(context.Exception.InnerException is null ? (context.Exception.Message + context.Exception.StackTrace) : (context.Exception.InnerException?.Message + context.Exception.InnerException?.StackTrace));
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
using Microsoft.AspNetCore.Mvc.Filters;
|
using Microsoft.AspNetCore.Mvc.Filters;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using IRaCIS.Core.Domain.Share;
|
using IRaCIS.Core.Domain.Share;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace IRaCIS.Application.Services.BusinessFilter
|
namespace IRaCIS.Application.Services.BusinessFilter
|
||||||
{
|
{
|
||||||
|
@ -10,6 +11,12 @@ namespace IRaCIS.Application.Services.BusinessFilter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class UnifiedApiResultFilter : Attribute, IAsyncResultFilter
|
public class UnifiedApiResultFilter : Attribute, IAsyncResultFilter
|
||||||
{
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
|
public UnifiedApiResultFilter(ILogger<UnifiedApiResultFilter> logger)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 异步版本
|
/// 异步版本
|
||||||
|
@ -31,12 +38,11 @@ namespace IRaCIS.Application.Services.BusinessFilter
|
||||||
var type = objectResult.Value?.GetType();
|
var type = objectResult.Value?.GetType();
|
||||||
|
|
||||||
|
|
||||||
if ( type!=null&& type.IsGenericType&&(type.GetGenericTypeDefinition()==typeof(ValueTuple<,>)|| type.GetGenericTypeDefinition()==typeof(Tuple<,>)))
|
if (type != null && type.IsGenericType && (type.GetGenericTypeDefinition() == typeof(ValueTuple<,>) || type.GetGenericTypeDefinition() == typeof(Tuple<,>)))
|
||||||
{
|
{
|
||||||
|
|
||||||
//报错
|
//报错
|
||||||
//var tuple = (object, object))objectResult.Value;
|
//var tuple = (object, object))objectResult.Value;
|
||||||
|
|
||||||
//var (val1, val2) = ((dynamic, dynamic))objectResult.Value;
|
//var (val1, val2) = ((dynamic, dynamic))objectResult.Value;
|
||||||
//var apiResponse = ResponseOutput.Ok(val1, val2);
|
//var apiResponse = ResponseOutput.Ok(val1, val2);
|
||||||
|
|
||||||
|
@ -56,16 +62,19 @@ namespace IRaCIS.Application.Services.BusinessFilter
|
||||||
objectResult.DeclaredType = apiResponse.GetType();
|
objectResult.DeclaredType = apiResponse.GetType();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
//如果不是200 是IResponseOutput 不处理
|
//如果是200 是IResponseOutput 记录下日志
|
||||||
else if (statusCode != 200 && (objectResult.Value is IResponseOutput))
|
else if (statusCode == 200 && (objectResult.Value is IResponseOutput))
|
||||||
{
|
{
|
||||||
|
var result = objectResult.Value as IResponseOutput;
|
||||||
|
|
||||||
|
_logger.LogWarning($"{result.LocalizedInfo}");
|
||||||
}
|
}
|
||||||
|
|
||||||
else if(statusCode != 200&&!(objectResult.Value is IResponseOutput))
|
else if (statusCode != 200 && !(objectResult.Value is IResponseOutput))
|
||||||
{
|
{
|
||||||
//---程序错误,请联系开发人员。
|
//---程序错误,请联系开发人员。
|
||||||
var apiResponse = ResponseOutput.NotOk(StaticData.International("UnifiedAPI_ProgramError"));
|
var apiResponse = ResponseOutput.NotOk(StaticData.International("UnifiedAPI_ProgramError"));
|
||||||
|
|
||||||
objectResult.Value = apiResponse;
|
objectResult.Value = apiResponse;
|
||||||
|
|
|
@ -53,6 +53,9 @@ namespace IRaCIS.Core.Application.Helper
|
||||||
jsonObject[item.Code] = item.Value;
|
jsonObject[item.Code] = item.Value;
|
||||||
|
|
||||||
StaticData.En_US_Dic[item.Code] = item.Value;
|
StaticData.En_US_Dic[item.Code] = item.Value;
|
||||||
|
|
||||||
|
//日志记录该信息方便自己人看, 返回给客户的是配置的
|
||||||
|
StaticData.Log_Locoalize_Dic[item.Code] = item.Description;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -71,7 +74,7 @@ namespace IRaCIS.Core.Application.Helper
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task AddOrUpdateJsonKeyValueAsync(string key, string value, string valueCN)
|
public static async Task AddOrUpdateJsonKeyValueAsync(string key, string value, string valueCN,string description)
|
||||||
{
|
{
|
||||||
|
|
||||||
VerifyFolder();
|
VerifyFolder();
|
||||||
|
@ -94,6 +97,9 @@ namespace IRaCIS.Core.Application.Helper
|
||||||
jsonObject[key] = value;
|
jsonObject[key] = value;
|
||||||
|
|
||||||
StaticData.En_US_Dic[key] = value;
|
StaticData.En_US_Dic[key] = value;
|
||||||
|
|
||||||
|
//日志记录该信息方便自己人看, 返回给客户的是配置的
|
||||||
|
StaticData.Log_Locoalize_Dic[key] = description;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -117,7 +123,8 @@ namespace IRaCIS.Core.Application.Helper
|
||||||
{
|
{
|
||||||
t.Code,
|
t.Code,
|
||||||
t.Value,
|
t.Value,
|
||||||
t.ValueCN
|
t.ValueCN,
|
||||||
|
t.Description
|
||||||
}).ToListAsync();
|
}).ToListAsync();
|
||||||
|
|
||||||
//组织成json 文件
|
//组织成json 文件
|
||||||
|
@ -131,6 +138,9 @@ namespace IRaCIS.Core.Application.Helper
|
||||||
{
|
{
|
||||||
StaticData.En_US_Dic[tojsonItem.Code] = tojsonItem.Value;
|
StaticData.En_US_Dic[tojsonItem.Code] = tojsonItem.Value;
|
||||||
StaticData.Zh_CN_Dic[tojsonItem.Code] = tojsonItem.ValueCN;
|
StaticData.Zh_CN_Dic[tojsonItem.Code] = tojsonItem.ValueCN;
|
||||||
|
|
||||||
|
//日志记录该信息方便自己人看, 返回给客户的是配置的
|
||||||
|
StaticData.Log_Locoalize_Dic[tojsonItem.Code] = tojsonItem.Description;
|
||||||
}
|
}
|
||||||
|
|
||||||
File.WriteAllText(usJsonPath, JsonConvert.SerializeObject(StaticData.En_US_Dic));
|
File.WriteAllText(usJsonPath, JsonConvert.SerializeObject(StaticData.En_US_Dic));
|
||||||
|
|
|
@ -711,7 +711,7 @@ namespace IRaCIS.Core.Application.Service
|
||||||
|
|
||||||
IsHaveGeneratedTask = t.SubjectVisitTaskList.Any(c => c.IsSelfAnalysis == false && c.TrialReadingCriterionId == trialReadingCriterionId),
|
IsHaveGeneratedTask = t.SubjectVisitTaskList.Any(c => c.IsSelfAnalysis == false && c.TrialReadingCriterionId == trialReadingCriterionId),
|
||||||
|
|
||||||
DoctorUserList = t.SubjectDoctorList.Where(t => t.TrialReadingCriterionId == trialReadingCriterionId && t.IsConfirmed && t.ArmEnum<=Arm.DoubleReadingArm2).Select(t => new UserSimpleInfo()
|
DoctorUserList = t.SubjectDoctorList.Where(t => t.TrialReadingCriterionId == trialReadingCriterionId && t.IsConfirmed && t.ArmEnum <= Arm.DoubleReadingArm2).Select(t => new UserSimpleInfo()
|
||||||
{
|
{
|
||||||
UserId = t.Id,
|
UserId = t.Id,
|
||||||
FullName = t.DoctorUser.FullName,
|
FullName = t.DoctorUser.FullName,
|
||||||
|
|
|
@ -184,7 +184,7 @@ namespace IRaCIS.Core.Application.Service
|
||||||
|
|
||||||
if (addOrEditInternationalization.InternationalizationType == 1)
|
if (addOrEditInternationalization.InternationalizationType == 1)
|
||||||
{
|
{
|
||||||
await InternationalizationHelper.AddOrUpdateJsonKeyValueAsync(entity.Code, addOrEditInternationalization.Value, addOrEditInternationalization.ValueCN);
|
await InternationalizationHelper.AddOrUpdateJsonKeyValueAsync(entity.Code, addOrEditInternationalization.Value, addOrEditInternationalization.ValueCN,addOrEditInternationalization.Description);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using IRaCIS.Core.Application.Auth;
|
using IRaCIS.Core.Application.Auth;
|
||||||
using IRaCIS.Core.Domain.Models;
|
using IRaCIS.Core.Domain.Models;
|
||||||
|
using IRaCIS.Core.Infrastructure;
|
||||||
|
|
||||||
namespace IRaCIS.Application.Services
|
namespace IRaCIS.Application.Services
|
||||||
{
|
{
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\IRaCIS.Core.Domain.Share\IRaCIS.Core.Domain.Share.csproj" />
|
<ProjectReference Include="..\IRaCIS.Core.Domain.Share\IRaCIS.Core.Domain.Share.csproj" />
|
||||||
|
<ProjectReference Include="..\IRaCIS.Core.Infrastructure\IRaCIS.Core.Infrastructure.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="AutoMapper" Version="13.0.1" />
|
<PackageReference Include="AutoMapper" Version="13.0.1" />
|
||||||
<PackageReference Include="AutoMapper.Collection.EntityFrameworkCore" Version="10.0.0" />
|
<PackageReference Include="AutoMapper.Collection.EntityFrameworkCore" Version="10.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="8.0.0" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.6" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.6" />
|
||||||
<PackageReference Include="SharpCompress" Version="0.37.2" />
|
<PackageReference Include="SharpCompress" Version="0.37.2" />
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using IRaCIS.Core.Infrastructure.Extention;
|
using IRaCIS.Core.Infrastructure.Extention;
|
||||||
|
using Microsoft.Extensions.Localization;
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace IRaCIS.Core.Infrastructure
|
namespace IRaCIS.Core.Infrastructure
|
||||||
|
@ -8,15 +9,24 @@ namespace IRaCIS.Core.Infrastructure
|
||||||
|
|
||||||
public ApiResponseCodeEnum Code { get; set; }
|
public ApiResponseCodeEnum Code { get; set; }
|
||||||
|
|
||||||
public BusinessValidationFailedException()
|
public string LocalizedKey { get; set; }=string.Empty;
|
||||||
|
|
||||||
|
public BusinessValidationFailedException()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BusinessValidationFailedException(LocalizedString message, ApiResponseCodeEnum code = ApiResponseCodeEnum.BusinessValidationFailed) : base(message)
|
||||||
|
{
|
||||||
|
Code = code;
|
||||||
|
LocalizedKey=message.Name;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public BusinessValidationFailedException(string message, ApiResponseCodeEnum code = ApiResponseCodeEnum.BusinessValidationFailed) : base(message)
|
public BusinessValidationFailedException(string message, ApiResponseCodeEnum code = ApiResponseCodeEnum.BusinessValidationFailed) : base(message)
|
||||||
{
|
{
|
||||||
Code = code;
|
Code = code;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,9 @@
|
||||||
/// 消息
|
/// 消息
|
||||||
/// </summary>
|
/// </summary>
|
||||||
string ErrorMessage { get; }
|
string ErrorMessage { get; }
|
||||||
|
|
||||||
|
|
||||||
|
public string LocalizedInfo { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -30,13 +33,4 @@
|
||||||
T Data { get; set; }
|
T Data { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
//public interface IResponseOutput<T,T2> : IResponseOutput
|
|
||||||
//{
|
|
||||||
// /// <summary>
|
|
||||||
// /// 返回数据
|
|
||||||
// /// </summary>
|
|
||||||
// T Data { get; }
|
|
||||||
|
|
||||||
// T2 OtherInfo { get; }
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
using Newtonsoft.Json;
|
using IRaCIS.Core.Domain.Share;
|
||||||
|
using Microsoft.Extensions.Localization;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace IRaCIS.Core.Infrastructure.Extention
|
namespace IRaCIS.Core.Infrastructure.Extention
|
||||||
{
|
{
|
||||||
|
@ -7,10 +10,10 @@ namespace IRaCIS.Core.Infrastructure.Extention
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ResponseOutput<T> : IResponseOutput<T>
|
public class ResponseOutput<T> : IResponseOutput<T>
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 是否成功标记
|
/// 是否成功标记
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsSuccess { get; private set; }
|
public bool IsSuccess { get; private set; }
|
||||||
|
|
||||||
|
|
||||||
public ApiResponseCodeEnum Code { get; set; } = ApiResponseCodeEnum.OK;
|
public ApiResponseCodeEnum Code { get; set; } = ApiResponseCodeEnum.OK;
|
||||||
|
@ -25,34 +28,20 @@ namespace IRaCIS.Core.Infrastructure.Extention
|
||||||
/// 数据 兼顾以前 Json序列化的时候返回属性名为“Result”
|
/// 数据 兼顾以前 Json序列化的时候返回属性名为“Result”
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("Result")]
|
[JsonProperty("Result")]
|
||||||
public T Data { get; set; }
|
public T Data { get; set; }
|
||||||
|
|
||||||
|
|
||||||
[JsonProperty("OtherInfo")]
|
[JsonProperty("OtherInfo")]
|
||||||
public object OtherData { get; set; }
|
public object OtherData { get; set; }
|
||||||
|
|
||||||
|
public string LocalizedInfo { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
public ResponseOutput<T> Ok(T data, object otherData, string msg = "", ApiResponseCodeEnum code = ApiResponseCodeEnum.OK)
|
||||||
/// 成功
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="data">数据</param>
|
|
||||||
/// <param name="msg">消息</param>
|
|
||||||
//public ResponseOutput<T> Ok(T data, string msg = "", ApiResponseCodeEnum code = ApiResponseCodeEnum.OK)
|
|
||||||
//{
|
|
||||||
// IsSuccess = true;
|
|
||||||
// Code = code;
|
|
||||||
// Data = data;
|
|
||||||
// ErrorMessage = msg;
|
|
||||||
|
|
||||||
// return this;
|
|
||||||
//}
|
|
||||||
|
|
||||||
public ResponseOutput<T> Ok(T data, object otherData, string msg = "", ApiResponseCodeEnum code = ApiResponseCodeEnum.OK)
|
|
||||||
{
|
{
|
||||||
IsSuccess = true;
|
IsSuccess = true;
|
||||||
Code = code;
|
Code = code;
|
||||||
Data = data;
|
Data = data;
|
||||||
OtherData=otherData;
|
OtherData = otherData;
|
||||||
ErrorMessage = msg;
|
ErrorMessage = msg;
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
@ -64,12 +53,13 @@ namespace IRaCIS.Core.Infrastructure.Extention
|
||||||
/// <param name="msg">提示消息</param>
|
/// <param name="msg">提示消息</param>
|
||||||
/// <param name="data">数据</param>
|
/// <param name="data">数据</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public ResponseOutput<T> NotOk(string msg = "", T data = default, ApiResponseCodeEnum code = ApiResponseCodeEnum.OK)
|
public ResponseOutput<T> NotOk(string msg = "", T data = default, ApiResponseCodeEnum code = ApiResponseCodeEnum.OK, string localizedInfo = "")
|
||||||
{
|
{
|
||||||
IsSuccess = false;
|
IsSuccess = false;
|
||||||
Code = code;
|
Code = code;
|
||||||
ErrorMessage = msg;
|
ErrorMessage = msg;
|
||||||
Data = data;
|
Data = data;
|
||||||
|
LocalizedInfo = localizedInfo;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,33 +67,6 @@ namespace IRaCIS.Core.Infrastructure.Extention
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//public class ResponseOutput<T, T2> : IResponseOutput<T, T2>
|
|
||||||
//{
|
|
||||||
// [JsonProperty("Result")]
|
|
||||||
// public T Data { get; private set; }
|
|
||||||
|
|
||||||
// public T2 OtherInfo { get; private set; }
|
|
||||||
|
|
||||||
// public bool IsSuccess { get; private set; }
|
|
||||||
|
|
||||||
// public ApiResponseCodeEnum Code { get; set; }
|
|
||||||
|
|
||||||
|
|
||||||
// public string ErrorMessage { get; private set; }
|
|
||||||
|
|
||||||
|
|
||||||
// public ResponseOutput<T, T2> Ok(T data, T2 otherInfo, string msg = "")
|
|
||||||
// {
|
|
||||||
// IsSuccess = true;
|
|
||||||
// Data = data;
|
|
||||||
// OtherInfo = otherInfo;
|
|
||||||
// ErrorMessage = msg;
|
|
||||||
|
|
||||||
// return this;
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 响应数据静态输出 为了代码简洁 不用每处都New
|
/// 响应数据静态输出 为了代码简洁 不用每处都New
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -111,23 +74,6 @@ namespace IRaCIS.Core.Infrastructure.Extention
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
//public static IResponseOutput<T, T2> Ok<T, T2>(T data, T2 otherInfo, string msg = "")
|
|
||||||
//{
|
|
||||||
// return new ResponseOutput<T, T2>().Ok(data, otherInfo);
|
|
||||||
//}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 成功 -----适合查询
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="data">数据</param>
|
|
||||||
/// <param name="msg">消息</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
//public static IResponseOutput<T> Ok<T>(T data = default, string msg = "")
|
|
||||||
//{
|
|
||||||
// return new ResponseOutput<T>().Ok(data, msg);
|
|
||||||
//}
|
|
||||||
|
|
||||||
public static IResponseOutput<T> Ok<T>(T data = default, object otherData = default, string msg = "", ApiResponseCodeEnum code = ApiResponseCodeEnum.OK)
|
public static IResponseOutput<T> Ok<T>(T data = default, object otherData = default, string msg = "", ApiResponseCodeEnum code = ApiResponseCodeEnum.OK)
|
||||||
{
|
{
|
||||||
return new ResponseOutput<T>().Ok(data, otherData, msg, code);
|
return new ResponseOutput<T>().Ok(data, otherData, msg, code);
|
||||||
|
@ -147,15 +93,11 @@ namespace IRaCIS.Core.Infrastructure.Extention
|
||||||
/// <param name="msg">消息</param>
|
/// <param name="msg">消息</param>
|
||||||
/// <param name="data">数据</param>
|
/// <param name="data">数据</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IResponseOutput<T> NotOk<T>(string msg = "", T data = default, ApiResponseCodeEnum code = ApiResponseCodeEnum.BusinessValidationFailed)
|
public static IResponseOutput<T> NotOk<T>(string msg = "", T data = default, ApiResponseCodeEnum code = ApiResponseCodeEnum.BusinessValidationFailed, string localizedInfo = "")
|
||||||
{
|
{
|
||||||
return new ResponseOutput<T>().NotOk(msg, data, code);
|
return new ResponseOutput<T>().NotOk(msg, data, code, localizedInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
//public static IResponseOutput<T> NotOk<T>( T data = default, ApiResponseCodeEnum code = ApiResponseCodeEnum.BusinessValidationFailed)
|
|
||||||
//{
|
|
||||||
// return new ResponseOutput<T>().NotOk("", data, code);
|
|
||||||
//}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 失败
|
/// 失败
|
||||||
|
@ -164,7 +106,13 @@ namespace IRaCIS.Core.Infrastructure.Extention
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IResponseOutput<string> NotOk(string msg = "", ApiResponseCodeEnum code = ApiResponseCodeEnum.BusinessValidationFailed)
|
public static IResponseOutput<string> NotOk(string msg = "", ApiResponseCodeEnum code = ApiResponseCodeEnum.BusinessValidationFailed)
|
||||||
{
|
{
|
||||||
return new ResponseOutput<string>().NotOk(msg,code:code);
|
return new ResponseOutput<string>().NotOk(msg, code: code);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IResponseOutput<string> NotOk(LocalizedString msg, ApiResponseCodeEnum code = ApiResponseCodeEnum.BusinessValidationFailed)
|
||||||
|
{
|
||||||
|
|
||||||
|
return new ResponseOutput<string>().NotOk(msg, code: code, localizedInfo: $"[{msg.Name}]:{StaticData.Log_Locoalize_Dic[msg.Name]}" );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IResponseOutput<string> DBNotExistIfNUll(object businessObject)
|
public static IResponseOutput<string> DBNotExistIfNUll(object businessObject)
|
||||||
|
@ -172,7 +120,7 @@ namespace IRaCIS.Core.Infrastructure.Extention
|
||||||
return new ResponseOutput<string>().NotOk($"The business object{businessObject.GetType().Name} does not exist in the database, or was deleted by someone else, or an incorrect parameter query caused");
|
return new ResponseOutput<string>().NotOk($"The business object{businessObject.GetType().Name} does not exist in the database, or was deleted by someone else, or an incorrect parameter query caused");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 根据布尔值返回结果 --适合删除
|
/// 根据布尔值返回结果 --适合删除
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -190,7 +138,7 @@ namespace IRaCIS.Core.Infrastructure.Extention
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IResponseOutput<T> Result<T>(bool success, T data = default)
|
public static IResponseOutput<T> Result<T>(bool success, T data = default)
|
||||||
{
|
{
|
||||||
return success ? Ok<T>(data) : NotOk<T>("Saved failed",data);
|
return success ? Ok<T>(data) : NotOk<T>("Saved failed", data);
|
||||||
}
|
}
|
||||||
|
|
||||||
///// <summary>
|
///// <summary>
|
||||||
|
|
|
@ -12,6 +12,8 @@ public static class StaticData
|
||||||
|
|
||||||
public static Dictionary<string, string> Zh_CN_Dic = new Dictionary<string, string>();
|
public static Dictionary<string, string> Zh_CN_Dic = new Dictionary<string, string>();
|
||||||
|
|
||||||
|
public static Dictionary<string, string> Log_Locoalize_Dic = new Dictionary<string, string>();
|
||||||
|
|
||||||
|
|
||||||
public static readonly string En_US_Json = "en-US.json";
|
public static readonly string En_US_Json = "en-US.json";
|
||||||
public static readonly string Zh_CN_Json = "zh-CN.json";
|
public static readonly string Zh_CN_Json = "zh-CN.json";
|
Loading…
Reference in New Issue