Explorar el Código

代码生成优化

xiongwanxiong hace 3 meses
padre
commit
2ec7e1ecaa
Se han modificado 33 ficheros con 3521 adiciones y 2930 borrados
  1. 0 247
      wxjy-wxjy-service/src/main/java/cn/gov/customs/wxjy/generator/controller/GenController.java
  2. 112 0
      wxjy-wxjy-service/src/main/java/cn/gov/customs/wxjy/generator/controller/GenTableColumnController.java
  3. 190 0
      wxjy-wxjy-service/src/main/java/cn/gov/customs/wxjy/generator/controller/GenTableController.java
  4. 50 34
      wxjy-wxjy-service/src/main/java/cn/gov/customs/wxjy/generator/dao/GenTableColumnMapper.java
  5. 46 61
      wxjy-wxjy-service/src/main/java/cn/gov/customs/wxjy/generator/dao/GenTableMapper.java
  6. 9 7
      wxjy-wxjy-service/src/main/java/cn/gov/customs/wxjy/generator/pojo/GenTable.java
  7. 9 8
      wxjy-wxjy-service/src/main/java/cn/gov/customs/wxjy/generator/pojo/GenTableColumn.java
  8. 75 0
      wxjy-wxjy-service/src/main/java/cn/gov/customs/wxjy/generator/pojo/GenTableColumnQuery.java
  9. 69 0
      wxjy-wxjy-service/src/main/java/cn/gov/customs/wxjy/generator/pojo/GenTableQuery.java
  10. 0 70
      wxjy-wxjy-service/src/main/java/cn/gov/customs/wxjy/generator/service/GenTableColumnServiceImpl.java
  11. 70 25
      wxjy-wxjy-service/src/main/java/cn/gov/customs/wxjy/generator/service/IGenTableColumnService.java
  12. 62 79
      wxjy-wxjy-service/src/main/java/cn/gov/customs/wxjy/generator/service/IGenTableService.java
  13. 175 0
      wxjy-wxjy-service/src/main/java/cn/gov/customs/wxjy/generator/service/impl/GenTableColumnServiceImpl.java
  14. 214 257
      wxjy-wxjy-service/src/main/java/cn/gov/customs/wxjy/generator/service/impl/GenTableServiceImpl.java
  15. 3 3
      wxjy-wxjy-service/src/main/java/cn/gov/customs/wxjy/generator/util/SysGenUtils.java
  16. 3 3
      wxjy-wxjy-service/src/main/java/cn/gov/customs/wxjy/generator/util/SysVelocityUtils.java
  17. 342 0
      wxjy-wxjy-service/src/main/resources/mapper/gen/GenTableColumnMapper.xml
  18. 359 0
      wxjy-wxjy-service/src/main/resources/mapper/gen/GenTableMapper.xml
  19. 0 183
      wxjy-wxjy-service/src/main/resources/mapper/generator/GenTableColumnMapper.xml
  20. 0 214
      wxjy-wxjy-service/src/main/resources/mapper/generator/GenTableMapper.xml
  21. 1 0
      wxjy-wxjy-web/package.json
  22. 34 91
      wxjy-wxjy-web/src/apis/gen/gen.ts
  23. 2 2
      wxjy-wxjy-web/src/router/app-router.ts
  24. 20 20
      wxjy-wxjy-web/src/types/base/PackCatalog.ts
  25. 57 0
      wxjy-wxjy-web/src/types/gen/GenTable.ts
  26. 46 0
      wxjy-wxjy-web/src/types/gen/GenTableColumn.ts
  27. 655 0
      wxjy-wxjy-web/src/views/gen/GenTable.vue
  28. 129 49
      wxjy-wxjy-web/src/views/gen/basicInfoForm.vue
  29. 0 70
      wxjy-wxjy-web/src/views/gen/createTable.vue
  30. 377 313
      wxjy-wxjy-web/src/views/gen/editTable.vue
  31. 0 734
      wxjy-wxjy-web/src/views/gen/genIndex.vue
  32. 256 327
      wxjy-wxjy-web/src/views/gen/genInfoForm.vue
  33. 156 133
      wxjy-wxjy-web/src/views/gen/importTable.vue

+ 0 - 247
wxjy-wxjy-service/src/main/java/cn/gov/customs/wxjy/generator/controller/GenController.java

@@ -1,247 +0,0 @@
-package cn.gov.customs.wxjy.generator.controller;
-
-import cn.gov.customs.wxjy.common.annotation.Log;
-import cn.gov.customs.wxjy.common.core.controller.BaseController;
-import cn.gov.customs.wxjy.common.core.domain.AjaxResult;
-import cn.gov.customs.wxjy.common.core.page.TableDataInfo;
-import cn.gov.customs.wxjy.common.core.text.Convert;
-import cn.gov.customs.wxjy.common.enums.BusinessType;
-import cn.gov.customs.wxjy.common.utils.SecurityUtils;
-import cn.gov.customs.wxjy.common.utils.sql.SqlUtil;
-import cn.gov.customs.wxjy.generator.domain.GenTable;
-import cn.gov.customs.wxjy.generator.domain.GenTableColumn;
-import cn.gov.customs.wxjy.generator.service.IGenTableColumnService;
-import cn.gov.customs.wxjy.generator.service.IGenTableService;
-import com.alibaba.druid.DbType;
-import com.alibaba.druid.sql.SQLUtils;
-import com.alibaba.druid.sql.ast.SQLStatement;
-import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement;
-import org.apache.commons.io.IOUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.validation.annotation.Validated;
-import org.springframework.web.bind.annotation.*;
-
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * 代码生成 操作处理
- * 
- * @author ruoyi
- */
-@RestController
-@RequestMapping("/tool/gen")
-public class GenController extends BaseController
-{
-    @Autowired
-    private IGenTableService genTableService;
-
-    @Autowired
-    private IGenTableColumnService genTableColumnService;
-
-    /**
-     * 查询代码生成列表
-     */
-//    @PreAuthorize("@ss.hasPermi('tool:gen:list')")
-    @GetMapping("/list")
-    public TableDataInfo genList(GenTable genTable)
-    {
-        startPage();
-        List<GenTable> list = genTableService.selectGenTableList(genTable);
-        return getDataTable(list);
-    }
-
-    /**
-     * 修改代码生成业务
-     */
-//    @PreAuthorize("@ss.hasPermi('tool:gen:query')")
-    @GetMapping(value = "/{tableId}")
-    public AjaxResult getInfo(@PathVariable Long tableId)
-    {
-        GenTable table = genTableService.selectGenTableById(tableId);
-        List<GenTable> tables = genTableService.selectGenTableAll();
-        List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(tableId);
-        Map<String, Object> map = new HashMap<String, Object>();
-        map.put("info", table);
-        map.put("rows", list);
-        map.put("tables", tables);
-        return success(map);
-    }
-
-    /**
-     * 查询数据库列表
-     */
-//    @PreAuthorize("@ss.hasPermi('tool:gen:list')")
-    @GetMapping("/db/list")
-    public TableDataInfo dataList(GenTable genTable)
-    {
-        startPage();
-        List<GenTable> list = genTableService.selectDbTableList(genTable);
-        return getDataTable(list);
-    }
-
-    /**
-     * 查询数据表字段列表
-     */
-//    @PreAuthorize("@ss.hasPermi('tool:gen:list')")
-    @GetMapping(value = "/column/{tableId}")
-    public TableDataInfo columnList(Long tableId)
-    {
-        TableDataInfo dataInfo = new TableDataInfo();
-        List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(tableId);
-        dataInfo.setRows(list);
-        dataInfo.setTotal(list.size());
-        return dataInfo;
-    }
-
-    /**
-     * 导入表结构(保存)
-     */
-//    @PreAuthorize("@ss.hasPermi('tool:gen:import')")
-    @Log(title = "代码生成", businessType = BusinessType.IMPORT)
-    @PostMapping("/importTable")
-    public AjaxResult importTableSave(String tables)
-    {
-        String[] tableNames = Convert.toStrArray(tables);
-        // 查询表信息
-        List<GenTable> tableList = genTableService.selectDbTableListByNames(tableNames);
-        genTableService.importGenTable(tableList, SecurityUtils.getUsername());
-        return success();
-    }
-
-    /**
-     * 创建表结构(保存)
-     */
-//    @PreAuthorize("@ss.hasRole('admin')")
-    @Log(title = "创建表", businessType = BusinessType.OTHER)
-    @PostMapping("/createTable")
-    public AjaxResult createTableSave(String sql)
-    {
-        try
-        {
-            SqlUtil.filterKeyword(sql);
-            List<SQLStatement> sqlStatements = SQLUtils.parseStatements(sql, DbType.kingbase);
-            List<String> tableNames = new ArrayList<>();
-            for (SQLStatement sqlStatement : sqlStatements)
-            {
-                if (sqlStatement instanceof MySqlCreateTableStatement)
-                {
-                    MySqlCreateTableStatement createTableStatement = (MySqlCreateTableStatement) sqlStatement;
-                    if (genTableService.createTable(createTableStatement.toString()))
-                    {
-                        String tableName = createTableStatement.getTableName().replaceAll("`", "");
-                        tableNames.add(tableName);
-                    }
-                }
-            }
-            List<GenTable> tableList = genTableService.selectDbTableListByNames(tableNames.toArray(new String[tableNames.size()]));
-            String operName = SecurityUtils.getUsername();
-            genTableService.importGenTable(tableList, operName);
-            return AjaxResult.success();
-        }
-        catch (Exception e)
-        {
-            logger.error(e.getMessage(), e);
-            return AjaxResult.error("创建表结构异常");
-        }
-    }
-
-    /**
-     * 修改保存代码生成业务
-     */
-    @Log(title = "代码生成", businessType = BusinessType.UPDATE)
-    @PutMapping
-    public AjaxResult editSave(@Validated @RequestBody GenTable genTable)
-    {
-        genTableService.validateEdit(genTable);
-        genTableService.updateGenTable(genTable);
-        return success();
-    }
-
-    /**
-     * 删除代码生成
-     */
-    @Log(title = "代码生成", businessType = BusinessType.DELETE)
-    @DeleteMapping("/{tableIds}")
-    public AjaxResult remove(@PathVariable Long[] tableIds)
-    {
-        genTableService.deleteGenTableByIds(tableIds);
-        return success();
-    }
-
-    /**
-     * 预览代码
-     */
-    @GetMapping("/preview/{tableId}")
-    public AjaxResult preview(@PathVariable("tableId") Long tableId) throws IOException
-    {
-        Map<String, String> dataMap = genTableService.previewCode(tableId);
-        return success(dataMap);
-    }
-
-    /**
-     * 生成代码(下载方式)
-     */
-//    @PreAuthorize("@ss.hasPermi('tool:gen:code')")
-    @Log(title = "代码生成", businessType = BusinessType.GENCODE)
-    @GetMapping("/download/{tableName}")
-    public void download(HttpServletResponse response, @PathVariable("tableName") String tableName) throws IOException
-    {
-        byte[] data = genTableService.downloadCode(tableName);
-        genCode(response, data);
-    }
-
-    /**
-     * 生成代码(自定义路径)
-     */
-//    @PreAuthorize("@ss.hasPermi('tool:gen:code')")
-    @Log(title = "代码生成", businessType = BusinessType.GENCODE)
-    @GetMapping("/genCode/{tableName}")
-    public AjaxResult genCode(@PathVariable("tableName") String tableName)
-    {
-        genTableService.generatorCode(tableName);
-        return success();
-    }
-
-    /**
-     * 同步数据库
-     */
-    @Log(title = "代码生成", businessType = BusinessType.UPDATE)
-    @GetMapping("/synchDb/{tableName}")
-    public AjaxResult synchDb(@PathVariable("tableName") String tableName)
-    {
-        genTableService.synchDb(tableName);
-        return success();
-    }
-
-    /**
-     * 批量生成代码
-     */
-//    @PreAuthorize("@ss.hasPermi('tool:gen:code')")
-    @Log(title = "代码生成", businessType = BusinessType.GENCODE)
-    @GetMapping("/batchGenCode")
-    public void batchGenCode(HttpServletResponse response, String tables) throws IOException
-    {
-        String[] tableNames = Convert.toStrArray(tables);
-        byte[] data = genTableService.downloadCode(tableNames);
-        genCode(response, data);
-    }
-
-    /**
-     * 生成zip文件
-     */
-    private void genCode(HttpServletResponse response, byte[] data) throws IOException
-    {
-        response.reset();
-        response.addHeader("Access-Control-Allow-Origin", "*");
-        response.addHeader("Access-Control-Expose-Headers", "Content-Disposition");
-        response.setHeader("Content-Disposition", "attachment; filename=\"rongji.zip\"");
-        response.addHeader("Content-Length", "" + data.length);
-        response.setContentType("application/octet-stream; charset=UTF-8");
-        IOUtils.write(data, response.getOutputStream());
-    }
-}

+ 112 - 0
wxjy-wxjy-service/src/main/java/cn/gov/customs/wxjy/generator/controller/GenTableColumnController.java

@@ -0,0 +1,112 @@
+package cn.gov.customs.wxjy.generator.controller;
+
+import cn.gov.customs.cacp.sdks.core.result.Result;
+import cn.gov.customs.cacp.sdks.core.user.trans.CacpTransUser;
+import cn.gov.customs.cacp.sdks.core.user.trans.UserContextHolder;
+import cn.gov.customs.wxjy.common.core.controller.BaseController;
+import cn.gov.customs.wxjy.common.utils.poi.ExcelUtil;
+import cn.gov.customs.wxjy.generator.pojo.GenTableColumn;
+import cn.gov.customs.wxjy.generator.pojo.GenTableColumnQuery;
+import cn.gov.customs.wxjy.generator.service.IGenTableColumnService;
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
+import lombok.RequiredArgsConstructor;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.servlet.http.HttpServletResponse;
+import java.util.List;
+
+/**
+ * 代码生成业务字段Controller
+ *
+ * @author xiong
+ * @date 2025-12-25
+ */
+@RestController
+@RequestMapping("/system/GenTableColumn")
+@RequiredArgsConstructor
+public class GenTableColumnController extends BaseController {
+
+    private final IGenTableColumnService genTableColumnService;
+
+    /**
+     * 查询代码生成业务字段列表
+     */
+    @PostMapping("/get-list")
+    public Result<PageInfo<GenTableColumn>> list(@RequestBody GenTableColumnQuery query) {
+        PageHelper.startPage(query.getPageIndex(), query.getPageSize());
+        PageInfo<GenTableColumn> list = genTableColumnService.selectPageList(query);
+        return Result.success(list);
+    }
+
+    /**
+     * 获取代码生成业务字段详细信息
+     */
+    @GetMapping(value = "/get-detail")
+    public Result<GenTableColumn> getInfo(@RequestParam String columnId) {
+        return Result.success(genTableColumnService.selectByColumnId(columnId));
+    }
+
+    /**
+     * 新增代码生成业务字段
+     */
+    @PostMapping("/insert-genTableColumn")
+    public Result<Integer> add(@RequestBody GenTableColumn genTableColumn) {
+        return Result.success(genTableColumnService.insert(genTableColumn));
+    }
+
+    /**
+     * 修改代码生成业务字段
+     */
+    @PostMapping("/update-genTableColumn")
+    public Result<Integer> edit(@RequestBody GenTableColumn genTableColumn) {
+        return Result.success(genTableColumnService.update(genTableColumn));
+    }
+
+    /**
+     * 删除代码生成业务字段
+     */
+    @PostMapping("/delete-genTableColumn")
+    public Result<Integer> remove(@RequestBody String[] ids) {
+        return Result.success(genTableColumnService.deleteByColumnIds(ids));
+    }
+
+    /**
+    * 导入 代码生成业务字段
+    * @param file
+    * @param updateSupport
+    * @return
+    * @throws Exception
+    */
+    @PostMapping("/import-genTableColumn")
+    public Result<String> importData(MultipartFile file, boolean updateSupport) throws Exception
+    {
+        CacpTransUser user = UserContextHolder.currentUser();
+        ExcelUtil<GenTableColumn> util = new ExcelUtil<GenTableColumn>(GenTableColumn.class);
+        List<GenTableColumn> genTableColumnList = util.importExcel(file.getInputStream());
+        String message = genTableColumnService.importGenTableColumn(genTableColumnList, updateSupport, user);
+        return Result.success(message);
+    }
+
+    /**
+     * 导出代码生成业务字段列表
+     */
+    @PostMapping("/get-genTableColumn-export")
+    public void export(HttpServletResponse response, @RequestBody GenTableColumnQuery query) {
+        List<GenTableColumn> list = genTableColumnService.selectList(query);
+        ExcelUtil<GenTableColumn> util = new ExcelUtil<GenTableColumn>(GenTableColumn. class);
+        util.exportExcel(response, list, "代码生成业务字段数据");
+    }
+
+    /**
+    * 获取导入模板
+    * @param response
+    */
+    @PostMapping("/template-genTableColumn")
+    public void importTemplate(HttpServletResponse response)
+    {
+        ExcelUtil<GenTableColumn> util = new ExcelUtil<GenTableColumn>(GenTableColumn.class);
+        util.importTemplateExcel(response, "代码生成业务字段");
+    }
+}

+ 190 - 0
wxjy-wxjy-service/src/main/java/cn/gov/customs/wxjy/generator/controller/GenTableController.java

@@ -0,0 +1,190 @@
+package cn.gov.customs.wxjy.generator.controller;
+
+import cn.gov.customs.cacp.sdks.core.result.CacpResultCodeMessage;
+import cn.gov.customs.cacp.sdks.core.result.Result;
+import cn.gov.customs.cacp.sdks.core.user.annotation.LogonUser;
+import cn.gov.customs.cacp.sdks.core.user.pojo.CacpLogonUser;
+import cn.gov.customs.wxjy.common.core.controller.BaseController;
+import cn.gov.customs.wxjy.common.core.text.Convert;
+import cn.gov.customs.wxjy.common.utils.StringUtils;
+import cn.gov.customs.wxjy.generator.pojo.GenTable;
+import cn.gov.customs.wxjy.generator.pojo.GenTableColumn;
+import cn.gov.customs.wxjy.generator.pojo.GenTableQuery;
+import cn.gov.customs.wxjy.generator.service.IGenTableColumnService;
+import cn.gov.customs.wxjy.generator.service.IGenTableService;
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
+import lombok.RequiredArgsConstructor;
+import org.apache.commons.io.IOUtils;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 代码生成业务Controller
+ *
+ * @author xiong
+ * @date 2025-12-25
+ */
+@RestController
+@RequestMapping("/gen/GenTable")
+@RequiredArgsConstructor
+public class GenTableController extends BaseController {
+
+    private final IGenTableService genTableService;
+
+    private final IGenTableColumnService genTableColumnService;
+
+    /**
+     * 查询代码生成业务列表
+     */
+    @PostMapping("/get-list")
+    public Result<PageInfo<GenTable>> list(@LogonUser CacpLogonUser user,@RequestBody GenTableQuery query) {
+        PageHelper.startPage(query.getPageIndex(), query.getPageSize());
+        PageInfo<GenTable> list = genTableService.selectPageList(query);
+        return Result.success(list);
+    }
+
+    /**
+     * 获取代码生成业务详细信息
+     */
+    @GetMapping(value = "/get-detail")
+    public Result<Map<String, Object>> getInfo(@RequestParam String tableId) {
+        GenTable table = genTableService.selectByTableId(tableId);
+        List<GenTable> tables = genTableService.selectGenTableAll();
+        List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(tableId);
+        Map<String, Object> map = new HashMap<String, Object>();
+        map.put("info", table);
+        map.put("rows", list);
+        map.put("tables", tables);
+        return Result.success(map);
+    }
+
+    /**
+     * 查询数据库列表
+     */
+    @PostMapping("/db-list")
+    public Result<PageInfo<GenTable>> dataList(@RequestBody GenTableQuery query) {
+        PageHelper.startPage(query.getPageIndex(), query.getPageSize());
+        PageInfo<GenTable> list = genTableService.selectDbTableList(query);
+        return Result.success(list);
+    }
+
+    /**
+     * 查询数据表字段列表
+     */
+    @PostMapping("/column-list")
+    public Result<List<GenTableColumn>> columnList(@RequestBody String tableId) {
+        List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(tableId);
+        return Result.success(list);
+    }
+
+    /**
+     * 导入表结构(保存)
+     */
+    @GetMapping("/importTable")
+    public Result<Boolean> importTableSave(@RequestParam String tables)
+    {
+        if (StringUtils.isEmpty(tables)){
+            return Result.fail(CacpResultCodeMessage.WARNING,"获取表名称失败");
+        }
+        String[] tableNames = tables.split(",");
+        // 查询表信息
+        List<GenTable> tableList = genTableService.selectDbTableListByNames(tableNames);
+        genTableService.importGenTable(tableList, getUsername());
+        return Result.success(true);
+    }
+
+
+
+    /**
+     * 新增代码生成业务
+     */
+    @PostMapping("/insert-genTable")
+    public Result<Integer> add(@RequestBody GenTable genTable) {
+        return Result.success(genTableService.insert(genTable));
+    }
+
+    /**
+     * 修改代码生成业务
+     */
+    @PostMapping("/update-genTable")
+    public Result<Integer> edit(@RequestBody GenTable genTable) {
+        genTableService.validateEdit(genTable);
+        return Result.success(genTableService.update(genTable));
+    }
+
+    /**
+     * 删除代码生成业务
+     */
+    @PostMapping("/delete-genTable")
+    public Result<Integer> remove(@RequestBody String[] ids) {
+        return Result.success(genTableService.deleteByTableIds(ids));
+    }
+
+    /**
+     * 预览代码
+     */
+    @GetMapping("/preview-code")
+    public Result<Map<String,String>> preview(@RequestParam String tableId) throws IOException
+    {
+        Map<String, String> dataMap = genTableService.previewCode(tableId);
+        return Result.success(dataMap);
+    }
+
+    /**
+     * 生成代码(下载方式)
+     */
+    @GetMapping("/download")
+    public void download(HttpServletResponse response, @RequestParam String tableName) throws IOException
+    {
+        byte[] data = genTableService.downloadCode(tableName);
+        genCode(response, data);
+    }
+
+    /**
+     * 生成代码(自定义路径)
+     */
+    @GetMapping("/genCode-tableName")
+    public Result<Boolean> genCode(@RequestParam String tableName)
+    {
+        genTableService.generatorCode(tableName);
+        return Result.success(true);
+    }
+
+    /**
+     * 同步数据库
+     */
+    @GetMapping("/synchDb-tableName")
+    public Result<Boolean> synchDb(@RequestParam String tableName)
+    {
+        genTableService.synchDb(tableName);
+        return Result.success(true);
+    }
+
+    /**
+     * 批量生成代码
+     */
+    @GetMapping("/batchGenCode")
+    public void batchGenCode(HttpServletResponse response,@RequestParam String tables) throws IOException
+    {
+        String[] tableNames = Convert.toStrArray(tables);
+        byte[] data = genTableService.downloadCode(tableNames);
+        genCode(response, data);
+    }
+
+    private void genCode(HttpServletResponse response, byte[] data) throws IOException
+    {
+        response.reset();
+        response.addHeader("Access-Control-Allow-Origin", "*");
+        response.addHeader("Access-Control-Expose-Headers", "Content-Disposition");
+        response.setHeader("Content-Disposition", "attachment; filename=\"rongji.zip\"");
+        response.addHeader("Content-Length", "" + data.length);
+        response.setContentType("application/octet-stream; charset=UTF-8");
+        IOUtils.write(data, response.getOutputStream());
+    }
+}

+ 50 - 34
wxjy-wxjy-service/src/main/java/cn/gov/customs/wxjy/generator/dao/GenTableColumnMapper.java

@@ -1,64 +1,80 @@
 package cn.gov.customs.wxjy.generator.dao;
 
+import java.util.List;
 
-import cn.gov.customs.wxjy.generator.domain.GenTableColumn;
 import org.apache.ibatis.annotations.Mapper;
-
-import java.util.List;
+import cn.gov.customs.wxjy.generator.pojo.GenTableColumn;
+import cn.gov.customs.wxjy.generator.pojo.GenTableColumnQuery;
 
 /**
- * 业务字段 数据层
- * 
- * @author ruoyi
+ * 代码生成业务字段Mapper接口
+ *
+ * @author xiong
+ * @date 2025-12-25
  */
 @Mapper
-public interface GenTableColumnMapper
-{
+public interface GenTableColumnMapper {
     /**
-     * 根据表名称查询列信息
-     * 
-     * @param tableName 表名称
-     * @return 列信息
+     * 查询代码生成业务字段
+     *
+     * @param columnId 代码生成业务字段主键
+     * @return 代码生成业务字段
      */
-    public List<GenTableColumn> selectDbTableColumnsByName(String tableName);
+    public GenTableColumn selectByColumnId(String columnId);
 
     /**
-     * 查询业务字段列表
-     * 
-     * @param tableId 业务字段编号
-     * @return 业务字段集合
+     * 查询代码生成业务字段列表
+     *
+     * @param genTableColumn 代码生成业务字段
+     * @return 代码生成业务字段集合
      */
-    public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId);
+    public List<GenTableColumn> selectList(GenTableColumnQuery genTableColumn);
 
     /**
-     * 新增业务字段
-     * 
-     * @param genTableColumn 业务字段信息
+     * 新增代码生成业务字段
+     *
+     * @param genTableColumn 代码生成业务字段
      * @return 结果
      */
-    public int insertGenTableColumn(GenTableColumn genTableColumn);
+    public int insert(GenTableColumn genTableColumn);
 
     /**
-     * 修改业务字段
-     * 
-     * @param genTableColumn 业务字段信息
+     * 修改代码生成业务字段
+     *
+     * @param genTableColumn 代码生成业务字段
      * @return 结果
      */
-    public int updateGenTableColumn(GenTableColumn genTableColumn);
+    public int update(GenTableColumn genTableColumn);
 
     /**
-     * 删除业务字段
-     * 
-     * @param genTableColumns 列数据
+     * 删除代码生成业务字段
+     *
+     * @param columnId 代码生成业务字段主键
      * @return 结果
      */
-    public int deleteGenTableColumns(List<GenTableColumn> genTableColumns);
+    public int deleteByColumnId(String columnId);
 
     /**
-     * 批量删除业务字段
-     * 
-     * @param ids 需要删除的数据ID
+     * 批量删除代码生成业务字段
+     *
+     * @param columnIds 需要删除的数据主键集合
      * @return 结果
      */
-    public int deleteGenTableColumnByIds(Long[] ids);
+    public int deleteByColumnIds(String[] columnIds);
+
+    /**
+     * 逻辑删除代码生成业务字段
+     *
+     * @param columnId 代码生成业务字段主键
+     * @return 结果
+     */
+    public int logicDelete(String columnId);
+
+    List<GenTableColumn> selectGenTableColumnListByTableId(String tableId);
+
+    List<GenTableColumn> selectDbTableColumnsByName(String tableName);
+
+    void deleteGenTableColumnByIds(String[] ids);
+
+    void deleteGenTableColumns(List<GenTableColumn> delColumns);
 }

+ 46 - 61
wxjy-wxjy-service/src/main/java/cn/gov/customs/wxjy/generator/dao/GenTableMapper.java

@@ -1,95 +1,80 @@
 package cn.gov.customs.wxjy.generator.dao;
 
+import java.util.List;
 
-import cn.gov.customs.wxjy.generator.domain.GenTable;
 import org.apache.ibatis.annotations.Mapper;
-
-import java.util.List;
+import cn.gov.customs.wxjy.generator.pojo.GenTable;
+import cn.gov.customs.wxjy.generator.pojo.GenTableQuery;
 
 /**
- * 业务 数据层
- * 
- * @author ruoyi
+ * 代码生成业务Mapper接口
+ *
+ * @author xiong
+ * @date 2025-12-25
  */
 @Mapper
