using System; using System.Collections.Generic; using System.Data; using System.Threading.Tasks; using Znyc.Admin.Commons.Dtos; using Znyc.Admin.Commons.Entitys; using Znyc.Admin.Commons.Pages; namespace Znyc.Admin.Commons.IServices { /// /// 泛型应用服务接口 /// /// /// /// public interface IService : IDisposable where T : Entity where TODto : class { /// /// 同步查询单个实体。 /// /// 主键 /// T Get(TKey id); /// /// 同步查询单个实体。 /// /// 主键 /// TODto GetOutDto(TKey id); /// /// 异步查询单个实体。 /// /// 主键 /// Task GetOutDtoAsync(TKey id); /// /// 异步查询单个实体。 /// /// 主键 /// Task GetAsync(TKey id); /// /// 同步查询单个实体。 /// /// 查询条件 /// 事务对象 /// T GetWhere(string where, IDbTransaction trans = null); /// /// 同步查询单个实体。 /// /// 查询条件 /// 事务对象 /// TODto GetOutDtoWhere(string where, IDbTransaction trans = null); /// /// 异步查询单个实体。 /// /// 查询条件 /// 事务对象 /// Task GetWhereAsync(string where, IDbTransaction trans = null); /// /// 异步查询单个实体。 /// /// 查询条件 /// 事务对象 /// Task GetOutDtoWhereAsync(string where, IDbTransaction trans = null); /// /// 同步查询所有实体。 /// /// 事务对象 /// IEnumerable GetAll(IDbTransaction trans = null); /// /// 异步查询所有实体。 /// /// 事务对象 /// Task> GetAllAsync(IDbTransaction trans = null); /// /// 根据查询条件查询数据 /// /// 查询条件 /// 事务对象 /// IEnumerable GetListWhere(string where = null, IDbTransaction trans = null); /// /// 异步根据查询条件查询数据 /// /// 查询条件 /// 事务对象 /// Task> GetListWhereAsync(string where = null, IDbTransaction trans = null); /// /// 根据查询条件查询前多少条数据 /// /// 多少条数据 /// 查询条件 /// 事务对象 /// IEnumerable GetListTopWhere(int top, string where = null, IDbTransaction trans = null); /// /// 根据查询条件查询前多少条数据 /// /// 多少条数据 /// 查询条件 /// 事务对象 /// Task> GetListTopWhereAsync(int top, string where = null, IDbTransaction trans = null); /// /// 同步新增实体。 /// /// 实体 /// 事务对象 /// long Insert(T entity, IDbTransaction trans = null); /// /// 异步新增实体。 /// /// 实体 /// 事务对象 /// Task InsertAsync(T entity, IDbTransaction trans = null); /// /// 异步新增实体返回主键 /// /// /// /// Task InsertReturnPrimaryKeyAsync(T entity, IDbTransaction trans = null); /// /// 同步批量新增实体。 /// /// 实体集合 /// void Insert(List entities); /// /// 同步更新实体。 /// /// 实体 /// 主键ID /// 事务对象 /// bool Update(T entity, TKey id, IDbTransaction trans = null); /// /// 异步更新实体。 /// /// 实体 /// 主键ID /// 事务对象 /// Task UpdateAsync(T entity, TKey id, IDbTransaction trans = null); /// /// 更新某一字段值 /// /// 字段 /// 字段值 /// 条件,为空更新所有内容 /// /// bool UpdateTableField(string strField, string fieldValue, string where, IDbTransaction trans = null); /// /// 异步更新某一字段值 /// /// 字段 /// 字段值 /// 条件,为空更新所有内容 /// /// Task UpdateTableFieldAsync(string strField, string fieldValue, string where, IDbTransaction trans = null); /// /// 更新某一字段值,字段值为数字 /// /// 字段 /// 字段值数字 /// 条件,为空更新所有内容 /// 事务对象 /// 执行成功返回true,否则为false bool UpdateTableField(string strField, int fieldValue, string where, IDbTransaction trans = null); /// /// 更新某一字段值,字段值为数字 /// /// 字段 /// 字段值数字 /// 条件,为空更新所有内容 /// 事务对象 /// 执行成功返回true,否则为false Task UpdateTableFieldAsync(string strField, int fieldValue, string where, IDbTransaction trans = null); /// /// 同步物理删除实体。 /// /// 实体 /// 事务对象 /// bool Delete(T entity, IDbTransaction trans = null); /// /// 异步物理删除实体。 /// /// 实体 /// 事务对象 /// Task DeleteAsync(T entity, IDbTransaction trans = null); /// /// 同步物理删除实体。 /// /// 主键 /// 事务对象 /// bool Delete(TKey id, IDbTransaction trans = null); /// /// 异步物理删除实体。 /// /// 主键 /// 事务对象 /// Task DeleteAsync(TKey id, IDbTransaction trans = null); /// /// 按主键批量删除 /// /// /// 事务对象 /// bool DeleteBatch(IList ids, IDbTransaction trans = null); /// /// 按条件批量删除 /// /// 条件 /// 事务对象 /// bool DeleteBatchWhere(string where, IDbTransaction trans = null); /// /// 异步按条件批量删除 /// /// 条件 /// 事务对象 /// Task DeleteBatchWhereAsync(string where, IDbTransaction trans = null); /// /// 同步软删除信息,将IsDeleted设置为1-删除,0-恢复删除 /// /// true为不删除,false删除 /// 主键ID /// 操作用户 /// 事务对象 /// bool DeleteSoft(bool bl, TKey id, long userId = 0, IDbTransaction trans = null); /// /// 异步软删除信息,将IsDeleted设置为1-删除,0-恢复删除 /// /// true为不删除,false删除 c /// 主键ID /// 操作用户 /// 事务对象 /// Task DeleteSoftAsync(bool bl, TKey id, long userId = 0, IDbTransaction trans = null); /// /// 异步批量软删除信息,将IsDeleted设置为1-删除,0-恢复删除 /// /// true为不删除,false删除 c /// 条件 /// 操作用户 /// 事务对象 /// Task DeleteSoftBatchAsync(bool bl, string where, long userId = 0, IDbTransaction trans = null); /// /// 设置数据有效性,将IsEnabled设置为1-有效,0-为无效 /// /// true为有效,false无效 /// 主键ID /// 操作用户 /// 事务对象 /// bool SetEnabledMark(bool bl, TKey id, long userId = 0, IDbTransaction trans = null); /// /// 异步设置数据有效性,将IsEnabled设置为1:有效,0-为无效 /// /// true为有效,false无效 /// 主键ID /// 操作用户 /// 事务对象 /// Task SetEnabledMarkAsync(bool bl, TKey id, long userId = 0, IDbTransaction trans = null); /// /// 异步按条件设置数据有效性,将IsEnabled设置为1:有效,0-为无效 /// /// true为有效,false无效 /// 条件 /// 操作用户 /// 事务对象 /// Task SetEnabledMarkByWhereAsync(bool bl, string where, long userId = 0, IDbTransaction trans = null); /// /// 异步按条件设置数据有效性,将IsEnabled设置为1:有效,0-为无效 /// /// true为有效,false无效 /// 条件 /// /// 操作用户 /// 事务对象 /// Task SetEnabledMarkByWhereAsync(bool bl, string where, object paramparameters = null, long userId = 0, IDbTransaction trans = null); /// /// 查询软删除的数据,如果查询条件为空,即查询所有软删除的数据 /// /// 查询条件 /// 事务对象 /// IEnumerable GetAllByIsIsDeleted(string where = null, IDbTransaction trans = null); /// /// 查询未软删除的数据,如果查询条件为空,即查询所有未软删除的数据 /// /// 查询条件 /// 事务对象 /// IEnumerable GetAllByIsNotIsDeleted(string where = null, IDbTransaction tran = null); /// /// 查询有效的数据,如果查询条件为空,即查询所有有效的数据 /// /// 查询条件 /// 事务对象 /// IEnumerable GetAllByIsEnabledMark(string where = null, IDbTransaction tran = null); /// /// 查询无效的数据,如果查询条件为空,即查询所有无效的数据 /// /// 查询条件 /// 事务对象 /// IEnumerable GetAllByIsNotEnabledMark(string where = null, IDbTransaction tran = null); /// /// 查询未软删除且有效的数据,如果查询条件为空,即查询所有数据 /// /// 查询条件 /// 事务对象 /// IEnumerable GetAllByIsNotDeleteAndEnabledMark(string where = null, IDbTransaction tran = null); /// /// 查询软删除的数据,如果查询条件为空,即查询所有软删除的数据 /// /// 查询条件 /// 事务对象 /// Task> GetAllByIsIsDeletedAsync(string where = null, IDbTransaction tran = null); /// /// 查询未软删除的数据,如果查询条件为空,即查询所有未软删除的数据 /// /// 查询条件 /// 事务对象 /// Task> GetAllByIsNotIsDeletedAsync(string where = null, IDbTransaction tran = null); /// /// 查询有效的数据,如果查询条件为空,即查询所有有效的数据 /// /// 查询条件 /// 事务对象 /// Task> GetAllByIsEnabledMarkAsync(string where = null, IDbTransaction tran = null); /// /// 查询无效的数据,如果查询条件为空,即查询所有无效的数据 /// /// 查询条件 /// 事务对象 /// Task> GetAllByIsNotEnabledMarkAsync(string where = null, IDbTransaction tran = null); /// /// 查询未软删除且有效的数据,如果查询条件为空,即查询所有数据 /// /// 查询条件 /// 事务对象 /// Task> GetAllByIsNotDeleteAndEnabledMarkAsync(string where = null, IDbTransaction trans = null); /// /// 根据条件查询数据库,并返回对象集合(用于分页数据显示) /// /// 查询的条件 /// 分页实体 /// 排序字段 /// 是否降序 /// 事务对象 /// 指定对象的集合 Task> FindWithPagerAsync(string condition, PagerInfo info, string fieldToSort, bool desc, IDbTransaction trans = null); /// /// 根据条件查询数据库,并返回对象集合(用于分页数据显示) /// /// 查询的条件 /// 分页实体 /// 排序字段 /// 是否降序 /// 事务对象 /// 指定对象的集合 List FindWithPager(string condition, PagerInfo info, string fieldToSort, bool desc, IDbTransaction trans = null); /// /// 根据条件查询数据库,并返回对象集合(用于分页数据显示) /// /// 查询的条件 /// 分页实体 /// 排序字段 /// 事务对象 /// 指定对象的集合 Task> FindWithPagerAsync(string condition, PagerInfo info, string fieldToSort, IDbTransaction trans = null); /// /// 根据条件查询数据库,并返回对象集合(用于分页数据显示) /// /// 查询的条件 /// 分页实体 /// 排序字段 /// 事务对象 /// 指定对象的集合 List FindWithPager(string condition, PagerInfo info, string fieldToSort, IDbTransaction trans = null); /// /// 根据条件查询数据库,并返回对象集合(用于分页数据显示) /// /// 查询的条件 /// 分页实体 /// 事务对象 /// 指定对象的集合 Task> FindWithPagerAsync(string condition, PagerInfo info, IDbTransaction trans = null); /// /// 根据条件查询数据库,并返回对象集合(用于分页数据显示) /// /// 查询的条件 /// 分页实体 /// 事务对象 /// 指定对象的集合 List FindWithPager(string condition, PagerInfo info, IDbTransaction trans = null); /// /// 根据条件查询数据库,并返回对象集合(用于分页数据显示) /// /// 查询的条件 /// 指定对象的集合 PageResult FindWithPager(SearchInputDto search); /// /// 根据条件查询数据库,并返回对象集合(用于分页数据显示) /// /// 查询的条件 /// 指定对象的集合 Task> FindWithPagerAsync(SearchInputDto search); /// /// 分页查询,自行封装sql语句(仅支持sql server) /// 非常复杂的查询,可在具体业务模块重写该方法 /// /// 查询条件 /// 分页信息 /// 排序字段 /// 排序方式 true为desc,false为asc /// /// Task> FindWithPagerSqlAsync(string condition, PagerInfo info, string fieldToSort, bool desc, IDbTransaction trans = null); /// /// 分页查询,自行封装sql语句(仅支持sql server) /// 非常复杂的查询,可在具体业务模块重写该方法 /// /// 查询条件 /// 分页信息 /// 排序字段 /// 排序方式 true为desc,false为asc /// /// List FindWithPagerSql(string condition, PagerInfo info, string fieldToSort, bool desc, IDbTransaction trans = null); /// /// 分页查询包含用户信息(仅支持sql server) /// 查询主表别名为t1,用户表别名为t2,在查询字段需要注意使用t1.xxx格式,xx表示主表字段 /// 用户信息主要有用户账号:Account、昵称:UserName、真实姓名:RealName、头像:HeadIcon、手机号:MobilePhone /// 输出对象请在Dtos中进行自行封装,不能是使用实体Model类 /// /// 查询条件字段需要加表别名 /// 分页信息 /// 排序字段,也需要加表别名 /// 排序方式 /// 事务 /// Task> FindWithPagerRelationUserAsync(string condition, PagerInfo info, string fieldToSort, bool desc, IDbTransaction trans = null); /// /// 分页查询包含用户信息(仅支持sql server) /// 查询主表别名为t1,用户表别名为t2,在查询字段需要注意使用t1.xxx格式,xx表示主表字段 /// 用户信息主要有用户账号:Account、昵称:UserName、真实姓名:RealName、头像:HeadIcon、手机号:MobilePhone /// 输出对象请在Dtos中进行自行封装,不能是使用实体Model类 /// /// 查询条件字段需要加表别名 /// 分页信息 /// 排序字段,也需要加表别名 /// 排序方式 /// 事务 /// List FindWithPagerRelationUser(string condition, PagerInfo info, string fieldToSort, bool desc, IDbTransaction trans = null); /// /// 根据条件统计数据 /// /// 查询条件 /// 统计字段名称 /// int GetCountByWhere(string condition, string fieldName = "*"); /// /// 根据条件统计数据 /// /// 查询条件 /// 统计字段名称 /// Task GetCountByWhereAsync(string condition, string fieldName = "*"); /// /// 获取总条数 /// /// Task GetCount(); /// /// 根据条件查询获取某个字段的最大值 /// /// 字段 /// 条件 /// 事务 /// 返回字段的最大值 Task GetMaxValueByFieldAsync(string strField, string where, IDbTransaction trans = null); /// /// 根据条件统计某个字段之和,sum(字段) /// /// 字段 /// 条件 /// 事务 /// 返回字段求和后的值 Task GetSumValueByFieldAsync(string strField, string where, IDbTransaction trans = null); /// /// 多表操作--事务 /// /// 事务 /// 超时 /// Task> ExecuteTransactionAsync(List> trans, int? commandTimeout = null); /// /// 多表操作--事务 /// /// 事务 /// 超时 /// Tuple ExecuteTransaction(List> trans, int? commandTimeout = null); } }