Pre Merge pull request !207 from XiaoHH/issue-I5AT0W
This commit is contained in:
commit
d0372623b4
|
|
@ -8,14 +8,7 @@ import javax.servlet.http.HttpServletResponse;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PutMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
import com.ruoyi.common.core.text.Convert;
|
import com.ruoyi.common.core.text.Convert;
|
||||||
import com.ruoyi.common.core.web.controller.BaseController;
|
import com.ruoyi.common.core.web.controller.BaseController;
|
||||||
import com.ruoyi.common.core.web.domain.AjaxResult;
|
import com.ruoyi.common.core.web.domain.AjaxResult;
|
||||||
|
|
@ -55,6 +48,17 @@ public class GenController extends BaseController
|
||||||
return getDataTable(list);
|
return getDataTable(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询所有可以生成代码的数据库名称列表
|
||||||
|
*/
|
||||||
|
@RequiresPermissions("tool:gen:list")
|
||||||
|
@GetMapping("/schema/list")
|
||||||
|
public AjaxResult genSchemaList()
|
||||||
|
{
|
||||||
|
List<String> list = genTableService.selectGenSchemaList();
|
||||||
|
return AjaxResult.success(list);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改代码生成业务
|
* 修改代码生成业务
|
||||||
*/
|
*/
|
||||||
|
|
@ -102,12 +106,12 @@ public class GenController extends BaseController
|
||||||
*/
|
*/
|
||||||
@RequiresPermissions("tool:gen:import")
|
@RequiresPermissions("tool:gen:import")
|
||||||
@Log(title = "代码生成", businessType = BusinessType.IMPORT)
|
@Log(title = "代码生成", businessType = BusinessType.IMPORT)
|
||||||
@PostMapping("/importTable")
|
@PostMapping("/importTable/{schemaName}")
|
||||||
public AjaxResult importTableSave(String tables)
|
public AjaxResult importTableSave(@PathVariable("schemaName") String schemaName, @RequestParam("tables") String tables)
|
||||||
{
|
{
|
||||||
String[] tableNames = Convert.toStrArray(tables);
|
String[] tableNames = Convert.toStrArray(tables);
|
||||||
// 查询表信息
|
// 查询表信息
|
||||||
List<GenTable> tableList = genTableService.selectDbTableListByNames(tableNames);
|
List<GenTable> tableList = genTableService.selectDbTableListByNames(schemaName, tableNames);
|
||||||
genTableService.importGenTable(tableList);
|
genTableService.importGenTable(tableList);
|
||||||
return AjaxResult.success();
|
return AjaxResult.success();
|
||||||
}
|
}
|
||||||
|
|
@ -153,10 +157,10 @@ public class GenController extends BaseController
|
||||||
*/
|
*/
|
||||||
@RequiresPermissions("tool:gen:code")
|
@RequiresPermissions("tool:gen:code")
|
||||||
@Log(title = "代码生成", businessType = BusinessType.GENCODE)
|
@Log(title = "代码生成", businessType = BusinessType.GENCODE)
|
||||||
@GetMapping("/download/{tableName}")
|
@GetMapping("/download/{schemaName}/{tableName}")
|
||||||
public void download(HttpServletResponse response, @PathVariable("tableName") String tableName) throws IOException
|
public void download(HttpServletResponse response, @PathVariable("schemaName") String schemaName, @PathVariable("tableName") String tableName) throws IOException
|
||||||
{
|
{
|
||||||
byte[] data = genTableService.downloadCode(tableName);
|
byte[] data = genTableService.downloadCode(schemaName, tableName);
|
||||||
genCode(response, data);
|
genCode(response, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -165,10 +169,10 @@ public class GenController extends BaseController
|
||||||
*/
|
*/
|
||||||
@RequiresPermissions("tool:gen:code")
|
@RequiresPermissions("tool:gen:code")
|
||||||
@Log(title = "代码生成", businessType = BusinessType.GENCODE)
|
@Log(title = "代码生成", businessType = BusinessType.GENCODE)
|
||||||
@GetMapping("/genCode/{tableName}")
|
@GetMapping("/genCode/{schemaName}/{tableName}")
|
||||||
public AjaxResult genCode(@PathVariable("tableName") String tableName)
|
public AjaxResult genCode(@PathVariable("schemaName") String schemaName, @PathVariable("tableName") String tableName)
|
||||||
{
|
{
|
||||||
genTableService.generatorCode(tableName);
|
genTableService.generatorCode(schemaName, tableName);
|
||||||
return AjaxResult.success();
|
return AjaxResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -177,10 +181,10 @@ public class GenController extends BaseController
|
||||||
*/
|
*/
|
||||||
@RequiresPermissions("tool:gen:edit")
|
@RequiresPermissions("tool:gen:edit")
|
||||||
@Log(title = "代码生成", businessType = BusinessType.UPDATE)
|
@Log(title = "代码生成", businessType = BusinessType.UPDATE)
|
||||||
@GetMapping("/synchDb/{tableName}")
|
@GetMapping("/synchDb/{schemaName}/{tableName}")
|
||||||
public AjaxResult synchDb(@PathVariable("tableName") String tableName)
|
public AjaxResult synchDb(@PathVariable("schemaName") String schemaName, @PathVariable("tableName") String tableName)
|
||||||
{
|
{
|
||||||
genTableService.synchDb(tableName);
|
genTableService.synchDb(schemaName, tableName);
|
||||||
return AjaxResult.success();
|
return AjaxResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -189,11 +193,11 @@ public class GenController extends BaseController
|
||||||
*/
|
*/
|
||||||
@RequiresPermissions("tool:gen:code")
|
@RequiresPermissions("tool:gen:code")
|
||||||
@Log(title = "代码生成", businessType = BusinessType.GENCODE)
|
@Log(title = "代码生成", businessType = BusinessType.GENCODE)
|
||||||
@GetMapping("/batchGenCode")
|
@GetMapping("/batchGenCode/{schemaName}")
|
||||||
public void batchGenCode(HttpServletResponse response, String tables) throws IOException
|
public void batchGenCode(HttpServletResponse response, @PathVariable("schemaName") String schemaName, String tables) throws IOException
|
||||||
{
|
{
|
||||||
String[] tableNames = Convert.toStrArray(tables);
|
String[] tableNames = Convert.toStrArray(tables);
|
||||||
byte[] data = genTableService.downloadCode(tableNames);
|
byte[] data = genTableService.downloadCode(schemaName, tableNames);
|
||||||
genCode(response, data);
|
genCode(response, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,10 @@ public class GenTable extends BaseEntity
|
||||||
/** 编号 */
|
/** 编号 */
|
||||||
private Long tableId;
|
private Long tableId;
|
||||||
|
|
||||||
|
/** 库名称 */
|
||||||
|
@NotBlank(message = "库名称不能为空")
|
||||||
|
private String schemaName;
|
||||||
|
|
||||||
/** 表名称 */
|
/** 表名称 */
|
||||||
@NotBlank(message = "表名称不能为空")
|
@NotBlank(message = "表名称不能为空")
|
||||||
private String tableName;
|
private String tableName;
|
||||||
|
|
@ -105,6 +109,16 @@ public class GenTable extends BaseEntity
|
||||||
this.tableId = tableId;
|
this.tableId = tableId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getSchemaName()
|
||||||
|
{
|
||||||
|
return schemaName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSchemaName(String schemaName)
|
||||||
|
{
|
||||||
|
this.schemaName = schemaName;
|
||||||
|
}
|
||||||
|
|
||||||
public String getTableName()
|
public String getTableName()
|
||||||
{
|
{
|
||||||
return tableName;
|
return tableName;
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package com.ruoyi.gen.mapper;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import com.ruoyi.gen.domain.GenTableColumn;
|
import com.ruoyi.gen.domain.GenTableColumn;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 业务字段 数据层
|
* 业务字段 数据层
|
||||||
|
|
@ -13,10 +14,11 @@ public interface GenTableColumnMapper
|
||||||
/**
|
/**
|
||||||
* 根据表名称查询列信息
|
* 根据表名称查询列信息
|
||||||
*
|
*
|
||||||
* @param tableName 表名称
|
* @param schemaName 数据库名字
|
||||||
|
* @param tableName 表名称
|
||||||
* @return 列信息
|
* @return 列信息
|
||||||
*/
|
*/
|
||||||
public List<GenTableColumn> selectDbTableColumnsByName(String tableName);
|
public List<GenTableColumn> selectDbTableColumnsByName(@Param("schemaName") String schemaName, @Param("tableName") String tableName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询业务字段列表
|
* 查询业务字段列表
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package com.ruoyi.gen.mapper;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import com.ruoyi.gen.domain.GenTable;
|
import com.ruoyi.gen.domain.GenTable;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 业务 数据层
|
* 业务 数据层
|
||||||
|
|
@ -18,6 +19,13 @@ public interface GenTableMapper
|
||||||
*/
|
*/
|
||||||
public List<GenTable> selectGenTableList(GenTable genTable);
|
public List<GenTable> selectGenTableList(GenTable genTable);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询所有可以生成代码的数据库名称列表
|
||||||
|
*
|
||||||
|
* @return 数据库名称列表
|
||||||
|
*/
|
||||||
|
public List<String> selectGenSchemaList();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询据库列表
|
* 查询据库列表
|
||||||
*
|
*
|
||||||
|
|
@ -32,7 +40,7 @@ public interface GenTableMapper
|
||||||
* @param tableNames 表名称组
|
* @param tableNames 表名称组
|
||||||
* @return 数据库表集合
|
* @return 数据库表集合
|
||||||
*/
|
*/
|
||||||
public List<GenTable> selectDbTableListByNames(String[] tableNames);
|
public List<GenTable> selectDbTableListByNames(@Param("schemaName") String schemaName, @Param("tableNames") String[] tableNames);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询所有表信息
|
* 查询所有表信息
|
||||||
|
|
@ -55,7 +63,7 @@ public interface GenTableMapper
|
||||||
* @param tableName 表名称
|
* @param tableName 表名称
|
||||||
* @return 业务信息
|
* @return 业务信息
|
||||||
*/
|
*/
|
||||||
public GenTable selectGenTableByName(String tableName);
|
public GenTable selectGenTableByName(@Param("schemaName") String schemaName, @Param("tableName") String tableName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增业务
|
* 新增业务
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,17 @@ public class GenTableServiceImpl implements IGenTableService
|
||||||
return genTableMapper.selectGenTableList(genTable);
|
return genTableMapper.selectGenTableList(genTable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询所有可以生成代码的数据库名称列表
|
||||||
|
*
|
||||||
|
* @return 数据库名称列表
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<String> selectGenSchemaList()
|
||||||
|
{
|
||||||
|
return genTableMapper.selectGenSchemaList();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询据库列表
|
* 查询据库列表
|
||||||
*
|
*
|
||||||
|
|
@ -94,13 +105,14 @@ public class GenTableServiceImpl implements IGenTableService
|
||||||
/**
|
/**
|
||||||
* 查询据库列表
|
* 查询据库列表
|
||||||
*
|
*
|
||||||
|
* @param schemaName 数据库的名称
|
||||||
* @param tableNames 表名称组
|
* @param tableNames 表名称组
|
||||||
* @return 数据库表集合
|
* @return 数据库表集合
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<GenTable> selectDbTableListByNames(String[] tableNames)
|
public List<GenTable> selectDbTableListByNames(String schemaName, String[] tableNames)
|
||||||
{
|
{
|
||||||
return genTableMapper.selectDbTableListByNames(tableNames);
|
return genTableMapper.selectDbTableListByNames(schemaName, tableNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -170,7 +182,7 @@ public class GenTableServiceImpl implements IGenTableService
|
||||||
if (row > 0)
|
if (row > 0)
|
||||||
{
|
{
|
||||||
// 保存列信息
|
// 保存列信息
|
||||||
List<GenTableColumn> genTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName);
|
List<GenTableColumn> genTableColumns = genTableColumnMapper.selectDbTableColumnsByName(table.getSchemaName(), tableName);
|
||||||
for (GenTableColumn column : genTableColumns)
|
for (GenTableColumn column : genTableColumns)
|
||||||
{
|
{
|
||||||
GenUtils.initColumnField(column, table);
|
GenUtils.initColumnField(column, table);
|
||||||
|
|
@ -221,15 +233,16 @@ public class GenTableServiceImpl implements IGenTableService
|
||||||
/**
|
/**
|
||||||
* 生成代码(下载方式)
|
* 生成代码(下载方式)
|
||||||
*
|
*
|
||||||
* @param tableName 表名称
|
* @param schemaName 库名称
|
||||||
|
* @param tableName 表名称
|
||||||
* @return 数据
|
* @return 数据
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public byte[] downloadCode(String tableName)
|
public byte[] downloadCode(String schemaName, String tableName)
|
||||||
{
|
{
|
||||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
ZipOutputStream zip = new ZipOutputStream(outputStream);
|
ZipOutputStream zip = new ZipOutputStream(outputStream);
|
||||||
generatorCode(tableName, zip);
|
generatorCode(schemaName, tableName, zip);
|
||||||
IOUtils.closeQuietly(zip);
|
IOUtils.closeQuietly(zip);
|
||||||
return outputStream.toByteArray();
|
return outputStream.toByteArray();
|
||||||
}
|
}
|
||||||
|
|
@ -237,13 +250,14 @@ public class GenTableServiceImpl implements IGenTableService
|
||||||
/**
|
/**
|
||||||
* 生成代码(自定义路径)
|
* 生成代码(自定义路径)
|
||||||
*
|
*
|
||||||
* @param tableName 表名称
|
* @param schemaName 库名称
|
||||||
|
* @param tableName 表名称
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void generatorCode(String tableName)
|
public void generatorCode(String schemaName, String tableName)
|
||||||
{
|
{
|
||||||
// 查询表信息
|
// 查询表信息
|
||||||
GenTable table = genTableMapper.selectGenTableByName(tableName);
|
GenTable table = genTableMapper.selectGenTableByName(schemaName, tableName);
|
||||||
// 设置主子表信息
|
// 设置主子表信息
|
||||||
setSubTable(table);
|
setSubTable(table);
|
||||||
// 设置主键列信息
|
// 设置主键列信息
|
||||||
|
|
@ -283,13 +297,13 @@ public class GenTableServiceImpl implements IGenTableService
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void synchDb(String tableName)
|
public void synchDb(String schemaName, String tableName)
|
||||||
{
|
{
|
||||||
GenTable table = genTableMapper.selectGenTableByName(tableName);
|
GenTable table = genTableMapper.selectGenTableByName(schemaName, tableName);
|
||||||
List<GenTableColumn> tableColumns = table.getColumns();
|
List<GenTableColumn> tableColumns = table.getColumns();
|
||||||
Map<String, GenTableColumn> tableColumnMap = tableColumns.stream().collect(Collectors.toMap(GenTableColumn::getColumnName, Function.identity()));
|
Map<String, GenTableColumn> tableColumnMap = tableColumns.stream().collect(Collectors.toMap(GenTableColumn::getColumnName, Function.identity()));
|
||||||
|
|
||||||
List<GenTableColumn> dbTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName);
|
List<GenTableColumn> dbTableColumns = genTableColumnMapper.selectDbTableColumnsByName(schemaName, tableName);
|
||||||
if (StringUtils.isEmpty(dbTableColumns))
|
if (StringUtils.isEmpty(dbTableColumns))
|
||||||
{
|
{
|
||||||
throw new ServiceException("同步数据失败,原表结构不存在");
|
throw new ServiceException("同步数据失败,原表结构不存在");
|
||||||
|
|
@ -334,17 +348,18 @@ public class GenTableServiceImpl implements IGenTableService
|
||||||
/**
|
/**
|
||||||
* 批量生成代码(下载方式)
|
* 批量生成代码(下载方式)
|
||||||
*
|
*
|
||||||
|
* @param schemaName 库名称
|
||||||
* @param tableNames 表数组
|
* @param tableNames 表数组
|
||||||
* @return 数据
|
* @return 数据
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public byte[] downloadCode(String[] tableNames)
|
public byte[] downloadCode(String schemaName, String[] tableNames)
|
||||||
{
|
{
|
||||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
ZipOutputStream zip = new ZipOutputStream(outputStream);
|
ZipOutputStream zip = new ZipOutputStream(outputStream);
|
||||||
for (String tableName : tableNames)
|
for (String tableName : tableNames)
|
||||||
{
|
{
|
||||||
generatorCode(tableName, zip);
|
generatorCode(schemaName, tableName, zip);
|
||||||
}
|
}
|
||||||
IOUtils.closeQuietly(zip);
|
IOUtils.closeQuietly(zip);
|
||||||
return outputStream.toByteArray();
|
return outputStream.toByteArray();
|
||||||
|
|
@ -353,10 +368,10 @@ public class GenTableServiceImpl implements IGenTableService
|
||||||
/**
|
/**
|
||||||
* 查询表信息并生成代码
|
* 查询表信息并生成代码
|
||||||
*/
|
*/
|
||||||
private void generatorCode(String tableName, ZipOutputStream zip)
|
private void generatorCode(String schemaName, String tableName, ZipOutputStream zip)
|
||||||
{
|
{
|
||||||
// 查询表信息
|
// 查询表信息
|
||||||
GenTable table = genTableMapper.selectGenTableByName(tableName);
|
GenTable table = genTableMapper.selectGenTableByName(schemaName, tableName);
|
||||||
// 设置主子表信息
|
// 设置主子表信息
|
||||||
setSubTable(table);
|
setSubTable(table);
|
||||||
// 设置主键列信息
|
// 设置主键列信息
|
||||||
|
|
@ -474,7 +489,7 @@ public class GenTableServiceImpl implements IGenTableService
|
||||||
String subTableName = table.getSubTableName();
|
String subTableName = table.getSubTableName();
|
||||||
if (StringUtils.isNotEmpty(subTableName))
|
if (StringUtils.isNotEmpty(subTableName))
|
||||||
{
|
{
|
||||||
table.setSubTable(genTableMapper.selectGenTableByName(subTableName));
|
table.setSubTable(genTableMapper.selectGenTableByName(table.getSchemaName(), subTableName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,13 @@ public interface IGenTableService
|
||||||
*/
|
*/
|
||||||
public List<GenTable> selectGenTableList(GenTable genTable);
|
public List<GenTable> selectGenTableList(GenTable genTable);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询所有可以生成代码的数据库名称列表
|
||||||
|
*
|
||||||
|
* @return 数据库名称列表
|
||||||
|
*/
|
||||||
|
public List<String> selectGenSchemaList();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询据库列表
|
* 查询据库列表
|
||||||
*
|
*
|
||||||
|
|
@ -30,10 +37,11 @@ public interface IGenTableService
|
||||||
/**
|
/**
|
||||||
* 查询据库列表
|
* 查询据库列表
|
||||||
*
|
*
|
||||||
|
* @param schemaName 数据库的名称
|
||||||
* @param tableNames 表名称组
|
* @param tableNames 表名称组
|
||||||
* @return 数据库表集合
|
* @return 数据库表集合
|
||||||
*/
|
*/
|
||||||
public List<GenTable> selectDbTableListByNames(String[] tableNames);
|
public List<GenTable> selectDbTableListByNames(String schemaName, String[] tableNames);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询所有表信息
|
* 查询所有表信息
|
||||||
|
|
@ -84,10 +92,11 @@ public interface IGenTableService
|
||||||
/**
|
/**
|
||||||
* 生成代码(下载方式)
|
* 生成代码(下载方式)
|
||||||
*
|
*
|
||||||
* @param tableName 表名称
|
* @param schemaName 库名称
|
||||||
|
* @param tableName 表名称
|
||||||
* @return 数据
|
* @return 数据
|
||||||
*/
|
*/
|
||||||
public byte[] downloadCode(String tableName);
|
public byte[] downloadCode(String schemaName, String tableName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成代码(自定义路径)
|
* 生成代码(自定义路径)
|
||||||
|
|
@ -95,22 +104,24 @@ public interface IGenTableService
|
||||||
* @param tableName 表名称
|
* @param tableName 表名称
|
||||||
* @return 数据
|
* @return 数据
|
||||||
*/
|
*/
|
||||||
public void generatorCode(String tableName);
|
public void generatorCode(String schemaName, String tableName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 同步数据库
|
* 同步数据库
|
||||||
*
|
*
|
||||||
* @param tableName 表名称
|
* @param schemaName 数据库的名称
|
||||||
|
* @param tableName 表名称
|
||||||
*/
|
*/
|
||||||
public void synchDb(String tableName);
|
public void synchDb(String schemaName, String tableName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量生成代码(下载方式)
|
* 批量生成代码(下载方式)
|
||||||
*
|
*
|
||||||
|
* @param schemaName 库名称
|
||||||
* @param tableNames 表数组
|
* @param tableNames 表数组
|
||||||
* @return 数据
|
* @return 数据
|
||||||
*/
|
*/
|
||||||
public byte[] downloadCode(String[] tableNames);
|
public byte[] downloadCode(String schemaName, String[] tableNames);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改保存参数校验
|
* 修改保存参数校验
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
|
||||||
<select id="selectDbTableColumnsByName" parameterType="String" resultMap="GenTableColumnResult">
|
<select id="selectDbTableColumnsByName" parameterType="String" resultMap="GenTableColumnResult">
|
||||||
select column_name, (case when (is_nullable = 'no' <![CDATA[ && ]]> column_key != 'PRI') then '1' else null end) as is_required, (case when column_key = 'PRI' then '1' else '0' end) as is_pk, ordinal_position as sort, column_comment, (case when extra = 'auto_increment' then '1' else '0' end) as is_increment, column_type
|
select column_name, (case when (is_nullable = 'no' <![CDATA[ && ]]> column_key != 'PRI') then '1' else null end) as is_required, (case when column_key = 'PRI' then '1' else '0' end) as is_pk, ordinal_position as sort, column_comment, (case when extra = 'auto_increment' then '1' else '0' end) as is_increment, column_type
|
||||||
from information_schema.columns where table_schema = (select database()) and table_name = (#{tableName})
|
from information_schema.columns where table_schema = #{schemaName} and table_name = (#{tableName})
|
||||||
order by ordinal_position
|
order by ordinal_position
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
|
||||||
<resultMap type="GenTable" id="GenTableResult">
|
<resultMap type="GenTable" id="GenTableResult">
|
||||||
<id property="tableId" column="table_id" />
|
<id property="tableId" column="table_id" />
|
||||||
|
<result property="schemaName" column="schema_name" />
|
||||||
<result property="tableName" column="table_name" />
|
<result property="tableName" column="table_name" />
|
||||||
<result property="tableComment" column="table_comment" />
|
<result property="tableComment" column="table_comment" />
|
||||||
<result property="subTableName" column="sub_table_name" />
|
<result property="subTableName" column="sub_table_name" />
|
||||||
|
|
@ -54,14 +55,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<sql id="selectGenTableVo">
|
<sql id="selectGenTableVo">
|
||||||
select table_id, table_name, table_comment, sub_table_name, sub_table_fk_name, class_name, tpl_category, package_name, module_name, business_name, function_name, function_author, gen_type, gen_path, options, create_by, create_time, update_by, update_time, remark from gen_table
|
select table_id, schema_name, table_name, table_comment, sub_table_name, sub_table_fk_name, class_name, tpl_category, package_name, module_name, business_name, function_name, function_author, gen_type, gen_path, options, create_by, create_time, update_by, update_time, remark from gen_table
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
<select id="selectGenTableList" parameterType="GenTable" resultMap="GenTableResult">
|
<select id="selectGenTableList" parameterType="GenTable" resultMap="GenTableResult">
|
||||||
<include refid="selectGenTableVo"/>
|
<include refid="selectGenTableVo"/>
|
||||||
<where>
|
<where>
|
||||||
|
<if test="schemaName != null and schemaName != ''">
|
||||||
|
AND lower(`schema_name`) like lower(concat('%', #{schemaName}, '%'))
|
||||||
|
</if>
|
||||||
<if test="tableName != null and tableName != ''">
|
<if test="tableName != null and tableName != ''">
|
||||||
AND lower(table_name) like lower(concat('%', #{tableName}, '%'))
|
AND lower(`table_name`) like lower(concat('%', #{tableName}, '%'))
|
||||||
</if>
|
</if>
|
||||||
<if test="tableComment != null and tableComment != ''">
|
<if test="tableComment != null and tableComment != ''">
|
||||||
AND lower(table_comment) like lower(concat('%', #{tableComment}, '%'))
|
AND lower(table_comment) like lower(concat('%', #{tableComment}, '%'))
|
||||||
|
|
@ -75,11 +79,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
</where>
|
</where>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="selectGenSchemaList" resultType="String">
|
||||||
|
SELECT TABLE_SCHEMA
|
||||||
|
FROM information_schema.`TABLES`
|
||||||
|
WHERE TABLE_SCHEMA NOT IN ( 'ry-config', 'ry-seata' )
|
||||||
|
AND TABLE_SCHEMA LIKE 'ry-%'
|
||||||
|
GROUP BY TABLE_SCHEMA
|
||||||
|
</select>
|
||||||
|
|
||||||
<select id="selectDbTableList" parameterType="GenTable" resultMap="GenTableResult">
|
<select id="selectDbTableList" parameterType="GenTable" resultMap="GenTableResult">
|
||||||
select table_name, table_comment, create_time, update_time from information_schema.tables
|
select table_schema as schema_name, table_name, table_comment, create_time, update_time from information_schema.tables
|
||||||
where table_schema = (select database())
|
where table_schema = #{schemaName}
|
||||||
AND table_name NOT LIKE 'qrtz_%' AND table_name NOT LIKE 'gen_%'
|
AND table_name NOT LIKE 'qrtz_%' AND table_name NOT LIKE 'gen_%'
|
||||||
AND table_name NOT IN (select table_name from gen_table)
|
AND table_name NOT IN (select table_name from gen_table where schema_name = table_schema)
|
||||||
<if test="tableName != null and tableName != ''">
|
<if test="tableName != null and tableName != ''">
|
||||||
AND lower(table_name) like lower(concat('%', #{tableName}, '%'))
|
AND lower(table_name) like lower(concat('%', #{tableName}, '%'))
|
||||||
</if>
|
</if>
|
||||||
|
|
@ -96,10 +108,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="selectDbTableListByNames" resultMap="GenTableResult">
|
<select id="selectDbTableListByNames" resultMap="GenTableResult">
|
||||||
select table_name, table_comment, create_time, update_time from information_schema.tables
|
select table_schema as schema_name, table_name, table_comment, create_time, update_time from information_schema.tables
|
||||||
where table_name NOT LIKE 'qrtz_%' and table_name NOT LIKE 'gen_%' and table_schema = (select database())
|
where table_name NOT LIKE 'qrtz_%' and table_name NOT LIKE 'gen_%' and table_schema = #{schemaName}
|
||||||
and table_name in
|
and table_name in
|
||||||
<foreach collection="array" item="name" open="(" separator="," close=")">
|
<foreach collection="tableNames" item="name" open="(" separator="," close=")">
|
||||||
#{name}
|
#{name}
|
||||||
</foreach>
|
</foreach>
|
||||||
</select>
|
</select>
|
||||||
|
|
@ -111,7 +123,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="selectGenTableById" parameterType="Long" resultMap="GenTableResult">
|
<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,
|
SELECT t.table_id, t.schema_name, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark,
|
||||||
c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort
|
c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort
|
||||||
FROM gen_table t
|
FROM gen_table t
|
||||||
LEFT JOIN gen_table_column c ON t.table_id = c.table_id
|
LEFT JOIN gen_table_column c ON t.table_id = c.table_id
|
||||||
|
|
@ -119,11 +131,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="selectGenTableByName" parameterType="String" resultMap="GenTableResult">
|
<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,
|
SELECT t.table_id, t.schema_name, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark,
|
||||||
c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort
|
c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort
|
||||||
FROM gen_table t
|
FROM gen_table t
|
||||||
LEFT JOIN gen_table_column c ON t.table_id = c.table_id
|
LEFT JOIN gen_table_column c ON t.table_id = c.table_id
|
||||||
where t.table_name = #{tableName} order by c.sort
|
where t.schema_name = #{schemaName} and t.table_name = #{tableName} order by c.sort
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="selectGenTableAll" parameterType="String" resultMap="GenTableResult">
|
<select id="selectGenTableAll" parameterType="String" resultMap="GenTableResult">
|
||||||
|
|
@ -136,6 +148,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
|
||||||
<insert id="insertGenTable" parameterType="GenTable" useGeneratedKeys="true" keyProperty="tableId">
|
<insert id="insertGenTable" parameterType="GenTable" useGeneratedKeys="true" keyProperty="tableId">
|
||||||
insert into gen_table (
|
insert into gen_table (
|
||||||
|
<if test="tableName != null">schema_name ,</if>
|
||||||
<if test="tableName != null">table_name,</if>
|
<if test="tableName != null">table_name,</if>
|
||||||
<if test="tableComment != null and tableComment != ''">table_comment,</if>
|
<if test="tableComment != null and tableComment != ''">table_comment,</if>
|
||||||
<if test="className != null and className != ''">class_name,</if>
|
<if test="className != null and className != ''">class_name,</if>
|
||||||
|
|
@ -151,6 +164,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
<if test="createBy != null and createBy != ''">create_by,</if>
|
<if test="createBy != null and createBy != ''">create_by,</if>
|
||||||
create_time
|
create_time
|
||||||
)values(
|
)values(
|
||||||
|
<if test="tableName != null">#{schemaName},</if>
|
||||||
<if test="tableName != null">#{tableName},</if>
|
<if test="tableName != null">#{tableName},</if>
|
||||||
<if test="tableComment != null and tableComment != ''">#{tableComment},</if>
|
<if test="tableComment != null and tableComment != ''">#{tableComment},</if>
|
||||||
<if test="className != null and className != ''">#{className},</if>
|
<if test="className != null and className != ''">#{className},</if>
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,14 @@ export function listTable(query) {
|
||||||
params: query
|
params: query
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function listSchema() {
|
||||||
|
return request({
|
||||||
|
url: '/code/gen/schema/list',
|
||||||
|
method: 'get',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// 查询db数据库列表
|
// 查询db数据库列表
|
||||||
export function listDbTable(query) {
|
export function listDbTable(query) {
|
||||||
return request({
|
return request({
|
||||||
|
|
@ -35,9 +43,9 @@ export function updateGenTable(data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 导入表
|
// 导入表
|
||||||
export function importTable(data) {
|
export function importTable(data, schemaName) {
|
||||||
return request({
|
return request({
|
||||||
url: '/code/gen/importTable',
|
url: `/code/gen/importTable/${schemaName}`,
|
||||||
method: 'post',
|
method: 'post',
|
||||||
params: data
|
params: data
|
||||||
})
|
})
|
||||||
|
|
@ -68,9 +76,9 @@ export function genCode(tableName) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 同步数据库
|
// 同步数据库
|
||||||
export function synchDb(tableName) {
|
export function synchDb(schemaName, tableName) {
|
||||||
return request({
|
return request({
|
||||||
url: '/code/gen/synchDb/' + tableName,
|
url: `/code/gen/synchDb/${schemaName}/${tableName}`,
|
||||||
method: 'get'
|
method: 'get'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,17 @@
|
||||||
<template>
|
<template>
|
||||||
<!-- 导入表 -->
|
<!-- 导入表 -->
|
||||||
<el-dialog title="导入表" :visible.sync="visible" width="800px" top="5vh" append-to-body>
|
<el-dialog title="导入表" :visible.sync="visible" width="1200px" top="5vh" append-to-body>
|
||||||
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true">
|
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true">
|
||||||
|
<el-form-item label="库名称" prop="schemaName">
|
||||||
|
<el-select v-model="queryParams.schemaName" placeholder="请选择库名称">
|
||||||
|
<el-option
|
||||||
|
v-for="item in schemaList"
|
||||||
|
:key="item"
|
||||||
|
:label="item"
|
||||||
|
:value="item">
|
||||||
|
</el-option>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
<el-form-item label="表名称" prop="tableName">
|
<el-form-item label="表名称" prop="tableName">
|
||||||
<el-input
|
<el-input
|
||||||
v-model="queryParams.tableName"
|
v-model="queryParams.tableName"
|
||||||
|
|
@ -26,6 +36,7 @@
|
||||||
<el-row>
|
<el-row>
|
||||||
<el-table @row-click="clickRow" ref="table" :data="dbTableList" @selection-change="handleSelectionChange" height="260px">
|
<el-table @row-click="clickRow" ref="table" :data="dbTableList" @selection-change="handleSelectionChange" height="260px">
|
||||||
<el-table-column type="selection" width="55"></el-table-column>
|
<el-table-column type="selection" width="55"></el-table-column>
|
||||||
|
<el-table-column prop="schemaName" label="库名称" :show-overflow-tooltip="true"></el-table-column>
|
||||||
<el-table-column prop="tableName" label="表名称" :show-overflow-tooltip="true"></el-table-column>
|
<el-table-column prop="tableName" label="表名称" :show-overflow-tooltip="true"></el-table-column>
|
||||||
<el-table-column prop="tableComment" label="表描述" :show-overflow-tooltip="true"></el-table-column>
|
<el-table-column prop="tableComment" label="表描述" :show-overflow-tooltip="true"></el-table-column>
|
||||||
<el-table-column prop="createTime" label="创建时间"></el-table-column>
|
<el-table-column prop="createTime" label="创建时间"></el-table-column>
|
||||||
|
|
@ -47,7 +58,7 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { listDbTable, importTable } from "@/api/tool/gen";
|
import { listSchema, listDbTable, importTable } from "@/api/tool/gen";
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
|
@ -59,10 +70,15 @@ export default {
|
||||||
total: 0,
|
total: 0,
|
||||||
// 表数据
|
// 表数据
|
||||||
dbTableList: [],
|
dbTableList: [],
|
||||||
|
// 数据库列表
|
||||||
|
schemaList: [],
|
||||||
|
// 上一次选中数据库的名称,这个名称会在点搜索按钮的时候同步为 queryParams.tableName
|
||||||
|
preTableSchema: undefined,
|
||||||
// 查询参数
|
// 查询参数
|
||||||
queryParams: {
|
queryParams: {
|
||||||
pageNum: 1,
|
pageNum: 1,
|
||||||
pageSize: 10,
|
pageSize: 10,
|
||||||
|
schemaName: undefined,
|
||||||
tableName: undefined,
|
tableName: undefined,
|
||||||
tableComment: undefined
|
tableComment: undefined
|
||||||
}
|
}
|
||||||
|
|
@ -71,7 +87,7 @@ export default {
|
||||||
methods: {
|
methods: {
|
||||||
// 显示弹框
|
// 显示弹框
|
||||||
show() {
|
show() {
|
||||||
this.getList();
|
this.getSchemaList();
|
||||||
this.visible = true;
|
this.visible = true;
|
||||||
},
|
},
|
||||||
clickRow(row) {
|
clickRow(row) {
|
||||||
|
|
@ -81,8 +97,23 @@ export default {
|
||||||
handleSelectionChange(selection) {
|
handleSelectionChange(selection) {
|
||||||
this.tables = selection.map(item => item.tableName);
|
this.tables = selection.map(item => item.tableName);
|
||||||
},
|
},
|
||||||
|
getSchemaList() {
|
||||||
|
// 首先获取数据库信息
|
||||||
|
listSchema().then(schemaRes => {
|
||||||
|
// 至少有一个数据库
|
||||||
|
if (schemaRes.code === 200) {
|
||||||
|
this.schemaList = schemaRes.data;
|
||||||
|
this.queryParams.schemaName = schemaRes.data[0];
|
||||||
|
this.getList();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
// 查询表数据
|
// 查询表数据
|
||||||
getList() {
|
getList() {
|
||||||
|
// 查询之前先要将原有的选中的表空间清空
|
||||||
|
this.tables = []
|
||||||
|
// 同步preSchemaList
|
||||||
|
this.preTableSchema = this.queryParams.schemaName
|
||||||
listDbTable(this.queryParams).then(res => {
|
listDbTable(this.queryParams).then(res => {
|
||||||
if (res.code === 200) {
|
if (res.code === 200) {
|
||||||
this.dbTableList = res.rows;
|
this.dbTableList = res.rows;
|
||||||
|
|
@ -107,7 +138,7 @@ export default {
|
||||||
this.$modal.msgError("请选择要导入的表");
|
this.$modal.msgError("请选择要导入的表");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
importTable({ tables: tableNames }).then(res => {
|
importTable({ tables: tableNames }, this.preTableSchema).then(res => {
|
||||||
this.$modal.msgSuccess(res.msg);
|
this.$modal.msgSuccess(res.msg);
|
||||||
if (res.code === 200) {
|
if (res.code === 200) {
|
||||||
this.visible = false;
|
this.visible = false;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,14 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="app-container">
|
<div class="app-container">
|
||||||
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
|
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
|
||||||
|
<el-form-item label="库名称" prop="schemaName">
|
||||||
|
<el-input
|
||||||
|
v-model="queryParams.schemaName"
|
||||||
|
placeholder="请输入库名称"
|
||||||
|
clearable
|
||||||
|
@keyup.enter.native="handleQuery"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
<el-form-item label="表名称" prop="tableName">
|
<el-form-item label="表名称" prop="tableName">
|
||||||
<el-input
|
<el-input
|
||||||
v-model="queryParams.tableName"
|
v-model="queryParams.tableName"
|
||||||
|
|
@ -87,6 +95,13 @@
|
||||||
<span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
|
<span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
|
<el-table-column
|
||||||
|
label="库名称"
|
||||||
|
align="center"
|
||||||
|
prop="schemaName"
|
||||||
|
:show-overflow-tooltip="true"
|
||||||
|
width="120"
|
||||||
|
/>
|
||||||
<el-table-column
|
<el-table-column
|
||||||
label="表名称"
|
label="表名称"
|
||||||
align="center"
|
align="center"
|
||||||
|
|
@ -180,6 +195,7 @@ import { listTable, previewTable, delTable, genCode, synchDb } from "@/api/tool/
|
||||||
import importTable from "./importTable";
|
import importTable from "./importTable";
|
||||||
import hljs from "highlight.js/lib/highlight";
|
import hljs from "highlight.js/lib/highlight";
|
||||||
import "highlight.js/styles/github-gist.css";
|
import "highlight.js/styles/github-gist.css";
|
||||||
|
import {MessageBox} from "element-ui";
|
||||||
hljs.registerLanguage("java", require("highlight.js/lib/languages/java"));
|
hljs.registerLanguage("java", require("highlight.js/lib/languages/java"));
|
||||||
hljs.registerLanguage("xml", require("highlight.js/lib/languages/xml"));
|
hljs.registerLanguage("xml", require("highlight.js/lib/languages/xml"));
|
||||||
hljs.registerLanguage("html", require("highlight.js/lib/languages/xml"));
|
hljs.registerLanguage("html", require("highlight.js/lib/languages/xml"));
|
||||||
|
|
@ -198,6 +214,8 @@ export default {
|
||||||
uniqueId: "",
|
uniqueId: "",
|
||||||
// 选中数组
|
// 选中数组
|
||||||
ids: [],
|
ids: [],
|
||||||
|
// 选中库数组
|
||||||
|
schemaNames: [],
|
||||||
// 选中表数组
|
// 选中表数组
|
||||||
tableNames: [],
|
tableNames: [],
|
||||||
// 非单个禁用
|
// 非单个禁用
|
||||||
|
|
@ -216,6 +234,7 @@ export default {
|
||||||
queryParams: {
|
queryParams: {
|
||||||
pageNum: 1,
|
pageNum: 1,
|
||||||
pageSize: 10,
|
pageSize: 10,
|
||||||
|
schemaName: undefined,
|
||||||
tableName: undefined,
|
tableName: undefined,
|
||||||
tableComment: undefined
|
tableComment: undefined
|
||||||
},
|
},
|
||||||
|
|
@ -257,24 +276,41 @@ export default {
|
||||||
},
|
},
|
||||||
/** 生成代码操作 */
|
/** 生成代码操作 */
|
||||||
handleGenTable(row) {
|
handleGenTable(row) {
|
||||||
|
console.log(schemaName)
|
||||||
|
console.log(this.schemaNames)
|
||||||
const tableNames = row.tableName || this.tableNames;
|
const tableNames = row.tableName || this.tableNames;
|
||||||
if (tableNames == "") {
|
if (tableNames == "") {
|
||||||
this.$modal.msgError("请选择要生成的数据");
|
this.$modal.msgError("请选择要生成的数据");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// 获取数据库名字
|
||||||
|
let schemaName = row.schemaName
|
||||||
|
if (schemaName === undefined) {
|
||||||
|
// 居然已经选中生成的表信息了,那么就不会导致 this.schemaNames 为空了
|
||||||
|
schemaName = this.schemaNames[0];
|
||||||
|
for (let i = 1; i < this.schemaNames.length; i++) {
|
||||||
|
if (schemaName != this.schemaNames[i]) {
|
||||||
|
MessageBox.alert("请确保选中的表在同一个数据库当中", {
|
||||||
|
confirmButtonText: '知道了',
|
||||||
|
type: "error",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if(row.genType === "1") {
|
if(row.genType === "1") {
|
||||||
genCode(row.tableName).then(response => {
|
genCode(schemaName, row.tableName).then(response => {
|
||||||
this.$modal.msgSuccess("成功生成到自定义路径:" + row.genPath);
|
this.$modal.msgSuccess("成功生成到自定义路径:" + row.genPath);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this.$download.zip("/code/gen/batchGenCode?tables=" + tableNames, "ruoyi");
|
this.$download.zip(`/code/gen/batchGenCode/${schemaName}?tables=${tableNames}`, "ruoyi");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
/** 同步数据库操作 */
|
/** 同步数据库操作 */
|
||||||
handleSynchDb(row) {
|
handleSynchDb(row) {
|
||||||
const tableName = row.tableName;
|
const tableName = row.tableName;
|
||||||
this.$modal.confirm('确认要强制同步"' + tableName + '"表结构吗?').then(function() {
|
this.$modal.confirm('确认要强制同步"' + tableName + '"表结构吗?').then(function() {
|
||||||
return synchDb(tableName);
|
return synchDb(row.schemaName, tableName);
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
this.$modal.msgSuccess("同步成功");
|
this.$modal.msgSuccess("同步成功");
|
||||||
}).catch(() => {});
|
}).catch(() => {});
|
||||||
|
|
@ -311,6 +347,7 @@ export default {
|
||||||
// 多选框选中数据
|
// 多选框选中数据
|
||||||
handleSelectionChange(selection) {
|
handleSelectionChange(selection) {
|
||||||
this.ids = selection.map(item => item.tableId);
|
this.ids = selection.map(item => item.tableId);
|
||||||
|
this.schemaNames = selection.map(item => item.schemaName);
|
||||||
this.tableNames = selection.map(item => item.tableName);
|
this.tableNames = selection.map(item => item.tableName);
|
||||||
this.single = selection.length != 1;
|
this.single = selection.length != 1;
|
||||||
this.multiple = !selection.length;
|
this.multiple = !selection.length;
|
||||||
|
|
|
||||||
|
|
@ -634,6 +634,7 @@ insert into sys_notice values('2', '维护通知:2018-07-01 若依系统凌晨
|
||||||
drop table if exists gen_table;
|
drop table if exists gen_table;
|
||||||
create table gen_table (
|
create table gen_table (
|
||||||
table_id bigint(20) not null auto_increment comment '编号',
|
table_id bigint(20) not null auto_increment comment '编号',
|
||||||
|
schema_name varchar(200) default '' comment '数据库名称',
|
||||||
table_name varchar(200) default '' comment '表名称',
|
table_name varchar(200) default '' comment '表名称',
|
||||||
table_comment varchar(500) default '' comment '表描述',
|
table_comment varchar(500) default '' comment '表描述',
|
||||||
sub_table_name varchar(64) default null comment '关联子表的表名',
|
sub_table_name varchar(64) default null comment '关联子表的表名',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue