diff --git a/Infrastructure/Extensions/AppServiceExtensions.cs b/Infrastructure/Extensions/AppServiceExtensions.cs index 98545c7..4f3f5e5 100644 --- a/Infrastructure/Extensions/AppServiceExtensions.cs +++ b/Infrastructure/Extensions/AppServiceExtensions.cs @@ -59,7 +59,7 @@ namespace Infrastructure.Extensions services.AddTransient(serviceType, type); break; } - Console.WriteLine($"注册:{serviceType}"); + //Console.WriteLine($"注册:{serviceType}"); } else { diff --git a/Infrastructure/OptionsSetting.cs b/Infrastructure/OptionsSetting.cs index fb677bb..6a876d1 100644 --- a/Infrastructure/OptionsSetting.cs +++ b/Infrastructure/OptionsSetting.cs @@ -6,22 +6,11 @@ namespace Infrastructure /// public class OptionsSetting { - public static string ConnAdmin = "Conn_admin"; - public static string Conn = "ConnDynamic"; - public static string DbType = "DbType"; - public static string CodeGenDbType = "CodeGenDbType"; + public static string ConnAdmin = "conn_zrAdmin"; + public static string ConnDbType = "conn_zrAdmin_Type"; public static string DbKey = "DbKey"; - public string Conn_Admin { get; set; } - - public string AppName { get; set; } - /// - /// 主库 - /// - public string Master { get; set; } - public string Redis { get; set; } - public string Database { get; set; } /// /// 是否演示模式 diff --git a/README.md b/README.md index 9962992..431f829 100644 --- a/README.md +++ b/README.md @@ -3,15 +3,13 @@ ## 🍟概述 * 本项目适合有一定NetCore和 vue基础的开发人员 * 基于.NET 5实现的通用权限管理平台(RBAC模式)。整合最新技术高效快速开发,前后端分离模式,开箱即用。 -* 模块化架构设计,层次清晰,业务层推荐写到单独模块,框架升级不影响业务! -* 代码量少、通俗易懂、功能强大、易扩展,轻松开发从现在开始! +* 代码量少、学习简单、通俗易懂、功能强大、易扩展、轻量级,让web开发更快速、简单高效,解决70%的重复工作,专注您的业务,轻松开发从现在开始! * 前端采用Vue2.0、Element UI。 * 后端采用Net5、Sqlsugar、MySQL。 * 权限认证使用Jwt,支持多终端认证系统。 * 支持加载动态权限菜单,多方式轻松权限控制 -* 基于若依vue分离版本(java版本)修改 -> 如果对您有帮助,点击右上角⭐Star⭐关注 ,感谢支持开源! +> 如果对您有帮助,您可以点右上角 “Star” 收藏一下 ,这样作者才有继续免费下去的动力,谢谢!~ ## 🍿在线体验 体验地址:http://www.izhaorui.cn:8080/ @@ -36,7 +34,7 @@ Vue版前端技术栈 :基于vue、vuex、vue-router 、vue-cli 、axios 和 e ## 🍄快速启动 需要安装:VS2019(最新版)、npm或yarn(最新版) -准备工作:将document文件夹下面的admin.sql脚本导入到数据库中,修改ZRAdmin项目里面的Conn_Admin数据库连接字符串以及DbType选择对应的数据库类型,目前仅MySQL验证了 +准备工作:将document文件夹下面的admin.sql脚本导入到数据库中,修改ZR.Admin.WebApi项目里面配置文件中的conn_zrAdmin数据库连接字符串以及DbType选择对应的数据库类型,目前仅支持MySQL、SQL server 启动后台:打开项目根目录的startup.bat即可启动(数据库默认MySQL) 启动前端:打开ZR.Vue文件夹,运行npm install命令,再运行npm run serve启动 浏览器访问:http://localhost:8887 (默认前端端口为:8887,后台端口为:8888) @@ -59,7 +57,30 @@ Vue版前端技术栈 :基于vue、vuex、vue-router 、vue-cli 、axios 和 e 13. [X] 在线构建器:拖动表单元素生成相应的VUE代码。 14. [X] 任务系统:基于Quartz.NET定时任务执行。 15. [X] 文章管理:可以写文章记录。 -16. [X] 代码生成:可以一键生成前后端代码。 +16. [X] 代码生成:可以一键生成前后端代码(.cs、.vue、.js),自定义配置前端展示控件、让开发更快捷高效。 + +## 项目结构 + +ZRAdmin解决方案包含: + +Infrastructure[基础类库]:包框架的核心组件,包含一系列快速开发中经常用到的Utility辅助工具功能,部分核心功能的实现; + +ZR.Service[服务层类库]:提供WebApi接口调用; + +ZR.Tasks[定时任务类库]:提供项目定时任务实现功能; + +ZR.Repository[仓库层类库]:方便提供有执行存储过程的操作; + +ZR.Model[实体层类库],提供项目中的数据库表、数据传输对象; + +ZR.CodeGenerator[代码生成功能],包含代码生成的模板、方法、代码生成的下载。 + +ZR.Admin.WebApi[webapi接口]:为Vue版或其他三方系统提供接口服务。 + +ZR.Vue[前端UI]:vue版本UI层。 + +DataBase是最新数据库备份文件,目前支持MS SQL Server和MySql。 + ## 🍎演示图 @@ -92,6 +113,10 @@ Vue版前端技术栈 :基于vue、vuex、vue-router 、vue-cli 、axios 和 e + + + + ## 🎉优势 @@ -100,6 +125,7 @@ Vue版前端技术栈 :基于vue、vuex、vue-router 、vue-cli 、axios 和 e 2. 后台系统无需任何二次开发,直接发布即可使用 3. 前台与后台系统分离,分别为不同的系统(域名可独立) 4. 全局异常统一处理 +5. 自定义的代码生成功能 ## 💐 特别鸣谢 - 👉Ruoyi.vue:[Ruoyi](http://www.ruoyi.vip/) diff --git a/ZR.Admin.WebApi/Controllers/CodeGeneratorController.cs b/ZR.Admin.WebApi/Controllers/CodeGeneratorController.cs index 7cffe87..c504bf6 100644 --- a/ZR.Admin.WebApi/Controllers/CodeGeneratorController.cs +++ b/ZR.Admin.WebApi/Controllers/CodeGeneratorController.cs @@ -1,15 +1,25 @@ using Infrastructure; using Infrastructure.Attribute; using Infrastructure.Enums; +using Mapster; +using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Hosting; using SqlSugar; +using System; using System.Collections.Generic; +using System.IO; +using ZR.Admin.WebApi.Extensions; using ZR.Admin.WebApi.Filters; using ZR.CodeGenerator; using ZR.CodeGenerator.Model; using ZR.CodeGenerator.Service; +using ZR.Common; using ZR.Model; +using ZR.Model.System.Dto; +using ZR.Model.System.Generate; using ZR.Model.Vo; +using ZR.Service.System.IService; namespace ZR.Admin.WebApi.Controllers { @@ -20,6 +30,15 @@ namespace ZR.Admin.WebApi.Controllers public class CodeGeneratorController : BaseController { private CodeGeneraterService _CodeGeneraterService = new CodeGeneraterService(); + private IGenTableService GenTableService; + private IGenTableColumnService GenTableColumnService; + private IWebHostEnvironment WebHostEnvironment; + public CodeGeneratorController(IGenTableService genTableService, IGenTableColumnService genTableColumnService, IWebHostEnvironment webHostEnvironment) + { + GenTableService = genTableService; + GenTableColumnService = genTableColumnService; + WebHostEnvironment = webHostEnvironment; + } /// /// 获取所有数据库的信息 @@ -51,22 +70,6 @@ namespace ZR.Admin.WebApi.Controllers return SUCCESS(vm); } - /// - /// 获取表格列 - /// - /// - /// - /// - [HttpGet("getColumnInfo")] - [ActionPermissionFilter(Permission = "tool:gen:list")] - public IActionResult QueryColumnInfo(string dbName, string tableName) - { - if (string.IsNullOrEmpty(dbName) || string.IsNullOrEmpty(tableName)) - return ToRespose(ResultCode.PARAM_ERROR); - - return SUCCESS(_CodeGeneraterService.GetColumnInfo(dbName, tableName)); - } - /// /// 代码生成器 /// @@ -77,14 +80,143 @@ namespace ZR.Admin.WebApi.Controllers [ActionPermissionFilter(Permission = "tool:gen:code")] public IActionResult Generate([FromBody] GenerateDto dto) { - if (string.IsNullOrEmpty(dto.tableName)) + if (dto.TableId <= 0) { throw new CustomException(ResultCode.CUSTOM_ERROR, "请求参数为空"); } - DbTableInfo dbTableInfo = new() { Name = dto.tableName }; - CodeGeneratorTool.Generate(dbTableInfo, dto); + dto.ZipPath = Path.Combine(WebHostEnvironment.WebRootPath, "Generatecode"); + dto.GenCodePath = Path.Combine(dto.ZipPath, DateTime.Now.ToString("yyyyMMdd")); - return SUCCESS(dbTableInfo); + var genTableInfo = GenTableService.GetGenTableInfo(dto.TableId); + genTableInfo.Columns = GenTableColumnService.GenTableColumns(dto.TableId); + + dto.GenTable = genTableInfo; + //生成代码 + CodeGeneratorTool.Generate(genTableInfo, dto); + //下载文件 + CodeGeneratorTool.ZipGenCode(dto); + + //HttpContext.Response.Headers.Add("Content-disposition", $"attachment; filename={zipFileName}"); + return SUCCESS(new { zipPath = "/Generatecode/" + dto.ZipFileName, fileName = dto.ZipFileName }); + } + + /// + /// 获取代码生成表列表 + /// + /// 表名 + /// 分页信息 + /// + [HttpGet("listGenTable")] + public IActionResult GetGenTable(string tableName, PagerInfo pagerInfo) + { + //查询原表数据,部分字段映射到代码生成表字段 + var rows = GenTableService.GetGenTables(new GenTable() { TableName = tableName }, pagerInfo); + + return SUCCESS(rows); + } + + /// + /// 查询表字段列表 + /// + /// genTable表id + /// + [HttpGet("column/{tableId}")] + public IActionResult GetColumnList(long tableId) + { + var tableColumns = GenTableColumnService.GenTableColumns(tableId); + var tableInfo = GenTableService.GetGenTableInfo(tableId); + return SUCCESS(new { result = tableColumns, info = tableInfo }); + } + + /// + /// 删除代码生成 + /// + /// + /// + [Log(Title = "代码生成", BusinessType = BusinessType.DELETE)] + [HttpDelete("{tableIds}")] + [ActionPermissionFilter(Permission = "tool:gen:remove")] + public IActionResult Remove(string tableIds) + { + long[] tableId = Tools.SpitLongArrary(tableIds); + + int result = GenTableService.DeleteGenTableByIds(tableId); + return SUCCESS(result); + } + + /// + /// 导入表 + /// + /// + /// + /// + [HttpPost("importTable")] + [Log(Title = "代码生成", BusinessType = BusinessType.IMPORT)] + [ActionPermissionFilter(Permission = "tool:gen:import")] + public IActionResult ImportTableSave(string tables, string dbName) + { + if (string.IsNullOrEmpty(tables)) + { + throw new CustomException("表不能为空"); + } + string[] tableNames = tables.Split(',', StringSplitOptions.RemoveEmptyEntries); + string userName = User.Identity.Name; + + foreach (var tableName in tableNames) + { + var tabInfo = _CodeGeneraterService.GetTableInfo(dbName, tableName); + if (tabInfo != null) + { + GenTable genTable = new() + { + BaseNameSpace = "ZR.",//导入默认命名空间前缀 + ModuleName = "business",//导入默认模块名 + ClassName = CodeGeneratorTool.GetClassName(tableName), + BusinessName = CodeGeneratorTool.GetClassName(tableName), + FunctionAuthor = ConfigUtils.Instance.GetConfig(GenConstants.Gen_author), + FunctionName = tabInfo.Description, + TableName = tableName, + TableComment = tabInfo.Description, + Create_by = userName, + }; + genTable.TableId = GenTableService.ImportGenTable(genTable); + + if (genTable.TableId > 0) + { + //保存列信息 + List dbColumnInfos = _CodeGeneraterService.GetColumnInfo(dbName, tableName); + List genTableColumns = CodeGeneratorTool.InitGenTableColumn(genTable, dbColumnInfos); + + GenTableColumnService.DeleteGenTableColumnByTableName(tableName); + GenTableColumnService.InsertGenTableColumn(genTableColumns); + genTable.Columns = genTableColumns; + + return SUCCESS(genTable); + } + } + } + + return ToRespose(ResultCode.FAIL); + } + + /// + /// 修改保存代码生成业务 + /// + /// + [HttpPut] + //[Log(Title = "代码生成", BusinessType = BusinessType.UPDATE)] + [ActionPermissionFilter(Permission = "tool:gen:edit")] + public IActionResult EditSave([FromBody] GenTableDto genTableDto) + { + if (genTableDto == null) throw new CustomException("请求参数错误"); + var genTable = genTableDto.Adapt().ToUpdate(HttpContext); + + int rows = GenTableService.UpdateGenTable(genTable); + if (rows > 0) + { + GenTableColumnService.UpdateGenTableColumn(genTable.Columns); + } + return SUCCESS(rows); } } } diff --git a/ZR.Admin.WebApi/Controllers/System/ArticleController.cs b/ZR.Admin.WebApi/Controllers/System/ArticleController.cs index 6f73f98..e175c26 100644 --- a/ZR.Admin.WebApi/Controllers/System/ArticleController.cs +++ b/ZR.Admin.WebApi/Controllers/System/ArticleController.cs @@ -1,22 +1,12 @@ - -//------------------------------------------------------------------------------ -// -// 此代码已从模板生成。 -// -// 手动更改此文件可能导致应用程序出现意外的行为。 -// 如果重新生成代码,将覆盖对此文件的手动更改。 -// -//------------------------------------------------------------------------------ - -using Infrastructure.Attribute; +using Infrastructure.Attribute; using Microsoft.AspNetCore.Mvc; using ZR.Admin.WebApi.Filters; using ZR.Model.System; -using ZR.Service.IService; +using ZR.Service.System.IService; using Infrastructure.Model; using SqlSugar; using Mapster; -using ZR.Model.Dto.System; +using ZR.Model.System.Dto; using Infrastructure.Enums; using Infrastructure; using ZR.Admin.WebApi.Extensions; diff --git a/ZR.Admin.WebApi/Controllers/System/SysDeptController.cs b/ZR.Admin.WebApi/Controllers/System/SysDeptController.cs index 8dec679..dc99ec2 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysDeptController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysDeptController.cs @@ -7,7 +7,7 @@ using ZR.Admin.WebApi.Filters; using ZR.Common; using ZR.Model.System; using ZR.Service; -using ZR.Service.IService; +using ZR.Service.System.IService; namespace ZR.Admin.WebApi.Controllers.System { diff --git a/ZR.Admin.WebApi/Controllers/System/SysDictDataController.cs b/ZR.Admin.WebApi/Controllers/System/SysDictDataController.cs index d0968af..c5fe262 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysDictDataController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysDictDataController.cs @@ -7,7 +7,7 @@ using ZR.Admin.WebApi.Filters; using ZR.Model; using ZR.Model.System; using ZR.Model.Vo; -using ZR.Service.IService; +using ZR.Service.System.IService; namespace ZR.Admin.WebApi.Controllers.System { diff --git a/ZR.Admin.WebApi/Controllers/System/SysDictTypeController.cs b/ZR.Admin.WebApi/Controllers/System/SysDictTypeController.cs index 177430a..d61222c 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysDictTypeController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysDictTypeController.cs @@ -8,7 +8,7 @@ using ZR.Common; using ZR.Model; using ZR.Model.System; using ZR.Model.Vo; -using ZR.Service.IService; +using ZR.Service.System.IService; namespace ZR.Admin.WebApi.Controllers.System { diff --git a/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs b/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs index b363ab8..08afac8 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs @@ -11,8 +11,8 @@ using Infrastructure.Model; using Infrastructure; using Infrastructure.Attribute; using ZR.Model.System; -using ZR.Model.Dto.System; -using ZR.Service.IService; +using ZR.Model.System.Dto; +using ZR.Service.System.IService; using Hei.Captcha; using ZR.Common; diff --git a/ZR.Admin.WebApi/Controllers/System/SysMenuController.cs b/ZR.Admin.WebApi/Controllers/System/SysMenuController.cs index 27dd846..aa05eaf 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysMenuController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysMenuController.cs @@ -5,10 +5,10 @@ using Infrastructure.Model; using Microsoft.AspNetCore.Mvc; using ZR.Admin.WebApi.Extensions; using ZR.Admin.WebApi.Filters; -using ZR.Model.Dto.System; +using ZR.Model.System.Dto; using ZR.Model.System; using ZR.Service; -using ZR.Service.IService; +using ZR.Service.System.IService; namespace ZR.Admin.WebApi.Controllers.System { diff --git a/ZR.Admin.WebApi/Controllers/System/SysPostController.cs b/ZR.Admin.WebApi/Controllers/System/SysPostController.cs index 477ee60..ef3da92 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysPostController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysPostController.cs @@ -8,7 +8,7 @@ using Infrastructure.Extensions; using Infrastructure.Attribute; using Infrastructure.Enums; using Infrastructure; -using ZR.Service.IService; +using ZR.Service.System.IService; namespace ZR.Admin.WebApi.Controllers.System { diff --git a/ZR.Admin.WebApi/Controllers/System/SysProfileController.cs b/ZR.Admin.WebApi/Controllers/System/SysProfileController.cs index d1e2172..29890f1 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysProfileController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysProfileController.cs @@ -12,9 +12,9 @@ using System.IO; using ZR.Admin.WebApi.Extensions; using ZR.Admin.WebApi.Filters; using ZR.Common; -using ZR.Model.Dto.System; +using ZR.Model.System.Dto; using ZR.Model.System; -using ZR.Service.IService; +using ZR.Service.System.IService; namespace ZR.Admin.WebApi.Controllers.System { diff --git a/ZR.Admin.WebApi/Controllers/System/SysRoleController.cs b/ZR.Admin.WebApi/Controllers/System/SysRoleController.cs index 1b92d24..7fa72fc 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysRoleController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysRoleController.cs @@ -8,7 +8,7 @@ using ZR.Admin.WebApi.Filters; using ZR.Model; using ZR.Model.System; using ZR.Model.Vo; -using ZR.Service.IService; +using ZR.Service.System.IService; using ZR.Admin.WebApi.Extensions; namespace ZR.Admin.WebApi.Controllers.System diff --git a/ZR.Admin.WebApi/Controllers/System/SysUserController.cs b/ZR.Admin.WebApi/Controllers/System/SysUserController.cs index 649738f..e309a41 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysUserController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysUserController.cs @@ -10,7 +10,7 @@ using ZR.Admin.WebApi.Filters; using ZR.Model; using ZR.Model.System; using ZR.Model.Vo; -using ZR.Service.IService; +using ZR.Service.System.IService; namespace ZR.Admin.WebApi.Controllers.System { diff --git a/ZR.Admin.WebApi/Controllers/System/SysUserRoleController.cs b/ZR.Admin.WebApi/Controllers/System/SysUserRoleController.cs index a801832..b355f44 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysUserRoleController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysUserRoleController.cs @@ -5,9 +5,9 @@ using System; using System.Linq; using ZR.Admin.WebApi.Filters; using ZR.Model; -using ZR.Model.Dto.System; +using ZR.Model.System.Dto; using ZR.Model.System; -using ZR.Service.IService; +using ZR.Service.System.IService; namespace ZR.Admin.WebApi.Controllers.System { diff --git a/ZR.Admin.WebApi/Controllers/System/TasksController.cs b/ZR.Admin.WebApi/Controllers/System/TasksController.cs index ad60385..541ad29 100644 --- a/ZR.Admin.WebApi/Controllers/System/TasksController.cs +++ b/ZR.Admin.WebApi/Controllers/System/TasksController.cs @@ -10,9 +10,9 @@ using System.Threading.Tasks; using ZR.Admin.WebApi.Extensions; using ZR.Admin.WebApi.Filters; using ZR.Model; -using ZR.Model.Dto.System; +using ZR.Model.System.Dto; using ZR.Model.System; -using ZR.Service.IService; +using ZR.Service.System.IService; using ZR.Tasks; namespace ZR.Admin.WebApi.Controllers diff --git a/ZR.Admin.WebApi/Controllers/System/TasksLogController.cs b/ZR.Admin.WebApi/Controllers/System/TasksLogController.cs index ca842ca..1a045ec 100644 --- a/ZR.Admin.WebApi/Controllers/System/TasksLogController.cs +++ b/ZR.Admin.WebApi/Controllers/System/TasksLogController.cs @@ -1,14 +1,14 @@ using Microsoft.AspNetCore.Mvc; using SqlSugar; using ZR.Model; -using ZR.Model.Dto.System; +using ZR.Model.System.Dto; using ZR.Model.System; using Infrastructure.Extensions; using Infrastructure.Attribute; using ZR.Admin.WebApi.Filters; using ZR.Common; using Infrastructure.Enums; -using ZR.Service.IService; +using ZR.Service.System.IService; namespace ZR.Admin.WebApi.Controllers.System { diff --git a/ZR.Admin.WebApi/Controllers/System/monitor/SysLogininforController.cs b/ZR.Admin.WebApi/Controllers/System/monitor/SysLogininforController.cs index 74a4139..686be34 100644 --- a/ZR.Admin.WebApi/Controllers/System/monitor/SysLogininforController.cs +++ b/ZR.Admin.WebApi/Controllers/System/monitor/SysLogininforController.cs @@ -5,7 +5,7 @@ using ZR.Common; using ZR.Model; using ZR.Model.System; using ZR.Model.Vo; -using ZR.Service.IService; +using ZR.Service.System.IService; namespace ZR.Admin.WebApi.Controllers.monitor { diff --git a/ZR.Admin.WebApi/Controllers/System/monitor/SysOperlogController.cs b/ZR.Admin.WebApi/Controllers/System/monitor/SysOperlogController.cs index fd76f8f..e2774b2 100644 --- a/ZR.Admin.WebApi/Controllers/System/monitor/SysOperlogController.cs +++ b/ZR.Admin.WebApi/Controllers/System/monitor/SysOperlogController.cs @@ -5,10 +5,10 @@ using Microsoft.AspNetCore.Mvc; using ZR.Admin.WebApi.Filters; using ZR.Common; using ZR.Model; -using ZR.Model.Dto.System; +using ZR.Model.System.Dto; using ZR.Model.System; using ZR.Model.Vo; -using ZR.Service.IService; +using ZR.Service.System.IService; namespace ZR.Admin.WebApi.Controllers.monitor { diff --git a/ZR.Admin.WebApi/Extensions/EntityExtension.cs b/ZR.Admin.WebApi/Extensions/EntityExtension.cs index c472ed5..879a258 100644 --- a/ZR.Admin.WebApi/Extensions/EntityExtension.cs +++ b/ZR.Admin.WebApi/Extensions/EntityExtension.cs @@ -49,27 +49,34 @@ namespace ZR.Admin.WebApi.Extensions return source; } - //public static TSource ToUpdate(this TSource source, UserSessionVM userSession) - //{ - // var types = source.GetType(); + public static TSource ToUpdate(this TSource source, HttpContext context = null) + { + var types = source.GetType(); - // if (types.GetProperty("UpdateTime") != null) - // { - // types.GetProperty("UpdateTime").SetValue(source, DateTime.Now, null); - // } + if (types.GetProperty("UpdateTime") != null) + { + types.GetProperty("UpdateTime").SetValue(source, DateTime.Now, null); + } + if (types.GetProperty("Update_Time") != null) + { + types.GetProperty("Update_Time").SetValue(source, DateTime.Now, null); + } + //if (types.GetProperty("UpdateID") != null) + //{ + // types.GetProperty("UpdateID").SetValue(source, userSession.UserID, null); + //} - // if (types.GetProperty("UpdateID") != null) - // { - // types.GetProperty("UpdateID").SetValue(source, userSession.UserID, null); - // } + if (types.GetProperty("UpdateBy") != null) + { + types.GetProperty("UpdateBy").SetValue(source,context.GetName(), null); + } + if (types.GetProperty("Update_by") != null) + { + types.GetProperty("Update_by").SetValue(source, context.GetName(), null); + } - // if (types.GetProperty("UpdateName") != null) - // { - // types.GetProperty("UpdateName").SetValue(source, userSession.UserName, null); - // } - - // return source; - //} + return source; + } } } diff --git a/ZR.Admin.WebApi/Extensions/HttpContextExtension.cs b/ZR.Admin.WebApi/Extensions/HttpContextExtension.cs index 0720d47..d2cb61f 100644 --- a/ZR.Admin.WebApi/Extensions/HttpContextExtension.cs +++ b/ZR.Admin.WebApi/Extensions/HttpContextExtension.cs @@ -71,7 +71,7 @@ namespace ZR.Admin.WebApi.Extensions } public static string GetName(this HttpContext context) { - var uid = context.User.Identity.Name; + var uid = context.User?.Identity?.Name; return uid; } diff --git a/ZR.Admin.WebApi/Extensions/TasksExtension.cs b/ZR.Admin.WebApi/Extensions/TasksExtension.cs index dda6ba7..d125afa 100644 --- a/ZR.Admin.WebApi/Extensions/TasksExtension.cs +++ b/ZR.Admin.WebApi/Extensions/TasksExtension.cs @@ -3,7 +3,7 @@ using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; using Quartz.Spi; using System; -using ZR.Service.IService; +using ZR.Service.System.IService; using ZR.Tasks; namespace ZR.Admin.WebApi.Extensions diff --git a/ZR.Admin.WebApi/Filters/ActionPermissionFilter.cs b/ZR.Admin.WebApi/Filters/ActionPermissionFilter.cs index 1f87286..88258d7 100644 --- a/ZR.Admin.WebApi/Filters/ActionPermissionFilter.cs +++ b/ZR.Admin.WebApi/Filters/ActionPermissionFilter.cs @@ -54,7 +54,7 @@ namespace ZR.Admin.WebApi.Filters bool isDemoMode = ConfigUtils.Instance.GetAppConfig("DemoMode", false); //演示公开环境屏蔽权限 - string[] denyPerms = new string[] { "update", "add", "remove", "add", "edit", "delete", "import", "run", "start", "stop", "clear", "code" }; + string[] denyPerms = new string[] { "update", "add", "remove", "add", "edit", "delete", "import", "run", "start", "stop", "clear" }; if (isDemoMode && (denyPerms.Any(f => Permission.ToLower().Contains(f.ToLower())) || Permission.Equals("system"))) { context.Result = new JsonResult(new { code = ResultCode.FORBIDDEN, msg = "演示模式 , 不允许操作" }); diff --git a/ZR.Admin.WebApi/Filters/LogActionFilter.cs b/ZR.Admin.WebApi/Filters/LogActionFilter.cs index 0d9df95..b116d74 100644 --- a/ZR.Admin.WebApi/Filters/LogActionFilter.cs +++ b/ZR.Admin.WebApi/Filters/LogActionFilter.cs @@ -12,7 +12,7 @@ using System.Linq; using System.Text; using ZR.Admin.WebApi.Extensions; using ZR.Model.System; -using ZR.Service.IService; +using ZR.Service.System.IService; namespace ZR.Admin.WebApi.Filters { diff --git a/ZR.Admin.WebApi/Framework/JwtUtil.cs b/ZR.Admin.WebApi/Framework/JwtUtil.cs index e75abff..1f7f073 100644 --- a/ZR.Admin.WebApi/Framework/JwtUtil.cs +++ b/ZR.Admin.WebApi/Framework/JwtUtil.cs @@ -1,4 +1,5 @@ -using Microsoft.AspNetCore.Http; +using Infrastructure; +using Microsoft.AspNetCore.Http; using Microsoft.IdentityModel.Tokens; using Newtonsoft.Json; using System; @@ -43,12 +44,13 @@ namespace ZR.Admin.WebApi.Framework { var tokenHandler = new JwtSecurityTokenHandler(); var key = Encoding.ASCII.GetBytes(KEY); + var expires = ConfigUtils.Instance.GetAppConfig("sysConfig:tokenExpire", 10); var tokenDescriptor = new SecurityTokenDescriptor { Subject = new ClaimsIdentity(claims), //Issuer = "", //Audience = "", - Expires = DateTime.Now.AddDays(7), + Expires = DateTime.Now.AddMinutes(expires), SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature) }; var token = tokenHandler.CreateToken(tokenDescriptor); diff --git a/ZR.Admin.WebApi/Middleware/GlobalExceptionMiddleware.cs b/ZR.Admin.WebApi/Middleware/GlobalExceptionMiddleware.cs index 4bbe298..cca6d89 100644 --- a/ZR.Admin.WebApi/Middleware/GlobalExceptionMiddleware.cs +++ b/ZR.Admin.WebApi/Middleware/GlobalExceptionMiddleware.cs @@ -9,7 +9,7 @@ using System.Threading.Tasks; using ZR.Admin.WebApi.Extensions; using ZR.Admin.WebApi.Filters; using ZR.Model.System; -using ZR.Service.IService; +using ZR.Service.System.IService; namespace ZR.Admin.WebApi.Middleware { diff --git a/ZR.Admin.WebApi/NLog.config b/ZR.Admin.WebApi/NLog.config index a9d6783..a6d075c 100644 --- a/ZR.Admin.WebApi/NLog.config +++ b/ZR.Admin.WebApi/NLog.config @@ -23,7 +23,8 @@ -// 此代码已从模板生成。 -// -// 手动更改此文件可能导致应用程序出现意外的行为。 -// 如果重新生成代码,将覆盖对此文件的手动更改。 -// -//------------------------------------------------------------------------------ -using Infrastructure.Attribute; -using Microsoft.AspNetCore.Mvc; -using ZR.Admin.WebApi.Filters; -using ZR.Model.System; -using ZR.Service.IService; -using Infrastructure.Model; -using SqlSugar; -using Mapster; -using ZR.Model.Dto.System; -using Infrastructure.Enums; -using Infrastructure; -using ZR.Admin.WebApi.Extensions; - -namespace ZR.Admin.WebApi.Controllers -{ - /// - /// T4代码自动生成 - /// - - [Verify] - [Route("system/SysFile")] - public class SysFile1Controller: BaseController - { - /// - /// 文件管理接口 - /// - private readonly ISysFileService _SysFileService; - - public SysFile1Controller(ISysFileService SysFileService) - { - _SysFileService = SysFileService; - } - - /// - /// 查询文件管理列表 - /// - /// - [HttpGet("list")] - //[ActionPermissionFilter(Permission = "system:SysFile:list")] - public IActionResult Query([FromQuery] SysFileQueryDto parm) - { - //开始拼装查询条件 - var predicate = Expressionable.Create(); - - //TODO 搜索条件 - //predicate = predicate.And(m => m.Name.Contains(parm.Name)); - - var response = _SysFileService.GetPages(predicate.ToExpression(), parm); - - return SUCCESS(response); - } - - /// - /// 查询文件管理详情 - /// - /// - /// - [HttpGet("{id}")] - public IActionResult Get(string id) - { - var response = _SysFileService.GetId(id); - - return SUCCESS(response); - } - - /// - /// 添加文件管理 - /// - /// - [HttpPost] - //[ActionPermissionFilter(Permission = "system:SysFile:add")] - [Log(Title = "文件管理添加", BusinessType = BusinessType.INSERT)] - public IActionResult Create([FromBody] SysFile parm) - { - if (parm == null) - { - throw new CustomException("请求参数错误"); - } - //从 Dto 映射到 实体 - var addModel = parm.Adapt().ToCreate(); - //addModel.CreateID = User.Identity.Name; - - return SUCCESS(_SysFileService.Add(addModel)); - } - - /// - /// 更新文件管理 - /// - /// - [HttpPut("edit")] - //[ActionPermissionFilter(Permission = "system:SysFile:update")] - [Log(Title = "文件管理修改", BusinessType = BusinessType.UPDATE)] - public IActionResult Update([FromBody] SysFile parm) - { - //从 Dto 映射到 实体 - var addModel = parm.Adapt().ToCreate(); - //addModel.CreateID = User.Identity.Name; - //TODO 字段映射 - var response = _SysFileService.Update(addModel); - - return SUCCESS(response); - } - - /// - /// 删除文件管理 - /// - /// - [HttpDelete("{id}")] - //[ActionPermissionFilter(Permission = "system:SysFile:delete")] - [Log(Title = "文件管理删除", BusinessType = BusinessType.DELETE)] - public IActionResult Delete(int id = 0) - { - if (id <= 0) { return OutputJson(ApiResult.Error($"删除失败Id 不能为空")); } - - // 删除文件管理 - var response = _SysFileService.Delete(id); - - return SUCCESS(response); - } - } -} \ No newline at end of file diff --git a/ZR.Admin.WebApi/Template/Controller.tt b/ZR.Admin.WebApi/Template/Controller.tt deleted file mode 100644 index 3646cc6..0000000 --- a/ZR.Admin.WebApi/Template/Controller.tt +++ /dev/null @@ -1,145 +0,0 @@ -<#@ template debug="false" hostspecific="false" language="C#" #> -<#@ assembly name="System.Core" #> -<#@ import namespace="System.Linq" #> -<#@ import namespace="System.Text" #> -<#@ import namespace="System.Collections.Generic" #> -<#@ output extension=".cs" #> - -<# -string ModelName="SysFile"; -string ControllerName="SysFile"; -string ServiceName="SysFileService"; -string FileName="文件管理"; -string ModelNameSpace="ZRAdmin.Controllers"; -#> -//------------------------------------------------------------------------------ -// -// 此代码已从模板生成。 -// -// 手动更改此文件可能导致应用程序出现意外的行为。 -// 如果重新生成代码,将覆盖对此文件的手动更改。 -// -//------------------------------------------------------------------------------ -using Infrastructure.Attribute; -using Microsoft.AspNetCore.Mvc; -using ZRAdmin.Filters; -using ZR.Model; -using ZR.Model.System; -using ZR.Model.Vo; -using ZR.Service.IService; -using Infrastructure.Model; -using SqlSugar; -using Mapster; -using ZR.Model.Dto.System; -using Infrastructure.Enums; -using Infrastructure; -using ZRAdmin.Extensions; - -namespace <#=ModelNameSpace#> -{ - /// - /// T4代码自动生成 - /// - - [Verify] - [Route("system/<#=ModelName#>")] - public class <#=ControllerName#>1Controller: BaseController - { - /// - /// <#=FileName#>接口 - /// - private readonly I<#=ServiceName#> _<#=ServiceName#>; - - public <#=ControllerName#>1Controller(I<#=ServiceName#> <#=ServiceName#>) - { - _<#=ServiceName#> = <#=ServiceName#>; - } - - /// - /// 查询<#=FileName#>列表 - /// - /// - [HttpGet("list")] - //[ActionPermissionFilter(Permission = "system:<#=ModelName#>:list")] - public IActionResult Query([FromQuery] <#=ModelName#>QueryDto parm) - { - //开始拼装查询条件 - var predicate = Expressionable.Create<<#=ModelName#>>(); - - //TODO 搜索条件 - //predicate = predicate.And(m => m.Name.Contains(parm.Name)); - - var response = _<#=ServiceName#>.GetPages(predicate.ToExpression(), parm); - - return SUCCESS(response); - } - - /// - /// 查询<#=FileName#>详情 - /// - /// - /// - [HttpGet("{id}")] - public IActionResult Get(string id) - { - var response = _<#=ServiceName#>.GetId(id); - - return SUCCESS(response); - } - - /// - /// 添加<#=FileName#> - /// - /// - [HttpPost] - //[ActionPermissionFilter(Permission = "system:<#=ModelName#>:add")] - [Log(Title = "<#=FileName#>添加", BusinessType = BusinessType.INSERT)] - public IActionResult Create([FromBody] <#=ModelName#> parm) - { - if (parm == null) - { - throw new CustomException("请求参数错误"); - } - //从 Dto 映射到 实体 - var addModel = parm.Adapt<<#=ModelName#>>().ToCreate(); - //addModel.CreateID = User.Identity.Name; - - return SUCCESS(_<#=ServiceName#>.Add(addModel)); - } - - /// - /// 更新<#=FileName#> - /// - /// - [HttpPut("edit")] - //[ActionPermissionFilter(Permission = "system:<#=ModelName#>:update")] - [Log(Title = "<#=FileName#>修改", BusinessType = BusinessType.UPDATE)] - public IActionResult Update([FromBody] <#=ModelName#> parm) - { - //从 Dto 映射到 实体 - var addModel = parm.Adapt<<#=ModelName#>>().ToCreate(); - //addModel.CreateID = User.Identity.Name; - //TODO 字段映射 - var response = _<#=ServiceName#>.Update(addModel); - - return SUCCESS(response); - } - - /// - /// 删除<#=FileName#> - /// - /// - [HttpDelete("{id}")] - //[ActionPermissionFilter(Permission = "system:<#=ModelName#>:delete")] - [Log(Title = "<#=FileName#>删除", BusinessType = BusinessType.DELETE)] - public IActionResult Delete(int id = 0) - { - if (id <= 0) { return OutputJson(ApiResult.Error($"删除失败Id 不能为空")); } - - // 删除<#=FileName#> - var response = _<#=ServiceName#>.Delete(id); - - return SUCCESS(response); - } - } -} \ No newline at end of file diff --git a/ZR.Admin.WebApi/Template/ControllersTemplate.txt b/ZR.Admin.WebApi/Template/ControllersTemplate.txt deleted file mode 100644 index 6d8d8b2..0000000 --- a/ZR.Admin.WebApi/Template/ControllersTemplate.txt +++ /dev/null @@ -1,134 +0,0 @@ -using Microsoft.AspNetCore.Mvc; -using System; -using System.Collections.Generic; -using System.Threading.Tasks; -using ZR.Admin.WebApi.Filters; -using ZR.Admin.WebApi.Controllers; -using ZR.Service.Business; -using SqlSugar; -using Infrastructure; -using Infrastructure.Attribute; -using Infrastructure.Enums; -using Infrastructure.Model; -using Mapster; -using ZR.Admin.WebApi.Extensions; -using {ModelsNamespace}.Dto; -using {ModelsNamespace}.Models; - -namespace ZRAdmin.Controllers -{ - /// - /// 代码自动生成 - /// - - [Verify] - [Route("bus/{ModelName}")] - public class {ControllerName}Controller: BaseController - { - /// - /// {FileName}接口 - /// - private readonly I{ServiceName} _{ServiceName}; - - public {ControllerName}Controller(I{ServiceName} {ServiceName}) - { - _{ServiceName} = {ServiceName}; - } - - /// - /// 查询{FileName}列表 - /// - /// - [HttpGet("list")] - [ActionPermissionFilter(Permission = "{Permission}:list")] - public IActionResult Query([FromQuery] {ModelName}QueryDto parm) - { - //开始拼装查询条件 - var predicate = Expressionable.Create<{ModelName}>(); - - //TODO 搜索条件 - //predicate = predicate.And(m => m.Name.Contains(parm.Name)); - - var response = _{ServiceName}.GetPages(predicate.ToExpression(), parm); - - return SUCCESS(response); - } - - /// - /// 查询{FileName}详情 - /// - /// - /// - [HttpGet("{{primaryKey}}")] - [ActionPermissionFilter(Permission = "{Permission}:query")] - public IActionResult Get({KeyTypeName} {primaryKey}) - { - var response = _{ServiceName}.GetId({primaryKey}); - - return SUCCESS(response); - } - - /// - /// 添加{FileName} - /// - /// - [HttpPost] - [ActionPermissionFilter(Permission = "{Permission}:add")] - [Log(Title = "{FileName}添加", BusinessType = BusinessType.INSERT)] - public IActionResult Create([FromBody] {ModelName}Dto parm) - { - if (parm == null) - { - throw new CustomException("请求参数错误"); - } - //从 Dto 映射到 实体 - var addModel = parm.Adapt<{ModelName}>().ToCreate(); - //addModel.CreateID = User.Identity.Name; - - return SUCCESS(_{ServiceName}.Add(addModel)); - } - - /// - /// 更新{FileName} - /// - /// - [HttpPut] - [ActionPermissionFilter(Permission = "{Permission}:update")] - [Log(Title = "{FileName}修改", BusinessType = BusinessType.UPDATE)] - public IActionResult Update([FromBody] {ModelName}Dto parm) - { - if (parm == null) - { - throw new CustomException("请求实体不能为空"); - } - //从 Dto 映射到 实体 - var updateModel = parm.Adapt<{ModelName}>().ToCreate(); - //updateModel.CreateID = User.Identity.Name; - - var response = _{ServiceName}.Update(w => w.{primaryKey} == updateModel.{primaryKey}, it => new {ModelName}() - { - //TODO 字段映射 - {updateColumn} - }); - - return SUCCESS(response); - } - - /// - /// 删除{FileName} - /// - /// - [HttpDelete("{{primaryKey}}")] - [ActionPermissionFilter(Permission = "{Permission}:delete")] - [Log(Title = "{FileName}删除", BusinessType = BusinessType.DELETE)] - public IActionResult Delete({KeyTypeName} {primaryKey} = 0) - { - if ({primaryKey} <= 0) { return OutputJson(ApiResult.Error($"删除失败Id 不能为空")); } - - // 删除{FileName} - var response = _{ServiceName}.Delete({primaryKey}); - - return SUCCESS(response); - } - } -} \ No newline at end of file diff --git a/ZR.Admin.WebApi/ZR.Admin.WebApi.csproj b/ZR.Admin.WebApi/ZR.Admin.WebApi.csproj index cbbf3ed..7b52794 100644 --- a/ZR.Admin.WebApi/ZR.Admin.WebApi.csproj +++ b/ZR.Admin.WebApi/ZR.Admin.WebApi.csproj @@ -15,6 +15,11 @@ + + + + + @@ -53,10 +58,6 @@ Always - - TextTemplatingFileGenerator - Controller.cs - Always @@ -85,7 +86,7 @@ - + @@ -102,12 +103,4 @@ - - - True - True - Controller.tt - - - diff --git a/ZR.Admin.WebApi/appsettings.Development.json b/ZR.Admin.WebApi/appsettings.Development.json deleted file mode 100644 index 61f44c9..0000000 --- a/ZR.Admin.WebApi/appsettings.Development.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft": "Warning", - "Microsoft.Hosting.Lifetime": "Information" - } - }, - "ConnectionStrings": { - "Conn_Admin": "server=127.0.0.1;user=zr;pwd=abc;database=admin", - "ConnDynamic": "server=127.0.0.1;user=zr;pwd=abc;database={database}"//ʹ - }, - "urls": "http://localhost:8888", //url - "sysConfig": { - "DBCommandTimeout": 10, - "cors": "http://localhost:8887" //ÿַ - }, - "DemoMode": false, //Ƿʾģʽ - "DbKey": "", - "DbType": 0, //MySql = 0, SqlServer = 1, Sqlite = 2, Oracle = 3, PostgreSQL = 4, - "CodeGenDbType": 0,//ݿ - "Upload": { - "UploadDirectory": "/", - "UploadUrl": "http://localhost:8888" - }, - "ALYUN_OCS": { - "REGIONID": "cn-hangzhou", - "KEY": "XX", - "SECRET": "XX" - } -} diff --git a/ZR.Admin.WebApi/appsettings.Production.json b/ZR.Admin.WebApi/appsettings.Production.json deleted file mode 100644 index 8983e0f..0000000 --- a/ZR.Admin.WebApi/appsettings.Production.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft": "Warning", - "Microsoft.Hosting.Lifetime": "Information" - } - } -} diff --git a/ZR.Admin.WebApi/appsettings.json b/ZR.Admin.WebApi/appsettings.json index 8983e0f..4416867 100644 --- a/ZR.Admin.WebApi/appsettings.json +++ b/ZR.Admin.WebApi/appsettings.json @@ -5,5 +5,33 @@ "Microsoft": "Warning", "Microsoft.Hosting.Lifetime": "Information" } + }, + "ConnectionStrings": { + "conn_zrAdmin": "server=127.0.0.1;user=zr;pwd=abc;database=admin" + }, + "conn_zrAdmin_Type": 0, //MySql = 0, SqlServer = 1 + "urls": "http://localhost:8888", //Ŀurl + "sysConfig": { + "DBCommandTimeout": 10, + "tokenExpire": 1440,//Jwt tokenʱʱ䣨֣ + "cors": "http://localhost:8887" //ַ"," + }, + "DemoMode": false, //Ƿʾģʽ + "DbKey": "", //ݿkey + "Upload": { + "UploadDirectory": "/", + "UploadUrl": "http://localhost:8888" + }, + "ALYUN_OCS": { + "REGIONID": "cn-hangzhou", + "KEY": "XX", + "SECRET": "XX" + }, + "gen": { + "conn": "server=127.0.0.1;user=zr;pwd=abc;database={database}", + "dbType": 0, //MySql = 0, SqlServer = 1 + "autoPre": true, //Զȥǰ׺ + "author": "zr", + "tablePrefix": "live_,sys_" //"ǰ׺ǰ׺öŷָ", } } diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/ControllersTemplate.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/ControllersTemplate.txt new file mode 100644 index 0000000..af2cc5c --- /dev/null +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/ControllersTemplate.txt @@ -0,0 +1,134 @@ +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 {ModelsNamespace}.Dto; +using {ModelsNamespace}.Models; +using {ServicesNamespace}.Business; +using {ApiControllerNamespace}.Extensions; +using {ApiControllerNamespace}.Filters; +using ZR.Common; + +namespace {ApiControllerNamespace}.Controllers +{ + /// + /// 代码自动生成 + /// + [Verify] + [Route("{ModuleName}/{ModelName}")] + public class {ModelName}Controller: BaseController + { + /// + /// {TableDesc}接口 + /// + private readonly I{ModelName}Service _{ModelName}Service; + + public {ModelName}Controller(I{ModelName}Service {ModelName}Service) + { + _{ModelName}Service = {ModelName}Service; + } + + /// + /// 查询{TableDesc}列表 + /// + /// + [HttpGet("list")] + [ActionPermissionFilter(Permission = "{Permission}:list")] + public IActionResult Query{ModelName}([FromQuery] {ModelName}QueryDto parm) + { + //开始拼装查询条件 + var predicate = Expressionable.Create<{ModelName}>(); + + //TODO 搜索条件 + //predicate = predicate.And(m => m.Name.Contains(parm.Name)); + + var response = _{ModelName}Service.GetPages(predicate.ToExpression(), parm); + + return SUCCESS(response); + } + + /// + /// 查询{TableDesc}详情 + /// + /// + /// + [HttpGet("{{PrimaryKey}}")] + [ActionPermissionFilter(Permission = "{Permission}:query")] + public IActionResult Get{ModelName}({PKCsharpType} {PrimaryKey}) + { + var response = _{ModelName}Service.GetId({PrimaryKey}); + + return SUCCESS(response); + } + + /// + /// 添加{TableDesc} + /// + /// + [HttpPost] + [ActionPermissionFilter(Permission = "{Permission}:add")] + [Log(Title = "{TableDesc}添加", BusinessType = BusinessType.INSERT)] + public IActionResult Add{ModelName}([FromBody] {ModelName}Dto parm) + { + if (parm == null) + { + throw new CustomException("请求参数错误"); + } + //从 Dto 映射到 实体 + var model = parm.Adapt<{ModelName}>().ToCreate(); + + return SUCCESS(_{ModelName}Service.Add(model, it => new + { + {InsertColumn} + })); + } + + /// + /// 更新{TableDesc} + /// + /// + [HttpPut] + [ActionPermissionFilter(Permission = "{Permission}:update")] + [Log(Title = "{TableDesc}修改", BusinessType = BusinessType.UPDATE)] + public IActionResult Update{ModelName}([FromBody] {ModelName}Dto parm) + { + if (parm == null) + { + throw new CustomException("请求实体不能为空"); + } + //从 Dto 映射到 实体 + var model = parm.Adapt<{ModelName}>().ToUpdate(); + + var response = _{ModelName}Service.Update(w => w.{PrimaryKey} == model.{PrimaryKey}, it => new {ModelName}() + { + //Update 字段映射 + {UpdateColumn} + }); + + return SUCCESS(response); + } + + /// + /// 删除{TableDesc} + /// + /// + [HttpDelete("{ids}")] + [ActionPermissionFilter(Permission = "{Permission}:delete")] + [Log(Title = "{TableDesc}删除", BusinessType = BusinessType.DELETE)] + public IActionResult Delete{ModelName}(string ids) + { + int[] idsArr = Tools.SpitIntArrary(ids); + if (idsArr.Length <= 0) { return OutputJson(ApiResult.Error($"删除失败Id 不能为空")); } + + var response = _{ModelName}Service.Delete(idsArr); + + return SUCCESS(response); + } + } +} \ No newline at end of file diff --git a/ZR.Admin.WebApi/Template/IServiceTemplate.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/IServiceTemplate.txt similarity index 100% rename from ZR.Admin.WebApi/Template/IServiceTemplate.txt rename to ZR.Admin.WebApi/wwwroot/CodeGenTemplate/IServiceTemplate.txt diff --git a/ZR.Admin.WebApi/Template/InputDtoTemplate.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/InputDtoTemplate.txt similarity index 82% rename from ZR.Admin.WebApi/Template/InputDtoTemplate.txt rename to ZR.Admin.WebApi/wwwroot/CodeGenTemplate/InputDtoTemplate.txt index 656cdad..0398c07 100644 --- a/ZR.Admin.WebApi/Template/InputDtoTemplate.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/InputDtoTemplate.txt @@ -13,8 +13,12 @@ namespace {DtosNamespace}.Dto {PropertyName} } + /// + /// {TableNameDesc}查询对象模型 + /// public class {ModelTypeName}QueryDto: PagerInfo { +{QueryProperty} public DateTime? BeginTime { get; set; } public DateTime? EndTime { get; set; } } diff --git a/ZR.Admin.WebApi/Template/ModelTemplate.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/ModelTemplate.txt similarity index 100% rename from ZR.Admin.WebApi/Template/ModelTemplate.txt rename to ZR.Admin.WebApi/wwwroot/CodeGenTemplate/ModelTemplate.txt diff --git a/ZR.Admin.WebApi/Template/RepositoryTemplate.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/RepositoryTemplate.txt similarity index 100% rename from ZR.Admin.WebApi/Template/RepositoryTemplate.txt rename to ZR.Admin.WebApi/wwwroot/CodeGenTemplate/RepositoryTemplate.txt diff --git a/ZR.Admin.WebApi/Template/ServiceTemplate.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/ServiceTemplate.txt similarity index 95% rename from ZR.Admin.WebApi/Template/ServiceTemplate.txt rename to ZR.Admin.WebApi/wwwroot/CodeGenTemplate/ServiceTemplate.txt index 1c88cf6..340390a 100644 --- a/ZR.Admin.WebApi/Template/ServiceTemplate.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/ServiceTemplate.txt @@ -9,7 +9,6 @@ using System.Text; using ZR.Common; using {ModelsNamespace}.Models; using {IRepositoriesNamespace}; -using {ServicesNamespace}.IService; namespace {ServicesNamespace}.Business { diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/SqlTemplate.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/SqlTemplate.txt new file mode 100644 index 0000000..f6e1aff --- /dev/null +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/SqlTemplate.txt @@ -0,0 +1,19 @@ +-- 菜单 +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}'); + +-- 按钮父菜单id +declare @menuId int = @@identity + + +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 ('查询', @menuId, 1, '#', NULL, 0, 0, 'F', '0', '0', '{Permission}:query', '', '', GETDATE(), '', NULL, ''); + +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 ('新增', @menuId, 1, '#', NULL, 0, 0, 'F', '0', '0', '{Permission}:add', '', '', GETDATE(), '', NULL, NULL); + +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 ('删除', @menuId, 2, '#', NULL, 0, 0, 'F', '0', '0', '{Permission}:delete', '', '', GETDATE(), '', NULL, NULL); + +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 ('修改', @menuId, 3, '#', NULL, 0, 0, 'F', '0', '0', '{Permission}:update', '', '', GETDATE(), '', NULL, NULL); diff --git a/ZR.Admin.WebApi/Template/VueJsTemplate.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/VueJsTemplate.txt similarity index 73% rename from ZR.Admin.WebApi/Template/VueJsTemplate.txt rename to ZR.Admin.WebApi/wwwroot/CodeGenTemplate/VueJsTemplate.txt index 719dfc7..d4efae3 100644 --- a/ZR.Admin.WebApi/Template/VueJsTemplate.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/VueJsTemplate.txt @@ -4,11 +4,11 @@ * {ModelTypeDesc}分页查询 * @param {查询条件} data */ -export function list{ModelTypeName}(data) { +export function list{ModelTypeName}(query) { return request({ - url: 'bus/{ModelTypeName}/list', + url: '{ModuleName}/{ModelTypeName}/list', method: 'get', - params: data, + params: query, }) } @@ -18,7 +18,7 @@ export function list{ModelTypeName}(data) { */ export function add{ModelTypeName}(data) { return request({ - url: '/bus/{ModelTypeName}', + url: '{ModuleName}/{ModelTypeName}', method: 'post', data: data, }) @@ -30,7 +30,7 @@ export function add{ModelTypeName}(data) { */ export function update{ModelTypeName}(data) { return request({ - url: '/bus/{ModelTypeName}', + url: '{ModuleName}/{ModelTypeName}', method: 'PUT', data: data, }) @@ -42,7 +42,7 @@ export function update{ModelTypeName}(data) { */ export function get{ModelTypeName}(id) { return request({ - url: '/bus/{ModelTypeName}/' + id, + url: '{ModuleName}/{ModelTypeName}/' + id, method: 'get' }) } @@ -53,7 +53,7 @@ export function get{ModelTypeName}(id) { */ export function del{ModelTypeName}(pid) { return request({ - url: '/bus/{ModelTypeName}/' + pid, + url: '{ModuleName}/{ModelTypeName}/' + pid, method: 'delete' }) } diff --git a/ZR.Admin.WebApi/Template/VueTemplate.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/VueTemplate.txt similarity index 73% rename from ZR.Admin.WebApi/Template/VueTemplate.txt rename to ZR.Admin.WebApi/wwwroot/CodeGenTemplate/VueTemplate.txt index ac347d3..bca90fa 100644 --- a/ZR.Admin.WebApi/Template/VueTemplate.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/VueTemplate.txt @@ -1,24 +1,8 @@  @@ -44,6 +47,7 @@ import Hamburger from "@/components/Hamburger"; import Screenfull from "@/components/Screenfull"; import SizeSelect from "@/components/SizeSelect"; import Search from "@/components/HeaderSearch"; +import ZrGit from "@/components/Zr/Git"; export default { components: { @@ -52,6 +56,7 @@ export default { Screenfull, SizeSelect, Search, + ZrGit, }, computed: { ...mapGetters(["sidebar", "avatar", "device"]), diff --git a/ZR.Vue/src/router/index.js b/ZR.Vue/src/router/index.js index d0fd641..3dd9d34 100644 --- a/ZR.Vue/src/router/index.js +++ b/ZR.Vue/src/router/index.js @@ -44,7 +44,7 @@ export const constantRoutes = [ }, { path: '/demo', - component: (resolve) => require(['@/views/demo'], resolve), + component: (resolve) => require(['@/views/gendemo/index'], resolve), hidden: true }, { diff --git a/ZR.Vue/src/utils/zipdownload.js b/ZR.Vue/src/utils/zipdownload.js index faa613c..cffbc9a 100644 --- a/ZR.Vue/src/utils/zipdownload.js +++ b/ZR.Vue/src/utils/zipdownload.js @@ -1,4 +1,5 @@ import axios from 'axios' +import request from '@/utils/request' import { getToken } from '@/utils/auth' const mimeMap = { @@ -9,9 +10,9 @@ const mimeMap = { const baseUrl = process.env.VUE_APP_BASE_API export function downLoadZip(str, filename) { var url = baseUrl + str - axios({ + request({ method: 'get', - url: url, + url: str, responseType: 'blob', headers: { 'Token': getToken() } }).then(res => { @@ -40,7 +41,7 @@ export function resolveBlob(res, mimeType) { // //从response的headers中获取filename, 后端response.setHeader("Content-disposition", "attachment; filename=xxxx.docx") 设置的文件名; var patt = new RegExp('filename=([^;]+\\.[^\\.;]+);*') - var contentDisposition = decodeURI(res.headers['content-disposition']) + var contentDisposition = decodeURI(res.headers['Content-disposition']) var result = patt.exec(contentDisposition) var fileName = result[1] fileName = fileName.replace(/\"/g, '') @@ -68,3 +69,23 @@ export function resolveExcel(res, fileName) { // 5.释放这个临时的对象url // window.URL.revokeObjectURL(aLink.href); } + +/** + * 下载文件调用 + * @param 接口返回数据 文件名 + */ + export function downloadFile(resUrl, fileName) { + if (!resUrl) { + return + } + // 创建下载链接 + const url = resUrl + const link = document.createElement('a') + link.style.display = 'none' + link.href = url + link.setAttribute('download', fileName)// 文件名 + document.body.appendChild(link) + link.click() + document.body.removeChild(link) // 下载完成移除元素 + window.URL.revokeObjectURL(url) // 释放掉blob对象 +} diff --git a/ZR.Vue/src/views/gendemo/index.vue b/ZR.Vue/src/views/gendemo/index.vue deleted file mode 100644 index 8bb4ec9..0000000 --- a/ZR.Vue/src/views/gendemo/index.vue +++ /dev/null @@ -1,279 +0,0 @@ - - - diff --git a/ZR.Vue/src/views/tool/gen/basicInfoForm.vue b/ZR.Vue/src/views/tool/gen/basicInfoForm.vue index 757962c..afe4a5b 100644 --- a/ZR.Vue/src/views/tool/gen/basicInfoForm.vue +++ b/ZR.Vue/src/views/tool/gen/basicInfoForm.vue @@ -1,23 +1,23 @@