package com.steering.pss.sale.order.qualityDesign.server.iserver;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.steering.comm.tools.StringTool;
import com.steering.pss.judge.comm.JudgeHelper;
import com.steering.pss.sale.order.craftDesign.tool.CraftTool;
import com.steering.pss.sale.order.model.ComMscEntity;
import com.steering.pss.sale.order.qualityDesign.QualityDesignTool;
import com.steering.pss.sale.order.qualityDesign.Dao.factory.FactoryDao;
import com.steering.pss.sale.order.qualityDesign.Dao.imp.MscDaoImp;
import com.steering.pss.sale.order.qualityDesign.Dao.imp.PhyDaoImp;
import com.steering.pss.sale.order.qualityDesign.ReturnsModel.DesignEntity;
import com.steering.pss.sale.order.qualityDesign.model.SlmOrdDesignStdPicEntity;
import com.steering.pss.sale.order.qualityDesign.model.SlmOrdDesignStdPicSmpEntity;
import com.steering.pss.sale.order.qualityDesign.server.imp.MscPhyImp;

public class IMscPhy implements MscPhyImp {

	// 验证理化标准流程：
	// 1、通过基础冶金规范码查询理化索引号
	// 2、通过理化索引号查询理化标准
	// 3、过滤外径、壁厚、径壁比等限制条件
	// 4、查询理化的取样要求
	// 5、只取一个理化索引号通过的数据
	/**
	 * 验证理化标准
	 * 
	 * @param con
	 *            连接字符串
	 * @param disignEntity
	 *            质量设计状态类
	 * @return boolean
	 * @throws SQLException
	 */
	@SuppressWarnings("unchecked")
	public String checkPhy(Connection con, String msc, DesignEntity design,
			String flag) throws SQLException {
		PhyDaoImp phyDaoImp = FactoryDao.getPhyDaoImp();
		MscDaoImp mscDaoImp = FactoryDao.getMscDaoImp();
		String message = "";
		String designKey = design.getDesignKey();
		String modelCode = design.getModelCode();
		String dimater = design.getDimater();
		String height = design.getHeight();
		String specStyle = design.getSpecStyle();
		String specCode = design.getSpecCode();
		String specName = design.getSpecName();
		String useCode = design.getUserCode();
		String useDesc = design.getUserDesc();
		ComMscEntity comMscEntity = mscDaoImp.getMsc(con, msc);

		// 如果冶金规范码已经通过审批，即状态等于C
		List<String> pics = null;
		if (comMscEntity.getValidflag().equals("C")) {
			pics = phyDaoImp.getExaminePic(con, msc, modelCode);
		} else {
			pics = phyDaoImp.getEValidPic(con, msc, modelCode);
		}
		if (pics == null || pics.size() == 0) {
			return message;
		}

		for (String pic : pics) {
			// 通过索引号查询理化标准
			List<SlmOrdDesignStdPicEntity> phys = phyDaoImp.getPhyByPic(con,
					pic);
			if (phys == null) {
				message = "理化索引号:" + pic + "找不到理化标准";
				continue;
			}
			// 过滤理化标准，如果是钢管，过滤外径/壁厚/内径等，如果是管坯，只过滤外径，如果是钢锭，或者其它规格，则过滤规格
			List<SlmOrdDesignStdPicEntity> phyAs = null;
			if (specStyle.equals("A")) {
				// 钢管
				// 径壁比
				String dh = String.valueOf(Double.parseDouble(dimater)
						/ Double.parseDouble(height));
				// 壁径比
				String hd = String.valueOf(Double.parseDouble(height)
						/ Double.parseDouble(dimater));
				// 内径
				String in = String.valueOf(Double.parseDouble(dimater) - 2
						* Double.parseDouble(height));
				phyAs = IMscPhy.fiterPhyA(phys, dimater, height, dh, hd, in);
			} else if (specStyle.equals("B")) {
				phyAs = IMscPhy.fiterPhyB(phys, dimater);
			} else {
				phyAs = IMscPhy.fiterPhyByCAndD(phys, specCode);
			}
			
			
			
			// 验证理化标准
			Object[] info = IMscPhy.fiterPhy(phyAs, phys, specStyle, dimater,
					height, specName);
			message = (String) info[1];
			phyAs = (ArrayList<SlmOrdDesignStdPicEntity>) info[0];
			if (message.length() > 0) {
				message = "理化索引号:" + pic + "," + message;
				continue;
			}
			// 验证理化标准的检验项目
			//验证理化公式
			boolean existsRm = false;
			boolean existsP0088 = false;
			for (SlmOrdDesignStdPicEntity phy : phyAs) {
				if(phy.getStdmin().contains("Rm") || phy.getStdmax().contains("Rm")){
					existsRm = true;
				}
				if(phy.getPhyCode().equals("P0088")){
					existsP0088 = true;
				}
			}
			if(existsRm && !existsP0088){
				message = "理化索引号:" + pic + "," + "公式中存在Rm, 请维护抗拉强度（高温）Rm";
				continue;
			}
			
			List<SlmOrdDesignStdPicSmpEntity> smps = new ArrayList<SlmOrdDesignStdPicSmpEntity>();
			if(flag.equals("2")){
				for (SlmOrdDesignStdPicEntity phy : phyAs) {
					// 验证取样要求
					if(!phy.getIscheck().equals("1") && !phy.getIscheck().equals("1") && !phy.getIscheck().equals("1"))
					{
						continue;
					}
					List<SlmOrdDesignStdPicSmpEntity> picSmpEntitys = phyDaoImp
							.getPicSample(con, pic, phy.getPhyCodeMin(), phy.getItemCodeF(),
									phy.getItemCodeS(), phy.getItemCodeW(), design.getStdCode(), design.getSteelCode(), design.getProducCode());
					SlmOrdDesignStdPicSmpEntity smp = IMscPhy.checkSmp(
							picSmpEntitys, design.getSteelCode(), dimater, height);
					
					if (smp == null) {
						message = "理化索引号:" + pic + "序号:" + phy.getIndexSeq()
								+ " 理化标准没有取样要求(钢级:" + design.getSteelName()
								+ ",外径:" + dimater + ",壁厚:" + height + ")";
						break;
					}else{
						if(smp.getSic().equals("")){
							message = "理化索引号:" + pic + "序号:" + phy.getIndexSeq()
							+ " 理化标准没有取样要求(钢级:" + design.getSteelName()
							+ ",外径:" + dimater + ",壁厚:" + height + ")";
							break;
						}else if(smp.getSmpCount() >= 2){
							message = "理化索引号：" + pic + "序号:" + phy.getIndexSeq() +
							" 试样组：" + phy.getPhyNameMin() + " 找到多条取样要求！";
							break;
						}
					}
					smp.setDesginKey(designKey);
					smps.add(smp);
					
				}
			}
			
			if(!message.equals("")){
				continue;
			}
			
			// 录入理化标准检验项
			for (SlmOrdDesignStdPicSmpEntity smp : smps) {
				if (!phyDaoImp.checkSmp(con, smp)) {
					phyDaoImp.savePicSample(con, smp);
				}
			}
			for (SlmOrdDesignStdPicEntity phy : phyAs) {
				// 是否特殊要求(0否;1是)
				phy.setSpeclFl(flag);
				if (flag.equals("1")) {
					phy.setUseCode(useCode);
					phy.setUseDesc(useDesc);
				}
				phy.setDesginKey(designKey);
				phyDaoImp.savePhy(con, phy);
			}
			if (flag.equals("0")) {
				phyDaoImp.updateDesignStd(con, pic, designKey);
			}

			message = "";
			break;
		}
		return message;
	}

