package com.steering.pss.sale.order.craftDesign.server;

import com.steering.comm.tools.StringTool;
import com.steering.pss.sale.order.craftDesign.dao.*;
import com.steering.pss.sale.order.craftDesign.model.*;
import com.steering.pss.sale.order.craftDesign.tool.CraftTool;
import org.apache.commons.lang.StringUtils;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * 工艺评审-内控标准
 * 
 * @author Administrator
 * 
 */
public class InnerStd {

	private String errMessage = "";

	/**
	 * 验证内控标准
	 * 
	 * @param con
	 *            连接字符串
	 * @param msc
	 *            冶金规范码
	 * @param mscPline
	 *            制程号
	 * @param wholeBacklog
	 *            制程全程途径码
	 * @param design
	 *            工艺全局类
	 * @param grades
	 *            钢种组合
	 * @param specEntity
	 *            规格类
	 * @return
	 * @throws Exception
	 */
	public InnerStdEntity checkInnerStd(Connection con, String msc, String mscPline, String wholeBacklog,
			CraftEntity design, List<CraftOrdDesignMscPlGzEntity> grades, SpecEntity specEntity) throws Exception {
		// 返回类
		InnerStdEntity innerEntity = new InnerStdEntity();
		// 成分标准
		List<CraftOrdDesignStdCicEntity> inchems = innerEntity.getChems();
		// 理化
		List<CraftOrdDesignStdPicEntity> inphys = innerEntity.getPhys();
		// 取样
		List<CraftOrdDesignStdPicSmpEntity> insmps = innerEntity.getSmps();
		// 公差
		List<CraftOrdDesignStdSicEntity> inspecs = innerEntity.getSpecs();
		// 探伤
		List<CraftOrdDesignStdDicEntity> indetes = innerEntity.getDetes();
		// 水压
		List<CraftOrdDesignStdWicEntity> inwaters = innerEntity.getWaters();
		// 加工
		List<CraftOrdDesignStdGicEntity> inprocesses = innerEntity.getProesses();
		// 工序索引号
		List<ProcessEntity> processList = innerEntity.getProcessList();
		innerEntity.setFlag(true);
		// 一个制程的索引号集合
		//List<String> inseqList = new ArrayList<String>();
		// 钢种代码集合
		List<String> gradeCodes = new ArrayList<String>();
		// 钢种名称字符串
		String gradeNameStr = "";
		for (CraftOrdDesignMscPlGzEntity grade : grades) {
			gradeCodes.add(grade.getGradecode());
			gradeNameStr += grade.getGradename() + " ";
		}
		
		// 工序MAP
		HashMap<String, CraftOrdDesignMscPlPrcEntity> processes = new HashMap<String, CraftOrdDesignMscPlPrcEntity>();
		
		// 工序集合
		String[] processCodes = wholeBacklog.split("-");
		OperationDao operationDao = new OperationDao();
		OperationPointDao operationPointDao = new OperationPointDao();
		for (String processCode : processCodes) {
			errMessage = "";
			// if (!processCode.equals("A") && !processCode.equals("D")) {
			// continue;
			// }
			innerEntity.setProcessCode(processCode);
			ProcessEntity processEntity = new ProcessEntity();
			processEntity.setProcessCode(processCode);
			// 查询对应的工序类
			CraftOrdDesignMscPlPrcEntity mscPlPrcEntity = operationDao.getOperation(con, msc, mscPline, processCode);
			processes.put(processCode, mscPlPrcEntity);
			if (mscPlPrcEntity == null) {
				innerEntity.setFlag(false);
				innerEntity.setMessage("制程(" + mscPline + ")缺少工序" + processCode);
				return innerEntity;
			}
			// 工序的工序点集合
			List<CraftOrdDesignMscPlStiEntity> points = operationPointDao.getOperationPoint(con, msc, mscPline,
					processCode);
			if (points == null) {
				innerEntity.setFlag(false);
				innerEntity.setMessage("制程(" + mscPline + ")/工序(" + mscPlPrcEntity.getProcessDesc() + ")缺少工序点!");
				return innerEntity;
			}
			// 工序点代码集合
			List<String> pointCodeList = new ArrayList<String>();
			for (CraftOrdDesignMscPlStiEntity point : points) {
				if (!pointCodeList.contains(point.getStationType())) {
					pointCodeList.add(point.getStationType());
				}
			}
			
			/**
			 * 1. 成分内控标准
			 */
			// 如果有成分工序点，但没有成分索引号
			if(design.getAllowNk().equals("1") || (design.getAllowNk().equals("0") && processCode.equals("A"))){
				// 如果这个制程没有验证这个成分索引号，则需要验证
				String[] inCics = mscPlPrcEntity.getCic().split(",");
				inCics = cleanDuplicate(inCics);
				
				if(mscPlPrcEntity.getCic().equals("")){
					inCics = new String[0];
				}
				List<String> fiterInCics = fiterCic(con, inCics, gradeCodes, processCode, 
						gradeNameStr, design, grades, specEntity);
				if (!errMessage.equals("") && (fiterInCics == null || fiterInCics.size() == 0)) {
					innerEntity.setFlag(false);
					innerEntity.setMessage("制程(" + mscPline + ")/工序(" + mscPlPrcEntity.getProcessDesc() + ")成分内控标准: "
							 + errMessage + "(" + mscPlPrcEntity.getCic() + ")");
					return innerEntity;
				}
				
				if(fiterInCics == null || fiterInCics.size() == 0){
					if (pointCodeList.contains("403201")) {
						innerEntity.setFlag(false);
						innerEntity.setMessage(
								"制程(" + mscPline + ")、工序(" + mscPlPrcEntity.getProcessDesc() + ")存在成分类型工序点,但不存在成分内控标准!");
						return innerEntity;
					}
				}else{
					if (!pointCodeList.contains("403201")) {
						innerEntity.setFlag(false);
						innerEntity.setMessage("制程(" + mscPline + ")/工序(" + mscPlPrcEntity.getProcessDesc()
								+ ")不存在成分类型工序点,但存在成分内控标准(" + mscPlPrcEntity.getCic() + ")!");
						return innerEntity;
					}
					
					
					for (int i = 0; i < fiterInCics.size(); i++) {
						String cic = fiterInCics.get(i);
//						if (!inseqList.contains(cic)) {
//							inseqList.add(cic);
//						} else {
//							continue;
//						}
						// 验证成分标准
						List<String> cics = new ArrayList<String>();
						cics.add(cic);
						//
						groupByProcess(con, cics, mscPlPrcEntity, specEntity, mscPline, design, "CIC", innerEntity, inchems,
								inphys, insmps, inspecs, indetes, inwaters, inprocesses);
						if (!innerEntity.isFlag()) {
							return innerEntity;
						}
					}
					// 修改索引号
					processEntity.setCic(StringUtils.join(fiterInCics.toArray(), ','));
					mscPlPrcEntity.setCic(processEntity.getCic());
				}
			}
			
			/**
			 * 理化内控标准
			 */
			if (design.getAllowNk().equals("1")) {
				// 索引号可能存在多个组成一个字符串
				String[] inPics = mscPlPrcEntity.getPic().split(",");
				inPics = cleanDuplicate(inPics);
				if(mscPlPrcEntity.getPic().equals("")){
					inPics = new String[0];
				}
				List<String> fiterInPics = fiterPic(con, inPics, gradeCodes, processCode, gradeNameStr, design, grades);
				
				if (!errMessage.equals("") && (fiterInPics == null || fiterInPics.size() == 0)) {
					innerEntity.setFlag(false);
					innerEntity.setMessage("制程(" + mscPline + ")/工序(" + mscPlPrcEntity.getProcessDesc() + ")理化内控标准("
							+ mscPlPrcEntity.getPic() + ")" + errMessage);
					return innerEntity;
				}
				
				if(fiterInPics == null || fiterInPics.size() == 0){
					if (pointCodeList.contains("403202")) {
						innerEntity.setFlag(false);
						innerEntity.setMessage(
								"制程(" + mscPline + ")、工序(" + mscPlPrcEntity.getProcessDesc() + ")存在理化类型工序点,但不存在理化内控标准");
						return innerEntity;
					}
				}else{
					if (!pointCodeList.contains("403202")) {
						innerEntity.setFlag(false);
						innerEntity.setMessage("制程(" + mscPline + ")、工序(" + mscPlPrcEntity.getProcessDesc()
								+ ")不存在理化类型工序点,但存在理化内控标准(" + mscPlPrcEntity.getPic() + ")!");
						return innerEntity;
					}
					
					for (int i = 0; i < fiterInPics.size(); i++) {
						String pic = fiterInPics.get(i);
//						if (!inseqList.contains(pic)) {
//							inseqList.add(pic);
//						}
						List<String> pics = new ArrayList<String>();
						pics.add(pic);
						groupByProcess(con, pics, mscPlPrcEntity, specEntity, mscPline, design, "PIC", innerEntity,
								inchems, inphys, insmps, inspecs, indetes, inwaters, inprocesses);
						if (!innerEntity.isFlag()) {
							return innerEntity;
						}
					}
					// 修改索引号
					processEntity.setPic(StringUtils.join(fiterInPics.toArray(), ','));
					mscPlPrcEntity.setPic(processEntity.getPic());
				}
			}
			
			/**
			 * 公差内控标准
			 */
			
			String[] inSics = mscPlPrcEntity.getSic().split(",");
			inSics = cleanDuplicate(inSics);
			if(mscPlPrcEntity.getSic().equals("")){
				inSics = new String[0];
			}
			List<String> fiterInSics = fiterSic(con, inSics, processCode, design);
			
			if (!errMessage.equals("") && (fiterInSics == null || fiterInSics.size() == 0)) {
				innerEntity.setFlag(false);
				innerEntity.setMessage("制程(" + mscPline + ")/工序(" + mscPlPrcEntity.getProcessDesc() + ")公差内控标准("
						+ mscPlPrcEntity.getSic() + ")" + errMessage);
				return innerEntity;
			}
			
			if (fiterInSics == null || fiterInSics.size() == 0) {
				if(mscPlPrcEntity.getProcessCode().equals("D")){
					innerEntity.setFlag(false);
					innerEntity.setMessage(
							"制程(" + mscPline + ")/工序(" + mscPlPrcEntity.getProcessDesc() + ")必须维护公差内控标准!");
					return innerEntity;
				}
				if(mscPlPrcEntity.getProcessCode().equals("E") && !mscPlPrcEntity.getProcessCodeC().equals("B008")){
					innerEntity.setFlag(false);
					innerEntity.setMessage(
							"制程(" + mscPline + ")/工序(" + mscPlPrcEntity.getProcessDesc() + ")/二级工序("
					+ mscPlPrcEntity.getProcessDescC() +")必须维护公差内控标准!");
					return innerEntity;
				}
				if (pointCodeList.contains("403203")) {
					innerEntity.setFlag(false);
					innerEntity.setMessage(
							"制程(" + mscPline + ")/工序(" + mscPlPrcEntity.getProcessDesc() + ")存在公差类型工序点,不存在公差内控标准!");
					return innerEntity;
				}
			}else{
				if (!pointCodeList.contains("403203")) {
					innerEntity.setFlag(false);
					innerEntity.setMessage("制程(" + mscPline + ")工序(" + mscPlPrcEntity.getProcessDesc()
							+ ")不存在公差类型工序点,但存在公差内控标准(" + mscPlPrcEntity.getSic() + ")!");
					return innerEntity;
				}
				
				
				for (int i = 0; i < fiterInSics.size(); i++) {
					String sic = fiterInSics.get(i);
//					if (!inseqList.contains(sic)) {
//						inseqList.add(sic);
//					} else {
//						continue;
//					}
					List<String> sics = new ArrayList<String>();
					sics.add(sic);
					groupByProcess(con, sics, mscPlPrcEntity, specEntity, mscPline, design, "SIC", innerEntity,
							inchems, inphys, insmps, inspecs, indetes, inwaters, inprocesses);
					if (!innerEntity.isFlag()) {
						return innerEntity;
					}
				}
				// 修改索引号
				processEntity.setSic(StringUtils.join(fiterInSics.toArray(), ','));
				mscPlPrcEntity.setSic(processEntity.getSic());
			}

			/**
			 * 探伤内控标准
			 */
			if (design.getAllowNk().equals("1")) {
				String[] inDics = mscPlPrcEntity.getDic().split(",");
				inDics = cleanDuplicate(inDics);
				if(mscPlPrcEntity.getDic().equals("")){
					inDics = new String[0];
				}
				List<String> fiterInDics = fiterDic(con, inDics, processCode, design);
				
				if (!errMessage.equals("") && (fiterInDics == null || fiterInDics.size() == 0)) {
					innerEntity.setFlag(false);
					innerEntity.setMessage("制程(" + mscPline + ")/工序(" + mscPlPrcEntity.getProcessDesc() + ")探伤内控标准("
							+ mscPlPrcEntity.getDic() + ")" + errMessage);
					return innerEntity;
				}
				
				if(fiterInDics == null || fiterInDics.size() == 0){
					if (pointCodeList.contains("403204")) {
						innerEntity.setFlag(false);
						innerEntity.setMessage(
								"制程(" + mscPline + ")/工序(" + mscPlPrcEntity.getProcessDesc() + ")存在探伤类型工序点,不存在探伤内控标准");
						return innerEntity;
					}
				}else{
					if (!pointCodeList.contains("403204")) {
						innerEntity.setFlag(false);
						innerEntity.setMessage("制程(" + mscPline + ")/工序(" + mscPlPrcEntity.getProcessDesc()
								+ ")不存在探伤类型工序点,但存在探伤内控标准(" + mscPlPrcEntity.getDic() + ")!");
						return innerEntity;
					}
					
					for (int i = 0; i < fiterInDics.size(); i++) {
						String dic = fiterInDics.get(i);
//						if (!inseqList.contains(dic)) {
//							inseqList.add(dic);
//						} else {
//							continue;
//						}

						List<String> dics = new ArrayList<String>();
						dics.add(dic);
						groupByProcess(con, dics, mscPlPrcEntity, specEntity, mscPline, design, "DIC", innerEntity,
								inchems, inphys, insmps, inspecs, indetes, inwaters, inprocesses);
						if (!innerEntity.isFlag()) {
							return innerEntity;
						}
					}
					// 修改索引号
					processEntity.setDic(StringUtils.join(fiterInDics.toArray(), ','));
					mscPlPrcEntity.setDic(processEntity.getDic());
				}
			}
			
			/**
			 * 水压内控标准
			 */
			if (design.getAllowNk().equals("1")) {
				String[] inWics = mscPlPrcEntity.getWic().split(",");
				inWics = cleanDuplicate(inWics);
				if(mscPlPrcEntity.getWic().equals("")){
					inWics = new String[0];
				}
				List<String> fiterInWics = fiterWic(con, inWics, processCode, design, specEntity);
				
				if (!errMessage.equals("") && (fiterInWics == null || fiterInWics.size() == 0)) {
					innerEntity.setFlag(false);
					innerEntity.setMessage("制程(" + mscPline + ")/工序(" + mscPlPrcEntity.getProcessDesc() + ")水压内控标准("
							+ mscPlPrcEntity.getWic() + ")" + errMessage);
					return innerEntity;
				}
				
				if(fiterInWics == null || fiterInWics.size() == 0){
					if (pointCodeList.contains("403205")) {
						innerEntity.setFlag(false);
						innerEntity.setMessage(
								"制程(" + mscPline + ")/工序(" + mscPlPrcEntity.getProcessDesc() + ")存在水压类型工序点,没有水压内控标准");
						return innerEntity;
					}
				}else{
					if (!pointCodeList.contains("403205")) {
						innerEntity.setFlag(false);
						innerEntity.setMessage("制程(" + mscPline + ")/工序(" + mscPlPrcEntity.getProcessDesc()
								+ ")不存在水压类型工序点,存在水压内控标准(" + mscPlPrcEntity.getWic() + ")");
						return innerEntity;
					}
					
					for (int i = 0; i < fiterInWics.size(); i++) {
						String wic = fiterInWics.get(i);
//						if (!inseqList.contains(wic)) {
//							inseqList.add(wic);
//						} else {
//							continue;
//						}
						List<String> wics = new ArrayList<String>();
						wics.add(wic);
						groupByProcess(con, wics, mscPlPrcEntity, specEntity, mscPline, design, "WIC", innerEntity,
								inchems, inphys, insmps, inspecs, indetes, inwaters, inprocesses);
						if (!innerEntity.isFlag()) {
							return innerEntity;
						}
					}
					// 修改索引号
					processEntity.setWic(StringUtils.join(fiterInWics.toArray(), ','));
					mscPlPrcEntity.setWic(processEntity.getWic());
				}
			}
			
			/**
			 * 加工内控标准
			 */
			if (design.getAllowNk().equals("1")) {
				String[] inGics = mscPlPrcEntity.getGic().split(",");
				inGics = cleanDuplicate(inGics);
				if(mscPlPrcEntity.getGic().equals("")){
					inGics = new String[0];
				}
				List<String> fiterInGics = fiterGic(con, inGics, processCode, design);
				
				if (!errMessage.equals("") && (fiterInGics == null || fiterInGics.size() == 0)) {
					innerEntity.setFlag(false);
					innerEntity.setMessage("制程(" + mscPline + ")/工序(" + mscPlPrcEntity.getProcessDesc() + ")加工内控标准("
							+ mscPlPrcEntity.getGic() + ")" + errMessage);
					return innerEntity;
				}
				
				if(fiterInGics == null || fiterInGics.size() == 0){
					if (pointCodeList.contains("403208")) {
						innerEntity.setFlag(false);
						innerEntity.setMessage("制程(" + mscPline + ")/工序(" + mscPlPrcEntity.getProcessDesc() + ")"
								+ "存在端部加工类型工序点,不存在加工内控标准!");
						return innerEntity;
					}
				}else{
					if (!pointCodeList.contains("403208")) {
						innerEntity.setFlag(false);
						innerEntity.setMessage("制程(" + mscPline + ")/工序(" + mscPlPrcEntity.getProcessDesc()
								+ ")不存在端部加类型工序点,存在加工内控标准(" + mscPlPrcEntity.getGic() + ")");
						return innerEntity;
					}
					
					for (int i = 0; i < fiterInGics.size(); i++) {
						String gic = fiterInGics.get(i);
//						if (!inseqList.contains(gic)) {
//							inseqList.add(gic);
//						} else {
//							continue;
//						}
						List<String> gics = new ArrayList<String>();
						gics.add(gic);
						groupByProcess(con, gics, mscPlPrcEntity, specEntity, mscPline, design, "GIC", innerEntity,
								inchems, inphys, insmps, inspecs, indetes, inwaters, inprocesses);
						if (!innerEntity.isFlag()) {
							return innerEntity;
						}
					}
					// 修改索引号
					processEntity.setGic(StringUtils.join(fiterInGics.toArray(), ','));
					mscPlPrcEntity.setGic(processEntity.getGic());
				}
			}
			processList.add(processEntity);
		}
		
		List<CraftOrdDesignStdCicEntity> msc0Chems = InnerStdDao.getCraftMsc0Chem(con, design.getDesignKey());
		List<CraftOrdDesignStdCicEntity> mscNChems = InnerStdDao.getCraftMscNChem(con, design.getDesignKey());
		//**************************   验证内控是否包含交付标准  && !con.toString().contains("172.16.2.128")
		if(design.getAllowNk().equals("1") ){
			String result = CheckNkComplete(con, design.getDesignKey(), msc, mscPline, processes,
					innerEntity, msc0Chems, mscNChems);
			if(!result.equals("")){
				innerEntity.setFlag(false);
				innerEntity.setMessage(result);
				return innerEntity;
			}
		}
		
		List<CraftOrdDesignStdCicEntity> jfChems = InnerStdDao.getCraftJfChem(con, design.getDesignKey());
		String jfValueMsg = checkNkJfChemValue(jfChems, innerEntity.getChems());
		if(!jfValueMsg.equals("")){
			innerEntity.setFlag(false);
			innerEntity.setMessage(jfValueMsg);
			return innerEntity;
		}
		
		innerEntity.setFlag(true);
		innerEntity.setMessage("内控标准通过验证!");
		return innerEntity;
	}
	
