using System;
using System.Collections.Generic;
using System.Data;
using System.Linq.Expressions;
using System.Threading.Tasks;
using Znyc.Recruitment.Admin.Commons.Entitys;
using Znyc.Recruitment.Admin.Commons.Pages;
namespace Znyc.Recruitment.Admin.Commons.IRepositories
{
///
/// 定义泛型接口,实体仓储模型的数据标准操作
///
/// 实体类型
/// 主键类型
public interface IRepository : IDisposable where T : Entity
{
#region dapper 操作
#region 新增
///
/// 同步新增实体。
///
/// 实体
/// 事务对象
///
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);
#endregion 新增
#region 删除
///
/// 同步物理删除实体。
///
/// 实体
///
bool Delete(T entity);
///
/// 异步物理删除实体。
///
/// 实体
/// 事务对象
///
Task DeleteAsync(T entity, IDbTransaction trans = null);
///
/// 同步物理删除实体。
///
/// 主键
/// 事务对象
///
bool Delete(TKey primaryKey, IDbTransaction trans = null);
///
/// 异步物理删除实体。
///
/// 主键
/// 事务对象
///
Task DeleteAsync(TKey primaryKey, IDbTransaction trans = null);
///
/// 按主键批量删除
///
///
/// 事务对象
///
bool DeleteBatch(IList ids, IDbTransaction trans = null);
///
/// 按条件批量删除
///
/// 条件
/// 事务对象
///
bool DeleteBatchWhere(string where, IDbTransaction trans = null);
///
/// 异步按条件批量删除
///
/// 条件
/// 事务对象
///
Task DeleteBatchWhereAsync(string where, IDbTransaction trans = null);
#endregion 删除
#region 更新操作
#region 更新实体或批量更新
///
/// 同步更新实体。
///
/// 实体
/// 主键ID
/// 事务对象
///
bool Update(T entity, TKey primaryKey, IDbTransaction trans = null);
///
/// 异步更新实体。
///
/// 实体
/// 主键ID
/// 事务对象
///
Task UpdateAsync(T entity, TKey primaryKey, IDbTransaction trans = null);
#endregion 更新实体或批量更新
#region 更新某一字段值
///
/// 更新某一字段值
///
/// 字段
/// 字段值
/// 条件,为空更新所有内容
///
///
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);
#endregion 更新某一字段值
#region 逻辑删除
///
/// 同步软删除信息,将IsDeleted设置为1-删除,0-恢复删除
///
/// true为不删除,false删除
/// 主键ID
/// 操作用户
/// 事务对象
///
bool DeleteSoft(bool bl, TKey primaryKey, long userId = 0, IDbTransaction trans = null);
///
/// 异步软删除信息,将IsDeleted设置为1-删除,0-恢复删除
///
/// true为不删除,false删除
/// c
/// 主键ID
/// 操作用户
/// 事务对象
///
Task DeleteSoftAsync(bool bl, TKey primaryKey, long userId = 0, IDbTransaction trans = null);
///
/// 异步批量软删除信息,将IsDeleted设置为1-删除,0-恢复删除
///
/// true为不删除,false删除
/// c
/// 条件
/// 操作用户
/// 事务对象
///
Task DeleteSoftBatchAsync(bool bl, string where, long userId = 0, IDbTransaction trans = null);
#endregion 逻辑删除
#region 数据有效性
///
/// 设置数据有效性,将IsEnabled设置为1-有效,0-为无效
///
/// true为有效,false无效
/// 主键ID
/// 操作用户
/// 事务对象
///
bool SetEnabledMark(bool bl, TKey primaryKey, long userId = 0, IDbTransaction trans = null);
///
/// 异步设置数据有效性,将IsEnabled设置为1:有效,0-为无效
///
/// true为有效,false无效
/// 主键ID
/// 操作用户
/// 事务对象
///
Task SetEnabledMarkAsync(bool bl, TKey primaryKey, long userId = 0, IDbTransaction trans = null);
///
/// 异步按条件设置数据有效性,将IsEnabled设置为1:有效,0-为无效
///
/// true为有效,false无效
/// 条件
/// 操作用户
/// 事务对象
///
Task SetEnabledMarkByWhereAsync(bool bl, string where, long userId = 0, IDbTransaction trans = null);
///
/// 异步按条件设置数据的状态,将Status设置为0:审核中,1:正常,-1:停用,-2:停用
///
/// 0:审核中,1:正常,-1:停用,-2:停用
/// 条件
/// 操作用户
/// 事务对象
///
Task SetStatusByWhereAsync(int 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);
#endregion 数据有效性
#endregion 更新操作
#region 查询
#region 单个实体
///
/// 同步查询单个实体。
///
/// 主键
///
T Get(TKey primaryKey);
///
/// 异步查询单个实体。
///
/// 主键
///
Task GetAsync(TKey primaryKey);
///
/// 同步查询单个实体。
///
/// 查询条件
///
T GetWhere(string where);
///
/// 异步查询单个实体。
///
/// 查询条件
///
Task GetWhereAsync(string where);
#endregion 单个实体
///
/// 获取所有数据,谨慎使用
///
/// 事务对象
///
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);
///
/// 查询软删除的数据,如果查询条件为空,即查询所有软删除的数据
///
/// 查询条件
/// 事务对象
///
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);
///
/// 分页查询,自行封装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