package com.jeeplus.modules.sg.util;

import com.jeeplus.common.utils.excel.ImportExcel;
import com.jeeplus.modules.sg.entity.JkxlData;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class JkxlExcel {
    public static List<JkxlData> getData(String  file) throws IOException, InvalidFormatException {

        ImportExcel importExcel = new ImportExcel(file,1,"分部分项工程量清单计价表");
        List<JkxlData> list = new ArrayList<>();
        int lastRow = importExcel.getLastDataRowNum();
        int[] row = new int[6];
        double totalFee = 0.00;
        for(int i=0;i<lastRow;i++){
            String type =  importExcel.getValue(i+1,2);
            if(type.equals(BashInfo.PROJECTNAME)){
                totalFee = importExcel.getDouble(i+1,12);
            }
            if(type.equals("1 基础工程")){
                row[0] = i+1;
                continue;
            }
            if(type.equals("2 杆塔工程")){
                row[1] = i+1;
                continue;
            }
            if(type.equals("3 接地工程")){
                row[2] = i+1;
                continue;
            }
            if(type.equals("4 架线工程")){
                row[3] = i+1;
                continue;
            }
            if(type.equals("5 附件安装工程")){
                row[4] = i+1;
                continue;
            }
            if(type.equals("6 辅助工程")){
                row[5] = i+1;
                break;
            }
        }
        for(int i=0;i<6;i++){
            JkxlData jkxlData = new JkxlData();
            Double originalRgCost = importExcel.getDouble(row[i],13);
//            Double rgCost = originalRgCost/(1+rate[0]);
            Double originalCbrCost = importExcel.getDouble(row[i],14);
//            Double cbrCost = originalCbrCost/(1+rate[1]);
            Double originalFbrCost = importExcel.getDouble(row[i],15);
//            Double fbrCost = originalFbrCost/(1+0.17);
            Double originalJxrCost = importExcel.getDouble(row[i],17);
//            Double jxCost = originalJxrCost/(1+rate[2]);
            jkxlData.setOriginalTotalCost(importExcel.getDouble(row[i],12));
            jkxlData.setOriginalRgCost(originalRgCost);
//            jkxlData.setRgCost(rgCost);
            jkxlData.setOriginalCbrCost(originalCbrCost);
//            jkxlData.setCbrCost(cbrCost);
            jkxlData.setOriginalFbrCost(originalFbrCost);
//            jkxlData.setFbrCost(fbrCost);
            jkxlData.setOriginalJxCost(originalJxrCost);
//            jkxlData.setJxCost(jxCost);
            list.add(jkxlData);
        }
        return list;
    }


//    public  static  double get(String file) throws IOException, InvalidFormatException {
//        ImportExcel importExcel = new ImportExcel(file,1,1);
//        int lastRow = importExcel.getLastDataRowNum();
//        double lsRate = 0.00;
//        double aqRate = 0.00;
//        double totalRate = 0.00;
//        for(int i=2;i<lastRow;i++){
//            String type = importExcel.getValue(i+1,1);
//            if(type.equals(BashInfo.CS_LS)){
//                lsRate = importExcel.getDouble(i+1,3);
//            }
//            if(type.equals(BashInfo.CS_AQWM)){
//                aqRate = importExcel.getDouble(i+1,3);
//            }
//            totalRate += importExcel.getDouble(i+1,3);
//        }
//        double[] rate = new double[2];
//        rate[0] = (lsRate+aqRate)/100;
//        rate[1] = (totalRate-lsRate-aqRate)/100;
//        return  rate;
//        double totalRate = 0.00;
//        double wxzyRate = 0.00;
//        for (int i = 2; i < lastRow; i++) {
//            String type = importExcel.getValue(i + 1, 1);
//            if (type.equals(BashInfo.GF_WXZY)) {
//                wxzyRate = importExcel.getDouble(i + 1, 3);
//            }
//            if (!importExcel.getValue(i + 1, 2).equals("")) {
//                totalRate += importExcel.getDouble(i + 1, 3);
//            }
//        }
//        double[] rate = new double[2];
//        rate[0] = wxzyRate / 100;
//        rate[1] = (totalRate - wxzyRate) / 100;
//        return rate;
//        double cdFree = 0.00;
//        double zbFree = 0.00;
//        double totalFree = 0.00;
//        for(int i=2;i<lastRow;i++){
//            String type = importExcel.getValue(i+1,1);
//            String type1 = importExcel.getValue(i+1,0);
//            if(type.equals(BashInfo.QT_SGCDZY)){
//                cdFree = importExcel.getDouble(i+1,2);
//            }
//            if(type.equals(BashInfo.QT_ZBDL)){
//                zbFree = importExcel.getDouble(i+1,2);
//            }
////      totalFree += importExcel.getDouble(i+1,2);
//            if(type1.equals(BashInfo.QT_HJ)){
//                totalFree = importExcel.getDouble(i+1,2);
//            }
//        }
//        double[] rate = new double[3];
//        rate[0] = cdFree;
//        rate[1] = zbFree;
//        rate[2] = totalFree-cdFree-zbFree;
//        return  rate;
//        double bzFree = 0.00;
//        double kcFree = 0.00;
//        for(int i=0;i<lastRow;i++){
//            String type = importExcel.getValue(i+1,1);
//            if(type.equals(BashInfo.BZZSSL)){
//                bzFree = importExcel.getDouble(i+1,2);
//                continue;
//            }
//            if(type.equals(BashInfo.KJJGCC)){
//                kcFree = importExcel.getDouble(i+1,2);
//                break;
//            }
//        }
//
//        return  bzFree+kcFree;
//    }



}
