Browse Source

代码提交

jingyuanchao 2 years ago
parent
commit
dcfc1acc54

+ 121 - 0
soc-modules/soc-modules-gen/src/main/java/com/xunmei/gen/util/CodeGenerators.java

@@ -0,0 +1,121 @@
+/*
+package com.xunmei.gen.util;
+
+
+import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException;
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
+import com.baomidou.mybatisplus.generator.AutoGenerator;
+import com.baomidou.mybatisplus.generator.InjectionConfig;
+import com.baomidou.mybatisplus.generator.config.*;
+import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Scanner;
+
+public class CodeGenerators {
+
+    */
+/**
+     * 读取控制填的内容
+     * @param tip
+     * @return
+     *//*
+
+    public static String scanner(String tip) {
+        Scanner scanner = new Scanner(System.in);
+        System.out.println("请输入" + tip + ":");
+        if (scanner.hasNext()) {
+            String ipt = scanner.next();
+            if (ObjectUtils.isNotEmpty(ipt)) {
+                return ipt;
+            }
+        }
+        throw new MybatisPlusException("请输入正确的" + tip + "!");
+    }
+
+    public static void main(String[] args) {
+        // 代码生成器
+        AutoGenerator mpg = new AutoGenerator();
+        // 全局配置
+        GlobalConfig gc = new GlobalConfig();
+        // System.getProperty("user.dir");
+        String projectPath = "/Users/jingyuanchao/Downloads";
+        //生成文件输出目录
+        gc.setOutputDir(projectPath + "/java");
+        gc.setAuthor("jingyuanchao");
+        //生成代码后,是否打开文件夹
+        gc.setOpen(true);
+        // 实体属性 Swagger2 注解
+        gc.setSwagger2(true);
+        mpg.setGlobalConfig(gc);
+        // 数据源配置
+        DataSourceConfig dsc = new DataSourceConfig();
+        dsc.setUrl("jdbc:mysql://10.87.10.54:3306/soc?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8");
+        dsc.setDriverName("com.mysql.cj.jdbc.Driver");
+        //com.microsoft.sqlserver.jdbc.SQLServerDriver
+        dsc.setUsername("root");
+        dsc.setPassword("XM_zm2019");
+        mpg.setDataSource(dsc);
+
+
+        // 包配置
+        PackageConfig pc = new PackageConfig();
+        pc.setModuleName(scanner("模块名"));
+        pc.setEntity("domain");
+        pc.setMapper("mapper");
+        pc.setService("service");
+        pc.setController("controller");
+        mpg.setPackageInfo(pc);
+        // 自定义配置
+        InjectionConfig cfg = new InjectionConfig() {
+            @Override
+            public void initMap() {
+                // to do nothing
+            }
+        };
+        // 如果模板引擎是 freemarker
+        //String templatePath = "/templates/mapper.xml.ftl";
+        // 自定义输出配置
+        List<FileOutConfig> focList = new ArrayList<>();
+        // 自定义配置会被优先输出
+//        focList.add(new FileOutConfig(templatePath) {
+//            @Override
+//            pub String outputFile(TableInfo tableInfo) {
+//                // 自定义输出文件名 , 如果你 Entity 设置了前后缀、此处注意 xml 的名称会跟着发生变化!!
+//                return projectPath + "/src/main/resources/mapper/" + pc.getModuleName()
+//                        + "/" + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML;
+//            }
+//        });
+        cfg.setFileOutConfigList(focList);
+        //这个必须要,需要提供一个默认的
+        mpg.setCfg(cfg);
+
+        // 策略配置
+        StrategyConfig strategy = new StrategyConfig();
+        // 表名生成策略
+        strategy.setNaming(NamingStrategy.underline_to_camel);
+        // 实体字段生成策略
+        strategy.setColumnNaming(NamingStrategy.underline_to_camel);
+        // 需要生成的表
+//        strategy.setInclude(scanner("表名").split(","));
+        strategy.setInclude("core_safety_responsibility_task,core_safety_responsibility_book,core_safety_responsibility_type".split(","));
+        // 使用lombook
+        strategy.setEntityLombokModel(true);
+        strategy.setRestControllerStyle(true);
+        // 生成注解
+        strategy.setEntityTableFieldAnnotationEnable(true);
+        // 自动生成实体类继承基类(基类必须已存在)
+        //strategy.setTablePrefix("t_","core_");
+        strategy.setSuperEntityClass("com.xunmei.common.core.web.domain.BaseEntity");
+        // 写于父类中的公共字段
+        strategy.setSuperEntityColumns("create_by","create_time", "update_by", "update_time");
+        mpg.setStrategy(strategy);
+        //mpg.setTemplateEngine(new FreemarkerTemplateEngine());
+        mpg.execute();
+    }
+
+
+
+}
+*/

+ 1 - 0
soc-modules/soc-modules-gen/src/main/resources/mapper/generator/GenTableMapper.xml

@@ -210,5 +210,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 			</if>
 			</if>
 
 
 		</where>
 		</where>
+		order by create_time desc
     </select>
     </select>
 </mapper>
 </mapper>