commit 9f1eddccb97766880a05deea77b0e81190fbdc6a Author: NiuZiYuan Date: Thu Apr 17 09:28:25 2025 +0800 dev diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..35410ca --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# 默认忽略的文件 +/shelf/ +/workspace.xml +# 基于编辑器的 HTTP 客户端请求 +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..82dbec8 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..e272ed2 --- /dev/null +++ b/pom.xml @@ -0,0 +1,81 @@ + + + 4.0.0 + + com.syjiaer.pharmacy + dbhelper + 1.0-SNAPSHOT + + + 17 + 17 + UTF-8 + + + + org.yaml + snakeyaml + 1.30 + + + org.postgresql + postgresql + 42.7.5 + + + com.baomidou + mybatis-plus-generator + 3.5.10.1 + + + org.slf4j + slf4j-api + 1.7.36 + + + org.slf4j + slf4j-simple + 1.7.36 + + + com.baomidou + mybatis-plus + 3.5.10.1 + + + org.freemarker + freemarker + 2.3.23 + + + + + + org.apache.maven.plugins + maven-assembly-plugin + 3.3.0 + + + jar-with-dependencies + + + + com.syjiaer.clinic.dbhelper.Main + + + + + + make-assembly + package + + single + + + + + + + \ No newline at end of file diff --git a/src/main/java/com/syjiaer/clinic/dbhelper/Main.java b/src/main/java/com/syjiaer/clinic/dbhelper/Main.java new file mode 100644 index 0000000..6c5f652 --- /dev/null +++ b/src/main/java/com/syjiaer/clinic/dbhelper/Main.java @@ -0,0 +1,77 @@ +package com.syjiaer.clinic.dbhelper; + +import com.baomidou.mybatisplus.generator.FastAutoGenerator; +import com.baomidou.mybatisplus.generator.config.OutputFile; +import com.baomidou.mybatisplus.generator.config.rules.DbColumnType; +import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine; +import org.yaml.snakeyaml.Yaml; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.sql.Types; +import java.util.Collections; +import java.util.Map; +//TIP 要运行代码,请按 或 +// 点击装订区域中的 图标。 +public class Main { + public static void main(String[] args) { + //TIP 当文本光标位于高亮显示的文本处时按 + + + if (args.length != 1) { + System.out.println("参数个数不正确"); + return; + } + String base_path = System.getProperty("user.dir"); + String application_path = base_path + "/src/main/resources/application.yml"; + Yaml yaml = new Yaml(); + Map yam_map = null; + try (InputStream in = Files.newInputStream(Paths.get(application_path))) { + yam_map = yaml.load(in); + } catch (IOException e) { + System.out.println("地址异常"); + return; + } + Map map1 = (Map) yam_map.get("spring"); + Map master_map = (Map) map1.get("datasource"); + String table = args[0]; + String model_name = table.split("_")[0]; + String url = master_map.get("url"); + String username = master_map.get("username"); + String password = String.valueOf(master_map.get("password")); + String path = base_path + "/src/main/java"; + FastAutoGenerator.create(url, username, password) + .globalConfig(builder -> { + builder.author("NiuZiYuan") // 设置作者 + .disableOpenDir() // 禁止打开输出目录 + .enableSwagger() // 开启 swagger 模式 + .outputDir(path); // 指定输出目录 + }) + + .packageConfig(builder -> + builder.parent("com.syjiaer.clinic.server.modules").moduleName(model_name).pathInfo(Collections.singletonMap(OutputFile.xml, base_path + "/src/main/resources/xml")) + ) + .dataSourceConfig(builder -> + builder.typeConvertHandler((globalConfig, typeRegistry, metaInfo) -> { + int typeCode = metaInfo.getJdbcType().TYPE_CODE; + if (typeCode == Types.NUMERIC) { + return DbColumnType.BIG_DECIMAL; + } + return typeRegistry.getColumnType(metaInfo); + }) + ) + .strategyConfig(builder -> + builder.addInclude(table) + .entityBuilder().enableLombok().enableFileOverride().enableChainModel().fieldUseJavaDoc(false) + + .controllerBuilder().disable() + .serviceBuilder().disable() + //.columnNaming(NamingStrategy.no_change) + //.enableTableFieldAnnotation() // 设置需要生成的表名 + ) + .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板,默认的是Velocity引擎模板 + .execute(); + } +} \ No newline at end of file