/***文档注释***********************************************
 * 作者               :                   易鑫
 * 创建日期      :                   2017.10.24
 * 描述               :        			合同指定产线信息
 * 注意事项      :                   无
 * 遗留BUG :                   无
 * 修改日期      :                   
 * 修改人员      :                   
 * 修改内容      :                   
 ***********************************************************/
package market.Slm.ContractManagement.impl;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import market.Api.Qms.vo.ComMscStdPhy;
import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;
import market.Slm.ContractManagement.mapper.SlmContractLineInfoMapper;
import market.Slm.ContractManagement.mapper.SlmCustAlphaChemMapper;
import market.Slm.ContractManagement.mapper.SlmCustAlphaDetectionMapper;
import market.Slm.ContractManagement.mapper.SlmCustAlphaMapper;
import market.Slm.ContractManagement.mapper.SlmCustAlphaPhyMapper;
import market.Slm.ContractManagement.mapper.SlmCustAlphaSpecMapper;
import market.Slm.ContractManagement.mapper.SlmCustAlphaUseMapper;
import market.Slm.ContractManagement.service.SlmCustAlphaService;
import market.Slm.ContractManagement.vo.SlmContractLineInfo;
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.ContractManagement.vo.SlmCustAlphaUse;
import market.Slm.OrderManagement.impl.SlmOrderInfoServiceImpl;
import market.Slm.OrderManagement.vo.SlmOrderInfo;

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;

