package com.jeeplus.modules.sg.managementcenter.reserveManagement.utils;

import com.jeeplus.modules.sg.managementcenter.materialproject.util.ImportUtil;
import com.jeeplus.modules.sg.managementcenter.reserveManagement.entity.ReserveManagement;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Row;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

public class ReserveManagementProUtil {

    /**
     * 获取表格数据
     * @param importUtil
     * @return List<ReserveManagementMapper> 导入表格数据
     */
    public static List<ReserveManagement> getProjectUtil(ImportUtil importUtil) throws ParseException {
        int lastRow = importUtil.getLastDataRowNum();
        List<ReserveManagement> list = new ArrayList<ReserveManagement>();
        ReserveManagement reserveManagement = null;
        for(int i=4; i<=lastRow;i++){
            reserveManagement = new ReserveManagement();
            Row row = importUtil.getRow(i);
            String reserveProjectName = (String) importUtil.getCellValue(row,0);
            //获取项目储备编号
            String projectReserveId = (String) importUtil.getCellValue(row, 9);
            if(StringUtils.isNotBlank(reserveProjectName) ) {
                if(StringUtils.isNotBlank(projectReserveId)){
                    reserveManagement.setProjectNature((String)importUtil.getCellValue(row,1));
                    reserveManagement.setDemandUnit((String)importUtil.getCellValue(row,2));
                    reserveManagement.setDistrict((String)importUtil.getCellValue(row,3));
                    reserveManagement.setProjectGroup((String)importUtil.getCellValue(row,4));
                    reserveManagement.setReserveBatches((String)importUtil.getCellValue(row,5));
                    reserveManagement.setBlockSupply((String)importUtil.getCellValue(row,6));
                    reserveManagement.setGridNumber((String)importUtil.getCellValue(row,7));
                    reserveManagement.setCellNumber((String)importUtil.getCellValue(row,8));
                    reserveManagement.setProjectReserveId((String)importUtil.getCellValue(row,9));
                    reserveManagement.setPowerGridProjectId((String)importUtil.getCellValue(row,10));
                    reserveManagement.setProjectName((String)importUtil.getCellValue(row,11));
                    reserveManagement.setConstructionNecessityAndContent((String)importUtil.getCellValue(row,12));
                    reserveManagement.setSubstationName((String)importUtil.getCellValue(row,13));
                    reserveManagement.setCircuitName((String)importUtil.getCellValue(row,14));
                    reserveManagement.setNetRackProjectDivide((String)importUtil.getCellValue(row,15));
                    reserveManagement.setProjectType((String)importUtil.getCellValue(row,16));
                    String costEstimateStr = importUtil.getCellValue(row,17).toString();
                    if(StringUtils.isNotBlank(costEstimateStr)){
                        reserveManagement.setCostEstimate(costEstimateStr);
                    }
                    reserveManagement.setWhetherWindwardProject((String)importUtil.getCellValue(row,18));
                    reserveManagement.setProjectUrgencyDegree((String)importUtil.getCellValue(row,19));
                    reserveManagement.setImplementIssuedYear((String)importUtil.getCellValue(row,20));
                    reserveManagement.setImplementBatch((String)importUtil.getCellValue(row,21));
                    reserveManagement.setBasicRemarks((String)importUtil.getCellValue(row,22));
                    reserveManagement.setDesignCondition((String)importUtil.getCellValue(row,23));
                    reserveManagement.setWhetherPassReview((String)importUtil.getCellValue(row,24));
                    reserveManagement.setWhetherNeedWiringDiagram((String)importUtil.getCellValue(row,25));
                    reserveManagement.setWhetherFinishMaterials((String)importUtil.getCellValue(row,26));
                    reserveManagement.setWhetherFinishDrawing((String)importUtil.getCellValue(row,27));


                    //项目经理负责部分
                    reserveManagement.setDisclosureToCoordinate((String)importUtil.getCellValue(row,28));
                    reserveManagement.setDisclosureParticipate((String)importUtil.getCellValue(row,29));
                    reserveManagement.setWhetherFinishDisclosure((String)importUtil.getCellValue(row,30));
                    reserveManagement.setProjectManagementPeople((String)importUtil.getCellValue(row,31));
                    reserveManagement.setDesigningInstitutePeople((String)importUtil.getCellValue(row,32));
                    reserveManagement.setIfoPeople((String)importUtil.getCellValue(row,33));
                    reserveManagement.setRegionalCenterPeople((String)importUtil.getCellValue(row,34));
                    reserveManagement.setUninterruptedOperationPeople((String)importUtil.getCellValue(row,35));
                    reserveManagement.setWorkMode((String)importUtil.getCellValue(row,36));
                    String dateStr = importUtil.getCellValue(row,37).toString();
                    if(StringUtils.isNotBlank(dateStr)){
                        reserveManagement.setDisclosureFinishDate(new SimpleDateFormat("yyyy-MM-dd").parse(dateStr));
                    }
                    reserveManagement.setDisclosureRemarks((String)importUtil.getCellValue(row,38));
                    reserveManagement.setProjectDescription((String)importUtil.getCellValue(row,39));
                    reserveManagement.setDoNotPossessProjectDescription((String)importUtil.getCellValue(row,40));
                    reserveManagement.setChangedProgramsExplain((String)importUtil.getCellValue(row,41));
                    reserveManagement.setInitialDifficulty((String)importUtil.getCellValue(row,42));
                    reserveManagement.setCapitalEquipment((String)importUtil.getCellValue(row,43));
                    reserveManagement.setSubstationNewLine((String)importUtil.getCellValue(row,44));
                    reserveManagement.setWhetherImplement((String)importUtil.getCellValue(row,45));
                    reserveManagement.setFieldDescription((String)importUtil.getCellValue(row,46));
                    reserveManagement.setNecessaryOfImplementation((String)importUtil.getCellValue(row,47));
                    reserveManagement.setUnnecessaryDescription((String)importUtil.getCellValue(row,48));
                    reserveManagement.setPrecondition((String)importUtil.getCellValue(row,49));
                    reserveManagement.setConditionsDescribed((String)importUtil.getCellValue(row,50));
                    reserveManagement.setConstructionSchemeProblem((String)importUtil.getCellValue(row,51));
                    reserveManagement.setProblemDescriptionOfConstructionScheme((String)importUtil.getCellValue(row,52));
                    reserveManagement.setExistingSecurityThreat((String)importUtil.getCellValue(row,53));
                    reserveManagement.setSafetyHazardDescription((String)importUtil.getCellValue(row,54));
                    reserveManagement.setCustomizedMaterials((String)importUtil.getCellValue(row,55));
                    reserveManagement.setMaterialDescription((String)importUtil.getCellValue(row,56));
                    reserveManagement.setDismantlingTheOldMaterial((String)importUtil.getCellValue(row,57));
                    reserveManagement.setOperatingType((String)importUtil.getCellValue(row,58));
                    reserveManagement.setProblemDescription((String)importUtil.getCellValue(row,59));
                    reserveManagement.setCivilWork((String)importUtil.getCellValue(row,60));
                    reserveManagement.setVerticalRodWorkload((String)importUtil.getCellValue(row,61));
                    reserveManagement.setTotalWorkloadDescription((String)importUtil.getCellValue(row,62));
                    reserveManagement.setRegionalCenter((String)importUtil.getCellValue(row,63));
                    reserveManagement.setPowerSupplyArea((String)importUtil.getCellValue(row,64));
                    reserveManagement.setZhengLocation((String)importUtil.getCellValue(row,65));
                    reserveManagement.setZhengType((String)importUtil.getCellValue(row,66));
                    reserveManagement.setZhengObject((String)importUtil.getCellValue(row,67));
                    reserveManagement.setZhengDescribe((String)importUtil.getCellValue(row,68));
                    reserveManagement.setProjectApproval((String)importUtil.getCellValue(row,69));
                    reserveManagement.setCourseEvaluationProcedures((String)importUtil.getCellValue(row,70));
                    reserveManagement.setZhengDifficultyWarn((String)importUtil.getCellValue(row,71));

                    //对该数据进行数据处理
                    disposeData(reserveManagement);
                    //判断集合中是否含有相同的 projectReserveId 数据 如果存在 则不进行添加数据
                    if(!list.contains(reserveManagement)){
                        list.add(reserveManagement);
                    }
                }
            }
        }
        return list;
    }