	/**
	 * 去掉重复字符串数组。
	 * @param ary
	 * @return
	 */
	private String[] cleanDuplicate(String[] ary){
		List<String> list = new ArrayList<String>();
		for(String str : ary){
			if(!list.contains(str)){
				list.add(str);
			}
		}
		
		return list.toArray(new String[1]);
	}

	/**
	 * 过滤成分索引号
	 * 
	 * @param con
	 * @param cics
	 *            成分索引号集合
	 * @param gradeCodes
	 *            钢种集合
	 *            扣型
	 *            钢级
	 * @param processCode
	 *            工序
	 *            品名
	 * @return
	 * @throws SQLException
	 */
	private List<String> fiterCic(Connection con, String[] cics, List<String> gradeCodes, 
			String processCode, String gradeNameStr, CraftEntity design,
			List<CraftOrdDesignMscPlGzEntity> grades, SpecEntity specEntity) throws SQLException {
		errMessage = "";
		InnerStdDao InnerStdDao = new InnerStdDao();
		List<String> list = new ArrayList<String>();
		List<String> gradelist = new ArrayList<String>();

		boolean purchaseStd = false;
		boolean ownStd = false;
		for (String cic : cics) {
			ComMscStdCicEntity cicInfo = InnerStdDao.getCicInfo(con, cic, design.getModelCode(), gradeCodes);
			if (cicInfo == null) {
				//errMessage = cic + " 不是有效数据!";
				continue;
			}
			
			// 通过外径、壁厚过滤成分主记录
			String dimater = "";
			String height = "";
//			if(processCode.equals("D")){
//				for (CraftOrdDesignMscGzGgEntity rollSpec : specEntity.getRollSpecs()) {
//					dimater = rollSpec.getDimater();
//					height = rollSpec.getHeight();
//					if(!CraftTool.checkStr(dimater, cicInfo.getMinDSign(), cicInfo.getMinD())
//							|| !CraftTool.checkStr(dimater, cicInfo.getMaxDSign(), cicInfo.getMaxD())
//							|| !CraftTool.checkStr(height, cicInfo.getMinDSign(), cicInfo.getMinD())
//							|| !CraftTool.checkStr(height, cicInfo.getMaxDSign(), cicInfo.getMaxD())){
//						errMessage = "不满足轧制规格（外径：" + dimater + " 壁厚：" + height + "）";
//						continue;
//					}
//				}
//			}else if(processCode.equals("C")){
//				for (CraftOrdDesignMscBiltEntity billSpec : specEntity.getBillSpecs()) {
//					dimater = billSpec.getBSpecName();
//					if(!CraftTool.checkStr(dimater, cicInfo.getMinDSign(), cicInfo.getMinD())
//							|| !CraftTool.checkStr(dimater, cicInfo.getMaxDSign(), cicInfo.getMaxD())){
//						errMessage = "不满足锻造规格（直径：" + dimater + "）";
//						continue;
//					}
//				}
//			}else if(processCode.equals("B")){
//				for (CraftOrdDesignMscBiltCEntity billSpecC : specEntity.getBillSpecCs()) {
//					dimater = billSpecC.getCSpecName();
//					if(!CraftTool.checkStr(dimater, cicInfo.getMinDSign(), cicInfo.getMinD())
//							|| !CraftTool.checkStr(dimater, cicInfo.getMaxDSign(), cicInfo.getMaxD())){
//						errMessage = "不满足铸造规格（直径：" + dimater + "）";
//						continue;
//					}
//				}
//			}else{
//				dimater = design.getDimater();
//				height = design.getHeight();
//				if(!CraftTool.checkStr(dimater, cicInfo.getMinDSign(), cicInfo.getMinD())
//						|| !CraftTool.checkStr(dimater, cicInfo.getMaxDSign(), cicInfo.getMaxD())
//						|| !CraftTool.checkStr(height, cicInfo.getMinHSign(), cicInfo.getMinH())
//						|| !CraftTool.checkStr(height, cicInfo.getMaxHSign(), cicInfo.getMaxH())){
//					errMessage = "不满足合同规格（外径：" + dimater + " 壁厚：" + height + "）";
//					continue;
//				}
//			}
			
			dimater = design.getDimater();
			height = design.getHeight();
			if(!CraftTool.checkStr(dimater, cicInfo.getMinDSign(), cicInfo.getMinD())
					|| !CraftTool.checkStr(dimater, cicInfo.getMaxDSign(), cicInfo.getMaxD())
					|| !CraftTool.checkStr(height, cicInfo.getMinHSign(), cicInfo.getMinH())
					|| !CraftTool.checkStr(height, cicInfo.getMaxHSign(), cicInfo.getMaxH())){
				errMessage = "不满足合同规格（外径：" + dimater + " 壁厚：" + height + "）";
				continue;
			}
			
			// 验证扣型
			if (!cicInfo.getModelCodeNk().equals("")) {
				if (!cicInfo.getModelCodeNk().contains(design.getModelCode())) {
					errMessage = "扣型 " + cicInfo.getModelDescNk() + "不符合合同扣型 " + design.getModelDesc();
					continue;
				}
			}
			// 验证钢级
			if (!cicInfo.getSteelcodeNk().equals("")) {
				if (!cicInfo.getSteelcodeNk().contains(design.getSteelCode())) {
					errMessage = "钢级 " + cicInfo.getSteelnameNk() + "不符合合同钢级 " + design.getSteelName();
					continue;
				}
			}
			// 工序
			if (!cicInfo.getProcessCode().equals("")) {
				if (!cicInfo.getProcessCode().contains(processCode)) {
					errMessage = "工序 " + cicInfo.getProcessDesc() + "不符合制程工序 ";
					continue;
				}
			}
			// 品名
			if (!cicInfo.getProduccodeNk().equals("")) {
				if (!cicInfo.getProduccodeNk().contains(design.getProducCode())) {
					errMessage = "品名 " + cicInfo.getProducnameNk() + "不符合合同品名 " + design.getProducDesc();
					continue;
				}
			}
			if(!cicInfo.getModelCodeNk().equals("")){
				if(!cicInfo.getModelCodeNk().contains(design.getModelCode())){
					errMessage = "扣型 " + cicInfo.getModelDescNk() + "不符合合同扣型 " + design.getModelDesc();
					continue;
				}
			}
			// 验证钢种
//			String gradeCodeStr = cicInfo.getGradecode();
//			if (gradeCodeStr.equals("")) {
//				errMessage = "必须维护钢种!";
//				continue;
//			}
//			boolean flag = false;
//			for (CraftOrdDesignMscPlGzEntity grade : grades) {
//				if (gradeCodeStr.contains(grade.getGradecode())) {
//					gradelist.add(grade.getGradecode());
//					flag = true;
//					
//					if(design.getOutsBilietFl().equals("121801")){
//						if(grade.getAllowBuy().equals("1") && !cicInfo.getPurchaseStd().equals("1")){
//							errMessage = " 外购钢种:" + grade.getGradename() + "不能维护在非外购协议标准的成分索引号"+ cicInfo.getCic() +"中！";
//							//errMessage = " 成分索引号:"+ cicInfo.getCic() +"不属于外购协议标准，不能选择外购钢种！";
//							return null;
//						}
//					}
//				}
//			}
//			if (!flag) {
//				errMessage = "验证通过的钢种:" + gradeNameStr + ",成分内控标准:"+ cicInfo.getCic() + "不能钢种!";
//				continue;
//			}
			if (cicInfo.getPurchaseStd().equals("1")) {
				purchaseStd = true;
			}else{
				ownStd = true;
			}
			list.add(cic);
		}
		
		//钢种
		for (CraftOrdDesignMscPlGzEntity grade : grades) {
			boolean existGrade = false;
			for (String cic : cics) {
				ComMscStdCicEntity cicInfo = InnerStdDao.getCicInfo(con, cic, design.getModelCode(), gradeCodes);
				if (cicInfo == null) {
					//errMessage = "找不到成分内控！";
					continue;
				}
				
				// 验证钢种
				if (cicInfo.getGradecode().equals("")) {
					errMessage = "：该成分内控必须维护适用钢种!";
					list.clear();
					return null;
				}
				
				if(cicInfo.getGradecode().contains(grade.getGradecode())){
//					if(design.getOutsBilietFl().equals("121801")){
//						if(grade.getAllowBuy().equals("1") && !cicInfo.getPurchaseStd().equals("1")){
//							errMessage = " 外购钢种:" + grade.getGradename() + "不能维护在非外购协议标准的成分索引号"+ cicInfo.getCic() +"中！";
//							//errMessage = " 成分索引号:"+ cicInfo.getCic() +"不属于外购协议标准，不能选择外购钢种！";
//							list.clear();
//							return null;
//						}
//					}
					existGrade = true;
					break;
				}
			}
			
			if (cics.length > 0 && !existGrade) {
				errMessage = "：该成分内控适用钢种不包含制程中维护的钢种:" + gradeNameStr;
				list.clear();
				break;
			}
		}

		if(cics.length > 0){
			// 外购坯合同必须找到一条外购协议标准(炼钢，铸造，锻造验证外购坯 轧管验证外购管)
			if (processCode.equals("A") || processCode.equals("B") || processCode.equals("C")) {
				if (design.getOutsBilietFl().equals("121801") && !purchaseStd && errMessage.equals("")) {
					errMessage = " :该合同行允许外购坯，但系统中未找到满足外购的制程(" + GetProcessDesc(processCode) + "工序选择的成分索引号中不存在可用的外购协议标准)";
					return null;
				}
			}
			if (processCode.equals("D")) {
				if ((design.getOutsStlPipeFl().equals("121902") || design.getOutsStlPipeFl().equals("121903"))
						&& !purchaseStd && errMessage.equals("")) {
					errMessage = " :该合同行允许外购管，但系统中未找到满足外购的制程(" + GetProcessDesc(processCode) + "工序选择的成分索引号中不存在可用的外购协议标准)";
					return null;
				}
			}
			
			//自炼必须拿到至少一个自炼内控
			if (processCode.equals("A")) {
				if (design.getOutsBilietFl().equals("121802") && !ownStd && errMessage.equals("")) {
					errMessage = " :该合同行是自炼坯，但系统中未找到满足自炼的制程(" + GetProcessDesc(processCode) + "工序选择的成分索引号中不存在可用的自炼索引号)";
					return null;
				}
			}
			
//			if (processCode.equals("D")) {
//				if (design.getOutsStlPipeFl().equals("121901") && !ownStd && errMessage.equals("")) {
//					errMessage = " :该合同行是自炼管，但系统中未找到满足自炼的制程(" + GetProcessDesc(processCode) + "工序选择的成分索引号中不存在可用的自炼标准)";
//					return null;
//				}
//			}
		}
		
		//外购管必须拿到炼钢的成分索引码（不区分自炼还是采购标准）
		if (cics.length == 0 && processCode.equals("A")) {
			if ((design.getOutsStlPipeFl().equals("121902") || design.getOutsStlPipeFl().equals("121903"))
					&& errMessage.equals("")) {
				errMessage = " :该合同行允许外购管，系统没有找到炼钢成分索引码！";
				return null;
			}
		}
		
		return list;
	}

