Java教程

Flink流处理-Entity之Model

本文主要是介绍Flink流处理-Entity之Model,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

DataPartObj

package pers.aishuang.flink.streaming.entity;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 定义原始数据中jsob对象对应的部分所需字段对象
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class DataPartObj extends VehicleLocationModel implements Comparable<DataPartObj>{
    //电池单体一致性差报警 0:正常 , 1:异常--
    private int batteryConsistencyDifferenceAlarm = -999999;
    //SOC %--
    private int soc = -999999;
    //soc跳变报警 0:正常, 1:异常 --
    private int socJumpAlarm = -999999;
    //soc低报警 0:正常,1:异常--
    private int socLowAlarm = -999999;
    //终端时间
    private String terminalTime = "" ;
    //单体电池过压报警 0:正常, 1:异常--
    private int singleBatteryOverVoltageAlarm = -999999;
    //车载储能装置过压报警 0:正常 1:异常--
    private int vehicleStorageDeviceOvervoltageAlarm = -999999;
    //制动系统报警   0:正常 1:异常--
    private int brakeSystemAlarm = -999999;
    //车辆唯一编号--
    private String vin = "";
    //"0x01:停车充电 0x02:行车充电 0x03:未充电 0x04:充电完成 0xFE:异常 0xFF:无效“
    private int chargeStatus = -999999;
    //驱动电机温度报警 0:正常 1:异常--
    private int driveMotorTemperatureAlarm = -999999;
    //DC-DC状态报警 0:正常,1:异常--
    private int dcdcStatusAlarm = -999999;
    //位置时间
    private String gpsTime = "";
    //位置维度--
    private Double lat = -999999D;
    //驱动电机控制器温度报警 0:正常, 1:异常
    private int driveMotorFaultCount = -999999;
    //车速--
    private Double vehicleSpeed = -999999D;
    //位置经度--
    private Double lng = -999999D;
    //可充电储能装置电压 V--
    private Double chargeSystemVoltage = -999999D;
    //可充电储储能装置电流 A--
    private Double chargeSystemCurrent = -999999D;
    //单体电池欠压报警 0:正常,1:异常--
    private int singleBatteryUnderVoltageAlarm = -999999;
    //总电压 单位:V, 实际取值 0.1~100V
    private Double totalVoltage = -999999D;
    //温度差异报警   0:正常 1:异常--
    private int temperatureDifferenceAlarm = -999999;
    //--电池单体电压最低值  单位:V,实际值=传输值*0.001,即实际为0~15V。0xFF,0xFE表示异常,0xFF,0xFF表示无效
    private Double minVoltageBattery = -999999D;
    //GPS是否有效(可忽略)
    private String validGps = "";
    //累计里程 单位:km--
    private Double totalOdometer = -999999D;
    //车速(可忽略)  单位:km/h
    private Double speed = -999999D;
    //SOC过高报警  0:正常 1:异常--
    private int socHighAlarm = -999999;
    //车载储能装置欠压报警   0:正常 1:异常--
    private int vehicleStorageDeviceUndervoltageAlarm = -999999;
    //总电流  单位:A,实际值 = 传输值 * 0.1-1000,即实际取值为-1000~1000A
    private Double totalCurrent = -999999D;
    //电池高温报警   0:正常 1:异常--
    private int batteryAlarm = -999999;
    //可充电储能系统不匹配报警 0:正常 1:异常--
    private int rechargeableStorageDeviceMismatchAlarm = -999999;
    //车载储能装置类型过充报警 0:正常 1:异常--
    private int vehiclePureDeviceTypeOvercharge = -999999;
    //--电池单体电压最高值  单位:V,实际值=传输值*0.001,即实际为0~15V。0xFF,0xFE表示异常,0xFF,0xFF表示无效
    private Double maxVoltageBattery = -999999D;
    //DC-DC温度报警    0:正常 1:异常--
    private int dcdcTemperatureAlarm = -999999;
    //同validGps(可忽略)
    private String isValidGps = "";
    //驱动电机控制器温度报警  0:正常 1:异常
    private int driveMotorControllerTemperatureAlarm = -999999;
    //是否补发 TRUE:补发数据 ; FALSE:实时数据
    private String repay = "";
    //车辆状态 0x01: 车辆启动状态,0x02:熄火状态 0x03:其他状态,0xFE:异常,0xFF:无效
    private int carStatus = -999999;
    //前电机故障代码 json数据中,ecuErrCodeDataList数组中ecuType=4--
    private String IpuFaultCodes = "";
    //能量回收状态   高/低
    private int energyRecoveryStatus = -999999;
    //点火状态 0:未点火 ;2:已点火
    private int fireStatus = -999999;
    //运行模式 0x01: 纯电 0x02 混动 0x03 燃油 0xFE: 异常 0xFF: 无效
    private int carMode = -999999;
    //高压互锁状态报警 0:正常 1:异常--
    private int highVoltageInterlockStateAlarm = -999999;
    //绝缘报警 0:正常 1:异常--
    private int insulationAlarm = -999999;
    //续航里程信息   单位:km--
    private int mileageInformation = -999999;
    //当前电量 %
    private Double remainPower = -999999D;
    //发动机状态    0:stop  1:crank   2:running
    private String engineStatus = "";
    //ABS故障 "0x0:No error 0x1:Error"--
    private String absStatus = "";
    //EPB故障状态 "0x0:no error 0x1:not defined 0x2:not defined 0x3:error"--
    private String VcuBrkErr = "";
    //ESP故障 "0x0:No error 0x1:Error"--
    private String ESP_TCSFailStatus = "";
    //助力转向故障 "0x0:No Failed 0x1:Failed"--
    private String EPS_EPSFailed = "";
    //电池故障代码 json数据中,ecuErrCodeDataList数组中ecuType=2--
    private String BcuFaultCodes = "";
    //VCU故障代码 json数据中,ecuErrCodeDataList数组中ecuType=1--
    private String VcuFaultCode = "";
    /**
     * --充电机故障码  "0x0:当前无故障 0x1:12V电池电压过高 0x2:12V电池电压过低 0x3:CP内部6V电压异常 0x4:CP内部9V电压异常
     * 0x5:CP内部频率异常 0x6:CP内部占空比异常 0x7:CAN收发器异常 0x8:内部SCI通信失败 0x9:内部SCICRC错误 0xA:输出过压关机
     * 0xB:输出低压关机 0xC:交流输入低压关机 0xD:输入过压关机 0xE:环境温度过低关机 0xF:环境温度过高关机
     * 0x10:充电机PFC电压欠压 0x11:输入过载 0x12:输出过载 0x13:自检故障 0x14:外部CANbusoff 0x15:内部CANbusoff
     * 0x16:外部CAN通信超时 0x17:外部CAN使能超时 0x18:外部CAN通信错误 0x19:输出短路 0x1A:充电参数错误
     * 0x1B:充电机PFC电压过压 0x1C:内部SCI通信失败 0x1D:过功率 0x1E:PFC电感过温 0x1F:LLC变压器过温 0x20:M1功率板过温
     * 0x21:PFC温度降额 0x22:LLC温度降额 0x23:M1板温度降额 0x24:Air环境温度降额"
     * json数据中,ecuErrCodeDataList数组中ecuType=5
     */
    private String ObcFaultCode  = "";
    //最高温度值    单位:℃。实际值:-40~210。0xFE表示异常,1xFF表示无效
    private Double maxTemperatureValue = -999999D;
    //最低温度值    单位:℃。实际值:-40~210。0xFE表示异常,1xFF表示无效
    private Double minTemperatureValue = -999999D;
    //DCDC故障码 json数据中,ecuErrCodeDataList数组中ecuType=3
    private String DcdcFaultCode = "";
    //电池极注高温报警 "0x0:Noerror 0x1:error"
    private String battPoleTOver = "";
    //AC系统故障 "0x0:NotFailure 0x1:Failure"
    private int acSystemFailure = -999999;
    //气囊系统报警灯状态  "0x0:Lamp off-no failure 0x1:Lamp on-no failure 0x2:Lamp flashing-no failure 0x3:Failure-failure present"
    private int airBagWarningLamp = -999999;
    //电池充电状态 "0x0:uncharged 0x1:charging 0x2:fullofcharge 0x3:chargeend"
    private int batteryChargeStatus = -999999;
    //充电枪连接状态  0:解锁1:锁定2:失败
    private int chargingGunConnectionState = -999999;
    //单体电池电压列表 Array类型的数组格式
    private String batteryVoltage = "" ;
    //电池模块温度列表
    private String probeTemperatures = "";

    //------扩展字段------
    //终端时间戳 (由终端时间terminalTime装换而来)
    private Long terminalTimeStamp = -999999L;
    //存储异常数据,用于标识数据是否异常
    private String errorData = "";


    /**
     * 通过参数获取相应的参数字段值,用于故障分析
     * @param filed 字段名称
     * @return 字段值
     */
    public String get(String filed) {
        switch (filed) {
            // 6类故障
            case "battPoleTOver":
                return this.battPoleTOver;
            case "absStatus" :
                return this.absStatus;
            case "VcuBrkErr":
                return this.VcuBrkErr;
            case "ESP_TCSFailStatus":
                return this.ESP_TCSFailStatus;
            case "EPS_EPSFailed":
                return this.EPS_EPSFailed;
            case "acSystemFailure":
                return String.valueOf(this.acSystemFailure);
            // 19类故障
            case "batteryAlarm":
                return String.valueOf(this.batteryAlarm);
            case "singleBatteryOverVoltageAlarm":
                return String.valueOf(this.singleBatteryOverVoltageAlarm);
            case "batteryConsistencyDifferenceAlarm":
                return String.valueOf(this.batteryConsistencyDifferenceAlarm);
            case "insulationAlarm":
                String.valueOf(this.insulationAlarm);
            case "highVoltageInterlockStateAlarm":
                return String.valueOf(this.highVoltageInterlockStateAlarm);
            case "socJumpAlarm":
                return String.valueOf(this.socJumpAlarm);
            case "driveMotorControllerTemperatureAlarm":
                return String.valueOf(this.driveMotorControllerTemperatureAlarm);
            case "dcdcTemperatureAlarm"                   :
                return String.valueOf(this.dcdcTemperatureAlarm);
            case "socHighAlarm"                           :
                return String.valueOf(this.socHighAlarm);
            case "socLowAlarm"                            :
                return String.valueOf(this.socLowAlarm);
            case "temperatureDifferenceAlarm"             :
                return String.valueOf(this.temperatureDifferenceAlarm);
            case "vehicleStorageDeviceUndervoltageAlarm"  :
                return String.valueOf(this.vehicleStorageDeviceUndervoltageAlarm);
            case "dcdcStatusAlarm"                        :
                return String.valueOf(this.dcdcStatusAlarm);
            case "singleBatteryUnderVoltageAlarm"         :
                return String.valueOf(this.singleBatteryUnderVoltageAlarm);
            case "rechargeableStorageDeviceMismatchAlarm" :
                return String.valueOf(this.rechargeableStorageDeviceMismatchAlarm);
            case "vehicleStorageDeviceOvervoltageAlarm"   :
                return String.valueOf(this.vehicleStorageDeviceOvervoltageAlarm);
            case "brakeSystemAlarm"                       :
                return String.valueOf(this.brakeSystemAlarm);
            case "driveMotorTemperatureAlarm"             :
                return String.valueOf(this.driveMotorTemperatureAlarm);
            case "vehiclePureDeviceTypeOvercharge"        :
                return String.valueOf(this.vehiclePureDeviceTypeOvercharge);
            // 5类故障
            case "VcuFaultCode"                           :
                return this.VcuFaultCode;
            case "BcuFaultCodes"                          :
                return this.BcuFaultCodes;
            case "DcdcFaultCode"                          :
                return this.DcdcFaultCode;
            case "IpuFaultCodes"                          :
                return this.IpuFaultCodes;
            case "ObcFaultCode"                           :
                return this.ObcFaultCode;
            default:
                return null;
        }
    }

    /**
     * @desc:定义根据输入字符获取字段值
     * @param str
     * @return double
     */
    public Double getValue(String str) {
        switch (str) {
            case "maxVoltageBattery":
                return this.maxVoltageBattery;
            case "minVoltageBattery":
                return this.minVoltageBattery;
            case "maxTemperatureValue":
                return this.maxTemperatureValue;
            case "minTemperatureValue":
                return this.minTemperatureValue;
            default:
                return 0.0;
        }
    }

    // 重写ItcastDataPartObj对象的toString方法
    @Override
    public String toString() {
        return "ItcastDataPartObj{" +
                "batteryConsistencyDifferenceAlarm=" + batteryConsistencyDifferenceAlarm +
                ", soc=" + soc +
                ", socJumpAlarm=" + socJumpAlarm +
                ", socLowAlarm=" + socLowAlarm +
                ", terminalTime='" + terminalTime + '\'' +
                ", singleBatteryOverVoltageAlarm=" + singleBatteryOverVoltageAlarm +
                ", vehicleStorageDeviceOvervoltageAlarm=" + vehicleStorageDeviceOvervoltageAlarm +
                ", brakeSystemAlarm=" + brakeSystemAlarm +
                ", vin='" + vin + '\'' +
                ", chargeStatus=" + chargeStatus +
                ", driveMotorTemperatureAlarm=" + driveMotorTemperatureAlarm +
                ", dcdcStatusAlarm=" + dcdcStatusAlarm +
                ", gpsTime='" + gpsTime + '\'' +
                ", lat=" + lat +
                ", driveMotorFaultCount=" + driveMotorFaultCount +
                ", vehicleSpeed=" + vehicleSpeed +
                ", lng=" + lng +
                ", chargeSystemVoltage=" + chargeSystemVoltage +
                ", chargeSystemCurrent=" + chargeSystemCurrent +
                ", singleBatteryUnderVoltageAlarm=" + singleBatteryUnderVoltageAlarm +
                ", totalVoltage=" + totalVoltage +
                ", temperatureDifferenceAlarm=" + temperatureDifferenceAlarm +
                ", minVoltageBattery=" + minVoltageBattery +
                ", validGps='" + validGps + '\'' +
                ", totalOdometer=" + totalOdometer +
                ", speed=" + speed +
                ", socHighAlarm=" + socHighAlarm +
                ", vehicleStorageDeviceUndervoltageAlarm=" + vehicleStorageDeviceUndervoltageAlarm +
                ", totalCurrent=" + totalCurrent +
                ", batteryAlarm=" + batteryAlarm +
                ", rechargeableStorageDeviceMismatchAlarm=" + rechargeableStorageDeviceMismatchAlarm +
                ", vehiclePureDeviceTypeOvercharge=" + vehiclePureDeviceTypeOvercharge +
                ", maxVoltageBattery=" + maxVoltageBattery +
                ", dcdcTemperatureAlarm=" + dcdcTemperatureAlarm +
                ", isValidGps='" + isValidGps + '\'' +
                ", driveMotorControllerTemperatureAlarm=" + driveMotorControllerTemperatureAlarm +
                ", repay='" + repay + '\'' +
                ", carStatus=" + carStatus +
                ", IpuFaultCodes='" + IpuFaultCodes + '\'' +
                ", energyRecoveryStatus=" + energyRecoveryStatus +
                ", fireStatus=" + fireStatus +
                ", carMode=" + carMode +
                ", highVoltageInterlockStateAlarm=" + highVoltageInterlockStateAlarm +
                ", insulationAlarm=" + insulationAlarm +
                ", mileageInformation=" + mileageInformation +
                ", remainPower=" + remainPower +
                ", engineStatus='" + engineStatus + '\'' +
                ", absStatus='" + absStatus + '\'' +
                ", VcuBrkErr='" + VcuBrkErr + '\'' +
                ", ESP_TCSFailStatus='" + ESP_TCSFailStatus + '\'' +
                ", EPS_EPSFailed='" + EPS_EPSFailed + '\'' +
                ", BcuFaultCodes='" + BcuFaultCodes + '\'' +
                ", VcuFaultCode='" + VcuFaultCode + '\'' +
                ", ObcFaultCode='" + ObcFaultCode + '\'' +
                ", maxTemperatureValue=" + maxTemperatureValue +
                ", minTemperatureValue=" + minTemperatureValue +
                ", DcdcFaultCode='" + DcdcFaultCode + '\'' +
                ", battPoleTOver='" + battPoleTOver + '\'' +
                ", acSystemFailure=" + acSystemFailure +
                ", airBagWarningLamp=" + airBagWarningLamp +
                ", batteryChargeStatus=" + batteryChargeStatus +
                ", chargingGunConnectionState=" + chargingGunConnectionState +
                ", batteryVoltage='" + batteryVoltage + '\'' +
                ", probeTemperatures='" + probeTemperatures + '\'' +
                ", terminalTimeStamp=" + terminalTimeStamp +
                ", errorData='" + errorData + '\'' +
                '}';
    }


    @Override
    public int compareTo(ItcastDataPartObj o) {
        return this.terminalTimeStamp > o.terminalTimeStamp ? 1 : -1;
    }
}

