|
|
|
|
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<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<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<TResult>> QueryDto<TResult>(Expression<Func<TEntity, TResult>> expression)
|
|
|
|
|
{
|
|
|
|
|
return await BaseDal.QueryDto(expression);
|
|
|
|
|
}
|
|
|
|
|
public async Task<List<TResult>> QueryDto<TResult>(Expression<Func<TEntity, TResult>> expression, Expression<Func<TEntity, bool>> whereExpression, string orderByFileds)
|
|
|
|
|
{
|
|
|
|
|
return await BaseDal.QueryDto(expression, whereExpression, 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);
|
|
|
|
|
}
|
|
|
|
|
public async Task<List<TResult>> QueryMuch<T, T2, TResult>(Expression<Func<T, T2, object[]>> joinExpression,
|
|
|
|
|
Expression<Func<T, T2, bool>> whereLambda,
|
|
|
|
|
Expression<Func<T, T2, TResult>> selectExpression) where T : class, new()
|
|
|
|
|
{
|
|
|
|
|
return await BaseDal.QueryMuch(joinExpression, whereLambda, selectExpression);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<PageModel<TResult>> QueryMuchPage<T, T2, TResult>(Expression<Func<T, T2, object[]>> joinExpression,
|
|
|
|
|
Expression<Func<T, T2, bool>> whereExpression,
|
|
|
|
|
Expression<Func<T, T2, TResult>> selectExpression,
|
|
|
|
|
int pageIndex = 1,
|
|
|
|
|
int pageSize = 20,
|
|
|
|
|
string strOrderByFileds = null)
|
|
|
|
|
{
|
|
|
|
|
return await BaseDal.QueryMuchPage(joinExpression, whereExpression, selectExpression, pageIndex, pageSize, strOrderByFileds);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<PageModel<TResult>> QueryMuchPageGroup<T, T2, TResult>(Expression<Func<T, T2, object[]>> joinExpression,
|
|
|
|
|
Expression<Func<T, T2, bool>> whereExpression,
|
|
|
|
|
Expression<Func<T, T2, TResult>> selectExpression,
|
|
|
|
|
Expression<Func<T, object>> groupExpression,
|
|
|
|
|
int pageIndex = 1,
|
|
|
|
|
int pageSize = 20,
|
|
|
|
|
string strOrderByFileds = null)
|
|
|
|
|
{
|
|
|
|
|
return await BaseDal.QueryMuchPageGroup(joinExpression, whereExpression, selectExpression, groupExpression, pageIndex, pageSize, strOrderByFileds);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<List<TResult>> QueryMuch<T, T2, T3, TResult>(Expression<Func<T, T2, T3, object[]>> joinExpression,
|
|
|
|
|
Expression<Func<T, T2, T3, bool>> whereLambda,
|
|
|
|
|
Expression<Func<T, T2, T3, TResult>> selectExpression) where T : class, new()
|
|
|
|
|
{
|
|
|
|
|
return await BaseDal.QueryMuch(joinExpression, whereLambda, selectExpression);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<PageModel<TResult>> QueryMuchPage<T, T2, T3, TResult>(Expression<Func<T, T2, T3, object[]>> joinExpression,
|
|
|
|
|
Expression<Func<T, T2, T3, bool>> whereExpression,
|
|
|
|
|
Expression<Func<T, T2, T3, TResult>> selectExpression,
|
|
|
|
|
int pageIndex = 1,
|
|
|
|
|
int pageSize = 20,
|
|
|
|
|
string strOrderByFileds = null)
|
|
|
|
|
{
|
|
|
|
|
return BaseDal.QueryMuchPage(joinExpression, whereExpression, selectExpression, pageIndex, pageSize, strOrderByFileds);
|
|
|
|
|
}
|
|
|
|
|
#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(object operateAnonymousObjects)
|
|
|
|
|
{
|
|
|
|
|
return await BaseDal.Update(operateAnonymousObjects);
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
}
|