Skip to content

Commit d740425

Browse files
author
hewei
committed
解决EnumTypeStatusPlugin和逻辑删除插件在某些情况下冲突的问题
1 parent fc8a33a commit d740425

File tree

1 file changed

+28
-22
lines changed

1 file changed

+28
-22
lines changed

src/main/java/com/itfsw/mybatis/generator/plugins/EnumTypeStatusPlugin.java

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,15 @@
1616

1717
package com.itfsw.mybatis.generator.plugins;
1818

19-
import com.itfsw.mybatis.generator.plugins.utils.BasePlugin;
20-
import com.itfsw.mybatis.generator.plugins.utils.FormatTools;
21-
import com.itfsw.mybatis.generator.plugins.utils.IntrospectedTableTools;
22-
import com.itfsw.mybatis.generator.plugins.utils.JavaElementGeneratorTools;
19+
import com.itfsw.mybatis.generator.plugins.utils.*;
2320
import org.mybatis.generator.api.CommentGenerator;
2421
import org.mybatis.generator.api.IntrospectedColumn;
2522
import org.mybatis.generator.api.IntrospectedTable;
2623
import org.mybatis.generator.api.dom.java.*;
2724
import org.mybatis.generator.internal.util.StringUtility;
2825

2926
import java.math.BigDecimal;
30-
import java.util.ArrayList;
31-
import java.util.LinkedHashMap;
32-
import java.util.List;
33-
import java.util.Map;
27+
import java.util.*;
3428
import java.util.regex.Matcher;
3529
import java.util.regex.Pattern;
3630

@@ -113,6 +107,19 @@ public void initialized(IntrospectedTable introspectedTable) {
113107
}
114108
}
115109
}
110+
111+
// 逻辑删除插件依赖该插件生成对应枚举
112+
if (PluginTools.checkDependencyPlugin(this.getContext(), LogicalDeletePlugin.class)) {
113+
// 1. 获取配置的逻辑删除列
114+
String logicalDeleteColumnStr = this.getProperties().getProperty(LogicalDeletePlugin.PRO_LOGICAL_DELETE_COLUMN);
115+
if (introspectedTable.getTableConfigurationProperty(LogicalDeletePlugin.PRO_LOGICAL_DELETE_COLUMN) != null) {
116+
logicalDeleteColumnStr = introspectedTable.getTableConfigurationProperty(LogicalDeletePlugin.PRO_LOGICAL_DELETE_COLUMN);
117+
}
118+
IntrospectedColumn logicalDeleteColumn = IntrospectedTableTools.safeGetColumn(introspectedTable, logicalDeleteColumnStr);
119+
if (logicalDeleteColumn != null) {
120+
this.enumColumns.remove(logicalDeleteColumn.getJavaProperty());
121+
}
122+
}
116123
}
117124

118125
/**
@@ -127,6 +134,19 @@ public boolean modelPrimaryKeyClassGenerated(TopLevelClass topLevelClass, Intros
127134
return super.modelPrimaryKeyClassGenerated(topLevelClass, introspectedTable);
128135
}
129136

137+
/**
138+
* Model 生成
139+
* 具体执行顺序 http://www.mybatis.org/generator/reference/pluggingIn.html
140+
* @param topLevelClass
141+
* @param introspectedTable
142+
* @return
143+
*/
144+
@Override
145+
public boolean modelBaseRecordClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
146+
this.generateModelEnum(topLevelClass, introspectedTable);
147+
return super.modelBaseRecordClassGenerated(topLevelClass, introspectedTable);
148+
}
149+
130150
/**
131151
* 生成对应enum
132152
* @param topLevelClass
@@ -142,20 +162,6 @@ private void generateModelEnum(TopLevelClass topLevelClass, IntrospectedTable in
142162
}
143163
}
144164

145-
/**
146-
* Model 生成
147-
* 具体执行顺序 http://www.mybatis.org/generator/reference/pluggingIn.html
148-
* @param topLevelClass
149-
* @param introspectedTable
150-
* @return
151-
*/
152-
@Override
153-
public boolean modelBaseRecordClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
154-
this.generateModelEnum(topLevelClass, introspectedTable);
155-
return super.modelBaseRecordClassGenerated(topLevelClass, introspectedTable);
156-
}
157-
158-
159165
public static class EnumInfo {
160166
private List<EnumItemInfo> items = new ArrayList<>();
161167
private IntrospectedColumn column;

0 commit comments

Comments
 (0)