package com.gyee.wisdom.alarm.sharding.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.gyee.wisdom.alarm.sharding.cache.WindturbineCache;
import com.gyee.wisdom.alarm.sharding.util.SpringContextUtil;
import lombok.AccessLevel;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.Date;


@Data
public class FaultInfo implements Serializable {


    private long id;
    //报警时间
    private Date faultTime;
    //对象类型
    private int messageType;
    //报警内容
    private long snapID;

    private Integer confirmType;

    private Date confirmTime;

    private String confirmPerson;

    private String stationId;

    private String projectId;

    private String lineId;

    private String windturbineId;
    //报警对应故障编码
    private long alertValue;
    //报警级别
    private String rank;

    private String category1;

    private String category2;

    private String category3;

    private boolean isOpened;

    private Date lastUpdateTime;

    private String lastUpdatePerson;

    private String stationName;

    private String projectName;

    private String lineName;

    private String windturbineName;

    private String alertText;

    private String modelId;

    public String getObjectName() {
        if (category1 == "FJ")
            return windturbineName;
        else
            return stationName;
    }

    public String getObjectId() {
        if (category1.equals("FJ"))
            return windturbineId;
        else
            return stationId;
    }

    public String getCategoryName() {
        switch (category1) {
            case "FJ":
                return "风机";
            case "SYZ":
                return "升压站";
            default:
                return "未知";
        }
    }

    public String getMessageTypeString() {
        String resultString = "";
        if (messageType == 1) {
            resultString = "触发";
        } else if (messageType == 2) {
            resultString = "";
        } else if (messageType == 3) {
            resultString = "解除";
        }
        return resultString;
    }

    public String getIdString() {
        return id + "";
    }

    @TableField(exist = false)
    @Getter(AccessLevel.NONE)
    @Setter(AccessLevel.NONE)
    private String shortStationName;

    @TableField(exist = false)
    @Getter(AccessLevel.NONE)
    @Setter(AccessLevel.NONE)
    private String windturbineCode;


    public String getShortStationName() {
        return this.stationName.replace("风电场", "").replace("风场", "");
    }

    public String getWindturbineCode() {
        WindturbineCache bean = SpringContextUtil.getBean(WindturbineCache.class);
        if (StringUtils.isNotBlank(this.windturbineId)) {

            Windturbine windturbine = bean.getWindturbine(this.windturbineId);
            if (windturbine != null)
                return windturbine.getCode();
            else
                return "";
        } else {
            return "";
        }
    }
}
