package com.zcloud.controller.hiddenDangerCheckStandard;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.zcloud.controller.base.BaseController;
import com.zcloud.entity.Page;
import com.zcloud.entity.PageData;
import com.zcloud.entity.system.Dictionaries;
import com.zcloud.logs.LogAnno;
import com.zcloud.service.bus.HiddenUserService;
import com.zcloud.service.check.ListManagerService;
import com.zcloud.service.check.RecordItemService;
import com.zcloud.service.corp.CorpInfoService;
import com.zcloud.service.hidden.HiddenCheckService;
import com.zcloud.service.hidden.HiddenSchemeService;
import com.zcloud.service.hidden.HiddenService;
import com.zcloud.service.hiddenDangerCheckStandard.*;
import com.zcloud.service.inspection.SafetyEnvironmentalService;
import com.zcloud.service.sms.SMSLogService;
import com.zcloud.service.sms.SMSManagementService;
import com.zcloud.service.system.DepartmentService;
import com.zcloud.service.system.DictionariesService;
import com.zcloud.service.system.ImgFilesService;
import com.zcloud.service.system.UsersService;
import com.zcloud.util.*;
import com.zcloud.util.message.MessageService;
import net.sf.json.JSONArray;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
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 org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 说明：隐患 作者：luoxiaobao 时间：2021-01-04 官网：www.zcloudchina.com
 */
@Controller
@RequestMapping("/customHidden")
public class CustomHiddenController extends BaseController {

    @Autowired
    private CustomHiddenService customHiddenService;
    @Autowired
    private CustomHiddenUserService customHiddenUserService; // 隐患相关人员信息
    @Autowired
    private ImgFilesService imgFilesService;
    @Autowired
    private UsersService usersService;
    @Autowired
    private DepartmentService departmentService;
    @Autowired
    private HiddenSchemeService hiddenSchemeService;
    @Autowired
    private CustomHiddenCheckService customHiddenCheckService;
    @Autowired
    private CorpInfoService corpinfoService;
    @Autowired
    private DictionariesService dictionariesService;
    @Autowired
    private CustomService customService;
    @Autowired
    private CustomCheckRecordItemService customCheckRecordItemService;
    @Autowired
    private SendMessageUtil sendMessageUtil;
    @Autowired
    private Smb smb;
    @Autowired
    private SafetyEnvironmentalService safetyenvironmentalService;
    @Autowired
    private MessageService messageService;

    /**
     * 新增
     *
     * @param
     * @throws Exception
     */
    @RequestMapping(value = "/add")
    // @RequiresPermissions("hidden:add")
    @ResponseBody
    @LogAnno(menuType = "双重预防", menuServer = "隐患排查", instructionsOperate = "清单排查", instructionsType = "新增")
    public Object add() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        pd.put("HIDDEN_ID", this.get32UUID()); // 主键
        pd.put("CREATOR", Jurisdiction.getUSER_ID()); // 发现人
        pd.put("HIDDENFINDDEPT", Jurisdiction.getDEPARTMENT_ID());
        pd.put("CREATTIME", DateUtil.date2Str(new Date())); // 发现时间
        pd.put("ISDELETE", "0"); // 是否删除 1 删除 0未删除
        pd.put("ISCONFIRM", "0"); //
        pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID()); // 企业id
        if (pd.get("RECTIFICATIONTYPE") != null && Tools.notEmpty(pd.get("RECTIFICATIONTYPE").toString())) {
            if ("1".equals(pd.get("RECTIFICATIONTYPE").toString())) {
                pd.put("RECTIFICATIONTIME", DateUtil.getDay()); // 整改时间
                pd.put("RECTIFICATIONOR", Jurisdiction.getUSER_ID()); // 整改人
                pd.put("RECTIFICATIONDEPT", Jurisdiction.getDEPARTMENT_ID());
                pd.put("STATE", "4");
            } else {
                pd.put("STATE", "1");

            }
        }
        pd.put("STATE", "0");
        pd.put("SOURCE", "3");
        customHiddenService.save(pd);
        //  立即整改保存检查数据
        if ("4".equals(pd.get("STATE").toString())) {
            PageData hc = new PageData();
            hc.put("HIDDENCHECK_ID", this.get32UUID());
            hc.put("HIDDEN_ID", pd.get("HIDDEN_ID"));
            hc.put("DEPARTMENT_ID", pd.get("HIDDENFINDDEPT"));
            hc.put("USER_ID", pd.get("CREATOR"));
            hc.put("STATUS", "1");
            hc.put("CHECK_TIME", pd.get("CREATTIME").toString().substring(0, 10));
            customHiddenCheckService.save(hc);
        }

        if (pd.get("STATE") != null && Tools.notEmpty(pd.get("STATE").toString()) && !"0".equals(pd.get("STATE").toString())) {
            // 发短信
            PageData mes = new PageData();
            mes.put("RECEIVER_ID", pd.get("RECTIFICATIONOR"));// 收信人userid
            mes.put("templateCode", "SMS_215820677");// 短信模板编码
            mes.put("CORPINFO_ID", pd.get("CORPINFO_ID"));// 企业id

            // 参数集合
            List<PageData> paramsList = new ArrayList<PageData>();
            // 第1个参数
            PageData params1 = new PageData();
            params1.put("name", "time");// 存入短信模板中的参数名称
            params1.put("value", pd.get("RECTIFICATIONDEADLINE"));// 存入上面参数名称所传递的值
            paramsList.add(params1);

            sendMessageUtil.sendMessages(mes, paramsList);
        }

        map.put("result", errInfo);
        map.put("pd", pd);
        return map;
    }

    /**
     * 列表
     *
     * @param page
     * @throws Exception
     */
    @RequestMapping(value = "/listForSafetyEnvironmental")
    // @RequiresPermissions("hidden:list")
    @ResponseBody
    public Object listForSafetyEnvironmental(Page page) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());
        pd = Jurisdiction.getUserDataJurisdiction(pd);
        page.setPd(pd);
        List<PageData> varList = customHiddenService.listForSafetyEnvironmental(page); // 列出Hidden列表
        varList = customHiddenUserService.getHiddebFind(varList);
        for (PageData vector : varList) {
            safetyenvironmentalService.departmentUtil(vector);
        }
        map.put("varList", varList);
        map.put("page", page);
        map.put("result", errInfo);
        return map;
    }

    /**
     * 新增
     *
     * @param
     * @throws Exception
     */
    @RequestMapping(value = "/listAdd")
    @ResponseBody
    @LogAnno(menuType = "双重预防", menuServer = "隐患排查", instructionsOperate = "清单管理", instructionsType = "新增其他隐患")
    public Object listAdd() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        pd.put("HIDDEN_ID", this.get32UUID()); // 主键
        pd.put("CREATOR", Jurisdiction.getUSER_ID()); // 发现人
        pd.put("HIDDENFINDDEPT", Jurisdiction.getDEPARTMENT_ID());
        pd.put("CREATTIME", DateUtil.date2Str(new Date())); // 发现时间
        pd.put("ISDELETE", "0"); // 是否删除 1 删除 0未删除
        pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID()); // 企业id
        if (pd.get("RECTIFICATIONTYPE") != null && Tools.notEmpty(pd.get("RECTIFICATIONTYPE").toString())) {
            if ("1".equals(pd.get("RECTIFICATIONTYPE").toString())) {
                pd.put("RECTIFICATIONTIME", DateUtil.getDay()); // 整改时间
                pd.put("RECTIFICATIONOR", Jurisdiction.getUSER_ID()); // 整改人
                pd.put("RECTIFICATIONDEPT", Jurisdiction.getDEPARTMENT_ID());
            } else {

            }
        }
        pd.put("ISCONFIRM", "0");
		pd.put("SOURCE", "3");
        customHiddenService.save(pd);
        map.put("result", errInfo);
        map.put("pd", pd);
        return map;
    }

    public String getCode() {
        String code = "";
        Random random = new Random();
        for (int i = 0; i < 6; i++) {

            int r = random.nextInt(10); // 每次随机出一个数字（0-9）

            code = code + r; // 把每次随机出的数字拼在一起

        }
        return code;
    }

    /**
     * 删除
     *
     * @param
     * @throws Exception
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    @LogAnno(menuType = "双重预防", menuServer = "隐患排查", instructionsOperate = "清单检查情况", instructionsType = "删除")
    public Object delete() throws Exception {
        Map<String, String> map = new HashMap<String, String>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();

        customHiddenService.delete(pd);
        pd = customHiddenService.findById(pd);
        if (pd.get("SOURCE") != null && Tools.notEmpty(pd.get("SOURCE").toString())
                && "2".equals(pd.get("SOURCE").toString())) {

            PageData ri = new PageData();
            ri.put("ISNORMAL", "0");
            ri.put("CHECKRECORD_ID", pd.get("CHECKRECORD_ID"));
            ri.put("CUSTOM_ID", pd.get("CUSTOM_ID"));
            ri.put("CUSTOM_ITEM_ID", pd.get("CUSTOM_ITEM_ID"));
            customCheckRecordItemService.editIsnormal(ri);
        }
        map.put("result", errInfo); // 返回结果
        return map;
    }

    /**
     * 修改
     *
     * @param
     * @throws Exception
     */
    @RequestMapping(value = "/edit")
    // @RequiresPermissions("hidden:edit")
    @ResponseBody
    public Object edit() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        customHiddenService.editInfo(pd);
        pd = customHiddenService.findById(pd);
        map.put("pd", pd);
        map.put("result", errInfo);
        return map;
    }

    /**
     * 修改
     *
     * @param
     * @throws Exception
     */
    @RequestMapping(value = "/editRec")
    @ResponseBody
    public Object editRec() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        customHiddenService.edit(pd);
        pd = this.customHiddenService.findById(pd);
        // 发短信
        PageData mes = new PageData();
        mes.put("RECEIVER_ID", pd.get("RECTIFICATIONOR"));// 收信人userid
        mes.put("templateCode", "SMS_215820677");// 短信模板编码
        mes.put("CORPINFO_ID", pd.get("CORPINFO_ID"));// 企业id

        // 参数集合
        List<PageData> paramsList = new ArrayList<PageData>();
        // 第1个参数
        PageData params1 = new PageData();
        params1.put("name", "time");// 存入短信模板中的参数名称
        params1.put("value", pd.get("RECTIFICATIONDEADLINE"));// 存入上面参数名称所传递的值
        paramsList.add(params1);

        sendMessageUtil.sendMessages(mes, paramsList);

        map.put("pd", pd);
        map.put("result", errInfo);
        return map;
    }


    @RequestMapping(value = "/editHIDDENLEVEL")
    @ResponseBody
    public Object editHIDDENLEVEL() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        customHiddenService.editHIDDENLEVEL(pd);
        map.put("pd", pd);
        map.put("result", errInfo);
        return map;
    }

    @RequestMapping(value = "/editISCONFIRM")
    @ResponseBody
    @LogAnno(menuType = "双重预防", menuServer = "隐患治理", instructionsOperate = "重大隐患", instructionsType = "确认为重大隐患")
    public Object editISCONFIRM() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        pd.put("ISCONFIRM", '1');
        customHiddenService.editISCONFIRM(pd);
        map.put("pd", pd);
        map.put("result", errInfo);
        return map;
    }

    /**
     * 整改
     *
     * @param
     * @throws Exception
     */
    @RequestMapping(value = "/rectify")
    @ResponseBody
    @Transactional
    @LogAnno(menuType = "双重预防", menuServer = "隐患治理", instructionsOperate = "隐患整改", instructionsType = "整改")
    public Object rectify(@RequestParam(value = "rectify_files", required = false) MultipartFile[] rectify_files,
                          @RequestParam(value = "scheme_files", required = false) MultipartFile[] scheme_files,
                          @RequestParam(value = "plan_files", required = false) MultipartFile[] plan_files) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        PageData corpinfo = new PageData();
        corpinfo.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());
        corpinfo = corpinfoService.findById(corpinfo);
        pd.put("OPERATTIME", DateUtil.date2Str(new Date())); //
        customHiddenService.rectify(pd);
        pd.put("HIDDENSCHEME_ID", this.get32UUID()); // 主键
        hiddenSchemeService.deleteHd(pd);
        if (Tools.notEmpty(pd.get("HAVESCHEME").toString())) {
            pd.put("CREATOR", Jurisdiction.getUSER_ID()); //
            pd.put("CREATTIME", DateUtil.date2Str(new Date())); //
            pd.put("OPERATOR", Jurisdiction.getUSER_ID()); //
            pd.put("OPERATTIME", DateUtil.date2Str(new Date())); //
            pd.put("ISDELETE", "0"); // 是否删除 1 删除 0未删除
            pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID()); // 企业id
