package com.jeeplus.modules.sg.financial.erpcredit.util;

import com.jeeplus.modules.filing.basicInformation.entity.BasicInformation;
import com.jeeplus.modules.sg.financial.erpcredit.entity.*;
import com.jeeplus.modules.sg.financial.settlement.entity.MaintainData;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFFont;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * 写入表格中模板
 */
public class ExportUtil {

    //导出表（一览表） 写入数据
    public static void getSheetView(Sheet sheet,List<ErpCredit> erpCredits,List<MaintainData> maintainDataList,Workbook workbook){
        if (sheet!=null){
            CellStyle cellStyleFont = getCellStyleFont(workbook);
            CellStyle cellStyle = getCellStyle(workbook);
            Schedule schedule = null;
            XSSFRow row = (XSSFRow) sheet.createRow(6);
            XSSFCell cell = row.getCell(3);
            List<Schedule> scheduleList = ExportUtilCalculate.getScheduleList(erpCredits, maintainDataList);
            for (int i = 0; i <scheduleList.size(); i++) {
                schedule = scheduleList.get(i);
                row=(XSSFRow)sheet.createRow(i+6);
                if (row.getCell(0) == null){
                    cell = row.createCell(0);
                }else {
                    cell = row.getCell(0);
                }
                cell.setCellValue(i+1);
                cell.setCellStyle(cellStyle);
                if (i==scheduleList.size()-1){ cell.setCellStyle(cellStyleFont); }

                if (row.getCell(1) == null){
                    cell = row.createCell(1);
                }else {
                    cell = row.getCell(1);
                }
                cell.setCellValue(schedule.getItemId());
                cell.setCellStyle(cellStyle);
                if (i==scheduleList.size()-1){ cell.setCellStyle(cellStyleFont); }
                if (row.getCell(2)==null){
                    cell =row.createCell(2);
                }else {
                    cell=row.getCell(2);
                }
                cell.setCellValue(schedule.getItemName());
                cell.setCellStyle(cellStyle);
                if (i==scheduleList.size()-1){ cell.setCellStyle(cellStyleFont); }
                if (row.getCell(3)==null){
                    cell=row.createCell(3);
                }else {
                    cell=row.getCell(3);
                }
                cell.setCellValue(schedule.getBudgetBuildProject());
                cell.setCellStyle(cellStyle);
                if (i==scheduleList.size()-1){ cell.setCellStyle(cellStyleFont); }
                if (row.getCell(4)==null){
                    cell=row.createCell(4);
                }else {
                    cell=row.getCell(4);
                }
                cell.setCellValue(schedule.getBudgetInstallProject());
                cell.setCellStyle(cellStyle);
                if (i==scheduleList.size()-1){ cell.setCellStyle(cellStyleFont); }
                if (row.getCell(5)==null){
                    cell=row.createCell(5);
                }else {
                    cell=row.getCell(5);
                }
                cell.setCellValue(schedule.getBudgetEquipmentValue());
                cell.setCellStyle(cellStyle);
                if (i==scheduleList.size()-1){ cell.setCellStyle(cellStyleFont); }
                if (row.getCell(6)==null){
                    cell=row.createCell(6);
                }else {
                    cell=row.getCell(6);
                }
                cell.setCellValue(schedule.getBudgetOtherFee());
                cell.setCellStyle(cellStyle);
                if (i==scheduleList.size()-1){ cell.setCellStyle(cellStyleFont); }
                if (row.getCell(7)==null){
                    cell=row.createCell(7);
                }else {
                    cell=row.getCell(7);
                }
                cell.setCellValue(schedule.getBudgetTotalFee());
                cell.setCellStyle(cellStyle);
                if (i==scheduleList.size()-1){ cell.setCellStyle(cellStyleFont); }
                if (row.getCell(8)==null){
                    cell=row.createCell(8);
                }else {
                    cell=row.getCell(8);
                }
                cell.setCellValue(schedule.getActualBuildProject());
                cell.setCellStyle(cellStyle);
                if (i==scheduleList.size()-1){ cell.setCellStyle(cellStyleFont); }
                if (row.getCell(9)==null){
                    cell=row.createCell(9);
                }else {
                    cell=row.getCell(9);
                }
                String actualIntallProject = schedule.getActualIntallProject();
                String actualEquipmentValue = schedule.getActualEquipmentValue();
                if (null == actualIntallProject || "".equals(actualIntallProject)) {
                    actualIntallProject = "0.0";
                }
                if (null == actualEquipmentValue || "".equals(actualEquipmentValue)) {
                    actualEquipmentValue = "0.0";
                }
                BigDecimal all = new BigDecimal(actualIntallProject);
                BigDecimal mul = new BigDecimal(actualEquipmentValue);
                BigDecimal bigDecimal = all.subtract(mul);
                cell.setCellValue(bigDecimal.toString());
                cell.setCellStyle(cellStyle);
                if (i==scheduleList.size()-1){ cell.setCellStyle(cellStyleFont); }
                if (row.getCell(10)==null){
                    cell=row.createCell(10);
                }else {
                    cell=row.getCell(10);
                }
                cell.setCellValue(schedule.getActualEquipmentValue());
                cell.setCellStyle(cellStyle);
                if (i==scheduleList.size()-1){ cell.setCellStyle(cellStyleFont); }
                if (row.getCell(11)==null){
                    cell=row.createCell(11);
                }else {
                    cell=row.getCell(11);
                }
                cell.setCellValue(schedule.getActualOtherFee());
                cell.setCellStyle(cellStyle);
                if (i==scheduleList.size()-1){ cell.setCellStyle(cellStyleFont); }
                if (row.getCell(12)==null){
                    cell = row.createCell(12);
                }else {
                    cell=row.getCell(12);
                }
                String actualTotalFee = schedule.getActualTotalFee();
                if (null == actualTotalFee || "".equals(actualTotalFee)) {
                    actualTotalFee = "0.0";
                }
                BigDecimal actual = new BigDecimal(actualTotalFee);
                BigDecimal subtract = actual.subtract(mul);
                cell.setCellValue(subtract.toString());
                cell.setCellStyle(cellStyle);
                if (i==scheduleList.size()-1){ cell.setCellStyle(cellStyleFont); }


                if (row.getCell(13)==null){
                    cell = row.createCell(13);
                }else {
                    cell = row.getCell(13);
                }
                String listDeduction = schedule.getListDeduction();
                cell.setCellValue(listDeduction);
                cell.setCellStyle(cellStyle);
                if (i==scheduleList.size()-1){ cell.setCellStyle(cellStyleFont); }

                BigDecimal allDecimal = new BigDecimal("0.0");
                if (null != listDeduction && !"".equals(listDeduction)) {
                    allDecimal = new BigDecimal(listDeduction);
                }
                BigDecimal add = allDecimal.add(subtract);
                if (row.getCell(14)==null){
                    cell = row.createCell(14);
                }else {
                    cell = row.getCell(14);
                }
                cell.setCellValue(add.toString());
                cell.setCellStyle(cellStyle);
                if (i==scheduleList.size()-1){ cell.setCellStyle(cellStyleFont); }



                if (row.getCell(15)==null){
                    cell = row.createCell(15);
                }else {
                    cell=row.getCell(15);
                }
                String addSubtractionLines = schedule.getAddSubtractionLines();
                if (null == addSubtractionLines || "".equals(addSubtractionLines)) {
                    addSubtractionLines = "0.0";
                }
                BigDecimal addSub = new BigDecimal(addSubtractionLines);
                BigDecimal decimal = addSub.subtract(mul);
                cell.setCellValue(decimal.toString());
                cell.setCellStyle(cellStyle);
                if (i==scheduleList.size()-1){ cell.setCellStyle(cellStyleFont); }

                if (row.getCell(16)==null){
                    cell = row.createCell(16);
                }else {
                    cell = row.getCell(16);
                }
                cell.setCellValue(schedule.getAddSubtractionRate());
                cell.setCellStyle(cellStyle);
                if (i==scheduleList.size()-1){ cell.setCellStyle(cellStyleFont); }
            }
        }

    }
    //读取得到其他费用表
   public static void getSheetOtherFee(Sheet sheet,List<ErpCredit> erpCredits,List<MaintainData> maintainDataList){
       if (null!=sheet){
           XSSFRow row = (XSSFRow) sheet.getRow(0);
           XSSFCell cell = row.getCell(3);
           ScheduleOther scheduleOtherAct = ExportUtilCalculate.getScheduleOfOtherExpenses(erpCredits);
           ScheduleOther scheduleOtherBud = ExportUtilCalculate.getScheduleOfOtherExpensesReg(maintainDataList);
           List<String> listAct = new ArrayList<String>();
           List<String> listBud = new ArrayList<String>();
           List<String> listActual = getListSchOther(listAct, scheduleOtherAct);
           List<String> listBudget = getListSchOther(listBud,scheduleOtherBud);
           for (int i = 0; i < listActual.size(); i++) {
               row = (XSSFRow) sheet.getRow((int)i+6);
               cell=row.getCell(3);
               cell.setCellValue((String)listActual.get(i));
           }
           for (int i = 0; i < listBudget.size(); i++) {
               row = (XSSFRow) sheet.getRow((int)i+6);
               cell=row.getCell(2);
               cell.setCellValue((String)listBudget.get(i));
           }
       }
   }
   //移交资产—配电网资产一览表(线路)1
   public static void getSheetLine1(Sheet sheet, List<ErpCredit> erpCredits, XSSFWorkbook workbook){
       if (null!=sheet){
           CellStyle style=getCellStyleFont(workbook);
           CellStyle cellStyle = getCellStyle(workbook);
           XSSFRow row = (XSSFRow) sheet.createRow(4);
           XSSFCell cell = row.getCell(0);
           TransferOfPowerLine transferOfPower1 = null;
           List<TransferOfPowerLine> transferOfPower1s = ExportUtilCalculate.getTransFerPower1(erpCredits);
           for (int i = 0; i < transferOfPower1s.size(); i++) {
               transferOfPower1=transferOfPower1s.get(i);
               row = (XSSFRow) sheet.createRow((int)i+4);
               //线路第一行
               if (row.getCell(0)==null){
                   cell = row.createCell(0);
               }else {
                   cell = row.getCell(0);
               }
               cell.setCellValue(transferOfPower1.getPowerId());//添加项目编号
               cell.setCellStyle(cellStyle);
               if (i == transferOfPower1s.size() - 1){cell.setCellStyle(style); }

               //线路第二行
               if (row.getCell(1)==null){
                   cell = row.createCell(1);
               }else {
                   cell = row.getCell(1);
               }
               cell.setCellValue(transferOfPower1.getPowerName());
               cell.setCellStyle(cellStyle);
               if (i == transferOfPower1s.size() - 1){cell.setCellStyle(style); }
               //添加第3行
               if (row.createCell(2)==null){
                   cell = row.createCell(2);
               }else {
                   cell = row.getCell(2);
               }
               cell.setCellValue("-");
               cell.setCellStyle(cellStyle);
               if (i == transferOfPower1s.size() - 1){cell.setCellStyle(style); }
               //添加第4行
               if (row.createCell(3)==null){
                   cell = row.createCell(3);
               }else {
                   cell = row.getCell(3);
               }
               cell.setCellValue(transferOfPower1.getPowerDepartment());
               cell.setCellStyle(cellStyle);
               if (i == transferOfPower1s.size() - 1){cell.setCellStyle(style); }

               //第5行
               if (row.createCell(4)==null){
                   cell = row.createCell(4);
               }else {
                   cell = row.getCell(4);
               }
               cell.setCellValue(transferOfPower1.getPowerTenKvLineLength());
               cell.setCellStyle(cellStyle);
               if (i == transferOfPower1s.size() - 1){cell.setCellStyle(style); }

               //第6行
               if (row.createCell(5)==null){
                   cell = row.createCell(5);
               }else {
                   cell=row.getCell(5);
               }
               cell.setCellValue(transferOfPower1.getPowerTenKvCableType());
               cell.setCellStyle(cellStyle);
               if (i == transferOfPower1s.size() - 1){cell.setCellStyle(style); }

               //第7行
               if (row.createCell(6)==null){
                   cell = row.createCell(6);
               }else {
                   cell = row.getCell(6);
               }
               cell.setCellValue(transferOfPower1.getPowerBuildFee());
               cell.setCellStyle(cellStyle);
               if (i == transferOfPower1s.size() - 1){cell.setCellStyle(style); }

               //第8行
               if (row.getCell(7)==null){
                   cell = row.createCell(7);
               }else {
                   cell = row.getCell(7);
               }
               cell.setCellValue(transferOfPower1.getPowerInstallFee());
               cell.setCellStyle(cellStyle);
               if (i == transferOfPower1s.size() - 1){cell.setCellStyle(style); }

               //添加第9行
               if (row.getCell(8)==null){
                   cell = row.createCell(8);
               }else {
                   cell = row.getCell(8);
               }
               cell.setCellValue(transferOfPower1.getPowerStandInFee());
               cell.setCellStyle(cellStyle);
               if (i == transferOfPower1s.size() - 1){cell.setCellStyle(style); }
               //添加滴10行
               if (row.getCell(9)==null){
                   cell = row.createCell(9);
               }else {
                   cell = row.getCell(9);
               }
               cell.setCellValue(transferOfPower1.getPowerDeliveredAssets());
               cell.setCellStyle(cellStyle);
               if (i == transferOfPower1s.size() - 1){cell.setCellStyle(style); }

               //添加第11行
               if (row.getCell(10)==null){
                   cell = row.createCell(10);
               }else {
                   cell = row.getCell(10);
               }
               cell.setCellValue(transferOfPower1.getPoweRequipmentFee());
               cell.setCellStyle(cellStyle);
               if (i == transferOfPower1s.size() - 1){cell.setCellStyle(style); }

           }
       }
   }
   //移交资产—配电网资产一览表（设备）
   public static void getSheetEquip(Sheet sheet,List<ErpCredit> erpCredits,List<MaintainData> maintainDataList,Workbook workbook){
      if (sheet!=null){
          CellStyle style=getCellStyleFont(workbook);
          CellStyle cellStyle = getCellStyle(workbook);
          XSSFRow row = (XSSFRow) sheet.createRow(4);
          XSSFCell cell = row.getCell(0);
          TransferOfEquipment transferOfPower2 = null;
          List<TransferOfEquipment> transferOfPower2s = ExportUtilCalculate.getTransferOfPower2(erpCredits,maintainDataList);
          for (int i = 0; i < transferOfPower2s.size(); i++) {
              transferOfPower2=transferOfPower2s.get(i);
              row = (XSSFRow) sheet.createRow((int)i+4);
              //第一行
              if (row.getCell(0)==null){
                  cell = row.createCell(0);
              }else {
                  cell = row.getCell(0);
              }
              cell.setCellValue(transferOfPower2.getPowerId());
              cell.setCellStyle(cellStyle);
              if (i == transferOfPower2s.size() - 1){ cell.setCellStyle(style); }
              //第二行
              if (row.getCell(1)==null){
                  cell = row.createCell(1);
              }else {
                  cell =row.getCell(1);
              }
              cell.setCellValue(transferOfPower2.getPowerName());//配电网资产名称
              cell.setCellStyle(cellStyle);
              if (i == transferOfPower2s.size() - 1){ cell.setCellStyle(style); }
              //第三行
              if (row.getCell(2)==null){
                  cell = row.createCell(2);
              }else {
                  cell = row.getCell(2);
              }
              cell.setCellValue(transferOfPower2.getPowerArea());////线路起止地点或配变所在滴
              cell.setCellStyle(cellStyle);
              if (i == transferOfPower2s.size() - 1){ cell.setCellStyle(style); }

              //第四行
              if (row.getCell(3)==null){
                  cell = row.createCell(3);
              }else {
                  cell = row.getCell(3);
              }
              cell.setCellValue(transferOfPower2.getPowerDepartment());//保管部门
              cell.setCellStyle(cellStyle);
              if (i == transferOfPower2s.size() - 1){ cell.setCellStyle(style); }

              //第五行
              if (row.getCell(4)==null){
                  cell = row.createCell(4);
              }else {
                  cell = row.getCell(4);
              }
              cell.setCellValue(transferOfPower2.getPowerNumber());//配变数量
              cell.setCellStyle(cellStyle);
              if (i == transferOfPower2s.size() - 1){ cell.setCellStyle(style); }
              //第六行
              if (row.getCell(5)==null){
                  cell = row.createCell(5);
              }else {
                  cell = row.getCell(5);
              }
              cell.setCellValue(transferOfPower2.getPowerUnit());//计量单位
              cell.setCellStyle(cellStyle);
              if (i == transferOfPower2s.size() - 1){ cell.setCellStyle(style); }
              //第七行
              if (row.getCell(6)==null){
                  cell = row.createCell(6);
              }else {
                  cell = row.getCell(6);
              }
              cell.setCellValue(transferOfPower2.getPowerCapacity());//配变容量
              cell.setCellStyle(cellStyle);
              if (i == transferOfPower2s.size() - 1){ cell.setCellStyle(style); }
              //第8行
              if (row.getCell(7)==null){
                  cell = row.createCell(7);
              }else {
                  cell = row.getCell(7);
              }
              cell.setCellValue(transferOfPower2.getPowerInstallFee());//安装费
              cell.setCellStyle(cellStyle);
              if (i == transferOfPower2s.size() - 1){ cell.setCellStyle(style); }
              //第9行
              if (row.getCell(8)==null){
                  cell = row.createCell(8);
              }else {
                  cell = row.getCell(8);
              }
              cell.setCellValue(transferOfPower2.getPowerValue());//设备价值
              cell.setCellStyle(cellStyle);
              if (i == transferOfPower2s.size() - 1){ cell.setCellStyle(style); }
              //第10行
              if (row.getCell(9)==null){
                  cell = row.createCell(9);
              }else {
                  cell = row.getCell(9);
              }
              cell.setCellValue(transferOfPower2.getPowerStandInFee());//摊入费用
              cell.setCellStyle(cellStyle);
              if (i == transferOfPower2s.size() - 1){ cell.setCellStyle(style); }
              //第11行
              if (row.getCell(10)==null){
                  cell = row.createCell(10);
              }else {
                  cell = row.getCell(10);
              }
              cell.setCellValue(transferOfPower2.getPowerDeliveredAssets());//交付使用资产价值
              cell.setCellStyle(cellStyle);
              if (i == transferOfPower2s.size() - 1){ cell.setCellStyle(style); }
              //第12行
              if (row.getCell(11) == null){
                  cell = row.createCell(11);
              }else {
                  cell = row.getCell(11);
              }
              cell.setCellValue(transferOfPower2.getPoweRequipmentFee());//其中：附属设备价值
              cell.setCellStyle(cellStyle);
              if (i == transferOfPower2s.size() - 1){ cell.setCellStyle(style); }
          }
      }
   }
   //设备材料清册
    public static void getSheetEquipMaterial(Sheet sheet,List<ErpCredit> erpCredits,Workbook workbook){
        XSSFRow row = (XSSFRow) sheet.createRow(5);
        XSSFCell cell = row.getCell(0);
        CellStyle cellStyle = getCellStyle(workbook);//设备材料清册
        CellStyle cellStyle1 = getCellStyleAlign(workbook);
        MaterialEquipment materialEquipment = null;
        if (null!=sheet){
            List<MaterialEquipment> materialEquipments = ExportUtilCalculate.getSureMateralEquipment(erpCredits);
            for (int i = 0; i < materialEquipments.size(); i++) {
                materialEquipment = materialEquipments.get(i);
                row = (XSSFRow) sheet.createRow((int)i+5);
                //第一行
                if (row.getCell(0)==null){
                    cell = row.createCell(0);
                }else {
                    cell = row.getCell(0);
                }
                cell.setCellValue(i+1);//项目定义编号
                cell.setCellStyle(cellStyle1);//添加边框
                //第二行
                if (row.getCell(1)==null){
                    cell = row.createCell(1);
                }else {
                    cell = row.getCell(1);
                }
                cell.setCellValue(materialEquipment.getMeName());
                cell.setCellStyle(cellStyle);
                //第三行
                if (row.getCell(2)==null){
                    cell = row.createCell(2);
                }else {
                    cell = row.getCell(2);
                }
                cell.setCellValue(materialEquipment.getMeSpecifications());
                cell.setCellStyle(cellStyle);
                //第四行
                if (row.getCell(3)==null){
                    cell = row.createCell(3);
                }else {
                    cell = row.getCell(3);
                }
                cell.setCellValue(materialEquipment.getMeSupplierName());//供应单位制造
                cell.setCellStyle(cellStyle);
                //第五行
                if (row.getCell(4)==null){
                    cell = row.createCell(4);
                }else {
                    cell = row.getCell(4);
                }
                cell.setCellValue(materialEquipment.getMeUnit());////计量单位
                cell.setCellStyle(cellStyle);
                //第六行
                if (row.getCell(5)==null){
                    cell = row.createCell(5);
                }else {
                    cell = row.getCell(5);
                }
                cell.setCellValue(materialEquipment.getMeNumber());////数量
                cell.setCellStyle(cellStyle);
                //第七行
                if (row.getCell(6)==null){
                    cell = row.createCell(6);
                }else {
                    cell = row.getCell(6);
                }
                cell.setCellValue(materialEquipment.getMeUnitPrice());////单价
                cell.setCellStyle(cellStyle);
                if (row.getCell(7)==null){
                    cell = row.createCell(7);
                }else {
                    cell = row.getCell(7);
                }
                cell.setCellValue(materialEquipment.getMeAllPrice());////合计
                cell.setCellStyle(cellStyle);
            }
        }
    }

