package com.jeeplus.modules.sg.audit.information.utils;

import com.jeeplus.common.utils.SpringContextHolder;
import com.jeeplus.common.utils.excel.ImportExcel;
import com.jeeplus.modules.sg.audit.information.entity.Information;
import com.jeeplus.modules.sg.audit.information.entity.append;
import com.jeeplus.modules.sg.audit.information.service.InformationService;
import com.jeeplus.modules.sg.audit.material.entity.Material;
import com.jeeplus.modules.sg.audit.material.service.MaterialService;
import com.jeeplus.modules.sys.entity.User;
import com.jeeplus.modules.sys.utils.UserUtils;
import org.apache.poi.ss.usermodel.Row;
import org.springframework.beans.factory.annotation.Autowired;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;

public  class ImportInformation {
    @Autowired
    private static InformationService informationService = SpringContextHolder.getBean(InformationService.class);
    @Autowired
    private static MaterialService materialService = SpringContextHolder.getBean(MaterialService.class);

    /**
     * 导入欠供物资Excel数据
     */
    public static Map<String,Object> importmation(ImportExcel ei,int lastDataRowNum){
        HashMap<String,Object> hashMap = new HashMap<String,Object>();
        int successNum = 0;
        int failureNum = 0;
        int isBackNo = 0;
        List<Material> materials = new ArrayList<Material>();
        String countProjectId = "";
        int flag = 0;
        User user = UserUtils.getUser();
        Double difference = 0.0;
        List<Material> status = materialService.findStatus();
        for (int i = 1; i < lastDataRowNum; i++) {
            Material material = new Material();
            try {
                Row row = ei.getRow(i);
                Object projectId = ei.getCellValue(row, 1);
                if (projectId.toString().equals(countProjectId)) {
                    flag = 0;
                    countProjectId = projectId.toString();
                } else {
                    flag = 1;
                    countProjectId = projectId.toString();
                }
                Object inforId = ei.getCellValue(row, 3);
                Object materialName = ei.getCellValue(row, 4);
                Object outboundAmount = ei.getCellValue(row, 5);
                Object authorizedAmount = ei.getCellValue(row, 6);
                Object outboundNumber = ei.getCellValue(row, 8);
                Object authorizedNumber = ei.getCellValue(row, 9);
                Object price = ei.getCellValue(row, 11);
                Object unit = ei.getCellValue(row, 12);
                Object materialSmall = ei.getCellValue(row, 13);
                Object materialMid = ei.getCellValue(row, 14);
                Object materialBig = ei.getCellValue(row, 15);
                String isBack = "";
                if (outboundAmount.equals("")) {
                    outboundAmount = "0.0";
                }
                if (authorizedAmount.equals("")) {
                    authorizedAmount = "0.0";
                }
                if (outboundNumber.equals("")) {
                    outboundNumber = "0.0";
                }
                if (authorizedNumber.equals("")) {
                    authorizedNumber = "0.0";
                }
                if (price.equals("")) {
                    price = "0.0";
                }
                BigDecimal b1 = new BigDecimal(Double.parseDouble(outboundNumber.toString()));
                BigDecimal b2 = new BigDecimal(Double.parseDouble(authorizedNumber.toString()));
                double v =  b1.subtract(b2).doubleValue();
                difference =  v;
                if (difference == 0.0) {
                    isBack = "是";
                    isBackNo = 0;
                } else {
                    isBack = "否";
                    isBackNo = 1;
                }
                if (materials.size() >= 1000 && flag == 1) {
                    //更新物料信息
                    materialService.saveMater(materials);
                    //根据插入的物料信息查询项目定义号，sum（判断是否完成领退料(0完成-1为完成)） 并按照项目定义号分组
                    List<Material> information = materialService.findInformation(materials);
                    materials = new ArrayList<>();
                    //循环查询出的信息
                    for (Material maInfor : information) {
                        Information upInfor = new Information();
                        //根据项目定义号，查询获得项目信息
                        Information needInfor = materialService.findNeedInfor(maInfor);
                        if (needInfor != null) {
                            upInfor.setProjectId(needInfor.getProjectId());
                            //查询出的信息中是否完成领退料，每条物料0为完成，1为未完成，根据项目定义号分组后sum如果为0则改项目定义号下的所有物料都完成领退料
                            if (maInfor.getIsBackNo() == 0) {
                                //获取项目表中的第一次完成领退料，第一次完成领退料时间，第二次完成领退料
                                if (needInfor.getFirstFinish() == "" || needInfor.getFirstFinish() == null || ("否").equals(needInfor.getFirstFinish())) {
                                    upInfor.setFirstFinish("是");
                                    upInfor.setFirstFinishDate(new Date());
                                }  else if (("否").equals(needInfor.getSecondFinish())) {
                                    upInfor.setSecondFinish("是");
                                    upInfor.setSecondFinishDate(new Date());
                                } else if (("是").equals(needInfor.getSecondFinish())) {
                                    upInfor.setSecondFinish("是");
                                    upInfor.setSecondFinishDate(needInfor.getSecondFinishDate());
                                } else if (("是").equals(needInfor.getFirstFinish())) {
                                    upInfor.setFirstFinish("是");
                                    upInfor.setFirstFinishDate(needInfor.getFirstFinishDate());
                                }
                            } else {
                                if (needInfor.getFirstFinish() == "" || needInfor.getFirstFinish() == null || ("否").equals(needInfor.getFirstFinish())) {
                                    upInfor.setFirstFinish("否");
                                } else {
                                    upInfor.setSecondFinish("否");
                                }
                            }
                            materialService.updateNeed(upInfor);
                        }
                    }
                    if (status.size() > 0) {
                        for (Material list : status) {
                            double afterNumber = list.getAfterNumber();
                            double afterAuthor = list.getAfterAuthor();
                            double testOutBoundNumber = Double.parseDouble(outboundNumber.toString());
                            double testafterAuthor = Double.parseDouble(authorizedNumber.toString());
                            if (list.getProjectId().equals(projectId.toString()) && list.getInforId().equals(inforId.toString()) &&  afterNumber == testOutBoundNumber && afterAuthor==testafterAuthor) {
                                material.setIsBack("是");
                                material.setIsBackNo(0);
                                material.setStatus(list.getStatus());
                                material.setInfo(list.getInfo());
                                material.setAfterNumber(afterNumber);
                                material.setAfterAuthor(afterAuthor);
                                break;
                            } else if (list.getProjectId().equals(projectId.toString()) && list.getInforId().equals(inforId.toString()) && afterNumber!=testOutBoundNumber) {
                                material.setIsBack("否");
                                material.setIsBackNo(1);
                                material.setStatus(list.getStatus());
                                material.setInfo(list.getInfo());
                                material.setAfterNumber(afterNumber);
                                material.setAfterAuthor(afterAuthor);
                                break;
                            } else if (list.getProjectId().equals(projectId.toString()) && list.getInforId().equals(inforId.toString()) && afterAuthor!=testafterAuthor) {
                                material.setIsBack("否");
                                material.setIsBackNo(1);
                                material.setStatus(list.getStatus());
                                material.setInfo(list.getInfo());
                                material.setAfterNumber(afterNumber);
                                material.setAfterAuthor(afterAuthor);
                                break;
                            }else {
                                material.setIsBack(isBack);
                                material.setIsBackNo(isBackNo);
                            }
                        }
                    } else {
                        material.setIsBack(isBack);
                        material.setIsBackNo(isBackNo);
                    }
                    material.setInforId(inforId.toString());
                    material.setProjectId(projectId.toString());
                    material.setMaterialName(materialName.toString());
                    material.setOutboundAmount(Double.parseDouble(outboundAmount.toString()));
                    material.setAuthorizedAmount(Double.parseDouble(authorizedAmount.toString()));;
                    material.setDifference(difference);
                    material.setOutboundNumber(Double.parseDouble(outboundNumber.toString()));
                    material.setAuthorizedNumber(Double.parseDouble(authorizedNumber.toString()));
                    material.setPrice(Double.parseDouble(price.toString()));
                    material.setUnit(unit.toString());
                    material.setMaterialSmall(materialSmall.toString());
                    material.setMaterialMid(materialMid.toString());
                    material.setMaterialBig(materialBig.toString());
                    material.preInsert();
                    material.setCreateBy(user);
                    material.setCreateDate(new Date());
                    material.setUpdateBy(user);
                    material.setUpdateDate(new Date());
                    materials.add(material);
                    successNum++;
                } else {
                    if (status.size() > 0) {
                        for (Material list : status) {
                            double afterNumber = list.getAfterNumber();
                            double afterAuthor = list.getAfterAuthor();
                            double testOutBoundNumber = Double.parseDouble(outboundNumber.toString());
                            double testafterAuthor = Double.parseDouble(authorizedNumber.toString());
                            if (list.getProjectId().equals(projectId.toString()) && list.getInforId().equals(inforId.toString()) &&  afterNumber == testOutBoundNumber && afterAuthor==testafterAuthor) {
                                material.setIsBack("是");
                                material.setIsBackNo(0);
                                material.setStatus(list.getStatus());
                                material.setInfo(list.getInfo());
                                material.setAfterNumber(afterNumber);
                                material.setAfterAuthor(afterAuthor);
                                break;
                            } else if (list.getProjectId().equals(projectId.toString()) && list.getInforId().equals(inforId.toString()) && afterNumber!=testOutBoundNumber) {
                                material.setIsBack("否");
                                material.setIsBackNo(1);
                                material.setStatus(list.getStatus());
                                material.setInfo(list.getInfo());
                                material.setAfterNumber(afterNumber);
                                material.setAfterAuthor(afterAuthor);
                                break;
                            } else if (list.getProjectId().equals(projectId.toString()) && list.getInforId().equals(inforId.toString()) && afterAuthor!=testafterAuthor) {
                                material.setIsBack("否");
                                material.setIsBackNo(1);
                                material.setStatus(list.getStatus());
                                material.setInfo(list.getInfo());
                                material.setAfterNumber(afterNumber);
                                material.setAfterAuthor(afterAuthor);
                                break;
                            }else {
                                material.setIsBack(isBack);
                                material.setIsBackNo(isBackNo);
                            }
                        }
                    } else {
                        material.setIsBack(isBack);
                        material.setIsBackNo(isBackNo);
                    }
                    material.setInforId(inforId.toString());
                    material.setProjectId(projectId.toString());
                    material.setMaterialName(materialName.toString());
                    material.setOutboundAmount(Double.parseDouble(outboundAmount.toString()));
                    material.setAuthorizedAmount(Double.parseDouble(authorizedAmount.toString()));;
                    material.setDifference(difference);
                    material.setOutboundNumber(Double.parseDouble(outboundNumber.toString()));
                    material.setAuthorizedNumber(Double.parseDouble(authorizedNumber.toString()));
                    material.setPrice(Double.parseDouble(price.toString()));
                    material.setUnit(unit.toString());
                    material.setMaterialSmall(materialSmall.toString());
                    material.setMaterialMid(materialMid.toString());
                    material.setMaterialBig(materialBig.toString());
                    material.preInsert();
                    material.setCreateBy(user);
                    material.setCreateDate(new Date());
                    material.setUpdateBy(user);
                    material.setUpdateDate(new Date());
                    materials.add(material);
                    successNum++;
                }
            }catch (Exception ex) {
                ex.getMessage();
                failureNum++;
            }
        }
        if (materials.size() != 0) {
            materialService.saveMater(materials);
            List<Material> information = materialService.findInformation(materials);
            for (Material maInfor:information) {
                Information upInfor = new Information();
                Information needInfor = materialService.findNeedInfor(maInfor);
                if (needInfor != null) {
                    upInfor.setProjectId(needInfor.getProjectId());
                    if (maInfor.getIsBackNo() == 0) {
                        if (needInfor.getFirstFinish() == "" || needInfor.getFirstFinish() == null || ("否").equals(needInfor.getFirstFinish())) {
                            upInfor.setFirstFinish("是");
                            upInfor.setFirstFinishDate(new Date());
                        }  else if (("否").equals(needInfor.getSecondFinish())) {
                            upInfor.setSecondFinish("是");
                            upInfor.setSecondFinishDate(new Date());
                        } else if (("是").equals(needInfor.getSecondFinish())) {
                            upInfor.setSecondFinish("是");
                            upInfor.setSecondFinishDate(needInfor.getSecondFinishDate());
                        } else if (("是").equals(needInfor.getFirstFinish())) {
                            upInfor.setFirstFinish("是");
                            upInfor.setFirstFinishDate(needInfor.getFirstFinishDate());
                        }
                    } else {
                        if (needInfor.getFirstFinish() == "" || needInfor.getFirstFinish() == null || ("否").equals(needInfor.getFirstFinish())) {
                            upInfor.setFirstFinish("否");
                        } else {
                            upInfor.setSecondFinish("否");
                        }
                    }
                    materialService.updateNeed(upInfor);
                }
            }
        }
        hashMap.put("successNum",successNum);
        hashMap.put("failureNum",failureNum);
        return hashMap;
    }