-public interface GenTableMapper
-{
-    /**
-     * 查询业务列表
-     * 
-     * @param genTable 业务信息
-     * @return 业务集合
-     */
-    public List<GenTable> selectGenTableList(GenTable genTable);
-
-    /**
-     * 查询据库列表
-     * 
-     * @param genTable 业务信息
-     * @return 数据库表集合
-     */
-    public List<GenTable> selectDbTableList(GenTable genTable);
-
-    /**
-     * 查询据库列表
-     * 
-     * @param tableNames 表名称组
-     * @return 数据库表集合
-     */
-    public List<GenTable> selectDbTableListByNames(String[] tableNames);
-
+public interface GenTableMapper {
     /**
-     * 查询所有表信息
-     * 
-     * @return 表信息集合
+     * 查询代码生成业务
+     *
+     * @param tableId 代码生成业务主键
+     * @return 代码生成业务
      */
-    public List<GenTable> selectGenTableAll();
+    public GenTable selectByTableId(String tableId);
 
     /**
-     * 查询表ID业务信息
-     * 
-     * @param id 业务ID
-     * @return 业务信息
+     * 查询代码生成业务列表
+     *
+     * @param genTable 代码生成业务
+     * @return 代码生成业务集合
      */
-    public GenTable selectGenTableById(Long id);
+    public List<GenTable> selectList(GenTableQuery genTable);
 
     /**
-     * 查询表名称业务信息
-     * 
-     * @param tableName 表名称
-     * @return 业务信息
+     * 新增代码生成业务
+     *
+     * @param genTable 代码生成业务
+     * @return 结果
      */
-    public GenTable selectGenTableByName(String tableName);
+    public int insert(GenTable genTable);
 
     /**
-     * 新增业务
-     * 
-     * @param genTable 业务信息
+     * 修改代码生成业务
+     *
+     * @param genTable 代码生成业务
      * @return 结果
      */
-    public int insertGenTable(GenTable genTable);
+    public int update(GenTable genTable);
 
     /**
-     * 修改业务
-     * 
-     * @param genTable 业务信息
+     * 删除代码生成业务
+     *
+     * @param tableId 代码生成业务主键
      * @return 结果
      */
-    public int updateGenTable(GenTable genTable);
+    public int deleteByTableId(String tableId);
 
     /**
-     * 批量删除业务
-     * 
-     * @param ids 需要删除的数据ID
+     * 批量删除代码生成业务
+     *
+     * @param tableIds 需要删除的数据主键集合
      * @return 结果
      */
-    public int deleteGenTableByIds(Long[] ids);
+    public int deleteByTableIds(String[] tableIds);
 
     /**
-     * 创建表
+     * 逻辑删除代码生成业务
      *
-     * @param sql 表结构
+     * @param tableId 代码生成业务主键
      * @return 结果
      */
-    public int createTable(String sql);
+    public int logicDelete(String tableId);
+
+    List<GenTable> selectGenTableAll();
+
+    List<GenTable> selectDbTableList(GenTableQuery query);
+
+    List<GenTable> selectDbTableListByNames(String[] tableNames);
+
+    GenTable selectGenTableByName(String subTableName);
 }

+ 9 - 7
wxjy-wxjy-service/src/main/java/cn/gov/customs/wxjy/generator/domain/GenTable.java → wxjy-wxjy-service/src/main/java/cn/gov/customs/wxjy/generator/pojo/GenTable.java

@@ -1,8 +1,9 @@
-package cn.gov.customs.wxjy.generator.domain;
+package cn.gov.customs.wxjy.generator.pojo;
 
 import cn.gov.customs.wxjy.common.constant.GenConstants;
 import cn.gov.customs.wxjy.common.core.domain.BaseEntity;
 import cn.gov.customs.wxjy.common.utils.StringUtils;
+import lombok.Data;
 import org.apache.commons.lang3.ArrayUtils;
 
 import javax.validation.Valid;
@@ -10,12 +11,13 @@ import javax.validation.constraints.NotBlank;
 import java.util.List;
 
 /**
- * 业务表 gen_table
- * 
- * @author ruoyi
+ * 代码生成业务对象 SYS_GEN_TABLE
+ *
+ * @author xiong
+ * @date 2025-12-25
  */
-public class GenTable extends BaseEntity
-{
+@Data
+public class GenTable extends BaseEntity {
     private static final long serialVersionUID = 1L;
 
     /** 编号 */
@@ -383,4 +385,4 @@ public class GenTable extends BaseEntity
         }
         return StringUtils.equalsAnyIgnoreCase(javaField, GenConstants.BASE_ENTITY);
     }
-}
+}

+ 9 - 8
wxjy-wxjy-service/src/main/java/cn/gov/customs/wxjy/generator/domain/GenTableColumn.java → wxjy-wxjy-service/src/main/java/cn/gov/customs/wxjy/generator/pojo/GenTableColumn.java

@@ -1,18 +1,19 @@
-package cn.gov.customs.wxjy.generator.domain;
+package cn.gov.customs.wxjy.generator.pojo;
 
-
-import cn.gov.customs.wxjy.common.core.domain.BaseEntity;
 import cn.gov.customs.wxjy.common.utils.StringUtils;
+import lombok.Data;
+import cn.gov.customs.wxjy.common.core.domain.BaseEntity;
 
 import javax.validation.constraints.NotBlank;
 
 /**
- * 代码生成业务字段表 gen_table_column
- * 
- * @author ruoyi
+ * 代码生成业务字段对象 SYS_GEN_TABLE_COLUMN
+ *
+ * @author xiong
+ * @date 2025-12-25
  */
-public class GenTableColumn extends BaseEntity
-{
+@Data
+public class GenTableColumn extends BaseEntity {
     private static final long serialVersionUID = 1L;
 
     /** 编号 */

+ 75 - 0
wxjy-wxjy-service/src/main/java/cn/gov/customs/wxjy/generator/pojo/GenTableColumnQuery.java

@@ -0,0 +1,75 @@
+package cn.gov.customs.wxjy.generator.pojo;
+
+import lombok.Data;
+import java.io.Serializable;
+
+/**
+ * 代码生成业务字段对象 SYS_GEN_TABLE_COLUMN
+ *
+ * @author xiong
+ * @date 2025-12-25
+ */
+@Data
+public class GenTableColumnQuery implements Serializable {
+
+
+    /** 编号 */
+    private String columnId;
+
+    /** 归属表编号 */
+    private String tableId;
+
+    /** 列名称 */
+    private String columnName;
+
+    /** 列描述 */
+    private String columnComment;
+
+    /** 列类型 */
+    private String columnType;
+
+    /** JAVA类型 */
+    private String javaType;
+
+    /** JAVA字段名 */
+    private String javaField;
+
+    /** 是否主键(1是) */
+    private String isPk;
+
+    /** 是否自增(1是) */
+    private String isIncrement;
+
+    /** 是否必填(1是) */
+    private String isRequired;
+
+    /** 是否为插入字段(1是) */
+    private String isInsert;
+
+    /** 是否编辑字段(1是) */
+    private String isEdit;
+
+    /** 是否列表字段(1是) */
+    private String isList;
+
+    /** 是否查询字段(1是) */
+    private String isQuery;
+
+    /** 查询方式(等于、不等于、大于、小于、范围) */
+    private String queryType;
+
+    /** 显示类型(文本框、文本域、下拉框、复选框、单选框、日期控件) */
+    private String htmlType;
+
+    /** 字典类型 */
+    private String dictType;
+
+    /** 排序 */
+    private String SORT;
+
+
+    private String beginDate;
+    private String endDate;
+    private int pageIndex;
+    private int pageSize;
+}

+ 69 - 0
wxjy-wxjy-service/src/main/java/cn/gov/customs/wxjy/generator/pojo/GenTableQuery.java

@@ -0,0 +1,69 @@
+package cn.gov.customs.wxjy.generator.pojo;
+
+import lombok.Data;
+import java.io.Serializable;
+
+/**
+ * 代码生成业务对象 SYS_GEN_TABLE
+ *
+ * @author xiong
+ * @date 2025-12-25
+ */
+@Data
+public class GenTableQuery implements Serializable {
+
+
+    /** 编号 */
+    private String tableId;
+
+    /** 表名称 */
+    private String tableName;
+
+    /** 表描述 */
+    private String tableComment;
+
+    /** 关联子表的表名 */
+    private String subTableName;
+
+    /** 子表关联的外键名 */
+    private String subTableFkName;
+
+    /** 实体类名称 */
+    private String className;
+
+    /** 使用的模板(crud单表操作 tree树表操作) */
+    private String tplCategory;
+
+    /** 生成包路径 */
+    private String packageName;
+
+    /** 生成模块名 */
+    private String moduleName;
+
+    /** 生成业务名 */
+    private String businessName;
+
+    /** 生成功能名 */
+    private String functionName;
+
+    /** 生成功能作者 */
+    private String functionAuthor;
+
+    /** 生成代码方式(0zip压缩包 1自定义路径) */
+    private String genType;
+
+    /** 生成路径(不填默认项目路径) */
+    private String genPath;
+
+    /** 其它生成选项 */
+    private String options;
+
+    /** 模板web类型 */
+    private String tplWebType;
+
+
+    private String beginDate;
+    private String endDate;
+    private int pageIndex;
+    private int pageSize;
+}

+ 0 - 70
wxjy-wxjy-service/src/main/java/cn/gov/customs/wxjy/generator/service/GenTableColumnServiceImpl.java

@@ -1,70 +0,0 @@
-package cn.gov.customs.wxjy.generator.service;
-
-import cn.gov.customs.wxjy.common.core.text.Convert;
-import cn.gov.customs.wxjy.generator.dao.GenTableColumnMapper;
-import cn.gov.customs.wxjy.generator.domain.GenTableColumn;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
-import java.util.List;
-
-
-/**
- * 业务字段 服务层实现
- * 
- * @author ruoyi
- */
-@Service
-public class GenTableColumnServiceImpl implements IGenTableColumnService 
-{
-	@Autowired
-	private GenTableColumnMapper genTableColumnMapper;
-
-	/**
-     * 查询业务字段列表
-     * 
-     * @param tableId 业务字段编号
-     * @return 业务字段集合
-     */
-	@Override
-	public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId)
-	{
-	    return genTableColumnMapper.selectGenTableColumnListByTableId(tableId);
-	}
-	
-    /**
-     * 新增业务字段
-     * 
-     * @param genTableColumn 业务字段信息
-     * @return 结果
-     */
-	@Override
-	public int insertGenTableColumn(GenTableColumn genTableColumn)
-	{
-	    return genTableColumnMapper.insertGenTableColumn(genTableColumn);
-	}
-	
-	/**
-     * 修改业务字段
-     * 
-     * @param genTableColumn 业务字段信息
-     * @return 结果
-     */
-	@Override
-	public int updateGenTableColumn(GenTableColumn genTableColumn)
-	{
-	    return genTableColumnMapper.updateGenTableColumn(genTableColumn);
-	}
-
-	/**
-     * 删除业务字段对象
-     * 
-     * @param ids 需要删除的数据ID
-     * @return 结果
-     */
-	@Override
-	public int deleteGenTableColumnByIds(String ids)
-	{
-		return genTableColumnMapper.deleteGenTableColumnByIds(Convert.toLongArray(ids));
-	}
-}

+ 70 - 25
wxjy-wxjy-service/src/main/java/cn/gov/customs/wxjy/generator/service/IGenTableColumnService.java

@@ -1,46 +1,91 @@
 package cn.gov.customs.wxjy.generator.service;
 
-
-import cn.gov.customs.wxjy.generator.domain.GenTableColumn;
-
 import java.util.List;
+import cn.gov.customs.cacp.sdks.core.user.trans.CacpTransUser;
+import cn.gov.customs.wxjy.generator.pojo.GenTableColumn;
+import cn.gov.customs.wxjy.generator.pojo.GenTableColumnQuery;
+import com.github.pagehelper.PageInfo;
 
 /**
- * 业务字段 服务层
- * 
- * @author ruoyi
+ * 代码生成业务字段Service接口
+ *
+ * @author xiong
+ * @date 2025-12-25
  */
-public interface IGenTableColumnService
-{
+public interface IGenTableColumnService {
+    /**
+     * 查询代码生成业务字段
+     *
+     * @param columnId 代码生成业务字段主键
+     * @return 代码生成业务字段
+     */
+    public GenTableColumn selectByColumnId(String columnId);
+
     /**
-     * 查询业务字段列表
-     * 
-     * @param tableId 业务字段编号
-     * @return 业务字段集合
+     * 分页查询代码生成业务字段列表
+     *
+     * @param query
+     * @return 代码生成业务字段集合
      */
-    public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId);
+    public PageInfo<GenTableColumn> selectPageList(GenTableColumnQuery query);
 
     /**
-     * 新增业务字段
-     * 
-     * @param genTableColumn 业务字段信息
+     * 查询代码生成业务字段列表
+     *
+     * @param query
+     * @return 代码生成业务字段集合
+     */
+    public List<GenTableColumn> selectList(GenTableColumnQuery query);
+
+    /**
+     * 新增代码生成业务字段
+     *
+     * @param genTableColumn 代码生成业务字段
      * @return 结果
      */
-    public int insertGenTableColumn(GenTableColumn genTableColumn);
+    public int insert(GenTableColumn genTableColumn);
 
     /**
-     * 修改业务字段
-     * 
-     * @param genTableColumn 业务字段信息
+     * 修改代码生成业务字段
+     *
+     * @param genTableColumn 代码生成业务字段
      * @return 结果
      */
-    public int updateGenTableColumn(GenTableColumn genTableColumn);
+    public int update(GenTableColumn genTableColumn);
 
     /**
-     * 删除业务字段信息
-     * 
-     * @param ids 需要删除的数据ID
+     * 批量删除代码生成业务字段
+     *
+     * @param ids 需要删除的ids主键集合
      * @return 结果
      */
-    public int deleteGenTableColumnByIds(String ids);
+    public int deleteByColumnIds(String[] ids);
+
+    /**
+     * 删除代码生成业务字段信息
+     *
+     * @param columnId 代码生成业务字段主键
+     * @return 结果
+     */
+    public int deleteByColumnId(String columnId);
+
+    /**
+     * 逻辑删除代码生成业务字段信息
+     *
+     * @param columnId 代码生成业务字段主键
+     * @return 结果
+     */
+    public int logicDelete(String columnId);
+
+    /**
+     * 导入代码生成业务字段数据
+     *
+     * @param genTableColumnList 代码生成业务字段数据列表
+     * @param isUpdateSupport 是否更新支持,如果已存在,则进行更新数据
+     * @param cacpTransUser 操作用户
+     * @return 结果
+     */
+    public String importGenTableColumn(List<GenTableColumn> genTableColumnList, Boolean isUpdateSupport, CacpTransUser cacpTransUser);
+
+    List<GenTableColumn> selectGenTableColumnListByTableId(String tableId);
 }

+ 62 - 79
wxjy-wxjy-service/src/main/java/cn/gov/customs/wxjy/generator/service/IGenTableService.java

@@ -1,131 +1,114 @@
 package cn.gov.customs.wxjy.generator.service;
 
-import cn.gov.customs.wxjy.generator.domain.GenTable;
+import cn.gov.customs.wxjy.generator.pojo.GenTable;
+import cn.gov.customs.wxjy.generator.pojo.GenTableQuery;
+import com.github.pagehelper.PageInfo;
 
 import java.util.List;
 import java.util.Map;
 
 /**
- * 业务 服务层
- * 
- * @author ruoyi
+ * 代码生成业务Service接口
+ *
+ * @author xiong
+ * @date 2025-12-25
  */
-public interface IGenTableService
-{
+public interface IGenTableService {
     /**
-     * 查询业务列表
-     * 
-     * @param genTable 业务信息
-     * @return 业务集合
+     * 查询代码生成业务
+     *
+     * @param tableId 代码生成业务主键
+     * @return 代码生成业务
      */
-    public List<GenTable> selectGenTableList(GenTable genTable);
+    public GenTable selectByTableId(String tableId);
 
     /**
-     * 查询据库列表
-     * 
-     * @param genTable 业务信息
-     * @return 数据库表集合
+     * 分页查询代码生成业务列表
+     *
+     * @param query
+     * @return 代码生成业务集合
      */
-    public List<GenTable> selectDbTableList(GenTable genTable);
+    public PageInfo<GenTable> selectPageList(GenTableQuery query);
 
     /**
-     * 查询据库列表
-     * 
-     * @param tableNames 表名称组
-     * @return 数据库表集合
+     * 查询代码生成业务列表
+     *
+     * @param query
+     * @return 代码生成业务集合
      */
-    public List<GenTable> selectDbTableListByNames(String[] tableNames);
+    public List<GenTable> selectList(GenTableQuery query);
 
     /**
-     * 查询所有表信息
-     * 
-     * @return 表信息集合
+     * 新增代码生成业务
+     *
+     * @param genTable 代码生成业务
+     * @return 结果
      */
-    public List<GenTable> selectGenTableAll();
+    public int insert(GenTable genTable);
 
     /**
-     * 查询业务信息
-     * 
-     * @param id 业务ID
-     * @return 业务信息
+     * 修改代码生成业务
+     *
+     * @param genTable 代码生成业务
+     * @return 结果
      */
-    public GenTable selectGenTableById(Long id);
+    public int update(GenTable genTable);
 
     /**
-     * 修改业务
-     * 
-     * @param genTable 业务信息
+     * 批量删除代码生成业务
+     *
+     * @param ids 需要删除的ids主键集合
      * @return 结果
      */
-    public void updateGenTable(GenTable genTable);
+    public int deleteByTableIds(String[] ids);
 
     /**
-     * 删除业务信息
-     * 
-     * @param tableIds 需要删除的表数据ID
+     * 删除代码生成业务信息
+     *
+     * @param tableId 代码生成业务主键
      * @return 结果
      */
-    public void deleteGenTableByIds(Long[] tableIds);
+    public int deleteByTableId(String tableId);
 
     /**
-     * 创建表
+     * 逻辑删除代码生成业务信息
      *
-     * @param sql 创建表语句
+     * @param tableId 代码生成业务主键
      * @return 结果
      */
-    public boolean createTable(String sql);
+    public int logicDelete(String tableId);
 
     /**
-     * 导入表结构
+     * 导入代码生成业务数据
      *
-     * @param tableList 导入表列表
-     * @param operName 操作人员
+     * @param genTableList 代码生成业务数据列表
+     * @param userName 操作用户
+     * @return 结果
      */
-    public void importGenTable(List<GenTable> tableList, String operName);
+    public void importGenTable(List<GenTable> genTableList, String userName);
 
-    /**
-     * 预览代码
-     * 
-     * @param tableId 表编号
-     * @return 预览数据列表
-     */
-    public Map<String, String> previewCode(Long tableId);
+    List<GenTable> selectGenTableAll();
 
-    /**
-     * 生成代码(下载方式)
-     * 
-     * @param tableName 表名称
-     * @return 数据
-     */
-    public byte[] downloadCode(String tableName);
+    PageInfo<GenTable> selectDbTableList(GenTableQuery query);
 
-    /**
-     * 生成代码(自定义路径)
-     * 
-     * @param tableName 表名称
-     * @return 数据
-     */
-    public void generatorCode(String tableName);
+    List<GenTable> selectDbTableListByNames(String[] tableNames);
 
-    /**
-     * 同步数据库
-     * 
-     * @param tableName 表名称
-     */
-    public void synchDb(String tableName);
+    void validateEdit(GenTable genTable);
+
+    Map<String, String> previewCode(String tableId);
+
+    byte[] downloadCode(String tableName);
 
     /**
      * 批量生成代码(下载方式)
-     * 
+     *
      * @param tableNames 表数组
      * @return 数据
      */
     public byte[] downloadCode(String[] tableNames);
 
-    /**
-     * 修改保存参数校验
-     * 
-     * @param genTable 业务信息
-     */
-    public void validateEdit(GenTable genTable);
+
+    void generatorCode(String tableName);
+
+    void synchDb(String tableName);
 }

+ 175 - 0
wxjy-wxjy-service/src/main/java/cn/gov/customs/wxjy/generator/service/impl/GenTableColumnServiceImpl.java

@@ -0,0 +1,175 @@
+package cn.gov.customs.wxjy.generator.service.impl;
+
+import cn.gov.customs.cacp.sdks.core.user.trans.CacpTransUser;
+import cn.gov.customs.wxjy.common.exception.ServiceException;
+import cn.gov.customs.wxjy.common.utils.DateUtils;
+import cn.gov.customs.wxjy.common.utils.bean.BeanValidators;
+import cn.gov.customs.wxjy.generator.dao.GenTableColumnMapper;
+import cn.gov.customs.wxjy.generator.pojo.GenTableColumn;
+import cn.gov.customs.wxjy.generator.pojo.GenTableColumnQuery;
+import cn.gov.customs.wxjy.generator.service.IGenTableColumnService;
+import com.github.pagehelper.PageInfo;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.CollectionUtils;
+import org.springframework.stereotype.Service;
+
+import javax.validation.Validator;
+import java.util.List;
+
+/**
+ * 代码生成业务字段Service业务层处理
+ *
+ * @author xiong
+ * @date 2025-12-25
+ */
+@Service
+@Slf4j
+@RequiredArgsConstructor
+public class GenTableColumnServiceImpl implements IGenTableColumnService {
+
+    private final GenTableColumnMapper genTableColumnMapper;
+
+    private final Validator validator;
+
+    /**
+     * 查询代码生成业务字段
+     *
+     * @param columnId 代码生成业务字段主键
+     * @return 代码生成业务字段
+     */
+    @Override
+    public GenTableColumn selectByColumnId(String columnId) {
+        return genTableColumnMapper.selectByColumnId(columnId);
+    }
+
+    /**
+     * 分页查询代码生成业务字段列表
+     *
+     * @param query
+     * @return 代码生成业务字段
+     */
+    @Override
+    public PageInfo<GenTableColumn> selectPageList(GenTableColumnQuery query) {
+        return PageInfo.of(genTableColumnMapper.selectList(query));
+    }
+
+    /**
+     * 查询代码生成业务字段列表
+     *
+     * @param query
+     * @return 代码生成业务字段
+     */
+    @Override
+    public List<GenTableColumn> selectList(GenTableColumnQuery query) {
+        return genTableColumnMapper.selectList(query);
+    }
+
+    /**
+     * 新增代码生成业务字段
+     *
+     * @param genTableColumn 代码生成业务字段
+     * @return 结果
+     */
+    @Override
+    public int insert(GenTableColumn genTableColumn) {
+            return genTableColumnMapper.insert(genTableColumn);
+    }
+
+    /**
+     * 修改代码生成业务字段
+     *
+     * @param genTableColumn 代码生成业务字段
+     * @return 结果
+     */
+    @Override
+    public int update(GenTableColumn genTableColumn) {
+        return genTableColumnMapper.update(genTableColumn);
+    }
+
+    /**
+     * 批量删除代码生成业务字段
+     *
+     * @param ids 需要删除的代码生成业务字段主键
+     * @return 结果
+     */
+    @Override
+    public int deleteByColumnIds(String[] ids) {
+        return genTableColumnMapper.deleteByColumnIds(ids);
+    }
+
+    /**
+     * 删除代码生成业务字段信息
+     *
+     * @param columnId 代码生成业务字段主键
+     * @return 结果
+     */
+    @Override
+    public int deleteByColumnId(String columnId) {
+        return genTableColumnMapper.deleteByColumnId(columnId);
+    }
+
+    /**
+     * 逻辑删除代码生成业务字段信息
+     *
+     * @param columnId 代码生成业务字段主键
+     * @return 结果
+     */
+    @Override
+    public int logicDelete(String columnId) {
+
+        return genTableColumnMapper.logicDelete(columnId);
+    }
+
+    /**
+     * 导入代码生成业务字段数据
+     *
+     * @param genTableColumnList 代码生成业务字段数据列表
+     * @param isUpdateSupport 是否更新支持,如果已存在,则进行更新数据
+     * @param cacpTransUser 操作用户
+     * @return 结果
+     */
+    @Override
+    public String importGenTableColumn(List<GenTableColumn> genTableColumnList, Boolean isUpdateSupport, CacpTransUser cacpTransUser) {
+        if (CollectionUtils.isEmpty(genTableColumnList)) {
+            throw new ServiceException("导入数据不能为空!");
+        }
+        int successNum = 0;
+        int failureNum = 0;
+        StringBuilder successMsg = new StringBuilder();
+        StringBuilder failureMsg = new StringBuilder();
+        for (GenTableColumn genTableColumn : genTableColumnList) {
+            try {
+
+                BeanValidators.validateWithException(validator, genTableColumn);
+                //id名称不统一,自行处理
+                genTableColumn.setCreateTime(DateUtils.getNowDate());
+                genTableColumn.setUpdateTime(DateUtils.getNowDate());
+                genTableColumn.setCreateUser(cacpTransUser.getUserId());
+                genTableColumn.setCreateDept(cacpTransUser.getParentGuid());
+
+                genTableColumnMapper.insert(genTableColumn);
+                successNum++;
+                successMsg.append("<br/>" + successNum + "、 " + cacpTransUser.getUserName() + " 导入成功");
+
+            } catch (Exception e) {
+                failureNum++;
+                String msg = "<br/>" + failureNum + "、" + cacpTransUser.getUserName() + " 导入失败:";
+                failureMsg.append(msg + e.getMessage());
+                log.error(msg, e);
+            }
+        }
+        if (failureNum > 0) {
+            failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
+            throw new ServiceException(failureMsg.toString());
+        } else {
+            successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
+        }
+        return successMsg.toString();
+    }
+
+    @Override
+    public List<GenTableColumn> selectGenTableColumnListByTableId(String tableId) {
+        return genTableColumnMapper.selectGenTableColumnListByTableId(tableId);
+    }
+}

+ 214 - 257
wxjy-wxjy-service/src/main/java/cn/gov/customs/wxjy/generator/service/GenTableServiceImpl.java → wxjy-wxjy-service/src/main/java/cn/gov/customs/wxjy/generator/service/impl/GenTableServiceImpl.java

@@ -1,30 +1,33 @@
-package cn.gov.customs.wxjy.generator.service;
+package cn.gov.customs.wxjy.generator.service.impl;
 
 import cn.gov.customs.wxjy.common.constant.Constants;
 import cn.gov.customs.wxjy.common.constant.GenConstants;
 import cn.gov.customs.wxjy.common.core.text.CharsetKit;
 import cn.gov.customs.wxjy.common.exception.ServiceException;
 import cn.gov.customs.wxjy.common.utils.StringUtils;
+import cn.gov.customs.wxjy.generator.util.SysGenUtils;
+import cn.gov.customs.wxjy.generator.util.SysVelocityUtils;
+import cn.gov.customs.wxjy.generator.util.VelocityInitializer;
 import cn.gov.customs.wxjy.generator.dao.GenTableColumnMapper;
 import cn.gov.customs.wxjy.generator.dao.GenTableMapper;
-import cn.gov.customs.wxjy.generator.domain.GenTable;
-import cn.gov.customs.wxjy.generator.domain.GenTableColumn;
-import cn.gov.customs.wxjy.generator.util.GenUtils;
-import cn.gov.customs.wxjy.generator.util.VelocityInitializer;
-import cn.gov.customs.wxjy.generator.util.VelocityUtils;
+import cn.gov.customs.wxjy.generator.pojo.GenTable;
+import cn.gov.customs.wxjy.generator.pojo.GenTableColumn;
+import cn.gov.customs.wxjy.generator.pojo.GenTableQuery;
+import cn.gov.customs.wxjy.generator.service.IGenTableService;
 import com.alibaba.fastjson2.JSON;
 import com.alibaba.fastjson2.JSONObject;
+import com.github.pagehelper.PageInfo;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
 import org.apache.velocity.Template;
 import org.apache.velocity.VelocityContext;
 import org.apache.velocity.app.Velocity;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import javax.validation.Validator;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.IOException;
@@ -38,186 +41,221 @@ import java.util.zip.ZipEntry;
 import java.util.zip.ZipOutputStream;
 
 /**
- * 业务 服务层实现
- * 
- * @author ruoyi
+ * 代码生成业务Service业务层处理
+ *
+ * @author xiong
+ * @date 2025-12-25
  */
 @Service
-public class GenTableServiceImpl implements IGenTableService
-{
-    private static final Logger log = LoggerFactory.getLogger(GenTableServiceImpl.class);
+@Slf4j
+@RequiredArgsConstructor
+public class GenTableServiceImpl implements IGenTableService {
 
-    @Autowired
-    private GenTableMapper genTableMapper;
+    private final GenTableMapper genTableMapper;
 
-    @Autowired
-    private GenTableColumnMapper genTableColumnMapper;
+    private final GenTableColumnMapper genTableColumnMapper;
 
-    /**
-     * 查询业务信息
-     * 
-     * @param id 业务ID
-     * @return 业务信息
-     */
-    @Override
-    public GenTable selectGenTableById(Long id)
-    {
-        GenTable genTable = genTableMapper.selectGenTableById(id);
-        setTableFromOptions(genTable);
-        return genTable;
-    }
+    private final Validator validator;
 
     /**
-     * 查询业务列表
-     * 
-     * @param genTable 业务信息
-     * @return 业务集合
+     * 查询代码生成业务
+     *
+     * @param tableId 代码生成业务主键
+     * @return 代码生成业务
      */
     @Override
-    public List<GenTable> selectGenTableList(GenTable genTable)
-    {
-        return genTableMapper.selectGenTableList(genTable);
+    public GenTable selectByTableId(String tableId) {
+        return genTableMapper.selectByTableId(tableId);
     }
 
     /**
-     * 查询据库列表
-     * 
-     * @param genTable 业务信息
-     * @return 数据库表集合
+     * 分页查询代码生成业务列表
+     *
+     * @param query
+     * @return 代码生成业务
      */
     @Override
-    public List<GenTable> selectDbTableList(GenTable genTable)
-    {
-        return genTableMapper.selectDbTableList(genTable);
+    public PageInfo<GenTable> selectPageList(GenTableQuery query) {
+        return PageInfo.of(genTableMapper.selectList(query));
     }
 
     /**
-     * 查询据库列表
-     * 
-     * @param tableNames 表名称组
-     * @return 数据库表集合
+     * 查询代码生成业务列表
+     *
+     * @param query
+     * @return 代码生成业务
      */
     @Override
-    public List<GenTable> selectDbTableListByNames(String[] tableNames)
-    {
-        return genTableMapper.selectDbTableListByNames(tableNames);
+    public List<GenTable> selectList(GenTableQuery query) {
+        return genTableMapper.selectList(query);
     }
 
     /**
-     * 查询所有表信息
-     * 
-     * @return 表信息集合
+     * 新增代码生成业务
+     *
+     * @param genTable 代码生成业务
+     * @return 结果
      */
     @Override
-    public List<GenTable> selectGenTableAll()
-    {
-        return genTableMapper.selectGenTableAll();
+    public int insert(GenTable genTable) {
+            return genTableMapper.insert(genTable);
     }
 
     /**
-     * 修改业务
-     * 
-     * @param genTable 业务信息
+     * 修改代码生成业务
+     *
+     * @param genTable 代码生成业务
      * @return 结果
      */
     @Override
-    @Transactional
-    public void updateGenTable(GenTable genTable)
-    {
+    public int update(GenTable genTable) {
         String options = JSON.toJSONString(genTable.getParams());
         genTable.setOptions(options);
-        int row = genTableMapper.updateGenTable(genTable);
+        int row = genTableMapper.update(genTable);
         if (row > 0)
         {
             for (GenTableColumn cenTableColumn : genTable.getColumns())
             {
-                genTableColumnMapper.updateGenTableColumn(cenTableColumn);
+                genTableColumnMapper.update(cenTableColumn);
             }
         }
+        return row;
     }
 
     /**
-     * 删除业务对象
-     * 
-     * @param tableIds 需要删除的数据ID
+     * 批量删除代码生成业务
+     *
+     * @param ids 需要删除的代码生成业务主键
      * @return 结果
      */
     @Override
     @Transactional
-    public void deleteGenTableByIds(Long[] tableIds)
-    {
-        genTableMapper.deleteGenTableByIds(tableIds);
-        genTableColumnMapper.deleteGenTableColumnByIds(tableIds);
+    public int deleteByTableIds(String[] ids) {
+        genTableColumnMapper.deleteGenTableColumnByIds(ids);
+        return genTableMapper.deleteByTableIds(ids);
     }
 
     /**
-     * 创建表
+     * 删除代码生成业务信息
      *
-     * @param sql 创建表语句
+     * @param tableId 代码生成业务主键
      * @return 结果
      */
     @Override
-    public boolean createTable(String sql)
-    {
-        return genTableMapper.createTable(sql) == 0;
+    public int deleteByTableId(String tableId) {
+        return genTableMapper.deleteByTableId(tableId);
     }
 
     /**
-     * 导入表结构
-     * 
-     * @param tableList 导入表列表
+     * 逻辑删除代码生成业务信息
+     *
+     * @param tableId 代码生成业务主键
+     * @return 结果
      */
     @Override
-    @Transactional
-    public void importGenTable(List<GenTable> tableList, String operName)
-    {
-        try
+    public int logicDelete(String tableId) {
+
+        return genTableMapper.logicDelete(tableId);
+    }
+
+    /**
+     * 导入代码生成业务数据
+     *
+     * @param genTableList 代码生成业务数据列表
+     * @param operUser 操作用户
+     * @return 结果
+     */
+    @Override
+    public void importGenTable(List<GenTable> genTableList, String operUser) {
         {
-            for (GenTable table : tableList)
+            try
             {
-                String tableName = table.getTableName();
-                GenUtils.initTable(table, operName);
-                int row = genTableMapper.insertGenTable(table);
-                if (row > 0)
+                for (GenTable table : genTableList)
                 {
-                    // 保存列信息
-                    List<GenTableColumn> genTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName);
-                    for (GenTableColumn column : genTableColumns)
+                    String tableName = table.getTableName();
+                    SysGenUtils.initTable(table, operUser);
+                    int row = genTableMapper.insert(table);
+                    if (row > 0)
                     {
-                        GenUtils.initColumnField(column, table);
-                        genTableColumnMapper.insertGenTableColumn(column);
+                        // 保存列信息
+                        List<GenTableColumn> genTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName);
+                        for (GenTableColumn column : genTableColumns)
+                        {
+                            SysGenUtils.initColumnField(column, table);
+                            genTableColumnMapper.insert(column);
+                        }
                     }
                 }
             }
+            catch (Exception e)
+            {
+                throw new ServiceException("导入失败:" + e.getMessage());
+            }
         }
-        catch (Exception e)
+    }
+
+    @Override
+    public List<GenTable> selectGenTableAll() {
+        return genTableMapper.selectGenTableAll();
+    }
+
+    @Override
+    public PageInfo<GenTable> selectDbTableList(GenTableQuery query) {
+        return PageInfo.of(genTableMapper.selectDbTableList(query));
+    }
+
+    @Override
+    public List<GenTable> selectDbTableListByNames(String[] tableNames) {
+        return genTableMapper.selectDbTableListByNames(tableNames);
+    }
+
+    @Override
+    public void validateEdit(GenTable genTable) {
+        if (GenConstants.TPL_TREE.equals(genTable.getTplCategory()))
         {
-            throw new ServiceException("导入失败:" + e.getMessage());
+            String options = JSON.toJSONString(genTable.getParams());
+            JSONObject paramsObj = JSON.parseObject(options);
+            if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_CODE)))
+            {
+                throw new ServiceException("树编码字段不能为空");
+            }
+            else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_PARENT_CODE)))
+            {
+                throw new ServiceException("树父编码字段不能为空");
+            }
+            else if (StringUtils.isEmpty(paramsObj.getString(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 tableId 表编号
-     * @return 预览数据列表
-     */
     @Override
-    public Map<String, String> previewCode(Long tableId)
-    {
+    public Map<String, String> previewCode(String tableId) {
         Map<String, String> dataMap = new LinkedHashMap<>();
         // 查询表信息
-        GenTable table = genTableMapper.selectGenTableById(tableId);
+        GenTable table = genTableMapper.selectByTableId(tableId);
         // 设置主子表信息
         setSubTable(table);
         // 设置主键列信息
         setPkColumn(table);
         VelocityInitializer.initVelocity();
 
-        VelocityContext context = VelocityUtils.prepareContext(table);
+        VelocityContext context = SysVelocityUtils.prepareContext(table);
 
         // 获取模板列表
-        List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory(), table.getTplWebType());
+        List<String> templates = SysVelocityUtils.getTemplateList(table.getTplCategory(), table.getTplWebType());
         for (String template : templates)
         {
             // 渲染模板
@@ -229,15 +267,8 @@ public class GenTableServiceImpl implements IGenTableService
         return dataMap;
     }
 
-    /**
-     * 生成代码(下载方式)
-     * 
-     * @param tableName 表名称
-     * @return 数据
-     */
     @Override
-    public byte[] downloadCode(String tableName)
-    {
+    public byte[] downloadCode(String tableName) {
         ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
         ZipOutputStream zip = new ZipOutputStream(outputStream);
         generatorCode(tableName, zip);
@@ -245,14 +276,25 @@ public class GenTableServiceImpl implements IGenTableService
         return outputStream.toByteArray();
     }
 
+    @Override
+    public byte[] downloadCode(String[] tableNames) {
+        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+        ZipOutputStream zip = new ZipOutputStream(outputStream);
+        for (String tableName : tableNames)
+        {
+            generatorCode(tableName, zip);
+        }
+        IOUtils.closeQuietly(zip);
+        return outputStream.toByteArray();
+    }
+
     /**
      * 生成代码(自定义路径)
-     * 
+     *
      * @param tableName 表名称
      */
     @Override
-    public void generatorCode(String tableName)
-    {
+    public void generatorCode(String tableName) {
         // 查询表信息
         GenTable table = genTableMapper.selectGenTableByName(tableName);
         // 设置主子表信息
@@ -262,10 +304,10 @@ public class GenTableServiceImpl implements IGenTableService
 
         VelocityInitializer.initVelocity();
 
-        VelocityContext context = VelocityUtils.prepareContext(table);
+        VelocityContext context = SysVelocityUtils.prepareContext(table);
 
         // 获取模板列表
-        List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory(), table.getTplWebType());
+        List<String> templates = SysVelocityUtils.getTemplateList(table.getTplCategory(), table.getTplWebType());
         for (String template : templates)
         {
             if (!StringUtils.containsAny(template, "sql.vm", "api.js.vm", "index.vue.vm", "index-tree.vue.vm"))
@@ -287,15 +329,9 @@ public class GenTableServiceImpl implements IGenTableService
         }
     }
 
-    /**
-     * 同步数据库
-     * 
-     * @param tableName 表名称
-     */
     @Override
     @Transactional
-    public void synchDb(String tableName)
-    {
+    public void synchDb(String tableName) {
         GenTable table = genTableMapper.selectGenTableByName(tableName);
         List<GenTableColumn> tableColumns = table.getColumns();
         Map<String, GenTableColumn> tableColumnMap = tableColumns.stream().collect(Collectors.toMap(GenTableColumn::getColumnName, Function.identity()));
@@ -308,7 +344,7 @@ public class GenTableServiceImpl implements IGenTableService
         List<String> dbTableColumnNames = dbTableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList());
 
         dbTableColumns.forEach(column -> {
-            GenUtils.initColumnField(column, table);
+            SysGenUtils.initColumnField(column, table);
             if (tableColumnMap.containsKey(column.getColumnName()))
             {
                 GenTableColumn prevColumn = tableColumnMap.get(column.getColumnName());
@@ -327,11 +363,11 @@ public class GenTableServiceImpl implements IGenTableService
                     column.setIsRequired(prevColumn.getIsRequired());
                     column.setHtmlType(prevColumn.getHtmlType());
                 }
-                genTableColumnMapper.updateGenTableColumn(column);
+                genTableColumnMapper.update(column);
             }
             else
             {
-                genTableColumnMapper.insertGenTableColumn(column);
+                genTableColumnMapper.update(column);
             }
         });
 
@@ -343,105 +379,22 @@ public class GenTableServiceImpl implements IGenTableService
     }
 
     /**
-     * 批量生成代码(下载方式)
-     * 
-     * @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);
-        }
-        IOUtils.closeQuietly(zip);
-        return outputStream.toByteArray();
-    }
-
-    /**
-     * 查询表信息并生成代码
-     */
-    private void generatorCode(String tableName, ZipOutputStream zip)
-    {
-        // 查询表信息
-        GenTable table = genTableMapper.selectGenTableByName(tableName);
-        // 设置主子表信息
-        setSubTable(table);
-        // 设置主键列信息
-        setPkColumn(table);
-
-        VelocityInitializer.initVelocity();
-
-        VelocityContext context = VelocityUtils.prepareContext(table);
-
-        // 获取模板列表
-        List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory(), table.getTplWebType());
-        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)));
-                IOUtils.write(sw.toString(), zip, Constants.UTF8);
-                IOUtils.closeQuietly(sw);
-                zip.flush();
-                zip.closeEntry();
-            }
-            catch (IOException e)
-            {
-                log.error("渲染模板失败,表名:" + table.getTableName(), e);
-            }
-        }
-    }
-
-    /**
-     * 修改保存参数校验
-     * 
-     * @param genTable 业务信息
+     * 设置主子表信息
+     *
+     * @param table 业务表信息
      */
-    @Override
-    public void validateEdit(GenTable genTable)
+    public void setSubTable(GenTable table)
     {
-        if (GenConstants.TPL_TREE.equals(genTable.getTplCategory()))
+        String subTableName = table.getSubTableName();
+        if (StringUtils.isNotEmpty(subTableName))
         {
-            String options = JSON.toJSONString(genTable.getParams());
-            JSONObject paramsObj = JSON.parseObject(options);
-            if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_CODE)))
-            {
-                throw new ServiceException("树编码字段不能为空");
-            }
-            else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_PARENT_CODE)))
-            {
-                throw new ServiceException("树父编码字段不能为空");
-            }
-            else if (StringUtils.isEmpty(paramsObj.getString(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("子表关联的外键名不能为空");
-                }
-            }
+            table.setSubTable(genTableMapper.selectGenTableByName(subTableName));
         }
     }
 
     /**
      * 设置主键列信息
-     * 
+     *
      * @param table 业务表信息
      */
     public void setPkColumn(GenTable table)