	/**
	 * 过滤理化标准(钢管)
	 * 
	 * @param phys
	 *            理化标准类
	 * @param dimater
	 *            外径
	 * @param height
	 *            壁厚
	 * @return List<DesignStdPicEntity>
	 */
	public static List<SlmOrdDesignStdPicEntity> fiterPhyA(
			List<SlmOrdDesignStdPicEntity> phys, String dimater, String height,
			String DHProportion, String HDProportion, String innerProportion) {
		if (phys == null || phys.size() == 0) {
			return null;
		}
		// 有限制规格的理化标准
		List<SlmOrdDesignStdPicEntity> phyAs = new ArrayList<SlmOrdDesignStdPicEntity>();
		for (int i = 0; i < phys.size(); i++) {
			SlmOrdDesignStdPicEntity phy = phys.get(i);
			if (phy.getSizeCode().equals("") && phy.getSizeCode2().equals("") 
					&& phy.getFormula().equals("")) {
				phyAs.add(phys.get(i));
				continue;
			}
			// 外径 :400301 壁厚:400302 径壁比:400303 壁径比 400304 内径 400305 长度 400306
			if (phy.getSizeCode2().equals("400301")) {
				if ((!QualityDesignTool.checkStr(dimater,
						phy.getSizeMinSign2(), phy.getSizeMin2()))
						|| (!QualityDesignTool.checkStr(dimater,
								phy.getSizeMaxSign2(), phy.getSizeMax2()))) {
					continue;
				}
			}
			if (phy.getSizeCode2().equals("400302")) {
				if ((!QualityDesignTool.checkStr(height, phy.getSizeMinSign2(),
						phy.getSizeMin2()))
						|| (!QualityDesignTool.checkStr(height,
								phy.getSizeMaxSign2(), phy.getSizeMax2()))) {
					continue;
				}
			}
			if (phy.getSizeCode2().equals("400303")) {
				if ((!QualityDesignTool.checkStr(DHProportion,
						phy.getSizeMinSign2(), phy.getSizeMin2()))
						|| (!QualityDesignTool.checkStr(DHProportion,
								phy.getSizeMaxSign2(), phy.getSizeMax2()))) {
					continue;
				}
			}
			if (phy.getSizeCode2().equals("400304")) {
				if ((!QualityDesignTool.checkStr(HDProportion,
						phy.getSizeMinSign2(), phy.getSizeMin2()))
						|| (!QualityDesignTool.checkStr(HDProportion,
								phy.getSizeMaxSign2(), phy.getSizeMax2()))) {
					continue;
				}
			}
			if (phy.getSizeCode2().equals("400305")) {
				if ((!QualityDesignTool.checkStr(innerProportion,
						phy.getSizeMinSign2(), phy.getSizeMin2()))
						|| (!QualityDesignTool.checkStr(innerProportion,
								phy.getSizeMaxSign2(), phy.getSizeMax2()))) {
					continue;
				}
			}

			if (phy.getSizeCode().equals("400301")) {
				if ((!QualityDesignTool.checkStr(dimater, phy.getSizeMinSign(),
						phy.getSizeMin()))
						|| (!QualityDesignTool.checkStr(dimater,
								phy.getSizeMaxSign(), phy.getSizeMax()))) {
					continue;
				}
			}
			if (phy.getSizeCode().equals("400302")) {
				if ((!QualityDesignTool.checkStr(height, phy.getSizeMinSign(),
						phy.getSizeMin()))
						|| (!QualityDesignTool.checkStr(height,
								phy.getSizeMaxSign(), phy.getSizeMax()))) {
					continue;
				}
			}
			if (phy.getSizeCode().equals("400303")) {
				if ((!QualityDesignTool.checkStr(DHProportion,
						phy.getSizeMinSign(), phy.getSizeMin()))
						|| (!QualityDesignTool.checkStr(DHProportion,
								phy.getSizeMaxSign(), phy.getSizeMax()))) {
					continue;
				}
			}
			if (phy.getSizeCode().equals("400304")) {
				if ((!QualityDesignTool.checkStr(HDProportion,
						phy.getSizeMinSign(), phy.getSizeMin()))
						|| (!QualityDesignTool.checkStr(HDProportion,
								phy.getSizeMaxSign(), phy.getSizeMax()))) {
					continue;
				}
			}
			if (phy.getSizeCode().equals("400305")) {
				if ((!QualityDesignTool.checkStr(innerProportion,
						phy.getSizeMinSign(), phy.getSizeMin()))
						|| (!QualityDesignTool.checkStr(innerProportion,
								phy.getSizeMaxSign2(), phy.getSizeMax()))) {
					continue;
				}
			}
			
			//公式验证。
			String formula = phy.getFormula();
			if(!formula.equals("")){
				formula = formula.replaceAll("t", height).replaceAll("D", dimater);
				if(StringTool.isDouble(JudgeHelper.eval(formula))){
					double dFormula = Double.parseDouble(JudgeHelper.eval(formula));
					BigDecimal d = new BigDecimal(dFormula);
					dFormula = d.setScale(2, RoundingMode.HALF_UP).doubleValue();//4舍5入
					formula = String.valueOf(dFormula);
				}else{
					formula = "-1";
				}
			}
			
			if(!phy.getMinFSign().equals("")){
				if(!QualityDesignTool.checkStr(formula, phy.getMinFSign(), phy.getMinF())){
					continue;
				}
			}
			if(!phy.getMaxFSign().equals("")){
				if(!QualityDesignTool.checkStr(formula, phy.getMaxFSign(), phy.getMaxF())){
					continue;
				}
			}
			
			phyAs.add(phy);
		}

		return phyAs;
	}

