package market.Qms.slmord.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;

import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;
import market.Qms.common.DataHelper;
import market.Qms.common.ReturnMsg;
import market.Qms.metallurgy.impl.ComMscServiceImpl;
import market.Qms.metallurgy.impl.ComMscStdCicServiceImpl;
import market.Qms.metallurgy.impl.ComMscStdDetectionServiceImpl;
import market.Qms.metallurgy.impl.ComMscStdPicServiceImpl;
import market.Qms.metallurgy.impl.ComMscStdSpecServiceImpl;
import market.Qms.metallurgy.mapper.ComBaseStdRCustMapper;
import market.Qms.metallurgy.mapper.ComMscMapper;
import market.Qms.metallurgy.mapper.ComMscStdChemMapper;
import market.Qms.metallurgy.mapper.ComMscStdCicMapper;
import market.Qms.metallurgy.mapper.ComMscStdDetectionCMapper;
import market.Qms.metallurgy.mapper.ComMscStdDetectionMapper;
import market.Qms.metallurgy.mapper.ComMscStdPhyMapper;
import market.Qms.metallurgy.mapper.ComMscStdPicMapper;
import market.Qms.metallurgy.mapper.ComMscStdSpecCMapper;
import market.Qms.metallurgy.mapper.ComMscStdSpecMapper;
import market.Qms.metallurgy.mapper.ComPscRMscMapper;
import market.Qms.metallurgy.vo.ComBaseStdRCust;
import market.Qms.metallurgy.vo.ComMsc;
import market.Qms.metallurgy.vo.ComMscStdChem;
import market.Qms.metallurgy.vo.ComMscStdCic;
import market.Qms.metallurgy.vo.ComMscStdDetection;
import market.Qms.metallurgy.vo.ComMscStdDetectionC;
import market.Qms.metallurgy.vo.ComMscStdPhy;
import market.Qms.metallurgy.vo.ComMscStdPic;
import market.Qms.metallurgy.vo.ComMscStdSpec;
import market.Qms.metallurgy.vo.ComMscStdSpecC;
import market.Qms.metallurgy.vo.ComPscRMsc;
import market.Qms.slmord.mapper.SlmOrdDesignMscNMapper;
import market.Qms.slmord.mapper.SlmOrdDesignStsTklgMapper;
import market.Qms.slmord.service.QualityDesignMscNService;
import market.Qms.slmord.service.QualityDesignStdCicService;
import market.Qms.slmord.service.QualityDesignStdDicService;
import market.Qms.slmord.service.QualityDesignStdPicService;
import market.Qms.slmord.service.QualityDesignStdSicService;
import market.Qms.slmord.vo.SlmOrdDesignMscN;
import market.Qms.slmord.vo.SlmOrdDesignStsTklg;
import market.Qms.slmord.vo.SlmReviewsCustAlpha;
import market.Slm.ContractManagement.impl.SlmCustAlphaServiceImpl;
import market.Slm.ContractManagement.mapper.SlmCustAlphaMapper;
import market.Slm.ContractManagement.vo.SlmCustAlpha;
import market.Slm.ContractManagement.vo.SlmCustAlphaChem;
import market.Slm.ContractManagement.vo.SlmCustAlphaDetection;
import market.Slm.ContractManagement.vo.SlmCustAlphaPhy;
import market.Slm.ContractManagement.vo.SlmCustAlphaSpec;
import market.Slm.OrderManagement.vo.SlmContractProcessPlan;

import org.springframework.beans.BeanUtils;
import org.springframework.transaction.annotation.Transactional;

import com.hnshituo.basic.service.impl.BaseServiceImpl;
import com.hnshituo.basic.spring.remoting.annotation.RemoteService;
import com.hnshituo.core.auth.service.HomeService;

/**
 * MSC(n) 评审
 * @author ZQ
 *
 */
@RemoteService(path="QualityDesignMscNService")
public class QualityDesignMscNServiceImpl  extends BaseServiceImpl<Object,Object> implements QualityDesignMscNService{

	@Override
	public boolean ValidationMscN(ReturnMsg msg, ComMsc _msc,SlmContractProcessPlan orderLine, String designKey) {
		ComMsc mscNEntity = this.getMapper(ComMscMapper.class).findById(orderLine.getMsc_n());
		// 如果为NULL，没有此MSC的记录
		if (mscNEntity == null) {
			msg.setMessage("有特殊要求,但找不到特殊要求MSC(N),请重新生成MSC(n)");
			return false;
		}
		// 无效的冶金规范码
		if (mscNEntity.getValidflag().equals("D")) {
			msg.setMessage("MSC(n)：‘" + orderLine.getMsc_n() + "’已无效");
			return false;
		}

		if (orderLine.getCustomer_alpha_no() == null) {
			mscNEntity.setPsc(orderLine.getPsc());
			boolean pass = this.getService(QualityDesignStdCicService.class).ValidationStdCIC(msg, mscNEntity,
					orderLine, designKey, "1");
			if (!pass) {
				return false;
			}
			pass = this.getService(QualityDesignStdPicService.class).ValidationStdPIC(msg, mscNEntity, orderLine,
					designKey, "1");
			if (!pass) {
				return false;
			}

			pass = this.getService(QualityDesignStdSicService.class).ValidationStdSIC(msg, mscNEntity, orderLine,
					designKey, "1");
			if (!pass) {
				return false;
			}
			pass = this.getService(QualityDesignStdDicService.class).ValidationStdDIC(msg, mscNEntity, orderLine,
					designKey, "1");
			if (!pass) {
				return false;
			}
			
			
			return true;

		}

		mscNEntity.setPsc(orderLine.getPsc());
		mscNEntity.setPsc_desc(orderLine.getPsc_desc());
		CommonPage<SlmCustAlpha> com = new CommonPage<>();
		SlmCustAlpha _alpha = new SlmCustAlpha();
		_alpha.setCust_alpha_no(orderLine.getCustomer_alpha_no());
		com.setObject(_alpha);
		ResultModel custModel = this.getBean(SlmCustAlphaServiceImpl.class).doQueryWeb(com);
		SlmCustAlpha custAlpha = (SlmCustAlpha) custModel.getData();
		mscNEntity.setPsc(orderLine.getPsc());
		// 成分标准
		if (custAlpha.getChemList().size() > 0) {
			boolean pass = this.getService(QualityDesignStdCicService.class).ValidationStdCIC(msg, mscNEntity,
					orderLine, designKey, "1");
			if (!pass) {
				return false;
			}
		}
		// 材质标准
		if (custAlpha.getPhyList().size() > 0) {
			boolean pass = this.getService(QualityDesignStdPicService.class).ValidationStdPIC(msg, mscNEntity,
					orderLine, designKey, "1");
			if (!pass) {
				return false;
			}
		}
		// 公差标准
		if (custAlpha.getSpecList().size() > 0) {
			boolean pass = this.getService(QualityDesignStdSicService.class).ValidationStdSIC(msg, mscNEntity,
					orderLine, designKey, "1");
			if (!pass) {
				return false;
			}
		}

		// 探伤标准
		if (custAlpha.getDetectionList().size() > 0) {
			boolean pass = this.getService(QualityDesignStdDicService.class).ValidationStdDIC(msg, mscNEntity,
					orderLine, designKey, "1");
			if (!pass) {
				return false;
			}
		}
		return true;
	}

