优化代码生成api
This commit is contained in:
parent
57f5437920
commit
3037718786
@ -4,7 +4,6 @@ using Infrastructure.Enums;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Newtonsoft.Json;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
@ -19,7 +18,6 @@ using ZR.Common;
|
||||
using ZR.Model;
|
||||
using ZR.Model.System.Dto;
|
||||
using ZR.Model.System.Generate;
|
||||
using ZR.Service;
|
||||
using ZR.Service.System.IService;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers
|
||||
@ -31,20 +29,18 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
[Route("tool/gen")]
|
||||
public class CodeGeneratorController : BaseController
|
||||
{
|
||||
private CodeGeneraterService _CodeGeneraterService = new CodeGeneraterService();
|
||||
private IGenTableService GenTableService;
|
||||
private IGenTableColumnService GenTableColumnService;
|
||||
private readonly ISysDictDataService SysDictDataService;
|
||||
private IWebHostEnvironment WebHostEnvironment;
|
||||
private readonly CodeGeneraterService _CodeGeneraterService = new CodeGeneraterService();
|
||||
private readonly IGenTableService GenTableService;
|
||||
private readonly IGenTableColumnService GenTableColumnService;
|
||||
|
||||
private readonly IWebHostEnvironment WebHostEnvironment;
|
||||
public CodeGeneratorController(
|
||||
IGenTableService genTableService,
|
||||
IGenTableColumnService genTableColumnService,
|
||||
ISysDictDataService dictDataService,
|
||||
IWebHostEnvironment webHostEnvironment)
|
||||
{
|
||||
GenTableService = genTableService;
|
||||
GenTableColumnService = genTableColumnService;
|
||||
SysDictDataService = dictDataService;
|
||||
WebHostEnvironment = webHostEnvironment;
|
||||
}
|
||||
|
||||
@ -62,7 +58,7 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///获取所有表根据数据名
|
||||
///获取所有表根据数据库名
|
||||
/// </summary>
|
||||
/// <param name="dbName">数据库名</param>
|
||||
/// <param name="tableName">表名</param>
|
||||
@ -78,12 +74,13 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取代码生成表列表
|
||||
/// 查询生成表数据
|
||||
/// </summary>
|
||||
/// <param name="tableName">表名</param>
|
||||
/// <param name="pagerInfo">分页信息</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("listGenTable")]
|
||||
[HttpGet("list")]
|
||||
[ActionPermissionFilter(Permission = "tool:gen:list")]
|
||||
public IActionResult GetGenTable(string tableName, PagerInfo pagerInfo)
|
||||
{
|
||||
//查询原表数据,部分字段映射到代码生成表字段
|
||||
@ -93,18 +90,34 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询表字段列表
|
||||
/// 修改代码生成业务查询
|
||||
/// </summary>
|
||||
/// <param name="tableId">genTable表id</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("column/{tableId}")]
|
||||
[HttpGet("{tableId}")]
|
||||
[ActionPermissionFilter(Permission = "tool:gen:query")]
|
||||
public IActionResult GetColumnList(long tableId)
|
||||
{
|
||||
var tableColumns = GenTableColumnService.GenTableColumns(tableId);
|
||||
var tableInfo = GenTableService.GetGenTableInfo(tableId);
|
||||
return SUCCESS(new { cloumns = tableColumns, info = tableInfo });
|
||||
var tables = GenTableService.GetGenTableAll();
|
||||
|
||||
return SUCCESS(new { columns = tableColumns, info = tableInfo, tables });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据表id查询表列
|
||||
/// </summary>
|
||||
/// <param name="tableId">genTable表id</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("column/{tableId}")]
|
||||
[ActionPermissionFilter(Permission = "tool:gen:query")]
|
||||
public IActionResult GetTableColumnList(long tableId)
|
||||
{
|
||||
var tableColumns = GenTableColumnService.GenTableColumns(tableId);
|
||||
|
||||
return SUCCESS(new { columns = tableColumns });
|
||||
}
|
||||
/// <summary>
|
||||
/// 删除代码生成
|
||||
/// </summary>
|
||||
|
||||
@ -25,7 +25,7 @@ namespace ZR.Model.System.Generate
|
||||
/// <summary>
|
||||
/// 列说明
|
||||
/// </summary>
|
||||
public string ColumnComment { get; set; }
|
||||
public string ColumnComment { get; set; } = string.Empty;
|
||||
/// <summary>
|
||||
/// 数据库列类型
|
||||
/// </summary>
|
||||
|
||||
@ -60,6 +60,15 @@ namespace ZR.Service.System
|
||||
return info;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有代码生成表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<GenTable> GetGenTableAll()
|
||||
{
|
||||
return GenTableRepository.GetAll();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置代码生成其他参数
|
||||
/// </summary>
|
||||
|
||||
@ -14,6 +14,7 @@ namespace ZR.Service.System.IService
|
||||
int DeleteGenTableByTbName(string tableName);
|
||||
PagedInfo<GenTable> GetGenTables(GenTable genTable, Model.PagerInfo pagerInfo);
|
||||
GenTable GetGenTableInfo(long tableId);
|
||||
List<GenTable> GetGenTableAll();
|
||||
int UpdateGenTable(GenTable genTable);
|
||||
}
|
||||
|
||||
|
||||
@ -21,7 +21,7 @@
|
||||
"dependencies": {
|
||||
"@riophae/vue-treeselect": "0.4.0",
|
||||
"axios": "^0.21.4",
|
||||
"clipboard": "2.0.4",
|
||||
"clipboard": "2.0.8",
|
||||
"core-js": "3.6.5",
|
||||
"echarts": "^5.1.1",
|
||||
"element-ui": "2.15.6",
|
||||
|
||||
@ -60,15 +60,23 @@ export function queryColumnInfo(tableId) {
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// 查询表详细信息
|
||||
export function getGenTable(params) {
|
||||
// 查询生成表数据
|
||||
export function listTable(params) {
|
||||
return request({
|
||||
url: 'tool/gen/listGenTable',
|
||||
url: 'tool/gen/list',
|
||||
method: 'get',
|
||||
params: params
|
||||
})
|
||||
}
|
||||
|
||||
// 查询表详细信息
|
||||
export function getGenTable(tableId) {
|
||||
return request({
|
||||
url: '/tool/gen/' + tableId,
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
|
||||
// 导入表
|
||||
export function importTable(data) {
|
||||
return request({
|
||||
@ -102,25 +110,3 @@ export function previewTable(tableId, data) {
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
// /**
|
||||
// *
|
||||
// * 数据库解密
|
||||
// */
|
||||
// export function dbtoolsConnStrDecrypt(data) {
|
||||
// return request({
|
||||
// url: 'DbTools/ConnStrDecrypt',
|
||||
// method: 'post',
|
||||
// params: data,
|
||||
// })
|
||||
// }
|
||||
// /**
|
||||
// * 数据库加密
|
||||
// */
|
||||
// export function dbtoolsConnStrEncrypt(data) {
|
||||
// return request({
|
||||
// url: 'DbTools/ConnStrEncrypt',
|
||||
// method: 'post',
|
||||
// params: data,
|
||||
// })
|
||||
// }
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<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 ref="dragTable" :data="columns" 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%">
|
||||
@ -101,7 +101,7 @@
|
||||
</el-table>
|
||||
</el-tab-pane>
|
||||
<el-tab-pane label="生成信息" name="genInfo">
|
||||
<gen-info-form ref="genInfo" :info="info" :tables="tables" :menus="menus" :columns="cloumns" />
|
||||
<gen-info-form ref="genInfo" :info="info" :tables="tables" :menus="menus" :columns="columns" />
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
<el-form label-width="100px">
|
||||
@ -114,7 +114,7 @@
|
||||
</el-card>
|
||||
</template>
|
||||
<script>
|
||||
import { updateGenTable, queryColumnInfo } from "@/api/tool/gen";
|
||||
import { updateGenTable, getGenTable } from "@/api/tool/gen";
|
||||
import { listType } from "@/api/system/dict/type";
|
||||
import { listMenu as getMenuTreeselect } from "@/api/system/menu";
|
||||
import basicInfoForm from "./basicInfoForm";
|
||||
@ -136,7 +136,7 @@ export default {
|
||||
// 表信息
|
||||
tables: [],
|
||||
// 表列信息
|
||||
cloumns: [],
|
||||
columns: [],
|
||||
// 字典信息
|
||||
dictOptions: [],
|
||||
// 菜单信息
|
||||
@ -154,10 +154,10 @@ export default {
|
||||
|
||||
if (tableId) {
|
||||
// 获取表详细信息
|
||||
queryColumnInfo(tableId).then((res) => {
|
||||
this.cloumns = res.data.cloumns;
|
||||
getGenTable(tableId).then((res) => {
|
||||
this.columns = res.data.columns;
|
||||
this.info = res.data.info;
|
||||
// this.tables = res.data.tables;/子表
|
||||
this.tables = res.data.tables;//子表
|
||||
});
|
||||
/** 查询字典下拉列表 */
|
||||
listType().then((response) => {
|
||||
@ -177,7 +177,7 @@ export default {
|
||||
const validateResult = res.every((item) => !!item);
|
||||
if (validateResult) {
|
||||
const genTable = Object.assign({}, basicForm.model, genForm.model);
|
||||
genTable.columns = this.cloumns;
|
||||
genTable.columns = this.columns;
|
||||
genTable.params = {
|
||||
// treeCode: genTable.treeCode,
|
||||
// treeName: genTable.treeName,
|
||||
@ -217,7 +217,7 @@ export default {
|
||||
const sortable = Sortable.create(el, {
|
||||
handle: ".allowDrag",
|
||||
onEnd: (evt) => {
|
||||
const targetRow = that.cloumns.splice(evt.oldIndex, 1)[0];
|
||||
const targetRow = that.columns.splice(evt.oldIndex, 1)[0];
|
||||
columns.splice(evt.newIndex, 0, targetRow);
|
||||
for (let index in columns) {
|
||||
columns[index].sort = parseInt(index) + 1;
|
||||
@ -230,7 +230,7 @@ export default {
|
||||
},
|
||||
},
|
||||
watch: {
|
||||
cloumns: {
|
||||
columns: {
|
||||
handler(val) {
|
||||
this.sortTable(val);
|
||||
},
|
||||
|
||||
@ -7,7 +7,8 @@
|
||||
<el-select v-model="info.tplCategory" @change="tplSelectChange">
|
||||
<el-option label="单表(增删改查)" value="crud" />
|
||||
<!-- <el-option label="树表(增删改查)" value="tree" />
|
||||
<el-option label="主子表(增删改查)" value="sub" /> -->
|
||||
<el-option label="导航查询" value="subNav"></el-option> -->
|
||||
<!-- <el-option label="主子表(增删改查)" value="sub" /> -->
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
@ -179,7 +180,7 @@
|
||||
<i class="el-icon-question"></i>
|
||||
</el-tooltip>
|
||||
</span>
|
||||
<el-select v-model="info.subTableName" placeholder="请选择" @change="subSelectChange">
|
||||
<el-select v-model="info.subTableName" placeholder="请选择" @change="subSelectChange(this)">
|
||||
<el-option v-for="(table, index) in tables" :key="index" :label="table.tableName + ':' + table.tableComment" :value="table.tableName">
|
||||
</el-option>
|
||||
</el-select>
|
||||
@ -203,6 +204,7 @@
|
||||
</el-form>
|
||||
</template>
|
||||
<script>
|
||||
import { queryColumnInfo } from "@/api/tool/gen";
|
||||
import Treeselect from "@riophae/vue-treeselect";
|
||||
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
|
||||
|
||||
@ -214,7 +216,7 @@ export default {
|
||||
type: Object,
|
||||
default: null,
|
||||
},
|
||||
// 字表
|
||||
// 子表
|
||||
tables: {
|
||||
type: Array,
|
||||
default: null,
|
||||
@ -237,10 +239,20 @@ export default {
|
||||
{ required: true, message: "请选择生成模板", trigger: "blur" },
|
||||
],
|
||||
moduleName: [
|
||||
{ required: true, message: "请输入生成模块名", trigger: "blur", pattern:/^[A-Za-z]+$/ },
|
||||
{
|
||||
required: true,
|
||||
message: "请输入生成模块名",
|
||||
trigger: "blur",
|
||||
pattern: /^[A-Za-z]+$/,
|
||||
},
|
||||
],
|
||||
businessName: [
|
||||
{ required: true, message: "请输入生成业务名", trigger: "blur", pattern:/^[A-Za-z]+$/},
|
||||
{
|
||||
required: true,
|
||||
message: "请输入生成业务名",
|
||||
trigger: "blur",
|
||||
pattern: /^[A-Za-z]+$/,
|
||||
},
|
||||
],
|
||||
functionName: [
|
||||
{ required: true, message: "请输入生成功能名", trigger: "blur" },
|
||||
@ -281,10 +293,18 @@ export default {
|
||||
},
|
||||
/** 设置关联外键 */
|
||||
setSubTableColumns(value) {
|
||||
console.log(value);
|
||||
if (value == null || value == undefined || value == "") {
|
||||
return;
|
||||
}
|
||||
for (var item in this.tables) {
|
||||
const name = this.tables[item].tableName;
|
||||
if (value === name) {
|
||||
this.subColumns = this.tables[item].columns;
|
||||
const obj = this.tables[item];
|
||||
if (value === obj.tableName) {
|
||||
queryColumnInfo(obj.tableId).then((res) => {
|
||||
if (res.code == 200) {
|
||||
this.subColumns = res.data.columns;
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user