@RemoteService(path="SlmCustAlphaService")
public class SlmCustAlphaServiceImpl extends BaseServiceImpl<SlmCustAlpha,Object> implements SlmCustAlphaService {
	/**
	 * 技术要求-保存
	 * 一次性保存4大要求的所有内容，以及生成新alpha码
	 * memo1传客户编号,实现技术要求与alpha码关联，alpha码与客户关联
	 * @throws Exception 
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doAddWeb(CommonPage<SlmCustAlpha> sum) throws Exception{
		ResultModel rm=new ResultModel();
		String userName=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		SlmCustAlpha alpha=sum.getObject();
		String customer_no=sum.getMemo1();
		//重名验证
		SlmCustAlpha check=new SlmCustAlpha();
		check.setCust_alpha_desc(alpha.getCust_alpha_desc());
		if(check.getCust_alpha_desc()!=null&&!"".equals(check.getCust_alpha_desc())){
			int count=this.getMapper(SlmCustAlphaMapper.class).count(check);
			if(count>0){
				rm.setState("500");
				rm.setMsgInfo("该名称已存在");
				return rm;
			}
		}
		//获取序号
		String alphaNo=this.getMapper(SlmCustAlphaMapper.class).doQueryCount(customer_no);
		int count=1;
		if(alphaNo!=null){
			alphaNo=alphaNo.substring(alphaNo.length()-4);
			count=Integer.parseInt(alphaNo)+1;
		}
		String alpha_no=customer_no+new SimpleDateFormat("yyMM").format(new Date())+String.format("%04d", count);
		//成分要求
		List<SlmCustAlphaChem>  chemList=alpha.getChemList();
		if(chemList!=null){
			CommonPage<SlmCustAlphaChem> chemSum=new CommonPage<SlmCustAlphaChem>();
			int chemIndex=1;
			for(SlmCustAlphaChem chems:chemList){
				String index=String.format("%03d", chemIndex);
				chems.setIndex_seq(Integer.parseInt(index));
				chems.setCust_alpha_no(alpha_no);
				chemSum.setObject(chems);
				rm=this.getBean(SlmCustAlphaChemServiceImpl.class).doAddWeb(chemSum);
				if(!"200".equals(rm.getState()))
					throw new Exception(rm.getMsgInfo());
				chemIndex++;
			}
		}
		//探伤要求
		List<SlmCustAlphaDetection>  detectionList=alpha.getDetectionList();
		if(detectionList!=null){
			CommonPage<SlmCustAlphaDetection> detectionSum=new CommonPage<SlmCustAlphaDetection>();
			int deteIndex=1;
			for(SlmCustAlphaDetection detections:detectionList){
				String index=String.format("%03d", deteIndex);
				detections.setXh(Integer.parseInt(index));
				detections.setCust_alpha_no(alpha_no);
				detectionSum.setObject(detections);
				rm=this.getBean(SlmCustAlphaDetectionServiceImpl.class).doAddWeb(detectionSum);
				if(!"200".equals(rm.getState()))
					throw new Exception(rm.getMsgInfo());
				deteIndex++;
			}
		}
		//材质要求
		List<SlmCustAlphaPhy>  phyList=alpha.getPhyList();
		if(phyList!=null){
			int phyIndex=1;
			CommonPage<SlmCustAlphaPhy> phySum=new CommonPage<SlmCustAlphaPhy>();
			for(SlmCustAlphaPhy phys:phyList){
				String index=String.format("%03d", phyIndex);
				phys.setIndex_seq(Integer.parseInt(index));
				phys.setCust_alpha_no(alpha_no);
				phySum.setObject(phys);
				rm=this.getBean(SlmCustAlphaPhyServiceImpl.class).doAddWeb(phySum);
				if(!"200".equals(rm.getState()))
					throw new Exception(rm.getMsgInfo());
				phyIndex++;
			}
		}
		//公差要求
		List<SlmCustAlphaSpec>  specList=alpha.getSpecList();
		if(specList!=null){
			CommonPage<SlmCustAlphaSpec> specSum=new CommonPage<SlmCustAlphaSpec>();
			int specIndex=1;
			for(SlmCustAlphaSpec specs:specList){
				String index=String.format("%03d", specIndex);
				specs.setIndex_seq(Integer.parseInt(index));
				specs.setCust_alpha_no(alpha_no);
				specSum.setObject(specs);
				rm=this.getBean(SlmCustAlphaSpecServiceImpl.class).doAddWeb(specSum);
				if(!"200".equals(rm.getState()))
					throw new Exception(rm.getMsgInfo());
				specIndex++;
			}
		}
		try{
			//生成新alpha码
			alpha.setCust_alpha_no(alpha_no);
			alpha.setCust_alpha_sts("W");		//待评审
			alpha.setValidflag("1");
			alpha.setCreate_name(userName);		
			alpha.setCreate_time(new Date());
			this.getMapper(SlmCustAlphaMapper.class).insert(alpha);

			//客户与alpha码绑定
			SlmCustAlphaUse use=new SlmCustAlphaUse();
			use.setChem_alpha_no(customer_no);
			use.setCust_alpha_no(alpha_no);
			use.setValidflag("1");
			use.setCreate_name(userName);		
			use.setCreate_time(new Date());
			this.getMapper(SlmCustAlphaUseMapper.class).doAdd(use);
			rm.setState("200");
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo(e.getMessage());
			e.printStackTrace();
			//--19-10-15添加异常回滚
			throw new Exception(rm.getMsgInfo());
		}
		return rm;
	}

	/**
	 * 技术要求-选择
	 * memo1合同行号
	 * memo2 传 0合同行 1订单
	 * */
	public ResultModel doSelectWeb(CommonPage<SlmCustAlpha> sum){
		ResultModel rm=new ResultModel();
		String userId=(String) this.getSession().getAttribute(HomeService.SESSION_USER_ID);
		String userName=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		SlmCustAlpha alpha=sum.getObject();
		String line_no=sum.getMemo1();
		String desc="";
		//成分要求
		SlmCustAlphaChem chem=new SlmCustAlphaChem();
		chem.setCust_alpha_no(alpha.getCust_alpha_no());
		List<SlmCustAlphaChem> chemList=this.getMapper(SlmCustAlphaChemMapper.class).find(chem,0,0);
		if(chemList.size()>0){
			desc+="成分要求：";
			int chemSeq=1;
			for(SlmCustAlphaChem chems:chemList){
				String type="A".equals(chems.getChem_type())?"单一元素":"复合元素";
				desc+=chemSeq+".化学元素："+chems.getChem_name()+"，元素类型："+type+"，计算公式："+chems.getChem_formula()
						+"，标准范围下限符号："+chems.getStdmin_sign()+"，标准范围下限值："+chems.getStdmin()
						+"，标准范围上限符号："+chems.getStdmax_sign()+"，标准范围上限值："+chems.getStdmax()
						+"，标准备注："+chems.getStdmemo()+"，是否检出："+(("1".equals(chems.getIscheck()))?"是":"否")
						+"，是否判定："+(("1".equals(chems.getIsjudge()))?"是":"否")+"，是否报出："+(("1".equals(chems.getIsquote()))?"是":"否")
						+"是否是复合标准项："+(("1".equals(chems.getComplex_type()))?"是":"否")+"，备注："+chems.getMemo()+"。\r\n";
				chemSeq++;
			}
		}
		//探伤要求
		SlmCustAlphaDetection detection=new SlmCustAlphaDetection();
		detection.setCust_alpha_no(alpha.getCust_alpha_no());
		List<SlmCustAlphaDetection> detectionList=this.getMapper(SlmCustAlphaDetectionMapper.class).find(detection,0,0);
		if(detectionList.size()>0){
			desc+="探伤要求：";
			int detectionSeq=1;
			for(SlmCustAlphaDetection detections:detectionList){
				desc+=detectionSeq+".材质检验项："+detections.getPhy_name_s()+"，探伤位置："+detections.getPosition_desc()+"，探伤级别："+detections.getLv_desc()
						+"，参考标准："+detections.getStd_desc()+"，探伤覆盖率(%)："+detections.getCoverage()+"，探伤频率："+detections.getDesc_rate()
						+"，频率值："+detections.getDesc_val()+"，最大宽："+detections.getMax_d()+"，最小宽："+detections.getMin_d()
						+"，最大厚："+detections.getMax_h()+"最小厚："+detections.getMin_h()+"，备注："+detections.getMemo()+"。\r\n";
				detectionSeq++;
			}
		}
		//材质要求
		SlmCustAlphaPhy phy=new SlmCustAlphaPhy();
		phy.setCust_alpha_no(alpha.getCust_alpha_no());
		List<SlmCustAlphaPhy> phyList=this.getMapper(SlmCustAlphaPhyMapper.class).find(phy,0,0);
		if(phyList.size()>0){
			desc+="材质要求：";
			int phySeq=1;
			for(SlmCustAlphaPhy phys:phyList){
				desc+=phySeq+".材质检验项名称(大类)："+phys.getPhy_name_l()+"，材质检验项名称(中类)："+phys.getPhy_name_m()
						+"，材质检验项名称(小类)："+phys.getPhy_name_s()+"，试验方向描述："+phys.getItem_name_d()+"，试验温度描述："+phys.getItem_name_t()
						+"，试样尺寸描述："+phys.getItem_name_s()+"，标准范围下限符号："+phys.getStdmin_sign()+"，标准范围下限值："+phys.getStdmin()
						+"，标准范围上限符号："+phys.getStdmax_sign()+"，标准范围上限值："+phys.getStdmax()+"，标准范围下限符号二："+phys.getStdmin_sign2()
						+"，标准范围下限值二："+phys.getStdmin2()+"，标准范围上限符号二："+phys.getStdmax_sign2()+"，标准范围上限值二："+phys.getStdmax2()
						+"，标准备注："+phys.getStdmemo()+"，是否检验："+(("1".equals(phys.getIscheck()))?"是":"否")+"，是否报出："+(("1".equals(phys.getIsquote()))?"是":"否")
						+"，是否判定："+(("1".equals(phys.getIsjudge()))?"是":"否")+"，是否是复合标准项："+(("1".equals(phys.getPhy_type()))?"是":"否")
						+"，交货状态："+phys.getDeliverystate()+"，备注："+phys.getMemo()+"。\r\n";
				phySeq++;
			}
		}
		//公差要求
		SlmCustAlphaSpec spec=new SlmCustAlphaSpec();
		spec.setCust_alpha_no(alpha.getCust_alpha_no());
		List<SlmCustAlphaSpec> specList=this.getMapper(SlmCustAlphaSpecMapper.class).find(spec,0,0);
		if(specList.size()>0){
			desc+="探伤要求：";
			int specSeq=1;
			for(SlmCustAlphaSpec specs:specList){
				desc+=specSeq+".公差项："+specs.getBias_name()+"，标准下偏差值(mm)："+specs.getStd_min_val()+"，标准上偏差值(mm)："+specs.getStd_max_val()
						+"，标准下偏差值(%)："+specs.getStd_min_percent()+"，标准上偏差值(%)："+specs.getStd_max_percent()+"，取小值："+specs.getStd_min_formula_v()
						+"，取大值："+specs.getStd_max_formula_v()+"，标准备注："+specs.getStdmemo()+"，是否必检项："+(("1".equals(specs.getIscheck()))?"是":"否")
						+"，精度等级："+specs.getLv()+"，备注："+specs.getMemo()+"。\r\n";
				specSeq++;
			}
		}
		if("1".equals(sum.getMemo2())){		//订单
			SlmOrderInfo order=this.getBean(SlmOrderInfoServiceImpl.class).doQueryOne(line_no);
			order.setCustomer_alpha_no(alpha.getCust_alpha_no());
			order.setCustomer_alpha_desc(desc);
			order.setUpdate_man_no(userId);
			order.setUpdate_man_name(userName);
			order.setUpdate_time(new Date());
			this.getBean(SlmOrderInfoServiceImpl.class).doUpdate(order);
		}else{	//修改合同行信息
			SlmContractLineInfo line=this.getMapper(SlmContractLineInfoMapper.class).findById(line_no);
			line.setCustomer_alpha_no(alpha.getCust_alpha_no());
			line.setCustomer_alpha_desc(desc);
			line.setUpdate_man_no(userId);
			line.setUpdate_man_name(userName);
			line.setUpdate_time(new Date());
			this.getMapper(SlmContractLineInfoMapper.class).update(line);
		}
		rm.setState("200");
		return rm;
	}

