package com.jeeplus.modules.sg.scheduleView.web;

import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.web.BaseController;
import com.jeeplus.modules.sg.managementcenter.activiti.utils.MyActiviUtils;
import com.jeeplus.modules.sg.scheduleView.util.ExportUtil;
import com.jeeplus.modules.sg.scheduleView.util.ScheduleViewUtil;
import com.jeeplus.modules.sg.scheduleView.entity.*;
import com.jeeplus.modules.sg.scheduleView.service.ScheduleViewService;
import org.activiti.engine.history.HistoricActivityInstance;
import org.activiti.engine.task.Task;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.text.SimpleDateFormat;
import java.util.*;

@Controller
@RequestMapping(value = "${adminPath}/scheduleView")
public class ScheduleViewController extends BaseController {
    @Autowired
    private ScheduleViewService scheduleViewService;


    /**
     * 模块查看所有项目信息
     */
    @RequestMapping(value = "allView")
    public String form(ScheduleView scheduleView, Model model) {
        model.addAttribute("scheduleView", scheduleView);
        return "modules/sg/scheduleView/show/scheduleView";
    }

    /**
     * 施工交底项目模块
     */
    @RequestMapping(value = "disView")
    public String disView(ScheduleView scheduleView, Model model) {
        model.addAttribute("scheduleView", scheduleView);
        return "modules/sg/scheduleView/show/disView";
    }

    /**
     * 物资领料模块
     */
    @RequestMapping(value = "recView")
    public String recView(ScheduleView scheduleView, Model model) {
        model.addAttribute("scheduleView", scheduleView);
        return "modules/sg/scheduleView/show/recView";
    }

    /**
     * 土建验收模块
     */
    @RequestMapping(value = "civilView")
    public String civilView(ScheduleView scheduleView, Model model) {
        model.addAttribute("scheduleView", scheduleView);
        return "modules/sg/scheduleView/show/civilView";
    }

    /**
     * 电气验收模块
     */
    @RequestMapping(value = "electricView")
    public String electricView(ScheduleView scheduleView, Model model) {
        model.addAttribute("scheduleView", scheduleView);
        return "modules/sg/scheduleView/show/electricView";
    }

    /**
     * 结算模块
     */
    @RequestMapping(value = "settView")
    public String settView(ScheduleView scheduleView, Model model) {
        model.addAttribute("scheduleView", scheduleView);
        return "modules/sg/scheduleView/show/settView";
    }

    /**
     * 设计进度
     */
    @RequestMapping(value = "designView")
    public String designView(ScheduleView scheduleView, Model model) {
        model.addAttribute("scheduleView", scheduleView);
        return "modules/sg/scheduleView/show/designView";
    }

    /**
     * 项目关闭进度
     */
    @RequestMapping(value = "closureView")
    public String closureView(ScheduleView scheduleView, Model model) {
        model.addAttribute("scheduleView", scheduleView);
        return "modules/sg/scheduleView/show/closureView";
    }

    /**
     * 政策处理进度
     */
    @RequestMapping(value = "policyView")
    public String policyView(ScheduleView scheduleView, Model model) {
        model.addAttribute("scheduleView", scheduleView);
        return "modules/sg/scheduleView/show/policyView";
    }

    /**
     * 所有项目大流程进度
     */
    @ResponseBody
    @RequestMapping(value = "allData")
    public Map<String, Object> useQuantityData(ScheduleView scheduleView, HttpServletRequest request, HttpServletResponse response, Model model) {
        //获取查询的项目定义号
        String projectId = scheduleView.getProjectId();
        String[] projectList = null;
        List<String> searchList = new ArrayList<>();
        if (!projectId.equals("")) {
            //根据空格分割
            projectList = projectId.split("\\s+");
            for (int i = 0; i < projectList.length; i++) {
                searchList.add(projectList[i]);
            }
            scheduleView.setProjectList(searchList);
        }
        //查询所有项目信息
        Page<ScheduleView> scheduleViewPage = scheduleViewService.scheduleProjectAll(new Page<ScheduleView>(request, response), scheduleView);
        List<ScheduleView> list = scheduleViewPage.getList();
        for (ScheduleView c : list) {
            String status = c.getStatus();
            String acquisitionStatus = c.getAcquisitionStatus();
            String constructionStatus = c.getConstructionStatus();
            String settStatus = c.getSettStatus();
            String advanceStatus = c.getAdvanceStatus();
            //对不同流程状态进行判断重新赋值
            if ("0".equalsIgnoreCase(status)) {
                c.setStatus("未发起流程");
            } else if ("1".equalsIgnoreCase(status)) {
                c.setStatus("发起流程中");
            } else {
                c.setStatus("流程结束");
            }

            if ("0".equalsIgnoreCase(acquisitionStatus)) {
                c.setAcquisitionStatus("未发起流程");
            } else if ("1".equalsIgnoreCase(acquisitionStatus)) {
                c.setAcquisitionStatus("发起流程中");
            } else {
                c.setAcquisitionStatus("流程结束");
            }

            if ("0".equalsIgnoreCase(advanceStatus)) {
                c.setAdvanceStatus("未发起流程");
            } else if ("1".equalsIgnoreCase(advanceStatus)) {
                c.setAdvanceStatus("发起流程中");
            } else {
                c.setAdvanceStatus("流程结束");
            }

            if ("0".equalsIgnoreCase(constructionStatus)) {
                c.setConstructionStatus("未发起流程");
            } else if ("1".equalsIgnoreCase(constructionStatus)) {
                c.setConstructionStatus("发起流程中");
            } else {
                c.setConstructionStatus("流程结束");
            }
            if ("0".equalsIgnoreCase(settStatus)) {
                c.setSettStatus("未发起流程");
            } else if ("1".equalsIgnoreCase(status)) {
                c.setSettStatus("发起流程中");
            } else {
                c.setSettStatus("流程结束");
            }
        }
        return getBootstrapData(scheduleViewPage);
    }


