From 197d6ff6cb11fa0f58c4897325a11e3b647877ca Mon Sep 17 00:00:00 2001 From: panbaolin Date: Fri, 7 Aug 2026 11:51:30 +0800 Subject: [PATCH] =?UTF-8?q?fix:1.=E5=86=8D=E6=AC=A1=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=A4=A9=E6=B0=94=E9=A2=84=E6=8A=A5=E6=92=AD=E6=94=BE=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=EF=BC=8C=E6=8A=8A=E7=BC=93=E5=AD=98=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=AD=98=E5=85=A5=E7=A3=81=E7=9B=98=EF=BC=8C=E9=80=9A=E8=BF=87?= =?UTF-8?q?=E7=9B=B4=E6=8E=A5=E7=9B=B4=E6=8E=A5=E6=9F=A5=E6=89=BE=EF=BC=8C?= =?UTF-8?q?=E6=80=A7=E8=83=BD=E4=B8=8D=E5=88=B070=E6=AF=AB=E7=A7=92?= =?UTF-8?q?=E5=8D=B3=E8=BF=94=E5=9B=9E2.=E6=B7=BB=E5=8A=A0=E5=AE=9A?= =?UTF-8?q?=E6=97=B6=E6=B8=85=E9=99=A4=E7=BC=93=E5=AD=98=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jeecg/common/constant/CommonConstant.java | 5 - .../properties/SystemStorageProperties.java | 5 + .../java/org/jeecg/common/util/GzipUtil.java | 50 ++++++++ .../controller/WeatherDataController.java | 15 +-- .../org/jeecg/job/CacheWeatherDataJob.java | 114 +++++++++++------ .../org/jeecg/service/WeatherDataService.java | 9 +- .../service/impl/WeatherDataServiceImpl.java | 117 +++++++++--------- .../jeecg/JeecgConsumerCloudApplication.java | 33 ++++- 8 files changed, 234 insertions(+), 114 deletions(-) create mode 100644 jeecg-boot-base-core/src/main/java/org/jeecg/common/util/GzipUtil.java diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/CommonConstant.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/CommonConstant.java index 10a3135..8695f06 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/CommonConstant.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/CommonConstant.java @@ -339,9 +339,4 @@ public interface CommonConstant { */ String BUILD_TASK_STATE_PRE = "build_task_"; - /*** - * weather_data:数据类型(ncep、fnl):变量类型(温、湿、压、风) - */ - String WEATHER_DATA_CACHE = "weather_data:%s:%s"; - } diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/properties/SystemStorageProperties.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/properties/SystemStorageProperties.java index a47d7aa..52d5f45 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/properties/SystemStorageProperties.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/properties/SystemStorageProperties.java @@ -98,4 +98,9 @@ public class SystemStorageProperties { * 天气预测docker容器http请求 url */ private String weatherForecastUri; + + /** + * 气象数据json缓存路径 + */ + private String gribDataVariableCachePath; } diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/GzipUtil.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/GzipUtil.java new file mode 100644 index 0000000..7bf2e5b --- /dev/null +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/GzipUtil.java @@ -0,0 +1,50 @@ +package org.jeecg.common.util; + +import java.io.*; +import java.nio.charset.StandardCharsets; +import java.util.zip.GZIPInputStream; +import java.util.zip.GZIPOutputStream; + +public class GzipUtil { + + private static final int BUFFER_SIZE = 8192; + + /** + * 压缩: String/byte[] → 压缩后 byte[] + */ + public static byte[] compress(byte[] data) throws IOException { + if (data == null || data.length == 0) return data; + + ByteArrayOutputStream baos = new ByteArrayOutputStream(data.length / 4); + try (GZIPOutputStream gzip = new GZIPOutputStream(baos, BUFFER_SIZE)) { + gzip.write(data); + } + return baos.toByteArray(); + } + + public static byte[] compress(String json) throws IOException { + return compress(json.getBytes(StandardCharsets.UTF_8)); + } + + /** + * 解压: 压缩后 byte[] → 原始 byte[] + */ + public static byte[] decompress(byte[] compressed) throws IOException { + if (compressed == null || compressed.length == 0) return compressed; + + ByteArrayOutputStream baos = new ByteArrayOutputStream(compressed.length * 4); + try (GZIPInputStream gzip = new GZIPInputStream( + new ByteArrayInputStream(compressed), BUFFER_SIZE)) { + byte[] buffer = new byte[BUFFER_SIZE]; + int len; + while ((len = gzip.read(buffer)) != -1) { + baos.write(buffer, 0, len); + } + } + return baos.toByteArray(); + } + + public static String decompressToString(byte[] compressed) throws IOException { + return new String(decompress(compressed), StandardCharsets.UTF_8); + } +} diff --git a/jeecg-module-weather/src/main/java/org/jeecg/controller/WeatherDataController.java b/jeecg-module-weather/src/main/java/org/jeecg/controller/WeatherDataController.java index d4d6c10..2607903 100644 --- a/jeecg-module-weather/src/main/java/org/jeecg/controller/WeatherDataController.java +++ b/jeecg-module-weather/src/main/java/org/jeecg/controller/WeatherDataController.java @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import io.swagger.v3.oas.annotations.Operation; import jakarta.annotation.Resource; +import jakarta.servlet.http.HttpServletResponse; import jakarta.validation.constraints.NotNull; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -77,13 +78,13 @@ public class WeatherDataController { @AutoLog(value = "气象预测-气象数据查询") @Operation(summary = "气象预测-气象数据查询") @GetMapping(value = "getWeatherData") - public Result getWeatherData(Integer dataType, - Integer weatherType, - String timeBatch, - @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime startTime, - @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime endTime, - int hour) { - return Result.OK(weatherDataService.getWeatherData(dataType, weatherType, timeBatch, startTime,endTime, hour)); + public void getWeatherData(Integer dataType, + Integer weatherType, + String timeBatch, + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime startTime, + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime endTime, + int hour, HttpServletResponse res) { + weatherDataService.getWeatherData(dataType, weatherType, timeBatch, startTime,endTime, hour,res); } /** diff --git a/jeecg-module-weather/src/main/java/org/jeecg/job/CacheWeatherDataJob.java b/jeecg-module-weather/src/main/java/org/jeecg/job/CacheWeatherDataJob.java index fa0855d..18d5c83 100644 --- a/jeecg-module-weather/src/main/java/org/jeecg/job/CacheWeatherDataJob.java +++ b/jeecg-module-weather/src/main/java/org/jeecg/job/CacheWeatherDataJob.java @@ -1,16 +1,25 @@ package org.jeecg.job; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson2.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import lombok.extern.slf4j.Slf4j; -import org.jeecg.common.constant.CommonConstant; import org.jeecg.common.constant.enums.WeatherDataSourceEnum; import org.jeecg.common.constant.enums.WeatherTypeEnum; -import org.jeecg.common.util.RedisUtil; +import org.jeecg.modules.base.entity.WeatherData; import org.jeecg.service.WeatherDataService; import org.jeecg.vo.WeatherResultVO; - +import java.io.IOException; +import java.io.OutputStream; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.Objects; +import java.util.zip.GZIPOutputStream; /** * 缓存天气数据 @@ -19,72 +28,61 @@ import java.util.Objects; public class CacheWeatherDataJob extends Thread { private WeatherDataService weatherDataService; - private RedisUtil redisUtil; private Integer dataType; private String timeBatch; private LocalDateTime startTime; private LocalDateTime endTime; - + private String cacheVariablePath; /** * 初始化 * @param weatherDataService - * @param redisUtil * @param dataType * @param timeBatch * @param startTime * @param endTime */ public void init(WeatherDataService weatherDataService, - RedisUtil redisUtil, Integer dataType, String timeBatch, LocalDateTime startTime, - LocalDateTime endTime){ + LocalDateTime endTime, + String cacheVariablePath){ this.weatherDataService = weatherDataService; - this.redisUtil = redisUtil; this.dataType = dataType; this.timeBatch = timeBatch; this.startTime = startTime; this.endTime = endTime; + this.cacheVariablePath = cacheVariablePath; } @Override public void run() { + boolean add_six_hour_flag = false; while (!startTime.isAfter(endTime)) { try { WeatherTypeEnum[] weatherTypes = WeatherTypeEnum.values(); for (WeatherTypeEnum weatherTypeEnum : weatherTypes){ WeatherResultVO weatherResultVO= null; - WeatherDataSourceEnum dataSourceEnum = null; - if (WeatherDataSourceEnum.PANGU.getKey().equals(dataType)) { - dataSourceEnum = WeatherDataSourceEnum.PANGU; - weatherResultVO = weatherDataService.processWeatherData(weatherTypeEnum.getKey(), null, startTime, WeatherDataSourceEnum.PANGU); - }else if (WeatherDataSourceEnum.GRAPHCAST.getKey().equals(dataType)){ - dataSourceEnum = WeatherDataSourceEnum.GRAPHCAST; - weatherResultVO = weatherDataService.processWeatherData(weatherTypeEnum.getKey(), timeBatch, startTime, WeatherDataSourceEnum.GRAPHCAST); - } else if (WeatherDataSourceEnum.CRA40.getKey().equals(dataType)){ - dataSourceEnum = WeatherDataSourceEnum.CRA40; - weatherResultVO = weatherDataService.processWeatherData(weatherTypeEnum.getKey(), null, startTime, WeatherDataSourceEnum.CRA40); - } else if (WeatherDataSourceEnum.NCEP.getKey().equals(dataType)){ - dataSourceEnum = WeatherDataSourceEnum.NCEP; - weatherResultVO = weatherDataService.processWeatherData(weatherTypeEnum.getKey(), null, startTime, WeatherDataSourceEnum.NCEP); - } else if (WeatherDataSourceEnum.FNL.getKey().equals(dataType)){ - dataSourceEnum = WeatherDataSourceEnum.FNL; - weatherResultVO = weatherDataService.processWeatherData(weatherTypeEnum.getKey(),null, startTime, WeatherDataSourceEnum.FNL); - } else if (WeatherDataSourceEnum.T1H.getKey().equals(dataType)){ - dataSourceEnum = WeatherDataSourceEnum.T1H; - weatherResultVO = weatherDataService.processWeatherData(weatherTypeEnum.getKey(), timeBatch, startTime, WeatherDataSourceEnum.T1H); - }else if (WeatherDataSourceEnum.GFS.getKey().equals(dataType)){ - dataSourceEnum = WeatherDataSourceEnum.GFS; - weatherResultVO = weatherDataService.processWeatherData(weatherTypeEnum.getKey(), timeBatch, startTime, WeatherDataSourceEnum.GFS); + //如果是pangu和GRAPHCAST,缓存数据时,第一次需要加6,因为预测的是预测时间未来的6小时数据 + // 例如:预测时间是0,预测结果就从6小时开始 + if (WeatherDataSourceEnum.PANGU.getKey().equals(dataType) || WeatherDataSourceEnum.GRAPHCAST.getKey().equals(dataType)) { + if(!add_six_hour_flag){ + add_six_hour_flag = true; + startTime = startTime.plusHours(6); + } } - if(Objects.nonNull(weatherResultVO)){ - String key = String.format(CommonConstant.WEATHER_DATA_CACHE, dataSourceEnum.getValue(), weatherTypeEnum.getValue()); - String item = startTime.format(DateTimeFormatter.ofPattern("yyyyMMddHH")); - if (!redisUtil.hHasKey(key,item)) { - //数据缓存1天过期 - redisUtil.hset(key,item,weatherResultVO,3600*24); + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(WeatherData::getDataSource,this.dataType); + queryWrapper.eq(StrUtil.isNotBlank(timeBatch),WeatherData::getTimeBatch,timeBatch); + queryWrapper.eq(WeatherData::getDataStartTime,startTime); + WeatherData weatherData = weatherDataService.getOne(queryWrapper); + if(Objects.nonNull(weatherData)){ + weatherResultVO = weatherDataService.processWeatherData(weatherTypeEnum.getKey(),weatherData); + if(Objects.nonNull(weatherResultVO)){ + String time = startTime.format(DateTimeFormatter.ofPattern("yyyyMMddHH")); + WeatherDataSourceEnum dataSourceEnum = WeatherDataSourceEnum.getInfoByKey(dataType); + this.writeWeatherJson(cacheVariablePath,time,timeBatch,dataSourceEnum.getValue(),weatherTypeEnum.getValue(),JSONObject.toJSONString(weatherResultVO)); } } } @@ -94,4 +92,46 @@ public class CacheWeatherDataJob extends Thread { } } } + + /** + * 把气象数据生成json文件 + * @param cacheVariablePath + * @param time + * @param timeBatch + * @param dataType + * @param variable + * @param json + * @throws IOException + */ + public void writeWeatherJson( + String cacheVariablePath, + String time, + String timeBatch, + String dataType, + String variable, + String json) throws IOException { + + if (!time.matches("\\d{10}")) { + throw new IllegalArgumentException("时间必须为yyyyMMddHH格式"); + } + Path directory = Paths.get(cacheVariablePath).resolve(dataType).resolve(variable); + if(StrUtil.isNotBlank(timeBatch)){ + directory = directory.resolve(timeBatch); + } + Files.createDirectories(directory); + + Path target = directory.resolve(time + ".json.gz"); + Path temporary = directory.resolve(time + ".json.gz.tmp"); + + try (OutputStream output = Files.newOutputStream(temporary); + GZIPOutputStream gzip = new GZIPOutputStream(output)) { + gzip.write(json.getBytes(StandardCharsets.UTF_8)); + } + Files.move( + temporary, + target, + StandardCopyOption.REPLACE_EXISTING, + StandardCopyOption.ATOMIC_MOVE + ); + } } diff --git a/jeecg-module-weather/src/main/java/org/jeecg/service/WeatherDataService.java b/jeecg-module-weather/src/main/java/org/jeecg/service/WeatherDataService.java index 21047b6..8b8ca3b 100644 --- a/jeecg-module-weather/src/main/java/org/jeecg/service/WeatherDataService.java +++ b/jeecg-module-weather/src/main/java/org/jeecg/service/WeatherDataService.java @@ -2,6 +2,7 @@ package org.jeecg.service; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.IService; +import jakarta.servlet.http.HttpServletResponse; import org.jeecg.common.constant.enums.WeatherDataSourceEnum; import org.jeecg.common.system.query.PageRequest; import org.jeecg.modules.base.entity.WeatherData; @@ -12,7 +13,7 @@ import java.util.List; public interface WeatherDataService extends IService { - WeatherResultVO getWeatherData(Integer dataType, Integer weatherType, String timeBatch, LocalDateTime startTime,LocalDateTime endTime, int hour); + void getWeatherData(Integer dataType, Integer weatherType, String timeBatch, LocalDateTime startTime, LocalDateTime endTime, int hour, HttpServletResponse res); WeatherResultVO getWeatherDataPreview(Integer weatherId, Integer weatherType); WindDataLineVO getDataLine(Integer dataType, String timeBatch, LocalDateTime startTime, LocalDateTime endTime, double longitude, double latitude); List getWindRose(Integer dataType, String timeBatch, LocalDateTime startTime, LocalDateTime endTime,double longitude, double latitude); @@ -55,10 +56,8 @@ public interface WeatherDataService extends IService { /** * 处理气象数据 * @param weatherType - * @param timeBatch - * @param targetTime - * @param dataTypeEnum + * @param weatherData * @return */ - WeatherResultVO processWeatherData(Integer weatherType, String timeBatch, LocalDateTime targetTime, WeatherDataSourceEnum dataTypeEnum); + WeatherResultVO processWeatherData(Integer weatherType,WeatherData weatherData); } diff --git a/jeecg-module-weather/src/main/java/org/jeecg/service/impl/WeatherDataServiceImpl.java b/jeecg-module-weather/src/main/java/org/jeecg/service/impl/WeatherDataServiceImpl.java index 674bdd5..34b42fe 100644 --- a/jeecg-module-weather/src/main/java/org/jeecg/service/impl/WeatherDataServiceImpl.java +++ b/jeecg-module-weather/src/main/java/org/jeecg/service/impl/WeatherDataServiceImpl.java @@ -7,18 +7,17 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.lang3.StringUtils; -import org.jeecg.common.constant.CommonConstant; import org.jeecg.common.constant.WeatherStepConstants; import org.jeecg.common.constant.enums.*; import org.jeecg.common.exception.JeecgBootException; import org.jeecg.common.properties.SystemStorageProperties; import org.jeecg.common.system.query.PageRequest; import org.jeecg.common.util.NcUtil; -import org.jeecg.common.util.RedisUtil; import org.jeecg.job.CacheWeatherDataJob; import org.jeecg.modules.base.entity.WeatherData; import org.jeecg.modules.base.mapper.WeatherDataMapper; @@ -26,6 +25,8 @@ import org.jeecg.service.WeatherDataService; import org.jeecg.service.WeatherLinkedDataLogService; import org.jeecg.utils.WindRoseDataGenerator; import org.jeecg.vo.*; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import ucar.nc2.NetcdfFile; @@ -49,7 +50,6 @@ public class WeatherDataServiceImpl extends ServiceImpl queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(WeatherData::getDataStartTime, targetTime).eq(WeatherData::getDataSource,dataTypeEnum.getKey()); - if(StringUtils.isNotBlank(timeBatch)){ - queryWrapper.eq(WeatherData::getTimeBatch, timeBatch); - } - List weatherDataList = weatherDataMapper.selectList(queryWrapper); + @Override + public WeatherResultVO processWeatherData(Integer weatherType,WeatherData weatherData) { WeatherResultVO weatherResultVO = new WeatherResultVO(); - String filePath = getWeatherFilePath(weatherDataList, targetTime); + String filePath = weatherData.getFilePath(); validateFile(filePath); try (NetcdfFile ncFile = NetcdfFile.open(filePath)) { @@ -634,19 +638,19 @@ public class WeatherDataServiceImpl extends ServiceImpl value; - List>> windDataList = processWindData(weatherDataList, targetTime, dataTypeEnum); + List>> windDataList = processWindData(weatherData); processResultDataInternal(weatherResultVO, null, windDataList.get(0), windDataList.get(1), lonData, latData, converter); }else{ List> dataList; if (WeatherTypeEnum.TEMPERATURE.getKey().equals(weatherType)) { converter = value -> value - 273.15; - dataList = processVariableData(ncFile, dataTypeEnum.getKey(), WeatherTypeEnum.TEMPERATURE); + dataList = processVariableData(ncFile, weatherData.getDataSource(), WeatherTypeEnum.TEMPERATURE); } else if (WeatherTypeEnum.PRESSURE.getKey().equals(weatherType)) { converter = value -> value / 1000; - dataList = processVariableData(ncFile, dataTypeEnum.getKey(), WeatherTypeEnum.PRESSURE); + dataList = processVariableData(ncFile,weatherData.getDataSource(), WeatherTypeEnum.PRESSURE); } else if (WeatherTypeEnum.HUMIDITY.getKey().equals(weatherType)) { converter = value -> value; - dataList = processVariableData(ncFile, dataTypeEnum.getKey(), WeatherTypeEnum.HUMIDITY); + dataList = processVariableData(ncFile,weatherData.getDataSource(), WeatherTypeEnum.HUMIDITY); } else { throw new JeecgBootException("未知天气类型!"); } @@ -662,17 +666,16 @@ public class WeatherDataServiceImpl extends ServiceImpl>> processWindData(List weatherDataList, LocalDateTime targetTime, - WeatherDataSourceEnum dataTypeEnum) { + private List>> processWindData(WeatherData weatherData) { List>> windDataList = new ArrayList<>(); - String filePath = getWeatherFilePath(weatherDataList, targetTime); + String filePath = weatherData.getFilePath(); validateFile(filePath); try (NetcdfFile ncFile = NetcdfFile.open(filePath)) { List> u = NcUtil.get2DNCByName(ncFile, - WeatherVariableNameEnum.getValueByTypeAndKey(dataTypeEnum.getKey(), WeatherTypeEnum.WIND.getKey()), 0, 0); + WeatherVariableNameEnum.getValueByTypeAndKey(weatherData.getDataSource(), WeatherTypeEnum.WIND.getKey()), 0, 0); List> v = NcUtil.get2DNCByName(ncFile, - WeatherVariableNameEnum.getValueByTypeAndKey(dataTypeEnum.getKey(), WeatherTypeEnum.WIND.getKey() + 1), 0, 0); + WeatherVariableNameEnum.getValueByTypeAndKey(weatherData.getDataSource(), WeatherTypeEnum.WIND.getKey() + 1), 0, 0); windDataList.add(u); windDataList.add(v); } catch (IOException e) { diff --git a/jeecg-server-cloud/jeecg-consumer-start/src/main/java/org/jeecg/JeecgConsumerCloudApplication.java b/jeecg-server-cloud/jeecg-consumer-start/src/main/java/org/jeecg/JeecgConsumerCloudApplication.java index 6f2a88d..2a9a117 100644 --- a/jeecg-server-cloud/jeecg-consumer-start/src/main/java/org/jeecg/JeecgConsumerCloudApplication.java +++ b/jeecg-server-cloud/jeecg-consumer-start/src/main/java/org/jeecg/JeecgConsumerCloudApplication.java @@ -1,12 +1,20 @@ package org.jeecg; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.jeecg.common.base.BaseMap; import org.jeecg.common.constant.GlobalConstants; +import org.jeecg.common.properties.DataFusionProperties; +import org.jeecg.common.properties.TransportSimulationProperties; import org.jeecg.common.util.oConvertUtils; +import org.jeecg.modules.base.entity.TransportTask; +import org.jeecg.modules.base.entity.TransportTaskBackwardChild; +import org.jeecg.modules.base.mapper.TransportTaskBackwardChildMapper; import org.jeecg.rebuild.consumer.RebuildTaskConsumerHandler; import org.jeecg.transport.consumer.TranTaskConsumerHandler; +import org.jeecg.transport.flexparttask.BuildNcToSrsFile; +import org.jeecg.transport.service.TransportTaskService; import org.jeecg.weather.consumer.WeatherTaskConsumerHandler; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; @@ -18,6 +26,8 @@ import org.springframework.core.env.Environment; import org.springframework.data.redis.core.RedisTemplate; import java.net.InetAddress; import java.net.UnknownHostException; +import java.util.List; +import java.util.Objects; @Slf4j @SpringBootApplication @@ -28,6 +38,10 @@ public class JeecgConsumerCloudApplication extends SpringBootServletInitializer private final TranTaskConsumerHandler tranTaskConsumerHandler; private final RebuildTaskConsumerHandler rebuildTaskConsumerHandler; private final WeatherTaskConsumerHandler weatherTaskConsumerHandler; + private final TransportTaskService transportTaskService; + private final TransportTaskBackwardChildMapper taskBackwardChildMapper; + private final DataFusionProperties dataFusionProperties; + private final TransportSimulationProperties simulationProperties; @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { @@ -55,8 +69,21 @@ public class JeecgConsumerCloudApplication extends SpringBootServletInitializer params.put(GlobalConstants.HANDLER_NAME, GlobalConstants.LODER_ROUDER_HANDLER); //刷新网关 redisTemplate.convertAndSend(GlobalConstants.REDIS_TOPIC_NAME, params); - tranTaskConsumerHandler.startConsumerThread(); - rebuildTaskConsumerHandler.startConsumerThread(); - weatherTaskConsumerHandler.startConsumerThread(); +// tranTaskConsumerHandler.startConsumerThread(); +// rebuildTaskConsumerHandler.startConsumerThread(); +// weatherTaskConsumerHandler.startConsumerThread(); + TransportTask transportTask = transportTaskService.getById(35); + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(TransportTaskBackwardChild::getTaskId, transportTask.getId()); + List transportTaskBackwardChildren = taskBackwardChildMapper.selectList(queryWrapper); + transportTask.setBackwardChild(transportTaskBackwardChildren); + for (TransportTaskBackwardChild transportTaskChild : transportTask.getBackwardChild()){ + //如果是分析系统来的反演数据,会有样品id和样品类型会生成srs文件,如果是氙本地源系统新增的,没有生成srs文件,因为没有样品id和类型参数 + if(Objects.nonNull(transportTaskChild.getSampleId()) && Objects.nonNull(transportTaskChild.getSampleType())){ + BuildNcToSrsFile ncToSrsFile = new BuildNcToSrsFile(); + ncToSrsFile.init(dataFusionProperties,simulationProperties,transportTask,transportTaskChild,transportTaskChild.getReleaseAmount()); + ncToSrsFile.execute(); + } + } } } \ No newline at end of file