    //移交资产—配电网资产一览表(线路)2
    public static void getSheetLine2(Sheet sheet,List<ErpCredit> erpCredits,Workbook workbook){
        if (null!=sheet){
            CellStyle style=getCellStyleFont(workbook);
            CellStyle cellStyle = getCellStyle(workbook);
            XSSFRow row = (XSSFRow) sheet.createRow(4);
            XSSFCell cell = row.getCell(0);
            TransferOfPowerLine transferOfPower1 = null;
            List<TransferOfPowerLine> transferOfPower1s = ExportUtilCalculate.getTransFerPower1(erpCredits);
            for (int i = 0; i < transferOfPower1s.size(); i++) {
                transferOfPower1=transferOfPower1s.get(i);
                row = (XSSFRow) sheet.createRow((int)i+4);
                //线路第一行
                if (row.getCell(0)==null){
                    cell = row.createCell(0);
                }else {
                    cell = row.getCell(0);
                }
                cell.setCellValue(transferOfPower1.getPowerId());//添加项目编号
                cell.setCellStyle(cellStyle);
                if (i == transferOfPower1s.size() - 1){ cell.setCellStyle(style); }

                //线路第二行
                if (row.getCell(1)==null){
                    cell = row.createCell(1);
                }else {
                    cell = row.getCell(1);
                }
                cell.setCellValue(transferOfPower1.getPowerName());
                cell.setCellStyle(cellStyle);
                if (i == transferOfPower1s.size() - 1){ cell.setCellStyle(style); }
                //添加第三行
                if (row.getCell(2)==null){
                    cell = row.createCell(2);
                }else {
                    cell = row.getCell(2);
                }
                cell.setCellValue(transferOfPower1.getPowerNumberBars());
                cell.setCellStyle(cellStyle);
                if (i == transferOfPower1s.size() - 1){ cell.setCellStyle(style); }

                //添加第四行
                if (row.createCell(3)==null){
                    cell = row.createCell(3);
                }else {
                    cell = row.getCell(3);
                }
                cell.setCellValue(transferOfPower1.getPowerAssetClass());
                cell.setCellStyle(cellStyle);
                if (i == transferOfPower1s.size() - 1){ cell.setCellStyle(style); }
                //添加第五行
                if (row.createCell(4)==null){
                    cell = row.createCell(4);
                }else {
                    cell = row.getCell(4);
                }
                cell.setCellValue(transferOfPower1.getPowerArea());
                cell.setCellStyle(cellStyle);
                if (i == transferOfPower1s.size() - 1){ cell.setCellStyle(style); }
                //添加第六行
                if (row.createCell(5)==null){
                    cell = row.createCell(5);
                }else {
                    cell = row.getCell(5);
                }
                cell.setCellValue(transferOfPower1.getPowerDepartment());
                cell.setCellStyle(cellStyle);
                if (i == transferOfPower1s.size() - 1){ cell.setCellStyle(style); }
                //第七行
                if (row.createCell(6)==null){
                    cell = row.createCell(6);
                }else {
                    cell = row.getCell(6);
                }
                cell.setCellValue(transferOfPower1.getPowerTenKvLineLength());
                cell.setCellStyle(cellStyle);
                if (i == transferOfPower1s.size() - 1){ cell.setCellStyle(style); }
                //第八行
                if (row.createCell(7)==null){
                    cell = row.createCell(7);
                }else {
                    cell=row.getCell(7);
                }
                cell.setCellValue(transferOfPower1.getPowerTenKvCableType());
                cell.setCellStyle(cellStyle);
                if (i == transferOfPower1s.size() - 1){ cell.setCellStyle(style); }
                //第九行
                if (row.createCell(8)==null){
                    cell = row.createCell(8);
                }else {
                    cell = row.getCell(8);
                }
                cell.setCellValue(transferOfPower1.getPowerBuildFee());
                cell.setCellStyle(cellStyle);
                if (i == transferOfPower1s.size() - 1){ cell.setCellStyle(style); }
                //第10行
                if (row.getCell(9)==null){
                    cell = row.createCell(9);
                }else {
                    cell = row.getCell(9);
                }
                cell.setCellValue(transferOfPower1.getPowerInstallFee());
                cell.setCellStyle(cellStyle);
                if (i == transferOfPower1s.size() - 1){ cell.setCellStyle(style); }
                //添加第11行
                if (row.getCell(10)==null){
                    cell = row.createCell(10);
                }else {
                    cell = row.getCell(10);
                }
                cell.setCellValue(transferOfPower1.getPowerStandInFee());
                cell.setCellStyle(cellStyle);
                if (i == transferOfPower1s.size() - 1){ cell.setCellStyle(style); }
                //添加滴12行
                if (row.getCell(11)==null){
                    cell = row.createCell(11);
                }else {
                    cell = row.getCell(11);
                }
                cell.setCellValue(transferOfPower1.getPowerDeliveredAssets());
                cell.setCellStyle(cellStyle);
                if (i == transferOfPower1s.size() - 1){ cell.setCellStyle(style); }
                //添加第13行
                if (row.getCell(12)==null){
                    cell = row.createCell(12);
                }else {
                    cell = row.getCell(12);
                }
                cell.setCellValue(transferOfPower1.getPoweRequipmentFee());
                cell.setCellStyle(cellStyle);
                if (i == transferOfPower1s.size() - 1){ cell.setCellStyle(style); }
            }
        }
    }
    //移交资产—配电网资产一览表（设备）2-（04-2）
    public static void getSheetEquip2(Sheet sheet,List<ErpCredit> erpCredits,List<MaintainData> maintainDataList,Workbook workbook){
        if (sheet!=null){
            CellStyle style=getCellStyleFont(workbook);
            CellStyle cellStyle = getCellStyle(workbook);
            XSSFRow row = (XSSFRow) sheet.createRow(4);
            XSSFCell cell = row.getCell(0);
            TransferOfEquipment transferOfPower2 = null;
            List<TransferOfEquipment> transferOfPower2s = ExportUtilCalculate.getTransferOfPower2(erpCredits,maintainDataList);
            for (int i = 0; i <transferOfPower2s.size(); i++) {
                transferOfPower2=transferOfPower2s.get(i);
                row = (XSSFRow) sheet.createRow((int)i+4);
                //第1行
                if (row.getCell(0)==null){
                    cell = row.createCell(0);
                }else {
                    cell = row.getCell(0);
                }
                cell.setCellValue(transferOfPower2.getPowerId());
                cell.setCellStyle(cellStyle);
                if (i == transferOfPower2s.size() - 1){ cell.setCellStyle(style); }
                //第2行
                if (row.getCell(1)==null){
                    cell = row.createCell(1);
                }else {
                    cell =row.getCell(1);
                }
                cell.setCellValue(transferOfPower2.getPowerName());//配电网资产名称
                cell.setCellStyle(cellStyle);
                if (i == transferOfPower2s.size() - 1){ cell.setCellStyle(style); }
                   //第3行
                if (row.getCell(2)==null){
                    cell = row.createCell(2);
                }else {
                    cell = row.getCell(2);
                }
                cell.setCellValue(transferOfPower2.getPowerAssetClass());//资产类别
                cell.setCellStyle(cellStyle);
                if (i == transferOfPower2s.size() - 1){ cell.setCellStyle(style); }
                //第4行
                if (row.getCell(3)==null){
                    cell = row.createCell(3);
                }else {
                    cell = row.getCell(3);
                }
                cell.setCellValue(transferOfPower2.getPowerArea());////线路起止地点或配变所在滴
                cell.setCellStyle(cellStyle);
                if (i == transferOfPower2s.size() - 1){ cell.setCellStyle(style); }
                //第5行
                if (row.getCell(4)==null){
                    cell = row.createCell(4);
                }else {
                    cell = row.getCell(4);
                }
                cell.setCellValue(transferOfPower2.getPowerDepartment());//保管部门
                cell.setCellStyle(cellStyle);
                if (i == transferOfPower2s.size() - 1){ cell.setCellStyle(style); }
                //第6行
                if (row.getCell(5)==null){
                    cell = row.createCell(5);
                }else {
                    cell = row.getCell(5);
                }
                cell.setCellValue(transferOfPower2.getPowerNumber());//配变数量
                cell.setCellStyle(cellStyle);
                if (i == transferOfPower2s.size() - 1){ cell.setCellStyle(style); }
                //第7行
                if (row.getCell(6)==null){
                    cell = row.createCell(6);
                }else {
                    cell = row.getCell(6);
                }
                cell.setCellValue(transferOfPower2.getPowerUnit());//计量单位
                cell.setCellStyle(cellStyle);
                if (i == transferOfPower2s.size() - 1){ cell.setCellStyle(style); }
                //第8行
                if (row.getCell(7)==null){
                    cell = row.createCell(7);
                }else {
                    cell = row.getCell(7);
                }
                cell.setCellValue(transferOfPower2.getPowerCapacity());//配变容量
                cell.setCellStyle(cellStyle);
                if (i == transferOfPower2s.size() - 1){ cell.setCellStyle(style); }

                //第9行
                if (row.getCell(8)==null){
                    cell = row.createCell(8);
                }else {
                    cell = row.getCell(8);
                }
                cell.setCellValue(transferOfPower2.getPowerInstallFee());//安装费
                cell.setCellStyle(cellStyle);
                if (i == transferOfPower2s.size() - 1){ cell.setCellStyle(style); }

                //第10行
                if (row.getCell(9)==null){
                    cell = row.createCell(9);
                }else {
                    cell = row.getCell(9);
                }
                cell.setCellValue(transferOfPower2.getPowerValue());//设备价值
                cell.setCellStyle(cellStyle);
                if (i == transferOfPower2s.size() - 1){ cell.setCellStyle(style); }
                //第11行
                if (row.getCell(10)==null){
                    cell = row.createCell(10);
                }else {
                    cell = row.getCell(10);
                }
                cell.setCellValue(transferOfPower2.getPowerStandInFee());//摊入费用
                cell.setCellStyle(cellStyle);
                if (i == transferOfPower2s.size() - 1){ cell.setCellStyle(style); }
                //第12行
                if (row.getCell(11)==null){
                    cell = row.createCell(11);
                }else {
                    cell = row.getCell(11);
                }
                cell.setCellValue(transferOfPower2.getPowerDeliveredAssets());//交付使用资产价值
                cell.setCellStyle(cellStyle);
                if (i == transferOfPower2s.size() - 1){ cell.setCellStyle(style); }
                //第13行
                if (row.getCell(12) == null){
                    cell = row.createCell(12);
                }else {
                    cell = row.getCell(12);
                }
                cell.setCellValue(transferOfPower2.getPoweRequipmentFee());//其中：附属设备价值
                cell.setCellStyle(cellStyle);
                if (i == transferOfPower2s.size() - 1){ cell.setCellStyle(style); }
            }
        }
    }

