You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
4.9 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using EntrustSettle.Model;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq.Expressions;
using System.Threading.Tasks;
namespace EntrustSettle.IServices.Base
{
/// <summary>
///
/// </summary>
/// <remarks>已在<see cref="AutofacModuleRegister"/>中注册,可以直接在需要的地方注入</remarks>
public interface IBaseServices<TEntity> where TEntity : class, new()
{
ISqlSugarClient Db { get; }
#region 查询
ISugarQueryable<TEntity> AsQueryable();
Task<TEntity> QueryById(object objId);
Task<TEntity> QueryById(object objId, bool blnUseCache = false);
Task<List<TEntity>> QueryByIDs(object[] lstIds);
Task<TEntity> QueryFirst(Expression<Func<TEntity, bool>> whereExpression);
Task<TResult> QueryFirst<TResult>(Expression<Func<TEntity, bool>> whereExpression, Expression<Func<TEntity, TResult>> selectExpression);
Task<TEntity> QueryFirstInclude<TReturn>(Expression<Func<TEntity, bool>> whereExpression, Expression<Func<TEntity, List<TReturn>>> include);
Task<List<TEntity>> Query();
Task<List<TEntity>> Query(Expression<Func<TEntity, bool>> whereExpression);
Task<List<TResult>> Query<TResult>(Expression<Func<TEntity, bool>> whereExpression, Expression<Func<TEntity, TResult>> selectExpression);
Task<List<TEntity>> Query(Expression<Func<TEntity, bool>> whereExpression, Expression<Func<TEntity, object>> orderByExpression, bool isAsc = true);
Task<List<TEntity>> Query(Expression<Func<TEntity, bool>> whereExpression, string orderByFields);
Task<List<TEntity>> Query(string where, string orderByFields);
Task<List<TEntity>> QueryTop(string where, int intTop, string orderByFields);
Task<List<TEntity>> QueryTop(Expression<Func<TEntity, bool>> whereExpression, int intTop, string orderByFields);
Task<List<TEntity>> QueryPage(string where, int pageIndex, int pageSize, string orderByFields);
Task<List<TEntity>> QueryPage(Expression<Func<TEntity, bool>> whereExpression, int pageIndex, int pageSize, string orderByFields);
Task<PageModel<TEntity>> QueryPageModel(Expression<Func<TEntity, bool>> whereExpression, int pageIndex = 1, int pageSize = 20, Expression<Func<TEntity, object>> orderByExpression = null, bool isAsc = true);
Task<PageModel<TEntity>> QueryPageModel(Expression<Func<TEntity, bool>> whereExpression, int pageIndex = 1, int pageSize = 20, string orderByFields = null);
Task<PageModel<TEntity>> QueryPageModel(Expression<Func<TEntity, bool>> whereExpression, PaginationModel paginationModel);
Task<List<TEntity>> QuerySql(string sql, SugarParameter[] parameters = null);
Task<DataTable> QueryTable(string sql, SugarParameter[] parameters = null);
#endregion
#region 新增
IInsertable<TEntity> AsInsertable(TEntity model);
IInsertable<TEntity> AsInsertable(List<TEntity> listEntity);
Task<long> Add(TEntity model);
Task<List<long>> Add(List<TEntity> listEntity);
#endregion
#region 删除
Task<bool> Delete(Expression<Func<TEntity, bool>> whereExpression);
Task<bool> DeleteById(object id);
Task<bool> Delete(TEntity model);
Task<bool> DeleteByIds(object[] ids);
#endregion
#region 更新
IUpdateable<TEntity> AsUpdateable();
IUpdateable<TEntity> AsUpdateable(TEntity model);
IUpdateable<TEntity> AsUpdateable(params TEntity[] entities);
Task<bool> Update(TEntity model);
Task<bool> Update(TEntity entity, Expression<Func<TEntity, object>> updateColumns);
Task<bool> Update(List<TEntity> model);
Task<bool> Update(TEntity entity, string where);
Task<bool> Update(TEntity entity, List<string> lstColumns = null, List<string> lstIgnoreColumns = null, string where = "");
Task<bool> Update(Expression<Func<TEntity, TEntity>> columns, Expression<Func<TEntity, bool>> where);
#endregion
#region Split分表基础接口 基础CRUD
/// <summary>
/// 通过ID查询(自动分表)
/// </summary>
Task<TEntity> QueryByIdSplit(object objId);
/// <summary>
/// 分页查询(自动分表)
/// </summary>
Task<PageModel<TEntity>> QueryPageSplit(Expression<Func<TEntity, bool>> whereExpression, DateTime beginTime, DateTime endTime, int pageIndex = 1, int pageSize = 20, string orderByFields = null);
/// <summary>
/// 插入(自动分表)
/// </summary>
Task<List<long>> AddSplit(TEntity entity);
/// <summary>
/// 删除(自动分表)
/// </summary>
Task<bool> DeleteSplit(TEntity entity, DateTime dateTime);
/// <summary>
/// 更新(自动分表)
/// </summary>
Task<bool> UpdateSplit(TEntity entity, DateTime dateTime);
#endregion
}
}