songjinsheng c9abb90c97 上传
2022-06-22 08:38:11 +08:00

93 lines
2.9 KiB
Java

package com.xkrs.microservice.controller;
import com.xkrs.microservice.common.encapsulation.PromptMessageEnum;
import com.xkrs.microservice.common.tool.PageBean;
import com.xkrs.microservice.common.tool.WeatherGet;
import com.xkrs.microservice.dao.WeatherDao;
import com.xkrs.microservice.model.entity.WeatherEntity;
import com.xkrs.microservice.service.WeatherService;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import static com.xkrs.microservice.common.encapsulation.OutputEncapsulation.outputEncapsulationObject;
/**
* @author XinYiSong
*/
@RestController
@RequestMapping("/api/weather-station")
public class WeatherController {
@Resource
private WeatherGet weatherGet;
@Resource
private WeatherService weatherService;
@Resource
private WeatherDao weatherDao;
/**
* 获取区域信息
*/
Locale locale = LocaleContextHolder.getLocale();
/**
* 测试
* @return
*/
@PostMapping("/insertWeather")
public void insertWeather(){
weatherGet.findWeather();
}
/**
* 查询相关的天气和气候
* @param map
* @return
*/
@PostMapping("/queryWeather")
public String queryWeather(@RequestBody Map map){
Integer pageNo = (Integer) map.get("pageNo");
String addTimeStart = (String) map.get("addTimeStart");
String addTimeEnd = (String) map.get("addTimeEnd");
PageBean pageBean = weatherService.queryWeather(pageNo, addTimeStart, addTimeEnd);
if(pageBean.getList() == null || pageBean.getList().size() == 0){
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"暂时没有相关数据",locale);
}
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,pageBean,locale);
}
/**
* 查询气候最新的一条信息
* @return
*/
@GetMapping("/selectNewest")
public String selectNewest(){
WeatherEntity weatherEntity = weatherDao.selectNewest();
if(weatherEntity == null){
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"暂时没有相关数据",locale);
}
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,weatherEntity,locale);
}
/**
* 根据时间查询气象信息
* 修改
* @param map
* @return
*/
@PostMapping("/selectWeather")
public String selectWeather(@RequestBody Map map){
String addTimeStart = (String) map.get("addTimeStart");
String addTimeEnd = (String) map.get("addTimeEnd");
List<WeatherEntity> weatherEntities = weatherService.selectWeather(addTimeStart, addTimeEnd);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,weatherEntities,locale);
}
}