feat: 更新代码生成功能-二阶段

This commit is contained in:
l90215
2025-07-22 18:50:37 +08:00
parent 8b3c0b4134
commit ffe4867d40
5 changed files with 43 additions and 18 deletions

View File

@@ -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;
}
}

View File

@@ -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());
}
}

View File

@@ -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());
}
}

View File

@@ -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;
/**
* 查询数据模型字段列表
*/

View File

@@ -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());