From 23187ed8c549e93bb03afa283a2eb2ce830a1f14 Mon Sep 17 00:00:00 2001 From: izory <791736813@qq.com> Date: Mon, 6 Sep 2021 17:06:36 +0800 Subject: [PATCH 01/28] =?UTF-8?q?fix=20=E8=87=AA=E5=A2=9E=E6=A0=87?= =?UTF-8?q?=E8=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ZR.Model/System/SysMenu.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ZR.Model/System/SysMenu.cs b/ZR.Model/System/SysMenu.cs index 1af655c..36f53f7 100644 --- a/ZR.Model/System/SysMenu.cs +++ b/ZR.Model/System/SysMenu.cs @@ -13,7 +13,7 @@ namespace ZR.Model.System /// 菜单ID /// //[Key]//非自动增长主键时使用ExplicitKey - [SqlSugar.SugarColumn(IsPrimaryKey = true)] + [SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)] public long menuId { get; set; } /// /// 菜单名称 From c1e014a5d05faed37638fe0f6df8a986dfa98547 Mon Sep 17 00:00:00 2001 From: izory <791736813@qq.com> Date: Mon, 6 Sep 2021 18:35:36 +0800 Subject: [PATCH 02/28] =?UTF-8?q?=E5=BC=80=E5=8F=91=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E7=94=9F=E6=88=90=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ZR.Admin.WebApi/Controllers/BaseController.cs | 10 +- .../Controllers/CodeGeneratorController.cs | 60 ++++ ZR.Admin.WebApi/appsettings.Development.json | 1 + ZR.Admin.WebApi/appsettings.Production.json | 1 + ZR.Model/CodeGenerator/DataBaseInfo.cs | 14 + ZR.Model/CodeGenerator/DbFieldInfo.cs | 78 +++++ ZR.Model/CodeGenerator/DbTableInfo.cs | 75 +++++ .../System/CodeGeneratorRepository.cs | 34 ++ ZR.Service/IService/ICodeGeneratorService.cs | 17 + ZR.Service/System/CodeGeneratorService.cs | 67 ++++ ZR.Vue/src/api/tool/gen.js | 64 ++++ ZR.Vue/src/views/demo.vue | 2 +- ZR.Vue/src/views/tool/index.vue | 300 ++++++++++++++++++ ZRAdmin.xml | 20 ++ 14 files changed, 738 insertions(+), 5 deletions(-) create mode 100644 ZR.Admin.WebApi/Controllers/CodeGeneratorController.cs create mode 100644 ZR.Model/CodeGenerator/DataBaseInfo.cs create mode 100644 ZR.Model/CodeGenerator/DbFieldInfo.cs create mode 100644 ZR.Model/CodeGenerator/DbTableInfo.cs create mode 100644 ZR.Repository/System/CodeGeneratorRepository.cs create mode 100644 ZR.Service/IService/ICodeGeneratorService.cs create mode 100644 ZR.Service/System/CodeGeneratorService.cs create mode 100644 ZR.Vue/src/views/tool/index.vue diff --git a/ZR.Admin.WebApi/Controllers/BaseController.cs b/ZR.Admin.WebApi/Controllers/BaseController.cs index 49413f1..5436fb8 100644 --- a/ZR.Admin.WebApi/Controllers/BaseController.cs +++ b/ZR.Admin.WebApi/Controllers/BaseController.cs @@ -22,6 +22,12 @@ namespace ZR.Admin.WebApi.Controllers return Content(jsonStr, "application/json"); } + protected IActionResult ToRespose(ResultCode resultCode, object data = null) + { + string jsonStr = GetJsonStr(GetApiResult(resultCode, data), ""); + return Content(jsonStr, "application/json"); + } + /// /// json输出带时间格式的 /// @@ -40,10 +46,6 @@ namespace ZR.Admin.WebApi.Controllers return Content(jsonStr, "application/json"); } - protected string SerializeObject(object obj) - { - return JsonConvert.SerializeObject(obj); - } /// /// 响应返回结果 diff --git a/ZR.Admin.WebApi/Controllers/CodeGeneratorController.cs b/ZR.Admin.WebApi/Controllers/CodeGeneratorController.cs new file mode 100644 index 0000000..83c32a1 --- /dev/null +++ b/ZR.Admin.WebApi/Controllers/CodeGeneratorController.cs @@ -0,0 +1,60 @@ +using Infrastructure; +using Infrastructure.Model; +using Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using ZR.Model; +using ZR.Model.CodeGenerator; +using ZR.Service.IService; +using ZR.Service.System; + +namespace ZR.Admin.WebApi.Controllers +{ + /// + /// 代码生成 + /// + [Route("codeGenerator")] + public class CodeGeneratorController : BaseController + { + public ICodeGeneratorService CodeGeneratorService; + public CodeGeneratorController(ICodeGeneratorService codeGeneratorService) + { + CodeGeneratorService = codeGeneratorService; + } + + /// + /// 获取所有数据库的信息 + /// + /// + [HttpGet("GetListDataBase")] + //[YuebonAuthorize("GetListDataBase")] + //[NoPermissionRequired] + public IActionResult GetListDataBase() + { + List listTable = CodeGeneratorService.GetAllDataBases("SqlServer"); + + return SUCCESS(listTable); + } + + /// + ///获取所有表根据数据名 + /// + /// 数据库名 + /// 表名 + /// 分页信息 + /// + [HttpGet("FindListTable")] + public IActionResult FindListTable(string enCode, string keywords, PagerInfo pagerInfo) + { + if (string.IsNullOrEmpty(enCode)) + { + return ToRespose(ResultCode.PARAM_ERROR); + } + List listTable = CodeGeneratorService.GetTablesWithPage(keywords, enCode, pagerInfo); + + return SUCCESS(listTable); + } + } +} diff --git a/ZR.Admin.WebApi/appsettings.Development.json b/ZR.Admin.WebApi/appsettings.Development.json index 8d64c6d..7bda31a 100644 --- a/ZR.Admin.WebApi/appsettings.Development.json +++ b/ZR.Admin.WebApi/appsettings.Development.json @@ -18,6 +18,7 @@ "DemoMode": false, //Ƿʾģʽ "DbKey": "", "DbType": 0, //MySql = 0, SqlServer = 1, Sqlite = 2, Oracle = 3, PostgreSQL = 4, + "CodeGenDbType": 0,//ݿ "Upload": { "UploadDirectory": "/", "UploadUrl": "http://localhost:8888" diff --git a/ZR.Admin.WebApi/appsettings.Production.json b/ZR.Admin.WebApi/appsettings.Production.json index 68ffe8e..e709dfb 100644 --- a/ZR.Admin.WebApi/appsettings.Production.json +++ b/ZR.Admin.WebApi/appsettings.Production.json @@ -18,6 +18,7 @@ "DemoMode": false, //Ƿʾģʽ "DbKey": "", "DbType": 0, //MySql = 0, SqlServer = 1, Sqlite = 2, Oracle = 3, PostgreSQL = 4, + "CodeGenDbType": 0, //ݿ "Upload": { "UploadDirectory": "/", "UploadUrl": "http://localhost:8888" diff --git a/ZR.Model/CodeGenerator/DataBaseInfo.cs b/ZR.Model/CodeGenerator/DataBaseInfo.cs new file mode 100644 index 0000000..3d8c16d --- /dev/null +++ b/ZR.Model/CodeGenerator/DataBaseInfo.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace ZR.Model.CodeGenerator +{ + public class DataBaseInfo + { + /// + /// 数据库名称 + /// + public string DbName { get; set; } + } +} diff --git a/ZR.Model/CodeGenerator/DbFieldInfo.cs b/ZR.Model/CodeGenerator/DbFieldInfo.cs new file mode 100644 index 0000000..f176895 --- /dev/null +++ b/ZR.Model/CodeGenerator/DbFieldInfo.cs @@ -0,0 +1,78 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Text; + +namespace ZR.Model +{ + /// + /// 表的字段 + /// + public class DbFieldInfo + { + /// + /// 初始化 + /// + public DbFieldInfo() + { + FieldName = string.Empty; + Description = string.Empty; + } + /// + /// 字段名称 + /// + public string FieldName { get; set; } + /// + /// 描述 + /// + public string Description { get; set; } + /// + /// 系统数据类型,如 int + /// + public string DataType + { + get; + set; + } + + /// + /// 数据库里面存放的类型。 + /// + public string FieldType { get; set; } + + /// + /// 代表小数位精度。 + /// + public long? FieldScale { get; set; } + /// + /// 数据精度,仅数字类型有效,总共多少位数字(10进制)。 + /// 在MySql里面代表了字段长度 + /// + public long? FieldPrecision { get; set; } + + /// + /// + /// + public long? FieldMaxLength { get; set; } + + /// + /// 可空 + /// + public bool IsNullable { get; set; } + /// + /// 是否为主键字段 + /// + public bool IsIdentity { get; set; } + /// + /// 【未用上】该字段是否自增 + /// + public bool Increment { get; set; } + + + /// + /// 默认值 + /// + public string FieldDefaultValue { get; set; } + + } +} diff --git a/ZR.Model/CodeGenerator/DbTableInfo.cs b/ZR.Model/CodeGenerator/DbTableInfo.cs new file mode 100644 index 0000000..0752175 --- /dev/null +++ b/ZR.Model/CodeGenerator/DbTableInfo.cs @@ -0,0 +1,75 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace ZR.Model +{ + /// + /// 数据表的信息 + /// + public class DbTableInfo + { + /// + /// 表格ID,表的名称。 + /// + public string TableName { get; set; } + + /// + /// 表的别称,或者描述 + /// + public string Description { get; set; } + /// + /// 字段列表 + /// + public List Fileds { get; set; } + /// + /// 初始化 + /// + public DbTableInfo() + { + Fileds = new List(); + } + + /// + /// 获取主键的名称列表。 + /// + /// + public List GetIdentityList() + { + var list = Fileds.Where(x => x.IsIdentity); + if (list == null) return null; + return list.Select(x => x.FieldName).ToList(); + } + /// + /// 获取主键字段列表 + /// + /// + public List GetIdentityFields() + { + var list = Fileds.Where(x => x.IsIdentity); + if (list == null) return null; + return list.ToList(); + } + /// + /// 获取可空字段。 + /// + /// + public List GetIsNullableFields() + { + var list = Fileds.Where(x => x.IsNullable); + if (list == null) return null; + return list.ToList(); + } + /// + /// 获取不可空字段。 + /// + /// + public List GetNotNullableFields() + { + var list = Fileds.Where(x => !x.IsNullable); + if (list == null) return null; + return list.ToList(); + } + } +} diff --git a/ZR.Repository/System/CodeGeneratorRepository.cs b/ZR.Repository/System/CodeGeneratorRepository.cs new file mode 100644 index 0000000..4e9fedb --- /dev/null +++ b/ZR.Repository/System/CodeGeneratorRepository.cs @@ -0,0 +1,34 @@ +using Infrastructure.Attribute; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ZR.Model; +using ZR.Model.CodeGenerator; + +namespace ZR.Repository.System +{ + [AppService(ServiceLifetime = LifeTime.Transient)] + public class CodeGeneratorRepository: BaseRepository + { + /// + /// 获取数据库信息 + /// + /// + public List GetAllDataBaseInfos() + { + return Db.Ado.SqlQuery("select name as DbName from master..sysdatabases "); + } + + /// + /// 获取所有的表 + /// + /// + public List GetAllTables(string dbName) + { + string sql = $"SELECT name as TableName FROM {dbName}..SysObjects Where XType='U' ORDER BY Name"; + return Db.Ado.SqlQuery(sql, new { dbName}); + } + } +} diff --git a/ZR.Service/IService/ICodeGeneratorService.cs b/ZR.Service/IService/ICodeGeneratorService.cs new file mode 100644 index 0000000..db7798e --- /dev/null +++ b/ZR.Service/IService/ICodeGeneratorService.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ZR.Model; +using ZR.Model.CodeGenerator; + +namespace ZR.Service.IService +{ + public interface ICodeGeneratorService + { + List GetAllDataBases(string dbType); + + List GetTablesWithPage(string tablename, string dbName, PagerInfo info); + } +} diff --git a/ZR.Service/System/CodeGeneratorService.cs b/ZR.Service/System/CodeGeneratorService.cs new file mode 100644 index 0000000..2a8b4f7 --- /dev/null +++ b/ZR.Service/System/CodeGeneratorService.cs @@ -0,0 +1,67 @@ +using Infrastructure; +using Infrastructure.Attribute; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ZR.Model; +using ZR.Model.CodeGenerator; +using ZR.Repository.System; +using ZR.Service.IService; + +namespace ZR.Service.System +{ + /// + /// + /// + [AppService(ServiceType = typeof(ICodeGeneratorService), ServiceLifetime = LifeTime.Transient)] + public class CodeGeneratorService: ICodeGeneratorService + { + public CodeGeneratorRepository CodeGeneratorRepository; + + public CodeGeneratorService(CodeGeneratorRepository codeGeneratorRepository) + { + CodeGeneratorRepository = codeGeneratorRepository; + } + + /// + /// 获取所有数据库名 + /// + /// + public List GetAllDataBases(string dbType) + { + List list = new List(); + if (dbType.Contains("SqlServer")) + { + list = CodeGeneratorRepository.GetAllDataBaseInfos(); + } + else if (dbType.Contains("MySql")) + { + // list = mssqlExtractor.GetAllDataBases(); + } + return list; + } + + public List GetTablesWithPage(string tablename, string dbName, PagerInfo info) + { + var dbType = ConfigUtils.Instance.GetConfig("CodeGenDbType"); + List list = new List(); + if (dbType == "1") + { + list = CodeGeneratorRepository.GetAllTables(dbName); + } + else if (dbType.Contains("MySql")) + { + //list = mysqlExtractor.GetAllTables(this.dbName, tablename, fieldNameToSort, isDescending, info); + } + if (!string.IsNullOrEmpty(tablename)) + { + list = list.Where(f => f.TableName.Contains(tablename)).ToList(); + } + + return list; + } + + } +} diff --git a/ZR.Vue/src/api/tool/gen.js b/ZR.Vue/src/api/tool/gen.js index 4506927..88e4a3d 100644 --- a/ZR.Vue/src/api/tool/gen.js +++ b/ZR.Vue/src/api/tool/gen.js @@ -74,3 +74,67 @@ export function synchDb(tableName) { method: 'get' }) } + +/**新的代码生成 */ + +/** + * 创建数据库连接 + */ + export function createGetDBConn(data) { + return request({ + url: 'CodeGenerator/CreateDBConn', + method: 'post', + data: data, + }) +} +/** + * 获取数据库 + */ +export function codeGetDBList() { + return request({ + url: 'CodeGenerator/GetListDataBase', + method: 'get', + }) +} +/** + * 获取数据库表 + */ +export function codeGetTableList(data) { + return request({ + url: 'CodeGenerator/FindListTable', + method: 'get', + params: data, + }) +} +/** + * 生成代码 + */ +export async function codeGenerator(data) { + return await request({ + url: 'CodeGenerator/Generate', + method: 'get', + params: data, + timeout: 0, + }) +} +/** + * +* 数据库解密 +*/ +export function dbtoolsConnStrDecrypt(data) { + return request({ + url: 'DbTools/ConnStrDecrypt', + method: 'post', + params: data, + }) +} +/** + * 数据库加密 + */ +export function dbtoolsConnStrEncrypt(data) { + return request({ + url: 'DbTools/ConnStrEncrypt', + method: 'post', + params: data, + }) +} diff --git a/ZR.Vue/src/views/demo.vue b/ZR.Vue/src/views/demo.vue index 51f7a1e..7c0c302 100644 --- a/ZR.Vue/src/views/demo.vue +++ b/ZR.Vue/src/views/demo.vue @@ -158,7 +158,7 @@ export default { name: "你好", userId: 1000001, sortId: 1, - address: "浙江省杭州市西湖区", + address: "", content: "我是一个超长超长的文字啊", addtime: "2021-8-7 23:00:00", }, diff --git a/ZR.Vue/src/views/tool/index.vue b/ZR.Vue/src/views/tool/index.vue new file mode 100644 index 0000000..56a51b4 --- /dev/null +++ b/ZR.Vue/src/views/tool/index.vue @@ -0,0 +1,300 @@ + + + diff --git a/ZRAdmin.xml b/ZRAdmin.xml index de38893..974524e 100644 --- a/ZRAdmin.xml +++ b/ZRAdmin.xml @@ -27,6 +27,26 @@ + + + 代码生成 + + + + + 获取所有数据库的信息 + + + + + + 获取所有表根据数据名 + + 数据库名 + 表名 + 分页信息 + + 心跳 From 37155011f09bb4f72d26ba5175e40466327906d3 Mon Sep 17 00:00:00 2001 From: izory <791736813@qq.com> Date: Mon, 6 Sep 2021 21:37:32 +0800 Subject: [PATCH 03/28] =?UTF-8?q?=E5=BC=80=E5=8F=91=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E7=94=9F=E6=88=90=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/CodeGeneratorController.cs | 21 ++++++++++++--- ZR.Repository/DbProvider/SugarDbContext.cs | 1 + .../System/CodeGeneratorRepository.cs | 19 +++++++++++--- ZR.Service/System/CodeGeneratorService.cs | 12 ++++----- ZR.Vue/src/views/tool/index.vue | 26 ++++++++----------- ZRAdmin.xml | 8 +++++- 6 files changed, 57 insertions(+), 30 deletions(-) diff --git a/ZR.Admin.WebApi/Controllers/CodeGeneratorController.cs b/ZR.Admin.WebApi/Controllers/CodeGeneratorController.cs index 83c32a1..e4ba737 100644 --- a/ZR.Admin.WebApi/Controllers/CodeGeneratorController.cs +++ b/ZR.Admin.WebApi/Controllers/CodeGeneratorController.cs @@ -7,6 +7,7 @@ using System.Linq; using System.Threading.Tasks; using ZR.Model; using ZR.Model.CodeGenerator; +using ZR.Model.Vo; using ZR.Service.IService; using ZR.Service.System; @@ -43,18 +44,30 @@ namespace ZR.Admin.WebApi.Controllers /// /// 数据库名 /// 表名 - /// 分页信息 + /// 分页信息 /// [HttpGet("FindListTable")] - public IActionResult FindListTable(string enCode, string keywords, PagerInfo pagerInfo) + public IActionResult FindListTable(string enCode, string keywords, PagerInfo pager) { if (string.IsNullOrEmpty(enCode)) { return ToRespose(ResultCode.PARAM_ERROR); } - List listTable = CodeGeneratorService.GetTablesWithPage(keywords, enCode, pagerInfo); + List list = CodeGeneratorService.GetTablesWithPage(keywords, enCode, pager); + var vm = new VMPageResult(list, pager); - return SUCCESS(listTable); + return SUCCESS(vm); + } + + /// + /// 生成代码 + /// + /// + [HttpGet("Generate")] + public IActionResult Generate() + { + + return SUCCESS(null); } } } diff --git a/ZR.Repository/DbProvider/SugarDbContext.cs b/ZR.Repository/DbProvider/SugarDbContext.cs index 67ec657..2aa9b4e 100644 --- a/ZR.Repository/DbProvider/SugarDbContext.cs +++ b/ZR.Repository/DbProvider/SugarDbContext.cs @@ -27,6 +27,7 @@ namespace ZR.Repository.DbProvider { connStr = NETCore.Encrypt.EncryptProvider.DESDecrypt(connStr, dbKey); } + Db = new SqlSugarClient(new List() { new ConnectionConfig(){ diff --git a/ZR.Repository/System/CodeGeneratorRepository.cs b/ZR.Repository/System/CodeGeneratorRepository.cs index 4e9fedb..7455f89 100644 --- a/ZR.Repository/System/CodeGeneratorRepository.cs +++ b/ZR.Repository/System/CodeGeneratorRepository.cs @@ -10,7 +10,7 @@ using ZR.Model.CodeGenerator; namespace ZR.Repository.System { [AppService(ServiceLifetime = LifeTime.Transient)] - public class CodeGeneratorRepository: BaseRepository + public class CodeGeneratorRepository : BaseRepository { /// /// 获取数据库信息 @@ -24,11 +24,22 @@ namespace ZR.Repository.System /// /// 获取所有的表 /// + /// + /// + /// /// - public List GetAllTables(string dbName) + public List GetAllTables(string dbName, string tableName, PagerInfo pager) { - string sql = $"SELECT name as TableName FROM {dbName}..SysObjects Where XType='U' ORDER BY Name"; - return Db.Ado.SqlQuery(sql, new { dbName}); + string sql = $"SELECT name as TableName FROM {dbName}..SysObjects Where XType='U'"; + int total = 0; + var list = Db.SqlQueryable(sql) + //.WithCache(60 * 10) + .WhereIF(!string.IsNullOrEmpty(tableName), it => it.TableName.Contains(tableName)) + .AddParameters(new { dbName }) + .OrderBy(x => x.TableName) + .ToPageList(pager.PageNum, pager.PageSize, ref total); + pager.TotalNum = total; + return list; } } } diff --git a/ZR.Service/System/CodeGeneratorService.cs b/ZR.Service/System/CodeGeneratorService.cs index 2a8b4f7..c6b9112 100644 --- a/ZR.Service/System/CodeGeneratorService.cs +++ b/ZR.Service/System/CodeGeneratorService.cs @@ -43,22 +43,22 @@ namespace ZR.Service.System return list; } - public List GetTablesWithPage(string tablename, string dbName, PagerInfo info) + public List GetTablesWithPage(string tablename, string dbName, PagerInfo pager) { var dbType = ConfigUtils.Instance.GetConfig("CodeGenDbType"); List list = new List(); if (dbType == "1") { - list = CodeGeneratorRepository.GetAllTables(dbName); + list = CodeGeneratorRepository.GetAllTables(dbName, tablename, pager); } else if (dbType.Contains("MySql")) { //list = mysqlExtractor.GetAllTables(this.dbName, tablename, fieldNameToSort, isDescending, info); } - if (!string.IsNullOrEmpty(tablename)) - { - list = list.Where(f => f.TableName.Contains(tablename)).ToList(); - } + //if (!string.IsNullOrEmpty(tablename)) + //{ + // list = list.Where(f => f.TableName.Contains(tablename)).ToList(); + //} return list; } diff --git a/ZR.Vue/src/views/tool/index.vue b/ZR.Vue/src/views/tool/index.vue index 56a51b4..572bb82 100644 --- a/ZR.Vue/src/views/tool/index.vue +++ b/ZR.Vue/src/views/tool/index.vue @@ -46,12 +46,12 @@ 查询 - - + + - + @@ -129,7 +129,7 @@ export default { }, ], tableData: [], - tableloading: true, + tableloading: false, pagination: { pageNum: 1, pagesize: 20, @@ -146,7 +146,7 @@ export default { created() { this.pagination.pageNum = 1; this.loadData(); - this.loadTableData(); + // this.loadTableData(); }, methods: { loadData: function () { @@ -169,7 +169,7 @@ export default { // Sort: this.sortableData.sort, }; codeGetTableList(seachdata).then((res) => { - this.tableData = res.data; + this.tableData = res.data.result; this.pagination.pageTotal = res.data.totalNum; this.tableloading = false; }); @@ -179,6 +179,7 @@ export default { * 点击查询 */ handleSearch: function () { + this.tableloading = true; this.pagination.pageNum = 1; this.loadTableData(); }, @@ -230,20 +231,15 @@ export default { }; codeGenerator(seachdata) .then((res) => { - if (res.Success) { + if (res.code == 100) { downloadFile( defaultSettings.fileUrl + res.ResData[0], res.ResData[1] ); - this.$message({ - message: "恭喜你,代码生成完成!", - type: "success", - }); + + this.msgSuccess("恭喜你,代码生成完成!"); } else { - this.$message({ - message: res.ErrMsg, - type: "error", - }); + this.msgError(res.msg); } pageLoading.close(); }) diff --git a/ZRAdmin.xml b/ZRAdmin.xml index 974524e..1ca6464 100644 --- a/ZRAdmin.xml +++ b/ZRAdmin.xml @@ -44,9 +44,15 @@ 数据库名 表名 - 分页信息 + 分页信息 + + + 生成代码 + + + 心跳 From 18d8051d659da1f04c6c700c6a5484b378b76cb8 Mon Sep 17 00:00:00 2001 From: izory <791736813@qq.com> Date: Tue, 7 Sep 2021 18:37:21 +0800 Subject: [PATCH 04/28] =?UTF-8?q?=E5=BC=80=E5=8F=91=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E7=94=9F=E6=88=90=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Infrastructure/OptionsSetting.cs | 1 + .../Controllers/CodeGeneratorController.cs | 54 +- ZR.Admin.WebApi/Template/ModelTemplate.txt | 14 + ZR.Admin.WebApi/ZR.Admin.WebApi.csproj | 4 + ZR.CodeGenerator/CodeGenerateOption.cs | 54 ++ ZR.CodeGenerator/CodeGeneratorTool.cs | 322 ++++++++++++ ZR.CodeGenerator/DbProvider.cs | 30 ++ .../Service/CodeGeneraterService.cs | 88 ++++ ZR.CodeGenerator/TableMappingHelper.cs | 2 + ZR.CodeGenerator/ZR.CodeGenerator.csproj | 11 +- ZR.Model/CodeGenerator/DbFieldInfo.cs | 1 + ZR.Model/Models/README.txt | 1 + ZR.Repository/DbProvider/SugarDbContext.cs | 17 + .../System/CodeGeneratorRepository.cs | 59 ++- ZR.Service/IService/ICodeGeneratorService.cs | 16 +- ZR.Service/System/CodeGeneratorService.cs | 112 +++-- ZR.Vue/src/api/monitor/operlog.js | 14 +- ZR.Vue/src/layout/components/Navbar.vue | 8 +- ZR.Vue/src/views/dashboard/bigdata.vue | 218 -------- .../views/dashboard/bigdata/IviewCircle.vue | 88 ---- .../views/dashboard/bigdata/chart-options.js | 471 ------------------ .../src/views/dashboard/bigdata/head_bg.png | Bin 7881 -> 0 bytes .../src/views/dashboard/bigdata/layout.less | 197 -------- ZR.Vue/src/views/monitor/cache/index.vue | 151 ------ ZR.Vue/src/views/monitor/online/index.vue | 128 ----- ZR.Vue/src/views/monitor/operlog/index.vue | 5 +- ZR.Vue/src/views/tool/index.vue | 130 +++-- ZRAdmin.xml | 12 +- 28 files changed, 786 insertions(+), 1422 deletions(-) create mode 100644 ZR.Admin.WebApi/Template/ModelTemplate.txt create mode 100644 ZR.CodeGenerator/CodeGenerateOption.cs create mode 100644 ZR.CodeGenerator/CodeGeneratorTool.cs create mode 100644 ZR.CodeGenerator/DbProvider.cs create mode 100644 ZR.CodeGenerator/Service/CodeGeneraterService.cs create mode 100644 ZR.Model/Models/README.txt delete mode 100644 ZR.Vue/src/views/dashboard/bigdata.vue delete mode 100644 ZR.Vue/src/views/dashboard/bigdata/IviewCircle.vue delete mode 100644 ZR.Vue/src/views/dashboard/bigdata/chart-options.js delete mode 100644 ZR.Vue/src/views/dashboard/bigdata/head_bg.png delete mode 100644 ZR.Vue/src/views/dashboard/bigdata/layout.less delete mode 100644 ZR.Vue/src/views/monitor/cache/index.vue delete mode 100644 ZR.Vue/src/views/monitor/online/index.vue diff --git a/Infrastructure/OptionsSetting.cs b/Infrastructure/OptionsSetting.cs index 4aa2b2e..91d7963 100644 --- a/Infrastructure/OptionsSetting.cs +++ b/Infrastructure/OptionsSetting.cs @@ -7,6 +7,7 @@ namespace Infrastructure public class OptionsSetting { public static string ConnAdmin = "Conn_admin"; + public static string Conn = "ConnDynamic"; public static string DbType = "DbType"; public static string DbKey = "DbKey"; diff --git a/ZR.Admin.WebApi/Controllers/CodeGeneratorController.cs b/ZR.Admin.WebApi/Controllers/CodeGeneratorController.cs index e4ba737..7248560 100644 --- a/ZR.Admin.WebApi/Controllers/CodeGeneratorController.cs +++ b/ZR.Admin.WebApi/Controllers/CodeGeneratorController.cs @@ -1,10 +1,14 @@ using Infrastructure; +using Infrastructure.Attribute; +using Infrastructure.Enums; using Infrastructure.Model; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using ZR.CodeGenerator; +using ZR.CodeGenerator.Service; using ZR.Model; using ZR.Model.CodeGenerator; using ZR.Model.Vo; @@ -19,11 +23,12 @@ namespace ZR.Admin.WebApi.Controllers [Route("codeGenerator")] public class CodeGeneratorController : BaseController { - public ICodeGeneratorService CodeGeneratorService; - public CodeGeneratorController(ICodeGeneratorService codeGeneratorService) - { - CodeGeneratorService = codeGeneratorService; - } + //public ICodeGeneratorService CodeGeneratorService; + //public CodeGeneratorController(ICodeGeneratorService codeGeneratorService) + //{ + // CodeGeneratorService = codeGeneratorService; + //} + private CodeGeneraterService _CodeGeneraterService = new CodeGeneraterService(); /// /// 获取所有数据库的信息 @@ -34,38 +39,53 @@ namespace ZR.Admin.WebApi.Controllers //[NoPermissionRequired] public IActionResult GetListDataBase() { - List listTable = CodeGeneratorService.GetAllDataBases("SqlServer"); - - return SUCCESS(listTable); + return SUCCESS(_CodeGeneraterService.GetAllDataBases()); } /// ///获取所有表根据数据名 /// - /// 数据库名 - /// 表名 + /// 数据库名 + /// 表名 /// 分页信息 /// [HttpGet("FindListTable")] - public IActionResult FindListTable(string enCode, string keywords, PagerInfo pager) + public IActionResult FindListTable(string dbName, string tableName, PagerInfo pager) { - if (string.IsNullOrEmpty(enCode)) + if (string.IsNullOrEmpty(dbName)) { - return ToRespose(ResultCode.PARAM_ERROR); + dbName = "ZrAdmin"; } - List list = CodeGeneratorService.GetTablesWithPage(keywords, enCode, pager); - var vm = new VMPageResult(list, pager); + List list = _CodeGeneraterService.GetAllTables(dbName, tableName, pager); + var vm = new VMPageResult(list, pager); return SUCCESS(vm); } /// - /// 生成代码 + /// 代码生成器 /// + /// + /// 要生成代码的表 + /// 项目命名空间 + /// 要删除表名的字符串用英文逗号","隔开 /// [HttpGet("Generate")] - public IActionResult Generate() + [Log(Title = "代码生成", BusinessType = BusinessType.OTHER)] + public IActionResult Generate(string dbName, string baseSpace, string tables, string replaceTableNameStr) { + if (string.IsNullOrEmpty(baseSpace)) + { + throw new CustomException(ResultCode.CUSTOM_ERROR, "命名空间不能为空"); + } + string[] tableList = tables.Split(","); + List tableInfos = new List();// CodeGeneratorService.GetAllTables(tables); + foreach (var item in tableList) + { + tableInfos.Add(new DbTableInfo() { TableName = item }); + } + + CodeGeneratorTool.Generate(dbName, baseSpace, tableInfos, replaceTableNameStr, true); return SUCCESS(null); } diff --git a/ZR.Admin.WebApi/Template/ModelTemplate.txt b/ZR.Admin.WebApi/Template/ModelTemplate.txt new file mode 100644 index 0000000..47fafe1 --- /dev/null +++ b/ZR.Admin.WebApi/Template/ModelTemplate.txt @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace {ModelsNamespace} +{ + /// + /// {TableNameDesc},数据实体对象 + /// + [SqlSugar.SugarTable("{TableName}")] + public class {ModelTypeName} + { +{ModelContent} + } +} diff --git a/ZR.Admin.WebApi/ZR.Admin.WebApi.csproj b/ZR.Admin.WebApi/ZR.Admin.WebApi.csproj index 9f82d37..ed4e7c1 100644 --- a/ZR.Admin.WebApi/ZR.Admin.WebApi.csproj +++ b/ZR.Admin.WebApi/ZR.Admin.WebApi.csproj @@ -32,6 +32,7 @@ + @@ -56,6 +57,9 @@ TextTemplatingFileGenerator Controller.cs + + Always + diff --git a/ZR.CodeGenerator/CodeGenerateOption.cs b/ZR.CodeGenerator/CodeGenerateOption.cs new file mode 100644 index 0000000..abb237f --- /dev/null +++ b/ZR.CodeGenerator/CodeGenerateOption.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ZR.CodeGenerator +{ + public class CodeGenerateOption + { + /// + /// 项目命名空间 + /// + public string BaseNamespace { get; set; } + /// + /// 数据实体命名空间 + /// + public string ModelsNamespace { get; set; } + /// + /// 输入输出数据实体名称空间 + /// + public string DtosNamespace { get; set; } + /// + /// 仓储接口命名空间 + /// + public string IRepositoriesNamespace { get; set; } + /// + /// 仓储实现名称空间 + /// + public string RepositoriesNamespace { get; set; } + /// + /// 服务接口命名空间 + /// + public string IServicsNamespace { get; set; } + /// + /// 服务接口实现命名空间 + /// + public string ServicesNamespace { get; set; } + + /// + /// Api控制器命名空间 + /// + public string ApiControllerNamespace { get; set; } + + /// + /// 去掉的表头字符 + /// + public string ReplaceTableNameStr { get; set; } + /// + /// 要生数据的表,用“,”分割 + /// + public string TableList { get; set; } + } +} diff --git a/ZR.CodeGenerator/CodeGeneratorTool.cs b/ZR.CodeGenerator/CodeGeneratorTool.cs new file mode 100644 index 0000000..dc84deb --- /dev/null +++ b/ZR.CodeGenerator/CodeGeneratorTool.cs @@ -0,0 +1,322 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using ZR.CodeGenerator.CodeGenerator; +using ZR.CodeGenerator.Service; +using ZR.Model; + +namespace ZR.CodeGenerator +{ + /// + /// 代码生成器。 + /// + /// 根据指定的实体域名空间生成Repositories和Services层的基础代码文件。 + /// + /// + public class CodeGeneratorTool + { + /// + /// 代码生成器配置 + /// + private static CodeGenerateOption _option = new CodeGenerateOption(); + /// + /// InputDto输入实体是不包含字段 + /// + private static string inputDtoNoField = "DeleteMark,CreatorTime,CreatorUserId,CompanyId,DeptId,LastModifyTime,LastModifyUserId,DeleteTime,DeleteUserId,"; + + /// + /// 代码生成器入口方法 + /// + /// + /// 要生成代码的表 + /// + /// + /// 要删除表名称的字符 + /// 是否替换现有文件,为true时替换 + public static void Generate(string dbName, string baseNamespace, List listTable, string replaceTableNameStr, bool ifExsitedCovered = false) + { + _option.DtosNamespace = baseNamespace + ".Dtos"; + _option.ModelsNamespace = baseNamespace + ".Model"; + _option.IRepositoriesNamespace = baseNamespace + ".IRepositories"; + _option.RepositoriesNamespace = baseNamespace + ".Repositories"; + _option.IServicsNamespace = baseNamespace + ".IServices"; + _option.ServicesNamespace = baseNamespace + ".Services"; + _option.ApiControllerNamespace = baseNamespace + "Api"; + _option.ReplaceTableNameStr = replaceTableNameStr; + //_option.TableList = listTable; + _option.BaseNamespace = baseNamespace; + + CodeGeneraterService codeGeneraterService = new CodeGeneraterService(); + //List listTable = dbExtractor.GetWhereTables(_option.TableList); + string profileContent = string.Empty; + foreach (DbTableInfo dbTableInfo in listTable) + { + List listField = codeGeneraterService.GetColumnInfo(dbName, dbTableInfo.TableName); + GenerateSingle(listField, dbTableInfo, ifExsitedCovered); + string tableName = dbTableInfo.TableName; + if (!string.IsNullOrEmpty(_option.ReplaceTableNameStr)) + { + string[] rel = _option.ReplaceTableNameStr.Split(';'); + for (int i = 0; i < rel.Length; i++) + { + if (!string.IsNullOrEmpty(rel[i].ToString())) + { + tableName = tableName.Replace(rel[i].ToString(), ""); + } + } + } + tableName = tableName.Substring(0, 1).ToUpper() + tableName.Substring(1); + profileContent += string.Format(" CreateMap<{0}, {0}OutputDto>();\n", tableName); + profileContent += string.Format(" CreateMap<{0}InputDto, {0}>();\n", tableName); + } + + //GenerateDtoProfile(_option.ModelsNamespace, profileContent, ifExsitedCovered); + } + + + + /// + /// 单表生成代码 + /// + /// 表字段集合 + /// 表信息 + /// 如果目标文件存在,是否覆盖。默认为false + public static void GenerateSingle(List listField, DbTableInfo tableInfo, bool ifExsitedCovered = false) + { + var modelsNamespace = _option.ModelsNamespace; + var modelTypeName = tableInfo.TableName;//表名 + var modelTypeDesc = tableInfo.Description;//表描述 + if (!string.IsNullOrEmpty(_option.ReplaceTableNameStr)) + { + string[] rel = _option.ReplaceTableNameStr.Split(';'); + for (int i = 0; i < rel.Length; i++) + { + if (!string.IsNullOrEmpty(rel[i].ToString())) + { + modelTypeName = modelTypeName.Replace(rel[i].ToString(), ""); + } + } + } + modelTypeName = modelTypeName.Substring(0, 1).ToUpper() + modelTypeName.Substring(1); + string keyTypeName = "string";//主键数据类型 + string modelcontent = "";//数据库模型字段 + string InputDtocontent = "";//输入模型 + string outputDtocontent = "";//输出模型 + string vueViewListContent = string.Empty;//Vue列表输出内容 + string vueViewFromContent = string.Empty;//Vue表单输出内容 + string vueViewEditFromContent = string.Empty;//Vue变量输出内容 + string vueViewEditFromBindContent = string.Empty;//Vue显示初始化输出内容 + string vueViewSaveBindContent = string.Empty;//Vue保存时输出内容 + string vueViewEditFromRuleContent = string.Empty;//Vue数据校验 + + foreach (SqlSugar.DbColumnInfo dbFieldInfo in listField) + { + string columnName = dbFieldInfo.DbColumnName.Substring(0, 1).ToUpper() + dbFieldInfo.DbColumnName.Substring(1); + + modelcontent += " /// \n"; + modelcontent += ($" /// {dbFieldInfo.ColumnDescription}\n"); + modelcontent += " /// \n"; + if (dbFieldInfo.IsIdentity || dbFieldInfo.IsPrimarykey) + { + modelcontent += $" [SugarColumn(IsPrimaryKey = {dbFieldInfo.IsPrimarykey}, IsIdentity = {dbFieldInfo.IsIdentity})]\n"; + } + modelcontent += $" public {TableMappingHelper.GetPropertyDatatype(dbFieldInfo.DataType)} {columnName} {{ get; set; }}\n\r"; + + //主键 + if (dbFieldInfo.IsIdentity) + { + keyTypeName = dbFieldInfo.DataType; + //outputDtocontent += " /// \n"; + //outputDtocontent += string.Format(" /// 设置或获取{0}\n", dbFieldInfo.ColumnDescription); + //outputDtocontent += " /// \n"; + + //outputDtocontent += string.Format(" [SqlSugar.SugarColumn(IsIdentity = true, IsPrimaryKey = true)]\n"); + //outputDtocontent += string.Format(" public {0} {1}", TableMappingHelper.GetPropertyDatatype(dbFieldInfo.DataType), columnName); + //outputDtocontent += " { get; set; }\n\r"; + } + else //非主键 + { + modelcontent += " /// \n"; + modelcontent += string.Format(" /// 设置或获取{0}\n", dbFieldInfo.ColumnDescription); + modelcontent += " /// \n"; + //if (dbFieldInfo.DataType == "string") + //{ + // modelcontent += string.Format(" [MaxLength({0})]\n", dbFieldInfo.FieldMaxLength); + //} + modelcontent += string.Format(" public {0} {1}", TableMappingHelper.GetPropertyDatatype(dbFieldInfo.DataType), columnName); + modelcontent += " { get; set; }\n\r"; + + + //outputDtocontent += " /// \n"; + //outputDtocontent += string.Format(" /// 设置或获取{0}\n", dbFieldInfo.ColumnDescription); + //outputDtocontent += " /// \n"; + //if (dbFieldInfo.DataType == "string") + //{ + // outputDtocontent += string.Format(" [MaxLength({0})]\n", dbFieldInfo.FieldMaxLength); + //} + //outputDtocontent += string.Format(" public {0} {1}", dbFieldInfo.DataType, columnName); + //outputDtocontent += " { get; set; }\n\r"; + //if (dbFieldInfo.DataType == "bool" || dbFieldInfo.DataType == "tinyint") + //{ + + // vueViewListContent += string.Format(" \n", columnName, dbFieldInfo.ColumnDescription); + // vueViewListContent += " \n"; + // vueViewListContent += " \n"; + + // vueViewFromContent += string.Format(" ", dbFieldInfo.ColumnDescription, columnName); + // vueViewFromContent += string.Format(" \n", columnName); + // vueViewFromContent += " \n"; + // vueViewFromContent += " \n"; + // vueViewFromContent += " \n"; + // vueViewFromContent += " \n"; + + // vueViewEditFromContent += string.Format(" {0}: 'true',\n", columnName); + // vueViewEditFromBindContent += string.Format(" this.editFrom.{0} = res.ResData.{0}+''\n", columnName); + //} + //else + //{ + // vueViewListContent += string.Format(" \n", columnName, dbFieldInfo.ColumnDescription); + + // vueViewFromContent += string.Format(" \n", dbFieldInfo.ColumnDescription, columnName); + // vueViewFromContent += string.Format(" \n", columnName, dbFieldInfo.ColumnDescription); + // vueViewFromContent += " \n"; + // vueViewEditFromContent += string.Format(" {0}: '',\n", columnName); + // vueViewEditFromBindContent += string.Format(" this.editFrom.{0} = res.ResData.{0}\n", columnName); + //} + //vueViewSaveBindContent += string.Format(" '{0}':this.editFrom.{0},\n", columnName); + //if (!dbFieldInfo.IsNullable) + //{ + // vueViewEditFromRuleContent += string.Format(" {0}: [\n", columnName); + // vueViewEditFromRuleContent += " {"; + // vueViewEditFromRuleContent += string.Format("required: true, message:\"请输入{0}\", trigger: \"blur\"", dbFieldInfo.ColumnDescription); + // vueViewEditFromRuleContent += "},\n { min: 2, max: 50, message: \"长度在 2 到 50 个字符\", trigger:\"blur\" }\n"; + // vueViewEditFromRuleContent += " ],\n"; + //} + } + + //if (!inputDtoNoField.Contains(columnName) || columnName == "Id") + //{ + // InputDtocontent += " /// \n"; + // InputDtocontent += string.Format(" /// 设置或获取{0}\n", dbFieldInfo.ColumnDescription); + // InputDtocontent += " /// \n"; + // //if (dbFieldInfo.FieldType == "string") + // //{ + // // InputDtocontent += string.Format(" [MaxLength({0})]\n", dbFieldInfo.FieldMaxLength); + // //} + // InputDtocontent += string.Format(" public {0} {1}", dbFieldInfo.DataType, columnName); + // InputDtocontent += " { get; set; }\n\r"; + //} + // + } + GenerateModels(modelsNamespace, modelTypeName, tableInfo.TableName, modelcontent, modelTypeDesc, keyTypeName, ifExsitedCovered); + //GenerateIRepository(modelTypeName, modelTypeDesc, keyTypeName, ifExsitedCovered); + //GenerateRepository(modelTypeName, modelTypeDesc, tableInfo.TableName, keyTypeName, ifExsitedCovered); + //GenerateIService(modelsNamespace, modelTypeName, modelTypeDesc, keyTypeName, ifExsitedCovered); + //GenerateService(modelsNamespace, modelTypeName, modelTypeDesc, keyTypeName, ifExsitedCovered); + //GenerateOutputDto(modelTypeName, modelTypeDesc, outputDtocontent, ifExsitedCovered); + //GenerateInputDto(modelsNamespace, modelTypeName, modelTypeDesc, InputDtocontent, keyTypeName, ifExsitedCovered); + //GenerateControllers(modelTypeName, modelTypeDesc, keyTypeName, ifExsitedCovered); + //GenerateVueViews(modelTypeName, modelTypeDesc, vueViewListContent, vueViewFromContent, vueViewEditFromContent, vueViewEditFromBindContent, vueViewSaveBindContent, vueViewEditFromRuleContent, ifExsitedCovered); + } + + + #region 生成Model + + /// + /// 生成Models文件 + /// + /// 命名空间 + /// 类名 + /// 表名称 + /// 表描述 + /// 数据库表实体内容 + /// 主键数据类型 + /// 如果目标文件存在,是否覆盖。默认为false + private static void GenerateModels(string modelsNamespace, string modelTypeName, string tableName, string modelContent, string modelTypeDesc, string keyTypeName, bool ifExsitedCovered = false) + { + var path = AppDomain.CurrentDomain.BaseDirectory; + //path = path.Substring(0, path.IndexOf("\\bin")); + var parentPath = path.Substring(0, path.LastIndexOf("\\")); + var servicesPath = parentPath + "\\" + _option.BaseNamespace + "\\" + modelsNamespace; + if (!Directory.Exists(servicesPath)) + { + servicesPath = parentPath + "\\" + _option.BaseNamespace + "\\Models"; + Directory.CreateDirectory(servicesPath); + } + var fullPath = servicesPath + "\\" + modelTypeName + ".cs"; + if (File.Exists(fullPath) && !ifExsitedCovered) + return; + var content = ReadTemplate("ModelTemplate.txt"); + content = content + .Replace("{ModelsNamespace}", modelsNamespace) + .Replace("{ModelTypeName}", modelTypeName) + .Replace("{TableNameDesc}", modelTypeDesc) + .Replace("{KeyTypeName}", keyTypeName) + .Replace("{ModelContent}", modelContent) + .Replace("{TableName}", tableName); + WriteAndSave(fullPath, content); + } + #endregion + + #region 帮助方法 + + /// + /// 从代码模板中读取内容 + /// + /// 模板名称,应包括文件扩展名称。比如:template.txt + /// + private static string ReadTemplate(string templateName) + { + var path = AppDomain.CurrentDomain.BaseDirectory; + string fullName = $"{path}\\Template\\{templateName}"; + string temp = fullName; + string str = ""; + if (!File.Exists(temp)) + { + return str; + } + StreamReader sr = null; + try + { + sr = new StreamReader(temp); + str = sr.ReadToEnd(); // 读取文件 + } + catch { } + sr?.Close(); + sr?.Dispose(); + return str; + + } + + /// + /// 写文件 + /// + /// + /// + private static void WriteAndSave(string fileName, string content) + { + //实例化一个文件流--->与写入文件相关联 + using var fs = new FileStream(fileName, FileMode.Create, FileAccess.Write); + //实例化一个StreamWriter-->与fs相关联 + using var sw = new StreamWriter(fs); + //开始写入 + sw.Write(content); + //清空缓冲区 + sw.Flush(); + //关闭流 + sw.Close(); + fs.Close(); + } + + #endregion + } +} diff --git a/ZR.CodeGenerator/DbProvider.cs b/ZR.CodeGenerator/DbProvider.cs new file mode 100644 index 0000000..c4a5265 --- /dev/null +++ b/ZR.CodeGenerator/DbProvider.cs @@ -0,0 +1,30 @@ +using Infrastructure; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ZR.CodeGenerator +{ + public class DbProvider + { + + public SqlSugarClient GetSugarDbContext(string dbName) + { + string connStr = ConfigUtils.Instance.GetConnectionStrings(OptionsSetting.Conn).Replace("{DbName}", dbName); + int dbType = ConfigUtils.Instance.GetAppConfig(OptionsSetting.DbType, 0); + + return new SqlSugarClient(new List() + { + new ConnectionConfig(){ + ConnectionString = connStr, + DbType = (DbType)dbType, + IsAutoCloseConnection = true,//开启自动释放模式和EF原理一样 + InitKeyType = InitKeyType.Attribute,//从特性读取主键和自增列信息 + }, + }); + } + } +} diff --git a/ZR.CodeGenerator/Service/CodeGeneraterService.cs b/ZR.CodeGenerator/Service/CodeGeneraterService.cs new file mode 100644 index 0000000..6dc3b1d --- /dev/null +++ b/ZR.CodeGenerator/Service/CodeGeneraterService.cs @@ -0,0 +1,88 @@ +using Infrastructure; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ZR.Model; +using ZR.Model.CodeGenerator; + +namespace ZR.CodeGenerator.Service +{ + public class CodeGeneraterService: DbProvider + { + ///// + ///// 获取表所有列 + ///// + ///// + ///// + //public List GetAllColumns(string tableName) + //{ + // var dbType = ConfigUtils.Instance.GetConfig("CodeGenDbType"); + // if (tableName == null) + // throw new ArgumentException(nameof(tableName)); + // List list = new List(); + // if (dbType == "1") + // { + // list = CodeGeneratorRepository.GetAllColumns(tableName); + // } + // return list; + //} + + /// + /// 获取所有数据库名 + /// + /// + public List GetAllDataBases() + { + var dbType = ConfigUtils.Instance.GetConfig("CodeGenDbType"); + List list = new List(); + if (dbType == "1") + { + var db = GetSugarDbContext("ZrAdmin"); + var templist = db.DbMaintenance.GetDataBaseList(db); + templist.ForEach(item => + { + list.Add(new DataBaseInfo() { DbName = item }); + }); + } + else if (dbType == "0") + { + // list = mssqlExtractor.GetAllDataBases(); + } + return list; + } + + /// + /// 获取所有表 + /// + /// + /// + /// + /// + /// + public List GetAllTables(string dbName, string tableName, PagerInfo pager) + { + var tableList = GetSugarDbContext(dbName).DbMaintenance.GetTableInfoList(true); + if (!string.IsNullOrEmpty(tableName)) + { + tableList = tableList.Where(f => f.Name.Contains(tableName)).ToList(); + } + pager.TotalNum = tableList.Count; + return tableList.Skip(pager.PageSize * (pager.PageNum - 1)).Take(pager.PageSize).OrderBy(f => f.Name).ToList(); + } + + /// + /// 获取列信息 + /// + /// + /// + /// + public List GetColumnInfo(string dbName, string tableName) + { + return GetSugarDbContext(dbName).DbMaintenance.GetColumnInfosByTableName(tableName, true); + } + + } +} diff --git a/ZR.CodeGenerator/TableMappingHelper.cs b/ZR.CodeGenerator/TableMappingHelper.cs index e0c9daa..44f8e38 100644 --- a/ZR.CodeGenerator/TableMappingHelper.cs +++ b/ZR.CodeGenerator/TableMappingHelper.cs @@ -34,6 +34,8 @@ namespace ZR.CodeGenerator.CodeGenerator public static string GetClassNamePrefix(string tableName) { string[] arr = tableName.Split('_'); + if (arr.Length <= 0) return tableName; + StringBuilder sb = new StringBuilder(); for (int i = 1; i < arr.Length; i++) { diff --git a/ZR.CodeGenerator/ZR.CodeGenerator.csproj b/ZR.CodeGenerator/ZR.CodeGenerator.csproj index 948f805..d93648b 100644 --- a/ZR.CodeGenerator/ZR.CodeGenerator.csproj +++ b/ZR.CodeGenerator/ZR.CodeGenerator.csproj @@ -12,7 +12,16 @@ - + + + + + + + + + PreserveNewest + diff --git a/ZR.Model/CodeGenerator/DbFieldInfo.cs b/ZR.Model/CodeGenerator/DbFieldInfo.cs index f176895..f5e145e 100644 --- a/ZR.Model/CodeGenerator/DbFieldInfo.cs +++ b/ZR.Model/CodeGenerator/DbFieldInfo.cs @@ -10,6 +10,7 @@ namespace ZR.Model /// public class DbFieldInfo { + public string TableName { get; set; } /// /// 初始化 /// diff --git a/ZR.Model/Models/README.txt b/ZR.Model/Models/README.txt new file mode 100644 index 0000000..39e9872 --- /dev/null +++ b/ZR.Model/Models/README.txt @@ -0,0 +1 @@ +此文件夹用于存放业务代码数据库实体类 \ No newline at end of file diff --git a/ZR.Repository/DbProvider/SugarDbContext.cs b/ZR.Repository/DbProvider/SugarDbContext.cs index 2aa9b4e..68f7afe 100644 --- a/ZR.Repository/DbProvider/SugarDbContext.cs +++ b/ZR.Repository/DbProvider/SugarDbContext.cs @@ -42,6 +42,7 @@ 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))); }; //出错打印日志 @@ -51,5 +52,21 @@ namespace ZR.Repository.DbProvider Console.WriteLine(); }; } + + public SqlSugarClient GetSugarDbContext(string dbName) + { + string connStr = ConfigUtils.Instance.GetConnectionStrings(OptionsSetting.Conn).Replace("{DbName}", dbName); + int dbType = ConfigUtils.Instance.GetAppConfig(OptionsSetting.DbType, 0); + + return new SqlSugarClient(new List() + { + new ConnectionConfig(){ + ConnectionString = connStr, + DbType = (DbType)dbType, + IsAutoCloseConnection = true,//开启自动释放模式和EF原理一样 + InitKeyType = InitKeyType.Attribute,//从特性读取主键和自增列信息 + }, + }); + } } } diff --git a/ZR.Repository/System/CodeGeneratorRepository.cs b/ZR.Repository/System/CodeGeneratorRepository.cs index 7455f89..b5d5f97 100644 --- a/ZR.Repository/System/CodeGeneratorRepository.cs +++ b/ZR.Repository/System/CodeGeneratorRepository.cs @@ -13,33 +13,62 @@ namespace ZR.Repository.System public class CodeGeneratorRepository : BaseRepository { /// - /// 获取数据库信息 + /// 获取数据库 /// /// - public List GetAllDataBaseInfos() + public List GetAllDb() { - return Db.Ado.SqlQuery("select name as DbName from master..sysdatabases "); + //return Db.Ado.SqlQuery("select name as DbName from master..sysdatabases "); + var list = Db.DbMaintenance.GetDataBaseList(Db); + List dataBases = new List(); + list.ForEach(item => + { + dataBases.Add(new DataBaseInfo() { DbName = item }); + }); + return dataBases; } /// - /// 获取所有的表 + /// 根据数据库名获取所有的表 /// /// /// /// /// - public List GetAllTables(string dbName, string tableName, PagerInfo pager) + public List GetAllTables(string dbName, string tableName, PagerInfo pager) { - string sql = $"SELECT name as TableName FROM {dbName}..SysObjects Where XType='U'"; - int total = 0; - var list = Db.SqlQueryable(sql) - //.WithCache(60 * 10) - .WhereIF(!string.IsNullOrEmpty(tableName), it => it.TableName.Contains(tableName)) - .AddParameters(new { dbName }) - .OrderBy(x => x.TableName) - .ToPageList(pager.PageNum, pager.PageSize, ref total); - pager.TotalNum = total; - return list; + var tableList = GetSugarDbContext(dbName).DbMaintenance.GetTableInfoList(true); + if (!string.IsNullOrEmpty(tableName)) + { + tableList = tableList.Where(f => f.Name.Contains(tableName)).ToList(); + } + pager.TotalNum = tableList.Count; + return tableList.Skip(pager.PageSize * (pager.PageNum - 1)).Take(pager.PageSize).OrderBy(f => f.Name).ToList(); + } + + /// + /// 获取表格列信息 + /// + /// + /// + /// + public List GetColumnInfo(string dbName, string tableName) + { + return GetSugarDbContext(dbName).DbMaintenance.GetColumnInfosByTableName(tableName, true); + } + + + /// + /// 获取当前数据库表名 + /// + /// + /// + public List GetAllTables(string[] tabList) + { + string sql = @"SELECT tbs.name as TableName ,ds.value as Description FROM sys.tables tbs + left join sys.extended_properties ds on ds.major_id=tbs.object_id and ds.minor_id=0"; + + return Db.SqlQueryable(sql).WhereIF(tabList.Length > 0, x => tabList.Contains(x.TableName)).ToList(); } } } diff --git a/ZR.Service/IService/ICodeGeneratorService.cs b/ZR.Service/IService/ICodeGeneratorService.cs index db7798e..2e713a9 100644 --- a/ZR.Service/IService/ICodeGeneratorService.cs +++ b/ZR.Service/IService/ICodeGeneratorService.cs @@ -8,10 +8,16 @@ using ZR.Model.CodeGenerator; namespace ZR.Service.IService { - public interface ICodeGeneratorService - { - List GetAllDataBases(string dbType); + //public interface ICodeGeneratorService + //{ + // List GetAllDataBases(); - List GetTablesWithPage(string tablename, string dbName, PagerInfo info); - } + // List GetTablesWithPage(string tablename, string dbName, PagerInfo info); + + // List GetAllColumns(string tableName); + + // List GetAllTables(string tabList); + + // List GetColumnInfo(string dbName, string tableName); + //} } diff --git a/ZR.Service/System/CodeGeneratorService.cs b/ZR.Service/System/CodeGeneratorService.cs index c6b9112..7c8446e 100644 --- a/ZR.Service/System/CodeGeneratorService.cs +++ b/ZR.Service/System/CodeGeneratorService.cs @@ -15,53 +15,85 @@ namespace ZR.Service.System /// /// /// - [AppService(ServiceType = typeof(ICodeGeneratorService), ServiceLifetime = LifeTime.Transient)] - public class CodeGeneratorService: ICodeGeneratorService + //[AppService(ServiceType = typeof(ICodeGeneratorService), ServiceLifetime = LifeTime.Transient)] + public class CodeGeneratorService //: ICodeGeneratorService { - public CodeGeneratorRepository CodeGeneratorRepository; + //public CodeGeneratorRepository CodeGeneratorRepository; - public CodeGeneratorService(CodeGeneratorRepository codeGeneratorRepository) - { - CodeGeneratorRepository = codeGeneratorRepository; - } + //public CodeGeneratorService(CodeGeneratorRepository codeGeneratorRepository) + //{ + // CodeGeneratorRepository = codeGeneratorRepository; + //} + + ///// + ///// 获取表所有列 + ///// + ///// + ///// + //public List GetAllColumns(string tableName) + //{ + // var dbType = ConfigUtils.Instance.GetConfig("CodeGenDbType"); + // if (tableName == null) + // throw new ArgumentException(nameof(tableName)); + // List list = new List(); + // if (dbType == "1") + // { + // list = CodeGeneratorRepository.GetAllColumns(tableName); + // } + // return list; + //} + + ///// + ///// 获取所有数据库名 + ///// + ///// + //public List GetAllDataBases() + //{ + // var dbType = ConfigUtils.Instance.GetConfig("CodeGenDbType"); + // List list = new List(); + // if (dbType == "1") + // { + // list = CodeGeneratorRepository.GetAllDb(); + // } + // else if (dbType == "0") + // { + // // list = mssqlExtractor.GetAllDataBases(); + // } + // return list; + //} + + //public List GetAllTables(string tableStrs) + //{ + // string[] tabList = tableStrs.Split(","); + + // return CodeGeneratorRepository.GetAllTables(tabList); + //} /// - /// 获取所有数据库名 + /// 获取列信息 /// + /// + /// /// - public List GetAllDataBases(string dbType) - { - List list = new List(); - if (dbType.Contains("SqlServer")) - { - list = CodeGeneratorRepository.GetAllDataBaseInfos(); - } - else if (dbType.Contains("MySql")) - { - // list = mssqlExtractor.GetAllDataBases(); - } - return list; - } + //public List GetColumnInfo(string dbName, string tableName) + //{ + // return CodeGeneratorRepository.GetColumnInfo(dbName, tableName); + //} - public List GetTablesWithPage(string tablename, string dbName, PagerInfo pager) - { - var dbType = ConfigUtils.Instance.GetConfig("CodeGenDbType"); - List list = new List(); - if (dbType == "1") - { - list = CodeGeneratorRepository.GetAllTables(dbName, tablename, pager); - } - else if (dbType.Contains("MySql")) - { - //list = mysqlExtractor.GetAllTables(this.dbName, tablename, fieldNameToSort, isDescending, info); - } - //if (!string.IsNullOrEmpty(tablename)) - //{ - // list = list.Where(f => f.TableName.Contains(tablename)).ToList(); - //} - - return list; - } + //public List GetTablesWithPage(string tablename, string dbName, PagerInfo pager) + //{ + // var dbType = ConfigUtils.Instance.GetConfig("CodeGenDbType"); + // List list = new List(); + // if (dbType == "1") + // { + // list = CodeGeneratorRepository.GetAllTables(dbName, tablename, pager); + // } + // else if (dbType == "0") + // { + // //list = mysqlExtractor.GetAllTables(this.dbName, tablename, fieldNameToSort, isDescending, info); + // } + // return list; + //} } } diff --git a/ZR.Vue/src/api/monitor/operlog.js b/ZR.Vue/src/api/monitor/operlog.js index 07e27ab..58def23 100644 --- a/ZR.Vue/src/api/monitor/operlog.js +++ b/ZR.Vue/src/api/monitor/operlog.js @@ -26,10 +26,10 @@ export function cleanOperlog() { } // 导出操作日志 -export function exportOperlog(query) { - return request({ - url: '/monitor/operlog/export', - method: 'get', - params: query - }) -} +// export function exportOperlog(query) { +// return request({ +// url: '/monitor/operlog/export', +// method: 'get', +// params: query +// }) +// } diff --git a/ZR.Vue/src/layout/components/Navbar.vue b/ZR.Vue/src/layout/components/Navbar.vue index 2d0df08..1e36156 100644 --- a/ZR.Vue/src/layout/components/Navbar.vue +++ b/ZR.Vue/src/layout/components/Navbar.vue @@ -6,16 +6,13 @@ -
@@ -85,9 +82,6 @@ export default { }); }); }, - to() { - this.$router.replace("/bigdata"); - }, }, }; diff --git a/ZR.Vue/src/views/dashboard/bigdata.vue b/ZR.Vue/src/views/dashboard/bigdata.vue deleted file mode 100644 index f6caa73..0000000 --- a/ZR.Vue/src/views/dashboard/bigdata.vue +++ /dev/null @@ -1,218 +0,0 @@ - - - - - - - - diff --git a/ZR.Vue/src/views/dashboard/bigdata/IviewCircle.vue b/ZR.Vue/src/views/dashboard/bigdata/IviewCircle.vue deleted file mode 100644 index a0deaed..0000000 --- a/ZR.Vue/src/views/dashboard/bigdata/IviewCircle.vue +++ /dev/null @@ -1,88 +0,0 @@ - - - - diff --git a/ZR.Vue/src/views/dashboard/bigdata/chart-options.js b/ZR.Vue/src/views/dashboard/bigdata/chart-options.js deleted file mode 100644 index 98dfb75..0000000 --- a/ZR.Vue/src/views/dashboard/bigdata/chart-options.js +++ /dev/null @@ -1,471 +0,0 @@ -var echarts = require("echarts"); -let chartLeft1 = { - tooltip: { - trigger: "axis", - axisPointer: { - type: "shadow" - } - }, - grid: { - left: "0%", - top: "10px", - right: "0%", - bottom: "4%", - containLabel: true - }, - xAxis: [ - { - type: "category", - data: [ - "商超门店", - "教育培训", - "房地产", - "生活服务", - "汽车销售", - "旅游酒店", - "五金建材" - ], - axisLine: { - show: true, - lineStyle: { - color: "rgba(255,255,255,.1)", - width: 1, - type: "solid" - } - }, - - axisTick: { - show: false - }, - axisLabel: { - interval: 0, - show: true, - splitNumber: 15, - textStyle: { - color: "rgba(255,255,255,.6)", - fontSize: "12" - } - } - } - ], - yAxis: [ - { - type: "value", - axisLabel: { - show: true, - textStyle: { - color: "rgba(255,255,255,.6)", - fontSize: "12" - } - }, - axisTick: { - show: false - }, - axisLine: { - show: true, - lineStyle: { - color: "rgba(255,255,255,.1 )", - width: 1, - type: "solid" - } - }, - splitLine: { - lineStyle: { - color: "rgba(255,255,255,.1)" - } - } - } - ], - series: [ - { - type: "bar", - data: [200, 600, 300, 900, 1500, 1200, 600], - barWidth: "35%", - itemStyle: { - normal: { - color: "#2f89cf", - opacity: 1, - barBorderRadius: 5 - } - } - } - ] -}; - - -let chartLeft2 = { - tooltip: { - trigger: "axis", - axisPointer: { - type: "shadow" - } - }, - grid: { - left: "0%", - top: "10px", - right: "0%", - bottom: "4%", - containLabel: true - }, - xAxis: [ - { - type: "category", - data: [ - "07.01", - "07.02", - "07.03", - "07.04", - "07.05", - "07.06", - ], - axisLine: { - show: true, - lineStyle: { - color: "rgba(255,255,255,.1)", - width: 1, - type: "solid" - } - }, - axisTick: { - show: false - }, - axisLabel: { - interval: 0, - // rotate:50, - show: true, - splitNumber: 15, - textStyle: { - color: "rgba(255,255,255,.6)", - fontSize: "12" - } - } - } - ], - yAxis: [ - { - type: "value", - axisLabel: { - show: true, - textStyle: { - color: "rgba(255,255,255,.6)", - fontSize: "12" - } - }, - axisTick: { - show: false - }, - axisLine: { - show: true, - lineStyle: { - color: "rgba(255,255,255,.1 )", - width: 1, - type: "solid" - } - }, - splitLine: { - lineStyle: { - color: "rgba(255,255,255,.1)" - } - } - }, - { - type: "value", - axisLabel: { - show: true, - textStyle: { - color: "rgba(255,255,255,.6)", - fontSize: "12" - } - }, - axisTick: { - show: false - }, - axisLine: { - show: true, - lineStyle: { - color: "rgba(255,255,255,.1 )", - width: 1, - type: "solid" - } - }, - splitLine: { - lineStyle: { - color: "rgba(255,255,255,.1)" - } - } - } - ], series: [ - { - type: "bar", - name: "销量", - data: [1200, 800, 300, 500, 560, 220], - barWidth: "25%", - itemStyle: { - normal: { - color: "#2f89cf", - opacity: 1, - barBorderRadius: 5 - } - } - }, { - type: "bar", - name: "订单", - data: [1000, 750, 380, 450, 450, 120], - barWidth: "25%", - itemStyle: { - normal: { - color: "#46d000", - opacity: 1, - barBorderRadius: 5 - } - } - } - ] -}; - -let chartLeft3 = { - tooltip: { - trigger: 'axis', - axisPointer: { // 坐标轴指示器,坐标轴触发有效 - type: 'shadow' // 默认为直线,可选为:'line' | 'shadow' - } - }, - grid: { - left: "0%", - top: "-5px", - right: "3%", - bottom: "4%", - containLabel: true - }, - xAxis: { - type: 'value', - axisLabel: { - show: true, - textStyle: { - color: "rgba(255,255,255,.6)", - fontSize: "12" - } - }, - axisTick: { - show: false - }, - axisLine: { - show: true, - lineStyle: { - color: "rgba(255,255,255,.1 )", - width: 1, - type: "solid" - } - }, - splitLine: { - lineStyle: { - color: "rgba(255,255,255,.1)" - } - } - }, - yAxis: { - type: 'category', - axisLabel: { - show: true, - textStyle: { - color: "rgba(255,255,255,.6)", - fontSize: "12" - } - }, - axisTick: { - show: false - }, - axisLine: { - show: true, - lineStyle: { - color: "rgba(255,255,255,.1 )", - width: 1, - type: "solid" - } - }, - splitLine: { - lineStyle: { - color: "rgba(255,255,255,.1)" - } - }, - data: ['周一', '周二', '周三', '周四', '周五'] - }, - series: [ - { - name: '直接访问', - type: 'bar', - stack: '总量', - label: { - show: true, - position: 'insideRight' - }, - barWidth: "55%", - itemStyle: { - normal: { - color: "#2f89cf", - opacity: 1, - barBorderRadius: 5 - } - }, - data: [120, 302, 400, 200, 700] - } - ] -}; - -let chartRight1 = { - title: {}, - tooltip: { - trigger: "axis", - axisPointer: { - type: "cross", - label: { - backgroundColor: "#6a7985" - } - } - }, - - color: ["#ffab6f", "#09b916", "#83cddc"], //图例颜色 - legend: { - top: "0%", - icon: "roundRect", - data: ["销售订单", "退货订单", "折扣订单"], - textStyle: { - color: "rgba(255,255,255,.5)", - fontSize: "12" - } - }, - toolbox: { - feature: {} - }, - grid: { - left: "10", - top: "20", - right: "10", - bottom: "10", - containLabel: true - }, - xAxis: [ - { - type: "category", - boundaryGap: false, - axisLabel: { - textStyle: { - color: "rgba(255,255,255,.6)", - fontSize: 12 - } - }, - axisLine: { - lineStyle: { - color: "rgba(255,255,255,.2)" - } - }, - data: [ - "2020.06.15", - "2020.06.16", - "2020.06.17", - "2020.06.18", - "2020.06.19", - "2020.06.20", - "2020.06.21", - "2020.06.22" - ] - } - ], - yAxis: [ - { - type: "value", - axisTick: { show: false }, - minInterval: 60, - axisLine: { - lineStyle: { - color: "rgba(255,255,255,.1)" - } - }, - axisLabel: { - textStyle: { - color: "rgba(255,255,255,.6)", - fontSize: 12 - } - }, - - splitLine: { - lineStyle: { - color: "rgba(255,255,255,.1)" - } - } - } - ], - series: [ - { - name: "销售订单", - type: "line", - smooth: true, - lineStyle: { - color: "#45d4ba", - width: 1 - }, //线条的样式 - areaStyle: { - color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [ - { - offset: 0, - color: "#83cddc" - }, - { - offset: 1, - color: "#bfdffbb5" - } - ]) - }, - data: [5, 22, 150, 54, 1, 230, 4, 1] - }, - { - name: "退货订单", - type: "line", - - smooth: true, - lineStyle: { - color: "#04a710", - width: 1 - }, // - areaStyle: { - color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [ - { - offset: 0, - color: "#0cbf22" - }, - { - offset: 1, - color: "#b8f7d1b5" - } - ]) - }, - data: [10, 150, 1, 250, 20, 100, 10, 150] - }, - { - name: "折扣订单", - type: "line", - - lineStyle: { - color: "#0864c3", - width: 1 - }, //线条的样式 - smooth: true, - areaStyle: { - color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [ - { - offset: 0, - color: "#29d7ff" - }, - { - offset: 1, - color: "#34ccef85" - } - ]) - }, - data: [100, 2, 260, 1, 200, 30, 101, 40] - } - ] -}; - - -export { chartLeft1, chartLeft2,chartLeft3, chartRight1 } diff --git a/ZR.Vue/src/views/dashboard/bigdata/head_bg.png b/ZR.Vue/src/views/dashboard/bigdata/head_bg.png deleted file mode 100644 index a2e45f6911fa3d1616d0b75a122161a3896aa3c4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 7881 zcmeHs_gfQNw00;0B1NQ2Q#eOdno5-_N>M3_bP)nd5dwtXNl-)(1Vj`Ngir*eOAS4s zq99U22|WQRp(T{i)9!H2`M$s5{&44+C(lYUvuCaSuJx{W?|F6K)R2??EISAU;=FTP z?*RzJ8U@(yY%IX%l&Ll&2qgaIj-IYX$VbAASFq^f2kFhShc)HWQ?s+Iug|MoIGDKN z7Q_~EEtSb>smoQ-_U*c1#=R>NZm3Svw>{r_+Q(hoR5TR-dhkztzhGY6bL7SU4f(%$F7?2mk1iAOU}xol{{YQ}$kj|Li!jJC{|CEGcKt6q!vw)z zQtN7q-a@Een!W(q+Rp;V{1kEN?}X6~7Xf zt9Vr|wka@t19@{+Q*uCZARam_!pKxE_>4ab-KHH-71ZM6&I&v>k&y7Bj?rP+tp$X! zzC`g#-tMb;in~zotTs-mPE5`rw^jWO%VlB|g@H@?7A3E?_ zjJlRy5K?*WA75-t=-s*aWyrJe>O>H?L0C3UiDF_%7l_He(WvDSQnxx<(>-ObV<^q+ zeFAldZ93;{a|X-VSz4KPW6i1Oh0(ZCW0I#5P>LNtzP#;dC=J>q#XR!#?vDXs%rPc# zJJmY}SxGdnn07RB_$)yiIfc&B5B>xd4}~1~Tw+dIo>t=nVJw@$yf)RsmIFUhtXWVp z!gDgmcnf*=a>C0hIc-WmhxB{EFON6Aj$(ajaE1~@ypRXQPojF11}mDa&V76hBAPPI zoIRL|hl!x$T$MD=`#>JAv??E|)?m6dH1r+cZ^yf5qvC!=D=`SvkI_}JBJB9c&JDkB z_CVTzI(#0Q988fv22fYQ5-R1ao2og&+N==_*)tXc^)S0Rs1&3QBiQM4jq0y=1|(Pz z)pC{xz5b#j^sg~y@7VUxx}qq7N>Ew-P;{;(!J9?&cSYa<$66spFbAoC9&7_ouW&w3 z*Enm#25{4rM`^tMSeXMklpYSk9#!(Hp2NvYpo3{xm9bH46{*PB$WL>%E#RdE6-6gq z1T(3vJsL*tzQl0?;1ZReP3ihr8H;#Tv6ffs&aHRM^j-dX$!)e8%|TIwBHoQQO_4r& z3$3StTFYOCHE2%CBl;_rJ=}Y@MWRynR|qFQL6uIs`{}j~WCXc0&08 zgdz*jagX0X^OP7HRhi}0LrHt8m!8jJa&g{5j|MMsl>cJqda0ggwO9`;a|qi^m~yMm zdv8chQ|KAw3QZ_SiZUbb+L?!a>Lj+^bod9xBb$WH;QO0X8uuIdSd6O2XRSoB@@C%Q zARTl2t9Or49Q*bGK59WQ)7#OBE`QrTurixIS#Vi# zt}t45{QfT{T!E5@s@S0&^H-+lvwync(H%4B&i$M-50Amzbd*!2*jsLDIIiNK;mm{C zm1}ka@chXYxjJTJQl7HkhGr(x=?42+tr0b2xtpqwZ-Az$EM2^$Zc?j;zB4ktk^I8h zqleS!7WK=0Xm+2kaQOHyk}*qm#DmPjT>9MkiGpu_f5ZFR3gETN4j=MF`j@)w_M*;( zl%P9qIs!~E_vOOe#+gniZs+Yx`fcK>k;{BD{@fdeWa}kV?}UIe_mzk=bnBZN2e6_E#5E&XxJxFNok zP*o0bKIYfDx5i2SNJ<}3YxhxV$4khVwb5xP{BwBsxK8{qmC%Ed7x`FqLmdRdGk$e_59%o58 zI=hcYpuSTu?DTqeMs~|E=ktWI-rAwM!IgJ||3tdmkhvK=_!;MY2XhiuTzuiNM_9i3 zFzKOIcApW2<4AwviR^16>&p*srVB3YAd(4ak2sM<%Q0X2wmsa2!baIJ{%B5uCp_A$s`f-ssC zg7ArtT{}B^)7e>v%hXeJic_67Xz%0WR#*CI&@Ai{7L`S45aKySP(kQ_=S54<*rOO6 z=kMStt98=Jv@Tk8$xL!z|I90^y{!Eg9X#$A|0z(Ldk`L4T5$x?c>klm@ja98Gff}3 zaj4A!>w>A!k1sp4rx`jn%h;m;J`>;}7wAyr7-#F4gdH=+6?9QbAn&?#5gxQ!z`DYI zvI!AOpO_}JpH`D>{tvD-*NU&W(n|=bgmD#R;b7>%BkJxHeZwO_<8?u#4CrO2r(nmI zJNIVqGR<~9W$g$rfUn|HmV?Ak*+x0tuUDvnKd;Ob`7V!xwavJmNnI{_Vfqz2 z`l6$^0_e}Viw>R8hvr=H;k7-k%Tk}*{koJ_c5Bwk z_w0J5(gHs_(3)ix*2OGv4~eE5triD%%qSkh=6=7lH9V4rN4@es$ZAkxOFHeX`+XMj zWJ){A=}k_ZB@7Jimi#j(6fpxH)?r%nn(fA=4p95hKgRb8{QZL^CI9rV?cIA_q&b3s9UV4M$sNJC2tTez+FePl#W7TXrOH7%k; zI4mzUFv*5w21D)D$UpAM*GZ_H5fV}fEeXWp4J99!|LF|)>=TN8YBF56`?PPNL71oS z1Gj?xRPDxn6&3BKa2V`-!)p`mYfVp}BurxOShMoR?{(OYV?$tshjp@>u&qZt`t zPsx;-7}Me#dUfe`r)-^jsQKW$KyRC{qR=!K8SQ8>fTTQD+{%f5N4DhwZMel)R5tB> z8|yuZjPVA1i7aGvfrOOLp(7D(Vt44hv|_NP=2dE80T1DvC$07r9(&Mpc-w%p%*?zX zbBXp%LHt9;DrVu7KYpN{HeY+kWYW6n^k`&8W|8|EI@4@YfnN$P#WKJv2f`?MY1xg| z>19VFA=U~G;XBn;-_t61!)Ye+TI8*o!m<+EMh{6vaOXoIQ^G=w80by$%8j1I1Uzo1tvex<+=Kf8*MN zcH8{5q~L;k;+l~@e&LV>D1>ieJ;onOX%sp!!TvR=H6mi|dr~UT%(?YGFeMkSxWa4b zpnbi_z{DPs3D+boL2z)Hw^3^DX4M>Du5@NB;gX+Itj+;9;DvfB`%LM$!&u1A0C;pBc9qcT7qk4&WKl;3d58V)6V zCvM2QZ_m8+t7Fuz6;@i=Fh4xNEHH1jRPm9L$*{OH#7fq%Mn1nyf_(66N@63Na=XFB zGh%~6x%t{t7^g_xq&0?8sgOH;zYE9+qOq`6jZ4J9&aLFGzO{{kI(&MlxXW8kTOR=bgWbM$S*@eBfdoH#G{Iq^tv(H{4f^S$G&y%79TUg|^BOB^+ znOrG0=sP>Ma8Hz4X5KcpF@u~08in9Q6Q6wmvZS@nVfeUQU0yz5?g$NdpI%P`=N7qh z7wLCVZ>QBd+Y9h)ZM`Rrh25M*SKM?|&MI}S<7dPpD^c`2TdF#wxx%#;39UC?*%{ct zed0|S=A6libRNW z;@aI2u{y2h1xpFBsQD?QxefYfc6e`ZG_fjJr?kkcLEzS=B8QR8j;tVqPg=Qgx@u}E zI8zK+#Azt2SE=1Va(D`h@G)+98=LCXMZ%o&hMNY%V&ZglePosiZA1&?w|sRW%>RpRYNP@k zC%a}6t?>+cb#h<46MA)372;g&6?Sb2uU*0gM-n10_dWy?n^=)R*hCI*Y#*dRMRDp| z_d_S~PFx!!pAYku3sX=C#9=a=O5VvtEt;W1E!<9QGnt4a2{2*246@>LRJ8s+Lvg{>xTgc9G{2T#-LZ`GFDoAZ~KnAQ41#L0Kn&xGucBt`nJ z{a{7#O?CZ_O|RUTBrle;J^R^Ux-qT3Te!5o0iP0Nyl1Rc7wH7c<6UwE6u4Ea{u!b{ z@O5>2!CQk(`R)MmAD=45a)%xP7(=(a`0kozQ>v!gftRx_ps0QTimGfQhg{r?=B2?1 z9V7oFs?5T})^O6FCRNx`(B#@atKqgU*S%szTAUdZs`A9wQ^4 zmVRedMe2whW;M93G_-P*qe@%P**k1-Z0k1c;6!ZoUdzu5TBt5&`#bpB)yqptn$mZ1 zSQLU|d25n>w82Bws50==`0T=i4guKun4Zl4l^`Sy)d7d5gVm;;a81(JVACJn3n!I5 zJnpAz9e>*ynWj+>WzuO|gxd`W-hs%q2&%Q>jLOcZNzHa}lY{8VY6Z+FWrg>bNKcQ$}U#I^`dgtsVWp5 zlMII9#FQd5C0}%G=KiIzTdMeQs3Z8VyK~TL%K9ms*861RkLxUt;cCH)L-gwi7{blr zpnnTHXq=eI`G`c3k$xPo8e&HJIfZDC+#S*>Jnv)0^$dF4yA1iyZ(>&3$Zl@XV8&_F z)1qc#EJ$L2;0YA4W?^!1KRsPLE^^e6*0Ltm`#3D@nl^&ks6d$sUWTw^D2+JWvldB2S80zUywy%d8D%B}<3i}a@8RMK@jR^Jt)*f|52T{Pzs|O&q*j=v zXt6#o&Vet6q`hzjGOMIWj1l})XPW&PeckS-K?6~()q;(()058i+GJw_JhBjqWrs~c zW8HEY`6qt&GVA~_e9LVd} zT1ao5i8sO%hs)K&Yt&mDspVI<$CK=1Yjl3Ml3E^H?jTI=J5;$(9@YKugH+nLZT4Uz zV{59ndS)ut3QX5?CbynWH*a1nlKC@p_a7lkBXts-)ob$W zE3NBC0;}?O@3u!AZZGzxD}av;%ibyjjLp%*j>MsP0tBQwG+`3x&1^9^K6AO4Qpf@5tE*rF1b27`swz=5)mAOwwL!#w5ulsE-z(c*A1Ijj4 zotQU42_!fL$=y#~x1L)U7rJ2UXNTQVxX#%4S!)-_%F71&X$GdWvH6MRovT3UJ{s0I z6CymUs}s4psE`buA|Fgo6S`AN5T~-qi@Vrszyg8gm%6=JSA2P7>U%5XS6oR+&%wN# z1UMA`yA1W}y$Siz)$QOtf+C7yHsIDxjRk8~0d@DbJKTMyeT!&#{Ua)Zvc^E|iW28^!_ZXC0#J*+#d@+4u%OUhOrlRj3s zJ5gUI=(e|$#EcykzkYb9MZVO)wDdS7dc?x#f%SpDi8g6Yzckz&+C*m{ z@8pRZJN41-2UD%#YXIr00~-Bu<)Iyan$|y(I8~#!;1W<~cTA)ya-W>M&k|LP)@m23 zb6^H0!b=pR9pIcDRf%1IGw<1|Ut!-k&nOWN1Oi(xJ8K_tW4i%fw7pi(y5% zp&mSK$>xb?c<^7FZev*TavMBU=b_XyL&<#KgAeK44F-(3mDZr(L8u=U*GhLDFAW4( zBFiMrW#1;fek^dz*u>N4?we1nplEgsSMG-+-E_17F{^X?)@;a9%*Mxz$-P3} zWA0wVV=s$c(FPbk38+L;CUPpcHty+1$|^G1YpR<3)XbmsBX%Q)zE8J((UBM@bbWgr zEH>Rl?%=KFxCREaYUkye*}I7TM>Im0Dt(_d#h4sHxko3ZYP9c+TgPV(c=tb2BOfK> zl8ANnTfa$FqFIx)+xz~rZmRulz>;?lW)(quKM$}^Ymv}lmZ2VPePtsj<0JMG<%EY^ zLfi~mY+`t2IuUz*G|)U}C{OL;s_2csd%LJR%^;qo!`NLbZRG|{PQ6jTP?XhAsz|wB zsNF@VYFEJJm95U(J7BjK4>Hhi92b9$iO7KwN(7`aSz&nXLt2%2sYGgDrAIS<8`yp9 zU1{KR(s;gWwR63Qn&PhGV)?^XQ@{)d>kWX9rurr|oMH)_#_S3{xVW?l)muv+x>zCO z5&yHm;z=?0np;VvWwVz`L5m6gJm_Ujsn?|$?|84`5Cu6=nv zDud5x%^*9A4AhRt2&#Id?AZ8@waS9ivE(6mw^jXal{wbEpeH)(5R^yRkPUuZeBPIb zvSfzS5g5OHr0{mQ<(m=rYJA|$%gf47^&%%H?tj#hK7I?;sFTJE!a)``T-T>!!b{kr zSmgw%=iPC)tHo_}+;LB&O8r|cEMHpx-0#{Z!-^9P=nVP-7143q3SYcgvR6_|R|hL6 z51Ec*u?WQ@-$pl-{w&+$0s8As=Jpdy=^Ok%nHM)zwX!OSZbJZXXtG5Y70a=9tTdOp zBMJiGHrmmpW~5w?w6KW5y_%6VV5Gs>_qv_XOnRYWG{$Un>!viw;q_`iZb$GzG1z!C zsayt-#HD~9h5o6A3(MQ7@croK>v1c$-)=&+d`S zr&6xZzs~y{-YBDJIv$iS{BCO|;vD7po_Q;VF=79FuP&@C2IA>heaHIgT{O0IEzPRW zlP%z6n9~!PrhI&rPJmEDcD+TWO_1dSS7=w={trby%DnD1D8SJpq1wBYgaUl z7a1XCtLI80eCmZ=Ie<}YxT9Ih-bu)eG09jf-`CS&p_fw@Eu9!>FtJ@yjq9NHojmcN=T?D21X@`b`9jr>v1zZI*j@ zrKWCq#&&4!%k~?Q97nVBOg!aUc?tk5)ZnTsLI;0XcHNiPKq~n;pb*7-ha4jaZbKis z+VPN$^c}AbY5|n#b3w#)4ONXBj#8UWY%de$k6%tL4p%XJ(?_v<;o;DP9nfui9b_S? S4ims_pga1edX+aFpZ^cs0d1uK diff --git a/ZR.Vue/src/views/dashboard/bigdata/layout.less b/ZR.Vue/src/views/dashboard/bigdata/layout.less deleted file mode 100644 index 3f6cffd..0000000 --- a/ZR.Vue/src/views/dashboard/bigdata/layout.less +++ /dev/null @@ -1,197 +0,0 @@ - -.big-data-container { - position: absolute; - overflow: hidden; - height: 100%; - width: 100%; - background-color: #1400a8; - background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100%25' height='100%25' viewBox='0 0 1200 800'%3E%3Cdefs%3E%3CradialGradient id='a' cx='0' cy='800' r='800' gradientUnits='userSpaceOnUse'%3E%3Cstop offset='0' stop-color='%230e0077'/%3E%3Cstop offset='1' stop-color='%230e0077' stop-opacity='0'/%3E%3C/radialGradient%3E%3CradialGradient id='b' cx='1200' cy='800' r='800' gradientUnits='userSpaceOnUse'%3E%3Cstop offset='0' stop-color='%2314057c'/%3E%3Cstop offset='1' stop-color='%2314057c' stop-opacity='0'/%3E%3C/radialGradient%3E%3CradialGradient id='c' cx='600' cy='0' r='600' gradientUnits='userSpaceOnUse'%3E%3Cstop offset='0' stop-color='%230d0524'/%3E%3Cstop offset='1' stop-color='%230d0524' stop-opacity='0'/%3E%3C/radialGradient%3E%3CradialGradient id='d' cx='600' cy='800' r='600' gradientUnits='userSpaceOnUse'%3E%3Cstop offset='0' stop-color='%231400a8'/%3E%3Cstop offset='1' stop-color='%231400a8' stop-opacity='0'/%3E%3C/radialGradient%3E%3CradialGradient id='e' cx='0' cy='0' r='800' gradientUnits='userSpaceOnUse'%3E%3Cstop offset='0' stop-color='%23000000'/%3E%3Cstop offset='1' stop-color='%23000000' stop-opacity='0'/%3E%3C/radialGradient%3E%3CradialGradient id='f' cx='1200' cy='0' r='800' gradientUnits='userSpaceOnUse'%3E%3Cstop offset='0' stop-color='%23130733'/%3E%3Cstop offset='1' stop-color='%23130733' stop-opacity='0'/%3E%3C/radialGradient%3E%3C/defs%3E%3Crect fill='url(%23a)' width='1200' height='800'/%3E%3Crect fill='url(%23b)' width='1200' height='800'/%3E%3Crect fill='url(%23c)' width='1200' height='800'/%3E%3Crect fill='url(%23d)' width='1200' height='800'/%3E%3Crect fill='url(%23e)' width='1200' height='800'/%3E%3Crect fill='url(%23f)' width='1200' height='800'/%3E%3C/svg%3E"); - background-attachment: fixed; - background-size: cover; - .head { - height: 75px; - /* height: 1.05rem; */ - background: url(./head_bg.png) no-repeat center center; - background-size: 100% 100%; - position: relative; - z-index: 100; - } -} - -.head h1 { - margin: 0; - color: #fff; - text-align: center; - /* font-size: .4rem; */ - /* line-height: .8rem; */ - line-height: 71px; -} - -.data-container { - /* margin: 5px 15px; - height:100%; */ - - margin: 0px 15px; - position: absolute; - left: 0; - right: 0; - top: 76px; - bottom: 0; -} - -.data-container > div { - float: left; - /* border: 1px solid white; */ - height: 100%; -} - -.data-center { - padding: 0 0.9rem; - width: 40%; - display: flex; - flex-direction: column; - // .center-top{ - // height: 210px; - // background: red; - // } -.chart-center{ - flex: 1; -} -} -.chart-center{ - width: 100%; -display: flex; -// background: white; -} -.data-left, -.data-right { - width: 30%; - display: flex; - - flex-direction: column; -} - -.data-left-item, -.data-right-item,.center-top,.center-top-num,.chart-center { - border: 1px solid rgba(25, 186, 139, 0.17); - padding: 0 0.2rem 0.4rem 0.15rem; - background: rgba(255, 255, 255, 0.04); - background-size: 100% auto; - position: relative; - margin-bottom: 0.15rem; - z-index: 10; -} - -.data-foot-line { - position: absolute; - bottom: 0; - width: 100%; - left: 0; -} - -.data-foot-line:before, -.data-foot-line:after { - position: absolute; - width: 10px; - height:10px; - content: ""; - border-bottom: 2px solid #02a6b5; - bottom: 0; -} - -.boxall:before, -.data-foot-line:before { - border-left: 2px solid #02a6b5; - left: 0; -} - -.boxall:after, -.data-foot-line:after { - border-right: 2px solid #02a6b5; - right: 0; -} - -.boxall:before, -.boxall:after { - position: absolute; - width: 10px; - height: 10px; - content: ""; - border-top: 2px solid #02a6b5; - top: 0; -} - -.data-left-item:before, -.data-right-item:before, -.center-top-num:before, -.center-top:before{ - border-left: 2px solid #02a6b5; - left: 0; - position: absolute; - width: 10px; - height:10px; - content: ""; - border-top: 2px solid #02a6b5; - top: 0; -} - -.data-left-item:after, -.data-right-item:after, -.center-top-num:after, -.center-top:after { - border-right: 2px solid #02a6b5; - right: 0; - position: absolute; - width: 10px; - height: 10px; - content: ""; - border-top: 2px solid #02a6b5; - top: 0; -} - -.data-left, -.data-right { - /* display: flex; */ -} - -.data-left > .data-left-item, -.data-right > .data-right-item { - flex: 1; - margin-bottom: 0.9rem; -} - -.data-center .title, -.data-left > .data-left-item .title, -.data-right > .data-right-item .title { - /* font-size: .2rem; */ - font-size: 1rem; - padding: 7px 0; - color: #fff; - text-align: center; - /* line-height: .5rem; */ -} - -.data-center .chart-center{ - width: 100%; -} - -.center-top-num{ - height: 80px; - padding-top: 7px; - margin-bottom: 0.8rem; - display: flex; - .item{ - flex: 1; - text-align: center; - } - .text{ - color: #fcf0d8; - font-size: 14px; - } - .num{ - font-size: 34px; - font-family: -apple-system, BlinkMacSystemFont, Segoe UI, PingFang SC, Hiragino Sans GB, Microsoft YaHei, Helvetica Neue, Helvetica, Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol; - font-weight: bold; - color: #67caca; - } -} diff --git a/ZR.Vue/src/views/monitor/cache/index.vue b/ZR.Vue/src/views/monitor/cache/index.vue deleted file mode 100644 index 5965dfb..0000000 --- a/ZR.Vue/src/views/monitor/cache/index.vue +++ /dev/null @@ -1,151 +0,0 @@ - - - diff --git a/ZR.Vue/src/views/monitor/online/index.vue b/ZR.Vue/src/views/monitor/online/index.vue deleted file mode 100644 index a33614b..0000000 --- a/ZR.Vue/src/views/monitor/online/index.vue +++ /dev/null @@ -1,128 +0,0 @@ - - - - diff --git a/ZR.Vue/src/views/monitor/operlog/index.vue b/ZR.Vue/src/views/monitor/operlog/index.vue index 081b728..b4ba071 100644 --- a/ZR.Vue/src/views/monitor/operlog/index.vue +++ b/ZR.Vue/src/views/monitor/operlog/index.vue @@ -38,7 +38,7 @@ - + @@ -121,11 +121,10 @@ import { cleanOperlog, exportOperlog, } from "@/api/monitor/operlog"; -import template from "../../../../document/template.vue"; import DateRangePicker from '@/components/DateRangePicker' export default { - components: { template ,DateRangePicker}, + components: { DateRangePicker}, name: "Operlog", data() { return { diff --git a/ZR.Vue/src/views/tool/index.vue b/ZR.Vue/src/views/tool/index.vue index 572bb82..fefeab2 100644 --- a/ZR.Vue/src/views/tool/index.vue +++ b/ZR.Vue/src/views/tool/index.vue @@ -39,7 +39,7 @@ - + @@ -56,15 +56,21 @@ - 生成代码 + 刷新
- - - + + + + + +
@@ -84,7 +90,9 @@ import { downloadFile } from "@/utils/index"; import { Loading } from "element-ui"; import defaultSettings from "@/settings"; +import template from "../../../document/template.vue"; export default { + components: { template }, name: "CodeGenerator", data() { return { @@ -163,8 +171,8 @@ export default { var seachdata = { pageNum: this.pagination.pageNum, PageSize: this.pagination.pagesize, - Keywords: this.searchform.tableName, - EnCode: this.searchform.DbName, + tableName: this.searchform.tableName, + dbName: this.searchform.DbName, // Order: this.sortableData.order, // Sort: this.sortableData.sort, }; @@ -206,75 +214,57 @@ export default { /** * 点击生成服务端代码 */ - handleGenerate: async function () { - if (this.currentSelected.length === 0) { - this.$alert("请先选择要生成代码的数据表", "提示"); - return false; - } else { - this.$refs["codeform"].validate((valid) => { - if (valid) { - var loadop = { - lock: true, - text: "正在生成代码...", - spinner: "el-icon-loading", - background: "rgba(0, 0, 0, 0.7)", - }; - const pageLoading = Loading.service(loadop); - var currentTables = ""; - this.currentSelected.forEach((element) => { - currentTables += element.TableName + ","; - }); - var seachdata = { - tables: currentTables, - baseSpace: this.codeform.baseSpace, - replaceTableNameStr: this.codeform.replaceTableNameStr, - }; - codeGenerator(seachdata) - .then((res) => { - if (res.code == 100) { - downloadFile( - defaultSettings.fileUrl + res.ResData[0], - res.ResData[1] - ); + handleGenerate: async function (row) { + console.log(JSON.stringify(row)); + // if (this.currentSelected.length === 0 || this.currentSelected.length > 3) { + // this.msgError("请先选择要生成代码的数据表", "提示"); + // return false; + // } else { + this.$refs["codeform"].validate((valid) => { + if (valid) { + var loadop = { + lock: true, + text: "正在生成代码...", + spinner: "el-icon-loading", + background: "rgba(0, 0, 0, 0.7)", + }; + const pageLoading = Loading.service(loadop); - this.msgSuccess("恭喜你,代码生成完成!"); - } else { - this.msgError(res.msg); - } - pageLoading.close(); - }) - .catch((erre) => { - pageLoading.close(); - }); - } else { - return false; - } - }); - } - }, - /** - * 当表格的排序条件发生变化的时候会触发该事件 - */ - handleSortChange: function (column) { - this.sortableData.sort = column.prop; - if (column.order === "ascending") { - this.sortableData.order = "asc"; - } else { - this.sortableData.order = "desc"; - } - this.loadTableData(); + var seachdata = { + dbName: this.searchform.DbName, + tables: row.name, // this.currentSelected.toString(), + baseSpace: this.codeform.baseSpace, + replaceTableNameStr: this.codeform.replaceTableNameStr, + }; + codeGenerator(seachdata) + .then((res) => { + if (res.code == 200) { + // downloadFile( + // defaultSettings.fileUrl + res.ResData[0], + // res.ResData[1] + // ); + + this.msgSuccess("恭喜你,代码生成完成!"); + } else { + this.msgError(res.msg); + } + pageLoading.close(); + }) + .catch((erre) => { + pageLoading.close(); + }); + } else { + return false; + } + }); + // } }, /** * 当用户手动勾选checkbox数据行事件 */ handleSelectChange: function (selection, row) { - this.currentSelected = selection; - }, - /** - * 当用户手动勾选全选checkbox事件 - */ - handleSelectAllChange: function (selection) { - this.currentSelected = selection; + console.log(JSON.stringify(selection)); + this.currentSelected = selection.map((item) => item.name); }, /** * 选择每页显示数量 diff --git a/ZRAdmin.xml b/ZRAdmin.xml index 1ca6464..521037d 100644 --- a/ZRAdmin.xml +++ b/ZRAdmin.xml @@ -42,15 +42,19 @@ 获取所有表根据数据名 - 数据库名 - 表名 + 数据库名 + 表名 分页信息 - + - 生成代码 + 代码生成器 + + 要生成代码的表 + 项目命名空间 + 要删除表名的字符串用英文逗号","隔开 From 85b0305cbcd474e2d223b472d770a6c8e0bd032f Mon Sep 17 00:00:00 2001 From: izory <791736813@qq.com> Date: Tue, 7 Sep 2021 21:52:44 +0800 Subject: [PATCH 05/28] =?UTF-8?q?=E5=BC=80=E5=8F=91=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E7=94=9F=E6=88=90=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Infrastructure/OptionsSetting.cs | 1 + .../Controllers/CodeGeneratorController.cs | 19 ++- ZR.Admin.WebApi/appsettings.Development.json | 1 - ZR.Admin.WebApi/appsettings.Production.json | 1 - ZR.CodeGenerator/CodeGeneratorTool.cs | 131 +++++++++--------- ZR.CodeGenerator/DbProvider.cs | 2 +- .../Service/CodeGeneraterService.cs | 19 --- ZR.Model/CodeGenerator/DbFieldInfo.cs | 79 ----------- ZR.Model/CodeGenerator/DbTableInfo.cs | 75 ---------- .../System/CodeGeneratorRepository.cs | 97 ++++++------- ZR.Vue/src/views/tool/index.vue | 18 +-- 11 files changed, 131 insertions(+), 312 deletions(-) delete mode 100644 ZR.Model/CodeGenerator/DbFieldInfo.cs delete mode 100644 ZR.Model/CodeGenerator/DbTableInfo.cs diff --git a/Infrastructure/OptionsSetting.cs b/Infrastructure/OptionsSetting.cs index 91d7963..fb677bb 100644 --- a/Infrastructure/OptionsSetting.cs +++ b/Infrastructure/OptionsSetting.cs @@ -9,6 +9,7 @@ namespace Infrastructure public static string ConnAdmin = "Conn_admin"; public static string Conn = "ConnDynamic"; public static string DbType = "DbType"; + public static string CodeGenDbType = "CodeGenDbType"; public static string DbKey = "DbKey"; public string Conn_Admin { get; set; } diff --git a/ZR.Admin.WebApi/Controllers/CodeGeneratorController.cs b/ZR.Admin.WebApi/Controllers/CodeGeneratorController.cs index 7248560..81d751d 100644 --- a/ZR.Admin.WebApi/Controllers/CodeGeneratorController.cs +++ b/ZR.Admin.WebApi/Controllers/CodeGeneratorController.cs @@ -3,6 +3,7 @@ using Infrastructure.Attribute; using Infrastructure.Enums; using Infrastructure.Model; using Microsoft.AspNetCore.Mvc; +using SqlSugar; using System; using System.Collections.Generic; using System.Linq; @@ -74,20 +75,18 @@ namespace ZR.Admin.WebApi.Controllers [Log(Title = "代码生成", BusinessType = BusinessType.OTHER)] public IActionResult Generate(string dbName, string baseSpace, string tables, string replaceTableNameStr) { + if (string.IsNullOrEmpty(tables)) + { + throw new CustomException(ResultCode.CUSTOM_ERROR, "请求参数为空"); + } if (string.IsNullOrEmpty(baseSpace)) { - throw new CustomException(ResultCode.CUSTOM_ERROR, "命名空间不能为空"); - } - string[] tableList = tables.Split(","); - List tableInfos = new List();// CodeGeneratorService.GetAllTables(tables); - foreach (var item in tableList) - { - tableInfos.Add(new DbTableInfo() { TableName = item }); + //baseSpace = "Zr"; } + DbTableInfo dbTableInfo = new() { Name = tables }; + CodeGeneratorTool.Generate(dbName, baseSpace, dbTableInfo, replaceTableNameStr, true); - CodeGeneratorTool.Generate(dbName, baseSpace, tableInfos, replaceTableNameStr, true); - - return SUCCESS(null); + return SUCCESS(1); } } } diff --git a/ZR.Admin.WebApi/appsettings.Development.json b/ZR.Admin.WebApi/appsettings.Development.json index 7bda31a..49a30f6 100644 --- a/ZR.Admin.WebApi/appsettings.Development.json +++ b/ZR.Admin.WebApi/appsettings.Development.json @@ -6,7 +6,6 @@ "Microsoft.Hosting.Lifetime": "Information" } }, - "appName": "ZR Admin System", "ConnectionStrings": { "Conn_Admin": "server=127.0.0.1;database=admin;user=zr;pwd=abc" }, diff --git a/ZR.Admin.WebApi/appsettings.Production.json b/ZR.Admin.WebApi/appsettings.Production.json index e709dfb..4dd2ae0 100644 --- a/ZR.Admin.WebApi/appsettings.Production.json +++ b/ZR.Admin.WebApi/appsettings.Production.json @@ -6,7 +6,6 @@ "Microsoft.Hosting.Lifetime": "Information" } }, - "appName": "ZR Admin system", "ConnectionStrings": { "Conn_Admin": "server=127.0.0.1;database=admin;user=zr;pwd=abc" }, diff --git a/ZR.CodeGenerator/CodeGeneratorTool.cs b/ZR.CodeGenerator/CodeGeneratorTool.cs index dc84deb..f390fa7 100644 --- a/ZR.CodeGenerator/CodeGeneratorTool.cs +++ b/ZR.CodeGenerator/CodeGeneratorTool.cs @@ -1,4 +1,5 @@ -using System; +using SqlSugar; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -32,47 +33,44 @@ namespace ZR.CodeGenerator /// 代码生成器入口方法 ///
/// - /// 要生成代码的表 - /// - /// + /// /// 要删除表名称的字符 /// 是否替换现有文件,为true时替换 - public static void Generate(string dbName, string baseNamespace, List listTable, string replaceTableNameStr, bool ifExsitedCovered = false) + public static void Generate(string dbName, string baseNamespace, DbTableInfo dbTableInfo, string replaceTableNameStr, bool ifExsitedCovered = false) { - _option.DtosNamespace = baseNamespace + ".Dtos"; - _option.ModelsNamespace = baseNamespace + ".Model"; - _option.IRepositoriesNamespace = baseNamespace + ".IRepositories"; - _option.RepositoriesNamespace = baseNamespace + ".Repositories"; - _option.IServicsNamespace = baseNamespace + ".IServices"; - _option.ServicesNamespace = baseNamespace + ".Services"; + _option.BaseNamespace = baseNamespace; + _option.DtosNamespace = baseNamespace + "ZR.Model.Dto"; + _option.ModelsNamespace = baseNamespace + "ZR.Model"; + //_option.IRepositoriesNamespace = baseNamespace + ".IRepositorie"; + _option.RepositoriesNamespace = baseNamespace + "ZR.Repository"; + //_option.IServicsNamespace = baseNamespace + ".IService"; + _option.ServicesNamespace = baseNamespace + "ZR.Service"; _option.ApiControllerNamespace = baseNamespace + "Api"; _option.ReplaceTableNameStr = replaceTableNameStr; //_option.TableList = listTable; - _option.BaseNamespace = baseNamespace; CodeGeneraterService codeGeneraterService = new CodeGeneraterService(); - //List listTable = dbExtractor.GetWhereTables(_option.TableList); string profileContent = string.Empty; - foreach (DbTableInfo dbTableInfo in listTable) - { - List listField = codeGeneraterService.GetColumnInfo(dbName, dbTableInfo.TableName); - GenerateSingle(listField, dbTableInfo, ifExsitedCovered); - string tableName = dbTableInfo.TableName; - if (!string.IsNullOrEmpty(_option.ReplaceTableNameStr)) - { - string[] rel = _option.ReplaceTableNameStr.Split(';'); - for (int i = 0; i < rel.Length; i++) - { - if (!string.IsNullOrEmpty(rel[i].ToString())) - { - tableName = tableName.Replace(rel[i].ToString(), ""); - } - } - } - tableName = tableName.Substring(0, 1).ToUpper() + tableName.Substring(1); - profileContent += string.Format(" CreateMap<{0}, {0}OutputDto>();\n", tableName); - profileContent += string.Format(" CreateMap<{0}InputDto, {0}>();\n", tableName); - } + //foreach (DbTableInfo dbTableInfo in listTable) + //{ + List listField = codeGeneraterService.GetColumnInfo(dbName, dbTableInfo.Name); + GenerateSingle(listField, dbTableInfo, ifExsitedCovered); + //string tableName = dbTableInfo.TableName; + //if (!string.IsNullOrEmpty(_option.ReplaceTableNameStr)) + //{ + // string[] rel = _option.ReplaceTableNameStr.Split(';'); + // for (int i = 0; i < rel.Length; i++) + // { + // if (!string.IsNullOrEmpty(rel[i].ToString())) + // { + // tableName = tableName.Replace(rel[i].ToString(), ""); + // } + // } + //} + //tableName = tableName.Substring(0, 1).ToUpper() + tableName.Substring(1); + //profileContent += string.Format(" CreateMap<{0}, {0}OutputDto>();\n", tableName); + //profileContent += string.Format(" CreateMap<{0}InputDto, {0}>();\n", tableName); + //} //GenerateDtoProfile(_option.ModelsNamespace, profileContent, ifExsitedCovered); } @@ -85,23 +83,18 @@ namespace ZR.CodeGenerator /// 表字段集合 /// 表信息 /// 如果目标文件存在,是否覆盖。默认为false - public static void GenerateSingle(List listField, DbTableInfo tableInfo, bool ifExsitedCovered = false) + public static void GenerateSingle(List listField, DbTableInfo tableInfo, bool ifExsitedCovered = false) { var modelsNamespace = _option.ModelsNamespace; - var modelTypeName = tableInfo.TableName;//表名 + var modelTypeName = tableInfo.Name;//表名 var modelTypeDesc = tableInfo.Description;//表描述 if (!string.IsNullOrEmpty(_option.ReplaceTableNameStr)) { - string[] rel = _option.ReplaceTableNameStr.Split(';'); - for (int i = 0; i < rel.Length; i++) - { - if (!string.IsNullOrEmpty(rel[i].ToString())) - { - modelTypeName = modelTypeName.Replace(rel[i].ToString(), ""); - } - } + modelTypeName = modelTypeName.Replace(_option.ReplaceTableNameStr.ToString(), ""); } + modelTypeName = modelTypeName.Replace("_", ""); modelTypeName = modelTypeName.Substring(0, 1).ToUpper() + modelTypeName.Substring(1); + string keyTypeName = "string";//主键数据类型 string modelcontent = "";//数据库模型字段 string InputDtocontent = "";//输入模型 @@ -113,23 +106,25 @@ namespace ZR.CodeGenerator string vueViewSaveBindContent = string.Empty;//Vue保存时输出内容 string vueViewEditFromRuleContent = string.Empty;//Vue数据校验 - foreach (SqlSugar.DbColumnInfo dbFieldInfo in listField) + foreach (DbColumnInfo dbFieldInfo in listField) { string columnName = dbFieldInfo.DbColumnName.Substring(0, 1).ToUpper() + dbFieldInfo.DbColumnName.Substring(1); modelcontent += " /// \n"; - modelcontent += ($" /// {dbFieldInfo.ColumnDescription}\n"); + modelcontent += ($" /// 描述 :{dbFieldInfo.ColumnDescription}\n"); + modelcontent += ($" /// 空值 :{dbFieldInfo.IsNullable}\n"); + modelcontent += ($" /// 默认 :{dbFieldInfo.DefaultValue}\n"); modelcontent += " /// \n"; if (dbFieldInfo.IsIdentity || dbFieldInfo.IsPrimarykey) { - modelcontent += $" [SugarColumn(IsPrimaryKey = {dbFieldInfo.IsPrimarykey}, IsIdentity = {dbFieldInfo.IsIdentity})]\n"; + modelcontent += $" [SqlSugar.SugarColumn(IsPrimaryKey = {dbFieldInfo.IsPrimarykey.ToString().ToLower()}, IsIdentity = {dbFieldInfo.IsIdentity.ToString().ToLower()})]\n"; } modelcontent += $" public {TableMappingHelper.GetPropertyDatatype(dbFieldInfo.DataType)} {columnName} {{ get; set; }}\n\r"; //主键 - if (dbFieldInfo.IsIdentity) - { - keyTypeName = dbFieldInfo.DataType; + //if (dbFieldInfo.IsIdentity) + //{ + //keyTypeName = dbFieldInfo.DataType; //outputDtocontent += " /// \n"; //outputDtocontent += string.Format(" /// 设置或获取{0}\n", dbFieldInfo.ColumnDescription); //outputDtocontent += " /// \n"; @@ -137,18 +132,18 @@ namespace ZR.CodeGenerator //outputDtocontent += string.Format(" [SqlSugar.SugarColumn(IsIdentity = true, IsPrimaryKey = true)]\n"); //outputDtocontent += string.Format(" public {0} {1}", TableMappingHelper.GetPropertyDatatype(dbFieldInfo.DataType), columnName); //outputDtocontent += " { get; set; }\n\r"; - } - else //非主键 - { - modelcontent += " /// \n"; - modelcontent += string.Format(" /// 设置或获取{0}\n", dbFieldInfo.ColumnDescription); - modelcontent += " /// \n"; - //if (dbFieldInfo.DataType == "string") - //{ - // modelcontent += string.Format(" [MaxLength({0})]\n", dbFieldInfo.FieldMaxLength); - //} - modelcontent += string.Format(" public {0} {1}", TableMappingHelper.GetPropertyDatatype(dbFieldInfo.DataType), columnName); - modelcontent += " { get; set; }\n\r"; + //} + // else //非主键 + //{ + //modelcontent += " /// \n"; + //modelcontent += string.Format(" /// 设置或获取{0}\n", dbFieldInfo.ColumnDescription); + //modelcontent += " /// \n"; + ////if (dbFieldInfo.DataType == "string") + ////{ + //// modelcontent += string.Format(" [MaxLength({0})]\n", dbFieldInfo.FieldMaxLength); + ////} + //modelcontent += string.Format(" public {0} {1}", TableMappingHelper.GetPropertyDatatype(dbFieldInfo.DataType), columnName); + //modelcontent += " { get; set; }\n\r"; //outputDtocontent += " /// \n"; @@ -216,8 +211,8 @@ namespace ZR.CodeGenerator // InputDtocontent += " { get; set; }\n\r"; //} // - } - GenerateModels(modelsNamespace, modelTypeName, tableInfo.TableName, modelcontent, modelTypeDesc, keyTypeName, ifExsitedCovered); + //} + GenerateModels(modelsNamespace, modelTypeName, tableInfo.Name, modelcontent, modelTypeDesc, keyTypeName, ifExsitedCovered); //GenerateIRepository(modelTypeName, modelTypeDesc, keyTypeName, ifExsitedCovered); //GenerateRepository(modelTypeName, modelTypeDesc, tableInfo.TableName, keyTypeName, ifExsitedCovered); //GenerateIService(modelsNamespace, modelTypeName, modelTypeDesc, keyTypeName, ifExsitedCovered); @@ -243,16 +238,14 @@ namespace ZR.CodeGenerator /// 如果目标文件存在,是否覆盖。默认为false private static void GenerateModels(string modelsNamespace, string modelTypeName, string tableName, string modelContent, string modelTypeDesc, string keyTypeName, bool ifExsitedCovered = false) { - var path = AppDomain.CurrentDomain.BaseDirectory; - //path = path.Substring(0, path.IndexOf("\\bin")); - var parentPath = path.Substring(0, path.LastIndexOf("\\")); - var servicesPath = parentPath + "\\" + _option.BaseNamespace + "\\" + modelsNamespace; + var parentPath = "..\\"; + var servicesPath = parentPath + _option.BaseNamespace + "\\" + modelsNamespace; if (!Directory.Exists(servicesPath)) { - servicesPath = parentPath + "\\" + _option.BaseNamespace + "\\Models"; + servicesPath = parentPath + _option.ModelsNamespace; Directory.CreateDirectory(servicesPath); } - var fullPath = servicesPath + "\\" + modelTypeName + ".cs"; + var fullPath = servicesPath + "\\Models\\" + modelTypeName + ".cs"; if (File.Exists(fullPath) && !ifExsitedCovered) return; var content = ReadTemplate("ModelTemplate.txt"); diff --git a/ZR.CodeGenerator/DbProvider.cs b/ZR.CodeGenerator/DbProvider.cs index c4a5265..ed3757e 100644 --- a/ZR.CodeGenerator/DbProvider.cs +++ b/ZR.CodeGenerator/DbProvider.cs @@ -14,7 +14,7 @@ namespace ZR.CodeGenerator public SqlSugarClient GetSugarDbContext(string dbName) { string connStr = ConfigUtils.Instance.GetConnectionStrings(OptionsSetting.Conn).Replace("{DbName}", dbName); - int dbType = ConfigUtils.Instance.GetAppConfig(OptionsSetting.DbType, 0); + int dbType = ConfigUtils.Instance.GetAppConfig(OptionsSetting.CodeGenDbType, 0); return new SqlSugarClient(new List() { diff --git a/ZR.CodeGenerator/Service/CodeGeneraterService.cs b/ZR.CodeGenerator/Service/CodeGeneraterService.cs index 6dc3b1d..a66aa0c 100644 --- a/ZR.CodeGenerator/Service/CodeGeneraterService.cs +++ b/ZR.CodeGenerator/Service/CodeGeneraterService.cs @@ -12,24 +12,6 @@ namespace ZR.CodeGenerator.Service { public class CodeGeneraterService: DbProvider { - ///// - ///// 获取表所有列 - ///// - ///// - ///// - //public List GetAllColumns(string tableName) - //{ - // var dbType = ConfigUtils.Instance.GetConfig("CodeGenDbType"); - // if (tableName == null) - // throw new ArgumentException(nameof(tableName)); - // List list = new List(); - // if (dbType == "1") - // { - // list = CodeGeneratorRepository.GetAllColumns(tableName); - // } - // return list; - //} - /// /// 获取所有数据库名 /// @@ -59,7 +41,6 @@ namespace ZR.CodeGenerator.Service /// /// /// - /// /// /// public List GetAllTables(string dbName, string tableName, PagerInfo pager) diff --git a/ZR.Model/CodeGenerator/DbFieldInfo.cs b/ZR.Model/CodeGenerator/DbFieldInfo.cs deleted file mode 100644 index f5e145e..0000000 --- a/ZR.Model/CodeGenerator/DbFieldInfo.cs +++ /dev/null @@ -1,79 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Text; - -namespace ZR.Model -{ - /// - /// 表的字段 - /// - public class DbFieldInfo - { - public string TableName { get; set; } - /// - /// 初始化 - /// - public DbFieldInfo() - { - FieldName = string.Empty; - Description = string.Empty; - } - /// - /// 字段名称 - /// - public string FieldName { get; set; } - /// - /// 描述 - /// - public string Description { get; set; } - /// - /// 系统数据类型,如 int - /// - public string DataType - { - get; - set; - } - - /// - /// 数据库里面存放的类型。 - /// - public string FieldType { get; set; } - - /// - /// 代表小数位精度。 - /// - public long? FieldScale { get; set; } - /// - /// 数据精度,仅数字类型有效,总共多少位数字(10进制)。 - /// 在MySql里面代表了字段长度 - /// - public long? FieldPrecision { get; set; } - - /// - /// - /// - public long? FieldMaxLength { get; set; } - - /// - /// 可空 - /// - public bool IsNullable { get; set; } - /// - /// 是否为主键字段 - /// - public bool IsIdentity { get; set; } - /// - /// 【未用上】该字段是否自增 - /// - public bool Increment { get; set; } - - - /// - /// 默认值 - /// - public string FieldDefaultValue { get; set; } - - } -} diff --git a/ZR.Model/CodeGenerator/DbTableInfo.cs b/ZR.Model/CodeGenerator/DbTableInfo.cs deleted file mode 100644 index 0752175..0000000 --- a/ZR.Model/CodeGenerator/DbTableInfo.cs +++ /dev/null @@ -1,75 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace ZR.Model -{ - /// - /// 数据表的信息 - /// - public class DbTableInfo - { - /// - /// 表格ID,表的名称。 - /// - public string TableName { get; set; } - - /// - /// 表的别称,或者描述 - /// - public string Description { get; set; } - /// - /// 字段列表 - /// - public List Fileds { get; set; } - /// - /// 初始化 - /// - public DbTableInfo() - { - Fileds = new List(); - } - - /// - /// 获取主键的名称列表。 - /// - /// - public List GetIdentityList() - { - var list = Fileds.Where(x => x.IsIdentity); - if (list == null) return null; - return list.Select(x => x.FieldName).ToList(); - } - /// - /// 获取主键字段列表 - /// - /// - public List GetIdentityFields() - { - var list = Fileds.Where(x => x.IsIdentity); - if (list == null) return null; - return list.ToList(); - } - /// - /// 获取可空字段。 - /// - /// - public List GetIsNullableFields() - { - var list = Fileds.Where(x => x.IsNullable); - if (list == null) return null; - return list.ToList(); - } - /// - /// 获取不可空字段。 - /// - /// - public List GetNotNullableFields() - { - var list = Fileds.Where(x => !x.IsNullable); - if (list == null) return null; - return list.ToList(); - } - } -} diff --git a/ZR.Repository/System/CodeGeneratorRepository.cs b/ZR.Repository/System/CodeGeneratorRepository.cs index b5d5f97..7c1888e 100644 --- a/ZR.Repository/System/CodeGeneratorRepository.cs +++ b/ZR.Repository/System/CodeGeneratorRepository.cs @@ -1,4 +1,5 @@ using Infrastructure.Attribute; +using SqlSugar; using System; using System.Collections.Generic; using System.Linq; @@ -12,50 +13,50 @@ namespace ZR.Repository.System [AppService(ServiceLifetime = LifeTime.Transient)] public class CodeGeneratorRepository : BaseRepository { - /// - /// 获取数据库 - /// - /// - public List GetAllDb() - { - //return Db.Ado.SqlQuery("select name as DbName from master..sysdatabases "); - var list = Db.DbMaintenance.GetDataBaseList(Db); - List dataBases = new List(); - list.ForEach(item => - { - dataBases.Add(new DataBaseInfo() { DbName = item }); - }); - return dataBases; - } + ///// + ///// 获取数据库 + ///// + ///// + //public List GetAllDb() + //{ + // //return Db.Ado.SqlQuery("select name as DbName from master..sysdatabases "); + // var list = Db.DbMaintenance.GetDataBaseList(Db); + // List dataBases = new List(); + // list.ForEach(item => + // { + // dataBases.Add(new DataBaseInfo() { DbName = item }); + // }); + // return dataBases; + //} - /// - /// 根据数据库名获取所有的表 - /// - /// - /// - /// - /// - public List GetAllTables(string dbName, string tableName, PagerInfo pager) - { - var tableList = GetSugarDbContext(dbName).DbMaintenance.GetTableInfoList(true); - if (!string.IsNullOrEmpty(tableName)) - { - tableList = tableList.Where(f => f.Name.Contains(tableName)).ToList(); - } - pager.TotalNum = tableList.Count; - return tableList.Skip(pager.PageSize * (pager.PageNum - 1)).Take(pager.PageSize).OrderBy(f => f.Name).ToList(); - } + ///// + ///// 根据数据库名获取所有的表 + ///// + ///// + ///// + ///// + ///// + //public List GetAllTables(string dbName, string tableName, PagerInfo pager) + //{ + // var tableList = GetSugarDbContext(dbName).DbMaintenance.GetTableInfoList(true); + // if (!string.IsNullOrEmpty(tableName)) + // { + // tableList = tableList.Where(f => f.Name.Contains(tableName)).ToList(); + // } + // pager.TotalNum = tableList.Count; + // return tableList.Skip(pager.PageSize * (pager.PageNum - 1)).Take(pager.PageSize).OrderBy(f => f.Name).ToList(); + //} - /// - /// 获取表格列信息 - /// - /// - /// - /// - public List GetColumnInfo(string dbName, string tableName) - { - return GetSugarDbContext(dbName).DbMaintenance.GetColumnInfosByTableName(tableName, true); - } + ///// + ///// 获取表格列信息 + ///// + ///// + ///// + ///// + //public List GetColumnInfo(string dbName, string tableName) + //{ + // return GetSugarDbContext(dbName).DbMaintenance.GetColumnInfosByTableName(tableName, true); + //} /// @@ -63,12 +64,12 @@ namespace ZR.Repository.System /// /// /// - public List GetAllTables(string[] tabList) - { - string sql = @"SELECT tbs.name as TableName ,ds.value as Description FROM sys.tables tbs - left join sys.extended_properties ds on ds.major_id=tbs.object_id and ds.minor_id=0"; + //public List GetAllTables(string[] tabList) + //{ + // string sql = @"SELECT tbs.name as TableName ,ds.value as Description FROM sys.tables tbs + // left join sys.extended_properties ds on ds.major_id=tbs.object_id and ds.minor_id=0"; - return Db.SqlQueryable(sql).WhereIF(tabList.Length > 0, x => tabList.Contains(x.TableName)).ToList(); - } + // return Db.SqlQueryable(sql).WhereIF(tabList.Length > 0, x => tabList.Contains(x.TableName)).ToList(); + //} } } diff --git a/ZR.Vue/src/views/tool/index.vue b/ZR.Vue/src/views/tool/index.vue index fefeab2..b291e7c 100644 --- a/ZR.Vue/src/views/tool/index.vue +++ b/ZR.Vue/src/views/tool/index.vue @@ -113,15 +113,15 @@ export default { replaceTableNameStr: "", }, rules: { - baseSpace: [ - { required: true, message: "请输入项目名称", trigger: "blur" }, - { - min: 2, - max: 50, - message: "长度在 2 到 50 个字符", - trigger: "blur", - }, - ], + // baseSpace: [ + // { required: true, message: "请输入项目名称", trigger: "blur" }, + // { + // min: 2, + // max: 50, + // message: "长度在 2 到 50 个字符", + // trigger: "blur", + // }, + // ], replaceTableNameStr: [ { min: 0, max: 50, message: "长度小于50个字符", trigger: "blur" }, ], From 2d722579455627da8ad15b2ed52b263c3a0e74ac Mon Sep 17 00:00:00 2001 From: izory <791736813@qq.com> Date: Wed, 8 Sep 2021 07:48:18 +0800 Subject: [PATCH 06/28] =?UTF-8?q?=E5=AE=8C=E6=88=90Model=E3=80=81Dto?= =?UTF-8?q?=E7=9A=84=E4=BB=A3=E7=A0=81=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ZR.Admin.WebApi/Template/InputDtoTemplate.txt | 20 ++ ZR.Admin.WebApi/Template/ModelTemplate.txt | 2 +- ZR.Admin.WebApi/ZR.Admin.WebApi.csproj | 3 + ZR.CodeGenerator/CodeGeneratorTool.cs | 194 ++++++++++-------- 4 files changed, 127 insertions(+), 92 deletions(-) create mode 100644 ZR.Admin.WebApi/Template/InputDtoTemplate.txt diff --git a/ZR.Admin.WebApi/Template/InputDtoTemplate.txt b/ZR.Admin.WebApi/Template/InputDtoTemplate.txt new file mode 100644 index 0000000..f38f62b --- /dev/null +++ b/ZR.Admin.WebApi/Template/InputDtoTemplate.txt @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using {ModelsNamespace}; + +namespace {DtosNamespace} +{ + /// + /// {TableNameDesc}输入对象模型 + /// + public class {ModelTypeName}Dto + { +{PropertyName} + } + + public class {ModelTypeName}QueryDto: PagerInfo + { + + + } +} diff --git a/ZR.Admin.WebApi/Template/ModelTemplate.txt b/ZR.Admin.WebApi/Template/ModelTemplate.txt index 47fafe1..23e36c5 100644 --- a/ZR.Admin.WebApi/Template/ModelTemplate.txt +++ b/ZR.Admin.WebApi/Template/ModelTemplate.txt @@ -9,6 +9,6 @@ namespace {ModelsNamespace} [SqlSugar.SugarTable("{TableName}")] public class {ModelTypeName} { -{ModelContent} +{PropertyName} } } diff --git a/ZR.Admin.WebApi/ZR.Admin.WebApi.csproj b/ZR.Admin.WebApi/ZR.Admin.WebApi.csproj index ed4e7c1..5bbdc8a 100644 --- a/ZR.Admin.WebApi/ZR.Admin.WebApi.csproj +++ b/ZR.Admin.WebApi/ZR.Admin.WebApi.csproj @@ -57,6 +57,9 @@ TextTemplatingFileGenerator Controller.cs + + Always + Always diff --git a/ZR.CodeGenerator/CodeGeneratorTool.cs b/ZR.CodeGenerator/CodeGeneratorTool.cs index f390fa7..5162a9b 100644 --- a/ZR.CodeGenerator/CodeGeneratorTool.cs +++ b/ZR.CodeGenerator/CodeGeneratorTool.cs @@ -39,7 +39,7 @@ namespace ZR.CodeGenerator public static void Generate(string dbName, string baseNamespace, DbTableInfo dbTableInfo, string replaceTableNameStr, bool ifExsitedCovered = false) { _option.BaseNamespace = baseNamespace; - _option.DtosNamespace = baseNamespace + "ZR.Model.Dto"; + _option.DtosNamespace = baseNamespace + "ZR.Model"; _option.ModelsNamespace = baseNamespace + "ZR.Model"; //_option.IRepositoriesNamespace = baseNamespace + ".IRepositorie"; _option.RepositoriesNamespace = baseNamespace + "ZR.Repository"; @@ -86,14 +86,8 @@ namespace ZR.CodeGenerator public static void GenerateSingle(List listField, DbTableInfo tableInfo, bool ifExsitedCovered = false) { var modelsNamespace = _option.ModelsNamespace; - var modelTypeName = tableInfo.Name;//表名 + var modelTypeName = GetModelName(tableInfo.Name); ;//表名 var modelTypeDesc = tableInfo.Description;//表描述 - if (!string.IsNullOrEmpty(_option.ReplaceTableNameStr)) - { - modelTypeName = modelTypeName.Replace(_option.ReplaceTableNameStr.ToString(), ""); - } - modelTypeName = modelTypeName.Replace("_", ""); - modelTypeName = modelTypeName.Substring(0, 1).ToUpper() + modelTypeName.Substring(1); string keyTypeName = "string";//主键数据类型 string modelcontent = "";//数据库模型字段 @@ -121,104 +115,75 @@ namespace ZR.CodeGenerator } modelcontent += $" public {TableMappingHelper.GetPropertyDatatype(dbFieldInfo.DataType)} {columnName} {{ get; set; }}\n\r"; - //主键 - //if (dbFieldInfo.IsIdentity) + //if (dbFieldInfo.DataType == "string") //{ - //keyTypeName = dbFieldInfo.DataType; - //outputDtocontent += " /// \n"; - //outputDtocontent += string.Format(" /// 设置或获取{0}\n", dbFieldInfo.ColumnDescription); - //outputDtocontent += " /// \n"; - - //outputDtocontent += string.Format(" [SqlSugar.SugarColumn(IsIdentity = true, IsPrimaryKey = true)]\n"); - //outputDtocontent += string.Format(" public {0} {1}", TableMappingHelper.GetPropertyDatatype(dbFieldInfo.DataType), columnName); - //outputDtocontent += " { get; set; }\n\r"; + // outputDtocontent += string.Format(" [MaxLength({0})]\n", dbFieldInfo.FieldMaxLength); //} - // else //非主键 + //outputDtocontent += string.Format(" public {0} {1}", dbFieldInfo.DataType, columnName); + //outputDtocontent += " { get; set; }\n\r"; + //if (dbFieldInfo.DataType == "bool" || dbFieldInfo.DataType == "tinyint") //{ - //modelcontent += " /// \n"; - //modelcontent += string.Format(" /// 设置或获取{0}\n", dbFieldInfo.ColumnDescription); - //modelcontent += " /// \n"; - ////if (dbFieldInfo.DataType == "string") - ////{ - //// modelcontent += string.Format(" [MaxLength({0})]\n", dbFieldInfo.FieldMaxLength); - ////} - //modelcontent += string.Format(" public {0} {1}", TableMappingHelper.GetPropertyDatatype(dbFieldInfo.DataType), columnName); - //modelcontent += " { get; set; }\n\r"; + // vueViewListContent += string.Format(" \n", columnName, dbFieldInfo.ColumnDescription); + // vueViewListContent += " \n"; + // vueViewListContent += " \n"; - //outputDtocontent += " /// \n"; - //outputDtocontent += string.Format(" /// 设置或获取{0}\n", dbFieldInfo.ColumnDescription); - //outputDtocontent += " /// \n"; - //if (dbFieldInfo.DataType == "string") - //{ - // outputDtocontent += string.Format(" [MaxLength({0})]\n", dbFieldInfo.FieldMaxLength); - //} - //outputDtocontent += string.Format(" public {0} {1}", dbFieldInfo.DataType, columnName); - //outputDtocontent += " { get; set; }\n\r"; - //if (dbFieldInfo.DataType == "bool" || dbFieldInfo.DataType == "tinyint") - //{ + // vueViewFromContent += string.Format(" ", dbFieldInfo.ColumnDescription, columnName); + // vueViewFromContent += string.Format(" \n", columnName); + // vueViewFromContent += " \n"; + // vueViewFromContent += " \n"; + // vueViewFromContent += " \n"; + // vueViewFromContent += " \n"; - // vueViewListContent += string.Format(" \n", columnName, dbFieldInfo.ColumnDescription); - // vueViewListContent += " \n"; - // vueViewListContent += " \n"; + // vueViewEditFromContent += string.Format(" {0}: 'true',\n", columnName); + // vueViewEditFromBindContent += string.Format(" this.editFrom.{0} = res.ResData.{0}+''\n", columnName); + //} + //else + //{ + // vueViewListContent += string.Format(" \n", columnName, dbFieldInfo.ColumnDescription); - // vueViewFromContent += string.Format(" ", dbFieldInfo.ColumnDescription, columnName); - // vueViewFromContent += string.Format(" \n", columnName); - // vueViewFromContent += " \n"; - // vueViewFromContent += " \n"; - // vueViewFromContent += " \n"; - // vueViewFromContent += " \n"; + // vueViewFromContent += string.Format(" \n", dbFieldInfo.ColumnDescription, columnName); + // vueViewFromContent += string.Format(" \n", columnName, dbFieldInfo.ColumnDescription); + // vueViewFromContent += " \n"; + // vueViewEditFromContent += string.Format(" {0}: '',\n", columnName); + // vueViewEditFromBindContent += string.Format(" this.editFrom.{0} = res.ResData.{0}\n", columnName); + //} + //vueViewSaveBindContent += string.Format(" '{0}':this.editFrom.{0},\n", columnName); + //if (!dbFieldInfo.IsNullable) + //{ + // vueViewEditFromRuleContent += string.Format(" {0}: [\n", columnName); + // vueViewEditFromRuleContent += " {"; + // vueViewEditFromRuleContent += string.Format("required: true, message:\"请输入{0}\", trigger: \"blur\"", dbFieldInfo.ColumnDescription); + // vueViewEditFromRuleContent += "},\n { min: 2, max: 50, message: \"长度在 2 到 50 个字符\", trigger:\"blur\" }\n"; + // vueViewEditFromRuleContent += " ],\n"; + //} - // vueViewEditFromContent += string.Format(" {0}: 'true',\n", columnName); - // vueViewEditFromBindContent += string.Format(" this.editFrom.{0} = res.ResData.{0}+''\n", columnName); - //} - //else - //{ - // vueViewListContent += string.Format(" \n", columnName, dbFieldInfo.ColumnDescription); - - // vueViewFromContent += string.Format(" \n", dbFieldInfo.ColumnDescription, columnName); - // vueViewFromContent += string.Format(" \n", columnName, dbFieldInfo.ColumnDescription); - // vueViewFromContent += " \n"; - // vueViewEditFromContent += string.Format(" {0}: '',\n", columnName); - // vueViewEditFromBindContent += string.Format(" this.editFrom.{0} = res.ResData.{0}\n", columnName); - //} - //vueViewSaveBindContent += string.Format(" '{0}':this.editFrom.{0},\n", columnName); - //if (!dbFieldInfo.IsNullable) - //{ - // vueViewEditFromRuleContent += string.Format(" {0}: [\n", columnName); - // vueViewEditFromRuleContent += " {"; - // vueViewEditFromRuleContent += string.Format("required: true, message:\"请输入{0}\", trigger: \"blur\"", dbFieldInfo.ColumnDescription); - // vueViewEditFromRuleContent += "},\n { min: 2, max: 50, message: \"长度在 2 到 50 个字符\", trigger:\"blur\" }\n"; - // vueViewEditFromRuleContent += " ],\n"; - //} - } //if (!inputDtoNoField.Contains(columnName) || columnName == "Id") //{ - // InputDtocontent += " /// \n"; - // InputDtocontent += string.Format(" /// 设置或获取{0}\n", dbFieldInfo.ColumnDescription); - // InputDtocontent += " /// \n"; - // //if (dbFieldInfo.FieldType == "string") - // //{ - // // InputDtocontent += string.Format(" [MaxLength({0})]\n", dbFieldInfo.FieldMaxLength); - // //} - // InputDtocontent += string.Format(" public {0} {1}", dbFieldInfo.DataType, columnName); - // InputDtocontent += " { get; set; }\n\r"; + InputDtocontent += " /// \n"; + InputDtocontent += string.Format(" /// 设置或获取{0}\n", dbFieldInfo.ColumnDescription); + InputDtocontent += " /// \n"; + //if (dbFieldInfo.FieldType == "string") + //{ + // InputDtocontent += string.Format(" [MaxLength({0})]\n", dbFieldInfo.FieldMaxLength); + //} + InputDtocontent += $" public {TableMappingHelper.GetPropertyDatatype(dbFieldInfo.DataType)} {columnName} {{ get; set; }}\n\r"; //} // - //} + } GenerateModels(modelsNamespace, modelTypeName, tableInfo.Name, modelcontent, modelTypeDesc, keyTypeName, ifExsitedCovered); + GenerateInputDto(modelsNamespace, modelTypeName, modelTypeDesc, InputDtocontent, keyTypeName, ifExsitedCovered); //GenerateIRepository(modelTypeName, modelTypeDesc, keyTypeName, ifExsitedCovered); //GenerateRepository(modelTypeName, modelTypeDesc, tableInfo.TableName, keyTypeName, ifExsitedCovered); //GenerateIService(modelsNamespace, modelTypeName, modelTypeDesc, keyTypeName, ifExsitedCovered); //GenerateService(modelsNamespace, modelTypeName, modelTypeDesc, keyTypeName, ifExsitedCovered); //GenerateOutputDto(modelTypeName, modelTypeDesc, outputDtocontent, ifExsitedCovered); - //GenerateInputDto(modelsNamespace, modelTypeName, modelTypeDesc, InputDtocontent, keyTypeName, ifExsitedCovered); //GenerateControllers(modelTypeName, modelTypeDesc, keyTypeName, ifExsitedCovered); //GenerateVueViews(modelTypeName, modelTypeDesc, vueViewListContent, vueViewFromContent, vueViewEditFromContent, vueViewEditFromBindContent, vueViewSaveBindContent, vueViewEditFromRuleContent, ifExsitedCovered); } @@ -238,13 +203,15 @@ namespace ZR.CodeGenerator /// 如果目标文件存在,是否覆盖。默认为false private static void GenerateModels(string modelsNamespace, string modelTypeName, string tableName, string modelContent, string modelTypeDesc, string keyTypeName, bool ifExsitedCovered = false) { - var parentPath = "..\\"; - var servicesPath = parentPath + _option.BaseNamespace + "\\" + modelsNamespace; + var parentPath = ".."; + //../ZR.Model + var servicesPath = parentPath + "\\" + _option.BaseNamespace + "\\" + modelsNamespace; if (!Directory.Exists(servicesPath)) { - servicesPath = parentPath + _option.ModelsNamespace; + //servicesPath = parentPath + "\\" + _option.ModelsNamespace; Directory.CreateDirectory(servicesPath); } + // ../ZR.Model/Models/User.cs var fullPath = servicesPath + "\\Models\\" + modelTypeName + ".cs"; if (File.Exists(fullPath) && !ifExsitedCovered) return; @@ -254,14 +221,59 @@ namespace ZR.CodeGenerator .Replace("{ModelTypeName}", modelTypeName) .Replace("{TableNameDesc}", modelTypeDesc) .Replace("{KeyTypeName}", keyTypeName) - .Replace("{ModelContent}", modelContent) + .Replace("{PropertyName}", modelContent) .Replace("{TableName}", tableName); WriteAndSave(fullPath, content); } + + + /// + /// 生成InputDto文件 + /// + /// + /// + /// + /// + /// + /// 如果目标文件存在,是否覆盖。默认为false + private static void GenerateInputDto(string modelsNamespace, string modelTypeName, string modelTypeDesc, string modelContent, string keyTypeName, bool ifExsitedCovered = false) + { + var parentPath = ".."; + var servicesPath = parentPath + "\\" + _option.BaseNamespace + "\\" + modelsNamespace; + if (!Directory.Exists(servicesPath)) + { + //servicesPath = parentPath + "\\" + _option.BaseNamespace + "\\Dtos"; + Directory.CreateDirectory(servicesPath); + } + // ../ZR.Model/Dto/User.cs + var fullPath = servicesPath + "\\Dto\\" + modelTypeName + "Dto.cs"; + if (File.Exists(fullPath) && !ifExsitedCovered) + return; + var content = ReadTemplate("InputDtoTemplate.txt"); + content = content + .Replace("{DtosNamespace}", _option.DtosNamespace) + .Replace("{ModelsNamespace}", modelsNamespace) + .Replace("{TableNameDesc}", modelTypeDesc) + .Replace("{KeyTypeName}", keyTypeName) + .Replace("{PropertyName}", modelContent) + .Replace("{ModelTypeName}", modelTypeName); + WriteAndSave(fullPath, content); + } #endregion #region 帮助方法 + private static string GetModelName(string modelTypeName) + { + if (!string.IsNullOrEmpty(_option.ReplaceTableNameStr)) + { + modelTypeName = modelTypeName.Replace(_option.ReplaceTableNameStr.ToString(), ""); + } + modelTypeName = modelTypeName.Replace("_", ""); + modelTypeName = modelTypeName.Substring(0, 1).ToUpper() + modelTypeName.Substring(1); + return modelTypeName; + } + /// /// 从代码模板中读取内容 /// From 8478df3a1193805d2c904582da5e09c85ec77a1d Mon Sep 17 00:00:00 2001 From: izory <791736813@qq.com> Date: Wed, 8 Sep 2021 18:12:08 +0800 Subject: [PATCH 07/28] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E7=94=9F=E6=88=90?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0service=E3=80=81Repository=E3=80=81Controller?= =?UTF-8?q?=E5=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/CodeGeneratorController.cs | 11 +- ZR.Admin.WebApi/Extensions/EntityExtension.cs | 12 +- .../Template/ControllersTemplate.txt | 124 +++++++ ZR.Admin.WebApi/Template/IServiceTemplate.txt | 13 + .../Template/RepositoryTemplate.txt | 24 ++ ZR.Admin.WebApi/Template/ServiceTemplate.txt | 28 ++ ZR.Admin.WebApi/Template/VueJsTemplate.txt | 85 +++++ ZR.Admin.WebApi/Template/VueTemplate.txt | 249 +++++++++++++ ZR.Admin.WebApi/ZR.Admin.WebApi.csproj | 28 ++ ZR.Admin.WebApi/appsettings.Production.json | 3 +- ZR.CodeGenerator/CodeGeneratorTool.cs | 330 +++++++++++++++--- ZR.CodeGenerator/DbProvider.cs | 21 +- .../Service/CodeGeneraterService.cs | 34 +- .../System/CodeGeneratorRepository.cs | 75 ---- ZR.Service/System/CodeGeneratorService.cs | 99 ------ ZR.Service/ZR.Service.csproj | 4 + ZR.Vue/src/views/tool/index.vue | 45 +-- 17 files changed, 897 insertions(+), 288 deletions(-) create mode 100644 ZR.Admin.WebApi/Template/ControllersTemplate.txt create mode 100644 ZR.Admin.WebApi/Template/IServiceTemplate.txt create mode 100644 ZR.Admin.WebApi/Template/RepositoryTemplate.txt create mode 100644 ZR.Admin.WebApi/Template/ServiceTemplate.txt create mode 100644 ZR.Admin.WebApi/Template/VueJsTemplate.txt create mode 100644 ZR.Admin.WebApi/Template/VueTemplate.txt delete mode 100644 ZR.Repository/System/CodeGeneratorRepository.cs delete mode 100644 ZR.Service/System/CodeGeneratorService.cs diff --git a/ZR.Admin.WebApi/Controllers/CodeGeneratorController.cs b/ZR.Admin.WebApi/Controllers/CodeGeneratorController.cs index 81d751d..92bd1f5 100644 --- a/ZR.Admin.WebApi/Controllers/CodeGeneratorController.cs +++ b/ZR.Admin.WebApi/Controllers/CodeGeneratorController.cs @@ -37,7 +37,6 @@ namespace ZR.Admin.WebApi.Controllers /// [HttpGet("GetListDataBase")] //[YuebonAuthorize("GetListDataBase")] - //[NoPermissionRequired] public IActionResult GetListDataBase() { return SUCCESS(_CodeGeneraterService.GetAllDataBases()); @@ -53,12 +52,8 @@ namespace ZR.Admin.WebApi.Controllers [HttpGet("FindListTable")] public IActionResult FindListTable(string dbName, string tableName, PagerInfo pager) { - if (string.IsNullOrEmpty(dbName)) - { - dbName = "ZrAdmin"; - } - List list = _CodeGeneraterService.GetAllTables(dbName, tableName, pager); - var vm = new VMPageResult(list, pager); + List list = _CodeGeneraterService.GetAllTables(dbName, tableName, pager); + var vm = new VMPageResult(list, pager); return SUCCESS(vm); } @@ -81,7 +76,7 @@ namespace ZR.Admin.WebApi.Controllers } if (string.IsNullOrEmpty(baseSpace)) { - //baseSpace = "Zr"; + baseSpace = "ZR.Admin"; } DbTableInfo dbTableInfo = new() { Name = tables }; CodeGeneratorTool.Generate(dbName, baseSpace, dbTableInfo, replaceTableNameStr, true); diff --git a/ZR.Admin.WebApi/Extensions/EntityExtension.cs b/ZR.Admin.WebApi/Extensions/EntityExtension.cs index d518656..c472ed5 100644 --- a/ZR.Admin.WebApi/Extensions/EntityExtension.cs +++ b/ZR.Admin.WebApi/Extensions/EntityExtension.cs @@ -10,13 +10,13 @@ namespace ZR.Admin.WebApi.Extensions { var types = source.GetType(); - var worker = new IdWorker(1, 1); - if (types.GetProperty("ID") != null) - { - long id = worker.NextId(); + //var worker = new IdWorker(1, 1); + //if (types.GetProperty("ID") != null) + //{ + // long id = worker.NextId(); - types.GetProperty("ID").SetValue(source, id.ToString(), null); - } + // types.GetProperty("ID").SetValue(source, id.ToString(), null); + //} if (types.GetProperty("CreateTime") != null) { diff --git a/ZR.Admin.WebApi/Template/ControllersTemplate.txt b/ZR.Admin.WebApi/Template/ControllersTemplate.txt new file mode 100644 index 0000000..6ff88ef --- /dev/null +++ b/ZR.Admin.WebApi/Template/ControllersTemplate.txt @@ -0,0 +1,124 @@ +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; +using SqlSugar; +using Infrastructure; +using Infrastructure.Attribute; +using Infrastructure.Enums; +using Infrastructure.Model; +using Mapster; +using ZR.Admin.WebApi.Extensions; +using ZR.Model; + +namespace ZRAdmin.Controllers +{ + /// + /// T4代码自动生成 + /// + + [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 = "<#=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("{{primaryKey}}")] + public IActionResult Get(int {primaryKey}) + { + var response = _<#=ServiceName#>.GetId({primaryKey}); + + return SUCCESS(response); + } + + /// + /// 添加<#=FileName#> + /// + /// + [HttpPost] + [ActionPermissionFilter(Permission = "<#=ModelName#>: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("edit")] + [ActionPermissionFilter(Permission = "<#=ModelName#>:update")] + [Log(Title = "<#=FileName#>修改", BusinessType = BusinessType.UPDATE)] + public IActionResult Update([FromBody] <#=ModelName#>Dto parm) + { + //从 Dto 映射到 实体 + var addModel = parm.Adapt<<#=ModelName#>>().ToCreate(); + //addModel.CreateID = User.Identity.Name; + //TODO 字段映射 + var response = _<#=ServiceName#>.Update(addModel); + + return SUCCESS(response); + } + + /// + /// 删除<#=FileName#> + /// + /// + [HttpDelete("{{primaryKey}}")] + [ActionPermissionFilter(Permission = "<#=ModelName#>:delete")] + [Log(Title = "<#=FileName#>删除", BusinessType = BusinessType.DELETE)] + public IActionResult Delete(int {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/Template/IServiceTemplate.txt b/ZR.Admin.WebApi/Template/IServiceTemplate.txt new file mode 100644 index 0000000..7bd979a --- /dev/null +++ b/ZR.Admin.WebApi/Template/IServiceTemplate.txt @@ -0,0 +1,13 @@ +using System; +using ZR.Model.System; +using ZR.Model; + +namespace {IServicsNamespace} +{ + /// + /// 定义{TableNameDesc}服务接口 + /// + public interface I{ModelTypeName}Service: IBaseService<{ModelTypeName}> + { + } +} diff --git a/ZR.Admin.WebApi/Template/RepositoryTemplate.txt b/ZR.Admin.WebApi/Template/RepositoryTemplate.txt new file mode 100644 index 0000000..78765e4 --- /dev/null +++ b/ZR.Admin.WebApi/Template/RepositoryTemplate.txt @@ -0,0 +1,24 @@ +using System; +using Infrastructure.Attribute; +using {RepositoriesNamespace}.System; +using {ModelsNamespace}; + +namespace {RepositoriesNamespace} +{ + /// + /// {TableNameDesc}仓储接口的实现 + /// + [AppService(ServiceLifetime = LifeTime.Transient)] + public class {ModelTypeName}Repository : BaseRepository + { + public {ModelTypeName}Repository() + { + } + + #region 业务逻辑代码 + + + + #endregion + } +} \ No newline at end of file diff --git a/ZR.Admin.WebApi/Template/ServiceTemplate.txt b/ZR.Admin.WebApi/Template/ServiceTemplate.txt new file mode 100644 index 0000000..de593c9 --- /dev/null +++ b/ZR.Admin.WebApi/Template/ServiceTemplate.txt @@ -0,0 +1,28 @@ +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; +using ZR.Repository; +using ZR.Service.IService; + +namespace {ServicesNamespace} +{ + /// + /// {TableNameDesc}服务接口实现 + /// + [AppService(ServiceType = typeof(I{ModelTypeName}Service), ServiceLifetime = LifeTime.Transient)] + public class {ModelTypeName}Service: BaseService<{ModelTypeName}>, I{ModelTypeName}Service + { + private readonly {ModelTypeName}Repository _repository; + public {ModelTypeName}Service({ModelTypeName}Repository repository) + { + _repository = repository; + } + } +} \ No newline at end of file diff --git a/ZR.Admin.WebApi/Template/VueJsTemplate.txt b/ZR.Admin.WebApi/Template/VueJsTemplate.txt new file mode 100644 index 0000000..d882fc9 --- /dev/null +++ b/ZR.Admin.WebApi/Template/VueJsTemplate.txt @@ -0,0 +1,85 @@ +import http from '@/utils/request' +import defaultSettings from '@/settings' + +/** + * {ModelTypeDesc}分页查询 + * @param {查询条件} data + */ +export function get{ModelTypeName}ListWithPager(data) { + return http.request({ + url: '{ModelTypeName}/FindWithPagerAsync', + method: 'post', + data: data, + baseURL: defaultSettings.api{fileClassName}Url // 直接通过覆盖的方式 + }) +}/** + * 获取所有可用的{ModelTypeDesc} + */ +export function getAll{ModelTypeName}List() { + return http.request({ + url: '{ModelTypeName}/GetAllEnable', + method: 'get', + baseURL: defaultSettings.api{fileClassName}Url // 直接通过覆盖的方式 + }) +} +/** + * 新增或修改保存{ModelTypeDesc} + * @param data + */ +export function save{ModelTypeName}(data, url) { + return http.request({ + url: url, + method: 'post', + data: data, + baseURL: defaultSettings.api{fileClassName}Url // 直接通过覆盖的方式 + }) +} +/** + * 获取{ModelTypeDesc}详情 + * @param {Id} {ModelTypeDesc}Id + */ +export function get{ModelTypeName}Detail(id) { + return http({ + url: '{ModelTypeName}/GetById', + method: 'get', + params: { id: id }, + baseURL: defaultSettings.api{fileClassName}Url // 直接通过覆盖的方式 + }) +} +/** + * 批量设置启用状态 + * @param {id集合} ids + */ +export function set{ModelTypeName}Enable(data) { + return http({ + url: '{ModelTypeName}/SetEnabledMarktBatchAsync', + method: 'post', + data: data, + baseURL: defaultSettings.api{fileClassName}Url // 直接通过覆盖的方式 + }) +} +/** + * 批量软删除 + * @param {id集合} ids + */ +export function deleteSoft{ModelTypeName}(data) { + return http({ + url: '{ModelTypeName}/DeleteSoftBatchAsync', + method: 'post', + data: data, + baseURL: defaultSettings.api{fileClassName}Url // 直接通过覆盖的方式 + }) +} + +/** + * 批量删除 + * @param {id集合} ids + */ +export function delete{ModelTypeName}(data) { + return http({ + url: '{ModelTypeName}/DeleteBatchAsync', + method: 'delete', + data: data, + baseURL: defaultSettings.api{fileClassName}Url // 直接通过覆盖的方式 + }) +} diff --git a/ZR.Admin.WebApi/Template/VueTemplate.txt b/ZR.Admin.WebApi/Template/VueTemplate.txt new file mode 100644 index 0000000..e109a38 --- /dev/null +++ b/ZR.Admin.WebApi/Template/VueTemplate.txt @@ -0,0 +1,249 @@ + + + diff --git a/ZR.Admin.WebApi/ZR.Admin.WebApi.csproj b/ZR.Admin.WebApi/ZR.Admin.WebApi.csproj index 5bbdc8a..cbbf3ed 100644 --- a/ZR.Admin.WebApi/ZR.Admin.WebApi.csproj +++ b/ZR.Admin.WebApi/ZR.Admin.WebApi.csproj @@ -57,12 +57,30 @@ TextTemplatingFileGenerator Controller.cs + + Always + Always + + Always + Always + + Always + + + Always + + + Always + + + Always + @@ -70,6 +88,16 @@ + + + + Always + + + Always + + + diff --git a/ZR.Admin.WebApi/appsettings.Production.json b/ZR.Admin.WebApi/appsettings.Production.json index 4dd2ae0..8dd126d 100644 --- a/ZR.Admin.WebApi/appsettings.Production.json +++ b/ZR.Admin.WebApi/appsettings.Production.json @@ -7,7 +7,8 @@ } }, "ConnectionStrings": { - "Conn_Admin": "server=127.0.0.1;database=admin;user=zr;pwd=abc" + "Conn_Admin": "server=127.0.0.1,1433;database=admin;user=admin;pwd=abc", + "ConnDynamic": "server=127.0.0.1,1433;uid=dev_test;Password=%54Gz@cn;database={database}" }, "urls": "http://localhost:8888", "sysConfig": { diff --git a/ZR.CodeGenerator/CodeGeneratorTool.cs b/ZR.CodeGenerator/CodeGeneratorTool.cs index 5162a9b..2ad6547 100644 --- a/ZR.CodeGenerator/CodeGeneratorTool.cs +++ b/ZR.CodeGenerator/CodeGeneratorTool.cs @@ -43,9 +43,9 @@ namespace ZR.CodeGenerator _option.ModelsNamespace = baseNamespace + "ZR.Model"; //_option.IRepositoriesNamespace = baseNamespace + ".IRepositorie"; _option.RepositoriesNamespace = baseNamespace + "ZR.Repository"; - //_option.IServicsNamespace = baseNamespace + ".IService"; + _option.IServicsNamespace = baseNamespace + "ZR.Service"; _option.ServicesNamespace = baseNamespace + "ZR.Service"; - _option.ApiControllerNamespace = baseNamespace + "Api"; + _option.ApiControllerNamespace = baseNamespace + "ZR.Admin.WebApi"; _option.ReplaceTableNameStr = replaceTableNameStr; //_option.TableList = listTable; @@ -88,6 +88,7 @@ namespace ZR.CodeGenerator var modelsNamespace = _option.ModelsNamespace; var modelTypeName = GetModelName(tableInfo.Name); ;//表名 var modelTypeDesc = tableInfo.Description;//表描述 + var primaryKey = "id";//主键 string keyTypeName = "string";//主键数据类型 string modelcontent = "";//数据库模型字段 @@ -111,6 +112,7 @@ namespace ZR.CodeGenerator modelcontent += " ///
\n"; if (dbFieldInfo.IsIdentity || dbFieldInfo.IsPrimarykey) { + primaryKey = columnName; modelcontent += $" [SqlSugar.SugarColumn(IsPrimaryKey = {dbFieldInfo.IsPrimarykey.ToString().ToLower()}, IsIdentity = {dbFieldInfo.IsIdentity.ToString().ToLower()})]\n"; } modelcontent += $" public {TableMappingHelper.GetPropertyDatatype(dbFieldInfo.DataType)} {columnName} {{ get; set; }}\n\r"; @@ -121,39 +123,43 @@ namespace ZR.CodeGenerator //} //outputDtocontent += string.Format(" public {0} {1}", dbFieldInfo.DataType, columnName); //outputDtocontent += " { get; set; }\n\r"; - //if (dbFieldInfo.DataType == "bool" || dbFieldInfo.DataType == "tinyint") - //{ + if (dbFieldInfo.DataType == "bool" || dbFieldInfo.DataType == "tinyint") + { - // vueViewListContent += string.Format(" \n", columnName, dbFieldInfo.ColumnDescription); - // vueViewListContent += " \n"; - // vueViewListContent += " \n"; + vueViewListContent += string.Format(" \n", columnName, dbFieldInfo.ColumnDescription); + vueViewListContent += " \n"; + vueViewListContent += " \n"; - // vueViewFromContent += string.Format(" ", dbFieldInfo.ColumnDescription, columnName); - // vueViewFromContent += string.Format(" \n", columnName); - // vueViewFromContent += " \n"; - // vueViewFromContent += " \n"; - // vueViewFromContent += " \n"; - // vueViewFromContent += " \n"; + vueViewFromContent += string.Format(" ", dbFieldInfo.ColumnDescription, columnName); + vueViewFromContent += string.Format(" \n", columnName); + vueViewFromContent += " \n"; + vueViewFromContent += " \n"; + vueViewFromContent += " \n"; + vueViewFromContent += " \n"; - // vueViewEditFromContent += string.Format(" {0}: 'true',\n", columnName); - // vueViewEditFromBindContent += string.Format(" this.editFrom.{0} = res.ResData.{0}+''\n", columnName); - //} - //else - //{ - // vueViewListContent += string.Format(" \n", columnName, dbFieldInfo.ColumnDescription); + vueViewEditFromContent += string.Format(" {0}: 'true',\n", columnName); + vueViewEditFromBindContent += string.Format(" this.editFrom.{0} = res.data.{0}+''\n", columnName); + } + else + { + //table-column + vueViewListContent += $" \n"; - // vueViewFromContent += string.Format(" \n", dbFieldInfo.ColumnDescription, columnName); - // vueViewFromContent += string.Format(" \n", columnName, dbFieldInfo.ColumnDescription); - // vueViewFromContent += " \n"; - // vueViewEditFromContent += string.Format(" {0}: '',\n", columnName); - // vueViewEditFromBindContent += string.Format(" this.editFrom.{0} = res.ResData.{0}\n", columnName); - //} + //form-item + vueViewFromContent += $" \n"; + vueViewFromContent += $" \n"; + vueViewFromContent += " \n"; + vueViewEditFromContent += string.Format(" {0}: '',\n", columnName); + vueViewEditFromBindContent += string.Format(" this.editFrom.{0} = res.ResData.{0}\n", columnName); + } //vueViewSaveBindContent += string.Format(" '{0}':this.editFrom.{0},\n", columnName); + + //Rule 规则验证 //if (!dbFieldInfo.IsNullable) //{ // vueViewEditFromRuleContent += string.Format(" {0}: [\n", columnName); @@ -169,23 +175,20 @@ namespace ZR.CodeGenerator InputDtocontent += " /// \n"; InputDtocontent += string.Format(" /// 设置或获取{0}\n", dbFieldInfo.ColumnDescription); InputDtocontent += " /// \n"; - //if (dbFieldInfo.FieldType == "string") - //{ - // InputDtocontent += string.Format(" [MaxLength({0})]\n", dbFieldInfo.FieldMaxLength); - //} InputDtocontent += $" public {TableMappingHelper.GetPropertyDatatype(dbFieldInfo.DataType)} {columnName} {{ get; set; }}\n\r"; //} // } - GenerateModels(modelsNamespace, modelTypeName, tableInfo.Name, modelcontent, modelTypeDesc, keyTypeName, ifExsitedCovered); - GenerateInputDto(modelsNamespace, modelTypeName, modelTypeDesc, InputDtocontent, keyTypeName, ifExsitedCovered); - //GenerateIRepository(modelTypeName, modelTypeDesc, keyTypeName, ifExsitedCovered); - //GenerateRepository(modelTypeName, modelTypeDesc, tableInfo.TableName, keyTypeName, ifExsitedCovered); + //GenerateModels(modelsNamespace, modelTypeName, tableInfo.Name, modelcontent, modelTypeDesc, keyTypeName, ifExsitedCovered); + //GenerateInputDto(modelsNamespace, modelTypeName, modelTypeDesc, InputDtocontent, keyTypeName, ifExsitedCovered); + //GenerateRepository(modelTypeName, modelTypeDesc, tableInfo.Name, keyTypeName, ifExsitedCovered); //GenerateIService(modelsNamespace, modelTypeName, modelTypeDesc, keyTypeName, ifExsitedCovered); //GenerateService(modelsNamespace, modelTypeName, modelTypeDesc, keyTypeName, ifExsitedCovered); + //GenerateControllers(modelTypeName, primaryKey, modelTypeDesc, keyTypeName, ifExsitedCovered); + + //GenerateIRepository(modelTypeName, modelTypeDesc, keyTypeName, ifExsitedCovered); //GenerateOutputDto(modelTypeName, modelTypeDesc, outputDtocontent, ifExsitedCovered); - //GenerateControllers(modelTypeName, modelTypeDesc, keyTypeName, ifExsitedCovered); - //GenerateVueViews(modelTypeName, modelTypeDesc, vueViewListContent, vueViewFromContent, vueViewEditFromContent, vueViewEditFromBindContent, vueViewSaveBindContent, vueViewEditFromRuleContent, ifExsitedCovered); + GenerateVueViews(modelTypeName, primaryKey, modelTypeDesc, vueViewListContent, vueViewFromContent, vueViewEditFromContent, vueViewEditFromBindContent, vueViewSaveBindContent, vueViewEditFromRuleContent, ifExsitedCovered); } @@ -261,6 +264,210 @@ namespace ZR.CodeGenerator } #endregion + #region 生成Repository + + /// + /// 生成Repository层代码文件 + /// + /// + /// + /// 表名 + /// + /// 如果目标文件存在,是否覆盖。默认为false + private static void GenerateRepository(string modelTypeName, string modelTypeDesc, string tableName, string keyTypeName, bool ifExsitedCovered = false) + { + //var path = AppDomain.CurrentDomain.BaseDirectory; + var parentPath = "..";// path.Substring(0, path.LastIndexOf("\\")); + var repositoryPath = parentPath + "\\" + _option.BaseNamespace + "\\" + _option.RepositoriesNamespace; + if (!Directory.Exists(repositoryPath)) + { + //repositoryPath = parentPath + "\\" + _option.BaseNamespace + "\\Repositories"; + Directory.CreateDirectory(repositoryPath); + } + var fullPath = repositoryPath + "\\" + modelTypeName + "Repository.cs"; + if (File.Exists(fullPath) && !ifExsitedCovered) + return; + var content = ReadTemplate("RepositoryTemplate.txt"); + content = content.Replace("{ModelsNamespace}", _option.ModelsNamespace) + .Replace("{IRepositoriesNamespace}", _option.IRepositoriesNamespace) + .Replace("{RepositoriesNamespace}", _option.RepositoriesNamespace) + .Replace("{ModelTypeName}", modelTypeName) + .Replace("{TableNameDesc}", modelTypeDesc) + .Replace("{TableName}", tableName) + .Replace("{KeyTypeName}", keyTypeName); + WriteAndSave(fullPath, content); + } + + #endregion + + #region 生成Service + /// + /// 生成IService文件 + /// + /// + /// + /// + /// + /// 如果目标文件存在,是否覆盖。默认为false + private static void GenerateIService(string modelsNamespace, string modelTypeName, string modelTypeDesc, string keyTypeName, bool ifExsitedCovered = false) + { + //var path = AppDomain.CurrentDomain.BaseDirectory; + //path = path.Substring(0, path.IndexOf("\\bin")); + var parentPath = "..";// path.Substring(0, path.LastIndexOf("\\")); + var iServicesPath = parentPath + "\\" + _option.BaseNamespace + "\\" + _option.IServicsNamespace; + if (!Directory.Exists(iServicesPath)) + { + iServicesPath = parentPath + "\\" + _option.BaseNamespace + "\\IBusService"; + Directory.CreateDirectory(iServicesPath); + } + var fullPath = $"{iServicesPath}\\Business\\IService\\I{modelTypeName}Service.cs"; + if (File.Exists(fullPath) && !ifExsitedCovered) + return; + var content = ReadTemplate("IServiceTemplate.txt"); + content = content.Replace("{ModelsNamespace}", modelsNamespace) + .Replace("{DtosNamespace}", _option.DtosNamespace) + .Replace("{TableNameDesc}", modelTypeDesc) + .Replace("{IServicsNamespace}", _option.IServicsNamespace) + .Replace("{ModelTypeName}", modelTypeName) + .Replace("{KeyTypeName}", keyTypeName); + WriteAndSave(fullPath, content); + } + + /// + /// 生成Service文件 + /// + /// + /// + /// + /// + /// 如果目标文件存在,是否覆盖。默认为false + private static void GenerateService(string modelsNamespace, string modelTypeName, string modelTypeDesc, string keyTypeName, bool ifExsitedCovered = false) + { + //var path = AppDomain.CurrentDomain.BaseDirectory; + //path = path.Substring(0, path.IndexOf("\\bin")); + var parentPath = "..";// path.Substring(0, path.LastIndexOf("\\")); + var servicesPath = parentPath + "\\" + _option.BaseNamespace + "\\" + _option.ServicesNamespace; + if (!Directory.Exists(servicesPath)) + { + servicesPath = parentPath + "\\" + _option.BaseNamespace + "\\Business"; + Directory.CreateDirectory(servicesPath); + } + var fullPath = servicesPath + "\\Business\\" + modelTypeName + "Service.cs"; + Console.WriteLine(fullPath); + if (File.Exists(fullPath) && !ifExsitedCovered) + return; + var content = ReadTemplate("ServiceTemplate.txt"); + content = content + .Replace("{IRepositoriesNamespace}", _option.IRepositoriesNamespace) + .Replace("{DtosNamespace}", _option.DtosNamespace) + .Replace("{IServicsNamespace}", _option.IServicsNamespace) + .Replace("{TableNameDesc}", modelTypeDesc) + .Replace("{ModelsNamespace}", modelsNamespace) + .Replace("{ServicesNamespace}", _option.ServicesNamespace) + .Replace("{ModelTypeName}", modelTypeName) + .Replace("{KeyTypeName}", keyTypeName); + WriteAndSave(fullPath, content); + } + + #endregion + + #region 生成Controller + /// + /// 生成控制器ApiControllers文件 + /// + /// 实体类型名称 + /// 主键 + /// 实体描述 + /// + /// 如果目标文件存在,是否覆盖。默认为false + private static void GenerateControllers(string modelTypeName, string primaryKey, string modelTypeDesc, string keyTypeName, bool ifExsitedCovered = false) + { + //var servicesNamespace = _option.DtosNamespace; + //var fileClassName = _option.BaseNamespace.Substring(_option.BaseNamespace.IndexOf('.') + 1); + //var path = AppDomain.CurrentDomain.BaseDirectory; + //path = path.Substring(0, path.IndexOf("\\bin")); + var parentPath = "..";//path.Substring(0, path.LastIndexOf("\\")); + var servicesPath = parentPath + "\\" + _option.BaseNamespace + "\\" + _option.ApiControllerNamespace; + if (!Directory.Exists(servicesPath)) + { + servicesPath = parentPath + "\\" + _option.BaseNamespace + "\\Controllers\\"; + Directory.CreateDirectory(servicesPath); + } + var fullPath = servicesPath + "\\Controllers\\business\\" + modelTypeName + "Controller.cs"; + Console.WriteLine(fullPath); + if (File.Exists(fullPath) && !ifExsitedCovered) + return; + var content = ReadTemplate("ControllersTemplate.txt"); + content = content + //.Replace("{DtosNamespace}", _option.DtosNamespace) + .Replace("<#=ControllerName#>", modelTypeName) + //.Replace("{ModelsNamespace}", _option.ModelsNamespace) + .Replace("<#=FileName#>", modelTypeDesc) + .Replace("<#=ServiceName#>", modelTypeName + "Service") + .Replace("<#=ModelName#>", modelTypeName) + .Replace("{primaryKey}", primaryKey) + .Replace("{KeyTypeName}", keyTypeName); + WriteAndSave(fullPath, content); + } + #endregion + + #region 生成Vue页面 + /// + /// 生成Vue页面 + /// + /// 类名 + /// 表/类描述 + /// + /// + /// + /// + /// + /// + /// 如果目标文件存在,是否覆盖。默认为false + private static void GenerateVueViews(string modelTypeName, string primaryKey, string modelTypeDesc, string vueViewListContent, string vueViewFromContent, string vueViewEditFromContent, string vueViewEditFromBindContent, string vueViewSaveBindContent, string vueViewEditFromRuleContent, bool ifExsitedCovered = false) + { + var servicesNamespace = _option.DtosNamespace; + var fileClassName = _option.BaseNamespace.Substring(_option.BaseNamespace.IndexOf('.') + 1); + var path = AppDomain.CurrentDomain.BaseDirectory; + //path = path.Substring(0, path.IndexOf("\\bin")); + var parentPath = path.Substring(0, path.LastIndexOf("\\")); + var servicesPath = parentPath + "\\" + _option.BaseNamespace + "\\" + servicesNamespace; + if (!Directory.Exists(servicesPath)) + { + servicesPath = parentPath + "\\" + _option.BaseNamespace + "\\vue\\" + modelTypeName.ToLower(); + Directory.CreateDirectory(servicesPath); + } + var fullPath = servicesPath + "\\" + "index.vue"; + if (File.Exists(fullPath) && !ifExsitedCovered) + return; + var content = ReadTemplate("VueTemplate.txt"); + content = content + .Replace("{BaseNamespace}", fileClassName.ToLower()) + .Replace("{fileClassName}", modelTypeName.ToLower()) + .Replace("{ModelTypeNameToLower}", modelTypeName.ToLower()) + .Replace("{VueViewListContent}", vueViewListContent) + .Replace("{VueViewFromContent}", vueViewFromContent) + .Replace("{ModelTypeName}", modelTypeName) + .Replace("{VueViewEditFromContent}", vueViewEditFromContent) + .Replace("{VueViewEditFromBindContent}", vueViewEditFromBindContent) + .Replace("{VueViewSaveBindContent}", vueViewSaveBindContent) + .Replace("{primaryKey}", primaryKey) + .Replace("{VueViewEditFromRuleContent}", vueViewEditFromRuleContent); + WriteAndSave(fullPath, content); + + fullPath = servicesPath + "\\" + modelTypeName.ToLower() + ".js"; + if (File.Exists(fullPath) && !ifExsitedCovered) + return; + content = ReadTemplate("VueJsTemplate.txt"); + content = content + .Replace("{ModelTypeName}", modelTypeName) + .Replace("{ModelTypeDesc}", modelTypeDesc) + .Replace("{fileClassName}", fileClassName); + WriteAndSave(fullPath, content); + } + + #endregion + #region 帮助方法 private static string GetModelName(string modelTypeName) @@ -273,7 +480,19 @@ namespace ZR.CodeGenerator modelTypeName = modelTypeName.Substring(0, 1).ToUpper() + modelTypeName.Substring(1); return modelTypeName; } - + private static string FirstLowerCase(string str) + { + if (string.IsNullOrEmpty(str)) + { + return str; + } + str = str.Substring(0, 1).ToLower() + str.Substring(1); + return str; + } + private static string GetLabelName(string columnDescription, string columnName) + { + return string.IsNullOrEmpty(columnDescription) ? columnName : columnDescription; + } /// /// 从代码模板中读取内容 /// @@ -309,17 +528,24 @@ namespace ZR.CodeGenerator /// private static void WriteAndSave(string fileName, string content) { - //实例化一个文件流--->与写入文件相关联 - using var fs = new FileStream(fileName, FileMode.Create, FileAccess.Write); - //实例化一个StreamWriter-->与fs相关联 - using var sw = new StreamWriter(fs); - //开始写入 - sw.Write(content); - //清空缓冲区 - sw.Flush(); - //关闭流 - sw.Close(); - fs.Close(); + try + { + //实例化一个文件流--->与写入文件相关联 + using var fs = new FileStream(fileName, FileMode.Create, FileAccess.Write); + //实例化一个StreamWriter-->与fs相关联 + using var sw = new StreamWriter(fs); + //开始写入 + sw.Write(content); + //清空缓冲区 + sw.Flush(); + //关闭流 + sw.Close(); + fs.Close(); + } + catch (Exception ex) + { + Console.WriteLine("写入文件出错了:" + ex.Message); + } } #endregion diff --git a/ZR.CodeGenerator/DbProvider.cs b/ZR.CodeGenerator/DbProvider.cs index ed3757e..56525f3 100644 --- a/ZR.CodeGenerator/DbProvider.cs +++ b/ZR.CodeGenerator/DbProvider.cs @@ -10,13 +10,23 @@ namespace ZR.CodeGenerator { public class DbProvider { + protected static SqlSugarScope CodeDb; - public SqlSugarClient GetSugarDbContext(string dbName) + /// + /// 获取动态连接字符串 + /// + /// 数据库名 + /// + public SqlSugarScope GetSugarDbContext(string dbName = "") { - string connStr = ConfigUtils.Instance.GetConnectionStrings(OptionsSetting.Conn).Replace("{DbName}", dbName); + string connStr = ConfigUtils.Instance.GetConnectionStrings(OptionsSetting.Conn).Replace("{database}", dbName); int dbType = ConfigUtils.Instance.GetAppConfig(OptionsSetting.CodeGenDbType, 0); - - return new SqlSugarClient(new List() + if (string.IsNullOrEmpty(dbName)) + { + connStr = ConfigUtils.Instance.GetConnectionStrings(OptionsSetting.ConnAdmin); + dbType = ConfigUtils.Instance.GetAppConfig(OptionsSetting.DbType, 0); + } + var db = new SqlSugarScope(new List() { new ConnectionConfig(){ ConnectionString = connStr, @@ -25,6 +35,9 @@ namespace ZR.CodeGenerator InitKeyType = InitKeyType.Attribute,//从特性读取主键和自增列信息 }, }); + + CodeDb = db; + return db; } } } diff --git a/ZR.CodeGenerator/Service/CodeGeneraterService.cs b/ZR.CodeGenerator/Service/CodeGeneraterService.cs index a66aa0c..f24f4e1 100644 --- a/ZR.CodeGenerator/Service/CodeGeneraterService.cs +++ b/ZR.CodeGenerator/Service/CodeGeneraterService.cs @@ -1,16 +1,12 @@ -using Infrastructure; -using SqlSugar; -using System; +using SqlSugar; using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; using ZR.Model; using ZR.Model.CodeGenerator; namespace ZR.CodeGenerator.Service { - public class CodeGeneraterService: DbProvider + public class CodeGeneraterService : DbProvider { /// /// 获取所有数据库名 @@ -18,21 +14,15 @@ namespace ZR.CodeGenerator.Service /// public List GetAllDataBases() { - var dbType = ConfigUtils.Instance.GetConfig("CodeGenDbType"); - List list = new List(); - if (dbType == "1") + List list = new(); + + var db = GetSugarDbContext(); + var templist = db.DbMaintenance.GetDataBaseList(db.ScopedContext); + templist.ForEach(item => { - var db = GetSugarDbContext("ZrAdmin"); - var templist = db.DbMaintenance.GetDataBaseList(db); - templist.ForEach(item => - { - list.Add(new DataBaseInfo() { DbName = item }); - }); - } - else if (dbType == "0") - { - // list = mssqlExtractor.GetAllDataBases(); - } + list.Add(new DataBaseInfo() { DbName = item }); + }); + return list; } @@ -43,7 +33,7 @@ namespace ZR.CodeGenerator.Service /// /// /// - public List GetAllTables(string dbName, string tableName, PagerInfo pager) + public List GetAllTables(string dbName, string tableName, PagerInfo pager) { var tableList = GetSugarDbContext(dbName).DbMaintenance.GetTableInfoList(true); if (!string.IsNullOrEmpty(tableName)) @@ -62,7 +52,7 @@ namespace ZR.CodeGenerator.Service /// public List GetColumnInfo(string dbName, string tableName) { - return GetSugarDbContext(dbName).DbMaintenance.GetColumnInfosByTableName(tableName, true); + return GetSugarDbContext(dbName).DbMaintenance.GetColumnInfosByTableName(tableName, true); } } diff --git a/ZR.Repository/System/CodeGeneratorRepository.cs b/ZR.Repository/System/CodeGeneratorRepository.cs deleted file mode 100644 index 7c1888e..0000000 --- a/ZR.Repository/System/CodeGeneratorRepository.cs +++ /dev/null @@ -1,75 +0,0 @@ -using Infrastructure.Attribute; -using SqlSugar; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using ZR.Model; -using ZR.Model.CodeGenerator; - -namespace ZR.Repository.System -{ - [AppService(ServiceLifetime = LifeTime.Transient)] - public class CodeGeneratorRepository : BaseRepository - { - ///// - ///// 获取数据库 - ///// - ///// - //public List GetAllDb() - //{ - // //return Db.Ado.SqlQuery("select name as DbName from master..sysdatabases "); - // var list = Db.DbMaintenance.GetDataBaseList(Db); - // List dataBases = new List(); - // list.ForEach(item => - // { - // dataBases.Add(new DataBaseInfo() { DbName = item }); - // }); - // return dataBases; - //} - - ///// - ///// 根据数据库名获取所有的表 - ///// - ///// - ///// - ///// - ///// - //public List GetAllTables(string dbName, string tableName, PagerInfo pager) - //{ - // var tableList = GetSugarDbContext(dbName).DbMaintenance.GetTableInfoList(true); - // if (!string.IsNullOrEmpty(tableName)) - // { - // tableList = tableList.Where(f => f.Name.Contains(tableName)).ToList(); - // } - // pager.TotalNum = tableList.Count; - // return tableList.Skip(pager.PageSize * (pager.PageNum - 1)).Take(pager.PageSize).OrderBy(f => f.Name).ToList(); - //} - - ///// - ///// 获取表格列信息 - ///// - ///// - ///// - ///// - //public List GetColumnInfo(string dbName, string tableName) - //{ - // return GetSugarDbContext(dbName).DbMaintenance.GetColumnInfosByTableName(tableName, true); - //} - - - /// - /// 获取当前数据库表名 - /// - /// - /// - //public List GetAllTables(string[] tabList) - //{ - // string sql = @"SELECT tbs.name as TableName ,ds.value as Description FROM sys.tables tbs - // left join sys.extended_properties ds on ds.major_id=tbs.object_id and ds.minor_id=0"; - - // return Db.SqlQueryable(sql).WhereIF(tabList.Length > 0, x => tabList.Contains(x.TableName)).ToList(); - //} - } -} diff --git a/ZR.Service/System/CodeGeneratorService.cs b/ZR.Service/System/CodeGeneratorService.cs deleted file mode 100644 index 7c8446e..0000000 --- a/ZR.Service/System/CodeGeneratorService.cs +++ /dev/null @@ -1,99 +0,0 @@ -using Infrastructure; -using Infrastructure.Attribute; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using ZR.Model; -using ZR.Model.CodeGenerator; -using ZR.Repository.System; -using ZR.Service.IService; - -namespace ZR.Service.System -{ - /// - /// - /// - //[AppService(ServiceType = typeof(ICodeGeneratorService), ServiceLifetime = LifeTime.Transient)] - public class CodeGeneratorService //: ICodeGeneratorService - { - //public CodeGeneratorRepository CodeGeneratorRepository; - - //public CodeGeneratorService(CodeGeneratorRepository codeGeneratorRepository) - //{ - // CodeGeneratorRepository = codeGeneratorRepository; - //} - - ///// - ///// 获取表所有列 - ///// - ///// - ///// - //public List GetAllColumns(string tableName) - //{ - // var dbType = ConfigUtils.Instance.GetConfig("CodeGenDbType"); - // if (tableName == null) - // throw new ArgumentException(nameof(tableName)); - // List list = new List(); - // if (dbType == "1") - // { - // list = CodeGeneratorRepository.GetAllColumns(tableName); - // } - // return list; - //} - - ///// - ///// 获取所有数据库名 - ///// - ///// - //public List GetAllDataBases() - //{ - // var dbType = ConfigUtils.Instance.GetConfig("CodeGenDbType"); - // List list = new List(); - // if (dbType == "1") - // { - // list = CodeGeneratorRepository.GetAllDb(); - // } - // else if (dbType == "0") - // { - // // list = mssqlExtractor.GetAllDataBases(); - // } - // return list; - //} - - //public List GetAllTables(string tableStrs) - //{ - // string[] tabList = tableStrs.Split(","); - - // return CodeGeneratorRepository.GetAllTables(tabList); - //} - - /// - /// 获取列信息 - /// - /// - /// - /// - //public List GetColumnInfo(string dbName, string tableName) - //{ - // return CodeGeneratorRepository.GetColumnInfo(dbName, tableName); - //} - - //public List GetTablesWithPage(string tablename, string dbName, PagerInfo pager) - //{ - // var dbType = ConfigUtils.Instance.GetConfig("CodeGenDbType"); - // List list = new List(); - // if (dbType == "1") - // { - // list = CodeGeneratorRepository.GetAllTables(dbName, tablename, pager); - // } - // else if (dbType == "0") - // { - // //list = mysqlExtractor.GetAllTables(this.dbName, tablename, fieldNameToSort, isDescending, info); - // } - // return list; - //} - - } -} diff --git a/ZR.Service/ZR.Service.csproj b/ZR.Service/ZR.Service.csproj index 6f3c4d0..7d41173 100644 --- a/ZR.Service/ZR.Service.csproj +++ b/ZR.Service/ZR.Service.csproj @@ -9,4 +9,8 @@ + + + + diff --git a/ZR.Vue/src/views/tool/index.vue b/ZR.Vue/src/views/tool/index.vue index b291e7c..dcdeef6 100644 --- a/ZR.Vue/src/views/tool/index.vue +++ b/ZR.Vue/src/views/tool/index.vue @@ -32,30 +32,26 @@
- - - - - - + + + + - - 查询 - - + + 查询 刷新 @@ -105,7 +101,7 @@ export default { DbType: "", }, searchform: { - DbName: "", + dbName: "", tableName: "", }, codeform: { @@ -122,6 +118,9 @@ export default { // trigger: "blur", // }, // ], + dbName: [ + { required: true, message: "请选择数据库名称", trigger: "blur" }, + ], replaceTableNameStr: [ { min: 0, max: 50, message: "长度小于50个字符", trigger: "blur" }, ], @@ -166,15 +165,13 @@ export default { * 加载页面table数据 */ loadTableData: function () { - if (this.searchform.dataBaseName !== "") { + if (this.codeform.dataBaseName !== "") { this.tableloading = true; var seachdata = { pageNum: this.pagination.pageNum, PageSize: this.pagination.pagesize, - tableName: this.searchform.tableName, - dbName: this.searchform.DbName, - // Order: this.sortableData.order, - // Sort: this.sortableData.sort, + tableName: this.codeform.tableName, + dbName: this.codeform.dbName, }; codeGetTableList(seachdata).then((res) => { this.tableData = res.data.result; @@ -187,9 +184,15 @@ export default { * 点击查询 */ handleSearch: function () { - this.tableloading = true; - this.pagination.pageNum = 1; - this.loadTableData(); + this.$refs["codeform"].validate((valid) => { + if (valid) { + this.tableloading = true; + this.pagination.pageNum = 1; + this.loadTableData(); + }else{ + return false; + } + }); }, handleShowTable: function () { this.pagination.pageNum = 1; @@ -231,7 +234,7 @@ export default { const pageLoading = Loading.service(loadop); var seachdata = { - dbName: this.searchform.DbName, + dbName: this.codeform.dbName, tables: row.name, // this.currentSelected.toString(), baseSpace: this.codeform.baseSpace, replaceTableNameStr: this.codeform.replaceTableNameStr, From a06f41a5878e2973eae92a85b96d584db98da0cc Mon Sep 17 00:00:00 2001 From: izory <791736813@qq.com> Date: Wed, 8 Sep 2021 18:13:46 +0800 Subject: [PATCH 08/28] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=A4=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ZR.Service/ZR.Service.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ZR.Service/ZR.Service.csproj b/ZR.Service/ZR.Service.csproj index 7d41173..c5a4822 100644 --- a/ZR.Service/ZR.Service.csproj +++ b/ZR.Service/ZR.Service.csproj @@ -10,7 +10,7 @@ - + From d581934a39b4dbf9e57dc4ab50cb4dfa03779f86 Mon Sep 17 00:00:00 2001 From: izory <791736813@qq.com> Date: Wed, 8 Sep 2021 22:02:05 +0800 Subject: [PATCH 09/28] =?UTF-8?q?=E5=BC=80=E5=8F=91=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E7=94=9F=E6=88=90=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ZR.Admin.WebApi/Template/VueTemplate.txt | 12 +- ZR.CodeGenerator/CodeGeneratorTool.cs | 144 ++++++++++------- ZR.Vue/src/views/demo.vue | 198 +++++++++++++---------- 3 files changed, 200 insertions(+), 154 deletions(-) diff --git a/ZR.Admin.WebApi/Template/VueTemplate.txt b/ZR.Admin.WebApi/Template/VueTemplate.txt index e109a38..7a2717e 100644 --- a/ZR.Admin.WebApi/Template/VueTemplate.txt +++ b/ZR.Admin.WebApi/Template/VueTemplate.txt @@ -83,7 +83,7 @@
+ diff --git a/ZR.Vue/src/api/tool/gen.js b/ZR.Vue/src/api/tool/gen.js index 88e4a3d..348f6c3 100644 --- a/ZR.Vue/src/api/tool/gen.js +++ b/ZR.Vue/src/api/tool/gen.js @@ -70,7 +70,7 @@ export function genCode(tableName) { // 同步数据库 export function synchDb(tableName) { return request({ - url: '/tool/gen/synchDb/' + tableName, + url: 'tool/gen/synchDb/' + tableName, method: 'get' }) } @@ -80,9 +80,9 @@ export function synchDb(tableName) { /** * 创建数据库连接 */ - export function createGetDBConn(data) { +export function createGetDBConn(data) { return request({ - url: 'CodeGenerator/CreateDBConn', + url: 'tool/gen/CreateDBConn', method: 'post', data: data, }) @@ -92,7 +92,7 @@ export function synchDb(tableName) { */ export function codeGetDBList() { return request({ - url: 'CodeGenerator/GetListDataBase', + url: 'tool/gen/getDbList', method: 'get', }) } @@ -101,7 +101,7 @@ export function codeGetDBList() { */ export function codeGetTableList(data) { return request({ - url: 'CodeGenerator/FindListTable', + url: 'tool/gen/FindListTable', method: 'get', params: data, }) @@ -111,12 +111,26 @@ export function codeGetTableList(data) { */ export async function codeGenerator(data) { return await request({ - url: 'CodeGenerator/Generate', - method: 'get', - params: data, + url: '/tool/gen/Generate', + method: 'post', + data: data, timeout: 0, }) } + +/** + * 获取表格列信息 + * @param {*} data + * @returns + */ +export function queryColumnInfo(data) { + return request({ + url: 'tool/gen/queryColumnInfo', + method: 'GET', + params: data, + }) +} + /** * * 数据库解密 diff --git a/ZR.Vue/src/views/demo.vue b/ZR.Vue/src/views/demo.vue index 4d03edb..51f7a1e 100644 --- a/ZR.Vue/src/views/demo.vue +++ b/ZR.Vue/src/views/demo.vue @@ -36,13 +36,13 @@ - 新增 + 新增 - 修改 + 修改 - 删除 + 删除 - - - - - - - - - - - - - - + + + + + + + + + + + + + @@ -84,57 +87,35 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + {{dict.dictLabel}} + + + + + + + + + diff --git a/ZRAdmin.xml b/ZRAdmin.xml index 521037d..fe02fe5 100644 --- a/ZRAdmin.xml +++ b/ZRAdmin.xml @@ -47,14 +47,19 @@ 分页信息 - + + + 获取表格列 + + + + + + 代码生成器 - - 要生成代码的表 - 项目命名空间 - 要删除表名的字符串用英文逗号","隔开 + 数据传输对象 From 2172b9ddc6a67017b6e08bdc1ddd5017562cd0e5 Mon Sep 17 00:00:00 2001 From: izory <791736813@qq.com> Date: Thu, 9 Sep 2021 18:42:51 +0800 Subject: [PATCH 11/28] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ZR.CodeGenerator/ZR.CodeGenerator.csproj | 4 ---- 1 file changed, 4 deletions(-) diff --git a/ZR.CodeGenerator/ZR.CodeGenerator.csproj b/ZR.CodeGenerator/ZR.CodeGenerator.csproj index d93648b..cbcf969 100644 --- a/ZR.CodeGenerator/ZR.CodeGenerator.csproj +++ b/ZR.CodeGenerator/ZR.CodeGenerator.csproj @@ -10,10 +10,6 @@ - - - - From 8903aff64231b1f11775cfcd3975649896ce7966 Mon Sep 17 00:00:00 2001 From: izory <791736813@qq.com> Date: Fri, 10 Sep 2021 10:44:17 +0800 Subject: [PATCH 12/28] =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E7=94=9F=E6=88=90=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/CodeGeneratorController.cs | 33 ++-- .../Filters/ActionPermissionFilter.cs | 2 +- ZR.CodeGenerator/CodeGeneratorTool.cs | 16 +- ZR.CodeGenerator/Model/GenerateDto.cs | 4 +- ZR.Vue/public/index.html | 46 +++--- ZR.Vue/src/api/{ => system}/login.js | 0 ZR.Vue/src/api/tool/gen.js | 144 +++++------------- ZR.Vue/src/store/modules/user.js | 2 +- ZR.Vue/src/views/index.vue | 4 +- ZR.Vue/src/views/login.vue | 2 +- ZR.Vue/src/views/tool/index.vue | 38 ++--- 11 files changed, 105 insertions(+), 186 deletions(-) rename ZR.Vue/src/api/{ => system}/login.js (100%) diff --git a/ZR.Admin.WebApi/Controllers/CodeGeneratorController.cs b/ZR.Admin.WebApi/Controllers/CodeGeneratorController.cs index 49cb10b..7cffe87 100644 --- a/ZR.Admin.WebApi/Controllers/CodeGeneratorController.cs +++ b/ZR.Admin.WebApi/Controllers/CodeGeneratorController.cs @@ -1,20 +1,15 @@ using Infrastructure; using Infrastructure.Attribute; using Infrastructure.Enums; -using Infrastructure.Model; using Microsoft.AspNetCore.Mvc; using SqlSugar; -using System; using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +using ZR.Admin.WebApi.Filters; using ZR.CodeGenerator; using ZR.CodeGenerator.Model; using ZR.CodeGenerator.Service; using ZR.Model; using ZR.Model.Vo; -using ZR.Service.IService; -using ZR.Service.System; namespace ZR.Admin.WebApi.Controllers { @@ -24,11 +19,6 @@ namespace ZR.Admin.WebApi.Controllers [Route("tool/gen")] public class CodeGeneratorController : BaseController { - //public ICodeGeneratorService CodeGeneratorService; - //public CodeGeneratorController(ICodeGeneratorService codeGeneratorService) - //{ - // CodeGeneratorService = codeGeneratorService; - //} private CodeGeneraterService _CodeGeneraterService = new CodeGeneraterService(); /// @@ -36,7 +26,7 @@ namespace ZR.Admin.WebApi.Controllers /// /// [HttpGet("getDbList")] - //[YuebonAuthorize("GetListDataBase")] + [ActionPermissionFilter(Permission = "tool:gen:list")] public IActionResult GetListDataBase() { var dbList = _CodeGeneraterService.GetAllDataBases(); @@ -51,7 +41,8 @@ namespace ZR.Admin.WebApi.Controllers /// 表名 /// 分页信息 /// - [HttpGet("FindListTable")] + [HttpGet("getTableList")] + [ActionPermissionFilter(Permission = "tool:gen:list")] public IActionResult FindListTable(string dbName, string tableName, PagerInfo pager) { List list = _CodeGeneraterService.GetAllTables(dbName, tableName, pager); @@ -66,7 +57,8 @@ namespace ZR.Admin.WebApi.Controllers /// /// /// - [HttpGet("QueryColumnInfo")] + [HttpGet("getColumnInfo")] + [ActionPermissionFilter(Permission = "tool:gen:list")] public IActionResult QueryColumnInfo(string dbName, string tableName) { if (string.IsNullOrEmpty(dbName) || string.IsNullOrEmpty(tableName)) @@ -80,18 +72,19 @@ namespace ZR.Admin.WebApi.Controllers ///
/// 数据传输对象 /// - [HttpGet("Generate")] - [Log(Title = "代码生成", BusinessType = BusinessType.OTHER)] - public IActionResult Generate([FromQuery] GenerateDto dto) + [HttpPost("genCode")] + [Log(Title = "代码生成", BusinessType = BusinessType.GENCODE)] + [ActionPermissionFilter(Permission = "tool:gen:code")] + public IActionResult Generate([FromBody] GenerateDto dto) { - if (string.IsNullOrEmpty(dto.tables)) + if (string.IsNullOrEmpty(dto.tableName)) { throw new CustomException(ResultCode.CUSTOM_ERROR, "请求参数为空"); } - DbTableInfo dbTableInfo = new() { Name = dto.tables }; + DbTableInfo dbTableInfo = new() { Name = dto.tableName }; CodeGeneratorTool.Generate(dbTableInfo, dto); - return SUCCESS(1); + return SUCCESS(dbTableInfo); } } } diff --git a/ZR.Admin.WebApi/Filters/ActionPermissionFilter.cs b/ZR.Admin.WebApi/Filters/ActionPermissionFilter.cs index 88258d7..08cad61 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" }; + string[] denyPerms = new string[] { "update", "add", "remove", "add", "edit", "delete", "import", "run", "start", "stop", "clear", "gen" }; 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.CodeGenerator/CodeGeneratorTool.cs b/ZR.CodeGenerator/CodeGeneratorTool.cs index 9c51eb8..8269080 100644 --- a/ZR.CodeGenerator/CodeGeneratorTool.cs +++ b/ZR.CodeGenerator/CodeGeneratorTool.cs @@ -64,7 +64,7 @@ namespace ZR.CodeGenerator public static void GenerateSingle(List listField, DbTableInfo tableInfo, GenerateDto dto) { bool ifExsitedCovered = dto.coverd; - var modelTypeName = GetModelName(tableInfo.Name).Replace(_option.ReplaceTableNameStr, "");//表名 + var modelTypeName = GetModelName(tableInfo.Name); var modelTypeDesc = tableInfo.Description;//表描述 var primaryKey = "id";//主键 @@ -107,7 +107,7 @@ namespace ZR.CodeGenerator } if (dto.genFiles.Contains(1)) { - GenerateModels(_option.ModelsNamespace, modelTypeName, tableInfo.Name, modelContent, modelTypeDesc, keyTypeName, ifExsitedCovered); + //GenerateModels(_option.ModelsNamespace, modelTypeName, tableInfo.Name, modelContent, modelTypeDesc, keyTypeName, ifExsitedCovered); } if (dto.genFiles.Contains(2)) { @@ -478,16 +478,14 @@ namespace ZR.CodeGenerator /// 如果目标文件存在,是否覆盖。默认为false private static void GenerateVueViews(string modelTypeName, string primaryKey, string modelTypeDesc, string vueViewListContent, string vueViewFromContent, string vueViewEditFromContent, string vueViewEditFromBindContent, string vueViewSaveBindContent, string vueViewEditFromRuleContent, bool ifExsitedCovered = false) { - var servicesNamespace = _option.DtosNamespace; - var path = "..\\CodeGenerate\\"; - var parentPath = path.Substring(0, path.LastIndexOf("\\")); - var servicesPath = parentPath + "\\" + _option.BaseNamespace + "\\" + servicesNamespace; + var parentPath = "..\\CodeGenerate";//若要生成到项目中将路径改成 “..\\ZR.Vue\\src” + var servicesPath = parentPath + "\\views\\" + FirstLowerCase(modelTypeName); if (!Directory.Exists(servicesPath)) { - servicesPath = parentPath + "\\" + _option.BaseNamespace + "\\views\\" + FirstLowerCase(modelTypeName); Directory.CreateDirectory(servicesPath); } var fullPath = servicesPath + "\\" + "index.vue"; + Console.WriteLine(fullPath); if (File.Exists(fullPath) && !ifExsitedCovered) return; var content = ReadTemplate("VueTemplate.txt"); @@ -505,7 +503,11 @@ namespace ZR.CodeGenerator .Replace("{VueViewEditFromRuleContent}", vueViewEditFromRuleContent); WriteAndSave(fullPath, content); + //api js + servicesPath = parentPath + "\\api\\"; + Directory.CreateDirectory(servicesPath); fullPath = servicesPath + "\\" + FirstLowerCase(modelTypeName) + ".js"; + Console.WriteLine(fullPath); if (File.Exists(fullPath) && !ifExsitedCovered) return; content = ReadTemplate("VueJsTemplate.txt"); diff --git a/ZR.CodeGenerator/Model/GenerateDto.cs b/ZR.CodeGenerator/Model/GenerateDto.cs index be9e00f..60399fc 100644 --- a/ZR.CodeGenerator/Model/GenerateDto.cs +++ b/ZR.CodeGenerator/Model/GenerateDto.cs @@ -8,7 +8,7 @@ namespace ZR.CodeGenerator.Model { public class GenerateDto { - public string queryColumn { get; set; } + public string[] queryColumn { get; set; } /// /// /// @@ -20,7 +20,7 @@ namespace ZR.CodeGenerator.Model /// /// 要生成代码的表 /// - public string tables { get; set; } + public string tableName { get; set; } /// /// 要删除表名的字符串用 /// diff --git a/ZR.Vue/public/index.html b/ZR.Vue/public/index.html index 6d64bf9..c896b69 100644 --- a/ZR.Vue/public/index.html +++ b/ZR.Vue/public/index.html @@ -1,13 +1,16 @@ - - - - - - - <%= webpackConfig.name %> - - - -
-
-
-
-
-
正在加载系统资源,请耐心等待
-
-
- + + + +
+
+
+
+
+
Loading...
+
+
+ + diff --git a/ZR.Vue/src/api/login.js b/ZR.Vue/src/api/system/login.js similarity index 100% rename from ZR.Vue/src/api/login.js rename to ZR.Vue/src/api/system/login.js diff --git a/ZR.Vue/src/api/tool/gen.js b/ZR.Vue/src/api/tool/gen.js index 348f6c3..93d7a27 100644 --- a/ZR.Vue/src/api/tool/gen.js +++ b/ZR.Vue/src/api/tool/gen.js @@ -1,92 +1,23 @@ import request from '@/utils/request' -// 查询生成表数据 -export function listTable(query) { - return request({ - url: '/tool/gen/list', - method: 'get', - params: query - }) -} -// 查询db数据库列表 -export function listDbTable(query) { - return request({ - url: '/tool/gen/db/list', - method: 'get', - params: query - }) -} - -// 查询表详细信息 -export function getGenTable(tableId) { - return request({ - url: '/tool/gen/' + tableId, - method: 'get' - }) -} - -// 修改代码生成信息 -export function updateGenTable(data) { - return request({ - url: '/tool/gen', - method: 'put', - data: data - }) -} - -// 导入表 -export function importTable(data) { - return request({ - url: '/tool/gen/importTable', - method: 'post', - params: data - }) -} - // 预览生成代码 -export function previewTable(tableId) { - return request({ - url: '/tool/gen/preview/' + tableId, - method: 'get' - }) -} - -// 删除表数据 -export function delTable(tableId) { - return request({ - url: '/tool/gen/' + tableId, - method: 'delete' - }) -} - -// 生成代码(自定义路径) -export function genCode(tableName) { - return request({ - url: '/tool/gen/genCode/' + tableName, - method: 'get' - }) -} - -// 同步数据库 -export function synchDb(tableName) { - return request({ - url: 'tool/gen/synchDb/' + tableName, - method: 'get' - }) -} - -/**新的代码生成 */ +// export function previewTable(tableId) { +// return request({ +// url: '/tool/gen/preview/' + tableId, +// method: 'get' +// }) +// } /** * 创建数据库连接 */ -export function createGetDBConn(data) { - return request({ - url: 'tool/gen/CreateDBConn', - method: 'post', - data: data, - }) -} +// export function createGetDBConn(data) { +// return request({ +// url: 'tool/gen/CreateDBConn', +// method: 'post', +// data: data, +// }) +// } /** * 获取数据库 */ @@ -101,7 +32,7 @@ export function codeGetDBList() { */ export function codeGetTableList(data) { return request({ - url: 'tool/gen/FindListTable', + url: 'tool/gen/getTableList', method: 'get', params: data, }) @@ -111,10 +42,9 @@ export function codeGetTableList(data) { */ export async function codeGenerator(data) { return await request({ - url: '/tool/gen/Generate', + url: 'tool/gen/genCode', method: 'post', data: data, - timeout: 0, }) } @@ -125,30 +55,30 @@ export async function codeGenerator(data) { */ export function queryColumnInfo(data) { return request({ - url: 'tool/gen/queryColumnInfo', + url: 'tool/gen/getColumnInfo', method: 'GET', params: data, }) } -/** - * -* 数据库解密 -*/ -export function dbtoolsConnStrDecrypt(data) { - return request({ - url: 'DbTools/ConnStrDecrypt', - method: 'post', - params: data, - }) -} -/** - * 数据库加密 - */ -export function dbtoolsConnStrEncrypt(data) { - return request({ - url: 'DbTools/ConnStrEncrypt', - method: 'post', - params: data, - }) -} +// /** +// * +// * 数据库解密 +// */ +// export function dbtoolsConnStrDecrypt(data) { +// return request({ +// url: 'DbTools/ConnStrDecrypt', +// method: 'post', +// params: data, +// }) +// } +// /** +// * 数据库加密 +// */ +// export function dbtoolsConnStrEncrypt(data) { +// return request({ +// url: 'DbTools/ConnStrEncrypt', +// method: 'post', +// params: data, +// }) +// } diff --git a/ZR.Vue/src/store/modules/user.js b/ZR.Vue/src/store/modules/user.js index cc944ee..7a95dbd 100644 --- a/ZR.Vue/src/store/modules/user.js +++ b/ZR.Vue/src/store/modules/user.js @@ -1,4 +1,4 @@ -import { login, logOut, getInfo } from '@/api/login' +import { login, logOut, getInfo } from '@/api/system/login' import { getToken, setToken, removeToken } from '@/utils/auth' const user = { diff --git a/ZR.Vue/src/views/index.vue b/ZR.Vue/src/views/index.vue index c1be6dd..41a28d7 100644 --- a/ZR.Vue/src/views/index.vue +++ b/ZR.Vue/src/views/index.vue @@ -23,7 +23,7 @@
技术选型
- +

后端技术

  • NET5
  • @@ -35,7 +35,7 @@
  • ...
- +

前端技术