package com.zcloud.service.hiddenDangerCheckStandard.impl;

import com.zcloud.entity.Page;
import com.zcloud.entity.PageData;
import com.zcloud.mapper.datasource.hiddenDangerCheckStandard.CustomCheckRecordMapper;
import com.zcloud.service.hiddenDangerCheckStandard.CustomCheckRecordService;
import com.zcloud.util.DateSysUtil;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * 说明：清单检查记录
 * 作者：luoxiaobao
 * 时间：2021-01-04
 * 官网：www.zcloudchina.com
 */
@Service
@Transactional //开启事物
public class CustomCheckRecordServiceImpl implements CustomCheckRecordService {

	@Autowired
	private CustomCheckRecordMapper customCheckRecordMapper;

	/**新增
	 * @param pd
	 * @throws Exception
	 */
	public void save(PageData pd)throws Exception{
		customCheckRecordMapper.save(pd);
	}

	/**删除
	 * @param pd
	 * @throws Exception
	 */
	public void delete(PageData pd)throws Exception{
		customCheckRecordMapper.delete(pd);
	}

	/**修改
	 * @param pd
	 * @throws Exception
	 */
	public void edit(PageData pd)throws Exception{
		customCheckRecordMapper.edit(pd);
	}

	/**清单逾期检查记录数
	 * @param pd
	 * @throws Exception
	 */
	public int countOverTime(PageData pd)throws Exception{
		return customCheckRecordMapper.countOverTime(pd);
	}

	/**列表
	 * @param page
	 * @throws Exception
	 */
	public List<PageData> list(Page page)throws Exception{
		return customCheckRecordMapper.datalistPage(page);
	}


	/**节假日分页
	 * @param page
	 * @throws Exception
	 */
	public List<PageData> listAllList(Page page)throws Exception{
		return customCheckRecordMapper.listlistPage(page);
	}
	/**列表(全部)
	 * @param pd
	 * @throws Exception
	 */
	public List<PageData> listAll(PageData pd)throws Exception{
		return customCheckRecordMapper.listAll(pd);
	}

	/**列表(全部)
	 * @param pd
	 * @throws Exception
	 */
	public List<PageData> listAllUnfinished(PageData pd)throws Exception{
		return customCheckRecordMapper.listAllUnfinished(pd);
	}
	/**通过清单ID获取风险点数据
	 * @param pd
	 * @throws Exception
	 */
	public List<PageData> findRiskPointByLId(PageData pd)throws Exception{
		return customCheckRecordMapper.findRiskPointByLId(pd);
	}

	/**通过id获取数据
	 * @param pd
	 * @throws Exception
	 */
	public PageData findById(PageData pd)throws Exception{
		return customCheckRecordMapper.findById(pd);
	}

	/**批量删除
	 * @param ArrayDATA_IDS
	 * @throws Exception
	 */
	public void deleteAll(String[] ArrayDATA_IDS)throws Exception{
		customCheckRecordMapper.deleteAll(ArrayDATA_IDS);
	}


	/* 统计功能 */
	@Override
	public List<PageData> listCountDay(PageData pd) throws Exception {
		return customCheckRecordMapper.listCountDay(pd);
	}

	@Override
	public List<PageData> listCountWeek(PageData pd) throws Exception {
		return customCheckRecordMapper.listCountWeek(pd);
	}

	@Override
	public List<PageData> listCountTenDays(PageData pd) throws Exception {
		return customCheckRecordMapper.listCountTenDays(pd);
	}

	@Override
	public List<PageData> listCountMonth(PageData pd) throws Exception {
		return customCheckRecordMapper.listCountMonth(pd);
	}

	@Override
	public List<PageData> listCountQuarter(PageData pd) throws Exception {
		return customCheckRecordMapper.listCountQuarter(pd);
	}

	@Override
	public List<PageData> listCountHalfYear(PageData pd) throws Exception {
		return customCheckRecordMapper.listCountHalfYear(pd);
	}

	@Override
	public List<PageData> listCountYear(PageData pd) throws Exception {
		return customCheckRecordMapper.listCountYear(pd);
	}

