package com.casic.missiles.modular.system.dto;

import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by test203 on 2019/5/20.
 */
@Component
public class BusConfigDTO {
    private Long id;
    private Long deviceId;
    private String devcode;        //设备编号
    private String deviceName;        //设备名称
    private Long deviceType;        //设备类型编号
    private String deviceTypeName;    //	设备类型名称
    private String deptid;    //	权属单位id
    private String deptName;//	权属单位名称
    private String wellCode;//	闸井编号
    private float threshold;//		报警阈值
    private float percent;//	井深百分比
    private float installHeight;        //安装高度
    private String retryTimes;//	重传次数
    private String ip;//	IP地址
    private String port;//		端口
    private String attemptsMax;    //最大尝试次数
    private String attemptsCurrent;//	已尝试次数
    private String status;//	已尝试次数
    private String statusName;//	已尝试次数

    private String collectInterval;//采集间隔
    private String collectCount;//采集次数
    private String reloadInterval;//重传次数
    private String sleepPeriod;//休眠周期
    private String uploadPeriod;//上传周期
    private String collectTime;//采集时间
    private String sleepStartTime;//休眠开始时间
    private String sensorId;//休眠开始时间

    public static Map<Integer, String> sensorHashMap = new HashMap<Integer, String>();
    {//根据前期产品化文档，配置时存入config表中对应的sensorid字段，区分是哪类设备
        sensorHashMap.put(DeviceTypeEnum.Liquid.getIndex(), "000034");
        sensorHashMap.put(DeviceTypeEnum.Methane.getIndex(), "000044");
        sensorHashMap.put(DeviceTypeEnum.Tube.getIndex(), "000080");
        sensorHashMap.put(DeviceTypeEnum.WasteGas.getIndex(), "000035");
        sensorHashMap.put(DeviceTypeEnum.TempHumi.getIndex(), "000055");
        sensorHashMap.put(DeviceTypeEnum.Dig.getIndex(), "000064");
        sensorHashMap.put(DeviceTypeEnum.Noise.getIndex(), "000032");
        sensorHashMap.put(DeviceTypeEnum.LG.getIndex(), "000065");
    }

//    private String framecontent;//下发内容


    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public void setDeviceType(Long deviceType) {
        this.deviceType = deviceType;
    }

    public Long getDeviceId() {
        return deviceId;
    }

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

    public String getDevcode() {
        return devcode;
    }

    public void setDevcode(String devcode) {
        this.devcode = devcode;
    }

    public String getDeviceName() {
        return deviceName;
    }

    public void setDeviceName(String deviceName) {
        this.deviceName = deviceName;
    }

    public String getDeviceTypeName() {
        return deviceTypeName;
    }

    public void setDeviceTypeName(String deviceTypeName) {
        this.deviceTypeName = deviceTypeName;
    }

    public String getDeptid() {
        return deptid;
    }

    public void setDeptid(String deptid) {
        this.deptid = deptid;
    }

    public String getDeptName() {
        return deptName;
    }

    public void setDeptName(String deptName) {
        this.deptName = deptName;
    }

    public String getWellCode() {
        return wellCode;
    }

    public void setWellCode(String wellCode) {
        this.wellCode = wellCode;
    }

    public float getThreshold() {
        return threshold;
    }

    public void setThreshold(float threshold) {
        this.threshold = threshold;
    }

    public float getPercent() {
        return percent;
    }

    public void setPercent(float percent) {
        this.percent = percent;
    }

    public float getInstallHeight() {
        return installHeight;
    }

    public void setInstallHeight(float installHeight) {
        this.installHeight = installHeight;
    }

    public String getRetryTimes() {
        return retryTimes;
    }

    public void setRetryTimes(String retryTimes) {
        this.retryTimes = retryTimes;
    }

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public String getPort() {
        return port;
    }

    public void setPort(String port) {
        this.port = port;
    }

    public String getAttemptsMax() {
        return attemptsMax;
    }

    public void setAttemptsMax(String attemptsMax) {
        this.attemptsMax = attemptsMax;
    }

    public String getAttemptsCurrent() {
        return attemptsCurrent;
    }

    public void setAttemptsCurrent(String attemptsCurrent) {
        this.attemptsCurrent = attemptsCurrent;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getStatusName() {
        return statusName;
    }

    public void setStatusName(String statusName) {
        this.statusName = statusName;
    }

    public Long getDeviceType() {
        return deviceType;
    }

    public String getCollectInterval() {
        return collectInterval;
    }

    public void setCollectInterval(String collectInterval) {
        this.collectInterval = collectInterval;
    }

    public String getCollectCount() {
        return collectCount;
    }

    public void setCollectCount(String collectCount) {
        this.collectCount = collectCount;
    }

    public String getReloadInterval() {
        return reloadInterval;
    }

    public void setReloadInterval(String reloadInterval) {
        this.reloadInterval = reloadInterval;
    }

    public String getSleepPeriod() {
        return sleepPeriod;
    }

    public void setSleepPeriod(String sleepPeriod) {
        this.sleepPeriod = sleepPeriod;
    }

    public String getUploadPeriod() {
        return uploadPeriod;
    }

    public void setUploadPeriod(String uploadPeriod) {
        this.uploadPeriod = uploadPeriod;
    }

    public String getCollectTime() {
        return collectTime;
    }

    public void setCollectTime(String collectTime) {
        this.collectTime = collectTime;
    }

    public String getSleepStartTime() {
        return sleepStartTime;
    }

    public void setSleepStartTime(String sleepStartTime) {
        this.sleepStartTime = sleepStartTime;
    }

    public String getSensorId() {
        return sensorId;
    }

    public void setSensorId(String sensorId) {
        this.sensorId = sensorId;
    }

    public BusConfigDTO() {
    }


    public static BusConfigDTO ConvertDTO(Map<String, Object> objectMap) {
        if (null != objectMap) {
            BusConfigDTO dto = new BusConfigDTO();
            dto.setId(null != objectMap.get("id") ?
                    Long.valueOf(objectMap.get("id").toString()) : null);
            dto.setDeviceId(null != objectMap.get("deviceId") ?
                    Long.valueOf(objectMap.get("deviceId").toString()) : null);
            dto.setDevcode(objectMap.get("devcode").toString());
            dto.setDeviceName(objectMap.get("deviceName").toString());
            dto.setDeviceType(null != objectMap.get("deviceType") ?
                    Long.valueOf(objectMap.get("deviceType").toString()) : null);
            dto.setDeviceTypeName(objectMap.get("deviceTypeName").toString());
            dto.setDeptid(objectMap.get("deptid").toString());
            dto.setDeptName(objectMap.get("deptName").toString());
            dto.setWellCode(objectMap.get("wellCode").toString());
            dto.setAttemptsCurrent(null != objectMap.get("attemptscurrent") ?
                    objectMap.get("attemptscurrent").toString() : "");
            dto.setStatus(objectMap.get("status").toString());
            dto.setStatusName("1".equals(objectMap.get("status").toString()) ?
                    "已下发" : "未下发");
            dto.setAttemptsMax(objectMap.get("attemptsmax").toString());
            return dto;
        }
        return new BusConfigDTO();
    }

    public static List<BusConfigDTO> convert(List<Map<String, Object>> result) {
        List<BusConfigDTO> busConfigDTOList = new ArrayList<>();
        for (Map<String, Object> objectMap : result) {
            busConfigDTOList.add(ConvertDTO(objectMap));
        }
        return busConfigDTOList;
    }
}
