package cn.wise.sc.acquisition.business.util;

import com.sun.org.apache.bcel.internal.generic.RETURN;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.cookie.SM;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.formula.functions.T;
import org.apache.poi.ss.usermodel.*;

import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 校核计算工具类
 * 
 * @author zhutianwei
 *
 */
public class CheckCountUtil {

	//倍数
	public final static BigDecimal param10 = new BigDecimal(10.00);
	public final static BigDecimal param100 = new BigDecimal(100.00);
	public final static BigDecimal param1000 = new BigDecimal(1000.00);
	public final static BigDecimal param10000 = new BigDecimal(10000.00);

	//object 转成  BigDecimal
	public static BigDecimal getBigDecimal(Object value ) {
		BigDecimal ret = null;
		if( value != null &&  !value.equals("") ) {
			if( value instanceof BigDecimal ) {
				ret = (BigDecimal) value;
			} else if( value instanceof String ) {
				ret = new BigDecimal( (String) value );
			} else if( value instanceof BigInteger) {
				ret = new BigDecimal( (BigInteger) value );
			} else if( value instanceof Number ) {
				ret = new BigDecimal( ((Number)value).doubleValue() );
			} else {
				throw new ClassCastException("Not possible to coerce ["+value+"] from class "+value.getClass()+" into a BigDecimal.");
			}
		}
		return ret;
	}

