using Rhea.Common;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace Tiger.IBusiness
|
{
|
///// <summary>
|
///// API 返回 泛型标准类
|
///// </summary>
|
///// <typeparam name="T">Data数据类型</typeparam>
|
//public class ApiAction<T> : Rhea.Common.ApiAction<T>
|
//{
|
// /// <summary>
|
// /// 返回的本地化信息
|
// /// </summary>
|
// public AuthOptions Options { get; set; } = new();
|
|
// /// <summary>
|
// /// 捕获当前 Action 的异常,返回数据和消息, 并记录日志
|
// /// </summary>
|
// /// <param name="ex">捕获到的异常</param>
|
// /// <param name="localeMsg">返回消息</param>
|
// /// <param name="data">返回数据</param>
|
// /// <returns></returns>
|
// public ApiAction<T> CatchExceptionWithLog(Exception ex, Locale localeMsg, T data)
|
// {
|
// Data = data;
|
// return CatchExceptionWithLog(ex, localeMsg);
|
// }
|
|
// /// <summary>
|
// /// 捕获当前 Action 的异常,返回消息, 并记录日志
|
// /// </summary>
|
// /// <param name="ex">捕获到的异常</param>
|
// /// <param name="localeMsg">返回消息</param>
|
// public ApiAction<T> CatchExceptionWithLog(Exception ex, Locale localeMsg)
|
// {
|
// CatchException(ex, localeMsg);
|
// Logger.Default.Fatal(ex, localeMsg.Default());
|
// return this;
|
// }
|
|
// /// <summary>
|
// /// 捕获当前 Action 的异常,返回数据和消息, 并记录日志
|
// /// </summary>
|
// /// <param name="ex">捕获到的异常</param>
|
// /// <param name="msg">返回消息,最终按 "Catch ApiAction Exception : {msg}. {ex.Message}{ex.StackTrace}" 返回</param>
|
// /// <param name="data">返回数据</param>
|
// /// <returns></returns>
|
// public ApiAction<T> CatchExceptionWithLog(Exception ex, string msg, T data)
|
// {
|
// Data = data;
|
// return CatchExceptionWithLog(ex, msg);
|
// }
|
|
// /// <summary>
|
// /// 捕获当前 Action 的异常,返回消息, 并记录日志
|
// /// </summary>
|
// /// <param name="ex">捕获到的异常</param>
|
// /// <param name="msg">返回消息,最终按 "Catch ApiAction Exception : {msg}. {ex.Message}{ex.StackTrace}" 返回</param>
|
// public ApiAction<T> CatchExceptionWithLog(Exception ex, string msg = null)
|
// {
|
// CatchException(ex, msg);
|
// Logger.Default.Fatal(ex, msg);
|
// return this;
|
// }
|
//}
|
|
///// <summary>
|
///// API 返回 标准类
|
///// </summary>
|
//public class ApiAction : Rhea.Common.ApiAction
|
//{
|
// /// <summary>
|
// /// 返回的本地化信息
|
// /// </summary>
|
// public AuthOptions Options { get; set; } = new();
|
|
// /// <summary>
|
// /// 捕获当前 Action 的异常,返回数据和消息, 并记录日志
|
// /// </summary>
|
// /// <param name="ex">捕获到的异常</param>
|
// /// <param name="localeMsg">返回消息</param>
|
// /// <param name="data">返回数据</param>
|
// /// <returns></returns>
|
// public ApiAction CatchExceptionWithLog(Exception ex, Locale localeMsg, object data)
|
// {
|
// Data = data;
|
// return CatchExceptionWithLog(ex, localeMsg);
|
// }
|
|
// /// <summary>
|
// /// 捕获当前 Action 的异常,返回消息, 并记录日志
|
// /// </summary>
|
// /// <param name="ex">捕获到的异常</param>
|
// /// <param name="localeMsg">返回消息</param>
|
// public ApiAction CatchExceptionWithLog(Exception ex, Locale localeMsg)
|
// {
|
// CatchException(ex, localeMsg);
|
// Logger.Default.Fatal(ex, localeMsg.Default());
|
// return this;
|
// }
|
|
// /// <summary>
|
// /// 捕获当前 Action 的异常,返回数据和消息, 并记录日志
|
// /// </summary>
|
// /// <param name="ex">捕获到的异常</param>
|
// /// <param name="msg">返回消息,最终按 "Catch ApiAction Exception : {msg}. {ex.Message}{ex.StackTrace}" 返回</param>
|
// /// <param name="data">返回数据</param>
|
// /// <returns></returns>
|
// public ApiAction CatchExceptionWithLog(Exception ex, string msg, object data)
|
// {
|
// Data = data;
|
// return CatchExceptionWithLog(ex, msg);
|
// }
|
|
// /// <summary>
|
// /// 捕获当前 Action 的异常,返回消息, 并记录日志
|
// /// </summary>
|
// /// <param name="ex">捕获到的异常</param>
|
// /// <param name="msg">返回消息,最终按 "Catch ApiAction Exception : {msg}. {ex.Message}{ex.StackTrace}" 返回</param>
|
// public ApiAction CatchExceptionWithLog(Exception ex, string msg = null)
|
// {
|
// CatchException(ex, msg);
|
// Logger.Default.Fatal(ex, msg);
|
// return this;
|
// }
|
//}
|
|
/// <summary>
|
/// ApiAction 扩展类
|
/// </summary>
|
public static class ApiActionExtension
|
{
|
/// <summary>
|
/// 捕获当前 Action 的异常,返回数据和消息, 并记录日志
|
/// </summary>
|
/// <param name="ex">捕获到的异常</param>
|
/// <param name="localeMsg">返回消息</param>
|
/// <param name="data">返回数据</param>
|
/// <returns></returns>
|
public static ApiAction<T> CatchExceptionWithLog<T>(this ApiAction<T> action, Exception ex, Locale localeMsg, T data)
|
{
|
action.Data = data;
|
return CatchExceptionWithLog<T>(action, ex, localeMsg);
|
}
|
|
/// <summary>
|
/// 捕获当前 Action 的异常,返回消息, 并记录日志
|
/// </summary>
|
/// <param name="ex">捕获到的异常</param>
|
/// <param name="localeMsg">返回消息</param>
|
public static ApiAction<T> CatchExceptionWithLog<T>(this ApiAction<T> action, Exception ex, Locale localeMsg)
|
{
|
action.CatchException(ex, localeMsg);
|
Logger.Default.Fatal(ex, localeMsg.Default());
|
return action;
|
}
|
|
/// <summary>
|
/// 捕获当前 Action 的异常,返回数据和消息, 并记录日志
|
/// </summary>
|
/// <param name="ex">捕获到的异常</param>
|
/// <param name="msg">返回消息,最终按 "Catch ApiAction Exception : {msg}. {ex.Message}{ex.StackTrace}" 返回</param>
|
/// <param name="data">返回数据</param>
|
/// <returns></returns>
|
public static ApiAction<T> CatchExceptionWithLog<T>(this ApiAction<T> action, Exception ex, string msg, T data)
|
{
|
action.Data = data;
|
return CatchExceptionWithLog<T>(action, ex, msg);
|
}
|
|
/// <summary>
|
/// 捕获当前 Action 的异常,返回消息, 并记录日志
|
/// </summary>
|
/// <param name="ex">捕获到的异常</param>
|
/// <param name="msg">返回消息,最终按 "Catch ApiAction Exception : {msg}. {ex.Message}{ex.StackTrace}" 返回</param>
|
public static ApiAction<T> CatchExceptionWithLog<T>(this ApiAction<T> action, Exception ex, string msg = null)
|
{
|
action.CatchException(ex, msg);
|
Logger.Default.Fatal(ex, msg);
|
return action;
|
}
|
|
/// <summary>
|
/// 捕获当前 Action 的异常,返回数据和消息, 并记录日志
|
/// </summary>
|
/// <param name="ex">捕获到的异常</param>
|
/// <param name="localeMsg">返回消息</param>
|
/// <param name="data">返回数据</param>
|
public static ApiAction CatchExceptionWithLog(this ApiAction action, Exception ex, Locale localeMsg, object data)
|
{
|
action.Data = data;
|
return CatchExceptionWithLog(action, ex, localeMsg);
|
}
|
|
/// <summary>
|
/// 捕获当前 Action 的异常,返回消息, 并记录日志
|
/// </summary>
|
/// <param name="ex">捕获到的异常</param>
|
/// <param name="localeMsg">返回消息</param>
|
public static ApiAction CatchExceptionWithLog(this ApiAction action, Exception ex, Locale localeMsg)
|
{
|
action.CatchException(ex, localeMsg);
|
Logger.Default.Fatal(ex, localeMsg.Default());
|
return action;
|
}
|
|
|
/// <summary>
|
/// 捕获当前 Action 的异常,返回数据和消息, 并记录日志
|
/// </summary>
|
/// <param name="ex">捕获到的异常</param>
|
/// <param name="msg">返回消息,最终按 "Catch ApiAction Exception : {msg}. {ex.Message}{ex.StackTrace}" 返回</param>
|
/// <param name="data">返回数据</param>
|
public static ApiAction CatchExceptionWithLog(this ApiAction action, Exception ex, string msg, object data)
|
{
|
action.Data = data;
|
return CatchExceptionWithLog(action, ex, msg);
|
}
|
|
/// <summary>
|
/// 捕获当前 Action 的异常,返回消息, 并记录日志
|
/// </summary>
|
/// <param name="ex">捕获到的异常</param>
|
/// <param name="msg">返回消息,最终按 "Catch ApiAction Exception : {msg}. {ex.Message}{ex.StackTrace}" 返回</param>
|
public static ApiAction CatchExceptionWithLog(this ApiAction action, Exception ex, string msg = null)
|
{
|
action.CatchException(ex, msg);
|
Logger.Default.Fatal(ex, msg);
|
return action;
|
}
|
}
|
|
/// <summary>
|
/// ApiAction 扩展实体
|
/// </summary>
|
public class ApiActionExt : ApiAction
|
{
|
/// <summary>
|
/// SqlSugar IncludesAllFirstLayer
|
/// </summary>
|
public bool NeedInclude { get; set; } = false;
|
}
|
}
|