package com.huatek.busi.util;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;

import com.huatek.busi.entity.TransformerEpaData;

public class EqaUtil {

	
	/**
	 * 判断是否有载气信号
	 * @return 
	 * 		true : 载气正常
	 * 		false: 载气异常
	 */
	public static boolean judgePasPressIsExist(String pasPress) {
		if (StringUtils.isNoneBlank(pasPress) && new BigDecimal(pasPress).compareTo(BigDecimal.ZERO) > 0) {
			return true;
		}
		return false;
	}
	
	
	/** 
	* @Title: ThreeRatioCalculation 
	* @Description: 計算三比值結果 
	* @createDate: Sep 6, 2018 9:26:45 AM
	* @param    entity
	* @return   void    
	* @throws 
	*/ 
	public static Map<String, String>  threeRatioCalculation(TransformerEpaData entity){
		String H2 = entity.getH2();
		String CH4 = entity.getCh4();
		String C2H6 = entity.getC2h6();
		String C2H4 = entity.getC2h4();
		String C2H2 = entity.getC2h2();
		String CO = entity.getCo();
		String CO2 = entity.getCo2();
		return  Sanbizhi.getSanBiZhiResult(H2, CH4, C2H6, C2H4, C2H2, CO, CO2);		
	}
	
	
	/**
	 * @Title: diffValue
	 * @Description: 对比预警值 
	 * @createDate: Sep 4, 2018 4:20:55M 
	 * @param @return boolean @throws
	 */
	public static boolean diffValue(String limit, String value) {
		if(StringUtils.isBlank(value) || StringUtils.isBlank(limit)){
			return false ;
		}
		if (new BigDecimal(value).compareTo(new BigDecimal(limit)) > 0) {
			return true;
		}
		return false;
	}
	
	/**
	 * @Title: diffValue2
	 * @Description: 对比预警值 
	 * @createDate: Sep 4, 2018 4:20:55M 
	 * @param @return boolean @throws
	 */
	public static String diffValue2(String limit, String value) {
		if(StringUtils.isBlank(value) || StringUtils.isBlank(limit)){
			return "-" ;
		}
		if (new BigDecimal(value).compareTo(new BigDecimal(limit)) > 0) {
			return value;
		}
		return "-";
	}

	
	/** 
	* @Title: compareGasValue 
	* @Description: 对比偏差率值 
	* @createDate: Sep 5, 2018 11:21:53 AM
	* @param   
	* @return   BigDecimal    
	* @throws 
	*/ 
	public static BigDecimal compareGasValue(String newValue1, String originalValue1) {
		BigDecimal newValue = BigDecimal.ZERO, originalValue = BigDecimal.ZERO;
		try {
			newValue = new BigDecimal(newValue1);
			originalValue = new BigDecimal(originalValue1);
		} catch (Exception e) {
			return BigDecimal.ZERO;
		}
		if(BigDecimal.ZERO.compareTo(newValue) == 0 || BigDecimal.ZERO.compareTo(originalValue) == 0) {
			return BigDecimal.ZERO;
		}
		BigDecimal subtract = originalValue.subtract(newValue);
		if(newValue.compareTo(BigDecimal.ZERO) == 0) {
			return BigDecimal.ZERO;
		}
		BigDecimal divide =  subtract.divide(newValue,2, RoundingMode.HALF_DOWN);
		if(divide.compareTo(new BigDecimal("0"))!=0) {
			return divide.setScale(2,  RoundingMode.HALF_DOWN);	
		}
		return new BigDecimal("0.00");
	}
	
	public static BigDecimal validationGasValue(BigDecimal valiation, BigDecimal originalValue){
		if(null == valiation){
			return originalValue.setScale(2, RoundingMode.HALF_UP);
		}
		
		if(valiation.compareTo(BigDecimal.ZERO) >0 ){
			return originalValue.multiply(new BigDecimal("1.0").add(valiation)).setScale(2, RoundingMode.HALF_UP); 
		}else if(valiation.compareTo(BigDecimal.ZERO) == 0 ){
				return originalValue ;
		}else if(valiation.compareTo(BigDecimal.ZERO) < 0 ){
			return originalValue.multiply(new BigDecimal("1.0").add(valiation)).setScale(2, RoundingMode.HALF_UP); 
		}
		return BigDecimal.ZERO;
		
	}
	
	
	public static String transforeData(String value){
		if(StringUtils.isNotBlank(value)){
			return new BigDecimal(value).setScale(2, RoundingMode.HALF_DOWN).toString();
		}
		
		return value ;
	}


	
	
}
