Procházet zdrojové kódy

Merge branch 'feature_V0.4.5_gencode' into dev-V0.4.5

jay před 1 rokem
rodič
revize
256d436329
25 změnil soubory, kde provedl 773 přidání a 195 odebrání
  1. 45 27
      iot-module/iot-generator/pom.xml
  2. 108 0
      iot-module/iot-generator/src/main/java/cc/iotkit/generator/config/MybatisPlusConfig.java
  3. 53 40
      iot-module/iot-generator/src/main/java/cc/iotkit/generator/controller/GenController.java
  4. 1 1
      iot-module/iot-generator/src/main/java/cc/iotkit/generator/core/BaseMapperPlus.java
  5. 5 0
      iot-module/iot-generator/src/main/java/cc/iotkit/generator/core/DataBaseHelper.java
  6. 1 0
      iot-module/iot-generator/src/main/java/cc/iotkit/generator/core/DataBaseType.java
  7. 38 0
      iot-module/iot-generator/src/main/java/cc/iotkit/generator/core/DbIdGenerator.java
  8. 35 0
      iot-module/iot-generator/src/main/java/cc/iotkit/generator/core/PageBuilder.java
  9. 6 0
      iot-module/iot-generator/src/main/java/cc/iotkit/generator/domain/GenTable.java
  10. 4 4
      iot-module/iot-generator/src/main/java/cc/iotkit/generator/domain/GenTableColumn.java
  11. 24 0
      iot-module/iot-generator/src/main/java/cc/iotkit/generator/dto/bo/ImportTableBo.java
  12. 32 0
      iot-module/iot-generator/src/main/java/cc/iotkit/generator/factory/YmlPropertySourceFactory.java
  13. 7 2
      iot-module/iot-generator/src/main/java/cc/iotkit/generator/mapper/GenTableMapper.java
  14. 21 16
      iot-module/iot-generator/src/main/java/cc/iotkit/generator/service/GenTableServiceImpl.java
  15. 7 6
      iot-module/iot-generator/src/main/java/cc/iotkit/generator/service/IGenTableService.java
  16. 1 0
      iot-module/iot-generator/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
  17. 33 0
      iot-module/iot-generator/src/main/resources/common-mybatis.yml
  18. 16 4
      iot-module/iot-generator/src/main/resources/mapper/generator/GenTableColumnMapper.xml
  19. 181 92
      iot-module/iot-generator/src/main/resources/mapper/generator/GenTableMapper.xml
  20. 1 1
      iot-module/pom.xml
  21. 4 0
      iot-starter/pom.xml
  22. 31 0
      iot-starter/src/main/resources/application-mysql.yml
  23. 54 2
      iot-starter/src/main/resources/application.yml
  24. 60 0
      iot-starter/src/main/resources/sql/schema.sql
  25. 5 0
      pom.xml

+ 45 - 27
iot-module/iot-generator/pom.xml

@@ -2,37 +2,24 @@
 <project xmlns="http://maven.apache.org/POM/4.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-<!--    <parent>-->
-<!--        <groupId>cc.iotkit</groupId>-->
-<!--        <artifactId>iot-module</artifactId>-->
-<!--        <version>${revision}</version>-->
-<!--    </parent>-->
-    <build>
-        <plugins>
-            <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-compiler-plugin</artifactId>
-                <configuration>
-                    <source>8</source>
-                    <target>8</target>
-                </configuration>
-            </plugin>
-        </plugins>
-    </build>
+    <parent>
+        <artifactId>iot-module</artifactId>
+        <groupId>cc.iotkit</groupId>
+        <version>${revision}</version>
+    </parent>
+
     <modelVersion>4.0.0</modelVersion>
 
     <artifactId>iot-generator</artifactId>
-    <version>1.0.0</version>
+
 
     <description>
         generator 代码生成
     </description>
 
     <properties>
-        <dynamic-ds.version>3.6.1</dynamic-ds.version>
-        <mapstruct-plus.version>1.2.1</mapstruct-plus.version>
+        <dynamic-ds.version>3.5.1</dynamic-ds.version>
         <mapstruct-plus.lombok.version>0.2.0</mapstruct-plus.lombok.version>
-        <spring-boot.mybatis>3.0.1</spring-boot.mybatis>
         <mybatis-plus.version>3.5.3.1</mybatis-plus.version>
 
     </properties>
@@ -49,7 +36,10 @@
             <artifactId>iot-common-doc</artifactId>
         </dependency>
         <!--常用工具类 -->
-
+        <dependency>
+            <groupId>com.github.yitter</groupId>
+            <artifactId>yitter-idgenerator</artifactId>
+        </dependency>
 
         <dependency>
             <groupId>cc.iotkit</groupId>
@@ -74,11 +64,7 @@
             <version>${dynamic-ds.version}</version>
         </dependency>
 
-        <dependency>
-            <groupId>org.mybatis.spring.boot</groupId>
-            <artifactId>mybatis-spring-boot-starter</artifactId>
-            <version>${spring-boot.mybatis}</version>
-        </dependency>
+
 
         <dependency>
             <groupId>com.baomidou</groupId>
@@ -93,5 +79,37 @@
         </dependency>
 
     </dependencies>
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>3.8.1</version>
+                <configuration>
+                    <source>${java.version}</source> <!-- depending on your project -->
+                    <target>${java.version}</target> <!-- depending on your project -->
+                    <encoding>utf8</encoding>
+                    <annotationProcessorPaths>
+                        <path>
+                            <groupId>org.projectlombok</groupId>
+                            <artifactId>lombok</artifactId>
+                            <version>${lombok.version}</version>
+                        </path>
+                        <path>
+                            <groupId>io.github.linpeilie</groupId>
+                            <artifactId>mapstruct-plus-processor</artifactId>
+                            <version>${mapstruct-plus.version}</version>
+                        </path>
+                        <path>
+                            <groupId>org.projectlombok</groupId>
+                            <artifactId>lombok-mapstruct-binding</artifactId>
+                            <version>0.2.0</version>
+                        </path>
+                        <!-- other annotation processors -->
+                    </annotationProcessorPaths>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
 
 </project>

+ 108 - 0
iot-module/iot-generator/src/main/java/cc/iotkit/generator/config/MybatisPlusConfig.java

@@ -0,0 +1,108 @@
+package cc.iotkit.generator.config;
+
+import cc.iotkit.generator.core.DbIdGenerator;
+import cc.iotkit.generator.factory.YmlPropertySourceFactory;
+import cn.hutool.core.net.NetUtil;
+import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
+import com.baomidou.mybatisplus.core.incrementer.DefaultIdentifierGenerator;
+import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
+import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
+import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
+import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
+//import org.dromara.common.core.factory.YmlPropertySourceFactory;
+//import org.dromara.common.mybatis.handler.InjectionMetaObjectHandler;
+//import org.dromara.common.mybatis.interceptor.PlusDataPermissionInterceptor;
+import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.boot.autoconfigure.AutoConfiguration;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.PropertySource;
+import org.springframework.transaction.annotation.EnableTransactionManagement;
+
+/**
+ * mybatis-plus配置类(下方注释有插件介绍)
+ *
+ * @author Lion Li
+ */
+@EnableTransactionManagement(proxyTargetClass = true)
+@AutoConfiguration
+@MapperScan("${mybatis-plus.mapperPackage}")
+//@PropertySource(value = "classpath:common-mybatis.yml", factory = YmlPropertySourceFactory.class)
+public class MybatisPlusConfig {
+
+    @Bean
+    public MybatisPlusInterceptor mybatisPlusInterceptor() {
+        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
+        // 数据权限处理
+//        interceptor.addInnerInterceptor(dataPermissionInterceptor());
+        // 分页插件
+        interceptor.addInnerInterceptor(paginationInnerInterceptor());
+        // 乐观锁插件
+        interceptor.addInnerInterceptor(optimisticLockerInnerInterceptor());
+        return interceptor;
+    }
+
+    /**
+     * 数据权限拦截器
+     */
+//    public PlusDataPermissionInterceptor dataPermissionInterceptor() {
+//        return new PlusDataPermissionInterceptor();
+//    }
+
+    /**
+     * 分页插件,自动识别数据库类型
+     */
+    public PaginationInnerInterceptor paginationInnerInterceptor() {
+        PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor();
+        // 设置最大单页限制数量,默认 500 条,-1 不受限制
+        paginationInnerInterceptor.setMaxLimit(-1L);
+        // 分页合理化
+        paginationInnerInterceptor.setOverflow(true);
+        return paginationInnerInterceptor;
+    }
+
+    /**
+     * 乐观锁插件
+     */
+    public OptimisticLockerInnerInterceptor optimisticLockerInnerInterceptor() {
+        return new OptimisticLockerInnerInterceptor();
+    }
+
+    /**
+     * 元对象字段填充控制器
+     */
+//    @Bean
+//    public MetaObjectHandler metaObjectHandler() {
+//        return new InjectionMetaObjectHandler();
+//    }
+
+    /**
+     * 使用网卡信息绑定雪花生成器
+     * 防止集群雪花ID重复
+     */
+    @Bean
+    public IdentifierGenerator idGenerator() {
+        String hostAddress = NetUtil.getLocalhost().getHostAddress();
+        return new DbIdGenerator((short) ((short) hostAddress.hashCode()%64));
+    }
+
+    /**
+     * PaginationInnerInterceptor 分页插件,自动识别数据库类型
+     * https://baomidou.com/pages/97710a/
+     * OptimisticLockerInnerInterceptor 乐观锁插件
+     * https://baomidou.com/pages/0d93c0/
+     * MetaObjectHandler 元对象字段填充控制器
+     * https://baomidou.com/pages/4c6bcf/
+     * ISqlInjector sql注入器
+     * https://baomidou.com/pages/42ea4a/
+     * BlockAttackInnerInterceptor 如果是对全表的删除或更新操作,就会终止该操作
+     * https://baomidou.com/pages/f9a237/
+     * IllegalSQLInnerInterceptor sql性能规范插件(垃圾SQL拦截)
+     * IdentifierGenerator 自定义主键策略
+     * https://baomidou.com/pages/568eb2/
+     * TenantLineInnerInterceptor 多租户插件
+     * https://baomidou.com/pages/aef2f2/
+     * DynamicTableNameInnerInterceptor 动态表名插件
+     * https://baomidou.com/pages/2a45ff/
+     */
+
+}