//			if (null != file && !file.isEmpty()) {
//				String  ffile = DateUtil.getDays();
//				String filePath = PathUtil.getProjectpath() + Const.FILEPATHFILE + ffile;	//文件上传路径
//				String fileName = FileUpload.fileUp(file, filePath, this.get32UUID());				//执行上传
//				pd.put("FILEPATH", Const.FILEPATHFILE + ffile + "/" + fileName);
//			}
            hiddenSchemeService.save(pd);
        }

        if (rectify_files != null && rectify_files.length > 0) {
            for (int i = 0; i < rectify_files.length; i++) {
                MultipartFile file = rectify_files[i];
//                 保存文件

                String ffile = DateUtil.getDays();
                String fileName = "";                //执0行上传

                if (null != file && !file.isEmpty()) {
                    fileName = this.get32UUID() + file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
                    byte[] bytes = file.getBytes();
                    smb.sshSftp(file, fileName, Const.FILEPATHYHTP + ffile);
                }
                pd.put("IMGFILES_ID", this.get32UUID());
                pd.put("FILEPATH", Const.FILEPATHYHTP + ffile + "/" + fileName);
                pd.put("TYPE", 4);
                pd.put("FOREIGN_KEY", pd.get("HIDDEN_ID"));
                imgFilesService.save(pd);
            }
        }

        if ("1".equals(pd.get("HAVESCHEME")) && scheme_files != null && scheme_files.length > 0) {
            for (int i = 0; i < scheme_files.length; i++) {
                MultipartFile file = scheme_files[i];
//                 保存文件

                String ffile = DateUtil.getDays();
                String fileName = "";                //执0行上传

                if (null != file && !file.isEmpty()) {
                    fileName = this.get32UUID() + file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
                    byte[] bytes = file.getBytes();
                    smb.sshSftp(file, fileName, Const.FILEPATHYHTP + ffile);
                }
                pd.put("IMGFILES_ID", this.get32UUID());
                pd.put("FILEPATH", Const.FILEPATHYHTP + ffile + "/" + fileName);
                pd.put("TYPE", 8);
                pd.put("FOREIGN_KEY", pd.get("HIDDENSCHEME_ID"));
                imgFilesService.save(pd);
            }
        }

        if ("1".equals(pd.get("HAVEPLAN")) && plan_files != null && plan_files.length > 0) {
            for (int i = 0; i < plan_files.length; i++) {
                MultipartFile file = plan_files[i];
//                 保存文件

                String ffile = DateUtil.getDays();
                String fileName = "";                //执0行上传

                if (null != file && !file.isEmpty()) {
                    fileName = this.get32UUID() + file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
                    byte[] bytes = file.getBytes();
                    smb.sshSftp(file, fileName, Const.FILEPATHYHTP + ffile);
                }
                pd.put("IMGFILES_ID", this.get32UUID());
                pd.put("FILEPATH", Const.FILEPATHYHTP + ffile + "/" + fileName);
                pd.put("TYPE", 22);
                pd.put("FOREIGN_KEY", pd.get("HIDDEN_ID"));
                imgFilesService.save(pd);
            }
        }

        this.customHiddenCheckService.delete(pd);

        if(Tools.notEmpty(pd.getString("CHECKOR"))){//判断验收人是否空，否就发送站内信
            PageData hiddenPd = customHiddenService.findById(pd);
            messageService.sendMessageByParameter("HIDDEN_MAIL_004","友情提示：有一条隐患需要验收",
                    hiddenPd.getString("CORPINFO_ID"),hiddenPd.getString("RECTIFICATIONOR"),hiddenPd.getString("HIDDEN_ID"),
                    hiddenPd.getString("HIDDENDESCR"),"隐患验收","验收","","");
        }

        PageData checkUser = new PageData();
        checkUser.put("HIDDENCHECK_ID", this.get32UUID()); // 主键
        checkUser.put("HIDDEN_ID", pd.get("HIDDEN_ID"));
        checkUser.put("DEPARTMENT_ID", pd.get("CHECKDEPT"));
        checkUser.put("USER_ID", pd.get("CHECKOR"));
        checkUser.put("STATUS", "0");
        customHiddenCheckService.save(checkUser);
        if (pd.get("OTHER") != null && !pd.get("OTHER").equals("")) {
            List<JSONObject> list = (List<JSONObject>) JSON.parse(pd.get("OTHER").toString());
            for (JSONObject json : list) {
                if (json.get("DEPARTMENT_ID") != null && json.get("DEPARTMENT_ID") != "" && json.get("USER_ID") != null
                        && json.get("USER_ID") != "") {
                    PageData other = new PageData();
                    other.put("HIDDENCHECK_ID", this.get32UUID()); // 主键
                    other.put("HIDDEN_ID", pd.get("HIDDEN_ID"));
                    other.put("DEPARTMENT_ID", json.get("DEPARTMENT_ID"));
                    other.put("USER_ID", json.get("USER_ID"));
                    other.put("STATUS", "0");
                    customHiddenCheckService.save(other);

                    // 发短信
                    PageData mes = new PageData();
                    mes.put("RECEIVER_ID", json.get("USER_ID"));// 收信人userid
                    mes.put("templateCode", "SMS_215800731");// 短信模板编码
                    mes.put("CORPINFO_ID", pd.get("CORPINFO_ID"));// 企业id

                    // 参数集合
                    List<PageData> paramsList = new ArrayList<PageData>();

                    sendMessageUtil.sendMessages(mes, paramsList);

                }
            }
        }

        // 发短信
        PageData mes = new PageData();
        mes.put("RECEIVER_ID", pd.get("CHECKOR"));// 收信人userid
        mes.put("templateCode", "SMS_215800731");// 短信模板编码
        mes.put("CORPINFO_ID", pd.get("CORPINFO_ID"));// 企业id

        // 参数集合
        List<PageData> paramsList = new ArrayList<PageData>();

        sendMessageUtil.sendMessages(mes, paramsList);

        // 给发现人发送短信，提示其进行复查，暂时先用发验证码代替

        map.put("result", errInfo);
        map.put("HIDDENSCHEME_ID", pd.get("HIDDENSCHEME_ID"));
        return map;
    }

    /**
     * 复查
     *
     * @param
     * @throws Exception
     */
    @RequestMapping(value = "/review")
    @ResponseBody
    public Object review() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        customHiddenService.review(pd);
        // 删除整改照片及方案
        if (pd.get("ISPASS") != null && Tools.notEmpty(pd.get("ISPASS").toString())) {
            if ("0".equals(pd.get("ISPASS").toString())) {
                PageData pic = new PageData();
//				List<PageData> picList = new ArrayList<PageData>();
//				pic.put("FOREIGN_KEY", pd.get("HIDDEN_ID"));
//				pic.put("TYPE", "4");
//				picList = imgFilesService.listAll(pic);
//				if (picList != null && picList.size() > 0) {
//					for (PageData deletePic : picList) {
//						File file = new File(PathUtil.getProjectpath() + deletePic.getString("FILEPATH"));
//						file.delete();
//					}
//				}
                imgFilesService.deleteList(pic);
                List<PageData> picsList = new ArrayList<PageData>();
                pic.put("FOREIGN_KEY", pd.get("HIDDENSCHEME_ID"));
                pic.put("TYPE", "8");
//				picsList = imgFilesService.listAll(pic);
//				if (picsList != null && picsList.size() > 0) {
//					for (PageData deletePic : picsList) {
//						File file = new File(PathUtil.getProjectpath() + deletePic.getString("FILEPATH"));
//						file.delete();
//					}
//				}
                hiddenSchemeService.deleteHd(pd);
                imgFilesService.deleteList(pic);

//				List<PageData> planPicList = new ArrayList<PageData>();
//				pic.put("FOREIGN_KEY", pd.get("HIDDEN_ID"));
//				pic.put("TYPE", "22");
//				planPicList = imgFilesService.listAll(pic);
//				if (planPicList != null && planPicList.size() > 0) {
//					for (PageData deletePic : planPicList) {
//						File file = new File(PathUtil.getProjectpath() + deletePic.getString("FILEPATH"));
//						file.delete();
//					}
//				}
                imgFilesService.deleteList(pic);
            }

        }
        map.put("result", errInfo);
        return map;
    }

    /**
     * 验收
     *
     * @param
     * @throws Exception
     */
    @RequestMapping(value = "/check")
    @ResponseBody
    @LogAnno(menuType = "双重预防", menuServer = "隐患治理", instructionsOperate = "隐患验收", instructionsType = "验收")
    public Object check() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        if (pd.get("ISQUALIFIED").equals("1")) {
            pd.put("CHECKOR", Jurisdiction.getUSER_ID());
            PageData pd2 = customHiddenCheckService.findByHidden(pd);
            pd.put("STATUS", 1);
            pd.put("HIDDENCHECK_ID", pd2.get("HIDDENCHECK_ID"));
            pd.put("DEPARTMENT_ID", pd2.get("DEPARTMENT_ID"));
            pd.put("USER_ID", pd2.get("USER_ID"));

            if (Tools.notEmpty(pd2.getString("USER_ID")) && pd.getString("STATUS").equals("1")) {
                messageService.sendMessageByParameter("HIDDEN_MAIL_008", "友情提示：有一条隐患已验收",
                        pd.getString("CORPINFO_ID"), pd.getString("USER_ID"), pd.getString("HIDDEN_ID"),
                        pd.getString("HIDDENDESCR"), "通过", "整改", "", "");
            }

            customHiddenCheckService.edit(pd);

            List<PageData> checkList = customHiddenCheckService.listAll(pd);
            for (PageData check : checkList) {
                if (check.get("STATUS").toString().equals("0")) {
                    map.put("result", errInfo);
                    map.put("check", pd);
                    return map;
                }
            }
            pd.put("CHECKTIME", DateUtil.date2Str(new Date()));
            pd.put("OPERATTIME", DateUtil.date2Str(new Date()));
            customHiddenService.check(pd);

        } else {
            PageData hidden = new PageData();
            hidden.put("HIDDEN_ID", pd.get("HIDDEN_ID"));
            hidden.put("STATE", 1);
            hidden.put("BUHEGE", 1);
            hidden.put("OPERATTIME", DateUtil.date2Str(new Date()));
            customHiddenService.changeState(hidden);

            hidden.put("FOREIGN_KEY", pd.get("HIDDEN_ID"));
            hidden.put("TYPE", 4);
            List<PageData> zgimgs = imgFilesService.listAll(hidden);
            hidden.put("TYPE", 5);
            List<PageData> ysimgs = imgFilesService.listAll(hidden);
            hidden.put("TYPE", 8);
            List<PageData> fsimgs = imgFilesService.listAll(hidden);
            hidden.put("TYPE", 22);
            List<PageData> jsimgs = imgFilesService.listAll(hidden);
            List<PageData> imgs = new ArrayList<PageData>();
            imgs.addAll(zgimgs);
            imgs.addAll(ysimgs);
            imgs.addAll(fsimgs);
            imgs.addAll(jsimgs);
            for (PageData img : imgs) {
                smb.deleteFile(img.getString("FILEPATH"));
                imgFilesService.delete(img);
            }
        }
        map.put("check", pd);
        map.put("result", errInfo);
        return map;
    }

    /**
     * 列表
     *
     * @param page
     * @throws Exception
     */
    @RequestMapping(value = "/list")
    // @RequiresPermissions("hidden:list")
    @ResponseBody
    @LogAnno(menuType = "双重预防", menuServer = "隐患治理", instructionsOperate = "隐患整改", instructionsType = "列表")
    public Object list(Page page) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
