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 : IBaseServices where TEntity : class, new() { public BaseServices(IBaseRepository BaseDal = null) { this.BaseDal = BaseDal; } public IBaseRepository BaseDal { get; set; } //通过在子类的构造函数中注入,这里是基类,不用构造函数 public ISqlSugarClient Db => BaseDal.Db; #region 查询 public ISugarQueryable AsQueryable() { return Db.Queryable(); } public async Task QueryById(object objId) { return await BaseDal.QueryById(objId); } public async Task QueryById(object objId, bool blnUseCache = false) { return await BaseDal.QueryById(objId, blnUseCache); } public async Task> QueryByIDs(object[] lstIds) { return await BaseDal.QueryByIDs(lstIds); } public async Task QueryFirst(Expression> whereExpression) { return await BaseDal.QueryFirst(whereExpression); } public async Task QueryFirstInclude(Expression> whereExpression, Expression>> include) { return await BaseDal.QueryFirstInclude(whereExpression, include); } public async Task> Query() { return await BaseDal.Query(); } public async Task> Query(Expression> whereExpression) { return await BaseDal.Query(whereExpression); } public async Task> Query(Expression> whereExpression, Expression> orderByExpression, bool isAsc = true) { return await BaseDal.Query(whereExpression, orderByExpression, isAsc); } public async Task> Query(Expression> whereExpression, string orderByFileds) { return await BaseDal.Query(whereExpression, orderByFileds); } public async Task> Query(string where, string orderByFileds) { return await BaseDal.Query(where, orderByFileds); } public async Task> QueryTop(Expression> whereExpression, int top, string orderByFileds) { return await BaseDal.QueryTop(whereExpression, top, orderByFileds); } public async Task> QueryTop(string where, int top, string orderByFileds) { return await BaseDal.QueryTop(where, top, orderByFileds); } public async Task> QueryPage(Expression> whereExpression, int pageIndex, int pageSize, string orderByFileds) { return await BaseDal.QueryPage(whereExpression, pageIndex, pageSize, orderByFileds); } public async Task> QueryPage(string where, int pageIndex, int pageSize, string orderByFileds) { return await BaseDal.QueryPage(where, pageIndex, pageSize, orderByFileds); } public async Task> QueryPageModel(Expression> whereExpression, int pageIndex = 1, int pageSize = 20, Expression> orderByExpression = null, bool isAsc = true) { return await BaseDal.QueryPageModel(whereExpression, pageIndex, pageSize, orderByExpression, isAsc); } public async Task> QueryPageModel(Expression> whereExpression, int pageIndex = 1, int pageSize = 20, string orderByFileds = null) { return await BaseDal.QueryPageModel(whereExpression, pageIndex, pageSize, orderByFileds); } public async Task> QueryPageModel(Expression> whereExpression, PaginationModel pagination) { return await BaseDal.QueryPageModel(whereExpression, pagination.pageIndex, pagination.pageSize, pagination.orderByFileds); } public async Task> QueryDto(Expression> expression) { return await BaseDal.QueryDto(expression); } public async Task> QueryDto(Expression> expression, Expression> whereExpression, string orderByFileds) { return await BaseDal.QueryDto(expression, whereExpression, orderByFileds); } public async Task> QuerySql(string sql, SugarParameter[] parameters = null) { return await BaseDal.QuerySql(sql, parameters); } public async Task QueryTable(string sql, SugarParameter[] parameters = null) { return await BaseDal.QueryTable(sql, parameters); } public async Task> QueryMuch(Expression> joinExpression, Expression> whereLambda, Expression> selectExpression) where T : class, new() { return await BaseDal.QueryMuch(joinExpression, whereLambda, selectExpression); } public async Task> QueryMuchPage(Expression> joinExpression, Expression> whereExpression, Expression> selectExpression, int pageIndex = 1, int pageSize = 20, string strOrderByFileds = null) { return await BaseDal.QueryMuchPage(joinExpression, whereExpression, selectExpression, pageIndex, pageSize, strOrderByFileds); } public async Task> QueryMuchPageGroup(Expression> joinExpression, Expression> whereExpression, Expression> selectExpression, Expression> groupExpression, int pageIndex = 1, int pageSize = 20, string strOrderByFileds = null) { return await BaseDal.QueryMuchPageGroup(joinExpression, whereExpression, selectExpression, groupExpression, pageIndex, pageSize, strOrderByFileds); } public async Task> QueryMuch(Expression> joinExpression, Expression> whereLambda, Expression> selectExpression) where T : class, new() { return await BaseDal.QueryMuch(joinExpression, whereLambda, selectExpression); } public Task> QueryMuchPage(Expression> joinExpression, Expression> whereExpression, Expression> selectExpression, int pageIndex = 1, int pageSize = 20, string strOrderByFileds = null) { return BaseDal.QueryMuchPage(joinExpression, whereExpression, selectExpression, pageIndex, pageSize, strOrderByFileds); } #endregion #region 新增 public IInsertable AsInsertable(TEntity model) { return Db.Insertable(model); } public IInsertable AsInsertable(params TEntity[] entities) { return Db.Insertable(entities); } public async Task Add(TEntity entity) { return await BaseDal.Add(entity); } public async Task> Add(List listEntity) { return await BaseDal.Add(listEntity); } #endregion #region 更新 public IUpdateable AsUpdateable(TEntity model) { return Db.Updateable(model); } public IUpdateable AsUpdateable() { return Db.Updateable(); } public IUpdateable AsUpdateable(params TEntity[] entities) { return Db.Updateable(entities); } public async Task Update(TEntity entity) { return await BaseDal.Update(entity); } public async Task Update(List entity) { return await BaseDal.Update(entity); } public async Task Update(TEntity entity, string where) { return await BaseDal.Update(entity, where); } public async Task Update(object operateAnonymousObjects) { return await BaseDal.Update(operateAnonymousObjects); } public async Task Update(TEntity entity, List lstColumns = null, List lstIgnoreColumns = null, string where = "") { return await BaseDal.Update(entity, lstColumns, lstIgnoreColumns, where); } public async Task Update(TEntity entity, Expression> updateColumns) { return await BaseDal.Update(entity, updateColumns); } public async Task Update(Expression> columns, Expression> where) { return await BaseDal.Update(columns, where); } #endregion #region 删除 public async Task Delete(Expression> whereExpression) { return await BaseDal.Delete(whereExpression); } public async Task Delete(TEntity entity) { return await BaseDal.Delete(entity); } public async Task DeleteById(object id) { return await BaseDal.DeleteById(id); } public async Task DeleteByIds(object[] ids) { return await BaseDal.DeleteByIds(ids); } #endregion #region Split分表基础接口 (基础CRUD) public async Task QueryByIdSplit(object objId) { return await BaseDal.QueryByIdSplit(objId); } public async Task> QueryPageSplit(Expression> 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> AddSplit(TEntity entity) { return await BaseDal.AddSplit(entity); } public async Task UpdateSplit(TEntity entity, DateTime dateTime) { return await BaseDal.UpdateSplit(entity, dateTime); } public async Task DeleteSplit(TEntity entity, DateTime dateTime) { return await BaseDal.DeleteSplit(entity, dateTime); } #endregion } }