BehaviorProcess.java 5.57 KB
package com.viontech.process;

import io.netty.buffer.ByteBuf;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

public class BehaviorProcess extends Process{

    @Override
    public void getData(Map jsonMap, ByteBuf byteBuf) throws Exception{
        if(!jsonMap.get("event_cate").equals("behavior")){
            return;
        }
        Integer event_refid=(Integer) jsonMap.get("event_refid");
        byteBuf.writeInt(event_refid);
        DateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        if(jsonMap.get("video")!=null){
            List<Map> videoList= (List<Map>) jsonMap.get("video");
            for (Map map : videoList) {
                Date start_dt= (Date) map.get("start_dt");
                Date end_dt= (Date) map.get("end_dt");
                Date startDateSecond=dateFormat.parse(dateFormat.format(start_dt));
                Date endDateSecond=dateFormat.parse(dateFormat.format(end_dt));
                byteBuf.writeInt((int) startDateSecond.getTime());
                byteBuf.writeInt((int) start_dt.getTime());
                byteBuf.writeInt((int) endDateSecond.getTime());
                byteBuf.writeInt((int) end_dt.getTime());
            }
        }else{
            byteBuf.writeInt(0);
            byteBuf.writeInt(0);
            byteBuf.writeInt(0);
            byteBuf.writeInt(0);
        }
        Date event_dt= (Date) jsonMap.get("event_dt");
        Date eventDateSecond=dateFormat.parse(dateFormat.format(event_dt));
        byteBuf.writeInt((int) eventDateSecond.getTime());
        byteBuf.writeInt((int) event_dt.getTime());
        String event_type= (String) jsonMap.get("event_type");
        //事件类型需要转换
        convertBehaviorCode(event_type,byteBuf);
        Integer laneNumber=0;
        String plate="";
        String carType="";
        String carColor="";
        Integer speed=0;
        String direction="";
        String locationName="";
        if(jsonMap.get("event_data")!=null){
            Map event_data= (Map) jsonMap.get("event_data");
            if(event_data.get("lane")!=null){
                Map laneMap= (Map) event_data.get("lane");
                if(laneMap.get("number")!=null){
                    laneNumber=(Integer) laneMap.get("number");
                }
            }
            if(event_data.get("vehicle")!=null){
                Map vehicle= (Map) event_data.get("vehicle");
                if(vehicle.get("plate")!=null){
                    Map plateMap= (Map) vehicle.get("plate");
                    plate= (String) plateMap.get("text");
                }
            }
            if(event_data.get("uservehicle")!=null){
                Map userVehicle= (Map) event_data.get("uservehicle");
                carType= (String) userVehicle.get("vehicletype");
                carColor= (String) userVehicle.get("vehiclecolor");
            }
            speed=Integer.valueOf(String.valueOf((Double)event_data.get("speed")));
            if(event_data.get("location")!=null){
                Map locationMap= (Map) event_data.get("location");
                if(locationMap.get("drive_direction")!=null){
                    Map directionMap= (Map) locationMap.get("drive_direction");
                    direction= (String) directionMap.get("code");
                }
                locationName= (String) locationMap.get("name");
            }
        }
        byteBuf.writeInt(laneNumber);
        if(jsonMap.get("pics")!=null){
            List<Map> pics= (List<Map>) jsonMap.get("pics");
            String picbase64= (String) pics.get(0).get("pic_base64");
            byteBuf.writeInt(picbase64.getBytes().length);
            byteBuf.writeInt((Integer) pics.get(0).get("width"));
            byteBuf.writeInt((Integer) pics.get(0).get("hight"));
            //这两个坐标不知道怎么赋值
            byteBuf.writeInt(0);
            byteBuf.writeInt(0);
        }else{
            byteBuf.writeInt(0);
            byteBuf.writeInt(0);
            byteBuf.writeInt(0);
            byteBuf.writeInt(0);
            byteBuf.writeInt(0);
        }
        //车牌需要转换一下
        convertPlate(plate,byteBuf);
        //事件录像存储位置不知道怎么赋值
        byteBuf.writeBytes(new byte[128]);
        //车辆类型没法给需要转换
        convertCarType(carType,byteBuf);
        //车身颜色需要转换
        convertCarColor(carColor,byteBuf);
        byteBuf.writeInt(speed);
        //行驶方向需要转换
        convertDirection(direction,byteBuf);
        //地点名称暂时没有赋值,确认是不是用locationName
        byteBuf.writeBytes(new byte[32]);
        //事件快照路径不知道怎么赋值
        byteBuf.writeBytes(new byte[128]);

        //车身颜色2,3和权重暂时未赋值
        byteBuf.writeInt(0);
        byteBuf.writeInt(0);
        byteBuf.writeInt(0);
        byteBuf.writeInt(0);
        byteBuf.writeInt(0);
        //车型细分暂时未赋值
        byteBuf.writeInt(0);
        //预置位我不知道怎么赋值
        byteBuf.writeInt(0);
        //录像时长
        byteBuf.writeInt(0);
        byteBuf.writeInt(0);
        byteBuf.writeInt(0);
        byteBuf.writeBytes(new byte[24]);
    }
    public void convertBehaviorCode(String event_type,ByteBuf byteBuf){

    }
    public void convertPlate(String plate,ByteBuf byteBuf){

    }
    public void convertCarType(String carType,ByteBuf byteBuf){

    }
    public void convertCarColor(String carColor,ByteBuf byteBuf){

    }
    public void convertDirection(String direction,ByteBuf byteBuf){

    }
}