    /**
     *	导入综合信息Excel数据
     * */
    public static Map<String,Integer> importCom(ImportExcel ei,int lastDataRowNum) {
        HashMap<String,Integer> hashMap = new HashMap<String,Integer>();
        int successNum = 0;
        int failureNum = 0;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        List<Information> informationList = new ArrayList<>();
        User user = UserUtils.getUser();
        String firstFinish = "否";
        for (int i = 2; i < lastDataRowNum; i++) {
            Information information = new Information();
            try {
                Row row = ei.getRow(i);
                Object projectId = ei.getCellValue(row, 1);
                Object projectName = ei.getCellValue(row, 2);
                Object projectType = ei.getCellValue(row, 3);
                if (projectId.equals("")) {
                    continue;
                }
                if (projectType.equals("项目类型")
                    ||projectType.equals("配网建设改造项目")
                    ||projectType.equals("新建居住区供配电工程")
                    ||projectType.equals("配网专项成本")
                    ||projectType.equals("生产辅助大修项目")
                    ||projectType.equals("电网检修专项")
                    ||projectType.equals("大中型基建项目")
                    ||projectType.equals("农电运检项目")
                    ||projectType.equals("营销专项")
                    ||projectType.equals("生产修理项目")
                    ||projectType.equals("通信技改项目")
                    ||projectType.equals("二次技改项目")
                    ||projectType.equals("一次技改项目")
                    ||projectType.equals("营销成本项目")
                    ||projectType.equals("营销资本项目")
                    ||projectType.equals("通信修理项目")
                    ||projectType.equals("调度修理项目")
                    ||projectType.equals("小型基建项目")
                    ||projectType.equals("信息运维")
                    ||projectType.equals("生产辅助技改项目")
                ){
                    Information inforById = informationService.findListById(projectId.toString());
                    if (inforById != null) {
                        if (inforById.getFirstFinish() != null || inforById.getFirstFinish() != "") {
                            information.setFirstFinish(inforById.getFirstFinish());
                        } else {
                            information.setFirstFinish(firstFinish);
                        }
                        if (inforById.getFirstFinishDate() != null) {
                            information.setFirstFinishDate(inforById.getFirstFinishDate());
                        }
                        if (inforById.getSecondFinish() != null || inforById.getSecondFinish() != "") {
                            information.setSecondFinish(inforById.getSecondFinish());
                        }
                        if (inforById.getSecondFinishDate() != null) {
                            information.setSecondFinishDate(inforById.getSecondFinishDate());
                        }
                    } else {
                        information.setFirstFinish(firstFinish);
                    }
                    Object projectGrade = ei.getCellValue(row, 4);
                    Object projectYear = ei.getCellValue(row, 6);
                    Object projectTotal = ei.getCellValue(row, 7);
                    Object projectStart = ei.getCellValue(row, 14);
                    Object projectStop = ei.getCellValue(row, 15);
                    Object department = ei.getCellValue(row, 16);
                    //26 土建审定金额
                    Object civil = ei.getCellValue(row, 26);
                    if (civil.equals("")) {
                        civil = "0.0";
                    }
                    //27 安装审定金额
                    Object installation = ei.getCellValue(row, 27);
                    if (installation.equals("")) {
                        installation = "0.0";
                    }

                    BigDecimal b1 = new BigDecimal(Double.parseDouble(civil.toString()));
                    BigDecimal b2 = new BigDecimal(Double.parseDouble(installation.toString()));
                    double settlementPrice = b1.add(b2).doubleValue();
                    //AH(建议结算款)
                    Object suggestedAmount = ei.getCellValue(row, 33);
                    if ("".equals(suggestedAmount)) {
                        suggestedAmount = "0.0";
                    }
                    Object projectFirm = ei.getCellValue(row, 39);
                    Object subDate = ei.getCellValue(row, 41);
                    Object releaseDate = ei.getCellValue(row, 42);
                    Object endDate = ei.getCellValue(row, 43);
                    Object resultDate = ei.getCellValue(row, 44);
                    Object approvalDate = ei.getCellValue(row, 45);
                    Object underCentralized = ei.getCellValue(row, 53);
                    Object secondUnits = ei.getCellValue(row, 54);
                    Object firstUnits = ei.getCellValue(row, 55);
                    if (projectTotal.equals("")) {
                        projectTotal = "0.0";
                    }

                    information.setProjectId(projectId.toString());
                    information.setProjectName(projectName.toString());
                    information.setProjectType(projectType.toString());
                    information.setProjectGrade(projectGrade.toString());
                    information.setProjectYear(projectYear.toString());
                    information.setProjectTotal(projectTotal.toString());
                    information.setUnderCentralized(secondUnits.toString()+underCentralized.toString());
                        if (!projectStart.equals("")&&projectStart!=null) {
                            information.setProjectStart(simpleDateFormat.parse(projectStart.toString()));
                        }
                        if (!projectStop.equals("")&&projectStop!=null) {
                            information.setProjectStop(simpleDateFormat.parse(projectStop.toString()));
                        }
                        information.setDepartment(department.toString());
                        information.setProjectFirm(projectFirm.toString());
                        if (!subDate.equals("")&&subDate!=null) {
                            information.setSubDate(simpleDateFormat.parse(subDate.toString()));
                        }
                        if (!releaseDate.equals("")&&releaseDate!=null) {
                            information.setReleaseDate(simpleDateFormat.parse(releaseDate.toString()));
                        }
                        if (!endDate.equals("")&&endDate!=null) {
                            information.setEndDate(simpleDateFormat.parse(endDate.toString()));
                        }
                        if (!resultDate.equals("")&&resultDate!=null) {
                            information.setResultDate(simpleDateFormat.parse(resultDate.toString()));
                        }
                        if (!approvalDate.equals("")&&approvalDate!=null) {
                            information.setApprovalDate(simpleDateFormat.parse(approvalDate.toString()));
                        }
                    information.setSettlementPrice(settlementPrice);
                    information.setSecondUnits(secondUnits.toString());
                    information.setFirstUnits(firstUnits.toString());
                    information.preInsert();
                    information.setCreateBy(user);
                    information.setCreateDate(new Date());
                    information.setUpdateBy(user);
                    information.setUpdateDate(new Date());
                    information.setSuggestedAmount(suggestedAmount.toString());
                    informationList.add(information);
                    successNum++;
             }
                if (informationList.size() == 1000) {
                    informationService.saveInfo(informationList);
                    informationList = new ArrayList<>();
                }
            } catch (Exception ex) {
                ex.getMessage();
                failureNum++;
            }
        }
        if (informationList.size() != 0) {
            informationService.saveInfo(informationList);
        }
        hashMap.put("successNum",successNum);
        hashMap.put("failureNum",failureNum);
        return hashMap;
    }

    /**
     * 导入原因类型
     * */
    public static Map<String,Object> btnInReason(ImportExcel ei,int lastDataRowNum) {
        HashMap<String,Object> hashMap = new HashMap<String,Object>();
        //用于记录导入原因类型时，没有原因类型的情况
        List<Material> materialList = new ArrayList<>();
        //用于记录导入原因类型时，已有原因类型的情况
        List<Material> noChange = new ArrayList<>();
        List error = new ArrayList();
        int successNum = 0;
        int failureNum = 0;
        for (int i = 2; i < lastDataRowNum; i++) {
            try {
                Material material = new Material();
                Row row = ei.getRow(i);
                //项目定义号
                Object projectId = ei.getCellValue(row, 1);
                //审定数量
                Object authorizedNumber = ei.getCellValue(row, 10);
                //出库数量
                Object outboundNumber = ei.getCellValue(row, 9);
                //物料编号
                Object inforId = ei.getCellValue(row, 2);
                //原因类型
                Object status = ei.getCellValue(row, 17);
                //备注说明
                Object info = ei.getCellValue(row, 18);
                //根据项目定义号，物料定义号查询出该条的物料信息
                Material myProIn = materialService.findByProIn(projectId.toString(), inforId.toString());
                //如果出库数量与记录的出库数量不一致，不与插入
                if (!myProIn.getOutboundNumber().equals(Double.parseDouble(outboundNumber.toString())) || !myProIn.getAuthorizedNumber().equals(Double.parseDouble(authorizedNumber.toString()))) {
                    error.add(projectId.toString());
                    continue;
                }
                String infoW = "";
                //判断原因说明有没有填写------------没有填写进行下条数据的
                if (status.equals("") || status == null) {
                    continue;
                }else if(myProIn.getStatus()!=null){
                    material.setProjectId(projectId.toString());
                    material.setInforId(inforId.toString());
                    material.setStatus(status.toString());
                    if (info == null || info.equals("")) {
                        infoW =" ";
                    } else {
                        infoW = info.toString();
                    }
                    material.setInfo(infoW);
                    material.setIsBackNo(0);
                    material.setIsBack("是");
                    Double outboundNumber1 = myProIn.getOutboundNumber();
                    material.setAfterNumber(outboundNumber1);
                    Double authorizedNumber1 = myProIn.getAuthorizedNumber();
                    material.setAfterAuthor(authorizedNumber1);
                    noChange.add(material);
                } else {
                    material.setProjectId(projectId.toString());
                    material.setInforId(inforId.toString());
                    material.setStatus(status.toString());
                    if (info == null || info.equals("")) {
                         infoW =" ";
                    } else {
                         infoW = info.toString();
                    }
                    material.setInfo(infoW);
                    material.setIsBack("是");
                    material.setIsBackNo(0);
                    Double outboundNumber1 = myProIn.getOutboundNumber();
                    material.setAfterNumber(outboundNumber1);
                    Double authorizedNumber1 = myProIn.getAuthorizedNumber();
                    material.setAfterAuthor(authorizedNumber1);
                    materialList.add(material);
                }
                successNum++;
                if (materialList.size() == 1000) {
                    materialService.updateStatus(materialList);
                    //根据
                    List<Material> isBack = materialService.findIsBack(materialList);
                    for (Material maInfor:isBack) {
                        Information upInfor = new Information();
                        Information needInfor = materialService.findNeedInfor(maInfor);
                        if (needInfor.getFirstFinish() == "" || needInfor.getFirstFinish() == null || ("否").equals(needInfor.getFirstFinish())) {
                            upInfor.setProjectId(needInfor.getProjectId());
                            upInfor.setFirstFinish("是");
                            upInfor.setFirstFinishDate(new Date());
                        } else  {
                            upInfor.setProjectId(needInfor.getProjectId());
                            upInfor.setSecondFinish("是");
                            upInfor.setSecondFinishDate(new Date());
                        }
                        materialService.updateNeed(upInfor);
                    }
                    materialList = new ArrayList<>();
                }
                if (noChange.size() == 1000) {
                    materialService.updateStatus(noChange);
                    List<Material> isBack = materialService.findIsBack(materialList);
                    for (Material maInfor:isBack) {
                        Information upInfor = new Information();
                        Information needInfor = materialService.findNeedInfor(maInfor);
                        if (needInfor.getFirstFinish() == "" || needInfor.getFirstFinish() == null || ("否").equals(needInfor.getFirstFinish())) {
                            upInfor.setProjectId(needInfor.getProjectId());
                            upInfor.setFirstFinish("是");
                            upInfor.setFirstFinishDate(new Date());
                        } else if (("否").equals(needInfor.getSecondFinish())) {
                            upInfor.setProjectId(needInfor.getProjectId());
                            upInfor.setSecondFinish("是");
                            upInfor.setSecondFinishDate(new Date());
                        } else {
                            continue;
                        }
                        materialService.updateNeed(upInfor);
                    }
                    noChange = new ArrayList<>();
                }
            } catch (Exception e) {
                failureNum++;
            }
        }
        try {
            if (materialList.size() != 0) {
                materialService.updateStatus(materialList);
                List<Material> isBack = materialService.findIsBack(materialList);
                for (Material maInfor:isBack) {
                    Information upInfor = new Information();
                    Information needInfor = materialService.findNeedInfor(maInfor);
                    if (needInfor.getFirstFinish() == "" || needInfor.getFirstFinish() == null || ("否").equals(needInfor.getFirstFinish())) {
                        upInfor.setProjectId(needInfor.getProjectId());
                        upInfor.setFirstFinish("是");
                        upInfor.setFirstFinishDate(new Date());
                    }  else {
                        upInfor.setProjectId(needInfor.getProjectId());
                        upInfor.setSecondFinish("是");
                        upInfor.setSecondFinishDate(new Date());
                    }
                    //根据项目定义号，更新项目是否完成领退料的状态
                    materialService.updateNeed(upInfor);
                }
                materialList = new ArrayList<>();
            }
            if (noChange.size() != 0) {
                materialService.updateStatus(noChange);
                noChange = new ArrayList<>();
            }
        } catch (Exception e) {
            failureNum++;
            e.printStackTrace();
        }
        hashMap.put("error",error);
        hashMap.put("successNum",successNum);
        hashMap.put("failureNum",failureNum);
        return hashMap;
    }

