关联查询入库

This commit is contained in:
20932067@zju.edu.cn 2021-02-06 18:25:22 +08:00
parent 1821148e36
commit 4b5a133a04
27 changed files with 1203 additions and 601 deletions

View File

@ -0,0 +1,32 @@
import request from "@/utils/request";
/**
* 获取表信息
* @returns {AxiosPromise}
*/
export function getTableInfos() {
return request({
url: '/ass/tableinfos',
method: 'get'
})
}
/**
* 获取关联表表的字段信息
* @param tableName 关联表表名
* @param tableId 关联表id
* @returns {AxiosPromise}
*/
export function getAssColumns(tableName,tableId){
return request({
url: '/ass/'+tableName+'/'+tableId,
method: 'get'
})
}
export function getAssColumnsByTableId(tableId){
return request({
url:'/ass/'+tableId,
method: 'get'
})
}

View File

@ -129,13 +129,7 @@ export const constantRoutes = [
component: (resolve) => require(['@/views/tool/query/uniQuery'], resolve), component: (resolve) => require(['@/views/tool/query/uniQuery'], resolve),
name: 'UniQuery', name: 'UniQuery',
meta: { title: '万能查询配置' } meta: { title: '万能查询配置' }
}, }
// {
// path: 'data/:dataId(\\d+)',
// component: (resolve) => require(['@/views/tool/query/queryDate'], resolve),
// name: 'QueryDate',
// meta: { title: '信息统计' }
// }
] ]
}, },
{ {

View File

@ -122,7 +122,7 @@
</el-table> </el-table>
</el-tab-pane> </el-tab-pane>
<el-tab-pane label="生成信息" name="genInfo"> <el-tab-pane label="生成信息" name="genInfo">
<gen-info-form ref="genInfo" :info="info" :tables="tables" :menus="menus"/> <gen-info-form ref="genInfo" :info="info" :tables="tables" :menus="menus" :dict-options="dictOptions"/>
</el-tab-pane> </el-tab-pane>
</el-tabs> </el-tabs>
<el-form label-width="100px"> <el-form label-width="100px">
@ -204,11 +204,13 @@ export default {
submitForm() { submitForm() {
const basicForm = this.$refs.basicInfo.$refs.basicInfoForm; const basicForm = this.$refs.basicInfo.$refs.basicInfoForm;
const genForm = this.$refs.genInfo.$refs.genInfoForm; const genForm = this.$refs.genInfo.$refs.genInfoForm;
const assColumns = this.$refs.genInfo.$refs.assCloumnTable.data;
Promise.all([basicForm, genForm].map(this.getFormPromise)).then(res => { Promise.all([basicForm, genForm].map(this.getFormPromise)).then(res => {
const validateResult = res.every(item => !!item); const validateResult = res.every(item => !!item);
if (validateResult) { if (validateResult) {
const genTable = Object.assign({}, basicForm.model, genForm.model); const genTable = Object.assign({}, basicForm.model, genForm.model);
genTable.columns = this.cloumns; genTable.columns = this.cloumns;
genTable.assColumns = assColumns;
genTable.params = { genTable.params = {
treeCode: genTable.treeCode, treeCode: genTable.treeCode,
treeName: genTable.treeName, treeName: genTable.treeName,

View File

@ -5,9 +5,10 @@
<el-form-item prop="tplCategory"> <el-form-item prop="tplCategory">
<span slot="label">生成模板</span> <span slot="label">生成模板</span>
<el-select v-model="info.tplCategory" @change="tplSelectChange"> <el-select v-model="info.tplCategory" @change="tplSelectChange">
<el-option label="单表(增删改查)" value="crud" /> <el-option label="单表(增删改查)" value="crud"/>
<el-option label="树表(增删改查)" value="tree" /> <el-option label="树表(增删改查)" value="tree"/>
<el-option label="主子表(增删改查)" value="sub" /> <el-option label="关联表(增删改查)" value="ass"/>
<el-option label="主子表(增删改查)" value="sub"/>
</el-select> </el-select>
</el-form-item> </el-form-item>
</el-col> </el-col>
@ -20,7 +21,7 @@
<i class="el-icon-question"></i> <i class="el-icon-question"></i>
</el-tooltip> </el-tooltip>
</span> </span>
<el-input v-model="info.packageName" /> <el-input v-model="info.packageName"/>
</el-form-item> </el-form-item>
</el-col> </el-col>
@ -32,7 +33,7 @@
<i class="el-icon-question"></i> <i class="el-icon-question"></i>
</el-tooltip> </el-tooltip>
</span> </span>
<el-input v-model="info.moduleName" /> <el-input v-model="info.moduleName"/>
</el-form-item> </el-form-item>
</el-col> </el-col>
@ -44,7 +45,7 @@
<i class="el-icon-question"></i> <i class="el-icon-question"></i>
</el-tooltip> </el-tooltip>
</span> </span>
<el-input v-model="info.businessName" /> <el-input v-model="info.businessName"/>
</el-form-item> </el-form-item>
</el-col> </el-col>
@ -56,7 +57,7 @@
<i class="el-icon-question"></i> <i class="el-icon-question"></i>
</el-tooltip> </el-tooltip>
</span> </span>
<el-input v-model="info.functionName" /> <el-input v-model="info.functionName"/>
</el-form-item> </el-form-item>
</el-col> </el-col>
@ -172,6 +173,7 @@
</el-form-item> </el-form-item>
</el-col> </el-col>
</el-row> </el-row>
<el-row v-show="info.tplCategory == 'sub'"> <el-row v-show="info.tplCategory == 'sub'">
<h4 class="form-header">关联信息</h4> <h4 class="form-header">关联信息</h4>
<el-col :span="12"> <el-col :span="12">
@ -211,90 +213,257 @@
</el-form-item> </el-form-item>
</el-col> </el-col>
</el-row> </el-row>
<div v-if="info.tplCategory == 'ass'">
<el-row>
<h4 class="form-header">关联关系</h4>
<el-col :span="8">
<el-form-item>
<span slot="label">
主表id
<el-tooltip content="主表idacc_id" placement="top">
<i class="el-icon-question"></i>
</el-tooltip>
</span>
<el-select v-model="info.assTableColumn" placeholder="请选择表名">
<el-option
v-for="(column , index) in info.columns"
:key="index"
:label="column.columnName+':'+column.columnComment"
:value="column.columnName"/>
</el-select>
</el-form-item>
</el-col>
<el-col :span="8">
<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.assTableName" @change="assSelectChang" 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="8">
<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.assTableFkColumn" @change="assSelectChang" placeholder="请选择表名">
<el-option
v-for="(cloumn , index) in assCloumns"
:key="index"
:label="cloumn.columnName + ':'+cloumn.columnComment"
:value="cloumn.columnName"/>
</el-select>
</el-form-item>
</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="字段列名"
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>
</el-form> </el-form>
</template> </template>
<script> <script>
import Treeselect from "@riophae/vue-treeselect"; import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css"; import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import {getTableInfos, getAssColumns,getAssColumnsByTableId} from "@/api/tool/associated"
export default { export default {
name: "BasicInfoForm", name: "BasicInfoForm",
components: { Treeselect }, components: {Treeselect},
props: { props: {
info: { info: {
type: Object, type: Object,
default: null default: null
},
tables: {
type: Array,
default: null
},
menus: {
type: Array,
default: []
},
}, },
data() { tables: {
type: Array,
default: null
},
menus: {
type: Array,
default: []
},
dictOptions:{
type:Array,
default:[]
}
},
data() {
return {
subColumns: [],
//
tableHeight: document.documentElement.scrollHeight - 245 + "px",
assCloumns:[],
tableInfo: [],
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() {
const 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);
}
},
methods: {
/** 关联表该表 */
assSelectChang() {
getAssColumns(this.info.assTableName, this.info.tableId).then(res => {
this.assCloumns = res.data
})
},
/** 转换菜单数据结构 */
normalizer(node) {
if (node.children && !node.children.length) {
delete node.children;
}
return { return {
subColumns: [], id: node.menuId,
rules: { label: node.menuName,
tplCategory: [ children: node.children
{ 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: { subSelectChange() {
'info.subTableName': function(val) { this.info.subTableFkName = '';
this.setSubTableColumns(val); },
/** 选择生成模板触发 */
tplSelectChange(value) {
if (value !== 'sub') {
this.info.subTableName = '';
this.info.subTableFkName = '';
} }
}, },
methods: { /** 设置关联外键 */
/** 转换菜单数据结构 */ setSubTableColumns(value) {
normalizer(node) { for (var item in this.tables) {
if (node.children && !node.children.length) { const name = this.tables[item].tableName;
delete node.children; if (value === name) {
} this.subColumns = this.tables[item].columns;
return { break;
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> </script>

View File

@ -151,7 +151,7 @@ export default {
/** 导出按钮操作 */ /** 导出按钮操作 */
handleExport() { handleExport() {
var that = this var that = this
this.$confirm('是否确认查询数据项?', "警告", { this.$confirm('是否确认导出查询数据项?', "警告", {
confirmButtonText: "确定", confirmButtonText: "确定",
cancelButtonText: "取消", cancelButtonText: "取消",
type: "warning" type: "warning"

View File

@ -415,7 +415,7 @@ export default {
var that = this var that = this
let list = JSONString(that.cloumns) let list = JSONString(that.cloumns)
let data = that.info let data = that.info
this.$confirm('是否确认查询数据项?', "警告", { this.$confirm('是否确认导出查询数据项?', "警告", {
confirmButtonText: "确定", confirmButtonText: "确定",
cancelButtonText: "取消", cancelButtonText: "取消",
type: "warning" type: "warning"

View File

@ -3,13 +3,13 @@
PUBLIC "-//mybatis.org//DTD Config 3.0//EN" PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd"> "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration> <configuration>
<settings> <settings>
<setting name="cacheEnabled" value="true" /> <!-- 全局映射器启用缓存 --> <setting name="cacheEnabled" value="true" /> <!-- 全局映射器启用缓存 -->
<setting name="useGeneratedKeys" value="true" /> <!-- 允许 JDBC 支持自动生成主键 --> <setting name="useGeneratedKeys" value="true" /> <!-- 允许 JDBC 支持自动生成主键 -->
<setting name="defaultExecutorType" value="REUSE" /> <!-- 配置默认的执行器 --> <setting name="defaultExecutorType" value="REUSE" /> <!-- 配置默认的执行器 -->
<setting name="logImpl" value="SLF4J" /> <!-- 指定 MyBatis 所用日志的具体实现 --> <setting name="logImpl" value="SLF4J" /> <!-- 指定 MyBatis 所用日志的具体实现 -->
<!-- <setting name="mapUnderscoreToCamelCase" value="true"/> 驼峰式命名 --> <setting name="mapUnderscoreToCamelCase" value="true"/> <!--驼峰式命名 -->
</settings> </settings>
</configuration> </configuration>

View File

@ -109,7 +109,11 @@ public class GenConstants
/** 模糊查询 */ /** 模糊查询 */
public static final String QUERY_LIKE = "LIKE"; public static final String QUERY_LIKE = "LIKE";
/** 精确查询 */
public static final String QUERY_EQ = "EQ";
/** 需要 */ /** 需要 */
public static final String REQUIRE = "1"; public static final String REQUIRE = "1";
/** 不需要 */
public static final String NO_REQUIRE = "0";
} }

View File

@ -4,11 +4,10 @@ import com.hchyun.common.utils.StringUtils;
/** /**
* 字符串格式化 * 字符串格式化
* *
* @author hchyun * @author hchyun
*/ */
public class StrFormatter public class StrFormatter {
{
public static final String EMPTY_JSON = "{}"; public static final String EMPTY_JSON = "{}";
public static final char C_BACKSLASH = '\\'; public static final char C_BACKSLASH = '\\';
public static final char C_DELIM_START = '{'; public static final char C_DELIM_START = '{';
@ -22,15 +21,13 @@ public class StrFormatter
* 通常使用format("this is {} for {}", "a", "b") -> this is a for b<br> * 通常使用format("this is {} for {}", "a", "b") -> this is a for b<br>
* 转义{} format("this is \\{} for {}", "a", "b") -> this is \{} for a<br> * 转义{} format("this is \\{} for {}", "a", "b") -> this is \{} for a<br>
* 转义\ format("this is \\\\{} for {}", "a", "b") -> this is \a for b<br> * 转义\ format("this is \\\\{} for {}", "a", "b") -> this is \a for b<br>
* *
* @param strPattern 字符串模板 * @param strPattern 字符串模板
* @param argArray 参数列表 * @param argArray 参数列表
* @return 结果 * @return 结果
*/ */
public static String format(final String strPattern, final Object... argArray) public static String format(final String strPattern, final Object... argArray) {
{ if (StringUtils.isEmpty(strPattern) || StringUtils.isEmpty(argArray)) {
if (StringUtils.isEmpty(strPattern) || StringUtils.isEmpty(argArray))
{
return strPattern; return strPattern;
} }
final int strPatternLength = strPattern.length(); final int strPatternLength = strPattern.length();
@ -40,43 +37,30 @@ public class StrFormatter
int handledPosition = 0; int handledPosition = 0;
int delimIndex;// 占位符所在位置 int delimIndex;// 占位符所在位置
for (int argIndex = 0; argIndex < argArray.length; argIndex++) for (int argIndex = 0; argIndex < argArray.length; argIndex++) {
{
delimIndex = strPattern.indexOf(EMPTY_JSON, handledPosition); delimIndex = strPattern.indexOf(EMPTY_JSON, handledPosition);
if (delimIndex == -1) if (delimIndex == -1) {
{ if (handledPosition == 0) {
if (handledPosition == 0)
{
return strPattern; return strPattern;
} } else { // 字符串模板剩余部分不再包含占位符加入剩余部分后返回结果
else
{ // 字符串模板剩余部分不再包含占位符加入剩余部分后返回结果
sbuf.append(strPattern, handledPosition, strPatternLength); sbuf.append(strPattern, handledPosition, strPatternLength);
return sbuf.toString(); return sbuf.toString();
} }
} } else {
else if (delimIndex > 0 && strPattern.charAt(delimIndex - 1) == C_BACKSLASH) {
{ if (delimIndex > 1 && strPattern.charAt(delimIndex - 2) == C_BACKSLASH) {
if (delimIndex > 0 && strPattern.charAt(delimIndex - 1) == C_BACKSLASH)
{
if (delimIndex > 1 && strPattern.charAt(delimIndex - 2) == C_BACKSLASH)
{
// 转义符之前还有一个转义符占位符依旧有效 // 转义符之前还有一个转义符占位符依旧有效
sbuf.append(strPattern, handledPosition, delimIndex - 1); sbuf.append(strPattern, handledPosition, delimIndex - 1);
sbuf.append(Convert.utf8Str(argArray[argIndex])); sbuf.append(Convert.utf8Str(argArray[argIndex]));
handledPosition = delimIndex + 2; handledPosition = delimIndex + 2;
} } else {
else
{
// 占位符被转义 // 占位符被转义
argIndex--; argIndex--;
sbuf.append(strPattern, handledPosition, delimIndex - 1); sbuf.append(strPattern, handledPosition, delimIndex - 1);
sbuf.append(C_DELIM_START); sbuf.append(C_DELIM_START);
handledPosition = delimIndex + 1; handledPosition = delimIndex + 1;
} }
} } else {
else
{
// 正常占位符 // 正常占位符
sbuf.append(strPattern, handledPosition, delimIndex); sbuf.append(strPattern, handledPosition, delimIndex);
sbuf.append(Convert.utf8Str(argArray[argIndex])); sbuf.append(Convert.utf8Str(argArray[argIndex]));

View File

@ -6,186 +6,172 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import com.hchyun.common.core.text.StrFormatter; import com.hchyun.common.core.text.StrFormatter;
/** /**
* 字符串工具类 * 字符串工具类
* *
* @author hchyun * @author hchyun
*/ */
public class StringUtils extends org.apache.commons.lang3.StringUtils public class StringUtils extends org.apache.commons.lang3.StringUtils {
{ /**
/** 空字符串 */ * 空字符串
*/
private static final String NULLSTR = ""; private static final String NULLSTR = "";
/** 下划线 */ /**
* 下划线
*/
private static final char SEPARATOR = '_'; private static final char SEPARATOR = '_';
/** /**
* 获取参数不为空值 * 获取参数不为空值
* *
* @param value defaultValue 要判断的value * @param value defaultValue 要判断的value
* @return value 返回值 * @return value 返回值
*/ */
public static <T> T nvl(T value, T defaultValue) public static <T> T nvl(T value, T defaultValue) {
{
return value != null ? value : defaultValue; return value != null ? value : defaultValue;
} }
/** /**
* * 判断一个Collection是否为空 包含ListSetQueue * * 判断一个Collection是否为空 包含ListSetQueue
* *
* @param coll 要判断的Collection * @param coll 要判断的Collection
* @return true为空 false非空 * @return true为空 false非空
*/ */
public static boolean isEmpty(Collection<?> coll) public static boolean isEmpty(Collection<?> coll) {
{
return isNull(coll) || coll.isEmpty(); return isNull(coll) || coll.isEmpty();
} }
/** /**
* * 判断一个Collection是否非空包含ListSetQueue * * 判断一个Collection是否非空包含ListSetQueue
* *
* @param coll 要判断的Collection * @param coll 要判断的Collection
* @return true非空 false * @return true非空 false
*/ */
public static boolean isNotEmpty(Collection<?> coll) public static boolean isNotEmpty(Collection<?> coll) {
{
return !isEmpty(coll); return !isEmpty(coll);
} }
/** /**
* * 判断一个对象数组是否为空 * * 判断一个对象数组是否为空
* *
* @param objects 要判断的对象数组 * @param objects 要判断的对象数组
** @return true为空 false非空 * * @return true为空 false非空
*/ */
public static boolean isEmpty(Object[] objects) public static boolean isEmpty(Object[] objects) {
{
return isNull(objects) || (objects.length == 0); return isNull(objects) || (objects.length == 0);
} }
/** /**
* * 判断一个对象数组是否非空 * * 判断一个对象数组是否非空
* *
* @param objects 要判断的对象数组 * @param objects 要判断的对象数组
* @return true非空 false * @return true非空 false
*/ */
public static boolean isNotEmpty(Object[] objects) public static boolean isNotEmpty(Object[] objects) {
{
return !isEmpty(objects); return !isEmpty(objects);
} }
/** /**
* * 判断一个Map是否为空 * * 判断一个Map是否为空
* *
* @param map 要判断的Map * @param map 要判断的Map
* @return true为空 false非空 * @return true为空 false非空
*/ */
public static boolean isEmpty(Map<?, ?> map) public static boolean isEmpty(Map<?, ?> map) {
{
return isNull(map) || map.isEmpty(); return isNull(map) || map.isEmpty();
} }
/** /**
* * 判断一个Map是否为空 * * 判断一个Map是否为空
* *
* @param map 要判断的Map * @param map 要判断的Map
* @return true非空 false * @return true非空 false
*/ */
public static boolean isNotEmpty(Map<?, ?> map) public static boolean isNotEmpty(Map<?, ?> map) {
{
return !isEmpty(map); return !isEmpty(map);
} }
/** /**
* * 判断一个字符串是否为空串 * * 判断一个字符串是否为空串
* *
* @param str String * @param str String
* @return true为空 false非空 * @return true为空 false非空
*/ */
public static boolean isEmpty(String str) public static boolean isEmpty(String str) {
{
return isNull(str) || NULLSTR.equals(str.trim()); return isNull(str) || NULLSTR.equals(str.trim());
} }
/** /**
* * 判断一个字符串是否为非空串 * * 判断一个字符串是否为非空串
* *
* @param str String * @param str String
* @return true非空串 false空串 * @return true非空串 false空串
*/ */
public static boolean isNotEmpty(String str) public static boolean isNotEmpty(String str) {
{
return !isEmpty(str); return !isEmpty(str);
} }
/** /**
* * 判断一个对象是否为空 * * 判断一个对象是否为空
* *
* @param object Object * @param object Object
* @return true为空 false非空 * @return true为空 false非空
*/ */
public static boolean isNull(Object object) public static boolean isNull(Object object) {
{
return object == null; return object == null;
} }
/** /**
* * 判断一个对象是否非空 * * 判断一个对象是否非空
* *
* @param object Object * @param object Object
* @return true非空 false * @return true非空 false
*/ */
public static boolean isNotNull(Object object) public static boolean isNotNull(Object object) {
{
return !isNull(object); return !isNull(object);
} }
/** /**
* * 判断一个对象是否是数组类型Java基本型别的数组 * * 判断一个对象是否是数组类型Java基本型别的数组
* *
* @param object 对象 * @param object 对象
* @return true是数组 false不是数组 * @return true是数组 false不是数组
*/ */
public static boolean isArray(Object object) public static boolean isArray(Object object) {
{
return isNotNull(object) && object.getClass().isArray(); return isNotNull(object) && object.getClass().isArray();
} }
/** /**
* 去空格 * 去空格
*/ */
public static String trim(String str) public static String trim(String str) {
{
return (str == null ? "" : str.trim()); return (str == null ? "" : str.trim());
} }
/** /**
* 截取字符串 * 截取字符串
* *
* @param str 字符串 * @param str 字符串
* @param start 开始 * @param start 开始
* @return 结果 * @return 结果
*/ */
public static String substring(final String str, int start) public static String substring(final String str, int start) {
{ if (str == null) {
if (str == null)
{
return NULLSTR; return NULLSTR;
} }
if (start < 0) if (start < 0) {
{
start = str.length() + start; start = str.length() + start;
} }
if (start < 0) if (start < 0) {
{
start = 0; start = 0;
} }
if (start > str.length()) if (start > str.length()) {
{
return NULLSTR; return NULLSTR;
} }
@ -194,44 +180,36 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/** /**
* 截取字符串 * 截取字符串
* *
* @param str 字符串 * @param str 字符串
* @param start 开始 * @param start 开始
* @param end 结束 * @param end 结束
* @return 结果 * @return 结果
*/ */
public static String substring(final String str, int start, int end) public static String substring(final String str, int start, int end) {
{ if (str == null) {
if (str == null)
{
return NULLSTR; return NULLSTR;
} }
if (end < 0) if (end < 0) {
{
end = str.length() + end; end = str.length() + end;
} }
if (start < 0) if (start < 0) {
{
start = str.length() + start; start = str.length() + start;
} }
if (end > str.length()) if (end > str.length()) {
{
end = str.length(); end = str.length();
} }
if (start > end) if (start > end) {
{
return NULLSTR; return NULLSTR;
} }
if (start < 0) if (start < 0) {
{
start = 0; start = 0;
} }
if (end < 0) if (end < 0) {
{
end = 0; end = 0;
} }
@ -246,15 +224,13 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
* 通常使用format("this is {} for {}", "a", "b") -> this is a for b<br> * 通常使用format("this is {} for {}", "a", "b") -> this is a for b<br>
* 转义{} format("this is \\{} for {}", "a", "b") -> this is \{} for a<br> * 转义{} format("this is \\{} for {}", "a", "b") -> this is \{} for a<br>
* 转义\ format("this is \\\\{} for {}", "a", "b") -> this is \a for b<br> * 转义\ format("this is \\\\{} for {}", "a", "b") -> this is \a for b<br>
* *
* @param template 文本模板被替换的部分用 {} 表示 * @param template 文本模板被替换的部分用 {} 表示
* @param params 参数值 * @param params 参数值
* @return 格式化后的文本 * @return 格式化后的文本
*/ */
public static String format(String template, Object... params) public static String format(String template, Object... params) {
{ if (isEmpty(params) || isEmpty(template)) {
if (isEmpty(params) || isEmpty(template))
{
return template; return template;
} }
return StrFormatter.format(template, params); return StrFormatter.format(template, params);
@ -262,47 +238,40 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/** /**
* 字符串转set * 字符串转set
* *
* @param str 字符串 * @param str 字符串
* @param sep 分隔符 * @param sep 分隔符
* @return set集合 * @return set集合
*/ */
public static final Set<String> str2Set(String str, String sep) public static final Set<String> str2Set(String str, String sep) {
{
return new HashSet<String>(str2List(str, sep, true, false)); return new HashSet<String>(str2List(str, sep, true, false));
} }
/** /**
* 字符串转list * 字符串转list
* *
* @param str 字符串 * @param str 字符串
* @param sep 分隔符 * @param sep 分隔符
* @param filterBlank 过滤纯空白 * @param filterBlank 过滤纯空白
* @param trim 去掉首尾空白 * @param trim 去掉首尾空白
* @return list集合 * @return list集合
*/ */
public static final List<String> str2List(String str, String sep, boolean filterBlank, boolean trim) public static final List<String> str2List(String str, String sep, boolean filterBlank, boolean trim) {
{
List<String> list = new ArrayList<String>(); List<String> list = new ArrayList<String>();
if (StringUtils.isEmpty(str)) if (StringUtils.isEmpty(str)) {
{
return list; return list;
} }
// 过滤空白字符串 // 过滤空白字符串
if (filterBlank && StringUtils.isBlank(str)) if (filterBlank && StringUtils.isBlank(str)) {
{
return list; return list;
} }
String[] split = str.split(sep); String[] split = str.split(sep);
for (String string : split) for (String string : split) {
{ if (filterBlank && StringUtils.isBlank(string)) {
if (filterBlank && StringUtils.isBlank(string))
{
continue; continue;
} }
if (trim) if (trim) {
{
string = string.trim(); string = string.trim();
} }
list.add(string); list.add(string);
@ -314,10 +283,8 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/** /**
* 下划线转驼峰命名 * 下划线转驼峰命名
*/ */
public static String toUnderScoreCase(String str) public static String toUnderScoreCase(String str) {
{ if (str == null) {
if (str == null)
{
return null; return null;
} }
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
@ -327,31 +294,23 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
boolean curreCharIsUpperCase = true; boolean curreCharIsUpperCase = true;
// 下一字符是否大写 // 下一字符是否大写
boolean nexteCharIsUpperCase = true; boolean nexteCharIsUpperCase = true;
for (int i = 0; i < str.length(); i++) for (int i = 0; i < str.length(); i++) {
{
char c = str.charAt(i); char c = str.charAt(i);
if (i > 0) if (i > 0) {
{
preCharIsUpperCase = Character.isUpperCase(str.charAt(i - 1)); preCharIsUpperCase = Character.isUpperCase(str.charAt(i - 1));
} } else {
else
{
preCharIsUpperCase = false; preCharIsUpperCase = false;
} }
curreCharIsUpperCase = Character.isUpperCase(c); curreCharIsUpperCase = Character.isUpperCase(c);
if (i < (str.length() - 1)) if (i < (str.length() - 1)) {
{
nexteCharIsUpperCase = Character.isUpperCase(str.charAt(i + 1)); nexteCharIsUpperCase = Character.isUpperCase(str.charAt(i + 1));
} }
if (preCharIsUpperCase && curreCharIsUpperCase && !nexteCharIsUpperCase) if (preCharIsUpperCase && curreCharIsUpperCase && !nexteCharIsUpperCase) {
{
sb.append(SEPARATOR); sb.append(SEPARATOR);
} } else if ((i != 0 && !preCharIsUpperCase) && curreCharIsUpperCase) {
else if ((i != 0 && !preCharIsUpperCase) && curreCharIsUpperCase)
{
sb.append(SEPARATOR); sb.append(SEPARATOR);
} }
sb.append(Character.toLowerCase(c)); sb.append(Character.toLowerCase(c));
@ -362,19 +321,15 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/** /**
* 是否包含字符串 * 是否包含字符串
* *
* @param str 验证字符串 * @param str 验证字符串
* @param strs 字符串组 * @param strs 字符串组
* @return 包含返回true * @return 包含返回true
*/ */
public static boolean inStringIgnoreCase(String str, String... strs) public static boolean inStringIgnoreCase(String str, String... strs) {
{ if (str != null && strs != null) {
if (str != null && strs != null) for (String s : strs) {
{ if (str.equalsIgnoreCase(trim(s))) {
for (String s : strs)
{
if (str.equalsIgnoreCase(trim(s)))
{
return true; return true;
} }
} }
@ -384,31 +339,25 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/** /**
* 将下划线大写方式命名的字符串转换为驼峰式如果转换前的下划线大写方式命名的字符串为空则返回空字符串 例如HELLO_WORLD->HelloWorld * 将下划线大写方式命名的字符串转换为驼峰式如果转换前的下划线大写方式命名的字符串为空则返回空字符串 例如HELLO_WORLD->HelloWorld
* *
* @param name 转换前的下划线大写方式命名的字符串 * @param name 转换前的下划线大写方式命名的字符串
* @return 转换后的驼峰式命名的字符串 * @return 转换后的驼峰式命名的字符串
*/ */
public static String convertToCamelCase(String name) public static String convertToCamelCase(String name) {
{
StringBuilder result = new StringBuilder(); StringBuilder result = new StringBuilder();
// 快速检查 // 快速检查
if (name == null || name.isEmpty()) if (name == null || name.isEmpty()) {
{
// 没必要转换 // 没必要转换
return ""; return "";
} } else if (!name.contains("_")) {
else if (!name.contains("_"))
{
// 不含下划线仅将首字母大写 // 不含下划线仅将首字母大写
return name.substring(0, 1).toUpperCase() + name.substring(1); return name.substring(0, 1).toUpperCase() + name.substring(1);
} }
// 用下划线将原始字符串分割 // 用下划线将原始字符串分割
String[] camels = name.split("_"); String[] camels = name.split("_");
for (String camel : camels) for (String camel : camels) {
{
// 跳过原始字符串中开头结尾的下换线或双重下划线 // 跳过原始字符串中开头结尾的下换线或双重下划线
if (camel.isEmpty()) if (camel.isEmpty()) {
{
continue; continue;
} }
// 首字母大写 // 首字母大写
@ -421,30 +370,22 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/** /**
* 驼峰式命名法 例如user_name->userName * 驼峰式命名法 例如user_name->userName
*/ */
public static String toCamelCase(String s) public static String toCamelCase(String s) {
{ if (s == null) {
if (s == null)
{
return null; return null;
} }
s = s.toLowerCase(); s = s.toLowerCase();
StringBuilder sb = new StringBuilder(s.length()); StringBuilder sb = new StringBuilder(s.length());
boolean upperCase = false; boolean upperCase = false;
for (int i = 0; i < s.length(); i++) for (int i = 0; i < s.length(); i++) {
{
char c = s.charAt(i); char c = s.charAt(i);
if (c == SEPARATOR) if (c == SEPARATOR) {
{
upperCase = true; upperCase = true;
} } else if (upperCase) {
else if (upperCase)
{
sb.append(Character.toUpperCase(c)); sb.append(Character.toUpperCase(c));
upperCase = false; upperCase = false;
} } else {
else
{
sb.append(c); sb.append(c);
} }
} }
@ -452,8 +393,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static <T> T cast(Object obj) public static <T> T cast(Object obj) {
{
return (T) obj; return (T) obj;
} }
} }

View File

@ -3,6 +3,7 @@ package com.hchyun.framework.dao;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.PreDestroy; import javax.annotation.PreDestroy;
/** /**
@ -11,28 +12,22 @@ import javax.annotation.PreDestroy;
* @author hchyun * @author hchyun
*/ */
@Component @Component
public class ShutdownDao public class ShutdownDao {
{
private static final Logger logger = LoggerFactory.getLogger("sys-user"); private static final Logger logger = LoggerFactory.getLogger("sys-user");
@PreDestroy @PreDestroy
public void destroy() public void destroy() {
{
shutdownAsyncManager(); shutdownAsyncManager();
} }
/** /**
* 停止异步执行任务 * 停止异步执行任务
*/ */
private void shutdownAsyncManager() private void shutdownAsyncManager() {
{ try {
try
{
logger.info("====关闭后台任务任务线程池===="); logger.info("====关闭后台任务任务线程池====");
AsyncDao.me().shutdown(); AsyncDao.me().shutdown();
} } catch (Exception e) {
catch (Exception e)
{
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);
} }
} }

View File

@ -0,0 +1,82 @@
package com.hchyun.generator.controller;
import com.hchyun.common.constant.ReturnConstants;
import com.hchyun.common.core.entity.AjaxResult;
import com.hchyun.common.utils.ServerResult;
import com.hchyun.generator.entity.AssColumn;
import com.hchyun.generator.service.AssociatedService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
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/5 17:38
* @Version 1.0
*/
@RestController
@Api("关联查询")
@RequestMapping("/ass")
public class AssociatedController {
private Logger logger = LoggerFactory.getLogger(AssociatedController.class);
@Autowired
private AssociatedService associatedService;
@ApiOperation("tableid")
@GetMapping("/{tableId}")
private AjaxResult assColumnsByTable(@PathVariable("tableId")Long tableId){
try {
ServerResult<List<AssColumn>> serverResult = associatedService.assColumnsByTable(tableId);
if (serverResult.isStart()){
return AjaxResult.success(serverResult.getData());
}else {
return AjaxResult.error(serverResult.getMsg());
}
}catch (RuntimeException e){
logger.error(e.getMessage());
return AjaxResult.error();
}
}
@ApiOperation("获取表信息")
@GetMapping("/tableinfos")
public AjaxResult tableInfos(){
try {
ServerResult<List<Map<String,Object>>> serverResult = associatedService.tableInfos();
if (serverResult.isStart()){
return AjaxResult.success(serverResult.getData());
}else {
return AjaxResult.error(serverResult.getMsg());
}
}catch (RuntimeException e){
logger.error(e.getMessage());
return AjaxResult.error(ReturnConstants.SYS_ERROR);
}
}
@ApiOperation("关联表字段")
@GetMapping("/{tableName}/{tableId}")
public AjaxResult assColumns(@PathVariable("tableName")String tableName,@PathVariable("tableId") Long tableId){
try {
ServerResult<List<AssColumn>> serverResult = associatedService.assColumns(tableName, tableId);
if (serverResult.isStart()){
return AjaxResult.success(serverResult.getData());
}else {
return AjaxResult.error(serverResult.getMsg());
}
}catch (RuntimeException e){
logger.error(e.getMessage());
return AjaxResult.error(ReturnConstants.SYS_ERROR);
}
}
}

View File

@ -35,7 +35,7 @@ import java.util.Map;
@Api("query") @Api("query")
@RequestMapping("/query") @RequestMapping("/query")
public class QueryController extends BaseController { public class QueryController extends BaseController {
protected final Logger logger = LoggerFactory.getLogger(QueryController.class); private Logger logger = LoggerFactory.getLogger(QueryController.class);
@Autowired @Autowired

View File

@ -1,44 +0,0 @@
package com.hchyun.generator.controller;
import com.hchyun.generator.dao.ApiclassDao;
import com.hchyun.generator.dao.InterTableDao;
import com.hchyun.generator.entity.Apiclass;
import com.hchyun.generator.entity.InterTable;
import com.hchyun.generator.service.InterTableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/tests")
public class SysTest {
@Autowired
private InterTableDao interTableDao;
@Autowired
private InterTableService interTableService;
@GetMapping("/1")
public Apiclass test() {
return interTableDao.selectInterTableClass(3L);
}
@GetMapping("/2")
public List<InterTable> test2() {
return interTableDao.selectInterTableModule(3L);
}
@GetMapping("/3")
public Map<String, String> test3(){
return interTableService.previewCodeCalss(3L).getData();
}
@GetMapping("/4")
public Map<String,Object> test4(){
return interTableService.previewCodeMoudle(3L).getData();
}
}

View File

@ -0,0 +1,48 @@
package com.hchyun.generator.dao;
import com.hchyun.generator.entity.AssColumn;
import java.util.List;
import java.util.Map;
/**
* @Author 18209
* @Date 2021/2/5 17:41
* @Version 1.0
*/
public interface AssociatedDao {
/**
* 获取表信息
* @return
*/
List<Map<String,Object>> tableInfos();
/**
* 获取表字段信息
* @param tableName
* @return
*/
List<AssColumn> selectTableColumn(String tableName);
/**
* 通过tableId删除字段信息
* @param tableId
* @return
*/
Integer deleteTableColumn(Long tableId);
/**
* 批量增加字段信息
* @param assColumns
* @return
*/
Integer insertColumns(List<AssColumn> assColumns);
/**
* 通过tableId获取字段信息
* @param tableId
* @return
*/
List<AssColumn> selectTableColumnByTableId(Long tableId);
}

View File

@ -0,0 +1,155 @@
package com.hchyun.generator.entity;
public class AssColumn {
private long id;
private long tableId;
private String columnName;
private String columnComment;
private String columnType;
private String javaType;
private String javaField;
private String isList;
private String isQuery;
private String queryType;
private String htmlType;
private String dictType;
private Integer sort;
private long createBy;
private long updateBy;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public long getTableId() {
return tableId;
}
public void setTableId(long tableId) {
this.tableId = tableId;
}
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;
}
public long getUpdateBy() {
return updateBy;
}
public void setUpdateBy(long updateBy) {
this.updateBy = updateBy;
}
}

View File

@ -77,6 +77,9 @@ public class GenTable extends BaseEntity
@Valid @Valid
private List<GenTableColumn> columns; private List<GenTableColumn> columns;
private List<AssColumn> assColumns;
/** 其它生成选项 */ /** 其它生成选项 */
private String options; private String options;
@ -95,6 +98,45 @@ public class GenTable extends BaseEntity
/** 上级菜单名称字段 */ /** 上级菜单名称字段 */
private String parentMenuName; private String parentMenuName;
private String assTableName;
private String assTableColumn;
private String assTableFkColumn;
public List<AssColumn> getAssColumns() {
return assColumns;
}
public void setAssColumns(List<AssColumn> assColumns) {
this.assColumns = assColumns;
}
public String getAssTableName() {
return assTableName;
}
public void setAssTableName(String assTableName) {
this.assTableName = assTableName;
}
public String getAssTableColumn() {
return assTableColumn;
}
public void setAssTableColumn(String assTableColumn) {
this.assTableColumn = assTableColumn;
}
public String getAssTableFkColumn() {
return assTableFkColumn;
}
public void setAssTableFkColumn(String assTableFkColumn) {
this.assTableFkColumn = assTableFkColumn;
}
public Long getTableId() public Long getTableId()
{ {
return tableId; return tableId;

View File

@ -1,77 +1,117 @@
package com.hchyun.generator.entity; package com.hchyun.generator.entity;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import com.hchyun.common.core.entity.BaseEntity; import com.hchyun.common.core.entity.BaseEntity;
import com.hchyun.common.utils.StringUtils; import com.hchyun.common.utils.StringUtils;
/** /**
* 代码生成业务字段表 gen_table_column * 代码生成业务字段表 gen_table_column
* *
* @author hchyun * @author hchyun
*/ */
public class GenTableColumn extends BaseEntity public class GenTableColumn extends BaseEntity {
{
/** 编号 */ /**
* 编号
*/
private Long columnId; private Long columnId;
/** 归属表编号 */ /**
* 归属表编号
*/
private Long tableId; private Long tableId;
/** 列名称 */ /**
* 列名称
*/
private String columnName; private String columnName;
/** 列描述 */ /**
* 列描述
*/
private String columnComment; private String columnComment;
/** 列类型 */ /**
* 列类型
*/
private String columnType; private String columnType;
/** JAVA类型 */ /**
* JAVA类型
*/
private String javaType; private String javaType;
/** JAVA字段名 */ /**
* JAVA字段名
*/
@NotBlank(message = "Java属性不能为空") @NotBlank(message = "Java属性不能为空")
private String javaField; private String javaField;
/** 是否主键1是 */ /**
* 是否主键1是
*/
private String isPk; private String isPk;
/** 是否自增1是 */ /**
* 是否自增1是
*/
private String isIncrement; private String isIncrement;
/** 是否必填1是 */ /**
* 是否必填1是
*/
private String isRequired; private String isRequired;
/** 是否为插入字段1是 */ /**
* 是否为插入字段1是
*/
private String isInsert; private String isInsert;
/** 是否编辑字段1是 */ /**
* 是否编辑字段1是
*/
private String isEdit; private String isEdit;
/** 是否列表字段1是 */ /**
* 是否列表字段1是
*/
private String isList; private String isList;
/** 是否查询字段1是 */ /**
* 是否查询字段1是
*/
private String isQuery; private String isQuery;
/** 是否正则(1否)*/ /**
* 是否正则(1否)
*/
private Long isRegular; private Long isRegular;
/** 正则表达式内容 */ /**
* 正则表达式内容
*/
private String regular; private String regular;
/** 查询方式EQ等于、NE不等于、GT大于、LT小于、LIKE模糊、BETWEEN范围 */ /**
* 查询方式EQ等于NE不等于GT大于LT小于LIKE模糊BETWEEN范围
*/
private String queryType; private String queryType;
/** 显示类型input文本框、textarea文本域、select下拉框、checkbox复选框、radio单选框、datetime日期控件、image图片上传控件、upload文件上传控件、editor富文本控件 */ /**
* 显示类型input文本框textarea文本域select下拉框checkbox复选框radio单选框datetime日期控件image图片上传控件upload文件上传控件editor富文本控件
*/
private String htmlType; private String htmlType;
/** 字典类型 */ /**
* 字典类型
*/
private String dictType; private String dictType;
/** 排序 */ /**
* 排序
*/
private Integer sort; private Integer sort;
@ -91,268 +131,215 @@ public class GenTableColumn extends BaseEntity
this.regular = regular; this.regular = regular;
} }
public void setColumnId(Long columnId) public void setColumnId(Long columnId) {
{
this.columnId = columnId; this.columnId = columnId;
} }
public Long getColumnId() public Long getColumnId() {
{
return columnId; return columnId;
} }
public void setTableId(Long tableId) public void setTableId(Long tableId) {
{
this.tableId = tableId; this.tableId = tableId;
} }
public Long getTableId() public Long getTableId() {
{
return tableId; return tableId;
} }
public void setColumnName(String columnName) public void setColumnName(String columnName) {
{
this.columnName = columnName; this.columnName = columnName;
} }
public String getColumnName() public String getColumnName() {
{
return columnName; return columnName;
} }
public void setColumnComment(String columnComment) public void setColumnComment(String columnComment) {
{
this.columnComment = columnComment; this.columnComment = columnComment;
} }
public String getColumnComment() public String getColumnComment() {
{
return columnComment; return columnComment;
} }
public void setColumnType(String columnType) public void setColumnType(String columnType) {
{
this.columnType = columnType; this.columnType = columnType;
} }
public String getColumnType() public String getColumnType() {
{
return columnType; return columnType;
} }
public void setJavaType(String javaType) public void setJavaType(String javaType) {
{
this.javaType = javaType; this.javaType = javaType;
} }
public String getJavaType() public String getJavaType() {
{
return javaType; return javaType;
} }
public void setJavaField(String javaField) public void setJavaField(String javaField) {
{
this.javaField = javaField; this.javaField = javaField;
} }
public String getJavaField() public String getJavaField() {
{
return javaField; return javaField;
} }
public String getCapJavaField() public String getCapJavaField() {
{
return StringUtils.capitalize(javaField); return StringUtils.capitalize(javaField);
} }
public void setIsPk(String isPk) public void setIsPk(String isPk) {
{
this.isPk = isPk; this.isPk = isPk;
} }
public String getIsPk() public String getIsPk() {
{
return isPk; return isPk;
} }
public boolean isPk() public boolean isPk() {
{
return isPk(this.isPk); return isPk(this.isPk);
} }
public boolean isPk(String isPk) public boolean isPk(String isPk) {
{
return isPk != null && StringUtils.equals("1", isPk); return isPk != null && StringUtils.equals("1", isPk);
} }
public String getIsIncrement() public String getIsIncrement() {
{
return isIncrement; return isIncrement;
} }
public void setIsIncrement(String isIncrement) public void setIsIncrement(String isIncrement) {
{
this.isIncrement = isIncrement; this.isIncrement = isIncrement;
} }
public boolean isIncrement() public boolean isIncrement() {
{
return isIncrement(this.isIncrement); return isIncrement(this.isIncrement);
} }
public boolean isIncrement(String isIncrement) public boolean isIncrement(String isIncrement) {
{
return isIncrement != null && StringUtils.equals("1", isIncrement); return isIncrement != null && StringUtils.equals("1", isIncrement);
} }
public void setIsRequired(String isRequired) public void setIsRequired(String isRequired) {
{
this.isRequired = isRequired; this.isRequired = isRequired;
} }
public String getIsRequired() public String getIsRequired() {
{
return isRequired; return isRequired;
} }
public boolean isRequired() public boolean isRequired() {
{
return isRequired(this.isRequired); return isRequired(this.isRequired);
} }
public boolean isRequired(String isRequired) public boolean isRequired(String isRequired) {
{
return isRequired != null && StringUtils.equals("1", isRequired); return isRequired != null && StringUtils.equals("1", isRequired);
} }
public void setIsInsert(String isInsert) public void setIsInsert(String isInsert) {
{
this.isInsert = isInsert; this.isInsert = isInsert;
} }
public String getIsInsert() public String getIsInsert() {
{
return isInsert; return isInsert;
} }
public boolean isInsert() public boolean isInsert() {
{
return isInsert(this.isInsert); return isInsert(this.isInsert);
} }
public boolean isInsert(String isInsert) public boolean isInsert(String isInsert) {
{
return isInsert != null && StringUtils.equals("1", isInsert); return isInsert != null && StringUtils.equals("1", isInsert);
} }
public void setIsEdit(String isEdit) public void setIsEdit(String isEdit) {
{
this.isEdit = isEdit; this.isEdit = isEdit;
} }
public String getIsEdit() public String getIsEdit() {
{
return isEdit; return isEdit;
} }
public boolean isEdit() public boolean isEdit() {
{
return isInsert(this.isEdit); return isInsert(this.isEdit);
} }
public boolean isEdit(String isEdit) public boolean isEdit(String isEdit) {
{
return isEdit != null && StringUtils.equals("1", isEdit); return isEdit != null && StringUtils.equals("1", isEdit);
} }
public void setIsList(String isList) public void setIsList(String isList) {
{
this.isList = isList; this.isList = isList;
} }
public String getIsList() public String getIsList() {
{
return isList; return isList;
} }
public boolean isList() public boolean isList() {
{
return isList(this.isList); return isList(this.isList);
} }
public boolean isList(String isList) public boolean isList(String isList) {
{
return isList != null && StringUtils.equals("1", isList); return isList != null && StringUtils.equals("1", isList);
} }
public void setIsQuery(String isQuery) public void setIsQuery(String isQuery) {
{
this.isQuery = isQuery; this.isQuery = isQuery;
} }
public String getIsQuery() public String getIsQuery() {
{
return isQuery; return isQuery;
} }
public boolean isQuery() public boolean isQuery() {
{
return isQuery(this.isQuery); return isQuery(this.isQuery);
} }
public boolean isQuery(String isQuery) public boolean isQuery(String isQuery) {
{
return isQuery != null && StringUtils.equals("1", isQuery); return isQuery != null && StringUtils.equals("1", isQuery);
} }
public void setQueryType(String queryType) public void setQueryType(String queryType) {
{
this.queryType = queryType; this.queryType = queryType;
} }
public String getQueryType() public String getQueryType() {
{
return queryType; return queryType;
} }
public String getHtmlType() public String getHtmlType() {
{
return htmlType; return htmlType;
} }
public void setHtmlType(String htmlType) public void setHtmlType(String htmlType) {
{
this.htmlType = htmlType; this.htmlType = htmlType;
} }
public void setDictType(String dictType) public void setDictType(String dictType) {
{
this.dictType = dictType; this.dictType = dictType;
} }
public String getDictType() public String getDictType() {
{
return dictType; return dictType;
} }
public void setSort(Integer sort) public void setSort(Integer sort) {
{
this.sort = sort; this.sort = sort;
} }
public Integer getSort() public Integer getSort() {
{
return sort; return sort;
} }
public boolean isSuperColumn() public boolean isSuperColumn() {
{
return isSuperColumn(this.javaField); return isSuperColumn(this.javaField);
} }
public static boolean isSuperColumn(String javaField) public static boolean isSuperColumn(String javaField) {
{
return StringUtils.equalsAnyIgnoreCase(javaField, return StringUtils.equalsAnyIgnoreCase(javaField,
// BaseEntity // BaseEntity
"createBy", "createTime", "updateBy", "updateTime", "remark", "createBy", "createTime", "updateBy", "updateTime", "remark",
@ -360,36 +347,28 @@ public class GenTableColumn extends BaseEntity
"parentName", "parentId", "orderNum", "ancestors"); "parentName", "parentId", "orderNum", "ancestors");
} }
public boolean isUsableColumn() public boolean isUsableColumn() {
{
return isUsableColumn(javaField); return isUsableColumn(javaField);
} }
public static boolean isUsableColumn(String javaField) public static boolean isUsableColumn(String javaField) {
{
// isSuperColumn()中的名单用于避免生成多余Domain属性若某些属性在生成页面时需要用到不能忽略则放在此处白名单 // isSuperColumn()中的名单用于避免生成多余Domain属性若某些属性在生成页面时需要用到不能忽略则放在此处白名单
return StringUtils.equalsAnyIgnoreCase(javaField, "parentId", "orderNum", "remark"); return StringUtils.equalsAnyIgnoreCase(javaField, "parentId", "orderNum", "remark");
} }
public String readConverterExp() public String readConverterExp() {
{
String remarks = StringUtils.substringBetween(this.columnComment, "", ""); String remarks = StringUtils.substringBetween(this.columnComment, "", "");
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
if (StringUtils.isNotEmpty(remarks)) if (StringUtils.isNotEmpty(remarks)) {
{ for (String value : remarks.split(" ")) {
for (String value : remarks.split(" ")) if (StringUtils.isNotEmpty(value)) {
{
if (StringUtils.isNotEmpty(value))
{
Object startStr = value.subSequence(0, 1); Object startStr = value.subSequence(0, 1);
String endStr = value.substring(1); String endStr = value.substring(1);
sb.append("").append(startStr).append("=").append(endStr).append(","); sb.append("").append(startStr).append("=").append(endStr).append(",");
} }
} }
return sb.deleteCharAt(sb.length() - 1).toString(); return sb.deleteCharAt(sb.length() - 1).toString();
} } else {
else
{
return this.columnComment; return this.columnComment;
} }
} }

View File

@ -0,0 +1,38 @@
package com.hchyun.generator.service;
import com.hchyun.common.utils.ServerResult;
import com.hchyun.generator.entity.AssColumn;
import java.util.List;
import java.util.Map;
/**
* @Author 18209
* @Date 2021/2/5 17:56
* @Version 1.0
*/
public interface AssociatedService {
/**
* 获取到数据库表信息
* @return
*/
ServerResult<List<Map<String,Object>>> tableInfos();
/**
* 获取到关联边字段信息
* @param tableName 关联表表名
* @param tableId 关联关系id
* @return
*/
ServerResult<List<AssColumn>> assColumns(String tableName,Long tableId);
/**
* 通过table获取到关联信息
* @param tableId
* @return
*/
ServerResult<List<AssColumn>> assColumnsByTable(Long tableId);
}

View File

@ -0,0 +1,64 @@
package com.hchyun.generator.service.impl;
import com.hchyun.common.constant.ReturnConstants;
import com.hchyun.common.utils.ServerResult;
import com.hchyun.generator.dao.AssociatedDao;
import com.hchyun.generator.entity.AssColumn;
import com.hchyun.generator.service.AssociatedService;
import com.hchyun.generator.util.AssociatedUtils;
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/5 17:56
* @Version 1.0
*/
@Service
public class AssociatedServiceImpl implements AssociatedService {
private Logger logger = LoggerFactory.getLogger(AssociatedServiceImpl.class);
@Autowired
private AssociatedDao associatedDao;
@Override
public ServerResult<List<AssColumn>> assColumnsByTable(Long tableId) {
try {
List<AssColumn> assColumns = associatedDao.selectTableColumnByTableId(tableId);
return new ServerResult<>(true,assColumns);
}catch (RuntimeException e){
logger.error(e.getMessage());
return new ServerResult<>(false,ReturnConstants.DB_EX);
}
}
@Override
public ServerResult<List<Map<String, Object>>> tableInfos() {
try {
List<Map<String, Object>> dataMap = associatedDao.tableInfos();
return new ServerResult<>(true, dataMap);
} catch (RuntimeException e) {
logger.error(e.getMessage());
return new ServerResult<>(false, ReturnConstants.DB_EX);
}
}
@Override
public ServerResult<List<AssColumn>> assColumns(String tableName, Long tableId) {
try {
List<AssColumn> assColumns = associatedDao.selectTableColumn(tableName);
for (AssColumn assColumn : assColumns) {
AssociatedUtils.initAssColumn(assColumn, tableId);
}
return new ServerResult<>(true, assColumns);
} catch (RuntimeException e) {
logger.error(e.getMessage());
return new ServerResult<>(false, ReturnConstants.DB_EX);
}
}
}

View File

@ -11,6 +11,9 @@ import java.util.stream.Collectors;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
import com.hchyun.common.constant.ReturnConstants;
import com.hchyun.generator.dao.AssociatedDao;
import com.hchyun.generator.entity.AssColumn;
import com.hchyun.generator.service.IGenTableService; import com.hchyun.generator.service.IGenTableService;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.velocity.Template; import org.apache.velocity.Template;
@ -54,6 +57,9 @@ public class GenTableServiceImpl implements IGenTableService {
@Autowired @Autowired
private GenTableColumnDao genTableColumnDao; private GenTableColumnDao genTableColumnDao;
@Autowired
private AssociatedDao associatedDao;
/** /**
* 查询业务信息 * 查询业务信息
* *
@ -119,14 +125,22 @@ public class GenTableServiceImpl implements IGenTableService {
@Override @Override
@Transactional @Transactional
public void updateGenTable(GenTable genTable) { public void updateGenTable(GenTable genTable) {
String options = JSON.toJSONString(genTable.getParams()); try {
genTable.setOptions(options); String options = JSON.toJSONString(genTable.getParams());
int row = genTableDao.updateGenTable(genTable); genTable.setOptions(options);
if (row > 0) { int row = genTableDao.updateGenTable(genTable);
// for (GenTableColumn cenTableColumn : genTable.getColumns()) if (row > 0) {
// { genTableColumnDao.updateGenTableColumn(genTable.getColumns());
genTableColumnDao.updateGenTableColumn(genTable.getColumns()); List<AssColumn> assColumns = genTable.getAssColumns();
// } if (assColumns.size() > 0){
associatedDao.deleteTableColumn(genTable.getTableId());
associatedDao.insertColumns(assColumns);
}
}
}catch (CustomException e){
log.error(e.getMessage());
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
throw new CustomException(ReturnConstants.DB_EX);
} }
} }

View File

@ -0,0 +1,77 @@
package com.hchyun.generator.util;
import com.hchyun.common.constant.GenConstants;
import com.hchyun.common.utils.StringUtils;
import com.hchyun.generator.entity.AssColumn;
import org.apache.commons.lang3.RegExUtils;
/**
* @Author 18209
* @Date 2021/2/6 14:48
* @Version 1.0
*/
public class AssociatedUtils {
public static void initAssColumn(AssColumn assColumn, Long tableId) {
//获取数据库数据类型
String dataType = GenUtils.getDbType(assColumn.getColumnType());
//获取字段名称
String columnName = assColumn.getColumnName();
//设置tableid
assColumn.setTableId(tableId);
//设置创建者id
assColumn.setCreateBy(1);
//转为设置java字段名称
assColumn.setJavaField(StringUtils.toCamelCase(columnName));
//默认类型
assColumn.setJavaType(GenConstants.TYPE_STRING);
//默认查询条件 精确查询
assColumn.setQueryType(GenConstants.QUERY_EQ);
if (GenUtils.arraysContains(GenConstants.COLUMNTYPE_STR, dataType) || GenUtils.arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType)) {
//字符串长度超500设置htmlType为文本域
Integer columnLength = GenUtils.getColumnLength(assColumn.getColumnType());
String htmlType = columnLength >= 500 || GenUtils.arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType) ? GenConstants.HTML_TEXTAREA : GenConstants.HTML_INPUT;
assColumn.setHtmlType(htmlType);
} else if (GenUtils.arraysContains(GenConstants.COLUMNTYPE_TIME, dataType)) {
assColumn.setJavaType(GenConstants.TYPE_DATE);
assColumn.setHtmlType(GenConstants.HTML_DATETIME);
} else if (GenUtils.arraysContains(GenConstants.COLUMNTYPE_NUMBER, dataType)) {
assColumn.setHtmlType(GenConstants.HTML_INPUT);
// 如果是浮点型 统一用BigDecimal
String[] str = StringUtils.split(StringUtils.substringBetween(assColumn.getColumnType(), "(", ")"), ",");
if (str != null && str.length == 2 && Integer.parseInt(str[1]) > 0) {
assColumn.setJavaType(GenConstants.TYPE_BIGDECIMAL);
}
// 如果是整形
else if (str != null && str.length == 1 && Integer.parseInt(str[0]) <= 10) {
assColumn.setJavaType(GenConstants.TYPE_INTEGER);
}
// 长整形
else {
assColumn.setJavaType(GenConstants.TYPE_LONG);
}
}
// 列表字段
assColumn.setIsList(GenConstants.REQUIRE);
// 查询字段
assColumn.setIsQuery(GenConstants.NO_REQUIRE);
// 查询字段类型
if (StringUtils.endsWithIgnoreCase(columnName, "name")) {
assColumn.setQueryType(GenConstants.QUERY_LIKE);
}
// 状态字段设置单选框
if (StringUtils.endsWithIgnoreCase(columnName, "status")) {
assColumn.setHtmlType(GenConstants.HTML_RADIO);
}
// 类型&性别字段设置下拉框
else if (StringUtils.endsWithIgnoreCase(columnName, "type")
|| StringUtils.endsWithIgnoreCase(columnName, "sex")) {
assColumn.setHtmlType(GenConstants.HTML_SELECT);
}
}
}

View File

@ -1,6 +1,7 @@
package com.hchyun.generator.util; package com.hchyun.generator.util;
import java.util.Arrays; import java.util.Arrays;
import org.apache.commons.lang3.RegExUtils; import org.apache.commons.lang3.RegExUtils;
import com.hchyun.common.constant.GenConstants; import com.hchyun.common.constant.GenConstants;
import com.hchyun.common.utils.StringUtils; import com.hchyun.common.utils.StringUtils;
@ -10,16 +11,14 @@ import com.hchyun.generator.entity.GenTableColumn;
/** /**
* 代码生成器 工具类 * 代码生成器 工具类
* *
* @author hchyun * @author hchyun
*/ */
public class GenUtils public class GenUtils {
{
/** /**
* 初始化表信息 * 初始化表信息
*/ */
public static void initTable(GenTable genTable, Long operName) public static void initTable(GenTable genTable, Long operName) {
{
genTable.setClassName(convertClassName(genTable.getTableName())); genTable.setClassName(convertClassName(genTable.getTableName()));
genTable.setPackageName(GenConfig.getPackageName()); genTable.setPackageName(GenConfig.getPackageName());
genTable.setModuleName(getModuleName(GenConfig.getPackageName())); genTable.setModuleName(getModuleName(GenConfig.getPackageName()));
@ -32,8 +31,7 @@ public class GenUtils
/** /**
* 初始化列属性字段 * 初始化列属性字段
*/ */
public static void initColumnField(GenTableColumn column, GenTable table) public static void initColumnField(GenTableColumn column, GenTable table) {
{
String dataType = getDbType(column.getColumnType()); String dataType = getDbType(column.getColumnType());
String columnName = column.getColumnName(); String columnName = column.getColumnName();
column.setTableId(table.getTableId()); column.setTableId(table.getTableId());
@ -43,36 +41,28 @@ public class GenUtils
// 设置默认类型 // 设置默认类型
column.setJavaType(GenConstants.TYPE_STRING); column.setJavaType(GenConstants.TYPE_STRING);
if (arraysContains(GenConstants.COLUMNTYPE_STR, dataType) || arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType)) if (arraysContains(GenConstants.COLUMNTYPE_STR, dataType) || arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType)) {
{
// 字符串长度超过500设置为文本域 // 字符串长度超过500设置为文本域
Integer columnLength = getColumnLength(column.getColumnType()); Integer columnLength = getColumnLength(column.getColumnType());
String htmlType = columnLength >= 500 || arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType) ? GenConstants.HTML_TEXTAREA : GenConstants.HTML_INPUT; String htmlType = columnLength >= 500 || arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType) ? GenConstants.HTML_TEXTAREA : GenConstants.HTML_INPUT;
column.setHtmlType(htmlType); column.setHtmlType(htmlType);
} } else if (arraysContains(GenConstants.COLUMNTYPE_TIME, dataType)) {
else if (arraysContains(GenConstants.COLUMNTYPE_TIME, dataType))
{
column.setJavaType(GenConstants.TYPE_DATE); column.setJavaType(GenConstants.TYPE_DATE);
column.setHtmlType(GenConstants.HTML_DATETIME); column.setHtmlType(GenConstants.HTML_DATETIME);
} } else if (arraysContains(GenConstants.COLUMNTYPE_NUMBER, dataType)) {
else if (arraysContains(GenConstants.COLUMNTYPE_NUMBER, dataType))
{
column.setHtmlType(GenConstants.HTML_INPUT); column.setHtmlType(GenConstants.HTML_INPUT);
// 如果是浮点型 统一用BigDecimal // 如果是浮点型 统一用BigDecimal
String[] str = StringUtils.split(StringUtils.substringBetween(column.getColumnType(), "(", ")"), ","); String[] str = StringUtils.split(StringUtils.substringBetween(column.getColumnType(), "(", ")"), ",");
if (str != null && str.length == 2 && Integer.parseInt(str[1]) > 0) if (str != null && str.length == 2 && Integer.parseInt(str[1]) > 0) {
{
column.setJavaType(GenConstants.TYPE_BIGDECIMAL); column.setJavaType(GenConstants.TYPE_BIGDECIMAL);
} }
// 如果是整形 // 如果是整形
else if (str != null && str.length == 1 && Integer.parseInt(str[0]) <= 10) else if (str != null && str.length == 1 && Integer.parseInt(str[0]) <= 10) {
{
column.setJavaType(GenConstants.TYPE_INTEGER); column.setJavaType(GenConstants.TYPE_INTEGER);
} }
// 长整形 // 长整形
else else {
{
column.setJavaType(GenConstants.TYPE_LONG); column.setJavaType(GenConstants.TYPE_LONG);
} }
} }
@ -81,74 +71,63 @@ public class GenUtils
column.setIsInsert(GenConstants.REQUIRE); column.setIsInsert(GenConstants.REQUIRE);
// 编辑字段 // 编辑字段
if (!arraysContains(GenConstants.COLUMNNAME_NOT_EDIT, columnName) && !column.isPk()) if (!arraysContains(GenConstants.COLUMNNAME_NOT_EDIT, columnName) && !column.isPk()) {
{
column.setIsEdit(GenConstants.REQUIRE); column.setIsEdit(GenConstants.REQUIRE);
} }
// 列表字段 // 列表字段
if (!arraysContains(GenConstants.COLUMNNAME_NOT_LIST, columnName) && !column.isPk()) if (!arraysContains(GenConstants.COLUMNNAME_NOT_LIST, columnName) && !column.isPk()) {
{
column.setIsList(GenConstants.REQUIRE); column.setIsList(GenConstants.REQUIRE);
} }
// 查询字段 // 查询字段
if (!arraysContains(GenConstants.COLUMNNAME_NOT_QUERY, columnName) && !column.isPk()) if (!arraysContains(GenConstants.COLUMNNAME_NOT_QUERY, columnName) && !column.isPk()) {
{
column.setIsQuery(GenConstants.REQUIRE); column.setIsQuery(GenConstants.REQUIRE);
} }
// 查询字段类型 // 查询字段类型
if (StringUtils.endsWithIgnoreCase(columnName, "name")) if (StringUtils.endsWithIgnoreCase(columnName, "name")) {
{
column.setQueryType(GenConstants.QUERY_LIKE); column.setQueryType(GenConstants.QUERY_LIKE);
} }
// 状态字段设置单选框 // 状态字段设置单选框
if (StringUtils.endsWithIgnoreCase(columnName, "status")) if (StringUtils.endsWithIgnoreCase(columnName, "status")) {
{
column.setHtmlType(GenConstants.HTML_RADIO); column.setHtmlType(GenConstants.HTML_RADIO);
} }
// 类型&性别字段设置下拉框 // 类型&性别字段设置下拉框
else if (StringUtils.endsWithIgnoreCase(columnName, "type") else if (StringUtils.endsWithIgnoreCase(columnName, "type")
|| StringUtils.endsWithIgnoreCase(columnName, "sex")) || StringUtils.endsWithIgnoreCase(columnName, "sex")) {
{
column.setHtmlType(GenConstants.HTML_SELECT); column.setHtmlType(GenConstants.HTML_SELECT);
} }
// 图片字段设置图片上传控件 // 图片字段设置图片上传控件
else if (StringUtils.endsWithIgnoreCase(columnName, "image")) else if (StringUtils.endsWithIgnoreCase(columnName, "image")) {
{
column.setHtmlType(GenConstants.HTML_IMAGE_UPLOAD); column.setHtmlType(GenConstants.HTML_IMAGE_UPLOAD);
} }
// 文件字段设置文件上传控件 // 文件字段设置文件上传控件
else if (StringUtils.endsWithIgnoreCase(columnName, "file")) else if (StringUtils.endsWithIgnoreCase(columnName, "file")) {
{
column.setHtmlType(GenConstants.HTML_FILE_UPLOAD); column.setHtmlType(GenConstants.HTML_FILE_UPLOAD);
} }
// 内容字段设置富文本控件 // 内容字段设置富文本控件
else if (StringUtils.endsWithIgnoreCase(columnName, "content")) else if (StringUtils.endsWithIgnoreCase(columnName, "content")) {
{
column.setHtmlType(GenConstants.HTML_EDITOR); column.setHtmlType(GenConstants.HTML_EDITOR);
} }
} }
/** /**
* 校验数组是否包含指定值 * 校验数组是否包含指定值
* *
* @param arr 数组 * @param arr 数组
* @param targetValue * @param targetValue
* @return 是否包含 * @return 是否包含
*/ */
public static boolean arraysContains(String[] arr, String targetValue) public static boolean arraysContains(String[] arr, String targetValue) {
{
return Arrays.asList(arr).contains(targetValue); return Arrays.asList(arr).contains(targetValue);
} }
/** /**
* 获取模块名 * 获取模块名
* *
* @param packageName 包名 * @param packageName 包名
* @return 模块名 * @return 模块名
*/ */
public static String getModuleName(String packageName) public static String getModuleName(String packageName) {
{
int lastIndex = packageName.lastIndexOf("."); int lastIndex = packageName.lastIndexOf(".");
int nameLength = packageName.length(); int nameLength = packageName.length();
String moduleName = StringUtils.substring(packageName, lastIndex + 1, nameLength); String moduleName = StringUtils.substring(packageName, lastIndex + 1, nameLength);
@ -157,12 +136,11 @@ public class GenUtils
/** /**
* 获取业务名 * 获取业务名
* *
* @param tableName 表名 * @param tableName 表名
* @return 业务名 * @return 业务名
*/ */
public static String getBusinessName(String tableName) public static String getBusinessName(String tableName) {
{
int lastIndex = tableName.lastIndexOf("_"); int lastIndex = tableName.lastIndexOf("_");
int nameLength = tableName.length(); int nameLength = tableName.length();
String businessName = StringUtils.substring(tableName, lastIndex + 1, nameLength); String businessName = StringUtils.substring(tableName, lastIndex + 1, nameLength);
@ -171,16 +149,14 @@ public class GenUtils
/** /**
* 表名转换成Java类名 * 表名转换成Java类名
* *
* @param tableName 表名称 * @param tableName 表名称
* @return 类名 * @return 类名
*/ */
public static String convertClassName(String tableName) public static String convertClassName(String tableName) {
{
boolean autoRemovePre = GenConfig.getAutoRemovePre(); boolean autoRemovePre = GenConfig.getAutoRemovePre();
String tablePrefix = GenConfig.getTablePrefix(); String tablePrefix = GenConfig.getTablePrefix();
if (autoRemovePre && StringUtils.isNotEmpty(tablePrefix)) if (autoRemovePre && StringUtils.isNotEmpty(tablePrefix)) {
{
String[] searchList = StringUtils.split(tablePrefix, ","); String[] searchList = StringUtils.split(tablePrefix, ",");
tableName = replaceFirst(tableName, searchList); tableName = replaceFirst(tableName, searchList);
} }
@ -189,18 +165,15 @@ public class GenUtils
/** /**
* 批量替换前缀 * 批量替换前缀
* *
* @param replacementm 替换值 * @param replacementm 替换值
* @param searchList 替换列表 * @param searchList 替换列表
* @return * @return
*/ */
public static String replaceFirst(String replacementm, String[] searchList) public static String replaceFirst(String replacementm, String[] searchList) {
{
String text = replacementm; String text = replacementm;
for (String searchString : searchList) for (String searchString : searchList) {
{ if (replacementm.startsWith(searchString)) {
if (replacementm.startsWith(searchString))
{
text = replacementm.replaceFirst(searchString, ""); text = replacementm.replaceFirst(searchString, "");
break; break;
} }
@ -210,48 +183,39 @@ public class GenUtils
/** /**
* 关键字替换 * 关键字替换
* *
* @param text 需要被替换的名字 * @param text 需要被替换的名字
* @return 替换后的名字 * @return 替换后的名字
*/ */
public static String replaceText(String text) public static String replaceText(String text) {
{
return RegExUtils.replaceAll(text, "(?:表|若依)", ""); return RegExUtils.replaceAll(text, "(?:表|若依)", "");
} }
/** /**
* 获取数据库类型字段 * 获取数据库类型字段
* *
* @param columnType 列类型 * @param columnType 列类型
* @return 截取后的列类型 * @return 截取后的列类型
*/ */
public static String getDbType(String columnType) public static String getDbType(String columnType) {
{ if (StringUtils.indexOf(columnType, "(") > 0) {
if (StringUtils.indexOf(columnType, "(") > 0)
{
return StringUtils.substringBefore(columnType, "("); return StringUtils.substringBefore(columnType, "(");
} } else {
else
{
return columnType; return columnType;
} }
} }
/** /**
* 获取字段长度 * 获取字段长度
* *
* @param columnType 列类型 * @param columnType 列类型
* @return 截取后的列类型 * @return 截取后的列类型
*/ */
public static Integer getColumnLength(String columnType) public static Integer getColumnLength(String columnType) {
{ if (StringUtils.indexOf(columnType, "(") > 0) {
if (StringUtils.indexOf(columnType, "(") > 0)
{
String length = StringUtils.substringBetween(columnType, "(", ")"); String length = StringUtils.substringBetween(columnType, "(", ")");
return Integer.valueOf(length); return Integer.valueOf(length);
} } else {
else
{
return 0; return 0;
} }
} }

View File

@ -0,0 +1,46 @@
<?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.AssociatedDao">
<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="selectTableColumnByTableId" resultType="com.hchyun.generator.entity.AssColumn" parameterType="Long">
select * from gen_acc_column where table_id = #{tableId} order by sort
</select>
<select id="selectTableColumn" resultType="com.hchyun.generator.entity.AssColumn" 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>
<delete id="deleteTableColumn" parameterType="Long">
delete
from gen_acc_column
where table_id = #{tableId}
</delete>
<insert id="insertColumns" parameterType="java.util.List">
insert into gen_acc_column(table_id, column_name, column_comment, column_type, java_type, java_field, is_list,
is_query, query_type, html_type, dict_type, sort, create_by, update_by)
values
<foreach collection="list" item="item" index="index" separator=",">
(#{item.tableId},#{item.columnName},#{item.columnComment},#{item.columnType},
#{item.javaType},#{item.javaField},#{item.isList},#{item.isQuery},
#{item.queryType},#{item.htmlType},#{item.dictType},#{item.sort},
#{item.createBy},#{item.updateBy})
</foreach>
</insert>
</mapper>

View File

@ -4,28 +4,31 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.hchyun.generator.dao.GenTableDao"> <mapper namespace="com.hchyun.generator.dao.GenTableDao">
<resultMap type="GenTable" id="GenTableResult"> <resultMap type="com.hchyun.generator.entity.GenTable" id="GenTableResult">
<id property="tableId" column="table_id" /> <id property="tableId" column="table_id" />
<result property="tableName" column="table_name" /> <result property="tableName" column="table_name" />
<result property="tableComment" column="table_comment" /> <result property="tableComment" column="table_comment" />
<result property="subTableName" column="sub_table_name" /> <result property="subTableName" column="sub_table_name" />
<result property="subTableFkName" column="sub_table_fk_name" /> <result property="subTableFkName" column="sub_table_fk_name" />
<result property="className" column="class_name" /> <result property="className" column="class_name" />
<result property="tplCategory" column="tpl_category" /> <result property="tplCategory" column="tpl_category" />
<result property="packageName" column="package_name" /> <result property="packageName" column="package_name" />
<result property="moduleName" column="module_name" /> <result property="moduleName" column="module_name" />
<result property="businessName" column="business_name" /> <result property="businessName" column="business_name" />
<result property="functionName" column="function_name" /> <result property="functionName" column="function_name" />
<result property="functionAuthor" column="function_author" /> <result property="functionAuthor" column="function_author" />
<result property="genType" column="gen_type" /> <result property="genType" column="gen_type" />
<result property="genPath" column="gen_path" /> <result property="genPath" column="gen_path" />
<result property="options" column="options" /> <result property="options" column="options" />
<result property="createBy" column="create_by" /> <result property="assTableName" column="ass_table_name" />
<result property="createTime" column="create_time" /> <result property="assTableColumn" column="ass_table_column" />
<result property="updateBy" column="update_by" /> <result property="assTableFkColumn" column="ass_table_fk_column"/>
<result property="updateTime" column="update_time" /> <result property="createBy" column="create_by" />
<result property="remark" column="remark" /> <result property="createTime" column="create_time" />
<collection property="columns" javaType="java.util.List" resultMap="GenTableColumnResult" /> <result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="remark" column="remark" />
<collection property="columns" javaType="java.util.List" resultMap="GenTableColumnResult" />
</resultMap> </resultMap>
<resultMap type="com.hchyun.generator.entity.GenTableColumn" id="GenTableColumnResult"> <resultMap type="com.hchyun.generator.entity.GenTableColumn" id="GenTableColumnResult">
@ -59,7 +62,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
${paramSQL} ${paramSQL}
</insert> </insert>
<sql id="selectGenTableVo"> <sql id="selectGenTableVo">
select table_id, table_name, table_comment, sub_table_name, sub_table_fk_name, class_name, tpl_category, package_name, module_name, business_name, function_name, function_author, gen_type, gen_path, options, create_by, create_time, update_by, update_time, remark from gen_table select table_id, table_name, table_comment, sub_table_name, sub_table_fk_name, class_name, tpl_category,
package_name, module_name, business_name, function_name, function_author, gen_type, gen_path,
options, ass_table_name, ass_table_column, ass_table_fk_column, create_by, create_time, update_by, update_time, remark from gen_table
</sql> </sql>
<select id="selectGenTableList" parameterType="GenTable" resultMap="GenTableResult"> <select id="selectGenTableList" parameterType="GenTable" resultMap="GenTableResult">
@ -116,8 +121,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<!--todo 获取表信息 预览代码使用--> <!--todo 获取表信息 预览代码使用-->
<select id="selectGenTableById" parameterType="Long" resultMap="GenTableResult"> <select id="selectGenTableById" parameterType="Long" resultMap="GenTableResult">
SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark, SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name,t.ass_table_name,t.ass_table_column,
c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort, c.is_regular, r.regular t.ass_table_fk_column, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name,
t.function_author, t.gen_type, t.gen_path, t.options, t.remark,
c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required,
c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort, c.is_regular, r.regular
FROM gen_table t FROM gen_table t
LEFT JOIN gen_table_column c ON t.table_id = c.table_id LEFT JOIN gen_table_column c ON t.table_id = c.table_id
LEFT JOIN sys_regular r ON c.is_regular = r.id LEFT JOIN sys_regular r ON c.is_regular = r.id
@ -125,8 +133,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select> </select>
<select id="selectGenTableByName" parameterType="String" resultMap="GenTableResult"> <select id="selectGenTableByName" parameterType="String" resultMap="GenTableResult">
SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark, SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name,t.ass_table_name,t.ass_table_column,
c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort, c.is_regular, r.regular t.ass_table_fk_column, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name,
t.function_author, t.gen_type, t.gen_path, t.options, t.remark,
c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required,
c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort, c.is_regular, r.regular
FROM gen_table t FROM gen_table t
LEFT JOIN gen_table_column c ON t.table_id = c.table_id LEFT JOIN gen_table_column c ON t.table_id = c.table_id
LEFT JOIN sys_regular r ON c.is_regular = r.id LEFT JOIN sys_regular r ON c.is_regular = r.id
@ -134,8 +145,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select> </select>
<!-- todo 查询数据库行配置信息--> <!-- todo 查询数据库行配置信息-->
<select id="selectGenTableAll" parameterType="String" resultMap="GenTableResult"> <select id="selectGenTableAll" parameterType="String" resultMap="GenTableResult">
SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.options, t.remark, SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name,t.ass_table_name,t.ass_table_column,t.ass_table_fk_column,
c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.options, t.remark,
c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert,
c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort
FROM gen_table t FROM gen_table t
LEFT JOIN gen_table_column c ON t.table_id = c.table_id LEFT JOIN gen_table_column c ON t.table_id = c.table_id
order by c.sort order by c.sort
@ -182,6 +195,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="tableComment != null and tableComment != ''">table_comment = #{tableComment},</if> <if test="tableComment != null and tableComment != ''">table_comment = #{tableComment},</if>
<if test="subTableName != null">sub_table_name = #{subTableName},</if> <if test="subTableName != null">sub_table_name = #{subTableName},</if>
<if test="subTableFkName != null">sub_table_fk_name = #{subTableFkName},</if> <if test="subTableFkName != null">sub_table_fk_name = #{subTableFkName},</if>
<if test="assTableName != null and assTableName !=''">ass_table_name = #{assTableName},</if>
<if test="assTableColumn != null and assTableColumn !=''">ass_table_column = #{assTableColumn},</if>
<if test="assTableFkColumn != null and assTableFkColumn !=''">ass_table_fk_column = #{assTableFkColumn},</if>
<if test="className != null and className != ''">class_name = #{className},</if> <if test="className != null and className != ''">class_name = #{className},</if>
<if test="functionAuthor != null and functionAuthor != ''">function_author = #{functionAuthor},</if> <if test="functionAuthor != null and functionAuthor != ''">function_author = #{functionAuthor},</if>
<if test="genType != null and genType != ''">gen_type = #{genType},</if> <if test="genType != null and genType != ''">gen_type = #{genType},</if>

View File

@ -3,9 +3,9 @@ package ${packageName}.controller;
/** /**
* ${ClassName} ${functionName} * ${ClassName} ${functionName}
* *
* @Author ${author} * Author ${author}
* @Email ${emali} * Email ${emali}
* @Date ${time} * Date ${time}
*/ */
import com.hchyun.common.annotation.Log; import com.hchyun.common.annotation.Log;
import com.hchyun.common.constant.ReturnConstants; import com.hchyun.common.constant.ReturnConstants;

View File

@ -40,6 +40,7 @@ import com.hchyun.common.core.page.TableDataInfo;
* @author ${author} * @author ${author}
* @date ${datetime} * @date ${datetime}
*/ */
@Api(value = "${functionName}管理",tags = "${functionName}管理") @Api(value = "${functionName}管理",tags = "${functionName}管理")
@RestController @RestController
@RequestMapping("/${moduleName}/${businessName}") @RequestMapping("/${moduleName}/${businessName}")