	/**
	 * 过滤理化内控索引号
	 * 
	 * @param con
	 * @param pics
	 * @param gradeCodes
	 * @param processCode
	 * @return
	 * @throws SQLException
	 */
	private List<String> fiterPic(Connection con, String[] pics, List<String> gradeCodes, String processCode,
			String gradeNameStr, CraftEntity design, List<CraftOrdDesignMscPlGzEntity> grades) throws SQLException {
		errMessage = "";
		InnerStdDao InnerStdDao = new InnerStdDao();
		List<String> list = new ArrayList<String>();

		boolean purchaseStd = false;
		List<String> gradeList = new ArrayList<String>();
		for (String pic : pics) {
			ComMscStdPicEntity entity = InnerStdDao.getPicInfo(con, pic, design.getModelCode(), gradeCodes);
			if (entity == null) {
				continue;
			}
			// 验证钢种
//			boolean flag = false;
//			if (!entity.getGradecode().equals("")) {
//				String gradeCodeStr = entity.getGradecode();
//				for (CraftOrdDesignMscPlGzEntity grade : grades) {
//					if (gradeCodeStr.contains(grade.getGradecode())) {
//						flag = true;
//						gradeList.add(grade.getGradecode());
//						
//						if(design.getOutsBilietFl().equals("121801")){
//							if(grade.getAllowBuy().equals("1") && !entity.getPurchaseStd().equals("1")){
//								errMessage = " 外购钢种:" + grade.getGradename() + "不能维护在非外购协议标准的理化索引号"+ entity.getPic() +"中！";
//								return null;
//							}
//						}
//					}
//				}
//			} else {
//				gradeList.add("");
//				flag = true;
//			}
//			if (!flag) {
//				errMessage = "钢种 " + entity.getGradename() + "不满足制程验证通过的钢种 " + gradeNameStr;
//				continue;
//			}
			// 验证扣型
			if (!entity.getModelCode().equals("")) {
				if (!entity.getModelCode().contains(design.getModelCode())) {
					errMessage = "扣型 " + entity.getModelDesc() + "不符合合同扣型 " + design.getModelDesc();
					continue;
				}
			}
			
			// 验证钢级
			if (entity.getSteelcodeNk().equals("")) {
				errMessage = "必须维护钢级 ";
				continue;
			} else {
				if (!entity.getSteelcodeNk().contains(design.getSteelCode())) {
					errMessage = "钢级 " + entity.getSteelnameNk() + "不符合合同钢级 " + design.getSteelName();
					continue;
				}
			}
			// 工序
			if (!entity.getProcessCdoe().equals("")) {
				if (!entity.getProcessCdoe().contains(processCode)) {
					errMessage = "工序 " + entity.getProcessDesc() + "不符合制程工序 ";
					continue;
				}
			}
			// 吕名
			if (!entity.getProduccodeNk().equals("")) {
				if (!entity.getProduccodeNk().contains(design.getProducCode())) {
					errMessage = "品名 " + entity.getProducnameNk() + "不符合合同品名 " + design.getProducDesc();
					continue;
				}
			}
			if(!entity.getModelCodeNk().equals("")){
				if(!entity.getModelCodeNk().contains(design.getModelCode())){
					errMessage = "扣型 " + entity.getModelDescNk() + "不符合合同扣型 " + design.getModelDesc();
					continue;
				}
			}
			if (entity.getPurchaseStd().equals("1")) {
				purchaseStd = true;
			}
			list.add(pic);
		}
		
		//钢种
		for (CraftOrdDesignMscPlGzEntity grade : grades) {
			boolean existGrade = false;
			for (String pic : pics) {
				ComMscStdPicEntity entity = InnerStdDao.getPicInfo(con, pic, design.getModelCode(), gradeCodes);
				if (entity == null) {
					//errMessage = "找不到理化内控！";
					continue;
				}
				// 验证钢种 理化可以不维护钢种
//				if (entity.getGradecode().equals("")) {
//					errMessage = "理化内控:" + entity.getPic() + "必须维护适用钢种!";
//					list.clear();
//					return null;
//				}

				if(entity.getGradecode().equals("") || entity.getGradecode().contains(grade.getGradecode())){
//					if(design.getOutsBilietFl().equals("121801")){
//						if(grade.getAllowBuy().equals("1") && !entity.getPurchaseStd().equals("1")){
//							errMessage = " 外购钢种:" + grade.getGradename() + "不能维护在非外购协议标准的理化索引号"+ entity.getPic() +"中！";
//							list.clear();
//							return null;
//						}
//					}
					existGrade = true;
					break;
				}
			}
			
			if (pics.length > 0 && !existGrade) {
				errMessage = "：该理化内控适用钢种不包含制程中维护的钢种:" + gradeNameStr;
				list.clear();
				break;
			}
		}

//		if(pics.length > 0){
//			// 外购坯合同必须找到一条外购协议标准(炼钢，铸造，锻造验证外购坯 轧管验证外购管)
//			if (processCode.equals("A") || processCode.equals("B") || processCode.equals("C")) {
//				if (design.getOutsBilietFl().equals("121801") && !purchaseStd && errMessage.equals("")) {
//					errMessage = " :该合同行允许外购坯，但系统中未找到满足外购的制程(" + GetProcessDesc(processCode) + "工序选择的理化索引号中不存在可用的外购协议标准)";
//					return null;
//				}
//			}
//			if (processCode.equals("D")) {
//				if ((design.getOutsStlPipeFl().equals("121902") || design.getOutsStlPipeFl().equals("121903"))
//						&& !purchaseStd && errMessage.equals("")) {
//					errMessage = " :该合同行允许外购管，但系统中未找到满足外购的制程(" + GetProcessDesc(processCode) + "工序选择的理化索引号中不存在可用的外购协议标准)";
//					return null;
//				}
//			}
//		}
		
		return list;
	}

	private String GetProcessDesc(String processCode) {
		if (processCode.equals("A")) {
			return "炼钢";
		} else if (processCode.equals("B")) {
			return "铸造";
		} else if (processCode.equals("C")) {
			return "锻造";
		} else if (processCode.equals("D")) {
			return "轧制";
		} else if (processCode.equals("E")) {
			return "镦拔扩";
		} else if (processCode.equals("F")) {
			return "热处理";
		} else if (processCode.equals("G")) {
			return "加工";
		} else if (processCode.equals("H")) {
			return "接箍加工";
		} else
			return "";
	}

	/**
	 * 过滤公差标准
	 * 
	 * @param con
	 * @param sics
	 * @param processCode
	 * @return
	 * @throws SQLException
	 */
	private List<String> fiterSic(Connection con, String[] sics, String processCode, CraftEntity design)
			throws SQLException {
		errMessage = "";
		InnerStdDao InnerStdDao = new InnerStdDao();
		List<String> list = new ArrayList<String>();

		boolean purchaseStd = false;
		for (String sic : sics) {
			ComMscStdSpecEntity entity = InnerStdDao.getSicInfo(con, sic, design.getModelCode());
			if (entity == null) {
				continue;
			}
			
			// 验证扣型
			if (!entity.getModelCode().equals("")) {
				if (!entity.getModelCode().contains(design.getModelCode())) {
					errMessage = "扣型 " + entity.getModelDesc() + "不符合合同扣型 " + design.getModelDesc();
					continue;
				}
			}
			// 验证钢级
			if (!entity.getSteelcodeNk().equals("")) {
				if (!entity.getSteelcodeNk().contains(design.getSteelCode())) {
					errMessage = "钢级 " + entity.getSteelnameNk() + "不符合合同钢级 " + design.getSteelName();
					continue;
				}
			}
			// 工序
			if (!entity.getProcessCode().equals("")) {
				if (!entity.getProcessCode().contains(processCode)) {
					errMessage = "工序 " + entity.getProcessDesc() + "不符合制程工序 ";
					continue;
				}
			}
			// 吕名
			if (!entity.getProduccodeNk().equals("")) {
				if (!entity.getProduccodeNk().contains(design.getProducCode())) {
					errMessage = "品名 " + entity.getProducnameNk() + "不符合合同品名 " + design.getProducDesc();
					continue;
				}
			}
			if(!entity.getModelCodeNk().equals("")){
				if(!entity.getModelCodeNk().contains(design.getModelCode())){
					errMessage = "扣型 " + entity.getModelDescNk() + "不符合合同扣型 " + design.getModelDesc();
					continue;
				}
			}
			if (entity.getPurchaseStd().equals("1")) {
				purchaseStd = true;
			}
			list.add(sic);
		}

//		if(sics.length > 0){
//			// 外购坯合同必须找到一条外购协议标准(炼钢，铸造，锻造验证外购坯 轧管验证外购管)
//			if (processCode.equals("A") || processCode.equals("B") || processCode.equals("C")) {
//				if (design.getOutsBilietFl().equals("121801") && !purchaseStd && errMessage.equals("")) {
//					errMessage = " :该合同行允许外购坯，但系统中未找到满足外购的制程(" + GetProcessDesc(processCode) + "工序选择的公差索引号中不存在可用的外购协议标准)";
//					return null;
//				}
//			}
//			if (processCode.equals("D")) {
//				if ((design.getOutsStlPipeFl().equals("121902") || design.getOutsStlPipeFl().equals("121903"))
//						&& !purchaseStd && errMessage.equals("")) {
//					errMessage = " :该合同行允许外购管，但系统中未找到满足外购的制程(" + GetProcessDesc(processCode) + "工序选择的公差索引号中不存在可用的外购协议标准)";
//					return null;
//				}
//			}
//		}
		
		return list;
	}

	/**
	 * 过滤探伤索引号
	 * 
	 * @param con
	 * @param dics
	 * @param processCode
	 * @return
	 * @throws SQLException
	 */
	private List<String> fiterDic(Connection con, String[] dics, String processCode, CraftEntity design)
			throws SQLException {
		errMessage = "";
		InnerStdDao InnerStdDao = new InnerStdDao();
		List<String> list = new ArrayList<String>();

		boolean purchaseStd = false;
		for (String dic : dics) {
			ComMscStdDetectionEntity entity = InnerStdDao.getDicInfo(con, dic, design.getModelCode());
			if (entity == null) {
				continue;
			}
			// 验证扣型
			if (!entity.getModelCode().equals("")) {
				if (!entity.getModelCode().contains(design.getModelCode())) {
					errMessage = "扣型 " + entity.getModelDesc() + "不符合合同扣型 " + design.getModelDesc();
					continue;
				}
			}
			// 验证钢级
			if (!entity.getSteelcodeNk().equals("")) {
				if (!entity.getSteelcodeNk().contains(design.getSteelCode())) {
					errMessage = "钢级 " + entity.getSteelnameNk() + "不符合合同钢级 " + design.getSteelName();
					continue;
				}
			}
			// 工序
			if (!entity.getProcessCode().equals("")) {
				if (!entity.getProcessCode().contains(processCode)) {
					errMessage = "工序 " + entity.getProcessDesc() + "不符合制程工序 ";
					continue;
				}
			}
			// 吕名
			if (!entity.getProduccodeNk().equals("")) {
				if (!entity.getProduccodeNk().contains(design.getProducCode())) {
					errMessage = "品名 " + entity.getProducnameNk() + "不符合合同品名 " + design.getProducDesc();
					continue;
				}
			}
			if(!entity.getModelCodeNk().equals("")){
				if(!entity.getModelCodeNk().contains(design.getModelCode())){
					errMessage = "扣型 " + entity.getModelDescNk() + "不符合合同扣型 " + design.getModelDesc();
					continue;
				}
			}
			// 标准
			if (!entity.getStdCodeSNk().equals("")) {
				if (!entity.getStdCodeSNk().contains(design.getStdCode())) {
					errMessage = "产品标准 " + entity.getStdNameSNk() + "不符合合同产品标准 " + design.getStdName();
					continue;
				}
			}
			// 标准类别
			if (!entity.getStdStyleSNk().equals("")) {
				if (!entity.getStdStyleSNk().contains(design.getStdStyle())) {
					errMessage = "产品标准类别 " + entity.getStdStyleDescSNk() + "不符合合同产品标准类别 " + design.getStdStyleDesc();
					continue;
				}
			}
			if (entity.getPurchaseStd().equals("1")) {
				purchaseStd = true;
			}
			list.add(dic);
		}
		
//		if(dics.length > 0){
//			// 外购坯合同必须找到一条外购协议标准(炼钢，铸造，锻造验证外购坯 轧管验证外购管)
//			if (processCode.equals("A") || processCode.equals("B") || processCode.equals("C")) {
//				if (design.getOutsBilietFl().equals("121801") && !purchaseStd && errMessage.equals("")) {
//					errMessage = " :该合同行允许外购坯，但系统中未找到满足外购的制程(" + GetProcessDesc(processCode) + "工序选择的探伤索引号中不存在可用的外购协议标准)";
//					return null;
//				}
//			}
//			if (processCode.equals("D")) {
//				if ((design.getOutsStlPipeFl().equals("121902") || design.getOutsStlPipeFl().equals("121903"))
//						&& !purchaseStd && errMessage.equals("")) {
//					errMessage = " :该合同行允许外购管，但系统中未找到满足外购的制程(" + GetProcessDesc(processCode) + "工序选择的探伤索引号中不存在可用的外购协议标准)";
//					return null;
//				}
//			}
//		}
		

		return list;
	}

