fix:1.修改播放数据返回格式

This commit is contained in:
panbaolin 2026-08-07 14:59:31 +08:00
parent 56afd228bb
commit e3fe064509
3 changed files with 27 additions and 35 deletions

View File

@ -72,6 +72,15 @@ public class CacheWeatherDataJob extends Thread {
startTime = startTime.plusHours(6);
}
}
WeatherDataSourceEnum dataSourceEnum = WeatherDataSourceEnum.getInfoByKey(dataType);
Path directory = Paths.get(cacheVariablePath).resolve(dataSourceEnum.getValue()).resolve(weatherTypeEnum.getValue());
if(StrUtil.isNotBlank(timeBatch)){
directory = directory.resolve(timeBatch);
}
Files.createDirectories(directory);
String time = startTime.format(DateTimeFormatter.ofPattern("yyyyMMddHH"));
Path target = directory.resolve(time + ".json.gz");
if(!Files.exists(target)){
LambdaQueryWrapper<WeatherData> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(WeatherData::getDataSource,this.dataType);
queryWrapper.eq(StrUtil.isNotBlank(timeBatch),WeatherData::getTimeBatch,timeBatch);
@ -80,9 +89,8 @@ public class CacheWeatherDataJob extends Thread {
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));
this.writeWeatherJson(target,directory,time,JSONObject.toJSONString(weatherResultVO));
}
}
}
}
@ -95,34 +103,18 @@ public class CacheWeatherDataJob extends Thread {
/**
* 把气象数据生成json文件
* @param cacheVariablePath
* @param time
* @param timeBatch
* @param dataType
* @param variable
* @param target
* @param directory
* @param json
* @throws IOException
*/
public void writeWeatherJson(
String cacheVariablePath,
Path target,
Path directory,
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));

View File

@ -74,10 +74,7 @@ public class WeatherDataServiceImpl extends ServiceImpl<WeatherDataMapper, Weath
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();
throw new RuntimeException(time+"气象数据不存在");
}else {
long fileSize = Files.size(targetFile);
res.setStatus(HttpServletResponse.SC_OK);

View File

@ -1,5 +1,6 @@
package org.jeecg.vo;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;
import java.util.List;
@ -18,7 +19,9 @@ public class WeatherResultVO {
private double minLong;
private int sn;
private int we;
@JSONField(name = "xspeed")
private double xSpeed ;
@JSONField(name = "yspeed")
private double ySpeed;
private List<List<Double>> dataList;
}