using JSMachine.WMS.Domain.Entity; using JSMachine.WMS.Domain.IRepository; using JSMachine.WMS.Domain.Repository; using SqlSugar; using System.Data; using System.Linq.Expressions; namespace JSMachine.WMS.Domain.IRepository { /// /// 基于 SqlSugar 的通用仓储契约,提供聚合根的增删改查和分页能力。 /// /// 仓储管理的聚合根类型。 public interface IBaseRepository where TAggregateRoot : AggregateRoot, IAggregateRoot { /// /// 获取或设置仓储共享的数据库作用域。 /// public static SqlSugarScope DB { get; set; } #region Add /// /// 添加单个实体 /// /// /// Task Add(TAggregateRoot entity, SqlSugarScope sqlSugarScope = null); /// /// 添加单个实体 /// /// /// 要忽略的字段 /// Task Add(TAggregateRoot entity, params string[] ignoreColumns); /// /// 批量插入实体 /// /// /// Task Add(List entities); /// /// 字典方式添加单个实体 /// /// 表名称 /// /// Task Add(string tableName, Dictionary dic); /// /// 添加之前判断指定字段是否存在,不存在则添加 /// /// /// /// Task AddIfNotExist(TAggregateRoot entity, Expression> expression); #endregion #region Delete /// /// 根据Id删除记录 /// /// /// Task DeleteById(Guid id, SqlSugarScope sqlSugarScope = null); /// /// 根据Id批量删除 /// /// /// Task DeleteBatch(Guid[] ids); /// /// 根据实体删除 /// /// /// Task DeleteByEntity(TAggregateRoot aggregateRoot); /// /// 根据实体批量删除 /// /// /// Task DeleteByEntity(List aggregateRoots); /// /// 根据条件删除 /// /// /// Task DeleByExpression(Expression> expression); #endregion #region Edit /// /// 更改单个实体 /// /// /// Task EditSingal(TAggregateRoot aggregateRoot); /// /// 更改单个实体但忽略指定的列 /// /// /// 忽略指定的条件 /// Task EditSingal(TAggregateRoot aggregateRoot, Expression> ignoredColumns); /// /// 更改单个实体但忽略指定的列 /// /// /// 要忽略的列名 /// Task EditSingal(TAggregateRoot aggregateRoot, string[] ignoredColumns); /// /// 更改单个实体中指定的列 /// /// /// 要更改的列名 /// Task EditSingalWithSpecificCols(TAggregateRoot aggregateRoot, string[] columns); /// /// 批量更新 /// /// /// Task EditBatch(List aggregateRoots); /// /// 快速批量更新 /// /// /// Task EditBatchFast(List dtos); /// /// 字典方式更改 /// /// /// /// Task EditByDic(string tableName, Dictionary dic); /// /// 字典方式批量更改 /// /// /// /// Task EditByDic(string tableName, List> dic); #endregion #region Query /// /// 查询所有 /// /// Task> GetAll(); /// /// 查询所有 /// /// Task> GetAll(Expression> orderByExpress, OrderByType orderByType); /// /// 分片查询所有 /// /// /// Task> GetAllFragment(int fragmentSize = 50000); /// /// 分片查询所有(带排序功能) /// /// 要排序的字段 /// 排序方式 /// 分片大小,分片越大效率越高,但是占用的内存也越大,需要合理考虑数据量和硬件性能确定此参数大小 /// Task> GetAllFragment(Expression> orderByExpress, OrderByType orderByType, int fragmentSize = 200); /// /// 查询数量 /// /// Task Count(); /// /// 根据条件查询数量 /// /// /// Task Count(Expression> expression); /// /// 根据主键查询 /// /// /// Task QueryByKey(string key); /// /// 查询满足条件的第一个 /// /// /// Task GetSingalByExpression(Expression> expression); /// /// 查询满足条件的第一个(带排序) /// /// /// /// /// Task GetSingalByExpression( Expression> expression, Expression> orderByExpress, OrderByType orderByType); /// /// 查询满足条件的所有实体 /// /// /// /// Task> GetListByExpression(Expression> expression); /// /// 查询满足条件的所有实体(带排序功能) /// /// /// /// Asc = 0,Desc = 1 /// Task> GetListByExpression(Expression> expression, string filedName, OrderByType orderByType = OrderByType.Desc); /// /// 通过实体查询满足条件的数据 /// /// /// Task> GetListWhereClass(TAggregateRoot aggregateRoot); /// /// 分页查询 /// /// 当前页码 /// Task> QueryByPage(PageQueryCondition pageQueryCondition); /// /// 根据主键批量查询 /// /// /// Task> QueryByIds(Guid[] ids); /// /// 是否存在 /// /// /// Task Exist(Expression> expression); #endregion #region RawSql Sql操作 /// /// sql查询,不带参数 /// /// /// Task> GetBySql(string sql); /// /// sql查询,带参数 参数示例 select * from table where id=@id and name=@name 则字典的key为 "@id" /// /// /// /// Task> GetBySql(string sql, Dictionary sqlParam); /// /// sql查询匿名类型 /// /// /// Task> GetDynamicsBysql(string sql); /// /// sql查询匿名类型,附带参数 参数示例 select * from table where id=@id and name=@name 则字典的key为 "@id" /// /// /// /// Task> GetDynamicsBysql(string sql, Dictionary sqlParam); /// /// 通过sql查询DataTable /// /// /// Task GetDataTableBysql(string sql); /// /// 通过sql查询DataTable, 参数示例 select * from table where id=@id and name=@name 则字典的key为 "@id" /// /// /// /// Task GetDataTableBysql(string sql, Dictionary sqlParam); /// /// 执行原生sql /// /// /// /// Task ExcuteSql(string sql, params SugarParameter[] @params); #endregion #region 事务 /// /// 开始事务 /// /// Task BeginTran(SqlSugarScope sqlSugarScope); /// /// 提交事务 /// /// Task CommitTran(SqlSugarScope sqlSugarScope); /// /// 回滚事务 /// /// Task RollbackTran(SqlSugarScope sqlSugarScope); SqlSugarTransaction UseTranAsync(); #endregion } }