Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
457da7d6aa
|
|
@ -1,20 +1,14 @@
|
||||||
package org.jeecg.controller;
|
package org.jeecg.controller;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.codec.digest.DigestUtils;
|
|
||||||
import org.jeecg.common.api.vo.Result;
|
import org.jeecg.common.api.vo.Result;
|
||||||
import org.jeecg.common.aspect.annotation.AutoLog;
|
import org.jeecg.common.aspect.annotation.AutoLog;
|
||||||
import org.jeecg.common.constant.enums.T1hFilePrefixEnum;
|
|
||||||
import org.jeecg.common.constant.enums.WeatherDataSourceEnum;
|
|
||||||
import org.jeecg.common.constant.enums.WeatherFileSuffixEnum;
|
import org.jeecg.common.constant.enums.WeatherFileSuffixEnum;
|
||||||
import org.jeecg.common.properties.SystemStorageProperties;
|
|
||||||
import org.jeecg.common.properties.T1hDownloadProperties;
|
|
||||||
import org.jeecg.common.system.query.PageRequest;
|
import org.jeecg.common.system.query.PageRequest;
|
||||||
import org.jeecg.job.DownloadT1hJob;
|
import org.jeecg.job.DownloadT1hJob;
|
||||||
import org.jeecg.modules.base.entity.WeatherData;
|
import org.jeecg.modules.base.entity.WeatherData;
|
||||||
|
|
@ -22,31 +16,12 @@ import org.jeecg.service.WeatherDataService;
|
||||||
import org.jeecg.vo.FileExistVo;
|
import org.jeecg.vo.FileExistVo;
|
||||||
import org.jeecg.vo.FileUploadResultVo;
|
import org.jeecg.vo.FileUploadResultVo;
|
||||||
import org.jeecg.vo.FileVo;
|
import org.jeecg.vo.FileVo;
|
||||||
import org.jeecg.vo.WeatherResultVO;
|
|
||||||
import org.springframework.format.annotation.DateTimeFormat;
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
|
||||||
import org.springframework.util.StopWatch;
|
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import ucar.ma2.Array;
|
|
||||||
import ucar.nc2.NetcdfFile;
|
|
||||||
import ucar.nc2.Variable;
|
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.Year;
|
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.concurrent.TimeoutException;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Validated
|
@Validated
|
||||||
|
|
@ -142,4 +117,10 @@ public class WeatherDataController {
|
||||||
public void downloadT1HFile() {
|
public void downloadT1HFile() {
|
||||||
downloadT1hJob.downloadT1HFile();
|
downloadT1hJob.downloadT1HFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("handleStaticDataToDB")
|
||||||
|
public Result<?> handleStaticDataToDB(String path,Integer dataSource){
|
||||||
|
weatherDataService.handleStaticDataToDB(path,dataSource);
|
||||||
|
return Result.OK();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -51,4 +51,8 @@ public interface WeatherDataService extends IService<WeatherData> {
|
||||||
*/
|
*/
|
||||||
void delete(List<String> ids);
|
void delete(List<String> ids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理静态气象数据入库接口,比上传快
|
||||||
|
*/
|
||||||
|
void handleStaticDataToDB(String path,Integer dataSource);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.codec.digest.DigestUtils;
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.jeecg.common.constant.WeatherPrefixConstants;
|
import org.jeecg.common.constant.WeatherPrefixConstants;
|
||||||
|
|
@ -401,6 +402,54 @@ public class WeatherDataServiceImpl extends ServiceImpl<WeatherDataMapper, Weath
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理静态气象数据入库接口,比上传快
|
||||||
|
*/
|
||||||
|
@Transactional(rollbackFor = RuntimeException.class)
|
||||||
|
@Override
|
||||||
|
public void handleStaticDataToDB(String path,Integer dataSource) {
|
||||||
|
File[] files = FileUtil.file(path).listFiles();
|
||||||
|
for(File file : files) {
|
||||||
|
if(file.getName().endsWith(".grib2") || file.getName().endsWith(".grib") || file.getName().endsWith(".grb2")) {
|
||||||
|
InputStream is = null;
|
||||||
|
try{
|
||||||
|
is = new FileInputStream(file);
|
||||||
|
WeatherData weatherData = new WeatherData();
|
||||||
|
weatherData.setFileName(file.getName());
|
||||||
|
weatherData.setFileExt(file.getName().substring(file.getName().lastIndexOf(".")+1));
|
||||||
|
weatherData.setDataSource(dataSource);
|
||||||
|
weatherData.setFilePath(file.getAbsolutePath());
|
||||||
|
weatherData.setMd5Value(DigestUtils.md5Hex(is));
|
||||||
|
weatherData.setShareTotal(1);
|
||||||
|
//获取文件数据开始日期
|
||||||
|
String reftime = NcUtil.getReftime(file.getAbsolutePath());
|
||||||
|
if(StringUtils.isBlank(reftime)) {
|
||||||
|
throw new JeecgFileUploadException("解析气象文件起始时间数据异常,此文件可能损坏");
|
||||||
|
}
|
||||||
|
Instant instant = Instant.parse(reftime);
|
||||||
|
LocalDateTime utcDateTime = LocalDateTime.ofInstant(instant, ZoneId.of("UTC"));
|
||||||
|
weatherData.setDataStartTime(utcDateTime);
|
||||||
|
//计算文件大小M
|
||||||
|
BigDecimal divideVal = new BigDecimal("1024");
|
||||||
|
BigDecimal bg = new BigDecimal(file.length());
|
||||||
|
BigDecimal fileSize = bg.divide(divideVal).divide(divideVal).setScale(2, RoundingMode.HALF_UP);
|
||||||
|
weatherData.setFileSize(fileSize.doubleValue());
|
||||||
|
this.baseMapper.insert(weatherData);
|
||||||
|
}catch (Exception e){
|
||||||
|
throw new RuntimeException(e.getMessage());
|
||||||
|
}finally {
|
||||||
|
if(is != null){
|
||||||
|
try {
|
||||||
|
is.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件合并
|
* 文件合并
|
||||||
* @param fileVo
|
* @param fileVo
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user