package com.njcn.advance.pojo.carrycapacity.excel;

import cn.afterturn.easypoi.excel.annotation.Excel;
import com.njcn.influx.pojo.bo.CarryCapcityData;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 类的介绍：
 *
 * @author xuyang
 * @version 1.0.0
 * @createTime 2022/5/12 9:13
 */
@Data
public class CarryCapcityDataVEexcel {

    @Excel(name = "时间",width = 30)
    private Instant time;

    @Excel(name = "监测点id",width = 30)
    private String lineId;

    @Excel(name = "数据类型(CP95)",width = 30)
    private String valueType;


    @Excel(name = "数据(A项电压)",width = 30)
    private Double value_a;
    @Excel(name = "数据(B项电压)",width = 30)
    private Double value_b;
    @Excel(name = "数据(C项电压)",width = 30)
    private Double value_c;

    public static List<CarryCapcityData> excelToPO(CarryCapcityDataVEexcel carryCapcityDataVEexcel) {
        List<CarryCapcityData> data = new ArrayList<>();
        if (carryCapcityDataVEexcel == null) {
            return null;
        }
        List<String> phaseList = Stream.of("A", "B", "C").collect(Collectors.toList());
        for (String phase : phaseList) {
            CarryCapcityData carryCapcityData = new CarryCapcityData();
            BeanUtils.copyProperties(carryCapcityDataVEexcel,carryCapcityData);
            carryCapcityData.setPhaseType(phase);
            carryCapcityData.setTime(carryCapcityDataVEexcel.getTime());

            if (phase.equals("A")) {
                carryCapcityData.setValue(carryCapcityDataVEexcel.getValue_a());
            } else if (phase.equals("B")) {
                carryCapcityData.setValue(carryCapcityDataVEexcel.getValue_b());
            }else if (phase.equals("C")){
                carryCapcityData.setValue(carryCapcityDataVEexcel.getValue_c());
            }
            data.add(carryCapcityData);

        }
        return data;
    }
}