+ 53 - 40
iot-module/iot-generator/src/main/java/cc/iotkit/generator/controller/GenController.java

@@ -2,8 +2,8 @@ package cc.iotkit.generator.controller;
 
 import cc.iotkit.common.api.PageRequest;
 import cc.iotkit.common.api.Paging;
-import cc.iotkit.generator.core.PageQuery;
-import cn.dev33.satoken.annotation.SaCheckPermission;
+import cc.iotkit.common.api.Request;
+import cc.iotkit.generator.dto.bo.ImportTableBo;
 import cn.hutool.core.convert.Convert;
 import cn.hutool.core.io.IoUtil;
 
@@ -14,11 +14,14 @@ import cc.iotkit.common.log.enums.BusinessType;
 import cc.iotkit.generator.domain.GenTable;
 import cc.iotkit.generator.domain.GenTableColumn;
 import cc.iotkit.generator.service.IGenTableService;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiOperation;
 import lombok.RequiredArgsConstructor;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
-import jakarta.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpServletResponse;
+
 import java.io.IOException;
 import java.util.HashMap;
 import java.util.List;
@@ -40,20 +43,22 @@ public class GenController extends BaseController {
     /**
      * 查询代码生成列表
      */
-    @SaCheckPermission("tool:gen:list")
+//    @SaCheckPermission("tool:gen:list")
+    @ApiOperation(value = "查询代码生成列表", notes = "查询代码生成列表,根据查询条件分页")
     @PostMapping("/list")
-    public Paging<GenTable> genList(GenTable genTable, PageQuery pageQuery) {
-        return genTableService.selectPageGenTableList(genTable, pageQuery);
+    public Paging<GenTable> genList(@RequestBody @Validated PageRequest<GenTable> query) {
+        return genTableService.selectPageGenTableList(query );
     }
 
     /**
      * 修改代码生成业务
      *
-     * @param tableId 表ID
      */
-    @SaCheckPermission("tool:gen:query")
-    @PostMapping(value = "/{tableId}")
-    public Map<String, Object> getInfo(@PathVariable Long tableId) {
+//    @SaCheckPermission("tool:gen:query")
+    @ApiOperation(value = "修改代码生成业务", notes = "修改代码生成业务详情")
+    @PostMapping(value = "/getDetail")
+    public Map<String, Object> getInfo(@Validated @RequestBody Request<Long> bo) {
+        Long tableId = bo.getData();
         GenTable table = genTableService.selectGenTableById(tableId);
         List<GenTable> tables = genTableService.selectGenTableAll();
         List<GenTableColumn> list = genTableService.selectGenTableColumnListByTableId(tableId);
@@ -67,10 +72,11 @@ public class GenController extends BaseController {
     /**
      * 查询数据库列表
      */
-    @SaCheckPermission("tool:gen:list")
+//    @SaCheckPermission("tool:gen:list")
+    @ApiOperation(value = "查询数据库列表", notes = "查询数据库列表")
     @PostMapping("/db/list")
-    public Paging<GenTable> dataList(GenTable genTable, PageQuery pageQuery) {
-        return genTableService.selectPageDbTableList(genTable, pageQuery);
+    public Paging<GenTable> dataList(@RequestBody @Validated PageRequest<GenTable> pageQuery) {
+        return genTableService.selectPageDbTableList( pageQuery);
     }
 
     /**
@@ -78,7 +84,8 @@ public class GenController extends BaseController {
      *
      * @param tableId 表ID
      */
-    @SaCheckPermission("tool:gen:list")
+//    @SaCheckPermission("tool:gen:list")
+    @ApiOperation(value = "查询数据表字段列表", notes = "查询数据表字段列表")
     @PostMapping(value = "/column/{tableId}")
     public Paging<GenTableColumn> columnList(Long tableId) {
 
@@ -90,15 +97,16 @@ public class GenController extends BaseController {
     /**
      * 导入表结构(保存)
      *
-     * @param tables 表名串
      */
-    @SaCheckPermission("tool:gen:import")
+//    @SaCheckPermission("tool:gen:import")
     @Log(title = "代码生成", businessType = BusinessType.IMPORT)
     @PostMapping("/importTable")
-    public void importTableSave(String tables) {
-        String[] tableNames = Convert.toStrArray(tables);
+    @ApiOperation(value = "导入表结构(保存)", notes = "导入表结构(保存)")
+    public void importTableSave(@Validated @RequestBody Request<ImportTableBo> bo) {
+        List<String> tables = bo.getData().getTables();
+
         // 查询表信息
-        List<GenTable> tableList = genTableService.selectDbTableListByNames(tableNames);
+        List<GenTable> tableList = genTableService.selectDbTableListByNames(tables);
         genTableService.importGenTable(tableList);
         return;
     }
@@ -106,10 +114,12 @@ public class GenController extends BaseController {
     /**
      * 修改保存代码生成业务
      */
-    @SaCheckPermission("tool:gen:edit")
+//    @SaCheckPermission("tool:gen:edit")
+    @ApiOperation(value = "修改保存代码生成业务", notes = "修改保存代码生成业务")
     @Log(title = "代码生成", businessType = BusinessType.UPDATE)
-    @PutMapping
-    public void editSave(@Validated @RequestBody GenTable genTable) {
+    @PostMapping("/edit")
+    public void editSave(@Validated @RequestBody Request<GenTable> bo) {
+        GenTable genTable = bo.getData();
         genTableService.validateEdit(genTable);
         genTableService.updateGenTable(genTable);
         return;
@@ -118,25 +128,26 @@ public class GenController extends BaseController {
     /**
      * 删除代码生成
      *
-     * @param tableIds 表ID串
+
      */
-    @SaCheckPermission("tool:gen:remove")
+//    @SaCheckPermission("tool:gen:remove")
     @Log(title = "代码生成", businessType = BusinessType.DELETE)
-    @DeleteMapping("/{tableIds}")
-    public void remove(@PathVariable Long[] tableIds) {
-        genTableService.deleteGenTableByIds(tableIds);
+    @PostMapping("/delete")
+    @ApiOperation(value = "删除代码生成", notes = "删除代码生成")
+    public void remove(@Validated @RequestBody Request<List<Long>> bo) {
+        genTableService.deleteGenTableByIds(bo.getData());
         return;
     }
 
     /**
      * 预览代码
      *
-     * @param tableId 表ID
      */
-    @SaCheckPermission("tool:gen:preview")
-    @PostMapping("/preview/{tableId}")
-    public Map<String, String> preview(@PathVariable("tableId") Long tableId) throws IOException {
-        Map<String, String> dataMap = genTableService.previewCode(tableId);
+//    @SaCheckPermission("tool:gen:preview")
+    @ApiOperation(value = "预览代码", notes = "预览代码")
+    @PostMapping("/preview")
+    public Map<String, String> preview(@Validated @RequestBody Request<Long> bo) throws IOException {
+        Map<String, String> dataMap = genTableService.previewCode(bo.getData());
         return dataMap;
     }
 
@@ -145,7 +156,7 @@ public class GenController extends BaseController {
      *
      * @param tableName 表名
      */
-    @SaCheckPermission("tool:gen:code")
+//    @SaCheckPermission("tool:gen:code")
     @Log(title = "代码生成", businessType = BusinessType.GENCODE)
     @PostMapping("/download/{tableName}")
     public void download(HttpServletResponse response, @PathVariable("tableName") String tableName) throws IOException {
@@ -158,8 +169,9 @@ public class GenController extends BaseController {
      *
      * @param tableName 表名
      */
-    @SaCheckPermission("tool:gen:code")
+//    @SaCheckPermission("tool:gen:code")
     @Log(title = "代码生成", businessType = BusinessType.GENCODE)
+    @ApiOperation(value = "生成代码(自定义路径)", notes = "生成代码(自定义路径)")
     @PostMapping("/genCode/{tableName}")
     public void genCode(@PathVariable("tableName") String tableName) {
         genTableService.generatorCode(tableName);
@@ -169,13 +181,13 @@ public class GenController extends BaseController {
     /**
      * 同步数据库
      *
-     * @param tableName 表名
      */
-    @SaCheckPermission("tool:gen:edit")
+//    @SaCheckPermission("tool:gen:edit")
     @Log(title = "代码生成", businessType = BusinessType.UPDATE)
-    @PostMapping("/synchDb/{tableName}")
-    public void synchDb(@PathVariable("tableName") String tableName) {
-        genTableService.synchDb(tableName);
+    @ApiOperation(value = "同步数据库", notes = "同步数据库")
+    @PostMapping("/synchDb")
+    public void synchDb(@Validated @RequestBody Request<String> bo) {
+        genTableService.synchDb(bo.getData());
         return ;
     }
 
@@ -184,8 +196,9 @@ public class GenController extends BaseController {
      *
      * @param tables 表名串
      */
-    @SaCheckPermission("tool:gen:code")
+//    @SaCheckPermission("tool:gen:code")
     @Log(title = "代码生成", businessType = BusinessType.GENCODE)
+    @ApiOperation(value = "批量生成代码", notes = "批量生成代码")
     @PostMapping("/batchGenCode")
     public void batchGenCode(HttpServletResponse response, String tables) throws IOException {
         String[] tableNames = Convert.toStrArray(tables);

+ 1 - 1
iot-module/iot-generator/src/main/java/cc/iotkit/generator/core/BaseMapperPlus.java

@@ -10,10 +10,10 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.ReflectionKit;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.toolkit.Db;
+
 import org.apache.ibatis.logging.Log;
 import org.apache.ibatis.logging.LogFactory;
 
-
 import java.io.Serializable;
 import java.util.Collection;
 import java.util.List;

+ 5 - 0
iot-module/iot-generator/src/main/java/cc/iotkit/generator/core/DataBaseHelper.java

@@ -41,6 +41,11 @@ public class DataBaseHelper {
         return DataBaseType.MY_SQL == getDataBaseType();
     }
 
+    public static boolean isH2() {
+        return DataBaseType.H2 == getDataBaseType();
+    }
+
+
     public static boolean isOracle() {
         return DataBaseType.ORACLE == getDataBaseType();
     }

+ 1 - 0
iot-module/iot-generator/src/main/java/cc/iotkit/generator/core/DataBaseType.java

@@ -19,6 +19,7 @@ public enum DataBaseType {
      */
     MY_SQL("MySQL"),
 
+    H2("H2"),
     /**
      * Oracle
      */

+ 38 - 0
iot-module/iot-generator/src/main/java/cc/iotkit/generator/core/DbIdGenerator.java

@@ -0,0 +1,38 @@
+package cc.iotkit.generator.core;
+
+import cn.hutool.core.net.NetUtil;
+import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
+import com.github.yitter.contract.IdGeneratorOptions;
+import com.github.yitter.idgen.YitIdHelper;
+
+import org.springframework.stereotype.Component;
+
+import javax.annotation.PostConstruct;
+import java.io.Serializable;
+import java.lang.reflect.Field;
+import java.util.Objects;
+
+/**
+ * @author: Jay
+ * @description:
+ * @date:created in 2023/5/18 10:20
+ * @modificed by:
+ */
+public class DbIdGenerator implements IdentifierGenerator {
+
+
+  public  DbIdGenerator(Short workerId) {
+//    使用网卡信息绑定雪花生成器
+//    防止集群雪花ID重复
+
+    IdGeneratorOptions options = new IdGeneratorOptions(workerId);
+    YitIdHelper.setIdGenerator(options);
+  }
+
+
+
+  @Override
+  public Number nextId(Object entity) {
+    return YitIdHelper.nextId();
+  }
+}

+ 35 - 0
iot-module/iot-generator/src/main/java/cc/iotkit/generator/core/PageBuilder.java

@@ -0,0 +1,35 @@
+package cc.iotkit.generator.core;
+
+import cc.iotkit.common.api.PageRequest;
+import cc.iotkit.common.exception.BizException;
+import cc.iotkit.common.utils.StringUtils;
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.ObjectUtil;
+import com.baomidou.mybatisplus.core.metadata.OrderItem;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 分页查询实体类
+ *
+ * @author Lion Li
+ */
+
+
+public class PageBuilder implements Serializable {
+
+
+    static public Page build(PageRequest pageRequest) {
+       Integer pageNum = ObjectUtil.defaultIfNull(pageRequest.getPageNum(), PageQuery.DEFAULT_PAGE_NUM);
+       Integer pageSize = ObjectUtil.defaultIfNull(pageRequest.getPageSize(), PageQuery.DEFAULT_PAGE_SIZE);
+       Page page = new Page(pageNum, pageSize);
+
+       return page;
+   }
+
+}

+ 6 - 0
iot-module/iot-generator/src/main/java/cc/iotkit/generator/domain/GenTable.java

@@ -32,6 +32,12 @@ public class GenTable extends BaseEntity {
     @TableId(value = "table_id")
     private Long tableId;
 
+    /**
+     * 数据源名称
+     */
+    @NotBlank(message = "数据源名称不能为空")
+    private String dataName;
+
     /**
      * 表名称
      */

+ 4 - 4
iot-module/iot-generator/src/main/java/cc/iotkit/generator/domain/GenTableColumn.java

@@ -190,10 +190,10 @@ public class GenTableColumn extends BaseEntity {
 
     public static boolean isSuperColumn(String javaField) {
         return StringUtils.equalsAnyIgnoreCase(javaField,
-            // BaseEntity
-            "createBy", "createTime", "updateBy", "updateTime",
-            // TreeEntity
-            "parentName", "parentId");
+                // BaseEntity
+                "createBy", "createTime", "updateBy", "updateTime",
+                // TreeEntity
+                "parentName", "parentId");
     }
 
     public boolean isUsableColumn() {

+ 24 - 0
iot-module/iot-generator/src/main/java/cc/iotkit/generator/dto/bo/ImportTableBo.java

@@ -0,0 +1,24 @@
+package cc.iotkit.generator.dto.bo;
+
+import cc.iotkit.common.api.BaseDto;
+import io.swagger.annotations.ApiModelProperty;
+import jakarta.validation.constraints.NotEmpty;
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * @Author: jay
+ * @Date: 2023/6/24 16:47
+ * @Version: V1.0
+ * @Description: 导入表Bo
+ */
+@Data
+public class ImportTableBo extends BaseDto {
+
+    @ApiModelProperty(value = "表名列表", notes = "表名列表")
+    @NotEmpty(message = "表名列表不能为空")
+    private List<String> tables;
+
+
+}

+ 32 - 0
iot-module/iot-generator/src/main/java/cc/iotkit/generator/factory/YmlPropertySourceFactory.java

@@ -0,0 +1,32 @@
+package cc.iotkit.generator.factory;
+
+
+import cc.iotkit.common.utils.StringUtils;
+import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
+import org.springframework.core.env.PropertiesPropertySource;
+import org.springframework.core.env.PropertySource;
+import org.springframework.core.io.support.DefaultPropertySourceFactory;
+import org.springframework.core.io.support.EncodedResource;
+
+import java.io.IOException;
+
+/**
+ * yml 配置源工厂
+ *
+ * @author Lion Li
+ */
+public class YmlPropertySourceFactory extends DefaultPropertySourceFactory {
+
+    @Override
+    public PropertySource<?> createPropertySource(String name, EncodedResource resource) throws IOException {
+        String sourceName = resource.getResource().getFilename();
+        if (StringUtils.isNotBlank(sourceName) && StringUtils.endsWithAny(sourceName, ".yml", ".yaml")) {
+            YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
+            factory.setResources(resource.getResource());
+            factory.afterPropertiesSet();
+            return new PropertiesPropertySource(sourceName, factory.getObject());
+        }
+        return super.createPropertySource(name, resource);
+    }
+
+}

+ 7 - 2
iot-module/iot-generator/src/main/java/cc/iotkit/generator/mapper/GenTableMapper.java

@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import cc.iotkit.generator.domain.GenTable;
 import org.apache.ibatis.annotations.Param;
 
+import java.util.Collection;
 import java.util.List;
 
 /**
@@ -14,7 +15,7 @@ import java.util.List;
  *
  * @author Lion Li
  */
-@InterceptorIgnore(dataPermission = "true", tenantLine = "true")
+@InterceptorIgnore( tenantLine = "true")
 public interface GenTableMapper extends BaseMapperPlus<GenTable, GenTable> {
 
     /**
@@ -23,6 +24,7 @@ public interface GenTableMapper extends BaseMapperPlus<GenTable, GenTable> {
      * @param genTable 查询条件
      * @return 数据库表集合
      */
+    @InterceptorIgnore( tenantLine = "true")
     Page<GenTable> selectPageDbTableList(@Param("page") Page<GenTable> page, @Param("genTable") GenTable genTable);
 
     /**
@@ -31,7 +33,7 @@ public interface GenTableMapper extends BaseMapperPlus<GenTable, GenTable> {
      * @param tableNames 表名称组
      * @return 数据库表集合
      */
-    List<GenTable> selectDbTableListByNames(String[] tableNames);
+    List<GenTable> selectDbTableListByNames(Collection<String> tableNames);
 
     /**
      * 查询所有表信息
@@ -56,4 +58,7 @@ public interface GenTableMapper extends BaseMapperPlus<GenTable, GenTable> {
      */
     GenTable selectGenTableByName(String tableName);
 
+    List<String> selectTableNameList(String dataName);
+
+
 }

+ 21 - 16
iot-module/iot-generator/src/main/java/cc/iotkit/generator/service/GenTableServiceImpl.java

@@ -1,5 +1,6 @@
 package cc.iotkit.generator.service;
 
+import cc.iotkit.common.api.PageRequest;
 import cc.iotkit.common.api.Paging;
 import cc.iotkit.common.constant.Constants;
 import cc.iotkit.common.exception.BizException;
@@ -7,6 +8,8 @@ import cc.iotkit.common.utils.JsonUtils;
 import cc.iotkit.common.utils.StreamUtils;
 import cc.iotkit.common.utils.StringUtils;
 import cc.iotkit.common.utils.file.FileUtils;
+import cc.iotkit.generator.core.DbIdGenerator;
+import cc.iotkit.generator.core.PageBuilder;
 import cc.iotkit.generator.core.PageQuery;
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.io.IoUtil;
@@ -15,7 +18,6 @@ import cn.hutool.core.util.ObjectUtil;
 import com.baomidou.dynamic.datasource.annotation.DS;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 
@@ -59,7 +61,7 @@ public class GenTableServiceImpl implements IGenTableService {
 
     private final GenTableMapper baseMapper;
     private final GenTableColumnMapper genTableColumnMapper;
-    private final IdentifierGenerator identifierGenerator;
+    private final DbIdGenerator identifierGenerator;
 
     /**
      * 查询业务字段列表
@@ -70,8 +72,8 @@ public class GenTableServiceImpl implements IGenTableService {
     @Override
     public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId) {
         return genTableColumnMapper.selectList(new LambdaQueryWrapper<GenTableColumn>()
-            .eq(GenTableColumn::getTableId, tableId)
-            .orderByAsc(GenTableColumn::getSort));
+                .eq(GenTableColumn::getTableId, tableId)
+                .orderByAsc(GenTableColumn::getSort));
     }
 
     /**
@@ -88,8 +90,8 @@ public class GenTableServiceImpl implements IGenTableService {
     }
 
     @Override
-    public Paging<GenTable> selectPageGenTableList(GenTable genTable, PageQuery pageQuery) {
-        Page<GenTable> page = baseMapper.selectPage(pageQuery.build(), this.buildGenTableQueryWrapper(genTable));
+    public Paging<GenTable> selectPageGenTableList(  PageRequest<GenTable> pageQuery) {
+        Page<GenTable> page = baseMapper.selectPage(PageBuilder.build(pageQuery), this.buildGenTableQueryWrapper(pageQuery.getData()));
         return new Paging<>(page.getTotal(), page.getRecords());
     }
 
@@ -98,15 +100,18 @@ public class GenTableServiceImpl implements IGenTableService {
         QueryWrapper<GenTable> wrapper = Wrappers.query();
         wrapper.like(StringUtils.isNotBlank(genTable.getTableName()), "lower(table_name)", StringUtils.lowerCase(genTable.getTableName()))
             .like(StringUtils.isNotBlank(genTable.getTableComment()), "lower(table_comment)", StringUtils.lowerCase(genTable.getTableComment()))
-            .between(params.get("beginTime") != null && params.get("endTime") != null,
+            .between(StringUtils.isNotBlank((CharSequence) params.get("beginTime"))  && StringUtils.isNotBlank((CharSequence) params.get("endTime")),
                 "create_time", params.get("beginTime"), params.get("endTime"));
         return wrapper;
     }
 
 
     @Override
-    public Paging<GenTable> selectPageDbTableList(GenTable genTable, PageQuery pageQuery) {
-        Page<GenTable> page = baseMapper.selectPageDbTableList(pageQuery.build(), genTable);
+    public Paging<GenTable> selectPageDbTableList(PageRequest<GenTable> pageQuery) {
+        GenTable genTable = pageQuery.getData();
+        genTable.getParams().put("genTableNames",baseMapper.selectTableNameList(genTable.getDataName()));
+
+        Page<GenTable> page = baseMapper.selectPageDbTableList(PageBuilder.build(pageQuery), genTable);
         return new Paging<>(page.getTotal(), page.getRecords());
     }
 
@@ -117,7 +122,7 @@ public class GenTableServiceImpl implements IGenTableService {
      * @return 数据库表集合
      */
     @Override
-    public List<GenTable> selectDbTableListByNames(String[] tableNames) {
+    public List<GenTable> selectDbTableListByNames(Collection<String> tableNames) {
         return baseMapper.selectDbTableListByNames(tableNames);
     }
 
@@ -158,10 +163,10 @@ public class GenTableServiceImpl implements IGenTableService {
      */
     @Transactional(rollbackFor = Exception.class)
     @Override
-    public void deleteGenTableByIds(Long[] tableIds) {
-        List<Long> ids = Arrays.asList(tableIds);
-        baseMapper.deleteBatchIds(ids);
-        genTableColumnMapper.delete(new LambdaQueryWrapper<GenTableColumn>().in(GenTableColumn::getTableId, ids));
+    public void deleteGenTableByIds(Collection<Long> tableIds) {
+
+        baseMapper.deleteBatchIds(tableIds);
+        genTableColumnMapper.delete(new LambdaQueryWrapper<GenTableColumn>().in(GenTableColumn::getTableId, tableIds));
     }
 
     /**
@@ -209,7 +214,7 @@ public class GenTableServiceImpl implements IGenTableService {
         GenTable table = baseMapper.selectGenTableById(tableId);
         List<Long> menuIds = new ArrayList<>();
         for (int i = 0; i < 6; i++) {
-            menuIds.add(identifierGenerator.nextId(null).longValue());
+            menuIds.add((Long) identifierGenerator.nextId(null));
         }
         table.setMenuIds(menuIds);
         // 设置主键列信息
@@ -353,7 +358,7 @@ public class GenTableServiceImpl implements IGenTableService {
         GenTable table = baseMapper.selectGenTableByName(tableName);
         List<Long> menuIds = new ArrayList<>();
         for (int i = 0; i < 6; i++) {
-            menuIds.add(identifierGenerator.nextId(null).longValue());
+            menuIds.add((Long) identifierGenerator.nextId(null));
         }
         table.setMenuIds(menuIds);
         // 设置主键列信息

+ 7 - 6
iot-module/iot-generator/src/main/java/cc/iotkit/generator/service/IGenTableService.java

@@ -2,11 +2,13 @@ package cc.iotkit.generator.service;
 
 
 
+import cc.iotkit.common.api.PageRequest;
 import cc.iotkit.common.api.Paging;
 import cc.iotkit.generator.core.PageQuery;
 import cc.iotkit.generator.domain.GenTable;
 import cc.iotkit.generator.domain.GenTableColumn;
 
+import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 
@@ -28,18 +30,17 @@ public interface IGenTableService {
     /**
      * 查询业务列表
      *
-     * @param genTable 业务信息
+     *
      * @return 业务集合
      */
-    Paging<GenTable> selectPageGenTableList(GenTable genTable, PageQuery pageQuery);
+    Paging<GenTable> selectPageGenTableList(PageRequest<GenTable> pageQuery);
 
     /**
      * 查询据库列表
      *
-     * @param genTable 业务信息
      * @return 数据库表集合
      */
-    Paging<GenTable> selectPageDbTableList(GenTable genTable, PageQuery pageQuery);
+    Paging<GenTable> selectPageDbTableList(PageRequest<GenTable>  pageQuery);
 
     /**
      * 查询据库列表
@@ -47,7 +48,7 @@ public interface IGenTableService {
      * @param tableNames 表名称组
      * @return 数据库表集合
      */
-    List<GenTable> selectDbTableListByNames(String[] tableNames);
+    List<GenTable> selectDbTableListByNames(Collection<String> tableNames);
 
     /**
      * 查询所有表信息
@@ -78,7 +79,7 @@ public interface IGenTableService {
      * @param tableIds 需要删除的表数据ID
      * @return 结果
      */
-    void deleteGenTableByIds(Long[] tableIds);
+    void deleteGenTableByIds(Collection<Long> tableIds);
 
     /**
      * 导入表结构

+ 1 - 0
iot-module/iot-generator/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports

@@ -0,0 +1 @@
+cc.iotkit.generator.config.MybatisPlusConfig

+ 33 - 0
iot-module/iot-generator/src/main/resources/common-mybatis.yml

@@ -0,0 +1,33 @@
+# 内置配置 不允许修改 如需修改请在 nacos 上写相同配置覆盖
+# MyBatisPlus配置
+# https://baomidou.com/config/
+mybatis-plus:
+  # 启动时是否检查 MyBatis XML 文件的存在,默认不检查
+  checkConfigLocation: false
+  configuration:
+    # 自动驼峰命名规则(camel case)映射
+    mapUnderscoreToCamelCase: true
+    # MyBatis 自动映射策略
+    # NONE:不启用 PARTIAL:只对非嵌套 resultMap 自动映射 FULL:对所有 resultMap 自动映射
+    autoMappingBehavior: FULL
+    # MyBatis 自动映射时未知列或未知属性处理策
+    # NONE:不做处理 WARNING:打印相关警告 FAILING:抛出异常和详细信息
+    autoMappingUnknownColumnBehavior: NONE
+    # 更详细的日志输出 会有性能损耗 org.apache.ibatis.logging.stdout.StdOutImpl
+    # 关闭日志记录 (可单纯使用 p6spy 分析) org.apache.ibatis.logging.nologging.NoLoggingImpl
+    # 默认日志输出 org.apache.ibatis.logging.slf4j.Slf4jImpl
+    logImpl: org.apache.ibatis.logging.nologging.NoLoggingImpl
+  global-config:
+    # 是否打印 Logo banner
+    banner: true
+    dbConfig:
+      # 主键类型
+      # AUTO 自增 NONE 空 INPUT 用户输入 ASSIGN_ID 雪花 ASSIGN_UUID 唯一 UUID
+      idType: ASSIGN_ID
+      # 逻辑已删除值(框架表均使用此值 禁止随意修改)
+      logicDeleteValue: 2
+      # 逻辑未删除值
+      logicNotDeleteValue: 0
+      insertStrategy: NOT_NULL
+      updateStrategy: NOT_NULL
+      whereStrategy: NOT_NULL

+ 16 - 4
iot-module/iot-generator/src/main/resources/mapper/generator/GenTableColumnMapper.xml

@@ -8,7 +8,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </resultMap>
 
     <select id="selectDbTableColumnsByName" parameterType="String" resultMap="GenTableColumnResult">
-        <if test="@cc.iotkit.common.mybatis.helper.DataBaseHelper@isMySql()">
+        <if test="@cc.iotkit.generator.core.DataBaseHelper@isMySql()">
             select column_name,
                    (case when (is_nullable = 'no' <![CDATA[ && ]]> column_key != 'PRI') then '1' else null end) as is_required,
                    (case when column_key = 'PRI' then '1' else '0' end) as is_pk,
@@ -19,7 +19,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             from information_schema.columns where table_schema = (select database()) and table_name = (#{tableName})
             order by ordinal_position
         </if>
-        <if test="@cc.iotkit.common.mybatis.helper.DataBaseHelper@isOracle()">
+        <if test="@cc.iotkit.generator.core.DataBaseHelper@isH2()">
+            select column_name,
+--             (case when (is_nullable = 'no' <![CDATA[ && ]]> column_key != 'PRI') then '1' else null end) as is_required,
+            (case when (is_nullable = 'no' ) then '1' else null end) as is_required,
+--             (case when column_key = 'PRI' then '1' else '0' end) as is_pk,
+            ordinal_position as sort
+--             column_comment,
+--             (case when extra = 'auto_increment' then '1' else '0' end) as is_increment,
+--             column_type
+            from information_schema.columns where table_name = (#{tableName})
+            order by ordinal_position
+        </if>
+        <if test="@cc.iotkit.generator.core.DataBaseHelper@isOracle()">
             select lower(temp.column_name) as column_name,
                     (case when (temp.nullable = 'N'  and  temp.constraint_type != 'P') then '1' else null end) as is_required,
                     (case when temp.constraint_type = 'P' then '1' else '0' end) as is_pk,
@@ -39,7 +51,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             WHERE temp.row_flg = 1
             ORDER BY temp.column_id
         </if>
-        <if test="@cc.iotkit.common.mybatis.helper.DataBaseHelper@isPostgerSql()">
+        <if test="@cc.iotkit.generator.core.DataBaseHelper@isPostgerSql()">
             SELECT column_name, is_required, is_pk, sort, column_comment, is_increment, column_type
             FROM (
                 SELECT c.relname AS table_name,
@@ -73,7 +85,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             WHERE table_name = (#{tableName})
                 AND column_type <![CDATA[ <> ]]> '-'
         </if>
-        <if test="@cc.iotkit.common.mybatis.helper.DataBaseHelper@isSqlServer()">
+        <if test="@cc.iotkit.generator.core.DataBaseHelper@isSqlServer()">
             SELECT
                 cast(A.NAME as nvarchar) as column_name,
                 cast(B.NAME as nvarchar) + (case when B.NAME = 'numeric' then '(' + cast(A.prec as nvarchar) + ',' + cast(A.scale as nvarchar) + ')' else '' end) as column_type,

+ 181 - 92
iot-module/iot-generator/src/main/resources/mapper/generator/GenTableMapper.xml

@@ -1,26 +1,71 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <!DOCTYPE mapper
-PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
-"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="cc.iotkit.generator.mapper.GenTableMapper">
 
     <!-- 多结构嵌套自动映射需带上每个实体的主键id 否则映射会失败 -->
     <resultMap type="cc.iotkit.generator.domain.GenTable" id="GenTableResult">
-        <id property="tableId" column="table_id" />
-        <collection property="columns" javaType="java.util.List" resultMap="GenTableColumnResult" />
+        <id     property="tableId"        column="table_id"          />
+        <result property="tableName"      column="table_name"        />
+        <result property="tableComment"   column="table_comment"     />
+        <result property="subTableName"   column="sub_table_name"    />
+        <result property="subTableFkName" column="sub_table_fk_name" />
+        <result property="className"      column="class_name"        />
+        <result property="tplCategory"    column="tpl_category"      />
+        <result property="packageName"    column="package_name"      />
+        <result property="moduleName"     column="module_name"       />
+        <result property="businessName"   column="business_name"     />
+        <result property="functionName"   column="function_name"     />
+        <result property="functionAuthor" column="function_author"   />
+        <result property="genType"        column="gen_type"          />
+        <result property="genPath"        column="gen_path"          />
+        <result property="options"        column="options"           />
+        <result property="createBy"       column="create_by"         />
+        <result property="createTime"     column="create_time"       />
+        <result property="updateBy"       column="update_by"         />
+        <result property="updateTime"     column="update_time"       />
+        <result property="remark"         column="remark"            />
+        <collection  property="columns"  javaType="java.util.List"  resultMap="GenTableColumnResult" />
     </resultMap>
 
     <resultMap type="cc.iotkit.generator.domain.GenTableColumn" id="GenTableColumnResult">
-        <id property="columnId" column="column_id"/>
+        <id     property="columnId"       column="column_id"      />
+        <result property="tableId"        column="table_id"       />
+        <result property="columnName"     column="column_name"    />
+        <result property="columnComment"  column="column_comment" />
+        <result property="columnType"     column="column_type"    />
+        <result property="javaType"       column="java_type"      />
+        <result property="javaField"      column="java_field"     />
+        <result property="isPk"           column="is_pk"          />
+        <result property="isIncrement"    column="is_increment"   />
+        <result property="isRequired"     column="is_required"    />
+        <result property="isInsert"       column="is_insert"      />
+        <result property="isEdit"         column="is_edit"        />
+        <result property="isList"         column="is_list"        />
+        <result property="isQuery"        column="is_query"       />
+        <result property="queryType"      column="query_type"     />
+        <result property="htmlType"       column="html_type"      />
+        <result property="dictType"       column="dict_type"      />
+        <result property="sort"           column="sort"           />
+        <result property="createBy"       column="create_by"      />
+        <result property="createTime"     column="create_time"    />
+        <result property="updateBy"       column="update_by"      />
+        <result property="updateTime"     column="update_time"    />
     </resultMap>
 
     <select id="selectPageDbTableList" resultMap="GenTableResult">
-        <if test="@cc.iotkit.common.mybatis.helper.DataBaseHelper@isMySql()">
+        <if test="@cc.iotkit.generator.core.DataBaseHelper@isMySql()">
             select table_name, table_comment, create_time, update_time
             from information_schema.tables
             where table_schema = (select database())
-            AND table_name NOT LIKE 'xxl_job_%' AND table_name NOT LIKE 'gen_%'
-            AND table_name NOT IN (select table_name from gen_table)
+            AND table_name NOT LIKE 'pj_%' AND table_name NOT LIKE 'gen_%'
+            <if test="genTable.params.genTableNames != null and genTable.params.genTableNames.size > 0">
+                AND table_name NOT IN
+                <foreach collection="genTable.params.genTableNames" open="(" close=")" separator="," item="item">
+                    #{item}
+                </foreach>
+            </if>
             <if test="genTable.tableName != null and genTable.tableName != ''">
                 AND lower(table_name) like lower(concat('%', #{genTable.tableName}, '%'))
             </if>
@@ -29,14 +74,38 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             </if>
             order by create_time desc
         </if>
-        <if test="@cc.iotkit.common.mybatis.helper.DataBaseHelper@isOracle()">
+        <if test="@cc.iotkit.generator.core.DataBaseHelper@isH2()">
+            select table_name
+            from information_schema.tables
+            where
+             table_name NOT LIKE 'pj_%' AND table_name NOT LIKE 'gen_%'
+            <if test="genTable.params.genTableNames != null and genTable.params.genTableNames.size > 0">
+                AND table_name NOT IN
+                <foreach collection="genTable.params.genTableNames" open="(" close=")" separator="," item="item">
+                    #{item}
+                </foreach>
+            </if>
+            <if test="genTable.tableName != null and genTable.tableName != ''">
+                AND lower(table_name) like lower(concat('%', #{genTable.tableName}, '%'))
+            </if>
+            <if test="genTable.tableComment != null and genTable.tableComment != ''">
+                AND lower(table_comment) like lower(concat('%', #{genTable.tableComment}, '%'))
+            </if>
+            order by table_name desc
+        </if>
+        <if test="@cc.iotkit.generator.core.DataBaseHelper@isOracle()">
             select lower(dt.table_name) as table_name, dtc.comments as table_comment, uo.created as create_time, uo.last_ddl_time as update_time
             from user_tables dt, user_tab_comments dtc, user_objects uo
             where dt.table_name = dtc.table_name
             and dt.table_name = uo.object_name
             and uo.object_type = 'TABLE'
-            AND dt.table_name NOT LIKE 'XXL_JOB_%' AND dt.table_name NOT LIKE 'GEN_%'
-            AND lower(dt.table_name) NOT IN (select table_name from gen_table)
+            AND dt.table_name NOT LIKE 'pj_%' AND dt.table_name NOT LIKE 'GEN_%'
+            <if test="genTable.params.genTableNames != null and genTable.params.genTableNames.size > 0">
+                AND lower(dt.table_name) NOT IN
+                <foreach collection="genTable.params.genTableNames" open="(" close=")" separator="," item="item">
+                    #{item}
+                </foreach>
+            </if>
             <if test="genTable.tableName != null and genTable.tableName != ''">
                 AND lower(dt.table_name) like lower(concat(concat('%', #{genTable.tableName}), '%'))
             </if>
@@ -45,22 +114,27 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             </if>
             order by create_time desc
         </if>
-        <if test="@cc.iotkit.common.mybatis.helper.DataBaseHelper@isPostgerSql()">
+        <if test="@cc.iotkit.generator.core.DataBaseHelper@isPostgerSql()">
             select table_name, table_comment, create_time, update_time
             from (
-                SELECT c.relname AS table_name,
-                        obj_description(c.oid) AS table_comment,
-                        CURRENT_TIMESTAMP AS create_time,
-                        CURRENT_TIMESTAMP AS update_time
-                FROM pg_class c
-                    LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
-                WHERE (c.relkind = ANY (ARRAY ['r'::"char", 'p'::"char"]))
-                    AND c.relname != 'spatial_%'::text
-                    AND n.nspname = 'public'::name
-                    AND n.nspname <![CDATA[ <> ]]> ''::name
+            SELECT c.relname AS table_name,
+            obj_description(c.oid) AS table_comment,
+            CURRENT_TIMESTAMP AS create_time,
+            CURRENT_TIMESTAMP AS update_time
+            FROM pg_class c
+            LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
+            WHERE (c.relkind = ANY (ARRAY ['r'::"char", 'p'::"char"]))
+            AND c.relname != 'spatial_%'::text
+            AND n.nspname = 'public'::name
+            AND n.nspname <![CDATA[ <> ]]> ''::name
             ) list_table
-            where table_name NOT LIKE 'xxl_job_%' AND table_name NOT LIKE 'gen_%'
-            AND table_name NOT IN (select table_name from gen_table)
+            where table_name NOT LIKE 'pj_%' AND table_name NOT LIKE 'gen_%'
+            <if test="genTable.params.genTableNames != null and genTable.params.genTableNames.size > 0">
+                AND table_name NOT IN
+                <foreach collection="genTable.params.genTableNames" open="(" close=")" separator="," item="item">
+                    #{item}
+                </foreach>
+            </if>
             <if test="genTable.tableName != null and genTable.tableName != ''">
                 AND lower(table_name) like lower(concat('%', #{genTable.tableName}, '%'))
             </if>
@@ -69,16 +143,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             </if>
             order by create_time desc
         </if>
-        <if test="@cc.iotkit.common.mybatis.helper.DataBaseHelper@isSqlServer()">
+        <if test="@cc.iotkit.generator.core.DataBaseHelper@isSqlServer()">
             SELECT cast(D.NAME as nvarchar) as table_name,
-                   cast(F.VALUE as nvarchar) as table_comment,
-                   crdate as create_time,
-                   refdate as update_time
+            cast(F.VALUE as nvarchar) as table_comment,
+            crdate as create_time,
+            refdate as update_time
             FROM SYSOBJECTS D
-                INNER JOIN SYS.EXTENDED_PROPERTIES F ON D.ID = F.MAJOR_ID
-                    AND F.MINOR_ID = 0 AND D.XTYPE = 'U' AND D.NAME != 'DTPROPERTIES'
-                    AND D.NAME NOT LIKE 'xxl_job_%' AND D.NAME NOT LIKE 'gen_%'
-                    AND D.NAME NOT IN (select table_name from gen_table)
+            INNER JOIN SYS.EXTENDED_PROPERTIES F ON D.ID = F.MAJOR_ID
+            AND F.MINOR_ID = 0 AND D.XTYPE = 'U' AND D.NAME != 'DTPROPERTIES'
+            AND D.NAME NOT LIKE 'pj_%' AND D.NAME NOT LIKE 'gen_%'
+            <if test="genTable.params.genTableNames != null and genTable.params.genTableNames.size > 0">
+                AND D.NAME NOT IN
+                <foreach collection="genTable.params.genTableNames" open="(" close=")" separator="," item="item">
+                    #{item}
+                </foreach>
+            </if>
             <if test="genTable.tableName != null and genTable.tableName != ''">
                 AND lower(D.NAME) like lower(concat(N'%', N'${genTable.tableName}', N'%'))
             </if>
@@ -90,131 +169,141 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </select>
 
     <select id="selectDbTableListByNames" resultMap="GenTableResult">
-        <if test="@cc.iotkit.common.mybatis.helper.DataBaseHelper@isMySql()">
+        <if test="@cc.iotkit.generator.core.DataBaseHelper@isMySql()">
             select table_name, table_comment, create_time, update_time from information_schema.tables
-            where table_name NOT LIKE 'xxl_job_%' and table_name NOT LIKE 'gen_%' and table_schema = (select database())
+            where table_name NOT LIKE 'pj_%' and table_name NOT LIKE 'gen_%' and table_schema = (select database())
+            and table_name in
+            <foreach collection="list" item="name" open="(" separator="," close=")">
+                #{name}
+            </foreach>
+        </if>
+        <if test="@cc.iotkit.generator.core.DataBaseHelper@isH2()">
+            select table_name from information_schema.tables
+            where table_name NOT LIKE 'pj_%' and table_name NOT LIKE 'gen_%'
             and table_name in
-            <foreach collection="array" item="name" open="(" separator="," close=")">
-                 #{name}
+            <foreach collection="list" item="name" open="(" separator="," close=")">
+                #{name}
             </foreach>
         </if>
-        <if test="@cc.iotkit.common.mybatis.helper.DataBaseHelper@isOracle()">
+        <if test="@cc.iotkit.generator.core.DataBaseHelper@isOracle()">
             select lower(dt.table_name) as table_name, dtc.comments as table_comment, uo.created as create_time, uo.last_ddl_time as update_time
             from user_tables dt, user_tab_comments dtc, user_objects uo
             where dt.table_name = dtc.table_name
             and dt.table_name = uo.object_name
             and uo.object_type = 'TABLE'
-            AND dt.table_name NOT LIKE 'XXL_JOB_%' AND dt.table_name NOT LIKE 'GEN_%'
-            AND dt.table_name NOT IN (select table_name from gen_table)
+            AND dt.table_name NOT LIKE 'pj_%' AND dt.table_name NOT LIKE 'GEN_%'
             and lower(dt.table_name) in
-            <foreach collection="array" item="name" open="(" separator="," close=")">
+            <foreach collection="list" item="name" open="(" separator="," close=")">
                 #{name}
             </foreach>
         </if>
-        <if test="@cc.iotkit.common.mybatis.helper.DataBaseHelper@isPostgerSql()">
+        <if test="@cc.iotkit.generator.core.DataBaseHelper@isPostgerSql()">
             select table_name, table_comment, create_time, update_time
             from (
-                SELECT c.relname AS table_name,
-                        obj_description(c.oid) AS table_comment,
-                        CURRENT_TIMESTAMP AS create_time,
-                        CURRENT_TIMESTAMP AS update_time
-                FROM pg_class c
-                    LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
-                WHERE (c.relkind = ANY (ARRAY ['r'::"char", 'p'::"char"]))
-                    AND c.relname != 'spatial_%'::text
-                    AND n.nspname = 'public'::name
-                    AND n.nspname <![CDATA[ <> ]]> ''::name
+            SELECT c.relname AS table_name,
+            obj_description(c.oid) AS table_comment,
+            CURRENT_TIMESTAMP AS create_time,
+            CURRENT_TIMESTAMP AS update_time
+            FROM pg_class c
+            LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
+            WHERE (c.relkind = ANY (ARRAY ['r'::"char", 'p'::"char"]))
+            AND c.relname != 'spatial_%'::text
+            AND n.nspname = 'public'::name
+            AND n.nspname <![CDATA[ <> ]]> ''::name
             ) list_table
-            where table_name NOT LIKE 'xxl_job_%' and table_name NOT LIKE 'gen_%'
+            where table_name NOT LIKE 'pj_%' and table_name NOT LIKE 'gen_%'
             and table_name in
-            <foreach collection="array" item="name" open="(" separator="," close=")">
+            <foreach collection="list" item="name" open="(" separator="," close=")">
                 #{name}
             </foreach>
         </if>
-        <if test="@cc.iotkit.common.mybatis.helper.DataBaseHelper@isSqlServer()">
+        <if test="@cc.iotkit.generator.core.DataBaseHelper@isSqlServer()">
             SELECT cast(D.NAME as nvarchar) as table_name,
-                   cast(F.VALUE as nvarchar) as table_comment,
-                   crdate as create_time,
-                   refdate as update_time
+            cast(F.VALUE as nvarchar) as table_comment,
+            crdate as create_time,
+            refdate as update_time
             FROM SYSOBJECTS D
-                INNER JOIN SYS.EXTENDED_PROPERTIES F ON D.ID = F.MAJOR_ID
-                    AND F.MINOR_ID = 0 AND D.XTYPE = 'U' AND D.NAME != 'DTPROPERTIES'
-                    AND D.NAME NOT LIKE 'xxl_job_%' AND D.NAME NOT LIKE 'gen_%'
-                    AND D.NAME in
-            <foreach collection="array" item="name" open="(" separator="," close=")">
+            INNER JOIN SYS.EXTENDED_PROPERTIES F ON D.ID = F.MAJOR_ID
+            AND F.MINOR_ID = 0 AND D.XTYPE = 'U' AND D.NAME != 'DTPROPERTIES'
+            AND D.NAME NOT LIKE 'pj_%' AND D.NAME NOT LIKE 'gen_%'
+            AND D.NAME in
+            <foreach collection="list" item="name" open="(" separator="," close=")">
                 #{name}
             </foreach>
         </if>
     </select>
 
     <select id="selectTableByName" parameterType="String" resultMap="GenTableResult">
-        <if test="@cc.iotkit.common.mybatis.helper.DataBaseHelper@isMySql()">
+        <if test="@cc.iotkit.generator.core.DataBaseHelper@isMySql()">
             select table_name, table_comment, create_time, update_time from information_schema.tables
-            where table_name NOT LIKE 'xxl_job_%' and table_name NOT LIKE 'gen_%' and table_schema = (select database())
+            where table_name NOT LIKE 'pj_%' and table_name NOT LIKE 'gen_%' and table_schema = (select database())
             and table_name = #{tableName}
         </if>
-        <if test="@cc.iotkit.common.mybatis.helper.DataBaseHelper@isOracle()">
+        <if test="@cc.iotkit.generator.core.DataBaseHelper@isOracle()">
             select lower(dt.table_name) as table_name, dtc.comments as table_comment, uo.created as create_time, uo.last_ddl_time as update_time
             from user_tables dt, user_tab_comments dtc, user_objects uo
             where dt.table_name = dtc.table_name
             and dt.table_name = uo.object_name
             and uo.object_type = 'TABLE'
-            AND dt.table_name NOT LIKE 'XXL_JOB_%' AND dt.table_name NOT LIKE 'GEN_%'
+            AND dt.table_name NOT LIKE 'pj_%' AND dt.table_name NOT LIKE 'GEN_%'
             AND dt.table_name NOT IN (select table_name from gen_table)
             and lower(dt.table_name) = #{tableName}
         </if>
-        <if test="@cc.iotkit.common.mybatis.helper.DataBaseHelper@isPostgerSql()">
+        <if test="@cc.iotkit.generator.core.DataBaseHelper@isPostgerSql()">
             select table_name, table_comment, create_time, update_time
             from (
-                SELECT c.relname AS table_name,
-                        obj_description(c.oid) AS table_comment,
-                        CURRENT_TIMESTAMP AS create_time,
-                        CURRENT_TIMESTAMP AS update_time
-                FROM pg_class c
-                    LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
-                WHERE (c.relkind = ANY (ARRAY ['r'::"char", 'p'::"char"]))
-                    AND c.relname != 'spatial_%'::text
-                    AND n.nspname = 'public'::name
-                    AND n.nspname <![CDATA[ <> ]]> ''::name
+            SELECT c.relname AS table_name,
+            obj_description(c.oid) AS table_comment,
+            CURRENT_TIMESTAMP AS create_time,
+            CURRENT_TIMESTAMP AS update_time
+            FROM pg_class c
+            LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
+            WHERE (c.relkind = ANY (ARRAY ['r'::"char", 'p'::"char"]))
+            AND c.relname != 'spatial_%'::text
+            AND n.nspname = 'public'::name
+            AND n.nspname <![CDATA[ <> ]]> ''::name
             ) list_table
-            where table_name NOT LIKE 'xxl_job_%' and table_name NOT LIKE 'gen_%'
+            where table_name NOT LIKE 'pj_%' and table_name NOT LIKE 'gen_%'
             and table_name = #{tableName}
         </if>
-        <if test="@cc.iotkit.common.mybatis.helper.DataBaseHelper@isSqlServer()">
+        <if test="@cc.iotkit.generator.core.DataBaseHelper@isSqlServer()">
             SELECT cast(D.NAME as nvarchar) as table_name,
-                   cast(F.VALUE as nvarchar) as table_comment,
-                   crdate as create_time,
-                   refdate as update_time
+            cast(F.VALUE as nvarchar) as table_comment,
+            crdate as create_time,
+            refdate as update_time
             FROM SYSOBJECTS D
-                INNER JOIN SYS.EXTENDED_PROPERTIES F ON D.ID = F.MAJOR_ID
-                    AND F.MINOR_ID = 0 AND D.XTYPE = 'U' AND D.NAME != 'DTPROPERTIES'
-                    AND D.NAME NOT LIKE 'xxl_job_%' AND D.NAME NOT LIKE 'gen_%'
-                    AND D.NAME = #{tableName}
+            INNER JOIN SYS.EXTENDED_PROPERTIES F ON D.ID = F.MAJOR_ID
+            AND F.MINOR_ID = 0 AND D.XTYPE = 'U' AND D.NAME != 'DTPROPERTIES'
+            AND D.NAME NOT LIKE 'pj_%' AND D.NAME NOT LIKE 'gen_%'
+            AND D.NAME = #{tableName}
         </if>
     </select>
 
     <select id="selectGenTableById" parameterType="Long" resultMap="GenTableResult">
-        SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark,
+        SELECT t.table_id, t.data_name, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark,
                c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort
         FROM gen_table t
-             LEFT JOIN gen_table_column c ON t.table_id = c.table_id
+                 LEFT JOIN gen_table_column c ON t.table_id = c.table_id
         where t.table_id = #{tableId} order by c.sort
     </select>
 
     <select id="selectGenTableByName" parameterType="String" resultMap="GenTableResult">
-        SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark,
+        SELECT t.table_id, t.data_name, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark,
                c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort
         FROM gen_table t
-             LEFT JOIN gen_table_column c ON t.table_id = c.table_id
+                 LEFT JOIN gen_table_column c ON t.table_id = c.table_id
         where t.table_name = #{tableName} order by c.sort
     </select>
 
     <select id="selectGenTableAll" parameterType="String" resultMap="GenTableResult">
-        SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.options, t.remark,
+        SELECT t.table_id, t.data_name, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.options, t.remark,
                c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort
         FROM gen_table t
-             LEFT JOIN gen_table_column c ON t.table_id = c.table_id
+                 LEFT JOIN gen_table_column c ON t.table_id = c.table_id
         order by c.sort
     </select>
 
+    <select id="selectTableNameList" resultType="java.lang.String">
+        select table_name from gen_table where data_name = #{dataName,jdbcType=VARCHAR}
+    </select>
 </mapper>

+ 1 - 1
iot-module/pom.xml

@@ -17,7 +17,7 @@
         <module>iot-manager</module>
         <module>iot-rule-engine</module>
         <module>iot-message-notify</module>
-<!--        <module>iot-generator</module>-->
+        <module>iot-generator</module>
     </modules>
 
 

+ 4 - 0
iot-starter/pom.xml

@@ -158,6 +158,10 @@
       <groupId>cc.iotkit</groupId>
       <artifactId>iot-baetyl</artifactId>
     </dependency>
+    <dependency>
+      <groupId>cc.iotkit</groupId>
+      <artifactId>iot-generator</artifactId>
+    </dependency>
  <!--   <dependency>
       <groupId>cc.iotkit</groupId>
       <artifactId>iot-baetyl</artifactId>

+ 31 - 0
iot-starter/src/main/resources/application-mysql.yml

@@ -17,6 +17,37 @@ spring:
     password: 123456
     validationQuery: SELECT 1
     testOnBorrow: true
+
+    type: com.zaxxer.hikari.HikariDataSource
+    # 动态数据源文档 https://www.kancloud.cn/tracy5546/dynamic-datasource/content
+    dynamic:
+      hikari:
+        connection-timeout: 5000
+        idle-timeout: 30000 # 经过idle-timeout时间如果连接还处于空闲状态, 该连接会被回收
+        min-idle: 5 # 池中维护的最小空闲连接数, 默认为 10 个
+        max-pool-size: 16 # 池中最大连接数, 包括闲置和使用中的连接, 默认为 10 个
+        max-lifetime: 60000 # 如果一个连接超过了时长,且没有被使用, 连接会被回收
+        is-auto-commit: true
+      primary: master #设置默认的数据源或者数据源组,默认值即为master
+      strict: true #严格匹配数据源,默认false. true未匹配到指定数据源时抛异常,false使用默认数据源
+      datasource:
+        # 主库数据源
+        master:
+          type: ${spring.datasource.type}
+          driverClassName: com.mysql.cj.jdbc.Driver
+          # jdbc 所有参数配置参考 https://lionli.blog.csdn.net/article/details/122018562
+          # rewriteBatchedStatements=true 批处理优化 大幅提升批量插入更新删除性能(对数据库有性能损耗 使用批量操作应考虑性能问题)
+          url: jdbc:mysql://localhost:3306/iotkit?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true
+          username: root
+          password: 123456
+        # 从库数据源
+        slave:
+          lazy: true
+          type: ${spring.datasource.type}
+          driverClassName: com.mysql.cj.jdbc.Driver
+          url: jdbc:mysql://localhost:3306/iotkit?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true
+          username: root
+          password: 123456
   jpa:
     database: MySQL
     database-platform: org.hibernate.dialect.MySQL5InnoDBDialect

+ 54 - 2
iot-starter/src/main/resources/application.yml

@@ -17,12 +17,45 @@ spring:
     properties:
       hibernate:
         format_sql: true
-
+  sql:
+    init:
+      schema-locations: classpath:sql/schema.sql
+      mode: ALWAYS
   datasource:
     url: jdbc:h2:./data/iotkit;MODE=MySQL
     username: sa
     password: 123456
     driverClassName: org.h2.Driver
+    type: com.zaxxer.hikari.HikariDataSource
+    # 动态数据源文档 https://www.kancloud.cn/tracy5546/dynamic-datasource/content
+    dynamic:
+      hikari:
+        connection-timeout: 5000
+        idle-timeout: 30000 # 经过idle-timeout时间如果连接还处于空闲状态, 该连接会被回收
+        min-idle: 5 # 池中维护的最小空闲连接数, 默认为 10 个
+        max-pool-size: 16 # 池中最大连接数, 包括闲置和使用中的连接, 默认为 10 个
+        max-lifetime: 60000 # 如果一个连接超过了时长,且没有被使用, 连接会被回收
+        is-auto-commit: true
+      primary: master #设置默认的数据源或者数据源组,默认值即为master
+      strict: true #严格匹配数据源,默认false. true未匹配到指定数据源时抛异常,false使用默认数据源
+      datasource:
+        # 主库数据源
+        master:
+          type: ${spring.datasource.type}
+          driverClassName: org.h2.Driver
+          # jdbc 所有参数配置参考 https://lionli.blog.csdn.net/article/details/122018562
+          # rewriteBatchedStatements=true 批处理优化 大幅提升批量插入更新删除性能(对数据库有性能损耗 使用批量操作应考虑性能问题)
+          url: jdbc:h2:./data/iotkit;MODE=MySQL
+          username: sa
+          password: 123456
+        # 从库数据源
+        slave:
+          lazy: true
+          type: ${spring.datasource.type}
+          driverClassName: org.h2.Driver
+          url: jdbc:h2:./data/iotkit;MODE=MySQL
+          username: sa
+          password: 123456
 
   # 内置h2 web console设置
     platform: h2
@@ -84,6 +117,8 @@ spring:
   mvc:
     pathmatch:
       matching-strategy: ant_path_matcher
+#  profiles:
+#    active: mysql
 
 #application.yml中打开注释支持rocketMq作为消息总线,pom.xml中打开注释使用rocketmq消息总线
 #rocketmq:
@@ -162,4 +197,21 @@ oss:
   buckName: xxxx
 baetyl:
   api-type: feign
-  service-url: http://116.168.30.140:30004
+  service-url: http://116.168.30.140:30004
+
+# MyBatisPlus配置
+# https://baomidou.com/config/
+mybatis-plus:
+  # 不支持多包, 如有需要可在注解配置 或 提升扫包等级
+  # 例如 com.**.**.mapper
+  mapperPackage: cc.iotkit.**.mapper
+  # 对应的 XML 文件位置
+  mapperLocations: classpath*:mapper/**/*Mapper.xml
+  # 实体扫描,多个package用逗号或者分号分隔
+  typeAliasesPackage: cc.iotkit.**.domain
+  global-config:
+    dbConfig:
+      # 主键类型
+      # AUTO 自增 NONE 空 INPUT 用户输入 ASSIGN_ID 雪花 ASSIGN_UUID 唯一 UUID
+      # 如需改为自增 需要将数据库表全部设置为自增
+      idType: ASSIGN_ID

+ 60 - 0
iot-starter/src/main/resources/sql/schema.sql

@@ -0,0 +1,60 @@
+-- ----------------------------
+-- 18、代码生成业务表
+-- ----------------------------
+create table if not exists gen_table (
+                           table_id          bigint(20)      not null                   comment '编号',
+                           data_name         varchar(200)    default ''                 comment '数据源名称',
+                           table_name        varchar(200)    default ''                 comment '表名称',
+                           table_comment     varchar(500)    default ''                 comment '表描述',
+                           sub_table_name    varchar(64)     default null               comment '关联子表的表名',
+                           sub_table_fk_name varchar(64)     default null               comment '子表关联的外键名',
+                           class_name        varchar(100)    default ''                 comment '实体类名称',
+                           tpl_category      varchar(200)    default 'crud'             comment '使用的模板(crud单表操作 tree树表操作)',
+                           package_name      varchar(100)                               comment '生成包路径',
+                           module_name       varchar(30)                                comment '生成模块名',
+                           business_name     varchar(30)                                comment '生成业务名',
+                           function_name     varchar(50)                                comment '生成功能名',
+                           function_author   varchar(50)                                comment '生成功能作者',
+                           gen_type          char(1)         default '0'                comment '生成代码方式(0zip压缩包 1自定义路径)',
+                           gen_path          varchar(200)    default '/'                comment '生成路径(不填默认项目路径)',
+                           options           varchar(1000)                              comment '其它生成选项',
+                           create_dept       bigint(20)      default null               comment '创建部门',
+                           create_by         bigint(20)      default null               comment '创建者',
+                           create_time       datetime                                   comment '创建时间',
+                           update_by         bigint(20)      default null               comment '更新者',
+                           update_time       datetime                                   comment '更新时间',
+                           remark            varchar(500)    default null               comment '备注',
+                           primary key (table_id)
+) engine=innodb comment = '代码生成业务表';
+
+
+-- ----------------------------
+-- 19、代码生成业务表字段
+-- ----------------------------
+
+create table if not exists gen_table_column (
+                                  column_id         bigint(20)      not null                   comment '编号',
+                                  table_id          bigint(20)                                 comment '归属表编号',
+                                  column_name       varchar(200)                               comment '列名称',
+                                  column_comment    varchar(500)                               comment '列描述',
+                                  column_type       varchar(100)                               comment '列类型',
+                                  java_type         varchar(500)                               comment 'JAVA类型',
+                                  java_field        varchar(200)                               comment 'JAVA字段名',
+                                  is_pk             char(1)                                    comment '是否主键(1是)',
+                                  is_increment      char(1)                                    comment '是否自增(1是)',
+                                  is_required       char(1)                                    comment '是否必填(1是)',
+                                  is_insert         char(1)                                    comment '是否为插入字段(1是)',
+                                  is_edit           char(1)                                    comment '是否编辑字段(1是)',
+                                  is_list           char(1)                                    comment '是否列表字段(1是)',
+                                  is_query          char(1)                                    comment '是否查询字段(1是)',
+                                  query_type        varchar(200)    default 'EQ'               comment '查询方式(等于、不等于、大于、小于、范围)',
+                                  html_type         varchar(200)                               comment '显示类型(文本框、文本域、下拉框、复选框、单选框、日期控件)',
+                                  dict_type         varchar(200)    default ''                 comment '字典类型',
+                                  sort              int                                        comment '排序',
+                                  create_dept       bigint(20)      default null               comment '创建部门',
+                                  create_by         bigint(20)      default null               comment '创建者',
+                                  create_time       datetime                                   comment '创建时间',
+                                  update_by         bigint(20)      default null               comment '更新者',
+                                  update_time       datetime                                   comment '更新时间',
+                                  primary key (column_id)
+) engine=innodb comment = '代码生成业务表字段';

+ 5 - 0
pom.xml

@@ -539,6 +539,11 @@
                 <version>${project.version}</version>
             </dependency>
 
+            <dependency>
+                <groupId>cc.iotkit</groupId>
+                <artifactId>iot-generator</artifactId>
+                <version>${project.version}</version>
+            </dependency>
             <dependency>
                 <groupId>cc.iotkit</groupId>
                 <artifactId>iot-virtual-device</artifactId>