@@ -475,47 +428,50 @@ public class GenTableServiceImpl implements IGenTableService
         }
     }
 
-    /**
-     * 设置主子表信息
-     * 
-     * @param table 业务表信息
-     */
-    public void setSubTable(GenTable table)
-    {
-        String subTableName = table.getSubTableName();
-        if (StringUtils.isNotEmpty(subTableName))
-        {
-            table.setSubTable(genTableMapper.selectGenTableByName(subTableName));
-        }
-    }
 
     /**
-     * 设置代码生成其他选项值
-     * 
-     * @param genTable 设置后的生成对象
+     * 查询表信息并生成代码
      */
-    public void setTableFromOptions(GenTable genTable)
+    private void generatorCode(String tableName, ZipOutputStream zip)
     {
-        JSONObject paramsObj = JSON.parseObject(genTable.getOptions());
-        if (StringUtils.isNotNull(paramsObj))
+        // 查询表信息
+        GenTable table = genTableMapper.selectGenTableByName(tableName);
+        // 设置主子表信息
+        setSubTable(table);
+        // 设置主键列信息
+        setPkColumn(table);
+
+        VelocityInitializer.initVelocity();
+
+        VelocityContext context = SysVelocityUtils.prepareContext(table);
+
+        // 获取模板列表
+        List<String> templates = SysVelocityUtils.getTemplateList(table.getTplCategory(), table.getTplWebType());
+        for (String template : templates)
         {
-            String treeCode = paramsObj.getString(GenConstants.TREE_CODE);
-            String treeParentCode = paramsObj.getString(GenConstants.TREE_PARENT_CODE);
-            String treeName = paramsObj.getString(GenConstants.TREE_NAME);
-            String parentMenuId = paramsObj.getString(GenConstants.PARENT_MENU_ID);
-            String parentMenuName = paramsObj.getString(GenConstants.PARENT_MENU_NAME);
-
-            genTable.setTreeCode(treeCode);
-            genTable.setTreeParentCode(treeParentCode);
-            genTable.setTreeName(treeName);
-            genTable.setParentMenuId(parentMenuId);
-            genTable.setParentMenuName(parentMenuName);
+            // 渲染模板
+            StringWriter sw = new StringWriter();
+            Template tpl = Velocity.getTemplate(template, Constants.UTF8);
+            tpl.merge(context, sw);
+            try
+            {
+                // 添加到zip
+                zip.putNextEntry(new ZipEntry(SysVelocityUtils.getFileName(template, table)));
+                IOUtils.write(sw.toString(), zip, Constants.UTF8);
+                IOUtils.closeQuietly(sw);
+                zip.flush();
+                zip.closeEntry();
+            }
+            catch (IOException e)
+            {
+                log.error("渲染模板失败,表名:" + table.getTableName(), e);
+            }
         }
     }
 
     /**
      * 获取代码生成地址
-     * 
+     *
      * @param table 业务表信息
      * @param template 模板文件路径
      * @return 生成地址
@@ -525,8 +481,9 @@ public class GenTableServiceImpl implements IGenTableService
         String genPath = table.getGenPath();
         if (StringUtils.equals(genPath, "/"))
         {
-            return System.getProperty("user.dir") + File.separator + "src" + File.separator + VelocityUtils.getFileName(template, table);
+            return System.getProperty("user.dir") + File.separator + "src" + File.separator + SysVelocityUtils.getFileName(template, table);
         }
-        return genPath + File.separator + VelocityUtils.getFileName(template, table);
+        return genPath + File.separator + SysVelocityUtils.getFileName(template, table);
     }
-}
+
+}

+ 3 - 3
wxjy-wxjy-service/src/main/java/cn/gov/customs/wxjy/generator/util/GenUtils.java → wxjy-wxjy-service/src/main/java/cn/gov/customs/wxjy/generator/util/SysGenUtils.java

@@ -3,8 +3,8 @@ package cn.gov.customs.wxjy.generator.util;
 import cn.gov.customs.wxjy.common.constant.GenConstants;
 import cn.gov.customs.wxjy.common.utils.StringUtils;
 import cn.gov.customs.wxjy.generator.config.GenConfig;
-import cn.gov.customs.wxjy.generator.domain.GenTable;
-import cn.gov.customs.wxjy.generator.domain.GenTableColumn;
+import cn.gov.customs.wxjy.generator.pojo.GenTable;
+import cn.gov.customs.wxjy.generator.pojo.GenTableColumn;
 import org.apache.commons.lang3.RegExUtils;
 
 import java.util.Arrays;
@@ -14,7 +14,7 @@ import java.util.Arrays;
  * 
  * @author ruoyi
  */
