ProcessService.java 1.42 KB
package com.viontech.process;

import com.alibaba.fastjson.JSONObject;
import com.viontech.model.BaseModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * .
 *
 * @author 谢明辉
 * @date 2020/8/31
 */
@Service
@Slf4j
public class ProcessService {

    @Resource
    private Process behaviorProcess;
    @Resource
    private Process trafficProcess;
    @Resource
    private Process flowProcess;

    /**
     * 分类处理繁星发来的数据
     *
     * @param jsonStr 繁星发来的数据
     *
     * @return 转换成对接方需要的
     */
    public BaseModel process(String jsonStr) throws Exception {
        JSONObject jsonObject = JSONObject.parseObject(jsonStr);
        String eventCate = jsonObject.getString("event_cate");
        String eventType = jsonObject.getString("event_type");
        if (eventCate == null) {
            return null;
        }
        switch (eventCate) {
            case "traffic":
                if ("vehicle".equals(eventType)) {
                    return trafficProcess.process(jsonObject);
                } else if ("tflow".equals(eventType)) {
                    return flowProcess.process(jsonObject);
                }
                return null;
            case "behavior":
                return behaviorProcess.process(jsonObject);
            default:
                return null;
        }
    }
}