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

import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.gyee.wisdom.alarm.sharding.config.MyConfig;
import com.gyee.wisdom.alarm.sharding.util.ChineseDes;
import com.gyee.wisdom.alarm.sharding.util.SpringContextUtil;
import lombok.AccessLevel;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;

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

@Data
@TableName("ALERTRULE2")
public class Alertrule2 implements Serializable {

    @TableId("id")
    private String id;
    @ChineseDes("名称")
    @TableField("Name")
    private String name;
    @JSONField(serialize=false,deserialize = false) //不序列化
    @ChineseDes("规则描述")
    @TableField("description")
    private String description;
    @JSONField(serialize=false,deserialize = false)//不序列化
    @ChineseDes("表达式")
    @TableField("expression")
    private String expression;
    @ChineseDes("标签")
    @TableField("tag")
    private String tag;
    @ChineseDes("报警级别")
    @TableField("rank")
    private String rank;
    @ChineseDes("是否启用")
    @TableField("enabled")
    private int enabled;
    @ChineseDes("风机类型")
    @TableField("modelId")
    private String modelId;
    @ChineseDes("ednavlue")
    @TableField("ednaValue")
    private int ednaValue;
    @ChineseDes("类别")
    @TableField("category")
    private String category;
    @ChineseDes("range范围")
    @TableField("range")
    private String range;
    @ChineseDes("场站")
    @TableField("station")
    private String station;
    @ChineseDes("风机")
    @TableField("windturbine")
    private String windturbine;
    @ChineseDes("线路")
    @TableField("line")
    private String line;
    @ChineseDes("项目")
    @TableField("project")
    private String project;
    @ChineseDes("电气")
    @TableField("electrical")
    private String electrical;
    @ChineseDes("任务开始事件")
    @TableField("taskstart")
    private String taskstart;
    @TableField("relatedParts")
    @ChineseDes("关联部件")
    private String relatedParts;//关联部件
    @TableField(exist = false)
    private String userName;//操作人
    @ChineseDes("操作时间")
    @TableField("createtime")
    private Date createtime;//操作时间
    //前端显示字段 防止报警规则泄漏
    @TableField(exist = false)
    @Setter(AccessLevel.NONE)
    @Getter(AccessLevel.NONE)
    private String descriptionShow;
    //前端显示字段 防止报警规则泄漏
    @TableField(exist = false)
    @Setter(AccessLevel.NONE)
    @Getter(AccessLevel.NONE)
    private String expressionShow;

    private WindPowerStation windPowerStation;
    private Datadictionary datadictionary;

    public  String getDescriptionShow(){
        boolean ruleEncryption = MyConfig.getRuleEncryption();
        if(ruleEncryption&&"1".equals(this.range))
            return "***********";
        else
            return this.description;

    }
    public String getExpressionShow(){
        boolean ruleEncryption = MyConfig.getRuleEncryption();
        if(ruleEncryption&&"1".equals(this.range))
            return "***********";
        else
            return this.expression;
    }

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

    public void setExpressionShow(String expression){
        this.expression=expression;
        this.expressionShow=expression;
    }
}
