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

import CoreFS.SA06.CoreReturnObject;
import CoreFS.SC01.CoreConstantData;
import com.steering.comm.db.DBCommon;
import com.steering.pss.sale.order.ReviewForm.CoreOrderReviewTechnology;
import com.steering.pss.sale.order.bomGeneration.BOMGeneration;
import com.steering.pss.sale.order.bomGeneration.daoImp.BomFactoryDao;
import com.steering.pss.sale.order.bomGeneration.daoImp.BomQueryDaoImp;
import com.steering.pss.sale.order.bomGeneration.model.BomEntity;
import com.steering.pss.sale.order.bomGeneration.server.BomMaterial;
import com.steering.pss.sale.order.bomGeneration.server.GeneraBomEntity;
import com.steering.pss.sale.order.model.*;
import com.steering.pss.sale.order.qualityDesign.Dao.factory.FactoryDao;
import com.steering.pss.sale.order.qualityDesign.Dao.idao.*;
import com.steering.pss.sale.order.qualityDesign.Dao.imp.*;
import com.steering.pss.sale.order.qualityDesign.ReturnsModel.DesignEntity;
import com.steering.pss.sale.order.qualityDesign.ReturnsModel.ProLineEntity;
import com.steering.pss.sale.order.qualityDesign.ReturnsModel.SpecEntity;
import com.steering.pss.sale.order.qualityDesign.model.ComMscJgEntity;
import com.steering.pss.sale.order.qualityDesign.model.SlmOrdDesignMscJgEntity;
import com.steering.pss.sale.order.qualityDesign.model.*;
import com.steering.pss.sale.order.qualityDesign.server.factory.FactoryServer;
import com.steering.pss.sale.order.qualityDesign.server.imp.*;
import com.steering.pss.sale.order.qualityDesign.server.iserver.*;

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

/**
 * 质量设计主流程
 * 
 * @author Administrator PDY 2015/04/20
 */
public class QualityDesignMain extends DBCommon {
	// 质量设计流程:
	// 1、预处理(判断传入值合同行号的合理性、通过合同行号查询的信息合理性)
	// 2、生成设计状态(此状态用于保存验证质量设计每一步的结果)
	// 3、验证基础冶金规范码
	// 4、基础冶金规范码验证交互标准
	// 5、验证客户特殊要求
	// 6、验证附加要求
	// 7、获取特殊要求MSC(n)的信息
	// 8、验证制程
	// 9、验证钢种、镦拔扩、规格、产线、内控标准等
	// 10、验证生产周期
	// 11、验证接箍码
	// 12、验证备料码
	// 13、生成物料码

