后端国际化支持,日志记录的信息和返回前端的国际化不一致
This commit is contained in:
@@ -16,6 +16,9 @@
|
||||
/// 消息
|
||||
/// </summary>
|
||||
string ErrorMessage { get; }
|
||||
|
||||
|
||||
public string LocalizedInfo { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -30,13 +33,4 @@
|
||||
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
|
||||
{
|
||||
@@ -7,10 +10,10 @@ namespace IRaCIS.Core.Infrastructure.Extention
|
||||
/// </summary>
|
||||
public class ResponseOutput<T> : IResponseOutput<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否成功标记
|
||||
/// </summary>
|
||||
public bool IsSuccess { get; private set; }
|
||||
/// <summary>
|
||||
/// 是否成功标记
|
||||
/// </summary>
|
||||
public bool IsSuccess { get; private set; }
|
||||
|
||||
|
||||
public ApiResponseCodeEnum Code { get; set; } = ApiResponseCodeEnum.OK;
|
||||
@@ -25,34 +28,20 @@ namespace IRaCIS.Core.Infrastructure.Extention
|
||||
/// 数据 兼顾以前 Json序列化的时候返回属性名为“Result”
|
||||
/// </summary>
|
||||
[JsonProperty("Result")]
|
||||
public T Data { get; set; }
|
||||
public T Data { get; set; }
|
||||
|
||||
|
||||
[JsonProperty("OtherInfo")]
|
||||
public object OtherData { get; set; }
|
||||
|
||||
public string LocalizedInfo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 成功
|
||||
/// </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)
|
||||
public ResponseOutput<T> Ok(T data, object otherData, string msg = "", ApiResponseCodeEnum code = ApiResponseCodeEnum.OK)
|
||||
{
|
||||
IsSuccess = true;
|
||||
Code = code;
|
||||
Data = data;
|
||||
OtherData=otherData;
|
||||
OtherData = otherData;
|
||||
ErrorMessage = msg;
|
||||
|
||||
return this;
|
||||
@@ -64,12 +53,13 @@ namespace IRaCIS.Core.Infrastructure.Extention
|
||||
/// <param name="msg">提示消息</param>
|
||||
/// <param name="data">数据</param>
|
||||
/// <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;
|
||||
Code = code;
|
||||
Code = code;
|
||||
ErrorMessage = msg;
|
||||
Data = data;
|
||||
LocalizedInfo = localizedInfo;
|
||||
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>
|
||||
/// 响应数据静态输出 为了代码简洁 不用每处都New
|
||||
/// </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)
|
||||
{
|
||||
return new ResponseOutput<T>().Ok(data, otherData, msg, code);
|
||||
@@ -147,15 +93,11 @@ namespace IRaCIS.Core.Infrastructure.Extention
|
||||
/// <param name="msg">消息</param>
|
||||
/// <param name="data">数据</param>
|
||||
/// <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>
|
||||
/// 失败
|
||||
@@ -164,7 +106,13 @@ namespace IRaCIS.Core.Infrastructure.Extention
|
||||
/// <returns></returns>
|
||||
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)
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 根据布尔值返回结果 --适合删除
|
||||
/// </summary>
|
||||
@@ -190,7 +138,7 @@ namespace IRaCIS.Core.Infrastructure.Extention
|
||||
/// <returns></returns>
|
||||
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>
|
||||
|
||||
Reference in New Issue
Block a user