开发优化代码生成功能
This commit is contained in:
parent
48acf4b9f7
commit
30e1098a45
@ -1,15 +1,21 @@
|
||||
using Infrastructure;
|
||||
using Infrastructure.Attribute;
|
||||
using Infrastructure.Enums;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.CodeGenerator;
|
||||
using ZR.CodeGenerator.CodeGenerator;
|
||||
using ZR.CodeGenerator.Model;
|
||||
using ZR.CodeGenerator.Service;
|
||||
using ZR.Common;
|
||||
using ZR.Model;
|
||||
using ZR.Model.System.Generate;
|
||||
using ZR.Model.Vo;
|
||||
using ZR.Service.System.IService;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers
|
||||
{
|
||||
@ -20,6 +26,13 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
public class CodeGeneratorController : BaseController
|
||||
{
|
||||
private CodeGeneraterService _CodeGeneraterService = new CodeGeneraterService();
|
||||
private IGenTableService GenTableService;
|
||||
private IGenTableColumnService GenTableColumnService;
|
||||
public CodeGeneratorController(IGenTableService genTableService, IGenTableColumnService genTableColumnService)
|
||||
{
|
||||
GenTableService = genTableService;
|
||||
GenTableColumnService = genTableColumnService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有数据库的信息
|
||||
@ -57,15 +70,15 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
/// <param name="dbName"></param>
|
||||
/// <param name="tableName"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("getColumnInfo")]
|
||||
[ActionPermissionFilter(Permission = "tool:gen:list")]
|
||||
public IActionResult QueryColumnInfo(string dbName, string tableName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(dbName) || string.IsNullOrEmpty(tableName))
|
||||
return ToRespose(ResultCode.PARAM_ERROR);
|
||||
//[HttpGet("getColumnInfo")]
|
||||
//[ActionPermissionFilter(Permission = "tool:gen:list")]
|
||||
//public IActionResult QueryColumnInfo(string dbName, string tableName)
|
||||
//{
|
||||
// if (string.IsNullOrEmpty(dbName) || string.IsNullOrEmpty(tableName))
|
||||
// return ToRespose(ResultCode.PARAM_ERROR);
|
||||
|
||||
return SUCCESS(_CodeGeneraterService.GetColumnInfo(dbName, tableName));
|
||||
}
|
||||
// return SUCCESS(_CodeGeneraterService.GetColumnInfo(dbName, tableName));
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// 代码生成器
|
||||
@ -86,5 +99,125 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
|
||||
return SUCCESS(dbTableInfo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取表详细信息
|
||||
/// </summary>
|
||||
/// <param name="tableName"></param>
|
||||
/// <param name="pagerInfo">分页信息</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("getGenTable")]
|
||||
public IActionResult GetGenTable(string tableName, PagerInfo pagerInfo)
|
||||
{
|
||||
//if (string.IsNullOrEmpty(tableName))
|
||||
//{
|
||||
// throw new CustomException(ResultCode.CUSTOM_ERROR, "请求参数为空");
|
||||
//}
|
||||
//查询原表数据,部分字段映射到代码生成表字段
|
||||
var rows = GenTableService.GetGenTables(new GenTable() { TableName = tableName }, pagerInfo);
|
||||
|
||||
return SUCCESS(rows);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询表字段列表
|
||||
/// </summary>
|
||||
/// <param name="tableId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("column/{tableId}")]
|
||||
public IActionResult GetColumnList(long tableId)
|
||||
{
|
||||
var tableColumns = GenTableColumnService.GenTableColumns(tableId);
|
||||
var tableInfo = GenTableService.GetGenTableInfo(tableId);
|
||||
return SUCCESS(new { result = tableColumns, info = tableInfo });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 代码生成删除
|
||||
/// </summary>
|
||||
/// <param name="tableIds"></param>
|
||||
/// <returns></returns>
|
||||
[Log(Title = "代码生成", BusinessType = BusinessType.DELETE)]
|
||||
[HttpDelete("{tableIds}")]
|
||||
[ActionPermissionFilter(Permission = "tool:gen:remove")]
|
||||
public IActionResult Remove(string tableIds)
|
||||
{
|
||||
long[] tableId = Tools.SpitLongArrary(tableIds);
|
||||
//TODO 带做 删除表
|
||||
return SUCCESS("");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 导入表
|
||||
/// </summary>
|
||||
/// <param name="tables"></param>
|
||||
/// <param name="dbName"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("importTable")]
|
||||
[Log(Title = "代码生成", BusinessType = BusinessType.IMPORT)]
|
||||
[ActionPermissionFilter(Permission = "tool:gen:import")]
|
||||
public IActionResult ImportTableSave(string tables, string dbName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(tables))
|
||||
{
|
||||
throw new CustomException("表不能为空");
|
||||
}
|
||||
string[] tableNames = tables.Split(',', StringSplitOptions.RemoveEmptyEntries);
|
||||
string userName = User.Identity.Name;
|
||||
|
||||
foreach (var item in tableNames)
|
||||
{
|
||||
var tabInfo = _CodeGeneraterService.GetTableInfo(dbName, item);
|
||||
if (tabInfo != null)
|
||||
{
|
||||
GenTable genTable = new()
|
||||
{
|
||||
TableName = item,
|
||||
TableComment = tabInfo.Description,
|
||||
ClassName = CodeGeneratorTool.GetModelClassName(item),
|
||||
CreateBy = userName,
|
||||
CreateTime = DateTime.Now
|
||||
};
|
||||
int rows = GenTableService.InsertGenTable(genTable);
|
||||
if (rows > 0)
|
||||
{
|
||||
//保存列信息
|
||||
List<DbColumnInfo> dbColumnInfos = _CodeGeneraterService.GetColumnInfo(dbName, item);
|
||||
List<GenTableColumn> genTableColumns = new();
|
||||
long tableId = 0;
|
||||
foreach (var column in dbColumnInfos)
|
||||
{
|
||||
tableId = column.TableId;
|
||||
|
||||
GenTableColumn genTableColumn = new()
|
||||
{
|
||||
ColumnName = column.DbColumnName,
|
||||
ColumnComment = column.ColumnDescription,
|
||||
IsPk = column.IsPrimarykey,
|
||||
ColumnType = column.DataType,
|
||||
TableId = rows,
|
||||
TableName = item,
|
||||
CsharpType = TableMappingHelper.GetPropertyDatatype(column.DataType),
|
||||
CsharpField = column.DbColumnName.Substring(0, 1).ToUpper() + column.DbColumnName[1..],
|
||||
IsRequired = column.IsNullable,
|
||||
IsIncrement = column.IsIdentity,
|
||||
CreateBy = userName,
|
||||
CreateTime = DateTime.Now,
|
||||
IsInsert = true,
|
||||
IsEdit = true,
|
||||
IsList = true,
|
||||
IsQuery = false
|
||||
};
|
||||
genTableColumns.Add(genTableColumn);
|
||||
}
|
||||
|
||||
GenTableColumnService.DeleteGenTableColumn(tableId);
|
||||
GenTableColumnService.InsertGenTableColumn(genTableColumns);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return SUCCESS(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,7 +9,6 @@ using System.Text;
|
||||
using ZR.Common;
|
||||
using {ModelsNamespace}.Models;
|
||||
using {IRepositoriesNamespace};
|
||||
using {ServicesNamespace}.IService;
|
||||
|
||||
namespace {ServicesNamespace}.Business
|
||||
{
|
||||
|
||||
@ -42,10 +42,16 @@ namespace ZR.CodeGenerator
|
||||
if (!dbFieldInfo.IsNullable && !dbFieldInfo.IsIdentity)
|
||||
{
|
||||
vueViewEditFromRuleContent += $" {dbFieldInfo.DbColumnName}: [\n";
|
||||
vueViewEditFromRuleContent += $" {{ required: true, message:\"请输入{dbFieldInfo.ColumnDescription}\", trigger: \"blur\"}},\n";
|
||||
vueViewEditFromRuleContent += $" {{ required: true, message: '请输入{dbFieldInfo.ColumnDescription}', trigger: \"blur\"}},\n";
|
||||
//vueViewEditFromRuleContent += " { min: 2, max: 50, message: \"长度在 2 到 50 个字符\", trigger:\"blur\" }\n";
|
||||
vueViewEditFromRuleContent += " ],\n";
|
||||
}
|
||||
else if (TableMappingHelper.IsNumber(dbFieldInfo.DataType))
|
||||
{
|
||||
vueViewEditFromRuleContent += $" {dbFieldInfo.DbColumnName}: [\n";
|
||||
vueViewEditFromRuleContent += $" {{ type: 'number', message: '{dbFieldInfo.DbColumnName}必须为数字值', trigger: \"blur\"}},\n";
|
||||
vueViewEditFromRuleContent += " ],\n";
|
||||
}
|
||||
|
||||
return vueViewEditFromRuleContent;
|
||||
}
|
||||
@ -98,24 +104,26 @@ namespace ZR.CodeGenerator
|
||||
//图片
|
||||
vueViewFromContent += $" <el-form-item label=\"{labelName}\" :label-width=\"labelWidth\" prop=\"{columnName}\">\n";
|
||||
vueViewFromContent += $" <el-upload class=\"avatar-uploader\" name=\"file\" action=\"/api/upload/saveFile/\" :show-file-list=\"false\" :on-success=\"handleUpload{columnName}Success\" :before-upload=\"beforeFileUpload\">\n";
|
||||
vueViewFromContent += $" <img v-if=\"form.{columnName}\" :src=\"form.{columnName}\" class=\"icon\">\n";
|
||||
vueViewFromContent += " <i v-else class=\"el-icon-plus uploader-icon\"></i>\n";
|
||||
vueViewFromContent += " </el-upload>\n";
|
||||
vueViewFromContent += $" <el-input v-model=\"form.{columnName}\" placeholder=\"请上传文件或手动输入文件地址\"></el-input>\n";
|
||||
vueViewFromContent += $" <img v-if=\"form.{columnName}\" :src=\"form.{columnName}\" class=\"icon\">\n";
|
||||
vueViewFromContent += " <i v-else class=\"el-icon-plus uploader-icon\"></i>\n";
|
||||
vueViewFromContent += " </el-upload>\n";
|
||||
vueViewFromContent += $" <el-input v-model=\"form.{columnName}\" placeholder=\"请上传文件或手动输入文件地址\"></el-input>\n";
|
||||
vueViewFromContent += " </el-form-item>\n";
|
||||
}
|
||||
else if (CodeGeneratorTool.radioFiled.Any(f => columnName.Contains(f)) && (dbFieldInfo.DataType == "bool" || dbFieldInfo.DataType == "tinyint" || dbFieldInfo.DataType == "int"))
|
||||
{
|
||||
vueViewFromContent += $" <el-form-item label=\"{labelName}\" :label-width=\"labelWidth\" prop=\"{columnName}\">";
|
||||
vueViewFromContent += $" <el-form-item label=\"{labelName}\" :label-width=\"labelWidth\" prop=\"{columnName}\">\n";
|
||||
vueViewFromContent += $" <el-radio-group v-model=\"form.{columnName}\">\n";
|
||||
vueViewFromContent += " <el-radio v-for=\"dict in statusOptions\" :key=\"dict.dictValue\" :label=\"dict.dictValue\">{{dict.dictLabel}}</el-radio>\n";
|
||||
vueViewFromContent += " <el-radio :key=\"1\" :label=\"1\">是</el-radio>\n";
|
||||
vueViewFromContent += " <el-radio :key=\"0\" :label=\"0\">否</el-radio>\n";
|
||||
vueViewFromContent += " </el-radio-group>\n";
|
||||
vueViewFromContent += " </el-form-item>\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
string inputNumTxt = TableMappingHelper.IsNumber(dbFieldInfo.DataType) ? ".number" : "";
|
||||
vueViewFromContent += $" <el-form-item label=\"{ CodeGeneratorTool.GetLabelName(dbFieldInfo.ColumnDescription, columnName)}\" :label-width=\"labelWidth\" prop=\"{CodeGeneratorTool.FirstLowerCase(columnName)}\">\n";
|
||||
vueViewFromContent += $" <el-input v-model=\"form.{CodeGeneratorTool.FirstLowerCase(columnName)}\" placeholder=\"{placeHolder}\" {labelDisabled}/>\n";
|
||||
vueViewFromContent += $" <el-input v-model{inputNumTxt}=\"form.{CodeGeneratorTool.FirstLowerCase(columnName)}\" placeholder=\"{placeHolder}\" {labelDisabled}/>\n";
|
||||
vueViewFromContent += " </el-form-item>\n";
|
||||
}
|
||||
|
||||
|
||||
@ -33,10 +33,27 @@ namespace ZR.CodeGenerator.Service
|
||||
{
|
||||
tableList = tableList.Where(f => f.Name.ToLower().Contains(tableName.ToLower())).ToList();
|
||||
}
|
||||
tableList = tableList.Where(f => !new string[] { "gen", "sys_" }.Contains(f.Name)).ToList();
|
||||
pager.TotalNum = tableList.Count;
|
||||
return tableList.Skip(pager.PageSize * (pager.PageNum - 1)).Take(pager.PageSize).OrderBy(f => f.Name).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取单表数据
|
||||
/// </summary>
|
||||
/// <param name="dbName"></param>
|
||||
/// <param name="tableName"></param>
|
||||
/// <returns></returns>
|
||||
public DbTableInfo GetTableInfo(string dbName, string tableName)
|
||||
{
|
||||
var tableList = GetSugarDbContext(dbName).DbMaintenance.GetTableInfoList(true);
|
||||
if (!string.IsNullOrEmpty(tableName))
|
||||
{
|
||||
return tableList.Where(f => f.Name.ToLower() == (tableName.ToLower())).FirstOrDefault();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取列信息
|
||||
/// </summary>
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Infrastructure.Extensions;
|
||||
using ZR.Common.Extension;
|
||||
@ -108,5 +109,11 @@ namespace ZR.CodeGenerator.CodeGenerator
|
||||
}
|
||||
return sTempDatatype;
|
||||
}
|
||||
|
||||
public static bool IsNumber(string tableDataType)
|
||||
{
|
||||
string[] arr = new string[] { "int", "long" };
|
||||
return arr.Any(f => f.Replace("?", "").Contains(GetPropertyDatatype(tableDataType)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
34
ZR.Model/System/Generate/GenTable.cs
Normal file
34
ZR.Model/System/Generate/GenTable.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace ZR.Model.System.Generate
|
||||
{
|
||||
/// <summary>
|
||||
/// 代码生成表
|
||||
/// </summary>
|
||||
[SqlSugar.SugarTable("gen_table")]
|
||||
public class GenTable
|
||||
{
|
||||
[SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
||||
public int TableId { get; set; }
|
||||
public string TableName { get; set; }
|
||||
public string TableComment { get; set; }
|
||||
public string SubTableName { get; set; }
|
||||
public string SubTableFkName { get; set; }
|
||||
public string ClassName { get; set; }
|
||||
public string TplCategory { get; set; }
|
||||
public string PackageName { get; set; }
|
||||
public string ModuleName { get; set; }
|
||||
public string BusinessName { get; set; }
|
||||
public string FunctionName { get; set; }
|
||||
public string FunctionAuthor { get; set; }
|
||||
public string GenType { get; set; }
|
||||
public string Options { get; set; }
|
||||
|
||||
[SqlSugar.SugarColumn(IsOnlyIgnoreUpdate = true)]
|
||||
public string CreateBy { get; set; }
|
||||
[SqlSugar.SugarColumn(IsOnlyIgnoreUpdate = true)]
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
}
|
||||
43
ZR.Model/System/Generate/GenTableColumn.cs
Normal file
43
ZR.Model/System/Generate/GenTableColumn.cs
Normal file
@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace ZR.Model.System.Generate
|
||||
{
|
||||
/// <summary>
|
||||
/// 代码生成表字段
|
||||
/// </summary>
|
||||
[SqlSugar.SugarTable("gen_table_column")]
|
||||
public class GenTableColumn
|
||||
{
|
||||
[SqlSugar.SugarColumn(IsIdentity = true, IsPrimaryKey = true)]
|
||||
public int ColumnId { get; set; }
|
||||
public string ColumnName { get; set; }
|
||||
public int TableId { get; set; }
|
||||
public string TableName { get; set; }
|
||||
public string ColumnComment { get; set; }
|
||||
public string ColumnType { get; set; }
|
||||
public string CsharpType { get; set; }
|
||||
public string CsharpField { get; set; }
|
||||
public bool IsPk { get; set; }
|
||||
public bool IsRequired { get; set; }
|
||||
public bool IsIncrement { get; set; }
|
||||
/// <summary>
|
||||
/// 是否插入
|
||||
/// </summary>
|
||||
public bool IsInsert { get; set; }
|
||||
/// <summary>
|
||||
/// 是否需要编辑
|
||||
/// </summary>
|
||||
public bool IsEdit { get; set; }
|
||||
/// <summary>
|
||||
/// isList
|
||||
/// </summary>
|
||||
public bool IsList { get; set; }
|
||||
public bool IsQuery { get; set; }
|
||||
public int Sort { get; set; }
|
||||
|
||||
public string CreateBy { get; set; }
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
}
|
||||
@ -65,7 +65,7 @@ namespace ZR.Service
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加或更新数据
|
||||
/// 添加或更新数据,不推荐使用了
|
||||
/// </summary>
|
||||
/// <param name="parm">List<T></param>
|
||||
/// <returns></returns>
|
||||
|
||||
114
ZR.Service/System/GenTableService.cs
Normal file
114
ZR.Service/System/GenTableService.cs
Normal file
@ -0,0 +1,114 @@
|
||||
using Infrastructure.Attribute;
|
||||
using Infrastructure.Extensions;
|
||||
using Infrastructure.Model;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ZR.Model.System.Generate;
|
||||
using ZR.Service.System.IService;
|
||||
|
||||
namespace ZR.Service.System
|
||||
{
|
||||
/// <summary>
|
||||
/// 代码生成表
|
||||
/// </summary>
|
||||
[AppService(ServiceType = typeof(IGenTableService), ServiceLifetime = LifeTime.Transient)]
|
||||
public class GenTableService : BaseService<GenTable>, IGenTableService
|
||||
{
|
||||
/// <summary>
|
||||
/// 删除表
|
||||
/// </summary>
|
||||
/// <param name="table"></param>
|
||||
/// <returns></returns>
|
||||
public int DeleteGenTable(GenTable table)
|
||||
{
|
||||
return Db.Deleteable<GenTable>().Where(f => f.TableName == table.TableName).ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取表信息
|
||||
/// </summary>
|
||||
/// <param name="tableId"></param>
|
||||
/// <returns></returns>
|
||||
public GenTable GetGenTableInfo(long tableId)
|
||||
{
|
||||
return GetId(tableId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询代码生成表信息
|
||||
/// </summary>
|
||||
/// <param name="genTable"></param>
|
||||
/// <param name="pagerInfo"></param>
|
||||
/// <returns></returns>
|
||||
public PagedInfo<GenTable> GetGenTables(GenTable genTable, Model.PagerInfo pagerInfo)
|
||||
{
|
||||
var predicate = Expressionable.Create<GenTable>();
|
||||
predicate = predicate.AndIF(genTable.TableName.IfNotEmpty(), it => it.TableName.Contains(genTable.TableName));
|
||||
|
||||
return GetPages(predicate.ToExpression(), pagerInfo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 插入代码生成表
|
||||
/// </summary>
|
||||
/// <param name="table"></param>
|
||||
/// <returns></returns>
|
||||
public int InsertGenTable(GenTable table)
|
||||
{
|
||||
var db = Db;
|
||||
DeleteGenTable(table);
|
||||
return db.Insertable(table).ExecuteReturnIdentity();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取表数据
|
||||
/// </summary>
|
||||
/// <param name="tableNames"></param>
|
||||
/// <returns></returns>
|
||||
public List<GenTable> SelectDbTableListByNamess(string[] tableNames)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 代码生成表列
|
||||
/// </summary>
|
||||
[AppService(ServiceType = typeof(IGenTableColumnService), ServiceLifetime = LifeTime.Transient)]
|
||||
public class GenTableColumnService : BaseService<GenTableColumn>, IGenTableColumnService
|
||||
{
|
||||
/// <summary>
|
||||
/// 删除表字段
|
||||
/// </summary>
|
||||
/// <param name="tableColumn"></param>
|
||||
/// <returns></returns>
|
||||
public int DeleteGenTableColumn(long tableId)
|
||||
{
|
||||
return Db.Deleteable<GenTableColumn>().Where(f => f.TableId == tableId).ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取表所有字段
|
||||
/// </summary>
|
||||
/// <param name="tableId"></param>
|
||||
/// <returns></returns>
|
||||
public List<GenTableColumn> GenTableColumns(long tableId)
|
||||
{
|
||||
return GetAll().OrderBy(x => x.Sort).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 插入表字段
|
||||
/// </summary>
|
||||
/// <param name="tableColumn"></param>
|
||||
/// <returns></returns>
|
||||
public int InsertGenTableColumn(List<GenTableColumn> tableColumn)
|
||||
{
|
||||
return Db.Insertable(tableColumn).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
}
|
||||
30
ZR.Service/System/IService/IGenTableService.cs
Normal file
30
ZR.Service/System/IService/IGenTableService.cs
Normal file
@ -0,0 +1,30 @@
|
||||
using Infrastructure.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ZR.Model.System.Generate;
|
||||
|
||||
namespace ZR.Service.System.IService
|
||||
{
|
||||
public interface IGenTableService
|
||||
{
|
||||
List<GenTable> SelectDbTableListByNamess(string[] tableNames);
|
||||
|
||||
int InsertGenTable(GenTable tables);
|
||||
|
||||
int DeleteGenTable(GenTable table);
|
||||
PagedInfo<GenTable> GetGenTables(GenTable genTable, Model.PagerInfo pagerInfo);
|
||||
GenTable GetGenTableInfo(long tableId);
|
||||
}
|
||||
|
||||
public interface IGenTableColumnService
|
||||
{
|
||||
int InsertGenTableColumn(List<GenTableColumn> tableColumn);
|
||||
|
||||
int DeleteGenTableColumn(long tableId);
|
||||
|
||||
List<GenTableColumn> GenTableColumns(long tableId);
|
||||
}
|
||||
}
|
||||
@ -30,7 +30,7 @@ export function codeGetDBList() {
|
||||
/**
|
||||
* 获取数据库表
|
||||
*/
|
||||
export function codeGetTableList(data) {
|
||||
export function listDbTable(data) {
|
||||
return request({
|
||||
url: 'tool/gen/getTableList',
|
||||
method: 'get',
|
||||
@ -53,14 +53,32 @@ export async function codeGenerator(data) {
|
||||
* @param {*} data
|
||||
* @returns
|
||||
*/
|
||||
export function queryColumnInfo(data) {
|
||||
export function queryColumnInfo(tableId) {
|
||||
return request({
|
||||
url: 'tool/gen/getColumnInfo',
|
||||
url: 'tool/gen/Column/' + tableId,
|
||||
method: 'GET',
|
||||
params: data,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// 查询表详细信息
|
||||
export function getGenTable(params) {
|
||||
return request({
|
||||
url: 'tool/gen/getGenTable',
|
||||
method: 'get',
|
||||
params: params
|
||||
})
|
||||
}
|
||||
// 导入表
|
||||
export function importTable(data) {
|
||||
return request({
|
||||
url: '/tool/gen/importTable',
|
||||
method: 'post',
|
||||
params: data
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// /**
|
||||
// *
|
||||
// * 数据库解密
|
||||
|
||||
225
ZR.Vue/src/views/tool/gen/editTable.vue
Normal file
225
ZR.Vue/src/views/tool/gen/editTable.vue
Normal file
@ -0,0 +1,225 @@
|
||||
<template>
|
||||
<el-card>
|
||||
<el-tabs v-model="activeName">
|
||||
<el-tab-pane label="基本信息" name="basic">
|
||||
<basic-info-form ref="basicInfo" :info="info" />
|
||||
</el-tab-pane>
|
||||
<el-tab-pane label="字段信息" name="cloum">
|
||||
<el-table ref="dragTable" :data="cloumns" row-key="columnId" :max-height="tableHeight">
|
||||
<el-table-column label="序号" type="index" min-width="5%" class-name="allowDrag" />
|
||||
<el-table-column label="字段列名" prop="columnName" min-width="10%" :show-overflow-tooltip="true" />
|
||||
<el-table-column label="字段描述" min-width="10%">
|
||||
<template slot-scope="scope">
|
||||
<el-input v-model="scope.row.columnComment"></el-input>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="物理类型" prop="columnType" min-width="10%" :show-overflow-tooltip="true" />
|
||||
<el-table-column label="C#类型" min-width="11%">
|
||||
<template slot-scope="scope">
|
||||
<el-select v-model="scope.row.csharpType">
|
||||
<el-option label="long" value="long" />
|
||||
<el-option label="int" value="int" />
|
||||
<el-option label="string" value="string" />
|
||||
<el-option label="double" value="double" />
|
||||
<el-option label="decimal" value="decimal" />
|
||||
<el-option label="dateTime" value="DateTime" />
|
||||
</el-select>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="C#属性" min-width="10%">
|
||||
<template slot-scope="scope">
|
||||
<el-input v-model="scope.row.csharpField"></el-input>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column label="插入" min-width="5%">
|
||||
<template slot-scope="scope">
|
||||
<el-checkbox true-label="1" v-model="scope.row.isInsert"></el-checkbox>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="编辑" min-width="5%">
|
||||
<template slot-scope="scope">
|
||||
<el-checkbox true-label="1" v-model="scope.row.isEdit"></el-checkbox>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="列表" min-width="5%">
|
||||
<template slot-scope="scope">
|
||||
<el-checkbox true-label="1" v-model="scope.row.isList"></el-checkbox>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="查询" min-width="5%">
|
||||
<template slot-scope="scope">
|
||||
<el-checkbox true-label="1" v-model="scope.row.isQuery"></el-checkbox>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="查询方式" min-width="10%">
|
||||
<template slot-scope="scope">
|
||||
<el-select v-model="scope.row.queryType">
|
||||
<el-option label="=" value="EQ" />
|
||||
<el-option label="!=" value="NE" />
|
||||
<el-option label=">" value="GT" />
|
||||
<el-option label=">=" value="GTE" />
|
||||
<el-option label="<" value="LT" />
|
||||
<el-option label="<=" value="LTE" />
|
||||
<el-option label="LIKE" value="LIKE" />
|
||||
<el-option label="BETWEEN" value="BETWEEN" />
|
||||
</el-select>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="必填" min-width="5%">
|
||||
<template slot-scope="scope">
|
||||
<el-checkbox true-label="1" v-model="scope.row.isRequired"></el-checkbox>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="显示类型" min-width="12%">
|
||||
<template slot-scope="scope">
|
||||
<el-select v-model="scope.row.htmlType">
|
||||
<el-option label="文本框" value="input" />
|
||||
<el-option label="文本域" value="textarea" />
|
||||
<el-option label="下拉框" value="select" />
|
||||
<el-option label="单选框" value="radio" />
|
||||
<el-option label="复选框" value="checkbox" />
|
||||
<el-option label="日期控件" value="datetime" />
|
||||
<el-option label="图片上传" value="imageUpload" />
|
||||
<el-option label="文件上传" value="fileUpload" />
|
||||
<el-option label="富文本控件" value="editor" />
|
||||
</el-select>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="字典类型" min-width="12%">
|
||||
<template slot-scope="scope">
|
||||
<el-select v-model="scope.row.dictType" clearable filterable placeholder="请选择">
|
||||
<el-option v-for="dict in dictOptions" :key="dict.dictType" :label="dict.dictName" :value="dict.dictType">
|
||||
<span style="float: left">{{ dict.dictName }}</span>
|
||||
<span style="float: right; color: #8492a6; font-size: 13px">{{ dict.dictType }}</span>
|
||||
</el-option>
|
||||
</el-select>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-tab-pane>
|
||||
<el-tab-pane label="生成信息" name="genInfo">
|
||||
<gen-info-form ref="genInfo" :info="info" :tables="tables" :menus="menus" />
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
<el-form label-width="100px">
|
||||
<el-form-item style="text-align: center;margin-left:-100px;margin-top:10px;">
|
||||
<el-button type="primary" @click="submitForm()">提交</el-button>
|
||||
<el-button type="success" @click="handleQuery()">刷新</el-button>
|
||||
<el-button @click="close()">返回</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-card>
|
||||
</template>
|
||||
<script>
|
||||
import { updateGenTable, queryColumnInfo } from "@/api/tool/gen";
|
||||
import { listType } from "@/api/system/dict/type";
|
||||
import { listMenu as getMenuTreeselect } from "@/api/system/menu";
|
||||
import basicInfoForm from "./basicInfoForm";
|
||||
import genInfoForm from "./genInfoForm";
|
||||
import Sortable from "sortablejs";
|
||||
|
||||
export default {
|
||||
name: "GenEdit",
|
||||
components: {
|
||||
basicInfoForm,
|
||||
genInfoForm,
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
// 选中选项卡的 name
|
||||
activeName: "cloum",
|
||||
// 表格的高度
|
||||
tableHeight: document.documentElement.scrollHeight - 245 + "px",
|
||||
// 表信息
|
||||
tables: [],
|
||||
// 表列信息
|
||||
cloumns: [],
|
||||
// 字典信息
|
||||
dictOptions: [],
|
||||
// 菜单信息
|
||||
menus: [],
|
||||
// 表详细信息
|
||||
info: {},
|
||||
};
|
||||
},
|
||||
created() {
|
||||
this.handleQuery();
|
||||
},
|
||||
methods: {
|
||||
handleQuery() {
|
||||
const tableId = this.$route.query && this.$route.query.tableId;
|
||||
|
||||
if (tableId) {
|
||||
// 获取表详细信息
|
||||
queryColumnInfo(tableId).then((res) => {
|
||||
this.cloumns = res.data.result;
|
||||
this.info = res.data.info;
|
||||
this.tables = res.data.tables;
|
||||
});
|
||||
/** 查询字典下拉列表 */
|
||||
listType().then((response) => {
|
||||
this.dictOptions = response.data.result;
|
||||
});
|
||||
/** 查询菜单下拉列表 */
|
||||
// getMenuTreeselect().then((response) => {
|
||||
// this.menus = this.handleTree(response.data, "menuId");
|
||||
// });
|
||||
}
|
||||
},
|
||||
/** 提交按钮 */
|
||||
submitForm() {
|
||||
const basicForm = this.$refs.basicInfo.$refs.basicInfoForm;
|
||||
const genForm = this.$refs.genInfo.$refs.genInfoForm;
|
||||
Promise.all([basicForm, genForm].map(this.getFormPromise)).then((res) => {
|
||||
const validateResult = res.every((item) => !!item);
|
||||
if (validateResult) {
|
||||
const genTable = Object.assign({}, basicForm.model, genForm.model);
|
||||
genTable.columns = this.cloumns;
|
||||
genTable.params = {
|
||||
treeCode: genTable.treeCode,
|
||||
treeName: genTable.treeName,
|
||||
treeParentCode: genTable.treeParentCode,
|
||||
parentMenuId: genTable.parentMenuId,
|
||||
};
|
||||
updateGenTable(genTable).then((res) => {
|
||||
this.msgSuccess(res.msg);
|
||||
if (res.code === 200) {
|
||||
this.close();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.msgError("表单校验未通过,请重新检查提交内容");
|
||||
}
|
||||
});
|
||||
},
|
||||
getFormPromise(form) {
|
||||
return new Promise((resolve) => {
|
||||
form.validate((res) => {
|
||||
resolve(res);
|
||||
});
|
||||
});
|
||||
},
|
||||
/** 关闭按钮 */
|
||||
close() {
|
||||
this.$store.dispatch("tagsView/delView", this.$route);
|
||||
this.$router.push({ path: "/tool/gen", query: { t: Date.now() } });
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
const el = this.$refs.dragTable.$el.querySelectorAll(
|
||||
".el-table__body-wrapper > table > tbody"
|
||||
)[0];
|
||||
const sortable = Sortable.create(el, {
|
||||
handle: ".allowDrag",
|
||||
onEnd: (evt) => {
|
||||
const targetRow = this.cloumns.splice(evt.oldIndex, 1)[0];
|
||||
this.cloumns.splice(evt.newIndex, 0, targetRow);
|
||||
for (let index in this.cloumns) {
|
||||
this.cloumns[index].sort = parseInt(index) + 1;
|
||||
}
|
||||
},
|
||||
});
|
||||
},
|
||||
};
|
||||
</script>
|
||||
300
ZR.Vue/src/views/tool/gen/genInfoForm.vue
Normal file
300
ZR.Vue/src/views/tool/gen/genInfoForm.vue
Normal file
@ -0,0 +1,300 @@
|
||||
<template>
|
||||
<el-form ref="genInfoForm" :model="info" :rules="rules" label-width="150px">
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item prop="tplCategory">
|
||||
<span slot="label">生成模板</span>
|
||||
<el-select v-model="info.tplCategory" @change="tplSelectChange">
|
||||
<el-option label="单表(增删改查)" value="crud" />
|
||||
<el-option label="树表(增删改查)" value="tree" />
|
||||
<el-option label="主子表(增删改查)" value="sub" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="12">
|
||||
<el-form-item prop="packageName">
|
||||
<span slot="label">
|
||||
生成包路径
|
||||
<el-tooltip content="生成在哪个java包下,例如 com.ruoyi.system" placement="top">
|
||||
<i class="el-icon-question"></i>
|
||||
</el-tooltip>
|
||||
</span>
|
||||
<el-input v-model="info.packageName" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="12">
|
||||
<el-form-item prop="moduleName">
|
||||
<span slot="label">
|
||||
生成模块名
|
||||
<el-tooltip content="可理解为子系统名,例如 system" placement="top">
|
||||
<i class="el-icon-question"></i>
|
||||
</el-tooltip>
|
||||
</span>
|
||||
<el-input v-model="info.moduleName" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="12">
|
||||
<el-form-item prop="businessName">
|
||||
<span slot="label">
|
||||
生成业务名
|
||||
<el-tooltip content="可理解为功能英文名,例如 user" placement="top">
|
||||
<i class="el-icon-question"></i>
|
||||
</el-tooltip>
|
||||
</span>
|
||||
<el-input v-model="info.businessName" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="12">
|
||||
<el-form-item prop="functionName">
|
||||
<span slot="label">
|
||||
生成功能名
|
||||
<el-tooltip content="用作类描述,例如 用户" placement="top">
|
||||
<i class="el-icon-question"></i>
|
||||
</el-tooltip>
|
||||
</span>
|
||||
<el-input v-model="info.functionName" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="12">
|
||||
<el-form-item>
|
||||
<span slot="label">
|
||||
上级菜单
|
||||
<el-tooltip content="分配到指定菜单下,例如 系统管理" placement="top">
|
||||
<i class="el-icon-question"></i>
|
||||
</el-tooltip>
|
||||
</span>
|
||||
<treeselect
|
||||
:append-to-body="true"
|
||||
v-model="info.parentMenuId"
|
||||
:options="menus"
|
||||
:normalizer="normalizer"
|
||||
:show-count="true"
|
||||
placeholder="请选择系统菜单"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="12">
|
||||
<el-form-item prop="genType">
|
||||
<span slot="label">
|
||||
生成代码方式
|
||||
<el-tooltip content="默认为zip压缩包下载,也可以自定义生成路径" placement="top">
|
||||
<i class="el-icon-question"></i>
|
||||
</el-tooltip>
|
||||
</span>
|
||||
<el-radio v-model="info.genType" label="0">zip压缩包</el-radio>
|
||||
<el-radio v-model="info.genType" label="1">自定义路径</el-radio>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="24" v-if="info.genType == '1'">
|
||||
<el-form-item prop="genPath">
|
||||
<span slot="label">
|
||||
自定义路径
|
||||
<el-tooltip content="填写磁盘绝对路径,若不填写,则生成到当前Web项目下" placement="top">
|
||||
<i class="el-icon-question"></i>
|
||||
</el-tooltip>
|
||||
</span>
|
||||
<el-input v-model="info.genPath">
|
||||
<el-dropdown slot="append">
|
||||
<el-button type="primary">
|
||||
最近路径快速选择
|
||||
<i class="el-icon-arrow-down el-icon--right"></i>
|
||||
</el-button>
|
||||
<el-dropdown-menu slot="dropdown">
|
||||
<el-dropdown-item @click.native="info.genPath = '/'">恢复默认的生成基础路径</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</el-dropdown>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row v-show="info.tplCategory == 'tree'">
|
||||
<h4 class="form-header">其他信息</h4>
|
||||
<el-col :span="12">
|
||||
<el-form-item>
|
||||
<span slot="label">
|
||||
树编码字段
|
||||
<el-tooltip content="树显示的编码字段名, 如:dept_id" placement="top">
|
||||
<i class="el-icon-question"></i>
|
||||
</el-tooltip>
|
||||
</span>
|
||||
<el-select v-model="info.treeCode" placeholder="请选择">
|
||||
<el-option
|
||||
v-for="(column, index) in info.columns"
|
||||
:key="index"
|
||||
:label="column.columnName + ':' + column.columnComment"
|
||||
:value="column.columnName"
|
||||
></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item>
|
||||
<span slot="label">
|
||||
树父编码字段
|
||||
<el-tooltip content="树显示的父编码字段名, 如:parent_Id" placement="top">
|
||||
<i class="el-icon-question"></i>
|
||||
</el-tooltip>
|
||||
</span>
|
||||
<el-select v-model="info.treeParentCode" placeholder="请选择">
|
||||
<el-option
|
||||
v-for="(column, index) in info.columns"
|
||||
:key="index"
|
||||
:label="column.columnName + ':' + column.columnComment"
|
||||
:value="column.columnName"
|
||||
></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item>
|
||||
<span slot="label">
|
||||
树名称字段
|
||||
<el-tooltip content="树节点的显示名称字段名, 如:dept_name" placement="top">
|
||||
<i class="el-icon-question"></i>
|
||||
</el-tooltip>
|
||||
</span>
|
||||
<el-select v-model="info.treeName" placeholder="请选择">
|
||||
<el-option
|
||||
v-for="(column, index) in info.columns"
|
||||
:key="index"
|
||||
:label="column.columnName + ':' + column.columnComment"
|
||||
:value="column.columnName"
|
||||
></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row v-show="info.tplCategory == 'sub'">
|
||||
<h4 class="form-header">关联信息</h4>
|
||||
<el-col :span="12">
|
||||
<el-form-item>
|
||||
<span slot="label">
|
||||
关联子表的表名
|
||||
<el-tooltip content="关联子表的表名, 如:sys_user" placement="top">
|
||||
<i class="el-icon-question"></i>
|
||||
</el-tooltip>
|
||||
</span>
|
||||
<el-select v-model="info.subTableName" placeholder="请选择" @change="subSelectChange">
|
||||
<el-option
|
||||
v-for="(table, index) in tables"
|
||||
:key="index"
|
||||
:label="table.tableName + ':' + table.tableComment"
|
||||
:value="table.tableName"
|
||||
></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item>
|
||||
<span slot="label">
|
||||
子表关联的外键名
|
||||
<el-tooltip content="子表关联的外键名, 如:user_id" placement="top">
|
||||
<i class="el-icon-question"></i>
|
||||
</el-tooltip>
|
||||
</span>
|
||||
<el-select v-model="info.subTableFkName" placeholder="请选择">
|
||||
<el-option
|
||||
v-for="(column, index) in subColumns"
|
||||
:key="index"
|
||||
:label="column.columnName + ':' + column.columnComment"
|
||||
:value="column.columnName"
|
||||
></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-form>
|
||||
</template>
|
||||
<script>
|
||||
import Treeselect from "@riophae/vue-treeselect";
|
||||
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
|
||||
|
||||
export default {
|
||||
name: "BasicInfoForm",
|
||||
components: { Treeselect },
|
||||
props: {
|
||||
info: {
|
||||
type: Object,
|
||||
default: null
|
||||
},
|
||||
tables: {
|
||||
type: Array,
|
||||
default: null
|
||||
},
|
||||
menus: {
|
||||
type: Array,
|
||||
default: []
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
subColumns: [],
|
||||
rules: {
|
||||
tplCategory: [
|
||||
{ required: true, message: "请选择生成模板", trigger: "blur" }
|
||||
],
|
||||
packageName: [
|
||||
{ required: true, message: "请输入生成包路径", trigger: "blur" }
|
||||
],
|
||||
moduleName: [
|
||||
{ required: true, message: "请输入生成模块名", trigger: "blur" }
|
||||
],
|
||||
businessName: [
|
||||
{ required: true, message: "请输入生成业务名", trigger: "blur" }
|
||||
],
|
||||
functionName: [
|
||||
{ required: true, message: "请输入生成功能名", trigger: "blur" }
|
||||
],
|
||||
}
|
||||
};
|
||||
},
|
||||
created() {},
|
||||
watch: {
|
||||
'info.subTableName': function(val) {
|
||||
this.setSubTableColumns(val);
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
/** 转换菜单数据结构 */
|
||||
normalizer(node) {
|
||||
if (node.children && !node.children.length) {
|
||||
delete node.children;
|
||||
}
|
||||
return {
|
||||
id: node.menuId,
|
||||
label: node.menuName,
|
||||
children: node.children
|
||||
};
|
||||
},
|
||||
/** 选择子表名触发 */
|
||||
subSelectChange(value) {
|
||||
this.info.subTableFkName = '';
|
||||
},
|
||||
/** 选择生成模板触发 */
|
||||
tplSelectChange(value) {
|
||||
if(value !== 'sub') {
|
||||
this.info.subTableName = '';
|
||||
this.info.subTableFkName = '';
|
||||
}
|
||||
},
|
||||
/** 设置关联外键 */
|
||||
setSubTableColumns(value) {
|
||||
for (var item in this.tables) {
|
||||
const name = this.tables[item].tableName;
|
||||
if (value === name) {
|
||||
this.subColumns = this.tables[item].columns;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
132
ZR.Vue/src/views/tool/gen/importTable.vue
Normal file
132
ZR.Vue/src/views/tool/gen/importTable.vue
Normal file
@ -0,0 +1,132 @@
|
||||
<template>
|
||||
<!-- 导入表 -->
|
||||
<el-dialog title="导入表" :visible.sync="visible" width="900px" top="5vh" append-to-body>
|
||||
<el-form ref="queryParams" :inline="true" :rules="rules" :model="queryParams" size="small">
|
||||
<el-form-item label="数据库" prop="dbName">
|
||||
<el-select v-model="queryParams.dbName" clearable placeholder="请选择" @change="handleShowTable">
|
||||
<el-option v-for="item in dbList" :key="item" :label="item" :value="item" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="表名">
|
||||
<el-input v-model="queryParams.tableName" clearable placeholder="输入要查询的表名" />
|
||||
</el-form-item>
|
||||
<!-- <el-form-item label="去掉表名前缀:">
|
||||
<el-tooltip class="item" effect="dark" content="表名直接变为类名,去掉表名前缀。" placement="bottom">
|
||||
<el-input v-model="codeform.replaceTableNameStr" clearable width="300" placeholder="例如:sys_" />
|
||||
</el-tooltip>
|
||||
</el-form-item> -->
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="handleQuery()">查询</el-button>
|
||||
<!-- <el-button type="default" icon="el-icon-refresh" size="small" @click="loadTableData()">刷新</el-button> -->
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<el-row>
|
||||
<el-table ref="table" @row-click="clickRow" :data="dbTableList" highlight-current-row height="300px" @selection-change="handleSelectionChange">
|
||||
<el-table-column type="selection" width="55"></el-table-column>
|
||||
<el-table-column prop="name" label="表名" sortable="custom" width="380" />
|
||||
<el-table-column prop="description" label="表描述" />
|
||||
</el-table>
|
||||
<pagination background :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total" @pagination="getList" />
|
||||
|
||||
</el-row>
|
||||
<div slot="footer" class="dialog-footer">
|
||||
<el-button type="primary" @click="handleImportTable">确 定</el-button>
|
||||
<el-button @click="visible = false">取 消</el-button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { listDbTable, importTable, codeGetDBList } from "@/api/tool/gen";
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
// 遮罩层
|
||||
visible: false,
|
||||
// 选中数组值
|
||||
tables: [],
|
||||
// 总条数
|
||||
total: 0,
|
||||
// 表数据
|
||||
dbTableList: [],
|
||||
// 数据库数据
|
||||
dbList: [],
|
||||
// 查询参数
|
||||
queryParams: {
|
||||
dbName: "",
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
tableName: undefined,
|
||||
},
|
||||
rules: {
|
||||
dbName: [
|
||||
{ required: true, message: "请选择数据库名称", trigger: "blur" },
|
||||
],
|
||||
// replaceTableNameStr: [
|
||||
// { min: 0, max: 50, message: "长度小于50个字符", trigger: "blur" },
|
||||
// ],
|
||||
},
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
// 显示弹框
|
||||
show() {
|
||||
this.getList();
|
||||
this.visible = true;
|
||||
},
|
||||
clickRow(row) {
|
||||
this.$refs.table.toggleRowSelection(row);
|
||||
},
|
||||
// 多选框选中数据
|
||||
handleSelectionChange(selection) {
|
||||
this.tables = selection.map((item) => item.name);
|
||||
},
|
||||
// 查询表数据
|
||||
getList() {
|
||||
codeGetDBList().then((res) => {
|
||||
const { dbList, defaultDb } = res.data;
|
||||
// this.queryParams.dbName =
|
||||
// this.queryParams.dbName !== "" ? defaultDb : "";
|
||||
this.dbList = dbList;
|
||||
});
|
||||
if (this.queryParams.dbName !== "") {
|
||||
listDbTable(this.queryParams).then((res) => {
|
||||
this.dbTableList = res.data.result;
|
||||
this.total = res.data.totalNum;
|
||||
// this.tableloading = false;
|
||||
});
|
||||
}
|
||||
},
|
||||
/** 搜索按钮操作 */
|
||||
handleQuery() {
|
||||
this.queryParams.pageNum = 1;
|
||||
this.getList();
|
||||
},
|
||||
/** 重置按钮操作 */
|
||||
resetQuery() {
|
||||
this.resetForm("queryForm");
|
||||
this.handleQuery();
|
||||
},
|
||||
handleShowTable() {
|
||||
// console.log(json)
|
||||
this.handleQuery();
|
||||
},
|
||||
/** 导入按钮操作 */
|
||||
handleImportTable() {
|
||||
console.log(JSON.stringify(this.tables));
|
||||
|
||||
importTable({
|
||||
tables: this.tables.join(","),
|
||||
dbName: this.queryParams.dbName,
|
||||
}).then((res) => {
|
||||
this.msgSuccess(res.msg);
|
||||
if (res.code === 200) {
|
||||
this.visible = false;
|
||||
this.$emit("ok");
|
||||
}
|
||||
});
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
@ -1,23 +1,23 @@
|
||||
<template>
|
||||
<div class="app-container">
|
||||
|
||||
<el-form ref="codeform" :inline="true" :rules="rules" :model="codeform" size="small">
|
||||
<el-form-item label="数据库" prop="dbName">
|
||||
<el-select v-model="codeform.dbName" clearable placeholder="请选择" @change="handleShowTable">
|
||||
<el-form ref="codeform" :inline="true" :rules="rules" :model="queryParams" size="small">
|
||||
<!-- <el-form-item label="数据库" prop="dbName">
|
||||
<el-select v-model="queryParams.dbName" clearable placeholder="请选择" @change="handleShowTable">
|
||||
<el-option v-for="item in selectedDataBase" :key="item" :label="item" :value="item" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-form-item> -->
|
||||
<el-form-item label="表名">
|
||||
<el-input v-model="codeform.tableName" clearable placeholder="输入要查询的表名" />
|
||||
<el-input v-model="queryParams.tableName" clearable placeholder="输入要查询的表名" />
|
||||
</el-form-item>
|
||||
<!-- <el-form-item label="项目命名空间:" prop="baseSpace">
|
||||
<el-tooltip class="item" effect="dark" content="系统会根据项目命名空间自动生成IService、Service、Models等子命名空间" placement="bottom">
|
||||
<el-input v-model="codeform.baseSpace" clearable placeholder="如Zr" />
|
||||
<el-input v-model="queryParams.baseSpace" clearable placeholder="如Zr" />
|
||||
</el-tooltip>
|
||||
</el-form-item> -->
|
||||
<el-form-item label="去掉表名前缀:">
|
||||
<el-tooltip class="item" effect="dark" content="表名直接变为类名,去掉表名前缀。" placement="bottom">
|
||||
<el-input v-model="codeform.replaceTableNameStr" clearable width="300" placeholder="例如:sys_" />
|
||||
<el-input v-model="queryParams.replaceTableNameStr" clearable width="300" placeholder="例如:sys_" />
|
||||
</el-tooltip>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
@ -26,17 +26,38 @@
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<el-row :gutter="10" class="mb10">
|
||||
<el-col :span="1.5">
|
||||
<el-button type="info" plain icon="el-icon-upload" size="mini" @click="openImportTable" v-hasPermi="['tool:gen:import']">导入</el-button>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="1.5">
|
||||
<el-button type="danger" plain icon="el-icon-delete" size="mini" v-hasPermi="['tool:gen:delete']">删除</el-button>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-table ref="gridtable" v-loading="tableloading" :data="tableData" border stripe highlight-current-row height="500px" style="width: 100%;">
|
||||
<el-table-column prop="name" label="表名" sortable="custom" width="380" />
|
||||
<el-table-column prop="description" label="表描述" />
|
||||
<el-table-column label="操作" align="center" width="200">
|
||||
<el-table-column type="selection" align="center" width="55"></el-table-column>
|
||||
<el-table-column label="序号" type="index" width="50" align="center">
|
||||
<template slot-scope="scope">
|
||||
<span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="tableName" label="表名" sortable="custom" width="380" />
|
||||
<el-table-column prop="tableComment" label="表描述" />
|
||||
<el-table-column prop="className" label="实体" />
|
||||
<el-table-column prop="createTime" label="创建时间" />
|
||||
<el-table-column prop="updateTime" label="更新时间" />
|
||||
<el-table-column label="操作" align="center" width="240">
|
||||
<template slot-scope="scope">
|
||||
<el-button type="text" icon="el-icon-view" @click="handlePreview()">预览</el-button>
|
||||
<el-button type="text" icon="el-icon-edit" @click="handleEditTable(scope.row)">编辑</el-button>
|
||||
<el-button type="text" icon="el-icon-download" @click="handleShowDialog(scope.row)" v-hasPermi="['tool:gen:code']">生成代码</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<el-pagination background :current-page="pagination.pageNum" :page-sizes="[5,10,20,50,100, 200, 300, 400]" :page-size="pagination.pagesize" layout="total, sizes, prev, pager, next, jumper" :total="pagination.pageTotal" @size-change="handleSizeChange" @current-change="handleCurrentChange" />
|
||||
<pagination :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" :total="total" @pagination="handleSearch" />
|
||||
|
||||
<import-table ref="import" @ok="handleSearch" />
|
||||
|
||||
<el-dialog :visible.sync="showGenerate" title="代码生成" width="800px">
|
||||
<el-form ref="codeGenerateForm" label-width="140px">
|
||||
@ -55,38 +76,7 @@
|
||||
<el-radio v-model="coverd" :label="true">是</el-radio>
|
||||
<el-radio v-model="coverd" :label="false">否</el-radio>
|
||||
</el-form-item>
|
||||
<!-- <el-form-item label="生成查询的列">
|
||||
<el-table :data="columnData" height="300px">
|
||||
<el-table-column type="selection" width="60" />
|
||||
<el-table-column label="字段列名" prop="dbColumnName" />
|
||||
<el-table-column label="字段描述" prop="columnDescription">
|
||||
<template slot-scope="scope">
|
||||
<el-input v-model="scope.row.columnDescription" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="表数据类型" prop="dataType" />
|
||||
<el-table-column label="C#类型">
|
||||
<template slot-scope="scope">
|
||||
<el-select v-model="scope.row.dataType">
|
||||
<el-option value="int">int</el-option>
|
||||
<el-option value="bigint">bigint</el-option>
|
||||
<el-option value="varchar">varchar</el-option>
|
||||
</el-select>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="显示类型">
|
||||
<el-select v-model="selectType">
|
||||
<el-option value="input">文本框</el-option>
|
||||
<el-option value="textArea">文本域</el-option>
|
||||
<el-option value="select">下拉框</el-option>
|
||||
<el-option value="radio">单选框</el-option>
|
||||
<el-option value="datetime">日期控件</el-option>
|
||||
<el-option value="upload">图片上传</el-option>
|
||||
<el-option value="fileUpload">文件上传</el-option>
|
||||
</el-select>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-form-item> -->
|
||||
|
||||
</el-form>
|
||||
<div slot="footer" class="dialog-footer">
|
||||
<el-button type="primary" @click="handleGenerate">确 定</el-button>
|
||||
@ -97,21 +87,18 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {
|
||||
// createGetDBConn,
|
||||
codeGetDBList,
|
||||
codeGetTableList,
|
||||
codeGenerator,
|
||||
queryColumnInfo,
|
||||
} from "@/api/tool/gen";
|
||||
// import { downloadFile } from "@/utils/index";
|
||||
import { codeGenerator, getGenTable } from "@/api/tool/gen";
|
||||
import importTable from "./importTable";
|
||||
import { Loading } from "element-ui";
|
||||
|
||||
export default {
|
||||
name: "CodeGenerator",
|
||||
components: { importTable },
|
||||
data() {
|
||||
return {
|
||||
codeform: {
|
||||
queryParams: {
|
||||
pageNum: 1,
|
||||
pageSize: 20,
|
||||
dbName: "",
|
||||
tableName: "",
|
||||
baseSpace: "",
|
||||
@ -127,18 +114,16 @@ export default {
|
||||
{ min: 0, max: 50, message: "长度小于50个字符", trigger: "blur" },
|
||||
],
|
||||
},
|
||||
// 表数据
|
||||
tableData: [],
|
||||
// 是否显示加载
|
||||
tableloading: false,
|
||||
pagination: {
|
||||
pageNum: 1,
|
||||
pagesize: 20,
|
||||
pageTotal: 0,
|
||||
},
|
||||
total: 0,
|
||||
// 选中行的表
|
||||
currentSelected: {},
|
||||
selectedDataBase: [],
|
||||
// 列信息
|
||||
columnData: [],
|
||||
// columnData: [],
|
||||
// 选中的列
|
||||
checkedQueryColumn: [],
|
||||
//是否覆盖原先代码
|
||||
@ -146,54 +131,27 @@ export default {
|
||||
};
|
||||
},
|
||||
created() {
|
||||
this.pagination.pageNum = 1;
|
||||
this.loadData();
|
||||
this.loadTableData();
|
||||
this.handleSearch();
|
||||
},
|
||||
methods: {
|
||||
loadData() {
|
||||
codeGetDBList().then((res) => {
|
||||
const { dbList, defaultDb } = res.data;
|
||||
this.codeform.dbName = defaultDb;
|
||||
this.selectedDataBase = dbList;
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 加载页面table数据
|
||||
*/
|
||||
loadTableData() {
|
||||
if (this.codeform.dbName !== "") {
|
||||
this.tableloading = true;
|
||||
var seachdata = {
|
||||
pageNum: this.pagination.pageNum,
|
||||
PageSize: this.pagination.pagesize,
|
||||
tableName: this.codeform.tableName,
|
||||
dbName: this.codeform.dbName,
|
||||
};
|
||||
codeGetTableList(seachdata).then((res) => {
|
||||
this.tableData = res.data.result;
|
||||
this.pagination.pageTotal = res.data.totalNum;
|
||||
this.tableloading = false;
|
||||
});
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 点击查询
|
||||
*/
|
||||
handleSearch() {
|
||||
this.$refs["codeform"].validate((valid) => {
|
||||
if (valid) {
|
||||
this.tableloading = true;
|
||||
this.pagination.pageNum = 1;
|
||||
this.loadTableData();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
this.tableloading = true;
|
||||
|
||||
getGenTable(this.queryParams).then((res) => {
|
||||
this.tableData = res.data.result;
|
||||
this.total = res.data.totalCount;
|
||||
this.tableloading = false;
|
||||
});
|
||||
},
|
||||
handleShowTable() {
|
||||
this.pagination.pageNum = 1;
|
||||
this.loadTableData();
|
||||
/**
|
||||
* 编辑表格
|
||||
*/
|
||||
handleEditTable(row) {
|
||||
console.log(row);
|
||||
this.$router.push("/tool/editTable?tableId=" + row.tableId);
|
||||
},
|
||||
handlePreview() {
|
||||
this.msgError("敬请期待");
|
||||
@ -202,15 +160,6 @@ export default {
|
||||
this.showGenerate = true;
|
||||
this.currentSelected = row;
|
||||
|
||||
queryColumnInfo({
|
||||
dbName: this.codeform.dbName,
|
||||
tableName: row.name,
|
||||
}).then((res) => {
|
||||
if (res.code === 200) {
|
||||
const columnData = res.data;
|
||||
this.columnData = columnData;
|
||||
}
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 点击生成服务端代码
|
||||
@ -267,22 +216,26 @@ export default {
|
||||
/**
|
||||
* 选择每页显示数量
|
||||
*/
|
||||
handleSizeChange(val) {
|
||||
this.pagination.pagesize = val;
|
||||
this.pagination.pageNum = 1;
|
||||
this.loadTableData();
|
||||
},
|
||||
// handleSizeChange(val) {
|
||||
// this.pagination.pagesize = val;
|
||||
// this.pagination.pageNum = 1;
|
||||
// this.loadTableData();
|
||||
// },
|
||||
/**
|
||||
* 选择当页面
|
||||
*/
|
||||
handleCurrentChange(val) {
|
||||
this.pagination.pageNum = val;
|
||||
this.loadTableData();
|
||||
},
|
||||
// handleCurrentChange(val) {
|
||||
// this.pagination.pageNum = val;
|
||||
// this.loadTableData();
|
||||
// },
|
||||
cancel() {
|
||||
this.showGenerate = false;
|
||||
this.currentSelected = {};
|
||||
},
|
||||
// 导入代码生成
|
||||
openImportTable() {
|
||||
this.$refs.import.show();
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
79
ZRAdmin.xml
79
ZRAdmin.xml
@ -27,6 +27,47 @@
|
||||
<param name="data"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:ZR.Admin.WebApi.Controllers.GiftController">
|
||||
<summary>
|
||||
代码自动生成
|
||||
</summary>
|
||||
</member>
|
||||
<member name="F:ZR.Admin.WebApi.Controllers.GiftController._GiftService">
|
||||
<summary>
|
||||
接口
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:ZR.Admin.WebApi.Controllers.GiftController.QueryGift(ZR.Model.Dto.GiftQueryDto)">
|
||||
<summary>
|
||||
查询列表
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:ZR.Admin.WebApi.Controllers.GiftController.GetGift(System.Int32)">
|
||||
<summary>
|
||||
查询详情
|
||||
</summary>
|
||||
<param name="GiftId"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:ZR.Admin.WebApi.Controllers.GiftController.AddGift(ZR.Model.Dto.GiftDto)">
|
||||
<summary>
|
||||
添加
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:ZR.Admin.WebApi.Controllers.GiftController.UpdateGift(ZR.Model.Dto.GiftDto)">
|
||||
<summary>
|
||||
更新
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:ZR.Admin.WebApi.Controllers.GiftController.DeleteGift(System.Int32)">
|
||||
<summary>
|
||||
删除
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:ZR.Admin.WebApi.Controllers.CodeGeneratorController">
|
||||
<summary>
|
||||
代码生成
|
||||
@ -47,14 +88,6 @@
|
||||
<param name="pager">分页信息</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:ZR.Admin.WebApi.Controllers.CodeGeneratorController.QueryColumnInfo(System.String,System.String)">
|
||||
<summary>
|
||||
获取表格列
|
||||
</summary>
|
||||
<param name="dbName"></param>
|
||||
<param name="tableName"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:ZR.Admin.WebApi.Controllers.CodeGeneratorController.Generate(ZR.CodeGenerator.Model.GenerateDto)">
|
||||
<summary>
|
||||
代码生成器
|
||||
@ -62,6 +95,36 @@
|
||||
<param name="dto">数据传输对象</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:ZR.Admin.WebApi.Controllers.CodeGeneratorController.GetGenTable(System.String,ZR.Model.PagerInfo)">
|
||||
<summary>
|
||||
获取表详细信息
|
||||
</summary>
|
||||
<param name="tableName"></param>
|
||||
<param name="pagerInfo">分页信息</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:ZR.Admin.WebApi.Controllers.CodeGeneratorController.GetColumnList(System.Int64)">
|
||||
<summary>
|
||||
查询表字段列表
|
||||
</summary>
|
||||
<param name="tableId"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:ZR.Admin.WebApi.Controllers.CodeGeneratorController.Remove(System.String)">
|
||||
<summary>
|
||||
代码生成删除
|
||||
</summary>
|
||||
<param name="tableIds"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:ZR.Admin.WebApi.Controllers.CodeGeneratorController.ImportTableSave(System.String,System.String)">
|
||||
<summary>
|
||||
导入表
|
||||
</summary>
|
||||
<param name="tables"></param>
|
||||
<param name="dbName"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:ZR.Admin.WebApi.Controllers.HomeController.Health">
|
||||
<summary>
|
||||
心跳
|
||||
|
||||
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user