V0.0.1.241223 预发布测试:

1. 增加地面数据源切换;
2. 修改创建数据表静态操作
download
shiyi 6 months ago
parent 20c4a6ca41
commit 11d010ec1b

@ -50,25 +50,28 @@ public class TableStoreGrid implements GridStore {
} }
@Override @Override
public void createStore(TableOptions tableOptions) throws Exception { public void createStore(TableOptions tableOptions) throws Exception {
// create meta table this.tableOptions = tableOptions;
// create buffer table
try { try {
this.tableOptions = tableOptions; tableOptions.setAllowUpdate(true); // 数据表必须允许更新,否则无法导入数据
this.asyncClient.createTable(RequestBuilder.buildCreateMetaTableRequest(config.getMetaTableName(), tableOptions), null).get(); this.asyncClient.createTable(RequestBuilder.buildCreateDataTableRequest(config.getDataTableName(), tableOptions), null).get();
} catch (TableStoreException ex) { } catch (TableStoreException ex) {
if (!ex.getErrorCode().equals(ErrorCode.OBJECT_ALREADY_EXIST)) { if (!ex.getErrorCode().equals(ErrorCode.OBJECT_ALREADY_EXIST)) {
throw ex; throw ex;
} }
} }
// create buffer table // create meta table
try { try {
tableOptions.setAllowUpdate(false); // 禁止update操作 tableOptions.setAllowUpdate(false); // 属性表为了设置过期时间,禁止update操作只允许put操作
this.asyncClient.createTable(RequestBuilder.buildCreateDataTableRequest(config.getDataTableName(), tableOptions), null).get(); this.asyncClient.createTable(RequestBuilder.buildCreateMetaTableRequest(config.getMetaTableName(), tableOptions), null).get();
} catch (TableStoreException ex) { } catch (TableStoreException ex) {
if (!ex.getErrorCode().equals(ErrorCode.OBJECT_ALREADY_EXIST)) { if (!ex.getErrorCode().equals(ErrorCode.OBJECT_ALREADY_EXIST)) {
throw ex; throw ex;
} }
} }
} }
/** /**

@ -1,5 +1,7 @@
package com.aliyun.tablestore.grid.consts; package com.aliyun.tablestore.grid.consts;
import java.util.function.Consumer;
/** /**
* @Author : shiyi * @Author : shiyi
* @Date : 2024/5/8 15:27 * @Date : 2024/5/8 15:27

@ -66,7 +66,11 @@ public class TableConfig {
// private final String configPath = Objects.requireNonNull(this.getClass().getClassLoader().getResource("config/tableConf.json")).getPath(); // private final String configPath = Objects.requireNonNull(this.getClass().getClassLoader().getResource("config/tableConf.json")).getPath();
private final String configPath = System.getProperty("user.dir") +"/tableConf.json"; private final String configPath = System.getProperty("user.dir") +"/tableConf.json";
@PostConstruct @PostConstruct
public void initTableConfig() { public void init() {
if (dataConfig == null){
dataConfig = new GfsDataConfig();
dataConfig.init();
}
readConfig(); readConfig();
initLonList(); initLonList();
initLatList(); initLatList();

@ -17,11 +17,10 @@ import java.util.stream.Collectors;
/** /**
* @Author : shiyi * @Author : shiyi
* @Date : 2024/1/15 19:10 * @Date : 2024/1/15 19:10
* @Description : meta * @Description : meta
*/ */
@Slf4j @Component @Slf4j
public class TableConfigStatic { public class TableConfigStatic {
@Autowired
GfsDataConfig dataConfig; GfsDataConfig dataConfig;
/** /**
* index * index
@ -48,7 +47,6 @@ public class TableConfigStatic {
// 数据过期时间,单位为秒 // 数据过期时间,单位为秒
public static int TIME_TO_LIVE; public static int TIME_TO_LIVE;
@PostConstruct
private void initTableConfig() { private void initTableConfig() {
initDatasetConfig(); initDatasetConfig();
initLonList(); initLonList();

@ -1,9 +1,16 @@
package com.htfp.weather.griddata.common; package com.htfp.weather.griddata.common;
import com.google.gson.Gson;
import com.htfp.weather.utils.JSONUtils;
import lombok.Data; import lombok.Data;
import org.apache.commons.io.IOUtils;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import java.io.FileInputStream;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
@Data @Data
@Configuration("tableStoreConf") @Configuration("tableStoreConf")
@ConfigurationProperties("tablestore") @ConfigurationProperties("tablestore")
@ -12,4 +19,16 @@ public class TableStoreConf {
private String accessId; private String accessId;
private String accessKey; private String accessKey;
private String instanceName; private String instanceName;
public static TableStoreConf init() {
try {
String path = System.getProperty("user.dir") + "./tablestoreConf.json";
InputStream f = new FileInputStream(path);
String jsonStr = IOUtils.toString(f, StandardCharsets.UTF_8);
return JSONUtils.json2pojo(jsonStr, TableStoreConf.class);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
} }

@ -23,6 +23,13 @@ public abstract class BaseTableOperation{
@PostConstruct @PostConstruct
public void init() { public void init() {
TableStoreGridConfig config = new TableStoreGridConfig(); TableStoreGridConfig config = new TableStoreGridConfig();
if (tableStoreConf == null){
tableStoreConf = TableStoreConf.init();
}
if (tableConfig == null) {
tableConfig = new TableConfig();
tableConfig.init();
}
config.setTableStoreEndpoint(tableStoreConf.getEndpoint()); config.setTableStoreEndpoint(tableStoreConf.getEndpoint());
config.setAccessId(tableStoreConf.getAccessId()); config.setAccessId(tableStoreConf.getAccessId());
config.setAccessKey(tableStoreConf.getAccessKey()); config.setAccessKey(tableStoreConf.getAccessKey());

@ -4,10 +4,13 @@ import com.alicloud.openservices.tablestore.model.TableOptions;
import com.alicloud.openservices.tablestore.model.search.FieldSchema; import com.alicloud.openservices.tablestore.model.search.FieldSchema;
import com.alicloud.openservices.tablestore.model.search.FieldType; import com.alicloud.openservices.tablestore.model.search.FieldType;
import com.alicloud.openservices.tablestore.model.search.IndexSchema; import com.alicloud.openservices.tablestore.model.search.IndexSchema;
import com.aliyun.tablestore.grid.consts.AttributionEnum;
import com.htfp.weather.griddata.common.TableConfigStatic; import com.htfp.weather.griddata.common.TableConfigStatic;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
/** /**
* @Author : shiyi * @Author : shiyi
@ -33,19 +36,24 @@ public class CreateTable extends BaseTableOperation {
*/ */
private void createIndex() throws Exception { private void createIndex() throws Exception {
IndexSchema indexSchema = new IndexSchema(); IndexSchema indexSchema = new IndexSchema();
indexSchema.setFieldSchemas(Arrays.asList( AttributionEnum[] values = AttributionEnum.values();
new FieldSchema("status", FieldType.KEYWORD).setIndex(true).setEnableSortAndAgg(true), ArrayList<FieldSchema> fieldSchemas = new ArrayList<>();
new FieldSchema("create_time", FieldType.LONG).setIndex(true).setEnableSortAndAgg(true), for (AttributionEnum attributionEnum : values) {
new FieldSchema("ref_time", FieldType.LONG).setIndex(true).setEnableSortAndAgg(true) fieldSchemas.add(new FieldSchema(attributionEnum.getName(), FieldType.KEYWORD).setIndex(true).setEnableSortAndAgg(true));
)); }
indexSchema.setFieldSchemas(fieldSchemas);
this.tableStoreGrid.createMetaIndex(TableConfigStatic.META_INDEX_NAME, indexSchema); this.tableStoreGrid.createMetaIndex(TableConfigStatic.META_INDEX_NAME, indexSchema);
} }
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
TableConfigStatic.initDatasetConfig();
CreateTable example = new CreateTable(); CreateTable example = new CreateTable();
example.init();
try { try {
example.createStore(); example.createStore();
example.createIndex(); example.createIndex();
} catch (Exception e) {
e.printStackTrace();
} finally { } finally {
example.close(); example.close();
} }

@ -47,7 +47,7 @@ public class GfsDataFetcher extends BaseTableOperation {
public GridDataSetMeta getLastGridDataSetMeta() { public GridDataSetMeta getLastGridDataSetMeta() {
if (lastGridDataSetMeta == null) { if (lastGridDataSetMeta == null) {
updateLastGridDataSetMeta(); updateLastGridDataSetMeta();
throw new AppException(ErrorCode.DATA_SET_EMPTY, ": e.getMessage()"); throw new AppException(ErrorCode.DATA_SET_EMPTY);
} }
return lastGridDataSetMeta; return lastGridDataSetMeta;
} }

@ -17,6 +17,7 @@ import lombok.Getter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.DependsOn; import org.springframework.context.annotation.DependsOn;
import org.springframework.context.annotation.Description;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import ucar.ma2.*; import ucar.ma2.*;
@ -26,6 +27,7 @@ import ucar.nc2.Variable;
import javax.annotation.PreDestroy; import javax.annotation.PreDestroy;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.annotation.security.DenyAll;
import java.io.File; import java.io.File;
import java.time.OffsetDateTime; import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
@ -78,18 +80,6 @@ public class GfsDataImport extends BaseTableOperation {
return meta; return meta;
} }
/**
* meta
*
* @param meta
* @return
* @throws Exception
*/
public GridDataSetMeta updateMeta(GridDataSetMeta meta) throws Exception {
tableStoreGrid.updateDataSetMeta(meta);
return meta;
}
/** /**
* meta * meta
*/ */

@ -0,0 +1,15 @@
package com.htfp.weather.web.config;
import com.htfp.weather.web.exception.AppException;
import com.htfp.weather.web.exception.ErrorCode;
import org.apache.commons.lang3.StringUtils;
public class Config {
public static final String SECRET = "htfpweather";
public static void validSecret(String secret) {
if (StringUtils.isEmpty(secret) || !SECRET.equals(secret)) {
throw new AppException(ErrorCode.SECRET_ERROR);
}
}
}

@ -7,6 +7,7 @@ import com.htfp.weather.griddata.operation.GfsDataImport;
import com.htfp.weather.griddata.operation.GfsDataImport.ImportFileInfo; import com.htfp.weather.griddata.operation.GfsDataImport.ImportFileInfo;
import com.htfp.weather.info.Constant; import com.htfp.weather.info.Constant;
import com.htfp.weather.utils.DateTimeUtils; import com.htfp.weather.utils.DateTimeUtils;
import com.htfp.weather.web.config.Config;
import com.htfp.weather.web.config.aspect.ControllerLog; import com.htfp.weather.web.config.aspect.ControllerLog;
import com.htfp.weather.web.exception.AppException; import com.htfp.weather.web.exception.AppException;
import com.htfp.weather.web.exception.ErrorCode; import com.htfp.weather.web.exception.ErrorCode;
@ -52,14 +53,18 @@ public class ConfigController {
FileService fileService; FileService fileService;
@Resource @Resource
GfsDataServiceImpl gfsDataService; GfsDataServiceImpl gfsDataService;
private final String SECRET = "htfpweather";
private void validSecret(String secret) { @Resource
if (StringUtils.isEmpty(secret) || !SECRET.equals(secret)) { SurfaceWeatherController surfaceWeatherController;
throw new AppException(ErrorCode.SECRET_ERROR); @PostMapping("/switchSurfaceDataSource")
public Result switchService(@RequestBody Map<String, String> params) {
Config.validSecret(params.get("secret"));
String dataSource = params.get("dataSource");
if (StringUtils.isEmpty(dataSource)) {
return Result.error(ErrorCode.VALIDATE_ERROR, "dataSource不能为空");
} }
return surfaceWeatherController.switchSurfaceDataSource(dataSource);
} }
/** /**
* tablestore * tablestore
*/ */
@ -77,7 +82,7 @@ public class ConfigController {
public Result updateDatabaseConfig(@RequestBody TableConfigUpdate request) { public Result updateDatabaseConfig(@RequestBody TableConfigUpdate request) {
String secret = request.getSecret(); String secret = request.getSecret();
TableConfig updateConfig = request.getConfig(); TableConfig updateConfig = request.getConfig();
validSecret(secret); Config.validSecret(secret);
if (updateConfig == null) { if (updateConfig == null) {
throw new AppException(ErrorCode.CONFIG_ERROR, "配置文件不能为空"); throw new AppException(ErrorCode.CONFIG_ERROR, "配置文件不能为空");
} }
@ -107,7 +112,7 @@ public class ConfigController {
public Result updateDataSourceConfig(@Validated @RequestBody GfsConfigUpdate request) { public Result updateDataSourceConfig(@Validated @RequestBody GfsConfigUpdate request) {
String secret = request.getSecret(); String secret = request.getSecret();
GfsDataConfig updateConfig = request.getConfig(); GfsDataConfig updateConfig = request.getConfig();
validSecret(secret); Config.validSecret(secret);
if (updateConfig == null) { if (updateConfig == null) {
throw new AppException(ErrorCode.CONFIG_ERROR, "配置文件不能为空"); throw new AppException(ErrorCode.CONFIG_ERROR, "配置文件不能为空");
} }
@ -127,7 +132,7 @@ public class ConfigController {
@ControllerLog(info = "下载当前时刻未来24小时的数据文件") @ControllerLog(info = "下载当前时刻未来24小时的数据文件")
public Result downloadAllFiles(@RequestBody Map<String, String> params) { public Result downloadAllFiles(@RequestBody Map<String, String> params) {
String secret = params.get("secret"); String secret = params.get("secret");
validSecret(secret); Config.validSecret(secret);
// List<FileInfo> allCompleted = false; // List<FileInfo> allCompleted = false;
try { try {
DownloadResult data = gfsDataService.downloadNowAllFile(); DownloadResult data = gfsDataService.downloadNowAllFile();
@ -149,7 +154,7 @@ public class ConfigController {
@ControllerLog(info = "下载指定时刻文件") @ControllerLog(info = "下载指定时刻文件")
public Result downloadSingleFile(@RequestBody Map<String, String> params) { public Result downloadSingleFile(@RequestBody Map<String, String> params) {
String secret = params.get("secret"); String secret = params.get("secret");
validSecret(secret); Config.validSecret(secret);
OffsetDateTime offsetDateTime = OffsetDateTime.parse(params.get("time"), Constant.API_TIME_FORMATTER); OffsetDateTime offsetDateTime = OffsetDateTime.parse(params.get("time"), Constant.API_TIME_FORMATTER);
DownLoadFileInfo downLoadFileInfo = gfsDataService.downloadSingleFile(offsetDateTime); DownLoadFileInfo downLoadFileInfo = gfsDataService.downloadSingleFile(offsetDateTime);
return Result.success(downLoadFileInfo); return Result.success(downLoadFileInfo);
@ -162,7 +167,7 @@ public class ConfigController {
@ControllerLog(info = "根据起报时间将数据导入数据库") @ControllerLog(info = "根据起报时间将数据导入数据库")
public Result importData(@RequestBody Map<String, String> params) { public Result importData(@RequestBody Map<String, String> params) {
String secret = params.get("secret"); String secret = params.get("secret");
validSecret(secret); Config.validSecret(secret);
OffsetDateTime time = OffsetDateTime.parse(params.get("time"), Constant.API_TIME_FORMATTER); OffsetDateTime time = OffsetDateTime.parse(params.get("time"), Constant.API_TIME_FORMATTER);
return getImportResponse(time); return getImportResponse(time);
} }
@ -205,7 +210,7 @@ public class ConfigController {
@ControllerLog(info = "查询所有数据文件夹") @ControllerLog(info = "查询所有数据文件夹")
public Result queryAllDataDir(@RequestBody Map<String, String> params) { public Result queryAllDataDir(@RequestBody Map<String, String> params) {
String secret = params.get("secret"); String secret = params.get("secret");
validSecret(secret); Config.validSecret(secret);
File dataRoot = new File(gfsDataConfig.getSaveRoot()); File dataRoot = new File(gfsDataConfig.getSaveRoot());
List<String> subDirList = fileService.getSubDirList(dataRoot); List<String> subDirList = fileService.getSubDirList(dataRoot);
return Result.success(subDirList); return Result.success(subDirList);
@ -218,7 +223,7 @@ public class ConfigController {
@ControllerLog(info = "查询指定起报时间文件夹中的所有文件名") @ControllerLog(info = "查询指定起报时间文件夹中的所有文件名")
public Result queryAllFileByReferenceTime(@RequestBody Map<String, String> params) { public Result queryAllFileByReferenceTime(@RequestBody Map<String, String> params) {
String secret = params.get("secret"); String secret = params.get("secret");
validSecret(secret); Config.validSecret(secret);
OffsetDateTime time = OffsetDateTime.parse(params.get("time"), Constant.API_TIME_FORMATTER); OffsetDateTime time = OffsetDateTime.parse(params.get("time"), Constant.API_TIME_FORMATTER);
String timeStr = DateTimeUtils.getUTCDateTime(time).format(DateTimeFormatter.ofPattern(Constant.DATA_FOLDER_STRING)); String timeStr = DateTimeUtils.getUTCDateTime(time).format(DateTimeFormatter.ofPattern(Constant.DATA_FOLDER_STRING));
File dataDir = new File(gfsDataConfig.getSaveRoot(), timeStr); File dataDir = new File(gfsDataConfig.getSaveRoot(), timeStr);
@ -235,7 +240,7 @@ public class ConfigController {
@ControllerLog(info = "删除指定起报时间对应的文件夹") @ControllerLog(info = "删除指定起报时间对应的文件夹")
public Result deleteDirByReferenceTime(@RequestBody Map<String, String> params) { public Result deleteDirByReferenceTime(@RequestBody Map<String, String> params) {
String secret = params.get("secret"); String secret = params.get("secret");
validSecret(secret); Config.validSecret(secret);
OffsetDateTime time = OffsetDateTime.parse(params.get("time"), Constant.API_TIME_FORMATTER); OffsetDateTime time = OffsetDateTime.parse(params.get("time"), Constant.API_TIME_FORMATTER);
String timeStr = DateTimeUtils.getUTCDateTime(time).format(DateTimeFormatter.ofPattern(Constant.DATA_FOLDER_STRING)); String timeStr = DateTimeUtils.getUTCDateTime(time).format(DateTimeFormatter.ofPattern(Constant.DATA_FOLDER_STRING));
File dataDir = new File(gfsDataConfig.getSaveRoot(), timeStr); File dataDir = new File(gfsDataConfig.getSaveRoot(), timeStr);
@ -257,7 +262,7 @@ public class ConfigController {
@ControllerLog(info = "删除指定文件") @ControllerLog(info = "删除指定文件")
public Result deleteTargetFile(@RequestBody Map<String, String> params) { public Result deleteTargetFile(@RequestBody Map<String, String> params) {
String secret = params.get("secret"); String secret = params.get("secret");
validSecret(secret); Config.validSecret(secret);
String filePath = params.get("filePath"); String filePath = params.get("filePath");
File file = new File(filePath); File file = new File(filePath);
if (gfsDataImport.isImporting()) { if (gfsDataImport.isImporting()) {

@ -1,21 +1,22 @@
package com.htfp.weather.web.controller; package com.htfp.weather.web.controller;
import com.htfp.weather.web.config.aspect.ControllerLog; import com.htfp.weather.web.config.aspect.ControllerLog;
import com.htfp.weather.web.pojo.hefeng.HeFengWarningResponse; import com.htfp.weather.web.exception.ErrorCode;
import com.htfp.weather.web.pojo.request.Position2D; import com.htfp.weather.web.pojo.request.Position2D;
import com.htfp.weather.web.pojo.response.NowWeatherStatus; import com.htfp.weather.web.pojo.response.NowWeatherStatus;
import com.htfp.weather.web.pojo.response.Result; import com.htfp.weather.web.pojo.response.Result;
import com.htfp.weather.web.pojo.response.SurfaceWeatherWarning; import com.htfp.weather.web.pojo.response.SurfaceWeatherWarning;
import com.htfp.weather.web.pojo.response.TimeSeriesDataset; import com.htfp.weather.web.pojo.response.TimeSeriesDataset;
import com.htfp.weather.web.service.GfsDataServiceImpl;
import com.htfp.weather.web.service.surfaceapi.CaiYunServiceImpl; import com.htfp.weather.web.service.surfaceapi.CaiYunServiceImpl;
import com.htfp.weather.web.service.surfaceapi.CmaServiceImpl; import com.htfp.weather.web.service.surfaceapi.CmaServiceImpl;
import com.htfp.weather.web.service.surfaceapi.HeFengServiceImpl; import com.htfp.weather.web.service.surfaceapi.HeFengServiceImpl;
import com.htfp.weather.web.service.IDataService;
import com.htfp.weather.web.service.surfaceapi.ISurfaceDataService; import com.htfp.weather.web.service.surfaceapi.ISurfaceDataService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.PostConstruct;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List; import java.util.List;
@ -29,11 +30,32 @@ import java.util.List;
@Slf4j @Slf4j
@RequestMapping("/htfp/weather/surface/") @RequestMapping("/htfp/weather/surface/")
public class SurfaceWeatherController { public class SurfaceWeatherController {
@Resource(name = "hefeng")
ISurfaceDataService surfaceDataService;
@Resource @Resource
CmaServiceImpl cmaService; CmaServiceImpl cmaService;
@Resource
HeFengServiceImpl heFengService;
@Resource
CaiYunServiceImpl caiYunService;
@Resource
GfsDataServiceImpl gfsDataService;
ISurfaceDataService service;
@PostConstruct
public void init() {
service = gfsDataService;
}
public Result switchSurfaceDataSource(String dataSource) {
switch (dataSource.toLowerCase()) {
case "hefeng":
service = heFengService;
return Result.success();
case "caiyun":
service = caiYunService;
return Result.success();
default:
return Result.error(ErrorCode.VALIDATE_ERROR, "未知数据源");
}
}
@PostMapping("/querySurfaceNowWeather") @PostMapping("/querySurfaceNowWeather")
@ControllerLog(info = "地面实时气象信息查询") @ControllerLog(info = "地面实时气象信息查询")
@ -41,9 +63,10 @@ public class SurfaceWeatherController {
double lat = position2D.getLatitude(); double lat = position2D.getLatitude();
double lon = position2D.getLongitude(); double lon = position2D.getLongitude();
NowWeatherStatus nowWeatherStatus = surfaceDataService.getNowSurfaceWeatherStatus(lat, lon); NowWeatherStatus nowWeatherStatus = service.getNowSurfaceWeatherStatus(lat, lon);
nowWeatherStatus.setLatitude(lat); nowWeatherStatus.setLatitude(lat);
nowWeatherStatus.setLongitude(lon); nowWeatherStatus.setLongitude(lon);
nowWeatherStatus.setDataSource(service.getDataSource());
return Result.success(nowWeatherStatus); return Result.success(nowWeatherStatus);
} }
@ -53,9 +76,10 @@ public class SurfaceWeatherController {
double lat = position2D.getLatitude(); double lat = position2D.getLatitude();
double lon = position2D.getLongitude(); double lon = position2D.getLongitude();
TimeSeriesDataset forecastSeries = surfaceDataService.getForecastSeries(lat, lon); TimeSeriesDataset forecastSeries = service.getForecastSeries(lat, lon);
forecastSeries.setLatitude(lat); forecastSeries.setLatitude(lat);
forecastSeries.setLongitude(lon); forecastSeries.setLongitude(lon);
forecastSeries.setDataSource(service.getDataSource());
return Result.success(forecastSeries); return Result.success(forecastSeries);
} }

@ -1,29 +0,0 @@
package com.htfp.weather.web.controller;
import com.htfp.weather.griddata.common.TableConfig;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import javax.annotation.Resource;
/**
* @Author : shiyi
* @Date : 2024/4/20 17:30
* @Description :
*/
@Controller
public class ThymeleafTest {
@Resource
TableConfig tableConfig;
@GetMapping("index")// 页面的url地址
public String getindex(Model model, String secret) {
if (!"shiyi".equals(secret)){
return "wrong";
}
model.addAttribute("tableConfig", tableConfig);
return "index";// 与templates中index.html对应
}
}

@ -23,4 +23,5 @@ public class NowWeatherStatus {
// Float pressure; // 大气压强,默认单位:百帕 // Float pressure; // 大气压强,默认单位:百帕
Float cloud; // 云量 Float cloud; // 云量
Float precip; //降水量 Float precip; //降水量
String dataSource;
} }

@ -25,7 +25,7 @@ public class TimeSeriesDataset {
// float[] pressure; // float[] pressure;
float[] cloud; float[] cloud;
float[] precip; float[] precip;
String dataSource;
public TimeSeriesDataset() {} public TimeSeriesDataset() {}
public TimeSeriesDataset(int size) { public TimeSeriesDataset(int size) {
time = new ArrayList<>(size); time = new ArrayList<>(size);

@ -19,6 +19,7 @@ import com.htfp.weather.utils.MeteoUtils;
import com.htfp.weather.web.exception.AppException; import com.htfp.weather.web.exception.AppException;
import com.htfp.weather.web.exception.ErrorCode; import com.htfp.weather.web.exception.ErrorCode;
import com.htfp.weather.web.pojo.response.*; import com.htfp.weather.web.pojo.response.*;
import com.htfp.weather.web.service.surfaceapi.ISurfaceDataService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.A; import org.checkerframework.checker.units.qual.A;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -26,6 +27,7 @@ import ucar.ma2.Array;
import ucar.ma2.Index4D; import ucar.ma2.Index4D;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.annotation.security.DenyAll;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.time.Instant; import java.time.Instant;
import java.time.OffsetDateTime; import java.time.OffsetDateTime;
@ -41,7 +43,7 @@ import java.util.stream.Collectors;
*/ */
@Service("tablestore-gfs") @Service("tablestore-gfs")
@Slf4j @Slf4j
public class GfsDataServiceImpl implements IDataService { public class GfsDataServiceImpl implements IDataService, ISurfaceDataService {
@Resource @Resource
GfsDataFetcher gfsDataFetcher; GfsDataFetcher gfsDataFetcher;
@Resource @Resource
@ -50,6 +52,30 @@ public class GfsDataServiceImpl implements IDataService {
GfsDownloader gfsDownloader; GfsDownloader gfsDownloader;
@Resource @Resource
GfsDataImport gfsDataImport; GfsDataImport gfsDataImport;
@Override
public String getDataSource() {
return dataSource;
}
String dataSource = "GFS";
// 地面站数据访问接口
@Override
public NowWeatherStatus getNowSurfaceWeatherStatus(double lat, double lon) throws Exception {
return getNowWeather(GfsLevelsEnum.SURFACE.getCode(), lat, lon);
}
@Override
public TimeSeriesDataset getForecastSeries(double lat, double lon) throws Exception {
return getForecastSeries(GfsLevelsEnum.SURFACE.getCode(), lat, lon);
}
@Override @DenyAll
public List<SurfaceWeatherWarning> getSurfaceWarning(double lat, double lon) throws Exception {
return null;
}
// 下载和导入数据 // 下载和导入数据
public DownloadResult downloadNowAllFile() { public DownloadResult downloadNowAllFile() {
gfsDownloader.iniTimeSetting(); gfsDownloader.iniTimeSetting();
@ -94,9 +120,6 @@ public class GfsDataServiceImpl implements IDataService {
return importResult; return importResult;
} }
public void downloadAndImportData() {
}
// 从tablestore获取数据 // 从tablestore获取数据

@ -31,9 +31,14 @@ import static com.htfp.weather.utils.HttpClientUtils.sendGet;
*/ */
@Service("caiyun") @Slf4j @Service("caiyun") @Slf4j
public class CaiYunServiceImpl implements ISurfaceDataService { public class CaiYunServiceImpl implements ISurfaceDataService {
String dataSource = "CaiYun";
@Value("${caiyun.key}") @Value("${caiyun.key}")
private String key; private String key;
static final String STATUS_OK = "ok"; static final String STATUS_OK = "ok";
@Override
public String getDataSource() {
return dataSource;
}
public <T extends CaiYunBaseResponse> T caiYunRequest(String url, HashMap<String, String> params, Class<T> responseClass) { public <T extends CaiYunBaseResponse> T caiYunRequest(String url, HashMap<String, String> params, Class<T> responseClass) {
params.put("units", "metric:v2"); params.put("units", "metric:v2");
try { try {

@ -37,10 +37,15 @@ import static com.htfp.weather.utils.HttpClientUtils.sendGet;
@Slf4j @Slf4j
@Service("cma") @Service("cma")
public class CmaServiceImpl implements ISurfaceDataService{ public class CmaServiceImpl implements ISurfaceDataService{
String dataSource = "CMA";
@Value("${tianditu.key}") @Setter @Value("${tianditu.key}") @Setter
private String keyOfTianDiTu; private String keyOfTianDiTu;
private Map<String, List<SurfaceWeatherWarning>> warningCache = new ConcurrentHashMap<>(); private Map<String, List<SurfaceWeatherWarning>> warningCache = new ConcurrentHashMap<>();
@Override
public String getDataSource() {
return dataSource;
}
@Override @Override
public NowWeatherStatus getNowSurfaceWeatherStatus(double lat, double lon) throws Exception { public NowWeatherStatus getNowSurfaceWeatherStatus(double lat, double lon) throws Exception {
return null; return null;

@ -34,6 +34,7 @@ import static com.htfp.weather.utils.HttpClientUtils.*;
@Service("hefeng") @Service("hefeng")
@Slf4j @Slf4j
public class HeFengServiceImpl implements ISurfaceDataService { public class HeFengServiceImpl implements ISurfaceDataService {
String dataSource = "HeFeng";
@Value("${hefeng.key}") @Value("${hefeng.key}")
private String key; private String key;
private final HashMap<String, String> variableNameMap = private final HashMap<String, String> variableNameMap =
@ -49,7 +50,10 @@ public class HeFengServiceImpl implements ISurfaceDataService {
}}; }};
static final String STATUS_OK = "200"; static final String STATUS_OK = "200";
static final String STATUS_NO_DATA = "204"; static final String STATUS_NO_DATA = "204";
@Override
public String getDataSource() {
return dataSource;
}
public <T extends HeFengBaseResponse> T heFengRequest(String url, HashMap<String, String> params, Class<T> responseClass) throws Exception { public <T extends HeFengBaseResponse> T heFengRequest(String url, HashMap<String, String> params, Class<T> responseClass) throws Exception {
// String signature = getSignature(params, key); // String signature = getSignature(params, key);
// HashMap<String, String> params = new HashMap<>(); // HashMap<String, String> params = new HashMap<>();

@ -12,6 +12,7 @@ import java.util.List;
* @Description : * @Description :
*/ */
public interface ISurfaceDataService { public interface ISurfaceDataService {
String getDataSource();
NowWeatherStatus getNowSurfaceWeatherStatus(double lat, double lon) throws Exception; NowWeatherStatus getNowSurfaceWeatherStatus(double lat, double lon) throws Exception;
TimeSeriesDataset getForecastSeries(double lat, double lon) throws Exception; TimeSeriesDataset getForecastSeries(double lat, double lon) throws Exception;

@ -4,11 +4,11 @@ hefeng:
caiyun: caiyun:
key: Tc9tgOYr5jlPPlEw key: Tc9tgOYr5jlPPlEw
tianditu: tianditu:
key: 86c4d7e4084ee8bf162a1fe9b62d982e key: 26b108f24d9d0e7337a39e84200e59d3
# tablestore # tablestore
tablestore: tablestore:
endpoint: https://gfs-test.cn-hangzhou.ots.aliyuncs.com endpoint: https://gfs25km.cn-hangzhou.ots.aliyuncs.com
accessId: LTAI5tDphvXLfwKJEmVQqrVz accessId: LTAI5tH1nLqUgyvEpEgNVJwp
accessKey: ksioVP1S36PI6plkIIRN4A2xLB94uc accessKey: f5YXyvIqdDfd4yvYj8DVSzNry6RmA0
instanceName: gfs-test instanceName: gfs25km

@ -6,9 +6,9 @@ spring:
mvc: mvc:
servlet: servlet:
load-on-startup: 1 # 关闭 dispatcherServlet懒加载 load-on-startup: 1 # 关闭 dispatcherServlet懒加载
thymeleaf: # thymeleaf:
cache: false # cache: false
encoding: UTF-8 # encoding: UTF-8
mail: mail:
host: smtp.exmail.qq.com host: smtp.exmail.qq.com
username: shiyi@htsdfp.com username: shiyi@htsdfp.com

@ -1,6 +0,0 @@
<html>
<body>
<h1>hello word!!!</h1>
<p>this is a html page</p>
</body>
</html>

@ -1,60 +0,0 @@
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body class="container">
<br/>
<h1> Tablestore 表格存储配置信息</h1>
<br/><br/>
<div class="with:80%" >
<table class="tftable" border="1">
<tr>
<td>数据表名称</td> <td th:text="${tableConfig.dataTableName}">dataTableName</td>
</tr>
<tr>
<td>属性表名称</td> <td th:text="${tableConfig.metaTableName}">metaTableName</td>
</tr>
<tr>
<td>数据索引名称</td> <td th:text="${tableConfig.dataIndexName}">dataIndexName</td>
</tr>
<tr>
<td>属性索引名称</td> <td th:text="${tableConfig.metaIndexName}">metaIndexName</td>
</tr>
<tr>
<td>数据存储路径根目录</td> <td th:text="${tableConfig.dataDir}">dataDir</td> <td><a th:href="@{/toEdit(dataDir=${tableConfig.dataDir})}">edit</a></td>
</tr>
<tr>
<td>纬度网格数</td> <td th:text="${tableConfig.latSize}">latSize</td>
</tr>
<tr>
<td>经度网格数</td> <td th:text="${tableConfig.lonSize}">lonSize</td>
</tr>
<tr>
<td>高度层数</td> <td th:text="${tableConfig.levSize}">levSize</td>
</tr>
</table>
</div>
<!-- Row Highlight Javascript -->
<script type="text/javascript">
window.onload=function(){
var tfrow = document.getElementById('tfhover').rows.length;
var tbRow=[];
for (var i=1;i<tfrow;i++) {
tbRow[i]=document.getElementById('tfhover').rows[i];
tbRow[i].onmouseover = function(){
this.style.backgroundColor = '#ffffff';
};
tbRow[i].onmouseout = function() {
this.style.backgroundColor = '#d4e3e5';
};
}
};
</script>
</body>
</html>

@ -1,10 +0,0 @@
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
请求错误
</body>
</html>
Loading…
Cancel
Save