TransferServiceImpl.java 3.75 KB
package com.viontech.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.viontech.constant.SystemConstants;
import com.viontech.service.TransferService;
import com.viontech.vo.FxData;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Slf4j
@Service
public class TransferServiceImpl implements TransferService {
    private final ThreadPoolExecutor recvDataTaskAsyncPool = new ThreadPoolExecutor(5, 10, 8l, TimeUnit.SECONDS, new ArrayBlockingQueue<>(10), new ThreadPoolExecutor.CallerRunsPolicy());

    @Override
    public void receiveData(FxData fxdata) {
        try {
            String event_cate = fxdata.getEvent_cate();
            if (!event_cate.equals(SystemConstants.CATE_TRAFFIC)) {
                log.warn("event_cate与traffic不匹配,跳过");
                return;
            }
            String event_type = fxdata.getEvent_type();
            if (StringUtils.isBlank(event_type)) {
                log.warn("event_type为空,跳过");
                return;
            }
            recvDataTaskAsyncPool.submit(new Runnable() {
                @Override
                public void run() {
                    switch (event_cate) {
                        case SystemConstants.CATE_TRAFFIC:
                            switch (event_type) {
                                case SystemConstants.TYPE_VEHICLE:
                                    String ID = fxdata.getEvent_data().getID();
                                    String startDt = fxdata.getEvent_data().getStart_dt();
                                    String endDt = fxdata.getEvent_data().getEnd_dt();
                                    String deviceCode = fxdata.getEvent_data().getDevice().getCode();
                                    String vchanRefid = fxdata.getVchan_refid();
                                    Map vehicle = JSONObject.parseObject(JSONObject.toJSONString(fxdata.getEvent_data().getVehicle()), Map.class);
                                    Map illegal = JSONObject.parseObject(JSONObject.toJSONString(fxdata.getEvent_data().getIllegal()), Map.class);
                                    String state = (String) illegal.get("state");
                                    String base64 = fxdata.getPics().get(0).getPic_base64();
                                    Map lane = JSONObject.parseObject(JSONObject.toJSONString(fxdata.getEvent_data().getLane()), Map.class);

                                    try {
                                        if ("1".equals(state)) {
//                                            iilleProcessor.addIill(ID, startDt, endDt, deviceCode, vchanRefid, vehicle, illegal, base64);
                                        } else {
                                            return;
                                        }
                                    } catch (Exception e) {
                                        log.error("handle.Exception", e);
                                    }
                                    break;
                                default:
                                    log.warn("event_type类型无法判断:{},跳过处理", event_type);
                                    break;
                            }
                            break;
                        default:
                            log.warn("event_cate类型无法判断:{}跳过处理", event_cate);
                            break;
                    }
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
        }
        fxdata.setPics(null);
    }
}