¶Ô±ÈÐÂÎļþ |
| | |
| | | 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("å 餿å"); |
| | | } |
| | | } |