	/**
	 * 点击技术要求模板MSC或alpha
	 * memo1传msc号
	 * */
	public ResultModel doQueryWeb(CommonPage<SlmCustAlpha> sum){
		ResultModel rm=new ResultModel();
		SlmCustAlpha alpha=sum.getObject()!=null?sum.getObject():new SlmCustAlpha();
		List<SlmCustAlphaChem> chemList=new ArrayList<SlmCustAlphaChem>();
		List<SlmCustAlphaDetection> detectionList=new ArrayList<SlmCustAlphaDetection>();
		List<SlmCustAlphaPhy> phyList=new ArrayList<SlmCustAlphaPhy>();
		List<SlmCustAlphaSpec> specList=new ArrayList<SlmCustAlphaSpec>();
		if(sum.getMemo1()!=null&&!"".equals(sum.getMemo1())){
			String msc=sum.getMemo1();
			chemList=this.getMapper(SlmCustAlphaChemMapper.class).doQueryStd(msc);
			detectionList=this.getMapper(SlmCustAlphaDetectionMapper.class).doQueryStd(msc);
			phyList=this.getMapper(SlmCustAlphaPhyMapper.class).doQueryStd(msc);
			specList=this.getMapper(SlmCustAlphaSpecMapper.class).doQueryStd(msc);
		}else if(alpha!=null&&alpha.getCust_alpha_no()!=null&&!"".equals(alpha.getCust_alpha_no())){
			//成分要求
			SlmCustAlphaChem chem=new SlmCustAlphaChem();
			chem.setCust_alpha_no(alpha.getCust_alpha_no());
			chemList=this.getMapper(SlmCustAlphaChemMapper.class).find(chem,0,0);
			//探伤要求
			SlmCustAlphaDetection detection=new SlmCustAlphaDetection();
			detection.setCust_alpha_no(alpha.getCust_alpha_no());
			detectionList=this.getMapper(SlmCustAlphaDetectionMapper.class).find(detection,0,0);
			//材质要求
			SlmCustAlphaPhy phy=new SlmCustAlphaPhy();
			phy.setCust_alpha_no(alpha.getCust_alpha_no());
			phyList=this.getMapper(SlmCustAlphaPhyMapper.class).find(phy,0,0);
			//公差要求
			SlmCustAlphaSpec spec=new SlmCustAlphaSpec();
			spec.setCust_alpha_no(alpha.getCust_alpha_no());
			specList=this.getMapper(SlmCustAlphaSpecMapper.class).find(spec,0,0);
		}

		alpha.setChemList(chemList);
		alpha.setPhyList(phyList);
		alpha.setDetectionList(detectionList);
		alpha.setSpecList(specList);
		rm.setState("200");
		rm.setData(alpha);
		return rm;
	}

