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

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

@Data
@NoArgsConstructor
@ToString
@EqualsAndHashCode()
@Entity
@Table(name = "windpowerstation")
public class GyeePowerStationEntity implements ToData<GyeePowerStation> {
    /**
     * 主键ID
     */
    @Id
    @Column(name = "id")
    private String id;

    /**
     * 场站编码
     */
    @Column(name = "code")
    private String code;

    /**
     * 场站名称
     */
    @Column(name = "name")
    private String name;

    /**
     * 场站地址
     */
    @Column(name = "address")
    private String address;

    /**
     * 电话
     */
    @Column(name = "telephone")
    private String telephone;

    /**
     * 装机容量
     */
    @Column(name = "capacity")
    private double capacity;

    /**
     * 容量单位
     */
    @Column(name = "capacityunit")
    private String capacityUnit;

    /**
     * 装机数量
     */
    @Column(name = "quantity")
    private int quantity;

    /**
     * 简称
     */
    @Column(name = "aname")
    private String aName;

    /**
     * 经度
     */
    @Column(name = "longitude")
    private double longitude;

    /**
     * 纬度
     */
    @Column(name = "latitude")
    private double latitude;

    @Column(name = "photo")
    private String photo;
    /**
     * 公司编码
     */
    @Column(name = "companyid")
    private String companyId;

    /**
     * 系统厂家
     */
    @Column(name = "systemmanufact")
    private String systemManuFact;

    /**
     * 场长
     */
    @Column(name = "headfarm")
    private String headFarm;

    /**
     * 场长电话
     */
    @Column(name = "headfarmphone")
    private String headFarmPhone;

    /**
     * 机型
     */
    @Column(name = "model")
    private String model;

    /**
     * 编号
     */
    @Column(name = "ordernum")
    private int orderNum;

    /**
     * 海拔高度
     */
    @Column(name = "altitude")
    private double altitude;


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

    public GyeePowerStationEntity(GyeePowerStation station) {
        this.id=station.getId();
        this.code = station.getCode();
        this.name = station.getName();
        this.address = station.getAddress();
        this.telephone = station.getTelephone();
        this.capacity = station.getCapacity();
        this.capacityUnit = station.getCapacityUnit();
        this.quantity = station.getQuantity();
        this.aName = station.getAname();
        this.longitude = station.getLongitude();
        this.latitude = station.getLatitude();
        this.companyId = station.getCompanyId();
        this.systemManuFact = station.getSystemManuFact();
        this.headFarm = station.getHeadFarm();
        this.headFarmPhone = station.getHeadFarmPhone();
        this.model = station.getModel();
        this.orderNum = station.getOrderNum();
        this.altitude = station.getAltitude();
/*        List<ProjectEntity> lproject=new ArrayList<>();
        for(Project project:station.getListproject()) {
            ProjectEntity lineEntity=new ProjectEntity(project);
            lproject.add(lineEntity);
        }
        this.listprojetentity=lproject;*/
    }

    @Override
    public GyeePowerStation toData() {
        if(this!=null) {
            GyeePowerStation station = new GyeePowerStation();
            station.setId(this.id);
            station.setCode(this.code);
            station.setName(this.name);
            station.setAddress(this.address);
            station.setTelephone(this.telephone);
            station.setCapacity(this.capacity);
            station.setCapacityUnit(this.capacityUnit);
            station.setQuantity(this.quantity);
            station.setAname(this.aName);
            station.setLongitude(this.longitude);
            station.setLatitude(this.latitude);
            station.setCompanyId(this.companyId);
            station.setSystemManuFact(this.systemManuFact);
            station.setHeadFarm(this.headFarm);
            station.setHeadFarmPhone(this.headFarmPhone);
            station.setModel(this.model);
            station.setOrderNum(this.orderNum);
            station.setAltitude(this.altitude);
            /*station.setListproject(DataUtil.convertDataList(this.listprojetentity));*/
            return station;
        }else{
            return null;
        }
    }
}