//		String DEPARTMENT_ID = Jurisdiction.getDEPARTMENT_ID();
//		String ids = departmentService.getDEPARTMENT_IDS(DEPARTMENT_ID);
//		if(ids!=null && Tools.notEmpty(ids)) {
//			ids = ids.substring(0,ids.lastIndexOf(","));
//			pd.put("DEPARTMENT_IDS", ids.split(","));
//		}
        pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID()); // 企业id
        String KEYWORDS = pd.getString("KEYWORDS"); // 关键词检索条件
        if (Tools.notEmpty(KEYWORDS))
            pd.put("KEYWORDS", KEYWORDS.trim());
        String CREATORNAME = pd.getString("CREATORNAME"); // 关键词检索条件
        if (Tools.notEmpty(CREATORNAME))
            pd.put("CREATORNAME", CREATORNAME.trim());

        String ISQUALIFIED = pd.getString("ISQUALIFIED"); // 关键词检索条件
        if (Tools.notEmpty(ISQUALIFIED))
            pd.put("ISQUALIFIED", ISQUALIFIED.trim());
        String HIDDENLEVELE = pd.getString("HIDDENLEVELE"); // 关键词检索条件
        if (Tools.notEmpty(HIDDENLEVELE))
            pd.put("HIDDENLEVELE", HIDDENLEVELE.trim());
        String STARTTIME = pd.getString("STARTTIME"); // 关键词检索条件
        if (Tools.notEmpty(STARTTIME))
            pd.put("STARTTIME", STARTTIME.trim());
        String STATE = pd.getString("STATE"); // 关键词检索条件
        if (Tools.notEmpty(STATE))
            pd.put("STATE", STATE.trim());
        String ENDTIME = pd.getString("ENDTIME"); // 关键词检索条件
        if (Tools.notEmpty(ENDTIME))
            pd.put("ENDTIME", ENDTIME + " 23:59:59");
        String DISPOSESTATE = pd.getString("DISPOSESTATE"); // 关键词检索条件

        String BISTATE = pd.getString("BISTATE"); // BI页跳转条件
        if (Tools.notEmpty(BISTATE))
            pd.put("BISTATE", BISTATE.trim());
        String IS_DAY = pd.getString("IS_DAY"); // BI页跳转条件
        if (Tools.notEmpty(IS_DAY))
            pd.put("IS_DAY", IS_DAY.trim());
        String IS_WEEK = pd.getString("IS_WEEK"); // BI页跳转条件
        if (Tools.notEmpty(IS_WEEK))
            pd.put("IS_WEEK", IS_WEEK.trim());
        String IS_XUN = pd.getString("IS_XUN"); // BI页跳转条件
        if (Tools.notEmpty(IS_XUN))
            pd.put("IS_XUN", IS_XUN.trim());
        String IS_MONTH = pd.getString("IS_MONTH"); // BI页跳转条件
        if (Tools.notEmpty(IS_MONTH))
            pd.put("IS_MONTH", IS_MONTH.trim());
        String IS_QUARTER = pd.getString("IS_QUARTER"); // BI页跳转条件
        if (Tools.notEmpty(IS_QUARTER))
            pd.put("IS_QUARTER", IS_QUARTER.trim());
        String IS_YEAR = pd.getString("IS_YEAR"); // BI页跳转条件
        if (Tools.notEmpty(IS_YEAR))
            pd.put("IS_YEAR", IS_YEAR.trim());
        if (Tools.notEmpty(DISPOSESTATE)) {
            pd.put("DISPOSESTATE", DISPOSESTATE.trim());
            if ("-1".equals(DISPOSESTATE.trim())) {
                pd.put("ISSUPERVISE", Jurisdiction.getISSUPERVISE());
                pd.put("DEPARTMENT_ID", Jurisdiction.getDEPARTMENT_ID());
                String DEPTIDS = pd.getString("DEPTIDS");
                if (Tools.notEmpty(DEPTIDS)) {
                    String DEPT_IDS[] = DEPTIDS.split(",");
                    pd.put("DEPT_IDS", DEPT_IDS);
                }
                pd.put("USER_ID", Jurisdiction.getUSER_ID());
                PageData cpd = new PageData();
                cpd = usersService.findById(pd);
                pd.put("ISLEADER", cpd.getString("ISLEADER"));
                if (cpd.getString("ISLEADER") != null && cpd.getString("ISLEADER").equals("1")) {
                    String DEPARTMENT_ID = pd.getString("DEPARTMENT_ID");
                    String ids = departmentService.getDEPARTMENT_IDS(DEPARTMENT_ID);
                    ids = pd.getString("DEPARTMENT_ID") + "," + ids;   //把自己部门插入进去
                    if (ids != null && Tools.notEmpty(ids) && ids.lastIndexOf(",") > -1) {
                        ids = ids.substring(0, ids.lastIndexOf(","));
                        pd.put("DEPARTMENT_IDS", ids.split(","));
                    } else {
                        pd.put("DEPARTMENT_IDS", DEPARTMENT_ID);
                    }
                }
            }
            pd.put("SELFUSERID", Jurisdiction.getUSER_ID());
            pd.put("USERDEPT", Jurisdiction.getDEPARTMENT_ID());
        }
        pd.put("ISMAIN", Jurisdiction.getIS_MAIN());
        if (Jurisdiction.getIS_MAIN().equals("0")) {
            String IS_SELF = pd.getString("IS_SELF"); // 关键词检索条件
            if (IS_SELF != null && IS_SELF.equals("1"))
                pd.put("SELF_USER_ID", Jurisdiction.getUSER_ID());
        }
        // 旬
        if (pd.get("IS_XUN") != null && Tools.notEmpty(pd.get("IS_XUN").toString())) {
            // 1-10
            if (DateUtil.timeCalendar(new Date(),
                    DateUtil.fomatDateTime(DateUtil.getYear() + "-" + DateUtil.getMonth() + "-" + "01 00:00:00"),
                    DateUtil.fomatDateTime(DateUtil.getYear() + "-" + DateUtil.getMonth() + "-" + "10 23:59:59"))) {
                pd.put("STARTTIME", DateUtil.getYear() + "-" + DateUtil.getMonth() + "-" + "01 00:00:00");
                pd.put("ENDTIME", DateUtil.getYear() + "-" + DateUtil.getMonth() + "-" + "10 23:59:59");
            }
            // 10-20
            if (DateUtil.timeCalendar(new Date(),
                    DateUtil.fomatDateTime(DateUtil.getYear() + "-" + DateUtil.getMonth() + "-" + "11 00:00:00"),
                    DateUtil.fomatDateTime(DateUtil.getYear() + "-" + DateUtil.getMonth() + "-" + "20 23:59:59"))) {
                pd.put("STARTTIME", DateUtil.getYear() + "-" + DateUtil.getMonth() + "-" + "11 00:00:00");
                pd.put("ENDTIME", DateUtil.getYear() + "-" + DateUtil.getMonth() + "-" + "20 23:59:59");
            }
            // 20-月底
            if (DateUtil.timeCalendar(new Date(),
                    DateUtil.fomatDateTime(DateUtil.getYear() + "-" + DateUtil.getMonth() + "-" + "21 00:00:00"),
                    DateUtil.fomatDateTime(DateUtil.getMonthEndDay() + " 23:59:59"))) {
                pd.put("STARTTIME", DateUtil.getYear() + "-" + DateUtil.getMonth() + "-" + "21 00:00:00");
                pd.put("ENDTIME", DateUtil.getMonthEndDay() + " 23:59:59");
            }
        }
        // 季度
        if (pd.get("IS_QUARTER") != null && Tools.notEmpty(pd.get("IS_QUARTER").toString())) {
            pd.put("STARTTIME", DateUtil.quarterStart() + " 00:00:00");
            pd.put("ENDTIME", DateUtil.quarterEnd() + " 23:59:59");
        }
        page.setPd(pd);

        List<PageData> varList = customHiddenService.list(page); // 列出Hidden列表
        map.put("varList", varList);
        map.put("page", page);
        map.put("result", errInfo);
        return map;
    }

    /**
     * 获取清单风险点
     *
     * @param
     * @throws Exception
     */
    @RequestMapping(value = "/getOtherHidden")
    @ResponseBody
    @LogAnno(menuType = "双重预防", menuServer = "隐患排查", instructionsOperate = "清单管理", instructionsType = "获取其他隐患信息列表")
    public Object getOtherHidden() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        pd.put("USER_ID", Jurisdiction.getUSER_ID());
        String USER_ID = pd.get("USER_ID").toString();
        pd.put("CUSTOM_ID", pd.get("ID"));
        pd = customService.findById(pd);
        if (pd.getString("TYPE").equals("listType0005")) {
            if (DateUtil.timeCalendar(new Date(), DateUtil.fomatDateTime(pd.getString("START_DATE") + " 00:00:00"),
                    DateUtil.fomatDateTime(pd.getString("END_DATE") + " 23:59:59"))) {
                PageData type = new PageData();
                type.put("CUSTOM_ID", pd.get("CUSTOM_ID"));
                type.put("IS_XUN", 1);// 查询方法和旬一样,直接借用
                type.put("STATE", "0");
                type.put("USER_ID", USER_ID);
                type.put("BEGINTIME", pd.getString("START_DATE") + " 00:00:00");
                type.put("ENDTIME", pd.getString("END_DATE") + " 23:59:59");
                List<PageData> hiddenList = customHiddenService.getOtherHidden(type);
                map.put("hiddenList", hiddenList);
            }
            map.put("result", errInfo);
            return map;
        }
        String cycle = pd.getString("PERIODNAME");
        PageData type = new PageData();
        if (cycle.equals("每日")) {
            type.put("CUSTOM_ID", pd.get("CUSTOM_ID"));
            type.put("IS_DAY", 1);
            type.put("STATE", "0");
            type.put("USER_ID", USER_ID);
        } else if (cycle.equals("每周")) {
            type.put("CUSTOM_ID", pd.get("CUSTOM_ID"));
            type.put("IS_WEEK", 1);
            type.put("STATE", "0");
            type.put("USER_ID", USER_ID);
        } else if (cycle.equals("每旬")) {
            // 1-10
            if (DateUtil.timeCalendar(new Date(),
                    DateUtil.fomatDateTime(DateUtil.getYear() + "-" + DateUtil.getMonth() + "-" + "01 00:00:00"),
                    DateUtil.fomatDateTime(DateUtil.getYear() + "-" + DateUtil.getMonth() + "-" + "10 23:59:59"))) {
                type.put("CUSTOM_ID", pd.get("CUSTOM_ID"));
                type.put("IS_XUN", 1);
                type.put("STATE", "0");
                type.put("USER_ID", USER_ID);
                type.put("BEGINTIME", DateUtil.getYear() + "-" + DateUtil.getMonth() + "-" + "01 00:00:00");
                type.put("ENDTIME", DateUtil.getYear() + "-" + DateUtil.getMonth() + "-" + "10 23:59:59");
            }
            // 10-20
            if (DateUtil.timeCalendar(new Date(),
                    DateUtil.fomatDateTime(DateUtil.getYear() + "-" + DateUtil.getMonth() + "-" + "11 00:00:00"),
                    DateUtil.fomatDateTime(DateUtil.getYear() + "-" + DateUtil.getMonth() + "-" + "20 23:59:59"))) {
                type.put("CUSTOM_ID", pd.get("CUSTOM_ID"));
                type.put("IS_XUN", 1);
                type.put("STATE", "0");
                type.put("USER_ID", USER_ID);
                type.put("BEGINTIME", DateUtil.getYear() + "-" + DateUtil.getMonth() + "-" + "11 00:00:00");
                type.put("ENDTIME", DateUtil.getYear() + "-" + DateUtil.getMonth() + "-" + "20 23:59:59");
            }
            // 20-月底
            if (DateUtil.timeCalendar(new Date(),
                    DateUtil.fomatDateTime(DateUtil.getYear() + "-" + DateUtil.getMonth() + "-" + "21 00:00:00"),
                    DateUtil.fomatDateTime(DateUtil.getMonthEndDay() + " 23:59:59"))) {
                type.put("CUSTOM_ID", pd.get("CUSTOM_ID"));
                type.put("IS_XUN", 1);
                type.put("STATE", "0");
                type.put("USER_ID", USER_ID);
                type.put("BEGINTIME", DateUtil.getYear() + "-" + DateUtil.getMonth() + "-" + "21 00:00:00");
                type.put("ENDTIME", DateUtil.getMonthEndDay() + " 23:59:59");
            }

        } else if (cycle.equals("每月")) {
            type.put("CUSTOM_ID", pd.get("CUSTOM_ID"));
            type.put("IS_MONTH", 1);
            type.put("STATE", "0");
            type.put("USER_ID", USER_ID);
        } else if (cycle.equals("每季")) {
            type.put("CUSTOM_ID", pd.get("CUSTOM_ID"));
            type.put("IS_QUARTER", 1);
            type.put("STATE", "0");
            type.put("USER_ID", USER_ID);
        } else if (cycle.equals("半年")) {
            type.put("CUSTOM_ID", pd.get("CUSTOM_ID"));
            type.put("IS_HALFYEAR", 1);
            type.put("STATE", "0");
            type.put("USER_ID", USER_ID);
        } else if (cycle.equals("每年")) {
            type.put("CUSTOM_ID", pd.get("CUSTOM_ID"));
            type.put("IS_YEAR", 1);
            type.put("STATE", "0");
            type.put("USER_ID", USER_ID);
        }

        List<PageData> hiddenList = customHiddenService.getOtherHidden(type);
        map.put("result", errInfo);
        map.put("hiddenList", hiddenList);
        return map;
    }

    /**
     * 获取检查记录风险点
     *
     * @param
     * @throws Exception
     */
    @RequestMapping(value = "/getCheckHidden")
    @ResponseBody
    @LogAnno(menuType = "双重预防", menuServer = "隐患排查", instructionsOperate = "清单检查记录", instructionsType = "获取检查记录风险点")
    public Object getCheckHidden() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        List<PageData> hiddenList = customHiddenService.getOtherHidden(pd);
        map.put("result", errInfo);
        map.put("hiddenList", hiddenList);
        return map;
    }

    /**
     * 去修改页面获取数据
     *
     * @param
     * @throws Exception
     */
    @RequestMapping(value = "/goEdit")
    // @RequiresPermissions("hidden:edit")
    @ResponseBody
    @LogAnno(menuType = "双重预防", menuServer = "隐患排查", instructionsOperate = "清单检查记录", instructionsType = "查看隐患信息")
    public Object goEdit() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        pd = customHiddenService.findById(pd); // 根据ID读取
        PageData pd2 = new PageData();
        pd2.put("FOREIGN_KEY", pd.getString("HIDDEN_ID"));
        pd2.put("TYPE", 3);
        List<PageData> hImgs = imgFilesService.listAll(pd2);// 隐患图片
        pd2.put("TYPE", 4);
        List<PageData> rImgs = imgFilesService.listAll(pd2);// 整改图片
        /*
         * pd2.put("TYPE",5); List<PageData> cImgs = imgFilesService.listAll(pd2);//验收图片
         */ // 查询整改方案
        PageData hs = hiddenSchemeService.findByHdId(pd);
        List<PageData> sImgs = new ArrayList<PageData>();

        if (hs != null && hs.getString("HIDDENSCHEME_ID") != null) {
            PageData pd3 = new PageData();
            pd3.put("FOREIGN_KEY", hs.getString("HIDDENSCHEME_ID"));
            pd3.put("TYPE", 8);
            sImgs = imgFilesService.listAll(pd3);// 方案图片
        }

        List<PageData> pImgs = new ArrayList<PageData>();
        if ("1".equals(pd.get("HAVEPLAN"))) {
            PageData pd3 = new PageData();
            pd3.put("FOREIGN_KEY", hs.getString("HIDDEN_ID"));
            pd3.put("TYPE", 22);
            pImgs = imgFilesService.listAll(pd3);//方案图片
        }

        List<PageData> checkList = customHiddenCheckService.listAll(pd);
        if (checkList != null && checkList.size() > 0) {
            PageData pd3 = new PageData();
            pd3.put("TYPE", 5);
            for (PageData check : checkList) {
                pd3.put("FOREIGN_KEY", check.get("HIDDENCHECK_ID"));
                check.put("cImgs", imgFilesService.listAll(pd3));// 验收图片
            }
        }
        map.put("pd", pd);
        map.put("hs", hs);
        map.put("hImgs", hImgs);
        map.put("rImgs", rImgs);