	/**
	 * 获取默认成分索引信息
	 * @param msc
	 * @return
	 */
	private ComMscStdCic GetDefaultCic(ComMsc msc){
		
		ComMscStdCic cic = new ComMscStdCic();
		cic.setPsc(msc.getPsc());
		cic.setMsc(msc.getMsc());
		cic.setStd_type("G");
		cic.setCreate_name((String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME));
		cic.setCreate_time(new Date());
		cic.setValidflag("1");
		cic.setMemo("系统评审技术要求时自动创建");
		cic.setProd_line(msc.getProd_line());
		return cic;
		
	}
	
	/**
	 * 获取默认探伤索引信息
	 * @param msc
	 * @return
	 */
	private ComMscStdDetection GetDefaultDic(ComMsc msc){
		ComMscStdDetection dic = new ComMscStdDetection();
		dic.setPsc(msc.getPsc());
		dic.setMsc(msc.getMsc());
		dic.setStdType("G");
		dic.setValidflag("1");
		dic.setMemo("系统评审产品技术要求时自动创建");
		dic.setProdLine(msc.getProd_line());
		dic.setCreateName((String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME));
		dic.setCreateTime(new Date());
		return dic;

	}
	
	/**
	 * 获取默认公差索引信息
	 * @param msc
	 * @return
	 */
	private ComMscStdSpec GetDefaultSic(ComMsc msc){
		ComMscStdSpec sic = new ComMscStdSpec();
		sic.setPsc(msc.getPsc());
		sic.setMsc(msc.getMsc());
		sic.setStdType("G");
		sic.setValidflag("1");
		sic.setProdLine(msc.getProd_line());
		sic.setCreateName((String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME));
		sic.setCreateTime(new Date());
		return sic;
	}
	
	/**
	 * 获取默认材质索引信息
	 * @param msc
	 * @return
	 */
	private ComMscStdPic GetDefaultPic(ComMsc msc){
		ComMscStdPic pic = new ComMscStdPic();
		pic.setPsc(msc.getPsc());
		pic.setMsc(msc.getMsc());
		pic.setStdType("G");
		pic.setValidflag("1");
		pic.setMemo("系统评审技术要求时自动创建");
		pic.setProdLine(msc.getProd_line());
		pic.setCreateName((String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME));
		pic.setCreateTime(new Date());
		return pic;
	}
	
	@Override
	public ResultModel GetAlphaCust(CommonPage<ComBaseStdRCust> com){
		ResultModel rm=new ResultModel();
		try{
			ComBaseStdRCust cust=com.getObject();
			if(DataHelper.IsNullOrSpace(cust.getCustomer_no())||DataHelper.IsNullOrSpace(cust.getStd_code())){
				rm.setMsgInfo("标准编号与最终用户编号不能为空");
				rm.setState("500");
				return rm;
			}
			
			//查询 mscN
			ComPscRMscMapper rmMapperr=this.getMapper(ComPscRMscMapper.class);
			ComPscRMsc _pscMsc=new ComPscRMsc();
			_pscMsc.setValidflag("1");
			_pscMsc.setPsc(cust.getPsc());
			String condition="cust_alpha_no like '%"+cust.getCust_alpha_no()+"%'";
			List<ComPscRMsc> listPscMsc=rmMapperr.findWithCondition(_pscMsc,condition,"", 0, 0);
		
			if(listPscMsc.size()<1){
				rm.setState("404");
				rm.setMsgInfo("未找到适合客户的msc(n)");
				return rm;
			}
			
			// 调用销售的接口，获取客户的特殊要求
			CommonPage<SlmCustAlpha> coms = new CommonPage<>();
			SlmCustAlpha _alpha = new SlmCustAlpha();
			_alpha.setCust_alpha_no(cust.getCust_alpha_no());
			coms.setObject(_alpha);
			ResultModel custModel = this.getBean(SlmCustAlphaServiceImpl.class).doQueryWeb(coms);
			SlmCustAlpha custAlpha = (SlmCustAlpha) custModel.getData();
			// 客户需求的信息
			List<SlmCustAlphaChem> chemT = custAlpha.getChemList();
			List<SlmCustAlphaPhy> phyT = custAlpha.getPhyList();
			List<SlmCustAlphaSpec> specT = custAlpha.getSpecList();
			List<SlmCustAlphaDetection> detectionT = custAlpha.getDetectionList();
			// 标准索引号
			List<ComMscStdCic> listCic = new ArrayList<ComMscStdCic>();
			List<ComMscStdPic> listPic = new ArrayList<ComMscStdPic>();
			List<ComMscStdDetection> listDetection = new ArrayList<ComMscStdDetection>();
			List<ComMscStdSpec> listSpec = new ArrayList<ComMscStdSpec>();

			for (int i = 0; i < listPscMsc.size(); i++) {
				// 根据mscn查询标准索引号
				listCic = this.getMapper(ComMscStdCicMapper.class).findWithCondition(null,
						"PSC='" + cust.getPsc() + "' and MSC='" + listPscMsc.get(i).getMsc() + "'", null, 0, 0);
				listPic = this.getMapper(ComMscStdPicMapper.class).findWithCondition(null,
						"PSC='" + cust.getPsc() + "' and MSC='" + listPscMsc.get(i).getMsc() + "'", null, 0, 0);
				listDetection = this.getMapper(ComMscStdDetectionMapper.class).findWithCondition(null,
						"PSC='" + cust.getPsc() + "' and MSC='" + listPscMsc.get(i).getMsc() + "'", null, 0, 0);
				listSpec = this.getMapper(ComMscStdSpecMapper.class).findWithCondition(null,
						"PSC='" + cust.getPsc() + "' and MSC='" + listPscMsc.get(i).getMsc() + "'", null, 0, 0);
				// 过滤大项
				boolean pass = FilterBigItems(listPscMsc, chemT, phyT, specT, detectionT, listCic, listPic,
						listDetection, listSpec);
				if (!pass) {
					listPscMsc.remove(listPscMsc.get(i));
					i--;
					continue;
				}

				// 判断成分是否满足
				/*if (chemT != null && chemT.size() > 0) {

					// 过滤索引号的 交货状态
					FilterDeliveryChem(cust.getOrderLine().getDelivery_state_code(), listCic);
					if (listCic != null && listCic.size() > 1) {
						listPscMsc.remove(listPscMsc.get(i));
						i--;
						continue;
					}
					if (listCic != null && listCic.size() == 1) {
						// 过滤项目
						boolean judge = judgetChem(cust, chemT, listCic);

						// 项目验证不通过，则此mscn不符合需求，进行下一个循环
						if (!judge) {
							listPscMsc.remove(listPscMsc.get(i));
							i--;
							continue;
						}

					}

				}*/

				// 判断材质
				if (phyT.size() > 0) {

					FilterDeliveryQlty(cust, listPic);
					
					if (listPic == null || listPic.size()<1) {
						listPscMsc.remove(listPscMsc.get(i));
						i--;
						continue;
					}

					if (listPic != null && listPic.size()>1) {
						listPscMsc.remove(listPscMsc.get(i));
						i--;
						continue;
					}
					if (listPic != null && listPic.size() == 1) {
						// 过滤项目

						if (!judgePhy(phyT, listPic, cust)) {
							listPscMsc.remove(listPscMsc.get(i));
							i--;
							continue;
						}

					}

				}

				if (specT.size() > 0) {
					FilterDeliverySpec(cust, listSpec);
					if (listSpec != null && listSpec.size() > 1) {
						listPscMsc.remove(listPscMsc.get(i));
						i--;
						continue;
					}

					if (listSpec != null && listSpec.size() == 1) {
						if (!judgeSpec(specT, listSpec, cust)) {
							listPscMsc.remove(listPscMsc.get(i));
							i--;
							continue;
						}

					}

				}

				/*if (detectionT != null && detectionT.size() > 0) {
					FilterDeliveryDection(cust, listDetection);
					if (listDetection != null && listDetection.size() > 1) {
						listPscMsc.remove(listPscMsc.get(i));
						i--;
						continue;
					}
					if (listDetection != null && listDetection.size() == 1) {
						if (!judgeDetection(detectionT, listDetection, cust)) {
							listPscMsc.remove(listPscMsc.get(i));
							i--;
							continue;
						}

					}

				}*/

			}
			
			
			
			
			
			
			
			List<String> _listMsc=new ArrayList<>();
			for (ComPscRMsc comPscRMsc : listPscMsc) {
				_listMsc.add(comPscRMsc.getMsc());
			}
			condition=DataHelper.CreateSqlCondition(_listMsc, "msc");
			List<ComMsc> listMsc=this.getMapper(ComMscMapper.class).findWithCondition(null, condition, null, 0, 0);
			rm.setState("200");
			rm.setData(listMsc);	
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("查询出错："+ex.getMessage());
		}
		return rm;
	}
	
