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.check.*;
import com.zcloud.service.hiddenDangerCheckStandard.*;
import com.zcloud.service.inspection.DictionaryService;
import com.zcloud.service.offduty.OffDutyService;
import com.zcloud.service.risk.IdentificationPartsService;
import com.zcloud.service.system.DepartmentService;
import com.zcloud.service.system.PostService;
import com.zcloud.service.system.UsersService;
import com.zcloud.util.*;
import org.apache.commons.io.FileUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.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 java.io.File;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
 * 说明：清单管理-隐患排查清单
 * 作者：luoxiaobao
 * 时间：2020-12-30
 * 官网：www.zcloudchina.com
 */
@Controller
@RequestMapping("/hiddenstandardCustom")
public class CustomController extends BaseController {

    @Autowired
    private CustomService customService;
    @Autowired
    private CustomItemService customItemService;
    @Autowired
    private CustomDisableTimeService customDisableTimeService;
    @Autowired
    private DepartmentService departmentService;
    @Autowired
    private CustomCheckRecordService customCheckRecordService;
    @Autowired
    private RecordItemService recordItemService;
    @Autowired
    private CustomStatisticsService customStatisticsService;
    @Autowired
    private IdentificationPartsService identificationPartsService;
    @Autowired
    private ListDisableTimeService listdisabletimeService;
    @Autowired
    private CheckRouteService checkRouteService;
    @Autowired
    private UsersService usersService;
    @Autowired
    private OffDutyService offdutyService;
    @Autowired
    private StandardDictionaryService standardDictionaryService;
    @Autowired
    private DictionaryService dictionaryService;
    @Autowired
    private PostService postService;