    /**
     * 施工交底项目列表
     */
    @ResponseBody
    @RequestMapping(value = "disData")
    public Map<String, Object> disData(ScheduleView scheduleView, HttpServletRequest request, HttpServletResponse response, Model model) {
        String projectId = scheduleView.getProjectId();
//        String[] projectList = null;
//        List<String> searchList = new ArrayList<>();
//        if (!projectId.equals("")) {
//            projectList = projectId.split("\\s+");
//            for (int i = 0; i < projectList.length; i++) {
//                searchList.add(projectList[i]);
//            }
//            scheduleView.setProjectList(searchList);
//        }
        if(StringUtils.isNotBlank(projectId)){
            String[] idArr = projectId.split("\\s+");
            List<String> idList = Arrays.asList(idArr);
            scheduleView.setProjectList(idList);
        }

        Page<ScheduleView> scheduleViewPage = scheduleViewService.disAll(new Page<ScheduleView>(request, response), scheduleView);
        List<ScheduleView> list = scheduleViewPage.getList();
        ScheduleViewUtil.dealDiscloseList(list);
//        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        String fin = "";
//        boolean flag;
//        boolean designFlag;
//        boolean closeFlag;
//        boolean finalClose;
//        boolean policyStart1;
//        boolean policyStart2;
//        boolean policyStart3;
//        boolean policyEnd1;
//        boolean policyEnd2;
//        boolean policyEnd3;
//        boolean policy1;
//        boolean policy2;
//        boolean policy3;
//        for (ScheduleView s : list) {
//            String status = s.getStatus();
//
//            flag = false;
//            designFlag = false;
//            closeFlag = false;
//            finalClose = false;
//            policyStart1 = false;
//            policyStart2 = false;
//            policyStart3 = false;
//            policyEnd1 = false;
//            policyEnd2 = false;
//            policyEnd3 = false;
//            policy1 = false;
//            policy2 = false;
//            policy3 = false;
//            String procInsId = s.getProcInsId();
//            if (procInsId != null && !"".equals(procInsId)) {
//                List<HistoricActivityInstance> historicActivityInstances = MyActiviUtils.hisTask(procInsId);
///*                List<Task> tasks = MyActiviUtils.runNowTask(procInsId);
//                String runNowName = "";
//                for (Task a : tasks) {
//                    runNowName += a.getName();
//                }*/
//                for (HistoricActivityInstance a : historicActivityInstances) {
//                    String activityName = a.getActivityName();
//                    String format = formatter.format(a.getEndTime());
//                    if (s.getDisView() == null) {
//                        s.setDisView(new DisView());
//                    }
//                    if ("2".equals(status)) {
//                        s.getDisView().setPolicyType("政策处理完成");
//                        s.getDisView().setProjectClosure("项目关闭完成");
//                        s.getDisView().setDesignChange("设计变更完成");
//                        continue;
//                    }
//                    if ("开始".equals(activityName)) {
//                        DisView disView = s.getDisView();
//                        if (disView != null) {
//                            s.getDisView().setFullTimeStart(format);
//                        } else {
//                            DisView disView1 = new DisView();
//                            disView1.setFullTimeStart(format);
//                            s.setDisView(disView1);
//                        }
//                    }
//                    //交底:项目经理交底内容
//                    if ("交底:项目经理交底内容".equals(activityName)) {
//                        s.getDisView().setProjectManagerImport(format);
//                    }
//                    //交底:导入材料表和拆旧物资表
//                    if ("交底:导入材料表和拆旧物资表".equals(activityName)) {
//                        s.getDisView().setUnitManagerJudge(format);
//                    }
//                    //交底:填写部分工程量信息
//                    if ("交底:填写部分工程量信息".equals(activityName)) {
//                        s.getDisView().setProjectManagerJudge(format);
//                    }
//                    if ("交底:填写部分工程量信息".equals(activityName)) {
//                        if (fin.equals("")) {
//                            fin = format;
//                        }
//                        if (fin.compareTo(format) < 1) {
//                            fin = format;
//                        }
//                    }
//
//
//                    //设计变更
//                    if ("交底:配网项目经理判定设计变更".equals(activityName)
//                            || "交底:经研所判定是否设计变更".equals(activityName)
//                            || "交底:运行单位经理审核方案".equals(activityName)
//                            || "交底:设计单位人员重新设计".equals(activityName)
//                            || "交底:运行经理审核设计变更后".equals(activityName)
//                            || "交底:配网经理审核设计变更后".equals(activityName)
//                    ) {
//                        s.getDisView().setDesignChange("设计变更流程中");
//                    }
//                    //项目关闭
//                    if ("交底:项目经理判定是否关闭".equals(activityName)
//                            || "交底:配网工程专职判定是否关闭".equals(activityName)
//                            || "交底:配网运行人员判定是否关闭".equals(activityName)
//                            || "交底:配网工程专职判定变更或关闭".equals(activityName)
//                            || "交底:配网系统专职确认系统关闭".equals(activityName)
//
//                    ) {
//                        s.getDisView().setProjectClosure("项目关闭流程中");
//                    }
//
//
//                    //如果因为各种原因完成了设计变更流程或者项目关闭流程
//                    if ("交底:导入材料表和拆旧物资表".equals(activityName)) {
//                        flag = true;
//                    }
//
//                    if ("交底:配网项目经理判定设计变更".equals(activityName)) {
//                        designFlag = true;
//                    }
//
//                    if ("交底:项目经理判定是否关闭".equals(activityName)) {
//                        closeFlag = true;
//                    }
//
//                    if ("交底:配网项目经理判定变更或关闭".equals(activityName) || "交底:配网系统专职确认系统关闭".equals(activityName)) {
//                        finalClose = true;
//                    }
//
//                    //政策处理
//                    if ("交底:农村政处".equals(activityName)
//                            || "交底:政策处理专职判断".equals(activityName)
//                            || "交底:政策处理专职判断".equals(activityName)
//                            || "交底:农村上传文件".equals(activityName)
//                            || "交底:行政政处".equals(activityName)
//                            || "行政:政策处理专职判断".equals(activityName)
//                            || "交底:行政上传文件".equals(activityName)
//                            || "交底:民事政处".equals(activityName)
//                            || "民事:政策处理专职判断".equals(activityName)
//                            || "交底:民事上传文件".equals(activityName)
//                            || "是否需要农村政处".equals(activityName)
//                            || "是否需要行政政处".equals(activityName)
//                            || "是否需要民事政处".equals(activityName)
//                    ) {
//                        s.getDisView().setPolicyType("政策处理流程中");
//                    }
//                    //判断是否发起农村政处
//                    if ("交底:农村政处".equals(activityName)) {
//                        policyStart1 = true;
//                    }
//                    //判断是否发起行政政处
//                    if ("交底:行政政处".equals(activityName)) {
//                        policyStart2 = true;
//                    }
//                    //判断是否发起民事政处
//                    if ("交底:民事政处".equals(activityName)) {
//                        policyStart3 = true;
//                    }
//                    //判断农村政处是否完成
//                    if ("交底:民事是否支付".equals(activityName)
//                            || "交底:民事是完成否借款".equals(activityName)) {
//                        policyEnd1 = true;
//                    }
//                    //判断行政政处是否完成
//                    if ("交底:行政是否支付".equals(activityName)
//                            || "交底:行政是完成否借款".equals(activityName)) {
//                        policyEnd2 = true;
//                    }
//                    //判断民事政处是否完成
//                    if ("交底:农村是否支付".equals(activityName)
//                            || "交底:农村是完成否借款".equals(activityName)) {
//                        policyEnd3 = true;
//                    }
//                }
//                //判断项目是否完成
//                if ("2".equals(s.getStatus())) {
//                    s.getDisView().setFinTime(fin);
//                }
//                //判断是否已经导入拆旧表
//                if (flag) {
//                    //判断是否发起过设计变更
//                    if (designFlag) {
//                        s.getDisView().setDesignChange("设计变更完成");
//                    }
//                }
//                //判断是否发起过项目关闭
//                if (closeFlag) {
//                    if (finalClose) {
//                        s.getDisView().setProjectClosure("项目关闭完成");
//                    }
//                }
//                if (policyStart1) {
//                    if (policyEnd1) {
//                        policy1 = true;
//                    } else {
//                        policy1 = false;
//                    }
//                } else {
//                    policy1 = true;
//
//                }
//                if (policyStart2) {
//                    if (policyEnd2) {
//                        policy2 = true;
//                    } else {
//                        policy2 = false;
//                    }
//                } else {
//                    policy2 = true;
//                }
//                if (policyStart3) {
//                    if (policyEnd3) {
//                        policy3 = true;
//                    } else {
//                        policy3 = false;
//                    }
//                } else {
//                    policy3 = true;
//                }
//                if (policyStart1 == false && policyStart2 == false && policyStart3 == false) {
//
//                } else {
//                    if (policy1 == true && policy2 == true && policy3 == true) {
//                        s.getDisView().setPolicyType("政策处理完成");
//                    }
//                }
//            }
//        }
        return getBootstrapData(scheduleViewPage);
    }

    /**
     * 导出施工交底项目进度列表
     */
    @ResponseBody
    @RequestMapping(value = "disExport")
    public void disExport(ScheduleView scheduleView, HttpServletRequest request, HttpServletResponse response, Model model) throws UnsupportedEncodingException {
        scheduleView.setReserveProjectName(URLDecoder.decode(scheduleView.getReserveProjectName(),"UTF-8"));
        scheduleView.setProjectId(URLDecoder.decode(scheduleView.getProjectId(),"UTF-8"));
        scheduleView.setProjectName(URLDecoder.decode(scheduleView.getProjectName(),"UTF-8"));
        String projectId = scheduleView.getProjectId();
        if(StringUtils.isNotBlank(projectId)){
            String[] idArr = projectId.split("\\s+");
            List<String> idList = Arrays.asList(idArr);
            scheduleView.setProjectList(idList);
        }

        List<ScheduleView> list = scheduleViewService.disAll(scheduleView);
        ScheduleViewUtil.dealDiscloseList(list);

        ExportUtil util = ExportUtil.getOne();
        XSSFWorkbook workbook = util.getWorkbook("scheduleViewDisclose");
        util.exportDisclose(response,workbook,list);
    }

    /**
     * 项目进度查询-物资领料状态
     */
    @ResponseBody
    @RequestMapping(value = "recData")
    public Map<String, Object> recData(ScheduleView scheduleView, HttpServletRequest request, HttpServletResponse response, Model model) {
        String projectId = scheduleView.getProjectId();
        String[] projectList = null;
        List<String> searchList = new ArrayList<>();
        if (!projectId.equals("")) {
            projectList = projectId.split("\\s+");
            for (int i = 0; i < projectList.length; i++) {
                searchList.add(projectList[i]);
            }
            scheduleView.setProjectList(searchList);
        }
        Page<ScheduleView> scheduleViewPage = scheduleViewService.recAll(new Page<ScheduleView>(request, response), scheduleView);
        List<ScheduleView> list = scheduleViewPage.getList();
        ScheduleViewUtil.dealRec(list);
        return getBootstrapData(scheduleViewPage);
    }

