@@ -93,11 +93,11 @@ public class LogicalDeletePlugin extends BasePlugin {
9393 /**
9494 * 逻辑删除常量
9595 */
96- private String logicalDeleteConstName ;
96+ private String logicalDeleteConstName = DEFAULT_LOGICAL_DELETE_NAME ;
9797 /**
9898 * 逻辑删除常量(未删除)
9999 */
100- private String logicalUnDeleteConstName ;
100+ private String logicalUnDeleteConstName = DEFAULT_LOGICAL_UN_DELETE_NAME ;
101101 /**
102102 * 是否支持常量类型
103103 */
@@ -128,7 +128,18 @@ public void initialized(IntrospectedTable introspectedTable) {
128128 warnings .add ("itfsw(逻辑删除插件):" + introspectedTable .getFullyQualifiedTable () + "没有找到您配置的逻辑删除列(" + introspectedTable .getTableConfigurationProperty (PRO_LOGICAL_DELETE_COLUMN ) + ")!" );
129129 }
130130
131- // 2. 优先借助 EnumTypeStatusPlugin 插件,去注解里面解析枚举
131+ // 2. 获取逻辑删除常量值
132+ this .enableLogicalDeleteConst = properties .getProperty (PRO_ENABLE_LOGICAL_DELETE_CONST ) == null ? true : StringUtility .isTrue (properties .getProperty (PRO_ENABLE_LOGICAL_DELETE_CONST ));
133+ if (this .enableLogicalDeleteConst ) {
134+ if (properties .getProperty (PRO_LOGICAL_DELETE_CONST_NAME ) != null ) {
135+ this .logicalDeleteConstName = properties .getProperty (PRO_LOGICAL_DELETE_CONST_NAME ).toUpperCase ();
136+ }
137+ if (properties .getProperty (PRO_LOGICAL_UN_DELETE_CONST_NAME ) != null ) {
138+ this .logicalUnDeleteConstName = properties .getProperty (PRO_LOGICAL_UN_DELETE_CONST_NAME ).toUpperCase ();
139+ }
140+ }
141+
142+ // 3. 优先借助 EnumTypeStatusPlugin 插件,去注解里面解析枚举
132143 if (this .logicalDeleteColumn != null ) {
133144 EnumTypeStatusPlugin .EnumInfo enumInfo = null ;
134145 try {
@@ -146,7 +157,9 @@ public void initialized(IntrospectedTable introspectedTable) {
146157 // 这个是注释里配置了枚举
147158 if (enumInfo .hasItems () && enumInfo .getItems ().size () >= 2 ) {
148159 this .logicalUnDeleteValue = enumInfo .getItems ().get (0 ).getOriginalValue ();
160+ this .logicalUnDeleteConstName = enumInfo .getItems ().get (0 ).getName ();
149161 this .logicalDeleteValue = enumInfo .getItems ().get (1 ).getOriginalValue ();
162+ this .logicalDeleteConstName = enumInfo .getItems ().get (1 ).getName ();
150163 this .logicalDeleteEnum = enumInfo .generateEnum (commentGenerator , introspectedTable );
151164 } else {
152165 // 没有在注释里配置读取xml中配置的
@@ -158,35 +171,28 @@ public void initialized(IntrospectedTable introspectedTable) {
158171 if (introspectedTable .getTableConfigurationProperty (PRO_LOGICAL_UN_DELETE_VALUE ) != null ) {
159172 this .logicalUnDeleteValue = introspectedTable .getTableConfigurationProperty (PRO_LOGICAL_UN_DELETE_VALUE );
160173 }
161- // 3 . 判断逻辑删除值是否配置了
174+ // 4 . 判断逻辑删除值是否配置了
162175 if (this .logicalDeleteValue == null || this .logicalUnDeleteValue == null ) {
163176 this .logicalDeleteColumn = null ;
164177 warnings .add ("itfsw(逻辑删除插件):" + introspectedTable .getFullyQualifiedTable () + "没有找到您配置的逻辑删除值,请全局或者局部配置logicalDeleteValue和logicalUnDeleteValue值!" );
165178 } else {
166- enumInfo .addItem (DEFAULT_LOGICAL_UN_DELETE_NAME , "未删除" , this .logicalUnDeleteValue );
167- enumInfo .addItem (DEFAULT_LOGICAL_DELETE_NAME , "已删除" , this .logicalDeleteValue );
179+ enumInfo .addItem (this . logicalUnDeleteConstName , "未删除" , this .logicalUnDeleteValue );
180+ enumInfo .addItem (this . logicalDeleteConstName , "已删除" , this .logicalDeleteValue );
168181 this .logicalDeleteEnum = enumInfo .generateEnum (commentGenerator , introspectedTable );
169182 }
170183 }
171184 }
172185 }
173186 }
174187
175- // 4 . 防止增强的selectByPrimaryKey中逻辑删除键冲突
188+ // 5 . 防止增强的selectByPrimaryKey中逻辑删除键冲突
176189 if (this .logicalDeleteColumn != null ) {
177190 Field logicalDeleteField = JavaBeansUtil .getJavaBeansField (this .logicalDeleteColumn , context , introspectedTable );
178191 if (logicalDeleteField .getName ().equals (PARAMETER_LOGICAL_DELETED )) {
179192 this .logicalDeleteColumn = null ;
180193 warnings .add ("itfsw(逻辑删除插件):" + introspectedTable .getFullyQualifiedTable () + "配置的逻辑删除列和插件保留关键字(" + PARAMETER_LOGICAL_DELETED + ")冲突!" );
181194 }
182195 }
183-
184- // 5. 获取逻辑删除常量值
185- this .enableLogicalDeleteConst = properties .getProperty (PRO_ENABLE_LOGICAL_DELETE_CONST ) == null ? true : StringUtility .isTrue (properties .getProperty (PRO_ENABLE_LOGICAL_DELETE_CONST ));
186- if (this .enableLogicalDeleteConst ) {
187- this .logicalDeleteConstName = properties .getProperty (PRO_LOGICAL_DELETE_CONST_NAME ) != null ? properties .getProperty (PRO_LOGICAL_DELETE_CONST_NAME ).toUpperCase () : DEFAULT_LOGICAL_DELETE_NAME ;
188- this .logicalUnDeleteConstName = properties .getProperty (PRO_LOGICAL_UN_DELETE_CONST_NAME ) != null ? properties .getProperty (PRO_LOGICAL_UN_DELETE_CONST_NAME ).toUpperCase () : DEFAULT_LOGICAL_UN_DELETE_NAME ;
189- }
190196 }
191197
192198 /**
@@ -460,14 +466,12 @@ public boolean modelFieldGenerated(Field field, TopLevelClass topLevelClass, Int
460466 this .logicalDeleteColumn .getFullyQualifiedJavaType (),
461467 this .getEnumConstantValue (false )
462468 );
463- logicalUnDeleteConstField .addAnnotation ("@Deprecated" );
464469 commentGenerator .addFieldComment (logicalUnDeleteConstField , introspectedTable );
465470 Field logicalDeleteConstField = JavaElementGeneratorTools .generateStaticFinalField (
466471 this .logicalDeleteConstName ,
467472 this .logicalDeleteColumn .getFullyQualifiedJavaType (),
468473 this .getEnumConstantValue (true )
469474 );
470- logicalDeleteConstField .addAnnotation ("@Deprecated" );
471475 commentGenerator .addFieldComment (logicalDeleteConstField , introspectedTable );
472476
473477 // 常量放在字段开头
0 commit comments