-public class GenUtils
+public class SysGenUtils
 {
     /**
      * 初始化表信息

+ 3 - 3
wxjy-wxjy-service/src/main/java/cn/gov/customs/wxjy/generator/util/VelocityUtils.java → wxjy-wxjy-service/src/main/java/cn/gov/customs/wxjy/generator/util/SysVelocityUtils.java

@@ -3,8 +3,8 @@ package cn.gov.customs.wxjy.generator.util;
 import cn.gov.customs.wxjy.common.constant.GenConstants;
 import cn.gov.customs.wxjy.common.utils.DateUtils;
 import cn.gov.customs.wxjy.common.utils.StringUtils;
-import cn.gov.customs.wxjy.generator.domain.GenTable;
-import cn.gov.customs.wxjy.generator.domain.GenTableColumn;
+import cn.gov.customs.wxjy.generator.pojo.GenTable;
+import cn.gov.customs.wxjy.generator.pojo.GenTableColumn;
 import com.alibaba.fastjson2.JSON;
 import com.alibaba.fastjson2.JSONObject;
 import org.apache.velocity.VelocityContext;
@@ -19,7 +19,7 @@ import java.util.Set;
  * 
  * @author ruoyi
  */
-public class VelocityUtils
+public class SysVelocityUtils
 {
     /** 项目空间路径 */
     private static final String PROJECT_PATH = "main/java";

+ 342 - 0
wxjy-wxjy-service/src/main/resources/mapper/gen/GenTableColumnMapper.xml

@@ -0,0 +1,342 @@
+<?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="cn.gov.customs.wxjy.generator.dao.GenTableColumnMapper">
+
+    <resultMap type="GenTableColumn" id="GenTableColumnResult">
+        <result 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="createUser" column="CREATE_USER"/>
+        <result property="createTime" column="CREATE_TIME"/>
+        <result property="updateUser" column="UPDATE_USER"/>
+        <result property="updateTime" column="UPDATE_TIME"/>
+        <result property="isDeleted" column="IS_DELETED"/>
+    </resultMap>
+
+    <sql id="baseVo">
+        select COLUMN_ID, TABLE_ID, COLUMN_NAME, COLUMN_COMMENT, COLUMN_TYPE, JAVA_TYPE, JAVA_FIELD, IS_PK, IS_INCREMENT, IS_REQUIRED, IS_INSERT, IS_EDIT, IS_LIST, IS_QUERY, QUERY_TYPE, HTML_TYPE, DICT_TYPE, SORT, CREATE_USER, CREATE_TIME, UPDATE_USER, UPDATE_TIME, IS_DELETED
+        from SYS_GEN_TABLE_COLUMN
+    </sql>
+
+    <select id="selectList" parameterType="GenTableColumnQuery" resultMap="GenTableColumnResult">
+        <include refid="baseVo"/>
+        <where>
+        <if test="tableId != null  and tableId != ''">
+            and TABLE_ID = #{tableId}
+        </if>
+        <if test="columnName != null  and columnName != ''">
+            and COLUMN_NAME like concat('%', #{columnName}, '%')
+        </if>
+        <if test="columnComment != null  and columnComment != ''">
+            and COLUMN_COMMENT = #{columnComment}
+        </if>
+        <if test="columnType != null  and columnType != ''">
+            and COLUMN_TYPE = #{columnType}
+        </if>
+        <if test="javaType != null  and javaType != ''">
+            and JAVA_TYPE = #{javaType}
+        </if>
+        <if test="javaField != null  and javaField != ''">
+            and JAVA_FIELD = #{javaField}
+        </if>
+        <if test="isPk != null  and isPk != ''">
+            and IS_PK = #{isPk}
+        </if>
+        <if test="isIncrement != null  and isIncrement != ''">
+            and IS_INCREMENT = #{isIncrement}
+        </if>
+        <if test="isRequired != null  and isRequired != ''">
+            and IS_REQUIRED = #{isRequired}
+        </if>
+        <if test="isInsert != null  and isInsert != ''">
+            and IS_INSERT = #{isInsert}
+        </if>
+        <if test="isEdit != null  and isEdit != ''">
+            and IS_EDIT = #{isEdit}
+        </if>
+        <if test="isList != null  and isList != ''">
+            and IS_LIST = #{isList}
+        </if>
+        <if test="isQuery != null  and isQuery != ''">
+            and IS_QUERY = #{isQuery}
+        </if>
+        <if test="queryType != null  and queryType != ''">
+            and QUERY_TYPE = #{queryType}
+        </if>
+        <if test="htmlType != null  and htmlType != ''">
+            and HTML_TYPE = #{htmlType}
+        </if>
+        <if test="dictType != null  and dictType != ''">
+            and DICT_TYPE = #{dictType}
+        </if>
+        <if test="sort != null  and sort != ''">
+            and SORT = #{sort}
+        </if>
+        <if test="createUser != null  and createUser != ''">
+            and CREATE_USER = #{createUser}
+        </if>
+        <if test="createTime != null  and createTime != ''">
+            and CREATE_TIME = #{createTime}
+        </if>
+        <if test="updateUser != null  and updateUser != ''">
+            and UPDATE_USER = #{updateUser}
+        </if>
+        <if test="updateTime != null  and updateTime != ''">
+            and UPDATE_TIME = #{updateTime}
+        </if>
+        <if test="isDeleted != null  and isDeleted != ''">
+            and IS_DELETED = #{isDeleted}
+        </if>
+        </where>
+    </select>
+
+    <select id="selectByColumnId" parameterType="String"
+        resultMap="GenTableColumnResult">
+        <include refid="baseVo"/>
+        where COLUMN_ID = #{columnId}
+    </select>
+    <select id="selectGenTableColumnListByTableId" parameterType="String" resultType="GenTableColumn">
+        <include refid="baseVo"/>
+        where table_id = #{tableId}
+        order by sort
+    </select>
+    <select id="selectDbTableColumnsByName" resultType="GenTableColumn">
+        SELECT
+        c.COLUMN_NAME as column_name,
+        CASE WHEN c.NULLABLE = 'N' THEN '1' ELSE '0' END as is_required,
+        CASE WHEN pk.COLUMN_NAME IS NOT NULL THEN '1' ELSE '0' END as is_pk,
+        c.COLUMN_ID as sort,
+        cc.COMMENTS as column_comment,
+        '0' as is_increment,  <!-- 暂时设为0,不判断自增列 -->
+        c.DATA_TYPE as column_type
+        FROM USER_TAB_COLUMNS c
+        LEFT JOIN USER_COL_COMMENTS cc ON c.TABLE_NAME = cc.TABLE_NAME AND c.COLUMN_NAME = cc.COLUMN_NAME
+        LEFT JOIN (
+        SELECT cu.COLUMN_NAME
+        FROM USER_CONS_COLUMNS cu, USER_CONSTRAINTS au
+        WHERE cu.CONSTRAINT_NAME = au.CONSTRAINT_NAME
+        AND au.CONSTRAINT_TYPE = 'P'
+        AND au.TABLE_NAME = #{tableName}
+        ) pk ON c.COLUMN_NAME = pk.COLUMN_NAME
+        WHERE c.TABLE_NAME = #{tableName}
+        ORDER BY c.COLUMN_ID
+    </select>
+
+    <insert id="insert" parameterType="GenTableColumn">
+        insert into SYS_GEN_TABLE_COLUMN
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="columnId != null and columnId != ''">COLUMN_ID,
+            </if>
+            <if test="tableId != null">TABLE_ID,
+            </if>
+            <if test="columnName != null">COLUMN_NAME,
+            </if>
+            <if test="columnComment != null">COLUMN_COMMENT,
+            </if>
+            <if test="columnType != null">COLUMN_TYPE,
+            </if>
+            <if test="javaType != null">JAVA_TYPE,
+            </if>
+            <if test="javaField != null">JAVA_FIELD,
+            </if>
+            <if test="isPk != null">IS_PK,
+            </if>
+            <if test="isIncrement != null">IS_INCREMENT,
+            </if>
+            <if test="isRequired != null">IS_REQUIRED,
+            </if>
+            <if test="isInsert != null">IS_INSERT,
+            </if>
+            <if test="isEdit != null">IS_EDIT,
+            </if>
+            <if test="isList != null">IS_LIST,
+            </if>
+            <if test="isQuery != null">IS_QUERY,
+            </if>
+            <if test="queryType != null">QUERY_TYPE,
+            </if>
+            <if test="htmlType != null">HTML_TYPE,
+            </if>
+            <if test="dictType != null">DICT_TYPE,
+            </if>
+            <if test="sort != null">SORT,
+            </if>
+            <if test="createUser != null">CREATE_USER,
+            </if>
+            <if test="createTime != null">CREATE_TIME,
+            </if>
+            <if test="updateUser != null">UPDATE_USER,
+            </if>
+            <if test="updateTime != null">UPDATE_TIME,
+            </if>
+            <if test="isDeleted != null">IS_DELETED,
+            </if>
+        </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
+            <if test="columnId != null and columnId != ''">#{columnId},
+            </if>
+            <if test="tableId != null">#{tableId},
+            </if>
+            <if test="columnName != null">#{columnName},
+            </if>
+            <if test="columnComment != null">#{columnComment},
+            </if>
+            <if test="columnType != null">#{columnType},
+            </if>
+            <if test="javaType != null">#{javaType},
+            </if>
+            <if test="javaField != null">#{javaField},
+            </if>
+            <if test="isPk != null">#{isPk},
+            </if>
+            <if test="isIncrement != null">#{isIncrement},
+            </if>
+            <if test="isRequired != null">#{isRequired},
+            </if>
+            <if test="isInsert != null">#{isInsert},
+            </if>
+            <if test="isEdit != null">#{isEdit},
+            </if>
+            <if test="isList != null">#{isList},
+            </if>
+            <if test="isQuery != null">#{isQuery},
+            </if>
+            <if test="queryType != null">#{queryType},
+            </if>
+            <if test="htmlType != null">#{htmlType},
+            </if>
+            <if test="dictType != null">#{dictType},
+            </if>
+            <if test="sort != null">#{sort},
+            </if>
+            <if test="createUser != null">#{createUser},
+            </if>
+            <if test="createTime != null">#{createTime},
+            </if>
+            <if test="updateUser != null">#{updateUser},
+            </if>
+            <if test="updateTime != null">#{updateTime},
+            </if>
+            <if test="isDeleted != null">#{isDeleted},
+            </if>
+        </trim>
+    </insert>
+
+    <update id="update" parameterType="GenTableColumn">
+        update SYS_GEN_TABLE_COLUMN
+        <trim prefix="SET" suffixOverrides=",">
+            <if test="tableId != null">TABLE_ID =
+                #{tableId},
+            </if>
+            <if test="columnName != null">COLUMN_NAME =
+                #{columnName},
+            </if>
+            <if test="columnComment != null">COLUMN_COMMENT =
+                #{columnComment},
+            </if>
+            <if test="columnType != null">COLUMN_TYPE =
+                #{columnType},
+            </if>
+            <if test="javaType != null">JAVA_TYPE =
+                #{javaType},
+            </if>
+            <if test="javaField != null">JAVA_FIELD =
+                #{javaField},
+            </if>
+            <if test="isPk != null">IS_PK =
+                #{isPk},
+            </if>
+            <if test="isIncrement != null">IS_INCREMENT =
+                #{isIncrement},
+            </if>
+            <if test="isRequired != null">IS_REQUIRED =
+                #{isRequired},
+            </if>
+            <if test="isInsert != null">IS_INSERT =
+                #{isInsert},
+            </if>
+            <if test="isEdit != null">IS_EDIT =
+                #{isEdit},
+            </if>
+            <if test="isList != null">IS_LIST =
+                #{isList},
+            </if>
+            <if test="isQuery != null">IS_QUERY =
+                #{isQuery},
+            </if>
+            <if test="queryType != null">QUERY_TYPE =
+                #{queryType},
+            </if>
+            <if test="htmlType != null">HTML_TYPE =
+                #{htmlType},
+            </if>
+            <if test="dictType != null">DICT_TYPE =
+                #{dictType},
+            </if>
+            <if test="sort != null">SORT =
+                #{sort},
+            </if>
+            <if test="createUser != null">CREATE_USER =
+                #{createUser},
+            </if>
+            <if test="createTime != null">CREATE_TIME =
+                #{createTime},
+            </if>
+            <if test="updateUser != null">UPDATE_USER =
+                #{updateUser},
+            </if>
+            <if test="updateTime != null">UPDATE_TIME =
+                #{updateTime},
+            </if>
+            <if test="isDeleted != null">IS_DELETED =
+                #{isDeleted},
+            </if>
+        </trim>
+        where COLUMN_ID = #{columnId}
+    </update>
+
+    <delete id="deleteByColumnId" parameterType="String">
+        delete
+        from SYS_GEN_TABLE_COLUMN where COLUMN_ID = #{columnId}
+    </delete>
+
+    <delete id="deleteByColumnIds" parameterType="String">
+        delete from SYS_GEN_TABLE_COLUMN where COLUMN_ID in
+        <foreach item="columnId" collection="array" open="(" separator="," close=")">
+            #{columnId}
+        </foreach>
+    </delete>
+
+    <delete id="logicDelete" parameterType="String">
+        update  SYS_GEN_TABLE_COLUMN set is_del = 1  where COLUMN_ID = #{columnId}
+    </delete>
+    <delete id="deleteGenTableColumnByIds">
+        delete from SYS_GEN_TABLE_COLUMN where table_id in
+        <foreach collection="array" item="tableId" open="(" separator="," close=")">
+            #{tableId}
+        </foreach>
+    </delete>
+    <delete id="deleteGenTableColumns">
+        delete from SYS_GEN_TABLE_COLUMN where column_id in
+        <foreach collection="list" item="item" open="(" separator="," close=")">
+            #{item.columnId}
+        </foreach>
+    </delete>
+</mapper>

+ 359 - 0
wxjy-wxjy-service/src/main/resources/mapper/gen/GenTableMapper.xml

@@ -0,0 +1,359 @@
+<?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="cn.gov.customs.wxjy.generator.dao.GenTableMapper">
+
+    <resultMap type="GenTable" id="GenTableResult">
+        <result 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="createUser" column="CREATE_USER"/>
+        <result property="createTime" column="CREATE_TIME"/>
+        <result property="updateUser" column="UPDATE_USER"/>
+        <result property="updateTime" column="UPDATE_TIME"/>
+        <result property="remark" column="REMARK"/>
+        <result property="tplWebType" column="TPL_WEB_TYPE"/>
+        <result property="isDeleted" column="IS_DELETED"/>
+        <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="createUser"       column="CREATE_USER"      />
+        <result property="createTime"     column="create_time"    />
+        <result property="updateUser"       column="UPDATE_USER"      />
+        <result property="updateTime"     column="update_time"    />
+    </resultMap>
+
+    <sql id="baseVo">
+        select TABLE_ID, TABLE_NAME, TABLE_COMMENT, SUB_TABLE_NAME, SUB_TABLE_FK_NAME, CLASS_NAME, TPL_CATEGORY, PACKAGE_NAME, MODULE_NAME, BUSINESS_NAME, FUNCTION_NAME, FUNCTION_AUTHOR, GEN_TYPE, GEN_PATH, OPTIONS, CREATE_USER, CREATE_TIME, UPDATE_USER, UPDATE_TIME, REMARK, TPL_WEB_TYPE, IS_DELETED
+        from SYS_GEN_TABLE
+    </sql>
+
+    <select id="selectList" parameterType="GenTableQuery" resultMap="GenTableResult">
+        <include refid="baseVo"/>
+        <where>
+            <if test="tableName != null  and tableName != ''">
+                and TABLE_NAME like concat('%', #{tableName}, '%')
+            </if>
+            <if test="tableComment != null  and tableComment != ''">
+                and TABLE_COMMENT = #{tableComment}
+            </if>
+            <if test="subTableName != null  and subTableName != ''">
+                and SUB_TABLE_NAME like concat('%', #{subTableName}, '%')
+            </if>
+            <if test="subTableFkName != null  and subTableFkName != ''">
+                and SUB_TABLE_FK_NAME like concat('%', #{subTableFkName}, '%')
+            </if>
+            <if test="className != null  and className != ''">
+                and CLASS_NAME like concat('%', #{className}, '%')
+            </if>
+            <if test="tplCategory != null  and tplCategory != ''">
+                and TPL_CATEGORY = #{tplCategory}
+            </if>
+            <if test="packageName != null  and packageName != ''">
+                and PACKAGE_NAME like concat('%', #{packageName}, '%')
+            </if>
+            <if test="moduleName != null  and moduleName != ''">
+                and MODULE_NAME like concat('%', #{moduleName}, '%')
+            </if>
+            <if test="businessName != null  and businessName != ''">
+                and BUSINESS_NAME like concat('%', #{businessName}, '%')
+            </if>
+            <if test="functionName != null  and functionName != ''">
+                and FUNCTION_NAME like concat('%', #{functionName}, '%')
+            </if>
+            <if test="functionAuthor != null  and functionAuthor != ''">
+                and FUNCTION_AUTHOR = #{functionAuthor}
+            </if>
+            <if test="genType != null  and genType != ''">
+                and GEN_TYPE = #{genType}
+            </if>
+            <if test="genPath != null  and genPath != ''">
+                and GEN_PATH = #{genPath}
+            </if>
+            <if test="options != null  and options != ''">
+                and OPTIONS = #{options}
+            </if>
+            <if test="beginDate != null and beginDate != ''">
+                and UPDATE_TIME &gt;= #{beginDate}
+            </if>
+            <if test="endDate != null and endDate != ''">
+                and UPDATE_TIME &lt;= #{endDate}
+            </if>
+            <if test="tplWebType != null  and tplWebType != ''">
+                and TPL_WEB_TYPE = #{tplWebType}
+            </if>
+
+        </where>
+    </select>
+
+    <select id="selectByTableId" parameterType="String"
+            resultMap="GenTableResult">
+        <include refid="baseVo"/>
+        where TABLE_ID = #{tableId}
+    </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, coalesce(c.dict_type,'') as dict_type, c.sort
+        FROM sys_gen_table t
+                 LEFT JOIN sys_gen_table_column c ON t.table_id = c.table_id
+        order by c.sort
+    </select>
+    <select id="selectDbTableList" parameterType="GenTableQuery" resultMap="GenTableResult">
+        SELECT
+        t.TABLE_NAME as TABLE_NAME,
+        t.COMMENTS as TABLE_COMMENT,
+        SYSDATE as CREATE_TIME,
+        SYSDATE as UPDATE_TIME
+        FROM ALL_TAB_COMMENTS t
+        WHERE t.OWNER = (SELECT USER FROM DUAL)
+        AND t.TABLE_NAME NOT LIKE 'QRTZ_%'
+        AND t.TABLE_NAME NOT LIKE 'GEN_%'
+        AND t.TABLE_NAME NOT LIKE 'SYS_GEN_%'
+        AND t.TABLE_NAME NOT IN (SELECT table_name FROM sys_gen_table)
+        <if test="tableName != null and tableName != ''">
+            AND LOWER(t.TABLE_NAME) LIKE LOWER(CONCAT(CONCAT('%', #{tableName}), '%'))
+        </if>
+        <if test="tableComment != null and tableComment != ''">
+            AND LOWER(t.COMMENTS) LIKE LOWER(CONCAT(CONCAT('%', #{tableComment}), '%'))
+        </if>
+        ORDER BY t.TABLE_NAME
+    </select>
+
+    <select id="selectDbTableListByNames" resultMap="GenTableResult">
+        SELECT
+        t.TABLE_NAME as TABLE_NAME,
+        t.COMMENTS as TABLE_COMMENT,
+        SYSDATE as CREATE_TIME,
+        SYSDATE as UPDATE_TIME
+        FROM ALL_TAB_COMMENTS t
+        WHERE t.OWNER = (SELECT USER FROM DUAL)
+        AND t.TABLE_NAME NOT LIKE 'QRTZ_%'
+        AND t.TABLE_NAME NOT LIKE 'GEN_%'
+        AND t.TABLE_NAME NOT LIKE 'SYS_GEN_%'
+        AND t.TABLE_NAME IN
+        <foreach collection="array" item="name" open="(" separator="," close=")">
+            #{name}
+        </foreach>
+    </select>
+    <select id="selectGenTableByName" 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, coalesce(c.dict_type,'') as dict_type, c.sort
+        FROM SYS_GEN_TABLE t
+                 LEFT JOIN sys_gen_table_column c ON t.table_id = c.table_id
+        where t.table_name = #{tableName} order by c.sort
+    </select>
+
+    <insert id="insert" parameterType="GenTable" useGeneratedKeys="true" keyProperty="tableId">
+        insert into SYS_GEN_TABLE
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="tableId != null and tableId != ''">TABLE_ID,
+            </if>
+            <if test="tableName != null">TABLE_NAME,
+            </if>
+            <if test="tableComment != null">TABLE_COMMENT,
+            </if>
+            <if test="subTableName != null">SUB_TABLE_NAME,
+            </if>
+            <if test="subTableFkName != null">SUB_TABLE_FK_NAME,
+            </if>
+            <if test="className != null">CLASS_NAME,
+            </if>
+            <if test="tplCategory != null">TPL_CATEGORY,
+            </if>
+            <if test="packageName != null">PACKAGE_NAME,
+            </if>
+            <if test="moduleName != null">MODULE_NAME,
+            </if>
+            <if test="businessName != null">BUSINESS_NAME,
+            </if>
+            <if test="functionName != null">FUNCTION_NAME,
+            </if>
+            <if test="functionAuthor != null">FUNCTION_AUTHOR,
+            </if>
+            <if test="genType != null">GEN_TYPE,
+            </if>
+            <if test="genPath != null">GEN_PATH,
+            </if>
+            <if test="options != null">OPTIONS,
+            </if>
+            <if test="createUser != null">CREATE_USER,
+            </if>
+            <if test="createTime != null">CREATE_TIME,
+            </if>
+            <if test="updateUser != null">UPDATE_USER,
+            </if>
+            <if test="updateTime != null">UPDATE_TIME,
+            </if>
+            <if test="remark != null">REMARK,
+            </if>
+            <if test="tplWebType != null">TPL_WEB_TYPE,
+            </if>
+            <if test="isDeleted != null">IS_DELETED,
+            </if>
+        </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
+            <if test="tableId != null and tableId != ''">#{tableId},
+            </if>
+            <if test="tableName != null">#{tableName},
+            </if>
+            <if test="tableComment != null">#{tableComment},
+            </if>
+            <if test="subTableName != null">#{subTableName},
+            </if>
+            <if test="subTableFkName != null">#{subTableFkName},
+            </if>
+            <if test="className != null">#{className},
+            </if>
+            <if test="tplCategory != null">#{tplCategory},
+            </if>
+            <if test="packageName != null">#{packageName},
+            </if>
+            <if test="moduleName != null">#{moduleName},
+            </if>
+            <if test="businessName != null">#{businessName},
+            </if>
+            <if test="functionName != null">#{functionName},
+            </if>
+            <if test="functionAuthor != null">#{functionAuthor},
+            </if>
+            <if test="genType != null">#{genType},
+            </if>
+            <if test="genPath != null">#{genPath},
+            </if>
+            <if test="options != null">#{options},
+            </if>
+            <if test="createUser != null">#{createUser},
+            </if>
+            <if test="createTime != null">#{createTime},
+            </if>
+            <if test="updateUser != null">#{updateUser},
+            </if>
+            <if test="updateTime != null">#{updateTime},
+            </if>
+            <if test="remark != null">#{remark},
+            </if>
+            <if test="tplWebType != null">#{tplWebType},
+            </if>
+            <if test="isDeleted != null">#{isDeleted},
+            </if>
+        </trim>
+    </insert>
+
+    <update id="update" parameterType="GenTable">
+        update SYS_GEN_TABLE
+        <trim prefix="SET" suffixOverrides=",">
+            <if test="tableName != null">TABLE_NAME =
+                #{tableName},
+            </if>
+            <if test="tableComment != null">TABLE_COMMENT =
+                #{tableComment},
+            </if>
+            <if test="subTableName != null">SUB_TABLE_NAME =
+                #{subTableName},
+            </if>
+            <if test="subTableFkName != null">SUB_TABLE_FK_NAME =
+                #{subTableFkName},
+            </if>
+            <if test="className != null">CLASS_NAME =
+                #{className},
+            </if>
+            <if test="tplCategory != null">TPL_CATEGORY =
+                #{tplCategory},
+            </if>
+            <if test="packageName != null">PACKAGE_NAME =
+                #{packageName},
+            </if>
+            <if test="moduleName != null">MODULE_NAME =
+                #{moduleName},
+            </if>
+            <if test="businessName != null">BUSINESS_NAME =
+                #{businessName},
+            </if>
+            <if test="functionName != null">FUNCTION_NAME =
+                #{functionName},
+            </if>
+            <if test="functionAuthor != null">FUNCTION_AUTHOR =
+                #{functionAuthor},
+            </if>
+            <if test="genType != null">GEN_TYPE =
+                #{genType},
+            </if>
+            <if test="genPath != null">GEN_PATH =
+                #{genPath},
+            </if>
+            <if test="options != null">OPTIONS =
+                #{options},
+            </if>
+            <if test="createUser != null">CREATE_USER =
+                #{createUser},
+            </if>
+            <if test="createTime != null">CREATE_TIME =
+                #{createTime},
+            </if>
+            <if test="updateUser != null">UPDATE_USER =
+                #{updateUser},
+            </if>
+            <if test="updateTime != null">UPDATE_TIME =
+                #{updateTime},
+            </if>
+            <if test="remark != null">REMARK =
+                #{remark},
+            </if>
+            <if test="tplWebType != null">TPL_WEB_TYPE =
+                #{tplWebType},
+            </if>
+            <if test="isDeleted != null">IS_DELETED =
+                #{isDeleted},
+            </if>
+        </trim>
+        where TABLE_ID = #{tableId}
+    </update>
+
+    <delete id="deleteByTableId" parameterType="String">
+        delete
+        from SYS_GEN_TABLE where TABLE_ID = #{tableId}
+    </delete>
+
+    <delete id="deleteByTableIds" parameterType="String">
+        delete from SYS_GEN_TABLE where TABLE_ID in
+        <foreach item="tableId" collection="array" open="(" separator="," close=")">
+            #{tableId}
+        </foreach>
+    </delete>
+
+    <delete id="logicDelete" parameterType="String">
+        update  SYS_GEN_TABLE set is_del = 1  where TABLE_ID = #{tableId}
+    </delete>
+</mapper>

+ 0 - 183
wxjy-wxjy-service/src/main/resources/mapper/generator/GenTableColumnMapper.xml

@@ -1,183 +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="cn.gov.customs.wxjy.generator.dao.GenTableColumnMapper">
-
-    <resultMap type="cn.gov.customs.wxjy.generator.domain.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="createUser" column="CREATE_USER"/>
-        <result property="createTime" column="create_time"/>
-        <result property="updateUser" column="UPDATE_USER"/>
-        <result property="updateTime" column="update_time"/>
-    </resultMap>
-
-    <sql id="selectGenTableColumnVo">
-        select column_id,
-               table_id,
-               column_name,
-               column_comment,
-               column_type,
-               java_type,
-               java_field,
-               is_pk,
-               is_increment,
-               is_required,
-               is_insert,
-               is_edit,
-               is_list,
-               is_query,
-               query_type,
-               html_type,
-               dict_type,
-               sort,
-               CREATE_USER,
-               create_time,
-               UPDATE_USER,
-               update_time
-        from gen_table_column
-    </sql>
-
-    <select id="selectGenTableColumnListByTableId" parameterType="Long" resultMap="GenTableColumnResult">
-        <include refid="selectGenTableColumnVo"/>
-        where table_id = #{tableId}
-        order by sort
-    </select>
-
-    <select id="selectDbTableColumnsByName" parameterType="String" resultMap="GenTableColumnResult">
-        SELECT
-        c.COLUMN_NAME as column_name,
-        CASE WHEN c.NULLABLE = 'N' THEN '1' ELSE '0' END as is_required,
-        CASE WHEN pk.COLUMN_NAME IS NOT NULL THEN '1' ELSE '0' END as is_pk,
-        c.COLUMN_ID as sort,
-        cc.COMMENTS as column_comment,
-        '0' as is_increment,  <!-- 暂时设为0,不判断自增列 -->
-        c.DATA_TYPE as column_type
-        FROM USER_TAB_COLUMNS c
-        LEFT JOIN USER_COL_COMMENTS cc ON c.TABLE_NAME = cc.TABLE_NAME AND c.COLUMN_NAME = cc.COLUMN_NAME
-        LEFT JOIN (
-        SELECT cu.COLUMN_NAME
-        FROM USER_CONS_COLUMNS cu, USER_CONSTRAINTS au
-        WHERE cu.CONSTRAINT_NAME = au.CONSTRAINT_NAME
-        AND au.CONSTRAINT_TYPE = 'P'
-        AND au.TABLE_NAME = #{tableName}
-        ) pk ON c.COLUMN_NAME = pk.COLUMN_NAME
-        WHERE c.TABLE_NAME = #{tableName}
-        ORDER BY c.COLUMN_ID
-    </select>
-
-    <!-- 如果上面的方法还有问题,使用这个最简版本 -->
-    <!--
-    <select id="selectDbTableColumnsByName" parameterType="String" resultMap="GenTableColumnResult">
-        SELECT
-            COLUMN_NAME as column_name,
-            CASE WHEN NULLABLE = 'N' THEN '1' ELSE '0' END as is_required,
-            '0' as is_pk,
-            COLUMN_ID as sort,
-            COMMENTS as column_comment,
-            '0' as is_increment,
-            DATA_TYPE as column_type
-        FROM USER_TAB_COLUMNS c
-        LEFT JOIN USER_COL_COMMENTS cc ON c.TABLE_NAME = cc.TABLE_NAME AND c.COLUMN_NAME = cc.COLUMN_NAME
-        WHERE c.TABLE_NAME = #{tableName}
-        ORDER BY c.COLUMN_ID
-    </select>
-    -->
-
-    <insert id="insertGenTableColumn" parameterType="cn.gov.customs.wxjy.generator.domain.GenTableColumn" useGeneratedKeys="true" keyProperty="columnId">
-        insert into gen_table_column (
-        <if test="tableId != null and tableId != ''">table_id,</if>
-        <if test="columnName != null and columnName != ''">column_name,</if>
-        <if test="columnComment != null and columnComment != ''">column_comment,</if>
-        <if test="columnType != null and columnType != ''">column_type,</if>
-        <if test="javaType != null and javaType != ''">java_type,</if>
-        <if test="javaField != null  and javaField != ''">java_field,</if>
-        <if test="isPk != null and isPk != ''">is_pk,</if>
-        <if test="isIncrement != null and isIncrement != ''">is_increment,</if>
-        <if test="isRequired != null and isRequired != ''">is_required,</if>
-        <if test="isInsert != null and isInsert != ''">is_insert,</if>
-        <if test="isEdit != null and isEdit != ''">is_edit,</if>
-        <if test="isList != null and isList != ''">is_list,</if>
-        <if test="isQuery != null and isQuery != ''">is_query,</if>
-        <if test="queryType != null and queryType != ''">query_type,</if>
-        <if test="htmlType != null and htmlType != ''">html_type,</if>
-        <if test="dictType != null and dictType != ''">dict_type,</if>
-        <if test="sort != null">sort,</if>
-        <if test="createUser != null and createUser != ''">CREATE_USER,</if>
-        create_time
-        )values(
-        <if test="tableId != null and tableId != ''">#{tableId},</if>
-        <if test="columnName != null and columnName != ''">#{columnName},</if>
-        <if test="columnComment != null and columnComment != ''">#{columnComment},</if>
-        <if test="columnType != null and columnType != ''">#{columnType},</if>
-        <if test="javaType != null and javaType != ''">#{javaType},</if>
-        <if test="javaField != null and javaField != ''">#{javaField},</if>
-        <if test="isPk != null and isPk != ''">#{isPk},</if>
-        <if test="isIncrement != null and isIncrement != ''">#{isIncrement},</if>
-        <if test="isRequired != null and isRequired != ''">#{isRequired},</if>
-        <if test="isInsert != null and isInsert != ''">#{isInsert},</if>
-        <if test="isEdit != null and isEdit != ''">#{isEdit},</if>
-        <if test="isList != null and isList != ''">#{isList},</if>
-        <if test="isQuery != null and isQuery != ''">#{isQuery},</if>
-        <if test="queryType != null and queryType != ''">#{queryType},</if>
-        <if test="htmlType != null and htmlType != ''">#{htmlType},</if>
-        <if test="dictType != null and dictType != ''">#{dictType},</if>
-        <if test="sort != null">#{sort},</if>
-        <if test="createUser != null and createUser != ''">#{createUser},</if>
-        current_timestamp
-        )
-    </insert>
-
-    <update id="updateGenTableColumn" parameterType="cn.gov.customs.wxjy.generator.domain.GenTableColumn">
-        update gen_table_column
-        <set>
-            <if test="columnComment != null">column_comment = #{columnComment},</if>
-            <if test="javaType != null">java_type = #{javaType},</if>
-            <if test="javaField != null">java_field = #{javaField},</if>
-            <if test="isInsert != null">is_insert = #{isInsert},</if>
-            <if test="isEdit != null">is_edit = #{isEdit},</if>
-            <if test="isList != null">is_list = #{isList},</if>
-            <if test="isQuery != null">is_query = #{isQuery},</if>
-            <if test="isRequired != null">is_required = #{isRequired},</if>
-            <if test="queryType != null">query_type = #{queryType},</if>
-            <if test="htmlType != null">html_type = #{htmlType},</if>
-            <if test="dictType != null">dict_type = #{dictType},</if>
-            <if test="sort != null">sort = #{sort},</if>
-            <if test="updateUser != null">UPDATE_USER = #{updateUser},</if>
-            update_time = current_timestamp
-        </set>
-        where column_id = #{columnId}
-    </update>
-
-    <delete id="deleteGenTableColumnByIds" parameterType="Long">
-        delete from gen_table_column where table_id in
-        <foreach collection="array" item="tableId" open="(" separator="," close=")">
-            #{tableId}
-        </foreach>
-    </delete>
-
-    <delete id="deleteGenTableColumns">
-        delete from gen_table_column where column_id in
-        <foreach collection="list" item="item" open="(" separator="," close=")">
-            #{item.columnId}
-        </foreach>
-    </delete>
-
-</mapper>

+ 0 - 214
wxjy-wxjy-service/src/main/resources/mapper/generator/GenTableMapper.xml

@@ -1,214 +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="cn.gov.customs.wxjy.generator.dao.GenTableMapper">
-
-	<resultMap type="cn.gov.customs.wxjy.generator.domain.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="createUser"       column="CREATE_USER"         />
-		<result property="createTime"     column="create_time"       />
-		<result property="updateUser"       column="UPDATE_USER"         />
-		<result property="updateTime"     column="update_time"       />
-		<result property="remark"         column="remark"            />
-		<collection  property="columns"  javaType="java.util.List"  resultMap="GenTableColumnResult" />
-	</resultMap>
-
-	<resultMap type="cn.gov.customs.wxjy.generator.domain.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="createUser"       column="CREATE_USER"      />
-        <result property="createTime"     column="create_time"    />
-        <result property="updateUser"       column="UPDATE_USER"      />
-        <result property="updateTime"     column="update_time"    />
-    </resultMap>
-
-	<sql id="selectGenTableVo">
-        select table_id, table_name, table_comment, sub_table_name, sub_table_fk_name, class_name, tpl_category, package_name, module_name, business_name, function_name, function_author, gen_type, gen_path, options, CREATE_USER, create_time, UPDATE_USER, update_time, remark from gen_table
-    </sql>
-
-    <select id="selectGenTableList" parameterType="cn.gov.customs.wxjy.generator.domain.GenTable" resultMap="GenTableResult">
-		<include refid="selectGenTableVo"/>
-		<where>
-			<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>
-			<if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
-				and to_char(create_time,'yyyy-MM-dd') &gt;= to_char(#{params.beginTime},'yyyy-MM-dd')
-			</if>
-			<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
-				and to_char(create_time,'yyyy-MM-dd') &lt;= to_char(#{params.endTime},'yyyy-MM-dd')
-			</if>
-		</where>
-	</select>
-
-	<select id="selectDbTableList" parameterType="cn.gov.customs.wxjy.generator.domain.GenTable" resultMap="GenTableResult">
-		SELECT
-		t.TABLE_NAME as table_name,
-		t.COMMENTS as table_comment,
-		SYSDATE as create_time,
-		SYSDATE as update_time
-		FROM ALL_TAB_COMMENTS t
-		WHERE t.OWNER = (SELECT USER FROM DUAL)
-		AND t.TABLE_NAME NOT LIKE 'QRTZ_%'
-		AND t.TABLE_NAME NOT LIKE 'GEN_%'
-		AND t.TABLE_NAME NOT IN (SELECT table_name FROM gen_table)
-		<if test="tableName != null and tableName != ''">
-			AND LOWER(t.TABLE_NAME) LIKE LOWER(CONCAT(CONCAT('%', #{tableName}), '%'))
-		</if>
-		<if test="tableComment != null and tableComment != ''">
-			AND LOWER(t.COMMENTS) LIKE LOWER(CONCAT(CONCAT('%', #{tableComment}), '%'))
-		</if>
-		ORDER BY t.TABLE_NAME
-	</select>
-
-	<select id="selectDbTableListByNames" resultMap="GenTableResult">
-		SELECT
-		t.TABLE_NAME as table_name,
-		t.COMMENTS as table_comment,
-		SYSDATE as create_time,
-		SYSDATE as update_time
-		FROM ALL_TAB_COMMENTS t
-		WHERE t.OWNER = (SELECT USER FROM DUAL)
-		AND t.TABLE_NAME NOT LIKE 'QRTZ_%'
-		AND t.TABLE_NAME NOT LIKE 'GEN_%'
-		AND t.TABLE_NAME IN
-		<foreach collection="array" item="name" open="(" separator="," close=")">
-			#{name}
-		</foreach>
-	</select>
-
-	<select id="selectTableByName" parameterType="String" resultMap="GenTableResult">
-		SELECT
-			t.TABLE_NAME as table_name,
-			t.COMMENTS as table_comment,
-			SYSDATE as create_time,
-			SYSDATE as update_time
-		FROM ALL_TAB_COMMENTS t
-		WHERE t.OWNER = (SELECT USER FROM DUAL)
-		  AND t.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, coalesce(c.dict_type,'') as 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, coalesce(c.dict_type,'') as 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, coalesce(c.dict_type,'') as 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>
-
-	<insert id="insertGenTable" parameterType="cn.gov.customs.wxjy.generator.domain.GenTable" useGeneratedKeys="true" keyProperty="tableId">
-        insert into gen_table (
-			<if test="tableName != null">table_name,</if>
-			<if test="tableComment != null and tableComment != ''">table_comment,</if>
-			<if test="className != null and className != ''">class_name,</if>
-			<if test="tplCategory != null and tplCategory != ''">tpl_category,</if>
-			<if test="packageName != null and packageName != ''">package_name,</if>
-			<if test="moduleName != null and moduleName != ''">module_name,</if>
-			<if test="businessName != null and businessName != ''">business_name,</if>
-			<if test="functionName != null and functionName != ''">function_name,</if>
-			<if test="functionAuthor != null and functionAuthor != ''">function_author,</if>
-			<if test="genType != null and genType != ''">gen_type,</if>
-			<if test="genPath != null and genPath != ''">gen_path,</if>
-			<if test="remark != null and remark != ''">remark,</if>
- 			<if test="createUser != null and createUser != ''">CREATE_USER,</if>
-			create_time
-         )values(
-			<if test="tableName != null">#{tableName},</if>
-			<if test="tableComment != null and tableComment != ''">#{tableComment},</if>
-			<if test="className != null and className != ''">#{className},</if>
-			<if test="tplCategory != null and tplCategory != ''">#{tplCategory},</if>
-			<if test="packageName != null and packageName != ''">#{packageName},</if>
-			<if test="moduleName != null and moduleName != ''">#{moduleName},</if>
-			<if test="businessName != null and businessName != ''">#{businessName},</if>
-			<if test="functionName != null and functionName != ''">#{functionName},</if>
-			<if test="functionAuthor != null and functionAuthor != ''">#{functionAuthor},</if>
-			<if test="genType != null and genType != ''">#{genType},</if>
-			<if test="genPath != null and genPath != ''">#{genPath},</if>
-			<if test="remark != null and remark != ''">#{remark},</if>
- 			<if test="createUser != null and createUser != ''">#{createUser},</if>
-			current_timestamp
-         )
-    </insert>
-
-    <update id="updateGenTable" parameterType="cn.gov.customs.wxjy.generator.domain.GenTable">
-        update gen_table
-        <set>
-            <if test="tableName != null">table_name = #{tableName},</if>
-            <if test="tableComment != null and tableComment != ''">table_comment = #{tableComment},</if>
-            <if test="subTableName != null">sub_table_name = #{subTableName},</if>
-            <if test="subTableFkName != null">sub_table_fk_name = #{subTableFkName},</if>
-            <if test="className != null and className != ''">class_name = #{className},</if>
-            <if test="functionAuthor != null and functionAuthor != ''">function_author = #{functionAuthor},</if>
-            <if test="genType != null and genType != ''">gen_type = #{genType},</if>
-            <if test="genPath != null and genPath != ''">gen_path = #{genPath},</if>
-            <if test="tplCategory != null and tplCategory != ''">tpl_category = #{tplCategory},</if>
-            <if test="packageName != null and packageName != ''">package_name = #{packageName},</if>
-            <if test="moduleName != null and moduleName != ''">module_name = #{moduleName},</if>
-            <if test="businessName != null and businessName != ''">business_name = #{businessName},</if>
-            <if test="functionName != null and functionName != ''">function_name = #{functionName},</if>
-            <if test="options != null and options != ''">options = #{options},</if>
-            <if test="updateUser != null and updateUser != ''">UPDATE_USER = #{updateUser},</if>
-            <if test="remark != null">remark = #{remark},</if>
-            update_time = current_timestamp
-        </set>
-        where table_id = #{tableId}
-    </update>
-
-    <delete id="deleteGenTableByIds" parameterType="Long">
-        delete from gen_table where table_id in
-        <foreach collection="array" item="tableId" open="(" separator="," close=")">
-            #{tableId}
-        </foreach>
-    </delete>
-
-</mapper>

+ 1 - 0
wxjy-wxjy-web/package.json

@@ -53,6 +53,7 @@
     "@types/node": "22.8.4",
     "@types/nprogress": "0.2.3",
     "@types/qs": "6.9.15",
+    "@types/sortablejs": "^1.15.9",
     "@types/string-format": "2.0.3",
     "@vitejs/plugin-vue": "4.1.0",
     "@vitejs/plugin-vue-jsx": "3.0.1",

+ 34 - 91
wxjy-wxjy-web/src/apis/gen/gen.ts

@@ -1,129 +1,72 @@
-// api/tool/gen.ts
 import type { AxiosResponse } from 'axios'
 import type { PageInfo, Result } from '@cacp/ui'
 import request from '@/utils/request'
 
-// 类型定义
-export interface GenTableInfo {
-  tableId: number
-  tableName: string
-  tableComment: string
-  className: string
-  createTime: string
-  updateTime: string
-  genType?: string
-  genPath?: string
-}
-
-export interface DbTableInfo {
-  tableName: string
-  tableComment: string
-  createTime: string
-  updateTime: string
-}
-
-export interface GenTableQuery {
-  pageNum?: number
-  pageSize?: number
-  tableName?: string
-  tableComment?: string
-  beginTime?: string
-  endTime?: string
-}
-
-export interface ImportTableParams {
-  tables: string
-}
-
-export interface CreateTableParams {
-  tableName: string
-  tableComment: string
-  // 其他创建表需要的参数
-}
+import type {GenTable,GenTableQuery}  from '@/types/gen/GenTable'
 
 export interface PreviewResult {
   [key: string]: string
 }
 
-const contextPath = '/tool/gen'
+const contextPath = '/gen/GenTable'
 
-// 查询生成表数据
-export async function listTable(query: GenTableQuery): Promise<Result<PageInfo<GenTableInfo>>> {
-  const res: AxiosResponse<Result<PageInfo<GenTableInfo>>> = await request.get(
-    `${contextPath}/list`,
-    { params: query }
-  )
+// 查询代码生成业务列表
+export async function getList(query: GenTableQuery): Promise<Result<PageInfo<GenTable>>> {
+  const res: AxiosResponse<Result<PageInfo<GenTable>>> = await request.post(`${contextPath}/get-list`, query)
   return res.data
 }
 
-// 查询db数据库列表
-export async function listDbTable(query: GenTableQuery): Promise<Result<PageInfo<DbTableInfo>>> {
-  const res: AxiosResponse<Result<PageInfo<DbTableInfo>>> = await request.get(
-    `${contextPath}/db/list`,
-    { params: query }
-  )
+// 获取代码生成业务详情
+export async function getDetail(tableId: string): Promise<Result<GenTable>> {
+  const res: AxiosResponse<Result<GenTable>> = await request.get(`${contextPath}/get-detail?tableId=${tableId}`)
   return res.data
 }
 
-// 查询表详细信息
-export async function getGenTable(tableId: number): Promise<Result<GenTableInfo>> {
-  const res: AxiosResponse<Result<GenTableInfo>> = await request.get(
-    `${contextPath}/${tableId}`
-  )
+// 新增代码生成业务
+export async function insert(row: GenTable): Promise<Result<number>> {
+  const res: AxiosResponse<Result<number>> = await request.post(`${contextPath}/insert-genTable`, row)
   return res.data
 }
 
-// 修改代码生成信息
-export async function updateGenTable(data: GenTableInfo): Promise<Result<number>> {
-  console.log(data)
-  const res: AxiosResponse<Result<number>> = await request.put(
-    `${contextPath}`,
-    data
-  )
+// 更新代码生成业务
+export async function update(row: GenTable): Promise<Result<number>> {
+  const res: AxiosResponse<Result<number>> = await request.post(`${contextPath}/update-genTable`, row)
   return res.data
 }
 
-// 导入表
-export async function importTable(data: ImportTableParams): Promise<Result<number>> {
+// 删除代码生成业务
+export async function remove(genTables: string | string[]): Promise<Result<number>> {
+  // 统一转换为数组格式
+  const ids = Array.isArray(genTables) ? genTables : [genTables];
   const res: AxiosResponse<Result<number>> = await request.post(
-    `${contextPath}/importTable`,
-    null,
-    { params: data }
+    `${contextPath}/delete-genTable?ids`,ids
   )
   return res.data
 }
 
-// 创建表
-export async function createTable(data: CreateTableParams): Promise<Result<number>> {
-  const res: AxiosResponse<Result<number>> = await request.post(
-    `${contextPath}/createTable`,
-    null,
-    { params: data }
+// 查询db数据库列表
+export async function listDbTable(query: GenTableQuery): Promise<Result<PageInfo<GenTable>>> {
+  const res: AxiosResponse<Result<PageInfo<GenTable>>> = await request.post(
+    `${contextPath}/db-list`,
+    query
   )
   return res.data
 }
 
-// 预览生成代码
-export async function previewTable(tableId: number): Promise<Result<PreviewResult>> {
-  const res: AxiosResponse<Result<PreviewResult>> = await request.get(
-    `${contextPath}/preview/${tableId}`
+// 导入表
+export async function importTable(data: string): Promise<Result<number>> {
+  console.log(data);
+  const res: AxiosResponse<Result<number>> = await request.get(
+    `${contextPath}/importTable?tables=${data}`,
   )
   return res.data
 }
 
-// 删除表数据
-export async function delTable(tableId: number | number[]): Promise<Result<number>> {
-  const ids = Array.isArray(tableId) ? tableId.join(',') : tableId
-  const res: AxiosResponse<Result<number>> = await request.delete(
-    `${contextPath}/${ids}`
-  )
-  return res.data
-}
 
-// 生成代码(自定义路径)
-export async function genCode(tableName: string): Promise<Result<string>> {
-  const res: AxiosResponse<Result<string>> = await request.get(
-    `${contextPath}/genCode/${tableName}`
+// 预览生成代码
+export async function previewTable(tableId: string): Promise<Result<PreviewResult>> {
+  const res: AxiosResponse<Result<PreviewResult>> = await request.get(
+    `${contextPath}/preview-code?tableId=${tableId}`
   )
   return res.data
 }
@@ -131,7 +74,7 @@ export async function genCode(tableName: string): Promise<Result<string>> {
 // 同步数据库
 export async function synchDb(tableName: string): Promise<Result<number>> {
   const res: AxiosResponse<Result<number>> = await request.get(
-    `${contextPath}/synchDb/${tableName}`
+    `${contextPath}/synchDb-tableName?tableName=${tableName}`
   )
   return res.data
 }

+ 2 - 2
wxjy-wxjy-web/src/router/app-router.ts

@@ -33,7 +33,7 @@ const routers: Array<RouteRecordRaw> = [
   {
     path: '/gen-index',
     name: 'GenIndex',
-    component: () => import('@/views/gen/genIndex.vue'),
+    component: () => import('@/views/gen/GenTable.vue'),
     meta: {
       title: '代码生成'
     }
@@ -42,7 +42,7 @@ const routers: Array<RouteRecordRaw> = [
     path: '/gen-edit/:tableId', // 确保这个路由存在
     component: () => import('@/views/gen/editTable.vue'), // 确认组件路径正确
     name: 'GenEdit',
-    meta: { title: '编辑生成配置', activeMenu: '/gen/index' },
+    meta: { title: '编辑生成配置', activeMenu: '/gen/GenTable' },
   },
   {
     path: '/analyze-newDeclaredGoods',

+ 20 - 20
wxjy-wxjy-web/src/types/base/PackCatalog.ts

@@ -1,27 +1,27 @@
 // 包装种类目录
 export interface PackCatalog {
-                    ID?: string
-                    maxType?: string
-                    minTypeCode?: string
-                    minTypeName?: string
-                    requireInfo?: string
-                    maxL?: string
-                    maxKg?: string
-                    packStatus?: string
+  ID?: string
+  maxType?: string
+  minTypeCode?: string
+  minTypeName?: string
+  requireInfo?: string
+  maxL?: string
+  maxKg?: string
+  packStatus?: string
 }
 
 // 包装种类目录查询参数
 export interface PackCatalogQuery {
-                    ID?: string
-                    maxType?: string
-                    minTypeCode?: string
-                    minTypeName?: string
-                    requireInfo?: string
-                    maxL?: string
-                    maxKg?: string
-                    packStatus?: string
-    beginDate?: string
-    endDate?: string
-    pageIndex?: number
-    pageSize?: number
+  ID?: string
+  maxType?: string
+  minTypeCode?: string
+  minTypeName?: string
+  requireInfo?: string
+  maxL?: string
+  maxKg?: string
+  packStatus?: string
+  beginDate?: string
+  endDate?: string
+  pageIndex?: number
+  pageSize?: number
 }

+ 57 - 0
wxjy-wxjy-web/src/types/gen/GenTable.ts

@@ -0,0 +1,57 @@
+// 代码生成业务
+export interface GenTable {
+  tableId?: string
+  tableName?: string
+  tableComment?: string
+  subTableName?: string
+  subTableFkName?: string
+  className?: string
+  tplCategory?: string
+  packageName?: string
+  moduleName?: string
+  businessName?: string
+  functionName?: string
+  functionAuthor?: string
+  genType?: string
+  genPath?: string
+  options?: string
+  tplWebType?: string
+  [key: string]: any;
+}
+
+export interface DbTableInfo {
+  tableName: string
+  tableComment: string
+  createTime: string
+  updateTime: string
+}
+
+export interface GenTableQuery {
+  pageNum?: number
+  pageSize?: number
+  tableName?: string
+  tableComment?: string
+  beginTime?: string
+  endTime?: string
+}
+
+export interface ImportTableParams {
+  tables: string
+}
+
+export interface CreateTableParams {
+  tableName: string
+  tableComment: string
+  // 其他创建表需要的参数
+}
+
+export interface PreviewResult {
+  [key: string]: string
+}
+
+export interface SelectionItem {
+  tableName: string
+  tableComment: string
+  createTime: string
+  updateTime: string
+}

+ 46 - 0
wxjy-wxjy-web/src/types/gen/GenTableColumn.ts

@@ -0,0 +1,46 @@
+// 代码生成业务字段
+export interface GenTableColumn {
+  columnId?: string
+  tableId?: string
+  columnName?: string
+  columnComment?: string
+  columnType?: string
+  javaType?: string
+  javaField?: string
+  isPk?: string
+  isIncrement?: string
+  isRequired?: string
+  isInsert?: string
+  isEdit?: string
+  isList?: string
+  isQuery?: string
+  queryType?: string
+  htmlType?: string
+  dictType?: string
+  sort?: number
+}
+
+// 代码生成业务字段查询参数
+export interface GenTableColumnQuery {
+  tableId?: string
+  columnName?: string
+  columnComment?: string
+  columnType?: string
+  javaType?: string
+  javaField?: string
+  isPk?: string
+  isIncrement?: string
+  isRequired?: string
+  isInsert?: string
+  isEdit?: string
+  isList?: string
+  isQuery?: string
+  queryType?: string
+  htmlType?: string
+  dictType?: string
+  SORT?: string
+  beginDate?: string
+  endDate?: string
+  pageIndex?: number
+  pageSize?: number
+}

+ 655 - 0
wxjy-wxjy-web/src/views/gen/GenTable.vue

@@ -0,0 +1,655 @@
+<template>
+  <cacp-search-layout>
+    <template #search>
+      <cacp-search-panel-layout
+        :model="state.queryData"
+        ref="queryFormRef"
+        label-position="left"
+        label-width="auto"
+        :gutter="30"
+        :colSpan="6"
+      >
+        <el-form-item label="表名称" prop="tableName">
+          <el-input
+            v-model="state.queryData.tableName"
+            placeholder="请输入表名称"
+            clearable
+            @keyup.enter="onSearch"
+          />
+        </el-form-item>
+        <el-form-item label="表描述" prop="tableComment">
+          <el-input
+            v-model="state.queryData.tableComment"
+            placeholder="请输入表描述"
+            clearable
+            @keyup.enter="onSearch"
+          />
+        </el-form-item>
+        <el-form-item label="创建时间">
+          <el-date-picker
+            v-model="state.dateRange"
+            style="width: 100%"
+            value-format="YYYY-MM-DD"
+            type="daterange"
+            range-separator="-"
+            start-placeholder="开始日期"
+            end-placeholder="结束日期"
+            @change="onDateChange"
+          />
+        </el-form-item>
+        <template #buttonGroup>
+          <el-button type="primary" @click="onSearch">查询</el-button>
+          <el-button type="info" @click="onReset">重置</el-button>
+        </template>
+      </cacp-search-panel-layout>
+    </template>
+
+    <cacp-complex-table
+      :actions="actions"
+      :data="tableData"
+      :pagination="tablePagination"
+      @selection-change="handleSelectionChange"
+      @on-page-change="onPageChange"
+      @on-size-change="onSizeChange"
+      :loading="loading"
+    >
+      <el-table-column type="selection" align="center" width="55" />
+      <el-table-column label="序号" width="50" align="center">
+        <template #default="{ $index }">
+          <span>{{ (state.queryData.pageNum - 1) * state.queryData.pageSize + $index + 1 }}</span>
+        </template>
+      </el-table-column>
+      <el-table-column
+        label="表名称"
+        align="center"
+        prop="tableName"
+        :show-overflow-tooltip="true"
+      />
+      <el-table-column
+        label="实体"
+        align="center"
+        prop="className"
+        :show-overflow-tooltip="true"
+      />
+      <el-table-column
+        label="表描述"
+        align="center"
+        prop="tableComment"
+        :show-overflow-tooltip="true"
+        width="220"
+      />
+      <el-table-column
+        label="创建时间"
+        align="center"
+        prop="createTime"
+        width="160"
+      />
+      <el-table-column
+        label="更新时间"
+        align="center"
+        prop="updateTime"
+        width="160"
+      />
+<!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
+        <template #default="{ row }">
+          <el-button
+            type="text"
+            size="small"
+            @click="onPreview(row)"
+            v-has-permi="['tool:gen:preview']"
+          >
+            预览
+          </el-button>
+          <el-button
+            type="text"
+            size="small"
+            @click="onEditTable(row)"
+            v-has-permi="['tool:gen:edit']"
+          >
+            编辑
+          </el-button>
+          <el-button
+            type="text"
+            size="small"
+            @click="onDelete(row)"
+            v-has-permi="['tool:gen:remove']"
+          >
+            删除
+          </el-button>
+          <el-button
+            type="text"
+            size="small"
+            @click="onSynchDb(row)"
+            v-has-permi="['tool:gen:edit']"
+          >
+            同步
+          </el-button>
+          <el-button
+            type="text"
+            size="small"
+            @click="onGenTable(row)"
+          >
+            生成代码
+          </el-button>
+        </template>
+      </el-table-column>-->
+    </cacp-complex-table>
+
+    <!-- 代码预览对话框 -->
+    <el-dialog
+      :title="state.preview.title"
+      v-model="state.preview.open"
+      width="80%"
+      top="5vh"
+      append-to-body
+      class="scrollbar"
+      @closed="onPreviewClose"
+    >
+      <el-tabs v-model="state.preview.activeName" type="border-card">
+        <el-tab-pane
+          v-for="(value, key) in state.preview.data"
+          :label="getTabLabel(key)"
+          :name="getTabName(key)"
+          :key="key"
+        >
+          <template #label>
+            <span class="tab-label">{{ getTabLabel(key) }}</span>
+          </template>
+          <div class="code-header">
+            <el-tooltip content="复制代码" placement="top">
+              <el-button
+                @click="onCopy(value)"
+                size="small"
+                text
+              >
+                复制
+              </el-button>
+            </el-tooltip>
+          </div>
+          <div class="code-container">
+            <pre><code class="hljs" v-html="highlightedCode(value, key)"></code></pre>
+          </div>
+        </el-tab-pane>
+      </el-tabs>
+    </el-dialog>
+
+    <!-- 子组件 -->
+    <ImportTable ref="importRef" @ok="onSearch" />
+  </cacp-search-layout>
+</template>
+
+<script lang="ts" setup>
+import { onMounted, reactive, ref, computed, watch } from 'vue'
+import { useRoute, useRouter } from 'vue-router'
+import { ElMessage, ElMessageBox } from 'element-plus'
+import config from '@/config'
+import type { GenTable, GenTableQuery } from '@/types/gen/GenTable'
+
+import {
+  useComplexTable,
+  type SearchPanelLayoutInstance,
+  type TableAction,
+  useLoading, SuccessResultCode
+} from '@cacp/ui'
+
+import {
+  getList,
+  previewTable,
+  remove,
+  synchDb,
+  batchGenCode
+} from '@/apis/gen/gen'
+
+import ImportTable from './importTable.vue'
+import hljs from 'highlight.js/lib/core'
+import javascript from 'highlight.js/lib/languages/javascript'
+import xml from 'highlight.js/lib/languages/xml'
+import json from 'highlight.js/lib/languages/json'
+import sql from 'highlight.js/lib/languages/sql'
+import java from 'highlight.js/lib/languages/java'
+import css from 'highlight.js/lib/languages/css'
+
+// 注册语言
+hljs.registerLanguage('javascript', javascript)
+hljs.registerLanguage('xml', xml)
+hljs.registerLanguage('json', json)
+hljs.registerLanguage('sql', sql)
+hljs.registerLanguage('java', java)
+hljs.registerLanguage('css', css)
+
+// 路由
+const route = useRoute()
+const router = useRouter()
+
+// Refs
+const queryFormRef = ref<SearchPanelLayoutInstance>()
+const importRef = ref<InstanceType<typeof ImportTable>>()
+
+// 加载状态
+const { loading, setLoading } = useLoading()
+
+// 表格 Hook
+const tableHooks = useComplexTable<GenTable>(config)
+const { tableData, tablePagination, setPagination, setPageIndex, setPageSizes } = tableHooks
+
+// 响应式数据
+interface PreviewData {
+  open: boolean
+  title: string
+  data: Record<string, string>
+  activeName: string
+}
+
+interface State {
+  queryData: GenTableQuery & {
+    sort?: string
+    order?: string
+    beginTime?: string
+    endTime?: string
+    pageNum: number
+    pageSize: number
+    tableName?: string
+    tableComment?: string
+  }
+  preview: PreviewData
+  dateRange: string[]
+  selectedRows: GenTable[]
+}
+
+const state = reactive<State>({
+  queryData: {
+    pageNum: 1,
+    pageSize: 10,
+    tableName: undefined,
+    tableComment: undefined,
+    sort: undefined,
+    order: undefined
+  },
+  preview: {
+    open: false,
+    title: '代码预览',
+    data: {},
+    activeName: 'domain.java'
+  },
+  dateRange: [],
+  selectedRows: []
+})
+
+// 计算属性
+const ids = computed(() => state.selectedRows.map(item => item.tableId))
+const tableNames = computed(() => state.selectedRows.map(item => item.tableName))
+
+// 表格操作按钮配置
+const actions = <Array<TableAction>>[
+  {
+    key: 'gen',
+    text: '生成',
+    onclick: onGenTable,
+    limit: 'none',
+    type: 'primary',
+  },
+/*  {
+    key: 'create',
+    text: '创建',
+    onclick: onCreateTable,
+    limit: 'none',
+    type: 'primary',
+    plain: true,
+    icon: 'Plus'
+  },*/
+  {
+    key: 'import',
+    text: '导入',
+    onclick: onImportTable,
+    limit: 'none',
+    type: 'info',
+  },
+  {
+    key: 'preview',
+    text: '预览',
+    onclick: onPreview,
+    limit:'one',
+    // limit: permissionStatus('one', 'ANALYZE_NEWDECLAREDGOODS_EDIT_BT'),
+    type: 'primary'
+  },
+  {
+    key: 'edit',
+    text: '修改',
+    onclick: onEditTable,
+    limit: 'one',
+    type: 'success',
+  },
+  {
+    key: 'delete',
+    text: '删除',
+    onclick: onDelete,
+    limit: 'one',
+    type: 'danger',
+  },
+  {
+    key: 'synchDb',
+    text: '同步',
+    onclick: onSynchDb,
+    limit: 'one',
+    type: 'success',
+  },
+  {
+    key: 'genOne',
+    text: '生成',
+    onclick: onGenTable,
+    limit: 'one',
+    type: 'primary',
+  },
+]
+
+// 搜索方法
+const onSearch = () => {
+  setPageIndex(1)
+  onLoadData()
+}
+
+// 重置方法
+const onReset = () => {
+  queryFormRef.value?.resetFields()
+  state.dateRange = []
+  state.queryData.sort = undefined
+  state.queryData.order = undefined
+  onPageChange(1)
+}
+
+// 日期范围变化
+const onDateChange = (value: string[]) => {
+  state.dateRange = value
+}
+
+// 每页显示条数变化
+const onSizeChange = (size: number) => {
+  setPageSizes(size)
+  onLoadData()
+}
+
+// 翻页查询
+const onPageChange = (currentPage: number) => {
+  setPageIndex(currentPage)
+  onLoadData()
+}
+
+// 多选框选中数据
+function handleSelectionChange(selection: GenTable[]) {
+  state.selectedRows = selection
+}
+
+// 生成代码操作
+async function onGenTable(row?: GenTable) {
+  const targetTableNames = row?.tableName || tableNames.value.join(',')
+
+  if (!targetTableNames) {
+    ElMessage.error('请选择要生成的数据')
+    return
+  }
+
+  try {
+    setLoading(true)
+    const response = await batchGenCode(targetTableNames)
+
+    if (response.data instanceof Blob && response.data.size > 0) {
+      const url = window.URL.createObjectURL(response.data)
+      const link = document.createElement('a')
+      link.href = url
+      link.download = targetTableNames.includes(',') ? 'codes.zip' : `${targetTableNames}.zip`
+      document.body.appendChild(link)
+      link.click()
+      document.body.removeChild(link)
+      window.URL.revokeObjectURL(url)
+      ElMessage.success('代码生成成功')
+    } else {
+      throw new Error('响应不是有效的文件数据')
+    }
+  } catch (error: any) {
+    console.error('生成代码失败:', error)
+    ElMessage.error('生成代码失败: ' + (error.message || '未知错误'))
+  } finally {
+    setLoading(false)
+  }
+}
+
+// 同步数据库操作
+async function onSynchDb(row: GenTable) {
+  try {
+    await ElMessageBox.confirm(
+      `确认要强制同步"${row.tableName}"表结构吗?`,
+      '系统提示',
+      {
+        type: 'warning',
+        confirmButtonText: '确定',
+        cancelButtonText: '取消'
+      }
+    )
+
+    const res = await synchDb(row.tableName)
+    if (res.code === SuccessResultCode) {
+      ElMessage.success('同步成功')
+      onLoadData()
+    } else {
+      ElMessage.error(res.message || '同步失败')
+    }
+  } catch (error) {
+    console.error('操作失败:', error)
+    ElMessage.error('同步失败')
+  }
+}
+
+// 打开导入表弹窗
+function onImportTable() {
+  importRef.value?.show()
+}
+
+// 预览按钮
+async function onPreview(row: GenTable) {
+  try {
+    const res = await previewTable(row.tableId)
+    if (res.code === SuccessResultCode) {
+      state.preview.data = res.data
+      state.preview.open = true
+      state.preview.activeName = Object.keys(res.data)[0]?.split('/').pop()?.split('.vm')[0] || 'domain.java'
+    } else {
+      ElMessage.error(res.message || '预览失败')
+    }
+  } catch (error) {
+    ElMessage.error('预览失败')
+    console.error('预览失败:', error)
+  }
+}
+
+// 关闭预览
+function onPreviewClose() {
+  state.preview.data = {}
+  state.preview.activeName = 'domain.java'
+}
+
+// 获取标签页名称
+function getTabName(key: string) {
+  const lastSlashIndex = key.lastIndexOf('/')
+  const vmIndex = key.indexOf('.vm')
+  return key.substring(lastSlashIndex + 1, vmIndex)
+}
+
+// 获取标签页显示标签
+function getTabLabel(key: string) {
+  return getTabName(key)
+}
+
+// 高亮显示代码
+function highlightedCode(code: string, key: string) {
+  const vmName = getTabName(key)
+  const language = vmName.substring(vmName.lastIndexOf('.') + 1)
+
+  try {
+    const result = hljs.highlight(code || '', {
+      language: getLanguageAlias(language)
+    })
+    return result.value || '&nbsp;'
+  } catch (error) {
+    console.error( error)
+    return code || '&nbsp;'
+  }
+}
+
+// 获取语言别名
+function getLanguageAlias(language: string): string {
+  const aliases: Record<string, string> = {
+    'java': 'java',
+    'xml': 'xml',
+    'html': 'xml',
+    'js': 'javascript',
+    'javascript': 'javascript',
+    'json': 'json',
+    'sql': 'sql',
+    'css': 'css',
+    'vue': 'xml'
+  }
+  return aliases[language] || 'plaintext'
+}
+
+// 复制代码
+async function onCopy(code: string) {
+  try {
+    await navigator.clipboard.writeText(code)
+    ElMessage.success('复制成功')
+  } catch (error) {
+    console.error('复制失败:', error)
+    ElMessage.error('复制失败')
+  }
+}
+
+// 修改按钮操作
+function onEditTable(row?: GenTable) {
+  const tableId = row?.tableId || ids.value[0]
+  const tableName = row?.tableName || tableNames.value[0]
+
+  router.push({
+    name: 'GenEdit',
+    params: { tableId },
+    query: {
+      pageNum: state.queryData.pageNum.toString(),
+      tableName
+    }
+  })
+}
+
+// 删除按钮操作
+async function onDelete(row?: GenTable) {
+  const tableIds = row?.tableId || ids.value
+
+  try {
+    await ElMessageBox.confirm(
+      `是否确认删除表编号为"${Array.isArray(tableIds) ? tableIds.join(',') : tableIds}"的数据项?`,
+      '系统提示',
+      {
+        type: 'warning',
+        confirmButtonText: '确定',
+        cancelButtonText: '取消'
+      }
+    )
+
+    const res = await remove(tableIds)
+    if (res.code === SuccessResultCode) {
+      ElMessage.success('删除成功')
+      onLoadData()
+    } else {
+      ElMessage.error(res.message || '删除失败')
+    }
+  } catch (error) {
+    // 用户取消操作
+    console.log(error)
+  }
+}
+
+// 数据查询
+async function onLoadData() {
+  setLoading(true)
+  try {
+    const query = {
+      ...state.queryData,
+      pageIndex: tablePagination.currentPage,
+      pageSize: tablePagination.pageSize
+    }
+    const res = await getList(query)
+
+    if (res.code === SuccessResultCode) {
+      setPagination(res.data)
+    } else {
+      ElMessage.error(res.message || '获取数据失败')
+    }
+  } catch (error) {
+    ElMessage.error('网络错误,请稍后重试')
+    console.error('获取表列表失败:', error)
+  } finally {
+    setLoading(false)
+  }
+}
+
+// 监听路由变化
+watch(
+  () => route.query,
+  (newQuery) => {
+    const time = newQuery.t as string
+    if (time) {
+      state.queryData.pageNum = Number(newQuery.pageNum) || 1
+      onLoadData()
+    }
+  },
+  { immediate: true }
+)
+
+// 组件挂载时加载数据
+onMounted(() => {
+  onLoadData()
+})
+</script>
+
+<style scoped>
+.scrollbar {
+  max-height: 70vh;
+  overflow-y: auto;
+}
+
+.code-header {
+  display: flex;
+  justify-content: flex-end;
+  padding: 8px 0;
+  border-bottom: 1px solid #e8e8e8;
+  margin-bottom: 12px;
+}
+
+.code-container {
+  background: #f8f9fa;
+  border-radius: 4px;
+  padding: 16px;
+  overflow-x: auto;
+}
+
+.hljs {
+  background: transparent !important;
+  padding: 0 !important;
+  font-family: 'JetBrains Mono', 'Fira Code', Consolas, 'Courier New', monospace;
+  font-size: 14px;
+  line-height: 1.5;
+}
+
+.tab-label {
+  font-weight: 500;
+}
+
+:deep(.el-table .small-padding) {
+  padding: 8px 0;
+}
+
+:deep(.el-tabs__content) {
+  position: relative;
+}
+
+:deep(.el-tabs--border-card > .el-tabs__content) {
+  padding: 16px;
+}
+</style>

+ 129 - 49
wxjy-wxjy-web/src/views/gen/basicInfoForm.vue

@@ -1,37 +1,66 @@
 <template>
-  <el-form ref="basicInfoFormRef" :model="info" :rules="rules" label-width="150px">
-    <el-row>
-      <el-col :span="12">
-        <el-form-item label="表名称" prop="tableName">
-          <el-input placeholder="请输入仓库名称" v-model="info.tableName" />
-        </el-form-item>
-      </el-col>
-      <el-col :span="12">
-        <el-form-item label="表描述" prop="tableComment">
-          <el-input placeholder="请输入" v-model="info.tableComment" />
-        </el-form-item>
-      </el-col>
-      <el-col :span="12">
-        <el-form-item label="实体类名称" prop="className">
-          <el-input placeholder="请输入" v-model="info.className" />
-        </el-form-item>
-      </el-col>
-      <el-col :span="12">
-        <el-form-item label="作者" prop="functionAuthor">
-          <el-input placeholder="请输入" v-model="info.functionAuthor" />
-        </el-form-item>
-      </el-col>
-      <el-col :span="24">
-        <el-form-item label="备注" prop="remark">
-          <el-input type="textarea" :rows="3" v-model="info.remark"></el-input>
-        </el-form-item>
-      </el-col>
-    </el-row>
-  </el-form>
+  <cacp-form-layout>
+    <el-form
+      ref="basicInfoFormRef"
+      :model="state.formData"
+      :rules="state.rules"
+      label-width="150px"
+      label-position="right"
+    >
+      <el-row :gutter="20">
+        <el-col :span="12">
+          <el-form-item label="表名称" prop="tableName">
+            <el-input
+              v-model="state.formData.tableName"
+              placeholder="请输入表名称"
+              clearable
+            />
+          </el-form-item>
+        </el-col>
+        <el-col :span="12">
+          <el-form-item label="表描述" prop="tableComment">
+            <el-input
+              v-model="state.formData.tableComment"
+              placeholder="请输入表描述"
+              clearable
+            />
+          </el-form-item>
+        </el-col>
+        <el-col :span="12">
+          <el-form-item label="实体类名称" prop="className">
+            <el-input
+              v-model="state.formData.className"
+              placeholder="请输入实体类名称"
+              clearable
+            />
+          </el-form-item>
+        </el-col>
+        <el-col :span="12">
+          <el-form-item label="作者" prop="functionAuthor">
+            <el-input
+              v-model="state.formData.functionAuthor"
+              placeholder="请输入作者"
+              clearable
+            />
+          </el-form-item>
+        </el-col>
+        <el-col :span="24">
+          <el-form-item label="备注" prop="remark">
+            <el-input
+              v-model="state.formData.remark"
+              type="textarea"
+              :rows="3"
+              placeholder="请输入备注"
+            />
+          </el-form-item>
+        </el-col>
+      </el-row>
+    </el-form>
+  </cacp-form-layout>
 </template>
 
-<script setup lang="ts">
-import { ref, reactive, defineProps, defineExpose } from 'vue'
+<script lang="ts" setup>
+import { reactive, ref, watch } from 'vue'
 import type { FormInstance, FormRules } from 'element-plus'
 
 // 定义类型
@@ -44,31 +73,82 @@ interface TableInfo {
 }
 
 // Props
-const props = defineProps<{
+interface Props {
   info: TableInfo
-}>()
+}
+
+const props = defineProps<Props>()
 
 // Refs
 const basicInfoFormRef = ref<FormInstance>()
 
-// 表单验证规则
-const rules = reactive<FormRules>({
-  tableName: [
-    { required: true, message: "请输入表名称", trigger: "blur" }
-  ],
-  tableComment: [
-    { required: true, message: "请输入表描述", trigger: "blur" }
-  ],
-  className: [
-    { required: true, message: "请输入实体类名称", trigger: "blur" }
-  ],
-  functionAuthor: [
-    { required: true, message: "请输入作者", trigger: "blur" }
-  ]
+// 响应式状态
+interface State {
+  formData: TableInfo
+  rules: FormRules
+}
+
+const state = reactive<State>({
+  formData: {
+    tableName: '',
+    tableComment: '',
+    className: '',
+    functionAuthor: '',
+    remark: ''
+  },
+  rules: {
+    tableName: [
+      { required: true, message: '请输入表名称', trigger: 'blur' }
+    ],
+    tableComment: [
+      { required: true, message: '请输入表描述', trigger: 'blur' }
+    ],
+    className: [
+      { required: true, message: '请输入实体类名称', trigger: 'blur' }
+    ],
+    functionAuthor: [
+      { required: true, message: '请输入作者', trigger: 'blur' }
+    ]
+  }
 })
 
-// 暴露方法给父组件
+// 监听 props 变化,更新表单数据
+watch(
+  () => props.info,
+  (newInfo) => {
+    if (newInfo) {
+      state.formData = {
+        tableName: newInfo.tableName || '',
+        tableComment: newInfo.tableComment || '',
+        className: newInfo.className || '',
+        functionAuthor: newInfo.functionAuthor || '',
+        remark: newInfo.remark || ''
+      }
+    }
+  },
+  { immediate: true, deep: true }
+)
+
+const validate = () => {
+  return new Promise((resolve, reject) => {
+    if (!basicInfoFormRef.value) {
+      reject(new Error('表单未初始化'))
+      return
+    }
+
+    basicInfoFormRef.value.validate((valid) => {
+      if (valid) {
+        resolve(state.formData)
+      } else {
+        reject(new Error('表单验证失败'))
+      }
+    })
+  })
+}
+
+// 更新 expose
 defineExpose({
-  getFormRef: () => basicInfoFormRef.value
+  getFormRef: () => basicInfoFormRef.value,
+  validate  // 暴露 validate 方法
 })
 </script>

+ 0 - 70
wxjy-wxjy-web/src/views/gen/createTable.vue

@@ -1,70 +0,0 @@
-<template>
-  <!-- 创建表 -->
-  <el-dialog
-    title="创建表"
-    v-model="visible"
-    width="800px"
-    top="5vh"
-    append-to-body
-  >
-    <span>创建表语句(支持多个建表语句):</span>
-    <el-input
-      type="textarea"
-      :rows="10"
-      placeholder="请输入文本"
-      v-model="content"
-    />
-    <template #footer>
-      <div class="dialog-footer">
-        <el-button type="primary" @click="handleCreateTable">确 定</el-button>
-        <el-button @click="visible = false">取 消</el-button>
-      </div>
-    </template>
-  </el-dialog>
-</template>
-
-<script setup lang="ts">
-import { ref } from 'vue'
-import { ElMessage } from 'element-plus'
-import { createTable } from "@/apis/gen/gen"
-
-// 定义props和emits
-interface Emits {
-  (e: 'ok'): void
-}
-
-const emit = defineEmits<Emits>()
-
-// 响应式数据
-const visible = ref(false)
-const content = ref('')
-
-// 方法
-const show = () => {
-  visible.value = true
-}
-
-/** 创建按钮操作 */
-const handleCreateTable = async () => {
-  if (content.value === "") {
-    ElMessage.error("请输入建表语句")
-    return
-  }
-
-  try {
-    const res = await createTable({ sql: content.value })
-    ElMessage.success(res.msg)
-    if (res.code === 200) {
-      visible.value = false
-      emit('ok')
-    }
-  } catch (error) {
-    console.error('创建表失败:', error)
-  }
-}
-
-// 暴露方法给父组件
-defineExpose({
-  show
-})
-</script>

+ 377 - 313
wxjy-wxjy-web/src/views/gen/editTable.vue

@@ -1,214 +1,259 @@
 <template>
-  <el-card>
-    <el-tabs v-model="activeName">
-      <el-tab-pane label="基本信息" name="basic">
-        <basic-info-form ref="basicInfoRef" :info="info" />
-      </el-tab-pane>
-      <el-tab-pane label="字段信息" name="columnInfo">
-        <el-table
-          ref="dragTableRef"
-          :data="columns"
-          row-key="columnId"
-          :max-height="tableHeight"
-        >
-          <el-table-column
-            label="序号"
-            type="index"
-            min-width="5%"
-            class-name="allowDrag"
-          />
-          <el-table-column
-            label="字段列名"
-            prop="columnName"
-            min-width="10%"
-            :show-overflow-tooltip="true"
-          />
-          <el-table-column label="字段描述" min-width="10%">
-            <template #default="scope">
-              <el-input v-model="scope.row.columnComment"></el-input>
-            </template>
-          </el-table-column>
-          <el-table-column
-            label="物理类型"
-            prop="columnType"
-            min-width="10%"
-            :show-overflow-tooltip="true"
-          />
-          <el-table-column label="Java类型" min-width="11%">
-            <template #default="scope">
-              <el-select v-model="scope.row.javaType">
-                <el-option label="Long" value="Long" />
-                <el-option label="String" value="String" />
-                <el-option label="Integer" value="Integer" />
-                <el-option label="Double" value="Double" />
-                <el-option label="BigDecimal" value="BigDecimal" />
-                <el-option label="Date" value="Date" />
-                <el-option label="Boolean" value="Boolean" />
-              </el-select>
-            </template>
-          </el-table-column>
-          <el-table-column label="java属性" min-width="10%">
-            <template #default="scope">
-              <el-input v-model="scope.row.javaField"></el-input>
-            </template>
-          </el-table-column>
-
-          <el-table-column label="插入" min-width="5%">
-            <template #default="scope">
-              <el-checkbox
-                true-label="1"
-                false-label="0"
-                v-model="scope.row.isInsert"
-              />
-            </template>
-          </el-table-column>
-          <el-table-column label="编辑" min-width="5%">
-            <template #default="scope">
-              <el-checkbox
-                true-label="1"
-                false-label="0"
-                v-model="scope.row.isEdit"
-              />
-            </template>
-          </el-table-column>
-          <el-table-column label="列表" min-width="5%">
-            <template #default="scope">
-              <el-checkbox
-                true-label="1"
-                false-label="0"
-                v-model="scope.row.isList"
-              />
-            </template>
-          </el-table-column>
-          <el-table-column label="查询" min-width="5%">
-            <template #default="scope">
-              <el-checkbox
-                true-label="1"
-                false-label="0"
-                v-model="scope.row.isQuery"
-              />
-            </template>
-          </el-table-column>
-          <el-table-column label="查询方式" min-width="10%">
-            <template #default="scope">
-              <el-select v-model="scope.row.queryType">
-                <el-option label="=" value="EQ" />
-                <el-option label="!=" value="NE" />
-                <el-option label=">" value="GT" />
-                <el-option label=">=" value="GTE" />
-                <el-option label="<" value="LT" />
-                <el-option label="<=" value="LTE" />
-                <el-option label="LIKE" value="LIKE" />
-                <el-option label="BETWEEN" value="BETWEEN" />
-              </el-select>
-            </template>
-          </el-table-column>
-          <el-table-column label="必填" min-width="5%">
-            <template #default="scope">
-              <el-checkbox
-                true-label="1"
-                false-label="0"
-                v-model="scope.row.isRequired"
-              />
-            </template>
-          </el-table-column>
-          <el-table-column label="显示类型" min-width="12%">
-            <template #default="scope">
-              <el-select v-model="scope.row.htmlType">
-                <el-option label="文本框" value="input" />
-                <el-option label="文本域" value="textarea" />
-                <el-option label="下拉框" value="select" />
-                <el-option label="单选框" value="radio" />
-                <el-option label="复选框" value="checkbox" />
-                <el-option label="日期控件" value="datetime" />
-                <el-option label="图片上传" value="imageUpload" />
-                <el-option label="文件上传" value="fileUpload" />
-                <el-option label="富文本控件" value="editor" />
-              </el-select>
-            </template>
-          </el-table-column>
-          <el-table-column label="字典类型" min-width="12%">
-            <template #default="scope">
-              <el-select
-                v-model="scope.row.dictType"
-                clearable
-                filterable
-                placeholder="请选择"
-              >
-                <el-option
-                  v-for="dict in dictOptions"
-                  :key="dict.dictType"
-                  :label="dict.dictName"
-                  :value="dict.dictType"
+  <cacp-page-layout>
+    <el-card>
+      <el-tabs v-model="state.activeName" type="border-card">
+        <el-tab-pane label="基本信息" name="basic">
+          <basic-info-form ref="basicInfoRef" :info="state.info" />
+        </el-tab-pane>
+        <el-tab-pane label="字段信息" name="columnInfo">
+          <el-table
+            ref="dragTableRef"
+            :data="state.columns"
+            row-key="columnId"
+            :height="state.tableHeight"
+            border
+            stripe
+          >
+            <el-table-column
+              label="序号"
+              type="index"
+              width="55"
+              align="center"
+              class-name="allowDrag"
+            />
+            <el-table-column
+              label="字段列名"
+              prop="columnName"
+              min-width="120"
+              :show-overflow-tooltip="true"
+              align="center"
+            />
+            <el-table-column label="字段描述" min-width="120" align="center">
+              <template #default="scope">
+                <el-input
+                  v-model="scope.row.columnComment"
+                  placeholder="请输入字段描述"
+                  clearable
+                />
+              </template>
+            </el-table-column>
+            <el-table-column
+              label="物理类型"
+              prop="columnType"
+              min-width="120"
+              :show-overflow-tooltip="true"
+              align="center"
+            />
+            <el-table-column label="Java类型" min-width="130" align="center">
+              <template #default="scope">
+                <el-select
+                  v-model="scope.row.javaType"
+                  placeholder="请选择"
+                  style="width: 100%"
+                >
+                  <el-option label="Long" value="Long" />
+                  <el-option label="String" value="String" />
+                  <el-option label="Integer" value="Integer" />
+                  <el-option label="Double" value="Double" />
+                  <el-option label="BigDecimal" value="BigDecimal" />
+                  <el-option label="Date" value="Date" />
+                  <el-option label="Boolean" value="Boolean" />
+                </el-select>
+              </template>
+            </el-table-column>
+            <el-table-column label="java属性" min-width="120" align="center">
+              <template #default="scope">
+                <el-input
+                  v-model="scope.row.javaField"
+                  placeholder="请输入java属性"
+                  clearable
+                  @blur="handleJavaFieldBlur(scope.row)"
+                />
+              </template>
+            </el-table-column>
+
+            <el-table-column label="插入" width="70" align="center">
+              <template #default="scope">
+                <el-checkbox
+                  v-model="scope.row.isInsert"
+                  true-label="1"
+                  false-label="0"
+                />
+              </template>
+            </el-table-column>
+            <el-table-column label="编辑" width="70" align="center">
+              <template #default="scope">
+                <el-checkbox
+                  v-model="scope.row.isEdit"
+                  true-label="1"
+                  false-label="0"
+                />
+              </template>
+            </el-table-column>
+            <el-table-column label="列表" width="70" align="center">
+              <template #default="scope">
+                <el-checkbox
+                  v-model="scope.row.isList"
+                  true-label="1"
+                  false-label="0"
+                />
+              </template>
+            </el-table-column>
+            <el-table-column label="查询" width="70" align="center">
+              <template #default="scope">
+                <el-checkbox
+                  v-model="scope.row.isQuery"
+                  true-label="1"
+                  false-label="0"
+                />
+              </template>
+            </el-table-column>
+            <el-table-column label="查询方式" min-width="120" align="center">
+              <template #default="scope">
+                <el-select
+                  v-model="scope.row.queryType"
+                  placeholder="请选择"
+                  style="width: 100%"
+                >
+                  <el-option label="=" value="EQ" />
+                  <el-option label="!=" value="NE" />
+                  <el-option label=">" value="GT" />
+                  <el-option label=">=" value="GTE" />
+                  <el-option label="<" value="LT" />
+                  <el-option label="<=" value="LTE" />
+                  <el-option label="LIKE" value="LIKE" />
+                  <el-option label="BETWEEN" value="BETWEEN" />
+                </el-select>
+              </template>
+            </el-table-column>
+            <el-table-column label="必填" width="70" align="center">
+              <template #default="scope">
+                <el-checkbox
+                  v-model="scope.row.isRequired"
+                  true-label="1"
+                  false-label="0"
+                />
+              </template>
+            </el-table-column>
+            <el-table-column label="显示类型" min-width="140" align="center">
+              <template #default="scope">
+                <el-select
+                  v-model="scope.row.htmlType"
+                  placeholder="请选择"
+                  style="width: 100%"
                 >
-                  <span style="float: left">{{ dict.dictName }}</span>
-                  <span style="float: right; color: #8492a6; font-size: 13px">
-                    {{ dict.dictType }}
-                  </span>
-                </el-option>
-              </el-select>
-            </template>
-          </el-table-column>
-        </el-table>
-      </el-tab-pane>
-      <el-tab-pane label="生成信息" name="genInfo">
-        <gen-info-form
-          ref="genInfoRef"
-          :info="info"
-          :tables="tables"
-          :menus="menus"
-        />
-      </el-tab-pane>
-    </el-tabs>
-    <el-form label-width="100px">
-      <el-form-item
-        style="text-align: center;margin-left:-100px;margin-top:10px;"
-      >
-        <el-button type="primary" @click="submitForm()">提交</el-button>
-        <el-button @click="close()">返回</el-button>
-      </el-form-item>
-    </el-form>
-  </el-card>
+                  <el-option label="文本框" value="input" />
+                  <el-option label="文本域" value="textarea" />
+                  <el-option label="下拉框" value="select" />
+                  <el-option label="单选框" value="radio" />
+                  <el-option label="复选框" value="checkbox" />
+                  <el-option label="日期控件" value="datetime" />
+                  <el-option label="图片上传" value="imageUpload" />
+                  <el-option label="文件上传" value="fileUpload" />
+                  <el-option label="富文本控件" value="editor" />
+                </el-select>
+              </template>
+            </el-table-column>
+            <el-table-column label="字典类型" min-width="140" align="center">
+              <template #default="scope">
+                <el-select
+                  v-model="scope.row.dictType"
+                  placeholder="请选择字典类型"
+                  clearable
+                  filterable
+                  style="width: 100%"
+                >
+                  <el-option
+                    v-for="dict in state.dictOptions"
+                    :key="dict.dictType"
+                    :label="dict.dictName"
+                    :value="dict.dictType"
+                  >
+                    <span style="float: left">{{ dict.dictName }}</span>
+                    <span style="float: right; color: #8492a6; font-size: 13px">
+                      {{ dict.dictType }}
+                    </span>
+                  </el-option>
+                </el-select>
+              </template>
+            </el-table-column>
+          </el-table>
+        </el-tab-pane>
+        <el-tab-pane label="生成信息" name="genInfo">
+          <gen-info-form
+            ref="genInfoRef"
+            :info="state.info"
+            :tables="state.tables"
+            :menus="state.menus"
+          />
+        </el-tab-pane>
+      </el-tabs>
+
+      <div class="footer-action">
+        <el-button type="primary" @click="onSubmit">提交</el-button>
+        <el-button @click="onCancel">返回</el-button>
+      </div>
+    </el-card>
+  </cacp-page-layout>
 </template>
 
-<script setup lang="ts">
-import { ref, onMounted, nextTick } from 'vue'
+<script lang="ts" setup>
+import { reactive, ref, onMounted, nextTick } from 'vue'
 import { useRoute, useRouter } from 'vue-router'
-import { ElMessage, ElMessageBox } from 'element-plus'
+import { ElMessage } from 'element-plus'
 import Sortable from 'sortablejs'
-
-import { getGenTable, updateGenTable } from "@/apis/gen/gen"
+import type { GenTable } from '@/types/gen/GenTable'
+import type { GenTableColumn } from '@/types/gen/GenTableColumn'
+import { getDetail, update } from "@/apis/gen/gen"
 // import { optionselect as getDictOptionselect } from "@/api/system/dict/type"
 // import { listMenu as getMenuTreeselect } from "@/api/system/menu"
 import basicInfoForm from "./basicInfoForm.vue"
 import genInfoForm from "./genInfoForm.vue"
+import { SuccessResultCode } from '@cacp/ui'
 
-// 定义类型
-interface DictOption {
-  dictType: string
-  dictName: string
+// 组件引用
+const basicInfoRef = ref<InstanceType<typeof basicInfoForm>>()
+const genInfoRef = ref<InstanceType<typeof genInfoForm>>()
+const dragTableRef = ref()
+
+// 路由
+const route = useRoute()
+const router = useRouter()
+
+// 工具函数:检查是否为驼峰命名
+const isCamelCase = (str: string): boolean => {
+  if (!str) return false
+  // 驼峰命名规则:以小写字母开头,后续可以包含大写字母
+  return /^[a-z]+([A-Z][a-z]*)*$/.test(str)
 }
 
-interface Column {
-  columnId: number
-  columnName: string
-  columnComment: string
-  columnType: string
-  javaType: string
-  javaField: string
-  isInsert: string
-  isEdit: string
-  isList: string
-  isQuery: string
-  queryType: string
-  isRequired: string
-  htmlType: string
-  dictType: string
-  sort?: number
+// 工具函数:格式化java属性
+const formatJavaField = (field: string = ''): string => {
+  if (!field) return ''
+
+  // 如果是驼峰命名,保持原样
+  if (isCamelCase(field)) {
+    return field
+  }
+
+  // 其他情况全部转为小写
+  return field.toLowerCase()
 }
 
-interface TableInfo {
-  [key: string]: any
+// 处理java属性输入框失去焦点事件 - 明确指定参数类型
+const handleJavaFieldBlur = (column: GenTableColumn) => {
+  if (column.javaField) {
+    const formatted = formatJavaField(column.javaField)
+    if (column.javaField !== formatted) {
+      column.javaField = formatted
+    }
+  }
+}
+
+// 响应式状态
+interface DictOption {
+  dictType: string
+  dictName: string
 }
 
 interface Menu {
@@ -216,136 +261,113 @@ interface Menu {
   [key: string]: any
 }
 
-// 响应式数据
-const activeName = ref('columnInfo')
-const tableHeight = ref(`${document.documentElement.scrollHeight - 245}px`)
-const tables = ref<TableInfo[]>([])
-const columns = ref<Column[]>([])
-const dictOptions = ref<DictOption[]>([])
-const menus = ref<Menu[]>([])
-const info = ref<TableInfo>({})
-
-// 模板引用
-const basicInfoRef = ref<InstanceType<typeof basicInfoForm> | null>(null)
-const genInfoRef = ref<InstanceType<typeof genInfoForm> | null>(null)
-const dragTableRef = ref()
-
-// 路由
-const route = useRoute()
-const router = useRouter()
-
-// 方法
-const handleTree = (data: any[], idKey: string) => {
-  // 这里需要实现树形数据处理逻辑,根据原项目中的实现
-  // 这里仅作示例,您需要根据实际实现调整
-  return data
+interface State {
+  activeName: string
+  tableHeight: string
+  info: Partial<GenTable>
+  columns: GenTableColumn[]
+  tables: any[]
+  dictOptions: DictOption[]
+  menus: Menu[]
 }
 
-const submitForm = async () => {
-  if (!basicInfoRef.value || !genInfoRef.value) {
-    ElMessage.error('表单组件未正确加载')
-    return
-  }
+const state = reactive<State>({
+  activeName: 'columnInfo',
+  tableHeight: `${document.documentElement.scrollHeight - 300}px`,
+  info: {},
+  columns: [],
+  tables: [],
+  dictOptions: [],
+  menus: []
+})
 
+// 修改 onSubmit 方法
+const onSubmit = async () => {
   try {
-    const basicForm = basicInfoRef.value.getFormRef()
-    const genForm = genInfoRef.value.getFormRef()
-
-    console.log('基础表单引用:', basicForm)
-    console.log('生成信息表单引用:', genForm)
-
-    if (!basicForm || !genForm) {
-      ElMessage.error('表单引用获取失败')
+    if (!basicInfoRef.value || !genInfoRef.value) {
+      ElMessage.error('表单组件未正确加载')
       return
     }
 
-    // 分别验证表单
-    let basicValid = false
-    let genValid = false
+    // 直接从子组件获取最新的表单数据
+    let basicInfoData = {}
+    let genInfoData = {}
 
     try {
-      basicValid = await basicForm.validate()
-      console.log('基础表单验证通过')
-    } catch (basicError) {
-      console.error('基础表单验证失败:', basicError)
+      basicInfoData = await basicInfoRef.value.validate?.()
+    } catch (error) {
+      console.error('基础表单验证失败:', error)
       ElMessage.error('基本信息表单验证失败,请检查必填项')
-      activeName.value = 'basic'
+      state.activeName = 'basic'
       return
     }
 
     try {
-      genValid = await genForm.validate()
-      console.log('生成信息表单验证通过')
-    } catch (genError) {
-      console.error('生成信息表单验证失败:', genError)
+      genInfoData = await genInfoRef.value.validate?.()
+    } catch (error) {
+      console.error('生成信息表单验证失败:', error)
       ElMessage.error('生成信息表单验证失败,请检查必填项')
-      activeName.value = 'genInfo'
+      state.activeName = 'genInfo'
       return
     }
 
-    if (basicValid && genValid) {
-      // 详细检查所有必填字段
-      console.log('提交前的完整 info 数据:', JSON.stringify(info.value, null, 2))
-
-      const requiredFields = [
-        'packageName', 'tableName', 'functionName', 'functionAuthor',
-        'businessName', 'moduleName', 'className', 'tableComment'
-      ]
-
-      // 检查每个字段的具体值
-      requiredFields.forEach(field => {
-        console.log(`${field}:`, info.value[field], '类型:', typeof info.value[field])
-      })
-
-      const missingFields = requiredFields.filter(field => !info.value[field])
-      if (missingFields.length > 0) {
-        ElMessage.error(`以下字段不能为空: ${missingFields.join(', ')}`)
-        activeName.value = 'basic'
-        return
-      }
+    // 合并所有数据
+    const mergedInfo: { [key: string]: any }  = {
+      ...state.info,
+      ...basicInfoData,
+      ...genInfoData
+    }
 
+    // 检查必填字段
+    const requiredFields = [
+      'packageName', 'tableName', 'functionName', 'functionAuthor',
+      'businessName', 'moduleName', 'className', 'tableComment'
+    ]
+
+    const missingFields = requiredFields.filter(field => !mergedInfo[field])
+    if (missingFields.length > 0) {
+      ElMessage.error(`以下字段不能为空: ${missingFields.join(', ')}`)
+      state.activeName = 'basic'
+      return
+    }
 
-      const genTable = {
-        ...info.value,
-        columns: columns.value,
-        params: {
-          treeCode: info.value.treeCode || '',
-          treeName: info.value.treeName || '',
-          treeParentCode: info.value.treeParentCode || '',
-          parentMenuId: info.value.parentMenuId || ''
-        }
+    // 准备提交的数据
+    const genTable = {
+      ...mergedInfo,
+      columns: state.columns,
+      params: {
+        treeCode: mergedInfo.treeCode || '',
+        treeName: mergedInfo.treeName || '',
+        treeParentCode: mergedInfo.treeParentCode || '',
+        parentMenuId: mergedInfo.parentMenuId || ''
       }
+    }
 
-      console.log('提交的完整数据:', genTable)
+    console.log('准备提交的数据:', JSON.stringify(genTable, null, 2))
 
-      const res = await updateGenTable(genTable)
-      if (res.code === 200) {
-        ElMessage.success(res.msg)
-        close()
-      } else {
-        ElMessage.error(res.msg || '提交失败')
-      }
+    const res = await update(genTable)
+    if (res.code === SuccessResultCode) {
+      ElMessage.success(res.message || '提交成功')
+      onCancel()
+    } else {
+      console.error('提交失败响应:', res)
+      ElMessage.error(res.message || '提交失败')
     }
   } catch (error) {
     console.error('提交过程中发生错误:', error)
-    ElMessage.error("提交失败,请检查表单数据")
+    ElMessage.error('提交失败,请检查表单数据')
   }
 }
 
-
-const close = () => {
-
-  const obj = {
-    path: "/gen-index",
+// 返回
+const onCancel = () => {
+  router.push({
+    path: '/gen-index',
     query: {
       t: Date.now(),
       pageNum: route.query.pageNum
     }
-  }
-
-  // 根据您的路由和标签页管理实现调整
-  // 这里假设您有类似的功能来关闭页面
-  router.push(obj)
+  })
 }
 
 // 初始化拖拽
@@ -353,20 +375,20 @@ const initSortable = () => {
   nextTick(() => {
     if (!dragTableRef.value) return
 
-    const el = dragTableRef.value.$el.querySelectorAll(".el-table__body-wrapper > table > tbody")[0]
+    const el = dragTableRef.value.$el.querySelectorAll('.el-table__body-wrapper > table > tbody')[0]
     if (!el) return
 
     Sortable.create(el, {
-      handle: ".allowDrag",
-      onEnd: (evt) => {
+      handle: '.allowDrag',
+      onEnd: (evt: { oldIndex?: number; newIndex?: number }) => {
         const { oldIndex, newIndex } = evt
         if (oldIndex === undefined || newIndex === undefined) return
 
-        const targetRow = columns.value.splice(oldIndex, 1)[0]
-        columns.value.splice(newIndex, 0, targetRow)
+        const targetRow = state.columns.splice(oldIndex, 1)[0]
+        state.columns.splice(newIndex, 0, targetRow)
 
-        // 更新排序
-        columns.value.forEach((column, index) => {
+        // 更新排序 - 明确指定参数类型
+        state.columns.forEach((column: GenTableColumn, index: number) => {
           column.sort = index + 1
         })
       }
@@ -374,30 +396,72 @@ const initSortable = () => {
   })
 }
 
-// 生命周期
-onMounted(async () => {
+// 初始化数据
+const initData = async () => {
   const tableId = route.params?.tableId as string
-  if (tableId) {
-    try {
-      // 获取表详细信息
-      const res = await getGenTable(tableId)
-      columns.value = res.data.rows
-      info.value = res.data.info
-      tables.value = res.data.tables
+  if (!tableId) return
+
+  try {
+    const res = await getDetail(tableId)
+    if (res.code === SuccessResultCode) {
+      // 初始化时格式化所有 javaField,非驼峰命名的转为小写
+      state.columns = (res.data.rows || []).map((column: GenTableColumn) => ({
+        ...column,
+        javaField: formatJavaField(column.javaField)
+      }))
+
+      state.info = res.data.info || {}
+      state.tables = res.data.tables || []
 
       // 查询字典下拉列表
       // const dictRes = await getDictOptionselect()
-      // dictOptions.value = dictRes.data
+      // state.dictOptions = dictRes.data || []
 
       // 查询菜单下拉列表
       // const menuRes = await getMenuTreeselect()
-      // menus.value = handleTree(menuRes.data, "menuId")
+      // state.menus = handleTree(menuRes.data || [], 'menuId')
 
       // 初始化拖拽
       initSortable()
-    } catch (error) {
-      console.error('初始化数据失败:', error)
+    } else {
+      ElMessage.error(res.message || '获取数据失败')
     }
+  } catch (error) {
+    console.error('初始化数据失败:', error)
+    ElMessage.error('初始化数据失败,请稍后重试')
   }
+}
+
+// 组件挂载
+onMounted(() => {
+  initData()
+})
+
+// 监听窗口大小变化调整表格高度
+window.addEventListener('resize', () => {
+  state.tableHeight = `${document.documentElement.scrollHeight - 300}px`
 })
 </script>
+
+<style scoped>
+.footer-action {
+  display: flex;
+  justify-content: center;
+  margin-top: 20px;
+  padding-top: 20px;
+  border-top: 1px solid #ebeef5;
+}
+
+:deep(.el-tabs--border-card) {
+  box-shadow: none;
+  border: 1px solid #dcdfe6;
+}
+
+:deep(.el-table) {
+  margin-top: 10px;
+}
+
+:deep(.el-tabs__content) {
+  padding: 20px;
+}
+</style>

+ 0 - 734
wxjy-wxjy-web/src/views/gen/genIndex.vue

@@ -1,734 +0,0 @@
-<template>
-  <div class="app-container">
-    <!-- 搜索表单 -->
-    <el-form
-      :model="queryParams"
-      ref="queryFormRef"
-      size="small"
-      :inline="true"
-      v-show="showSearch"
-      label-width="68px"
-    >
-      <el-form-item label="表名称" prop="tableName">
-        <el-input
-          v-model="queryParams.tableName"
-          placeholder="请输入表名称"
-          clearable
-          @keyup.enter="handleQuery"
-        />
-      </el-form-item>
-      <el-form-item label="表描述" prop="tableComment">
-        <el-input
-          v-model="queryParams.tableComment"
-          placeholder="请输入表描述"
-          clearable
-          @keyup.enter="handleQuery"
-        />
-      </el-form-item>
-      <el-form-item label="创建时间">
-        <el-date-picker
-          v-model="dateRange"
-          style="width: 240px"
-          value-format="YYYY-MM-DD"
-          type="daterange"
-          range-separator="-"
-          start-placeholder="开始日期"
-          end-placeholder="结束日期"
-          @change="handleDateChange"
-        />
-      </el-form-item>
-      <el-form-item>
-        <el-button type="primary" :icon="Search" size="small" @click="handleQuery">
-          搜索
-        </el-button>
-        <el-button :icon="Refresh" size="small" @click="resetQuery">
-          重置
-        </el-button>
-      </el-form-item>
-    </el-form>
-
-    <!-- 操作按钮 -->
-    <el-row :gutter="10" class="mb8">
-      <el-col :span="1.5">
-        <el-button
-          type="primary"
-          plain
-          :icon="Download"
-          size="small"
-          :disabled="multiple"
-          @click="handleGenTable"
-        >
-          生成
-        </el-button>
-      </el-col>
-      <el-col :span="1.5">
-        <el-button
-          type="primary"
-          plain
-          :icon="Plus"
-          size="small"
-          @click="openCreateTable"
-        >
-          创建
-        </el-button>
-      </el-col>
-      <el-col :span="1.5">
-        <el-button
-          type="info"
-          plain
-          :icon="Upload"
-          size="small"
-          @click="openImportTable"
-        >
-          导入
-        </el-button>
-      </el-col>
-      <el-col :span="1.5">
-        <el-button
-          type="success"
-          plain
-          :icon="Edit"
-          size="small"
-          :disabled="single"
-          @click="handleEditTable"
-        >
-          修改
-        </el-button>
-      </el-col>
-      <el-col :span="1.5">
-        <el-button
-          type="danger"
-          plain
-          :icon="Delete"
-          size="small"
-          :disabled="multiple"
-          @click="handleDelete"
-        >
-          删除
-        </el-button>
-      </el-col>
-<!--      <RightToolbar :show-search="showSearch" @query-table="getList" />-->
-    </el-row>
-
-    <!-- 数据表格 -->
-    <el-table
-      v-loading="loading"
-      :data="tableList"
-      @selection-change="handleSelectionChange"
-      @sort-change="handleSortChange"
-    >
-      <el-table-column type="selection" align="center" width="55" />
-      <el-table-column label="序号" width="50" align="center">
-        <template #default="{ $index }">
-          <span>{{ (queryParams.pageNum - 1) * queryParams.pageSize + $index + 1 }}</span>
-        </template>
-      </el-table-column>
-      <el-table-column
-        label="表名称"
-        align="center"
-        prop="tableName"
-        :show-overflow-tooltip="true"
-        width="260"
-        sortable="custom"
-      />
-      <el-table-column
-        label="表描述"
-        align="center"
-        prop="tableComment"
-        :show-overflow-tooltip="true"
-        width="220"
-        sortable="custom"
-      />
-      <el-table-column
-        label="实体"
-        align="center"
-        prop="className"
-        :show-overflow-tooltip="true"
-        width="220"
-      />
-      <el-table-column
-        label="创建时间"
-        align="center"
-        prop="createTime"
-        width="160"
-        sortable="custom"
-      />
-      <el-table-column
-        label="更新时间"
-        align="center"
-        prop="updateTime"
-        width="160"
-        sortable="custom"
-      />
-      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
-        <template #default="{ row }">
-          <el-button
-            type="text"
-            size="small"
-            :icon="View"
-            @click="handlePreview(row)"
-            v-has-permi="['tool:gen:preview']"
-          >
-            预览
-          </el-button>
-          <el-button
-            type="text"
-            size="small"
-            :icon="Edit"
-            @click="handleEditTable(row)"
-            v-has-permi="['tool:gen:edit']"
-          >
-            编辑
-          </el-button>
-          <el-button
-            type="text"
-            size="small"
-            :icon="Delete"
-            @click="handleDelete(row)"
-            v-has-permi="['tool:gen:remove']"
-          >
-            删除
-          </el-button>
-          <el-button
-            type="text"
-            size="small"
-            :icon="Refresh"
-            @click="handleSynchDb(row)"
-            v-has-permi="['tool:gen:edit']"
-          >
-            同步
-          </el-button>
-          <el-button
-            type="text"
-            size="small"
-            :icon="Download"
-            @click="handleGenTable(row)"
-          >
-            生成代码
-          </el-button>
-        </template>
-      </el-table-column>
-    </el-table>
-
-    <!-- 分页组件 -->
-    <Pagination
-      v-show="total > 0"
-      :total="total"
-      v-model:page="queryParams.pageNum"
-      v-model:limit="queryParams.pageSize"
-      @pagination="getList"
-    />
-
-    <!-- 代码预览对话框 -->
-    <el-dialog
-      :title="preview.title"
-      v-model="preview.open"
-      width="80%"
-      top="5vh"
-      append-to-body
-      class="scrollbar"
-      @close="handlePreviewClose"
-    >
-      <el-tabs v-model="preview.activeName" type="border-card">
-        <el-tab-pane
-          v-for="(value, key) in preview.data"
-          :label="getTabLabel(key)"
-          :name="getTabName(key)"
-          :key="key"
-        >
-          <template #label>
-            <span class="tab-label">{{ getTabLabel(key) }}</span>
-          </template>
-          <div class="code-header">
-            <el-tooltip content="复制代码" placement="top">
-              <el-button
-                :icon="DocumentCopy"
-                @click="handleCopy(value)"
-                size="small"
-                text
-              >
-                复制
-              </el-button>
-            </el-tooltip>
-          </div>
-          <div class="code-container">
-            <pre><code class="hljs" v-html="highlightedCode(value, key)"></code></pre>
-          </div>
-        </el-tab-pane>
-      </el-tabs>
-    </el-dialog>
-
-    <!-- 子组件 -->
-    <ImportTable ref="importRef" @ok="handleQuery" />
-    <CreateTable ref="createRef" @ok="handleQuery" />
-  </div>
-</template>
-
-<script setup lang="ts">
-import { ref, reactive, onMounted, nextTick, computed } from 'vue'
-import { useRoute, useRouter } from 'vue-router'
-import { ElMessage, ElMessageBox, ElNotification } from 'element-plus'
-import type { FormInstance, TableColumnCtx } from 'element-plus'
-import {
-  Search,
-  Refresh,
-  Download,
-  Plus,
-  Upload,
-  Edit,
-  Delete,
-  View,
-  DocumentCopy
-} from '@element-plus/icons-vue'
-
-// API
-import {
-  listTable,
-  previewTable,
-  delTable,
-  genCode,
-  synchDb,
-  type GenTableInfo,
-  type GenTableQuery, batchGenCode
-} from '@/apis/gen/gen'
-
-// 组件
-import ImportTable from './importTable.vue'
-import CreateTable from './createTable.vue'
-// import RightToolbar from '@/components/RightToolbar/NewDeclaredGodds.vue'
-import Pagination from '@/components/Pagination/index.vue'
-
-// Highlight.js 配置
-import hljs from 'highlight.js/lib/core'
-import javascript from 'highlight.js/lib/languages/javascript'
-import xml from 'highlight.js/lib/languages/xml'
-import json from 'highlight.js/lib/languages/json'
-import sql from 'highlight.js/lib/languages/sql'
-import java from 'highlight.js/lib/languages/java'
-import css from 'highlight.js/lib/languages/css'
-
-// 注册语言
-hljs.registerLanguage('javascript', javascript)
-hljs.registerLanguage('xml', xml)
-hljs.registerLanguage('json', json)
-hljs.registerLanguage('sql', sql)
-hljs.registerLanguage('java', java)
-hljs.registerLanguage('css', css)
-
-// 类型定义
-interface PreviewData {
-  open: boolean
-  title: string
-  data: Record<string, string>
-  activeName: string
-}
-
-interface SortParams {
-  prop: string
-  order: 'ascending' | 'descending'
-}
-
-// 路由
-const route = useRoute()
-const router = useRouter()
-
-// Refs
-const queryFormRef = ref<FormInstance>()
-const importRef = ref<InstanceType<typeof ImportTable>>()
-const createRef = ref<InstanceType<typeof CreateTable>>()
-
-// 响应式数据
-const loading = ref(true)
-const uniqueId = ref('')
-const selectedRows = ref<GenTableInfo[]>([])
-const showSearch = ref(true)
-const total = ref(0)
-const tableList = ref<GenTableInfo[]>([])
-const dateRange = ref<string[]>([])
-
-const queryParams = reactive<GenTableQuery & { sort?: string; order?: string }>({
-  pageNum: 1,
-  pageSize: 10,
-  tableName: undefined,
-  tableComment: undefined
-})
-
-const preview = reactive<PreviewData>({
-  open: false,
-  title: '代码预览',
-  data: {},
-  activeName: 'domain.java'
-})
-
-// 计算属性
-const ids = computed(() => selectedRows.value.map(item => item.tableId))
-const tableNames = computed(() => selectedRows.value.map(item => item.tableName))
-const single = computed(() => selectedRows.value.length !== 1)
-const multiple = computed(() => selectedRows.value.length === 0)
-
-// 生命周期
-onMounted(() => {
-  getList()
-})
-
-
-
-// 方法
-/** 查询表集合 */
-const getList = async () => {
-  try {
-    loading.value = true
-
-    // 构建请求参数
-    const params: GenTableQuery = { ...queryParams }
-    if (dateRange.value && dateRange.value.length === 2) {
-      params.beginTime = dateRange.value[0]
-      params.endTime = dateRange.value[1]
-    }
-
-    const response = await listTable(params)
-    console.log(response);
-    if (response.code === 200) {
-      tableList.value = response.rows
-      total.value = response.total
-    } else {
-      ElMessage.error(response.msg || '获取数据失败')
-    }
-  } catch (error) {
-    ElMessage.error('网络错误,请稍后重试')
-    console.error('获取表列表失败:', error)
-  } finally {
-    loading.value = false
-  }
-}
-
-/** 搜索按钮操作 */
-const handleQuery = () => {
-  queryParams.pageNum = 1
-  getList()
-}
-
-/** 日期范围变化 */
-const handleDateChange = (value: string[]) => {
-  dateRange.value = value
-}
-
-/** 生成代码操作 */
-/** 生成代码操作 */
-const handleGenTable = async (row?: GenTableInfo) => {
-  const targetTableNames = row?.tableName || tableNames.value.join(',')
-
-  if (!targetTableNames) {
-    ElMessage.error('请选择要生成的数据')
-    return
-  }
-
-  try {
-    loading.value = true
-    console.log('开始生成代码,表名:', targetTableNames)
-
-    // 使用 axios 下载
-    const response = await batchGenCode(targetTableNames)
-    console.log('完整响应对象:', response)
-    console.log('响应状态:', response.status)
-    console.log('响应头:', response.headers)
-    console.log('响应数据类型:', typeof response.data)
-    console.log('响应数据构造函数:', response.data?.constructor?.name)
-    console.log('响应数据:', response.data)
-
-    // 检查是否是 Blob
-    if (response.data instanceof Blob) {
-      console.log('是 Blob 对象,大小:', response.data.size, '类型:', response.data.type)
-    } else {
-      console.log('不是 Blob 对象,实际类型:', typeof response.data)
-      // 尝试查看内容
-      try {
-        const text = await new Response(response.data).text()
-        console.log('响应内容:', text.substring(0, 200)) // 只显示前200个字符
-      } catch (e) {
-        console.log('无法读取响应内容')
-      }
-    }
-
-    // 只有确认是 Blob 才创建 URL
-    if (response.data instanceof Blob && response.data.size > 0) {
-      const url = window.URL.createObjectURL(response.data)
-      const link = document.createElement('a')
-      link.href = url
-      link.download = targetTableNames.includes(',') ? 'codes.zip' : `${targetTableNames}.zip`
-      document.body.appendChild(link)
-      link.click()
-      document.body.removeChild(link)
-      window.URL.revokeObjectURL(url)
-      ElMessage.success('代码生成成功')
-    } else {
-      throw new Error('响应不是有效的文件数据')
-    }
-
-  } catch (error: any) {
-    console.error('生成代码失败:', error)
-    ElMessage.error('生成代码失败: ' + (error.message || '未知错误'))
-  } finally {
-    loading.value = false
-  }
-}
-
-/** 同步数据库操作 */
-const handleSynchDb = async (row: GenTableInfo) => {
-  try {
-    await ElMessageBox.confirm(
-      `确认要强制同步"${row.tableName}"表结构吗?`,
-      '系统提示',
-      {
-        type: 'warning',
-        confirmButtonText: '确定',
-        cancelButtonText: '取消'
-      }
-    )
-
-    const response = await synchDb(row.tableName)
-    if (response.code === 200) {
-      ElMessage.success('同步成功')
-      getList() // 刷新列表
-    } else {
-      ElMessage.error(response.msg || '同步失败')
-    }
-  } catch (error) {
-    // 用户取消操作
-  }
-}
-
-/** 打开导入表弹窗 */
-const openImportTable = () => {
-  importRef.value?.show()
-}
-
-/** 打开创建表弹窗 */
-const openCreateTable = () => {
-  createRef.value?.show()
-}
-
-/** 重置按钮操作 */
-const resetQuery = () => {
-  dateRange.value = []
-  if (queryFormRef.value) {
-    queryFormRef.value.resetFields()
-  }
-  queryParams.sort = undefined
-  queryParams.order = undefined
-  handleQuery()
-}
-
-/** 预览按钮 */
-const handlePreview = async (row: GenTableInfo) => {
-  try {
-    const response = await previewTable(row.tableId)
-    if (response.code === 200) {
-      preview.data = response.data
-      preview.open = true
-      preview.activeName = Object.keys(response.data)[0]?.split('/').pop()?.split('.vm')[0] || 'domain.java'
-    } else {
-      ElMessage.error(response.msg || '预览失败')
-    }
-  } catch (error) {
-    ElMessage.error('预览失败')
-    console.error('预览失败:', error)
-  }
-}
-
-/** 关闭预览 */
-const handlePreviewClose = () => {
-  preview.data = {}
-  preview.activeName = 'domain.java'
-}
-
-/** 获取标签页名称 */
-const getTabName = (key: string) => {
-  const lastSlashIndex = key.lastIndexOf('/')
-  const vmIndex = key.indexOf('.vm')
-  return key.substring(lastSlashIndex + 1, vmIndex)
-}
-
-/** 获取标签页显示标签 */
-const getTabLabel = (key: string) => {
-  return getTabName(key)
-}
-
-/** 高亮显示代码 */
-const highlightedCode = (code: string, key: string) => {
-  const vmName = getTabName(key)
-  const language = vmName.substring(vmName.lastIndexOf('.') + 1)
-
-  try {
-    const result = hljs.highlight(code || '', {
-      language: getLanguageAlias(language)
-    })
-    return result.value || '&nbsp;'
-  } catch (error) {
-    return code || '&nbsp;'
-  }
-}
-
-/** 获取语言别名 */
-const getLanguageAlias = (language: string): string => {
-  const aliases: Record<string, string> = {
-    'java': 'java',
-    'xml': 'xml',
-    'html': 'xml',
-    'js': 'javascript',
-    'javascript': 'javascript',
-    'json': 'json',
-    'sql': 'sql',
-    'css': 'css',
-    'vue': 'xml'
-  }
-  return aliases[language] || 'plaintext'
-}
-
-/** 复制代码 */
-const handleCopy = async (code: string) => {
-  try {
-    await navigator.clipboard.writeText(code)
-    ElMessage.success('复制成功')
-  } catch (error) {
-    ElMessage.error('复制失败')
-  }
-}
-
-/** 多选框选中数据 */
-const handleSelectionChange = (selection: GenTableInfo[]) => {
-  selectedRows.value = selection
-}
-
-/** 表格排序 */
-const handleSortChange = ({ prop, order }: SortParams) => {
-  if (prop && order) {
-    queryParams.sort = prop
-    queryParams.order = order === 'ascending' ? 'asc' : 'desc'
-  } else {
-    queryParams.sort = undefined
-    queryParams.order = undefined
-  }
-  getList()
-}
-
-/** 修改按钮操作 */
-const handleEditTable = (row?: GenTableInfo) => {
-  const tableId = row?.tableId || ids.value[0]
-  const tableName = row?.tableName || tableNames.value[0]
-
-  // 使用 name 跳转而不是 path
-  router.push({
-    name: 'GenEdit', // 使用路由名称
-    params: { tableId },
-    query: {
-      pageNum: queryParams.pageNum.toString(),
-      tableName
-    }
-  })
-  /*// 路由跳转到编辑页面
-  router.push({
-    path: `/gen/gen-edit/${tableId}`,
-    query: {
-      pageNum: queryParams.pageNum.toString(),
-      tableName
-    }
-  })*/
-}
-
-/** 删除按钮操作 */
-const handleDelete = async (row?: GenTableInfo) => {
-  const tableIds = row?.tableId || ids.value
-
-  try {
-    await ElMessageBox.confirm(
-      `是否确认删除表编号为"${Array.isArray(tableIds) ? tableIds.join(',') : tableIds}"的数据项?`,
-      '系统提示',
-      {
-        type: 'warning',
-        confirmButtonText: '确定',
-        cancelButtonText: '取消'
-      }
-    )
-
-    const response = await delTable(tableIds)
-    if (response.code === 200) {
-      ElMessage.success('删除成功')
-      getList()
-    } else {
-      ElMessage.error(response.msg || '删除失败')
-    }
-  } catch (error) {
-    // 用户取消操作
-  }
-}
-
-// 监听路由变化
-import { watch } from 'vue'
-watch(
-  () => route.query,
-  (newQuery) => {
-    const time = newQuery.t as string
-    if (time && time !== uniqueId.value) {
-      uniqueId.value = time
-      queryParams.pageNum = Number(newQuery.pageNum) || 1
-      getList()
-    }
-  },
-  { immediate: true }
-)
-</script>
-
-<style scoped>
-.app-container {
-  padding: 20px;
-}
-
-.mb8 {
-  margin-bottom: 8px;
-}
-
-.scrollbar {
-  max-height: 70vh;
-  overflow-y: auto;
-}
-
-.code-header {
-  display: flex;
-  justify-content: flex-end;
-  padding: 8px 0;
-  border-bottom: 1px solid #e8e8e8;
-  margin-bottom: 12px;
-}
-
-.code-container {
-  background: #f8f9fa;
-  border-radius: 4px;
-  padding: 16px;
-  overflow-x: auto;
-}
-
-.hljs {
-  background: transparent !important;
-  padding: 0 !important;
-  font-family: 'JetBrains Mono', 'Fira Code', Consolas, 'Courier New', monospace;
-  font-size: 14px;
-  line-height: 1.5;
-}
-
-.tab-label {
-  font-weight: 500;
-}
-
-:deep(.el-table .small-padding) {
-  padding: 8px 0;
-}
-
-:deep(.el-tabs__content) {
-  position: relative;
-}
-
-:deep(.el-tabs--border-card > .el-tabs__content) {
-  padding: 16px;
-}
-</style>

+ 256 - 327
wxjy-wxjy-web/src/views/gen/genInfoForm.vue

@@ -1,354 +1,284 @@
 <template>
-  <el-form ref="formRef" :model="formData" :rules="rules" label-width="150px">
-    <el-row>
-      <el-col :span="12">
-        <el-form-item prop="tplCategory">
-          <span slot="label">生成模板</span>
-          <el-select v-model="formData.tplCategory" @change="handleTplChange">
-            <el-option label="单表(增删改查)" value="crud" />
-            <el-option label="树表(增删改查)" value="tree" />
-            <el-option label="主子表(增删改查)" value="sub" />
-          </el-select>
-        </el-form-item>
-      </el-col>
-
-      <el-col :span="12">
-        <el-form-item prop="tplWebType">
-          <span slot="label">前端类型</span>
-          <el-select v-model="formData.tplWebType">
-            <el-option label="Vue2 Element UI 模版" value="element-ui" />
-            <el-option label="Vue3 Element Plus 模版" value="element-plus" />
-          </el-select>
-        </el-form-item>
-      </el-col>
-
-      <el-col :span="12">
-        <el-form-item prop="packageName">
-          <span slot="label">
-            生成包路径
-            <el-tooltip content="生成在哪个java包下,例如 com.rongji.system" placement="top">
-              <i class="el-icon-question"></i>
-            </el-tooltip>
-          </span>
-          <el-input v-model="formData.packageName" />
-        </el-form-item>
-      </el-col>
-
-      <el-col :span="12">
-        <el-form-item prop="moduleName">
-          <span slot="label">
-            生成模块名
-            <el-tooltip content="可理解为子系统名,例如 system" placement="top">
-              <i class="el-icon-question"></i>
-            </el-tooltip>
-          </span>
-          <el-input v-model="formData.moduleName" />
-        </el-form-item>
-      </el-col>
-
-      <el-col :span="12">
-        <el-form-item prop="businessName">
-          <span slot="label">
-            生成业务名
-            <el-tooltip content="可理解为功能英文名,例如 user" placement="top">
-              <i class="el-icon-question"></i>
-            </el-tooltip>
-          </span>
-          <el-input v-model="formData.businessName" />
-        </el-form-item>
-      </el-col>
-
-      <el-col :span="12">
-        <el-form-item prop="functionName">
-          <span slot="label">
-            生成功能名
-            <el-tooltip content="用作类描述,例如 用户" placement="top">
-              <i class="el-icon-question"></i>
-            </el-tooltip>
-          </span>
-          <el-input v-model="formData.functionName" />
-        </el-form-item>
-      </el-col>
-
-      <el-col :span="12">
-        <el-form-item prop="genType">
-          <span slot="label">
-            生成代码方式
-            <el-tooltip content="默认为zip压缩包下载,也可以自定义生成路径" placement="top">
-              <i class="el-icon-question"></i>
-            </el-tooltip>
-          </span>
-          <el-radio v-model="formData.genType" label="0">zip压缩包</el-radio>
-          <el-radio v-model="formData.genType" label="1">自定义路径</el-radio>
-        </el-form-item>
-      </el-col>
-
-      <!--      <el-col :span="12">
-              <el-form-item>
-                <span slot="label">
-                  上级菜单
-                  <el-tooltip content="分配到指定菜单下,例如 系统管理" placement="top">
-                    <i class="el-icon-question"></i>
-                  </el-tooltip>
-                </span>
-                <el-tree-select
-                  v-model="formData.parentMenuId"
-                  :data="menus"
-                  :props="treeProps"
-                  check-strictly
-                  :render-after-expand="false"
-                  placeholder="请选择系统菜单"
-                />
-              </el-form-item>
-            </el-col>-->
-
-      <el-col :span="24" v-if="formData.genType == '1'">
-        <el-form-item prop="genPath">
-          <span slot="label">
-            自定义路径
-            <el-tooltip content="填写磁盘绝对路径,若不填写,则生成到当前Web项目下" placement="top">
-              <i class="el-icon-question"></i>
-            </el-tooltip>
-          </span>
-          <el-input v-model="formData.genPath">
-            <template #append>
-              <el-dropdown @command="handlePathCommand">
-                <el-button type="primary">
-                  最近路径快速选择
-                  <i class="el-icon-arrow-down el-icon--right"></i>
-                </el-button>
-                <template #dropdown>
-                  <el-dropdown-menu>
-                    <el-dropdown-item command="reset">恢复默认的生成基础路径</el-dropdown-item>
-                    <el-dropdown-item command="project">项目根路径</el-dropdown-item>
-                  </el-dropdown-menu>
-                </template>
-              </el-dropdown>
+  <cacp-form-layout>
+    <el-form
+      ref="formRef"
+      :model="state.formData"
+      :rules="state.rules"
+      label-width="150px"
+      label-position="right"
+    >
+      <el-row :gutter="20">
+        <el-col :span="12">
+          <el-form-item prop="tplCategory"  label="生成模板">
+            <el-select v-model="state.formData.tplCategory" disabled @change="handleTplChange">
+              <el-option label="单表(增删改查)" value="crud" />
+              <el-option label="树表(增删改查)" value="tree" />
+              <el-option label="主子表(增删改查)" value="sub" />
+            </el-select>
+          </el-form-item>
+        </el-col>
+
+        <el-col :span="12">
+          <el-form-item prop="tplWebType" label="前端类型">
+            <el-select v-model="state.formData.tplWebType" disabled>
+              <el-option label="Vue2 Element UI 模版" value="element-ui" />
+              <el-option label="Vue3 Element Plus 模版" value="element-plus" />
+            </el-select>
+          </el-form-item>
+        </el-col>
+
+        <el-col :span="12">
+          <el-form-item prop="packageName">
+            <template #label>
+              生成包路径
+              <el-tooltip content="生成在哪个java包下,例如 com.rongji.system" placement="top">
+                <i class="el-icon-question" />
+              </el-tooltip>
             </template>
-          </el-input>
-        </el-form-item>
-      </el-col>
-    </el-row>
-
-    <!-- 树表配置 -->
-    <el-row v-show="formData.tplCategory == 'tree'">
-      <h4 class="form-header">其他信息</h4>
-      <el-col :span="12">
-        <el-form-item>
-          <span slot="label">
-            树编码字段
-            <el-tooltip content="树显示的编码字段名, 如:dept_id" placement="top">
-              <i class="el-icon-question"></i>
-            </el-tooltip>
-          </span>
-          <el-select v-model="formData.treeCode" placeholder="请选择">
-            <el-option
-              v-for="(column, index) in formData.columns"
-              :key="index"
-              :label="`${column.columnName}:${column.columnComment}`"
-              :value="column.columnName"
-            />
-          </el-select>
-        </el-form-item>
-      </el-col>
-      <el-col :span="12">
-        <el-form-item>
-          <span slot="label">
-            树父编码字段
-            <el-tooltip content="树显示的父编码字段名, 如:parent_Id" placement="top">
-              <i class="el-icon-question"></i>
-            </el-tooltip>
-          </span>
-          <el-select v-model="formData.treeParentCode" placeholder="请选择">
-            <el-option
-              v-for="(column, index) in formData.columns"
-              :key="index"
-              :label="`${column.columnName}:${column.columnComment}`"
-              :value="column.columnName"
-            />
-          </el-select>
-        </el-form-item>
-      </el-col>
-      <el-col :span="12">
-        <el-form-item>
-          <span slot="label">
-            树名称字段
-            <el-tooltip content="树节点的显示名称字段名, 如:dept_name" placement="top">
-              <i class="el-icon-question"></i>
-            </el-tooltip>
-          </span>
-          <el-select v-model="formData.treeName" placeholder="请选择">
-            <el-option
-              v-for="(column, index) in formData.columns"
-              :key="index"
-              :label="`${column.columnName}:${column.columnComment}`"
-              :value="column.columnName"
-            />
-          </el-select>
-        </el-form-item>
-      </el-col>
-    </el-row>
-
-    <!-- 主子表配置 -->
-    <el-row v-show="formData.tplCategory == 'sub'">
-      <h4 class="form-header">关联信息</h4>
-      <el-col :span="12">
-        <el-form-item>
-          <span slot="label">
-            关联子表的表名
-            <el-tooltip content="关联子表的表名, 如:sys_user" placement="top">
-              <i class="el-icon-question"></i>
-            </el-tooltip>
-          </span>
-          <el-select v-model="formData.subTableName" placeholder="请选择" @change="handleSubTableChange">
-            <el-option
-              v-for="(table, index) in tables"
-              :key="index"
-              :label="`${table.tableName}:${table.tableComment}`"
-              :value="table.tableName"
-            />
-          </el-select>
-        </el-form-item>
-      </el-col>
-      <el-col :span="12">
-        <el-form-item>
-          <span slot="label">
-            子表关联的外键名
-            <el-tooltip content="子表关联的外键名, 如:user_id" placement="top">
-              <i class="el-icon-question"></i>
-            </el-tooltip>
-          </span>
-          <el-select v-model="formData.subTableFkName" placeholder="请选择">
-            <el-option
-              v-for="(column, index) in subColumns"
-              :key="index"
-              :label="`${column.columnName}:${column.columnComment}`"
-              :value="column.columnName"
-            />
-          </el-select>
-        </el-form-item>
-      </el-col>
-    </el-row>
-  </el-form>
+            <el-input v-model="state.formData.packageName" placeholder="请输入生成包路径" clearable />
+          </el-form-item>
+        </el-col>
+
+        <el-col :span="12">
+          <el-form-item prop="moduleName">
+            <template #label>
+              生成模块名
+              <el-tooltip content="可理解为子系统名,例如 system" placement="top">
+                <i class="el-icon-question" />
+              </el-tooltip>
+            </template>
+            <el-input v-model="state.formData.moduleName" placeholder="请输入生成模块名" clearable />
+          </el-form-item>
+        </el-col>
+
+        <el-col :span="12">
+          <el-form-item prop="businessName">
+            <template #label>
+              生成业务名
+              <el-tooltip content="可理解为功能英文名,例如 user" placement="top">
+                <i class="el-icon-question" />
+              </el-tooltip>
+            </template>
+            <el-input v-model="state.formData.businessName" placeholder="请输入生成业务名" clearable />
+          </el-form-item>
+        </el-col>
+
+        <el-col :span="12">
+          <el-form-item prop="functionName">
+            <template #label>
+              生成功能名
+              <el-tooltip content="用作类描述,例如 用户" placement="top">
+                <i class="el-icon-question" />
+              </el-tooltip>
+            </template>
+            <el-input v-model="state.formData.functionName" placeholder="请输入生成功能名" clearable />
+          </el-form-item>
+        </el-col>
+      </el-row>
+    </el-form>
+  </cacp-form-layout>
 </template>
 
-<script setup>
-import { ref, watch, nextTick } from 'vue'
+<script lang="ts" setup>
+import { reactive, ref, watch} from 'vue'
+import type { GenTableColumn } from '@/types/gen/GenTableColumn'
+import type { FormInstance, FormRules } from 'element-plus'
 
-// Props
-const props = defineProps({
-  info: {
-    type: Object,
-    default: () => ({})
-  },
-  tables: {
-    type: Array,
-    default: () => []
-  },
-  menus: {
-    type: Array,
-    default: () => []
-  }
-})
-
-// Emits
-const emit = defineEmits(['update:info', 'change'])
-
-// Refs
-const formRef = ref(null)
-const subColumns = ref([])
-
-// 表单数据 - 使用 computed 或者直接使用 props.info
-const formData = ref({ ...props.info })
+// 定义类型
+interface TableInfo {
+  tableName: string
+  tableComment: string
+  columns?: GenTableColumn[]
+}
 
-// 监听 props.info 的变化
-watch(() => props.info, (newVal) => {
-  formData.value = { ...newVal }
-}, { deep: true })
+interface Menu {
+  menuId: number
+  menuName?: string
+  children?: Menu[]
+}
 
-// 树形选择器配置
-const treeProps = {
-  value: 'menuId',
-  label: 'menuName',
-  children: 'children'
+interface FormData {
+  tplCategory?: string
+  tplWebType?: string
+  packageName?: string
+  moduleName?: string
+  businessName?: string
+  functionName?: string
+  genType?: string
+  genPath?: string
+  treeCode?: string
+  treeParentCode?: string
+  treeName?: string
+  subTableName?: string
+  subTableFkName?: string
+  columns?: GenTableColumn[]
+  parentMenuId?: number
+  [key: string]: any
 }
 
-// 表单验证规则
-const rules = {
-  tplCategory: [
-    { required: true, message: "请选择生成模板", trigger: "blur" }
-  ],
-  packageName: [
-    { required: true, message: "请输入生成包路径", trigger: "blur" }
-  ],
-  moduleName: [
-    { required: true, message: "请输入生成模块名", trigger: "blur" }
-  ],
-  businessName: [
-    { required: true, message: "请输入生成业务名", trigger: "blur" }
-  ],
-  functionName: [
-    { required: true, message: "请输入生成功能名", trigger: "blur" }
-  ],
+// Props
+interface Props {
+  info: FormData
+  tables: TableInfo[]
+  menus: Menu[]
 }
 
-// 监听器
-watch(() => formData.value.subTableName, (val) => {
-  setSubTableColumns(val)
+const props = withDefaults(defineProps<Props>(), {
+  info: () => ({
+    tplCategory: 'crud',
+    tplWebType: 'element-ui',
+    packageName: '',
+    moduleName: '',
+    businessName: '',
+    functionName: '',
+    genType: '0',
+    genPath: '',
+    treeCode: '',
+    treeParentCode: '',
+    treeName: '',
+    subTableName: '',
+    subTableFkName: '',
+    columns: []
+  }),
+  tables: () => [],
+  menus: () => []
 })
 
-watch(() => formData.value.tplWebType, (val) => {
-  if (val === '') {
-    formData.value.tplWebType = "element-ui"
+// Refs
+const formRef = ref<FormInstance>()
+
+// 响应式状态
+interface State {
+  formData: FormData
+  subColumns: GenTableColumn[]
+  rules: FormRules
+  treeProps: {
+    value: string
+    label: string
+    children: string
   }
-})
-
-// 确保数据正确同步到父组件
-watch(formData, (newVal) => {
-  // 同步所有字段到父组件的 info
-  Object.keys(newVal).forEach(key => {
-    props.info[key] = newVal[key]
-  })
-}, { deep: true, immediate: true })
-
-// 添加一个方法来强制同步数据
-const syncDataToParent = () => {
-  Object.keys(formData.value).forEach(key => {
-    props.info[key] = formData.value[key]
-  })
 }
 
-// 方法
-const handleSubTableChange = (value) => {
-  formData.value.subTableFkName = ''
-}
+const state = reactive<State>({
+  formData: {
+    tplCategory: 'crud',
+    tplWebType: 'element-ui',
+    packageName: '',
+    moduleName: '',
+    businessName: '',
+    functionName: '',
+    genType: '0',
+    genPath: '',
+    treeCode: '',
+    treeParentCode: '',
+    treeName: '',
+    subTableName: '',
+    subTableFkName: '',
+    columns: []
+  },
+  subColumns: [],
+  rules: {
+    tplCategory: [
+      { required: true, message: '请选择生成模板', trigger: 'blur' }
+    ],
+    packageName: [
+      { required: true, message: '请输入生成包路径', trigger: 'blur' }
+    ],
+    moduleName: [
+      { required: true, message: '请输入生成模块名', trigger: 'blur' }
+    ],
+    businessName: [
+      { required: true, message: '请输入生成业务名', trigger: 'blur' }
+    ],
+    functionName: [
+      { required: true, message: '请输入生成功能名', trigger: 'blur' }
+    ]
+  },
+  treeProps: {
+    value: 'menuId',
+    label: 'menuName',
+    children: 'children'
+  }
+})
 
-const handleTplChange = (value) => {
+// 监听 props 变化,更新表单数据
+watch(
+  () => props.info,
+  (newInfo) => {
+    if (newInfo) {
+      state.formData = {
+        tplCategory: newInfo.tplCategory || 'crud',
+        tplWebType: newInfo.tplWebType || 'element-ui',
+        packageName: newInfo.packageName || '',
+        moduleName: newInfo.moduleName || '',
+        businessName: newInfo.businessName || '',
+        functionName: newInfo.functionName || '',
+        genType: newInfo.genType || '0',
+        genPath: newInfo.genPath || '',
+        treeCode: newInfo.treeCode || '',
+        treeParentCode: newInfo.treeParentCode || '',
+        treeName: newInfo.treeName || '',
+        subTableName: newInfo.subTableName || '',
+        subTableFkName: newInfo.subTableFkName || '',
+        columns: newInfo.columns || [],
+        parentMenuId: newInfo.parentMenuId
+      }
+    }
+  },
+  { immediate: true, deep: true }
+)
+
+// 监听 tables 和 menus
+// watch(
+//   () => props.tables,
+//   (newTables) => {
+//     // 可以在这里处理 tables 数据的更新
+//   },
+//   { immediate: true }
+// )
+//
+// watch(
+//   () => props.menus,
+//   (newMenus) => {
+//     // 可以在这里处理 menus 数据的更新
+//   },
+//   { immediate: true }
+// )
+
+// 监听子表名变化
+watch(
+  () => state.formData.subTableName,
+  (newVal) => {
+    setSubTableColumns(newVal)
+  }
+)
+
+// 监听前端类型变化
+watch(
+  () => state.formData.tplWebType,
+  (newVal) => {
+    if (!newVal) {
+      state.formData.tplWebType = 'element-ui'
+    }
+  }
+)
+
+const handleTplChange = (value: string) => {
   if (value !== 'sub') {
-    formData.value.subTableName = ''
-    formData.value.subTableFkName = ''
+    state.formData.subTableName = ''
+    state.formData.subTableFkName = ''
   }
 }
 
-const setSubTableColumns = (value) => {
+const setSubTableColumns = (value: string) => {
   const table = props.tables.find(item => item.tableName === value)
   if (table) {
-    subColumns.value = table.columns || []
+    state.subColumns = table.columns || []
   } else {
-    subColumns.value = []
+    state.subColumns = []
   }
 }
 
-const handlePathCommand = (command) => {
-  switch (command) {
-    case 'reset':
-      formData.value.genPath = '/'
-      break
-    case 'project':
-      formData.value.genPath = process.cwd()
-      break
-  }
-}
 
 // 表单验证方法
 const validate = () => {
@@ -360,7 +290,7 @@ const validate = () => {
 
     formRef.value.validate((valid) => {
       if (valid) {
-        resolve(formData.value)
+        resolve(state.formData)
       } else {
         reject(new Error('表单验证失败'))
       }
@@ -387,8 +317,7 @@ defineExpose({
   getFormRef: () => formRef.value,
   validate,
   resetFields,
-  clearValidate,
-  syncDataToParent
+  clearValidate
 })
 </script>
 

+ 156 - 133
wxjy-wxjy-web/src/views/gen/importTable.vue

@@ -1,91 +1,97 @@
 <template>
-  <!-- 导入表 -->
-  <el-dialog
-    :title="title"
-    v-model="visible"
-    width="800px"
-    top="5vh"
-    append-to-body
-    @close="handleClose"
+
+  <cacp-dialog
+    v-model="state.visible"
+    :resizable="false"
+    :title="state.title"
+    width="50%"
+    @closed="onClose"
   >
-    <el-form :model="queryParams" ref="queryFormRef" size="small" :inline="true">
+    <cacp-search-panel-layout
+      :model="state.queryData"
+      ref="queryFormRef"
+      label-position="left"
+      label-width="auto"
+      :gutter="30"
+      :colSpan="6"
+    >
       <el-form-item label="表名称" prop="tableName">
         <el-input
-          v-model="queryParams.tableName"
+          v-model="state.queryData.tableName"
           placeholder="请输入表名称"
           clearable
-          @keyup.enter="handleQuery"
+          @keyup.enter="onSearch"
         />
       </el-form-item>
       <el-form-item label="表描述" prop="tableComment">
         <el-input
-          v-model="queryParams.tableComment"
+          v-model="state.queryData.tableComment"
           placeholder="请输入表描述"
           clearable
-          @keyup.enter="handleQuery"
+          @keyup.enter="onSearch"
         />
       </el-form-item>
-      <el-form-item>
-        <el-button type="primary" :icon="Search" size="small" @click="handleQuery">
-          搜索
-        </el-button>
-        <el-button :icon="Refresh" size="small" @click="resetQuery">
-          重置
-        </el-button>
-      </el-form-item>
-    </el-form>
+      <template #buttonGroup>
+        <el-button type="primary" @click="onSearch">查询</el-button>
+        <el-button type="info" @click="onReset">重置</el-button>
+      </template>
+    </cacp-search-panel-layout>
 
-    <el-row>
-      <el-table
-        @row-click="clickRow"
-        ref="tableRef"
-        :data="dbTableList"
+    <div  style="max-height: 60vh; overflow-y: auto; padding-right: 10px;">
+      <cacp-complex-table
+        :data="tableData"
+        :pagination="tablePagination"
         @selection-change="handleSelectionChange"
-        height="260px"
-        v-loading="loading"
+        @on-page-change="onPageChange"
+        @on-size-change="onSizeChange"
+        :loading="loading"
       >
-        <el-table-column type="selection" width="55" />
-        <el-table-column prop="tableName" label="表名称" :show-overflow-tooltip="true" />
-        <el-table-column prop="tableComment" label="表描述" :show-overflow-tooltip="true" />
-        <el-table-column prop="createTime" label="创建时间" width="180" />
-        <el-table-column prop="updateTime" label="更新时间" width="180" />
-      </el-table>
-
-      <Pagination
-        v-show="total > 0"
-        :total="total"
-        v-model:page="queryParams.pageNum"
-        v-model:limit="queryParams.pageSize"
-        @pagination="handlePaginationChange"
-      />
-    </el-row>
+        <el-table-column type="selection" align="center" width="55" />
+        <el-table-column
+          label="表名称"
+          align="center"
+          prop="tableName"
+          :show-overflow-tooltip="true"
+        />
+        <el-table-column
+          label="表描述"
+          align="center"
+          prop="tableComment"
+          :show-overflow-tooltip="true"
+          width="220"
+        />
+        <el-table-column
+          label="创建时间"
+          align="center"
+          prop="createTime"
+          width="160"
+        />
+        <el-table-column
+          label="更新时间"
+          align="center"
+          prop="updateTime"
+          width="160"
+        />
+      </cacp-complex-table>
+    </div>
 
     <template #footer>
       <span class="dialog-footer">
-        <el-button type="primary" @click="handleImportTable">确 定</el-button>
-        <el-button @click="visible = false">取 消</el-button>
+        <el-button type="primary" @click="onImportTable">确 定</el-button>
+        <el-button @click="state.visible = false">取 消</el-button>
       </span>
     </template>
-  </el-dialog>
+  </cacp-dialog>
 </template>
 
 <script setup lang="ts">
-import { ref, reactive, onMounted, nextTick } from 'vue'
-import { ElMessage, ElMessageBox, ElTable } from 'element-plus'
-import type { FormInstance } from 'element-plus'
-import { Search, Refresh } from '@element-plus/icons-vue'
-
+import { reactive, ref, computed } from 'vue'
+import { ElMessage } from 'element-plus'
+import { useComplexTable,type SearchPanelLayoutInstance, SuccessResultCode,useLoading } from '@cacp/ui'
+import type { DbTableInfo, GenTable, GenTableQuery, SelectionItem } from '@/types/gen/GenTable'
+import config from '@/config'
 // API
-import { listDbTable, importTable, type DbTableInfo, type GenTableQuery } from '@/apis/gen/gen'
-import Pagination from '@/components/Pagination/index.vue'
-
-// 类型定义
-interface SelectionItem {
-  tableName: string
-  tableComment: string
-  createTime: string
-  updateTime: string
-}
+import { listDbTable, importTable } from '@/apis/gen/gen'
 
 // Emits
 const emit = defineEmits<{
@@ -93,125 +99,142 @@ const emit = defineEmits<{
 }>()
 
 // Refs
-const queryFormRef = ref<FormInstance>()
-const tableRef = ref<InstanceType<typeof ElTable>>()
+const queryFormRef = ref<SearchPanelLayoutInstance>()
 
 // 响应式数据
-const visible = ref(false)
-const loading = ref(false)
-const title = ref('导入表')
-const total = ref(0)
-const selectedTables = ref<SelectionItem[]>([])
-const dbTableList = ref<DbTableInfo[]>([])
-
-const queryParams = reactive<GenTableQuery>({
-  pageNum: 1,
-  pageSize: 10,
-  tableName: undefined,
-  tableComment: undefined
+interface State {
+  visible: boolean
+  loading: boolean
+  title: string
+  total: number
+  selectedTables: SelectionItem[]
+  dbTableList: DbTableInfo[]
+  queryData: GenTableQuery & {
+    pageNum: number
+    pageSize: number
+    tableName?: string
+    tableComment?: string
+  }
+}
+
+const state = reactive<State>({
+  visible: false,
+  loading: false,
+  title: '导入表',
+  total: 0,
+  selectedTables: [],
+  dbTableList: [],
+  queryData: {
+    pageNum: 1,
+    pageSize: 10,
+    tableName: undefined,
+    tableComment: undefined
+  }
 })
 
+// 表格 Hook
+const tableHooks = useComplexTable<GenTable>(config)
+const { tableData, tablePagination, setPagination, setPageIndex, setPageSizes } = tableHooks
+
+// 计算属性
+const tableNames = computed(() => state.selectedTables.map(item => item.tableName).join(','))
+
 // 方法
 /** 显示弹框 */
 const show = () => {
-  visible.value = true
-  getList()
+  state.visible = true
+  onLoadData()
 }
 
-/** 点击行 */
-const clickRow = (row: SelectionItem) => {
-  if (tableRef.value) {
-    tableRef.value.toggleRowSelection(row)
-  }
-}
 
 /** 多选框选中数据 */
 const handleSelectionChange = (selection: SelectionItem[]) => {
-  selectedTables.value = selection
+  state.selectedTables = selection
 }
 
 /** 查询表数据 */
-const getList = async () => {
+const onLoadData = async () => {
   try {
-    loading.value = true
-    const response = await listDbTable(queryParams)
-    console.log('获取数据库表列表:', response)
-    if (response.code === 200) {
-      dbTableList.value = response.rows
-      total.value = response.total
+    state.loading = true
+    const query = {
+      ...state.queryData,
+      pageIndex: tablePagination.currentPage,
+      pageSize: tablePagination.pageSize
+    }
+    const res = await listDbTable(query)
+    console.log('获取数据库表列表:', res)
+    if (res.code === SuccessResultCode) {
+      setPagination(res.data)
     } else {
-      ElMessage.error(response.msg || '获取数据失败')
+      ElMessage.error(res.message || '获取数据失败')
     }
   } catch (error) {
     ElMessage.error('网络错误,请稍后重试')
     console.error('获取数据库表列表失败:', error)
   } finally {
-    loading.value = false
+    state.loading = false
   }
 }
 
-/** 分页事件处理 */
-const handlePaginationChange = (pagination: any) => {
-  console.log('分页变化:', pagination)
-  // 更新分页参数
-  queryParams.pageNum = pagination.page
-  queryParams.pageSize = pagination.limit
-  // 重新获取数据
-  getList()
-}
-
 /** 搜索按钮操作 */
-const handleQuery = () => {
-  queryParams.pageNum = 1  // 搜索时重置到第一页
-  getList()
+const onSearch = () => {
+  state.queryData.pageNum = 1  // 搜索时重置到第一页
+  onLoadData()
 }
 
 /** 重置按钮操作 */
-const resetQuery = () => {
-  if (queryFormRef.value) {
-    queryFormRef.value.resetFields()
-  }
-  queryParams.pageNum = 1  // 重置时回到第一页
-  queryParams.tableName = undefined
-  queryParams.tableComment = undefined
-  getList()
+const onReset = () => {
+  queryFormRef.value?.resetFields()
+  state.queryData.pageNum = 1  // 重置时回到第一页
+  state.queryData.tableName = undefined
+  state.queryData.tableComment = undefined
+  onLoadData()
 }
 
 /** 导入按钮操作 */
-const handleImportTable = async () => {
-  const tableNames = selectedTables.value.map(item => item.tableName).join(',')
-
-  if (!tableNames) {
+const onImportTable = async () => {
+  if (!tableNames.value) {
     ElMessage.error('请选择要导入的表')
     return
   }
 
   try {
-    const response = await importTable({ tables: tableNames })
-    if (response.code === 200) {
-      ElMessage.success(response.msg || '导入成功')
-      visible.value = false
+
+    const response = await importTable(tableNames.value)
+    if (response.code === SuccessResultCode) {
+      ElMessage.success(response.message || '导入成功')
+      state.visible = false
       emit('ok')
     } else {
-      ElMessage.error(response.msg || '导入失败')
+      ElMessage.error(response.message || '导入失败')
     }
   } catch (error) {
     ElMessage.error('导入失败')
     console.error('导入表失败:', error)
   }
 }
+// 加载状态
+const { loading } = useLoading()
+// 翻页查询
+const onPageChange = (currentPage: number) => {
+  setPageIndex(currentPage)
+  onLoadData()
+}
 
+// 每页显示条数变化
+const onSizeChange = (size: number) => {
+  setPageSizes(size)
+  onLoadData()
+}
 /** 关闭对话框 */
-const handleClose = () => {
+const onClose = () => {
   // 重置数据
-  selectedTables.value = []
-  if (queryFormRef.value) {
-    queryFormRef.value.resetFields()
-  }
-  queryParams.pageNum = 1
-  queryParams.pageSize = 10
-  queryParams.tableName = undefined
-  queryParams.tableComment = undefined
+  state.selectedTables = []
+  queryFormRef.value?.resetFields()
+  state.queryData.pageNum = 1
+  state.queryData.pageSize = 10
+  state.queryData.tableName = undefined
+  state.queryData.tableComment = undefined
 }
 
 // 暴露方法给父组件