feat: 增加查询data表名和字段名
parent
758c963540
commit
0d5e1d4b73
@ -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…
Reference in New Issue