/***文档注释***********************************************
 * 作者            ：
 * 创建日期     ：2018-04-08
 * 描述            ：材质判定记录表
 * 注意事项     ：
 * 遗留BUG   ：
 * 修改日期     ：
 * 修改人员     ：
 * 修改内容     ：
 ***********************************************************/
package market.Qms.qcm.service.impl;

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

import market.Api.Lms.impl.LmsQmsApiServiceImpl;
import market.Api.Mes.impl.Judge_Prc_Info;
import market.Api.Mes.impl.MesApiDesignInfoImpl;
import market.Api.Mes.service.MesApiDesignInfoService;
import market.Com.mapper.ComBaseInfoMapper;
import market.Com.mapper.ComBaseSteelMapper;
import market.Com.mapper.ComPscMapper;
import market.Com.vo.ComBaseCbYdd;
import market.Com.vo.ComBaseInfo;
import market.Com.vo.ComBaseSteel;
import market.Com.vo.ComPsc;
import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;
import market.Lms.Warehouse.mapper.YdmProductDetailMapper;
import market.Lms.Warehouse.service.YdmProductInlistService;
import market.Lms.Warehouse.vo.YdmProductDetail;
import market.Mes.Lengthwise.Plan.impl.PlnMaterielDetailServiceImpl;
import market.Mes.Lengthwise.Plan.service.PlnMaterielDetailService;
import market.Mes.Lengthwise.Plan.vo.PlnMaterielDetail;
import market.Mes.Opr.mapper.MesOprLogMapper;
import market.Mes.Opr.vo.MesOprLog;
import market.Mes.Tpm.mapper.PlnSkinrollingPlanMapper;
import market.Qms.com.service.impl.ComBaseConfigServiceImpl;
import market.Qms.common.DataHelper;
import market.Qms.qcm.mapper.ComBaseDeliverystateRPhyMapper;
import market.Qms.qcm.mapper.QcmJhyPhyresultMapper;
import market.Qms.qcm.mapper.QcmJhySampleConsignDItemMapper;
import market.Qms.qcm.mapper.QcmJhySampleConsignDMapper;
import market.Qms.qcm.mapper.QcmJhySampleConsignMMapper;
import market.Qms.qcm.mapper.QcmJhySampleROrdMapper;
import market.Qms.qcm.mapper.QcmJudgeChemicalMapper;
import market.Qms.qcm.mapper.QcmJudgeMeasureMapper;
import market.Qms.qcm.mapper.QcmJudgePhysicalMapper;
import market.Qms.qcm.mapper.QcmJudgePhysicalUtmDMapper;
import market.Qms.qcm.mapper.QcmJudgePhysicalUtmMMapper;
import market.Qms.qcm.mapper.QcmJudgeSurfaceMapper;
import market.Qms.qcm.mapper.QcmJudgeUltimateMapper;
import market.Qms.qcm.mapper.QcmPhyJudgeResultMapper;
import market.Qms.qcm.mapper.QcmPhyResultMapper;
import market.Qms.qcm.service.QcmJudgePhysicalService;
import market.Qms.qcm.vo.ComBaseDeliverystateRPhy;
import market.Qms.qcm.vo.QcmJhyPhyresult;
import market.Qms.qcm.vo.QcmJhySampleConsignD;
import market.Qms.qcm.vo.QcmJhySampleConsignDItem;
import market.Qms.qcm.vo.QcmJhySampleConsignM;
import market.Qms.qcm.vo.QcmJhySampleROrd;
import market.Qms.qcm.vo.QcmJudgeChemical;
import market.Qms.qcm.vo.QcmJudgeMeasure;
import market.Qms.qcm.vo.QcmJudgePhysical;
import market.Qms.qcm.vo.QcmJudgePhysicalTemp;
import market.Qms.qcm.vo.QcmJudgePhysicalUtmD;
import market.Qms.qcm.vo.QcmJudgePhysicalUtmM;
import market.Qms.qcm.vo.QcmJudgeSurface;
import market.Qms.qcm.vo.QcmJudgeUltimate;
import market.Qms.qcm.vo.QcmPhyJudgeResult;
import market.Qms.qcm.vo.QcmPhyResult;
import market.Qms.slmord.mapper.QcmJudgeBlockadeInfoMapper;
import market.Qms.slmord.mapper.SlmOrdDesignMscMapper;
import market.Qms.slmord.mapper.SlmOrdDesignMscPlPrcMapper;
import market.Qms.slmord.mapper.SlmOrdDesignMscPlStiMapper;
import market.Qms.slmord.mapper.SlmOrdDesignStdMapper;
import market.Qms.slmord.mapper.SlmOrdDesignStdPicMapper;
import market.Qms.slmord.vo.QcmJudgeBlockadeInfo;
import market.Qms.slmord.vo.SlmOrdDesignMsc;
import market.Qms.slmord.vo.SlmOrdDesignMscPlPrc;
import market.Qms.slmord.vo.SlmOrdDesignMscPlSti;
import market.Qms.slmord.vo.SlmOrdDesignStd;
import market.Qms.slmord.vo.SlmOrdDesignStdPic;
import market.Slm.FundManagement.service.SlmFundFirstDetailService;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

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

@Service("QcmJudgePhysicalService")
@RemoteService(path = "QcmJudgePhysicalService")
public class QcmJudgePhysicalServiceImpl extends BaseServiceImpl<QcmJudgePhysical, Object> implements QcmJudgePhysicalService {
	
	/**
	 * 质量判定-材质判定管理-获取材质判定记录信息
	 * sum.smp_no 试样号
	 * sum.heat_no 炉号
	 * sum.inspection_lot 检验号
	 * */
	public ResultModel doQueryQcmJudgePhysical(CommonPage<QcmJudgePhysical> sum) {
		ResultModel rm = new ResultModel();
		QcmJudgePhysical qj=sum.getObject();
		try {
			if(qj==null){
				rm.setMsgInfo("请传入参数！");
				rm.setState("500");
				return rm;
			}
			PageModel<QcmJudgePhysical> pm=new PageModel<QcmJudgePhysical>(sum.getPageIndex(),sum.getPageSize());
			String Str="";
			if(qj.getHeat_no()!=null&&!qj.getHeat_no().equals("")){
				Str+=" and t.heat_no like '%"+qj.getHeat_no()+"%'";
			}
			if(qj.getInspection_lot()!=null&&!qj.getInspection_lot().equals("")){
				Str+=" and t.inspection_lot like '%"+qj.getInspection_lot()+"%'";
			}
			if(!DataHelper.IsNullOrSpace(qj.getBatch_no())){
				Str+=" and t.batch_no like '%"+qj.getBatch_no()+"%'";
			}
			if(qj.getPhy_result_desc()!=null&&!qj.getPhy_result_desc().equals("")){
				Str+=" and t.phy_result_desc ='"+qj.getPhy_result_desc()+"'";
			}
			//投料卷号
			if(qj.getObject_no()!=null && !"".equals(qj.getObject_no())){
				Str+=" and pmr.object_no like '%"+qj.getObject_no()+"%'";
			}
			//原料卷号
			if(qj.getMaterailcoilno()!=null && !"".equals(qj.getMaterailcoilno())){
				Str+=" and ypd.materailcoilno like '%"+qj.getMaterailcoilno()+"%'";
			}
			List<QcmJudgePhysical> list = this.getMapper(QcmJudgePhysicalMapper.class).doQueryQcmJudgePhysical(Str,(pm.getPageNumber()-1)*pm.getPageSize(), pm.getPageNumber()*pm.getPageSize());
			pm.setRows(list);
			int count = this.getMapper(QcmJudgePhysicalMapper.class).doQueryQcmJudgePhysicalCount(Str);
			pm.setTotal(count);
			rm.setData(pm);
			rm.setState("200");
		} catch (Exception e) {
			rm.setMsgInfo("材质判定记录信息获取失败!"+e.getMessage());
			rm.setState("500");
		}
		return rm;
	}
	/**
	 * 质量判定-材质判定管理-获取判定结果
	 * sum.smp_no 试样号
	 * sum.design_key design_key
	 * sum.psc 产品码
	 * sum.contract_line_no  销售订单号PK码
	 * sum.phy_id 材质结果集
	 * */
	public ResultModel findSampleItem(CommonPage<QcmJudgePhysical> sum){
		ResultModel rm=new ResultModel();
		try {
			QcmJudgePhysical qd=sum.getObject();
			if(qd==null||"".equals(qd.getSmp_no())){
				rm.setState("500");
				rm.setMsgInfo("请传入参数！");
				return rm;
			}
			List<QcmJhySampleConsignDItem> qsds=new ArrayList<>();
			List<QcmPhyResult> qprt=this.getMapper(QcmPhyResultMapper.class).findWithCondition(null, "PHY_ID ='"+qd.getPhy_id()+"'", null, 0, 0);
			for(QcmPhyResult qpr:qprt){
				QcmJhySampleConsignDItem qsd=new QcmJhySampleConsignDItem();
//				材质检验项
				qsd.setPhy_code_l(qpr.getPhy_code_l());
				qsd.setPhy_code_m(qpr.getPhy_code_m());
				qsd.setPhy_code_s(qpr.getPhy_code_s());
				qsd.setPhy_name_l(qpr.getPhy_name_l());
				qsd.setPhy_name_m(qpr.getPhy_name_m());
				qsd.setPhy_name_s(qpr.getPhy_name_s());
				qsd.setItem_code_d(qpr.getItem_code_d());
				qsd.setItem_code_s(qpr.getItem_code_s());
				qsd.setItem_code_t(qpr.getItem_code_t());
				qsd.setItem_name_d(qpr.getItem_name_d());
				qsd.setItem_name_s(qpr.getItem_name_s());
				qsd.setItem_name_t(qpr.getItem_name_t());
				//
//				交付标准
				String pic="";
				List<SlmOrdDesignStd> sordlist=this.getMapper(SlmOrdDesignStdMapper.class).findWithCondition(null, "Design_key='"+qd.getDesign_key()+"' and Psc='"+qd.getPsc()+"'", null, 0, 0);
				if(sordlist!=null&&sordlist.size()>0){
					pic=sordlist.get(0).getPic();
					SlmOrdDesignStdPic ss=new SlmOrdDesignStdPic();
					List<SlmOrdDesignStdPic> sslist=this.getMapper(SlmOrdDesignStdPicMapper.class)
							.findWithCondition(null, "PIC='"+pic
									+"' and DESIGN_KEY='"+qd.getDesign_key()
									+"' and PHY_CODE_S='"+qsd.getPhy_code_s()+"'", null, 0, 1);
					if(sslist!=null&&sslist.size()>0){
						ss=sslist.get(0);
					}
					qsd.setJf_stdmax_sign(ss.getStdmax_sign());
					qsd.setJf_stdmax(ss.getStdmax());
					qsd.setJf_stdmin_sign(ss.getStdmin_sign());
					qsd.setJf_stdmin(ss.getStdmin());
				}
				
//				客户标准
				String picK="";
				List<SlmOrdDesignStd> ssplist=this.getMapper(SlmOrdDesignStdMapper.class)
						.findWithCondition(null, "DESIGN_KEY='"+qd.getDesign_key()+"' and PSC='"+qd.getPsc()+"'",null, 0, 0);
				if(ssplist!=null&&ssplist.size()>0){
					picK=ssplist.get(0).getPic_k();
					SlmOrdDesignStdPic ss2=new SlmOrdDesignStdPic();
					List<SlmOrdDesignStdPic> sslist=this.getMapper(SlmOrdDesignStdPicMapper.class)
							.findWithCondition(null, "PIC='"+picK
									+"' and DESIGN_KEY='"+qd.getDesign_key()
									+"' and PHY_CODE_S='"+qsd.getPhy_code_s()+
									"'", null, 0, 0);
					if(sslist!=null&&sslist.size()>0){
						ss2=sslist.get(0);
					}
					qsd.setKh_stdmax_sign(ss2.getStdmax_sign());
					qsd.setKh_stdmax(ss2.getStdmax());
					qsd.setKh_stdmin_sign(ss2.getStdmin_sign());
					qsd.setKh_stdmin(ss2.getStdmin());		
				}
				
//				内控标准
//				//验证内控是否存在引用
				String IS_STDPIC="0";
				String PIC="";
				List<SlmOrdDesignMscPlPrc> prclist=this.getMapper(SlmOrdDesignMscPlPrcMapper.class)
						.findWithCondition(null, "Design_key='"+qd.getDesign_key()+"'", null, 0, 0);
				if(prclist!=null&&prclist.size()>0){
					PIC=prclist.get(0).getPic();
					for(SlmOrdDesignMscPlPrc prc:prclist){
						if(prc.getIs_stdpic().equals("1")){
							IS_STDPIC="1";
							break;
						}
					}			
				}
				if(IS_STDPIC.equals("1")){
//						则弹出原型所示提示信息
					qsd.setIs_stdpic("1");
				}
				else{
					qsd.setIs_stdpic("0");
//					验证内控标准索引号是否为空
					if(PIC!=null&&!PIC.equals("")){
						SlmOrdDesignStdPic ss3=new SlmOrdDesignStdPic();
						List<SlmOrdDesignStdPic> sslist=this.getMapper(SlmOrdDesignStdPicMapper.class)
								.findWithCondition(null, "PIC='"+PIC
										+"' and DESIGN_KEY='"+qd.getDesign_key()
										+"' and PHY_CODE_S='"+qsd.getPhy_code_s()+"'", null, 0, 1);
						if(sslist!=null&&sslist.size()>0){
							ss3=sslist.get(0);
						}
						qsd.setNk_stdmax_sign(ss3.getStdmax_sign());
						qsd.setNk_stdmax(ss3.getStdmax());
						qsd.setNk_stdmin_sign(ss3.getStdmin_sign());
						qsd.setNk_stdmin(ss3.getStdmin());
					}
					else{
//						验证检验项是否存在修正值
						String delivery_state_code="";
						List<SlmOrdDesignMsc> smlist=this.getMapper(SlmOrdDesignMscMapper.class)
								.findWithCondition(null, "CONTRACT_LINE_NO='"+qd.getContract_line_no()
										+"' and VALIDFLAG='1'", null, 0, 0);
						if(smlist!=null&&smlist.size()>0){
							delivery_state_code=smlist.get(0).getDelivery_state_code();
						}
						List<ComBaseDeliverystateRPhy> cr=this.getMapper(ComBaseDeliverystateRPhyMapper.class).
								findWithCondition(null, "PHY_CODE_S='"+qsd.getPhy_code_s()+"' and DELIVERY_STATE_CODE='"+delivery_state_code+"'", null, 0, 0);
						if(cr!=null&&cr.size()>=1){
							ComBaseDeliverystateRPhy crr=cr.get(0);
							qsd.setStdmin_update(crr.getStdmin_update());
							qsd.setStdmax_update(crr.getStdmax_update());
//							取值逻辑：如果交付、客户标准同时存在，则拿客户标准与修正值进行计算，否则，取交付标准进行计算；
							if((pic!=null&&!pic.equals(""))&&(picK!=null&&!picK.equals(""))){
								qsd.setNk_stdmax_sign(qsd.getKh_stdmax_sign());
								qsd.setNk_stdmin_sign(qsd.getKh_stdmin_sign());
								qsd.setNk_stdmax((Long.parseLong(qsd.getKh_stdmax())-qsd.getStdmax_update())+"");
								qsd.setNk_stdmin((Long.parseLong(qsd.getKh_stdmin())+qsd.getStdmin_update())+"");
							}else{
								qsd.setNk_stdmax_sign(qsd.getJf_stdmax_sign());
								qsd.setNk_stdmin_sign(qsd.getJf_stdmin_sign());
								qsd.setNk_stdmax((Long.parseLong(qsd.getJf_stdmax())-qsd.getStdmax_update())+"");
								qsd.setNk_stdmin((Long.parseLong(qsd.getJf_stdmin())+qsd.getStdmin_update())+"");
							}
						}
					}
				}
//				修正值
				String delivery_state_code="";
				List<SlmOrdDesignMsc> smlist=this.getMapper(SlmOrdDesignMscMapper.class)
						.findWithCondition(null, "CONTRACT_LINE_NO='"+qd.getContract_line_no()
								+"' and VALIDFLAG='1'", null, 0, 0);
				if(smlist!=null&&smlist.size()>0){
					delivery_state_code=smlist.get(0).getDelivery_state_code();
				}
				List<ComBaseDeliverystateRPhy> cr=this.getMapper(ComBaseDeliverystateRPhyMapper.class).
						findWithCondition(null, "PHY_CODE_S='"+qsd.getPhy_code_s()+"' and DELIVERY_STATE_CODE='"+delivery_state_code+"'", null, 0, 0);
				if(cr!=null&&cr.size()>=1){
					qsd.setIs_std("1");
					ComBaseDeliverystateRPhy crr=cr.get(0);
					qsd.setStdmin_update(crr.getStdmin_update());
					qsd.setStdmax_update(crr.getStdmax_update());
				}
				else{
					qsd.setIs_std("0");
				}
				qsds.add(qsd);
			}
			rm.setData(qsds);
			rm.setState("200");
		} catch (Exception e) {
			rm.setMsgInfo("查询出错！"+e.getMessage());
			rm.setState("500");
			e.printStackTrace();
		}
		return rm;
	}

