测试
This commit is contained in:
@@ -0,0 +1,431 @@
|
||||
using Infrastructure;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Dynamic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ZR.Repository
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public class BaseRepository<T> : SimpleClient<T>, IBaseRepository<T> where T : class, new()
|
||||
{
|
||||
public BaseRepository(ISqlSugarClient dbContext = null, int configId = 0) : base(dbContext)
|
||||
{
|
||||
if (dbContext == null)
|
||||
{
|
||||
string connStr = ConfigUtils.Instance.GetConnectionStrings(OptionsSetting.ConnAdmin);
|
||||
string dbKey = ConfigUtils.Instance.GetAppConfig<string>(OptionsSetting.DbKey);
|
||||
int dbType = ConfigUtils.Instance.GetAppConfig<int>(OptionsSetting.ConnDbType);
|
||||
if (!string.IsNullOrEmpty(dbKey))
|
||||
{
|
||||
connStr = NETCore.Encrypt.EncryptProvider.DESDecrypt(connStr, dbKey);
|
||||
}
|
||||
|
||||
var Db = new SqlSugarClient(new List<ConnectionConfig>()
|
||||
{
|
||||
new ConnectionConfig(){
|
||||
ConnectionString = connStr,
|
||||
DbType = (DbType)dbType,
|
||||
IsAutoCloseConnection = true,//开启自动释放模式和EF原理一样
|
||||
InitKeyType = InitKeyType.Attribute,//从特性读取主键和自增列信息
|
||||
ConfigId = 0
|
||||
},
|
||||
new ConnectionConfig(){
|
||||
ConnectionString = "",
|
||||
DbType = DbType.SqlServer,
|
||||
IsAutoCloseConnection = true,
|
||||
InitKeyType = InitKeyType.Attribute,//从特性读取主键和自增列信息
|
||||
ConfigId = 1
|
||||
},
|
||||
});
|
||||
|
||||
//调式代码 用来打印SQL
|
||||
Db.GetConnection(0).Aop.OnLogExecuting = (sql, pars) =>
|
||||
{
|
||||
Console.BackgroundColor = ConsoleColor.Yellow;
|
||||
Console.WriteLine("【SQL语句】" + sql.ToLower() + "\r\n" + Db.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value)));
|
||||
};
|
||||
//出错打印日志
|
||||
Db.GetConnection(0).Aop.OnError = (e) =>
|
||||
{
|
||||
Console.WriteLine($"[执行Sql出错]{e.Message},SQL={e.Sql}");
|
||||
Console.WriteLine();
|
||||
};
|
||||
|
||||
base.Context = Db.GetConnection(configId);//根据类传入的ConfigId自动选择
|
||||
}
|
||||
}
|
||||
|
||||
#region add
|
||||
public int Add(T parm, Expression<Func<T, object>> iClumns = null, bool ignoreNull = true)
|
||||
{
|
||||
return base.Context.Insertable(parm).InsertColumns(iClumns).IgnoreColumns(ignoreNullColumn: ignoreNull).ExecuteCommand();
|
||||
}
|
||||
public int Insert(T t, bool IgnoreNullColumn = true)
|
||||
{
|
||||
return base.Context.Insertable(t).IgnoreColumns(IgnoreNullColumn).ExecuteCommand();
|
||||
}
|
||||
|
||||
public int InsertIgnoreNullColumn(T t)
|
||||
{
|
||||
return base.Context.Insertable(t).IgnoreColumns(true).ExecuteCommand();
|
||||
}
|
||||
|
||||
public int InsertIgnoreNullColumn(T t, params string[] columns)
|
||||
{
|
||||
return base.Context.Insertable(t).IgnoreColumns(columns).ExecuteCommand();
|
||||
}
|
||||
|
||||
//public int Insert(SqlSugarClient client, T t)
|
||||
//{
|
||||
// return client.Insertable(t).ExecuteCommand();
|
||||
//}
|
||||
|
||||
public long InsertBigIdentity(T t)
|
||||
{
|
||||
return base.Context.Insertable(t).ExecuteReturnBigIdentity();
|
||||
}
|
||||
|
||||
public int Insert(List<T> t)
|
||||
{
|
||||
return base.Context.Insertable(t).ExecuteCommand();
|
||||
}
|
||||
|
||||
public int InsertIgnoreNullColumn(List<T> t)
|
||||
{
|
||||
return base.Context.Insertable(t).IgnoreColumns(true).ExecuteCommand();
|
||||
}
|
||||
|
||||
public int InsertIgnoreNullColumn(List<T> t, params string[] columns)
|
||||
{
|
||||
return base.Context.Insertable(t).IgnoreColumns(columns).ExecuteCommand();
|
||||
}
|
||||
public int Insert(T parm, Expression<Func<T, object>> iClumns = null, bool ignoreNull = true)
|
||||
{
|
||||
return base.Context.Insertable(parm).InsertColumns(iClumns).IgnoreColumns(ignoreNullColumn: ignoreNull).ExecuteCommand();
|
||||
}
|
||||
public DbResult<bool> InsertTran(T t)
|
||||
{
|
||||
var result = base.Context.Ado.UseTran(() =>
|
||||
{
|
||||
base.Context.Insertable(t).ExecuteCommand();
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
public DbResult<bool> InsertTran(List<T> t)
|
||||
{
|
||||
var result = base.Context.Ado.UseTran(() =>
|
||||
{
|
||||
base.Context.Insertable(t).ExecuteCommand();
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
public T InsertReturnEntity(T t)
|
||||
{
|
||||
return base.Context.Insertable(t).ExecuteReturnEntity();
|
||||
}
|
||||
|
||||
public T InsertReturnEntity(T t, string sqlWith = SqlWith.UpdLock)
|
||||
{
|
||||
return base.Context.Insertable(t).With(sqlWith).ExecuteReturnEntity();
|
||||
}
|
||||
|
||||
public bool ExecuteCommand(string sql, object parameters)
|
||||
{
|
||||
return base.Context.Ado.ExecuteCommand(sql, parameters) > 0;
|
||||
}
|
||||
|
||||
public bool ExecuteCommand(string sql, params SugarParameter[] parameters)
|
||||
{
|
||||
return base.Context.Ado.ExecuteCommand(sql, parameters) > 0;
|
||||
}
|
||||
|
||||
public bool ExecuteCommand(string sql, List<SugarParameter> parameters)
|
||||
{
|
||||
return base.Context.Ado.ExecuteCommand(sql, parameters) > 0;
|
||||
}
|
||||
|
||||
#endregion add
|
||||
|
||||
#region update
|
||||
|
||||
public bool UpdateEntity(T entity, bool ignoreNullColumns = false)
|
||||
{
|
||||
return base.Context.Updateable(entity).IgnoreColumns(ignoreNullColumns).ExecuteCommand() > 0;
|
||||
}
|
||||
|
||||
public bool Update(T entity, Expression<Func<T, bool>> expression)
|
||||
{
|
||||
return base.Context.Updateable(entity).Where(expression).ExecuteCommand() > 0;
|
||||
}
|
||||
|
||||
public bool Update(T entity, Expression<Func<T, object>> expression, bool ignoreAllNull = false)
|
||||
{
|
||||
return base.Context.Updateable(entity).UpdateColumns(expression).IgnoreColumns(ignoreAllNull).ExecuteCommand() > 0;
|
||||
}
|
||||
|
||||
public bool Update(T entity, Expression<Func<T, object>> expression, Expression<Func<T, bool>> where)
|
||||
{
|
||||
return base.Context.Updateable(entity).UpdateColumns(expression).Where(where).ExecuteCommand() > 0;
|
||||
}
|
||||
|
||||
public bool Update(SqlSugarClient client, T entity, Expression<Func<T, object>> expression, Expression<Func<T, bool>> where)
|
||||
{
|
||||
return client.Updateable(entity).UpdateColumns(expression).Where(where).ExecuteCommand() > 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <param name="list"></param>
|
||||
/// <param name="isNull">默认为true</param>
|
||||
/// <returns></returns>
|
||||
public bool Update(T entity, List<string> list = null, bool isNull = true)
|
||||
{
|
||||
if (list == null)
|
||||
{
|
||||
list = new List<string>()
|
||||
{
|
||||
"Create_By",
|
||||
"Create_time"
|
||||
};
|
||||
}
|
||||
//base.Context.Updateable(entity).IgnoreColumns(c => list.Contains(c)).Where(isNull).ExecuteCommand()
|
||||
return base.Context.Updateable(entity).IgnoreColumns(isNull).IgnoreColumns(list.ToArray()).ExecuteCommand() > 0;
|
||||
}
|
||||
|
||||
public bool Update(List<T> entity)
|
||||
{
|
||||
var result = base.Context.Ado.UseTran(() =>
|
||||
{
|
||||
base.Context.Updateable(entity).ExecuteCommand();
|
||||
});
|
||||
return result.IsSuccess;
|
||||
}
|
||||
public bool Update(Expression<Func<T, bool>> where, Expression<Func<T, T>> columns)
|
||||
{
|
||||
return base.Context.Updateable<T>().SetColumns(columns).Where(where).RemoveDataCache().ExecuteCommand() > 0;
|
||||
}
|
||||
#endregion update
|
||||
|
||||
//public DbResult<bool> UseTran(Action action)
|
||||
//{
|
||||
// var result = base.Context.Ado.UseTran(() => action());
|
||||
// return result;
|
||||
//}
|
||||
|
||||
//public DbResult<bool> UseTran(SqlSugarClient client, Action action)
|
||||
//{
|
||||
// var result = client.Ado.UseTran(() => action());
|
||||
// return result;
|
||||
//}
|
||||
|
||||
//public bool UseTran2(Action action)
|
||||
//{
|
||||
// var result = base.Context.Ado.UseTran(() => action());
|
||||
// return result.IsSuccess;
|
||||
//}
|
||||
|
||||
#region delete
|
||||
|
||||
public bool Delete(Expression<Func<T, bool>> expression)
|
||||
{
|
||||
return base.Context.Deleteable<T>().Where(expression).ExecuteCommand() > 0;
|
||||
}
|
||||
|
||||
//public bool Delete<PkType>(PkType[] primaryKeyValues)
|
||||
//{
|
||||
// return base.Context.Deleteable<T>().In(primaryKeyValues).ExecuteCommand() > 0;
|
||||
//}
|
||||
|
||||
public bool Delete(object[] obj)
|
||||
{
|
||||
return base.Context.Deleteable<T>().In(obj).ExecuteCommand() > 0;
|
||||
}
|
||||
public bool Delete(object id)
|
||||
{
|
||||
return base.Context.Deleteable<T>(id).ExecuteCommand() > 0;
|
||||
}
|
||||
public bool Delete()
|
||||
{
|
||||
return base.Context.Deleteable<T>().ExecuteCommand() > 0;
|
||||
}
|
||||
|
||||
#endregion delete
|
||||
|
||||
#region query
|
||||
|
||||
public bool IsAny(Expression<Func<T, bool>> expression)
|
||||
{
|
||||
//base.Context.Queryable<T>().Any();
|
||||
return base.Context.Queryable<T>().Where(expression).Any();
|
||||
}
|
||||
|
||||
public ISugarQueryable<T> Queryable()
|
||||
{
|
||||
return base.Context.Queryable<T>();
|
||||
}
|
||||
|
||||
public ISugarQueryable<ExpandoObject> Queryable(string tableName, string shortName)
|
||||
{
|
||||
return base.Context.Queryable(tableName, shortName);
|
||||
}
|
||||
|
||||
public List<T> QueryableToList(Expression<Func<T, bool>> expression)
|
||||
{
|
||||
return base.Context.Queryable<T>().Where(expression).ToList();
|
||||
}
|
||||
|
||||
public Task<List<T>> QueryableToListAsync(Expression<Func<T, bool>> expression)
|
||||
{
|
||||
return base.Context.Queryable<T>().Where(expression).ToListAsync();
|
||||
}
|
||||
|
||||
//public string QueryableToJson(string select, Expression<Func<T, bool>> expressionWhere)
|
||||
//{
|
||||
// var query = base.Context.Queryable<T>().Select(select).Where(expressionWhere).ToList();
|
||||
// return query.JilToJson();
|
||||
//}
|
||||
|
||||
public T QueryableToEntity(Expression<Func<T, bool>> expression)
|
||||
{
|
||||
return base.Context.Queryable<T>().Where(expression).First();
|
||||
}
|
||||
|
||||
public List<T> QueryableToList(string tableName)
|
||||
{
|
||||
return base.Context.Queryable<T>(tableName).ToList();
|
||||
}
|
||||
|
||||
public List<T> QueryableToList(string tableName, Expression<Func<T, bool>> expression)
|
||||
{
|
||||
return base.Context.Queryable<T>(tableName).Where(expression).ToList();
|
||||
}
|
||||
|
||||
public (List<T>, int) QueryableToPage(Expression<Func<T, bool>> expression, int pageIndex = 0, int pageSize = 10)
|
||||
{
|
||||
int totalNumber = 0;
|
||||
var list = base.Context.Queryable<T>().Where(expression).ToPageList(pageIndex, pageSize, ref totalNumber);
|
||||
return (list, totalNumber);
|
||||
}
|
||||
|
||||
public (List<T>, int) QueryableToPage(Expression<Func<T, bool>> expression, string order, int pageIndex = 0, int pageSize = 10)
|
||||
{
|
||||
int totalNumber = 0;
|
||||
var list = base.Context.Queryable<T>().Where(expression).OrderBy(order).ToPageList(pageIndex, pageSize, ref totalNumber);
|
||||
return (list, totalNumber);
|
||||
}
|
||||
|
||||
public (List<T>, int) QueryableToPage(Expression<Func<T, bool>> expression, Expression<Func<T, object>> orderFiled, string orderBy, int pageIndex = 0, int pageSize = 10)
|
||||
{
|
||||
int totalNumber = 0;
|
||||
|
||||
if (orderBy.Equals("DESC", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var list = base.Context.Queryable<T>().Where(expression).OrderBy(orderFiled, OrderByType.Desc).ToPageList(pageIndex, pageSize, ref totalNumber);
|
||||
return (list, totalNumber);
|
||||
}
|
||||
else
|
||||
{
|
||||
var list = base.Context.Queryable<T>().Where(expression).OrderBy(orderFiled, OrderByType.Asc).ToPageList(pageIndex, pageSize, ref totalNumber);
|
||||
return (list, totalNumber);
|
||||
}
|
||||
}
|
||||
|
||||
//public (List<T>, int) QueryableToPage(Expression<Func<T, bool>> expression, Bootstrap.BootstrapParams bootstrap)
|
||||
//{
|
||||
// int totalNumber = 0;
|
||||
// if (bootstrap.offset != 0)
|
||||
// {
|
||||
// bootstrap.offset = bootstrap.offset / bootstrap.limit + 1;
|
||||
// }
|
||||
// if (bootstrap.order.Equals("DESC", StringComparison.OrdinalIgnoreCase))
|
||||
// {
|
||||
// var list = base.Context.Queryable<T>().Where(expression).OrderBy(bootstrap.sort).ToPageList(bootstrap.offset, bootstrap.limit, ref totalNumber);
|
||||
// return (list, totalNumber);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// var list = base.Context.Queryable<T>().Where(expression).OrderBy(bootstrap.sort).ToPageList(bootstrap.offset, bootstrap.limit, ref totalNumber);
|
||||
// return (list, totalNumber);
|
||||
// }
|
||||
//}
|
||||
|
||||
public List<T> SqlQueryToList(string sql, object obj = null)
|
||||
{
|
||||
return base.Context.Ado.SqlQuery<T>(sql, obj);
|
||||
}
|
||||
/// <summary>
|
||||
/// 获得一条数据
|
||||
/// </summary>
|
||||
/// <param name="where">Expression<Func<T, bool>></param>
|
||||
/// <returns></returns>
|
||||
public T GetFirst(Expression<Func<T, bool>> where)
|
||||
{
|
||||
return Context.Queryable<T>().Where(where).First();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据主值查询单条数据
|
||||
/// </summary>
|
||||
/// <param name="pkValue">主键值</param>
|
||||
/// <returns>泛型实体</returns>
|
||||
public T GetId(object pkValue)
|
||||
{
|
||||
return Context.Queryable<T>().InSingle(pkValue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得一条数据
|
||||
/// </summary>
|
||||
/// <param name="parm">string</param>
|
||||
/// <returns></returns>
|
||||
public T GetFirst(string parm)
|
||||
{
|
||||
return Context.Queryable<T>().Where(parm).First();
|
||||
}
|
||||
#endregion query
|
||||
|
||||
/// <summary>
|
||||
/// 此方法不带output返回值
|
||||
/// var list = new List<SugarParameter>();
|
||||
/// list.Add(new SugarParameter(ParaName, ParaValue)); input
|
||||
/// </summary>
|
||||
/// <param name="procedureName"></param>
|
||||
/// <param name="parameters"></param>
|
||||
/// <returns></returns>
|
||||
//public DataTable UseStoredProcedureToDataTable(string procedureName, List<SugarParameter> parameters)
|
||||
//{
|
||||
// return base.Context.Ado.UseStoredProcedure().GetDataTable(procedureName, parameters);
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// 带output返回值
|
||||
/// var list = new List<SugarParameter>();
|
||||
/// list.Add(new SugarParameter(ParaName, ParaValue, true)); output
|
||||
/// list.Add(new SugarParameter(ParaName, ParaValue)); input
|
||||
/// </summary>
|
||||
/// <param name="procedureName"></param>
|
||||
/// <param name="parameters"></param>
|
||||
/// <returns></returns>
|
||||
//public (DataTable, List<SugarParameter>) UseStoredProcedureToTuple(string procedureName, List<SugarParameter> parameters)
|
||||
//{
|
||||
// var result = (base.Context.Ado.UseStoredProcedure().GetDataTable(procedureName, parameters), parameters);
|
||||
// return result;
|
||||
//}
|
||||
|
||||
public string QueryableToJson(string select, Expression<Func<T, bool>> expressionWhere)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,18 +15,12 @@ namespace ZR.Repository.DbProvider
|
||||
|
||||
/// <summary>
|
||||
/// 使用SugarSql获取连接对象
|
||||
/// 构造方法有问题
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public SugarDbContext()
|
||||
{
|
||||
string connStr = ConfigUtils.Instance.GetConnectionStrings(OptionsSetting.ConnAdmin);
|
||||
string dbKey = ConfigUtils.Instance.GetAppConfig<string>(OptionsSetting.DbKey);
|
||||
int dbType = ConfigUtils.Instance.GetAppConfig<int>(OptionsSetting.ConnDbType);
|
||||
if (!string.IsNullOrEmpty(dbKey))
|
||||
{
|
||||
connStr = NETCore.Encrypt.EncryptProvider.DESDecrypt(connStr, dbKey);
|
||||
}
|
||||
|
||||
Db = new SqlSugarClient(new List<ConnectionConfig>()
|
||||
{
|
||||
@@ -39,18 +33,18 @@ namespace ZR.Repository.DbProvider
|
||||
},
|
||||
});
|
||||
|
||||
//调式代码 用来打印SQL
|
||||
Db.Aop.OnLogExecuting = (sql, pars) =>
|
||||
{
|
||||
Console.BackgroundColor = ConsoleColor.Yellow;
|
||||
Console.WriteLine("【SQL语句】" + sql.ToLower() + "\r\n" + Db.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value)));
|
||||
};
|
||||
//出错打印日志
|
||||
Db.Aop.OnError = (e) =>
|
||||
{
|
||||
Console.WriteLine($"[执行Sql出错]{e.Message},SQL={e.Sql}");
|
||||
Console.WriteLine();
|
||||
};
|
||||
////调式代码 用来打印SQL
|
||||
//Db.Aop.OnLogExecuting = (sql, pars) =>
|
||||
//{
|
||||
// Console.BackgroundColor = ConsoleColor.Yellow;
|
||||
// Console.WriteLine("【SQL语句】" + sql.ToLower() + "\r\n" + Db.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value)));
|
||||
//};
|
||||
////出错打印日志
|
||||
//Db.Aop.OnError = (e) =>
|
||||
//{
|
||||
// Console.WriteLine($"[执行Sql出错]{e.Message},SQL={e.Sql}");
|
||||
// Console.WriteLine();
|
||||
//};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Dynamic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ZR.Repository
|
||||
{
|
||||
public interface IBaseRepository<T> where T : class, new()
|
||||
{
|
||||
#region add
|
||||
int Add(T parm, Expression<Func<T, object>> iClumns = null, bool ignoreNull = true);
|
||||
int Insert(T t, bool IgnoreNullColumn = true);
|
||||
|
||||
int InsertIgnoreNullColumn(T t);
|
||||
|
||||
int InsertIgnoreNullColumn(T t, params string[] columns);
|
||||
|
||||
//int Insert(SqlSugarClient client, T t);
|
||||
|
||||
long InsertBigIdentity(T t);
|
||||
|
||||
int Insert(List<T> t);
|
||||
int Insert(T parm, Expression<Func<T, object>> iClumns = null, bool ignoreNull = true);
|
||||
|
||||
int InsertIgnoreNullColumn(List<T> t);
|
||||
|
||||
int InsertIgnoreNullColumn(List<T> t, params string[] columns);
|
||||
|
||||
DbResult<bool> InsertTran(T t);
|
||||
|
||||
DbResult<bool> InsertTran(List<T> t);
|
||||
|
||||
T InsertReturnEntity(T t);
|
||||
|
||||
T InsertReturnEntity(T t, string sqlWith = SqlWith.UpdLock);
|
||||
|
||||
bool ExecuteCommand(string sql, object parameters);
|
||||
|
||||
bool ExecuteCommand(string sql, params SugarParameter[] parameters);
|
||||
|
||||
bool ExecuteCommand(string sql, List<SugarParameter> parameters);
|
||||
|
||||
#endregion add
|
||||
|
||||
#region update
|
||||
|
||||
bool UpdateEntity(T entity, bool ignoreNullColumns = false);
|
||||
|
||||
bool Update(T entity, Expression<Func<T, bool>> expression);
|
||||
|
||||
/// <summary>
|
||||
/// 只更新表达式的值
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <param name="expression"></param>
|
||||
/// <returns></returns>
|
||||
bool Update(T entity, Expression<Func<T, object>> expression, bool ignoreAllNull = false);
|
||||
|
||||
bool Update(T entity, Expression<Func<T, object>> expression, Expression<Func<T, bool>> where);
|
||||
|
||||
bool Update(SqlSugarClient client, T entity, Expression<Func<T, object>> expression, Expression<Func<T, bool>> where);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="entity">T</param>
|
||||
/// <param name="list">忽略更新</param>
|
||||
/// <param name="isNull">Null不更新</param>
|
||||
/// <returns></returns>
|
||||
bool Update(T entity, List<string> list = null, bool isNull = true);
|
||||
|
||||
bool Update(List<T> entity);
|
||||
bool Update(Expression<Func<T, bool>> where, Expression<Func<T, T>> columns);
|
||||
|
||||
#endregion update
|
||||
|
||||
//DbResult<bool> UseTran(Action action);
|
||||
|
||||
//DbResult<bool> UseTran(SqlSugarClient client, Action action);
|
||||
|
||||
//bool UseTran2(Action action);
|
||||
|
||||
#region delete
|
||||
|
||||
bool Delete(Expression<Func<T, bool>> expression);
|
||||
|
||||
//bool Delete<PkType>(PkType[] primaryKeyValues);
|
||||
|
||||
bool Delete(object[] obj);
|
||||
bool Delete(object id);
|
||||
bool Delete();
|
||||
|
||||
#endregion delete
|
||||
|
||||
#region query
|
||||
|
||||
bool IsAny(Expression<Func<T, bool>> expression);
|
||||
|
||||
ISugarQueryable<T> Queryable();
|
||||
|
||||
//ISugarQueryable<ExpandoObject> Queryable(string tableName, string shortName);
|
||||
|
||||
//ISugarQueryable<T, T1, T2> Queryable<T1, T2>() where T1 : class where T2 : new();
|
||||
|
||||
List<T> QueryableToList(Expression<Func<T, bool>> expression);
|
||||
|
||||
Task<List<T>> QueryableToListAsync(Expression<Func<T, bool>> expression);
|
||||
|
||||
//string QueryableToJson(string select, Expression<Func<T, bool>> expressionWhere);
|
||||
|
||||
List<T> QueryableToList(string tableName);
|
||||
|
||||
T QueryableToEntity(Expression<Func<T, bool>> expression);
|
||||
|
||||
List<T> QueryableToList(string tableName, Expression<Func<T, bool>> expression);
|
||||
|
||||
(List<T>, int) QueryableToPage(Expression<Func<T, bool>> expression, int pageIndex = 0, int pageSize = 10);
|
||||
|
||||
(List<T>, int) QueryableToPage(Expression<Func<T, bool>> expression, string order, int pageIndex = 0, int pageSize = 10);
|
||||
|
||||
(List<T>, int) QueryableToPage(Expression<Func<T, bool>> expression, Expression<Func<T, object>> orderFiled, string orderBy, int pageIndex = 0, int pageSize = 10);
|
||||
|
||||
//(List<T>, int) QueryableToPage(Expression<Func<T, bool>> expression, Bootstrap.BootstrapParams bootstrap);
|
||||
|
||||
List<T> SqlQueryToList(string sql, object obj = null);
|
||||
/// <summary>
|
||||
/// 获得一条数据
|
||||
/// </summary>
|
||||
/// <param name="where">Expression<Func<T, bool>></param>
|
||||
/// <returns></returns>
|
||||
T GetFirst(Expression<Func<T, bool>> where);
|
||||
T GetId(object pkValue);
|
||||
|
||||
/// <summary>
|
||||
/// 获得一条数据
|
||||
/// </summary>
|
||||
/// <param name="parm">string</param>
|
||||
/// <returns></returns>
|
||||
T GetFirst(string parm);
|
||||
|
||||
#endregion query
|
||||
|
||||
#region Procedure
|
||||
|
||||
//DataTable UseStoredProcedureToDataTable(string procedureName, List<SugarParameter> parameters);
|
||||
|
||||
//(DataTable, List<SugarParameter>) UseStoredProcedureToTuple(string procedureName, List<SugarParameter> parameters);
|
||||
|
||||
#endregion Procedure
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using Infrastructure.Attribute;
|
||||
using ZR.Repository.System;
|
||||
using ZR.Model.Models;
|
||||
using SqlSugar;
|
||||
|
||||
namespace ZR.Repository
|
||||
{
|
||||
/// <summary>
|
||||
/// 代码生成演示仓储接口的实现
|
||||
///
|
||||
/// @author zhaorui
|
||||
/// @date 2021-09-24
|
||||
/// </summary>
|
||||
[AppService(ServiceLifetime = LifeTime.Transient)]
|
||||
public class GendemoRepository : BaseRepository<Gendemo>
|
||||
{
|
||||
public GendemoRepository(SqlSugarClient dbContext) : base(dbContext)
|
||||
{
|
||||
}
|
||||
#region 业务逻辑代码
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ZR.Model.System.Generate;
|
||||
|
||||
namespace ZR.Repository.System
|
||||
{
|
||||
public class GenTableRepository : BaseRepository<GenTable>
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public class GenTableColumnRepository : BaseRepository<GenTableColumn>
|
||||
{
|
||||
/// <summary>
|
||||
/// 根据表id批量删除表字段
|
||||
/// </summary>
|
||||
/// <param name="tableId"></param>
|
||||
/// <returns></returns>
|
||||
public int DeleteGenTableColumn(long[] tableId)
|
||||
{
|
||||
return Context.Deleteable<GenTableColumn>().Where(f => tableId.Contains(f.TableId)).ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据表名删除字段
|
||||
/// </summary>
|
||||
/// <param name="tableName"></param>
|
||||
/// <returns></returns>
|
||||
public int DeleteGenTableColumnByTableName(string tableName)
|
||||
{
|
||||
return Context.Deleteable<GenTableColumn>().Where(f => f.TableName == tableName).ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取表所有字段
|
||||
/// </summary>
|
||||
/// <param name="tableId"></param>
|
||||
/// <returns></returns>
|
||||
public List<GenTableColumn> GenTableColumns(long tableId)
|
||||
{
|
||||
return Context.Queryable<GenTableColumn>().Where(f => f.TableId == tableId).OrderBy(x => x.Sort).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 插入表字段
|
||||
/// </summary>
|
||||
/// <param name="tableColumn"></param>
|
||||
/// <returns></returns>
|
||||
public int InsertGenTableColumn(List<GenTableColumn> tableColumn)
|
||||
{
|
||||
return Context.Insertable(tableColumn).IgnoreColumns(x => new { x.Remark }).ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量更新表字段
|
||||
/// </summary>
|
||||
/// <param name="tableColumn"></param>
|
||||
/// <returns></returns>
|
||||
public int UpdateGenTableColumn(List<GenTableColumn> tableColumn)
|
||||
{
|
||||
foreach (var item in tableColumn)
|
||||
{
|
||||
Context.Updateable<GenTableColumn>()
|
||||
.Where(f => f.TableId == item.TableId)
|
||||
.SetColumns(it => new GenTableColumn()
|
||||
{
|
||||
ColumnComment = item.ColumnComment,
|
||||
CsharpField = item.CsharpField,
|
||||
CsharpType = item.CsharpType,
|
||||
IsQuery = item.IsQuery,
|
||||
IsEdit = item.IsEdit,
|
||||
IsInsert = item.IsInsert,
|
||||
IsList = item.IsList,
|
||||
QueryType = item.QueryType,
|
||||
HtmlType = item.HtmlType,
|
||||
IsRequired = item.IsRequired,
|
||||
Sort = item.Sort,
|
||||
Update_time = DateTime.Now,
|
||||
DictType = item.DictType
|
||||
})
|
||||
.Where(f => f.ColumnId == item.ColumnId)
|
||||
.ExecuteCommand();
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ namespace ZR.Repository.System
|
||||
/// 部门管理
|
||||
/// </summary>
|
||||
[AppService(ServiceLifetime= LifeTime.Transient)]
|
||||
public class SysDeptRepository : BaseRepository
|
||||
public class SysDeptRepository : BaseRepository<SysDept>
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
@@ -19,12 +19,12 @@ namespace ZR.Repository.System
|
||||
{
|
||||
string sql = "select * from sys_dept where find_in_set(@deptId, ancestors)";
|
||||
|
||||
return Db.SqlQueryable<SysDept>(sql).AddParameters(new { @deptId = deptId }).ToList();
|
||||
return Context.SqlQueryable<SysDept>(sql).AddParameters(new { @deptId = deptId }).ToList();
|
||||
}
|
||||
|
||||
public int UdateDeptChildren(SysDept dept)
|
||||
{
|
||||
return Db.Updateable(dept).UpdateColumns(it => new { it.Ancestors }).ExecuteCommand();
|
||||
return Context.Updateable(dept).UpdateColumns(it => new { it.Ancestors }).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace ZR.Repository.System
|
||||
/// 字典数据
|
||||
/// </summary>
|
||||
[AppService(ServiceLifetime = LifeTime.Transient)]
|
||||
public class SysDictDataRepository : BaseRepository
|
||||
public class SysDictDataRepository : BaseRepository<SysDictData>
|
||||
{
|
||||
/// <summary>
|
||||
/// 字典类型数据搜索
|
||||
@@ -18,7 +18,7 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public List<SysDictData> SelectDictDataList(SysDictData dictData)
|
||||
{
|
||||
return Db.Queryable<SysDictData>()
|
||||
return Context.Queryable<SysDictData>()
|
||||
.WhereIF(!string.IsNullOrEmpty(dictData.DictLabel), it => it.DictLabel.Contains(dictData.DictLabel))
|
||||
.WhereIF(!string.IsNullOrEmpty(dictData.Status), it => it.Status == dictData.Status)
|
||||
.WhereIF(!string.IsNullOrEmpty(dictData.DictType), it => it.DictType == dictData.DictType)
|
||||
@@ -32,7 +32,7 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public List<SysDictData> SelectDictDataByType(string dictType)
|
||||
{
|
||||
return Db.Queryable<SysDictData>().Where(f => f.Status == "0" && f.DictType == dictType)
|
||||
return Context.Queryable<SysDictData>().Where(f => f.Status == "0" && f.DictType == dictType)
|
||||
.OrderBy(it => it.DictSort)
|
||||
.ToList();
|
||||
}
|
||||
@@ -44,7 +44,7 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public long InsertDictData(SysDictData dict)
|
||||
{
|
||||
var result = Db.Insertable(dict).IgnoreColumns(it => new { dict.Update_by })
|
||||
var result = Context.Insertable(dict).IgnoreColumns(it => new { dict.Update_by })
|
||||
.ExecuteReturnIdentity();
|
||||
return result;
|
||||
}
|
||||
@@ -56,7 +56,7 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public long UpdateDictData(SysDictData dict)
|
||||
{
|
||||
return Db.Updateable<SysDictData>()
|
||||
return Context.Updateable<SysDictData>()
|
||||
.SetColumns(t => new SysDictData()
|
||||
{
|
||||
Remark = dict.Remark,
|
||||
@@ -76,7 +76,7 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public int DeleteDictDataByIds(long[] dictCodes)
|
||||
{
|
||||
return Db.Deleteable<SysDictData>().In(dictCodes).ExecuteCommand();
|
||||
return Context.Deleteable<SysDictData>().In(dictCodes).ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -88,7 +88,7 @@ namespace ZR.Repository.System
|
||||
public int UpdateDictDataType(string old_dictType, string new_dictType)
|
||||
{
|
||||
//只更新DictType字段根据where条件
|
||||
return Db.Updateable<SysDictData>()
|
||||
return Context.Updateable<SysDictData>()
|
||||
.SetColumns(t => new SysDictData() { DictType = new_dictType })
|
||||
.Where(f => f.DictType == old_dictType)
|
||||
.ExecuteCommand();
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace ZR.Repository.System
|
||||
/// 字典
|
||||
/// </summary>
|
||||
[AppService(ServiceLifetime = LifeTime.Transient)]
|
||||
public class SysDictRepository : BaseRepository
|
||||
public class SysDictRepository : BaseRepository<SysDictType>
|
||||
{
|
||||
/// <summary>
|
||||
/// 查询字段类型列表
|
||||
@@ -20,7 +20,7 @@ namespace ZR.Repository.System
|
||||
public List<SysDictType> SelectDictTypeList(SysDictType dictType, Model.PagerInfo pager)
|
||||
{
|
||||
var totalNum = 0;
|
||||
var list = Db
|
||||
var list = Context
|
||||
.Queryable<SysDictType>()
|
||||
.WhereIF(!string.IsNullOrEmpty(dictType.DictName), it => it.DictName.Contains(dictType.DictName))
|
||||
.WhereIF(!string.IsNullOrEmpty(dictType.Status), it => it.Status == dictType.Status)
|
||||
@@ -37,7 +37,7 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public int DeleteDictTypeByIds(long[] id)
|
||||
{
|
||||
return Db.Deleteable<SysDictType>().In(id).ExecuteCommand();
|
||||
return Context.Deleteable<SysDictType>().In(id).ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -47,7 +47,7 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public int UpdateDictType(SysDictType dictType)
|
||||
{
|
||||
return Db.Updateable(dictType).IgnoreColumns(it => new { dictType.Create_by }).ExecuteCommand();
|
||||
return Context.Updateable(dictType).IgnoreColumns(it => new { dictType.Create_by }).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ using ZR.Model.System;
|
||||
namespace ZR.Repository.System
|
||||
{
|
||||
[AppService(ServiceLifetime = LifeTime.Transient)]
|
||||
public class SysLogininfoRepository : BaseRepository
|
||||
public class SysLogininfoRepository : BaseRepository<SysLogininfor>
|
||||
{
|
||||
/// <summary>
|
||||
/// 查询登录日志
|
||||
@@ -19,7 +19,7 @@ namespace ZR.Repository.System
|
||||
public List<SysLogininfor> GetLoginLog(SysLogininfor logininfoDto, PagerInfo pager)
|
||||
{
|
||||
int totalCount = 0;
|
||||
var list = Db.Queryable<SysLogininfor>()
|
||||
var list = Context.Queryable<SysLogininfor>()
|
||||
.Where(it => it.loginTime >= logininfoDto.BeginTime && it.loginTime <= logininfoDto.EndTime)
|
||||
.WhereIF(logininfoDto.ipaddr.IfNotEmpty(), f => f.ipaddr == logininfoDto.ipaddr)
|
||||
.WhereIF(logininfoDto.userName.IfNotEmpty(), f => f.userName.Contains(logininfoDto.userName))
|
||||
@@ -38,7 +38,7 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public void AddLoginInfo(SysLogininfor sysLogininfor)
|
||||
{
|
||||
int result = Db.Insertable(sysLogininfor)
|
||||
int result = Context.Insertable(sysLogininfor)
|
||||
.IgnoreColumns(it => new { it.Create_by, it.Create_time, it.Remark })
|
||||
.ExecuteReturnIdentity();
|
||||
}
|
||||
@@ -50,7 +50,7 @@ namespace ZR.Repository.System
|
||||
{
|
||||
string sql = "truncate table sys_logininfor";
|
||||
|
||||
Db.Ado.ExecuteCommand(sql);
|
||||
Context.Ado.ExecuteCommand(sql);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -60,7 +60,7 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public int DeleteLogininforByIds(long[] ids)
|
||||
{
|
||||
return Db.Deleteable<SysLogininfor>().In(ids).ExecuteCommand();
|
||||
return Context.Deleteable<SysLogininfor>().In(ids).ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -70,7 +70,7 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public SysUser Login(LoginBodyDto user)
|
||||
{
|
||||
return Db.Queryable<SysUser>().First(it => it.UserName == user.Username && it.Password == user.Password);
|
||||
return Context.Queryable<SysUser>().First(it => it.UserName == user.Username && it.Password == user.Password);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -81,7 +81,8 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public void UpdateLoginInfo(LoginBodyDto user, long userId)
|
||||
{
|
||||
Db.Updateable(new SysUser() { LoginIP = user.LoginIP, LoginDate = Db.GetDate(), UserId = userId })
|
||||
var db = Context;
|
||||
db.Updateable(new SysUser() { LoginIP = user.LoginIP, LoginDate = db.GetDate(), UserId = userId })
|
||||
.UpdateColumns(it => new { it.LoginIP, it.LoginDate })
|
||||
.ExecuteCommand();
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace ZR.Repository.System
|
||||
/// 系统菜单
|
||||
/// </summary>
|
||||
[AppService(ServiceLifetime = LifeTime.Transient)]
|
||||
public class SysMenuRepository : BaseRepository
|
||||
public class SysMenuRepository : BaseRepository<SysMenu>
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取所有菜单(菜单管理)
|
||||
@@ -20,7 +20,7 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public List<SysMenu> SelectMenuList(SysMenu menu)
|
||||
{
|
||||
return Db.Queryable<SysMenu>()
|
||||
return Context.Queryable<SysMenu>()
|
||||
.WhereIF(!string.IsNullOrEmpty(menu.menuName), it => it.menuName.Contains(menu.menuName))
|
||||
.WhereIF(!string.IsNullOrEmpty(menu.visible), it => it.visible == menu.visible)
|
||||
.WhereIF(!string.IsNullOrEmpty(menu.status), it => it.status == menu.status)
|
||||
@@ -36,7 +36,7 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public List<SysMenu> SelectMenuListByUserId(SysMenu sysMenu, long userId)
|
||||
{
|
||||
return Db.Queryable<SysMenu, SysRoleMenu, SysUserRole, SysRole>((menu, roleMenu, userRole, role) => new JoinQueryInfos(
|
||||
return Context.Queryable<SysMenu, SysRoleMenu, SysUserRole, SysRole>((menu, roleMenu, userRole, role) => new JoinQueryInfos(
|
||||
JoinType.Left, menu.menuId == roleMenu.Menu_id,
|
||||
JoinType.Left, roleMenu.Role_id == userRole.RoleId,
|
||||
JoinType.Left, userRole.RoleId == role.RoleId
|
||||
@@ -60,7 +60,7 @@ namespace ZR.Repository.System
|
||||
{
|
||||
var menuTypes = new string[] { "M", "C" };
|
||||
|
||||
return Db.Queryable<SysMenu>()
|
||||
return Context.Queryable<SysMenu>()
|
||||
.Where(f => f.status == "0" && menuTypes.Contains(f.menuType))
|
||||
.OrderBy(it => new { it.parentId, it.orderNum }).ToList();
|
||||
}
|
||||
@@ -73,7 +73,7 @@ namespace ZR.Repository.System
|
||||
public List<SysMenu> SelectMenuTreeByRoleIds(List<long> roleIds)
|
||||
{
|
||||
var menuTypes = new string[] { "M", "C"};
|
||||
return Db.Queryable<SysMenu, SysRoleMenu>((menu, roleMenu) => new JoinQueryInfos(
|
||||
return Context.Queryable<SysMenu, SysRoleMenu>((menu, roleMenu) => new JoinQueryInfos(
|
||||
JoinType.Left, menu.menuId == roleMenu.Menu_id
|
||||
))
|
||||
.Where((menu, roleMenu) => roleIds.Contains(roleMenu.Role_id) && menuTypes.Contains(menu.menuType) && menu.status == "0")
|
||||
@@ -90,7 +90,7 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public SysMenu SelectMenuById(int menuId)
|
||||
{
|
||||
return Db.Queryable<SysMenu>().Where(it => it.menuId == menuId).Single();
|
||||
return Context.Queryable<SysMenu>().Where(it => it.menuId == menuId).Single();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -100,6 +100,7 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public int AddMenu(SysMenu menu)
|
||||
{
|
||||
var Db = Context;
|
||||
menu.Create_time = Db.GetDate();
|
||||
menu.menuId = Db.Insertable(menu).ExecuteReturnIdentity();
|
||||
return 1;
|
||||
@@ -112,7 +113,7 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public int EditMenu(SysMenu menu)
|
||||
{
|
||||
return Db.Updateable(menu).ExecuteCommand();
|
||||
return Context.Updateable(menu).ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -122,7 +123,7 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public int DeleteMenuById(int menuId)
|
||||
{
|
||||
return Db.Deleteable<SysMenu>().Where(it => it.menuId == menuId).ExecuteCommand();
|
||||
return Context.Deleteable<SysMenu>().Where(it => it.menuId == menuId).ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -132,7 +133,7 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public int ChangeSortMenu(MenuDto menuDto)
|
||||
{
|
||||
var result = Db.Updateable(new SysMenu() { menuId = menuDto.MenuId, orderNum = menuDto.orderNum })
|
||||
var result = Context.Updateable(new SysMenu() { menuId = menuDto.MenuId, orderNum = menuDto.orderNum })
|
||||
.UpdateColumns(it => new { it.orderNum }).ExecuteCommand();
|
||||
return result;
|
||||
}
|
||||
@@ -144,7 +145,7 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public List<SysMenu> SelectMenuPermsByUserId(long userId)
|
||||
{
|
||||
return Db.Queryable<SysMenu, SysRoleMenu, SysUserRole, SysRole>((m, rm, ur, r) => new JoinQueryInfos(
|
||||
return Context.Queryable<SysMenu, SysRoleMenu, SysUserRole, SysRole>((m, rm, ur, r) => new JoinQueryInfos(
|
||||
JoinType.Left, m.menuId == rm.Menu_id,
|
||||
JoinType.Left, rm.Role_id == ur.RoleId,
|
||||
JoinType.Left, ur.RoleId == r.RoleId
|
||||
@@ -161,7 +162,7 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public SysMenu CheckMenuNameUnique(SysMenu menu)
|
||||
{
|
||||
return Db.Queryable<SysMenu>()
|
||||
return Context.Queryable<SysMenu>()
|
||||
.Where(it => it.menuName == menu.menuName && it.parentId == menu.parentId).Single();
|
||||
}
|
||||
|
||||
@@ -172,7 +173,7 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public int HasChildByMenuId(long menuId)
|
||||
{
|
||||
return Db.Queryable<SysMenu>().Where(it => it.parentId == menuId).Count();
|
||||
return Context.Queryable<SysMenu>().Where(it => it.parentId == menuId).Count();
|
||||
}
|
||||
|
||||
#region RoleMenu
|
||||
@@ -184,7 +185,7 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public int CheckMenuExistRole(long menuId)
|
||||
{
|
||||
return Db.Queryable<SysRoleMenu>().Where(it => it.Menu_id == menuId).Count();
|
||||
return Context.Queryable<SysRoleMenu>().Where(it => it.Menu_id == menuId).Count();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -8,7 +8,7 @@ using ZR.Model.System;
|
||||
namespace ZR.Repository.System
|
||||
{
|
||||
[AppService(ServiceLifetime = LifeTime.Transient)]
|
||||
public class SysOperLogRepository : BaseRepository
|
||||
public class SysOperLogRepository : BaseRepository<SysOperLog>
|
||||
{
|
||||
/// <summary>
|
||||
/// 查询操作日志
|
||||
@@ -19,7 +19,7 @@ namespace ZR.Repository.System
|
||||
public List<SysOperLog> GetSysOperLog(SysOperLogDto sysOper, PagerInfo pagerInfo)
|
||||
{
|
||||
int totalCount = 0;
|
||||
var list = Db.Queryable<SysOperLog>()
|
||||
var list = Context.Queryable<SysOperLog>()
|
||||
.Where(it => it.operTime >= sysOper.BeginTime && it.operTime <= sysOper.EndTime)
|
||||
.WhereIF(sysOper.Title.IfNotEmpty(), it => it.title.Contains(sysOper.Title))
|
||||
.WhereIF(sysOper.operName.IfNotEmpty(), it => it.operName.Contains(sysOper.operName))
|
||||
@@ -38,7 +38,7 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public void AddSysOperLog(SysOperLog sysOperLog)
|
||||
{
|
||||
Db.Insertable(sysOperLog).ExecuteCommandAsync();
|
||||
Context.Insertable(sysOperLog).ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -47,7 +47,7 @@ namespace ZR.Repository.System
|
||||
public void ClearOperLog()
|
||||
{
|
||||
string sql = "truncate table sys_oper_log";
|
||||
Db.Ado.ExecuteCommand(sql);
|
||||
Context.Ado.ExecuteCommand(sql);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -57,7 +57,7 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public int DeleteOperLogByIds(long[] operIds)
|
||||
{
|
||||
return Db.Deleteable<SysOperLog>().In(operIds).ExecuteCommand();
|
||||
return Context.Deleteable<SysOperLog>().In(operIds).ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -67,7 +67,7 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public SysOperLog SelectOperLogById(long operId)
|
||||
{
|
||||
return Db.Queryable<SysOperLog>().InSingle(operId);
|
||||
return Context.Queryable<SysOperLog>().InSingle(operId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ZR.Model.System;
|
||||
|
||||
namespace ZR.Repository.System
|
||||
{
|
||||
public class SysPostRepository : BaseRepository<SysPost>
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ namespace ZR.Repository.System
|
||||
/// 角色操作类
|
||||
/// </summary>
|
||||
[AppService(ServiceLifetime = LifeTime.Transient)]
|
||||
public class SysRoleRepository : BaseRepository
|
||||
public class SysRoleRepository : BaseRepository<SysRole>
|
||||
{
|
||||
/// <summary>
|
||||
/// 根据条件分页查询角色数据
|
||||
@@ -17,7 +17,7 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public List<SysRole> SelectRoleList(SysRole sysRole)
|
||||
{
|
||||
return Db.Queryable<SysRole>()
|
||||
return Context.Queryable<SysRole>()
|
||||
.Where(role => role.DelFlag == "0")
|
||||
.WhereIF(!string.IsNullOrEmpty(sysRole.RoleName), role => role.RoleName.Contains(sysRole.RoleName))
|
||||
.WhereIF(!string.IsNullOrEmpty(sysRole.Status), role => role.Status == sysRole.Status)
|
||||
@@ -33,7 +33,7 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public List<SysRole> SelectRolePermissionByUserId(long userId)
|
||||
{
|
||||
return Db.Queryable<SysRole>()
|
||||
return Context.Queryable<SysRole>()
|
||||
.Where(role => role.DelFlag == "0")
|
||||
.Where(it => SqlFunc.Subqueryable<SysUserRole>().Where(s => s.UserId == userId).Any())
|
||||
.OrderBy(role => role.RoleSort)
|
||||
@@ -46,7 +46,7 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public List<SysRole> SelectRoleAll()
|
||||
{
|
||||
return Db.Queryable<SysRole>().OrderBy(it => it.RoleSort).ToList();
|
||||
return Context.Queryable<SysRole>().OrderBy(it => it.RoleSort).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -56,7 +56,7 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public SysRole SelectRoleById(long roleId)
|
||||
{
|
||||
return Db.Queryable<SysRole>().InSingle(roleId);
|
||||
return Context.Queryable<SysRole>().InSingle(roleId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -66,7 +66,7 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public int DeleteRoleByRoleIds(long[] roleId)
|
||||
{
|
||||
return Db.Deleteable<SysRole>().In(roleId).ExecuteCommand();
|
||||
return Context.Deleteable<SysRole>().In(roleId).ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -76,7 +76,7 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public List<SysRole> SelectUserRoleListByUserId(long userId)
|
||||
{
|
||||
return Db.Queryable<SysUserRole, SysRole>((ur, r) => new SqlSugar.JoinQueryInfos(
|
||||
return Context.Queryable<SysUserRole, SysRole>((ur, r) => new SqlSugar.JoinQueryInfos(
|
||||
SqlSugar.JoinType.Left, ur.RoleId == r.RoleId
|
||||
)).Where((ur, r) => ur.UserId == userId)
|
||||
.Select((ur, r) => r).ToList();
|
||||
@@ -91,7 +91,7 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public List<SysRoleMenu> SelectRoleMenuByRoleId(long roleId)
|
||||
{
|
||||
return Db.Queryable<SysRoleMenu>().Where(it => it.Role_id == roleId).ToList();
|
||||
return Context.Queryable<SysRoleMenu>().Where(it => it.Role_id == roleId).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -101,7 +101,7 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public int AddRoleMenu(List<SysRoleMenu> sysRoleMenus)
|
||||
{
|
||||
return Db.Insertable(sysRoleMenus).ExecuteCommand();
|
||||
return Context.Insertable(sysRoleMenus).ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -111,7 +111,7 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public int DeleteRoleMenuByRoleId(long roleId)
|
||||
{
|
||||
return Db.Deleteable<SysRoleMenu>().Where(it => it.Role_id == roleId).ExecuteCommand();
|
||||
return Context.Deleteable<SysRoleMenu>().Where(it => it.Role_id == roleId).ExecuteCommand();
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -123,8 +123,8 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public long InsertRole(SysRole sysRole)
|
||||
{
|
||||
sysRole.Create_time = Db.GetDate();
|
||||
return Db.Insertable(sysRole).ExecuteReturnBigIdentity();
|
||||
sysRole.Create_time = Context.GetDate();
|
||||
return Context.Insertable(sysRole).ExecuteReturnBigIdentity();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -134,7 +134,7 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public int UpdateSysRole(SysRole sysRole)
|
||||
{
|
||||
var db = Db;
|
||||
var db = Context;
|
||||
sysRole.Update_time = db.GetDate();
|
||||
|
||||
return db.Updateable<SysRole>()
|
||||
@@ -156,7 +156,7 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public int UpdateRoleStatus(SysRole role)
|
||||
{
|
||||
return Db.Updateable(role).UpdateColumns(t => new { t.Status }).ExecuteCommand();
|
||||
return Context.Updateable(role).UpdateColumns(t => new { t.Status }).ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -166,7 +166,7 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public SysRole CheckRoleKeyUnique(string roleKey)
|
||||
{
|
||||
return Db.Queryable<SysRole>().Where(it => it.RoleKey == roleKey).Single();
|
||||
return Context.Queryable<SysRole>().Where(it => it.RoleKey == roleKey).Single();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -176,7 +176,7 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public SysRole CheckRoleNameUnique(string roleName)
|
||||
{
|
||||
return Db.Queryable<SysRole>().Where(it => it.RoleName == roleName).Single();
|
||||
return Context.Queryable<SysRole>().Where(it => it.RoleName == roleName).Single();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace ZR.Repository.System
|
||||
/// 用户岗位
|
||||
/// </summary>
|
||||
[AppService(ServiceLifetime = LifeTime.Transient)]
|
||||
public class SysUserPostRepository : BaseRepository
|
||||
public class SysUserPostRepository : BaseRepository<SysUserPost>
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取用户岗位
|
||||
@@ -18,7 +18,7 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public List<SysPost> SelectPostsByUserId(long userId)
|
||||
{
|
||||
return Db.Queryable<SysPost, SysUserPost>((p, up) => new JoinQueryInfos(
|
||||
return Context.Queryable<SysPost, SysUserPost>((p, up) => new JoinQueryInfos(
|
||||
JoinType.Left, up.PostId == p.PostId
|
||||
)).Where((p, up) => up.UserId == userId)
|
||||
.Select<SysPost>().ToList();
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace ZR.Repository.System
|
||||
/// 用户管理
|
||||
/// </summary>
|
||||
[AppService(ServiceLifetime = LifeTime.Transient)]
|
||||
public class SysUserRepository : BaseRepository
|
||||
public class SysUserRepository : BaseRepository<SysUser>
|
||||
{
|
||||
/// <summary>
|
||||
/// 根据条件分页查询用户列表
|
||||
@@ -25,7 +25,7 @@ namespace ZR.Repository.System
|
||||
left join sys_dept d on u.deptId = d.deptId
|
||||
WHERE u.delFlag = '0' ";
|
||||
int totalCount = 0;
|
||||
var list = Db.SqlQueryable<SysUser>(sql)
|
||||
var list = Context.SqlQueryable<SysUser>(sql)
|
||||
.WhereIF(!string.IsNullOrEmpty(user.UserName), it => it.UserName.Contains(user.UserName))
|
||||
.WhereIF(!string.IsNullOrEmpty(user.Status), it => it.Status == user.Status)
|
||||
.WhereIF(user.BeginTime != DateTime.MinValue && user.BeginTime != null, it => it.Create_time >= user.BeginTime)
|
||||
@@ -44,7 +44,7 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public SysUser SelectUserById(long userId)
|
||||
{
|
||||
return Db.Queryable<SysUser>().Where(f => f.UserId == userId).First();
|
||||
return Context.Queryable<SysUser>().Where(f => f.UserId == userId).First();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -54,7 +54,7 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public int CheckUserNameUnique(string userName)
|
||||
{
|
||||
return Db.Queryable<SysUser>().Where(it => it.UserName == userName).Count();
|
||||
return Context.Queryable<SysUser>().Where(it => it.UserName == userName).Count();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -65,7 +65,7 @@ namespace ZR.Repository.System
|
||||
public int AddUser(SysUser sysUser)
|
||||
{
|
||||
sysUser.Create_time = DateTime.Now;
|
||||
return Db.Insertable(sysUser).ExecuteReturnIdentity();
|
||||
return Context.Insertable(sysUser).ExecuteReturnIdentity();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -76,7 +76,7 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public int ResetPwd(long userid, string password)
|
||||
{
|
||||
return Db.Updateable(new SysUser() { UserId = userid, Password = password })
|
||||
return Context.Updateable(new SysUser() { UserId = userid, Password = password })
|
||||
.UpdateColumns(it => new { it.Password }).ExecuteCommand();
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public int ChangeUserStatus(SysUser user)
|
||||
{
|
||||
return Db.Updateable(user).UpdateColumns(t => new { t.Status })
|
||||
return Context.Updateable(user).UpdateColumns(t => new { t.Status })
|
||||
.ExecuteCommand();
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public int DeleteUser(long userid)
|
||||
{
|
||||
return Db.Updateable(new SysUser() { UserId = userid, DelFlag = "2" })
|
||||
return Context.Updateable(new SysUser() { UserId = userid, DelFlag = "2" })
|
||||
.UpdateColumns(t => t.DelFlag)
|
||||
.ExecuteCommand();
|
||||
}
|
||||
@@ -110,7 +110,7 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public int UpdateUser(SysUser user)
|
||||
{
|
||||
return Db.Updateable(user)
|
||||
return Context.Updateable(user)
|
||||
//.SetColumns(t => new SysUser()
|
||||
//{
|
||||
// UserName = user.UserName,
|
||||
@@ -136,7 +136,7 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public int UpdatePhoto(SysUser user)
|
||||
{
|
||||
return Db.Updateable<SysUser>()
|
||||
return Context.Updateable<SysUser>()
|
||||
.SetColumns(t => new SysUser()
|
||||
{
|
||||
Avatar = user.Avatar
|
||||
|
||||
@@ -6,7 +6,7 @@ using ZR.Model.System;
|
||||
namespace ZR.Repository.System
|
||||
{
|
||||
[AppService(ServiceLifetime = LifeTime.Transient)]
|
||||
public class SysUserRoleRepository : BaseRepository
|
||||
public class SysUserRoleRepository : BaseRepository<SysUserRole>
|
||||
{
|
||||
/// <summary>
|
||||
/// 删除用户角色
|
||||
@@ -15,7 +15,7 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public int DeleteUserRoleByUserId(int userId)
|
||||
{
|
||||
return Db.Deleteable<SysUserRole>().Where(it => it.UserId == userId).ExecuteCommand();
|
||||
return Context.Deleteable<SysUserRole>().Where(it => it.UserId == userId).ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -26,7 +26,7 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public int DeleteRoleUserByUserIds(long roleId, List<long> userIds)
|
||||
{
|
||||
return Db.Deleteable<SysUserRole>().Where(it => it.RoleId == roleId && userIds.Contains(it.UserId))
|
||||
return Context.Deleteable<SysUserRole>().Where(it => it.RoleId == roleId && userIds.Contains(it.UserId))
|
||||
.ExecuteCommand();
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public int AddUserRole(List<SysUserRole> sysUsers)
|
||||
{
|
||||
return Db.Insertable(sysUsers).ExecuteCommand();
|
||||
return Context.Insertable(sysUsers).ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -47,7 +47,7 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public int DeleteUserRoleByRoleId(int roleId)
|
||||
{
|
||||
return Db.Deleteable<SysUserRole>().In(roleId).ExecuteCommand();
|
||||
return Context.Deleteable<SysUserRole>().In(roleId).ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -57,7 +57,7 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public int CountUserRoleByRoleId(long roleId)
|
||||
{
|
||||
return Db.Queryable<SysUserRole>().Where(it => it.RoleId == roleId).Count();
|
||||
return Context.Queryable<SysUserRole>().Where(it => it.RoleId == roleId).Count();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -67,7 +67,7 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public List<SysUser> GetSysUsersByRoleId(long roleId)
|
||||
{
|
||||
return Db.Queryable<SysUserRole, SysUser>((t1, u) => new JoinQueryInfos(
|
||||
return Context.Queryable<SysUserRole, SysUser>((t1, u) => new JoinQueryInfos(
|
||||
JoinType.Left, t1.UserId == u.UserId))
|
||||
.Where((t1, u) => t1.RoleId == roleId && u.DelFlag == "0")
|
||||
.Select((t1, u) => u)
|
||||
|
||||
Reference in New Issue
Block a user