ReceiveController.java
1.35 KB
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
package com.viontech.tvp;
import cn.hutool.core.lang.Dict;
import cn.hutool.json.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.Optional;
/**
* .
*
* @author 谢明辉
* @date 2022/3/7
*/
@RestController
@Slf4j
public class ReceiveController {
@Resource
private ForwardService forwardService;
@PostMapping("/recv")
public Object receive(@RequestBody JSONObject fxData) {
String eventCate = fxData.getStr("event_cate");
String eventType = fxData.getStr("event_type");
boolean illegal = Optional.of(fxData)
.map(x -> x.getJSONObject("event_data"))
.map(x -> x.getJSONObject("illegal"))
.map(x -> x.getInt("state"))
.map(x -> x == 1)
.orElse(false);
if ("traffic".equals(eventCate) && "vehicle".equals(eventType) && illegal) {
// 进行异步转发
forwardService.forwardAsync(fxData);
} else {
log.debug("非违法数据, 不转发: event_cate: {}, event_type: {}", eventCate, eventType);
}
return Dict.of("code", "200", "msg", "success");
}
}