	/**
	 * 质量判定-材质判定管理-人工干预判定
	 * List<QcmJhySampleConsignDItem>
	 * */
	@Transactional(value = "tm", rollbackFor = Exception.class)
	public ResultModel judgeByHuman(CommonPage<QcmJudgePhysicalTemp> sum)
			throws Exception{
				ResultModel rm=new ResultModel();
				try {
					String username = (String)this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
					List<QcmJudgePhysicalTemp> qptlist=sum.getObjectList();
					if(qptlist==null||qptlist.size()==0){
						rm.setState("200");
						rm.setMsgInfo("请传入参数！");
						return rm;
					}
					List<QcmJhySampleConsignD> listd = this.getMapper(QcmJhySampleConsignDMapper.class).findWithCondition(null, "smp_no='"+qptlist.get(0).getSmp_no()+"'", null, 0, 0);
					for (QcmJhySampleConsignD d : listd) {
						if (!d.getStatus().equals("3")) {
							rm.setState("403");
							rm.setMsgInfo("此试样号对应的取样编号"+d.getSpecimen_no()+"不是已完成状态，无法进行判定");
							return rm;
						}
					}
					String connect="";
					if (qptlist.get(0).getOrder_no()!=null&&!"".equals(qptlist.get(0).getOrder_no())) {
						connect+="and ORDERNO ='"+qptlist.get(0).getOrder_no()+"'";
					}
					if (qptlist.get(0).getInspection_lot()!=null&&!"".equals(qptlist.get(0).getInspection_lot())) {
						connect+="and INSPECTION_LOT ='"+qptlist.get(0).getInspection_lot()+"'";
					}
					//单项检验不判断锁定标识
//					List<YdmProductDetail> listqju=this.getMapper(YdmProductDetailMapper.class).findWithCondition(null, connect, null, 0,0);
//					Boolean flag = false;
//					for (YdmProductDetail ypd : listqju) {
//				    	if ("1".equals(ypd.getCic_is_lock()) || "1".equals(ypd.getSic_is_lock()) || "1".equals(ypd.getDic_is_lock()) || "1".equals(ypd.getSfu_is_lock()) || "1".equals(ypd.getSfd_is_lock()) || "1".equals(ypd.getSfe_is_lock())) {
//							flag=true;
//							break;
//						}
//				    }
//				    if (flag) {
//						rm.setState("403");
//						rm.setMsgInfo("试样号"+qptlist.get(0).getSmp_no()+"对应的检验号和订单号向下存在被锁定的物料，请先解锁后再进行操作");
//						return rm;
//					}
					QcmJudgePhysicalTemp qpt1=qptlist.get(0);
					System.out.println(qpt1.getPic_result_code());
//					验证综合判定结果是否存在
//					QcmJudgeUltimate qu=new QcmJudgeUltimate();
//					qu.setContract_line_no(qpt1.getContract_line_no());
//					List<QcmJudgeUltimate> qulist=this.getMapper(QcmJudgeUltimateMapper.class).find(qu, 0, 0);
//					for(QcmJudgeUltimate quu:qulist){
//						if(quu.getUtm_result_code()!=null&&!quu.getUtm_result_code().equals("")){
//							rm.setState("500");
//							rm.setMsgInfo("存在综合判定结果！");
//							return rm;
//						}
//					}
                    for (QcmJudgePhysicalTemp q : qptlist) {
                    	CommonPage<YdmProductDetail> cp=new CommonPage<>();
                    	YdmProductDetail ydm=new YdmProductDetail();
                    	ydm.setOrderno(q.getOrder_no());
                    	cp.setMemo1(q.getOrder_no());
						ResultModel va = this.getBean(LmsQmsApiServiceImpl.class).doJudgeIsPhysresult(cp);
					     String str=va.getState();
						if ("500".equals(str)) {
							rm.setState("403");
							rm.setMsgInfo(va.getMsgInfo());
							return rm;
						}
                    }
//					材质结果集编号
					int count=0;
					SimpleDateFormat sdf=new SimpleDateFormat("yyMMdd");
					String date=sdf.format(new Date());
//					获取材质结果集编号最大值
					List<QcmPhyJudgeResult> qrlist=this.getMapper(QcmPhyJudgeResultMapper.class)
							.findWithCondition(null, "PHY_ID like 'PHY"+date+"%'", "PHY_ID DESC", 0, 1);
					if(qrlist!=null&&qrlist.size()>0){
						String s=qrlist.get(0).getPhy_id();
						count=Integer.parseInt(s.substring(s.length()-4, s.length()));
					}
					count++;
					String phy_id="PHY"+sdf.format(new Date())+String.format("%04d",count);
					for(QcmJudgePhysicalTemp qpt:qptlist){
//						插入QCM_PHY_RESULT表
						QcmPhyJudgeResult qpr=new QcmPhyJudgeResult();
						qpr.setPhy_id(phy_id);
						qpr.setGuid(java.util.UUID.randomUUID().toString().replace("-", ""));
						qpr.setSmp_no(qpt.getSmp_no());
						qpr.setContract_line_no(qpt.getContract_line_no());
						qpr.setHeat_no(qpt.getHeat_no());
						qpr.setBatch_no(qpt.getBatch_no());
						qpr.setInspection_lot(qpt.getInspection_lot());
//						if (qpt.getMaterial_no()!=null&&!qpt.getMaterial_no().equals("")) {
//							qpr.setMaterial_no(qpt.getMaterial_no());
//						}else {
//							qpr.setMaterial_no("NULL");
//						}
						List<QcmJhySampleConsignD> listcd = this.getMapper(QcmJhySampleConsignDMapper.class).findWithCondition(null, "smp_no='"+qpt.getSmp_no()+"' and material_no is not null", null, 0, 0);
						if (listcd!=null&&listcd.size()>0) {
							qpr.setMaterial_no(listcd.get(0).getMaterial_no());
						}
						qpr.setPhy_code_l(qpt.getPhy_code_l());
						qpr.setPhy_code_m(qpt.getPhy_code_m());
						qpr.setPhy_code_s(qpt.getPhy_code_s());
						qpr.setPhy_name_l(qpt.getPhy_name_l());
						qpr.setPhy_name_m(qpt.getPhy_name_m());
						qpr.setPhy_name_s(qpt.getPhy_name_s());
						qpr.setItem_code_d(qpt.getItem_code_d());
						qpr.setItem_code_s(qpt.getItem_code_s());
						qpr.setItem_code_t(qpt.getItem_code_t());
						qpr.setItem_name_d(qpt.getItem_name_d());
						qpr.setItem_name_s(qpt.getItem_name_s());
						qpr.setItem_name_t(qpt.getItem_name_t());
						qpr.setVal1(qpt.getVal1());
						qpr.setVal2(qpt.getVal2());
						qpr.setVal3(qpt.getVal3());
						qpr.setCreate_name(username);
						qpr.setCreate_time(new Date());
						this.getMapper(QcmPhyJudgeResultMapper.class).insert(qpr);
					}
//					插入QCM_JUDGE_PHYSICAL表
					QcmJudgePhysical qp=new QcmJudgePhysical();
					QcmJudgePhysicalTemp qptt=qptlist.get(0);
					qp.setSmp_no(qptt.getSmp_no());
					qp.setOrder_no(qptt.getOrder_no());
					qp.setHeat_no(qptt.getHeat_no());
					qp.setBatch_no(qptt.getBatch_no());
					qp.setInspection_lot(qptt.getInspection_lot());
					qp.setDesign_key(qptt.getDesign_key());
					qp.setPsc(qptt.getPsc());
//					qp.setBoard_no(qptt.getBoard_no());
					qp.setPhy_id(phy_id);
					if (qptt.getPline_code()!=null&&!qptt.getPline_code().equals("")) {
						qp.setPline_code(qptt.getPline_code());
					}else {
						qp.setPline_code("NULL");
					}
					qp.setPline_name(qptt.getPline_name());
					qp.setContract_line_no(qptt.getContract_line_no());
					qp.setPhy_result_code(qptt.getPic_result_code());
					qp.setPhy_result_desc(qptt.getPic_result_desc());
					qp.setJudge_ttime(new Date());
					qp.setPhy_memo(qptt.getPic_memo());
					if (!DataHelper.IsNullOrSpace(username)) {
						qp.setJudge_name(username);
					}else {
						qp.setJudge_name("SYSTEM");
					}
					qp.setCert_inst_code(qptt.getCert_inst_code());
					qp.setCert_inst_name(qptt.getCert_inst_name());
					qp.setSmp_type_code(qptt.getSmp_type_code());
					qp.setSmp_type_name(qptt.getSmp_type_name());
					this.getMapper(QcmJudgePhysicalMapper.class).insert(qp);
					
					//异常材料处置，进行物料封锁
					// 不合格时，直接进行异常材料处置业务
					if ("40740202".equals(qp.getPhy_result_code())) {
						MaterialAbnormalTreatment(qp,qptlist.get(0).getLists());
					}
					// 判废时，根据代码配置决定是否发起异常材料处置业务
//					if ("40740202".equals(qp.getPic_result_code())) {
//						ArrayList<String> listconfig_id = new ArrayList<>();
//						listconfig_id.add("QCM0005  ");
//						List<ComBaseConfig> listcbc =(List<ComBaseConfig>) this.getBean(ComBaseConfigServiceImpl.class).getBaseConfigInfo(listconfig_id).getData();
//						if ("1".equals(listcbc.get(0).getConfig_val())) {
//							MaterialAbnormalTreatment(qp);
//						} else {
//							// 判废业务
//						}
//					}
					
					//将数据插入材质最终判定结果表QCM_JUDGE_PHYSICAL_UTM_m
					QcmJudgePhysicalUtmM qpu=new QcmJudgePhysicalUtmM();
					QcmJudgePhysicalUtmD qpd=new QcmJudgePhysicalUtmD();
					String pic_id1="";
//					 for (QcmJudgePhysicalTemp q:qptlist) {
//						//获取当日最大编号
//							int cou=0;
//							SimpleDateFormat sd=new SimpleDateFormat("yyMMdd");
//							String da=sd.format(new Date());
////							获取材质结果集编号最大值
//							List<QcmJudgePhysicalUtmM> qrlis=this.getMapper(QcmJudgePhysicalUtmMMapper.class)
//									.findWithCondition(null, "PIC_ID like 'P%"+da+"%'", "PIC_ID DESC", 0, 1);
//							if(qrlis!=null&&qrlis.size()>0){
//								String s=qrlis.get(0).getPic_id();
//								cou=Integer.parseInt(s.substring(s.length()-4, s.length()));
//							}
//							cou++;
//							String pic="PIC"+sdf.format(new Date())+String.format("%04d",cou);
//							qpu.setPic_id(pic);
//							qpu.setPic_result_desc(q.getPic_result_code());
//							qpu.setPic_result_code(q.getPic_result_desc());
//							qpu.setInspection_lot(q.getInspection_lot());
//							qpu.setDesign_key(q.getDesign_key());
//							qpu.setContract_line_no(q.getContract_line_no());
//							List<QcmJudgePhysicalUtmM> listcon = this.getMapper(QcmJudgePhysicalUtmMMapper.class).findWithCondition(null, "CONTRACT_LINE_NO='"+q.getContract_line_no()+"'", null, 0, 0);
//							if (listcon.size()==0) {
//								this.getMapper(QcmJudgePhysicalUtmMMapper.class).insert(qpu);
//							}
							//把结果插入qcm_judge_Physical_Utm_d
//							int count1=0;
//							SimpleDateFormat sdf1=new SimpleDateFormat("yyMMdd");
//							String date1=sdf1.format(new Date());
////							获取材质结果集编号最大值
//							List<QcmJudgePhysicalUtmD> qrlist1=this.getMapper(QcmJudgePhysicalUtmDMapper.class)
//									.findWithCondition(null, "PIC_ID like 'P%"+date1+"%'", "PIC_ID DESC", 0, 1);
//							if(qrlist1!=null&&qrlist1.size()>0){
//								String s=qrlist1.get(0).getPic_id();
//								count1=Integer.parseInt(s.substring(s.length()-4, s.length()));
//							}
//							count1++;
//							 pic_id1="PIC"+sdf1.format(new Date())+String.format("%04d",count1);
//							qpd.setPic_id(pic_id1);
//							if (DataHelper.IsNullOrSpace(q.getSmp_no())) {
//								 qpd.setSmp_no("NULL");
//							}else {
//								qpd.setSmp_no(q.getSmp_no());
//							}
//						    qpd.setHeat_no(q.getHeat_no());
//							qpd.setBatch_no(q.getBatch_no());
//							qpd.setInspection_lot(q.getInspection_lot());
//							qpd.setDesign_key(q.getDesign_key());
//							qpd.setPsc(q.getPsc());
//							qpd.setCert_inst_code(q.getCert_inst_code());
//							qpd.setCert_inst_name(q.getCert_inst_name());
//							qpd.setSmp_type_code(q.getSmp_type_code());
//							qpd.setSmp_type_name(q.getSmp_type_name());
//							qpd.setJudge_result_code(q.getPic_result_code());
//							qpd.setJudge_result_desc(q.getPic_result_desc());
//							qpd.setPic_memo(q.getPic_memo());
//							if (!DataHelper.IsNullOrSpace(q.getPic_result_code())) {
//								qpd.setPic_result_code(q.getPic_result_code());
//							}else {
//								qpd.setPic_result_code("NULL");
//							}
//							qpd.setPic_result_desc(q.getPic_result_desc());
//							qpd.setPhy_id(q.getPhy_id());
//							qpd.setJudge_ttime(new Date());
//							qpd.setJudge_name("system");
//							this.getMapper(QcmJudgePhysicalUtmDMapper.class).insert(qpd);
//					}
					//把判定结果更新到试样号与合同信息关系表
					qpt1.setJudge_name(username);
					qpt1.setJudge_ttime(new Date());
//					qpt1.setDesign_key(qptlist.get(0).getDesign_key());
					this.getMapper(QcmJhySampleROrdMapper.class).updateQcmSample(qpt1);
					//再一次查询材质判定试样信息
//					QcmJhySampleROrd qsr=new QcmJhySampleROrd();
//					this.getMapper(QcmJhySampleROrdMapper.class).getSampleInformation(qsr);
					//判断订单向下所有试样号都已经判定完成
					List<String> str=new ArrayList<>();
					List<QcmJhySampleROrd> listor = this.getMapper(QcmJhySampleROrdMapper.class).findInfo(qptt.getDesign_key(), "B",qptt.getInspection_lot());
					  for (QcmJhySampleROrd l : listor) {
						if (!DataHelper.IsNullOrSpace(l.getJudge_result_desc())) {
							str.add(l.getJudge_result_desc());
						}else {
							str.add("null");
						}
					}
				if (!str.contains("null")) {
					YdmProductDetail pme=new YdmProductDetail();
					int cou=0;
					SimpleDateFormat sd=new SimpleDateFormat("yyMMdd");
					String da=sd.format(new Date());
//					获取材质结果集编号最大值
					List<QcmJudgePhysicalUtmM> qrlis=this.getMapper(QcmJudgePhysicalUtmMMapper.class)
							.findWithCondition(null, "PIC_ID like 'P%"+da+"%'", "PIC_ID DESC", 0, 1);
					if(qrlis!=null&&qrlis.size()>0){
						String s=qrlis.get(0).getPic_id();
						cou=Integer.parseInt(s.substring(s.length()-4, s.length()));
					}
					cou++;
					String pic="PIC"+sdf.format(new Date())+String.format("%04d",cou);
					qpu.setPic_id(pic);
					System.out.println(str.contains("不合格"));
					if (str.contains("不合格")) {
						qpu.setPic_result_desc("不合格");
						qpu.setPic_result_code("40740202");
						pme.setPhysresult("40740202");
						pme.setPhysresult_id(pic);
//						pme.setPic_result_desc("不合格");
					}else {
						qpu.setPic_result_desc("合格");
						qpu.setPic_result_code("40740201");
						pme.setPhysresult("40740201");
						pme.setPhysresult_id(pic);
//						pme.setPic_result_desc("合格");
					}
					qpu.setInspection_lot(qptt.getInspection_lot());
					qpu.setDesign_key(qptt.getDesign_key());
					qpu.setContract_line_no(qptt.getContract_line_no());
//					List<QcmJudgePhysicalUtmM> listcon = this.getMapper(QcmJudgePhysicalUtmMMapper.class).findWithCondition(null, "CONTRACT_LINE_NO='"+qptt.getOrder_no()+"'", null, 0, 0);
//					if (listcon.size()==0) {
						this.getMapper(QcmJudgePhysicalUtmMMapper.class).insert(qpu);
//					}
						
						for (QcmJhySampleROrd q:listor) {
								qpd.setPic_id(pic);
								if (DataHelper.IsNullOrSpace(q.getSmp_no())) {
									 qpd.setSmp_no("NULL");
								}else {
									qpd.setSmp_no(q.getSmp_no());
								}
							    qpd.setHeat_no(q.getHeat_no());
								qpd.setBatch_no(q.getBatch_no());
								qpd.setInspection_lot(q.getInspection_lot());
								qpd.setDesign_key(q.getDesign_key());
								qpd.setPsc(q.getPsc());
								qpd.setCert_inst_code(q.getCert_inst_code());
								qpd.setCert_inst_name(q.getCert_inst_name());
								qpd.setSmp_type_code(q.getSmp_type_code());
								qpd.setSmp_type_name(q.getSmp_type_name());
								qpd.setJudge_result_code(q.getJudge_result_code());
								qpd.setJudge_result_desc(q.getJudge_result_desc());
								qpd.setPhy_id(q.getPhy_id());
								qpd.setJudge_ttime(new Date());
								qpd.setJudge_name("system");
								
								this.getMapper(QcmJudgePhysicalUtmDMapper.class).insert(qpd);
								//更新库存表psc
								List<YdmProductDetail> yptList = new ArrayList<>();
								yptList = this.getMapper(YdmProductDetailMapper.class).findWithCondition(null, "ORDERNO = '" + q.getOrder_no() + "' and INSPECTION_LOT ='" + q.getInspection_lot() + "'", null, 0, 0);
								for (YdmProductDetail ypt: yptList) {
									YdmProductDetail ydm = new YdmProductDetail();
									ydm.setCoilno(ypt.getCoilno());
									ydm.setPsc(qptt.getPsc());
									this.getMapper(YdmProductDetailMapper.class).update(ydm);
								}
								//把判定结果更新到物料进程表中
								pme.setPhysresult_id(pic);
								this.getMapper(YdmProductDetailMapper.class).doUpdateByOrderno(q.getOrder_no(), pme.getPhysresult(), pme.getPhysresult_id(), q.getInspection_lot());
						}
//					   String st="";
//						if ("40740202".equals(pme.getPhysresult())||"40740203".equals(pme.getPhysresult())) {
//							this.getBean(QcmJhyPhyresultServiceImpl.class).MaterialAbnormalTreatment(listor.get(0), qptlist.get(0).getLists(), "40740202", "不合格", qptlist.get(0).getPic_memo());
//					   upInitialInspectionResult(qptt.getMaterial_no(), qptt.getDesign_key(), qptt.getPsc());
//					  }
				}   
					rm.setState("200");
				}catch (Exception e) {
					e.printStackTrace();
					throw new Exception();
				}
				return rm;}

