fix:1.再次优化天气预报播放功能,把缓存数据存入磁盘,通过直接直接查找,性能不到70毫秒即返回2.添加定时清除缓存数据功能

This commit is contained in:
panbaolin 2026-08-07 11:51:30 +08:00
parent 79fd294f78
commit 197d6ff6cb
8 changed files with 234 additions and 114 deletions

View File

@ -339,9 +339,4 @@ public interface CommonConstant {
*/
String BUILD_TASK_STATE_PRE = "build_task_";
/***
* weather_data:数据类型ncepfnl:变量类型(湿)
*/
String WEATHER_DATA_CACHE = "weather_data:%s:%s";
}

View File

@ -98,4 +98,9 @@ public class SystemStorageProperties {
* 天气预测docker容器http请求 url
*/
private String weatherForecastUri;
/**
* 气象数据json缓存路径
*/
private String gribDataVariableCachePath;
}

View File

@ -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);
}
}

View File

@ -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);
}
/**

View File

@ -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<WeatherData> 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
);
}
}

View File

@ -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<WeatherData> {
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<WindRoseData> getWindRose(Integer dataType, String timeBatch, LocalDateTime startTime, LocalDateTime endTime,double longitude, double latitude);
@ -55,10 +56,8 @@ public interface WeatherDataService extends IService<WeatherData> {
/**
* 处理气象数据
* @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);
}

View File

@ -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<WeatherDataMapper, Weath
private final WeatherDataMapper weatherDataMapper;
private final WeatherLinkedDataLogService weatherLinkedDataLogService;
private final SystemStorageProperties systemStorageProperties;
private final RedisUtil redisUtil;
/**
* 根据类型和小时数获取天气数据
@ -60,17 +60,48 @@ public class WeatherDataServiceImpl extends ServiceImpl<WeatherDataMapper, Weath
* @return 天气数据列表
*/
@Override
public WeatherResultVO getWeatherData(Integer dataType, Integer weatherType, String timeBatch, LocalDateTime startTime,LocalDateTime endTime, int hour) {
WeatherDataSourceEnum dataSourceEnum = WeatherDataSourceEnum.getInfoByKey(dataType);
WeatherTypeEnum weatherTypeEnum = WeatherTypeEnum.getInfoByKey(weatherType);
public void getWeatherData(Integer dataType, Integer weatherType, String timeBatch, LocalDateTime startTime, LocalDateTime endTime, int hour, HttpServletResponse res) {
try {
WeatherDataSourceEnum dataSourceEnum = WeatherDataSourceEnum.getInfoByKey(dataType);
WeatherTypeEnum weatherTypeEnum = WeatherTypeEnum.getInfoByKey(weatherType);
String key = String.format(CommonConstant.WEATHER_DATA_CACHE, dataSourceEnum.getValue(), weatherTypeEnum.getValue());
startTime = startTime.plusHours(hour);
String item = startTime.format(DateTimeFormatter.ofPattern("yyyyMMddHH"));
if (!redisUtil.hHasKey(key,item)) {
throw new RuntimeException(item+"气象数据不存在");
String cacheVariablePath = systemStorageProperties.getGribDataVariableCachePath();
Path directory = Paths.get(cacheVariablePath).resolve(dataSourceEnum.getValue()).resolve(weatherTypeEnum.getValue());
if(StrUtil.isNotBlank(timeBatch)){
directory = directory.resolve(timeBatch);
}
startTime = startTime.plusHours(hour);
String time = startTime.format(DateTimeFormatter.ofPattern("yyyyMMddHH"));
Path targetFile = directory.resolve(time + ".json.gz");
if (!Files.exists(targetFile)) {
res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
res.setContentType("text/plain;charset=UTF-8");
res.getWriter().write(time+"气象数据不存在");
res.flushBuffer();
}else {
long fileSize = Files.size(targetFile);
res.setStatus(HttpServletResponse.SC_OK);
res.setContentType(MediaType.APPLICATION_JSON_VALUE);
res.setHeader(HttpHeaders.CONTENT_ENCODING, "gzip");
res.setContentLengthLong(fileSize);
res.setHeader(
HttpHeaders.CACHE_CONTROL,
"public, max-age=21600"
);
res.setHeader(
"X-Content-Type-Options",
"nosniff"
);
try (InputStream inputStream = Files.newInputStream(targetFile)) {
inputStream.transferTo(res.getOutputStream());
res.flushBuffer();
}
}
} catch (IOException e) {
String errLog = "处理气象数据出现问题";
log.error(errLog,e);
throw new RuntimeException(errLog);
}
return (WeatherResultVO)redisUtil.hget(key, item);
}
/**
@ -83,31 +114,11 @@ public class WeatherDataServiceImpl extends ServiceImpl<WeatherDataMapper, Weath
public WeatherResultVO getWeatherDataPreview(Integer weatherId, Integer weatherType) {
Objects.requireNonNull(weatherId, "天气数据ID不能为空");
WeatherData weatherData = this.baseMapper.selectById(weatherId);
Integer dataType = weatherData.getDataSource();
LocalDateTime targetTime = weatherData.getDataStartTime();
try {
if (WeatherDataSourceEnum.PANGU.getKey() == dataType) {
return processWeatherData(weatherType, null, targetTime, WeatherDataSourceEnum.PANGU);
}else if (WeatherDataSourceEnum.GRAPHCAST.getKey() == dataType){
return processWeatherData(weatherType, null, targetTime, WeatherDataSourceEnum.GRAPHCAST);
} else if (WeatherDataSourceEnum.CRA40.getKey() == dataType){
return processWeatherData(weatherType, null, targetTime, WeatherDataSourceEnum.CRA40);
} else if (WeatherDataSourceEnum.NCEP.getKey() == dataType){
return processWeatherData(weatherType, null, targetTime, WeatherDataSourceEnum.NCEP);
} else if (WeatherDataSourceEnum.FNL.getKey() == dataType){
return processWeatherData(weatherType, null, targetTime, WeatherDataSourceEnum.FNL);
} else if (WeatherDataSourceEnum.T1H.getKey() == dataType){
return processWeatherData(weatherType, null, targetTime, WeatherDataSourceEnum.T1H);
}else if (WeatherDataSourceEnum.GFS.getKey() == dataType){
return processWeatherData(weatherType, null, targetTime, WeatherDataSourceEnum.GFS);
}
} catch (JeecgBootException e) {
throw e;
} catch (Exception e) {
log.error("处理天气数据失败", e);
throw new JeecgBootException("处理天气数据失败", e);
WeatherResultVO weatherResultVO = processWeatherData(weatherType, weatherData);
if(Objects.nonNull(weatherResultVO)){
return weatherResultVO;
}
throw new JeecgBootException("没有该类型的气象数据");
throw new RuntimeException("该气象数据文件不存在!");
}
/**
@ -495,7 +506,7 @@ public class WeatherDataServiceImpl extends ServiceImpl<WeatherDataMapper, Weath
throw new RuntimeException("此时间范围无气象数据");
}
CacheWeatherDataJob weatherDataJob = new CacheWeatherDataJob();
weatherDataJob.init(this,redisUtil,dataType,timeBatch,startTime,endTime);
weatherDataJob.init(this,dataType,timeBatch,startTime,endTime,systemStorageProperties.getGribDataVariableCachePath());
weatherDataJob.setName("cacheWeatherDataJob");
weatherDataJob.start();
}
@ -610,20 +621,13 @@ public class WeatherDataServiceImpl extends ServiceImpl<WeatherDataMapper, Weath
/**
* 处理气象数据
* @param weatherType
* @param timeBatch
* @param targetTime
* @param dataTypeEnum
* @param weatherData
* @return
*/
public WeatherResultVO processWeatherData(Integer weatherType, String timeBatch, LocalDateTime targetTime, WeatherDataSourceEnum dataTypeEnum) {
LambdaQueryWrapper<WeatherData> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(WeatherData::getDataStartTime, targetTime).eq(WeatherData::getDataSource,dataTypeEnum.getKey());
if(StringUtils.isNotBlank(timeBatch)){
queryWrapper.eq(WeatherData::getTimeBatch, timeBatch);
}
List<WeatherData> 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<WeatherDataMapper, Weath
ValueConverter converter = null;
if (WeatherTypeEnum.WIND.getKey().equals(weatherType)) {
converter = value -> value;
List<List<List<Double>>> windDataList = processWindData(weatherDataList, targetTime, dataTypeEnum);
List<List<List<Double>>> windDataList = processWindData(weatherData);
processResultDataInternal(weatherResultVO, null, windDataList.get(0), windDataList.get(1), lonData, latData, converter);
}else{
List<List<Double>> 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<WeatherDataMapper, Weath
/**
* 处理风场数据
*/
private List<List<List<Double>>> processWindData(List<WeatherData> weatherDataList, LocalDateTime targetTime,
WeatherDataSourceEnum dataTypeEnum) {
private List<List<List<Double>>> processWindData(WeatherData weatherData) {
List<List<List<Double>>> windDataList = new ArrayList<>();
String filePath = getWeatherFilePath(weatherDataList, targetTime);
String filePath = weatherData.getFilePath();
validateFile(filePath);
try (NetcdfFile ncFile = NetcdfFile.open(filePath)) {
List<List<Double>> u = NcUtil.get2DNCByName(ncFile,
WeatherVariableNameEnum.getValueByTypeAndKey(dataTypeEnum.getKey(), WeatherTypeEnum.WIND.getKey()), 0, 0);
WeatherVariableNameEnum.getValueByTypeAndKey(weatherData.getDataSource(), WeatherTypeEnum.WIND.getKey()), 0, 0);
List<List<Double>> 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) {

View File

@ -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<TransportTaskBackwardChild> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(TransportTaskBackwardChild::getTaskId, transportTask.getId());
List<TransportTaskBackwardChild> 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();
}
}
}
}