| | |
| | | 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 javax.annotation.Resource; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @author wMeng |
| | | * @ClassName YsshWeatherController |
| | | * @Description TODO |
| | | * @date 2022/10/30 13:21 |
| | | * @Version 1.0 |
| | | */ |
| | | @Api(tags="天气") |
| | | @RestController |
| | | @RequestMapping("/weather") |
| | |
| | | }) |
| | | @GetMapping("/query/{begin}/{end}") |
| | | public Result query(@PathVariable("begin") String begin, @PathVariable("end") String end) { |
| | | List<Weather> data = new ArrayList<>(); |
| | | try { |
| | | 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()); |
| | | 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()); |
| | | } |
| | | |
| | | data = weatherService.query(begin, end); |
| | | //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()); |
| | | } |
| | | return Result.OK(data); |
| | | } |
| | | |
| | | @GetMapping("/getAll") |