package com.gyee.wisdom.dao.sql.alarm.Entity;

import com.gyee.wisdom.common.data.ToData;
import com.gyee.wisdom.common.data.alarm.GyeeWindturbine;
import com.gyee.wisdom.common.data.windturbine.Windturbine;
import com.gyee.wisdom.dao.sql.ModelConstants;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;

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


@Data
@NoArgsConstructor
@ToString
@EqualsAndHashCode()
@Entity
@Table(name = "windturbine")
public class GyeeWindturbineEntity implements ToData<GyeeWindturbine> {
    /** 主键ID */
    @Id
    /*@GeneratedValue(strategy = GenerationType.IDENTITY)*/
    @Column(name = "id")
    private String id;
    /** 编码 */
    @Column(name = "code")
    private String code;
    /** 风场id */
    @Column(name = "windpowerstationid")
    private String windPowerStationId;
    /** 经度*/
    @Column(name = "longitude")
    private Double longitude;
    /** 纬度 */
    @Column(name = "latitude")
    private Double latitude;
    /** 模型id */
    @Column(name = "modelid")
    private String modelId;
    /** 状态 */
    @Column(name = "status")
    private String status;
    /** 项目id */
    @Column(name = "projectid")
    private String projectId;
    /** 线路id */
    @Column(name = "lineid")
    private String lineId;
    /** 首次并网的时间 */
    @Column(name = "firstintegratedtime")
    private Date firstIntegratedTime;
    /** app注册ID */
    @Column(name = "photo")
    private String photo;
    /** app注册ID */
    @Column(name = "name")
    private String name;
    /** app注册ID */
    @Column(name = "standardid")
    private String standardid;
/*    @ManyToOne(cascade = {CascadeType.MERGE,CascadeType.REFRESH},fetch=FetchType.EAGER)
    @JoinColumn(name=ModelConstants.LINEID, referencedColumnName=ModelConstants.ID_,insertable=false, updatable=false)
    private LineEntity line;
    @ManyToOne(cascade = {CascadeType.MERGE,CascadeType.REFRESH},fetch=FetchType.EAGER)
    @JoinColumn(name=ModelConstants.MODELID, referencedColumnName=ModelConstants.ID_,insertable=false, updatable=false)
    private ModelEntity model;*/



    public GyeeWindturbineEntity(GyeeWindturbine win) {
        this.id = win.getId();
        this.code = win.getCode();
        this.windPowerStationId = win.getWindPowerStationId();
        this.longitude = win.getLongitude();
        this.latitude = win.getLatitude();
        this.modelId = win.getModelId();
        this.status = win.getStatus();
        this.projectId = win.getProjectId();
        this.lineId = win.getLineId();
        this.firstIntegratedTime = win.getFirstIntegratedTime();
        this.photo = win.getPhoto();
        this.name = win.getName();
        this.standardid=win.getStandardid();
/*        this.line=new LineEntity(win.getLine());
        this.model=new ModelEntity(win.getModel());*/
    }


    @Override
    public GyeeWindturbine toData() {
        if(this!=null) {
            GyeeWindturbine win = new GyeeWindturbine();
            win.setId(id);
            win.setCode(code);
            win.setWindPowerStationId(windPowerStationId);
            win.setLongitude(longitude);
            win.setLatitude(latitude);
            win.setModelId(modelId);
            win.setStatus(status);
            win.setProjectId(projectId);
            win.setLineId(lineId);
            win.setFirstIntegratedTime(firstIntegratedTime);
            win.setPhoto(photo);
            win.setName(name);
            win.setStandardid(standardid);
/*        win.setLine(line.toData());
        win.setModel(model.toData());*/
            return win;
        }else{
            return null;
        }
    }


}
