package api.controller; import api.bean.PoleLightBatchEntity; import api.bean.ReqParams; import api.result.Msg; import api.service.AccessService; import api.service.PoleService; import api.utils.HttpUtil; import com.alibaba.fastjson.JSON; import com.google.common.util.concurrent.RateLimiter; import com.google.gson.Gson; 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:单灯控制层 * @date 2021/11/2 15:04 */ @RestController @RequestMapping("/pole") public class PoleController { @Autowired private AccessService accessService; RateLimiter rateLimiter = RateLimiter.create(10.0); @RequestMapping(value = "polestreetlight/listWithNotStatus",method = RequestMethod.POST) public Msg listWithNotStatus(@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!!!"); } reqParams.setApiKey(reqParams.getApiKey()); reqParams.setUserId(userId); String result = HttpUtil.Post( "http://47.106.172.9:8888/machine-fast/serv/api/pole/polestreetlight/listWithNotStatus", new Gson().toJson(reqParams) ); Map msg = JSON.parseObject(result, HashMap.class); if (msg.get("msg").equals("success")){ return Msg.ok().put("data",msg.get("data")); } else { return Msg.error(msg.get("msg").toString()); } } @RequestMapping(value = "polestreetlight/getStatusById",method = RequestMethod.POST) public Msg getStatusById(@RequestBody ReqParams reqParams){ rateLimiter.acquire(1); Long userId = accessService.getUserId(reqParams.getAccessToken()); if(userId == null){ return Msg.error("accessToken exception!!!"); } reqParams.setApiKey(reqParams.getApiKey()); reqParams.setUserId(userId); String result = HttpUtil.Post( "http://47.106.172.9:8888/machine-fast/serv/api/pole/polestreetlight/getStatusById", new Gson().toJson(reqParams) ); Map msg = JSON.parseObject(result, HashMap.class); if (msg.get("msg").equals("success")){ return Msg.ok().put("data",msg.get("data")); } else { return Msg.error(msg.get("msg").toString()); } } @RequestMapping(value = "polestreetlight/lightBatch",method = RequestMethod.POST) public Msg list(@RequestBody ReqParams reqParams){ rateLimiter.acquire(1); Long userId = accessService.getUserId(reqParams.getAccessToken()); if(userId == null){ return Msg.error("accessToken exception!!!"); } reqParams.setApiKey(reqParams.getApiKey()); reqParams.setUserId(userId); PoleLightBatchEntity poleLightBatch = new PoleLightBatchEntity(); poleLightBatch.setAdIds(reqParams.getPoleLightBatch().getStreetlightIds()); poleLightBatch.setLightNumber(reqParams.getPoleLightBatch().getLightNumber()); poleLightBatch.setLightLevel(reqParams.getPoleLightBatch().getLightLevel()); reqParams.setPoleLightBatch(poleLightBatch); String result = HttpUtil.Post( "http://47.106.172.9:8888/machine-fast/serv/api/pole/polestreetlight/lightBatch", new Gson().toJson(reqParams) ); Map msg = JSON.parseObject(result, HashMap.class); assert msg != null; if (msg.get("msg").equals("success")){ return Msg.ok().put("data",msg.get("data")); } else { return Msg.error(msg.get("msg").toString()); } } }