	/**
	 * 检测项名称
	 * @param name
	 * @return
	 */
	//加 add 减 subtract  乘 multiply  除 divide
	public static String checkCount(String name, Map<String, String> resultMap) {
		BigDecimal endResult = null;
		if(name.equals("L.O.I")){
			if( StringUtils.isNotBlank(resultMap.get("样重m1")) &&
				StringUtils.isNotBlank(resultMap.get("空埚重m2"))&&
				StringUtils.isNotBlank(resultMap.get("烧后重m3"))){
				//样重m1—保留4位⼩数
				BigDecimal m1 = getBigDecimal(resultMap.get("样重m1").trim()).setScale(4,BigDecimal.ROUND_HALF_UP);
				//空埚重m2—保留4位⼩数
				BigDecimal m2 = getBigDecimal(resultMap.get("空埚重m2").trim()).setScale(4,BigDecimal.ROUND_HALF_UP);
				//烧后重m3—保留4位⼩数
				BigDecimal m3 = getBigDecimal(resultMap.get("烧后重m3").trim()).setScale(4,BigDecimal.ROUND_HALF_UP);
				//计算的核心公式结果
				BigDecimal countResult = (m1.add(m2).subtract(m3)).divide(m1,10,BigDecimal.ROUND_HALF_UP);
				BigDecimal result1 = countResult.multiply(param100.multiply(param100));
				int resultInt1  = result1.setScale( 0, BigDecimal.ROUND_DOWN ).intValue();
				if((resultInt1&1) == 1){  //如果结果为奇数
					endResult =  countResult.multiply(param100).setScale(2,BigDecimal.ROUND_HALF_UP);
				}else{
					endResult = countResult.multiply(param100).subtract(new BigDecimal(0.0000000001)).setScale(2,BigDecimal.ROUND_HALF_UP);
				}
			}
		}else if(name.equals("SiO<sub>2</sub>")){
			if( StringUtils.isNotBlank(resultMap.get("VSiO<sub>2</sub>")) &&
					StringUtils.isNotBlank(resultMap.get("TSiO<sub>2</sub>"))&&
					StringUtils.isNotBlank(resultMap.get("样重m"))){
				//毫升数
				BigDecimal VSiO2 = getBigDecimal(resultMap.get("VSiO<sub>2</sub>").trim());
				//滴定度
				BigDecimal TSiO2 = getBigDecimal(resultMap.get("TSiO<sub>2</sub>").trim());
				//样m
				BigDecimal m = getBigDecimal(resultMap.get("样重m").trim());
				//计算的核心公式结果
				BigDecimal countResult = VSiO2.multiply(TSiO2).divide(m,10,BigDecimal.ROUND_HALF_UP);
				BigDecimal result1 = countResult.multiply(param100);
				int resultInt1  = result1.setScale( 0, BigDecimal.ROUND_DOWN ).intValue();
				if((resultInt1&1) == 1){  //如果结果为奇数
					endResult =  countResult.setScale(2,BigDecimal.ROUND_HALF_UP);
				}else{
					endResult = countResult.subtract(new BigDecimal(0.0000000001)).setScale(2,BigDecimal.ROUND_HALF_UP);
				}
			}
		}else if(name.equals("Al<sub>2</sub>O<sub>3</sub>+TiO<sub>2</sub>")){
			if( StringUtils.isNotBlank(resultMap.get("TAl<sub>2</sub>O<sub>3</sub>")) &&
					StringUtils.isNotBlank(resultMap.get("VAl<sub>2</sub>O<sub>3</sub>"))&&
					StringUtils.isNotBlank(resultMap.get("K"))&&
					StringUtils.isNotBlank(resultMap.get("VCuSO<sub>4</sub>(I)"))&&
					StringUtils.isNotBlank(resultMap.get("样重m"))
					){
				BigDecimal TAl2O3 = getBigDecimal(resultMap.get("TAl<sub>2</sub>O<sub>3</sub>").trim());
				BigDecimal VAl2O3 = getBigDecimal(resultMap.get("VAl<sub>2</sub>O<sub>3</sub>").trim());
				BigDecimal K = getBigDecimal(resultMap.get("K").trim());
				BigDecimal VCuSO4_I = getBigDecimal(resultMap.get("VCuSO<sub>4</sub>(I)").trim());
				BigDecimal m = getBigDecimal(resultMap.get("样重m").trim());
				//计算的核心公式结果
				BigDecimal countResult = TAl2O3.multiply(VAl2O3.subtract(K.multiply(VCuSO4_I))).divide(m,10,BigDecimal.ROUND_HALF_UP);
				BigDecimal result1 = countResult.multiply(param100);
				int resultInt1  = result1.setScale( 0, BigDecimal.ROUND_DOWN ).intValue();
				if((resultInt1&1) == 1){  //如果结果为奇数
					endResult =  countResult.setScale(2,BigDecimal.ROUND_HALF_UP);
				}else{
					endResult = countResult.subtract(new BigDecimal(0.0000000001)).setScale(2,BigDecimal.ROUND_HALF_UP);
				}
			}
		}else if(name.equals("Al<sub>2</sub>O<sub>3</sub>")){
			if( StringUtils.isNotBlank(resultMap.get("TAl<sub>2</sub>O<sub>3</sub>")) &&
					StringUtils.isNotBlank(resultMap.get("VAl<sub>2</sub>O<sub>3</sub>"))&&
					StringUtils.isNotBlank(resultMap.get("K"))&&
					StringUtils.isNotBlank(resultMap.get("VCuSO<sub>4</sub>(I)"))&&
					StringUtils.isNotBlank(resultMap.get("样重m"))&&
					StringUtils.isNotBlank(resultMap.get("VCuSO<sub>4</sub>(II)"))
					){
				BigDecimal TAl2O3 = getBigDecimal(resultMap.get("TAl<sub>2</sub>O<sub>3</sub>").trim());
				BigDecimal VAl2O3 = getBigDecimal(resultMap.get("VAl<sub>2</sub>O<sub>3</sub>").trim());
				BigDecimal K = getBigDecimal(resultMap.get("K").trim());
				BigDecimal VCuSO4_I = getBigDecimal(resultMap.get("VCuSO<sub>4</sub>(I)").trim());
				BigDecimal m = getBigDecimal(resultMap.get("样重m").trim());
				BigDecimal VCuSO4_II = getBigDecimal(resultMap.get("VCuSO<sub>4</sub>(II)").trim());
				//计算的核心公式结果
				BigDecimal countResult = TAl2O3.multiply(VAl2O3.subtract(K.multiply(VCuSO4_I.add(VCuSO4_II)))).divide(m,10,BigDecimal.ROUND_HALF_UP);
				BigDecimal result1 = countResult.multiply(param100);
				int resultInt1  = result1.setScale( 0, BigDecimal.ROUND_DOWN ).intValue();
				if((resultInt1&1) == 1){  //如果结果为奇数
					endResult =  countResult.setScale(2,BigDecimal.ROUND_HALF_UP);
				}else{
					endResult = countResult.subtract(new BigDecimal(0.0000000001)).setScale(2,BigDecimal.ROUND_HALF_UP);
				}
			}
		}else if(name.equals("Fe<sub>2</sub>O<sub>3</sub>")){

			if( StringUtils.isNotBlank(resultMap.get("TFe<sub>2</sub>O<sub>3</sub>")) &&
					StringUtils.isNotBlank(resultMap.get("VF<sub>2</sub>O<sub>3</sub>"))&&
					StringUtils.isNotBlank(resultMap.get("样重m"))
					){
				BigDecimal TFe2O3  = getBigDecimal(resultMap.get("TFe<sub>2</sub>O<sub>3</sub>").trim());
				BigDecimal VF2O3  = getBigDecimal(resultMap.get("VF<sub>2</sub>O<sub>3</sub>").trim());
				BigDecimal m = getBigDecimal(resultMap.get("样重m").trim());
				//计算的核心公式结果
				BigDecimal countResult = TFe2O3.multiply(VF2O3).divide(m,10,BigDecimal.ROUND_HALF_UP);
				BigDecimal result1 = countResult.multiply(param100);
				int resultInt1  = result1.setScale( 0, BigDecimal.ROUND_DOWN ).intValue();
				if((resultInt1&1) == 1){  //如果结果为奇数
					endResult =  countResult.setScale(2,BigDecimal.ROUND_HALF_UP);
				}else{
					endResult = countResult.subtract(new BigDecimal(0.0000000001)).setScale(2,BigDecimal.ROUND_HALF_UP);
				}
			}
		}else if(name.equals("CaO")){
			if( StringUtils.isNotBlank(resultMap.get("TCaO")) &&
					StringUtils.isNotBlank(resultMap.get("VCaO"))&&
					StringUtils.isNotBlank(resultMap.get("样重m"))
					){
				BigDecimal TCaO  = getBigDecimal(resultMap.get("TCaO").trim());
				BigDecimal VCaO  = getBigDecimal(resultMap.get("VCaO").trim());
				BigDecimal m = getBigDecimal(resultMap.get("样重m").trim());
				//计算的核心公式结果
				BigDecimal countResult = TCaO.multiply(VCaO).divide(m,10,BigDecimal.ROUND_HALF_UP);
				BigDecimal result1 = countResult.multiply(param100);
				int resultInt1  = result1.setScale( 0, BigDecimal.ROUND_DOWN ).intValue();
				if((resultInt1&1) == 1){  //如果结果为奇数
					endResult =  countResult.setScale(2,BigDecimal.ROUND_HALF_UP);
				}else{
					endResult = countResult.subtract(new BigDecimal(0.00000000001)).setScale(2,BigDecimal.ROUND_HALF_UP);
				}
			}
		}else if(name.equals("MgO")){
			if( StringUtils.isNotBlank(resultMap.get("TMgO")) &&
					StringUtils.isNotBlank(resultMap.get("VMgO"))&&
					StringUtils.isNotBlank(resultMap.get("VCaO"))&&
					StringUtils.isNotBlank(resultMap.get("样重m"))
					){
				BigDecimal TMgO  = getBigDecimal(resultMap.get("TMgO").trim());
				BigDecimal VMgO  = getBigDecimal(resultMap.get("VMgO").trim());
				BigDecimal VCaO  = getBigDecimal(resultMap.get("VCaO").trim());
				BigDecimal m = getBigDecimal(resultMap.get("样重m").trim());
				//计算的核心公式结果
				BigDecimal countResult = TMgO.multiply(VMgO.subtract(VCaO)).divide(m,10,BigDecimal.ROUND_HALF_UP);
				BigDecimal result1 = countResult.multiply(param100);
				int resultInt1  = result1.setScale( 0, BigDecimal.ROUND_DOWN ).intValue();
				if((resultInt1&1) == 1){  //如果结果为奇数
					endResult =  countResult.setScale(2,BigDecimal.ROUND_HALF_UP);
				}else{
					endResult = countResult.subtract(new BigDecimal(0.0000000001)).setScale(2,BigDecimal.ROUND_HALF_UP);
				}
			}
		}else if(name.equals("TiO<sub>2</sub>")){
			if( StringUtils.isNotBlank(resultMap.get("TTiO<sub>2</sub>")) &&
					StringUtils.isNotBlank(resultMap.get("VCuSO<sub>4</sub>(II)"))&&
					StringUtils.isNotBlank(resultMap.get("K"))&&
					StringUtils.isNotBlank(resultMap.get("样重m"))
					){
				BigDecimal TTiO2  = getBigDecimal(resultMap.get("TTiO<sub>2</sub>").trim());
				BigDecimal VCuSO4_II  = getBigDecimal(resultMap.get("VCuSO<sub>4</sub>(II)").trim());
				BigDecimal K  = getBigDecimal(resultMap.get("K").trim());
				BigDecimal m = getBigDecimal(resultMap.get("样重m").trim());
				//计算的核心公式结果
				BigDecimal countResult = TTiO2.multiply(VCuSO4_II).multiply(K).divide(m,10,BigDecimal.ROUND_HALF_UP);
				BigDecimal result1 = countResult.multiply(param100);
				int resultInt1  = result1.setScale( 0, BigDecimal.ROUND_DOWN ).intValue();
				if((resultInt1&1) == 1){  //如果结果为奇数
					endResult =  countResult.setScale(2,BigDecimal.ROUND_HALF_UP);
				}else{
					endResult = countResult.subtract(new BigDecimal(0.00000000001)).setScale(2,BigDecimal.ROUND_HALF_UP);
				}
			}

		}else if(name.equals("重量法SO<sub>3</sub>")){
			if( StringUtils.isNotBlank(resultMap.get("烧重m2")) &&
					StringUtils.isNotBlank(resultMap.get("埚重m1"))&&
					StringUtils.isNotBlank(resultMap.get("空白m3"))&&
					StringUtils.isNotBlank(resultMap.get("样重m"))
					){
				BigDecimal m2  = getBigDecimal(resultMap.get("烧重m2").trim());
				BigDecimal m1  = getBigDecimal(resultMap.get("埚重m1").trim());
				BigDecimal m3  = getBigDecimal(resultMap.get("空白m3").trim());
				BigDecimal m = getBigDecimal(resultMap.get("样重m").trim());
				//计算的核心公式结果
				BigDecimal countResult =  m2.subtract(m1).subtract(m3).divide(m,10,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(0.343));
				endResult = countResult.multiply(param100).setScale(2,BigDecimal.ROUND_HALF_EVEN);
			}else{
				endResult = new BigDecimal(0);
			}
		}else if(name.equals("K<sub>2</sub>O")){
			if( StringUtils.isNotBlank(resultMap.get("CK<sub>2</sub>O")) &&
					StringUtils.isNotBlank(resultMap.get("V"))&&
					StringUtils.isNotBlank(resultMap.get("AK<sub>2</sub>O"))&&
					StringUtils.isNotBlank(resultMap.get("样重R2O"))
					){
				BigDecimal CK2O  = getBigDecimal(resultMap.get("CK<sub>2</sub>O").trim());
				BigDecimal V  = getBigDecimal(resultMap.get("V").trim());
				BigDecimal AK2O  = getBigDecimal(resultMap.get("AK<sub>2</sub>O").trim());
				BigDecimal mR20 = getBigDecimal(resultMap.get("样重R2O").trim());
				//计算的核心公式结果
				BigDecimal countResult = CK2O.multiply(V).multiply(AK2O).divide(mR20,10,BigDecimal.ROUND_HALF_UP).divide(param10000,10,BigDecimal.ROUND_HALF_UP);
				BigDecimal result1 = countResult.multiply(param100);
				int resultInt1  = result1.setScale( 0, BigDecimal.ROUND_DOWN ).intValue();
				if((resultInt1&1) == 1){  //如果结果为奇数
					endResult =  countResult.setScale(2,BigDecimal.ROUND_HALF_UP);
				}else{
					endResult = countResult.subtract(new BigDecimal(0.00000000001)).setScale(2,BigDecimal.ROUND_HALF_UP);
				}
			}
		}else if(name.equals("Na<sub>2</sub>O")){
			if( StringUtils.isNotBlank(resultMap.get("CNa<sub>2</sub>O")) &&
					StringUtils.isNotBlank(resultMap.get("V"))&&
					StringUtils.isNotBlank(resultMap.get("ANa<sub>2</sub>O"))&&
					StringUtils.isNotBlank(resultMap.get("样重R2O"))
					){
				BigDecimal CNa2O  = getBigDecimal(resultMap.get("CNa<sub>2</sub>O").trim());
				BigDecimal V  = getBigDecimal(resultMap.get("V").trim());
				BigDecimal ANa2O  = getBigDecimal(resultMap.get("ANa<sub>2</sub>O").trim());
				BigDecimal mR20 = getBigDecimal(resultMap.get("样重R2O").trim());
				//计算的核心公式结果
				BigDecimal countResult = CNa2O.multiply(V).multiply(ANa2O).divide(mR20,10,BigDecimal.ROUND_HALF_UP).divide(param10000,10,BigDecimal.ROUND_HALF_UP);
				BigDecimal result1 = countResult.multiply(param100);
				int resultInt1  = result1.setScale( 0, BigDecimal.ROUND_DOWN ).intValue();
				if((resultInt1&1) == 1){  //如果结果为奇数
					endResult =  countResult.setScale(2,BigDecimal.ROUND_HALF_UP);
				}else{
					endResult = countResult.subtract(new BigDecimal(0.00000000001)).setScale(2,BigDecimal.ROUND_HALF_UP);
				}
			}

		}else if(name.equals("MnO")){
			if( StringUtils.isNotBlank(resultMap.get("CMnO")) &&
					StringUtils.isNotBlank(resultMap.get("V"))&&
					StringUtils.isNotBlank(resultMap.get("AMnO"))&&
					StringUtils.isNotBlank(resultMap.get("样重R2O"))
					){
				BigDecimal CMnO  = getBigDecimal(resultMap.get("CMnO").trim());
				BigDecimal V  = getBigDecimal(resultMap.get("V").trim());
				BigDecimal AMnO  = getBigDecimal(resultMap.get("AMnO").trim());
				BigDecimal mR20 = getBigDecimal(resultMap.get("样重R2O").trim());
				//计算的核心公式结果
				BigDecimal countResult = CMnO.multiply(V).multiply(AMnO).divide(mR20,10,BigDecimal.ROUND_HALF_UP).divide(param10000,10,BigDecimal.ROUND_HALF_UP);
				BigDecimal result1 = countResult.multiply(param100);
				int resultInt1  = result1.setScale( 0, BigDecimal.ROUND_DOWN ).intValue();
				if((resultInt1&1) == 1){  //如果结果为奇数
					endResult =  countResult.setScale(2,BigDecimal.ROUND_HALF_UP);
				}else{
					endResult = countResult.subtract(new BigDecimal(0.00000000001)).setScale(2,BigDecimal.ROUND_HALF_UP);
				}
			}

		}else if(name.equals("Cl<sup>-</sup>")){
			if( StringUtils.isNotBlank(resultMap.get("T")) &&
					StringUtils.isNotBlank(resultMap.get("V2"))&&
					StringUtils.isNotBlank(resultMap.get("V1"))&&
					StringUtils.isNotBlank(resultMap.get("样重Cl"))
					){
				BigDecimal T  = getBigDecimal(resultMap.get("T").trim());
				BigDecimal V2  = getBigDecimal(resultMap.get("V2").trim());
				BigDecimal V1  = getBigDecimal(resultMap.get("V1").trim());
				BigDecimal mCl = getBigDecimal(resultMap.get("样重Cl").trim());
				//计算的核心公式结果
				BigDecimal countResult = T.multiply(V2.subtract(V1)).divide(mCl,10,BigDecimal.ROUND_HALF_UP).divide(param10,10,BigDecimal.ROUND_HALF_UP);
				BigDecimal result1 = countResult.multiply(param1000);
				int resultInt1  = result1.setScale( 0, BigDecimal.ROUND_DOWN ).intValue();
				if((resultInt1&1) == 1){  //如果结果为奇数
					endResult =  countResult.setScale(3,BigDecimal.ROUND_HALF_UP);
				}else{
					endResult = countResult.subtract(new BigDecimal(0.00000000001)).setScale(3,BigDecimal.ROUND_HALF_UP);
				}
			}

		}else if(name.equals("Mad1")){
			if( StringUtils.isNotBlank(resultMap.get("样重M1")) &&
					StringUtils.isNotBlank(resultMap.get("皿重M1"))&&
					StringUtils.isNotBlank(resultMap.get("烧重M1"))
					){
				BigDecimal YZ_M1  = getBigDecimal(resultMap.get("样重M1").trim());
				BigDecimal MZ_M1  = getBigDecimal(resultMap.get("皿重M1").trim());
				BigDecimal SZ_M1  = getBigDecimal(resultMap.get("烧重M1").trim());
				//计算的核心公式结果
				BigDecimal countResult = YZ_M1.add(MZ_M1).subtract(SZ_M1).divide(YZ_M1,10,BigDecimal.ROUND_HALF_UP);
				endResult = countResult.multiply(param100).setScale(3,BigDecimal.ROUND_HALF_EVEN);
			}
		}else if(name.equals("Mad2")){
			if( StringUtils.isNotBlank(resultMap.get("样重M2")) &&
					StringUtils.isNotBlank(resultMap.get("皿重M2"))&&
					StringUtils.isNotBlank(resultMap.get("烧重M2"))
					){
				BigDecimal YZ_M2  = getBigDecimal(resultMap.get("样重M2").trim());
				BigDecimal MZ_M2  = getBigDecimal(resultMap.get("皿重M2").trim());
				BigDecimal SZ_M2  = getBigDecimal(resultMap.get("烧重M2").trim());
				//计算的核心公式结果
				BigDecimal countResult = YZ_M2.add(MZ_M2).subtract(SZ_M2).divide(YZ_M2,10,BigDecimal.ROUND_HALF_UP);
				endResult = countResult.multiply(param100).setScale(3,BigDecimal.ROUND_HALF_EVEN);
			}

		}else if(name.equals("Aad1")){
			if( StringUtils.isNotBlank(resultMap.get("烧重A1")) &&
					StringUtils.isNotBlank(resultMap.get("皿重A1"))&&
					StringUtils.isNotBlank(resultMap.get("样重A1"))
					){
				BigDecimal SZ_A1  = getBigDecimal(resultMap.get("烧重A1").trim());
				BigDecimal MZ_A1  = getBigDecimal(resultMap.get("皿重A1").trim());
				BigDecimal YZ_A1  = getBigDecimal(resultMap.get("样重A1").trim());
				//计算的核心公式结果
				BigDecimal countResult = SZ_A1.subtract(MZ_A1).divide(YZ_A1,10,BigDecimal.ROUND_HALF_UP);
				endResult = countResult.multiply(param100).setScale(3,BigDecimal.ROUND_HALF_EVEN);
			}

		}else if(name.equals("Aad2")){
			if( StringUtils.isNotBlank(resultMap.get("烧重A2")) &&
					StringUtils.isNotBlank(resultMap.get("皿重A2"))&&
					StringUtils.isNotBlank(resultMap.get("样重A2"))
					){
				BigDecimal SZ_A2  = getBigDecimal(resultMap.get("烧重A2").trim());
				BigDecimal MZ_A2  = getBigDecimal(resultMap.get("皿重A2").trim());
				BigDecimal YZ_A2  = getBigDecimal(resultMap.get("样重A2").trim());
				//计算的核心公式结果
				BigDecimal countResult = SZ_A2.subtract(MZ_A2).divide(YZ_A2,10,BigDecimal.ROUND_HALF_UP);
				endResult = countResult.multiply(param100).setScale(3,BigDecimal.ROUND_HALF_EVEN);
			}

		}else if(name.equals("焦渣")){
			if( StringUtils.isNotBlank(resultMap.get("焦渣特征"))
					){
				endResult  = getBigDecimal(resultMap.get("焦渣特征").trim());
			}

		}

		/*else if(name.equals("St,ad")){
			if( StringUtils.isNotBlank(resultMap.get("显示值"))
					){
				endResult  = getBigDecimal(resultMap.get("显示值").trim());
			}
		}*/

		return endResult==null?"":endResult.toString();
	}

	/**
	 * 求激光粒度分析
	 * @param resultMap
	 * @return
	 */
	public static String countJGLD(Map<String, String> resultMap) {
		String count = "";

		String D10="";
		String D50="";
		String D90="";
		if( StringUtils.isNotBlank(resultMap.get("D10"))){
			D10 = resultMap.get("D10").trim();
		}
		if( StringUtils.isNotBlank(resultMap.get("D50"))){
			D50  = resultMap.get("D50").trim();
		}
		if( StringUtils.isNotBlank(resultMap.get("D90"))){
			D90  = resultMap.get("D90").trim();
		}

		count = "D10="+D10+" \n D50="+D50+" \n D90="+D90;
		return  count;
	}

	/**
	 * 求可磨
	 * @param resultMap
	 * @return
	 */
	public static String countKm(Map<String, String> resultMap) {
		String count = "";

		String HGI="";
		String ZYL="";  //制样率
		if( StringUtils.isNotBlank(resultMap.get("HGI"))){
			HGI = resultMap.get("HGI").trim();
		}
		if( StringUtils.isNotBlank(resultMap.get("制样率"))){
			ZYL  = resultMap.get("制样率").trim();
		}

		count = "HGI="+HGI+" \n 制样率="+ZYL+"%";
		return  count;
	}