	/**
	 * 过滤加工索引号
	 * 
	 * @param con
	 * @param gics
	 * @param processCode
	 * @param design
	 * @return
	 * @throws SQLException
	 */
	private List<String> fiterGic(Connection con, String[] gics, String processCode, CraftEntity design)
			throws SQLException {
		errMessage = "";
		InnerStdDao InnerStdDao = new InnerStdDao();
		List<String> list = new ArrayList<String>();
		boolean purchaseStd = false;
		for (String gic : gics) {
			ComMscStdProcessEntity entity = InnerStdDao.getGicInfo(con, gic, design.getModelCode());
			if (entity == null) {
				continue;
			}
			// 验证扣型
			if (!entity.getModelCode().equals("")) {
				if (!entity.getModelCode().contains(design.getModelCode())) {
					errMessage = "扣型 " + entity.getModelDesc() + "不符合合同扣型 " + design.getModelDesc();
					continue;
				}
			}
			// 验证钢级
			if (!entity.getSteelcodeNk().equals("")) {
				if (!entity.getSteelcodeNk().contains(design.getSteelCode())) {
					errMessage = "钢级 " + entity.getSteelnameNk() + "不符合合同钢级 " + design.getSteelName();
					continue;
				}
			}
			// 工序
			if (!entity.getProcessCdoe().equals("")) {
				if (!entity.getProcessCdoe().contains(processCode)) {
					errMessage = "工序 " + entity.getProcessDesc() + "不符合制程工序 ";
					continue;
				}
			}
			// 吕名
			if (!entity.getProduccodeNk().equals("")) {
				if (!entity.getProduccodeNk().contains(design.getProducCode())) {
					errMessage = "品名 " + entity.getProducnameNk() + "不符合合同品名 " + design.getProducDesc();
					continue;
				}
			}
			if(!entity.getModelCodeNk().equals("")){
				if(!entity.getModelCodeNk().contains(design.getModelCode())){
					errMessage = "扣型 " + entity.getModelDescNk() + "不符合合同扣型 " + design.getModelDesc();
					continue;
				}
			}
			if (entity.getPurchaseStd().equals("1")) {
				purchaseStd = true;
			}
			list.add(gic);
		}
		
//		if(gics.length > 0){
//			// 外购坯合同必须找到一条外购协议标准(炼钢，铸造，锻造验证外购坯 轧管验证外购管)
//			if (processCode.equals("A") || processCode.equals("B") || processCode.equals("C")) {
//				if (design.getOutsBilietFl().equals("121801") && !purchaseStd && errMessage.equals("")) {
//					errMessage = " :该合同行允许外购坯，但系统中未找到满足外购的制程(" + GetProcessDesc(processCode) + "工序选择的加工索引号中不存在可用的外购协议标准)";
//					return null;
//				}
//			}
//			if (processCode.equals("D")) {
//				if ((design.getOutsStlPipeFl().equals("121902") || design.getOutsStlPipeFl().equals("121903"))
//						&& !purchaseStd && errMessage.equals("")) {
//					errMessage = " :该合同行允许外购管，但系统中未找到满足外购的制程(" + GetProcessDesc(processCode) + "工序选择的加工索引号中不存在可用的外购协议标准)";
//					return null;
//				}
//			}
//		}
		

		return list;
	}

	/**
	 * 过滤水压索引号
	 * 
	 * @param con
	 * @param wics
	 * @param processCode
	 * @param design
	 * @return
	 * @throws SQLException
	 */
	private List<String> fiterWic(Connection con, String[] wics, String processCode,
			CraftEntity design, SpecEntity specEntity)
			throws SQLException {
		errMessage = "";
		InnerStdDao InnerStdDao = new InnerStdDao();
		List<String> list = new ArrayList<String>();
		boolean purchaseStd = false;
		for (String wic : wics) {
			ComMscStdWaterEntity entity = InnerStdDao.getWicInfo(con, wic, design.getModelCode());
			if (entity == null) {
				continue;
			}
			// 验证扣型
			if (!entity.getModelCode().equals("")) {
				if (!entity.getModelCode().contains(design.getModelCode())) {
					errMessage = "扣型 " + entity.getModelDesc() + "不符合合同扣型 " + design.getModelDesc();
					continue;
				}
			}
			// 验证钢级
			if (!entity.getSteelcodeNk().equals("")) {
				if (!entity.getSteelcodeNk().contains(design.getSteelCode())) {
					errMessage = "钢级 " + entity.getSteelnameNk() + "不符合合同钢级 " + design.getSteelName();
					continue;
				}
			}
			// 工序
			if (!entity.getProcessCdoe().equals("")) {
				if (!entity.getProcessCdoe().contains(processCode)) {
					errMessage = "工序 " + entity.getProcessDesc() + "不符合制程工序 ";
					continue;
				}
			}
			// 吕名
			if (!entity.getProduccodeNk().equals("")) {
				if (!entity.getProduccodeNk().contains(design.getProducCode())) {
					errMessage = "品名 " + entity.getProducnameNk() + "不符合合同品名 " + design.getProducDesc();
					continue;
				}
			}
			if(!entity.getModelCodeNk().equals("")){
				if(!entity.getModelCodeNk().contains(design.getModelCode())){
					errMessage = "扣型 " + entity.getModelDescNk() + "不符合合同扣型 " + design.getModelDesc();
					continue;
				}
			}
			
			//验证规格。
			String dimater = design.getDimater();
			String height = design.getHeight();
			boolean specCheck = true;
			// 根据工序验证设置不同的外径与壁厚
			if (processCode.equals("D")) {
				// 如果是轧管
				List<CraftOrdDesignMscGzGgEntity> rollSpecs = specEntity.getRollSpecs();
				for (CraftOrdDesignMscGzGgEntity rollSpec : rollSpecs) {
					design.setDimater(rollSpec.getDimater());
					design.setHeight(rollSpec.getHeight());
					design.setSpecStyle("A");
					if(!entity.getMinD().equals("")){
						if(Double.parseDouble(design.getDimater()) < Double.parseDouble(entity.getMinD())){
							errMessage = "最小外径 " + entity.getMinD() + "不符合轧管外径 " + design.getDimater();
							specCheck = false;
							break;
						}
					}
					if(!entity.getMaxD().equals("")){
						if(Double.parseDouble(design.getDimater()) > Double.parseDouble(entity.getMaxD())){
							errMessage = "最大外径 " + entity.getMinD() + "不符合轧管外径 " + design.getDimater();
							specCheck = false;
							break;
						}
					}
					if(!entity.getMinH().equals("")){
						if(Double.parseDouble(design.getHeight()) < Double.parseDouble(entity.getMinH())){
							errMessage = "最小壁厚 " + entity.getMinH() + "不符合轧管壁厚 " + design.getHeight();
							specCheck = false;
							break;
						}
					}
					if(!entity.getMaxH().equals("")){
						if(Double.parseDouble(design.getHeight()) > Double.parseDouble(entity.getMaxH())){
							errMessage = "最大壁厚 " + entity.getMaxH() + "不符合轧管壁厚 " + design.getHeight();
							specCheck = false;
							break;
						}
					}
				}
			} else if (processCode.equals("C")) {
				List<CraftOrdDesignMscBiltEntity> billSpecs = specEntity.getBillSpecs();
				for (CraftOrdDesignMscBiltEntity billSpec : billSpecs) {
					design.setDimater(billSpec.getBSpecName());
					design.setHeight("");
					design.setSpecStyle("B");
					if(!entity.getMinD().equals("")){
						if(Double.parseDouble(design.getDimater()) < Double.parseDouble(entity.getMinD())){
							errMessage = "最小外径 " + entity.getMinD() + "不符合锻造外径 " + design.getDimater();
							specCheck = false;
							break;
						}
					}
					if(!entity.getMaxD().equals("")){
						if(Double.parseDouble(design.getDimater()) > Double.parseDouble(entity.getMaxD())){
							errMessage = "最大外径 " + entity.getMinD() + "不符合锻造外径 " + design.getDimater();
							specCheck = false;
							break;
						}
					}
				}
			} else if (processCode.equals("B")) {
				List<CraftOrdDesignMscBiltCEntity> billSpecCs = specEntity.getBillSpecCs();
				for (CraftOrdDesignMscBiltCEntity billSpecC : billSpecCs) {
					String specName = billSpecC.getCSpecName();
					if (CraftTool.isNumeric(specName)) {
						design.setDimater(specName);
						design.setHeight("");
						design.setSpecStyle("B");
						if(!entity.getMinD().equals("")){
							if(Double.parseDouble(design.getDimater()) < Double.parseDouble(entity.getMinD())){
								errMessage = "最小外径 " + entity.getMinD() + "不符合铸造外径 " + design.getDimater();
								specCheck = false;
								break;
							}
						}
						if(!entity.getMaxD().equals("")){
							if(Double.parseDouble(design.getDimater()) > Double.parseDouble(entity.getMaxD())){
								errMessage = "最大外径 " + entity.getMinD() + "不符合铸造外径 " + design.getDimater();
								specCheck = false;
								break;
							}
						}
					} else {
						
					}
				}
			} else {
				if(!entity.getMinD().equals("")){
					if(Double.parseDouble(design.getDimater()) < Double.parseDouble(entity.getMinD())){
						errMessage = "最小外径 " + entity.getMinD() + "不符合合同外径 " + design.getDimater();
						specCheck = false;
					}
				}
				if(!entity.getMaxD().equals("")){
					if(Double.parseDouble(design.getDimater()) > Double.parseDouble(entity.getMaxD())){
						errMessage = "最大外径 " + entity.getMinD() + "不符合合同外径 " + design.getDimater();
						specCheck = false;
					}
				}
				if(!entity.getMinH().equals("")){
					if(Double.parseDouble(design.getHeight()) < Double.parseDouble(entity.getMinH())){
						errMessage = "最小壁厚 " + entity.getMinH() + "不符合合同壁厚 " + design.getHeight();
						specCheck = false;
					}
				}
				if(!entity.getMaxH().equals("")){
					if(Double.parseDouble(design.getHeight()) > Double.parseDouble(entity.getMaxH())){
						errMessage = "最大壁厚 " + entity.getMaxH() + "不符合合同壁厚 " + design.getHeight();
						specCheck = false;
					}
				}
			}
			design.setDimater(dimater);
			design.setHeight(height);
			if(!specCheck){
				continue;
			}
			
			if (entity.getPurchaseStd().equals("1")) {
				purchaseStd = true;
			}
			list.add(wic);
		}
		
//		if(wics.length > 0){
//			// 外购坯合同必须找到一条外购协议标准(炼钢，铸造，锻造验证外购坯 轧管验证外购管)
//			if (processCode.equals("A") || processCode.equals("B") || processCode.equals("C")) {
//				if (design.getOutsBilietFl().equals("121801") && !purchaseStd && errMessage.equals("")) {
//					errMessage = " :该合同行允许外购坯，但系统中未找到满足外购的制程(" + GetProcessDesc(processCode) + "工序选择的水压索引号中不存在可用的外购协议标准)";
//					return null;
//				}
//			}
//			if (processCode.equals("D")) {
//				if ((design.getOutsStlPipeFl().equals("121902") || design.getOutsStlPipeFl().equals("121903"))
//						&& !purchaseStd && errMessage.equals("")) {
//					errMessage = " :该合同行允许外购管，但系统中未找到满足外购的制程(" + GetProcessDesc(processCode) + "工序选择的水压索引号中不存在可用的外购协议标准)";
//					return null;
//				}
//			}
//		}
		

		return list;
	}

	/**
	 * 验证成分
	 * 
	 * @param con
	 * @param innerEntity
	 * @param design
	 * @param cicList
	 * @param mscPline
	 * @param processDesc
	 * @param message
	 * @throws SQLException
	 */
	private void checkChem(Connection con, CraftEntity design, List<String> cicList, String mscPline,
			String processCode, String processDesc, String message, InnerStdEntity innerEntity,
			List<CraftOrdDesignStdCicEntity> inchems, SpecEntity specEntity) throws SQLException {
		MscChem mscChem = new MscChem();
		MscSplineDao mscSplineDao = new MscSplineDao();
		
		ComBaseSpecEntity spec = mscSplineDao.getSpecInfoBySpecCode(design.getSpecCode(), con);
		StdEntity stdEntity = mscChem.checkChem(con, design, spec, "2", cicList);
		
		//StdEntity stdEntity = mscChem.checkChem(con, design, design.getSpecCode(), "2", cicList);
		// 如果成分内控验证不通过
		if (!stdEntity.isFlag()) {
			innerEntity.setFlag(false);
			innerEntity.setMessage("制程(" + mscPline + ")/工序(" + processDesc + ")" + message + stdEntity.getMessage());
			return;
		} else {
			@SuppressWarnings("unchecked")
			List<CraftOrdDesignStdCicEntity> chems = (List<CraftOrdDesignStdCicEntity>) stdEntity.getObjM();
			for (CraftOrdDesignStdCicEntity chem : chems) {
				chem.setMscPline(mscPline);
				chem.setProcessCode(processCode);
				inchems.add(chem);
			}
		}
	}