//		map.put("cImgs", cImgs);
        map.put("sImgs", sImgs);
        map.put("pImgs", pImgs);
        map.put("checkList", checkList);
        // 获取部门下拉树
        List<PageData> zdepartmentPdList = new ArrayList<PageData>();
        PageData dept = new PageData();
        dept.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());
        dept = this.departmentService.findByCorpId(dept);
        String ZDEPARTMENT_ID = dept.getString("DEPARTMENT_ID");

        PageData node = new PageData();
        node.put("id", dept.get("DEPARTMENT_ID"));
        node.put("parentId", dept.get("PARENT_ID"));
        node.put("name", dept.get("NAME"));
        node.put("icon", "../../../assets/images/user.gif");
        zdepartmentPdList.add(node);
        JSONArray arr = JSONArray
                .fromObject(departmentService.listAllDepartmentToSelect(ZDEPARTMENT_ID, zdepartmentPdList));
        map.put("zTreeNodes", (null == arr ? "" : "{\"treeNodes\":" + arr.toString() + "}"));

        map.put("result", errInfo);
        return map;
    }

    /**
     * 首页统计
     *
     * @param
     * @throws Exception
     */
    @RequestMapping(value = "/statistic")
    @ResponseBody
    public Object statistic() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");// 设置日期格式
        Date now = new Date();
        String endDay = sdf.format(now);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(now);
        calendar.add(Calendar.DATE, -15);
        String startDay = sdf.format(calendar.getTime());
        pd.put("START_DAY", startDay);
        pd.put("END_DAY", endDay);
        pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());
        pd.put("HIDDENLEVEL", "hiddenLevel0001");// 一般隐患

        if (pd.get("isBI") == null && Jurisdiction.getIS_MAIN().equals("0")) {
            pd.put("USER_ID", Jurisdiction.getUSER_ID());
        }
        List<PageData> nhds = customHiddenService.hiddenStatisticsByDay(pd);
        pd.put("HIDDENLEVEL", "hiddenLevel0002");// 重大隐患
        List<PageData> zhds = customHiddenService.hiddenStatisticsByDay(pd);

        List<PageData> hdAll = customHiddenService.hiddenStatisticsAll(pd);
        map.put("nhds", nhds);
        map.put("zhds", zhds);
        map.put("hdAll", hdAll);
        map.put("result", errInfo);
        return map;
    }

    /**
     * 首页统计
     *
     * @param
     * @throws Exception
     */
    @RequestMapping(value = "/getBICount")
    @ResponseBody
    public Object getBICount() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());
        // 旬
        if (pd.get("IS_XUN") != null && Tools.notEmpty(pd.get("IS_XUN").toString())) {
            // 1-10
            if (DateUtil.timeCalendar(new Date(),
                    DateUtil.fomatDateTime(DateUtil.getYear() + "-" + DateUtil.getMonth() + "-" + "01 00:00:00"),
                    DateUtil.fomatDateTime(DateUtil.getYear() + "-" + DateUtil.getMonth() + "-" + "10 23:59:59"))) {
                pd.put("STARTTIME", DateUtil.getYear() + "-" + DateUtil.getMonth() + "-" + "01 00:00:00");
                pd.put("ENDTIME", DateUtil.getYear() + "-" + DateUtil.getMonth() + "-" + "10 23:59:59");
            }
            // 10-20
            if (DateUtil.timeCalendar(new Date(),
                    DateUtil.fomatDateTime(DateUtil.getYear() + "-" + DateUtil.getMonth() + "-" + "11 00:00:00"),
                    DateUtil.fomatDateTime(DateUtil.getYear() + "-" + DateUtil.getMonth() + "-" + "20 23:59:59"))) {
                pd.put("STARTTIME", DateUtil.getYear() + "-" + DateUtil.getMonth() + "-" + "11 00:00:00");
                pd.put("ENDTIME", DateUtil.getYear() + "-" + DateUtil.getMonth() + "-" + "20 23:59:59");
            }
            // 20-月底
            if (DateUtil.timeCalendar(new Date(),
                    DateUtil.fomatDateTime(DateUtil.getYear() + "-" + DateUtil.getMonth() + "-" + "21 00:00:00"),
                    DateUtil.fomatDateTime(DateUtil.getMonthEndDay() + " 23:59:59"))) {
                pd.put("STARTTIME", DateUtil.getYear() + "-" + DateUtil.getMonth() + "-" + "21 00:00:00");
                pd.put("ENDTIME", DateUtil.getMonthEndDay() + " 23:59:59");
            }
        }
        // 季度
        if (pd.get("IS_QUARTER") != null && Tools.notEmpty(pd.get("IS_QUARTER").toString())) {
            pd.put("STARTTIME", DateUtil.quarterStart() + " 00:00:00");
            pd.put("ENDTIME", DateUtil.quarterEnd() + " 23:59:59");
        }
        List<PageData> varList = customHiddenService.getBICount(pd);
        if (varList != null && varList.size() > 0) {
            map.put("total", varList.size());
            int checked = 0;
            int uncheck = 0;
            for (PageData hidden : varList) {
                if (hidden.get("STATE").toString().equals("4")) {
                    checked++;
                } else {
                    uncheck++;
                }

            }
            map.put("checked", checked);
            map.put("uncheck", uncheck);
        } else {
            map.put("total", 0);
            map.put("checked", 0);
            map.put("uncheck", 0);
        }

        map.put("result", errInfo);
        return map;
    }

    /**
     * 批量删除
     *
     * @param
     * @throws Exception
     */
    @RequestMapping(value = "/deleteAll")
    // @RequiresPermissions("hidden:del")
    @ResponseBody
    public Object deleteAll() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        String DATA_IDS = pd.getString("DATA_IDS");
        if (Tools.notEmpty(DATA_IDS)) {
            String ArrayDATA_IDS[] = DATA_IDS.split(",");
            customHiddenService.deleteAll(ArrayDATA_IDS);
            errInfo = "success";
        } else {
            errInfo = "error";
        }
        map.put("result", errInfo); // 返回结果
        return map;
    }

    /**
     * * @param
     *
     * @throws Exception
     */
    @RequestMapping(value = "/listAll")
    @ResponseBody
    public Object listAll() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        String DATA_IDS = pd.getString("ids");
        if (Tools.notEmpty(DATA_IDS)) {
            String ArrayDATA_IDS[] = DATA_IDS.split(",");
            pd.put("HIDDEN_IDS", ArrayDATA_IDS);
            List<PageData> varList = customHiddenService.listAll(pd);
            errInfo = "success";
            map.put("varList", varList);
        } else {
            errInfo = "error";
        }
        map.put("result", errInfo); // 返回结果
        return map;
    }

    @RequestMapping(value = "/listAllToPrint")
    @ResponseBody
    public Object listAllToPrint() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        String DATA_IDS = pd.getString("ids");
        if (Tools.notEmpty(DATA_IDS)) {
            String ArrayDATA_IDS[] = DATA_IDS.split(",");
            pd.put("HIDDEN_IDS", ArrayDATA_IDS);
            List<PageData> varList = customHiddenService.listAllToPrint(pd);
            errInfo = "success";
            map.put("varList", varList);
        } else {
            errInfo = "error";
        }
        map.put("result", errInfo); // 返回结果
        return map;
    }

    /**
     * 导出到excel
     *
     * @param
     * @throws Exception
     */
    @RequestMapping(value = "/excel2")
    public ModelAndView exportExcel2() throws Exception {
        ModelAndView mv = new ModelAndView();
        PageData pd = new PageData();
        pd = this.getPageData();
        Map<String, String> sourceMap = new HashMap<>();
        sourceMap.put("1", "隐患快报");
        sourceMap.put("2", "隐患排查");
        sourceMap.put("3", "隐患排查");
        String dicParentId = "5e7cf8620ba54ad89719d0be62133c7a";
        List<Dictionaries> dicList = dictionariesService.listSubDictByParentId(dicParentId);
        Map<String, String> dicMap = new HashMap<>();
        for (Dictionaries pageData : dicList) {
            dicMap.put(pageData.getBIANMA(), pageData.getNAME());
        }
        Map<String, String> stateMap = new HashMap<>();
        stateMap.put("-1", "已过期");
        stateMap.put("0", "未提交");
        stateMap.put("1", "未整改");
        stateMap.put("2", "已整改");
        stateMap.put("3", "已复查");
        stateMap.put("4", "已验收");
        Map<String, String> rectifType = new HashMap<>();
        rectifType.put("1", "立即整改");
        rectifType.put("2", "限期整改");
        PageData corpIdPd = new PageData();
        corpIdPd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());// CORPINFO_ID

        Map<String, String> userMap = new HashMap<>();
        List<PageData> userList = usersService.listAllUser(corpIdPd);
        for (PageData pageData : userList) {
            userMap.put(pageData.getString("USER_ID"), pageData.getString("NAME"));
        }
        Map<String, String> deparMap = new HashMap<>();
        List<PageData> deparList = departmentService.listAll(corpIdPd);
        for (PageData pageData : deparList) {
            deparMap.put(pageData.getString("DEPARTMENT_ID"), pageData.getString("NAME"));
        }

        Map<String, Object> dataMap = new HashMap<String, Object>();
        List<String> titles = new ArrayList<String>();
        titles.add("隐患来源"); // 1
        titles.add("风险点（单元）"); // 2
        titles.add("辨识部位"); // 3
        titles.add("存在风险"); // 4
        titles.add("风险分级"); // 6
        titles.add("检查内容"); // 7
        titles.add("隐患级别"); // 16
        titles.add("隐患状态"); // 17=
        titles.add("隐患描述"); // 8
        titles.add("隐患部位"); // 9
        titles.add("隐患发现部门"); // 9 ````````
        titles.add("发现人"); // 10
        titles.add("发现时间"); // 11
        titles.add("整改类型"); // 10
        titles.add("整改期限"); // 11
        titles.add("图片"); // 11
        dataMap.put("titles", titles);
        pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID()); // 企业id
        List<PageData> varOList = customHiddenService.listAll(pd);

        List<PageData> varList = new ArrayList<PageData>();
        for (int i = 0; i < varOList.size(); i++) {
            PageData vpd = new PageData();
            vpd.put("var1", sourceMap.get(varOList.get(i).getString("SOURCE"))); // 1
            vpd.put("var2", varOList.get(i).getString("RISK_UNIT")); // 2
            vpd.put("var3", varOList.get(i).getString("IDENTIFICATION")); // 3
            vpd.put("var4", varOList.get(i).getString("RISK_DESCR")); // 4
            vpd.put("var5", varOList.get(i).getString("LEVEL")); // 6
            vpd.put("var6", varOList.get(i).getString("CHECK_CONTENT")); // 7
            vpd.put("var7", dicMap.get(varOList.get(i).getString("HIDDENLEVEL"))); // 16
            vpd.put("var8", stateMap.get(varOList.get(i).getString("STATE"))); // 17
            vpd.put("var9", varOList.get(i).getString("HIDDENDESCR")); // 8
            vpd.put("var10", varOList.get(i).getString("HIDDENPART")); // 9
            vpd.put("var11", deparMap.get(varOList.get(i).getString("HIDDENFINDDEPT"))); // 9````````````
            vpd.put("var12", userMap.get(varOList.get(i).getString("CREATOR"))); // 10
            vpd.put("var13", varOList.get(i).getString("CREATTIME")); // 11
            vpd.put("var14", rectifType.get(varOList.get(i).getString("RECTIFICATIONTYPE"))); // 10
            vpd.put("var15", varOList.get(i).getString("RECTIFICATIONDEADLINE")); // 11
            vpd.put("var16", varOList.get(i).getString("HIDDENFINDDEPT")); // 9````````````
            varList.add(vpd);
        }
        dataMap.put("varList", varList);
        dataMap.put("imgIndex", "16");

        ObjectExcelView erv = new ObjectExcelView();
        ObjectExcelImgView erv2 = new ObjectExcelImgView();
        mv = new ModelAndView(erv2, dataMap);
        return mv;
    }

    /**
     * 导出到excel
     *
     * @param
     * @throws Exception
     */
    @RequestMapping(value = "/excelOld")
    public ModelAndView exportExcel() throws Exception {
        ModelAndView mv = new ModelAndView();
        PageData pd = new PageData();
        pd = this.getPageData();

        String dicParentId = "5e7cf8620ba54ad89719d0be62133c7a";
        List<Dictionaries> dicList = dictionariesService.listSubDictByParentId(dicParentId);// 字典
        Map<String, String> dicMap = new HashMap<>();
        for (Dictionaries pageData : dicList) {
            dicMap.put(pageData.getBIANMA(), pageData.getNAME());
        }

        PageData corpIdPd = new PageData();
        corpIdPd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());// CORPINFO_ID
        Map<String, String> userMap = new HashMap<>();// 查看企业下的所有用户，根据用户id匹配信息
        List<PageData> userList = usersService.listAllUser(corpIdPd);
        for (PageData pageData : userList) {
            userMap.put(pageData.getString("USER_ID"), pageData.getString("NAME"));
        }
        Map<String, String> deparMap = new HashMap<>();
        List<PageData> deparList = departmentService.listAll(corpIdPd);// 查看企业下的所有部门，根据部门id匹配信息
        for (PageData pageData : deparList) {
            deparMap.put(pageData.getString("DEPARTMENT_ID"), pageData.getString("NAME"));
        }

        Map<String, String> sourceMap = new HashMap<>();
        sourceMap.put("1", "隐患快报");
        sourceMap.put("2", "隐患排查");
        sourceMap.put("3", "隐患排查");
        Map<String, String> stateMap = new HashMap<>();
        stateMap.put("-1", "已过期");
        stateMap.put("0", "未提交");
        stateMap.put("1", "未整改");
        stateMap.put("2", "已整改");
        stateMap.put("3", "已复查");
        stateMap.put("4", "已验收");
        Map<String, String> rectifType = new HashMap<>();
        rectifType.put("1", "立即整改");
        rectifType.put("2", "限期整改");
        Map<String, Object> haveschemeMap = new HashMap<>();
        haveschemeMap.put("0", "无");
        haveschemeMap.put("1", "有");
        Map<String, Object> ysStatusMap = new HashMap<>();
        ysStatusMap.put("0", "否");
        ysStatusMap.put("1", "是");

        Map<String, Object> dataMap = new HashMap<String, Object>();// 传给导出页面的数据
//		List<String> imgKeyId = new ArrayList<>();// 需要查询图片的id标识信息
        HashSet<String> imgIds = new HashSet<String>();
        pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID()); // 企业id
        String KEYWORDS = pd.getString("KEYWORDS"); // 关键词检索条件
        if (Tools.notEmpty(KEYWORDS)) {
            pd.put("KEYWORDS", KEYWORDS.trim());
        }
        String ISQUALIFIED = pd.getString("ISQUALIFIED"); // 关键词检索条件
        if (Tools.notEmpty(ISQUALIFIED)) {
            pd.put("ISQUALIFIED", ISQUALIFIED.trim());
        }
        String HIDDENLEVELE = pd.getString("HIDDENLEVELE"); // 关键词检索条件
        if (Tools.notEmpty(HIDDENLEVELE)) {
            pd.put("HIDDENLEVELE", HIDDENLEVELE.trim());
        }
        String STARTTIME = pd.getString("STARTTIME"); // 关键词检索条件
        if (Tools.notEmpty(STARTTIME)) {
            pd.put("STARTTIME", STARTTIME.trim());
        }
        String STATE = pd.getString("STATE"); // 关键词检索条件
        if (Tools.notEmpty(STATE)) {
            pd.put("STATE", STATE.trim());
        }
        String ENDTIME = pd.getString("ENDTIME"); // 关键词检索条件
        if (Tools.notEmpty(ENDTIME)) {
            pd.put("ENDTIME", ENDTIME + " 23:59:59");
        }
        String DISPOSESTATE = pd.getString("DISPOSESTATE"); // 关键词检索条件
        if (Tools.notEmpty(DISPOSESTATE)) {
            pd.put("DISPOSESTATE", DISPOSESTATE.trim());
            pd.put("SELFUSERID", Jurisdiction.getUSER_ID());
            pd.put("USERDEPT", Jurisdiction.getDEPARTMENT_ID());
        }
        String IS_SELF = pd.getString("IS_SELF"); // 关键词检索条件
        if (IS_SELF != null && IS_SELF.equals("1")) {
            pd.put("SELF_USER_ID", Jurisdiction.getUSER_ID());
        }
        String DEPTIDS = pd.getString("DEPTIDS");
        if (Tools.notEmpty(DEPTIDS)) {
            String DEPT_IDS[] = DEPTIDS.split(",");
            pd.put("DEPT_IDS", DEPT_IDS);
        }
        // 查看隐患信息
        List<PageData> varOList = customHiddenService.listAll(pd);
        for (PageData pageData : varOList) {
//			imgKeyId.add(pageData.getString("HIDDEN_ID"));
            imgIds.add(pageData.getString("HIDDEN_ID"));
        }

        // 查询整改方案
        List<PageData> schemeList = hiddenSchemeService.listExport(pd);
        Map<String, PageData> schemeMap = new HashMap<>();
        for (PageData pageData : schemeList) {
            schemeMap.put(pageData.getString("HIDDEN_ID"), pageData);
//			imgKeyId.add(pageData.getString("HIDDEN_ID"));
//			imgKeyId.add(pageData.getString("HIDDENSCHEME_ID"));

            imgIds.add(pageData.getString("HIDDENSCHEME_ID"));
        }
        // 验收信息
        List<PageData> checkList = customHiddenCheckService.listExport(pd);
        Map<String, List<PageData>> checkMap = new HashMap<>();
        Integer checkMaxCount = 1;
        for (PageData pageData : checkList) {
            Integer checkCount = 1;
            List<PageData> vaList = new ArrayList<>();
            if (checkMap.containsKey(pageData.get("HIDDEN_ID"))) {
                vaList = checkMap.get(pageData.get("HIDDEN_ID"));
                checkCount = vaList.size();
                if (checkMaxCount < checkCount) {
                    checkMaxCount = checkCount;
                }
            }
            vaList.add(pageData);
            checkMap.put(pageData.get("HIDDEN_ID").toString(), vaList);
//			imgKeyId.add(pageData.getString("HIDDENCHECK_ID"));

            imgIds.add(pageData.getString("HIDDENCHECK_ID"));
        }


//		String[] imgId = new String[imgKeyId.size()];
//		for (int i = 0; i < imgKeyId.size(); i++) {
//			imgId[i] = imgKeyId.get(i);
//		}
//		String[] imgId = new String[imgIds.size()];
//		for(String imgid : imgIds) {
//			imgId[i] = imgid;
//		}
//
        List<String> imgIdList = new ArrayList<>();
        for (String imgid : imgIds) {
            imgIdList.add(imgid);
        }
        PageData imgpd2 = new PageData();
        String[] imgId = imgIdList.toArray(new String[imgIdList.size()]);
        imgpd2.put("ArrayDATA_IDS", imgId);
        List<PageData> imgList = imgFilesService.listAllByIds(imgpd2);

        Map<String, Integer> imgCount = new HashMap<>();
        Integer imgTypeMaxCount1 = 1, imgTypeMaxCount2 = 1, imgTypeMaxCount3 = 1, imgTypeMaxCount4 = 1,
                imgTypeMaxCount5 = 1, imgTypeMaxCount6 = 1, imgTypeMaxCount7 = 1, imgTypeMaxCount8 = 1;

        Map<String, List<String>> imgMap = new HashMap<>();
        for (int i = 0; i < imgList.size(); i++) {
            if (Tools.isEmpty(imgList.get(i).get("TYPE"))) {
                continue;
            }
            if (Tools.isEmpty(imgList.get(i).get("FOREIGN_KEY"))) {
                continue;
            }
            List<String> list = new ArrayList<>();
            String key = imgList.get(i).getString("FOREIGN_KEY") + ";" + imgList.get(i).get("TYPE");
            if (imgMap.containsKey(key)) {
                list = imgMap.get(key);
            }
            list.add(imgList.get(i).getString("FILEPATH"));
            imgMap.put(key, list);
            String imgType = imgList.get(i).get("TYPE").toString();
            Integer count = 1;
            if (imgCount.containsKey(key)) {
                count = imgCount.get(key) + 1;
            }
            if ("1".equals(imgType)) {
                if (imgTypeMaxCount1 < count) {
                    imgTypeMaxCount1 = count;
                }
            }
            if ("2".equals(imgType)) {
                if (imgTypeMaxCount2 < count) {
                    imgTypeMaxCount2 = count;
                }
            }
            if ("3".equals(imgType)) {
                if (imgTypeMaxCount3 < count) {
                    imgTypeMaxCount3 = count;
                }
            }
            if ("4".equals(imgType)) {
                if (imgTypeMaxCount4 < count) {
                    imgTypeMaxCount4 = count;
                }
            }
            if ("5".equals(imgType)) {
                if (imgTypeMaxCount5 < count) {
                    imgTypeMaxCount5 = count;
                }
            }
            if ("6".equals(imgType)) {
                if (imgTypeMaxCount6 < count) {
                    imgTypeMaxCount6 = count;
                }
            }
            if ("7".equals(imgType)) {
                if (imgTypeMaxCount7 < count) {
                    imgTypeMaxCount7 = count;
                }
            }
            if ("8".equals(imgType)) {
                if (imgTypeMaxCount8 < count) {
                    imgTypeMaxCount8 = count;
                }
            }
            imgCount.put(key, count);
        }
        List<PageData> varList = new ArrayList<PageData>();
        for (PageData pageData : varOList) {
            int count = 0;
            PageData vpd = new PageData();
            String hidId = pageData.getString("HIDDEN_ID");
            vpd.put("var" + (1 + count), sourceMap.get(pageData.getString("SOURCE")));
            vpd.put("var" + (2 + count), pageData.getString("RISK_UNIT"));
            vpd.put("var" + (3 + count), pageData.getString("IDENTIFICATION"));
            vpd.put("var" + (4 + count), pageData.getString("RISK_DESCR"));
            vpd.put("var" + (5 + count), pageData.getString("LEVEL"));
            vpd.put("var" + (6 + count), pageData.getString("CHECK_CONTENT"));
            vpd.put("var" + (7 + count), dicMap.get(pageData.getString("HIDDENLEVEL")));
            vpd.put("var" + (8 + count), stateMap.get(pageData.getString("STATE")));
            vpd.put("var" + (9 + count), pageData.getString("HIDDENDESCR"));
            vpd.put("var" + (10 + count), pageData.getString("HIDDENPART"));
            vpd.put("var" + (11 + count), deparMap.get(pageData.getString("HIDDENFINDDEPT")));
            vpd.put("var" + (12 + count), userMap.get(pageData.getString("CREATOR")));
            vpd.put("var" + (13 + count), pageData.getString("CREATTIME"));
            vpd.put("var" + (14 + count), rectifType.get(pageData.getString("RECTIFICATIONTYPE")));
            vpd.put("var" + (15 + count), pageData.getString("RECTIFICATIONDEADLINE"));
            List<String> yhImg = imgMap.get(pageData.getString("HIDDEN_ID") + ";3");
            for (int i = 0; i < imgTypeMaxCount3; i++) {
                if (null != yhImg) {
                    if (i < yhImg.size()) {
                        vpd.put("img" + (16 + i), yhImg.get(i));
                    } else {
                        vpd.put("img" + (16 + i), "");
                    }
                } else {
                    vpd.put("img" + (16 + i), "");
                }

            }
            count += imgTypeMaxCount3;
            vpd.put("var" + (16 + count), pageData.getString("RECTIFYDESCR"));// 整改描述
            vpd.put("var" + (17 + count), deparMap.get(pageData.getString("RECTIFICATIONDEPT")));// 整改部门
            vpd.put("var" + (18 + count), userMap.get(pageData.getString("RECTIFICATIONOR")));// 整改人
            vpd.put("var" + (19 + count), pageData.getString("RECTIFICATIONTIME"));// 整改时间
            List<String> zgImg = imgMap.get(hidId + ";4");// 整改后图片
            for (int i = 0; i < imgTypeMaxCount4; i++) {
                if (null != zgImg) {
                    if (i < zgImg.size()) {
                        vpd.put("img" + (20 + count + i), zgImg.get(i));
                    } else {
                        vpd.put("img" + (20 + count + i), "");
                    }
                } else {
                    vpd.put("img" + (20 + count + i), "");
                }

            }
            count += imgTypeMaxCount4;
            vpd.put("var" + (20 + count), haveschemeMap.get(pageData.getString("HAVESCHEME")));// 整改方案
            if (schemeMap.containsKey(hidId)) {
                PageData schemePd = schemeMap.get(hidId);
                if ("1".equals(pageData.getString("HAVESCHEME"))) {
                    vpd.put("var" + (21 + count), schemePd.getString("SCREENINGDATE"));// 排查日期
                    vpd.put("var" + (22 + count), schemePd.getString("LISTNAME"));// 隐患清单
                    vpd.put("var" + (23 + count), schemePd.getString("GOVERNSTANDARDS"));// 治理标准要求
                    vpd.put("var" + (24 + count), schemePd.getString("GOVERNMETHOD"));// 治理方法
                    vpd.put("var" + (25 + count), schemePd.getString("EXPENDITURE"));// 经费和物资的落实
                    vpd.put("var" + (26 + count), schemePd.getString("PRINCIPAL"));// 负责治理人员
                    vpd.put("var" + (27 + count), schemePd.getString("PROGRAMMING"));// 工时安排
                    vpd.put("var" + (28 + count), schemePd.getString("TIMELIMITFOR"));// 时限要求
                    vpd.put("var" + (29 + count), pageData.getString("FILEPATH"));// 应急预案附件
                    vpd.put("var" + (30 + count), schemePd.getString("JOBREQUIREMENT"));// 工作要求
                    vpd.put("var" + (31 + count), schemePd.getString("OTHERBUSINESS"));// 其他事项
                    List<String> ysImg = imgMap.get(schemePd.getString("HIDDENSCHEME_ID") + ";8");
                    for (int i = 0; i < imgTypeMaxCount8; i++) {
                        if (null != ysImg) {
                            if (i < ysImg.size()) {
                                vpd.put("img" + (32 + count + i), ysImg.get(i));// 方案图片
                            } else {
                                vpd.put("img" + (32 + count + i), "");
                            }
                        } else {
                            vpd.put("img" + (32 + count + i), "");
                        }
                    }

                }
                count += imgTypeMaxCount8;
                if (checkMap.containsKey(hidId)) {
                    List<PageData> check = checkMap.get(hidId);
                    for (PageData pageData2 : check) {
                        vpd.put("var" + (32 + count), ysStatusMap.get(pageData2.getString("CHECKDESCR")));// 验收描述
                        vpd.put("var" + (33 + count), pageData2.getString("STATUS"));// 是否合格
                        vpd.put("var" + (34 + count), pageData2.getString("CHECKDEPTNAME"));// 验收部门
                        vpd.put("var" + (35 + count), pageData2.getString("CHECKORNAME"));// 验收人
                        vpd.put("var" + (36 + count), pageData2.getString("CHECK_TIME"));// 验收时间
//						vpd.put("var"+(37+count),pageData2.getString("HIDDENCHECK_ID"));//验收图片
                        List<String> ysImg = imgMap.get(pageData2.getString("HIDDENCHECK_ID") + ";5");// 整改后图片
                        for (int i = 0; i < imgTypeMaxCount5; i++) {
                            if (null != ysImg) {
                                if (i < ysImg.size()) {
                                    vpd.put("img" + (37 + count + i), ysImg.get(i));
                                } else {
                                    vpd.put("img" + (37 + count + i), "");
                                }
                            } else {
                                vpd.put("img" + (37 + count + i), "");
                            }

                        }
                    }

                }
            }

            varList.add(vpd);
        }

        List<String> titles = new ArrayList<String>();

        titles.add("隐患来源"); // 1
        titles.add("风险点（单元）"); // 2
        titles.add("辨识部位"); // 3
        titles.add("存在风险"); // 4
        titles.add("风险分级"); // 6
        titles.add("检查内容"); // 7
        titles.add("隐患级别"); // 16
        titles.add("隐患状态"); // 17=
        titles.add("隐患描述"); // 8
        titles.add("隐患部位"); // 9
        titles.add("隐患发现部门"); // 9 ````````
        titles.add("发现人"); // 10
        titles.add("发现时间"); // 11
        titles.add("整改类型"); // 10
        titles.add("整改期限"); // 11
        for (int i = 0; i < imgTypeMaxCount3; i++) {
            titles.add("隐患图片"); // 11
        }

        titles.add("整改描述");
        titles.add("整改部门");
        titles.add("整改人");
        titles.add("整改时间");

        for (int i = 0; i < imgTypeMaxCount4; i++) {
            titles.add("整改后图片"); // 11
        }

        titles.add("整改方案");
        titles.add("排查日期");
        titles.add("隐患清单");
        titles.add("治理标准要求");
        titles.add("治理方法");
        titles.add("经费和物资的落实");
        titles.add("负责治理人员");
        titles.add("工时安排");
        titles.add("时限要求");
        titles.add("应急预案附件");
        titles.add("工作要求");
        titles.add("其他事项");
        for (int i = 0; i < imgTypeMaxCount8; i++) {
            titles.add("方案图片"); // 11
        }
        for (int i = 0; i < checkMaxCount; i++) {
            titles.add("验收描述");
            titles.add("是否合格");
            titles.add("验收部门");
            titles.add("验收人");
            titles.add("验收时间");

            for (int j = 0; j < imgTypeMaxCount5; j++) {
                titles.add("验收图片");
            }
        }
        dataMap.put("titles", titles);
        dataMap.put("varList", varList);
        HiddenExcelCompressImg erv2 = new HiddenExcelCompressImg();
        mv = new ModelAndView(erv2, dataMap);
        return mv;
    }

    @RequestMapping(value = "/excel")
    public void exportExcelPro(HttpServletResponse response) throws Exception {
        customHiddenService.createExcel(response, this.getPageData());
    }

    /**
     * app首页获取数量
     *
     * @param page
     * @throws Exception
     */
    @RequestMapping(value = "/getCountByUserId")
    @ResponseBody
    @LogAnno(menuType = "首页", menuServer = "首页", instructionsOperate = "首页", instructionsType = "首页获取数量")
    public Object getCountByUserId(Page page) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        Map<String, Object> hidCount = new HashMap<>();