	/**
	 * 技术要求-停用
	 * cust_alpha_no
	 * */
	public ResultModel doDeleteWeb(CommonPage<SlmCustAlpha> sum){
		ResultModel rm=new ResultModel();
		SlmCustAlpha alpha=sum.getObject();
		String userName=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		try{
			if(alpha!=null){
				alpha.setValidflag("0");	//无效
				alpha.setDelete_name(userName);
				alpha.setDelete_time(new Date());
				this.getMapper(SlmCustAlphaMapper.class).update(alpha);
			}
			rm.setState("200");
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo("停用失败");
			e.printStackTrace();
		}
		return rm;
	}
	/**
     * 材质要求项新增过滤限制规格
     * @param listphy
     * @param orderLine
     * @return
     */
	public List<SlmCustAlphaPhy> FilterphyAl(List<SlmCustAlphaPhy> listphy,
			Double thick,Double width,Double length){
		List<SlmCustAlphaPhy> _listPhy = new ArrayList<>();
		// 过滤限制规格 厚 400301， 宽 400302， 长 400306
		for(SlmCustAlphaPhy _stdPhy : listphy){
			if(_stdPhy.getSize_code() != null
					&& !_stdPhy.getSize_code().equals("")){//为空则适用全部规格
				// 过滤限制规格一
				// 厚
				if(_stdPhy.getSize_code().equals("400301")){
					boolean pass;
					if (_stdPhy.getSize_max() == null) {
						pass = true;
					} else {
						pass = checkSignAndValue(_stdPhy.getSize_max_sign(),
								Double.parseDouble(_stdPhy.getSize_max()),
								thick);
					}
					if (!pass) {
						continue;
					}

					if (_stdPhy.getSize_min() == null) {
						pass = true;
					} else {
						pass = checkSignAndValue(_stdPhy.getSize_min_sign(),
								Double.parseDouble(_stdPhy.getSize_min()),
								thick);
					}

					if (!pass) {
						continue;
					}
				}else if (_stdPhy.getSize_code().equals("400302")) {

					boolean pass;
					if (_stdPhy.getSize_max() == null) {
						pass = true;
					} else {
						pass = checkSignAndValue(_stdPhy.getSize_max_sign(),
								Double.parseDouble(_stdPhy.getSize_max()),
								width);
					}

					if (!pass) {
						continue;
					}

					if (_stdPhy.getSize_min() == null) {
						pass = true;
					} else {
						pass = checkSignAndValue(_stdPhy.getSize_min_sign(),
								Double.parseDouble(_stdPhy.getSize_min()),
								width);
					}

					if (!pass) {
					    continue;
					}
				}else if (_stdPhy.getSize_code().equals("400306")) {

					boolean pass;
					if (_stdPhy.getSize_max() == null) {
						pass = true;
					} else {
						pass = checkSignAndValue(_stdPhy.getSize_max_sign(),
								Double.parseDouble(_stdPhy.getSize_max()),
								length);
					}

					if (!pass) {
						continue;
					}

					if (_stdPhy.getSize_min() == null) {
						pass = true;
					} else {
						pass = checkSignAndValue(_stdPhy.getSize_min_sign(),
								Double.parseDouble(_stdPhy.getSize_min()),
								length);
					}

					if (!pass) {
						continue;
					}
				}
				// 验证限制规格二
				if (_stdPhy.getSize_code2() != null
						&& !_stdPhy.getSize_code2().equals("")) {
					if (_stdPhy.getSize_code2().equals("400301")) {
						boolean pass;

						if (_stdPhy.getSize_max2() == null) {
							pass = true;
						} else {
							pass = checkSignAndValue(
									_stdPhy.getSize_max_sign2(),
									Double.parseDouble(_stdPhy.getSize_max2()),
									thick);
						}

						if (!pass) {
							continue;
						}

						if (_stdPhy.getSize_min2() == null) {
							pass = true;
						} else {
							pass = checkSignAndValue(
									_stdPhy.getSize_min_sign2(),
									Double.parseDouble(_stdPhy.getSize_min2()),
									thick);
						}

						if (!pass) {
							continue;
						}
					} else if (_stdPhy.getSize_code2().equals("400302")) {
						boolean pass;

						if (_stdPhy.getSize_max2() == null) {
							pass = true;
						} else {
							pass = checkSignAndValue(
									_stdPhy.getSize_max_sign2(),
									Double.parseDouble(_stdPhy.getSize_max2()),
									width);
						}

						if (!pass) {
							continue;
						}

						if (_stdPhy.getSize_min2() == null) {
							pass = true;
						} else {
							pass = checkSignAndValue(
									_stdPhy.getSize_min_sign2(),
									Double.parseDouble(_stdPhy.getSize_min2()),
									width);
						}

						if (!pass) {
							continue;
						}
					} else if (_stdPhy.getSize_code2().equals("400306")) {
						boolean pass;

						if (_stdPhy.getSize_max2() == null) {
							pass = true;
						} else {
							pass = checkSignAndValue(
									_stdPhy.getSize_max_sign2(),
									Double.parseDouble(_stdPhy.getSize_max2()),
									length);
						}

						if (!pass) {
							continue;
						}

						if (pass) {
							pass = true;
						} else {
							pass = checkSignAndValue(
									_stdPhy.getSize_min_sign2(),
									Double.parseDouble(_stdPhy.getSize_min2()),
									length);
						}

						if (!pass) {
							continue;
						}
					}
				}
			}
			_listPhy.add(_stdPhy);
		}
		return _listPhy;
	}