	/**
	 * 验证理化
	 * 
	 * @param con
	 * @param design
	 * @param seqList
	 * @param mscPline
	 * @param processDesc
	 * @param message
	 * @throws SQLException
	 */
	private void checkPhy(Connection con, CraftEntity design, List<String> seqList, String mscPline, String processCode,
			String processDesc, String message, InnerStdEntity innerEntity, List<CraftOrdDesignStdPicEntity> inphys,
			List<CraftOrdDesignStdPicSmpEntity> insmps, SpecEntity specEntity) throws Exception {
		MscPhy mscPhy = new MscPhy();
		MscSplineDao mscSplineDao = new MscSplineDao();
		StdEntity stdEntity = new StdEntity();
		int count = 0;
		// specEntity.getRollSpecs(), specEntity.getBillSpecs(), specEntity.getBillSpecCs()
		if(processCode.equals("B")){
			ComBaseSpecEntity spec = new ComBaseSpecEntity();
			for(CraftOrdDesignMscBiltCEntity blitCSpec : specEntity.getBillSpecCs()){
				spec = mscSplineDao.getSpecInfoBySpecCode(blitCSpec.getCSpecCode(), con);
				stdEntity = mscPhy.checkPhy(con, design, "2", seqList, spec, processCode, processDesc, mscPline);
				if(stdEntity.isFlag()){
					count++;
					break;
				}
			}
			if(count == 0){
				stdEntity.setMessage(stdEntity.getMessage() + " 铸造坯外径：" + spec.getDimater() );
			}
		}else if(processCode.equals("C")){
			ComBaseSpecEntity spec = new ComBaseSpecEntity();
			for(CraftOrdDesignMscBiltEntity blitSpec : specEntity.getBillSpecs()){
				spec = mscSplineDao.getSpecInfoBySpecCode(blitSpec.getBSpecCode(), con);
				stdEntity = mscPhy.checkPhy(con, design, "2", seqList, spec, processCode, processDesc, mscPline);
				if(stdEntity.isFlag()){
					count++;
					break;
				}
			}
			if(count == 0){
				stdEntity.setMessage(stdEntity.getMessage() + " 锻造坯外径：" + spec.getDimater() );
			}
		}else if(processCode.equals("D")){
			ComBaseSpecEntity spec = new ComBaseSpecEntity();
			for(CraftOrdDesignMscGzGgEntity rollSpec : specEntity.getRollSpecs()){
				spec = mscSplineDao.getSpecInfoBySpecCode(rollSpec.getSpecCode(), con);
				stdEntity = mscPhy.checkPhy(con, design, "2", seqList, spec, processCode, processDesc, mscPline);
				if(stdEntity.isFlag()){
					count++;
					break;
				}
			}
			if(count == 0){
				stdEntity.setMessage(stdEntity.getMessage() + " (轧管规格：" + spec.getSpecName() + ")");
			}
		}else{
			ComBaseSpecEntity spec = mscSplineDao.getSpecInfoBySpecCode(design.getSpecCode(), con);
			stdEntity = mscPhy.checkPhy(con, design, "2", seqList, spec, processCode, processDesc, mscPline);
		}
		
		
		if (!stdEntity.isFlag()) {
			innerEntity.setFlag(false);
			innerEntity.setMessage("制程(" + mscPline + ")/工序(" + processDesc + ")" + message + stdEntity.getMessage());
			return;
		} else {
			@SuppressWarnings("unchecked")
			List<CraftOrdDesignStdPicEntity> phys = (List<CraftOrdDesignStdPicEntity>) stdEntity.getObjM();
//			ArrayList<String> existPics = new ArrayList<String>();
//			for(CraftOrdDesignStdPicEntity inPhy : inphys){
//				if(!existPics.contains(inPhy.getPic())){
//					existPics.add(inPhy.getPic());
//				}
//			}
			
//			phys = CraftTool.fiterCommon(phys, new String[] {
//					"desginKey", "pic", "speclFl", "indexSeq",
//					"mscPline", "processCode" });
//			MscPhyDao mscPhyDao = new MscPhyDao();
//			for (CraftOrdDesignStdPicEntity phy : phys) {
//				mscPhyDao.savePhy(con, phy);
//			}
			
			for (CraftOrdDesignStdPicEntity phy : phys) {
				phy.setMscPline(mscPline);
				phy.setProcessCode(processCode);
				inphys.add(phy);
			}
			
			if (stdEntity.getObjC() != null) {
				@SuppressWarnings("unchecked")
				List<CraftOrdDesignStdPicSmpEntity> smps = (List<CraftOrdDesignStdPicSmpEntity>) stdEntity.getObjC();
				for (CraftOrdDesignStdPicSmpEntity smp : smps) {
					insmps.add(smp);
				}
			}

		}
	}

	/**
	 * 验证公差
	 * 
	 * @param con
	 * @param design
	 * @param seqList
	 * @param mscPline
	 * @param processDesc
	 * @param message
	 * @throws Exception
	 */
	private void checkSpec(Connection con, CraftEntity design, List<String> seqList, String mscPline,
			String processCode, String processDesc, String message, InnerStdEntity innerEntity,
			List<CraftOrdDesignStdSicEntity> inspecs, SpecEntity specEntity) throws Exception {
		MscSpec mscSpec = new MscSpec();
		MscSplineDao mscSplineDao = new MscSplineDao();
		StdEntity stdEntity = new StdEntity();
		int count = 0;
		
		if(processCode.equals("B")){
			ComBaseSpecEntity spec = new ComBaseSpecEntity();
			for(CraftOrdDesignMscBiltCEntity blitCSpec : specEntity.getBillSpecCs()){
				spec = mscSplineDao.getSpecInfoBySpecCode(blitCSpec.getCSpecCode(), con);
				stdEntity = mscSpec.checkSpec(con, design, "2", seqList, processCode, spec);
				if(stdEntity.isFlag()){
					count++;
					break;
				}
			}
			if(count == 0){
				stdEntity.setMessage(stdEntity.getMessage() + " 铸造坯外径：" + spec.getDimater() );
			}
		}else if(processCode.equals("C")){
			ComBaseSpecEntity spec = new ComBaseSpecEntity();
			for(CraftOrdDesignMscBiltEntity blitSpec : specEntity.getBillSpecs()){
				spec = mscSplineDao.getSpecInfoBySpecCode(blitSpec.getBSpecCode(), con);
				stdEntity = mscSpec.checkSpec(con, design, "2", seqList, processCode, spec);
				if(stdEntity.isFlag()){
					count++;
					break;
				}
			}
			if(count == 0){
				stdEntity.setMessage(stdEntity.getMessage() + " 锻造坯外径：" + spec.getDimater() );
			}
		}else if(processCode.equals("D")){
			ComBaseSpecEntity spec = new ComBaseSpecEntity();
			for(CraftOrdDesignMscGzGgEntity rollSpec : specEntity.getRollSpecs()){
				spec = mscSplineDao.getSpecInfoBySpecCode(rollSpec.getSpecCode(), con);
				stdEntity = mscSpec.checkSpec(con, design, "2", seqList, processCode, spec);
				if(stdEntity.isFlag()){
					count++;
					break;
				}
			}
			if(count == 0){
				stdEntity.setMessage(stdEntity.getMessage() + " (轧管规格：" + spec.getSpecName() + ")");
			}
		}else{
			ComBaseSpecEntity spec = mscSplineDao.getSpecInfoBySpecCode(design.getSpecCode(), con);
			stdEntity = mscSpec.checkSpec(con, design, "2", seqList, processCode, spec);
		}
		
		//StdEntity stdEntity = mscSpec.checkSpec(con, design, "2", seqList, processCode);
		if (!stdEntity.isFlag()) {
			innerEntity.setFlag(false);
			innerEntity.setMessage("制程(" + mscPline + ")/工序(" + processDesc + ")" + message + stdEntity.getMessage());
			return;
		} else {
			@SuppressWarnings("unchecked")
			List<CraftOrdDesignStdSicEntity> specs = (List<CraftOrdDesignStdSicEntity>) stdEntity.getObjM();
			for (CraftOrdDesignStdSicEntity spec : specs) {
				spec.setMscPline(mscPline);
				spec.setProcessCode(processCode);
				inspecs.add(spec);
			}
		}
	}

	/**
	 * 验证探伤
	 * 
	 * @param con
	 * @param design
	 * @param seqList
	 * @param mscPline
	 * @param processDesc
	 * @param message
	 * @throws SQLException
	 */
	private void checkDete(Connection con, CraftEntity design, List<String> seqList, String mscPline,
			String processCode, String processDesc, String message, InnerStdEntity innerEntity,
			List<CraftOrdDesignStdDicEntity> indetes, SpecEntity specEntity) throws SQLException {
		MscDete mscDete = new MscDete();
		MscSplineDao mscSplineDao = new MscSplineDao();
		StdEntity stdEntity = new StdEntity();
		int count = 0;
		
		if(processCode.equals("B")){
			ComBaseSpecEntity spec = new ComBaseSpecEntity();
			for(CraftOrdDesignMscBiltCEntity blitCSpec : specEntity.getBillSpecCs()){
				spec = mscSplineDao.getSpecInfoBySpecCode(blitCSpec.getCSpecCode(), con);
				stdEntity = mscDete.checkDete(con, design, "2", seqList, spec);
				if(stdEntity.isFlag()){
					count++;
					break;
				}
			}
			if(count == 0){
				stdEntity.setMessage(stdEntity.getMessage() + " 铸造坯外径：" + spec.getDimater() );
			}
		}else if(processCode.equals("C")){
			ComBaseSpecEntity spec = new ComBaseSpecEntity();
			for(CraftOrdDesignMscBiltEntity blitSpec : specEntity.getBillSpecs()){
				spec = mscSplineDao.getSpecInfoBySpecCode(blitSpec.getBSpecCode(), con);
				stdEntity = mscDete.checkDete(con, design, "2", seqList, spec);
				if(stdEntity.isFlag()){
					count++;
					break;
				}
			}
			if(count == 0){
				stdEntity.setMessage(stdEntity.getMessage() + " 锻造坯外径：" + spec.getDimater() );
			}
		}else if(processCode.equals("D")){
			ComBaseSpecEntity spec = new ComBaseSpecEntity();
			for(CraftOrdDesignMscGzGgEntity rollSpec : specEntity.getRollSpecs()){
				spec = mscSplineDao.getSpecInfoBySpecCode(rollSpec.getSpecCode(), con);
				stdEntity = mscDete.checkDete(con, design, "2", seqList, spec);
				if(stdEntity.isFlag()){
					count++;
					break;
				}
			}
			if(count == 0){
				stdEntity.setMessage(stdEntity.getMessage() + " (轧管规格：" + spec.getSpecName() + ")");
			}
		}else{
			ComBaseSpecEntity spec = mscSplineDao.getSpecInfoBySpecCode(design.getSpecCode(), con);
			stdEntity = mscDete.checkDete(con, design, "2", seqList, spec);
		}
		
		//StdEntity stdEntity = mscDete.checkDete(con, design, "2", seqList);
		if (!stdEntity.isFlag()) {
			innerEntity.setFlag(false);
			innerEntity.setMessage("制程(" + mscPline + ")/工序(" + processDesc + ")" + message + stdEntity.getMessage());
			return;
		} else {
			@SuppressWarnings("unchecked")
			List<CraftOrdDesignStdDicEntity> detes = (List<CraftOrdDesignStdDicEntity>) stdEntity.getObjM();
			for (CraftOrdDesignStdDicEntity dete : detes) {
				dete.setMscPline(mscPline);
				dete.setProcessCode(processCode);
				indetes.add(dete);
			}
		}
	}

	/**
	 * 验证水压
	 * 
	 * @param con
	 * @param design
	 * @param seqList
	 * @param mscPline
	 * @param processDesc
	 * @param message
	 * @throws SQLException
	 */
	private void checkWater(Connection con, CraftEntity design, List<String> seqList, String mscPline,
			String processCode, String processDesc, String message, InnerStdEntity innerEntity,
			List<CraftOrdDesignStdWicEntity> inwaters) throws SQLException {
		MscWater mscWater = new MscWater();
		
		StdEntity stdEntity = mscWater.checkWater(con, design, "2", seqList, null);
		if (!stdEntity.isFlag()) {
			innerEntity.setFlag(false);
			innerEntity.setMessage("制程(" + mscPline + ")/工序(" + processDesc + ")" + message + stdEntity.getMessage());
			return;
		} else {
			@SuppressWarnings("unchecked")
			List<CraftOrdDesignStdWicEntity> waters = (List<CraftOrdDesignStdWicEntity>) stdEntity.getObjM();
			for (CraftOrdDesignStdWicEntity water : waters) {
				water.setMscPline(mscPline);
				water.setProcessCode(processCode);
				inwaters.add(water);
			}
		}
	}

	/**
	 * 验证加工
	 * 
	 * @param con
	 * @param design
	 * @param seqList
	 * @param mscPline
	 * @param processDesc
	 * @param message
	 * @throws SQLException
	 */
	private void checkGrocess(Connection con, CraftEntity design, List<String> seqList, String mscPline,
			String processCode, String processDesc, String message, InnerStdEntity innerEntity,
			List<CraftOrdDesignStdGicEntity> inprocesses) throws SQLException {
		MscGprocess mscGprocess = new MscGprocess();
		StdEntity stdEntity = mscGprocess.checkProcess(con, design, "2", seqList);
		if (!stdEntity.isFlag()) {
			innerEntity.setFlag(false);
			innerEntity.setMessage("制程(" + mscPline + ")/工序(" + processDesc + ")" + message + stdEntity.getMessage());
			return;
		} else {
			@SuppressWarnings("unchecked")
			List<CraftOrdDesignStdGicEntity> processes = (List<CraftOrdDesignStdGicEntity>) stdEntity.getObjM();
			for (CraftOrdDesignStdGicEntity process : processes) {
				process.setMscPline(mscPline);
				process.setProcessCode(processCode);
				inprocesses.add(process);
			}
		}
	}

