Browse Source

添加代码生成模块代码

Administrator 4 years ago
parent
commit
119eabff99
22 changed files with 714 additions and 48 deletions
  1. 3 2
      boman-api/boman-api-gen/src/main/java/com/boman/gen/api/RemoteGenTableService.java
  2. 5 0
      boman-common/boman-common-core/src/main/java/com/boman/common/core/constant/UserConstants.java
  3. 2 0
      boman-common/boman-common-security/pom.xml
  4. 4 0
      boman-modules/boman-gen/src/main/java/com/boman/gen/controller/GenController.java
  5. 1 1
      boman-modules/boman-gen/src/main/java/com/boman/gen/controller/GenTableColumnController.java
  6. 63 0
      boman-modules/boman-gen/src/main/java/com/boman/gen/controller/TableSqlController.java
  7. 20 6
      boman-modules/boman-gen/src/main/java/com/boman/gen/domain/GenTable.java
  8. 53 0
      boman-modules/boman-gen/src/main/java/com/boman/gen/domain/GenTableColumn.java
  9. 51 0
      boman-modules/boman-gen/src/main/java/com/boman/gen/domain/GenTableRelation.java
  10. 66 0
      boman-modules/boman-gen/src/main/java/com/boman/gen/domain/TableSql.java
  11. 8 1
      boman-modules/boman-gen/src/main/java/com/boman/gen/mapper/GenTableColumnMapper.java
  12. 20 0
      boman-modules/boman-gen/src/main/java/com/boman/gen/mapper/TableSqlMapper.java
  13. 40 0
      boman-modules/boman-gen/src/main/java/com/boman/gen/service/GenTableColumnServiceImpl.java
  14. 35 2
      boman-modules/boman-gen/src/main/java/com/boman/gen/service/GenTableServiceImpl.java
  15. 8 1
      boman-modules/boman-gen/src/main/java/com/boman/gen/service/IGenTableColumnService.java
  16. 20 18
      boman-modules/boman-gen/src/main/java/com/boman/gen/service/IGenTableService.java
  17. 40 0
      boman-modules/boman-gen/src/main/java/com/boman/gen/service/ITableSqlService.java
  18. 151 0
      boman-modules/boman-gen/src/main/java/com/boman/gen/service/TableSqlServiceImpl.java
  19. 31 6
      boman-modules/boman-gen/src/main/resources/mapper/generator/GenTableColumnMapper.xml
  20. 8 4
      boman-modules/boman-gen/src/main/resources/mapper/generator/GenTableMapper.xml
  21. 24 7
      boman-modules/boman-gen/src/main/resources/mapper/generator/GenTableRelationMapper.xml
  22. 61 0
      boman-modules/boman-gen/src/main/resources/mapper/generator/TableSqlMapper.xml

+ 3 - 2
boman-api/boman-api-gen/src/main/java/com/boman/gen/api/RemoteGenTableService.java

@@ -1,10 +1,13 @@
 package com.boman.gen.api;
 
 import com.boman.common.core.constant.ServiceNameConstants;
+import com.boman.common.core.web.domain.AjaxResult;
+import com.boman.gen.domain.TableSql;
 import com.boman.gen.domain.GenTable;
 import org.springframework.cloud.openfeign.FeignClient;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
 
 /**
  * 生成代码模块,远程调用入口,如需其他接口,在此添加
@@ -24,6 +27,4 @@ public interface RemoteGenTableService {
      */
     @GetMapping(value = "/gen/table/{tableName}")
     GenTable getByTableName(@PathVariable("tableName") String tableName);
-
-
 }

+ 5 - 0
boman-common/boman-common-core/src/main/java/com/boman/common/core/constant/UserConstants.java

@@ -75,4 +75,9 @@ public class UserConstants
     public static final int PASSWORD_MIN_LENGTH = 5;
 
     public static final int PASSWORD_MAX_LENGTH = 20;
+
+    /**
+     * 是自增
+     */
+    public static final String INCREMENT = "1";
 }

+ 2 - 0
boman-common/boman-common-security/pom.xml

@@ -21,6 +21,8 @@
             <groupId>com.boman</groupId>
             <artifactId>boman-api-system</artifactId>
         </dependency>
+
+
         
         <!-- RuoYi Common Redis-->
         <dependency>

+ 4 - 0
boman-modules/boman-gen/src/main/java/com/boman/gen/controller/GenController.java

@@ -216,6 +216,10 @@ public class GenController extends BaseController {
      */
     @PostMapping("/addTable")
     public AjaxResult add(@Validated @RequestBody GenTable genTable) {
+        if (UserConstants.NOT_UNIQUE.equals(genTableService.checkTableNameUnique(genTable)))
+        {
+            return AjaxResult.error("新增表名'" + genTable.getTableName() + "'失败,表名已存在");
+        }
         return genTableService.insertGenTable(genTable);
     }
 }

+ 1 - 1
boman-modules/boman-gen/src/main/java/com/boman/gen/controller/GenTableColumnController.java

