package api.controller;
|
|
import api.bean.ReqParams;
|
import api.bean.WeatherEntity;
|
import api.result.Msg;
|
import api.service.AccessService;
|
import api.service.WeatherService;
|
import com.github.pagehelper.PageInfo;
|
import com.google.common.util.concurrent.RateLimiter;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* @program: wog
|
* @description:
|
* @author: YSS
|
* @create: 2020-09-26 16:28
|
**/
|
@RestController
|
@RequestMapping("/weather")
|
public class WeatherController {
|
@Autowired
|
private AccessService accessService;
|
@Autowired
|
private WeatherService weatherService;
|
|
RateLimiter rateLimiter = RateLimiter.create(10.0);
|
@RequestMapping(value = "/list",method = RequestMethod.POST)
|
public Msg list(@RequestBody ReqParams reqParams){
|
rateLimiter.acquire(1);
|
if(reqParams.getLimit() > 50){
|
return Msg.error("limit exception!!!");
|
}
|
|
Long userId = accessService.getUserId(reqParams.getAccessToken());
|
|
if(userId == null) {
|
return Msg.error("server exception");
|
}
|
|
PageInfo<WeatherEntity> info = weatherService.selectList(userId, reqParams);
|
|
Map data = new HashMap();
|
|
data.put("total",info.getTotal());
|
data.put("list",info.getList());
|
|
return Msg.ok().put("data",data);
|
|
}
|
|
@RequestMapping(value = "/info",method = RequestMethod.POST)
|
public Msg info(@RequestBody ReqParams reqParams){
|
rateLimiter.acquire(1);
|
if(reqParams.getLimit() > 50){
|
return Msg.error("limit exception");
|
}
|
|
Long userId = accessService.getUserId(reqParams.getAccessToken());
|
|
if(userId == null) {
|
return Msg.error("server exception");
|
}
|
|
PageInfo<WeatherEntity> info = weatherService.selectByStreetlightId(reqParams);
|
|
Map data = new HashMap();
|
|
data.put("total",info.getTotal());
|
data.put("list",info.getList());
|
|
return Msg.ok().put("data",data);
|
}
|
}
|