	/**
	 * 根据不同工序分开验证
	 *
	 * @param specEntity
	 * @param design
	 * @throws Exception
	 */
	private void groupByProcess(Connection con, List<String> seqList, CraftOrdDesignMscPlPrcEntity mscPlPrcEntity,
			SpecEntity specEntity, String mscPline, CraftEntity design, String flag, InnerStdEntity innerEntity,
			List<CraftOrdDesignStdCicEntity> inchems, List<CraftOrdDesignStdPicEntity> inphys,
			List<CraftOrdDesignStdPicSmpEntity> insmps, List<CraftOrdDesignStdSicEntity> inspecs,
			List<CraftOrdDesignStdDicEntity> indetes, List<CraftOrdDesignStdWicEntity> inwaters,
			List<CraftOrdDesignStdGicEntity> inprocesses) throws Exception {
		String processCode = mscPlPrcEntity.getProcessCode();
		String processDesc = mscPlPrcEntity.getProcessDesc();
		String dimater = design.getDimater();
		String height = design.getHeight();
		// 根据工序验证设置不同的外径与壁厚
		if (processCode.equals("D")) {
			// 如果是轧管
			List<CraftOrdDesignMscGzGgEntity> rollSpecs = specEntity.getRollSpecs();
			for (CraftOrdDesignMscGzGgEntity rollSpec : rollSpecs) {
				design.setDimater(rollSpec.getDimater());
				design.setHeight(rollSpec.getHeight());
				design.setSpecStyle("A");

				if (flag.equals("CIC")) {
					checkChem(con, design, seqList, mscPline, processCode, processDesc,
							"/轧管规格(" + rollSpec.getSpecName() + ")", innerEntity, inchems, specEntity);
					if (!innerEntity.isFlag()) {
						return;
					}
				} else if (flag.equals("PIC")) {
					checkPhy(con, design, seqList, mscPline, processCode, processDesc,
							"/轧管规格(" + rollSpec.getSpecName() + ")", innerEntity, inphys, insmps, specEntity);
					if (!innerEntity.isFlag()) {
						return;
					}
				} else if (flag.equals("SIC")) {
					checkSpec(con, design, seqList, mscPline, processCode, processDesc,
							"/轧管规格(" + rollSpec.getSpecName() + ")", innerEntity, inspecs, specEntity);
					if (!innerEntity.isFlag()) {
						return;
					}
				} else if (flag.equals("DIC")) {
					checkDete(con, design, seqList, mscPline, processCode, processDesc,
							"/轧管规格(" + rollSpec.getSpecName() + ")", innerEntity, indetes, specEntity);
					if (!innerEntity.isFlag()) {
						return;
					}
				} else if (flag.equals("WIC")) {
					checkWater(con, design, seqList, mscPline, processCode, processDesc,
							"/轧管规格(" + rollSpec.getSpecName() + ")", innerEntity, inwaters);
					if (!innerEntity.isFlag()) {
						return;
					}
				} else {
					checkGrocess(con, design, seqList, mscPline, processCode, processDesc,
							"/轧管规格(" + rollSpec.getSpecName() + ")", innerEntity, inprocesses);
					if (!innerEntity.isFlag()) {
						return;
					}
				}
			}
		} else if (processCode.equals("C")) {
			List<CraftOrdDesignMscBiltEntity> billSpecs = specEntity.getBillSpecs();
			for (CraftOrdDesignMscBiltEntity billSpec : billSpecs) {
				design.setDimater(billSpec.getBSpecName());
				design.setHeight("");
				design.setSpecStyle("B");
				if (flag.equals("CIC")) {
					checkChem(con, design, seqList, mscPline, processCode, processDesc,
							"/锻造规格(" + billSpec.getBSpecName() + ")", innerEntity, inchems, specEntity);
					if (!innerEntity.isFlag()) {
						return;
					}
				} else if (flag.equals("PIC")) {
					checkPhy(con, design, seqList, mscPline, processCode, processDesc,
							"/锻造规格(" + billSpec.getBSpecName() + ")", innerEntity, inphys, insmps, specEntity);
					if (!innerEntity.isFlag()) {
						return;
					}
				} else if (flag.equals("SIC")) {
					checkSpec(con, design, seqList, mscPline, processCode, processDesc,
							"/锻造规格(" + billSpec.getBSpecName() + ")", innerEntity, inspecs, specEntity);
					if (!innerEntity.isFlag()) {
						return;
					}
				} else if (flag.equals("DIC")) {
					checkDete(con, design, seqList, mscPline, processCode, processDesc,
							"/锻造规格(" + billSpec.getBSpecName() + ")", innerEntity, indetes, specEntity);
					if (!innerEntity.isFlag()) {
						return;
					}
				} else if (flag.equals("WIC")) {
					checkWater(con, design, seqList, mscPline, processCode, processDesc,
							"/锻造规格(" + billSpec.getBSpecName() + ")", innerEntity, inwaters);
					if (!innerEntity.isFlag()) {
						return;
					}
				} else {
					checkGrocess(con, design, seqList, mscPline, processCode, processDesc,
							"/锻造规格(" + billSpec.getBSpecName() + ")", innerEntity, inprocesses);
					if (!innerEntity.isFlag()) {
						return;
					}
				}
			}
		} else if (processCode.equals("B")) {
			List<CraftOrdDesignMscBiltCEntity> billSpecCs = specEntity.getBillSpecCs();
			for (CraftOrdDesignMscBiltCEntity billSpecC : billSpecCs) {
				String specName = billSpecC.getCSpecName();
				if (CraftTool.isNumeric(specName)) {
					design.setDimater(specName);
					design.setHeight("");
					design.setSpecStyle("B");
					if (flag.equals("CIC")) {
						checkChem(con, design, seqList, mscPline, processCode, processDesc, "/铸造规格(" + specName + ")",
								innerEntity, inchems, specEntity);
						if (!innerEntity.isFlag()) {
							return;
						}
					} else if (flag.equals("PIC")) {
						checkPhy(con, design, seqList, mscPline, processCode, processDesc, "/铸造规格(" + specName + ")",
								innerEntity, inphys, insmps, specEntity);
						if (!innerEntity.isFlag()) {
							return;
						}
					} else if (flag.equals("SIC")) {
						checkSpec(con, design, seqList, mscPline, processCode, processDesc, "/铸造规格(" + specName + ")",
								innerEntity, inspecs, specEntity);
						if (!innerEntity.isFlag()) {
							return;
						}
					} else if (flag.equals("DIC")) {
						checkDete(con, design, seqList, mscPline, processCode, processDesc, "/铸造规格(" + specName + ")",
								innerEntity, indetes, specEntity);
						if (!innerEntity.isFlag()) {
							return;
						}
					} else if (flag.equals("WIC")) {
						checkWater(con, design, seqList, mscPline, processCode, processDesc, "/铸造规格(" + specName + ")",
								innerEntity, inwaters);
						if (!innerEntity.isFlag()) {
							return;
						}
					} else {
						checkGrocess(con, design, seqList, mscPline, processCode, processDesc,
								"/铸造规格(" + specName + ")", innerEntity, inprocesses);
						if (!innerEntity.isFlag()) {
							return;
						}
					}
				} else {
					if (flag.equals("CIC")) {
						checkChem(con, design, seqList, mscPline, processCode, processDesc, "", innerEntity, inchems, specEntity);
						if (!innerEntity.isFlag()) {
							return;
						}
					} else if (flag.equals("PIC")) {
						checkPhy(con, design, seqList, mscPline, processCode, processDesc, "", innerEntity, inphys,
								insmps, specEntity);
						if (!innerEntity.isFlag()) {
							return;
						}
					} else if (flag.equals("SIC")) {
						checkSpec(con, design, seqList, mscPline, processCode, processDesc, "", innerEntity, inspecs, specEntity);
						if (!innerEntity.isFlag()) {
							return;
						}
					} else if (flag.equals("DIC")) {
						checkDete(con, design, seqList, mscPline, processCode, processDesc, "", innerEntity, indetes, specEntity);
						if (!innerEntity.isFlag()) {
							return;
						}
					} else if (flag.equals("WIC")) {
						checkWater(con, design, seqList, mscPline, processCode, processDesc, "", innerEntity, inwaters);
						if (!innerEntity.isFlag()) {
							return;
						}
					} else {
						checkGrocess(con, design, seqList, mscPline, processCode, processDesc, "", innerEntity,
								inprocesses);
						if (!innerEntity.isFlag()) {
							return;
						}
					}
				}
			}
		} else {
			if (flag.equals("CIC")) {
				checkChem(con, design, seqList, mscPline, processCode, processDesc, "", innerEntity, inchems, specEntity);
				if (!innerEntity.isFlag()) {
					return;
				}
			} else if (flag.equals("PIC")) {
				checkPhy(con, design, seqList, mscPline, processCode, processDesc, "", innerEntity, inphys, insmps, specEntity);
				if (!innerEntity.isFlag()) {
					return;
				}
			} else if (flag.equals("SIC")) {
				checkSpec(con, design, seqList, mscPline, processCode, processDesc, "", innerEntity, inspecs, specEntity);
				if (!innerEntity.isFlag()) {
					return;
				}
			} else if (flag.equals("DIC")) {
				checkDete(con, design, seqList, mscPline, processCode, processDesc, "", innerEntity, indetes, specEntity);
				if (!innerEntity.isFlag()) {
					return;
				}
			} else if (flag.equals("WIC")) {
				checkWater(con, design, seqList, mscPline, processCode, processDesc, "", innerEntity, inwaters);
				if (!innerEntity.isFlag()) {
					return;
				}
			} else {
				checkGrocess(con, design, seqList, mscPline, processCode, processDesc, "", innerEntity, inprocesses);
				if (!innerEntity.isFlag()) {
					return;
				}
			}
		}
		
		design.setDimater(dimater);
		design.setHeight(height);
		
		//保存理化
		if(flag.equals("PIC")){
			inphys = CraftTool.fiterCommon(inphys, new String[] {
					"desginKey", "pic", "speclFl", "indexSeq",
					"mscPline", "processCode" });
			MscPhyDao mscPhyDao = new MscPhyDao();
			for (CraftOrdDesignStdPicEntity phy : inphys) {
				if(seqList.contains(phy.getPic()) &&
						phy.getSpeclFl().equals("2") && phy.getMscPline().equals(mscPline)
						&& phy.getProcessCode().equals(processCode)){
					mscPhyDao.savePhy(con, phy);
				}
			}
		}
	}
	
	private String CheckNkComplete(Connection con, String designKey, String msc, String mscPline,
			HashMap<String, CraftOrdDesignMscPlPrcEntity> processes, InnerStdEntity innerStd,
			List<CraftOrdDesignStdCicEntity> msc0Chems, List<CraftOrdDesignStdCicEntity> mscNChems){
		String msg = "";
		
		//比较成分内控
		
		//递归比较内控是否包含交付
		if(msc0Chems != null){
			msg = ForeachChem(msc0Chems, processes, "A", null, innerStd.getChems());
			if(!msg.equals("")){
				return msg;
			}
		}
		if(mscNChems != null){
			msg = ForeachChem(mscNChems, processes, "A", null, innerStd.getChems());
			if(!msg.equals("")){
				return msg;
			}
		}
		
		
		//递归比较内控是否包含交付
		List<CraftOrdDesignStdPicEntity> msc0Phys = InnerStdDao.getCraftMsc0Phy(con, designKey);
		List<CraftOrdDesignStdPicEntity> mscNPhys = InnerStdDao.getCraftMscNPhy(con, designKey);
		if(msc0Phys != null){
			msg =  ForeachPhy(msc0Phys, processes, "A", null, innerStd.getPhys());
			if(!msg.equals("")){
				return msg;
			}
		}
		if(mscNPhys != null){
			msg =  ForeachPhy(mscNPhys, processes, "A", null, innerStd.getPhys());
			if(!msg.equals("")){
				return msg;
			}
		}
		
		
		//递归比较内控是否包含交付
		List<CraftOrdDesignStdSicEntity> msc0Specs = InnerStdDao.getCraftMsc0Spec(con, designKey);
		List<CraftOrdDesignStdSicEntity> mscNSpecs = InnerStdDao.getCraftMscNSpec(con, designKey);
		if(msc0Specs != null){
			msg =  ForeachSpec(msc0Specs, processes, "A", null, innerStd.getSpecs());
			if(!msg.equals("")){
				return msg;
			}
		}
		if(mscNSpecs != null){
			msg =  ForeachSpec(mscNSpecs, processes, "A", null, innerStd.getSpecs());
			if(!msg.equals("")){
				return msg;
			}
		}
		
		
		//递归比较内控是否包含交付
		List<CraftOrdDesignStdDicEntity> msc0Detes = InnerStdDao.getCraftMsc0Dete(con, designKey);
		List<CraftOrdDesignStdDicEntity> mscNDetes = InnerStdDao.getCraftMscNDete(con, designKey);
		if(msc0Detes != null){
			msg =  ForeachDete(msc0Detes, processes, "A", null, innerStd.getDetes());
			if(!msg.equals("")){
				return msg;
			}
		}
		if(mscNDetes != null){
			msg =  ForeachDete(mscNDetes, processes, "A", null, innerStd.getDetes());
			if(!msg.equals("")){
				return msg;
			}
		}
		
		
		//递归比较内控是否包含交付
		List<CraftOrdDesignStdWicEntity> msc0Waters = InnerStdDao.getCraftMsc0Water(con, designKey);
		List<CraftOrdDesignStdWicEntity> mscNWaters = InnerStdDao.getCraftMscNWater(con, designKey);
		if(msc0Waters != null){
			msg =  ForeachWater(msc0Waters, processes, "A", null, innerStd.getWaters());
			if(!msg.equals("")){
				return msg;
			}
		}
		if(mscNWaters != null){
			msg =  ForeachWater(mscNWaters, processes, "A", null, innerStd.getWaters());
			if(!msg.equals("")){
				return msg;
			}
		}
		
		
		//递归比较内控是否包含交付
		List<CraftOrdDesignStdGicEntity> msc0Procs = InnerStdDao.getCraftMsc0Process(con, designKey);
		List<CraftOrdDesignStdGicEntity> mscNProcs = InnerStdDao.getCraftMscNProcess(con, designKey);
		if(msc0Procs != null){
			msg =  ForeachProc(msc0Procs, processes, "A", null, innerStd.getProesses());
			if(!msg.equals("")){
				return msg;
			}
		}
		if(mscNProcs != null){
			msg =  ForeachProc(mscNProcs, processes, "A", null, innerStd.getProesses());
			if(!msg.equals("")){
				return msg;
			}
		}
		
		
		return "";
	}
	
