package com.jeeplus.modules.sg.managementcenter.projectPlanArrage.web;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.jeeplus.common.json.AjaxJson;
import com.jeeplus.common.utils.DateUtils;
import com.jeeplus.common.utils.excel.ExportExcel;
import com.jeeplus.common.websocket.service.system.SystemInfoSocketHandler;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.web.BaseController;
import com.jeeplus.modules.act.entity.Act;
import com.jeeplus.modules.act.service.ActTaskService;
import com.jeeplus.modules.oa.entity.OaNotify;
import com.jeeplus.modules.oa.entity.OaNotifyRecord;
import com.jeeplus.modules.oa.service.OaNotifyService;
import com.jeeplus.modules.sg.managementcenter.materialplan.entity.MaterialPlan;
import com.jeeplus.modules.sg.managementcenter.materialproject.entity.MaterialProject;
import com.jeeplus.modules.sg.managementcenter.projectPlanArrage.entity.ProjectActProclnsAss;
import com.jeeplus.modules.sg.managementcenter.projectPlanArrage.entity.ProjectAssignment;
import com.jeeplus.modules.sg.managementcenter.projectPlanArrage.entity.ProjectPlanArrage;
import com.jeeplus.modules.sg.managementcenter.projectPlanArrage.service.ProjectDailyPlanService;
import com.jeeplus.modules.sg.managementcenter.projectPlanArrage.service.ProjectPlanActService;
import com.jeeplus.modules.sg.managementcenter.projectPlanArrage.service.ProjectPlanArrageService;
import com.jeeplus.modules.sg.managementcenter.projectPlanArrage.util.BookStrapTreeUtil;
import com.jeeplus.modules.sg.managementcenter.projectPlanArrage.util.ImportUtil;
import com.jeeplus.modules.sg.managementcenter.projectPlanArrage.util.PackagingUtil;
import com.jeeplus.modules.sg.managementcenter.projectPlanArrage.util.Result;
import com.jeeplus.modules.sys.utils.UserUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
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.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.ServletContext;
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.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import static com.jeeplus.core.service.BaseService.dataRuleFilter;

@Controller
@RequestMapping(value = "${adminPath}/sg/managementCenter/projectPlanArrage")
public class ProjectPlanArrageController extends BaseController {
    @Autowired
    private ProjectPlanArrageService projectPlanArrageService;
    @Autowired
    private ProjectPlanActService projectPlanActService;
    @Autowired
    private ActTaskService actTaskService;
    @Autowired
    private OaNotifyService oaNotifyService;
    @Autowired
    private ProjectDailyPlanService projectDailyPlanService;


    /*
        初始节点(配网项目经理节点)-----------------------------------------------------------------------------------01
    */
    /*
        页面跳转（配网项目经理节点）
     */
    //进入月计划安排列表 返回projectPlanArrageList 页面（projectPlanArrageList）
    @RequestMapping(value = {"list", ""})
    @RequiresPermissions("sg:managementcenter:monthplan:list")
    public String list(ProjectPlanArrage projectPlanArrage, Model model) {
        model.addAttribute("projectPlanArrage", projectPlanArrage);
        return "modules/sg/managementcenter/projectPlanArrage/projectPlanArrageList";
    }

    //安排项目计划【按钮】 -- 跳转配网项目经理操作页面 该页面可操作项目名称，项目定义号 页面（projectDateForm）
    @RequestMapping(value = "arrageProjectPlan")
    public String arrageProjectPlan(ProjectPlanArrage projectPlanArrage,Model model){
        return "modules/sg/managementcenter/projectPlanArrage/projectDateForm";
    }