TripModel

package pers.aishuang.flink.streaming.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import pers.aishuang.flink.streaming.utils.DateUtil;

/**
 * 定义驾驶行程计算结果对应的JavaBean对象
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class TripModel {
    //车架号
    private String vin = "";
    //上次报文soc
    private Double lastSoc =  -999999D;
    //上次报文里程数
    private Double lastMileage = -999999D;
    //行程开始时间
    private String tripStartTime = "";
    //行程开始soc
    private int start_BMS_SOC =  -999999;
    //行程开始经度
    private Double start_longitude = -999999D;
    //行程开始纬度
    private Double start_latitude =  -999999D;
    //行程开始里程
    private Double start_mileage = -999999D;
    //结束soc
    private int end_BMS_SOC =  -999999;
    //结束经度
    private Double end_longitude =  -999999D;
    //结束纬度
    private Double end_latitude =  -999999D;
    //结束里程
    private Double end_mileage =  -999999D;
    //行程结束时间
    private String tripEndTime = "" ;
    //行程里程消耗
    private Double mileage =  -999999D;
    //最高行驶车速
    private Double max_speed =  0D;
    //soc消耗
    private Double soc_comsuption =  0D;
    //行程消耗时间(分钟)
    private Double time_comsuption =  -999999D;
    //总低速的个数
    private Long total_low_speed_nums = 0L;
    //总中速的个数
    private Long total_medium_speed_nums =  0L;
    //总高速个数
    private Long total_high_speed_nums =  0L;
    //低速soc消耗
    private Double Low_BMS_SOC =  0D;
    //中速soc消耗
    private Double Medium_BMS_SOC =  0D;
    //高速soc消耗
    private Double High_BMS_SOC =  0D;
    //低速里程
    private Double Low_BMS_Mileage =  0D;
    //中速里程
    private Double Medium_BMS_Mileage =  0D;
    //高速里程
    private Double High_BMS_Mileage =  0D;
    //是否为异常行程 0:正常行程 1:异常行程(只有一个采样点)
    private int tripStatus = -999999;

    /**
     * 将驾驶行程计算结果数据保存到hdfs时候需要转换成可以被hive所识别的字符串格式
     * @return
     */
    public String toHiveString() {
        StringBuilder resultString = new StringBuilder();
        if (this.vin != "") resultString.append(this.vin).append("\t"); else resultString.append("NULL").append("\t");
        if (this.tripStartTime != "") resultString.append(this.tripStartTime).append("\t"); else resultString.append("NULL").append("\t");
        if (this.tripEndTime != "") resultString.append(this.tripEndTime).append("\t"); else resultString.append("NULL").append("\t");
        if (this.lastSoc !=  -999999 ) resultString.append(this.lastSoc).append("\t"); else resultString.append("NULL").append("\t");
        if (this.lastMileage !=  -999999 ) resultString.append(this.lastMileage).append("\t"); else resultString.append("NULL").append("\t");
        if (this.start_BMS_SOC !=  -999999 ) resultString.append(this.start_BMS_SOC).append("\t"); else resultString.append("NULL").append("\t");
        if (this.start_longitude !=  -999999 ) resultString.append(this.start_longitude).append("\t"); else resultString.append("NULL").append("\t");
        if (this.start_latitude !=  -999999 ) resultString.append(this.start_latitude).append("\t"); else resultString.append("NULL").append("\t");
        if (this.start_mileage !=  -999999 ) resultString.append(this.start_mileage).append("\t"); else resultString.append("NULL").append("\t");
        if (this.end_BMS_SOC !=  -999999 ) resultString.append(this.end_BMS_SOC).append("\t"); else resultString.append("NULL").append("\t");
        if (this.end_longitude !=  -999999 ) resultString.append(this.end_longitude).append("\t"); else resultString.append("NULL").append("\t");
        if (this.end_latitude !=  -999999 ) resultString.append(this.end_latitude).append("\t"); else resultString.append("NULL").append("\t");
        if (this.end_mileage !=  -999999 ) resultString.append(this.end_mileage).append("\t"); else resultString.append("NULL").append("\t");
        if (this.mileage !=  -999999 ) resultString.append(this.mileage).append("\t"); else resultString.append("NULL").append("\t");
        if (this.max_speed !=  -999999 ) resultString.append(this.max_speed).append("\t"); else resultString.append("NULL").append("\t");
        if (this.soc_comsuption !=  -999999 ) resultString.append(this.soc_comsuption).append("\t"); else resultString.append("NULL").append("\t");
        if (this.time_comsuption !=  -999999 ) resultString.append(this.time_comsuption).append("\t"); else resultString.append("NULL").append("\t");
        if (this.total_low_speed_nums !=  -999999 ) resultString.append(this.total_low_speed_nums).append("\t"); else resultString.append("NULL").append("\t");
        if (this.total_medium_speed_nums !=  -999999 ) resultString.append(this.total_medium_speed_nums).append("\t"); else resultString.append("NULL").append("\t");
        if (this.total_high_speed_nums !=  -999999 ) resultString.append(this.total_high_speed_nums).append("\t"); else resultString.append("NULL").append("\t");
        if (this.Low_BMS_SOC !=  -999999 ) resultString.append(this.Low_BMS_SOC).append("\t"); else resultString.append("NULL").append("\t");
        if (this.Medium_BMS_SOC !=  -999999 ) resultString.append(this.Medium_BMS_SOC).append("\t"); else resultString.append("NULL").append("\t");
        if (this.High_BMS_SOC !=  -999999 ) resultString.append(this.High_BMS_SOC).append("\t"); else resultString.append("NULL").append("\t");
        if (this.Low_BMS_Mileage !=  -999999 ) resultString.append(this.Low_BMS_Mileage).append("\t"); else resultString.append("NULL").append("\t");
        if (this.Medium_BMS_Mileage !=  -999999 ) resultString.append(this.Medium_BMS_Mileage).append("\t"); else resultString.append("NULL").append("\t");
        if (this.High_BMS_Mileage !=  -999999 ) resultString.append(this.High_BMS_Mileage).append("\t"); else resultString.append("NULL").append("\t");
        if (this.tripStatus !=  -999999 ) resultString.append(this.tripStatus).append("\t"); else resultString.append("NULL").append("\t");
        resultString.append(DateUtil.getCurrentDateTime());
        return resultString.toString();
    }

}

这篇关于Flink流处理-Entity之Model的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!