	/**
	 * 材质异常材料处置	2019.1.7	
	 */
	public void MaterialAbnormalTreatment(QcmJudgePhysical qjp,String memo){
		try {
			//更新材料异常处理表
			 QcmJudgeBlockadeInfo qjb=new QcmJudgeBlockadeInfo();
			 //生成质量封锁记录号
			 //调用计划模块接口获取订单和检验号下面所有的子板信息
//			 ResultModel rm = this.getBean(MesApiServiceImpl.class).getPlateInfoByOrderInspection(qjsr.getOrder_no(), qjsr.getInspection_lot());
//			 List<PrcMaterielExtinfo> listp = (List<PrcMaterielExtinfo>) rm.getData();
			 List<YdmProductDetail> ydmList=this.getMapper(YdmProductDetailMapper.class).findWithCondition(null, "ORDERNO = '"+qjp.getOrder_no()+"' and INSPECTION_LOT = '"+qjp.getInspection_lot()+"'", null, 0, 0);
			 for (YdmProductDetail ydm : ydmList) {
			 int count=0;
				SimpleDateFormat sdf=new SimpleDateFormat("yyMMdd");
				String date=sdf.format(new Date());
				 List<QcmJudgeBlockadeInfo> listqcbk = this.getMapper(QcmJudgeBlockadeInfoMapper.class).findWithCondition(null, "BIC like '%"+date+"%'", "BIC desc", 0, 0);
				if(listqcbk!=null&&listqcbk.size()>0){
					String s=listqcbk.get(0).getBic();
					count=Integer.parseInt(s.substring(s.length()-4, s.length()));
				}
				count++;
				String bic=sdf.format(new Date())+String.format("%04d",count);
				qjb.setBic(bic);
//				String memo="";
//				if (lists!=null&&lists.size()>0) {
//					for (String str : lists) {
//						memo=memo+str+",";
//					}
//				}
				if (!DataHelper.IsNullOrSpace(memo)&&",".equals(memo.substring(memo.length()-1,memo.length()))) {
					qjb.setBic_memo(memo);
				}else {
					qjb.setBic_memo(memo.substring(0, memo.length()-1));
				}
				// 原产品信息
				ComPsc psc = this.getMapper(ComPscMapper.class).findById(qjp.getPsc());
				// 交货状态
				SlmOrdDesignMsc sod = this.getMapper(SlmOrdDesignMscMapper.class).findById(qjp.getDesign_key());
				qjb.setBic_type("P");
				qjb.setHeat_no(qjp.getHeat_no());
				qjb.setBatch_no(qjp.getBatch_no());
				qjb.setBoard_no(qjp.getBoard_no());
				qjb.setInspection_lot(qjp.getInspection_lot());
				qjb.setMaterial_no(ydm.getCoilno());
				qjb.setObject_no_pseudo(ydm.getObject_no_vt());
				qjb.setContract_line_no(qjp.getOrder_no());
				qjb.setPsc(qjp.getPsc());
//		    	qjb.setProd_code(qjs.getProd_code());
//		    	qjb.setProd_name(qjs.getProd_name());
//		    	qjb.setStd_code(qjs.getStd_code());
//		    	qjb.setStd_name(qjs.getStd_name());
//		    	qjb.setSteel_code(qjs.getSteel_code());
//		    	qjb.setSteel_name(qjs.getSteel_name());
		    	qjb.setCreate_time(new Date());
		    	qjb.setCreate_name((String) this.getSession().getAttribute(
						HomeService.SESSION_USER_NAME));
		    	qjb.setPline_code(qjp.getPline_code());
		    	qjb.setPline_name(qjp.getPline_name());
		    	if (ydm.getWidth()!=null&&!(ydm.getWidth()).equals("")) {
		    		qjb.setWidth(ydm.getWidth());	
				}
		    	if (ydm.getThick()!=null&&!(ydm.getThick()).equals("")) {
		    		qjb.setThick(ydm.getThick());
				}
		    	if (ydm.getLength()!=null&&!(ydm.getLength()).equals("")) {
		    		qjb.setLength(ydm.getLength());	
				}
			//更新物料进程表标识
		    	qjb.setOld_prod_code(psc.getProd_code());
				qjb.setOld_prod_name(psc.getProd_name());
				qjb.setOld_psc(psc.getPsc());
//				qjb.setHt_code(ydm.getHt_code());
				qjb.setOld_std_code(psc.getStd_code());
				qjb.setOld_std_name(psc.getStd_name());
				qjb.setOld_steel_code(psc.getSteel_code());
				qjb.setOld_steel_name(psc.getSteel_name());
		    	qjb.setDelivery_state_code(sod.getDelivery_state_code());
		    	qjb.setDelivery_state_desc(sod.getDelivery_state_desc());
				this.getMapper(QcmJudgeBlockadeInfoMapper.class).insert(qjb);
				YdmProductDetail ypd=new YdmProductDetail();
				ypd.setCoilno(ydm.getCoilno());
				ypd.setPic_is_lock("1");
				this.getMapper(YdmProductDetailMapper.class).update(ypd);
			 }
		} catch (Exception e) {
			System.out.println(e.getMessage());
			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
		}
	}
	/**
	 * 质量判定-材质判定管理-自动判定
	 * */
	@Transactional(value = "tm", rollbackFor = Exception.class)
	public ResultModel judgeByComputer()
	throws Exception{
		ResultModel rm=new ResultModel();
		try {
//			前置条件
//			1、材质试样信息列表中试样号对应判定状态为待判（QCM_JHY_SAMPLE_R_ORD.JUDGE_STATUS='0')
//			2、试样号向下委托明细状态为已完成（QCM_JHY_SAMPLE_CONSIGN_D.STATUS='3'）
//			获取所有试样号
			List<QcmJhySampleConsignM> qmlist=this.getMapper(QcmJhySampleConsignMMapper.class).find(null, 0, 0);
//			循环所有试样号
			for(QcmJhySampleConsignM qm:qmlist){
				String syh=qm.getSmp_no();
//				标识-试样号对应所有判定状态为待判
				int flagJ=0;
//				获取试样号对应合同关系表信息
				List<QcmJhySampleROrd> qordlist=this.getMapper(QcmJhySampleROrdMapper.class).findWithCondition(null, "SMP_NO='"+syh+"'", null, 0, 0);
				for(QcmJhySampleROrd qord:qordlist){
					if(!qord.getJudge_status().equals("0")){
						flagJ++;
						break;
					}
				}
//				标识-试样号向下所有委托明细状态为已完成
				int flagS=0;
//				获取试样号对应委托明细表信息
				List<QcmJhySampleConsignD> qdlist=this.getMapper(QcmJhySampleConsignDMapper.class).findWithCondition(null, "SMP_NO='"+syh+"'", null, 0, 0);
				for(QcmJhySampleConsignD qd:qdlist){
					if(!qd.getStatus().equals("3")){
						flagS++;
						break;
					}
				}
//				满足条件自动判定
				if(flagJ==0&&flagS==0){
					List<QcmJhySampleConsignDItem> qjsd=new ArrayList<>();
//					试样号对应的所有材质检验项目	
					for(QcmJhySampleConsignD qd:qdlist){
						List<QcmJhySampleConsignDItem> q=this.getMapper(QcmJhySampleConsignDItemMapper.class)
								.findWithCondition(null, "SPECIMEN_NO='"+qd.getSpecimen_no()+"'", null, 0, 0);
						for(QcmJhySampleConsignDItem qdii:q){
							qjsd.add(qdii);
						}
					}
					
//					获取试样号向下检验项目及对应检验实绩、判定标准，修正值
				for(QcmJhySampleROrd qd:qordlist){
					//在这个层级插入QCM_JUDGE_PHYSICAL表
					
//					材质结果集编号
					int count=0;
					SimpleDateFormat sdf=new SimpleDateFormat("yyMMdd");
					String date=sdf.format(new Date());
//					获取材质结果集编号最大值
					List<QcmPhyResult> qrlist=this.getMapper(QcmPhyResultMapper.class)
							.findWithCondition(null, "PHY_ID like 'PIC"+date+"%'", "PHY_ID DESC", 0, 1);
					if(qrlist!=null&&qrlist.size()>0){
						String s=qrlist.get(0).getPhy_id();
						count=Integer.parseInt(s.substring(s.length()-4, s.length()));
					}
					count++;
					String phy_id="PIC"+sdf.format(new Date())+String.format("%04d",count);
					
					boolean test=true;
//					判定标准与修正值
					for(QcmJhySampleConsignDItem qsd:qjsd){
//						在这个层级插入QCM_PHY_RESULT表
//						检验实绩
						List<String> phylist=new ArrayList<>();
//						交付标准
						String pic="";
						List<SlmOrdDesignStd> sordlist=this.getMapper(SlmOrdDesignStdMapper.class).findWithCondition(null, "Design_key='"+qd.getDesign_key()+"' and Psc='"+qd.getPsc()+"'", null, 0, 0);
						if(sordlist!=null&&sordlist.size()>0){
							pic=sordlist.get(0).getPic();
							SlmOrdDesignStdPic ss=new SlmOrdDesignStdPic();
							List<SlmOrdDesignStdPic> sslist=this.getMapper(SlmOrdDesignStdPicMapper.class)
									.findWithCondition(null, "PIC='"+pic
											+"' and DESIGN_KEY='"+qd.getDesign_key()
											+"' and PHY_CODE_S='"+qsd.getPhy_code_s()+"'", null, 0, 1);
							if(sslist!=null&&sslist.size()>0){
								ss=sslist.get(0);
							}
							qsd.setJf_stdmax_sign(ss.getStdmax_sign());
							qsd.setJf_stdmax(ss.getStdmax());
							qsd.setJf_stdmin_sign(ss.getStdmin_sign());
							qsd.setJf_stdmin(ss.getStdmin());
						}
						
//						客户标准
						String picK="";
						List<SlmOrdDesignStd> ssplist=this.getMapper(SlmOrdDesignStdMapper.class)
								.findWithCondition(null, "DESIGN_KEY='"+qd.getDesign_key()+"' and PSC='"+qd.getPsc()+"'",null, 0, 0);
						if(ssplist!=null&&ssplist.size()>0){
							picK=ssplist.get(0).getPic_k();
							SlmOrdDesignStdPic ss2=new SlmOrdDesignStdPic();
							List<SlmOrdDesignStdPic> sslist=this.getMapper(SlmOrdDesignStdPicMapper.class)
									.findWithCondition(null, "PIC='"+picK
											+"' and DESIGN_KEY='"+qd.getDesign_key()
											+"' and PHY_CODE_S='"+qsd.getPhy_code_s()+
											"'", null, 0, 0);
							if(sslist!=null&&sslist.size()>0){
								ss2=sslist.get(0);
							}
							qsd.setKh_stdmax_sign(ss2.getStdmax_sign());
							qsd.setKh_stdmax(ss2.getStdmax());
							qsd.setKh_stdmin_sign(ss2.getStdmin_sign());
							qsd.setKh_stdmin(ss2.getStdmin());		
						}
						
//						内控标准
//						//验证内控是否存在引用
						String IS_STDPIC="0";
						String PIC="";
						List<SlmOrdDesignMscPlPrc> prclist=this.getMapper(SlmOrdDesignMscPlPrcMapper.class)
								.findWithCondition(null, "Design_key='"+qd.getDesign_key()+"'", null, 0, 0);
						if(prclist!=null&&prclist.size()>0){
							PIC=prclist.get(0).getPic();
							for(SlmOrdDesignMscPlPrc prc:prclist){
								if(prc.getIs_stdpic().equals("1")){
									IS_STDPIC="1";
									break;
								}
							}			
						}
						if(IS_STDPIC.equals("1")){
//								则弹出原型所示提示信息
							qsd.setIs_stdpic("1");
						}
						else{
							qsd.setIs_stdpic("0");
//							验证内控标准索引号是否为空
							if(PIC!=null&&!PIC.equals("")){
								SlmOrdDesignStdPic ss3=new SlmOrdDesignStdPic();
								List<SlmOrdDesignStdPic> sslist=this.getMapper(SlmOrdDesignStdPicMapper.class)
										.findWithCondition(null, "PIC='"+PIC
												+"' and DESIGN_KEY='"+qd.getDesign_key()
												+"' and PHY_CODE_S='"+qsd.getPhy_code_s()+"'", null, 0, 1);
								if(sslist!=null&&sslist.size()>0){
									ss3=sslist.get(0);
								}
								qsd.setNk_stdmax_sign(ss3.getStdmax_sign());
								qsd.setNk_stdmax(ss3.getStdmax());
								qsd.setNk_stdmin_sign(ss3.getStdmin_sign());
								qsd.setNk_stdmin(ss3.getStdmin());
							}
							else{
//								验证检验项是否存在修正值
								String delivery_state_code="";
								List<SlmOrdDesignMsc> smlist=this.getMapper(SlmOrdDesignMscMapper.class)
										.findWithCondition(null, "CONTRACT_LINE_NO='"+qd.getContract_line_no()
												+"' and VALIDFLAG='1'", null, 0, 0);
								if(smlist!=null&&smlist.size()>0){
									delivery_state_code=smlist.get(0).getDelivery_state_code();
								}
								List<ComBaseDeliverystateRPhy> cr=this.getMapper(ComBaseDeliverystateRPhyMapper.class).
										findWithCondition(null, "PHY_CODE_S='"+qsd.getPhy_code_s()+"' and DELIVERY_STATE_CODE='"+delivery_state_code+"'", null, 0, 0);
								if(cr!=null&&cr.size()>=1){
									ComBaseDeliverystateRPhy crr=cr.get(0);
									qsd.setStdmin_update(crr.getStdmin_update());
									qsd.setStdmax_update(crr.getStdmax_update());
//									取值逻辑：如果交付、客户标准同时存在，则拿客户标准与修正值进行计算，否则，取交付标准进行计算；
									if((pic!=null&&!pic.equals(""))&&(picK!=null&&!picK.equals(""))){
										qsd.setNk_stdmax_sign(qsd.getKh_stdmax_sign());
										qsd.setNk_stdmin_sign(qsd.getKh_stdmin_sign());
										qsd.setNk_stdmax((Long.parseLong(qsd.getKh_stdmax())-qsd.getStdmax_update())+"");
										qsd.setNk_stdmin((Long.parseLong(qsd.getKh_stdmin())+qsd.getStdmin_update())+"");
									}else{
										qsd.setNk_stdmax_sign(qsd.getJf_stdmax_sign());
										qsd.setNk_stdmin_sign(qsd.getJf_stdmin_sign());
										qsd.setNk_stdmax((Long.parseLong(qsd.getJf_stdmax())-qsd.getStdmax_update())+"");
										qsd.setNk_stdmin((Long.parseLong(qsd.getJf_stdmin())+qsd.getStdmin_update())+"");
									}
								}
							}
						}
//						修正值
						String delivery_state_code="";
						List<SlmOrdDesignMsc> smlist=this.getMapper(SlmOrdDesignMscMapper.class)
								.findWithCondition(null, "CONTRACT_LINE_NO='"+qd.getContract_line_no()
										+"' and VALIDFLAG='1'", null, 0, 0);
						if(smlist!=null&&smlist.size()>0){
							delivery_state_code=smlist.get(0).getDelivery_state_code();
						}
						List<ComBaseDeliverystateRPhy> cr=this.getMapper(ComBaseDeliverystateRPhyMapper.class).
								findWithCondition(null, "PHY_CODE_S='"+qsd.getPhy_code_s()+"' and DELIVERY_STATE_CODE='"+delivery_state_code+"'", null, 0, 0);
						if(cr!=null&&cr.size()>=1){
							qsd.setIs_std("1");
							ComBaseDeliverystateRPhy crr=cr.get(0);
							qsd.setStdmin_update(crr.getStdmin_update());
							qsd.setStdmax_update(crr.getStdmax_update());
						}
						else{
							qsd.setIs_std("0");
						}
						
						
						boolean istrue_jfmax=true,istrue_jfmin=true,istrue_khmax=true,istrue_khmin=true,istrue_nkmax=true,istrue_nkmin=true;
						//是否必判
						if(qsd.getIsjudge().equals("1")){
//							判定：一个实绩值的任意一个标准不通过即为不合格									
							for(String phy:phylist){
//								交付标准下限
								if(qsd.getJf_stdmin()!=null&&!qsd.getJf_stdmin().equals("")){
									if(!judgeVal(phy, qsd.getJf_stdmin(), qsd.getJf_stdmin_sign())){
										istrue_jfmin=false;
									}
								}
//								交付标准上限
								if(qsd.getJf_stdmax()!=null&&!qsd.getJf_stdmax().equals("")){
									if(!judgeVal(phy, qsd.getJf_stdmax(), qsd.getJf_stdmax())){
										istrue_jfmax=false;
									}
								}
//								客户标准下限
								if(qsd.getKh_stdmin()!=null&&!qsd.getKh_stdmin().equals("")){
									if(!judgeVal(phy, qsd.getKh_stdmin(), qsd.getKh_stdmin())){
										istrue_khmin=false;
									}
								}
//								客户标准上限
								if(qsd.getKh_stdmax()!=null&&!qsd.getKh_stdmax().equals("")){
									if(!judgeVal(phy, qsd.getKh_stdmax(), qsd.getKh_stdmax())){
										istrue_khmax=false;
									}
								}
//								内控标准下限
								if(qsd.getNk_stdmin()!=null&&!qsd.getNk_stdmin().equals("")){
									if(!judgeVal(phy, qsd.getNk_stdmin(), qsd.getNk_stdmin())){
										istrue_nkmin=false;
									}
								}
//								内控标准上限
								if(qsd.getNk_stdmax()!=null&&!qsd.getNk_stdmax().equals("")){
									if(!judgeVal(phy, qsd.getNk_stdmax(), qsd.getNk_stdmax())){
										istrue_nkmax=false;
									}
								}
							}
						}
//						一个必判项目不合格则不合格
						if(!(istrue_jfmax&&istrue_jfmin&&istrue_khmax&&istrue_khmin&&istrue_nkmax&&istrue_nkmin)){
							test=false;
						}
//						插入QCM_PHY_RESULT
						QcmPhyResult qpr=new QcmPhyResult();
						qpr.setBatch_no(qd.getBatch_no());
						qpr.setContract_line_no(qd.getContract_line_no());
						qpr.setCreate_name("SYSTEM");
						qpr.setCreate_time(new Date());
						qpr.setGuid(java.util.UUID.randomUUID().toString().replace("-", ""));
						qpr.setHeat_no(qd.getHeat_no());
						qpr.setInspection_lot(qd.getInspection_lot());
						qpr.setItem_code_d(qsd.getItem_code_d());
						qpr.setItem_code_s(qsd.getItem_code_s());
						qpr.setItem_code_t(qsd.getItem_code_t());
						qpr.setItem_name_d(qsd.getItem_name_d());
						qpr.setItem_name_s(qsd.getItem_name_s());
						qpr.setItem_name_t(qsd.getItem_name_t());
						qpr.setMaterial_no(qm.getMaterial_no());
						qpr.setPhy_code_l(qsd.getPhy_code_l());
						qpr.setPhy_code_m(qsd.getPhy_code_m());
						qpr.setPhy_code_s(qsd.getPhy_code_s());
						qpr.setPhy_id(phy_id);
						qpr.setPhy_name_l(qsd.getPhy_name_l());
						qpr.setPhy_name_m(qsd.getPhy_name_m());
						qpr.setPhy_name_s(qsd.getPhy_name_s());
						qpr.setSmp_no(qd.getSmp_no());
						//插入检验实测值
//						qpr.setVal1("");
						//...
						this.getMapper(QcmPhyResultMapper.class).insert(qpr);
					}
//					判定合格
					if(test){
						qd.setJudge_status("1");
						qd.setJudge_result_code("40740201");
						qd.setJudge_result_desc("合格");
					}
//					不合格
					else{
						qd.setJudge_status("1");
						qd.setJudge_result_code("40740203");
						qd.setJudge_result_desc("待处理");
					}
					
//					插入QCM_JUDGE_PHYSICAL
					QcmJudgePhysical qps=new QcmJudgePhysical();
					qps.setBatch_no(qd.getBatch_no());
					qps.setContract_line_no(qd.getContract_line_no());
					qps.setDesign_key(qd.getDesign_key());
					qps.setHeat_no(qd.getHeat_no());
					qps.setInspection_lot(qd.getInspection_lot());
					qps.setJudge_name("SYSTEM");
					qps.setPhy_result_code(qd.getJudge_result_code());
					qps.setPhy_result_desc(qd.getJudge_result_desc());
					qps.setJudge_ttime(new Date());
					qps.setPhy_memo("系统自动判定");
					qps.setPhy_id(phy_id);
//					qps.setPic_id(pic_id);
					qps.setPline_code(qm.getPline_code());
					qps.setPline_name(qm.getPline_name());
					qps.setPsc(qd.getPsc());
					qps.setSmp_no(qd.getSmp_no());
					this.getMapper(QcmJudgePhysicalMapper.class).insert(qps);
					
//					获取材质结果集ID及材质判定记录号通过试样号更新试样号与合同信息关系表（QCM_JHY_SAMPLE_R_ORD.PHY_ID、PIC_ID）
					qd.setPhy_id(phy_id);
//					qd.setPic_id(pic_id);
					this.getMapper(QcmJhySampleROrdMapper.class).update(qd);
				}
				}
			}
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("自动判定失败！");
		}
		return rm;
	}
	/**
	 * Val 实绩值
	 * val 标准值
	 * valsign 标准值符号
	 * */
	public boolean judgeVal(String Val,String val, String valsign) {
		double A=Double.parseDouble(Val);
		double B=Double.parseDouble(val);
		if(valsign.equals(">")){
			if(A>B){
				return true;
			}
			else{
				return false;
			}
		}
		if(valsign.equals(">=")){
			if(A>=B){
				return true;
			}
			else{
				return false;
			}
		}
		if(valsign.equals("<")){
			if(A<B){
				return true;
			}
			else{
				return false;
			}
		}
		if(valsign.equals("<=")){
			if(A<=B){
				return true;
			}
			else{
				return false;
			}
		}
		return true;
	}
	/**
	 * 质量判定-材质判定管理-自动判定测试
	 * */
	@Transactional(value = "tm", rollbackFor = Exception.class)
	public ResultModel judgeByComputer2()
	throws Exception{
		ResultModel rm=new ResultModel();
		try {
//			前置条件
//			1、材质试样信息列表中试样号对应判定状态为待判（QCM_JHY_SAMPLE_R_ORD.JUDGE_STATUS='0')
//			2、试样号向下委托明细状态为已完成（QCM_JHY_SAMPLE_CONSIGN_D.STATUS='3'）
//			获取所有试样号
			List<QcmJhySampleConsignM> qmlist=this.getMapper(QcmJhySampleConsignMMapper.class).find(null, 0, 0);
//			循环所有试样号
			for(QcmJhySampleConsignM qm:qmlist){
				String syh=qm.getSmp_no();
//				标识-试样号对应所有判定状态为待判
				int flagJ=0;
//				获取试样号对应合同关系表信息
				List<QcmJhySampleROrd> qordlist=this.getMapper(QcmJhySampleROrdMapper.class).findWithCondition(null, "SMP_NO='"+syh+"'", null, 0, 0);
				for(QcmJhySampleROrd qord:qordlist){
					if(!qord.getJudge_status().equals("0")){
						flagJ++;
						break;
					}
				}
//				标识-试样号向下所有委托明细状态为已完成
				int flagS=0;
//				获取试样号对应委托明细表信息
				List<QcmJhySampleConsignD> qdlist=this.getMapper(QcmJhySampleConsignDMapper.class).findWithCondition(null, "SMP_NO='"+syh+"'", null, 0, 0);
				for(QcmJhySampleConsignD qd:qdlist){
					if(!qd.getStatus().equals("3")){
						flagS++;
						break;
					}
				}
//				满足条件自动判定
				if(flagJ==0&&flagS==0){
					List<QcmJhySampleConsignDItem> qjsd=new ArrayList<>();
//					试样号对应的所有材质检验项目	
					for(QcmJhySampleConsignD qd:qdlist){
						List<QcmJhySampleConsignDItem> q=this.getMapper(QcmJhySampleConsignDItemMapper.class)
								.findWithCondition(null, "SPECIMEN_NO='"+qd.getSpecimen_no()+"'", null, 0, 0);
						for(QcmJhySampleConsignDItem qdii:q){
							qjsd.add(qdii);
						}
					}
					
//					获取试样号向下检验项目及对应检验实绩、判定标准，修正值
				for(QcmJhySampleROrd qd:qordlist){
					//在这个层级插入QCM_JUDGE_PHYSICAL表
					
//					材质结果集编号
					int count=0;
					SimpleDateFormat sdf=new SimpleDateFormat("yyMMdd");
					String date=sdf.format(new Date());
//					获取材质结果集编号最大值
					List<QcmPhyResult> qrlist=this.getMapper(QcmPhyResultMapper.class)
							.findWithCondition(null, "PHY_ID like 'PIC"+date+"%'", "PHY_ID DESC", 0, 1);
					if(qrlist!=null&&qrlist.size()>0){
						String s=qrlist.get(0).getPhy_id();
						count=Integer.parseInt(s.substring(s.length()-4, s.length()));
					}
					count++;
					String phy_id="PIC"+sdf.format(new Date())+String.format("%04d",count);
					
					boolean test=true;
//					判定标准与修正值
					for(QcmJhySampleConsignDItem qsd:qjsd){
//						在这个层级插入QCM_PHY_RESULT表				
						boolean istrue_jfmax=true,istrue_jfmin=true,istrue_khmax=true,istrue_khmin=true,istrue_nkmax=true,istrue_nkmin=true;
//						一个必判项目不合格则不合格
						if(!(istrue_jfmax&&istrue_jfmin&&istrue_khmax&&istrue_khmin&&istrue_nkmax&&istrue_nkmin)){
							test=false;
						}
//						插入QCM_PHY_RESULT
						QcmPhyResult qpr=new QcmPhyResult();
						qpr.setBatch_no(qd.getBatch_no());
						qpr.setContract_line_no(qd.getContract_line_no());
						qpr.setCreate_name("SYSTEM");
						qpr.setCreate_time(new Date());
						qpr.setGuid(java.util.UUID.randomUUID().toString().replace("-", ""));
						qpr.setHeat_no(qd.getHeat_no());
						qpr.setInspection_lot(qd.getInspection_lot());
						qpr.setItem_code_d(qsd.getItem_code_d());
						qpr.setItem_code_s(qsd.getItem_code_s());
						qpr.setItem_code_t(qsd.getItem_code_t());
						qpr.setItem_name_d(qsd.getItem_name_d());
						qpr.setItem_name_s(qsd.getItem_name_s());
						qpr.setItem_name_t(qsd.getItem_name_t());
						qpr.setMaterial_no(qm.getMaterial_no());
						qpr.setPhy_code_l(qsd.getPhy_code_l());
						qpr.setPhy_code_m(qsd.getPhy_code_m());
						qpr.setPhy_code_s(qsd.getPhy_code_s());
						qpr.setPhy_id(phy_id);
						qpr.setPhy_name_l(qsd.getPhy_name_l());
						qpr.setPhy_name_m(qsd.getPhy_name_m());
						qpr.setPhy_name_s(qsd.getPhy_name_s());
						qpr.setSmp_no(qd.getSmp_no());
//						qpr.setVal1("");...
						this.getMapper(QcmPhyResultMapper.class).insert(qpr);
					}
//					判定合格
					if(test){
						qd.setJudge_status("1");
						qd.setJudge_result_code("40740201");
						qd.setJudge_result_desc("合格");
					}
//					不合格
					else{
						qd.setJudge_status("1");
						qd.setJudge_result_code("40740203");
						qd.setJudge_result_desc("待处理");
					}
					
//					插入QCM_JUDGE_PHYSICAL
					QcmJudgePhysical qps=new QcmJudgePhysical();
					qps.setBatch_no(qd.getBatch_no());
					qps.setContract_line_no(qd.getContract_line_no());
					qps.setDesign_key(qd.getDesign_key());
					qps.setHeat_no(qd.getHeat_no());
					qps.setInspection_lot(qd.getInspection_lot());
					qps.setJudge_name("SYSTEM");
					qps.setPhy_result_code(qd.getJudge_result_code());
					qps.setPhy_result_desc(qd.getJudge_result_desc());
					qps.setJudge_ttime(new Date());
					qps.setPhy_memo("系统自动判定");
					qps.setPhy_id(phy_id);
					qps.setPline_code(qm.getPline_code());
					qps.setPline_name(qm.getPline_name());
					qps.setPsc(qd.getPsc());
					qps.setSmp_no(qd.getSmp_no());
					this.getMapper(QcmJudgePhysicalMapper.class).insert(qps);
					
//					获取材质结果集ID及材质判定记录号通过试样号更新试样号与合同信息关系表（QCM_JHY_SAMPLE_R_ORD.PHY_ID、PIC_ID）
					qd.setPhy_id(phy_id);
					this.getMapper(QcmJhySampleROrdMapper.class).update(qd);
				}
				}
			}
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("自动判定失败！");
			throw new Exception();
		}
		return rm;
	}
	/*
	 *综合判定-获取材质判定检验实绩信息 
	 * */
	public ResultModel getPhySampleItem(CommonPage<YdmProductDetail> sum){
		ResultModel rm=new ResultModel();
		YdmProductDetail ydm=sum.getObject();
//		QcmJudgePhysical qjp=new QcmJudgePhysical();
//		System.out.println(ydm.getPic_id());
		try {
			if (DataHelper.IsNullOrSpace(ydm.getPhysresult_id())) {
				rm.setMsgInfo("请传入材质判定记录号");
				return rm;
			}
//			qjp.setPic_id(ydm.getPic_id());
//			qjp=this.getMapper(QcmJudgePhysicalMapper.class).getPhySampleItem(qjp);
			List<QcmJudgePhysicalUtmD> listd = this.getMapper(QcmJudgePhysicalUtmDMapper.class).findWithCondition(null, "pic_id='"+ydm.getPhysresult_id()+"'", null, 0, 0);
			rm.setData(listd);
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("查询失败");
			rm.setErrorInfo(e.getMessage());
		}
		return rm;
	}
	
