package com.yssh.controller; import com.yssh.entity.Weather; import com.yssh.service.IWeatherService; 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.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.util.ArrayList; import java.util.List; /** * @author wMeng * @ClassName YsshWeatherController * @Description TODO * @date 2022/10/30 13:21 * @Version 1.0 */ @Api(tags="天气") @RestController @RequestMapping("/weather") @SuppressWarnings("rawtypes") public class WeatherController { @Autowired private IWeatherService weatherService; @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){ List data = new ArrayList<>(); try { 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 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("删除成功"); } }