package api.controller; import api.bean.PoleSensorV2SoilVOEntity; import api.bean.PoleSensorV2VOEntity; import api.bean.ReqParams; import api.bean.WeatherEntity; import api.result.Msg; import api.service.AccessService; import api.service.WeatherService; import api.service.WeatherV2Service; 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.Map; @RestController @RequestMapping("/weather/v2") public class WeatherV2Controller { @Autowired private AccessService accessService; @Autowired private WeatherV2Service weatherV2Service; RateLimiter rateLimiter = RateLimiter.create(10.0); @RequestMapping(value = "/list") public Msg list(@RequestBody ReqParams reqParams){ rateLimiter.acquire(1); if(reqParams.getLimit() > 200){ return Msg.error("limit exception!!!"); } Long userId = accessService.getUserId(reqParams.getAccessToken()); if(userId == null) { return Msg.error("server exception"); } PageInfo info = weatherV2Service.list(userId, reqParams); Map data = new HashMap(); data.put("total",info.getTotal()); data.put("list",info.getList()); return Msg.ok().put("data",data); } @RequestMapping(value = "/soil/list") public Msg soilList(@RequestBody ReqParams reqParams){ rateLimiter.acquire(1); if(reqParams.getLimit() > 200){ return Msg.error("limit exception!!!"); } Long userId = accessService.getUserId(reqParams.getAccessToken()); if(userId == null) { return Msg.error("server exception"); } PageInfo info = weatherV2Service.soilList(userId, reqParams); Map data = new HashMap(); data.put("total",info.getTotal()); data.put("list",info.getList()); return Msg.ok().put("data",data); } }