	/**
	 * 过滤钢锭或者其它规格
	 * 
	 * @param chems
	 * @param specCode
	 * @return
	 */
	public static List<SlmOrdDesignStdPicEntity> fiterPhyByCAndD(
			List<SlmOrdDesignStdPicEntity> phys, String specCode) {
		List<SlmOrdDesignStdPicEntity> list = new ArrayList<SlmOrdDesignStdPicEntity>();
		for (SlmOrdDesignStdPicEntity phy : phys) {
			if (phy.getSpecJg().equals("") || phy.getSpecJg().equals(specCode)) {
				list.add(phy);
			}
		}
		return list;
	}

	/**
	 * 过滤理化标准（管坯）
	 * 
	 * @param phys
	 *            理化标准类
	 * @param dimater
	 *            外径
	 * @param height
	 *            壁厚
	 * @return List<DesignStdPicEntity>
	 */
	public static List<SlmOrdDesignStdPicEntity> fiterPhyB(
			List<SlmOrdDesignStdPicEntity> phys, String dimater) {
		if (phys == null || phys.size() == 0) {
			return null;
		}
		List<SlmOrdDesignStdPicEntity> phyAs = new ArrayList<SlmOrdDesignStdPicEntity>();

		for (int i = 0; i < phys.size(); i++) {
			SlmOrdDesignStdPicEntity phy = phys.get(i);
			if (phy.getSizeCode().equals("") && phy.getSizeCode2().equals("")) {
				phyAs.add(phys.get(i));
				continue;
			}
			// 如果限制规格不为空且不为外径
			if (!phy.getSizeCode().equals("")
					&& !phy.getSizeCode().equals("400301")) {
				continue;
			}
			if (!phy.getSizeCode2().equals("")
					&& !phy.getSizeCode2().equals("400301")) {
				continue;
			}
			// 外径 :400301 壁厚:400302 径壁比:400303 壁径比 400304 内径 400305 长度 400306
			if (phy.getSizeCode2().equals("400301")) {
				if ((!QualityDesignTool.checkStr(dimater,
						phy.getSizeMinSign2(), phy.getSizeMin2()))
						|| (!QualityDesignTool.checkStr(dimater,
								phy.getSizeMaxSign2(), phy.getSizeMax2()))) {
					continue;
				}
			}

			if (phy.getSizeCode().equals("400301")) {
				if ((!QualityDesignTool.checkStr(dimater, phy.getSizeMinSign(),
						phy.getSizeMin()))
						|| (!QualityDesignTool.checkStr(dimater,
								phy.getSizeMaxSign(), phy.getSizeMax()))) {
					continue;
				}
			}
			phyAs.add(phys.get(i));
		}

		return phyAs;
	}

	/**
	 * 验证理化标准
	 * 
	 * @param phys
	 * @param phyAlls
	 * @param specStyle
	 * @param dimater
	 * @param height
	 * @param specName
	 * @return
	 */
	public static Object[] fiterPhy(List<SlmOrdDesignStdPicEntity> phys,
			List<SlmOrdDesignStdPicEntity> phyAlls, String specStyle,
			String dimater, String height, String specName) {
		Object[] arr = new Object[2];
		if (phys == null || phys.size() == 0 || phyAlls == null
				|| phyAlls.size() == 0) {
			arr[0] = null;
			if (specStyle.equals("A") || specStyle.equals("B")) {
				arr[1] = "满足外径(" + dimater + ")、壁厚(" + height + ")等约束理化标准不存在";
			} else {
				arr[1] = "满足规格(" + specName + ")约束理化标准不存在";
			}
			return arr;
		}
		// 有限制规格
		List<SlmOrdDesignStdPicEntity> phyYs = new ArrayList<SlmOrdDesignStdPicEntity>();
		List<String> phyYKeys = new ArrayList<String>();
		// 没有限制规格
		List<SlmOrdDesignStdPicEntity> phyNs = new ArrayList<SlmOrdDesignStdPicEntity>();
		List<String> phyNKeys = new ArrayList<String>();
		for (SlmOrdDesignStdPicEntity phy : phys) {
			// 理化主键代码组合
			String keyCode = phy.getPhyCodeMax() + "," + phy.getPhyCodeMin()
					+ "," + phy.getPhyCode() + "," + phy.getItemCodeF() + ","
					+ phy.getItemCodeS() + "," + phy.getItemCodeW();
			// 理化主键名称组合
			String keyName = phy.getPhyNameMax() + "," + phy.getPhyNameMin()
					+ "," + phy.getPhyName() + "," + phy.getItemNameF() + ","
					+ phy.getItemNameS() + "," + phy.getItemNameW();

			/**
			 * 钢管或者管坯
			 */
			if (specStyle.equals("A") || specStyle.equals("B")) {
				if (phy.getSizeCode().equals("")
						&& phy.getSizeCode2().equals("")) {
					if (phyNKeys.contains(keyCode)) {
						arr[0] = null;
						arr[1] = "理化检验项目(" + keyName + ")存在多条理化标准,且没有任何限制规格!";
						return arr;
					}
					phyNKeys.add(keyCode);
					phyNs.add(phy);
				} else {
					if (phyYKeys.contains(keyCode)) {
						arr[0] = null;
						arr[1] = "理化检验项目(" + keyName + ")存在多条满足外径(" + dimater
								+ ")、壁厚(" + height + ")的理化标准!";
						return arr;
					}
					phyYKeys.add(keyCode);
					phyYs.add(phy);
				}
			} else {
				/**
				 * 钢锭或者接箍规格
				 */
				if (phy.getSpecJg().equals("")) {
					if (phyNKeys.contains(keyCode)) {
						arr[0] = null;
						arr[1] = "理化检验项目(" + keyName + ")存在多条理化标准,且没有任何限制规格!";
						return arr;
					}
					phyNKeys.add(keyCode);
					phyNs.add(phy);
				} else {
					if (phyYKeys.contains(keyCode)) {
						arr[0] = null;
						arr[1] = "理化检验项目(" + keyName + ")存在多条满足规格(" + specName
								+ ")的理化标准!";
						return arr;
					}
					phyYKeys.add(keyCode);
					phyYs.add(phy);
				}
			}
		}
		for (int i = 0; i < phyNs.size(); i++) {
			SlmOrdDesignStdPicEntity phy = phyNs.get(i);
			// 理化主键代码组合
			String keyCode = phy.getPhyCodeMax() + "," + phy.getPhyCodeMin()
					+ "," + phy.getPhyCode() + "," + phy.getItemCodeF() + ","
					+ phy.getItemCodeS() + "," + phy.getItemCodeW();
			// 新增 限制规格理化集合中没有的理化标准
			if (!phyYKeys.contains(keyCode)) {
				phyYs.add(phy);
			}
		}
		
		//验证理化是否重复
//		String returnInfo = IMscPhy.checkCommon(phys, dimater, height);
//		if (!returnInfo.equals("")) {
//			arr[0] = null;
//			arr[1] = returnInfo;
//			return arr;
//		}
		
		/**
		 * 取消验证理化的总项目数
		 */
//		// 验证理化标准的检验项目
//		Object[] objPhyCodes = IMscPhy.getPhySizes(phys);
//		List<String> phyCodeKeys = (List<String>)objPhyCodes[0];
//		ArrayList<String> phyCodeGroupSeqs = (ArrayList<String>)objPhyCodes[1];
//		Object[] objPhyAllCodes = IMscPhy.getPhySizes(phyAlls);
//		List<String> phyAllCodeKeys = (List<String>)objPhyAllCodes[0];
//		ArrayList<String> phyAllGroupSeqs = (ArrayList<String>)objPhyAllCodes[1];
//		
//		// 如果检验项目数不相同
//		if (phyCodeKeys.size() != phyAllCodeKeys.size()) {
//			for (int i = 0; i < phyAllCodeKeys.size(); i ++) {
//				String key = phyAllCodeKeys.get(i);
//				if (!phyCodeKeys.contains(key) &&
//						(phyAllGroupSeqs.get(i).equals("") || !phyCodeGroupSeqs.contains(phyAllGroupSeqs.get(i)))) {
//					arr[0] = null;
//					if (specStyle.equals("A") || specStyle.equals("B")) {
//						arr[1] = "理化标准维护理化项目:" + phyAllCodeKeys.size() + "项,"
//								+ "但满足约束:" + phyCodeKeys.size() + "项,理化检验项("
//								+ key + ")不满足外径(" + dimater + ")、壁厚(" + height
//								+ ")等约束";
//					} else {
//						arr[1] = "理化标准维护理化项目:" + phyAllCodeKeys.size() + "项,"
//								+ "但满足约束:" + phyCodeKeys.size() + "项,理化检验项("
//								+ key + ")不满足规格(" + specName + ")约束";
//					}
//					return arr;
//				}
//			}
//		} else {
//			for (int i = 0; i < phyCodeKeys.size(); i++) {
//				if (!phyCodeKeys.get(i).equals(phyAllCodeKeys.get(i)) &&
//						(phyAllGroupSeqs.get(i).equals("") || !phyCodeGroupSeqs.contains(phyAllGroupSeqs.get(i)))) {
//					arr[0] = null;
//					if (specStyle.equals("A") || specStyle.equals("B")) {
//						arr[1] = "理化标准维护理化项目:" + phyAllCodeKeys.size() + "项,"
//								+ "但满足约束:" + phyCodeKeys.size() + "项,"
//								+ phyCodeKeys.get(i) + "不满足外径(" + dimater
//								+ ")、壁厚(" + height + ")等约束";
//					} else {
//						arr[1] = "理化标准维护理化项目:" + phyAllCodeKeys.size() + "项,"
//								+ "但满足约束:" + phyCodeKeys.size() + "项,"
//								+ phyCodeKeys.get(i) + "不满足规格(" + specName
//								+ ")约束";
//					}
//					return arr;
//				}
//			}
//		}
		arr[0] = phyYs;
		arr[1] = "";
		return arr;
	}
	
