【fix sonar】generater-core文件夹

This commit is contained in:
梁琦涛
2023-03-14 11:25:54 +08:00
parent 921e9d20bd
commit c37787bd8e
19 changed files with 140 additions and 214 deletions
@@ -3,7 +3,7 @@ package com.jero.codegenerate.database;
import com.jero.codegenerate.properties.CodeConfigProperties; import com.jero.codegenerate.properties.CodeConfigProperties;
public class CodegenDatasourceConfig { public class CodegenDatasourceConfig {
public CodegenDatasourceConfig() { private CodegenDatasourceConfig() {
} }
/** /**
* 加载配置 * 加载配置
@@ -26,25 +26,26 @@ public class DbReadTableUtil {
private static Connection connection; private static Connection connection;
private static Statement statement; private static Statement statement;
public DbReadTableUtil() { private DbReadTableUtil() {
} }
private static final String CONNECT_DATABASE_NAME = " connect databaseName : ";
private static final String COLUMN_GET_FIELD_NAME = "columnt.getFieldName() -------------";
public static void main(String[] args) throws SQLException { public static void main(String[] args) throws SQLException {
try { try {
List list = listColumns("demo"); List<ColumnVo> list = listColumns("demo");
Iterator iterator = list.iterator();
while(iterator.hasNext()) { for (ColumnVo columnVo : list) {
ColumnVo columnVo = (ColumnVo)iterator.next(); log.info(columnVo.getFieldName());
System.out.println(columnVo.getFieldName());
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
PrintStream printStream = System.out;
new DbReadTableUtil(); new DbReadTableUtil();
printStream.println(ArrayUtils.toString(listTableName())); log.info(ArrayUtils.toString(listTableName()));
} }
/** /**
* 获取所有表名的集合 * 获取所有表名的集合
@@ -54,7 +55,7 @@ public class DbReadTableUtil {
*/ */
public static List<String> listTableName() throws SQLException { public static List<String> listTableName() throws SQLException {
String sqlStr = null; String sqlStr = null;
ArrayList list = new ArrayList(0); ArrayList<String> list = new ArrayList<>(0);
try { try {
Class.forName(CodeConfigProperties.driverName); Class.forName(CodeConfigProperties.driverName);
@@ -62,7 +63,7 @@ public class DbReadTableUtil {
statement = connection.createStatement(1005, 1007); statement = connection.createStatement(1005, 1007);
// 表格所属的库 // 表格所属的库
String catalog = connection.getCatalog(); String catalog = connection.getCatalog();
log.info(" connect databaseName : " + catalog); log.info(CONNECT_DATABASE_NAME + catalog);
if (CodeConfigProperties.databaseType.equals(DbConvertDef.MYSQL)) { if (CodeConfigProperties.databaseType.equals(DbConvertDef.MYSQL)) {
// mysql查询所有表的sql // mysql查询所有表的sql
sqlStr = MessageFormat.format(DbConvertDef.MYSQL_ALLTABLES_SQL, TableConvert.formatStr(catalog)); sqlStr = MessageFormat.format(DbConvertDef.MYSQL_ALLTABLES_SQL, TableConvert.formatStr(catalog));
@@ -94,16 +95,14 @@ public class DbReadTableUtil {
if (statement != null) { if (statement != null) {
statement.close(); statement.close();
statement = null; statement = null;
System.gc();
} }
if (connection != null) { if (connection != null) {
connection.close(); connection.close();
connection = null; connection = null;
System.gc();
} }
} catch (SQLException e) { } catch (SQLException e) {
throw e; e.printStackTrace();
} }
} }
@@ -118,7 +117,7 @@ public class DbReadTableUtil {
*/ */
public static List<ColumnVo> listColumns(String tableName) throws Exception { public static List<ColumnVo> listColumns(String tableName) throws Exception {
String sqlStr = null; String sqlStr = null;
ArrayList list = new ArrayList(); ArrayList<ColumnVo> list = new ArrayList<>();
int row; int row;
try { try {
@@ -127,7 +126,7 @@ public class DbReadTableUtil {
statement = connection.createStatement(1005, 1007); statement = connection.createStatement(1005, 1007);
// 表格所属的库 // 表格所属的库
String catalog = connection.getCatalog(); String catalog = connection.getCatalog();
log.info(" connect databaseName : " + catalog); log.info(CONNECT_DATABASE_NAME + catalog);
if (com.jero.codegenerate.properties.CodeConfigProperties.databaseType.equals(DbConvertDef.MYSQL)) { if (com.jero.codegenerate.properties.CodeConfigProperties.databaseType.equals(DbConvertDef.MYSQL)) {
// mysql查询表的所有列信息sql // mysql查询表的所有列信息sql
sqlStr = MessageFormat.format(DbConvertDef.MYSQL_ALLCOLUMNS_SQL, TableConvert.formatStr(tableName), TableConvert.formatStr(catalog)); sqlStr = MessageFormat.format(DbConvertDef.MYSQL_ALLCOLUMNS_SQL, TableConvert.formatStr(tableName), TableConvert.formatStr(catalog));
@@ -174,7 +173,7 @@ public class DbReadTableUtil {
columnVo.setNullable(TableConvert.getNullable(resultSet.getString(7))); columnVo.setNullable(TableConvert.getNullable(resultSet.getString(7)));
setupColumnVo(columnVo); setupColumnVo(columnVo);
columnVo.setFiledComment(StringUtils.isBlank(resultSet.getString(3)) ? columnVo.getFieldName() : resultSet.getString(3)); columnVo.setFiledComment(StringUtils.isBlank(resultSet.getString(3)) ? columnVo.getFieldName() : resultSet.getString(3));
log.debug("columnt.getFieldName() -------------" + columnVo.getFieldName()); log.debug(COLUMN_GET_FIELD_NAME + columnVo.getFieldName());
String[] pageFilterFieldsStrings = new String[0]; String[] pageFilterFieldsStrings = new String[0];
if (com.jero.codegenerate.properties.CodeConfigProperties.pageFilterFields != null) { if (com.jero.codegenerate.properties.CodeConfigProperties.pageFilterFields != null) {
pageFilterFieldsStrings = com.jero.codegenerate.properties.CodeConfigProperties.pageFilterFields.toLowerCase().split(","); pageFilterFieldsStrings = com.jero.codegenerate.properties.CodeConfigProperties.pageFilterFields.toLowerCase().split(",");
@@ -193,7 +192,7 @@ public class DbReadTableUtil {
} }
columnVo1.setFieldDbName(resultSet.getString(1).toUpperCase()); columnVo1.setFieldDbName(resultSet.getString(1).toUpperCase());
log.debug("columnt.getFieldName() -------------" + columnVo1.getFieldName()); log.debug(COLUMN_GET_FIELD_NAME + columnVo1.getFieldName());
if (!com.jero.codegenerate.properties.CodeConfigProperties.dbTableId.equals(columnVo1.getFieldName()) && !CodeStringUtils.isPageFilterFieldsContainDbName(columnVo1.getFieldDbName().toLowerCase(), pageFilterFieldsStrings)) { if (!com.jero.codegenerate.properties.CodeConfigProperties.dbTableId.equals(columnVo1.getFieldName()) && !CodeStringUtils.isPageFilterFieldsContainDbName(columnVo1.getFieldDbName().toLowerCase(), pageFilterFieldsStrings)) {
columnVo1.setFieldType(convertFieldNameToCamelCase(resultSet.getString(2).toLowerCase())); columnVo1.setFieldType(convertFieldNameToCamelCase(resultSet.getString(2).toLowerCase()));
columnVo1.setFieldDbType(convertFieldNameToCamelCase(resultSet.getString(2).toLowerCase())); columnVo1.setFieldDbType(convertFieldNameToCamelCase(resultSet.getString(2).toLowerCase()));
@@ -209,33 +208,29 @@ public class DbReadTableUtil {
} }
log.debug("读取表成功"); log.debug("读取表成功");
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException | SQLException e) {
throw e;
} catch (SQLException e) {
throw e; throw e;
} finally { } finally {
try { try {
if (statement != null) { if (statement != null) {
statement.close(); statement.close();
statement = null; statement = null;
System.gc();
} }
if (connection != null) { if (connection != null) {
connection.close(); connection.close();
connection = null; connection = null;
System.gc();
} }
} catch (SQLException e) { } catch (SQLException e) {
throw e; e.printStackTrace();
} }
} }
ArrayList result = new ArrayList(); ArrayList<ColumnVo> result = new ArrayList<>();
for(row = list.size() - 1; row >= 0; --row) { for(row = list.size() - 1; row >= 0; --row) {
ColumnVo columnVo = (ColumnVo)list.get(row); ColumnVo columnVo = list.get(row);
result.add(columnVo); result.add(columnVo);
} }
@@ -248,9 +243,9 @@ public class DbReadTableUtil {
* @return java.util.List<com.jero.codegenerate.generate.pojo.ColumnVo> * @return java.util.List<com.jero.codegenerate.generate.pojo.ColumnVo>
*/ */
public static List<ColumnVo> listOriginalColumns(String tableName) throws Exception { public static List<ColumnVo> listOriginalColumns(String tableName) throws Exception {
ResultSet resultSet = null; ResultSet resultSet;
String sqlStr = null; String sqlStr = null;
ArrayList list = new ArrayList(); ArrayList<ColumnVo> list = new ArrayList<>();
int row; int row;
try { try {
@@ -259,7 +254,7 @@ public class DbReadTableUtil {
statement = connection.createStatement(1005, 1007); statement = connection.createStatement(1005, 1007);
// 表格所属的库 // 表格所属的库
String catalog = connection.getCatalog(); String catalog = connection.getCatalog();
log.info(" connect databaseName : " + catalog); log.info(CONNECT_DATABASE_NAME + catalog);
if (com.jero.codegenerate.properties.CodeConfigProperties.databaseType.equals(DbConvertDef.MYSQL)) { if (com.jero.codegenerate.properties.CodeConfigProperties.databaseType.equals(DbConvertDef.MYSQL)) {
// mysql查询表的所有列信息sql // mysql查询表的所有列信息sql
sqlStr = MessageFormat.format(DbConvertDef.MYSQL_ALLCOLUMNS_SQL, TableConvert.formatStr(tableName), TableConvert.formatStr(catalog)); sqlStr = MessageFormat.format(DbConvertDef.MYSQL_ALLCOLUMNS_SQL, TableConvert.formatStr(tableName), TableConvert.formatStr(catalog));
@@ -305,7 +300,7 @@ public class DbReadTableUtil {
columnVo.setFieldDbType(convertFieldNameToCamelCase(resultSet.getString(2).toLowerCase())); columnVo.setFieldDbType(convertFieldNameToCamelCase(resultSet.getString(2).toLowerCase()));
setupColumnVo(columnVo); setupColumnVo(columnVo);
columnVo.setFiledComment(StringUtils.isBlank(resultSet.getString(3)) ? columnVo.getFieldName() : resultSet.getString(3)); columnVo.setFiledComment(StringUtils.isBlank(resultSet.getString(3)) ? columnVo.getFieldName() : resultSet.getString(3));
log.debug("columnt.getFieldName() -------------" + columnVo.getFieldName()); log.debug(COLUMN_GET_FIELD_NAME + columnVo.getFieldName());
list.add(columnVo); list.add(columnVo);
while(true) { while(true) {
@@ -332,33 +327,29 @@ public class DbReadTableUtil {
columnVo1.setFiledComment(StringUtils.isBlank(resultSet.getString(3)) ? columnVo1.getFieldName() : resultSet.getString(3)); columnVo1.setFiledComment(StringUtils.isBlank(resultSet.getString(3)) ? columnVo1.getFieldName() : resultSet.getString(3));
list.add(columnVo1); list.add(columnVo1);
} }
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException | SQLException e) {
throw e;
} catch (SQLException e) {
throw e; throw e;
} finally { } finally {
try { try {
if (statement != null) { if (statement != null) {
statement.close(); statement.close();
statement = null; statement = null;
System.gc();
} }
if (connection != null) { if (connection != null) {
connection.close(); connection.close();
connection = null; connection = null;
System.gc();
} }
} catch (SQLException e) { } catch (SQLException e) {
throw e; e.printStackTrace();
} }
} }
ArrayList result = new ArrayList(); ArrayList<ColumnVo> result = new ArrayList<>();
for(row = list.size() - 1; row >= 0; --row) { for(row = list.size() - 1; row >= 0; --row) {
ColumnVo columnVo = (ColumnVo)list.get(row); ColumnVo columnVo = list.get(row);
result.add(columnVo); result.add(columnVo);
} }
@@ -380,7 +371,7 @@ public class DbReadTableUtil {
statement = connection.createStatement(1005, 1007); statement = connection.createStatement(1005, 1007);
// 表格所属的库 // 表格所属的库
String catalog = connection.getCatalog(); String catalog = connection.getCatalog();
log.info(" connect databaseName : " + catalog); log.info(CONNECT_DATABASE_NAME + catalog);
if (com.jero.codegenerate.properties.CodeConfigProperties.databaseType.equals(DbConvertDef.MYSQL)) { if (com.jero.codegenerate.properties.CodeConfigProperties.databaseType.equals(DbConvertDef.MYSQL)) {
// mysql获取表的列信息sql // mysql获取表的列信息sql
sqlStr = "select column_name,data_type,column_comment,0,0 from information_schema.columns where table_name = '" + tableName + "' and table_schema = '" + catalog + "'"; sqlStr = "select column_name,data_type,column_comment,0,0 from information_schema.columns where table_name = '" + tableName + "' and table_schema = '" + catalog + "'";
@@ -500,6 +491,7 @@ public class DbReadTableUtil {
* @return java.lang.String * @return java.lang.String
*/ */
private static String getFieldType(String value, String precision, String scale) { private static String getFieldType(String value, String precision, String scale) {
String bigDecimal = "java.math.BigDecimal";
if (value.contains("char")) { if (value.contains("char")) {
value = "java.lang.String"; value = "java.lang.String";
} else if (value.contains("int")) { } else if (value.contains("int")) {
@@ -510,14 +502,14 @@ public class DbReadTableUtil {
value = "java.lang.Double"; value = "java.lang.Double";
} else if (value.contains("number")) { } else if (value.contains("number")) {
if (StringUtils.isNotBlank(scale) && Integer.parseInt(scale) > 0) { if (StringUtils.isNotBlank(scale) && Integer.parseInt(scale) > 0) {
value = "java.math.BigDecimal"; value = bigDecimal;
} else if (StringUtils.isNotBlank(precision) && Integer.parseInt(precision) > 10) { } else if (StringUtils.isNotBlank(precision) && Integer.parseInt(precision) > 10) {
value = "java.lang.Long"; value = "java.lang.Long";
} else { } else {
value = "java.lang.Integer"; value = "java.lang.Integer";
} }
} else if (value.contains("decimal")) { } else if (value.contains("decimal")) {
value = "java.math.BigDecimal"; value = bigDecimal;
} else if (value.contains("date")) { } else if (value.contains("date")) {
value = "java.util.Date"; value = "java.util.Date";
} else if (value.contains("time")) { } else if (value.contains("time")) {
@@ -527,7 +519,7 @@ public class DbReadTableUtil {
} else if (value.contains("clob")) { } else if (value.contains("clob")) {
value = "java.sql.Clob"; value = "java.sql.Clob";
} else if (value.contains("numeric")) { } else if (value.contains("numeric")) {
value = "java.math.BigDecimal"; value = bigDecimal;
} else { } else {
value = "java.lang.Object"; value = "java.lang.Object";
} }
@@ -4,7 +4,7 @@ import java.util.List;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
public class CodeStringUtils { public class CodeStringUtils {
public CodeStringUtils() { private CodeStringUtils() {
} }
/** /**
@@ -14,7 +14,7 @@ public class CodeStringUtils {
* @return java.lang.String * @return java.lang.String
*/ */
public static String joinComma(String[] stringArray) { public static String joinComma(String[] stringArray) {
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
String[] array = stringArray; String[] array = stringArray;
int length = stringArray.length; int length = stringArray.length;
@@ -82,7 +82,7 @@ public class CodeStringUtils {
public static boolean isListContainString(String target, List<String> stringList) { public static boolean isListContainString(String target, List<String> stringList) {
String[] stringArray = new String[0]; String[] stringArray = new String[0];
if (stringList != null) { if (stringList != null) {
stringArray = (String[])((String[])stringList.toArray()); stringArray = stringList.toArray(new String[0]);
} }
if (stringArray != null && stringArray.length != 0) { if (stringArray != null && stringArray.length != 0) {
@@ -1,18 +1,18 @@
package com.jero.codegenerate.database.util; package com.jero.codegenerate.database.util;
public interface DbConvertDef { public class DbConvertDef {
String Y = "Y"; public static final String Y = "Y";
String N = "N"; public static final String N = "N";
String MYSQL = "mysql"; public static final String MYSQL = "mysql";
String ORACLE = "oracle"; public static final String ORACLE = "oracle";
String SQLSERVER = "sqlserver"; public static final String SQLSERVER = "sqlserver";
String POSTGRESQL = "postgresql"; public static final String POSTGRESQL = "postgresql";
String MYSQL_ALLCOLUMNS_SQL = "select column_name,data_type,column_comment,numeric_precision,numeric_scale,character_maximum_length,is_nullable nullable from information_schema.columns where table_name = {0} and table_schema = {1} order by ORDINAL_POSITION"; public static final String MYSQL_ALLCOLUMNS_SQL = "select column_name,data_type,column_comment,numeric_precision,numeric_scale,character_maximum_length,is_nullable nullable from information_schema.columns where table_name = {0} and table_schema = {1} order by ORDINAL_POSITION";
String ORACLE_ALLCOLUMNS_SQL = " select colstable.column_name column_name, colstable.data_type data_type, commentstable.comments column_comment, colstable.Data_Precision column_precision, colstable.Data_Scale column_scale,colstable.Char_Length,colstable.nullable from user_tab_cols colstable inner join user_col_comments commentstable on colstable.column_name = commentstable.column_name where colstable.table_name = commentstable.table_name and colstable.table_name = {0}"; public static final String ORACLE_ALLCOLUMNS_SQL = " select colstable.column_name column_name, colstable.data_type data_type, commentstable.comments column_comment, colstable.Data_Precision column_precision, colstable.Data_Scale column_scale,colstable.Char_Length,colstable.nullable from user_tab_cols colstable inner join user_col_comments commentstable on colstable.column_name = commentstable.column_name where colstable.table_name = commentstable.table_name and colstable.table_name = {0}";
String SQLSERVER_ALLCOLUMNS_SQL = "select distinct cast(a.name as varchar(50)) column_name, cast(b.name as varchar(50)) data_type, cast(e.value as NVARCHAR(200)) comment, cast(ColumnProperty(a.object_id,a.Name,'''Precision''') as int) num_precision, cast(ColumnProperty(a.object_id,a.Name,'''Scale''') as int) num_scale, a.max_length, (case when a.is_nullable=1 then '''y''' else '''n''' end) nullable,column_id from sys.columns a left join sys.types b on a.user_type_id=b.user_type_id left join (select top 1 * from sys.objects where type = '''U''' and name ={0} order by name) c on a.object_id=c.object_id left join sys.extended_properties e on e.major_id=c.object_id and e.minor_id=a.column_id and e.class=1 where c.name={0} order by a.column_id"; public static final String SQLSERVER_ALLCOLUMNS_SQL = "select distinct cast(a.name as varchar(50)) column_name, cast(b.name as varchar(50)) data_type, cast(e.value as NVARCHAR(200)) comment, cast(ColumnProperty(a.object_id,a.Name,'''Precision''') as int) num_precision, cast(ColumnProperty(a.object_id,a.Name,'''Scale''') as int) num_scale, a.max_length, (case when a.is_nullable=1 then '''y''' else '''n''' end) nullable,column_id from sys.columns a left join sys.types b on a.user_type_id=b.user_type_id left join (select top 1 * from sys.objects where type = '''U''' and name ={0} order by name) c on a.object_id=c.object_id left join sys.extended_properties e on e.major_id=c.object_id and e.minor_id=a.column_id and e.class=1 where c.name={0} order by a.column_id";
String POSTGRESQL_ALLCOLUMNS_SQL = "select icm.column_name as field,icm.udt_name as type,fieldtxt.descript as comment, icm.numeric_precision_radix as column_precision ,icm.numeric_scale as column_scale ,icm.character_maximum_length as Char_Length,icm.is_nullable as attnotnull from information_schema.columns icm, (SELECT A.attnum,( SELECT description FROM pg_catalog.pg_description WHERE objoid = A.attrelid AND objsubid = A.attnum ) AS descript,A.attname FROM\tpg_catalog.pg_attribute A WHERE A.attrelid = ( SELECT oid FROM pg_class WHERE relname = {0} ) AND A.attnum > 0 AND NOT A.attisdropped ORDER BY\tA.attnum ) fieldtxt where icm.table_name={1} and fieldtxt.attname = icm.column_name"; public static final String POSTGRESQL_ALLCOLUMNS_SQL = "select icm.column_name as field,icm.udt_name as type,fieldtxt.descript as comment, icm.numeric_precision_radix as column_precision ,icm.numeric_scale as column_scale ,icm.character_maximum_length as Char_Length,icm.is_nullable as attnotnull from information_schema.columns icm, (SELECT A.attnum,( SELECT description FROM pg_catalog.pg_description WHERE objoid = A.attrelid AND objsubid = A.attnum ) AS descript,A.attname FROM\tpg_catalog.pg_attribute A WHERE A.attrelid = ( SELECT oid FROM pg_class WHERE relname = {0} ) AND A.attnum > 0 AND NOT A.attisdropped ORDER BY\tA.attnum ) fieldtxt where icm.table_name={1} and fieldtxt.attname = icm.column_name";
String MYSQL_ALLTABLES_SQL = "select distinct table_name from information_schema.columns where table_schema = {0}"; public static final String MYSQL_ALLTABLES_SQL = "select distinct table_name from information_schema.columns where table_schema = {0}";
String ORACLE_ALLTABLES_SQL = "select distinct colstable.table_name as table_name from user_tab_cols colstable order by colstable.table_name"; public static final String ORACLE_ALLTABLES_SQL = "select distinct colstable.table_name as table_name from user_tab_cols colstable order by colstable.table_name";
String SQLSERVER_ALLTABLES_SQL = "select distinct c.name as table_name from sys.objects c where c.type = 'U' "; public static final String SQLSERVER_ALLTABLES_SQL = "select distinct c.name as table_name from sys.objects c where c.type = 'U' ";
String POSTGRESQL_ALLTABLES_SQL = "select tablename from pg_tables where schemaname='public'"; public static final String POSTGRESQL_ALLTABLES_SQL = "select tablename from pg_tables where schemaname='public'";
} }
@@ -12,7 +12,7 @@ import java.util.List;
@Slf4j @Slf4j
public class CreateFileConfig { public class CreateFileConfig {
private String templatePath; private String templatePath;
private List<File> templateRootDirs = new ArrayList(); private List<File> templateRootDirs = new ArrayList<>();
private String stylePath; private String stylePath;
public CreateFileConfig(String templatePath) { public CreateFileConfig(String templatePath) {
@@ -65,7 +65,7 @@ public class CreateFileConfig {
public List<File> listTemplateRootDirs() throws UnsupportedEncodingException { public List<File> listTemplateRootDirs() throws UnsupportedEncodingException {
String file = this.getClass().getResource(this.templatePath).getFile(); String file = this.getClass().getResource(this.templatePath).getFile();
// 对中文路径进行处理 // 对中文路径进行处理
file = URLDecoder.decode(file.replaceAll("%20", " "), "UTF-8"); file = URLDecoder.decode(file.replace("%20", " "), "UTF-8");
log.debug("-------classpath-------" + file); log.debug("-------classpath-------" + file);
if (file.indexOf("/BOOT-INF/classes!") != -1 || file.indexOf("/BOOT-INF/lib/") != -1) { if (file.indexOf("/BOOT-INF/classes!") != -1 || file.indexOf("/BOOT-INF/lib/") != -1) {
@@ -5,6 +5,7 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import com.jero.codegenerate.properties.CodeConfigProperties;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import com.jero.codegenerate.database.DbReadTableUtil; import com.jero.codegenerate.database.DbReadTableUtil;
@@ -33,7 +34,7 @@ public class CodeGenerateOne extends BaseCodeGenerate implements IGenerate {
@Override @Override
public Map<String, Object> getCodeGenerateConfig() throws Exception { public Map<String, Object> getCodeGenerateConfig() throws Exception {
HashMap var1 = new HashMap(); HashMap<String, Object> var1 = new HashMap<>();
var1.put("bussiPackage", com.jero.codegenerate.properties.CodeConfigProperties.packageName); var1.put("bussiPackage", com.jero.codegenerate.properties.CodeConfigProperties.packageName);
var1.put("entityPackage", this.tableVo.getEntityPackage()); var1.put("entityPackage", this.tableVo.getEntityPackage());
var1.put("entityName", this.tableVo.getEntityName()); var1.put("entityName", this.tableVo.getEntityName());
@@ -54,12 +55,12 @@ public class CodeGenerateOne extends BaseCodeGenerate implements IGenerate {
var1.put("tableVo", this.tableVo); var1.put("tableVo", this.tableVo);
try { try {
if (this.columns == null || this.columns.size() == 0) { if (this.columns == null || this.columns.isEmpty()) {
this.columns = DbReadTableUtil.listColumns(this.tableVo.getTableName()); this.columns = DbReadTableUtil.listColumns(this.tableVo.getTableName());
} }
var1.put("columns", this.columns); var1.put("columns", this.columns);
if (this.originalColumns == null || this.originalColumns.size() == 0) { if (this.originalColumns == null || this.originalColumns.isEmpty()) {
this.originalColumns = DbReadTableUtil.listOriginalColumns(this.tableVo.getTableName()); this.originalColumns = DbReadTableUtil.listOriginalColumns(this.tableVo.getTableName());
} }
@@ -68,7 +69,7 @@ public class CodeGenerateOne extends BaseCodeGenerate implements IGenerate {
while(iterator.hasNext()) { while(iterator.hasNext()) {
ColumnVo var3 = (ColumnVo)iterator.next(); ColumnVo var3 = (ColumnVo)iterator.next();
if (var3.getFieldName().toLowerCase().equals(com.jero.codegenerate.properties.CodeConfigProperties.dbTableId.toLowerCase())) { if (var3.getFieldName().equalsIgnoreCase(CodeConfigProperties.dbTableId)) {
var1.put("primaryKeyPolicy", var3.getFieldType()); var1.put("primaryKeyPolicy", var3.getFieldType());
} }
} }
@@ -86,7 +87,7 @@ public class CodeGenerateOne extends BaseCodeGenerate implements IGenerate {
public List<String> generateCodeFile(String stylePath) throws Exception { public List<String> generateCodeFile(String stylePath) throws Exception {
log.debug("----jero---Code----Generation----[单表模型:" + this.tableVo.getTableName() + "]------- 生成中。。。"); log.debug("----jero---Code----Generation----[单表模型:" + this.tableVo.getTableName() + "]------- 生成中。。。");
String projectPath = com.jero.codegenerate.properties.CodeConfigProperties.projectPath; String projectPath = com.jero.codegenerate.properties.CodeConfigProperties.projectPath;
Map codeGenerateConfig = this.getCodeGenerateConfig(); Map<String, Object> codeGenerateConfig = this.getCodeGenerateConfig();
String templateUrl = com.jero.codegenerate.properties.CodeConfigProperties.templateUrl; String templateUrl = com.jero.codegenerate.properties.CodeConfigProperties.templateUrl;
if (dealAndGetTemplateUrl(templateUrl, "/").equals("jero/code-template")) { if (dealAndGetTemplateUrl(templateUrl, "/").equals("jero/code-template")) {
templateUrl = "/" + dealAndGetTemplateUrl(templateUrl, "/") + "/one"; templateUrl = "/" + dealAndGetTemplateUrl(templateUrl, "/") + "/one";
@@ -6,6 +6,7 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import com.jero.codegenerate.properties.CodeConfigProperties;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import com.jero.codegenerate.database.DbReadTableUtil; import com.jero.codegenerate.database.DbReadTableUtil;
@@ -19,16 +20,12 @@ import com.jero.codegenerate.generate.util.NonceUtils;
@Slf4j @Slf4j
public class CodeGenerateOneToMany extends BaseCodeGenerate implements IGenerate { public class CodeGenerateOneToMany extends BaseCodeGenerate implements IGenerate {
private static String f;
public static String A = "A";
public static String B = "B";
// 主表vo // 主表vo
private MainTableVo mainTableVo; private MainTableVo mainTableVo;
private List<ColumnVo> mainColumns; private List<ColumnVo> mainColumns;
private List<ColumnVo> originalMainColumns; private List<ColumnVo> originalMainColumns;
// 从表集合 // 从表集合
private List<SubTableVo> subTables; private List<SubTableVo> subTables;
private static DbReadTableUtil dbReadTableUtil = new DbReadTableUtil();
public CodeGenerateOneToMany(MainTableVo mainTableVo, List<SubTableVo> subTables) { public CodeGenerateOneToMany(MainTableVo mainTableVo, List<SubTableVo> subTables) {
this.subTables = subTables; this.subTables = subTables;
@@ -49,7 +46,7 @@ public class CodeGenerateOneToMany extends BaseCodeGenerate implements IGenerate
*/ */
@Override @Override
public Map<String, Object> getCodeGenerateConfig() throws Exception { public Map<String, Object> getCodeGenerateConfig() throws Exception {
HashMap hashMap = new HashMap(); HashMap<String,Object> hashMap = new HashMap<>();
// 包名 // 包名
hashMap.put("bussiPackage", com.jero.codegenerate.properties.CodeConfigProperties.packageName); hashMap.put("bussiPackage", com.jero.codegenerate.properties.CodeConfigProperties.packageName);
// 实体包名 // 实体包名
@@ -76,11 +73,11 @@ public class CodeGenerateOneToMany extends BaseCodeGenerate implements IGenerate
hashMap.put("tableVo", this.mainTableVo); hashMap.put("tableVo", this.mainTableVo);
try { try {
if (this.mainColumns == null || this.mainColumns.size() == 0) { if (this.mainColumns == null || this.mainColumns.isEmpty()) {
this.mainColumns = DbReadTableUtil.listColumns(this.mainTableVo.getTableName()); this.mainColumns = DbReadTableUtil.listColumns(this.mainTableVo.getTableName());
} }
if (this.originalMainColumns == null || this.originalMainColumns.size() == 0) { if (this.originalMainColumns == null || this.originalMainColumns.isEmpty()) {
this.originalMainColumns = DbReadTableUtil.listOriginalColumns(this.mainTableVo.getTableName()); this.originalMainColumns = DbReadTableUtil.listOriginalColumns(this.mainTableVo.getTableName());
} }
@@ -91,7 +88,7 @@ public class CodeGenerateOneToMany extends BaseCodeGenerate implements IGenerate
while(iterator.hasNext()) { while(iterator.hasNext()) {
ColumnVo columnVo = (ColumnVo)iterator.next(); ColumnVo columnVo = (ColumnVo)iterator.next();
// 主键类型 // 主键类型
if (columnVo.getFieldName().toLowerCase().equals(com.jero.codegenerate.properties.CodeConfigProperties.dbTableId.toLowerCase())) { if (columnVo.getFieldName().equalsIgnoreCase(CodeConfigProperties.dbTableId)) {
hashMap.put("primaryKeyPolicy", columnVo.getFieldType()); hashMap.put("primaryKeyPolicy", columnVo.getFieldType());
} }
} }
@@ -101,20 +98,20 @@ public class CodeGenerateOneToMany extends BaseCodeGenerate implements IGenerate
while(iterator.hasNext()) { while(iterator.hasNext()) {
// 从表(局部变量) // 从表(局部变量)
SubTableVo subTableVo = (SubTableVo)iterator.next(); SubTableVo subTableVo = (SubTableVo)iterator.next();
List originalColumns; List<ColumnVo> originalColumns;
if (subTableVo.getColums() == null || subTableVo.getColums().size() == 0) { if (subTableVo.getColums() == null || subTableVo.getColums().isEmpty()) {
originalColumns = DbReadTableUtil.listColumns(subTableVo.getTableName()); originalColumns = DbReadTableUtil.listColumns(subTableVo.getTableName());
subTableVo.setColums(originalColumns); subTableVo.setColums(originalColumns);
} }
if (subTableVo.getOriginalColumns() == null || subTableVo.getOriginalColumns().size() == 0) { if (subTableVo.getOriginalColumns() == null || subTableVo.getOriginalColumns().isEmpty()) {
originalColumns = DbReadTableUtil.listOriginalColumns(subTableVo.getTableName()); originalColumns = DbReadTableUtil.listOriginalColumns(subTableVo.getTableName());
subTableVo.setOriginalColumns(originalColumns); subTableVo.setOriginalColumns(originalColumns);
} }
// 从表外键 // 从表外键
String[] foreignKeys = subTableVo.getForeignKeys(); String[] foreignKeys = subTableVo.getForeignKeys();
// 存储外键的集合 // 存储外键的集合
ArrayList list = new ArrayList(); ArrayList<String> list = new ArrayList<>();
String[] foreignKeys1 = foreignKeys; String[] foreignKeys1 = foreignKeys;
int length = foreignKeys.length; int length = foreignKeys.length;
@@ -123,7 +120,7 @@ public class CodeGenerateOneToMany extends BaseCodeGenerate implements IGenerate
list.add(DbReadTableUtil.convertForeignKeyToCamelCase(foreignKey)); list.add(DbReadTableUtil.convertForeignKeyToCamelCase(foreignKey));
} }
// put外键数组 // put外键数组
subTableVo.setForeignKeys((String[])list.toArray(new String[0])); subTableVo.setForeignKeys(list.toArray(new String[0]));
subTableVo.setOriginalForeignKeys(foreignKeys); subTableVo.setOriginalForeignKeys(foreignKeys);
} }
// put从表集合 // put从表集合
@@ -141,7 +138,7 @@ public class CodeGenerateOneToMany extends BaseCodeGenerate implements IGenerate
@Override @Override
public List<String> generateCodeFile(String stylePath) throws Exception { public List<String> generateCodeFile(String stylePath) throws Exception {
String projectPath = com.jero.codegenerate.properties.CodeConfigProperties.projectPath; String projectPath = com.jero.codegenerate.properties.CodeConfigProperties.projectPath;
Map configMap = this.getCodeGenerateConfig(); Map<String, Object> configMap = this.getCodeGenerateConfig();
String templateUrl = com.jero.codegenerate.properties.CodeConfigProperties.templateUrl; String templateUrl = com.jero.codegenerate.properties.CodeConfigProperties.templateUrl;
if (dealAndGetTemplateUrl(templateUrl, "/").equals("jero/code-template")) { if (dealAndGetTemplateUrl(templateUrl, "/").equals("jero/code-template")) {
templateUrl = "/" + dealAndGetTemplateUrl(templateUrl, "/") + "/onetomany"; templateUrl = "/" + dealAndGetTemplateUrl(templateUrl, "/") + "/onetomany";
@@ -11,9 +11,11 @@ import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.io.Writer; import java.io.Writer;
import java.nio.file.Files;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import com.jero.codegenerate.generate.config.CreateFileConfig; import com.jero.codegenerate.generate.config.CreateFileConfig;
import com.jero.codegenerate.generate.util.FileHelper; import com.jero.codegenerate.generate.util.FileHelper;
@@ -24,10 +26,8 @@ import lombok.extern.slf4j.Slf4j;
public class BaseCodeGenerate { public class BaseCodeGenerate {
protected static String characterSet = "UTF-8"; protected static String characterSet = "UTF-8";
protected List<String> messageList = new ArrayList(); protected List<String> messageList = new ArrayList<>();
public BaseCodeGenerate() {
}
/** /**
* 生成项目文件 * 生成项目文件
* @date 2021/4/2 14:32 * @date 2021/4/2 14:32
@@ -41,7 +41,7 @@ public class BaseCodeGenerate {
for(int i = 0; i < createFileConfig.listTemplateRootDirs().size(); ++i) { for(int i = 0; i < createFileConfig.listTemplateRootDirs().size(); ++i) {
// 获取一个模板根目录 // 获取一个模板根目录
File templateRootDir = (File)createFileConfig.listTemplateRootDirs().get(i); File templateRootDir = createFileConfig.listTemplateRootDirs().get(i);
this.createOutPutFile(projectPath, templateRootDir, configMap, createFileConfig); this.createOutPutFile(projectPath, templateRootDir, configMap, createFileConfig);
} }
@@ -63,13 +63,13 @@ public class BaseCodeGenerate {
} else { } else {
log.info(" load template from templateRootDir = '" + templateRootDir.getAbsolutePath() + "',stylePath ='" + createFileConfig.getStylePath() + "', out GenerateRootDir:" + com.jero.codegenerate.properties.CodeConfigProperties.projectPath); log.info(" load template from templateRootDir = '" + templateRootDir.getAbsolutePath() + "',stylePath ='" + createFileConfig.getStylePath() + "', out GenerateRootDir:" + com.jero.codegenerate.properties.CodeConfigProperties.projectPath);
// 获取模板目录下的模板 // 获取模板目录下的模板
List templateFileList = FileHelper.listFileAndSort(templateRootDir); List<File> templateFileList = FileHelper.listFileAndSort(templateRootDir);
log.debug("----srcFiles----size-----------" + templateFileList.size()); log.debug("----srcFiles----size-----------" + templateFileList.size());
log.debug("----srcFiles----list------------" + templateFileList.toString()); log.debug("----srcFiles----list------------" + templateFileList.toString());
for(int i = 0; i < templateFileList.size(); ++i) { for(int i = 0; i < templateFileList.size(); ++i) {
// 获取一个模板文件 // 获取一个模板文件
File srcFile = (File)templateFileList.get(i); File srcFile = templateFileList.get(i);
this.createOutPutFile(projectPath, templateRootDir, configMap, srcFile, createFileConfig); this.createOutPutFile(projectPath, templateRootDir, configMap, srcFile, createFileConfig);
} }
@@ -97,6 +97,9 @@ public class BaseCodeGenerate {
} }
//模板文件目录 //模板文件目录
String outputFilepath = getTemplatePath(configMap, templateFilePath, createFileConfig); String outputFilepath = getTemplatePath(configMap, templateFilePath, createFileConfig);
if(Objects.isNull(outputFilepath)){
return;
}
log.debug("-------outputFilepath--" + outputFilepath); log.debug("-------outputFilepath--" + outputFilepath);
String packageDir; String packageDir;
// 输出文件路径以 java 开头 // 输出文件路径以 java 开头
@@ -182,18 +185,16 @@ public class BaseCodeGenerate {
* @return void * @return void
*/ */
protected void splitFileAndGenerate(File file, String str) { protected void splitFileAndGenerate(File file, String str) {
InputStreamReader isr = null; ArrayList<OutputStreamWriter> list = new ArrayList<>();
BufferedReader bf = null;
ArrayList list = new ArrayList();
boolean flag = false; boolean flag = false;
int i; int i;
label341: { label341: {
label342: { label342: {
try { try (InputStreamReader isr = new InputStreamReader(new FileInputStream(file), characterSet);
BufferedReader bf = new BufferedReader(isr);){
flag = true; flag = true;
isr = new InputStreamReader(new FileInputStream(file), characterSet);
bf = new BufferedReader(isr);
boolean b = false; boolean b = false;
OutputStreamWriter osw = null; OutputStreamWriter osw = null;
@@ -214,16 +215,13 @@ public class BaseCodeGenerate {
this.messageList.add("生成成功:" + substring); this.messageList.add("生成成功:" + substring);
b = true; b = true;
} else if (b) { } else if (b) {
osw.append(s + "\r\n"); osw.append(s).append("\r\n");
} }
} }
for(int j = 0; j < list.size(); ++j) { for(int j = 0; j < list.size(); ++j) {
((Writer)list.get(j)).close(); ((Writer)list.get(j)).close();
} }
bf.close();
isr.close();
log.debug("[generate]\t delete file:" + file.getAbsolutePath()); log.debug("[generate]\t delete file:" + file.getAbsolutePath());
// 删除文件 // 删除文件
delFile(file); delFile(file);
@@ -240,15 +238,7 @@ public class BaseCodeGenerate {
} finally { } finally {
if (flag) { if (flag) {
try { try {
if (bf != null) { if (!list.isEmpty()) {
bf.close();
}
if (isr != null) {
isr.close();
}
if (list.size() > 0) {
for(int var12 = 0; var12 < list.size(); ++var12) { for(int var12 = 0; var12 < list.size(); ++var12) {
if (list.get(var12) != null) { if (list.get(var12) != null) {
((Writer)list.get(var12)).close(); ((Writer)list.get(var12)).close();
@@ -263,15 +253,8 @@ public class BaseCodeGenerate {
} }
try { try {
if (bf != null) {
bf.close();
}
if (isr != null) { if (!list.isEmpty()) {
isr.close();
}
if (list.size() > 0) {
for(i = 0; i < list.size(); ++i) { for(i = 0; i < list.size(); ++i) {
if (list.get(i) != null) { if (list.get(i) != null) {
((Writer)list.get(i)).close(); ((Writer)list.get(i)).close();
@@ -286,15 +269,8 @@ public class BaseCodeGenerate {
} }
try { try {
if (bf != null) {
bf.close();
}
if (isr != null) { if (!list.isEmpty()) {
isr.close();
}
if (list.size() > 0) {
for(i = 0; i < list.size(); ++i) { for(i = 0; i < list.size(); ++i) {
if (list.get(i) != null) { if (list.get(i) != null) {
((Writer)list.get(i)).close(); ((Writer)list.get(i)).close();
@@ -309,15 +285,7 @@ public class BaseCodeGenerate {
} }
try { try {
if (bf != null) { if (!list.isEmpty()) {
bf.close();
}
if (isr != null) {
isr.close();
}
if (list.size() > 0) {
for(i = 0; i < list.size(); ++i) { for(i = 0; i < list.size(); ++i) {
if (list.get(i) != null) { if (list.get(i) != null) {
((Writer)list.get(i)).close(); ((Writer)list.get(i)).close();
@@ -339,7 +307,6 @@ public class BaseCodeGenerate {
*/ */
protected static String getTemplatePath(Map<String, Object> configMap, String templateFilePath, CreateFileConfig createFileConfig) throws Exception { protected static String getTemplatePath(Map<String, Object> configMap, String templateFilePath, CreateFileConfig createFileConfig) throws Exception {
String templateFilePath1 = templateFilePath; String templateFilePath1 = templateFilePath;
boolean flag = true;
int i; int i;
// ascii 64 = @ // ascii 64 = @
if ((i = templateFilePath.indexOf(64)) != -1) { if ((i = templateFilePath.indexOf(64)) != -1) {
@@ -348,7 +315,7 @@ public class BaseCodeGenerate {
String substring = templateFilePath.substring(i + 1); String substring = templateFilePath.substring(i + 1);
Object o = configMap.get(substring); Object o = configMap.get(substring);
if (o == null) { if (o == null) {
System.err.println("[not-generate] WARN: test expression is null by key:[" + substring + "] on template:[" + templateFilePath + "]"); log.error("[not-generate] WARN: test expression is null by key:[" + substring + "] on template:[" + templateFilePath + "]");
return null; return null;
} }
@@ -361,7 +328,7 @@ public class BaseCodeGenerate {
Configuration configuration = FreemarkerHelper.getConfiguration(createFileConfig.listTemplateRootDirs(), characterSet, "/"); Configuration configuration = FreemarkerHelper.getConfiguration(createFileConfig.listTemplateRootDirs(), characterSet, "/");
templateFilePath1 = FreemarkerHelper.getFillTemplateString(templateFilePath1, configMap, configuration); templateFilePath1 = FreemarkerHelper.getFillTemplateString(templateFilePath1, configMap, configuration);
String stylePath = createFileConfig.getStylePath(); String stylePath = createFileConfig.getStylePath();
if (stylePath != null && stylePath != "") { if (stylePath != null && !"".equals(stylePath)) {
templateFilePath1 = templateFilePath1.substring(stylePath.length() + 1); templateFilePath1 = templateFilePath1.substring(stylePath.length() + 1);
} }
// 后缀名 // 后缀名
@@ -376,11 +343,11 @@ public class BaseCodeGenerate {
* @param file * @param file
* @return boolean * @return boolean
*/ */
protected static boolean delFile(File file) { protected static boolean delFile(File file) throws IOException {
boolean flag = false; boolean flag = false;
for(int i = 0; !flag && i++ < 10; flag = file.delete()) { for(int i = 0; !flag && i++ < 10;flag = Files.deleteIfExists(file.toPath())) {
System.gc(); log.info("");
} }
return flag; return flag;
@@ -20,8 +20,6 @@ public class CgFormColumnExtendVo {
protected String defaultVal; protected String defaultVal;
protected String uploadnum; protected String uploadnum;
public CgFormColumnExtendVo() {
}
public String getUploadnum() { public String getUploadnum() {
return this.uploadnum; return this.uploadnum;
@@ -16,9 +16,6 @@ public class ColumnVo extends CgFormColumnExtendVo {
private String classType_row = ""; private String classType_row = "";
private String optionType = ""; private String optionType = "";
public ColumnVo() {
}
public String getFieldDbType() { public String getFieldDbType() {
return this.fieldDbType; return this.fieldDbType;
} }
@@ -92,7 +89,7 @@ public class ColumnVo extends CgFormColumnExtendVo {
} }
public String getClassType_row() { public String getClassType_row() {
return this.classType != null && this.classType.indexOf("easyui-") >= 0 ? this.classType.replaceAll("easyui-", "") : this.classType_row; return this.classType != null && this.classType.contains("easyui-") ? this.classType.replace("easyui-", "") : this.classType_row;
} }
public void setClassType_row(String classType_row) { public void setClassType_row(String classType_row) {
@@ -14,8 +14,6 @@ public class TableVo {
private Integer fieldRequiredNum; private Integer fieldRequiredNum;
private Map<?, ?> extendParams; private Map<?, ?> extendParams;
public TableVo() {
}
public String getEntityPackage() { public String getEntityPackage() {
return this.entityPackage; return this.entityPackage;
@@ -17,8 +17,6 @@ public class MainTableVo {
public Integer fieldRequiredNum; public Integer fieldRequiredNum;
private Map<?, ?> extendParams; private Map<?, ?> extendParams;
public MainTableVo() {
}
public Map<?, ?> getExtendParams() { public Map<?, ?> getExtendParams() {
return this.extendParams; return this.extendParams;
@@ -21,8 +21,6 @@ public class SubTableVo {
private List<ColumnVo> originalColumns; private List<ColumnVo> originalColumns;
private Map<?, ?> extendParams; private Map<?, ?> extendParams;
public SubTableVo() {
}
public Map<?, ?> getExtendParams() { public Map<?, ?> getExtendParams() {
return this.extendParams; return this.extendParams;
@@ -12,11 +12,9 @@ import org.apache.commons.lang.StringUtils;
@Slf4j @Slf4j
public class FileHelper { public class FileHelper {
public static List<String> dirNameList = new ArrayList(); public static List<String> dirNameList = new ArrayList<>();
public static List<String> fileSuffixList = new ArrayList(); public static List<String> fileSuffixList = new ArrayList<>();
public FileHelper() {
}
static { static {
dirNameList.add(".svn"); dirNameList.add(".svn");
@@ -37,14 +35,9 @@ public class FileHelper {
* @return java.util.List<java.io.File> * @return java.util.List<java.io.File>
*/ */
public static List<File> listFileAndSort(File dir) throws IOException { public static List<File> listFileAndSort(File dir) throws IOException {
ArrayList list = new ArrayList(); ArrayList<File> list = new ArrayList<>();
dfsAndAddFile(dir, (List)list); dfsAndAddFile(dir, list);
Collections.sort(list, new Comparator<File>() { Collections.sort(list, (var1, var2) -> var1.getAbsolutePath().compareTo(var2.getAbsolutePath()));
@Override
public int compare(File var1, File var2) {
return var1.getAbsolutePath().compareTo(var2.getAbsolutePath());
}
});
return list; return list;
} }
/** /**
@@ -88,7 +81,7 @@ public class FileHelper {
* @return boolean * @return boolean
*/ */
public static boolean isFile(File file) { public static boolean isFile(File file) {
return file.isDirectory() ? false : isSuffixNotBlank(file.getName()); return !file.isDirectory() && isSuffixNotBlank(file.getName());
} }
/** /**
* 后缀名是否为空白 * 后缀名是否为空白
@@ -163,7 +156,7 @@ public class FileHelper {
*/ */
private static boolean isSuffixContain(File file) { private static boolean isSuffixContain(File file) {
for(int i = 0; i < fileSuffixList.size(); ++i) { for(int i = 0; i < fileSuffixList.size(); ++i) {
if (file.getName().endsWith((String) fileSuffixList.get(i))) { if (file.getName().endsWith(fileSuffixList.get(i))) {
return true; return true;
} }
} }
@@ -22,8 +22,6 @@ import java.util.StringTokenizer;
@Slf4j @Slf4j
public class FreemarkerHelper { public class FreemarkerHelper {
public FreemarkerHelper() {
}
/** /**
* 获取配置类 * 获取配置类
* @date 2021/4/2 15:47 * @date 2021/4/2 15:47
@@ -39,7 +37,7 @@ public class FreemarkerHelper {
FileTemplateLoader[] fileTemplateLoaders = new FileTemplateLoader[templateRootDirs.size()]; FileTemplateLoader[] fileTemplateLoaders = new FileTemplateLoader[templateRootDirs.size()];
for(int i = 0; i < templateRootDirs.size(); ++i) { for(int i = 0; i < templateRootDirs.size(); ++i) {
File file = (File)templateRootDirs.get(i); File file = templateRootDirs.get(i);
log.debug(" FileTemplateLoader " + file.getAbsolutePath()); log.debug(" FileTemplateLoader " + file.getAbsolutePath());
fileTemplateLoaders[i] = new FileTemplateLoader(file); fileTemplateLoaders[i] = new FileTemplateLoader(file);
} }
@@ -54,7 +52,7 @@ public class FreemarkerHelper {
public static List<String> a(String var0, String var1) { public static List<String> a(String var0, String var1) {
String[] var2 = b(var0, "\\/"); String[] var2 = b(var0, "\\/");
ArrayList var3 = new ArrayList(); ArrayList<String> var3 = new ArrayList<>();
var3.add(var1); var3.add(var1);
var3.add(File.separator + var1); var3.add(File.separator + var1);
String var4 = ""; String var4 = "";
@@ -72,14 +70,14 @@ public class FreemarkerHelper {
return new String[0]; return new String[0];
} else { } else {
StringTokenizer var2 = new StringTokenizer(var0, var1); StringTokenizer var2 = new StringTokenizer(var0, var1);
ArrayList var3 = new ArrayList(); ArrayList<String> var3 = new ArrayList<>();
while(var2.hasMoreElements()) { while(var2.hasMoreElements()) {
Object var4 = var2.nextElement(); Object var4 = var2.nextElement();
var3.add(var4.toString()); var3.add(var4.toString());
} }
return (String[])var3.toArray(new String[var3.size()]); return var3.toArray(new String[var3.size()]);
} }
} }
/** /**
@@ -5,18 +5,18 @@ import java.security.SecureRandom;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.UUID; import java.util.UUID;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.RandomStringUtils; import org.apache.commons.lang.RandomStringUtils;
/** /**
* Nonce Number Once 只使用一次的数字相关工具类 * Nonce Number Once 只使用一次的数字相关工具类
*/ */
@Slf4j
public class NonceUtils { public class NonceUtils {
private static final SimpleDateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
private static final String[] NUMBER_STRINGS = new String[]{"0", "00", "0000", "00000000"}; private static final String[] NUMBER_STRINGS = new String[]{"0", "00", "0000", "00000000"};
private static Date date; private static Date date;
private static int count = 0; private static int count = 0;
public NonceUtils() {
}
/** /**
* 生成指定长度随机字符串 * 生成指定长度随机字符串
* @date 2021/4/6 9:01 * @date 2021/4/6 9:01
@@ -72,6 +72,7 @@ public class NonceUtils {
* @return java.lang.String * @return java.lang.String
*/ */
public static String getNow() { public static String getNow() {
SimpleDateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
Date date = new Date(); Date date = new Date();
return SIMPLE_DATE_FORMAT.format(date); return SIMPLE_DATE_FORMAT.format(date);
} }
@@ -133,6 +134,6 @@ public class NonceUtils {
} }
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
System.out.println(getSecureRandomLong() + getCurrentTimeMillis()); log.info(getSecureRandomLong() + getCurrentTimeMillis() + "");
} }
} }
@@ -11,8 +11,7 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
public class SimpleFormat { public class SimpleFormat {
public SimpleFormat() {
}
/** /**
* 下划线字符串转换为驼峰字符串 * 下划线字符串转换为驼峰字符串
* @date 2021/4/6 9:55 * @date 2021/4/6 9:55
@@ -158,16 +157,16 @@ public class SimpleFormat {
* @return java.lang.String * @return java.lang.String
*/ */
public String getInStrs(List<String> stringList) { public String getInStrs(List<String> stringList) {
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
Iterator iterator = stringList.iterator(); Iterator iterator = stringList.iterator();
while(iterator.hasNext()) { while(iterator.hasNext()) {
String s = (String)iterator.next(); String s = (String)iterator.next();
sb.append("'" + s + "',"); sb.append("'").append(s).append("',");
} }
String string = sb.toString(); String string = sb.toString();
if ("".equals(string) && !string.endsWith(",")) { if ("".equals(string)) {
return null; return null;
} else { } else {
string = string.substring(0, string.length() - 1); string = string.substring(0, string.length() - 1);
@@ -3,8 +3,7 @@ package com.jero.codegenerate.generate.util;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
public class TableConvert { public class TableConvert {
public TableConvert() {
}
/** /**
* 校验字段为 '是' 或 '否' * 校验字段为 '是' 或 '否'
* @date 2021/4/6 10:46 * @date 2021/4/6 10:46
@@ -36,30 +36,20 @@ public class CodeConfigProperties {
public static String pageFilterFields; public static String pageFilterFields;
public static String fieldRowNum; public static String fieldRowNum;
private static ResourceBundle getDatasourcePropties(String url) { public static final String MY_SQL = "mysql";
PropertyResourceBundle propertyResourceBundle = null; public static final String SQL_SERVER = "sqlserver";
BufferedInputStream bufferedInputStream = null;
String configPath = System.getProperty("user.dir") + File.separator + "config" + File.separator + url + ".properties";
try { private static ResourceBundle getDatasourcePropties(String url) {
bufferedInputStream = new BufferedInputStream(new FileInputStream(configPath)); String configPath = System.getProperty("user.dir") + File.separator + "config" + File.separator + url + ".properties";
PropertyResourceBundle propertyResourceBundle = null;
try (BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(configPath))){
propertyResourceBundle = new PropertyResourceBundle(bufferedInputStream); propertyResourceBundle = new PropertyResourceBundle(bufferedInputStream);
bufferedInputStream.close();
if (propertyResourceBundle != null) { if (propertyResourceBundle != null) {
log.info(" JAR方式部署,通过config目录读取配置:" + configPath); log.info(" JAR方式部署,通过config目录读取配置:" + configPath);
} }
} catch (IOException e) { } catch (IOException e) {
} finally { e.printStackTrace();
if (bufferedInputStream != null) {
try {
bufferedInputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
} }
return propertyResourceBundle; return propertyResourceBundle;
} }
@@ -85,7 +75,7 @@ public class CodeConfigProperties {
public static final boolean getDbFiledConvert() { public static final boolean getDbFiledConvert() {
String dbFiledConvert = configDatasourcePropties.getString("db_filed_convert"); String dbFiledConvert = configDatasourcePropties.getString("db_filed_convert");
return !dbFiledConvert.toString().equals("false"); return !dbFiledConvert.equals("false");
} }
private static String getBussiPackage() { private static String getBussiPackage() {
@@ -146,7 +136,7 @@ public class CodeConfigProperties {
configDatasourcePropties = ResourceBundle.getBundle(CodeConfigProperties.CONFIG_FILE_URL); configDatasourcePropties = ResourceBundle.getBundle(CodeConfigProperties.CONFIG_FILE_URL);
} }
databaseType = "mysql"; databaseType = MY_SQL;
driverName = "com.mysql.jdbc.Driver"; driverName = "com.mysql.jdbc.Driver";
databaseUrl = "jdbc:mysql://localhost:3306/jero-boot?useUnicode=true&characterEncoding=UTF-8"; databaseUrl = "jdbc:mysql://localhost:3306/jero-boot?useUnicode=true&characterEncoding=UTF-8";
username = "root"; username = "root";
@@ -173,11 +163,11 @@ public class CodeConfigProperties {
dbFiledConvert = getDbFiledConvert(); dbFiledConvert = getDbFiledConvert();
pageFilterFields = getPageFilterFields(); pageFilterFields = getPageFilterFields();
pageSearchFieldNum = getPageSearchFieldNum(); pageSearchFieldNum = getPageSearchFieldNum();
if (databaseUrl.indexOf("mysql") < 0 && databaseUrl.indexOf("MYSQL") < 0) { if (!databaseUrl.contains(MY_SQL) && !databaseUrl.contains("MYSQL")) {
if (databaseUrl.indexOf("oracle") < 0 && databaseUrl.indexOf("ORACLE") < 0) { if (!databaseUrl.contains("oracle") && !databaseUrl.contains("ORACLE")) {
if (databaseUrl.indexOf("postgresql") < 0 && databaseUrl.indexOf("POSTGRESQL") < 0) { if (!databaseUrl.contains("postgresql") && !databaseUrl.contains("POSTGRESQL")) {
if (databaseUrl.indexOf("sqlserver") >= 0 || databaseUrl.indexOf("sqlserver") >= 0) { if (databaseUrl.contains(SQL_SERVER) || databaseUrl.contains("sql server")) {
databaseType = "sqlserver"; databaseType = SQL_SERVER;
} }
} else { } else {
databaseType = "postgresql"; databaseType = "postgresql";
@@ -186,7 +176,7 @@ public class CodeConfigProperties {
databaseType = "oracle"; databaseType = "oracle";
} }
} else { } else {
databaseType = "mysql"; databaseType = MY_SQL;
} }
sourceRootPackage = sourceRootPackage.replace(".", "/"); sourceRootPackage = sourceRootPackage.replace(".", "/");