package com.huatek.busi.dto.cable;

import com.huatek.torch.sql.annotation.FieldName;
import com.huatek.torch.sql.beans.PageBean;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.util.StringUtils;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * 电缆环流
 *
 * @author Bobi_huo
 * @date 2020-09-10 10:32
 */
@ApiModel(value = "BusiCableDlgDto", description = "电缆沟 Dto", parent = PageBean.class)
@Data
@EqualsAndHashCode(callSuper = false)
public class BusiCableDlgDto extends PageBean implements Serializable {

    private static final long serialVersionUID = -6151563459902980836L;

    @ApiModelProperty(hidden = true)
    private final int DEFAULT_DAYS = 15;

    /**
     * 主键id
     */
    @ApiModelProperty(name = "id", value = "主键ID")
    private String id;

    /**
     * CAC 的唯一标识（17 位码）
     */
    @ApiModelProperty(name = "cacId", value = "CAC 的唯一标识（17 位码）")
    private String cacId;

    /**
     * 监测数据组的数目
     */
    @ApiModelProperty(name = "dataNodeNum", value = "监测数据组的数目")
    private BigDecimal dataNodeNum;

    /**
     * 在线监测装置的唯一标识（17 位码）
     */
    @ApiModelProperty(name = "sensorId", value = "在线监测装置的唯一标识（17 位码）")
    private String sensorId;

    /**
     * 监测类型编码
     */
    @ApiModelProperty(name = "cacMonitorTypeCode", value = "监测类型编码")
    private String cacMonitorTypeCode;

    /**
     * 在线监测装置对应的被监测设备的 唯一标识（17 位码）
     */
    @ApiModelProperty(name = "equipmentId", value = "在线监测装置对应的被监测设备的 唯一标识（17 位码）")
    private String equipmentId;

    /**
     * 数据采集时间
     */
    @ApiModelProperty(name = "timeStamp", value = "数据采集时间，格式为：yyyy-MM-dd HH:mm:ss")
    private LocalDateTime timeStamp;

    /**
     * 站点ID
     */
    @ApiModelProperty(name = "siteId", value = "站点ID")
    private String siteId;

    /**
     * 被监测设备相别
     */
    @ApiModelProperty(name = "phase", value = "被监测设备相别")
    private String phase;

    /**
     * @Fields temperature :温度
     */
    @FieldName("temperature")
    private String temperature;

    /**
     * @Fields humidity :湿度
     */
    @FieldName("humidity")
    private String humidity;

    /**
     * @Fields aWater :水浸
     */
    @FieldName("a_water")
    private String aWater;

    /**
     * @Fields smokeAlarm1: 烟雾告警1
     */
    @FieldName("smoke_alarm1")
    private String smokeAlarm1;

    /**
     * @Fields smokeAlarm2: 烟雾告警2
     */
    @FieldName("smoke_alarm2")
    private String smokeAlarm2;

    /**
     * @Fields smokeAlarm3: 烟雾告警3
     */
    @FieldName("smoke_alarm3")
    private String smokeAlarm3;

    /**
     * 主设备ID
     */
    @ApiModelProperty(name = "mainEquipmentId", value = "主设备ID")
    private String mainEquipmentId;

    /**
     * 外挂设备ID
     */
    @ApiModelProperty(name = "subEquipmentId", value = "外挂设备ID")
    private String subEquipmentId;

    /**
     * 主设备编号
     */
    @ApiModelProperty(name = "equipmentCode", value = "主设备编号")
    private String equipmentCode;

    /**
     * 外挂设备编号
     */
    @ApiModelProperty(name = "extEquipmentCode", value = "外挂设备编号")
    private String extEquipmentCode;

    /**
     * 站点设备树ID
     */
    @ApiModelProperty(name = "mainTreeId", value = "站点设备树ID")
    private String mainTreeId;

    /**
     * 外挂设备树ID
     */
    @ApiModelProperty(name = "subTreeId", value = "外挂设备树ID")
    private String subTreeId;

    /**
     * 设备运行状态：0-无  1-发电  2-抽水  3-空闲
     */
    @ApiModelProperty(name = "runState", value = "设备运行状态")
    private String runState;

    /**
     * 序号
     */
    @ApiModelProperty(name = "serialNumber", value = "序号")
    private String serialNumber;

    /**
     * 状态：2-删除，1-正常
     */
    @ApiModelProperty(name = "status", value = "状态")
    private String status;

    /**
     * hbase中的rowkey
     */
    @ApiModelProperty(name = "hbaseRowkey", value = "hbase中的rowkey")
    private String hbaseRowkey;

    /**
     * 开始日期
     */
    @ApiModelProperty(value = "开始日期", name = "startTime")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private LocalDate startTime;

    /**
     * 终止日期
     */
    @ApiModelProperty(value = "终止日期", name = "endTime")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private LocalDate endTime;

    public BusiCableDlgDto check() {
        if (this.getStartTime() == null && this.getEndTime() == null) {
            this.setEndTime(LocalDate.now());
            this.setStartTime(this.getEndTime().minusDays(DEFAULT_DAYS));
        }
        if(StringUtils.isEmpty(this.sensorId)) {
            this.sensorId = this.mainTreeId;
        }
        return this;
    }

}
