1.添加分页查询气象数据接口
This commit is contained in:
		
							parent
							
								
									5cb6ee52f8
								
							
						
					
					
						commit
						0b9d05678b
					
				|  | @ -1,5 +1,6 @@ | |||
| package org.jeecg.controller; | ||||
| 
 | ||||
| import com.baomidou.mybatisplus.core.metadata.IPage; | ||||
| import io.swagger.v3.oas.annotations.Operation; | ||||
| import jakarta.validation.constraints.NotBlank; | ||||
| import lombok.RequiredArgsConstructor; | ||||
|  | @ -7,11 +8,14 @@ import org.apache.commons.codec.digest.DigestUtils; | |||
| import org.jeecg.common.api.vo.Result; | ||||
| import org.jeecg.common.aspect.annotation.AutoLog; | ||||
| import org.jeecg.common.constant.enums.WeatherFileSuffixEnum; | ||||
| import org.jeecg.common.system.query.PageRequest; | ||||
| import org.jeecg.modules.base.entity.WeatherData; | ||||
| import org.jeecg.service.WeatherDataService; | ||||
| import org.jeecg.vo.FileExistVo; | ||||
| import org.jeecg.vo.FileUploadResultVo; | ||||
| import org.jeecg.vo.FileVo; | ||||
| import org.jeecg.vo.WeatherResultVO; | ||||
| import org.springframework.format.annotation.DateTimeFormat; | ||||
| import org.springframework.validation.annotation.Validated; | ||||
| import org.springframework.web.bind.annotation.*; | ||||
| import ucar.ma2.Array; | ||||
|  | @ -21,8 +25,11 @@ import ucar.nc2.Variable; | |||
| import java.io.FileInputStream; | ||||
| import java.io.IOException; | ||||
| import java.io.InputStream; | ||||
| import java.time.LocalDate; | ||||
| import java.time.LocalDateTime; | ||||
| import java.util.HashMap; | ||||
| import java.util.List; | ||||
| import java.util.Map; | ||||
| 
 | ||||
| @Validated | ||||
| @RestController | ||||
|  | @ -33,23 +40,36 @@ public class WeatherDataController { | |||
|     private final WeatherDataService weatherDataService; | ||||
| 
 | ||||
| 
 | ||||
|     @AutoLog(value = "分页查询气象文件数据") | ||||
|     @Operation(summary = "分页查询气象文件数据") | ||||
|     @GetMapping("page") | ||||
|     public Result<?> page(PageRequest pageRequest, String fileExt, Integer dataSource, | ||||
|                           @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate startDate, | ||||
|                           @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate endDate) { | ||||
|         IPage<WeatherData> page = weatherDataService.page(pageRequest,fileExt,dataSource,startDate,endDate); | ||||
|         Map<String, Object> rspData = new HashMap<>(); | ||||
|         rspData.put("rows", page.getRecords()); | ||||
|         rspData.put("total", page.getTotal()); | ||||
|         return Result.OK(rspData); | ||||
|     } | ||||
| 
 | ||||
|     @AutoLog(value = "验证文件是否存在") | ||||
|     @Operation(summary = "验证文件是否存在") | ||||
|     @GetMapping("verifyFileExist") | ||||
|     public FileExistVo verifyFileExist(@NotBlank(message = "文件MD5值不能为空") String fileMD5Value) { | ||||
|     public Result<?> verifyFileExist(@NotBlank(message = "文件MD5值不能为空") String fileMD5Value) { | ||||
|         FileExistVo fileExist = weatherDataService.verifyFileExist(fileMD5Value); | ||||
|         return fileExist; | ||||
|         return Result.ok(fileExist); | ||||
|     } | ||||
| 
 | ||||
|     @AutoLog(value = "上传文件") | ||||
|     @Operation(summary = "上传文件") | ||||
|     @PostMapping("uploadFile") | ||||
|     public FileUploadResultVo uploadFile(FileVo fileVo){ | ||||
|     public Result<?> uploadFile(FileVo fileVo){ | ||||
|         if (!fileVo.getFileExt().equals(WeatherFileSuffixEnum.GRIB.getValue()) && !fileVo.getFileExt().equals(WeatherFileSuffixEnum.GRIB2.getValue())){ | ||||
|             throw new RuntimeException("不支持当前上传的文件类型!"); | ||||
|         } | ||||
|         FileUploadResultVo resultVo = weatherDataService.uploadFile(fileVo); | ||||
|         return resultVo; | ||||
|         return Result.ok(resultVo); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|  | @ -59,7 +79,7 @@ public class WeatherDataController { | |||
|     @AutoLog(value = "气象预测-气象数据查询") | ||||
|     @Operation(summary = "气象预测-气象数据查询") | ||||
|     @GetMapping(value = "getWeatherData") | ||||
|     public Result<WeatherResultVO> getWeatherData(Integer type, | ||||
|     public Result<?> getWeatherData(Integer type, | ||||
|                                                   LocalDateTime startTime, | ||||
|                                                   int hour) { | ||||
|         return Result.OK(weatherDataService.getWeatherData(type,startTime,hour)); | ||||
|  | @ -81,22 +101,22 @@ public class WeatherDataController { | |||
| 
 | ||||
|     public static void main(String[] args) { | ||||
|         //reftime_ISO | ||||
|         String filePath = "F:\\工作\\五木\\放射性核素监测数据综合分析及氙本底源解析系统\\其他资料\\气象数据\\中国CRA40再分析数据\\CRA40\\20250523\\CRA40_AVO_2025052300_GLB_0P25_HOUR_V1_0_0.grib2"; | ||||
|         String filePath = "F:\\工作\\五木\\放射性核素监测数据综合分析及氙本底源解析系统\\其他资料\\气象数据\\中国CRA40再分析数据\\CRA40\\20250524\\CRA40_AVO_2025052418_GLB_0P25_HOUR_V1_0_0.grib2"; | ||||
|         String filePath1 = "F:\\工作\\五木\\放射性核素监测数据综合分析及氙本底源解析系统\\其他资料\\气象数据\\中国CRA40再分析数据\\GRAPES\\2024110100\\Z_NAFP_C_BABJ_20241101000000_P_NWPC-GRAPES-GFS-HNEHE-00000.grib2"; | ||||
|         String filePath2 = "F:\\工作\\五木\\放射性核素监测数据综合分析及氙本底源解析系统\\其他资料\\气象数据\\盘古模型预测数据\\panguweather_2025073106.grib"; | ||||
| //        try { | ||||
| //            String md5 = calculateMD5("F:\\工作\\五木\\放射性核素监测数据综合分析及氙本底源解析系统\\其他资料\\气象数据\\中国CRA40再分析数据\\CRA40\\20250523\\CRA40_AVO_2025052300_GLB_0P25_HOUR_V1_0_0.grib2"); | ||||
| //            System.out.println("MD5: " + md5); | ||||
| //        } catch (IOException e) { | ||||
| //            e.printStackTrace(); | ||||
| //        } | ||||
|         try (NetcdfFile ncFile = NetcdfFile.open(filePath2)) { | ||||
|             Variable variable = ncFile.findVariable("reftime_ISO"); | ||||
|             if (variable != null) { | ||||
|                 Array data = variable.read(); | ||||
|                 System.out.println(variable.getFullName()); | ||||
|                 System.out.println(data.getObject(0)); | ||||
|             } | ||||
|         try { | ||||
|             String md5 = calculateMD5(filePath); | ||||
|             System.out.println("MD5: " + md5); | ||||
|         } catch (IOException e) { | ||||
|             e.printStackTrace(); | ||||
|         } | ||||
| //        try (NetcdfFile ncFile = NetcdfFile.open(filePath2)) { | ||||
| //            Variable variable = ncFile.findVariable("reftime_ISO"); | ||||
| //            if (variable != null) { | ||||
| //                Array data = variable.read(); | ||||
| //                System.out.println(variable.getFullName()); | ||||
| //                System.out.println(data.getObject(0)); | ||||
| //            } | ||||
| //            int index = 0; | ||||
| //            for (Variable variable : ncFile.getVariables()) { | ||||
| //                if (variable != null) { | ||||
|  | @ -109,8 +129,8 @@ public class WeatherDataController { | |||
| //                    index++; | ||||
| //                } | ||||
| //            } | ||||
|         }catch (Exception e){ | ||||
| 
 | ||||
|         } | ||||
| //        }catch (Exception e){ | ||||
| // | ||||
| //        } | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -8,6 +8,7 @@ import org.jeecg.vo.FileUploadResultVo; | |||
| import org.jeecg.vo.FileVo; | ||||
| import org.jeecg.vo.WeatherResultVO; | ||||
| 
 | ||||
| import java.time.LocalDate; | ||||
| import java.time.LocalDateTime; | ||||
| import java.util.List; | ||||
| 
 | ||||
|  | @ -20,11 +21,11 @@ public interface WeatherDataService { | |||
|      * @param pageRequest | ||||
|      * @param fileExt | ||||
|      * @param dataSource | ||||
|      * @param startTime | ||||
|      * @param endTime | ||||
|      * @param startDate | ||||
|      * @param endDate | ||||
|      * @return | ||||
|      */ | ||||
|     IPage<WeatherData> page(PageRequest pageRequest,String fileExt,Integer dataSource,LocalDateTime startTime,LocalDateTime endTime); | ||||
|     IPage<WeatherData> page(PageRequest pageRequest, String fileExt, Integer dataSource, LocalDate startDate, LocalDate endDate); | ||||
| 
 | ||||
|     /** | ||||
|      * 验证文件是否存在 | ||||
|  |  | |||
|  | @ -40,6 +40,7 @@ import java.nio.file.Files; | |||
| import java.nio.file.Path; | ||||
| import java.nio.file.Paths; | ||||
| import java.time.Instant; | ||||
| import java.time.LocalDate; | ||||
| import java.time.LocalDateTime; | ||||
| import java.time.ZoneId; | ||||
| import java.util.ArrayList; | ||||
|  | @ -154,17 +155,25 @@ public class WeatherDataServiceImpl extends ServiceImpl<WeatherDataMapper, Weath | |||
|      * @param pageRequest | ||||
|      * @param fileExt | ||||
|      * @param dataSource | ||||
|      * @param startTime | ||||
|      * @param endTime | ||||
|      * @param startDate | ||||
|      * @param endDate | ||||
|      * @return | ||||
|      */ | ||||
|     @Override | ||||
|     public IPage<WeatherData> page(PageRequest pageRequest, String fileExt, Integer dataSource, LocalDateTime startTime, LocalDateTime endTime) { | ||||
|     public IPage<WeatherData> page(PageRequest pageRequest, String fileExt, Integer dataSource, LocalDate startDate, LocalDate endDate) { | ||||
|         LocalDateTime startTime = null; | ||||
|         if(Objects.nonNull(startDate)){ | ||||
|             startTime = LocalDateTime.of(startDate.getYear(), startDate.getMonth(), startDate.getDayOfMonth(), 0, 0, 0); | ||||
|         } | ||||
|         LocalDateTime endTime = null; | ||||
|         if(Objects.nonNull(endDate)){ | ||||
|             endTime = LocalDateTime.of(endDate.getYear(), endDate.getMonth(), endDate.getDayOfMonth(), 23, 59, 59); | ||||
|         } | ||||
|         LambdaQueryWrapper<WeatherData> queryWrapper = new LambdaQueryWrapper<>(); | ||||
|         queryWrapper.eq(Objects.nonNull(dataSource),WeatherData::getDataSource, dataSource); | ||||
|         queryWrapper.between((Objects.nonNull(startTime) && Objects.nonNull(endTime)),WeatherData::getDataStartTime,startTime,endTime); | ||||
|         queryWrapper.eq(StringUtils.isNotBlank(fileExt),WeatherData::getFileExt, fileExt); | ||||
| 
 | ||||
|         queryWrapper.select(WeatherData::getId,WeatherData::getFileName,WeatherData::getFileSize,WeatherData::getDataSource,WeatherData::getFileExt,WeatherData::getDataStartTime,WeatherData::getFilePath); | ||||
|         IPage<WeatherData> iPage = new Page<>(pageRequest.getPageNum(),pageRequest.getPageSize()); | ||||
|         return this.baseMapper.selectPage(iPage, queryWrapper); | ||||
|     } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 panbaolin
						panbaolin