	/***
	 * 综合判定:
	 * @param sum
	 * @return
	 */
	public ResultModel ultimateJudgeAuto(CommonPage<YdmProductDetail> sum){
		ResultModel rm=new ResultModel();
		List<YdmProductDetail> ypdList=sum.getObjectList();
		
		for (YdmProductDetail ypd : ypdList) {
			YdmProductDetail y = this.getMapper(YdmProductDetailMapper.class).doFind(ypd.getCoilno(), null);
			if (y!=null && "2".equals(y.getState())) {
				rm.setState("500");
				rm.setMsgInfo("物料已经发运锁定，无法进行综合判定");
				return rm;
			}
			if (y!=null && "5".equals(y.getState())) {
				rm.setState("500");
				rm.setMsgInfo("物料已经出库，无法进行综合判定");
				return rm;
			}
			if ("1".equals(sum.getMemo1())) { //手动进行综合判定
				// 手动改判必须是库存状态：20220627 treals
				if (!"0".equals(y.getState())) {
					rm.setState("500");
					rm.setMsgInfo("物料不是在库状态，无法进行综合判定");
					return rm;
				}
				// 如果该卷进行了计划编制也不能再进行综合判定：
				List<String> strs = this.getMapper(PlnSkinrollingPlanMapper.class).isCoilNext(y.getCoilno());
				if (strs != null && strs.size() > 0) {
					rm.setState("500");
					rm.setMsgInfo("物料已经进行下道工序的计划编制，无法进行综合判定");
					return rm;
				}
			}
		}
		if ("1".equals(sum.getMemo1())) { //手动进行综合判定
			rm = creatUltimateResultByHand(ypdList);
		}
		return rm;
	}
	
