From 7f1356a447d290c186fe047af557e050497e39e4 Mon Sep 17 00:00:00 2001
From: 疯狂的狮子li <15040126243@163.com>
Date: 星期一, 14 三月 2022 14:05:37 +0800
Subject: [PATCH] update 重构代码生成 多数据库sql加载 使用xml特性动态切换sql

---
 ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableServiceImpl.java |  155 ++++++++++++++++--
 /dev/null                                                                          |  117 --------------
 ruoyi-common/src/main/java/com/ruoyi/common/helper/DataBaseHelper.java             |   12 
 ruoyi-generator/src/main/resources/mapper/generator/GenTableMapper.xml             |  125 +++++++++++++-
 ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/GenTableMapper.java       |    8 
 ruoyi-generator/src/main/resources/mapper/generator/GenTableColumnMapper.xml       |   38 ++++
 6 files changed, 288 insertions(+), 167 deletions(-)

diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/helper/DataBaseHelper.java b/ruoyi-common/src/main/java/com/ruoyi/common/helper/DataBaseHelper.java
index 55a3a41..c1adea3 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/helper/DataBaseHelper.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/helper/DataBaseHelper.java
@@ -23,7 +23,7 @@
     /**
      * 鑾峰彇褰撳墠鏁版嵁搴撶被鍨�
      */
-    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 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
diff --git a/ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/GenTableMapper.java b/ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/GenTableMapper.java
index 37119a5..29bfe0d 100644
--- a/ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/GenTableMapper.java
+++ b/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 @@
 @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);
 
     /**
      * 鏌ヨ鎹簱鍒楄〃
diff --git a/ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/OracleGenTableColumnMapper.java b/ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/OracleGenTableColumnMapper.java
deleted file mode 100644
index b14f2e6..0000000
--- a/ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/OracleGenTableColumnMapper.java
+++ /dev/null
@@ -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);
-
-}
diff --git a/ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/OracleGenTableMapper.java b/ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/OracleGenTableMapper.java
deleted file mode 100644
index 23a5fed..0000000
--- a/ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/OracleGenTableMapper.java
+++ /dev/null
@@ -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();
-
-    /**
-     * 鏌ヨ琛↖D涓氬姟淇℃伅
-     *
-     * @param id 涓氬姟ID
-     * @return 涓氬姟淇℃伅
-     */
-    GenTable selectGenTableById(Long id);
-
-    /**
-     * 鏌ヨ琛ㄥ悕绉颁笟鍔′俊鎭�
-     *
-     * @param tableName 琛ㄥ悕绉�
-     * @return 涓氬姟淇℃伅
-     */
-    GenTable selectGenTableByName(String tableName);
-
-}
diff --git a/ruoyi-generator/src/main/java/com/ruoyi/generator/service/BaseGenTableServiceImpl.java b/ruoyi-generator/src/main/java/com/ruoyi/generator/service/BaseGenTableServiceImpl.java
deleted file mode 100644
index 6d3034f..0000000
--- a/ruoyi-generator/src/main/java/com/ruoyi/generator/service/BaseGenTableServiceImpl.java
+++ /dev/null
@@ -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);
-    }
-
-    /**
-     * 棰勮浠g爜
-     *
-     * @param tableId 琛ㄧ紪鍙�
-     * @return 棰勮鏁版嵁鍒楄〃
-     */
-    @Override
-    public Map<String, String> previewCode(Long tableId) {
-        return getService().previewCode(tableId);
-    }
-
-    /**
-     * 鐢熸垚浠g爜锛堜笅杞芥柟寮忥級
-     *
-     * @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();
-    }
-
-    /**
-     * 鐢熸垚浠g爜锛堣嚜瀹氫箟璺緞锛�
-     *
-     * @param tableName 琛ㄥ悕绉�
-     */
-    @Override
-    public void generatorCode(String tableName) {
-        getService().generatorCode(tableName);
-    }
-
-    /**
-     * 鍚屾鏁版嵁搴�
-     *
-     * @param tableName 琛ㄥ悕绉�
-     */
-    @Override
-    public void synchDb(String tableName) {
-        getService().synchDb(tableName);
-    }
-
-    /**
-     * 鎵归噺鐢熸垚浠g爜锛堜笅杞芥柟寮忥級
-     *
-     * @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();
-    }
-
-    /**
-     * 鏌ヨ琛ㄤ俊鎭苟鐢熸垚浠g爜
-     */
-    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));
-            }
-        }
-    }
-
-    /**
-     * 璁剧疆浠g爜鐢熸垚鍏朵粬閫夐」鍊�
-     *
-     * @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);
-        }
-    }
-
-    /**
-     * 鑾峰彇浠g爜鐢熸垚鍦板潃
-     *
-     * @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);
-    }
-}
diff --git a/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableServiceImpl.java b/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableServiceImpl.java
index f957009..ac0c6be 100644
--- a/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableServiceImpl.java
+++ b/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableServiceImpl.java
@@ -2,12 +2,15 @@
 
 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.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 @@
  *
  * @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 @@
 
     @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 @@
      */
     @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);
     }
 
     /**
@@ -252,6 +243,21 @@
     }
 
     /**
+     * 鐢熸垚浠g爜锛堜笅杞芥柟寮忥級
+     *
+     * @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();
+    }
+
+    /**
      * 鐢熸垚浠g爜锛堣嚜瀹氫箟璺緞锛�
      *
      * @param tableName 琛ㄥ悕绉�
@@ -339,10 +345,26 @@
     }
 
     /**
-     * 鏌ヨ琛ㄤ俊鎭苟鐢熸垚浠g爜
+     * 鎵归噺鐢熸垚浠g爜锛堜笅杞芥柟寮忥級
+     *
+     * @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();
+    }
+
+    /**
+     * 鏌ヨ琛ㄤ俊鎭苟鐢熸垚浠g爜
+     */
+    private void generatorCode(String tableName, ZipOutputStream zip) {
         // 鏌ヨ琛ㄤ俊鎭�
         GenTable table = baseMapper.selectGenTableByName(tableName);
         // 璁剧疆涓诲瓙琛ㄤ俊鎭�
@@ -375,6 +397,60 @@
     }
 
     /**
+     * 淇敼淇濆瓨鍙傛暟鏍¢獙
+     *
+     * @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 table 涓氬姟琛ㄤ俊鎭�
@@ -386,4 +462,41 @@
         }
     }
 
+    /**
+     * 璁剧疆浠g爜鐢熸垚鍏朵粬閫夐」鍊�
+     *
+     * @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);
+        }
+    }
+
+    /**
+     * 鑾峰彇浠g爜鐢熸垚鍦板潃
+     *
+     * @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);
+    }
 }
+
diff --git a/ruoyi-generator/src/main/java/com/ruoyi/generator/service/OracleGenTableServiceImpl.java b/ruoyi-generator/src/main/java/com/ruoyi/generator/service/OracleGenTableServiceImpl.java
deleted file mode 100644
index 79550d5..0000000
--- a/ruoyi-generator/src/main/java/com/ruoyi/generator/service/OracleGenTableServiceImpl.java
+++ /dev/null
@@ -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());
-        }
-    }
-
-    /**
-     * 棰勮浠g爜
-     *
-     * @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;
-    }
-
-    /**
-     * 鐢熸垚浠g爜锛堣嚜瀹氫箟璺緞锛�
-     *
-     * @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);
-        }
-    }
-
-    /**
-     * 鏌ヨ琛ㄤ俊鎭苟鐢熸垚浠g爜
-     */
-    @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 {
-                // 娣诲姞鍒皕ip
-                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));
-        }
-    }
-
-}
diff --git a/ruoyi-generator/src/main/resources/mapper/generator/GenTableColumnMapper.xml b/ruoyi-generator/src/main/resources/mapper/generator/GenTableColumnMapper.xml
index 7ef9744..4614dd4 100644
--- a/ruoyi-generator/src/main/resources/mapper/generator/GenTableColumnMapper.xml
+++ b/ruoyi-generator/src/main/resources/mapper/generator/GenTableColumnMapper.xml
@@ -30,9 +30,41 @@
     </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>