	/**
	 * 求辊磨
	 * @param resultMap
	 * @return
	 */
	public static String countGm(Map<String, String> resultMap) {
		String count = "";

		String TMF="";
		String TWF="";
		if( StringUtils.isNotBlank(resultMap.get("TMF"))){
			TMF = resultMap.get("TMF").trim();
		}
		if( StringUtils.isNotBlank(resultMap.get("TWF(kg/t)"))){
			TWF  = resultMap.get("TWF(kg/t)").trim();
		}

		count = "TMF="+TMF+" \n TWF(kg/t)="+TWF;
		return  count;
	}

	/**
	 * 求塑性指数
	 * @param resultMap
	 * @return
	 */
	public static String countSxzs(Map<String, String> resultMap) {
		String count = "";

		String YX="";
		String SX="";
		String SXZS="";
		if( StringUtils.isNotBlank(resultMap.get("液限"))){
			YX = resultMap.get("液限").trim();
		}
		if( StringUtils.isNotBlank(resultMap.get("塑限"))){
			SX  = resultMap.get("塑限").trim();
		}
		if( StringUtils.isNotBlank(resultMap.get("塑性指数"))){
			SXZS  = resultMap.get("塑性指数").trim();
		}
		count = "液限="+YX+" \n 塑限="+SX+" \n 塑性指数="+SXZS;
		return  count;
	}


	/**
	 * 求SO3
	 * @param resultMap
	 * @param countMap
	 * @return
	 */
	public static String countSO3(Map<String, String> resultMap, Map<String, String> countMap) {
		BigDecimal count = null;
		if( StringUtils.isNotBlank(countMap.get("重量法SO<sub>3</sub>")) &&
				StringUtils.isNotBlank(resultMap.get("显示值"))&&
				StringUtils.isNotBlank(resultMap.get("样重SO<sub>3</sub>"))
				){
			BigDecimal weightSO3 = getBigDecimal(countMap.get("重量法SO<sub>3</sub>"));
			BigDecimal displaySO3= getBigDecimal(resultMap.get("显示值").trim());
			BigDecimal mSO3= getBigDecimal(resultMap.get("样重SO<sub>3</sub>").trim());
			BigDecimal elseResult = displaySO3.multiply(new BigDecimal(2.5));
			BigDecimal countResult = weightSO3.compareTo(new BigDecimal(0))==1?
					weightSO3:elseResult;
			BigDecimal result1 = countResult.multiply(param100);
			int resultInt1  = result1.setScale( 0, BigDecimal.ROUND_DOWN ).intValue();
			if((resultInt1&1) == 1){  //如果结果为奇数
				BigDecimal jsResult =  weightSO3.compareTo(new BigDecimal(0))==1?
						weightSO3:elseResult.multiply(mSO3).divide(mSO3,10,BigDecimal.ROUND_HALF_UP);
				count =  jsResult.setScale(2,BigDecimal.ROUND_HALF_UP);
			}else{
				BigDecimal osResult =  weightSO3.compareTo(new BigDecimal(0))==1?
						weightSO3:elseResult.multiply(mSO3).divide(mSO3,10,BigDecimal.ROUND_HALF_UP);
				count = osResult.subtract(new BigDecimal(0.00000000001)).setScale(2,BigDecimal.ROUND_HALF_UP);
			}

		}else if(StringUtils.isNotBlank(resultMap.get("显示值"))){
			BigDecimal displaySO3= getBigDecimal(resultMap.get("显示值").trim());
			count = displaySO3.multiply(new BigDecimal(2.5)).setScale(2, BigDecimal.ROUND_HALF_EVEN);
		}
		//如果有值按照“四舍六入五留双”修约规则保留至小数后两位
		return count==null?"":count.toString();
	}


	/**
	 *  求合量  L.O.I+SiO2+(Al2O3+TiO2)+Al2O3+Fe2O3+CaO+MgO+TiO2+K2O+Na2O+MnO+SO3
	 * @param countMap
	 * @return
	 */
	public static String countHL(Map<String, String> countMap) {
		BigDecimal count = new BigDecimal(0);
		List<String> list = new ArrayList<>();
		list.add(StringUtils.isEmpty(countMap.get("L.O.I"))?"0":countMap.get("L.O.I"));
		list.add(StringUtils.isEmpty(countMap.get("SiO<sub>2</sub>"))?"0":countMap.get("SiO<sub>2</sub>"));
//		list.add(countMap.get("Al2O3+TiO2"));
		list.add(StringUtils.isEmpty(countMap.get("Al<sub>2</sub>O<sub>3</sub>"))?"0":countMap.get("Al<sub>2</sub>O<sub>3</sub>"));
		list.add(StringUtils.isEmpty(countMap.get("Fe<sub>2</sub>O<sub>3</sub>"))?"0":countMap.get("Fe<sub>2</sub>O<sub>3</sub>"));
		list.add(StringUtils.isEmpty(countMap.get("CaO"))?"0":countMap.get("CaO"));
		list.add(StringUtils.isEmpty(countMap.get("MgO"))?"0":countMap.get("MgO"));
		list.add(StringUtils.isEmpty(countMap.get("TiO<sub>2</sub>"))?"0":countMap.get("TiO<sub>2</sub>"));
		list.add(StringUtils.isEmpty(countMap.get("K<sub>2</sub>O"))?"0":countMap.get("K<sub>2</sub>O"));
		list.add(StringUtils.isEmpty(countMap.get("Na<sub>2</sub>O"))?"0":countMap.get("Na<sub>2</sub>O"));
		list.add(StringUtils.isEmpty(countMap.get("MnO"))?"0":countMap.get("MnO"));
		list.add(StringUtils.isEmpty(countMap.get("SO<sub>3</sub>"))?"0":countMap.get("SO<sub>3</sub>"));
		for(String s:list) {
			count = count.add(new BigDecimal(s));
		}
		return count.setScale(2,BigDecimal.ROUND_HALF_EVEN).toString();
	}

	/**
	 * 求KH (CaO - 1.65*{Al2O3+TiO2} * Fe2O3) / 2.8 / SiO2
	 * @param countMap
	 * @return
	 */
	public static String countKH(Map<String, String> countMap) {
		BigDecimal KH = null;
		if( StringUtils.isNotBlank(countMap.get("Ca0")) &&
				StringUtils.isNotBlank(countMap.get("Al<sub>2</sub>O<sub>3</sub>+TiO<sub>2</sub>"))&&
				StringUtils.isNotBlank(countMap.get("Fe<sub>2</sub>O<sub>3</sub>"))&&
				StringUtils.isNotBlank(countMap.get("SiO<sub>2</sub>"))
				){
			BigDecimal CaO = getBigDecimal(countMap.get("CaO"));
			BigDecimal Al2O3_TiO2= getBigDecimal(countMap.get("Al<sub>2</sub>O<sub>3</sub>+TiO<sub>2</sub>"));
			BigDecimal Fe2O3 = getBigDecimal(countMap.get("Fe<sub>2</sub>O<sub>3</sub>"));
			BigDecimal SiO2 = getBigDecimal(countMap.get("SiO<sub>2</sub>"));
			KH =CaO.subtract(new BigDecimal(1.65).multiply(Al2O3_TiO2)).subtract(new BigDecimal(0.35).multiply(Fe2O3)).divide(new BigDecimal(2.8),10,BigDecimal.ROUND_HALF_UP).divide(SiO2,10,BigDecimal.ROUND_HALF_UP);
		}
		return KH==null?"":KH.setScale(3,BigDecimal.ROUND_HALF_EVEN).toString();
	}

	/**
	 * 求SM  SiO2/ ({Al2O3+TiO2} + Fe2O3)
	 * @param countMap
	 * @return
	 */
	public static String countSM(Map<String, String> countMap) {
		BigDecimal SM = null;
		if( StringUtils.isNotBlank(countMap.get("SiO<sub>2</sub>")) &&
				StringUtils.isNotBlank(countMap.get("Al<sub>2</sub>O<sub>3</sub>+TiO<sub>2</sub>"))&&
				StringUtils.isNotBlank(countMap.get("Fe<sub>2</sub>O<sub>3</sub>"))
				){
			BigDecimal SiO2 = getBigDecimal(countMap.get("SiO<sub>2</sub>"));
			BigDecimal Al2O3_TiO2= getBigDecimal(countMap.get("Al<sub>2</sub>O<sub>3</sub>+TiO<sub>2</sub>"));
			BigDecimal Fe2O3 = getBigDecimal(countMap.get("Fe<sub>2</sub>O<sub>3</sub>"));
			SM = SiO2.divide(Al2O3_TiO2.add(Fe2O3),10,BigDecimal.ROUND_HALF_UP);
		}
		return SM==null?"":SM.setScale(2,BigDecimal.ROUND_HALF_EVEN).toString();
	}

	/**
	 * 求AM  「Al2O3+TiO2」/ Fe2O3
	 * @param countMap
	 * @return
	 */
	public static String countAM(Map<String, String> countMap) {
		BigDecimal AM = null;
		if( StringUtils.isNotBlank(countMap.get("Al<sub>2</sub>O<sub>3</sub>+TiO<sub>2</sub>"))&&
				StringUtils.isNotBlank(countMap.get("Fe<sub>2</sub>O<sub>3</sub>"))
				){
			BigDecimal Al2O3_TiO2= getBigDecimal(countMap.get("Al<sub>2</sub>O<sub>3</sub>+TiO<sub>2</sub>"));
			BigDecimal Fe2O3 = getBigDecimal(countMap.get("Fe<sub>2</sub>O<sub>3</sub>"));
			AM = Al2O3_TiO2.divide(Fe2O3,10,BigDecimal.ROUND_HALF_UP);
		}
		return AM==null?"":AM.setScale(2,BigDecimal.ROUND_HALF_EVEN).toString();
	}

	/**
	 * 求易烧性等级
	 * @param resultMap 输入集合
	 * @param countMap  输出集合
	 * @return
	 */
	public static String countBurnupLevel(Map<String, String> resultMap, Map<String, String> countMap) {
		String endResult = "";
		if( StringUtils.isNotBlank(resultMap.get("fCaO_1450"))&&
				StringUtils.isNotBlank(countMap.get("KH"))
				){
			BigDecimal fCaO_1450  = getBigDecimal(resultMap.get("fCaO_1450").trim());
			BigDecimal KH= getBigDecimal(countMap.get("KH").trim());
			BigDecimal E = new BigDecimal(45).multiply(KH).subtract(new BigDecimal(37.4));
			BigDecimal D = new BigDecimal(35).multiply(KH).subtract(new BigDecimal(29.3));
			BigDecimal C = new BigDecimal(26.25).multiply(KH).subtract(new BigDecimal(22.15));
			BigDecimal B = new BigDecimal(18.75).multiply(KH).subtract(new BigDecimal(16));
			if(fCaO_1450.compareTo(E) == 1){
				endResult = "E";
			}else if (fCaO_1450.compareTo(D) == 1){
				endResult =  "D";
			}else if (fCaO_1450.compareTo(C) == 1){
				endResult =  "C";
			}else if (fCaO_1450.compareTo(B) == 1){
				endResult =  "B";
			}else{
				endResult =  "A";
			}
		}
		return  endResult;
	}






	/**
	 * 求报出_Mad  （Mad1 + Mad2 ）/ 2
	 * @param countMap
	 * @return
	 */
	public static String countBCMad(Map<String, String> countMap) {
		BigDecimal BC_Mad = null;
		if( StringUtils.isNotBlank(countMap.get("Mad1"))&&
				StringUtils.isNotBlank(countMap.get("Mad2"))
				){
			BigDecimal Mad1= getBigDecimal(countMap.get("Mad1"));
			BigDecimal Mad2= getBigDecimal(countMap.get("Mad2"));
			//计算Mad1 和 Mad2 的平均值
			BC_Mad = Mad1.add(Mad2).divide(new BigDecimal(2),10,BigDecimal.ROUND_HALF_UP);
		}

		return  BC_Mad==null?"":BC_Mad.toString();
	}

	/**
	 * 求Mad  报出_Mad *100 判断奇偶数判断后的结果
	 * @param countMap
	 * @return
	 */
	public static String countMad(Map<String, String> countMap) {
		BigDecimal Mad = null;
		if( StringUtils.isNotBlank(countMap.get("报出_Mad"))
				){
			BigDecimal BC_Mad= getBigDecimal(countMap.get("报出_Mad"));
			//判断奇偶数的最终值
			BigDecimal result1 = BC_Mad.multiply(param100);
			int resultInt1  = result1.setScale( 0, BigDecimal.ROUND_DOWN ).intValue();

			if((resultInt1&1) == 1){  //如果结果为奇数
				Mad =  BC_Mad.setScale(2,BigDecimal.ROUND_HALF_UP);
			}else{
				Mad = BC_Mad.subtract(new BigDecimal(0.00000000001)).setScale(2,BigDecimal.ROUND_HALF_UP);
			}
		}
		return  Mad==null?"":Mad.setScale(2,BigDecimal.ROUND_HALF_EVEN).toString();
	}

	/**
	 * 求报出_Aad  (Aad1 + Aad2)/2
	 * @param countMap
	 * @return
	 */
	public static String countBCAad(Map<String, String> countMap) {
		BigDecimal BC_Aad = null;
		if( StringUtils.isNotBlank(countMap.get("Aad1")) &&
				StringUtils.isNotBlank(countMap.get("Aad2"))
				){
			BigDecimal Aad1= getBigDecimal(countMap.get("Aad1"));
			BigDecimal Aad2= getBigDecimal(countMap.get("Aad2"));
			//计算Mad1 和 Mad2 的平均值
			BC_Aad = Aad1.add(Aad2).divide(new BigDecimal(2),10,BigDecimal.ROUND_HALF_UP);
		}

		return  BC_Aad==null?"":BC_Aad.toString();
	}

	/**
	 * 求Aad  报出_Aad *100 判断奇偶数判断后的结果
	 * @param countMap
	 * @return
	 */
	public static String countAad(Map<String, String> countMap) {
		BigDecimal Aad = null;
		if( StringUtils.isNotBlank(countMap.get("报出_Aad"))
				){
			BigDecimal BC_Aad= getBigDecimal(countMap.get("报出_Aad"));
			//判断奇偶数的最终值
			BigDecimal result1 = BC_Aad.multiply(param100);
			int resultInt1  = result1.setScale( 0, BigDecimal.ROUND_DOWN ).intValue();
			if((resultInt1&1) == 1){  //如果结果为奇数
				Aad =  BC_Aad.setScale(2,BigDecimal.ROUND_HALF_UP);
			}else{
				Aad = BC_Aad.subtract(new BigDecimal(0.00000000001)).setScale(2,BigDecimal.ROUND_HALF_UP);
			}
		}
		return  Aad==null?"":Aad.setScale(2,BigDecimal.ROUND_HALF_EVEN).toString();
	}

