1.完成解析气象文件获取数据起始时间并入库
This commit is contained in:
parent
061f8d8211
commit
c74fe7e633
|
@ -1,5 +1,6 @@
|
||||||
package org.jeecg.common.util;
|
package org.jeecg.common.util;
|
||||||
|
|
||||||
|
import lombok.val;
|
||||||
import ucar.ma2.Array;
|
import ucar.ma2.Array;
|
||||||
import ucar.ma2.ArrayDouble;
|
import ucar.ma2.ArrayDouble;
|
||||||
import ucar.ma2.DataType;
|
import ucar.ma2.DataType;
|
||||||
|
@ -251,4 +252,21 @@ public final class NcUtil {
|
||||||
return SPECIAL_VARS.contains(name) ? value :
|
return SPECIAL_VARS.contains(name) ? value :
|
||||||
Math.ceil(value * ROUNDING_FACTOR) / ROUNDING_FACTOR;
|
Math.ceil(value * ROUNDING_FACTOR) / ROUNDING_FACTOR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 读取GRIB2文件数据起始时间
|
||||||
|
* @param filePath
|
||||||
|
*/
|
||||||
|
public static String getReftime(String filePath){
|
||||||
|
try (NetcdfFile ncFile = NetcdfFile.open(filePath)) {
|
||||||
|
Variable variable = ncFile.findVariable("reftime_ISO");
|
||||||
|
if (variable != null) {
|
||||||
|
Array data = variable.read();
|
||||||
|
return data.getObject(0).toString();
|
||||||
|
}
|
||||||
|
}catch (Exception e){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -48,12 +48,6 @@ public class WeatherData {
|
||||||
@TableField(value = "data_start_time")
|
@TableField(value = "data_start_time")
|
||||||
private LocalDateTime dataStartTime;
|
private LocalDateTime dataStartTime;
|
||||||
|
|
||||||
/**
|
|
||||||
* 气象数据结束时间
|
|
||||||
*/
|
|
||||||
@TableField(value = "data_end_time")
|
|
||||||
private LocalDateTime dataEndTime;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 数据来源(1-盘古模型,2-graphcast,3-再分析数据)
|
* 数据来源(1-盘古模型,2-graphcast,3-再分析数据)
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -34,7 +34,9 @@ import java.math.RoundingMode;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.time.Instant;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZoneId;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -233,11 +235,18 @@ public class WeatherDataServiceImpl extends ServiceImpl<WeatherDataMapper, Weath
|
||||||
}else {
|
}else {
|
||||||
flag = true;
|
flag = true;
|
||||||
}
|
}
|
||||||
//获取文件数据开始日期
|
//处理气象文件数据开始时间和计算文件大小
|
||||||
//计算文件大小M
|
|
||||||
WeatherData queryResult = this.baseMapper.selectById(id);
|
WeatherData queryResult = this.baseMapper.selectById(id);
|
||||||
File dataFile = new File(storagePath);
|
File dataFile = new File(storagePath);
|
||||||
if(dataFile.exists() && dataFile.length()>0){
|
if(dataFile.exists() && dataFile.length()>0){
|
||||||
|
//获取文件数据开始日期
|
||||||
|
String reftime = NcUtil.getReftime(dataFile.getAbsolutePath());
|
||||||
|
if(StringUtils.isNotBlank(reftime)) {
|
||||||
|
Instant instant = Instant.parse(reftime);
|
||||||
|
LocalDateTime utcDateTime = LocalDateTime.ofInstant(instant, ZoneId.of("UTC"));
|
||||||
|
queryResult.setDataStartTime(utcDateTime);
|
||||||
|
}
|
||||||
|
//计算文件大小M
|
||||||
BigDecimal divideVal = new BigDecimal("1024");
|
BigDecimal divideVal = new BigDecimal("1024");
|
||||||
BigDecimal bg = new BigDecimal(dataFile.length());
|
BigDecimal bg = new BigDecimal(dataFile.length());
|
||||||
BigDecimal fileSize = bg.divide(divideVal).divide(divideVal).setScale(2, RoundingMode.HALF_UP);
|
BigDecimal fileSize = bg.divide(divideVal).divide(divideVal).setScale(2, RoundingMode.HALF_UP);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user