package com.jeeplus.modules.sg.managementcenter.constructionProject.util;

import com.jeeplus.common.utils.excel.ImportExcel;
import com.jeeplus.modules.sg.managementcenter.constructionProject.entity.ConstructionProject;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Row;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public  class ImportProUtil {
    /**
     * 获取表格数据
     * @param importUtil
     * @return List<MaterialProjectMapper> 导入表格数据
     */
    public static List<ConstructionProject> getProjectUtil(ImportUtil importUtil)  {
        int lastRow = importUtil.getLastDataRowNum();
        List<ConstructionProject> list = new ArrayList<ConstructionProject>();
        ConstructionProject constructionProject = null;
        String projectName="";
        for(int i=2; i<=lastRow;i++){
            constructionProject = new ConstructionProject();
            Row row = importUtil.getRow(i);
            projectName = (String) importUtil.getCellValue(row,8);
            if(StringUtils.isNotBlank(projectName)) {
                constructionProject.setProjectName(projectName);
                constructionProject.setCityCompany((String)importUtil.getCellValue(row,1));//  市公司
                constructionProject.setCountyCompany((String)importUtil.getCellValue(row,2));//  县公司
                constructionProject.setProjectNature((String)importUtil.getCellValue(row,3));//  项目性质
                constructionProject.setPowerSupplyArea((String)importUtil.getCellValue(row,4));//  供电区域
                constructionProject.setGridNumber((String)importUtil.getCellValue(row,5));//  网格编号
                constructionProject.setCellNumber((String)importUtil.getCellValue(row,6));//  单元格编号
                constructionProject.setReserveNumber((String)importUtil.getCellValue(row,7));//  项目储备编号
                constructionProject.setProjectNumber((String)importUtil.getCellValue(row,9));//  项目定义号
                constructionProject.setSubstationName((String)importUtil.getCellValue(row,10));//  变电站名称
                constructionProject.setLineName((String)importUtil.getCellValue(row,11));//  线路名称
                constructionProject.setProjectType((String)importUtil.getCellValue(row,12));//  项目类型
                constructionProject.setInstructions((String)importUtil.getCellValue(row,13));//  说明
                constructionProject.setWorkAreaNote((String)importUtil.getCellValue(row,14));//  工区备注
//                constructionProject.setContructiveContent((String)importUtil.getCellValue(row,15));//  建设必要性内容
//                constructionProject.setCostEstimate(ImportProUtil.getDouble(importUtil,row,16));//  费用估算
//                constructionProject.setWhetherGraceProject((String)importUtil.getCellValue(row,17));///  是否迎风度夏项目
//                constructionProject.setProjectNote((String)importUtil.getCellValue(row,18));//  项目备注
//                constructionProject.setConstructionUnit((String)importUtil.getCellValue(row,19));//  施工单位
                constructionProject.setProjectStatus("0");
                list.add(constructionProject);
            }
        }
        return list;
    }
    //验证表格数据是否正确
    public static Boolean getMaterialProjectFlag(ImportUtil importUtil){
        Boolean flag = false;
        Row row = importUtil.getRow(0);
        String index =  (String)importUtil.getCellValue(row,0);
        String two = (String)importUtil.getCellValue(row,1);
        if (!index.contains("储备")){
            flag = true;
        }
        if (!two.contains("项目")){
            flag = true;
        }
        return flag;
    }
    /**
     *获取excel double类型的值
     */
    private static double getDouble(ImportUtil importUtil, Row row, int col){
        double d = 0.00;
        Object o = importUtil.getCellValue(row,col);
        if(!o.equals("")){
            d = Double.parseDouble(o.toString());
        }
        return d;
    }
}
