mirror of
https://gitcode.com/ageerle/ruoyi-ai.git
synced 2026-03-13 20:53:42 +08:00
feat: 更新代码生成功能-二阶段
This commit is contained in:
@@ -78,4 +78,28 @@ public class DataBaseHelper {
|
||||
public static List<String> getDataSourceNameList() {
|
||||
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");
|
||||
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.vo.SchemaVo;
|
||||
import org.ruoyi.generator.service.ISchemaService;
|
||||
import org.ruoyi.helper.DataBaseHelper;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@@ -57,8 +58,7 @@ public class SchemaController extends BaseController {
|
||||
*/
|
||||
@SaCheckPermission("dev:schema:query")
|
||||
@GetMapping("/{id}")
|
||||
public R<SchemaVo> getInfo(@NotNull(message = "主键不能为空")
|
||||
@PathVariable Long id) {
|
||||
public R<SchemaVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
|
||||
return R.ok(schemaService.queryById(id));
|
||||
}
|
||||
|
||||
@@ -92,8 +92,16 @@ public class SchemaController extends BaseController {
|
||||
@SaCheckPermission("dev:schema:remove")
|
||||
@Log(title = "数据模型", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public R<Void> remove(@NotEmpty(message = "主键不能为空")
|
||||
@PathVariable Long[] ids) {
|
||||
public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
|
||||
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
|
||||
*/
|
||||
@Validated
|
||||
*/@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/dev/schemaField")
|
||||
public class SchemaFieldController extends BaseController {
|
||||
|
||||
private final ISchemaFieldService schemaFieldService;
|
||||
|
||||
|
||||
/**
|
||||
* 查询数据模型字段列表
|
||||
*/
|
||||
|
||||
@@ -26,6 +26,7 @@ import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 数据模型字段Service业务层处理
|
||||
@@ -53,15 +54,17 @@ public class SchemaFieldServiceImpl implements ISchemaFieldService {
|
||||
*/
|
||||
@Override
|
||||
public TableDataInfo<SchemaFieldVo> queryPageList(SchemaFieldBo bo, PageQuery pageQuery) {
|
||||
if (Objects.isNull(bo.getSchemaId())) {
|
||||
return TableDataInfo.build();
|
||||
}
|
||||
LambdaQueryWrapper<SchemaField> lqw = buildQueryWrapper(bo);
|
||||
Page<SchemaFieldVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
||||
return TableDataInfo.build(result);
|
||||
}
|
||||
|
||||
private LambdaQueryWrapper<SchemaField> buildQueryWrapper(SchemaFieldBo bo) {
|
||||
|
||||
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.eq(StringUtils.isNotBlank(bo.getCode()), SchemaField::getCode, bo.getCode());
|
||||
lqw.eq(StringUtils.isNotBlank(bo.getType()), SchemaField::getType, bo.getType());
|
||||
|
||||
Reference in New Issue
Block a user