	@Override
	public Integer listCountJjr(PageData pd) throws Exception {
		return customCheckRecordMapper.listCountJjr(pd);
	}

	/**修改统计状态
	 * @param pd
	 * @throws Exception
	 */
	public void editStatistics(PageData pd)throws Exception{
		customCheckRecordMapper.editStatistics(pd);
	}

	/**
	 * 查询辨识部位检查记录
	 * @param pd
	 * @return
	 */
	public List<PageData> listLogByIde(PageData pd)throws Exception{
		return customCheckRecordMapper.listLogByIde(pd);
	}

	/**
	 * 指定辨识部位检查记录
	 * @param pd
	 * @return
	 */
	public List<PageData> recordByIde(PageData pd)throws Exception{
		return customCheckRecordMapper.recordByIde(pd);
	}

	/**补录
	 * @param pd
	 * @throws Exception
	 */
	public void recording(PageData pd)throws Exception{
		customCheckRecordMapper.recording(pd);
	}

	/**APP清单检查记录
	 * @param page
	 * @throws Exception
	 */
	public List<PageData> appdatalist(PageData pd)throws Exception{
		return customCheckRecordMapper.appdatalist(pd);
	}

	/**统计各用户各类型检查数据
	 * @param page
	 * @throws Exception
	 */
	public List<PageData> countByPeriodUser(PageData pd)throws Exception{
		return customCheckRecordMapper.countByPeriodUser(pd);
	}

	/**
	 * 查询公司检查过清单的员工总数
	 * @param pd
	 * @return
	 */
	public int getWorkedUserCount(PageData pd) throws Exception{
		return customCheckRecordMapper.getWorkedUserCount(pd);
	}

	/**
	 * 查询公司检查过清单的部门总数
	 * @param pd
	 * @return
	 */
	public int getWorkedDepCount(PageData pd)throws Exception{
		return customCheckRecordMapper.getWorkedDepCount(pd);
	}

	public List<PageData> listTypeBi(PageData pd)throws Exception{
		return customCheckRecordMapper.listTypeBi(pd);
	}

	/**
	 * 查询检查记录(按ids)
	 * @param pd
	 * @return
	 */
	public List<PageData> listForIdsAndMonth(PageData pd)throws Exception{
		return customCheckRecordMapper.listForIdsAndMonth(pd);
	}

	/**
	 * 清单检查记录（日检）统计(按清单ID统计指定年内检查情况)
	 * @param pd
	 * @return
	 */
	public List<PageData> listAllYearForDay(PageData pd)throws Exception {
		List<PageData> list = new ArrayList<>();
		List<PageData> recordList = customCheckRecordMapper.listAllYearForDay(pd);
		List<PageData> trList = new ArrayList<>();
		for (int i = 0; i < 12; i++) {
			PageData month = new PageData();
			month.put("MONTH",(i+1)+"");
			List<PageData> dayList = new ArrayList<>();
			List<PageData> tdList = new ArrayList<>();
			int days = DateSysUtil.getMonthDays(Integer.parseInt(pd.getString("YEAR")), i);
			for (int j = 1; j <= days; j++) {
				PageData day = new PageData();
				day.put("DAY", j+"");
				day.put("CHECKDATA","△"); 	// 默认离岗
				String curDay = pd.getString("YEAR") + "-" + ((i+1) <= 9 ? "0"+(i+1) : (i+1)) + "-" + (j <= 9 ? ("0"+j) : j);
				//清单生成日期在遍历日期之后（未建立清单）
				if (DateSysUtil.fomatDate(pd.getString("CREATTIME").substring(0,10)).after(DateSysUtil.fomatDate(curDay))) {
					day.put("CHECKDATA","-");
				}
				else {
					for (PageData r : recordList) {
						if (curDay.equals(r.getString("PERIODSTART").substring(0,10))) {
							if ("1".equals(r.getString("TYPE"))) {
								day.put("CHECKDATA", "√"); // 已检查（隐患数）
								break;
							} else if ("2".equals(r.getString("TYPE"))) {
								day.put("CHECKDATA","×"); 	// 未排查
								break;
							}
						}
					}
				}
				dayList.add(day);
				if (j % 7 == 0) {
					PageData dayPd = new PageData();
					dayPd.put("DAYLIST", dayList);
					tdList.add(dayPd);
					dayList = new ArrayList<>();
				}
			}
			if (dayList.size() > 0) {
				PageData dayPd = new PageData();
				dayPd.put("DAYLIST", dayList);
				tdList.add(dayPd);
			}
			String curMonth = pd.getString("YEAR") + "-" + ((i+1) <= 9 ? "0"+(i+1) : (i+1));
			List<String> hdList = new ArrayList<>();
			recordList.forEach(record -> {
				if(DateSysUtil.isSameMonth(record.getString("CREATTIME"),curMonth)) {//如果清单创建时间是查询月
					String hddesc = record.getString("HIDDEN_DESC");
					if (StringUtils.isNotBlank(hddesc)) {
						String[] hddescArr = hddesc.split("[$]");
						for (int k = 0; k < hddescArr.length; k++) {
							hdList.add(hddescArr[k]);
						}
					}
				}
			});
			month.put("HDLIST", hdList);
			month.put("TDLIST", tdList);
			trList.add(month);
			if (i!=0 && (i+1) % 2 == 0) {
				PageData tr = new PageData();
				tr.put("TRLIST", trList);
				list.add(tr);
				trList = new ArrayList<>();
			}
		}
		if (trList.size() > 0) {
			PageData tr = new PageData();
			tr.put("TRLIST", trList);
			list.add(tr);
		}
		return list;
	}

