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

import java.math.BigDecimal;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.dubbo.config.annotation.Service;
import com.google.common.collect.Lists;
import com.huatek.busi.common.SiteConstants.ExternalTypeEnum;
import com.huatek.busi.common.util.DateUtil;
import com.huatek.busi.common.util.FieldUtil;
import com.huatek.busi.dao.TransformerEpaDataCacheDao;
import com.huatek.busi.dto.TransformerEpaDataCacheDto;
import com.huatek.busi.entity.BusiExternalEquipment;
import com.huatek.busi.entity.TransformerEpaAbsIncreaseCache;
import com.huatek.busi.entity.TransformerEpaData;
import com.huatek.busi.entity.TransformerEpaDataCache;
import com.huatek.busi.entity.TransformerEpaDeviation;
import com.huatek.busi.entity.TransformerEpaIncreaseCache;
import com.huatek.busi.mapper.TransformerEpaDataCacheMapper;
import com.huatek.busi.service.BusiCommonService;
import com.huatek.busi.service.BusiEqmWarningService;
import com.huatek.busi.service.BusiExternalEquipmentService;
import com.huatek.busi.service.BusiSensorService;
import com.huatek.busi.service.BusiSiteTreeService;
import com.huatek.busi.service.threshold.TransformerOilThresholdService;
import com.huatek.busi.service.transformer.TransformerEpaDataCacheService;
import com.huatek.busi.service.transformer.TransformerEpaDataOriginService;
import com.huatek.busi.service.transformer.TransformerEpaDeviationService;
import com.huatek.busi.util.EqaUtil;
import com.huatek.busi.vo.BusiEquipmentVo;
import com.huatek.busi.vo.BusiSensorVo;
import com.huatek.busi.vo.TransformerEpaDataCacheVo;
import com.huatek.busi.vo.TransformerOilThresholdVo;
import com.huatek.busi.vo.warning.BusiOiTmplVo;
import com.huatek.busi.vo.warning.BusiOilVo;

/**
 * 变压器油色谱暂存数据（类型编码 ：021002） ServiceImpl
 *
 * @author anker_cheng
 * @date Jul 15, 2019 1:49:05 PM
 */
@Component
@Service(interfaceClass = TransformerEpaDataCacheService.class)
@Transactional(rollbackFor = Exception.class)
public class TransformerEpaDataCacheServiceImpl implements TransformerEpaDataCacheService {

	@Autowired
    private TransformerEpaDataCacheMapper transformerEpaDataCacheMapper;
    @Autowired
    private TransformerEpaDataCacheDao transformerEpaDataCacheDao; 
    @Reference(check = false)
    private TransformerOilThresholdService transformerOilThresholdService;
    @Reference(check = false)
    private BusiCommonService busiCommonService;
    @Reference(check = false)
    private BusiEqmWarningService busiEqmWarningService;
    @Reference(check = false)
    private BusiExternalEquipmentService busiExternalEquipmentService;
    @Reference(check = false)
    private BusiSensorService busiSensorService;
    @Reference(check = false)
    private BusiSiteTreeService busiSiteTreeService;
    @Reference(check = false)
    private TransformerEpaDataOriginService epaDataOriginService;
    @Reference(check = false)
    private TransformerEpaDeviationService transformerEpaDeviationService;

