燕山石化溯源三维电子沙盘-【后端】-服务
1
13693261870
2023-04-26 e68142dd60447fce6eb7cc251811c6b13311d3bc
1
已修改2个文件
51 ■■■■■ 文件已修改
src/main/java/com/yssh/controller/WeatherController.java 38 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapping/WeatherMapper.xml 13 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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("删除成功");
src/main/resources/mapping/WeatherMapper.xml
@@ -13,12 +13,13 @@
    <select id="query" resultMap="WeatherResult">
        select * from yssh_weather
        <where>
            <if test="begin != null and begin != ''">
                and Time &gt;= #{begin}
            </if>
            <if test="end != null and end != ''">
                and Time &lt;= #{end}
            </if>
            1 = 1
            <if test="begin != null">
                and str_to_date(time, '%Y-%m-%d-%H:%i:%S') >= #{begin}
            </if>
            <if test="end != null">
                and str_to_date(time, '%Y-%m-%d-%H:%i:%S') &lt;= #{end}
            </if>
        </where>
    </select>