package com.zcloud.controller.check;

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.logs.LogAnno;
import com.zcloud.service.check.*;
import com.zcloud.service.hiddenDangerCheckStandard.CustomService;
import com.zcloud.service.offduty.OffDutyService;
import com.zcloud.service.risk.IdentificationPartsService;
import com.zcloud.service.risk.RiskPointService;
import com.zcloud.service.statistics.ListStatisticsService;
import com.zcloud.service.system.DepartmentService;
import com.zcloud.service.system.UsersService;
import com.zcloud.util.DateUtil;
import com.zcloud.util.Jurisdiction;
import com.zcloud.util.ObjectExcelView;
import com.zcloud.util.Tools;
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.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.*;

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

	@Autowired
	private ListManagerService listmanagerService;
	@Autowired
	private ListCheckItemService listcheckitemService;
	@Autowired
	private DepartmentService departmentService;
	@Autowired
	private CheckRecordService checkrecordService;
	@Autowired
	private RecordItemService recordItemService;
	@Autowired
	private RiskPointService riskpointService;
	@Autowired
	private ListStatisticsService listStatisticsService;
	@Autowired
	private IdentificationPartsService identificationPartsService;
	@Autowired
	private ListDisableTimeService listdisabletimeService;
	@Autowired
	private CheckRouteService checkRouteService;
	@Autowired
	private UsersService usersService;
	@Autowired
	private OffDutyService offdutyService;
	@Autowired
	private CustomService customService;

	/**新增
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value="/add")
	// @RequiresPermissions("listmanager: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");
		if(pd.get("USER_IDS") != null && Tools.notEmpty(pd.get("USER_IDS").toString())) {
			String[] userIds = pd.get("USER_IDS").toString().split(",");
			for(int i = 0; i < userIds.length; i++) {
				pd.put("LISTMANAGER_ID", this.get32UUID());	//主键
				pd.put("USER_ID", userIds[i]);
				if(pd.get("LISTITEM")!=null && !pd.get("LISTITEM").equals("")) {
					Set<String> set = new HashSet<String>();//记录所有风险点
					int acount=0;//重大风险数
					int bcount=0;//较大风险数
					int ccount=0;//一般风险数
					int dcount=0;//低风险数
					List<JSONObject> list = (List<JSONObject>) JSON.parse(pd.get("LISTITEM").toString());
					System.out.println(list);
					for (JSONObject json : list) {
						if(json.get("RISKCHECKITEM_ID")!=null && json.get("RISKCHECKITEM_ID")!="" && json.get("RISKPOINT_ID")!=null && json.get("RISKPOINT_ID")!="") {
							PageData itme = new PageData();
							itme.put("LISTCHECKITEM_ID", this.get32UUID());	//主键
							itme.put("RISKCHECKITEM_ID", json.get("RISKCHECKITEM_ID"));
							itme.put("RISKPOINT_ID",json.get("RISKPOINT_ID"));
							itme.put("LISTMANAGER_ID",pd.get("LISTMANAGER_ID"));
							itme.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());	//企业
							itme.put("ISDELETE", "0");	//是否删除
							itme.put("CREATOR", Jurisdiction.getUsername());	//添加人
							itme.put("CREATTIME", DateUtil.date2Str(new Date()));	//创建时间
							itme.put("OPERATOR", Jurisdiction.getUsername());	//修改人
							itme.put("OPERATTIME", DateUtil.date2Str(new Date()));	//修改时间
							listcheckitemService.save(itme);
							set.add(json.get("RISKPOINT_ID").toString());
						}
					}
					for (String str : set) {
						PageData rpd= new PageData();
						rpd.put("RISKPOINT_ID", str);
						rpd=this.riskpointService.findById(rpd);
						if(rpd.getString("LEVELID").equals("levelA")) {
							acount++;
						}else if(rpd.getString("LEVELID").equals("levelB")) {
							bcount++;
						}else if(rpd.getString("LEVELID").equals("levelC")) {
							ccount++;
						}else if(rpd.getString("LEVELID").equals("levelD")) {
							dcount++;
						}
					}
					pd.put("ACOUNT", acount);
					pd.put("BCOUNT", bcount);
					pd.put("CCOUNT", ccount);
					pd.put("DCOUNT", dcount);
				}
				//巡检路线
				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("ID")!=null && json.get("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("ID"));
						route.put("ORDERBY",j);
						checkRouteService.save(route);
					}
				}

				pd.put("PERIOD", listPeriod);
				listmanagerService.save(pd);
				// 修改清单统计
				if(!pd.getString("TYPE").equals("listType0006")){
					if(pd.get("TYPE") != null && Tools.notEmpty(pd.get("TYPE").toString())) {
						pd.put("LISTSTATISTICS_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 = listStatisticsService.findByCondition(pd);
							if(statistics != null && statistics.get("LISTSTATISTICS_ID") != null) {
								statistics.put("NOTEXAMINEDNUM", Integer.parseInt(statistics.get("NOTEXAMINEDNUM").toString())+2);
								listStatisticsService.edit(statistics);
							} else {
								pd.put("NOTEXAMINEDNUM", 2);
								listStatisticsService.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 = listStatisticsService.findByCondition(pd);
							if(statistics != null && statistics.get("LISTSTATISTICS_ID") != null) {
								statistics.put("NOTEXAMINEDNUM", Integer.parseInt(statistics.get("NOTEXAMINEDNUM").toString())+1);
								listStatisticsService.edit(statistics);
							} else {
								pd.put("NOTEXAMINEDNUM", 1);
								listStatisticsService.save(pd);
							}
						}
					}
				}

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


	/**禁用
	 * @param out
	 * @throws Exception
	 */
	@RequestMapping(value="/delete")
	// @RequiresPermissions("listmanager:del")
	@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()));	//修改时间
		listmanagerService.delete(pd);
		pd = listmanagerService.findById(pd);
		// 记录清单禁用开始时间

		PageData disPd = new PageData();
		disPd = this.getPageData();
		disPd.put("LISTDISABLETIME_ID", this.get32UUID());	//主键
		disPd.put("LISTMANAGER_ID", pd.get("LISTMANAGER_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()));	//创建时间
		listdisabletimeService.save(disPd);
		// 修改清单统计
		if(pd.get("TYPE") != null && Tools.notEmpty(pd.get("TYPE").toString())) {
			if("listType0005".equals(pd.get("TYPE").toString())) {
				pd.put("LISTSTATISTICS_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 = listStatisticsService.findByCondition(pd);
				if(statistics != null && statistics.get("LISTSTATISTICS_ID") != null) {
					statistics.put("NOTEXAMINEDNUM", Integer.parseInt(statistics.get("NOTEXAMINEDNUM").toString())-2);
					listStatisticsService.edit(statistics);
				}
				pd.put("ISSTATISTICS", '0');
				// 本期已检查的不计入统计
				checkrecordService.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 = listStatisticsService.findByCondition(pd);
				if(statistics != null && statistics.get("LISTSTATISTICS_ID") != null) {
					statistics.put("NOTEXAMINEDNUM", Integer.parseInt(statistics.get("NOTEXAMINEDNUM").toString())-1);
					listStatisticsService.edit(statistics);
				}

				pd.put("ISSTATISTICS", '0');
				// 本期已检查的不计入统计
				checkrecordService.editStatistics(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()));	//修改时间
		listmanagerService.enable(pd);
		pd = listmanagerService.findById(pd);
		// 启用清单时，修改禁用清单时间段的结束时间
		PageData disPd = new PageData();
		disPd.put("LISTMANAGER_ID", pd.get("LISTMANAGER_ID"));
		disPd.put("CORPINFO_ID", pd.get("CORPINFO_ID"));
		disPd = listdisabletimeService.findByList(pd);
		disPd.put("ENDTIME", DateUtil.date2Str(new Date()));
		disPd.put("OPERATOR", Jurisdiction.getUsername());	//修改人
		disPd.put("OPERATTIME", DateUtil.date2Str(new Date()));	//修改时间
		listdisabletimeService.editEndTime(disPd);
		// 修改清单统计
		if(pd.get("TYPE") != null && Tools.notEmpty(pd.get("TYPE").toString())) {
			if("listType0005".equals(pd.get("TYPE").toString())) {
				pd.put("LISTSTATISTICS_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 = listStatisticsService.findByCondition(pd);
				if(statistics != null && statistics.get("LISTSTATISTICS_ID") != null) {
					statistics.put("NOTEXAMINEDNUM", Integer.parseInt(statistics.get("NOTEXAMINEDNUM").toString())+2);
					listStatisticsService.edit(statistics);
				}
				pd.put("ISSTATISTICS", '1');
				// 本期已检查的不计入统计
				checkrecordService.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 = listStatisticsService.findByCondition(pd);
				if(statistics != null && statistics.get("LISTSTATISTICS_ID") != null) {
					statistics.put("NOTEXAMINEDNUM", Integer.parseInt(statistics.get("NOTEXAMINEDNUM").toString())+1);
					listStatisticsService.edit(statistics);
				}

				pd.put("ISSTATISTICS", '1');
				// 本期已检查的不计入统计
				checkrecordService.editStatistics(pd);
			}
		}
		// 将本频率内已检查的记录，改为不计入
		map.put("result", errInfo);				//返回结果
		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 = listmanagerService.findById(pd);

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

		if(pd.get("LISTITEM")!=null && !pd.get("LISTITEM").equals("")) {
			Set<String> set = new HashSet<String>();//记录所有风险点
			int acount=0;//重大风险数
			int bcount=0;//较大风险数
			int ccount=0;//一般风险数
			int dcount=0;//低风险数
			List<JSONObject> list = (List<JSONObject>) JSON.parse(pd.get("LISTITEM").toString());
			for (JSONObject json : list) {
				if(json.get("RISKCHECKITEM_ID")!=null && json.get("RISKCHECKITEM_ID")!="" && json.get("RISKPOINT_ID")!=null && json.get("RISKPOINT_ID")!="") {
					PageData itme = new PageData();
					itme.put("LISTCHECKITEM_ID", this.get32UUID());	//主键
					itme.put("RISKCHECKITEM_ID", json.get("RISKCHECKITEM_ID"));
					itme.put("RISKPOINT_ID",json.get("RISKPOINT_ID"));
					itme.put("LISTMANAGER_ID",pd.get("LISTMANAGER_ID"));
					itme.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());	//企业
					itme.put("ISDELETE", "0");	//是否删除
					itme.put("CREATOR", Jurisdiction.getUsername());	//添加人
					itme.put("CREATTIME", DateUtil.date2Str(new Date()));	//创建时间
					itme.put("OPERATOR", Jurisdiction.getUsername());	//修改人
					itme.put("OPERATTIME", DateUtil.date2Str(new Date()));	//修改时间
					listcheckitemService.save(itme);
					set.add(json.get("RISKPOINT_ID").toString());
				}
			}
			for (String str : set) {
				PageData rpd= new PageData();
				rpd.put("RISKPOINT_ID", str);
				rpd=this.riskpointService.findById(rpd);
				if(rpd.getString("LEVELID").equals("levelA")) {
					acount++;
				}else if(rpd.getString("LEVELID").equals("levelB")) {
					bcount++;
				}else if(rpd.getString("LEVELID").equals("levelC")) {
					ccount++;
				}else if(rpd.getString("LEVELID").equals("levelD")) {
					dcount++;
				}
			}
			pd.put("ACOUNT", acount);
			pd.put("BCOUNT", bcount);
			pd.put("CCOUNT", ccount);
			pd.put("DCOUNT", dcount);
		}

		//巡检路线
		checkRouteService.delete(pd2);
		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("ID")!=null && json.get("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("ID"));
				route.put("ORDERBY",j);
				checkRouteService.save(route);
			}
		}
		if(pd.getString("TYPE").equals("listType0006")){
			pd.put("ISDELETE","-99");
		}else {
			pd.put("ISDELETE","0");
		}
		listmanagerService.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("LISTSTATISTICS_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 = listStatisticsService.findByCondition(oldPd);
				if(statistics != null && statistics.get("LISTSTATISTICS_ID") != null) {
					if(Integer.parseInt(statistics.get("NOTEXAMINEDNUM").toString())-2 <=0) {
						listStatisticsService.deletewl(statistics);
					} else {
						statistics.put("NOTEXAMINEDNUM", Integer.parseInt(statistics.get("NOTEXAMINEDNUM").toString())-2);
						listStatisticsService.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 = listStatisticsService.findByCondition(oldPd);
				if(statistics != null && statistics.get("LISTSTATISTICS_ID") != null) {
					if(Integer.parseInt(statistics.get("NOTEXAMINEDNUM").toString())-1 <=0) {
						listStatisticsService.deletewl(statistics);
					} else {
						statistics.put("NOTEXAMINEDNUM", Integer.parseInt(statistics.get("NOTEXAMINEDNUM").toString())-1);
						listStatisticsService.edit(statistics);
					}
				}
			}
		}


		if(pd.get("TYPE") != null && Tools.notEmpty(pd.get("TYPE").toString())) {

			pd.put("LISTSTATISTICS_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 = listStatisticsService.findByCondition(pd);
				if(statistics != null && statistics.get("LISTSTATISTICS_ID") != null) {
					statistics.put("NOTEXAMINEDNUM", Integer.parseInt(statistics.get("NOTEXAMINEDNUM").toString())+2);
					listStatisticsService.edit(statistics);
				} else {
					pd.put("NOTEXAMINEDNUM", 2);
					listStatisticsService.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 = listStatisticsService.findByCondition(pd);
				if(statistics != null && statistics.get("LISTSTATISTICS_ID") != null) {
					statistics.put("NOTEXAMINEDNUM", Integer.parseInt(statistics.get("NOTEXAMINEDNUM").toString())+1);
					listStatisticsService.edit(statistics);
				} else {
					pd.put("NOTEXAMINEDNUM", 1);
					listStatisticsService.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("OPERATOR", Jurisdiction.getUsername());	//修改人
		npd.put("OPERATTIME", DateUtil.date2Str(new Date()));	//修改时间
		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 = new 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 = listmanagerService.list(page);	//列出ListManager列表
		map.put("varList", varList);
		map.put("page", page);
		map.put("result", errInfo);
		return map;
	}

	/**列表
	 * @param page
	 * @throws Exception
	 */
	@RequestMapping(value="/checkList")
	@ResponseBody
	@LogAnno(menuType= "双重预防",menuServer= "隐患排查",instructionsOperate = "清单排查",instructionsType = "列表")
	public Object checkList(Page page) throws Exception{
		Map<String,Object> map = new HashMap<String,Object>();
		String errInfo = "success";
		PageData pd = new PageData();
		pd = this.getPageData();
		PageData isRest = this.getPageData();
		isRest.put("ISREST", "1");
		isRest.put("USER_ID", Jurisdiction.getUSER_ID());
		isRest.put("CORPINFO_ID",  Jurisdiction.getCORPINFO_ID());
		List<PageData> restList = offdutyService.listAll(isRest);
		if(restList != null && restList.size() > 0) {
			// 休假中
			map.put("ISREST", "1");
		} else {
			// 正常工作
			map.put("ISREST", "0");
		}
		PageData npd = new PageData();
		npd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());	//企业
//		pd.put("POST_ID", Jurisdiction.getPOST_ID());	//岗位
		pd.put("USER_ID", Jurisdiction.getUSER_ID());
		String indexType = pd.getString("indexType");						//关键词检索条件
		if(Tools.notEmpty(indexType))pd.put("indexType", indexType.trim());
		if("1".equals(indexType)) {
			npd.put("STATUS", "0");
			String DEPARTMENT_ID = Jurisdiction.getDEPARTMENT_ID();
			npd.put("DEPARTMENT_ID", DEPARTMENT_ID);
		} else if("2".equals(indexType)) {

			npd.put("STATUS", "1");
			String DEPARTMENT_ID = Jurisdiction.getDEPARTMENT_ID();
			npd.put("DEPARTMENT_ID", DEPARTMENT_ID);
		} else {
			String 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(","));
					npd.put("DEPARTMENT_IDS", ids.split(","));
				}else {
					npd.put("DEPARTMENT_ID", DEPARTMENT_ID);
				}
			}
		}

		npd.put("orderUserId", Jurisdiction.getUSER_ID());
		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());
		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());
		PageData cpd = new 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());
			}
		}
		String DEPTIDS = pd.getString("DEPTIDS");
		if(Tools.notEmpty(DEPTIDS)) {
			String DEPT_IDS[] = DEPTIDS.split(",");
			npd.put("DEPT_IDS", DEPT_IDS);
		}
		npd.put("PERIOD",pd.getString("PERIOD"));
		npd.put("STATUS",pd.getString("STATUS"));
		npd.put("LISTINGLEVEL",pd.getString("LISTINGLEVEL"));
		page.setPd(npd);
		List<PageData>	varList = listmanagerService.checklistPage(page);	//列出ListManager列表
		for (PageData list : varList) {
			String userId= list.getString("USER_ID");
			if(userId.equals(Jurisdiction.getUSER_ID())) {
				list.put("stateMy", "0");
			}else {
				list.put("stateMy", "1");
			}
			list.put("List_type", "1");  //清单种类：风险管控清单
		}
		map.put("varList", varList);
		map.put("page", page);
		map.put("result", errInfo);
		return map;
	}

	/**列表
	 * @param page
	 * @throws Exception
	 */
	@RequestMapping(value="/recordList")
	@ResponseBody
	@LogAnno(menuType= "双重预防",menuServer= "隐患排查",instructionsOperate = "清单检查情况",instructionsType = "列表")
	public Object recordList(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());	//企业