	@Override
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel ApproverPass(CommonPage<ComBaseStdRCust> com) throws Exception{
		ResultModel rm=new ResultModel();
		ComBaseStdRCust cust=com.getObject();
		if(!DataHelper.IsNullOrSpace(cust.getMsc_n())){
			ComPscRMsc _prMsc=new ComPscRMsc();
			_prMsc.setPsc(cust.getPsc());
			_prMsc.setMsc(cust.getMsc_n());
			List<ComPscRMsc> listPRMsc=this.getMapper(ComPscRMscMapper.class).find(_prMsc, 0, 0);
			listPRMsc.get(0).setCust_alpha_no(listPRMsc.get(0).getCust_alpha_no()+","+cust.getCust_alpha_no());
			this.getMapper(ComPscRMscMapper.class).update(listPRMsc.get(0));
			/*SlmProcessPlan plan=new SlmProcessPlan();
			plan.setMsc(cust.getMsc_n());
			plan.setPlan_no(cust.getPlan_no());
			this.getMapper(SlmProcessPlanMapper.class).update(plan);*/
			rm.setState("200");
			rm.setMsgInfo("为订单设置制造规范码为‘"+cust.getMsc_n()+"’成功");
			return rm;
		}

		String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		ComBaseStdRCustMapper custMapper=this.getMapper(ComBaseStdRCustMapper.class);
		ComBaseStdRCust _cust=new ComBaseStdRCust();
		_cust.setCustomer_no(cust.getCustomer_no());
		_cust.setAlpha_code(cust.getAlpha_code());
		List<ComBaseStdRCust> listRCust=custMapper.find(_cust, 0, 0);
		if(listRCust.size()<1){
			//新增客户用途码
			cust.setValidflag("1");
			cust.setCreate_name(userName);
			cust.setCreate_time(new Date());
			custMapper.insert(cust);
		}
		//创建msc(n)
		ComMsc _msc=this.getMapper(ComMscMapper.class).findById(cust.getMsc());
		ComMsc msc=new ComMsc();
		DataHelper.CopyEntity(_msc, msc);
		msc.setAlpha_code(cust.getAlpha_code());
		msc.setAlpha_name(cust.getAlpha_name());
		msc.setMsc_seq(_msc.getMsc());
		msc.setMsc_desc_seq(_msc.getMsc_desc());
		msc.setMsc(null);
		msc.setPsc(cust.getPsc());
		msc.setMsc_desc(_msc.getMsc_desc());
		msc.setCust_alpha_no(cust.getCust_alpha_no());
		msc.setValidflag("A");// 审核通过，则变为已生效
		List<ComMsc> listMsc=new ArrayList<>();
		listMsc.add(msc);
		ComMscServiceImpl mscImpl = this.getBean(ComMscServiceImpl.class);
		CommonPage<ComMsc> _page = new CommonPage<>();
		_page.setObjectList(listMsc);
		mscImpl.doAddmsc(_page);
		
		//设置该mscN适用当前客户
		/*ComPscRMsc _prMsc=new ComPscRMsc();
		_prMsc.setPsc(cust.getPsc());
		_prMsc.setMsc(_page.getObjectList().get(0).getMsc());
		List<ComPscRMsc> listPRMsc=this.getMapper(ComPscRMscMapper.class).find(_prMsc, 0, 0);
		listPRMsc.get(0).setCust_alpha_no(listPRMsc.get(0).getCust_alpha_no()+","+cust.getCust_alpha_no());
		this.getMapper(ComPscRMscMapper.class).update(listPRMsc.get(0));*/
		
		//修改加工计划 msc
		/*SlmProcessPlan plan=new SlmProcessPlan();
		plan.setMsc(_page.getObjectList().get(0).getMsc());
		plan.setPlan_no(cust.getOrderLine().getContract_line_no());
		plan.setMsc_desc(_page.getObjectList().get(0).getMsc_desc());
		this.getMapper(SlmProcessPlanMapper.class).update(plan);*/
		//新增客户标准
		if(cust.getListChem()!=null&&cust.getListChem().size()>0){
			ComMscStdCic stdCic = GetDefaultCic(msc);
			stdCic.setStd_type("G");
			stdCic.setPsc(cust.getOrderLine().getPsc());
			stdCic.setDelivery_state_code(cust.getOrderLine().getDelivery_state_code());
			stdCic.setDelivery_state_desc(cust.getOrderLine().getDelivery_state_desc());
			List<ComMscStdCic> listCic = new ArrayList<>();
			listCic.add(stdCic);
			this.getBean(ComMscStdCicServiceImpl.class).doSaveCicG(listCic);
			ComMscStdChemMapper chemMapper = this.getMapper(ComMscStdChemMapper.class);
				for (SlmCustAlphaChem chem : cust.getListChem()) {
					ComMscStdChem _chem = new ComMscStdChem();
					BeanUtils.copyProperties(chem, _chem);
					// DataHelper.CopyEntity(chem, _chem);
					_chem.setCic(stdCic.getCic());
					_chem.setStdmaxSign(chem.getStdmax_sign());
					_chem.setStdmax(chem.getStdmax());
					_chem.setStdmin(chem.getStdmin());
					_chem.setStdminSign(chem.getStdmin_sign());
					_chem.setChemCode(chem.getChem_code());
					_chem.setChemName(chem.getChem_name());
					_chem.setChemFormula(chem.getChem_formula());
					_chem.setChemType(chem.getChem_type());
					_chem.setComplexType(chem.getComplex_type());
					_chem.setEleCode(chem.getEle_code());
					_chem.setEleName(chem.getEle_name());
					_chem.setEleMax(chem.getEle_max());
					_chem.setEleMaxSign(chem.getEle_max_sign());
					_chem.setEleMin(chem.getEle_min());
					_chem.setEleMinSign(chem.getEle_min_sign());
					_chem.setIndexSeq(chem.getIndex_seq());
					_chem.setModelCode(chem.getModel_code());
					_chem.setModelDesc(chem.getModel_desc());
					_chem.setRepCode(chem.getRep_code());
					_chem.setRepMax(chem.getRep_max());
					_chem.setRepMaxSign(chem.getRep_max_sign());
					_chem.setRepMin(chem.getRep_min());
					_chem.setRepMinSign(chem.getRep_min_sign());
					_chem.setRepName(chem.getRep_name());
					_chem.setRepVal(chem.getRep_val());
					if (chem.getRound_off_digits() != null) {
						_chem.setRoundOffDigits(chem.getRound_off_digits());
					}
					
					_chem.setRoundOffRulesCode(chem.getRound_off_rules_code());
					_chem.setRoundOffRulesName(chem.getRound_off_rules_name());
					_chem.setValidflag("1");
					_chem.setStd_type_code(chem.getStd_type_code());
					_chem.setStd_type_name(chem.getStd_type_name());
					
					_chem.setSizeCode("400301");
					_chem.setSizeName("厚度");
					_chem.setSizeCode2("400302");
					_chem.setSizeName2("宽度");
					_chem.setSizeMin(cust.getThick());
					_chem.setSizeMinSign(">=");
					_chem.setSizeMax(cust.getThick());
					_chem.setSizeMaxSign("<=");
					_chem.setSizeMin2(cust.getWidth());
					_chem.setSizeMinSign2(">=");
					_chem.setSizeMax2(cust.getWidth());
					_chem.setSizeMaxSign2("<=");
					chemMapper.insert(_chem);
				}
		}
		if(cust.getListSpec()!=null&&cust.getListSpec().size()>0){
			ComMscStdSpec stdSic = GetDefaultSic(msc);
			stdSic.setPsc(cust.getOrderLine().getPsc());
			stdSic.setPrecisiconTypeCode(cust.getOrderLine().getH_precisicon_type_code());
			stdSic.setPrecisiconTypeDesc(cust.getOrderLine().getH_precisicon_type_desc());
			//stdSic.setDeliveryStateCode(cust.getOrderLine().getDelivery_state_code());
			//stdSic.setDeliveryStateDesc(cust.getOrderLine().getDelivery_state_desc());
			List<ComMscStdSpec> listSic = new ArrayList<>();
			listSic.add(stdSic);
			this.getBean(ComMscStdSpecServiceImpl.class).doSaveComMscStdSpec(listSic);
			ComMscStdSpecCMapper specMapper = this.getMapper(ComMscStdSpecCMapper.class);
				for (SlmCustAlphaSpec spec : cust.getListSpec()) {
					ComMscStdSpecC _spec = new ComMscStdSpecC();
					DataHelper.CopyEntity(spec, _spec);
					_spec.setSic(stdSic.getSic());
					_spec.setIndexSeq(spec.getIndex_seq());
					_spec.setLvCode(spec.getLv_code());
					_spec.setLvDesc(spec.getLv_desc());
					_spec.setBiasCode(spec.getBias_code());
					_spec.setBiasName(spec.getBias_name());
					_spec.setIscheck(spec.getIscheck());
					_spec.setStdMinVal(spec.getStd_min_val());
					_spec.setStdMaxVal(spec.getStd_max_val());	
					/*_spec.setBiasCodeZ("404001");
					_spec.setBiasNameZ("厚度");
					_spec.setZmin(cust.getThick());
					_spec.setZminSign(">=");
					_spec.setZmax(cust.getThick());
					_spec.setZmaxSign("<=");
					_spec.setBiasCodeC("404002");
					_spec.setBiasNameC("宽度");
					_spec.setCmin(cust.getWidth());
					_spec.setCminSign(">=");
					_spec.setCmax(cust.getWidth());
					_spec.setCmaxSign("<=");*/
					_spec.setCut_edge_type_no(cust.getOrderLine().getCut_edge_type_code());
					_spec.setCut_edge_type_name(cust.getOrderLine().getCut_edge_type_name());
					specMapper.insert(_spec);
				}
		}
		if(cust.getListPhy()!=null&&cust.getListPhy().size()>0){
				createPicAndPhy(cust, msc);
				/*ComMscStdPic stdPic=GetDefaultPic(msc);
				List<ComMscStdPic> listPic=new ArrayList<>();
				listPic.add(stdPic);
				this.getBean(ComMscStdPicServiceImpl.class).doSaveComMscStdPic(listPic);
				ComMscStdPhyMapper phyMapper=this.getMapper(ComMscStdPhyMapper.class);
				for (SlmCustAlphaPhy phy : cust.getListPhy()) {
					ComMscStdPhy _phy=new ComMscStdPhy();
					DataHelper.CopyEntity(phy, _phy);
					_phy.setPic(stdPic.getPic());
					_phy.setSizeCode("400301");
					_phy.setSizeName("宽度");
					_phy.setSizeCode2("400302");
					_phy.setSizeName2("厚度");
					_phy.setSizeMin(cust.getWidth());
					_phy.setSizeMinSign("=");
					_phy.setSizeMin2(cust.getThick());
					_phy.setSizeMinSign2("=");
					phyMapper.insert(_phy);
				}*/
		}
		if(cust.getListDetecion()!=null&&cust.getListDetecion().size()>0){
			ComMscStdDetection stdDic = GetDefaultDic(msc);//
			stdDic.setPsc(cust.getOrderLine().getPsc());
			stdDic.setDeliveryStateCode(cust.getOrderLine().getDelivery_state_code());
			stdDic.setDeliveryStateDesc(cust.getOrderLine().getDelivery_state_desc());
			List<ComMscStdDetection> listDic = new ArrayList<>();
			listDic.add(stdDic);
			this.getBean(ComMscStdDetectionServiceImpl.class).doSaveComMscStdDetection(listDic);
			ComMscStdDetectionCMapper dicMapper = this.getMapper(ComMscStdDetectionCMapper.class);
				for (SlmCustAlphaDetection dic : cust.getListDetecion()) {
					ComMscStdDetectionC _dic = new ComMscStdDetectionC();
					DataHelper.CopyEntity(dic, _dic);
					_dic.setDic(stdDic.getDic());
					_dic.setIndexSeq(dic.getIndex_seq());
					_dic.setMinD(cust.getWidth());
					_dic.setMaxD(cust.getWidth());
					_dic.setMaxH(cust.getThick());
					_dic.setMinH(cust.getThick());
					_dic.setMinDSign(">=");
					_dic.setMinHSign(">=");
					_dic.setMaxDSign("<=");
					_dic.setMaxHSign("<=");
					dicMapper.insert(_dic);
				}
		}	
		
		SlmOrdDesignMscN newMsnc = new SlmOrdDesignMscN();
		newMsnc.setContract_line_no(cust.getOrderLine().getContract_line_no());
		newMsnc.setMsc(msc.getMsc());
		this.getMapper(SlmOrdDesignMscNMapper.class).insert(newMsnc);
		rm.setMsgInfo("操作成功");
		rm.setState("200");
		return rm;
	}