	/**
	 * 清单检查记录（周检）统计(按清单ID统计指定年内检查情况)
	 * @param pd
	 * @return
	 */
	public List<PageData> listAllYearForWeek(PageData pd)throws Exception {
		List<PageData> list = new ArrayList<>();
		List<PageData> recordList = customCheckRecordMapper.listAllYearForWeek(pd);
		recordList.forEach( record -> {
			String week = DateSysUtil.getMonthNoAndWeekNo(record.getString("PERIODSTART")); // 按照排查任务的周期开始时间计算该任务是哪月第几周，例如:12,2
			record.put("RECORD_WEEK", week);
		});
		String listWeek = DateSysUtil.getMonthNoAndWeekNo(pd.getString("CREATTIME"));
		int index = 0, colIndex0 = 0, colIndex2 = 0, colIndex3 = 0, colIndex4 = 0, colIndex5 = 0;
		for (int z = 0; z < 24; z++) {
			List<PageData> trList = new ArrayList<>();
			PageData col0 = new PageData();
			col0.put("VALUETYPE","string");
			col0.put("COLSPAN",2);
			col0.put("ROWSPAN",1);
			switch (index){
				case 0:
					col0.put("VALUE","月份");
					trList.add(col0);
					for (int i = 1; i <= 3; i++) {
						PageData month = new PageData();
						month.put("VALUETYPE","string");
						month.put("VALUE", (colIndex0 * 3 + i) + "月");
						month.put("COLSPAN", 5);
						month.put("ROWSPAN", 1);
						trList.add(month);
					}
					colIndex0++;
					break;
				case 1:
					col0.put("VALUE","检查日期");
					trList.add(col0);
					for (int i = 1; i <= 3; i++) {
						for (int j = 1; j <= 5; j++) {
							PageData week = new PageData();
							week.put("VALUETYPE","string");
							week.put("VALUE", "第" + j + "周");
							week.put("COLSPAN", 1);
							week.put("ROWSPAN", 1);
							trList.add(week);
						}
					}
					break;
				case 2:
					col0.put("VALUE","检查情况");
					col0.put("COLSPAN",1);
					col0.put("ROWSPAN",4);
					trList.add(col0);
					PageData col1 = new PageData();
					col1.put("VALUETYPE","string");
					col1.put("VALUE","是否检查");
					col1.put("COLSPAN",1);
					col1.put("ROWSPAN",1);
					trList.add(col1);
					for (int i = 1; i <= 3; i++) {
						for (int j = 1; j <= 5; j++) {
							int month = colIndex2 * 3 + i;
							String curWeek = pd.getString("YEAR") + "," + (month <= 9 ? "0"+month : month) + "," + j;
							PageData col = new PageData();
							col.put("VALUETYPE","string");
							col.put("COLSPAN", 1);
							col.put("ROWSPAN", 1);
							col.put("VALUE","△"); 	// 默认离岗
							//清单生成日期在遍历日期之后（未建立清单）
							if (Integer.parseInt(listWeek.replace(",",""))>Integer.parseInt(curWeek.replace(",",""))) {
								col.put("VALUE","-");
							}
							else {
								for (PageData r : recordList) {
									if (curWeek.equals(r.getString("RECORD_WEEK"))) {
										if ("1".equals(r.getString("TYPE"))) {
											col.put("VALUE", "√"); // 已检查（隐患数）
											break;
										} else if ("2".equals(r.getString("TYPE"))) {
											col.put("VALUE","×"); 	// 未排查
											break;
										}
									}
								}
							}
							trList.add(col);
						}
					}
					colIndex2++;
					break;
				case 3:
					col0.put("VALUE","发现隐患数");
					col0.put("COLSPAN",1);
					col0.put("ROWSPAN",1);
					trList.add(col0);
					PageData col = new PageData();
					col.put("VALUETYPE","array");
					col.put("COLSPAN", 15);
					col.put("ROWSPAN", 1);
					for (int i = 1; i <= 3; i++) {
						for (int j = 1; j <= 5; j++) {
							int month = colIndex3 * 3 + i;
							String curWeek = pd.getString("YEAR") + "," + (month <= 9 ? "0"+month : month) + "," + j;
							PageData col01 = new PageData();
							col01.put("VALUETYPE","string");
							col01.put("COLSPAN", 1);
							col01.put("ROWSPAN", 1);
							col01.put("VALUE","0"); 	// 默认离岗
							//清单生成日期在遍历日期之后（未建立清单）
							if (Integer.parseInt(listWeek.replace(",",""))>Integer.parseInt(curWeek.replace(",",""))) {
								col01.put("VALUE","0");
							}
							else {
								int hiddenCount = 0;
								for (PageData r : recordList) {
									if (curWeek.equals(r.getString("RECORD_WEEK"))) {
										if ("1".equals(r.getString("TYPE"))) {
											hiddenCount += Integer.parseInt(r.getString("HIDDEN_COUNT"));
//											col01.put("VALUE", r.getString("HIDDEN_COUNT")); // 已检查（隐患数）
										} else if ("2".equals(r.getString("TYPE"))) {
											hiddenCount = 0;
//											col01.put("VALUE","0"); 	// 未排查
											break;
										}
									}
								}
											col01.put("VALUE",hiddenCount); 	// 未排查
							}
							trList.add(col01);
						}
					}
//					trList.add(col);
					colIndex3++;
					break;
				case 4:
					col0.put("VALUE","检查时间");
					col0.put("COLSPAN",1);
					trList.add(col0);
					col = new PageData();
					col.put("VALUETYPE","array");
					col.put("COLSPAN", 15);
					col.put("ROWSPAN", 1);
					for (int i = 1; i <= 3; i++) {
						for (int j = 1; j <= 5; j++) {
							int month = colIndex4 * 3 + i;
							String curWeek = pd.getString("YEAR") + "," + (month <= 9 ? "0"+month : month) + "," + j;
							PageData col01 = new PageData();
							col01.put("VALUETYPE","string");
							col01.put("COLSPAN", 1);
							col01.put("ROWSPAN", 1);
							col01.put("VALUE",""); 	// 默认离岗
							//清单生成日期在遍历日期之后（未建立清单）
							if (Integer.parseInt(listWeek.replace(",",""))>Integer.parseInt(curWeek.replace(",",""))) {
								col01.put("VALUE","");
							}
							else {
								for (PageData r : recordList) {
									if (curWeek.equals(r.getString("RECORD_WEEK"))) {
										if ("1".equals(r.getString("TYPE"))) {
											col01.put("VALUE", r.getString("CREATTIME")); // 已检查（隐患数）
											break;
										} else if ("2".equals(r.getString("TYPE"))) {
											col01.put("VALUE",""); 	// 未排查
											break;
										}
									}
								}
							}
							trList.add(col01);
						}
					}
//					trList.add(col);
					colIndex4++;
					break;
				case 5:
					col0.put("VALUE","发现问题");
					col0.put("COLSPAN",1);
					trList.add(col0);
					PageData col02 = new PageData();
					for (int i = 1; i <= 3; i++) {
						List<String> descList = new ArrayList<>();
						col02 = new PageData();
						col02.put("VALUETYPE","array");
						col02.put("COLSPAN", 5);
						col02.put("ROWSPAN", 1);
//						for (int j = 1; j <= 5; j++) {
							int month = colIndex5 * 3 + i;
//							String curWeek = pd.getString("YEAR") + "," + (month <= 9 ? "0"+month : month) + "," + j;
							String curMonth = pd.getString("YEAR") + "-" + (month <= 9 ? "0"+month : month);
							for (PageData r : recordList) {
//								if (curWeek.equals(r.getString("RECORD_WEEK")) && StringUtils.isNotBlank(r.getString("HIDDENDESCR"))) {
								if (DateSysUtil.isSameMonth(r.getString("PERIODSTART"),curMonth) && StringUtils.isNotBlank(r.getString("HIDDENDESCR"))) {
									String[] hddescArr = r.getString("HIDDENDESCR").split("[$]");
									for (int k = 0; k < hddescArr.length; k++) {
										descList.add(hddescArr[k]);
									}
								}
							}
//						}
						col02.put("VALUE",descList);
						trList.add(col02);
					}
					colIndex5++;
					break;
			}
			PageData tr = new PageData();
			tr.put("TRLIST", trList);
			list.add(tr);

			index++;
			if (index==6) { index = 0;}
		}
		return list;
	}