    /**
     * 批量添加数据处理
     * @param reserveManagement
     */
    private static void disposeData (ReserveManagement reserveManagement){
        reserveManagement.setWhetherWindwardProject(ReserveManagementUtil.boolResultByInt(reserveManagement.getWhetherWindwardProject()));
        reserveManagement.setProjectUrgencyDegree(ReserveManagementUtil.boolResultByDegree(reserveManagement.getProjectUrgencyDegree()));
        reserveManagement.setDesignCondition(ReserveManagementUtil.boolResultByCondition(reserveManagement.getDesignCondition()));
        reserveManagement.setWhetherPassReview(ReserveManagementUtil.boolResultByReview(reserveManagement.getWhetherPassReview()));
        reserveManagement.setWhetherNeedWiringDiagram(ReserveManagementUtil.boolResultByInt(reserveManagement.getWhetherNeedWiringDiagram()));
        reserveManagement.setWhetherFinishMaterials(ReserveManagementUtil.boolResultByInt(reserveManagement.getWhetherFinishMaterials()));
        reserveManagement.setWhetherFinishDrawing(ReserveManagementUtil.boolResultByInt(reserveManagement.getWhetherFinishDrawing()));

        //项目经理负责部分
        reserveManagement.setWhetherFinishDisclosure(ReserveManagementUtil.boolResultByInt(reserveManagement.getWhetherFinishDisclosure()));
        reserveManagement.setCapitalEquipment(ReserveManagementUtil.boolResultByInt(reserveManagement.getCapitalEquipment()));
        reserveManagement.setSubstationNewLine(ReserveManagementUtil.boolResultByInt(reserveManagement.getSubstationNewLine()));
        reserveManagement.setWhetherImplement(ReserveManagementUtil.boolResultByInt(reserveManagement.getWhetherImplement()));
        reserveManagement.setNecessaryOfImplementation(ReserveManagementUtil.boolResultByInt(reserveManagement.getNecessaryOfImplementation()));
        reserveManagement.setPrecondition(ReserveManagementUtil.boolResultByInt(reserveManagement.getPrecondition()));
        reserveManagement.setConstructionSchemeProblem(ReserveManagementUtil.boolResultByInt(reserveManagement.getConstructionSchemeProblem()));
        reserveManagement.setExistingSecurityThreat(ReserveManagementUtil.boolResultByInt(reserveManagement.getExistingSecurityThreat()));
        reserveManagement.setCustomizedMaterials(ReserveManagementUtil.boolResultByInt(reserveManagement.getCustomizedMaterials()));
        reserveManagement.setDismantlingTheOldMaterial(ReserveManagementUtil.boolResultByInt(reserveManagement.getDismantlingTheOldMaterial()));
        reserveManagement.setCivilWork(ReserveManagementUtil.boolResultByInt(reserveManagement.getCivilWork()));
        reserveManagement.setVerticalRodWorkload(ReserveManagementUtil.boolResultByInt(reserveManagement.getVerticalRodWorkload()));
        reserveManagement.setProjectApproval(ReserveManagementUtil.boolResultByInt(reserveManagement.getProjectApproval()));
        reserveManagement.setCourseEvaluationProcedures(ReserveManagementUtil.boolResultByInt(reserveManagement.getCourseEvaluationProcedures()));
    }
}