	/**
	 * 新增项过滤限制规格
	 * 
	 * @param listChem
	 * @param orderLine
	 * @return
	 */
	public List<SlmCustAlphaChem> FilterChemAl(List<SlmCustAlphaChem> listChem,
			Double thick,Double width,Double length) {
		List<SlmCustAlphaChem> _listChem = new ArrayList<>();
		// 过滤限制规格 厚 400301， 宽 400302， 长 400306
		for (SlmCustAlphaChem _stdChem : listChem) {
			if (_stdChem.getSize_code() != null
					&& !_stdChem.getSize_code().equals("")) {// 为空则适用全部规格
				// 过滤限制规格一
				// 厚
				if (_stdChem.getSize_code().equals("400301")) {
					boolean pass;
					if (_stdChem.getSize_max() == null) {
						pass = true;
					} else {
						pass = checkSignAndValue(_stdChem.getSize_max_sign(),
								Double.parseDouble(_stdChem.getSize_max()),
								thick);
					}
					if (!pass) {
						continue;
					}

					if (_stdChem.getSize_min() == null) {
						pass = true;
					} else {
						pass = checkSignAndValue(_stdChem.getSize_min_sign(),
								Double.parseDouble(_stdChem.getSize_min()),
								thick);
					}

					if (!pass) {
						continue;
					}
				} else if (_stdChem.getSize_code().equals("400302")) {

					boolean pass;
					if (_stdChem.getSize_max() == null) {
						pass = true;
					} else {
						pass = checkSignAndValue(_stdChem.getSize_max_sign(),
								Double.parseDouble(_stdChem.getSize_max()),
								width);
					}

					if (!pass) {
						continue;
					}

					if (_stdChem.getSize_min() == null) {
						pass = true;
					} else {
						pass = checkSignAndValue(_stdChem.getSize_min_sign(),
								Double.parseDouble(_stdChem.getSize_min()),
								width);
					}

					if (!pass) {
						continue;
					}
				} else if (_stdChem.getSize_code().equals("400306")) {

					boolean pass;
					if (_stdChem.getSize_max() == null) {
						pass = true;
					} else {
						pass = checkSignAndValue(_stdChem.getSize_max_sign(),
								Double.parseDouble(_stdChem.getSize_max()),
								length);
					}

					if (!pass) {
						continue;
					}

					if (_stdChem.getSize_min() == null) {
						pass = true;
					} else {
						pass = checkSignAndValue(_stdChem.getSize_min_sign(),
								Double.parseDouble(_stdChem.getSize_min()),
								length);
					}

					if (!pass) {
						continue;
					}
				}
				// 验证限制规格二
				if (_stdChem.getSize_code2() != null
						&& !_stdChem.getSize_code2().equals("")) {
					if (_stdChem.getSize_code2().equals("400301")) {
						boolean pass;

						if (_stdChem.getSize_max2() == null) {
							pass = true;
						} else {
							pass = checkSignAndValue(
									_stdChem.getSize_max_sign2(),
									Double.parseDouble(_stdChem.getSize_max2()),
									thick);
						}

						if (!pass) {
							continue;
						}

						if (_stdChem.getSize_min2() == null) {
							pass = true;
						} else {
							pass = checkSignAndValue(
									_stdChem.getSize_max_sign2(),
									Double.parseDouble(_stdChem.getSize_min2()),
									thick);
						}

						if (!pass) {
							continue;
						}
					} else if (_stdChem.getSize_code2().equals("400302")) {
						boolean pass;

						if (_stdChem.getSize_max2() == null) {
							pass = true;
						} else {
							pass = checkSignAndValue(
									_stdChem.getSize_max_sign2(),
									Double.parseDouble(_stdChem.getSize_max2()),
									width);
						}

						if (!pass) {
							continue;
						}

						if (_stdChem.getSize_min2() == null) {
							pass = true;
						} else {
							pass = checkSignAndValue(
									_stdChem.getSize_max_sign2(),
									Double.parseDouble(_stdChem.getSize_min2()),
									width);
						}

						if (!pass) {
							continue;
						}
					} else if (_stdChem.getSize_code2().equals("400306")) {
						boolean pass;

						if (_stdChem.getSize_max2() == null) {
							pass = true;
						} else {
							pass = checkSignAndValue(
									_stdChem.getSize_max_sign2(),
									Double.parseDouble(_stdChem.getSize_max2()),
									length);
						}

						if (!pass) {
							continue;
						}

						if (pass) {
							pass = true;
						} else {
							pass = checkSignAndValue(
									_stdChem.getSize_max_sign2(),
									Double.parseDouble(_stdChem.getSize_min2()),
									length);
						}

						if (!pass) {
							continue;
						}
					}
				}
			}
			_listChem.add(_stdChem);
		}
		return _listChem;
	}
	/**
     * 公差要求项新增项过滤限制规格
     * @param listphy
     * @param orderLine
     * @return
     */
	public List<SlmCustAlphaSpec> FilterSpecCAl(List<SlmCustAlphaSpec> listSpecC,
			Double thick,Double width,Double length){
		List<SlmCustAlphaSpec> _listSpecC = new ArrayList<>();
		// 过滤限制规格 厚 400301， 宽 400302， 长 400306
		for(SlmCustAlphaSpec _stdSpecC : listSpecC){
			if(_stdSpecC.getBias_code_z() != null
					&& !_stdSpecC.getBias_code_z().equals("")){//为空则适用全部规格
				// 过滤限制规格一
				// 厚
				if(_stdSpecC.getBias_code_z().equals("400301")){
					boolean pass;
					if (_stdSpecC.getZmax() == null) {
						pass = true;
					} else {
						pass = checkSignAndValue(_stdSpecC.getZmax_sign(),
								Double.parseDouble(_stdSpecC.getZmax()),
								thick);
					}
					if (!pass) {
						continue;
					}

					if (_stdSpecC.getZmin() == null) {
						pass = true;
					} else {
						pass = checkSignAndValue(_stdSpecC.getZmin_sign(),
								Double.parseDouble(_stdSpecC.getZmin()),
								thick);
					}

					if (!pass) {
						continue;
					}
				}else if (_stdSpecC.getBias_code_z().equals("400302")) {

					boolean pass;
					if (_stdSpecC.getZmax() == null) {
						pass = true;
					} else {
						pass = checkSignAndValue(_stdSpecC.getZmax_sign(),
								Double.parseDouble(_stdSpecC.getZmax()),
								width);
					}

					if (!pass) {
						continue;
					}

					if (_stdSpecC.getZmin() == null) {
						pass = true;
					} else {
						pass = checkSignAndValue(_stdSpecC.getZmin_sign(),
								Double.parseDouble(_stdSpecC.getZmin()),
								width);
					}

					if (!pass) {
					    continue;
					}
				}else if (_stdSpecC.getBias_code_z().equals("400306")) {

					boolean pass;
					if (_stdSpecC.getZmax() == null) {
						pass = true;
					} else {
						pass = checkSignAndValue(_stdSpecC.getZmax_sign(),
								Double.parseDouble(_stdSpecC.getZmax()),
								length);
					}

					if (!pass) {
						continue;
					}

					if (_stdSpecC.getZmin() == null) {
						pass = true;
					} else {
						pass = checkSignAndValue(_stdSpecC.getZmin_sign(),
								Double.parseDouble(_stdSpecC.getZmin()),
								length);
					}

					if (!pass) {
						continue;
					}
				}
				// 验证限制规格二
				if (_stdSpecC.getBias_code_c() != null
						&& !_stdSpecC.getBias_code_c().equals("")) {
					if (_stdSpecC.getBias_code_c().equals("400301")) {
						boolean pass;

						if (_stdSpecC.getCmax() == null) {
							pass = true;
						} else {
							pass = checkSignAndValue(
									_stdSpecC.getCmax_sign(),
									Double.parseDouble(_stdSpecC.getCmax()),
									thick);
						}

						if (!pass) {
							continue;
						}

						if (_stdSpecC.getCmin() == null) {
							pass = true;
						} else {
							pass = checkSignAndValue(
									_stdSpecC.getCmin_sign(),
									Double.parseDouble(_stdSpecC.getCmin()),
									thick);
						}

						if (!pass) {
							continue;
						}
					} else if (_stdSpecC.getBias_code_c().equals("400302")) {
						boolean pass;

						if (_stdSpecC.getCmax() == null) {
							pass = true;
						} else {
							pass = checkSignAndValue(
									_stdSpecC.getCmax_sign(),
									Double.parseDouble(_stdSpecC.getCmax()),
									width);
						}

						if (!pass) {
							continue;
						}

						if (_stdSpecC.getCmin() == null) {
							pass = true;
						} else {
							pass = checkSignAndValue(
									_stdSpecC.getCmin_sign(),
									Double.parseDouble(_stdSpecC.getCmin()),
									width);
						}

						if (!pass) {
							continue;
						}
					} else if (_stdSpecC.getBias_code_c().equals("400306")) {
						boolean pass;

						if (_stdSpecC.getCmax() == null) {
							pass = true;
						} else {
							pass = checkSignAndValue(
									_stdSpecC.getCmax_sign(),
									Double.parseDouble(_stdSpecC.getCmax()),
									length);
						}

						if (!pass) {
							continue;
						}

						if (_stdSpecC.getCmin() == null) {
							pass = true;
						} else {
							pass = checkSignAndValue(
									_stdSpecC.getCmin_sign(),
									Double.parseDouble(_stdSpecC.getCmin()),
									length);
						}

						if (!pass) {
							continue;
						}
					}
				}
				// 验证限制规格三
				if (_stdSpecC.getBias_code_s() != null
						&& !_stdSpecC.getBias_code_s().equals("")) {
					if (_stdSpecC.getBias_code_s().equals("400301")) {
						boolean pass;

						if (_stdSpecC.getSmax() == null) {
							pass = true;
						} else {
							pass = checkSignAndValue(
									_stdSpecC.getSmax_sign(),
									Double.parseDouble(_stdSpecC.getSmax()),
									thick);
						}

						if (!pass) {
							continue;
						}

						if (_stdSpecC.getSmin() == null) {
							pass = true;
						} else {
							pass = checkSignAndValue(
									_stdSpecC.getSmin_sign(),
									Double.parseDouble(_stdSpecC.getSmin()),
									thick);
						}

						if (!pass) {
							continue;
						}
					} else if (_stdSpecC.getBias_code_s().equals("400302")) {
						boolean pass;

						if (_stdSpecC.getSmax() == null) {
							pass = true;
						} else {
							pass = checkSignAndValue(
									_stdSpecC.getSmax_sign(),
									Double.parseDouble(_stdSpecC.getSmax()),
									width);
						}

						if (!pass) {
							continue;
						}

						if (_stdSpecC.getSmin() == null) {
							pass = true;
						} else {
							pass = checkSignAndValue(
									_stdSpecC.getSmin_sign(),
									Double.parseDouble(_stdSpecC.getSmin()),
									width);
						}

						if (!pass) {
							continue;
						}
					} else if (_stdSpecC.getBias_code_s().equals("400306")) {
						boolean pass;

						if (_stdSpecC.getSmax() == null) {
							pass = true;
						} else {
							pass = checkSignAndValue(
									_stdSpecC.getSmax_sign(),
									Double.parseDouble(_stdSpecC.getSmax()),
									length);
						}

						if (!pass) {
							continue;
						}

						if (pass) {
							pass = true;
						} else {
							pass = checkSignAndValue(
									_stdSpecC.getSmin_sign(),
									Double.parseDouble(_stdSpecC.getSmin()),
									length);
						}

						if (!pass) {
							continue;
						}
					}
				}
			}
			_listSpecC.add(_stdSpecC);
		}
		return _listSpecC;
	}
	
	/**
     * 探伤要求项过滤限制规格
     * @param listphy
     * @param orderLine
     * @return
     */
	public List<SlmCustAlphaDetection> FilterdetectionAl(List<SlmCustAlphaDetection> listdetection,
			Double thick,Double width,Double length){
		List<SlmCustAlphaDetection> _listDetection = new ArrayList<>();
		// 过滤限制规格 厚 400301， 宽 400302， 长 400306
		for(SlmCustAlphaDetection _stdDetection : listdetection){
			if(_stdDetection.getMax_h() != null
					&& !_stdDetection.getMax_h().equals("")
					&& _stdDetection.getMin_h() != null
					&& !_stdDetection.getMin_h().equals("")){//为空则适用全部规格
				// 过滤限制规格一
				// 厚
				boolean pass;
				if(_stdDetection.getMax_h() == null){
					pass = true;
				}else{
					pass = checkSignAndValue(_stdDetection.getMax_h_sign(),
							Double.parseDouble(_stdDetection.getMax_h()),
							thick);
				}
				if (!pass) {
					continue;
				}

				if (_stdDetection.getMin_h() == null) {
					pass = true;
				} else {
					pass = checkSignAndValue(_stdDetection.getMin_h_sign(),
							Double.parseDouble(_stdDetection.getMin_h()),
							thick);
				}

				if (!pass) {
					continue;
				}
			}
			// 过滤限制规格二
			if(_stdDetection.getMax_d() != null
					&& !_stdDetection.getMax_d().equals("")
					&& _stdDetection.getMin_d() != null
					&& !_stdDetection.getMin_d().equals("")){//为空则适用全部规格
				// 宽
				boolean pass;
				if(_stdDetection.getMax_d() == null){
					pass = true;
				}else{
					pass = checkSignAndValue(_stdDetection.getMax_d_sign(),
							Double.parseDouble(_stdDetection.getMax_d()),
							width);
				}
				if (!pass) {
					continue;
				}

				if (_stdDetection.getMin_d() == null) {
					pass = true;
				} else {
					pass = checkSignAndValue(_stdDetection.getMin_d_sign(),
							Double.parseDouble(_stdDetection.getMin_d()),
							width);
				}

				if (!pass) {
					continue;
				}
			}
			_listDetection.add(_stdDetection);
		}
		return _listDetection;
	}
    /**
     * 材质要求项过滤限制规格
     * @param listphy
     * @param orderLine
     * @return
     */
	public List<ComMscStdPhy> Filterphy(List<ComMscStdPhy> listphy,
			Double thick,Double width,Double length){
		List<ComMscStdPhy> _listPhy = new ArrayList<>();
		// 过滤限制规格 厚 400301， 宽 400302， 长 400306
		for(ComMscStdPhy _stdPhy : listphy){
			if(_stdPhy.getSize_code() != null
					&& !_stdPhy.getSize_code().equals("")){//为空则适用全部规格
				// 过滤限制规格一
				// 厚
				if(_stdPhy.getSize_code().equals("400301")){
					boolean pass;
					if (_stdPhy.getSize_max() == null) {
						pass = true;
					} else {
						pass = checkSignAndValue(_stdPhy.getSize_max_sign(),
								Double.parseDouble(_stdPhy.getSize_max()),
								thick);
					}
					if (!pass) {
						continue;
					}

					if (_stdPhy.getSize_min() == null) {
						pass = true;
					} else {
						pass = checkSignAndValue(_stdPhy.getSize_min_sign(),
								Double.parseDouble(_stdPhy.getSize_min()),
								thick);
					}

					if (!pass) {
						continue;
					}
				}else if (_stdPhy.getSize_code().equals("400302")) {

					boolean pass;
					if (_stdPhy.getSize_max() == null) {
						pass = true;
					} else {
						pass = checkSignAndValue(_stdPhy.getSize_max_sign(),
								Double.parseDouble(_stdPhy.getSize_max()),
								width);
					}

					if (!pass) {
						continue;
					}

					if (_stdPhy.getSize_min() == null) {
						pass = true;
					} else {
						pass = checkSignAndValue(_stdPhy.getSize_min_sign(),
								Double.parseDouble(_stdPhy.getSize_min()),
								width);
					}

					if (!pass) {
					    continue;
					}
				}else if (_stdPhy.getSize_code().equals("400306")) {

					boolean pass;
					if (_stdPhy.getSize_max() == null) {
						pass = true;
					} else {
						pass = checkSignAndValue(_stdPhy.getSize_max_sign(),
								Double.parseDouble(_stdPhy.getSize_max()),
								length);
					}

					if (!pass) {
						continue;
					}

					if (_stdPhy.getSize_min() == null) {
						pass = true;
					} else {
						pass = checkSignAndValue(_stdPhy.getSize_min_sign(),
								Double.parseDouble(_stdPhy.getSize_min()),
								length);
					}

					if (!pass) {
						continue;
					}
				}
				// 验证限制规格二
				if (_stdPhy.getSize_code2() != null
						&& !_stdPhy.getSize_code2().equals("")) {
					if (_stdPhy.getSize_code2().equals("400301")) {
						boolean pass;

						if (_stdPhy.getSize_max2() == null) {
							pass = true;
						} else {
							pass = checkSignAndValue(
									_stdPhy.getSize_max_sign2(),
									Double.parseDouble(_stdPhy.getSize_max2()),
									thick);
						}

						if (!pass) {
							continue;
						}

						if (_stdPhy.getSize_min2() == null) {
							pass = true;
						} else {
							pass = checkSignAndValue(
									_stdPhy.getSize_min_sign2(),
									Double.parseDouble(_stdPhy.getSize_min2()),
									thick);
						}

						if (!pass) {
							continue;
						}
					} else if (_stdPhy.getSize_code2().equals("400302")) {
						boolean pass;

						if (_stdPhy.getSize_max2() == null) {
							pass = true;
						} else {
							pass = checkSignAndValue(
									_stdPhy.getSize_max_sign2(),
									Double.parseDouble(_stdPhy.getSize_max2()),
									width);
						}

						if (!pass) {
							continue;
						}

						if (_stdPhy.getSize_min2() == null) {
							pass = true;
						} else {
							pass = checkSignAndValue(
									_stdPhy.getSize_min_sign2(),
									Double.parseDouble(_stdPhy.getSize_min2()),
									width);
						}

						if (!pass) {
							continue;
						}
					} else if (_stdPhy.getSize_code2().equals("400306")) {
						boolean pass;

						if (_stdPhy.getSize_max2() == null) {
							pass = true;
						} else {
							pass = checkSignAndValue(
									_stdPhy.getSize_max_sign2(),
									Double.parseDouble(_stdPhy.getSize_max2()),
									length);
						}

						if (!pass) {
							continue;
						}

						if (pass) {
							pass = true;
						} else {
							pass = checkSignAndValue(
									_stdPhy.getSize_min_sign2(),
									Double.parseDouble(_stdPhy.getSize_min2()),
									length);
						}

						if (!pass) {
							continue;
						}
					}
				}
			}
			_listPhy.add(_stdPhy);
		}
		return _listPhy;
	}
	/**
	 * 检查是否符合标准
	 * 
	 * @param sign
	 *            符号
	 * @param signValue
	 *            标准值
	 * @param value
	 *            对比值
	 * @return
	 */
	public static boolean checkSignAndValue(String sign, Double signValue,
			Double value) {
		if (value == null) {
			return true;
		}
		if (sign == null) {
			return true;
		}
		switch (sign) {
		case ">":
			return signValue.doubleValue() < value;
		case ">=":
			return signValue.doubleValue() <= value;
		case "<":
			return signValue.doubleValue() > value;
		case "<=":
			return signValue.doubleValue() >= value;
		case "=":
			return signValue.doubleValue() == value;
		default:
			return true;
		}
	}
}
