mirror of
https://gitcode.com/ageerle/ruoyi-ai.git
synced 2026-04-16 13:23:42 +00:00
feat: 更新代码生成功能-二阶段
This commit is contained in:
@@ -78,4 +78,28 @@ public class DataBaseHelper {
|
|||||||
public static List<String> getDataSourceNameList() {
|
public static List<String> getDataSourceNameList() {
|
||||||
return new ArrayList<>(DS.getDataSources().keySet());
|
return new ArrayList<>(DS.getDataSources().keySet());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前连接的所有表名称
|
||||||
|
*/
|
||||||
|
public static List<String> getCurrentDataSourceTableNameList() {
|
||||||
|
DataSource dataSource = DS.determineDataSource();
|
||||||
|
List<String> tableNames = new ArrayList<>();
|
||||||
|
try (Connection conn = dataSource.getConnection()) {
|
||||||
|
DatabaseMetaData metaData = conn.getMetaData();
|
||||||
|
String catalog = conn.getCatalog();
|
||||||
|
String schema = conn.getSchema();
|
||||||
|
|
||||||
|
// 获取所有表名
|
||||||
|
try (var resultSet = metaData.getTables(catalog, schema, "%", new String[]{"TABLE"})) {
|
||||||
|
while (resultSet.next()) {
|
||||||
|
String tableName = resultSet.getString("TABLE_NAME");
|
||||||
|
tableNames.add(tableName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new ServiceException("获取表名称失败: " + e.getMessage());
|
||||||
|
}
|
||||||
|
return tableNames;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,13 +58,4 @@ public class GenController extends BaseController {
|
|||||||
response.setContentType("application/octet-stream; charset=UTF-8");
|
response.setContentType("application/octet-stream; charset=UTF-8");
|
||||||
IoUtil.write(response.getOutputStream(), false, data);
|
IoUtil.write(response.getOutputStream(), false, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询数据源名称列表
|
|
||||||
*/
|
|
||||||
@SaCheckPermission("tool:gen:list")
|
|
||||||
@GetMapping(value = "/getDataNames")
|
|
||||||
public R<Object> getCurrentDataSourceNameList() {
|
|
||||||
return R.ok(DataBaseHelper.getDataSourceNameList());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import org.ruoyi.core.page.TableDataInfo;
|
|||||||
import org.ruoyi.generator.domain.bo.SchemaBo;
|
import org.ruoyi.generator.domain.bo.SchemaBo;
|
||||||
import org.ruoyi.generator.domain.vo.SchemaVo;
|
import org.ruoyi.generator.domain.vo.SchemaVo;
|
||||||
import org.ruoyi.generator.service.ISchemaService;
|
import org.ruoyi.generator.service.ISchemaService;
|
||||||
|
import org.ruoyi.helper.DataBaseHelper;
|
||||||
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.DeleteMapping;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
@@ -57,8 +58,7 @@ public class SchemaController extends BaseController {
|
|||||||
*/
|
*/
|
||||||
@SaCheckPermission("dev:schema:query")
|
@SaCheckPermission("dev:schema:query")
|
||||||
@GetMapping("/{id}")
|
@GetMapping("/{id}")
|
||||||
public R<SchemaVo> getInfo(@NotNull(message = "主键不能为空")
|
public R<SchemaVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
|
||||||
@PathVariable Long id) {
|
|
||||||
return R.ok(schemaService.queryById(id));
|
return R.ok(schemaService.queryById(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,8 +92,16 @@ public class SchemaController extends BaseController {
|
|||||||
@SaCheckPermission("dev:schema:remove")
|
@SaCheckPermission("dev:schema:remove")
|
||||||
@Log(title = "数据模型", businessType = BusinessType.DELETE)
|
@Log(title = "数据模型", businessType = BusinessType.DELETE)
|
||||||
@DeleteMapping("/{ids}")
|
@DeleteMapping("/{ids}")
|
||||||
public R<Void> remove(@NotEmpty(message = "主键不能为空")
|
public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
|
||||||
@PathVariable Long[] ids) {
|
|
||||||
return toAjax(schemaService.deleteWithValidByIds(List.of(ids), true));
|
return toAjax(schemaService.deleteWithValidByIds(List.of(ids), true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询数据源表名
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("dev:schema:getTableNameList")
|
||||||
|
@GetMapping(value = "/getDataNames")
|
||||||
|
public R<Object> getCurrentDataSourceTableNameList() {
|
||||||
|
return R.ok(DataBaseHelper.getCurrentDataSourceTableNameList());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -32,15 +32,14 @@ import java.util.List;
|
|||||||
* 数据模型字段
|
* 数据模型字段
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/@Validated
|
||||||
@Validated
|
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/dev/schemaField")
|
@RequestMapping("/dev/schemaField")
|
||||||
public class SchemaFieldController extends BaseController {
|
public class SchemaFieldController extends BaseController {
|
||||||
|
|
||||||
private final ISchemaFieldService schemaFieldService;
|
private final ISchemaFieldService schemaFieldService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询数据模型字段列表
|
* 查询数据模型字段列表
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import java.util.Collection;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 数据模型字段Service业务层处理
|
* 数据模型字段Service业务层处理
|
||||||
@@ -53,15 +54,17 @@ public class SchemaFieldServiceImpl implements ISchemaFieldService {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public TableDataInfo<SchemaFieldVo> queryPageList(SchemaFieldBo bo, PageQuery pageQuery) {
|
public TableDataInfo<SchemaFieldVo> queryPageList(SchemaFieldBo bo, PageQuery pageQuery) {
|
||||||
|
if (Objects.isNull(bo.getSchemaId())) {
|
||||||
|
return TableDataInfo.build();
|
||||||
|
}
|
||||||
LambdaQueryWrapper<SchemaField> lqw = buildQueryWrapper(bo);
|
LambdaQueryWrapper<SchemaField> lqw = buildQueryWrapper(bo);
|
||||||
Page<SchemaFieldVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
Page<SchemaFieldVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
||||||
return TableDataInfo.build(result);
|
return TableDataInfo.build(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
private LambdaQueryWrapper<SchemaField> buildQueryWrapper(SchemaFieldBo bo) {
|
private LambdaQueryWrapper<SchemaField> buildQueryWrapper(SchemaFieldBo bo) {
|
||||||
|
|
||||||
LambdaQueryWrapper<SchemaField> lqw = Wrappers.lambdaQuery();
|
LambdaQueryWrapper<SchemaField> lqw = Wrappers.lambdaQuery();
|
||||||
lqw.eq(bo.getSchemaId() != null, SchemaField::getSchemaId, bo.getSchemaId());
|
lqw.eq(SchemaField::getSchemaId, bo.getSchemaId());
|
||||||
lqw.like(StringUtils.isNotBlank(bo.getName()), SchemaField::getName, bo.getName());
|
lqw.like(StringUtils.isNotBlank(bo.getName()), SchemaField::getName, bo.getName());
|
||||||
lqw.eq(StringUtils.isNotBlank(bo.getCode()), SchemaField::getCode, bo.getCode());
|
lqw.eq(StringUtils.isNotBlank(bo.getCode()), SchemaField::getCode, bo.getCode());
|
||||||
lqw.eq(StringUtils.isNotBlank(bo.getType()), SchemaField::getType, bo.getType());
|
lqw.eq(StringUtils.isNotBlank(bo.getType()), SchemaField::getType, bo.getType());
|
||||||
|
|||||||
Reference in New Issue
Block a user