From 0d5e1d4b73f86a4d9502e17520293c78de8ff62e Mon Sep 17 00:00:00 2001 From: huangfeng Date: Tue, 2 Jan 2024 16:39:33 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E6=9F=A5=E8=AF=A2dat?= =?UTF-8?q?a=E8=A1=A8=E5=90=8D=E5=92=8C=E5=AD=97=E6=AE=B5=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cac/controller/IcdConfigController.java | 27 +++++++++- .../com/xydl/cac/service/DataService.java | 11 +++++ .../cac/service/impl/DataServiceImpl.java | 49 +++++++++++++++++++ 3 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/xydl/cac/service/DataService.java create mode 100644 src/main/java/com/xydl/cac/service/impl/DataServiceImpl.java diff --git a/src/main/java/com/xydl/cac/controller/IcdConfigController.java b/src/main/java/com/xydl/cac/controller/IcdConfigController.java index a8a152c..220e377 100644 --- a/src/main/java/com/xydl/cac/controller/IcdConfigController.java +++ b/src/main/java/com/xydl/cac/controller/IcdConfigController.java @@ -2,6 +2,7 @@ package com.xydl.cac.controller; import com.xydl.cac.entity.IcdFileConfig; import com.xydl.cac.model.Response; +import com.xydl.cac.service.DataService; import com.xydl.cac.service.IcdFileConfigService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -24,6 +25,8 @@ public class IcdConfigController extends BasicController { @Resource IcdFileConfigService configService; + @Resource + DataService dataService; @PostMapping("upload") @ApiOperation("处理icd文件") @@ -70,7 +73,7 @@ public class IcdConfigController extends BasicController { } } - @PostMapping("/delete") + @PostMapping("delete") @ApiOperation("删除ICD类型配置") public Response delete(@Validated @NotNull(message = "ID不能为空!") Integer id) { try { @@ -81,4 +84,26 @@ public class IcdConfigController extends BasicController { } } + @GetMapping("tableList") + @ApiOperation("查询data表名") + public Response> tableList() { + try { + List result = dataService.getDataTables(); + return Response.success(result); + } catch (Exception ex) { + return Response.fail(ex.getMessage()); + } + } + + @GetMapping("colList") + @ApiOperation("查询data表字段名") + public Response> colList(String tableName) { + try { + List result = dataService.getDataTableColumns(tableName); + return Response.success(result); + } catch (Exception ex) { + return Response.fail(ex.getMessage()); + } + } + } diff --git a/src/main/java/com/xydl/cac/service/DataService.java b/src/main/java/com/xydl/cac/service/DataService.java new file mode 100644 index 0000000..22bfa9f --- /dev/null +++ b/src/main/java/com/xydl/cac/service/DataService.java @@ -0,0 +1,11 @@ +package com.xydl.cac.service; + + +import java.util.List; + +public interface DataService { + + List getDataTables() throws Exception; + + List getDataTableColumns(String tableName) throws Exception; +} diff --git a/src/main/java/com/xydl/cac/service/impl/DataServiceImpl.java b/src/main/java/com/xydl/cac/service/impl/DataServiceImpl.java new file mode 100644 index 0000000..9a213b2 --- /dev/null +++ b/src/main/java/com/xydl/cac/service/impl/DataServiceImpl.java @@ -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 getDataTables() throws Exception { + List tables = new ArrayList<>(); + String sql = "SHOW TABLES"; + List list = jdbcTemplate.queryForList(sql, String.class); + for (String table : list) { + if (table.startsWith("data_")) { + tables.add(table); + } + } + return tables; + } + + @Override + public List getDataTableColumns(String tableName) throws Exception { + List cols = new ArrayList<>(); + String sql = "SELECT COLUMN_NAME FROM information_schema.columns WHERE TABLE_NAME='" + tableName + "'"; + List 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; + } +}