	/**
	 * 手动进行综合判定
	 * @param ypdList
	 * @param result
	 * @throws Exception 
	 */
	private ResultModel creatUltimateResultByHand(List<YdmProductDetail> ypdList){
		ResultModel rm = new ResultModel();
		Date now = new Date();
		String opr_time = new SimpleDateFormat("yyyyMMddHHmmss").format(now); //操作时间
		String userId = (String) this.getSession().getAttribute(HomeService.SESSION_USER_ID);
		String username = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
	 	if (ypdList==null || ypdList.size()<=0) {
	 		rm.setMsgInfo("请传入参数");
	 		rm.setState("500");
			return rm;
		}
	 	SimpleDateFormat sdf=new SimpleDateFormat("yyMMdd");
		String date=sdf.format(now);
		try {	
			for (YdmProductDetail ypd : ypdList) {
				YdmProductDetail y = this.getMapper(YdmProductDetailMapper.class).doFind(ypd.getCoilno(), null);
				if (y!=null) {					
					//1.删除原有的判定记录
					QcmJudgeUltimate qj = new QcmJudgeUltimate();
					qj.setMaterial_no(ypd.getCoilno());
					List<QcmJudgeUltimate> qjuList = this.getMapper(QcmJudgeUltimateMapper.class).find(qj, 0, 0);
					if (CollectionUtils.isNotEmpty(qjuList)) {
						for (QcmJudgeUltimate q : qjuList) {
							//this.getMapper(QcmJudgeUltimateMapper.class).delete(q.getUtm_id());
						}
					}					
					//2.新增综合判定记录
					QcmJudgeUltimate qju=new QcmJudgeUltimate();
					//获取判定记录号当天的最大值
					int count=0;			
					List<QcmJudgeUltimate> listUl=this.getMapper(QcmJudgeUltimateMapper.class).findWithCondition(null, "UTM_ID like 'Z"+date+"%'", "UTM_ID desc", 0, 1);
					if (listUl!=null&&listUl.size()>0) {
						String s=listUl.get(0).getUtm_id();
						count=Integer.parseInt(s.substring(s.length()-4,s.length()));
					}
					count++;
					String utm_id="Z"+sdf.format(now)+String.format("%04d",count);
					System.out.println("主键ID = "+utm_id);
					//公差检验实绩表
					QcmJudgeMeasure qjm = new QcmJudgeMeasure();
					if (!DataHelper.IsNullOrSpace(y.getMeasure_result_id())) {
						qjm = this.getMapper(QcmJudgeMeasureMapper.class).findById(y.getMeasure_result_id());
					} else {
						qjm.setSic_result_code(y.getMeasure_result());
						qjm.setSic_result_desc("合格");
					}
					qju.setSic_id(qjm.getSic_id());
					qju.setSic_memo(qjm.getSic_memo());
					qju.setSic_result_code(qjm.getSic_result_code());
					qju.setSic_result_desc(qjm.getSic_result_desc());
					//表面检验实绩表
					QcmJudgeSurface qjsU = new QcmJudgeSurface();
					if (!DataHelper.IsNullOrSpace(y.getUp_surface_result_id())) {
						qjsU=this.getMapper(QcmJudgeSurfaceMapper.class).getSurfaceSampleItem("U",y.getUp_surface_result_id());
					} else {
						qjsU.setSf_result_code(y.getUp_surface_result());
						qjsU.setSf_result_desc("合格");
					}
					qju.setSfu_id(qjsU.getSurface_id());
					qju.setSfu_memo(qjsU.getSf_memo());
					qju.setSfu_result_code(qjsU.getSf_result_code());
					qju.setSfu_result_desc(qjsU.getSf_result_desc());
					qju.setUtm_id(utm_id);
					qju.setHeat_no(y.getHeatno());
					qju.setBatch_no(y.getBatchno());
					qju.setInspection_lot(y.getInspection_lot());
					qju.setOrder_no(y.getOrderno());
					qju.setDesign_key(y.getDesign_key());
					qju.setPsc(y.getPsc());
					qju.setPline_name(y.getPline_name());
					qju.setMaterial_no(y.getCoilno());
					qju.setBox_no(y.getBoxno());
					qju.setContract_line_no(y.getOrderno());
					//材质
					qju.setPic_id(y.getPhysresult_id());
					qju.setPic_result_code(y.getPhysresult());
					if (StringUtils.isNotEmpty(y.getPhysresult())) {						
						if ("40740201".equals(y.getPhysresult())) {
							qju.setPic_result_desc("合格");
						}else {
							qju.setPic_result_desc("不合格");
						}		    
					}
					//成分
					qju.setCic_id(y.getChemresult_id());
					qju.setCic_result_code(y.getChemresult());
					if (StringUtils.isNotEmpty(y.getChemresult())) {						
						if ("40740101".equals(y.getChemresult())) {
							qju.setCic_result_desc("合格");
						}else {
							qju.setCic_result_desc("不合格");
						}
					}
					//探伤
					qju.setDic_id(y.getSpyresult_id());
					qju.setDic_result_code(y.getSpyresult());
					if (StringUtils.isNotEmpty(y.getSpyresult())) {						
						if ("40740401".equals(y.getSpyresult())) {
							qju.setDic_result_desc("合格");
						}else {
							qju.setDic_result_desc("不合格");
						}
					}
					//前端传参
					qju.setUtm_memo(ypd.getUtm_memo() );
					qju.setUtm_reason(ypd.getUtm_reason());
					qju.setUtm_result_code(ypd.getUtm_result_code());
					qju.setUtm_result_desc(ypd.getUtm_result_desc());
					qju.setJudge_name(username);
					qju.setJudge_time(now);					
					this.getMapper(QcmJudgeUltimateMapper.class).insert(qju);
					//3.根据综合判定，判定是否脱单：不合格，判次，判废都脱单；20230215刘侣
					if("40740802".equals(ypd.getUtm_result_code()) || "40740804".equals(ypd.getUtm_result_code()) || "40740803".equals(ypd.getUtm_result_code())){
						// end
						//如果综合判定结果为不合格，调用生产接口脱单
						CommonPage<PlnMaterielDetail> oci = new CommonPage<>();
						List<PlnMaterielDetail> listPln = new ArrayList<>();
						PlnMaterielDetail pln = new PlnMaterielDetail();
						pln.setObject_no(ypd.getCoilno());
						listPln.add(pln);
						oci.setObjectList(listPln);
						oci.setMemo1("质量综合判定");
						this.getService(PlnMaterielDetailService.class).doMatReplaceAuto(oci);				
					}
					//4.更新库存表的综合判定结果
					this.getMapper(YdmProductDetailMapper.class).updateUlJudgeResult(ypd.getCoilno(), ypd.getUtm_result_code());
					
					String isOpen = this.getMapper(ComBaseInfoMapper.class).findById("9512").getMemo();
					if ("1".equals(isOpen)) {
					
						if ("500203".equals(ypd.getStorageattr()) || "40740804".equals(ypd.getUtm_result_code())) {
							// 记录成本异动点：20230811刘侣
							YdmProductDetail ypd2 = this.getMapper(YdmProductDetailMapper.class).doFind(ypd.getCoilno(), null);
							ComBaseCbYdd cd = new ComBaseCbYdd();
							cd.setCoilStus("1"); // 综判前算半成品0，综判入库后算成品1
							cd.setInstDisp("01");
							cd.setDataTypeIdx("O");
							// 当前产线：
							String currentMachine = ypd2.getCoilno().contains("S") ? "YTSX" : ypd2.getCoilno().contains("L") ? "YTZZ" : ypd2.getCoilno().contains("P") ? "YTPZ" : ypd2.getCoilno().contains("T") ? "YTTH" : ypd2.getCoilno().contains("K") ? "YTHJ" : ypd2.getCoilno().contains("F") ? "YTZJ" : "YT1";
							cd.setLocNo(currentMachine); // 填当前产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
							cd.setInvQtyUnit("块");
							cd.setInvWidth(ypd2.getWidth() != null ? String.valueOf(ypd2) : "0");
							cd.setCreateId(userId);
							cd.setActivityId("40740801".equals(ypd2.getJudgeresult()) ? "11AC" : "11AZ");
							cd.setInvLength(ypd2.getLength() != null ? String.valueOf(ypd2.getLength()) : "0");
							cd.setManageip(currentMachine); // 填当前产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
							cd.setProdName(ypd2.getProd_name());
							cd.setInvThick(ypd2.getThick() != null ? String.valueOf(ypd2.getThick()) : "0");
							
							
							String prevcoil = this.getBean(YdmProductInlistService.class).doQueryTl(ypd2.getCoilno());
							// 上道产线：
							String prevMachine = prevcoil.contains("S") ? "YTSX" : prevcoil.contains("L") ? "YTZZ" : prevcoil.contains("P") ? "YTPZ" : prevcoil.contains("T") ? "YTTH" : prevcoil.contains("K") ? "YTHJ" : prevcoil.contains("F") ? "YTZJ" : "YT1";
							cd.setRefnoA(prevcoil); // 投料卷号
							cd.setSysId("IA");
							cd.setOrderItem(ypd2.getOrderno());
							cd.setCrntMill(currentMachine); // 填当前产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
							cd.setBeTransUnit("t");
							cd.setExecJobFunc("N");
							ComBaseSteel cbs = this.getMapper(ComBaseSteelMapper.class).findById(ypd2.getSteelcode());
							if (cbs != null) {
								cd.setAlloyNo(cbs.getSteel_name()); // 牌号
							}
							
							cd.setAcctDate(new SimpleDateFormat("yyyyMMdd").format(now));
							cd.setLastMill(prevMachine); // 填上道工序产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
							cd.setBeTransWgt(ypd2.getFactweight() != null ? ypd2.getFactweight() / 1000 : ypd2.getFactweight());
							cd.setProdTypeNo("CTR");
							String currentMName = ypd2.getCoilno().contains("S") ? "酸洗" : ypd2.getCoilno().contains("L") ? "冷轧" : ypd2.getCoilno().contains("P") ? "平整" : ypd2.getCoilno().contains("T") ? "退火" : ypd2.getCoilno().contains("K") ? "横剪" : ypd2.getCoilno().contains("F") ? "分条" : "原料";
							cd.setAppId("优特" + currentMName + "手动综判");
							cd.setInvId(ypd2.getCoilno());
							cd.setInvQty("1");

							// setSrcFac根据卷的物料属性去判断：20231031刘侣
							cd.setSrcFac("507101".equals(ypd2.getObject_attr()) ? "1" : "3");
							
							cd.setGrade("40740801".equals(ypd2.getJudgeresult()) ? "1" : "1"); // 正品　1　协议　3　次品　5
							cd.setProdClassNo("H");
							// 存入表：
							this.getBean(SlmFundFirstDetailService.class).doCbDataIns(cd, cd.getActivityId(), ypd2.getMaterailcoilno());
							// end
						}
					}
						
				}
				//日志
				MesOprLog mol = new MesOprLog("质量管理", "综合判定管理", "综合判定", username, opr_time, ypd.getCoilno(), null, null, null, "判定结果:"+ypd.getUtm_result_desc());
				this.getMapper(MesOprLogMapper.class).insert(mol);
			}	
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("综合判定失败");
			return rm;
		}
		rm.setState("200");
		rm.setMsgInfo("综合判定成功");
		return rm;
	}
	
	/*
	 *综合判定-综合判定按钮(此接口已不再使用，现使用ultimateJudgeAuto)
	 * 
	 * */
	@Transactional(value = "tm", rollbackFor = Exception.class)
	public ResultModel ultimateJudge(CommonPage<YdmProductDetail> sum){
		ResultModel rm=new ResultModel();
		List<YdmProductDetail> ypd=sum.getObjectList();
		String username=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		try {
			//验证所选列是否为在库状态
			//验证其他判定是否已经判定
			for (YdmProductDetail y2 : ypd) {
		     YdmProductDetail ypd2=this.getMapper(YdmProductDetailMapper.class).findById(y2.getCoilno());
				if (!ypd2.getState().equals("0")) {
					rm.setState("500");
					rm.setMsgInfo("【"+ypd2.getCoilno()+"】物料已出库、无法执行综合判定操作");
					return rm;
				}  

			   //获取判定记录号当天的最大值
			 	int count=0;
				SimpleDateFormat sdf=new SimpleDateFormat("yyMMdd");
				String date=sdf.format(new Date());
				List<QcmJudgeUltimate> listUl=this.getMapper(QcmJudgeUltimateMapper.class).findWithCondition(null, "UTM_ID like 'Z"+date+"%'", "UTM_ID desc", 0, 1);
				if (listUl!=null&&listUl.size()>0) {
					String s=listUl.get(0).getUtm_id();
					count=Integer.parseInt(s.substring(s.length()-4,s.length()));
				}
				count++;
				String utm_id="Z"+sdf.format(new Date())+String.format("%04d",count);
				System.out.println(utm_id);
				//获取成分基本信息（检验判定记录号、检验判定结果代码、检验判定结果名称、备注信息）
				//QcmJudgeChemical qjc = this.getMapper(QcmJudgeChemicalMapper.class).getchemsampl(ypd2.getChemresult_id());
				//获取材质基本信息（检验判定记录号、检验判定结果代码、检验判定结果名称、备注信息）
				//this.getMapper(QcmJudgePhysicalUtmDMapper.class).findWithCondition(null, condition, orderBy, skipResults, maxResults)
				//QcmJudgePhysical qjp = this.getMapper(QcmJudgePhysicalMapper.class).findById(ypd2.getPhysresult_id());
				//获取卡量基本信息（检验判定记录号、检验判定结果代码、检验判定结果名称、备注信息）
				QcmJudgeMeasure qjm = new QcmJudgeMeasure();
				if (!DataHelper.IsNullOrSpace(ypd2.getMeasure_result_id())) {
					qjm = this.getMapper(QcmJudgeMeasureMapper.class).findById(ypd2.getMeasure_result_id());
				} else {
					qjm.setSic_result_code(ypd2.getMeasure_result());
					qjm.setSic_result_desc("合格");
				}
                //获取上、下、边部检验基本信息（检验判定记录号、检验判定结果代码、检验判定结果名称、备注信息）
				 //获取上表信息
				QcmJudgeSurface qjsU = new QcmJudgeSurface();
				QcmJudgeSurface qjsD = new QcmJudgeSurface();
				QcmJudgeSurface qjsE = new QcmJudgeSurface();
				if (!DataHelper.IsNullOrSpace(ypd2.getUp_surface_result_id())) {
					qjsU=this.getMapper(QcmJudgeSurfaceMapper.class).getSurfaceSampleItem("U",ypd2.getUp_surface_result_id());
				} else {
					qjsU.setSf_result_code(ypd2.getUp_surface_result());
					qjsU.setSf_result_desc("合格");
				}
				 
				//获取下表信息
				if (!DataHelper.IsNullOrSpace(ypd2.getUd_surface_result_id())) {
					qjsD=this.getMapper(QcmJudgeSurfaceMapper.class).getSurfaceSampleItem("D",ypd2.getUd_surface_result_id());
				} else {
					qjsD.setSf_result_code(ypd2.getUd_surface_result());
					qjsD.setSf_result_desc("合格");
				}
				
				//获取边部信息
				if (!DataHelper.IsNullOrSpace(ypd2.getMarginal_result_id())) {
					qjsE=this.getMapper(QcmJudgeSurfaceMapper.class).getSurfaceSampleItem("E",ypd2.getMarginal_result_id());
				} else {
					qjsE.setSf_result_code(ypd2.getMarginal_result());
					qjsE.setSf_result_desc("合格");
				}
				 
				//将数据插入到综合判定记录表QCM_JUDGE_ULTIMATE
				QcmJudgeUltimate qju=new QcmJudgeUltimate();
				qju.setUtm_id(utm_id);
				qju.setHeat_no(ypd2.getHeatno());
				qju.setBatch_no(ypd2.getBatchno());
				qju.setInspection_lot(ypd2.getInspection_lot());
				qju.setOrder_no(ypd2.getOrderno());
				qju.setDesign_key(ypd2.getDesign_key());
				qju.setPsc(ypd2.getPsc());
				//qju.setBatch_no(batch_no);
				//qju.setInspection_lot(inspection_lot);
				qju.setMaterial_no(ypd2.getCoilno());
				qju.setContract_line_no(ypd2.getOrderno());
				//产品规范码
				//qju.setPsc();
				//产线代码？
				qju.setBox_no(ypd2.getBoxno());
				//成分
//				if (qjc!=null) {
//					qju.setCic_id(qjc.getCic_id());
//					qju.setCic_memo(qjc.getCic_memo());
//					qju.setCic_result_code(qjc.getCic_result_code());
//					qju.setCic_result_desc(qjc.getCic_result_desc());
//				}
				//材质
//				if (qjp!=null) {
					 qju.setPic_id(ypd2.getPhysresult_id());
//				     qju.setPic_memo(qjp.getPic_memo());
				     qju.setPic_result_code(ypd2.getPhysresult());
				     if ("40740201".equals(ypd2.getPhysresult())) {
				    	 qju.setPic_result_desc("合格");
					}else {
						 qju.setPic_result_desc("不合格");
					}
				    
//				}
		        //卡量
				if (qjm!=null) {
					 qju.setSic_id(qjm.getSic_id());
				     qju.setSic_memo(qjm.getSic_memo());
				     qju.setSic_result_code(qjm.getSic_result_code());
				     qju.setSic_result_desc(qjm.getSic_result_desc());
				}else {
					qju.setSic_result_code(ypd2.getMeasure_result());
					qju.setSfd_result_desc("合格");
				}
		        //上表
				if (qjsU!=null) {
					  qju.setSfu_id(qjsU.getSurface_id());
				      qju.setSfu_memo(qjsU.getSf_memo());
				      qju.setSfu_result_code(qjsU.getSf_result_code());
				      qju.setSfu_result_desc(qjsU.getSf_result_desc());	
				}else {
					   qju.setSfu_result_code(ypd2.getUd_surface_result());
					    qju.setSfu_result_desc("合格");	
				}
		        //下表
				if (qjsD!=null) {
					qju.setSfd_id(qjsD.getSurface_id());
			        qju.setSfd_memo(qjsD.getSf_memo());
			        qju.setSfd_result_code(qjsD.getSf_result_code());
			        qju.setSfd_result_desc(qjsD.getSf_result_desc());
				}
				else {
					 qju.setSfd_result_code(ypd2.getUd_surface_result());
				     qju.setSfd_result_desc("合格");
				}
		        //边部
				if (qjsE!=null) {
					  qju.setSfe_id(qjsE.getSurface_id());
				      qju.setSfe_memo(qjsE.getSf_memo());
				      qju.setSfe_result_code(qjsE.getSf_result_code());
				      qju.setSfe_result_desc(qjsE.getSf_result_desc());
				}
				else {
					 qju.setSfe_result_code(ypd2.getMarginal_result());
				      qju.setSfe_result_desc("合格");
				}
		        //综合
		        qju.setUtm_result_code(y2.getUtm_result_code());
		        qju.setUtm_memo(y2.getUtm_memo());
		        qju.setUtm_result_desc(y2.getUtm_result_desc());
		        qju.setUtm_reason(y2.getUtm_reason());
		        qju.setJudge_name(username);
		        qju.setJudge_time(new Date());
		        qju.setPline_name(y2.getPline_name());		       		        
		        this.getMapper(QcmJudgeUltimateMapper.class).insert(qju);
		        //再一次验证是否在库
				for (YdmProductDetail y1 : ypd) {
					YdmProductDetail ypd3 = this.getMapper(YdmProductDetailMapper.class).findById(y1.getCoilno());
					if (!ypd3.getState().equals("0")) {
						rm.setState("500");
						rm.setMsgInfo("【"+ypd3.getCoilno()+"】物料不在库、无法执行综合判定操作");
						return rm;
					}
				}
		        //更新综合判定结果
				this.getMapper(YdmProductDetailMapper.class).updateUlJudgeResult(ypd2.getCoilno(), y2.getUtm_result_code());
			}
			rm.setData("200");
			
		} catch (Exception e) {
			rm.setState("500");
			rm.setErrorInfo(e.getMessage());
		}
		
		return rm;
	}
	
