Van333
2022-09-02 2234cee8e872fd7633b95eef5b0c760cbbb8eabf
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
package api.controller;
 
import api.bean.ReqParams;
import api.bean.WeatherEntity;
import api.result.Msg;
import api.service.AccessService;
import api.service.WeatherService;
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.List;
import java.util.Map;
 
/**
 * @program: wog
 * @description:
 * @author: YSS
 * @create: 2020-09-26 16:28
 **/
@RestController
@RequestMapping("/weather")
public class WeatherController {
    @Autowired
    private AccessService accessService;
    @Autowired
    private WeatherService weatherService;
 
    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<WeatherEntity> info = weatherService.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<WeatherEntity> info = weatherService.selectByStreetlightId(reqParams);
 
        Map data = new HashMap();
 
        data.put("total",info.getTotal());
        data.put("list",info.getList());
 
        return Msg.ok().put("data",data);
    }
}