    public static void getOtherExpenses(Sheet sheet,List<ErpCredit> erpCredits,List<MaintainData> maintainDataList,Workbook workbook){
        if (sheet!=null){
            CellStyle cellStyleFont = getCellStyleFont(workbook);
            CellStyle cellStyle = getCellStyle(workbook);
            OtherExpenses otherExpenses = null;
            XSSFRow row = (XSSFRow) sheet.createRow(5);
            XSSFCell cell = row.getCell(3);
            List<OtherExpenses> otherList = ExportUtilCalculate.getOtherExpenses(erpCredits, maintainDataList);
            for (int i = 0; i <otherList.size(); i++) {
                otherExpenses = otherList.get(i);
                row=(XSSFRow)sheet.createRow(i+5);
                if (row.getCell(0) == null){
                    cell = row.createCell(0);
                }else {
                    cell = row.getCell(0);
                }
                cell.setCellValue(i+1);
                cell.setCellStyle(cellStyle);
                if (i==otherList.size()-1){ cell.setCellStyle(cellStyleFont); }

                if (row.getCell(1) == null){
                    cell = row.createCell(1);
                }else {
                    cell = row.getCell(1);
                }
                cell.setCellValue(otherExpenses.getProjectNumber());
                cell.setCellStyle(cellStyle);
                if (i==otherList.size()-1){ cell.setCellStyle(cellStyleFont); }
                if (row.getCell(2)==null){
                    cell =row.createCell(2);
                }else {
                    cell=row.getCell(2);
                }
                cell.setCellValue("");
                cell.setCellStyle(cellStyle);
                if (i==otherList.size()-1){ cell.setCellStyle(cellStyleFont); }
                if (row.getCell(3)==null){
                    cell=row.createCell(3);
                }else {
                    cell=row.getCell(3);
                }
                cell.setCellValue(otherExpenses.getProjectName());
                cell.setCellStyle(cellStyle);
                if (i==otherList.size()-1){ cell.setCellStyle(cellStyleFont); }
                if (row.getCell(4)==null){
                    cell=row.createCell(4);
                }else {
                    cell=row.getCell(4);
                }
                cell.setCellValue(otherExpenses.getManagementFunds());
                cell.setCellStyle(cellStyle);
                if (i==otherList.size()-1){ cell.setCellStyle(cellStyleFont); }
                if (row.getCell(5)==null){
                    cell=row.createCell(5);
                }else {
                    cell=row.getCell(5);
                }
                cell.setCellValue(otherExpenses.getSupervisionFee());
                cell.setCellStyle(cellStyle);
                if (i==otherList.size()-1){ cell.setCellStyle(cellStyleFont); }
                if (row.getCell(6)==null){
                    cell=row.createCell(6);
                }else {
                    cell=row.getCell(6);
                }
                cell.setCellValue(otherExpenses.getDesignFee());
                cell.setCellStyle(cellStyle);
                if (i==otherList.size()-1){ cell.setCellStyle(cellStyleFont); }
                if (row.getCell(7)==null){
                    cell=row.createCell(7);
                }else {
                    cell=row.getCell(7);
                }
                cell.setCellValue(otherExpenses.getLoanInterest());
                cell.setCellStyle(cellStyle);
                if (i==otherList.size()-1){ cell.setCellStyle(cellStyleFont); }
                if (row.getCell(8)==null){
                    cell=row.createCell(8);
                }else {
                    cell=row.getCell(8);
                }
                cell.setCellValue(otherExpenses.getDamages());
                cell.setCellStyle(cellStyle);
                if (i==otherList.size()-1){ cell.setCellStyle(cellStyleFont); }

                if (row.getCell(9)==null){
                    cell=row.createCell(9);
                }else {
                    cell=row.getCell(9);
                }
                cell.setCellValue(otherExpenses.getTotal());
                cell.setCellStyle(cellStyle);
                if (i==otherList.size()-1){ cell.setCellStyle(cellStyleFont); }

                if (row.getCell(10)==null){
                    cell=row.createCell(10);
                }else {
                    cell=row.getCell(10);
                }
                cell.setCellValue(otherExpenses.getDeduction());
                cell.setCellStyle(cellStyle);
                if (i==otherList.size()-1){ cell.setCellStyle(cellStyleFont); }
                if (row.getCell(11)==null){
                    cell=row.createCell(11);
                }else {
                    cell=row.getCell(11);
                }
                cell.setCellValue(otherExpenses.getIncludingTax());
                cell.setCellStyle(cellStyle);
                if (i==otherList.size()-1){ cell.setCellStyle(cellStyleFont); }
            }
        }

    }

