更新生成插件

This commit is contained in:
iqudoo
2026-04-09 16:41:32 +08:00
parent 8a5ff1c44c
commit caeaad6426
3 changed files with 42 additions and 2 deletions

View File

@@ -312,6 +312,16 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
updateMethod.setAbstract(true);
repositoryInterface.addMethod(updateMethod);
// 17. updateByExampleSelective
Method updateByExampleSelectiveMethod = new Method("updateByExampleSelective");
updateByExampleSelectiveMethod.setVisibility(JavaVisibility.PUBLIC);
updateByExampleSelectiveMethod.setReturnType(new FullyQualifiedJavaType("int"));
updateByExampleSelectiveMethod.addParameter(new Parameter(new FullyQualifiedJavaType(modelClassName), "record"));
updateByExampleSelectiveMethod.addParameter(new Parameter(new FullyQualifiedJavaType(exampleClassName), "example"));
updateByExampleSelectiveMethod.addException(new FullyQualifiedJavaType("Throwable"));
updateByExampleSelectiveMethod.setAbstract(true);
repositoryInterface.addMethod(updateByExampleSelectiveMethod);
return repositoryInterface;
}
@@ -349,6 +359,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
generateFindTrashByIdMethod(implClass, modelClassName, mapperFieldName, exampleClassName);
generateInsertMethod(implClass, modelClassName, mapperFieldName, introspectedTable);
generateUpdateMethod(implClass, modelClassName, exampleClassName, mapperFieldName, introspectedTable, hasBLOBColumns);
generateUpdateByExampleSelectiveMethod(implClass, modelClassName, exampleClassName, mapperFieldName);
generateDeleteByIdMethod(implClass, modelClassName, mapperFieldName);
generateDeleteAllMethod(implClass, modelClassName, exampleClassName, mapperFieldName);
generateTrashByIdMethod(implClass, modelClassName, mapperFieldName);
@@ -637,6 +648,31 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
implClass.addMethod(method);
}
private void generateUpdateByExampleSelectiveMethod(TopLevelClass implClass, String modelClassName, String exampleClassName, String mapperFieldName) {
Method method = new Method("updateByExampleSelective");
method.addAnnotation("@Override");
method.setVisibility(JavaVisibility.PUBLIC);
method.setReturnType(new FullyQualifiedJavaType("int"));
method.addParameter(new Parameter(new FullyQualifiedJavaType(modelClassName), "record"));
method.addParameter(new Parameter(new FullyQualifiedJavaType(exampleClassName), "example"));
method.addException(new FullyQualifiedJavaType("Throwable"));
// 方法体
method.addBodyLine("for (" + exampleClassName + ".Criteria criteria : example.getOredCriteria()) {");
method.addBodyLine("criteria.andIsDeleteEqualTo(0).andIsHiddenEqualTo(0);");
method.addBodyLine("}");
method.addBodyLine("record.setUpdateTime(new Date());");
method.addBodyLine("// It is not supported to directly modify the following columns");
method.addBodyLine("record.setIsHidden(null);");
method.addBodyLine("record.setIsDelete(null);");
method.addBodyLine("record.setDeleteToken(null);");
method.addBodyLine("record.setDataVersion(null);");
method.addBodyLine("record.setCreateTime(null);");
method.addBodyLine("return " + mapperFieldName + ".updateByExampleSelective(record, example);");
implClass.addMethod(method);
}
private void generateDeleteByIdMethod(TopLevelClass implClass, String modelClassName, String mapperFieldName) {
Method method = new Method("deleteById");
method.addAnnotation("@Override");