	/*
	 * 综合判定-取消综合判定按钮
	 * 
	 * */
	public ResultModel cancelUltimateJudge(CommonPage<YdmProductDetail> sum){
		ResultModel rm=new ResultModel();
		Date now = new Date();
		String opr_time = new SimpleDateFormat("yyyyMMddHHmmss").format(now); //操作时间
		String userId = (String) this.getSession().getAttribute(HomeService.SESSION_USER_ID);
		String username = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		List<YdmProductDetail> ypd=sum.getObjectList();
		try {
			//验证所选列是否为在库状态
			for (YdmProductDetail y : ypd) {
				YdmProductDetail ypd1=this.getMapper(YdmProductDetailMapper.class).findById(y.getCoilno());
				if (!ypd1.getState().equals("0")) {
					rm.setState("500");
					rm.setMsgInfo("【"+ypd1.getCoilno()+"】物料不在库、无法执行综合判定操作");
					return rm;
				}

				String isOpen = this.getMapper(ComBaseInfoMapper.class).findById("9512").getMemo();
				if ("1".equals(isOpen)) {
				
					if ("500203".equals(ypd1.getStorageattr()) || "40740804".equals(ypd1.getUtm_result_code())) {
						// 记录成本异动点：20230811刘侣
						YdmProductDetail ypd2 = this.getMapper(YdmProductDetailMapper.class).doFind(y.getCoilno(), null);
						ComBaseCbYdd cd = new ComBaseCbYdd();
						cd.setCoilStus("1"); // 综判前算半成品0，综判入库后算成品1
						cd.setInstDisp("01");
						cd.setDataTypeIdx("O");
						// 当前产线：
						String currentMachine = ypd2.getCoilno().contains("S") ? "YTSX" : ypd2.getCoilno().contains("L") ? "YTZZ" : ypd2.getCoilno().contains("P") ? "YTPZ" : ypd2.getCoilno().contains("T") ? "YTTH" : ypd2.getCoilno().contains("K") ? "YTHJ" : ypd2.getCoilno().contains("F") ? "YTZJ" : "YT1";
						cd.setLocNo(currentMachine); // 填当前产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
						cd.setInvQtyUnit("块");
						cd.setInvWidth(ypd2.getWidth() != null ? String.valueOf(ypd2) : "0");
						cd.setCreateId(userId);
						cd.setActivityId("40740801".equals(ypd2.getJudgeresult()) ? "11AC" : "11AZ");
						cd.setInvLength(ypd2.getLength() != null ? String.valueOf(ypd2.getLength()) : "0");
						cd.setManageip(currentMachine); // 填当前产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
						cd.setProdName(ypd2.getProd_name());
						cd.setInvThick(ypd2.getThick() != null ? String.valueOf(ypd2.getThick()) : "0");
						
						
						String prevcoil = this.getBean(YdmProductInlistService.class).doQueryTl(ypd2.getCoilno());
						// 上道产线：
						String prevMachine = prevcoil.contains("S") ? "YTSX" : prevcoil.contains("L") ? "YTZZ" : prevcoil.contains("P") ? "YTPZ" : prevcoil.contains("T") ? "YTTH" : prevcoil.contains("K") ? "YTHJ" : prevcoil.contains("F") ? "YTZJ" : "YT1";
						cd.setRefnoA(prevcoil); // 投料卷号
						cd.setSysId("IA");
						cd.setOrderItem(ypd2.getOrderno());
						cd.setCrntMill(currentMachine); // 填当前产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
						cd.setBeTransUnit("t");
						cd.setExecJobFunc("D");
						ComBaseSteel cbs = this.getMapper(ComBaseSteelMapper.class).findById(ypd2.getSteelcode());
						if (cbs != null) {
							cd.setAlloyNo(cbs.getSteel_name()); // 牌号
						}
						
						cd.setAcctDate(new SimpleDateFormat("yyyyMMdd").format(now));
						cd.setLastMill(prevMachine); // 填上道工序产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
						cd.setBeTransWgt(ypd2.getFactweight() != null ? ypd2.getFactweight() / 1000 : ypd2.getFactweight());
						cd.setProdTypeNo("CTR");
						String currentMName = ypd2.getCoilno().contains("S") ? "酸洗" : ypd2.getCoilno().contains("L") ? "冷轧" : ypd2.getCoilno().contains("P") ? "平整" : ypd2.getCoilno().contains("T") ? "退火" : ypd2.getCoilno().contains("K") ? "横剪" : ypd2.getCoilno().contains("F") ? "分条" : "原料";
						cd.setAppId("优特" + currentMName + "取消手动综判");
						cd.setInvId(ypd2.getCoilno());
						cd.setInvQty("1");

						// setSrcFac根据卷的物料属性去判断：20231031刘侣
						cd.setSrcFac("507101".equals(ypd2.getObject_attr()) ? "1" : "3");
						
						cd.setGrade("40740801".equals(ypd2.getJudgeresult()) ? "1" : "1"); // 正品　1　协议　3　次品　5
						cd.setProdClassNo("H");
						// 存入表：
						this.getBean(SlmFundFirstDetailService.class).doCbDataIns(cd, cd.getActivityId(), ypd2.getMaterailcoilno());
						// end
					}
				}
				
				//把卷号对应的综合判定结果清空
				this.getMapper(QcmJudgePhysicalMapper.class).emptyUtJudgeResult(ypd1);
				
				
				MesOprLog mol = new MesOprLog("质量管理", "综合判定管理", "取消综合判定", username, opr_time, y.getCoilno(), null, null, null, null);
				this.getMapper(MesOprLogMapper.class).insert(mol);
			}
			rm.setData("200");
		} catch (Exception e) {
			rm.setData("500");
			rm.setMsgInfo(e.getMessage());
		}
		
		return rm;
	}
	/*
	 * 
	 * 综合判定-更新初样结果
	 * 
	 * */
	@Transactional(value = "tm", rollbackFor = Exception.class)
	public ResultModel UpdateTheInitialSample(CommonPage<YdmProductDetail> sum){
		ResultModel rm=new ResultModel();
		YdmProductDetail ypd2=sum.getObject();
		try {
			//验证所选列是否为在库状态
				YdmProductDetail ypd1=this.getMapper(YdmProductDetailMapper.class).findById(ypd2.getCoilno());
				if (!ypd1.getState().equals("0")) {
					rm.setState("500");
					rm.setMsgInfo("【"+ypd1.getCoilno()+"】物料已出库、无法更新初样信息");
					return rm;
			}
		      //验证其他判定是否为空
				//验证成分判定结果是否存在
				  if (ypd2.getChemresult()==null||ypd2.getChemresult().equals("")) {
			    	    rm.setState("500");
						rm.setMsgInfo(ypd2.getCoilno()+"中"+"【成分判定结果不存在】");
						return rm;
				}
			   //验证材质判定结果是否存在
			     if (ypd2.getPhysresult()==null||ypd2.getPhysresult().equals("")) {
			    	    rm.setState("500");
						rm.setMsgInfo(ypd2.getCoilno()+"中"+"【材质判定结果不存在】");
						return rm;
				}
			     //验证探伤判定结果是否存在
//			     if (ypd2.getSpyresult()==null&&ypd2.getSpyresult().equals("")) {
//			    	    rm.setState("500");
//						rm.setMsgInfo(ypd2.getCoilno()+"中"+"【探伤判定结果不存在】");
//						return rm;
//				}
			     //验证上表检验结果是否存在
			     if (ypd2.getUp_surface_result()==null||ypd2.getUp_surface_result().equals("")) {
			    	    rm.setState("500");
						rm.setMsgInfo(ypd2.getCoilno()+"中"+"【上表检验结果不存在】");
						return rm;
				}
			   //验证下表检验结果是否存在
			     if (ypd2.getUd_surface_result()==null||ypd2.getUd_surface_result().equals("")) {
			    	    rm.setState("500");
						rm.setMsgInfo(ypd2.getCoilno()+"中"+"【下表检验结果不存在】");
						return rm;
				}
			   //验证边部检验结果是否存在
			     if (ypd2.getMarginal_result()==null||ypd2.getMarginal_result().equals("")) {
			    	    rm.setState("500");
						rm.setMsgInfo(ypd2.getCoilno()+"中"+"【边部检验结果不存在】");
						return rm;
				}
			     //验证卡量检验结果是否存在
//			     if (ypd2.getMeasure_result()==null||ypd2.getMeasure_result().equals("")) {
//			    	    rm.setState("500");
//						rm.setMsgInfo(ypd2.getCoilno()+"中"+"【卡量检验结果不存在】");
//						return rm;
//				}
			       //获取成分基本信息（检验判定记录号、检验判定结果代码、检验判定结果名称、备注信息）
					QcmJudgeChemical qjc=this.getMapper(QcmJudgeChemicalMapper.class).findById(ypd2.getChemid());
					//获取材质基本信息（检验判定记录号、检验判定结果代码、检验判定结果名称、备注信息）
					QcmJudgePhysical qjp = this.getMapper(QcmJudgePhysicalMapper.class).findById(ypd2.getPhysid());
					//获取卡量基本信息（检验判定记录号、检验判定结果代码、检验判定结果名称、备注信息）
					 QcmJudgeMeasure qjm = this.getMapper(QcmJudgeMeasureMapper.class).findById(ypd2.getMeasure_result_id());
	                //获取上、下、边部检验基本信息（检验判定记录号、检验判定结果代码、检验判定结果名称、备注信息）
					 //获取上表信息
					 QcmJudgeSurface qjsU=this.getMapper(QcmJudgeSurfaceMapper.class).getSurfaceSampleItem("U",ypd2.getUp_surface_result_id());
					
					//获取下表信息
					 QcmJudgeSurface qjsD=this.getMapper(QcmJudgeSurfaceMapper.class).getSurfaceSampleItem("D",ypd2.getUd_surface_result_id());
					
					//获取边部信息
					 QcmJudgeSurface qjsE=this.getMapper(QcmJudgeSurfaceMapper.class).getSurfaceSampleItem("E",ypd2.getMarginal_result_id());
					 if (qjc.getCic_result_desc().equals("合格")&&qjp.getPhy_result_desc().equals("合格")&&qjm.getSic_result_desc().equals("合格")
					    &&qjsU.getSf_result_desc().equals("合格")&&	 qjsD.getSf_result_desc().equals("合格")&&qjsE.getSf_result_desc().equals("合格")
							 ) {
						//引用计划模块接口更新初样结果为合格
						 
					}else{
						//引用计划模块接口更新初样结果为不合格
					}
			rm.setData("200");	
			
		} catch (Exception e) {

		}
		return rm;
	}
	/**
	 * 查询综合判定判定记录信息
	 * Coilno 产品序号
	 * Utm_result_desc 判定结果名称
	 * StartTime 开始时间
	 * EndTime 结束时间
	 * PageIndex 页码
	 * PageSize 显示条数
	 * @param sum
	 * @return
	 */
	public ResultModel getDecisionRecodeSample(CommonPage<QcmJudgeUltimate> sum){
		ResultModel rm=new ResultModel();
		QcmJudgeUltimate qju=sum.getObject();
		PageModel<QcmJudgeUltimate> pm=new PageModel<>(sum.getPageIndex(), sum.getPageSize());
		try {
			String connect="";
			if (qju.getMaterial_no()!=null&&!qju.getMaterial_no().equals("")) {
				connect+="and t.material_no like '%"+qju.getMaterial_no()+"%'";
			}
			if (qju.getUtm_result_desc()!=null&&!qju.getUtm_result_desc().equals("")) {
				connect+="and t.utm_result_desc ='"+qju.getUtm_result_desc()+"'";
			}
			if (!DataHelper.IsNullOrSpace(qju.getInspection_lot())){
				connect+="and t.inspection_lot ='"+qju.getInspection_lot()+"'";
			}
			if (!DataHelper.IsNullOrSpace(qju.getHeat_no())){
				connect+="and t.heat_no ='"+qju.getHeat_no()+"'";
			}
			if (!DataHelper.IsNullOrSpace(qju.getBatch_no())){
				connect+="and t.batch_no ='"+qju.getBatch_no()+"'";
			}
			if (!DataHelper.IsNullOrSpace(qju.getOrder_no())){
				connect+="and t.order_no like '%"+qju.getOrder_no()+"%'";
			}
			if(sum.getStartTime()!=null&&!sum.getStartTime().equals("")){
				connect+=" and t.judge_time >=to_date(concat('"+sum.getStartTime()+"',' 00:00:00'),'yyyy-MM-dd HH24:mi:ss')"; 
			}
			if(sum.getEndTime()!=null&&!sum.getEndTime().equals("")){
				connect+=" and t.judge_time <=to_date(concat('"+sum.getEndTime()+"',' 23:59:59'),'yyyy-MM-dd HH24:mi:ss') ";
			}
			//投料卷号
			if (!DataHelper.IsNullOrSpace(qju.getObject_no())){
				connect+="and pmr.object_no like '%"+qju.getObject_no()+"%'";
			}
			//原料卷号
			if (!DataHelper.IsNullOrSpace(qju.getMaterailcoilno())){
				connect+="and ypd.materailcoilno ='"+qju.getMaterailcoilno()+"'";
			}
			//产线
			if (!DataHelper.IsNullOrSpace(qju.getMachine_code())){
				if ("".equals(qju.getMachine_code())) {
					connect+="and ypd.machine_code in ('M0004','M0005','M0006','M0009')";
				}else {					
					connect+="and ypd.machine_code ='"+qju.getMachine_code()+"'";
				}
			}
			System.out.println(connect);
			List<QcmJudgeUltimate> list = this.getMapper(QcmJudgeUltimateMapper.class).getDecisionRecodeSample(connect,(pm.getPageNumber()-1)*pm.getPageSize(),pm.getPageSize()*pm.getPageNumber());
			pm.setRows(list);
			pm.setTotal(this.getMapper(QcmJudgeUltimateMapper.class).getDecisionRecodeSampleCount(connect));
			rm.setData(pm);
		    rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("查询失败");
			rm.setErrorInfo(e.getMessage());
		}
		return rm;
	}
	/**
	 * 查询判定原因
	 * @return
	 */
	public ResultModel getJudementCause(){
		ResultModel rm=new ResultModel();
		ComBaseInfo cbi=new ComBaseInfo();
		cbi.setSort_code("4075");
		try {
		 List<ComBaseInfo> listcbi = this.getMapper(ComBaseInfoMapper.class).find(cbi, 0, 100);
		 rm.setData(listcbi);
		 rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("查询原因失败");
			rm.setErrorInfo(e.getMessage());
		}
		return rm;
	}
	/**
	 * 自动获取综合判定结果
	 * @param sum
	 * @return
	 */
	public ResultModel autoGetJudgeResult(CommonPage<YdmProductDetail> sum){
		ResultModel rm=new ResultModel();
		List<YdmProductDetail> listypd2=sum.getObjectList();
		boolean zh=false,cf=false,cz=false,kl=false,sb=false,xb=false,bb=false;
		try {
			for (YdmProductDetail ypd2 : listypd2) {
				//验证成分判定结果是否存在
				  if (ypd2.getChemresult()==null||ypd2.getChemresult().equals("")) {
			    	    rm.setState("500");
						rm.setMsgInfo(ypd2.getCoilno()+"中"+"【成分判定结果不存在】");
						return rm;
				}
			   //验证材质判定结果是否存在
			     if (ypd2.getPhysresult()==null||ypd2.getPhysresult().equals("")) {
			    	    rm.setState("500");
						rm.setMsgInfo(ypd2.getCoilno()+"中"+"【材质判定结果不存在】");
						return rm;
				}
			     //验证探伤判定结果是否存在
//			     if (ypd2.getSpyresult()==null&&ypd2.getSpyresult().equals("")) {
//			    	    rm.setState("500");
//						rm.setMsgInfo(ypd2.getCoilno()+"中"+"【探伤判定结果不存在】");
//						return rm;
//				}
			     //验证上表检验结果是否存在
			     if (ypd2.getUp_surface_result()==null||ypd2.getUp_surface_result().equals("")) {
			    	    rm.setState("500");
						rm.setMsgInfo(ypd2.getCoilno()+"中"+"【上表检验结果不存在】");
						return rm;
				}
			   //验证下表检验结果是否存在
			     if (ypd2.getUd_surface_result()==null||ypd2.getUd_surface_result().equals("")) {
			    	    rm.setState("500");
						rm.setMsgInfo(ypd2.getCoilno()+"中"+"【下表检验结果不存在】");
						return rm;
				}
			   //验证边部检验结果是否存在
			     if (ypd2.getMarginal_result()==null||ypd2.getMarginal_result().equals("")) {
			    	    rm.setState("500");
						rm.setMsgInfo(ypd2.getCoilno()+"中"+"【边部检验结果不存在】");
						return rm;
				}
			     //验证卡量检验结果是否存在
			     if (ypd2.getMeasure_result()==null||ypd2.getMeasure_result().equals("")) {
			    	    rm.setState("500");
						rm.setMsgInfo(ypd2.getCoilno()+"中"+"【卡量检验结果不存在】");
						return rm;
				}  
			   //验证是否全部合格
					if (ypd2.getChemresult().equals("合格")) {
						cf=true;
					}
					if (ypd2.getPhysresult().equals("合格")) {
						cz=true;
					}
					if (ypd2.getUp_surface_result().equals("合格")) {
						sb=true;
					}
					if (ypd2.getUd_surface_result().equals("合格")) {
						xb=true;
					}
					if (ypd2.getMarginal_result().equals("合格")) {
						bb=true;
					}
					if (ypd2.getMeasure_result().equals("合格")) {
						kl=true;
					}
					if (cf&&cz&&kl&&sb&&xb&&bb) {
						zh=true; 
					}
			}
			rm.setData(zh);
		} catch (Exception e) {

		}
		return rm;
	}
	/**
	 * 综合判定前判定其他判定是否已经完成
	 * @param sum
	 * memo1  design_key
	 * memo2  psc
	 * @return
	 */
	public ResultModel verificationUltimateisOrNoJudge(CommonPage<YdmProductDetail> sum){
		ResultModel rm=new ResultModel();
		List<YdmProductDetail> ypd=sum.getObjectList();
		try {
			for (YdmProductDetail y2 : ypd) {
				List<YdmProductDetail> listypd2=this.getMapper(YdmProductDetailMapper.class).findWithCondition(null, "coilno='"+y2.getCoilno()+"'", null, 0, 0);
				YdmProductDetail ypd2=new YdmProductDetail();
				if (listypd2.size()>0) {
                	ypd2=listypd2.get(0);
				}
				//验证成分判定结果是否存在
//			     if (ypd2.getChemresult()==null||ypd2.getChemresult().equals("")) {
//			    	    rm.setState("403");
//						rm.setMsgInfo(y2.getCoilno()+"中"+"【成分判定结果不存在】综合判定未完成,请先执行成分检验判定后再进行综合判定!");
//						return rm;
//				}
			   //验证材质判定结果是否存在
			     if (ypd2.getPhysresult()==null||ypd2.getPhysresult().equals("")) {
			    	    rm.setState("403");
						rm.setMsgInfo(y2.getCoilno()+"中"+"【材质判定结果不存在】综合判定未完成,请先执行材质检验判定后再进行综合判定!");
						return rm;
				}
			     //查询标准主表看是否存在探伤标准
//			     if (DataHelper.IsNullOrSpace(ypd2.getSpyresult())) {
//			     List<SlmOrdDesignStd> liststd = this.getMapper(SlmOrdDesignStdMapper.class).findWithCondition(null, "DESIGN_KEY='"+y2.getDesign_key()+"' and psc='"+y2.getPsc()+"'", null, 0, 0);
//			    if (liststd.size()>0) {
//			    	  if (!DataHelper.IsNullOrSpace(liststd.get(0).getDic())||! DataHelper.IsNullOrSpace(liststd.get(0).getDic_k())) {
////						     验证探伤判定结果是否存在
//						 rm.setState("403");
//						rm.setMsgInfo(y2.getCoilno()+"中"+"【探伤判定结果不存在】综合判定未完成,请先执行探伤检验判定后再进行综合判定!");
//						return rm;
//						}
//				}
//			     }
			     //验证上表检验结果是否存在
			     if (ypd2.getUp_surface_result()==null||ypd2.getUp_surface_result().equals("")) {
			    	    rm.setState("403");
						rm.setMsgInfo(y2.getCoilno()+"中"+"【上表检验结果不存在】综合判定未完成,请先执行上表检验判定后再进行综合判定!");
						return rm;
				}
//			   验证下表检验结果是否存在
			     if (ypd2.getUd_surface_result()==null||ypd2.getUd_surface_result().equals("")) {
			    	    rm.setState("403");
						rm.setMsgInfo(y2.getCoilno()+"中"+"【下表检验结果不存在】综合判定未完成,请先执行下表检验判定后再进行综合判定!");
						return rm;
				}
			   //验证边部检验结果是否存在
//			     if (ypd2.getSfe_result_desc()==null||ypd2.getSfe_result_desc().equals("")) {
//			    	    rm.setState("403");
//						rm.setMsgInfo(y2.getObject_no_pseudo()+"中"+"【边部检验结果不存在】综合判定未完成,请先执行边部检验判定后再进行综合判定!");
//						return rm;
//				}
			     //验证卡量检验结果是否存在
			     if (ypd2.getMeasure_result()==null||ypd2.getMeasure_result().equals("")) {
			    	    rm.setState("403");
						rm.setMsgInfo(y2.getCoilno()+"中"+"【卡量检验结果不存在】综合判定未完成,请先执行卡量检验判定后再进行综合判定!");
						return rm;
				}
			}
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
		}
		return rm;
	}
	
	/***
	 * 自动综合判定线程
	 */
	@Override
	public void autoJudge() {
		String configStr = this.getBean(ComBaseConfigServiceImpl.class).getConfig("QCM0006");
		if(!"1".equals(configStr)){
			return;
		}
		// 临时查找问题：可注释and COILNO = 'Y2381240P0102'
		String condition = "state='0' and judgeresult is null and COILNO = 'Y2381240P0102'";
		List<YdmProductDetail> ypd=this.getMapper(YdmProductDetailMapper.class).findWithCondition(null, condition, "createdate desc", 0, 0);
		for (YdmProductDetail y2 : ypd){			
			List<QcmJudgeUltimate> utmList = this.getMapper(QcmJudgeUltimateMapper.class).findWithCondition(null, " material_no='"+y2.getCoilno()+"'", null, 0, 0);
			if(utmList != null && utmList.size()>0){
				continue;
			}
			doAutoJudge(y2,"","","");
		}		
	}
	