//		pd.put("POST_ID", Jurisdiction.getPOST_ID());	//岗位
		pd.put("USER_ID", Jurisdiction.getUSER_ID());
		npd.put("ISMAIN", Jurisdiction.getIS_MAIN());
		npd.put("ISSUPERVISE", Jurisdiction.getISSUPERVISE());
		npd.put("DEPARTMENT_ID", Jurisdiction.getDEPARTMENT_ID());
		PageData cpd = new 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());
			}
		}
		String DEPTIDS = pd.getString("DEPTIDS");
		if(Tools.notEmpty(DEPTIDS)) {
			String DEPT_IDS[] = DEPTIDS.split(",");
			npd.put("DEPT_IDS", DEPT_IDS);
		}
		String KEYWORDS = pd.getString("KEYWORDS");						//关键词检索条件
		if(Tools.notEmpty(KEYWORDS))npd.put("KEYWORDS", KEYWORDS.trim());
		String STARTTIME = pd.getString("STARTTIME");						//关键词检索条件
		if(Tools.notEmpty(STARTTIME))npd.put("STARTTIME", STARTTIME.trim() + " 00:00:00");
		String ENDTIME = pd.getString("ENDTIME");						//关键词检索条件
		if(Tools.notEmpty(ENDTIME))npd.put("ENDTIME", ENDTIME.trim() + " 23:59:59");
		npd.put("ISDELETE",pd.getString("ISDELETE"));
		npd.put("USERNAME",pd.getString("USERNAME"));
		npd.put("STATUS",pd.getString("STATUS"));
		npd.put("PERIOD",pd.getString("PERIOD"));
		npd.put("OVERTIME",pd.getString("OVERTIME"));
		npd.put("WORKSTATUS",pd.getString("WORKSTATUS"));
		npd.put("LISTINGLEVEL",pd.getString("LISTINGLEVEL"));
		npd.put("TYPE",pd.getString("TYPE"));
		npd.put("HASHIDDEN",pd.getString("HASHIDDEN"));
		npd.put("RISKCHECKLISTTYPE",pd.getString("RISKCHECKLISTTYPE"));
		page.setPd(npd);
		List<PageData>	varList = listmanagerService.recordList(page);	//列出ListManager列表
		for (PageData list : varList) {
			String userId= list.getString("USER_ID");
			if(userId.equals(Jurisdiction.getUSER_ID())) {
				list.put("stateMy", "0");
			}else {
				list.put("stateMy", "1");
			}
		}
		map.put("varList", varList);
		map.put("page", page);
		map.put("result", errInfo);
		return map;
	}


	/**列表
	 * @param page
	 * @throws Exception
	 */
	@RequestMapping(value="/riskStandardRecordList")
	@ResponseBody
	@LogAnno(menuType= "双重预防",menuServer= "隐患排查",instructionsOperate = "清单检查情况",instructionsType = "列表")
	public Object riskStandardRecordList(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());	//企业