    /**
     * 导出物资领料项目进度列表
     */
    @ResponseBody
    @RequestMapping(value = "recExport")
    public void recExport(ScheduleView scheduleView, HttpServletRequest request, HttpServletResponse response, Model model) throws UnsupportedEncodingException {
        scheduleView.setReserveProjectName(URLDecoder.decode(scheduleView.getReserveProjectName(),"UTF-8"));
        scheduleView.setProjectId(URLDecoder.decode(scheduleView.getProjectId(),"UTF-8"));
        scheduleView.setProjectName(URLDecoder.decode(scheduleView.getProjectName(),"UTF-8"));
        String projectId = scheduleView.getProjectId();
        if(StringUtils.isNotBlank(projectId)){
            String[] idArr = projectId.split("\\s+");
            List<String> idList = Arrays.asList(idArr);
            scheduleView.setProjectList(idList);
        }

        List<ScheduleView> list = scheduleViewService.recAll(scheduleView);
        ScheduleViewUtil.dealRec(list);

        ExportUtil util = ExportUtil.getOne();
        XSSFWorkbook workbook = util.getWorkbook("scheduleViewRec");
        util.exportRec(response,workbook,list);
    }

    /**
     * 结算流程数据
     */
    @ResponseBody
    @RequestMapping(value = "settData")
    public Map<String, Object> settData(ScheduleView scheduleView, HttpServletRequest request, HttpServletResponse response, Model model) {
        String projectId = scheduleView.getProjectId();
        String[] projectList = null;
        List<String> searchList = new ArrayList<>();
        if (!projectId.equals("")) {
            projectList = projectId.split("\\s+");
            for (int i = 0; i < projectList.length; i++) {
                searchList.add(projectList[i]);
            }
            scheduleView.setProjectList(searchList);
        }
        Page<ScheduleView> scheduleViewPage = scheduleViewService.settAll(new Page<ScheduleView>(request, response), scheduleView);
        List<ScheduleView> list = scheduleViewPage.getList();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        for (ScheduleView s : list) {
            String procInsId = s.getProcInsId();
            if (procInsId != null && !"".equals(procInsId)) {
                List<HistoricActivityInstance> historicActivityInstances = MyActiviUtils.hisTask(procInsId);
                for (HistoricActivityInstance a : historicActivityInstances) {
                    String activityName = a.getActivityName();
                    String format = formatter.format(a.getEndTime());
                    if (s.getSettView() == null) {
                        s.setSettView(new SettView());
                    }
                    if ("结算验收发起模块".equals(activityName)) {
                        s.getSettView().setSettStart(format);
                    }
                    if ("填写现场使用数量".equals(activityName)) {
                        s.getSettView().setSettNumber(format);
                    }
                    if ("审计现场复核数量".equals(activityName)) {
                        s.getSettView().setSettReview(format);
                    }
                    if ("生成领料退料单".equals(activityName)) {
                        s.getSettView().setSettFin(format);
                    }
                }
            }
        }
        return getBootstrapData(scheduleViewPage);
    }

