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

import com.jeeplus.common.utils.SpringContextHolder;
import com.jeeplus.common.utils.excel.ImportExcel;
import com.jeeplus.modules.sg.audit.information.service.InformationService;
import com.jeeplus.modules.sg.managementcenter.project.entity.*;
import com.jeeplus.modules.sg.managementcenter.project.mapper.ProjectMapper;
import com.jeeplus.modules.sg.managementcenter.project.service.ProjectService;
import groovy.util.IFileNameFinder;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ProjectImportUtil {
    private static ProjectMapper projectMapper = SpringContextHolder.getBean(ProjectMapper.class);
    public static String[] PRO_NAT = {"资本", "成本"};
    public static String[] DEM_UNIT = {"经研所", "新区", "丹徒", "城区"};
    public static String[] OPE_UNIT = {"新区", "丹徒", "城区"};
    public static String[] PRO_TYPE = {"配变改造", "配变新增", "电缆项目", "配变新增", "杆线项目", "混合项目", "纯自动化", "纯土建", "井盖维修", "环网柜更换", "箱变更换", "其他特殊类"};
    public static String[] DIS_TYPE = {"项目经理组织交底", "施工单位自行交底"};
    public static String[] ASS_UNIT = {"镇江大照电力建设有限公司", "镇江市金龙电业发展有限公司"};
    public static String[] CON_UNIT = {"配电工区", "工程公司", "新区供电", "振农公司"};

    /**
     * 前期基本信息数据验证方法
     */
    public static Map<String, Object> basicValidation(ImportExcel ei, int lastDataRowNum) {
        HashMap<String, Object> hashMap = new HashMap<String, Object>();
        List<Project> afterValidation = new ArrayList<>();
        Project project = null;
        String str = "";
        String flagStr = "";
        Boolean flag = false;
        Boolean proNa = false;
        //获取所有的已有项目信息-比对，项目名称项目的数据进行数据比对
        List<Project> compareList = new ArrayList<>();
        List<Project> noCompareList = new ArrayList<>();
        List<String> strings = projectMapper.allProjectName();
        for (String a : strings) {
            for (int i = 6; i < lastDataRowNum; i++) {
                project = new Project();
                Row row = ei.getRow(i);
                //获取表格项目名称
                Object reserveProjectName = ei.getCellValue(row, 1);
                if (reserveProjectName != null && reserveProjectName != "" && a.equals(reserveProjectName)) {
                    //查询项目前期基本信息表中是否有该项目信息，如果有获取之前数据，修改部分信息
                    Project proByName = projectMapper.findProByName((String) reserveProjectName);
                    project.setBasicInformation(new BasicInformation());
                    if (proByName != null) {
                        Boolean aBoolean = checkProcess((String) reserveProjectName);
                        if (!aBoolean) {
                            flagStr += proByName.getBasicInformation().getReserveProjectName() + "项目流程运行中，不能更改信息\n";
                            continue;
                        }
                        project.getBasicInformation().setReserveProjectName(proByName.getBasicInformation().getReserveProjectName());
                        project.getBasicInformation().setPowerSupplyArea((String) ei.getCellValue(row, 9));
                        project.getBasicInformation().setGridNumber((String) ei.getCellValue(row, 10));
                        project.getBasicInformation().setCellNumber((String) ei.getCellValue(row, 11));
                        project.getBasicInformation().setProjectReserveNo((String) ei.getCellValue(row, 12));
                        project.getBasicInformation().setGridProjectNo((String) ei.getCellValue(row, 13));
                        project.getBasicInformation().setNecessityContent((String) ei.getCellValue(row, 15));
                        project.getBasicInformation().setSubStationName((String) ei.getCellValue(row, 16));
                        project.getBasicInformation().setLineName((String) ei.getCellValue(row, 17));
                        project.getBasicInformation().setWhetherSummer((String) ei.getCellValue(row, 19));
                        project.getBasicInformation().setBasicDescription((String) ei.getCellValue(row, 20));
                        project.getBasicInformation().setWorkAreaRemarks((String) ei.getCellValue(row, 21));
                        noCompareList.add(project);
                    } else {
                        project.getBasicInformation().setReserveProjectName((String) ei.getCellValue(row, 1));
                        project.getBasicInformation().setMunicipalCompany((String) ei.getCellValue(row, 4));
                        project.getBasicInformation().setCountyCompany((String) ei.getCellValue(row, 5));
                        project.getBasicInformation().setProjectNature((String) ei.getCellValue(row, 6));
                        project.getBasicInformation().setDemandUnit((String) ei.getCellValue(row, 7));
                        project.getBasicInformation().setOperationUnit((String) ei.getCellValue(row, 8));
                        project.getBasicInformation().setPowerSupplyArea((String) ei.getCellValue(row, 9));
                        project.getBasicInformation().setGridNumber((String) ei.getCellValue(row, 10));
                        project.getBasicInformation().setCellNumber((String) ei.getCellValue(row, 11));
                        project.getBasicInformation().setProjectReserveNo((String) ei.getCellValue(row, 12));
                        project.getBasicInformation().setGridProjectNo((String) ei.getCellValue(row, 13));
                        project.getBasicInformation().setErpNo((String) ei.getCellValue(row, 14));
                        project.getBasicInformation().setNecessityContent((String) ei.getCellValue(row, 15));
                        project.getBasicInformation().setSubStationName((String) ei.getCellValue(row, 16));
                        project.getBasicInformation().setLineName((String) ei.getCellValue(row, 17));
                        project.getBasicInformation().setProjectType((String) ei.getCellValue(row, 18));
                        project.getBasicInformation().setWhetherSummer((String) ei.getCellValue(row, 19));
                        project.getBasicInformation().setBasicDescription((String) ei.getCellValue(row, 20));
                        project.getBasicInformation().setWorkAreaRemarks((String) ei.getCellValue(row, 21));
                        compareList.add(project);
                    }
                }
            }
        }
        //得到比对后list，进行数据验证，成功存入list返回，失败，返回
        for (Project p : compareList) {
            proNa = false;
            str = "";
            String reserveProjectName = p.getBasicInformation().getReserveProjectName();
            String municipalCompany = p.getBasicInformation().getMunicipalCompany();
            String countyCompany = p.getBasicInformation().getCountyCompany();
            String projectNature = p.getBasicInformation().getProjectNature();
            String demandUnit = p.getBasicInformation().getDemandUnit();
            String operationUnit = p.getBasicInformation().getOperationUnit();
            String erpNo = p.getBasicInformation().getErpNo();
            String subStationName = p.getBasicInformation().getSubStationName();
            String lineName = p.getBasicInformation().getLineName();
            String projectType = p.getBasicInformation().getProjectType();
            String whetherSummer = p.getBasicInformation().getWhetherSummer();
            if (isaBoolean(reserveProjectName)) {
                proNa = true;
                str += "储备项目名称不能为空;";
            }
            if (isaBoolean(municipalCompany)) {
                str += "市公司不能为空;";
                proNa = true;
            }
            if (isaBoolean(countyCompany)) {
                proNa = true;
                str += "县公司不能为空;";
            }
            if (isaBoolean(projectNature)) {
                proNa = true;
                str += "项目性质不能为空;";
            } else {
                flag = checkFlag(projectNature, PRO_NAT);
                if (flag) {
                    proNa = true;
                    str += "项目性质填写有误";
                }
            }
            if (isaBoolean(demandUnit)) {
                proNa = true;
                str += "需求单位不能为空;";
            } else {
                flag = checkFlag(demandUnit, DEM_UNIT);
                if (flag) {
                    proNa = true;
                    str += "需求单位填写有误";
                }
            }
            if (isaBoolean(operationUnit)) {
                proNa = true;
                str += "运维单位不能为空;";
            } else {
                flag = checkFlag(operationUnit, OPE_UNIT);
                if (flag) {
                    proNa = true;
                    str += "运维单位填写有误";
                }
            }
            if (isaBoolean(erpNo)) {
                proNa = true;
                str += "ERP编号不能为空;";
            }

            if (isaBoolean(subStationName)) {
                proNa = true;
                str += "变电站名称不能为空;";
            }
            if (isaBoolean(lineName)) {
                proNa = true;
                str += "线路名称不能为空;";
            }
            if (isaBoolean(projectType)) {
                proNa = true;
                str += "项目类型不能为空;";
            } else {
                flag = checkFlag(projectType, PRO_TYPE);
                if (flag) {
                    proNa = true;
                    str += "项目类型填写有误";
                }
            }
            if (isaBoolean(whetherSummer)) {
                proNa = true;
                str += "是否迎峰度夏项目不能为空;";
            }
            if (proNa) {
                flagStr += p.getBasicInformation().getReserveProjectName() + str + "\n";
            } else {
                afterValidation.add(p);
            }
        }
        hashMap.put("errorMsg", flagStr);
        hashMap.put("afterValidation", afterValidation);
        hashMap.put("noCompareList", noCompareList);
        return hashMap;
    }

    /**
     * 施工任务分配信息数据验证方法
     */
    public static Map<String, Object> assValidation(ImportExcel ei, int lastDataRowNum) {
        HashMap<String, Object> hashMap = new HashMap<String, Object>();
        List<Project> afterValidation = new ArrayList<>();
        Project project = null;
        String str = "";
        String flagStr = "";
        Boolean flag = false;
        DecimalFormat format = new DecimalFormat("0.0000");
        //获取所有的已有项目信息-比对，项目名称项目的数据进行数据比对
        List<Project> compareList = new ArrayList<>();
        List<Project> noCompareList = new ArrayList<>();
        //获取所有的储备项目暂定名称，比对名称纯在的进行数据验证
        List<String> strings = projectMapper.allProjectName();
        for (int i = 4; i < lastDataRowNum; i++) {
            project = new Project();
            Row row = ei.getRow(i);
            //获取表格项目名称
            Object reserveProjectName = ei.getCellValue(row, 0);
            if (reserveProjectName != null && reserveProjectName != "" && strings.contains(reserveProjectName)) {
                //获得储备项目暂定名称

                //查询项目前期基本信息表中是否有该项目信息，如果有获取之前数据，修改部分信息
                Project proByName = projectMapper.findAssByName((String) reserveProjectName);
                project.setAssignment(new Assignment());
                if (proByName != null) {
                    Boolean aBoolean = checkProcess((String) reserveProjectName);
                    if (!aBoolean) {
//                        flagStr += proByName.getBasicInformation().getReserveProjectName() + "项目流程运行中，不能更改信息\n";
                        flagStr += proByName.getReserveProjectName() + "项目流程运行中，不能更改信息\n\n";
                        continue;
                    }
                    project.getAssignment().setReserveProjectName((String) reserveProjectName);
                    project.getAssignment().setDeliveryDate((String) ei.getCellValue(row, 3));
                    project.getAssignment().setPackageNo((String) ei.getCellValue(row, 4));
                    project.getAssignment().setRate(format.format(new BigDecimal((String) ei.getCellValue(row, 5))));
                    project.getAssignment().setConstructionSubcontractor((String) ei.getCellValue(row, 8));
                    project.getAssignment().setBehalf((String) ei.getCellValue(row, 9));
                    project.getAssignment().setSubcontractingContact((String) ei.getCellValue(row, 14));
                    noCompareList.add(project);
                } else {
                    project.getAssignment().setReserveProjectName((String) reserveProjectName);
                    project.getAssignment().setDisclosureType((String) ei.getCellValue(row, 1));
                    project.getAssignment().setProjectReleaseBatch((String) ei.getCellValue(row, 2));
                    project.getAssignment().setDeliveryDate((String) ei.getCellValue(row, 3));
                    project.getAssignment().setPackageNo((String) ei.getCellValue(row, 4));
                    project.getAssignment().setRate(format.format(new BigDecimal((String) ei.getCellValue(row, 5))));
                    project.getAssignment().setAssignedUnit((String) ei.getCellValue(row, 6));
                    project.getAssignment().setConstructionUnit((String) ei.getCellValue(row, 7));
                    project.getAssignment().setConstructionSubcontractor((String) ei.getCellValue(row, 8));
                    project.getAssignment().setBehalf((String) ei.getCellValue(row, 9));
                    project.getAssignment().setConstructionFullTime((String) ei.getCellValue(row, 10));
                    project.getAssignment().setConstructionTechnical((String) ei.getCellValue(row, 11));
                    project.getAssignment().setConstructionManage((String) ei.getCellValue(row, 12));
                    project.getAssignment().setConstructionLeader((String) ei.getCellValue(row, 13));
                    project.getAssignment().setSubcontractingContact((String) ei.getCellValue(row, 14));
                    project.getAssignment().setDesigner((String) ei.getCellValue(row, 15));
                    project.getAssignment().setDesignLeader((String) ei.getCellValue(row, 16));
                    project.getAssignment().setOwnerManager((String) ei.getCellValue(row, 17));
                    project.getAssignment().setDistribution((String) ei.getCellValue(row, 18));
                    project.getAssignment().setDistributionFullTime((String) ei.getCellValue(row, 19));
                    project.getAssignment().setDistributionSystem((String) ei.getCellValue(row, 20));
                    project.getAssignment().setDistributionPolicy((String) ei.getCellValue(row, 21));
                    project.getAssignment().setCenterLeader((String) ei.getCellValue(row, 22));
                    project.getAssignment().setCenterTechnical((String) ei.getCellValue(row, 23));
                    String demandUnit = projectMapper.findDemandUnit((String) reserveProjectName);
                    if ("经研所".equals(demandUnit)) {
                        project.getAssignment().setInstituteRole((String) ei.getCellValue(row, 24));
                    }
                    project.getAssignment().setRepUnit((String) ei.getCellValue(row, 25));
                    project.getAssignment().setInspectionUnit((String) ei.getCellValue(row, 26));
                    compareList.add(project);
                }
            }
        }
//        for (String a : strings) {
//            for (int i = 4; i < lastDataRowNum; i++) {
//                project = new Project();
//                Row row = ei.getRow(i);
//                //获取表格项目名称
//                Object reserveProjectName = ei.getCellValue(row, 0);
//                if (reserveProjectName != null && reserveProjectName != "" && a.equals(reserveProjectName)) {
//                    //获得储备项目暂定名称
//
//                    //查询项目前期基本信息表中是否有该项目信息，如果有获取之前数据，修改部分信息
//                    Project proByName = projectMapper.findAssByName((String) reserveProjectName);
//                    project.setAssignment(new Assignment());
//                    if (proByName != null) {
//                        Boolean aBoolean = checkProcess((String) reserveProjectName);
//                        if (!aBoolean) {
//                            flagStr += proByName.getBasicInformation().getReserveProjectName() + "项目流程运行中，不能更改信息\n";
//                            continue;
//                        }
//                        project.getAssignment().setReserveProjectName((String) reserveProjectName);
//                        project.getAssignment().setDeliveryDate((String) ei.getCellValue(row, 3));
//                        project.getAssignment().setPackageNo((String) ei.getCellValue(row, 4));
//                        project.getAssignment().setRate(format.format(new BigDecimal((String) ei.getCellValue(row, 5))));
//                        project.getAssignment().setConstructionSubcontractor((String) ei.getCellValue(row, 8));
//                        project.getAssignment().setBehalf((String) ei.getCellValue(row, 9));
//                        project.getAssignment().setSubcontractingContact((String) ei.getCellValue(row, 14));
//                        noCompareList.add(project);
//                    } else {
//                        project.getAssignment().setReserveProjectName((String) reserveProjectName);
//                        project.getAssignment().setDisclosureType((String) ei.getCellValue(row, 1));
//                        project.getAssignment().setProjectReleaseBatch((String) ei.getCellValue(row, 2));
//                        project.getAssignment().setDeliveryDate((String) ei.getCellValue(row, 3));
//                        project.getAssignment().setPackageNo((String) ei.getCellValue(row, 4));
//                        project.getAssignment().setRate(format.format(new BigDecimal((String) ei.getCellValue(row, 5))));
//                        project.getAssignment().setAssignedUnit((String) ei.getCellValue(row, 6));
//                        project.getAssignment().setConstructionUnit((String) ei.getCellValue(row, 7));
//                        project.getAssignment().setConstructionSubcontractor((String) ei.getCellValue(row, 8));
//                        project.getAssignment().setBehalf((String) ei.getCellValue(row, 9));
//                        project.getAssignment().setConstructionFullTime((String) ei.getCellValue(row, 10));
//                        project.getAssignment().setConstructionTechnical((String) ei.getCellValue(row, 11));
//                        project.getAssignment().setConstructionManage((String) ei.getCellValue(row, 12));
//                        project.getAssignment().setConstructionLeader((String) ei.getCellValue(row, 13));
//                        project.getAssignment().setSubcontractingContact((String) ei.getCellValue(row, 14));
//                        project.getAssignment().setDesigner((String) ei.getCellValue(row, 15));
//                        project.getAssignment().setDesignLeader((String) ei.getCellValue(row, 16));
//                        project.getAssignment().setOwnerManager((String) ei.getCellValue(row, 17));
//                        project.getAssignment().setDistribution((String) ei.getCellValue(row, 18));
//                        project.getAssignment().setDistributionFullTime((String) ei.getCellValue(row, 19));
//                        project.getAssignment().setDistributionSystem((String) ei.getCellValue(row, 20));
//                        project.getAssignment().setDistributionPolicy((String) ei.getCellValue(row, 21));
//                        project.getAssignment().setCenterLeader((String) ei.getCellValue(row, 22));
//                        project.getAssignment().setCenterTechnical((String) ei.getCellValue(row, 23));
//                        String demandUnit = projectMapper.findDemandUnit((String) reserveProjectName);
//                        if ("经研所".equals(demandUnit)) {
//                            project.getAssignment().setInstituteRole((String) ei.getCellValue(row, 24));
//                        }
//                        project.getAssignment().setRepUnit((String) ei.getCellValue(row, 25));
//                        project.getAssignment().setInspectionUnit((String) ei.getCellValue(row, 26));
//                        compareList.add(project);
//                    }
//                }
//            }
//        }
        //得到比对后list，进行数据验证，成功存入list返回，失败，返回
        for (Project p : compareList) {
            str = "";
            String disclosureType = p.getAssignment().getDisclosureType();
            String assignedUnit = p.getAssignment().getAssignedUnit();
            String constructionUnit = p.getAssignment().getConstructionUnit();
            flag = ProjectImportUtil.checkFlag(disclosureType, ProjectImportUtil.DIS_TYPE);
            if (flag) {
                str += "交底类型填写有误\t";
            }
            flag = ProjectImportUtil.checkFlag(assignedUnit, ProjectImportUtil.ASS_UNIT);
            if (flag) {
                str += "合同单位填写有误\t";
            }
            flag = ProjectImportUtil.checkFlag(constructionUnit, ProjectImportUtil.CON_UNIT);
            if (flag) {
                str += "施工单位填写有误\t";
            }
            String s = ProjectImportUtil.checkMember(p);
            str += s;
            if (!"".equals(str)) {
                flagStr += p.getAssignment().getReserveProjectName() + str + "\n";
            }else {
                afterValidation.add(p);
            }
        }
        hashMap.put("errorMsg", flagStr);
        hashMap.put("afterValidation", afterValidation);
        hashMap.put("noCompareList", noCompareList);
        return hashMap;
    }

    /**
     * 交底计划安排信息数据验证方法
     */
    public static Map<String, Object> approvalValidation(ImportExcel ei, int lastDataRowNum) {
        HashMap<String, Object> hashMap = new HashMap<String, Object>();
        List<Project> afterValidation = new ArrayList<>();
        Project project = null;
        String str = "";
        String flagStr = "";
        Boolean flag = false;
        //获取所有的已有项目信息-比对，项目名称项目的数据进行数据比对
        List<Project> compareList = new ArrayList<>();
        List<Project> noCompareList = new ArrayList<>();
        //获取所有的储备项目暂定名称，比对名称纯在的进行数据验证
        List<String> strings = projectMapper.allProjectId();
        for (String a : strings) {
            for (int i = 6; i < lastDataRowNum; i++) {
                project = new Project();
                Row row = ei.getRow(i);
                //获取表格项目名称
                String projectId = (String) ei.getCellValue(row, 0);
                if (projectId != null && projectId != "" && a.equals(projectId)) {
                    project.setApproval(new Approval());
                    project.setProjectId(projectId);
                    project.getApproval().setProjectPackage((String) ei.getCellValue(row, 1));
                    project.getApproval().setProjectBudget((String) ei.getCellValue(row, 2));
                    project.getApproval().setEnterSystemAmount((String) ei.getCellValue(row, 3));
                    project.getApproval().setAfterAmount((String) ei.getCellValue(row, 4));
                    project.getApproval().setAdjustmentReasons((String) ei.getCellValue(row, 5));
                    project.getApproval().setConstructionCost((String) ei.getCellValue(row, 6));
                    project.getApproval().setMaterialCost((String) ei.getCellValue(row, 7));
                    project.getApproval().setDesignFee((String) ei.getCellValue(row, 8));
                    project.getApproval().setSupervisionFee((String) ei.getCellValue(row, 9));
                    project.getApproval().setPolicyFee((String) ei.getCellValue(row, 10));
                    project.getApproval().setOtherExpenses((String) ei.getCellValue(row, 11));
                    //查询项目前期基本信息表中是否有该项目信息，如果有获取之前数据，修改部分信息
                    Project proByName = projectMapper.findApprovalByName(projectId);
                    if (proByName != null) {
                        noCompareList.add(project);
                    } else {
                        compareList.add(project);
                    }
                }
            }
        }
        hashMap.put("errorMsg", flagStr);
        hashMap.put("afterValidation", compareList);
        hashMap.put("noCompareList", noCompareList);
        return hashMap;
    }

    /**
     * 项目立项信息数据验证方法
     */
    public static Map<String, Object> planValidation(ImportExcel ei, int lastDataRowNum) {
        HashMap<String, Object> hashMap = new HashMap<String, Object>();
        Project project = null;
        String flagStr = "";
        //获取所有的已有项目信息-比对，项目名称项目的数据进行数据比对
        List<Project> compareList = new ArrayList<>();
        List<Project> noCompareList = new ArrayList<>();
        //获取所有的储备项目暂定名称，比对名称纯在的进行数据验证
        List<String> strings = projectMapper.allProjectName();
        for (String a : strings) {
            for (int i = 5; i < lastDataRowNum; i++) {
                project = new Project();
                Row row = ei.getRow(i);
                //获取表格项目名称
                String reserveProjectName = (String) ei.getCellValue(row, 0);
                if (reserveProjectName != null && reserveProjectName != "" && a.equals(reserveProjectName)) {
                    Project assByName = projectMapper.findAssByName(reserveProjectName);
                    Project basicByName = projectMapper.findProByName(reserveProjectName);
                    if (assByName == null || basicByName == null) {
                        flagStr += reserveProjectName + "请先完善项目的前置信息\n";
                        continue;
                    } else {
                        project.setAssignment(assByName.getAssignment());
                        project.setBasicInformation(basicByName.getBasicInformation());
                    }
                    project.setDisclosurePlan(new DisclosurePlan());
                    project.setReserveProjectName(reserveProjectName);
                    project.getDisclosurePlan().setReserveProjectName(reserveProjectName);
                    project.getDisclosurePlan().setPowerSupplyStation((String) ei.getCellValue(row, 6));
                    project.getDisclosurePlan().setMaintenance((String) ei.getCellValue(row, 8));
                    project.getDisclosurePlan().setAutomationContacts((String) ei.getCellValue(row, 9));
                    project.getDisclosurePlan().setLiveSurveyContact((String) ei.getCellValue(row, 10));
                    project.getDisclosurePlan().setInspector((String) ei.getCellValue(row, 11));
                    project.getDisclosurePlan().setDisclosurePlanDate((String) ei.getCellValue(row, 12));
                    Project proByName = projectMapper.findPlanByName(reserveProjectName);
                    if (proByName != null) {
                        noCompareList.add(project);
                        project.setStatus(proByName.getStatus());
                    } else {
                        project.setStatus("0");
                        compareList.add(project);
                    }
                }
            }
        }
        hashMap.put("errorMsg", flagStr);
        hashMap.put("compareList", compareList);
        hashMap.put("noCompareList", noCompareList);
        return hashMap;
    }


    /**
     * 判断是否为空
     */
    private static boolean isaBoolean(String operationUnit) {
        return null == operationUnit || "".equals(operationUnit);
    }

    /**
     * 判断是否包含规定值
     * string【】写入静态数据比对
     */
    public static Boolean checkFlag(String name, String[] strings) {
        boolean flag = true;
        for (String str : strings) {
            if (str.equals(name)) {
                flag = false;
                break;
            }
        }
        return flag;
    }

    /**
     * 根据储备项目名称查询项目是否在流程中
     */
    public static Boolean checkProcess(String name) {
        Project process = projectMapper.findProcess(name);
        String status = process.getStatus();
        String acquisitionStatus = process.getAcquisitionStatus();
        String advanceStatus = process.getAdvanceStatus();
        String constructionStatus = process.getConstructionStatus();
        String whetherCloseStatus = process.getWhetherCloseStatus();
        String settStatus = process.getSettStatus();
        if ("0".equals(status) && "0".equals(acquisitionStatus) && "0".equals(constructionStatus) && "0".equals(whetherCloseStatus) && "0".equals(settStatus) && "0".equals(advanceStatus)) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 根据储备项目名称查询项目是否在流程中
     */
    public static Boolean CHECKACQ(String name) {
        Project process = projectMapper.findProcess(name);
        String acquisitionStatus = process.getAcquisitionStatus();
        String advanceStatus = process.getAdvanceStatus();
        String constructionStatus = process.getConstructionStatus();
        String whetherCloseStatus = process.getWhetherCloseStatus();
        String settStatus = process.getSettStatus();
        if ("0".equals(acquisitionStatus) && "0".equals(constructionStatus) && "0".equals(whetherCloseStatus) && "0".equals(settStatus) && "0".equals(advanceStatus)) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 判断人员是否存在
     */
    public static String checkMember(Project project) {
        Boolean flag = false;
        String str = "";
        String constructionFullTime = project.getAssignment().getConstructionFullTime();
        String constructionTechnical = project.getAssignment().getConstructionTechnical();
        String constructionManage = project.getAssignment().getConstructionManage();
        String constructionLeader = project.getAssignment().getConstructionLeader();
        String designer = project.getAssignment().getDesigner();
        String designLeader = project.getAssignment().getDesignLeader();
        String ownerManager = project.getAssignment().getOwnerManager();
        String distribution = project.getAssignment().getDistribution();
        String distributionFullTime = project.getAssignment().getDistributionFullTime();
        String distributionSystem = project.getAssignment().getDistributionSystem();
        String distributionPolicy = project.getAssignment().getDistributionPolicy();
        String centerLeader = project.getAssignment().getCenterLeader();
        String centerTechnical = project.getAssignment().getCenterTechnical();
        String instituteRole = project.getAssignment().getInstituteRole();
        String repUnit = project.getAssignment().getRepUnit();
        String inspectionUnit = project.getAssignment().getInspectionUnit();
        List<String> allMember = projectMapper.findAllMember();
        flag = getJudgeLoginName(allMember, constructionFullTime);
        if (flag) {
            str += "施工单位物资专职人员有误\t";
        }
        flag = getJudgeLoginName(allMember, constructionTechnical);
        if (flag) {
            str += "施工单位技经专职人员有误\t";
        }
        flag = getJudgeLoginName(allMember, constructionManage);
        if (flag) {
            str += "施工项目经理人员有误\t";
        }
        flag = getJudgeLoginName(allMember, constructionLeader);
        if (flag) {
            str += "施工单位领导人员有误\t";
        }
        flag = getJudgeLoginName(allMember, designer);
        if (flag) {
            str += "设计人员人员有误\t";
        }
        flag = getJudgeLoginName(allMember, designLeader);
        if (flag) {
            str += "设计单位领导人员有误\t";
        }
        flag = getJudgeLoginName(allMember, ownerManager);
        if (flag) {
            str += "业主项目经理人员有误\t";
        }
        flag = getJudgeLoginName(allMember, distribution);
        if (flag) {
            str += "配网工程专职人员有误\t";
        }
        flag = getJudgeLoginName(allMember, distributionFullTime);
        if (flag) {
            str += "配网物资专职人员有误\t";
        }
        flag = getJudgeLoginName(allMember, distributionSystem);
        if (flag) {
            str += "配网系统维护专职人员有误\t";
        }
        flag = getJudgeLoginName(allMember, distributionPolicy);
        if (flag) {
            str += "配网政策处理人员有误\t";
        }
        flag = getJudgeLoginName(allMember, centerLeader);
        if (flag) {
            str += "项目管理中心领导人员有误\t";
        }
        flag = getJudgeLoginName(allMember, centerTechnical);
        if (flag) {
            str += "项目管理中心技经专职人员有误\t";
        }
        //获取需求单位
        String demandUnit = projectMapper.findDemandUnit(project.getReserveProjectName());
        if ("经研所".equals(demandUnit)) {
            if (isaBoolean(instituteRole)) {
                str += "需求单位为经研所，人员不能为空\t";
            } else {
                flag = getJudgeLoginName(allMember, instituteRole);
                if (flag) {
                    str += "经研所角色人员有误\t";
                }
            }
        }
        flag = getJudgeLoginName(allMember, repUnit);
        if (flag) {
            str += "运行单位业主代表人员有误\t";
        }
        flag = getJudgeLoginName(allMember, inspectionUnit);
        if (flag) {
            str += "运行单位运检专职人员有误\t";
        }
        return str;
    }

    //对登录人进行验证 true人员不存在
    public static boolean getJudgeLoginName(List<String> users, String string) {
        boolean flag = true;
        for (String user : users) {
            if (string.equals(user)) {
                flag = false;
                break;
            }
        }
        return flag;
    }
}