    /**
     * 新增
     *
     * @param
     * @throws Exception
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    @Transactional
    @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("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());    //企业
        if (pd.getString("TYPE").equals("listType0006")) {
            pd.put("ISDELETE", "-99");
        } else {
            pd.put("ISDELETE", "0");    //是否删除
        }
        pd.put("CREATOR", Jurisdiction.getUsername());    //添加人
        pd.put("CREATTIME", DateUtil.date2Str(new Date()));    //创建时间
        pd.put("OPERATOR", Jurisdiction.getUsername());    //修改人
        pd.put("OPERATTIME", DateUtil.date2Str(new Date()));    //修改时间
        String listPeriod = pd.getString("PERIOD");
        pd.put("CUSTOM_ID", this.get32UUID());    //主键
        if (pd.get("LISTITEM") != null && !pd.get("LISTITEM").equals("")) {
            List<JSONObject> list = (List<JSONObject>) JSON.parse(pd.get("LISTITEM").toString());
            for (JSONObject json : list) {
                int commonSort = 0;
                String CHECK_CATEGORY_Temp = "";
                String CHECK_ITEM_Temp = "";
                if (Tools.isEmpty(json.get("CHECK_CATEGORY")) || Tools.isEmpty(json.get("CHECK_ITEM"))) {
                    PageData dict = new PageData();
                    dict.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());
                    List<PageData> dictList = standardDictionaryService.list(dict);
                    int maxsortNum = 0;
                    Boolean existCategory = false;
                    for (int j = 0; j < dictList.size(); j++) {
                        if ("1".equals(dictList.get(j).get("DICTIONARY_LEVEL").toString())) {
                            if (!dictList.get(j).get("DICTIONARY_NAME").equals(json.get("CHECK_CATEGORY_NAME"))) {   //如果不存在该字典，获取最大排序号
                                if (maxsortNum < Integer.parseInt(dictList.get(j).getString("DICTIONARY_SORT"))) {
                                    maxsortNum = Integer.parseInt(dictList.get(j).getString("DICTIONARY_SORT"));
                                }
                            } else {
                                CHECK_CATEGORY_Temp = dictList.get(j).get("DICTIONARY_ID").toString();
                                existCategory = true;
                            }
                        }
                    }
                    if (!existCategory) {
                        dict.put("DICTIONARY_ID", this.get32UUID());
                        dict.put("DICTIONARY_LEVEL", "1");
                        dict.put("DICTIONARY_SORT", maxsortNum + 1);
                        dict.put("DICTIONARY_NAME", json.get("CHECK_CATEGORY_NAME"));
                        dict.put("PARENT_ID", "0");
                        dict.put("PARENT_IDS", dict.get("DICTIONARY_ID"));
                        dict.put("DICTIONARY_NAMES", dict.get("DICTIONARY_NAME"));
                        dict.put("DICTIONARY_SOURCE", "2");
                        dict.put("ISDELETE", "0");
                        dict.put("CREATOR_ID", Jurisdiction.getUSER_ID());
                        dict.put("CREATOR_NAME", Jurisdiction.getUsername());
                        dict.put("CREATE_TIME", DateUtil.date2Str(new Date()));
                        dict.put("OPERATOR_ID", Jurisdiction.getUSER_ID());
                        dict.put("OPERATOR_NAME", Jurisdiction.getUsername());
                        dict.put("OPERATE_TIME", DateUtil.date2Str(new Date()));
                        dict.put("DELETEOR_ID", Jurisdiction.getUSER_ID());
                        dict.put("DELETEOR_NAME", Jurisdiction.getUsername());
                        dict.put("DELETE_TIME", DateUtil.date2Str(new Date()));
                        standardDictionaryService.save(dict);
                        CHECK_CATEGORY_Temp = dict.get("DICTIONARY_ID").toString();
                    }
                    PageData dictItem = new PageData();
                    dictItem.putAll(dict);
                    maxsortNum = 0;
                    Boolean existItem = false;
                    for (int j = 0; j < dictList.size(); j++) {
                        if ("2".equals(dictList.get(j).get("DICTIONARY_LEVEL").toString())) {
                            if (!dictList.get(j).get("DICTIONARY_NAME").equals(json.get("CHECK_ITEM_NAME"))) {   //如果不存在该字典，获取最大排序号
                                if (maxsortNum < Integer.parseInt(dictList.get(j).getString("DICTIONARY_SORT"))) {
                                    maxsortNum = Integer.parseInt(dictList.get(j).getString("DICTIONARY_SORT"));
                                }
                            } else {
                                CHECK_ITEM_Temp = dictList.get(j).get("DICTIONARY_ID").toString();
                                existItem = true;
                            }
                        }
                    }
                    commonSort = maxsortNum == 0 ? 1 : maxsortNum;
                    if (!existItem) {
                        dictItem.put("DICTIONARY_ID", this.get32UUID());
                        dictItem.put("DICTIONARY_LEVEL", "2");
                        dictItem.put("DICTIONARY_SORT", maxsortNum + 1);
                        dictItem.put("DICTIONARY_NAME", json.get("CHECK_ITEM_NAME"));
                        dictItem.put("PARENT_ID", dict.get("DICTIONARY_ID"));
                        dictItem.put("PARENT_IDS", dictItem.getString("DICTIONARY_ID") + ',' + dict.getString("DICTIONARY_ID"));
                        dictItem.put("DICTIONARY_NAMES", dictItem.getString("DICTIONARY_NAME") + ',' + dict.getString("DICTIONARY_NAME"));
                        standardDictionaryService.save(dictItem);
                        CHECK_ITEM_Temp = dictItem.get("DICTIONARY_ID").toString();
                    }
                }
                PageData itme = new PageData();
                itme.put("CUSTOM_ITEM_ID", this.get32UUID());    //主键
                itme.put("CUSTOM_ID", pd.get("CUSTOM_ID"));
                itme.put("CHECK_CATEGORY", Tools.isEmpty(json.get("CHECK_CATEGORY")) ? CHECK_CATEGORY_Temp : json.get("CHECK_CATEGORY"));
                itme.put("CHECK_ITEM", Tools.isEmpty(json.get("CHECK_ITEM")) ? CHECK_ITEM_Temp : json.get("CHECK_ITEM"));
                itme.put("CHECK_CONTENT", json.get("CHECK_CONTENT"));
                itme.put("CHECK_STANDARD", json.get("CHECK_STANDARD"));
                itme.put("REFERENCE_BASIS", json.get("REFERENCE_BASIS"));
                itme.put("CHECK_QUALIFIED", json.get("CHECK_QUALIFIED"));
                itme.put("CHECK_UNQUALIFIED", json.get("CHECK_UNQUALIFIED"));
                itme.put("OPERATION_TYPE", json.get("OPERATION_TYPE"));
                itme.put("COMMON_ITEM_SORT", commonSort);
                itme.put("COMMON_ID", json.get("COMMON_ID") == null ? "" : json.get("COMMON_ID"));
                itme.put("COMMON_ITEM_ID", json.get("COMMON_ITEM_ID") == null ? "" : json.get("COMMON_ITEM_ID"));
                itme.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());    //企业
                itme.put("ISDELETE", "0");    //是否删除
                itme.put("CREATOR_ID", Jurisdiction.getUSER_ID());    //添加人id
                itme.put("CREATOR_NAME", Jurisdiction.getUsername());    //添加人
                itme.put("CREATE_TIME", DateUtil.date2Str(new Date()));    //创建时间
                itme.put("OPERATOR_ID", Jurisdiction.getUSER_ID());    //修改人
                itme.put("OPERATOR_NAME", Jurisdiction.getUsername());    //修改时间
                itme.put("OPERATE_TIME", DateUtil.date2Str(new Date()));    //修改时间
                itme.put("DELETEOR_ID", Jurisdiction.getUSER_ID());    //添加人id
                itme.put("DELETEOR_NAME", Jurisdiction.getUsername());    //添加人
                itme.put("DELETE_TIME", DateUtil.date2Str(new Date()));    //删除时间
                customItemService.save(itme);
            }
        }
        pd.put("PERIOD", listPeriod);
        customService.save(pd);
        // 修改清单统计
        if (!pd.getString("TYPE").equals("listType0006")) {
            if (pd.get("TYPE") != null && Tools.notEmpty(pd.get("TYPE").toString())) {
                pd.put("CUSTOMSTATISTICS_ID", this.get32UUID());    //主键
                if ("listType0005".equals(pd.get("TYPE").toString())) {
                    pd.put("STARTTIME", pd.get("START_DATE").toString() + " 00:00:00");
                    pd.put("ENDTIME", pd.get("END_DATE").toString() + " 23:59:59");
                    pd.put("PERIOD", null);
                    PageData statistics = customStatisticsService.findByCondition(pd);
                    if (statistics != null && statistics.get("CUSTOMSTATISTICS_ID") != null) {
                        statistics.put("NOTEXAMINEDNUM", Integer.parseInt(statistics.get("NOTEXAMINEDNUM").toString()) + 2);
                        customStatisticsService.edit(statistics);
                    } else {
                        pd.put("NOTEXAMINEDNUM", 2);
                        customStatisticsService.save(pd);
                    }
                } else {
                    if (pd.get("PERIOD") != null && Tools.notEmpty(pd.get("PERIOD").toString())) {
                        String period = pd.get("PERIOD").toString();
                        switch (period) {
                            case "checkPeriod0001"://每日
                                pd.put("STARTTIME", DateUtil.getDay() + " 00:00:00");
                                pd.put("ENDTIME", DateUtil.getDay() + " 23:59:59");
                                break;

                            case "checkPeriod0002"://每周
                                pd.put("STARTTIME", DateUtil.getWeekStart());
                                pd.put("ENDTIME", DateUtil.getWeekEnd());
                                break;

                            case "checkPeriod0003"://每旬
                                String year = DateUtil.getYear().toString();
                                String month = DateUtil.getMonth().toString();
                                Integer day = Integer.parseInt(DateUtil.getOnlyDay().toString());
                                String startTime = year + "-" + month + "-";
                                String endTime = year + "-" + month + "-";
                                if (day <= 10) {
                                    startTime = startTime + "01 00:00:00";
                                    endTime = endTime + "10 23:59:59";
                                } else if (day > 10 && day <= 20) {
                                    startTime = startTime + "11 00:00:00";
                                    endTime = endTime + "20 23:59:59";
                                } else {
                                    startTime = startTime + "21 00:00:00";
                                    endTime = DateUtil.getMonthEndDay() + " 23:59:59";
                                }
                                pd.put("STARTTIME", startTime);
                                pd.put("ENDTIME", endTime);
                                break;

                            case "checkPeriod0004"://每月
                                pd.put("STARTTIME", DateUtil.getMonthFirstDay() + " 00:00:00");
                                pd.put("ENDTIME", DateUtil.getMonthEndDay() + " 23:59:59");
                                break;

                            case "checkPeriod0005"://每季
                                pd.put("STARTTIME", DateUtil.quarterStart() + " 00:00:00");
                                pd.put("ENDTIME", DateUtil.quarterEnd() + " 23:59:59");
                                break;

                            case "checkPeriod0006"://每年
                                pd.put("STARTTIME", DateUtil.getCurrYearFirst() + " 00:00:00");
                                pd.put("ENDTIME", DateUtil.getCurrYearLast() + " 23:59:59");
                                break;

                            case "checkPeriod0007"://半年
                                String byear = DateUtil.getYear().toString();
                                Integer bmonth = Integer.parseInt(DateUtil.getMonth().toString());
                                if (bmonth <= 6) {
                                    pd.put("STARTTIME", byear + "-01-01 00:00:00");
                                    pd.put("ENDTIME", byear + "-06-30 23:59:59");
                                } else if (bmonth > 6) {
                                    pd.put("STARTTIME", byear + "-07-01 00:00:00");
                                    pd.put("ENDTIME", byear + "-12-31 23:59:59");
                                }
                                break;

                            default:
                                break;
                        }
                    }
                    PageData statistics = customStatisticsService.findByCondition(pd);
                    if (statistics != null && statistics.get("CUSTOMSTATISTICS_ID") != null) {
                        statistics.put("NOTEXAMINEDNUM", Integer.parseInt(statistics.get("NOTEXAMINEDNUM").toString()) + 1);
                        customStatisticsService.edit(statistics);
                    } else {
                        pd.put("NOTEXAMINEDNUM", 1);
                        customStatisticsService.save(pd);
                    }
                }
            }

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

    /**
     * 列表
     *
     * @param page
     * @throws Exception
     */
    @RequestMapping(value = "/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();
        PageData npd = new PageData();
        pd = this.getPageData();
        npd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());
        npd.put("ISMAIN", Jurisdiction.getIS_MAIN());
        npd.put("ISSUPERVISE", Jurisdiction.getISSUPERVISE());
        npd.put("DEPARTMENT_ID", Jurisdiction.getDEPARTMENT_ID());
        pd.put("USER_ID",Jurisdiction.getUSER_ID());
        String DEPTIDS = pd.getString("DEPTIDS");
        if(Tools.notEmpty(DEPTIDS)) {
            String DEPT_IDS[] = DEPTIDS.split(",");
            npd.put("DEPT_IDS", DEPT_IDS);
        }
        npd.put("HIDFORBIDDEN", "no");	//企业
        String KEYWORDS = pd.getString("KEYWORDS");						//关键词检索条件
        if(Tools.notEmpty(KEYWORDS))npd.put("KEYWORDS", KEYWORDS.trim());
        String USERNAME = pd.getString("USERNAME");						//关键词检索条件
        if(Tools.notEmpty(USERNAME))npd.put("USERNAME", USERNAME.trim());
        PageData cpd = usersService.findById(pd);
        npd.put("ISLEADER", cpd.getString("ISLEADER"));
        if(cpd.getString("ISLEADER") != null && cpd.getString("ISLEADER").equals("1")){
            String DEPARTMENT_ID = npd.getString("DEPARTMENT_ID");
            String ids = departmentService.getDEPARTMENT_IDS(DEPARTMENT_ID);
            ids=npd.getString("DEPARTMENT_ID")+","+ids;   //把自己部门插入进去
            if(ids!=null && Tools.notEmpty(ids)&& ids.lastIndexOf(",")>-1) {
                ids = ids.substring(0,ids.lastIndexOf(","));
                npd.put("DEPARTMENT_IDS", ids.split(","));
            }else {
                npd.put("DEPARTMENT_IDS", DEPARTMENT_ID);
            }
        }else{
            if(npd.getString("ISMAIN").equals("0") ){
                npd.put("USER_ID",Jurisdiction.getUSER_ID());
            }
        }
        npd.put("TYPE",pd.getString("TYPE"));
        npd.put("LISTINGLEVEL",pd.getString("LISTINGLEVEL"));
        npd.put("RISKCHECKLISTTYPE",pd.getString("RISKCHECKLISTTYPE"));
        npd.put("POST_ID",pd.getString("POST_ID"));
        npd.put("PERIOD",pd.getString("PERIOD"));
        page.setPd(npd);
        List<PageData> varList = customService.list(page);
        map.put("varList", varList);
        map.put("page", page);
        map.put("result", errInfo);
        return map;
    }


    /**
     * 禁用
     *
     * @param out
     * @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();
        pd.put("OPERATOR", Jurisdiction.getUsername());    //修改人
        pd.put("OPERATTIME", DateUtil.date2Str(new Date()));    //修改时间
        customService.delete(pd);
        pd = customService.findById(pd);
        // 记录清单禁用开始时间

        PageData disPd = new PageData();
        disPd = this.getPageData();
        disPd.put("CUSTOMDISABLETIME_ID", this.get32UUID());    //主键
        disPd.put("CUSTOM_ID", pd.get("CUSTOM_ID"));
        disPd.put("CORPINFO_ID", pd.get("CORPINFO_ID"));
        disPd.put("STARTTIME", DateUtil.date2Str(new Date()));    //开始时间
        disPd.put("ISDELETE", "0");    //是否删除 0 未删除  1已删除
        disPd.put("OPERATOR", Jurisdiction.getUsername());    //操作人
        disPd.put("OPERATTIME", DateUtil.date2Str(new Date()));    //操作时间
        disPd.put("CREATOR", Jurisdiction.getUsername());    //创建人
        disPd.put("CREATTIME", DateUtil.date2Str(new Date()));    //创建时间
        customDisableTimeService.save(disPd);
        // 修改清单统计
        if (pd.get("TYPE") != null && Tools.notEmpty(pd.get("TYPE").toString())) {
            if ("listType0005".equals(pd.get("TYPE").toString())) {
                pd.put("CUSTOMSTATISTICS_ID", this.get32UUID());    //主键
                pd.put("STARTTIME", pd.get("START_DATE").toString() + " 00:00:00");
                pd.put("ENDTIME", pd.get("END_DATE").toString() + " 23:59:59");
                pd.put("PERIOD", null);
                PageData statistics = customStatisticsService.findByCondition(pd);
                if (statistics != null && statistics.get("CUSTOMSTATISTICS_ID") != null) {
                    statistics.put("NOTEXAMINEDNUM", Integer.parseInt(statistics.get("NOTEXAMINEDNUM").toString()) - 2);
                    customStatisticsService.edit(statistics);
                }
                pd.put("ISSTATISTICS", '0');
                // 本期已检查的不计入统计
                customCheckRecordService.editStatistics(pd);
            } else {
                if (pd.get("PERIOD") != null && Tools.notEmpty(pd.get("PERIOD").toString())) {
                    String period = pd.get("PERIOD").toString();
                    switch (period) {
                        case "checkPeriod0001"://每日
                            pd.put("STARTTIME", DateUtil.getDay() + " 00:00:00");
                            pd.put("ENDTIME", DateUtil.getDay() + " 23:59:59");
                            break;

                        case "checkPeriod0002"://每周
                            pd.put("STARTTIME", DateUtil.getWeekStart());
                            pd.put("ENDTIME", DateUtil.getWeekEnd());
                            break;

                        case "checkPeriod0003"://每旬
                            String year = DateUtil.getYear().toString();
                            String month = DateUtil.getMonth().toString();
                            Integer day = Integer.parseInt(DateUtil.getOnlyDay().toString());
                            String startTime = year + "-" + month + "-";
                            String endTime = year + "-" + month + "-";
                            if (day <= 10) {
                                startTime = startTime + "01 00:00:00";
                                endTime = endTime + "10 23:59:59";
                            } else if (day > 10 && day <= 20) {
                                startTime = startTime + "11 00:00:00";
                                endTime = endTime + "20 23:59:59";
                            } else {
                                startTime = startTime + "21 00:00:00";
                                endTime = DateUtil.getMonthEndDay() + " 23:59:59";
                            }
                            pd.put("STARTTIME", startTime);
                            pd.put("ENDTIME", endTime);
                            break;

                        case "checkPeriod0004"://每月
                            pd.put("STARTTIME", DateUtil.getMonthFirstDay() + " 00:00:00");
                            pd.put("ENDTIME", DateUtil.getMonthEndDay() + " 23:59:59");
                            break;

                        case "checkPeriod0005"://每季
                            pd.put("STARTTIME", DateUtil.quarterStart() + " 00:00:00");
                            pd.put("ENDTIME", DateUtil.quarterEnd() + " 23:59:59");
                            break;

                        case "checkPeriod0006"://每年
                            pd.put("STARTTIME", DateUtil.getCurrYearFirst() + " 00:00:00");
                            pd.put("ENDTIME", DateUtil.getCurrYearLast() + " 23:59:59");
                            break;

                        case "checkPeriod0007"://半年
                            String byear = DateUtil.getYear().toString();
                            Integer bmonth = Integer.parseInt(DateUtil.getMonth().toString());
                            if (bmonth <= 6) {
                                pd.put("STARTTIME", byear + "-01-01 00:00:00");
                                pd.put("ENDTIME", byear + "-06-30 23:59:59");
                            } else if (bmonth > 6) {
                                pd.put("STARTTIME", byear + "-07-01 00:00:00");
                                pd.put("ENDTIME", byear + "-12-31 23:59:59");
                            }
                            break;

                        default:
                            break;
                    }
                }
                PageData statistics = customStatisticsService.findByCondition(pd);
                if (statistics != null && statistics.get("CUSTOMSTATISTICS_ID") != null) {
                    statistics.put("NOTEXAMINEDNUM", Integer.parseInt(statistics.get("NOTEXAMINEDNUM").toString()) - 1);
                    customStatisticsService.edit(statistics);
                }

                pd.put("ISSTATISTICS", '0');
                // 本期已检查的不计入统计
                customCheckRecordService.editStatistics(pd);
            }
        }
        // 将本频率内已检查的记录，改为不计入
        map.put("result", errInfo);                //返回结果
        return map;
    }

    /**
     * 去修改页面获取数据
     *
     * @param
     * @throws Exception
     */
    @RequestMapping(value = "/goEdit")
    @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();
        String KEYWORDS = pd.getString("KEYWORDS"); // 关键词检索条件
        if (Tools.notEmpty(KEYWORDS))
            pd.put("KEYWORDS", KEYWORDS.trim());
        pd.put("CUSTOM_ID", pd.get("ID"));
        List<PageData> varList = customItemService.listAll(pd);
        pd = customService.findById(pd);    //根据ID读取

        for (PageData item : varList) {
            item.put("RECORDITEM_ID", this.get32UUID());    //主键
        }
