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.

222 lines
8.8 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.IRepository.Base;
using EntrustSettle.IServices.Base;
using EntrustSettle.Model;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq.Expressions;
using System.Threading.Tasks;
namespace EntrustSettle.Services.Base
{
public class BaseServices<TEntity> : IBaseServices<TEntity> where TEntity : class, new()
{
public BaseServices(IBaseRepository<TEntity> BaseDal = null)
{
this.BaseDal = BaseDal;
}
public IBaseRepository<TEntity> BaseDal { get; set; } //通过在子类的构造函数中注入,这里是基类,不用构造函数
public ISqlSugarClient Db => BaseDal.Db;
#region 查询
public ISugarQueryable<TEntity> AsQueryable()
{
return Db.Queryable<TEntity>();
}
public async Task<TEntity> QueryById(object objId)
{
return await BaseDal.QueryById(objId);
}
public async Task<TEntity> QueryById(object objId, bool blnUseCache = false)
{
return await BaseDal.QueryById(objId, blnUseCache);
}
public async Task<List<TEntity>> QueryByIDs(object[] lstIds)
{
return await BaseDal.QueryByIDs(lstIds);
}
public async Task<TEntity> QueryFirst(Expression<Func<TEntity, bool>> whereExpression)
{
return await BaseDal.QueryFirst(whereExpression);
}
public async Task<TResult> QueryFirst<TResult>(Expression<Func<TEntity, bool>> whereExpression, Expression<Func<TEntity, TResult>> selectExpression)
{
return await BaseDal.QueryFirst(whereExpression, selectExpression);
}
public async Task<TEntity> QueryFirstInclude<TReturn>(Expression<Func<TEntity, bool>> whereExpression, Expression<Func<TEntity, List<TReturn>>> include)
{
return await BaseDal.QueryFirstInclude(whereExpression, include);
}
public async Task<List<TEntity>> Query()
{
return await BaseDal.Query();
}
public async Task<List<TEntity>> Query(Expression<Func<TEntity, bool>> whereExpression)
{
return await BaseDal.Query(whereExpression);
}
public async Task<List<TResult>> Query<TResult>(Expression<Func<TEntity, bool>> whereExpression, Expression<Func<TEntity, TResult>> selectExpression)
{
return await BaseDal.Query(whereExpression, selectExpression);
}
public async Task<List<TEntity>> Query(Expression<Func<TEntity, bool>> whereExpression, Expression<Func<TEntity, object>> orderByExpression, bool isAsc = true)
{
return await BaseDal.Query(whereExpression, orderByExpression, isAsc);
}
public async Task<List<TEntity>> Query(Expression<Func<TEntity, bool>> whereExpression, string orderByFileds)
{
return await BaseDal.Query(whereExpression, orderByFileds);
}
public async Task<List<TEntity>> Query(string where, string orderByFileds)
{
return await BaseDal.Query(where, orderByFileds);
}
public async Task<List<TEntity>> QueryTop(Expression<Func<TEntity, bool>> whereExpression, int top, string orderByFileds)
{
return await BaseDal.QueryTop(whereExpression, top, orderByFileds);
}
public async Task<List<TEntity>> QueryTop(string where, int top, string orderByFileds)
{
return await BaseDal.QueryTop(where, top, orderByFileds);
}
public async Task<List<TEntity>> QueryPage(Expression<Func<TEntity, bool>> whereExpression, int pageIndex, int pageSize, string orderByFileds)
{
return await BaseDal.QueryPage(whereExpression, pageIndex, pageSize, orderByFileds);
}
public async Task<List<TEntity>> QueryPage(string where, int pageIndex, int pageSize, string orderByFileds)
{
return await BaseDal.QueryPage(where, pageIndex, pageSize, orderByFileds);
}
public async Task<PageModel<TEntity>> QueryPageModel(Expression<Func<TEntity, bool>> whereExpression, int pageIndex = 1, int pageSize = 20, Expression<Func<TEntity, object>> orderByExpression = null, bool isAsc = true)
{
return await BaseDal.QueryPageModel(whereExpression, pageIndex, pageSize, orderByExpression, isAsc);
}
public async Task<PageModel<TEntity>> QueryPageModel(Expression<Func<TEntity, bool>> whereExpression, int pageIndex = 1, int pageSize = 20, string orderByFileds = null)
{
return await BaseDal.QueryPageModel(whereExpression, pageIndex, pageSize, orderByFileds);
}
public async Task<PageModel<TEntity>> QueryPageModel(Expression<Func<TEntity, bool>> whereExpression, PaginationModel pagination)
{
return await BaseDal.QueryPageModel(whereExpression, pagination.pageIndex, pagination.pageSize, pagination.orderByFileds);
}
public async Task<List<TEntity>> QuerySql(string sql, SugarParameter[] parameters = null)
{
return await BaseDal.QuerySql(sql, parameters);
}
public async Task<DataTable> QueryTable(string sql, SugarParameter[] parameters = null)
{
return await BaseDal.QueryTable(sql, parameters);
}
#endregion
#region 新增
public IInsertable<TEntity> AsInsertable(TEntity model)
{
return Db.Insertable(model);
}
public IInsertable<TEntity> AsInsertable(params TEntity[] entities)
{
return Db.Insertable(entities);
}
public async Task<long> Add(TEntity entity)
{
return await BaseDal.Add(entity);
}
public async Task<List<long>> Add(List<TEntity> listEntity)
{
return await BaseDal.Add(listEntity);
}
#endregion
#region 更新
public IUpdateable<TEntity> AsUpdateable(TEntity model)
{
return Db.Updateable(model);
}
public IUpdateable<TEntity> AsUpdateable()
{
return Db.Updateable<TEntity>();
}
public IUpdateable<TEntity> AsUpdateable(params TEntity[] entities)
{
return Db.Updateable(entities);
}
public async Task<bool> Update(TEntity entity)
{
return await BaseDal.Update(entity);
}
public async Task<bool> Update(List<TEntity> entity)
{
return await BaseDal.Update(entity);
}
public async Task<bool> Update(TEntity entity, string where)
{
return await BaseDal.Update(entity, where);
}
public async Task<bool> Update(TEntity entity, List<string> lstColumns = null, List<string> lstIgnoreColumns = null, string where = "")
{
return await BaseDal.Update(entity, lstColumns, lstIgnoreColumns, where);
}
public async Task<bool> Update(TEntity entity, Expression<Func<TEntity, object>> updateColumns)
{
return await BaseDal.Update(entity, updateColumns);
}
public async Task<bool> Update(Expression<Func<TEntity, TEntity>> columns, Expression<Func<TEntity, bool>> where)
{
return await BaseDal.Update(columns, where);
}
#endregion
#region 删除
public async Task<bool> Delete(Expression<Func<TEntity, bool>> whereExpression)
{
return await BaseDal.Delete(whereExpression);
}
public async Task<bool> Delete(TEntity entity)
{
return await BaseDal.Delete(entity);
}
public async Task<bool> DeleteById(object id)
{
return await BaseDal.DeleteById(id);
}
public async Task<bool> DeleteByIds(object[] ids)
{
return await BaseDal.DeleteByIds(ids);
}
#endregion
#region Split分表基础接口 基础CRUD
public async Task<TEntity> QueryByIdSplit(object objId)
{
return await BaseDal.QueryByIdSplit(objId);
}
public async Task<PageModel<TEntity>> QueryPageSplit(Expression<Func<TEntity, bool>> whereExpression, DateTime beginTime, DateTime endTime, int pageIndex = 1, int pageSize = 20, string orderByFields = null)
{
return await BaseDal.QueryPageSplit(whereExpression, beginTime, endTime, pageIndex, pageSize, orderByFields);
}
public async Task<List<long>> AddSplit(TEntity entity)
{
return await BaseDal.AddSplit(entity);
}
public async Task<bool> UpdateSplit(TEntity entity, DateTime dateTime)
{
return await BaseDal.UpdateSplit(entity, dateTime);
}
public async Task<bool> DeleteSplit(TEntity entity, DateTime dateTime)
{
return await BaseDal.DeleteSplit(entity, dateTime);
}
#endregion
}
}