feat: 增加查询data表名和字段名

haikang
huangfeng 1 year ago
parent 758c963540
commit 0d5e1d4b73

@ -2,6 +2,7 @@ package com.xydl.cac.controller;
import com.xydl.cac.entity.IcdFileConfig; import com.xydl.cac.entity.IcdFileConfig;
import com.xydl.cac.model.Response; import com.xydl.cac.model.Response;
import com.xydl.cac.service.DataService;
import com.xydl.cac.service.IcdFileConfigService; import com.xydl.cac.service.IcdFileConfigService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
@ -24,6 +25,8 @@ public class IcdConfigController extends BasicController {
@Resource @Resource
IcdFileConfigService configService; IcdFileConfigService configService;
@Resource
DataService dataService;
@PostMapping("upload") @PostMapping("upload")
@ApiOperation("处理icd文件") @ApiOperation("处理icd文件")
@ -70,7 +73,7 @@ public class IcdConfigController extends BasicController {
} }
} }
@PostMapping("/delete") @PostMapping("delete")
@ApiOperation("删除ICD类型配置") @ApiOperation("删除ICD类型配置")
public Response<String> delete(@Validated @NotNull(message = "ID不能为空!") Integer id) { public Response<String> delete(@Validated @NotNull(message = "ID不能为空!") Integer id) {
try { try {
@ -81,4 +84,26 @@ public class IcdConfigController extends BasicController {
} }
} }
@GetMapping("tableList")
@ApiOperation("查询data表名")
public Response<List<String>> tableList() {
try {
List<String> result = dataService.getDataTables();
return Response.success(result);
} catch (Exception ex) {
return Response.fail(ex.getMessage());
}
}
@GetMapping("colList")
@ApiOperation("查询data表字段名")
public Response<List<String>> colList(String tableName) {
try {
List<String> result = dataService.getDataTableColumns(tableName);
return Response.success(result);
} catch (Exception ex) {
return Response.fail(ex.getMessage());
}
}
} }

@ -0,0 +1,11 @@
package com.xydl.cac.service;
import java.util.List;
public interface DataService {
List<String> getDataTables() throws Exception;
List<String> getDataTableColumns(String tableName) throws Exception;
}

@ -0,0 +1,49 @@
package com.xydl.cac.service.impl;
import com.xydl.cac.service.DataService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
@Service
@Slf4j
@Transactional(rollbackFor = Exception.class)
public class DataServiceImpl implements DataService {
@Resource
private JdbcTemplate jdbcTemplate;
@Override
public List<String> getDataTables() throws Exception {
List<String> tables = new ArrayList<>();
String sql = "SHOW TABLES";
List<String> list = jdbcTemplate.queryForList(sql, String.class);
for (String table : list) {
if (table.startsWith("data_")) {
tables.add(table);
}
}
return tables;
}
@Override
public List<String> getDataTableColumns(String tableName) throws Exception {
List<String> cols = new ArrayList<>();
String sql = "SELECT COLUMN_NAME FROM information_schema.columns WHERE TABLE_NAME='" + tableName + "'";
List<String> list = jdbcTemplate.queryForList(sql, String.class);
for (String col : list) {
if (!col.equals("id") && !col.equals("eqmid")
&& !col.equals("acquisitionTime") && !col.equals("d_time")
&& !col.equals("create_time") && !col.equals("update_time")
&& !col.equals("isupload")) {
cols.add(col);
}
}
return cols;
}
}
Loading…
Cancel
Save