移除QA消息通知代码
This commit is contained in:
@@ -1,184 +0,0 @@
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Linq.Dynamic.Core;
|
||||
|
||||
namespace IRaCIS.Core.Infrastructure.Extention
|
||||
{
|
||||
public static class QueryablePageListExtensions
|
||||
{
|
||||
//单字段排序
|
||||
public static PageOutput<T> ToPagedList<T>(this IQueryable<T> source, int pageIndex, int pageSize, string defaultSortFiled = "Id", bool isAsc = true)
|
||||
{
|
||||
if (pageIndex <= 0)
|
||||
{
|
||||
pageIndex = 1;
|
||||
}
|
||||
if (pageSize <= 0)
|
||||
{
|
||||
pageSize = 10;
|
||||
}
|
||||
var count = source.Count();
|
||||
|
||||
if (count == 0)
|
||||
{
|
||||
return new PageOutput<T>() { CurrentPageData=new T[0] };
|
||||
}
|
||||
|
||||
|
||||
var propName = string.IsNullOrWhiteSpace(defaultSortFiled) ? "Id" : defaultSortFiled;
|
||||
|
||||
source = isAsc ? source.OrderBy(propName) : source.OrderBy(propName + " desc");
|
||||
|
||||
source = source.Skip((pageIndex - 1) * pageSize);
|
||||
|
||||
var items = source
|
||||
.Take(pageSize)
|
||||
.ToArray();
|
||||
|
||||
var pagedList = new PageOutput<T>()
|
||||
{
|
||||
PageIndex = pageIndex,
|
||||
PageSize = pageSize,
|
||||
TotalCount = count,
|
||||
CurrentPageData = items
|
||||
};
|
||||
|
||||
return pagedList;
|
||||
}
|
||||
|
||||
//单字段排序 异步
|
||||
public static async Task<PageOutput<T>> ToPagedListAsync<T>(this IQueryable<T> source, int pageNumber, int pageSize, string defaultSortFiled = "Id", bool isAsc = true,bool isMultiSortFiled=false, string[] sortArray=default, CancellationToken cancellationToken = default)
|
||||
{
|
||||
|
||||
if (isMultiSortFiled&& sortArray==default)
|
||||
{
|
||||
throw new System.Exception("必须指定排序字段");
|
||||
}
|
||||
|
||||
if (pageNumber <= 0)
|
||||
{
|
||||
pageNumber = 1;
|
||||
}
|
||||
if (pageSize <= 0)
|
||||
{
|
||||
pageSize = 10;
|
||||
}
|
||||
|
||||
var count = await source.CountAsync(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (count == 0)
|
||||
{
|
||||
return new PageOutput<T>() { CurrentPageData = new T[0] };
|
||||
}
|
||||
var propName = string.IsNullOrWhiteSpace(defaultSortFiled) ? "Id" : defaultSortFiled;
|
||||
|
||||
if (!isMultiSortFiled)
|
||||
{
|
||||
source = isAsc ? source.OrderBy(propName) : source.OrderBy(propName + " desc");
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
var sortString = string.Join(',', sortArray);
|
||||
|
||||
source= source.OrderBy(sortString);
|
||||
}
|
||||
source = source.Skip((pageNumber - 1) * pageSize);
|
||||
var items = await source
|
||||
.Take(pageSize)
|
||||
.ToArrayAsync(cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
var pagedList = new PageOutput<T>()
|
||||
{
|
||||
PageIndex = pageNumber,
|
||||
PageSize = pageSize,
|
||||
TotalCount = count,
|
||||
CurrentPageData = items
|
||||
};
|
||||
|
||||
return pagedList;
|
||||
}
|
||||
|
||||
//多字段排序 ["a asc", "b desc", "c asc"]
|
||||
public static PageOutput<T> ToPagedList<T>(this IQueryable<T> source, int pageIndex, int pageSize,string[] sortArray)
|
||||
{
|
||||
if (pageIndex <= 0)
|
||||
{
|
||||
pageIndex = 1;
|
||||
}
|
||||
if (pageSize <= 0)
|
||||
{
|
||||
pageSize = 10;
|
||||
}
|
||||
var count = source.Count();
|
||||
|
||||
if (count == 0)
|
||||
{
|
||||
return new PageOutput<T>() { CurrentPageData = new T[0] };
|
||||
}
|
||||
|
||||
var sortString = string.Join(',', sortArray);
|
||||
|
||||
source.OrderBy(sortString);
|
||||
|
||||
source = source.Skip((pageIndex - 1) * pageSize);
|
||||
|
||||
var items = source
|
||||
.Take(pageSize)
|
||||
.ToArray();
|
||||
|
||||
var pagedList = new PageOutput<T>()
|
||||
{
|
||||
PageIndex = pageIndex,
|
||||
PageSize = pageSize,
|
||||
TotalCount = count,
|
||||
CurrentPageData = items
|
||||
};
|
||||
|
||||
return pagedList;
|
||||
}
|
||||
|
||||
//多字段排序异步 ["a asc", "b desc", "c asc"]
|
||||
public static async Task<PageOutput<T>> ToPagedListAsync<T>(this IQueryable<T> source, int pageNumber, int pageSize, string[] sortArray, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (pageNumber <= 0)
|
||||
{
|
||||
pageNumber = 1;
|
||||
}
|
||||
if (pageSize <= 0)
|
||||
{
|
||||
pageSize = 10;
|
||||
}
|
||||
|
||||
var count = await source.CountAsync(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (count == 0)
|
||||
{
|
||||
return new PageOutput<T>() { CurrentPageData = new T[0] };
|
||||
}
|
||||
|
||||
var sortString = string.Join(',', sortArray);
|
||||
|
||||
source = source.OrderBy(sortString);
|
||||
|
||||
source = source.Skip((pageNumber - 1) * pageSize);
|
||||
var items = await source
|
||||
.Take(pageSize)
|
||||
.ToArrayAsync(cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
var pagedList = new PageOutput<T>()
|
||||
{
|
||||
PageIndex = pageNumber,
|
||||
PageSize = pageSize,
|
||||
TotalCount = count,
|
||||
CurrentPageData = items
|
||||
};
|
||||
|
||||
return pagedList;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace IRaCIS.Core.Infrastructure.Extention
|
||||
{
|
||||
public static class QueryableWhereExtension
|
||||
{
|
||||
public static IQueryable<TEntity> WhereIf<TEntity>(this IQueryable<TEntity> query, [NotNullWhen(true)] bool condition, Expression<Func<TEntity, bool>> filter) where TEntity : class
|
||||
{
|
||||
return condition ? query.Where(filter) : query;
|
||||
}
|
||||
|
||||
public static IEnumerable<TEntity> WhereIf<TEntity>(this IEnumerable<TEntity> query, bool condition, Func<TEntity, bool> filter) where TEntity : class
|
||||
{
|
||||
return condition ? query.Where(filter) : query;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace IRaCIS.Core.Infrastructure.Extention
|
||||
{
|
||||
/// <summary>
|
||||
/// 分页信息输入
|
||||
/// </summary>
|
||||
public class PageInput
|
||||
{
|
||||
public int PageIndex { get; set; } = 1;
|
||||
public int PageSize { set; get; } = 10;
|
||||
public bool Asc { get; set; } = true;
|
||||
public string SortField { get; set; } = "";
|
||||
}
|
||||
|
||||
public class PageInputMultiSort
|
||||
{
|
||||
public int PageIndex { get; set; } = 1;
|
||||
public int PageSize { set; get; } = 10;
|
||||
|
||||
//["a asc", "b desc", "c asc"]
|
||||
public string[] SortArray { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace IRaCIS.Core.Infrastructure.Extention
|
||||
{
|
||||
/// <summary>
|
||||
/// LINQ扩展方法
|
||||
/// </summary>
|
||||
public static class LinqExtension
|
||||
{
|
||||
/// <summary>
|
||||
/// 与连接
|
||||
/// </summary>
|
||||
/// <typeparam name="T">类型</typeparam>
|
||||
/// <param name="left">左条件</param>
|
||||
/// <param name="right">右条件</param>
|
||||
/// <returns>新表达式</returns>
|
||||
public static Expression<Func<T, bool>> And<T>(this Expression<Func<T, bool>> left, Expression<Func<T, bool>> right)
|
||||
{
|
||||
return CombineLambdas(left, right, ExpressionType.AndAlso);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 或连接
|
||||
/// </summary>
|
||||
/// <typeparam name="T">类型</typeparam>
|
||||
/// <param name="left">左条件</param>
|
||||
/// <param name="right">右条件</param>
|
||||
/// <returns>新表达式</returns>
|
||||
public static Expression<Func<T, bool>> Or<T>(this Expression<Func<T, bool>> left, Expression<Func<T, bool>> right)
|
||||
{
|
||||
return CombineLambdas(left, right, ExpressionType.OrElse);
|
||||
}
|
||||
|
||||
private static Expression<Func<T, bool>> CombineLambdas<T>(this Expression<Func<T, bool>> left, Expression<Func<T, bool>> right, ExpressionType expressionType)
|
||||
{
|
||||
var visitor = new SubstituteParameterVisitor
|
||||
{
|
||||
Sub =
|
||||
{
|
||||
[right.Parameters[0]] = left.Parameters[0]
|
||||
}
|
||||
};
|
||||
|
||||
Expression body = Expression.MakeBinary(expressionType, left.Body, visitor.Visit(right.Body));
|
||||
return Expression.Lambda<Func<T, bool>>(body, left.Parameters[0]);
|
||||
}
|
||||
}
|
||||
|
||||
internal class SubstituteParameterVisitor : ExpressionVisitor
|
||||
{
|
||||
public Dictionary<Expression, Expression> Sub = new Dictionary<Expression, Expression>();
|
||||
|
||||
protected override Expression VisitParameter(ParameterExpression node)
|
||||
{
|
||||
return Sub.TryGetValue(node, out var newValue) ? newValue : node;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace IRaCIS.Core.Infrastructure.Extention
|
||||
{
|
||||
public static class ListExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// 将列表转换为树形结构
|
||||
/// </summary>
|
||||
/// <typeparam name="T">类型</typeparam>
|
||||
/// <param name="list">数据</param>
|
||||
/// <param name="rootWhere">根条件</param>
|
||||
/// <param name="childsWhere">节点条件</param>
|
||||
/// <param name="addChilds">添加子节点</param>
|
||||
/// <param name="childEntity"></param>
|
||||
/// <returns></returns>
|
||||
public static List<T> ToTree<T,Tkey>(this List<T> list, Func<T, T, bool> rootWhere, Func<T, T, bool> childsWhere, Action<T, IEnumerable<T>> addChilds, Func<T, Tkey> orderSelector, T childEntity = default)
|
||||
{
|
||||
if (rootWhere is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(rootWhere));
|
||||
}
|
||||
|
||||
if (childsWhere is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(childsWhere));
|
||||
}
|
||||
|
||||
if (addChilds is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(addChilds));
|
||||
}
|
||||
|
||||
if (orderSelector is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(orderSelector));
|
||||
}
|
||||
|
||||
var treelist = new List<T>();
|
||||
//空树
|
||||
if (list == null || list.Count == 0)
|
||||
{
|
||||
return treelist;
|
||||
}
|
||||
if (!list.Any(e => rootWhere(childEntity, e)))
|
||||
{
|
||||
return treelist;
|
||||
}
|
||||
//树根
|
||||
if (list.Any(e => rootWhere(childEntity, e)))
|
||||
{
|
||||
treelist.AddRange(list.Where(e => rootWhere(childEntity, e)).OrderBy(orderSelector));
|
||||
}
|
||||
//树叶 item 是根
|
||||
foreach (var item in treelist)
|
||||
{
|
||||
if (list.Any(e => childsWhere(item, e)))
|
||||
{
|
||||
var nodedata = list.Where(e => childsWhere(item, e)).OrderBy(orderSelector).ToList();
|
||||
|
||||
foreach (var child in nodedata)
|
||||
{
|
||||
//添加子集
|
||||
var data = list.ToTree(childsWhere, childsWhere, addChilds, orderSelector, child);
|
||||
|
||||
addChilds(child, data);
|
||||
}
|
||||
addChilds(item, nodedata);
|
||||
}
|
||||
}
|
||||
return treelist;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
|
||||
namespace IRaCIS.Core.Infrastructure.Extention
|
||||
{
|
||||
public static class ObjectExtension
|
||||
{
|
||||
|
||||
public static T Clone<T>(this T source)
|
||||
{
|
||||
// Don't serialize a null object, simply return the default for that object
|
||||
if (Object.ReferenceEquals(source, null))
|
||||
{
|
||||
return default(T);
|
||||
}
|
||||
|
||||
var deserializeSettings = new JsonSerializerSettings { ObjectCreationHandling = ObjectCreationHandling.Replace };
|
||||
var serializeSettings = new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore };
|
||||
return JsonConvert.DeserializeObject<T>(JsonConvert.SerializeObject(source, serializeSettings), deserializeSettings);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将对象序列化成稽查需要的Json字符串
|
||||
/// </summary>
|
||||
/// <param name="obj"></param>
|
||||
/// <returns></returns>
|
||||
public static string ToJsonStr(this object obj)
|
||||
{
|
||||
|
||||
return JsonConvert.SerializeObject(obj, new JsonSerializerSettings { DateFormatString = "yyyy-MM-dd HH:mm:ss", ReferenceLoopHandling = ReferenceLoopHandling.Ignore });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
|
||||
|
||||
namespace IRaCIS.Core.Infrastructure.Extention
|
||||
{
|
||||
/// <summary>
|
||||
/// 此处是为了 后续代替 IsSuccess IsSuccess暂时还是保留,接下来的接口判断现在用Code 判断 不用IsSuccess就好了
|
||||
|
||||
/// </summary>
|
||||
public enum ApiResponseCodeEnum
|
||||
{
|
||||
//正常的 相当于之前的 IsSuccess = true
|
||||
OK = 0,
|
||||
|
||||
//Api 输入参数有问题 相当于之前的 IsSuccess = false
|
||||
ApiInputError = 1,
|
||||
|
||||
//业务验证不通过 相当于之前的 IsSuccess = false
|
||||
BusinessValidationFailed = 2,
|
||||
|
||||
//数据不存在
|
||||
DataNotExist=3,
|
||||
|
||||
//程序异常 相当于之前的 IsSuccess = false
|
||||
ProgramException = 4,
|
||||
|
||||
|
||||
|
||||
|
||||
//需要提示 ,需要提示 从Result 取数据 ( 0 可以继续处理提交 ,1 不能进行继续处理提交 ,2 刷新列表 )
|
||||
NeedTips = 5,
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//在其他地方登陆,被迫下线
|
||||
LoginInOtherPlace = -1,
|
||||
|
||||
//没有带token访问(未登陆)
|
||||
NoToken=10,
|
||||
|
||||
//带了Token,但是没有相应权限(该用户类型不能做)
|
||||
HaveTokenNotAccess=11
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
namespace IRaCIS.Core.Infrastructure.Extention
|
||||
{
|
||||
/// <summary>
|
||||
/// 响应数据输出接口
|
||||
/// </summary>
|
||||
public interface IResponseOutput
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否成功
|
||||
/// </summary>
|
||||
bool IsSuccess { get; }
|
||||
|
||||
public ApiResponseCodeEnum Code { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 消息
|
||||
/// </summary>
|
||||
string ErrorMessage { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 响应数据输出泛型接口
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public interface IResponseOutput<T> : IResponseOutput
|
||||
{
|
||||
/// <summary>
|
||||
/// 返回数据
|
||||
/// </summary>
|
||||
T Data { get; }
|
||||
}
|
||||
|
||||
public interface IResponseOutput<T,T2> : IResponseOutput
|
||||
{
|
||||
/// <summary>
|
||||
/// 返回数据
|
||||
/// </summary>
|
||||
T Data { get; }
|
||||
|
||||
T2 OtherInfo { get; }
|
||||
}
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace IRaCIS.Core.Infrastructure.Extention
|
||||
{
|
||||
public static class NUllCheckExtension
|
||||
{
|
||||
|
||||
|
||||
[DoesNotReturn]
|
||||
public static TEntity IfNullThrowException<TEntity>(this TEntity businessObject) where TEntity : class
|
||||
{
|
||||
if(businessObject == null)
|
||||
{
|
||||
throw new QueryBusinessObjectNotExistException($"The query object {typeof(TEntity).Name} does not exist , or was deleted by someone else, or an incorrect parameter query caused");
|
||||
}
|
||||
else
|
||||
{
|
||||
return businessObject!;
|
||||
}
|
||||
}
|
||||
|
||||
[DoesNotReturn]
|
||||
public static TEntity IfNullThrowException<TEntity>(this TEntity? businessStruct) where TEntity : struct
|
||||
{
|
||||
if (businessStruct == null)
|
||||
{
|
||||
throw new QueryBusinessObjectNotExistException($"The query object {typeof(TEntity).Name} does not exist , or was deleted by someone else, or an incorrect parameter query caused");
|
||||
}
|
||||
else
|
||||
{
|
||||
return (TEntity)businessStruct;
|
||||
}
|
||||
}
|
||||
|
||||
[DoesNotReturn]
|
||||
public static TEntity IfNullThrowConvertException<TEntity>(this TEntity businessObject) where TEntity : class
|
||||
{
|
||||
if (businessObject == null)
|
||||
{
|
||||
throw new QueryBusinessObjectNotExistException($" Can not Convert to {typeof(TEntity).Name} Type, Please check parameter");
|
||||
}
|
||||
else
|
||||
{
|
||||
return businessObject!;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class QueryBusinessObjectNotExistException : Exception
|
||||
{
|
||||
|
||||
public QueryBusinessObjectNotExistException()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public QueryBusinessObjectNotExistException(string message) : base(message)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class ConversionException : Exception
|
||||
{
|
||||
public ConversionException(string message) : base(message)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace IRaCIS.Core.Infrastructure.Extention
|
||||
{
|
||||
/// <summary>
|
||||
/// 分页信息输出 泛型
|
||||
/// </summary>
|
||||
public class PageOutput<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// 当前页索引
|
||||
/// </summary>
|
||||
public int PageIndex { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 每页的记录条数
|
||||
/// </summary>
|
||||
public int PageSize { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 数据总数
|
||||
/// </summary>
|
||||
public long TotalCount { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 数据
|
||||
/// </summary>
|
||||
public IList<T> CurrentPageData { get; set; }
|
||||
|
||||
public PageOutput()
|
||||
{
|
||||
}
|
||||
|
||||
public PageOutput(int pageIndex, int pageSize, long totalCount, IList<T> data)
|
||||
{
|
||||
PageIndex = pageIndex;
|
||||
PageSize = pageSize;
|
||||
TotalCount = totalCount;
|
||||
CurrentPageData = data;
|
||||
}
|
||||
|
||||
public PageOutput(int pageIndex, int pageSize, IQueryable<T> list)
|
||||
{
|
||||
PageIndex = pageIndex;
|
||||
PageSize = pageSize;
|
||||
TotalCount = list.Count();
|
||||
CurrentPageData = list.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,206 +0,0 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace IRaCIS.Core.Infrastructure.Extention
|
||||
{
|
||||
/// <summary>
|
||||
/// 响应数据输出 泛型
|
||||
/// </summary>
|
||||
public class ResponseOutput<T> : IResponseOutput<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否成功标记
|
||||
/// </summary>
|
||||
public bool IsSuccess { get; private set; }
|
||||
|
||||
|
||||
public ApiResponseCodeEnum Code { get; set; } = ApiResponseCodeEnum.OK;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 消息
|
||||
/// </summary>
|
||||
public string ErrorMessage { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 数据 兼顾以前 Json序列化的时候返回属性名为“Result”
|
||||
/// </summary>
|
||||
[JsonProperty("Result")]
|
||||
public T Data { get; private set; }
|
||||
|
||||
|
||||
|
||||
public object OtherData { 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)
|
||||
{
|
||||
IsSuccess = true;
|
||||
Code = code;
|
||||
Data = data;
|
||||
OtherData=otherData;
|
||||
ErrorMessage = msg;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 失败
|
||||
/// </summary>
|
||||
/// <param name="msg">提示消息</param>
|
||||
/// <param name="data">数据</param>
|
||||
/// <returns></returns>
|
||||
public ResponseOutput<T> NotOk(string msg = "", T data = default, ApiResponseCodeEnum code = ApiResponseCodeEnum.OK)
|
||||
{
|
||||
IsSuccess = false;
|
||||
Code = code;
|
||||
ErrorMessage = msg;
|
||||
Data = data;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
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>
|
||||
public static class ResponseOutput
|
||||
{
|
||||
|
||||
|
||||
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 = "")
|
||||
{
|
||||
return new ResponseOutput<T>().Ok(data, otherData, msg);
|
||||
}
|
||||
/// <summary>
|
||||
/// 成功
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static IResponseOutput Ok()
|
||||
{
|
||||
return Ok<string>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 失败
|
||||
/// </summary>
|
||||
/// <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)
|
||||
{
|
||||
return new ResponseOutput<T>().NotOk(msg, data, code);
|
||||
}
|
||||
|
||||
public static IResponseOutput<T> NotOk<T>( T data = default, ApiResponseCodeEnum code = ApiResponseCodeEnum.BusinessValidationFailed)
|
||||
{
|
||||
return new ResponseOutput<T>().NotOk("", data, code);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 失败
|
||||
/// </summary>
|
||||
/// <param name="msg">消息</param>
|
||||
/// <returns></returns>
|
||||
public static IResponseOutput<string> NotOk(string msg = "", ApiResponseCodeEnum code = ApiResponseCodeEnum.BusinessValidationFailed)
|
||||
{
|
||||
return new ResponseOutput<string>().NotOk(msg,code:code);
|
||||
}
|
||||
|
||||
public static IResponseOutput<string> DBNotExistIfNUll(object businessObject)
|
||||
{
|
||||
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>
|
||||
/// <param name="success"></param>
|
||||
/// <returns></returns>
|
||||
public static IResponseOutput Result(bool success)
|
||||
{
|
||||
return success ? Ok() : NotOk("Expect a change, but the database data has not changed");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据布尔值返回结果 --适合添加和更新一起
|
||||
/// </summary>
|
||||
/// <param name="success"></param>
|
||||
/// <returns></returns>
|
||||
public static IResponseOutput<T> Result<T>(bool success, T data = default)
|
||||
{
|
||||
return success ? Ok<T>(data) : NotOk<T>("Saved failed");
|
||||
}
|
||||
|
||||
///// <summary>
|
||||
///// 根据布尔值返回结果
|
||||
///// </summary>
|
||||
///// <param name="success"></param>
|
||||
///// <returns></returns>
|
||||
//public static IResponseOutput Result<T>(bool success)
|
||||
//{
|
||||
// return success ? Ok<T>() : NotOk<T>();
|
||||
//}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user