    /**
     * 项目关闭数据列表
     */
    @ResponseBody
    @RequestMapping(value = "closureData")
    public Map<String, Object> closureData(ScheduleView scheduleView, HttpServletRequest request, HttpServletResponse response, Model model) {
        String projectId = scheduleView.getProjectId();
        String[] projectList = null;
        List<String> searchList = new ArrayList<>();
        if (!projectId.equals("")) {
            projectList = projectId.split("\\s+");
            for (int i = 0; i < projectList.length; i++) {
                searchList.add(projectList[i]);
            }
            scheduleView.setProjectList(searchList);
        }
        Page<ScheduleView> scheduleViewPage = scheduleViewService.disAll(new Page<ScheduleView>(request, response), scheduleView);
        List<ScheduleView> list = scheduleViewPage.getList();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        for (ScheduleView s : list) {
            String procInsId = s.getProcInsId();
            if (procInsId != null && !"".equals(procInsId)) {
                List<HistoricActivityInstance> historicActivityInstances = MyActiviUtils.hisTask(procInsId);
                for (HistoricActivityInstance a : historicActivityInstances) {
                    if (s.getClosureView() == null) {
                        s.setClosureView(new ClosureView());
                    }
                    String activityName = a.getActivityName();
                    String format = formatter.format(a.getEndTime());
                    if ("交底:项目经理判定是否关闭".equals(activityName)) {
                        s.getClosureView().setIfClose(format);
                    }
                    if ("交底:配网工程专职判定是否关闭".equals(activityName)) {
                        s.getClosureView().setRunMember(format);
                    }
                    if ("交底:配网运行人员判定是否关闭".equals(activityName)) {
                        s.getClosureView().setIsClosed(format);
                    }
                    if ("交底:配网工程专职判定变更或关闭".equals(activityName)) {
                        s.getClosureView().setDetermination(format);
                    }
                    if ("交底:配网项目经理判定变更或关闭".equals(activityName)) {
                        s.getClosureView().setProjectManager(format);
                    }
                    if ("交底:配网系统专职确认系统关闭".equals(activityName)) {
                        s.getClosureView().setShutDown(format);
                    }
                }
            }
        }
        return getBootstrapData(scheduleViewPage);
    }

    /**
     * 设计变更数据列表
     */
    @ResponseBody
    @RequestMapping(value = "designData")
    public Map<String, Object> designData(ScheduleView scheduleView, HttpServletRequest request, HttpServletResponse response, Model model) {
        String projectId = scheduleView.getProjectId();
        String[] projectList = null;
        List<String> searchList = new ArrayList<>();
        if (!projectId.equals("")) {
            projectList = projectId.split("\\s+");
            for (int i = 0; i < projectList.length; i++) {
                searchList.add(projectList[i]);
            }
            scheduleView.setProjectList(searchList);
        }
        Page<ScheduleView> scheduleViewPage = scheduleViewService.disAll(new Page<ScheduleView>(request, response), scheduleView);
        List<ScheduleView> list = scheduleViewPage.getList();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        for (ScheduleView s : list) {
            String procInsId = s.getProcInsId();
            if (procInsId != null && !"".equals(procInsId)) {
                List<HistoricActivityInstance> historicActivityInstances = MyActiviUtils.hisTask(procInsId);
                for (HistoricActivityInstance a : historicActivityInstances) {
                    if (s.getDesignView() == null) {
                        s.setDesignView(new DesignView());
                    }
                    String activityName = a.getActivityName();
                    String format = formatter.format(a.getEndTime());
                    if ("交底:配网项目经理判定设计变更".equals(activityName)) {
                        s.getDesignView().setDesignChange(format);
                    }
                    if ("交底:经研所判定是否设计变更".equals(activityName)) {
                        s.getDesignView().setIfChange(format);
                    }
                    if ("交底:运行单位经理审核方案".equals(activityName)) {
                        s.getDesignView().setJYSChange(format);
                    }
                    if ("交底:设计单位人员重新设计".equals(activityName)) {
                        s.getDesignView().setUnitReview(format);
                    }
                    if ("交底:运行经理审核设计变更后".equals(activityName)) {
                        s.getDesignView().setDesignAgain(format);
                    }
                    if ("交底:配网经理审核设计变更后".equals(activityName)) {
                        s.getDesignView().setChangeAfter(format);
                    }
                    if ("交底:配网项目经理判断变更后材料".equals(activityName)) {
                        s.getDesignView().setManagerAfter(format);
                    }
                }
            }
        }
        return getBootstrapData(scheduleViewPage);
    }