    @Override
    public synchronized int saveOrUpdateTransformerEpaDataCache(TransformerEpaData entity, EquipmentInfoDto equipmentInfo) {
        TransformerEpaDataCache transformerEpaDataCache =
            transformerEpaDataCacheMapper.findBySubEquipmentId(entity.getSiteId(), entity.getSensorId());
        if (transformerEpaDataCache == null) {
            transformerEpaDataCache = new TransformerEpaDataCache();
        }
        transformerEpaDataCache.setH2(EqaUtil.transforeData(entity.getH2()));
        transformerEpaDataCache.setC2h2(EqaUtil.transforeData(entity.getC2h2()));
        transformerEpaDataCache.setC2h4(EqaUtil.transforeData(entity.getC2h4()));
        transformerEpaDataCache.setC2h6(EqaUtil.transforeData(entity.getC2h6()));
        transformerEpaDataCache.setCh4(EqaUtil.transforeData(entity.getCh4()));
        transformerEpaDataCache.setCo(EqaUtil.transforeData(entity.getCo()));
        transformerEpaDataCache.setCo2(EqaUtil.transforeData(entity.getCo2()));
        transformerEpaDataCache.setO2(EqaUtil.transforeData(entity.getO2()));
        transformerEpaDataCache.setN2(EqaUtil.transforeData(entity.getN2()));
        transformerEpaDataCache.setTotalHydrocarbon(EqaUtil.transforeData(entity.getTotalHydrocarbon()));
        transformerEpaDataCache.setH2o(EqaUtil.transforeData(entity.getH2o()));
        transformerEpaDataCache.setTmp(EqaUtil.transforeData(entity.getTemperature()));
        transformerEpaDataCache.setDew(EqaUtil.transforeData(entity.getHumidity()));
        transformerEpaDataCache.setMst(EqaUtil.transforeData(entity.getMicroMoisture()));
        transformerEpaDataCache.setFlatGas(EqaUtil.transforeData(entity.getFlatGas()));
        transformerEpaDataCache.setCmbuGas(EqaUtil.transforeData(entity.getCmbuGas()));
        transformerEpaDataCache.setDTime(entity.getTimeStamp());
        transformerEpaDataCache.setPhase(entity.getPhase());

        String oilType = equipmentInfo.getOilDetailType();
        if(oilType.equals(SiteConstants.oilDetailType.OIL_DETAIL_TYPE_1.getValue())){
			if (entity.getGasPress() == null || StringUtils.isNotBlank(entity.getGasPress())) {
				transformerEpaDataCache.setGasPressStatus("1");
			} else {
				transformerEpaDataCache.setGasPressStatus("2");
			}
		} else if(oilType.equals(SiteConstants.oilDetailType.OIL_DETAIL_TYPE_2.getValue())){
			transformerEpaDataCache.setGasPressStatus("");
		}

        transformerEpaDataCache.setSiteId(entity.getSiteId());
        transformerEpaDataCache.setEquipmentId(entity.getEquipmentId());
        transformerEpaDataCache.setMainEquipmentId(entity.getMainEquipmentId());
        transformerEpaDataCache.setSubEquipmentId(entity.getSubEquipmentId());
        transformerEpaDataCache.setMainTreeId(entity.getMainTreeId());
        transformerEpaDataCache.setSubTreeId(entity.getSubTreeId());
        transformerEpaDataCache.setSensorId(entity.getSensorId());
        transformerEpaDataCache.setCacId(entity.getCacId());
        
        return transformerEpaDataCacheDao.saveOrUpdate(transformerEpaDataCache);
    }

