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

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

import javax.persistence.*;
import java.util.Date;


@Data
@NoArgsConstructor
@ToString
@EqualsAndHashCode()
@Entity
@Table(name = ModelConstants.PROJECT_)
public class ProjectEntity implements ToData<Project> {
    /** 主键ID */
    @Id
    @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.STATION_ID)
    private String stationId;
    /** 装机容量*/
    @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.MODEL_)
    private String model;
    /*投产日期*/
    @Column(name = ModelConstants.COMMISSION_DATE)
    private Date commissionDate;
    /*主控电话*/
    @Column(name = ModelConstants.MASTER_PHONE)
    private String masterPhone;
    /*执长*/
    @Column(name = ModelConstants.SHIFT_FOREMAN)
    private String shiftForman;
    /*执长电话*/
    @Column(name = ModelConstants.SHIFT_FOREMAN_PHONE)
    private String shiftFormanPhone;
    /*顺序*/
    @Column(name = ModelConstants.ORDER_NUM)
    private Integer orderNum;

/*    @OneToMany(mappedBy=ModelConstants.ID_,cascade = {CascadeType.MERGE,CascadeType.REFRESH},fetch=FetchType.EAGER)
    private List<LineEntity> listlines;

    @ManyToOne(cascade = {CascadeType.MERGE,CascadeType.REFRESH},fetch=FetchType.EAGER)
    @JoinColumn(name=ModelConstants.STATION_ID, referencedColumnName=ModelConstants.ID_,insertable=false, updatable=false)
    private PowerStationEntity powerStationEntity;*/

    public ProjectEntity(Project project) {
        this.id = project.getId();
        this.code = project.getCode();
        this.name = project.getName();
        this.aname = project.getAname();
        this.stationId = project.getStationId();
        this.capacity = project.getCapacity();
        this.capacityUnit = project.getCapacityUnit();
        this.quantity = project.getQuantity();
        this.model = project.getModel();
        this.commissionDate=project.getCommissionDate();
        this.masterPhone=project.getMasterPhone();
        this.shiftFormanPhone=project.getShiftForemanPhone();
        this.shiftForman=project.getShiftForeman();
        this.orderNum=project.getOrderNum();
/*        List<LineEntity> lline=new ArrayList<>();
        for(Line line:project.getListline()) {
             LineEntity lineEntity=new LineEntity(line);
             lline.add(lineEntity);
        }
        this.listlines=lline;
        this.powerStationEntity=new PowerStationEntity(project.getPowerStation());*/
    }

    @Override
    public Project toData() {
        if(this!=null) {
            Project project = new Project();
            project.setId(this.id);
            project.setCode(this.code);
            project.setName(this.name);
            project.setAname(this.aname);
            project.setStationId(this.stationId);
            project.setCapacity(this.capacity);
            project.setCapacityUnit(this.getCapacityUnit());
            project.setQuantity(this.getQuantity());
            project.setModel(this.getModel());
            project.setCommissionDate(this.commissionDate);
            project.setMasterPhone(this.masterPhone);
            project.setShiftForeman(this.shiftFormanPhone);
            project.setShiftForemanPhone(this.shiftFormanPhone);
            project.setOrderNum(this.orderNum);
/*        project.setListline(DataUtil.convertDataList(this.getListlines()));
        project.setPowerStation(this.powerStationEntity.toData());*/
            return project;
        }else{
            return null;
        }
    }
}