    /**
     * 政策处理数据列表
     */
    @ResponseBody
    @RequestMapping(value = "policyData")
    public Map<String, Object> policyData(ScheduleView scheduleView, HttpServletRequest request, HttpServletResponse response, Model model) {
        String projectId = scheduleView.getProjectId();
        String[] projectList = null;
        List<String> searchList = new ArrayList<>();
        if (!projectId.equals("")) {
            projectList = projectId.split("\\s+");
            for (int i = 0; i < projectList.length; i++) {
                searchList.add(projectList[i]);
            }
            scheduleView.setProjectList(searchList);
        }
        Page<ScheduleView> scheduleViewPage = scheduleViewService.disAll(new Page<ScheduleView>(request, response), scheduleView);
        List<ScheduleView> list = scheduleViewPage.getList();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        for (ScheduleView s : list) {
            String procInsId = s.getProcInsId();
            if (procInsId != null && !"".equals(procInsId)) {
                List<HistoricActivityInstance> historicActivityInstances = MyActiviUtils.hisTask(procInsId);
                for (HistoricActivityInstance a : historicActivityInstances) {
                    if (s.getPolicyView() == null) {
                        s.setPolicyView(new PolicyView());
                    }
                    String activityName = a.getActivityName();
                    String format = formatter.format(a.getEndTime());
                    if ("交底:农村政处".equals(activityName)) {
                        s.getPolicyView().setUrbanRoad(format);
                    }
                    if ("交底:农村专职判断".equals(activityName)) {
                        s.getPolicyView().setPolicyNeed(format);
                    }
                    if ("交底:农村上传文件".equals(activityName)) {
                        s.getPolicyView().setSealScheme(format);
                    }
                    if ("交底:农村是否支付".equals(activityName)) {
                        s.getPolicyView().setUploadReceipt(format);
                    }
                    if ("交底:农村是否借款".equals(activityName)) {
                        s.getPolicyView().setPayment(format);
                    }
                    if ("交底:行政政处".equals(activityName)) {
                        s.getPolicyView().setUploadLoan(format);
                    }
                    if ("交底:行政专职判断".equals(activityName)) {
                        s.getPolicyView().setHandling(format);
                    }
                    if ("交底:行政上传文件".equals(activityName)) {
                        s.getPolicyView().setUnsignedVersion(format);
                    }
                    if ("交底:行政是否支付".equals(activityName)) {
                        s.getPolicyView().setRuralNeed(format);
                    }
                    if ("交底:行政是否借款".equals(activityName)) {
                        s.getPolicyView().setPolicyList(format);
                    }
                    if ("交底:民事政处".equals(activityName)) {
                        s.getPolicyView().setSignedContract(format);
                    }
                    if ("交底:民事专职判断".equals(activityName)) {
                        s.getPolicyView().setUploadLoan1(format);
                    }
                    if ("交底:民事上传文件".equals(activityName)) {
                        s.getPolicyView().setCivilUpload(format);
                    }
                    if ("交底:民事是否支付".equals(activityName)) {
                        s.getPolicyView().setCivilPay(format);
                    }
                    if ("交底:民事是否借款".equals(activityName)) {
                        s.getPolicyView().setCivilBorrow(format);
                    }
                }
            }
        }
        return getBootstrapData(scheduleViewPage);
    }

    /**
     * 施工验收土建流程
     */
    @ResponseBody
    @RequestMapping(value = "civilData")
    public Map<String, Object> civilData(ScheduleView scheduleView, HttpServletRequest request, HttpServletResponse response, Model model) {
        String projectId = scheduleView.getProjectId();
        String[] projectList = null;
        List<String> searchList = new ArrayList<>();
        if (!projectId.equals("")) {
            projectList = projectId.split("\\s+");
            for (int i = 0; i < projectList.length; i++) {
                searchList.add(projectList[i]);
            }
            scheduleView.setProjectList(searchList);
        }
        Page<ScheduleView> scheduleViewPage = scheduleViewService.civilAll(new Page<ScheduleView>(request, response), scheduleView);
        List<ScheduleView> list = scheduleViewPage.getList();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        for (ScheduleView s : list) {
            String procInsId = s.getProcInsId();
            if (procInsId != null && !"".equals(procInsId)) {
                List<HistoricActivityInstance> historicActivityInstances = MyActiviUtils.hisTask(procInsId);
                for (HistoricActivityInstance a : historicActivityInstances) {
                    String activityName = a.getActivityName();
                    String format = formatter.format(a.getEndTime());
                    if (s.getCivilView() == null) {
                        s.setCivilView(new CivilView());
                    }
                    if ("土建结算流程发起".equals(activityName)) {
                        s.getCivilView().setCivilBegins(format);
                    }
                    if ("土建开工".equals(activityName)) {
                        s.getCivilView().setCivilStarts(format);
                    }
                    if ("土建竣工".equals(activityName)) {
                        s.getCivilView().setCivilCompleted(format);
                    }
                    if ("审核土建竣工".equals(activityName)) {
                        s.getCivilView().setCivilReview(format);
                    }
                    if ("土建完成时间".equals(activityName)) {
                        s.getCivilView().setCivilCompletion(format);
                    }
                }
            }
        }
        return getBootstrapData(scheduleViewPage);
    }


