This commit is contained in:
iqudoo
2026-04-17 15:49:30 +08:00
parent b6e4ab65e7
commit 908d7333ab
4 changed files with 92 additions and 121 deletions

View File

@@ -56,48 +56,46 @@ public class TapeMybatisGeneratorPlugin extends PluginAdapter {
} }
private int getIgnorePageSize(IntrospectedTable introspectedTable) { private int getIgnorePageSize(IntrospectedTable introspectedTable) {
try { return getTableInt(introspectedTable, "ignorePageSize", ignorePageSize);
TableConfiguration tableConfiguration = introspectedTable.getTableConfiguration();
String getIgnorePageSize = tableConfiguration.getProperty("ignorePageSize");
if (getIgnorePageSize != null && !getIgnorePageSize.isEmpty()) {
int value = Integer.parseInt(getIgnorePageSize);
if (value > 0) {
return value;
}
}
} catch (Throwable ignored) {
}
return ignorePageSize;
} }
public int getMaxPageSize(IntrospectedTable introspectedTable) { public int getMaxPageSize(IntrospectedTable introspectedTable) {
try { return getTableInt(introspectedTable, "maxPageSize", maxPageSize);
TableConfiguration tableConfiguration = introspectedTable.getTableConfiguration();
String getMaxPageSize = tableConfiguration.getProperty("maxPageSize");
if (getMaxPageSize != null && !getMaxPageSize.isEmpty()) {
int value = Integer.parseInt(getMaxPageSize);
if (value > 0) {
return value;
}
}
} catch (Throwable ignored) {
}
return maxPageSize;
} }
public int getStartPageNum(IntrospectedTable introspectedTable) { public int getStartPageNum(IntrospectedTable introspectedTable) {
return getTableInt(introspectedTable, "startPageNum", startPageNum);
}
// ====================== 统一 Table 属性获取(你全类都能用) ======================
private String getTableProperty(IntrospectedTable introspectedTable, String propName, String defaultValue) {
try { try {
TableConfiguration tableConfiguration = introspectedTable.getTableConfiguration(); TableConfiguration tc = introspectedTable.getTableConfiguration();
String getStartPageNum = tableConfiguration.getProperty("startPageNum"); String v = tc.getProperty(propName);
if (getStartPageNum != null && !getStartPageNum.isEmpty()) { if (StringUtility.stringHasValue(v)) {
int value = Integer.parseInt(getStartPageNum); return v.trim();
if (value > 0) { }
return value; } catch (Exception ignored) {
}
return defaultValue;
}
private boolean getTableBool(IntrospectedTable introspectedTable, String propName, boolean defaultValue) {
String v = getTableProperty(introspectedTable, propName, String.valueOf(defaultValue));
try {
return Boolean.parseBoolean(v);
} catch (Exception e) {
return defaultValue;
} }
} }
} catch (Throwable ignored) {
private int getTableInt(IntrospectedTable introspectedTable, String propName, int defaultValue) {
String v = getTableProperty(introspectedTable, propName, String.valueOf(defaultValue));
try {
return Integer.parseInt(v);
} catch (Exception e) {
return defaultValue;
} }
return startPageNum;
} }
@SuppressWarnings("DuplicatedCode") @SuppressWarnings("DuplicatedCode")

View File