	public static String checkCommon(List<SlmOrdDesignStdPicEntity> phyList,
			String dimater, String height) {
		for (SlmOrdDesignStdPicEntity phyEntityA : phyList) {
			for (SlmOrdDesignStdPicEntity phyEntityB : phyList) {
				if (!phyEntityA.getIndexSeq().equals(phyEntityB.getIndexSeq())
						&& phyEntityA.getPhyCodeMax().equals(
								phyEntityB.getPhyCodeMax())
						&& phyEntityA.getPhyCodeMin().equals(
								phyEntityB.getPhyCodeMin())
						&& phyEntityA.getPhyCode().equals(phyEntityB.getPhyCode())
						&& phyEntityA.getItemCodeF().equals(phyEntityB.getItemCodeF())
						&& phyEntityA.getItemCodeS().equals(phyEntityB.getItemCodeS())
						&& phyEntityA.getItemCodeW().equals(phyEntityB.getItemCodeW())) {
					return "理化标准维护了多条满足外径(" + dimater + ") 壁厚(" + height
							+ ")的公差项(序号分别为:" + phyEntityA.getIndexSeq() + 
							", " + phyEntityB.getIndexSeq();
				}
			}
		}
		return "";
	}

	/**
	 * 查询理化标准维护项目
	 * 
	 * @param phys
	 * @return
	 */
	public static Object[] getPhySizes(List<SlmOrdDesignStdPicEntity> phys) {
		if (phys == null || phys.size() == 0) {
			return null;
		}
		List<String> phyKeys = new ArrayList<String>();
		ArrayList<String> groupSeqs = new ArrayList<String>();
		for (SlmOrdDesignStdPicEntity phy : phys) {
			// 理化主键名称组合
			String keyName = phy.getPhyNameMax() + "," + phy.getPhyNameMin()
					+ "," + phy.getPhyName() + "," + phy.getItemNameF() + ","
					+ phy.getItemNameS() + "," + phy.getItemNameW() + "," + phy.getGroupSeq();
			if (!phyKeys.contains(keyName) && (phy.getGroupSeq().equals("") 
					|| !groupSeqs.contains(phy.getGroupSeq()))) {
				phyKeys.add( keyName );
				groupSeqs.add(phy.getGroupSeq());
			}
		}
		// 升序排序
//		Collections.sort(phyKeys);
		
		return new Object[]{ phyKeys, groupSeqs};
	}

