【update】注释代码与重命名变量

This commit is contained in:
mzc5649
2021-04-02 10:54:13 +08:00
parent 5761557a6f
commit 438f4a47a5
5 changed files with 44 additions and 9 deletions
@@ -5,7 +5,15 @@ import com.jero.codegenerate.properties.CodeConfigProperties;
public class CodegenDatasourceConfig { public class CodegenDatasourceConfig {
public CodegenDatasourceConfig() { public CodegenDatasourceConfig() {
} }
/**
* 加载配置
* @date 2021/4/2 10:29
* @param DIVERNAME
* @param URL
* @param USERNAME
* @param PASSWORD
* @return void
*/
public static void initDbConfig(String DIVERNAME, String URL, String USERNAME, String PASSWORD) { public static void initDbConfig(String DIVERNAME, String URL, String USERNAME, String PASSWORD) {
CodeConfigProperties.driverName = DIVERNAME; CodeConfigProperties.driverName = DIVERNAME;
CodeConfigProperties.databaseUrl = URL; CodeConfigProperties.databaseUrl = URL;
@@ -432,7 +432,12 @@ public class DbReadTableUtil {
return fieldName; return fieldName;
} }
/**
* 将外键字符串下划线间隔命名转换为驼峰命名
* @date 2021/4/2 10:52
* @param foreignKey
* @return java.lang.String
*/
public static String convertForeignKeyToCamelCase(String foreignKey) { public static String convertForeignKeyToCamelCase(String foreignKey) {
String[] foreignKeyWords = foreignKey.split("_"); String[] foreignKeyWords = foreignKey.split("_");
foreignKey = ""; foreignKey = "";
@@ -22,7 +22,12 @@ public class CreateFileConfig {
private void setFileList(File file) { private void setFileList(File file) {
this.convertArrToList(file); this.convertArrToList(file);
} }
/**
* 将文件数组转换为文件集合
* @date 2021/4/2 10:30
* @param files
* @return void
*/
private void convertArrToList(File... files) { private void convertArrToList(File... files) {
this.fileList = Arrays.asList(files); this.fileList = Arrays.asList(files);
} }
@@ -20,13 +20,15 @@ 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; private static String f;
public static String a = "A"; public static String A = "A";
public static String b = "B"; public static String B = "B";
// 主表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 k = new DbReadTableUtil(); 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;
@@ -39,15 +41,25 @@ public class CodeGenerateOneToMany extends BaseCodeGenerate implements IGenerate
this.originalMainColumns = originalMainColumns; this.originalMainColumns = originalMainColumns;
this.subTables = subTables; this.subTables = subTables;
} }
/**
* 获取代码生成器的配置 map
* @date 2021/4/2 10:39
* @param
* @return java.util.Map<java.lang.String,java.lang.Object>
*/
@Override @Override
public Map<String, Object> getCodeGenerateConfig() throws Exception { public Map<String, Object> getCodeGenerateConfig() throws Exception {
HashMap hashMap = new HashMap(); HashMap hashMap = new HashMap();
// 包名
hashMap.put("bussiPackage", com.jero.codegenerate.properties.CodeConfigProperties.packageName); hashMap.put("bussiPackage", com.jero.codegenerate.properties.CodeConfigProperties.packageName);
// 实体包名
hashMap.put("entityPackage", this.mainTableVo.getEntityPackage()); hashMap.put("entityPackage", this.mainTableVo.getEntityPackage());
// 实体名
hashMap.put("entityName", this.mainTableVo.getEntityName()); hashMap.put("entityName", this.mainTableVo.getEntityName());
// 表名
hashMap.put("tableName", this.mainTableVo.getTableName()); hashMap.put("tableName", this.mainTableVo.getTableName());
hashMap.put("ftl_description", this.mainTableVo.getFtlDescription()); hashMap.put("ftl_description", this.mainTableVo.getFtlDescription());
// 主键名
hashMap.put("primaryKeyField", com.jero.codegenerate.properties.CodeConfigProperties.dbTableId); hashMap.put("primaryKeyField", com.jero.codegenerate.properties.CodeConfigProperties.dbTableId);
if (this.mainTableVo.getFieldRequiredNum() == null) { if (this.mainTableVo.getFieldRequiredNum() == null) {
this.mainTableVo.setFieldRequiredNum(StringUtils.isNotEmpty(com.jero.codegenerate.properties.CodeConfigProperties.fieldRequiredNum) ? Integer.parseInt(com.jero.codegenerate.properties.CodeConfigProperties.fieldRequiredNum) : -1); this.mainTableVo.setFieldRequiredNum(StringUtils.isNotEmpty(com.jero.codegenerate.properties.CodeConfigProperties.fieldRequiredNum) ? Integer.parseInt(com.jero.codegenerate.properties.CodeConfigProperties.fieldRequiredNum) : -1);
@@ -60,7 +72,7 @@ public class CodeGenerateOneToMany extends BaseCodeGenerate implements IGenerate
if (this.mainTableVo.getFieldRowNum() == null) { if (this.mainTableVo.getFieldRowNum() == null) {
this.mainTableVo.setFieldRowNum(Integer.parseInt(com.jero.codegenerate.properties.CodeConfigProperties.fieldRowNum)); this.mainTableVo.setFieldRowNum(Integer.parseInt(com.jero.codegenerate.properties.CodeConfigProperties.fieldRowNum));
} }
// put主表
hashMap.put("tableVo", this.mainTableVo); hashMap.put("tableVo", this.mainTableVo);
try { try {
@@ -78,6 +90,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().toLowerCase().equals(com.jero.codegenerate.properties.CodeConfigProperties.dbTableId.toLowerCase())) {
hashMap.put("primaryKeyPolicy", columnVo.getFieldType()); hashMap.put("primaryKeyPolicy", columnVo.getFieldType());
} }
@@ -86,6 +99,7 @@ public class CodeGenerateOneToMany extends BaseCodeGenerate implements IGenerate
iterator = this.subTables.iterator(); iterator = this.subTables.iterator();
while(iterator.hasNext()) { while(iterator.hasNext()) {
// 从表(局部变量)
SubTableVo subTableVo = (SubTableVo)iterator.next(); SubTableVo subTableVo = (SubTableVo)iterator.next();
List originalColumns; List originalColumns;
if (subTableVo.getColums() == null || subTableVo.getColums().size() == 0) { if (subTableVo.getColums() == null || subTableVo.getColums().size() == 0) {
@@ -97,7 +111,7 @@ public class CodeGenerateOneToMany extends BaseCodeGenerate implements IGenerate
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 list = new ArrayList();
String[] foreignKeys1 = foreignKeys; String[] foreignKeys1 = foreignKeys;
@@ -123,6 +137,7 @@ public class CodeGenerateOneToMany extends BaseCodeGenerate implements IGenerate
return hashMap; return hashMap;
} }
@Override
public List<String> generateCodeFile(String stylePath) throws Exception { public List<String> generateCodeFile(String stylePath) throws Exception {
String var2 = com.jero.codegenerate.properties.CodeConfigProperties.projectPath; String var2 = com.jero.codegenerate.properties.CodeConfigProperties.projectPath;
Map var3 = this.getCodeGenerateConfig(); Map var3 = this.getCodeGenerateConfig();
@@ -139,6 +154,7 @@ public class CodeGenerateOneToMany extends BaseCodeGenerate implements IGenerate
return this.list; return this.list;
} }
@Override
public List<String> generateCodeFile(String projectPath, String templatePath, String stylePath) throws Exception { public List<String> generateCodeFile(String projectPath, String templatePath, String stylePath) throws Exception {
if (projectPath != null && !"".equals(projectPath)) { if (projectPath != null && !"".equals(projectPath)) {
com.jero.codegenerate.properties.CodeConfigProperties.a(projectPath); com.jero.codegenerate.properties.CodeConfigProperties.a(projectPath);
@@ -116,6 +116,7 @@ public class MainTableVo {
this.sequenceCode = sequenceCode; this.sequenceCode = sequenceCode;
} }
@Override
public String toString() { public String toString() {
return "{\"entityPackage\":\"" + this.entityPackage + "\",\"tableName\":\"" + this.tableName + "\",\"entityName\":\"" + this.entityName + "\",\"ftlDescription\":\"" + this.ftlDescription + "\",\"primaryKeyPolicy\":\"" + this.primaryKeyPolicy + "\",\"sequenceCode\":\"" + this.sequenceCode + "\",\"ftl_mode\":\"" + this.ftl_mode + "\",\"subTables\":" + this.subTables + ",\"fieldRowNum\":\"" + this.fieldRowNum + "\",\"searchFieldNum\":\"" + this.searchFieldNum + "\",\"fieldRequiredNum\":\"" + this.fieldRequiredNum + "\"}"; return "{\"entityPackage\":\"" + this.entityPackage + "\",\"tableName\":\"" + this.tableName + "\",\"entityName\":\"" + this.entityName + "\",\"ftlDescription\":\"" + this.ftlDescription + "\",\"primaryKeyPolicy\":\"" + this.primaryKeyPolicy + "\",\"sequenceCode\":\"" + this.sequenceCode + "\",\"ftl_mode\":\"" + this.ftl_mode + "\",\"subTables\":" + this.subTables + ",\"fieldRowNum\":\"" + this.fieldRowNum + "\",\"searchFieldNum\":\"" + this.searchFieldNum + "\",\"fieldRequiredNum\":\"" + this.fieldRequiredNum + "\"}";
} }