Merge branch 'framework' of https://gitee.com/ccnetcore/Yi into framework
This commit is contained in:
@@ -43,7 +43,11 @@ namespace Yi.Framework.Core.Sqlsugar.Repositories
|
||||
{
|
||||
return await _DbQueryable.Where(whereExpression).OrderByIF(orderBy is not null, orderBy + " " + orderByType.ToString().ToLower()).ToPageListAsync(page.PageNum, page.PageSize);
|
||||
}
|
||||
|
||||
public async Task<List<T>> GetPageListAsync(List<IConditionalModel> whereExpression, IPagedAndSortedResultRequestDto page, string? orderBy, OrderByEnum orderByType = OrderByEnum.Asc)
|
||||
{
|
||||
return await _DbQueryable.Where(whereExpression).OrderByIF(orderBy is not null, orderBy + " " + orderByType.ToString().ToLower()).ToPageListAsync(page.PageNum, page.PageSize);
|
||||
}
|
||||
|
||||
|
||||
public async Task<bool> UpdateIgnoreNullAsync(T updateObj)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Core.Enums;
|
||||
|
||||
namespace Yi.Framework.Core.Attributes
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property)]
|
||||
public class QueryParameterAttribute:Attribute
|
||||
{
|
||||
public QueryParameterAttribute()
|
||||
{
|
||||
}
|
||||
public QueryParameterAttribute(QueryOperatorEnum queryOperatorEnum)
|
||||
{
|
||||
QueryOperator = queryOperatorEnum;
|
||||
}
|
||||
|
||||
public QueryOperatorEnum QueryOperator { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 验证值为0时是否作为查询条件
|
||||
/// true-作为查询条件 false-不作为查询条件
|
||||
/// </summary>
|
||||
public bool VerifyIsZero { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string ColumnName { get; set; }
|
||||
|
||||
public ColumnTypeEnum ColumnType { get; set; }
|
||||
}
|
||||
|
||||
public enum ColumnTypeEnum
|
||||
{
|
||||
datetime,
|
||||
@bool
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.Core.Enums
|
||||
{
|
||||
public enum QueryOperatorEnum
|
||||
{
|
||||
/// <summary>
|
||||
/// 相等
|
||||
/// </summary>
|
||||
Equal,
|
||||
/// <summary>
|
||||
/// 匹配
|
||||
/// </summary>
|
||||
Like,
|
||||
/// <summary>
|
||||
/// 大于
|
||||
/// </summary>
|
||||
GreaterThan,
|
||||
/// <summary>
|
||||
/// 大于或等于
|
||||
/// </summary>
|
||||
GreaterThanOrEqual,
|
||||
/// <summary>
|
||||
/// 小于
|
||||
/// </summary>
|
||||
LessThan,
|
||||
/// <summary>
|
||||
/// 小于或等于
|
||||
/// </summary>
|
||||
LessThanOrEqual,
|
||||
/// <summary>
|
||||
/// 等于集合
|
||||
/// </summary>
|
||||
In,
|
||||
/// <summary>
|
||||
/// 不等于集合
|
||||
/// </summary>
|
||||
NotIn,
|
||||
/// <summary>
|
||||
/// 左边匹配
|
||||
/// </summary>
|
||||
LikeLeft,
|
||||
/// <summary>
|
||||
/// 右边匹配
|
||||
/// </summary>
|
||||
LikeRight,
|
||||
/// <summary>
|
||||
/// 不相等
|
||||
/// </summary>
|
||||
NoEqual,
|
||||
/// <summary>
|
||||
/// 为空或空
|
||||
/// </summary>
|
||||
IsNullOrEmpty,
|
||||
/// <summary>
|
||||
/// 不为空
|
||||
/// </summary>
|
||||
IsNot,
|
||||
/// <summary>
|
||||
/// 不匹配
|
||||
/// </summary>
|
||||
NoLike,
|
||||
/// <summary>
|
||||
/// 时间段 值用 "|" 隔开
|
||||
/// </summary>
|
||||
DateRange
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,6 @@ namespace Yi.Framework.Data.Entities
|
||||
{
|
||||
public interface IState
|
||||
{
|
||||
public bool? State { get; set; }
|
||||
public bool State { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -14,5 +15,7 @@ namespace Yi.Framework.Ddd.Dtos
|
||||
string? SortBy { get; set; }
|
||||
|
||||
OrderByEnum SortType { get; set; }
|
||||
List<IConditionalModel> Conditions { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -13,5 +14,6 @@ namespace Yi.Framework.Ddd.Dtos
|
||||
public int PageSize { get; set; } = int.MaxValue;
|
||||
public string? SortBy { get; set; }
|
||||
public OrderByEnum SortType { get; set; } = OrderByEnum.Desc;
|
||||
public List<IConditionalModel> Conditions { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,8 @@ namespace Yi.Framework.Ddd.Repositories
|
||||
Task<List<T>> GetPageListAsync(Expression<Func<T, bool>> whereExpression, IPagedAndSortedResultRequestDto page);
|
||||
Task<List<T>> GetPageListAsync(Expression<Func<T, bool>> whereExpression, IPagedAndSortedResultRequestDto page, Expression<Func<T, object>>? orderByExpression = null, OrderByEnum orderByType = OrderByEnum.Asc);
|
||||
Task<List<T>> GetPageListAsync(Expression<Func<T, bool>> whereExpression, IPagedAndSortedResultRequestDto page, string? orderBy, OrderByEnum orderByType = OrderByEnum.Asc);
|
||||
|
||||
Task<List<T>> GetPageListAsync(List<IConditionalModel> whereExpression, IPagedAndSortedResultRequestDto page, string? orderBy, OrderByEnum orderByType = OrderByEnum.Asc);
|
||||
|
||||
|
||||
//插入
|
||||
Task<bool> InsertAsync(T insertObj);
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Core.Attributes;
|
||||
using Yi.Framework.Core.Helper;
|
||||
using Yi.Framework.Core.Model;
|
||||
using Yi.Framework.Ddd.Dtos;
|
||||
@@ -84,38 +85,97 @@ where TEntityDto : IEntityDto<TKey>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<PagedResultDto<TGetListOutputDto>> GetListAsync(TGetListInput input)
|
||||
{
|
||||
|
||||
var totalCount = await _repository.CountAsync(_ => true);
|
||||
var totalCount = -1;
|
||||
|
||||
var entities = new List<TEntity>();
|
||||
var entityDtos = new List<TGetListOutputDto>();
|
||||
|
||||
if (totalCount > 0)
|
||||
bool isPageList = true;
|
||||
//这里还可以追加如果是审计日志,继续拼接条件即可
|
||||
if (input is IPageTimeResultRequestDto timeInput)
|
||||
{
|
||||
|
||||
//这里还可以追加如果是审计日志,继续拼接条件即可
|
||||
if (input is IPageTimeResultRequestDto timeInput)
|
||||
if (timeInput.StartTime is not null)
|
||||
{
|
||||
if (timeInput.StartTime is not null)
|
||||
{
|
||||
timeInput.EndTime = timeInput.EndTime ?? DateTime.Now;
|
||||
}
|
||||
timeInput.EndTime = timeInput.EndTime ?? DateTime.Now;
|
||||
}
|
||||
|
||||
|
||||
if (input is IPagedAndSortedResultRequestDto sortInput)
|
||||
{
|
||||
entities = await _repository.GetPageListAsync(_ => true, sortInput,sortInput.SortBy, sortInput.SortType);
|
||||
}
|
||||
|
||||
|
||||
else
|
||||
{
|
||||
entities = await _repository.GetListAsync();
|
||||
}
|
||||
entityDtos = await MapToGetListOutputDtosAsync(entities);
|
||||
}
|
||||
|
||||
if (input is IPagedAndSortedResultRequestDto sortInput)
|
||||
{
|
||||
var dependsOnbuild = sortInput.GetType().GetCustomAttributes(typeof(QueryParameterAttribute), false).FirstOrDefault() as QueryParameterAttribute;
|
||||
if (dependsOnbuild is null)
|
||||
{
|
||||
entities = await _repository.GetPageListAsync(_ => true, sortInput, sortInput.SortBy, sortInput.SortType);
|
||||
}
|
||||
else
|
||||
{
|
||||
sortInput.Conditions = new List<IConditionalModel>();
|
||||
System.Reflection.PropertyInfo[] properties = sortInput.GetType().GetProperties();
|
||||
foreach (System.Reflection.PropertyInfo item in properties)
|
||||
{
|
||||
var query = item.GetCustomAttributes(typeof(QueryParameterAttribute), false).FirstOrDefault() as QueryParameterAttribute;
|
||||
if (query is not null)
|
||||
{
|
||||
object value = item.GetValue(sortInput, null);
|
||||
if (value is not null)
|
||||
{
|
||||
if (value.ToString() == "0")
|
||||
{
|
||||
if (query.VerifyIsZero)
|
||||
{
|
||||
sortInput.Conditions.Add(new ConditionalModel { FieldValue = value.ToString(), FieldName = item.Name, ConditionalType = (ConditionalType)(int)query.QueryOperator });
|
||||
}
|
||||
}
|
||||
else {
|
||||
switch (query.ColumnType)
|
||||
{
|
||||
case ColumnTypeEnum.datetime:
|
||||
if (!string.IsNullOrEmpty(query.ColumnName))
|
||||
{
|
||||
DateTime dt = DateTime.Now;
|
||||
DateTime.TryParse(value.ToString(), out dt);
|
||||
sortInput.Conditions.Add(new ConditionalModel { FieldValue = dt.ToString("yyyy-MM-dd HH:mm:ss"), FieldName = query.ColumnName, ConditionalType = (ConditionalType)(int)query.QueryOperator });
|
||||
}
|
||||
else
|
||||
{
|
||||
sortInput.Conditions.Add(new ConditionalModel { FieldValue = value.ToString(), FieldName = item.Name, ConditionalType = (ConditionalType)(int)query.QueryOperator });
|
||||
}
|
||||
break;
|
||||
case ColumnTypeEnum.@bool:
|
||||
string _Value = "";
|
||||
if ((bool)value)
|
||||
{
|
||||
_Value = "1";
|
||||
}
|
||||
else {
|
||||
_Value = "0";
|
||||
}
|
||||
sortInput.Conditions.Add(new ConditionalModel { FieldValue = _Value, FieldName = item.Name, ConditionalType = (ConditionalType)(int)query.QueryOperator });
|
||||
break;
|
||||
default:
|
||||
sortInput.Conditions.Add(new ConditionalModel { FieldValue = value.ToString(), FieldName = item.Name, ConditionalType = (ConditionalType)(int)query.QueryOperator });
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
entities = await _repository.GetPageListAsync(sortInput.Conditions, sortInput, sortInput.SortBy, sortInput.SortType);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
isPageList = false;
|
||||
entities = await _repository.GetListAsync();
|
||||
}
|
||||
entityDtos = await MapToGetListOutputDtosAsync(entities);
|
||||
//如果是分页查询,还需要统计数量
|
||||
if (isPageList)
|
||||
{
|
||||
totalCount = await _repository.CountAsync(_ => true);
|
||||
}
|
||||
return new PagedResultDto<TGetListOutputDto>(
|
||||
totalCount,
|
||||
entityDtos
|
||||
|
||||
Reference in New Issue
Block a user