pert: 调整查询data表字段返回

dev
huangfeng 1 year ago
parent a289642053
commit 6223612495

@ -2,6 +2,7 @@ package com.xydl.cac.controller;
import com.xydl.cac.entity.IcdConfigType;
import com.xydl.cac.entity.IcdConfigTypeAtt;
import com.xydl.cac.model.ColumnModel;
import com.xydl.cac.model.Response;
import com.xydl.cac.service.DataService;
import com.xydl.cac.service.IcdFileConfigService;
@ -85,8 +86,8 @@ public class IcdConfigController extends BasicController {
@GetMapping("colList")
@ApiOperation("查询data表字段名")
public Response<List<String>> colList(String tableName) throws Exception {
List<String> result = dataService.getDataTableColumns(tableName);
public Response<List<ColumnModel>> colList(String tableName) throws Exception {
List<ColumnModel> result = dataService.getDataTableColumns(tableName);
return Response.success(result);
}

@ -0,0 +1,9 @@
package com.xydl.cac.model;
import lombok.Data;
@Data
public class ColumnModel {
private String name;
private String comment;
}

@ -11,7 +11,7 @@ public interface DataService {
List<String> getDataTables() throws Exception;
List<String> getDataTableColumns(String tableName) throws Exception;
List<ColumnModel> getDataTableColumns(String tableName) throws Exception;
OnePage<Map<String, Object>> getDate(NiecSensor sensor, List<NiecPoint> points, ConditionModel model);
}

@ -2,12 +2,14 @@ package com.xydl.cac.service.impl;
import com.xydl.cac.entity.NiecPoint;
import com.xydl.cac.entity.NiecSensor;
import com.xydl.cac.model.ColumnModel;
import com.xydl.cac.model.ConditionModel;
import com.xydl.cac.model.OnePage;
import com.xydl.cac.service.DataService;
import com.xydl.cac.util.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -41,23 +43,25 @@ public class DataServiceImpl implements DataService {
}
@Override
public List<String> getDataTableColumns(String tableName) throws Exception {
public List<ColumnModel> getDataTableColumns(String tableName) throws Exception {
if (StringUtils.isBlank(schema)) {
this.getDatabase();
}
List<String> cols = new ArrayList<>();
String sql = "SELECT COLUMN_NAME FROM information_schema.columns WHERE TABLE_NAME='" + tableName + "' AND TABLE_SCHEMA='" + schema + "'";
List<String> list = jdbcTemplate.queryForList(sql, String.class);
for (String col : list) {
List<ColumnModel> result = new ArrayList<>();
String sql = "SELECT COLUMN_NAME name, COLUMN_COMMENT comment FROM information_schema.columns WHERE TABLE_NAME='"
+ tableName + "' AND TABLE_SCHEMA='" + schema + "'";
List<ColumnModel> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(ColumnModel.class));
for (ColumnModel item : list) {
String col = item.getName();
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);
result.add(item);
}
}
return cols;
return result;
}
private void getDatabase() {

Loading…
Cancel
Save