From 40026f596f81ea71ac13b1865e8609d95a169563 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=81=9A=E7=A0=81=E5=86=9C?= <599854767@qq.com> Date: Mon, 27 Sep 2021 08:06:09 +0800 Subject: [PATCH 01/21] =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../System/SysDictTypeController.cs | 2 +- .../Controllers/business/GendemoController.cs | 137 ++++++ ZR.Model/Dto/GendemoDto.cs | 32 ++ ZR.Model/Models/Gendemo.cs | 53 +++ ZR.Repository/BaseRepository.cs | 431 ++++++++++++++++++ ZR.Repository/DbProvider/SugarDbContext.cs | 30 +- ZR.Repository/IBaseRepository.cs | 156 +++++++ .../Repositories/GendemoRepository.cs | 24 + ZR.Repository/System/GenTableRepository.cs | 91 ++++ ZR.Repository/System/SysDeptRepository.cs | 6 +- ZR.Repository/System/SysDictDataRepository.cs | 14 +- ZR.Repository/System/SysDictRepository.cs | 8 +- .../System/SysLogininfoRepository.cs | 15 +- ZR.Repository/System/SysMenuRepository.cs | 27 +- ZR.Repository/System/SysOperLogRepository.cs | 12 +- ZR.Repository/System/SysPostRepository.cs | 13 + ZR.Repository/System/SysRoleRepository.cs | 32 +- ZR.Repository/System/SysUserPostRepository.cs | 4 +- ZR.Repository/System/SysUserRepository.cs | 20 +- ZR.Repository/System/SysUserRoleRepository.cs | 14 +- ZR.Service/BaseService.cs | 224 ++++----- ZR.Service/Business/GendemoService.cs | 35 ++ .../Business/IBusService/IGendemoService.cs | 15 + ZR.Service/IBaseService.cs | 24 +- ZR.Service/System/ArticleCategoryService.cs | 2 +- ZR.Service/System/ArticleService.cs | 2 +- ZR.Service/System/GenTableService.cs | 72 ++- .../IService/IArticleCategoryService.cs | 2 +- ZR.Service/System/IService/IArticleService.cs | 2 +- ZR.Service/System/IService/ISysDeptService.cs | 2 +- .../System/IService/ISysDictDataService.cs | 2 +- ZR.Service/System/IService/ISysDictService.cs | 2 +- ZR.Service/System/IService/ISysFileService.cs | 2 +- ZR.Service/System/IService/ISysMenuService.cs | 2 +- .../System/IService/ISysOperLogService.cs | 2 +- ZR.Service/System/IService/ISysPostService.cs | 3 +- ZR.Service/System/IService/ISysRoleService.cs | 2 +- .../System/IService/ISysTasksLogService.cs | 3 +- .../System/IService/ISysTasksQzService.cs | 3 +- .../System/IService/ISysUserPostService.cs | 3 +- ZR.Service/System/IService/ISysUserService.cs | 2 +- ZR.Service/System/SysDeptService.cs | 20 +- ZR.Service/System/SysDictDataService.cs | 4 +- ZR.Service/System/SysDictService.cs | 20 +- ZR.Service/System/SysFileService.cs | 2 +- ZR.Service/System/SysMenuService.cs | 2 +- ZR.Service/System/SysOperLogService.cs | 2 +- ZR.Service/System/SysPostService.cs | 14 +- ZR.Service/System/SysRoleService.cs | 2 +- ZR.Service/System/SysTasksLogService.cs | 5 +- ZR.Service/System/SysTasksQzService.cs | 2 +- ZR.Service/System/SysUserPostService.cs | 14 +- ZR.Service/System/SysUserService.cs | 4 +- 53 files changed, 1306 insertions(+), 312 deletions(-) create mode 100644 ZR.Admin.WebApi/Controllers/business/GendemoController.cs create mode 100644 ZR.Model/Dto/GendemoDto.cs create mode 100644 ZR.Model/Models/Gendemo.cs create mode 100644 ZR.Repository/BaseRepository.cs create mode 100644 ZR.Repository/IBaseRepository.cs create mode 100644 ZR.Repository/Repositories/GendemoRepository.cs create mode 100644 ZR.Repository/System/GenTableRepository.cs create mode 100644 ZR.Repository/System/SysPostRepository.cs create mode 100644 ZR.Service/Business/GendemoService.cs create mode 100644 ZR.Service/Business/IBusService/IGendemoService.cs diff --git a/ZR.Admin.WebApi/Controllers/System/SysDictTypeController.cs b/ZR.Admin.WebApi/Controllers/System/SysDictTypeController.cs index d61222c..776901d 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysDictTypeController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysDictTypeController.cs @@ -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)); } /// diff --git a/ZR.Admin.WebApi/Controllers/business/GendemoController.cs b/ZR.Admin.WebApi/Controllers/business/GendemoController.cs new file mode 100644 index 0000000..23f6e12 --- /dev/null +++ b/ZR.Admin.WebApi/Controllers/business/GendemoController.cs @@ -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 +{ + /// + /// 代码生成演示Controller + /// + /// @author zhaorui + /// @date 2021-09-24 + /// + [Verify] + [Route("business/Gendemo")] + public class GendemoController: BaseController + { + /// + /// 代码生成演示接口 + /// + private readonly IGendemoService _GendemoService; + + public GendemoController(IGendemoService GendemoService) + { + _GendemoService = GendemoService; + } + + /// + /// 查询代码生成演示列表 + /// + /// + [HttpGet("list")] + [ActionPermissionFilter(Permission = "business:gendemo:list")] + public IActionResult QueryGendemo([FromQuery] GendemoQueryDto parm) + { + //开始拼装查询条件 + var predicate = Expressionable.Create(); + + //TODO 搜索条件 + //predicate = predicate.And(m => m.Name.Contains(parm.Name)); + + var response = _GendemoService.GetPages(predicate.ToExpression(), parm); + + return SUCCESS(response); + } + + /// + /// 查询代码生成演示详情 + /// + /// + /// + [HttpGet("{Id}")] + [ActionPermissionFilter(Permission = "business:gendemo:query")] + public IActionResult GetGendemo(int Id) + { + var response = _GendemoService.GetId(Id); + + return SUCCESS(response); + } + + /// + /// 添加代码生成演示 + /// + /// + [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().ToCreate(); + + return SUCCESS(_GendemoService.Add(model, it => new + { + it.Name, it.Icon, it.ShowStatus, it.Sex, it.Sort, + })); + } + + /// + /// 更新代码生成演示 + /// + /// + [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().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); + } + + /// + /// 删除代码生成演示 + /// + /// + [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); + } + } +} \ No newline at end of file diff --git a/ZR.Model/Dto/GendemoDto.cs b/ZR.Model/Dto/GendemoDto.cs new file mode 100644 index 0000000..de6932b --- /dev/null +++ b/ZR.Model/Dto/GendemoDto.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using ZR.Model.Dto; +using ZR.Model.Models; + +namespace ZR.Model.Dto +{ + /// + /// 代码生成演示输入对象模型 + /// + 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; } + + } + + /// + /// 代码生成演示查询对象模型 + /// + public class GendemoQueryDto: PagerInfo + { + public string Name { get; set; } + + public DateTime? BeginTime { get; set; } + public DateTime? EndTime { get; set; } + } +} diff --git a/ZR.Model/Models/Gendemo.cs b/ZR.Model/Models/Gendemo.cs new file mode 100644 index 0000000..115f745 --- /dev/null +++ b/ZR.Model/Models/Gendemo.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; + +namespace ZR.Model.Models +{ + /// + /// 代码生成演示,数据实体对象 + /// + /// @author zhaorui + /// @date 2021-09-24 + /// + [SqlSugar.SugarTable("gen_demo")] + public class Gendemo + { + /// + /// 描述 :自增id + /// 空值 :False + /// + [SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)] + public int Id { get; set; } + /// + /// 描述 :名称 + /// 空值 :False + /// + public string Name { get; set; } + /// + /// 描述 :图片 + /// 空值 :True + /// + public string Icon { get; set; } + /// + /// 描述 :显示状态 + /// 空值 :False + /// + public int ShowStatus { get; set; } + /// + /// 描述 :添加时间 + /// 空值 :True + /// + public DateTime? AddTime { get; set; } + /// + /// 描述 :用户性别 + /// 空值 :True + /// + public int? Sex { get; set; } + /// + /// 描述 :排序 + /// 空值 :True + /// + public int? Sort { get; set; } + + } +} diff --git a/ZR.Repository/BaseRepository.cs b/ZR.Repository/BaseRepository.cs new file mode 100644 index 0000000..0a8a13b --- /dev/null +++ b/ZR.Repository/BaseRepository.cs @@ -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 +{ + /// + /// + /// + /// + public class BaseRepository : SimpleClient, IBaseRepository 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(OptionsSetting.DbKey); + int dbType = ConfigUtils.Instance.GetAppConfig(OptionsSetting.ConnDbType); + if (!string.IsNullOrEmpty(dbKey)) + { + connStr = NETCore.Encrypt.EncryptProvider.DESDecrypt(connStr, dbKey); + } + + var Db = new SqlSugarClient(new List() + { + 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> 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) + { + return base.Context.Insertable(t).ExecuteCommand(); + } + + public int InsertIgnoreNullColumn(List t) + { + return base.Context.Insertable(t).IgnoreColumns(true).ExecuteCommand(); + } + + public int InsertIgnoreNullColumn(List t, params string[] columns) + { + return base.Context.Insertable(t).IgnoreColumns(columns).ExecuteCommand(); + } + public int Insert(T parm, Expression> iClumns = null, bool ignoreNull = true) + { + return base.Context.Insertable(parm).InsertColumns(iClumns).IgnoreColumns(ignoreNullColumn: ignoreNull).ExecuteCommand(); + } + public DbResult InsertTran(T t) + { + var result = base.Context.Ado.UseTran(() => + { + base.Context.Insertable(t).ExecuteCommand(); + }); + return result; + } + + public DbResult InsertTran(List 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 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> expression) + { + return base.Context.Updateable(entity).Where(expression).ExecuteCommand() > 0; + } + + public bool Update(T entity, Expression> expression, bool ignoreAllNull = false) + { + return base.Context.Updateable(entity).UpdateColumns(expression).IgnoreColumns(ignoreAllNull).ExecuteCommand() > 0; + } + + public bool Update(T entity, Expression> expression, Expression> where) + { + return base.Context.Updateable(entity).UpdateColumns(expression).Where(where).ExecuteCommand() > 0; + } + + public bool Update(SqlSugarClient client, T entity, Expression> expression, Expression> where) + { + return client.Updateable(entity).UpdateColumns(expression).Where(where).ExecuteCommand() > 0; + } + + /// + /// + /// + /// + /// + /// 默认为true + /// + public bool Update(T entity, List list = null, bool isNull = true) + { + if (list == null) + { + list = new List() + { + "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 entity) + { + var result = base.Context.Ado.UseTran(() => + { + base.Context.Updateable(entity).ExecuteCommand(); + }); + return result.IsSuccess; + } + public bool Update(Expression> where, Expression> columns) + { + return base.Context.Updateable().SetColumns(columns).Where(where).RemoveDataCache().ExecuteCommand() > 0; + } + #endregion update + + //public DbResult UseTran(Action action) + //{ + // var result = base.Context.Ado.UseTran(() => action()); + // return result; + //} + + //public DbResult 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> expression) + { + return base.Context.Deleteable().Where(expression).ExecuteCommand() > 0; + } + + //public bool Delete(PkType[] primaryKeyValues) + //{ + // return base.Context.Deleteable().In(primaryKeyValues).ExecuteCommand() > 0; + //} + + public bool Delete(object[] obj) + { + return base.Context.Deleteable().In(obj).ExecuteCommand() > 0; + } + public bool Delete(object id) + { + return base.Context.Deleteable(id).ExecuteCommand() > 0; + } + public bool Delete() + { + return base.Context.Deleteable().ExecuteCommand() > 0; + } + + #endregion delete + + #region query + + public bool IsAny(Expression> expression) + { + //base.Context.Queryable().Any(); + return base.Context.Queryable().Where(expression).Any(); + } + + public ISugarQueryable Queryable() + { + return base.Context.Queryable(); + } + + public ISugarQueryable Queryable(string tableName, string shortName) + { + return base.Context.Queryable(tableName, shortName); + } + + public List QueryableToList(Expression> expression) + { + return base.Context.Queryable().Where(expression).ToList(); + } + + public Task> QueryableToListAsync(Expression> expression) + { + return base.Context.Queryable().Where(expression).ToListAsync(); + } + + //public string QueryableToJson(string select, Expression> expressionWhere) + //{ + // var query = base.Context.Queryable().Select(select).Where(expressionWhere).ToList(); + // return query.JilToJson(); + //} + + public T QueryableToEntity(Expression> expression) + { + return base.Context.Queryable().Where(expression).First(); + } + + public List QueryableToList(string tableName) + { + return base.Context.Queryable(tableName).ToList(); + } + + public List QueryableToList(string tableName, Expression> expression) + { + return base.Context.Queryable(tableName).Where(expression).ToList(); + } + + public (List, int) QueryableToPage(Expression> expression, int pageIndex = 0, int pageSize = 10) + { + int totalNumber = 0; + var list = base.Context.Queryable().Where(expression).ToPageList(pageIndex, pageSize, ref totalNumber); + return (list, totalNumber); + } + + public (List, int) QueryableToPage(Expression> expression, string order, int pageIndex = 0, int pageSize = 10) + { + int totalNumber = 0; + var list = base.Context.Queryable().Where(expression).OrderBy(order).ToPageList(pageIndex, pageSize, ref totalNumber); + return (list, totalNumber); + } + + public (List, int) QueryableToPage(Expression> expression, Expression> orderFiled, string orderBy, int pageIndex = 0, int pageSize = 10) + { + int totalNumber = 0; + + if (orderBy.Equals("DESC", StringComparison.OrdinalIgnoreCase)) + { + var list = base.Context.Queryable().Where(expression).OrderBy(orderFiled, OrderByType.Desc).ToPageList(pageIndex, pageSize, ref totalNumber); + return (list, totalNumber); + } + else + { + var list = base.Context.Queryable().Where(expression).OrderBy(orderFiled, OrderByType.Asc).ToPageList(pageIndex, pageSize, ref totalNumber); + return (list, totalNumber); + } + } + + //public (List, int) QueryableToPage(Expression> 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().Where(expression).OrderBy(bootstrap.sort).ToPageList(bootstrap.offset, bootstrap.limit, ref totalNumber); + // return (list, totalNumber); + // } + // else + // { + // var list = base.Context.Queryable().Where(expression).OrderBy(bootstrap.sort).ToPageList(bootstrap.offset, bootstrap.limit, ref totalNumber); + // return (list, totalNumber); + // } + //} + + public List SqlQueryToList(string sql, object obj = null) + { + return base.Context.Ado.SqlQuery(sql, obj); + } + /// + /// 获得一条数据 + /// + /// Expression> + /// + public T GetFirst(Expression> where) + { + return Context.Queryable().Where(where).First(); + } + + /// + /// 根据主值查询单条数据 + /// + /// 主键值 + /// 泛型实体 + public T GetId(object pkValue) + { + return Context.Queryable().InSingle(pkValue); + } + + /// + /// 获得一条数据 + /// + /// string + /// + public T GetFirst(string parm) + { + return Context.Queryable().Where(parm).First(); + } + #endregion query + + /// + /// 此方法不带output返回值 + /// var list = new List(); + /// list.Add(new SugarParameter(ParaName, ParaValue)); input + /// + /// + /// + /// + //public DataTable UseStoredProcedureToDataTable(string procedureName, List parameters) + //{ + // return base.Context.Ado.UseStoredProcedure().GetDataTable(procedureName, parameters); + //} + + /// + /// 带output返回值 + /// var list = new List(); + /// list.Add(new SugarParameter(ParaName, ParaValue, true)); output + /// list.Add(new SugarParameter(ParaName, ParaValue)); input + /// + /// + /// + /// + //public (DataTable, List) UseStoredProcedureToTuple(string procedureName, List parameters) + //{ + // var result = (base.Context.Ado.UseStoredProcedure().GetDataTable(procedureName, parameters), parameters); + // return result; + //} + + public string QueryableToJson(string select, Expression> expressionWhere) + { + throw new NotImplementedException(); + } + } +} diff --git a/ZR.Repository/DbProvider/SugarDbContext.cs b/ZR.Repository/DbProvider/SugarDbContext.cs index 69fee4e..de5ff07 100644 --- a/ZR.Repository/DbProvider/SugarDbContext.cs +++ b/ZR.Repository/DbProvider/SugarDbContext.cs @@ -15,18 +15,12 @@ namespace ZR.Repository.DbProvider /// /// 使用SugarSql获取连接对象 - /// 构造方法有问题 /// /// public SugarDbContext() { string connStr = ConfigUtils.Instance.GetConnectionStrings(OptionsSetting.ConnAdmin); - string dbKey = ConfigUtils.Instance.GetAppConfig(OptionsSetting.DbKey); int dbType = ConfigUtils.Instance.GetAppConfig(OptionsSetting.ConnDbType); - if (!string.IsNullOrEmpty(dbKey)) - { - connStr = NETCore.Encrypt.EncryptProvider.DESDecrypt(connStr, dbKey); - } Db = new SqlSugarClient(new List() { @@ -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(); + //}; } } } diff --git a/ZR.Repository/IBaseRepository.cs b/ZR.Repository/IBaseRepository.cs new file mode 100644 index 0000000..545c46d --- /dev/null +++ b/ZR.Repository/IBaseRepository.cs @@ -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 where T : class, new() + { + #region add + int Add(T parm, Expression> 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); + int Insert(T parm, Expression> iClumns = null, bool ignoreNull = true); + + int InsertIgnoreNullColumn(List t); + + int InsertIgnoreNullColumn(List t, params string[] columns); + + DbResult InsertTran(T t); + + DbResult InsertTran(List 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 parameters); + + #endregion add + + #region update + + bool UpdateEntity(T entity, bool ignoreNullColumns = false); + + bool Update(T entity, Expression> expression); + + /// + /// 只更新表达式的值 + /// + /// + /// + /// + bool Update(T entity, Expression> expression, bool ignoreAllNull = false); + + bool Update(T entity, Expression> expression, Expression> where); + + bool Update(SqlSugarClient client, T entity, Expression> expression, Expression> where); + + /// + /// + /// + /// T + /// 忽略更新 + /// Null不更新 + /// + bool Update(T entity, List list = null, bool isNull = true); + + bool Update(List entity); + bool Update(Expression> where, Expression> columns); + + #endregion update + + //DbResult UseTran(Action action); + + //DbResult UseTran(SqlSugarClient client, Action action); + + //bool UseTran2(Action action); + + #region delete + + bool Delete(Expression> expression); + + //bool Delete(PkType[] primaryKeyValues); + + bool Delete(object[] obj); + bool Delete(object id); + bool Delete(); + + #endregion delete + + #region query + + bool IsAny(Expression> expression); + + ISugarQueryable Queryable(); + + //ISugarQueryable Queryable(string tableName, string shortName); + + //ISugarQueryable Queryable() where T1 : class where T2 : new(); + + List QueryableToList(Expression> expression); + + Task> QueryableToListAsync(Expression> expression); + + //string QueryableToJson(string select, Expression> expressionWhere); + + List QueryableToList(string tableName); + + T QueryableToEntity(Expression> expression); + + List QueryableToList(string tableName, Expression> expression); + + (List, int) QueryableToPage(Expression> expression, int pageIndex = 0, int pageSize = 10); + + (List, int) QueryableToPage(Expression> expression, string order, int pageIndex = 0, int pageSize = 10); + + (List, int) QueryableToPage(Expression> expression, Expression> orderFiled, string orderBy, int pageIndex = 0, int pageSize = 10); + + //(List, int) QueryableToPage(Expression> expression, Bootstrap.BootstrapParams bootstrap); + + List SqlQueryToList(string sql, object obj = null); + /// + /// 获得一条数据 + /// + /// Expression> + /// + T GetFirst(Expression> where); + T GetId(object pkValue); + + /// + /// 获得一条数据 + /// + /// string + /// + T GetFirst(string parm); + + #endregion query + + #region Procedure + + //DataTable UseStoredProcedureToDataTable(string procedureName, List parameters); + + //(DataTable, List) UseStoredProcedureToTuple(string procedureName, List parameters); + + #endregion Procedure + } +} diff --git a/ZR.Repository/Repositories/GendemoRepository.cs b/ZR.Repository/Repositories/GendemoRepository.cs new file mode 100644 index 0000000..0a967d4 --- /dev/null +++ b/ZR.Repository/Repositories/GendemoRepository.cs @@ -0,0 +1,24 @@ +using System; +using Infrastructure.Attribute; +using ZR.Repository.System; +using ZR.Model.Models; +using SqlSugar; + +namespace ZR.Repository +{ + /// + /// 代码生成演示仓储接口的实现 + /// + /// @author zhaorui + /// @date 2021-09-24 + /// + [AppService(ServiceLifetime = LifeTime.Transient)] + public class GendemoRepository : BaseRepository + { + public GendemoRepository(SqlSugarClient dbContext) : base(dbContext) + { + } + #region 业务逻辑代码 + #endregion + } +} \ No newline at end of file diff --git a/ZR.Repository/System/GenTableRepository.cs b/ZR.Repository/System/GenTableRepository.cs new file mode 100644 index 0000000..8207ead --- /dev/null +++ b/ZR.Repository/System/GenTableRepository.cs @@ -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 + { + + } + + public class GenTableColumnRepository : BaseRepository + { + /// + /// 根据表id批量删除表字段 + /// + /// + /// + public int DeleteGenTableColumn(long[] tableId) + { + return Context.Deleteable().Where(f => tableId.Contains(f.TableId)).ExecuteCommand(); + } + + /// + /// 根据表名删除字段 + /// + /// + /// + public int DeleteGenTableColumnByTableName(string tableName) + { + return Context.Deleteable().Where(f => f.TableName == tableName).ExecuteCommand(); + } + + /// + /// 获取表所有字段 + /// + /// + /// + public List GenTableColumns(long tableId) + { + return Context.Queryable().Where(f => f.TableId == tableId).OrderBy(x => x.Sort).ToList(); + } + + /// + /// 插入表字段 + /// + /// + /// + public int InsertGenTableColumn(List tableColumn) + { + return Context.Insertable(tableColumn).IgnoreColumns(x => new { x.Remark }).ExecuteCommand(); + } + + /// + /// 批量更新表字段 + /// + /// + /// + public int UpdateGenTableColumn(List tableColumn) + { + foreach (var item in tableColumn) + { + Context.Updateable() + .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; + } + } +} diff --git a/ZR.Repository/System/SysDeptRepository.cs b/ZR.Repository/System/SysDeptRepository.cs index 4935ec2..b41871a 100644 --- a/ZR.Repository/System/SysDeptRepository.cs +++ b/ZR.Repository/System/SysDeptRepository.cs @@ -8,7 +8,7 @@ namespace ZR.Repository.System /// 部门管理 /// [AppService(ServiceLifetime= LifeTime.Transient)] - public class SysDeptRepository : BaseRepository + public class SysDeptRepository : BaseRepository { /// /// @@ -19,12 +19,12 @@ namespace ZR.Repository.System { string sql = "select * from sys_dept where find_in_set(@deptId, ancestors)"; - return Db.SqlQueryable(sql).AddParameters(new { @deptId = deptId }).ToList(); + return Context.SqlQueryable(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(); } } } diff --git a/ZR.Repository/System/SysDictDataRepository.cs b/ZR.Repository/System/SysDictDataRepository.cs index 6cdf0c6..f9830cb 100644 --- a/ZR.Repository/System/SysDictDataRepository.cs +++ b/ZR.Repository/System/SysDictDataRepository.cs @@ -9,7 +9,7 @@ namespace ZR.Repository.System /// 字典数据 /// [AppService(ServiceLifetime = LifeTime.Transient)] - public class SysDictDataRepository : BaseRepository + public class SysDictDataRepository : BaseRepository { /// /// 字典类型数据搜索 @@ -18,7 +18,7 @@ namespace ZR.Repository.System /// public List SelectDictDataList(SysDictData dictData) { - return Db.Queryable() + return Context.Queryable() .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 /// public List SelectDictDataByType(string dictType) { - return Db.Queryable().Where(f => f.Status == "0" && f.DictType == dictType) + return Context.Queryable().Where(f => f.Status == "0" && f.DictType == dictType) .OrderBy(it => it.DictSort) .ToList(); } @@ -44,7 +44,7 @@ namespace ZR.Repository.System /// 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 /// public long UpdateDictData(SysDictData dict) { - return Db.Updateable() + return Context.Updateable() .SetColumns(t => new SysDictData() { Remark = dict.Remark, @@ -76,7 +76,7 @@ namespace ZR.Repository.System /// public int DeleteDictDataByIds(long[] dictCodes) { - return Db.Deleteable().In(dictCodes).ExecuteCommand(); + return Context.Deleteable().In(dictCodes).ExecuteCommand(); } /// @@ -88,7 +88,7 @@ namespace ZR.Repository.System public int UpdateDictDataType(string old_dictType, string new_dictType) { //只更新DictType字段根据where条件 - return Db.Updateable() + return Context.Updateable() .SetColumns(t => new SysDictData() { DictType = new_dictType }) .Where(f => f.DictType == old_dictType) .ExecuteCommand(); diff --git a/ZR.Repository/System/SysDictRepository.cs b/ZR.Repository/System/SysDictRepository.cs index e01de1b..b792879 100644 --- a/ZR.Repository/System/SysDictRepository.cs +++ b/ZR.Repository/System/SysDictRepository.cs @@ -10,7 +10,7 @@ namespace ZR.Repository.System /// 字典 /// [AppService(ServiceLifetime = LifeTime.Transient)] - public class SysDictRepository : BaseRepository + public class SysDictRepository : BaseRepository { /// /// 查询字段类型列表 @@ -20,7 +20,7 @@ namespace ZR.Repository.System public List SelectDictTypeList(SysDictType dictType, Model.PagerInfo pager) { var totalNum = 0; - var list = Db + var list = Context .Queryable() .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 /// public int DeleteDictTypeByIds(long[] id) { - return Db.Deleteable().In(id).ExecuteCommand(); + return Context.Deleteable().In(id).ExecuteCommand(); } /// @@ -47,7 +47,7 @@ namespace ZR.Repository.System /// 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(); } } } diff --git a/ZR.Repository/System/SysLogininfoRepository.cs b/ZR.Repository/System/SysLogininfoRepository.cs index f91a88d..53c023c 100644 --- a/ZR.Repository/System/SysLogininfoRepository.cs +++ b/ZR.Repository/System/SysLogininfoRepository.cs @@ -8,7 +8,7 @@ using ZR.Model.System; namespace ZR.Repository.System { [AppService(ServiceLifetime = LifeTime.Transient)] - public class SysLogininfoRepository : BaseRepository + public class SysLogininfoRepository : BaseRepository { /// /// 查询登录日志 @@ -19,7 +19,7 @@ namespace ZR.Repository.System public List GetLoginLog(SysLogininfor logininfoDto, PagerInfo pager) { int totalCount = 0; - var list = Db.Queryable() + var list = Context.Queryable() .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 /// 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); } /// @@ -60,7 +60,7 @@ namespace ZR.Repository.System /// public int DeleteLogininforByIds(long[] ids) { - return Db.Deleteable().In(ids).ExecuteCommand(); + return Context.Deleteable().In(ids).ExecuteCommand(); } /// @@ -70,7 +70,7 @@ namespace ZR.Repository.System /// public SysUser Login(LoginBodyDto user) { - return Db.Queryable().First(it => it.UserName == user.Username && it.Password == user.Password); + return Context.Queryable().First(it => it.UserName == user.Username && it.Password == user.Password); } /// @@ -81,7 +81,8 @@ namespace ZR.Repository.System /// 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(); } diff --git a/ZR.Repository/System/SysMenuRepository.cs b/ZR.Repository/System/SysMenuRepository.cs index 3fafa0b..8086698 100644 --- a/ZR.Repository/System/SysMenuRepository.cs +++ b/ZR.Repository/System/SysMenuRepository.cs @@ -12,7 +12,7 @@ namespace ZR.Repository.System /// 系统菜单 /// [AppService(ServiceLifetime = LifeTime.Transient)] - public class SysMenuRepository : BaseRepository + public class SysMenuRepository : BaseRepository { /// /// 获取所有菜单(菜单管理) @@ -20,7 +20,7 @@ namespace ZR.Repository.System /// public List SelectMenuList(SysMenu menu) { - return Db.Queryable() + return Context.Queryable() .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 /// public List SelectMenuListByUserId(SysMenu sysMenu, long userId) { - return Db.Queryable((menu, roleMenu, userRole, role) => new JoinQueryInfos( + return Context.Queryable((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() + return Context.Queryable() .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 SelectMenuTreeByRoleIds(List roleIds) { var menuTypes = new string[] { "M", "C"}; - return Db.Queryable((menu, roleMenu) => new JoinQueryInfos( + return Context.Queryable((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 /// public SysMenu SelectMenuById(int menuId) { - return Db.Queryable().Where(it => it.menuId == menuId).Single(); + return Context.Queryable().Where(it => it.menuId == menuId).Single(); } /// @@ -100,6 +100,7 @@ namespace ZR.Repository.System /// 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 /// public int EditMenu(SysMenu menu) { - return Db.Updateable(menu).ExecuteCommand(); + return Context.Updateable(menu).ExecuteCommand(); } /// @@ -122,7 +123,7 @@ namespace ZR.Repository.System /// public int DeleteMenuById(int menuId) { - return Db.Deleteable().Where(it => it.menuId == menuId).ExecuteCommand(); + return Context.Deleteable().Where(it => it.menuId == menuId).ExecuteCommand(); } /// @@ -132,7 +133,7 @@ namespace ZR.Repository.System /// 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 /// public List SelectMenuPermsByUserId(long userId) { - return Db.Queryable((m, rm, ur, r) => new JoinQueryInfos( + return Context.Queryable((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 /// public SysMenu CheckMenuNameUnique(SysMenu menu) { - return Db.Queryable() + return Context.Queryable() .Where(it => it.menuName == menu.menuName && it.parentId == menu.parentId).Single(); } @@ -172,7 +173,7 @@ namespace ZR.Repository.System /// public int HasChildByMenuId(long menuId) { - return Db.Queryable().Where(it => it.parentId == menuId).Count(); + return Context.Queryable().Where(it => it.parentId == menuId).Count(); } #region RoleMenu @@ -184,7 +185,7 @@ namespace ZR.Repository.System /// public int CheckMenuExistRole(long menuId) { - return Db.Queryable().Where(it => it.Menu_id == menuId).Count(); + return Context.Queryable().Where(it => it.Menu_id == menuId).Count(); } #endregion diff --git a/ZR.Repository/System/SysOperLogRepository.cs b/ZR.Repository/System/SysOperLogRepository.cs index 9c47b11..7953394 100644 --- a/ZR.Repository/System/SysOperLogRepository.cs +++ b/ZR.Repository/System/SysOperLogRepository.cs @@ -8,7 +8,7 @@ using ZR.Model.System; namespace ZR.Repository.System { [AppService(ServiceLifetime = LifeTime.Transient)] - public class SysOperLogRepository : BaseRepository + public class SysOperLogRepository : BaseRepository { /// /// 查询操作日志 @@ -19,7 +19,7 @@ namespace ZR.Repository.System public List GetSysOperLog(SysOperLogDto sysOper, PagerInfo pagerInfo) { int totalCount = 0; - var list = Db.Queryable() + var list = Context.Queryable() .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 /// public void AddSysOperLog(SysOperLog sysOperLog) { - Db.Insertable(sysOperLog).ExecuteCommandAsync(); + Context.Insertable(sysOperLog).ExecuteCommandAsync(); } /// @@ -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); } /// @@ -57,7 +57,7 @@ namespace ZR.Repository.System /// public int DeleteOperLogByIds(long[] operIds) { - return Db.Deleteable().In(operIds).ExecuteCommand(); + return Context.Deleteable().In(operIds).ExecuteCommand(); } /// @@ -67,7 +67,7 @@ namespace ZR.Repository.System /// public SysOperLog SelectOperLogById(long operId) { - return Db.Queryable().InSingle(operId); + return Context.Queryable().InSingle(operId); } } } diff --git a/ZR.Repository/System/SysPostRepository.cs b/ZR.Repository/System/SysPostRepository.cs new file mode 100644 index 0000000..bd31ba6 --- /dev/null +++ b/ZR.Repository/System/SysPostRepository.cs @@ -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 + { + } +} diff --git a/ZR.Repository/System/SysRoleRepository.cs b/ZR.Repository/System/SysRoleRepository.cs index fc2480d..2a70a10 100644 --- a/ZR.Repository/System/SysRoleRepository.cs +++ b/ZR.Repository/System/SysRoleRepository.cs @@ -9,7 +9,7 @@ namespace ZR.Repository.System /// 角色操作类 /// [AppService(ServiceLifetime = LifeTime.Transient)] - public class SysRoleRepository : BaseRepository + public class SysRoleRepository : BaseRepository { /// /// 根据条件分页查询角色数据 @@ -17,7 +17,7 @@ namespace ZR.Repository.System /// public List SelectRoleList(SysRole sysRole) { - return Db.Queryable() + return Context.Queryable() .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 /// public List SelectRolePermissionByUserId(long userId) { - return Db.Queryable() + return Context.Queryable() .Where(role => role.DelFlag == "0") .Where(it => SqlFunc.Subqueryable().Where(s => s.UserId == userId).Any()) .OrderBy(role => role.RoleSort) @@ -46,7 +46,7 @@ namespace ZR.Repository.System /// public List SelectRoleAll() { - return Db.Queryable().OrderBy(it => it.RoleSort).ToList(); + return Context.Queryable().OrderBy(it => it.RoleSort).ToList(); } /// @@ -56,7 +56,7 @@ namespace ZR.Repository.System /// public SysRole SelectRoleById(long roleId) { - return Db.Queryable().InSingle(roleId); + return Context.Queryable().InSingle(roleId); } /// @@ -66,7 +66,7 @@ namespace ZR.Repository.System /// public int DeleteRoleByRoleIds(long[] roleId) { - return Db.Deleteable().In(roleId).ExecuteCommand(); + return Context.Deleteable().In(roleId).ExecuteCommand(); } /// @@ -76,7 +76,7 @@ namespace ZR.Repository.System /// public List SelectUserRoleListByUserId(long userId) { - return Db.Queryable((ur, r) => new SqlSugar.JoinQueryInfos( + return Context.Queryable((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 /// public List SelectRoleMenuByRoleId(long roleId) { - return Db.Queryable().Where(it => it.Role_id == roleId).ToList(); + return Context.Queryable().Where(it => it.Role_id == roleId).ToList(); } /// @@ -101,7 +101,7 @@ namespace ZR.Repository.System /// public int AddRoleMenu(List sysRoleMenus) { - return Db.Insertable(sysRoleMenus).ExecuteCommand(); + return Context.Insertable(sysRoleMenus).ExecuteCommand(); } /// @@ -111,7 +111,7 @@ namespace ZR.Repository.System /// public int DeleteRoleMenuByRoleId(long roleId) { - return Db.Deleteable().Where(it => it.Role_id == roleId).ExecuteCommand(); + return Context.Deleteable().Where(it => it.Role_id == roleId).ExecuteCommand(); } #endregion @@ -123,8 +123,8 @@ namespace ZR.Repository.System /// 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(); } /// @@ -134,7 +134,7 @@ namespace ZR.Repository.System /// public int UpdateSysRole(SysRole sysRole) { - var db = Db; + var db = Context; sysRole.Update_time = db.GetDate(); return db.Updateable() @@ -156,7 +156,7 @@ namespace ZR.Repository.System /// 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(); } /// @@ -166,7 +166,7 @@ namespace ZR.Repository.System /// public SysRole CheckRoleKeyUnique(string roleKey) { - return Db.Queryable().Where(it => it.RoleKey == roleKey).Single(); + return Context.Queryable().Where(it => it.RoleKey == roleKey).Single(); } /// @@ -176,7 +176,7 @@ namespace ZR.Repository.System /// public SysRole CheckRoleNameUnique(string roleName) { - return Db.Queryable().Where(it => it.RoleName == roleName).Single(); + return Context.Queryable().Where(it => it.RoleName == roleName).Single(); } } } diff --git a/ZR.Repository/System/SysUserPostRepository.cs b/ZR.Repository/System/SysUserPostRepository.cs index 73ffb91..af85023 100644 --- a/ZR.Repository/System/SysUserPostRepository.cs +++ b/ZR.Repository/System/SysUserPostRepository.cs @@ -9,7 +9,7 @@ namespace ZR.Repository.System /// 用户岗位 /// [AppService(ServiceLifetime = LifeTime.Transient)] - public class SysUserPostRepository : BaseRepository + public class SysUserPostRepository : BaseRepository { /// /// 获取用户岗位 @@ -18,7 +18,7 @@ namespace ZR.Repository.System /// public List SelectPostsByUserId(long userId) { - return Db.Queryable((p, up) => new JoinQueryInfos( + return Context.Queryable((p, up) => new JoinQueryInfos( JoinType.Left, up.PostId == p.PostId )).Where((p, up) => up.UserId == userId) .Select().ToList(); diff --git a/ZR.Repository/System/SysUserRepository.cs b/ZR.Repository/System/SysUserRepository.cs index 754edcd..c9e8e8c 100644 --- a/ZR.Repository/System/SysUserRepository.cs +++ b/ZR.Repository/System/SysUserRepository.cs @@ -10,7 +10,7 @@ namespace ZR.Repository.System /// 用户管理 /// [AppService(ServiceLifetime = LifeTime.Transient)] - public class SysUserRepository : BaseRepository + public class SysUserRepository : BaseRepository { /// /// 根据条件分页查询用户列表 @@ -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(sql) + var list = Context.SqlQueryable(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 /// public SysUser SelectUserById(long userId) { - return Db.Queryable().Where(f => f.UserId == userId).First(); + return Context.Queryable().Where(f => f.UserId == userId).First(); } /// @@ -54,7 +54,7 @@ namespace ZR.Repository.System /// public int CheckUserNameUnique(string userName) { - return Db.Queryable().Where(it => it.UserName == userName).Count(); + return Context.Queryable().Where(it => it.UserName == userName).Count(); } /// @@ -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(); } /// @@ -76,7 +76,7 @@ namespace ZR.Repository.System /// 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 /// 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 /// 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 /// 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 /// public int UpdatePhoto(SysUser user) { - return Db.Updateable() + return Context.Updateable() .SetColumns(t => new SysUser() { Avatar = user.Avatar diff --git a/ZR.Repository/System/SysUserRoleRepository.cs b/ZR.Repository/System/SysUserRoleRepository.cs index f63d296..4f80eed 100644 --- a/ZR.Repository/System/SysUserRoleRepository.cs +++ b/ZR.Repository/System/SysUserRoleRepository.cs @@ -6,7 +6,7 @@ using ZR.Model.System; namespace ZR.Repository.System { [AppService(ServiceLifetime = LifeTime.Transient)] - public class SysUserRoleRepository : BaseRepository + public class SysUserRoleRepository : BaseRepository { /// /// 删除用户角色 @@ -15,7 +15,7 @@ namespace ZR.Repository.System /// public int DeleteUserRoleByUserId(int userId) { - return Db.Deleteable().Where(it => it.UserId == userId).ExecuteCommand(); + return Context.Deleteable().Where(it => it.UserId == userId).ExecuteCommand(); } /// @@ -26,7 +26,7 @@ namespace ZR.Repository.System /// public int DeleteRoleUserByUserIds(long roleId, List userIds) { - return Db.Deleteable().Where(it => it.RoleId == roleId && userIds.Contains(it.UserId)) + return Context.Deleteable().Where(it => it.RoleId == roleId && userIds.Contains(it.UserId)) .ExecuteCommand(); } @@ -37,7 +37,7 @@ namespace ZR.Repository.System /// public int AddUserRole(List sysUsers) { - return Db.Insertable(sysUsers).ExecuteCommand(); + return Context.Insertable(sysUsers).ExecuteCommand(); } /// @@ -47,7 +47,7 @@ namespace ZR.Repository.System /// public int DeleteUserRoleByRoleId(int roleId) { - return Db.Deleteable().In(roleId).ExecuteCommand(); + return Context.Deleteable().In(roleId).ExecuteCommand(); } /// @@ -57,7 +57,7 @@ namespace ZR.Repository.System /// public int CountUserRoleByRoleId(long roleId) { - return Db.Queryable().Where(it => it.RoleId == roleId).Count(); + return Context.Queryable().Where(it => it.RoleId == roleId).Count(); } /// @@ -67,7 +67,7 @@ namespace ZR.Repository.System /// public List GetSysUsersByRoleId(long roleId) { - return Db.Queryable((t1, u) => new JoinQueryInfos( + return Context.Queryable((t1, u) => new JoinQueryInfos( JoinType.Left, t1.UserId == u.UserId)) .Where((t1, u) => t1.RoleId == roleId && u.DelFlag == "0") .Select((t1, u) => u) diff --git a/ZR.Service/BaseService.cs b/ZR.Service/BaseService.cs index 8eb83d0..e9f4097 100644 --- a/ZR.Service/BaseService.cs +++ b/ZR.Service/BaseService.cs @@ -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 /// 基础服务定义 /// /// - public class BaseService : SugarDbContext, IBaseService where T : class, new() + public class BaseService : BaseRepository where T : class,new()//, IBaseService where T : class, new() { + //private readonly IBaseRepository BaseRepository; + //public BaseService(IBaseRepository baseRepository) + //{ + // BaseRepository = baseRepository; + //} + #region 事务 - /// - /// 启用事务 - /// - public void BeginTran() - { - Db.Ado.BeginTran(); - } + ///// + ///// 启用事务 + ///// + //public void BeginTran() + //{ + // Context.Ado.BeginTran(); + //} - /// - /// 提交事务 - /// - public void CommitTran() - { - Db.Ado.CommitTran(); - } + ///// + ///// 提交事务 + ///// + //public void CommitTran() + //{ + // Context.Ado.CommitTran(); + //} - /// - /// 回滚事务 - /// - public void RollbackTran() - { - Db.Ado.RollbackTran(); - } + ///// + ///// 回滚事务 + ///// + //public void RollbackTran() + //{ + // Context.Ado.RollbackTran(); + //} #endregion @@ -51,7 +58,7 @@ namespace ZR.Service /// public int Add(T parm) { - return Db.Insertable(parm).RemoveDataCache().ExecuteCommand(); + return base.Add(parm);// Context.Insertable(parm).RemoveDataCache().ExecuteCommand(); } /// @@ -61,10 +68,10 @@ namespace ZR.Service /// 插入列 /// 忽略null列 /// - public int Add(T parm, Expression> iClumns = null, bool ignoreNull = true) - { - return Db.Insertable(parm).InsertColumns(iClumns).IgnoreColumns(ignoreNullColumn: ignoreNull).ExecuteCommand(); - } + //public int Add(T parm, Expression> iClumns = null, bool ignoreNull = true) + //{ + // return Add(parm); + //} /// /// 批量添加数据 @@ -73,7 +80,7 @@ namespace ZR.Service /// public int Add(List parm) { - return Db.Insertable(parm).RemoveDataCache().ExecuteCommand(); + return Context.Insertable(parm).RemoveDataCache().ExecuteCommand(); } /// @@ -83,7 +90,7 @@ namespace ZR.Service /// public T Saveable(T parm, Expression> uClumns = null, Expression> iColumns = null) { - var command = Db.Saveable(parm); + var command = Context.Saveable(parm); if (uClumns != null) { @@ -105,7 +112,7 @@ namespace ZR.Service /// public List Saveable(List parm, Expression> uClumns = null, Expression> iColumns = null) { - var command = Db.Saveable(parm); + var command = Context.Saveable(parm); if (uClumns != null) { @@ -128,10 +135,10 @@ namespace ZR.Service /// /// 条件表达式树 /// - public bool Any(Expression> where) - { - return Db.Queryable().Any(where); - } + //public bool Any(Expression> where) + //{ + // return base.Context.Any(where); + //} /// /// 根据条件合计字段 @@ -140,7 +147,7 @@ namespace ZR.Service /// public TResult Sum(Expression> where, Expression> field) { - return Db.Queryable().Where(where).Sum(field); + return base.Context.Queryable().Where(where).Sum(field); } /// @@ -148,10 +155,10 @@ namespace ZR.Service /// /// 主键值 /// 泛型实体 - public T GetId(object pkValue) - { - return Db.Queryable().InSingle(pkValue); - } + //public T GetId(object pkValue) + //{ + // return base.Context.Queryable().InSingle(pkValue); + //} /// /// 根据主键查询多条数据 @@ -160,7 +167,7 @@ namespace ZR.Service /// public List GetIn(object[] ids) { - return Db.Queryable().In(ids).ToList(); + return Context.Queryable().In(ids).ToList(); } /// @@ -170,7 +177,7 @@ namespace ZR.Service /// public int GetCount(Expression> where) { - return Db.Queryable().Count(where); + return Context.Queryable().Count(where); } @@ -180,7 +187,7 @@ namespace ZR.Service /// public List GetAll(bool useCache = false, int cacheSecond = 3600) { - return Db.Queryable().WithCacheIF(useCache, cacheSecond).ToList(); + return Context.Queryable().WithCacheIF(useCache, cacheSecond).ToList(); } /// @@ -188,9 +195,9 @@ namespace ZR.Service /// /// Expression> /// - public T GetFirst(Expression> where) + public T GetFirst2(Expression> where) { - return Db.Queryable().Where(where).First(); + return base.GetFirst(where);// Context.Queryable().Where(where).First(); } /// @@ -198,11 +205,10 @@ namespace ZR.Service /// /// string /// - public T GetFirst(string parm) - { - return Db.Queryable().Where(parm).First(); - } - + //public T GetFirst(string parm) + //{ + // return Context.Queryable().Where(parm).First(); + //} /// /// 根据条件查询分页数据 @@ -212,14 +218,14 @@ namespace ZR.Service /// public PagedInfo GetPages(Expression> where, PagerInfo parm) { - var source = Db.Queryable().Where(where); + var source = Context.Queryable().Where(where); return source.ToPage(parm); } public PagedInfo GetPages(Expression> where, PagerInfo parm, Expression> order, string orderEnum = "Asc") { - var source = Db.Queryable().Where(where).OrderByIF(orderEnum == "Asc", order, OrderByType.Asc).OrderByIF(orderEnum == "Desc", order, OrderByType.Desc); + var source = Context.Queryable().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 /// public List GetWhere(Expression> where, bool useCache = false, int cacheSecond = 3600) { - var query = Db.Queryable().Where(where).WithCacheIF(useCache, cacheSecond); + var query = Context.Queryable().Where(where).WithCacheIF(useCache, cacheSecond); return query.ToList(); } @@ -242,7 +248,7 @@ namespace ZR.Service /// public List GetWhere(Expression> where, Expression> order, string orderEnum = "Asc", bool useCache = false, int cacheSecond = 3600) { - var query = Db.Queryable().Where(where).OrderByIF(orderEnum == "Asc", order, OrderByType.Asc).OrderByIF(orderEnum == "Desc", order, OrderByType.Desc).WithCacheIF(useCache, cacheSecond); + var query = Context.Queryable().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 修改操作 - /// - /// 修改一条数据 - /// - /// T - /// - public int Update(T parm) - { - return Db.Updateable(parm).RemoveDataCache().ExecuteCommand(); - } + ///// + ///// 修改一条数据 + ///// + ///// T + ///// + //public int Update(T parm) + //{ + // return Context.Updateable(parm).RemoveDataCache().ExecuteCommand(); + //} - /// - /// 批量修改 - /// - /// T - /// - public int Update(List parm) - { - return Db.Updateable(parm).RemoveDataCache().ExecuteCommand(); - } + ///// + ///// 批量修改 + ///// + ///// T + ///// + //public int Update(List parm) + //{ + // return Context.Updateable(parm).RemoveDataCache().ExecuteCommand(); + //} - /// - /// 按查询条件更新 - /// - /// - /// - /// - public int Update(Expression> where, Expression> columns) - { - return Db.Updateable().SetColumns(columns).Where(where).RemoveDataCache().ExecuteCommand(); - } + ///// + ///// 按查询条件更新 + ///// + ///// + ///// + ///// + //public int Update(Expression> where, Expression> columns) + //{ + // return Context.Updateable().SetColumns(columns).Where(where).RemoveDataCache().ExecuteCommand(); + //} #endregion #region 删除操作 - /// - /// 删除一条或多条数据 - /// - /// string - /// - public int Delete(object id) - { - return Db.Deleteable(id).RemoveDataCache().ExecuteCommand(); - } + ///// + ///// 删除一条或多条数据 + ///// + ///// string + ///// + //public int Delete(object id) + //{ + // return Context.Deleteable(id).RemoveDataCache().ExecuteCommand(); + //} - /// - /// 删除一条或多条数据 - /// - /// string - /// - public int Delete(object[] ids) - { - return Db.Deleteable().In(ids).RemoveDataCache().ExecuteCommand(); - } + ///// + ///// 删除一条或多条数据 + ///// + ///// string + ///// + //public int Delete(object[] ids) + //{ + // return Context.Deleteable().In(ids).RemoveDataCache().ExecuteCommand(); + //} - /// - /// 根据条件删除一条或多条数据 - /// - /// 过滤条件 - /// - public int Delete(Expression> where) - { - return Db.Deleteable().Where(where).RemoveDataCache().ExecuteCommand(); - } + ///// + ///// 根据条件删除一条或多条数据 + ///// + ///// 过滤条件 + ///// + //public int Delete(Expression> where) + //{ + // return Context.Deleteable().Where(where).RemoveDataCache().ExecuteCommand(); + //} public int DeleteTable() { - return Db.Deleteable().RemoveDataCache().ExecuteCommand(); + return Context.Deleteable().RemoveDataCache().ExecuteCommand(); } #endregion diff --git a/ZR.Service/Business/GendemoService.cs b/ZR.Service/Business/GendemoService.cs new file mode 100644 index 0000000..119fa92 --- /dev/null +++ b/ZR.Service/Business/GendemoService.cs @@ -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 +{ + /// + /// 代码生成演示Service业务层处理 + /// + /// @author zhaorui + /// @date 2021-09-24 + /// + [AppService(ServiceType = typeof(IGendemoService), ServiceLifetime = LifeTime.Transient)] + public class GendemoService : BaseService, IGendemoService + { + //private readonly SqlSugarClient _client; + + //public GendemoService(SqlSugarClient client, int db =1) : base(db) + //{ + // _client = client; + //} + + #region 业务逻辑代码 + + #endregion + } +} \ No newline at end of file diff --git a/ZR.Service/Business/IBusService/IGendemoService.cs b/ZR.Service/Business/IBusService/IGendemoService.cs new file mode 100644 index 0000000..a99bf46 --- /dev/null +++ b/ZR.Service/Business/IBusService/IGendemoService.cs @@ -0,0 +1,15 @@ +using System; +using ZR.Model.Models; + +namespace ZR.Service.Business +{ + /// + /// 代码生成演示service接口 + /// + /// @author zhaorui + /// @date 2021-09-24 + /// + public interface IGendemoService: IBaseService + { + } +} diff --git a/ZR.Service/IBaseService.cs b/ZR.Service/IBaseService.cs index 38d2065..13f602e 100644 --- a/ZR.Service/IBaseService.cs +++ b/ZR.Service/IBaseService.cs @@ -15,22 +15,22 @@ namespace ZR.Service #region 事务 - /// - /// 启用事务 - /// - void BeginTran(); + ///// + ///// 启用事务 + ///// + //void BeginTran(); - /// - /// 提交事务 - /// - void CommitTran(); + ///// + ///// 提交事务 + ///// + //void CommitTran(); - /// - /// 回滚事务 - /// - void RollbackTran(); + ///// + ///// 回滚事务 + ///// + //void RollbackTran(); #endregion diff --git a/ZR.Service/System/ArticleCategoryService.cs b/ZR.Service/System/ArticleCategoryService.cs index 7ef4573..8df3251 100644 --- a/ZR.Service/System/ArticleCategoryService.cs +++ b/ZR.Service/System/ArticleCategoryService.cs @@ -10,7 +10,7 @@ namespace ZR.Service.System /// 文章目录 /// [AppService(ServiceType = typeof(IArticleCategoryService), ServiceLifetime = LifeTime.Transient)] - public class ArticleCategoryService : BaseService, IArticleCategoryService + public class ArticleCategoryService : IArticleCategoryService { /// /// 构建前端所需要树结构 diff --git a/ZR.Service/System/ArticleService.cs b/ZR.Service/System/ArticleService.cs index 863efa9..2cee43b 100644 --- a/ZR.Service/System/ArticleService.cs +++ b/ZR.Service/System/ArticleService.cs @@ -8,7 +8,7 @@ namespace ZR.Service.System /// /// [AppService(ServiceType = typeof(IArticleService), ServiceLifetime = LifeTime.Transient)] - public class ArticleService : BaseService
, IArticleService + public class ArticleService : IArticleService { } diff --git a/ZR.Service/System/GenTableService.cs b/ZR.Service/System/GenTableService.cs index 782324e..4e6d99e 100644 --- a/ZR.Service/System/GenTableService.cs +++ b/ZR.Service/System/GenTableService.cs @@ -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 /// 代码生成表 ///
[AppService(ServiceType = typeof(IGenTableService), ServiceLifetime = LifeTime.Transient)] - public class GenTableService : BaseService, 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; } /// @@ -29,7 +32,7 @@ namespace ZR.Service.System /// public int DeleteGenTableByIds(long[] tableIds) { - Db.Deleteable().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 /// public int DeleteGenTableByTbName(string tableName) { - return Db.Deleteable().Where(f => f.TableName == tableName).ExecuteCommand(); + return GenTableRepository.Delete(f => f.TableName == tableName) ? 1 : 0; } /// @@ -50,7 +53,7 @@ namespace ZR.Service.System /// public GenTable GetGenTableInfo(long tableId) { - return GetId(tableId); + return GenTableRepository.GetById(tableId); } /// @@ -64,7 +67,11 @@ namespace ZR.Service.System var predicate = Expressionable.Create(); predicate = predicate.AndIF(genTable.TableName.IfNotEmpty(), it => it.TableName.Contains(genTable.TableName)); - return GetPages(predicate.ToExpression(), pagerInfo); + (List, int) ts = GenTableRepository.QueryableToPage(predicate.ToExpression(), pagerInfo.PageNum, pagerInfo.PageSize); + + PagedInfo pagedInfo = new(ts.Item1, pagerInfo.PageNum, pagerInfo.PageSize); + pagedInfo.TotalCount = ts.Item2; + return pagedInfo; } /// @@ -74,13 +81,12 @@ namespace ZR.Service.System /// 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(); } /// @@ -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 /// 代码生成表列 /// [AppService(ServiceType = typeof(IGenTableColumnService), ServiceLifetime = LifeTime.Transient)] - public class GenTableColumnService : BaseService, IGenTableColumnService + public class GenTableColumnService : IGenTableColumnService { + + private GenTableColumnRepository GetTableColumnRepository; + public GenTableColumnService(GenTableColumnRepository genTableColumnRepository) + { + GetTableColumnRepository = genTableColumnRepository; + } /// /// 删除表字段 /// @@ -114,7 +126,7 @@ namespace ZR.Service.System /// public int DeleteGenTableColumn(long tableId) { - return DeleteGenTableColumn(new long[] { tableId }); + return GetTableColumnRepository.DeleteGenTableColumn(new long[] { tableId }); } /// /// 根据表id批量删除表字段 @@ -123,7 +135,7 @@ namespace ZR.Service.System /// public int DeleteGenTableColumn(long[] tableId) { - return Db.Deleteable().Where(f => tableId.Contains(f.TableId)).ExecuteCommand(); + return GetTableColumnRepository.DeleteGenTableColumn(tableId); } /// @@ -133,7 +145,7 @@ namespace ZR.Service.System /// public int DeleteGenTableColumnByTableName(string tableName) { - return Db.Deleteable().Where(f => f.TableName == tableName).ExecuteCommand(); + return GetTableColumnRepository.DeleteGenTableColumnByTableName(tableName); } /// @@ -143,7 +155,7 @@ namespace ZR.Service.System /// public List GenTableColumns(long tableId) { - return Db.Queryable().Where(f => f.TableId == tableId).OrderBy(x => x.Sort).ToList(); + return GetTableColumnRepository.GenTableColumns(tableId); } /// @@ -153,7 +165,7 @@ namespace ZR.Service.System /// public int InsertGenTableColumn(List tableColumn) { - return Db.Insertable(tableColumn).IgnoreColumns(x => new { x.Remark }).ExecuteCommand(); + return GetTableColumnRepository.InsertGenTableColumn(tableColumn); } /// @@ -163,31 +175,7 @@ namespace ZR.Service.System /// public int UpdateGenTableColumn(List tableColumn) { - foreach (var item in tableColumn) - { - Db.Updateable() - .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); } } } diff --git a/ZR.Service/System/IService/IArticleCategoryService.cs b/ZR.Service/System/IService/IArticleCategoryService.cs index 602b228..57c7427 100644 --- a/ZR.Service/System/IService/IArticleCategoryService.cs +++ b/ZR.Service/System/IService/IArticleCategoryService.cs @@ -7,7 +7,7 @@ using ZR.Model.System; namespace ZR.Service.System.IService { - public interface IArticleCategoryService : IBaseService + public interface IArticleCategoryService //: IBaseService { List BuildCategoryTree(List categories); } diff --git a/ZR.Service/System/IService/IArticleService.cs b/ZR.Service/System/IService/IArticleService.cs index 0f4e7de..cbfa13f 100644 --- a/ZR.Service/System/IService/IArticleService.cs +++ b/ZR.Service/System/IService/IArticleService.cs @@ -8,7 +8,7 @@ using ZR.Model.System; namespace ZR.Service.System.IService { - public interface IArticleService : IBaseService
+ public interface IArticleService //: IBaseService
{ } diff --git a/ZR.Service/System/IService/ISysDeptService.cs b/ZR.Service/System/IService/ISysDeptService.cs index 4e90491..1dc6b77 100644 --- a/ZR.Service/System/IService/ISysDeptService.cs +++ b/ZR.Service/System/IService/ISysDeptService.cs @@ -6,7 +6,7 @@ using ZR.Model.Vo.System; namespace ZR.Service.System.IService { - public interface ISysDeptService : IBaseService + public interface ISysDeptService //: IBaseService { public List GetSysDepts(SysDept dept); public string CheckDeptNameUnique(SysDept dept); diff --git a/ZR.Service/System/IService/ISysDictDataService.cs b/ZR.Service/System/IService/ISysDictDataService.cs index d048b1a..7d57d66 100644 --- a/ZR.Service/System/IService/ISysDictDataService.cs +++ b/ZR.Service/System/IService/ISysDictDataService.cs @@ -5,7 +5,7 @@ using ZR.Model.System; namespace ZR.Service.System.IService { - public interface ISysDictDataService : IBaseService + public interface ISysDictDataService { public List SelectDictDataList(SysDictData dictData); public List SelectDictDataByType(string dictType); diff --git a/ZR.Service/System/IService/ISysDictService.cs b/ZR.Service/System/IService/ISysDictService.cs index 6d99e7a..28d77cd 100644 --- a/ZR.Service/System/IService/ISysDictService.cs +++ b/ZR.Service/System/IService/ISysDictService.cs @@ -8,7 +8,7 @@ namespace ZR.Service.System.IService /// /// /// - public interface ISysDictService: IBaseService + public interface ISysDictService : IBaseService { public List SelectDictTypeList(SysDictType dictType, Model.PagerInfo pager); diff --git a/ZR.Service/System/IService/ISysFileService.cs b/ZR.Service/System/IService/ISysFileService.cs index f223bff..99daf07 100644 --- a/ZR.Service/System/IService/ISysFileService.cs +++ b/ZR.Service/System/IService/ISysFileService.cs @@ -3,7 +3,7 @@ using ZR.Model.System; namespace ZR.Service.System.IService { - public interface ISysFileService : IBaseService + public interface ISysFileService { } } diff --git a/ZR.Service/System/IService/ISysMenuService.cs b/ZR.Service/System/IService/ISysMenuService.cs index 8928c4e..90aea34 100644 --- a/ZR.Service/System/IService/ISysMenuService.cs +++ b/ZR.Service/System/IService/ISysMenuService.cs @@ -6,7 +6,7 @@ using ZR.Model.Vo.System; namespace ZR.Service.System.IService { - public interface ISysMenuService: IBaseService + public interface ISysMenuService { public List SelectMenuList(long userId); diff --git a/ZR.Service/System/IService/ISysOperLogService.cs b/ZR.Service/System/IService/ISysOperLogService.cs index 0029904..7f9eb76 100644 --- a/ZR.Service/System/IService/ISysOperLogService.cs +++ b/ZR.Service/System/IService/ISysOperLogService.cs @@ -6,7 +6,7 @@ using ZR.Service.System; namespace ZR.Service.System.IService { - public interface ISysOperLogService : IBaseService + public interface ISysOperLogService { public void InsertOperlog(SysOperLog operLog); diff --git a/ZR.Service/System/IService/ISysPostService.cs b/ZR.Service/System/IService/ISysPostService.cs index 9cd098b..6230e23 100644 --- a/ZR.Service/System/IService/ISysPostService.cs +++ b/ZR.Service/System/IService/ISysPostService.cs @@ -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 + public interface ISysPostService: IBaseRepository { string CheckPostNameUnique(SysPost sysPost); string CheckPostCodeUnique(SysPost sysPost); diff --git a/ZR.Service/System/IService/ISysRoleService.cs b/ZR.Service/System/IService/ISysRoleService.cs index 6f039fd..f4f2bcc 100644 --- a/ZR.Service/System/IService/ISysRoleService.cs +++ b/ZR.Service/System/IService/ISysRoleService.cs @@ -6,7 +6,7 @@ using ZR.Model.System; namespace ZR.Service.System.IService { - public interface ISysRoleService: IBaseService + public interface ISysRoleService { /// /// 根据条件分页查询角色数据 diff --git a/ZR.Service/System/IService/ISysTasksLogService.cs b/ZR.Service/System/IService/ISysTasksLogService.cs index 48dbff4..c5885e7 100644 --- a/ZR.Service/System/IService/ISysTasksLogService.cs +++ b/ZR.Service/System/IService/ISysTasksLogService.cs @@ -1,8 +1,9 @@ using ZR.Model.System; +using ZR.Repository; namespace ZR.Service.System.IService { - public interface ISysTasksLogService : IBaseService + public interface ISysTasksLogService: IBaseRepository { /// /// 记录任务执行日志 diff --git a/ZR.Service/System/IService/ISysTasksQzService.cs b/ZR.Service/System/IService/ISysTasksQzService.cs index 69931d0..d3df7a1 100644 --- a/ZR.Service/System/IService/ISysTasksQzService.cs +++ b/ZR.Service/System/IService/ISysTasksQzService.cs @@ -7,7 +7,8 @@ using ZR.Model.System; namespace ZR.Service.System.IService { - public interface ISysTasksQzService: IBaseService + public interface ISysTasksQzService { + SysTasksQz GetId(object id); } } diff --git a/ZR.Service/System/IService/ISysUserPostService.cs b/ZR.Service/System/IService/ISysUserPostService.cs index 0514047..193dfdd 100644 --- a/ZR.Service/System/IService/ISysUserPostService.cs +++ b/ZR.Service/System/IService/ISysUserPostService.cs @@ -3,12 +3,13 @@ using ZR.Model.System; namespace ZR.Service.System.IService { - public interface ISysUserPostService: IBaseService + public interface ISysUserPostService { public void InsertUserPost(SysUser user); public List GetUserPostsByUserId(long userId); public string GetPostsStrByUserId(long userId); + int Delete(long userId); } } diff --git a/ZR.Service/System/IService/ISysUserService.cs b/ZR.Service/System/IService/ISysUserService.cs index f49e926..4f56323 100644 --- a/ZR.Service/System/IService/ISysUserService.cs +++ b/ZR.Service/System/IService/ISysUserService.cs @@ -8,7 +8,7 @@ using ZR.Model.System; namespace ZR.Service.System.IService { - public interface ISysUserService : IBaseService + public interface ISysUserService { public List SelectUserList(SysUser user, PagerInfo pager); diff --git a/ZR.Service/System/SysDeptService.cs b/ZR.Service/System/SysDeptService.cs index a99c541..fb6dbc5 100644 --- a/ZR.Service/System/SysDeptService.cs +++ b/ZR.Service/System/SysDeptService.cs @@ -18,7 +18,7 @@ namespace ZR.Service.System /// 部门管理 /// [AppService(ServiceType = typeof(ISysDeptService), ServiceLifetime = LifeTime.Transient)] - public class SysDeptService : BaseService, 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 /// 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); } /// @@ -86,8 +86,8 @@ namespace ZR.Service.System /// 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); } } diff --git a/ZR.Service/System/SysDictDataService.cs b/ZR.Service/System/SysDictDataService.cs index 92c7a01..e52501c 100644 --- a/ZR.Service/System/SysDictDataService.cs +++ b/ZR.Service/System/SysDictDataService.cs @@ -10,7 +10,7 @@ using ZR.Service.System.IService; namespace ZR.Service.System { [AppService(ServiceType = typeof(ISysDictDataService), ServiceLifetime = LifeTime.Transient)] - public class SysDictDataService: BaseService, 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; diff --git a/ZR.Service/System/SysDictService.cs b/ZR.Service/System/SysDictService.cs index cf8c849..fb72f93 100644 --- a/ZR.Service/System/SysDictService.cs +++ b/ZR.Service/System/SysDictService.cs @@ -15,12 +15,12 @@ namespace ZR.Service.System [AppService(ServiceType = typeof(ISysDictService), ServiceLifetime = LifeTime.Transient)] public class SysDictService : BaseService, 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 /// public List SelectDictTypeList(SysDictType dictType, Model.PagerInfo pager) { - return sysDictRepository.SelectDictTypeList(dictType, pager); + return DictRepository.SelectDictTypeList(dictType, pager); } /// @@ -41,7 +41,7 @@ namespace ZR.Service.System /// 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 /// public long InsertDictType(SysDictType sysDictType) { - return Saveable(sysDictType, iColumns: it => new { sysDictType.Update_by }).DictId; + return DictRepository.InsertReturnEntity(sysDictType).DictId; } /// @@ -89,13 +89,13 @@ namespace ZR.Service.System /// 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); } } } diff --git a/ZR.Service/System/SysFileService.cs b/ZR.Service/System/SysFileService.cs index 5098a88..7a0741d 100644 --- a/ZR.Service/System/SysFileService.cs +++ b/ZR.Service/System/SysFileService.cs @@ -8,7 +8,7 @@ namespace ZR.Service.System /// 文件管理 /// [AppService(ServiceType = typeof(ISysFileService), ServiceLifetime = LifeTime.Transient)] - public class SysFileService: BaseService, ISysFileService + public class SysFileService : ISysFileService { } diff --git a/ZR.Service/System/SysMenuService.cs b/ZR.Service/System/SysMenuService.cs index 780a468..cbc39c6 100644 --- a/ZR.Service/System/SysMenuService.cs +++ b/ZR.Service/System/SysMenuService.cs @@ -15,7 +15,7 @@ namespace ZR.Service /// 菜单 /// [AppService(ServiceType = typeof(ISysMenuService), ServiceLifetime = LifeTime.Transient)] - public class SysMenuService: BaseService, ISysMenuService + public class SysMenuService: ISysMenuService { public SysMenuRepository MenuRepository; public ISysRoleService SysRoleService; diff --git a/ZR.Service/System/SysOperLogService.cs b/ZR.Service/System/SysOperLogService.cs index 80a5f5f..043ba8c 100644 --- a/ZR.Service/System/SysOperLogService.cs +++ b/ZR.Service/System/SysOperLogService.cs @@ -13,7 +13,7 @@ namespace ZR.Service.System /// 操作日志 /// [AppService(ServiceType = typeof(ISysOperLogService), ServiceLifetime = LifeTime.Transient)] - public class SysOperLogService: BaseService, ISysOperLogService + public class SysOperLogService : ISysOperLogService { public SysOperLogRepository sysOperLogRepository; diff --git a/ZR.Service/System/SysPostService.cs b/ZR.Service/System/SysPostService.cs index 39808a5..b32957c 100644 --- a/ZR.Service/System/SysPostService.cs +++ b/ZR.Service/System/SysPostService.cs @@ -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 /// 岗位管理 /// [AppService(ServiceType = typeof(ISysPostService), ServiceLifetime = LifeTime.Transient)] - public class SysPostService : BaseService, ISysPostService + public class SysPostService : BaseRepository, ISysPostService { + public SysPostRepository PostRepository; + public SysPostService(SysPostRepository postRepository) + { + PostRepository = postRepository; + } + /// /// 校验岗位编码是否唯一 /// @@ -20,7 +28,7 @@ namespace ZR.Service.System /// 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 /// 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; diff --git a/ZR.Service/System/SysRoleService.cs b/ZR.Service/System/SysRoleService.cs index c42b5fd..94b82f4 100644 --- a/ZR.Service/System/SysRoleService.cs +++ b/ZR.Service/System/SysRoleService.cs @@ -15,7 +15,7 @@ namespace ZR.Service /// 角色 ///
[AppService(ServiceType = typeof(ISysRoleService), ServiceLifetime = LifeTime.Transient)] - public class SysRoleService: BaseService, ISysRoleService + public class SysRoleService: ISysRoleService { private SysRoleRepository SysRoleRepository; private ISysUserRoleService SysUserRoleService; diff --git a/ZR.Service/System/SysTasksLogService.cs b/ZR.Service/System/SysTasksLogService.cs index 25f56e4..e4539c7 100644 --- a/ZR.Service/System/SysTasksLogService.cs +++ b/ZR.Service/System/SysTasksLogService.cs @@ -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, ISysTasksLogService + public class SysTasksLogService : BaseRepository, 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; } } diff --git a/ZR.Service/System/SysTasksQzService.cs b/ZR.Service/System/SysTasksQzService.cs index 1569287..9645e58 100644 --- a/ZR.Service/System/SysTasksQzService.cs +++ b/ZR.Service/System/SysTasksQzService.cs @@ -5,7 +5,7 @@ using ZR.Service.System.IService; namespace ZR.Service.System { [AppService(ServiceType = typeof(ISysTasksQzService), ServiceLifetime = LifeTime.Transient)] - public class SysTasksQzService : BaseService, ISysTasksQzService + public class SysTasksQzService : ISysTasksQzService { } diff --git a/ZR.Service/System/SysUserPostService.cs b/ZR.Service/System/SysUserPostService.cs index c312d31..78c4fa4 100644 --- a/ZR.Service/System/SysUserPostService.cs +++ b/ZR.Service/System/SysUserPostService.cs @@ -13,10 +13,9 @@ namespace ZR.Service.System /// 用户岗位 ///
[AppService(ServiceType = typeof(ISysUserPostService), ServiceLifetime = LifeTime.Transient)] - public class SysUserPostService : BaseService, 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 /// public List 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 ; + } } } diff --git a/ZR.Service/System/SysUserService.cs b/ZR.Service/System/SysUserService.cs index 23b972e..919d494 100644 --- a/ZR.Service/System/SysUserService.cs +++ b/ZR.Service/System/SysUserService.cs @@ -11,7 +11,7 @@ using ZR.Service.System.IService; namespace ZR.Service { [AppService(ServiceType = typeof(ISysUserService), ServiceLifetime = LifeTime.Transient)] - public class SysUserService : BaseService, 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); From 56a04bbf739a96c34fde333fc9c9d2e8bf399fb1 Mon Sep 17 00:00:00 2001 From: izory <791736813@qq.com> Date: Mon, 27 Sep 2021 16:07:55 +0800 Subject: [PATCH 02/21] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E3=80=81=E4=BB=93=E5=82=A8=E5=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ZR.Admin.WebApi/Controllers/BaseController.cs | 8 +- .../Controllers/CodeGeneratorController.cs | 2 +- .../Controllers/System/ArticleController.cs | 2 +- .../Controllers/System/SysDeptController.cs | 18 +- .../System/SysDictTypeController.cs | 6 +- .../Controllers/System/SysLoginController.cs | 2 +- .../Controllers/System/SysMenuController.cs | 24 +- .../Controllers/System/SysPostController.cs | 11 +- .../System/SysProfileController.cs | 8 +- .../Controllers/System/SysRoleController.cs | 18 +- .../Controllers/System/SysUserController.cs | 22 +- .../Controllers/System/TasksController.cs | 10 +- .../Controllers/System/TasksLogController.cs | 2 +- .../System/monitor/SysLogininforController.cs | 2 +- .../System/monitor/SysOperlogController.cs | 2 +- .../Controllers/UploadController.cs | 2 +- .../Controllers/business/GendemoController.cs | 2 +- ZR.Admin.WebApi/Extensions/TasksExtension.cs | 2 +- .../CodeGenTemplate/ControllersTemplate.txt | 2 +- ZR.Repository/BaseRepository.cs | 149 ++++-- ZR.Repository/DbProvider/SugarDbContext.cs | 50 -- ZR.Repository/IBaseRepository.cs | 31 +- .../Interceptor/SqlLogInterceptorAttribute.cs | 16 - ZR.Repository/System/BaseRepository.cs | 21 - ZR.Repository/System/GenTableRepository.cs | 6 +- ZR.Repository/System/SysDictDataRepository.cs | 5 +- ZR.Repository/System/SysPostRepository.cs | 4 +- ZR.Service/BaseService.cs | 504 ++++++++---------- ZR.Service/Extensions/QueryableExtension.cs | 30 -- ZR.Service/IBaseService.cs | 313 +++++------ ZR.Service/System/ArticleCategoryService.cs | 2 +- ZR.Service/System/ArticleService.cs | 2 +- ZR.Service/System/GenTableService.cs | 6 +- .../IService/IArticleCategoryService.cs | 2 +- ZR.Service/System/IService/IArticleService.cs | 2 +- ZR.Service/System/IService/ISysDeptService.cs | 18 +- ZR.Service/System/IService/ISysDictService.cs | 9 +- ZR.Service/System/IService/ISysPostService.cs | 2 +- .../System/IService/ISysTasksLogService.cs | 2 +- .../System/IService/ISysTasksQzService.cs | 4 +- ZR.Service/System/SysDeptService.cs | 18 +- ZR.Service/System/SysDictDataService.cs | 2 +- ZR.Service/System/SysDictService.cs | 14 +- ZR.Service/System/SysPostService.cs | 2 +- ZR.Service/System/SysTasksLogService.cs | 2 +- ZR.Service/System/SysTasksQzService.cs | 2 +- ZR.Vue/src/views/system/dept/index.vue | 1 + ZRAdmin.xml | 2 +- 48 files changed, 621 insertions(+), 745 deletions(-) delete mode 100644 ZR.Repository/DbProvider/SugarDbContext.cs delete mode 100644 ZR.Repository/Interceptor/SqlLogInterceptorAttribute.cs delete mode 100644 ZR.Repository/System/BaseRepository.cs diff --git a/ZR.Admin.WebApi/Controllers/BaseController.cs b/ZR.Admin.WebApi/Controllers/BaseController.cs index 119d7c4..5a318df 100644 --- a/ZR.Admin.WebApi/Controllers/BaseController.cs +++ b/ZR.Admin.WebApi/Controllers/BaseController.cs @@ -22,7 +22,7 @@ namespace ZR.Admin.WebApi.Controllers return Content(jsonStr, "application/json"); } - protected IActionResult ToRespose(ResultCode resultCode, object data = null) + protected IActionResult ToResponse(ResultCode resultCode, object data = null) { string jsonStr = GetJsonStr(GetApiResult(resultCode, data), ""); return Content(jsonStr, "application/json"); @@ -34,13 +34,13 @@ namespace ZR.Admin.WebApi.Controllers /// /// /// - protected IActionResult OutputJson(ApiResult apiResult, string timeFormatStr = "yyyy-MM-dd HH:mm:ss") + protected IActionResult ToResponse(ApiResult apiResult, string timeFormatStr = "yyyy-MM-dd HH:mm:ss") { string jsonStr = GetJsonStr(apiResult, timeFormatStr); return Content(jsonStr, "application/json"); } - protected IActionResult OutputJson(long rows, string timeFormatStr = "yyyy-MM-dd HH:mm:ss") + protected IActionResult ToResponse(long rows, string timeFormatStr = "yyyy-MM-dd HH:mm:ss") { string jsonStr = GetJsonStr(ToJson(rows), timeFormatStr); @@ -97,7 +97,7 @@ namespace ZR.Admin.WebApi.Controllers protected IActionResult CustomError(ResultCode resultCode, string msg = "") { - return OutputJson(GetApiResult(resultCode, msg)); + return ToResponse(GetApiResult(resultCode, msg)); } } } diff --git a/ZR.Admin.WebApi/Controllers/CodeGeneratorController.cs b/ZR.Admin.WebApi/Controllers/CodeGeneratorController.cs index d6a4f55..df5887c 100644 --- a/ZR.Admin.WebApi/Controllers/CodeGeneratorController.cs +++ b/ZR.Admin.WebApi/Controllers/CodeGeneratorController.cs @@ -196,7 +196,7 @@ namespace ZR.Admin.WebApi.Controllers } } - return ToRespose(ResultCode.FAIL); + return ToResponse(ResultCode.FAIL); } /// diff --git a/ZR.Admin.WebApi/Controllers/System/ArticleController.cs b/ZR.Admin.WebApi/Controllers/System/ArticleController.cs index e175c26..0466f31 100644 --- a/ZR.Admin.WebApi/Controllers/System/ArticleController.cs +++ b/ZR.Admin.WebApi/Controllers/System/ArticleController.cs @@ -147,7 +147,7 @@ namespace ZR.Admin.WebApi.Controllers { if (id <= 0) { - return OutputJson(ApiResult.Error($"删除失败Id 不能为空")); + return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); } // 删除文章 diff --git a/ZR.Admin.WebApi/Controllers/System/SysDeptController.cs b/ZR.Admin.WebApi/Controllers/System/SysDeptController.cs index dc99ec2..29f1fc8 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysDeptController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysDeptController.cs @@ -97,10 +97,10 @@ namespace ZR.Admin.WebApi.Controllers.System { if (UserConstants.NOT_UNIQUE.Equals(DeptService.CheckDeptNameUnique(dept))) { - return OutputJson(GetApiResult(ResultCode.CUSTOM_ERROR, $"新增部门{dept.DeptName}失败,部门名称已存在")); + return ToResponse(GetApiResult(ResultCode.CUSTOM_ERROR, $"新增部门{dept.DeptName}失败,部门名称已存在")); } dept.Create_by = User.Identity.Name; - return OutputJson(ToJson(DeptService.InsertDept(dept))); + return ToResponse(ToJson(DeptService.InsertDept(dept))); } /// @@ -115,14 +115,14 @@ namespace ZR.Admin.WebApi.Controllers.System { if (UserConstants.NOT_UNIQUE.Equals(DeptService.CheckDeptNameUnique(dept))) { - return OutputJson(GetApiResult(ResultCode.CUSTOM_ERROR, $"修改部门{dept.DeptName}失败,部门名称已存在")); + return ToResponse(GetApiResult(ResultCode.CUSTOM_ERROR, $"修改部门{dept.DeptName}失败,部门名称已存在")); } else if (dept.ParentId.Equals(dept.DeptId)) { - return OutputJson(GetApiResult(ResultCode.CUSTOM_ERROR, $"修改部门{dept.DeptName}失败,上级部门不能是自己")); + return ToResponse(GetApiResult(ResultCode.CUSTOM_ERROR, $"修改部门{dept.DeptName}失败,上级部门不能是自己")); } dept.Update_by = User.Identity.Name; - return OutputJson(ToJson(DeptService.UpdateDept(dept))); + return ToResponse(ToJson(DeptService.UpdateDept(dept))); } /// @@ -134,13 +134,13 @@ namespace ZR.Admin.WebApi.Controllers.System [Log(Title = "部门管理", BusinessType = BusinessType.DELETE)] public IActionResult Remove(long deptId) { - if (DeptService.GetCount(it => it.ParentId == deptId && it.DelFlag == "0") > 0) + if (DeptService.Queryable().Count(it => it.ParentId == deptId && it.DelFlag == "0") > 0) { - return OutputJson(GetApiResult(ResultCode.CUSTOM_ERROR, $"存在下级部门,不允许删除")); + return ToResponse(GetApiResult(ResultCode.CUSTOM_ERROR, $"存在下级部门,不允许删除")); } - if (UserService.GetCount(it => it.DeptId == deptId && it.DelFlag == "0") > 0) + if (DeptService.Queryable().Count(it => it.DeptId == deptId && it.DelFlag == "0") > 0) { - return OutputJson(GetApiResult(ResultCode.CUSTOM_ERROR, $"部门存在用户,不允许删除")); + return ToResponse(GetApiResult(ResultCode.CUSTOM_ERROR, $"部门存在用户,不允许删除")); } return SUCCESS(DeptService.Delete(deptId)); diff --git a/ZR.Admin.WebApi/Controllers/System/SysDictTypeController.cs b/ZR.Admin.WebApi/Controllers/System/SysDictTypeController.cs index 776901d..cee2abf 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysDictTypeController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysDictTypeController.cs @@ -51,7 +51,7 @@ namespace ZR.Admin.WebApi.Controllers.System [ActionPermissionFilter(Permission = "system:dict:query")] public IActionResult GetInfo(long dictId = 0) { - return SUCCESS(SysDictService(f => f.DictId == dictId)); + return SUCCESS(SysDictService.GetInfo(dictId)); } /// @@ -66,7 +66,7 @@ namespace ZR.Admin.WebApi.Controllers.System { if (UserConstants.NOT_UNIQUE.Equals(SysDictService.CheckDictTypeUnique(dict))) { - return OutputJson(ApiResult.Error($"新增字典'{dict.DictName}'失败,字典类型已存在")); + return ToResponse(ApiResult.Error($"新增字典'{dict.DictName}'失败,字典类型已存在")); } //设置添加人 dict.Create_by = HttpContext.User.Identity.Name; @@ -87,7 +87,7 @@ namespace ZR.Admin.WebApi.Controllers.System { if (UserConstants.NOT_UNIQUE.Equals(SysDictService.CheckDictTypeUnique(dict))) { - return OutputJson(ApiResult.Error($"修改字典'{dict.DictName}'失败,字典类型已存在")); + return ToResponse(ApiResult.Error($"修改字典'{dict.DictName}'失败,字典类型已存在")); } //设置添加人 dict.Update_by = HttpContext.User.Identity.Name; diff --git a/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs b/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs index 08afac8..93af7f7 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs @@ -125,7 +125,7 @@ namespace ZR.Admin.WebApi.Controllers.System long uid = HttpContext.GetUId(); var menus = sysMenuService.SelectMenuTreeByUserId(uid); - return OutputJson(ToJson(1, sysMenuService.BuildMenus(menus))); + return ToResponse(ToJson(1, sysMenuService.BuildMenus(menus))); } /// diff --git a/ZR.Admin.WebApi/Controllers/System/SysMenuController.cs b/ZR.Admin.WebApi/Controllers/System/SysMenuController.cs index aa05eaf..a6a4c29 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysMenuController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysMenuController.cs @@ -94,23 +94,23 @@ namespace ZR.Admin.WebApi.Controllers.System [ActionPermissionFilter(Permission = "system:menu:edit")] public IActionResult MenuEdit([FromBody] SysMenu MenuDto) { - if (MenuDto == null) { return OutputJson(ApiResult.Error(101, "请求参数错误")); } + if (MenuDto == null) { return ToResponse(ApiResult.Error(101, "请求参数错误")); } //if (UserConstants.NOT_UNIQUE.Equals(sysMenuService.CheckMenuNameUnique(MenuDto))) //{ - // return OutputJson(ApiResult.Error($"修改菜单'{MenuDto.menuName}'失败,菜单名称已存在")); + // return ToResponse(ApiResult.Error($"修改菜单'{MenuDto.menuName}'失败,菜单名称已存在")); //} if (UserConstants.YES_FRAME.Equals(MenuDto.isFrame) && !MenuDto.path.StartsWith("http")) { - return OutputJson(ApiResult.Error($"修改菜单'{MenuDto.menuName}'失败,地址必须以http(s)://开头")); + return ToResponse(ApiResult.Error($"修改菜单'{MenuDto.menuName}'失败,地址必须以http(s)://开头")); } if (MenuDto.menuId.Equals(MenuDto.parentId)) { - return OutputJson(ApiResult.Error($"修改菜单'{MenuDto.menuName}'失败,上级菜单不能选择自己")); + return ToResponse(ApiResult.Error($"修改菜单'{MenuDto.menuName}'失败,上级菜单不能选择自己")); } MenuDto.Update_by = User.Identity.Name; int result = sysMenuService.EditMenu(MenuDto); - return OutputJson(result); + return ToResponse(result); } /// @@ -123,20 +123,20 @@ namespace ZR.Admin.WebApi.Controllers.System [ActionPermissionFilter(Permission = "system:menu:add")] public IActionResult MenuAdd([FromBody] SysMenu MenuDto) { - if (MenuDto == null) { return OutputJson(ApiResult.Error(101, "请求参数错误")); } + if (MenuDto == null) { return ToResponse(ApiResult.Error(101, "请求参数错误")); } if (UserConstants.NOT_UNIQUE.Equals(sysMenuService.CheckMenuNameUnique(MenuDto))) { - return OutputJson(ApiResult.Error($"新增菜单'{MenuDto.menuName}'失败,菜单名称已存在")); + return ToResponse(ApiResult.Error($"新增菜单'{MenuDto.menuName}'失败,菜单名称已存在")); } if (UserConstants.YES_FRAME.Equals(MenuDto.isFrame) && !MenuDto.path.StartsWith("http")) { - return OutputJson(ApiResult.Error($"新增菜单'{MenuDto.menuName}'失败,地址必须以http(s)://开头")); + return ToResponse(ApiResult.Error($"新增菜单'{MenuDto.menuName}'失败,地址必须以http(s)://开头")); } MenuDto.Create_by = User.Identity.Name; int result = sysMenuService.AddMenu(MenuDto); - return OutputJson(result); + return ToResponse(result); } /// @@ -159,7 +159,7 @@ namespace ZR.Admin.WebApi.Controllers.System } int result = sysMenuService.DeleteMenuById(menuId); - return OutputJson(result); + return ToResponse(result); } /// @@ -172,10 +172,10 @@ namespace ZR.Admin.WebApi.Controllers.System [Log(Title = "保存排序", BusinessType = BusinessType.UPDATE)] public IActionResult ChangeSort([FromBody] MenuDto MenuDto) { - if (MenuDto == null) { return OutputJson(ApiResult.Error(101, "请求参数错误")); } + if (MenuDto == null) { return ToResponse(ApiResult.Error(101, "请求参数错误")); } int result = sysMenuService.ChangeSortMenu(MenuDto); - return OutputJson(result); + return ToResponse(result); } } } diff --git a/ZR.Admin.WebApi/Controllers/System/SysPostController.cs b/ZR.Admin.WebApi/Controllers/System/SysPostController.cs index ef3da92..b573aef 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysPostController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysPostController.cs @@ -36,7 +36,7 @@ namespace ZR.Admin.WebApi.Controllers.System //开始拼装查询条件 var predicate = Expressionable.Create(); predicate = predicate.AndIF(post.Status.IfNotEmpty(), it => it.Status == post.Status); - var list = PostService.GetPages(predicate.ToExpression(), pagerInfo); + var list = PostService.GetPages(predicate.ToExpression(), pagerInfo, s => new { s.PostSort }); return SUCCESS(list); } @@ -71,8 +71,9 @@ namespace ZR.Admin.WebApi.Controllers.System { throw new CustomException($"修改岗位{post.PostName}失败,岗位编码已存在"); } - post.Update_by = User.Identity.Name; - return OutputJson(ToJson(PostService.Add(post))); + + post.Create_by = User.Identity.Name; + return ToResponse(ToJson(PostService.Add(post))); } /// @@ -94,7 +95,7 @@ namespace ZR.Admin.WebApi.Controllers.System throw new CustomException($"修改岗位{post.PostName}失败,岗位编码已存在"); } post.Update_by = User.Identity.Name; - return OutputJson(ToJson(PostService.Update(post))); + return ToResponse(ToJson(PostService.Update(post) ? 1 : 0)); } /// @@ -107,7 +108,7 @@ namespace ZR.Admin.WebApi.Controllers.System [Log(Title = "岗位删除", BusinessType = BusinessType.DELETE)] public IActionResult Delete(int id = 0) { - return OutputJson(ToJson(PostService.Delete(id))); + return ToResponse(ToJson(PostService.Delete(id))); } /// diff --git a/ZR.Admin.WebApi/Controllers/System/SysProfileController.cs b/ZR.Admin.WebApi/Controllers/System/SysProfileController.cs index 29890f1..2ef8337 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysProfileController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysProfileController.cs @@ -84,7 +84,7 @@ namespace ZR.Admin.WebApi.Controllers.System user.Update_time = DateTime.Now; int result = UserService.ChangeUser(user); - return OutputJson(result); + return ToResponse(result); } /// @@ -103,11 +103,11 @@ namespace ZR.Admin.WebApi.Controllers.System string newMd5 = NETCore.Encrypt.EncryptProvider.Md5(newPassword); if (user.Password != oldMd5) { - return OutputJson(ApiResult.Error("修改密码失败,旧密码错误")); + return ToResponse(ApiResult.Error("修改密码失败,旧密码错误")); } if (user.Password == newMd5) { - return OutputJson(ApiResult.Error("新密码不能和旧密码相同")); + return ToResponse(ApiResult.Error("新密码不能和旧密码相同")); } if (UserService.ResetPwd(loginUser.UserId, newMd5) > 0) { @@ -116,7 +116,7 @@ namespace ZR.Admin.WebApi.Controllers.System return SUCCESS(1); } - return OutputJson(ApiResult.Error("修改密码异常,请联系管理员")); + return ToResponse(ApiResult.Error("修改密码异常,请联系管理员")); } /// diff --git a/ZR.Admin.WebApi/Controllers/System/SysRoleController.cs b/ZR.Admin.WebApi/Controllers/System/SysRoleController.cs index 7fa72fc..73a12fb 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysRoleController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysRoleController.cs @@ -69,17 +69,17 @@ namespace ZR.Admin.WebApi.Controllers.System [Route("edit")] public IActionResult RoleAdd([FromBody] SysRole sysRoleDto) { - if (sysRoleDto == null) return OutputJson(ApiResult.Error(101, "请求参数错误")); + if (sysRoleDto == null) return ToResponse(ApiResult.Error(101, "请求参数错误")); if (UserConstants.NOT_UNIQUE.Equals(sysRoleService.CheckRoleKeyUnique(sysRoleDto))) { - return OutputJson(ApiResult.Error((int)ResultCode.CUSTOM_ERROR, $"新增角色'{sysRoleDto.RoleName}'失败,角色权限已存在")); + return ToResponse(ApiResult.Error((int)ResultCode.CUSTOM_ERROR, $"新增角色'{sysRoleDto.RoleName}'失败,角色权限已存在")); } sysRoleDto.Create_by = User.Identity.Name; long roleId = sysRoleService.InsertRole(sysRoleDto); - return OutputJson(ToJson(roleId)); + return ToResponse(ToJson(roleId)); } /// @@ -95,7 +95,7 @@ namespace ZR.Admin.WebApi.Controllers.System { if (sysRoleDto == null || sysRoleDto.RoleId <= 0 || string.IsNullOrEmpty(sysRoleDto.RoleKey)) { - return OutputJson(ApiResult.Error(101, "请求参数错误")); + return ToResponse(ApiResult.Error(101, "请求参数错误")); } sysRoleService.CheckRoleAllowed(sysRoleDto); var info = sysRoleService.SelectRoleById(sysRoleDto.RoleId); @@ -103,7 +103,7 @@ namespace ZR.Admin.WebApi.Controllers.System { if (UserConstants.NOT_UNIQUE.Equals(sysRoleService.CheckRoleKeyUnique(sysRoleDto))) { - return OutputJson(ApiResult.Error($"编辑角色'{sysRoleDto.RoleName}'失败,角色权限已存在")); + return ToResponse(ApiResult.Error($"编辑角色'{sysRoleDto.RoleName}'失败,角色权限已存在")); } } @@ -115,7 +115,7 @@ namespace ZR.Admin.WebApi.Controllers.System return SUCCESS(upResult); } - return OutputJson(ApiResult.Error($"修改角色'{sysRoleDto.RoleName}'失败,请联系管理员")); + return ToResponse(ApiResult.Error($"修改角色'{sysRoleDto.RoleName}'失败,请联系管理员")); } /// @@ -128,7 +128,7 @@ namespace ZR.Admin.WebApi.Controllers.System [Log(Title = "角色管理", BusinessType = BusinessType.UPDATE)] public IActionResult DataScope([FromBody] SysRole sysRoleDto) { - if (sysRoleDto == null || sysRoleDto.RoleId <= 0) return OutputJson(ApiResult.Error(101, "请求参数错误")); + if (sysRoleDto == null || sysRoleDto.RoleId <= 0) return ToResponse(ApiResult.Error(101, "请求参数错误")); sysRoleDto.Create_by = HttpContextExtension.GetName(HttpContext); //删除角色菜单 @@ -151,7 +151,7 @@ namespace ZR.Admin.WebApi.Controllers.System long[] roleIds = Tools.SpitLongArrary(roleId); int result = sysRoleService.DeleteRoleByRoleId(roleIds); - return OutputJson(ToJson(result)); + return ToResponse(ToJson(result)); } /// @@ -166,7 +166,7 @@ namespace ZR.Admin.WebApi.Controllers.System { int result = sysRoleService.UpdateRoleStatus(roleDto); - return OutputJson(ToJson(result)); + return ToResponse(ToJson(result)); } } } diff --git a/ZR.Admin.WebApi/Controllers/System/SysUserController.cs b/ZR.Admin.WebApi/Controllers/System/SysUserController.cs index e309a41..91f1566 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysUserController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysUserController.cs @@ -75,7 +75,7 @@ namespace ZR.Admin.WebApi.Controllers.System dic.Add("roleIds", RoleService.SelectUserRoles(userId)); } - return OutputJson(ApiResult.Success(dic)); + return ToResponse(ApiResult.Success(dic)); } /// @@ -88,16 +88,16 @@ namespace ZR.Admin.WebApi.Controllers.System [ActionPermissionFilter(Permission = "system:user:add")] public IActionResult AddUser([FromBody] SysUser user) { - if (user == null) { return OutputJson(ApiResult.Error(101, "请求参数错误")); } + if (user == null) { return ToResponse(ApiResult.Error(101, "请求参数错误")); } if (UserConstants.NOT_UNIQUE.Equals(UserService.CheckUserNameUnique(user.UserName))) { - return OutputJson(ApiResult.Error($"新增用户 '{user.UserName}'失败,登录账号已存在")); + return ToResponse(ApiResult.Error($"新增用户 '{user.UserName}'失败,登录账号已存在")); } user.Create_by = User.Identity.Name; user.Password = NETCore.Encrypt.EncryptProvider.Md5(user.Password); - return OutputJson(UserService.InsertUser(user)); + return ToResponse(UserService.InsertUser(user)); } /// @@ -110,12 +110,12 @@ namespace ZR.Admin.WebApi.Controllers.System [ActionPermissionFilter(Permission = "system:user:edit")] public IActionResult UpdateUser([FromBody] SysUser user) { - if (user == null || user.UserId <= 0) { return OutputJson(ApiResult.Error(101, "请求参数错误")); } + if (user == null || user.UserId <= 0) { return ToResponse(ApiResult.Error(101, "请求参数错误")); } user.Update_by = User.Identity.Name; int upResult = UserService.UpdateUser(user); - return OutputJson(upResult); + return ToResponse(upResult); } /// @@ -128,10 +128,10 @@ namespace ZR.Admin.WebApi.Controllers.System [ActionPermissionFilter(Permission = "system:user:update")] public IActionResult ChangeStatus([FromBody] SysUser user) { - if (user == null) { return OutputJson(ApiResult.Error(101, "请求参数错误")); } + if (user == null) { return ToResponse(ApiResult.Error(101, "请求参数错误")); } int result = UserService.ChangeUserStatus(user); - return OutputJson(ToJson(result)); + return ToResponse(ToJson(result)); } /// @@ -144,11 +144,11 @@ namespace ZR.Admin.WebApi.Controllers.System [ActionPermissionFilter(Permission = "system:user:remove")] public IActionResult Remove(int userid = 0) { - if (userid <= 0) { return OutputJson(ApiResult.Error(101, "请求参数错误")); } + if (userid <= 0) { return ToResponse(ApiResult.Error(101, "请求参数错误")); } int result = UserService.DeleteUser(userid); - return OutputJson(ToJson(result)); + return ToResponse(ToJson(result)); } /// @@ -164,7 +164,7 @@ namespace ZR.Admin.WebApi.Controllers.System sysUser.Password = NETCore.Encrypt.EncryptProvider.Md5(sysUser.Password); int result = UserService.ResetPwd(sysUser.UserId, sysUser.Password); - return OutputJson(ToJson(result)); + return ToResponse(ToJson(result)); } /// diff --git a/ZR.Admin.WebApi/Controllers/System/TasksController.cs b/ZR.Admin.WebApi/Controllers/System/TasksController.cs index 541ad29..0968dfb 100644 --- a/ZR.Admin.WebApi/Controllers/System/TasksController.cs +++ b/ZR.Admin.WebApi/Controllers/System/TasksController.cs @@ -142,7 +142,7 @@ namespace ZR.Admin.WebApi.Controllers Update_by = User.Identity.Name, Update_time = DateTime.Now }); - if (response > 0) + if (response) { //先暂停原先的任务 var respon = await _schedulerServer.UpdateTaskScheduleAsync(tasksQz, tasksQz.JobGroup); @@ -177,7 +177,7 @@ namespace ZR.Admin.WebApi.Controllers { _tasksQzService.Delete(id); } - return OutputJson(taskResult); + return ToResponse(taskResult); } /// @@ -208,7 +208,7 @@ namespace ZR.Admin.WebApi.Controllers _tasksQzService.Update(tasksQz); } - return OutputJson(taskResult); + return ToResponse(taskResult); } /// @@ -239,7 +239,7 @@ namespace ZR.Admin.WebApi.Controllers _tasksQzService.Update(tasksQz); } - return OutputJson(taskResult); + return ToResponse(taskResult); } /// @@ -264,7 +264,7 @@ namespace ZR.Admin.WebApi.Controllers //_tasksQzService.Update(tasksQz); } - return OutputJson(taskResult); + return ToResponse(taskResult); } } } diff --git a/ZR.Admin.WebApi/Controllers/System/TasksLogController.cs b/ZR.Admin.WebApi/Controllers/System/TasksLogController.cs index 432aad4..916d052 100644 --- a/ZR.Admin.WebApi/Controllers/System/TasksLogController.cs +++ b/ZR.Admin.WebApi/Controllers/System/TasksLogController.cs @@ -61,7 +61,7 @@ namespace ZR.Admin.WebApi.Controllers.System int result = tasksLogService.Delete(jobIdArr); - return OutputJson(ToJson(result, result)); + return ToResponse(ToJson(result, result)); } /// diff --git a/ZR.Admin.WebApi/Controllers/System/monitor/SysLogininforController.cs b/ZR.Admin.WebApi/Controllers/System/monitor/SysLogininforController.cs index 686be34..a60033d 100644 --- a/ZR.Admin.WebApi/Controllers/System/monitor/SysLogininforController.cs +++ b/ZR.Admin.WebApi/Controllers/System/monitor/SysLogininforController.cs @@ -36,7 +36,7 @@ namespace ZR.Admin.WebApi.Controllers.monitor var list = sysLoginService.GetLoginLog(sysLogininfoDto, pagerInfo); var vMPage = new VMPageResult(list, pagerInfo); - return OutputJson(ToJson(vMPage.TotalNum, vMPage), TIME_FORMAT_FULL_2); + return ToResponse(ToJson(vMPage.TotalNum, vMPage), TIME_FORMAT_FULL_2); } /// diff --git a/ZR.Admin.WebApi/Controllers/System/monitor/SysOperlogController.cs b/ZR.Admin.WebApi/Controllers/System/monitor/SysOperlogController.cs index e2774b2..437aaa4 100644 --- a/ZR.Admin.WebApi/Controllers/System/monitor/SysOperlogController.cs +++ b/ZR.Admin.WebApi/Controllers/System/monitor/SysOperlogController.cs @@ -36,7 +36,7 @@ namespace ZR.Admin.WebApi.Controllers.monitor var list = sysOperLogService.SelectOperLogList(sysOperLog, pagerInfo); var vMPage = new VMPageResult(list, pagerInfo); - return OutputJson(ToJson(vMPage.TotalNum, vMPage), TIME_FORMAT_FULL_2); + return ToResponse(ToJson(vMPage.TotalNum, vMPage), TIME_FORMAT_FULL_2); } /// diff --git a/ZR.Admin.WebApi/Controllers/UploadController.cs b/ZR.Admin.WebApi/Controllers/UploadController.cs index c05fca5..07855f7 100644 --- a/ZR.Admin.WebApi/Controllers/UploadController.cs +++ b/ZR.Admin.WebApi/Controllers/UploadController.cs @@ -43,7 +43,7 @@ namespace ZR.Admin.WebApi.Controllers } string accessPath = $"{OptionsSetting.Upload.UploadUrl}/{finalFilePath.Replace("wwwroot", "").Replace("\\", "/")}"; - return OutputJson(ToJson(1, accessPath)); + return ToResponse(ToJson(1, accessPath)); } } } diff --git a/ZR.Admin.WebApi/Controllers/business/GendemoController.cs b/ZR.Admin.WebApi/Controllers/business/GendemoController.cs index 23f6e12..a167422 100644 --- a/ZR.Admin.WebApi/Controllers/business/GendemoController.cs +++ b/ZR.Admin.WebApi/Controllers/business/GendemoController.cs @@ -127,7 +127,7 @@ namespace ZR.Admin.WebApi.Controllers public IActionResult DeleteGendemo(string ids) { int[] idsArr = Tools.SpitIntArrary(ids); - if (idsArr.Length <= 0) { return OutputJson(ApiResult.Error($"删除失败Id 不能为空")); } + if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); } var response = _GendemoService.Delete(idsArr); diff --git a/ZR.Admin.WebApi/Extensions/TasksExtension.cs b/ZR.Admin.WebApi/Extensions/TasksExtension.cs index d125afa..72b8008 100644 --- a/ZR.Admin.WebApi/Extensions/TasksExtension.cs +++ b/ZR.Admin.WebApi/Extensions/TasksExtension.cs @@ -38,7 +38,7 @@ namespace ZR.Admin.WebApi.Extensions //var _tasksQzService2 = (ISysTasksQzService)services.GetRequiredService(typeof(SysTasksQzService)); ITaskSchedulerServer _schedulerServer = App.GetRequiredService(); - var tasks = _tasksQzService.GetWhere(m => m.IsStart); + var tasks = _tasksQzService.QueryableToList(m => m.IsStart); //程序启动后注册所有定时任务 foreach (var task in tasks) diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/ControllersTemplate.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/ControllersTemplate.txt index 24973ce..3a5d41c 100644 --- a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/ControllersTemplate.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/ControllersTemplate.txt @@ -127,7 +127,7 @@ namespace {ApiControllerNamespace}.Controllers public IActionResult Delete{ModelName}(string ids) { int[] idsArr = Tools.SpitIntArrary(ids); - if (idsArr.Length <= 0) { return OutputJson(ApiResult.Error($"删除失败Id 不能为空")); } + if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); } var response = _{ModelName}Service.Delete(idsArr); diff --git a/ZR.Repository/BaseRepository.cs b/ZR.Repository/BaseRepository.cs index 0a8a13b..a4d0fab 100644 --- a/ZR.Repository/BaseRepository.cs +++ b/ZR.Repository/BaseRepository.cs @@ -1,4 +1,5 @@ using Infrastructure; +using Infrastructure.Model; using SqlSugar; using System; using System.Collections.Generic; @@ -6,6 +7,7 @@ using System.Dynamic; using System.Linq; using System.Linq.Expressions; using System.Threading.Tasks; +using ZR.Model; namespace ZR.Repository { @@ -58,28 +60,41 @@ namespace ZR.Repository Console.WriteLine(); }; - base.Context = Db.GetConnection(configId);//根据类传入的ConfigId自动选择 + Context = Db.GetConnection(configId);//根据类传入的ConfigId自动选择 } } #region add + /// + /// 插入指定列使用 + /// + /// + /// + /// + /// public int Add(T parm, Expression> iClumns = null, bool ignoreNull = true) { - return base.Context.Insertable(parm).InsertColumns(iClumns).IgnoreColumns(ignoreNullColumn: ignoreNull).ExecuteCommand(); + return Context.Insertable(parm).InsertColumns(iClumns).IgnoreColumns(ignoreNullColumn: ignoreNull).ExecuteCommand(); } - public int Insert(T t, bool IgnoreNullColumn = true) + /// + /// 插入实体 + /// + /// + /// 默认忽略null列 + /// + public int Add(T t) { - return base.Context.Insertable(t).IgnoreColumns(IgnoreNullColumn).ExecuteCommand(); + return Context.Insertable(t).ExecuteCommand(); } public int InsertIgnoreNullColumn(T t) { - return base.Context.Insertable(t).IgnoreColumns(true).ExecuteCommand(); + return Context.Insertable(t).IgnoreColumns(true).ExecuteCommand(); } public int InsertIgnoreNullColumn(T t, params string[] columns) { - return base.Context.Insertable(t).IgnoreColumns(columns).ExecuteCommand(); + return Context.Insertable(t).IgnoreColumns(columns).ExecuteCommand(); } //public int Insert(SqlSugarClient client, T t) @@ -237,9 +252,9 @@ namespace ZR.Repository #region delete - public bool Delete(Expression> expression) + public bool DeleteExp(Expression> expression) { - return base.Context.Deleteable().Where(expression).ExecuteCommand() > 0; + return Context.Deleteable().Where(expression).ExecuteCommand() > 0; } //public bool Delete(PkType[] primaryKeyValues) @@ -247,47 +262,46 @@ namespace ZR.Repository // return base.Context.Deleteable().In(primaryKeyValues).ExecuteCommand() > 0; //} - public bool Delete(object[] obj) + public int Delete(object[] obj) { - return base.Context.Deleteable().In(obj).ExecuteCommand() > 0; + return Context.Deleteable().In(obj).ExecuteCommand(); } - public bool Delete(object id) + public int Delete(object id) { - return base.Context.Deleteable(id).ExecuteCommand() > 0; + return Context.Deleteable(id).ExecuteCommand(); } - public bool Delete() + public bool DeleteTable() { - return base.Context.Deleteable().ExecuteCommand() > 0; + return Context.Deleteable().ExecuteCommand() > 0; } #endregion delete #region query - public bool IsAny(Expression> expression) + public bool Any(Expression> expression) { - //base.Context.Queryable().Any(); - return base.Context.Queryable().Where(expression).Any(); + return Context.Queryable().Where(expression).Any(); } public ISugarQueryable Queryable() { - return base.Context.Queryable(); + return Context.Queryable(); } public ISugarQueryable Queryable(string tableName, string shortName) { - return base.Context.Queryable(tableName, shortName); + return Context.Queryable(tableName, shortName); } public List QueryableToList(Expression> expression) { - return base.Context.Queryable().Where(expression).ToList(); + return Context.Queryable().Where(expression).ToList(); } public Task> QueryableToListAsync(Expression> expression) { - return base.Context.Queryable().Where(expression).ToListAsync(); + return Context.Queryable().Where(expression).ToListAsync(); } //public string QueryableToJson(string select, Expression> expressionWhere) @@ -296,32 +310,27 @@ namespace ZR.Repository // return query.JilToJson(); //} - public T QueryableToEntity(Expression> expression) - { - return base.Context.Queryable().Where(expression).First(); - } - public List QueryableToList(string tableName) { - return base.Context.Queryable(tableName).ToList(); + return Context.Queryable(tableName).ToList(); } public List QueryableToList(string tableName, Expression> expression) { - return base.Context.Queryable(tableName).Where(expression).ToList(); + return Context.Queryable(tableName).Where(expression).ToList(); } public (List, int) QueryableToPage(Expression> expression, int pageIndex = 0, int pageSize = 10) { int totalNumber = 0; - var list = base.Context.Queryable().Where(expression).ToPageList(pageIndex, pageSize, ref totalNumber); + var list = Context.Queryable().Where(expression).ToPageList(pageIndex, pageSize, ref totalNumber); return (list, totalNumber); } public (List, int) QueryableToPage(Expression> expression, string order, int pageIndex = 0, int pageSize = 10) { int totalNumber = 0; - var list = base.Context.Queryable().Where(expression).OrderBy(order).ToPageList(pageIndex, pageSize, ref totalNumber); + var list = Context.Queryable().Where(expression).OrderBy(order).ToPageList(pageIndex, pageSize, ref totalNumber); return (list, totalNumber); } @@ -331,38 +340,19 @@ namespace ZR.Repository if (orderBy.Equals("DESC", StringComparison.OrdinalIgnoreCase)) { - var list = base.Context.Queryable().Where(expression).OrderBy(orderFiled, OrderByType.Desc).ToPageList(pageIndex, pageSize, ref totalNumber); + var list = Context.Queryable().Where(expression).OrderBy(orderFiled, OrderByType.Desc).ToPageList(pageIndex, pageSize, ref totalNumber); return (list, totalNumber); } else { - var list = base.Context.Queryable().Where(expression).OrderBy(orderFiled, OrderByType.Asc).ToPageList(pageIndex, pageSize, ref totalNumber); + var list = Context.Queryable().Where(expression).OrderBy(orderFiled, OrderByType.Asc).ToPageList(pageIndex, pageSize, ref totalNumber); return (list, totalNumber); } } - //public (List, int) QueryableToPage(Expression> 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().Where(expression).OrderBy(bootstrap.sort).ToPageList(bootstrap.offset, bootstrap.limit, ref totalNumber); - // return (list, totalNumber); - // } - // else - // { - // var list = base.Context.Queryable().Where(expression).OrderBy(bootstrap.sort).ToPageList(bootstrap.offset, bootstrap.limit, ref totalNumber); - // return (list, totalNumber); - // } - //} - public List SqlQueryToList(string sql, object obj = null) { - return base.Context.Ado.SqlQuery(sql, obj); + return Context.Ado.SqlQuery(sql, obj); } /// /// 获得一条数据 @@ -383,15 +373,32 @@ namespace ZR.Repository { return Context.Queryable().InSingle(pkValue); } - /// - /// 获得一条数据 + /// 根据条件查询分页数据 /// - /// string + /// + /// /// - public T GetFirst(string parm) + public PagedInfo GetPages(Expression> where, PagerInfo parm) { - return Context.Queryable().Where(parm).First(); + var source = Context.Queryable().Where(where); + + return source.ToPage(parm); + } + + public PagedInfo GetPages(Expression> where, PagerInfo parm, Expression> order, string orderEnum = "Asc") + { + var source = Context.Queryable().Where(where).OrderByIF(orderEnum == "Asc", order, OrderByType.Asc).OrderByIF(orderEnum == "Desc", order, OrderByType.Desc); + + return source.ToPage(parm); + } + /// + /// 查询所有数据(无分页,请慎用) + /// + /// + public List GetAll(bool useCache = false, int cacheSecond = 3600) + { + return Context.Queryable().WithCacheIF(useCache, cacheSecond).ToList(); } #endregion query @@ -423,9 +430,33 @@ namespace ZR.Repository // return result; //} - public string QueryableToJson(string select, Expression> expressionWhere) + //public string QueryableToJson(string select, Expression> expressionWhere) + //{ + // throw new NotImplementedException(); + //} + } + + public static class QueryableExtension + { + /// + /// 读取列表 + /// + /// + /// + /// + /// + public static PagedInfo ToPage(this ISugarQueryable source, PagerInfo parm) { - throw new NotImplementedException(); + var page = new PagedInfo(); + var total = source.Count(); + page.TotalCount = total; + page.PageSize = parm.PageSize; + page.PageIndex = parm.PageNum; + + //page.DataSource = source.OrderByIF(!string.IsNullOrEmpty(parm.Sort), $"{parm.OrderBy} {(parm.Sort == "descending" ? "desc" : "asc")}").ToPageList(parm.PageNum, parm.PageSize); + page.Result = source.ToPageList(parm.PageNum, parm.PageSize); + return page; } + } } diff --git a/ZR.Repository/DbProvider/SugarDbContext.cs b/ZR.Repository/DbProvider/SugarDbContext.cs deleted file mode 100644 index de5ff07..0000000 --- a/ZR.Repository/DbProvider/SugarDbContext.cs +++ /dev/null @@ -1,50 +0,0 @@ -using Infrastructure; -using SqlSugar; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace ZR.Repository.DbProvider -{ - /// - /// SqlSugar ORM - /// - public class SugarDbContext - { - public SqlSugarClient Db; //用来处理事务多表查询和复杂的操作 - - /// - /// 使用SugarSql获取连接对象 - /// - /// - public SugarDbContext() - { - string connStr = ConfigUtils.Instance.GetConnectionStrings(OptionsSetting.ConnAdmin); - int dbType = ConfigUtils.Instance.GetAppConfig(OptionsSetting.ConnDbType); - - Db = new SqlSugarClient(new List() - { - new ConnectionConfig(){ - ConnectionString = connStr, - DbType = (DbType)dbType, - IsAutoCloseConnection = true,//开启自动释放模式和EF原理一样 - InitKeyType = InitKeyType.Attribute,//从特性读取主键和自增列信息 - ConfigId = 0 - }, - }); - - ////调式代码 用来打印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(); - //}; - } - } -} diff --git a/ZR.Repository/IBaseRepository.cs b/ZR.Repository/IBaseRepository.cs index 545c46d..719eda4 100644 --- a/ZR.Repository/IBaseRepository.cs +++ b/ZR.Repository/IBaseRepository.cs @@ -1,4 +1,5 @@ -using SqlSugar; +using Infrastructure.Model; +using SqlSugar; using System; using System.Collections.Generic; using System.Data; @@ -7,6 +8,7 @@ using System.Linq; using System.Linq.Expressions; using System.Text; using System.Threading.Tasks; +using ZR.Model; namespace ZR.Repository { @@ -14,7 +16,7 @@ namespace ZR.Repository { #region add int Add(T parm, Expression> iClumns = null, bool ignoreNull = true); - int Insert(T t, bool IgnoreNullColumn = true); + int Add(T t); int InsertIgnoreNullColumn(T t); @@ -87,21 +89,30 @@ namespace ZR.Repository #region delete - bool Delete(Expression> expression); + bool DeleteExp(Expression> expression); //bool Delete(PkType[] primaryKeyValues); - - bool Delete(object[] obj); - bool Delete(object id); - bool Delete(); + int Delete(object[] obj); + int Delete(object id); + bool DeleteTable(); #endregion delete #region query + /// + /// 根据条件查询分页数据 + /// + /// + /// + /// + PagedInfo GetPages(Expression> where, PagerInfo parm); - bool IsAny(Expression> expression); + PagedInfo GetPages(Expression> where, PagerInfo parm, Expression> order, string orderEnum = "Asc"); + + bool Any(Expression> expression); ISugarQueryable Queryable(); + List GetAll(bool useCache = false, int cacheSecond = 3600); //ISugarQueryable Queryable(string tableName, string shortName); @@ -115,8 +126,6 @@ namespace ZR.Repository List QueryableToList(string tableName); - T QueryableToEntity(Expression> expression); - List QueryableToList(string tableName, Expression> expression); (List, int) QueryableToPage(Expression> expression, int pageIndex = 0, int pageSize = 10); @@ -141,7 +150,7 @@ namespace ZR.Repository /// /// string /// - T GetFirst(string parm); + //T GetFirst(string parm); #endregion query diff --git a/ZR.Repository/Interceptor/SqlLogInterceptorAttribute.cs b/ZR.Repository/Interceptor/SqlLogInterceptorAttribute.cs deleted file mode 100644 index fe569de..0000000 --- a/ZR.Repository/Interceptor/SqlLogInterceptorAttribute.cs +++ /dev/null @@ -1,16 +0,0 @@ -using AspectCore.DynamicProxy; -using System.Threading.Tasks; -using ZR.Repository.DbProvider; - -namespace ZR.Repository.Interceptor -{ - - public class SqlLogInterceptorAttribute : AbstractInterceptorAttribute - { - public override Task Invoke(AspectContext context, AspectDelegate next) - { - global::System.Console.WriteLine(""); - return next(context); - } - } -} diff --git a/ZR.Repository/System/BaseRepository.cs b/ZR.Repository/System/BaseRepository.cs deleted file mode 100644 index cd7a790..0000000 --- a/ZR.Repository/System/BaseRepository.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Infrastructure.Attribute; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using ZR.Repository.DbProvider; - -namespace ZR.Repository.System -{ - public class BaseRepository : SugarDbContext - { - protected void PrintLog() - { - //调式代码 用来打印SQL - Db.Aop.OnLogExecuting = (sql, pars) => - { - Console.WriteLine("【SQL语句】" + sql.ToLower() + "\r\n" + Db.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value))); - }; - } - } -} diff --git a/ZR.Repository/System/GenTableRepository.cs b/ZR.Repository/System/GenTableRepository.cs index 8207ead..0ce1970 100644 --- a/ZR.Repository/System/GenTableRepository.cs +++ b/ZR.Repository/System/GenTableRepository.cs @@ -1,4 +1,5 @@ -using System; +using Infrastructure.Attribute; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -7,11 +8,12 @@ using ZR.Model.System.Generate; namespace ZR.Repository.System { + [AppService(ServiceLifetime = LifeTime.Transient)] public class GenTableRepository : BaseRepository { } - + [AppService(ServiceLifetime = LifeTime.Transient)] public class GenTableColumnRepository : BaseRepository { /// diff --git a/ZR.Repository/System/SysDictDataRepository.cs b/ZR.Repository/System/SysDictDataRepository.cs index f9830cb..110bf55 100644 --- a/ZR.Repository/System/SysDictDataRepository.cs +++ b/ZR.Repository/System/SysDictDataRepository.cs @@ -44,8 +44,7 @@ namespace ZR.Repository.System /// public long InsertDictData(SysDictData dict) { - var result = Context.Insertable(dict).IgnoreColumns(it => new { dict.Update_by }) - .ExecuteReturnIdentity(); + var result = InsertReturnBigIdentity(dict); return result; } @@ -76,7 +75,7 @@ namespace ZR.Repository.System /// public int DeleteDictDataByIds(long[] dictCodes) { - return Context.Deleteable().In(dictCodes).ExecuteCommand(); + return Delete(dictCodes); } /// diff --git a/ZR.Repository/System/SysPostRepository.cs b/ZR.Repository/System/SysPostRepository.cs index bd31ba6..cc12aa0 100644 --- a/ZR.Repository/System/SysPostRepository.cs +++ b/ZR.Repository/System/SysPostRepository.cs @@ -1,4 +1,5 @@ -using System; +using Infrastructure.Attribute; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -7,6 +8,7 @@ using ZR.Model.System; namespace ZR.Repository.System { + [AppService(ServiceLifetime = LifeTime.Transient)] public class SysPostRepository : BaseRepository { } diff --git a/ZR.Service/BaseService.cs b/ZR.Service/BaseService.cs index e9f4097..9f79143 100644 --- a/ZR.Service/BaseService.cs +++ b/ZR.Service/BaseService.cs @@ -1,12 +1,4 @@ -using Infrastructure.Attribute; -using Infrastructure.Model; -using SqlSugar; -using System; -using System.Collections.Generic; -using System.Linq.Expressions; -using ZR.Model; -using ZR.Repository; -using ZR.Repository.DbProvider; +using ZR.Repository; namespace ZR.Service { @@ -14,318 +6,284 @@ namespace ZR.Service /// 基础服务定义 /// /// - public class BaseService : BaseRepository where T : class,new()//, IBaseService where T : class, new() + public class BaseService : BaseRepository, IBaseService where T : class, new() { - //private readonly IBaseRepository BaseRepository; - //public BaseService(IBaseRepository baseRepository) - //{ - // BaseRepository = baseRepository; - //} - - #region 事务 - + //#region 添加操作 ///// - ///// 启用事务 + ///// 添加一条数据 ///// - //public void BeginTran() + ///// T + ///// + //public int Add(T parm) //{ - // Context.Ado.BeginTran(); + // return Add(parm);// Context.Insertable(parm).RemoveDataCache().ExecuteCommand(); //} ///// - ///// 提交事务 + ///// 添加 ///// - //public void CommitTran() - //{ - // Context.Ado.CommitTran(); - //} - - ///// - ///// 回滚事务 - ///// - //public void RollbackTran() - //{ - // Context.Ado.RollbackTran(); - //} - - #endregion - - #region 添加操作 - /// - /// 添加一条数据 - /// - /// T - /// - public int Add(T parm) - { - return base.Add(parm);// Context.Insertable(parm).RemoveDataCache().ExecuteCommand(); - } - - /// - /// 添加 - /// - /// - /// 插入列 - /// 忽略null列 - /// + ///// + ///// 插入列 + ///// 忽略null列 + ///// //public int Add(T parm, Expression> iClumns = null, bool ignoreNull = true) //{ // return Add(parm); //} - /// - /// 批量添加数据 - /// - /// List - /// - public int Add(List parm) - { - return Context.Insertable(parm).RemoveDataCache().ExecuteCommand(); - } + ///// + ///// 批量添加数据 + ///// + ///// List + ///// + //public int Add(List parm) + //{ + // return 1;// Context.Insertable(parm).RemoveDataCache().ExecuteCommand(); + //} - /// - /// 添加或更新数据,不推荐使用了 - /// - /// List - /// - public T Saveable(T parm, Expression> uClumns = null, Expression> iColumns = null) - { - var command = Context.Saveable(parm); + ///// + ///// 添加或更新数据,不推荐使用了 + ///// + ///// List + ///// + //public T Saveable(T parm, Expression> uClumns = null, Expression> iColumns = null) + //{ + // var command = Context.Saveable(parm); - if (uClumns != null) - { - command = command.UpdateIgnoreColumns(uClumns); - } + // if (uClumns != null) + // { + // command = command.UpdateIgnoreColumns(uClumns); + // } - if (iColumns != null) - { - command = command.InsertIgnoreColumns(iColumns); - } + // if (iColumns != null) + // { + // command = command.InsertIgnoreColumns(iColumns); + // } - return command.ExecuteReturnEntity(); - } + // return command.ExecuteReturnEntity(); + //} - /// - /// 批量添加或更新数据 - /// - /// List - /// - public List Saveable(List parm, Expression> uClumns = null, Expression> iColumns = null) - { - var command = Context.Saveable(parm); + ///// + ///// 批量添加或更新数据 + ///// + ///// List + ///// + //public List Saveable(List parm, Expression> uClumns = null, Expression> iColumns = null) + //{ + // var command = Context.Saveable(parm); - if (uClumns != null) - { - command = command.UpdateIgnoreColumns(uClumns); - } + // if (uClumns != null) + // { + // command = command.UpdateIgnoreColumns(uClumns); + // } - if (iColumns != null) - { - command = command.InsertIgnoreColumns(iColumns); - } + // if (iColumns != null) + // { + // command = command.InsertIgnoreColumns(iColumns); + // } - return command.ExecuteReturnList(); - } - #endregion + // return command.ExecuteReturnList(); + //} + //#endregion - #region 查询操作 + //#region 查询操作 - /// - /// 根据条件查询数据是否存在 - /// - /// 条件表达式树 - /// + ///// + ///// 根据条件查询数据是否存在 + ///// + ///// 条件表达式树 + ///// //public bool Any(Expression> where) //{ - // return base.Context.Any(where); + // return true;// base.Context.Any(where); //} - /// - /// 根据条件合计字段 - /// - /// 条件表达式树 - /// - public TResult Sum(Expression> where, Expression> field) - { - return base.Context.Queryable().Where(where).Sum(field); - } - - /// - /// 根据主值查询单条数据 - /// - /// 主键值 - /// 泛型实体 - //public T GetId(object pkValue) + ///// + ///// 根据条件合计字段 + ///// + ///// 条件表达式树 + ///// + //public TResult Sum(Expression> where, Expression> field) //{ - // return base.Context.Queryable().InSingle(pkValue); + // return base.Context.Queryable().Where(where).Sum(field); //} - /// - /// 根据主键查询多条数据 - /// - /// - /// - public List GetIn(object[] ids) - { - return Context.Queryable().In(ids).ToList(); - } + ///// + ///// 根据主值查询单条数据 + ///// + ///// 主键值 + ///// 泛型实体 + ////public T GetId(object pkValue) + ////{ + //// return base.Context.Queryable().InSingle(pkValue); + ////} - /// - /// 根据条件取条数 - /// - /// 条件表达式树 - /// - public int GetCount(Expression> where) - { - return Context.Queryable().Count(where); - - } - - /// - /// 查询所有数据(无分页,请慎用) - /// - /// - public List GetAll(bool useCache = false, int cacheSecond = 3600) - { - return Context.Queryable().WithCacheIF(useCache, cacheSecond).ToList(); - } - - /// - /// 获得一条数据 - /// - /// Expression> - /// - public T GetFirst2(Expression> where) - { - return base.GetFirst(where);// Context.Queryable().Where(where).First(); - } - - /// - /// 获得一条数据 - /// - /// string - /// - //public T GetFirst(string parm) + ///// + ///// 根据主键查询多条数据 + ///// + ///// + ///// + //public List GetIn(object[] ids) //{ - // return Context.Queryable().Where(parm).First(); + // return Context.Queryable().In(ids).ToList(); //} - /// - /// 根据条件查询分页数据 - /// - /// - /// - /// - public PagedInfo GetPages(Expression> where, PagerInfo parm) - { - var source = Context.Queryable().Where(where); + ///// + ///// 根据条件取条数 + ///// + ///// 条件表达式树 + ///// + //public int GetCount(Expression> where) + //{ + // return Context.Queryable().Count(where); - return source.ToPage(parm); - } + //} - public PagedInfo GetPages(Expression> where, PagerInfo parm, Expression> order, string orderEnum = "Asc") - { - var source = Context.Queryable().Where(where).OrderByIF(orderEnum == "Asc", order, OrderByType.Asc).OrderByIF(orderEnum == "Desc", order, OrderByType.Desc); + ///// + ///// 查询所有数据(无分页,请慎用) + ///// + ///// + //public List GetAll(bool useCache = false, int cacheSecond = 3600) + //{ + // return Context.Queryable().WithCacheIF(useCache, cacheSecond).ToList(); + //} - return source.ToPage(parm); - } + ///// + ///// 获得一条数据 + ///// + ///// Expression> + ///// + //public T GetFirst2(Expression> where) + //{ + // return base.GetFirst(where);// Context.Queryable().Where(where).First(); + //} + + ///// + ///// 获得一条数据 + ///// + ///// string + ///// + ////public T GetFirst(string parm) + ////{ + //// return Context.Queryable().Where(parm).First(); + ////} + + ///// + ///// 根据条件查询分页数据 + ///// + ///// + ///// + ///// + //public PagedInfo GetPages(Expression> where, PagerInfo parm) + //{ + // var source = Context.Queryable().Where(where); + + // return source.ToPage(parm); + //} + + //public PagedInfo GetPages(Expression> where, PagerInfo parm, Expression> order, string orderEnum = "Asc") + //{ + // var source = Context.Queryable().Where(where).OrderByIF(orderEnum == "Asc", order, OrderByType.Asc).OrderByIF(orderEnum == "Desc", order, OrderByType.Desc); + + // return source.ToPage(parm); + //} /// /// 根据条件查询数据 /// /// 条件表达式树 /// - public List GetWhere(Expression> where, bool useCache = false, int cacheSecond = 3600) - { - var query = Context.Queryable().Where(where).WithCacheIF(useCache, cacheSecond); - return query.ToList(); - } + // public List GetWhere(Expression> where, bool useCache = false, int cacheSecond = 3600) + // { + // var query = Context.Queryable().Where(where).WithCacheIF(useCache, cacheSecond); + // return query.ToList(); + // } - /// - /// 根据条件查询数据 - /// - /// 条件表达式树 - /// - public List GetWhere(Expression> where, Expression> order, string orderEnum = "Asc", bool useCache = false, int cacheSecond = 3600) - { - var query = Context.Queryable().Where(where).OrderByIF(orderEnum == "Asc", order, OrderByType.Asc).OrderByIF(orderEnum == "Desc", order, OrderByType.Desc).WithCacheIF(useCache, cacheSecond); - return query.ToList(); - } - - #endregion - - #region 修改操作 - - ///// - ///// 修改一条数据 + // /// + ///// 根据条件查询数据 ///// - ///// T + ///// 条件表达式树 ///// - //public int Update(T parm) + // public List GetWhere(Expression> where, Expression> order, string orderEnum = "Asc", bool useCache = false, int cacheSecond = 3600) + // { + // var query = Context.Queryable().Where(where).OrderByIF(orderEnum == "Asc", order, OrderByType.Asc).OrderByIF(orderEnum == "Desc", order, OrderByType.Desc).WithCacheIF(useCache, cacheSecond); + // return query.ToList(); + // } + + // #endregion + + //#region 修改操作 + + /////// + /////// 修改一条数据 + /////// + /////// T + /////// + ////public int Update(T parm) + ////{ + //// return Context.Updateable(parm).RemoveDataCache().ExecuteCommand(); + ////} + + /////// + /////// 批量修改 + /////// + /////// T + /////// + ////public int Update(List parm) + ////{ + //// return Context.Updateable(parm).RemoveDataCache().ExecuteCommand(); + ////} + + /////// + /////// 按查询条件更新 + /////// + /////// + /////// + /////// + ////public int Update(Expression> where, Expression> columns) + ////{ + //// return Context.Updateable().SetColumns(columns).Where(where).RemoveDataCache().ExecuteCommand(); + ////} + + //#endregion + + //#region 删除操作 + + /////// + /////// 删除一条或多条数据 + /////// + /////// string + /////// + ////public int Delete(object id) + ////{ + //// return Context.Deleteable(id).RemoveDataCache().ExecuteCommand(); + ////} + + /////// + /////// 删除一条或多条数据 + /////// + /////// string + /////// + ////public int Delete(object[] ids) + ////{ + //// return Context.Deleteable().In(ids).RemoveDataCache().ExecuteCommand(); + ////} + + /////// + /////// 根据条件删除一条或多条数据 + /////// + /////// 过滤条件 + /////// + ////public int Delete(Expression> where) + ////{ + //// return Context.Deleteable().Where(where).RemoveDataCache().ExecuteCommand(); + ////} + + //public int DeleteTable() //{ - // return Context.Updateable(parm).RemoveDataCache().ExecuteCommand(); + // return Context.Deleteable().RemoveDataCache().ExecuteCommand(); //} - - ///// - ///// 批量修改 - ///// - ///// T - ///// - //public int Update(List parm) - //{ - // return Context.Updateable(parm).RemoveDataCache().ExecuteCommand(); - //} - - ///// - ///// 按查询条件更新 - ///// - ///// - ///// - ///// - //public int Update(Expression> where, Expression> columns) - //{ - // return Context.Updateable().SetColumns(columns).Where(where).RemoveDataCache().ExecuteCommand(); - //} - - #endregion - - #region 删除操作 - - ///// - ///// 删除一条或多条数据 - ///// - ///// string - ///// - //public int Delete(object id) - //{ - // return Context.Deleteable(id).RemoveDataCache().ExecuteCommand(); - //} - - ///// - ///// 删除一条或多条数据 - ///// - ///// string - ///// - //public int Delete(object[] ids) - //{ - // return Context.Deleteable().In(ids).RemoveDataCache().ExecuteCommand(); - //} - - ///// - ///// 根据条件删除一条或多条数据 - ///// - ///// 过滤条件 - ///// - //public int Delete(Expression> where) - //{ - // return Context.Deleteable().Where(where).RemoveDataCache().ExecuteCommand(); - //} - - public int DeleteTable() - { - return Context.Deleteable().RemoveDataCache().ExecuteCommand(); - } - #endregion + //#endregion } } diff --git a/ZR.Service/Extensions/QueryableExtension.cs b/ZR.Service/Extensions/QueryableExtension.cs index 1bf1a23..d87b195 100644 --- a/ZR.Service/Extensions/QueryableExtension.cs +++ b/ZR.Service/Extensions/QueryableExtension.cs @@ -11,31 +11,6 @@ namespace ZR.Service { public static class QueryableExtension { - /// - /// 读取列表 - /// - /// - /// - /// - /// - /// - //public static async Task> ToPageAsync(this ISugarQueryable source, PageParm parm) - //{ - // var page = new PagedInfo(); - // var total = await source.CountAsync(); - // page.TotalCount = total; - // page.TotalPages = total / parm.PageSize; - - // if (total % parm.PageSize > 0) - // page.TotalPages++; - - // page.PageSize = parm.PageSize; - // page.PageIndex = parm.PageIndex; - - // page.DataSource = await source.OrderByIF(!string.IsNullOrEmpty(parm.Sort), $"{parm.OrderBy} {(parm.Sort == "descending" ? "desc" : "asc")}").ToPageListAsync(parm.PageIndex, parm.PageSize); - // return page; - //} - /// /// 读取列表 /// @@ -49,11 +24,6 @@ namespace ZR.Service var page = new PagedInfo(); var total = source.Count(); page.TotalCount = total; - //page.TotalPage = total / parm.PageSize; - - //if (total % parm.PageSize > 0) - // page.TotalPages++; - page.PageSize = parm.PageSize; page.PageIndex = parm.PageNum; diff --git a/ZR.Service/IBaseService.cs b/ZR.Service/IBaseService.cs index 13f602e..3e0b4ba 100644 --- a/ZR.Service/IBaseService.cs +++ b/ZR.Service/IBaseService.cs @@ -3,6 +3,7 @@ using SqlSugar; using System; using System.Collections.Generic; using System.Linq.Expressions; +using ZR.Repository; namespace ZR.Service { @@ -10,221 +11,199 @@ namespace ZR.Service /// 基础服务定义 /// /// - public interface IBaseService where T : class + public interface IBaseService : IBaseRepository where T : class, new() { - - #region 事务 - - ///// - ///// 启用事务 - ///// - //void BeginTran(); - - - ///// - ///// 提交事务 - ///// - //void CommitTran(); - - - ///// - ///// 回滚事务 - ///// - //void RollbackTran(); - - #endregion - #region 添加操作 /// /// 添加一条数据 /// /// /// - int Add(T parm); + //int Add(T parm); - int Add(T parm, Expression> iClumns = null, bool ignoreNull = false); + //int Add(T parm, Expression> iClumns = null, bool ignoreNull = false); - /// - /// 批量添加数据 - /// - /// List - /// - int Add(List parm); + ///// + ///// 批量添加数据 + ///// + ///// List + ///// + //int Add(List parm); - /// - /// 添加或更新数据 - /// - /// - /// - T Saveable(T parm, Expression> uClumns = null, Expression> iColumns = null); + ///// + ///// 添加或更新数据 + ///// + ///// + ///// + //T Saveable(T parm, Expression> uClumns = null, Expression> iColumns = null); - /// - /// 批量添加或更新数据 - /// - /// List - /// - List Saveable(List parm, Expression> uClumns = null, Expression> iColumns = null); + ///// + ///// 批量添加或更新数据 + ///// + ///// List + ///// + //List Saveable(List parm, Expression> uClumns = null, Expression> iColumns = null); - #endregion + //#endregion - #region 查询操作 + //#region 查询操作 - /// - /// 根据条件查询数据是否存在 - /// - /// 条件表达式树 - /// - bool Any(Expression> where); + ///// + ///// 根据条件查询数据是否存在 + ///// + ///// 条件表达式树 + ///// + //bool Any(Expression> where); - /// - /// 根据条件合计字段 - /// - /// 条件表达式树 - /// - TResult Sum(Expression> where, Expression> field); + ///// + ///// 根据条件合计字段 + ///// + ///// 条件表达式树 + ///// + //TResult Sum(Expression> where, Expression> field); - /// - /// 根据主值查询单条数据 - /// - /// 主键值 - /// 泛型实体 - T GetId(object pkValue); + ///// + ///// 根据主值查询单条数据 + ///// + ///// 主键值 + ///// 泛型实体 + //T GetId(object pkValue); - /// - /// 根据主键查询多条数据 - /// - /// - /// - List GetIn(object[] ids); + ///// + ///// 根据主键查询多条数据 + ///// + ///// + ///// + //List GetIn(object[] ids); - /// - /// 根据条件取条数 - /// - /// 条件表达式树 - /// - int GetCount(Expression> where); + ///// + ///// 根据条件取条数 + ///// + ///// 条件表达式树 + ///// + //int GetCount(Expression> where); - /// - /// 查询所有数据(无分页,请慎用) - /// - /// - List GetAll(bool useCache = false, int cacheSecond = 3600); + ///// + ///// 查询所有数据(无分页,请慎用) + ///// + ///// + //List GetAll(bool useCache = false, int cacheSecond = 3600); - /// - /// 获得一条数据 - /// - /// Expression> - /// - T GetFirst(Expression> where); + ///// + ///// 获得一条数据 + ///// + ///// Expression> + ///// + //T GetFirst(Expression> where); - /// - /// 获得一条数据 - /// - /// string - /// - T GetFirst(string parm); + ///// + ///// 获得一条数据 + ///// + ///// string + ///// + //T GetFirst(string parm); - /// - /// 根据条件查询分页数据 - /// - /// - /// - /// - PagedInfo GetPages(Expression> where, Model.PagerInfo parm); + ///// + ///// 根据条件查询分页数据 + ///// + ///// + ///// + ///// + //PagedInfo GetPages(Expression> where, Model.PagerInfo parm); - /// - /// 根据条件查询分页 - /// - /// - /// - /// - /// - /// - PagedInfo GetPages(Expression> where, Model.PagerInfo parm, Expression> order, string orderEnum = "Asc"); + ///// + ///// 根据条件查询分页 + ///// + ///// + ///// + ///// + ///// + ///// + //PagedInfo GetPages(Expression> where, Model.PagerInfo parm, Expression> order, string orderEnum = "Asc"); - /// - /// 根据条件查询数据 - /// - /// 条件表达式树 - /// - List GetWhere(Expression> where, bool useCache = false, int cacheSecond = 3600); + ///// + ///// 根据条件查询数据 + ///// + ///// 条件表达式树 + ///// + ////List GetWhere(Expression> where, bool useCache = false, int cacheSecond = 3600); - /// - /// 根据条件查询数据 - /// - /// 条件表达式树 - /// - List GetWhere(Expression> where, Expression> order, string orderEnum = "Asc", bool useCache = false, int cacheSecond = 3600); + /////// + /////// 根据条件查询数据 + /////// + /////// 条件表达式树 + /////// + ////List GetWhere(Expression> where, Expression> order, string orderEnum = "Asc", bool useCache = false, int cacheSecond = 3600); - #endregion + //#endregion - #region 修改操作 + //#region 修改操作 - /// - /// 修改一条数据 - /// - /// T - /// - int Update(T parm); + ///// + ///// 修改一条数据 + ///// + ///// T + ///// + //int Update(T parm); - /// - /// 批量修改 - /// - /// T - /// - int Update(List parm); + ///// + ///// 批量修改 + ///// + ///// T + ///// + //int Update(List parm); - /// - /// 按查询条件更新 - /// - /// - /// - /// - int Update(Expression> where, Expression> columns); + ///// + ///// 按查询条件更新 + ///// + ///// + ///// + ///// + //int Update(Expression> where, Expression> columns); - #endregion + //#endregion - #region 删除操作 + //#region 删除操作 - /// - /// 删除一条或多条数据 - /// - /// string - /// - int Delete(object id); + ///// + ///// 删除一条或多条数据 + ///// + ///// string + ///// + //int Delete(object id); - /// - /// 删除一条或多条数据 - /// - /// string - /// - int Delete(object[] ids); + ///// + ///// 删除一条或多条数据 + ///// + ///// string + ///// + //int Delete(object[] ids); - /// - /// 根据条件删除一条或多条数据 - /// - /// 过滤条件 - /// - int Delete(Expression> where); - - /// - /// 清空表 - /// - /// - int DeleteTable(); + ///// + ///// 根据条件删除一条或多条数据 + ///// + ///// 过滤条件 + ///// + //int Delete(Expression> where); + + ///// + ///// 清空表 + ///// + ///// + //int DeleteTable(); #endregion } diff --git a/ZR.Service/System/ArticleCategoryService.cs b/ZR.Service/System/ArticleCategoryService.cs index 8df3251..7ef4573 100644 --- a/ZR.Service/System/ArticleCategoryService.cs +++ b/ZR.Service/System/ArticleCategoryService.cs @@ -10,7 +10,7 @@ namespace ZR.Service.System /// 文章目录 /// [AppService(ServiceType = typeof(IArticleCategoryService), ServiceLifetime = LifeTime.Transient)] - public class ArticleCategoryService : IArticleCategoryService + public class ArticleCategoryService : BaseService, IArticleCategoryService { /// /// 构建前端所需要树结构 diff --git a/ZR.Service/System/ArticleService.cs b/ZR.Service/System/ArticleService.cs index 2cee43b..863efa9 100644 --- a/ZR.Service/System/ArticleService.cs +++ b/ZR.Service/System/ArticleService.cs @@ -8,7 +8,7 @@ namespace ZR.Service.System /// /// [AppService(ServiceType = typeof(IArticleService), ServiceLifetime = LifeTime.Transient)] - public class ArticleService : IArticleService + public class ArticleService : BaseService
, IArticleService { } diff --git a/ZR.Service/System/GenTableService.cs b/ZR.Service/System/GenTableService.cs index 4e6d99e..14830c9 100644 --- a/ZR.Service/System/GenTableService.cs +++ b/ZR.Service/System/GenTableService.cs @@ -67,11 +67,7 @@ namespace ZR.Service.System var predicate = Expressionable.Create(); predicate = predicate.AndIF(genTable.TableName.IfNotEmpty(), it => it.TableName.Contains(genTable.TableName)); - (List, int) ts = GenTableRepository.QueryableToPage(predicate.ToExpression(), pagerInfo.PageNum, pagerInfo.PageSize); - - PagedInfo pagedInfo = new(ts.Item1, pagerInfo.PageNum, pagerInfo.PageSize); - pagedInfo.TotalCount = ts.Item2; - return pagedInfo; + return GenTableRepository.GetPages(predicate.ToExpression(), pagerInfo); } /// diff --git a/ZR.Service/System/IService/IArticleCategoryService.cs b/ZR.Service/System/IService/IArticleCategoryService.cs index 57c7427..602b228 100644 --- a/ZR.Service/System/IService/IArticleCategoryService.cs +++ b/ZR.Service/System/IService/IArticleCategoryService.cs @@ -7,7 +7,7 @@ using ZR.Model.System; namespace ZR.Service.System.IService { - public interface IArticleCategoryService //: IBaseService + public interface IArticleCategoryService : IBaseService { List BuildCategoryTree(List categories); } diff --git a/ZR.Service/System/IService/IArticleService.cs b/ZR.Service/System/IService/IArticleService.cs index cbfa13f..0f4e7de 100644 --- a/ZR.Service/System/IService/IArticleService.cs +++ b/ZR.Service/System/IService/IArticleService.cs @@ -8,7 +8,7 @@ using ZR.Model.System; namespace ZR.Service.System.IService { - public interface IArticleService //: IBaseService
+ public interface IArticleService : IBaseService
{ } diff --git a/ZR.Service/System/IService/ISysDeptService.cs b/ZR.Service/System/IService/ISysDeptService.cs index 1dc6b77..7a381f6 100644 --- a/ZR.Service/System/IService/ISysDeptService.cs +++ b/ZR.Service/System/IService/ISysDeptService.cs @@ -6,15 +6,15 @@ using ZR.Model.Vo.System; namespace ZR.Service.System.IService { - public interface ISysDeptService //: IBaseService + public interface ISysDeptService : IBaseService { - public List GetSysDepts(SysDept dept); - public string CheckDeptNameUnique(SysDept dept); - public int InsertDept(SysDept dept); - public int UpdateDept(SysDept dept); - public void UpdateDeptChildren(long deptId, string newAncestors, string oldAncestors); - public List GetChildrenDepts(List depts, long deptId); - public List BuildDeptTree(List depts); - public List BuildDeptTreeSelect(List depts); + List GetSysDepts(SysDept dept); + string CheckDeptNameUnique(SysDept dept); + int InsertDept(SysDept dept); + int UpdateDept(SysDept dept); + void UpdateDeptChildren(long deptId, string newAncestors, string oldAncestors); + List GetChildrenDepts(List depts, long deptId); + List BuildDeptTree(List depts); + List BuildDeptTreeSelect(List depts); } } diff --git a/ZR.Service/System/IService/ISysDictService.cs b/ZR.Service/System/IService/ISysDictService.cs index 28d77cd..a6bd282 100644 --- a/ZR.Service/System/IService/ISysDictService.cs +++ b/ZR.Service/System/IService/ISysDictService.cs @@ -8,7 +8,7 @@ namespace ZR.Service.System.IService /// /// /// - public interface ISysDictService : IBaseService + public interface ISysDictService { public List SelectDictTypeList(SysDictType dictType, Model.PagerInfo pager); @@ -39,5 +39,12 @@ namespace ZR.Service.System.IService /// /// public int UpdateDictType(SysDictType sysDictType); + + /// + /// 获取字典信息 + /// + /// + /// + SysDictType GetInfo(long dictId); } } diff --git a/ZR.Service/System/IService/ISysPostService.cs b/ZR.Service/System/IService/ISysPostService.cs index 6230e23..e8d0abf 100644 --- a/ZR.Service/System/IService/ISysPostService.cs +++ b/ZR.Service/System/IService/ISysPostService.cs @@ -6,7 +6,7 @@ using ZR.Repository; namespace ZR.Service.System.IService { - public interface ISysPostService: IBaseRepository + public interface ISysPostService : IBaseService { string CheckPostNameUnique(SysPost sysPost); string CheckPostCodeUnique(SysPost sysPost); diff --git a/ZR.Service/System/IService/ISysTasksLogService.cs b/ZR.Service/System/IService/ISysTasksLogService.cs index c5885e7..cf0f16e 100644 --- a/ZR.Service/System/IService/ISysTasksLogService.cs +++ b/ZR.Service/System/IService/ISysTasksLogService.cs @@ -3,7 +3,7 @@ using ZR.Repository; namespace ZR.Service.System.IService { - public interface ISysTasksLogService: IBaseRepository + public interface ISysTasksLogService : IBaseService { /// /// 记录任务执行日志 diff --git a/ZR.Service/System/IService/ISysTasksQzService.cs b/ZR.Service/System/IService/ISysTasksQzService.cs index d3df7a1..e7e0257 100644 --- a/ZR.Service/System/IService/ISysTasksQzService.cs +++ b/ZR.Service/System/IService/ISysTasksQzService.cs @@ -7,8 +7,8 @@ using ZR.Model.System; namespace ZR.Service.System.IService { - public interface ISysTasksQzService + public interface ISysTasksQzService : IBaseService { - SysTasksQz GetId(object id); + //SysTasksQz GetId(object id); } } diff --git a/ZR.Service/System/SysDeptService.cs b/ZR.Service/System/SysDeptService.cs index fb6dbc5..c2b56aa 100644 --- a/ZR.Service/System/SysDeptService.cs +++ b/ZR.Service/System/SysDeptService.cs @@ -18,7 +18,7 @@ namespace ZR.Service.System /// 部门管理 /// [AppService(ServiceType = typeof(ISysDeptService), ServiceLifetime = LifeTime.Transient)] - public class SysDeptService :ISysDeptService + public class SysDeptService : BaseService, ISysDeptService { public SysDeptRepository DeptRepository; @@ -76,7 +76,7 @@ namespace ZR.Service.System } dept.Ancestors = info.Ancestors + "," + dept.ParentId; - return DeptRepository.Insert(dept, true); + return DeptRepository.Add(dept); } /// @@ -86,8 +86,8 @@ namespace ZR.Service.System /// public int UpdateDept(SysDept dept) { - SysDept newParentDept = DeptRepository.GetSingle(it => it.ParentId == dept.ParentId); - SysDept oldDept = DeptRepository.GetSingle(m => m.DeptId == dept.DeptId); + SysDept newParentDept = DeptRepository.GetFirst(it => it.ParentId == dept.ParentId); + SysDept oldDept = DeptRepository.GetFirst(m => m.DeptId == dept.DeptId); if (newParentDept != null && oldDept != null) { string newAncestors = newParentDept.Ancestors + "," + newParentDept.DeptId; @@ -129,12 +129,10 @@ namespace ZR.Service.System foreach (var child in children) { child.Ancestors = child.Ancestors.Replace(oldAncestors, newAncestors); - - if (child.DeptId.Equals(deptId)) - { - //TODO Saveable(child, it => new { it.Ancestors }); - //DeptRepository.UdateDeptChildren(child); - } + } + if (children.Count > 0) + { + //DeptRepository.UdateDeptChildren(child); } } diff --git a/ZR.Service/System/SysDictDataService.cs b/ZR.Service/System/SysDictDataService.cs index e52501c..900341d 100644 --- a/ZR.Service/System/SysDictDataService.cs +++ b/ZR.Service/System/SysDictDataService.cs @@ -37,7 +37,7 @@ namespace ZR.Service.System public List SelectDictDataByType(string dictType) { string CK = $"SelectDictDataByType_{dictType}"; - if (!(CacheHelper.GetCache(CK) is List list)) + if (CacheHelper.GetCache(CK) is not List list) { list = SysDictDataRepository.SelectDictDataByType(dictType); CacheHelper.SetCache(CK, list, 30); diff --git a/ZR.Service/System/SysDictService.cs b/ZR.Service/System/SysDictService.cs index fb72f93..96a3395 100644 --- a/ZR.Service/System/SysDictService.cs +++ b/ZR.Service/System/SysDictService.cs @@ -13,7 +13,7 @@ namespace ZR.Service.System /// 字典类型 /// [AppService(ServiceType = typeof(ISysDictService), ServiceLifetime = LifeTime.Transient)] - public class SysDictService : BaseService, ISysDictService + public class SysDictService : ISysDictService { private SysDictRepository DictRepository; private SysDictDataRepository DictDataRepository; @@ -79,7 +79,7 @@ namespace ZR.Service.System /// public long InsertDictType(SysDictType sysDictType) { - return DictRepository.InsertReturnEntity(sysDictType).DictId; + return DictRepository.InsertReturnBigIdentity(sysDictType); } /// @@ -97,5 +97,15 @@ namespace ZR.Service.System } return DictRepository.UpdateDictType(sysDictType); } + + /// + /// 获取字典信息 + /// + /// + /// + public SysDictType GetInfo(long dictId) + { + return DictRepository.GetFirst(f => f.DictId == dictId); + } } } diff --git a/ZR.Service/System/SysPostService.cs b/ZR.Service/System/SysPostService.cs index b32957c..5a5e977 100644 --- a/ZR.Service/System/SysPostService.cs +++ b/ZR.Service/System/SysPostService.cs @@ -13,7 +13,7 @@ namespace ZR.Service.System /// 岗位管理 /// [AppService(ServiceType = typeof(ISysPostService), ServiceLifetime = LifeTime.Transient)] - public class SysPostService : BaseRepository, ISysPostService + public class SysPostService : BaseService, ISysPostService { public SysPostRepository PostRepository; public SysPostService(SysPostRepository postRepository) diff --git a/ZR.Service/System/SysTasksLogService.cs b/ZR.Service/System/SysTasksLogService.cs index e4539c7..7b7ae0d 100644 --- a/ZR.Service/System/SysTasksLogService.cs +++ b/ZR.Service/System/SysTasksLogService.cs @@ -28,7 +28,7 @@ namespace ZR.Service.System logModel.CreateTime = DateTime.Now; } - Insert(logModel, true); + Add(logModel); return logModel; } } diff --git a/ZR.Service/System/SysTasksQzService.cs b/ZR.Service/System/SysTasksQzService.cs index 9645e58..1569287 100644 --- a/ZR.Service/System/SysTasksQzService.cs +++ b/ZR.Service/System/SysTasksQzService.cs @@ -5,7 +5,7 @@ using ZR.Service.System.IService; namespace ZR.Service.System { [AppService(ServiceType = typeof(ISysTasksQzService), ServiceLifetime = LifeTime.Transient)] - public class SysTasksQzService : ISysTasksQzService + public class SysTasksQzService : BaseService, ISysTasksQzService { } diff --git a/ZR.Vue/src/views/system/dept/index.vue b/ZR.Vue/src/views/system/dept/index.vue index ce82cc5..759b8a9 100644 --- a/ZR.Vue/src/views/system/dept/index.vue +++ b/ZR.Vue/src/views/system/dept/index.vue @@ -24,6 +24,7 @@ + diff --git a/ZRAdmin.xml b/ZRAdmin.xml index 163b916..22d0f72 100644 --- a/ZRAdmin.xml +++ b/ZRAdmin.xml @@ -4,7 +4,7 @@ ZR.Admin.WebApi - + json输出带时间格式的 From d5087a17250db86a8283b630168e4cfb6f30f078 Mon Sep 17 00:00:00 2001 From: izory <791736813@qq.com> Date: Mon, 27 Sep 2021 17:38:09 +0800 Subject: [PATCH 03/21] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E7=94=9F=E6=88=90=E5=88=B0=E6=8C=87=E5=AE=9A=E8=8F=9C=E5=8D=95?= =?UTF-8?q?=E7=9B=AE=E5=BD=95=E4=B8=8B=E4=B8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/CodeGeneratorController.cs | 5 ++- .../Controllers/business/GendemoController.cs | 4 +- .../wwwroot/CodeGenTemplate/MySqlTemplate.txt | 2 +- .../CodeGenTemplate/RepositoryTemplate.txt | 2 +- .../CodeGenTemplate/ServiceTemplate.txt | 4 +- .../wwwroot/CodeGenTemplate/SqlTemplate.txt | 4 +- .../wwwroot/CodeGenTemplate/VueJsTemplate.txt | 2 +- ZR.CodeGenerator/CodeGeneratorTool.cs | 3 +- ZR.CodeGenerator/Model/GenerateDto.cs | 4 ++ ZR.CodeGenerator/Model/ReplaceDto.cs | 11 ----- ZR.Model/Models/Gendemo.cs | 4 +- ZR.Model/System/Dto/GenTableDto.cs | 4 ++ ZR.Model/System/Generate/GenTable.cs | 43 ++++++++++++++++++- .../Repositories/GendemoRepository.cs | 8 +--- ZR.Service/Business/GendemoService.cs | 18 ++++---- .../Business/IBusService/IGendemoService.cs | 4 +- ZR.Service/System/GenTableService.cs | 1 + ZR.Vue/src/views/tool/gen/editTable.vue | 8 ++-- ZR.Vue/src/views/tool/gen/genInfoForm.vue | 4 +- ZRAdmin.xml | 4 +- 20 files changed, 87 insertions(+), 52 deletions(-) diff --git a/ZR.Admin.WebApi/Controllers/CodeGeneratorController.cs b/ZR.Admin.WebApi/Controllers/CodeGeneratorController.cs index df5887c..4df2f83 100644 --- a/ZR.Admin.WebApi/Controllers/CodeGeneratorController.cs +++ b/ZR.Admin.WebApi/Controllers/CodeGeneratorController.cs @@ -5,6 +5,7 @@ using Mapster; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Hosting; +using Newtonsoft.Json; using SqlSugar; using System; using System.Collections.Generic; @@ -89,7 +90,8 @@ namespace ZR.Admin.WebApi.Controllers var genTableInfo = GenTableService.GetGenTableInfo(dto.TableId); genTableInfo.Columns = GenTableColumnService.GenTableColumns(dto.TableId); - + Dictionary options = JsonConvert.DeserializeObject>(genTableInfo.Options); + dto.ParentMenuId = (long)options.GetValueOrDefault("parentMenuId", 0); dto.GenTable = genTableInfo; //生成代码 CodeGeneratorTool.Generate(genTableInfo, dto); @@ -211,6 +213,7 @@ namespace ZR.Admin.WebApi.Controllers if (genTableDto == null) throw new CustomException("请求参数错误"); var genTable = genTableDto.Adapt().ToUpdate(HttpContext); + genTable.Options = JsonConvert.SerializeObject(new { parentMenuId = genTableDto.ParentMenuId }); int rows = GenTableService.UpdateGenTable(genTable); if (rows > 0) { diff --git a/ZR.Admin.WebApi/Controllers/business/GendemoController.cs b/ZR.Admin.WebApi/Controllers/business/GendemoController.cs index a167422..61e4d8c 100644 --- a/ZR.Admin.WebApi/Controllers/business/GendemoController.cs +++ b/ZR.Admin.WebApi/Controllers/business/GendemoController.cs @@ -20,8 +20,8 @@ namespace ZR.Admin.WebApi.Controllers /// /// 代码生成演示Controller /// - /// @author zhaorui - /// @date 2021-09-24 + /// @author zr + /// @date 2021-09-27 /// [Verify] [Route("business/Gendemo")] diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/MySqlTemplate.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/MySqlTemplate.txt index 1c36b1e..bd6bc5d 100644 --- a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/MySqlTemplate.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/MySqlTemplate.txt @@ -1,6 +1,6 @@ -- 菜单 INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time, update_by, update_time, remark) -VALUES ('{FunctionName}', 0, 1, '/{ModuleName}/{ModelTypeName}', '{ModuleName}/{ViewsFileName}/index', 0, 0, 'C', '0', '0', '{Permission}:list', '#', '', sysdate(), '', NULL, '{ModelTypeDesc}菜单'); +VALUES ('{FunctionName}', 0, 1, '/{ModuleName}/{ModelTypeName}', '{ModuleName}/{ViewsFileName}/index', 0, 0, 'C', '0', '0', '{Permission}:list', '#', '', sysdate(), '', NULL, '{FunctionName}菜单'); -- 按钮父菜单id SELECT @menuId := LAST_INSERT_ID(); diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/RepositoryTemplate.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/RepositoryTemplate.txt index db312b9..c2c5392 100644 --- a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/RepositoryTemplate.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/RepositoryTemplate.txt @@ -12,7 +12,7 @@ namespace {RepositoriesNamespace} /// @date {DateTime} ///
[AppService(ServiceLifetime = LifeTime.Transient)] - public class {ModelTypeName}Repository : BaseRepository + public class {ModelTypeName}Repository : BaseRepository { #region 业务逻辑代码 #endregion diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/ServiceTemplate.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/ServiceTemplate.txt index c42b2eb..1892b2f 100644 --- a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/ServiceTemplate.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/ServiceTemplate.txt @@ -21,10 +21,10 @@ namespace {ServicesNamespace}.Business [AppService(ServiceType = typeof(I{ModelTypeName}Service), ServiceLifetime = LifeTime.Transient)] public class {ModelTypeName}Service: BaseService<{ModelTypeName}>, I{ModelTypeName}Service { - private readonly {ModelTypeName}Repository _repository; + private readonly {ModelTypeName}Repository _{ModelTypeName}repository; public {ModelTypeName}Service({ModelTypeName}Repository repository) { - _repository = repository; + _{ModelTypeName}repository = repository; } #region 业务逻辑代码 diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/SqlTemplate.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/SqlTemplate.txt index 3cd128c..45ce4be 100644 --- a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/SqlTemplate.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/SqlTemplate.txt @@ -1,6 +1,6 @@ -- 菜单 INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time, update_by, update_time, remark) -VALUES ('{FunctionName}', 0, 1, '/{ModuleName}/{ModelTypeName}', '{ModuleName}/{ViewsFileName}/index', 0, 0, 'C', '0', '0', '{Permission}:list', '#', '', GETDATE(), '', NULL, '{ModelTypeDesc}'); +VALUES ('{FunctionName}', {ParentId}, 1, '/{ModuleName}/{ModelTypeName}', '{ModuleName}/{ViewsFileName}/index', 0, 0, 'C', '0', '0', '{Permission}:list', '#', '', GETDATE(), '', NULL, '{FunctionName}'); -- 按钮父菜单id declare @menuId int = @@identity @@ -19,5 +19,5 @@ INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isC VALUES ('修改', @menuId, 3, '#', NULL, 0, 0, 'F', '0', '0', '{Permission}:update', '', '', GETDATE(), '', NULL, NULL); GO -SELECT * FROM sys_menu WHERE parentId = @menuId; +SELECT * FROM sys_menu WHERE parentId = {ParentId}; SELECT * FROM sys_menu WHERE menuId = @menuId; \ No newline at end of file diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/VueJsTemplate.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/VueJsTemplate.txt index 3d37ec0..29b3edd 100644 --- a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/VueJsTemplate.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/VueJsTemplate.txt @@ -38,7 +38,7 @@ export function update{ModelTypeName}(data) { /** * 获取{FunctionName}详情 - * @param {Id} {ModelTypeDesc}Id + * @param {Id} {FunctionName}Id */ export function get{ModelTypeName}(id) { return request({ diff --git a/ZR.CodeGenerator/CodeGeneratorTool.cs b/ZR.CodeGenerator/CodeGeneratorTool.cs index f39c2dd..dda6f31 100644 --- a/ZR.CodeGenerator/CodeGeneratorTool.cs +++ b/ZR.CodeGenerator/CodeGeneratorTool.cs @@ -53,7 +53,6 @@ namespace ZR.CodeGenerator ReplaceDto replaceDto = new(); replaceDto.ModelTypeName = tableInfo.ClassName;//表名对应C# 实体类名 replaceDto.TableName = tableInfo.TableName;//表名 - replaceDto.TableDesc = tableInfo.TableComment;//表说明描述 replaceDto.Permission = $"{tableInfo.ModuleName}:{tableInfo.ClassName.ToLower()}";//权限 replaceDto.ViewsFileName = FirstLowerCase(replaceDto.ModelTypeName); replaceDto.Author = tableInfo.FunctionAuthor; @@ -393,9 +392,9 @@ namespace ZR.CodeGenerator var content = FileHelper.ReadTemplate($"{tempName}.txt") .Replace("{ModelTypeName}", replaceDto.ModelTypeName) .Replace("{Permission}", replaceDto.Permission) - .Replace("{ModelTypeDesc}", replaceDto.TableDesc) .Replace("{ModuleName}", generateDto.GenTable.ModuleName) .Replace("{ViewsFileName}", replaceDto.ViewsFileName) + .Replace("{ParentId}", generateDto.ParentMenuId.ToString()) .Replace("{FunctionName}", generateDto.GenTable.FunctionName); generateDto.GenCodes.Add(new GenCode(8, "sql", fullPath, content)); diff --git a/ZR.CodeGenerator/Model/GenerateDto.cs b/ZR.CodeGenerator/Model/GenerateDto.cs index 9ce7d07..e81020f 100644 --- a/ZR.CodeGenerator/Model/GenerateDto.cs +++ b/ZR.CodeGenerator/Model/GenerateDto.cs @@ -45,6 +45,10 @@ namespace ZR.CodeGenerator.Model /// 代码生成压缩包名称 ///
public string ZipFileName { get; set; } + /// + /// 父级菜单id + /// + public long ParentMenuId { get; set; } #endregion } diff --git a/ZR.CodeGenerator/Model/ReplaceDto.cs b/ZR.CodeGenerator/Model/ReplaceDto.cs index 425e63a..caad242 100644 --- a/ZR.CodeGenerator/Model/ReplaceDto.cs +++ b/ZR.CodeGenerator/Model/ReplaceDto.cs @@ -8,13 +8,6 @@ namespace ZR.CodeGenerator.Model { public class ReplaceDto { - //public string ModelsNamespace { get; set; } - //public string DtosNamespace { get; set; } - //public string RepositoriesNamespace { get; set; } - //public string IRepositoriesNamespace { get; set; } - //public string IServicsNamespace { get; set; } - //public string ServicesNamespace { get; set; } - /// /// 主键字段 /// @@ -36,10 +29,6 @@ namespace ZR.CodeGenerator.Model ///
public string TableName { get; set; } /// - /// 表描述、说明 - /// - public string TableDesc { get; set; } - /// /// 修改列 /// public string UpdateColumn { get; set; } diff --git a/ZR.Model/Models/Gendemo.cs b/ZR.Model/Models/Gendemo.cs index 115f745..e2e2556 100644 --- a/ZR.Model/Models/Gendemo.cs +++ b/ZR.Model/Models/Gendemo.cs @@ -6,8 +6,8 @@ namespace ZR.Model.Models /// /// 代码生成演示,数据实体对象 /// - /// @author zhaorui - /// @date 2021-09-24 + /// @author zr + /// @date 2021-09-27 /// [SqlSugar.SugarTable("gen_demo")] public class Gendemo diff --git a/ZR.Model/System/Dto/GenTableDto.cs b/ZR.Model/System/Dto/GenTableDto.cs index 7820d7b..36986c3 100644 --- a/ZR.Model/System/Dto/GenTableDto.cs +++ b/ZR.Model/System/Dto/GenTableDto.cs @@ -21,6 +21,10 @@ namespace ZR.Model.System.Dto public string FunctionAuthor { get; set; } public string GenType { get; set; } public string Options { get; set; } + /// + /// 上级菜单id + /// + public int ParentMenuId { get; set; } public List Columns { get; set; } } diff --git a/ZR.Model/System/Generate/GenTable.cs b/ZR.Model/System/Generate/GenTable.cs index 0737c33..d2cd238 100644 --- a/ZR.Model/System/Generate/GenTable.cs +++ b/ZR.Model/System/Generate/GenTable.cs @@ -10,23 +10,64 @@ namespace ZR.Model.System.Generate [SqlSugar.SugarTable("gen_table")] public class GenTable: SysBase { + /// + /// 表id + /// [SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)] public int TableId { get; set; } + /// + /// 表名 + /// public string TableName { get; set; } + /// + /// 表描述 + /// public string TableComment { get; set; } + /// + /// 关联父表的表名 + /// public string SubTableName { get; set; } + /// + /// 本表关联父表的外键名 + /// public string SubTableFkName { get; set; } + /// + /// csharp类名 + /// public string ClassName { get; set; } + /// + /// 使用的模板(crud单表操作 tree树表操作 sub主子表操作) + /// public string TplCategory { get; set; } + /// + /// 基本命名空间前缀 + /// public string BaseNameSpace { get; set; } + /// + /// 生成模块名 + /// public string ModuleName { get; set; } + /// + /// 生成业务名 + /// public string BusinessName { get; set; } + /// + /// 生成功能名 + /// public string FunctionName { get; set; } + /// + /// 生成作者名 + /// public string FunctionAuthor { get; set; } + /// + /// 生成代码方式(0zip压缩包 1自定义路径) + /// public string GenType { get; set; } + /// + /// 其他生成选项 + /// public string Options { get; set; } - /** 表列信息 */ [SqlSugar.SugarColumn(IsIgnore = true)] public List Columns { get; set; } diff --git a/ZR.Repository/Repositories/GendemoRepository.cs b/ZR.Repository/Repositories/GendemoRepository.cs index 0a967d4..1d1c8c6 100644 --- a/ZR.Repository/Repositories/GendemoRepository.cs +++ b/ZR.Repository/Repositories/GendemoRepository.cs @@ -2,22 +2,18 @@ using System; using Infrastructure.Attribute; using ZR.Repository.System; using ZR.Model.Models; -using SqlSugar; namespace ZR.Repository { /// /// 代码生成演示仓储接口的实现 /// - /// @author zhaorui - /// @date 2021-09-24 + /// @author zr + /// @date 2021-09-27 /// [AppService(ServiceLifetime = LifeTime.Transient)] public class GendemoRepository : BaseRepository { - public GendemoRepository(SqlSugarClient dbContext) : base(dbContext) - { - } #region 业务逻辑代码 #endregion } diff --git a/ZR.Service/Business/GendemoService.cs b/ZR.Service/Business/GendemoService.cs index 119fa92..e86a392 100644 --- a/ZR.Service/Business/GendemoService.cs +++ b/ZR.Service/Business/GendemoService.cs @@ -15,19 +15,17 @@ namespace ZR.Service.Business /// /// 代码生成演示Service业务层处理 /// - /// @author zhaorui - /// @date 2021-09-24 + /// @author zr + /// @date 2021-09-27 /// [AppService(ServiceType = typeof(IGendemoService), ServiceLifetime = LifeTime.Transient)] - public class GendemoService : BaseService, IGendemoService + public class GendemoService: BaseService, IGendemoService { - //private readonly SqlSugarClient _client; - - //public GendemoService(SqlSugarClient client, int db =1) : base(db) - //{ - // _client = client; - //} - + private readonly GendemoRepository _repository; + public GendemoService(GendemoRepository repository) + { + _repository = repository; + } #region 业务逻辑代码 #endregion diff --git a/ZR.Service/Business/IBusService/IGendemoService.cs b/ZR.Service/Business/IBusService/IGendemoService.cs index a99bf46..7e0454c 100644 --- a/ZR.Service/Business/IBusService/IGendemoService.cs +++ b/ZR.Service/Business/IBusService/IGendemoService.cs @@ -6,8 +6,8 @@ namespace ZR.Service.Business /// /// 代码生成演示service接口 /// - /// @author zhaorui - /// @date 2021-09-24 + /// @author zr + /// @date 2021-09-27 /// public interface IGendemoService: IBaseService { diff --git a/ZR.Service/System/GenTableService.cs b/ZR.Service/System/GenTableService.cs index 14830c9..f38f3cc 100644 --- a/ZR.Service/System/GenTableService.cs +++ b/ZR.Service/System/GenTableService.cs @@ -1,6 +1,7 @@ using Infrastructure.Attribute; using Infrastructure.Extensions; using Infrastructure.Model; +using Newtonsoft.Json; using SqlSugar; using System; using System.Collections.Generic; diff --git a/ZR.Vue/src/views/tool/gen/editTable.vue b/ZR.Vue/src/views/tool/gen/editTable.vue index cbd5dde..6f3930c 100644 --- a/ZR.Vue/src/views/tool/gen/editTable.vue +++ b/ZR.Vue/src/views/tool/gen/editTable.vue @@ -113,7 +113,7 @@ + diff --git a/ZRAdmin.xml b/ZRAdmin.xml index 7c7aa8d..e88b1f5 100644 --- a/ZRAdmin.xml +++ b/ZRAdmin.xml @@ -161,6 +161,13 @@ + + + 发送邮件 + + 请求参数接收实体 + + T4代码自动生成 From 8cf4273bd34dec4e8c8c1ad9a167009ee4541b1d Mon Sep 17 00:00:00 2001 From: izory <791736813@qq.com> Date: Tue, 28 Sep 2021 18:17:31 +0800 Subject: [PATCH 05/21] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E7=94=9F=E6=88=90?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=8A=A0=E6=9D=83=E9=99=90=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Infrastructure/Model/SendEmailDto.cs | 18 ++ ZR.Common/MailHelper.cs | 165 ++++++++++++++++++ .../src/views/{system => tool}/file/index.vue | 33 +--- ZR.Vue/src/views/tool/gen/index.vue | 8 +- document/admin-mysql.sql | 12 +- document/admin-sqlserver.sql | Bin 105644 -> 100480 bytes 6 files changed, 199 insertions(+), 37 deletions(-) create mode 100644 Infrastructure/Model/SendEmailDto.cs create mode 100644 ZR.Common/MailHelper.cs rename ZR.Vue/src/views/{system => tool}/file/index.vue (84%) diff --git a/Infrastructure/Model/SendEmailDto.cs b/Infrastructure/Model/SendEmailDto.cs new file mode 100644 index 0000000..749bbb8 --- /dev/null +++ b/Infrastructure/Model/SendEmailDto.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Infrastructure.Model +{ + public class SendEmailDto + { + public string FileUrl { get; set; } = ""; + public string Subject { get; set; } + public string ToUser { get; set; } + public string Content { get; set; } = ""; + public string HtmlContent { get; set; } + public DateTime AddTime { get; set; } + } +} diff --git a/ZR.Common/MailHelper.cs b/ZR.Common/MailHelper.cs new file mode 100644 index 0000000..c5299a2 --- /dev/null +++ b/ZR.Common/MailHelper.cs @@ -0,0 +1,165 @@ +using MailKit.Net.Smtp; +using MimeKit; +using MimeKit.Text; +using System; +using System.Collections.Generic; +using System.IO; + +namespace ZR.Common +{ + public class MailHelper + { + /// + /// 发送人邮箱 + /// + public string FromEmail { get; set; } = ""; + /// + /// 发送人密码 + /// + public string FromPwd { get; set; } = ""; + /// + /// 发送协议 + /// + public string Smtp { get; set; } = "smtp.qq.com"; + /// + /// 协议端口 + /// + public int Port { get; set; } = 587; + /// + /// 是否使用SSL协议 + /// + public bool UseSsl { get; set; } = false; + public string mailSign = @""; + + public MailHelper(string fromEmail, string smtp, int port, string fromPwd) + { + FromEmail = fromEmail; + Smtp = smtp; + FromPwd = fromPwd; + Port = port; + } + + public MailHelper(string fromEmail, string fromPwd) + { + FromEmail = fromEmail; + FromPwd = fromPwd; + } + + /// + /// 发送一个人 + /// + /// + /// + /// + /// + public void SendMail(string toAddress, string subject, string text, string path = "", string html = "") + { + IEnumerable mailboxes = new List() { + new MailboxAddress(toAddress) + }; + + SendMail(mailboxes, subject, text, path, html); + } + + /// + /// 发送多个邮箱 + /// + /// + /// + /// + /// + public void SendMail(string[] toAddress, string subject, string text, string path = "", string html = "") + { + IList mailboxes = new List() { }; + foreach (var item in toAddress) + { + mailboxes.Add(new MailboxAddress(item)); + } + + SendMail(mailboxes, subject, text, path, html); + } + + /// + /// 发送邮件 + /// + /// + /// + /// + /// + /// 附件url地址 + private void SendMail(IEnumerable toAddress, string subject, string text, string path = "", string html = "") + { + MimeMessage message = new MimeMessage(); + //发件人 + message.From.Add(new MailboxAddress(FromEmail, FromEmail)); + + //收件人 + //message.To.Add(new MailboxAddress(toAddress)); + //IList internets = null; + //internets.Add(new MailboxAddress(toAddress)); + + message.To.AddRange(toAddress); + message.Subject = subject; + message.Date = DateTime.Now; + + //创建附件Multipart + Multipart multipart = new Multipart("mixed"); + + //html内容 + if (!string.IsNullOrEmpty(html)) + { + var Html = new TextPart(TextFormat.Html) + { + Text = html + }; + multipart.Add(Html); + } + //文本内容 + if (!string.IsNullOrEmpty(text)) + { + var plain = new TextPart(TextFormat.Plain) + { + Text = text + "\r\n\n\n" + mailSign + }; + multipart.Add(plain); + } + + //附件 + if (!string.IsNullOrEmpty(path)) + { + MimePart attachment = new MimePart() + { + Content = new MimeContent(File.OpenRead(path), ContentEncoding.Default), + //读取文件,只能用绝对路径 + ContentDisposition = new ContentDisposition(ContentDisposition.Attachment), + ContentTransferEncoding = ContentEncoding.Base64, + //文件名字 + FileName = Path.GetFileName(path) + }; + multipart.Add(attachment); + } + + //赋值邮件内容 + message.Body = multipart; + + //开始发送 + using (var client = new SmtpClient()) + { + client.ServerCertificateValidationCallback = (s, c, h, e) => true; + + //Smtp服务器 + //client.Connect("smtp.qq.com", 587, false); + client.Connect(Smtp, Port, true); + //登录,发送 + //特别说明,对于服务器端的中文相应,Exception中有编码问题,显示乱码了 + client.Authenticate(FromEmail, FromPwd); + + client.Send(message); + //断开 + client.Disconnect(true); + Console.WriteLine($"发送邮件成功{DateTime.Now}"); + } + } + + } +} \ No newline at end of file diff --git a/ZR.Vue/src/views/system/file/index.vue b/ZR.Vue/src/views/tool/file/index.vue similarity index 84% rename from ZR.Vue/src/views/system/file/index.vue rename to ZR.Vue/src/views/tool/file/index.vue index 86d6824..ef152d8 100644 --- a/ZR.Vue/src/views/system/file/index.vue +++ b/ZR.Vue/src/views/tool/file/index.vue @@ -43,16 +43,6 @@ - - - - @@ -108,20 +98,10 @@ export default { dictLabel: "本地", }, ], - uploadUrl: process.env.VUE_APP_BASE_API + "/upload/SaveFile?token=zr", + uploadUrl: process.env.VUE_APP_BASE_API + "/upload/SaveFile", // 数据列表 dataList: [ - { - id: 1, - photo: - "https://ss1.baidu.com/-4o3dSag_xI4khGko9WTAnF6hhy/zhidao/pic/item/d788d43f8794a4c2b124d0000df41bd5ad6e3991.jpg", - name: "你好", - userId: 1000001, - sortId: 1, - address: "浙江省杭州市西湖区", - content: "我是一个超长超长的文字啊", - addtime: "2021-8-7 23:00:00", - }, + ], // 总记录数 total: 0, @@ -129,8 +109,6 @@ export default { btnSubmitVisible: true, // 表单校验 rules: { - name: [{ required: true, message: "名称不能为空", trigger: "blur" }], - userId: [{ required: true, message: "id不能为空", trigger: "blur" }], }, }; }, @@ -223,14 +201,9 @@ export default { this.title = "详情"; // TODO 给表单赋值 this.form = { - content: row.content, - userId: row.userId, - name: row.name, - sortId: row.sortId, + }; }, - handleImport() {}, - handleExport() {}, }, }; diff --git a/ZR.Vue/src/views/tool/gen/index.vue b/ZR.Vue/src/views/tool/gen/index.vue index 77f0796..cbdba71 100644 --- a/ZR.Vue/src/views/tool/gen/index.vue +++ b/ZR.Vue/src/views/tool/gen/index.vue @@ -16,7 +16,7 @@ 导入 - 删除 + 删除 @@ -33,9 +33,9 @@ diff --git a/document/admin-mysql.sql b/document/admin-mysql.sql index 720e652..4ec413d 100644 --- a/document/admin-mysql.sql +++ b/document/admin-mysql.sql @@ -251,7 +251,7 @@ INSERT INTO sys_menu VALUES (103, '部门管理', 1, 4, 'dept', 'system/dept/ind INSERT INTO sys_menu VALUES (104, '岗位管理', 1, 5, 'post', 'system/post/index', 0, 0, 'C', '0', '0', 'system:post:list', 'post', '', SYSDATE(), '', NULL, '岗位管理菜单'); INSERT INTO sys_menu VALUES (108, '日志管理', 1, 9, 'log', '', 0, 0, 'M', '0', '0', '', 'log', '', SYSDATE(), '', NULL, '日志管理菜单'); INSERT INTO sys_menu VALUES (105, '字典管理', 1, 5, 'dict', 'system/dict/index', 0, 0, 'C', '0', '0', 'system:dict:list', 'dict', '', SYSDATE(), '', NULL, ''); -INSERT INTO sys_menu VALUES (106, '分配用户', 1, 3, 'roleusers', 'system/roleusers/index', 0, 0, 'C', '0', '0', 'system:role:list', 'people', '', SYSDATE(), '', NULL, NULL); +INSERT INTO sys_menu VALUES (106, '权限分配', 1, 3, 'roleusers', 'system/roleusers/index', 0, 0, 'C', '0', '0', 'system:role:list', 'people', '', SYSDATE(), '', NULL, NULL); -- 一级菜单 缓存监控 INSERT INTO sys_menu VALUES (113, '缓存监控', 2, 5, 'cache', 'monitor/cache/index', 0, 0, 'C', '1', '1', 'monitor:cache:list', 'redis', '', SYSDATE(), '', NULL, '缓存监控菜单'); @@ -260,8 +260,7 @@ INSERT INTO sys_menu VALUES (113, '缓存监控', 2, 5, 'cache', 'monitor/cache/ INSERT INTO sys_menu VALUES (114, '表单构建', 3, 1, 'build', 'tool/build/index', 0, 0, 'C', '0', '0', 'tool:build:list', 'build', '', SYSDATE(), '', NULL, '表单构建菜单'); INSERT INTO sys_menu VALUES (115, '代码生成', 3, 1, 'gen', 'tool/gen/index', 0, 0, 'C', '0', '0', 'tool:gen:list', 'code', '', SYSDATE(), '', NULL, '代码生成菜单'); INSERT INTO sys_menu VALUES (116, '系统接口', 3, 3, 'swagger', 'tool/swagger/index', 0, 0, 'C', '0', '0', 'tool:swagger:list', 'swagger', '', SYSDATE(), '', NULL, '系统接口菜单'); -INSERT INTO sys_menu VALUES (117, '编辑表格', 3, 3, 'editTable', 'tool/gen/editTable', 0, 0, 'C', '1', '0', 'tool:gen:edittable', '', '', SYSDATE(), '', NULL, '代码生成编辑表格菜单'); - +INSERT INTO sys_menu VALUES (117, '发送邮件', 3, 4, '/sendEmail', 'tool/email/sendEmail', 0, 0, 'C', '0', '0', 'tool:email:send', 'message', '', GETDATE(), '', NULL, '发送邮件菜单'); -- 日志管理 INSERT INTO sys_menu VALUES (500, '操作日志', 108, 1, 'operlog', 'monitor/operlog/index', 0, 0, 'C', '0', '0', 'monitor:operlog:list', 'form', '', SYSDATE(), '', NULL, '操作日志菜单'); @@ -324,6 +323,13 @@ INSERT INTO sys_menu VALUES (2062, '新增', 2057, 1, '#', NULL, 0, 0, 'F', '0', INSERT INTO sys_menu VALUES (2063, '修改', 2057, 2, '#', NULL, 0, 0, 'F', '0', '0', 'system:article:update', '', '', SYSDATE(), '', NULL, NULL); INSERT INTO sys_menu VALUES (2064, '删除', 2057, 3, '#', NULL, 0, 0, 'F', '0', '0', 'system:article:delete', '', '', SYSDATE(), '', NULL, NULL); +--代码生成页面权限 +INSERT INTO sys_menu(menuId, menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time) VALUES (2070, '编辑', 115, 1, '#', NULL, 0, 0, 'F', '0', '0', 'tool:ten:edit', '', '', GETDATE()); +INSERT INTO sys_menu(menuId, menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time) VALUES (2071, '预览', 115, 1, '#', NULL, 0, 0, 'F', '0', '0', 'tool:ten:preview', '', '', GETDATE()); +INSERT INTO sys_menu(menuId, menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time) VALUES (2072, '删除', 115, 1, '#', NULL, 0, 0, 'F', '0', '0', 'tool:ten:remove', '', '', GETDATE()); +INSERT INTO sys_menu(menuId, menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time) VALUES (2073, '导入', 115, 1, '#', NULL, 0, 0, 'F', '0', '0', 'tool:ten:import', '', '', GETDATE()); +INSERT INTO sys_menu(menuId, menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time) VALUES (2074, '生成代码', 115, 1, '#', NULL, 0, 0, 'F', '0', '0', 'tool:ten:code', '', '', GETDATE()); + -- ---------------------------- -- Table structure for sys_oper_log diff --git a/document/admin-sqlserver.sql b/document/admin-sqlserver.sql index 28ac3d6e474386bc1bef82c887ef8ddbebed06a3..1dc23ef6fd0f129eec2fb90ea98accbaf5a14dc6 100644 GIT binary patch delta 1950 zcmZvce@t6d6vyv%+97UB)09#x!v+ZmVGhuM!Jnx!CjP;2HZO}#evMKXFv$jP&Sf-{ z7#0;vkK1inhGx-e$X1Gvl&#LCX%?KOAxx$rOr4@38VzZPqA_)P@4NTD_Ym`v=6&w> ze9t}SynB20f+a9yiQeLZqXTyJaaR(<7vnCd%ipAW^UiCa*5yxOC`h=V{#A?G=)R-_ zG`h3Y?t+-UpmrDjM-3EF_2_^T2Ft7vDB7f+xc5V2i(u(RO;rcWW}c#94hU|uK)h#I zZSH>*gDvF%>w)(;(E4ES%R*t0d?jWmrAIEQ*1md~+5*#o8Lslezm}n_lC02cI;Rbx z{Pj5lrrr!0;0T(OcSC743UsT=Q%-0-E))hCl7}nd&hR0L`kq_-fE$B(qg_=-1>ZA_t>p?HlrxR_Z5mNh~c=&$!kzymF zM$ahobW#6)`ZOUwY(I7nSo`wS=t&RjD5EMPUiMAwaPyrNIRU#GIc>*k^tu*9yLx|u zOSY5~Rz64=O84lm>r2o>Xd}vo@yZf4aoEAXN#VIDx3J?iFs8$_vFe?O7!Zq%a$w)j ze&MVEJs%4*Q|3O=;ffJ5k`(5J%Ts*S^XcdO#g=kG;{#Tdq6+2sK3w?g5#Ru>1wKn&Lo5>b*`|ilwPx$LjsDa)Zt;*bLR4y)# zqi^Ufe)ua;1?jWk?XYw_n^bMa59)i+@Cp&$AHH&IZFo+Pb}?&EH`+(vUZPjihYrAa zszlGRt{PRs*o_<#u;5y@#ci4g@ZUM$+LaB#t4=+Z?#FL_G0HseduHu^!u!uyE@Woi zy6>)PB>yW|^K1xfz3WA-a4MV&iIhv;$;qM3_~c_`upHY+$dA2b^aX6?xUU}XAXW8L z&{T>oBCY`|L}`#hr~$W`ghP!cK_MHOR^iBMEN@<=CUq=mp?i3DOI5=~Gm0%WA=@Y8 zw3@>{?9gl8K}uUC(n=MQXvKED+?_=6OD}DIj}ZKLCppq)5)@)>m$rp=s-9_=Dn-Ml xkklR#2hrF7{||XtYL1LTD8^QI4!O#B}!V&Bw=Qn%&;YcLR)Hi69!6TGy4FMj!Ytg zTZS2Nu%kQb7DA0Wf*mPbQeVOtu=$qGKrs`y;gB&lMwX@$LWpj0_uOl?ed)c={nCW= z_y0ft^PK0ox8ZQBCU993Tw)|coQ?!FiR4XF!n4(=0=6q zseimCbWbnSECU&-Zl}3xu`%gU-NYgPLCt}v&r@pQ8!l|evf8S!fd(^i0=aSEe+CiX z7khvP*tm+ez9fY3Nv)F$XRdm z?(ka3M6-!+KKP2fUTStCnXMZUJrYxD(#u(^$Vg_Ia(TPiL{`_|k))$Xs~h3cNUDis zHH=Hr@gp8LT*^WpI&xQ%&a}*&P$vz1@I*?Bvvc6m!4EG;6{jo4O5rjVcIc>BaVMmq z!tj3-6D~i6pK0Euba@7nckD+gRb`XM{rEc8wN(_(Z94?w#~ENxPyxzlg1tq_v*($ZK0`4dnQ#c`5R(y~R1~ zHeitjDL?+14vSino00Gg(@J%h`(Kr>Yd0H6W?M+Ad%9?$;*rDeg4H!W=15+9zj&uc ze};0Mx6eeyI;)cQ`Cb3^23gU|C)I@`lMfFsv`UJZS%L+k_4d$cpC zBFWuA07wsZT?dkOGe_(R9vJmQ2K`&l{_G9u&80cFSUPG3AbwvfO z`x@F0=Dm8bSA}=-H_&Nf-f35d#6?=X>XKh12A5xFTL*ZJGT3($4Bv+BGIMRa6@W)* zAMSy}9g!|L9Jn2X!#&@ta1M>BaPIp7c);#^9J%%rFh=*io3O(%*U^byIQ;XZ3V3!3 z*a;S6ZW??zjx7Fu37$D|Rz(c$p965`l&G|Ob5X_J<48#ic)+SKNA}JEGdt&pg}f=e z;(N4gf&GF8fUJDe;sUG-0?glen1Eq4d+~4n8#wW%$Ly)1{H&sOjA0}Z>Kk4{8_{}X zLHhdEk1LzDRa(Tqw-EemHogBe*3tQ=u#I(!*s8W&^gV|Qx09H58JCVWAsb2;w05)= zWuPr+^OH{toqPjVKp;2m%)&Ytxjq{}b~~__o`#SQ+_-@19ayVaUGzNWfK`7BX4jYl zv-8rwz@#r1=INo)T)YyJ(?ctrQ1TZrS?mIMHn^~ID+S0)R|0RwOTTji3JY_wU$Hln z9-;8Jc>p_++~I+eeLxZvv4Dnl0Y*ZMX!9yZB+LDq=;18<0{hp+QW^wEs54*a)W&>e eb4DtkN`MOJiv@sFi6m&v%C_R&7n2KdN!mZHK(NvP From 21a25ae479ce221eb7d97d6a484deba5a38d8e94 Mon Sep 17 00:00:00 2001 From: izory <791736813@qq.com> Date: Tue, 28 Sep 2021 18:19:33 +0800 Subject: [PATCH 06/21] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=8A=A0=E5=9F=BA?= =?UTF-8?q?=E7=A1=80=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- document/admin-mysql.sql | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/document/admin-mysql.sql b/document/admin-mysql.sql index 4ec413d..7748466 100644 --- a/document/admin-mysql.sql +++ b/document/admin-mysql.sql @@ -324,11 +324,11 @@ INSERT INTO sys_menu VALUES (2063, '修改', 2057, 2, '#', NULL, 0, 0, 'F', '0', INSERT INTO sys_menu VALUES (2064, '删除', 2057, 3, '#', NULL, 0, 0, 'F', '0', '0', 'system:article:delete', '', '', SYSDATE(), '', NULL, NULL); --代码生成页面权限 -INSERT INTO sys_menu(menuId, menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time) VALUES (2070, '编辑', 115, 1, '#', NULL, 0, 0, 'F', '0', '0', 'tool:ten:edit', '', '', GETDATE()); -INSERT INTO sys_menu(menuId, menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time) VALUES (2071, '预览', 115, 1, '#', NULL, 0, 0, 'F', '0', '0', 'tool:ten:preview', '', '', GETDATE()); -INSERT INTO sys_menu(menuId, menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time) VALUES (2072, '删除', 115, 1, '#', NULL, 0, 0, 'F', '0', '0', 'tool:ten:remove', '', '', GETDATE()); -INSERT INTO sys_menu(menuId, menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time) VALUES (2073, '导入', 115, 1, '#', NULL, 0, 0, 'F', '0', '0', 'tool:ten:import', '', '', GETDATE()); -INSERT INTO sys_menu(menuId, menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time) VALUES (2074, '生成代码', 115, 1, '#', NULL, 0, 0, 'F', '0', '0', 'tool:ten:code', '', '', GETDATE()); +INSERT INTO sys_menu(menuId, menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time) VALUES (2070, '编辑', 115, 1, '#', NULL, 0, 0, 'F', '0', '0', 'tool:ten:edit', '', '', SYSDATE()); +INSERT INTO sys_menu(menuId, menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time) VALUES (2071, '预览', 115, 1, '#', NULL, 0, 0, 'F', '0', '0', 'tool:ten:preview', '', '', SYSDATE()); +INSERT INTO sys_menu(menuId, menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time) VALUES (2072, '删除', 115, 1, '#', NULL, 0, 0, 'F', '0', '0', 'tool:ten:remove', '', '', SYSDATE()); +INSERT INTO sys_menu(menuId, menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time) VALUES (2073, '导入', 115, 1, '#', NULL, 0, 0, 'F', '0', '0', 'tool:ten:import', '', '', SYSDATE()); +INSERT INTO sys_menu(menuId, menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time) VALUES (2074, '生成代码', 115, 1, '#', NULL, 0, 0, 'F', '0', '0', 'tool:ten:code', '', '', SYSDATE()); -- ---------------------------- From 1d9ebbb677411779f5ac8b06183e08bca8bb49a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=81=9A=E7=A0=81=E5=86=9C?= <599854767@qq.com> Date: Wed, 29 Sep 2021 08:19:14 +0800 Subject: [PATCH 07/21] update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 77e1de2..243562e 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ Vue版前端技术栈 :基于vue、vuex、vue-router 、vue-cli 、axios 和 e - [ ] 参数管理 - [ ] 在线用户 - [ ] 文件管理 -- [ ] 邮件发送 +- [X] 邮件发送 - [ ] 集成微信开发 ## 📖 帮助文档 From b69ade5904a00d6df5ebcaf11e74605397aa159b Mon Sep 17 00:00:00 2001 From: izory <791736813@qq.com> Date: Wed, 29 Sep 2021 11:23:43 +0800 Subject: [PATCH 08/21] =?UTF-8?q?=E4=BF=AE=E6=94=B9sql=E5=9F=BA=E7=A1=80?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- document/admin-mysql.sql | 14 +++++++------- document/admin-sqlserver.sql | Bin 100480 -> 100542 bytes 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/document/admin-mysql.sql b/document/admin-mysql.sql index 7748466..ef41570 100644 --- a/document/admin-mysql.sql +++ b/document/admin-mysql.sql @@ -260,7 +260,8 @@ INSERT INTO sys_menu VALUES (113, '缓存监控', 2, 5, 'cache', 'monitor/cache/ INSERT INTO sys_menu VALUES (114, '表单构建', 3, 1, 'build', 'tool/build/index', 0, 0, 'C', '0', '0', 'tool:build:list', 'build', '', SYSDATE(), '', NULL, '表单构建菜单'); INSERT INTO sys_menu VALUES (115, '代码生成', 3, 1, 'gen', 'tool/gen/index', 0, 0, 'C', '0', '0', 'tool:gen:list', 'code', '', SYSDATE(), '', NULL, '代码生成菜单'); INSERT INTO sys_menu VALUES (116, '系统接口', 3, 3, 'swagger', 'tool/swagger/index', 0, 0, 'C', '0', '0', 'tool:swagger:list', 'swagger', '', SYSDATE(), '', NULL, '系统接口菜单'); -INSERT INTO sys_menu VALUES (117, '发送邮件', 3, 4, '/sendEmail', 'tool/email/sendEmail', 0, 0, 'C', '0', '0', 'tool:email:send', 'message', '', GETDATE(), '', NULL, '发送邮件菜单'); +INSERT INTO sys_menu VALUES (117, '发送邮件', 3, 4, '/sendEmail', 'tool/email/sendEmail', 0, 0, 'C', '0', '0', 'tool:email:send', 'message', '', SYSDATE(), '', NULL, '发送邮件菜单'); +INSERT INTO sys_menu VALUES (118, '编辑表格', 3, 5, '/tool/gen/editTable', 'tool/gen/editTable', 0, 0, 'C', '1', '0', 'tool:gen:edit', '', '', SYSDATE(), '', NULL, ''); -- 日志管理 INSERT INTO sys_menu VALUES (500, '操作日志', 108, 1, 'operlog', 'monitor/operlog/index', 0, 0, 'C', '0', '0', 'monitor:operlog:list', 'form', '', SYSDATE(), '', NULL, '操作日志菜单'); @@ -324,11 +325,10 @@ INSERT INTO sys_menu VALUES (2063, '修改', 2057, 2, '#', NULL, 0, 0, 'F', '0', INSERT INTO sys_menu VALUES (2064, '删除', 2057, 3, '#', NULL, 0, 0, 'F', '0', '0', 'system:article:delete', '', '', SYSDATE(), '', NULL, NULL); --代码生成页面权限 -INSERT INTO sys_menu(menuId, menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time) VALUES (2070, '编辑', 115, 1, '#', NULL, 0, 0, 'F', '0', '0', 'tool:ten:edit', '', '', SYSDATE()); -INSERT INTO sys_menu(menuId, menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time) VALUES (2071, '预览', 115, 1, '#', NULL, 0, 0, 'F', '0', '0', 'tool:ten:preview', '', '', SYSDATE()); -INSERT INTO sys_menu(menuId, menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time) VALUES (2072, '删除', 115, 1, '#', NULL, 0, 0, 'F', '0', '0', 'tool:ten:remove', '', '', SYSDATE()); -INSERT INTO sys_menu(menuId, menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time) VALUES (2073, '导入', 115, 1, '#', NULL, 0, 0, 'F', '0', '0', 'tool:ten:import', '', '', SYSDATE()); -INSERT INTO sys_menu(menuId, menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time) VALUES (2074, '生成代码', 115, 1, '#', NULL, 0, 0, 'F', '0', '0', 'tool:ten:code', '', '', SYSDATE()); +INSERT INTO sys_menu(menuId, menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time) VALUES (2071, '预览', 115, 1, '#', NULL, 0, 0, 'F', '0', '0', 'tool:gen:preview', '', '', SYSDATE()); +INSERT INTO sys_menu(menuId, menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time) VALUES (2072, '删除', 115, 1, '#', NULL, 0, 0, 'F', '0', '0', 'tool:gen:remove', '', '', SYSDATE()); +INSERT INTO sys_menu(menuId, menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time) VALUES (2073, '导入', 115, 1, '#', NULL, 0, 0, 'F', '0', '0', 'tool:gen:import', '', '', SYSDATE()); +INSERT INTO sys_menu(menuId, menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time) VALUES (2074, '生成代码', 115, 1, '#', NULL, 0, 0, 'F', '0', '0', 'tool:gen:code', '', '', SYSDATE()); -- ---------------------------- @@ -517,7 +517,7 @@ CREATE TABLE `sys_user` ( -- Records of sys_user -- ---------------------------- INSERT INTO `sys_user` VALUES (1, 0, 'admin', '管理员', '0', '', '', '0', '', 'e10adc3949ba59abbe56e057f20f883e', '0', '0', '127.0.0.1', '2021-08-23 14:03:17', 'admin', '2020-11-26 11:52:59', 'admin', '2021-08-03 10:11:24', '管理员'); -INSERT INTO `sys_user` VALUES (2, 200, 'zr', 'zr', '0', NULL, NULL, '0', '', 'e10adc3949ba59abbe56e057f20f883e', '0', '0', '', '0001-01-01 00:00:00', 'admin', '2021-07-05 17:29:13', 'admin', '2021-08-02 16:53:04', '普通用户2'); +INSERT INTO `sys_user` VALUES (2, 0, 'zr', 'zr', '0', NULL, NULL, '0', '', 'e10adc3949ba59abbe56e057f20f883e', '0', '0', '', '0001-01-01 00:00:00', 'admin', '2021-07-05 17:29:13', 'admin', '2021-08-02 16:53:04', '普通用户2'); INSERT INTO `sys_user` VALUES (3, 100, 'editor', '编辑人员', '0', NULL, NULL, '2', 'http://www.izhaorui.cn/static/pay.jpg', 'E10ADC3949BA59ABBE56E057F20F883E', '0', '0', '127.0.0.1', '2021-08-19 09:27:46', 'admin', '2021-08-18 18:24:53', '', NULL, NULL); SET FOREIGN_KEY_CHECKS = 1; diff --git a/document/admin-sqlserver.sql b/document/admin-sqlserver.sql index 1dc23ef6fd0f129eec2fb90ea98accbaf5a14dc6..10ea56efb1c3a6901ac4a8f6c8b821196e7d13e7 100644 GIT binary patch delta 195 zcmZpe$hL1H+lCucHybqhFnSv@STN`?C@`oqh}BQ*&*-qpPzUpk!K5ivPM@KKAs+~H z81xy^8B!VYfOIND3PUDPJcJ>UAqgmxI(h8`X+ccUk3Wp3KVW6#n#?zmWBM0nMvKV_ zi&>@%Ffp=helT@j?(`Z~#ypVR_D`≥C26Z|sb}AgmvpjQ=34f82~el(+xVXKafA E09^Aqvj6}9 delta 118 zcmdltk*#4O+lCucCofpaGChEWk!7>OjCr{{1`Ik33JmHDV)YaIr(fV?OkymVd~>?} zW`$#ZjMMk9G8QnFY}aLDWM%@=h8&EHOuQuwsSJ4xRt%X8xeNu98Bdr))E?nxECH&q Swg> Date: Wed, 29 Sep 2021 11:24:16 +0800 Subject: [PATCH 09/21] fix bug --- ZR.Admin.WebApi/wwwroot/CodeGenTemplate/RepositoryTemplate.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/RepositoryTemplate.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/RepositoryTemplate.txt index c2c5392..a073a0c 100644 --- a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/RepositoryTemplate.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/RepositoryTemplate.txt @@ -12,7 +12,7 @@ namespace {RepositoriesNamespace} /// @date {DateTime} /// [AppService(ServiceLifetime = LifeTime.Transient)] - public class {ModelTypeName}Repository : BaseRepository + public class {ModelTypeName}Repository : BaseRepository<{ModelTypeName}> { #region 业务逻辑代码 #endregion From 2b263fb64d35abd04fc31f5e6bddb5073fdd5b1b Mon Sep 17 00:00:00 2001 From: izory <791736813@qq.com> Date: Wed, 29 Sep 2021 11:24:38 +0800 Subject: [PATCH 10/21] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E7=94=9F=E6=88=90=E7=BC=96=E8=BE=91=E8=A1=A8=E6=A0=BC=E8=B7=B3?= =?UTF-8?q?=E8=BD=AC=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ZR.Vue/src/views/tool/gen/index.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ZR.Vue/src/views/tool/gen/index.vue b/ZR.Vue/src/views/tool/gen/index.vue index cbdba71..4dcc7ec 100644 --- a/ZR.Vue/src/views/tool/gen/index.vue +++ b/ZR.Vue/src/views/tool/gen/index.vue @@ -160,7 +160,7 @@ export default { */ handleEditTable(row) { console.log(row); - this.$router.push("/tool/editTable?tableId=" + row.tableId); + this.$router.push("/tool/gen/editTable?tableId=" + row.tableId); }, // 代码预览 handlePreview(row) { From 2b10934e09d04a4c0df35c094676e149af56ca8b Mon Sep 17 00:00:00 2001 From: izory <791736813@qq.com> Date: Wed, 29 Sep 2021 15:57:56 +0800 Subject: [PATCH 11/21] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=8A=A0=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/System/SysConfigController.cs | 162 ++++++++++++++++- .../System/SysProfileController.cs | 4 +- ZR.Admin.WebApi/Extensions/EntityExtension.cs | 4 +- .../CodeGenTemplate/ControllersTemplate.txt | 11 +- .../CodeGenTemplate/ServiceTemplate.txt | 7 - .../Service/CodeGeneraterService.cs | 2 +- .../src/layout/components/Settings/index.vue | 167 ++++++++++++++---- ZR.Vue/src/layout/index.vue | 4 +- ZR.Vue/src/main.js | 10 +- ZR.Vue/src/settings.js | 6 +- ZR.Vue/src/store/modules/settings.js | 16 +- ZR.Vue/src/utils/request.js | 4 +- ZR.Vue/src/views/system/user/index.vue | 6 +- ZRAdmin.xml | 50 +++++- document/admin-sqlserver.sql | Bin 100542 -> 104524 bytes 15 files changed, 378 insertions(+), 75 deletions(-) diff --git a/ZR.Admin.WebApi/Controllers/System/SysConfigController.cs b/ZR.Admin.WebApi/Controllers/System/SysConfigController.cs index a29eccd..55425f6 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysConfigController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysConfigController.cs @@ -1,23 +1,169 @@ -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; -using System.Linq; 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; +using ZR.Service.System; +using ZR.Model.System; +using Infrastructure.Extensions; -namespace ZR.Admin.WebApi.Controllers.System +namespace ZR.Admin.WebApi.Controllers { /// - /// 配置文件 + /// 参数配置Controller + /// + /// @author zhaorui + /// @date 2021-09-29 /// [Verify] [Route("system/config")] public class SysConfigController : BaseController { - [HttpGet("list")] - public IActionResult Index() + /// + /// 参数配置接口 + /// + private readonly ISysConfigService _SysConfigService; + + public SysConfigController(ISysConfigService SysConfigService) { - return SUCCESS(1); + _SysConfigService = SysConfigService; + } + + /// + /// 查询参数配置列表 + /// + /// + [HttpGet("list")] + [ActionPermissionFilter(Permission = "system:config:list")] + public IActionResult QuerySysConfig([FromQuery] SysConfigQueryDto parm) + { + //开始拼装查询条件 + var predicate = Expressionable.Create(); + + //TODO 搜索条件 + predicate = predicate.AndIF(!parm.ConfigType.IsEmpty(),m => m.ConfigType == parm.ConfigType); + predicate = predicate.AndIF(!parm.ConfigName.IsEmpty(),m => m.ConfigName.Contains(parm.ConfigType)); + predicate = predicate.AndIF(!parm.ConfigKey.IsEmpty(),m => m.ConfigKey.Contains(parm.ConfigKey)); + predicate = predicate.AndIF(!parm.BeginTime.IsEmpty(),m => m.Create_time >= parm.BeginTime ); + predicate = predicate.AndIF(!parm.BeginTime.IsEmpty(),m => m.Create_time <= parm.EndTime); + + var response = _SysConfigService.GetPages(predicate.ToExpression(), parm); + + return SUCCESS(response); + } + + /// + /// 查询参数配置详情 + /// + /// + /// + [HttpGet("{ConfigId}")] + [ActionPermissionFilter(Permission = "system:config:query")] + public IActionResult GetSysConfig(int ConfigId) + { + var response = _SysConfigService.GetId(ConfigId); + + return SUCCESS(response); + } + + /// + /// 根据参数键名查询参数值 + /// + /// + /// + [HttpGet("configKey/{configKey}")] + public IActionResult GetConfigKey(string configKey) + { + //TODO 增加缓存 + var response = _SysConfigService.Queryable().First(f=> f.ConfigKey == configKey); + + return SUCCESS(response?.ConfigValue); + } + + /// + /// 添加参数配置 + /// + /// + [HttpPost] + [ActionPermissionFilter(Permission = "system:config:add")] + [Log(Title = "参数配置添加", BusinessType = BusinessType.INSERT)] + public IActionResult AddSysConfig([FromBody] SysConfigDto parm) + { + if (parm == null) + { + throw new CustomException("请求参数错误"); + } + //从 Dto 映射到 实体 + var model = parm.Adapt().ToCreate(); + + return SUCCESS(_SysConfigService.Add(model, it => new + { + it.ConfigName, + it.ConfigKey, + it.ConfigValue, + it.ConfigType, + it.Create_by, + it.Create_time, + it.Remark, + })); + } + + /// + /// 更新参数配置 + /// + /// + [HttpPut] + [ActionPermissionFilter(Permission = "system:config:update")] + [Log(Title = "参数配置修改", BusinessType = BusinessType.UPDATE)] + public IActionResult UpdateSysConfig([FromBody] SysConfigDto parm) + { + if (parm == null) + { + throw new CustomException("请求实体不能为空"); + } + //从 Dto 映射到 实体 + var model = parm.Adapt().ToUpdate(HttpContext); + + var response = _SysConfigService.Update(w => w.ConfigId == model.ConfigId, it => new SysConfig() + { + //Update 字段映射 + ConfigName = model.ConfigName, + ConfigKey = model.ConfigKey, + ConfigValue = model.ConfigValue, + ConfigType = model.ConfigType, + Update_by = model.Update_by, + Update_time = model.Update_time, + }); + + return SUCCESS(response); + } + + /// + /// 删除参数配置 + /// + /// + [HttpDelete("{ids}")] + [ActionPermissionFilter(Permission = "system:config:remove")] + [Log(Title = "参数配置删除", BusinessType = BusinessType.DELETE)] + public IActionResult DeleteSysConfig(string ids) + { + int[] idsArr = Tools.SpitIntArrary(ids); + if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); } + + var response = _SysConfigService.Delete(idsArr); + + return SUCCESS(response); } } -} +} \ No newline at end of file diff --git a/ZR.Admin.WebApi/Controllers/System/SysProfileController.cs b/ZR.Admin.WebApi/Controllers/System/SysProfileController.cs index 2ef8337..c846d5a 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysProfileController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysProfileController.cs @@ -79,9 +79,7 @@ namespace ZR.Admin.WebApi.Controllers.System throw new CustomException(ResultCode.PARAM_ERROR, "请求参数错误"); } //从 Dto 映射到 实体 - var user = userDto.Adapt(); - user.Update_by = User.Identity.Name; - user.Update_time = DateTime.Now; + var user = userDto.Adapt().ToUpdate(HttpContext); int result = UserService.ChangeUser(user); return ToResponse(result); diff --git a/ZR.Admin.WebApi/Extensions/EntityExtension.cs b/ZR.Admin.WebApi/Extensions/EntityExtension.cs index 879a258..1ec762a 100644 --- a/ZR.Admin.WebApi/Extensions/EntityExtension.cs +++ b/ZR.Admin.WebApi/Extensions/EntityExtension.cs @@ -57,9 +57,9 @@ namespace ZR.Admin.WebApi.Extensions { types.GetProperty("UpdateTime").SetValue(source, DateTime.Now, null); } - if (types.GetProperty("Update_Time") != null) + if (types.GetProperty("Update_time") != null) { - types.GetProperty("Update_Time").SetValue(source, DateTime.Now, null); + types.GetProperty("Update_time").SetValue(source, DateTime.Now, null); } //if (types.GetProperty("UpdateID") != null) //{ diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/ControllersTemplate.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/ControllersTemplate.txt index 3a5d41c..e4ac42d 100644 --- a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/ControllersTemplate.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/ControllersTemplate.txt @@ -14,6 +14,7 @@ using {ServicesNamespace}.Business; using {ApiControllerNamespace}.Extensions; using {ApiControllerNamespace}.Filters; using ZR.Common; +using Infrastructure.Extensions; namespace {ApiControllerNamespace}.Controllers { @@ -76,7 +77,7 @@ namespace {ApiControllerNamespace}.Controllers /// [HttpPost] [ActionPermissionFilter(Permission = "{Permission}:add")] - [Log(Title = "{TableDesc}添加", BusinessType = BusinessType.INSERT)] + [Log(Title = "{FunctionName}添加", BusinessType = BusinessType.INSERT)] public IActionResult Add{ModelName}([FromBody] {ModelName}Dto parm) { if (parm == null) @@ -84,7 +85,7 @@ namespace {ApiControllerNamespace}.Controllers throw new CustomException("请求参数错误"); } //从 Dto 映射到 实体 - var model = parm.Adapt<{ModelName}>().ToCreate(); + var model = parm.Adapt<{ModelName}>().ToCreate(HttpContext); return SUCCESS(_{ModelName}Service.Add(model, it => new { @@ -98,7 +99,7 @@ namespace {ApiControllerNamespace}.Controllers /// [HttpPut] [ActionPermissionFilter(Permission = "{Permission}:update")] - [Log(Title = "{TableDesc}修改", BusinessType = BusinessType.UPDATE)] + [Log(Title = "{FunctionName}修改", BusinessType = BusinessType.UPDATE)] public IActionResult Update{ModelName}([FromBody] {ModelName}Dto parm) { if (parm == null) @@ -106,7 +107,7 @@ namespace {ApiControllerNamespace}.Controllers throw new CustomException("请求实体不能为空"); } //从 Dto 映射到 实体 - var model = parm.Adapt<{ModelName}>().ToUpdate(); + var model = parm.Adapt<{ModelName}>().ToUpdate(HttpContext); var response = _{ModelName}Service.Update(w => w.{PrimaryKey} == model.{PrimaryKey}, it => new {ModelName}() { @@ -123,7 +124,7 @@ namespace {ApiControllerNamespace}.Controllers /// [HttpDelete("{ids}")] [ActionPermissionFilter(Permission = "{Permission}:delete")] - [Log(Title = "{TableDesc}删除", BusinessType = BusinessType.DELETE)] + [Log(Title = "{FunctionName}删除", BusinessType = BusinessType.DELETE)] public IActionResult Delete{ModelName}(string ids) { int[] idsArr = Tools.SpitIntArrary(ids); diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/ServiceTemplate.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/ServiceTemplate.txt index 1892b2f..fe7121a 100644 --- a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/ServiceTemplate.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/ServiceTemplate.txt @@ -1,12 +1,5 @@ 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 {ModelsNamespace}.Models; using {IRepositoriesNamespace}; diff --git a/ZR.CodeGenerator/Service/CodeGeneraterService.cs b/ZR.CodeGenerator/Service/CodeGeneraterService.cs index 1e5612d..b0fcbe7 100644 --- a/ZR.CodeGenerator/Service/CodeGeneraterService.cs +++ b/ZR.CodeGenerator/Service/CodeGeneraterService.cs @@ -33,7 +33,7 @@ namespace ZR.CodeGenerator.Service { tableList = tableList.Where(f => f.Name.ToLower().Contains(tableName.ToLower())).ToList(); } - tableList = tableList.Where(f => !new string[] { "gen", "sys_" }.Contains(f.Name)).ToList(); + //tableList = tableList.Where(f => !new string[] { "gen", "sys_" }.Contains(f.Name)).ToList(); pager.TotalNum = tableList.Count; return tableList.Skip(pager.PageSize * (pager.PageNum - 1)).Take(pager.PageSize).OrderBy(f => f.Name).ToList(); } diff --git a/ZR.Vue/src/layout/components/Settings/index.vue b/ZR.Vue/src/layout/components/Settings/index.vue index 90d99df..5079b8e 100644 --- a/ZR.Vue/src/layout/components/Settings/index.vue +++ b/ZR.Vue/src/layout/components/Settings/index.vue @@ -1,13 +1,38 @@ + diff --git a/ZR.Vue/src/layout/index.vue b/ZR.Vue/src/layout/index.vue index 889b7dc..97c78ef 100644 --- a/ZR.Vue/src/layout/index.vue +++ b/ZR.Vue/src/layout/index.vue @@ -1,5 +1,5 @@ From 43a00c78bed78ec0701d1f21714c6f4f9dde560d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=81=9A=E7=A0=81=E5=86=9C?= <599854767@qq.com> Date: Fri, 8 Oct 2021 21:22:35 +0800 Subject: [PATCH 14/21] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E5=89=8D=E7=BC=80=E5=90=8Dkey=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ZR.Vue/.env.development | 6 ++---- ZR.Vue/.env.production | 2 +- ZR.Vue/src/router/index.js | 3 ++- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/ZR.Vue/.env.development b/ZR.Vue/.env.development index b6be2a4..2028595 100644 --- a/ZR.Vue/.env.development +++ b/ZR.Vue/.env.development @@ -1,11 +1,9 @@ +# 关于此文件说明 必须以VUE_APP开头 # 开发环境配置 ENV = 'development' # ZR管理系统/开发环境 VUE_APP_BASE_API = 'http://localhost:8888/' -# 路由懒加载 -VUE_CLI_BABEL_TRANSPILE_MODULES = true - # 路由前缀 -VUE_ROUTER_PREFIX = '/' +VUE_APP_ROUTER_PREFIX = '' diff --git a/ZR.Vue/.env.production b/ZR.Vue/.env.production index 08c684f..dc272e2 100644 --- a/ZR.Vue/.env.production +++ b/ZR.Vue/.env.production @@ -5,4 +5,4 @@ ENV = 'production' VUE_APP_BASE_API = '/prod-api' # 路由前缀 -VUE_ROUTER_PREFIX = '/' +VUE_APP_ROUTER_PREFIX = '' diff --git a/ZR.Vue/src/router/index.js b/ZR.Vue/src/router/index.js index b2aa8da..bec7dfb 100644 --- a/ZR.Vue/src/router/index.js +++ b/ZR.Vue/src/router/index.js @@ -110,6 +110,7 @@ export const constantRoutes = [ export default new Router({ mode: 'history', // 去掉url中的# - scrollBehavior: () => ({ y: 0 }), + // base: '', + // scrollBehavior: () => ({ y: 0 }), routes: constantRoutes }) From 077e05ca36dd7841250f7579c43e8e6cae13cdf4 Mon Sep 17 00:00:00 2001 From: izory <791736813@qq.com> Date: Sat, 9 Oct 2021 10:19:20 +0800 Subject: [PATCH 15/21] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E4=B8=BB=E9=A2=98?= =?UTF-8?q?=E6=A0=B7=E5=BC=8F=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ZR.Vue/src/assets/styles/sidebar.scss | 53 ++++++++++++------- ZR.Vue/src/assets/styles/variables.scss | 41 ++++++++------ .../src/layout/components/Settings/index.vue | 11 +++- ZR.Vue/src/layout/components/Sidebar/Logo.vue | 42 ++++++++++----- .../src/layout/components/Sidebar/index.vue | 7 +-- ZR.Vue/src/layout/index.vue | 2 +- ZR.Vue/src/settings.js | 2 +- 7 files changed, 103 insertions(+), 55 deletions(-) diff --git a/ZR.Vue/src/assets/styles/sidebar.scss b/ZR.Vue/src/assets/styles/sidebar.scss index 17381fc..c33d71f 100644 --- a/ZR.Vue/src/assets/styles/sidebar.scss +++ b/ZR.Vue/src/assets/styles/sidebar.scss @@ -3,22 +3,26 @@ .main-container { min-height: 100%; transition: margin-left .28s; - margin-left: $sideBarWidth; + margin-left: $base-sidebar-width; position: relative; } .sidebar-container { + -webkit-transition: width .28s; transition: width 0.28s; - width: $sideBarWidth !important; - background-color: $menuBg; + width: $base-sidebar-width !important; + background-color: $base-menu-background; height: 100%; position: fixed; - font-size: 0; + font-size: 0px; top: 0; bottom: 0; left: 0; z-index: 1001; overflow: hidden; + // 有改动 + -webkit-box-shadow: 2px 0 7px rgba(0,21,41 , .15); + box-shadow: 2px 0 7px rgba(0,21,41 , .15); // reset element-ui css .horizontal-collapse-transition { @@ -30,7 +34,7 @@ } .el-scrollbar__bar.is-vertical { - right: 0; + right: 0px; } .el-scrollbar { @@ -63,25 +67,39 @@ width: 100% !important; } + .el-menu-item, .el-submenu__title { + overflow: hidden !important; + text-overflow: ellipsis !important; + white-space: nowrap !important; + } + // menu hover .submenu-title-noDropdown, .el-submenu__title { &:hover { - background-color: $menuHover !important; + background-color: rgba(0, 0, 0, 0.06) !important; } } - .is-active>.el-submenu__title { - color: $subMenuActiveText !important; + & .theme-dark .is-active > .el-submenu__title { + color: $base-menu-color-active !important; } & .nest-menu .el-submenu>.el-submenu__title, & .el-submenu .el-menu-item { - min-width: $sideBarWidth !important; - background-color: $subMenuBg !important; + min-width: $base-sidebar-width !important; &:hover { - background-color: $subMenuHover !important; + background-color: rgba(0, 0, 0, 0.06) !important; + } + } + + & .theme-dark .nest-menu .el-submenu>.el-submenu__title, + & .theme-dark .el-submenu .el-menu-item { + background-color: $base-sub-menu-background !important; + + &:hover { + background-color: $base-sub-menu-hover !important; } } } @@ -118,9 +136,6 @@ margin-left: 20px; } - .el-submenu__icon-arrow { - display: none; - } } } @@ -140,25 +155,25 @@ } .el-menu--collapse .el-menu .el-submenu { - min-width: $sideBarWidth !important; + min-width: $base-sidebar-width !important; } // mobile responsive .mobile { .main-container { - margin-left: 0; + margin-left: 0px; } .sidebar-container { transition: transform .28s; - width: $sideBarWidth !important; + width: $base-sidebar-width !important; } &.hideSidebar { .sidebar-container { pointer-events: none; transition-duration: 0.3s; - transform: translate3d(-$sideBarWidth, 0, 0); + transform: translate3d(-$base-sidebar-width, 0, 0); } } } @@ -184,7 +199,7 @@ .el-menu-item { &:hover { // you can use $subMenuHover - background-color: $menuHover !important; + background-color: rgba(0, 0, 0, 0.06) !important; } } diff --git a/ZR.Vue/src/assets/styles/variables.scss b/ZR.Vue/src/assets/styles/variables.scss index 5688f25..86ae632 100644 --- a/ZR.Vue/src/assets/styles/variables.scss +++ b/ZR.Vue/src/assets/styles/variables.scss @@ -8,28 +8,35 @@ $tiffany: #4AB7BD; $yellow:#FEC171; $panGreen: #30B08F; -// sidebar -$menuText:#bfcbd9; -$menuActiveText:#409EFF; -$subMenuActiveText:#f4f4f5; // https://github.com/ElemeFE/element/issues/12951 +// 默认菜单主题风格 +$base-menu-color:#bfcbd9; +$base-menu-color-active:#f4f4f5; +$base-menu-background:#304156; +$base-logo-title-color: #ffffff; -$menuBg:#304156; -$menuHover:#263445; +$base-menu-light-color:rgba(0,0,0,.70); +$base-menu-light-background:#ffffff; +$base-logo-light-title-color: #001529; -$subMenuBg:#1f2d3d; -$subMenuHover:#001528; +$base-sub-menu-background:#1f2d3d; +$base-sub-menu-hover:#001528; -$sideBarWidth: 200px; + + +$base-sidebar-width: 200px; // the :export directive is the magic sauce for webpack // https://www.bluematador.com/blog/how-to-share-variables-between-js-and-sass :export { - menuText: $menuText; - menuActiveText: $menuActiveText; - subMenuActiveText: $subMenuActiveText; - menuBg: $menuBg; - menuHover: $menuHover; - subMenuBg: $subMenuBg; - subMenuHover: $subMenuHover; - sideBarWidth: $sideBarWidth; + menuColor: $base-menu-color; + menuLightColor: $base-menu-light-color; + menuColorActive: $base-menu-color-active; + menuBackground: $base-menu-background; + menuLightBackground: $base-menu-light-background; + subMenuBackground: $base-sub-menu-background; + subMenuHover: $base-sub-menu-hover; + sideBarWidth: $base-sidebar-width; + logoTitleColor: $base-logo-title-color; + logoLightTitleColor: $base-logo-light-title-color } + diff --git a/ZR.Vue/src/layout/components/Settings/index.vue b/ZR.Vue/src/layout/components/Settings/index.vue index 5079b8e..895042e 100644 --- a/ZR.Vue/src/layout/components/Settings/index.vue +++ b/ZR.Vue/src/layout/components/Settings/index.vue @@ -32,7 +32,7 @@ - +
开启 Tags-Views @@ -107,6 +107,7 @@ export default { key: "theme", value: val, }); + this.theme = val; }, handleTheme(val) { this.$store.dispatch("settings/changeSetting", { @@ -118,6 +119,12 @@ export default { // 保存配置好 saveSetting() { // this.$modal.loading("正在保存到本地,请稍后..."); + const loading = this.$loading({ + lock: true, + text: "正在保存到本地,请稍后...", + spinner: "el-icon-loading", + background: "rgba(0, 0, 0, 0.7)", + }); localStorage.setItem( "layout-setting", `{ @@ -129,7 +136,7 @@ export default { }` ); this.msgSuccess("保存成功"); - // setTimeout(this.$modal.closeLoading(), 1000); + setTimeout(loading.close(), 2000); }, resetSetting() { // this.$modal.loading("正在清除设置缓存并刷新,请稍后..."); diff --git a/ZR.Vue/src/layout/components/Sidebar/Logo.vue b/ZR.Vue/src/layout/components/Sidebar/Logo.vue index 1bc9b7a..c794875 100644 --- a/ZR.Vue/src/layout/components/Sidebar/Logo.vue +++ b/ZR.Vue/src/layout/components/Sidebar/Logo.vue @@ -1,5 +1,5 @@ diff --git a/ZRAdmin.xml b/ZRAdmin.xml index 6eb99c0..fc17de9 100644 --- a/ZRAdmin.xml +++ b/ZRAdmin.xml @@ -32,7 +32,7 @@ 代码生成演示Controller @author zr - @date 2021-09-27 + @date 2021-10-10