【更新】代码生成支持oracle数据库直连,添加number类型转换,增加oracle菜单sql
This commit is contained in:
parent
8039b50b9b
commit
de1fd9123f
@ -112,6 +112,16 @@ public interface CommonConstant {
|
||||
*/
|
||||
String DATABASE_URL_NAME = "DATABASE_URL_NAME";
|
||||
|
||||
/**
|
||||
* 数据库链接驱动标识
|
||||
*/
|
||||
String DATABASE_DRIVER_NAME = "DATABASE_DRIVER_NAME";
|
||||
|
||||
/**
|
||||
* 数据库用户标识
|
||||
*/
|
||||
String DATABASE_USER_NAME = "DATABASE_USER_NAME";
|
||||
|
||||
/**
|
||||
* 点选验证码
|
||||
*/
|
||||
|
@ -71,7 +71,8 @@ public class Config {
|
||||
public static String vueIndexPath;
|
||||
public static String vueAddFromPath;
|
||||
public static String vueEditFromPath;
|
||||
public static String sqlPath;
|
||||
public static String mysqlSqlPath;
|
||||
public static String oracleSqlPath;
|
||||
|
||||
/**
|
||||
* 各个代码存放路径文件夹
|
||||
@ -90,9 +91,10 @@ public class Config {
|
||||
vueIndexPath = BASE_VUE_PAHT + FILE_SEP + "views" + FILE_SEP + "main" + FILE_SEP + busName + FILE_SEP;
|
||||
vueAddFromPath = BASE_VUE_PAHT + FILE_SEP + "views" + FILE_SEP + "main" + FILE_SEP + busName + FILE_SEP;
|
||||
vueEditFromPath = BASE_VUE_PAHT + FILE_SEP + "views" + FILE_SEP + "main" + FILE_SEP + busName + FILE_SEP;
|
||||
sqlPath = BASE_SQL_PAHT;
|
||||
mysqlSqlPath = BASE_SQL_PAHT;
|
||||
oracleSqlPath = BASE_SQL_PAHT;
|
||||
return new String[] {
|
||||
controllerPath, entityPath, enumsPath, mapperPath, mappingPath, paramPath, servicePath, serviceImplPath, manageJsPath, vueIndexPath, vueAddFromPath, vueEditFromPath, sqlPath
|
||||
controllerPath, entityPath, enumsPath, mapperPath, mappingPath, paramPath, servicePath, serviceImplPath, manageJsPath, vueIndexPath, vueAddFromPath, vueEditFromPath, mysqlSqlPath, oracleSqlPath
|
||||
};
|
||||
}
|
||||
|
||||
@ -113,6 +115,7 @@ public class Config {
|
||||
"addForm.vue.vm",
|
||||
"editForm.vue.vm",
|
||||
"XnMysql.sql.vm",
|
||||
"XnOracle.sql.vm",
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -19,6 +19,7 @@ public class JavaSqlTool {
|
||||
sqlType = sqlType.toLowerCase();
|
||||
switch(sqlType){
|
||||
case "nvarchar":return "String";
|
||||
case "nvarchar2":return "String";
|
||||
case "char":return "String";
|
||||
case "varchar":return "String";
|
||||
case "text":return "String";
|
||||
@ -31,6 +32,7 @@ public class JavaSqlTool {
|
||||
case "mediumint":return "Integer";
|
||||
case "bit":return "Boolean";
|
||||
case "bigint":return "Long";
|
||||
case "number":return "Long";
|
||||
case "float":return "Fload";
|
||||
case "double":return "Double";
|
||||
case "decimal":return "BigDecimal";
|
||||
|
@ -1,5 +1,8 @@
|
||||
package com.cn.xiaonuo.generate.core.util;
|
||||
|
||||
import com.cn.xiaonuo.core.consts.CommonConstant;
|
||||
import com.cn.xiaonuo.core.context.constant.ConstantContext;
|
||||
import com.cn.xiaonuo.core.enums.DbIdEnum;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.velocity.app.Velocity;
|
||||
|
||||
@ -58,7 +61,7 @@ public class Util {
|
||||
* @author yubaoshan
|
||||
* @date 2020年12月16日23:29:53
|
||||
*/
|
||||
public static int getIndex(String string, int i, String str) {
|
||||
private static int getIndex(String string, int i, String str) {
|
||||
Matcher slashMatcher = Pattern.compile(str).matcher(string);
|
||||
int mIdx = 0;
|
||||
while (slashMatcher.find()) {
|
||||
@ -71,4 +74,22 @@ public class Util {
|
||||
return slashMatcher.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据库用户
|
||||
*
|
||||
* @author yubaoshan
|
||||
* @date 2021-03-11 18:37:00
|
||||
*/
|
||||
public static String getDataBasename () {
|
||||
String dataUrl = ConstantContext.me().getStr(CommonConstant.DATABASE_URL_NAME);
|
||||
String driverName = ConstantContext.me().getStr(CommonConstant.DATABASE_DRIVER_NAME);
|
||||
if (driverName.contains(DbIdEnum.MS_SQL.getCode())) {
|
||||
return dataUrl.substring(getIndex(dataUrl, 3, "/") + 1, dataUrl.indexOf("?"));
|
||||
} else if (driverName.contains(DbIdEnum.ORACLE.getCode())) {
|
||||
return ConstantContext.me().getStr(CommonConstant.DATABASE_USER_NAME);
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,20 +17,51 @@
|
||||
</resultMap>
|
||||
|
||||
<!-- 查询指定库中所有表 -->
|
||||
<select id="selectInformationTable" parameterType="String" resultMap="informationResult">
|
||||
<select id="selectInformationTable" parameterType="String" resultMap="informationResult" databaseId = "mysql">
|
||||
select table_name,create_time,update_time,table_comment
|
||||
from information_schema.tables
|
||||
where
|
||||
table_schema = '${dbName}'
|
||||
from information_schema.tables
|
||||
where
|
||||
table_schema = '${dbName}'
|
||||
</select>
|
||||
<select id="selectInformationTable" parameterType="String" resultMap="informationResult" databaseId = "oracle">
|
||||
select table_name, comments as table_comment
|
||||
from user_tab_comments
|
||||
</select>
|
||||
|
||||
<!-- 查询指定表中所有字段 -->
|
||||
<select id="selectInformationColumns" parameterType="String" resultMap="inforMationColumnsResult">
|
||||
<select id="selectInformationColumns" parameterType="String" resultMap="inforMationColumnsResult" databaseId = "mysql">
|
||||
select
|
||||
column_name,data_type,column_comment,column_key
|
||||
from information_schema.columns
|
||||
where
|
||||
table_schema = '${dbName}' and table_name = '${tableName}';
|
||||
</select>
|
||||
<select id="selectInformationColumns" parameterType="String" resultMap="inforMationColumnsResult" databaseId = "oracle">
|
||||
select
|
||||
a.column_name as column_name,
|
||||
a.data_type as data_type,
|
||||
b.comments as column_comment,
|
||||
case
|
||||
when c.position>0 then 'PRI'
|
||||
else ''
|
||||
end column_key
|
||||
from
|
||||
(select * from user_tab_columns where table_name='${tableName}') a
|
||||
left join
|
||||
(select * from user_col_comments where table_name='${tableName}') b
|
||||
on a.column_name=b.column_name
|
||||
left join
|
||||
(
|
||||
select table_name,column_name,position from user_cons_columns
|
||||
where
|
||||
table_name='${tableName}'
|
||||
and constraint_name=(select constraint_name
|
||||
from
|
||||
user_constraints where table_name='${tableName}' and constraint_type='P')
|
||||
and owner='${dbName}'
|
||||
) c
|
||||
on a.column_name=c.column_name
|
||||
order by a.column_id
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
@ -28,20 +28,13 @@ import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.cn.xiaonuo.core.consts.CommonConstant;
|
||||
import com.cn.xiaonuo.core.context.constant.ConstantContext;
|
||||
import com.cn.xiaonuo.core.enums.YesOrNotEnum;
|
||||
import com.cn.xiaonuo.core.exception.ServiceException;
|
||||
import com.cn.xiaonuo.core.factory.PageFactory;
|
||||
import com.cn.xiaonuo.core.pojo.page.PageResult;
|
||||
import com.cn.xiaonuo.generate.core.context.XnVelocityContext;
|
||||
import com.cn.xiaonuo.generate.core.param.TableField;
|
||||
import com.cn.xiaonuo.generate.core.param.XnCodeGenParam;
|
||||
import com.cn.xiaonuo.generate.core.tool.JavaSqlTool;
|
||||
import com.cn.xiaonuo.generate.core.tool.NamingConTool;
|
||||
import com.cn.xiaonuo.generate.core.tool.StringDateTool;
|
||||
import com.cn.xiaonuo.generate.core.config.Config;
|
||||
import com.cn.xiaonuo.generate.core.enums.TableFilteredFieldsEnum;
|
||||
import com.cn.xiaonuo.generate.core.util.Util;
|
||||
import com.cn.xiaonuo.generate.modular.entity.CodeGenerate;
|
||||
import com.cn.xiaonuo.generate.modular.entity.SysCodeGenerateConfig;
|
||||
@ -53,25 +46,20 @@ import com.cn.xiaonuo.generate.modular.result.InforMationColumnsResult;
|
||||
import com.cn.xiaonuo.generate.modular.result.InformationResult;
|
||||
import com.cn.xiaonuo.generate.modular.service.CodeGenerateService;
|
||||
import com.cn.xiaonuo.generate.modular.service.SysCodeGenerateConfigService;
|
||||
import com.cn.xiaonuo.sys.modular.menu.entity.SysMenu;
|
||||
import com.cn.xiaonuo.sys.modular.menu.mapper.SysMenuMapper;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.velocity.Template;
|
||||
import org.apache.velocity.VelocityContext;
|
||||
import org.apache.velocity.app.Velocity;
|
||||
import org.apache.velocity.app.VelocityEngine;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
|
||||
/**
|
||||
* 代码生成基础配置service接口实现类
|
||||
*
|
||||
@ -172,9 +160,7 @@ public class CodeGenerateServiceImpl extends ServiceImpl<CodeGenerateMapper, Cod
|
||||
|
||||
@Override
|
||||
public List<InformationResult> InformationTableList () {
|
||||
String databaseUrl = ConstantContext.me().getStr(CommonConstant.DATABASE_URL_NAME);
|
||||
String dbName = databaseUrl.substring(Util.getIndex(databaseUrl, 3, "/") + 1, databaseUrl.indexOf("?"));
|
||||
return this.baseMapper.selectInformationTable(dbName);
|
||||
return this.baseMapper.selectInformationTable(Util.getDataBasename());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -196,11 +182,10 @@ public class CodeGenerateServiceImpl extends ServiceImpl<CodeGenerateMapper, Cod
|
||||
* @date 2020年12月23日 00点32分
|
||||
*/
|
||||
private boolean vldTablePri (String tableName) {
|
||||
String databaseUrl = ConstantContext.me().getStr(CommonConstant.DATABASE_URL_NAME);
|
||||
String dbName = databaseUrl.substring(Util.getIndex(databaseUrl, 3, "/") + 1, databaseUrl.indexOf("?"));
|
||||
List<InforMationColumnsResult> inforMationColumnsResultList = this.baseMapper.selectInformationColumns(dbName, tableName);
|
||||
List<InforMationColumnsResult> inforMationColumnsResultList = this.baseMapper.selectInformationColumns(Util.getDataBasename(), tableName);
|
||||
for (int a = 0; a < inforMationColumnsResultList.size(); a++) {
|
||||
if (inforMationColumnsResultList.get(a).columnKey.equals(Config.DB_TABLE_COM_KRY)) {
|
||||
if (ObjectUtil.isNotNull(inforMationColumnsResultList.get(a).columnKey)
|
||||
&& inforMationColumnsResultList.get(a).columnKey.equals(Config.DB_TABLE_COM_KRY)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -234,9 +219,7 @@ public class CodeGenerateServiceImpl extends ServiceImpl<CodeGenerateMapper, Cod
|
||||
*/
|
||||
private List<InforMationColumnsResult> getInforMationColumnsResultList (CodeGenerateParam codeGenerateParam) {
|
||||
CodeGenerate codeGenerate = this.queryCodeGenerate(codeGenerateParam);
|
||||
String databaseUrl = ConstantContext.me().getStr(CommonConstant.DATABASE_URL_NAME);
|
||||
String dbName = databaseUrl.substring(Util.getIndex(databaseUrl, 3, "/") + 1, databaseUrl.indexOf("?"));
|
||||
return this.baseMapper.selectInformationColumns(dbName, codeGenerate.getTableName());
|
||||
return this.baseMapper.selectInformationColumns(Util.getDataBasename(), codeGenerate.getTableName());
|
||||
}
|
||||
|
||||
private XnCodeGenParam copyParams (CodeGenerateParam codeGenerateParam) {
|
||||
|
@ -27,12 +27,9 @@ package com.cn.xiaonuo.generate.modular.service.impl;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.cn.xiaonuo.core.enums.YesOrNotEnum;
|
||||
import com.cn.xiaonuo.core.exception.ServiceException;
|
||||
import com.cn.xiaonuo.core.factory.PageFactory;
|
||||
import com.cn.xiaonuo.core.pojo.page.PageResult;
|
||||
import com.cn.xiaonuo.generate.core.config.Config;
|
||||
import com.cn.xiaonuo.generate.core.enums.QueryTypeEnum;
|
||||
import com.cn.xiaonuo.generate.core.enums.TableFilteredFieldsEnum;
|
||||
@ -85,7 +82,8 @@ public class SysCodeGenerateConfigServiceImpl extends ServiceImpl<SysCodeGenerat
|
||||
SysCodeGenerateConfig sysCodeGenerateConfig = new SysCodeGenerateConfig();
|
||||
|
||||
String YesOrNo = YesOrNotEnum.Y.getCode();
|
||||
if (inforMationColumnsResult.getColumnKey().equals(Config.DB_TABLE_COM_KRY) ||
|
||||
if (ObjectUtil.isNotNull(inforMationColumnsResult.getColumnKey())
|
||||
&& inforMationColumnsResult.getColumnKey().equals(Config.DB_TABLE_COM_KRY) ||
|
||||
TableFilteredFieldsEnum.contains(inforMationColumnsResult.getColumnName())) {
|
||||
YesOrNo = YesOrNotEnum.N.getCode();
|
||||
}
|
||||
|
@ -0,0 +1,34 @@
|
||||
-- ----------------------------
|
||||
-- Records of sys_menu
|
||||
-- ----------------------------
|
||||
#foreach ($id in $sqlMenuId)
|
||||
#if($foreach.count == 1)
|
||||
INSERT INTO "sys_menu" VALUES
|
||||
("$id", "0", "[0],", "${functionName}", "${busName}_index", "1", null, "/${className}", "main/${busName}/index", null, "system_tool", "1", "Y", null, null, "1", "100", null, "0", null, null, null, null);
|
||||
#set ($pid=$id)
|
||||
|
||||
#elseif($foreach.count == 2)
|
||||
INSERT INTO `sys_menu` VALUES
|
||||
("$id", "$pid", "[0],[$pid],", "${functionName}查询", "${busName}_index_page", "2", null, null, null, "${className}:page", "system_tool", "0", "Y", null, null, "1", "100", null, "0", null, null, null, null);
|
||||
|
||||
#elseif($foreach.count == 3)
|
||||
INSERT INTO `sys_menu` VALUES
|
||||
("$id", "$pid", "[0],[$pid],", "${functionName}新增", "${busName}_index_add", "2", null, null, null, "${className}:add", "system_tool", "0", "Y", null, null, "1", "100", null, "0", null, null, null, null);
|
||||
|
||||
#elseif($foreach.count == 4)
|
||||
INSERT INTO `sys_menu` VALUES
|
||||
("$id", "$pid", "[0],[$pid],", "${functionName}编辑", "${busName}_index_edit", "2", null, null, null, "${className}:edit", "system_tool", "0", "Y", null, null, "1", "100", null, "0", null, null, null, null);
|
||||
|
||||
#elseif($foreach.count == 5)
|
||||
INSERT INTO `sys_menu` VALUES
|
||||
("$id", "$pid", "[0],[$pid],", "${functionName}删除", "${busName}_index_delete", "2", null, null, null, "${className}:delete", "system_tool", "0", "Y", null, null, "1", "100", null, "0", null, null, null, null);
|
||||
|
||||
#elseif($foreach.count == 6)
|
||||
INSERT INTO `sys_menu` VALUES
|
||||
("$id", "$pid", "[0],[$pid],", "${functionName}查看", "${busName}_index_detail", "2", null, null, null, "${className}:detail", "system_tool", "0", "Y", null, null, "1", "100", null, "0", null, null, null, null);
|
||||
|
||||
#elseif($foreach.count == 7)
|
||||
INSERT INTO "sys_menu" VALUES
|
||||
("$id", "$pid", "[0],[$pid],", "${functionName}列表", "${busName}_index_list", "2", null, null, null, "${className}:list", "system_tool", "0", "Y", null, null, "1", "100", null, "0", null, null, null, null);
|
||||
#end
|
||||
#end
|
@ -59,6 +59,14 @@ public class ConstantsInitListener implements ApplicationListener<ApplicationCon
|
||||
|
||||
private static final String CONFIG_LIST_SQL = "select code,value from sys_config where status = ?";
|
||||
|
||||
private static final String CAPITAL_CODE = "CODE";
|
||||
|
||||
private static final String CODE = "code";
|
||||
|
||||
private static final String CAPITAL_VALUE = "VALUE";
|
||||
|
||||
private static final String VALUE = "value";
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return Ordered.HIGHEST_PRECEDENCE;
|
||||
@ -75,6 +83,8 @@ public class ConstantsInitListener implements ApplicationListener<ApplicationCon
|
||||
|
||||
// 缓存中放入datasource链接,代码生成时候使用
|
||||
ConstantContext.putConstant(CommonConstant.DATABASE_URL_NAME, dataSourceUrl);
|
||||
ConstantContext.putConstant(CommonConstant.DATABASE_DRIVER_NAME, environment.getProperty("spring.datasource.driver-class-name"));
|
||||
ConstantContext.putConstant(CommonConstant.DATABASE_USER_NAME, dataSourceUsername);
|
||||
|
||||
// 如果有为空的配置,终止执行
|
||||
if (ObjectUtil.hasEmpty(dataSourceUrl, dataSourceUsername, dataSourcePassword)) {
|
||||
@ -83,7 +93,7 @@ public class ConstantsInitListener implements ApplicationListener<ApplicationCon
|
||||
|
||||
Connection conn = null;
|
||||
try {
|
||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||
Class.forName(environment.getProperty("spring.datasource.driver-class-name"));
|
||||
assert dataSourceUrl != null;
|
||||
conn = DriverManager.getConnection(dataSourceUrl, dataSourceUsername, dataSourcePassword);
|
||||
|
||||
@ -94,8 +104,8 @@ public class ConstantsInitListener implements ApplicationListener<ApplicationCon
|
||||
if (ObjectUtil.isNotEmpty(entityList)) {
|
||||
entityList.forEach(sysConfig ->
|
||||
ConstantContext.putConstant(
|
||||
sysConfig.getStr("code") == null ? sysConfig.getStr("CODE") : sysConfig.getStr("code"),
|
||||
sysConfig.getStr("value") == null ? sysConfig.getStr("VALUE") : sysConfig.getStr("value")
|
||||
sysConfig.getStr(CODE) == null ? sysConfig.getStr(CAPITAL_CODE) : sysConfig.getStr(CODE),
|
||||
sysConfig.getStr(VALUE) == null ? sysConfig.getStr(CAPITAL_VALUE) : sysConfig.getStr(VALUE)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user