Althars123 4 년 전
부모
커밋
4414a69f14

+ 7 - 7
zzjs-admin/src/main/resources/application-dev.yml

@@ -2,7 +2,7 @@
 spring:
     datasource:
         type: com.alibaba.druid.pool.DruidDataSource
-        driverClassName: com.mysql.cj.jdbc.Driver
+#        driverClassName: com.mysql.cj.jdbc.Driver
         druid:
             # 主库数据源
             master:
@@ -10,12 +10,12 @@ spring:
                 username: root
                 password: miaxis110
             # 从库数据源
-#            xueshi:
-#                # 从数据源开关/默认关闭
-#                enabled: true
-#                url: jdbc:mysql://192.168.8.213:3306/zzjs-xueshi?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true
-#                username: root
-#                password: miaxis110
+            newgzpt:
+                # 从数据源开关/默认关闭
+                enabled: true
+                url: jdbc:oracle:thin:@47.99.70.145:1521:orcl
+                username: newgzpt
+                password: newgzpt2016
             # 初始连接数
             initialSize: 5
             # 最小连接池数量

+ 1 - 1
zzjs-admin/src/main/resources/application.yml

@@ -175,7 +175,7 @@ mybatis-plus:
 
 # PageHelper分页插件
 pagehelper:
-  helperDialect: mysql
+#  helperDialect: mysql
   reasonable: true
   supportMethodsArguments: true
   params: count=countSql

+ 7 - 0
zzjs-common/pom.xml

@@ -138,6 +138,13 @@
             <groupId>org.projectlombok</groupId>
             <artifactId>lombok</artifactId>
         </dependency>
+        <!--oracle驱动-->
+        <dependency>
+            <groupId>com.oracle</groupId>
+            <artifactId>ojdbc6</artifactId>
+            <version>11.2.0.3</version>
+        </dependency>
+
 
         <!-- swagger2-->
         <dependency>

+ 2 - 2
zzjs-common/src/main/java/com/miaxis/common/enums/DataSourceTypeEnum.java

@@ -13,7 +13,7 @@ public enum DataSourceTypeEnum
     MASTER,
 
     /**
-     * 学时
+     * 新公众平台
      */
-    XUESHI
+    NEWGZPT
 }

+ 8 - 4
zzjs-framework/src/main/java/com/miaxis/framework/config/DruidConfig.java

@@ -39,10 +39,10 @@ public class DruidConfig
     }
 
     @Bean
-    @ConfigurationProperties("spring.datasource.druid.xueshi")
+    @ConfigurationProperties("spring.datasource.druid.newgzpt")
     //控制配置类是否生效 enabled为true时生效
-    @ConditionalOnProperty(prefix = "spring.datasource.druid.xueshi", name = "enabled", havingValue = "true")
-    public DataSource xueshiDataSource(DruidProperties druidProperties)
+    @ConditionalOnProperty(prefix = "spring.datasource.druid.newgzpt", name = "enabled", havingValue = "true")
+    public DataSource newgzptDataSource(DruidProperties druidProperties)
     {
         DruidDataSource dataSource = DruidDataSourceBuilder.create().build();
         return druidProperties.dataSource(dataSource);
@@ -54,7 +54,7 @@ public class DruidConfig
     {
         Map<Object, Object> targetDataSources = new HashMap<>();
         targetDataSources.put(DataSourceTypeEnum.MASTER.name(), masterDataSource);
-        setDataSource(targetDataSources, DataSourceTypeEnum.XUESHI.name(), "xueshiDataSource");
+        setDataSource(targetDataSources, DataSourceTypeEnum.NEWGZPT.name(), "newgzptDataSource");
         return new DynamicDataSource(masterDataSource, targetDataSources);
     }
 
@@ -122,4 +122,8 @@ public class DruidConfig
         registrationBean.addUrlPatterns(commonJsPattern);
         return registrationBean;
     }
+
+    public static void main(String[] args) {
+        System.out.println(DataSourceTypeEnum.MASTER.name());
+    }
 }

+ 3 - 0
zzjs-generator/pom.xml

@@ -23,6 +23,9 @@
             <artifactId>velocity</artifactId>
         </dependency>
 
+
+
+
         <!-- 通用工具-->
         <dependency>
             <groupId>com.miaxis</groupId>

