using System.Linq.Expressions; using Repository; using SqlSugar; namespace Service; public class BaseServices where T : class, new() { //public IBaseRepository baseDal = new BaseRepository(); public BaseRepository BaseDal; //通过在子类的构造函数中注入,这里是基类,不用构造函数 /// /// 根据主值查询单条数据 /// /// 主键值 /// 是否使用WITH(NOLOCK) /// 泛型实体· public T QueryById(object pkValue, bool blUseNoLock = false) { return BaseDal.QueryById(pkValue, blUseNoLock); } /// /// 根据主值查询单条数据 /// /// id(必须指定主键特性 [SugarColumn(IsPrimaryKey=true)]),如果是联合主键,请使用Where条件 /// 是否使用WITH(NOLOCK) /// 数据实体 public async Task QueryByIdAsync(object objId, bool blUseNoLock = false) { return await BaseDal.QueryByIdAsync(objId, blUseNoLock); } /// /// 根据主值列表查询单条数据 /// /// id列表(必须指定主键特性 [SugarColumn(IsPrimaryKey=true)]),如果是联合主键,请使用Where条件 /// 是否使用WITH(NOLOCK) /// 数据实体列表 public List QueryByIDs(object[] lstIds, bool blUseNoLock = false) { return BaseDal.QueryByIDs(lstIds, blUseNoLock); } /// /// 根据主值列表查询单条数据 /// /// id列表(必须指定主键特性 [SugarColumn(IsPrimaryKey=true)]),如果是联合主键,请使用Where条件 /// 是否使用WITH(NOLOCK) /// 数据实体列表 public async Task> QueryByIDsAsync(object[] lstIds, bool blUseNoLock = false) { return await BaseDal.QueryByIDsAsync(lstIds, blUseNoLock); } /// /// 根据主值列表查询单条数据 /// /// id列表(必须指定主键特性 [SugarColumn(IsPrimaryKey=true)]),如果是联合主键,请使用Where条件 /// 是否使用WITH(NOLOCK) /// 数据实体列表 public List QueryByIDs(int[] lstIds, bool blUseNoLock = false) { return BaseDal.QueryByIDs(lstIds, blUseNoLock); } /// /// 根据主值列表查询单条数据 /// /// id列表(必须指定主键特性 [SugarColumn(IsPrimaryKey=true)]),如果是联合主键,请使用Where条件 /// 是否使用WITH(NOLOCK) /// 数据实体列表 public async Task> QueryByIDsAsync(int[] lstIds, bool blUseNoLock = false) { return await BaseDal.QueryByIDsAsync(lstIds, blUseNoLock); } /// /// 查询表单所有数据(无分页,请慎用) /// /// 是否使用WITH(NOLOCK) /// public List Query(bool blUseNoLock = false) { var list = BaseDal.Query(blUseNoLock); return list; } /// /// 查询表单所有数据(无分页,请慎用) /// /// 是否使用WITH(NOLOCK) /// public async Task> QueryAsync(bool blUseNoLock = false) { return await BaseDal.QueryAsync(blUseNoLock); } /// /// 根据条件查询数据 /// /// 条件 /// 排序字段,如name asc,age desc /// 是否使用WITH(NOLOCK) /// 泛型实体集合 public List QueryListByClause(string strWhere, string orderBy = "", bool blUseNoLock = false) { return BaseDal.QueryListByClause(strWhere, orderBy, blUseNoLock); } /// /// 根据条件查询数据 /// /// 条件 /// 排序字段,如name asc,age desc /// 是否使用WITH(NOLOCK) /// 泛型实体集合 public async Task> QueryListByClauseAsync(string strWhere, string orderBy = "", bool blUseNoLock = false) { return await BaseDal.QueryListByClauseAsync(strWhere, orderBy, blUseNoLock); } /// /// 根据条件查询数据 /// /// 条件表达式树 /// 排序字段,如name asc,age desc /// 是否使用WITH(NOLOCK) /// 泛型实体集合 public List QueryListByClause(Expression> predicate, string orderBy = "", bool blUseNoLock = false) { return BaseDal.QueryListByClause(predicate, orderBy, blUseNoLock); } /// /// 根据条件查询数据 /// /// 条件表达式树 /// 排序字段,如name asc,age desc /// 是否使用WITH(NOLOCK) /// 泛型实体集合 public async Task> QueryListByClauseAsync(Expression> predicate, string orderBy = "", bool blUseNoLock = false) { return await BaseDal.QueryListByClauseAsync(predicate, orderBy, blUseNoLock); } /// /// 根据条件查询数据 /// /// 条件表达式树 /// 排序字段 /// 排序顺序 /// 是否使用WITH(NOLOCK) /// 泛型实体集合 public List QueryListByClause(Expression> predicate, Expression> orderByPredicate, OrderByType orderByType, bool blUseNoLock = false) { return BaseDal.QueryListByClause(predicate, orderByPredicate, orderByType, blUseNoLock); } /// /// 根据条件查询数据 /// /// 条件表达式树 /// 排序字段 /// 排序顺序 /// 是否使用WITH(NOLOCK) /// 泛型实体集合 public async Task> QueryListByClauseAsync(Expression> predicate, Expression> orderByPredicate, OrderByType orderByType, bool blUseNoLock = false) { return await BaseDal.QueryListByClauseAsync(predicate, orderByPredicate, orderByType, blUseNoLock); } /// /// 根据条件查询一定数量数据 /// /// 条件表达式树 /// 获取数量 /// 排序字段 /// 排序顺序 /// 是否使用WITH(NOLOCK) /// public List QueryListByClause(Expression> predicate, int take, Expression> orderByPredicate, OrderByType orderByType, bool blUseNoLock = false) { return BaseDal.QueryListByClause(predicate, take, orderByPredicate, orderByType, blUseNoLock); } /// /// 根据条件查询一定数量数据 /// /// 条件表达式树 /// 获取数量 /// 排序字段 /// 排序顺序 /// 是否使用WITH(NOLOCK) /// public async Task> QueryListByClauseAsync(Expression> predicate, int take, Expression> orderByPredicate, OrderByType orderByType, bool blUseNoLock = false) { return await BaseDal.QueryListByClauseAsync(predicate, take, orderByPredicate, orderByType, blUseNoLock); } /// /// 根据条件查询一定数量数据 /// /// 条件表达式树 /// 获取数量 /// 排序字段,如name asc,age desc /// 是否使用WITH(NOLOCK) /// public List QueryListByClause(Expression> predicate, int take, string strOrderByFileds = "", bool blUseNoLock = false) { return BaseDal.QueryListByClause(predicate, take, strOrderByFileds, blUseNoLock); } /// /// 根据条件查询一定数量数据 /// /// 条件表达式树 /// 获取数量 /// 排序字段,如name asc,age desc /// 是否使用WITH(NOLOCK) /// public async Task> QueryListByClauseAsync(Expression> predicate, int take, string strOrderByFileds = "", bool blUseNoLock = false) { return await BaseDal.QueryListByClauseAsync(predicate, take, strOrderByFileds, blUseNoLock); } /// /// 根据条件查询数据 /// /// 条件表达式树 /// 是否使用WITH(NOLOCK) /// public T QueryByClause(Expression> predicate, bool blUseNoLock = false) { return BaseDal.QueryByClause(predicate, blUseNoLock); } /// /// 根据条件查询数据 /// /// 条件表达式树 /// 是否使用WITH(NOLOCK) /// public async Task QueryByClauseAsync(Expression> predicate, bool blUseNoLock = false) { return await BaseDal.QueryByClauseAsync(predicate, blUseNoLock); } /// /// 根据条件查询数据 /// /// 条件表达式树 /// 排序字段 /// 排序顺序 /// 是否使用WITH(NOLOCK) /// public T QueryByClause(Expression> predicate, Expression> orderByPredicate, OrderByType orderByType, bool blUseNoLock = false) { var entity = BaseDal.QueryByClause(predicate, orderByPredicate, orderByType, blUseNoLock); return entity; } /// /// 根据条件查询数据 /// /// 条件表达式树 /// 排序字段 /// 排序顺序 /// 是否使用WITH(NOLOCK) /// public async Task QueryByClauseAsync(Expression> predicate, Expression> orderByPredicate, OrderByType orderByType, bool blUseNoLock = false) { return await BaseDal.QueryByClauseAsync(predicate, orderByPredicate, orderByType, blUseNoLock); } /// /// 写入实体数据 /// /// 实体数据 /// public T Insert(T entity) { return BaseDal.Insert(entity); } /// /// 写入实体数据 /// /// 实体数据 /// public async Task InsertAsync(T entity) { return await BaseDal.InsertAsync(entity); } /// /// 写入实体数据 /// /// 实体数据 /// 插入的列 /// public T Insert(T entity, Expression> insertColumns = null) { return BaseDal.Insert(entity, insertColumns); } /// /// 写入实体数据 /// /// 实体数据 /// 插入的列 /// public async Task InsertAsync(T entity, Expression> insertColumns = null) { return await BaseDal.InsertAsync(entity, insertColumns); } /// /// 写入实体数据 /// /// 实体类 /// 需插入的字段 /// public bool InsertGuid(T entity, Expression> insertColumns = null) { return BaseDal.InsertGuid(entity, insertColumns); } /// /// 写入实体数据 /// /// 实体类 /// 需插入的字段 /// public async Task InsertGuidAsync(T entity, Expression> insertColumns = null) { return await InsertGuidAsync(entity, insertColumns); } /// /// 批量写入实体数据 /// /// 实体类 /// public bool Insert(List entity) { return BaseDal.Insert(entity); } /// /// 批量写入实体数据 /// /// 实体类 /// public async Task InsertAsync(List entity) { return await BaseDal.InsertAsync(entity); } /// /// 批量写入实体数据 /// /// 实体类 /// public async Task InsertCommandAsync(List entity) { return await BaseDal.InsertCommandAsync(entity); } /// /// 批量更新实体数据 /// /// /// public bool Update(List entity) { return BaseDal.Update(entity); } /// /// 批量更新实体数据 /// /// /// public async Task UpdateAsync(List entity) { return await BaseDal.UpdateAsync(entity); } /// /// 更新实体数据 /// /// /// public bool Update(T entity) { return BaseDal.Update(entity); } /// /// 更新实体数据 /// /// /// public async Task UpdateAsync(T entity) { return await BaseDal.UpdateAsync(entity); } /// /// 根据手写条件更新 /// /// /// /// public bool Update(T entity, string strWhere) { return BaseDal.Update(entity, strWhere); } /// /// 根据手写条件更新 /// /// /// /// public async Task UpdateAsync(T entity, string strWhere) { return await BaseDal.UpdateAsync(entity, strWhere); } /// /// 根据手写sql语句更新数据 /// /// /// /// public bool Update(string strSql, SugarParameter[] parameters = null) { return BaseDal.Update(strSql, parameters); } /// /// 根据手写sql语句更新数据 /// /// /// /// public async Task UpdateAsync(string strSql, SugarParameter[] parameters = null) { return await BaseDal.UpdateAsync(strSql, parameters); } /// /// 更新某个字段 /// /// lamdba表达式,如it => new Student() { Name = "a", CreateTime = DateTime.Now } /// lamdba判断 /// public bool Update(Expression> columns, Expression> where) { return BaseDal.Update(columns, where); } /// /// 更新某个字段 /// /// lamdba表达式,如it => new Student() { Name = "a", CreateTime = DateTime.Now } /// lamdba判断 /// public async Task UpdateAsync(Expression> columns, Expression> where) { return await BaseDal.UpdateAsync(columns, where); } /// /// 根据条件更新 /// /// /// /// /// /// public async Task UpdateAsync(T entity, List lstColumns = null, List lstIgnoreColumns = null, string strWhere = "") { return await BaseDal.UpdateAsync(entity, lstColumns, lstIgnoreColumns, strWhere); } /// /// 根据条件更新 /// /// /// /// /// /// public bool Update(T entity, List lstColumns = null, List lstIgnoreColumns = null, string strWhere = "") { return BaseDal.Update(entity, lstColumns, lstIgnoreColumns, strWhere); } /// /// 删除数据 /// /// 实体类 /// public bool Delete(T entity) { return BaseDal.Delete(entity); } /// /// 删除数据 /// /// 实体类 /// public async Task DeleteAsync(T entity) { return await BaseDal.DeleteAsync(entity); } /// /// 删除数据 /// /// 实体类 /// public bool Delete(IEnumerable entity) { return BaseDal.Delete(entity); } /// /// 删除数据 /// /// 实体类 /// public async Task DeleteAsync(IEnumerable entity) { return await BaseDal.DeleteAsync(entity); } /// /// 删除数据 /// /// 过滤条件 /// public bool Delete(Expression> where) { return BaseDal.Delete(where); } /// /// 删除数据 /// /// 过滤条件 /// public async Task DeleteAsync(Expression> where) { return await BaseDal.DeleteAsync(where); } /// /// 删除指定ID的数据 /// /// /// public bool DeleteById(object id) { return BaseDal.DeleteById(id); } /// /// 删除指定ID的数据 /// /// /// public async Task DeleteByIdAsync(object id) { return await BaseDal.DeleteByIdAsync(id); } /// /// 删除指定ID集合的数据(批量删除) /// /// /// public bool DeleteByIds(int[] ids) { return BaseDal.DeleteByIds(ids); } /// /// 删除指定ID集合的数据(批量删除) /// /// /// public async Task DeleteByIdsAsync(int[] ids) { return await BaseDal.DeleteByIdsAsync(ids); } /// /// 删除指定ID集合的数据(批量删除) /// /// /// public bool DeleteByIds(long[] ids) { return BaseDal.DeleteByIds(ids); } /// /// 删除指定ID集合的数据(批量删除) /// /// /// public async Task DeleteByIdsAsync(long[] ids) { return await BaseDal.DeleteByIdsAsync(ids); } /// /// 删除指定ID集合的数据(批量删除) /// /// /// public bool DeleteByIds(Guid[] ids) { return BaseDal.DeleteByIds(ids); } /// /// 删除指定ID集合的数据(批量删除) /// /// /// public async Task DeleteByIdsAsync(Guid[] ids) { return await BaseDal.DeleteByIdsAsync(ids); } /// /// 删除指定ID集合的数据(批量删除) /// /// /// public bool DeleteByIds(string[] ids) { return BaseDal.DeleteByIds(ids); } /// /// 删除指定ID集合的数据(批量删除) /// /// /// public async Task DeleteByIdsAsync(string[] ids) { return await BaseDal.DeleteByIdsAsync(ids); } /// /// 删除指定ID集合的数据(批量删除) /// /// /// public bool DeleteByIds(List ids) { return BaseDal.DeleteByIds(ids); } /// /// 删除指定ID集合的数据(批量删除) /// /// /// public async Task DeleteByIdsAsync(List ids) { return await BaseDal.DeleteByIdsAsync(ids); } /// /// 删除指定ID集合的数据(批量删除) /// /// /// public bool DeleteByIds(List ids) { return BaseDal.DeleteByIds(ids); } /// /// 删除指定ID集合的数据(批量删除) /// /// /// public async Task DeleteByIdsAsync(List ids) { return await BaseDal.DeleteByIdsAsync(ids); } /// /// 删除指定ID集合的数据(批量删除) /// /// /// public bool DeleteByIds(List ids) { return BaseDal.DeleteByIds(ids); } /// /// 删除指定ID集合的数据(批量删除) /// /// /// public async Task DeleteByIdsAsync(List ids) { return await BaseDal.DeleteByIdsAsync(ids); } /// /// 删除指定ID集合的数据(批量删除) /// /// /// public bool DeleteByIds(List ids) { return BaseDal.DeleteByIds(ids); } /// /// 删除指定ID集合的数据(批量删除) /// /// /// public async Task DeleteByIdsAsync(List ids) { return await BaseDal.DeleteByIdsAsync(ids); } /// /// 判断数据是否存在 /// /// 条件表达式树 /// 是否使用WITH(NOLOCK) /// public bool Exists(Expression> predicate, bool blUseNoLock = false) { return BaseDal.Exists(predicate, blUseNoLock); } /// /// 判断数据是否存在 /// /// 条件表达式树 /// 是否使用WITH(NOLOCK) /// public async Task ExistsAsync(Expression> predicate, bool blUseNoLock = false) { return await BaseDal.ExistsAsync(predicate, blUseNoLock); } /// /// 获取数据总数 /// /// 条件表达式树 /// 是否使用WITH(NOLOCK) /// public int GetCount(Expression> predicate, bool blUseNoLock = false) { return BaseDal.GetCount(predicate, blUseNoLock); } /// /// 获取数据总数 /// /// 条件表达式树 /// 是否使用WITH(NOLOCK) /// public async Task GetCountAsync(Expression> predicate, bool blUseNoLock = false) { return await BaseDal.GetCountAsync(predicate, blUseNoLock); } /// /// 获取数据某个字段的合计 /// /// 条件表达式树 /// 是否使用WITH(NOLOCK) /// 字段 /// public int GetSum(Expression> predicate, Expression> field, bool blUseNoLock = false) { return BaseDal.GetSum(predicate, field, blUseNoLock); } /// /// 获取数据某个字段的合计 /// /// 条件表达式树 /// 是否使用WITH(NOLOCK) /// 字段 /// public async Task GetSumAsync(Expression> predicate, Expression> field, bool blUseNoLock = false) { return await BaseDal.GetSumAsync(predicate, field, blUseNoLock); } /// /// 获取数据某个字段的合计 /// /// 条件表达式树 /// 是否使用WITH(NOLOCK) /// 字段 /// public decimal GetSum(Expression> predicate, Expression> field, bool blUseNoLock = false) { return BaseDal.GetSum(predicate, field, blUseNoLock); } /// /// 获取数据某个字段的合计 /// /// 条件表达式树 /// 是否使用WITH(NOLOCK) /// 字段 /// public async Task GetSumAsync(Expression> predicate, Expression> field, bool blUseNoLock = false) { return await BaseDal.GetSumAsync(predicate, field, blUseNoLock); } /// /// 获取数据某个字段的合计 /// /// 条件表达式树 /// 是否使用WITH(NOLOCK) /// 字段 /// public float GetSum(Expression> predicate, Expression> field, bool blUseNoLock = false) { return BaseDal.GetSum(predicate, field, blUseNoLock); } /// /// 获取数据某个字段的合计 /// /// 条件表达式树 /// 是否使用WITH(NOLOCK) /// 字段 /// public async Task GetSumAsync(Expression> predicate, Expression> field, bool blUseNoLock = false) { return await BaseDal.GetSumAsync(predicate, field, blUseNoLock); } /// /// 查询-多表查询 /// /// 实体1 /// 实体2 /// 返回对象 /// 关联表达式 (join1,join2) => new object[] {JoinType.Left,join1.UserNo==join2.UserNo} /// 返回表达式 (s1, s2) => new { Id =s1.UserNo, Id1 = s2.UserNo} /// 查询表达式 (w1, w2) =>w1.UserNo == "") /// 是否使用WITH(NOLOCK) /// public List QueryMuch( Expression> joinExpression, Expression> selectExpression, Expression> whereLambda = null, bool blUseNoLock = false) where T1 : class, new() { return BaseDal.QueryMuch(joinExpression, selectExpression, whereLambda, blUseNoLock); } /// /// 查询-多表查询 /// /// 实体1 /// 实体2 /// 返回对象 /// 关联表达式 (join1,join2) => new object[] {JoinType.Left,join1.UserNo==join2.UserNo} /// 返回表达式 (s1, s2) => new { Id =s1.UserNo, Id1 = s2.UserNo} /// 查询表达式 (w1, w2) =>w1.UserNo == "") /// 是否使用WITH(NOLOCK) /// public async Task> QueryMuchAsync( Expression> joinExpression, Expression> selectExpression, Expression> whereLambda = null, bool blUseNoLock = false) where T1 : class, new() { return await BaseDal.QueryMuchAsync(joinExpression, selectExpression, whereLambda, blUseNoLock); } /// /// 查询-多表查询 /// /// 实体1 /// 实体2 /// 返回对象 /// 关联表达式 (join1,join2) => new object[] {JoinType.Left,join1.UserNo==join2.UserNo} /// 返回表达式 (s1, s2) => new { Id =s1.UserNo, Id1 = s2.UserNo} /// 查询表达式 (w1, w2) =>w1.UserNo == "") /// 是否使用WITH(NOLOCK) /// public TResult QueryMuchFirst( Expression> joinExpression, Expression> selectExpression, Expression> whereLambda = null, bool blUseNoLock = false) where T1 : class, new() { return BaseDal.QueryMuchFirst(joinExpression, selectExpression, whereLambda, blUseNoLock); } /// /// 查询-多表查询 /// /// 实体1 /// 实体2 /// 返回对象 /// 关联表达式 (join1,join2) => new object[] {JoinType.Left,join1.UserNo==join2.UserNo} /// 返回表达式 (s1, s2) => new { Id =s1.UserNo, Id1 = s2.UserNo} /// 查询表达式 (w1, w2) =>w1.UserNo == "") /// 是否使用WITH(NOLOCK) /// public async Task QueryMuchFirstAsync( Expression> joinExpression, Expression> selectExpression, Expression> whereLambda = null, bool blUseNoLock = false) where T1 : class, new() { return await BaseDal.QueryMuchFirstAsync(joinExpression, selectExpression, whereLambda, blUseNoLock); } /// /// 查询-三表查询 /// /// 实体1 /// 实体2 /// 实体3 /// 返回对象 /// 关联表达式 (join1,join2) => new object[] {JoinType.Left,join1.UserNo==join2.UserNo} /// 返回表达式 (s1, s2) => new { Id =s1.UserNo, Id1 = s2.UserNo} /// 查询表达式 (w1, w2) =>w1.UserNo == "") /// 是否使用WITH(NOLOCK) /// public List QueryMuch( Expression> joinExpression, Expression> selectExpression, Expression> whereLambda = null, bool blUseNoLock = false) where T1 : class, new() { return BaseDal.QueryMuch(joinExpression, selectExpression, whereLambda, blUseNoLock); } /// /// 查询-4表查询 /// /// 实体1 /// 实体2 /// 实体3 /// 返回对象 /// 关联表达式 (join1,join2) => new object[] {JoinType.Left,join1.UserNo==join2.UserNo} /// 返回表达式 (s1, s2) => new { Id =s1.UserNo, Id1 = s2.UserNo} /// 查询表达式 (w1, w2) =>w1.UserNo == "") /// 是否使用WITH(NOLOCK) /// public List QueryMuch( Expression> joinExpression, Expression> selectExpression, Expression> whereLambda = null, bool blUseNoLock = false) where T1 : class, new() { return BaseDal.QueryMuch(joinExpression, selectExpression, whereLambda, blUseNoLock); } /// /// 查询-三表查询 /// /// 实体1 /// 实体2 /// 实体3 /// 返回对象 /// 关联表达式 (join1,join2) => new object[] {JoinType.Left,join1.UserNo==join2.UserNo} /// 返回表达式 (s1, s2) => new { Id =s1.UserNo, Id1 = s2.UserNo} /// 查询表达式 (w1, w2) =>w1.UserNo == "") /// 是否使用WITH(NOLOCK) /// public async Task> QueryMuchAsync( Expression> joinExpression, Expression> selectExpression, Expression> whereLambda = null, bool blUseNoLock = false) where T1 : class, new() { return await BaseDal.QueryMuchAsync(joinExpression, selectExpression, whereLambda, blUseNoLock); } /// /// 执行sql语句并返回List /// /// /// /// /// public List SqlQuery(string sql, List parameters) { return BaseDal.SqlQuery(sql, parameters); } /// /// 执行sql语句并返回List /// /// /// /// public async Task> SqlQueryable(string sql) { return await BaseDal.SqlQueryable(sql); } }