    /**
     * 施工验收电气流程数据
     */
    @ResponseBody
    @RequestMapping(value = "electricData")
    public Map<String, Object> electricData(ScheduleView scheduleView, HttpServletRequest request, HttpServletResponse response, Model model) {
        String projectId = scheduleView.getProjectId();
        String[] projectList = null;
        List<String> searchList = new ArrayList<>();
        if (!projectId.equals("")) {
            projectList = projectId.split("\\s+");
            for (int i = 0; i < projectList.length; i++) {
                searchList.add(projectList[i]);
            }
            scheduleView.setProjectList(searchList);
        }
        Page<ScheduleView> scheduleViewPage = scheduleViewService.electricAll(new Page<ScheduleView>(request, response), scheduleView);
        List<ScheduleView> list = scheduleViewPage.getList();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        for (ScheduleView s : list) {
            String procInsId = s.getProcInsId();
            if (procInsId != null && !"".equals(procInsId)) {
                List<HistoricActivityInstance> historicActivityInstances = MyActiviUtils.hisTask(procInsId);
                for (HistoricActivityInstance a : historicActivityInstances) {
                    String activityName = a.getActivityName();
                    String format = formatter.format(a.getEndTime());
                    if (s.getElectricView() == null) {
                        s.setElectricView(new ElectricView());
                    }
                    if ("发起施工流程/填写项目类型".equals(activityName)) {
                        s.getElectricView().setStartTime(format);
                    }
                    if ("电气开工报告".equals(activityName)) {
                        s.getElectricView().setElectricStart(format);
                    }
                    if ("上传电气竣工资料".equals(activityName)) {
                        s.getElectricView().setElectricUploadCompletion(format);
                    }
                    if ("审核电气竣工流程".equals(activityName)) {
                        s.getElectricView().setElectricReviewCompletion(format);
                    }
                    if ("上传涉电开工资料".equals(activityName)) {
                        s.getElectricView().setElectricStartUpload(format);
                    }
                    if ("涉电开工报告".equals(activityName)) {
                        s.getElectricView().setElectricStartElectricity(format);
                    }
                    if ("涉电竣工报告".equals(activityName)) {
                        s.getElectricView().setElectricEndElectricity(format);
                    }
                    if ("审核涉电竣工".equals(activityName)) {
                        s.getElectricView().setElectricReviewRelated(format);
                    }
                    if ("是否完成所有涉电工作".equals(activityName)) {
                        s.getElectricView().setElectricWork(format);
                        if ("2".equals(s.getConstructionStatus())) {
                            s.getElectricView().setEndTime(format);
                        }
                    }
                }
            }
        }
        return getBootstrapData(scheduleViewPage);
    }


    /* *//**
     * 导出excel文件
     *//*
    @ResponseBody
    @RequestMapping(value = "exportSett")
    public AjaxJson exportSett(SettList settList, HttpServletRequest request, HttpServletResponse response){
        AjaxJson j = new AjaxJson();
        try {
            String fileName = "竣工甲供材核对表"+DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";
            Page<SettList> page = settActiviService.useQuantityData(new Page<SettList>(request, response), settList);
            new ExportExcel("竣工甲供材核对表", SettList.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;
    }*/
}


