package api.controller;
|
|
import api.bean.LampEntity;
|
import api.bean.ReqParams;
|
import api.dao.LampDao;
|
import api.result.Msg;
|
import api.service.AccessService;
|
import api.service.LampService;
|
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.*;
|
|
import java.util.HashMap;
|
import java.util.Map;
|
|
/**
|
* @author van
|
* @version 1.0
|
* msg:单灯数据控制层
|
* @date 2021/11/2 15:04
|
*/
|
@RestController
|
@RequestMapping("/lamp")
|
public class LampController {
|
|
@Autowired
|
private AccessService accessService;
|
@Autowired
|
private LampService lampService;
|
|
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<LampEntity> info = lampService.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<LampEntity> info = lampService.selectByStreetlightId(reqParams);
|
|
Map data = new HashMap();
|
|
data.put("total",info.getTotal());
|
data.put("list",info.getList());
|
|
return Msg.ok().put("data",data);
|
}
|
|
}
|