	/**
	 * 求Vad1
	 * @param resultMap
	 * @param countMap
	 * @return
	 */
	public static String countVad1(Map<String, String> resultMap, Map<String, String> countMap) {
		BigDecimal count = null;
		if( StringUtils.isNotBlank(resultMap.get("样重V1")) &&
				StringUtils.isNotBlank(resultMap.get("皿重V1")) &&
				StringUtils.isNotBlank(resultMap.get("烧重V1")) &&
				StringUtils.isNotBlank(countMap.get("报出_Mad"))
				){
			BigDecimal YZ_V1  = getBigDecimal(resultMap.get("样重V1").trim());
			BigDecimal MZ_V1  = getBigDecimal(resultMap.get("皿重V1").trim());
			BigDecimal SZ_V1  = getBigDecimal(resultMap.get("烧重V1").trim());
			BigDecimal BC_Mad  = getBigDecimal(countMap.get("报出_Mad"));
			//计算的核心公式结果
			BigDecimal countResult = YZ_V1.add(MZ_V1).subtract(SZ_V1).divide(YZ_V1,10,BigDecimal.ROUND_HALF_UP);
			count = countResult.multiply(param100).subtract(BC_Mad);

		}

		return  count==null?"":count.setScale(3,BigDecimal.ROUND_HALF_EVEN).toString();
	}

	/**
	 * 求Vad2
	 * @param resultMap
	 * @param countMap
	 * @return
	 */
	public static String countVad2(Map<String, String> resultMap, Map<String, String> countMap) {
		BigDecimal count = null;
		if( StringUtils.isNotBlank(resultMap.get("样重V2")) &&
				StringUtils.isNotBlank(resultMap.get("皿重V2")) &&
				StringUtils.isNotBlank(resultMap.get("烧重V2")) &&
				StringUtils.isNotBlank(countMap.get("报出_Mad"))
				){
			BigDecimal YZ_V2  = getBigDecimal(resultMap.get("样重V2"));
			BigDecimal MZ_V2  = getBigDecimal(resultMap.get("皿重V2"));
			BigDecimal SZ_V2  = getBigDecimal(resultMap.get("烧重V2"));
			BigDecimal BC_Mad  = getBigDecimal(countMap.get("报出_Mad"));
			//计算的核心公式结果
			BigDecimal countResult = YZ_V2.add(MZ_V2).subtract(SZ_V2).divide(YZ_V2,10,BigDecimal.ROUND_HALF_UP);
			count = countResult.multiply(param100).subtract(BC_Mad);
		}
		return  count==null?"":count.setScale(3,BigDecimal.ROUND_HALF_EVEN).toString();
	}

	/**
	 * 求报出_Vad  (Vad1+ Vad2)/2
	 * @param countMap
	 * @return
	 */
	public static String countBCVad(Map<String, String> countMap) {
		BigDecimal BC_Vad = null;
		if( StringUtils.isNotBlank(countMap.get("Vad1")) &&
				StringUtils.isNotBlank(countMap.get("Vad2"))
				){
			BigDecimal Vad1= getBigDecimal(countMap.get("Vad1"));
			BigDecimal Vad2= getBigDecimal(countMap.get("Vad2"));
			//计算Vad1 和 Vad2 的平均值
			BC_Vad = Vad1.add(Vad2).divide(new BigDecimal(2),10,BigDecimal.ROUND_HALF_UP);
		}
		return  BC_Vad==null?"":BC_Vad.toString();
	}

	/**
	 * 求Vad  报出_Vad *100 判断奇偶数判断后的结果
	 * @param countMap
	 * @return
	 */
	public static String countVad(Map<String, String> countMap) {
		BigDecimal Vad = null;
		if( StringUtils.isNotBlank(countMap.get("报出_Vad"))
				){
			BigDecimal BC_Vad= getBigDecimal(countMap.get("报出_Vad"));
			//判断奇偶数的最终值
			BigDecimal result1 = BC_Vad.multiply(param100);
			int resultInt1  = result1.setScale( 0, BigDecimal.ROUND_DOWN ).intValue();

			if((resultInt1&1) == 1){  //如果结果为奇数
				Vad =  BC_Vad.setScale(2,BigDecimal.ROUND_HALF_UP);
			}else{
				Vad = BC_Vad.subtract(new BigDecimal(0.00000000001)).setScale(2,BigDecimal.ROUND_HALF_UP);
			}
		}
		return  Vad==null?"":Vad.setScale(2,BigDecimal.ROUND_HALF_EVEN).toString();
	}

	/**
	 * 求Vdaf  Vad *100/(100-Mad-Aad)
	 * @param countMap
	 * @return
	 */
	public static String countVdaf(Map<String, String> countMap) {
		BigDecimal Vdaf = null;
		if( StringUtils.isNotBlank(countMap.get("Vad")) &&
				StringUtils.isNotBlank(countMap.get("Mad")) &&
				StringUtils.isNotBlank(countMap.get("Aad"))
				){
			BigDecimal Vad= getBigDecimal(countMap.get("Vad"));
			BigDecimal Mad= getBigDecimal(countMap.get("Mad"));
			BigDecimal Aad= getBigDecimal(countMap.get("Aad"));
			Vdaf = Vad.multiply(param100).multiply(param100.subtract(Mad).subtract(Aad));
		}
		return  Vdaf==null?"":Vdaf.toString();
	}

	/**
	 * 求K1,
	 * @param countMap
	 * @return
	 */
	public static String countK1_(Map<String, String> countMap) {
		BigDecimal K1_= null;
		if( StringUtils.isNotBlank(countMap.get("Vdaf"))
				){
			BigDecimal Vdaf= getBigDecimal(countMap.get("Vdaf"));
			K1_=
					Vdaf.compareTo(new BigDecimal(62))==1?new BigDecimal(61.5):(
							Vdaf.compareTo(new BigDecimal(56))==1?new BigDecimal(63):(
									Vdaf.compareTo(new BigDecimal(49))==1?new BigDecimal(65):(
											Vdaf.compareTo(new BigDecimal(45))==1?new BigDecimal(67):(
													Vdaf.compareTo(new BigDecimal(37))==1?new BigDecimal(68.5):
															new BigDecimal(0)
											))));
		}

		return  K1_==null?"":K1_.setScale(1,BigDecimal.ROUND_HALF_EVEN).toString();
	}

	/**
	 * 求K  if 焦渣特征=1 JZB1  if 焦渣特征=1.5 JZB1_5 f 焦渣特征=2 JZB2
	 * @param resultMap
	 * @param countMap
	 * @return
	 */
	public static String countK(Map<String, String> resultMap, Map<String, String> countMap) {
		String count = "";
		if( StringUtils.isNotBlank(resultMap.get("焦渣特征")) &&
				StringUtils.isNotBlank(countMap.get("Vdaf"))
				){
			String JZTZ= resultMap.get("焦渣特征").trim();
			BigDecimal Vdaf= getBigDecimal(countMap.get("Vdaf"));
			//获取焦渣特征序号对应的值
			Map<String, String>  map = JZTZCountUtil.getJZTZ(Vdaf);
			if(JZTZ.equals("1")){
				count = map.get(JZTZ);
			}else if(JZTZ.equals("1.5")){
				count = map.get(JZTZ);
			}else if(JZTZ.equals("2")){
				count = map.get(JZTZ);
			}else if(JZTZ.equals("2.5")){
				count = map.get(JZTZ);
			}else if(JZTZ.equals("3")){
				count = map.get(JZTZ);
			}else if(JZTZ.equals("3.5")){
				count = map.get(JZTZ);
			}else if(JZTZ.equals("4")){
				count = map.get(JZTZ);
			}else if(JZTZ.equals("4.5")){
				count = map.get(JZTZ);
			}else if(JZTZ.equals("5")){
				count = map.get(JZTZ);
			}else if(JZTZ.equals("5.5")){
				count = map.get(JZTZ);
			}else if(JZTZ.equals("6")){
				count = map.get(JZTZ);
			}else if(JZTZ.equals("6.5")){
				count = map.get(JZTZ);
			}else if(JZTZ.equals("7")){
				count = map.get(JZTZ);
			}else if(JZTZ.equals("7.5")){
				count = map.get(JZTZ);
			}else if(JZTZ.equals("8")){
				count = map.get(JZTZ);
			}else{
				count = "false";
			}
		}

		return  count;
	}

