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 a2e45f6..0000000 Binary files a/ZR.Vue/src/views/dashboard/bigdata/head_bg.png and /dev/null differ 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 @@ 获取所有表根据数据名 - 数据库名 - 表名 + 数据库名 + 表名 分页信息 - + - 生成代码 + 代码生成器 + + 要生成代码的表 + 项目命名空间 + 要删除表名的字符串用英文逗号","隔开