	private void createPicAndPhy(ComBaseStdRCust cust, ComMsc msc) {
		ComMscStdPic stdPic = GetDefaultPic(msc);//
		stdPic.setPsc(cust.getOrderLine().getPsc());
		List<ComMscStdPic> listPic = new ArrayList<>();
		listPic.add(stdPic);
		/*stdPic.setDeliveryStateCode(cust.getOrderLine().getDelivery_state_code());
		stdPic.setDeliveryStateDesc(cust.getOrderLine().getDelivery_state_desc());*/
		this.getBean(ComMscStdPicServiceImpl.class).doSaveComMscStdPic(listPic);
		ComMscStdPhyMapper phyMapper = this.getMapper(ComMscStdPhyMapper.class);
		for (SlmCustAlphaPhy phy : cust.getListPhy()) {
			ComMscStdPhy _phy = new ComMscStdPhy();
			BeanUtils.copyProperties(phy, _phy);
			_phy.setPic(stdPic.getPic());
			_phy.setIndexSeq(phy.getIndex_seq());
			_phy.setPhyCodeL(phy.getPhy_code_l());
			_phy.setPhyNameL(phy.getPhy_name_l());
			_phy.setPhyCodeM(phy.getPhy_code_m());
			_phy.setPhyNameM(phy.getPhy_name_m());
			_phy.setPhyCodeS(phy.getPhy_code_s());
			_phy.setPhyNameS(phy.getPhy_name_s());
			_phy.setItemCodeD(phy.getItem_code_d());
			_phy.setItemCodeS(phy.getItem_code_s());
			_phy.setItemCodeT(phy.getItem_code_t());
			_phy.setItemNameD(phy.getItem_name_d());
			_phy.setItemNameS(phy.getItem_name_s());
			_phy.setItemNameT(phy.getItem_name_t());
			_phy.setIscheck(phy.getIscheck());
			_phy.setIsjudge(phy.getIsjudge());
			_phy.setIsquote(phy.getIsquote());
			_phy.setPhyType(phy.getPhy_type());
			_phy.setJudgeBasis(phy.getJudge_basis());
			_phy.setSampleStyleCode(phy.getSampleStyleCode());
			_phy.setSampleStyleName(phy.getSampleStyleName());
			if (phy.getRound_off_digits() != null) {
				_phy.setRoundOffDigits(phy.getRound_off_digits());
			}
			_phy.setRoundOffRulesCode(phy.getRound_off_rules_code());
			_phy.setRoundOffRulesName(phy.getRound_off_rules_name());
			_phy.setStdmin(phy.getStdmin());
			_phy.setStdminSign(phy.getStdmin_sign());
			_phy.setStdmax(phy.getStdmax());
			_phy.setStdmaxSign(phy.getStdmax_sign());
			_phy.setPhyType(phy.getPhy_type());
			_phy.setPhyFormula(phy.getPhy_formula());
			/*_phy.setDeliveryStateCode(phy.getDelivery_state_code());
			_phy.setDeliveryStateDesc(phy.getDelivery_state_name());
			_phy.setSizeCode("400301");
			_phy.setSizeName("厚度");
			_phy.setSizeCode2("400302");
			_phy.setSizeName2("宽度");
			_phy.setSizeMin(cust.getThick());
			_phy.setSizeMinSign(">=");
			_phy.setSizeMax(cust.getThick());
			_phy.setSizeMaxSign("<=");
			_phy.setSizeMin2(cust.getWidth());
			_phy.setSizeMinSign2(">=");
			_phy.setSizeMax2(cust.getWidth());
			_phy.setSizeMaxSign2("<=");*/
			_phy.setSampleStyleCode("409401");
			_phy.setSampleStyleName("常规");
			_phy.setCreateTime(new Date());
			List<ComMscStdPhy> phys = this.getMapper(ComMscStdPhyMapper.class).findWithCondition(null,
					"PIC='" + stdPic.getPic() + "'", "INDEX_SEQ desc", 0, 0);
			if (phys != null && phys.size() > 0) {
				_phy.setIndexSeq(phys.get(0).getIndexSeq() + 1);
			} else {
				_phy.setIndexSeq(1);
			}
			phyMapper.insert(_phy);
		}
	}

