Browse Source

update 重构代码生成 多数据库sql加载 使用xml特性动态切换sql

疯狂的狮子li 3 năm trước cách đây
mục cha
commit
7f1356a447

+ 6 - 6
ruoyi-common/src/main/java/com/ruoyi/common/helper/DataBaseHelper.java

@@ -23,7 +23,7 @@ public class DataBaseHelper {
     /**
      * 获取当前数据库类型
      */
-    public static DataBaseType getDataBasyType() {
+    public static DataBaseType getDataBaseType() {
         DynamicRoutingDataSource ds = (DynamicRoutingDataSource) SpringUtils.getBean(DataSource.class);
         DataSource dataSource = ds.determineDataSource();
         try {
@@ -36,23 +36,23 @@ public class DataBaseHelper {
     }
 
     public static boolean isMySql() {
-        return DataBaseType.MY_SQL == getDataBasyType();
+        return DataBaseType.MY_SQL == getDataBaseType();
     }
 
     public static boolean isOracle() {
-        return DataBaseType.ORACLE == getDataBasyType();
+        return DataBaseType.ORACLE == getDataBaseType();
     }
 
     public static boolean isPostgerSql() {
-        return DataBaseType.POSTGRE_SQL == getDataBasyType();
+        return DataBaseType.POSTGRE_SQL == getDataBaseType();
     }
 
     public static boolean isSqlServer() {
-        return DataBaseType.SQL_SERVER == getDataBasyType();
+        return DataBaseType.SQL_SERVER == getDataBaseType();
     }
 
     public static String findInSet(Object var1, String var2) {
-        DataBaseType dataBasyType = getDataBasyType();
+        DataBaseType dataBasyType = getDataBaseType();
         String var = Convert.toStr(var1);
         if (dataBasyType == DataBaseType.SQL_SERVER) {
             // charindex(',100,' , ',0,100,101,') <> 0

+ 3 - 5
ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/GenTableMapper.java

@@ -1,8 +1,6 @@
 package com.ruoyi.generator.mapper;
 
 import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
-import com.baomidou.mybatisplus.core.conditions.Wrapper;
-import com.baomidou.mybatisplus.core.toolkit.Constants;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.ruoyi.common.core.mapper.BaseMapperPlus;
 import com.ruoyi.generator.domain.GenTable;
@@ -18,15 +16,15 @@ import java.util.List;
 @InterceptorIgnore(dataPermission = "true")
 public interface GenTableMapper extends BaseMapperPlus<GenTableMapper, GenTable, GenTable> {
 
-    Page<GenTable> selectPageDbTableList(@Param("page") Page<GenTable> page, @Param(Constants.WRAPPER) Wrapper<Object> queryWrapper);
+    Page<GenTable> selectPageDbTableList(@Param("page") Page<GenTable> page, @Param("genTable") GenTable genTable);
 
     /**
      * 查询据库列表
      *
-     * @param queryWrapper 查询条件
+     * @param genTable 查询条件
      * @return 数据库表集合
      */
-    List<GenTable> selectDbTableList(@Param(Constants.WRAPPER) Wrapper<Object> queryWrapper);
+    List<GenTable> selectDbTableList(GenTable genTable);
 
     /**
      * 查询据库列表

+ 0 - 24
ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/OracleGenTableColumnMapper.java

@@ -1,24 +0,0 @@
-package com.ruoyi.generator.mapper;
-
-import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
-import com.ruoyi.common.core.mapper.BaseMapperPlus;
-import com.ruoyi.generator.domain.GenTableColumn;
-
-import java.util.List;
-
-/**
- * 业务字段 数据层
- *
- * @author Lion Li
- */
-@InterceptorIgnore(dataPermission = "true")
-public interface OracleGenTableColumnMapper extends BaseMapperPlus<OracleGenTableColumnMapper, GenTableColumn, GenTableColumn> {
-    /**
-     * 根据表名称查询列信息
-     *
-     * @param tableName 表名称
-     * @return 列信息
-     */
-    List<GenTableColumn> selectDbTableColumnsByName(String tableName);
-
-}

+ 0 - 62
ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/OracleGenTableMapper.java

@@ -1,62 +0,0 @@
-package com.ruoyi.generator.mapper;
-
-import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
-import com.baomidou.mybatisplus.core.conditions.Wrapper;
-import com.baomidou.mybatisplus.core.toolkit.Constants;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.ruoyi.common.core.mapper.BaseMapperPlus;
-import com.ruoyi.generator.domain.GenTable;
-import org.apache.ibatis.annotations.Param;
-
-import java.util.List;
-
-/**
- * 业务 数据层
- *
- * @author Lion Li
- */
-@InterceptorIgnore(dataPermission = "true")
-public interface OracleGenTableMapper extends BaseMapperPlus<OracleGenTableMapper, GenTable, GenTable> {
-
-    Page<GenTable> selectPageDbTableList(@Param("page") Page<GenTable> page, @Param(Constants.WRAPPER) Wrapper<Object> queryWrapper);
-
-    /**
-     * 查询据库列表
-     *
-     * @param queryWrapper 查询条件
-     * @return 数据库表集合
-     */
-    List<GenTable> selectDbTableList(@Param(Constants.WRAPPER) Wrapper<Object> queryWrapper);
-
-    /**
-     * 查询据库列表
-     *
-     * @param tableNames 表名称组
-     * @return 数据库表集合
-     */
-    List<GenTable> selectDbTableListByNames(String[] tableNames);
-
-    /**
-     * 查询所有表信息
-     *
-     * @return 表信息集合
-     */
-    List<GenTable> selectGenTableAll();
-
-    /**
-     * 查询表ID业务信息
-     *
-     * @param id 业务ID
-     * @return 业务信息
-     */
-    GenTable selectGenTableById(Long id);
-
-    /**
-     * 查询表名称业务信息
-     *
-     * @param tableName 表名称
-     * @return 业务信息
-     */
-    GenTable selectGenTableByName(String tableName);
-
-}

+ 0 - 319
ruoyi-generator/src/main/java/com/ruoyi/generator/service/BaseGenTableServiceImpl.java

@@ -1,319 +0,0 @@
-package com.ruoyi.generator.service;
-
-import cn.hutool.core.io.IoUtil;
-import cn.hutool.core.lang.Dict;
-import cn.hutool.core.util.ObjectUtil;
-import com.baomidou.dynamic.datasource.annotation.DS;
-import com.ruoyi.common.constant.GenConstants;
-import com.ruoyi.common.core.domain.PageQuery;
-import com.ruoyi.common.core.page.TableDataInfo;
-import com.ruoyi.common.exception.ServiceException;
-import com.ruoyi.common.helper.DataBaseHelper;
-import com.ruoyi.common.utils.JsonUtils;
-import com.ruoyi.common.utils.StringUtils;
-import com.ruoyi.common.utils.spring.SpringUtils;
-import com.ruoyi.generator.domain.GenTable;
-import com.ruoyi.generator.domain.GenTableColumn;
-import com.ruoyi.generator.util.VelocityUtils;
-import org.springframework.context.annotation.Primary;
-import org.springframework.stereotype.Service;
-
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.util.List;
-import java.util.Map;
-import java.util.zip.ZipOutputStream;
-
-/**
- * 业务 服务层实现
- *
- * @author Lion Li
- */
-@DS("#header.datasource")
-@Primary
-@Service
-public class BaseGenTableServiceImpl implements IGenTableService {
-
-    public BaseGenTableServiceImpl getService() {
-        if (DataBaseHelper.isMySql()) {
-            return SpringUtils.getBean(GenTableServiceImpl.class);
-        } else if (DataBaseHelper.isOracle()) {
-            return SpringUtils.getBean(OracleGenTableServiceImpl.class);
-        } else if (DataBaseHelper.isPostgerSql()) {
-            throw new ServiceException("当前数据库类型不支持!!!");
-        } else if (DataBaseHelper.isSqlServer()) {
-            throw new ServiceException("当前数据库类型不支持!!!");
-        } else {
-            throw new ServiceException("当前数据库类型不支持!!!");
-        }
-    }
-
-    /**
-     * 查询业务字段列表
-     *
-     * @param tableId 业务字段编号
-     * @return 业务字段集合
-     */
-    @Override
-    public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId) {
-        return getService().selectGenTableColumnListByTableId(tableId);
-    }
-
-    /**
-     * 查询业务信息
-     *
-     * @param id 业务ID
-     * @return 业务信息
-     */
-    @Override
-    public GenTable selectGenTableById(Long id) {
-        return getService().selectGenTableById(id);
-    }
-
-    @Override
-    public TableDataInfo<GenTable> selectPageGenTableList(GenTable genTable, PageQuery pageQuery) {
-        return getService().selectPageGenTableList(genTable, pageQuery);
-    }
-
-    /**
-     * 查询业务列表
-     *
-     * @param genTable 业务信息
-     * @return 业务集合
-     */
-    @Override
-    public List<GenTable> selectGenTableList(GenTable genTable) {
-        return getService().selectGenTableList(genTable);
-    }
-
-
-    @Override
-    public TableDataInfo<GenTable> selectPageDbTableList(GenTable genTable, PageQuery pageQuery){
-        return getService().selectPageDbTableList(genTable, pageQuery);
-    }
-
-    /**
-     * 查询据库列表
-     *
-     * @param genTable 业务信息
-     * @return 数据库表集合
-     */
-    @Override
-    public List<GenTable> selectDbTableList(GenTable genTable) {
-        return getService().selectDbTableList(genTable);
-    }
-
-    /**
-     * 查询据库列表
-     *
-     * @param tableNames 表名称组
-     * @return 数据库表集合
-     */
-    @Override
-    public List<GenTable> selectDbTableListByNames(String[] tableNames) {
-        return getService().selectDbTableListByNames(tableNames);
-    }
-
-    /**
-     * 查询所有表信息
-     *
-     * @return 表信息集合
-     */
-    @Override
-    public List<GenTable> selectGenTableAll() {
-        return getService().selectGenTableAll();
-    }
-
-    /**
-     * 修改业务
-     *
-     * @param genTable 业务信息
-     * @return 结果
-     */
-    @Override
-    public void updateGenTable(GenTable genTable) {
-        getService().updateGenTable(genTable);
-    }
-
-    /**
-     * 删除业务对象
-     *
-     * @param tableIds 需要删除的数据ID
-     * @return 结果
-     */
-    @Override
-    public void deleteGenTableByIds(Long[] tableIds) {
-        getService().deleteGenTableByIds(tableIds);
-    }
-
-    /**
-     * 导入表结构
-     *
-     * @param tableList 导入表列表
-     */
-    @Override
-    public void importGenTable(List<GenTable> tableList) {
-        getService().importGenTable(tableList);
-    }
-
-    /**
-     * 预览代码
-     *
-     * @param tableId 表编号
-     * @return 预览数据列表
-     */
-    @Override
-    public Map<String, String> previewCode(Long tableId) {
-        return getService().previewCode(tableId);
-    }
-
-    /**
-     * 生成代码(下载方式)
-     *
-     * @param tableName 表名称
-     * @return 数据
-     */
-    @Override
-    public byte[] downloadCode(String tableName) {
-        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
-        ZipOutputStream zip = new ZipOutputStream(outputStream);
-        generatorCode(tableName, zip);
-        IoUtil.close(zip);
-        return outputStream.toByteArray();
-    }
-
-    /**
-     * 生成代码(自定义路径)
-     *
-     * @param tableName 表名称
-     */
-    @Override
-    public void generatorCode(String tableName) {
-        getService().generatorCode(tableName);
-    }
-
-    /**
-     * 同步数据库
-     *
-     * @param tableName 表名称
-     */
-    @Override
-    public void synchDb(String tableName) {
-        getService().synchDb(tableName);
-    }
-
-    /**
-     * 批量生成代码(下载方式)
-     *
-     * @param tableNames 表数组
-     * @return 数据
-     */
-    @Override
-    public byte[] downloadCode(String[] tableNames) {
-        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
-        ZipOutputStream zip = new ZipOutputStream(outputStream);
-        for (String tableName : tableNames) {
-            generatorCode(tableName, zip);
-        }
-        IoUtil.close(zip);
-        return outputStream.toByteArray();
-    }
-
-    /**
-     * 查询表信息并生成代码
-     */
-    public void generatorCode(String tableName, ZipOutputStream zip) {
-        getService().generatorCode(tableName, zip);
-    }
-
-    /**
-     * 修改保存参数校验
-     *
-     * @param genTable 业务信息
-     */
-    @Override
-    public void validateEdit(GenTable genTable) {
-        if (GenConstants.TPL_TREE.equals(genTable.getTplCategory())) {
-            String options = JsonUtils.toJsonString(genTable.getParams());
-            Dict paramsObj = JsonUtils.parseMap(options);
-            if (StringUtils.isEmpty(paramsObj.getStr(GenConstants.TREE_CODE))) {
-                throw new ServiceException("树编码字段不能为空");
-            } else if (StringUtils.isEmpty(paramsObj.getStr(GenConstants.TREE_PARENT_CODE))) {
-                throw new ServiceException("树父编码字段不能为空");
-            } else if (StringUtils.isEmpty(paramsObj.getStr(GenConstants.TREE_NAME))) {
-                throw new ServiceException("树名称字段不能为空");
-            } else if (GenConstants.TPL_SUB.equals(genTable.getTplCategory())) {
-                if (StringUtils.isEmpty(genTable.getSubTableName())) {
-                    throw new ServiceException("关联子表的表名不能为空");
-                } else if (StringUtils.isEmpty(genTable.getSubTableFkName())) {
-                    throw new ServiceException("子表关联的外键名不能为空");
-                }
-            }
-        }
-    }
-
-    /**
-     * 设置主键列信息
-     *
-     * @param table 业务表信息
-     */
-    public void setPkColumn(GenTable table) {
-        for (GenTableColumn column : table.getColumns()) {
-            if (column.isPk()) {
-                table.setPkColumn(column);
-                break;
-            }
-        }
-        if (ObjectUtil.isNull(table.getPkColumn())) {
-            table.setPkColumn(table.getColumns().get(0));
-        }
-        if (GenConstants.TPL_SUB.equals(table.getTplCategory())) {
-            for (GenTableColumn column : table.getSubTable().getColumns()) {
-                if (column.isPk()) {
-                    table.getSubTable().setPkColumn(column);
-                    break;
-                }
-            }
-            if (ObjectUtil.isNull(table.getSubTable().getPkColumn())) {
-                table.getSubTable().setPkColumn(table.getSubTable().getColumns().get(0));
-            }
-        }
-    }
-
-    /**
-     * 设置代码生成其他选项值
-     *
-     * @param genTable 设置后的生成对象
-     */
-    public void setTableFromOptions(GenTable genTable) {
-        Dict paramsObj = JsonUtils.parseMap(genTable.getOptions());
-        if (ObjectUtil.isNotNull(paramsObj)) {
-            String treeCode = paramsObj.getStr(GenConstants.TREE_CODE);
-            String treeParentCode = paramsObj.getStr(GenConstants.TREE_PARENT_CODE);
-            String treeName = paramsObj.getStr(GenConstants.TREE_NAME);
-            String parentMenuId = paramsObj.getStr(GenConstants.PARENT_MENU_ID);
-            String parentMenuName = paramsObj.getStr(GenConstants.PARENT_MENU_NAME);
-
-            genTable.setTreeCode(treeCode);
-            genTable.setTreeParentCode(treeParentCode);
-            genTable.setTreeName(treeName);
-            genTable.setParentMenuId(parentMenuId);
-            genTable.setParentMenuName(parentMenuName);
-        }
-    }
-
-    /**
-     * 获取代码生成地址
-     *
-     * @param table    业务表信息
-     * @param template 模板文件路径
-     * @return 生成地址
-     */
-    public static String getGenPath(GenTable table, String template) {
-        String genPath = table.getGenPath();
-        if (StringUtils.equals(genPath, "/")) {
-            return System.getProperty("user.dir") + File.separator + "src" + File.separator + VelocityUtils.getFileName(template, table);
-        }
-        return genPath + File.separator + VelocityUtils.getFileName(template, table);
-    }
-}

+ 134 - 21
ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableServiceImpl.java

@@ -2,12 +2,15 @@ package com.ruoyi.generator.service;
 
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.io.IoUtil;
-import com.baomidou.mybatisplus.core.conditions.Wrapper;
+import cn.hutool.core.lang.Dict;
+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.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.ruoyi.common.constant.Constants;
+import com.ruoyi.common.constant.GenConstants;
 import com.ruoyi.common.core.domain.PageQuery;
 import com.ruoyi.common.core.page.TableDataInfo;
 import com.ruoyi.common.exception.ServiceException;
@@ -29,6 +32,8 @@ import org.apache.velocity.VelocityContext;
 import org.apache.velocity.app.Velocity;
 import org.springframework.stereotype.Service;
 
+import java.io.ByteArrayOutputStream;
+import java.io.File;
 import java.io.IOException;
 import java.io.StringWriter;
 import java.nio.charset.StandardCharsets;
@@ -43,10 +48,11 @@ import java.util.zip.ZipOutputStream;
  *
  * @author Lion Li
  */
+@DS("#header.datasource")
 @Slf4j
 @RequiredArgsConstructor
 @Service
-public class GenTableServiceImpl extends BaseGenTableServiceImpl {
+public class GenTableServiceImpl implements IGenTableService {
 
     private final GenTableMapper baseMapper;
     private final GenTableColumnMapper genTableColumnMapper;
@@ -107,7 +113,7 @@ public class GenTableServiceImpl extends BaseGenTableServiceImpl {
 
     @Override
     public TableDataInfo<GenTable> selectPageDbTableList(GenTable genTable, PageQuery pageQuery) {
-        Page<GenTable> page = baseMapper.selectPageDbTableList(pageQuery.build(), this.buildDbTableQueryWrapper(genTable));
+        Page<GenTable> page = baseMapper.selectPageDbTableList(pageQuery.build(), genTable);
         return TableDataInfo.build(page);
     }
 
@@ -119,22 +125,7 @@ public class GenTableServiceImpl extends BaseGenTableServiceImpl {
      */
     @Override
     public List<GenTable> selectDbTableList(GenTable genTable) {
-        return baseMapper.selectDbTableList(this.buildDbTableQueryWrapper(genTable));
-    }
-
-    private Wrapper<Object> buildDbTableQueryWrapper(GenTable genTable) {
-        Map<String, Object> params = genTable.getParams();
-        QueryWrapper<Object> wrapper = Wrappers.query();
-        wrapper.apply("table_schema = (select database())")
-            .notLike("table_name", "xxl_job_")
-            .notLike("table_name", "gen_")
-            .notInSql("table_name", "select table_name from gen_table")
-            .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,
-                "create_time", params.get("beginTime"), params.get("endTime"))
-            .orderByDesc("create_time");
-        return wrapper;
+        return baseMapper.selectDbTableList(genTable);
     }
 
     /**
@@ -251,6 +242,21 @@ public class GenTableServiceImpl extends BaseGenTableServiceImpl {
         return dataMap;
     }
 
+    /**
+     * 生成代码(下载方式)
+     *
+     * @param tableName 表名称
+     * @return 数据
+     */
+    @Override
+    public byte[] downloadCode(String tableName) {
+        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+        ZipOutputStream zip = new ZipOutputStream(outputStream);
+        generatorCode(tableName, zip);
+        IoUtil.close(zip);
+        return outputStream.toByteArray();
+    }
+
     /**
      * 生成代码(自定义路径)
      *
@@ -339,10 +345,26 @@ public class GenTableServiceImpl extends BaseGenTableServiceImpl {
     }
 
     /**
-     * 查询表信息并生成代码
+     * 批量生成代码(下载方式)
+     *
+     * @param tableNames 表数组
+     * @return 数据
      */
     @Override
-    public void generatorCode(String tableName, ZipOutputStream zip) {
+    public byte[] downloadCode(String[] tableNames) {
+        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+        ZipOutputStream zip = new ZipOutputStream(outputStream);
+        for (String tableName : tableNames) {
+            generatorCode(tableName, zip);
+        }
+        IoUtil.close(zip);
+        return outputStream.toByteArray();
+    }
+
+    /**
+     * 查询表信息并生成代码
+     */
+    private void generatorCode(String tableName, ZipOutputStream zip) {
         // 查询表信息
         GenTable table = baseMapper.selectGenTableByName(tableName);
         // 设置主子表信息
@@ -374,6 +396,60 @@ public class GenTableServiceImpl extends BaseGenTableServiceImpl {
         }
     }
 
+    /**
+     * 修改保存参数校验
+     *
+     * @param genTable 业务信息
+     */
+    @Override
+    public void validateEdit(GenTable genTable) {
+        if (GenConstants.TPL_TREE.equals(genTable.getTplCategory())) {
+            String options = JsonUtils.toJsonString(genTable.getParams());
+            Dict paramsObj = JsonUtils.parseMap(options);
+            if (StringUtils.isEmpty(paramsObj.getStr(GenConstants.TREE_CODE))) {
+                throw new ServiceException("树编码字段不能为空");
+            } else if (StringUtils.isEmpty(paramsObj.getStr(GenConstants.TREE_PARENT_CODE))) {
+                throw new ServiceException("树父编码字段不能为空");
+            } else if (StringUtils.isEmpty(paramsObj.getStr(GenConstants.TREE_NAME))) {
+                throw new ServiceException("树名称字段不能为空");
+            } else if (GenConstants.TPL_SUB.equals(genTable.getTplCategory())) {
+                if (StringUtils.isEmpty(genTable.getSubTableName())) {
+                    throw new ServiceException("关联子表的表名不能为空");
+                } else if (StringUtils.isEmpty(genTable.getSubTableFkName())) {
+                    throw new ServiceException("子表关联的外键名不能为空");
+                }
+            }
+        }
+    }
+
+    /**
+     * 设置主键列信息
+     *
+     * @param table 业务表信息
+     */
+    public void setPkColumn(GenTable table) {
+        for (GenTableColumn column : table.getColumns()) {
+            if (column.isPk()) {
+                table.setPkColumn(column);
+                break;
+            }
+        }
+        if (ObjectUtil.isNull(table.getPkColumn())) {
+            table.setPkColumn(table.getColumns().get(0));
+        }
+        if (GenConstants.TPL_SUB.equals(table.getTplCategory())) {
+            for (GenTableColumn column : table.getSubTable().getColumns()) {
+                if (column.isPk()) {
+                    table.getSubTable().setPkColumn(column);
+                    break;
+                }
+            }
+            if (ObjectUtil.isNull(table.getSubTable().getPkColumn())) {
+                table.getSubTable().setPkColumn(table.getSubTable().getColumns().get(0));
+            }
+        }
+    }
+
     /**
      * 设置主子表信息
      *
@@ -386,4 +462,41 @@ public class GenTableServiceImpl extends BaseGenTableServiceImpl {
         }
     }
 
+    /**
+     * 设置代码生成其他选项值
+     *
+     * @param genTable 设置后的生成对象
+     */
+    public void setTableFromOptions(GenTable genTable) {
+        Dict paramsObj = JsonUtils.parseMap(genTable.getOptions());
+        if (ObjectUtil.isNotNull(paramsObj)) {
+            String treeCode = paramsObj.getStr(GenConstants.TREE_CODE);
+            String treeParentCode = paramsObj.getStr(GenConstants.TREE_PARENT_CODE);
+            String treeName = paramsObj.getStr(GenConstants.TREE_NAME);
+            String parentMenuId = paramsObj.getStr(GenConstants.PARENT_MENU_ID);
+            String parentMenuName = paramsObj.getStr(GenConstants.PARENT_MENU_NAME);
+
+            genTable.setTreeCode(treeCode);
+            genTable.setTreeParentCode(treeParentCode);
+            genTable.setTreeName(treeName);
+            genTable.setParentMenuId(parentMenuId);
+            genTable.setParentMenuName(parentMenuName);
+        }
+    }
+
+    /**
+     * 获取代码生成地址
+     *
+     * @param table    业务表信息
+     * @param template 模板文件路径
+     * @return 生成地址
+     */
+    public static String getGenPath(GenTable table, String template) {
+        String genPath = table.getGenPath();
+        if (StringUtils.equals(genPath, "/")) {
+            return System.getProperty("user.dir") + File.separator + "src" + File.separator + VelocityUtils.getFileName(template, table);
+        }
+        return genPath + File.separator + VelocityUtils.getFileName(template, table);
+    }
 }
+

+ 0 - 391
ruoyi-generator/src/main/java/com/ruoyi/generator/service/OracleGenTableServiceImpl.java

@@ -1,391 +0,0 @@
-package com.ruoyi.generator.service;
-
-import cn.hutool.core.collection.CollUtil;
-import cn.hutool.core.io.IoUtil;
-import com.baomidou.mybatisplus.core.conditions.Wrapper;
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.core.toolkit.Wrappers;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.ruoyi.common.constant.Constants;
-import com.ruoyi.common.core.domain.PageQuery;
-import com.ruoyi.common.core.page.TableDataInfo;
-import com.ruoyi.common.exception.ServiceException;
-import com.ruoyi.common.helper.LoginHelper;
-import com.ruoyi.common.utils.JsonUtils;
-import com.ruoyi.common.utils.StringUtils;
-import com.ruoyi.common.utils.file.FileUtils;
-import com.ruoyi.generator.domain.GenTable;
-import com.ruoyi.generator.domain.GenTableColumn;
-import com.ruoyi.generator.mapper.OracleGenTableColumnMapper;
-import com.ruoyi.generator.mapper.OracleGenTableMapper;
-import com.ruoyi.generator.util.GenUtils;
-import com.ruoyi.generator.util.VelocityInitializer;
-import com.ruoyi.generator.util.VelocityUtils;
-import lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.velocity.Template;
-import org.apache.velocity.VelocityContext;
-import org.apache.velocity.app.Velocity;
-import org.springframework.stereotype.Service;
-
-import java.io.IOException;
-import java.io.StringWriter;
-import java.nio.charset.StandardCharsets;
-import java.util.*;
-import java.util.function.Function;
-import java.util.stream.Collectors;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipOutputStream;
-
-/**
- * 业务 服务层实现
- *
- * @author Lion Li
- */
-@Slf4j
-@RequiredArgsConstructor
-@Service
-public class OracleGenTableServiceImpl extends BaseGenTableServiceImpl {
-
-    private final OracleGenTableMapper baseMapper;
-    private final OracleGenTableColumnMapper genTableColumnMapper;
-
-    /**
-     * 查询业务字段列表
-     *
-     * @param tableId 业务字段编号
-     * @return 业务字段集合
-     */
-    @Override
-    public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId) {
-        return genTableColumnMapper.selectList(new LambdaQueryWrapper<GenTableColumn>()
-            .eq(GenTableColumn::getTableId, tableId)
-            .orderByAsc(GenTableColumn::getSort));
-    }
-    /**
-     * 查询业务信息
-     *
-     * @param id 业务ID
-     * @return 业务信息
-     */
-    @Override
-    public GenTable selectGenTableById(Long id) {
-        GenTable genTable = baseMapper.selectGenTableById(id);
-        setTableFromOptions(genTable);
-        return genTable;
-    }
-
-    @Override
-    public TableDataInfo<GenTable> selectPageGenTableList(GenTable genTable, PageQuery pageQuery) {
-        Page<GenTable> page = baseMapper.selectPage(pageQuery.build(), this.buildGenTableQueryWrapper(genTable));
-        return TableDataInfo.build(page);
-    }
-
-    /**
-     * 查询业务列表
-     *
-     * @param genTable 业务信息
-     * @return 业务集合
-     */
-    @Override
-    public List<GenTable> selectGenTableList(GenTable genTable) {
-        return baseMapper.selectList(this.buildGenTableQueryWrapper(genTable));
-    }
-
-    private QueryWrapper<GenTable> buildGenTableQueryWrapper(GenTable genTable) {
-        Map<String, Object> params = genTable.getParams();
-        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,
-                "create_time", params.get("beginTime"), params.get("endTime"));
-        return wrapper;
-    }
-
-
-    @Override
-    public TableDataInfo<GenTable> selectPageDbTableList(GenTable genTable, PageQuery pageQuery) {
-        Page<GenTable> page = baseMapper.selectPageDbTableList(pageQuery.build(), this.buildDbTableQueryWrapper(genTable));
-        return TableDataInfo.build(page);
-    }
-
-    /**
-     * 查询据库列表
-     *
-     * @param genTable 业务信息
-     * @return 数据库表集合
-     */
-    @Override
-    public List<GenTable> selectDbTableList(GenTable genTable) {
-        return baseMapper.selectDbTableList(this.buildDbTableQueryWrapper(genTable));
-    }
-
-    private Wrapper<Object> buildDbTableQueryWrapper(GenTable genTable) {
-        Map<String, Object> params = genTable.getParams();
-        QueryWrapper<Object> wrapper = Wrappers.query();
-        wrapper.apply("dt.table_name = dtc.table_name")
-            .apply("dt.table_name = uo.object_name")
-            .eq("uo.object_type ", "TABLE")
-            .notLike("dt.table_name", "XXL_JOB_")
-            .notLike("dt.table_name", "GEN_")
-            .notInSql("lower(dt.table_name)", "select table_name from gen_table")
-            .like(StringUtils.isNotBlank(genTable.getTableName()), "lower(dt.table_name)", StringUtils.lowerCase(genTable.getTableName()))
-            .like(StringUtils.isNotBlank(genTable.getTableComment()), "lower(dt.table_comment)", StringUtils.lowerCase(genTable.getTableComment()))
-            .between(params.get("beginTime") != null && params.get("endTime") != null,
-                "create_time", params.get("beginTime"), params.get("endTime"))
-            .orderByDesc("create_time");
-        return wrapper;
-    }
-
-    /**
-     * 查询据库列表
-     *
-     * @param tableNames 表名称组
-     * @return 数据库表集合
-     */
-    @Override
-    public List<GenTable> selectDbTableListByNames(String[] tableNames) {
-        return baseMapper.selectDbTableListByNames(tableNames);
-    }
-
-    /**
-     * 查询所有表信息
-     *
-     * @return 表信息集合
-     */
-    @Override
-    public List<GenTable> selectGenTableAll() {
-        return baseMapper.selectGenTableAll();
-    }
-
-    /**
-     * 修改业务
-     *
-     * @param genTable 业务信息
-     * @return 结果
-     */
-    @Override
-    public void updateGenTable(GenTable genTable) {
-        String options = JsonUtils.toJsonString(genTable.getParams());
-        genTable.setOptions(options);
-        int row = baseMapper.updateById(genTable);
-        if (row > 0) {
-            for (GenTableColumn cenTableColumn : genTable.getColumns()) {
-                genTableColumnMapper.updateById(cenTableColumn);
-            }
-        }
-    }
-
-    /**
-     * 删除业务对象
-     *
-     * @param tableIds 需要删除的数据ID
-     * @return 结果
-     */
-    @Override
-    public void deleteGenTableByIds(Long[] tableIds) {
-        List<Long> ids = Arrays.asList(tableIds);
-        baseMapper.deleteBatchIds(ids);
-        genTableColumnMapper.delete(new LambdaQueryWrapper<GenTableColumn>().in(GenTableColumn::getTableId, ids));
-    }
-
-    /**
-     * 导入表结构
-     *
-     * @param tableList 导入表列表
-     */
-    @Override
-    public void importGenTable(List<GenTable> tableList) {
-        String operName = LoginHelper.getUsername();
-        try {
-            for (GenTable table : tableList) {
-                String tableName = table.getTableName();
-                GenUtils.initTable(table, operName);
-                int row = baseMapper.insert(table);
-                if (row > 0) {
-                    // 保存列信息
-                    List<GenTableColumn> genTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName);
-                    List<GenTableColumn> saveColumns = new ArrayList<>();
-                    for (GenTableColumn column : genTableColumns) {
-                        GenUtils.initColumnField(column, table);
-                        saveColumns.add(column);
-                    }
-                    if (CollUtil.isNotEmpty(saveColumns)) {
-                        genTableColumnMapper.insertBatch(saveColumns);
-                    }
-                }
-            }
-        } catch (Exception e) {
-            throw new ServiceException("导入失败:" + e.getMessage());
-        }
-    }
-
-    /**
-     * 预览代码
-     *
-     * @param tableId 表编号
-     * @return 预览数据列表
-     */
-    @Override
-    public Map<String, String> previewCode(Long tableId) {
-        Map<String, String> dataMap = new LinkedHashMap<>();
-        // 查询表信息
-        GenTable table = baseMapper.selectGenTableById(tableId);
-        // 设置主子表信息
-        setSubTable(table);
-        // 设置主键列信息
-        setPkColumn(table);
-        VelocityInitializer.initVelocity();
-
-        VelocityContext context = VelocityUtils.prepareContext(table);
-
-        // 获取模板列表
-        List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory());
-        for (String template : templates) {
-            // 渲染模板
-            StringWriter sw = new StringWriter();
-            Template tpl = Velocity.getTemplate(template, Constants.UTF8);
-            tpl.merge(context, sw);
-            dataMap.put(template, sw.toString());
-        }
-        return dataMap;
-    }
-
-    /**
-     * 生成代码(自定义路径)
-     *
-     * @param tableName 表名称
-     */
-    @Override
-    public void generatorCode(String tableName) {
-        // 查询表信息
-        GenTable table = baseMapper.selectGenTableByName(tableName);
-        // 设置主子表信息
-        setSubTable(table);
-        // 设置主键列信息
-        setPkColumn(table);
-
-        VelocityInitializer.initVelocity();
-
-        VelocityContext context = VelocityUtils.prepareContext(table);
-
-        // 获取模板列表
-        List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory());
-        for (String template : templates) {
-            if (!StringUtils.containsAny(template, "sql.vm", "api.js.vm", "index.vue.vm", "index-tree.vue.vm")) {
-                // 渲染模板
-                StringWriter sw = new StringWriter();
-                Template tpl = Velocity.getTemplate(template, Constants.UTF8);
-                tpl.merge(context, sw);
-                try {
-                    String path = getGenPath(table, template);
-                    FileUtils.writeUtf8String(sw.toString(), path);
-                } catch (Exception e) {
-                    throw new ServiceException("渲染模板失败,表名:" + table.getTableName());
-                }
-            }
-        }
-    }
-
-    /**
-     * 同步数据库
-     *
-     * @param tableName 表名称
-     */
-    @Override
-    public void synchDb(String tableName) {
-        GenTable table = baseMapper.selectGenTableByName(tableName);
-        List<GenTableColumn> tableColumns = table.getColumns();
-        Map<String, GenTableColumn> tableColumnMap = tableColumns.stream().collect(Collectors.toMap(GenTableColumn::getColumnName, Function.identity()));
-
-        List<GenTableColumn> dbTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName);
-        if (CollUtil.isEmpty(dbTableColumns)) {
-            throw new ServiceException("同步数据失败,原表结构不存在");
-        }
-        List<String> dbTableColumnNames = dbTableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList());
-
-        List<GenTableColumn> saveColumns = new ArrayList<>();
-        dbTableColumns.forEach(column -> {
-            GenUtils.initColumnField(column, table);
-            if (tableColumnMap.containsKey(column.getColumnName())) {
-                GenTableColumn prevColumn = tableColumnMap.get(column.getColumnName());
-                column.setColumnId(prevColumn.getColumnId());
-                if (column.isList()) {
-                    // 如果是列表,继续保留查询方式/字典类型选项
-                    column.setDictType(prevColumn.getDictType());
-                    column.setQueryType(prevColumn.getQueryType());
-                }
-                if (StringUtils.isNotEmpty(prevColumn.getIsRequired()) && !column.isPk()
-                    && (column.isInsert() || column.isEdit())
-                    && ((column.isUsableColumn()) || (!column.isSuperColumn())))
-                {
-                    // 如果是(新增/修改&非主键/非忽略及父属性),继续保留必填/显示类型选项
-                    column.setIsRequired(prevColumn.getIsRequired());
-                    column.setHtmlType(prevColumn.getHtmlType());
-                }
-                genTableColumnMapper.updateById(column);
-            } else {
-                genTableColumnMapper.insert(column);
-            }
-        });
-        if (CollUtil.isNotEmpty(saveColumns)) {
-            genTableColumnMapper.insertBatch(saveColumns);
-        }
-
-        List<GenTableColumn> delColumns = tableColumns.stream().filter(column -> !dbTableColumnNames.contains(column.getColumnName())).collect(Collectors.toList());
-        if (CollUtil.isNotEmpty(delColumns)) {
-            List<Long> ids = delColumns.stream().map(GenTableColumn::getColumnId).collect(Collectors.toList());
-            genTableColumnMapper.deleteBatchIds(ids);
-        }
-    }
-
-    /**
-     * 查询表信息并生成代码
-     */
-    @Override
-    public void generatorCode(String tableName, ZipOutputStream zip) {
-        // 查询表信息
-        GenTable table = baseMapper.selectGenTableByName(tableName);
-        // 设置主子表信息
-        setSubTable(table);
-        // 设置主键列信息
-        setPkColumn(table);
-
-        VelocityInitializer.initVelocity();
-
-        VelocityContext context = VelocityUtils.prepareContext(table);
-
-        // 获取模板列表
-        List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory());
-        for (String template : templates) {
-            // 渲染模板
-            StringWriter sw = new StringWriter();
-            Template tpl = Velocity.getTemplate(template, Constants.UTF8);
-            tpl.merge(context, sw);
-            try {
-                // 添加到zip
-                zip.putNextEntry(new ZipEntry(VelocityUtils.getFileName(template, table)));
-                IoUtil.write(zip, StandardCharsets.UTF_8, false, sw.toString());
-                IoUtil.close(sw);
-                zip.flush();
-                zip.closeEntry();
-            } catch (IOException e) {
-                log.error("渲染模板失败,表名:" + table.getTableName(), e);
-            }
-        }
-    }
-
-    /**
-     * 设置主子表信息
-     *
-     * @param table 业务表信息
-     */
-    public void setSubTable(GenTable table) {
-        String subTableName = table.getSubTableName();
-        if (StringUtils.isNotEmpty(subTableName)) {
-            table.setSubTable(baseMapper.selectGenTableByName(subTableName));
-        }
-    }
-
-}

+ 35 - 3
ruoyi-generator/src/main/resources/mapper/generator/GenTableColumnMapper.xml

@@ -30,9 +30,41 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </resultMap>
 
     <select id="selectDbTableColumnsByName" parameterType="String" resultMap="GenTableColumnResult">
-        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, 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_schema = (select database()) and table_name = (#{tableName})
-        order by ordinal_position
+        <if test="@com.ruoyi.common.helper.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,
+                   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_schema = (select database()) and table_name = (#{tableName})
+            order by ordinal_position
+        </if>
+        <if test="@com.ruoyi.common.helper.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,
+                    temp.column_id as sort,
+                    temp.comments as column_comment,
+                    (case when temp.constraint_type = 'P' then '1' else '0' end) as is_increment,
+                    lower(temp.data_type) as column_type
+            from (
+                select col.column_id, col.column_name,col.nullable, col.data_type, colc.comments, uc.constraint_type, row_number()
+                    over (partition by col.column_name order by uc.constraint_type desc) as row_flg
+                from user_tab_columns col
+                left join user_col_comments colc on colc.table_name = col.table_name and colc.column_name = col.column_name
+                left join user_cons_columns ucc on ucc.table_name = col.table_name and ucc.column_name = col.column_name
+                left join user_constraints uc on uc.constraint_name = ucc.constraint_name
+                where col.table_name = upper(#{tableName})
+            ) temp
+            WHERE temp.row_flg = 1
+            ORDER BY temp.column_id
+        </if>
+        <if test="@com.ruoyi.common.helper.DataBaseHelper@isPostgerSql()">
+        </if>
+        <if test="@com.ruoyi.common.helper.DataBaseHelper@isSqlServer()">
+        </if>
     </select>
 
 </mapper>

+ 110 - 15
ruoyi-generator/src/main/resources/mapper/generator/GenTableMapper.xml

@@ -54,30 +54,125 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </resultMap>
 
     <select id="selectPageDbTableList" resultMap="GenTableResult">
-        select table_name, table_comment, create_time, update_time
-        from information_schema.tables
-        ${ew.getCustomSqlSegment}
+        <if test="@com.ruoyi.common.helper.DataBaseHelper@isMySql()">
+            select table_name, table_comment, create_time, update_time
+            from information_schema.tables
+            AND table_name NOT LIKE 'qrtz_%' AND table_name NOT LIKE 'gen_%'
+            AND table_name NOT IN (select table_name from gen_table)
+            <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 create_time desc
+        </if>
+        <if test="@com.ruoyi.common.helper.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 'QRTZ_%' AND dt.table_name NOT LIKE 'GEN_%'
+            AND lower(dt.table_name) NOT IN (select table_name from gen_table)
+            <if test="genTable.tableName != null and genTable.tableName != ''">
+                AND lower(dt.table_name) like lower(concat(concat('%', #{genTable.tableName}), '%'))
+            </if>
+            <if test="genTable.tableComment != null and genTable.tableComment != ''">
+                AND lower(dtc.comments) like lower(concat(concat('%', #{genTable.tableComment}), '%'))
+            </if>
+            order by create_time desc
+        </if>
+        <if test="@com.ruoyi.common.helper.DataBaseHelper@isPostgerSql()">
+        </if>
+        <if test="@com.ruoyi.common.helper.DataBaseHelper@isSqlServer()">
+        </if>
     </select>
 
     <select id="selectDbTableList" resultMap="GenTableResult">
-        select table_name, table_comment, create_time, update_time
-        from information_schema.tables
-        ${ew.getCustomSqlSegment}
+        <if test="@com.ruoyi.common.helper.DataBaseHelper@isMySql()">
+            select table_name, table_comment, create_time, update_time
+            from information_schema.tables
+            AND table_name NOT LIKE 'qrtz_%' AND table_name NOT LIKE 'gen_%'
+            AND table_name NOT IN (select table_name from gen_table)
+            <if test="tableName != null and tableName != ''">
+                AND lower(table_name) like lower(concat('%', #{tableName}, '%'))
+            </if>
+            <if test="tableComment != null and tableComment != ''">
+                AND lower(table_comment) like lower(concat('%', #{tableComment}, '%'))
+            </if>
+            order by create_time desc
+        </if>
+        <if test="@com.ruoyi.common.helper.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 'QRTZ_%' AND dt.table_name NOT LIKE 'GEN_%'
+            AND lower(dt.table_name) NOT IN (select table_name from gen_table)
+            <if test="tableName != null and tableName != ''">
+                AND lower(dt.table_name) like lower(concat(concat('%', #{tableName}), '%'))
+            </if>
+            <if test="tableComment != null and tableComment != ''">
+                AND lower(dtc.comments) like lower(concat(concat('%', #{tableComment}), '%'))
+            </if>
+            order by create_time desc
+        </if>
+        <if test="@com.ruoyi.common.helper.DataBaseHelper@isPostgerSql()">
+        </if>
+        <if test="@com.ruoyi.common.helper.DataBaseHelper@isSqlServer()">
+        </if>
     </select>
 
     <select id="selectDbTableListByNames" resultMap="GenTableResult">
-        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())
-        and table_name in
-        <foreach collection="array" item="name" open="(" separator="," close=")">
-             #{name}
-        </foreach>
+        <if test="@com.ruoyi.common.helper.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())
+            and table_name in
+            <foreach collection="array" item="name" open="(" separator="," close=")">
+                 #{name}
+            </foreach>
+        </if>
+        <if test="@com.ruoyi.common.helper.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 lower(dt.table_name) in
+            <foreach collection="array" item="name" open="(" separator="," close=")">
+                #{name}
+            </foreach>
+        </if>
+        <if test="@com.ruoyi.common.helper.DataBaseHelper@isPostgerSql()">
+        </if>
+        <if test="@com.ruoyi.common.helper.DataBaseHelper@isSqlServer()">
+        </if>
     </select>
 
     <select id="selectTableByName" parameterType="String" resultMap="GenTableResult">
-        select table_name, table_comment, create_time, update_time from information_schema.tables
-        where table_comment <![CDATA[ <> ]]> '' and table_schema = (select database())
-        and table_name = #{tableName}
+        <if test="@com.ruoyi.common.helper.DataBaseHelper@isMySql()">
+            select table_name, table_comment, create_time, update_time from information_schema.tables
+            where table_comment <![CDATA[ <> ]]> '' and table_schema = (select database())
+            and table_name = #{tableName}
+        </if>
+        <if test="@com.ruoyi.common.helper.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 lower(dt.table_name) = #{tableName}
+        </if>
+        <if test="@com.ruoyi.common.helper.DataBaseHelper@isPostgerSql()">
+        </if>
+        <if test="@com.ruoyi.common.helper.DataBaseHelper@isSqlServer()">
+        </if>
     </select>
 
     <select id="selectGenTableById" parameterType="Long" resultMap="GenTableResult">

+ 0 - 53
ruoyi-generator/src/main/resources/mapper/generator/OracleGenTableColumnMapper.xml

@@ -1,53 +0,0 @@
-<?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.ruoyi.generator.mapper.OracleGenTableColumnMapper">
-
-    <resultMap type="GenTableColumn" id="GenTableColumnResult">
-        <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="selectDbTableColumnsByName" parameterType="String" resultMap="GenTableColumnResult">
-        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,
-               temp.column_id as sort,
-               temp.comments as column_comment,
-               (case when temp.constraint_type = 'P' then '1' else '0' end) as is_increment,
-               lower(temp.data_type) as column_type
-        from (
-                 select col.column_id, col.column_name,col.nullable, col.data_type, colc.comments, uc.constraint_type
-                      , row_number() over (partition by col.column_name order by uc.constraint_type desc) as row_flg
-                 from user_tab_columns col
-                          left join user_col_comments colc on colc.table_name = col.table_name and colc.column_name = col.column_name
-                          left join user_cons_columns ucc on ucc.table_name = col.table_name and ucc.column_name = col.column_name
-                          left join user_constraints uc on uc.constraint_name = ucc.constraint_name
-                 where col.table_name = upper(#{tableName})
-             ) temp
-        WHERE temp.row_flg = 1
-        ORDER BY temp.column_id
-    </select>
-
-</mapper>

+ 0 - 117
ruoyi-generator/src/main/resources/mapper/generator/OracleGenTableMapper.xml

@@ -1,117 +0,0 @@
-<?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.ruoyi.generator.mapper.OracleGenTableMapper">
-
-    <resultMap type="GenTable" id="GenTableResult">
-        <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="GenTableColumn" id="GenTableColumnResult">
-        <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">
-        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
-        ${ew.getCustomSqlSegment}
-    </select>
-
-    <select id="selectDbTableList" resultMap="GenTableResult">
-        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
-        ${ew.getCustomSqlSegment}
-    </select>
-
-    <select id="selectDbTableListByNames" resultMap="GenTableResult">
-        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 lower(dt.table_name) in
-        <foreach collection="array" item="name" open="(" separator="," close=")">
-            #{name}
-        </foreach>
-    </select>
-
-    <select id="selectTableByName" parameterType="String" resultMap="GenTableResult">
-        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 lower(dt.table_name) = #{tableName}
-    </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,
-               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
-        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,
-               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
-        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,
-               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
-        order by c.sort
-    </select>
-
-</mapper>