	/*
	 *综合判定-自动判定
	 * 
	 * */
	@Transactional(value = "tm", rollbackFor = Exception.class)
	public ResultModel doAutoJudge(YdmProductDetail y2,String judgeResult,String judgeMemo,String judgeReson){
		ResultModel rm=new ResultModel();
		rm.setState("200");
		try {
			// 判断物料当前工序是否存在综合判定工序点
			Boolean sfFlag = false;  // 外观
			Boolean cicFlag = false; // 成分
			Boolean sicFlag = false;  // 公差
			Boolean picFlag = false;  // 材质
			Boolean dicFlag = false; // 探伤
			
			// 判断物料所有工序是否存在各工序点
			Boolean sfFlagAll = false;  // 外观
			Boolean cicFlagAll = false; // 成分
			Boolean sicFlagAll = false;  // 公差
			Boolean picFlagAll = false;  // 材质
			Boolean dicFlagAll = false; // 探伤
			
			Boolean cicResultFlag = true;
			Boolean picResultFlag = true;
			Boolean sicResultFlag = true;
			Boolean dicResultFlag = true;
			Boolean sfResultFlag = true;			
			
			// 不管当前工序有没有相应工序点，只判断有没有结果
			Boolean cicResultFlag1 = true; 
			Boolean picResultFlag1 = true;
			Boolean sicResultFlag1 = true;
			Boolean dicResultFlag1 = true;
			Boolean sfResultFlag1 = true;
			// 各项检验结果都存在时，直接进行综合判定
			if(!DataHelper.IsNullOrSpace(y2.getUp_surface_result()) 
					&& !DataHelper.IsNullOrSpace(y2.getUd_surface_result()) 
					&& !DataHelper.IsNullOrSpace(y2.getMarginal_result()) 
					&& !DataHelper.IsNullOrSpace(y2.getMeasure_result()) 
					&& !DataHelper.IsNullOrSpace(y2.getPhysresult())) {
				// 执行综合判定逻辑
				creatUltimateResult(y2,false,picFlagAll,sicFlagAll,false,sfFlagAll,judgeResult,judgeMemo,judgeReson);
				return rm;
			}
			SlmOrdDesignMscPlSti sod =  this.getBean(MesApiDesignInfoImpl.class).getPrc_Code_Of_Mat(y2.getCoilno());
			if(sod == null || DataHelper.IsNullOrSpace(sod.getProcess_code())){
				rm.setState("500");
				rm.setMsgInfo("没有找到卷号:"+y2.getCoilno()+"对应的工序信息，请确认!");
				return rm;
			}

			String condition = "and DESIGN_KEY='"+sod.getDesign_key()+"' and msc_pline='"+sod.getMsc_pline()+"' and backlog_seq='"+sod.getBacklog_seq()+"' and PROCESS_CODE='"+sod.getProcess_code()+"'";
			List<SlmOrdDesignMscPlSti> sodList = (List<SlmOrdDesignMscPlSti>) this.getMapper(SlmOrdDesignMscPlStiMapper.class).findWithCondition(null, condition, null, 0, 0);
			for (SlmOrdDesignMscPlSti sod1 : sodList) {			
				if("403201".equals(sod1.getProcess_point_type()))  // 成分
					cicFlag = true;				
				if("403202".equals(sod1.getProcess_point_type())) // 材质
					picFlag = true;				
				if("403203".equals(sod1.getProcess_point_type())) // 公差
					sicFlag = true;				
				if("403204".equals(sod1.getProcess_point_type())) // 探伤
					dicFlag = true;			
				if("403210".equals(sod1.getProcess_point_type())) // 外观表面
					sfFlag = true;
			}
			String condition2 = "and DESIGN_KEY='"+sod.getDesign_key()+"' and MSC_PLINE='"+sod.getMsc_pline()+"'";
			List<SlmOrdDesignMscPlSti> sodList2 = (List<SlmOrdDesignMscPlSti>) this.getMapper(SlmOrdDesignMscPlStiMapper.class).findWithCondition(null, condition2, null, 0, 0);
			for (SlmOrdDesignMscPlSti sod2 : sodList2) {				
				if("403201".equals(sod2.getProcess_point_type())) // 成分
					cicFlagAll = true;			
				if("403202".equals(sod2.getProcess_point_type())) // 材质
					picFlagAll = true;				
				if("403203".equals(sod2.getProcess_point_type())) // 公差
					sicFlagAll = true;				
				if("403204".equals(sod2.getProcess_point_type())) // 探伤
					dicFlagAll = true;				
				if("403210".equals(sod2.getProcess_point_type())) // 外观
					sfFlagAll = true;
			}
			// 没有材质检验工序点时，取第一次投料卷号对应的试样号作为材质检验ID
			if(!picFlagAll){
				if (DataHelper.IsNullOrSpace(y2.getPhysresult_id())){
					String conn = " and materailcoilno = '"+y2.getMaterailcoilno()+"' and smpno is not null";
					List<YdmProductDetail> ydmList= this.getMapper(YdmProductDetailMapper.class).findWithCondition(null, conn, null, 0, 0);
					if(ydmList != null && ydmList.size() > 0){
						String picID = createPhy(ydmList.get(0).getSmpno(), y2);
						YdmProductDetail ydmp = new YdmProductDetail();
						ydmp.setCoilno(y2.getCoilno());
						ydmp.setPhysresult_id(picID);
						this.getMapper(YdmProductDetailMapper.class).update(ydmp);
					}
				}				
			}
			// 取原料卷号作为成分检验ID
			if (DataHelper.IsNullOrSpace(y2.getChemresult_id())){
				YdmProductDetail ypd = new YdmProductDetail();
				ypd.setCoilno(y2.getCoilno());
				ypd.setChemresult(null);
				ypd.setChemresult_id(y2.getMaterailcoilno());
				this.getMapper(YdmProductDetailMapper.class).update(ypd);
			}
			List<Judge_Prc_Info> ydmList = this.getBean(MesApiDesignInfoImpl.class).getMatList(y2.getCoilno());
			// 判断当前工序是否为末道工序(包含综合判定工序点的最后一道工序)
			String condition1 = "and DESIGN_KEY='"+sod.getDesign_key()+"' and MSC_PLINE='"+sod.getMsc_pline()+"'";
			List<SlmOrdDesignMscPlSti> sodList1 = (List<SlmOrdDesignMscPlSti>) this.getMapper(SlmOrdDesignMscPlStiMapper.class).findWithCondition(null, condition1, "BACKLOG_SEQ DESC", 0, 0);
			if(sod.getProcess_code().equals(sodList1.get(0).getProcess_code())) { 
				// （sod.getProcess_code().equals(sodList1.get(0).getProcess_code())）2019/6/17放开限制，所有工序不管有没有综合判定工序点都要进行综合判定
				// 验证物料所在订单制程向下所包含的工序点是否都有结果
				
				// 获取所有工序集合中工序代码为当前工序代码的数据进行判断
				for(Judge_Prc_Info ydm : ydmList) {
					// 判定当前工序下所有工序点是否都有结果，没有直接return
					if(ydm.getProcess_code()!=null && ydm.getProcess_code().equals(sod.getProcess_code())) {
						// 有成分工序点且无成分检验结果
						if(cicFlag && DataHelper.IsNullOrSpace(y2.getChemresult())){
							cicResultFlag = false;
							rm.setState("500");
							rm.setMsgInfo("物料:"+y2.getCoilno()+"成分判定结果不存在，无法进行综合判定");
							return rm;
						}
						// 无成分检验结果
						if(DataHelper.IsNullOrSpace(y2.getChemresult())){
							cicResultFlag1 = false;
						}
						// 有材质工序点且无材质检验结果
						if(picFlag && DataHelper.IsNullOrSpace(y2.getPhysresult())){
							picResultFlag = false;
							rm.setState("500");
							rm.setMsgInfo("物料:"+y2.getCoilno()+"材质判定结果不存在，无法进行综合判定");
							return rm;
						}
						// 无材质检验结果
						if(DataHelper.IsNullOrSpace(y2.getPhysresult())){
							picResultFlag1 = false;
						}
						// 有公差工序点且无公差检验结果
						if(sicFlag && DataHelper.IsNullOrSpace(y2.getMeasure_result())){
							sicResultFlag = false;
							rm.setState("500");
							rm.setMsgInfo("物料:"+y2.getCoilno()+"公差判定结果不存在，无法进行综合判定");
							return rm;
						}
						// 无公差检验结果
						if(DataHelper.IsNullOrSpace(y2.getMeasure_result())){
							sicResultFlag1 = false;
						}
						// 有探伤工序点且无探伤检验结果
						if(dicFlag && DataHelper.IsNullOrSpace(y2.getSpyresult())){
							dicResultFlag = false;
							rm.setState("500");
							rm.setMsgInfo("物料:"+y2.getCoilno()+"探伤判定结果不存在，无法进行综合判定");
							return rm;
						}
						// 无探伤检验结果
						if(DataHelper.IsNullOrSpace(y2.getSpyresult())){
							dicResultFlag1 = false;
						}
						// 有表检工序点且无上表检验结果
						if(sfFlag && (DataHelper.IsNullOrSpace(y2.getUp_surface_result()))){
							sfResultFlag = false;
							rm.setState("500");
							rm.setMsgInfo("物料:"+y2.getCoilno()+"表面检验结果不存在，无法进行综合判定");
							return rm;
						}
						// 无上表检验结果
						if(DataHelper.IsNullOrSpace(y2.getUp_surface_result())){
							sfResultFlag1 = false;
						}
					}
					// 判断所有工序下包含的检验类工序点是不是都有结果
					// 有成分工序点且无成分检验结果
					if(cicFlagAll && !cicResultFlag1){
						cicResultFlag = false;
					}
					// 有材质工序点且无材质检验结果
					if(picFlagAll && !picResultFlag1){
						picResultFlag = false;
					}
					// 有公差工序点且无公差检验结果
					if(sicFlagAll && !sicResultFlag1){
						sicResultFlag = false;
					}
					// 有探伤工序点且无探伤检验结果
					if(dicFlagAll && !dicResultFlag1){
						dicResultFlag = false;
					}
					// 有表检工序点且无表检结果
					if(sfFlagAll && !sfResultFlag1){
						sfResultFlag = false;
					}
				}
				if(cicResultFlag && picResultFlag && sicResultFlag && dicResultFlag && sfResultFlag) {
					// 执行综合判定逻辑
					creatUltimateResult(y2,cicFlagAll,picFlagAll,sicFlagAll,dicFlagAll,sfFlagAll,judgeResult,judgeMemo,judgeReson);
					return rm;
				} else {
					// 通过当前物料号调用计划接口MesApiDesignInfoImpl/getMatList获取历史物料集合信息,依次从上一个工序取相关结果，取完之后进行综合判定
					List<Judge_Prc_Info> cicResultList = new ArrayList<>();
					List<Judge_Prc_Info> picResultList = new ArrayList<>();
					List<Judge_Prc_Info> sicResultList = new ArrayList<>();
					List<Judge_Prc_Info> dicResultList = new ArrayList<>();
					List<Judge_Prc_Info> sfResultList = new ArrayList<>();
					for (Judge_Prc_Info ydm : ydmList){
						if (ydm.getListSti()!=null) {
							
							for(SlmOrdDesignMscPlSti sodm : ydm.getListSti()){
								if("403201".equals(sodm.getProcess_point_type()) && !DataHelper.IsNullOrSpace(ydm.getChemresult())) {
									cicResultList.add(ydm);
								}
								if("403202".equals(sodm.getProcess_point_type()) && !DataHelper.IsNullOrSpace(ydm.getPhysresult())) {
									picResultList.add(ydm);
								}
								if("403203".equals(sodm.getProcess_point_type()) && !DataHelper.IsNullOrSpace(ydm.getMeasure_result())) {
									sicResultList.add(ydm);
								}
								if("403204".equals(sodm.getProcess_point_type()) && !DataHelper.IsNullOrSpace(ydm.getSpyresult())) {
									dicResultList.add(ydm);
								}
								if("403210".equals(sodm.getProcess_point_type()) && !DataHelper.IsNullOrSpace(ydm.getUp_surface_result())) {
									sfResultList.add(ydm);
								}
							}
						}
					}
					// 有成分工序点无结果
					if(!cicResultFlag) {
						if(cicResultList.size() == 0){
							cicResultFlag = false;
							rm.setState("500");
							rm.setMsgInfo("物料:"+y2.getCoilno()+"成分判定结果不存在，无法进行综合判定");
							return rm;
						}else if(cicResultList.size() == 1){
							// 将当前结果复制进库存表
							YdmProductDetail ypd = new YdmProductDetail();
							ypd.setCoilno(y2.getCoilno());
							ypd.setChemresult(cicResultList.get(0).getChemresult());
							ypd.setChemresult_id(cicResultList.get(0).getChemresult_id());
							this.getMapper(YdmProductDetailMapper.class).update(ypd);
						}else if(cicResultList.size() > 1){
							// 将当前结果复制进库存表
							YdmProductDetail ypd = new YdmProductDetail();
							ypd.setCoilno(y2.getCoilno());
							ypd.setChemresult(cicResultList.get(0).getChemresult());
							ypd.setChemresult_id(cicResultList.get(0).getChemresult_id());
							this.getMapper(YdmProductDetailMapper.class).update(ypd);
						}
					}
					// 有材质工序点无结果
					if(!picResultFlag) {
						if(picResultList.size() == 0){
							cicResultFlag = false;
							rm.setState("500");
							rm.setMsgInfo("物料:"+y2.getCoilno()+"材质判定结果不存在，无法进行综合判定");
							return rm;
						}else if(picResultList.size() == 1){
							// 将当前结果复制进库存表
							y2.setPhysresult(picResultList.get(0).getPhysresult());
							y2.setPhysresult_id(picResultList.get(0).getPhysresult_id());
							this.getBean(LmsQmsApiServiceImpl.class).updatePhysResultByCoilno (y2.getCoilno(), picResultList.get(0).getPhysresult(), picResultList.get(0).getPhysresult_id());
						}else if(picResultList.size() > 1){
							// 将当前结果复制进库存表
							y2.setPhysresult(picResultList.get(0).getPhysresult());
							y2.setPhysresult_id(picResultList.get(0).getPhysresult_id());
							this.getBean(LmsQmsApiServiceImpl.class).updatePhysResultByCoilno (y2.getCoilno(), picResultList.get(0).getPhysresult(), picResultList.get(0).getPhysresult_id());
						}
					}
					// 有公差工序点无结果
					if(!sicResultFlag) {
						if(sicResultList.size() == 0){
							cicResultFlag = false;
							rm.setState("500");
							rm.setMsgInfo("物料:"+y2.getCoilno()+"公差检验结果不存在，无法进行综合判定");
							return rm;
						}else if(sicResultList.size() == 1){
							// 将当前结果复制进库存表
							y2.setMeasure_result(sicResultList.get(0).getMeasure_result());
							y2.setMeasure_result_id(sicResultList.get(0).getMeasure_result_id());
							this.getBean(LmsQmsApiServiceImpl.class).updateMeaResultByCoilno(y2.getCoilno(), sicResultList.get(0).getSpyresult(), sicResultList.get(0).getSpyresult_id());
						}else if(sicResultList.size() > 1){
							// 将当前结果复制进库存表
							y2.setMeasure_result(sicResultList.get(0).getMeasure_result());
							y2.setMeasure_result_id(sicResultList.get(0).getMeasure_result_id());
							this.getBean(LmsQmsApiServiceImpl.class).updateMeaResultByCoilno(y2.getCoilno(), sicResultList.get(0).getSpyresult(), sicResultList.get(0).getSpyresult_id());
						}
					}
					// 有探伤工序点无结果
					if(!dicResultFlag) {
						if(dicResultList.size() == 0){
							cicResultFlag = false;
							rm.setState("500");
							rm.setMsgInfo("物料:"+y2.getCoilno()+"探伤检验结果不存在，无法进行综合判定");
							return rm;
						}else if(dicResultList.size() == 1){
							// 将当前结果复制进库存表
							y2.setSpyresult(dicResultList.get(0).getSpyresult());
							y2.setSpyresult_id(dicResultList.get(0).getSpyresult_id());
							this.getBean(LmsQmsApiServiceImpl.class).updateSpyResultByCoilno(y2.getCoilno(), dicResultList.get(0).getSpyresult(), dicResultList.get(0).getSpyresult_id());
						}else if(dicResultList.size() > 1){
							// 将当前结果复制进库存表
							y2.setSpyresult(dicResultList.get(0).getSpyresult());
							y2.setSpyresult_id(dicResultList.get(0).getSpyresult_id());
							this.getBean(LmsQmsApiServiceImpl.class).updateSpyResultByCoilno(y2.getCoilno(), dicResultList.get(0).getSpyresult(), dicResultList.get(0).getSpyresult_id());
						}
					}
					// 有表检工序点无结果
					if(!sfResultFlag) {
						if(sfResultList.size() == 0){
							cicResultFlag = false;
							rm.setState("500");
							rm.setMsgInfo("物料:"+y2.getCoilno()+"表面检验结果不存在，无法进行综合判定");
							return rm;
						}else if(sfResultList.size() == 1){
							// 将当前结果复制进库存表
							y2.setUp_surface_result(sfResultList.get(0).getUp_surface_result());
							y2.setUp_surface_result_id(sfResultList.get(0).getUp_surface_result_id());
							// 更新库存表上表结果
							this.getMapper(YdmProductDetailMapper.class).upresultU(sfResultList.get(0).getUp_surface_result(), y2.getCoilno(),sfResultList.get(0).getUp_surface_result_id());
							
						}else if(sfResultList.size() > 1){
							// 将当前结果复制进库存表
							y2.setUp_surface_result(sfResultList.get(0).getUp_surface_result());
							y2.setUd_surface_result_id(sfResultList.get(0).getUd_surface_result_id());
							// 更新库存表上表结果
							this.getMapper(YdmProductDetailMapper.class).upresultU(sfResultList.get(0).getUp_surface_result(), y2.getCoilno(),sfResultList.get(0).getUp_surface_result_id());
						}
					}
					// 执行综合判定逻辑
					creatUltimateResult(y2,cicFlagAll,picFlagAll,sicFlagAll,dicFlagAll,sfFlagAll,judgeResult,judgeMemo,judgeReson);
					return rm;
				}
			} else {
				// 获取所有工序集合中工序代码为当前工序代码的数据进行判断
				for(Judge_Prc_Info ydm : ydmList) {
					// 判定当前工序下所有工序点是否都有结果，没有直接return
					if(ydm.getProcess_code().equals(sod.getProcess_code())) {
						// 有成分工序点且无成分检验结果
						if(cicFlag && DataHelper.IsNullOrSpace(y2.getChemresult())){
							cicResultFlag = false;
							rm.setState("500");
							rm.setMsgInfo("物料:"+y2.getCoilno()+"成分判定结果不存在，无法进行综合判定");
							return rm;
						}
						// 有材质工序点且无材质检验结果
						if(picFlag && DataHelper.IsNullOrSpace(y2.getPhysresult())){
							picResultFlag = false;
							rm.setState("500");
							rm.setMsgInfo("物料:"+y2.getCoilno()+"材质判定结果不存在，无法进行综合判定");
							return rm;
						}
						// 有公差工序点且无公差检验结果
						if(sicFlag && DataHelper.IsNullOrSpace(y2.getMeasure_result())){
							sicResultFlag = false;
							rm.setState("500");
							rm.setMsgInfo("物料:"+y2.getCoilno()+"公差判定结果不存在，无法进行综合判定");
							return rm;
						}
						// 有探伤工序点且无探伤检验结果
						if(dicFlag && DataHelper.IsNullOrSpace(y2.getSpyresult())){
							dicResultFlag = false;
							rm.setState("500");
							rm.setMsgInfo("物料:"+y2.getCoilno()+"探伤判定结果不存在，无法进行综合判定");
							return rm;
						}
						// 有表检工序点且无上表检验结果
						if(sfFlag && (DataHelper.IsNullOrSpace(y2.getUp_surface_result()))){
							sfResultFlag = false;
							rm.setState("500");
							rm.setMsgInfo("物料:"+y2.getCoilno()+"表面检验结果不存在，无法进行综合判定");
							return rm;
						}
					}
				}
				// 判断制程中当前工序向下所包含的检验类工序点是否都有结果，如果有，进行综合判定，否则return
				if(cicResultFlag && picResultFlag && sicResultFlag && dicResultFlag && sfResultFlag){
					creatUltimateResult(y2,cicFlag,picFlag,sicFlag,dicFlag,sfFlag,judgeResult,judgeMemo,judgeReson);
					return rm;
				}else{
					String mess = "";
					if(cicResultFlag){
						mess += "成分判定结果";
					}
					if(picResultFlag){
						if("".equals(mess)){
							mess += "材质判定结果";
						}else{
							mess += ",材质判定结果";
						}
					}
					if(sicResultFlag){
						if("".equals(mess)){
							mess += "公差检验结果";
						}else{
							mess += ",公差检验结果";
						}
					}
					if(dicResultFlag){
						if("".equals(mess)){
							mess += "探伤检验结果";
						}else{
							mess += ",探伤检验结果";
						}
					}
					if(sfResultFlag){
						if("".equals(mess)){
							mess += "表面检验结果";
						}else{
							mess += ",表面检验结果";
						}
					}
					mess += "不存在，无法进行综合判定!";
					rm.setState("500");
					rm.setMsgInfo(mess);
					return rm;
				}
			}
			
		} catch (Exception e) {
			System.out.println(e.getMessage());
			rm.setState("500");
		}
		return rm;
	}
	
