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

import com.gyee.wisdom.common.data.ToData;
import com.gyee.wisdom.common.data.alarm.GyeeLine;
import com.gyee.wisdom.common.data.windturbine.Line;
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;

/**
 *author:wangjw
 */
@Data
@NoArgsConstructor
@ToString
@EqualsAndHashCode()
@Entity
@Table(name = "line")
public class GyeeLineEntity implements ToData<GyeeLine> {
    /** 主键ID */
    @Id
    /*@GeneratedValue(strategy = GenerationType.IDENTITY)*/
    @Column(name = "id")
    private String id;
    /** 编码 */
    @Column(name = "code")
    private String code;
    /** 名称 */
    @Column(name = "name")
    private String name;
    /** 地址*/
    @Column(name = "aname")
    private String aname;
    /** 项目id */
    @Column(name = "projectid")
    private String projectId;
    /** 顺序 */
    @Column(name = "ordernum")
    private Integer orderNum;
    /** 装机容量*/
    @Column(name = "capacity")
    private Double capacity;
    /*装机单位*/
    @Column(name = "capacityunit")
    private String capacityUnit;
    /*装机数量*/
    @Column(name = "quantity")
    private Integer quantity;

/*    @OneToMany(mappedBy=ModelConstants.ID_,cascade = {CascadeType.MERGE,CascadeType.REFRESH},fetch=FetchType.EAGER)
    private List<WindturbineEntity> listwindturbines;
    @ManyToOne(cascade = {CascadeType.MERGE,CascadeType.REFRESH},fetch=FetchType.EAGER)
    @JoinColumn(name=ModelConstants.PROJECT_ID, referencedColumnName=ModelConstants.ID_,insertable=false, updatable=false)
    private ProjectEntity project;*/

    public GyeeLineEntity(GyeeLine line) {
        this.id = line.getId();
        this.code = line.getCode();
        this.name = line.getName();
        this.aname = line.getAname();
        this.projectId = line.getProjectId();
        this.orderNum = line.getOrderNum();
        this.capacity = line.getCapacity();
        this.capacityUnit = line.getCapacityUnit();
        this.quantity = line.getQuantity();
/*        List<WindturbineEntity> windturbinelist=new ArrayList<WindturbineEntity>();
        for(Windturbine windturbine:line.getListwindturbine()){
            WindturbineEntity wind=  new WindturbineEntity(windturbine);
            windturbinelist.add(wind);
        }
        listwindturbines=windturbinelist;
        project=new ProjectEntity(line.getProject());*/
    }


    @Override
    public GyeeLine toData() {
        if(this!=null) {
            GyeeLine line = new GyeeLine();
            line.setId(this.id);
            line.setCode(this.code);
            line.setName(this.name);
            line.setAname(this.aname);
            line.setProjectId(this.projectId);
            line.setOrderNum(this.orderNum);
            line.setCapacity(this.capacity);
            line.setCapacityUnit(this.getCapacityUnit());
            line.setQuantity(this.getQuantity());
            return line;
        }else{
            return null;
        }
/*        line.setListwindturbine(DataUtil.convertDataList(this.listwindturbines));
        line.setProject(this.getProject().toData());*/

    }


}
