【fix sonar】codegenerate文件夹

This commit is contained in:
梁琦涛
2023-03-17 09:59:09 +08:00
parent c605aaf1f6
commit b2301b1722
11 changed files with 35 additions and 33 deletions
@@ -567,11 +567,9 @@ public class DbReadTableUtil {
public void release(Connection connection, Statement statement) throws Exception {
if (statement != null) {
statement.close();
statement = null;
}
if (connection != null) {
connection.close();
connection = null;
}
}
}
@@ -1,6 +1,10 @@
package com.jero.codegenerate.database.util;
public class DbConvertDef {
private DbConvertDef(){
}
public static final String Y = "Y";
public static final String N = "N";
public static final String MYSQL = "mysql";
@@ -65,10 +65,8 @@ public class CodeGenerateOne extends BaseCodeGenerate implements IGenerate {
}
var1.put("originalColumns", this.originalColumns);
Iterator iterator = this.originalColumns.iterator();
while(iterator.hasNext()) {
ColumnVo var3 = (ColumnVo)iterator.next();
for (ColumnVo var3 : this.originalColumns) {
if (var3.getFieldName().equalsIgnoreCase(CodeConfigProperties.dbTableId)) {
var1.put("primaryKeyPolicy", var3.getFieldType());
}
@@ -83,21 +83,16 @@ public class CodeGenerateOneToMany extends BaseCodeGenerate implements IGenerate
hashMap.put("columns", this.mainColumns);
hashMap.put("originalColumns", this.originalMainColumns);
Iterator iterator = this.originalMainColumns.iterator();
while(iterator.hasNext()) {
ColumnVo columnVo = (ColumnVo)iterator.next();
for (ColumnVo columnVo : this.originalMainColumns) {
// 主键类型
if (columnVo.getFieldName().equalsIgnoreCase(CodeConfigProperties.dbTableId)) {
hashMap.put("primaryKeyPolicy", columnVo.getFieldType());
}
}
iterator = this.subTables.iterator();
while(iterator.hasNext()) {
for (SubTableVo subTableVo : this.subTables) {
// 从表(局部变量)
SubTableVo subTableVo = (SubTableVo)iterator.next();
List<ColumnVo> originalColumns;
if (subTableVo.getColums() == null || subTableVo.getColums().isEmpty()) {
originalColumns = DbReadTableUtil.listColumns(subTableVo.getTableName());
@@ -115,7 +110,7 @@ public class CodeGenerateOneToMany extends BaseCodeGenerate implements IGenerate
String[] foreignKeys1 = foreignKeys;
int length = foreignKeys.length;
for(int i = 0; i < length; ++i) {
for (int i = 0; i < length; ++i) {
String foreignKey = foreignKeys1[i];
list.add(DbReadTableUtil.convertForeignKeyToCamelCase(foreignKey));
}
@@ -2,15 +2,8 @@ package com.jero.codegenerate.generate.impl.base;
import freemarker.template.Configuration;
import freemarker.template.Template;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.io.*;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
@@ -20,6 +13,7 @@ import java.util.Objects;
import com.jero.codegenerate.generate.config.CreateFileConfig;
import com.jero.codegenerate.generate.util.FileHelper;
import com.jero.codegenerate.generate.util.FreemarkerHelper;
import freemarker.template.TemplateException;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@@ -36,7 +30,7 @@ public class BaseCodeGenerate {
* @param configMap 代码配置map
* @return void
*/
protected void createProject(CreateFileConfig createFileConfig, String projectPath, Map<String, Object> configMap) throws Exception {
protected void createProject(CreateFileConfig createFileConfig, String projectPath, Map<String, Object> configMap) throws IOException {
log.debug("--------generate----projectPath--------" + projectPath);
for(int i = 0; i < createFileConfig.listTemplateRootDirs().size(); ++i) {
@@ -56,7 +50,7 @@ public class BaseCodeGenerate {
* @param createFileConfig 生成文件配置
* @return void
*/
protected void createOutPutFile(String projectPath, File templateRootDir, Map<String, Object> configMap, CreateFileConfig createFileConfig) throws Exception {
protected void createOutPutFile(String projectPath, File templateRootDir, Map<String, Object> configMap, CreateFileConfig createFileConfig) throws IOException {
// 模板目录为空
if (templateRootDir == null) {
throw new IllegalStateException("'templateRootDir' must be not null");
@@ -85,7 +79,7 @@ public class BaseCodeGenerate {
* @param createFileConfig 生成文件配置
* @return void
*/
protected void createOutPutFile(String projectPath, File templateRootDir, Map<String, Object> configMap, File srcFile, CreateFileConfig createFileConfig) throws Exception {
protected void createOutPutFile(String projectPath, File templateRootDir, Map<String, Object> configMap, File srcFile, CreateFileConfig createFileConfig) {
log.debug("-------templateRootDir--" + templateRootDir.getPath());
log.debug("-------srcFile--" + srcFile.getPath());
String templateFilePath = FileHelper.getDirExcludeRootDir(templateRootDir, srcFile);
@@ -135,7 +129,7 @@ public class BaseCodeGenerate {
* @param createFileConfig 生成文件配置
* @return void
*/
protected void createOutPutFile(String templateFilePath, String outputFilepath, Map<String, Object> configMap, CreateFileConfig createFileConfig) throws Exception {
protected void createOutPutFile(String templateFilePath, String outputFilepath, Map<String, Object> configMap, CreateFileConfig createFileConfig) throws IOException, TemplateException {
if (outputFilepath.endsWith("i")) {
//将末尾的'i'去除
outputFilepath = outputFilepath.substring(0, outputFilepath.length() - 1);
@@ -305,7 +299,7 @@ public class BaseCodeGenerate {
* @param createFileConfig 生成文件配置
* @return java.lang.String
*/
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 IOException {
String templateFilePath1 = templateFilePath;
int i;
// ascii 64 = @
@@ -112,6 +112,7 @@ public class ColumnVo extends CgFormColumnExtendVo {
this.fieldDbName = fieldDbName;
}
@Override
public String toString() {
return "{\"fieldDbName\":\"" + this.fieldDbName + "\",\"fieldName\":\"" + this.fieldName + "\",\"filedComment\":\"" + this.filedComment + "\",\"fieldType\":\"" + this.fieldType + "\",\"fieldDbType\":\"" + this.fieldDbType + "\",\"classType\":\"" + this.classType + "\",\"classType_row\":\"" + this.classType_row + "\",\"optionType\":\"" + this.optionType + "\",\"charmaxLength\":\"" + this.charmaxLength + "\",\"precision\":\"" + this.precision + "\",\"scale\":\"" + this.scale + "\",\"nullable\":\"" + this.nullable + "\",\"fieldLength\":\"" + this.fieldLength + "\",\"fieldHref\":\"" + this.fieldHref + "\",\"fieldValidType\":\"" + this.fieldValidType + "\",\"fieldDefault\":\"" + this.fieldDefault + "\",\"fieldShowType\":\"" + this.fieldShowType + "\",\"fieldOrderNum\":\"" + this.fieldOrderNum + "\",\"isKey\":\"" + this.isKey + "\",\"isShow\":\"" + this.isShow + "\",\"isShowList\":\"" + this.isShowList + "\",\"isQuery\":\"" + this.isQuery + "\",\"uploadnum\":\"" + this.uploadnum + "\",\"defaultVal\":\"" + this.defaultVal + "\",\"sort\":\"" + this.sort + "\",\"readonly\":\"" + this.readonly + "\",\"queryMode\":\"" + this.queryMode + "\",\"dictField\":\"" + this.dictField + "\",\"dictTable\":\"" + this.dictTable + "\",\"dictText\":\"" + this.dictText + "\"}";
}
@@ -12,6 +12,10 @@ import org.apache.commons.lang.StringUtils;
@Slf4j
public class FileHelper {
private FileHelper(){
}
public static List<String> dirNameList = new ArrayList<>();
public static List<String> fileSuffixList = new ArrayList<>();
@@ -22,6 +22,10 @@ import java.util.StringTokenizer;
@Slf4j
public class FreemarkerHelper {
private FreemarkerHelper(){
}
/**
* 获取配置类
* @date 2021/4/2 15:47
@@ -158,10 +158,8 @@ public class SimpleFormat {
*/
public String getInStrs(List<String> stringList) {
StringBuilder sb = new StringBuilder();
Iterator iterator = stringList.iterator();
while(iterator.hasNext()) {
String s = (String)iterator.next();
for (String s : stringList) {
sb.append("'").append(s).append("',");
}
@@ -4,6 +4,10 @@ import org.apache.commons.lang.StringUtils;
public class TableConvert {
private TableConvert(){
}
/**
* 校验字段为 '是' 或 '否'
* @date 2021/4/6 10:46
@@ -15,6 +15,10 @@ import java.util.ResourceBundle;
@Slf4j
public class CodeConfigProperties {
private CodeConfigProperties(){
}
private static final String DATA_BASE_FILE_URL = "jero/jero_database";
private static final String CONFIG_FILE_URL = "jero/jero_config";
private static ResourceBundle databaseDatasourcePropties = getDatasourcePropties(CodeConfigProperties.DATA_BASE_FILE_URL);
@@ -44,9 +48,7 @@ public class CodeConfigProperties {
PropertyResourceBundle propertyResourceBundle = null;
try (BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(configPath))){
propertyResourceBundle = new PropertyResourceBundle(bufferedInputStream);
if (propertyResourceBundle != null) {
log.info(" JAR方式部署,通过config目录读取配置:" + configPath);
}
log.info(" JAR方式部署,通过config目录读取配置:" + configPath);
} catch (IOException e) {
e.printStackTrace();
}