增加可选高度的查询接口;增加项目文档
parent
6a5be20d82
commit
38312fe55b
@ -0,0 +1,62 @@
|
||||
package com.aliyun.tablestore.example.grid.common;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
|
||||
|
||||
public class TableStoreConf {
|
||||
|
||||
private String endpoint;
|
||||
private String accessId;
|
||||
private String accessKey;
|
||||
private String instanceName;
|
||||
|
||||
/**
|
||||
* 从目标配置文件中读取 数据库instance相关信息
|
||||
*/
|
||||
public static TableStoreConf newInstance(String path) {
|
||||
try {
|
||||
InputStream f = new FileInputStream(path);
|
||||
Gson gson = new Gson();
|
||||
return gson.fromJson(IOUtils.toString(f), TableStoreConf.class);
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public String getEndpoint() {
|
||||
return endpoint;
|
||||
}
|
||||
|
||||
public void setEndpoint(String endpoint) {
|
||||
this.endpoint = endpoint;
|
||||
}
|
||||
|
||||
public String getAccessId() {
|
||||
return accessId;
|
||||
}
|
||||
|
||||
public void setAccessId(String accessId) {
|
||||
this.accessId = accessId;
|
||||
}
|
||||
|
||||
public String getAccessKey() {
|
||||
return accessKey;
|
||||
}
|
||||
|
||||
public void setAccessKey(String accessKey) {
|
||||
this.accessKey = accessKey;
|
||||
}
|
||||
|
||||
public String getInstanceName() {
|
||||
return instanceName;
|
||||
}
|
||||
|
||||
public void setInstanceName(String instanceName) {
|
||||
this.instanceName = instanceName;
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package com.aliyun.tablestore.example.grid.common;
|
||||
|
||||
import com.aliyun.tablestore.grid.TableStoreGrid;
|
||||
import com.aliyun.tablestore.grid.TableStoreGridConfig;
|
||||
|
||||
public abstract class TableStoreGridExample {
|
||||
|
||||
protected TableStoreGrid tableStoreGrid;
|
||||
// private String pathSeperator = "/";
|
||||
|
||||
public TableStoreGridExample(String dataTableName, String metaTableName) {
|
||||
// String os = System.getProperty("os.name");
|
||||
// if (os.toLowerCase().startsWith("win")) {
|
||||
// pathSeparator = "\\";
|
||||
// }
|
||||
String pathSeparator = System.getProperty("file.separator");
|
||||
TableStoreConf conf = TableStoreConf.newInstance(System.getProperty("user.dir") + pathSeparator + "tablestoreConf.json");
|
||||
TableStoreGridConfig config = new TableStoreGridConfig();
|
||||
config.setTableStoreEndpoint(conf.getEndpoint());
|
||||
config.setAccessId(conf.getAccessId());
|
||||
config.setAccessKey(conf.getAccessKey());
|
||||
config.setTableStoreInstance(conf.getInstanceName());
|
||||
config.setDataTableName(dataTableName);
|
||||
config.setMetaTableName(metaTableName);
|
||||
tableStoreGrid = new TableStoreGrid(config);
|
||||
}
|
||||
|
||||
public void close() {
|
||||
if (tableStoreGrid != null) {
|
||||
tableStoreGrid.close();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package com.htfp.weather.web.controller;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
import com.htfp.weather.griddata.common.TableConfig;
|
||||
import com.htfp.weather.web.config.aspect.ControllerLog;
|
||||
import com.htfp.weather.web.exception.ErrorCode;
|
||||
import com.htfp.weather.web.param.response.LevelsAvailableResponse;
|
||||
import com.htfp.weather.web.param.response.LevelsAvailableResponse.LevelsAvailable;
|
||||
import com.htfp.weather.web.param.response.Result;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @Author : shiyi
|
||||
* @Date : 2024/4/21 15:56
|
||||
* @Description : 配置文件管理
|
||||
*/
|
||||
@CrossOrigin
|
||||
@RestController
|
||||
@Slf4j
|
||||
@RequestMapping("/htfp/weather/v1/info")
|
||||
public class InfoController {
|
||||
@Resource
|
||||
TableConfig tableConfig;
|
||||
|
||||
@PostMapping("/queryLevelsAvailable")
|
||||
@ControllerLog(info = "可选高度查询")
|
||||
public Result queryLevelsAvailable(Map<String, String> params) {
|
||||
String dataSource = params.get("dataSource");
|
||||
List<LevelsAvailable> levelsAvailableList = new ArrayList<>();
|
||||
if (StringUtils.isEmpty(dataSource)) {
|
||||
levelsAvailableList.add(
|
||||
new LevelsAvailable(
|
||||
"GFS",
|
||||
Ints.asList(tableConfig.getPressureList()),
|
||||
Ints.asList(tableConfig.getPressureHeightList()))
|
||||
);
|
||||
} else {
|
||||
if (dataSource.equals("GFS")) {
|
||||
levelsAvailableList = Collections.singletonList(
|
||||
new LevelsAvailable(
|
||||
"GFS",
|
||||
Ints.asList(tableConfig.getPressureList()),
|
||||
Ints.asList(tableConfig.getPressureHeightList()))
|
||||
);
|
||||
}
|
||||
}
|
||||
return Result.success(new LevelsAvailableResponse(levelsAvailableList));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue