/**
 * Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.modules.sg.managementcenter.activiti.web;

import java.io.*;
import java.net.URL;
import java.net.URLDecoder;
import java.util.*;

import com.jeeplus.common.config.Global;
import com.jeeplus.common.utils.DateUtils;
import com.jeeplus.common.utils.excel.ExportExcel;
import com.jeeplus.common.utils.excel.ImportExcel;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.modules.sg.audit.information.entity.Information;
import com.jeeplus.modules.sg.audit.information.entity.OutInformation;
import com.jeeplus.modules.sg.audit.information.utils.FreemarkerUtil;
import com.jeeplus.modules.sg.audit.information.utils.ResponseUtil;
import com.jeeplus.modules.sg.financial.erpcredit.util.ExportUtil;
import com.jeeplus.modules.sg.financial.erpcredit.util.ImportUtil;
import com.jeeplus.modules.sg.managementcenter.activiti.entity.*;
import com.jeeplus.modules.sg.managementcenter.activiti.service.UploadImagesService;
import com.jeeplus.modules.sg.managementcenter.activiti.utils.MyActiviUtils;
import com.jeeplus.modules.sg.managementcenter.activiti.utils.MyImportUtils;
import com.jeeplus.modules.sg.managementcenter.materialinfo.entity.MaterialInfo;
import com.jeeplus.modules.sg.managementcenter.materialinfo.entity.MaterialInfoBean;
import com.jeeplus.modules.sg.managementcenter.materialinfo.service.MaterialInfoService;
import com.jeeplus.modules.sg.managementcenter.materialinfo.util.MaterialInfoUtil;
import com.jeeplus.modules.sg.managementcenter.materialproject.entity.MaterialProject;
import com.jeeplus.modules.sg.managementcenter.materialproject.service.MaterialProjectService;
import com.jeeplus.modules.sg.managementcenter.moduleacquisition.entity.ModuleBlock;
import com.jeeplus.modules.sg.managementcenter.project.entity.Project;
import com.jeeplus.modules.sg.managementcenter.project.entity.Project1;

import com.google.common.collect.Maps;
import com.jeeplus.common.json.AjaxJson;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.core.web.BaseController;
import com.jeeplus.modules.act.service.ActProcessService;
import com.jeeplus.modules.act.service.ActTaskService;
import com.jeeplus.modules.sg.managementcenter.activiti.service.ConstructionService;
import com.jeeplus.modules.sg.managementcenter.project.service.ProjectService;
import com.jeeplus.modules.sg.materialmodule.activiti.entity.NonPower;
import com.jeeplus.modules.sg.materialmodule.activiti.service.NonPowerService;
import com.jeeplus.modules.sg.picking.activiti.entity.ShowList;
import com.jeeplus.modules.sg.picking.activiti.service.ShowListService;
import com.jeeplus.modules.sys.entity.DictValue;
import com.jeeplus.modules.sys.entity.User;
import com.jeeplus.modules.sys.utils.DictUtils;
import com.jeeplus.modules.sys.utils.UserUtils;
import com.jeeplus.modules.sys.web.FileController;
import org.activiti.engine.*;
import org.activiti.engine.repository.ProcessDefinition;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Row;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 施工交底Controller
 *
 * @author
 * @version 2019-11-08
 */
@Controller
@RequestMapping(value = "${adminPath}/managementcenter/activiti")

public class ConstructionController extends BaseController {
    @Autowired
    private ConstructionService constructionService;

    @Autowired
    private ActProcessService actProcessService;
    @Autowired
    private ActTaskService actTaskService;
    @Autowired
    private UploadImagesService uploadImagesService;
    @Autowired
    private TaskService taskService;
    @Autowired
    private ProjectService projectService;
    @Autowired
    private FileController fileController;
    @Autowired
    private MaterialInfoService materialInfoService;
    @Autowired
    private ShowListService showListService;
    @Autowired
    private NonPowerService nonPowerService;

    @ModelAttribute
    public Construction get(@RequestParam(required = false) String id) {
        Construction entity = null;
        if (StringUtils.isNotBlank(id)) {
            entity = constructionService.get(id);
        }
        if (entity == null) {
            entity = new Construction();
        }
        return entity;
    }


    /**
     * 施工交底流程开始页面
     */
    @RequestMapping(value = "start")
    public String form(Construction construction, Model model) {
        model.addAttribute("construction", construction);
        return "modules/sg/managementcenter/activiti/constructionForm";
    }

    /**
     * 项目经理组织交底页面
     */
    @RequestMapping(value = "divideForm")
    public String divideForm(Construction construction, Model model) {
        model.addAttribute("construction", construction);
        //项目经理组织交底
        Disclose disclose = construction.getDisclose();
        if (disclose == null) {
            model.addAttribute("noProblem", true);
        } else {
            MyImportUtils.getTheEcho(construction, model);
        }
        return "modules/sg/managementcenter/activiti/divideForm";
    }

    /**
     * 项目交底结论信息列表
     */
    @RequestMapping(value = "discloseList")
    public String disclose(Construction construction, Model model) {
        model.addAttribute("construction", construction);
        return "modules/sg/managementcenter/activiti/discloseList";
    }

    /**
     * 项目交底结论信息数据
     */
    @ResponseBody
    @RequestMapping(value = "data")
    public Map<String, Object> data(Construction construction, HttpServletRequest request, HttpServletResponse response, Model model) {
        String reserveProjectName = construction.getReserveProjectName();
        List<String> reserveList = new ArrayList<>();
        if (null != reserveProjectName && !"".equals(reserveProjectName)) {
            String[] split = reserveProjectName.split("\\s+");
            String reserveName = "";
            for (int i = 0; i < split.length; i++) {
                reserveName = split[i];
                reserveList.add(reserveName);
            }
            construction.setReserveList(reserveList);
        }
        Page<Construction> page = constructionService.findDisclosePage(new Page<Construction>(request, response), construction);
        return getBootstrapData(page);
    }

    /**
     * 导出施工交底进度
     */
    @ResponseBody
    @RequestMapping(value = "exportDisclose")
    public AjaxJson exportDisclose(Construction construction, HttpServletRequest request, HttpServletResponse response, Model model) throws UnsupportedEncodingException {
        AjaxJson j = new AjaxJson();

        String reserveProjectName =  URLDecoder.decode(construction.getReserveProjectName(),"UTF-8");
        construction.setProjectId(URLDecoder.decode(construction.getProjectId(),"UTF-8"));
        construction.setProjectName(URLDecoder.decode(construction.getProjectName(),"UTF-8"));
        List<String> reserveList = new ArrayList<>();
        if (null != reserveProjectName && !"".equals(reserveProjectName)) {
            String[] split = reserveProjectName.split("\\s+");
            String reserveName = "";
            for (int i = 0; i < split.length; i++) {
                reserveName = split[i];
                reserveList.add(reserveName);
            }
            construction.setReserveList(reserveList);
        }
        Page<Construction> page = constructionService.findDisclosePage(new Page<Construction>(request, response,-1), construction);

        try {
            String fileName = "施工交底进度"+ DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";
            new ExportExcel("施工交底进度", Construction.class).setDataList(page.getList()).write(response, fileName).dispose();
            j.setSuccess(true);
            j.setMsg("导出成功！");
            return j;
        } catch (Exception e) {
            j.setSuccess(false);
            j.setMsg("导出施工交底进度记录失败！失败信息："+e.getMessage());
        }
        return j;

    }

    /**
     * 人工审核页面
     */
    @RequestMapping(value = "artificial")
    public String form2(Construction construction, Model model) {
        MyImportUtils.getTheEcho(construction, model);
        //获取发起人
        model.addAttribute("construction", construction);
        return "modules/sg/managementcenter/activiti/artificialJudgment";
    }

    /**
     * 配网运行人员判定设计变更
     */
    @RequestMapping(value = "operatorDesignChange")
    public String form3(Construction construction, Model model) {
        model.addAttribute("construction", construction);
        return "modules/sg/managementcenter/activiti/operatorDesignChange";
    }

    /**
     * 交底:运行人员审核图纸
     */
    @RequestMapping(value = "auditDrawings")
    public String auditDrawings(Construction construction, Model model) {

        model.addAttribute("construction", construction);
        return "modules/sg/managementcenter/activiti/auditDrawings";
    }

    /**
     * 交底:运行单位经理审核方案
     */
    @RequestMapping(value = "designUpload")
    public String designUpload(Construction construction, Model model) {
        model.addAttribute("construction", construction);
        return "modules/sg/managementcenter/activiti/designUpload";
    }

    /**
     * 设计单位人员重新设计
     */
    @RequestMapping(value = "operatorUploadList")
    public String operatorUploadList(Construction construction, Model model) {
        model.addAttribute("construction", construction);
        return "modules/sg/managementcenter/activiti/operatorUploadList";
    }

    /**
     * 运行经理驳回-设计单位人员调整文件
     */
    @RequestMapping(value = "operatorUploadAfter")
    public String operatorUploadAfter(Construction construction, Model model) {
        model.addAttribute("construction", construction);
        return "modules/sg/managementcenter/activiti/operatorUploadAfter";
    }

    /**
     * 修改项目文件路径
     */
    @RequestMapping(value = "uploadAfter")
    public String uploadAfter(UploadImages uploadImages, Model model) {
        UploadImages uploadImages1 = uploadImagesService.get(uploadImages.getId());
        model.addAttribute("uploadImages", uploadImages1);
        return "modules/sg/managementcenter/activiti/uploadAfter";
    }

    /**
     * 运行经理审核设计变更后
     */
    @RequestMapping(value = "managerUploadList")
    public String managerUploadList(Construction construction, Model model) {
        model.addAttribute("construction", construction);
        return "modules/sg/managementcenter/activiti/managerUploadList";
    }

    /**
     * 配网经理审核设计变更后
     */
    @RequestMapping(value = "afterDistribution")
    public String afterDistribution(Construction construction, Model model) {
        model.addAttribute("construction", construction);
        return "modules/sg/managementcenter/activiti/afterDistribution";
    }

    /*
     交底:判断项目是否需要关闭
   */
    @RequestMapping(value = "speciallyForm")
    public String speciallyForm(Construction construction, Model model) {
        model.addAttribute("construction", construction);
        return "modules/sg/managementcenter/activiti/speciallyForm";
    }

    /*
      项目关闭，配网工程专职判定
   */
    @RequestMapping(value = "managerForm")
    public String managerForm(Construction construction, Model model) {
        model.addAttribute("construction", construction);
        return "modules/sg/managementcenter/activiti/managerCloseForm";
    }

    /*
        项目关闭，配网运行人员
     */
    @RequestMapping(value = "memberForm")
    public String memberForm(Construction construction, Model model) {
        model.addAttribute("construction", construction);
        return "modules/sg/managementcenter/activiti/memberForm";
    }


    /*
       项目关闭，配网系统专职
    */
    @RequestMapping(value = "departmentForm")
    public String departmentForm(Construction construction, Model model) {
        model.addAttribute("construction", construction);
        return "modules/sg/managementcenter/activiti/departmentForm";
    }

    /**
     * 政策处理
     */
    @RequestMapping(value = "policiesChange")
    public String policiesChange(Construction construction, Model model) {
        model.addAttribute("construction", construction);
        return "modules/sg/managementcenter/activiti/policiesChange";
    }


    /**
     * 政策处理项目经理判断是否需要继续
     */
    @RequestMapping(value = "managerPolicesChange")
    public String managerPolicesChange(Construction construction, Model model) {
        model.addAttribute("construction", construction);
        return "modules/sg/managementcenter/activiti/managerPolicesChange";
    }

    /**
     * 经研所审核页面
     */
    @RequestMapping(value = "economicsDesignChange")
    public String form4(Construction construction, Model model) {

        model.addAttribute("construction", construction);
        return "modules/sg/managementcenter/activiti/economicsDesignChange";
    }

    /**
     * 项目经理判断是否继续设计变更
     */
    @RequestMapping(value = "managerDesignChange")
    public String managerDesignChange(Construction construction, Model model) {
        model.addAttribute("construction", construction);
        return "modules/sg/managementcenter/activiti/managerDesignChange";
    }

    /**
     * 项目经理判定是否关闭
     */
    @RequestMapping(value = "coveredForm")
    public String coveredForm(Construction construction, Model model) {
        model.addAttribute("construction", construction);
        return "modules/sg/managementcenter/activiti/coveredForm";
    }

    /**
     * 配网工程专职判定是否关闭
     */
    @RequestMapping(value = "sealForm")
    public String sealForm(Construction construction, Model model) {
        model.addAttribute("construction", construction);
        return "modules/sg/managementcenter/activiti/sealForm";
    }

    /**
     * 配网运行人员判定是否关闭
     */
    @RequestMapping(value = "receiptForm")
    public String receiptForm(Construction construction, Model model) {
        model.addAttribute("construction", construction);
        return "modules/sg/managementcenter/activiti/receiptForm";
    }

    /*
        项目经理
     */
    @RequestMapping(value = "phaseManagerForm")
    public String phaseManagerForm(Construction construction, Model model) {
        model.addAttribute("construction", construction);
        return "modules/sg/managementcenter/activiti/phaseManageForm";
    }

    /**
     * 上传缴费单
     */
    @RequestMapping(value = "singleForm")
    public String singleForm(Construction construction, Model model) {
        model.addAttribute("construction", construction);
        return "modules/sg/managementcenter/activiti/singleForm";
    }

    /**
     * 配网项目经理判定变更或关闭
     */
    @RequestMapping(value = "documentsForm")
    public String documentsForm(Construction construction, Model model) {
        model.addAttribute("construction", construction);
        return "modules/sg/managementcenter/activiti/documentsForm";
    }

    /**
     * 配网系统专职确认系统关闭
     */
    @RequestMapping(value = "confirmClose")
    public String confirmClose(Construction construction, Model model) {
        model.addAttribute("construction", construction);
        return "modules/sg/managementcenter/activiti/confirmClose";
    }

    /**
     * 修改交底结论页面
     */
    @RequestMapping(value = "editCon")
    public String editCon(Construction construction, Model model) {
        model.addAttribute("construction", construction);
        return "modules/sg/managementcenter/activiti/editCon";
    }


    /**
     * 修改工程量页面
     */
    @RequestMapping(value = "editEng")
    public String editEng(Construction construction, Model model) {
        Quantity quantity = construction.getQuantity();
        if (construction.getQuantity() != null) {
            if (construction.getQuantity().getProcessingType() != null && construction.getQuantity().getProcessingType() != "") {
                String processingType = construction.getQuantity().getProcessingType();
                String[] split = processingType.split(",");
                List<String> processList = new ArrayList<>();
                for (int i = 0; i < split.length; i++) {
                    String s = split[i].toString();
                    processList.add(s);
                }
                construction.getQuantity().setProcessingTypeList(processList);
            }
        }
        List<String> courseList = new ArrayList<String>();
        courseList.add("行政政处");
        courseList.add("农村政处");
        courseList.add("民事政处");
        model.addAttribute("courseList", courseList);
        model.addAttribute("construction", construction);
        MaterialInfo materialInfo = new MaterialInfo();
        materialInfo.setProjectName(construction.getReserveProjectName());
        List<MaterialInfo> list = materialInfoService.findList(materialInfo);
        if (list.size()>0){
        Integer count = 0;
        for (MaterialInfo m : list) {
            String materialName = m.getMaterialName();
            if (materialName != null && materialName != "") {
                if (materialName.equals("FTU,三遥数量")) {
                    count += 1;
                }
                if (materialName.equals("FTU,二遥数量")) {
                    count += 1;
                }
                if (materialName.equals("DTU,三遥,遮蔽立式数量")) {
                    count += 1;
                }
                if (materialName.equals("DTU,三遥,户外立式数量")) {
                    count += 1;
                }
                if (materialName.equals("DTU,三遥,组屏式数量")) {
                    count += 1;
                }
                if (materialName.equals("一二次融合成套环网箱（2进2出）数量")) {
                    count += 1;
                }
                if (materialName.equals("一二次融合成套柱上负荷开关（户外）数量")) {
                    count += 1;
                }
                if (null == construction.getQuantity()) {
                    construction.setQuantity(new Quantity());
                }
                if (count > 0) {
                    construction.getQuantity().setIncludeAutomation("是");
                } else {
                    construction.getQuantity().setIncludeAutomation("否");
                }

            }
        }
        }
        return "modules/sg/managementcenter/activiti/editEng";
    }

    /**
     * 交底:运行人员审核页面
     */
    @RequestMapping(value = "humanReview")
    public String humanReview(Construction construction, Model model) {

        MyImportUtils.getTheEcho(construction, model);
        model.addAttribute("construction", construction);
        return "modules/sg/managementcenter/activiti/humanReview";
    }

    /**
     * 导入材料表及拆旧表
     */
    @RequestMapping(value = "importTable")
    public String importTable(Construction construction, Model model) {
        model.addAttribute("construction", construction);
        return "modules/sg/managementcenter/activiti/importTable";
    }

    /**
     * 填写部分工程量信息
     */
    @RequestMapping(value = "engineering")
    public String engineering(Construction construction, Model model) {
        //获取项目的所有的领料数据
        MaterialInfo materialInfo = new MaterialInfo();
        materialInfo.setProjectName(construction.getReserveProjectName());
        List<MaterialInfo> list = materialInfoService.findList(materialInfo);
        Integer ftuThree = 0;
        Integer ftuTwo = 0;
        Integer dtuVertical = 0;
        Integer dtuOutdoor = 0;
        Integer dtuGroup = 0;
        Integer ringCages = 0;
        Integer poleMounted = 0;
        for (MaterialInfo m : list) {
            String materialName = m.getExtendDescription();
            if (materialName != null && materialName != "") {
                if (materialName.contains("FTU,三遥")) {
                    ftuThree += 1;
                }
                if (materialName.contains("FTU,二遥")) {
                    ftuTwo += 1;
                }
                if (materialName.contains("DTU,三遥,遮蔽立式")) {
                    dtuVertical += 1;
                }
                if (materialName.contains("DTU,三遥,户外立式")) {
                    dtuOutdoor += 1;
                }
                if (materialName.contains("DTU,三遥,组屏式")) {
                    dtuGroup += 1;
                }
                if (materialName.contains("一二次融合成套环网箱（2进2出）")) {
                    ringCages += 1;
                }
                if (materialName.contains("一二次融合成套柱上负荷开关（户外）")) {
                    poleMounted += 1;
                }
                construction.setFtuThree(ftuThree.toString());
                construction.setFtuTwo(ftuTwo.toString());
                construction.setDtuVertical(dtuVertical.toString());
                construction.setDtuOutdoor(dtuOutdoor.toString());
                construction.setDtuGroup(dtuGroup.toString());
                construction.setRingCages(ringCages.toString());
                construction.setPoleMounted(poleMounted.toString());
            }
        }
        model.addAttribute("construction", construction);
        return "modules/sg/managementcenter/activiti/engineering";
    }

    /**
     * 农村政处开始页面
     */
    @RequestMapping(value = "ruralOffice")
    public String ruralOffice(Construction construction, Model model) {
        model.addAttribute("construction", construction);
        return "modules/sg/managementcenter/activiti/ruralOffice";
    }

    /**
     * 农村专职判断
     */
    @RequestMapping(value = "ruralJudge")
    public String ruralJudge(Construction construction, Model model) {
        model.addAttribute("construction", construction);
        return "modules/sg/managementcenter/activiti/ruralJudge";
    }

    /**
     * 农村上传文件
     */
    @RequestMapping(value = "ruralFiles")
    public String ruralFiles(Construction construction, Model model) {
        model.addAttribute("construction", construction);
        return "modules/sg/managementcenter/activiti/ruralFiles";
    }

    /**
     * 农村是否借款
     */
    @RequestMapping(value = "ruralLoan")
    public String ruralLoan(Construction construction, Model model) {
        model.addAttribute("construction", construction);
        return "modules/sg/managementcenter/activiti/ruralLoan";
    }

    /**
     * 农村是否支付
     */
    @RequestMapping(value = "ruralPays")
    public String ruralPays(Construction construction, Model model) {
        model.addAttribute("construction", construction);
        return "modules/sg/managementcenter/activiti/ruralPays";
    }

    /**
     * 行政政处开始页面
     */
    @RequestMapping(value = "administrativeOffice")
    public String administrativeOffice(Construction construction, Model model) {
        model.addAttribute("construction", construction);
        return "modules/sg/managementcenter/activiti/ruralOffice";
    }

    /**
     * 行政专职判断
     */
    @RequestMapping(value = "administrativeJudge")
    public String administrativeJudge(Construction construction, Model model) {
        model.addAttribute("construction", construction);
        return "modules/sg/managementcenter/activiti/ruralJudge";
    }

    /**
     * 行政上传文件
     */
    @RequestMapping(value = "administrativeFiles")
    public String administrativeFiles(Construction construction, Model model) {
        model.addAttribute("construction", construction);
        return "modules/sg/managementcenter/activiti/ruralFiles";
    }

    /**
     * 行政是否借款
     */
    @RequestMapping(value = "administrativeLoan")
    public String administrativeLoan(Construction construction, Model model) {
        model.addAttribute("construction", construction);
        return "modules/sg/managementcenter/activiti/ruralLoan";
    }

    /**
     * 行政是否支付
     */
    @RequestMapping(value = "administrativePays")
    public String administrativePays(Construction construction, Model model) {
        model.addAttribute("construction", construction);
        return "modules/sg/managementcenter/activiti/ruralPays";
    }

    /**
     * 民事政处开始页面
     */
    @RequestMapping(value = "civilOffice")
    public String civilOffice(Construction construction, Model model) {
        model.addAttribute("construction", construction);
        return "modules/sg/managementcenter/activiti/ruralOffice";
    }

    /**
     * 民事专职判断
     */
    @RequestMapping(value = "civilJudge")
    public String civilJudge(Construction construction, Model model) {
        model.addAttribute("construction", construction);
        return "modules/sg/managementcenter/activiti/ruralJudge";
    }

    /**
     * 民事上传文件
     */
    @RequestMapping(value = "civilFiles")
    public String civilFiles(Construction construction, Model model) {
        model.addAttribute("construction", construction);
        return "modules/sg/managementcenter/activiti/ruralFiles";
    }

    /**
     * 民事是否借款
     */
    @RequestMapping(value = "civilLoan")
    public String civilLoan(Construction construction, Model model) {
        model.addAttribute("construction", construction);
        return "modules/sg/managementcenter/activiti/ruralLoan";
    }

    /**
     * 民事是否支付
     */
    @RequestMapping(value = "civilPays")
    public String civilPays(Construction construction, Model model) {
        model.addAttribute("construction", construction);
        return "modules/sg/managementcenter/activiti/ruralPays";
    }

    /**
     * 是否需要民事政处
     */
    @RequestMapping(value = "needCivilOffice")
    public String needCivilOffice(Construction construction, Model model) {
        model.addAttribute("construction", construction);
        return "modules/sg/managementcenter/activiti/needCivilOffice";
    }

    /**
     * 是否需要行政政处
     */
    @RequestMapping(value = "needAdministrativeOffice")
    public String needAdministrativeOffice(Construction construction, Model model) {
        model.addAttribute("construction", construction);
        return "modules/sg/managementcenter/activiti/needAdministrativeOffice";
    }

    /**
     * 是否需要农村政处
     */
    @RequestMapping(value = "needRuralOffice")
    public String needRuralOffice(Construction construction, Model model) {
        model.addAttribute("construction", construction);
        return "modules/sg/managementcenter/activiti/needRuralOffice";
    }

    /**
     * 土建工程量数据列表
     */
    @ResponseBody
    @RequestMapping(value = "engineeringTable")
    public Map<String, Object> engineeringTable(EngineeringAmount engineeringAmount, HttpServletRequest request, HttpServletResponse response, Model model) {
        Page<EngineeringAmount> page = constructionService.engineeringTable(new Page<EngineeringAmount>(request, response), engineeringAmount);
        return getBootstrapData(page);
    }

    /**
     * 其它工程量数据列表
     */
    @ResponseBody
    @RequestMapping(value = "otherTable")
    public Map<String, Object> otherTable(OtherAmount otherAmount, HttpServletRequest request, HttpServletResponse response, Model model) {
        Page<OtherAmount> page = constructionService.otherTable(new Page<OtherAmount>(request, response), otherAmount);
        return getBootstrapData(page);
    }


    /**
     * 土建工程量修改页面
     */
    @RequestMapping(value = "editEngAmount")
    public String editEngAmount(EngineeringAmount engineeringAmount, Model model) {
        if (!"".equals(engineeringAmount.getId()) && engineeringAmount.getId() != null) {
            engineeringAmount = constructionService.getEngAmount(engineeringAmount);
        }
        model.addAttribute("engineeringAmount", engineeringAmount);
        return "modules/sg/managementcenter/activiti/editEngAmount";
    }

    /**
     * 其它工程量修改页面
     */
    @RequestMapping(value = "editOther")
    public String editOther(OtherAmount otherAmount, Model model) {
        if (!"".equals(otherAmount.getId()) && otherAmount.getId() != null) {
            otherAmount = constructionService.getOtherAmount(otherAmount);
        }
        model.addAttribute("otherAmount", otherAmount);
        return "modules/sg/managementcenter/activiti/editOther";
    }


    /**
     * 政策超权限处理选择页面
     */
    @RequestMapping(value = "advancePolicy")
    public String advancePolicy(Construction construction, Model model) {
        model.addAttribute("construction", construction);
        return "modules/sg/managementcenter/activiti/advancePolicy";
    }

    /**
     * 土建工程量添加，修改
     */
    @ResponseBody
    @RequestMapping(value = "EngAmountSave")
    public AjaxJson EngAmountSave(EngineeringAmount engineeringAmount, Model model) throws Exception {
        AjaxJson j = new AjaxJson();
        try {
            constructionService.EngAmountSave(engineeringAmount);
            j.setSuccess(true);
            j.setMsg("修改成功");
        } catch (Exception e) {
            j.setSuccess(false);
            j.setMsg("修改失败");
        }
        return j;
    }

    /**
     * 其它工程量添加，修改
     */
    @ResponseBody
    @RequestMapping(value = "addOther")
    public AjaxJson addOther(OtherAmount otherAmount, Model model) throws Exception {
        AjaxJson j = new AjaxJson();
        try {
            constructionService.addOther(otherAmount);
            j.setSuccess(true);
            j.setMsg("修改成功");
        } catch (Exception e) {
            j.setSuccess(false);
            j.setMsg("修改失败");
        }
        return j;
    }

    /**
     * 土建工程量删除
     */
    @ResponseBody
    @RequestMapping(value = "delEngAmount")
    public AjaxJson delEngAmount(String id) {
        AjaxJson j = new AjaxJson();
        constructionService.delEngAmount(id);
        j.setMsg("删除工程量成功");
        return j;
    }

    /**
     * 其它工程量删除
     */
    @ResponseBody
    @RequestMapping(value = "delOtherAmount")
    public AjaxJson delOtherAmount(String id) {
        AjaxJson j = new AjaxJson();
        constructionService.delOtherAmount(id);
        j.setMsg("删除工程量成功");
        return j;
    }

    /**
     * 下载施工交底模板文件
     */
    @RequestMapping(value = "excelOut")
    public void excelStandardTemplateOut(HttpServletRequest request,
                                         HttpServletResponse response) throws IOException {
        String fileName = "disclose.xlsx";
        String filePath = getClass().getResource("/freemarker/" + fileName).getPath();
        File f = new File(filePath);
        // 设置response参数，可以打开下载页面
        response.reset();
        response.setContentType("application/vnd.ms-excel;charset=utf-8");
        try {
            response.setHeader("Content-Disposition", "attachment;filename=" + new String(("交底结论模板" + ".xlsx").getBytes(), "iso-8859-1"));//下载文件的名称
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        ServletOutputStream out = response.getOutputStream();
        BufferedInputStream bis = null;
        BufferedOutputStream bos = null;
        try {
            bis = new BufferedInputStream(new FileInputStream(f));
            bos = new BufferedOutputStream(out);
            byte[] buff = new byte[2048];
            int bytesRead;
            while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
                bos.write(buff, 0, bytesRead);
            }
        } catch (final IOException e) {
            throw e;
        } finally {
            if (bis != null)
                bis.close();
            if (bos != null)
                bos.close();
        }
    }

    /**
     * 下载工程量模板文件
     */
    @RequestMapping(value = "excelQuantity")
    public void excelOutQuantity(HttpServletRequest request,
                                 HttpServletResponse response) throws IOException {
        String fileName = "quantity.xlsx";
        String filePath = getClass().getResource("/freemarker/" + fileName).getPath();
        File f = new File(filePath);
        // 设置response参数，可以打开下载页面
        response.reset();
        response.setContentType("application/vnd.ms-excel;charset=utf-8");
        try {
            response.setHeader("Content-Disposition", "attachment;filename=" + new String(("工程量模板" + ".xlsx").getBytes(), "iso-8859-1"));//下载文件的名称
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        ServletOutputStream out = response.getOutputStream();
        BufferedInputStream bis = null;
        BufferedOutputStream bos = null;
        try {
            bis = new BufferedInputStream(new FileInputStream(f));
            bos = new BufferedOutputStream(out);
            byte[] buff = new byte[2048];
            int bytesRead;
            while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
                bos.write(buff, 0, bytesRead);
            }
        } catch (final IOException e) {
            throw e;
        } finally {
            if (bis != null)
                bis.close();
            if (bos != null)
                bos.close();
        }
    }

    /**
     * 发起施工交底流程
     */
    @ResponseBody
    @RequestMapping(value = "save")
    public AjaxJson save(Construction construction, Model model) throws Exception {
        AjaxJson j = new AjaxJson();
        /**
         * 后台hibernate-validation插件校验
         */
        String errMsg = beanValidator(construction);
        if (StringUtils.isNotBlank(errMsg)) {
            j.setSuccess(false);
            j.setMsg(errMsg);
            return j;
        }
        /**
         * 流程审批
         */
        if (StringUtils.isBlank(construction.getId())) {
            //获取流程图id
            String procDefId = construction.getAct().getProcDefId();
            //通过id获取项目暂定名称
            //用于记录未发起的流程原因
            String info = "";
            //定义vars用于指派流程走向
            Map<String, Object> vars = Maps.newHashMap();
            //获取选择的项目
            String reserveProjectName = construction.getReserveProjectName();
            //根据，分割得到选择项目的id数组
            String[] proListId = reserveProjectName.split(",");
            //根据数组查询得到项目信息
            List<Project> listById = projectService.findListById(proListId);
            //循环项目信息
            for (Project each : listById) {
                if (each.getAssignment() == null) {
                    info += "<" + each.getReserveProjectName() + ">" + "未填写施工任务分配信息\t";
                    continue;
                }
                //查询是否有此配网项目经理人员（表中暂无配网项目经理人员信息）
                User user = constructionService.queryPerson(each.getAssignment().getConstructionManage());
                //查询是否有此用户
                if (user != null) {
                    //有此用户
                    vars.put("design", user.getLoginName());
                    construction.setReserveProjectName(each.getReserveProjectName());
                    constructionService.newSave(construction);//保存
                    //根据储备项目暂定名称修改项目状态
                    constructionService.updateStatus(construction.getReserveProjectName());
                    // 启动流程
                    ProcessDefinition p = actProcessService.getProcessDefinition(construction.getAct().getProcDefId());
                    String title = construction.getCurrentUser().getName() + "在" + DateUtils.getDateTime() + "发起" + p.getName();
                    actTaskService.startProcessNew(p.getKey(), "xm_construction_clarificaiton", construction.getId(), title, vars);
                } else {
                    //没有此用户
                    info += ("项目：" + each.getReserveProjectName() + "没有此项目经理，请核实。");
                    continue;
                }
            }
            //新增或编辑表单保存
            j.setMsg("发起流程审批成功!" + info);
            j.getBody().put("targetUrl", "/act/task/process/");
        }
        return j;
    }

    @ResponseBody
    @RequestMapping(value = "editConSave")
    public AjaxJson editConSave(Construction construction, Model model) throws Exception {
        AjaxJson j = new AjaxJson();
        try {
            List<Construction> constructionList = new ArrayList<>();
            constructionList.add(construction);
            constructionService.replaceDisclose(constructionList);
            j.setSuccess(true);
            j.setMsg("修改成功");
        } catch (Exception e) {
            j.setSuccess(false);
            j.setMsg("修改失败");
        }
        return j;
    }

    @ResponseBody
    @RequestMapping(value = "engSave")
    public AjaxJson engSave(Construction construction, Model model) throws Exception {
        AjaxJson j = new AjaxJson();
        List<String> processingTypeList = construction.getQuantity().getProcessingTypeList();
        String processType = "";
        for (int i = 0; i < processingTypeList.size(); i++) {
            processType += processingTypeList.get(i) + ",";
        }
        if (construction.getQuantity().getPolicyIssues().equals("是")) {
            construction.getQuantity().setProcessingType(processType);
        } else {
            construction.getQuantity().setProcessingType("");
            construction.getQuantity().setProcessingDescription("");
        }
        construction.getQuantity().setReserveProjectName(construction.getReserveProjectName());
        try {
            List<Construction> constructionList = new ArrayList<>();
            constructionList.add(construction);
            constructionService.quantityInsert(constructionList);
            j.setSuccess(true);
            j.setMsg("修改成功");
        } catch (Exception e) {
            j.setSuccess(false);
            j.setMsg("修改失败");
        }
        return j;
    }


    @ResponseBody
    @RequestMapping(value = "importDisclose")
    public AjaxJson importDisclose(@RequestParam("file") MultipartFile file, HttpServletResponse response, HttpServletRequest request) {
        AjaxJson j = new AjaxJson();
        int successNum = 0;
        String failureMsg = "";
        List<Construction> constructionList = new ArrayList<>();
        Construction construction;
        //获取当前登陆用户所有在《交底:项目经理组织交底》节点的流程
        List<Construction> activityList = MyActiviUtils.findActivity("交底:项目经理交底内容");
        //读取excel文件数据
        try {
            ImportExcel ei = new ImportExcel(file, 0, 0);
            Disclose disclose;
            int lastDataRowNum = ei.getLastDataRowNum();
            for (int i = 3; i <= lastDataRowNum; i++) {
                construction = new Construction();
                disclose = new Disclose();
                Row row = ei.getRow(i);
                String reserveProjectName = ei.getCellValue(row, 0).toString();
                if ("".equals(reserveProjectName) || null == reserveProjectName) {
                    continue;
                }
                construction.setReserveProjectName(reserveProjectName);
                //是否已实施
                disclose.setHasImplemented(ei.getCellValue(row, 1).toString());
                //现场情况描述
                disclose.setSceneDescription(ei.getCellValue(row, 2).toString());
                //是否有实施必要性
                disclose.setIsImplement(ei.getCellValue(row, 3).toString());
                //实施无必要描述
                disclose.setNoImplementation(ei.getCellValue(row, 4).toString());
                //图纸是否完整
                disclose.setWhetherComplete(ei.getCellValue(row, 5).toString());
                //图纸完整性描述
                disclose.setDrawingDescription(ei.getCellValue(row, 6).toString());
                //图纸是否规范
                disclose.setWhetherStandard(ei.getCellValue(row, 7).toString());
                //图纸规范性描述
                disclose.setNormativeDrawings(ei.getCellValue(row, 8).toString());
                //是否存在典设图问题
                disclose.setWhetherDrawing(ei.getCellValue(row, 9).toString());
                //典设图问题描述
                disclose.setProblemDescription(ei.getCellValue(row, 10).toString());
                //是否存在施工通道
                disclose.setWhetherChannel(ei.getCellValue(row, 11).toString());
                //施工通道情况描述
                disclose.setConstructionDescription(ei.getCellValue(row, 12).toString());
                //土建是否需要调整
                disclose.setCivilAdjusted(ei.getCellValue(row, 13).toString());
                //土建方案变更内容描述
                disclose.setDescriptionPlans(ei.getCellValue(row, 14).toString());
                //土建工作量调整内容描述
                disclose.setDescriptionAdjustment(ei.getCellValue(row, 15).toString());
                //电气方案是否需要调整
                disclose.setElectricalAdjusted(ei.getCellValue(row, 16).toString());
                //调整原因描述
                disclose.setAdjustmentDescription(ei.getCellValue(row, 17).toString());
                //自动化是否需要变更
                disclose.setDoesChange(ei.getCellValue(row, 18).toString());
                //自动化方案调整内容
                disclose.setAutomatedContent(ei.getCellValue(row, 19).toString());
                //自动化工作内容调整
                disclose.setAutomatedAdjustment(ei.getCellValue(row, 20).toString());
                //其他方案是否需要调整
                disclose.setOtherAdjusted(ei.getCellValue(row, 21).toString());
                //其他方案调整原因描述
                disclose.setDescriptionReasons(ei.getCellValue(row, 22).toString());
                //是否存在难以解决的政处
                disclose.setDifficultResolve(ei.getCellValue(row, 233).toString());
                //是否需要进行设计变更
                disclose.setDesignChanges(ei.getCellValue(row, 24).toString());
                //是否需要进行项目关闭
                disclose.setNeedsClosed(ei.getCellValue(row, 25).toString());
                //政处问题描述
                disclose.setAffairsDescription(ei.getCellValue(row, 26).toString());
                //是否需要规划报批（150米及以上土建）
                disclose.setPlanningRequired(ei.getCellValue(row, 27).toString());
                //是否涉及高铁、高速
                disclose.setHighSpeed(ei.getCellValue(row, 28).toString());
                //是否存在复杂民事政处
                disclose.setAffairsOffice(ei.getCellValue(row, 29).toString());
                //图纸方案是否存在前置条件
                disclose.setPreconditions(ei.getCellValue(row, 30).toString());
                //前置条件描述
                disclose.setPreconditionDescription(ei.getCellValue(row, 31).toString());
                //是否需要定制物资
                disclose.setCustomizedMaterials(ei.getCellValue(row, 32).toString());
                //是否能定制
                disclose.setCustomizedCan(ei.getCellValue(row, 33).toString());
                //定制原因描述
                disclose.setReasonDescription(ei.getCellValue(row, 34).toString());
                //定制物资描述
                disclose.setMaterialDescription(ei.getCellValue(row, 35).toString());
                //拆旧物资是否与设计一致
                disclose.setDemolitionMaterials(ei.getCellValue(row, 36).toString());
                //型号不一致描述
                disclose.setModelDescription(ei.getCellValue(row, 37).toString());
                //数量不一致描述
                disclose.setQuantityDescription(ei.getCellValue(row, 38).toString());
                //图纸标注是否存在问题
                disclose.setDrawingAnnotation(ei.getCellValue(row, 39).toString());
                //图纸标注问题描述
                disclose.setDrawingProblem(ei.getCellValue(row, 40).toString());
                //是否存在停电问题
                disclose.setPowerOutage(ei.getCellValue(row, 41).toString());
                //停电问题问题描述
                disclose.setPowerProblem(ei.getCellValue(row, 42).toString());
                //是否邻近带电线路
                disclose.setNearLiveLine(ei.getCellValue(row, 43).toString());
                //是否下穿高压线路
                disclose.setHighVoltageLine(ei.getCellValue(row, 44).toString());
                //是否存在复杂管线
                disclose.setComplexPipeline(ei.getCellValue(row, 45).toString());
                //是否涉及复杂停电
                disclose.setComplicatedPower(ei.getCellValue(row, 46).toString());
                construction.setDisclose(disclose);
                constructionList.add(construction);
            }
            //比对当前节点可以导入交底结论的信息
            List<Construction> criteriaList = new ArrayList<>();
            for (Construction c : activityList) {
                for (Construction n : constructionList) {
                    if (c.getReserveProjectName().equals(n.getReserveProjectName())) {
                        criteriaList.add(n);
                    }
                }
            }

            //进行数据验证
            Map<String, Object> stringObjectMap = MyImportUtils.errorTips(criteriaList);
            String fin = (String) stringObjectMap.get("fin");
            List<Construction> sendList = new ArrayList<>();
            List<Construction> insertList = (List<Construction>) stringObjectMap.get("newConList");
            if (insertList.size() > 0) {
                for (Construction c : insertList) {
                    for (Construction n : activityList) {
                        if (c.getReserveProjectName().equals(n.getReserveProjectName())) {
                            sendList.add(n);
                            c.getAct().setProcInsId(n.getProcInsId());
                        }
                    }
                }
                /*导入符合条件的交底结论信息*/
                constructionService.replaceDisclose(insertList);
                Map<String, Object> vars = Maps.newHashMap();
                for (Construction c : sendList) {
                    String instituteRole = c.getAssignment().getInspectionUnit();
                    vars.put("problem", true);
                    vars.put("design", UserUtils.getByUserName(instituteRole).getLoginName());
                    actTaskService.complete(c.getAct().getTaskId(), c.getAct().getProcInsId(), "系统判断成功，请自行查看", vars);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return j;
    }

    /**
     * 文件管理列表数据
     */
    @ResponseBody
    @RequestMapping(value = "uploadData")
    public Map<String, Object> uploadData(UploadImages uploadImages, HttpServletRequest request, HttpServletResponse response, Model model, String procInsId) {
        if (procInsId != null && procInsId != "") {
            uploadImages.setProcInsId(procInsId);
        }
        //查询出所有的附件信息
        Page<UploadImages> page = constructionService.findUploadPage(new Page<UploadImages>(request, response), uploadImages);
        //当判定系统为linux的时候
        if (Global.SYS_TYPE.equals("2")) {
            List<UploadImages> list = page.getList();
            for (UploadImages upload :
                    list) {
                String a = "";
                String path = upload.getPath();
                String[] split = path.split("\\|");
                for (int i = 0; i < split.length; i++) {
                    a += "http://" + request.getServerName() + split[i] + "|";
                }
                upload.setPath(a);
            }
        }
        List<UploadImages> list1 = page.getList();
        for (UploadImages images : list1) {
            String imgName = images.getImgName();
            boolean anInt = this.isInt(imgName);
            if (anInt) {
                String dictLabels = DictUtils.getDictLabel(imgName, "uploadFileType", "");
                images.setImgName(dictLabels);
            }
        }
        List<UploadImages> list = page.getList();
        //循环list
        return getBootstrapData(page);
    }

    public boolean isInt(String s)
    {
        try
        {
            int i = Integer.parseInt(s);
            return true;
        }
        catch(Exception _ex)
        {
            return false;
        }
    }

    /**
     * 导入物料表
     */
    @ResponseBody
    @RequestMapping(value = "btnMaterial")
    public AjaxJson btnMaterial(MultipartFile file, HttpServletResponse response, HttpServletRequest request) throws IOException, InvalidFormatException {
        AjaxJson j = new AjaxJson();
        ImportExcel mo = new ImportExcel(file, 1, "模块表");
        ImportExcel importExcel = new ImportExcel(file, 1, "领料清单");
        Row row = mo.getRow(0);
        String projectNam1 = (String) mo.getCellValue(row, 1);
        String projectName = projectNam1.trim();
        materialInfoService.deleteByPro(projectName);
        List<MaterialInfo> materialInfos = MaterialInfoUtil.getData(importExcel, projectName);   //sheet页数据
        List<MaterialInfo> list = MaterialInfoUtil.combineData(materialInfos);      //合并后数据
        materialInfoService.saveList(list);
        j.setSuccess(true);
        j.setMsg("插入成功");
        return j;
    }

    /**
     * 导入工程量
     */
    @ResponseBody
    @RequestMapping(value = "importQuantity")
    public AjaxJson importQuantity(MultipartFile file, HttpServletResponse response, HttpServletRequest request) throws IOException, InvalidFormatException {
        AjaxJson j = new AjaxJson();
        List<Construction> constructionList = new ArrayList<>();
        Construction construction;
        Boolean can = true;
        String flag = "";
        String allFlag = "";
        try {
            ImportExcel ei = new ImportExcel(file, 0, 0);
            int lastDataRowNum = ei.getLastDataRowNum();
            for (int i = 4; i <= lastDataRowNum; i++) {
                Quantity quantity = new Quantity();
                construction = new Construction();
                Row row = ei.getRow(i);
                quantity.setReserveProjectName(ei.getCellValue(row, 0).toString());
                //quantity.setIncludeAutomation(ei.getCellValue(row, 1).toString());

                quantity.setWayOf(ei.getCellValue(row, 2).toString());
                quantity.setAssignmentStyle(ei.getCellValue(row, 3).toString());
                quantity.setOperationSubstation(ei.getCellValue(row, 4).toString());
                quantity.setNamingNumber(ei.getCellValue(row, 5).toString());
                quantity.setEngineeringAcceptance(ei.getCellValue(row, 6).toString());
                quantity.setElectricalAcceptance(ei.getCellValue(row, 7).toString());
                quantity.setBlackoutLine(ei.getCellValue(row, 8).toString());
                quantity.setOutageRange(ei.getCellValue(row, 9).toString());
                quantity.setPolicyIssues(ei.getCellValue(row, 10).toString());
                quantity.setProcessingType(ei.getCellValue(row, 11).toString());
                quantity.setProcessingDescription(ei.getCellValue(row, 12).toString());
                construction.setQuantity(quantity);
//                String includeAutomation = quantity.getIncludeAutomation();
                String includeAutomation = "";
                String wayOf = quantity.getWayOf();
                String assignmentStyle = quantity.getAssignmentStyle();
                String operationSubstation = quantity.getOperationSubstation();
                String namingNumber = quantity.getNamingNumber();
                String engineeringAcceptance = quantity.getEngineeringAcceptance();
                String electricalAcceptance = quantity.getElectricalAcceptance();
                String policyIssues = quantity.getPolicyIssues();
                String processingType = quantity.getProcessingType();
                String processingDescription = quantity.getProcessingDescription();

                MaterialInfo materialInfo = new MaterialInfo();
                materialInfo.setProjectName(construction.getReserveProjectName());
                List<MaterialInfo> list = materialInfoService.findList(materialInfo);
                Integer count = 0;
                for (MaterialInfo m : list) {
                    String materialName = m.getMaterialName();
                    if (materialName != null && materialName != "") {
                        if (materialName.equals("FTU,三遥数量")) {
                            count += 1;
                        }
                        if (materialName.equals("FTU,二遥数量")) {
                            count += 1;
                        }
                        if (materialName.equals("DTU,三遥,遮蔽立式数量")) {
                            count += 1;
                        }
                        if (materialName.equals("DTU,三遥,户外立式数量")) {
                            count += 1;
                        }
                        if (materialName.equals("DTU,三遥,组屏式数量")) {
                            count += 1;
                        }
                        if (materialName.equals("一二次融合成套环网箱（2进2出）数量")) {
                            count += 1;
                        }
                        if (materialName.equals("一二次融合成套柱上负荷开关（户外）数量")) {
                            count += 1;
                        }
                        if (count > 0) {
                            includeAutomation = "是";
                        } else {
                            includeAutomation = "否";
                        }

                    }
                }

                can = true;
                flag = "";
                if ("".equals(includeAutomation)) {
                    flag += "是否含自动化不能为空\t";
                    can = false;
                } else {
                    if ("是".equals(includeAutomation)) {
                        if ("".equals(wayOf)) {
                            flag += "通信方式不能为空\t";
                            can = false;
                        } else if (!"公网".equals(wayOf)
                                && !"专网".equals(wayOf)
                                && !"光纤".equals(wayOf)
                                && !"混合".equals(wayOf)) {
                            flag += "通信方式填写有误\t";
                            can = false;
                        }
                    }
                }
                if ("".equals(assignmentStyle)) {
                    flag += "作业方式不能为空\t";
                    can = false;
                } else if (!"停电".equals(assignmentStyle)
                        && !"带电".equals(assignmentStyle)
                        && !"不涉电".equals(assignmentStyle)) {
                    flag += "作业方式填写有误\t";
                    can = false;
                }
                if ("".equals(operationSubstation)) {
                    flag += "是否含变电站新间隔投运不能为空\t";
                    can = false;
                } else if (!"是".equals(operationSubstation) && !"否".equals(operationSubstation)) {
                    flag += "是否含变电站新间隔投运填写有误\t";
                    can = false;
                }
                if ("".equals(namingNumber)) {
                    flag += "是否需调整命名编号不能为空\t";
                    can = false;
                } else if (!"是".equals(namingNumber) && !"否".equals(namingNumber)) {
                    flag += "是否需调整命名编号填写有误\t";
                    can = false;
                }
                if ("".equals(engineeringAcceptance)) {
                    flag += "是否存在土建验收不能为空\t";
                    can = false;
                } else if (!"是".equals(engineeringAcceptance) && !"否".equals(engineeringAcceptance)) {
                    flag += "是否存在土建验收填写有误\t";
                    can = false;
                }
                if ("".equals(electricalAcceptance)) {
                    flag += "是否存在电气验收不能为空\t";
                    can = false;
                } else if (!"是".equals(electricalAcceptance) && !"否".equals(electricalAcceptance)) {
                    flag += "是否存在电气验收填写有误\t";
                    can = false;
                }
                if ("".equals(policyIssues)) {
                    flag += "是否存在政策处理问题不能为空\t";
                    can = false;
                } else if (!"是".equals(electricalAcceptance) && !"否".equals(electricalAcceptance)) {
                    flag += "是否存在政策处理问题填写有误\t";
                    can = false;
                }
                if ("是".equals(policyIssues)) {
                    if ("".equals(processingType)) {
                        flag += "政策处理类型不能为空\t";
                        can = false;
                    } else {
                        String[] split = processingType.split(",");
                        for (String a : split) {
                            if ("行政政处".equals(a) || "农村政处".equals(a) || "民事政处".equals(a)) {

                            } else {
                                flag += "政策处理类型填写有误\t";
                                can = false;
                            }
                        }
                    }
                    if ("".equals(processingDescription)) {
                        flag += "政策处理描述不能为空\t";
                        can = false;
                    }
                } else {
                    construction.getQuantity().setProcessingType("");
                    construction.getQuantity().setProcessingDescription("");
                }
                if (can) {
                    constructionList.add(construction);
                } else {
                    allFlag += "<" + quantity.getReserveProjectName() + ">" + flag + "\n";
                }
            }
            if (constructionList.size() > 0) {
                constructionService.quantityInsert(constructionList);
            }
        } catch (Exception e) {
            j.setSuccess(false);
            j.setMsg(e.getMessage());
        }
        j.setSuccess(true);
        j.setMsg("插入成功" + allFlag);
        return j;
    }

    /**
     * 政策超权限处理
     */
    @ResponseBody
    @RequestMapping(value = "policySave")
    public AjaxJson policySave(Construction construction, Model model) throws Exception {
        AjaxJson j = new AjaxJson();
        /**
         * 后台hibernate-validation插件校验
         */
        String errMsg = beanValidator(construction);
        if (StringUtils.isNotBlank(errMsg)) {
            j.setSuccess(false);
            j.setMsg(errMsg);
            return j;
        }
        /**
         * 流程审批
         */
        if (StringUtils.isBlank(construction.getId())) {
            if ("".equals(construction.getProjectId())) {
                j.setSuccess(false);
                j.setMsg("请选择项目");
                return j;
            }
            //更改项目的政策处理状态
            constructionService.updatePolicyStatus(construction.getProjectName(), "2");
            //根据项目名称查询项目状态及信息
            Project byName = projectService.findByName(construction.getProjectName());
            ShowList showList = new ShowList();
            String projectId = byName.getProjectId();
            String projectName = byName.getProjectName();
            String reserveProjectName = byName.getReserveProjectName();
            if (!"".equals(projectId) && !"".equals(projectName)) {
                String acquisitionStatus = byName.getAcquisitionStatus();
                if ("0".equals(acquisitionStatus)) {
                    showList.setTheNumber("1");
                    showList.setProjectName(projectName);
                    showList.setReserveProjectName(reserveProjectName);
                    showList.setProjectId(projectId);
                    showListService.updateAcqStatus(reserveProjectName);
                    //保存数据
                    showListService.save(showList);
                    // 启动物资领料流程
                    Map<String, Object> vars = Maps.newHashMap();
                    vars.put("manager", UserUtils.getByUserName(byName.getAssignment().getOwnerManager()).getLoginName());
                    String procDefId = projectService.findDefId("wzll");
                    ProcessDefinition p = actProcessService.getProcessDefinition(procDefId);
                    String title = showList.getCurrentUser().getName() + "在" + DateUtils.getDateTime() + "发起" + p.getName();
                    actTaskService.startProcess(p.getKey(), "md_acquisition_process", showList.getId(), title, vars);
                }
                //判断是否需要发起土建领料流程(是否有土建工程量)
                boolean isEngineering = nonPowerService.findIsEngineering(reserveProjectName);
                if (isEngineering) {
                    if ("0".equals(byName.getAdvanceStatus())) {
                        NonPower nonPower = new NonPower();
                        nonPower.setProjectId(projectId);
                        nonPower.setProjectName(projectName);
                        nonPower.setReserveProjectName(reserveProjectName);
                        //保存土建基本数据
                        nonPowerService.insert(nonPower);
                        //修改项目基础信息土建流程状态
                        projectService.updateAdvanceStart(reserveProjectName, "1");
                        //启动土建流程
                        Map<String, Object> vars2 = Maps.newHashMap();
                        vars2.put("manager", UserUtils.getByUserName(byName.getAssignment().getConstructionManage()).getLoginName());
                        String procDefId2 = projectService.findDefId("tjys");
                        ProcessDefinition p2 = actProcessService.getProcessDefinition(procDefId2);
                        String title2 = nonPower.getCurrentUser().getName() + "在" + DateUtils.getDateTime() + "发起" + p2.getName();
                        actTaskService.startProcess(p2.getKey(), "xm_nonpower_process", nonPower.getId(), title2, vars2);
                    }
                }
                j.setMsg("超权限完成，已自动发送后续流程!");
            } else {
                j.setMsg("超权限完成，请补齐项目定义号及项目名称后自动发送流程");
            }
            // 启动流程
            //定义vars用于指派流程走向
            Map<String, Object> vars = Maps.newHashMap();
            ProcessDefinition p = actProcessService.getProcessDefinition(construction.getAct().getProcDefId());
            String title = construction.getCurrentUser().getName() + "在" + DateUtils.getDateTime() + "发起" + p.getName();
            construction.setId("必要数值id");
            actTaskService.startProcessNew(p.getKey(), "xm_nonpower_process", construction.getId(), title, vars);
            //新增或编辑表单保存

            j.getBody().put("targetUrl", "/act/task/process/");
        }
        return j;
    }

    /**
     * 设计人员审核不通过-修改文件
     */
    @ResponseBody
    @RequestMapping(value = "saveUpload")
    public AjaxJson saveOld(UploadImages uploadImages, Model model, HttpServletRequest request) throws Exception {
        AjaxJson j = new AjaxJson();
        /**
         * 后台hibernate-validation插件校验
         */
        String errMsg = beanValidator(uploadImages);
        if (StringUtils.isNotBlank(errMsg)) {
            j.setSuccess(false);
            j.setMsg(errMsg);
            return j;
        }
        uploadImagesService.saveUpload(uploadImages);
        j.setSuccess(true);
        j.setMsg("保存模块成功");
        return j;
    }

    /**
     *所有政策处理清单，缴费单
     * */
    @ResponseBody
    @RequestMapping(value = "conData")
    public Map<String, Object> conPage(ConstructionUpload constructionUpload, HttpServletRequest request, HttpServletResponse response, Model model) {
        Page<ConstructionUpload> page = uploadImagesService.findConPage(new Page<ConstructionUpload>(request, response), constructionUpload);
        //当判定系统为linux的时候
        if (Global.SYS_TYPE.equals("2")) {
            List<ConstructionUpload> list = page.getList();
            for (ConstructionUpload upload :
                    list) {
                String a = "";
                String path = upload.getProcessingList();
                String[] split = path.split("\\|");
                for (int i = 0; i < split.length; i++) {
                    a += "http://" + request.getServerName() + split[i] + "|";
                }
                upload.setProcessingList(a);

                String b = "";
                String billList = upload.getBillList();
                String[] split1 = path.split("\\|");
                for (int i = 0; i < split1.length; i++) {
                    b += "http://" + request.getServerName() + split[i] + "|";
                }
                upload.setBillList(b);
            }
        }
        return getBootstrapData(page);
    }

    /**
     * 新增项目政策处理方案
     */
    @RequestMapping(value = "conUpdate")
    public String conUpdate(ConstructionUpload constructionUpload, Model model) {
        model.addAttribute("constructionUpload", constructionUpload);
        return "modules/sg/managementcenter/activiti/conUpdate";
    }

    /**
     * 修改交底结论页面
     */
    @RequestMapping(value = "updateConUpload")
    public String updateConUpload(ConstructionUpload constructionUpload, Model model) {
        ConstructionUpload conUpload = uploadImagesService.getConUpload(constructionUpload);
        model.addAttribute("constructionUpload", conUpload);
        return "modules/sg/managementcenter/activiti/updateConUpload";
    }


    @ResponseBody
    @RequestMapping(value = "conUpdateSave")
    public AjaxJson conUpdateSave(ConstructionUpload constructionUpload, Model model) throws Exception {
        AjaxJson j = new AjaxJson();
        try {
            uploadImagesService.conUpdateSave(constructionUpload);
            j.setSuccess(true);
            j.setMsg("修改成功");
        } catch (Exception e) {
            j.setSuccess(false);
            j.setMsg("修改失败");
        }
        return j;
    }

    @ResponseBody
    @RequestMapping(value = "saveConUpload")
    public AjaxJson saveConUpload(ConstructionUpload constructionUpload, Model model) throws Exception {
        AjaxJson j = new AjaxJson();
        try {
            uploadImagesService.updateConUpload(constructionUpload);
            j.setSuccess(true);
            j.setMsg("修改成功");
        } catch (Exception e) {
            j.setSuccess(false);
            j.setMsg("修改失败");
        }
        return j;
    }

    @ResponseBody
    @RequestMapping(value = "delConUpload")
    public AjaxJson delConUpload(ConstructionUpload constructionUpload, Model model) throws Exception {
        AjaxJson j = new AjaxJson();
        try {
            uploadImagesService.delConUpload(constructionUpload);
            j.setSuccess(true);
            j.setMsg("删除成功");
        } catch (Exception e) {
            j.setSuccess(false);
            j.setMsg("删除失败");
        }
        return j;
    }
}