//		String DEPARTMENT_ID = Jurisdiction.getDEPARTMENT_ID();
//		String ids = departmentService.getDEPARTMENT_IDS(DEPARTMENT_ID);
//		if(ids!=null && Tools.notEmpty(ids)) {
//			ids = ids.substring(0,ids.lastIndexOf(","));
//			pd.put("DEPARTMENT_IDS", ids.split(","));
//		}
        pd.put("userId", Jurisdiction.getUSER_ID()); // 发现人
        Integer dzg = 0;// 待整改 1
        Integer ycq = 0;// 已超期 5
        Integer dfc = 0;// 待复查 2
        Integer yys = 0;// 已验收 4
        // STATE -- 隐患状态 0-未提交 1- 未整改 2-已整改 3-已复查 4-已验收 5-已过期
        if (Tools.notEmpty(pd.get("userId").toString())) {
            if (Jurisdiction.getIS_MAIN().equals("0")) {
                pd.put("SELFUSERID", pd.get("userId"));
            } else if (Jurisdiction.getIS_MAIN().equals("1")) {
                pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());
            }

            List<PageData> rectifiHid = customHiddenService.getCountByRectifiCationorId(pd); // 根据人员id获取整改隐患信息 state 1 5
            for (int i = 0; i < rectifiHid.size(); i++) {
                PageData rec = rectifiHid.get(i);
                if (null == rec.get("STATE")) {
                    continue;
                }
                if (rec.get("STATE").equals("1") || rec.get("STATE").equals("-1")) {
                    dzg++;
                }
            }
            pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());
            pd.put("ISMAIN", Jurisdiction.getIS_MAIN());
            pd.put("ISSUPERVISE", Jurisdiction.getISSUPERVISE());
            pd.put("DEPARTMENT_ID", Jurisdiction.getDEPARTMENT_ID());
            List<PageData> creatorHid = customHiddenService.getCountByCreatorId(pd); // 根据人员id获取发现隐患信息
            for (int i = 0; i < creatorHid.size(); i++) {
                PageData cre = creatorHid.get(i);
                if (null == cre.get("STATE")) {
                    continue;
                }
                if (cre.get("STATE").equals("2")) {
                    dfc++;
                }
                if (cre.get("STATE").equals("4")) {
                    yys++;
                }
                if (cre.get("STATE").equals("-1")) {
                    ycq++;
                }
            }
        }
        hidCount.put("dzg", dzg);
        hidCount.put("ycq", ycq);
        hidCount.put("dfc", dfc);
        hidCount.put("yys", yys);

        map.put("hidCount", hidCount);
        map.put("page", page);
        map.put("result", errInfo);
        return map;
    }

    /**
     * app首页获取数量
     *
     * @param page
     * @throws Exception
     */
    @RequestMapping(value = "/getCountByCorpId")
    @ResponseBody
    public Object getCountByCorpId(Page page) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        Map<String, Object> hidCount = new HashMap<>();
        pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());
        Integer dzg = 0;// 待整改 1
        Integer ycq = 0;// 已超期 5
        Integer dfc = 0;// 待复查 2
        Integer yys = 0;// 已验收 4
        // STATE -- 隐患状态 0-未提交 1- 未整改 2-已整改 3-已复查 4-已验收 5-已过期
        List<PageData> rectifiHid = customHiddenService.getCountByRectifiCationorId(pd); // 根据人员id获取整改隐患信息 state 1 5
        for (int i = 0; i < rectifiHid.size(); i++) {
            PageData rec = rectifiHid.get(i);
            if (null == rec.get("STATE")) {
                continue;
            }
            if (rec.get("STATE").equals("1")) {
                dzg++;
            }
            if (rec.get("STATE").equals("5")) {
                ycq++;
            }
        }
        List<PageData> creatorHid = customHiddenService.getCountByCreatorId(pd); // 根据人员id获取发现隐患信息
        for (int i = 0; i < creatorHid.size(); i++) {
            PageData cre = rectifiHid.get(i);
            if (null == cre.get("STATE")) {
                continue;
            }
            if (cre.get("STATE").equals("2")) {
                dfc++;
            }
            if (cre.get("STATE").equals("4")) {
                yys++;
            }
        }
        hidCount.put("dzg", dzg);
        hidCount.put("ycq", ycq);
        hidCount.put("dfc", dfc);
        hidCount.put("yys", yys);

        map.put("hidCount", hidCount);
        map.put("page", page);
        map.put("result", errInfo);
        return map;
    }

    /**
     * app首页获取数量
     *
     * @param page
     * @throws Exception
     */
    @RequestMapping(value = "/getCountByHiddenType")
    @ResponseBody
    @LogAnno(menuType = "首页", menuServer = "首页", instructionsOperate = "首页", instructionsType = "首页获取数量")
    public Object getCountByHiddenType(Page page) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());
        pd.put("ISMAIN", Jurisdiction.getIS_MAIN());
        pd.put("ISSUPERVISE", Jurisdiction.getISSUPERVISE());
        pd.put("DEPARTMENT_ID", Jurisdiction.getDEPARTMENT_ID());
        String DEPTIDS = pd.getString("DEPTIDS");
        if (Tools.notEmpty(DEPTIDS)) {
            String DEPT_IDS[] = DEPTIDS.split(",");
            pd.put("DEPT_IDS", DEPT_IDS);
        }
        List<PageData> hiddList = customHiddenService.getCountByHiddenType(pd);

        Map<String, Object> hiddMap = new HashedMap();
        for (PageData pageData : hiddList) {
            if (Tools.isEmpty(pageData.get("HIDDENTYPE"))) {
                hiddMap.put("hiddenType0006", pageData.get("count").toString());
            } else {
                hiddMap.put(pageData.get("HIDDENTYPE").toString(), pageData.get("count").toString());
            }
        }
        List<Dictionaries> dicList = dictionariesService.listSubDictByParentId("3babc15144444bdc8d763d0af2bdfff6");
        List valList = new ArrayList();
        Map<String, Object> valMap = new HashedMap();
        for (Dictionaries dictionaries : dicList) {
            valMap = new HashedMap();
            if (hiddMap.containsKey(dictionaries.getBIANMA())) {
                valMap.put("value", hiddMap.get(dictionaries.getBIANMA()));
            } else {
                valMap.put("value", "0");
            }
            valMap.put("name", dictionaries.getNAME());
            valList.add(valMap);
        }
        map.put("hiddenTypeCount", valList);
        map.put("result", errInfo);
        return map;
    }


    /**
     * 首页统计
     *
     * @param
     * @throws Exception
     */
    @RequestMapping(value = "/hiddenSta")
    @ResponseBody
    public Object hiddenSta() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());
        List<String> dates = DateUtil.getHalfYearMonth(true);
        Map<String, Object> dateMap = new HashMap<>();
        pd.put("TYPE", 1);
        pd.put("TIME", dates.get(0));
        List<PageData> allHidden = customHiddenService.getHiddenNum(pd);

        Map<String, PageData> allMap = new HashMap<>();
        for (int i = 0; i < allHidden.size(); i++) {
            allMap.put(allHidden.get(i).getString("TIME"), allHidden.get(i));
        }
        pd.put("TYPE", 2);
        List<PageData> wzgHidden = customHiddenService.getHiddenNum(pd);
        Map<String, PageData> wzgMap = new HashMap<>();
        for (int i = 0; i < wzgHidden.size(); i++) {
            wzgMap.put(wzgHidden.get(i).getString("TIME"), wzgHidden.get(i));
        }
        pd.put("TYPE", 3);
        List<PageData> yzgHidden = customHiddenService.getHiddenNum(pd);
        Map<String, PageData> yzgMap = new HashMap<>();
        for (int i = 0; i < yzgHidden.size(); i++) {
            yzgMap.put(yzgHidden.get(i).getString("TIME"), yzgHidden.get(i));
        }
        pd.put("TYPE", 4);
        List<PageData> yysHidden = customHiddenService.getHiddenNum(pd);
        Map<String, PageData> yysMap = new HashMap<>();
        for (int i = 0; i < yysHidden.size(); i++) {
            yysMap.put(yysHidden.get(i).getString("TIME"), yysHidden.get(i));
        }
        List<String> names = new ArrayList<String>();
        List<String> all = new ArrayList<String>();
        List<String> wzg = new ArrayList<String>();
        List<String> yzg = new ArrayList<String>();
        List<String> yys = new ArrayList<String>();
        for (int i = 0; i < dates.size(); i++) {
            names.add(dates.get(i).substring(dates.get(i).length() - 2, dates.get(i).length()) + "月");
            if (allMap.containsKey(dates.get(i))) {
                PageData hidden = allMap.get(dates.get(i));
                all.add(hidden.get("NUMBER").toString());
            } else {
                all.add("0");
            }
            if (wzgMap.containsKey(dates.get(i))) {
                PageData hidden = wzgMap.get(dates.get(i));
                wzg.add(hidden.get("NUMBER").toString());
            } else {
                wzg.add("0");
            }
            if (yzgMap.containsKey(dates.get(i))) {
                PageData hidden = yzgMap.get(dates.get(i));
                yzg.add(hidden.get("NUMBER").toString());
            } else {
                yzg.add("0");
            }
            if (yysMap.containsKey(dates.get(i))) {
                PageData hidden = yysMap.get(dates.get(i));
                yys.add(hidden.get("NUMBER").toString());
            } else {
                yys.add("0");
            }
        }
        map.put("result", errInfo);
        map.put("names", names);
        map.put("all", all);
        map.put("wzg", wzg);
        map.put("yzg", yzg);
        map.put("yys", yys);
        return map;
    }
}