@@ -52,9 +52,6 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
targetProject = stringConfig("targetProject", targetProject); targetProject = stringConfig("targetProject", targetProject);
slowQueryLoggerTime = stringConfig("slowQueryLoggerTime", slowQueryLoggerTime); slowQueryLoggerTime = stringConfig("slowQueryLoggerTime", slowQueryLoggerTime);
slowQueryLoggerLevel = stringConfig("slowQueryLoggerLevel", slowQueryLoggerLevel); slowQueryLoggerLevel = stringConfig("slowQueryLoggerLevel", slowQueryLoggerLevel);
if (!UtilTools.inArray(new String[]{"error", "warn", "debug", "info"}, slowQueryLoggerLevel)) {
slowQueryLoggerLevel = "error";
}
guidGeneratorClass = stringConfig("guidGeneratorClass", guidGeneratorClass); guidGeneratorClass = stringConfig("guidGeneratorClass", guidGeneratorClass);
guidGeneratorCode = stringConfig("guidGeneratorCode", guidGeneratorCode); guidGeneratorCode = stringConfig("guidGeneratorCode", guidGeneratorCode);
facadeRepositoryPackage = stringConfig("facadeRepositoryPackage", facadeRepositoryPackage); facadeRepositoryPackage = stringConfig("facadeRepositoryPackage", facadeRepositoryPackage);
@@ -67,70 +64,6 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
modelPackage = stringConfig("modelPackage", modelPackage); modelPackage = stringConfig("modelPackage", modelPackage);
} }
private boolean isChangeLogEnable(IntrospectedTable introspectedTable) {
String tableChangeLogEnable = changeLogEnable;
try {
TableConfiguration tableConfiguration = introspectedTable.getTableConfiguration();
String getChangeLogEnable = tableConfiguration.getProperty("changeLogEnable");
if (getChangeLogEnable != null && !getChangeLogEnable.isEmpty()) {
tableChangeLogEnable = getChangeLogEnable;
}
} catch (Throwable ignored) {
}
try {
boolean b = Boolean.parseBoolean(tableChangeLogEnable);
if (b) {
return true;
}
} catch (Throwable ignored) {
}
return false;
}
private boolean isOptimisticLockEnable(IntrospectedTable introspectedTable) {
String tableOptimisticLockEnable = optimisticLockEnable;
try {
TableConfiguration tableConfiguration = introspectedTable.getTableConfiguration();
String getOptimisticLockEnable = tableConfiguration.getProperty("optimisticLockEnable");
if (getOptimisticLockEnable != null && !getOptimisticLockEnable.isEmpty()) {
tableOptimisticLockEnable = getOptimisticLockEnable;
}
} catch (Throwable ignored) {
}
try {
boolean b = Boolean.parseBoolean(tableOptimisticLockEnable);
if (b) {
return true;
}
} catch (Throwable ignored) {
}
return false;
}
public String getSlowQueryLoggerLevel(IntrospectedTable introspectedTable) {
try {
TableConfiguration tableConfiguration = introspectedTable.getTableConfiguration();
String tableSlowQueryLoggerLevel = tableConfiguration.getProperty("slowQueryLoggerLevel");
if (tableSlowQueryLoggerLevel != null && !tableSlowQueryLoggerLevel.isEmpty()) {
return tableSlowQueryLoggerLevel;
}
} catch (Throwable ignored) {
}
return slowQueryLoggerLevel;
}
public String getSlowQueryLoggerTime(IntrospectedTable introspectedTable) {
try {
TableConfiguration tableConfiguration = introspectedTable.getTableConfiguration();
String tableSlowQueryLoggerTime = tableConfiguration.getProperty("slowQueryLoggerTime");
if (tableSlowQueryLoggerTime != null && !tableSlowQueryLoggerTime.isEmpty()) {
return tableSlowQueryLoggerTime;
}
} catch (Throwable ignored) {
}
return slowQueryLoggerTime;
}
private String stringConfig(String key, String defaultValue) { private String stringConfig(String key, String defaultValue) {
String v = properties.getProperty(key); String v = properties.getProperty(key);
if (StringUtility.stringHasValue(v)) { if (StringUtility.stringHasValue(v)) {
@@ -145,6 +78,48 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
return defaultValue; return defaultValue;
} }
private boolean isChangeLogEnable(IntrospectedTable introspectedTable) {
return getTableBool(introspectedTable, "changeLogEnable", Boolean.parseBoolean(changeLogEnable));
}
private boolean isOptimisticLockEnable(IntrospectedTable introspectedTable) {
return getTableBool(introspectedTable, "optimisticLockEnable", Boolean.parseBoolean(optimisticLockEnable));
}
private String getSlowQueryLoggerLevel(IntrospectedTable introspectedTable) {
String level = getTableProperty(introspectedTable, "slowQueryLoggerLevel", slowQueryLoggerLevel);
if (!UtilTools.inArray(new String[]{"error", "warn", "debug", "info"}, level)) {
return "error";
}
return level;
}
private String getSlowQueryLoggerTime(IntrospectedTable introspectedTable) {
return getTableProperty(introspectedTable, "slowQueryLoggerTime", slowQueryLoggerTime);
}
// ====================== 统一 Table 属性获取(你全类都能用) ======================
private String getTableProperty(IntrospectedTable introspectedTable, String propName, String defaultValue) {
try {
TableConfiguration tc = introspectedTable.getTableConfiguration();
String v = tc.getProperty(propName);
if (StringUtility.stringHasValue(v)) {
return v.trim();
}
} catch (Exception ignored) {
}
return defaultValue;
}
private boolean getTableBool(IntrospectedTable introspectedTable, String propName, boolean defaultValue) {
String v = getTableProperty(introspectedTable, propName, String.valueOf(defaultValue));
try {
return Boolean.parseBoolean(v);
} catch (Exception e) {
return defaultValue;
}
}
/** /**
* 核心方法:视图表过滤 + 生成完整Repository代码 * 核心方法:视图表过滤 + 生成完整Repository代码
*/ */

View File

@@ -49,9 +49,6 @@ public class TapeRepoviewGeneratorPlugin extends PluginAdapter {
targetProject = stringConfig("targetProject", targetProject); targetProject = stringConfig("targetProject", targetProject);
slowQueryLoggerTime = stringConfig("slowQueryLoggerTime", slowQueryLoggerTime); slowQueryLoggerTime = stringConfig("slowQueryLoggerTime", slowQueryLoggerTime);
slowQueryLoggerLevel = stringConfig("slowQueryLoggerLevel", slowQueryLoggerLevel); slowQueryLoggerLevel = stringConfig("slowQueryLoggerLevel", slowQueryLoggerLevel);
if (!UtilTools.inArray(new String[]{"error", "warn", "debug", "info"}, slowQueryLoggerLevel)) {
slowQueryLoggerLevel = "error";
}
facadeViewRepositoryPackage = stringConfig("facadeViewRepositoryPackage", facadeViewRepositoryPackage); facadeViewRepositoryPackage = stringConfig("facadeViewRepositoryPackage", facadeViewRepositoryPackage);
domainViewRepositoryPackage = stringConfig("facadeViewRepositoryPackage", domainViewRepositoryPackage); domainViewRepositoryPackage = stringConfig("facadeViewRepositoryPackage", domainViewRepositoryPackage);
mapperPackage = stringConfig("mapperPackage", mapperPackage); mapperPackage = stringConfig("mapperPackage", mapperPackage);
@@ -72,28 +69,29 @@ public class TapeRepoviewGeneratorPlugin extends PluginAdapter {
return defaultValue; return defaultValue;
} }
public String getSlowQueryLoggerLevel(IntrospectedTable introspectedTable) { private String getSlowQueryLoggerLevel(IntrospectedTable introspectedTable) {
try { String level = getTableProperty(introspectedTable, "slowQueryLoggerLevel", slowQueryLoggerLevel);
TableConfiguration tableConfiguration = introspectedTable.getTableConfiguration(); if (!UtilTools.inArray(new String[]{"error", "warn", "debug", "info"}, level)) {
String tableSlowQueryLoggerLevel = tableConfiguration.getProperty("slowQueryLoggerLevel"); return "error";
if (tableSlowQueryLoggerLevel != null && !tableSlowQueryLoggerLevel.isEmpty()) {
return tableSlowQueryLoggerLevel;
} }
} catch (Throwable ignored) { return level;
}
return slowQueryLoggerLevel;
} }
public String getSlowQueryLoggerTime(IntrospectedTable introspectedTable) { private String getSlowQueryLoggerTime(IntrospectedTable introspectedTable) {
return getTableProperty(introspectedTable, "slowQueryLoggerTime", slowQueryLoggerTime);
}
// ====================== 统一 Table 属性获取(你全类都能用) ======================
private String getTableProperty(IntrospectedTable introspectedTable, String propName, String defaultValue) {
try { try {
TableConfiguration tableConfiguration = introspectedTable.getTableConfiguration(); TableConfiguration tc = introspectedTable.getTableConfiguration();
String tableSlowQueryLoggerTime = tableConfiguration.getProperty("slowQueryLoggerTime"); String v = tc.getProperty(propName);
if (tableSlowQueryLoggerTime != null && !tableSlowQueryLoggerTime.isEmpty()) { if (StringUtility.stringHasValue(v)) {
return tableSlowQueryLoggerTime; return v.trim();
} }
} catch (Throwable ignored) { } catch (Exception ignored) {
} }
return slowQueryLoggerTime; return defaultValue;
} }
/** /**
@@ -244,7 +242,7 @@ public class TapeRepoviewGeneratorPlugin extends PluginAdapter {
generateFindOneMethod(implClass, modelClassName, exampleClassName); generateFindOneMethod(implClass, modelClassName, exampleClassName);
generateGetListMethod(implClass, introspectedTable, modelClassName, exampleClassName, mapperFieldName, hasBLOBColumns); generateGetListMethod(implClass, introspectedTable, modelClassName, exampleClassName, mapperFieldName, hasBLOBColumns);
generateCountMethod(implClass, introspectedTable, modelClassName, exampleClassName, mapperFieldName); generateCountMethod(implClass, introspectedTable, modelClassName, exampleClassName, mapperFieldName);
generateCountWithPageMethod(implClass, modelClassName, exampleClassName, mapperFieldName); generateCountWithPageMethod(implClass, exampleClassName);
return implClass; return implClass;
} }
@@ -374,7 +372,7 @@ public class TapeRepoviewGeneratorPlugin extends PluginAdapter {
/** /**
* 生成count方法 * 生成count方法
*/ */
private void generateCountWithPageMethod(TopLevelClass implClass, String modelClassName, String exampleClassName, String mapperFieldName) { private void generateCountWithPageMethod(TopLevelClass implClass, String exampleClassName) {
Method method = new Method("countWithPage"); Method method = new Method("countWithPage");
method.addAnnotation("@Override"); method.addAnnotation("@Override");
method.setVisibility(JavaVisibility.PUBLIC); method.setVisibility(JavaVisibility.PUBLIC);