	@Override
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel ApproverNotPass(CommonPage<SlmReviewsCustAlpha> com) {
		// TODO Auto-generated method stub
		ResultModel rm=new ResultModel();
		try{
			String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
			SlmReviewsCustAlpha param=com.getObject();
			//操作质量设计主记录评审不通过
			SlmOrdDesignStsTklgMapper tklgMapper=this.getMapper(SlmOrdDesignStsTklgMapper.class); 
			SlmOrdDesignStsTklg _tklg=new SlmOrdDesignStsTklg();
			_tklg.setOrd_ln_pk(param.getContractLineNo());
			List<SlmOrdDesignStsTklg> listTklg=tklgMapper.find(_tklg,0,0);
			listTklg.get(0).setDesign_sts("F");
			tklgMapper.update(listTklg.get(0));
			
			//操作合同行评审不通过
/*			SlmContractLineInfo line=new SlmContractLineInfo();
			line.setContract_line_no(param.getContractLineNo());
			rm=this.getBean(SlmContractLineInfoServiceImpl.class).doReviewFail(line);*/
			
			//操作合同客户要求表评审不通过
			SlmCustAlpha _alpha=new SlmCustAlpha();
			_alpha.setCust_alpha_sts("F");
			_alpha.setValidflag("1");
			_alpha.setUpdate_name(userName);
			_alpha.setUpdate_time(new Date());
			_alpha.setReview_f_rs(param.getMemo());
			_alpha.setCust_alpha_no(param.getCustAlphaNo());
			SlmCustAlphaMapper mapper=this.getMapper(SlmCustAlphaMapper.class);
			mapper.update(_alpha);
			
			rm.setMsgInfo("操作成功");
			rm.setState("200");
			
		}catch(Exception ex){
			rm.setMsgInfo("操作失败："+ex.getMessage());
			rm.setState("500");
		}
		return rm;
	}

	
	/**
	 * 过滤大项是否与客户要求的大项匹配
	 * 
	 * @param listPscMsc
	 * @param chemT
	 * @param phyT
	 * @param specT
	 * @param detectionT
	 * @param listCic
	 * @param listPic
	 * @param listDetection
	 * @param listSpec
	 * @param i
	 * @return
	 */

