diff --git a/tablestore-grid-master/src/main/java/com/aliyun/tablestore/grid/TableStoreGrid.java b/tablestore-grid-master/src/main/java/com/aliyun/tablestore/grid/TableStoreGrid.java index ff671e2..67a2937 100644 --- a/tablestore-grid-master/src/main/java/com/aliyun/tablestore/grid/TableStoreGrid.java +++ b/tablestore-grid-master/src/main/java/com/aliyun/tablestore/grid/TableStoreGrid.java @@ -50,25 +50,28 @@ public class TableStoreGrid implements GridStore { } @Override public void createStore(TableOptions tableOptions) throws Exception { - // create meta table + this.tableOptions = tableOptions; + // create buffer table try { - this.tableOptions = tableOptions; - this.asyncClient.createTable(RequestBuilder.buildCreateMetaTableRequest(config.getMetaTableName(), tableOptions), null).get(); + tableOptions.setAllowUpdate(true); // 数据表必须允许更新,否则无法导入数据 + this.asyncClient.createTable(RequestBuilder.buildCreateDataTableRequest(config.getDataTableName(), tableOptions), null).get(); } catch (TableStoreException ex) { if (!ex.getErrorCode().equals(ErrorCode.OBJECT_ALREADY_EXIST)) { throw ex; } } - // create buffer table + // create meta table try { - tableOptions.setAllowUpdate(false); // 禁止update操作 - this.asyncClient.createTable(RequestBuilder.buildCreateDataTableRequest(config.getDataTableName(), tableOptions), null).get(); + tableOptions.setAllowUpdate(false); // 属性表为了设置过期时间,禁止update操作,只允许put操作 + this.asyncClient.createTable(RequestBuilder.buildCreateMetaTableRequest(config.getMetaTableName(), tableOptions), null).get(); } catch (TableStoreException ex) { if (!ex.getErrorCode().equals(ErrorCode.OBJECT_ALREADY_EXIST)) { throw ex; } } + + } /** diff --git a/tablestore-grid-master/src/main/java/com/aliyun/tablestore/grid/consts/AttributionEnum.java b/tablestore-grid-master/src/main/java/com/aliyun/tablestore/grid/consts/AttributionEnum.java index 7528b89..2e049d7 100644 --- a/tablestore-grid-master/src/main/java/com/aliyun/tablestore/grid/consts/AttributionEnum.java +++ b/tablestore-grid-master/src/main/java/com/aliyun/tablestore/grid/consts/AttributionEnum.java @@ -1,5 +1,7 @@ package com.aliyun.tablestore.grid.consts; +import java.util.function.Consumer; + /** * @Author : shiyi * @Date : 2024/5/8 15:27 diff --git a/weather-service/src/main/java/com/htfp/weather/griddata/common/TableConfig.java b/weather-service/src/main/java/com/htfp/weather/griddata/common/TableConfig.java index be5f7ad..ca1b226 100644 --- a/weather-service/src/main/java/com/htfp/weather/griddata/common/TableConfig.java +++ b/weather-service/src/main/java/com/htfp/weather/griddata/common/TableConfig.java @@ -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 = System.getProperty("user.dir") +"/tableConf.json"; @PostConstruct - public void initTableConfig() { + public void init() { + if (dataConfig == null){ + dataConfig = new GfsDataConfig(); + dataConfig.init(); + } readConfig(); initLonList(); initLatList(); diff --git a/weather-service/src/main/java/com/htfp/weather/griddata/common/TableConfigStatic.java b/weather-service/src/main/java/com/htfp/weather/griddata/common/TableConfigStatic.java index bcf7b63..bf303c6 100644 --- a/weather-service/src/main/java/com/htfp/weather/griddata/common/TableConfigStatic.java +++ b/weather-service/src/main/java/com/htfp/weather/griddata/common/TableConfigStatic.java @@ -17,11 +17,10 @@ import java.util.stream.Collectors; /** * @Author : shiyi * @Date : 2024/1/15 19:10 - * @Description : 表格meta配置 + * @Description : 表格meta配置, 仅用于表格创建 */ -@Slf4j @Component +@Slf4j public class TableConfigStatic { - @Autowired GfsDataConfig dataConfig; /** * 表名和index名 @@ -48,7 +47,6 @@ public class TableConfigStatic { // 数据过期时间,单位为秒 public static int TIME_TO_LIVE; - @PostConstruct private void initTableConfig() { initDatasetConfig(); initLonList(); diff --git a/weather-service/src/main/java/com/htfp/weather/griddata/common/TableStoreConf.java b/weather-service/src/main/java/com/htfp/weather/griddata/common/TableStoreConf.java index b221697..49b4a4c 100644 --- a/weather-service/src/main/java/com/htfp/weather/griddata/common/TableStoreConf.java +++ b/weather-service/src/main/java/com/htfp/weather/griddata/common/TableStoreConf.java @@ -1,9 +1,16 @@ package com.htfp.weather.griddata.common; +import com.google.gson.Gson; +import com.htfp.weather.utils.JSONUtils; import lombok.Data; +import org.apache.commons.io.IOUtils; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Configuration; +import java.io.FileInputStream; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; + @Data @Configuration("tableStoreConf") @ConfigurationProperties("tablestore") @@ -12,4 +19,16 @@ public class TableStoreConf { private String accessId; private String accessKey; 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); + } + } + } diff --git a/weather-service/src/main/java/com/htfp/weather/griddata/operation/BaseTableOperation.java b/weather-service/src/main/java/com/htfp/weather/griddata/operation/BaseTableOperation.java index 0228d41..21516b5 100644 --- a/weather-service/src/main/java/com/htfp/weather/griddata/operation/BaseTableOperation.java +++ b/weather-service/src/main/java/com/htfp/weather/griddata/operation/BaseTableOperation.java @@ -23,6 +23,13 @@ public abstract class BaseTableOperation{ @PostConstruct public void init() { TableStoreGridConfig config = new TableStoreGridConfig(); + if (tableStoreConf == null){ + tableStoreConf = TableStoreConf.init(); + } + if (tableConfig == null) { + tableConfig = new TableConfig(); + tableConfig.init(); + } config.setTableStoreEndpoint(tableStoreConf.getEndpoint()); config.setAccessId(tableStoreConf.getAccessId()); config.setAccessKey(tableStoreConf.getAccessKey()); diff --git a/weather-service/src/main/java/com/htfp/weather/griddata/operation/CreateTable.java b/weather-service/src/main/java/com/htfp/weather/griddata/operation/CreateTable.java index 601b0f9..93a10a5 100644 --- a/weather-service/src/main/java/com/htfp/weather/griddata/operation/CreateTable.java +++ b/weather-service/src/main/java/com/htfp/weather/griddata/operation/CreateTable.java @@ -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.FieldType; import com.alicloud.openservices.tablestore.model.search.IndexSchema; +import com.aliyun.tablestore.grid.consts.AttributionEnum; import com.htfp.weather.griddata.common.TableConfigStatic; +import java.util.ArrayList; import java.util.Arrays; +import java.util.List; /** * @Author : shiyi @@ -33,19 +36,24 @@ public class CreateTable extends BaseTableOperation { */ private void createIndex() throws Exception { IndexSchema indexSchema = new IndexSchema(); - indexSchema.setFieldSchemas(Arrays.asList( - new FieldSchema("status", FieldType.KEYWORD).setIndex(true).setEnableSortAndAgg(true), - new FieldSchema("create_time", FieldType.LONG).setIndex(true).setEnableSortAndAgg(true), - new FieldSchema("ref_time", FieldType.LONG).setIndex(true).setEnableSortAndAgg(true) - )); + AttributionEnum[] values = AttributionEnum.values(); + ArrayList fieldSchemas = new ArrayList<>(); + for (AttributionEnum attributionEnum : values) { + fieldSchemas.add(new FieldSchema(attributionEnum.getName(), FieldType.KEYWORD).setIndex(true).setEnableSortAndAgg(true)); + } + indexSchema.setFieldSchemas(fieldSchemas); this.tableStoreGrid.createMetaIndex(TableConfigStatic.META_INDEX_NAME, indexSchema); } public static void main(String[] args) throws Exception { + TableConfigStatic.initDatasetConfig(); CreateTable example = new CreateTable(); + example.init(); try { example.createStore(); example.createIndex(); + } catch (Exception e) { + e.printStackTrace(); } finally { example.close(); } diff --git a/weather-service/src/main/java/com/htfp/weather/griddata/operation/GfsDataFetcher.java b/weather-service/src/main/java/com/htfp/weather/griddata/operation/GfsDataFetcher.java index 65dc9f9..7112dd1 100644 --- a/weather-service/src/main/java/com/htfp/weather/griddata/operation/GfsDataFetcher.java +++ b/weather-service/src/main/java/com/htfp/weather/griddata/operation/GfsDataFetcher.java @@ -47,7 +47,7 @@ public class GfsDataFetcher extends BaseTableOperation { public GridDataSetMeta getLastGridDataSetMeta() { if (lastGridDataSetMeta == null) { updateLastGridDataSetMeta(); - throw new AppException(ErrorCode.DATA_SET_EMPTY, ": e.getMessage()"); + throw new AppException(ErrorCode.DATA_SET_EMPTY); } return lastGridDataSetMeta; } diff --git a/weather-service/src/main/java/com/htfp/weather/griddata/operation/GfsDataImport.java b/weather-service/src/main/java/com/htfp/weather/griddata/operation/GfsDataImport.java index 9a694d0..1585511 100644 --- a/weather-service/src/main/java/com/htfp/weather/griddata/operation/GfsDataImport.java +++ b/weather-service/src/main/java/com/htfp/weather/griddata/operation/GfsDataImport.java @@ -17,6 +17,7 @@ import lombok.Getter; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.context.annotation.DependsOn; +import org.springframework.context.annotation.Description; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; import ucar.ma2.*; @@ -26,6 +27,7 @@ import ucar.nc2.Variable; import javax.annotation.PreDestroy; import javax.annotation.Resource; +import javax.annotation.security.DenyAll; import java.io.File; import java.time.OffsetDateTime; import java.time.format.DateTimeFormatter; @@ -78,18 +80,6 @@ public class GfsDataImport extends BaseTableOperation { return meta; } - /** - * 导入完成后,更新meta状态 - * - * @param meta - * @return - * @throws Exception - */ - public GridDataSetMeta updateMeta(GridDataSetMeta meta) throws Exception { - tableStoreGrid.updateDataSetMeta(meta); - return meta; - } - /** * 导入完成后,设置meta状态 */ diff --git a/weather-service/src/main/java/com/htfp/weather/web/config/Config.java b/weather-service/src/main/java/com/htfp/weather/web/config/Config.java new file mode 100644 index 0000000..dd9de6b --- /dev/null +++ b/weather-service/src/main/java/com/htfp/weather/web/config/Config.java @@ -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); + } + } +} diff --git a/weather-service/src/main/java/com/htfp/weather/web/controller/ConfigController.java b/weather-service/src/main/java/com/htfp/weather/web/controller/ConfigController.java index 0dc07fc..f23bfce 100644 --- a/weather-service/src/main/java/com/htfp/weather/web/controller/ConfigController.java +++ b/weather-service/src/main/java/com/htfp/weather/web/controller/ConfigController.java @@ -7,6 +7,7 @@ import com.htfp.weather.griddata.operation.GfsDataImport; import com.htfp.weather.griddata.operation.GfsDataImport.ImportFileInfo; import com.htfp.weather.info.Constant; 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.exception.AppException; import com.htfp.weather.web.exception.ErrorCode; @@ -52,14 +53,18 @@ public class ConfigController { FileService fileService; @Resource GfsDataServiceImpl gfsDataService; - private final String SECRET = "htfpweather"; - private void validSecret(String secret) { - if (StringUtils.isEmpty(secret) || !SECRET.equals(secret)) { - throw new AppException(ErrorCode.SECRET_ERROR); + @Resource + SurfaceWeatherController surfaceWeatherController; + @PostMapping("/switchSurfaceDataSource") + public Result switchService(@RequestBody Map 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数据库配置 */ @@ -77,7 +82,7 @@ public class ConfigController { public Result updateDatabaseConfig(@RequestBody TableConfigUpdate request) { String secret = request.getSecret(); TableConfig updateConfig = request.getConfig(); - validSecret(secret); + Config.validSecret(secret); if (updateConfig == null) { throw new AppException(ErrorCode.CONFIG_ERROR, "配置文件不能为空"); } @@ -107,7 +112,7 @@ public class ConfigController { public Result updateDataSourceConfig(@Validated @RequestBody GfsConfigUpdate request) { String secret = request.getSecret(); GfsDataConfig updateConfig = request.getConfig(); - validSecret(secret); + Config.validSecret(secret); if (updateConfig == null) { throw new AppException(ErrorCode.CONFIG_ERROR, "配置文件不能为空"); } @@ -127,7 +132,7 @@ public class ConfigController { @ControllerLog(info = "下载当前时刻未来24小时的数据文件") public Result downloadAllFiles(@RequestBody Map params) { String secret = params.get("secret"); - validSecret(secret); + Config.validSecret(secret); // List allCompleted = false; try { DownloadResult data = gfsDataService.downloadNowAllFile(); @@ -149,7 +154,7 @@ public class ConfigController { @ControllerLog(info = "下载指定时刻文件") public Result downloadSingleFile(@RequestBody Map params) { String secret = params.get("secret"); - validSecret(secret); + Config.validSecret(secret); OffsetDateTime offsetDateTime = OffsetDateTime.parse(params.get("time"), Constant.API_TIME_FORMATTER); DownLoadFileInfo downLoadFileInfo = gfsDataService.downloadSingleFile(offsetDateTime); return Result.success(downLoadFileInfo); @@ -162,7 +167,7 @@ public class ConfigController { @ControllerLog(info = "根据起报时间将数据导入数据库") public Result importData(@RequestBody Map params) { String secret = params.get("secret"); - validSecret(secret); + Config.validSecret(secret); OffsetDateTime time = OffsetDateTime.parse(params.get("time"), Constant.API_TIME_FORMATTER); return getImportResponse(time); } @@ -205,7 +210,7 @@ public class ConfigController { @ControllerLog(info = "查询所有数据文件夹") public Result queryAllDataDir(@RequestBody Map params) { String secret = params.get("secret"); - validSecret(secret); + Config.validSecret(secret); File dataRoot = new File(gfsDataConfig.getSaveRoot()); List subDirList = fileService.getSubDirList(dataRoot); return Result.success(subDirList); @@ -218,7 +223,7 @@ public class ConfigController { @ControllerLog(info = "查询指定起报时间文件夹中的所有文件名") public Result queryAllFileByReferenceTime(@RequestBody Map params) { String secret = params.get("secret"); - validSecret(secret); + Config.validSecret(secret); OffsetDateTime time = OffsetDateTime.parse(params.get("time"), Constant.API_TIME_FORMATTER); String timeStr = DateTimeUtils.getUTCDateTime(time).format(DateTimeFormatter.ofPattern(Constant.DATA_FOLDER_STRING)); File dataDir = new File(gfsDataConfig.getSaveRoot(), timeStr); @@ -235,7 +240,7 @@ public class ConfigController { @ControllerLog(info = "删除指定起报时间对应的文件夹") public Result deleteDirByReferenceTime(@RequestBody Map params) { String secret = params.get("secret"); - validSecret(secret); + Config.validSecret(secret); OffsetDateTime time = OffsetDateTime.parse(params.get("time"), Constant.API_TIME_FORMATTER); String timeStr = DateTimeUtils.getUTCDateTime(time).format(DateTimeFormatter.ofPattern(Constant.DATA_FOLDER_STRING)); File dataDir = new File(gfsDataConfig.getSaveRoot(), timeStr); @@ -257,7 +262,7 @@ public class ConfigController { @ControllerLog(info = "删除指定文件") public Result deleteTargetFile(@RequestBody Map params) { String secret = params.get("secret"); - validSecret(secret); + Config.validSecret(secret); String filePath = params.get("filePath"); File file = new File(filePath); if (gfsDataImport.isImporting()) { diff --git a/weather-service/src/main/java/com/htfp/weather/web/controller/SurfaceWeatherController.java b/weather-service/src/main/java/com/htfp/weather/web/controller/SurfaceWeatherController.java index 302fcfe..9a1ebef 100644 --- a/weather-service/src/main/java/com/htfp/weather/web/controller/SurfaceWeatherController.java +++ b/weather-service/src/main/java/com/htfp/weather/web/controller/SurfaceWeatherController.java @@ -1,21 +1,22 @@ package com.htfp.weather.web.controller; 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.response.NowWeatherStatus; import com.htfp.weather.web.pojo.response.Result; import com.htfp.weather.web.pojo.response.SurfaceWeatherWarning; 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.CmaServiceImpl; import com.htfp.weather.web.service.surfaceapi.HeFengServiceImpl; -import com.htfp.weather.web.service.IDataService; import com.htfp.weather.web.service.surfaceapi.ISurfaceDataService; import lombok.extern.slf4j.Slf4j; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import javax.annotation.PostConstruct; import javax.annotation.Resource; import java.util.List; @@ -29,11 +30,32 @@ import java.util.List; @Slf4j @RequestMapping("/htfp/weather/surface/") public class SurfaceWeatherController { - @Resource(name = "hefeng") - ISurfaceDataService surfaceDataService; - @Resource 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") @ControllerLog(info = "地面实时气象信息查询") @@ -41,9 +63,10 @@ public class SurfaceWeatherController { double lat = position2D.getLatitude(); double lon = position2D.getLongitude(); - NowWeatherStatus nowWeatherStatus = surfaceDataService.getNowSurfaceWeatherStatus(lat, lon); + NowWeatherStatus nowWeatherStatus = service.getNowSurfaceWeatherStatus(lat, lon); nowWeatherStatus.setLatitude(lat); nowWeatherStatus.setLongitude(lon); + nowWeatherStatus.setDataSource(service.getDataSource()); return Result.success(nowWeatherStatus); } @@ -53,9 +76,10 @@ public class SurfaceWeatherController { double lat = position2D.getLatitude(); double lon = position2D.getLongitude(); - TimeSeriesDataset forecastSeries = surfaceDataService.getForecastSeries(lat, lon); + TimeSeriesDataset forecastSeries = service.getForecastSeries(lat, lon); forecastSeries.setLatitude(lat); forecastSeries.setLongitude(lon); + forecastSeries.setDataSource(service.getDataSource()); return Result.success(forecastSeries); } diff --git a/weather-service/src/main/java/com/htfp/weather/web/controller/ThymeleafTest.java b/weather-service/src/main/java/com/htfp/weather/web/controller/ThymeleafTest.java deleted file mode 100644 index 347bd32..0000000 --- a/weather-service/src/main/java/com/htfp/weather/web/controller/ThymeleafTest.java +++ /dev/null @@ -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对应 - } - -} diff --git a/weather-service/src/main/java/com/htfp/weather/web/pojo/response/NowWeatherStatus.java b/weather-service/src/main/java/com/htfp/weather/web/pojo/response/NowWeatherStatus.java index dca12dd..e92b4d2 100644 --- a/weather-service/src/main/java/com/htfp/weather/web/pojo/response/NowWeatherStatus.java +++ b/weather-service/src/main/java/com/htfp/weather/web/pojo/response/NowWeatherStatus.java @@ -23,4 +23,5 @@ public class NowWeatherStatus { // Float pressure; // 大气压强,默认单位:百帕 Float cloud; // 云量 Float precip; //降水量 + String dataSource; } diff --git a/weather-service/src/main/java/com/htfp/weather/web/pojo/response/TimeSeriesDataset.java b/weather-service/src/main/java/com/htfp/weather/web/pojo/response/TimeSeriesDataset.java index 47348ca..c4b6577 100644 --- a/weather-service/src/main/java/com/htfp/weather/web/pojo/response/TimeSeriesDataset.java +++ b/weather-service/src/main/java/com/htfp/weather/web/pojo/response/TimeSeriesDataset.java @@ -25,7 +25,7 @@ public class TimeSeriesDataset { // float[] pressure; float[] cloud; float[] precip; - + String dataSource; public TimeSeriesDataset() {} public TimeSeriesDataset(int size) { time = new ArrayList<>(size); diff --git a/weather-service/src/main/java/com/htfp/weather/web/service/GfsDataServiceImpl.java b/weather-service/src/main/java/com/htfp/weather/web/service/GfsDataServiceImpl.java index e2d36a8..ff599fb 100644 --- a/weather-service/src/main/java/com/htfp/weather/web/service/GfsDataServiceImpl.java +++ b/weather-service/src/main/java/com/htfp/weather/web/service/GfsDataServiceImpl.java @@ -19,6 +19,7 @@ import com.htfp.weather.utils.MeteoUtils; import com.htfp.weather.web.exception.AppException; import com.htfp.weather.web.exception.ErrorCode; import com.htfp.weather.web.pojo.response.*; +import com.htfp.weather.web.service.surfaceapi.ISurfaceDataService; import lombok.extern.slf4j.Slf4j; import org.checkerframework.checker.units.qual.A; import org.springframework.stereotype.Service; @@ -26,6 +27,7 @@ import ucar.ma2.Array; import ucar.ma2.Index4D; import javax.annotation.Resource; +import javax.annotation.security.DenyAll; import java.lang.reflect.Method; import java.time.Instant; import java.time.OffsetDateTime; @@ -41,7 +43,7 @@ import java.util.stream.Collectors; */ @Service("tablestore-gfs") @Slf4j -public class GfsDataServiceImpl implements IDataService { +public class GfsDataServiceImpl implements IDataService, ISurfaceDataService { @Resource GfsDataFetcher gfsDataFetcher; @Resource @@ -50,6 +52,30 @@ public class GfsDataServiceImpl implements IDataService { GfsDownloader gfsDownloader; @Resource 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 getSurfaceWarning(double lat, double lon) throws Exception { + return null; + } + + // 下载和导入数据 public DownloadResult downloadNowAllFile() { gfsDownloader.iniTimeSetting(); @@ -94,9 +120,6 @@ public class GfsDataServiceImpl implements IDataService { return importResult; } - public void downloadAndImportData() { - - } // 从tablestore获取数据 diff --git a/weather-service/src/main/java/com/htfp/weather/web/service/surfaceapi/CaiYunServiceImpl.java b/weather-service/src/main/java/com/htfp/weather/web/service/surfaceapi/CaiYunServiceImpl.java index b527adc..5be0bba 100644 --- a/weather-service/src/main/java/com/htfp/weather/web/service/surfaceapi/CaiYunServiceImpl.java +++ b/weather-service/src/main/java/com/htfp/weather/web/service/surfaceapi/CaiYunServiceImpl.java @@ -31,9 +31,14 @@ import static com.htfp.weather.utils.HttpClientUtils.sendGet; */ @Service("caiyun") @Slf4j public class CaiYunServiceImpl implements ISurfaceDataService { + String dataSource = "CaiYun"; @Value("${caiyun.key}") private String key; static final String STATUS_OK = "ok"; + @Override + public String getDataSource() { + return dataSource; + } public T caiYunRequest(String url, HashMap params, Class responseClass) { params.put("units", "metric:v2"); try { diff --git a/weather-service/src/main/java/com/htfp/weather/web/service/surfaceapi/CmaServiceImpl.java b/weather-service/src/main/java/com/htfp/weather/web/service/surfaceapi/CmaServiceImpl.java index e86e119..21d7e76 100644 --- a/weather-service/src/main/java/com/htfp/weather/web/service/surfaceapi/CmaServiceImpl.java +++ b/weather-service/src/main/java/com/htfp/weather/web/service/surfaceapi/CmaServiceImpl.java @@ -37,10 +37,15 @@ import static com.htfp.weather.utils.HttpClientUtils.sendGet; @Slf4j @Service("cma") public class CmaServiceImpl implements ISurfaceDataService{ + String dataSource = "CMA"; + @Value("${tianditu.key}") @Setter private String keyOfTianDiTu; private Map> warningCache = new ConcurrentHashMap<>(); - + @Override + public String getDataSource() { + return dataSource; + } @Override public NowWeatherStatus getNowSurfaceWeatherStatus(double lat, double lon) throws Exception { return null; diff --git a/weather-service/src/main/java/com/htfp/weather/web/service/surfaceapi/HeFengServiceImpl.java b/weather-service/src/main/java/com/htfp/weather/web/service/surfaceapi/HeFengServiceImpl.java index 710555d..f7ecafd 100644 --- a/weather-service/src/main/java/com/htfp/weather/web/service/surfaceapi/HeFengServiceImpl.java +++ b/weather-service/src/main/java/com/htfp/weather/web/service/surfaceapi/HeFengServiceImpl.java @@ -34,6 +34,7 @@ import static com.htfp.weather.utils.HttpClientUtils.*; @Service("hefeng") @Slf4j public class HeFengServiceImpl implements ISurfaceDataService { + String dataSource = "HeFeng"; @Value("${hefeng.key}") private String key; private final HashMap variableNameMap = @@ -49,7 +50,10 @@ public class HeFengServiceImpl implements ISurfaceDataService { }}; static final String STATUS_OK = "200"; static final String STATUS_NO_DATA = "204"; - + @Override + public String getDataSource() { + return dataSource; + } public T heFengRequest(String url, HashMap params, Class responseClass) throws Exception { // String signature = getSignature(params, key); // HashMap params = new HashMap<>(); diff --git a/weather-service/src/main/java/com/htfp/weather/web/service/surfaceapi/ISurfaceDataService.java b/weather-service/src/main/java/com/htfp/weather/web/service/surfaceapi/ISurfaceDataService.java index 7eb88d8..7859b29 100644 --- a/weather-service/src/main/java/com/htfp/weather/web/service/surfaceapi/ISurfaceDataService.java +++ b/weather-service/src/main/java/com/htfp/weather/web/service/surfaceapi/ISurfaceDataService.java @@ -12,6 +12,7 @@ import java.util.List; * @Description : */ public interface ISurfaceDataService { + String getDataSource(); NowWeatherStatus getNowSurfaceWeatherStatus(double lat, double lon) throws Exception; TimeSeriesDataset getForecastSeries(double lat, double lon) throws Exception; diff --git a/weather-service/src/main/resources/application-weather.yml b/weather-service/src/main/resources/application-weather.yml index b374290..907a973 100644 --- a/weather-service/src/main/resources/application-weather.yml +++ b/weather-service/src/main/resources/application-weather.yml @@ -4,11 +4,11 @@ hefeng: caiyun: key: Tc9tgOYr5jlPPlEw tianditu: - key: 86c4d7e4084ee8bf162a1fe9b62d982e + key: 26b108f24d9d0e7337a39e84200e59d3 # tablestore tablestore: - endpoint: https://gfs-test.cn-hangzhou.ots.aliyuncs.com - accessId: LTAI5tDphvXLfwKJEmVQqrVz - accessKey: ksioVP1S36PI6plkIIRN4A2xLB94uc - instanceName: gfs-test + endpoint: https://gfs25km.cn-hangzhou.ots.aliyuncs.com + accessId: LTAI5tH1nLqUgyvEpEgNVJwp + accessKey: f5YXyvIqdDfd4yvYj8DVSzNry6RmA0 + instanceName: gfs25km diff --git a/weather-service/src/main/resources/application.yml b/weather-service/src/main/resources/application.yml index 6e127e4..00d98d0 100644 --- a/weather-service/src/main/resources/application.yml +++ b/weather-service/src/main/resources/application.yml @@ -6,9 +6,9 @@ spring: mvc: servlet: load-on-startup: 1 # 关闭 dispatcherServlet懒加载 - thymeleaf: - cache: false - encoding: UTF-8 +# thymeleaf: +# cache: false +# encoding: UTF-8 mail: host: smtp.exmail.qq.com username: shiyi@htsdfp.com diff --git a/weather-service/src/main/resources/static/index.html b/weather-service/src/main/resources/static/index.html deleted file mode 100644 index 89bb8ba..0000000 --- a/weather-service/src/main/resources/static/index.html +++ /dev/null @@ -1,6 +0,0 @@ - - -

hello word!!!

-

this is a html page

- - \ No newline at end of file diff --git a/weather-service/src/main/resources/templates/index.html b/weather-service/src/main/resources/templates/index.html deleted file mode 100644 index f5c6d26..0000000 --- a/weather-service/src/main/resources/templates/index.html +++ /dev/null @@ -1,60 +0,0 @@ - - - - - Title - - - - -
-

Tablestore 表格存储配置信息

-

-
- - - - - - - - - - - - - - - - - - - - - - - - - -
数据表名称 dataTableName
属性表名称 metaTableName
数据索引名称 dataIndexName
属性索引名称 metaIndexName
数据存储路径根目录 dataDir edit
纬度网格数 latSize
经度网格数 lonSize
高度层数 levSize
-
- - - - - - \ No newline at end of file diff --git a/weather-service/src/main/resources/templates/wrong.html b/weather-service/src/main/resources/templates/wrong.html deleted file mode 100644 index b6c1dec..0000000 --- a/weather-service/src/main/resources/templates/wrong.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - - Title - - -请求错误 - - \ No newline at end of file