//		pd.put("POST_ID", Jurisdiction.getPOST_ID());	//岗位
		pd.put("USER_ID", Jurisdiction.getUSER_ID());
		npd.put("ISMAIN", Jurisdiction.getIS_MAIN());
		npd.put("ISSUPERVISE", Jurisdiction.getISSUPERVISE());
		npd.put("DEPARTMENT_ID", Jurisdiction.getDEPARTMENT_ID());
		PageData cpd = new 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());
			}
		}
		String DEPTIDS = pd.getString("DEPTIDS");
		if(Tools.notEmpty(DEPTIDS)) {
			String DEPT_IDS[] = DEPTIDS.split(",");
			npd.put("DEPT_IDS", DEPT_IDS);
		}
		String KEYWORDS = pd.getString("KEYWORDS");						//关键词检索条件
		if(Tools.notEmpty(KEYWORDS))npd.put("KEYWORDS", KEYWORDS.trim());
		String STARTTIME = pd.getString("STARTTIME");						//关键词检索条件
		if(Tools.notEmpty(STARTTIME))npd.put("STARTTIME", STARTTIME.trim() + " 00:00:00");
		String ENDTIME = pd.getString("ENDTIME");						//关键词检索条件
		if(Tools.notEmpty(ENDTIME))npd.put("ENDTIME", ENDTIME.trim() + " 23:59:59");
		npd.put("ISDELETE",pd.getString("ISDELETE"));
		npd.put("USERNAME",pd.getString("USERNAME"));
		npd.put("STATUS",pd.getString("STATUS"));
		npd.put("PERIOD",pd.getString("PERIOD"));
		npd.put("OVERTIME",pd.getString("OVERTIME"));
		npd.put("LIST_TYPE",pd.getString("LIST_TYPE"));
		npd.put("WORKSTATUS",pd.getString("WORKSTATUS"));
		npd.put("LISTINGLEVEL",pd.getString("LISTINGLEVEL"));
		npd.put("TYPE",pd.getString("TYPE"));
		npd.put("HASHIDDEN",pd.getString("HASHIDDEN"));
		npd.put("RISKCHECKLISTTYPE",pd.getString("RISKCHECKLISTTYPE"));
		page.setPd(npd);
		List<PageData>	varList = listmanagerService.riskStandardRecordList(page);	//列出ListManager列表
		for (PageData list : varList) {
			String userId= list.getString("USER_ID");
			if(userId.equals(Jurisdiction.getUSER_ID())) {
				list.put("stateMy", "0");
			}else {
				list.put("stateMy", "1");
			}
		}
		map.put("varList", varList);
		map.put("page", page);
		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());

		System.out.println(pd.getString("KEYWORDS"));
		List<PageData>	varList = listcheckitemService.listAll(pd);
		pd = listmanagerService.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("LISTMANAGER_ID", ArrayDATA_IDS[i]);
				listmanagerService.remove(pd1);
				pd1 = listmanagerService.findById(pd1);
				if(pd1.get("TYPE") != null && Tools.notEmpty(pd1.get("TYPE").toString())) {
					if("listType0005".equals(pd1.get("TYPE").toString())) {
						pd1.put("LISTSTATISTICS_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 = listStatisticsService.findByCondition(pd1);
						if(statistics != null && statistics.get("LISTSTATISTICS_ID") != null) {
							statistics.put("NOTEXAMINEDNUM", Integer.parseInt(statistics.get("NOTEXAMINEDNUM").toString())-2);
							listStatisticsService.edit(statistics);
						}
						pd1.put("ISSTATISTICS", '0');
						// 本期已检查的不计入统计
						checkrecordService.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 = listStatisticsService.findByCondition(pd1);
						if(statistics != null && statistics.get("LISTSTATISTICS_ID") != null) {
							statistics.put("NOTEXAMINEDNUM", Integer.parseInt(statistics.get("NOTEXAMINEDNUM").toString())-1);
							listStatisticsService.edit(statistics);
						}

						pd1.put("ISSTATISTICS", '0');
						// 本期已检查的不计入统计
						checkrecordService.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("LISTMANAGER_ID", ArrayDATA_IDS[i]);
				listmanagerService.deleted(pd1);
				pd1 = listmanagerService.findById(pd1);
				if(pd1.get("TYPE") != null && Tools.notEmpty(pd1.get("TYPE").toString())) {
					pd1.put("LISTSTATISTICS_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 = listStatisticsService.findByCondition(pd1);
					if(statistics != null && statistics.get("LISTSTATISTICS_ID") != null) {
						statistics.put("NOTEXAMINEDNUM", Integer.parseInt(statistics.get("NOTEXAMINEDNUM").toString())-1);
						listStatisticsService.edit(statistics);
					}
					pd1.put("ISSTATISTICS", '0');
					// 本期已检查的不计入统计
					checkrecordService.editStatistics(pd1);
				}
			}
			errInfo = "success";
		}else{
			errInfo = "error";
		}
		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="/mergeCheckPlan")
	@ResponseBody
	@LogAnno(menuType= "双重预防",menuServer= "隐患排查",instructionsOperate = "排查计划",instructionsType = "根据分类统计清单")
	public Object mergeCheckPlan() 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 = listStatisticsService.mergeListAllForPlan(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.mergeListAllForPlan(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
	@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 = listStatisticsService.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();
		listmanagerService.saveBaoBaoType(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());

		System.out.println(pd.getString("KEYWORDS"));
		List<PageData>	varList = listcheckitemService.listAll(pd);
		PageData data = listmanagerService.findById(pd);	//根据ID读取
		data.put("YEAR", pd.getString("YEAR"));
		List<PageData> recordList = checkrecordService.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 = listcheckitemService.listAll(pd);
		PageData data = listmanagerService.findById(pd);	//根据ID读取
		data.put("YEAR", pd.getString("YEAR"));
		List<PageData> recordList = checkrecordService.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 = listcheckitemService.listAll(pd);
		PageData data = listmanagerService.findById(pd);	//根据ID读取
		data.put("YEAR", pd.getString("YEAR"));
		List<PageData> recordList = checkrecordService.statisticsListCheckTenday(data);//获取检查周期内的检查记录

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

	/**清单排查列表
	 * @param page
	 * @throws Exception
	 */
	@RequestMapping(value="/riskStandardCheckList")
	@ResponseBody
	@LogAnno(menuType= "双重预防",menuServer= "隐患排查",instructionsOperate = "清单排查",instructionsType = "列表")
	public Object riskStandardCheckList(Page page) throws Exception{
		Map<String,Object> map = new HashMap<String,Object>();
		String errInfo = "success";
		PageData pd = new PageData();
		pd = this.getPageData();
		PageData isRest = this.getPageData();
		isRest.put("ISREST", "1");
		isRest.put("USER_ID", Jurisdiction.getUSER_ID());
		isRest.put("CORPINFO_ID",  Jurisdiction.getCORPINFO_ID());
		List<PageData> restList = offdutyService.listAll(isRest);
		if(restList != null && restList.size() > 0) {
			// 休假中
			map.put("ISREST", "1");
		} else {
			// 正常工作
			map.put("ISREST", "0");
		}
		PageData npd = new PageData();
		npd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());	//企业
//		pd.put("POST_ID", Jurisdiction.getPOST_ID());	//岗位
		pd.put("USER_ID", Jurisdiction.getUSER_ID());
		String indexType = pd.getString("indexType");						//关键词检索条件
		if(Tools.notEmpty(indexType))pd.put("indexType", indexType.trim());
		if("1".equals(indexType)) {
			npd.put("STATUS", "0");
			String DEPARTMENT_ID = Jurisdiction.getDEPARTMENT_ID();
			npd.put("DEPARTMENT_ID", DEPARTMENT_ID);
		} else if("2".equals(indexType)) {

			npd.put("STATUS", "1");
			String DEPARTMENT_ID = Jurisdiction.getDEPARTMENT_ID();
			npd.put("DEPARTMENT_ID", DEPARTMENT_ID);
		} else {
			String 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(","));
					npd.put("DEPARTMENT_IDS", ids.split(","));
				}else {
					npd.put("DEPARTMENT_ID", DEPARTMENT_ID);
				}
			}
		}

		npd.put("orderUserId", Jurisdiction.getUSER_ID());
		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());
		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());
		PageData cpd = new 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());
			}
		}
		String DEPTIDS = pd.getString("DEPTIDS");
		if(Tools.notEmpty(DEPTIDS)) {
			String DEPT_IDS[] = DEPTIDS.split(",");
			npd.put("DEPT_IDS", DEPT_IDS);
		}
		npd.put("PERIOD",pd.getString("PERIOD"));
		npd.put("STATUS",pd.getString("STATUS"));
		npd.put("LISTINGLEVEL",pd.getString("LISTINGLEVEL"));
		npd.put("LIST_TYPE",pd.getString("LIST_TYPE"));
		page.setPd(npd);
		List<PageData>	varList = listmanagerService.riskStandardCheckList(page);	//列出ListManager列表
		for (PageData list : varList) {
			String userId= list.getString("USER_ID");
			if(userId.equals(Jurisdiction.getUSER_ID())) {
				list.put("stateMy", "0");
			}else {
				list.put("stateMy", "1");
			}
			list.put("List_type", "1");  //清单种类：风险管控清单
		}
		map.put("varList", varList);
		map.put("page", page);
		map.put("result", errInfo);
		return map;
	}


	/**列表
	 * @param page
	 * @throws Exception
	 */
	@RequestMapping(value="/recordListAll")
	@ResponseBody
	@LogAnno(menuType= "双重预防",menuServer= "隐患排查",instructionsOperate = "清单检查情况",instructionsType = "列表")
	public Object recordListAll(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());	//企业
		pd.put("USER_ID", Jurisdiction.getUSER_ID());
		npd.put("ISMAIN", Jurisdiction.getIS_MAIN());
		npd.put("ISSUPERVISE", Jurisdiction.getISSUPERVISE());
		npd.put("DEPARTMENT_ID", Jurisdiction.getDEPARTMENT_ID());
		PageData cpd = new 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());
			}
		}
		String DEPTIDS = pd.getString("DEPTIDS");
		if(Tools.notEmpty(DEPTIDS)) {
			String DEPT_IDS[] = DEPTIDS.split(",");
			npd.put("DEPT_IDS", DEPT_IDS);
		}
		String KEYWORDS = pd.getString("KEYWORDS");						//关键词检索条件
		if(Tools.notEmpty(KEYWORDS))npd.put("KEYWORDS", KEYWORDS.trim());
		String STARTTIME = pd.getString("STARTTIME");						//关键词检索条件
		if(Tools.notEmpty(STARTTIME))npd.put("STARTTIME", STARTTIME.trim() + " 00:00:00");
		String ENDTIME = pd.getString("ENDTIME");						//关键词检索条件
		if(Tools.notEmpty(ENDTIME))npd.put("ENDTIME", ENDTIME.trim() + " 23:59:59");
		npd.put("ISDELETE",pd.getString("ISDELETE"));
		npd.put("USERNAME",pd.getString("USERNAME"));
		npd.put("STATUS",pd.getString("STATUS"));
		npd.put("PERIOD",pd.getString("PERIOD"));
		npd.put("OVERTIME",pd.getString("OVERTIME"));
		npd.put("WORKSTATUS",pd.getString("WORKSTATUS"));
		npd.put("LISTINGLEVEL",pd.getString("LISTINGLEVEL"));
		npd.put("TYPE",pd.getString("TYPE"));
		npd.put("HASHIDDEN",pd.getString("HASHIDDEN"));
		npd.put("RISKCHECKLISTTYPE",pd.getString("RISKCHECKLISTTYPE"));
		npd.put("LIST_TYPE",pd.getString("LIST_TYPE"));
		page.setPd(npd);
		List<PageData>	varList = listmanagerService.recordListAll(page);	//列出ListManager列表
		for (PageData list : varList) {
			String userId= list.getString("USER_ID");
			if(userId.equals(Jurisdiction.getUSER_ID())) {
				list.put("stateMy", "0");
			}else {
				list.put("stateMy", "1");
			}
		}
		map.put("varList", varList);
		map.put("page", page);
		map.put("result", errInfo);
		return map;
	}
}
