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

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

import com.steering.comm.tools.StringTool;
import com.steering.pss.qcm.model.ComBaseSpecEntity;
import com.steering.pss.sale.order.model.ComMscCastRForgEntity;
import com.steering.pss.sale.order.model.ComMscPlineRSpecEntity;
import com.steering.pss.sale.order.model.ComMscRollRUpsetEntity;
import com.steering.pss.sale.order.model.DesignMscPlEntity;
import com.steering.pss.sale.order.model.DesignMscPlGzEntity;
import com.steering.pss.sale.order.model.DesignStatusEntity;
import com.steering.pss.sale.order.model.MscProcessEntity;
import com.steering.pss.sale.order.model.DesignMscBiltCEntity;
import com.steering.pss.sale.order.model.DesignMscBiltEntity;
import com.steering.pss.sale.order.model.DesignMscGzGgEntity;
import com.steering.pss.sale.order.qualityDesign.QualityDesignTool;
import com.steering.pss.sale.order.qualityDesign.Dao.factory.FactoryDao;
import com.steering.pss.sale.order.qualityDesign.Dao.imp.OperationDaoImp;
import com.steering.pss.sale.order.qualityDesign.Dao.imp.ProLineManageDaoImp;
import com.steering.pss.sale.order.qualityDesign.Dao.imp.SpecManageDaoImp;
import com.steering.pss.sale.order.qualityDesign.Dao.imp.StatusDaoImp;
import com.steering.pss.sale.order.qualityDesign.ReturnsModel.DesignEntity;
import com.steering.pss.sale.order.qualityDesign.ReturnsModel.SpecEntity;
import com.steering.pss.sale.order.qualityDesign.server.imp.SpecManageImp;

/**
 * 规格管理业务类
 * 
 * @author Administrator
 */
public class ISpecManage implements SpecManageImp {

	/**
	 * 轧制规格类
	 * 
	 * @param designKey
	 *            质量主键
	 * @param mscPline
	 *            制程
	 * @param gradeCode
	 *            钢种
	 * @param gradeName
	 *            钢种名称
	 * @param specCode
	 *            规格代码
	 * @param specName
	 *            规格描述
	 * @param dimater
	 *            外径
	 * @param height
	 *            壁厚
	 * @return OrdDesignMscGzGgEntity
	 */
	public static DesignMscGzGgEntity setRollSpec(String designKey,
			String mscPline, String gradeCode, String gradeName,
			String specCode, String specName, String dimater, String height) {
		DesignMscGzGgEntity rollSpec = new DesignMscGzGgEntity();
		rollSpec.setDesginKey(designKey);
		rollSpec.setMscPline(mscPline);
		rollSpec.setGradecode(gradeCode);
		rollSpec.setGradename(gradeName);
		rollSpec.setSpecCode(specCode);
		rollSpec.setSpecName(specName);
		rollSpec.setDimater(dimater);
		rollSpec.setHeight(height);
		return rollSpec;
	}

	/**
	 * 锻造规格类
	 * 
	 * @param designKey
	 *            质量主键
	 * @param mscPline
	 *            制程
	 * @param specCode
	 *            轧制规格
	 * @param bSpecCode
	 *            锻造规格代码
	 * @param bSpecName
	 *            锻造规格名称
	 * @return OrdDesignMscBiltEntity
	 */
	public static DesignMscBiltEntity setBlank(String designKey,
			String mscPline, String specCode, String bSpecCode, String bSpecName) {
		DesignMscBiltEntity blank = new DesignMscBiltEntity();
		blank.setDesginKey(designKey);
		blank.setMscPline(mscPline);
		blank.setSpecCode(specCode);
		blank.setbSpecCode(bSpecCode);
		blank.setbSpecName(bSpecName);
		return blank;
	}

	/**
	 * 锻造规格转铸造规格
	 * 
	 * @param sections
	 *            锻造规格
	 * @return List<OrdDesignMscBiltCEntity>
	 */
	public static List<DesignMscBiltCEntity> biltToBiltC(
			List<DesignMscBiltEntity> bilts) {
		List<DesignMscBiltCEntity> biltCs = new ArrayList<DesignMscBiltCEntity>();
		for (DesignMscBiltEntity bilt : bilts) {
			DesignMscBiltCEntity biltC = new DesignMscBiltCEntity();
			biltC.setDesginKey(bilt.getDesginKey());
			biltC.setMscPline(bilt.getMscPline());
			biltC.setSpecCode(bilt.getSpecCode());
			biltC.setBSpecCode("");
			biltC.setCSpecCode(bilt.getbSpecCode());
			biltC.setCSpecName(bilt.getbSpecName());
			biltCs.add(biltC);
		}
		return biltCs;
	}

	/**
	 * 铸造规格类
	 * 
	 * @param designKey
	 *            质量主键
	 * @param mscPline
	 *            制程
	 * @param specCode
	 *            轧制规格
	 * @param bSpecCode
	 *            锻造规格
	 * @param cSpecCode
	 *            铸造规格代码
	 * @param cSpecName
	 *            铸造规格描述
	 * @return OrdDesignMscBiltCEntity
	 */
	public static DesignMscBiltCEntity setBiltSpec(String designKey,
			String mscPline, String specCode, String bSpecCode,
			String bSpecName, String cSpecCode, String cSpecName) {
		DesignMscBiltCEntity bilt = new DesignMscBiltCEntity();
		bilt.setDesginKey(designKey);
		bilt.setMscPline(mscPline);
		bilt.setBSpecCode(bSpecCode);
		bilt.setbSpecName(bSpecName);
		bilt.setSpecCode(specCode);
		bilt.setCSpecCode(cSpecCode);
		bilt.setCSpecName(cSpecName);
		return bilt;
	}