//		List<PageData> ideList = identificationPartsService.listAllByList(pd);

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

    /**
     * 批量删除
     *
     * @param
     * @throws Exception
     */
    @RequestMapping(value = "/deleteAll")
//    @RequiresPermissions("listmanager:del")
    @ResponseBody
    @LogAnno(menuType = "双重预防", menuServer = "隐患排查", instructionsOperate = "清单管理", instructionsType = "批量删除")
    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(",");
            for (int i = 0; i < ArrayDATA_IDS.length; i++) {
                PageData pd1 = new PageData();
                pd1.put("OPERATOR", Jurisdiction.getUsername());    //修改人
                pd1.put("OPERATTIME", DateUtil.date2Str(new Date()));    //修改时间
                pd1.put("CUSTOM_ID", ArrayDATA_IDS[i]);
                customService.remove(pd1);
                pd1 = customService.findById(pd1);
                if (pd1.get("TYPE") != null && Tools.notEmpty(pd1.get("TYPE").toString())) {
                    if ("listType0005".equals(pd1.get("TYPE").toString())) {
                        pd1.put("CUSTOMSTATISTICS_ID", this.get32UUID());    //主键
                        pd1.put("STARTTIME", pd1.get("START_DATE").toString() + " 00:00:00");
                        pd1.put("ENDTIME", pd1.get("END_DATE").toString() + " 23:59:59");
                        pd1.put("PERIOD", null);
                        PageData statistics = customStatisticsService.findByCondition(pd1);
                        if (statistics != null && statistics.get("CUSTOMSTATISTICS_ID") != null) {
                            statistics.put("NOTEXAMINEDNUM", Integer.parseInt(statistics.get("NOTEXAMINEDNUM").toString()) - 2);
                            customStatisticsService.edit(statistics);
                        }
                        pd1.put("ISSTATISTICS", '0');
                        // 本期已检查的不计入统计
                        customCheckRecordService.editStatistics(pd1);
                    } else {
                        if (pd1.get("PERIOD") != null && Tools.notEmpty(pd1.get("PERIOD").toString())) {
                            String period = pd1.get("PERIOD").toString();
                            switch (period) {
                                case "checkPeriod0001"://每日
                                    pd1.put("STARTTIME", DateUtil.getDay() + " 00:00:00");
                                    pd1.put("ENDTIME", DateUtil.getDay() + " 23:59:59");
                                    break;

                                case "checkPeriod0002"://每周
                                    pd1.put("STARTTIME", DateUtil.getWeekStart());
                                    pd1.put("ENDTIME", DateUtil.getWeekEnd());
                                    break;

                                case "checkPeriod0003"://每旬
                                    String year = DateUtil.getYear().toString();
                                    String month = DateUtil.getMonth().toString();
                                    Integer day = Integer.parseInt(DateUtil.getOnlyDay().toString());
                                    String startTime = year + "-" + month + "-";
                                    String endTime = year + "-" + month + "-";
                                    if (day <= 10) {
                                        startTime = startTime + "01 00:00:00";
                                        endTime = endTime + "10 23:59:59";
                                    } else if (day > 10 && day <= 20) {
                                        startTime = startTime + "11 00:00:00";
                                        endTime = endTime + "20 23:59:59";
                                    } else {
                                        startTime = startTime + "21 00:00:00";
                                        endTime = DateUtil.getMonthEndDay() + " 23:59:59";
                                    }
                                    pd1.put("STARTTIME", startTime);
                                    pd1.put("ENDTIME", endTime);
                                    break;

                                case "checkPeriod0004"://每月
                                    pd1.put("STARTTIME", DateUtil.getMonthFirstDay() + " 00:00:00");
                                    pd1.put("ENDTIME", DateUtil.getMonthEndDay() + " 23:59:59");
                                    break;

                                case "checkPeriod0005"://每季
                                    pd1.put("STARTTIME", DateUtil.quarterStart() + " 00:00:00");
                                    pd1.put("ENDTIME", DateUtil.quarterEnd() + " 23:59:59");
                                    break;

                                case "checkPeriod0006"://每年
                                    pd1.put("STARTTIME", DateUtil.getCurrYearFirst() + " 00:00:00");
                                    pd1.put("ENDTIME", DateUtil.getCurrYearLast() + " 23:59:59");
                                    break;

                                case "checkPeriod0007"://半年
                                    String byear = DateUtil.getYear().toString();
                                    Integer bmonth = Integer.parseInt(DateUtil.getMonth().toString());
                                    if (bmonth <= 6) {
                                        pd1.put("STARTTIME", byear + "-01-01 00:00:00");
                                        pd1.put("ENDTIME", byear + "-06-30 23:59:59");
                                    } else if (bmonth > 6) {
                                        pd1.put("STARTTIME", byear + "-07-01 00:00:00");
                                        pd1.put("ENDTIME", byear + "-12-31 23:59:59");
                                    }
                                    break;

                                default:
                                    break;
                            }
                        }
                        PageData statistics = customStatisticsService.findByCondition(pd1);
                        if (statistics != null && statistics.get("CUSTOMSTATISTICS_ID") != null) {
                            statistics.put("NOTEXAMINEDNUM", Integer.parseInt(statistics.get("NOTEXAMINEDNUM").toString()) - 1);
                            customStatisticsService.edit(statistics);
                        }

                        pd1.put("ISSTATISTICS", '0');
                        // 本期已检查的不计入统计
                        customCheckRecordService.editStatistics(pd1);
                    }
                }
            }
            errInfo = "success";
        } else {
            errInfo = "error";
        }
        map.put("result", errInfo);                //返回结果
        return map;
    }

    /**
     * 批量删除
     *
     * @param
     * @throws Exception
     */
    @RequestMapping(value = "/deleteAlltemp")
    @ResponseBody
    @LogAnno(menuType = "双重预防", menuServer = "隐患排查", instructionsOperate = "清单管理", instructionsType = "批量删除")
    public Object deleteAlltemp() 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(",");
            for (int i = 0; i < ArrayDATA_IDS.length; i++) {
                PageData pd1 = new PageData();
                pd1.put("OPERATOR", Jurisdiction.getUsername());    //修改人
                pd1.put("OPERATTIME", DateUtil.date2Str(new Date()));    //修改时间
                pd1.put("CUSTOM_ID", ArrayDATA_IDS[i]);
                customService.deleted(pd1);
                pd1 = customService.findById(pd1);
                if (pd1.get("TYPE") != null && Tools.notEmpty(pd1.get("TYPE").toString())) {
                    pd1.put("CUSTOMSTATISTICS_ID", this.get32UUID());    //主键
                    pd1.put("STARTTIME", pd1.get("START_DATE").toString() + " 00:00:00");
                    pd1.put("ENDTIME", pd1.get("END_DATE").toString() + " 23:59:59");
                    pd1.put("PERIOD", null);
                    PageData statistics = customStatisticsService.findByCondition(pd1);
                    if (statistics != null && statistics.get("CUSTOMSTATISTICS_ID") != null) {
                        statistics.put("NOTEXAMINEDNUM", Integer.parseInt(statistics.get("NOTEXAMINEDNUM").toString()) - 1);
                        customStatisticsService.edit(statistics);
                    }
                    pd1.put("ISSTATISTICS", '0');
                    // 本期已检查的不计入统计
                    customCheckRecordService.editStatistics(pd1);
                }
            }
            errInfo = "success";
        } else {
            errInfo = "error";
        }
        map.put("result", errInfo);                //返回结果
        return map;
    }


    /**
     * 从EXCEL导入到数据库
     *
     * @param file
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/readExcel")
    @ResponseBody
    @Transactional
    @LogAnno(menuType = "双重预防", menuServer = "隐患排查", instructionsOperate = "清单管理", instructionsType = "导入")
    public Object readExcel(@RequestParam(value = "FFILE", required = false) MultipartFile file) throws Exception {
        Map<String, String> map = new HashMap<String, String>();
        String errInfo = "success";
        StringBuffer errorStr = new StringBuffer();
        PageData pd = new PageData();
        pd = this.getPageData(); // COURSEWAREID

        if (null != file && !file.isEmpty()) {
            File tempFile = new File(file.getOriginalFilename()); //新建file
            FileUtils.copyInputStreamToFile(file.getInputStream(), tempFile); //将MultipartFile复制到File
            List<PageData> listPd = (List) ObjectExcelRead.readExcel(tempFile, 1, 0, 0);            //执行读EXCEL操作,读出的数据导入List 2:从第3行开始；0:从第A列开始；0:第0个sheet
            /**
             * var0 :检查类别
             * var1 :检查项目
             * var2 :检查内容
             * var3 :检查标准
             * var4 :参考依据
             * var5 :检查合格项
             * var6 :检查不合格项
             * var7 :操作类型
             */
            List<String> header = new ArrayList<>();
            header.add("检查类别");
            header.add("检查项目");
            header.add("检查内容");
            header.add("检查标准");
            header.add("参考依据");
            header.add("检查合格项");
            header.add("检查不合格项");
            header.add("操作类型");

            if (listPd.size() > 0) {
                /**
                 *  判断是否填写必填
                 *  判断excel是有有重复数据
                 *  判断数据库是否有重复数据
                 *  导入
                 *  长度
                 */
                Integer number = 1;//行数，用于提示用户
                Boolean firstFlag = true;
                String CUSTOM_ID = "";
                for (PageData lpd : listPd) {
                    try {
                        number++;
                        for (int i = 0; i < 8; i++) {
                            if (i == 0) { // var0 :序号 非必填
                                continue;
                            }
                            if (!lpd.containsKey("var" + i) || Tools.isEmpty(lpd.get("var" + i))) {
                                if ("参考依据".equals(header.get(i))) {
                                    continue;
                                }
                                errorStr.append("第" + number + "行的" + header.get(i) + "无数据;\n");
                                continue;
                            }
                            if (lpd.get("var" + i).toString().length() >= 250) { //限制内容长度
                                errorStr.append("第" + number + "行的 \"" + header.get(i) + "\"字符长度超出,请精简的250内;\n");
                            }

                        }
                        String CHECK_CATEGORY = Tools.excelHandle(lpd.get("var0"));
                        String CHECK_ITEM = Tools.excelHandle(lpd.get("var1"));
                        String CHECK_CONTENT = Tools.excelHandle(lpd.get("var2"));
                        String CHECK_STANDARD = Tools.excelHandle(lpd.get("var3"));
                        String REFERENCE_BASIS = Tools.excelHandle(lpd.get("var4"));
                        String CHECK_QUALIFIED = Tools.excelHandle(lpd.get("var5"));
                        String CHECK_UNQUALIFIED = Tools.excelHandle(lpd.get("var6"));
                        String OPERATION_TYPE = "选择".equals(Tools.excelHandle(lpd.get("var7"))) ? "1" : "2";
                        //检查类别和检查项目如果字典里存在，则不存字典，如果不存在，则存一下
                        PageData dict = new PageData();
                        dict.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());
                        List<PageData> dictList = standardDictionaryService.list(dict);
                        int maxsortNum = 0;
                        Boolean existCategory = false;
                        String CHECK_CATEGORY_TEMP = "";
                        for (int j = 0; j < dictList.size(); j++) {
                            if ("1".equals(dictList.get(j).get("DICTIONARY_LEVEL").toString())) {
                                if (!dictList.get(j).get("DICTIONARY_NAME").equals(CHECK_CATEGORY)) {   //如果不存在该字典，获取最大排序号
                                    if (maxsortNum < Integer.parseInt(dictList.get(j).getString("DICTIONARY_SORT"))) {
                                        maxsortNum = Integer.parseInt(dictList.get(j).getString("DICTIONARY_SORT"));
                                    }
                                } else {
                                    CHECK_CATEGORY_TEMP = dictList.get(j).get("DICTIONARY_ID").toString();
                                    existCategory = true;
                                }
                            }
                        }
                        maxsortNum = maxsortNum == 0 ? 1 : maxsortNum + 1;
                        if (!existCategory) {
                            dict.put("DICTIONARY_ID", this.get32UUID());
                            dict.put("DICTIONARY_LEVEL", "1");
                            dict.put("DICTIONARY_SORT", maxsortNum);
                            dict.put("DICTIONARY_NAME", CHECK_CATEGORY);
                            dict.put("PARENT_ID", "0");
                            dict.put("PARENT_IDS", dict.get("DICTIONARY_ID"));
                            dict.put("DICTIONARY_NAMES", dict.get("DICTIONARY_NAME"));
                            dict.put("DICTIONARY_SOURCE", "2");
                            dict.put("ISDELETE", "0");
                            dict.put("CREATOR_ID", Jurisdiction.getUSER_ID());
                            dict.put("CREATOR_NAME", Jurisdiction.getUsername());
                            dict.put("CREATE_TIME", DateUtil.date2Str(new Date()));
                            dict.put("OPERATOR_ID", Jurisdiction.getUSER_ID());
                            dict.put("OPERATOR_NAME", Jurisdiction.getUsername());
                            dict.put("OPERATE_TIME", DateUtil.date2Str(new Date()));
                            dict.put("DELETEOR_ID", Jurisdiction.getUSER_ID());
                            dict.put("DELETEOR_NAME", Jurisdiction.getUsername());
                            dict.put("DELETE_TIME", DateUtil.date2Str(new Date()));
                            standardDictionaryService.save(dict);
                            CHECK_CATEGORY_TEMP = dict.get("DICTIONARY_ID").toString();
                        }
                        PageData dictItem = new PageData();
                        dictItem.putAll(dict);
                        maxsortNum = 0;
                        Boolean existItem = false;
                        String CHECK_ITEM_TEMP = "";
                        for (int j = 0; j < dictList.size(); j++) {
                            if ("2".equals(dictList.get(j).get("DICTIONARY_LEVEL").toString())) {
                                if (!dictList.get(j).get("DICTIONARY_NAME").equals(CHECK_ITEM)) {   //如果不存在该字典，获取最大排序号
                                    if (maxsortNum < Integer.parseInt(dictList.get(j).getString("DICTIONARY_SORT"))) {
                                        maxsortNum = Integer.parseInt(dictList.get(j).getString("DICTIONARY_SORT"));
                                    }
                                } else {
                                    CHECK_ITEM_TEMP = dictList.get(j).get("DICTIONARY_ID").toString();
                                    existItem = true;
                                }
                            }
                        }
                        maxsortNum = maxsortNum == 0 ? 1 : maxsortNum + 1;
                        if (!existItem) {
                            dictItem.put("DICTIONARY_ID", this.get32UUID());
                            dictItem.put("DICTIONARY_LEVEL", "2");
                            dictItem.put("DICTIONARY_SORT", maxsortNum);
                            dictItem.put("DICTIONARY_NAME", CHECK_ITEM);
                            dictItem.put("PARENT_ID", dict.get("DICTIONARY_ID"));
                            dictItem.put("PARENT_IDS", dictItem.getString("DICTIONARY_ID") + ',' + dict.getString("DICTIONARY_ID"));
                            dictItem.put("DICTIONARY_NAMES", dictItem.getString("DICTIONARY_NAME") + ',' + dict.getString("DICTIONARY_NAME"));
                            standardDictionaryService.save(dictItem);
                            CHECK_ITEM_TEMP = dictItem.get("DICTIONARY_ID").toString();
                        }
                        if (firstFlag) {
                            // 隐患排查清单保存
                            PageData customData = new PageData();
                            customData.put("CUSTOM_ID", this.get32UUID());
                            customData.put("NAME", pd.getString("NAME"));
                            customData.put("BAO_BAO_TYPE", pd.getString("BAO_BAO_TYPE"));
                            customData.put("TASK_TYPE", pd.getString("TASK_TYPE"));
                            customData.put("DEPARTMENT_ID", pd.getString("DEPARTMENT_ID"));
                            customData.put("POST_ID", pd.getString("POST_ID"));
                            customData.put("USER_ID", pd.getString("USER_ID"));
                            customData.put("SCREENTYPE", pd.getString("SCREENTYPE"));
                            customData.put("PERIOD", pd.getString("PERIOD"));
                            customData.put("TYPE", pd.getString("TYPE"));
                            customData.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());    //企业
                            customData.put("ISDELETE", "0");    //是否删除
                            customData.put("CREATOR", Jurisdiction.getUsername());    //添加人
                            customData.put("CREATTIME", DateUtil.date2Str(new Date()));    //创建时间
                            customData.put("OPERATOR", Jurisdiction.getUsername());    //修改人
                            customData.put("OPERATTIME", DateUtil.date2Str(new Date()));    //修改时间
                            customService.save(customData);
                            firstFlag = false;
                            CUSTOM_ID = customData.getString("CUSTOM_ID");
                        }
                        // 隐患排查清单检查项保存
                        PageData customItemData = new PageData();
                        customItemData.put("CUSTOM_ITEM_ID", this.get32UUID());    //主键
                        customItemData.put("CUSTOM_ID", CUSTOM_ID);
                        customItemData.put("CHECK_CATEGORY", CHECK_CATEGORY_TEMP);
                        customItemData.put("CHECK_ITEM", CHECK_ITEM_TEMP);
                        customItemData.put("CHECK_CONTENT", CHECK_CONTENT);
                        customItemData.put("CHECK_STANDARD", CHECK_STANDARD);
                        customItemData.put("REFERENCE_BASIS", REFERENCE_BASIS);
                        customItemData.put("CHECK_QUALIFIED", CHECK_QUALIFIED);
                        customItemData.put("CHECK_UNQUALIFIED", CHECK_UNQUALIFIED);
                        customItemData.put("OPERATION_TYPE", OPERATION_TYPE);
                        customItemData.put("COMMON_ITEM_SORT", maxsortNum);
                        customItemData.put("CREATOR_ID", Jurisdiction.getUSER_ID());
                        customItemData.put("CREATOR_NAME", Jurisdiction.getUsername());
                        customItemData.put("CREATE_TIME", DateUtil.date2Str(new Date()));
                        customItemData.put("OPERATOR_ID", Jurisdiction.getUSER_ID());
                        customItemData.put("OPERATOR_NAME", Jurisdiction.getUsername());
                        customItemData.put("OPERATE_TIME", DateUtil.date2Str(new Date()));
                        customItemData.put("DELETEOR_ID", Jurisdiction.getUSER_ID());
                        customItemData.put("DELETEOR_NAME", Jurisdiction.getUsername());
                        customItemData.put("ISDELETE", "0");    //是否删除
                        customItemService.save(customItemData);
//                        listAll.add(customData);
                        // 修改清单统计
                        PageData newpd = new PageData();
                        newpd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());    //企业
                        newpd.put("CUSTOM_ID", CUSTOM_ID);
                        if ("listType0005".equals(pd.getString("TYPE"))) {
                            newpd.put("CUSTOMSTATISTICS_ID", this.get32UUID());    //主键
                            newpd.put("STARTTIME", newpd.get("START_DATE").toString() + " 00:00:00");
                            newpd.put("ENDTIME", newpd.get("END_DATE").toString() + " 23:59:59");
                            newpd.put("PERIOD", null);
                            PageData statistics = customStatisticsService.findByCondition(newpd);
                            if (statistics != null && statistics.get("CUSTOMSTATISTICS_ID") != null) {
                                statistics.put("NOTEXAMINEDNUM", Integer.parseInt(statistics.get("NOTEXAMINEDNUM").toString()) - 2);
                                customStatisticsService.edit(statistics);
                            }
                            newpd.put("ISSTATISTICS", '0');
                            // 本期已检查的不计入统计
                            customCheckRecordService.editStatistics(newpd);
                        } else {
                            switch (pd.getString("PERIOD")) {
                                case "checkPeriod0001"://每日
                                    newpd.put("STARTTIME", DateUtil.getDay() + " 00:00:00");
                                    newpd.put("ENDTIME", DateUtil.getDay() + " 23:59:59");
                                    break;

                                case "checkPeriod0002"://每周
                                    newpd.put("STARTTIME", DateUtil.getWeekStart());
                                    newpd.put("ENDTIME", DateUtil.getWeekEnd());
                                    break;

                                case "checkPeriod0003"://每旬
                                    String year = DateUtil.getYear().toString();
                                    String month = DateUtil.getMonth().toString();
                                    Integer day = Integer.parseInt(DateUtil.getOnlyDay().toString());
                                    String startTime = year + "-" + month + "-";
                                    String endTime = year + "-" + month + "-";
                                    if (day <= 10) {
                                        startTime = startTime + "01 00:00:00";
                                        endTime = endTime + "10 23:59:59";
                                    } else if (day > 10 && day <= 20) {
                                        startTime = startTime + "11 00:00:00";
                                        endTime = endTime + "20 23:59:59";
                                    } else {
                                        startTime = startTime + "21 00:00:00";
                                        endTime = DateUtil.getMonthEndDay() + " 23:59:59";
                                    }
                                    newpd.put("STARTTIME", startTime);
                                    newpd.put("ENDTIME", endTime);
                                    break;

                                case "checkPeriod0004"://每月
                                    newpd.put("STARTTIME", DateUtil.getMonthFirstDay() + " 00:00:00");
                                    newpd.put("ENDTIME", DateUtil.getMonthEndDay() + " 23:59:59");
                                    break;

                                case "checkPeriod0005"://每季
                                    newpd.put("STARTTIME", DateUtil.quarterStart() + " 00:00:00");
                                    newpd.put("ENDTIME", DateUtil.quarterEnd() + " 23:59:59");
                                    break;

                                case "checkPeriod0006"://每年
                                    newpd.put("STARTTIME", DateUtil.getCurrYearFirst() + " 00:00:00");
                                    newpd.put("ENDTIME", DateUtil.getCurrYearLast() + " 23:59:59");
                                    break;

                                case "checkPeriod0007"://半年
                                    String byear = DateUtil.getYear().toString();
                                    Integer bmonth = Integer.parseInt(DateUtil.getMonth().toString());
                                    if (bmonth <= 6) {
                                        pd.put("STARTTIME", byear + "-01-01 00:00:00");
                                        pd.put("ENDTIME", byear + "-06-30 23:59:59");
                                    } else if (bmonth > 6) {
                                        pd.put("STARTTIME", byear + "-07-01 00:00:00");
                                        pd.put("ENDTIME", byear + "-12-31 23:59:59");
                                    }
                                    break;
                                default:
                                    break;
                            }
                            PageData statistics = customStatisticsService.findByCondition(newpd);
                            if (statistics != null && statistics.get("CUSTOMSTATISTICS_ID") != null) {
                                statistics.put("NOTEXAMINEDNUM", Integer.parseInt(statistics.get("NOTEXAMINEDNUM").toString()) - 1);
                                customStatisticsService.edit(statistics);
                            }
                            newpd.put("ISSTATISTICS", '0');
                            // 本期已检查的不计入统计
                            customCheckRecordService.editStatistics(newpd);
                        }
                    } catch (Exception e) {
                        map.put("result", "fail");                //返回结果
                        errorStr.append("第" + number + "行数据出现错误;<br/>");
                        return map;
                    }
                }

                if (Tools.isEmpty(errorStr.toString())) {
                    errorStr.append("成功导入" + (number - 1) + "条数据!");
                } else {
                    errInfo = "error";
                }
                FileUtils.deleteQuietly(tempFile);//删除临时文件
            } else {
                map.put("result", "fail");//返回结果
                map.put("msg", "Excel数据为空，请检查数据后，重新上传！");
                FileUtils.deleteQuietly(tempFile);//删除临时文件
                return map;
            }
        }
        map.put("result", errInfo);                //返回结果
        map.put("msg", errorStr.toString());                //返回结果
        map.put("resultStr", errorStr.toString());
        return map;
    }

    /**
     * 修改
     *
     * @param
     * @throws Exception
     */
    @RequestMapping(value = "/edit")
    // @RequiresPermissions("listmanager:edit")
    @ResponseBody
    @LogAnno(menuType = "双重预防", menuServer = "隐患排查", instructionsOperate = "清单管理", instructionsType = "修改")
    public Object edit() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        pd.put("OPERATOR", Jurisdiction.getUsername());    //修改人
        pd.put("OPERATTIME", DateUtil.date2Str(new Date()));    //修改时间
        // 查询原数据
        PageData oldPd = customService.findById(pd);

        PageData pd2 = new PageData(); //删除原有内容
        pd2.put("CUSTOM_ID", pd.getString("CUSTOM_ID"));
        List<PageData> varList = customItemService.listAll(pd2); //
        for (PageData pageData : varList) {
            PageData citem = new PageData();
            citem.put("CUSTOM_ITEM_ID", pageData.getString("CUSTOM_ITEM_ID"));
            customItemService.delete(citem);
        }

        if (pd.get("LISTITEM") != null && !pd.get("LISTITEM").equals("")) {
            List<JSONObject> list = (List<JSONObject>) JSON.parse(pd.get("LISTITEM").toString());
            for (JSONObject json : list) {
                int commonSort = 0;
                String CHECK_CATEGORY_Temp = "";
                String CHECK_ITEM_Temp = "";
                if (Tools.isEmpty(json.get("CHECK_CATEGORY")) || Tools.isEmpty(json.get("CHECK_ITEM"))) {
                    PageData dict = new PageData();
                    dict.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());
                    List<PageData> dictList = standardDictionaryService.list(dict);
                    int maxsortNum = 0;
                    Boolean existCategory = false;
                    for (int j = 0; j < dictList.size(); j++) {
                        if ("1".equals(dictList.get(j).get("DICTIONARY_LEVEL").toString())) {
                            if (!dictList.get(j).get("DICTIONARY_NAME").equals(json.get("CHECK_CATEGORY_NAME"))) {   //如果不存在该字典，获取最大排序号
                                if (maxsortNum < Integer.parseInt(dictList.get(j).getString("DICTIONARY_SORT"))) {
                                    maxsortNum = Integer.parseInt(dictList.get(j).getString("DICTIONARY_SORT"));
                                }
                            } else {
                                CHECK_CATEGORY_Temp = dictList.get(j).get("DICTIONARY_ID").toString();
                                existCategory = true;
                            }
                        }
                    }
                    if (!existCategory) {
                        dict.put("DICTIONARY_ID", this.get32UUID());
                        dict.put("DICTIONARY_LEVEL", "1");
                        dict.put("DICTIONARY_SORT", maxsortNum + 1);
                        dict.put("DICTIONARY_NAME", json.get("CHECK_CATEGORY_NAME"));
                        dict.put("PARENT_ID", "0");
                        dict.put("PARENT_IDS", dict.get("DICTIONARY_ID"));
                        dict.put("DICTIONARY_NAMES", dict.get("DICTIONARY_NAME"));
                        dict.put("DICTIONARY_SOURCE", "2");
                        dict.put("ISDELETE", "0");
                        dict.put("CREATOR_ID", Jurisdiction.getUSER_ID());
                        dict.put("CREATOR_NAME", Jurisdiction.getUsername());
                        dict.put("CREATE_TIME", DateUtil.date2Str(new Date()));
                        dict.put("OPERATOR_ID", Jurisdiction.getUSER_ID());
                        dict.put("OPERATOR_NAME", Jurisdiction.getUsername());
                        dict.put("OPERATE_TIME", DateUtil.date2Str(new Date()));
                        dict.put("DELETEOR_ID", Jurisdiction.getUSER_ID());
                        dict.put("DELETEOR_NAME", Jurisdiction.getUsername());
                        dict.put("DELETE_TIME", DateUtil.date2Str(new Date()));
                        standardDictionaryService.save(dict);
                        CHECK_CATEGORY_Temp = dict.get("DICTIONARY_ID").toString();
                    }
                    PageData dictItem = new PageData();
                    dictItem.putAll(dict);
                    maxsortNum = 0;
                    Boolean existItem = false;
                    for (int j = 0; j < dictList.size(); j++) {
                        if ("2".equals(dictList.get(j).get("DICTIONARY_LEVEL").toString())) {
                            if (!dictList.get(j).get("DICTIONARY_NAME").equals(json.get("CHECK_ITEM_NAME"))) {   //如果不存在该字典，获取最大排序号
                                if (maxsortNum < Integer.parseInt(dictList.get(j).getString("DICTIONARY_SORT"))) {
                                    maxsortNum = Integer.parseInt(dictList.get(j).getString("DICTIONARY_SORT"));
                                }
                            } else {
                                CHECK_ITEM_Temp = dictList.get(j).get("DICTIONARY_ID").toString();
                                existItem = true;
                            }
                        }
                    }
                    commonSort = maxsortNum == 0 ? 1 : maxsortNum;
                    if (!existItem) {
                        dictItem.put("DICTIONARY_ID", this.get32UUID());
                        dictItem.put("DICTIONARY_LEVEL", "2");
                        dictItem.put("DICTIONARY_SORT", maxsortNum + 1);
                        dictItem.put("DICTIONARY_NAME", json.get("CHECK_ITEM_NAME"));
                        dictItem.put("PARENT_ID", dict.get("DICTIONARY_ID"));
                        dictItem.put("PARENT_IDS", dictItem.getString("DICTIONARY_ID") + ',' + dict.getString("DICTIONARY_ID"));
                        dictItem.put("DICTIONARY_NAMES", dictItem.getString("DICTIONARY_NAME") + ',' + dict.getString("DICTIONARY_NAME"));
                        standardDictionaryService.save(dictItem);
                        CHECK_ITEM_Temp = dictItem.get("DICTIONARY_ID").toString();
                    }
                }
                PageData itme = new PageData();
                itme.put("CUSTOM_ITEM_ID", this.get32UUID());    //主键
                itme.put("CUSTOM_ID", pd.get("CUSTOM_ID"));
                itme.put("CHECK_CATEGORY", Tools.isEmpty(json.get("CHECK_CATEGORY")) ? CHECK_CATEGORY_Temp : json.get("CHECK_CATEGORY"));
                itme.put("CHECK_ITEM", Tools.isEmpty(json.get("CHECK_ITEM")) ? CHECK_ITEM_Temp : json.get("CHECK_ITEM"));
                itme.put("CHECK_CONTENT", json.get("CHECK_CONTENT"));
                itme.put("CHECK_STANDARD", json.get("CHECK_STANDARD"));
                itme.put("REFERENCE_BASIS", json.get("REFERENCE_BASIS"));
                itme.put("CHECK_QUALIFIED", json.get("CHECK_QUALIFIED"));
                itme.put("CHECK_UNQUALIFIED", json.get("CHECK_UNQUALIFIED"));
                itme.put("OPERATION_TYPE", json.get("OPERATION_TYPE"));
                itme.put("COMMON_ITEM_SORT", commonSort);
                itme.put("COMMON_ID", json.get("COMMON_ID") == null ? "" : json.get("COMMON_ID"));
                itme.put("COMMON_ITEM_ID", json.get("COMMON_ITEM_ID") == null ? "" : json.get("COMMON_ITEM_ID"));
                itme.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());    //企业
                itme.put("ISDELETE", "0");    //是否删除
                itme.put("CREATOR_ID", Jurisdiction.getUSER_ID());    //添加人id
                itme.put("CREATOR_NAME", Jurisdiction.getUsername());    //添加人
                itme.put("CREATE_TIME", DateUtil.date2Str(new Date()));    //创建时间
                itme.put("OPERATOR_ID", Jurisdiction.getUSER_ID());    //修改人
                itme.put("OPERATOR_NAME", Jurisdiction.getUsername());    //修改时间
                itme.put("OPERATE_TIME", DateUtil.date2Str(new Date()));    //修改时间
                itme.put("DELETEOR_ID", Jurisdiction.getUSER_ID());    //添加人id
                itme.put("DELETEOR_NAME", Jurisdiction.getUsername());    //添加人
                itme.put("DELETE_TIME", DateUtil.date2Str(new Date()));    //删除时间
                customItemService.save(itme);
            }
        }
        if (pd.getString("TYPE").equals("listType0006")) {
            pd.put("ISDELETE", "-99");
        } else {
            pd.put("ISDELETE", "0");
        }
        customService.edit(pd); // 修改清单管理的内容
        oldPd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());
        pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());
        // 修改清单统计
        if (oldPd.get("TYPE") != null && Tools.notEmpty(oldPd.get("TYPE").toString())) {
            oldPd.put("CUSTOMSTATISTICS_ID", this.get32UUID());    //主键
            if ("listType0005".equals(oldPd.get("TYPE").toString())) {
                oldPd.put("STARTTIME", oldPd.get("START_DATE").toString() + " 00:00:00");
                oldPd.put("ENDTIME", oldPd.get("END_DATE").toString() + " 23:59:59");
                oldPd.put("PERIOD", null);
                PageData statistics = customStatisticsService.findByCondition(oldPd);
                if (statistics != null && statistics.get("CUSTOMSTATISTICS_ID") != null) {
                    if (Integer.parseInt(statistics.get("NOTEXAMINEDNUM").toString()) - 2 <= 0) {
                        customStatisticsService.deletewl(statistics);
                    } else {
                        statistics.put("NOTEXAMINEDNUM", Integer.parseInt(statistics.get("NOTEXAMINEDNUM").toString()) - 2);
                        customStatisticsService.edit(statistics);
                    }
                }
            } else {
                if (oldPd.get("PERIOD") != null && Tools.notEmpty(oldPd.get("PERIOD").toString())) {
                    String period = oldPd.get("PERIOD").toString();
                    switch (period) {
                        case "checkPeriod0001"://每日
                            oldPd.put("STARTTIME", DateUtil.getDay() + " 00:00:00");
                            oldPd.put("ENDTIME", DateUtil.getDay() + " 23:59:59");
                            break;

                        case "checkPeriod0002"://每周
                            oldPd.put("STARTTIME", DateUtil.getWeekStart());
                            oldPd.put("ENDTIME", DateUtil.getWeekEnd());
                            break;

                        case "checkPeriod0003"://每旬
                            String year = DateUtil.getYear().toString();
                            String month = DateUtil.getMonth().toString();
                            Integer day = Integer.parseInt(DateUtil.getOnlyDay().toString());
                            String startTime = year + "-" + month + "-";
                            String endTime = year + "-" + month + "-";
                            if (day <= 10) {
                                startTime = startTime + "01 00:00:00";
                                endTime = endTime + "10 23:59:59";
                            } else if (day > 10 && day <= 20) {
                                startTime = startTime + "11 00:00:00";
                                endTime = endTime + "20 23:59:59";
                            } else {
                                startTime = startTime + "21 00:00:00";
                                endTime = DateUtil.getMonthEndDay() + " 23:59:59";
                            }
                            oldPd.put("STARTTIME", startTime);
                            oldPd.put("ENDTIME", endTime);
                            break;

                        case "checkPeriod0004"://每月
                            oldPd.put("STARTTIME", DateUtil.getMonthFirstDay() + " 00:00:00");
                            oldPd.put("ENDTIME", DateUtil.getMonthEndDay() + " 23:59:59");
                            break;

                        case "checkPeriod0005"://每季
                            oldPd.put("STARTTIME", DateUtil.quarterStart() + " 00:00:00");
                            oldPd.put("ENDTIME", DateUtil.quarterEnd() + " 23:59:59");
                            break;

                        case "checkPeriod0006"://每年
                            oldPd.put("STARTTIME", DateUtil.getCurrYearFirst() + " 00:00:00");
                            oldPd.put("ENDTIME", DateUtil.getCurrYearLast() + " 23:59:59");
                            break;

                        case "checkPeriod0007"://半年
                            String byear = DateUtil.getYear().toString();
                            Integer bmonth = Integer.parseInt(DateUtil.getMonth().toString());
                            if (bmonth <= 6) {
                                oldPd.put("STARTTIME", byear + "-01-01 00:00:00");
                                oldPd.put("ENDTIME", byear + "-06-30 23:59:59");
                            } else if (bmonth > 6) {
                                oldPd.put("STARTTIME", byear + "-07-01 00:00:00");
                                oldPd.put("ENDTIME", byear + "-12-31 23:59:59");
                            }
                            break;

                        default:
                            break;
                    }
                }
                PageData statistics = customStatisticsService.findByCondition(oldPd);
                if (statistics != null && statistics.get("CUSTOMSTATISTICS_ID") != null) {
                    if (Integer.parseInt(statistics.get("NOTEXAMINEDNUM").toString()) - 1 <= 0) {
                        customStatisticsService.deletewl(statistics);
                    } else {
                        statistics.put("NOTEXAMINEDNUM", Integer.parseInt(statistics.get("NOTEXAMINEDNUM").toString()) - 1);
                        customStatisticsService.edit(statistics);
                    }
                }
            }
        }
        if (pd.get("TYPE") != null && Tools.notEmpty(pd.get("TYPE").toString())) {
            pd.put("CUSTOMSTATISTICS_ID", this.get32UUID());    //主键
            if ("listType0005".equals(pd.get("TYPE").toString())) {
                pd.put("STARTTIME", pd.get("START_DATE").toString() + " 00:00:00");
                pd.put("ENDTIME", pd.get("END_DATE").toString() + " 23:59:59");
                pd.put("PERIOD", null);
                PageData statistics = customStatisticsService.findByCondition(pd);
                if (statistics != null && statistics.get("CUSTOMSTATISTICS_ID") != null) {
                    statistics.put("NOTEXAMINEDNUM", Integer.parseInt(statistics.get("NOTEXAMINEDNUM").toString()) + 2);
                    customStatisticsService.edit(statistics);
                } else {
                    pd.put("NOTEXAMINEDNUM", 2);
                    customStatisticsService.save(pd);
                }
            } else {
                if (pd.get("PERIOD") != null && Tools.notEmpty(pd.get("PERIOD").toString())) {
                    String period = pd.get("PERIOD").toString();
                    switch (period) {
                        case "checkPeriod0001"://每日
                            pd.put("STARTTIME", DateUtil.getDay() + " 00:00:00");
                            pd.put("ENDTIME", DateUtil.getDay() + " 23:59:59");
                            break;

                        case "checkPeriod0002"://每周
                            pd.put("STARTTIME", DateUtil.getWeekStart());
                            pd.put("ENDTIME", DateUtil.getWeekEnd());
                            break;

                        case "checkPeriod0003"://每旬
                            String year = DateUtil.getYear().toString();
                            String month = DateUtil.getMonth().toString();
                            Integer day = Integer.parseInt(DateUtil.getOnlyDay().toString());
                            String startTime = year + "-" + month + "-";
                            String endTime = year + "-" + month + "-";
                            if (day <= 10) {
                                startTime = startTime + "01 00:00:00";
                                endTime = endTime + "10 23:59:59";
                            } else if (day > 10 && day <= 20) {
                                startTime = startTime + "11 00:00:00";
                                endTime = endTime + "20 23:59:59";
                            } else {
                                startTime = startTime + "21 00:00:00";
                                endTime = DateUtil.getMonthEndDay() + " 23:59:59";
                            }
                            pd.put("STARTTIME", startTime);
                            pd.put("ENDTIME", endTime);
                            break;

                        case "checkPeriod0004"://每月
                            pd.put("STARTTIME", DateUtil.getMonthFirstDay() + " 00:00:00");
                            pd.put("ENDTIME", DateUtil.getMonthEndDay() + " 23:59:59");
                            break;

                        case "checkPeriod0005"://每季
                            pd.put("STARTTIME", DateUtil.quarterStart() + " 00:00:00");
                            pd.put("ENDTIME", DateUtil.quarterEnd() + " 23:59:59");
                            break;

                        case "checkPeriod0006"://每年
                            pd.put("STARTTIME", DateUtil.getCurrYearFirst() + " 00:00:00");
                            pd.put("ENDTIME", DateUtil.getCurrYearLast() + " 23:59:59");
                            break;

                        case "checkPeriod0007"://半年
                            String byear = DateUtil.getYear().toString();
                            Integer bmonth = Integer.parseInt(DateUtil.getMonth().toString());
                            if (bmonth <= 6) {
                                pd.put("STARTTIME", byear + "-01-01 00:00:00");
                                pd.put("ENDTIME", byear + "-06-30 23:59:59");
                            } else if (bmonth > 6) {
                                pd.put("STARTTIME", byear + "-07-01 00:00:00");
                                pd.put("ENDTIME", byear + "-12-31 23:59:59");
                            }
                            break;

                        default:
                            break;
                    }
                }
                PageData statistics = customStatisticsService.findByCondition(pd);
                if (statistics != null && statistics.get("CUSTOMSTATISTICS_ID") != null) {
                    statistics.put("NOTEXAMINEDNUM", Integer.parseInt(statistics.get("NOTEXAMINEDNUM").toString()) + 1);
                    customStatisticsService.edit(statistics);
                } else {
                    pd.put("NOTEXAMINEDNUM", 1);
                    customStatisticsService.save(pd);
                }
            }
        }
        map.put("result", errInfo);
        return map;
    }

    //
