多表查询前端完成
This commit is contained in:
parent
da30366a02
commit
aaf933d5ca
|
|
@ -0,0 +1,55 @@
|
|||
import request from "@/utils/request";
|
||||
|
||||
/**
|
||||
* 获取到gen_rel_table表的自增字段
|
||||
* @returns
|
||||
*/
|
||||
export function getRelId(){
|
||||
return request({
|
||||
url:'/seq/next/gen_rel_table',
|
||||
method:'get',
|
||||
})
|
||||
}
|
||||
/**
|
||||
* 获取关联表表的字段信息
|
||||
* @param tableName 关联表表名
|
||||
* @param relId 关联表id
|
||||
* @returns
|
||||
*/
|
||||
export function getRelColumns(tableName,relId){
|
||||
return request({
|
||||
url: '/rel/'+tableName+'/'+relId,
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
/**
|
||||
* 获取表信息
|
||||
* @returns
|
||||
*/
|
||||
export function getTableInfos() {
|
||||
return request({
|
||||
url: '/rel/tableinfo',
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取表字段信息
|
||||
* @returns
|
||||
*/
|
||||
export function getTableColumns(tableName) {
|
||||
return request({
|
||||
url: '/rel/'+tableName,
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
/**
|
||||
* 获取子表所以信息(基本信息 字段信息)
|
||||
* @returns
|
||||
*/
|
||||
export function getRelColumnInfos(tableId) {
|
||||
return request({
|
||||
url: '/rel/colums/'+tableId,
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
|
|
@ -141,6 +141,7 @@ import basicInfoForm from "./basicInfoForm";
|
|||
import genInfoForm from "./genInfoForm";
|
||||
import Sortable from 'sortablejs'
|
||||
import {listRegular} from "../../../api/tool/regular";
|
||||
import {Message} from "element-ui";
|
||||
|
||||
export default {
|
||||
name: "GenEdit",
|
||||
|
|
@ -151,7 +152,8 @@ export default {
|
|||
data() {
|
||||
return {
|
||||
// 选中选项卡的 name
|
||||
activeName: "cloum",
|
||||
// activeName: "cloum",
|
||||
activeName: "genInfo",
|
||||
// 表格的高度
|
||||
tableHeight: document.documentElement.scrollHeight - 245 + "px",
|
||||
// 表信息
|
||||
|
|
@ -204,7 +206,39 @@ export default {
|
|||
submitForm() {
|
||||
const basicForm = this.$refs.basicInfo.$refs.basicInfoForm;
|
||||
const genForm = this.$refs.genInfo.$refs.genInfoForm;
|
||||
const assCloumnTable = this.$refs.genInfo.$refs.assCloumnTable
|
||||
const assCloumnTable = this.$refs.genInfo.$refs.assCloumnTable;
|
||||
const relTables = this.$refs.genInfo.relTables;
|
||||
console.log(relTables)
|
||||
for (let i=0;i<relTables.length;i++){
|
||||
if (relTables[i].unionId===null){
|
||||
Message({
|
||||
message: "关联父表不能为空!",
|
||||
type: 'error'
|
||||
})
|
||||
return
|
||||
}
|
||||
if (relTables[i].tableColumn===null){
|
||||
Message({
|
||||
message: "关联父表字段不能为空!",
|
||||
type: 'error'
|
||||
})
|
||||
return
|
||||
}
|
||||
if (relTables[i].relName===null){
|
||||
Message({
|
||||
message: "关联子表不能为空!",
|
||||
type: 'error'
|
||||
})
|
||||
return
|
||||
}
|
||||
if (relTables[i].relColumn===null){
|
||||
Message({
|
||||
message: "关联子表字段不能为空!",
|
||||
type: 'error'
|
||||
})
|
||||
return
|
||||
}
|
||||
}
|
||||
let assColumns = null;
|
||||
if (assCloumnTable!=undefined){
|
||||
assColumns = assCloumnTable.data
|
||||
|
|
@ -215,6 +249,7 @@ export default {
|
|||
const genTable = Object.assign({}, basicForm.model, genForm.model);
|
||||
genTable.columns = this.cloumns;
|
||||
genTable.assColumns = assColumns;
|
||||
genTable.relTables = relTables
|
||||
genTable.params = {
|
||||
treeCode: genTable.treeCode,
|
||||
treeName: genTable.treeName,
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
<el-select v-model="info.tplCategory" @change="tplSelectChange">
|
||||
<el-option label="单表(增删改查)" value="crud"/>
|
||||
<el-option label="树表(增删改查)" value="tree"/>
|
||||
<el-option label="多表关联(增删改查)" value="rel"/>
|
||||
<el-option label="关联表(增删改查)" value="ass"/>
|
||||
<el-option label="主子表(增删改查)" value="sub"/>
|
||||
</el-select>
|
||||
|
|
@ -115,7 +116,7 @@
|
|||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<!--树表配置-->
|
||||
<el-row v-show="info.tplCategory == 'tree'">
|
||||
<h4 class="form-header">其他信息</h4>
|
||||
<el-col :span="12">
|
||||
|
|
@ -173,7 +174,7 @@
|
|||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<!--主子表配置-->
|
||||
<el-row v-show="info.tplCategory == 'sub'">
|
||||
<h4 class="form-header">关联信息</h4>
|
||||
<el-col :span="12">
|
||||
|
|
@ -213,6 +214,7 @@
|
|||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<!--关联查询-->
|
||||
<div v-if="info.tplCategory == 'ass'">
|
||||
<el-row>
|
||||
<h4 class="form-header">关联关系</h4>
|
||||
|
|
@ -284,7 +286,7 @@
|
|||
</el-col>
|
||||
</el-row>
|
||||
<el-table ref="assCloumnTable" :data="assCloumns" row-key="columnId" :max-height="tableHeight">
|
||||
<el-table-column label="序号" type="index" min-width="5%" class-name="allowDrag" />
|
||||
<el-table-column label="序号" type="index" min-width="5%" class-name="allowDrag"/>
|
||||
<el-table-column
|
||||
label="字段列名"
|
||||
prop="columnName"
|
||||
|
|
@ -305,12 +307,12 @@
|
|||
<el-table-column label="Java类型" min-width="11%">
|
||||
<template slot-scope="scope">
|
||||
<el-select v-model="scope.row.javaType">
|
||||
<el-option label="Long" value="Long" />
|
||||
<el-option label="String" value="String" />
|
||||
<el-option label="Integer" value="Integer" />
|
||||
<el-option label="Double" value="Double" />
|
||||
<el-option label="BigDecimal" value="BigDecimal" />
|
||||
<el-option label="Date" value="Date" />
|
||||
<el-option label="Long" value="Long"/>
|
||||
<el-option label="String" value="String"/>
|
||||
<el-option label="Integer" value="Integer"/>
|
||||
<el-option label="Double" value="Double"/>
|
||||
<el-option label="BigDecimal" value="BigDecimal"/>
|
||||
<el-option label="Date" value="Date"/>
|
||||
</el-select>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
|
@ -332,25 +334,25 @@
|
|||
<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-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="12%">
|
||||
<template slot-scope="scope">
|
||||
<el-select v-model="scope.row.htmlType">
|
||||
<el-option label="文本框" value="input" />
|
||||
<el-option label="下拉框" value="select" />
|
||||
<el-option label="单选框" value="radio" />
|
||||
<el-option label="复选框" value="checkbox" />
|
||||
<el-option label="日期控件" value="datetime" />
|
||||
<el-option label="文本框" value="input"/>
|
||||
<el-option label="下拉框" value="select"/>
|
||||
<el-option label="单选框" value="radio"/>
|
||||
<el-option label="复选框" value="checkbox"/>
|
||||
<el-option label="日期控件" value="datetime"/>
|
||||
</el-select>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
|
@ -370,12 +372,218 @@
|
|||
</el-table-column>
|
||||
</el-table>
|
||||
</div>
|
||||
<!--多表关联配置-->
|
||||
<div v-if="info.tplCategory == 'rel'">
|
||||
<el-row class="form-header">
|
||||
<el-col :span="4">
|
||||
<div style="font-size: 15px;color:#6379bb;font-weight: bold;">多表关联关系</div>
|
||||
</el-col>
|
||||
<el-col :offset="18" :span="2">
|
||||
<el-button
|
||||
clearable
|
||||
@click="addRelTable"
|
||||
>添加表
|
||||
</el-button>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<div v-for="(table,index) in relTables">
|
||||
<el-row>
|
||||
<el-col :span="4">
|
||||
<el-form-item label-width="95px">
|
||||
<span slot="label">
|
||||
关联父表
|
||||
<el-tooltip content="父表名称, 如:sys_table" placement="top">
|
||||
<i class="el-icon-question"></i>
|
||||
</el-tooltip>
|
||||
</span>
|
||||
<el-select v-model="table.tableIndex" @change="tableChange(table.tableIndex,index)"
|
||||
placeholder="请选择关联主表">
|
||||
<el-option
|
||||
v-for="(item , num) in tableList"
|
||||
:key="num"
|
||||
:label="item.tableName"
|
||||
:value="num"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="4">
|
||||
<el-form-item label-width="80px">
|
||||
<span slot="label">
|
||||
父表id
|
||||
<el-tooltip content="父表id, 如:table_id" placement="top">
|
||||
<i class="el-icon-question"></i>
|
||||
</el-tooltip>
|
||||
</span>
|
||||
<el-select v-model="table.tableColumn" placeholder="请选择字段">
|
||||
<el-option
|
||||
v-for="(column , index) in table.tableColumns"
|
||||
:key="index"
|
||||
:label="column.column_name+':'+column.column_comment"
|
||||
:value="column.column_name"/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="4">
|
||||
<el-form-item label-width="110px">
|
||||
<span slot="label">
|
||||
关联表表名
|
||||
<el-tooltip content="关联子表的表名, 如:sys_user" placement="top">
|
||||
<i class="el-icon-question"></i>
|
||||
</el-tooltip>
|
||||
</span>
|
||||
<el-select v-model="table.relName" @change="relNameChang(index,table.relName)" placeholder="请选择表名">
|
||||
<el-option
|
||||
v-for="(table , index) in tableInfo"
|
||||
:key="index"
|
||||
:label="table.table_name + ':'+table.table_comment"
|
||||
:value="table.table_name"/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="4">
|
||||
<el-form-item label-width="110px">
|
||||
<span slot="label">
|
||||
关联表字段
|
||||
<el-tooltip content="关联子表的关联字段, 如:user_id" placement="top">
|
||||
<i class="el-icon-question"></i>
|
||||
</el-tooltip>
|
||||
</span>
|
||||
<el-select v-model="table.relColumn" placeholder="请选择表名">
|
||||
<el-option
|
||||
v-for="(cloumn , index) in table.relColumns"
|
||||
:key="index"
|
||||
:label="cloumn.columnName + ':'+cloumn.columnComment"
|
||||
:value="cloumn.columnName"/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="4">
|
||||
<el-form-item label-width="125px">
|
||||
<span slot="label">
|
||||
关联查询方式
|
||||
<el-tooltip content="关联子表的查询方式, 如:inner join" placement="top">
|
||||
<i class="el-icon-question"></i>
|
||||
</el-tooltip>
|
||||
</span>
|
||||
<el-select v-model="table.queryType" placeholder="请选择查询方式">
|
||||
<el-option label="inner join" value="inner"/>
|
||||
<el-option label="left join" value="left"/>
|
||||
<el-option label="right join" value="right"/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="3">
|
||||
<el-form-item label-width="20px">
|
||||
<div style="margin-right: 20px">
|
||||
<el-select v-model="table.sort" placeholder="请选择关联查询级别">
|
||||
<el-option label="一级关联" :value="1"/>
|
||||
<el-option label="二级关联" :value="2"/>
|
||||
<el-option label="三级关联" :value="3"/>
|
||||
<el-option label="四级关联" :value="4"/>
|
||||
</el-select>
|
||||
</div>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="1">
|
||||
<el-button @click="removeRelTable(index)">删除</el-button>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-table :ref="'relColumns'+index" :data="table.relColumns" 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="Java类型" min-width="11%">
|
||||
<template slot-scope="scope">
|
||||
<el-select v-model="scope.row.javaType">
|
||||
<el-option label="Long" value="Long"/>
|
||||
<el-option label="String" value="String"/>
|
||||
<el-option label="Integer" value="Integer"/>
|
||||
<el-option label="Double" value="Double"/>
|
||||
<el-option label="BigDecimal" value="BigDecimal"/>
|
||||
<el-option label="Date" value="Date"/>
|
||||
</el-select>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="java属性" min-width="10%">
|
||||
<template slot-scope="scope">
|
||||
<el-input v-model="scope.row.javaField"></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.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="12%">
|
||||
<template slot-scope="scope">
|
||||
<el-select v-model="scope.row.htmlType">
|
||||
<el-option label="文本框" value="input"/>
|
||||
<el-option label="下拉框" value="select"/>
|
||||
<el-option label="单选框" value="radio"/>
|
||||
<el-option label="复选框" value="checkbox"/>
|
||||
<el-option label="日期控件" value="datetime"/>
|
||||
</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>
|
||||
</div>
|
||||
</div>
|
||||
</el-form>
|
||||
</template>
|
||||
<script>
|
||||
import Treeselect from "@riophae/vue-treeselect";
|
||||
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
|
||||
import {getTableInfos, getAssColumns,getAssColumnsByTableId} from "@/api/tool/associated"
|
||||
import {getAssColumns, getAssColumnsByTableId} from "@/api/tool/associated"
|
||||
import {getRelId, getRelColumns, getTableInfos, getTableColumns, getRelColumnInfos} from '@/api/tool/relApi'
|
||||
|
||||
export default {
|
||||
name: "BasicInfoForm",
|
||||
|
|
@ -393,9 +601,9 @@ export default {
|
|||
type: Array,
|
||||
default: []
|
||||
},
|
||||
dictOptions:{
|
||||
type:Array,
|
||||
default:[]
|
||||
dictOptions: {
|
||||
type: Array,
|
||||
default: []
|
||||
}
|
||||
},
|
||||
data() {
|
||||
|
|
@ -403,8 +611,11 @@ export default {
|
|||
subColumns: [],
|
||||
// 表格的高度
|
||||
tableHeight: document.documentElement.scrollHeight - 245 + "px",
|
||||
assCloumns:[],
|
||||
assCloumns: [],
|
||||
tableId: null,
|
||||
relTables: [],
|
||||
tableInfo: [],
|
||||
tableList: [],
|
||||
rules: {
|
||||
tplCategory: [
|
||||
{required: true, message: "请选择生成模板", trigger: "blur"}
|
||||
|
|
@ -419,34 +630,132 @@ export default {
|
|||
{required: true, message: "请输入生成业务名", trigger: "blur"}
|
||||
],
|
||||
functionName: [
|
||||
{required: true, message: "请输入生成功能名", trigger: "blur"}
|
||||
{required: false, message: "请输入生成功能名", trigger: "blur"}
|
||||
],
|
||||
}
|
||||
};
|
||||
},
|
||||
created() {
|
||||
const tableId = this.$route.params && this.$route.params.tableId;
|
||||
this.tableId = this.$route.params && this.$route.params.tableId;
|
||||
getTableInfos().then(res => {
|
||||
this.tableInfo = res.data
|
||||
})
|
||||
getAssColumnsByTableId(tableId).then(res => {
|
||||
this.assCloumns = res.data
|
||||
})
|
||||
},
|
||||
watch: {
|
||||
'info.subTableName': function (val) {
|
||||
this.setSubTableColumns(val);
|
||||
},
|
||||
'info': function (val) {
|
||||
if (val.tplCategory === 'ass') {
|
||||
getAssColumnsByTableId(this.tableId).then(res => {
|
||||
this.assCloumns = res.data
|
||||
})
|
||||
} else if (val.tplCategory === 'rel') {
|
||||
this.tableList = []
|
||||
let table = {
|
||||
tableName: val.tableName,
|
||||
unionId: this.tableId,
|
||||
isMain: 1,
|
||||
}
|
||||
this.tableList.push(table)
|
||||
getRelColumnInfos(val.tableId).then(res => {
|
||||
this.relTables = []
|
||||
if (res.data.length === 0) {
|
||||
getRelId().then(res => {
|
||||
let relTable = {
|
||||
id: res.data,
|
||||
unionId: null,
|
||||
tableId: this.tableId,
|
||||
isMain: 2,
|
||||
relName: null,
|
||||
relComment: null,
|
||||
relColumn: null,
|
||||
tableColumn: null,
|
||||
queryType: 'left',
|
||||
sort: 1,
|
||||
tableColumns: [],
|
||||
relColumns: [],
|
||||
}
|
||||
this.relTables.push(relTable);
|
||||
})
|
||||
} else {
|
||||
let data = res.data
|
||||
for (let i=0;i<data.length;i++){
|
||||
let table = {
|
||||
tableName: data[i].relName,
|
||||
unionId: data[i].id,
|
||||
isMain: 1,
|
||||
}
|
||||
this.tableList.push(table)
|
||||
}
|
||||
this.relTables=res.data
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
/** 关联父表改变 */
|
||||
tableChange(num, index) {
|
||||
this.relTables[index].unionId = this.tableList[num].unionId
|
||||
this.relTables[index].isMain = this.tableList[num].isMain
|
||||
let tableName = this.tableList[num].tableName
|
||||
getTableColumns(tableName).then(res => {
|
||||
this.relTables[index].tableColumns = res.data
|
||||
})
|
||||
console.log(this.relTables)
|
||||
},
|
||||
/** 删除关子联表 */
|
||||
removeRelTable(index) {
|
||||
this.tableList.splice(index + 1, 1)
|
||||
this.relTables.splice(index, 1)
|
||||
},
|
||||
/** 关联子表改变 */
|
||||
relNameChang(index, relName) {
|
||||
getRelColumns(relName, this.relTables[index].id).then(res => {
|
||||
let table = {
|
||||
tableName: relName,
|
||||
unionId: this.relTables[index].id,
|
||||
isMain: 2,
|
||||
}
|
||||
this.tableList.push(table)
|
||||
for (let i = 0; i < this.tableInfo.length; i++) {
|
||||
if (this.tableInfo[i].table_name === relName){
|
||||
this.relTables[index].relComment = this.tableInfo[i].table_comment
|
||||
break
|
||||
}
|
||||
}
|
||||
this.relTables[index].relColumns = res.data
|
||||
})
|
||||
},
|
||||
/** 添加关联表 */
|
||||
addRelTable() {
|
||||
getRelId().then(res => {
|
||||
let relTable = {
|
||||
id: res.data,
|
||||
unionId: this.tableId,
|
||||
tableId: this.tableId,
|
||||
isMain: 1,
|
||||
tableIndex: null,
|
||||
relName: null,
|
||||
relComment: null,
|
||||
relColumn: null,
|
||||
tableColumn: null,
|
||||
queryType: 'left',
|
||||
sort: 1,
|
||||
tableColumns: [],
|
||||
relColumns: [],
|
||||
}
|
||||
this.relTables.push(relTable)
|
||||
})
|
||||
},
|
||||
/** 关联表该表 */
|
||||
assSelectChang() {
|
||||
getAssColumns(this.info.assTableName, this.info.tableId).then(res => {
|
||||
this.assCloumns = res.data
|
||||
})
|
||||
},
|
||||
|
||||
/** 转换菜单数据结构 */
|
||||
normalizer(node) {
|
||||
if (node.children && !node.children.length) {
|
||||
|
|
@ -482,3 +791,8 @@ export default {
|
|||
}
|
||||
};
|
||||
</script>
|
||||
<style scoped>
|
||||
.el-table {
|
||||
margin-bottom: 22px;
|
||||
}
|
||||
</style>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,36 @@
|
|||
package com.hchyun.web.controller.system;
|
||||
|
||||
import com.hchyun.common.core.entity.AjaxResult;
|
||||
import com.hchyun.system.service.SequenceService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @Author 18209
|
||||
* @Date 2021/2/24 17:52
|
||||
* @Version 1.0
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/seq")
|
||||
public class SequenceController {
|
||||
|
||||
@Autowired
|
||||
private SequenceService sequenceService;
|
||||
|
||||
@PreAuthorize("@hchyun.hasPermi('sequence:curr')")
|
||||
@GetMapping("/curr/{tableName}")
|
||||
public AjaxResult currval(@PathVariable String tableName){
|
||||
return AjaxResult.success(sequenceService.currval(tableName));
|
||||
}
|
||||
|
||||
@PreAuthorize("@hchyun.hasPermi('sequence:next')")
|
||||
@GetMapping("/next/{tableName}")
|
||||
public AjaxResult nextval(@PathVariable String tableName){
|
||||
return AjaxResult.success(sequenceService.nextval(tableName));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,106 @@
|
|||
package com.hchyun.generator.controller;
|
||||
|
||||
import com.hchyun.generator.entity.RelColumn;
|
||||
import com.hchyun.generator.entity.RelTable;
|
||||
import com.hchyun.generator.service.RelService;
|
||||
import com.hchyun.generator.utils.GenServerResult;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author 18209
|
||||
* @Date 2021/2/24 16:22
|
||||
* @Version 1.0
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/rel")
|
||||
public class RelController {
|
||||
private Logger logger = LoggerFactory.getLogger(RelController.class);
|
||||
@Autowired
|
||||
private RelService relService;
|
||||
|
||||
/**
|
||||
* 获取表的基础信息
|
||||
* @return
|
||||
*/
|
||||
@PreAuthorize("@hchyun.hasAnyPermi('rel:tableinfo')")
|
||||
@GetMapping("/tableinfo")
|
||||
public AjaxResult tableinfos(){
|
||||
try {
|
||||
GenServerResult<List<Map<String,Object>>> genServerResult = relService.tableInfos();
|
||||
if (genServerResult.isStart()){
|
||||
return AjaxResult.success(genServerResult.getData());
|
||||
}else {
|
||||
return AjaxResult.error(genServerResult.getMsg());
|
||||
}
|
||||
}catch (RuntimeException e){
|
||||
logger.error(e.getMessage());
|
||||
return AjaxResult.error();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取表的字段信息
|
||||
* @param tableName
|
||||
* @param relId
|
||||
* @return
|
||||
*/
|
||||
@PreAuthorize("@hchyun.hasAnyPermi('rel:tableinfo')")
|
||||
@GetMapping("/{tableName}/{relId}")
|
||||
public AjaxResult relColumns(@PathVariable("tableName") String tableName, @PathVariable("relId") Long relId){
|
||||
try {
|
||||
GenServerResult<List<RelColumn>> genServerResult = relService.relColumns(tableName,relId);
|
||||
if (genServerResult.isStart()){
|
||||
return AjaxResult.success(genServerResult.getData());
|
||||
}else {
|
||||
return AjaxResult.error(genServerResult.getMsg());
|
||||
}
|
||||
}catch (RuntimeException e){
|
||||
logger.error(e.getMessage());
|
||||
return AjaxResult.error();
|
||||
}
|
||||
}
|
||||
|
||||
@PreAuthorize("@hchyun.hasAnyPermi('rel:colums')")
|
||||
@GetMapping("/{tableName}")
|
||||
public AjaxResult tableColumns(@PathVariable("tableName")String tableName){
|
||||
try {
|
||||
GenServerResult<List<Map<String,Object>>> genServerResult = relService.tableColumns(tableName);
|
||||
if (genServerResult.isStart()){
|
||||
return AjaxResult.success(genServerResult.getData());
|
||||
}else {
|
||||
return AjaxResult.error(genServerResult.getMsg());
|
||||
}
|
||||
}catch (RuntimeException e){
|
||||
logger.error(e.getMessage());
|
||||
return AjaxResult.error();
|
||||
}
|
||||
}
|
||||
|
||||
@PreAuthorize("@hchyun.hasAnyPermi('rel:colums')")
|
||||
@GetMapping("/colums/{tableId}")
|
||||
public AjaxResult relTableByTableId(@PathVariable("tableId")Long tableId){
|
||||
try {
|
||||
GenServerResult<List<RelTable>> genServerResult = relService.relTableByTableId(tableId);
|
||||
if (genServerResult.isStart()){
|
||||
return AjaxResult.success(genServerResult.getData());
|
||||
}else {
|
||||
return AjaxResult.error(genServerResult.getMsg());
|
||||
}
|
||||
}catch (RuntimeException e){
|
||||
logger.error(e.getMessage());
|
||||
return AjaxResult.error();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
package com.hchyun.generator.dao;
|
||||
|
||||
import com.hchyun.generator.entity.RelColumn;
|
||||
import com.hchyun.generator.entity.RelTable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author 18209
|
||||
* @Date 2021/2/24 16:21
|
||||
* @Version 1.0
|
||||
*/
|
||||
public interface RelDao {
|
||||
/**
|
||||
* 获取表信息
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<Map<String,Object>> tableInfos();
|
||||
|
||||
/**
|
||||
* 获取表字段信息
|
||||
*
|
||||
* @param tableName
|
||||
* @return
|
||||
*/
|
||||
List<RelColumn> selectTableColumn(String tableName);
|
||||
|
||||
/**
|
||||
* 批量增加字段信息
|
||||
*
|
||||
* @param relColumns
|
||||
* @return
|
||||
*/
|
||||
Integer insertRelColumns(List<RelColumn> relColumns);
|
||||
|
||||
/**
|
||||
* 批量增加子表字段
|
||||
* @param relTables
|
||||
* @return
|
||||
*/
|
||||
Integer insertRelTables(List<RelTable> relTables);
|
||||
|
||||
/**
|
||||
* 通过tableName获取到column信息
|
||||
*
|
||||
* @param tableName
|
||||
* @return
|
||||
*/
|
||||
List<Map<String,Object>> tableColumns(String tableName);
|
||||
|
||||
/**
|
||||
* 通过主表id查询子表信息
|
||||
* @param tableId
|
||||
* @return
|
||||
*/
|
||||
List<RelTable> relTableByTableId(Long tableId);
|
||||
|
||||
/**
|
||||
* 通过relId删除RelColumn信息
|
||||
* @param relId
|
||||
* @return
|
||||
*/
|
||||
Integer deleteRelColumnByRelId(Long relId);
|
||||
|
||||
/**
|
||||
* 通过tableid删除RelTable信息
|
||||
* @param tableId
|
||||
* @return
|
||||
*/
|
||||
Integer deleteRelTableByTableId(Long tableId);
|
||||
|
||||
}
|
||||
|
|
@ -110,7 +110,12 @@ public class GenTable extends GenBaseEntity {
|
|||
@Valid
|
||||
private List<GenTableColumn> columns;
|
||||
|
||||
@Valid
|
||||
private List<AssColumn> assColumns;
|
||||
@Valid
|
||||
private List<RelTable> relTables;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -163,6 +168,14 @@ public class GenTable extends GenBaseEntity {
|
|||
*/
|
||||
private String assQueryType;
|
||||
|
||||
public List<RelTable> getRelTables() {
|
||||
return relTables;
|
||||
}
|
||||
|
||||
public void setRelTables(List<RelTable> relTables) {
|
||||
this.relTables = relTables;
|
||||
}
|
||||
|
||||
public String getAssQueryType() {
|
||||
return assQueryType;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,145 @@
|
|||
package com.hchyun.generator.entity;
|
||||
|
||||
public class RelColumn {
|
||||
|
||||
//表id
|
||||
private long id;
|
||||
//父表id
|
||||
private long relId;
|
||||
//列名称
|
||||
private String columnName;
|
||||
//列描述
|
||||
private String columnComment;
|
||||
//列类型
|
||||
private String columnType;
|
||||
//java类型
|
||||
private String javaType;
|
||||
//java字段名
|
||||
private String javaField;
|
||||
//是否列表显示(1是)
|
||||
private String isList;
|
||||
//是否可查询(1可)
|
||||
private String isQuery;
|
||||
//查询方式(等于,不等于,小于,大于,区间)
|
||||
private String queryType;
|
||||
//控件显示类型
|
||||
private String htmlType;
|
||||
//字典类型
|
||||
private String dictType;
|
||||
//排序
|
||||
private Integer sort;
|
||||
//创建时间
|
||||
private long createBy;
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public long getRelId() {
|
||||
return relId;
|
||||
}
|
||||
|
||||
public void setRelId(long relId) {
|
||||
this.relId = relId;
|
||||
}
|
||||
|
||||
public String getColumnName() {
|
||||
return columnName;
|
||||
}
|
||||
|
||||
public void setColumnName(String columnName) {
|
||||
this.columnName = columnName;
|
||||
}
|
||||
|
||||
public String getColumnComment() {
|
||||
return columnComment;
|
||||
}
|
||||
|
||||
public void setColumnComment(String columnComment) {
|
||||
this.columnComment = columnComment;
|
||||
}
|
||||
|
||||
public String getColumnType() {
|
||||
return columnType;
|
||||
}
|
||||
|
||||
public void setColumnType(String columnType) {
|
||||
this.columnType = columnType;
|
||||
}
|
||||
|
||||
public String getJavaType() {
|
||||
return javaType;
|
||||
}
|
||||
|
||||
public void setJavaType(String javaType) {
|
||||
this.javaType = javaType;
|
||||
}
|
||||
|
||||
public String getJavaField() {
|
||||
return javaField;
|
||||
}
|
||||
|
||||
public void setJavaField(String javaField) {
|
||||
this.javaField = javaField;
|
||||
}
|
||||
|
||||
public String getIsList() {
|
||||
return isList;
|
||||
}
|
||||
|
||||
public void setIsList(String isList) {
|
||||
this.isList = isList;
|
||||
}
|
||||
|
||||
public String getIsQuery() {
|
||||
return isQuery;
|
||||
}
|
||||
|
||||
public void setIsQuery(String isQuery) {
|
||||
this.isQuery = isQuery;
|
||||
}
|
||||
|
||||
public String getQueryType() {
|
||||
return queryType;
|
||||
}
|
||||
|
||||
public void setQueryType(String queryType) {
|
||||
this.queryType = queryType;
|
||||
}
|
||||
|
||||
public String getHtmlType() {
|
||||
return htmlType;
|
||||
}
|
||||
|
||||
public void setHtmlType(String htmlType) {
|
||||
this.htmlType = htmlType;
|
||||
}
|
||||
|
||||
public String getDictType() {
|
||||
return dictType;
|
||||
}
|
||||
|
||||
public void setDictType(String dictType) {
|
||||
this.dictType = dictType;
|
||||
}
|
||||
|
||||
public Integer getSort() {
|
||||
return sort;
|
||||
}
|
||||
|
||||
public void setSort(Integer sort) {
|
||||
this.sort = sort;
|
||||
}
|
||||
|
||||
public long getCreateBy() {
|
||||
return createBy;
|
||||
}
|
||||
|
||||
public void setCreateBy(long createBy) {
|
||||
this.createBy = createBy;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,140 @@
|
|||
package com.hchyun.generator.entity;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.util.List;
|
||||
|
||||
public class RelTable {
|
||||
|
||||
|
||||
//表id
|
||||
private long id;
|
||||
//unionid
|
||||
private long unionId;
|
||||
//主表id
|
||||
private long tableId;
|
||||
//是否是一级关联查询
|
||||
private Integer isMain;
|
||||
//关联子表表名
|
||||
private String relName;
|
||||
//关联子表描述
|
||||
private String relComment;
|
||||
//关联子表的字段
|
||||
private String relColumn;
|
||||
//关联父表字段
|
||||
private String tableColumn;
|
||||
//实体类名称(子表)
|
||||
private String relClass;
|
||||
//查询方式
|
||||
private String queryType;
|
||||
//排序
|
||||
private Integer sort;
|
||||
//创建者
|
||||
private long createBy;
|
||||
|
||||
private List<RelColumn> relColumns;
|
||||
|
||||
public List<RelColumn> getRelColumns() {
|
||||
return relColumns;
|
||||
}
|
||||
|
||||
public void setRelColumns(List<RelColumn> relColumns) {
|
||||
this.relColumns = relColumns;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public long getUnionId() {
|
||||
return unionId;
|
||||
}
|
||||
|
||||
public void setUnionId(long unionId) {
|
||||
this.unionId = unionId;
|
||||
}
|
||||
|
||||
public long getTableId() {
|
||||
return tableId;
|
||||
}
|
||||
|
||||
public void setTableId(long tableId) {
|
||||
this.tableId = tableId;
|
||||
}
|
||||
|
||||
public Integer getIsMain() {
|
||||
return isMain;
|
||||
}
|
||||
|
||||
public void setIsMain(Integer isMain) {
|
||||
this.isMain = isMain;
|
||||
}
|
||||
|
||||
public String getRelName() {
|
||||
return relName;
|
||||
}
|
||||
|
||||
public void setRelName(String relName) {
|
||||
this.relName = relName;
|
||||
}
|
||||
|
||||
public String getRelComment() {
|
||||
return relComment;
|
||||
}
|
||||
|
||||
public void setRelComment(String relComment) {
|
||||
this.relComment = relComment;
|
||||
}
|
||||
|
||||
public String getRelColumn() {
|
||||
return relColumn;
|
||||
}
|
||||
|
||||
public void setRelColumn(String relColumn) {
|
||||
this.relColumn = relColumn;
|
||||
}
|
||||
|
||||
public String getTableColumn() {
|
||||
return tableColumn;
|
||||
}
|
||||
|
||||
public void setTableColumn(String tableColumn) {
|
||||
this.tableColumn = tableColumn;
|
||||
}
|
||||
|
||||
public String getRelClass() {
|
||||
return relClass;
|
||||
}
|
||||
|
||||
public void setRelClass(String relClass) {
|
||||
this.relClass = relClass;
|
||||
}
|
||||
|
||||
public String getQueryType() {
|
||||
return queryType;
|
||||
}
|
||||
|
||||
public void setQueryType(String queryType) {
|
||||
this.queryType = queryType;
|
||||
}
|
||||
|
||||
public Integer getSort() {
|
||||
return sort;
|
||||
}
|
||||
|
||||
public void setSort(Integer sort) {
|
||||
this.sort = sort;
|
||||
}
|
||||
|
||||
public long getCreateBy() {
|
||||
return createBy;
|
||||
}
|
||||
|
||||
public void setCreateBy(long createBy) {
|
||||
this.createBy = createBy;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
package com.hchyun.generator.service;
|
||||
|
||||
import com.hchyun.generator.entity.RelColumn;
|
||||
import com.hchyun.generator.entity.RelTable;
|
||||
import com.hchyun.generator.utils.GenServerResult;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author 18209
|
||||
* @Date 2021/2/24 16:21
|
||||
* @Version 1.0
|
||||
*/
|
||||
public interface RelService {
|
||||
|
||||
/**
|
||||
* 获取到数据库表信息
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
GenServerResult<List<Map<String, Object>>> tableInfos();
|
||||
|
||||
/**
|
||||
* 获取到关联边字段信息
|
||||
*
|
||||
* @param tableName 关联表表名
|
||||
* @param relId 关联关系id
|
||||
* @return
|
||||
*/
|
||||
GenServerResult<List<RelColumn>> relColumns(String tableName, Long relId);
|
||||
|
||||
/**
|
||||
* 通过tableName获取到字段信息
|
||||
*
|
||||
* @param tableName
|
||||
* @return
|
||||
*/
|
||||
GenServerResult<List<Map<String,Object>>> tableColumns(String tableName);
|
||||
|
||||
/**
|
||||
* 通过主表id查询子表信息
|
||||
*
|
||||
* @param tableId
|
||||
* @return
|
||||
*/
|
||||
GenServerResult<List<RelTable>> relTableByTableId(Long tableId);
|
||||
|
||||
}
|
||||
|
|
@ -30,7 +30,7 @@ public class AssociatedServiceImpl implements AssociatedService {
|
|||
public GenServerResult<List<AssColumn>> assColumnsByTable(Long tableId) {
|
||||
try {
|
||||
List<AssColumn> assColumns = associatedDao.selectTableColumnByTableId(tableId);
|
||||
return new GenServerResult<>(true, assColumns);
|
||||
return new GenServerResult<>(assColumns);
|
||||
} catch (RuntimeException e) {
|
||||
logger.error(e.getMessage());
|
||||
return new GenServerResult<>(false, GenReturnConstants.DB_EX);
|
||||
|
|
@ -41,7 +41,7 @@ public class AssociatedServiceImpl implements AssociatedService {
|
|||
public GenServerResult<List<Map<String, Object>>> tableInfos() {
|
||||
try {
|
||||
List<Map<String, Object>> dataMap = associatedDao.tableInfos();
|
||||
return new GenServerResult<>(true, dataMap);
|
||||
return new GenServerResult<>(dataMap);
|
||||
} catch (RuntimeException e) {
|
||||
logger.error(e.getMessage());
|
||||
return new GenServerResult<>(false, GenReturnConstants.DB_EX);
|
||||
|
|
@ -55,7 +55,7 @@ public class AssociatedServiceImpl implements AssociatedService {
|
|||
for (AssColumn assColumn : assColumns) {
|
||||
AssociatedUtils.initAssColumn(assColumn, tableId);
|
||||
}
|
||||
return new GenServerResult<>(true, assColumns);
|
||||
return new GenServerResult<>(assColumns);
|
||||
} catch (RuntimeException e) {
|
||||
logger.error(e.getMessage());
|
||||
return new GenServerResult<>(false, GenReturnConstants.DB_EX);
|
||||
|
|
|
|||
|
|
@ -12,7 +12,9 @@ import java.util.zip.ZipEntry;
|
|||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import com.hchyun.generator.dao.AssociatedDao;
|
||||
import com.hchyun.generator.dao.RelDao;
|
||||
import com.hchyun.generator.entity.AssColumn;
|
||||
import com.hchyun.generator.entity.RelTable;
|
||||
import com.hchyun.generator.service.GenTableService;
|
||||
import com.hchyun.generator.utils.*;
|
||||
import com.hchyun.generator.utils.constant.Constants;
|
||||
|
|
@ -55,6 +57,9 @@ public class GenTableServiceImpl implements GenTableService {
|
|||
@Autowired
|
||||
private AssociatedDao associatedDao;
|
||||
|
||||
@Autowired
|
||||
private RelDao relDao;
|
||||
|
||||
/**
|
||||
* 查询业务信息
|
||||
*
|
||||
|
|
@ -67,7 +72,7 @@ public class GenTableServiceImpl implements GenTableService {
|
|||
GenTable genTable = genTableDao.selectGenTableById(id);
|
||||
setTableFromOptions(genTable);
|
||||
return genTable;
|
||||
}catch (RuntimeException e){
|
||||
} catch (RuntimeException e) {
|
||||
logger.error(e.getMessage());
|
||||
throw new GenCustomException(GenReturnConstants.OP_ERROR);
|
||||
}
|
||||
|
|
@ -83,7 +88,7 @@ public class GenTableServiceImpl implements GenTableService {
|
|||
public List<GenTable> selectGenTableList(GenTable genTable) {
|
||||
try {
|
||||
return genTableDao.selectGenTableList(genTable);
|
||||
}catch (RuntimeException e){
|
||||
} catch (RuntimeException e) {
|
||||
logger.error(e.getMessage());
|
||||
throw new GenCustomException(GenReturnConstants.OP_ERROR);
|
||||
}
|
||||
|
|
@ -99,7 +104,7 @@ public class GenTableServiceImpl implements GenTableService {
|
|||
public List<GenTable> selectDbTableList(GenTable genTable) {
|
||||
try {
|
||||
return genTableDao.selectDbTableList(genTable);
|
||||
}catch (RuntimeException e){
|
||||
} catch (RuntimeException e) {
|
||||
logger.error(e.getMessage());
|
||||
throw new GenCustomException(GenReturnConstants.OP_ERROR);
|
||||
}
|
||||
|
|
@ -115,7 +120,7 @@ public class GenTableServiceImpl implements GenTableService {
|
|||
public List<GenTable> selectDbTableListByNames(String[] tableNames) {
|
||||
try {
|
||||
return genTableDao.selectDbTableListByNames(tableNames);
|
||||
}catch (RuntimeException e){
|
||||
} catch (RuntimeException e) {
|
||||
logger.error(e.getMessage());
|
||||
throw new GenCustomException(GenReturnConstants.OP_ERROR);
|
||||
}
|
||||
|
|
@ -130,7 +135,7 @@ public class GenTableServiceImpl implements GenTableService {
|
|||
public List<GenTable> selectGenTableAll() {
|
||||
try {
|
||||
return genTableDao.selectGenTableAll();
|
||||
}catch (RuntimeException e){
|
||||
} catch (RuntimeException e) {
|
||||
logger.error(e.getMessage());
|
||||
throw new GenCustomException(GenReturnConstants.OP_ERROR);
|
||||
}
|
||||
|
|
@ -156,6 +161,25 @@ public class GenTableServiceImpl implements GenTableService {
|
|||
associatedDao.deleteTableColumn(genTable.getTableId());
|
||||
associatedDao.insertColumns(assColumns);
|
||||
}
|
||||
if (genTable.getTplCategory().equals("rel")){
|
||||
List<RelTable> relTables = relDao.relTableByTableId(genTable.getTableId());
|
||||
for (RelTable relTable : relTables) {
|
||||
relDao.deleteRelColumnByRelId(relTable.getId());
|
||||
}
|
||||
relDao.deleteRelTableByTableId(genTable.getTableId());
|
||||
relTables = genTable.getRelTables();
|
||||
for (int i = 0; i < relTables.size(); i++) {
|
||||
RelTable relTable = relTables.get(i);
|
||||
relTable.setRelClass(GenUtils.convertClassName(relTable.getRelName()));
|
||||
relTables.set(i,relTable);
|
||||
}
|
||||
if (relTables != null) {
|
||||
relDao.insertRelTables(relTables);
|
||||
for (RelTable relTable : relTables) {
|
||||
relDao.insertRelColumns(relTable.getRelColumns());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (GenCustomException e) {
|
||||
logger.error(e.getMessage());
|
||||
|
|
@ -247,7 +271,7 @@ public class GenTableServiceImpl implements GenTableService {
|
|||
dataMap.put(template, sw.toString());
|
||||
}
|
||||
return dataMap;
|
||||
}catch (RuntimeException e){
|
||||
} catch (RuntimeException e) {
|
||||
logger.error(e.getMessage());
|
||||
throw new GenCustomException(e.getMessage());
|
||||
}
|
||||
|
|
@ -267,7 +291,7 @@ public class GenTableServiceImpl implements GenTableService {
|
|||
generatorCode(tableName, zip);
|
||||
IOUtils.closeQuietly(zip);
|
||||
return outputStream.toByteArray();
|
||||
}catch (RuntimeException e){
|
||||
} catch (RuntimeException e) {
|
||||
logger.error(e.getMessage());
|
||||
throw new GenCustomException(GenReturnConstants.OP_ERROR);
|
||||
}
|
||||
|
|
@ -318,7 +342,7 @@ public class GenTableServiceImpl implements GenTableService {
|
|||
}
|
||||
}
|
||||
return true;
|
||||
}catch (RuntimeException e){
|
||||
} catch (RuntimeException e) {
|
||||
logger.error(e.getMessage());
|
||||
throw new GenCustomException(GenReturnConstants.OP_ERROR);
|
||||
}
|
||||
|
|
@ -354,7 +378,7 @@ public class GenTableServiceImpl implements GenTableService {
|
|||
if (GenStringUtils.isNotEmpty(delColumns)) {
|
||||
genTableColumnDao.deleteGenTableColumns(delColumns);
|
||||
}
|
||||
}catch (RuntimeException e){
|
||||
} catch (RuntimeException e) {
|
||||
logger.error(e.getMessage());
|
||||
throw new GenCustomException(GenReturnConstants.OP_ERROR);
|
||||
}
|
||||
|
|
@ -380,7 +404,7 @@ public class GenTableServiceImpl implements GenTableService {
|
|||
}
|
||||
IOUtils.closeQuietly(zip);
|
||||
return outputStream.toByteArray();
|
||||
}catch (RuntimeException e){
|
||||
} catch (RuntimeException e) {
|
||||
logger.error(e.getMessage());
|
||||
throw new GenCustomException(GenReturnConstants.OP_ERROR);
|
||||
}
|
||||
|
|
@ -409,7 +433,7 @@ public class GenTableServiceImpl implements GenTableService {
|
|||
private ZipOutputStream generatorCode(String tableName, ZipOutputStream zip) {
|
||||
try {
|
||||
|
||||
}catch (RuntimeException e){
|
||||
} catch (RuntimeException e) {
|
||||
logger.error(e.getMessage());
|
||||
throw new GenCustomException(GenReturnConstants.OP_ERROR);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,87 @@
|
|||
package com.hchyun.generator.service.impl;
|
||||
|
||||
import com.hchyun.generator.dao.RelDao;
|
||||
import com.hchyun.generator.entity.RelColumn;
|
||||
import com.hchyun.generator.entity.RelTable;
|
||||
import com.hchyun.generator.service.RelService;
|
||||
import com.hchyun.generator.utils.GenServerResult;
|
||||
import com.hchyun.generator.utils.RelUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author 18209
|
||||
* @Date 2021/2/24 16:21
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Service
|
||||
public class RelServiceImpl implements RelService {
|
||||
private Logger logger = LoggerFactory.getLogger(RelServiceImpl.class);
|
||||
|
||||
@Autowired
|
||||
private RelDao relDao;
|
||||
|
||||
/**
|
||||
* 获取到数据库表信息
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public GenServerResult<List<Map<String, Object>>> tableInfos() {
|
||||
try {
|
||||
List<Map<String, Object>> dataMap = relDao.tableInfos();
|
||||
return new GenServerResult<>(dataMap);
|
||||
} catch (RuntimeException e) {
|
||||
logger.error(e.getMessage());
|
||||
return new GenServerResult<>(false, "获取数据库表信息错误");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取到关联边字段信息
|
||||
*
|
||||
* @param tableName 关联表表名
|
||||
* @param relId 关联关系id
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public GenServerResult<List<RelColumn>> relColumns(String tableName, Long relId) {
|
||||
try {
|
||||
List<RelColumn> relColumns = relDao.selectTableColumn(tableName);
|
||||
for (RelColumn relColumn : relColumns) {
|
||||
RelUtil.initRelColumn(relColumn, relId);
|
||||
}
|
||||
return new GenServerResult<>(true,relColumns);
|
||||
} catch (RuntimeException e) {
|
||||
logger.error(e.getMessage());
|
||||
return new GenServerResult<>(false, "获取关联边字段信息错误");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public GenServerResult<List<Map<String, Object>>> tableColumns(String tableName) {
|
||||
try {
|
||||
List<Map<String,Object>> columns = relDao.tableColumns(tableName);
|
||||
return new GenServerResult<>(columns);
|
||||
}catch (RuntimeException e){
|
||||
logger.error(e.getMessage());
|
||||
return new GenServerResult<>(false,"获取字段信息错误!");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public GenServerResult<List<RelTable>> relTableByTableId(Long tableId) {
|
||||
try {
|
||||
List<RelTable> relTables = relDao.relTableByTableId(tableId);
|
||||
return new GenServerResult<>(relTables);
|
||||
}catch (RuntimeException e){
|
||||
logger.error(e.getMessage());
|
||||
return new GenServerResult<>(false,"获取关联数据错误!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -16,6 +16,12 @@ public class GenServerResult<T> {
|
|||
|
||||
public GenServerResult() {
|
||||
}
|
||||
public GenServerResult(T data) {
|
||||
this.data = data;
|
||||
this.start = true;
|
||||
this.msg = "操作成功";
|
||||
}
|
||||
|
||||
|
||||
public GenServerResult(boolean start, T data, Integer count) {
|
||||
this.data = data;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,74 @@
|
|||
package com.hchyun.generator.utils;
|
||||
|
||||
import com.hchyun.generator.entity.RelColumn;
|
||||
import com.hchyun.generator.utils.constant.GenConstants;
|
||||
|
||||
/**
|
||||
* @Author 18209
|
||||
* @Date 2021/2/24 22:46
|
||||
* @Version 1.0
|
||||
*/
|
||||
public class RelUtil {
|
||||
|
||||
|
||||
public static void initRelColumn(RelColumn relColumn, Long relId) {
|
||||
//获取数据库数据类型
|
||||
String dataType = GenUtils.getDbType(relColumn.getColumnType());
|
||||
//获取字段名称
|
||||
String columnName = relColumn.getColumnName();
|
||||
//设置tableid
|
||||
relColumn.setRelId(relId);
|
||||
//设置创建者id
|
||||
relColumn.setCreateBy(1);
|
||||
//转为设置java字段名称
|
||||
relColumn.setJavaField(GenStringUtils.toCamelCase(columnName));
|
||||
//默认类型
|
||||
relColumn.setJavaType(GenConstants.TYPE_STRING);
|
||||
//默认查询条件 精确查询
|
||||
relColumn.setQueryType(GenConstants.QUERY_EQ);
|
||||
|
||||
if (GenUtils.arraysContains(GenConstants.COLUMNTYPE_STR, dataType) || GenUtils.arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType)) {
|
||||
//字符串长度超500设置htmlType为文本域
|
||||
Integer columnLength = GenUtils.getColumnLength(relColumn.getColumnType());
|
||||
String htmlType = columnLength >= 500 || GenUtils.arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType) ? GenConstants.HTML_TEXTAREA : GenConstants.HTML_INPUT;
|
||||
relColumn.setHtmlType(htmlType);
|
||||
} else if (GenUtils.arraysContains(GenConstants.COLUMNTYPE_TIME, dataType)) {
|
||||
relColumn.setJavaType(GenConstants.TYPE_DATE);
|
||||
relColumn.setHtmlType(GenConstants.HTML_DATETIME);
|
||||
} else if (GenUtils.arraysContains(GenConstants.COLUMNTYPE_NUMBER, dataType)) {
|
||||
relColumn.setHtmlType(GenConstants.HTML_INPUT);
|
||||
|
||||
// 如果是浮点型 统一用BigDecimal
|
||||
String[] str = GenStringUtils.split(GenStringUtils.substringBetween(relColumn.getColumnType(), "(", ")"), ",");
|
||||
if (str != null && str.length == 2 && Integer.parseInt(str[1]) > 0) {
|
||||
relColumn.setJavaType(GenConstants.TYPE_BIGDECIMAL);
|
||||
}
|
||||
// 如果是整形
|
||||
else if (str != null && str.length == 1 && Integer.parseInt(str[0]) <= 10) {
|
||||
relColumn.setJavaType(GenConstants.TYPE_INTEGER);
|
||||
}
|
||||
// 长整形
|
||||
else {
|
||||
relColumn.setJavaType(GenConstants.TYPE_LONG);
|
||||
}
|
||||
}
|
||||
// 列表字段
|
||||
relColumn.setIsList(GenConstants.REQUIRE);
|
||||
// 查询字段
|
||||
relColumn.setIsQuery(GenConstants.NO_REQUIRE);
|
||||
// 查询字段类型
|
||||
if (GenStringUtils.endsWithIgnoreCase(columnName, "name")) {
|
||||
relColumn.setQueryType(GenConstants.QUERY_LIKE);
|
||||
}
|
||||
// 状态字段设置单选框
|
||||
if (GenStringUtils.endsWithIgnoreCase(columnName, "status")) {
|
||||
relColumn.setHtmlType(GenConstants.HTML_RADIO);
|
||||
}
|
||||
// 类型&性别字段设置下拉框
|
||||
else if (GenStringUtils.endsWithIgnoreCase(columnName, "type")
|
||||
|| GenStringUtils.endsWithIgnoreCase(columnName, "sex")) {
|
||||
relColumn.setHtmlType(GenConstants.HTML_SELECT);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,107 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.hchyun.generator.dao.RelDao">
|
||||
|
||||
<resultMap id="RelTableResult" type="com.hchyun.generator.entity.RelTable">
|
||||
<result property="id" column="id"/>
|
||||
<result property="unionId" column="union_id"/>
|
||||
<result property="tableId" column="table_id"/>
|
||||
<result property="isMain" column=""/>
|
||||
<result property="relName" column="rel_name"/>
|
||||
<result property="relComment" column="rel_comment"/>
|
||||
<result property="relColumn" column="rel_column"/>
|
||||
<result property="tableColumn" column="table_column"/>
|
||||
<result property="relClass" column="rel_class"/>
|
||||
<result property="queryType" column="query_type"/>
|
||||
<result property="sort" column="sort"/>
|
||||
<result property="createBy" column="create_by"/>
|
||||
</resultMap>
|
||||
<resultMap id="RelTableColumnResult" type="com.hchyun.generator.entity.RelTable" extends="RelTableResult">
|
||||
<collection property="relColumns" notNullColumn="id" javaType="java.util.List" resultMap="RelColumnResult" />
|
||||
</resultMap>
|
||||
<resultMap id="RelColumnResult" type="com.hchyun.generator.entity.RelColumn">
|
||||
<result property="relId" column="rel_id"/>
|
||||
<result property="columnName" column="column_name"/>
|
||||
<result property="columnComment" column="column_comment"/>
|
||||
<result property="columnType" column="column_type"/>
|
||||
<result property="javaType" column="java_type"/>
|
||||
<result property="javaField" column="java_field"/>
|
||||
<result property="isList" column="is_list"/>
|
||||
<result property="isQuery" column="is_query"/>
|
||||
<result property="queryType" column="query_type"/>
|
||||
<result property="htmlType" column="html_type"/>
|
||||
<result property="dictType" column="dict_type"/>
|
||||
<result property="sort" column="sort"/>
|
||||
<result property="createBy" column="create_by"/>
|
||||
</resultMap>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<select id="tableInfos" resultType="java.util.HashMap">
|
||||
select table_name, table_comment
|
||||
from information_schema.tables
|
||||
where table_schema = (select database())
|
||||
AND table_name NOT LIKE 'qrtz_%'
|
||||
AND table_name NOT LIKE 'gen_%'
|
||||
</select>
|
||||
|
||||
<select id="selectTableColumn" resultType="com.hchyun.generator.entity.RelColumn" parameterType="String">
|
||||
select column_name, ordinal_position as sort, column_comment, column_type
|
||||
from information_schema.columns
|
||||
where table_schema = (select database())
|
||||
and table_name = (#{tableName})
|
||||
order by sort
|
||||
</select>
|
||||
|
||||
<insert id="insertRelTables" parameterType="java.util.List">
|
||||
insert into gen_rel_table(id, union_id, table_id, is_main, rel_name, rel_comment,
|
||||
rel_column, table_column, rel_class, query_type, sort, create_by)
|
||||
values
|
||||
<foreach collection="list" item="item" index="index" separator=",">
|
||||
(#{item.id},#{item.unionId},#{item.tableId},#{item.isMain},
|
||||
#{item.relName},#{item.relComment},#{item.relColumn},#{item.tableColumn},#{item.relClass},
|
||||
#{item.queryType},#{item.sort},#{item.createBy})
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<insert id="insertRelColumns" parameterType="java.util.List">
|
||||
insert into gen_rel_column(rel_id, column_name, column_comment, column_type, java_type, java_field, is_list,
|
||||
is_query, query_type, html_type, dict_type, sort, create_by)
|
||||
values
|
||||
<foreach collection="list" item="item" index="index" separator=",">
|
||||
(#{item.relId},#{item.columnName},#{item.columnComment},#{item.columnType},
|
||||
#{item.javaType},#{item.javaField},#{item.isList},#{item.isQuery},
|
||||
#{item.queryType},#{item.htmlType},#{item.dictType},#{item.sort},
|
||||
#{item.createBy})
|
||||
</foreach>
|
||||
</insert>
|
||||
<select id="tableColumns" resultType="java.util.Map">
|
||||
select column_name, column_comment
|
||||
from information_schema.columns
|
||||
where table_schema = (select database())
|
||||
and table_name = (#{tableName})
|
||||
order by ordinal_position
|
||||
</select>
|
||||
|
||||
<select id="relTableByTableId" resultMap="RelTableColumnResult" parameterType="Long">
|
||||
select grt.id, grt.union_id, grt.table_id, grt.is_main, grt.rel_name, grt.rel_comment, grt.rel_column, grt.table_column, grt.rel_class, grt.query_type, grt.sort, grt.create_by,
|
||||
grc.rel_id, grc.column_name, grc.column_comment, grc.column_type, grc.java_type, grc.java_field, grc.is_list, grc.is_query, grc.query_type, grc.html_type, grc.dict_type, grc.sort, grc.create_by
|
||||
from gen_rel_table grt
|
||||
left join gen_rel_column grc on grt.id = grc.rel_id
|
||||
where grt.table_id = #{tableId}
|
||||
</select>
|
||||
|
||||
<delete id="deleteRelColumnByRelId">
|
||||
delete from gen_rel_column where rel_id = #{relId}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteRelTableByTableId">
|
||||
delete from gen_rel_table where table_id = #{tableId}
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
package com.hchyun.system.dao;
|
||||
|
||||
/**
|
||||
* @Author 18209
|
||||
* @Date 2021/2/24 17:56
|
||||
* @Version 1.0
|
||||
*/
|
||||
public interface SequenceDao {
|
||||
|
||||
/**
|
||||
* 当前值
|
||||
* @param tableName
|
||||
* @return
|
||||
*/
|
||||
Long currval(String tableName);
|
||||
|
||||
/**
|
||||
* 下一个值
|
||||
* @param tableName
|
||||
* @return
|
||||
*/
|
||||
Long nextval(String tableName);
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
package com.hchyun.system.service;
|
||||
|
||||
/**
|
||||
* @Author 18209
|
||||
* @Date 2021/2/24 17:56
|
||||
* @Version 1.0
|
||||
*/
|
||||
public interface SequenceService {
|
||||
/**
|
||||
* 当前值
|
||||
* @param tableName
|
||||
* @return
|
||||
*/
|
||||
Long currval(String tableName);
|
||||
|
||||
/**
|
||||
* 下一个值
|
||||
* @param tableName
|
||||
* @return
|
||||
*/
|
||||
Long nextval(String tableName);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
package com.hchyun.system.service.impl;
|
||||
|
||||
import com.hchyun.system.dao.SequenceDao;
|
||||
import com.hchyun.system.service.SequenceService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @Author 18209
|
||||
* @Date 2021/2/24 17:56
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Service
|
||||
public class SequenceServiceImpl implements SequenceService {
|
||||
private Logger logger = LoggerFactory.getLogger(SequenceServiceImpl.class);
|
||||
|
||||
@Autowired
|
||||
private SequenceDao sequenceDao;
|
||||
|
||||
@Override
|
||||
public Long currval(String tableName) {
|
||||
return sequenceDao.currval(tableName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long nextval(String tableName) {
|
||||
return sequenceDao.nextval(tableName);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.hchyun.system.dao.SequenceDao">
|
||||
<select id="currval" resultType="Long" parameterType="String">
|
||||
select currval(#{tableName}) FROM DUAL;
|
||||
</select>
|
||||
<select id="nextval" resultType="Long" parameterType="String">
|
||||
select nextval(#{tableName}) FROM DUAL;
|
||||
</select>
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue