package com.steering.jobface.qcm.task;

import java.lang.reflect.Method;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;

import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.EntityTool;
import com.steering.comm.tools.JudgeHelper;
import com.steering.comm.tools.SqlBuilder;
import com.steering.comm.tools.StringTool;
import com.steering.model.qcm.CraftOrdDesignStdPicEntity;
import com.steering.model.qcm.QcmBcPhyresultEntity;
import com.steering.model.qcm.QcmJhyElementsEntity;
import com.steering.model.qcm.QcmJhyPhyresultEntity;
import com.steering.model.qcm.SlmOrderLineEntity;

import CoreFS.Util.StringUtils;

public class PhyJudgeHelper extends DBCommon{
	
	public static Object[] judge(ArrayList<QcmJhyPhyresultEntity> jhyPhyResults, ArrayList<CraftOrdDesignStdPicEntity> craftDesingStdPics,
			String ordLnPk, String checkNo, String stoveNo, String specFlag, Connection con){
		Object[] results = new Object[]{ "", null };
		if (craftDesingStdPics.size() == 0) {
			results[0] = "没有找到内控标准数据！";
			return results;
		}
		
		HashMap<String, QcmBcPhyresultEntity> phyResults = new HashMap<String, QcmBcPhyresultEntity>();
		results[1] = phyResults;
		
		HashMap<String, CraftOrdDesignStdPicEntity> stdMap = new HashMap<String, CraftOrdDesignStdPicEntity>();
		
		SqlBuilder b = new SqlBuilder("PhyJudgeHelper.getSpecByDlyPk");
		b.Fill(new String[]{ ordLnPk });
		
		SlmOrderLineEntity orderLineEntity = EntityTool.getEntityBySqlNoClsCon(
				b.toString(), con, SlmOrderLineEntity.class);
		b = new SqlBuilder("SteelMakingAdvanceJudgeTask.getJhyElements");
		b.Fill(new String[]{ stoveNo, "601" });
		QcmJhyElementsEntity chem601 = EntityTool.getEntityBySqlNoClsCon(
				b.toString(), con, QcmJhyElementsEntity.class);
		b = new SqlBuilder("SteelMakingAdvanceJudgeTask.getJhyElements");
		b.Fill(new String[]{ stoveNo, "602" });
		QcmJhyElementsEntity chem602 = EntityTool.getEntityBySqlNoClsCon(
				b.toString(), con, QcmJhyElementsEntity.class);
		
		for(QcmJhyPhyresultEntity jhyPhyResult : jhyPhyResults){
			for (CraftOrdDesignStdPicEntity craftDesingStdPic : craftDesingStdPics) {
				if(craftDesingStdPic.getPhyCode().equals(jhyPhyResult.getPhyCode())
						&& (craftDesingStdPic.getItemCodeF().equals("") || craftDesingStdPic.getItemCodeF().equals(jhyPhyResult.getItemCodeF()))
						&& (craftDesingStdPic.getItemCodeW().equals("") || craftDesingStdPic.getItemCodeW().equals(jhyPhyResult.getItemCodeW()))
						&& (craftDesingStdPic.getItemCodeS().equals("") || craftDesingStdPic.getItemCodeS().equals(jhyPhyResult.getItemCodeS()))){
					//计算公式。
					CalculateExpress(craftDesingStdPic, orderLineEntity.getHeight(), chem601, chem602, jhyPhyResult);
					SetStdRange(craftDesingStdPic);
					
					//处理冲击功
					if(checkNo.startsWith("F") && craftDesingStdPic.getPhyName().startsWith("冲击功K")){
						craftDesingStdPic.setJudgeBasis("D");
						craftDesingStdPic.setAddcondition("");
						craftDesingStdPic.setAddpercent("");
						craftDesingStdPic.setAddstdconCode("");
						craftDesingStdPic.setAddstdMax("");
						craftDesingStdPic.setAddstdMaxSign("");
						craftDesingStdPic.setAddstdMin("");
						craftDesingStdPic.setAddstdMinSign("");
					}
					
					stdMap.put(jhyPhyResult.getPhyCode() + jhyPhyResult.getItemCodeF()
							+ jhyPhyResult.getItemCodeW() + jhyPhyResult.getItemCodeS(),
							craftDesingStdPic);
				}
			}
		}
		
		for (QcmJhyPhyresultEntity jhyResult : jhyPhyResults) {
			QcmBcPhyresultEntity phyParm = new QcmBcPhyresultEntity();
			phyParm.setPhyCode(jhyResult.getPhyCode());
			phyParm.setPhyCodeMin(jhyResult.getPhyCodeMin());
			phyParm.setPhyCodeMax(jhyResult.getPhyCodeMax());
			phyParm.setPhyName(jhyResult.getPhyName());
			phyParm.setPhyNameMin(jhyResult.getPhyNameMin());
			phyParm.setPhyNameMax(jhyResult.getPhyNameMax());
			phyParm.setItemCodeF(jhyResult.getItemCodeF());
			phyParm.setItemNameF(jhyResult.getItemNameF());
			phyParm.setItemCodeS(jhyResult.getItemCodeS());
			phyParm.setItemNameS(jhyResult.getItemNameS());
			phyParm.setItemCodeW(jhyResult.getItemCodeW());
			phyParm.setItemNameW(jhyResult.getItemNameW());
			phyParm.setUnqualifiedType("0");
			String key = jhyResult.getPhyCode() + jhyResult.getItemCodeF()
					+ jhyResult.getItemCodeW() + jhyResult.getItemCodeS();
			CraftOrdDesignStdPicEntity craftDesingStdPic = null;
			if(!stdMap.containsKey(key)){
				if(specFlag.equals("2")){
					phyParm.setNkQualified("3");
					phyParm.setNkTolQualified("3");
					phyResults.put(key, phyParm);
					results[0] = results[0].toString() + "检验项：" + jhyResult.getPhyName() + "找不到标准";
					continue;
				}else{
					continue;
				}
			}else{
				craftDesingStdPic = stdMap.get(key);
			}
			
			phyParm.setNkJudgeBasis(craftDesingStdPic.getJudgeBasis());
			phyParm.setNkAddJudgeBasis(craftDesingStdPic.getAddcondition());
			phyParm.setNkAddCondition(craftDesingStdPic.getAddcondition());
			phyResults.put(craftDesingStdPic.getPhyCode() + craftDesingStdPic.getItemCodeF()
					+ craftDesingStdPic.getItemCodeW() + craftDesingStdPic.getItemCodeS(), phyParm);
			
//			if(craftDesingStdPic.getPhyName().contains("下屈服强度ReL")){
//				String s = "";
//				s = "";
//			}	
				
			phyParm.setNkQualified("1");
			if(!craftDesingStdPic.getAddstdMin().equals("")){
				phyParm.setNkAddQualified("1");
			}
			
			if(craftDesingStdPic.getIsjudge().equals("1")){
				//如果是低倍检验则不用与标准对比：报出无就是合格，有就是不合格
				if(craftDesingStdPic.getPhyCodeMin().equals("C0022")){
					if(jhyResult.getValue1().equals("无")){
						phyParm.setNkQualified("1");
						phyParm.setNkTolQualified("1");
					}else{
						phyParm.setNkQualified("0");
						phyParm.setNkQualified("0");
					}
					continue;
				}
				
				//验证标准
				if(!craftDesingStdPic.getStdmin().equals("")){
					phyParm.setNkMin(craftDesingStdPic.getStdminSign() + craftDesingStdPic.getStdmin());
					String compareStr = ComparePhy(jhyResult, phyParm.getNkMin(), "Std", craftDesingStdPic);
					if(!compareStr.equals("")){
						if(compareStr.equals("noData")){
							phyParm.setNkQualified("2");
							results[0] = results[0].toString() + "检验项：" + craftDesingStdPic.getPhyName() + "没报出";
						}else if(compareStr.equals("noJudge")){
							phyParm.setNkQualified("3");
							results[0] = results[0].toString() + "检验项：" + craftDesingStdPic.getPhyName() + "无法判定";
						}else{
							phyParm.setNkQualified("0");
							phyParm.setUnqualifiedType("1");
							results[0] = results[0].toString() + "检验项：" + craftDesingStdPic.getPhyName() + "低于标准下限";
						}
					}
				}
				if(!craftDesingStdPic.getStdmax().equals("")){
					phyParm.setNkMax(craftDesingStdPic.getStdmaxSign() + craftDesingStdPic.getStdmax());
					String compareStr = ComparePhy(jhyResult, phyParm.getNkMax(), "Std", craftDesingStdPic);
					if(!compareStr.equals("")){
						if(compareStr.equals("noData")){
							phyParm.setNkQualified("2");
							results[0] = results[0].toString() + "检验项：" + craftDesingStdPic.getPhyName() + "没报出";
						}else if(compareStr.equals("noJudge")){
							phyParm.setNkQualified("3");
							results[0] = results[0].toString() + "检验项：" + craftDesingStdPic.getPhyName() + "无法判定";
						}else{
							phyParm.setNkQualified("0");
							phyParm.setUnqualifiedType("2");
							results[0] = results[0].toString() + "检验项：" + craftDesingStdPic.getPhyName() + "高于标准上限";
						}
					}
				}
				
//				if(craftDesingStdPic.getPhyName().equals("断后伸长率A")){
//					String str = "";
//					str = "";
//				}
				
				if(phyParm.getNkQualified().equals("0") && craftDesingStdPic.getAddcondition().equals("0")
						|| phyParm.getNkQualified().equals("1") && craftDesingStdPic.getAddcondition().equals("1")
						|| craftDesingStdPic.getAddcondition().equals("")){
					//验证附加标准
					if(!craftDesingStdPic.getAddstdMin().equals("")){
						phyParm.setNkAddMin(craftDesingStdPic.getAddstdMinSign() + craftDesingStdPic.getAddstdMin());
						String compareStr = ComparePhy(jhyResult, phyParm.getNkAddMin(), "Attach", craftDesingStdPic);
						if(!compareStr.equals("")){
							if(compareStr.equals("noData")){
								phyParm.setNkAddQualified("2");
								results[0] = results[0].toString() + "检验项：" + craftDesingStdPic.getPhyName() + "没报出";
							}else if(compareStr.equals("noJudge")){
								phyParm.setNkQualified("3");
								results[0] = results[0].toString() + "检验项：" + craftDesingStdPic.getPhyName() + "无法判定";
							}else{
								phyParm.setNkAddQualified("0");
								results[0] = results[0].toString() + "检验项：" + craftDesingStdPic.getPhyName() + "低于附加标准下限";
							}
							
						}
					}
					if(!craftDesingStdPic.getAddstdMax().equals("")
							){
						phyParm.setNkAddMax(craftDesingStdPic.getAddstdMaxSign() + craftDesingStdPic.getAddstdMax());
						String compareStr = ComparePhy(jhyResult, phyParm.getNkAddMax(), "Attach", craftDesingStdPic);
						if(!compareStr.equals("")){
							if(compareStr.equals("noData")){
								phyParm.setNkAddQualified("2");
								results[0] = results[0].toString() + "检验项：" + craftDesingStdPic.getPhyName() + "没报出";
							}else if(compareStr.equals("noJudge")){
								phyParm.setNkQualified("3");
								results[0] = results[0].toString() + "检验项：" + craftDesingStdPic.getPhyName() + "无法判定";
							}else{
								phyParm.setNkAddQualified("0");
								results[0] = results[0].toString() + "检验项：" + craftDesingStdPic.getPhyName() + "高于附加标准上限";
							}
						}
					}
				}
			}

			//最终是否合格
			if(phyParm.getNkQualified().equals("2")){
				phyParm.setNkTolQualified("2");
			}else if(phyParm.getNkQualified().equals("3")){
				phyParm.setNkTolQualified("3");
			}else if(phyParm.getNkQualified().equals("1")){
				if(phyParm.getNkAddQualified().equals("")){
					phyParm.setNkTolQualified("1");
				}else{
					if(phyParm.getNkAddCondition().equals("")){
						if(phyParm.getNkAddQualified().equals("1")){
							phyParm.setNkTolQualified("1");
						}else{
							phyParm.setNkTolQualified("0");
						}
					}else if(phyParm.getNkAddCondition().equals("1")){
						if(phyParm.getNkAddQualified().equals("1")){
							phyParm.setNkTolQualified("1");
						}else{
							phyParm.setNkTolQualified("0");
						}
					}else{
						phyParm.setNkTolQualified("1");
					}
				}
			}else{
				if(phyParm.getNkAddQualified().equals("")){
					phyParm.setNkTolQualified("0");
				}else{
					if(phyParm.getNkAddCondition().equals("")){
						phyParm.setNkTolQualified("0");
					}else if(phyParm.getNkAddCondition().equals("1")){
						phyParm.setNkTolQualified("0");
					}else{
						if(phyParm.getNkAddQualified().equals("1")){
							phyParm.setNkTolQualified("1");
						}else{
							phyParm.setNkTolQualified("0");
						}
					}
				}
			}
		}
		return results;
	}
	
	/**
	 * 计算表达式
	 * @param craftDesingStdPic
	 * @param t
	 */
	private static void CalculateExpress(CraftOrdDesignStdPicEntity craftDesingStdPic, String t,
			QcmJhyElementsEntity chem601, QcmJhyElementsEntity chem602, 
			QcmJhyPhyresultEntity jhyResult){
		if(craftDesingStdPic.getPhyType().equals("0")) return;
		String stdMin = craftDesingStdPic.getStdmin();
		String axc = CalculateAxc(jhyResult.getSampleSize(), t);
		
		//替换公式符号
		if(!stdMin.equals("") || !StringUtils.isNumeric(stdMin)){
			stdMin = stdMin.replaceAll("t", t).replaceAll("Axc", axc);
			craftDesingStdPic.setStdmin(JudgeHelper.getRoundValue(stdMin, 0));
			if(stdMin.contains("C")){
				if(!chem601.getC().equals("")){
					String tmpStd = stdMin.replaceAll("C%", chem601.getC()).replaceAll("C", chem601.getC());
					tmpStd = JudgeHelper.getRoundValue(tmpStd, 1);
					if(chem602 == null){
						craftDesingStdPic.setStdmin(tmpStd);
					}else{
						String tmpStd2 = stdMin.replaceAll("C%", chem602.getC().replaceAll("C", chem602.getC()));
						tmpStd2 = JudgeHelper.getRoundValue(tmpStd2, 1);
						if(Double.parseDouble(tmpStd) < Double.parseDouble(tmpStd2)){
							craftDesingStdPic.setStdmin(tmpStd);
						}else{
							craftDesingStdPic.setStdmin(tmpStd2);
						}
					}
				}
			}
		}
		String stdMax = craftDesingStdPic.getStdmax();
		if(!stdMax.equals("") || !StringUtils.isNumeric(stdMax)){
			stdMax = stdMax.replaceAll("t", t).replaceAll("Axc", axc);
			craftDesingStdPic.setStdmax(JudgeHelper.getRoundValue(stdMax, 0));
			
			if(stdMax.contains("C")){
				if(!chem601.getC().equals("")){
					String tmpStd = stdMax.replaceAll("C%", chem601.getC()).replaceAll("C", chem601.getC());
					tmpStd = JudgeHelper.getRoundValue(tmpStd, 1);
					if(chem602 == null){
						craftDesingStdPic.setStdmax(tmpStd);
					}else{
						String tmpStd2 = stdMax.replaceAll("C%", chem602.getC()).replaceAll("C", chem602.getC());
						tmpStd2 = JudgeHelper.getRoundValue(tmpStd2, 1);
						if(Double.parseDouble(tmpStd) < Double.parseDouble(tmpStd2)){
							craftDesingStdPic.setStdmax(tmpStd2);
						}else{
							craftDesingStdPic.setStdmax(tmpStd);
						}
					}
				}
			}
		}
		String stdMin2 = craftDesingStdPic.getStdmin2();
		if(!stdMin2.equals("") || !StringUtils.isNumeric(stdMin2)){
			stdMin2 = stdMin2.replaceAll("t", t).replaceAll("Axc", axc);
			craftDesingStdPic.setStdmin2(JudgeHelper.getRoundValue(stdMin2, 0));
			
			if(stdMin2.contains("C")){
				if(!chem601.getC().equals("")){
					String tmpStd = stdMin2.replaceAll("C%", chem601.getC()).replaceAll("C", chem601.getC());
					tmpStd = JudgeHelper.getRoundValue(tmpStd, 1);
					if(chem602 == null){
						craftDesingStdPic.setStdmin2(tmpStd);
					}else{
						String tmpStd2 = stdMin2.replaceAll("C%", chem602.getC()).replaceAll("C", chem602.getC());
						tmpStd2 = JudgeHelper.getRoundValue(tmpStd2, 1);
						if(Double.parseDouble(tmpStd) < Double.parseDouble(tmpStd2)){
							craftDesingStdPic.setStdmin2(tmpStd);
						}else{
							craftDesingStdPic.setStdmin2(tmpStd2);
						}
					}
				}
			}
		}
		String stdMax2 = craftDesingStdPic.getStdmax2();
		if(!stdMax2.equals("") || !StringUtils.isNumeric(stdMax2)){
			stdMax2 = stdMax2.replaceAll("t", t).replaceAll("Axc", axc);
			craftDesingStdPic.setStdmax2(JudgeHelper.getRoundValue(stdMax2, 0));
			
			if(stdMax2.contains("C")){
				if(!chem601.getC().equals("")){
					String tmpStd = stdMax2.replaceAll("C%", chem601.getC()).replaceAll("C", chem601.getC());
					tmpStd = JudgeHelper.getRoundValue(tmpStd, 1);
					if(chem602 == null){
						craftDesingStdPic.setStdmax2(tmpStd);
					}else{
						String tmpStd2 = stdMax2.replaceAll("C%", chem602.getC()).replaceAll("C", chem602.getC());
						tmpStd2 = JudgeHelper.getRoundValue(tmpStd2, 1);
						if(Double.parseDouble(tmpStd) < Double.parseDouble(tmpStd2)){
							craftDesingStdPic.setStdmax2(tmpStd2);
						}else{
							craftDesingStdPic.setStdmax2(tmpStd);
						}
					}
				}
			}
		}
	}
	
	private static String CalculateAxc(String sampleSize, String t){
		String axc = "Axc";
		// do为棒
		sampleSize = sampleSize.replaceAll("d0", "do").replaceAll(
				"b0", "bo").replaceAll("L0", "Lo");
		if(sampleSize.contains("do")){
			if(sampleSize.contains("do=12.7") || sampleSize.contains("do=8.9")
				|| (sampleSize.contains("do=12.5") && sampleSize.contains("Lo=50"))){
				axc = "130";
			}else if(sampleSize.contains("do=6.4")){
				axc = "65";
			}
		}else if(sampleSize.contains("bo")){
			int index = sampleSize.indexOf("bo=");
			String tmpStr = sampleSize.substring(index + 3);
			int index2 = tmpStr.indexOf("mm");
			String width = tmpStr.substring(0, index2);
			if(StringTool.isDouble(width)){
				double area = Double.parseDouble(width) * Double.parseDouble(t);
				area = RoundGBT81702008.round3_2(area / 10, 0);
				int iArea = (int)area * 10;
				if(iArea < 490){
					axc = String.valueOf(iArea);
				}else{
					axc = "490";
				}
			}
		}
		
		return axc;
	}
	
	private static String ComparePhy(QcmJhyPhyresultEntity jhyPhyResult, String express, String compareType,
			CraftOrdDesignStdPicEntity craftDesignStdPic)
    {
//		if(craftDesignStdPic.getPhyNameMin().equals("夏比摆锤冲击试验-V型")){
//        	String s = "";
//        	s = "";
//        }
		String strFLag = "";
		if(craftDesignStdPic.getSpeclFl().equals("0")){
			strFLag = "国家";
		}else if(craftDesignStdPic.getSpeclFl().equals("1")){
			strFLag = "客户";
		}else{
			strFLag = "内控";
		}
        
		//特殊处理夹杂物，有检验项备注的夹杂物不自动判定，人工干预。
		if(jhyPhyResult.getPhyCodeMax().equals("R0012") && !jhyPhyResult.getRemark().trim().equals("")){
			return "检验结果不符合标准！";
		}

		// 压扁、弯曲等报符合就直接判合格。
		if(!jhyPhyResult.getIsGood().equals("") || !jhyPhyResult.getIsDefect().equals("")){
			boolean ybResult = true;
			if(jhyPhyResult.getIsGood().equals("1")){
				ybResult = false;
			}
			if(jhyPhyResult.getIsDefect().equals("1")){
				ybResult = false;
			}
			if(ybResult){
				return "";
			}else{
				return "检验结果不符合标准！";
			}
		}
		
        ArrayList<Double> values = new ArrayList<Double>();
        Method[] methods = jhyPhyResult.getClass().getMethods();
        
        boolean hasValue = false;
        int chineseValueCnt = 0;
        int accordChineseValueCnt = 0;
        for(Method method : methods)
        {
        	String jhyName = method.getName();
        	if(jhyName.startsWith("set")) continue;
            if(jhyName.contains("Value") || jhyName.equals("getAverage")
            		|| jhyName.equals("getIsGood") || jhyName.equals("getIsDefect"))
            {
            	String value = "";
				try {
					value = method.invoke(jhyPhyResult, new Object[]{}).toString();
				} catch (Exception e) {
					e.printStackTrace();
				}
                if(!value.equals(""))
                {
                	hasValue = true;
                	if(jhyName.contains("Value")){
                		if(StringUtils.isNumeric(value)){
                			if("R0007".equals(craftDesignStdPic.getPhyCodeMax())){
            					if(craftDesignStdPic.getJudgeBasis().equals("C")){
            						if(jhyName.contains("4") || jhyName.contains("8") || jhyName.contains("12")){
            							values.add(Double.parseDouble(value));
            						}
            					}else if(craftDesignStdPic.getJudgeBasis().equals("D")){
            						if(!jhyName.contains("4") && !jhyName.contains("8") && !jhyName.contains("12")){
            							values.add(Double.parseDouble(value));
            						}
            					}else{
            						values.add(Double.parseDouble(value));
            					}
            				}else{
            					values.add(Double.parseDouble(value));
            				}
                    	}else{
                    		chineseValueCnt++;
							value = value.trim();
							if(value.startsWith("符合") || value.startsWith("不符合")
									|| jhyPhyResult.getPhyCodeMax().equals("R0012") && (value.startsWith("是") || value.startsWith("否"))){
								if (value.startsWith("符合") || value.startsWith("否")) {
									accordChineseValueCnt++;
								}
							}else{
								if((craftDesignStdPic.getStdminSign().equals("=") && craftDesignStdPic.getStdmin().equals(value))
										|| (jhyPhyResult.getPhyCodeMin().equals("C0013") && craftDesignStdPic.getStdmin().contains("或者") && craftDesignStdPic.getStdmin().contains(value))
								){
                        			return "";
                        		}else{
                        			return "noJudge";
                        		}
                    		}
                    	}
                	}
                }
            }
        }
        
        if(chineseValueCnt > 0){
        	if(chineseValueCnt == accordChineseValueCnt){
        		return "";
        	}else{
        		return "检验结果不符合标准！";
        	}
        }
        
        if(!hasValue){
        	return "noData";
        }
        String stdValue = express.replaceAll("<", "").replaceAll("=", "").replaceAll(">", "");
        if(!StringTool.isNumeric(stdValue)){
        	return "noJudge";
        }
        if (compareType == "Attach")
        {
        	if(values.size() == 0){
        		return "检验结果不符合"+ strFLag +"附加标准！";
        	}
        	
            if (craftDesignStdPic.getAddstdconCode().equals("407001"))//允许一个值
            {
                //row.Cells[columnKey].ToolTipText = str1 + str2 + row.GetValue(columnKey);
                int cnt = 0;
                String stdMinExpress = craftDesignStdPic.getStdminSign() + craftDesignStdPic.getStdmin();
                String stdMaxExpress = craftDesignStdPic.getStdmaxSign() + craftDesignStdPic.getStdmax();
                String addExpress = "";
                if(!craftDesignStdPic.getAddstdMin().equals("")){
                	addExpress = craftDesignStdPic.getAddstdMinSign() + craftDesignStdPic.getAddstdMin();
                }
                if(!craftDesignStdPic.getAddstdMax().equals("")){
                	if(!addExpress.equals("")){
                		addExpress += ";" + craftDesignStdPic.getAddstdMaxSign() + craftDesignStdPic.getAddstdMax();
                	}else{
                		addExpress = craftDesignStdPic.getAddstdMaxSign() + craftDesignStdPic.getAddstdMax();
                	}
                }
                for (Double value : values)
                {
                	if(!stdMinExpress.equals("") && stdMaxExpress.equals("")){
                		if (JudgeHelper.JudgeExpress(value.toString(), stdMinExpress)){
                			continue;
                        }
                	}else if(stdMinExpress.equals("") && !stdMaxExpress.equals("")){
                		if (JudgeHelper.JudgeExpress(value.toString(), stdMaxExpress)){
                			continue;
                        }
                	}else{
                		if (JudgeHelper.JudgeExpress(value.toString(), stdMinExpress)
                				&& JudgeHelper.JudgeExpress(value.toString(), stdMaxExpress)){
                			continue;
                        }
                	}
                	
                	if(JudgeHelper.JudgeExpress(value.toString(), addExpress)){
                		if (cnt == 0)
                        {
                            cnt++;
                        }else{
                        	return "检验结果不符合"+ strFLag +"附加标准！";
                        }
                	}else{
                		return "检验结果不符合"+ strFLag +"附加标准！";
                	}
                	
//                    if (JudgeHelper.JudgeExpress(value.toString(), express))
//                    {
//                        if (cnt == 0)
//                        {
//                            cnt++;
//                        }
//                        else
//                        {
//                            //row.Cells[columnKey].Appearance.BackColor = Color.FromArgb(255, 106, 106);
//                        	return "检验结果不符合"+ strFLag +"附加标准！";
//                        }
//                    }
                }
            }
            if (craftDesignStdPic.getAddstdconCode().equals("407002"))
            {
               // row.Cells[columnKey].ToolTipText = str1 + str2 + row.GetValue(columnKey);
                if (!JudgeHelper.JudgeExpress(String.valueOf(Collections.max(values) - Collections.min(values)), express))
                {
                	return "检验结果不符合"+ strFLag +"附加标准！";
                }
            }
            if (craftDesignStdPic.getAddstdconCode().equals("407003"))
            {
                //row.Cells[columnKey].ToolTipText = str1 + str2 + row.GetValue(columnKey);
            	String average = jhyPhyResult.getAverage();
                if(values.size() == 1)
                {
                    average = values.get(0).toString();
                }
                if (!JudgeHelper.JudgeExpress(average, express))
                {
                	return "检验结果不符合"+ strFLag +"附加标准！";
                }
            }
            if (craftDesignStdPic.getAddstdconCode().equals("407004"))
            {
                //row.Cells[columnKey].ToolTipText = str1 + str2 + row.GetValue(columnKey);
                if (!JudgeHelper.JudgeExpress(String.valueOf(Collections.min(values)), express))
                {
                	return "检验结果不符合"+ strFLag +"附加标准！";
                }
            }
            if (craftDesignStdPic.getAddstdconCode().equals("407005"))
            {
                //row.Cells[columnKey].ToolTipText = str1 + str2 + row.GetValue(columnKey);
                if (!JudgeHelper.JudgeExpress(String.valueOf(Collections.max(values)), express))
                {
                	return "检验结果不符合"+ strFLag +"附加标准！";
                }
            }
        }
        else
        {
        	if(values.size() ==0){
        		return "检验结果不符合"+ strFLag +"标准！";
            }
        	
            if (craftDesignStdPic.getJudgeBasis().equals("A"))
            {
                if (!JudgeHelper.JudgeExpress(String.valueOf(Collections.min(values)), express))
                {
                	return "检验结果不符合"+ strFLag +"标准！";
                }
            }
            else if (craftDesignStdPic.getJudgeBasis().equals("B"))
            {
                if (!JudgeHelper.JudgeExpress(String.valueOf(Collections.min(values)), express))
                {
                	return "检验结果不符合"+ strFLag +"标准！";
                }
            }
            else if (craftDesignStdPic.getJudgeBasis().equals("C") && !"R0007".equals(craftDesignStdPic.getPhyCodeMax()))
            {
            	String average = jhyPhyResult.getAverage();
                if(values.size() == 1)
                {
                    average = values.get(0).toString();
                }
                if (!JudgeHelper.JudgeExpress(average, express))
                {
                	return "检验结果不符合"+ strFLag +"标准！";
                }
            }
            else if (craftDesignStdPic.getJudgeBasis().equals("D") || "R0007".equals(craftDesignStdPic.getPhyCodeMax()))
            {
                for(Double value : values)
                {
                    if (!JudgeHelper.JudgeExpress(String.valueOf(value), express))
                    {
                    	return "检验结果不符合"+ strFLag +"标准！";
                    }
                }
            }
        }

        return "";
    }
	
