This commit is contained in:
不做码农 2021-09-27 08:06:09 +08:00
parent 48e14b4d4f
commit 40026f596f
53 changed files with 1306 additions and 312 deletions

View File

@ -51,7 +51,7 @@ namespace ZR.Admin.WebApi.Controllers.System
[ActionPermissionFilter(Permission = "system:dict:query")]
public IActionResult GetInfo(long dictId = 0)
{
return SUCCESS(SysDictService.GetFirst(f => f.DictId == dictId));
return SUCCESS(SysDictService(f => f.DictId == dictId));
}
/// <summary>

View File

@ -0,0 +1,137 @@
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using SqlSugar;
using Infrastructure;
using Infrastructure.Attribute;
using Infrastructure.Enums;
using Infrastructure.Model;
using Mapster;
using ZR.Model.Dto;
using ZR.Model.Models;
using ZR.Service.Business;
using ZR.Admin.WebApi.Extensions;
using ZR.Admin.WebApi.Filters;
using ZR.Common;
namespace ZR.Admin.WebApi.Controllers
{
/// <summary>
/// 代码生成演示Controller
///
/// @author zhaorui
/// @date 2021-09-24
/// </summary>
[Verify]
[Route("business/Gendemo")]
public class GendemoController: BaseController
{
/// <summary>
/// 代码生成演示接口
/// </summary>
private readonly IGendemoService _GendemoService;
public GendemoController(IGendemoService GendemoService)
{
_GendemoService = GendemoService;
}
/// <summary>
/// 查询代码生成演示列表
/// </summary>
/// <returns></returns>
[HttpGet("list")]
[ActionPermissionFilter(Permission = "business:gendemo:list")]
public IActionResult QueryGendemo([FromQuery] GendemoQueryDto parm)
{
//开始拼装查询条件
var predicate = Expressionable.Create<Gendemo>();
//TODO 搜索条件
//predicate = predicate.And(m => m.Name.Contains(parm.Name));
var response = _GendemoService.GetPages(predicate.ToExpression(), parm);
return SUCCESS(response);
}
/// <summary>
/// 查询代码生成演示详情
/// </summary>
/// <param name="Id"></param>
/// <returns></returns>
[HttpGet("{Id}")]
[ActionPermissionFilter(Permission = "business:gendemo:query")]
public IActionResult GetGendemo(int Id)
{
var response = _GendemoService.GetId(Id);
return SUCCESS(response);
}
/// <summary>
/// 添加代码生成演示
/// </summary>
/// <returns></returns>
[HttpPost]
[ActionPermissionFilter(Permission = "business:gendemo:add")]
[Log(Title = "{TableDesc}添加", BusinessType = BusinessType.INSERT)]
public IActionResult AddGendemo([FromBody] GendemoDto parm)
{
if (parm == null)
{
throw new CustomException("请求参数错误");
}
//从 Dto 映射到 实体
var model = parm.Adapt<Gendemo>().ToCreate();
return SUCCESS(_GendemoService.Add(model, it => new
{
it.Name, it.Icon, it.ShowStatus, it.Sex, it.Sort,
}));
}
/// <summary>
/// 更新代码生成演示
/// </summary>
/// <returns></returns>
[HttpPut]
[ActionPermissionFilter(Permission = "business:gendemo:update")]
[Log(Title = "{TableDesc}修改", BusinessType = BusinessType.UPDATE)]
public IActionResult UpdateGendemo([FromBody] GendemoDto parm)
{
if (parm == null)
{
throw new CustomException("请求实体不能为空");
}
//从 Dto 映射到 实体
var model = parm.Adapt<Gendemo>().ToUpdate();
var response = _GendemoService.Update(w => w.Id == model.Id, it => new Gendemo()
{
//Update 字段映射
Name = model.Name, Icon = model.Icon, ShowStatus = model.ShowStatus, Sex = model.Sex, Sort = model.Sort,
});
return SUCCESS(response);
}
/// <summary>
/// 删除代码生成演示
/// </summary>
/// <returns></returns>
[HttpDelete("{ids}")]
[ActionPermissionFilter(Permission = "business:gendemo:delete")]
[Log(Title = "{TableDesc}删除", BusinessType = BusinessType.DELETE)]
public IActionResult DeleteGendemo(string ids)
{
int[] idsArr = Tools.SpitIntArrary(ids);
if (idsArr.Length <= 0) { return OutputJson(ApiResult.Error($"删除失败Id 不能为空")); }
var response = _GendemoService.Delete(idsArr);
return SUCCESS(response);
}
}
}

View File

@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using ZR.Model.Dto;
using ZR.Model.Models;
namespace ZR.Model.Dto
{
/// <summary>
/// 代码生成演示输入对象模型
/// </summary>
public class GendemoDto
{
public int Id { get; set; }
public string Name { get; set; }
public string Icon { get; set; }
public int ShowStatus { get; set; }
public int? Sex { get; set; }
public int? Sort { get; set; }
}
/// <summary>
/// 代码生成演示查询对象模型
/// </summary>
public class GendemoQueryDto: PagerInfo
{
public string Name { get; set; }
public DateTime? BeginTime { get; set; }
public DateTime? EndTime { get; set; }
}
}

View File

@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
namespace ZR.Model.Models
{
/// <summary>
/// 代码生成演示,数据实体对象
///
/// @author zhaorui
/// @date 2021-09-24
/// </summary>
[SqlSugar.SugarTable("gen_demo")]
public class Gendemo
{
/// <summary>
/// 描述 :自增id
/// 空值 :False
/// </summary>
[SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
/// <summary>
/// 描述 :名称
/// 空值 :False
/// </summary>
public string Name { get; set; }
/// <summary>
/// 描述 :图片
/// 空值 :True
/// </summary>
public string Icon { get; set; }
/// <summary>
/// 描述 :显示状态
/// 空值 :False
/// </summary>
public int ShowStatus { get; set; }
/// <summary>
/// 描述 :添加时间
/// 空值 :True
/// </summary>
public DateTime? AddTime { get; set; }
/// <summary>
/// 描述 :用户性别
/// 空值 :True
/// </summary>
public int? Sex { get; set; }
/// <summary>
/// 描述 :排序
/// 空值 :True
/// </summary>
public int? Sort { get; set; }
}
}

View File

@ -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();
}
}
}

