package com.huatek.busi.service.impl.report;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Maps;
import com.huatek.busi.common.ReportType;
import com.huatek.busi.common.BusiConstant.WarningType;
import com.huatek.busi.common.SiteConstants.SiteTreeEnum;
import com.huatek.busi.common.util.DecimalUtil;
import com.huatek.busi.dto.EquipmentInfoDto;
import com.huatek.busi.mapper.report.BusiYspReportMapper;
import com.huatek.busi.service.BusiEqmWarningService;
import com.huatek.busi.service.BusiSubTreeService;
import com.huatek.busi.service.impl.report.helper.ReportImpl;
import com.huatek.busi.service.report.BusiCommonReportService;
import com.huatek.busi.service.threshold.TransformerOilThresholdService;
import com.huatek.busi.util.CalcUtil;
import com.huatek.busi.vo.TransformerOilThresholdVo;
import com.huatek.busi.vo.report.BusiYspMonitorDataVo;
import com.huatek.busi.vo.report.BusiYspReportVo;
import com.huatek.busi.vo.routinetest.transformer.InsulationOilTest;

import cn.hutool.core.collection.CollectionUtil;
import lombok.extern.slf4j.Slf4j;

/**
 * @ClassName: BusiYspDaliyReportServiceImpl
 * @FullClassPath: com.huatek.busi.service.impl.report.
 *                 BusiYspDaliyReportServiceImpl
 * @Description: 油色谱报告
 * @author: Arno
 * @date: Sep 23, 2019 2:30:13 PM
 * @version: 1.0
 */
@Slf4j
@ReportImpl(value = "busiYspReportService",
    exportTypes = {ReportType.YSP_DAILY_REPORT, ReportType.YSP_MONTHLY_REPORT})
public class BusiYspReportServiceImpl implements BusiCommonReportService {
	@Autowired
	private BusiYspReportMapper busiYspReportMapper;
	@Autowired
	private TransformerOilThresholdService transformerOilThresholdService;
    @Autowired
    private BusiSubTreeService busiSubTreeService;
    @Autowired
    private BusiEqmWarningService busiEqmWarningService;
    @Override
    public Map<String, Object> buildExportData(String exportType, List<String> sensors, String exportTime,String startTime, String endTime) {
        Map<String, Object> map = new HashMap<>();
        if (exportType.equals(ReportType.YSP_DAILY_REPORT)) {
            Map<String, Object> daliyReport = this.getDaliyReport(sensors, exportTime);
            map.put("fileName", "油色谱日报告");
            map.put("data", daliyReport);
        } else if (exportType.equals(ReportType.YSP_MONTHLY_REPORT)) {
            Map<String, Object> daliyReport = this.getMonthlyReport(sensors, exportTime,startTime,endTime);
            map.put("fileName", "油色谱月报告");
            map.put("data", daliyReport);
        }
        return map;
    }

	private Map<String, Object> getDaliyReport(List<String> sernsors, String exportTime) {
		Map<String, Object> map = new HashMap<String, Object>();
		String s2 = exportTime;

		String sernsorCode = sernsors.get(0);
		Map<String, Object> sensorInfo = this.getSensorInfo(sernsorCode);

		String mainTreeId = sensorInfo.get("mainTreeId").toString();
		String siteId = sensorInfo.get("siteId").toString();
		
		EquipmentInfoDto equipmentInfo = busiSubTreeService.findEquipmentInfo(sernsorCode, SiteTreeEnum.BYQ.getValue());
		Map<String, LocalDateTime> mapDate = CalcUtil.getcurrentMonthDateMap();
		Map<String, Object> param = Maps.newHashMap();
        param.put("mainTreeId", equipmentInfo.getMainTreeId());
        param.put("startTime", mapDate.get("startTime"));
		param.put("endTime", mapDate.get("endTime"));
        param.put("sensorCode", sernsorCode);
        BigDecimal totalCount = DecimalUtil.getVal(busiEqmWarningService.getBusiEqmWarningCount(param));
        param.put("warningType", WarningType.MISREPORT);
        BigDecimal wbCount = DecimalUtil.getVal(busiEqmWarningService.getBusiEqmWarningCount(param));//误报次数

		map.put("s1", ""); // 报告编号
		map.put("s2", LocalDate.now()); // 报告日期
		map.put("s3", "");// 离线检测日期
		map.put("s4", sensorInfo.get("installPosition") == null ? "" : sensorInfo.get("installPosition").toString()); // 安装位置
		map.put("s5", sensorInfo.get("useDate") == null ? "" : sensorInfo.get("useDate").toString()); // 投运日期
		map.put("s6", ""); // 数据缺失率
		map.put("s7", "");// 效验时间
		map.put("s8", sensorInfo.get("manufactor") == null ? "" : sensorInfo.get("manufactor").toString());// 设备生产厂家
		map.put("s9", "");// 检测频率
		map.put("s10", "");// 备注说明

		map.put("s11", totalCount);// 报警次数
		map.put("s12", wbCount);// 误报次数
		map.put("s13", "");// 色谱柱上次检修时间
		map.put("s14", "");// 传感器上次检修时间
		map.put("s15", "");//
		map.put("s16", "");// 报告评价
		map.put("s17", "");// 处理意见
		map.put("s18", "");// 报告人
		map.put("s19", "");// 签字
		map.put("s20", "");// 故障编码
		map.put("s21", "");// 故障判断结果

		String defectRate = this.getDefectRate(sernsorCode, exportTime);
		map.put("s6", defectRate); // 数据缺失率

		String frequency = this.getFrequency(siteId);
		map.put("s9", frequency);// 检测频率

//		Map<String, String> warningData = this.getWarningData(sernsorCode, exportTime);
//		map.put("s11", warningData.get("bjCount"));// 报警次数
//		map.put("s12", warningData.get("wbCount"));// 误报次数

		Map<String, Object> faultData = this.getFaultData(sernsorCode, exportTime);
		map.put("s20", faultData.get("code"));// 故障编码
		map.put("s21", faultData.get("msg"));// 故障判断结果

		List<BusiYspMonitorDataVo> caclist = this.getCacData(sernsorCode, exportTime);
		if(caclist.size()>0) {
			if(caclist.size()> 0) {
				BusiYspMonitorDataVo find = caclist.get(caclist.size()-1);
				String gasPress = find.getGasPress();
				if(StringUtils.isNoneBlank(gasPress)) {
					map.put("gasPress", gasPress.equals("1") ?"载气压力正常" :"载气压力异常");
				}
			}
		}else {
			map.put("gasPress", "--");
		}
		List<BusiYspMonitorDataVo> lxlist = this.getLxData(mainTreeId);
		if (CollectionUtils.isNotEmpty(lxlist)) {
			String time = lxlist.get(0).getTime();
			map.put("s3", time);// 离线检测日期
		}
		List<BusiYspReportVo> yspList = this.getSummaryData(sernsorCode, exportTime, caclist, lxlist);

		map.put("yspList", yspList);
		map.put("cacList", caclist);
		map.put("lxList", lxlist);
		map.put("r1", ""); // 报告评价说明

		return map;

	}