	public boolean FilterBigItems(List<ComPscRMsc> listPscMsc, List<SlmCustAlphaChem> chemT, List<SlmCustAlphaPhy> phyT,
			List<SlmCustAlphaSpec> specT, List<SlmCustAlphaDetection> detectionT, List<ComMscStdCic> listCic,
			List<ComMscStdPic> listPic, List<ComMscStdDetection> listDetection, List<ComMscStdSpec> listSpec) {
		if ((chemT.size() > 0 && listCic.size() < 1) || (chemT.size() < 1 && listCic.size() > 0)) {
			return false;
		}

		if ((phyT.size() > 0 && listPic.size() < 1) || (phyT.size() < 1 && listPic.size() > 0)) {

			return false;
		}
		if ((specT.size() > 0 && listSpec.size() < 1) || (specT.size() < 1 && listSpec.size() > 0)) {

			return false;
		}
		if ((detectionT.size() > 0 && listDetection.size() < 1)
				|| (detectionT.size() < 1 && listDetection.size() > 0)) {

			return false;
		}
		return true;
	}
	
	/**
	 * 过滤材质交货状态和精度类型
	 * 
	 * @param cust
	 * @param listPic
	 */

	private void FilterDeliveryQlty(ComBaseStdRCust cust, List<ComMscStdPic> listPic) {

		for (int i = 0; i < listPic.size(); i++) {
			if (listPic.get(i).getDeliveryStateCode() != null
					&& !listPic.get(i).getDeliveryStateCode().contains(cust.getOrderLine().getDelivery_state_code())) {

				listPic.remove(listPic.get(i));
				i--;
			}

		}

	}
	
	
	private boolean judgePhy(List<SlmCustAlphaPhy> phyT, List<ComMscStdPic> listPic, ComBaseStdRCust cust) {
		List<ComMscStdPhy> phyStandard = this.getMapper(ComMscStdPhyMapper.class).findWithCondition(null,
				"PIC='" + listPic.get(0).getPic() + "' and VALIDFLAG='1'", null, 0, 0);

		HashSet<String> stands = new HashSet<String>();
		for (int j = 0; j < phyStandard.size(); j++) {
			String standProject = phyStandard.get(j).getPhyCodeL() + phyStandard.get(j).getPhyCodeM()
					+ phyStandard.get(j).getPhyCodeS() + phyStandard.get(j).getItemCodeD()
					+ phyStandard.get(j).getItemCodeS() + phyStandard.get(j).getItemCodeT()+phyStandard.get(j).getSampleStyleCode();
			stands.add(standProject);

		}
		// 判断项目个数是否满足
		if (stands.size() != phyT.size()) {
			return false;
		}

		// 过滤项目
		boolean judge = FilterSpecificationsPhy(stands, phyT);

		if (!judge) {

			return false;

		}
		// 过滤标准
		List<String> tarP = new ArrayList<String>();
		for (int i = 0; i < phyStandard.size(); i++) {
			ComMscStdPhy comPhy = FilterPhy(phyStandard.get(i), cust.getOrderLine());
			if (comPhy != null) {
				// 过滤标准
				judge = FilterStandPhy(phyStandard.get(i), phyT);

				if (!judge) {
					return false;
				}

				// 过滤交货状态
				if (phyStandard.get(i).getDeliveryStateCode() != null && !phyStandard.get(i).getDeliveryStateCode()
						.contains(cust.getOrderLine().getDelivery_state_code())) {
					return false;
				}
				tarP.add(comPhy.getPhyCodeL() + comPhy.getPhyCodeM() + comPhy.getPhyCodeS() + comPhy.getItemCodeD()
						+ comPhy.getItemCodeS() + comPhy.getItemCodeT()+comPhy.getSampleStyleCode());

			}

		}

		if (tarP != null && tarP.size() > 0) {
			stands.clear();
			stands.addAll(tarP);
			if (stands.size() != tarP.size()) {
				return false;
			}
		}

		return true;
	}
	
	
	
	
	/**
	 * 过滤项目
	 * 
	 * @param stands
	 * @param phyT
	 * @return
	 */
	private boolean FilterSpecificationsPhy(HashSet<String> stands, List<SlmCustAlphaPhy> phyT) {

		for (SlmCustAlphaPhy slmCustAlphaPhy : phyT) {
			String project = slmCustAlphaPhy.getPhy_code_l() + slmCustAlphaPhy.getPhy_code_m()
					+ slmCustAlphaPhy.getPhy_code_s() + slmCustAlphaPhy.getItem_code_d()
					+ slmCustAlphaPhy.getItem_code_s() + slmCustAlphaPhy.getItem_code_t()+slmCustAlphaPhy.getSampleStyleCode();
			if (!stands.contains(project)) {
				return false;

			}

		}

		return true;
	}
	
	
	
	/**
	 * 过滤材质规格
	 */
	public ComMscStdPhy FilterPhy(ComMscStdPhy _stdPhy, SlmContractProcessPlan orderLine) {

		// 过滤限制规格 厚 400301， 宽 400302， 长 400306

		if (!DataHelper.IsNullOrSpace(_stdPhy.getSizeCode())) {// 为空则适用全部规格
			// 过滤限制规格一
			if (_stdPhy.getSizeCode().equals("400301")) {
				boolean pass;

				if (_stdPhy.getSizeMax() == null) {
					pass = true;
				} else {
					pass = DataHelper.checkSignAndValue(_stdPhy.getSizeMaxSign(),
							Double.parseDouble(_stdPhy.getSizeMax()), orderLine.getThick().toString());

				}
				if (!pass) {
					return null;
				}

				if (_stdPhy.getSizeMin() == null) {
					pass = true;
				} else {
					pass = DataHelper.checkSignAndValue(_stdPhy.getSizeMinSign(),
							Double.parseDouble(_stdPhy.getSizeMin()), orderLine.getThick().toString());

				}
				if (!pass) {
					return null;
				}
			}
			// 验证限制规格二
			if (!DataHelper.IsNullOrSpace(_stdPhy.getSizeCode2())) {
				if (_stdPhy.getSizeCode2().equals("400301")) {
					boolean pass;

					if (_stdPhy.getSizeMax2() == null) {
						pass = true;
					} else {
						pass = DataHelper.checkSignAndValue(_stdPhy.getSizeMaxSign2(),
								Double.parseDouble(_stdPhy.getSizeMax2()), orderLine.getThick().toString());

					}

					if (!pass) {
						return null;
					}

					if (_stdPhy.getSizeMin2() == null) {
						pass = true;
					} else {
						pass = DataHelper.checkSignAndValue(_stdPhy.getSizeMinSign2(),
								Double.parseDouble(_stdPhy.getSizeMin2()), orderLine.getThick().toString());

					}
					if (!pass) {
						return null;
					}
				}
			}
		}

		return _stdPhy;
	}
	
	

