فهرست منبع

fix: 代码生成器

jay 2 سال پیش
والد
کامیت
86584d1fa3

+ 4 - 1
iot-module/iot-generator/pom.xml

@@ -36,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>

+ 3 - 1
iot-module/iot-generator/src/main/java/cc/iotkit/generator/config/MybatisPlusConfig.java

@@ -1,5 +1,6 @@
 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;
@@ -80,7 +81,8 @@ public class MybatisPlusConfig {
      */
     @Bean
     public IdentifierGenerator idGenerator() {
-        return new DefaultIdentifierGenerator(NetUtil.getLocalhost());
+        String hostAddress = NetUtil.getLocalhost().getHostAddress();
+        return new DbIdGenerator((short) ((short) hostAddress.hashCode()%64));
     }
 
     /**

+ 33 - 21
iot-module/iot-generator/src/main/java/cc/iotkit/generator/controller/GenController.java

@@ -2,6 +2,8 @@ package cc.iotkit.generator.controller;
 
 import cc.iotkit.common.api.PageRequest;
 import cc.iotkit.common.api.Paging;
+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;
 
@@ -13,6 +15,7 @@ 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.*;
@@ -50,11 +53,12 @@ public class GenController extends BaseController {
     /**
      * 修改代码生成业务
      *
-     * @param tableId 表ID
      */
 //    @SaCheckPermission("tool:gen:query")
-    @PostMapping(value = "/{tableId}")
-    public Map<String, Object> getInfo(@PathVariable Long tableId) {
+    @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);
@@ -69,6 +73,7 @@ public class GenController extends BaseController {
      * 查询数据库列表
      */
 //    @SaCheckPermission("tool:gen:list")
+    @ApiOperation(value = "查询数据库列表", notes = "查询数据库列表")
     @PostMapping("/db/list")
     public Paging<GenTable> dataList(@RequestBody @Validated PageRequest<GenTable> pageQuery) {
         return genTableService.selectPageDbTableList( pageQuery);
@@ -80,6 +85,7 @@ public class GenController extends BaseController {
      * @param tableId 表ID
      */
 //    @SaCheckPermission("tool:gen:list")
+    @ApiOperation(value = "查询数据表字段列表", notes = "查询数据表字段列表")
     @PostMapping(value = "/column/{tableId}")
     public Paging<GenTableColumn> columnList(Long tableId) {
 
@@ -91,15 +97,16 @@ public class GenController extends BaseController {
     /**
      * 导入表结构(保存)
      *
-     * @param tables 表名串
      */
 //    @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;
     }
@@ -108,9 +115,11 @@ public class GenController extends BaseController {
      * 修改保存代码生成业务
      */
 //    @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;
@@ -119,25 +128,26 @@ public class GenController extends BaseController {
     /**
      * 删除代码生成
      *
-     * @param tableIds 表ID串
+
      */
 //    @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);
+    @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;
     }
 
@@ -161,6 +171,7 @@ public class GenController extends BaseController {
      */
 //    @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);
@@ -170,13 +181,13 @@ public class GenController extends BaseController {
     /**
      * 同步数据库
      *
-     * @param tableName 表名
      */
 //    @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 ;
     }
 
@@ -187,6 +198,7 @@ public class GenController extends BaseController {
      */
 //    @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);

+ 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();
+  }
+}

+ 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;
+
+
+}

+ 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);
+
+
 }

+ 15 - 12
iot-module/iot-generator/src/main/java/cc/iotkit/generator/service/GenTableServiceImpl.java

@@ -8,6 +8,7 @@ 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;
@@ -17,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;
 
@@ -61,7 +61,7 @@ public class GenTableServiceImpl implements IGenTableService {
 
     private final GenTableMapper baseMapper;
     private final GenTableColumnMapper genTableColumnMapper;
-    private final IdentifierGenerator identifierGenerator;
+    private final DbIdGenerator identifierGenerator;
 
     /**
      * 查询业务字段列表
@@ -72,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));
     }
 
     /**
@@ -108,7 +108,10 @@ public class GenTableServiceImpl implements IGenTableService {
 
     @Override
     public Paging<GenTable> selectPageDbTableList(PageRequest<GenTable> pageQuery) {
-        Page<GenTable> page = baseMapper.selectPageDbTableList(PageBuilder.build(pageQuery), pageQuery.getData());
+        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());
     }
 
@@ -119,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);
     }
 
@@ -160,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));
     }
 
     /**
@@ -211,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);
         // 设置主键列信息
@@ -355,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);
         // 设置主键列信息

+ 3 - 2
iot-module/iot-generator/src/main/java/cc/iotkit/generator/service/IGenTableService.java

@@ -8,6 +8,7 @@ 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;
 
@@ -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);
 
     /**
      * 导入表结构

+ 4 - 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,7 @@ 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@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 +39,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 +73,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,

+ 47 - 7
iot-module/iot-generator/src/main/resources/mapper/generator/GenTableMapper.xml

@@ -6,12 +6,52 @@
 
     <!-- 多结构嵌套自动映射需带上每个实体的主键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">
@@ -114,7 +154,7 @@
             select table_name, table_comment, create_time, update_time from information_schema.tables
             where table_name NOT LIKE 'pj_%' and table_name NOT LIKE 'gen_%' and table_schema = (select database())
             and table_name in
-            <foreach collection="array" item="name" open="(" separator="," close=")">
+            <foreach collection="list" item="name" open="(" separator="," close=")">
                 #{name}
             </foreach>
         </if>
@@ -126,7 +166,7 @@
             and uo.object_type = '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>
@@ -146,7 +186,7 @@
             ) list_table
             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>
@@ -160,7 +200,7 @@
             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="array" item="name" open="(" separator="," close=")">
+            <foreach collection="list" item="name" open="(" separator="," close=")">
                 #{name}
             </foreach>
         </if>

+ 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

+ 18 - 1
iot-starter/src/main/resources/application.yml

@@ -162,4 +162,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

+ 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>