package api.controller; import api.bean.ReqParams; import api.bean.SinglelampDataEntity; import api.result.Msg; import api.service.AccessService; import api.service.SinglelampDataServer; 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; /** * @author van * @version 1.0 * msg:MQTT和CAT1单灯控制 * @date 2021/12/13 15:26 */ @RestController @RequestMapping("/singlelampData") public class SinglelampDataController { @Autowired private AccessService accessService; @Autowired private SinglelampDataServer singlelampDataServer; RateLimiter rateLimiter = RateLimiter.create(10.0); @RequestMapping(value = "/list",method = RequestMethod.POST) 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("accessToken exception!!!"); } reqParams.toString(); PageInfo info = singlelampDataServer.selectList(userId,reqParams); Map data = new HashMap(); data.put("dataSize",info.getStartRow()); data.put("lampSize",info.getEndRow()); data.put("totalPage",Math.ceil(info.getStartRow()*1.0/reqParams.getLimit())); 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("accessToken exception!!!"); } PageInfo info = singlelampDataServer.selectByStreetlightId(reqParams); Map data = new HashMap(); data.put("total",info.getTotal()); data.put("list",info.getList()); return Msg.ok().put("data",data); } }