package com.hzjt.util;

import com.alibaba.fastjson.JSONObject;
import com.hzjt.domain.DeviceWriteParam;
import com.hzjt.domain.SbtdspsrParam;
import com.hzjt.domain.Traffdevicewriteresult;
import org.apache.commons.lang3.StringUtils;

/**
 * @author chenl
 * @version 1.0
 * @date 2020/3/15 22:13
 *
 *   deviceID;
 *   deviceType;
 *   deviceName;
 *   regionID;
 *   deviceStatus;
 *   deviceSupplier;
 *   dataType;
 *   locationType;
 *   locationX;
 *   locationY;
 *   locationEndX;
 *   locationEndY;
 */
public class TransHelper {
    public static DeviceWriteParam transDevice(SbtdspsrParam sbtdspsr, int dataType){
        DeviceWriteParam param  = new DeviceWriteParam();
        Long sbtdbh = sbtdspsr.getTdbh();
        //设备ID
        param.setDeviceID(sbtdspsr.getSbbh() + ( sbtdbh >= 10 ? sbtdbh : "0" + sbtdbh));
        //设备名称
        param.setDeviceName(sbtdspsr.getTdmc());
        //设备行政编号
        param.setRegionID(sbtdspsr.getXzbh());
        //设备状态正常填1
        param.setDeviceStatus(1);
        //设备推送者zksy中科
        param.setDeviceSupplier(sbtdspsr.getSbcsName());
        //设备注册操作填1
        param.setDataType(dataType);
        //设备额外配置JSON字符串
        JSONObject jsonObject = JSONObject.parseObject(sbtdspsr.getDeviceconfig());
        //道路类型
        if(jsonObject.get("RoadType")!=null){
            param.setRoadType(Integer.parseInt(jsonObject.get("RoadType").toString()));
        }
        //设备类型
        if(jsonObject.get("DeviceType")!=null && StringUtils.isNotBlank(jsonObject.get("DeviceType").toString())){
            param.setDeviceType(jsonObject.get("DeviceType").toString());
        }
        //所在位置方向。1-上行；2-下行。
        if(jsonObject.get("DeviceDirection")!=null){
            param.setDeviceDirection(Integer.parseInt(jsonObject.get("DeviceDirection").toString()));
        }
        //设备所在里程桩公里数
        if(jsonObject.get("StartNumK")!=null){
            param.setStartNumK(Integer.parseInt(jsonObject.get("StartNumK").toString()));
        }
        //设备所在里程桩米数
        if(jsonObject.get("StartNumM")!=null){
            param.setStartNumM(Integer.parseInt(jsonObject.get("StartNumM").toString()));
        }
        //道路代码 比如：G1504宁波绕城高速
        if(jsonObject.get("RoadNum")!=null && StringUtils.isNotBlank(jsonObject.get("RoadNum").toString())){
            param.setRoadNum(jsonObject.get("RoadNum").toString());
        }
        //地点名称。设备所在地点名称例如G15沈海高速、台州收费站、台州服务区、仰义枢纽（）
        if(jsonObject.get("LocationDesc")!=null && StringUtils.isNotBlank(jsonObject.get("LocationDesc").toString())){
            param.setLocationDesc(jsonObject.get("LocationDesc").toString());
        }
        //所在收费站具体位置
        if(jsonObject.get("Toll")!=null){
            param.setToll(Integer.parseInt(jsonObject.get("Toll").toString()));
        }
        //所在地POI编码，例如，XX收费站对应编码
        if(jsonObject.get("LocationID")!=null && StringUtils.isNotBlank(jsonObject.get("LocationID").toString())){
            param.setLocationID(jsonObject.get("LocationID").toString());
        }
        //所在服务区具体位置描述
        if(jsonObject.get("ServiceArea")!=null){
            param.setServiceArea(Integer.parseInt(jsonObject.get("ServiceArea").toString()));
        }
        //所在匝道（收费站）具体位置描述
        if(jsonObject.get("RampToll")!=null){
            param.setRampToll(Integer.parseInt(jsonObject.get("RampToll").toString()));
        }
        //所在匝道（服务区）具体位置描述
        if(jsonObject.get("RampServiceArea")!=null){
            param.setRampServiceArea(Integer.parseInt(jsonObject.get("RampServiceArea").toString()));
        }
        //匝道（枢纽）转入的道路代码采用国家统一编码规则比如：G1504宁波绕城高速
        if(jsonObject.get("RampHubRoad")!=null && StringUtils.isNotBlank(jsonObject.get("RampHubRoad").toString())){
            param.setRampHubRoad(jsonObject.get("RampHubRoad").toString());
        }
        //匝道（枢纽）转入的道路方向。1-上行；2-下行
        if(jsonObject.get("RampHubDirection")!=null){
            param.setRampHubDirection(Integer.parseInt(jsonObject.get("RampHubDirection").toString()));
        }

//        param.setLocationType();
//        param.setLocationX();
//        param.setLocationY();
//        param.setLocationEndX();
//        param.setLocationEndY();
        return param;
    }

    public static Traffdevicewriteresult transDeviceWriteResult(SbtdspsrParam sbtdspsr) {
        Traffdevicewriteresult param = new Traffdevicewriteresult();
        param.setSbbh(sbtdspsr.getSbbh());
        param.setTdbh(sbtdspsr.getTdbh());
        return param;
    }

    public static Traffdevicewriteresult transDeviceWriteResult(SbtdspsrParam sbtdspsr, Long pushstatus, String pushdesc) {
        Traffdevicewriteresult param = new Traffdevicewriteresult();
        param.setSbbh(sbtdspsr.getSbbh());
        param.setTdbh(sbtdspsr.getTdbh());
        param.setPushstatus(pushstatus);
        param.setPushcount(1L);
        param.setXzbh(sbtdspsr.getXzbh());
        param.setPushdesc(pushdesc);
        return param;
    }

    public static Traffdevicewriteresult transDeviceWriteResult(SbtdspsrParam sbtdspsr, Long pushstatus, String pushdesc, Long pushcount) {
        Traffdevicewriteresult param = new Traffdevicewriteresult();
        param.setSbbh(sbtdspsr.getSbbh());
        param.setTdbh(sbtdspsr.getTdbh());
        param.setPushstatus(pushstatus);
        param.setPushdesc(pushdesc);
        param.setPushdesc(pushdesc);
        param.setXzbh(sbtdspsr.getXzbh());
        param.setPushcount(pushcount);
        return param;
    }
}