	@Override
	public BusiOilVo findTransformerEpaDataCacheRecordPage(
			TransformerEpaDataCacheDto transformerEpaDataCacheDto) {
		// TODO Auto-generated method stub
		String sensorId = transformerEpaDataCacheDto.getSensorId();
		BusiOilVo busiOilVo = new BusiOilVo();
		TransformerEpaDataCacheVo transformerEpaDataCacheVoInfo = transformerEpaDataCacheMapper.selectTransformerEpaDataCachePage(transformerEpaDataCacheDto);

		Map<String, Object> typeMap = transformerOilThresholdService.findType(sensorId);
		String oilType = typeMap.get("type").toString();
		String oilDetailType = typeMap.get("oilType").toString();

	    List<String> gasNameList = new ArrayList<>();
	    if(oilType.equals(SiteConstants.oilType.OILTYPE1.getValue())){
	    	if(oilDetailType.equals(SiteConstants.oilDetailType.OIL_DETAIL_TYPE_1.getValue())){
				gasNameList = Lists.newArrayList("H2", "CH4","C2H2","C2H4", "C2H6","CO","CO2", "O2","N2","H2O","总烃");
			}else if(oilDetailType.equals(SiteConstants.oilDetailType.OIL_DETAIL_TYPE_2.getValue())) {
				gasNameList = Lists.newArrayList("H2", "CH4","C2H2","C2H4", "C2H6","CO","CO2", "O2","N2","微水","总可燃气体","总烃");
			}
		}else if(oilType.equals(SiteConstants.oilType.OILTYPE2.getValue())){
			if(oilDetailType.equals(SiteConstants.oilDetailType.OIL_DETAIL_TYPE_1.getValue())){
				gasNameList = Lists.newArrayList("温度","湿度","微水","总烃");
			}else if(oilDetailType.equals(SiteConstants.oilDetailType.OIL_DETAIL_TYPE_2.getValue())) {
				gasNameList = Lists.newArrayList("温度","湿度","微水","总可燃气体");
			}
		}
		busiOilVo = buildOilData(gasNameList,transformerEpaDataCacheVoInfo,sensorId,oilDetailType);

		BusiExternalEquipment externalEquipment = busiExternalEquipmentService.findBySensorCode(sensorId, ExternalTypeEnum.BYQ.getValue());
        if (ObjectUtils.isNotEmpty(externalEquipment)){
			busiOilVo.setExternalType(externalEquipment.getExternalType());
		}
        //监测装置名称
        BusiEquipmentVo equipmentVo = busiSiteTreeService.findBySensorCode(sensorId, ExternalTypeEnum.BYQ.getValue());
		if (ObjectUtils.isNotEmpty(equipmentVo)){
			busiOilVo.setEquipmentName(equipmentVo.getEquipmentName());
			busiOilVo.setMainEquipmentName(equipmentVo.getMainEquipmentName());
		}
        BusiSensorVo busiSensorVo = busiSensorService.getBusiSensorVo(ExternalTypeEnum.BYQ, sensorId);
        if (ObjectUtils.isNotEmpty(busiSensorVo)) {
	        //标牌
	        busiOilVo.setBrand(busiSensorVo.getSensorBrand());
	        //生产厂家
	        busiOilVo.setManufactor(busiSensorVo.getManufactor());
	        //安装位置
	        busiOilVo.setInstallLocation(busiSensorVo.getPositionDes());
	        //投运时间
	        busiOilVo.setUseDate(busiSensorVo.getUseDate());
        }
        //采集时间
        if(transformerEpaDataCacheVoInfo!=null)
        {
            busiOilVo.setCollectDate(transformerEpaDataCacheVoInfo.getDTime());
        }
		if (ObjectUtils.isNotEmpty(externalEquipment)){
			//维修次数
			busiOilVo.setRepairCount(busiCommonService.getEquipHalfYearRepairCount(ExternalTypeEnum.BYQ, externalEquipment.getId()));
			//误报率
			busiOilVo.setFalseAlarmRate(busiEqmWarningService.getFalseAlarmRateBySensor(sensorId, DateUtil.getMonthStartDay(), DateUtil.getMonthLastDay()));
		}

		return busiOilVo;
	}
	/**
	 * 组装油色谱数据
	 */
	private BusiOilVo buildOilData(List<String> gasNameList,TransformerEpaDataCacheVo transformerEpaDataCacheVoInfo,String sensorId, String oilDetailType) {
		DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
		List<BusiOiTmplVo> oilTempList = new ArrayList<>();
		BusiOilVo busiOilVo = new BusiOilVo();
		TransformerOilThresholdVo thresholdInfo = transformerOilThresholdService.getBySensorCode(sensorId);
		boolean thresholdVoFlag = ObjectUtils.isNotEmpty(thresholdInfo);
		boolean flag = ObjectUtils.isNotEmpty(transformerEpaDataCacheVoInfo);
		//获取增长率数据
		TransformerEpaAbsIncreaseCache absIncreaseCache = epaDataOriginService.getEpaAbsIncreaseCacheInfo(sensorId);
		//获取偏差率数据
		TransformerEpaIncreaseCache  increaseCache = epaDataOriginService.getEpaRelativeIncreaseCacheInfo(sensorId);
		TransformerEpaDeviation epaDeviation  = transformerEpaDeviationService.getEpaDeviation(sensorId);
		BigDecimal c2h2GasValue = new BigDecimal(0);
		BigDecimal coGasValue = new BigDecimal(0);
		BigDecimal ch4GasValue = new BigDecimal(0);
		BigDecimal c2h4GasValue = new BigDecimal(0);
		BigDecimal c2h6GasValue = new BigDecimal(0);
		BigDecimal h2GasValue = new BigDecimal(0);
//		BigDecimal h2oGasValue = new BigDecimal(0);
		if (flag) {
			if(StringUtils.isNotBlank(transformerEpaDataCacheVoInfo.getC2h2())) {
				c2h2GasValue = new BigDecimal(transformerEpaDataCacheVoInfo.getC2h2());
			}
			if(StringUtils.isNotBlank(transformerEpaDataCacheVoInfo.getCo())) {
				coGasValue = new BigDecimal(transformerEpaDataCacheVoInfo.getCo());
			}
			if(StringUtils.isNotBlank(transformerEpaDataCacheVoInfo.getCh4())) {
				ch4GasValue = new BigDecimal(transformerEpaDataCacheVoInfo.getCh4());
			}
			if(StringUtils.isNotBlank(transformerEpaDataCacheVoInfo.getC2h4())) {
				c2h4GasValue = new BigDecimal(transformerEpaDataCacheVoInfo.getC2h4());
			}
			if(StringUtils.isNotBlank(transformerEpaDataCacheVoInfo.getC2h6())) {
				c2h6GasValue = new BigDecimal(transformerEpaDataCacheVoInfo.getC2h6());
			}
			if(StringUtils.isNotBlank(transformerEpaDataCacheVoInfo.getH2())) {
				h2GasValue = new BigDecimal(transformerEpaDataCacheVoInfo.getH2());
			}
		}
		gasNameList.forEach(gasName -> {
			BusiOiTmplVo oilTmpVo = new BusiOiTmplVo();
			oilTmpVo.setDTime(flag ? transformerEpaDataCacheVoInfo.getDTime().format(formatter) : "-"); //收集时间
			//绝对增长率
			if (ObjectUtils.isNotEmpty(absIncreaseCache)) {
				if (gasName.equals("总烃")) {
					oilTmpVo.setIncreaseRate(FieldUtil.getFieldValue(absIncreaseCache, "totalHydrocarbon") + "");
				} else {
					oilTmpVo.setIncreaseRate(FieldUtil.getFieldValue(absIncreaseCache, gasName.toLowerCase()) + "");
				}
			}
			
			//相对增长率
			if (ObjectUtils.isNotEmpty(increaseCache)) {
				if (gasName.equals("总烃")) {
					oilTmpVo.setRelativeIncreaseRate(FieldUtil.getFieldValue(increaseCache, "totalHydrocarbon") + "");
				} else {
					oilTmpVo.setRelativeIncreaseRate(FieldUtil.getFieldValue(increaseCache, gasName.toLowerCase()) + "");
				}
			}
			oilTmpVo.setGasName(gasName);//气体类型
			if (gasName.equals("H2")) {
				oilTmpVo.setGasValue(flag ? transformerEpaDataCacheVoInfo.getH2() : "-"); //监测值
				
				if (thresholdVoFlag) {
					oilTmpVo.setThresholdValue(thresholdInfo.getH2Threshold()); //阈值
					oilTmpVo.setWarningValue(thresholdInfo.getH2Warning());//预警值
					oilTmpVo.setAccuracyIndex(thresholdInfo.getH2Accuracy());//精度指标
				}
				//偏差率
				if (ObjectUtils.isNotEmpty(epaDeviation)) {
					oilTmpVo.setDeviationRate(epaDeviation.getH2Deviation()+"");
				}
				
			}
			if (gasName.equals("CH4")) {
				oilTmpVo.setGasValue(flag ? transformerEpaDataCacheVoInfo.getCh4() : "-"); 
				if (thresholdVoFlag) {
					oilTmpVo.setThresholdValue(thresholdInfo.getCh4Threshold());
					oilTmpVo.setWarningValue(thresholdInfo.getCh4Warning());
					oilTmpVo.setAccuracyIndex(thresholdInfo.getCh4Accuracy());
				}
				//偏差率
				if (ObjectUtils.isNotEmpty(epaDeviation)) {
					oilTmpVo.setDeviationRate(epaDeviation.getCh4Deviation()+"");
				}
			}
			if (gasName.equals("C2H2")) {
				oilTmpVo.setGasValue(flag ? transformerEpaDataCacheVoInfo.getC2h2() : "-");
				if (thresholdVoFlag) {
					oilTmpVo.setThresholdValue(thresholdInfo.getC2h2Threshold()); 
					oilTmpVo.setWarningValue(thresholdInfo.getC2h2Warning());
					oilTmpVo.setAccuracyIndex(thresholdInfo.getC2h2Accuracy());
				}
				//偏差率
				if (ObjectUtils.isNotEmpty(epaDeviation)) {
					oilTmpVo.setDeviationRate(epaDeviation.getC2h2Deviation()+"");
				}
			}
			if (gasName.equals("C2H4")) {
				oilTmpVo.setGasValue(flag ? transformerEpaDataCacheVoInfo.getC2h4() : "-");
				if (thresholdVoFlag) {
					oilTmpVo.setThresholdValue(thresholdInfo.getC2h4Threshold()); 
					oilTmpVo.setWarningValue(thresholdInfo.getC2h4Warning());
					oilTmpVo.setAccuracyIndex(thresholdInfo.getC2h4Accuracy());
				}
				//偏差率
				if (ObjectUtils.isNotEmpty(epaDeviation)) {
					oilTmpVo.setDeviationRate(epaDeviation.getC2h4Deviation()+"");
				}
			}
			if (gasName.equals("C2H6")) {
				oilTmpVo.setGasValue(flag ? transformerEpaDataCacheVoInfo.getC2h6() : "-");
				if (thresholdVoFlag) {
					oilTmpVo.setThresholdValue(thresholdInfo.getC2h6Threshold());
					oilTmpVo.setWarningValue(thresholdInfo.getC2h6Warning());
					oilTmpVo.setAccuracyIndex(thresholdInfo.getC2h6Accuracy());
				}
				//偏差率
				if (ObjectUtils.isNotEmpty(epaDeviation)) {
					oilTmpVo.setDeviationRate(epaDeviation.getC2h6Deviation()+"");
				}
			}
			if (gasName.equals("CO")) {
				oilTmpVo.setGasValue(flag ? transformerEpaDataCacheVoInfo.getCo() : "-");
				if (thresholdVoFlag) {
					oilTmpVo.setThresholdValue(thresholdInfo.getCoThreshold());
					oilTmpVo.setWarningValue(thresholdInfo.getCoWarning());
					oilTmpVo.setAccuracyIndex(thresholdInfo.getCoAccuracy());
				}
				//偏差率
				if (ObjectUtils.isNotEmpty(epaDeviation)) {
					oilTmpVo.setDeviationRate(epaDeviation.getCoDeviation()+"");
				}
			}
			if (gasName.equals("CO2")) {
				oilTmpVo.setGasValue(flag ? transformerEpaDataCacheVoInfo.getCo2():"-");
				if (thresholdVoFlag) {
					oilTmpVo.setThresholdValue(thresholdInfo.getCo2Threshold()); 
					oilTmpVo.setWarningValue(thresholdInfo.getCo2Warning());
					oilTmpVo.setAccuracyIndex(thresholdInfo.getCo2Accuracy());
				}
				//偏差率
				if (ObjectUtils.isNotEmpty(epaDeviation)) {
					oilTmpVo.setDeviationRate(epaDeviation.getCo2Deviation()+"");
				}
			}
			if (gasName.equals("O2")) {
				oilTmpVo.setGasValue(flag ? transformerEpaDataCacheVoInfo.getO2():"-");
				if (thresholdVoFlag) {
					oilTmpVo.setThresholdValue(thresholdInfo.getO2Threshold()); 
					oilTmpVo.setWarningValue(thresholdInfo.getO2Warning());
					oilTmpVo.setAccuracyIndex(thresholdInfo.getO2Accuracy());
				}
				//偏差率
				if (ObjectUtils.isNotEmpty(epaDeviation)) {
					oilTmpVo.setDeviationRate(epaDeviation.getO2Deviation()+"");
				}
			}
			if (gasName.equals("N2")) {
				oilTmpVo.setGasValue(flag ? transformerEpaDataCacheVoInfo.getN2():"-"); 
				if (thresholdVoFlag) {
					oilTmpVo.setThresholdValue(thresholdInfo.getN2Threshold());
					oilTmpVo.setWarningValue(thresholdInfo.getN2Warning());
					oilTmpVo.setAccuracyIndex(thresholdInfo.getN2Accuracy());
				}
				//偏差率
				if (ObjectUtils.isNotEmpty(epaDeviation)) {
					oilTmpVo.setDeviationRate(epaDeviation.getN2Deviation()+"");
				}
			}
			if (gasName.equals("总烃")) {
				oilTmpVo.setGasValue(flag ? transformerEpaDataCacheVoInfo.getTotalHydrocarbon():"-");
				if (thresholdVoFlag) {
					oilTmpVo.setThresholdValue(thresholdInfo.getTotalHydrocarbonThreshold());
					oilTmpVo.setWarningValue(thresholdInfo.getTotalHydrocarbonWarning());
					oilTmpVo.setAccuracyIndex(thresholdInfo.getTotalHydrocarbonAccuracy());
				}
				if(absIncreaseCache != null)
				{
					oilTmpVo.setIncreaseRate(StringUtils.isNotEmpty(absIncreaseCache.getTotalHydrocarbon() + "")
							? absIncreaseCache.getTotalHydrocarbon() + "" : "-");
				}
				//偏差率
				if (ObjectUtils.isNotEmpty(epaDeviation)) {
					oilTmpVo.setDeviationRate(epaDeviation.getTotalHydrocarbonDeviation()+"");
				}
			}
			if (gasName.equals("H2O")) {
				oilTmpVo.setGasValue(flag ? transformerEpaDataCacheVoInfo.getH2o():"-");
				if (thresholdVoFlag) {
					oilTmpVo.setThresholdValue(thresholdInfo.getH2oThreshold()); 
					oilTmpVo.setWarningValue(thresholdInfo.getH2oWarning());
					oilTmpVo.setAccuracyIndex(thresholdInfo.getH2oAccuracy());
				}
				if (StringUtils.isNotEmpty(oilTmpVo.getIncreaseRate()) && oilTmpVo.getIncreaseRate().equals("null")) {
					oilTmpVo.setIncreaseRate("0");
				}
				//偏差率
				if (ObjectUtils.isNotEmpty(epaDeviation)) {
					oilTmpVo.setDeviationRate(epaDeviation.getH2oDeviation()+"");
				}
			}
			if (gasName.equals("温度")) {
				oilTmpVo.setGasValue(flag ? transformerEpaDataCacheVoInfo.getTmp() : "-");
				if (thresholdVoFlag) {
					oilTmpVo.setThresholdValue(thresholdInfo.getTmpThreshold());
					oilTmpVo.setWarningValue(thresholdInfo.getTmpWarning());
					oilTmpVo.setAccuracyIndex(thresholdInfo.getTmpAccuracy());
				}
				if (StringUtils.isNotEmpty(oilTmpVo.getIncreaseRate()) && oilTmpVo.getIncreaseRate().equals("null")) {
					oilTmpVo.setIncreaseRate("0");
				}
				//偏差率
				if (ObjectUtils.isNotEmpty(epaDeviation)) {
					oilTmpVo.setDeviationRate(epaDeviation.getTmpDeviation() + "");
				}
			}
			if (gasName.equals("湿度")) {
				oilTmpVo.setGasValue(flag ? transformerEpaDataCacheVoInfo.getDew() : "-");
				if (thresholdVoFlag) {
					oilTmpVo.setThresholdValue(thresholdInfo.getDewThreshold());
					oilTmpVo.setWarningValue(thresholdInfo.getDewWarning());
					oilTmpVo.setAccuracyIndex(thresholdInfo.getDewAccuracy());
				}
				if (StringUtils.isNotEmpty(oilTmpVo.getIncreaseRate()) && oilTmpVo.getIncreaseRate().equals("null")) {
					oilTmpVo.setIncreaseRate("0");
				}
				//偏差率
				if (ObjectUtils.isNotEmpty(epaDeviation)) {
					oilTmpVo.setDeviationRate(epaDeviation.getDewDeviation() + "");
				}
			}
			if (gasName.equals("微水")) {
				oilTmpVo.setGasValue(flag ? transformerEpaDataCacheVoInfo.getMst() : "-");
				if (thresholdVoFlag) {
					oilTmpVo.setThresholdValue(thresholdInfo.getMstThreshold());
					oilTmpVo.setWarningValue(thresholdInfo.getMstWarning());
					oilTmpVo.setAccuracyIndex(thresholdInfo.getMstAccuracy());
				}
				if (StringUtils.isNotEmpty(oilTmpVo.getIncreaseRate()) && oilTmpVo.getIncreaseRate().equals("null")) {
					oilTmpVo.setIncreaseRate("0");
				}
				//偏差率
				if (ObjectUtils.isNotEmpty(epaDeviation)) {
					oilTmpVo.setDeviationRate(epaDeviation.getMstDeviation() + "");
				}
			}
//			if (gasName.equals("瓦斯继电器中故障气")) {
//				oilTmpVo.setGasValue(flag ? transformerEpaDataCacheVoInfo.getFlatGas():"-");
//				if (thresholdVoFlag) {
//					oilTmpVo.setThresholdValue(thresholdInfo.getFlatGasThreshold());
//					oilTmpVo.setWarningValue(thresholdInfo.getFlatGasWarning());
//					oilTmpVo.setAccuracyIndex(thresholdInfo.getFlatGasAccuracy());
//				}
//				if (StringUtils.isNotEmpty(oilTmpVo.getIncreaseRate()) && oilTmpVo.getIncreaseRate().equals("null")) {
//					oilTmpVo.setIncreaseRate("0");
//				}
//				//偏差率
//				if (ObjectUtils.isNotEmpty(epaDeviation)) {
//					oilTmpVo.setDeviationRate(epaDeviation.getFlatGasDeviation()+"");
//				}
//			}
			if (gasName.equals("总可燃气体")) {
				oilTmpVo.setGasValue(flag ? transformerEpaDataCacheVoInfo.getCmbuGas() : "-");
				if (thresholdVoFlag) {
					oilTmpVo.setThresholdValue(thresholdInfo.getCmbuGasThreshold());
					oilTmpVo.setWarningValue(thresholdInfo.getCmbuGasWarning());
					oilTmpVo.setAccuracyIndex(thresholdInfo.getCmbuGasAccuracy());
				}
				if (StringUtils.isNotEmpty(oilTmpVo.getIncreaseRate()) && oilTmpVo.getIncreaseRate().equals("null")) {
					oilTmpVo.setIncreaseRate("0");
				}
				//偏差率
				if (ObjectUtils.isNotEmpty(epaDeviation)) {
					oilTmpVo.setDeviationRate(epaDeviation.getCmbuGasDeviation() + "");
				}
			}
			oilTempList.add(oilTmpVo);
		});
		if(oilDetailType.equals(SiteConstants.oilDetailType.OIL_DETAIL_TYPE_1.getValue())) {
			BusiOiTmplVo oilTmpVo = new BusiOiTmplVo();
			oilTmpVo.setGasName("总可燃气体");
			oilTmpVo.setGasValue(c2h2GasValue.add(coGasValue).add(ch4GasValue).add(c2h4GasValue).add(c2h6GasValue).add(h2GasValue)+"");
			oilTempList.add(oilTmpVo);
		}
		busiOilVo.setList(oilTempList);
		return busiOilVo;
	}
	
}