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

import com.gyee.wisdom.common.data.ToData;
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.*;
import java.math.BigDecimal;

/**
 *author:wangjw
 */
@Data
@NoArgsConstructor
@ToString
@EqualsAndHashCode()
@Entity
@Table(name = ModelConstants.LINE_)
public class LineEntity implements ToData<Line> {
    /** 主键ID */
    @Id
    /*@GeneratedValue(strategy = GenerationType.IDENTITY)*/
    @Column(name = ModelConstants.ID_)
    private String id;
    /** 编码 */
    @Column(name = ModelConstants.CODE_)
    private String code;
    /** 名称 */
    @Column(name = ModelConstants.NAME_)
    private String name;
    /** 地址*/
    @Column(name = ModelConstants.ANAME_)
    private String aname;
    /** 项目id */
    @Column(name = ModelConstants.PROJECT_ID)
    private String projectId;
    /** 顺序 */
    @Column(name = ModelConstants.ORDER_NUM)
    private Integer orderNum;
    /** 装机容量*/
    @Column(name = ModelConstants.CAPACITY_)
    private Double capacity;
    /*装机单位*/
    @Column(name = ModelConstants.CAPACITY_UNIT)
    private String capacityUnit;
    /*装机数量*/
    @Column(name = ModelConstants.QUANTITY)
    private Integer quantity;
    /*风场编号*/
    @Column(name = ModelConstants.STATION_CODE)
    private String stationCode;
/*    @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 LineEntity(Line 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();
        this.stationCode = line.getStationCode();
/*        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 Line toData() {
        if(this!=null) {
            Line line = new Line();
            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());
            line.setStationCode(this.stationCode);
            return line;
        }else{
            return null;
        }
/*        line.setListwindturbine(DataUtil.convertDataList(this.listwindturbines));
        line.setProject(this.getProject().toData());*/

    }


}