+ 10 - 7
zzjs-generator/src/main/java/com/miaxis/generator/service/GenTableColumnServiceImpl.java

@@ -1,6 +1,8 @@
 package com.miaxis.generator.service;
 
+import com.miaxis.common.annotation.DataSource;
 import com.miaxis.common.core.text.Convert;
+import com.miaxis.common.enums.DataSourceTypeEnum;
 import com.miaxis.generator.domain.GenTableColumn;
 import com.miaxis.generator.mapper.GenTableColumnMapper;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -10,10 +12,11 @@ import java.util.List;
 
 /**
  * 业务字段 服务层实现
- * 
+ *
  * @author miaxis
  */
 @Service
+//@DataSource(value = DataSourceTypeEnum.NEWGZPT)
 public class GenTableColumnServiceImpl implements com.miaxis.generator.service.IGenTableColumnService
 {
 	@Autowired
@@ -21,7 +24,7 @@ public class GenTableColumnServiceImpl implements com.miaxis.generator.service.I
 
 	/**
      * 查询业务字段列表
-     * 
+     *
      * @param tableId 业务字段编号
      * @return 业务字段集合
      */
@@ -30,10 +33,10 @@ public class GenTableColumnServiceImpl implements com.miaxis.generator.service.I
 	{
 	    return genTableColumnMapper.selectGenTableColumnListByTableId(tableId);
 	}
-	
+
     /**
      * 新增业务字段
-     * 
+     *
      * @param genTableColumn 业务字段信息
      * @return 结果
      */
@@ -42,10 +45,10 @@ public class GenTableColumnServiceImpl implements com.miaxis.generator.service.I
 	{
 	    return genTableColumnMapper.insertGenTableColumn(genTableColumn);
 	}
-	
+
 	/**
      * 修改业务字段
-     * 
+     *
      * @param genTableColumn 业务字段信息
      * @return 结果
      */
@@ -57,7 +60,7 @@ public class GenTableColumnServiceImpl implements com.miaxis.generator.service.I
 
 	/**
      * 删除业务字段对象
-     * 
+     *
      * @param ids 需要删除的数据ID
      * @return 结果
      */

+ 22 - 19
zzjs-generator/src/main/java/com/miaxis/generator/service/GenTableServiceImpl.java

@@ -2,9 +2,11 @@ package com.miaxis.generator.service;
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
+import com.miaxis.common.annotation.DataSource;
 import com.miaxis.common.constant.Constants;
 import com.miaxis.common.constant.GenConstants;
 import com.miaxis.common.core.text.CharsetKit;
+import com.miaxis.common.enums.DataSourceTypeEnum;
 import com.miaxis.common.exception.CustomException;
 import com.miaxis.common.utils.SecurityUtils;
 import com.miaxis.common.utils.StringUtils;
@@ -39,10 +41,11 @@ import java.util.zip.ZipOutputStream;
 
 /**
  * 业务 服务层实现
- * 
+ *
  * @author miaxis
  */
 @Service
+//@DataSource(value = DataSourceTypeEnum.NEWGZPT)
 public class GenTableServiceImpl implements IGenTableService
 {
     private static final Logger log = LoggerFactory.getLogger(GenTableServiceImpl.class);
@@ -55,7 +58,7 @@ public class GenTableServiceImpl implements IGenTableService
 
     /**
      * 查询业务信息
-     * 
+     *
      * @param id 业务ID
      * @return 业务信息
      */
@@ -69,7 +72,7 @@ public class GenTableServiceImpl implements IGenTableService
 
     /**
      * 查询业务列表
-     * 
+     *
      * @param genTable 业务信息
      * @return 业务集合
      */
@@ -81,7 +84,7 @@ public class GenTableServiceImpl implements IGenTableService
 
     /**
      * 查询据库列表
-     * 
+     *
      * @param genTable 业务信息
      * @return 数据库表集合
      */
@@ -93,7 +96,7 @@ public class GenTableServiceImpl implements IGenTableService
 
     /**
      * 查询据库列表
-     * 
+     *
      * @param tableNames 表名称组
      * @return 数据库表集合
      */
@@ -105,7 +108,7 @@ public class GenTableServiceImpl implements IGenTableService
 
     /**
      * 修改业务
-     * 
+     *
      * @param genTable 业务信息
      * @return 结果
      */
@@ -127,7 +130,7 @@ public class GenTableServiceImpl implements IGenTableService
 
     /**
      * 删除业务对象
-     * 
+     *
      * @param tableIds 需要删除的数据ID
      * @return 结果
      */
@@ -141,7 +144,7 @@ public class GenTableServiceImpl implements IGenTableService
 
     /**
      * 导入表结构
-     * 
+     *
      * @param tableList 导入表列表
      */
     @Override
@@ -176,7 +179,7 @@ public class GenTableServiceImpl implements IGenTableService
 
     /**
      * 预览代码
-     * 
+     *
      * @param tableId 表编号
      * @return 预览数据列表
      */
@@ -208,7 +211,7 @@ public class GenTableServiceImpl implements IGenTableService
 
     /**
      * 生成代码(下载方式)
-     * 
+     *
      * @param tableName 表名称
      * @return 数据
      */
@@ -224,7 +227,7 @@ public class GenTableServiceImpl implements IGenTableService
 
     /**
      * 生成代码(自定义路径)
-     * 
+     *
      * @param tableName 表名称
      */
     @Override
@@ -265,7 +268,7 @@ public class GenTableServiceImpl implements IGenTableService
 
     /**
      * 同步数据库
-     * 
+     *
      * @param tableName 表名称
      */
     @Override
@@ -296,7 +299,7 @@ public class GenTableServiceImpl implements IGenTableService
 
     /**
      * 批量生成代码(下载方式)
-     * 
+     *
      * @param tableNames 表数组
      * @return 数据
      */
@@ -354,7 +357,7 @@ public class GenTableServiceImpl implements IGenTableService
 
     /**
      * 修改保存参数校验
-     * 
+     *
      * @param genTable 业务信息
      */
     @Override
@@ -381,7 +384,7 @@ public class GenTableServiceImpl implements IGenTableService
 
     /**
      * 设置主键列信息
-     * 
+     *
      * @param table 业务表信息
      * @param columns 业务字段列表
      */
@@ -403,7 +406,7 @@ public class GenTableServiceImpl implements IGenTableService
 
     /**
      * 设置代码生成其他选项值
-     * 
+     *
      * @param genTable 设置后的生成对象
      */
     public void setTableFromOptions(GenTable genTable)
@@ -416,7 +419,7 @@ public class GenTableServiceImpl implements IGenTableService
             String treeName = paramsObj.getString(GenConstants.TREE_NAME);
             String parentMenuId = paramsObj.getString(GenConstants.PARENT_MENU_ID);
             String parentMenuName = paramsObj.getString(GenConstants.PARENT_MENU_NAME);
-            
+
             genTable.setTreeCode(treeCode);
             genTable.setTreeParentCode(treeParentCode);
             genTable.setTreeName(treeName);
@@ -427,7 +430,7 @@ public class GenTableServiceImpl implements IGenTableService
 
     /**
      * 获取代码生成地址
-     * 
+     *
      * @param table 业务表信息
      * @param template 模板文件路径
      * @return 生成地址
@@ -441,4 +444,4 @@ public class GenTableServiceImpl implements IGenTableService
         }
         return genPath + File.separator + VelocityUtils.getFileName(template, table);
     }
-}
+}

+ 12 - 1
zzjs-service/pom.xml

@@ -24,7 +24,18 @@
             <artifactId>zzjs-framework</artifactId>
         </dependency>
 
-
+        <!-- mpp代码生成器-->
+        <dependency>
+            <groupId>com.baomidou</groupId>
+            <artifactId>mybatis-plus-generator</artifactId>
+            <version>3.2.0</version>
+        </dependency>
+        <!--模板引擎-->
+        <dependency>
+            <groupId>org.apache.velocity</groupId>
+            <artifactId>velocity-engine-core</artifactId>
+            <version>2.1</version>
+        </dependency>
 
         <!-- https://mvnrepository.com/artifact/commons-httpclient/commons-httpclient -->
         <dependency>

+ 181 - 0
zzjs-service/src/main/java/com/miaxis/generator/CodeGenerator.java

@@ -0,0 +1,181 @@
+package com.miaxis.generator;
+
+
+import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException;
+import com.baomidou.mybatisplus.core.toolkit.StringPool;
+import com.baomidou.mybatisplus.generator.AutoGenerator;
+import com.baomidou.mybatisplus.generator.config.*;
+import com.baomidou.mybatisplus.generator.config.builder.ConfigBuilder;
+import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
+import com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine;
+import org.apache.commons.lang3.StringUtils;
+
+import java.io.File;
+import java.lang.reflect.Field;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Scanner;
+
+public class CodeGenerator {
+    /**
+     * <p>
+     * 读取控制台内容
+     * </p>
+     */
+    public static String scanner(String tip) {
+        Scanner scanner = new Scanner(System.in);
+
+        StringBuilder help = new StringBuilder();
+        help.append("请输入" + tip + ":");
+        System.out.println(help.toString());
+        if (scanner.hasNext()) {
+            String ipt = scanner.next();
+            if (StringUtils.isNotEmpty(ipt)) {
+                return ipt;
+            }
+        }
+        throw new MybatisPlusException("请输入正确的" + tip + "!");
+    }
+
+    public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException {
+        // 代码生成器
+        AutoGenerator mpg = new AutoGenerator();
+
+        // 全局配置
+        GlobalConfig gc = new GlobalConfig();
+        String projectPath = System.getProperty("user.dir");
+        gc.setOutputDir(projectPath + "/src/main/java");
+//        gc.setAuthor("jobob");
+        gc.setOpen(false);
+        gc.setSwagger2(true);// 实体属性 Swagger2 注解
+        mpg.setGlobalConfig(gc);
+
+        // 数据源配置
+        DataSourceConfig dsc = new DataSourceConfig();
+
+        //local
+//        dsc.setUrl("jdbc:mysql://localhost:3306/engine?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true");
+//        dsc.setDriverName("com.mysql.cj.jdbc.Driver");
+//        dsc.setUsername("root");
+//        dsc.setPassword("cj1234");
+
+
+        dsc.setUrl("jdbc:oracle:thin:@47.99.70.145:1521:orcl");
+        // dsc.setSchemaName("public");
+        dsc.setDriverName("oracle.jdbc.driver.OracleDriver");
+        dsc.setUsername("newgzpt");
+        dsc.setPassword("newgzpt2016");
+        //master
+//        dsc.setUrl("jdbc:mysql://172.16.18.112:3306/xiaodao?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true");
+//        dsc.setDriverName("com.mysql.cj.jdbc.Driver");
+//        dsc.setUsername("admin");
+//        dsc.setPassword("admin");
+
+        //yb
+//        dsc.setUrl("jdbc:mysql://172.16.2.233:33071/ims?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true");
+//        dsc.setDriverName("com.mysql.cj.jdbc.Driver");
+//        dsc.setUsername("root");
+//        dsc.setPassword("root");
+        mpg.setDataSource(dsc);
+
+        // 包配置
+        PackageConfig pc = new PackageConfig();
+        pc.setModuleName(scanner("模块名"));
+        pc.setParent("com.miaxis");
+        mpg.setPackageInfo(pc);
+        // 配置模板
+        TemplateConfig templateConfig = new TemplateConfig();
+        // 配置自定义输出模板
+        //指定自定义模板路径,注意不要带上.ftl/.vm, 会根据使用的模板引擎自动识别
+        // templateConfig.setEntity("templates/entity2.java");
+        // templateConfig.setService();
+        // templateConfig.setController();
+        // templateConfig.setXml(null);
+        mpg.setTemplate(templateConfig);
+
+        // 策略配置
+        StrategyConfig strategy = new StrategyConfig();
+        strategy.setNaming(NamingStrategy.underline_to_camel);
+        strategy.setColumnNaming(NamingStrategy.underline_to_camel);
+        //   strategy.setSuperEntityClass("com.baomidou.ant.common.BaseEntity");
+        strategy.setEntityLombokModel(true);
+        strategy.setRestControllerStyle(true);
+        // 公共父类
+//        strategy.setSuperEntityClass("com.ylzinfo.brt.engine.entity.BaseEntity");
+        // 写于父类中的公共字段
+//        strategy.setSuperEntityColumns("create_time","update_time");
+        strategy.setInclude(scanner("表名,多个英文逗号分割").split(","));
+        strategy.setControllerMappingHyphenStyle(true);
+        strategy.setTablePrefix(pc.getModuleName() + "_");
+        strategy.setEntityTableFieldAnnotationEnable(true);
+        mpg.setStrategy(strategy);
+        mpg.setTemplateEngine(new VelocityTemplateEngine());
+        //如果不调用该方法、就会使用MyBatis-Plus默认的文件生成路径和包路径生成文件、但可以使用上面的PackageConfig做一些简单的配置
+        customPackagePath(pc,mpg);
+        mpg.execute();
+    }
+
+
+
+    /**
+     * 自定义包路径,文件生成路径,这边配置更灵活
+     * 虽然也可以使用InjectionConfig设置FileOutConfig的方式设置路径
+     * 这里直接使用Map方式注入ConfigBuilder配置对象更加直观
+     * @param pc
+     * @param mpg
+     * @throws NoSuchFieldException
+     * @throws IllegalAccessException
+     */
+    public static void customPackagePath(PackageConfig pc,AutoGenerator mpg) throws NoSuchFieldException, IllegalAccessException {
+
+        String projectPath = System.getProperty("user.dir");
+        String mavenPath = "\\src\\main\\java\\";
+        String srcPath = projectPath+mavenPath;
+
+        String moduleName = pc.getModuleName();
+
+        /**
+         * packageInfo配置controller、service、serviceImpl、entity、mapper等文件的包路径
+         * 这里包路径可以根据实际情况灵活配置
+         */
+        Map<String,String> packageInfo = new HashMap<>();
+        packageInfo.put(ConstVal.CONTROLLER, pc.getParent()+".controller");
+        packageInfo.put(ConstVal.SERVICE,pc.getParent()+".service");
+        packageInfo.put(ConstVal.SERVICE_IMPL,pc.getParent()+".service.impl");
+        packageInfo.put(ConstVal.ENTITY, pc.getParent()+".domain");
+        packageInfo.put(ConstVal.MAPPER, pc.getParent()+".mapper");
+
+        /**
+         * pathInfo配置controller、service、serviceImpl、entity、mapper、mapper.xml等文件的生成路径
+         * srcPath也可以更具实际情况灵活配置
+         * 后面部分的路径是和上面packageInfo包路径对应的源码文件夹路径
+         * 这里你可以选择注释其中某些路径,可忽略生成该类型的文件,例如:注释掉下面pathInfo中Controller的路径,就不会生成Controller文件
+         */
+        Map pathInfo = new HashMap<>();
+        pathInfo.put(ConstVal.CONTROLLER_PATH, srcPath + packageInfo.get(ConstVal.CONTROLLER).replaceAll("\\.", StringPool.BACK_SLASH + File.separator));
+        pathInfo.put(ConstVal.SERVICE_PATH, srcPath + packageInfo.get(ConstVal.SERVICE).replaceAll("\\.", StringPool.BACK_SLASH + File.separator));
+        pathInfo.put(ConstVal.SERVICE_IMPL_PATH, srcPath + packageInfo.get(ConstVal.SERVICE_IMPL).replaceAll("\\.", StringPool.BACK_SLASH + File.separator));
+        pathInfo.put(ConstVal.ENTITY_PATH, srcPath + packageInfo.get(ConstVal.ENTITY).replaceAll("\\.", StringPool.BACK_SLASH + File.separator));
+        pathInfo.put(ConstVal.MAPPER_PATH, srcPath + packageInfo.get(ConstVal.MAPPER).replaceAll("\\.", StringPool.BACK_SLASH + File.separator));
+        pathInfo.put(ConstVal.XML_PATH, projectPath+"\\src\\main\\resources\\mapper\\");
+        pc.setPathInfo(pathInfo);
+
+        /**
+         * 创建configBuilder对象,传入必要的参数
+         * 将以上的定义的包路径packageInfo配置到赋值到configBuilder对象的packageInfo属性上
+         * 因为packageInfo是私有成员变量,也没有提交提供公共的方法,所以使用反射注入
+         * 为啥要这么干,看源码去吧
+         */
+        ConfigBuilder configBuilder = new ConfigBuilder(mpg.getPackageInfo(), mpg.getDataSource(), mpg.getStrategy(), mpg.getTemplate(), mpg.getGlobalConfig());
+        Field packageInfoField = configBuilder.getClass().getDeclaredField("packageInfo");
+        packageInfoField.setAccessible(true);
+        packageInfoField.set(configBuilder,packageInfo);
+
+        /**
+         * 设置配置对象
+         */
+        mpg.setConfig(configBuilder);
+    }
+
+
+}