	/**
	 * @Title: getCacData
	 * @Description: CAC数据
	 * @createDate: Sep 26, 2019 2:51:00 PM
	 * @param
	 * @return List<BusiYspMonitorDataVo>
	 */
	public List<BusiYspMonitorDataVo> getCacData(String sernsorCode, String exportTime) {
		List<BusiYspMonitorDataVo> resultlist = new ArrayList<>();
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			Date startDate = format.parse(exportTime + " 00:00:00");
			Date endDate = format.parse(exportTime + " 23:59:59");
			List<BusiYspMonitorDataVo> list = busiYspReportMapper.getDaliyReportData(sernsorCode, startDate, endDate);
			if (CollectionUtil.isNotEmpty(list)) {
				for (int i = 0; i < list.size(); i++) {
					list.get(i).setIndex((i + 1) + "");
					resultlist.add(list.get(i));
				}
			}
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return resultlist;
	}

	/**
	 * @Title: getSensorInfo
	 * @Description: 传感器信息
	 * @createDate: Sep 26, 2019 2:51:20 PM
	 * @param
	 * @return Map<String,Object>
	 */
	public Map<String, Object> getSensorInfo(String sernsorCode) {
		return busiYspReportMapper.getSensorInfo(sernsorCode);
	}

	/**
	 * @Title: getLxData
	 * @Description: 离线数据
	 * @createDate: Sep 26, 2019 2:51:55 PM
	 * @param
	 * @return List<BusiYspMonitorDataVo>
	 */
	public List<BusiYspMonitorDataVo> getLxData(String mainTreeId) {
		List<Map<String, Object>> list = busiYspReportMapper.getOutlineData(mainTreeId);
		List<BusiYspMonitorDataVo> volist = new ArrayList<>();
		int index = 1;
		for (Map<String, Object> map : list) {
			if (null != map && !map.isEmpty()) {
				BusiYspMonitorDataVo vo = new BusiYspMonitorDataVo();
				String createTime = map.get("createTime").toString();
				vo.setTime(createTime);
				vo.setIndex(index + "");
				Object json = map.get("insulationOiltTest");
				if (null != json && !("".equals(json))) {
					InsulationOilTest bean = this.jsonToBean(json.toString(), InsulationOilTest.class);
					Map<String, Object> gasMap = bean.convert();
					this.buildBusiYspMonitorDataVo(vo, gasMap);
				}
				index++;
				volist.add(vo);
			}
		}
		return volist;
	}

	/**
	 * @Title: getFrequency
	 * @Description: 获取频率
	 * @createDate: Sep 26, 2019 2:52:05 PM
	 * @param
	 * @return String
	 */
	public String getFrequency(String siteId) {
		String yspUploadCycle = this.busiYspReportMapper.getYspUploadCycle(siteId);
		if (StringUtils.isNoneBlank(yspUploadCycle)) {
			Double value = 24d / Double.valueOf(yspUploadCycle);
			return value.intValue() + "";
		}
		return "";
	}

	public void buildBusiYspMonitorDataVo(BusiYspMonitorDataVo vo, Map<String, Object> gasMap) {
		vo.setH2(this.getGasValue("氢H2（uL/L)", gasMap));
		vo.setCh4(this.getGasValue("甲烷CH4（uL/L)", gasMap));
		vo.setCo(this.getGasValue("一氧化碳CO（uL/L)", gasMap));
		vo.setCo2(this.getGasValue("二氧化碳CO（uL/L)", gasMap));
		vo.setC2h2(this.getGasValue("乙炔（uL/L)", gasMap));
		vo.setC2h4(this.getGasValue("乙烯C2H4（uL/L)", gasMap));
		vo.setC2h6(this.getGasValue("乙烷C2H6（uL/L)", gasMap));
		vo.setH2o(this.getGasValue("H2O", gasMap));
		vo.setTmp(this.getGasValue("温度（℃)", gasMap));
		vo.setDew(this.getGasValue("湿度（%)", gasMap));
		vo.setMst(this.getGasValue("微水含量（uL/L)", gasMap));
		vo.setCmbuGas(this.getGasValue("总可燃气体（uL/L)", gasMap));
		vo.setZt(this.getGasValue("总烃含量（uL/L)", gasMap));
	}
	/**
	 * @Title: getWarningData
	 * @Description: 获取告警
	 * @createDate: Sep 25, 2019 5:35:30 PM
	 * @param
	 * @return Map<String,String>
	 */
	public Map<String, String> getWarningData(String sensorId, String exportTime) {
		Map<String, String> resultMap = new HashMap<>();
		resultMap.put("wbCount", "");
		resultMap.put("bjCount", "");
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			Date startDate = format.parse(exportTime + " 00:00:00");
			Date endDate = format.parse(exportTime + " 23:59:59");
			List<Map<String, Object>> list = busiYspReportMapper.getWarningData(sensorId, startDate, endDate);
			if (CollectionUtil.isNotEmpty(list)) {
				Integer count = 0;
				for (Map<String, Object> map : list) {
					if (map.get("warningType") != null && map.get("warningType").toString().equals("2")) {
						count += 1;
					}
				}
				resultMap.put("wbCount", count + "");
				resultMap.put("bjCount", list.size() + "");
			}
		} catch (ParseException e) {
			e.printStackTrace();
		}