//	 /**导出到excel
//	 * @param
//	 * @throws Exception
//	 */
//	@RequestMapping(value="/excel")
//	public ModelAndView exportExcel() throws Exception{
//		ModelAndView mv = new ModelAndView();
//		PageData pd = new PageData();
//		pd = this.getPageData();
//		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("企业id");	//4
//		titles.add("添加人");	//5
//		titles.add("添加时间");	//6
//		titles.add("修改人");	//7
//		titles.add("修改时间");	//8
//		titles.add("是否删除 1-是  0-否");	//9
//		dataMap.put("titles", titles);
//		List<PageData> varOList = listmanagerService.listAll(pd);
//		List<PageData> varList = new ArrayList<PageData>();
//		for(int i=0;i<varOList.size();i++){
//			PageData vpd = new PageData();
//			vpd.put("var1", varOList.get(i).getString("NAME"));	    //1
//			vpd.put("var2", varOList.get(i).getString("PERIOD"));	    //2
//			vpd.put("var3", varOList.get(i).getString("TYPE"));	    //3
//			vpd.put("var4", varOList.get(i).getString("CORPINFO_ID"));	    //4
//			vpd.put("var5", varOList.get(i).getString("CREATOR"));	    //5
//			vpd.put("var6", varOList.get(i).getString("CREATTIME"));	    //6
//			vpd.put("var7", varOList.get(i).getString("OPERATOR"));	    //7
//			vpd.put("var8", varOList.get(i).getString("OPERATTIME"));	    //8
//			vpd.put("var9", varOList.get(i).getString("ISDELETE"));	    //9
//			varList.add(vpd);
//		}
//		dataMap.put("varList", varList);
//		ObjectExcelView erv = new ObjectExcelView();
//		mv = new ModelAndView(erv,dataMap);
//		return mv;
//	}
//
//	/**列表
//	 * @param page
//	 * @throws Exception
//	 */
//	@RequestMapping(value="/checkListIndex")
//	@ResponseBody
//	@LogAnno(menuType= "首页",menuServer= "首页",instructionsOperate = "首页",instructionsType = "列表")
//	public Object checkListIndex() 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("POST_ID", Jurisdiction.getPOST_ID());	//岗位
//		pd.put("USER_ID", Jurisdiction.getUSER_ID());
//		pd.put("orderUserId", Jurisdiction.getUSER_ID());
//		pd.put("DEPARTMENT_ID", Jurisdiction.getDEPARTMENT_ID());
////		String ids = departmentService.getDEPARTMENT_IDS(DEPARTMENT_ID);
////		if(Jurisdiction.getIS_MAIN().equals("0")) {
////			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_ID", DEPARTMENT_ID);
////			}
////		}
//		List<PageData>	varList = listmanagerService.listAll(pd);	//列出ListManager列表
//		int wjcNum = 0;
//		int yjcNum = 0;
//		for (PageData list : varList) {
//			if(list.getString("TYPE").equals("listType0005")) {
//				if(Integer.parseInt(list.get("checkCount").toString()) > 0) {
//					yjcNum++;
//				} else {
//					wjcNum++;
//				}
//				continue;
//			}
//			if(Integer.parseInt(list.get("checkCount").toString()) > 0) {
//				yjcNum++;
//			} else {
//				wjcNum++;
//			}
//		}
//		map.put("yjcNum", yjcNum);
//		map.put("wjcNum", wjcNum);
//		map.put("varList", varList);
//		map.put("result", errInfo);
//		return map;
//	}
//
//
//	/**列表
//	 * @param page
//	 * @throws Exception
//	 */
//	@RequestMapping(value="/listAllByCorpMsm")
//	@ResponseBody
//	public Object listAllByCorpMsm() throws Exception{
//		Map<String,Object> map = new HashMap<String,Object>();
//		String errInfo = "success";
//		PageData pd = new PageData();
//		pd = this.getPageData();
//		List<PageData>	varList = listmanagerService.listAllByCorpMsm(pd);	//列出ListManager列表
//		if(varList != null && varList.size() > 0) {
//			// 用户合集
//			Map<String, PageData> varMap = new HashMap<String, PageData>();
//			for(int i = 0;i<varList.size();i++) {
//				// 查询未检查清单，并按userid分组
//				if(Integer.parseInt(varList.get(i).get("checkCount").toString()) == 0) {
//					if(!varMap.containsKey(varList.get(i).get("USER_ID").toString())) {// 用户不存在时，向合集中加入该用户\
//						PageData user = new PageData();
//						user.put("USER_ID", varList.get(i).get("USER_ID"));
//						user.put("USER_NAME", varList.get(i).get("USER_NAME"));
//						user.put("PHONE", varList.get(i).get("PHONE"));
//						user.put("NUM", 1);
//						user.put("CORPINFO_ID", varList.get(i).get("CORPINFO_ID"));
//						user.put("SMS_COUNT", varList.get(i).get("SMS_COUNT"));
//						varMap.put(varList.get(i).get("USER_ID").toString(), user);
//					} else {
//						PageData uData = varMap.get(varList.get(i).get("USER_ID").toString());
//						uData.put("NUM", Integer.valueOf(uData.get("NUM").toString())+1);
//						varMap.put(varList.get(i).get("USER_ID").toString(), uData);
//					}
//				}
//			}
//			// 短信集合
//			List<PageData> msmList = new ArrayList<PageData>(varMap.values());
//			map.put("msmList", msmList);
//
//		}
//
//		map.put("result", errInfo);
//		return map;
//	}
//	/**根据分类统计清单
//	 * @param page
//	 * @throws Exception
//	 */
//	@RequestMapping(value="/countListByType")
//	@ResponseBody
//	public Object countListByType() 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<PageData>	varList = listmanagerService.countListByType(pd);	//列出ListManager列表
//		List<PageData> datas = new ArrayList<PageData>();
//
//		/*DecimalFormat df = new DecimalFormat("#.00");
//		Double sum = 0d;
//		for(PageData list:varList) {
//			sum += Double.parseDouble(list.get("NUM").toString());
//		}
//		for(PageData list: varList) {
//			PageData data = new PageData();
//			Double num = Double.parseDouble(list.get("NUM").toString());
//			data.put("value", Double.parseDouble(df.format(num/sum)));
//			data.put("name", list.getString("NAME"));
//			datas.add(data);
//		}*/
//		for(PageData list: varList) {
//			PageData data = new PageData();
//			data.put("value", Integer.parseInt(list.get("NUM").toString()));
//			data.put("name", list.getString("NAME"));
//			datas.add(data);
//		}
//		map.put("datas", datas);
//		map.put("result", errInfo);
//		return map;
//	}
//
//	/**首页 获取折线图
//	 * @param page
//	 * @throws Exception
//	 */
//	@RequestMapping(value="/goIndexCount")
//	@ResponseBody
//	@LogAnno(menuType= "首页",menuServer= "首页",instructionsOperate = "首页",instructionsType = "首页 获取折线图")
//	public Object goIndexCount() 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);
//		pd.put("TIME", dates.get(0));
//		List<PageData> varList = listmanagerService.goIndexCount(pd);
//		List<String> xcqd = new ArrayList<String>();
//		List<String> jcqd = new ArrayList<String>();
//		List<String> zhqd = new ArrayList<String>();
//		for(int i = 0; i < dates.size(); i++) {
//			xcqd.add("0");
//			jcqd.add("0");
//			zhqd.add("0");
//		}
//		Map<String, PageData> listMap = new HashMap<>();
//		if(varList != null && varList.size() > 0) {
//			for(PageData list : varList) {
//				int index = dates.indexOf(list.getString("TIME"));
//				switch (list.getString("SCREENTYPE")) {
//					case "riskChecklistType0001":
//						xcqd.set(index, list.get("COUNT").toString());
//						break;
//					case "riskChecklistType0002":
//
//						jcqd.set(index, list.get("COUNT").toString());
//						break;
//					case "zhqd03":
//
//						zhqd.set(index, list.get("COUNT").toString());
//						break;
//
//					default:
//						break;
//				}
//			}
//		}
//
//		map.put("xcqd", xcqd);
//		map.put("jcqd", jcqd);
//		map.put("zhqd", zhqd);
//		map.put("dates", dates);
//		map.put("result", errInfo);
//		return map;
//	}
//
//	/**根据分类统计清单
//	 * @param page
//	 * @throws Exception
//	 */
//	@RequestMapping(value="/checkPlan")
//	@ResponseBody
//	@LogAnno(menuType= "双重预防",menuServer= "隐患排查",instructionsOperate = "排查计划",instructionsType = "根据分类统计清单")
//	public Object checkPlan() 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<PageData> planList = listmanagerService.listAllPlan(null);
//		Map<String,PageData> planMap = new HashMap<String,PageData>();
//		for (PageData pageData : planList) {
//			pageData.put("dept_str", "");
//			planMap.put(pageData.getString("type_bianma") + "," + pageData.getString("level_bianma") + "," + pageData.getString("period_bianma"),pageData);
//		}
//		//企业所有应查数
//		List<PageData> staList = customStatisticsService.listAllForPlan(pd);
//		for (PageData pageData : staList) {
//			String rowName = pageData.getString("TYPE") + "," + pageData.getString("level_bianma") + "," + pageData.getString("PERIOD");
//			PageData row = planMap.get(rowName);
//			if(row!=null){
//				row.put("check_count",Integer.parseInt(row.get("check_count").toString()) + Integer.parseInt(pageData.get("NOTEXAMINEDNUM").toString()));
//			}
//		}
//		//企业所有清单数
//		List<PageData> liList = listmanagerService.listAllForPlan(pd);
//		for (PageData pageData : liList) {
//			String rowName = pageData.getString("TYPE") + "," + pageData.getString("level_bianma") + "," + pageData.getString("PERIOD");
//			PageData row = planMap.get(rowName);
//			if(row!=null){
//				row.put("list_count",Integer.parseInt(row.get("list_count").toString()) + 1 );
//				row.put("dept_str",row.get("dept_str").toString() +  pageData.getString("DEPARTMENT_ID") + ",");
//			}
//		}
//
//		for (PageData pageData : planList) {
//			if(pageData.get("dept_str")!=null && pageData.get("dept_str").toString()!="")
//				pageData.put("dept_count", new HashSet(Arrays.asList(pageData.get("dept_str").toString().substring(0,pageData.get("dept_str").toString().length()-1).split(","))).size());
//		}
//
//		map.put("planList",planList);
//		map.put("result", errInfo);
//		return map;
//	}
//
//
////	/**根据分类统计清单
////	 * @param page
////	 * @throws Exception
////	 */
////	@RequestMapping(value="/checkPlan")
////	@ResponseBody
////	public Object checkPlan() throws Exception{
////		Map<String,Object> map = new HashMap<String,Object>();
////		String errInfo = "success";
////		PageData pd = new PageData();
////		pd = this.getPageData();
////		if(pd.get("USER_ID") == null || "".equals(pd.get("USER_ID").toString())) {
////			pd.put("USER_ID", Jurisdiction.getUSER_ID());
////		}
////		pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());	//企业
////		List<PageData> varList = listmanagerService.listAll(pd);	//列出ListManager列表
////		Map<String,Object> typeMap = new HashMap<String,Object>();
////
////		for(PageData list: varList) {
////			if(list.get("TYPE").equals("listType0001")) {
////				if(!typeMap.containsKey("日常清单")){
////					typeMap.put("日常清单",new HashMap<String,Object>());
////				}
////
////				Map<String,Object> levelMap = (Map<String,Object>)typeMap.get("日常清单");
////				if(list.get("DEPARTMENT_LEVEL").equals("departmentLevel0001")) {
////					if (!levelMap.containsKey("厂级")) {
////						levelMap.put("厂级", new HashMap<String, Object>());
////					}
////
////					Map<String,Object> periodMap = (Map<String,Object>)levelMap.get("厂级");
////					if(list.get("PERIOD").equals("checkPeriod0001")) {
////						if (!periodMap.containsKey("每日")) {
////							periodMap.put("每日", new HashMap<String, Object>());
////						}
////					}
////				} else if(list.get("DEPARTMENT_LEVEL").equals("departmentLevel0002")) {
////					if (!levelMap.containsKey("车间级")) {
////						levelMap.put("车间级", new HashMap<String, Object>());
////					}
////
////					Map<String,Object> periodMap = (Map<String,Object>)levelMap.get("车间级");
////					if(list.get("PERIOD").equals("checkPeriod0001")) {
////						if (!periodMap.containsKey("每日")) {
////							periodMap.put("每日", new HashMap<String, Object>());
////						}
////					}
////				} else if(list.get("DEPARTMENT_LEVEL").equals("departmentLevel0003")) {
////					if (!levelMap.containsKey("班组级")) {
////						levelMap.put("班组级", new HashMap<String, Object>());
////					}
////
////					Map<String,Object> periodMap = (Map<String,Object>)levelMap.get("班组级");
////					if(list.get("PERIOD").equals("checkPeriod0001")) {
////						if (!periodMap.containsKey("每日")) {
////							periodMap.put("每日", new HashMap<String, Object>());
////						}
////					}
////				}
////			}
////		}
////		map.put("result", errInfo);
////		return map;
////	}
//
//	/**获取巡检路线
//	 * @param
//	 * @throws Exception
//	 */
//	@RequestMapping(value="/getRoute")
//	@ResponseBody
//	@LogAnno(menuType= "双重预防",menuServer= "隐患排查",instructionsOperate = "清单管理",instructionsType = "获取巡检路线")
//	public Object getRisk() throws Exception {
//		Map<String, Object> map = new HashMap<String, Object>();
//		String errInfo = "success";
//		PageData pd = new PageData();
//		pd = this.getPageData();
//		List<PageData> varList = listmanagerService.listAllRisk(pd);
//		map.put("varList", varList);
//		map.put("result", errInfo);
//		return map;
//	}
//
//	/**设置巡检路线
//	 * @param
//	 * @throws Exception
//	 */
//	@RequestMapping(value="/setRout")
//	@ResponseBody
//	@LogAnno(menuType= "双重预防",menuServer= "隐患排查",instructionsOperate = "清单管理",instructionsType = "设置巡检路线")
//	public Object setRout() throws Exception {
//		Map<String, Object> map = new HashMap<String, Object>();
//		String errInfo = "success";
//		PageData pd = new PageData();
//		pd = this.getPageData();
//		//巡检路线
//		checkRouteService.delete(pd);
//		List<JSONObject> routes = (List<JSONObject>) JSON.parse(pd.get("ROUTE").toString());
//		for (int j = 0; j < routes.size() ; j++) {
//			JSONObject json = routes.get(j);
//			if(json.get("IDENTIFICATIONPARTS_ID")!=null && json.get("IDENTIFICATIONPARTS_ID")!="") {
//				PageData route = new PageData();
//				route.put("CHECKROUTE_ID", this.get32UUID());	//主键
//				route.put("LISTMANAGER_ID",pd.get("LISTMANAGER_ID"));
//				route.put("IDENTIFICATIONPARTS_ID", json.get("IDENTIFICATIONPARTS_ID"));
//				route.put("ORDERBY",j);
//				checkRouteService.save(route);
//			}
//		}
//		map.put("result", errInfo);
//		return map;
//	}
//
//	/**
//	 * BI页清单排查类型统计
//	 *
//	 * @param
//	 * @throws Exception
//	 */
//	@RequestMapping(value = "/countNumBi")
//	@ResponseBody
//	public Object countNumBi() 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("YEAR",new Date().getYear()+1900);
//		List<PageData> typeList = listmanagerService.getCountNumBi(pd);
//		map.put("typeList", typeList);
//		map.put("result", errInfo);
//		return map;
//	}
//
    @RequestMapping(value = "/saveBaoBaoType")
    @ResponseBody
    public Object saveBaoBaoType() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        customService.saveBaoBaoType(pd);
        map.put("result", errInfo);
        return map;
    }

    /**启用
     * @param out
     * @throws Exception
     */
    @RequestMapping(value="/enable")
    // @RequiresPermissions("listmanager:del")
    @ResponseBody
    @LogAnno(menuType= "双重预防",menuServer= "隐患排查",instructionsOperate = "清单管理",instructionsType = "启用")
    public Object enable() throws Exception{
        Map<String,String> map = new HashMap<String,String>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        pd.put("OPERATOR", Jurisdiction.getUsername());	//修改人
        pd.put("OPERATTIME", DateUtil.date2Str(new Date()));	//修改时间
        customService.enable(pd);
        pd = customService.findById(pd);
        // 启用清单时，修改禁用清单时间段的结束时间
        PageData disPd = new PageData();
        disPd.put("CUSTOM_ID", pd.get("CUSTOM_ID"));
        disPd.put("CORPINFO_ID", pd.get("CORPINFO_ID"));
        disPd = customDisableTimeService.findByList(pd);
        disPd.put("ENDTIME", DateUtil.date2Str(new Date()));
        disPd.put("OPERATOR", Jurisdiction.getUsername());	//修改人
        disPd.put("OPERATTIME", DateUtil.date2Str(new Date()));	//修改时间
        customDisableTimeService.editEndTime(disPd);
        // 修改清单统计
        if(pd.get("TYPE") != null && Tools.notEmpty(pd.get("TYPE").toString())) {
            if("listType0005".equals(pd.get("TYPE").toString())) {
                pd.put("CUSTOMSTATISTICS_ID", this.get32UUID());	//主键
                pd.put("STARTTIME", pd.get("START_DATE").toString()+" 00:00:00");
                pd.put("ENDTIME", pd.get("END_DATE").toString()+" 23:59:59");
                pd.put("PERIOD", null);
                PageData statistics = customStatisticsService.findByCondition(pd);
                if(statistics != null && statistics.get("CUSTOMSTATISTICS_ID") != null) {
                    statistics.put("NOTEXAMINEDNUM", Integer.parseInt(statistics.get("NOTEXAMINEDNUM").toString())+2);
                    customStatisticsService.edit(statistics);
                }
                pd.put("ISSTATISTICS", '1');
                // 本期已检查的不计入统计
                customCheckRecordService.editStatistics(pd);
            } else {
                if(pd.get("PERIOD") != null && Tools.notEmpty(pd.get("PERIOD").toString())) {
                    String period = pd.get("PERIOD").toString();
                    switch (period) {
                        case "checkPeriod0001"://每日
                            pd.put("STARTTIME", DateUtil.getDay()+" 00:00:00");
                            pd.put("ENDTIME", DateUtil.getDay()+" 23:59:59");
                            break;

                        case "checkPeriod0002"://每周
                            pd.put("STARTTIME", DateUtil.getWeekStart());
                            pd.put("ENDTIME", DateUtil.getWeekEnd());
                            break;

                        case "checkPeriod0003"://每旬
                            String year = DateUtil.getYear().toString();
                            String month = DateUtil.getMonth().toString();
                            Integer day = Integer.parseInt(DateUtil.getOnlyDay().toString());
                            String startTime = year + "-" + month + "-";
                            String endTime = year + "-" + month + "-";
                            if(day <= 10) {
                                startTime = startTime+"01 00:00:00";
                                endTime = endTime+"10 23:59:59";
                            } else if(day > 10 && day <= 20) {
                                startTime = startTime+"11 00:00:00";
                                endTime = endTime+"20 23:59:59";
                            } else {
                                startTime = startTime+"21 00:00:00";
                                endTime = DateUtil.getMonthEndDay()+" 23:59:59";
                            }
                            pd.put("STARTTIME", startTime);
                            pd.put("ENDTIME", endTime);
                            break;

                        case "checkPeriod0004"://每月
                            pd.put("STARTTIME", DateUtil.getMonthFirstDay()+" 00:00:00");
                            pd.put("ENDTIME", DateUtil.getMonthEndDay()+" 23:59:59");
                            break;

                        case "checkPeriod0005"://每季
                            pd.put("STARTTIME", DateUtil.quarterStart()+" 00:00:00");
                            pd.put("ENDTIME", DateUtil.quarterEnd()+" 23:59:59");
                            break;

                        case "checkPeriod0006"://每年
                            pd.put("STARTTIME", DateUtil.getCurrYearFirst()+" 00:00:00");
                            pd.put("ENDTIME", DateUtil.getCurrYearLast()+" 23:59:59");
                            break;

                        case "checkPeriod0007"://半年
                            String byear = DateUtil.getYear().toString();
                            Integer bmonth = Integer.parseInt(DateUtil.getMonth().toString());
                            if(bmonth <= 6) {
                                pd.put("STARTTIME", byear+"-01-01 00:00:00");
                                pd.put("ENDTIME", byear+"-06-30 23:59:59");
                            } else if(bmonth > 6) {
                                pd.put("STARTTIME", byear+"-07-01 00:00:00");
                                pd.put("ENDTIME", byear+"-12-31 23:59:59");
                            }
                            break;

                        default:
                            break;
                    }
                }
                PageData statistics = customStatisticsService.findByCondition(pd);
                if(statistics != null && statistics.get("CUSTOMSTATISTICS_ID") != null) {
                    statistics.put("NOTEXAMINEDNUM", Integer.parseInt(statistics.get("NOTEXAMINEDNUM").toString())+1);
                    customStatisticsService.edit(statistics);
                }

                pd.put("ISSTATISTICS", '1');
                // 本期已检查的不计入统计
                customCheckRecordService.editStatistics(pd);
            }
        }
        // 将本频率内已检查的记录，改为不计入
        map.put("result", errInfo);				//返回结果
        return map;
    }

    /**清单检查记录（日检）统计
     * @param
     * @throws Exception
     */
    @RequestMapping(value="/statisticsListCheckDay")
    @ResponseBody
    @LogAnno(menuType= "双重预防",menuServer= "隐患排查",instructionsOperate = "清单管理",instructionsType = "清单检查记录（日检）统计")
    public Object statisticsListCheckDay() throws Exception{
        Map<String,Object> map = new HashMap<String,Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        String KEYWORDS = pd.getString("KEYWORDS"); // 关键词检索条件
        if (Tools.notEmpty(KEYWORDS))
            pd.put("KEYWORDS", KEYWORDS.trim());

        List<PageData>	varList = customItemService.listAll(pd);
        PageData data = customService.findById(pd);	//根据ID读取
        data.put("YEAR", pd.getString("YEAR"));
        List<PageData> recordList = customCheckRecordService.listAllYearForDay(data);//获取查询月在检查周期内的检查记录

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

    /**清单检查记录（周检）统计
     * @param
     * @throws Exception
     */
    @RequestMapping(value="/statisticsListCheckWeek")
    @ResponseBody
    @LogAnno(menuType= "双重预防",menuServer= "隐患排查",instructionsOperate = "清单管理",instructionsType = "清单检查记录（周检）统计")
    public Object statisticsListCheckWeek() throws Exception{
        Map<String,Object> map = new HashMap<String,Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        String KEYWORDS = pd.getString("KEYWORDS"); // 关键词检索条件
        if (Tools.notEmpty(KEYWORDS))
            pd.put("KEYWORDS", KEYWORDS.trim());

        System.out.println(pd.getString("KEYWORDS"));
        List<PageData>	varList = customItemService.listAll(pd);
        PageData data = customService.findById(pd);	//根据ID读取
        data.put("YEAR", pd.getString("YEAR"));
        List<PageData> recordList = customCheckRecordService.listAllYearForWeek(data);//获取检查周期内的检查记录

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

    /**清单检查记录（旬检）统计
     * @param
     * @throws Exception
     */
    @RequestMapping(value="/statisticsListCheckTenday")
    @ResponseBody
    @LogAnno(menuType= "双重预防",menuServer= "隐患排查",instructionsOperate = "清单管理",instructionsType = "清单检查记录（旬检）统计")
    public Object statisticsListCheckTenday() throws Exception{
        Map<String,Object> map = new HashMap<String,Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        String KEYWORDS = pd.getString("KEYWORDS"); // 关键词检索条件
        if (Tools.notEmpty(KEYWORDS))
            pd.put("KEYWORDS", KEYWORDS.trim());

        System.out.println(pd.getString("KEYWORDS"));
        List<PageData>	varList = customItemService.listAll(pd);
        PageData data = customService.findById(pd);	//根据ID读取
        data.put("YEAR", pd.getString("YEAR"));
        List<PageData> recordList = customCheckRecordService.statisticsListCheckTenday(data);//获取检查周期内的检查记录

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