	/**
	 * 质量设计
	 * 
	 * @param ordPk
	 *            合同头号
	 * @param ordLnPk
	 *            合同行号
	 * @param orderSeq
	 *            （可为空）
	 * @param info
	 *            操作人(集合，可能还有其它信息)
	 * @return CoreReturnObject 返回true 则质量设计通过 false 则不通过
	 */
	public CoreReturnObject qualityDesign(String ordPk, String ordLnPk,
			String orderSeq, ArrayList<Object> info) {
		CoreReturnObject core = new CoreReturnObject();
		core.setResult(false);
		/**
		 * 如果传入的合同头号与合同行号为空，停止质量设计
		 */
		if (ordPk.length() == 0 || info.size() == 0 || ordLnPk.length() == 0) {
			core.setV_errMsg("合同行主键为空!");
			return core;
		}
		/**
		 * 获取数据库连接
		 */
		java.sql.Connection con = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();

		try {
			// con.setAutoCommit(false);
			/**
			 * 通过合同头号与合同行号查询合同主记录信息
			 */
			QualityPrePDaoImp qualityPreDao = FactoryDao.getQualityPrePDaoImp();
			DesignMscEntity designMscEntity = qualityPreDao.getOrderLine(con,
					ordPk, ordLnPk);

			/**
			 * 如果找不到合同主记录信息,则停止质量设计-->
			 */
			if (designMscEntity == null) {
				core.setV_errMsg("通过合同行主键在合同信息表找不到有效合同行信息!");

				return core;
			}
			/**
			 * 验证产品码是否有效
			 */
			String psc = qualityPreDao.getValidPsc(con,
					designMscEntity.getPsc());
			if (psc.equals("")) {
				core.setV_errMsg("找不到有效产品描述( " + designMscEntity.getPscDesc()
						+ ") ,不能进行质量设计");

				return core;
			}
			/**
			 * 操作人
			 */
			String userName = info.get(0).toString();
			// 获取销售组织
			CoreCastWell coreCastWell = new CoreCastWell();
			String[] saleInfo = coreCastWell.getSaleInfo(con, ordPk,3);

			/**
			 * 验证合同主记录是否满足质量设计要求，返回错误信息停止质量设计
			 */
			QualityPreImp qualityPreImp = FactoryServer.getQualityPreImp();
			String errMessage = qualityPreImp.checkOrderLine(con,
					designMscEntity);
			if (!errMessage.equals("")) {
				core.setV_errMsg(errMessage);

				return core;
			}
			/**
			 * 客户ALPHA处理
			 */
			// qualityPreImp.checkAlpha(con, ordLnPk, psc, designMscEntity);
			/**
			 * 一、预处理 （新增质量设计MSC主记录,返回质量主键designKey）
			 */
			String designKey = qualityPreImp.DesignQualityPre(con,
					designMscEntity, userName);
			// 如果 designKey 为空则停止质量设计
			if (designKey.equals("")) {
				core.setV_errMsg("质量设计预处理失败,请联系管理员!");

				return core;
			}

			/**
			 * 二、初始状态
			 */

			StatusImp statusImp = FactoryServer.getStatusImp();
			statusImp.initialStatus(con, designKey, ordLnPk,
					designMscEntity.getPsc(), designMscEntity.getFinalUser(),
					userName);
			StatusDaoImp statusDaoImp = FactoryDao.getStatusDaoImp();
			// 提交

			/**
			 * 三 、验证基础冶金规范码（如果含有客户特殊要求，则要求冶金规范码状态为审核状态）
			 */
			MscImp mscImp = FactoryServer.getMscImp();
			DesignEntity design = mscImp.checkMsc(con, designKey, userName,
					designMscEntity, saleInfo);

			// 天淮合同，天管msc ，使用天淮工艺科
			if (saleInfo != null && saleInfo.length > 0 && ("100105".equals(saleInfo[0])
					&& design !=null && !design.getMscDunitCode().contains("002023005"))
					|| "120504".equals(saleInfo[2])) {
				design.setMscUnitCode("002023005003");
				design.setMscUnitDesc("工艺科");
				design.setMscDunitCode("002023005003");
				design.setMscDunitDesc("工艺科");
			}

			if (design == null) {
				statusDaoImp.updateDesignStsTklg(con, designKey, userName, "F",
						"W");

				return core;
			}

			DesignStatusEntity status = null;

			// status = statusDaoImp.setDesignStatus(design,
			// design.getOrderLineMsc(), "在线机探盲区切长", "F", "91",
			// "请维护在线机探盲区切长", design.getOrderLineMsc(),
			// design.getMscUnitCode(), design.getMscUnitDesc());
			// statusDaoImp.updateDesignStatus(con, status);
			// // 质量设计通过验证
			// statusDaoImp.updateDesignStsTklg(con, designKey, "", "F",
			// "W");
			// return core;

			/**
			 * 四、根据冶金规范码类型 是否验证交付标准( C:短节+附件 D:接箍 没有交付标准）
			 */
			String errMessageC = "";
			String errMessageP = "";
			String errMessageS = "";
			String errMessageD = "";
			String errMessageW = "";
			String errMessageG = "";

			if (design.getOrderLineMscStyle().equals("C")
					|| design.getOrderLineMscStyle().equals("D")
					|| design.getOrderLineMscStyle().equals("E")) {
				status = statusDaoImp.setDesignStatus(design, design.getMsc(),
						"成分标准", "S", "00", "成分标准无要求", "",
						design.getDunitCode(), design.getDunitDesc());
				statusDaoImp.updateDesignStatus(con, status);
				status = statusDaoImp.setDesignStatus(design, design.getMsc(),
						"理化标准", "S", "00", "理化标准无要求", "",
						design.getDunitCode(), design.getDunitDesc());
				statusDaoImp.updateDesignStatus(con, status);
				status = statusDaoImp.setDesignStatus(design, design.getMsc(),
						"公差标准", "S", "00", "公差标准无要求", "",
						design.getDunitCode(), design.getDunitDesc());
				statusDaoImp.updateDesignStatus(con, status);
				status = statusDaoImp.setDesignStatus(design, design.getMsc(),
						"探伤标准", "S", "00", "探伤标准无要求", "",
						design.getDunitCode(), design.getDunitDesc());
				statusDaoImp.updateDesignStatus(con, status);
				status = statusDaoImp.setDesignStatus(design, design.getMsc(),
						"水压标准", "S", "00", "水压标准无要求", "",
						design.getDunitCode(), design.getDunitDesc());
				statusDaoImp.updateDesignStatus(con, status);
				status = statusDaoImp.setDesignStatus(design, design.getMsc(),
						"加工标准", "S", "00", "加工标准无要求", "",
						design.getDunitCode(), design.getDunitDesc());
				statusDaoImp.updateDesignStatus(con, status);
			} else {
				/**
				 * 成分标准
				 */
				MscChemImp chemImp = FactoryServer.getChemImp();
				errMessageC = chemImp.checkChem(con, design.getMsc(), design,
						"0");
				if (errMessageC.length() > 0) {
					status = statusDaoImp.setDesignStatus(design,
							design.getMsc(), "成分标准", "F", "91", errMessageC,
							"", design.getDunitCode(), design.getDunitDesc());
					statusDaoImp.updateDesignStatus(con, status);
					statusDaoImp.updateDesignStsTklg(con, designKey, "", "F",
							"W");

					return core;
				} else {
					status = statusDaoImp.setDesignStatus(design,
							design.getMsc(), "成分标准", "S", "11", "成分标准通过验证", "",
							design.getDunitCode(), design.getDunitDesc());
					statusDaoImp.updateDesignStatus(con, status);
					errMessageC = "找不到成分索引号";
				}

				/**
				 * 理化标准
				 */
				MscPhyImp mscPhyImp = FactoryServer.getMscPhyImp();
				errMessageP = mscPhyImp.checkPhy(con, design.getMsc(), design,
						"0");
				if (errMessageP.length() > 0) {
					status = statusDaoImp.setDesignStatus(design,
							design.getMsc(), "理化标准", "F", "91", errMessageP,
							"", design.getDunitCode(), design.getDunitDesc());
					statusDaoImp.updateDesignStatus(con, status);
					statusDaoImp.updateDesignStsTklg(con, designKey, "", "F",
							"W");

					return core;
				} else {
					status = statusDaoImp.setDesignStatus(design,
							design.getMsc(), "理化标准", "S", "11", "理化标准通过验证", "",
							design.getDunitCode(), design.getDunitDesc());
					statusDaoImp.updateDesignStatus(con, status);
					errMessageP = "找不到理化索引号";
				}

				/**
				 * 公差标准
				 */
				MscSpecImp mscSpecImp = FactoryServer.getMscSpecImp();
				errMessageS = mscSpecImp.checkSpec(con, design.getMsc(),
						design, "0");
				if (errMessageS.length() > 0) {
					status = statusDaoImp.setDesignStatus(design,
							design.getMsc(), "公差标准", "F", "91", errMessageS,
							"", design.getDunitCode(), design.getDunitDesc());
					statusDaoImp.updateDesignStatus(con, status);
					statusDaoImp.updateDesignStsTklg(con, designKey, "", "F",
							"W");

					return core;
				} else {
					status = statusDaoImp.setDesignStatus(design,
							design.getMsc(), "公差标准", "S", "11", "理化标准通过验证", "",
							design.getDunitCode(), design.getDunitDesc());
					statusDaoImp.updateDesignStatus(con, status);
					errMessageS = "找不到公差索引号";
				}

				/**
				 * 探伤标准
				 */
				MscDeteImp mscDeteImp = FactoryServer.getMscDeteImp();
				errMessageD = mscDeteImp.checkDete(con, design.getMsc(),
						design, "0");
				if (errMessageD.length() > 0) {
					status = statusDaoImp.setDesignStatus(design,
							design.getMsc(), "探伤标准", "F", "91", errMessageD,
							"", design.getDunitCode(), design.getDunitDesc());
					statusDaoImp.updateDesignStatus(con, status);
					statusDaoImp.updateDesignStsTklg(con, designKey, "", "F",
							"W");

					return core;

				} else {
					status = statusDaoImp.setDesignStatus(design,
							design.getMsc(), "探伤标准", "S", "11", "探伤标准通过验证", "",
							design.getDunitCode(), design.getDunitDesc());
					statusDaoImp.updateDesignStatus(con, status);
					errMessageD = "找不到探伤索引号";
				}

				/**
				 * 水压标准
				 */
				MscWaterImp mscWaterImp = FactoryServer.getMscWaterImp();
				String[] waterResults = mscWaterImp.checkWater(con, design.getMsc(),
						design, "0");
				errMessageW = waterResults[0];
				if (errMessageW.length() > 0) {
					if(waterResults[1].equals("MSC(n)")){
						status = statusDaoImp.setDesignStatus(design,
								design.getOrderLineMsc(), "MSC(n)", "F", "91", errMessageW,
								design.getOrdLnPk(), design.getMscDunitCode(), design.getMscDunitDesc());
						statusDaoImp.updateDesignStatus(con, status);
					}else{
						status = statusDaoImp.setDesignStatus(design,
								design.getMsc(), "水压标准", "F", "91", errMessageW,
								design.getOrdLnPk(), design.getDunitCode(), design.getDunitDesc());
						statusDaoImp.updateDesignStatus(con, status);
					}
					statusDaoImp.updateDesignStsTklg(con, designKey, "", "F",
							"W");

					return core;
				} else {
					status = statusDaoImp.setDesignStatus(design,
							design.getMsc(), "水压标准", "S", "11", "水压标准通过验证", "",
							design.getDunitCode(), design.getDunitDesc());
					statusDaoImp.updateDesignStatus(con, status);
					errMessageW = design.getMsc() + "找不到水压索引号";
				}
				/**
				 * 加工标准
				 */
				MscProcessingImp mscProcessingImp = FactoryServer
						.getMscProcessingImp();
				errMessageG = mscProcessingImp.checkProcess(con,
						design.getMsc(), design, "0");
				if (errMessageG.length() > 0) {
					status = statusDaoImp.setDesignStatus(design,
							design.getMsc(), "加工标准", "F", "91", errMessageG,
							"", design.getDunitCode(), design.getDunitDesc());
					statusDaoImp.updateDesignStatus(con, status);
					statusDaoImp.updateDesignStsTklg(con, designKey, "", "F",
							"W");

					return core;
				} else {
					status = statusDaoImp.setDesignStatus(design,
							design.getMsc(), "加工标准", "S", "11", "加工标准通过验证", "",
							design.getDunitCode(), design.getDunitDesc());
					statusDaoImp.updateDesignStatus(con, status);
					errMessageG = design.getMsc() + "找不到加工索引号";
				}
			}

			/**
			 * 五、管理科室 (指定MSCN的交互标准管理科室和工艺管理科室)
			 */
			DeptSelectImp deptSelectImp = FactoryServer.getDeptSelectImp();
			CustSpecialAskDaoImp spcAskDaoImp = FactoryDao
					.getCustSpecialAskDaoImp();
			ComPscEntity pscInfo = spcAskDaoImp
					.getPscInfo(con, design.getPsc());
			// 技术要求管理科室规则:n的MSC管理部门是制造部（科室为标准科）
			// 如果管理部门是技术中心（科室为产品码中的002001007006 科技协调部)
			String unitCode = "";
			String unitDesc = "";
			if (pscInfo.getDepartmentCode().equals("002001001")) {
				unitCode = "002001001004";
				unitDesc = "标准科";
			} else if (pscInfo.getDepartmentCode().equals("002001007")) {
				unitCode = "002001007006";
				unitDesc = "科技协调部";
			} else {
				// 其它情况都属于标准科
				unitCode = "002001001004";
				unitDesc = "标准科";
			}
//			if (saleInfo != null && saleInfo.length > 0 && "100105".equals(saleInfo[0])) {
//				depts[0] = "002023005003";
//				depts[1] = "工艺科";
//			}
			if (deptSelectImp.deptSelect(con, design.getCustAlphyNo(), ordLnPk)) {
				status = statusDaoImp.setDesignStatus(design,
						design.getOrderLineMsc(), "MSC(n)管理科室", "S", "11",
						"管理科室已确认", ordLnPk, unitCode, unitDesc);
				statusDaoImp.updateDesignStatus(con, status);
			} else {
				status = statusDaoImp.setDesignStatus(design,
						design.getOrderLineMsc(), "MSC(n)管理科室", "F", "91",
						"需要新生成MSC(n),请选择管理科室", ordLnPk, unitCode, unitDesc);
				statusDaoImp.updateDesignStatus(con, status);
				statusDaoImp.updateDesignStsTklg(con, designKey, "", "F", "W");

				return core;
			}

			/**
			 * 六、验证特殊要求
			 */
			DeptSelectDaoImp deptSelectDaoImp = FactoryDao
					.getDeptSelectDaoImp();
			String[] depts = deptSelectDaoImp.getDept(con, ordLnPk);
			if (depts == null) {
				depts = new String[2];
				depts[0] = design.getMscDunitCode();
				depts[1] = design.getMscDunitDesc();
			}


			CustSpecialAskImp custSpecialAskImp = FactoryServer
					.getCustSpecialAskImp();
			String errMessageSpecial = custSpecialAskImp.checkCustSpecialAsk(
					con, design.getCustAlphyNo(), design.getOrderLineMsc(),
					design.getFinalUser(), design.getFinalUserDesc());
			if (errMessageSpecial.length() != 0) {
				status = statusDaoImp.setDesignStatus(design,
						design.getOrderLineMsc(), "产品技术要求", "F", "91",
						errMessageSpecial, design.getCustAlphyNo(), depts[0],
						depts[1]);
				statusDaoImp.updateDesignStatus(con, status);
				statusDaoImp.updateDesignStsTklg(con, designKey, "", "F", "W");

				return core;
			} else {
				status = statusDaoImp.setDesignStatus(design,
						design.getOrderLineMsc(), "产品技术要求", "S", "11",
						"特殊要求通过验证", design.getOrderLineMsc(), depts[0],
						depts[1]);
				statusDaoImp.updateDesignStatus(con, status);
			}

			/**
			 * 七、验证MSC(n) 成品接箍与短节+附件 产品特殊要求放到接箍码中,此处不验证
			 */
			if (!design.getOrderLineMscStyle().equals("C")
					&& !design.getOrderLineMscStyle().equals("D")
					&& !design.getOrderLineMscStyle().equals("E")) {
				SpecialMscImp specialMscImp = FactoryServer.getSpecialMscImp();
				boolean flagSpec = specialMscImp.checkSpecialMc(con, design);
				if (!flagSpec) {
					statusDaoImp.updateDesignStsTklg(con, designKey, "", "F",
							"W");

					return core;
				}
			} else {
				status = statusDaoImp.setDesignStatus(design,
						design.getOrderLineMsc(), "MSC(n)", "S", "00",
						"MSC(n)无要求", design.getOrderLineMsc(), depts[0],
						depts[1]);
				statusDaoImp.updateDesignStatus(con, status);
			}

			/**
			 * 八、验证接箍码
			 */
			// 接箍码(套管、成品接箍、短节附件有接箍码)
			String keyJG = "";
			String jg = "";
			MscJGDaoImp mscJGDaoImp = FactoryDao.getMscJGDaoImp();
			if (design.getOrderLineMscStyle().equals("B")
					|| design.getOrderLineMscStyle().equals("C")
					|| design.getOrderLineMscStyle().equals("D")) {
				MscJGImp mscJGImp = FactoryServer.getMscJGImp();
				// 设定接箍（在接箍验证界面设定一个接箍，后面验证都根据这个接箍来验证）
				List<SlmOrdDesignMscJgEntity> setJGEntitys = mscJGDaoImp
						.getSetJG(con, designKey);
				// 验证接箍码信息
				Object[] JGInfo = mscJGImp.checkMscJG(con,
						design.getOrderLineMsc(), design.getDimater(),
						design.getHeight(), design.getSteelCode(),
						design.getSteelName(), design.getModelCode(),
						design.getModelDesc(), design.getSpecCode(),
						design.getSpecName(), design.getSpecStyle(), designKey,
						design.getOrdLnPk(), setJGEntitys);
				String JGMessage = (String) JGInfo[0];
				String jgSetFlag = (String) JGInfo[1];
				// 接箍码信息
				SlmOrdDesignMscJgEntity jgEntity = (SlmOrdDesignMscJgEntity) JGInfo[2];
				@SuppressWarnings("unchecked")
				// 接箍备料对应关系
				List<SlmOrdDesignMscJgBlEntity> jgblEntitys = (List<SlmOrdDesignMscJgBlEntity>) JGInfo[3];
				if (jgEntity == null) {
					status = statusDaoImp.setDesignStatus(design,
							design.getOrderLineMsc(), "接箍", "F", "91",
							JGMessage, design.getOrderLineMsc() + ","
									+ jgSetFlag, design.getMscDunitCode(),
							design.getMscDunitDesc());
					statusDaoImp.updateDesignStatus(con, status);
					statusDaoImp.updateDesignStsTklg(con, designKey, "", "F",
							"W");

					return core;
				} else {
					status = statusDaoImp.setDesignStatus(design,
							design.getOrderLineMsc(), "接箍", "S", "11",
							"接箍码通过验证", design.getOrderLineMsc() + ",1",
							design.getMscDunitCode(), design.getMscDunitDesc());
					statusDaoImp.updateDesignStatus(con, status);
					// 保存接箍码(如果有设定接箍,则修改下接箍信息,否则新增)
					if (setJGEntitys == null || setJGEntitys.size() == 0) {
						mscJGDaoImp.saveJG(con, jgEntity);
					} else {
						mscJGDaoImp.updateSetJG(con, jgEntity);
					}
					// 对应的JGKEY
					keyJG = jgEntity.getKeyJg();
					jg = jgEntity.getCodeJg();
					// 保存接箍码对应的备料码
					for (SlmOrdDesignMscJgBlEntity jgblEntity : jgblEntitys) {
						mscJGDaoImp.saveJgBl(con, jgblEntity);
					}
				}
			} else {
				status = statusDaoImp.setDesignStatus(design,
						design.getOrderLineMsc(), "接箍", "S", "00", "接箍码无要求",
						design.getOrderLineMsc(), design.getMscDunitCode(),
						design.getMscDunitDesc());
				statusDaoImp.updateDesignStatus(con, status);
			}

			/**
			 * 九、 验证接箍制程（如果有返回接箍KEY，则验证接箍制程）
			 */
			if (keyJG.length() > 0) {
				JGplDaoImp jgplDaoImp = FactoryDao.getJGplDaoImp();
				SlmOrdDesignMscJgPlEntity jgplEntity = jgplDaoImp.getJGpl(con,
						keyJG);
				// 9.1结箍制程
				if (jgplEntity == null) {
					status = statusDaoImp.setDesignStatus(design,
							design.getOrderLineMsc(), "接箍制程", "F", "91",
							"请维护接箍码(" + jg + ")/接箍主键(" + keyJG + ")的制程!",
							design.getOrderLineMsc(), design.getMscDunitCode(),
							design.getMscDunitDesc());
					statusDaoImp.updateDesignStatus(con, status);
					statusDaoImp.updateDesignStsTklg(con, designKey, "", "F",
							"W");
					return core;
				}
				List<SlmOrdDesignMscJgPlStiEntity> plStiEntitys = jgplDaoImp
						.getJGPlSti(con, keyJG, jgplEntity.getMscPline());
				// 结箍工序点
				if (plStiEntitys == null || plStiEntitys.size() == 0) {
					status = statusDaoImp.setDesignStatus(design,
							design.getOrderLineMsc(), "接箍制程", "F", "91", "接箍码("
									+ jg + ")/接箍主键(" + keyJG + ")的接箍制程("
									+ jgplEntity.getMscPline() + ")无工序点",
							design.getOrderLineMsc(), design.getMscDunitCode(),
							design.getMscDunitDesc());
					statusDaoImp.updateDesignStatus(con, status);
					statusDaoImp.updateDesignStsTklg(con, designKey, "", "F",
							"W");
					return core;
				}
				// 接箍基础信息
				ComMscJgEntity comMscJgEntity = mscJGDaoImp.getJGBaseInfo(con,
						jg);
				// 结箍产线
				ProLineManageDaoImp proLineManageDaoImp = FactoryDao
						.getProLineManageDaoImp();
				List<ComMscPlineRSpecEntity> plines = proLineManageDaoImp
						.getLineBySpec(con, comMscJgEntity.getModelCode(),
								comMscJgEntity.getSpecJg(), "H");
				if (plines == null || plines.size() == 0) {
					status = statusDaoImp.setDesignStatus(
							design,
							design.getOrderLineMsc(),
							"接箍制程",
							"F",
							"91",
							"接箍码(" + jg + ")/接箍主键(" + keyJG + ")的接箍制程("
									+ jgplEntity.getMscPline()
									+ ")不可用！(找不到接箍加工产线![扣型:"
									+ comMscJgEntity.getModelDesc() + ",接箍规格:"
									+ comMscJgEntity.getSpecJgDesc() + "])",
							design.getOrderLineMsc(), design.getMscDunitCode(),
							design.getMscDunitDesc());
					statusDaoImp.updateDesignStatus(con, status);
					statusDaoImp.updateDesignStsTklg(con, designKey, "", "F",
							"W");
					return core;
				}
				// 验证成功
				// 保存工序点（接箍制程工艺点）
				for (SlmOrdDesignMscJgPlStiEntity plStiEntity : plStiEntitys) {
					plStiEntity.setCodeJg(keyJG);
					plStiEntity.setDesginKey(designKey);
					jgplDaoImp.saveJGPlSti(con, plStiEntity);
				}
				// 保存接箍产线
				for (ComMscPlineRSpecEntity pline : plines) {
					jgplDaoImp.saveJGLine(con, designKey,
							jgplEntity.getMscPline(), pline.getPlineCode(),
							pline.getPlineName(), pline.getWellCode(),
							pline.getWellName());
				}
				// 保存接箍制程
				jgplEntity.setCodeJg(keyJG);
				jgplEntity.setDesginKey(designKey);
				jgplEntity.setOrdLnPk(ordLnPk);
				jgplEntity.setSetFl("0");
				jgplEntity.setWarnDesc("");
				jgplDaoImp.saveJGpl(con, jgplEntity);
				status = statusDaoImp.setDesignStatus(design,
						design.getOrderLineMsc(), "接箍制程", "S", "11",
						"接箍制程验证通过", design.getOrderLineMsc(),
						design.getMscDunitCode(), design.getMscDunitDesc());
				statusDaoImp.updateDesignStatus(con, status);
			} else {
				status = statusDaoImp.setDesignStatus(design,
						design.getOrderLineMsc(), "接箍制程", "S", "00", "接箍制程无要求",
						design.getOrderLineMsc(), design.getMscDunitCode(),
						design.getMscDunitDesc());
				statusDaoImp.updateDesignStatus(con, status);
			}

			/**
			 * 十、验证备料码（A 钢管 B 钢管+接箍 C ）
			 */
			MscBLDaoImp mscBLDaoImp = FactoryDao.getMscBLDaoImp();
			if (designMscEntity.getMscStyle().equals("C")
					|| designMscEntity.getMscStyle().equals("E")) {
				MscBLImp mscBLImp = FactoryServer.getMscBLImp();
				Object[] blInfo = mscBLImp.checkBL(con,
						design.getOrderLineMsc(), design.getDimater(),
						design.getHeight(), design.getSteelCode(),
						design.getSteelName(), design.getSpecCode(),
						design.getSpecName(), design.getSpecStyle(), designKey,
						design.getModelCode(), design.getModelDesc());
				String blMessage = (String) blInfo[0];
				@SuppressWarnings("unchecked")
				List<String[]> mscBLs = (List<String[]>) blInfo[1];
				if (mscBLs == null || mscBLs.size() == 0) {
					status = statusDaoImp.setDesignStatus(design,
							design.getOrderLineMsc(), "备料", "F", "91",
							blMessage, design.getOrderLineMsc(),
							design.getMscDunitCode(), design.getMscDunitDesc());
					statusDaoImp.updateDesignStatus(con, status);
					statusDaoImp.updateDesignStsTklg(con, designKey, "", "F",
							"W");

					return core;
				} else {
					status = statusDaoImp.setDesignStatus(design,
							design.getOrderLineMsc(), "备料", "S", "11",
							blMessage, design.getOrderLineMsc(),
							design.getMscDunitCode(), design.getMscDunitDesc());
					statusDaoImp.updateDesignStatus(con, status);
					// 如果找到，即验证通过
					for (String[] arrStr : mscBLs) {
						mscBLDaoImp.saveBL(con, arrStr[0], arrStr[1],
								arrStr[2], arrStr[3]);
					}
				}
			} else {
				status = statusDaoImp.setDesignStatus(design,
						design.getOrderLineMsc(), "备料", "S", "00", "备料码无要求",
						design.getOrderLineMsc(), design.getMscDunitCode(),
						design.getMscDunitDesc());
				statusDaoImp.updateDesignStatus(con, status);
			}

			// 查询指定制程
			ProDucDaoImp proDucDaoImp = FactoryDao.getProDucDaoImp();
			List<DesignMscPlEntity> setProDucs = proDucDaoImp.getMscPlSetFl(
					con, ordLnPk, design.getOrderLineMsc());
			
			// 用于成分偏差标准钢种
			String biasGradeCode = "";
			String biasGradeName = "";

			/**
			 * 十一、验证制程
			 */
			List<String> errMessages = new ArrayList<String>();
			errMessages.add(errMessageC);
			errMessages.add(errMessageP);
			errMessages.add(errMessageS);
			errMessages.add(errMessageD);
			errMessages.add(errMessageW);
			errMessages.add(errMessageG);
			ProDucImp processImp = FactoryServer.getProcessImp();
			List<DesignMscPlEntity> mscPlEntitys = processImp.checkProDuc(con,
					design, errMessages, setProDucs);
			if (mscPlEntitys == null || mscPlEntitys.size() == 0) {
				statusDaoImp.updateDesignStsTklg(con, designKey, "", "F", "W");

				return core;
			}

			/**
			 * 十二、验证制程向下的钢种、镦拔扩、适用产线等
			 */
			String mscPlineMessage = "{";
			GradeDaoImp gradeDaoImp = FactoryDao.getGradeDaoImp();
			GradeImp gradeImp = FactoryServer.getGradeImp();
			ProDucDaoImp processDaoImp = FactoryDao.getProDucDaoImp();
			InnerStandardImp innerStdImp = FactoryServer.getInnerStandardImp();
			SpecManageImp specManageImp = FactoryServer.getSpecManageImp();
			CreateSpecLineDaoImp specLineDaoImp = FactoryDao
					.getCreateSpecLineDaoImp();
			ProLineManageImp proLineManageImp = FactoryServer
					.getProLineManageImp();
			boolean ducflag = false;
			for (DesignMscPlEntity proDuc : mscPlEntitys) {
				String wholeBacklog = proDuc.getWholeBacklog();

				/**
				 * 1、验证钢种
				 */
				Object[] gradeInfo = gradeImp.checkGrade(con,
						proDuc.getMscPline(), wholeBacklog,
						design.getOrderLineMsc(), design.getDimater(),
						design.getHeight(), design.getSpecStyle(),
						design.getSpecName(), design.getOutsBilietFl(), 
						design.getOrderLineMscStyle(), designKey);
				String errMessageGrade = (String) gradeInfo[0];
				@SuppressWarnings("unchecked")
				List<DesignMscPlGzEntity> grades = (List<DesignMscPlGzEntity>) gradeInfo[1];
				// 如果得到的钢种条数为零，则验证下一个制程
				if (grades == null || grades.size() == 0) {
					mscPlineMessage += errMessageGrade + "}";
					status = statusDaoImp.setDesignStatus(design,
							design.getOrderLineMsc(), "钢种", "F", "91",
							errMessageGrade, proDuc.getMscPline(),
							design.getMscDunitCode(), design.getMscDunitDesc());
					// 如果指定了制程,则每个制程每一步如果验证不通过,都要停止设计
					if (setProDucs != null && setProDucs.size() > 0) {
						statusDaoImp.updateDesignStatus(con, status);
						statusDaoImp.updateDesignStsTklg(con, designKey, "",
								"F", "W");

						return core;
					}
					continue;
				}
				/**
				 * 2、 验证规格
				 */
				SpecEntity specInfo = specManageImp.analysisSpec(con, proDuc,
						grades, design);
				if (specInfo.getStatus() != null) {
					status = specInfo.getStatus();
					mscPlineMessage += "{" + status.getDesignStsDesc() + "}";
					// 如果指定了制程,则每个制程每一步如果验证不通过,都要停止设计
					if (setProDucs != null && setProDucs.size() > 0) {
						statusDaoImp.updateDesignStsTklg(con, designKey, "",
								"F", "W");
						statusDaoImp.updateDesignStatus(con, status);

						return core;
					}
					continue;
				}

				/**
				 * 3、验证产线
				 */
				ProLineEntity proLineInfo = proLineManageImp.analysisProLine(
						con, design, proDuc, specInfo.getRollSpecs(),
						specInfo.getBlitSpecs(), specInfo.getBlitCSpecs());
				if (proLineInfo.getStatus() != null) {
					status = proLineInfo.getStatus();
					mscPlineMessage += "{" + status.getDesignStsDesc() + "}";
					// 如果指定了制程,则每个制程每一步如果验证不通过,都要停止设计
					if (setProDucs != null && setProDucs.size() > 0) {
						statusDaoImp.updateDesignStatus(con, status);
						statusDaoImp.updateDesignStsTklg(con, designKey, "",
								"F", "W");

						return core;
					}

					continue;
				}
				/**
				 * 4、 验证内控标准
				 */
				Object[] innerInfo = innerStdImp.checkInnerStd(con,
						design.getOrderLineMsc(), proDuc.getMscPline(),
						wholeBacklog, proDuc.getWholeBacklogDesc(), designKey);
				// boolean innerFlag = (Boolean) innerInfo[0];
				String innerMessage = (String) innerInfo[1];
				@SuppressWarnings("unchecked")
				List<DesignMscPlPrcEntity> inners = (List<DesignMscPlPrcEntity>) innerInfo[2];
				DesignStatusEntity statusInner = statusDaoImp.setDesignStatus(
						design, design.getOrderLineMsc(), "内控标准", "S", "91",
						innerMessage, proDuc.getMscPline(),
						design.getMscUnitCode(), design.getMscUnitDesc());
				statusDaoImp.updateDesignStatus(con, statusInner);
				for (DesignMscPlPrcEntity inner : inners) {
					specLineDaoImp.saveInnerStd(con, inner);
				}

				// 保存钢种
				for (DesignMscPlGzEntity grade : specInfo.getGrade()) {
					gradeDaoImp.saveGrade(con, grade, designKey);
					if(biasGradeCode.equals("")){
						biasGradeCode = grade.getGradecode();
						biasGradeName = grade.getGradename();
					}
				}

				// 保存轧管规格
				List<DesignMscGzGgEntity> rollSpecs = specInfo.getRollSpecs();
				if (rollSpecs != null && rollSpecs.size() != 0) {
					rollSpecs = ServerDesignTool.fiterRollSpec(rollSpecs);
					for (DesignMscGzGgEntity rollSpec : rollSpecs) {
						specLineDaoImp.savePipeRoll(con, rollSpec);
					}
				}
				List<DesignMscBiltEntity> biltSpecs = specInfo.getBlitSpecs();

				// 保存断面规格
				if (biltSpecs != null && biltSpecs.size() != 0) {
					biltSpecs = ServerDesignTool.fiterBiltSpec(biltSpecs);
					if (biltSpecs != null && biltSpecs.size() != 0) {
						for (DesignMscBiltEntity biltSpec : biltSpecs) {
							specLineDaoImp.saveBlankSection(con, biltSpec);
						}
					}
				}
				List<DesignMscBiltCEntity> biltsSpecs = specInfo
						.getBlitCSpecs();

				// 保存坯料规格
				if (biltsSpecs != null && biltsSpecs.size() != 0) {
					biltsSpecs = ServerDesignTool.fiterBiltCSpec(biltsSpecs);
					for (DesignMscBiltCEntity biltsSpec : biltsSpecs) {
						specLineDaoImp.saveStockSpecific(con, biltsSpec);
					}
				}

				// 保存制程适用产线
				List<DesignMscPlGxPrlEntity> proLines = proLineInfo
						.getProLines();
				for (DesignMscPlGxPrlEntity proLine : proLines) {
					specLineDaoImp.saveProLine(con, proLine);
				}

				// 保存铸造产线（含铸造规格）
				List<DesignMscBiltCPlEntity> biltCSpecLines = proLineInfo
						.getBiltCSpecLines();
				if (biltCSpecLines != null && biltCSpecLines.size() != 0) {
					for (DesignMscBiltCPlEntity blitCInLine : biltCSpecLines) {
						specLineDaoImp.saveBlits(con, blitCInLine);
					}
				}
				// 保存轧管产线（含轧管规格）
				List<DesignMscGzGgPlEntity> rollSpecLines = proLineInfo
						.getRollSpecLines();
				if (rollSpecLines != null && rollSpecLines.size() != 0) {
					for (DesignMscGzGgPlEntity specInline : rollSpecLines) {
						specLineDaoImp.saveSpec(con, specInline);
					}
				}

				// 保存锻造产线（含锻造规格）
				List<DesignMscBiltPlEntity> biltSpecLines = proLineInfo
						.getBiltSpecLines();
				if (biltSpecLines != null && biltSpecLines.size() != 0) {
					for (DesignMscBiltPlEntity biltInLine : biltSpecLines) {
						specLineDaoImp.saveBlank(con, biltInLine);
					}
				}

				// 计算压缩比
				// if (!wholeBacklog.contains("C")) {
				// if (!ServerDesignTool
				// .compressioRatio(rollSpecs, biltsSpecs)) {
				// proDuc.setWarnDesc("压缩比为≤3，但制程不经过锻造");
				// }
				// }
				// 保存制程
				if (setProDucs == null || setProDucs.size() == 0) {
					processDaoImp.saveProcess(con, proDuc, designKey);

				} else {
					String ordDesignKey = proDuc.getDesginKey();
					proDuc.setDesginKey(design.getDesignKey());
					processDaoImp.updateSetPl(con, proDuc, ordDesignKey);
				}
				// 保存锁定制程,用于锁定制程（MPS）
				if (design.getMpsFl().equals("1")) {
					qualityPreDao.saveDesignPlControl(con, ordLnPk,
							design.getOrderLineMsc(), proDuc.getMscPline());
				}
				/**
				 * 5、验证工序点(仅取工序点)
				 */
				OperationPointDaoImp operationPointDaoImp = FactoryDao
						.getOperationPointDaoImp();
				String[] processes = wholeBacklog.split("-");
				for (String porcess : processes) {
					List<DesignMscPlStiEntity> points = operationPointDaoImp
							.getDesignPoint(con, design.getOrderLineMsc(),
									proDuc.getMscPline(), porcess);
					if (points != null && points.size() > 0) {
						for (DesignMscPlStiEntity point : points) {
							point.setDesginKey(design.getDesignKey());

							operationPointDaoImp.saveOperationPoint(con, point);
						}
					}
				}
				if (setProDucs == null || setProDucs.size() == 0) {
					DesignStatusEntity statusUpset = null;
					if (proDuc.getWholeBacklog().contains("E")) {
						statusUpset = statusDaoImp.setDesignStatus(design,
								design.getOrderLineMsc(), "镦拔扩", "S", "11",
								"镦拔扩通过验证", proDuc.getMscPline(),
								design.getMscUnitCode(),
								design.getMscUnitDesc());
					} else {
						statusUpset = statusDaoImp.setDesignStatus(design,
								design.getOrderLineMsc(), "镦拔扩", "S", "00",
								"镦拔扩无要求", proDuc.getMscPline(),
								design.getMscUnitCode(),
								design.getMscUnitDesc());
					}
					statusDaoImp.updateDesignStatus(con, statusUpset);
					DesignStatusEntity statusGrade = statusDaoImp
							.setDesignStatus(design, design.getOrderLineMsc(),
									"钢种", "S", "11", "钢种通过验证",
									proDuc.getMscPline(),
									design.getMscDunitCode(),
									design.getMscDunitDesc());
					statusDaoImp.updateDesignStatus(con, statusGrade);
					DesignStatusEntity statusLine = statusDaoImp
							.setDesignStatus(design, design.getOrderLineMsc(),
									"适用产线", "S", "11", "适用产线通过验证",
									proDuc.getMscPline(),
									design.getMscUnitCode(),
									design.getMscUnitDesc());
					statusDaoImp.updateDesignStatus(con, statusLine);
					ducflag = true;
				}

			}
			if (!ducflag) {
				// 如果没有指定制程,有一项没有验证通过,则让操作人制定,指定完之后,就按这个制程走流程
				if (setProDucs == null || setProDucs.size() == 0) {
					String mscPline = "";
					for (DesignMscPlEntity proDuc : mscPlEntitys) {
						mscPline += proDuc.getMscPline() + ",";
					}
					// OBJ_KEY为1,则指定制程
					status = statusDaoImp.setDesignStatus(design, design
							.getOrderLineMsc(), "制程", "F", "91", "制程"
							+ mscPline.substring(0, mscPline.length() - 1)
							+ "交付标准与制程完整性通过验证,但(镦拔扩、规格、适用产线)某项未通过验证[未通过原因:"
							+ mscPlineMessage + "],请设定制程", "1", design
							.getMscDunitCode(), design.getMscDunitDesc());
					statusDaoImp.updateDesignStatus(con, status);
					statusDaoImp.updateDesignStsTklg(con, designKey, "", "F",
							"W");

					return core;
				} else {
					// 指定制程验证通过录入状态
					status = statusDaoImp.setDesignStatus(design,
							design.getOrderLineMsc(), "钢种", "S", "11",
							"钢种通过验证", "", design.getMscDunitCode(),
							design.getMscDunitDesc());
					statusDaoImp.updateDesignStatus(con, status);
					status = statusDaoImp.setDesignStatus(design,
							design.getOrderLineMsc(), "镦拔扩", "S", "11",
							"镦拔扩通过验证", "", design.getMscUnitCode(),
							design.getMscUnitDesc());
					statusDaoImp.updateDesignStatus(con, status);
					status = statusDaoImp.setDesignStatus(design,
							design.getOrderLineMsc(), "适用产线", "S", "11",
							"适用产线通过验证", "", design.getMscUnitCode(),
							design.getMscUnitDesc());
					statusDaoImp.updateDesignStatus(con, status);

				}

			}

			/**
			 * 十二、 合同附加要求
			 */
			AddAskImp addAskImp = FactoryServer.getAddAskImp();
			String addMessage = addAskImp.checkAddAsk(
					con, design.getAddAskNo(), design.getStdCode(), design.getOrdLnPk());
			if (addMessage.length() != 0) {
				status = statusDaoImp.setDesignStatus(design,
						design.getOrderLineMsc(), "合同附加要求", "F", "91",
						addMessage, design.getAddAskNo(),
						design.getMscUnitCode(), design.getMscUnitDesc());
				statusDaoImp.updateDesignStatus(con, status);
				statusDaoImp.updateDesignStsTklg(con, designKey, "", "F", "W");

				return core;
			} else {
				if (!design.getAddAskNo().equals("")) {
					status = statusDaoImp.setDesignStatus(design,
							design.getOrderLineMsc(), "合同附加要求", "S", "11",
							"产品附加要求通过验证", design.getOrderLineMsc(),
							design.getMscUnitCode(), design.getMscUnitDesc());
				} else {
					status = statusDaoImp.setDesignStatus(design,
							design.getOrderLineMsc(), "合同附加要求", "S", "00",
							"无产品附加要求", design.getOrderLineMsc(),
							design.getMscUnitCode(), design.getMscUnitDesc());
				}
				statusDaoImp.updateDesignStatus(con, status);
			}

			/**
			 * 十三、MPS
			 */
			// 删除操作在合同录入界面确认按钮执行
			if (design.getMpsFl().equals("1")) {
				MpsDaoImp mpsDaoImp = FactoryDao.getMpsDaoImp();
				if (mpsDaoImp.getTechParameter(con, ordPk, ordLnPk) == 0) {
					status = statusDaoImp.setDesignStatus(design,
							design.getOrderLineMsc(), "MPS", "F", "91",
							"合同行对MPS有要求,请维护MPS工艺参数", design.getOrderLineMsc(),
							design.getMscUnitCode(), design.getMscUnitDesc());
					statusDaoImp.updateDesignStatus(con, status);
					// 质量设计通过验证
					statusDaoImp.updateDesignStsTklg(con, designKey, "", "F",
							"W");

					return core;
				} else {
					status = statusDaoImp.setDesignStatus(design,
							design.getOrderLineMsc(), "MPS", "S", "11",
							"MPS通过验证", design.getOrderLineMsc(),
							design.getMscUnitCode(), design.getMscUnitDesc());
					statusDaoImp.updateDesignStatus(con, status);
				}
			} else {
				status = statusDaoImp.setDesignStatus(design,
						design.getOrderLineMsc(), "MPS", "S", "00", "MPS无要求",
						design.getOrderLineMsc(), design.getMscUnitCode(),
						design.getMscUnitDesc());
				statusDaoImp.updateDesignStatus(con, status);
			}
			/**
			 * 十四、 在线机探盲区切长
			 */
			IManInspectionDao IManInspectionDao = new IManInspectionDao();
			boolean inspectionFlag = IManInspectionDao.checkManInspection(con,
					designKey);
			if (design.getManInspection().equals("0") && inspectionFlag) {
				if (design.getInspectionValue().equals("")) {
					status = statusDaoImp.setDesignStatus(design,
							design.getOrderLineMsc(), "在线机探盲区切长", "F", "91",
							"请维护在线机探盲区切长", design.getOrderLineMsc(),
							design.getMscUnitCode(), design.getMscUnitDesc());
					statusDaoImp.updateDesignStatus(con, status);
					// 质量设计通过验证
					statusDaoImp.updateDesignStsTklg(con, designKey, "", "F",
							"W");
					return core;
				} else {
					status = statusDaoImp.setDesignStatus(design,
							design.getOrderLineMsc(), "在线机探盲区切长", "S", "11",
							"在线机探盲区切长已维护", design.getOrderLineMsc(),
							design.getMscUnitCode(), design.getMscUnitDesc());
					statusDaoImp.updateDesignStatus(con, status);
				}
			} else {
				status = statusDaoImp.setDesignStatus(design,
						design.getOrderLineMsc(), "在线机探盲区切长", "S", "00",
						"在线机探盲区切长无要求", design.getOrderLineMsc(),
						design.getMscUnitCode(), design.getMscUnitDesc());
				statusDaoImp.updateDesignStatus(con, status);
			}
			// 计划科
			unitCode = "002001001001";
			unitDesc = "计划科";
			if (saleInfo != null && saleInfo.length > 0 && "100105".equals(saleInfo[0]) || "120504".equals(saleInfo[2])) {
				// 天淮 计划科
				unitCode = "002023005003";
				unitDesc = "工艺科";
			}
			/**
			 * 十五、物料码
			 */
			try {
				BOMGeneration.generationBomMain(con, designKey, "0", "0");
				DesignStatusEntity statusBom = statusDaoImp.setDesignStatus(
						design, design.getOrderLineMsc(), "投入/产出物料", "S", "11",
						"投入/产出物料通过验证", design.getOrderLineMsc(),
						unitCode,unitDesc);
				statusDaoImp.updateDesignStatus(con, statusBom);
				statusDaoImp.updateDesignStsTklg(con, designKey, "", "S", "W");
			} catch (Exception e) {
				DesignStatusEntity statusBom = statusDaoImp.setDesignStatus(
						design, design.getOrderLineMsc(), "投入/产出物料", "F", "91",
						"投入/产出物料物料编码生成异常,请确认", design.getOrderLineMsc(),
						unitCode,unitDesc);
				statusDaoImp.updateDesignStsTklg(con, designKey, "", "F", "W");
				statusDaoImp.updateDesignStatus(con, statusBom);
				return core;
			}

			// 计算差异项
			DifferenceValue differenceValue = new DifferenceValue();
			differenceValue.checkDifference(con, designKey, ordPk, ordLnPk,
					design.getStdCode(), design.getAddAskNo(),
					design.getDimater(), design.getHeight(),
					design.getLengthMax());

			/**
			 * 十六、长度验证
			 */
			if(!con.toString().contains("172.16.2.128")){
				if (design.getOutsStlPileFl().equals("121902")
						|| design.getOutsStlPileFl().equals("121903")) {
					status = statusDaoImp.setDesignStatus(design,
							design.getOrderLineMsc(), "长度", "S", "00", "外购管,不计算长度",
							"", unitCode,unitDesc);
					statusDaoImp.updateDesignStatus(con, status);
				} else {
					LengthCalculateImp lengthCalculateImp = FactoryServer
							.getLengthCalculateImp();
					if (lengthCalculateImp.checkLength(con, design)) {
						status = statusDaoImp.setDesignStatus(design,
								design.getOrderLineMsc(), "长度", "S", "11",
								"长度验证通过", design.getOrderLineMsc(), unitCode,unitDesc);
						statusDaoImp.updateDesignStatus(con, status);
					} else {
						status = statusDaoImp.setDesignStatus(design,
								design.getOrderLineMsc(), "长度", "F", "90",
								"长度验证不能通过!", "", unitCode,unitDesc);
						statusDaoImp.updateDesignStatus(con, status);
						statusDaoImp.updateDesignStsTklg(con, designKey, "", "F",
								"W");
						return core;
					}
				}
			}else{
				status = statusDaoImp.setDesignStatus(design,
						design.getOrderLineMsc(), "长度", "S", "11",
						"长度验证通过", design.getOrderLineMsc(), unitCode,unitDesc);
				statusDaoImp.updateDesignStatus(con, status);
			}
			

			// 试样码评审
			// MscPhyImp mscPhyImp = FactoryServer.getMscPhyImp();
			// String msc0SplineMsg = mscPhyImp.checkPhy(con, design.getMsc(),
			// design, "0", true);
			// String mscnSplineMsg = mscPhyImp.checkPhy(con,
			// design.getOrderLineMsc(), design, "0", true);
			// if(msc0SplineMsg.equals("") && mscnSplineMsg.equals("")){
			// status = statusDaoImp.setDesignStatus(design,
			// design.getMsc(), "试样码", "S", "11",
			// "试样码评审验证通过", design.getMsc(),
			// "002001007011", "生产设备科");
			// statusDaoImp.updateDesignStatus(con, status);
			// }else{
			// if(!msc0SplineMsg.equals("")){
			// status = statusDaoImp.setDesignStatus(design,
			// design.getMsc(), "试样码", "F", "91",
			// msc0SplineMsg, design.getMsc(),
			// "002001007011", "生产设备科");
			// statusDaoImp.updateDesignStatus(con, status);
			// }else{
			// status = statusDaoImp.setDesignStatus(design,
			// design.getOrderLineMsc(), "试样码", "F", "91",
			// mscnSplineMsg, design.getOrderLineMsc(),
			// "002001007011", "生产设备科");
			// statusDaoImp.updateDesignStatus(con, status);
			// }
			// statusDaoImp.updateDesignStsTklg(con, designKey, "", "F",
			// "W");
			// }

			// ---------------------试样码（试样要求）------------0-MSC0 1-MSCN 2-内控
			IMscSplineDao mscSplineDao = new IMscSplineDao();
			String[] msc0SplineResults = mscSplineDao.CheckSpline(con, design,
					"0");
			String[] mscnSplineResults = mscSplineDao.CheckSpline(con, design,
					"1");

			if (msc0SplineResults[0].equals("")
					&& mscnSplineResults[0].equals("")) {
				status = statusDaoImp.setDesignStatus(design, design.getMsc(),
						"试样码", "S", "11", "试样码证通过", mscnSplineResults[1],
						"002001007011", "生产设备科");
				statusDaoImp.updateDesignStatus(con, status);
			} else {
				if (!msc0SplineResults[0].equals("")) {
					String objKey = msc0SplineResults[1] + "," + "0";
					status = statusDaoImp.setDesignStatus(design,
							design.getMsc(), "试样码", "S", "91",
							msc0SplineResults[0], objKey, "002001007011",
							"生产设备科");
					statusDaoImp.updateDesignStatus(con, status);
					// statusDaoImp.updateDesignStsTklg(con, designKey, "", "F",
					// "W");
				} else if (!mscnSplineResults[0].equals("")) {
					String objKey = mscnSplineResults[1] + "," + "1";
					status = statusDaoImp.setDesignStatus(design,
							design.getOrderLineMsc(), "试样码", "S", "91",
							mscnSplineResults[0], objKey, "002001007011",
							"生产设备科");
					statusDaoImp.updateDesignStatus(con, status);
					// statusDaoImp.updateDesignStsTklg(con, designKey, "", "F",
					// "W");
				}
				// return core;
			}

			// 质保书模版
			ZbsTemplateDao zbsTemplateDao = new ZbsTemplateDao();
			boolean templateResult = zbsTemplateDao.CheckTemplate(con,
					design.getOrderLineMsc(), design.getDimater(),
					design.getHeight(), design.getModelCode(),
					design.getSpecCode(), designKey);
			if (templateResult) {
				status = statusDaoImp.setDesignStatus(design,
						design.getOrderLineMsc(), "质保书模板", "S", "11",
						"质保书模板验证通过", design.getOrderLineMsc(), "002001015010",
						"质保站");
				statusDaoImp.updateDesignStatus(con, status);
			} else {
				status = statusDaoImp.setDesignStatus(design,
						design.getOrderLineMsc(), "质保书模板", "F", "91",
						"没有找到质保书模板，请维护！", design.getOrderLineMsc(),
						"002001015002", "检查科");
				statusDaoImp.updateDesignStatus(con, status);
				statusDaoImp.updateDesignStsTklg(con, designKey, "", "F", "W");
				return core;
			}

			// 检验项评审
			DetectionLeveDao detectionLeveDao = new DetectionLeveDao();
			String msc0DetectionLeveResult = detectionLeveDao
					.ChekDetectionLeve(con, design.getMsc());
			String mscnDetectionLeveResult = detectionLeveDao
					.ChekDetectionLeve(con, design.getOrderLineMsc());
			if (msc0DetectionLeveResult.equals("")
					&& mscnDetectionLeveResult.equals("")) {
				status = statusDaoImp.setDesignStatus(design, design.getMsc(),
						"检验项评审", "S", "11", "检验项评审验证通过", design.getMsc(),
						"002001015002", "检查科");
				statusDaoImp.updateDesignStatus(con, status);
			} else {
				String msg = "探伤级别" + msc0DetectionLeveResult + "无效";
				status = statusDaoImp.setDesignStatus(design, design.getMsc(),
						"检验项评审", "F", "91", msg, design.getMsc(),
						"002001015002", "检查科");
				statusDaoImp.updateDesignStatus(con, status);
				statusDaoImp.updateDesignStsTklg(con, designKey, "", "F", "W");
				return core;
			}
			
			//成分偏差
			// 成分偏差标准验证(先不卡住,只提示原因)
			IDeviationChem deviationChem = new IDeviationChem();
			String biasCic = IDeviationChemDao.getSlmCic(con, designKey, "0");
			String biasCicN = IDeviationChemDao.getSlmCic(con, designKey, "1");
			List<SlmOrdDesignStdCicEntity> chemBiasList = IDeviationChemDao.getSlmChem(con, designKey, "0");
			List<SlmOrdDesignStdCicEntity> chemNBiasList = IDeviationChemDao.getSlmChem(con, designKey, "1");
			if (!biasCic.equals("") || !biasCicN.equals("")) {
				// 验证msc0的成分偏差标准
				if (!biasCic.equals("")) {
					boolean cicFlag = deviationChem.checkDeviationChem(con,
							designKey, biasCic, biasGradeCode, biasGradeName,
							design.getSteelCode(), design.getSteelName(), "G",
							chemBiasList);
					if (cicFlag) {
						status = statusDaoImp.setDesignStatus(design, design.getMsc(),
								"成分偏差标准", "S", "11", "成分偏差标准验证通过", biasCic,
								design.getMscDunitCode(), design.getMscUnitDesc());
						statusDaoImp.updateDesignStatus(con, status);
					} else {
						status = statusDaoImp.setDesignStatus(design, design.getMsc(),
								"成分偏差标准", "F", "91", deviationChem.errMessage, biasCic,
								design.getMscDunitCode(), design.getMscUnitDesc());
						statusDaoImp.updateDesignStatus(con, status);
						statusDaoImp.updateDesignStsTklg(con, designKey, "", "F", "W");
						return core;
					}
				}
				// 验证mscn的成分偏差标准
				if (!biasCicN.equals("")) {
					boolean cicFlag = deviationChem.checkDeviationChem(con,
							designKey, biasCicN, biasGradeCode, biasGradeName,
							design.getSteelCode(), design.getSteelName(), "N",
							chemNBiasList);
					if (cicFlag) {
						status = statusDaoImp.setDesignStatus(design, design.getMsc(),
								"成分偏差标准", "S", "11", "成分偏差标准验证通过", biasCicN,
								design.getMscDunitCode(), design.getMscUnitDesc());
						statusDaoImp.updateDesignStatus(con, status);
					} else {
						status = statusDaoImp.setDesignStatus(design, design.getMsc(),
								"成分偏差标准", "F", "91", deviationChem.errMessage, biasCicN,
								design.getMscDunitCode(), design.getMscUnitDesc());
						statusDaoImp.updateDesignStatus(con, status);
						statusDaoImp.updateDesignStsTklg(con, designKey, "", "F", "W");
						return core;
					}
				}
			} else {
				status = statusDaoImp.setDesignStatus(design, design.getMsc(),
						"成分偏差标准", "S", "00", "成分偏差标准无要求", biasCicN,
						design.getMscDunitCode(), design.getMscUnitDesc());
				statusDaoImp.updateDesignStatus(con, status);
			}

			/**
			 * 十七、生产周期
			 */

			ProCycleImp proCycleImp = FactoryServer.getProCycleImp();
			DesignStatusEntity statusCycle = null;
			String message = proCycleImp.generateProCycle(con,
					design.getOrderLineMsc(), designKey, ordLnPk, "0");
			if (!message.equals("")) {
				statusCycle = statusDaoImp.setDesignStatus(design,
						design.getOrderLineMsc(), "生产周期", "F", "91",
						"生产周期验证失败," + message, design.getOrderLineMsc(),
						unitCode,unitDesc);
				statusDaoImp.updateDesignStatus(con, statusCycle);
				return core;
			} else {
				BomEntity bomEntity = GeneraBomEntity
						.generaBomEntity(designMscEntity);
				String[] materials = BomMaterial
						.formEndMaterial(bomEntity, con);
				BomQueryDaoImp bomDaoImp = BomFactoryDao.getBomQueryDaoImp();
				String firstPrdc = bomDaoImp.getFirstPrdc(con, materials[0]);
				statusCycle = statusDaoImp.setDesignStatus(design,
						design.getOrderLineMsc(), "生产周期", "S", "11",
						"生产周期通过验证", design.getOrderLineMsc(), unitCode,unitDesc);
				statusDaoImp.updateDesignStatus(con, statusCycle);
				// 质量设计通过验证
				statusDaoImp.updateDesignStsTklg(con, designKey, "", "S", "S");
				// 自动评审通过原则:物料码不是新物料 ，msc0 使用次数-1 ，如果有mscn 使用次数
				// -1,附加要求为空或者附加要求项都通过审批
				AutomaticReview automaticReview = new AutomaticReview();
				boolean autoFlag = automaticReview.automatic(con, firstPrdc,
						design.getMsc0UseCount(), design.getMscNUseCount(),
						design.getAddAskNo());
				if (autoFlag) {
					String[] arr = new String[] { ordPk, ordLnPk,
							design.getDesignKey() };
					ArrayList<String[]> listArr = new ArrayList<String[]>();
					listArr.add(arr);
					CoreOrderReviewTechnology coreOrderReviewTechnology = new CoreOrderReviewTechnology();
					coreOrderReviewTechnology.doCommit(listArr, "SYSTEM",
							"SYSTEM", "", "1", con);
				}
			}
			core.setResult(true);
			return core;

		} catch (Exception e) {
			try {
				System.out.println(e.getMessage());
				core.setV_errMsg(e.getMessage());
				con.rollback();
				con.close();
				return core;
			} catch (SQLException e1) {
			}
		} finally {
			try {
				con.close();
			} catch (SQLException e) {
			}
		}
		try {
			con.commit();
		} catch (SQLException e) {
			try {
				con.rollback();
			} catch (SQLException e1) {
				e1.printStackTrace();
			}
			e.printStackTrace();
		}
		core.setResult(true);
		return core;
	}
}
