using JinYuan.DAL.Models;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace JinYuan.DAL
{
public interface ISugarHepler: IDisposable
{
///
/// 初始化数据库连接
///
///
void SetConnectionStr(string connectionStr, SqlSugar.DbType dbType);
#region 数据库管理
///
/// 添加列
///
/// 表名
/// 列信息
///
bool AddColumn(string tableName, DbColumnInfo column);
///
/// 添加主键
///
/// 表名
/// 列名
///
bool AddPrimaryKey(string tableName, string columnName);
///
/// 备份数据库
///
/// 数据库名
/// 文件名
///
bool BackupDataBase(string databaseName, string fullFileName);
///
/// 备份表
///
/// 旧表名
/// 行表名
/// 行数
///
bool BackupTable(string oldTableName, string newTableName, int maxBackupDataRows = int.MaxValue);
///
/// 创建表
///
/// 表名
/// 列集合
/// 是否创建主键
///
bool CreateTable(string tableName, List columns, bool isCreatePrimaryKey = true);
///
/// 删除列
///
/// 表名
/// 列名
///
bool DropColumn(string tableName, string columnName);
///
/// 删除约束
///
/// 表名
/// 约束名
///
bool DropConstraint(string tableName, string constraintName);
///
/// 删除表
///
///
///
bool DropTable(string tableName);
///
/// 获取列信息
///
/// 表名
/// 是否缓存
///
List GetColumnInfosByTableName(string tableName, bool isCache = true);
///
/// 获取自增列
///
/// 表名
///
List GetIsIdentities(string tableName);
///
/// 获取主键
///
/// 表名
///
List GetPrimaries(string tableName);
///
/// 获取表集合
///
/// 是否缓存
///
List GetTableInfoList(bool isCache = true);
///
/// 获取视图集合
///
/// 是否缓存
///
List GetViewInfoList(bool isCache = true);
///
/// 检测列是否存在
///
/// 表名
/// 列名
///
bool IsAnyColumn(string tableName, string column);
///
/// 检测约束
///
/// 约束名称
///
bool IsAnyConstraint(string constraintName);
///
/// 检测是否有任何系统表权限
///
///
bool IsAnySystemTablePermissions();
///
/// 检测表是否存在
///
/// 表名
/// 是否缓存
///
bool IsAnyTable(string tableName, bool isCache = true);
///
/// 检测列是否自增列
///
/// 表名
/// 列名
///
bool IsIdentity(string tableName, string column);
///
/// 检测列是否主键
///
/// 表名
/// 列名
///
bool IsPrimaryKey(string tableName, string column);
///
/// 重置列名
///
/// 表名
/// 旧列名
/// 新列名
///
bool RenameColumn(string tableName, string oldColumnName, string newColumnName);
///
/// 重置表数据
///
/// 表名
///
bool TruncateTable(string tableName);
///
/// 修改列信息
///
/// 表名
/// 列信息
///
bool UpdateColumn(string tableName, DbColumnInfo column);
///
/// 获取数据库时间
///
/// 返回值
DateTime GetDataBaseTime();
#endregion
#region 查询
///
/// 查询所有
///
///
///
List QueryAll() where T : class, new();
///
/// 查询-返回自定义数据
///
/// 泛型参数(集合成员的类型)
/// 返回值类型
/// 返回值表达式
/// 查询表达式
/// 值
TResult QuerySelect(Expression> expression, Expression> whereLambda = null) where T : class, new();
///
/// 查询-返回自定义数据
///
/// 泛型参数(集合成员的类型)
/// 返回值类型
/// 返回值表达式
/// 查询表达式
/// 值
List QuerySelectList(Expression> expression, Expression> whereLambda = null) where T : class, new();
///
/// 根据条件查询单条数据
///
/// 泛型参数(集合成员的类型)
/// 查询表达式
///
T Query(Expression> whereLambda = null) where T : class, new();
///
/// 根据条件异步查询单条数据
///
///
///
///
Task QueryAsync(Expression> whereLambda = null) where T : class, new();
///
/// 根据条件查询排序数据
///
///
///
///
///
T Query(Expression> whereLambda = null, Expression> whereLambda2 = null, OrderByType byType = OrderByType.Desc) where T : class, new();
///
/// 根据条件查询集合
///
/// 泛型参数(集合成员的类型)
/// 过滤条件
/// 实体
List QueryWhereList(Expression> whereLambda = null) where T : class, new();
///
/// 查询排序数据
///
///
///
///
List QueryList(QueryDescriptor query = null) where T : class, new();
///
/// 查询前N条数据
///
///
/// 排序列名
/// 前N条数据
/// 条件
/// 升序/降序
///
List QueryList(string sort, int Take, Expression> whereLambda = null, OrderByType byType = OrderByType.Desc) where T : class, new();
///
/// 根据字段查询排列
///
///
///
///
///
///
List QueryList(string sort, Expression> whereLambda = null, OrderByType byType = OrderByType.Asc) where T : class, new();
///
/// 查询集合
///
/// 泛型参数(集合成员的类型)
/// sql
/// 实体
List QuerySqlList(string sql) where T : class, new();
///
/// 分页查询
///
/// 泛型参数(集合成员的类型)
/// 过滤条件
/// 总行数
/// 实体
List QueryPageList(QueryDescriptor query, out int totalCount) where T : class, new();
///
/// 通过多值查询数据集
///
/// 泛型参数(集合成员的类型)
/// 字段名
/// 数据集合
///
List In(string inFieldName, List inValues) where T : class, new();
///
/// 通过多值(主键)查询数据集
///
/// 泛型参数(集合成员的类型)
/// 主键数据集合
///
List In(List values) where T : class, new();
///
/// 条件查询DataTable
///
/// 泛型参数(集合成员的类型)
/// 查询表达式
/// 实体
DataTable QueryDataTable(Expression> whereLambda = null) where T : class, new();
///
/// 查询DataTable
///
/// sql
/// 实体
DataTable QueryDataTable(string sql);
///
/// 查询单个值
///
/// sql
/// 单个值
object QuerySqlScalar(string sql);
///
/// 分页查询
///
/// 泛型参数(集合成员的类型)
/// 过滤条件
/// 总行数
/// DataTable
DataTable QueryDataTablePageList(QueryDescriptor query, out int totalCount) where T : class, new();
#endregion
#region 新增
///
/// 新增
///
/// 泛型参数(集合成员的类型)
/// 实体对象
/// 操作影响的行数
int Add(T entity) where T : class, new();
///
/// 新增
///
/// 泛型参数(集合成员的类型)
/// 泛型集合
/// 操作影响的行数
int Add(List entitys) where T : class, new();
///
/// 新增
///
/// 泛型参数(集合成员的类型)
/// 字典集合(Key:列名 Value:值)
/// 操作影响的行数
int Add(Dictionary keyValues) where T : class, new();
///
/// 新增
///
/// 泛型参数(集合成员的类型)
/// 实体对象
/// 返回实体
T AddReturnEntity(T entity) where T : class, new();
///
/// 新增
///
/// 泛型参数(集合成员的类型)
/// 实体对象
/// 返回自增列
int AddReturnIdentity(T entity) where T : class, new();
///
/// 新增
///
/// 泛型参数(集合成员的类型)
/// 实体对象
/// 返回bool
bool AddReturnBool(T entity) where T : class, new();
///
/// 新增
///
/// 泛型参数(集合成员的类型)
/// 泛型集合
/// 返回bool
bool AddReturnBool(List entitys) where T : class, new();
#endregion
#region 修改
///
/// 修改(主键是更新条件)
///
/// 泛型参数(集合成员的类型)
/// 实体对象(必须指定主键特性 [SugarColumn(IsPrimaryKey=true)]),如果是联合主键,请使用Where条件
/// 不更新的列
/// 是否加锁
/// 操作影响的行数
int Update(T entity, List lstIgnoreColumns = null, bool isLock = true) where T : class, new();
///
/// 修改(主键是更新条件)
///
/// 泛型参数(集合成员的类型)
/// 实体对象集合(必须指定主键特性 [SugarColumn(IsPrimaryKey=true)]),如果是联合主键,请使用Where条件
/// 不更新的列
/// 是否加锁
/// 操作影响的行数
int Update(List entitys, List lstIgnoreColumns = null, bool isLock = true) where T : class, new();
///
/// 修改
///
/// 泛型参数(集合成员的类型)
/// 实体对象
/// 条件
/// 不更新的列
/// 是否加锁
/// 操作影响的行数
int Update(T entity, Expression> where, List lstIgnoreColumns = null,
bool isLock = true) where T : class, new();
///
/// 修改
///
/// 泛型参数(集合成员的类型)
/// 实体对象
/// 条件
/// 是否加锁
/// 操作影响的行数
int Update(Expression> update, Expression> where = null, bool isLock = true) where T : class, new();
///
/// 修改+1
///
/// 泛型参数(集合成员的类型)
/// 实体对象
/// 条件
/// 是否加锁
/// 操作影响的行数
int Update(Expression> update, Expression> where = null, bool isLock = true) where T : class, new();
///
/// 修改单条数据
///
///
///
///
///
int UpdateSingle(T entity, Expression> where = null, Expression> where2 = null, bool isLock = true) where T : class, new();
///
/// 修改
///
/// 泛型参数(集合成员的类型)
/// 字典集合(Key:列名 Value:值)
/// 条件
/// 是否加锁
/// 操作影响的行数
int Update(Dictionary keyValues, Expression> where = null, bool isLock = true)
where T : class, new();
///
/// 批量修改需要更新的列
///
/// 泛型参数(集合成员的类型)
/// 实体对象(必须指定主键特性 [SugarColumn(IsPrimaryKey=true)]),如果是联合主键,请使用Where条件
/// 更新指定列
/// 条件(为空则以主键更新,反之需要把wherecolumns中的列加到UpdateColumns中)
/// 是否加锁
/// 操作影响的行数
int UpdateColumns(List entitys, Expression> updateColumns,
Expression> wherecolumns = null, bool isLock = true) where T : class, new();
///
/// 修改 通过RowVer及主键Code 更新
///
/// 泛型参数(集合成员的类型)
/// 实体对象
/// 不更新的列
/// 是否加锁
/// 操作影响的行数
int UpdateRowVer(T entity, List lstIgnoreColumns = null, bool isLock = true) where T : class, new();
///
/// 修改 通过RowVer及主键Code 更新
///
/// 泛型参数(集合成员的类型)
/// 实体对象
/// 更新条件
/// 是否加锁
/// 操作影响的行数
int UpdateRowVer(Expression> update, Dictionary where, bool isLock = true) where T : class, new();
#endregion
#region 删除
///
/// 删除 通过主键数据
///
/// 泛型参数(集合成员的类型)
/// 主键值
/// 是否加锁
/// 操作影响的行数
int DeleteByPrimary(List