|
@@ -0,0 +1,517 @@
|
|
|
+using SqlSugar;
|
|
|
+using System.Linq.Expressions;
|
|
|
+using XF.Common.Core;
|
|
|
+using XF.Common.Map;
|
|
|
+
|
|
|
+
|
|
|
+namespace XF.Common.Repositories.Base
|
|
|
+{
|
|
|
+ public class AccountingRepository<T> : SimpleClient<T> where T : class ,new()
|
|
|
+ {
|
|
|
+ public AccountingRepository(ISqlSugarClient context = null) : base(context)
|
|
|
+ {
|
|
|
+ if (context == null)
|
|
|
+ {
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static SqlSugarScope Sqlite = SqlSugarHelper.PGSqlite;
|
|
|
+
|
|
|
+ public SimpleClient<T> CurrentDb
|
|
|
+ { get { return new SimpleClient<T>(Sqlite); } }
|
|
|
+
|
|
|
+ #region 通用方法
|
|
|
+
|
|
|
+ public virtual SqlSugarScope GetDB()
|
|
|
+ {
|
|
|
+ return Sqlite;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public virtual List<T> GetList()
|
|
|
+ {
|
|
|
+ return CurrentDb.GetList();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public virtual async Task<List<T>> GetListAsync()
|
|
|
+ {
|
|
|
+ return await CurrentDb.GetListAsync();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public virtual List<T> GetList(Expression<Func<T, bool>> whereExpression)
|
|
|
+ {
|
|
|
+ return CurrentDb.GetList(whereExpression);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public virtual async Task<List<T>> GetListAsync(Expression<Func<T, bool>> whereExpression)
|
|
|
+ {
|
|
|
+ return await CurrentDb.GetListAsync(whereExpression);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public virtual int Count(Expression<Func<T, bool>> whereExpression)
|
|
|
+ {
|
|
|
+ return CurrentDb.Count(whereExpression);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public virtual async Task<int> CountAsync(Expression<Func<T, bool>> whereExpression)
|
|
|
+ {
|
|
|
+ return await CurrentDb.CountAsync(whereExpression);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public virtual PageList<T> GetPageList(Expression<Func<T, bool>> whereExpression, PageModel page)
|
|
|
+ {
|
|
|
+ PageList<T> list = new PageList<T>();
|
|
|
+ list.List = CurrentDb.GetPageList(whereExpression, page);
|
|
|
+ list.PageIndex = page.PageIndex;
|
|
|
+ list.PageSize = page.PageSize;
|
|
|
+ list.TotalCount = page.TotalCount;
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ public virtual PageList<P> GetPageList<P>(Expression<Func<T, bool>> whereExpression, PageModel page)
|
|
|
+ {
|
|
|
+ var result = CurrentDb.GetPageList(whereExpression, page);
|
|
|
+ var pageData = new PageList<P>
|
|
|
+ {
|
|
|
+ TotalCount = page.TotalCount,
|
|
|
+ PageIndex = page.PageIndex,
|
|
|
+ PageSize = page.PageSize,
|
|
|
+ List = result.ToDTOList<P>()
|
|
|
+ };
|
|
|
+ return pageData;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public virtual async Task<PageList<T>> GetPageListAsync(Expression<Func<T, bool>> whereExpression, PageModel page)
|
|
|
+ {
|
|
|
+ PageList<T> list = new PageList<T>();
|
|
|
+ list.List = await CurrentDb.GetPageListAsync(whereExpression, page);
|
|
|
+ list.PageIndex = page.PageIndex;
|
|
|
+ list.PageSize = page.PageSize;
|
|
|
+ list.TotalCount = page.TotalCount;
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ public virtual async Task<PageList<P>> GetPageListAsync<P>(Expression<Func<T, bool>> whereExpression, PageModel page)
|
|
|
+ {
|
|
|
+ var result = await CurrentDb.GetPageListAsync(whereExpression, page);
|
|
|
+ var pageData = new PageList<P>
|
|
|
+ {
|
|
|
+ TotalCount = page.TotalCount,
|
|
|
+ PageIndex = page.PageIndex,
|
|
|
+ PageSize = page.PageSize,
|
|
|
+ List = result.ToDTOList<P>()
|
|
|
+ };
|
|
|
+ return pageData;
|
|
|
+ }
|
|
|
+
|
|
|
+ public virtual PageList<T> GetPageList(Expression<Func<T, bool>> whereExpression, PageModel page, Expression<Func<T, object>> orderByExpression = null, OrderByType orderByType = OrderByType.Asc)
|
|
|
+ {
|
|
|
+ PageList<T> list = new PageList<T>();
|
|
|
+ list.List = CurrentDb.GetPageList(whereExpression, page, orderByExpression, orderByType);
|
|
|
+ list.PageIndex = page.PageIndex;
|
|
|
+ list.PageSize = page.PageSize;
|
|
|
+ list.TotalCount = page.TotalCount;
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ public virtual async Task<PageList<T>> GetPageListAsync(Expression<Func<T, bool>> whereExpression, PageModel page, Expression<Func<T, object>> orderByExpression = null, OrderByType orderByType = OrderByType.Asc)
|
|
|
+ {
|
|
|
+ PageList<T> list = new PageList<T>();
|
|
|
+ list.List = await CurrentDb.GetPageListAsync(whereExpression, page, orderByExpression, orderByType);
|
|
|
+ list.PageIndex = page.PageIndex;
|
|
|
+ list.PageSize = page.PageSize;
|
|
|
+ list.TotalCount = page.TotalCount;
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ public virtual PageList<P> GetPageList<P>(Expression<Func<T, bool>> whereExpression, PageModel page, Expression<Func<T, object>> orderByExpression = null, OrderByType orderByType = OrderByType.Asc)
|
|
|
+ {
|
|
|
+ var result = CurrentDb.GetPageList(whereExpression, page, orderByExpression, orderByType);
|
|
|
+ var pageData = new PageList<P>
|
|
|
+ {
|
|
|
+ TotalCount = page.TotalCount,
|
|
|
+ PageIndex = page.PageIndex,
|
|
|
+ PageSize = page.PageSize,
|
|
|
+ List = result.ToDTOList<P>()
|
|
|
+ };
|
|
|
+ return pageData;
|
|
|
+ }
|
|
|
+
|
|
|
+ public virtual async Task<PageList<P>> GetPageListAsync<P>(Expression<Func<T, bool>> whereExpression, PageModel page, Expression<Func<T, object>> orderByExpression = null, OrderByType orderByType = OrderByType.Asc)
|
|
|
+ {
|
|
|
+ var result = await CurrentDb.GetPageListAsync(whereExpression, page, orderByExpression, orderByType);
|
|
|
+ var pageData = new PageList<P>
|
|
|
+ {
|
|
|
+ TotalCount = page.TotalCount,
|
|
|
+ PageIndex = page.PageIndex,
|
|
|
+ PageSize = page.PageSize,
|
|
|
+ List = result.ToDTOList<P>()
|
|
|
+ };
|
|
|
+ return pageData;
|
|
|
+ }
|
|
|
+
|
|
|
+ public virtual PageList<T> GetPageList(List<IConditionalModel> conditionalList, PageModel page)
|
|
|
+ {
|
|
|
+ PageList<T> list = new PageList<T>();
|
|
|
+ list.List = CurrentDb.GetPageList(conditionalList, page);
|
|
|
+ list.PageIndex = page.PageIndex;
|
|
|
+ list.PageSize = page.PageSize;
|
|
|
+ list.TotalCount = page.TotalCount;
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ public virtual async Task<PageList<T>> GetPageListAsync(List<IConditionalModel> conditionalList, PageModel page)
|
|
|
+ {
|
|
|
+ PageList<T> list = new PageList<T>();
|
|
|
+ list.List = await CurrentDb.GetPageListAsync(conditionalList, page);
|
|
|
+ list.PageIndex = page.PageIndex;
|
|
|
+ list.PageSize = page.PageSize;
|
|
|
+ list.TotalCount = page.TotalCount;
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ public virtual PageList<T> GetPageList(List<IConditionalModel> conditionalList, PageModel page, Expression<Func<T, object>> orderByExpression = null, OrderByType orderByType = OrderByType.Asc)
|
|
|
+ {
|
|
|
+ PageList<T> list = new PageList<T>();
|
|
|
+ list.List = CurrentDb.GetPageList(conditionalList, page, orderByExpression, orderByType);
|
|
|
+ list.PageIndex = page.PageIndex;
|
|
|
+ list.PageSize = page.PageSize;
|
|
|
+ list.TotalCount = page.TotalCount;
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ public virtual async Task<PageList<T>> GetPageListAsync(List<IConditionalModel> conditionalList, PageModel page, Expression<Func<T, object>> orderByExpression = null, OrderByType orderByType = OrderByType.Asc)
|
|
|
+ {
|
|
|
+ PageList<T> list = new PageList<T>();
|
|
|
+ list.List = await CurrentDb.GetPageListAsync(conditionalList, page, orderByExpression, orderByType);
|
|
|
+ list.PageIndex = page.PageIndex;
|
|
|
+ list.PageSize = page.PageSize;
|
|
|
+ list.TotalCount = page.TotalCount;
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public virtual T GetById(dynamic id)
|
|
|
+ {
|
|
|
+ return CurrentDb.GetById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public virtual async Task<T> GetByIdAsync(dynamic id)
|
|
|
+ {
|
|
|
+ return await CurrentDb.GetByIdAsync(id);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public virtual T GetSingle(Expression<Func<T, bool>> whereExpression)
|
|
|
+ {
|
|
|
+ return CurrentDb.GetSingle(whereExpression);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public virtual async Task<T> GetSingleAsync(Expression<Func<T, bool>> whereExpression)
|
|
|
+ {
|
|
|
+ return await CurrentDb.GetSingleAsync(whereExpression);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public virtual T GetFirst(Expression<Func<T, bool>> whereExpression)
|
|
|
+ {
|
|
|
+ return GetDB().Queryable<T>().First(whereExpression);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public virtual async Task<T> GetFirstAsync(Expression<Func<T, bool>> whereExpression)
|
|
|
+ {
|
|
|
+ return await GetDB().Queryable<T>().FirstAsync(whereExpression);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public virtual bool Insert(T obj)
|
|
|
+ {
|
|
|
+ return CurrentDb.Insert(obj);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public virtual async Task<bool> InsertAsync(T obj)
|
|
|
+ {
|
|
|
+ return await CurrentDb.InsertAsync(obj);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public virtual bool InsertRange(List<T> objs)
|
|
|
+ {
|
|
|
+ return CurrentDb.InsertRange(objs);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public virtual async Task<bool> InsertRangeAsync(List<T> objs)
|
|
|
+ {
|
|
|
+ return await CurrentDb.InsertRangeAsync(objs);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public virtual int InsertReturnIdentity(T obj)
|
|
|
+ {
|
|
|
+ return CurrentDb.InsertReturnIdentity(obj);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public virtual async Task<int> InsertReturnIdentityAsync(T obj)
|
|
|
+ {
|
|
|
+ return await CurrentDb.InsertReturnIdentityAsync(obj);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public virtual long InsertReturnBigIdentity(T obj)
|
|
|
+ {
|
|
|
+ return CurrentDb.InsertReturnBigIdentity(obj);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public virtual async Task<long> InsertReturnBigIdentityAsync(T obj)
|
|
|
+ {
|
|
|
+ return await CurrentDb.InsertReturnBigIdentityAsync(obj);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public virtual bool DeleteByIds(dynamic[] ids)
|
|
|
+ {
|
|
|
+ return CurrentDb.DeleteByIds(ids);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public virtual async Task<bool> DeleteByIdsAsync(dynamic[] ids)
|
|
|
+ {
|
|
|
+ return await CurrentDb.DeleteByIdsAsync(ids);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public virtual bool Delete(dynamic id)
|
|
|
+ {
|
|
|
+ return CurrentDb.DeleteById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public virtual async Task<bool> DeleteAsync(dynamic id)
|
|
|
+ {
|
|
|
+ return await CurrentDb.DeleteByIdAsync(id);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public virtual bool Delete(T obj)
|
|
|
+ {
|
|
|
+ return CurrentDb.Delete(obj);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public virtual async Task<bool> DeleteAsync(T obj)
|
|
|
+ {
|
|
|
+ return await CurrentDb.DeleteAsync(obj);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public virtual bool Delete(Expression<Func<T, bool>> whereExpression)
|
|
|
+ {
|
|
|
+ return CurrentDb.Delete(whereExpression);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public virtual async Task<bool> DeleteAsync(Expression<Func<T, bool>> whereExpression)
|
|
|
+ {
|
|
|
+ return await CurrentDb.DeleteAsync(whereExpression);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public virtual bool Update(T obj)
|
|
|
+ {
|
|
|
+ return CurrentDb.Update(obj);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public virtual async Task<bool> UpdateAsync(T obj)
|
|
|
+ {
|
|
|
+ return await CurrentDb.UpdateAsync(obj);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public virtual bool UpdateRange(List<T> objs)
|
|
|
+ {
|
|
|
+ return CurrentDb.UpdateRange(objs);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public virtual async Task<bool> UpdateRangeAsync(List<T> objs)
|
|
|
+ {
|
|
|
+ return await CurrentDb.UpdateRangeAsync(objs);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public virtual bool IsAny(Expression<Func<T, bool>> whereExpression)
|
|
|
+ {
|
|
|
+ return CurrentDb.IsAny(whereExpression);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public virtual async Task<bool> IsAnyAsync(Expression<Func<T, bool>> whereExpression)
|
|
|
+ {
|
|
|
+ return await CurrentDb.IsAnyAsync(whereExpression);
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion 通用方法
|
|
|
+ }
|
|
|
+}
|