	/**
	 * 清单检查记录（旬检）统计(按清单ID统计指定年内检查情况)
	 * @param pd
	 * @return
	 */
	public List<PageData> statisticsListCheckTenday(PageData pd)throws Exception {
		List<PageData> list = new ArrayList<>();
		List<PageData> recordList = customCheckRecordMapper.listAllYearForTenday(pd);
		String[] tendayList = {"上旬", "中旬", "下旬"};
		String listCreateDate = pd.getString("CREATTIME").substring(0, 10);
		int index = 0, colIndex0 = 0, colIndex2 = 0, colIndex3 = 0, colIndex4 = 0, colIndex5 = 0;
		for (int z = 0; z < 24; z++) {
			List<PageData> trList = new ArrayList<>();
			PageData col0 = new PageData();
			col0.put("VALUETYPE","string");
			col0.put("COLSPAN",2);
			col0.put("ROWSPAN",1);
			switch (index){
				case 0:
					col0.put("VALUE","月份");
					trList.add(col0);
					for (int i = 1; i <= 3; i++) {
						PageData month = new PageData();
						month.put("VALUETYPE","string");
						month.put("VALUE", (colIndex0 * 3 + i) + "月");
						month.put("COLSPAN", 3);
						month.put("ROWSPAN", 1);
						trList.add(month);
					}
					colIndex0++;
					break;
				case 1:
					col0.put("VALUE","检查日期");
					trList.add(col0);
					for (int i = 1; i <= 3; i++) {
						for (int j = 0; j < tendayList.length; j++) {
							PageData week = new PageData();
							week.put("VALUETYPE","string");
							week.put("VALUE", tendayList[j]);
							week.put("COLSPAN", 1);
							week.put("ROWSPAN", 1);
							trList.add(week);
						}
					}
					break;
				case 2:
					col0.put("VALUE","检查情况");
					col0.put("COLSPAN",1);
					col0.put("ROWSPAN",4);
					trList.add(col0);
					PageData col1 = new PageData();
					col1.put("VALUETYPE","string");
					col1.put("VALUE","是否检查");
					col1.put("COLSPAN",1);
					col1.put("ROWSPAN",1);
					trList.add(col1);
					for (int i = 1; i <= 3; i++) {
						for (int j = 0; j < tendayList.length; j++) {
							int month = colIndex2 * 3 + i;
							String curTendy = pd.getString("YEAR") + "-" + (month <= 9 ? "0"+month : month);
							String dateBegin = "", dateEnd = "";
							if (j == 0) {
								dateBegin = curTendy + "-01";
								dateEnd = curTendy + "-10";
							} else if (j == 1) {
								dateBegin = curTendy + "-11";
								dateEnd = curTendy + "-20";
							} else {
								dateBegin = curTendy + "-21";
								int lastDays = DateSysUtil.getMonthDays(Integer.parseInt(pd.getString("YEAR")),month-1);
								dateEnd = curTendy + "-" + lastDays;
							}

							PageData col = new PageData();
							col.put("VALUETYPE","string");
							col.put("COLSPAN", 1);
							col.put("ROWSPAN", 1);
							col.put("VALUE","△"); 	// 默认离岗
							//清单生成日期在遍历日期之后（未建立清单）
							if (DateSysUtil.fomatDate(listCreateDate).getTime()>DateSysUtil.fomatDate(dateEnd).getTime()) {
								col.put("VALUE","-");
							}else {
								for (PageData r : recordList) {
									if (DateSysUtil.fomatDate(dateBegin).getTime() <= DateSysUtil.fomatDate(r.getString("PERIODSTART").substring(0, 10)).getTime()
											&& DateSysUtil.fomatDate(r.getString("PERIODSTART").substring(0, 10)).getTime() <= DateSysUtil.fomatDate(dateEnd).getTime()) {
										if ("1".equals(r.getString("TYPE"))) {
											col.put("VALUE","√"); // 已检查（隐患数）
											break;
										} else if ("2".equals(r.getString("TYPE"))) {
											col.put("VALUE","×"); 	// 未排查
											break;
										}
									}
								}
							}
							trList.add(col);
						}
					}
					colIndex2++;
					break;
				case 3:
					col0.put("VALUE","发现隐患数");
					col0.put("COLSPAN",1);
					trList.add(col0);
					PageData col = new PageData();
					col.put("VALUETYPE","array");
					col.put("COLSPAN", 9);
					col.put("ROWSPAN", 1);
					for (int i = 1; i <= 3; i++) {
						for (int j = 0; j < tendayList.length; j++) {
							int month = colIndex3 * 3 + i;
							String curTendy = pd.getString("YEAR") + "-" + (month <= 9 ? "0"+month : month);
							String dateBegin = "", dateEnd = "";
							if (j == 0) {
								dateBegin = curTendy + "-01";
								dateEnd = curTendy + "-10";
							} else if (j == 1) {
								dateBegin = curTendy + "-11";
								dateEnd = curTendy + "-20";
							} else {
								dateBegin = curTendy + "-21";
								int lastDays = DateSysUtil.getMonthDays(Integer.parseInt(pd.getString("YEAR")),month-1);
								dateEnd = curTendy + "-" + lastDays;
							}

							PageData col2 = new PageData();
							col2.put("VALUETYPE","string");
							col2.put("COLSPAN", 1);
							col2.put("ROWSPAN", 1);
							col2.put("VALUE","0"); 	// 默认离岗
							//清单生成日期在遍历日期之后（未建立清单）
							if (DateSysUtil.fomatDate(listCreateDate).getTime()>DateSysUtil.fomatDate(dateEnd).getTime()) {
								col2.put("VALUE","0");
							}else {
								int hiddenCount = 0;
								for (PageData r : recordList) {
									if (DateSysUtil.fomatDate(dateBegin).getTime() <= DateSysUtil.fomatDate(r.getString("PERIODSTART").substring(0, 10)).getTime()
											&& DateSysUtil.fomatDate(r.getString("PERIODSTART").substring(0, 10)).getTime() <= DateSysUtil.fomatDate(dateEnd).getTime()) {
										if ("1".equals(r.getString("TYPE"))) {
											hiddenCount += Integer.parseInt(r.getString("HIDDEN_COUNT"));
//											col2.put("VALUE",r.getString("HIDDEN_COUNT")); // 已检查（隐患数）
										} else if ("2".equals(r.getString("TYPE"))) {
											hiddenCount = 0;
											break;
										}
									}
								}
								col2.put("VALUE",hiddenCount); 	// 未排查
							}
							trList.add(col2);
						}
					}
					colIndex3++;
					break;
				case 4:
					col0.put("VALUE","检查时间");
					col0.put("COLSPAN",1);
					trList.add(col0);
					col = new PageData();
					col.put("VALUETYPE","array");
					col.put("COLSPAN", 9);
					col.put("ROWSPAN", 1);
					for (int i = 1; i <= 3; i++) {
						for (int j = 0; j < tendayList.length; j++) {
							int month = colIndex4 * 3 + i;
							String curTendy = pd.getString("YEAR") + "-" + (month <= 9 ? "0"+month : month);
							String dateBegin = "", dateEnd = "";
							if (j == 0) {
								dateBegin = curTendy + "-01";
								dateEnd = curTendy + "-10";
							} else if (j == 1) {
								dateBegin = curTendy + "-11";
								dateEnd = curTendy + "-20";
							} else {
								dateBegin = curTendy + "-21";
								int lastDays = DateSysUtil.getMonthDays(Integer.parseInt(pd.getString("YEAR")),month-1);
								dateEnd = curTendy + "-" + lastDays;
							}

							PageData col2 = new PageData();
							col2.put("VALUETYPE","string");
							col2.put("COLSPAN", 1);
							col2.put("ROWSPAN", 1);
							col2.put("VALUE",""); 	// 默认离岗
							//清单生成日期在遍历日期之后（未建立清单）
							if (DateSysUtil.fomatDate(listCreateDate).getTime()>DateSysUtil.fomatDate(dateEnd).getTime()) {
								col2.put("VALUE","");
							}else {
								for (PageData r : recordList) {
									if (DateSysUtil.fomatDate(dateBegin).getTime() <= DateSysUtil.fomatDate(r.getString("PERIODSTART").substring(0, 10)).getTime()
											&& DateSysUtil.fomatDate(r.getString("PERIODSTART").substring(0, 10)).getTime() <= DateSysUtil.fomatDate(dateEnd).getTime()) {
										if ("1".equals(r.getString("TYPE"))) {
											col2.put("VALUE",r.getString("CREATTIME")); // 已检查（隐患数）
											break;
										} else if ("2".equals(r.getString("TYPE"))) {
											col2.put("VALUE",""); 	// 未排查
											break;
										}
									}
								}
							}
							trList.add(col2);
						}
					}
					colIndex4++;
					break;
				case 5:
					col0.put("VALUE","发现问题");
					col0.put("COLSPAN",1);
					trList.add(col0);
					PageData col02 = new PageData();
					for (int i = 1; i <= 3; i++) {
						col02 = new PageData();
						col02.put("VALUETYPE","array");
						col02.put("COLSPAN", 3);
						col02.put("ROWSPAN", 1);
						for (int j = 0; j < tendayList.length; j++) {
							List<String> descList = new ArrayList<>();

							int month = colIndex5 * 3 + i;
							String curTendy = pd.getString("YEAR") + "-" + (month <= 9 ? "0"+month : month);
							String dateBegin = "", dateEnd = "";
							if (j == 0) {
								dateBegin = curTendy + "-01";
								dateEnd = curTendy + "-10";
							} else if (j == 1) {
								dateBegin = curTendy + "-11";
								dateEnd = curTendy + "-20";
							} else {
								dateBegin = curTendy + "-21";
								int lastDays = DateSysUtil.getMonthDays(Integer.parseInt(pd.getString("YEAR")),month-1);
								dateEnd = curTendy + "-" + lastDays;
							}
							for (PageData r : recordList) {
								if (DateSysUtil.isSameMonth(r.getString("PERIODSTART"),dateBegin.substring(0,7))
										&& StringUtils.isNotBlank(r.getString("HIDDENDESCR")) ) {
									String[] hddescArr = r.getString("HIDDENDESCR").split("[$]");
									for (int k = 0; k < hddescArr.length; k++) {
										descList.add(hddescArr[k]);
									}
								}
							}
							col02.put("VALUE",descList);
						}
						trList.add(col02);
					}
					colIndex5++;
					break;
			}
			PageData tr = new PageData();
			tr.put("TRLIST", trList);
			list.add(tr);

			index++;
			if (index==6) { index = 0;}
		}
		return list;
	}
}