	/**
	 * 比较内控与交付
	 * @param mscChems
	 * @param processes
	 * @param processCode
	 * @param mapNkChems
	 * @return
	 */
	private String ForeachChem(List<CraftOrdDesignStdCicEntity> mscChems, 
			HashMap<String, CraftOrdDesignMscPlPrcEntity> processes, String processCode,
			HashMap<String, List<CraftOrdDesignStdCicEntity>> mapNkChems,
			List<CraftOrdDesignStdCicEntity> AllNks 
			){
		if(mapNkChems == null){
			mapNkChems = new HashMap<String, List<CraftOrdDesignStdCicEntity>>();
		}
		
//		String result = "";
//		CraftOrdDesignMscPlPrcEntity process = processes.get(processCode);
//		if(process == null){
//			processCode = String.valueOf((char)((int)processCode.charAt(0) + 1));
//			if(processCode.equals("I")){
//				return CompareChem(mscChems, mapNkChems, false);
//			}
//			result = ForeachChem(mscChems, processes, processCode, mapNkChems, AllNks);
//		}
//		else{
//			if(!process.getCic().equals("")){
//				String[] cics = process.getCic().split(",");
//				for(String cic : cics){
//					mapNkChems.remove(processCode);
//					ArrayList<CraftOrdDesignStdCicEntity> processNks = new ArrayList<CraftOrdDesignStdCicEntity>();
//					for(CraftOrdDesignStdCicEntity nk : AllNks){
//						if(nk.getProcessCode().equals(processCode) && nk.getCic().equals(cic)){
//							processNks.add(nk);
//						}
//					}
//					if(processNks.size() == 0) continue;
//					mapNkChems.put(processCode, processNks);
//					processCode = String.valueOf((char)((int)processCode.charAt(0) + 1));
//					if(processCode.equals("I")){
//						return CompareChem(mscChems, mapNkChems, false);
//					}
//					result = ForeachChem(mscChems, processes, processCode, mapNkChems, AllNks);
//					if(!result.equals("")){
//						return result;
//					}
//				}
//			}else{
//				processCode = String.valueOf((char)((int)processCode.charAt(0) + 1));
//				if(processCode.equals("I")){
//					return CompareChem(mscChems, mapNkChems, false);
//				}
//				result = ForeachChem(mscChems, processes, processCode, mapNkChems, AllNks);
//			}
//			
//		}
		String result = "";
		CraftOrdDesignMscPlPrcEntity process = processes.get(processCode);
		if(process == null) return "";
		String[] cics = process.getCic().split(",");
		for(String cic : cics){
			mapNkChems.remove(processCode);
			ArrayList<CraftOrdDesignStdCicEntity> processNks = new ArrayList<CraftOrdDesignStdCicEntity>();
			for(CraftOrdDesignStdCicEntity nk : AllNks){
				if(nk.getProcessCode().equals(processCode) && nk.getCic().equals(cic)){
					processNks.add(nk);
				}
			}
			if(processNks.size() == 0) continue;
			mapNkChems.put(processCode, processNks);
//			processCode = String.valueOf((char)((int)processCode.charAt(0) + 1));
			result = CompareChem(mscChems, mapNkChems, false);
			if(!result.equals("")){
				return result;
			}
		}
		
		return result;
	}
	
	private String CompareChem(List<CraftOrdDesignStdCicEntity> mscChems,
			HashMap<String, List<CraftOrdDesignStdCicEntity>> mapNkChems,  boolean group){
		HashMap<String, List<CraftOrdDesignStdCicEntity>> groupSames = new HashMap<String, List<CraftOrdDesignStdCicEntity>>();
		String msg = "";
		for(CraftOrdDesignStdCicEntity mscChem : mscChems){
			//处理分组
			if(!group && !mscChem.getGroupSeq().equals("")){
				if(groupSames.get(mscChem.getGroupSeq()) == null){
					groupSames.put(mscChem.getGroupSeq(), new ArrayList<CraftOrdDesignStdCicEntity>());
				}
				groupSames.get(mscChem.getGroupSeq()).add(mscChem);
				continue;
			}
			
			boolean same = false;
			String strIndex = "";
			for(String key : mapNkChems.keySet()){
				List<CraftOrdDesignStdCicEntity> nkChems = mapNkChems.get(key);
				if(nkChems.size() > 0){
					if(strIndex.equals("")){
						strIndex = nkChems.get(0).getCic();
					}else{
						strIndex += "+" + nkChems.get(0).getCic();
					}
				}
				
				for(CraftOrdDesignStdCicEntity nkChem : nkChems){
					if(mscChem.getChemCode().equals(nkChem.getChemCode())){
						same = true;
						break;
					}
				}
				if(same)
				{
					if(group){
						return "";
					}else{
						break;
					}
				}
			}
			if(!same){
				msg = "炼钢成分索引码"+ strIndex +"不包含交付成分标准项目！(化学元素："
						+ mscChem.getChemName() +")";
				if(!group){
					return msg;
				}
			}
		}
		
		if(group && !msg.equals("")){
			return msg;
		}
		
		//递归分组的理化。
		for(String key : groupSames.keySet()){
			msg = CompareChem(groupSames.get(key), mapNkChems, true);
			if(!msg.equals("")){
				return msg;
			}
		}
		
		return msg;
	}
	
	private String checkNkJfChemValue(List<CraftOrdDesignStdCicEntity> mscChems, List<CraftOrdDesignStdCicEntity> nkChems){
		for(CraftOrdDesignStdCicEntity mscChem : mscChems){
			if(mscChem.getChemName().equals("C")){
				String s = "";
				s = "";
			}
			for(CraftOrdDesignStdCicEntity nkChem : nkChems){
				if(nkChem.getChemCode().equals(mscChem.getChemCode())){
					if((mscChem.getChemCode().equals("C012") || mscChem.getChemCode().equals("C013") || mscChem.getChemCode().equals("C014") || mscChem.getChemCode().equals("C032")
							|| mscChem.getChemCode().equals("C043") || mscChem.getChemCode().equals("C051") || mscChem.getChemCode().equals("C064") || mscChem.getChemCode().equals("C065")) 
							&& mscChem.getIsjudge().equals("0") || nkChem.getIsjudge().equals("0")) continue;
					
					if(!mscChem.getStdmin().equals("")){
						double jfStdMin = StringTool.isNumeric(mscChem.getStdmin()) ? Math.round(Double.parseDouble(mscChem.getStdmin()) * 10000) : 0.0;
						double nkStdMin = StringTool.isNumeric(nkChem.getStdmin()) ? Math.round(Double.parseDouble(nkChem.getStdmin()) * 10000) : 0.0;
						if(nkChem.getStdmin().equals("")){
							return "内控成分索引码"+ nkChem.getCic() +"："+ nkChem.getChemName() + "元素不能松于交付标准！";
						}else if(StringTool.isNumeric(mscChem.getStdmin()) && StringTool.isNumeric(nkChem.getStdmin())){
							if(jfStdMin > nkStdMin){
								return "内控成分索引码"+ nkChem.getCic() +"："+ nkChem.getChemName() + "元素不能松于交付标准！";
							}else if(jfStdMin == nkStdMin){
								if(mscChem.getStdminSign().equals(">")){
									if(nkChem.getStdminSign().equals(">=")){
										return "内控成分索引码"+ nkChem.getCic() +"："+ nkChem.getChemName() + "元素不能松于交付标准！";
									}
								}
							}
						}
					}
					
					if(!mscChem.getStdmax().equals("")){
						double jfStdMax = StringTool.isNumeric(mscChem.getStdmax()) ? Math.round(Double.parseDouble(mscChem.getStdmax()) * 10000) : 0.0;
						double nkStdMax = StringTool.isNumeric(nkChem.getStdmax()) ? Math.round(Double.parseDouble(nkChem.getStdmax()) * 10000) : 0.0;
						if(nkChem.getStdmax().equals("")){
							return "内控成分索引码"+ nkChem.getCic() +"："+ nkChem.getChemName() + "元素不能松于交付标准！";
						}else if(StringTool.isNumeric(mscChem.getStdmax()) && StringTool.isNumeric(nkChem.getStdmax())){
							if(jfStdMax < nkStdMax){
								return "内控成分索引码"+ nkChem.getCic() +"："+ nkChem.getChemName() + "元素不能松于交付标准！";
							}else if(jfStdMax == nkStdMax){
								if(mscChem.getStdmaxSign().equals("<")){
									if(nkChem.getStdmaxSign().equals("<=")){
										return "内控成分索引码"+ nkChem.getCic() +"："+ nkChem.getChemName() + "元素不能松于交付标准！";
									}
								}
							}
						}
					}
				}
			}
		}
		
		return "";
	}
	
	/**
	 * 递归理化
	 * @param mscPhys
	 * @param processes
	 * @param processCode
	 * @param mapNkPhys
	 * @param AllNks
	 * @return
	 */
	private String ForeachPhy(List<CraftOrdDesignStdPicEntity> mscPhys, 
			HashMap<String, CraftOrdDesignMscPlPrcEntity> processes, String processCode,
			HashMap<String, List<CraftOrdDesignStdPicEntity>> mapNkPhys,
			List<CraftOrdDesignStdPicEntity> AllNks
			){
		if(mapNkPhys == null){
			mapNkPhys = new HashMap<String, List<CraftOrdDesignStdPicEntity>>();
		}
		
		String result = "";
		CraftOrdDesignMscPlPrcEntity process = processes.get(processCode);
		if(process == null){
			processCode = String.valueOf((char)((int)processCode.charAt(0) + 1));
			if(processCode.equals("I")){
				return ComparePhy(mscPhys, mapNkPhys, false);
			}
			result = ForeachPhy(mscPhys, processes, processCode, mapNkPhys, AllNks);
		}
		else{
			if(!process.getPic().equals("")){
				String[] pics = process.getPic().split(",");
				for(String pic : pics){
					mapNkPhys.remove(processCode);
					ArrayList<CraftOrdDesignStdPicEntity> processNks = new ArrayList<CraftOrdDesignStdPicEntity>();
					for(CraftOrdDesignStdPicEntity nk : AllNks){
						if(nk.getProcessCode().equals(processCode) && nk.getPic().equals(pic)){
							processNks.add(nk);
						}
					}
					if(processNks.size() == 0) continue;
					mapNkPhys.put(processCode, processNks);
					processCode = String.valueOf((char)((int)processCode.charAt(0) + 1));
					if(processCode.equals("I")){
						return ComparePhy(mscPhys, mapNkPhys, false);
					}
					result = ForeachPhy(mscPhys, processes, processCode, mapNkPhys, AllNks);
					if(!result.equals("")){
						return result;
					}
				}
			}else{
				processCode = String.valueOf((char)((int)processCode.charAt(0) + 1));
				if(processCode.equals("I")){
					return ComparePhy(mscPhys, mapNkPhys, false);
				}
				result = ForeachPhy(mscPhys, processes, processCode, mapNkPhys, AllNks);
			}
		}
		
		return result;
	}
	
	private String ComparePhy(List<CraftOrdDesignStdPicEntity> mscPhys,
			HashMap<String, List<CraftOrdDesignStdPicEntity>> mapNkPhys, boolean group){
		HashMap<String, List<CraftOrdDesignStdPicEntity>> groupSames = new HashMap<String, List<CraftOrdDesignStdPicEntity>>();
		String msg = "";
		for(CraftOrdDesignStdPicEntity mscPhy : mscPhys){
			//处理分组
			if(!group && !mscPhy.getGroupSeq().equals("")){
				if(groupSames.get(mscPhy.getGroupSeq()) == null){
					groupSames.put(mscPhy.getGroupSeq(), new ArrayList<CraftOrdDesignStdPicEntity>());
				}
				groupSames.get(mscPhy.getGroupSeq()).add(mscPhy);
				continue;
			}
			
			boolean same = false;
			boolean showItemS = true;
			String strIndex = "";
			for(String key : mapNkPhys.keySet()){
				List<CraftOrdDesignStdPicEntity> nkPhys = mapNkPhys.get(key);
				if(nkPhys.size() > 0){
					if(strIndex.equals("")){
						strIndex = nkPhys.get(0).getPic();
					}else{
						strIndex += "+" + nkPhys.get(0).getPic();
					}
				}
				
				for(CraftOrdDesignStdPicEntity nkPhy : nkPhys){
					if(nkPhy.getPhyCodeMax().equals("R0002")){
						if(mscPhy.getPhyCodeMax().equals(nkPhy.getPhyCodeMax())
								&& mscPhy.getPhyCodeMin().equals(nkPhy.getPhyCodeMin())
								&& mscPhy.getPhyCode().equals(nkPhy.getPhyCode())
								&& (mscPhy.getItemCodeF().equals("") || mscPhy.getItemCodeF().equals(nkPhy.getItemCodeF()))
								){
								same = true;
								showItemS = false;
								break;
							}
					}else{
						if(mscPhy.getPhyCodeMax().equals(nkPhy.getPhyCodeMax())
								&& mscPhy.getPhyCodeMin().equals(nkPhy.getPhyCodeMin())
								&& mscPhy.getPhyCode().equals(nkPhy.getPhyCode())
								&& (mscPhy.getItemCodeF().equals("") || mscPhy.getItemCodeF().equals(nkPhy.getItemCodeF()))
								&& (mscPhy.getItemCodeW().equals("") || mscPhy.getItemCodeW().equals(nkPhy.getItemCodeW()))
								&& (mscPhy.getItemCodeS().equals("") || mscPhy.getItemCodeS().equals(nkPhy.getItemCodeS()))
								){
								same = true;
								break;
						}
					}
				}
				if(same)
				{
					if(group){
						return "";
					}else{
						break;
					}
				}
			}
			if(!same){
				if(showItemS){
					msg = "内控索引组合"+ strIndex +"不包含交付理化标准项目！("
							+ mscPhy.getPhyNameMax() +", "+ mscPhy.getPhyNameMin() 
							+","+ mscPhy.getPhyName() +", "+ mscPhy.getItemNameF() +")";
				}else{
					msg = "内控索引组合"+ strIndex +"不包含交付理化标准项目！("
							+ mscPhy.getPhyNameMax() +", "+ mscPhy.getPhyNameMin() 
							+","+ mscPhy.getPhyName() +")";
				}
				if(!group){
					return msg;
				}
			}
		}
		
		if(group && !msg.equals("")){
			return msg;
		}
		
		//递归分组的理化。
		for(String key : groupSames.keySet()){
			msg = ComparePhy(groupSames.get(key), mapNkPhys, true);
			if(!msg.equals("")){
				return msg;
			}
		}
		
		return msg;
	}
	
	/**
	 * 递归公差
	 * @param processes
	 * @param processCode
	 * @param AllNks
	 * @return
	 */
	private String ForeachSpec(List<CraftOrdDesignStdSicEntity> mscSpecs, 
			HashMap<String, CraftOrdDesignMscPlPrcEntity> processes, String processCode,
			HashMap<String, List<CraftOrdDesignStdSicEntity>> mapNkSpecs,
			List<CraftOrdDesignStdSicEntity> AllNks
			){
		if(mapNkSpecs == null){
			mapNkSpecs = new HashMap<String, List<CraftOrdDesignStdSicEntity>>();
		}
		
		String result = "";
		CraftOrdDesignMscPlPrcEntity process = processes.get(processCode);
		if(process == null){
			processCode = String.valueOf((char)((int)processCode.charAt(0) + 1));
			if(processCode.equals("I")){
				return CompareSpec(mscSpecs, mapNkSpecs, false);
			}
			result = ForeachSpec(mscSpecs, processes, processCode, mapNkSpecs, AllNks);
		}
		else{
			if(!process.getSic().equals("")){
				String[] sics = process.getSic().split(",");
				for(String sic : sics){
					mapNkSpecs.remove(processCode);
					ArrayList<CraftOrdDesignStdSicEntity> processNks = new ArrayList<CraftOrdDesignStdSicEntity>();
					for(CraftOrdDesignStdSicEntity nk : AllNks){
						if(nk.getProcessCode().equals(processCode) && nk.getSic().equals(sic)){
							processNks.add(nk);
						}
					}
					if(processNks.size() == 0) continue;
					mapNkSpecs.put(processCode, processNks);
					processCode = String.valueOf((char)((int)processCode.charAt(0) + 1));
					if(processCode.equals("I")){
						return CompareSpec(mscSpecs, mapNkSpecs, false);
					}
					result = ForeachSpec(mscSpecs, processes, processCode, mapNkSpecs, AllNks);
					if(!result.equals("")){
						return result;
					}
				}
			}else{
				processCode = String.valueOf((char)((int)processCode.charAt(0) + 1));
				if(processCode.equals("I")){
					return CompareSpec(mscSpecs, mapNkSpecs, false);
				}
				result = ForeachSpec(mscSpecs, processes, processCode, mapNkSpecs, AllNks);
			}
		}
		
		return result;
	}
	
