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#

9 months ago
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;
9 months ago
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;
9 months ago
#region 查询
9 months ago
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);
}
9 months ago
public async Task<TEntity> QueryFirst(Expression<Func<TEntity, bool>> whereExpression)
{
9 months ago
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);
}
9 months ago
public async Task<TEntity> QueryFirstInclude<TReturn>(Expression<Func<TEntity, bool>> whereExpression, Expression<Func<TEntity, List<TReturn>>> include)
{
9 months ago
return await BaseDal.QueryFirstInclude(whereExpression, include);
}
9 months ago
public async Task<List<TEntity>> Query()
{
9 months ago
return await BaseDal.Query();
}
9 months ago
public async Task<List<TEntity>> Query(Expression<Func<TEntity, bool>> whereExpression)
{
9 months ago
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);
}
9 months ago
public async Task<List<TEntity>> Query(Expression<Func<TEntity, bool>> whereExpression, Expression<Func<TEntity, object>> orderByExpression, bool isAsc = true)
{
9 months ago
return await BaseDal.Query(whereExpression, orderByExpression, isAsc);
}
9 months ago
public async Task<List<TEntity>> Query(Expression<Func<TEntity, bool>> whereExpression, string orderByFileds)
{
9 months ago
return await BaseDal.Query(whereExpression, orderByFileds);
}
9 months ago
public async Task<List<TEntity>> Query(string where, string orderByFileds)
{
9 months ago
return await BaseDal.Query(where, orderByFileds);
}
9 months ago
public async Task<List<TEntity>> QueryTop(Expression<Func<TEntity, bool>> whereExpression, int top, string orderByFileds)
{
9 months ago
return await BaseDal.QueryTop(whereExpression, top, orderByFileds);
}
9 months ago
public async Task<List<TEntity>> QueryTop(string where, int top, string orderByFileds)
{
9 months ago
return await BaseDal.QueryTop(where, top, orderByFileds);
}
9 months ago
public async Task<List<TEntity>> QueryPage(Expression<Func<TEntity, bool>> whereExpression, int pageIndex, int pageSize, string orderByFileds)
{
9 months ago
return await BaseDal.QueryPage(whereExpression, pageIndex, pageSize, orderByFileds);
}
9 months ago
public async Task<List<TEntity>> QueryPage(string where, int pageIndex, int pageSize, string orderByFileds)
{
9 months ago
return await BaseDal.QueryPage(where, pageIndex, pageSize, orderByFileds);
}
9 months ago
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)
{
9 months ago
return await BaseDal.QueryPageModel(whereExpression, pageIndex, pageSize, orderByExpression, isAsc);
}
9 months ago
public async Task<PageModel<TEntity>> QueryPageModel(Expression<Func<TEntity, bool>> whereExpression, int pageIndex = 1, int pageSize = 20, string orderByFileds = null)
{
9 months ago
return await BaseDal.QueryPageModel(whereExpression, pageIndex, pageSize, orderByFileds);
}
9 months ago
public async Task<PageModel<TEntity>> QueryPageModel(Expression<Func<TEntity, bool>> whereExpression, PaginationModel pagination)
{
return await BaseDal.QueryPageModel(whereExpression, pagination.pageIndex, pagination.pageSize, pagination.orderByFileds);
}
9 months ago
public async Task<List<TEntity>> QuerySql(string sql, SugarParameter[] parameters = null)
{
9 months ago
return await BaseDal.QuerySql(sql, parameters);
}
9 months ago
public async Task<DataTable> QueryTable(string sql, SugarParameter[] parameters = null)
{
9 months ago
return await BaseDal.QueryTable(sql, parameters);
}
9 months ago
#endregion
9 months ago
#region 新增
9 months ago
public IInsertable<TEntity> AsInsertable(TEntity model)
{
return Db.Insertable(model);
}
public IInsertable<TEntity> AsInsertable(List<TEntity> listEntity)
9 months ago
{
return Db.Insertable(listEntity);
9 months ago
}
9 months ago
public async Task<long> Add(TEntity entity)
{
9 months ago
return await BaseDal.Add(entity);
}
9 months ago
public async Task<List<long>> Add(List<TEntity> listEntity)
{
return await BaseDal.Add(listEntity);
9 months ago
}
9 months ago
#endregion
9 months ago
#region 更新
9 months ago
public IUpdateable<TEntity> AsUpdateable(TEntity model)
{
return Db.Updateable(model);
}
8 months ago
public IUpdateable<TEntity> AsUpdateable()
{
return Db.Updateable<TEntity>();
}
9 months ago
public IUpdateable<TEntity> AsUpdateable(params TEntity[] entities)
{
return Db.Updateable(entities);
}
9 months ago
public async Task<bool> Update(TEntity entity)
{
return await BaseDal.Update(entity);
}
9 months ago
public async Task<bool> Update(List<TEntity> entity)
{
return await BaseDal.Update(entity);
}
9 months ago
public async Task<bool> Update(TEntity entity, string where)
{
9 months ago
return await BaseDal.Update(entity, where);
}
9 months ago
public async Task<bool> Update(TEntity entity, List<string> lstColumns = null, List<string> lstIgnoreColumns = null, string where = "")
{
9 months ago
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)
9 months ago
{
return await BaseDal.Update(columns, where);
}
9 months ago
#endregion
9 months ago
#region 删除
public async Task<bool> Delete(Expression<Func<TEntity, bool>> whereExpression)
{
return await BaseDal.Delete(whereExpression);
}
9 months ago
public async Task<bool> Delete(TEntity entity)
{
9 months ago
return await BaseDal.Delete(entity);
}
public async Task<bool> DeleteById(object id)
{
return await BaseDal.DeleteById(id);
}
9 months ago
public async Task<bool> DeleteByIds(object[] ids)
{
return await BaseDal.DeleteByIds(ids);
}
#endregion
9 months ago
#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
}
}