-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add prometheus-trace-etl release * feat: add gitlab log release jdk21 * feat: update athena * feat: update check code file path * feat: add code generator and mybatis generator * feat: add mybtais generator
- Loading branch information
Showing
9 changed files
with
231 additions
and
8 deletions.
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
jcommon/codegen/src/main/java/com/xiaomi/youpin/codegen/M78DoceanMongoGen.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package com.xiaomi.youpin.codegen; | ||
|
||
import com.xiaomi.youpin.codegen.bo.Dependency; | ||
import com.xiaomi.youpin.codegen.common.FileUtils; | ||
import com.xiaomi.youpin.codegen.generator.FileGenerator; | ||
import com.xiaomi.youpin.infra.rpc.Result; | ||
import com.xiaomi.youpin.infra.rpc.errors.GeneralCodes; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import java.io.File; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
@Slf4j | ||
public class M78DoceanMongoGen { | ||
// private static final String DEFAULT_MODEL = "mi-function"; | ||
private final String tmpPath = "m78-docean-mongo"; | ||
// private static final String handlerDir = "handler"; | ||
// private static final String srcPath = "/src/main/java/"; | ||
// private static final String testPath = "/src/test/java/"; | ||
|
||
public Result<String> generateAndZip(String projectPath, String projectName, String groupId, String packageName, String author, String versionId, HashMap<String, ArrayList<Dependency>> dep) { | ||
String packagePath = packageName.replaceAll("\\.", "/"); | ||
String camelName = this.adapterProjectNameToCamelName(projectName); | ||
Map<String, Object> m = new HashMap<>(); | ||
m.put("group", groupId); | ||
m.put("artifactId", projectName); | ||
m.put("version", versionId); | ||
m.put("author", author); | ||
m.put("camelName", camelName); | ||
m.put("package", packageName); | ||
try { | ||
// FileUtils.createDirectories(FileUtils.join(projectPath, projectName, projectName + "-common", "src", "test", "java")); | ||
FileUtils.createDirectories(FileUtils.join(projectPath, projectName, projectName + "-server", "src", "main", "java", packagePath, "bootstrap")); | ||
FileUtils.createDirectories(FileUtils.join(projectPath, projectName, projectName + "-server", "src", "test", "java")); | ||
FileUtils.createDirectories(FileUtils.join(projectPath, projectName, projectName + "-service", "src", "test", "java")); | ||
// FileUtils.createDirectories(FileUtils.join(projectPath, projectName, projectName + "-service", "src", "main", "resources")); | ||
FileUtils.createDirectories(FileUtils.join(projectPath, projectName, projectName + "-api", "src", "main", "java", packagePath, "api", "bo")); | ||
FileUtils.createDirectories(FileUtils.join(projectPath, projectName, projectName + "-api", "src", "main", "java", packagePath, "api", "vo")); | ||
FileUtils.createDirectories(FileUtils.join(projectPath, projectName, projectName + "-server", "src", "main", "java", packagePath, "controller")); | ||
FileUtils.createDirectories(FileUtils.join(projectPath, projectName, projectName + "-common", "src", "main", "java", packagePath, "common")); | ||
FileUtils.createDirectories(FileUtils.join(projectPath, projectName, projectName + "-server", "src", "main", "resources", "config")); | ||
FileUtils.createDirectories(FileUtils.join(projectPath, projectName, projectName + "-service", "src", "main", "java", packagePath, "service")); | ||
new FileGenerator(projectPath, projectName, FileUtils.join(projectName + "-service", "src", "main", "java", packagePath, "service", "MongoService.java"), FileUtils.join(tmpPath, "mongoservice.tml")).generator(m); | ||
new FileGenerator(projectPath, projectName, FileUtils.join(projectName + "-api", "src", "main", "java", packagePath, "api", "bo", "MongoBo.java"), FileUtils.join(tmpPath, "mongobo.tml")).generator(m); | ||
new FileGenerator(projectPath, projectName, FileUtils.join(projectName + "-api", "src", "main", "java", packagePath, "api", "bo", "Page.java"), FileUtils.join(tmpPath, "page.tml")).generator(m); | ||
new FileGenerator(projectPath, projectName, FileUtils.join(projectName + "-service", "pom.xml"), FileUtils.join(tmpPath, "service-pom.tml")).generator(m); | ||
new FileGenerator(projectPath, projectName, FileUtils.join(projectName + "-service", "src", "main", "java", packagePath, "service", "ServiceImpl1.java"), FileUtils.join(tmpPath, "serviceimpl1.tml")).generator(m); | ||
new FileGenerator(projectPath, projectName, FileUtils.join(projectName + "-server", "src", "main", "resources", "config", "staging.properties"), FileUtils.join(tmpPath, "staging.tml")).generator(m); | ||
new FileGenerator(projectPath, projectName, FileUtils.join(projectName + "-server", "src", "main", "resources", "config.properties"), FileUtils.join(tmpPath, "config.tml")).generator(m); | ||
new FileGenerator(projectPath, projectName, FileUtils.join(projectName + "-server", "src", "main", "resources", "logback.xml"), FileUtils.join(tmpPath, "logback.tml")).generator(m); | ||
new FileGenerator(projectPath, projectName, FileUtils.join("pom.xml"), FileUtils.join(tmpPath, "pom.tml")).generator(m); | ||
new FileGenerator(projectPath, projectName, FileUtils.join(projectName + "-common", "src", "main", "java", packagePath, "common", "Result.java"), FileUtils.join(tmpPath, "result.tml")).generator(m); | ||
new FileGenerator(projectPath, projectName, FileUtils.join(projectName + "-server", "src", "main", "java", packagePath, "bootstrap", "Bootstrap.java"), FileUtils.join(tmpPath, "bootstrap.tml")).generator(m); | ||
new FileGenerator(projectPath, projectName, FileUtils.join(projectName + "-server", "src", "main", "java", packagePath, "controller", "MongodbController.java"), FileUtils.join(tmpPath, "mongodbcontroller.tml")).generator(m); | ||
new FileGenerator(projectPath, projectName, FileUtils.join(projectName + "-server", "pom.xml"), FileUtils.join(tmpPath, "server-pom.tml")).generator(m); | ||
new FileGenerator(projectPath, projectName, FileUtils.join(projectName + "-server", "src", "main", "resources", "config", "dev.properties"), FileUtils.join(tmpPath, "dev.tml")).generator(m); | ||
new FileGenerator(projectPath, projectName, FileUtils.join(projectName + "-server", "src", "main", "resources", "config", "online.properties"), FileUtils.join(tmpPath, "online.tml")).generator(m); | ||
new FileGenerator(projectPath, projectName, FileUtils.join(projectName + "-api", "pom.xml"), FileUtils.join(tmpPath, "api-pom.tml")).generator(m); | ||
new FileGenerator(projectPath, projectName, FileUtils.join(projectName + "-api", "src", "main", "java", packagePath, "api", "IService.java"), FileUtils.join(tmpPath, "iservice.tml")).generator(m); | ||
new FileGenerator(projectPath, projectName, FileUtils.join(projectName + "-common", "pom.xml"), FileUtils.join(tmpPath, "common-pom.tml")).generator(m); | ||
|
||
new FileGenerator(projectPath, projectName, FileUtils.join(".gitignore"), "springboot_gitignore.tml").generator(m); | ||
FileUtils.compress(projectPath + File.separator + projectName, projectPath + File.separator + projectName + ".zip"); | ||
} catch (Exception e) { | ||
log.error("SpringBootProGen failed ", e); | ||
return Result.fail(GeneralCodes.InternalError, "InternalError"); | ||
} | ||
|
||
return Result.success(projectPath + File.separator + projectName + ".zip"); | ||
} | ||
|
||
private String adapterProjectNameToCamelName(String name) { | ||
if (StringUtils.isEmpty(name)) { | ||
return ""; | ||
} | ||
try { | ||
String[] strings = name.split("-"); | ||
if (strings.length > 1) { | ||
String res = ""; | ||
for (int i = 0; i < strings.length; i++) { | ||
if (!StringUtils.isEmpty(strings[i])) { | ||
res = res + StringUtils.capitalize(strings[i]); | ||
} | ||
} | ||
return res; | ||
} | ||
} catch (Exception e) { | ||
return StringUtils.capitalize(name); | ||
} | ||
return StringUtils.capitalize(name); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
jcommon/codegen/src/main/java/run/mone/ai/codegen/bo/MybatisGeneratorResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package run.mone.ai.codegen.bo; | ||
|
||
import lombok.Data; | ||
import lombok.ToString; | ||
|
||
|
||
@Data | ||
@ToString | ||
public class MybatisGeneratorResult { | ||
/** | ||
* 生成的Java Entity类列表 | ||
*/ | ||
private String entity; | ||
|
||
/** | ||
* 生成的Java mapper类列表 | ||
*/ | ||
private String mapper; | ||
} |
10 changes: 10 additions & 0 deletions
10
jcommon/codegen/src/main/java/run/mone/ai/codegen/holder/MybatisGeneratorHolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package run.mone.ai.codegen.holder; | ||
|
||
import lombok.Data; | ||
|
||
public class MybatisGeneratorHolder { | ||
|
||
public static String entity; | ||
public static String mapper; | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
jcommon/codegen/src/main/java/run/mone/ai/codegen/plugin/ClassNamePlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package run.mone.ai.codegen.plugin; | ||
|
||
import org.mybatis.generator.api.IntrospectedTable; | ||
import org.mybatis.generator.api.PluginAdapter; | ||
import org.mybatis.generator.api.dom.java.TopLevelClass; | ||
import org.mybatis.generator.api.dom.java.Interface; | ||
import org.mybatis.generator.config.Context; | ||
import run.mone.ai.codegen.holder.MybatisGeneratorHolder; | ||
import org.mybatis.generator.api.JavaFormatter; | ||
|
||
import java.util.List; | ||
|
||
public class ClassNamePlugin extends PluginAdapter { | ||
|
||
private JavaFormatter javaFormatter; | ||
|
||
@Override | ||
public void setContext(Context context) { | ||
super.setContext(context); | ||
this.javaFormatter = context.getJavaFormatter(); | ||
} | ||
|
||
@Override | ||
public boolean validate(List<String> warnings) { | ||
// 这里可以添加一些验证逻辑 | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean modelBaseRecordClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { | ||
String formattedContent = javaFormatter.getFormattedContent(topLevelClass); | ||
MybatisGeneratorHolder.entity = formattedContent; | ||
return true; | ||
} | ||
|
||
|
||
@Override | ||
public boolean clientGenerated(Interface interfaze, IntrospectedTable introspectedTable) { | ||
String formattedContent = javaFormatter.getFormattedContent(interfaze); | ||
MybatisGeneratorHolder.mapper = formattedContent; | ||
return true; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters