From e68142dd60447fce6eb7cc251811c6b13311d3bc Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期三, 26 四月 2023 14:49:44 +0800
Subject: [PATCH] 1

---
 src/main/java/com/yssh/controller/WeatherController.java |   38 +++++++++++++++++++++++++++-----------
 1 files changed, 27 insertions(+), 11 deletions(-)

diff --git a/src/main/java/com/yssh/controller/WeatherController.java b/src/main/java/com/yssh/controller/WeatherController.java
index 839db18..f84a16a 100644
--- a/src/main/java/com/yssh/controller/WeatherController.java
+++ b/src/main/java/com/yssh/controller/WeatherController.java
@@ -12,7 +12,9 @@
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import java.text.SimpleDateFormat;
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -30,32 +32,46 @@
     @Autowired
     private IWeatherService weatherService;
 
+    private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HH:00:00");
+
     @ApiOperation(value = "鏃堕棿鏌ヨ澶╂皵鏁版嵁", notes = "鏍规嵁寮�濮嬫椂闂村強鍏剁粨鏉熸椂闂存煡璇㈠ぉ姘旇缁嗕俊鎭�")
     @ApiImplicitParams({
-        @ApiImplicitParam(name = "begin", value = "鐐逛綅鍚嶇О", required = true, type = "String"),
-        @ApiImplicitParam(name = "end", value = "鐐逛綅绫诲瀷", required = true, type = "String"),
+            @ApiImplicitParam(name = "begin", value = "鐐逛綅鍚嶇О", required = true, type = "String"),
+            @ApiImplicitParam(name = "end", value = "鐐逛綅绫诲瀷", required = true, type = "String"),
     })
     @GetMapping("/query/{begin}/{end}")
-    public Result query(@PathVariable("begin") String begin,@PathVariable("end") String end){
+    public Result query(@PathVariable("begin") String begin, @PathVariable("end") String end) {
         List<Weather> data = new ArrayList<>();
         try {
-            data = weatherService.query(begin,end);
-        }catch (Exception e){
+            if (null != begin && begin.length() != 19) {
+                begin = null;
+            }
+            if (null != end && end.length() != 19) {
+                end = null;
+            }
+            if (null == begin && null == end) {
+                begin = dateFormat.format(new Date());
+            }
+
+            data = weatherService.query(begin, end);
+        } catch (Exception e) {
             return Result.error(e.getMessage());
         }
         return Result.OK(data);
     }
+
     @GetMapping("/getAll")
     @ApiOperation(value = "鏌ヨ鎵�鏈夊ぉ姘旀暟鎹�", notes = "鏌ヨ鎵�鏈夊ぉ姘旇缁嗘暟鎹�")
-    public Result getAll(){
-        List<Weather> list =  weatherService.getAll();
+    public Result getAll() {
+        List<Weather> list = weatherService.getAll();
         return Result.OK(list);
     }
+
     @PostMapping("/insert")
     @ApiOperation("鎻掑叆鏁版嵁")
-    public Result insert(@RequestBody Weather ysshWeather){
+    public Result insert(@RequestBody Weather ysshWeather) {
         int i = weatherService.insert(ysshWeather);
-        if(i == 0){
+        if (i == 0) {
             return Result.error("鎻掑叆澶辫触");
         }
         return Result.OK("鎻掑叆鎴愬姛");
@@ -64,9 +80,9 @@
     @ApiOperation("鍒犻櫎鏁版嵁")
     @ApiImplicitParam(name = "id", value = "缂栧彿", required = true, type = "String")
     @DeleteMapping("/delete/{id}")
-    public Result delete(@PathVariable("id") String id){
+    public Result delete(@PathVariable("id") String id) {
         int i = weatherService.delete(id);
-        if(i == 0){
+        if (i == 0) {
             return Result.error("鍒犻櫎澶辫触");
         }
         return Result.OK("鍒犻櫎鎴愬姛");

--
Gitblit v1.9.3