	/**
	 * 判断标准规格，是否满足订单要求的规格
	 * 
	 * @param comMscStdPhy
	 * @param phyT
	 * @return
	 */

	public boolean FilterStandPhy(ComMscStdPhy comMscStdPhy, List<SlmCustAlphaPhy> phyT) {

		String old = comMscStdPhy.getPhyCodeL() + comMscStdPhy.getPhyCodeM() + comMscStdPhy.getPhyCodeS()
				+ comMscStdPhy.getItemCodeD() + comMscStdPhy.getItemCodeS() + comMscStdPhy.getItemCodeT()+comMscStdPhy.getSampleStyleCode();
		for (SlmCustAlphaPhy phy : phyT) {
			String newProject = phy.getPhy_code_l() + phy.getPhy_code_m() + phy.getPhy_code_s() + phy.getItem_code_d()
					+ phy.getItem_code_s() + phy.getItem_code_t()+phy.getSampleStyleCode();

			if (old.equals(newProject)) {
				// 判断项目规格标准是否满足要求
				boolean pass;
				if (comMscStdPhy.getStdmin() == null) {
					pass = true;
				} else {
					pass = DataHelper.checkSignAndValue(comMscStdPhy.getStdminSign(),
							Double.parseDouble(comMscStdPhy.getStdmin()), phy.getStdmin());

				}

				if (!pass) {
					return false;
				}

				if (comMscStdPhy.getStdmax() == null) {
					pass = true;
				} else {
					pass = DataHelper.checkSignAndValue(comMscStdPhy.getStdmaxSign(),
							Double.parseDouble(comMscStdPhy.getStdmax()), phy.getStdmax());

				}

				if (!pass) {
					return false;
				}

			}

		}

		return true;
	}

	
	/**
	 * 过滤公差交货状态
	 * 
	 * @param cust
	 * @param listSpec
	 */
	private void FilterDeliverySpec(ComBaseStdRCust cust, List<ComMscStdSpec> listSpec) {

		for (int i = 0; i < listSpec.size(); i++) {

			if (listSpec.get(i).getDeliveryStateCode() != null
					&& !listSpec.get(i).getDeliveryStateCode().contains(cust.getOrderLine().getDelivery_state_code())) {
				listSpec.remove(listSpec.get(i));
				i--;

			}

		}

	}
	
	
	
