From 3405f5005599d9ba4638997aa2844732d6a71411 Mon Sep 17 00:00:00 2001 From: xiaowuler Date: Fri, 18 Mar 2022 16:40:39 +0800 Subject: [PATCH] modify some codes --- .../jobhandler/TianQingRadarDataHandler.java | 9 ++- .../xxljobexecutor/service/IRadarService.java | 2 +- .../service/impl/RadarService.java | 13 +++- .../service/impl/SchemaService.java | 77 ++++++++++++------- .../XxlJobExecutorApplicationTests.java | 19 +++-- 5 files changed, 78 insertions(+), 42 deletions(-) diff --git a/04.系统编码/01.xxl-job/xxl-job-executor/src/main/java/com/ping/chuan/ahpmsdp/xxljobexecutor/jobhandler/TianQingRadarDataHandler.java b/04.系统编码/01.xxl-job/xxl-job-executor/src/main/java/com/ping/chuan/ahpmsdp/xxljobexecutor/jobhandler/TianQingRadarDataHandler.java index ac79816..b221700 100644 --- a/04.系统编码/01.xxl-job/xxl-job-executor/src/main/java/com/ping/chuan/ahpmsdp/xxljobexecutor/jobhandler/TianQingRadarDataHandler.java +++ b/04.系统编码/01.xxl-job/xxl-job-executor/src/main/java/com/ping/chuan/ahpmsdp/xxljobexecutor/jobhandler/TianQingRadarDataHandler.java @@ -29,6 +29,7 @@ import com.ping.chuan.ahpmsdp.xxljobexecutor.model.vo.TianQingFileVO; import com.ping.chuan.ahpmsdp.xxljobexecutor.model.vo.TianQingResponse; import com.ping.chuan.ahpmsdp.xxljobexecutor.service.IDataService; import com.ping.chuan.ahpmsdp.xxljobexecutor.service.IDealInfoService; +import com.ping.chuan.ahpmsdp.xxljobexecutor.service.IRadarService; import com.ping.chuan.ahpmsdp.xxljobexecutor.service.ITianQingSCMOCDataService; import com.ping.chuan.ahpmsdp.xxljobexecutor.service.impl.BaseInfoService; import com.ping.chuan.ahpmsdp.xxljobexecutor.template.CacheTemplate; @@ -50,14 +51,14 @@ public class TianQingRadarDataHandler { private final BaseInfoService baseInfoService; private final ITianQingSCMOCDataService tianQingSCMOCDataService; private final IDealInfoService dealInfoService; - private final IDataService dataService; + private final IRadarService radarService; - public TianQingRadarDataHandler(ApplicationCommon applicationCommon, BaseInfoService baseInfoService, ITianQingSCMOCDataService tianQingSCMOCDataService, IDealInfoService dealInfoService, IDataService dataService){ + public TianQingRadarDataHandler(ApplicationCommon applicationCommon, BaseInfoService baseInfoService, ITianQingSCMOCDataService tianQingSCMOCDataService, IDealInfoService dealInfoService, IRadarService radarService){ this.applicationCommon = applicationCommon; this.baseInfoService = baseInfoService; this.tianQingSCMOCDataService = tianQingSCMOCDataService; this.dealInfoService = dealInfoService; - this.dataService = dataService; + this.radarService = radarService; } @XxlJob("readRadar") @@ -80,7 +81,7 @@ public class TianQingRadarDataHandler { XxlJobHelper.log("总共需要解析文件{}个", results.size()); for(Map.Entry> entry : results.entrySet()){ XxlJobHelper.log("文件:{} 开始解析", entry.getKey().getFileName()); - String result = null; + String result = radarService.read(entry); // if(paramInfo.isWind()){ // result = dataService.readWindElement(entry); // }else { diff --git a/04.系统编码/01.xxl-job/xxl-job-executor/src/main/java/com/ping/chuan/ahpmsdp/xxljobexecutor/service/IRadarService.java b/04.系统编码/01.xxl-job/xxl-job-executor/src/main/java/com/ping/chuan/ahpmsdp/xxljobexecutor/service/IRadarService.java index 316f774..89d363f 100644 --- a/04.系统编码/01.xxl-job/xxl-job-executor/src/main/java/com/ping/chuan/ahpmsdp/xxljobexecutor/service/IRadarService.java +++ b/04.系统编码/01.xxl-job/xxl-job-executor/src/main/java/com/ping/chuan/ahpmsdp/xxljobexecutor/service/IRadarService.java @@ -7,5 +7,5 @@ import com.ping.chuan.ahpmsdp.xxljobexecutor.model.domain.Coordinate; import java.util.Map; public interface IRadarService { - void read(Map.Entry> entry); + String read(Map.Entry> entry); } diff --git a/04.系统编码/01.xxl-job/xxl-job-executor/src/main/java/com/ping/chuan/ahpmsdp/xxljobexecutor/service/impl/RadarService.java b/04.系统编码/01.xxl-job/xxl-job-executor/src/main/java/com/ping/chuan/ahpmsdp/xxljobexecutor/service/impl/RadarService.java index 7338128..16cc05f 100644 --- a/04.系统编码/01.xxl-job/xxl-job-executor/src/main/java/com/ping/chuan/ahpmsdp/xxljobexecutor/service/impl/RadarService.java +++ b/04.系统编码/01.xxl-job/xxl-job-executor/src/main/java/com/ping/chuan/ahpmsdp/xxljobexecutor/service/impl/RadarService.java @@ -8,6 +8,7 @@ import org.springframework.stereotype.Service; import java.util.Map; +import com.xiaowuler.radar.core.exceptions.RadarReadException; import com.xiaowuler.radar.core.weather.resolver.RadarReader; /** @@ -16,7 +17,15 @@ import com.xiaowuler.radar.core.weather.resolver.RadarReader; @Service public class RadarService implements IRadarService { @Override - public void read(Map.Entry> entry) { - RadarReader radarReader = new RadarReader(); + public String read(Map.Entry> entry) { + try { + RadarReader radarReader = new RadarReader(); + radarReader.read(entry.getKey().getLocalPath()); + + + } catch (RadarReadException e) { + e.printStackTrace(); + } + return null; } } diff --git a/04.系统编码/01.xxl-job/xxl-job-executor/src/main/java/com/ping/chuan/ahpmsdp/xxljobexecutor/service/impl/SchemaService.java b/04.系统编码/01.xxl-job/xxl-job-executor/src/main/java/com/ping/chuan/ahpmsdp/xxljobexecutor/service/impl/SchemaService.java index ed2a7d0..d29046a 100644 --- a/04.系统编码/01.xxl-job/xxl-job-executor/src/main/java/com/ping/chuan/ahpmsdp/xxljobexecutor/service/impl/SchemaService.java +++ b/04.系统编码/01.xxl-job/xxl-job-executor/src/main/java/com/ping/chuan/ahpmsdp/xxljobexecutor/service/impl/SchemaService.java @@ -25,32 +25,36 @@ import com.ping.chuan.ahpmsdp.xxljobexecutor.util.CalcUtil; @Service public class SchemaService implements ISchemaService { - private static Map partitionKey = new LinkedHashMap<>(2); - private static Map dealPartitionKey = new LinkedHashMap<>(2); - private static Map dealColumn = new LinkedHashMap<>(2); - - static { - partitionKey.put("initial_time", DataType.timestamp()); - partitionKey.put("forecast_time", DataType.timestamp()); + private static Map partitionKey = new LinkedHashMap<>(2){{ + put("initial_time", DataType.timestamp()); + put("forecast_time", DataType.timestamp()); + }}; + private static Map dealPartitionKey = new LinkedHashMap<>(8){{ + put("mode_code", DataType.varchar()); + put("member_code", DataType.varchar()); + put("element_code", DataType.varchar()); + put("time_interval", DataType.cint()); + put("time_length", DataType.cint()); + put("height", DataType.decimal()); + put("initial_time", DataType.timestamp()); + put("forecast_time", DataType.timestamp()); + }}; + private static Map dealColumn = new LinkedHashMap<>(8) { + { + put("local_path", DataType.varchar()); + put("file_name", DataType.varchar()); + put("try_count", DataType.cint()); + put("message", DataType.varchar()); + put("state", DataType.cint()); + put("url", DataType.varchar()); + put("update_time", DataType.timestamp()); + put("create_time", DataType.timestamp()); + } + }; - dealPartitionKey.put("mode_code", DataType.varchar()); - dealPartitionKey.put("member_code", DataType.varchar()); - dealPartitionKey.put("element_code", DataType.varchar()); - dealPartitionKey.put("time_interval", DataType.cint()); - dealPartitionKey.put("time_length", DataType.cint()); - dealPartitionKey.put("height", DataType.decimal()); - dealPartitionKey.put("initial_time", DataType.timestamp()); - dealPartitionKey.put("forecast_time", DataType.timestamp()); - - dealColumn.put("local_path", DataType.varchar()); - dealColumn.put("file_name", DataType.varchar()); - dealColumn.put("try_count", DataType.cint()); - dealColumn.put("message", DataType.varchar()); - dealColumn.put("state", DataType.cint()); - dealColumn.put("url", DataType.varchar()); - dealColumn.put("update_time", DataType.timestamp()); - dealColumn.put("create_time", DataType.timestamp()); - } + private static Map radarPartitionKey = new LinkedHashMap<>(partitionKey){{ + put("station", DataType.varchar()); + }}; private final ISchemaRepository schemaRepository; public SchemaService(ISchemaRepository schemaRepository){ @@ -76,11 +80,30 @@ public class SchemaService implements ISchemaService { private void buildDataTable(String keyspace){ for(Map.Entry entry : CacheTemplate.metaInfos.entrySet()){ String tableName = entry.getKey().toTableName(); - Map columns = toColumn(CalcUtil.calcClip(entry.getValue().getLatCount(), entry.getKey().getLatClipCount()), CalcUtil.calcClip(entry.getValue().getLonCount(), entry.getKey().getLonClipCount())); - schemaRepository.prepareTable(keyspace, tableName, partitionKey, columns); + Map columns; + if (entry.getKey().getModeCode().equals("RADAR")){ + columns = toColumn(20); + schemaRepository.prepareTable(keyspace, tableName, radarPartitionKey, columns); + }else { + columns = toColumn(CalcUtil.calcClip(entry.getValue().getLatCount(), entry.getKey().getLatClipCount()), CalcUtil.calcClip(entry.getValue().getLonCount(), entry.getKey().getLonClipCount())); + schemaRepository.prepareTable(keyspace, tableName, partitionKey, columns); + } } } + private Map toColumn(int length){ + Map columns = new LinkedHashMap<>(length + 3){{ + put("site_configuration", DataType.blob()); + put("task_configuration", DataType.blob()); + put("generic_header", DataType.blob()); + }}; + + for(int index = 0; index < length; index++){ + columns.put("col_%s".formatted(index), DataType.blob()); + } + return columns; + } + private Map toColumn(int latLength, int lonLength){ Map columns = new LinkedHashMap<>(latLength * lonLength + 2); columns.put("time_effect", DataType.cint()); diff --git a/04.系统编码/01.xxl-job/xxl-job-executor/src/test/java/com/ping/chuan/ahpmsdp/xxljobexecutor/XxlJobExecutorApplicationTests.java b/04.系统编码/01.xxl-job/xxl-job-executor/src/test/java/com/ping/chuan/ahpmsdp/xxljobexecutor/XxlJobExecutorApplicationTests.java index 7df2cdd..167940f 100644 --- a/04.系统编码/01.xxl-job/xxl-job-executor/src/test/java/com/ping/chuan/ahpmsdp/xxljobexecutor/XxlJobExecutorApplicationTests.java +++ b/04.系统编码/01.xxl-job/xxl-job-executor/src/test/java/com/ping/chuan/ahpmsdp/xxljobexecutor/XxlJobExecutorApplicationTests.java @@ -167,14 +167,17 @@ class XxlJobExecutorApplicationTests { // metaInfos.add(Lists.newArrayList("CLDAS", "BABJ", "MXT", 60, 60, 1010, "1201_1401_0.05_0.05_0_60_70_140", 0, "H", 60, 60, 70, "Maximum_temperature_height_above_ground")); // metaInfos.add(Lists.newArrayList("CLDAS", "BABJ", "MXWIN_U", 60, 60, 1010, "1201_1401_0.05_0.05_0_60_70_140", 0, "H", 60, 60, 70, "VAR0-2-102_FROM_38-0--1_height_above_ground")); // metaInfos.add(Lists.newArrayList("CLDAS", "BABJ", "MXWIN_V", 60, 60, 1010, "1201_1401_0.05_0.05_0_60_70_140", 0, "H", 60, 60, 70, "VAR0-2-103_FROM_38-0--1_height_above_ground")); - metaInfos.add(Lists.newArrayList("SPCC", "BEHF", "TMP", 180, 4320, 1010, "243_221_0.025_0.025_29_35.05_114.5_120", 180, "H", 60, 30, 30, "Temperature_height_above_ground")); - metaInfos.add(Lists.newArrayList("SPCC", "BEHF", "EDA10_U", 180, 4320, 1010, "243_221_0.025_0.025_29_35.05_114.5_120", 180, "H", 60, 30, 30, "u-component_of_wind_height_above_ground")); - metaInfos.add(Lists.newArrayList("SPCC", "BEHF", "EDA10_V", 180, 4320, 1010, "243_221_0.025_0.025_29_35.05_114.5_120", 180, "H", 60, 30, 30, "v-component_of_wind_height_above_ground")); - metaInfos.add(Lists.newArrayList("SPCC", "BEHF", "ER03", 180, 4320, 1010, "243_221_0.025_0.025_29_35.05_114.5_120", 180, "H", 60, 30, 30, "Total_precipitation_surface_3_Hour_Accumulation")); - metaInfos.add(Lists.newArrayList("SPCC", "BEHF", "PPH", 180, 4320, 1010, "243_221_0.025_0.025_29_35.05_114.5_120", 180, "H", 60, 30, 30, "Precipitation_type_surface_3_Hour_Accumulation")); - metaInfos.add(Lists.newArrayList("SPCC", "BEHF", "TMAX", 1440, 4320, 1010, "243_221_0.025_0.025_29_35.05_114.5_120", 1440, "H", 60, 30, 30, "Maximum_temperature_height_above_ground_24_Hour_Maximum")); - metaInfos.add(Lists.newArrayList("SPCC", "BEHF", "TMIN", 1440, 4320, 1010, "243_221_0.025_0.025_29_35.05_114.5_120", 1440, "H", 60, 30, 30, "Minimum_temperature_height_above_ground_24_Hour_Minimum")); - metaInfos.add(Lists.newArrayList("CMPA", "BABJ", "PRE", 60, 60, 1010, "1201_1401_0.05_0.05_0_60_70_140", 0, "H", 60, 60, 70, "Total_precipitation_surface")); +// metaInfos.add(Lists.newArrayList("SPCC", "BEHF", "TMP", 180, 4320, 1010, "243_221_0.025_0.025_29_35.05_114.5_120", 180, "H", 60, 30, 30, "Temperature_height_above_ground")); +// metaInfos.add(Lists.newArrayList("SPCC", "BEHF", "EDA10_U", 180, 4320, 1010, "243_221_0.025_0.025_29_35.05_114.5_120", 180, "H", 60, 30, 30, "u-component_of_wind_height_above_ground")); +// metaInfos.add(Lists.newArrayList("SPCC", "BEHF", "EDA10_V", 180, 4320, 1010, "243_221_0.025_0.025_29_35.05_114.5_120", 180, "H", 60, 30, 30, "v-component_of_wind_height_above_ground")); +// metaInfos.add(Lists.newArrayList("SPCC", "BEHF", "ER03", 180, 4320, 1010, "243_221_0.025_0.025_29_35.05_114.5_120", 180, "H", 60, 30, 30, "Total_precipitation_surface_3_Hour_Accumulation")); +// metaInfos.add(Lists.newArrayList("SPCC", "BEHF", "PPH", 180, 4320, 1010, "243_221_0.025_0.025_29_35.05_114.5_120", 180, "H", 60, 30, 30, "Precipitation_type_surface_3_Hour_Accumulation")); +// metaInfos.add(Lists.newArrayList("SPCC", "BEHF", "TMAX", 1440, 4320, 1010, "243_221_0.025_0.025_29_35.05_114.5_120", 1440, "H", 60, 30, 30, "Maximum_temperature_height_above_ground_24_Hour_Maximum")); +// metaInfos.add(Lists.newArrayList("SPCC", "BEHF", "TMIN", 1440, 4320, 1010, "243_221_0.025_0.025_29_35.05_114.5_120", 1440, "H", 60, 30, 30, "Minimum_temperature_height_above_ground_24_Hour_Minimum")); +// metaInfos.add(Lists.newArrayList("CMPA", "BABJ", "PRE", 60, 60, 1010, "1201_1401_0.05_0.05_0_60_70_140", 0, "H", 60, 60, 70, "Total_precipitation_surface")); + metaInfos.add(Lists.newArrayList("RADAR", "SAD", "CAP", 6, 6, 1010, "1201_1401_0.05_0.05_0_60_70_140", 0, "m", 6, 6, 70, "")); + metaInfos.add(Lists.newArrayList("RADAR", "CC", "CAP", 6, 6, 1010, "1201_1401_0.05_0.05_0_60_70_140", 0, "m", 6, 6, 70, "")); + metaInfos.add(Lists.newArrayList("RADAR", "SA", "CAP", 6, 6, 1010, "1201_1401_0.05_0.05_0_60_70_140", 0, "m", 6, 6, 70, "")); return metaInfos; }