View File

@ -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();
//};
}
}
}

View File

@ -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
}
}

View File

@ -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
}
}

View File

@ -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;
}
}
}

View File

@ -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();
}
}
}

View File

@ -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();

View File

@ -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();
}
}
}

View File

@ -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();
}

View File

@ -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

View File

@ -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);
}
}
}

View File

@ -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>
{
}
}

View File

@ -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();
}
}
}

View File

@ -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();

View File

@ -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

View File

@ -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)

View File

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using ZR.Model;
using ZR.Repository;
using ZR.Repository.DbProvider;
namespace ZR.Service
@ -13,33 +14,39 @@ namespace ZR.Service
/// 基础服务定义
/// </summary>
/// <typeparam name="T"></typeparam>
public class BaseService<T> : SugarDbContext, IBaseService<T> where T : class, new()
public class BaseService<T> : BaseRepository<T> where T : class,new()//, IBaseService<T> where T : class, new()
{
//private readonly IBaseRepository<T> BaseRepository;
//public BaseService(IBaseRepository<T> baseRepository)
//{
// BaseRepository = baseRepository;
//}
#region
/// <summary>
/// 启用事务
/// </summary>
public void BeginTran()
{
Db.Ado.BeginTran();
}
///// <summary>
///// 启用事务
///// </summary>
//public void BeginTran()
//{
// Context.Ado.BeginTran();
//}
/// <summary>
/// 提交事务
/// </summary>
public void CommitTran()
{
Db.Ado.CommitTran();
}
///// <summary>
///// 提交事务
///// </summary>
//public void CommitTran()
//{
// Context.Ado.CommitTran();
//}
/// <summary>
/// 回滚事务
/// </summary>
public void RollbackTran()
{
Db.Ado.RollbackTran();
}
///// <summary>
///// 回滚事务
///// </summary>
//public void RollbackTran()
//{
// Context.Ado.RollbackTran();
//}
#endregion
@ -51,7 +58,7 @@ namespace ZR.Service
/// <returns></returns>
public int Add(T parm)
{
return Db.Insertable(parm).RemoveDataCache().ExecuteCommand();
return base.Add(parm);// Context.Insertable(parm).RemoveDataCache().ExecuteCommand();
}
/// <summary>
@ -61,10 +68,10 @@ namespace ZR.Service
/// <param name="iClumns">插入列</param>
/// <param name="ignoreNull">忽略null列</param>
/// <returns></returns>
public int Add(T parm, Expression<Func<T, object>> iClumns = null, bool ignoreNull = true)
{
return Db.Insertable(parm).InsertColumns(iClumns).IgnoreColumns(ignoreNullColumn: ignoreNull).ExecuteCommand();
}
//public int Add(T parm, Expression<Func<T, object>> iClumns = null, bool ignoreNull = true)
//{
// return Add(parm);
//}
/// <summary>
/// 批量添加数据
@ -73,7 +80,7 @@ namespace ZR.Service
/// <returns></returns>
public int Add(List<T> parm)
{
return Db.Insertable(parm).RemoveDataCache().ExecuteCommand();
return Context.Insertable(parm).RemoveDataCache().ExecuteCommand();
}
/// <summary>
@ -83,7 +90,7 @@ namespace ZR.Service
/// <returns></returns>
public T Saveable(T parm, Expression<Func<T, object>> uClumns = null, Expression<Func<T, object>> iColumns = null)
{
var command = Db.Saveable(parm);
var command = Context.Saveable(parm);
if (uClumns != null)
{
@ -105,7 +112,7 @@ namespace ZR.Service
/// <returns></returns>
public List<T> Saveable(List<T> parm, Expression<Func<T, object>> uClumns = null, Expression<Func<T, object>> iColumns = null)
{
var command = Db.Saveable(parm);
var command = Context.Saveable(parm);
if (uClumns != null)
{
@ -128,10 +135,10 @@ namespace ZR.Service
/// </summary>
/// <param name="where">条件表达式树</param>
/// <returns></returns>
public bool Any(Expression<Func<T, bool>> where)
{
return Db.Queryable<T>().Any(where);
}
//public bool Any(Expression<Func<T, bool>> where)
//{
// return base.Context.Any(where);
//}
/// <summary>
/// 根据条件合计字段
@ -140,7 +147,7 @@ namespace ZR.Service
/// <returns></returns>
public TResult Sum<TResult>(Expression<Func<T, bool>> where, Expression<Func<T, TResult>> field)
{
return Db.Queryable<T>().Where(where).Sum(field);
return base.Context.Queryable<T>().Where(where).Sum(field);
}
/// <summary>
@ -148,10 +155,10 @@ namespace ZR.Service
/// </summary>
/// <param name="pkValue">主键值</param>
/// <returns>泛型实体</returns>
public T GetId(object pkValue)
{
return Db.Queryable<T>().InSingle(pkValue);
}
//public T GetId(object pkValue)
//{
// return base.Context.Queryable<T>().InSingle(pkValue);
//}
/// <summary>
/// 根据主键查询多条数据
@ -160,7 +167,7 @@ namespace ZR.Service
/// <returns></returns>
public List<T> GetIn(object[] ids)
{
return Db.Queryable<T>().In(ids).ToList();
return Context.Queryable<T>().In(ids).ToList();
}
/// <summary>
@ -170,7 +177,7 @@ namespace ZR.Service
/// <returns></returns>
public int GetCount(Expression<Func<T, bool>> where)
{
return Db.Queryable<T>().Count(where);
return Context.Queryable<T>().Count(where);
}
@ -180,7 +187,7 @@ namespace ZR.Service
/// <returns></returns>
public List<T> GetAll(bool useCache = false, int cacheSecond = 3600)
{
return Db.Queryable<T>().WithCacheIF(useCache, cacheSecond).ToList();
return Context.Queryable<T>().WithCacheIF(useCache, cacheSecond).ToList();
}
/// <summary>
@ -188,9 +195,9 @@ namespace ZR.Service
/// </summary>
/// <param name="where">Expression<Func<T, bool>></param>
/// <returns></returns>
public T GetFirst(Expression<Func<T, bool>> where)
public T GetFirst2(Expression<Func<T, bool>> where)
{
return Db.Queryable<T>().Where(where).First();
return base.GetFirst(where);// Context.Queryable<T>().Where(where).First();
}
/// <summary>
@ -198,11 +205,10 @@ namespace ZR.Service
/// </summary>
/// <param name="parm">string</param>
/// <returns></returns>
public T GetFirst(string parm)
{
return Db.Queryable<T>().Where(parm).First();
}
//public T GetFirst(string parm)
//{
// return Context.Queryable<T>().Where(parm).First();
//}
/// <summary>
/// 根据条件查询分页数据
@ -212,14 +218,14 @@ namespace ZR.Service
/// <returns></returns>
public PagedInfo<T> GetPages(Expression<Func<T, bool>> where, PagerInfo parm)
{
var source = Db.Queryable<T>().Where(where);
var source = Context.Queryable<T>().Where(where);
return source.ToPage(parm);
}
public PagedInfo<T> GetPages(Expression<Func<T, bool>> where, PagerInfo parm, Expression<Func<T, object>> order, string orderEnum = "Asc")
{
var source = Db.Queryable<T>().Where(where).OrderByIF(orderEnum == "Asc", order, OrderByType.Asc).OrderByIF(orderEnum == "Desc", order, OrderByType.Desc);
var source = Context.Queryable<T>().Where(where).OrderByIF(orderEnum == "Asc", order, OrderByType.Asc).OrderByIF(orderEnum == "Desc", order, OrderByType.Desc);
return source.ToPage(parm);
}
@ -231,7 +237,7 @@ namespace ZR.Service
/// <returns></returns>
public List<T> GetWhere(Expression<Func<T, bool>> where, bool useCache = false, int cacheSecond = 3600)
{
var query = Db.Queryable<T>().Where(where).WithCacheIF(useCache, cacheSecond);
var query = Context.Queryable<T>().Where(where).WithCacheIF(useCache, cacheSecond);
return query.ToList();
}
@ -242,7 +248,7 @@ namespace ZR.Service
/// <returns></returns>
public List<T> GetWhere(Expression<Func<T, bool>> where, Expression<Func<T, object>> order, string orderEnum = "Asc", bool useCache = false, int cacheSecond = 3600)
{
var query = Db.Queryable<T>().Where(where).OrderByIF(orderEnum == "Asc", order, OrderByType.Asc).OrderByIF(orderEnum == "Desc", order, OrderByType.Desc).WithCacheIF(useCache, cacheSecond);
var query = Context.Queryable<T>().Where(where).OrderByIF(orderEnum == "Asc", order, OrderByType.Asc).OrderByIF(orderEnum == "Desc", order, OrderByType.Desc).WithCacheIF(useCache, cacheSecond);
return query.ToList();
}
@ -250,74 +256,74 @@ namespace ZR.Service
#region
/// <summary>
/// 修改一条数据
/// </summary>
/// <param name="parm">T</param>
/// <returns></returns>
public int Update(T parm)
{
return Db.Updateable(parm).RemoveDataCache().ExecuteCommand();
}
///// <summary>
///// 修改一条数据
///// </summary>
///// <param name="parm">T</param>
///// <returns></returns>
//public int Update(T parm)
//{
// return Context.Updateable(parm).RemoveDataCache().ExecuteCommand();
//}
/// <summary>
/// 批量修改
/// </summary>
/// <param name="parm">T</param>
/// <returns></returns>
public int Update(List<T> parm)
{
return Db.Updateable(parm).RemoveDataCache().ExecuteCommand();
}
///// <summary>
///// 批量修改
///// </summary>
///// <param name="parm">T</param>
///// <returns></returns>
//public int Update(List<T> parm)
//{
// return Context.Updateable(parm).RemoveDataCache().ExecuteCommand();
//}
/// <summary>
/// 按查询条件更新
/// </summary>
/// <param name="where"></param>
/// <param name="columns"></param>
/// <returns></returns>
public int Update(Expression<Func<T, bool>> where, Expression<Func<T, T>> columns)
{
return Db.Updateable<T>().SetColumns(columns).Where(where).RemoveDataCache().ExecuteCommand();
}
///// <summary>
///// 按查询条件更新
///// </summary>
///// <param name="where"></param>
///// <param name="columns"></param>
///// <returns></returns>
//public int Update(Expression<Func<T, bool>> where, Expression<Func<T, T>> columns)
//{
// return Context.Updateable<T>().SetColumns(columns).Where(where).RemoveDataCache().ExecuteCommand();
//}
#endregion
#region
/// <summary>
/// 删除一条或多条数据
/// </summary>
/// <param name="parm">string</param>
/// <returns></returns>
public int Delete(object id)
{
return Db.Deleteable<T>(id).RemoveDataCache().ExecuteCommand();
}
///// <summary>
///// 删除一条或多条数据
///// </summary>
///// <param name="parm">string</param>
///// <returns></returns>
//public int Delete(object id)
//{
// return Context.Deleteable<T>(id).RemoveDataCache().ExecuteCommand();
//}
/// <summary>
/// 删除一条或多条数据
/// </summary>
/// <param name="parm">string</param>
/// <returns></returns>
public int Delete(object[] ids)
{
return Db.Deleteable<T>().In(ids).RemoveDataCache().ExecuteCommand();
}
///// <summary>
///// 删除一条或多条数据
///// </summary>
///// <param name="parm">string</param>
///// <returns></returns>
//public int Delete(object[] ids)
//{
// return Context.Deleteable<T>().In(ids).RemoveDataCache().ExecuteCommand();
//}
/// <summary>
/// 根据条件删除一条或多条数据
/// </summary>
/// <param name="where">过滤条件</param>
/// <returns></returns>
public int Delete(Expression<Func<T, bool>> where)
{
return Db.Deleteable<T>().Where(where).RemoveDataCache().ExecuteCommand();
}
///// <summary>
///// 根据条件删除一条或多条数据
///// </summary>
///// <param name="where">过滤条件</param>
///// <returns></returns>
//public int Delete(Expression<Func<T, bool>> where)
//{
// return Context.Deleteable<T>().Where(where).RemoveDataCache().ExecuteCommand();
//}
public int DeleteTable()
{
return Db.Deleteable<T>().RemoveDataCache().ExecuteCommand();
return Context.Deleteable<T>().RemoveDataCache().ExecuteCommand();
}
#endregion

View File

@ -0,0 +1,35 @@
using Infrastructure;
using Infrastructure.Attribute;
using Infrastructure.Extensions;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ZR.Common;
using ZR.Model.Models;
using ZR.Repository;
namespace ZR.Service.Business
{
/// <summary>
/// 代码生成演示Service业务层处理
///
/// @author zhaorui
/// @date 2021-09-24
/// </summary>
[AppService(ServiceType = typeof(IGendemoService), ServiceLifetime = LifeTime.Transient)]
public class GendemoService : BaseService<Gendemo>, IGendemoService
{
//private readonly SqlSugarClient _client;
//public GendemoService(SqlSugarClient client, int db =1) : base(db)
//{
// _client = client;
//}
#region
#endregion
}
}

View File

@ -0,0 +1,15 @@
using System;
using ZR.Model.Models;
namespace ZR.Service.Business
{
/// <summary>
/// 代码生成演示service接口
///
/// @author zhaorui
/// @date 2021-09-24
/// </summary>
public interface IGendemoService: IBaseService<Gendemo>
{
}
}

View File

@ -15,22 +15,22 @@ namespace ZR.Service
#region
/// <summary>
/// 启用事务
/// </summary>
void BeginTran();
///// <summary>
///// 启用事务
///// </summary>
//void BeginTran();
/// <summary>
/// 提交事务
/// </summary>
void CommitTran();
///// <summary>
///// 提交事务
///// </summary>
//void CommitTran();
/// <summary>
/// 回滚事务
/// </summary>
void RollbackTran();
///// <summary>
///// 回滚事务
///// </summary>
//void RollbackTran();
#endregion

View File

@ -10,7 +10,7 @@ namespace ZR.Service.System
/// 文章目录
/// </summary>
[AppService(ServiceType = typeof(IArticleCategoryService), ServiceLifetime = LifeTime.Transient)]
public class ArticleCategoryService : BaseService<ArticleCategory>, IArticleCategoryService
public class ArticleCategoryService : IArticleCategoryService
{
/// <summary>
/// 构建前端所需要树结构

View File

@ -8,7 +8,7 @@ namespace ZR.Service.System
///
/// </summary>
[AppService(ServiceType = typeof(IArticleService), ServiceLifetime = LifeTime.Transient)]
public class ArticleService : BaseService<Article>, IArticleService
public class ArticleService : IArticleService
{
}

View File

@ -6,6 +6,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using ZR.Model.System.Generate;
using ZR.Repository.System;
using ZR.Service.System.IService;
namespace ZR.Service.System
@ -14,12 +15,14 @@ namespace ZR.Service.System
/// 代码生成表
/// </summary>
[AppService(ServiceType = typeof(IGenTableService), ServiceLifetime = LifeTime.Transient)]
public class GenTableService : BaseService<GenTable>, IGenTableService
public class GenTableService : IGenTableService
{
public IGenTableColumnService GenTableColumnService;
public GenTableService(IGenTableColumnService genTableColumnService)
private GenTableRepository GenTableRepository;
private IGenTableColumnService GenTableColumnService;
public GenTableService(IGenTableColumnService genTableColumnService, GenTableRepository genTableRepository)
{
GenTableColumnService = genTableColumnService;
GenTableRepository = genTableRepository;
}
/// <summary>
@ -29,7 +32,7 @@ namespace ZR.Service.System
/// <returns></returns>
public int DeleteGenTableByIds(long[] tableIds)
{
Db.Deleteable<GenTable>().Where(f => tableIds.Contains(f.TableId)).ExecuteCommand();
GenTableRepository.Delete(f => tableIds.Contains(f.TableId));
return GenTableColumnService.DeleteGenTableColumn(tableIds);
}
@ -40,7 +43,7 @@ namespace ZR.Service.System
/// <returns></returns>
public int DeleteGenTableByTbName(string tableName)
{
return Db.Deleteable<GenTable>().Where(f => f.TableName == tableName).ExecuteCommand();
return GenTableRepository.Delete(f => f.TableName == tableName) ? 1 : 0;
}
/// <summary>
@ -50,7 +53,7 @@ namespace ZR.Service.System
/// <returns></returns>
public GenTable GetGenTableInfo(long tableId)
{
return GetId(tableId);
return GenTableRepository.GetById(tableId);
}
/// <summary>
@ -64,7 +67,11 @@ namespace ZR.Service.System
var predicate = Expressionable.Create<GenTable>();
predicate = predicate.AndIF(genTable.TableName.IfNotEmpty(), it => it.TableName.Contains(genTable.TableName));
return GetPages(predicate.ToExpression(), pagerInfo);
(List<GenTable>, int) ts = GenTableRepository.QueryableToPage(predicate.ToExpression(), pagerInfo.PageNum, pagerInfo.PageSize);
PagedInfo<GenTable> pagedInfo = new(ts.Item1, pagerInfo.PageNum, pagerInfo.PageSize);
pagedInfo.TotalCount = ts.Item2;
return pagedInfo;
}
/// <summary>
@ -74,13 +81,12 @@ namespace ZR.Service.System
/// <returns></returns>
public int ImportGenTable(GenTable table)
{
var db = Db;
table.Create_time = db.GetDate();
table.Create_time = DateTime.Now;
//导入前删除现有表
//DeleteGenTableByIds(new long[] { table.TableId });
DeleteGenTableByTbName(table.TableName);
return db.Insertable(table).IgnoreColumns(ignoreNullColumn: true).ExecuteReturnIdentity();
return GenTableRepository.Context.Insertable(table).IgnoreColumns(ignoreNullColumn: true).ExecuteReturnIdentity();
}
/// <summary>
@ -95,7 +101,7 @@ namespace ZR.Service.System
public int UpdateGenTable(GenTable genTable)
{
var db = Db;
var db = GenTableRepository.Context;
genTable.Update_time = db.GetDate();
return db.Updateable(genTable).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
}
@ -105,8 +111,14 @@ namespace ZR.Service.System
/// 代码生成表列
/// </summary>
[AppService(ServiceType = typeof(IGenTableColumnService), ServiceLifetime = LifeTime.Transient)]
public class GenTableColumnService : BaseService<GenTableColumn>, IGenTableColumnService
public class GenTableColumnService : IGenTableColumnService
{
private GenTableColumnRepository GetTableColumnRepository;
public GenTableColumnService(GenTableColumnRepository genTableColumnRepository)
{
GetTableColumnRepository = genTableColumnRepository;
}
/// <summary>
/// 删除表字段
/// </summary>
@ -114,7 +126,7 @@ namespace ZR.Service.System
/// <returns></returns>
public int DeleteGenTableColumn(long tableId)
{
return DeleteGenTableColumn(new long[] { tableId });
return GetTableColumnRepository.DeleteGenTableColumn(new long[] { tableId });
}
/// <summary>
/// 根据表id批量删除表字段
@ -123,7 +135,7 @@ namespace ZR.Service.System
/// <returns></returns>
public int DeleteGenTableColumn(long[] tableId)
{
return Db.Deleteable<GenTableColumn>().Where(f => tableId.Contains(f.TableId)).ExecuteCommand();
return GetTableColumnRepository.DeleteGenTableColumn(tableId);
}
/// <summary>
@ -133,7 +145,7 @@ namespace ZR.Service.System
/// <returns></returns>
public int DeleteGenTableColumnByTableName(string tableName)
{
return Db.Deleteable<GenTableColumn>().Where(f => f.TableName == tableName).ExecuteCommand();
return GetTableColumnRepository.DeleteGenTableColumnByTableName(tableName);
}
/// <summary>
@ -143,7 +155,7 @@ namespace ZR.Service.System
/// <returns></returns>
public List<GenTableColumn> GenTableColumns(long tableId)
{
return Db.Queryable<GenTableColumn>().Where(f => f.TableId == tableId).OrderBy(x => x.Sort).ToList();
return GetTableColumnRepository.GenTableColumns(tableId);
}
/// <summary>
@ -153,7 +165,7 @@ namespace ZR.Service.System
/// <returns></returns>
public int InsertGenTableColumn(List<GenTableColumn> tableColumn)
{
return Db.Insertable(tableColumn).IgnoreColumns(x => new { x.Remark }).ExecuteCommand();
return GetTableColumnRepository.InsertGenTableColumn(tableColumn);
}
/// <summary>
@ -163,31 +175,7 @@ namespace ZR.Service.System
/// <returns></returns>
public int UpdateGenTableColumn(List<GenTableColumn> tableColumn)
{
foreach (var item in tableColumn)
{
Db.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;
return GetTableColumnRepository.UpdateGenTableColumn(tableColumn);
}
}
}

View File

@ -7,7 +7,7 @@ using ZR.Model.System;
namespace ZR.Service.System.IService
{
public interface IArticleCategoryService : IBaseService<ArticleCategory>
public interface IArticleCategoryService //: IBaseService<ArticleCategory>
{
List<ArticleCategory> BuildCategoryTree(List<ArticleCategory> categories);
}

View File

@ -8,7 +8,7 @@ using ZR.Model.System;
namespace ZR.Service.System.IService
{
public interface IArticleService : IBaseService<Article>
public interface IArticleService //: IBaseService<Article>
{
}

View File

@ -6,7 +6,7 @@ using ZR.Model.Vo.System;
namespace ZR.Service.System.IService
{
public interface ISysDeptService : IBaseService<SysDept>
public interface ISysDeptService //: IBaseService<SysDept>
{
public List<SysDept> GetSysDepts(SysDept dept);
public string CheckDeptNameUnique(SysDept dept);

View File

@ -5,7 +5,7 @@ using ZR.Model.System;
namespace ZR.Service.System.IService
{
public interface ISysDictDataService : IBaseService<SysDictData>
public interface ISysDictDataService
{
public List<SysDictData> SelectDictDataList(SysDictData dictData);
public List<SysDictData> SelectDictDataByType(string dictType);

View File

@ -8,7 +8,7 @@ namespace ZR.Service.System.IService
/// <summary>
///
/// </summary>
public interface ISysDictService: IBaseService<SysDictType>
public interface ISysDictService : IBaseService<SysDictType>
{
public List<SysDictType> SelectDictTypeList(SysDictType dictType, Model.PagerInfo pager);

View File

@ -3,7 +3,7 @@ using ZR.Model.System;
namespace ZR.Service.System.IService
{
public interface ISysFileService : IBaseService<SysFile>
public interface ISysFileService
{
}
}

View File

@ -6,7 +6,7 @@ using ZR.Model.Vo.System;
namespace ZR.Service.System.IService
{
public interface ISysMenuService: IBaseService<SysMenu>
public interface ISysMenuService
{
public List<SysMenu> SelectMenuList(long userId);

View File

@ -6,7 +6,7 @@ using ZR.Service.System;
namespace ZR.Service.System.IService
{
public interface ISysOperLogService : IBaseService<SysOperLog>
public interface ISysOperLogService
{
public void InsertOperlog(SysOperLog operLog);

View File

@ -2,10 +2,11 @@
using System.Collections.Generic;
using System.Text;
using ZR.Model.System;
using ZR.Repository;
namespace ZR.Service.System.IService
{
public interface ISysPostService: IBaseService<SysPost>
public interface ISysPostService: IBaseRepository<SysPost>
{
string CheckPostNameUnique(SysPost sysPost);
string CheckPostCodeUnique(SysPost sysPost);

View File

@ -6,7 +6,7 @@ using ZR.Model.System;
namespace ZR.Service.System.IService
{
public interface ISysRoleService: IBaseService<SysRole>
public interface ISysRoleService
{
/// <summary>
/// 根据条件分页查询角色数据

View File

@ -1,8 +1,9 @@
using ZR.Model.System;
using ZR.Repository;
namespace ZR.Service.System.IService
{
public interface ISysTasksLogService : IBaseService<SysTasksLog>
public interface ISysTasksLogService: IBaseRepository<SysTasksLog>
{
/// <summary>
/// 记录任务执行日志

View File

@ -7,7 +7,8 @@ using ZR.Model.System;
namespace ZR.Service.System.IService
{
public interface ISysTasksQzService: IBaseService<SysTasksQz>
public interface ISysTasksQzService
{
SysTasksQz GetId(object id);
}
}

View File

@ -3,12 +3,13 @@ using ZR.Model.System;
namespace ZR.Service.System.IService
{
public interface ISysUserPostService: IBaseService<SysUserPost>
public interface ISysUserPostService
{
public void InsertUserPost(SysUser user);
public List<long> GetUserPostsByUserId(long userId);
public string GetPostsStrByUserId(long userId);
int Delete(long userId);
}
}

View File

@ -8,7 +8,7 @@ using ZR.Model.System;
namespace ZR.Service.System.IService
{
public interface ISysUserService : IBaseService<SysUser>
public interface ISysUserService
{
public List<SysUser> SelectUserList(SysUser user, PagerInfo pager);

View File

@ -18,7 +18,7 @@ namespace ZR.Service.System
/// 部门管理
/// </summary>
[AppService(ServiceType = typeof(ISysDeptService), ServiceLifetime = LifeTime.Transient)]
public class SysDeptService : BaseService<SysDept>, ISysDeptService
public class SysDeptService :ISysDeptService
{
public SysDeptRepository DeptRepository;
@ -40,7 +40,7 @@ namespace ZR.Service.System
predicate = predicate.AndIF(dept.DeptName.IfNotEmpty(), it => it.DeptName.Contains(dept.DeptName));
predicate = predicate.AndIF(dept.Status.IfNotEmpty(), it => it.Status == dept.Status);
var response = GetWhere(predicate.ToExpression());
var response = DeptRepository.GetList(predicate.ToExpression());
return response;
}
@ -53,7 +53,7 @@ namespace ZR.Service.System
public string CheckDeptNameUnique(SysDept dept)
{
long deptId = dept.DeptId == 0 ? -1L : dept.DeptId;
SysDept info = GetFirst(it => it.DeptName == dept.DeptName && it.ParentId == dept.ParentId);
SysDept info = DeptRepository.GetFirst(it => it.DeptName == dept.DeptName && it.ParentId == dept.ParentId);
if (info != null && info.DeptId != deptId)
{
return UserConstants.NOT_UNIQUE;
@ -68,7 +68,7 @@ namespace ZR.Service.System
/// <returns></returns>
public int InsertDept(SysDept dept)
{
SysDept info = GetFirst(it => it.DeptId == dept.ParentId);
SysDept info = DeptRepository.GetSingle(it => it.DeptId == dept.ParentId);
//如果父节点不为正常状态,则不允许新增子节点
if (!UserConstants.DEPT_NORMAL.Equals(info.Status))
{
@ -76,7 +76,7 @@ namespace ZR.Service.System
}
dept.Ancestors = info.Ancestors + "," + dept.ParentId;
return Add(dept);
return DeptRepository.Insert(dept, true);
}
/// <summary>
@ -86,8 +86,8 @@ namespace ZR.Service.System
/// <returns></returns>
public int UpdateDept(SysDept dept)
{
SysDept newParentDept = GetFirst(it => it.ParentId == dept.ParentId);
SysDept oldDept = GetFirst(m => m.DeptId == dept.DeptId);
SysDept newParentDept = DeptRepository.GetSingle(it => it.ParentId == dept.ParentId);
SysDept oldDept = DeptRepository.GetSingle(m => m.DeptId == dept.DeptId);
if (newParentDept != null && oldDept != null)
{
string newAncestors = newParentDept.Ancestors + "," + newParentDept.DeptId;
@ -95,7 +95,7 @@ namespace ZR.Service.System
dept.Ancestors = newAncestors;
UpdateDeptChildren(dept.DeptId, newAncestors, oldAncestors);
}
int result = Update(dept);
int result = DeptRepository.Context.Updateable(dept).ExecuteCommand();
if (UserConstants.DEPT_NORMAL.Equals(dept.Status))
{
// 如果该部门是启用状态,则启用该部门的所有上级部门
@ -111,7 +111,7 @@ namespace ZR.Service.System
private void UpdateParentDeptStatus(SysDept dept)
{
string updateBy = dept.Update_by;
dept = GetFirst(it => it.DeptId == dept.DeptId);
dept = DeptRepository.GetFirst(it => it.DeptId == dept.DeptId);
dept.Update_by = updateBy;
//DeptRepository.UpdateParentDeptStatus(dept);
}
@ -132,7 +132,7 @@ namespace ZR.Service.System
if (child.DeptId.Equals(deptId))
{
Saveable(child, it => new { it.Ancestors });
//TODO Saveable(child, it => new { it.Ancestors });
//DeptRepository.UdateDeptChildren(child);
}
}

View File

@ -10,7 +10,7 @@ using ZR.Service.System.IService;
namespace ZR.Service.System
{
[AppService(ServiceType = typeof(ISysDictDataService), ServiceLifetime = LifeTime.Transient)]
public class SysDictDataService: BaseService<SysDictData>, ISysDictDataService
public class SysDictDataService: ISysDictDataService
{
private readonly SysDictDataRepository SysDictDataRepository;
@ -55,7 +55,7 @@ namespace ZR.Service.System
string CK = $"SelectDictDataByCode_{dictCode}";
if (CacheHelper.GetCache(CK) is not SysDictData list)
{
list = GetFirst(f => f.DictCode == dictCode);
list = SysDictDataRepository.GetFirst(f => f.DictCode == dictCode);
CacheHelper.SetCache(CK, list, 5);
}
return list;

View File

@ -15,12 +15,12 @@ namespace ZR.Service.System
[AppService(ServiceType = typeof(ISysDictService), ServiceLifetime = LifeTime.Transient)]
public class SysDictService : BaseService<SysDictType>, ISysDictService
{
private SysDictRepository sysDictRepository;
private SysDictRepository DictRepository;
private SysDictDataRepository DictDataRepository;
public SysDictService(SysDictRepository sysDictRepository, SysDictDataRepository dictDataRepository)
{
this.sysDictRepository = sysDictRepository;
this.DictRepository = sysDictRepository;
this.DictDataRepository = dictDataRepository;
}
@ -31,7 +31,7 @@ namespace ZR.Service.System
/// <returns></returns>
public List<SysDictType> SelectDictTypeList(SysDictType dictType, Model.PagerInfo pager)
{
return sysDictRepository.SelectDictTypeList(dictType, pager);
return DictRepository.SelectDictTypeList(dictType, pager);
}
/// <summary>
@ -41,7 +41,7 @@ namespace ZR.Service.System
/// <returns></returns>
public string CheckDictTypeUnique(SysDictType dictType)
{
SysDictType sysDictType = GetFirst(f => f.DictType == dictType.DictType);
SysDictType sysDictType = DictRepository.GetFirst(f => f.DictType == dictType.DictType);
if (sysDictType != null && sysDictType.DictId != dictType.DictId)
{
return UserConstants.NOT_UNIQUE;
@ -58,13 +58,13 @@ namespace ZR.Service.System
{
foreach (var dictId in dictIds)
{
SysDictType dictType = GetFirst(x => x.DictId == dictId);
if (GetCount(f => f.DictType == dictType.DictType) > 0)
SysDictType dictType = DictRepository.GetFirst(x => x.DictId == dictId);
if (DictRepository.Count(f => f.DictType == dictType.DictType) > 0)
{
throw new CustomException($"{dictType.DictName}已分配,不能删除");
}
}
int count = sysDictRepository.DeleteDictTypeByIds(dictIds);
int count = DictRepository.DeleteDictTypeByIds(dictIds);
//if (count > 0)
//{
// DictUtils.clearDictCache();
@ -79,7 +79,7 @@ namespace ZR.Service.System
/// <returns></returns>
public long InsertDictType(SysDictType sysDictType)
{
return Saveable(sysDictType, iColumns: it => new { sysDictType.Update_by }).DictId;
return DictRepository.InsertReturnEntity(sysDictType).DictId;
}
/// <summary>
@ -89,13 +89,13 @@ namespace ZR.Service.System
/// <returns></returns>
public int UpdateDictType(SysDictType sysDictType)
{
SysDictType oldDict = GetFirst(x => x.DictId == sysDictType.DictId);
SysDictType oldDict = DictRepository.GetFirst(x => x.DictId == sysDictType.DictId);
if (sysDictType.DictType != oldDict.DictType)
{
//同步修改 dict_data表里面的DictType值
DictDataRepository.UpdateDictDataType(oldDict.DictType, sysDictType.DictType);
}
return sysDictRepository.UpdateDictType(sysDictType);
return DictRepository.UpdateDictType(sysDictType);
}
}
}

View File

@ -8,7 +8,7 @@ namespace ZR.Service.System
/// 文件管理
/// </summary>
[AppService(ServiceType = typeof(ISysFileService), ServiceLifetime = LifeTime.Transient)]
public class SysFileService: BaseService<SysFile>, ISysFileService
public class SysFileService : ISysFileService
{
}

View File

@ -15,7 +15,7 @@ namespace ZR.Service
/// 菜单
/// </summary>
[AppService(ServiceType = typeof(ISysMenuService), ServiceLifetime = LifeTime.Transient)]
public class SysMenuService: BaseService<SysMenu>, ISysMenuService
public class SysMenuService: ISysMenuService
{
public SysMenuRepository MenuRepository;
public ISysRoleService SysRoleService;

View File

@ -13,7 +13,7 @@ namespace ZR.Service.System
/// 操作日志
/// </summary>
[AppService(ServiceType = typeof(ISysOperLogService), ServiceLifetime = LifeTime.Transient)]
public class SysOperLogService: BaseService<SysOperLog>, ISysOperLogService
public class SysOperLogService : ISysOperLogService
{
public SysOperLogRepository sysOperLogRepository;

View File

@ -3,6 +3,8 @@ using System;
using System.Collections.Generic;
using System.Text;
using ZR.Model.System;
using ZR.Repository;
using ZR.Repository.System;
using ZR.Service.System.IService;
namespace ZR.Service.System
@ -11,8 +13,14 @@ namespace ZR.Service.System
/// 岗位管理
/// </summary>
[AppService(ServiceType = typeof(ISysPostService), ServiceLifetime = LifeTime.Transient)]
public class SysPostService : BaseService<SysPost>, ISysPostService
public class SysPostService : BaseRepository<SysPost>, ISysPostService
{
public SysPostRepository PostRepository;
public SysPostService(SysPostRepository postRepository)
{
PostRepository = postRepository;
}
/// <summary>
/// 校验岗位编码是否唯一
/// </summary>
@ -20,7 +28,7 @@ namespace ZR.Service.System
/// <returns></returns>
public string CheckPostCodeUnique(SysPost post)
{
SysPost info = GetFirst(it => it.PostCode.Equals(post.PostCode));
SysPost info = PostRepository.GetFirst(it => it.PostCode.Equals(post.PostCode));
if (info != null && info.PostId != post.PostId)
{
return UserConstants.NOT_UNIQUE;
@ -35,7 +43,7 @@ namespace ZR.Service.System
/// <returns></returns>
public string CheckPostNameUnique(SysPost post)
{
SysPost info = GetFirst(it => it.PostName.Equals(post.PostName));
SysPost info = PostRepository.GetFirst(it => it.PostName.Equals(post.PostName));
if (info != null && info.PostId != post.PostId)
{
return UserConstants.NOT_UNIQUE;

View File

@ -15,7 +15,7 @@ namespace ZR.Service
/// 角色
/// </summary>
[AppService(ServiceType = typeof(ISysRoleService), ServiceLifetime = LifeTime.Transient)]
public class SysRoleService: BaseService<SysRole>, ISysRoleService
public class SysRoleService: ISysRoleService
{
private SysRoleRepository SysRoleRepository;
private ISysUserRoleService SysUserRoleService;

View File

@ -1,12 +1,13 @@
using Infrastructure.Attribute;
using System;
using ZR.Model.System;
using ZR.Repository;
using ZR.Service.System.IService;
namespace ZR.Service.System
{
[AppService(ServiceLifetime = LifeTime.Transient, ServiceType = typeof(ISysTasksLogService))]
public class SysTasksLogService : BaseService<SysTasksLog>, ISysTasksLogService
public class SysTasksLogService : BaseRepository<SysTasksLog>, ISysTasksLogService
{
private ISysTasksQzService _tasksQzService;
public SysTasksLogService(ISysTasksQzService tasksQzService)
@ -27,7 +28,7 @@ namespace ZR.Service.System
logModel.CreateTime = DateTime.Now;
}
Add(logModel);
Insert(logModel, true);
return logModel;
}
}

View File

@ -5,7 +5,7 @@ using ZR.Service.System.IService;
namespace ZR.Service.System
{
[AppService(ServiceType = typeof(ISysTasksQzService), ServiceLifetime = LifeTime.Transient)]
public class SysTasksQzService : BaseService<SysTasksQz>, ISysTasksQzService
public class SysTasksQzService : ISysTasksQzService
{
}

View File

@ -13,10 +13,9 @@ namespace ZR.Service.System
/// 用户岗位
/// </summary>
[AppService(ServiceType = typeof(ISysUserPostService), ServiceLifetime = LifeTime.Transient)]
public class SysUserPostService : BaseService<SysUserPost>, ISysUserPostService
public class SysUserPostService : ISysUserPostService
{
public SysUserPostRepository UserPostRepository;
private SysUserPostRepository UserPostRepository;
public SysUserPostService(SysUserPostRepository userPostRepository)
{
UserPostRepository = userPostRepository;
@ -34,7 +33,7 @@ namespace ZR.Service.System
{
list.Add(new SysUserPost() { PostId = item, UserId = user.UserId });
}
Add(list);
UserPostRepository.Insert(list);
}
@ -45,7 +44,7 @@ namespace ZR.Service.System
/// <returns></returns>
public List<long> GetUserPostsByUserId(long userId)
{
var list = GetWhere(f => f.UserId == userId);
var list = UserPostRepository.GetList(f => f.UserId == userId);
return list.Select(x => x.PostId).ToList();
}
@ -59,5 +58,10 @@ namespace ZR.Service.System
var list = UserPostRepository.SelectPostsByUserId(userId);
return string.Join(',', list.Select(x => x.PostName));
}
public int Delete(long userId)
{
return UserPostRepository.Delete(x => x.UserId == userId) ? 1: 0 ;
}
}
}

View File

@ -11,7 +11,7 @@ using ZR.Service.System.IService;
namespace ZR.Service
{
[AppService(ServiceType = typeof(ISysUserService), ServiceLifetime = LifeTime.Transient)]
public class SysUserService : BaseService<SysUser>, ISysUserService
public class SysUserService : ISysUserService
{
private readonly SysUserRepository UserRepository;
private readonly ISysRoleService RoleService;
@ -101,7 +101,7 @@ namespace ZR.Service
UserRoleService.InsertUserRole(user);
}
// 删除用户与岗位关联
UserPostService.Delete(it => it.UserId == user.UserId);
UserPostService.Delete(user.UserId);
// 新增用户与岗位管理
UserPostService.InsertUserPost(user);
return UserRepository.UpdateUser(user);