	/**
	 * 求Vdaf判断  Vdaf<35?1:0
	 * @param countMap
	 * @return
	 */
	public static String countVdafPD(Map<String, String> countMap) {
		Integer VdafPD = null;
		if( StringUtils.isNotBlank(countMap.get("Vdaf"))
				){
			BigDecimal Vdaf= getBigDecimal(countMap.get("Vdaf"));
			VdafPD = Vdaf.compareTo(new BigDecimal(35))==-1?1:0;
		}
		return VdafPD==null?"":VdafPD.toString();
	}

	/**
	 * 求Mad判断  Mad>3?1:0
	 * @param countMap
	 * @return
	 */
	public static String countMadPD(Map<String, String> countMap) {
		Integer MadPD = null;
		if( StringUtils.isNotBlank(countMap.get("报出_Mad"))
				){
			BigDecimal BC_Mad= getBigDecimal(countMap.get("报出_Mad"));
			MadPD = BC_Mad.compareTo(new BigDecimal(3))==1?1:0;
		}
		return  MadPD==null?"":MadPD.toString();
	}

	/**
	 * 求40Mad 0或1     Vdaf判断* Mad判断
	 * @param countMap
	 * @return
	 */
	public static String count40Mad0Or1(Map<String, String> countMap) {
		BigDecimal count = null;
		if( StringUtils.isNotBlank(countMap.get("Vdaf判断")) &&
				StringUtils.isNotBlank(countMap.get("Mad判断"))
				){
			BigDecimal VdafPD= getBigDecimal(countMap.get("Vdaf判断"));
			BigDecimal MadPD= getBigDecimal(countMap.get("Mad判断"));
			count = VdafPD.multiply(MadPD);
		}
		return  count==null?"":count.toString();
	}

	/**
	 * 求Ad
	 * @param countMap
	 * @return
	 */
	public static String countAd(Map<String, String> countMap) {
		BigDecimal count = null;
		if( StringUtils.isNotBlank(countMap.get("报出_Aad")) &&
				StringUtils.isNotBlank(countMap.get("报出_Mad"))
				){
			BigDecimal BC_Aad= getBigDecimal(countMap.get("报出_Aad"));
			BigDecimal BC_Mad= getBigDecimal(countMap.get("报出_Mad"));
			if(BC_Mad.compareTo(param100)!=0){
				count = BC_Aad.multiply(param100).divide(param100.subtract(BC_Mad),10,BigDecimal.ROUND_HALF_UP);
			}
		}
		return  count==null?"":count.toString();
	}

	/**
	 * 求Ad系数0.1或0   if Ad>20 0.1 else 0
	 * @param countMap
	 * @return
	 */
	public static String countAdXS(Map<String, String> countMap) {
		BigDecimal count = null;
		if( StringUtils.isNotBlank(countMap.get("Ad"))
				){
			BigDecimal Ad= getBigDecimal(countMap.get("Ad"));
			count =
					Ad.compareTo(new BigDecimal(20))==1?new BigDecimal(0.1):new BigDecimal(0);
		}

		return  count==null?"":count.toString();
	}

	public static String countVdafXS(Map<String, String> countMap) {
		Double count = null;
		if( StringUtils.isNotBlank(countMap.get("Ad"))
				){
			BigDecimal Ad= getBigDecimal(countMap.get("Ad"));
			count =
					Ad.compareTo(new BigDecimal(30))==1?0.8:(
							Ad.compareTo(new BigDecimal(25))==1?0.85:(
									Ad.compareTo(new BigDecimal(20))==1?0.95:(
											Ad.compareTo(new BigDecimal(15))==1?0.8:(
													Ad.compareTo(new BigDecimal(10))==1?0.9:
															0.95
											))));
		}
		return  count==null?"":count.toString();
	}

	/**
	 * 求V，daf  [Vdaf系数0.8~0.95]* Vdaf- [Ad系数0.1或0]*Ad
	 * @param countMap
	 * @return
	 */
	public static String countV_daf(Map<String, String> countMap) {
		BigDecimal count = null;
		if( StringUtils.isNotBlank(countMap.get("Vdaf系数0.8~0.95")) &&
				StringUtils.isNotBlank(countMap.get("Vdaf")) &&
				StringUtils.isNotBlank(countMap.get("Ad系数0.1或0")) &&
				StringUtils.isNotBlank(countMap.get("Ad"))
				){
			BigDecimal VdafXS= getBigDecimal(countMap.get("Vdaf系数0.8~0.95"));
			BigDecimal Vdaf= getBigDecimal(countMap.get("Vdaf"));
			BigDecimal AdXS= getBigDecimal(countMap.get("Ad系数0.1或0"));
			BigDecimal Ad= getBigDecimal(countMap.get("Ad"));
			count = VdafXS.multiply(Vdaf).subtract(AdXS.multiply(Ad));
		}

		return  count==null?"":count.toString();
	}

	/**
	 * 求K0，  if V，daf >8 8500 if V，daf >5.5 8400 if V，daf >3 8300  else 8200
	 * @param countMap
	 * @return
	 */
	public static String countK0_(Map<String, String> countMap) {
		BigDecimal count = null;
		if( StringUtils.isNotBlank(countMap.get("V,daf"))
				){
			BigDecimal V_daf= getBigDecimal(countMap.get("V,daf"));
			count =
					V_daf.compareTo(new BigDecimal(8))==1?new BigDecimal(8500):(
							V_daf.compareTo(new BigDecimal(5.5))==1?new BigDecimal(8400):(
									V_daf.compareTo(new BigDecimal(3))==1?new BigDecimal(8300):
											new BigDecimal(8200)
							));
		}

		return  count==null?"":count.toString();
	}

	/**
	 * 求Qnet,ad MJ/kg
	 * @param countMap
	 * @return
	 */
	public static String countQnet_adMJ_kg(Map<String, String> resultMap, Map<String, String> countMap) {
		BigDecimal count = null;
		if( StringUtils.isNotBlank(resultMap.get("烟无褐123")) &&
				StringUtils.isNotBlank(countMap.get("K1,")) &&
				StringUtils.isNotBlank(countMap.get("报出_Mad")) &&
				StringUtils.isNotBlank(countMap.get("报出_Aad")) &&
				StringUtils.isNotBlank(countMap.get("报出_Vad")) &&
				StringUtils.isNotBlank(countMap.get("K")) &&
				StringUtils.isNotBlank(countMap.get("40Mad 0或1")) &&
				StringUtils.isNotBlank(countMap.get("K0,"))
				){
			BigDecimal YWH_123= getBigDecimal(resultMap.get("烟无褐123").trim());
			BigDecimal K1_= getBigDecimal(countMap.get("K1,"));
			BigDecimal BC_Mad= getBigDecimal(countMap.get("报出_Mad"));
			BigDecimal BC_Aad= getBigDecimal(countMap.get("报出_Aad"));
			BigDecimal BC_Vad= getBigDecimal(countMap.get("报出_Vad"));
			BigDecimal K= getBigDecimal(countMap.get("K"));
			BigDecimal _40Mad_0_1= getBigDecimal(countMap.get("40Mad 0或1"));
			BigDecimal K0_= getBigDecimal(countMap.get("K0,"));
			BigDecimal value = null;
			if(YWH_123.compareTo(new BigDecimal(3))==0){
				value =param100.multiply(K1_).subtract(K1_.add(new BigDecimal(6)).multiply(BC_Mad.add(BC_Aad)))
						.subtract(BC_Vad);
			} else if(YWH_123.compareTo(new BigDecimal(1))==0){
				value =param100.multiply(K).subtract(K.add(new BigDecimal(6)).multiply(BC_Mad.add(BC_Aad)))
						.subtract(new BigDecimal(3).multiply(BC_Vad))
						.subtract(new BigDecimal(40).multiply(BC_Mad).multiply(_40Mad_0_1));
			}else if(YWH_123.compareTo(new BigDecimal(2))==0){
				value =K0_.subtract(new BigDecimal(86).multiply(BC_Mad))
						.subtract(new BigDecimal(92).multiply(BC_Aad))
						.subtract(new BigDecimal(24).multiply(BC_Vad));
			}
			count = value.multiply(new BigDecimal(4.1816)).divide(param1000,10,BigDecimal.ROUND_HALF_UP);

		}
		return  count==null?"":count.setScale(2,BigDecimal.ROUND_HALF_EVEN).toString();
	}