	/**
	 * 过滤取样要求
	 * 
	 * @param smpEntitys
	 * @param gradeCode
	 * @param dimater
	 * @param height
	 * @return
	 */
	public static SlmOrdDesignStdPicSmpEntity checkSmp(List<SlmOrdDesignStdPicSmpEntity> smpEntitys,
			String steelCode, String dimater, String height) {
		SlmOrdDesignStdPicSmpEntity returnData = null;
		int smpCnt = 0;
		if(smpEntitys != null){
			for (SlmOrdDesignStdPicSmpEntity smp : smpEntitys) {
				if (CraftTool.checkStr(dimater, smp.getMinDSign(),
								smp.getMinD())
						&& CraftTool.checkStr(dimater, smp.getMaxDSign(),
								smp.getMaxD())
						&& CraftTool.checkStr(height, smp.getMinHSign(),
								smp.getMinH())
						&& CraftTool.checkStr(height, smp.getMaxHSign(),
								smp.getMaxH())) {
					returnData = smp;
					smpCnt++;
				}else if(smp.getMinD().equals("")
						&& smp.getMaxD().equals("") && smp.getMinH().equals("")
						&& smp.getMaxH().equals("")) {
					returnData = smp;
					smpCnt++;
				}
			}
		}
		
		if(returnData != null){
			returnData.setSmpCount(smpCnt);
		}
		return returnData;
	}
	
