package com.gyee.wisdom.dao.sql.feature.entity;

import com.gyee.wisdom.common.data.ToData;
import com.gyee.wisdom.common.data.feature.FeatureStat;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Date;

/**
 * @descrition:
 * @author:Wanghs
 * @date:2019-11-18
 */
@Data
@Entity
@NoArgsConstructor
@Table(name = "feature_stat")
public class FeatureStatEntity implements ToData<FeatureStat> {

    //id
    @Id
    @Column(name = "id")
    private Long id;
    //风机编号
    @Column(name = "wtid")
    private String windturbineId;
    //风场编号
    @Column(name = "stationid")
    private String stationId;
    //统计日期
    @Column(name = "statdate")
    private Date statTime;
    //发生次数
    @Column(name = "total")
    private int total;
    //总时长(秒)
    @Column(name = "totalseconds")
    private int totalSeconds;
    //平均时长(秒)
    @Column(name = "avgseconds")
    private int avgSeconds;
    //最大时长
    @Column(name = "maxseconds")
    private int maxSeconds;
    //最小时长
    @Column(name = "minseconds")
    private int minSeconds;
    //类型编码
    @Column(name = "typecode")
    private String typeCode;
    //类型名称
    @Column(name = "typename")
    private String typeName;


    public FeatureStatEntity(FeatureStat stat) {
        this.id = stat.getId();
        this.windturbineId = stat.getWindturbineId();
        this.stationId = stat.getStationId();
        this.statTime = stat.getStatTime();
        this.total = stat.getTotal();
        this.totalSeconds = (int) stat.getTotalSeconds();
        this.avgSeconds = (int) stat.getAvgSeconds();
        this.maxSeconds = (int) stat.getMaxSeconds();
        this.minSeconds = (int) stat.getMinSeconds();
        this.typeCode = stat.getTypeCode();
        this.typeName = stat.getTypeName();
    }

    @Override
    public FeatureStat toData() {
        FeatureStat data = new FeatureStat();
        data.setId(this.id);
        data.setWindturbineId(this.windturbineId);
        data.setStationId(this.stationId);
        data.setStatTime(this.statTime);
        data.setTotal(this.total);
        data.setTotalSeconds(this.totalSeconds);
        data.setAvgSeconds(this.avgSeconds);
        data.setMaxSeconds(this.maxSeconds);
        data.setMinSeconds(this.minSeconds);
        data.setTypeCode(this.typeCode);
        data.setTypeName(this.typeName);
        return data;
    }
}
