package com.casic.PgInterface.devTable.dto;

import com.casic.PgInterface.devTable.domain.PgAlarm;
import com.casic.PgInterface.devTable.domain.PgDevice;
import com.casic.PgInterface.devTable.manager.PgAlarmTypeManager;
import com.casic.PgInterface.devTable.manager.PgDeviceManager;
import com.casic.PgInterface.patroler.manager.PgUserManager;

import java.text.SimpleDateFormat;

/**
 * Created by yxw on 2017/10/30.
 */
public class PgAlarmDto{

    private String id;
    private String alarmType;//报警类型
    private String alarmValue;//报警值
    private String alarmDate;//报警时间
    private String description;//描述
    private String alarmDevName;//报警设备
    private Long alarmDevId;//报警设备ID
    private String alarmLocation;//报警位置
    private String assetCode;//资产编号
    private String partition;//所在分区
    private String userName;//责任人
    private String phoneNumber;//联系电话
    private String active;//状态
    private String devType;//设备类型
    private String alarmGrade;//报警等级

    public String getId() {
        return id;
    }

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

    public String getAlarmType() {
        return alarmType;
    }

    public void setAlarmType(String alarmType) {
        this.alarmType = alarmType;
    }

    public String getAlarmValue() {
        return alarmValue;
    }

    public void setAlarmValue(String alarmValue) {
        this.alarmValue = alarmValue;
    }

    public String getAlarmDate() {
        return alarmDate;
    }

    public void setAlarmDate(String alarmDate) {
        this.alarmDate = alarmDate;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getAlarmDevName() {
        return alarmDevName;
    }

    public void setAlarmDevName(String alarmDevName) {
        this.alarmDevName = alarmDevName;
    }

    public Long getAlarmDevId() {
        return alarmDevId;
    }

    public void setAlarmDevId(Long alarmDevId) {
        this.alarmDevId = alarmDevId;
    }

    public String getAlarmLocation() {
        return alarmLocation;
    }

    public void setAlarmLocation(String alarmLocation) {
        this.alarmLocation = alarmLocation;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public String getActive() {
        return active;
    }

    public void setActive(String active) {
        this.active = active;
    }

    public String getDevType() {
        return devType;
    }

    public void setDevType(String devType) {
        this.devType = devType;
    }

    public String getAssetCode() {
        return assetCode;
    }

    public void setAssetCode(String assetCode) {
        this.assetCode = assetCode;
    }

    public String getPartition() {
        return partition;
    }

    public void setPartition(String partition) {
        this.partition = partition;
    }

    public String getAlarmGrade() {
        return alarmGrade;
    }

    public void setAlarmGrade(String alarmGrade) {
        this.alarmGrade = alarmGrade;
    }

    public PgAlarmDto(PgAlarm pgAlarm) {
        if(pgAlarm==null) return;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        this.setId(String.valueOf(pgAlarm.getId()));

        if(pgAlarm.getAlarmTypeId()==null)
            this.setAlarmType("");
        else
            this.setAlarmType(pgAlarm.getAlarmTypeId().getAlarmType());
        if(pgAlarm.getAlarmValue()==null)
            this.setAlarmValue("");
        else
            this.setAlarmValue(pgAlarm.getAlarmValue());
        if (pgAlarm.getAlarmDate() != null)
            this.setAlarmDate(sdf.format(pgAlarm.getAlarmDate()));
        else
            this.setAlarmDate("");
        this.setDescription(pgAlarm.getDescription());
        if(pgAlarm.getAlarmDevId()==null)
        {
            this.setAlarmDevId(null);
            this.setAlarmDevName("");
            this.setAlarmLocation("");
            this.setAssetCode("");
            this.setDevType("");
            this.setPartition("");
        }
        else
        {
            this.setAlarmDevId(pgAlarm.getAlarmDevId().getId());
            this.setAlarmDevName(pgAlarm.getAlarmDevId().getAssetName());
            this.setAlarmLocation(pgAlarm.getAlarmDevId().getPosition());
            this.setAssetCode(pgAlarm.getAlarmDevId().getAssetCode());
            this.setDevType(pgAlarm.getAlarmDevId().getDevType());
            this.setPartition(pgAlarm.getAlarmDevId().getPartition());
        }
        if(pgAlarm.getUserId()==null)
        {
            this.setUserName("");
            this.setPhoneNumber("");
        }
        else {
            this.setUserName(pgAlarm.getUserId().getUserName());
            this.setPhoneNumber(pgAlarm.getUserId().getPhoneNumber());
        }

        this.setAlarmGrade(pgAlarm.getAlarmGrade());
        this.setActive(String.valueOf(pgAlarm.getActive()));
    }

}