	private String CompareSpec(List<CraftOrdDesignStdSicEntity> mscSpecs,
			HashMap<String, List<CraftOrdDesignStdSicEntity>> mapNkSpecs, boolean group){
		HashMap<String, List<CraftOrdDesignStdSicEntity>> groupSames = new HashMap<String, List<CraftOrdDesignStdSicEntity>>();
		String msg = "";
		for(CraftOrdDesignStdSicEntity mscSpec : mscSpecs){
			//处理分组
			if(!group && !mscSpec.getGroupSeq().equals("")){
				if(groupSames.get(mscSpec.getGroupSeq()) == null){
					groupSames.put(mscSpec.getGroupSeq(), new ArrayList<CraftOrdDesignStdSicEntity>());
				}
				groupSames.get(mscSpec.getGroupSeq()).add(mscSpec);
				continue;
			}
			
			boolean same = false;
			String strIndex = "";
			for(String key : mapNkSpecs.keySet()){
				List<CraftOrdDesignStdSicEntity> nkSpecs = mapNkSpecs.get(key);
				if(nkSpecs.size() > 0){
					if(strIndex.equals("")){
						strIndex = nkSpecs.get(0).getSic();
					}else{
						strIndex += "+" + nkSpecs.get(0).getSic();
					}
				}
				
				for(CraftOrdDesignStdSicEntity nkSpec : nkSpecs){
					if(mscSpec.getBiasCode().equals(nkSpec.getBiasCode())){
						same = true;
						break;
					}
				}
				if(same)
				{
					if(group){
						return "";
					}else{
						break;
					}
				}
			}
			if(!same){
				msg = "内控索引组合"+ strIndex +"不包含交付公差标准项目！("
						+ mscSpec.getBiasName() +")";
				if(!group){
					return msg;
				}
			}
		}
		
		if(group && !msg.equals("")){
			return msg;
		}
		
		//递归分组的公差。
		for(String key : groupSames.keySet()){
			msg = CompareSpec(groupSames.get(key), mapNkSpecs, true);
			if(!msg.equals("")){
				return msg;
			}
		}
		
		return "";
	}
	
	/**
	 * 递归探伤
	 * @param processes
	 * @param processCode
	 * @param AllNks
	 * @return
	 */
	private String ForeachDete(List<CraftOrdDesignStdDicEntity> mscDetes, 
			HashMap<String, CraftOrdDesignMscPlPrcEntity> processes, String processCode,
			HashMap<String, List<CraftOrdDesignStdDicEntity>> mapNkDetes,
			List<CraftOrdDesignStdDicEntity> AllNks
			){
		if(mapNkDetes == null){
			mapNkDetes = new HashMap<String, List<CraftOrdDesignStdDicEntity>>();
		}
		
		String result = "";
		CraftOrdDesignMscPlPrcEntity process = processes.get(processCode);
		if(process == null){
			processCode = String.valueOf((char)((int)processCode.charAt(0) + 1));
			if(processCode.equals("I")){
				return CompareDete(mscDetes, mapNkDetes, false);
			}
			result = ForeachDete(mscDetes, processes, processCode, mapNkDetes, AllNks);
		}
		else{
			if(!process.getDic().equals("")){
				String[] dics = process.getDic().split(",");
				ArrayList<CraftOrdDesignStdDicEntity> processNks = new ArrayList<CraftOrdDesignStdDicEntity>();
				for(String dic : dics){
					mapNkDetes.remove(processCode);
					for(CraftOrdDesignStdDicEntity nk : AllNks){
						if(nk.getProcessCode().equals(processCode) && nk.getDic().equals(dic)){
							processNks.add(nk);
						}
					}
//					if(processNks.size() == 0) continue;
				}
				if(processNks.size() != 0) {
					mapNkDetes.put(processCode, processNks);
				}
				processCode = String.valueOf((char)((int)processCode.charAt(0) + 1));
				if(processCode.equals("I")){
					return CompareDete(mscDetes, mapNkDetes, false);
				}
				result = ForeachDete(mscDetes, processes, processCode, mapNkDetes, AllNks);
				if(!result.equals("")){
					return result;
				}
			}else{
				processCode = String.valueOf((char)((int)processCode.charAt(0) + 1));
				if(processCode.equals("I")){
					return CompareDete(mscDetes, mapNkDetes, false);
				}
				result = ForeachDete(mscDetes, processes, processCode, mapNkDetes, AllNks);
			}
		}
		
		return result;
	}
	
	private String CompareDete(List<CraftOrdDesignStdDicEntity> mscDetes,
			HashMap<String, List<CraftOrdDesignStdDicEntity>> mapNkDetes, boolean group){
		HashMap<String, List<CraftOrdDesignStdDicEntity>> groupSames = new HashMap<String, List<CraftOrdDesignStdDicEntity>>();
		String msg = "";
		for(CraftOrdDesignStdDicEntity mscDete : mscDetes){
			//处理分组
			if(!group && !mscDete.getGroupSeq().equals("")){
				if(groupSames.get(mscDete.getGroupSeq()) == null){
					groupSames.put(mscDete.getGroupSeq(), new ArrayList<CraftOrdDesignStdDicEntity>());
				}
				groupSames.get(mscDete.getGroupSeq()).add(mscDete);
				continue;
			}
			
			boolean same = false;
			String strIndex = "";
			for(String key : mapNkDetes.keySet()){
				List<CraftOrdDesignStdDicEntity> nkDetes = mapNkDetes.get(key);
				if(nkDetes.size() > 0){
					if(strIndex.equals("")){
						strIndex = nkDetes.get(0).getDic();
					}else{
						strIndex += "+" + nkDetes.get(0).getDic();
					}
				}
				
				for(CraftOrdDesignStdDicEntity nkDete : nkDetes){
					if(mscDete.getPhyCode().equals(nkDete.getPhyCode())){
						same = true;
						break;
					}
				}
				if(same)
				{
					if(group){
						return "";
					}else{
						break;
					}
				}
			}
			if(!same){
				msg = "内控索引组合"+ strIndex +"不包含交付探伤标准项目！("
						+ mscDete.getPhyName() + ")";
				if(!group){
					return msg;
				}
			}
		}
		
		if(group && !msg.equals("")){
			return msg;
		}
		
		//递归分组的探伤。
		for(String key : groupSames.keySet()){
			msg = CompareDete(groupSames.get(key), mapNkDetes, true);
			if(!msg.equals("")){
				return msg;
			}
		}
		return "";
	}
	
	/**
	 * 递归水压
	 * @param processes
	 * @param processCode
	 * @param AllNks
	 * @return
	 */
	private String ForeachWater(List<CraftOrdDesignStdWicEntity> mscWaters, 
			HashMap<String, CraftOrdDesignMscPlPrcEntity> processes, String processCode,
			HashMap<String, List<CraftOrdDesignStdWicEntity>> mapNkWaters,
			List<CraftOrdDesignStdWicEntity> AllNks
			){
		if(mapNkWaters == null){
			mapNkWaters = new HashMap<String, List<CraftOrdDesignStdWicEntity>>();
		}
		
		String result = "";
		CraftOrdDesignMscPlPrcEntity process = processes.get(processCode);
		if(process == null){
			processCode = String.valueOf((char)((int)processCode.charAt(0) + 1));
			if(processCode.equals("I")){
				return CompareWater(mscWaters, mapNkWaters);
			}
			result = ForeachWater(mscWaters, processes, processCode, mapNkWaters, AllNks);
		}
		else{
			if(!process.getWic().equals("")){
				String[] wics = process.getWic().split(",");
				for(String wic : wics){
					mapNkWaters.remove(processCode);
					ArrayList<CraftOrdDesignStdWicEntity> processNks = new ArrayList<CraftOrdDesignStdWicEntity>();
					for(CraftOrdDesignStdWicEntity nk : AllNks){
						if(nk.getProcessCode().equals(processCode) && nk.getWic().equals(wic)){
							processNks.add(nk);
						}
					}
					if(processNks.size() == 0) continue;
					mapNkWaters.put(processCode, processNks);
					processCode = String.valueOf((char)((int)processCode.charAt(0) + 1));
					if(processCode.equals("I")){
						return CompareWater(mscWaters, mapNkWaters);
					}
					result = ForeachWater(mscWaters, processes, processCode, mapNkWaters, AllNks);
					if(!result.equals("")){
						return result;
					}
				}
			}else{
				processCode = String.valueOf((char)((int)processCode.charAt(0) + 1));
				if(processCode.equals("I")){
					return CompareWater(mscWaters, mapNkWaters);
				}
				result = ForeachWater(mscWaters, processes, processCode, mapNkWaters, AllNks);
			}
		}
		
		return result;
	}
	
	private String CompareWater(List<CraftOrdDesignStdWicEntity> mscWaters,
			HashMap<String, List<CraftOrdDesignStdWicEntity>> mapNkWaters){
		for(CraftOrdDesignStdWicEntity mscWater : mscWaters){
			boolean same = false;
			String strIndex = "";
			for(String key : mapNkWaters.keySet()){
				List<CraftOrdDesignStdWicEntity> nkWaters = mapNkWaters.get(key);
				if(nkWaters.size() > 0){
					if(strIndex.equals("")){
						strIndex = nkWaters.get(0).getWic();
					}else{
						strIndex += "+" + nkWaters.get(0).getWic();
					}
				}
				
				
				if(nkWaters.size() > 0)
				{
					same = true;
					break;
				}
			}
			if(!same){
				return "交付标准存在水压，但内控索引组合"+ strIndex +"不包含水压内控标准！";
			}
		}
		return "";
	}
	
	/**
	 * 递归探伤
	 * @param mscProcs
	 * @param processes
	 * @param processCode
	 * @param AllNks
	 * @return
	 */
	private String ForeachProc(List<CraftOrdDesignStdGicEntity> mscProcs, 
			HashMap<String, CraftOrdDesignMscPlPrcEntity> processes, String processCode,
			HashMap<String, List<CraftOrdDesignStdGicEntity>> mapNkProcs,
			List<CraftOrdDesignStdGicEntity> AllNks
			){
		if(mapNkProcs == null){
			mapNkProcs = new HashMap<String, List<CraftOrdDesignStdGicEntity>>();
		}
		
		String result = "";
		CraftOrdDesignMscPlPrcEntity process = processes.get(processCode);
		if(process == null){
			processCode = String.valueOf((char)((int)processCode.charAt(0) + 1));
			if(processCode.equals("I")){
				return CompareProc(mscProcs, mapNkProcs, false);
			}
			result = ForeachProc(mscProcs, processes, processCode, mapNkProcs, AllNks);
		}
		else{
			if(!process.getGic().equals("")){
				String[] gics = process.getGic().split(",");
				for(String gic : gics){
					mapNkProcs.remove(processCode);
					ArrayList<CraftOrdDesignStdGicEntity> processNks = new ArrayList<CraftOrdDesignStdGicEntity>();
					for(CraftOrdDesignStdGicEntity nk : AllNks){
						if(nk.getProcessCode().equals(processCode) && nk.getGic().equals(gic)){
							processNks.add(nk);
						}
					}
					if(processNks.size() == 0) continue;
					mapNkProcs.put(processCode, processNks);
					processCode = String.valueOf((char)((int)processCode.charAt(0) + 1));
					if(processCode.equals("I")){
						return CompareProc(mscProcs, mapNkProcs, false);
					}
					result = ForeachProc(mscProcs, processes, processCode, mapNkProcs, AllNks);
					if(!result.equals("")){
						return result;
					}
				}
			}else{
				processCode = String.valueOf((char)((int)processCode.charAt(0) + 1));
				if(processCode.equals("I")){
					return CompareProc(mscProcs, mapNkProcs, false);
				}
				result = ForeachProc(mscProcs, processes, processCode, mapNkProcs, AllNks);
			}
		}
		
		return result;
	}
	
	private String CompareProc(List<CraftOrdDesignStdGicEntity> mscProcs,
			HashMap<String, List<CraftOrdDesignStdGicEntity>> mapNkProcs, boolean group){
		HashMap<String, List<CraftOrdDesignStdGicEntity>> groupSames = new HashMap<String, List<CraftOrdDesignStdGicEntity>>();
		String msg = "";
		for(CraftOrdDesignStdGicEntity mscProc : mscProcs){
			//处理分组
			if(!group && !mscProc.getGroupSeq().equals("")){
				if(groupSames.get(mscProc.getGroupSeq()) == null){
					groupSames.put(mscProc.getGroupSeq(), new ArrayList<CraftOrdDesignStdGicEntity>());
				}
				groupSames.get(mscProc.getGroupSeq()).add(mscProc);
				continue;
			}
			
			boolean same = false;
			String strIndex = "";
			for(String key : mapNkProcs.keySet()){
				List<CraftOrdDesignStdGicEntity> nkProcs = mapNkProcs.get(key);
				if(nkProcs.size() > 0){
					if(strIndex.equals("")){
						strIndex = nkProcs.get(0).getGic();
					}else{
						strIndex += "+" + nkProcs.get(0).getGic();
					}
				}
				
				for(CraftOrdDesignStdGicEntity nkProc : nkProcs){
					if(mscProc.getStationCode().equals(nkProc.getStationCode())){
						same = true;
						break;
					}
				}
				if(same)
				{
					if(group){
						return "";
					}else{
						break;
					}
				}
			}
			if(!same){
				msg = "内控索引组合"+ strIndex +"不包含交付加工标准项目！("
						+ mscProc.getStationDesc() +")";
				if(!group){
					return msg;
				}
			}
		}
		
		if(group && !msg.equals("")){
			return msg;
		}
		
		//递归分组的加工。
		for(String key : groupSames.keySet()){
			msg = CompareProc(groupSames.get(key), mapNkProcs, true);
			if(!msg.equals("")){
				return msg;
			}
		}
		
		return "";
	}
}