@@ -67,7 +67,7 @@ public class GenTableColumnController extends BaseController {
     @DeleteMapping("/{columnIds}")
     public AjaxResult remove(@PathVariable String columnIds)
     {
-        return toAjax(genTableColumnService.deleteGenTableColumnByIds(columnIds));
+        return toAjax(genTableColumnService.deleteGenTableColumnByColumnIds(columnIds));
     }
 
     /**

+ 63 - 0
boman-modules/boman-gen/src/main/java/com/boman/gen/controller/TableSqlController.java

@@ -0,0 +1,63 @@
+package com.boman.gen.controller;
+
+import com.boman.common.core.web.controller.BaseController;
+import com.boman.common.core.web.domain.AjaxResult;
+import com.boman.gen.domain.TableSql;
+import com.boman.gen.service.ITableSqlService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+/**
+ * @author tjf
+ * @Date: 2021/04/14/10:27
+ */
+@RequestMapping("/tableSql")
+@RestController
+public class TableSqlController extends BaseController {
+
+
+    @Autowired
+    private ITableSqlService tableSqlService;
+
+
+    /**
+     * @Description 新增建表sql语句
+     * @author tjf
+     * @Date 2021/3/24
+     */
+    @PostMapping
+    public AjaxResult add(@Validated @RequestBody TableSql tableSql) {
+        return tableSqlService.insertTableSql(tableSql);
+    }
+
+    /**
+     * @Description 刷新建表sql语句
+     * @author tjf
+     * @Date 2021/3/24
+     */
+    @PostMapping("/reload")
+    public AjaxResult reload(@Validated @RequestBody TableSql tableSql) {
+        return tableSqlService.reloadTableSql(tableSql);
+    }
+
+
+    /**
+     * 执行创建语句
+     * @param tableSql
+     * @return
+     */
+    @PostMapping("/implement")
+    public AjaxResult implementSql(@Validated @RequestBody TableSql tableSql) {
+        return tableSqlService.implementSql(tableSql);
+    }
+
+    /**
+     * 查询
+     */
+    @GetMapping(value = "/{id}")
+    public AjaxResult getInfo(@PathVariable Long id)
+    {
+        return tableSqlService.selectTableSqlByTableId(id);
+    }
+}

+ 20 - 6
boman-modules/boman-gen/src/main/java/com/boman/gen/domain/GenTable.java

@@ -35,30 +35,30 @@ public class GenTable extends BaseEntity
     private String subTableFkName;
 
     /** 实体类名称(首字母大写) */
-    @NotBlank(message = "实体类名称不能为空")
+    //@NotBlank(message = "实体类名称不能为空")
     private String className;
 
     /** 使用的模板(crud单表操作 tree树表操作 sub主子表操作) */
     private String tplCategory;
 
     /** 生成包路径 */
-    @NotBlank(message = "生成包路径不能为空")
+    //@NotBlank(message = "生成包路径不能为空")
     private String packageName;
 
     /** 生成模块名 */
-    @NotBlank(message = "生成模块名不能为空")
+    //@NotBlank(message = "生成模块名不能为空")
     private String moduleName;
 
     /** 生成业务名 */
-    @NotBlank(message = "生成业务名不能为空")
+    //@NotBlank(message = "生成业务名不能为空")
     private String businessName;
 
     /** 生成功能名 */
-    @NotBlank(message = "生成功能名不能为空")
+    //@NotBlank(message = "生成功能名不能为空")
     private String functionName;
 
     /** 生成作者 */
-    @NotBlank(message = "作者不能为空")
+    //@NotBlank(message = "作者不能为空")
     private String functionAuthor;
 
     /** 生成代码方式(0zip压缩包 1自定义路径) */
@@ -161,6 +161,20 @@ public class GenTable extends BaseEntity
     /** 上级菜单名称字段 */
     private String parentMenuName;
 
+
+    /**
+     * 对应表主键
+     */
+    private Long tablePrimaryKey;
+
+    public Long getTablePrimaryKey() {
+        return tablePrimaryKey;
+    }
+
+    public void setTablePrimaryKey(Long tablePrimaryKey) {
+        this.tablePrimaryKey = tablePrimaryKey;
+    }
+
     public String getRealTableName() {
         return realTableName;
     }

+ 53 - 0
boman-modules/boman-gen/src/main/java/com/boman/gen/domain/GenTableColumn.java

@@ -110,6 +110,59 @@ public class GenTableColumn extends BaseEntity
      */
     private String numColumns;
 
+    /**
+     * 字段翻译器
+     */
+    private String fieldTranslator;
+
+    /**
+     * 扩展属性
+     */
+    private String extendedAttributes;
+
+    /**
+     *是否输入 Y是
+     */
+    private String isIn;
+
+    /**
+     * 是否显示 Y是
+     */
+    private String isOut;
+
+
+    public String getFieldTranslator() {
+        return fieldTranslator;
+    }
+
+    public void setFieldTranslator(String fieldTranslator) {
+        this.fieldTranslator = fieldTranslator;
+    }
+
+    public String getExtendedAttributes() {
+        return extendedAttributes;
+    }
+
+    public void setExtendedAttributes(String extendedAttributes) {
+        this.extendedAttributes = extendedAttributes;
+    }
+
+    public String getIsIn() {
+        return isIn;
+    }
+
+    public void setIsIn(String isIn) {
+        this.isIn = isIn;
+    }
+
+    public String getIsOut() {
+        return isOut;
+    }
+
+    public void setIsOut(String isOut) {
+        this.isOut = isOut;
+    }
+
     public String getMask() {
         return mask;
     }

+ 51 - 0
boman-modules/boman-gen/src/main/java/com/boman/gen/domain/GenTableRelation.java

@@ -34,6 +34,16 @@ public class GenTableRelation extends BaseEntity {
      */
     private Long relationType;
 
+    /**
+     * 内嵌查询
+     */
+    private Long embedEdit;
+
+    /**
+     * 显示条件
+     */
+    private String displayConditions;
+
     /**
      * 排序
      */
@@ -43,6 +53,47 @@ public class GenTableRelation extends BaseEntity {
      * 是否删除(Y是)
      */
     private String isDel;
+    /**
+     * 字段名称
+     */
+    private String columnName;
+
+    /**
+     * 表名称
+     */
+    private String tableName;
+
+    public String getColumnName() {
+        return columnName;
+    }
+
+    public void setColumnName(String columnName) {
+        this.columnName = columnName;
+    }
+
+    public String getTableName() {
+        return tableName;
+    }
+
+    public void setTableName(String tableName) {
+        this.tableName = tableName;
+    }
+
+    public Long getEmbedEdit() {
+        return embedEdit;
+    }
+
+    public void setEmbedEdit(Long embedEdit) {
+        this.embedEdit = embedEdit;
+    }
+
+    public String getDisplayConditions() {
+        return displayConditions;
+    }
+
+    public void setDisplayConditions(String displayConditions) {
+        this.displayConditions = displayConditions;
+    }
 
     public Long getSort() {
         return sort;

+ 66 - 0
boman-modules/boman-gen/src/main/java/com/boman/gen/domain/TableSql.java

@@ -0,0 +1,66 @@
+package com.boman.gen.domain;
+
+import com.boman.common.core.web.domain.BaseEntity;
+
+/**
+ * @author tjf
+ * @Date: 2021/04/14/10:56
+ */
+public class TableSql extends BaseEntity {
+    private Long id;
+    private Long tableId;
+    private String createSql;
+    private String createLog;
+    private String isDel;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public Long getTableId() {
+        return tableId;
+    }
+
+    public void setTableId(Long tableId) {
+        this.tableId = tableId;
+    }
+
+    public String getCreateSql() {
+        return createSql;
+    }
+
+    public void setCreateSql(String createSql) {
+        this.createSql = createSql;
+    }
+
+    public String getCreateLog() {
+        return createLog;
+    }
+
+    public void setCreateLog(String createLog) {
+        this.createLog = createLog;
+    }
+
+    public String getIsDel() {
+        return isDel;
+    }
+
+    public void setIsDel(String isDel) {
+        this.isDel = isDel;
+    }
+
+    @Override
+    public String toString() {
+        return "TableSql{" +
+                "id=" + id +
+                ", tableId=" + tableId +
+                ", createSql='" + createSql + '\'' +
+                ", createLog='" + createLog + '\'' +
+                ", isDel='" + isDel + '\'' +
+                '}';
+    }
+}

+ 8 - 1
boman-modules/boman-gen/src/main/java/com/boman/gen/mapper/GenTableColumnMapper.java

@@ -69,11 +69,18 @@ public interface GenTableColumnMapper
     /**
      * 批量删除业务字段
      * 
-     * @param ids 需要删除的数据ID
+     * @param ids 需要删除的数据ID 表id
      * @return 结果
      */
     public int deleteGenTableColumnByIds(Long[] ids);
 
+    /**
+     * 批量删除业务字段
+     * @param ids 字段id
+     * @return
+     */
+    public int deleteGenTableColumnByColumnIds(Long[] ids);
+
 
 
     /**校验column_name是否重复

+ 20 - 0
boman-modules/boman-gen/src/main/java/com/boman/gen/mapper/TableSqlMapper.java

@@ -0,0 +1,20 @@
+package com.boman.gen.mapper;
+
+import com.boman.gen.domain.TableSql;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * @author tjf
+ * @Date: 2021/04/14/10:46
+ */
+@Mapper
+public interface TableSqlMapper {
+
+    public int insertTableSql(TableSql tableSql);
+
+
+    public int updateTableSql(TableSql tableSql);
+
+
+    public TableSql selectTableSqlByTableId(Long id);
+}

+ 40 - 0
boman-modules/boman-gen/src/main/java/com/boman/gen/service/GenTableColumnServiceImpl.java

@@ -2,9 +2,12 @@ package com.boman.gen.service;
 
 import java.util.Collections;
 import java.util.List;
+import java.util.concurrent.locks.Condition;
 
 import com.boman.common.core.constant.UserConstants;
 import com.boman.common.core.utils.StringUtils;
+import com.boman.gen.domain.GenTable;
+import com.boman.gen.mapper.GenTableMapper;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.boman.common.core.text.Convert;
@@ -20,6 +23,8 @@ import com.boman.gen.mapper.GenTableColumnMapper;
 public class GenTableColumnServiceImpl implements IGenTableColumnService {
     @Autowired
     private GenTableColumnMapper genTableColumnMapper;
+    @Autowired
+    private GenTableMapper genTableMapper;
 
     /**
      * 查询业务字段列表
@@ -76,9 +81,34 @@ public class GenTableColumnServiceImpl implements IGenTableColumnService {
      */
     @Override
     public int updateGenTableColumn(GenTableColumn genTableColumn) {
+        isAk(genTableColumn);
         return genTableColumnMapper.updateGenTableColumn(genTableColumn);
     }
 
+    /**
+     * 判断对象是否设置显示和输入字段
+     * @param genTableColumn
+     */
+    public void isAk(GenTableColumn genTableColumn) {
+        //是否是输入
+        String isIn = genTableColumn.getIsIn();
+        //是否是显示
+        String isOut = genTableColumn.getIsOut();
+        GenTable genTable = new GenTable();
+        if (UserConstants.YES.equals(isIn)){
+            genTable.setTableId(genTableColumn.getTableId());
+            genTable.setAkColumn(genTableColumn.getColumnId());
+        }
+        if (UserConstants.YES.equals(isOut)){
+            genTable.setTableId(genTableColumn.getTableId());
+            genTable.setDkColumn(genTableColumn.getColumnId());
+        }
+        if (genTable.getTableId() != null){
+            genTableMapper.updateGenTable(genTable);
+        }
+    }
+
+
     /**
      * 删除业务字段对象
      *
@@ -90,6 +120,16 @@ public class GenTableColumnServiceImpl implements IGenTableColumnService {
         return genTableColumnMapper.deleteGenTableColumnByIds(Convert.toLongArray(ids));
     }
 
+    /**
+     * 删除业务字段对象
+     * @param ids 字段id
+     * @return
+     */
+    @Override
+    public int deleteGenTableColumnByColumnIds(String ids) {
+        return genTableColumnMapper.deleteGenTableColumnByColumnIds(Convert.toLongArray(ids));
+    }
+
     /**
      * 校验column_name是否重复
      *

+ 35 - 2
boman-modules/boman-gen/src/main/java/com/boman/gen/service/GenTableServiceImpl.java

@@ -14,6 +14,8 @@ import java.util.zip.ZipOutputStream;
 import com.boman.common.core.constant.UserConstants;
 import com.boman.common.core.utils.DateUtils;
 import com.boman.common.core.web.domain.AjaxResult;
+import com.boman.gen.domain.TableSql;
+
 import com.boman.system.api.RemoteSysMenuService;
 import com.boman.system.api.domain.SysMenu;
 import org.apache.commons.io.IOUtils;
@@ -59,6 +61,9 @@ public class GenTableServiceImpl implements IGenTableService {
 
     @Autowired
     private RemoteSysMenuService remoteSysMenuService;
+
+    @Autowired
+    private TableSqlServiceImpl tableSqlService;
     /**
      * 查询业务信息
      *
@@ -393,9 +398,17 @@ public class GenTableServiceImpl implements IGenTableService {
         //新增表成功的时候,新增字段公共字段
         int i = genTableMapper.insertGenTable(genTable);
         if (i > 0) {
-            insertCommonColumn(genTable.getTableId());
+            Long id = insertCommonColumn(genTable.getTableId());
+            if (id != -1){
+                genTable.setTablePrimaryKey(id);
+                genTableMapper.updateGenTable(genTable);
+            }
             //判断是否是菜单
             isMenu(genTable);
+            //新建表时新增建表语句
+            TableSql tableSql = new TableSql();
+            tableSql.setTableId(genTable.getTableId());
+            tableSqlService.insertTableSql(tableSql);
             return AjaxResult.success();
         }
         return AjaxResult.error();
@@ -406,7 +419,7 @@ public class GenTableServiceImpl implements IGenTableService {
      *
      * @param tableId
      */
-    public void insertCommonColumn(Long tableId) {
+    public Long insertCommonColumn(Long tableId) {
         GenTableColumn genTableColumnLog = new GenTableColumn();
         GenTableColumn genTableColumnBaseInfo = new GenTableColumn();
 
@@ -439,6 +452,7 @@ public class GenTableServiceImpl implements IGenTableService {
         genTableColumnMapper.insertGenTableColumn(genTableColumnBaseInfo);
 
 
+        Long columnId = -1L;
         String[] columnName = new String[]{"id", "create_by", "create_time", "update_by", "update_time", "is_del"};
         String[] columnComment = new String[]{"编号","创建者", "创建时间", "更新者", "更新时间", "是否删除"};
         String[] columnType = new String[]{"bigint(20)","varchar(64)", "datetime", "varchar(64)", "datetime", "char(1)"};
@@ -463,7 +477,12 @@ public class GenTableServiceImpl implements IGenTableService {
                 genTableColumn.setHrParentId(genTableColumnLog.getColumnId());
             }
             genTableColumnMapper.insertGenTableColumn(genTableColumn);
+            //获得id字段的id
+            if (i == 0){
+                 columnId = genTableColumn.getColumnId();
+            }
         }
+        return columnId;
     }
 
     /**
@@ -578,4 +597,18 @@ public class GenTableServiceImpl implements IGenTableService {
         }
         return genPath + File.separator + VelocityUtils.getFileName(template, table);
     }
+
+    /**
+     *校验表名称是否存在
+     * @param genTable
+     * @return
+     */
+    @Override
+    public String checkTableNameUnique(GenTable genTable){
+        List<GenTable> genTables = genTableMapper.selectGenTableList(genTable);
+        if (genTables.size() > 0){
+            return UserConstants.NOT_UNIQUE;
+        }
+        return UserConstants.UNIQUE;
+    }
 }

+ 8 - 1
boman-modules/boman-gen/src/main/java/com/boman/gen/service/IGenTableColumnService.java

@@ -52,11 +52,18 @@ public interface IGenTableColumnService
     /**
      * 删除业务字段信息
      * 
-     * @param ids 需要删除的数据ID
+     * @param ids 需要删除的数据ID 表id
      * @return 结果
      */
     public int deleteGenTableColumnByIds(String ids);
 
+    /**
+     * 删除字段
+     * @param ids 字段id
+     * @return
+     */
+    public int deleteGenTableColumnByColumnIds(String ids);
+
 
     /**
     *校验column_name是否重复

+ 20 - 18
boman-modules/boman-gen/src/main/java/com/boman/gen/service/IGenTableService.java

@@ -8,14 +8,13 @@ import com.boman.gen.domain.GenTable;
 
 /**
  * 业务 服务层
- * 
+ *
  * @author ruoyi
  */
-public interface IGenTableService
-{
+public interface IGenTableService {
     /**
      * 查询业务列表
-     * 
+     *
      * @param genTable 业务信息
      * @return 业务集合
      */
@@ -23,7 +22,7 @@ public interface IGenTableService
 
     /**
      * 查询据库列表
-     * 
+     *
      * @param genTable 业务信息
      * @return 数据库表集合
      */
@@ -31,7 +30,7 @@ public interface IGenTableService
 
     /**
      * 查询据库列表
-     * 
+     *
      * @param tableNames 表名称组
      * @return 数据库表集合
      */
@@ -47,14 +46,14 @@ public interface IGenTableService
 
     /**
      * 查询所有表信息
-     * 
+     *
      * @return 表信息集合
      */
     public List<GenTable> selectGenTableAll();
 
     /**
      * 查询业务信息
-     * 
+     *
      * @param id 业务ID
      * @return 业务信息
      */
@@ -62,7 +61,7 @@ public interface IGenTableService
 
     /**
      * 修改业务
-     * 
+     *
      * @param genTable 业务信息
      * @return 结果
      */
@@ -70,7 +69,7 @@ public interface IGenTableService
 
     /**
      * 删除业务信息
-     * 
+     *
      * @param tableIds 需要删除的表数据ID
      * @return 结果
      */
@@ -78,14 +77,14 @@ public interface IGenTableService
 
     /**
      * 导入表结构
-     * 
+     *
      * @param tableList 导入表列表
      */
     public void importGenTable(List<GenTable> tableList);
 
     /**
      * 预览代码
-     * 
+     *
      * @param tableId 表编号
      * @return 预览数据列表
      */
@@ -93,7 +92,7 @@ public interface IGenTableService
 
     /**
      * 生成代码(下载方式)
-     * 
+     *
      * @param tableName 表名称
      * @return 数据
      */
@@ -101,7 +100,7 @@ public interface IGenTableService
 
     /**
      * 生成代码(自定义路径)
-     * 
+     *
      * @param tableName 表名称
      * @return 数据
      */
@@ -109,14 +108,14 @@ public interface IGenTableService
 
     /**
      * 同步数据库
-     * 
+     *
      * @param tableName 表名称
      */
     public void synchDb(String tableName);
 
     /**
      * 批量生成代码(下载方式)
-     * 
+     *
      * @param tableNames 表数组
      * @return 数据
      */
@@ -124,15 +123,18 @@ public interface IGenTableService
 
     /**
      * 修改保存参数校验
-     * 
+     *
      * @param genTable 业务信息
      */
     public void validateEdit(GenTable genTable);
 
     /**
      * 代码生成业务新增
+     *
      * @param genTable
      * @return
      */
     public AjaxResult insertGenTable(GenTable genTable);
-}
+
+    public String checkTableNameUnique(GenTable genTable);
+}

+ 40 - 0
boman-modules/boman-gen/src/main/java/com/boman/gen/service/ITableSqlService.java

@@ -0,0 +1,40 @@
+package com.boman.gen.service;
+
+import com.boman.common.core.web.domain.AjaxResult;
+import com.boman.gen.domain.TableSql;
+
+/**
+ * @author tjf
+ * @Date: 2021/04/14/10:43
+ */
+public interface ITableSqlService {
+
+    /**
+     * 创建sql语句
+     * @param tableSql
+     * @return
+     */
+    public AjaxResult insertTableSql(TableSql tableSql);
+
+    /**
+     * 刷新建表语句
+     * @param tableSql
+     * @return
+     */
+    public AjaxResult reloadTableSql(TableSql tableSql);
+
+    /**
+     * 执行建表语句
+     * @param tableSql
+     * @return
+     */
+    public AjaxResult implementSql(TableSql tableSql);
+
+
+    /**
+     * 根据表id查询该表的建表语句
+     * @param id
+     * @return
+     */
+    public AjaxResult selectTableSqlByTableId(Long id);
+}

+ 151 - 0
boman-modules/boman-gen/src/main/java/com/boman/gen/service/TableSqlServiceImpl.java

@@ -0,0 +1,151 @@
+package com.boman.gen.service;
+
+import com.boman.common.core.constant.UserConstants;
+import com.boman.common.core.utils.DateUtils;
+import com.boman.common.core.utils.SecurityUtils;
+import com.boman.common.core.utils.StringUtils;
+import com.boman.common.core.web.domain.AjaxResult;
+import com.boman.gen.domain.GenTable;
+import com.boman.gen.domain.GenTableColumn;
+import com.boman.gen.domain.TableSql;
+import com.boman.gen.mapper.GenTableColumnMapper;
+import com.boman.gen.mapper.GenTableMapper;
+import com.boman.gen.mapper.TableSqlMapper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.dao.DataAccessException;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/**
+ * @author tjf
+ * @Date: 2021/04/14/10:43
+ */
+@Service
+public class TableSqlServiceImpl implements ITableSqlService {
+
+    @Autowired
+    private TableSqlMapper tableSqlMapper;
+
+    @Autowired
+    private GenTableColumnMapper genTableColumnMapper;
+
+    @Autowired
+    private GenTableMapper genTableMapper;
+
+    @Autowired
+    private JdbcTemplate jdbcTemplate;
+
+
+    /**
+     * 创建sql语句
+     *
+     * @param tableSql
+     * @return
+     */
+    @Override
+    public AjaxResult insertTableSql(TableSql tableSql) {
+        Long tableId = tableSql.getTableId();
+        if (tableId == null) {
+            return AjaxResult.error("缺少表id");
+        }
+        GenTable genTable = genTableMapper.selectGenTableById(tableSql.getTableId());
+        String tableName = genTable.getTableName();
+        tableSql.setCreateSql(createSql(tableSql, tableName));
+        tableSql.setCreateBy(SecurityUtils.getUsername());
+        tableSql.setCreateLog(DateUtils.getNowDate() + SecurityUtils.getUsername() + " 创建表 " + tableName);
+        tableSqlMapper.insertTableSql(tableSql);
+        return AjaxResult.success();
+    }
+
+    /**
+     * 刷新建表语句
+     *
+     * @param tableSql
+     * @return
+     */
+    @Override
+    public AjaxResult reloadTableSql(TableSql tableSql) {
+        GenTable genTable = genTableMapper.selectGenTableById(tableSql.getTableId());
+        String tableName = genTable.getTableName();
+        tableSql.setCreateSql(createSql(tableSql, tableName));
+        String createLog = tableSql.getCreateLog();
+        StringBuffer sb = new StringBuffer(createLog);
+        sb.append("\r\n").append(DateUtils.getNowDate() + SecurityUtils.getUsername() + "刷新创建语句");
+        tableSql.setCreateLog(sb.toString());
+        tableSql.setUpdateBy(SecurityUtils.getUsername());
+        tableSqlMapper.updateTableSql(tableSql);
+        return AjaxResult.success();
+    }
+
+    /**
+     * 执行建表语句
+     *
+     * @param tableSql
+     * @return
+     */
+    @Override
+    public AjaxResult implementSql(TableSql tableSql) {
+        String createSql = tableSql.getCreateSql();
+        try {
+            jdbcTemplate.execute(createSql);
+        } catch (DataAccessException e) {
+            e.printStackTrace();
+            return AjaxResult.error("当前表已存在");
+        }
+        String createLog = tableSql.getCreateLog();
+        StringBuffer sb = new StringBuffer(createLog);
+        sb.append(DateUtils.getNowDate() + SecurityUtils.getUsername() +" 执行建表语句");
+        tableSqlMapper.updateTableSql(tableSql);
+        return AjaxResult.success();
+    }
+
+    /**
+     * 查询建表SQL
+     * @param id
+     * @return
+     */
+    @Override
+    public AjaxResult selectTableSqlByTableId(Long id) {
+        TableSql tableSql = tableSqlMapper.selectTableSqlByTableId(id);
+        return AjaxResult.success(tableSql);
+    }
+
+
+    /**
+     * 生成建表语句
+     *
+     * @param tableSql
+     * @param tableName
+     * @return
+     */
+    private String createSql(TableSql tableSql, String tableName) {
+        //根据表id查询所有字段
+        List<GenTableColumn> genTableColumns = genTableColumnMapper.selectGenTableColumnListByTableId(tableSql.getTableId());
+        //定义主键id
+        String primaryKey = null;
+        //拼接建表语句
+        StringBuffer sb = new StringBuffer("create table if not exists ");
+        sb.append(tableName).append(" (\r\n");
+
+        for (GenTableColumn genTableColumn : genTableColumns) {
+            sb.append(genTableColumn.getColumnName()).append(" " + genTableColumn.getColumnType());
+            if (genTableColumn.getIsIncrement().equals(UserConstants.INCREMENT)) {
+                sb = genTableColumn.getDefaultValue() == null ? sb.append(" DEFAULT NULL AUTO_INCREMENT COMMENT ") : sb.append(" DEFAULT '" + genTableColumn.getDefaultValue() + "' AUTO_INCREMENT COMMENT '");
+            } else {
+                sb = genTableColumn.getDefaultValue() == null ? sb.append(" DEFAULT NULL COMMENT ") : sb.append(" DEFAULT '" + genTableColumn.getDefaultValue() + "' COMMENT '");
+            }
+            sb.append(genTableColumn.getColumnComment() + "'").append(",\r\n");
+            if (genTableColumn.getIsPk().equals(UserConstants.INCREMENT)) {
+                primaryKey = genTableColumn.getColumnName();
+            }
+        }
+        if (StringUtils.isNotBlank(primaryKey)) {
+            sb.append(" PRIMARY KEY (" + primaryKey + " ) USING BTREE\r\n");
+        }
+        sb.append(") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='" + tableName + "';");
+        return sb.toString();
+    }
+
+}

+ 31 - 6
boman-modules/boman-gen/src/main/resources/mapper/generator/GenTableColumnMapper.xml

@@ -33,10 +33,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="defaultValue"     column="default_value"    />
         <result property="numRows"     column="num_rows"    />
         <result property="numColumns"     column="num_columns"    />
+        <result property="fieldTranslator"     column="field_translator"    />
+        <result property="extendedAttributes"     column="extended_attributes"    />
+        <result property="isIn"     column="is_in"    />
+        <result property="isOut"     column="is_out"    />
     </resultMap>
 	
 	<sql id="selectGenTableColumnVo">
-        select column_id, table_id, column_name, column_comment, column_type, java_type, java_field, is_pk, is_increment, is_required, is_insert, is_edit, is_list, is_query, query_type, html_type, foreign_key, dict_type, sort, create_by, create_time, update_by, update_time, hr_parent_id, mask, default_value, num_rows, num_columns from gen_table_column
+        select column_id, table_id, column_name, column_comment, column_type, java_type, java_field, is_pk, is_increment, is_required, is_insert, is_edit, is_list, is_query, query_type, html_type, foreign_key, dict_type, sort, create_by, create_time, update_by, update_time, hr_parent_id, mask, default_value, num_rows, num_columns, field_translator, extended_attributes, is_in, is_out from gen_table_column
     </sql>
 	
     <select id="selectGenTableColumnListByTableId" parameterType="GenTableColumn" resultMap="GenTableColumnResult">
@@ -92,6 +96,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 			<if test="defaultValue != null and defaultValue != ''">default_value,</if>
 			<if test="numRows != null and numRows != ''">num_rows,</if>
 			<if test="numColumns != null and numColumns != ''">num_columns,</if>
+			<if test="fieldTranslator != null and fieldTranslator != ''">field_translator,</if>
+			<if test="extendedAttributes != null and extendedAttributes != ''">extended_attributes,</if>
+			<if test="isIn != null and isIn != ''">is_in,</if>
+			<if test="isOut != null and isOut != ''">is_out,</if>
 			create_time
          )values(
 			<if test="tableId != null and tableId != ''">#{tableId},</if>
@@ -118,6 +126,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 			<if test="defaultValue != null and defaultValue != ''">#{defaultValue},</if>
 			<if test="numRows != null and numRows != ''">#{numRows},</if>
 			<if test="numColumns != null and numColumns != ''">#{numColumns},</if>
+			<if test="fieldTranslator != null and fieldTranslator != ''">#{fieldTranslator},</if>
+			<if test="extendedAttributes != null and extendedAttributes != ''">#{extendedAttributes},</if>
+			<if test="isIn != null and isIn != ''">#{isIn},</if>
+			<if test="isOut != null and isOut != ''">#{isOut},</if>
 			sysdate()
          )
     </insert>
@@ -125,14 +137,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     <update id="updateGenTableColumn" parameterType="GenTableColumn">
         update gen_table_column
         <set>
-            <if test="tableId != null and tableId != ''">#{tableId},</if>
-            <if test="columnName != null and columnName != ''">#{columnName},</if>
+            <if test="tableId != null and tableId != ''">table_id = #{tableId},</if>
+            <if test="columnName != null and columnName != ''">column_name = #{columnName},</if>
             <if test="columnComment != null and columnComment != ''">column_comment = #{columnComment},</if>
-            <if test="columnType != null and columnType != ''">#{columnType},</if>
+            <if test="columnType != null and columnType != ''">column_type = #{columnType},</if>
             <if test="javaType != null and javaType != ''">java_type = #{javaType},</if>
             <if test="javaField != null and javaField != ''">java_field = #{javaField},</if>
-            <if test="isPk != null and isPk != ''">#{isPk},</if>
-            <if test="isIncrement != null and isIncrement != ''">#{isIncrement},</if>
+            <if test="isPk != null and isPk != ''">is_pk = #{isPk},</if>
+            <if test="isIncrement != null and isIncrement != ''">is_increment = #{isIncrement},</if>
             <if test="isRequired != null and isRequired != ''">is_required = #{isRequired},</if>
             <if test="isInsert != null and isInsert != ''">is_insert = #{isInsert},</if>
             <if test="isEdit != null and isEdit != ''">is_edit = #{isEdit},</if>
@@ -150,6 +162,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="defaultValue != null and defaultValue != ''">default_value = #{defaultValue},</if>
             <if test="numRows != null and numRows != ''">num_rows = #{numRows},</if>
             <if test="numColumns != null and numColumns != ''">num_columns = #{numColumns},</if>
+            <if test="fieldTranslator != null and fieldTranslator != ''">field_translator = #{fieldTranslator},</if>
+            <if test="extendedAttributes != null and extendedAttributes != ''">extended_attributes = #{extendedAttributes},</if>
+            <if test="isIn != null and isIn != ''">is_in = #{isIn},</if>
+            <if test="isOut != null and isOut != ''">is_out = #{isOut},</if>
             update_time = sysdate()
         </set>
         where column_id = #{columnId}
@@ -175,4 +191,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         </foreach>
     </delete>
 
+
+
+    <delete id="deleteGenTableColumnByColumnIds" parameterType="Long">
+        delete from gen_table_column where column_id in
+        <foreach collection="array" item="columnId" open="(" separator="," close=")">
+            #{columnId}
+        </foreach>
+    </delete>
+
 </mapper>

+ 8 - 4
boman-modules/boman-gen/src/main/resources/mapper/generator/GenTableMapper.xml

@@ -37,6 +37,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 		<result property="realTableName"         column="real_table_name"            />
 		<result property="filterConditions"         column="filter_conditions"            />
 		<result property="extendedAttributes"         column="extended_attributes"            />
+		<result property="tablePrimaryKey"         column="table_primary_key"            />
 		<collection  property="columns"  javaType="java.util.List"  resultMap="GenTableColumnResult" />
 	</resultMap>
 	
@@ -67,7 +68,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 	
 	<sql id="selectGenTableVo">
         select table_id, table_name, table_comment, sub_table_name, sub_table_fk_name, class_name, tpl_category, package_name, module_name, business_name, function_name, function_author, gen_type, gen_path, options,
-         create_by, create_time, update_by, update_time, remark, is_menu, menu_role, ak_column, dk_column, trigger_create, trigger_retrieve, trigger_update, trigger_delete, trigger_submit, real_table_name, filter_conditions, extended_attributes from gen_table
+         create_by, create_time, update_by, update_time, remark, is_menu, menu_role, ak_column, dk_column, trigger_create, trigger_retrieve, trigger_update, trigger_delete, trigger_submit, real_table_name, filter_conditions, extended_attributes, table_primary_key from gen_table
     </sql>
     
     <select id="selectGenTableList" parameterType="GenTable" resultMap="GenTableResult">
@@ -126,7 +127,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 	</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, t.is_menu, t.menu_role, t.ak_column, t.dk_column, t.trigger_create, t.trigger_retrieve, t.trigger_update, t.trigger_delete, t.trigger_submit, t.real_table_name, t.filter_conditions, t.extended_attributes,
+	    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, t.is_menu, t.menu_role, t.ak_column, t.dk_column, t.trigger_create, t.trigger_retrieve, t.trigger_update, t.trigger_delete, t.trigger_submit, t.real_table_name, t.filter_conditions, t.extended_attributes, t.table_primary_key,
 			   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
@@ -134,7 +135,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 	</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, t.is_menu, t.menu_role, t.ak_column, t.dk_column, t.trigger_create, t.trigger_retrieve, t.trigger_update, t.trigger_delete, t.trigger_submit, t.real_table_name, t.filter_conditions, t.extended_attributes
+	    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, t.is_menu, t.menu_role, t.ak_column, t.dk_column, t.trigger_create, t.trigger_retrieve, t.trigger_update, t.trigger_delete, t.trigger_submit, t.real_table_name, t.filter_conditions, t.extended_attributes, t.table_primary_key,
 			   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
@@ -142,7 +143,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 	</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, t.is_menu, t.menu_role, t.ak_column, t.dk_column, t.trigger_create, t.trigger_retrieve, t.trigger_update, t.trigger_delete, t.trigger_submit, t.real_table_name, t.filter_conditions, t.extended_attributes
+	    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, t.is_menu, t.menu_role, t.ak_column, t.dk_column, t.trigger_create, t.trigger_retrieve, t.trigger_update, t.trigger_delete, t.trigger_submit, t.real_table_name, t.filter_conditions, t.extended_attributes, t.table_primary_key,
 			   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
@@ -175,6 +176,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  			<if test="realTableName != null and realTableName != ''">real_table_name,</if>
  			<if test="filterConditions != null and filterConditions != ''">filter_conditions,</if>
  			<if test="extendedAttributes != null and extendedAttributes != ''">extended_attributes,</if>
+ 			<if test="tablePrimaryKey != null and tablePrimaryKey != ''">table_primary_key,,</if>
  			<if test="createBy != null and createBy != ''">create_by,</if>
 			create_time
          )values(
@@ -202,6 +204,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  			<if test="realTableName != null and realTableName != ''">#{realTableName},</if>
  			<if test="filterConditions != null and filterConditions != ''">#{filterConditions},</if>
  			<if test="extendedAttributes != null and extendedAttributes != ''">#{extendedAttributes},</if>
+ 			<if test="tablePrimaryKey != null and tablePrimaryKey != ''">#{tablePrimaryKey},</if>
  			<if test="createBy != null and createBy != ''">#{createBy},</if>
 			sysdate()
          )
@@ -238,6 +241,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 			<if test="realTableName != null and realTableName !=''">real_table_name = #{realTableName},</if>
 			<if test="filterConditions != null and filterConditions !=''">filter_conditions = #{filterConditions},</if>
 			<if test="extendedAttributes != null and extendedAttributes !=''">extended_attributes = #{extendedAttributes},</if>
+			<if test="tablePrimaryKey != null and tablePrimaryKey !=''">table_primary_key = #{tablePrimaryKey},</if>
             update_time = sysdate()
         </set>
         where table_id = #{tableId}

+ 24 - 7
boman-modules/boman-gen/src/main/resources/mapper/generator/GenTableRelationMapper.xml

@@ -10,21 +10,29 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 		<result property="relationParentId"     column="relation_parent_id"      />
 		<result property="relationChildId"     column="relation_child_id"      />
 		<result property="relationType"     column="relation_type"      />
+		<result property="embedEdit"     column="embed_edit"      />
+		<result property="displayConditions"     column="display_conditions"      />
 		<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"      />
 		<result property="isDel"     column="is_del"      />
+		<result property="tableName"     column="table_name"      />
+		<result property="columnName"     column="column_name"      />
 	</resultMap>
 
 	<sql id="selectGenTableRelationVo">
-        select id, description, relation_parent_id, relation_child_id, relation_type, sort, create_by, create_time, update_by, update_time, is_del
+        select id, description, relation_parent_id, relation_child_id, relation_type, sort, embed_edit, display_conditions, create_by, create_time, update_by, update_time, is_del
 		from gen_table_relation
     </sql>
 
 	<select id="selectGenTableRelationList" parameterType="GenTableRelation" resultMap="GenTableRelationResult">
-		<include refid="selectGenTableRelationVo"/>
+		select r.id, r.description, r.relation_parent_id, r.relation_child_id, r.relation_type, r.sort, r.embed_edit, r.display_conditions, r.create_by, r.create_time, r.update_by, r.update_time, r.is_del,
+		t.table_name, c.column_name
+		from gen_table_relation r
+		left join gen_table t on t.table_id = r.relation_parent_id
+		left join gen_table_column c on c.column_id = r.relation_child_id
 		<where>
 			<if test="description != null and description != ''">
 				AND description like concat('%', #{description}, '%')
@@ -59,20 +67,26 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 		<if test="relationParentId != null">relation_parent_id,</if>
 		<if test="relationChildId != null">relation_child_id,</if>
 		<if test="relationType != null">relation_type,</if>
+		<if test="embedEdit != null">embed_edit,</if>
+		<if test="displayConditions != null and displayConditions != ''">display_conditions,</if>
 		<if test="sort != null">sort,</if>
 		<if test="createBy != null and createBy != ''">create_by,</if>
 		<if test="updateBy != null and updateBy != ''">update_by,</if>
 		<if test="updateTime != null and updateTime != ''">update_time,</if>
+		<if test="isDel != null and isDel != ''">is_del,</if>
 		create_time
 		)values(
 		<if test="description != null and description != ''">#{description},</if>
 		<if test="relationParentId != null">#{relationParentId},</if>
 		<if test="relationChildId != null">#{relationChildId},</if>
 		<if test="relationType != null">#{relationType},</if>
+		<if test="embedEdit != null">#{embedEdit},</if>
+		<if test="displayConditions != null and displayConditions != ''">#{displayConditions},</if>
 		<if test="sort != null">#{sort},</if>
 		<if test="createBy != null and createBy != ''">#{createBy},</if>
 		<if test="updateBy != null and updateBy != ''">#{updateBy},</if>
 		<if test="updateTime != null and updateTime != ''">#{updateTime},</if>
+		<if test="isDel != null and isDel != ''">#{isDel},</if>
 		sysdate()
 		)
 	</insert>
@@ -84,20 +98,23 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 			<if test="relationParentId != null">relation_parent_id = #{relationParentId},</if>
 			<if test="relationChildId != null">relation_child_id = #{relationChildId},</if>
 			<if test="relationType != null">relation_type = #{relationType},</if>
+			<if test="embedEdit != null">embed_edit = #{embedEdit},</if>
+			<if test="displayConditions != null and displayConditions != ''">display_conditions = #{displayConditions},</if>
 			<if test="sort != null">sort = #{sort},</if>
 			<if test="createBy != null and createBy != ''">create_by = #{createBy},</if>
-			<if test="create_time != null">create_time = #{createTime},</if>
+			<if test="createTime != null ">create_time = #{createTime},</if>
 			<if test="updateBy != null and updateBy != null">update_by = #{updateBy},</if>
+			<if test="isDel != null and isDel != null">is_del = #{isDel},</if>
 			update_time = sysdate()
 		</set>
 		where id = #{id}
 	</update>
 
-	<update id="deleteGenTableRelation" parameterType="GenTableRelation">
-		update gen_table_relation
-		set is_del = '1' where id in
+	<delete id="deleteGenTableRelation" parameterType="GenTableRelation">
+		delete from gen_table_relation
+		where id in
 		<foreach item="ids" collection="array" open="(" separator="," close=")">
 			#{ids}
 		</foreach>
-	</update>
+	</delete>
 </mapper> 

+ 61 - 0
boman-modules/boman-gen/src/main/resources/mapper/generator/TableSqlMapper.xml

@@ -0,0 +1,61 @@
+<?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">
+<mapper namespace="com.boman.gen.mapper.TableSqlMapper">
+    
+    <resultMap type="TableSql" id="TableSqlResult">
+        <result property="id"       column="id"      />
+        <result property="tableId"           column="table_id"           />
+        <result property="createSql"           column="create_sql"           />
+        <result property="createLog"           column="create_log"           />
+        <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"    />
+        <result property="isDel"     column="is_del"    />
+	</resultMap>
+
+	
+	<sql id="selectTableSqlVo">
+        select id, table_id, create_sql, create_log, create_by, create_time, update_by, update_time, remark, is_del from table_sql
+    </sql>
+
+    <select id="selectTableSqlByTableId" parameterType="Long" resultMap="TableSqlResult">
+        <include refid="selectTableSqlVo"></include>
+        where table_id = #{id} limit 1
+    </select>
+    <insert id="insertTableSql" parameterType="TableSql" useGeneratedKeys="true" keyProperty="id">
+        insert into table_sql (
+			<if test="tableId != null and tableId != ''">table_id,</if>
+			<if test="createSql != null and createSql != ''">create_sql,</if>
+			<if test="createLog != null and createLog != ''">create_log,</if>
+			<if test="remark != null and remark != ''">remark,</if>
+			<if test="createBy != null and createBy != ''">create_by,</if>
+			create_time
+         )values(
+			<if test="tableId != null and tableId != ''">#{tableId},</if>
+			<if test="createSql != null and createSql != ''">#{createSql},</if>
+			<if test="createLog != null and createLog != ''">#{createLog},</if>
+			<if test="remark != null and remark != ''">#{remark},</if>
+			<if test="createBy != null and createBy != ''">#{createBy},</if>
+			sysdate()
+         )
+    </insert>
+
+
+    <update id="updateTableSql" parameterType="TableSql">
+        update table_sql
+        <set>
+            <if test="tableId != null">table_id = #{tableId},</if>
+            <if test="createSql != null and createSql != ''">create_sql = #{createSql},</if>
+            <if test="createLog != null and createLog != ''">create_log = #{createLog},</if>
+            <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
+            <if test="remark != null and remark != ''">remark = #{remark},</if>
+            <if test="isDel != null and isDel != ''">is_del = #{isDel},</if>
+            update_time = sysdate()
+        </set>
+        where id = #{id}
+    </update>
+</mapper>