package cn.wise.sc.energy.power.plant.business.domain;


import cn.wise.sc.energy.power.plant.business.domain.eum.SignalTypeEnum;
import cn.wise.sc.energy.power.plant.business.domain.vo.CharacterParamInfoVo;
import cn.wise.sc.energy.power.plant.business.domain.vo.EntityVo;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.List;

/**
 * @description: 检测特点信息
 * @author: qh
 * @create: 2020-07-14 09:40
 **/
@Entity
@Data
@NoArgsConstructor
@Table(name = "characterparaminfo")
public class CharacterParamInfo extends AbstractEntity<String> {

    /**
     * 转换成Vo
     *
     * @return
     */
    @Override
    public EntityVo toVo() {
        CharacterParamInfoVo characterParamInfoVo = new CharacterParamInfoVo();
        BeanUtils.copyProperties(this, characterParamInfoVo);
        return characterParamInfoVo;
    }
    @Column(name = "parentdir")
    private String parentDir;
    /**
     * 监测特征所属电站的标识
     */
    @Column(name = "plantid")
    private String plantId;
    /**
     * 监测特征所属设备的标识
     */
    @Column(name = "deviceid")
    private String deviceId;
    /**
     * 监测特征所属监测单元标识
     */
    @Column(name = "unitcodeid")
    private String unitCodeId;
    /**
     * 监测特征唯一标识编码(KKS编码)如：C0A00101CBA00MKF26S101
     */
    @Id
    @Column(name = "kkscode")
    private String kksCode;
    /**
     * 监测特征名称
     */
    @Column(name = "cpname")
    private String cpName;
    /**
     * todo 枚举
     * 监测特征计算类型，很重要
     */
    @Column(name = "cptype")
    private Integer cpType;
    /**
     * 监测特征的物理单位，如 um/mm 等
     */
    @Column(name = "cpunit")
    private String cpUnit;
    /**
     * 监测特征 信号类型:
     * T: 温度参数   M: 机械参数
     * E: 电气参数   A: 辅机参数
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "signaltype")
    private SignalTypeEnum signalType;
    /**
     * 特征参数是否属于派生的特征参数
     * 1: 是  0: 不是
     */
    @Column(name = "isderiveparam")
    private Integer isDeriveParam;
    /**
     * 如果 isderiveparam =1  时，该字段 指名本特征参数是从哪一个  特征参数 计算获得，
     * derivefrom 指明该特征参数的KKScode
     */
    @Column(name = "derivedfrom")
    private String derivedFrom;
    /**
     * 特征参数保护(一级报警)规则是否有效
     * 1: 有效 0:无效(未设定)
     */
    @Column(name = "protectrulevalid")
    private Integer protectRuleValid;
    /**
     * 特征参数保护(一级报警)上限值
     */
    @Column(name = "protectrulemaxvalue")
    private Float protectRuleMaxValue;
    /**
     * 特征参数保护(一级报警)下限值
     */
    @Column(name = "protectruleminvalue")
    private Float protectRuleMinValue;

    /**
     * 特征参数保护(一级报警)规则阈值范围是否是排除范围
     * 1: 是排除范围 0:是限定范围
     */
    @Column(name = "protectruleexclude")
    private Integer protectRuleExclude;
    /**
     * 特征参数报警(二级报警)规则是否有效
     * 1: 有效 0:无效(未设定)
     */
    @Column(name = "alertrulevalid")
    private Integer alertRuleValid;
    /**
     * 特征参数警(二级报警)下限值
     */
    @Column(name = "alertruleminvalue")
    private Float alertRuleMinValue;
    /**
     * 特征参数报警(二级报警)上限值
     */
    @Column(name = "alertrulemaxvalue")
    private Float alertRuleMaxValue;
    /**
     * 特征参数报警(二级报警)规则阈值范围是否是排除范围
     * 1: 是排除范围 0:是限定范围
     */
    @Column(name = "alertruleexclude")
    private Integer alertRuleExclude;

    @Column(name = "hasderiveparam")
    private Integer hasDeriveParam;

    @Override
    public String getId() {
        return getKksCode();
    }

    /**
     * 报警值对象
     */
    @Data
    public static class Alert {
        /**
         * 一级报警上限值
         */
        private Float protectRuleMaxValue;
        /**
         * 一级报警下限值
         */
        private Float protectRuleMinValue;

        /**
         * 特征参数保护(一级报警)规则阈值范围是否是排除范围
         * 1: 是排除范围 0:是限定范围
         * 1表示这个范围内的为不报警的
         * 0表示这个范围内为报警的
         */
        private Integer protectRuleExclude;
        /**
         * 二级报警下限值
         */
        private Float alertRuleMinValue;
        /**
         * 二级报警上限值
         */
        private Float alertRuleMaxValue;
        /**
         * 特征参数保护(二级报警)规则阈值范围是否是排除范围
         * 1: 是排除范围 0:是限定范围
         * 1表示这个范围内的为不报警的
         * 0表示这个范围内为报警的
         */
        private Integer alertRuleExclude;
    }
}