    //概述表
    public static void getSheetOverView(Sheet sheet, List<ErpCredit> erpCredits, List<MaintainData> maintainDataList){
       if (sheet!=null){
           GeneralSituation generalSituation = ExportUtilCalculate.getFeneraSituation(erpCredits,maintainDataList);
           XSSFRow row = (XSSFRow) sheet.getRow(6);
           XSSFCell cell = row.getCell(6);
           cell.setCellValue(generalSituation.getOrganDataNumber());//日期，批文号

           row = (XSSFRow)sheet.getRow(9);
           cell = row.getCell(2);
           cell.setCellValue(generalSituation.getLineLength());
           cell = row.getCell(7);
           cell.setCellValue(generalSituation.getCommencementDate());

           row = (XSSFRow)sheet.getRow(10);
           cell = row.getCell(2);
           cell.setCellValue(generalSituation.getTenKvLength());
           cell = row.getCell(7);
           cell.setCellValue(generalSituation.getCompletionDate());

           row = (XSSFRow)sheet.getRow(11);
           cell=row.getCell(2);
           cell.setCellValue(generalSituation.getFourKvLength());

           row = (XSSFRow)sheet.getRow(12);
           cell=row.getCell(7);
           cell.setCellValue(generalSituation.getInvestmentBudget());

           row = (XSSFRow)sheet.getRow(13);
           cell=row.getCell(7);
           cell.setCellValue(generalSituation.getActualInvestment());//实际投资

           row = (XSSFRow)sheet.getRow(14);
           cell=row.getCell(7);
           cell.setCellValue(generalSituation.getTransferAssets());

           row = (XSSFRow)sheet.getRow(16);
           cell=row.getCell(7);
           cell.setCellValue(generalSituation.getHasItsOwn());
       }
    }
    //资产总表
    public static void getSheetAssetsTotal(Sheet sheet,List<ErpCredit> erpCredits,List<MaintainData> maintainDataList){
       if (sheet!=null){
           XSSFRow row = (XSSFRow) sheet.getRow(0);
           XSSFCell cell = row.getCell(0);
           TheAssetsTotal theAssetsTotal = null;
           List<TheAssetsTotal> theAssetsTotals = ExportUtilCalculate.getTheAssetsTotal(erpCredits,maintainDataList);
           for (int i = 0; i < theAssetsTotals.size(); i++) {
               theAssetsTotal = theAssetsTotals.get(i);
               row = (XSSFRow) sheet.getRow((int)i+5);
               cell = row.getCell(2);
               cell.setCellValue(theAssetsTotal.getBuildProject());
               cell=row.getCell(3);
               cell.setCellValue(theAssetsTotal.getIntallProject());
               cell=row.getCell(4);
               cell.setCellValue(theAssetsTotal.getEquipmentValue());
               cell=row.getCell(5);
               cell.setCellValue(theAssetsTotal.getCostSharing());
               cell=row.getCell(6);
               cell.setCellValue(theAssetsTotal.getDeliveryCostValue());
           }
       }
    }
    //竣工财务供材结算表
    public static void getSheetSettlement(Sheet sheet,List<ErpCredit> erpCredits,List<MaintainData> maintainDataList){
        if (null!=sheet){
            XSSFRow row = (XSSFRow) sheet.getRow(0);
            XSSFCell cell = row.getCell(0);
            MCompletionProject mCompletionProject = ExportUtilCalculate.getMCompletionProject(erpCredits,maintainDataList);
            row = (XSSFRow)sheet.getRow(4);
            cell = row.getCell(5);
            cell.setCellValue(mCompletionProject.getTransferAssets());
            row = (XSSFRow) sheet.getRow(6);
            cell=row.getCell(5);
            cell.setCellValue(mCompletionProject.getFixedAssets());
            row = (XSSFRow) sheet.getRow(11);
            cell=row.getCell(5);
            cell.setCellValue(mCompletionProject.getVatDeduction());
            row = (XSSFRow)sheet.getRow(13);
            cell = row.getCell(5);
            cell.setCellValue(mCompletionProject.getCompleted());
            row = (XSSFRow) sheet.getRow(15);
            cell=row.getCell(2);
            cell.setCellValue(mCompletionProject.getAppropriatedFunds());
        }
    }
    //设置 字体边框
    public static CellStyle getCellStyleFont(Workbook workbook){
        XSSFFont font = (XSSFFont) workbook.createFont();
        font.setFontHeightInPoints((short) 12);//设置字体大小
        font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);//粗体显示
        CellStyle style=workbook.createCellStyle();
        style.setBorderBottom(HSSFCellStyle.BORDER_THIN); //下边框
        style.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左边框
        style.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
        style.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框
        style.setFont(font);
        return style;
    }
    //设置边框
    public static CellStyle getCellStyle(Workbook workbook){
        CellStyle style = workbook.createCellStyle();
        style.setBorderBottom(HSSFCellStyle.BORDER_THIN); //下边框
        style.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左边框
        style.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
        style.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框
        return style;
    }
    //设置边框
    public static CellStyle getCellStyleAlign(Workbook workbook){
        CellStyle style = workbook.createCellStyle();
        style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 居中
        style.setBorderBottom(HSSFCellStyle.BORDER_THIN); //下边框
        style.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左边框
        style.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
        style.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框
        return style;
    }

    public static List<String> getListSchOther(List<String> list,ScheduleOther scheduleOther){
        list.add(scheduleOther.getRequisitionSite());
        list.add(scheduleOther.getCompensationAcquisition());
        list.add(scheduleOther.getCleaningFees());
        list.add(scheduleOther.getStorageFee());
        list.add(scheduleOther.getCompensateFee());
        list.add(scheduleOther.getManagementFee());
        list.add(scheduleOther.getPreparationFee());
        list.add(scheduleOther.getItemManageFee());
        list.add(scheduleOther.getTheTenderFee());
        list.add(scheduleOther.getSupervisionFee());
        list.add(scheduleOther.getTechnicalFee());
        list.add(scheduleOther.getSurveyFee());
        list.add(scheduleOther.getDesignFee());
        list.add(scheduleOther.getDrawingBudgetFee());
        list.add(scheduleOther.getEvaluationFee());
        list.add(scheduleOther.getEconomicFee());
        list.add(scheduleOther.getInspectionFee());
        list.add(scheduleOther.getPreparationFee());
        list.add(scheduleOther.getBasicFee());
        list.add(scheduleOther.getReserveFee());
        list.add(scheduleOther.getTotalFee());
        return list;
    }
}
