燕山石化溯源三维电子沙盘-【后端】-服务
1
13693261870
2024-11-20 8185e5cdc2bbdf7fb4ca46a10864106893a01ed3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package com.yssh.controller;
 
import com.yssh.config.InitConfig;
import com.yssh.entity.Weather;
import com.yssh.service.WeatherService;
import com.yssh.utils.CacheUtils;
import com.yssh.utils.Result;
 
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
 
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
 
@Api(tags="天气")
@RestController
@RequestMapping("/weather")
@SuppressWarnings("rawtypes")
public class WeatherController {
    @Resource
    private WeatherService 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"),
    })
    @GetMapping("/query/{begin}/{end}")
    public Result query(@PathVariable("begin") String begin, @PathVariable("end") String end) {
        try {
            if (null != begin && begin.length() != 19) {
                begin = null;
            }
            if (null != end && end.length() != 19) {
                end = null;
            }
            if (null == begin) {
                Calendar calendar = Calendar.getInstance();
                calendar.add(Calendar.DAY_OF_MONTH, -30);
                begin = dateFormat.format(calendar.getTime());
            }
            if (null == end) {
                end = dateFormat.format(InitConfig.getDate());
            }
 
            //List<Weather> list = weatherService.query(begin, end);
            String key = CacheUtils.getMd5("weatherService.query." + begin + "." + end);
            List<Weather> list = CacheUtils.getListByKey(key);
            if (null == list) {
                list = weatherService.query(begin, end);
                CacheUtils.putListByKey(key, list);
            }
 
            return Result.OK(list);
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }
 
    @GetMapping("/getAll")
    @ApiOperation(value = "查询所有天气数据", notes = "查询所有天气详细数据")
    public Result getAll() {
        List<Weather> list = weatherService.getAll();
        return Result.OK(list);
    }
 
    @PostMapping("/insert")
    @ApiOperation("插入数据")
    public Result insert(@RequestBody Weather ysshWeather) {
        int i = weatherService.insert(ysshWeather);
        if (i == 0) {
            return Result.error("插入失败");
        }
        return Result.OK("插入成功");
    }
 
    @ApiOperation("删除数据")
    @ApiImplicitParam(name = "id", value = "编号", required = true, type = "String")
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable("id") String id) {
        int i = weatherService.delete(id);
        if (i == 0) {
            return Result.error("删除失败");
        }
        return Result.OK("删除成功");
    }
}