    /**
     * 导入送审
     * */
    public static Map<String,Integer> importInTrial(ImportExcel ei,int lastDataRowNum) {
        HashMap<String,Integer> hashMap = new HashMap<String,Integer>();
        List<append> appendList = new ArrayList<>();
        int successNum = 0;
        int failureNum = 0;
        for (int i = 1; i < lastDataRowNum; i++) {
            try {
                append append = new append();
                Row row = ei.getRow(i);
                //项目定义号
                Object projectId = ei.getCellValue(row, 0);
                //是否决算送审
                Object trial = ei.getCellValue(row, 1);
                //工作状态
                Object appendStatus = ei.getCellValue(row, 2);
                append.setProjectId(projectId.toString());
                append.setTrial(trial.toString());
                append.setAppendStatus(appendStatus.toString());
                appendList.add(append);
                if (appendList.size() == 1000) {
                    informationService.updateAppend(appendList);
                    successNum = successNum + appendList.size();
                    appendList = new ArrayList<>();
                }
            } catch (Exception e) {
                failureNum++;
            }
        }
        if (appendList.size() != 0) {
            informationService.updateAppend(appendList);
            successNum = successNum + appendList.size();
        }
        hashMap.put("successNum",successNum);
        hashMap.put("failureNum",failureNum);
        return hashMap;
    }

}