	private void creatUltimateResult (YdmProductDetail ypd, Boolean cicFlag,Boolean picFlag,Boolean sicFlag,Boolean dicFlag,Boolean sfFlag,String judgeResult,String judgeMemo,String judgeReson){
		Date now = new Date();
		String opr_time = new SimpleDateFormat("yyyyMMddHHmmss").format(now); //操作时间
		try {
			// 综合判定结果
			int flag = 0;
			String userName = "";
			String judgeResultDesc = "";
			Boolean handleFlag = false;			
			// 判断是手动操作还是线程操作
			if(!"".equals(judgeResult)){
				handleFlag = true;
				userName = (String)this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
				judgeResultDesc = "40740801".equals(judgeResult) ? "合格" : "不合格";
			} else {
				judgeReson = "";
				judgeMemo = "系统自动判定";
				userName = "SYSTEM";
				// 存在表检工序点时,再一次判断上表检验结果是否存在(理论上不需要判断这个。。。)
				if(sfFlag){
					if (DataHelper.IsNullOrSpace(ypd.getUp_surface_result())) {
						return;
					} else {
						flag += "40740601".equals(ypd.getUp_surface_result()) ? 0 : 1;
						judgeReson += "40740601".equals(ypd.getUp_surface_result()) ? "" : "表面";
					}
				}
				// 公差检验结果是否存在
				if(sicFlag){
					if (DataHelper.IsNullOrSpace(ypd.getMeasure_result())) {
						return;
					} else {
						flag += "40740301".equals(ypd.getMeasure_result()) ? 0 : 1;
						if ("40740302".equals(ypd.getMeasure_result())) {
							if (!"".equals(judgeReson)) {
								judgeReson += ",公差";
							} else {
								judgeReson += "公差";
							}
						}
					}
				}
				// 成分判定结果是否存在
				if(cicFlag){
					if (DataHelper.IsNullOrSpace(ypd.getChemresult())) {
						return;
					} else {
						flag += "40740101".equals(ypd.getChemresult()) ? 0 : 1;
						if ("40740102".equals(ypd.getChemresult())) {
							if (!"".equals(judgeReson)) {
								judgeReson += ",成分";
							} else {
								judgeReson += "成分";
							}
						}
					}
				}
				// 材质判定结果是否存在
				if(picFlag){
					if (DataHelper.IsNullOrSpace(ypd.getPhysresult())) {
						return;
					} else {
						flag += "40740201".equals(ypd.getPhysresult()) ? 0 : 1;
						if ("40740202".equals(ypd.getPhysresult())) {
							if (!"".equals(judgeReson)) {
								judgeReson += ",材质";
							} else {
								judgeReson += "材质";
							}
						}
					}
				}
				// 探伤判定结果是否存在
				if(dicFlag){
					if (DataHelper.IsNullOrSpace(ypd.getSpyresult())) {
						return;
					} else {
						flag += "40740401".equals(ypd.getSpyresult()) ? 0 : 1;
						if ("40740402".equals(ypd.getSpyresult())) {
							if (!"".equals(judgeReson)) {
								judgeReson += ",探伤";
							} else {
								judgeReson += "探伤";
							}
						}
					}
				}
				//综合
				if (flag > 0) {
					judgeResult = "40740802";
					judgeResultDesc = "不合格";
				} else {
					judgeResult = "40740801";
					judgeResultDesc = "合格";
				}
			}
			QcmJudgeUltimate qju=new QcmJudgeUltimate();
			//获取判定记录号当天的最大值
			int count=0;
			SimpleDateFormat sdf=new SimpleDateFormat("yyMMdd");
			String date=sdf.format(new Date());
			List<QcmJudgeUltimate> listUl=this.getMapper(QcmJudgeUltimateMapper.class).findWithCondition(null, "UTM_ID like 'Z"+date+"%'", "UTM_ID desc", 0, 1);
			if (listUl!=null&&listUl.size()>0) {
				String s=listUl.get(0).getUtm_id();
				count=Integer.parseInt(s.substring(s.length()-4,s.length()));
			}
			count++;
			String utm_id="Z"+sdf.format(new Date())+String.format("%04d",count);
			System.out.println(utm_id);
			//获取成分基本信息（检验判定记录号、检验判定结果代码、检验判定结果名称、备注信息）
//		QcmJudgeChemical qjc = this.getMapper(QcmJudgeChemicalMapper.class).getchemsampl(ypd2.getChemresult_id());
			//获取材质基本信息（检验判定记录号、检验判定结果代码、检验判定结果名称、备注信息）
//		this.getMapper(QcmJudgePhysicalUtmDMapper.class).findWithCondition(null, condition, orderBy, skipResults, maxResults)
//		QcmJudgePhysical qjp = this.getMapper(QcmJudgePhysicalMapper.class).findById(ypd2.getPhysresult_id());
			//获取卡量基本信息（检验判定记录号、检验判定结果代码、检验判定结果名称、备注信息）
			if(sicFlag){	
				QcmJudgeMeasure qjm = new QcmJudgeMeasure();
				if (!DataHelper.IsNullOrSpace(ypd.getMeasure_result_id())) {
					qjm = this.getMapper(QcmJudgeMeasureMapper.class).findById(ypd.getMeasure_result_id());
				} else {
					qjm.setSic_result_code(ypd.getMeasure_result());
					qjm.setSic_result_desc("合格");
				}
				qju.setSic_id(qjm.getSic_id());
				qju.setSic_memo(qjm.getSic_memo());
				qju.setSic_result_code(qjm.getSic_result_code());
				qju.setSic_result_desc(qjm.getSic_result_desc());
			}
			//获取上、下、边部检验基本信息（检验判定记录号、检验判定结果代码、检验判定结果名称、备注信息）
			 //获取上表信息
			if(sfFlag){				
				QcmJudgeSurface qjsU = new QcmJudgeSurface();
				if (!DataHelper.IsNullOrSpace(ypd.getUp_surface_result_id())) {
					qjsU=this.getMapper(QcmJudgeSurfaceMapper.class).getSurfaceSampleItem("U",ypd.getUp_surface_result_id());
				} else {
					qjsU.setSf_result_code(ypd.getUp_surface_result());
					qjsU.setSf_result_desc("合格");
				}
				qju.setSfu_id(qjsU.getSurface_id());
				qju.setSfu_memo(qjsU.getSf_memo());
				qju.setSfu_result_code(qjsU.getSf_result_code());
				qju.setSfu_result_desc(qjsU.getSf_result_desc());
			}
			//将数据插入到综合判定记录表QCM_JUDGE_ULTIMATE
			qju.setUtm_id(utm_id);
			qju.setHeat_no(ypd.getHeatno());
			qju.setBatch_no(ypd.getBatchno());
			qju.setInspection_lot(ypd.getInspection_lot());
			qju.setOrder_no(ypd.getOrderno());
			qju.setDesign_key(ypd.getDesign_key());
			qju.setPsc(ypd.getPsc());
			//qju.setBatch_no(batch_no);
			//检验号?
			//qju.setInspection_lot(inspection_lot);
			qju.setMaterial_no(ypd.getCoilno());
			qju.setContract_line_no(ypd.getOrderno());
			//产品规范码
			//qju.setPsc();
			//箱号？
			qju.setBox_no(ypd.getBoxno());
			//材质
			if(picFlag){
				 qju.setPic_id(ypd.getPhysresult_id());
			     qju.setPic_result_code(ypd.getPhysresult());
			     if ("40740201".equals(ypd.getPhysresult())) {
			    	 qju.setPic_result_desc("合格");
				}else {
					 qju.setPic_result_desc("不合格");
				}
			}
			//成分
			if(cicFlag){
				 qju.setCic_id(ypd.getChemresult_id());
			     qju.setCic_result_code(ypd.getChemresult());
			     if ("40740101".equals(ypd.getChemresult())) {
			    	 qju.setCic_result_desc("合格");
				}else {
					 qju.setCic_result_desc("不合格");
				}
			}
			//探伤
			if(dicFlag){
				 qju.setDic_id(ypd.getSpyresult_id());
			     qju.setDic_result_code(ypd.getSpyresult());
			     if ("40740401".equals(ypd.getSpyresult())) {
			    	 qju.setDic_result_desc("合格");
				}else {
					 qju.setDic_result_desc("不合格");
				}
			}
			qju.setUtm_result_code(judgeResult);
			qju.setUtm_memo(judgeMemo);
			qju.setUtm_result_desc(judgeResultDesc);
			qju.setUtm_reason(judgeReson);
			qju.setJudge_name(userName);
			qju.setJudge_time(new Date());
			qju.setPline_name(ypd.getPline_name());
			this.getMapper(QcmJudgeUltimateMapper.class).insert(qju);
			if(judgeResult.equals("40740802")){
				//如果综合判定结果为不合格，调用生产接口脱单
				CommonPage<PlnMaterielDetail> oci = new CommonPage<>();
				List<PlnMaterielDetail> listPln = new ArrayList<>();
				PlnMaterielDetail pln = new PlnMaterielDetail();
				pln.setObject_no(ypd.getCoilno());
				listPln.add(pln);
				oci.setObjectList(listPln);
				if(!handleFlag){
					oci.setMemo1("质量综合判定");
					this.getService(PlnMaterielDetailService.class).doMatReplaceAuto(oci);
				}else{
					this.getService(PlnMaterielDetailServiceImpl.class).doMaterialReplace(oci);
				}
			}
			//更新综合判定结果
			this.getMapper(YdmProductDetailMapper.class).updateUlJudgeResult(ypd.getCoilno(), judgeResult);
			
			//日志
			MesOprLog mol = new MesOprLog("质量管理", "综合判定管理", "自动判定", "system", opr_time, qju.getMaterial_no(), null, null, null, "判定结果:"+qju.getUtm_result_desc());
			this.getMapper(MesOprLogMapper.class).insert(mol);
		} catch (Exception e) {
			
			e.printStackTrace();
		}
	}
	
	
	
	public String createPhy(String smp_no,YdmProductDetail ypd) {
		String pic = "";
		
		String conn = "and SPECIMEN_NO = '"+smp_no+"'";
		List<QcmJhyPhyresult> qjpList = this.getMapper(QcmJhyPhyresultMapper.class).findWithCondition(null, conn, null, 0, 0);
				
		
		
		// 材质结果集编号
		int count=0;
		SimpleDateFormat sdf=new SimpleDateFormat("yyMMdd");
		String date=sdf.format(new Date());
//		获取材质结果集编号最大值
		List<QcmPhyJudgeResult> qrlist=this.getMapper(QcmPhyJudgeResultMapper.class)
				.findWithCondition(null, "PHY_ID like 'PHY"+date+"%'", "PHY_ID DESC", 0, 1);
		if(qrlist!=null&&qrlist.size()>0){
			String s=qrlist.get(0).getPhy_id();
			count=Integer.parseInt(s.substring(s.length()-4, s.length()));
		}
		count++;
		String phy_id="PHY"+sdf.format(new Date())+String.format("%04d",count);
		for(QcmJhyPhyresult qpt:qjpList){
//			插入QCM_PHY_RESULT表
			QcmPhyJudgeResult qpr=new QcmPhyJudgeResult();
			qpr.setPhy_id(phy_id);
			qpr.setGuid(qpt.getGuid());
			qpr.setSmp_no(qpt.getSpecimen_no());
//			qpr.setContract_line_no(ypd.getco);
			qpr.setInspection_lot(qpt.getSpecimen_no());
			qpr.setHeat_no(ypd.getHeatno());
			qpr.setBatch_no(ypd.getBatchno());
			qpr.setMaterial_no(ypd.getMaterailcoilno());
			qpr.setPhy_code_l(qpt.getPhy_code_l());
			qpr.setPhy_code_m(qpt.getPhy_code_m());
			qpr.setPhy_code_s(qpt.getPhy_code_s());
			qpr.setPhy_name_l(qpt.getPhy_name_l());
			qpr.setPhy_name_m(qpt.getPhy_name_m());
			qpr.setPhy_name_s(qpt.getPhy_name_s());
			qpr.setItem_code_d(qpt.getItem_code_d());
			qpr.setItem_code_s(qpt.getItem_code_s());
			qpr.setItem_code_t(qpt.getItem_code_t());
			qpr.setItem_name_d(qpt.getItem_name_d());
			qpr.setItem_name_s(qpt.getItem_name_s());
			qpr.setItem_name_t(qpt.getItem_name_t());
			qpr.setVal1(qpt.getVal1());
			qpr.setVal2(qpt.getVal2());
			qpr.setVal3(qpt.getVal3());
			qpr.setCreate_name("SYSTEM");
			qpr.setCreate_time(new Date());
			this.getMapper(QcmPhyJudgeResultMapper.class).insert(qpr);
		}
		QcmJudgePhysicalUtmM qpu=new QcmJudgePhysicalUtmM();
		QcmJudgePhysicalUtmD qpd=new QcmJudgePhysicalUtmD();
		int cou=0;
		SimpleDateFormat sd=new SimpleDateFormat("yyMMdd");
		String da=sd.format(new Date());
//		获取材质结果集编号最大值
		List<QcmJudgePhysicalUtmM> qrlis=this.getMapper(QcmJudgePhysicalUtmMMapper.class)
				.findWithCondition(null, "PIC_ID like 'P%"+da+"%'", "PIC_ID DESC", 0, 1);
		if(qrlis!=null&&qrlis.size()>0){
			String s=qrlis.get(0).getPic_id();
			cou=Integer.parseInt(s.substring(s.length()-4, s.length()));
		}
		cou++;
		pic="PIC"+sdf.format(new Date())+String.format("%04d",cou);
		qpu.setPic_id(pic);
		qpu.setPic_result_desc("合格");
		qpu.setPic_result_code("40740201");
//		qpu.setDesign_key(qptt.getDesign_key());
//		qpu.setContract_line_no(qptt.getContract_line_no());
		this.getMapper(QcmJudgePhysicalUtmMMapper.class).insert(qpu);
		// 生成QcmJudgePhysicalUtmD表数据
		qpd.setPic_id(pic);
	    qpd.setHeat_no(ypd.getHeatno());
		qpd.setBatch_no(ypd.getBatchno());
		qpd.setSmp_no("无试样号");
		qpd.setInspection_lot(ypd.getBatchno()); // 没有检验号，用批次号代替
		qpd.setDesign_key(ypd.getDesign_key());
		if (DataHelper.IsNullOrSpace(ypd.getPsc())) {
			qpd.setPsc("无psc");
		} else {
			qpd.setPsc(ypd.getPsc());
		}
		qpd.setCert_inst_code("409601");
		qpd.setCert_inst_name("检测中心");
		qpd.setSmp_type_code("409401");
		qpd.setSmp_type_name("常规");
		qpd.setJudge_result_code("40740201");
		qpd.setJudge_result_desc("合格");
		qpd.setPhy_id(phy_id);
		qpd.setJudge_ttime(new Date());
		qpd.setJudge_name("system");
		this.getMapper(QcmJudgePhysicalUtmDMapper.class).insert(qpd);
		
		return pic;
	}

	
}