GpsEntity.java 5.03 KB
package com.bsth.entity;

import com.bsth.client.pd.protocol.BasicInfo;
import org.apache.commons.lang3.StringUtils;

/**
 * @author PanZhao
 * @ClassName: GpsRealData
 * @Description: TODO(HTTP接口的实时GPS数据)
 * @date 2016年5月11日 下午4:32:07
 */
public class GpsEntity {

    /**
     * 公司代码
     */
    private Short companyCode;

    /**
     * 线路编码
     */
    private String lineId;

    /**
     * 设备编码
     */
    private String deviceId;

    /**
     * 经度
     */
    private Float lon;

    /**
     * 纬度
     */
    private Float lat;

    /**
     * 发送时间戳
     */
    private Long timestamp;

    /**
     * 速度
     */
    private Float speed;

    /**
     * 方向(角度)
     */
    private float direction;

    /**
     * 营运状态( 0 营运 ,1 非营运, -1 无效)
     */
    private Integer state;

    /**
     * 上下行(0 上行 , 1 下行 , -1 无效)
     */
    private Byte upDown;

    private int version;

    /**
     * gps是否有效 设备端发送的状态
     */
    private int valid;

    /**
     * 数据来源
     * 1:网关
     * 0:转发
     */
    private int source;

    /** 网关收到时间 */
    private Long serverTimestamp;

    public static GpsEntity getInstance(BasicInfo basicInfo, int version, int source){
        if(StringUtils.isBlank(basicInfo.getDeviceId()))
            return null;

/*        byte cacheData = getCacheState(basicInfo.getServiceState());
        if(cacheData == 1)
            return null;*/

        GpsEntity gps = new GpsEntity();

        gps.setDeviceId(basicInfo.getDeviceId());
        gps.setTimestamp(basicInfo.getTimestamp());
        gps.setLat(basicInfo.getLat());
        gps.setLon(basicInfo.getLon());
        gps.setDirection((float)basicInfo.getDirection() / 10);
        gps.setValid(basicInfo.getGpsValid());
        gps.setCompanyCode(basicInfo.getCompanyCode());
        gps.setUpDown(basicInfo.getUpOrDown());
        gps.setSpeed((float)basicInfo.getSpeedGps() / 10);
        gps.setLineId(String.valueOf(basicInfo.getLineId()));
        gps.setState((int) getService(basicInfo.getServiceState()));
        gps.setVersion(version);
        gps.setSource(source);
        gps.setServerTimestamp(System.currentTimeMillis());
        return gps;
    }

    public static byte getCacheState(long serviceState) {
        return (byte)(((serviceState & 0x00100000) == 0x00100000) ? 1 : 0);
    }

    public static byte getGpsValid(long serviceState) {
        return (byte)(((serviceState & 0x80000000) == 0x80000000) ? 1 : 0);
    }

    public static void main(String[] args){
        int cache = getGpsValid(268435456);
        System.out.println(cache);
    }

    /**
     * 获取运营状态
     *
     * @return -1无效 0运营 1未运营
     */
    public static byte getService(long serviceState) {
        if ((serviceState & 0x00020000) == 0x00020000 || (serviceState & 0x80000000) == 0x80000000)
            return -1;
        return (byte) (((serviceState & 0x02000000) == 0x02000000) ? 1 : 0);
    }

    public String getDeviceId() {
        return deviceId;
    }

    public void setDeviceId(String deviceId) {
        this.deviceId = deviceId;
    }

    public Float getLon() {
        return lon;
    }

    public void setLon(Float lon) {
        this.lon = lon;
    }

    public Float getLat() {
        return lat;
    }

    public void setLat(Float lat) {
        this.lat = lat;
    }

    public Long getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(Long timestamp) {
        this.timestamp = timestamp;
    }


    public Integer getState() {
        return state;
    }

    public void setState(Integer state) {
        this.state = state;
    }

    public String getLineId() {
        return lineId;
    }

    public void setLineId(String lineId) {
        this.lineId = lineId;
    }


    public int getVersion() {
        return version;
    }

    public void setVersion(int version) {
        this.version = version;
    }

    public int getValid() {
        return valid;
    }

    public void setValid(int valid) {
        this.valid = valid;
    }


    public short getCompanyCode() {
        return companyCode;
    }

    public void setCompanyCode(short companyCode) {
        this.companyCode = companyCode;
    }

    public Byte getUpDown() {
        return upDown;
    }

    public void setUpDown(Byte upDown) {
        this.upDown = upDown;
    }


    public float getDirection() {
        return direction;
    }

    public void setDirection(float direction) {
        this.direction = direction;
    }

    public Float getSpeed() {
        return speed;
    }

    public void setSpeed(Float speed) {
        this.speed = speed;
    }

    public int getSource() {
        return source;
    }

    public void setSource(int source) {
        this.source = source;
    }

    public Long getServerTimestamp() {
        return serverTimestamp;
    }

    public void setServerTimestamp(Long serverTimestamp) {
        this.serverTimestamp = serverTimestamp;
    }
}