	/**
	 * 设置标准范围
	 * @param craftDesignStdPic
	 * @return
	 */
	private static void SetStdRange(CraftOrdDesignStdPicEntity craftDesignStdPic)
    {
        if (craftDesignStdPic.getStdChoose().equals("407101"))//取大值
        {
        	if(!craftDesignStdPic.getStdmin().equals("")){
        		if (Double.parseDouble(craftDesignStdPic.getStdmin()) >= Double.parseDouble(craftDesignStdPic.getStdmin2()))
                {
        			
                }
                else
                {
                	craftDesignStdPic.setStdmin(craftDesignStdPic.getStdmin2());
                }
        	}
    		
        	if(!craftDesignStdPic.getStdmax().equals("")){
        		if (Double.parseDouble(craftDesignStdPic.getStdmax()) >= Double.parseDouble(craftDesignStdPic.getStdmax2()))
                {
        			
                }
                else
                {
                	craftDesignStdPic.setStdmax(craftDesignStdPic.getStdmax2());
                }
        	}
        }
        else if (craftDesignStdPic.getStdChoose().equals("407101"))
        {
        	if(!craftDesignStdPic.getStdmin().equals("")){
        		if (Double.parseDouble(craftDesignStdPic.getStdmin()) <= Double.parseDouble(craftDesignStdPic.getStdmin2()))
                {
        			
                }
                else
                {
                	craftDesignStdPic.setStdmin(craftDesignStdPic.getStdmin2());
                }
        	}
        	if(!craftDesignStdPic.getStdmax().equals("")){
        		if (Double.parseDouble(craftDesignStdPic.getStdmax()) <= Double.parseDouble(craftDesignStdPic.getStdmax2()))
                {
                    
                }
                else
                {
                	craftDesignStdPic.setStdmax(craftDesignStdPic.getStdmax2());
                }
        	}
        }
        
        //附加标准公式替换
        String addStdMin = craftDesignStdPic.getAddstdMin();
		if(addStdMin.contains("Value")) {
			addStdMin = addStdMin.replaceAll("Value", craftDesignStdPic.getStdmin());
			craftDesignStdPic.setAddstdMin(JudgeHelper.getRoundValue(addStdMin, 0));
		}
//        if(!addStdMin.equals("") && !StringUtils.isNumeric(addStdMin)){
//        	addStdMin = JudgeHelper.eval(addStdMin);
//        	if(StringUtils.isNumeric(addStdMin)){
//        		double dMin = Double.parseDouble(addStdMin);
//        		craftDesignStdPic.setAddstdMin(String.valueOf(RoundGBT81702008.round3_2(dMin, 0)));
//        	}else{
//        		craftDesignStdPic.setAddstdMin(addStdMin);
//        	}
//        }else{
//        	craftDesignStdPic.setAddstdMin(addStdMin);
//        }
        String addStdMax = craftDesignStdPic.getAddstdMax();
		if(addStdMax.contains("Value")) {
			addStdMax = addStdMax.replaceAll("Value", craftDesignStdPic.getStdmax());
			craftDesignStdPic.setAddstdMax(JudgeHelper.getRoundValue(addStdMax, 0));
		}
//        if(!addStdMax.equals("") && !StringUtils.isNumeric(addStdMax)){
//        	addStdMax = JudgeHelper.eval(addStdMax);
//        	if(StringUtils.isNumeric(addStdMax)){
//        		double dMax = Double.parseDouble(addStdMax);
//        		craftDesignStdPic.setAddstdMax(String.valueOf(RoundGBT81702008.round3_2(dMax, 0)));
//        	}else{
//        		craftDesignStdPic.setAddstdMax(addStdMax);
//        	}
//        }else{
//        	craftDesignStdPic.setAddstdMax(addStdMax);
//        }
    }
}