    //返回安排计划列表，操作计划安排 -- 左树右边表 页面（projectPlanArrageForm） session(projectPlan)
    @RequestMapping(value = "isArranging")
    public String lsArranging(ProjectPlanArrage projectPlanArrage,Model model,HttpServletRequest request){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy");
        try {
            if (null!=projectPlanArrage.getProjectName()&&!"".equals(projectPlanArrage.getProjectName())){
                String name = URLDecoder.decode(projectPlanArrage.getProjectName(),"utf-8");
                projectPlanArrage.setProjectName(name);
            }
            //获取项目计划安排的初始项目
            MaterialProject materialProject = new MaterialProject();
            materialProject.setArrageProject("0");
            materialProject.setArrageProject1("1");
            //获取当前年份
            materialProject.setAttributionYear(simpleDateFormat.format(projectPlanArrage.getProjectMonthDate()));
            //初始安排计划项目列表
            List<ProjectPlanArrage> planArrageList = projectPlanArrageService.getProjectPlanArrageList(materialProject);
            if (!planArrageList.isEmpty()){
                //根据项目名称查询人员
                List<ProjectAssignment> listAssignment = projectPlanArrageService.findListAssignment(planArrageList);
                //获得最终集合
                List<ProjectPlanArrage> projectPlanArrageList = projectPlanArrageService.getPlanArrageList(planArrageList, listAssignment);

                //区分开关与项目--整体集合
                List<ProjectPlanArrage> projectList = projectPlanArrageService.getProjectList(projectPlanArrageList);
                //开关 - 项目 统一集合 用WhetherStatus区分
                List<ProjectPlanArrage> projectPlanList = PackagingUtil.getProjectPlanList(projectPlanArrage,projectList);
                for (ProjectPlanArrage par:projectList){
                    if (par.getWhetherStatus().equals("0")&&par.getArrageFlag().equals("1")){
                        par.setAssociatedBag("关联项目包1");
                        par.setAssociatedSort(1);
                    }
                    par.setProjectMonthDate(projectPlanArrage.getProjectMonthDate());
                    par.setHtmlStatus("0");
                    par.preInsert();
                }
                request.getSession().setAttribute("projectPlan",projectPlanList);
            }else {
                request.getSession().setAttribute("projectPlan",planArrageList);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return "modules/sg/managementcenter/projectPlanArrage/projectPlanArrageForm";
    }

    //设置停电开关页面--人工选择是否带电 页面(projectPowerList)
    @RequestMapping(value = "arrangementElectrified")
    public String arrangementElectrified(ProjectPlanArrage projectPlanArrage){
        return "modules/sg/managementcenter/projectPlanArrage/projectPowerList";
    }

    /*
        树形表格+列表展示 ： （初始配网项目经理节点） 处理数据显示问题
     */
    //初始列表数据：（刚进入月计划安排的列表数据）展示所有已经安排月计划数据
    @ResponseBody
//	@RequiresPermissions("managementcenter:materialproject:list")
    @RequestMapping(value = "data")
    public Map<String, Object> data(ProjectPlanArrage projectPlanArrage, HttpServletRequest request, HttpServletResponse response, Model model) {
        Page<ProjectPlanArrage> page = projectPlanArrageService.findPage(new Page<ProjectPlanArrage>(request, response), projectPlanArrage);
        return getBootstrapData(page);
    }

    //所有未安排的计划-树形表格展示 -- 初始安排月计划左侧树展示列表
    @ResponseBody
    @RequestMapping(value = "bootstrapTreeTable")
    public List<Map<String,Object>> getArrageNoPlan(ProjectPlanArrage projectPlanArrage,HttpServletRequest request){
        //创建树形表格
        List<Map<String,Object>> objects = Lists.newArrayList();
        List<ProjectPlanArrage> projectPlans = (List<ProjectPlanArrage>)request.getSession().getAttribute("projectPlan");
        List<ProjectPlanArrage> planArrageList = new ArrayList<ProjectPlanArrage>();
        if (null!=projectPlans){
            for (ProjectPlanArrage p:projectPlans){
                if (p.getArrageFlag().equals("0")){
                    planArrageList.add(p);
                }
            }
        }
        List<Map<String, Object>> bookStrapTree = BookStrapTreeUtil.getAllBookStrapTree(objects, planArrageList,"1");
        return bookStrapTree;
    }
    //初始安排的计划项目--右侧表格数据 展示计划安排的项目
    @ResponseBody
    @RequestMapping(value = "initArragePlanProject")
    public Map<String, Object> initArragePlanProject(ProjectPlanArrage projectPlanArrage,Model model,HttpServletRequest request,HttpServletResponse response){
        projectPlanArrage.setArrageFlag("1");
        projectPlanArrage.setWhetherStatus("0");
        List<ProjectPlanArrage> projectPlans = (List<ProjectPlanArrage>)request.getSession().getAttribute("projectPlan");
        Page<ProjectPlanArrage> page = findPageList(new Page<ProjectPlanArrage>(request, response),projectPlanArrage,projectPlans);
        projectPlanArrageService.getSortAssPackage(page.getList());
        return getBootstrapData(page);
    }

    public Page<ProjectPlanArrage> findPageList(Page<ProjectPlanArrage> page, ProjectPlanArrage entity,List<ProjectPlanArrage> list) {
        dataRuleFilter(entity);
        entity.setPage(page);
        List<ProjectPlanArrage> planArrages = new ArrayList<ProjectPlanArrage>();
        if (null!=list){
            for (ProjectPlanArrage projectPlanArrage:list){
                if (entity.getWhetherStatus().equals(projectPlanArrage.getWhetherStatus())&&entity.getArrageFlag().equals(projectPlanArrage.getArrageFlag())){
                    planArrages.add(projectPlanArrage);
                }
            }
        }
        page.setList(planArrages);
        return page;
    }
    //安排带电项目展示form--人工选择是否带电页面表格数据
    @ResponseBody
//	@RequiresPermissions("managementcenter:materialproject:list")
    @RequestMapping(value = "dataPower")
    public Map<String, Object> dataPower(ProjectPlanArrage projectPlanArrage, HttpServletRequest request, HttpServletResponse response, Model model) {
        projectPlanArrage.setArrageFlag("1");
        projectPlanArrage.setWhetherStatus("0");
        List<ProjectPlanArrage> projectPlans = (List<ProjectPlanArrage>)request.getSession().getAttribute("projectPlan");
        Page<ProjectPlanArrage> page = findPageList(new Page<ProjectPlanArrage>(request, response),projectPlanArrage,projectPlans);
        projectPlanArrageService.getSortPowerPackage(page.getList());
        return getBootstrapData(page);
    }

    /*
        【按钮】 （初始项目经理节点）操作按钮
     */
    //（jsp页面：projectPlanArrageForm.jsp）安排项目计划 -- 选择左侧树（勾选） 安排项目计划 projectPlan
    @ResponseBody
    @RequestMapping(value = "unplanned")
    public Result getUnplanned(ProjectPlanArrage projectPlanArrage,String ids,HttpServletRequest request){
        Result j = new Result();
        List<String> strings = PackagingUtil.getString(ids);
        j.setSuccess(false);
        j.setMessage("安排计划项目失败");
        try {
            //获取项目信息
            List<ProjectPlanArrage> projectPlans = (List<ProjectPlanArrage>)request.getSession().getAttribute("projectPlan");
            if (!projectPlans.isEmpty()&&!strings.isEmpty()){
                projectPlanArrageService.getUnplannedService(projectPlans,strings);
            }else {
                j.setSuccess(false);
                j.setMessage("安排计划项目失败");
            }
            List<ProjectPlanArrage> planArrages = new ArrayList<ProjectPlanArrage>();
            for (ProjectPlanArrage planArrage:projectPlans){
                if (planArrage.getArrageFlag().equals("0")){
                    planArrages.add(planArrage);
                }
            }
            List<Map<String,Object>> objects = Lists.newArrayList();
            List<Map<String, Object>> bookStrapTree = BookStrapTreeUtil.getAllBookStrapTree(objects, planArrages,"1");
            j.setMapListTree(bookStrapTree);
            j.setSuccess(true);
            j.setMessage("安排计划成功");
        }catch (Exception e){
            e.printStackTrace();
        }
        return j;
    }
    //（jsp页面：projectPlanArrageForm.jsp）退回操作,通过勾选右侧表格数据退回：单条退回。
    @ResponseBody
    @RequestMapping(value = "deleteAll")
    public Result getTheRoBack(ProjectPlanArrage projectPlanArrage, String ids, HttpServletRequest request){
        Result j = new Result();
        j.setSuccess(true);
        j.setMessage("退回成功");
        List<String> strings = PackagingUtil.getString(ids);
        try {
            //获取项目信息
            List<ProjectPlanArrage> projectPlans = (List<ProjectPlanArrage>)request.getSession().getAttribute("projectPlan");
            if (!projectPlans.isEmpty()&&!strings.isEmpty()){
                projectPlanArrageService.getTheRoBackOneService(projectPlans,strings);
            }else {
                j.setSuccess(false);
                j.setMessage("退回计划项目失败");
            }
            List<ProjectPlanArrage> planArrages = new ArrayList<ProjectPlanArrage>();
            for (ProjectPlanArrage planArrage:projectPlans){
                if (planArrage.getArrageFlag().equals("0")){
                    planArrages.add(planArrage);
                }
            }
            List<Map<String,Object>> objects = Lists.newArrayList();
            List<Map<String, Object>> bookStrapTree = BookStrapTreeUtil.getAllBookStrapTree(objects, planArrages,"1");
            j.setMapListTree(bookStrapTree);
            j.setSuccess(true);
            j.setMessage("退回计划成功");
        }catch (Exception e){
            e.printStackTrace();
        }
        return j;
    }
    //（jsp页面：projectPlanArrageForm.jsp）【安排停电打包】按钮  --- 勾选右侧表格数据 安排停电包
    @ResponseBody
    @RequestMapping(value = "unplannedPackage")
    public Result getUnplannedPackage(ProjectPlanArrage projectPlanArrage,String ids,HttpServletRequest request){
        Result j = new Result();
        List<String> strings = PackagingUtil.getString(ids);
        boolean flag = true;
        try {
            //获取项目信息
             List<ProjectPlanArrage> projectPlans = (List<ProjectPlanArrage>)request.getSession().getAttribute("projectPlan");
            Boolean powerOutagesInspection = projectPlanArrageService.getPowerOutagesInspection(strings, projectPlans);
            if (powerOutagesInspection){
                projectPlanArrageService.getUnplannedPowerPackage(projectPlans,strings);
            }else {
                flag = false;
                j.setSuccess(false);
                j.setMessage("停电打包失败：请选择相同关联包的项目!");
            }
            List<ProjectPlanArrage> planArrages = new ArrayList<ProjectPlanArrage>();
            for (ProjectPlanArrage planArrage:projectPlans){
                if (planArrage.getArrageFlag().equals("0")){
                    planArrages.add(planArrage);
                }
            }
            List<Map<String,Object>> objects = Lists.newArrayList();
            List<Map<String, Object>> bookStrapTree = BookStrapTreeUtil.getAllBookStrapTree(objects, planArrages,"1");
            j.setMapListTree(bookStrapTree);
            if (flag){
                j.setSuccess(true);
                j.setMessage("停电打包成功");
            }
            return j;
        }catch (Exception e){
            e.printStackTrace();
        }
        j.setSuccess(false);
        j.setMessage("停电打包失败");
        return j;
    }
    //（jsp页面：projectPlanArrageForm.jsp）【取消停电打包】按钮  --- 配网项目经理
    @ResponseBody
    @RequestMapping(value = "cancelPackage")
    public Result getCancelPackage(ProjectPlanArrage projectPlanArrage,String ids,HttpServletRequest request){
        Result j = new Result();
        List<String> strings = PackagingUtil.getString(ids);
        boolean flag = true;
        try {
            //获取项目信息
            List<ProjectPlanArrage> projectPlans = (List<ProjectPlanArrage>)request.getSession().getAttribute("projectPlan");
            if (!projectPlans.isEmpty()&&!strings.isEmpty()){
                projectPlanArrageService.getCancelPowerPackage(projectPlans,strings);
                j.setSuccess(true);
                j.setMessage("取消停电包成功");
            }
            List<ProjectPlanArrage> planArrages = new ArrayList<ProjectPlanArrage>();
            for (ProjectPlanArrage planArrage:projectPlans){
                if (planArrage.getArrageFlag().equals("0")){
                    planArrages.add(planArrage);
                }
            }
            List<Map<String,Object>> objects = Lists.newArrayList();
            List<Map<String, Object>> bookStrapTree = BookStrapTreeUtil.getAllBookStrapTree(objects, planArrages,"1");
            j.setMapListTree(bookStrapTree);
        }catch (Exception e){
            e.printStackTrace();
            j.setSuccess(false);
            j.setMessage("取消停电包失败");
        }
        return j;
    }
    //（jsp页面：projectPlanArrageForm.jsp）发起人备注 -- 可多条同事备注
    @ResponseBody
    @RequestMapping(value = "remarksBack")
    public Result getRemarksBack(ProjectPlanArrage projectPlanArrage, String ids, HttpServletRequest request){
        Result j = new Result();
        j.setSuccess(true);
        j.setMessage("备注成功");
        List<String> strings = PackagingUtil.getString(ids);
        boolean flag = true;
        try {
            String comment = URLDecoder.decode(projectPlanArrage.getRemarks(), "UTF-8");
            projectPlanArrage.setRemarks(comment);
            //获取项目信息
            List<ProjectPlanArrage> projectPlans = (List<ProjectPlanArrage>)request.getSession().getAttribute("projectPlan");
            if (!projectPlans.isEmpty()&&!strings.isEmpty()){
                projectPlanArrageService.getRemarksBack(projectPlans,strings,projectPlanArrage);
            }else {
                flag = false;
                j.setSuccess(false);
                j.setMessage("备注失败");
            }
            List<ProjectPlanArrage> planArrages = new ArrayList<ProjectPlanArrage>();
            for (ProjectPlanArrage planArrage:projectPlans){
                if (planArrage.getArrageFlag().equals("0")){
                    planArrages.add(planArrage);
                }
            }
            List<Map<String,Object>> objects = Lists.newArrayList();
            List<Map<String, Object>> bookStrapTree = BookStrapTreeUtil.getAllBookStrapTree(objects, planArrages,"1");
            j.setMapListTree(bookStrapTree);
            if (flag){
                j.setSuccess(true);
                j.setMessage("备注成功");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return j;
    }
    //（页面projectPowerList.jsp）人工选择是否带电 检验按钮
    @ResponseBody
    @RequestMapping(value = "inspection")
    public AjaxJson inspection(String ids,ProjectPlanArrage projectPlanArrage,Model model,HttpServletRequest request,HttpServletResponse response){
        List<ProjectPlanArrage> projectPlans = (List<ProjectPlanArrage>)request.getSession().getAttribute("projectPlan");
        List<ProjectPlanArrage> planArrages = projectPlanArrageService.inspectionService(ids, projectPlans);
        request.getSession().setAttribute("projectPlan",planArrages);
        AjaxJson j = new AjaxJson();
        j.setSuccess(true);
        j.setMsg("检验成功");
        return j;
    }
    //（页面projectPowerList.jsp）人工选择是否带电 确定按钮
    @ResponseBody
    @RequestMapping(value = "sureInspection")
    public AjaxJson sureInspection(String ids,ProjectPlanArrage projectPlanArrage,Model model,HttpServletRequest request,HttpServletResponse response){
        AjaxJson j = new AjaxJson();
        List<ProjectPlanArrage> projectPlans = (List<ProjectPlanArrage>)request.getSession().getAttribute("projectPlan");
        List<ProjectPlanArrage> planArrages = projectPlanArrageService.inspectionService(ids, projectPlans);
        request.getSession().setAttribute("projectPlan",planArrages);
        boolean flag = true;
        for (ProjectPlanArrage planArrage:planArrages){
            if (planArrage.getHtmlStatus().equals("1")){
                flag = false;
                break;
            }
        }
        if (flag){
            j.setSuccess(false);
        }else {
            j.setSuccess(true);
        }
        return j;
    }



    /*
        施工单位项目经理操作-----------------------------------------------------------------------------------02
     */
    /*
        施工单位项目经理操作所有跳转页面
     */
    //点击流程进入的页面 获取数据中数据，返回 constructionManageAct.jsp
    @RequestMapping(value = "conList")
    public String getConstructionList(ProjectActProclnsAss projectActProclnsAss, Model model,HttpServletRequest request){
        //得到当前流程
        Act act = projectActProclnsAss.getAct();
        act.setId(projectActProclnsAss.getId());
        projectActProclnsAss.setProcInsId(act.getProcInsId());//赋值项目id
        //配网项目经理安排的项目
        List<ProjectActProclnsAss> listAss = projectPlanActService.findListAss(projectActProclnsAss);//查找当前流程节点的项目
        //目前安排的存入session中
        request.getSession().setAttribute("presentActProInsAss",listAss);
        //项目已经安排项目定义号拼接
        String projectId = projectPlanActService.getMapProjectId(listAss);
        //获取计划安排月份
        Date mouthDate = projectPlanActService.getMouthDate(listAss);
        request.getSession().setAttribute("mouthDate",mouthDate);
        //获取项目计划安排的初始项目
        MaterialProject materialProject = new MaterialProject();
        materialProject.setArrageProject("0");
        materialProject.setArrageProject1("1");
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy");
        materialProject.setAttributionYear(simpleDateFormat.format(mouthDate));
        //初始安排计划项目列表
        List<ProjectPlanArrage> planArrageList = projectPlanArrageService.getProjectPlanArrageList(materialProject);
        //根据项目名称查询人员
        List<ProjectAssignment> listAssignment = projectPlanArrageService.findListAssignment(planArrageList);
        //获得最终集合
        List<ProjectPlanArrage> projectPlanArrageList = projectPlanArrageService.getPlanArrageList(planArrageList, listAssignment);
        //区分开关与项目--整体集合
        List<ProjectPlanArrage> projectList = projectPlanArrageService.getProjectList(projectPlanArrageList);
        //开关 - 项目 统一集合 用WhetherStatus区分
        ProjectPlanArrage planArrage = new ProjectPlanArrage();
        planArrage.setProjectNumber(projectId);//赋值项目定义号
        List<ProjectPlanArrage> projectPlanList = PackagingUtil.getProjectPlanArrageList(planArrage,projectList);
        //当前项目与配网项目经理安排项目会合
        List<ProjectPlanArrage> summaryService = projectPlanActService.getSummaryService(projectPlanList, listAss);
        for (ProjectPlanArrage planArrage1:summaryService){
            planArrage1.preInsert();
        }
        request.getSession().setAttribute("summaryList",summaryService);
        request.getSession().setAttribute("planAct",act);
        model.addAttribute("act",act);
        return "modules/sg/managementcenter/projectPlanArrage/act/constructionManageAct";
    }
    //施工单位项目经理安排具体时间页面   返回constructionDateList
    @RequestMapping(value = "planDate")
    public String planDate(Model model){
        return "modules/sg/managementcenter/projectPlanArrage/act/constructionDateList";
    }
    /*
        树形+表格 展示  施工单位项目经理列表
     */
    //施工单位项目经理 -- 左侧树形表格展示 session(summaryList) 页面（constructionManageAct.jsp）
    @ResponseBody
    @RequestMapping(value = "bootstrapConstructionTreeTable")
    public List<Map<String,Object>> getConstructionArrageNoPlan(ProjectPlanArrage projectPlanArrage,HttpServletRequest request){
        //创建树形表格
        List<Map<String,Object>> objects = Lists.newArrayList();
        List<ProjectPlanArrage> projectPlans = (List<ProjectPlanArrage>)request.getSession().getAttribute("summaryList");
//        List<ProjectPlanArrage> planArrageList = new ArrayList<ProjectPlanArrage>();
//        String name = UserUtils.getUser().getName();
//        for (ProjectPlanArrage p:projectPlans){
//            if (p.getArrageFlag().equals("0")){
//                if (null!=p.getConstructionUnit()){
//                    if (p.getConstructionUnit().equals(name)){
//                        planArrageList.add(p);
//                    }
//                }
//            }
//        }
        List<Map<String, Object>> bookStrapTree = BookStrapTreeUtil.getAllBookStrapTree(objects, projectPlans,"2");
        return bookStrapTree;
    }
    //施工单位项目经理 右侧表格 session(summaryList) 页面（constructionManageAct.jsp）
    @ResponseBody
    @RequestMapping(value = "initConstructionArragePlanProject")
    public Map<String, Object> initConstructionArragePlanProject(ProjectPlanArrage projectPlanArrage,Model model,HttpServletRequest request,HttpServletResponse response){
        projectPlanArrage.setArrageFlag("1");
        projectPlanArrage.setWhetherStatus("0");
        List<ProjectPlanArrage> projectPlans = (List<ProjectPlanArrage>)request.getSession().getAttribute("summaryList");
        Page<ProjectPlanArrage> page = findPageListCons(new Page<ProjectPlanArrage>(request, response),projectPlanArrage,projectPlans);
        projectPlanArrageService.getSortPowerPackage(page.getList());
        return getBootstrapData(page);
    }
    //施工单位项目经理安排时间列表 session(summaryList) 页面(constructionDateList)
    @ResponseBody
    @RequestMapping(value = "planDateTable")
    public Map<String, Object> planDateTable(ProjectPlanArrage projectPlanArrage,HttpServletRequest request,HttpServletResponse response){
        projectPlanArrage.setArrageFlag("1");
        projectPlanArrage.setWhetherStatus("0");
        List<ProjectPlanArrage> projectPlans = (List<ProjectPlanArrage>)request.getSession().getAttribute("summaryList");
        Page<ProjectPlanArrage> page = findPageListCons(new Page<ProjectPlanArrage>(request, response),projectPlanArrage,projectPlans);
        projectPlanArrageService.getSortPowerPackage(page.getList());
        return getBootstrapData(page);
    }

    public Page<ProjectPlanArrage> findPageListCons(Page<ProjectPlanArrage> page, ProjectPlanArrage entity,List<ProjectPlanArrage> list) {
        dataRuleFilter(entity);
        entity.setPage(page);
        List<ProjectPlanArrage> planArrages = new ArrayList<ProjectPlanArrage>();
        for (ProjectPlanArrage projectPlanArrage:list){
            if (entity.getWhetherStatus().equals(projectPlanArrage.getWhetherStatus())&&entity.getArrageFlag().equals(projectPlanArrage.getArrageFlag())){
                if (null != projectPlanArrage.getBackToStauts() && projectPlanArrage.getBackToStauts().equals("2")) {
                    projectPlanArrage.setHtmlStatus("2");
                }
                planArrages.add(projectPlanArrage);
            }
        }
        page.setList(planArrages);
        return page;
    }

    /*
        施工单位项目经理 【操作】 按钮
     */
    //页面(constructionManageAct.jsp)【安排项目计划】按钮--施工单位项目经理
    @ResponseBody
    @RequestMapping(value = "consPlanArranage")
    public Result getConsPlanArranage(ProjectPlanArrage projectPlanArrage,String ids,HttpServletRequest request){
        Result j = new Result();
        try{
            //得到拼接id
            List<String> strings = PackagingUtil.getString(ids);
            //获得安排月份
            Date mouthDate = (Date) request.getSession().getAttribute("mouthDate");
            //获取安排的项目
            List<ProjectPlanArrage> projectPlans = (List<ProjectPlanArrage>)request.getSession().getAttribute("summaryList");
            if (null!=projectPlans&&!projectPlans.isEmpty()){
                //安排计划
                projectPlanArrageService.getConsPlanArranageService(projectPlans,strings,mouthDate);
            }
//            List<ProjectPlanArrage> planArrages = new ArrayList<ProjectPlanArrage>();
//            String name = UserUtils.getUser().getName();
//            for (ProjectPlanArrage planArrage:projectPlans){
//                if (planArrage.getArrageFlag().equals("0")){
//                    if (null!=planArrage.getConstructionUnit()){
//                        if (planArrage.getConstructionUnit().equals(name)){
//                            planArrages.add(planArrage);
//                        }
//                    }
//                }
//            }
            List<Map<String,Object>> objects = Lists.newArrayList();
            List<Map<String, Object>> bookStrapTree = BookStrapTreeUtil.getAllBookStrapTree(objects, projectPlans,"2");
            j.setMapListTree(bookStrapTree);
            j.setSuccess(true);
            j.setMessage("安排计划成功");
            return j;
        }catch (Exception e){
            e.printStackTrace();
        }
        j.setSuccess(false);
        j.setMessage("安排计划失败");
        return j;
    }
    //页面(constructionManageAct.jsp)删除项目 -- 填写备注--施工单位项目经理 -- 填写完成后由配网项目经理同意删除
    @ResponseBody
    @RequestMapping(value = "deletePlanArrange")
    public Result deletePlanArrange(String ids,String backToText,HttpServletRequest request){
        Result ajaxJson = new Result();
        try {
            //获取ids的集合
            String comment = URLDecoder.decode(backToText, "UTF-8");
            List<String> strings = PackagingUtil.getString(ids);
            //获取安排的项目
            List<ProjectPlanArrage> projectPlans = (List<ProjectPlanArrage>)request.getSession().getAttribute("summaryList");
            //验证是否允许
            boolean flag = projectPlanArrageService.deleteJudgePlanArrange(projectPlans, strings);
            if (!flag){
                ajaxJson.setSuccess(false);
                ajaxJson.setMessage("只允许删除本人的项目!");
                return ajaxJson;
            }
            //删除项目
            projectPlanArrageService.deletePlanArrange(projectPlans,strings,comment);
            List<Map<String,Object>> objects = Lists.newArrayList();
            List<ProjectPlanArrage> planArrages = new ArrayList<ProjectPlanArrage>();
            for (ProjectPlanArrage planArrage:projectPlans){
                if (planArrage.getArrageFlag().equals("0")){
                    planArrages.add(planArrage);
                }
            }
            List<Map<String, Object>> bookStrapTree = BookStrapTreeUtil.getAllBookStrapTree(objects, planArrages,"2");
            ajaxJson.setMapListTree(bookStrapTree);
            ajaxJson.setSuccess(true);
            ajaxJson.setMessage("备注成功");
            return ajaxJson;
        }catch (Exception e){
            ajaxJson.setSuccess(false);
            ajaxJson.setMessage("备注失败!");
            e.printStackTrace();
        }
        return ajaxJson;
    }

    //页面(constructionManageAct.jsp)删除项目 -- 填写备注--施工单位项目经理 -- 填写完成后由配网项目经理同意删除
    @ResponseBody
    @RequestMapping(value = "deletePlanArrangeAll")
    public Result deletePlanArrangeAll(String ids,HttpServletRequest request){
        Result ajaxJson = new Result();
        try {
            //获取ids的集合
            List<String> strings = PackagingUtil.getString(ids);
            //获取安排的项目
            List<ProjectPlanArrage> projectPlans = (List<ProjectPlanArrage>)request.getSession().getAttribute("summaryList");
            //验证是否允许
            boolean flag = projectPlanArrageService.deleteJudgePlanArrange(projectPlans, strings);
            if (!flag){
                ajaxJson.setSuccess(false);
                ajaxJson.setMessage("只允许删除本人的项目!");
                return ajaxJson;
            }
            //删除项目
            boolean b = projectPlanArrageService.deletePlanArrangeAll(projectPlans, strings);
            List<Map<String,Object>> objects = Lists.newArrayList();
            List<ProjectPlanArrage> planArrages = new ArrayList<ProjectPlanArrage>();
            for (ProjectPlanArrage planArrage:projectPlans){
                if (planArrage.getArrageFlag().equals("0")){
                    planArrages.add(planArrage);
                }
            }
            List<Map<String, Object>> bookStrapTree = BookStrapTreeUtil.getAllBookStrapTree(objects, planArrages,"2");
            ajaxJson.setMapListTree(bookStrapTree);
            if (b){
                ajaxJson.setSuccess(true);
                ajaxJson.setMessage("删除成功");
            }else {
                ajaxJson.setSuccess(false);
                ajaxJson.setMessage("请选择本人增加的项目进行删除,如不是,删除请备注(列表文字颜色区分)!");
            }
            return ajaxJson;
        }catch (Exception e){
            ajaxJson.setSuccess(false);
            ajaxJson.setMessage("删除失败!");
            e.printStackTrace();
        }
        return ajaxJson;
    }
    //页面（constructionDateList.jsp）施工单位项目经理 -- 安排时间
    @ResponseBody
    @RequestMapping(value = "addtime")
    public AjaxJson getAddtime(ProjectPlanArrage projectPlanArrage,HttpServletRequest request){
        AjaxJson ajaxJson = new AjaxJson();
        List<ProjectPlanArrage> projectPlans = (List<ProjectPlanArrage>)request.getSession().getAttribute("summaryList");
        try {
            for (ProjectPlanArrage planArrage:projectPlans){
                if (projectPlanArrage.getId().equals(planArrage.getId())){
                    planArrage.setProjectDate(projectPlanArrage.getProjectDate());
                    break;
                }
            }
            ajaxJson.setSuccess(true);
            ajaxJson.setMsg("安排时间成功");
            return ajaxJson;
        }catch (Exception e){
            e.printStackTrace();
        }
        ajaxJson.setSuccess(false);
        ajaxJson.setMsg("安排时间失败");
        return ajaxJson;
    }
    //页面（constructionDateList.jsp） 确定安排计划时间验证--施工单位项目经理
    @ResponseBody
    @RequestMapping(value = "judgeAddTime")
    public AjaxJson getJudgeAddTime(HttpServletRequest request){
        AjaxJson ajaxJson = new AjaxJson();
        List<ProjectPlanArrage> projectPlans = (List<ProjectPlanArrage>)request.getSession().getAttribute("summaryList");
        try {
            boolean judgePlanTimeNULL = projectPlanActService.getJudgePlanTimeNULL(projectPlans);
            if (judgePlanTimeNULL){
                ajaxJson.setSuccess(false);
                ajaxJson.setMsg("1");
                return ajaxJson;
            }
            boolean flag = projectPlanActService.getJudgePlanTimeService(projectPlans);
            if (flag){
                ajaxJson.setSuccess(false);
                ajaxJson.setMsg("时间不一致");
                return ajaxJson;
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return ajaxJson;
    }

    /*
        配网项目经理审核（第二个节点）----------------------------------------------------------------------------03
     */
    /*
        配网项目经理审核（第二个节点）返回页面
     */
    //配网项目经理审核（第二个节点）--审核界面 页面（netWorkManageAct.jsp）
    @RequestMapping(value = "disList")
    public String getDisList(ProjectActProclnsAss projectActProclnsAss, Model model,HttpServletRequest request){
        //得到当前流程
        Act act = projectActProclnsAss.getAct();
        act.setId(projectActProclnsAss.getId());
        projectActProclnsAss.setProcInsId(act.getProcInsId());//赋值项目id
        //配网项目经理安排的项目
        List<ProjectActProclnsAss> listAss = projectPlanActService.findListAss(projectActProclnsAss);//查找当前流程节点的项目
        //目前安排的存入session中
        request.getSession().setAttribute("networkActProInsAss",listAss);
        //项目已经安排项目定义号拼接
        String projectId = projectPlanActService.getMapProjectId(listAss);
        MaterialProject materialProject = new MaterialProject();
        materialProject.setArrageProject("0");
        materialProject.setArrageProject1("1");
        //获取已经安排的年份
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy");
        for (ProjectActProclnsAss proclnsAss:listAss){
            if (null!=proclnsAss.getProjectMonthDate()){
                String year = simpleDateFormat.format(proclnsAss.getProjectMonthDate());
                materialProject.setAttributionYear(year);
                break;
            }
        }
        //初始安排计划项目列表
        List<ProjectPlanArrage> planArrageList = projectPlanArrageService.getProjectPlanArrageList(materialProject);
        //根据项目名称查询人员
        List<ProjectAssignment> listAssignment = projectPlanArrageService.findListAssignment(planArrageList);
        //获得最终集合
        List<ProjectPlanArrage> projectPlanArrageList = projectPlanArrageService.getPlanArrageList(planArrageList, listAssignment);
        //区分开关与项目--整体集合
        List<ProjectPlanArrage> projectList = projectPlanArrageService.getProjectList(projectPlanArrageList);
        //开关 - 项目 统一集合 用WhetherStatus区分
        ProjectPlanArrage planArrage = new ProjectPlanArrage();
        planArrage.setProjectNumber(projectId);//赋值项目定义号
        List<ProjectPlanArrage> projectPlanList = PackagingUtil.getProjectPlanArrageList(planArrage,projectList);
        //当前项目与配网项目经理汇合项目汇总
        List<ProjectPlanArrage> planArrages = projectPlanActService.getNetworkService(projectPlanList,listAss);
        for (ProjectPlanArrage planArrage1:planArrages){
            planArrage1.preInsert();
        }
        request.getSession().setAttribute("networkList",planArrages);
        request.getSession().setAttribute("networkPlanAct",act);
        model.addAttribute("act",act);
        return "modules/sg/managementcenter/projectPlanArrage/act/netWorkManageAct";
    }
    //设置开关
    //设置停电开关页面 ---配网项目经理审核（第二个节点）页面（netActPowerList2.jsp）
    @RequestMapping(value = "netWorkElectrified")
    public String netWorkElectrified(ProjectPlanArrage projectPlanArrage){
        return "modules/sg/managementcenter/projectPlanArrage/act/netActPowerList2";
    }
    //安排计划设置时间 --返回页面 --- 配网项目经理审核（第二个节点）(newDateList.jsp)
    @RequestMapping(value = "planNetDate")
    public String planNetDate(Model model){
        return "modules/sg/managementcenter/projectPlanArrage/act/newDateList";
    }

    /*
        配网项目经理（第二个节点）树形+表格展示汇总
     */
    //所有未安排的计划-树形表格展示（左侧）--配网项目经理（第二个节点）
    @ResponseBody
    @RequestMapping(value = "bootstrapNetWorkTreeTable")
    public List<Map<String,Object>> getNetWorkArrageNoPlan(ProjectPlanArrage projectPlanArrage,HttpServletRequest request){
        //创建树形表格
        List<Map<String,Object>> objects = Lists.newArrayList();
        List<ProjectPlanArrage> projectPlans = (List<ProjectPlanArrage>)request.getSession().getAttribute("networkList");
        List<ProjectPlanArrage> planArrageList = new ArrayList<ProjectPlanArrage>();
        for (ProjectPlanArrage p:projectPlans){
            if (p.getArrageFlag().equals("0")){
                planArrageList.add(p);
            }
        }
        List<Map<String, Object>> bookStrapTree = BookStrapTreeUtil.getAllBookStrapTree(objects, planArrageList,"1");
        return bookStrapTree;
    }
    //右侧表格展示已经安排数据--配网项目经理（第二个节点）
    @ResponseBody
    @RequestMapping(value = "initNetWorkArragePlanProject")
    public Map<String, Object> initNetWorkArragePlanProject(ProjectPlanArrage projectPlanArrage,Model model,HttpServletRequest request,HttpServletResponse response){
        projectPlanArrage.setArrageFlag("1");
        projectPlanArrage.setWhetherStatus("0");
        List<ProjectPlanArrage> projectPlans = (List<ProjectPlanArrage>)request.getSession().getAttribute("networkList");
        Page<ProjectPlanArrage> page = findPageListNetWorkArragePlan(new Page<ProjectPlanArrage>(request, response),projectPlanArrage,projectPlans);
        projectPlanArrageService.getSortPowerPackage(page.getList());
        return getBootstrapData(page);
    }
    public Page<ProjectPlanArrage> findPageListNetWorkArragePlan(Page<ProjectPlanArrage> page, ProjectPlanArrage entity,List<ProjectPlanArrage> list) {
        dataRuleFilter(entity);
        entity.setPage(page);
        List<ProjectPlanArrage> planArrages = new ArrayList<ProjectPlanArrage>();
        if (null!=list){
            for (ProjectPlanArrage projectPlanArrage:list){
                if (entity.getWhetherStatus().equals(projectPlanArrage.getWhetherStatus())&&entity.getArrageFlag().equals(projectPlanArrage.getArrageFlag())){
                    if (null!=projectPlanArrage.getBackToStauts()&&projectPlanArrage.getBackToStauts().equals("2")){
                        projectPlanArrage.setHtmlStatus("2");//新增项目
                    }
                    if (null!=projectPlanArrage.getBackToText()&&!"".equals(projectPlanArrage.getBackToText())){
                        projectPlanArrage.setHtmlStatus("1");//删除项目
                    }
                    planArrages.add(projectPlanArrage);
                }
            }
        }
        page.setList(planArrages);
        return page;
    }
    //安排带电项目展示form --配网项目经理（第二个节点）--人工选择带电页面（netActPowerList2）
    @ResponseBody
//	@RequiresPermissions("managementcenter:materialproject:list")
    @RequestMapping(value = "dataPower2")
    public Map<String, Object> dataPower2(ProjectPlanArrage projectPlanArrage, HttpServletRequest request, HttpServletResponse response, Model model) {
        projectPlanArrage.setArrageFlag("1");
        projectPlanArrage.setWhetherStatus("0");
        List<ProjectPlanArrage> projectPlans = (List<ProjectPlanArrage>)request.getSession().getAttribute("networkList");
        Page<ProjectPlanArrage> page = findPageList(new Page<ProjectPlanArrage>(request, response),projectPlanArrage,projectPlans);
        projectPlanArrageService.getSortPowerPackage(page.getList());
        return getBootstrapData(page);
    }
    //安排计划时间列表 --配网项目经理（第二个节点）--人工选择带电页面（newDateList）
    @ResponseBody
    @RequestMapping(value = "planNetDateTable")
    public Map<String, Object> planNetDateTable(ProjectPlanArrage projectPlanArrage,HttpServletRequest request,HttpServletResponse response){
        projectPlanArrage.setArrageFlag("1");
        projectPlanArrage.setWhetherStatus("0");
        List<ProjectPlanArrage> projectPlans = (List<ProjectPlanArrage>)request.getSession().getAttribute("networkList");
        Page<ProjectPlanArrage> page = findPageList(new Page<ProjectPlanArrage>(request, response),projectPlanArrage,projectPlans);
        projectPlanArrageService.getSortPowerPackage(page.getList());
        return getBootstrapData(page);
    }
    /*
        配网项目经理（第二个节点） 【按钮】 操作
     */
    //页面（netWorkManageAct.jsp） 安排项目计划  ---配网项目经理（第二个节点）
    @ResponseBody
    @RequestMapping(value = "unNetWorkplanned")
    public Result unNetWorkplanned(ProjectPlanArrage projectPlanArrage,String ids,HttpServletRequest request){
        Result j = new Result();
        List<String> strings = PackagingUtil.getString(ids);
        j.setSuccess(false);
        j.setMessage("安排计划项目失败");
        boolean flag = true;
        try {
            //获取项目信息
            List<ProjectPlanArrage> projectPlans = (List<ProjectPlanArrage>)request.getSession().getAttribute("networkList");
            if (!projectPlans.isEmpty()&&!strings.isEmpty()){
                projectPlanArrageService.getNetWorkUnplannedService(projectPlans,strings);
            }else {
                flag = false;
                j.setSuccess(false);
                j.setMessage("安排计划项目失败");
            }
            List<ProjectPlanArrage> planArrages = new ArrayList<ProjectPlanArrage>();
            for (ProjectPlanArrage planArrage:projectPlans){
                if (planArrage.getArrageFlag().equals("0")){
                    planArrages.add(planArrage);
                }
            }
            List<Map<String,Object>> objects = Lists.newArrayList();
            List<Map<String, Object>> bookStrapTree = BookStrapTreeUtil.getAllBookStrapTree(objects, planArrages,"1");
            j.setMapListTree(bookStrapTree);
            if (flag){
                j.setSuccess(true);
                j.setMessage("安排计划成功");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return j;
    }
    //页面（netWorkManageAct.jsp） 退回操作--配网项目经理（第二个节点）
    @ResponseBody
    @RequestMapping(value = "deleteNetWork")
    public Result getNetWorkTheRoBack(ProjectPlanArrage projectPlanArrage, String ids, HttpServletRequest request){
        Result j = new Result();
        j.setSuccess(true);
        j.setMessage("退回成功");
        List<String> strings = PackagingUtil.getString(ids);
        try {
            //获取项目信息
            List<ProjectPlanArrage> projectPlans = (List<ProjectPlanArrage>)request.getSession().getAttribute("networkList");
            if (!projectPlans.isEmpty()&&!strings.isEmpty()){
                projectPlanArrageService.getNetWorkSecond(projectPlans,strings);
            }else {
                j.setSuccess(false);
                j.setMessage("退回计划项目失败");
            }
            List<ProjectPlanArrage> planArrages = new ArrayList<ProjectPlanArrage>();
            for (ProjectPlanArrage planArrage:projectPlans){
                if (planArrage.getArrageFlag().equals("0")){
                    planArrages.add(planArrage);
                }
            }
            List<Map<String,Object>> objects = Lists.newArrayList();
            List<Map<String, Object>> bookStrapTree = BookStrapTreeUtil.getAllBookStrapTree(objects, planArrages,"1");
            j.setMapListTree(bookStrapTree);
            j.setSuccess(true);
            j.setMessage("退回计划成功");
        }catch (Exception e){
            e.printStackTrace();
        }
        return j;
    }
    //页面（netWorkManageAct.jsp）安排停电打包  --- 配网项目经理（第二个节点）
    @ResponseBody
    @RequestMapping(value = "unNetplannedPackage")
    public Result getUnNetplannedPackage(ProjectPlanArrage projectPlanArrage,String ids,HttpServletRequest request){
        Result j = new Result();
        List<String> strings = PackagingUtil.getString(ids);
        j.setSuccess(false);
        j.setMessage("停电打包失败");
        boolean flag = true;
        try {

            //获取项目信息
            List<ProjectPlanArrage> projectPlans = (List<ProjectPlanArrage>)request.getSession().getAttribute("networkList");
            if (!projectPlans.isEmpty()&&!strings.isEmpty()){
                projectPlanArrageService.getUnplannedPowerPackage(projectPlans,strings);
            }else {
                flag = false;
                j.setSuccess(false);
                j.setMessage("停电打包失败");
            }
            List<ProjectPlanArrage> planArrages = new ArrayList<ProjectPlanArrage>();
            for (ProjectPlanArrage planArrage:projectPlans){
                if (planArrage.getArrageFlag().equals("0")){
                    planArrages.add(planArrage);
                }
            }
            List<Map<String,Object>> objects = Lists.newArrayList();
            List<Map<String, Object>> bookStrapTree = BookStrapTreeUtil.getAllBookStrapTree(objects, planArrages,"1");
            j.setMapListTree(bookStrapTree);
            if (flag){
                j.setSuccess(true);
                j.setMessage("停电打包成功");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return j;
    }
    //页面（netWorkManageAct.jsp） 取消停电打包  --- 配网项目经理（第二个节点）
    @ResponseBody
    @RequestMapping(value = "cancelNetPackage")
    public Result getCancelNetPackage(ProjectPlanArrage projectPlanArrage,String ids,HttpServletRequest request){
        Result j = new Result();
        List<String> strings = PackagingUtil.getString(ids);
        boolean flag = true;
        try {
            //获取项目信息
            List<ProjectPlanArrage> projectPlans = (List<ProjectPlanArrage>)request.getSession().getAttribute("networkList");
            if (!projectPlans.isEmpty()&&!strings.isEmpty()){
                projectPlanArrageService.getCancelPowerPackage(projectPlans,strings);
                j.setSuccess(true);
                j.setMessage("取消停电包成功");
            }
            List<ProjectPlanArrage> planArrages = new ArrayList<ProjectPlanArrage>();
            for (ProjectPlanArrage planArrage:projectPlans){
                if (planArrage.getArrageFlag().equals("0")){
                    planArrages.add(planArrage);
                }
            }
            List<Map<String,Object>> objects = Lists.newArrayList();
            List<Map<String, Object>> bookStrapTree = BookStrapTreeUtil.getAllBookStrapTree(objects, planArrages,"1");
            j.setMapListTree(bookStrapTree);
        }catch (Exception e){
            e.printStackTrace();
            j.setSuccess(false);
            j.setMessage("取消停电包失败");
        }
        return j;
    }
    //页面（netWorkManageAct.jsp） 发起人备注 -- 配网项目经理（第二个节点）
    @ResponseBody
    @RequestMapping(value = "netRemarksBack")
    public Result getNetRemarksBack(ProjectPlanArrage projectPlanArrage, String ids, HttpServletRequest request){
        Result j = new Result();
        j.setSuccess(true);
        j.setMessage("备注成功");
        List<String> strings = PackagingUtil.getString(ids);
        boolean flag = true;
        try {
            String comment = URLDecoder.decode(projectPlanArrage.getRemarks(), "UTF-8");
            projectPlanArrage.setRemarks(comment);
            //获取项目信息
            List<ProjectPlanArrage> projectPlans = (List<ProjectPlanArrage>)request.getSession().getAttribute("networkList");
            if (!projectPlans.isEmpty()&&!strings.isEmpty()){
                projectPlanArrageService.getRemarksBack(projectPlans,strings,projectPlanArrage);
            }else {
                flag = false;
                j.setSuccess(false);
                j.setMessage("备注失败");
            }
            List<ProjectPlanArrage> planArrages = new ArrayList<ProjectPlanArrage>();
            for (ProjectPlanArrage planArrage:projectPlans){
                if (planArrage.getArrageFlag().equals("0")){
                    planArrages.add(planArrage);
                }
            }
            List<Map<String,Object>> objects = Lists.newArrayList();
            List<Map<String, Object>> bookStrapTree = BookStrapTreeUtil.getAllBookStrapTree(objects, planArrages,"1");
            j.setMapListTree(bookStrapTree);
            if (flag){
                j.setSuccess(true);
                j.setMessage("备注成功");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return j;
    }
    //页面(netActPowerList2.jsp)   检验开关  -- 配网项目经理（第二个节点）
    @ResponseBody
    @RequestMapping(value = "inspectionNetWork")
    public AjaxJson inspectionNetWork(String ids,ProjectPlanArrage projectPlanArrage,Model model,HttpServletRequest request,HttpServletResponse response){
        List<ProjectPlanArrage> projectPlans = (List<ProjectPlanArrage>)request.getSession().getAttribute("networkList");
        List<ProjectPlanArrage> planArrages = projectPlanArrageService.inspectionService(ids, projectPlans);
        request.getSession().setAttribute("networkList",planArrages);
        AjaxJson j = new AjaxJson();
        j.setSuccess(true);
        j.setMsg("检验成功");
        return j;
    }
    //页面(netActPowerList2.jsp) 停电开关确定按钮 -- 配网项目经理（第二个节点）
    @ResponseBody
    @RequestMapping(value = "sureNetWorkInspection")
    public AjaxJson sureNetWorkInspection(String ids,ProjectPlanArrage projectPlanArrage,Model model,HttpServletRequest request,HttpServletResponse response){
        AjaxJson j = new AjaxJson();
        List<ProjectPlanArrage> projectPlans = (List<ProjectPlanArrage>)request.getSession().getAttribute("networkList");
        List<ProjectPlanArrage> planArrages = projectPlanArrageService.inspectionService(ids, projectPlans);
        request.getSession().setAttribute("networkList",planArrages);
        boolean flag = true;
        for (ProjectPlanArrage planArrage:planArrages){
            if (planArrage.getHtmlStatus().equals("1")){
                flag = false;
                break;
            }
        }
        if (flag){
            j.setSuccess(false);
        }else {
            j.setSuccess(true);
        }
        return j;
    }
    //页面（newDateList.jsp）添加 -- 修改 时间 -- 配网项目经理（第二个节点）
    @ResponseBody
    @RequestMapping(value = "addtimeNet")
    public AjaxJson getAddtimeNet(ProjectPlanArrage projectPlanArrage,HttpServletRequest request){
        AjaxJson ajaxJson = new AjaxJson();
        List<ProjectPlanArrage> projectPlans = (List<ProjectPlanArrage>)request.getSession().getAttribute("networkList");
        try {
            for (ProjectPlanArrage planArrage:projectPlans){
                if (projectPlanArrage.getId().equals(planArrage.getId())){
                    planArrage.setProjectDate(projectPlanArrage.getProjectDate());
                    break;
                }
            }
            ajaxJson.setSuccess(true);
            ajaxJson.setMsg("安排时间成功");
            return ajaxJson;
        }catch (Exception e){
            e.printStackTrace();
        }
        ajaxJson.setSuccess(false);
        ajaxJson.setMsg("安排时间失败");
        return ajaxJson;
    }
    //页面（newDateList.jsp） 验证时间 -- 配网项目经理（第二个节点）
    @ResponseBody
    @RequestMapping(value = "judgeAddTimeNet")
    public AjaxJson getJudgeAddTimeNet(HttpServletRequest request){
        AjaxJson ajaxJson = new AjaxJson();
        List<ProjectPlanArrage> projectPlans = (List<ProjectPlanArrage>)request.getSession().getAttribute("networkList");
        try {
//            boolean judgePlanTimeNULL = projectPlanActService.getJudgePlanTimeNULL(projectPlans);
//            if (judgePlanTimeNULL){
//                ajaxJson.setSuccess(false);
//                ajaxJson.setMsg("1");
//                return ajaxJson;
//            }
            boolean flag = projectPlanActService.getJudgePlanTimeService(projectPlans);
            if (flag){
                ajaxJson.setSuccess(false);
                ajaxJson.setMsg("时间不一致");
                return ajaxJson;
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return ajaxJson;
    }


    /*
        流程发起方法 -----------------------------------------------------------04
     */
    //保存并且发送流程 -- 初始配网项目经理 ---->>>施工单位项目经理（多个）
    @ResponseBody
    @RequestMapping(value = "save")
    public AjaxJson saveStartupProcess(ProjectPlanArrage projectPlanArrage,Model model,HttpServletRequest request,HttpServletResponse response) throws Exception{
        AjaxJson ajaxJson= new AjaxJson();
        ajaxJson.setSuccess(true);
        //得到所有项目
        List<ProjectPlanArrage> projectPlans = (List<ProjectPlanArrage>)request.getSession().getAttribute("projectPlan");
        //安排项目 --- 得到安排项目
        List<ProjectPlanArrage> planArrages = new ArrayList<ProjectPlanArrage>();
        for (ProjectPlanArrage planArrage:projectPlans){
            if (planArrage.getArrageFlag().equals("1")&&planArrage.getWhetherStatus().equals("0")){
                planArrages.add(planArrage);
            }
        }
        //发送流程---施工单位项目经理
        projectPlanActService.startProjectArrangeAct(planArrages);
        ajaxJson.setMsg("流程发起成功");
        return ajaxJson;
    }

    //施工单位项目经理  ------->>> 配网项目经理（第二个节点）
    @ResponseBody
    @RequestMapping(value = "conRunProInsId")
    public AjaxJson conRunProInsId(String flag,String comment,HttpServletRequest request) {
        AjaxJson j = new AjaxJson();
        try {
            Act act = (Act)request.getSession().getAttribute("planAct");
            String comment1 = URLDecoder.decode(comment, "UTF-8");
            act.setComment(comment1);
            act.setFlag(flag);
            //项目经理安排的时间
            List<ProjectPlanArrage> presentActProInsAss = (List<ProjectPlanArrage>)request.getSession().getAttribute("presentActProInsAss");
            //得到项目--所以项目（包括安排和待安排的）
            List<ProjectPlanArrage> projectPlans = (List<ProjectPlanArrage>)request.getSession().getAttribute("summaryList");
            projectPlanActService.conRunProInsId(act,projectPlans,presentActProInsAss);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        j.setSuccess(true);
        j.setMsg("审批成功");
        return j;
    }

    //配网项目经理（第二个节点）结束流程 -----> 发送通知给 配网运行人员
    @ResponseBody
    @RequestMapping(value = "newWorkRunProInsId")
    public AjaxJson newWorkRunProInsId(String flag,String comment,HttpServletRequest request) {
        AjaxJson j = new AjaxJson();
        try {
            Act act = (Act)request.getSession().getAttribute("networkPlanAct");
            String comment1 = URLDecoder.decode(comment, "UTF-8");
            act.setComment(comment1);
            act.setFlag(flag);
            //得到项目
            List<ProjectPlanArrage> projectPlans = (List<ProjectPlanArrage>)request.getSession().getAttribute("networkList");
            projectPlanActService.newWorkRunProInsId(act,projectPlans);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        j.setSuccess(true);
        j.setMsg("审批成功");
        return j;
    }

    /*
        导入 --- 导出 -------------------------------------------------------------------------05
     */
    //导入 --- 配网项目经理导入月计划安排
    @ResponseBody
    @RequestMapping(value = "import")
    public AjaxJson importFile(@RequestParam("file") MultipartFile file, HttpServletResponse response, HttpServletRequest request){
        AjaxJson j = new AjaxJson();
        try {
            StringBuilder failureMsg = new StringBuilder();
            ImportUtil importUtil = new ImportUtil(file,0,0);
            List<ProjectPlanArrage> materProUtil = projectPlanArrageService.getMaterProUtil(importUtil);
            projectPlanArrageService.insertList(materProUtil);
            j.setMsg( "已成功导入项目"+materProUtil.size()+"条计划安排记录记录");
        } catch (Exception e) {
            j.setSuccess(false);
            j.setMsg("导入失败！失败信息："+e.getMessage());
        }
        return j;
    }

    /**
     * 导出excel文件-----配网运行人员导出
     */
    @ResponseBody
    @RequestMapping(value = "export")
    public AjaxJson exportFile(ProjectActProclnsAss projectActProclnsAss, HttpServletRequest request, HttpServletResponse response) {
        String name = UserUtils.getUser().getName();
        projectActProclnsAss.setOperationUnit(name);
        AjaxJson j = new AjaxJson();
        try {
            String fileName = "项目计划安排表"+ DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";
            Page<ProjectActProclnsAss> page = findPageRunList(new Page<ProjectActProclnsAss>(request, response, -1), projectActProclnsAss);
            new ExportExcel("项目计划安排表", ProjectActProclnsAss.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;
    }
    public Page<ProjectActProclnsAss> findPageRunList(Page<ProjectActProclnsAss> page, ProjectActProclnsAss entity) {
        dataRuleFilter(entity);
        entity.setPage(page);
        page.setList(projectPlanActService.findListAss(entity));
        return page;
    }


    //运行项目经理--审核界面
//    @RequestMapping(value = "runList")
//    public String getRunList(ProjectActProclnsAss projectActProclnsAss, Model model,HttpServletRequest request){
//        //得到当前流程
//        Act act = projectActProclnsAss.getAct();
//        act.setId(projectActProclnsAss.getId());
//        projectActProclnsAss.setProcInsId(act.getProcInsId());//赋值项目id
//        model.addAttribute("act",act);
//        model.addAttribute("projectActProclnsAss",projectActProclnsAss);
//        return "modules/sg/managementcenter/projectPlanArrage/act/runListManageAct";
//    }

    //初始安排的计划项目--跳转树形操作列表--配网运行人员
    @ResponseBody
    @RequestMapping(value = "runListArragePlanProject")
    public Map<String, Object> runListArragePlanProject(ProjectActProclnsAss projectActProclnsAss,Model model,HttpServletRequest request,HttpServletResponse response){
        String name = UserUtils.getUser().getName();
        projectActProclnsAss.setOperationUnit(name);
        Page<ProjectActProclnsAss> page = findPageRunList(new Page<ProjectActProclnsAss>(request, response),projectActProclnsAss);
        return getBootstrapData(page);
    }


    //主页面 删除按钮
    @ResponseBody
    @RequestMapping(value = "getDeleteMainAll")
    public AjaxJson getDeleteMainAll(String ids,String projectNames){
        AjaxJson ajaxJson = new AjaxJson();
        try {
            String comment = URLDecoder.decode(projectNames, "UTF-8");
            List<String> idList = new ArrayList<String>();
            List<String> list = new ArrayList<>();
            if (ids.contains(",")){
                String[] split = ids.split(",");
                String[] names = comment.split(",");
                for (String s:split){
                    idList.add(s);
                }
                for (String name:names){
                    list.add(name);
                }
            }else {
                list.add(comment);
                idList.add(ids);
            }
            projectDailyPlanService.updateNoMartailDaily(list);
            projectPlanArrageService.deleteMainAll(idList);
            ajaxJson.setSuccess(true);
            ajaxJson.setMsg("退回库成功");
            return ajaxJson;
        }catch (Exception e){
            e.printStackTrace();
        }
        ajaxJson.setSuccess(false);
        ajaxJson.setMsg("退回库失败");
        return ajaxJson;
    }

    //运行单位人员发起流程到配网项目经理
//    @ResponseBody
//    @RequestMapping(value = "runListRunProInsId")
//    public AjaxJson runListRunProInsId(Act act) {
//        AjaxJson j = new AjaxJson();
//        try {
//            String comment1 = URLDecoder.decode(act.getComment(), "UTF-8");
//            act.setComment(comment1);
//            projectPlanActService.runListRunProInsId(act);
//        } catch (UnsupportedEncodingException e) {
//            e.printStackTrace();
//        }
//        j.setSuccess(true);
//        j.setMsg("审批成功");
//        return j;
//    }

    //运行项目经理--审核界面
//    @RequestMapping(value = "disList2")
//    public String getDisList2(ProjectActProclnsAss projectActProclnsAss, Model model,HttpServletRequest request){
//        //得到当前流程
//        Act act = projectActProclnsAss.getAct();
//        act.setId(projectActProclnsAss.getId());
//        projectActProclnsAss.setProcInsId(act.getProcInsId());//赋值项目id
//        model.addAttribute("act",act);
//        model.addAttribute("projectActProclnsAss",projectActProclnsAss);
//        return "modules/sg/managementcenter/projectPlanArrage/act/disList2ManageAct";
//    }

    //初始安排的计划项目--跳转树形操作列表--配网项目经理
//    @ResponseBody
//    @RequestMapping(value = "disList2ArragePlanProject")
//    public Map<String, Object> disList2ArragePlanProject(ProjectActProclnsAss projectActProclnsAss,Model model,HttpServletRequest request,HttpServletResponse response){
//        Page<ProjectActProclnsAss> page = findPageRunList(new Page<ProjectActProclnsAss>(request, response),projectActProclnsAss);
//        return getBootstrapData(page);
//    }

    //运行单位人员发起流程到配网项目经理
//    @ResponseBody
//    @RequestMapping(value = "disList2RunProInsId")
//    public AjaxJson disList2RunProInsId(Act act) {
//        AjaxJson j = new AjaxJson();
//        try {
//            String comment1 = URLDecoder.decode(act.getComment(), "UTF-8");
//            act.setComment(comment1);
//            ProjectActProclnsAss proclnsAss = new ProjectActProclnsAss();
//            proclnsAss.setProcInsId(act.getProcInsId());
//            List<ProjectActProclnsAss> listAss = projectPlanActService.findListAss(proclnsAss);
//            projectPlanActService.disList2ProInsId(act,listAss);
//        } catch (UnsupportedEncodingException e) {
//            e.printStackTrace();
//        }
//        j.setSuccess(true);
//        j.setMsg("审批成功");
//        return j;
//    }



}