		return resultMap;
	}

	/**
	 * @Title: getDefectRate
	 * @Description: 获取缺失率
	 * @createDate: Sep 25, 2019 5:44:29 PM
	 * @param
	 * @return String
	 */
	public String getDefectRate(String sensorId, String exportTime) {
		String lossRate = "";
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		try {
			Date dtime = format.parse(exportTime);
			String defectRate = busiYspReportMapper.getDefectRate(sensorId, dtime)==null?"0":busiYspReportMapper.getDefectRate(sensorId, dtime);
			DecimalFormat df = new DecimalFormat("0.00%");
			lossRate = df.format(Double.valueOf(defectRate));
		} catch (ParseException e) {
			e.printStackTrace();
		}

		return lossRate;
	}

	/**
	 * @Title: getFaultData
	 * @Description: 获取故障
	 * @createDate: Sep 26, 2019 6:00:57 PM
	 * @param
	 * @return Map<String,Object>
	 */
	public Map<String, Object> getFaultData(String sensorId, String exportTime) {
		Map<String, Object> resultMap = new HashMap<>();
		resultMap.put("code", "");
		resultMap.put("msg", "");
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date startDate;
		try {
			startDate = format.parse(exportTime + " 00:00:00");
			Date endDate = format.parse(exportTime + " 23:59:59");
			Map<String, String> map = busiYspReportMapper.getFaultData(sensorId, startDate, endDate);
			if (map != null && !map.isEmpty()) {
				resultMap.put("code", map.get("threeRatio") == null ? "" : map.get("threeRatio").toString());
				resultMap.put("msg", map.get("warningMsg") == null ? "" : map.get("warningMsg").toString());
			}

		} catch (ParseException e) {
			e.printStackTrace();
		}
		return resultMap;
	}

	public List<BusiYspReportVo> getSummaryData(String sensorId, String exportTime, List<BusiYspMonitorDataVo> caclist,
			List<BusiYspMonitorDataVo> lxlist) {
		List<BusiYspReportVo> list = new ArrayList<BusiYspReportVo>();
		BusiYspReportVo y1 = new BusiYspReportVo("H2");
		BusiYspReportVo y2 = new BusiYspReportVo("CO");
		BusiYspReportVo y3 = new BusiYspReportVo("CO2");
		BusiYspReportVo y4 = new BusiYspReportVo("CH4");
		BusiYspReportVo y5 = new BusiYspReportVo("C2H4");
		BusiYspReportVo y6 = new BusiYspReportVo("C2H6");
		BusiYspReportVo y7 = new BusiYspReportVo("C2H2");
		BusiYspReportVo y8 = new BusiYspReportVo("O2");
		BusiYspReportVo y9 = new BusiYspReportVo("N2");
		BusiYspReportVo y10 = new BusiYspReportVo("H2O");
		BusiYspReportVo y11 = new BusiYspReportVo("总烃");
		BusiYspReportVo y12 = new BusiYspReportVo("温度");
		BusiYspReportVo y13 = new BusiYspReportVo("湿度");
		BusiYspReportVo y14 = new BusiYspReportVo("微水");
		BusiYspReportVo y15 = new BusiYspReportVo("总可燃气体");

		TransformerOilThresholdVo thresholdVo = this.getTransformerOilThreshold(sensorId);
		if (null != thresholdVo) {
			y1.setWarning(thresholdVo.getH2Threshold()==null ? "--" :thresholdVo.getH2Threshold());
			y2.setWarning(thresholdVo.getCoThreshold()==null ? "--" :thresholdVo.getCoThreshold());
			y3.setWarning(thresholdVo.getCo2Threshold()==null ? "--" :thresholdVo.getCo2Threshold());
			y4.setWarning(thresholdVo.getCh4Threshold()==null ? "--" :thresholdVo.getCh4Threshold());
			y5.setWarning(thresholdVo.getC2h4Threshold()==null ? "--" :thresholdVo.getC2h4Threshold());
			y6.setWarning(thresholdVo.getC2h6Threshold()==null ? "--" :thresholdVo.getC2h6Threshold());
			y7.setWarning(thresholdVo.getC2h2Threshold()==null ? "--" :thresholdVo.getC2h2Threshold());
			y8.setWarning(thresholdVo.getO2Threshold()==null ? "--" :thresholdVo.getO2Threshold());
			y9.setWarning(thresholdVo.getN2Threshold()==null ? "--" :thresholdVo.getN2Threshold());
			y10.setWarning(thresholdVo.getH2oThreshold()==null ? "--" :thresholdVo.getH2oThreshold());
			y11.setWarning(thresholdVo.getTotalHydrocarbonThreshold()==null ? "--" :thresholdVo.getTotalHydrocarbonThreshold());
			y12.setWarning(thresholdVo.getTmpThreshold()==null ? "--" :thresholdVo.getTmpThreshold());
			y13.setWarning(thresholdVo.getDewThreshold()==null ? "--" :thresholdVo.getDewThreshold());
			y14.setWarning(thresholdVo.getMstThreshold()==null ? "--" :thresholdVo.getMstThreshold());
			y15.setWarning(thresholdVo.getCmbuGasThreshold()==null ? "--" :thresholdVo.getCmbuGasThreshold());

			y1.setAccuracy(thresholdVo.getH2Accuracy()==null ? "--" :thresholdVo.getH2Accuracy());
			y2.setAccuracy(thresholdVo.getCoAccuracy()==null ? "--" :thresholdVo.getCoAccuracy());
			y3.setAccuracy(thresholdVo.getCo2Accuracy()==null ? "--" :thresholdVo.getCo2Accuracy());
			y4.setAccuracy(thresholdVo.getCh4Accuracy()==null ? "--" :thresholdVo.getCh4Accuracy());
			y5.setAccuracy(thresholdVo.getC2h4Accuracy()==null ? "--" :thresholdVo.getC2h4Accuracy());
			y6.setAccuracy(thresholdVo.getC2h6Accuracy()==null ? "--" :thresholdVo.getC2h6Accuracy());
			y7.setAccuracy(thresholdVo.getC2h2Accuracy()==null ? "--" :thresholdVo.getC2h2Accuracy());
			y8.setAccuracy(thresholdVo.getO2Accuracy()==null ? "--" :thresholdVo.getO2Accuracy());
			y9.setAccuracy(thresholdVo.getN2Accuracy()==null ? "--" :thresholdVo.getN2Accuracy());
			y10.setAccuracy(thresholdVo.getH2oAccuracy()==null ? "--" :thresholdVo.getH2oAccuracy());
			y11.setAccuracy(thresholdVo.getTotalHydrocarbonAccuracy()==null ? "--" :thresholdVo.getTotalHydrocarbonAccuracy());
			y12.setAccuracy(thresholdVo.getTmpAccuracy()==null ? "--" :thresholdVo.getTmpAccuracy());
			y13.setAccuracy(thresholdVo.getDewAccuracy()==null ? "--" :thresholdVo.getDewAccuracy());
			y14.setAccuracy(thresholdVo.getMstAccuracy()==null ? "--" :thresholdVo.getMstAccuracy());
			y15.setAccuracy(thresholdVo.getCmbuGasAccuracy()==null ? "--" :thresholdVo.getCmbuGasAccuracy());
		}

		if (!caclist.isEmpty()) {
			BusiYspMonitorDataVo busiYspMonitorDataVo = caclist.get(caclist.size() - 1);
			y1.setReal(busiYspMonitorDataVo.getH2()==null ? "--" :busiYspMonitorDataVo.getH2());
			y2.setReal(busiYspMonitorDataVo.getCo()==null ? "--" :busiYspMonitorDataVo.getCo());
			y3.setReal(busiYspMonitorDataVo.getCo2()==null ? "--" :busiYspMonitorDataVo.getCo2());
			y4.setReal(busiYspMonitorDataVo.getCh4()==null ? "--" :busiYspMonitorDataVo.getCh4());
			y5.setReal(busiYspMonitorDataVo.getC2h4()==null ? "--" :busiYspMonitorDataVo.getC2h4());
			y6.setReal(busiYspMonitorDataVo.getC2h6()==null ? "--" :busiYspMonitorDataVo.getC2h6());
			y7.setReal(busiYspMonitorDataVo.getC2h2()==null ? "--" :busiYspMonitorDataVo.getC2h2());
			y8.setReal("--");
			y9.setReal("--");
			y10.setReal(busiYspMonitorDataVo.getH2o()==null ? "--" :busiYspMonitorDataVo.getH2o());
			y11.setReal(busiYspMonitorDataVo.getZt()==null ? "--" :busiYspMonitorDataVo.getZt());
			y12.setReal(busiYspMonitorDataVo.getTmp()==null ? "--" :busiYspMonitorDataVo.getTmp());
			y13.setReal(busiYspMonitorDataVo.getDew()==null ? "--" :busiYspMonitorDataVo.getDew());
			y14.setReal(busiYspMonitorDataVo.getMst()==null ? "--" :busiYspMonitorDataVo.getMst());
			y15.setReal(busiYspMonitorDataVo.getCmbuGas()==null ? "--" :busiYspMonitorDataVo.getCmbuGas());
		}
		if (!lxlist.isEmpty()) {
			BusiYspMonitorDataVo busiYspMonitorDataVo = lxlist.get(0);
			y1.setOutline(busiYspMonitorDataVo.getH2()==null ? "--":busiYspMonitorDataVo.getH2());
			y2.setOutline(busiYspMonitorDataVo.getCo()==null ? "--":busiYspMonitorDataVo.getCo());
			y3.setOutline(busiYspMonitorDataVo.getCo2()==null ? "--":busiYspMonitorDataVo.getCo2());
			y4.setOutline(busiYspMonitorDataVo.getCh4()==null ? "--":busiYspMonitorDataVo.getCh4());
			y5.setOutline(busiYspMonitorDataVo.getC2h4()==null ? "--":busiYspMonitorDataVo.getC2h4());
			y6.setOutline(busiYspMonitorDataVo.getC2h6()==null ? "--":busiYspMonitorDataVo.getC2h6());
			y7.setOutline(busiYspMonitorDataVo.getC2h2()==null ? "--":busiYspMonitorDataVo.getC2h2());
			y8.setOutline("--");
			y9.setOutline("--");
			y10.setOutline(busiYspMonitorDataVo.getH2o()==null ? "--":busiYspMonitorDataVo.getH2o());
			y11.setOutline(busiYspMonitorDataVo.getZt()==null ? "--":busiYspMonitorDataVo.getZt());
			y12.setOutline(busiYspMonitorDataVo.getTmp()==null ? "--":busiYspMonitorDataVo.getTmp());
			y13.setOutline(busiYspMonitorDataVo.getDew()==null ? "--" :busiYspMonitorDataVo.getDew());
			y14.setOutline(busiYspMonitorDataVo.getMst()==null ? "--" :busiYspMonitorDataVo.getMst());
			y15.setOutline(busiYspMonitorDataVo.getCmbuGas()==null ? "--" :busiYspMonitorDataVo.getCmbuGas());
		}
		// 绝对产气速率
		Map<String, Object> absoluteMap = this.getAbsoluteGasProductionRate(sensorId, exportTime);
		if (null != absoluteMap) {
			y1.setGrowth(this.getGasValue("h2", absoluteMap) == null ?"--":this.getGasValue("h2", absoluteMap));
			y2.setGrowth(this.getGasValue("co", absoluteMap) == null ?"--":this.getGasValue("co", absoluteMap));
			y3.setGrowth(this.getGasValue("co2", absoluteMap) == null ?"--":this.getGasValue("co2", absoluteMap));
			y4.setGrowth(this.getGasValue("ch4", absoluteMap) == null ?"--":this.getGasValue("ch4", absoluteMap));
			y5.setGrowth(this.getGasValue("c2h4", absoluteMap) == null ?"--":this.getGasValue("c2h4", absoluteMap));
			y6.setGrowth(this.getGasValue("c2h6", absoluteMap) == null ?"--":this.getGasValue("c2h6", absoluteMap));
			y7.setGrowth(this.getGasValue("c2h2", absoluteMap) == null ?"--":this.getGasValue("c2h2", absoluteMap));
			y8.setGrowth(this.getGasValue("o2", absoluteMap) == null ?"--":this.getGasValue("o2", absoluteMap));
			y9.setGrowth(this.getGasValue("n2", absoluteMap) == null ?"--":this.getGasValue("n2", absoluteMap));
			y10.setGrowth(this.getGasValue("h2o", absoluteMap) == null ?"--":this.getGasValue("h2o", absoluteMap));
			y11.setGrowth(this.getGasValue("zt", absoluteMap) == null ?"--":this.getGasValue("zt", absoluteMap));
			y12.setGrowth(this.getGasValue("tmp", absoluteMap) == null ?"--":this.getGasValue("tmp", absoluteMap));
			y13.setGrowth(this.getGasValue("dew", absoluteMap) == null ?"--":this.getGasValue("dew", absoluteMap));
			y14.setGrowth(this.getGasValue("mst", absoluteMap) == null ?"--":this.getGasValue("mst", absoluteMap));
			y15.setGrowth(this.getGasValue("cmbuGas", absoluteMap) == null ?"--":this.getGasValue("cmbuGas", absoluteMap));
		}

		list.add(y1);
		list.add(y2);
		list.add(y3);
		list.add(y4);
		list.add(y5);
		list.add(y6);
		list.add(y7);
		list.add(y8);
		list.add(y9);
		list.add(y10);
		list.add(y11);
		list.add(y12);
		list.add(y13);
		list.add(y14);
		list.add(y15);

		return list;
	}

	/**
	 * @Title: getAbsoluteGasProductionRate
	 * @Description: TODO
	 * @createDate: Sep 26, 2019 3:35:34 PM
	 * @param
	 * @return Map<String,Object>
	 */
	public Map<String, Object> getAbsoluteGasProductionRate(String sensorId, String exportTime) {
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		Date dtime = null;
		try {
			dtime = format.parse(exportTime);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return busiYspReportMapper.getAbsoluteGasProductionRate(sensorId, dtime);
	}

	public TransformerOilThresholdVo getTransformerOilThreshold(String sensorId) {
		TransformerOilThresholdVo thresholdVo = transformerOilThresholdService.getBySensorCode(sensorId);
		return thresholdVo;
	}

	public <T> T jsonToBean(String json, Class<T> classes) {
		return JSONObject.parseObject(json, classes);
	}

	public String getGasValue(String key, Map<String, Object> map) {
		String value = "" ;
		if (map != null &&  !map.isEmpty()) {
			if (map.containsKey(key)) {
				value = map.get(key) == null ? "" : map.get(key).toString();
			} else if (map.containsKey(key.toLowerCase())) {
				value = map.get(key.toLowerCase()) == null ? "" : map.get(key.toLowerCase()).toString();
			}
		}
		return value;
	}

	/********************************************************** 月报告 ************************************************************/
	private Map<String, Object> getMonthlyReport(List<String> sernsors, String exportTime,String startTime,String endTime) {
		Map<String, Object> map = new HashMap<String, Object>();
		
		String sernsorCode = sernsors.get(0);
		Map<String, Object> sensorInfo = this.getSensorInfo(sernsorCode);

		String mainTreeId = sensorInfo.get("mainTreeId").toString();
		String siteId = sensorInfo.get("siteId").toString();

		map.put("s1", ""); // 报告编号
		map.put("s2", LocalDate.now()); // 报告日期
		map.put("s3", "");// 离线检测日期
		map.put("s4", sensorInfo.get("installPosition") == null ? "" : sensorInfo.get("installPosition").toString()); // 安装位置
		map.put("s5", sensorInfo.get("useDate") == null ? "" : sensorInfo.get("useDate").toString()); // 投运日期
		map.put("s6", ""); // 数据缺失率
		map.put("s7", "");// 效验时间
		map.put("s8", sensorInfo.get("manufactor") == null ? "" : sensorInfo.get("manufactor").toString());// 设备生产厂家
		map.put("s9", "");// 检测频率
		map.put("s10", "");// 备注说明

		map.put("s11", "");// 报警次数
		map.put("s12", "");// 误报次数
		map.put("s13", "");// 色谱柱上次检修时间
		map.put("s14", "");// 传感器上次检修时间
		map.put("s15", "");//
		map.put("s16", "");// 报告评价
		map.put("s17", "");// 处理意见
		map.put("s18", "");// 报告人
		map.put("s19", "");// 签字
		map.put("s20", "");// 故障编码
		map.put("s21", "");// 故障判断结果

		if(startTime != null && !"".equals(endTime))
    	{
	        startTime = startTime + " 00:00:00";
	        endTime = endTime+ " 23:59:59";
    	}
    	else
    	{
    		startTime = LocalDate.now()+" 00:00:00";
			endTime =  LocalDate.now().plusDays(1)+" 00:00:00";
    	}
		
	    String start = CalcUtil.currentMonthFirstDate().toString();
	    String end = LocalDate.now().plusDays(1).toString();
		
	    String defectRate = this.getDefectRates(sernsorCode,start,end);
		map.put("s6", defectRate); // 数据缺失率

		String frequency = this.getFrequency(siteId);
		map.put("s9", frequency);// 检测频率

		Map<String, String> warningData = this.getWarningDatas(sernsorCode,start,end);
		map.put("s11", warningData.get("bjCount"));// 报警次数
		map.put("s12", warningData.get("wbCount"));// 误报次数

		Map<String, Object> faultData = this.getFaultDatas(sernsorCode, startTime,endTime);
		map.put("s20", faultData.get("code"));// 故障编码
		map.put("s21", faultData.get("msg"));// 故障判断结果

		List<BusiYspMonitorDataVo> caclist = this.getCacDatas(sernsorCode, startTime,endTime);
		if(caclist.size()> 0) {
			BusiYspMonitorDataVo find = caclist.get(caclist.size()-1);
			String gasPress = find.getGasPress();
			if(StringUtils.isNoneBlank(gasPress)) {
				map.put("gasPress", gasPress.equals("1") ?"载气压力正常" :"载气压力异常");
			}else {
				map.put("gasPress", "--");
			}
		}else {
			map.put("gasPress", "--");
		}
		List<BusiYspMonitorDataVo> lxlist = this.getLxData(mainTreeId);
		if (CollectionUtils.isNotEmpty(lxlist)) {
			String time = lxlist.get(0).getTime();
			map.put("s3", time);// 离线检测日期
		}
		List<BusiYspReportVo> yspList = this.getSummaryData2(sernsorCode, exportTime, caclist, lxlist,startTime,endTime);

		map.put("yspList", yspList);
		map.put("cacList", caclist);
		map.put("lxList", lxlist);
		map.put("r1", ""); // 报告评价说明

		return map;
	}

	/**
	 * @Title: getDefectRates
	 * @Description: 获取缺失率
	 * @createDate: Sep 25, 2019 5:44:29 PM
	 * @param
	 * @return String
	 */
	public String getDefectRates(String sensorId,String startTime,String endTime) {
		String lossRate = "";
//		Calendar c = Calendar.getInstance();
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		
		try {
//			Map<String, LocalDateTime> mapDate = CalcUtil.getcurrentMonthDateMap();
			Date startDate = format.parse(startTime);
			Date endDate = format.parse(endTime);
			String defectRate = busiYspReportMapper.getDefectRates(sensorId, startDate, endDate)==null?"0":busiYspReportMapper.getDefectRates(sensorId, startDate, endDate);
			lossRate = defectRate + "%";
//			DecimalFormat df = new DecimalFormat("0.00%");
//			lossRate = df.format(Double.valueOf(defectRate));
			log.info("--> 油色谱[{}]月缺失率[{}]",  lossRate);
		
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		

		return lossRate;
	}

	/**
	 * @Title: getWarningDatas
	 * @Description: 获取告警
	 * @createDate: Sep 25, 2019 5:35:30 PM
	 * @param
	 * @return Map<String,String>
	 */
	public Map<String, String> getWarningDatas(String sensorId,String startTime,String endTime) {
		Map<String, String> resultMap = new HashMap<>();
		resultMap.put("wbCount", "");
		resultMap.put("bjCount", "");
//		Calendar c = Calendar.getInstance();
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		try {
//			Date dtime = format.parse(exportTime);
//			c.setTime(dtime);
//			int month = c.get(Calendar.MONTH) + 1;
//			String start = getFirstDayOfMonth(month);
//			String end = getLastDayOfMonth(month);
			Date startDate = format.parse(startTime);
			Date endDate = format.parse(endTime);
			
//			Map<String, LocalDateTime> mapDate = CalcUtil.getcurrentMonthDateMap();
//			Date startDate = Date.from(mapDate.get("startTime").atZone(ZoneId.systemDefault()).toInstant());
//			Date endDate = Date.from(mapDate.get("endTime").atZone(ZoneId.systemDefault()).toInstant());
			
			List<Map<String, Object>> list = busiYspReportMapper.getWarningData(sensorId, startDate, endDate);
			if (CollectionUtil.isNotEmpty(list)) {
				Integer count = 0;
				for (Map<String, Object> map : list) {
				    if(map != null)
				    {
    					if (map.get("warningType") != null && map.get("warningType").toString().equals("2")) {
    						count += 1;
    					}
				    }else
				    {
				        continue;
				    }
				}
				resultMap.put("wbCount", count + "");
				resultMap.put("bjCount", list.size() + "");
				log.info("--> 油色谱[{}]告警次数[{}]，误报次数[{}]",  list.size(), count);
			}
		} catch (ParseException e) {
			e.printStackTrace();
		}

		return resultMap;
	}

	/**
	 * @Title: getFaultDatas
	 * @Description: 获取故障
	 * @createDate: Sep 26, 2019 6:00:57 PM
	 * @param
	 * @return Map<String,Object>
	 */
	public Map<String, Object> getFaultDatas(String sensorId,String startTime,String endTime) {
		Map<String, Object> resultMap = new HashMap<>();
		resultMap.put("code", "");
		resultMap.put("msg", "");
//		Calendar c = Calendar.getInstance();
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		try {
//			Date dtime = format.parse(exportTime);
//			c.setTime(dtime);
//			int month = c.get(Calendar.MONTH) + 1;
//			String start = getFirstDayOfMonth(month);
//			String end = getFirstDayOfMonth(month);
			Date startDate = format.parse(startTime);
			Date endDate = format.parse(endTime);
			
//			Map<String, LocalDateTime> mapDate = CalcUtil.getcurrentMonthDateMap();
//			Date startDate = Date.from(mapDate.get("startTime").atZone(ZoneId.systemDefault()).toInstant());
//			Date endDate = Date.from(mapDate.get("endTime").atZone(ZoneId.systemDefault()).toInstant());
			
			
			Map<String, String> map = busiYspReportMapper.getFaultData(sensorId, startDate, endDate);
			if (map != null && !map.isEmpty()) {
				Object value = map.get("threeRatio") == null ? "" : map.get("threeRatio").toString();
				resultMap.put("code", value);
				Object value2 = map.get("warningMsg") == null ? "" : map.get("warningMsg").toString();
				resultMap.put("msg", value2);
				log.info("--> 油色谱[{}]月， 三比值编码[{}]，故障判断结果[{}]", value, value2);
			}

		} catch (ParseException e) {
			e.printStackTrace();
		}
		return resultMap;
	}

	/**
	 * @Title: getCacData
	 * @Description: CAC数据
	 * @createDate: Sep 26, 2019 2:51:00 PM
	 * @param
	 * @return List<BusiYspMonitorDataVo>
	 */
	public List<BusiYspMonitorDataVo> getCacDatas(String sernsorCode,String startTime,String endTime) {
		List<BusiYspMonitorDataVo> resultlist = new ArrayList<>();
//		Calendar c = Calendar.getInstance();
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		try {
//			Date dtime = format.parse(exportTime);
//			c.setTime(dtime);
//			int month = c.get(Calendar.MONTH) + 1;
//			String start = getFirstDayOfMonth(month);
//			String end = getLastDayOfMonth(month);
			Date startDate = format.parse(startTime);
			Date endDate = format.parse(endTime);
			List<BusiYspMonitorDataVo> list = busiYspReportMapper.getDaliyReportData(sernsorCode, startDate, endDate);
			if (CollectionUtil.isNotEmpty(list)) {
				for (int i = 0; i < list.size(); i++) {
					list.get(i).setIndex((i + 1) + "");
					if(list.get(i) != null)
					{
					    resultlist.add(list.get(i));
					}
				}
			}
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return resultlist;
	}

	public List<BusiYspReportVo> getSummaryData2(String sensorId, String exportTime, List<BusiYspMonitorDataVo> caclist,
			List<BusiYspMonitorDataVo> lxlist,String start,String end) {
//		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
//		Date startDate=null;
//		Date endDate=null;
//		try {
//			 startDate = format.parse(start);
//			 endDate = format.parse(end);
//		} catch (ParseException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
	
		List<BusiYspReportVo> list = new ArrayList<BusiYspReportVo>();
		BusiYspReportVo y1 = new BusiYspReportVo("H2");
		BusiYspReportVo y2 = new BusiYspReportVo("CO");
		BusiYspReportVo y3 = new BusiYspReportVo("CO2");
		BusiYspReportVo y4 = new BusiYspReportVo("CH4");
		BusiYspReportVo y5 = new BusiYspReportVo("C2H4");
		BusiYspReportVo y6 = new BusiYspReportVo("C2H6");
		BusiYspReportVo y7 = new BusiYspReportVo("C2H2");
		BusiYspReportVo y8 = new BusiYspReportVo("O2");
		BusiYspReportVo y9 = new BusiYspReportVo("N2");
		BusiYspReportVo y10 = new BusiYspReportVo("H20");
		BusiYspReportVo y11 = new BusiYspReportVo("总烃");
		BusiYspReportVo y12 = new BusiYspReportVo("温度");
		BusiYspReportVo y13 = new BusiYspReportVo("湿度");
		BusiYspReportVo y14 = new BusiYspReportVo("微水");
		BusiYspReportVo y15 = new BusiYspReportVo("总可燃气体");

		TransformerOilThresholdVo thresholdVo = this.getTransformerOilThreshold(sensorId);
		if (null != thresholdVo) {
			y1.setWarning(thresholdVo.getH2Threshold()==null ? "--" :thresholdVo.getH2Threshold());
			y2.setWarning(thresholdVo.getCoThreshold()==null ? "--" :thresholdVo.getCoThreshold());
			y3.setWarning(thresholdVo.getCo2Threshold()==null ? "--" :thresholdVo.getCo2Threshold());
			y4.setWarning(thresholdVo.getCh4Threshold()==null ? "--" :thresholdVo.getCh4Threshold());
			y5.setWarning(thresholdVo.getC2h4Threshold()==null ? "--" :thresholdVo.getC2h4Threshold());
			y6.setWarning(thresholdVo.getC2h6Threshold()==null ? "--" :thresholdVo.getC2h6Threshold());
			y7.setWarning(thresholdVo.getC2h2Threshold()==null ? "--" :thresholdVo.getC2h2Threshold());
			y8.setWarning(thresholdVo.getO2Threshold()==null ? "--" :thresholdVo.getO2Threshold());
			y9.setWarning(thresholdVo.getN2Threshold()==null ? "--" :thresholdVo.getN2Threshold());
			y10.setWarning(thresholdVo.getH2oThreshold()==null ? "--" :thresholdVo.getH2oThreshold());
			y11.setWarning(thresholdVo.getTotalHydrocarbonThreshold()==null ? "--" :thresholdVo.getTotalHydrocarbonThreshold());
			y12.setWarning(thresholdVo.getTmpThreshold()==null ? "--" :thresholdVo.getTmpThreshold());
			y13.setWarning(thresholdVo.getDewThreshold()==null ? "--" :thresholdVo.getDewThreshold());
			y14.setWarning(thresholdVo.getMstThreshold()==null ? "--" :thresholdVo.getMstThreshold());
			y15.setWarning(thresholdVo.getCmbuGasThreshold()==null ? "--" :thresholdVo.getCmbuGasThreshold());

			y1.setAccuracy(thresholdVo.getH2Accuracy()==null ? "--" :thresholdVo.getH2Accuracy());
			y2.setAccuracy(thresholdVo.getCoAccuracy()==null ? "--" :thresholdVo.getCoAccuracy());
			y3.setAccuracy(thresholdVo.getCo2Accuracy()==null ? "--" :thresholdVo.getCo2Accuracy());
			y4.setAccuracy(thresholdVo.getCh4Accuracy()==null ? "--" :thresholdVo.getCh4Accuracy());
			y5.setAccuracy(thresholdVo.getC2h4Accuracy()==null ? "--" :thresholdVo.getC2h4Accuracy());
			y6.setAccuracy(thresholdVo.getC2h6Accuracy()==null ? "--" :thresholdVo.getC2h6Accuracy());
			y7.setAccuracy(thresholdVo.getC2h2Accuracy()==null ? "--" :thresholdVo.getC2h2Accuracy());
			y8.setAccuracy(thresholdVo.getO2Accuracy()==null ? "--" :thresholdVo.getO2Accuracy());
			y9.setAccuracy(thresholdVo.getN2Accuracy()==null ? "--" :thresholdVo.getN2Accuracy());
			y10.setAccuracy(thresholdVo.getH2oAccuracy()==null ? "--" :thresholdVo.getH2oAccuracy());
			y11.setAccuracy(thresholdVo.getTotalHydrocarbonAccuracy()==null ? "--" :thresholdVo.getTotalHydrocarbonAccuracy());
			y12.setAccuracy(thresholdVo.getTmpAccuracy()==null ? "--" :thresholdVo.getTmpAccuracy());
			y13.setAccuracy(thresholdVo.getDewAccuracy()==null ? "--" :thresholdVo.getDewAccuracy());
			y14.setAccuracy(thresholdVo.getMstAccuracy()==null ? "--" :thresholdVo.getMstAccuracy());
			y15.setAccuracy(thresholdVo.getCmbuGasAccuracy()==null ? "--" :thresholdVo.getCmbuGasAccuracy());
		}

		if (!caclist.isEmpty()) {
			BusiYspMonitorDataVo busiYspMonitorDataVo = caclist.get(caclist.size() - 1);
			y1.setReal(busiYspMonitorDataVo.getH2()==null ? "--" :busiYspMonitorDataVo.getH2());
			y2.setReal(busiYspMonitorDataVo.getCo()==null ? "--" :busiYspMonitorDataVo.getCo());
			y3.setReal(busiYspMonitorDataVo.getCo2()==null ? "--" :busiYspMonitorDataVo.getCo2());
			y4.setReal(busiYspMonitorDataVo.getCh4()==null ? "--" :busiYspMonitorDataVo.getCh4());
			y5.setReal(busiYspMonitorDataVo.getC2h4()==null ? "--" :busiYspMonitorDataVo.getC2h4());
			y6.setReal(busiYspMonitorDataVo.getC2h6()==null ? "--" :busiYspMonitorDataVo.getC2h6());
			y7.setReal(busiYspMonitorDataVo.getC2h2()==null ? "--" :busiYspMonitorDataVo.getC2h2());
			y8.setReal("--");
			y9.setReal("--");
			y10.setReal(busiYspMonitorDataVo.getH2o()==null ? "--" :busiYspMonitorDataVo.getH2o());
			y11.setReal(busiYspMonitorDataVo.getZt()==null ? "--" :busiYspMonitorDataVo.getZt());
			y12.setReal(busiYspMonitorDataVo.getTmp()==null ? "--" :busiYspMonitorDataVo.getTmp());
			y13.setReal(busiYspMonitorDataVo.getDew()==null ? "--" :busiYspMonitorDataVo.getDew());
			y14.setReal(busiYspMonitorDataVo.getMst()==null ? "--" :busiYspMonitorDataVo.getMst());
			y15.setReal(busiYspMonitorDataVo.getCmbuGas()==null ? "--" :busiYspMonitorDataVo.getCmbuGas());
		}
		if (!lxlist.isEmpty()) {
			BusiYspMonitorDataVo busiYspMonitorDataVo = lxlist.get(0);
			y1.setOutline(busiYspMonitorDataVo.getH2()==null ? "--":busiYspMonitorDataVo.getH2());
			y2.setOutline(busiYspMonitorDataVo.getCo()==null ? "--":busiYspMonitorDataVo.getCo());
			y3.setOutline(busiYspMonitorDataVo.getCo2()==null ? "--":busiYspMonitorDataVo.getCo2());
			y4.setOutline(busiYspMonitorDataVo.getCh4()==null ? "--":busiYspMonitorDataVo.getCh4());
			y5.setOutline(busiYspMonitorDataVo.getC2h4()==null ? "--":busiYspMonitorDataVo.getC2h4());
			y6.setOutline(busiYspMonitorDataVo.getC2h6()==null ? "--":busiYspMonitorDataVo.getC2h6());
			y7.setOutline(busiYspMonitorDataVo.getC2h2()==null ? "--":busiYspMonitorDataVo.getC2h2());
			y8.setOutline("--");
			y9.setOutline("--");
			y10.setOutline(busiYspMonitorDataVo.getH2o()==null ? "--":busiYspMonitorDataVo.getH2o());
			y11.setOutline(busiYspMonitorDataVo.getZt()==null ? "--":busiYspMonitorDataVo.getZt());
			y12.setOutline(busiYspMonitorDataVo.getTmp()==null ? "--":busiYspMonitorDataVo.getTmp());
			y13.setOutline(busiYspMonitorDataVo.getDew()==null ? "--" :busiYspMonitorDataVo.getDew());
			y14.setOutline(busiYspMonitorDataVo.getMst()==null ? "--" :busiYspMonitorDataVo.getMst());
			y15.setOutline(busiYspMonitorDataVo.getCmbuGas()==null ? "--" :busiYspMonitorDataVo.getCmbuGas());
		}

		// 相对产气速率
		Map<String, Object> absoluteMap = this.getRelativeGasProductionRate(sensorId, start,end);
		if (null != absoluteMap) {
			y1.setGrowth(this.getGasValue("h2", absoluteMap) == null ?"--":this.getGasValue("h2", absoluteMap));
			y2.setGrowth(this.getGasValue("co", absoluteMap) == null ?"--":this.getGasValue("co", absoluteMap));
			y3.setGrowth(this.getGasValue("co2", absoluteMap) == null ?"--":this.getGasValue("co2", absoluteMap));
			y4.setGrowth(this.getGasValue("ch4", absoluteMap) == null ?"--":this.getGasValue("ch4", absoluteMap));
			y5.setGrowth(this.getGasValue("c2h4", absoluteMap) == null ?"--":this.getGasValue("c2h4", absoluteMap));
			y6.setGrowth(this.getGasValue("c2h6", absoluteMap) == null ?"--":this.getGasValue("c2h6", absoluteMap));
			y7.setGrowth(this.getGasValue("c2h2", absoluteMap) == null ?"--":this.getGasValue("c2h2", absoluteMap));
			y8.setGrowth(this.getGasValue("o2", absoluteMap) == null ?"--":this.getGasValue("o2", absoluteMap));
			y9.setGrowth(this.getGasValue("n2", absoluteMap) == null ?"--":this.getGasValue("n2", absoluteMap));
			y10.setGrowth(this.getGasValue("h2o", absoluteMap) == null ?"--":this.getGasValue("h2o", absoluteMap));
			y11.setGrowth(this.getGasValue("zt", absoluteMap) == null ?"--":this.getGasValue("zt", absoluteMap));
			y12.setGrowth(this.getGasValue("tmp", absoluteMap) == null ?"--":this.getGasValue("tmp", absoluteMap));
			y13.setGrowth(this.getGasValue("dew", absoluteMap) == null ?"--":this.getGasValue("dew", absoluteMap));
			y14.setGrowth(this.getGasValue("mst", absoluteMap) == null ?"--":this.getGasValue("mst", absoluteMap));
			y15.setGrowth(this.getGasValue("cmbuGas", absoluteMap) == null ?"--":this.getGasValue("cmbuGas", absoluteMap));
		}

		
		
		list.add(y1);
		list.add(y2);
		list.add(y3);
		list.add(y4);
		list.add(y5);
		list.add(y6);
		list.add(y7);
		list.add(y8);
		list.add(y9);
		list.add(y10);
		list.add(y11);
		list.add(y12);
		list.add(y13);
		list.add(y14);
		list.add(y15);

		return list;
	}

	/**
	 * @Title: getAbsoluteGasProductionRate
	 * @Description: TODO
	 * @createDate: Sep 26, 2019 3:35:34 PM
	 * @param
	 * @return Map<String,Object>
	 */
	public Map<String, Object> getRelativeGasProductionRate(String sensorId, String startTime, String endTime) {
//		Calendar c = Calendar.getInstance();
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		try {
//			Date dtime = format.parse(exportTime);
//			c.setTime(dtime);
//			int month = c.get(Calendar.MONTH) + 1;
//			String start = getFirstDayOfMonth(month);
//			String end = getLastDayOfMonth(month);
			Date startDate = format.parse(startTime);
			Date endDate = format.parse(endTime);
			return busiYspReportMapper.getRelativeGasProductionRate(sensorId, startDate, endDate);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return new HashMap<>();
	}
	
	

	public static String getFirstDayOfMonth(int month) {
		Calendar cal = Calendar.getInstance();
		// 设置月份
		cal.set(Calendar.MONTH, month - 1);
		// 获取某月最小天数
		int firstDay = cal.getActualMinimum(Calendar.DAY_OF_MONTH);
		// 设置日历中月份的最小天数
		cal.set(Calendar.DAY_OF_MONTH, firstDay);
		// 格式化日期
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Date time = cal.getTime();
		String firstDayOfMonth = sdf.format(time) + " 00:00:00";
		return firstDayOfMonth;
	}

	public static Date getFirstDayOfMonth2(int month) {
		Calendar cal = Calendar.getInstance();
		// 设置月份
		cal.set(Calendar.MONTH, month - 1);
		// 获取某月最小天数
		int firstDay = cal.getActualMinimum(Calendar.DAY_OF_MONTH);
		// 设置日历中月份的最小天数
		cal.set(Calendar.DAY_OF_MONTH, firstDay);

		//将小时至0
		cal.set(Calendar.HOUR_OF_DAY, 0);
		//将分钟至0
		cal.set(Calendar.MINUTE, 0);
		//将秒至0
		cal.set(Calendar.SECOND,0);
		//将毫秒至0
		cal.set(Calendar.MILLISECOND, 0);
	
		// 格式化日期
		Date time = cal.getTime();
		return time;

	}

	
	/**
	 * 获得该月最后一天
	 * 
	 * @param year
	 * @param month
	 * @return
	 */
	public static String getLastDayOfMonth(int month) {
		Calendar cal = Calendar.getInstance();
		// 设置月份
		cal.set(Calendar.MONTH, month - 1);
		// 获取某月最大天数
		int lastDay = 0;
		// 2月的平年瑞年天数
		if (month == 2) {
			lastDay = cal.getLeastMaximum(Calendar.DAY_OF_MONTH);
		} else {
			lastDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
		}
		// 设置日历中月份的最大天数
		cal.set(Calendar.DAY_OF_MONTH, lastDay);
		// 格式化日期
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String lastDayOfMonth = sdf.format(cal.getTime()) + " 23:59:59";
		return lastDayOfMonth;
	}

	/**
	 * 获得该月最后一天
	 * 
	 * @param year
	 * @param month
	 * @return
	 */
	public static Date getLastDayOfMonth2(int month) {
		Calendar cal = Calendar.getInstance();
		// 设置月份
		cal.set(Calendar.MONTH, month - 1);
		// 获取某月最大天数
		int lastDay = 0;
		// 2月的平年瑞年天数
		if (month == 2) {
			lastDay = cal.getLeastMaximum(Calendar.DAY_OF_MONTH);
		} else {
			lastDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
		}
		// 设置日历中月份的最大天数
		cal.set(Calendar.DAY_OF_MONTH, lastDay);
		cal.set(Calendar.HOUR_OF_DAY, 23);  
		//将分钟至59
		cal.set(Calendar.MINUTE, 59);  
		//将秒至59
		cal.set(Calendar.SECOND,59);  
		//将毫秒至999
		cal.set(Calendar.MILLISECOND, 999);  
		Date time = cal.getTime();
		return time;
	}

	public static void main(String[] args) throws ParseException {
		Calendar c = Calendar.getInstance();
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		Date dtime = format.parse("2019-08-08");
		c.setTime(dtime);
		int month = c.get(Calendar.MONTH) + 1;
		System.out.println("month:" + month);
		String firstDayOfMonth = getFirstDayOfMonth(month);
		String lastDayOfMonth = getLastDayOfMonth(month);
		System.out.println("firstDayOfMonth:" + firstDayOfMonth);
		System.out.println("lastDayOfMonth:" + lastDayOfMonth);

		Date firstDayOfMonth2 = getFirstDayOfMonth2(month);
		Date lastDayOfMonth2 = getLastDayOfMonth2(month);

		System.out.println("firstDayOfMonth2:" + firstDayOfMonth2);
		System.out.println("lastDayOfMonth2:" + lastDayOfMonth2);

	}

}
