Van333
2022-12-29 d8f66b834134f6b755fd3fb93bb91b56f9d31f6f
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
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());
        }
 
 
    }
 
 
}