ReceiveController.java 1.35 KB
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");
    }

}