	/**
	 * 判断公差项目是否符合客户特殊要求
	 * 
	 * @param specT
	 * @param listSpec
	 * @param cust
	 * @return
	 */
	private boolean judgeSpec(List<SlmCustAlphaSpec> specT, List<ComMscStdSpec> listSpec, ComBaseStdRCust cust) {
		// 判断标准中的元素个数是否与要求的统一

		List<ComMscStdSpecC> lists = this.getMapper(ComMscStdSpecCMapper.class).findWithCondition(null,
				"SIC='" + listSpec.get(0).getSic() + "'", null, 0, 0);

		if (lists.size() < 1) {
			return false;
		}

		HashSet<String> set = new HashSet<String>();
		for (int i = 0; i < lists.size(); i++) {
			set.add(lists.get(i).getBiasCode());

		}
		if (set.size() != specT.size()) {
			return false;
		}

		// 判断项目元素是否匹配

		boolean pass = FilterItemSpecC(set, specT);

		if (!pass) {
			return false;
		}

		// 过滤项目的规格和精度等级
		List<String> tarS = new ArrayList<String>();
		for (int i = 0; i < lists.size(); i++) {
			ComMscStdSpecC specC = FilterSpec(lists.get(i), cust);
			if (specC != null) {
				for (int j = 0; j < specT.size(); j++) {

					if (specC.getBiasCode().equals(specT.get(j).getBias_code())) {
						if (specC.getLvCode().equals(specT.get(j).getLv())) {

							boolean judge = FilterSpecVal(specT.get(j).getStd_min_val(), specC.getStdMinVal());
							if (!judge) {
								return false;
							}
							judge = FilterSpecVal(specT.get(j).getStd_max_val(), specC.getStdMaxVal());
							if (!judge) {
								return false;
							}
							judge = FilterSpecVal(specT.get(j).getStd_min_in(), specC.getStdMinIn());
							if (!judge) {
								return false;
							}
							judge = FilterSpecVal(specT.get(j).getStd_max_in(), specC.getStdMaxIn());
							if (!judge) {
								return false;
							}
							judge = FilterSpecVal(specT.get(j).getStd_min_percent(), specC.getStdMinPercent());

							if (!judge) {
								return false;
							}
							judge = FilterSpecVal(specT.get(j).getStd_max_percent(), specC.getStdMaxPercent());
							if (!judge) {
								return false;
							}

							tarS.add(specC.getBiasCode());

						}

					}

				}

			}

		}
		if (tarS != null && tarS.size() > 0) {
			set.clear();
			set.addAll(tarS);
			if (set != null && set.size() != tarS.size()) {
				return false;
			}

		}

		return true;
	}

	
	public ComMscStdSpecC FilterSpec(ComMscStdSpecC _stdPhy, ComBaseStdRCust cust) {
		ComMscStdSpecC _listSpec = null;
		// 过滤限制规格 厚 400301， 宽 400302， 长 400306

		if (!DataHelper.IsNullOrSpace(_stdPhy.getBiasCodeZ())) {// 为空则适用全部规格
			// 过滤限制规格一
			if (_stdPhy.getBiasCodeZ().equals("400301")) {
				boolean pass;
				if (_stdPhy.getZmax() == null) {
					pass = true;

				} else {
					pass = DataHelper.checkSignAndValue(_stdPhy.getZmaxSign(), Double.parseDouble(_stdPhy.getZmax()),
							cust.getOrderLine().getThick().toString());
				}

				if (!pass) {
					return null;
				}

				if (_stdPhy.getZmin() == null) {
					pass = true;
				} else {
					pass = DataHelper.checkSignAndValue(_stdPhy.getZminSign(), Double.parseDouble(_stdPhy.getZmin()),
							cust.getOrderLine().getThick().toString());
				}

				if (!pass) {
					return null;
				}
			} else if (_stdPhy.getBiasCodeZ().equals("400302")) {
				boolean pass;

				if (_stdPhy.getZmax() == null) {
					pass = true;
				} else {
					pass = DataHelper.checkSignAndValue(_stdPhy.getZmaxSign(), Double.parseDouble(_stdPhy.getZmax()),
							cust.getOrderLine().getWidth().toString());
				}

				if (!pass) {
					return null;
				}

				if (_stdPhy.getZmin() == null) {
					pass = true;
				} else {
					pass = DataHelper.checkSignAndValue(_stdPhy.getZminSign(), Double.parseDouble(_stdPhy.getZmin()),
							cust.getWidth().toString());
				}

				if (!pass) {
					return null;
				}
			} else if (_stdPhy.getBiasCodeZ().equals("400306")) {
				boolean pass;

				if (_stdPhy.getZmin() == null) {
					pass = true;
				} else {
					pass = DataHelper.checkSignAndValue(_stdPhy.getZminSign(), Double.parseDouble(_stdPhy.getZmin()),
							cust.getOrderLine().getLength().toString());
				}

				if (!pass) {
					return null;
				}

				if (_stdPhy.getZmax() == null) {
					pass = true;
				} else {
					pass = DataHelper.checkSignAndValue(_stdPhy.getZmaxSign(), Double.parseDouble(_stdPhy.getZmax()),
							cust.getOrderLine().getLength().toString());
				}

				if (!pass) {
					return null;
				}
			}
			// 验证限制规格二
			if (!DataHelper.IsNullOrSpace(_stdPhy.getBiasCodeC())) {
				if (_stdPhy.getBiasCodeC().equals("400301")) {
					boolean pass;
					if (_stdPhy.getCmin() == null) {
						pass = true;
					} else {
						pass = DataHelper.checkSignAndValue(_stdPhy.getCminSign(),
								Double.parseDouble(_stdPhy.getCmin()), cust.getOrderLine().getThick().toString());
					}

					if (!pass) {
						return null;
					}

					if (_stdPhy.getCmax() == null) {
						pass = true;
					} else {
						pass = DataHelper.checkSignAndValue(_stdPhy.getCmaxSign(),
								Double.parseDouble(_stdPhy.getCmax()), cust.getOrderLine().getThick().toString());
					}

					if (!pass) {
						return null;
					}
				} else if (_stdPhy.getBiasCodeC().equals("400302")) {
					boolean pass;

					if (_stdPhy.getCmin() == null) {
						pass = true;
					} else {
						pass = DataHelper.checkSignAndValue(_stdPhy.getCminSign(),
								Double.parseDouble(_stdPhy.getCmin()), cust.getOrderLine().getWidth().toString());

					}
					if (!pass) {
						return null;
					}
					if (_stdPhy.getCmax() == null) {
						pass = true;
					} else {
						pass = DataHelper.checkSignAndValue(_stdPhy.getCmaxSign(),
								Double.parseDouble(_stdPhy.getCmax()), cust.getWidth().toString());
					}

					if (!pass) {
						return null;
					}
				} else if (_stdPhy.getBiasCodeC().equals("400306")) {
					boolean pass;
					if (_stdPhy.getCmin() == null) {
						pass = true;
					} else {
						pass = DataHelper.checkSignAndValue(_stdPhy.getCminSign(),
								Double.parseDouble(_stdPhy.getCmin()), DataHelper.GetString(cust.getOrderLine().getLength()));
					}

					if (!pass) {
						return null;
					}

					if (_stdPhy.getCmax() == null) {
						pass = true;
					} else {
						pass = DataHelper.checkSignAndValue(_stdPhy.getCmaxSign(),
								Double.parseDouble(_stdPhy.getCmax()), DataHelper.GetString(cust.getOrderLine().getLength()));
					}

					if (!pass) {
						return null;
					}
				}
			}
			// 验证限制规格三
			if (!DataHelper.IsNullOrSpace(_stdPhy.getBiasCodeS())) {
				if (_stdPhy.getBiasCodeS().equals("400301")) {
					boolean pass;
					if (_stdPhy.getSmax() == null) {
						pass = true;
					} else {
						pass = DataHelper.checkSignAndValue(_stdPhy.getSmaxSign(),
								Double.parseDouble(_stdPhy.getSmax()), cust.getOrderLine().getThick().toString());
					}

					if (!pass) {
						return null;
					}

					if (_stdPhy.getSmin() == null) {
						pass = true;
					} else {
						pass = DataHelper.checkSignAndValue(_stdPhy.getSminSign(),
								Double.parseDouble(_stdPhy.getSmin()), cust.getOrderLine().getThick().toString());
					}

					if (!pass) {
						return null;
					}
				} else if (_stdPhy.getBiasCodeS().equals("400302")) {
					boolean pass;
					if (_stdPhy.getSmax() == null) {
						pass = true;
					} else {
						pass = DataHelper.checkSignAndValue(_stdPhy.getSmaxSign(),
								Double.parseDouble(_stdPhy.getSmax()), cust.getOrderLine().getWidth().toString());
					}

					if (!pass) {
						return null;
					}
					if (_stdPhy.getSmin() == null) {
						pass = true;
					} else {
						pass = DataHelper.checkSignAndValue(_stdPhy.getSminSign(),
								Double.parseDouble(_stdPhy.getSmin()), cust.getOrderLine().getWidth().toString());

					}

					if (!pass) {
						return null;
					}
				} else if (_stdPhy.getBiasCodeS().equals("400306")) {
					boolean pass;
					if (_stdPhy.getSmax() == null) {
						pass = true;
					} else {
						pass = DataHelper.checkSignAndValue(_stdPhy.getSmaxSign(),
								Double.parseDouble(_stdPhy.getSmax()),
								DataHelper.GetString(cust.getOrderLine().getLength()));

					}

					if (!pass) {
						return null;
					}
					if (_stdPhy.getSmin() == null) {
						pass = true;
					} else {
						pass = DataHelper.checkSignAndValue(_stdPhy.getSminSign(),
								Double.parseDouble(_stdPhy.getSmin()),
								DataHelper.GetString(cust.getOrderLine().getLength()));

					}

					if (!pass) {
						return null;
					}
				}
			}
		}
		_listSpec = _stdPhy;

		return _listSpec;

	}

	
	/**
	 * 过滤公差项目元素是否存在
	 * 
	 * @param set
	 * @param specT
	 * @return
	 */
	private boolean FilterItemSpecC(HashSet<String> set, List<SlmCustAlphaSpec> specT) {

		for (SlmCustAlphaSpec slmCustAlphaSpec : specT) {
			if (!set.contains(slmCustAlphaSpec.getBias_code())) {
				return false;
			}

		}

		return true;
	}

	
	/**
	 * 过滤材质标准值
	 * 
	 * @param std_min_val
	 * @param stdMinVal
	 * @return
	 */
	private boolean FilterSpecVal(String std_min_val, String stdMinVal) {

		if (std_min_val != null) {
			if (!std_min_val.equals(stdMinVal)) {
				return false;
			}

		} else {

			if (stdMinVal != null) {
				return false;
			}
		}

		return true;
	}
	
	
	
	
}