diff --git a/ruoyi-generator/src/main/resources/mapper/generator/GenTableMapper.xml b/ruoyi-generator/src/main/resources/mapper/generator/GenTableMapper.xml
index cb437b4..306f7af 100644
--- a/ruoyi-generator/src/main/resources/mapper/generator/GenTableMapper.xml
+++ b/ruoyi-generator/src/main/resources/mapper/generator/GenTableMapper.xml
@@ -54,30 +54,125 @@
     </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">
diff --git a/ruoyi-generator/src/main/resources/mapper/generator/OracleGenTableColumnMapper.xml b/ruoyi-generator/src/main/resources/mapper/generator/OracleGenTableColumnMapper.xml
deleted file mode 100644
index 9317ab1..0000000
--- a/ruoyi-generator/src/main/resources/mapper/generator/OracleGenTableColumnMapper.xml
+++ /dev/null
@@ -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>
diff --git a/ruoyi-generator/src/main/resources/mapper/generator/OracleGenTableMapper.xml b/ruoyi-generator/src/main/resources/mapper/generator/OracleGenTableMapper.xml
deleted file mode 100644
index 5bf1a20..0000000
--- a/ruoyi-generator/src/main/resources/mapper/generator/OracleGenTableMapper.xml
+++ /dev/null
@@ -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>

--
Gitblit v1.9.3