Van333
2022-10-26 b54ea64cbb2cf8d613ca1ecf6ed9e5140abb4b9f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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<SinglelampDataEntity> 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<SinglelampDataEntity> info = singlelampDataServer.selectByStreetlightId(reqParams);
 
        Map data = new HashMap();
 
        data.put("total",info.getTotal());
        data.put("list",info.getList());
 
        return Msg.ok().put("data",data);
    }
 
}