	/**
	 * 求工业分析
	 * @param countMap
	 * @return
	 */
	public static String countGYFX(Map<String, String> countMap) {
		String count = "";
		String Mad= "";
		String Aad= "";
		String Vad= "";
		String Qnet_ad_MJ_kg= "";
		String JZ= "";

		if( StringUtils.isNotBlank(countMap.get("Mad"))){
			Mad= getBigDecimal(countMap.get("Mad")).toString();
		}
		if( StringUtils.isNotBlank(countMap.get("Aad"))){
			Aad= getBigDecimal(countMap.get("Aad")).toString();
		}
		if( StringUtils.isNotBlank(countMap.get("Vad"))){
			Vad= getBigDecimal(countMap.get("Vad")).toString();
		}
		if( StringUtils.isNotBlank(countMap.get("Qnet,ad MJ/kg"))){
			Qnet_ad_MJ_kg= getBigDecimal(countMap.get("Qnet,ad MJ/kg")).toString();
		}
		if( StringUtils.isNotBlank(countMap.get("焦渣"))){
			JZ= getBigDecimal(countMap.get("焦渣")).toString();
		}
		count = "Mad="+Mad+"  \n Aad="+Aad+"  \n Vad="+Vad+"  \n Qnet,ad MJ/kg="+Qnet_ad_MJ_kg+"  \n 焦渣="+JZ;
		return  count;
	}



	/**
	 * 求易磨性等级
	 * @param resultMap
	 * @return
	 */
	public static String countYMXGrade(Map<String, String> resultMap) {
		String count = "";
		if( StringUtils.isNotBlank(resultMap.get("易磨性(kWh/t)"))
				){
			BigDecimal YMX_kWh_t  = getBigDecimal(resultMap.get("易磨性(kWh/t)"));
			if(YMX_kWh_t.compareTo(new BigDecimal(18))==1){
				count =  "E";
			}else if(YMX_kWh_t.compareTo(new BigDecimal(13))==1){
				count =  "D";
			}else if(YMX_kWh_t.compareTo(new BigDecimal(10))==1){
				count =  "C";
			}else if(YMX_kWh_t.compareTo(new BigDecimal(8))==1){
				count =  "B";
			}else{
				count =  "A";
			}
			String YMX_kWh_t_str = "";
			if(YMX_kWh_t != null){
				YMX_kWh_t_str = YMX_kWh_t.toString();
			}


			count = "易磨性值="+YMX_kWh_t_str+" \n 易磨性等级="+count;
		}
		return count;

	}

	/**
	 * 求易磨性校验码
	 * @param resultMap
	 * @return
	 */
	public static String countYMXCode(Map<String, String> resultMap) {
		String count = "";
		if( StringUtils.isNotBlank(resultMap.get("G")) &&
				StringUtils.isNotBlank(resultMap.get("P80")) &&
				StringUtils.isNotBlank(resultMap.get("F80")) &&
				StringUtils.isNotBlank(resultMap.get("易磨性(kWh/t)")) &&
				StringUtils.isNotBlank(resultMap.get("易磨性(MJ/t)"))
				){
			Double G  = Double.valueOf(resultMap.get("G").trim());
			Double P80  = Double.valueOf(resultMap.get("P80").trim());
			Double F80  = Double.valueOf(resultMap.get("F80").trim());
			BigDecimal YMX_kWh_t  = getBigDecimal(resultMap.get("易磨性(kWh/t)").trim());
			BigDecimal YMX_MJ_t  = getBigDecimal(resultMap.get("易磨性(MJ/t)").trim());
			Double countResult =
					Math.pow(80,0.23)*Math.pow(G,0.82)*(10/(Math.pow(P80,0.5)- 10/Math.pow(F80,0.5)));
			BigDecimal result1 = new BigDecimal(countResult);
			BigDecimal value1 =
					new BigDecimal(176.2).divide(result1,10,BigDecimal.ROUND_HALF_UP).subtract(new BigDecimal(3.6).multiply(new BigDecimal(P80))).abs();
			BigDecimal value2 = YMX_MJ_t.divide(YMX_kWh_t,10,BigDecimal.ROUND_HALF_UP);
			if(value1.compareTo(new BigDecimal(0.5) ) == -1 &&
					value2.compareTo(new BigDecimal(3.5)) == 1 &&
					value2.compareTo(new BigDecimal(3.7)) == -1){
				count = "OK";
			}else{
				count = "出错了";
			}
		}
		return count;

	}

	/**
	 * 计算平行数
	 * @param mainResult  主样数据
	 * @param secondaryResult 次样数据
	 * @return
	 */
	public static String countParallel(String mainResult, String secondaryResult) {
		BigDecimal main = getBigDecimal(mainResult);
		BigDecimal secondary = getBigDecimal(secondaryResult);
		BigDecimal aveCount = main.add(secondary).divide(new BigDecimal(2),10,BigDecimal.ROUND_HALF_UP);
		BigDecimal result1 = aveCount.multiply(param100);
		int resultInt1  = result1.setScale( 0, BigDecimal.ROUND_DOWN ).intValue();
		BigDecimal endResult = null;
		if((resultInt1&1) == 1){  //如果结果为奇数
			endResult =  aveCount.setScale(2,BigDecimal.ROUND_HALF_EVEN);
		}else{
			endResult = aveCount.subtract(new BigDecimal(0.0000000001)).setScale(2,BigDecimal.ROUND_HALF_EVEN);
		}
		return  endResult.toString();
	}


	/**
	 * 计算平行样的平均值  最大误差值
	 * @return
	 */
	public static Map<String,Map<String,String>> countParallelAvgError(Map<String,String> groupMap) {
		Map<String,Map<String,String>> map = new HashMap<>();
		Map<String,String> countResults = new HashMap<>();
		Map<String,String>  countError = new HashMap<>();
		for(Map.Entry<String,String> entry : groupMap.entrySet()){
			String[] values = entry.getValue().split(",");
			BigDecimal resultSum = null; //求总和
			BigDecimal maxNum = null;  //求最大值
			BigDecimal minNum = null;  //求最小值
			for(String val : values){
				BigDecimal valBD = getBigDecimal(val);
				resultSum = resultSum == null?valBD:resultSum.add(valBD);
				maxNum = maxNum ==null?valBD:(valBD.compareTo(maxNum) == 1?valBD:maxNum);
				minNum = minNum==null?valBD:(valBD.compareTo(minNum) == -1?valBD:minNum);
			}
			//平均值
			BigDecimal ResultsValue = null;
			if(resultSum != null){
				BigDecimal aveCount = resultSum.divide(new BigDecimal(values.length),10,BigDecimal.ROUND_HALF_UP);
				BigDecimal result1 = aveCount.multiply(param100);
				int resultInt1  = result1.setScale( 0, BigDecimal.ROUND_DOWN ).intValue();
				if((resultInt1&1) == 1){  //如果结果为奇数
					ResultsValue =  aveCount.setScale(2,BigDecimal.ROUND_HALF_EVEN);
				}else{
					ResultsValue = aveCount.subtract(new BigDecimal(0.0000000001)).setScale(2,BigDecimal.ROUND_HALF_EVEN);
				}
			}
			//最大误差值
			BigDecimal errorValue = null;
			if(maxNum != null && minNum != null){
				errorValue = maxNum.subtract(minNum).setScale(2,BigDecimal.ROUND_HALF_EVEN);
			}
			countResults.put(entry.getKey(),ResultsValue == null?"":ResultsValue.toString());
			countError.put(entry.getKey(),errorValue==null?"":errorValue.toString());
		}
		map.put("countResults",countResults);
		map.put("countError",countError);
		return  map;
	}








}