	/**
	 * 轧制规格、锻造规格、铸造规格(改善)
	 * 
	 * @param con
	 *            连接字符串
	 * @param proDucInfo
	 *            制程
	 * @param grades
	 *            钢种集合
	 * @param design
	 *            质量设计类
	 * @return SpecEntity
	 * @throws SQLException
	 */
	public SpecEntity analysisSpec(Connection con,
			DesignMscPlEntity proDucInfo, List<DesignMscPlGzEntity> grades,
			DesignEntity design) throws SQLException {
		SpecManageDaoImp specManageDaoImp = FactoryDao.getSpecManageDaoImp();
		OperationDaoImp operationDaoImp = FactoryDao.getOperationDaoImp();
		ProLineManageDaoImp proLineManageDaoImp = FactoryDao
				.getProLineManageDaoImp();
		DesignStatusEntity status = null;
		StatusDaoImp statusDaoImp = FactoryDao.getStatusDaoImp();
		// 提示信息
		String errMessage = "";
		// 主键信息
		String message = "";
		// 全程途径码
		String wholeBacklog = proDucInfo.getWholeBacklog();
		// 冶金规范码
		String msc = design.getOrderLineMsc();
		// 制程
		String mscPline = proDucInfo.getMscPline();
		// 外徑
		String dimater = design.getDimater();
		// 壁厚
		String height = design.getHeight();
		// 质量主键
		String designKey = design.getDesignKey();

		SpecEntity specInfo = new SpecEntity();
		/**
		 * 轧制规格类集合
		 */
		List<DesignMscGzGgEntity> rolledSpecsA = new ArrayList<DesignMscGzGgEntity>();
		/**
		 * 合适的钢种集合
		 */
		List<DesignMscPlGzEntity> fiterGrades = new ArrayList<DesignMscPlGzEntity>();

		/**
		 * 镦拔扩工序
		 */
		if (wholeBacklog.contains("E")) {
			// 查询镦拔扩的二级工序
			MscProcessEntity processInfo = operationDaoImp.getOperation(con,
					msc, mscPline, "E");
			for (DesignMscPlGzEntity grade : grades) {
				boolean eFlag = false;
				// 钢种+镦拔扩规格+二级工序找轧制规格
				List<ComMscRollRUpsetEntity> rollSpecs = specManageDaoImp
						.getRollSpec(con, dimater, height,
								grade.getGradecode(),
								processInfo.getProcessCodeC());
				// 如果镦拔扩找不到轧制规格
				if (rollSpecs == null || rollSpecs.size() == 0) {
					errMessage = "制程(" + mscPline + " )/ 全程途径码(" + wholeBacklog
							+ ")  镦拔扩工序: 外径(" + dimater + " ) 壁厚(" + height
							+ ")  钢种(" + grade.getGradename() + ")  镦拔扩二级工序("
							+ processInfo.getProcessDescC() + ") 找不到轧管规格!";
					status = statusDaoImp.setDesignStatus(design,
							design.getOrderLineMsc(), "镦拔扩", "F", "91",
							errMessage, mscPline, design.getMscUnitCode(),
							design.getMscUnitDesc());
					status.setGradecode(grade.getGradecode());
					continue;
				}

				for (ComMscRollRUpsetEntity rollSpec : rollSpecs) {
					List<ComBaseSpecEntity> baseSpec = specManageDaoImp
							.getBaseSpec(con, rollSpec.getMinD(),
									rollSpec.getMinH());
					// 找不到基础规格
					if (baseSpec == null) {
						errMessage = "制程(" + mscPline + " )/ 全程途径码("
								+ wholeBacklog + ") 轧管规格:外径("
								+ rollSpec.getMinD() + ") 壁厚("
								+ rollSpec.getMinH() + ")在基础规格表不存在!";
						status = statusDaoImp.setDesignStatus(design,
								design.getOrderLineMsc(), "镦拔扩", "F", "91",
								errMessage, mscPline, design.getMscUnitCode(),
								design.getMscUnitDesc());
						status.setGradecode(grade.getGradecode());
						continue;
					}
					if (baseSpec.size() > 1) {
						errMessage = "制程(" + mscPline + " )/ 全程途径码("
								+ wholeBacklog + ") 轧制规格: 外径("
								+ rollSpec.getMinD() + ") 壁厚("
								+ rollSpec.getMinH() + ")在基础规格表存在多条!";
						status = statusDaoImp.setDesignStatus(design,
								design.getOrderLineMsc(), "镦拔扩", "F", "91",
								errMessage, mscPline, design.getMscUnitCode(),
								design.getMscUnitDesc());
						status.setGradecode(grade.getGradecode());
						continue;
					}
					// 轧制规格
					DesignMscGzGgEntity rolledSpec = ISpecManage.setRollSpec(
							designKey, mscPline, grade.getGradecode(), grade
									.getGradename(), baseSpec.get(0)
									.getSpecCode(), baseSpec.get(0)
									.getSpecName(), rollSpec.getMinD(),
							rollSpec.getMinH());
					rolledSpecsA.add(rolledSpec);
					eFlag = true;
				}
				if (eFlag) {
					fiterGrades.add(grade);
				}
			}

		} else {
			// 如果不存在镦拔扩,则所有钢种都适用，且合同的产品规格为轧管规格
			for (DesignMscPlGzEntity grade : grades) {
				fiterGrades.add(grade);
			}
			DesignMscGzGgEntity rolledSpec = ISpecManage.setRollSpec(designKey,
					mscPline, "", "", design.getSpecCode(),
					design.getSpecName(), dimater, height);
			rolledSpecsA.add(rolledSpec);
		}
		// 只要有一个钢种能找到轧制规格就通过
		if (rolledSpecsA.size() == 0) {
			specInfo.setStatus(status);
			return specInfo;
		}

		List<DesignMscGzGgEntity> rolledSpecs = new ArrayList<DesignMscGzGgEntity>();
		// 如果合同允许原料管 ，要求轧制工序 只能是外购产线，或者只能是自炼产线
		List<DesignMscBiltCEntity> blitCSpecsW = new ArrayList<DesignMscBiltCEntity>();// 专门用于外购管的铸造规格
		if (wholeBacklog.contains("D")) {
			for (DesignMscGzGgEntity rolledSpec : rolledSpecsA) {
				message = "D," + rolledSpec.getDimater() + ","
						+ rolledSpec.getHeight() + "," + "," + "," + "," + ","
						+ "1";
				List<String[]> biltSpecArray = specManageDaoImp.getBiltSpec(
						con, rolledSpec.getDimater(), rolledSpec.getHeight(),
						design.getOutsStlPileFl());
				if (biltSpecArray == null || biltSpecArray.size() == 0) {
					if (design.getOutsStlPileFl().equals("121902")
							|| design.getOutsStlPileFl().equals("121903")) {
						errMessage = "制程(" + mscPline + " )/ 全程途径码("
								+ wholeBacklog + ")  轧制 :外径("
								+ rolledSpec.getDimater() + ") 壁厚("
								+ rolledSpec.getHeight()
								+ ") 找不到外购产线![合同允许原料管,轧制只能为外购产线] ";
					} else {
						errMessage = " 轧制(外径:" + rolledSpec.getDimater()
								+ "、壁厚:" + rolledSpec.getHeight() + ")找不到自炼产线";
					}
					continue;
				}
				rolledSpecs.add(rolledSpec);
				// 如果是外购管则不往下验证锻造/铸造规格
				if (design.getOutsStlPileFl().equals("121902")
						|| design.getOutsStlPileFl().equals("121903")) {
					for (String[] strings : biltSpecArray) {
						DesignMscBiltCEntity biltCSpec = new DesignMscBiltCEntity();
						biltCSpec = ISpecManage.setBiltSpec(designKey,
								mscPline, rolledSpec.getSpecCode(), "", "",
								strings[0], strings[1]);
						blitCSpecsW.add(biltCSpec);
					}

				}

			}
			if (rolledSpecs == null || rolledSpecs.size() == 0) {
				status = statusDaoImp.setDesignStatus(design,
						design.getOrderLineMsc(), "适用产线", "F", "91",
						errMessage, message, design.getMscUnitCode(),
						design.getMscUnitDesc());
				specInfo.setStatus(status);
				return specInfo;
			}

		}

		// 如果是外购管则不往下验证锻造/铸造规格
		if (design.getOutsStlPileFl().equals("121902")
				|| design.getOutsStlPileFl().equals("121903")) {
			specInfo.setGrade(fiterGrades);
			specInfo.setBlitCSpecs(blitCSpecsW);
			specInfo.setBlitSpecs(null);
			specInfo.setRollSpecs(rolledSpecs);
			specInfo.setStatus(null);
			return specInfo;
		}

		// 铸造比极限值
		String ratio = AutomaticReview.getPscRatio(con, design.getPsc());
		if (ratio.equals("")) {
			status = statusDaoImp.setDesignStatus(design,
					design.getOrderLineMsc(), "适用产线", "F", "91", "请维护产品码("
							+ design.getPsc() + "的锻造比极限值!", message,
					design.getMscUnitCode(), design.getMscUnitDesc());
			specInfo.setStatus(status);
			return specInfo;
		}
		/**
		 * 轧制工序(如果制程包含锻造工序，则对应的是锻造规格，否则是铸造规格)
		 */
		/**
		 * 最终轧制规格类集合
		 */
		List<DesignMscGzGgEntity> rolledSpecsE = new ArrayList<DesignMscGzGgEntity>();
		// 锻造规格
		List<DesignMscBiltEntity> blitSpecs = new ArrayList<DesignMscBiltEntity>();
		// 铸造规格
		List<DesignMscBiltCEntity> blitCSpecs = new ArrayList<DesignMscBiltCEntity>();
		// 定义错误提示信息
		String messageM = "";
		String messageD = "";
		if (wholeBacklog.contains("D")) {
			// 遍历轧管规格
			for (DesignMscGzGgEntity rolledSpec : rolledSpecs) {
				// 通过外径、壁厚找锻造/铸造工序的规格
				List<String[]> biltSpecArray = specManageDaoImp.getBiltSpec(
						con, rolledSpec.getDimater(), rolledSpec.getHeight(),
						design.getOutsStlPileFl());
				messageD = "D," + rolledSpec.getDimater() + ","
						+ rolledSpec.getHeight() + "," + "," + "," + "," + ","
						+ "1";
				// 前面验证轧管规格是否外购/自炼，则对应的管坯规格则肯定能够找到
				// 如果制程有锻造工序，则对应的fiterProLine管坯规格是锻造规格，否则一定为铸造规格
				if (wholeBacklog.contains("C")) {
					for (int i = 0; i < biltSpecArray.size(); i++) {
						// 轧制锻造类
						if (!StringTool.isNumeric(biltSpecArray.get(i)[1])) {
							messageM = "制程(" + mscPline + ")/全程途径码("
									+ wholeBacklog + ") :轧制规格("
									+ rolledSpec.getSpecName() + ")->锻造规格("
									+ biltSpecArray.get(i)[1] + ")是钢锭规格类型!";
							continue;
						}
						// 如果是合同允许原料坯，则锻造规格必须找到外购产线，否则找自炼产线。
						List<ComMscPlineRSpecEntity> plineCs = proLineManageDaoImp
								.getProLine(con, "C");
						plineCs = IProLineManage.fiterProLine(plineCs,
								biltSpecArray.get(i)[0], "", "", "", "");
						if (design.getOutsBilietFl().equals("121801")) {
							plineCs = IProLineManage
									.fiterOutLine(plineCs, true);
						} else {
							plineCs = IProLineManage.fiterOutLine(plineCs,
									false);
						}
						// 如果对应的产线找不到，则继续找下一个规格对应的产线
						if (plineCs == null || plineCs.size() == 0) {
							if (design.getOutsBilietFl().equals("121801")) {
								messageM = "制程(" + mscPline + ")/全程途径码("
										+ wholeBacklog + ") :轧制规格("
										+ rolledSpec.getSpecName() + ")->锻造规格("
										+ biltSpecArray.get(i)[1]
										+ ") 锻造工序不存在(外购)产线";
							} else {
								messageM = "制程(" + mscPline + ")/全程途径码("
										+ wholeBacklog + ") :轧制规格("
										+ rolledSpec.getSpecName() + ")->锻造规格("
										+ biltSpecArray.get(i)[1]
										+ ") 锻造工序不存在(自炼)产线";
							}
							continue;
						}
						// 转化为锻造规格实体类
						DesignMscBiltEntity blitSpec = ISpecManage.setBlank(
								designKey, mscPline, rolledSpec.getSpecCode(),
								biltSpecArray.get(i)[0],
								biltSpecArray.get(i)[1]);
						// 如果是锻造工序则必定要有对应连铸坯规格
						// 如果有铸造工序，铸造二级工序取数据库，否则直接赋值连铸
						String processCodeC = "";
						if (wholeBacklog.contains("B")) {
							MscProcessEntity processInfoB = operationDaoImp
									.getOperation(con, msc, mscPline, "B");
							processCodeC = processInfoB.getProcessCodeC();
						} else {
							processCodeC = "B002";
						}
						List<ComMscCastRForgEntity> castRForgs = specManageDaoImp
								.getBiltCSpec(con, blitSpec.getbSpecCode(),
										processCodeC);
						if (castRForgs == null || castRForgs.size() == 0) {
							if (processCodeC.equals("B002")) {
								messageM = "制程(" + mscPline + ")/全程途径码("
										+ wholeBacklog + ") :轧制规格("
										+ rolledSpec.getSpecName()
										+ " )->锻造规格(" + blitSpec.getbSpecName()
										+ ")不存在连铸坯规格(二级工序:连铸)";
								continue;
							} else {
								messageM = "制程(" + mscPline + ")/全程途径码("
										+ wholeBacklog + ") :轧制规格("
										+ rolledSpec.getSpecName() + "->锻造规格("
										+ blitSpec.getbSpecName()
										+ ")找不到钢锭规格(二级工序:模铸)";
								continue;
							}
						}
						DesignMscBiltCEntity biltCSpec = null;
						for (ComMscCastRForgEntity castRForg : castRForgs) {
							// 连铸或者模铸
							if (processCodeC.equals("B002")) {
								if (!StringTool.isNumeric(castRForg
										.getSpecName())) {
									messageM = "制程(" + mscPline + ")/全程途径码("
											+ wholeBacklog + ") :轧制规格("
											+ rolledSpec.getSpecName()
											+ ")->锻造规格("
											+ blitSpec.getbSpecName()
											+ "->铸造规格("
											+ castRForg.getSpecName()
											+ ")是钢锭规格!(二级工序:连铸)";
									continue;
								}
								biltCSpec = ISpecManage.setBiltSpec(designKey,
										mscPline, blitSpec.getSpecCode(),
										blitSpec.getbSpecCode(),
										blitSpec.getbSpecName(),
										castRForg.getSpecCode(),
										castRForg.getSpecName());
							} else {
								biltCSpec = ISpecManage.setBiltSpec(designKey,
										mscPline, blitSpec.getSpecCode(),
										blitSpec.getbSpecCode(),
										blitSpec.getbSpecName(),
										castRForg.getSpecCodeIngot(),
										castRForg.getSpecNameIngot());
							}
							// 验证压缩比
							if (QualityDesignTool.isNumeric(biltCSpec
									.getbSpecName())) {
								String ratioFlag = AutomaticReview
										.compressioRatio(con, dimater, height,
												biltCSpec.getbSpecName(), ratio);
								if (ratioFlag.equals("B")) {
									messageM = "制程(" + mscPline + ")/全程途径码("
											+ wholeBacklog + ") :轧制规格("
											+ rolledSpec.getSpecName()
											+ ")->锻造规格("
											+ blitSpec.getbSpecName()
											+ "->铸造规格("
											+ castRForg.getSpecName()
											+ ",压缩比大于产品码锻造比极限值为" + ratio
											+ ",制程不能包含锻造!";
									continue;
								}
							}
							// 验证产线
							List<ComMscPlineRSpecEntity> plineBs = proLineManageDaoImp
									.getProLine(con, "B");
							plineBs = IProLineManage.fiterProLine(plineBs,
									biltCSpec.getCSpecCode(), processCodeC, "",
									"", "");
							plineBs = IProLineManage.fiterOutLine(plineBs,
									false);
							if (plineBs == null || plineBs.size() == 0) {
								messageM = "制程(" + mscPline + ")/全程途径码("
										+ wholeBacklog + ") :轧制规格("
										+ rolledSpec.getSpecName() + ")->锻造规格("
										+ blitSpec.getbSpecName() + "->铸造规格("
										+ castRForg.getSpecName()
										+ " 铸造工序不存在自炼产线";
								continue;
							}
							// 增加锻造规格与铸造规格
							blitSpecs.add(blitSpec);
							blitCSpecs.add(biltCSpec);
							// 重新获取轧管规格
							if (!rolledSpecsE.contains(rolledSpec)) {
								rolledSpecsE.add(rolledSpec);
							}
						}
					}
				} else {
					// 如果没有锻造工序，则是对应的连铸坯规格
					for (int i = 0; i < biltSpecArray.size(); i++) {
						if (!StringTool.isNumeric(biltSpecArray.get(i)[1])) {
							messageM = "制程(" + mscPline + ")/全程途径码("
									+ wholeBacklog + ") : 轧制规格("
									+ rolledSpec.getSpecName() + ")->铸造规格(连铸)"
									+ biltSpecArray.get(i)[1] + "是钢锭规格!";
							continue;
						}
						DesignMscBiltCEntity biltCSpec = new DesignMscBiltCEntity();
						biltCSpec.setCSpecCode(biltSpecArray.get(i)[0]);
						biltCSpec.setCSpecName(biltSpecArray.get(i)[1]);
						biltCSpec.setDesginKey(design.getDesignKey());
						biltCSpec.setMscPline(mscPline);
						biltCSpec.setSpecCode(rolledSpec.getSpecCode());
						// 验证压缩比
						String ratioFlag = AutomaticReview.compressioRatio(con,
								dimater, height, biltCSpec.getCSpecName(),
								ratio);
						if (ratioFlag.equals("C")) {
							messageM += "制程(" + mscPline + ")/全程途径码("
									+ wholeBacklog + ") : 轧制规格("
									+ rolledSpec.getSpecName() + ")->铸造规格(连铸)"
									+ biltSpecArray.get(i)[1]
									+ ",压缩比小于产品码锻造比极限值为" + ratio + ",制程必须包含锻造!";
							continue;
						}
						// 如果工序包含铸造工序，则验证对应的产线，否则不验证
						String processCodeC = "";
						if (wholeBacklog.contains("B")) {
							MscProcessEntity process = operationDaoImp
									.getOperation(con, msc, mscPline, "B");
							processCodeC = process.getProcessCodeC();
						} else {
							processCodeC = "B002";
						}
						List<ComMscPlineRSpecEntity> plineBs = proLineManageDaoImp
								.getProLine(con, "B");
						plineBs = IProLineManage.fiterProLine(plineBs,
								biltCSpec.getCSpecCode(), processCodeC, "", "",
								"");
						if (design.getOutsBilietFl().equals("121801")) {
							plineBs = IProLineManage
									.fiterOutLine(plineBs, true);
						} else {
							plineBs = IProLineManage.fiterOutLine(plineBs,
									false);
						}
						if (plineBs == null || plineBs.size() == 0) {
							if (design.getOutsBilietFl().equals("121801")) {
								messageM = "制程(" + mscPline + ")/全程途径码("
										+ wholeBacklog + ") : 轧制规格("
										+ rolledSpec.getSpecName()
										+ ")->铸造规格(连铸)"
										+ biltSpecArray.get(i)[1]
										+ " 铸造工序找不到(外购)产线";
							} else {
								messageM = "制程(" + mscPline + ")/全程途径码("
										+ wholeBacklog + ") :轧制规格("
										+ rolledSpec.getSpecName()
										+ ")->铸造规格(连铸)"
										+ biltSpecArray.get(i)[1]
										+ " 铸造工序找不到(自炼)产线";
							}
							continue;
						}
						blitCSpecs.add(biltCSpec);
						// 重新获取轧管规格
						if (!rolledSpecsE.contains(rolledSpec)) {
							rolledSpecsE.add(rolledSpec);
						}
					}

				}
			}

		}
		// 如果是管坯(特殊处理)
		if (design.getSpecStyle().equals("B")) {
			message = "D," + design.getDimater() + "," + design.getHeight()
					+ "," + "," + "," + "," + "," + "1";
			// 如果包含锻造工序
			if (wholeBacklog.contains("C")) {
				DesignMscBiltEntity blitSpec = new DesignMscBiltEntity();
				blitSpec.setSpecCode("/");
				blitSpec.setbSpecCode(design.getSpecCode());
				blitSpec.setbSpecName(design.getSpecName());
				blitSpec.setDesginKey(design.getDesignKey());
				blitSpec.setMscPline(mscPline);
				String processCodeC = "";
				if (wholeBacklog.contains("B")) {
					MscProcessEntity process = operationDaoImp.getOperation(
							con, msc, mscPline, "B");
					processCodeC = process.getProcessCodeC();
				} else {
					processCodeC = "B002";
				}
				List<ComMscCastRForgEntity> castRForgs = specManageDaoImp
						.getBiltCSpec(con, blitSpec.getbSpecCode(),
								processCodeC);
				if (castRForgs == null || castRForgs.size() == 0) {
					if (processCodeC.equals("B002")) {
						messageM = "制程(" + mscPline + ")/全程途径码(" + wholeBacklog
								+ ") :锻造规格(" + blitSpec.getbSpecName()
								+ ")不存在连铸坯规格(二级工序:连铸)";
					} else {
						messageM = "制程(" + mscPline + ")/全程途径码(" + wholeBacklog
								+ ") :锻造规格(" + blitSpec.getbSpecName()
								+ ")找不到钢锭规格(二级工序:模铸)";
					}
				}

				for (ComMscCastRForgEntity castRForg : castRForgs) {
					// 连铸或者模铸
					DesignMscBiltCEntity biltCSpec = null;
					if (processCodeC.equals("B002")) {
						if (!StringTool.isNumeric(castRForg.getSpecName())) {
							messageM = "制程(" + mscPline + ")/全程途径码("
									+ wholeBacklog + ") :锻造规格("
									+ blitSpec.getbSpecName() + "->铸造规格("
									+ castRForg.getSpecName()
									+ ")是钢锭规格!(二级工序:连铸)";
							continue;
						}
						biltCSpec = ISpecManage.setBiltSpec(designKey,
								mscPline, blitSpec.getSpecCode(),
								blitSpec.getbSpecCode(),
								blitSpec.getbSpecName(),
								castRForg.getSpecCode(),
								castRForg.getSpecName());
					} else {
						biltCSpec = ISpecManage.setBiltSpec(designKey,
								mscPline, blitSpec.getSpecCode(),
								blitSpec.getbSpecCode(),
								blitSpec.getbSpecName(),
								castRForg.getSpecCodeIngot(),
								castRForg.getSpecNameIngot());
					}
					blitSpecs.add(blitSpec);
					blitCSpecs.add(biltCSpec);
				}
			} else {
				// 只包含铸造(制程已加限制 管坯只能必须包含铸造或者)
				DesignMscBiltCEntity biltCSpec = new DesignMscBiltCEntity();
				biltCSpec.setCSpecCode(design.getSpecCode());
				biltCSpec.setCSpecName(design.getSpecName());
				biltCSpec.setDesginKey(design.getDesignKey());
				biltCSpec.setBSpecCode("");
				biltCSpec.setbSpecName("");
				biltCSpec.setMscPline(mscPline);
				biltCSpec.setSpecCode("/");
				biltCSpec.setSpecCodeS(design.getSpecCode());
				blitCSpecs.add(biltCSpec);
			}

		}
		// 判断是否找到铸造规格
		if (wholeBacklog.contains("D") || wholeBacklog.contains("B")
				|| wholeBacklog.contains("C")) {
			if (blitCSpecs == null || blitCSpecs.size() == 0) {
				status = statusDaoImp.setDesignStatus(design,
						design.getOrderLineMsc(), "适用产线", "F", "91", messageM,
						messageD, design.getMscUnitCode(),
						design.getMscUnitDesc());
				specInfo.setStatus(status);
				return specInfo;
			}
		}
		specInfo.setGrade(fiterGrades);
		specInfo.setBlitCSpecs(blitCSpecs);
		specInfo.setBlitSpecs(blitSpecs);
		specInfo.setRollSpecs(rolledSpecsE);
		specInfo.setStatus(null);
		return specInfo;
	}

}
