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

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
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
@TableName("FAULTSNAP")
public class FaultSnap implements Serializable {

    @TableId("ID")
    private Long id;
    @TableField("STATIONID")
    private String stationId;
    @TableField("PROJECTID")
    private String projectId;
    @TableField("LINEID")
    private String lineId;
    @TableField("WINDTURBINEID")
    private String windturbineId;
    @TableField("ALERTVALUE")
    private int alertValue;
    @TableField("CATEGORY1")
    private String category1;
    @TableField("CATEGORY2")
    private String category2;
    @TableField("CATEGORY3")
    private String category3;
    @TableField("RANK")
    private String rank;
    @TableField("ISOPENED")
    private int isOpened;
    @TableField("LASTUPDATETIME")
    private Date lastUpdateTime;
    @TableField("LASTUPDATEPERSON")
    private String lastUpdatePerson;
    @TableField("STATIONNAME")
    private String stationName;
    @TableField("PROJECTNAME")
    private String projectName;
    @TableField("LINENAME")
    private String lineName;
    @TableField("WINDTURBINENAME")
    private String windturbineName;
    @TableField("ALERTTEXT")
    private String alertText;
    @TableField("MODELID")
    private String modelId;
    @TableField("TESTINGPOINTKEY")
    private String testingpointKey;
    @TableField("ALARMSNAPID")
    private long alarmSnapId;
    //接收AlarmSnap 中dataInfo值
    @TableField(exist = false)
    private String dataInfo;

    @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 "";
        }
    }
}