	/**
	 * 过滤试样要求
	 * 
	 * @param smpEntitys
	 * @param gradeCode
	 * @param dimater
	 * @param height
	 * @return
	 */
	public static SlmOrdDesignStdPicSmpEntity checkSpline(List<SlmOrdDesignStdPicSmpEntity> splineEntitys,
			String steelCode, String dimater, String height) {
		
		SlmOrdDesignStdPicSmpEntity returnData = null;
		
		ArrayList<String> eics = new ArrayList<String>();
		int splineCnt = 0;
		if(splineEntitys != null){
			for (SlmOrdDesignStdPicSmpEntity spline : splineEntitys) {
				String value = "";
				if(!spline.getFormula().equals("")){
					value = spline.getFormula().replaceAll("t", height).replaceAll("D", dimater);
					value = JudgeHelper.eval(value).toString();
				}
				if (CraftTool.checkStr(dimater, spline.getMinDSign(),
						spline.getMinD())
						&& CraftTool.checkStr(dimater, spline.getMaxDSign(),
								spline.getMaxD())
						&& CraftTool.checkStr(height, spline.getMinHSign(),
								spline.getMinH())
						&& CraftTool.checkStr(height, spline.getMaxHSign(),
								spline.getMaxH())
						&& CraftTool.checkStr(value, spline.getMinFSign(), spline.getMinF())
						&& CraftTool.checkStr(value, spline.getMaxFSign(), spline.getMaxF())) {
					if(returnData != null){
						returnData.setLength(spline.getLength());
						returnData.setWidth(spline.getWidth());
						returnData.setSampleStyle(spline.getSampleStyle());
						returnData.setEic(spline.getEic());
						returnData.setPhyDir(spline.getPhyDir());
						returnData.setSizeDesc(spline.getSizeDesc());
					}else{
						returnData = spline;
					}
					
					if(!eics.contains(spline.getEic())){
						splineCnt++;
						eics.add(spline.getEic());
					}
				}else if (spline.getMinD().equals("") && spline.getMaxD().equals("") 
						&& spline.getMinH().equals("") && spline.getMaxH().equals("")
						&& spline.getMinF().equals("") && spline.getMaxF().equals("")) {
					returnData = spline;
					if(!eics.contains(spline.getEic())){
						splineCnt++;
						eics.add(spline.getEic());
					}
				}
			}
		}
		
		if(returnData != null){
			returnData.setSplineCount(splineCnt);
		}
		return returnData;
	}
}
