/***文档注释***********************************************
 * 作者            ：      易鑫
 * 创建日期     ：2018-02-6
 * 描述            ：材质判定结果集表
 * 注意事项     ：
 * 遗留BUG   ：
 * 修改日期     ：
 * 修改人员     ：
 * 修改内容     ：
 ***********************************************************/
package market.Qms.qcm.service.impl;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import market.Com.pb.DBUtil;
import market.Com.vo.ResultModel;
import market.Lms.Warehouse.mapper.YdmProductDetailMapper;
import market.Lms.Warehouse.vo.YdmProductDetail;
import market.Qms.common.DataHelper;
import market.Qms.qcm.mapper.QcmJhyPhyresultMapper;
import market.Qms.qcm.mapper.QcmJhySampleConsignDItemMapper;
import market.Qms.qcm.mapper.QcmJhySampleConsignDMapper;
import market.Qms.qcm.mapper.QcmJhySampleROrdMapper;
import market.Qms.qcm.mapper.QcmJudgePhysicalMapper;
import market.Qms.qcm.mapper.QcmJudgePhysicalUtmDMapper;
import market.Qms.qcm.mapper.QcmJudgePhysicalUtmMMapper;
import market.Qms.qcm.mapper.QcmPhyJudgeResultMapper;
import market.Qms.qcm.service.QcmJhyPhyresultService;
import market.Qms.qcm.service.QcmJhySampleConsignDService;
import market.Qms.qcm.service.QcmJhySampleROrdService;
import market.Qms.qcm.vo.IfJhyPhyResult;
import market.Qms.qcm.vo.IfJhySampleInfoD;
import market.Qms.qcm.vo.QcmJhyPhyresult;
import market.Qms.qcm.vo.QcmJhySampleConsignD;
import market.Qms.qcm.vo.QcmJhySampleConsignDItem;
import market.Qms.qcm.vo.QcmJhySampleROrd;
import market.Qms.qcm.vo.QcmJudgePhysical;
import market.Qms.qcm.vo.QcmJudgePhysicalUtmD;
import market.Qms.qcm.vo.QcmJudgePhysicalUtmM;
import market.Qms.qcm.vo.QcmPhyJudgeResult;
import market.Qms.slmord.mapper.SlmOrdDesignStdMapper;
import market.Qms.slmord.mapper.SlmOrdDesignStdPicMapper;
import market.Qms.slmord.vo.SlmOrdDesignStd;
import market.Qms.slmord.vo.SlmOrdDesignStdPic;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

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

@Service("QcmJhyPhyresultService")
@RemoteService(path = "QcmJhyPhyresultService")
public class QcmJhyPhyresultServiceImpl extends BaseServiceImpl<QcmJhyPhyresult, Object> implements QcmJhyPhyresultService {
//	
//	/**
//	 * 创建材质判定结果集
//	 * @param listResult
//	 * @param ord
//	 * @return
//	 */
//	public List<QcmPhyJudgeResult> CreatePhyresult(List<QcmJhyPhyresult> listResult,QcmJhySampleROrd ord){
//		List<QcmPhyJudgeResult> list=new ArrayList<>();
//		List<QcmJhySampleConsignM> listm = this.getMapper(QcmJhySampleConsignMMapper.class).findWithCondition(null, "SMP_NO ='"+ord.getSmp_no()+"'", null, 0, 1);
//		for (QcmJhySampleConsignM m : listm) {
//			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 '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);
//			for (QcmJhyPhyresult qcmJhyPhyresult : listResult) {
//				QcmPhyJudgeResult result=new QcmPhyJudgeResult();
//				result.setBatch_no(ord.getBatch_no());
//				result.setContract_line_no(ord.getContract_line_no());
//				result.setCreate_name("System");
//				result.setCreate_time(new Date());
//				result.setGuid(qcmJhyPhyresult.getGuid());
//				result.setHeat_no(ord.getHeat_no());
//				result.setInspection_lot(ord.getInspection_lot());
//				result.setItem_code_d(qcmJhyPhyresult.getItem_code_d());
//				result.setItem_code_s(qcmJhyPhyresult.getItem_code_s());
//				result.setItem_code_t(qcmJhyPhyresult.getItem_code_t());
//				result.setItem_name_d(qcmJhyPhyresult.getItem_name_d());
//				result.setItem_name_s(qcmJhyPhyresult.getItem_name_s());
//				result.setItem_name_t(qcmJhyPhyresult.getItem_name_t());
//				result.setMaterial_no(m.getMaterial_no());
//				result.setPhy_code_l(qcmJhyPhyresult.getPhy_code_l());
//				result.setPhy_code_m(qcmJhyPhyresult.getPhy_code_m());
//				result.setPhy_code_s(qcmJhyPhyresult.getPhy_code_s());
//				result.setPhy_id(phy_id);
//				result.setPhy_name_l(qcmJhyPhyresult.getPhy_name_l());
//				result.setPhy_name_m(qcmJhyPhyresult.getPhy_name_m());
//				result.setPhy_name_s(qcmJhyPhyresult.getPhy_name_s());
//				result.setSmp_no(ord.getSmp_no());
//				//result.setPri();e
//				result.setVal2(qcmJhyPhyresult.getVal1());
//				result.setVal2(qcmJhyPhyresult.getVal2());
//				result.setVal3(qcmJhyPhyresult.getVal3());
//				list.add(result);
//			}
//		}
//		
//		System.out.println(list.size());
//		return list;
//	}
//	
//	/**
//	 * 创建材质判定记录
//	 * @param specNo
//	 * @param ord
//	 * @param resultId
//	 * @param pass
//	 * @return
//	 */
//	public QcmJudgePhysical CreatePhyJudgeRecord(String specNo,QcmJhySampleROrd ord,String resultId,boolean pass){
//		QcmJhySampleConsignD _consignD=new QcmJhySampleConsignD();
//		_consignD.setSmp_no(ord.getSmp_no());
//		_consignD.setSpecimen_no(specNo);
//		List<QcmJhySampleConsignD> listConsignD=this.getMapper(QcmJhySampleConsignDMapper.class).find(_consignD, 0, 0);
//		int icount=0;
//		SimpleDateFormat sdf=new SimpleDateFormat("yyMMdd");
//		String date=sdf.format(new Date());
//		List<QcmJudgePhysical> qpsl=this.getMapper(QcmJudgePhysicalMapper.class).findWithCondition(null, "PIC_ID like 'P"+date+"%'", "PIC_ID DESC", 0, 1);
//		if(qpsl!=null&&qpsl.size()>0){
//			String s=qpsl.get(0).getPic_id();
//			icount=Integer.parseInt(s.substring(s.length()-4,s.length()));
//		}
//		icount++;
//		String pic_id="P"+date+String.format("%04d",icount);
//		QcmJudgePhysical _phy=new QcmJudgePhysical();
//		_phy.setBatch_no(ord.getBatch_no());
//		_phy.setContract_line_no(ord.getContract_line_no());
//		_phy.setDesign_key(ord.getDesign_key());
//		_phy.setCert_inst_code(ord.getCert_inst_code());
//		_phy.setSmp_type_code(ord.getSmp_type_code());
//		_phy.setHeat_no(ord.getHeat_no());
//		_phy.setInspection_lot(ord.getInspection_lot());
//		_phy.setJudge_name(ord.getJudge_name());
//		_phy.setJudge_ttime(new Date());
//		_phy.setPhy_id(resultId);
//		_phy.setPic_id(pic_id);
//		_phy.setPic_memo("系统自动判定");
//		_phy.setPic_result_code(pass?"40740201":"40740202");
//		_phy.setPic_result_desc(pass?"合格":"不合格");
//		_phy.setSmp_no(ord.getSmp_no());
//		_phy.setPsc(ord.getPsc());
//		_phy.setPline_name(listConsignD.get(0).getPline_name());
//		_phy.setPline_code(listConsignD.get(0).getPline_code());
//		return _phy;
//	}
//	
//	/**
//	 * 材质自动判定
//	 */
//	@Override
//	public void AutoJudge(){
//		//获取未判定的数据
//		String condition=" Smp_type_code='409801' and Judge_status='0'";
//		QcmJhySampleROrd qjsr=new QcmJhySampleROrd();
//		List<QcmJhySampleROrd> listqjsr=new ArrayList<>();
//		int status=0;
//		List<QcmJhySampleROrd> listOrd=this.getMapper(QcmJhySampleROrdMapper.class).GetSamplePhyInfo(condition);
//		QcmJhySampleConsignDMapper consignDMapper=this.getMapper(QcmJhySampleConsignDMapper.class);
//		QcmJhySampleConsignD _consignD=new QcmJhySampleConsignD();
//		QcmJhyPhyresultMapper resultMapper=this.getMapper(QcmJhyPhyresultMapper.class);
//		for (QcmJhySampleROrd qcmJhySampleROrd : listOrd) {
//			//获取取样编号
//			_consignD.setSmp_no(qcmJhySampleROrd.getSmp_no());
//			_consignD.setInspection_lot(qcmJhySampleROrd.getInspection_lot());
//			_consignD.setHeat_no(qcmJhySampleROrd.getHeat_no());
//			List<QcmJhySampleConsignD> listConsignD=consignDMapper.find(_consignD, 0, 0);
//			//上面listConsignD 只会查出一条数据，如果有多条数据需要跟设计确认是如何进行关联的
//			
//			//获取检验信息
//			QcmJhyPhyresult _result=new QcmJhyPhyresult();
//			_result.setSpecimen_no(listConsignD.get(0).getSpecimen_no());
//			List<QcmJhyPhyresult> listResult=resultMapper.find(_result, 0, 0);
//			if (listResult.size()<1) {
//				continue;
//			}
//			
//			//查询判定标准信息
//			ResultModel model=this.getBean(SlmOrdDesignStdPicServiceImpl.class).GetOrdJudgeStdPic(qcmJhySampleROrd.getDesign_key(), qcmJhySampleROrd.getPsc(),listConsignD.get(0).getPline_code(), "000001");
//			OrdJudgeStd<SlmOrdDesignStdPic> listStdPic=(OrdJudgeStd<SlmOrdDesignStdPic>)model.getData();
//			
//			//判定开始：内控>客户>交付，出现不合格则停止继续对比  //2018-06-05 去掉‘出现不合格则停止继续对比’改为‘判内控还有交付、客户一起判，存两套结果’
//			boolean pass=true;
//			System.out.println(listStdPic.getListStdGB().get(0).getPhy_code_s());
//			if(!listStdPic.isNkQuote()&&listStdPic.getListStdNK().size()>0){
//				pass=CompareResult(listStdPic.getListStdNK(),listResult);
//				qjsr=UpdateData(listResult,qcmJhySampleROrd,pass);
//				listqjsr.add(qjsr);
//				if (qjsr.getJudge_status().equals("1")) {
//					status++;
//				}
//			}
//			if(listStdPic.getListStdGB().size()>0&&pass){
//				if (listStdPic.getListStdKH().size()>0&&pass) {
//					pass=CompareResult(listStdPic.getListStdKH(),listResult);
//				}
//				if(pass){
//					pass=CompareResult(listStdPic.getListStdGB(),listResult);
//				}
//				qjsr=UpdateData(listResult,qcmJhySampleROrd,pass);
//				listqjsr.add(qjsr);
//				if (qjsr.getJudge_status().equals("1")) {
//					status++;
//				}
//			}	
//		}
//		//判断试样号是否都已经判定完
//		int result=0;
//		QcmJudgePhysicalUtmM qpu=new QcmJudgePhysicalUtmM();
//		QcmJudgePhysicalUtmD qpd=new QcmJudgePhysicalUtmD();
//	     if (status==listOrd.size()) {
//				for (QcmJhySampleROrd q : listOrd) {
//					if (q.getJudge_result_desc().equals("合格")) {
//						result++;
//					}
//				}
//				if (result==listOrd.size()) {
//					qpu.setPic_result_desc("合格");
//					qpu.setPic_result_code("40740201");
//					qpd.setPic_result_desc("合格");
//					qpd.setPic_result_code("40740201");
//				}else {
//					qpu.setPic_result_desc("不合格");
//					qpu.setPic_result_code("40740202");
//					qpd.setPic_result_desc("不合格");
//					qpd.setPic_result_code("40740202");
//				}
//				//把对应的数据加入qcm_judge_Physical_Utm_M表中
//				for (QcmJhySampleROrd q : listOrd) {
//					//获取当日最大编号
//					int count=0;
//					SimpleDateFormat sdf=new SimpleDateFormat("yyMMdd");
//					String date=sdf.format(new Date());
////					获取材质结果集编号最大值
//					List<QcmJudgePhysicalUtmM> qrlist=this.getMapper(QcmJudgePhysicalUtmMMapper.class)
//							.findWithCondition(null, "PIC_ID like 'P%"+date+"%'", "PIC_ID DESC", 0, 1);
//					if(qrlist!=null&&qrlist.size()>0){
//						String s=qrlist.get(0).getPic_id();
//						count=Integer.parseInt(s.substring(s.length()-4, s.length()));
//					}
//					count++;
//					String pic_id="PIC"+sdf.format(new Date())+String.format("%04d",count);
//					qpu.setPic_id(pic_id);
//					qpu.setInspection_lot(q.getInspection_lot());
//					qpu.setDesign_key(q.getDesign_key());
//					qpu.setContract_line_no(q.getContract_line_no());
//					this.getMapper(QcmJudgePhysicalUtmMMapper.class).insert(qpu);
//					//把结果插入qcm_judge_Physical_Utm_M
//					qpd.setPic_id(pic_id);
//				    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.setPic_memo(q.getJudge_memo());
//					qpd.setJudge_ttime(new Date());
//					qpd.setJudge_name("system");
//					this.getMapper(QcmJudgePhysicalUtmDMapper.class).insert(qpd);
//				}
//			}
//	}
//	
//	/**
//	 * 新增判定记录与判定结果集
//	 * @param listResult
//	 * @param qcmJhySampleROrd
//	 * @param pass
//	 */
//	public QcmJhySampleROrd UpdateData(List<QcmJhyPhyresult> listResult,QcmJhySampleROrd qcmJhySampleROrd,boolean pass){
//		List<QcmPhyJudgeResult> listJudgeResult=CreatePhyresult(listResult, qcmJhySampleROrd);
//		QcmJudgePhysical phyCal=CreatePhyJudgeRecord(listResult.get(0).getSpecimen_no(),qcmJhySampleROrd,listJudgeResult.get(0).getPhy_id(),pass);
//		this.getMapper(QcmPhyJudgeResultMapper.class).insertBatch(listJudgeResult);
//		this.getMapper(QcmJudgePhysicalMapper.class).insert(phyCal);
//		
//		//修改委托为已判定
//		QcmJhySampleROrd ord=new QcmJhySampleROrd();
//		ord.setSmp_no(qcmJhySampleROrd.getSmp_no());
//		ord.setContract_line_no(qcmJhySampleROrd.getContract_line_no());
//		ord.setPsc(qcmJhySampleROrd.getPsc());
//		ord.setJudge_status("1");
//		ord.setJudge_memo(phyCal.getPic_memo());
//		ord.setJudge_name(phyCal.getJudge_name());
//		ord.setJudge_time(phyCal.getJudge_ttime());
//		ord.setJudge_result_code(phyCal.getPic_result_code());
//		ord.setJudge_result_desc(phyCal.getPic_result_desc());
//		this.getMapper(QcmJhySampleROrdMapper.class).update(ord);
//		return ord;
//	}
//	
//	/**
//	 * 获取对比结果 
//	 * @param listPic
//	 * @param listResult
//	 * @return
//	 */
//	public boolean CompareResult(List<SlmOrdDesignStdPic> listPic,List<QcmJhyPhyresult> listResult){
//		for (SlmOrdDesignStdPic stdPic : listPic) {
//			for (QcmJhyPhyresult qcmJhyPhyresult : listResult) {
//				if(stdPic.getIsjudge().equals("1")&&qcmJhyPhyresult.getPhy_code_s().equals(stdPic.getPhy_code_s())){
//					boolean pass=DataHelper.checkSignAndValue(stdPic.getStdmin_sign(), DataHelper.GetDouble(stdPic.getStdmin()), qcmJhyPhyresult.getVal1());
//					if(!pass){
//						return false;
//					}
//					pass=DataHelper.checkSignAndValue(stdPic.getStdmax_sign(), DataHelper.GetDouble(stdPic.getStdmax()), qcmJhyPhyresult.getVal1());
//					if(!pass){
//						return false;
//					}
//					break;
//				}
//			}
//		}
//		return true;
//	}
	/**
	 * 把检化验已经接受数据 进行确认操作。
	 * @throws Exception 
	 */
	@Override
	@Scheduled(cron="0/180 * * * * ?")
	@Transactional(value = "tm", rollbackFor = Exception.class)//,propagation=Propagation.REQUIRES_NEW
	public void AutoGetDesicionInfo() throws Exception{
		try {
			//A=优特钢数据库，B=检化验数据库
			//1.从A库根据状态=1（0：未发送，1：已发送，2：已确认，3：已完成）获取QCM_JHY_SAMPLE_CONSIGN_D表中的试样号集合
		    List<QcmJhySampleConsignD> listd =  this.getMapper(QcmJhySampleConsignDMapper.class).findWithCondition(null, "STATUS ='1' ", null, 0, 0);
		    List<QcmJhyPhyresult> listr=new ArrayList<>();
		    if (listd.size()>0) {
		    List<QcmJhySampleConsignD> list=new ArrayList<>();
		    //2.根据得到的试样号集合和另一个数据库中IF_JHY_SAMPLE_INFO_M。status='1'
		    //查询IF_JHY_SAMPLE_INFO_M中试样号集合并且把对应试样号对应的status='2'(0,待接收,1,已接收,2,已确认 ,3,已完成,4,已关闭) )
				  for (QcmJhySampleConsignD q : listd) {
					  QcmJhySampleConsignD qscd = findInfoM("1",q.getSmp_no(),q.getSpecimen_no());
				    	if (qscd.getSmp_no()!=null) {
				    		list.add(qscd);
						} 
				}
		       for (QcmJhySampleConsignD q : list) {
		    	   updateStatus("2",q.getSmp_no(),q.getSpecimen_no());
		       }
		       //3.根据得到的status=2和试样号集合改变A库QCM_JHY_SAMPLE_CONSIGN_D表并把查询到的试样号对应的状态改为2
		       List<QcmJhySampleConsignD> list2=new ArrayList<>();
		        for (QcmJhySampleConsignD q : list) {
		        	QcmJhySampleConsignD qscd = findInfoM("2",q.getSmp_no(),q.getSpecimen_no());
		        	if (qscd.getSmp_no()!=null) {
			    		list2.add(qscd);
					} 
				}
		       for(QcmJhySampleConsignD q : list2) {
		        	 QcmJhySampleConsignD qsd=new QcmJhySampleConsignD();
			    	   qsd.setSmp_no(q.getSmp_no());
			    	   qsd.setStatus("2");
			    	   qsd.setSpecimen_no(q.getSpecimen_no());
			    	   this.getMapper(QcmJhySampleConsignDMapper.class).update(qsd);
			    	   //4.把B库IF_JHY_SAMPLE_INFO_M中试样号集合对应status=2改成status=3并根据此条件查询if_jhy_phy_result表获取数据
//			    	   this.getBean(PbModelDbServiceImpl.class).updateStatus("3",q.getSmp_no(),q.getSpecimen_no());
				}

				//有线程同步状态3的数据，这里注释掉，方便代码修改
//		        List<QcmJhySampleConsignD> list3 = new ArrayList<>();
//		        for (QcmJhySampleConsignD q : list2) {
//		        	QcmJhySampleConsignD qjsc = this.getBean(PbModelDbServiceImpl.class).findInfoM("3",q.getSmp_no(),q.getSpecimen_no());
//		        	if (qjsc.getSmp_no()!=null) {
//			    		list3.add(qjsc);
//					}
//				}
//		        for (QcmJhySampleConsignD q : list3) {
//		        	 List<QcmJhyPhyresult> listqpr = this.getBean(PbModelDbServiceImpl.class).findResultInfo(q.getSpecimen_no());
//			    	  for (QcmJhyPhyresult qpr : listqpr) {
//		        	 if (qpr!=null) {
//			    		   if (qpr.getSpecimen_no()!=null && qpr.getSpecimen_no()!="") {
//			    			   listr.add(qpr);
//						}
//					}
//			    	  }
//			    	   if (listr.size()<=0) {
//						return ;
//					}
//			    	   //判断取样编号对应的检验项目是否都已经做完试样，并且都有实测值
//			    	   int num=0;
//			    	   List<QcmJhySampleConsignDItem> listjscd = this.getBean(PbModelDbServiceImpl.class).findDInfo(q.getSpecimen_no());
//			    	    for (QcmJhySampleConsignDItem qcd : listjscd) {
//							String conn="specimen_no='"+qcd.getSpecimen_no()+"'";
//							if (!DataHelper.IsNullOrSpace(qcd.getPhy_code_l())) {
//								conn+="and phy_code_l='"+qcd.getPhy_code_l()+"'";
//							}
//							if (!DataHelper.IsNullOrSpace(qcd.getPhy_code_m())) {
//								conn+="and phy_code_m='"+qcd.getPhy_code_m()+"'";
//							}
//							if (!DataHelper.IsNullOrSpace(qcd.getPhy_code_s())) {
//								conn+="and phy_code_s='"+qcd.getPhy_code_s()+"'";
//							}
//							if (!DataHelper.IsNullOrSpace(qcd.getItem_code_d())) {
//								conn+="and item_code_d='"+qcd.getItem_code_d()+"'";
//							}
//							if (!DataHelper.IsNullOrSpace(qcd.getItem_code_t())) {
//								conn+="and item_code_t='"+qcd.getItem_code_t()+"'";
//							}
//							if (!DataHelper.IsNullOrSpace(qcd.getItem_code_s())) {
//								conn+="and item_code_s='"+qcd.getItem_code_s()+"'";
//							}
//							List<IfJhyPhyResult> listjpr = this.getBean(PbModelDbServiceImpl.class).findinforesult(conn);
//						    if (listjpr!=null&&listjpr.size()>0) {
//						    	if (!DataHelper.IsNullOrSpace(listjpr.get(0).getVal1())||!DataHelper.IsNullOrSpace(listjpr.get(0).getVal2())||!DataHelper.IsNullOrSpace(listjpr.get(0).getVal3())) {
//									num++;
//								}
//						    	else {//如果为false，则考虑特殊情况（判断该取样编号的项目同组号向下其他项目是否有值，如有也可取回）
//									boolean flag = this.getBean(PbModelDbServiceImpl.class).findResultByGroupAndSpecimen_no(qcd.getSpecimen_no(),listjpr.get(0).getGroup_seq());
//								    if (flag) {
//								    	num++;
//									}
//								}
//							}
//			    	    }
//			    	    if (num==listjscd.size()) {
//						}else {
//							continue;
//						}
//			    	   for (QcmJhyPhyresult p : listr) {
//			    		   this.getMapper(QcmJhyPhyresultMapper.class).insert(p);
//					   }
//		        	QcmJhySampleConsignD qsd=new QcmJhySampleConsignD();
//			    	   qsd.setSmp_no(q.getSmp_no());
//			    	   qsd.setStatus("3");
//			    	   qsd.setSpecimen_no(q.getSpecimen_no());
//			    	   this.getMapper(QcmJhySampleConsignDMapper.class).update(qsd);
//			    	 //6.把数据插入A库后把B库IF_JHY_SAMPLE_INFO_M表中的status改为4
//			    	   this.getBean(PbModelDbServiceImpl.class).updateStatus("4", q.getSmp_no(),q.getSpecimen_no());
//				}
		      }
		} catch (Exception e) {
			// TODO: handle exception
			System.out.println(e.getMessage());
			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
		}
		
	}
	/**
	 * 自动获取检化验数据库数据（只扫描检化验数据库关系表中状态等于3的数据进行写我们这边的结果表）
	 */
	@Scheduled(cron="0/180 * * * * ?")
	@Transactional(value = "tm", rollbackFor = Exception.class)
	public void AutoGetDesicionInfo1(){
		try {
			 List<QcmJhySampleConsignD> qjsc = findInfoM1("3");
	   	  for (QcmJhySampleConsignD q : qjsc) {
	   		List<QcmJhyPhyresult> listr=new ArrayList<>();
	   		List<QcmJhyPhyresult> listqpr = findResultInfo(q.getSpecimen_no());
	   		  for (QcmJhyPhyresult qpr : listqpr) {
	   		   if (qpr!=null) {
		    		   if (qpr.getSpecimen_no()!=null && qpr.getSpecimen_no()!="") {
		    			   listr.add(qpr);
					}
				}
	   		  }
		    	   if (listr.size()<=0) {
					TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
				}
		    	 //判断取样编号对应的检验项目是否都已经做完试样，并且都有实测值
		    	   int num=0;
		    	   List<QcmJhySampleConsignDItem> listjscd = findDInfo(q.getSpecimen_no());
		    	    for (QcmJhySampleConsignDItem qcd : listjscd) {
						String conn="specimen_no='"+qcd.getSpecimen_no()+"'";
						if (!DataHelper.IsNullOrSpace(qcd.getPhy_code_l())) {
							conn+="and phy_code_l='"+qcd.getPhy_code_l()+"'";
						}
						if (!DataHelper.IsNullOrSpace(qcd.getPhy_code_m())) {
							conn+="and phy_code_m='"+qcd.getPhy_code_m()+"'";
						}
						if (!DataHelper.IsNullOrSpace(qcd.getPhy_code_s())) {
							conn+="and phy_code_s='"+qcd.getPhy_code_s()+"'";
						}
						if (!DataHelper.IsNullOrSpace(qcd.getItem_code_d())) {
							conn+="and item_code_d='"+qcd.getItem_code_d()+"'";
						}
						if (!DataHelper.IsNullOrSpace(qcd.getItem_code_t())) {
							conn+="and item_code_t='"+qcd.getItem_code_t()+"'";
						}
						if (!DataHelper.IsNullOrSpace(qcd.getItem_code_s())) {
							conn+="and item_code_s='"+qcd.getItem_code_s()+"'";
						}
						List<IfJhyPhyResult> listjpr = findinforesult(conn);
					    if (listjpr!=null&&listjpr.size()>0) {
					    	if (!DataHelper.IsNullOrSpace(listjpr.get(0).getVal1())||!DataHelper.IsNullOrSpace(listjpr.get(0).getVal2())||!DataHelper.IsNullOrSpace(listjpr.get(0).getVal3())) {
								num++;
							}
					    	else {//如果为false，则考虑特殊情况（判断该取样编号的项目同组号向下其他项目是否有值，如有也可取回）
					    		//如果组号为空则不进行累加
					    		if (!DataHelper.IsNullOrSpace(listjpr.get(0).getGroup_seq())) {
					    			boolean flag = findResultByGroupAndSpecimen_no(qcd.getSpecimen_no(),listjpr.get(0).getGroup_seq());
								    if (flag) {
								    	num++;
									}
								}
							}
						}
		    	    }
		    	    if (num==listjscd.size()) {
					}else {
						continue;
					}
		    	   for (QcmJhyPhyresult p : listr) {
		    		   this.getMapper(QcmJhyPhyresultMapper.class).insert(p);
				}
	       	QcmJhySampleConsignD qsd=new QcmJhySampleConsignD();
		    	   qsd.setSmp_no(q.getSmp_no());
		    	   qsd.setStatus("3");
		    	   qsd.setSpecimen_no(q.getSpecimen_no());
		    	   this.getMapper(QcmJhySampleConsignDMapper.class).update(qsd);
		    	 //6.把数据插入A库后把B库IF_JHY_SAMPLE_INFO_M表中的status改为4
		    	   updateStatus("4", q.getSmp_no(),q.getSpecimen_no());
	   	    }
	   	  } catch (Exception e) {
			// TODO: handle exception
	   		TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
		}
		
	}
	/**
	 * 从检化验数据库扫描中间表等于5的数据，判断是否和我们这边业务等于1的数据保持一致，不一致则把业务数据状态改为1
	 * @throws Exception 
	 */
	@Override
	@Scheduled(cron="0/180 * * * * ?")
	@Transactional(value = "tm", rollbackFor = Exception.class)//,propagation=Propagation.REQUIRES_NEW
	public void AutoGetDesicionInfo2() throws Exception{
		try {
			//A=优特钢数据库，B=检化验数据库
			//扫描中间表获取m表中状态等于的数据
		   List<QcmJhySampleConsignD> findInfoM1 = findInfoM1("5");
		    //判断业务数据状态是否等于，不等于1则改为1
		   for (QcmJhySampleConsignD qjsd : findInfoM1) {
				QcmJhySampleConsignD qjs = this.getMapper(QcmJhySampleConsignDMapper.class).findById(qjsd.getSmp_no(),qjsd.getSpecimen_no());
			    if (qjs!=null&&"1".equals(qjs.getStatus())) {
					continue;
				}else {
				 QcmJhySampleConsignD  qjsc=new QcmJhySampleConsignD();
				 qjsc.setSmp_no(qjsd.getSmp_no());
				 qjsc.setSpecimen_no(qjsd.getSpecimen_no());
				 qjsc.setStatus("1");
				 this.getMapper(QcmJhySampleConsignDMapper.class).update(qjsc);
				}
		   }
		} catch (Exception e) {
			// TODO: handle exception
			System.out.println(e.getMessage());
			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
		}
		
	}
	
	/**
	 * 创建材质判定结果集
	 * @param listResult
	 * @param ord
	 * @return
	 */
	public List<QcmPhyJudgeResult> CreatePhyresult(List<QcmJhyPhyresult> listResult,QcmJhySampleROrd ord){
		List<QcmPhyJudgeResult> list=new ArrayList<>();
//		List<QcmJhySampleConsignM> listm = this.getMapper(QcmJhySampleConsignMMapper.class).findWithCondition(null, "SMP_NO ='"+ord.getSmp_no()+"'", null, 0, 1);
//		for (QcmJhySampleConsignM m : listm) {
			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 qcmJhyPhyresult : listResult) {
				System.out.println(qcmJhyPhyresult.getVal1());
				QcmPhyJudgeResult result=new QcmPhyJudgeResult();
				result.setBatch_no(ord.getBatch_no());
				List<QcmJhySampleConsignD> listcd = this.getMapper(QcmJhySampleConsignDMapper.class).findWithCondition(null, "smp_no='"+ord.getSmp_no()+"' and material_no is not null", null, 0, 0);
				if (listcd!=null&&listcd.size()>0) {
					result.setMaterial_no(listcd.get(0).getMaterial_no());
				}
				result.setContract_line_no(ord.getContract_line_no());
				result.setCreate_name("System");
				result.setCreate_time(new Date());
				result.setGuid(qcmJhyPhyresult.getGuid());
				result.setHeat_no(ord.getHeat_no());
				result.setInspection_lot(ord.getInspection_lot());
				result.setItem_code_d(qcmJhyPhyresult.getItem_code_d());
				result.setItem_code_s(qcmJhyPhyresult.getItem_code_s());
				result.setItem_code_t(qcmJhyPhyresult.getItem_code_t());
				result.setItem_name_d(qcmJhyPhyresult.getItem_name_d());
				result.setItem_name_s(qcmJhyPhyresult.getItem_name_s());
				result.setItem_name_t(qcmJhyPhyresult.getItem_name_t());
//				result.setMaterial_no(ord.getMaterial_no());
				result.setPhy_code_l(qcmJhyPhyresult.getPhy_code_l());
				result.setPhy_code_m(qcmJhyPhyresult.getPhy_code_m());
				result.setPhy_code_s(qcmJhyPhyresult.getPhy_code_s());
				result.setPhy_id(phy_id);
				result.setPhy_name_l(qcmJhyPhyresult.getPhy_name_l());
				result.setPhy_name_m(qcmJhyPhyresult.getPhy_name_m());
				result.setPhy_name_s(qcmJhyPhyresult.getPhy_name_s());
				result.setSmp_no(ord.getSmp_no());
				//result.setPri();e
				result.setVal1(qcmJhyPhyresult.getVal1());
				result.setVal2(qcmJhyPhyresult.getVal2());
				result.setVal3(qcmJhyPhyresult.getVal3());
				list.add(result);
//			}
		}
		
		System.out.println(list.size());
		return list;
	}
	
	/**
	 * 创建材质判定记录
	 * @param specNo
	 * @param ord
	 * @param resultId
	 * @param pass
	 * @return
	 */
	public QcmJudgePhysical CreatePhyJudgeRecord(String specNo,QcmJhySampleROrd ord,String resultId,boolean pass){
		QcmJhySampleConsignD _consignD=new QcmJhySampleConsignD();
		_consignD.setSmp_no(ord.getSmp_no());
		_consignD.setSpecimen_no(specNo);
//		String username=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		List<QcmJhySampleConsignD> listConsignD=this.getMapper(QcmJhySampleConsignDMapper.class).find(_consignD, 0, 0);
		
		QcmJudgePhysical _phy=new QcmJudgePhysical();
		_phy.setBatch_no(ord.getBatch_no());
		_phy.setOrder_no(ord.getOrder_no());
		_phy.setContract_line_no(ord.getContract_line_no());
//		_phy.setOrder_no(ord.getOrder_no());
		_phy.setDesign_key(ord.getDesign_key());
		_phy.setCert_inst_code(ord.getCert_inst_code());
		_phy.setCert_inst_name(ord.getCert_inst_name());
		_phy.setSmp_type_code(ord.getSmp_type_code());
		_phy.setSmp_type_name(ord.getSmp_type_name());
		_phy.setHeat_no(ord.getHeat_no());
		_phy.setInspection_lot(ord.getInspection_lot());
		_phy.setJudge_name("SYSTEM");
		_phy.setJudge_ttime(new Date());
		_phy.setPhy_id(resultId);
		_phy.setPhy_memo("系统自动判定");
		_phy.setPhy_result_code(pass?"40740201":"40740203");
		_phy.setPhy_result_desc(pass?"合格":"待判");
		_phy.setSmp_no(ord.getSmp_no());
		_phy.setPsc(ord.getPsc());
		_phy.setPline_name(listConsignD.get(0).getPline_name());
		_phy.setPline_code(listConsignD.get(0).getPline_code());
		return _phy;
	}
	/**
	 * 材质自动判定
	 */
	@Override
	@Scheduled(cron="0/60 * * * * ?")
	@Transactional(value = "tm", rollbackFor = Exception.class)
	public void AutoJudge(){
		//获取未判定的数据
		String condition=" Judge_status='0'";
		QcmJhySampleROrd qjsr=new QcmJhySampleROrd();
		List<QcmJhySampleROrd> listqjsr=new ArrayList<>();
		int status=0;
		  List<String> lists=new ArrayList<>();//异常材料处理用，用于不合格项目的备注
		List<QcmJhySampleROrd> list=this.getMapper(QcmJhySampleROrdMapper.class).GetSamplePhyInfo(condition);
		List<QcmJhySampleROrd> listOrd=new ArrayList<>();
		List<QcmJhySampleConsignDItem> qjscList = new ArrayList<>(); // 存放不合格的项目，用于自动复样
		List<String> w=new ArrayList<>();
		for (QcmJhySampleROrd o : list) {
			boolean flag=true;//判定试样号向下的取样编号是否都是已完成状态;
			List<QcmJhySampleConsignD> listd = this.getMapper(QcmJhySampleConsignDMapper.class).findWithCondition(null, "smp_no='"+o.getSmp_no()+"'", null, 0, 0);
			for (QcmJhySampleConsignD d : listd) {
				if (!d.getStatus().equals("3")) {
//					listOrd.add(o);
//					w.add(o.getSmp_no());
					flag=false;
				}
			}
			String connect="";
			if (o.getOrder_no()!=null&&!"".equals(o.getOrder_no())) {
				connect+="and ORDERNO ='"+o.getOrder_no()+"'";
			}
			if (o.getInspection_lot()!=null&&!"".equals(o.getInspection_lot())) {
				connect+="and INSPECTION_LOT ='"+o.getInspection_lot()+"'";
			}
			// 单项检验不判断锁定标识
//			List<YdmProductDetail> listqju=this.getMapper(YdmProductDetailMapper.class).findWithCondition(null, connect, null, 0,0);
//			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=false;
//					break;
//				}
//		    }
			if (flag) {
				listOrd.add(o);
			}
		}
		QcmJhySampleConsignDMapper consignDMapper=this.getMapper(QcmJhySampleConsignDMapper.class);
		QcmJhySampleConsignD _consignD=new QcmJhySampleConsignD();
		QcmJhyPhyresultMapper resultMapper=this.getMapper(QcmJhyPhyresultMapper.class);
		String pic_id="";
		for (QcmJhySampleROrd qcmJhySampleROrd : listOrd) {
			//获取取样编号
			_consignD.setSmp_no(qcmJhySampleROrd.getSmp_no());
			_consignD.setInspection_lot(qcmJhySampleROrd.getInspection_lot());
			_consignD.setHeat_no(qcmJhySampleROrd.getHeat_no());
			List<QcmJhySampleConsignD> listConsignD=consignDMapper.find(_consignD, 0, 0);
			//上面listConsignD 只会查出一条数据，如果有多条数据需要跟设计确认是如何进行关联的
			List<QcmJhyPhyresult> listResult=new ArrayList<>();
			//获取检验信息
			for (QcmJhySampleConsignD d : listConsignD) {
				QcmJhyPhyresult _result=new QcmJhyPhyresult();
				_result.setSpecimen_no(d.getSpecimen_no());
				List<QcmJhyPhyresult> listqjp=resultMapper.find(_result, 0, 0);
				if (listqjp.size()<1) {
					continue;
				}
				for (QcmJhyPhyresult q : listqjp) {
					if(DataHelper.IsNullOrSpace(q.getVal1()) && DataHelper.IsNullOrSpace(q.getVal2()) && DataHelper.IsNullOrSpace(q.getVal3())){
					}else{
						listResult.add(q);
					}
				}
				
				ResultModel resultInfo = this.getService(QcmJhySampleConsignDService.class).getResultInfo(d.getSpecimen_no());
				List<QcmJhySampleConsignDItem> listi=(List<QcmJhySampleConsignDItem>) resultInfo.getData();
				if(listi.size()<=0){
					return;
				}else{
					for (QcmJhySampleConsignDItem t : listi) {
						List<QcmJhySampleConsignDItem> qjsList = this.getMapper(QcmJhySampleConsignDItemMapper.class).findWithCondition(null, "and SPECIMEN_NO='"+t.getSpecimen_no()+"' and GROUP_SEQ='"+t.getGroup_seq()+"'", null, 0, 0);
						Boolean groupFlag = false;
						for (QcmJhySampleConsignDItem qsc : qjsList) {
							for(QcmJhySampleConsignDItem qjs1: listi){
								if(qjs1.getSpecimen_no().equals(qsc.getSpecimen_no()) && qjs1.getSeq().equals(qsc.getSeq())){
									if(!DataHelper.IsNullOrSpace(qjs1.getVal1()) || !DataHelper.IsNullOrSpace(qjs1.getVal2()) || !DataHelper.IsNullOrSpace(qjs1.getVal3())){
										groupFlag = true;
										break;
									}
								}
							}
						}
						if (DataHelper.IsNullOrSpace(t.getVal1())&&DataHelper.IsNullOrSpace(t.getVal2())&&DataHelper.IsNullOrSpace(t.getVal3()) && (DataHelper.IsNullOrSpace(t.getGroup_seq()) || !groupFlag) && !"0".equals(t.getIsjudge())) {
							return;
						}
					}
				}
			}
//			if (listResult.size()<=0) {
//				continue;
//			}
//			for (QcmJhyPhyresult r : listResult) {
//				if (DataHelper.IsNullOrSpace(r.getVal1())&&DataHelper.IsNullOrSpace(r.getVal2())&&DataHelper.IsNullOrSpace(r.getVal3())) {
//					return ;
//				}
//			}
			//获取标准和实测值（调用zj书写的接口）
			ResultModel r =querryJudgetItems(qcmJhySampleROrd.getSmp_no(), qcmJhySampleROrd.getDesign_key(), qcmJhySampleROrd.getPsc());
			List<QcmJhySampleConsignDItem> listd=(List<QcmJhySampleConsignDItem>) r.getData();
		   boolean pass=true;//是否合格
			for (QcmJhySampleConsignDItem sod : listd) {
				if(DataHelper.IsNullOrSpace(sod.getVal1()) && DataHelper.IsNullOrSpace(sod.getVal2()) && DataHelper.IsNullOrSpace(sod.getVal3())){
					continue;
				}
			   String bool0="";
			   String bool1="";
			   String bool2="";
			   String bool3="";
			   String bool4="";
			   String bool5="";
			   //最小值判定
				if (!DataHelper.IsNullOrSpace(sod.getJudge_basis())&&sod.getJudge_basis().equalsIgnoreCase("A")&&"1".equals(sod.getIsjudge())) {
					    String min =compareVal(sod.getVal1(),sod.getVal2(),sod.getVal3(), sod.getJudge_basis());
					    bool0=getJudgeColor(sod.getJf_stdmin_sign(),sod.getJf_stdmin(),min,null,null);
					    if ("2".equals(bool0)&&!lists.contains(sod.getPhy_name_l()+":"+min)) {
							lists.add(sod.getPhy_name_l()+":"+min);
						}
					    bool1=getJudgeColor(sod.getJf_stdmax_sign(),sod.getJf_stdmax(),min,null,null);
					    if ("2".equals(bool1)&&!lists.contains(sod.getPhy_name_l()+":"+min)) {
							lists.add(sod.getPhy_name_l()+":"+min);
						}
					    bool2=getJudgeColor(sod.getKh_stdmin_sign(),sod.getKh_stdmin(),min,null,null);
					    if ("2".equals(bool2)&&!lists.contains(sod.getPhy_name_l()+":"+min)) {
							lists.add(sod.getPhy_name_l()+":"+min);
						}
					    bool3=getJudgeColor(sod.getKh_stdmax_sign(),sod.getKh_stdmax(),min,null,null);
					    if ("2".equals(bool3)&&!lists.contains(sod.getPhy_name_l()+":"+min)) {
							lists.add(sod.getPhy_name_l()+":"+min);
						}
					    bool4=getJudgeColor(sod.getNk_stdmin_sign(),sod.getNk_stdmin(),min,null,null);
					    if ("2".equals(bool4)&&!lists.contains(sod.getPhy_name_l()+":"+min)) {
							lists.add(sod.getPhy_name_l()+":"+min);
						}
					    bool5=getJudgeColor(sod.getNk_stdmax_sign(),sod.getNk_stdmax(),min,null,null);
					    if ("2".equals(bool5)&&!lists.contains(sod.getPhy_name_l()+":"+min)) {
							lists.add(sod.getPhy_name_l()+":"+min);
						}
					    if ("2".equals(bool0)||"2".equals(bool1)||"2".equals(bool2)||"2".equals(bool3)||"2".equals(bool4)||"2".equals(bool5)) {
							pass=false;
							qjscList.add(sod);
						}
				}
				//最大值判定
				if (!DataHelper.IsNullOrSpace(sod.getJudge_basis())&&sod.getJudge_basis().equalsIgnoreCase("B")&&"1".equals(sod.getIsjudge())) {
				    String min = compareVal(sod.getVal1(),sod.getVal2(),sod.getVal3(), sod.getJudge_basis());
				    bool0=getJudgeColor(sod.getJf_stdmin_sign(),sod.getJf_stdmin(),min,null,null);
				    if ("2".equals(bool0)&&!lists.contains(sod.getPhy_name_l()+":"+min)) {
						lists.add(sod.getPhy_name_l()+":"+min);
					}
				    bool1=getJudgeColor(sod.getJf_stdmax_sign(),sod.getJf_stdmax(),min,null,null);
				    if ("2".equals(bool1)&&!lists.contains(sod.getPhy_name_l()+":"+min)) {
						lists.add(sod.getPhy_name_l()+":"+min);
					}
				    bool2=getJudgeColor(sod.getKh_stdmin_sign(),sod.getKh_stdmin(),min,null,null);
				    if ("2".equals(bool2)&&!lists.contains(sod.getPhy_name_l()+":"+min)) {
						lists.add(sod.getPhy_name_l()+":"+min);
					}
				    bool3=getJudgeColor(sod.getKh_stdmax_sign(),sod.getKh_stdmax(),min,null,null);
				    if ("2".equals(bool3)&&!lists.contains(sod.getPhy_name_l()+":"+min)) {
						lists.add(sod.getPhy_name_l()+":"+min);
					}
				    bool4=getJudgeColor(sod.getNk_stdmin_sign(),sod.getNk_stdmin(),min,null,null);
				    if ("2".equals(bool4)&&!lists.contains(sod.getPhy_name_l()+":"+min)) {
						lists.add(sod.getPhy_name_l()+":"+min);
					}
				    bool5=getJudgeColor(sod.getNk_stdmax_sign(),sod.getNk_stdmax(),min,null,null);
				    if ("2".equals(bool5)&&!lists.contains(sod.getPhy_name_l()+":"+min)) {
						lists.add(sod.getPhy_name_l()+":"+min);
					}
				    if ("2".equals(bool0)||"2".equals(bool1)||"2".equals(bool2)||"2".equals(bool3)||"2".equals(bool4)||"2".equals(bool5)) {
						pass=false;
						qjscList.add(sod);
					}
				}
				//平均值判定
				if (!DataHelper.IsNullOrSpace(sod.getJudge_basis())&&sod.getJudge_basis().equalsIgnoreCase("C")&&"1".equals(sod.getIsjudge())) {
					String min="";
					if (!DataHelper.IsNullOrSpace(sod.getAvg_val())) {
						min=sod.getVal1();
					}else {
					    min = compareVal(sod.getVal1(),sod.getVal2(),sod.getVal3(), sod.getJudge_basis());
					}
				    bool0=getJudgeColor(sod.getJf_stdmin_sign(),sod.getJf_stdmin(),min,null,null);
				    if ("2".equals(bool0)&&!lists.contains(sod.getPhy_name_l()+":"+min)) {
						lists.add(sod.getPhy_name_l()+":"+min);
					}
				    bool1=getJudgeColor(sod.getJf_stdmax_sign(),sod.getJf_stdmax(),min,null,null);
				    if ("2".equals(bool1)&&!lists.contains(sod.getPhy_name_l()+":"+min)) {
						lists.add(sod.getPhy_name_l()+":"+min);
					}
				    bool2=getJudgeColor(sod.getKh_stdmin_sign(),sod.getKh_stdmin(),min,null,null);
				    if ("2".equals(bool2)&&!lists.contains(sod.getPhy_name_l()+":"+min)) {
						lists.add(sod.getPhy_name_l()+":"+min);
					}
				    bool3=getJudgeColor(sod.getKh_stdmax_sign(),sod.getKh_stdmax(),min,null,null);
				    if ("2".equals(bool3)&&!lists.contains(sod.getPhy_name_l()+":"+min)) {
						lists.add(sod.getPhy_name_l()+":"+min);
					}
				    bool4=getJudgeColor(sod.getNk_stdmin_sign(),sod.getNk_stdmin(),min,null,null);
				    if ("2".equals(bool4)&&!lists.contains(sod.getPhy_name_l()+":"+min)) {
						lists.add(sod.getPhy_name_l()+":"+min);
					}
				    bool5=getJudgeColor(sod.getNk_stdmax_sign(),sod.getNk_stdmax(),min,null,null);
				    if ("2".equals(bool5)&&!lists.contains(sod.getPhy_name_l()+":"+min)) {
						lists.add(sod.getPhy_name_l()+":"+min);
					}
				    if ("2".equals(bool0)||"2".equals(bool1)||"2".equals(bool2)||"2".equals(bool3)||"2".equals(bool4)||"2".equals(bool5)) {
						pass=false;
						qjscList.add(sod);
					}
				}
				//逐项值判定
				if (DataHelper.IsNullOrSpace(sod.getJudge_basis())||sod.getJudge_basis().equalsIgnoreCase("D")&&"1".equals(sod.getIsjudge())) {
					bool0=getJudgeColor(sod.getJf_stdmin_sign(),sod.getJf_stdmin(),sod.getVal1(),sod.getVal2(),sod.getVal3());
					String str=connectVal(sod.getPhy_name_l(), sod.getVal1(),sod.getVal2(),sod.getVal3());
					if ("2".equals(bool0)&&!lists.contains(str)) {
						lists.add(str);
					}
				    bool1=getJudgeColor(sod.getJf_stdmax_sign(),sod.getJf_stdmax(),sod.getVal1(),sod.getVal2(),sod.getVal3());
				    if ("2".equals(bool1)&&!lists.contains(str)) {
						lists.add(str);
					}
				    bool2=getJudgeColor(sod.getKh_stdmin_sign(),sod.getKh_stdmin(),sod.getVal1(),sod.getVal2(),sod.getVal3());
				    if ("2".equals(bool2)&&!lists.contains(str)) {
						lists.add(str);
					}
				    bool3=getJudgeColor(sod.getKh_stdmax_sign(),sod.getKh_stdmax(),sod.getVal1(),sod.getVal2(),sod.getVal3());
				    if ("2".equals(bool3)&&!lists.contains(str)) {
						lists.add(str);
					}
				    bool4=getJudgeColor(sod.getNk_stdmin_sign(),sod.getNk_stdmin(),sod.getVal1(),sod.getVal2(),sod.getVal3());
				    if ("2".equals(bool4)&&!lists.contains(str)) {
						lists.add(str);
					}
				    bool5=getJudgeColor(sod.getNk_stdmax_sign(),sod.getNk_stdmax(),sod.getVal1(),sod.getVal2(),sod.getVal3());
				    if ("2".equals(bool5)&&!lists.contains(str)) {
						lists.add(str);
					}
				    if ("2".equals(bool0)||"2".equals(bool1)||"2".equals(bool2)||"2".equals(bool3)||"2".equals(bool4)||"2".equals(bool5)) {
						pass=false;
						qjscList.add(sod);
					}
				}
//				if ((sod.getVal1()==null||sod.getVal1().equals(""))&&(sod.getVal2()==null||sod.getVal2().equals(""))&&(sod.getVal3()==null||sod.getVal1().equals(""))) {
//			    	   sod.setJf_min_result("0");
//				       sod.setJf_max_result("0");
//				       sod.setKh_min_result("0");
//				       sod.setKh_max_result("0");
//				       sod.setNk_min_result("0");
//				       sod.setNk_max_result("0");
//				}else {
//					   sod.setJf_min_result(bool0);
//				       sod.setJf_max_result(bool1);
//				       sod.setKh_min_result(bool2);
//				       sod.setKh_max_result(bool3);
//				       sod.setNk_min_result(bool4);
//				       sod.setNk_max_result(bool5);
//				}
			}
			//查询判定标准信息
//			ResultModel model=this.getBean(SlmOrdDesignStdPicServiceImpl.class).GetOrdJudgeStdPic(qcmJhySampleROrd.getDesign_key(), qcmJhySampleROrd.getPsc(),listConsignD.get(0).getPline_code(), "000001");
//		      OrdJudgeStd<SlmOrdDesignStdPic> listStdPic= (OrdJudgeStd<SlmOrdDesignStdPic>) model.getData();
//			
//			//判定开始：内控>客户>交付，出现不合格则停止继续对比  //2018-06-05 去掉‘出现不合格则停止继续对比’改为‘判内控还有交付、客户一起判，存两套结果’
//			boolean pass=true;
//			boolean pass1=true;
//			boolean pass2=true;
//			boolean pass3=true;
//			System.out.println(listStdPic.getListStdGB().get(0).getPhy_code_s());
//			if(!listStdPic.isNkQuote()&&listStdPic.getListStdNK().size()>0){
//				pass1=CompareResult(listStdPic.getListStdNK(),listResult);
//			}
//			if(listStdPic.getListStdGB().size()>0&&pass){
//				pass2=CompareResult(listStdPic.getListStdGB(),listResult);
//			}
//			if(listStdPic.getListStdKH()!=null&&listStdPic.getListStdKH().size()>0){
//				pass3=CompareResult(listStdPic.getListStdKH(),listResult);
//			}
			if (pass) {
				qjsr=UpdateData(listResult,qcmJhySampleROrd,pass);
//				listqjsr.add(qjsr);
//				if (qjsr.getJudge_status().equals("1")) {
//					status++;
//				}
			}else {
				// 发起自动复样    "mesApiDesignInfoImpl",MesApiDesignInfoService.class
				this.getService(QcmJhySampleROrdService.class).AgainPhySendSample(qjscList, _consignD);
				//修改委托为已判定
				QcmJhySampleROrd ord=new QcmJhySampleROrd();
				ord.setSmp_no(qcmJhySampleROrd.getSmp_no());
				ord.setContract_line_no(qcmJhySampleROrd.getContract_line_no());
				ord.setPsc(qcmJhySampleROrd.getPsc());
				ord.setJudge_status("1");
//				ord.setDesign_key(qcmJhySampleROrd.getDesign_key());
				ord.setJudge_memo("系统自动判定");
				ord.setJudge_name("SYSTEM");
				ord.setJudge_time(new Date());
				ord.setJudge_result_code("40740203");
				ord.setJudge_result_desc("待判");
				this.getMapper(QcmJhySampleROrdMapper.class).update(ord);
		}
		//判断试样号是否都已经判定完
		List<QcmJhySampleROrd> listor = this.getMapper(QcmJhySampleROrdMapper.class).findInfo(qcmJhySampleROrd.getDesign_key(), "B",qcmJhySampleROrd.getInspection_lot());
		List<String> lstr=new ArrayList<>();
		 for (QcmJhySampleROrd l : listor) {
				if (!DataHelper.IsNullOrSpace(l.getJudge_result_desc())) {
					lstr.add(l.getJudge_result_desc());
				}
				else if ("40740203".equals(l.getJudge_result_desc())) {
					lstr.add("待判");
				}
				else {
					lstr.add("null");
				}
			}
		QcmJudgePhysicalUtmM qpu=new QcmJudgePhysicalUtmM();
		QcmJudgePhysicalUtmD qpd=new QcmJudgePhysicalUtmD();
		if (!lstr.contains("待判")) {
	     if (!lstr.contains("null")) {
	    	 YdmProductDetail pme=new YdmProductDetail();
	    	 if (lstr.contains("不合格")) {
					qpu.setPic_result_desc("不合格");
					qpu.setPic_result_code("40740202");
					pme.setPhysresult("40740202");
//					pme.setPic_result_desc("不合格");
				}else {
					qpu.setPic_result_desc("合格");
					qpu.setPic_result_code("40740201");
					pme.setPhysresult("40740201");
//					pme.setPic_result_desc("合格");
				}
				//把对应的数据加入qcm_judge_Physical_Utm_M表中
				int a=0;
				for (QcmJhySampleROrd q : listor) {
					//获取当日最大编号
					if (a==0) {
						int count=0;
						SimpleDateFormat sdf=new SimpleDateFormat("yyMMdd");
						String date=sdf.format(new Date());
//						获取材质结果集编号最大值
						List<QcmJudgePhysicalUtmM> qrlist=this.getMapper(QcmJudgePhysicalUtmMMapper.class)
								.findWithCondition(null, "PIC_ID like 'P%"+date+"%'", "PIC_ID DESC", 0, 1);
						if(qrlist!=null&&qrlist.size()>0){
							String s=qrlist.get(0).getPic_id();
							count=Integer.parseInt(s.substring(s.length()-4, s.length()));
						}
						count++;
					     pic_id="PIC"+sdf.format(new Date())+String.format("%04d",count);
						qpu.setPic_id(pic_id);
						qpu.setInspection_lot(q.getInspection_lot());
						qpu.setDesign_key(q.getDesign_key());
						qpu.setContract_line_no(q.getContract_line_no());
							this.getMapper(QcmJudgePhysicalUtmMMapper.class).insert(qpu);
					    a++;
					}
					qpd.setPic_id(pic_id);
				    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");
					pme.setPhysresult_id(pic_id);
					this.getMapper(QcmJudgePhysicalUtmDMapper.class).insert(qpd);
					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) {
						ypt.setPsc(q.getPsc());
						this.getMapper(YdmProductDetailMapper.class).update(ypt);
					}
					// 更新库存表材质判定结果
					this.getMapper(YdmProductDetailMapper.class).doUpdateByOrderno(q.getOrder_no(), pme.getPhysresult(), pme.getPhysresult_id(), q.getInspection_lot());
//					pme.setPic_id(pic_id);
//					pme.setPic_memo("系统自动判定");
//					this.getBean(MesApiServiceImpl.class).ModChemMatByOrder(q.getDesign_key(), null, q.getInspection_lot(), pme);
//					//异常材料处置
//					String st="";
//					if ("40740202".equals(pme.getPic_result_code())) {
//						for (String s : lists) {
//							if (!DataHelper.IsNullOrSpace(s)) {
//								st=st+s+",";
//							}
//						}
//						MaterialAbnormalTreatment(listor.get(0), st, "40740202", "不合格", "系统自动判定");
//					}
				}
				
			}
	     }
		}
	}
	/**
	 * 新增判定记录与判定结果集
	 * @param listResult
	 * @param qcmJhySampleROrd
	 * @param pass
	 */
	public QcmJhySampleROrd UpdateData(List<QcmJhyPhyresult> listResult,QcmJhySampleROrd qcmJhySampleROrd,boolean pass){
		List<QcmPhyJudgeResult> listJudgeResult=CreatePhyresult(listResult, qcmJhySampleROrd);
		QcmJudgePhysical phyCal=CreatePhyJudgeRecord(listResult.get(0).getSpecimen_no(),qcmJhySampleROrd,listJudgeResult.get(0).getPhy_id(),pass);
		String phy_id="";
		if (listJudgeResult!=null&&listJudgeResult.size()>0) {
		for (QcmPhyJudgeResult q : listJudgeResult) {
			this.getMapper(QcmPhyJudgeResultMapper.class).insert(q);
		}
		phy_id=listJudgeResult.get(0).getPhy_id();
		}
		
		this.getMapper(QcmJudgePhysicalMapper.class).insert(phyCal);
		
		//修改委托为已判定
		QcmJhySampleROrd ord=new QcmJhySampleROrd();
		ord.setPhy_id(phy_id);
		ord.setSmp_no(qcmJhySampleROrd.getSmp_no());
		ord.setContract_line_no(qcmJhySampleROrd.getContract_line_no());
		ord.setPsc(qcmJhySampleROrd.getPsc());
		ord.setJudge_status("1");
//		ord.setDesign_key(qcmJhySampleROrd.getDesign_key());
		ord.setJudge_memo(phyCal.getPhy_memo());
		ord.setJudge_name(phyCal.getJudge_name());
		ord.setJudge_time(phyCal.getJudge_ttime());
		if (pass) {
			ord.setJudge_result_code(phyCal.getPhy_result_code());
			ord.setJudge_result_desc(phyCal.getPhy_result_desc());
		}else {
//			ord.setJudge_result_code("40740202");
//			ord.setJudge_result_desc("不合格");
			ord.setJudge_result_code("40740203");
			ord.setJudge_result_desc("待判");
		}
		
		this.getMapper(QcmJhySampleROrdMapper.class).update(ord);
		return ord;
	}
	/**
	 * 为前端获取对比结果好标颜色
	 * 0 为null
	 * 1 为合格
	 * 2为不合格
	 * @param sign 符号
	 * @param qsd  标准值
	 * @param val1   实测值
	 * @param val2
	 * @param val3
	 * @return
	 */
	public String getJudgeColor(String sign,String qsd,String val1,String val2,String val3){
		boolean min1=true;
		boolean min3=true;
		boolean min2=true;
		boolean v1=true;
		boolean v2=true;
		boolean v3=true;
		boolean q=true;
		if (DataHelper.IsNullOrSpace(qsd)) {
			return "0";
		}
		if (!DataHelper.IsNullOrSpace(qsd)) {
			 q=isNumeric(qsd);
		}
		
		if (!DataHelper.IsNullOrSpace(val1)) {
			 v1=isNumeric(val1);
		}
		if (!DataHelper.IsNullOrSpace(val2)) {
			v2=isNumeric(val2);
		}
		if (!DataHelper.IsNullOrSpace(val3)) {
			v3=isNumeric(val3);
		}
		if (!q) {
			if (!DataHelper.IsNullOrSpace(val1)) {
				min1=qsd.equals(val1);
			}
			if (!DataHelper.IsNullOrSpace(val2)) {
				 min2=qsd.equals(val2);
			}
			if (!DataHelper.IsNullOrSpace(val3)) {
				min3=qsd.equals(val3);
			}
			if (DataHelper.IsNullOrSpace(val1)&&DataHelper.IsNullOrSpace(val2)&&DataHelper.IsNullOrSpace(val3)) {
				return "0";
			}
		    if (min1&&min2&&min3) {
				return "1";
			}else {
				return "2";
			}
		}
		////111111111111111
		if (!v1) {
			if (v2) {
				if (v3) {
					 min1=qsd.equals(val1);
					 min2=DataHelper.checkSignAndValue(sign, Double.parseDouble(qsd), val2);
					 min3=DataHelper.checkSignAndValue(sign, Double.parseDouble(qsd), val3);
				}else {
					 min1=qsd.equals(val1);
					 min2=DataHelper.checkSignAndValue(sign, Double.parseDouble(qsd), val2);
					 min3=qsd.equals(val3);
				}
			}else {
				if (v3) {
					 min1=qsd.equals(val1);
					 min2=qsd.equals(val2);
					 min3=DataHelper.checkSignAndValue(sign, Double.parseDouble(qsd), val3);
				}else {
					 min1=qsd.equals(val1);
					 min2=qsd.equals(val2);
					 min3=qsd.equals(val3);
				}
			}
			    if (min1&&min2&&min3) {
					return "1";
				}else {
					return "2";
				}
		}
		//2222222222222222222222222
		if (!v2) {
			if (v1) {
				if (v3) {
					 min2=qsd.equals(val2);
					 min1=DataHelper.checkSignAndValue(sign, Double.parseDouble(qsd), val1);
					 min3=DataHelper.checkSignAndValue(sign, Double.parseDouble(qsd), val3);
				}else {
					 min2=qsd.equals(val2);
					 min1=DataHelper.checkSignAndValue(sign, Double.parseDouble(qsd), val1);
					 min3=qsd.equals(val3);
				}
			}else {
				if (v3) {
					 min1=qsd.equals(val1);
					 min2=qsd.equals(val2);
					 min3=DataHelper.checkSignAndValue(sign, Double.parseDouble(qsd), val3);
				}else {
					 min1=qsd.equals(val1);
					 min2=qsd.equals(val2);
					 min3=qsd.equals(val3);
				}
			}
			    if (min1&&min2&&min3) {
					return "1";
				}else {
					return "2";
				}
		}
		
		//3333333333333333333333333
				if (!v3) {
					if (v1) {
						if (v2) {
							 min3=qsd.equals(val3);
							 min1=DataHelper.checkSignAndValue(sign, Double.parseDouble(qsd), val1);
							 min2=DataHelper.checkSignAndValue(sign, Double.parseDouble(qsd), val2);
						}else {
							 min2=qsd.equals(val2);
							 min1=DataHelper.checkSignAndValue(sign, Double.parseDouble(qsd), val1);
							 min3=qsd.equals(val3);
						}
					}else {
						if (v2) {
							 min1=qsd.equals(val1);
							 min3=qsd.equals(val3);
							 min2=DataHelper.checkSignAndValue(sign, Double.parseDouble(qsd), val2);
						}else {
							 min1=qsd.equals(val1);
							 min2=qsd.equals(val2);
							 min3=qsd.equals(val3);
						}
					}
					    if (min1&&min2&&min3) {
							return "1";
						}else {
							return "2";
						}
				}
		if (qsd!=null) {
				min1=DataHelper.checkSignAndValue(sign, Double.parseDouble(qsd), val1);
			    min2=DataHelper.checkSignAndValue(sign, Double.parseDouble(qsd), val2);
			    min3=DataHelper.checkSignAndValue(sign, Double.parseDouble(qsd), val3);
			    if (min1&&min2&&min3) {
					return "1";
				}else {
					return "2";
				}
            }else {
				return "0";
            }
	}
	/**
	 * 判断字符串是否为数字-------蒋崇波
	 * @param str
	 * @return
	 */
	public boolean isNumeric(String str){ 
		   Pattern pattern = Pattern.compile("[0-9]+([.]{1}[0-9]+){0,1}"); 
		   Matcher isNum = pattern.matcher(str);
		   if( !isNum.matches() ){
		       return false; 
		   } 
		   return true; 
		}
	/**
	 * 拼接val值----异常材料处理用---2019.1.8
	 * @param jyx
	 * @param val1
	 * @param val2
	 * @param val3
	 * @return
	 */
	public String connectVal(String jyx,String val1,String val2,String val3){
		if (!DataHelper.IsNullOrSpace(val1)) {
			if (!DataHelper.IsNullOrSpace(val2)) {
				if (!DataHelper.IsNullOrSpace(val3)) {
					jyx=jyx+":"+val1+"-"+val2+"-"+val3;
				}else {
					jyx=jyx+":"+val1+"-"+val2;
				}
			}else {
				if (!DataHelper.IsNullOrSpace(val3)) {
					jyx=jyx+":"+val1+"-"+val3;
				}else {
					jyx=jyx+":"+val1;
				}
			}
		}
		if (!DataHelper.IsNullOrSpace(val2)) {
			if (!DataHelper.IsNullOrSpace(val1)) {
				if (!DataHelper.IsNullOrSpace(val3)) {
					jyx=jyx+":"+val1+"-"+val2+"-"+val3;
				}else {
					jyx=jyx+":"+val1+"-"+val2;
				}
			}else {
				if (!DataHelper.IsNullOrSpace(val3)) {
					jyx=jyx+":"+val2+"-"+val3;
				}else {
					jyx=jyx+":"+val2;
				}
			}
		}
		if (!DataHelper.IsNullOrSpace(val3)) {
			if (!DataHelper.IsNullOrSpace(val1)) {
				if (!DataHelper.IsNullOrSpace(val2)) {
					jyx=jyx+":"+val1+"-"+val2+"-"+val3;
				}else {
					jyx=jyx+":"+val1+"-"+val3;
				}
			}else {
				if (!DataHelper.IsNullOrSpace(val2)) {
					jyx=jyx+":"+val2+"-"+val3;
				}else {
					jyx=jyx+":"+val3;
				}
			}
		}
		return jyx;
	}
	 /**
		 * 查询对应项目实测值，标准值
		 */
		public ResultModel querryJudgetItems(String smp_no, String design_key, String psc) {
			ResultModel rm = new ResultModel();

			try {

				List<QcmJhySampleConsignD> qd = this.getMapper(QcmJhySampleConsignDMapper.class).findWithCondition(null,
						"SMP_NO='" + smp_no + "'", null, 0, 0);

				List<SlmOrdDesignStdPic> itemAll = new ArrayList<SlmOrdDesignStdPic>();
				SlmOrdDesignStd std = this.getMapper(SlmOrdDesignStdMapper.class).findById(design_key, psc);
				if (std!=null) {
					List<SlmOrdDesignStdPic> pic = this.getMapper(SlmOrdDesignStdPicMapper.class).findWithCondition(null,
							"PIC='" + std.getPic() + "' and DESIGN_KEY='"+design_key+"'", null, 0, 0);
					itemAll.addAll(pic);
					if (std.getPic_k()!=null) {
						List<SlmOrdDesignStdPic> pic_k = this.getMapper(SlmOrdDesignStdPicMapper.class).findWithCondition(null,
								"PIC='" + std.getPic_k() + "'", null, 0, 0);
						itemAll.addAll(pic_k);
					}
				}
				/*if (condition) {
					
				}
				
				
				List<SlmOrdDesignStdPic> pic_n = this.getMapper(SlmOrdDesignStdPicMapper.class).findWithCondition(null,
						"PIC='" + std.getPic() + "'", null, 0, 0);
				
				itemAll.addAll(pic_n);*/
				
				

				String oldProject = null;
				String newProject = null;
				List<QcmJhySampleConsignDItem> targets=new ArrayList<QcmJhySampleConsignDItem>();
				for (QcmJhySampleConsignD qcmJhySampleConsignD : qd) {
					List<QcmJhySampleConsignDItem> items = this.getMapper(QcmJhySampleConsignDItemMapper.class)
							.findWithCondition(null, "SPECIMEN_NO='" + qcmJhySampleConsignD.getSpecimen_no() + "'", null, 0,
									0);

					for (QcmJhySampleConsignDItem qi : items) {
						oldProject = qi.getPhy_code_l() + qi.getPhy_code_m() + qi.getPhy_code_s() + qi.getItem_code_d()
								+ qi.getItem_code_s() + qi.getItem_code_t();
						//获取标准
							for (SlmOrdDesignStdPic si : itemAll) {
							newProject = si.getPhy_code_l() + si.getPhy_code_m() + si.getPhy_code_s() + si.getItem_code_d()
									+ si.getItem_code_s() + si.getItem_code_t();

							if (oldProject.equals(newProject)) {
								if ("0".equals(si.getSpecl_fl())) {
									qi.setJf_stdmax(si.getStdmax());
									qi.setJf_stdmax_sign(si.getStdmax_sign());
									qi.setJf_stdmin(si.getStdmin());
									qi.setJf_stdmin_sign(si.getStdmin_sign());
									qi.setJudge_basis(si.getJudge_basis());
									qi.setIsjudge(si.getIsjudge());
									qi.setQuote_consign_no(qcmJhySampleConsignD.getQuote_consign_no());
									qi.setOld_consign_no(qcmJhySampleConsignD.getOld_consign_no());


								} else if ("1".equals(si.getSpecl_fl())) {
									qi.setKh_stdmax(si.getStdmax());
									qi.setKh_stdmax_sign(si.getStdmax_sign());
									qi.setKh_stdmin(si.getStdmin());
									qi.setKh_stdmin_sign(si.getStdmin_sign());
									qi.setJudge_basis(si.getJudge_basis());
									qi.setIsjudge(si.getIsjudge());
									qi.setQuote_consign_no(qcmJhySampleConsignD.getQuote_consign_no());
									qi.setOld_consign_no(qcmJhySampleConsignD.getOld_consign_no());


								} else if ("2".equals(si.getSpecl_fl())) {
									qi.setNk_stdmax(si.getStdmax());
									qi.setNk_stdmax_sign(si.getStdmax_sign());
									qi.setNk_stdmin(si.getStdmin());
									qi.setNk_stdmin_sign(si.getStdmin_sign());
									qi.setJudge_basis(si.getJudge_basis());
									qi.setIsjudge(si.getIsjudge());
									qi.setQuote_consign_no(qcmJhySampleConsignD.getQuote_consign_no());
									qi.setOld_consign_no(qcmJhySampleConsignD.getOld_consign_no());

								}

							}

						}
							//获取实测值
						List<QcmJhyPhyresult> qpt = this.getMapper(QcmJhyPhyresultMapper.class).findWithCondition(null,"SPECIMEN_NO='"+qi.getSpecimen_no()+"'" , null, 0, 0);
						if (DataHelper.IsNullOrSpace(qi.getQuote_specimen_no())) {
							for (QcmJhyPhyresult qp : qpt) {
								String str = qp.getPhy_code_l() + qp.getPhy_code_m() + qp.getPhy_code_s() + qp.getItem_code_d()
								+ qp.getItem_code_s() + qp.getItem_code_t();
								if (!DataHelper.IsNullOrSpace(oldProject)&&!DataHelper.IsNullOrSpace(str)) {
									if (str.equals(oldProject)) {
										if (DataHelper.IsNullOrSpace(qi.getQuote_consign_no())) {
											qi.setVal1(qp.getVal1());
											qi.setVal2(qp.getVal2());
											qi.setVal3(qp.getVal3());
											 qi.setAvg_val(qp.getAvg_val());
										}
									}
								}
							}
						}else {//不为空则获取引用检验项目的实测值
							List<QcmJhyPhyresult> q = this.getMapper(QcmJhyPhyresultMapper.class).findWithCondition(null,"SPECIMEN_NO='"+qi.getQuote_specimen_no()+"'" , null, 0, 0); 
						    for (QcmJhyPhyresult qjp : q) {
								String qutospe=qjp.getPhy_code_l() + qjp.getPhy_code_m() + qjp.getPhy_code_s() + qjp.getItem_code_d()
								+ qjp.getItem_code_s() + qjp.getItem_code_t();
								String qutospeI=qi.getQuote_phy_code_l()+qi.getQuote_phy_code_m()+qi.getQuote_phy_code_s()+qi.getQuote_item_code_d()
							    +qi.getQuote_item_code_s()+qi.getQuote_item_code_t();
						       if (qutospe.endsWith(qutospeI)) {
						    	    qi.setVal1(qjp.getVal1());
									qi.setVal2(qjp.getVal2());
									qi.setVal3(qjp.getVal3());	
								    qi.setAvg_val(qjp.getAvg_val());
							}
						    }
						}
						qi.setSMP_TYPE_CODE(qcmJhySampleConsignD.getSmp_type_code());
						qi.setSmp_type_name(qcmJhySampleConsignD.getSmp_type_name());
					
						targets.add(qi);
					}

				
						
				
				}
				
				
				rm.setData(targets);
				rm.setState("200");

			} catch (Exception e) {
				rm.setErrorInfo(e.getMessage());
				rm.setState("500");
			}

			return rm;
		}
		/**
		 * 比较val值，根据判定依据比较
		 * @param val1
		 * @param val2
		 * @param val3
		 * @param type
		 * @return
		 */
		public String compareVal(String val1,String val2,String val3,String type){
			String flag="";
			//最小值
			if (type.equalsIgnoreCase("A")) {
				//如果val1不为空
				if (!DataHelper.IsNullOrSpace(val1)) {
					flag=val1;
					if (!DataHelper.IsNullOrSpace(val2)) {
						if (flag.compareTo(val2)>=0) {
							flag=val2;
							if (!DataHelper.IsNullOrSpace(val3)) {
								if (flag.compareTo(val3)>=0) {
									flag=val3;
								}
							}
						}else {
							if (!DataHelper.IsNullOrSpace(val3)) {
								if (flag.compareTo(val3)>=0) {
									flag=val3;
								}
							}
						}
					}else {
						if (!DataHelper.IsNullOrSpace(val3)) {
							if (flag.compareTo(val3)>=0) {
								flag=val3;
							}
						}
					}
					return flag;
				}
				//如果val1为空
				if (!DataHelper.IsNullOrSpace(val2)) {
					flag=val2;
					if (!DataHelper.IsNullOrSpace(val3)) {
						if (flag.compareTo(val3)>=0) {
							flag=val3;
						}
					}
					return flag;
				}
				//如果val1和val2都为空
				if (!DataHelper.IsNullOrSpace(val3)) {
					flag=val3;
					return flag;
				}
			}
			      //最大值
					if (type.equalsIgnoreCase("B")) {
						//如果val1不为空
						if (!DataHelper.IsNullOrSpace(val1)) {
							flag=val1;
							if (!DataHelper.IsNullOrSpace(val2)) {
								if (flag.compareTo(val2)<=0) {
									flag=val2;
									if (!DataHelper.IsNullOrSpace(val3)) {
										if (flag.compareTo(val3)<=0) {
											flag=val3;
										}
									}
								}else {
									if (!DataHelper.IsNullOrSpace(val3)) {
										if (flag.compareTo(val3)<=0) {
											flag=val3;
										}
									}
								}
							}else {
								if (!DataHelper.IsNullOrSpace(val3)) {
									if (flag.compareTo(val3)<=0) {
										flag=val3;
									}
								}
							}
							return flag;
						}
						//如果val1为空
						if (!DataHelper.IsNullOrSpace(val2)) {
							flag=val2;
							if (!DataHelper.IsNullOrSpace(val3)) {
								if (flag.compareTo(val3)<=0) {
									flag=val3;
								}
							}
							return flag;
						}
						//如果val1和val2都为空
						if (!DataHelper.IsNullOrSpace(val3)) {
							flag=val3;
							return flag;
						}
					}
			  //平均值判定
				if (type.equalsIgnoreCase("C")) {
					if (!DataHelper.IsNullOrSpace(val1)) {
						flag=val1;
						if (!DataHelper.IsNullOrSpace(val2)) {
							if (!DataHelper.IsNullOrSpace(val3)) {
								Double a=(Double.parseDouble(val1)+Double.parseDouble(val2)+Double.parseDouble(val3))/3;
							    flag=a.toString();
							}else {
								Double a=(Double.parseDouble(val1)+Double.parseDouble(val2))/2;
								flag=a.toString();
							}
						}else {
							if (!DataHelper.IsNullOrSpace(val3)) {
								Double a=(Double.parseDouble(val1)+Double.parseDouble(val3))/2;
								flag=a.toString();
							}
						}
					}else {
						if (!DataHelper.IsNullOrSpace(val2)) {
							flag=val2;
							if (!DataHelper.IsNullOrSpace(val3)) {
								Double a=(Double.parseDouble(val2)+Double.parseDouble(val3))/2;
								flag=a.toString();
							}
						}else {
							if (!DataHelper.IsNullOrSpace(val3)) {
								flag=val3;
							}
						}
					}
					return flag;
				}	
			return flag;
		}
		
//		/**
//		 * 查询if_jhy_sample_info_m表数据状态等于3的数据
//		 */
//		@TargetDataSource(dataSourceKey=DataSourceKey.DB_SLAVE3)
//		@Transactional(value="tm",rollbackFor=Exception.class,propagation=Propagation.REQUIRES_NEW)
//		public List<QcmJhySampleConsignD> findInfoM1(String sta){
////			Connection conn = null;
////			Statement st = null;
////			String strSql="select * from jhyuser.if_jhy_sample_info_m where status=?";
////			try{
////				conn = DBUtil.getConnection();
////				conn.setAutoCommit(false);	// 更改JDBC事务的默认提交方式 
////				st = conn.createStatement();
////				 PreparedStatement ps=conn.prepareStatement(strSql);
////				 ps.setString(1, sta);
////				ResultSet rs = ps.executeQuery();
////				//得到数据
////				while(rs.next()){
////					QcmJhySampleConsignD qcm=new QcmJhySampleConsignD();
////					qcm.setSmp_no(rs.getString("SMP_NO"));
////					qcm.setStatus(rs.getString("STATUS"));
////					qcm.setSpecimen_no(rs.getString("SPECIMEN_NO"));
////					listqcm.add(qcm);
////				}
////				
////				// 执行批处理sql 
////				st.executeBatch();
////				
////				conn.commit();//提交JDBC事务 
////				conn.setAutoCommit(true);// 恢复JDBC事务的默认提交方式 
////				
////			}catch(Exception ex){
////				System.out.println(ex);
////				try {
////					if(conn!=null){
////						if(!conn.isClosed()){
////							conn.rollback();
////							conn.setAutoCommit(true);
////						}
////					}
////				} catch (SQLException e) {
////					e.printStackTrace();
////				}
////			}finally{
////				try {
////					if(st!=null){
////						st.clearBatch();
////						st.close();
////					}
////				} catch (SQLException e) {
////					e.printStackTrace();
////				}
////				try {
////					if(conn!=null){
////						conn.close();
////					}
////				} catch (SQLException e) {
////					e.printStackTrace();
////				}
////			}
//			List<QcmJhySampleConsignD> listqcm=new ArrayList<>();
//			List<IfJhySampleInfoM> listm = this.getMapper(IfJhySampleInfoMMapper.class).findWithCondition(null, "status='"+sta+"'", null, 0, 0);
//			for (IfJhySampleInfoM m : listm) {
//				QcmJhySampleConsignD qcm=new QcmJhySampleConsignD();
//				qcm.setSmp_no(m.getSmp_no());
//				qcm.setStatus(m.getStatus());
//				qcm.setSpecimen_no(m.getSpecimen_no());
//				listqcm.add(qcm);
//			}
//			return listqcm;
//		}
//		/**
//		 * 获取结果实绩信息
//		 * @param spe
//		 * @return
//		 */
//		@Transactional(value="tm",rollbackFor=Exception.class,propagation=Propagation.REQUIRES_NEW)
//		public List<QcmJhyPhyresult> findResultInfo(String spe){
//			Connection conn = null;
//			Statement st = null;
//			String strSql="select * from jhyuser.if_jhy_phy_result  where SPECIMEN_NO=?";
//			try{
//				conn = DBUtil.getConnection();
//				conn.setAutoCommit(false);	// 更改JDBC事务的默认提交方式 
//				st = conn.createStatement();
//				 PreparedStatement ps=conn.prepareStatement(strSql);
//				 ps.setString(1, spe);
//				ResultSet rs = ps.executeQuery();
//				//得到数据
//				while(rs.next()){
//					QcmJhyPhyresult qcm=new QcmJhyPhyresult();
//				    qcm.setSpecimen_no(rs.getString("SPECIMEN_NO"));
//				    qcm.setSeq(rs.getLong("SEQ"));
//				    qcm.setTest_qty(rs.getLong("TEST_QTY"));
//				    qcm.setPhy_code_l(rs.getString("PHY_CODE_L"));
//				    qcm.setPhy_name_l(rs.getString("PHY_NAME_L"));
//				    qcm.setPhy_code_m(rs.getString("PHY_CODE_M"));
//				    qcm.setPhy_name_m(rs.getString("PHY_NAME_M"));
//				    qcm.setPhy_code_s(rs.getString("PHY_CODE_S"));
//				    qcm.setPhy_name_s(rs.getString("PHY_NAME_S"));
//				    qcm.setItem_code_d(rs.getString("ITEM_CODE_D"));
//				    qcm.setItem_name_d(rs.getString("ITEM_NAME_D"));
//				    qcm.setItem_code_t(rs.getString("ITEM_CODE_T"));
//				    qcm.setItem_name_t(rs.getString("ITEM_NAME_T"));
//				    qcm.setItem_code_s(rs.getString("ITEM_CODE_S"));
//				    qcm.setItem_name_s(rs.getString("ITEM_NAME_S"));
//				    qcm.setVal1(rs.getString("VAL1"));
//				    qcm.setVal2(rs.getString("VAL2"));
//				    qcm.setVal3(rs.getString("VAL3"));
//				    qcm.setGuid(rs.getString("GUID"));
//				    qcm.setCreate_name(rs.getString("CREATE_NAME"));
//				    qcm.setCreate_time(rs.getDate("CREATE_TIME"));
//				    listp.add(qcm);
//				}
//				
//				// 执行批处理sql 
//				st.executeBatch();
//				conn.commit();//提交JDBC事务 
//				conn.setAutoCommit(true);// 恢复JDBC事务的默认提交方式 
//				
//			}catch(Exception ex){
//				System.out.println(ex);
//				try {
//					if(conn!=null){
//						if(!conn.isClosed()){
//							conn.rollback();
//							conn.setAutoCommit(true);
//						}
//					}
//				} catch (SQLException e) {
//					e.printStackTrace();
//				}
//			}finally{
//				try {
//					if(st!=null){
//						st.clearBatch();
//						st.close();
//					}
//				} catch (SQLException e) {
//					e.printStackTrace();
//				}
//				try {
//					if(conn!=null){
//						conn.close();
//					}
//				} catch (SQLException e) {
//					e.printStackTrace();
//				}
//			}
////			List<QcmJhyPhyresult> listp=new ArrayList<>();
////			List<IfJhyPhyResult> listr = this.getMapper(IfJhyPhyResultMapper.class).findWithCondition(null, "specimen_no='"+spe+"'", null, 0, 0);
////			for (IfJhyPhyResult p : listr) {
////				QcmJhyPhyresult qcm=new QcmJhyPhyresult();
////			    qcm.setSpecimen_no(p.getSpecimen_no());
////			    qcm.setSeq(p.getSeq());
////			    qcm.setTest_qty(p.getTest_qty());
////			    qcm.setPhy_code_l(p.getPhy_code_l());
////			    qcm.setPhy_name_l(p.getPhy_name_l());
////			    qcm.setPhy_code_m(p.getPhy_code_m());
////			    qcm.setPhy_name_m(p.getPhy_name_m());
////			    qcm.setPhy_code_s(p.getPhy_code_s());
////			    qcm.setPhy_name_s(p.getPhy_name_s());
////			    qcm.setItem_code_d(p.getItem_code_d());
////			    qcm.setItem_name_d(p.getItem_name_d());
////			    qcm.setItem_code_t(p.getItem_code_t());
////			    qcm.setItem_name_t(p.getItem_name_t());
////			    qcm.setItem_code_s(p.getItem_code_s());
////			    qcm.setItem_name_s(p.getItem_name_s());
////			    qcm.setVal1(p.getVal1());
////			    qcm.setVal2(p.getVal2());
////			    qcm.setVal3(p.getVal3());
////			    qcm.setAvg_val(p.getAvg_val());
////			    qcm.setGuid(p.getGuid());
////			    qcm.setGroup_seq(p.getGroup_seq());
////			    qcm.setCreate_name(p.getCreate_name());
////			    qcm.setCreate_time(p.getCreate_time());
////			    listp.add(qcm);
////			}
////			return listp;
//		}
		/**
		 * 查询if_jhy_sample_info_m表数据状态等于3的数据
		 */
		@Transactional(value="tm",rollbackFor=Exception.class,propagation=Propagation.REQUIRES_NEW)
		public List<QcmJhySampleConsignD> findInfoM1(String sta){
			Connection conn = null;
			Statement st = null;
			List<QcmJhySampleConsignD> listqcm=new ArrayList<>();
			String strSql="select * from jhyuser.if_jhy_sample_info_m where status=?";
			try{
				conn = DBUtil.getConnection();
				conn.setAutoCommit(false);	// 更改JDBC事务的默认提交方式 
				st = conn.createStatement();
				 PreparedStatement ps=conn.prepareStatement(strSql);
				 ps.setString(1, sta);
				ResultSet rs = ps.executeQuery();
				//得到数据
				while(rs.next()){
					QcmJhySampleConsignD qcm=new QcmJhySampleConsignD();
					qcm.setSmp_no(rs.getString("SMP_NO"));
					qcm.setStatus(rs.getString("STATUS"));
					qcm.setSpecimen_no(rs.getString("SPECIMEN_NO"));
					listqcm.add(qcm);
				}
				
				// 执行批处理sql 
				st.executeBatch();
				
				conn.commit();//提交JDBC事务 
				conn.setAutoCommit(true);// 恢复JDBC事务的默认提交方式 
				
			}catch(Exception ex){
				System.out.println(ex);
				try {
					if(conn!=null){
						if(!conn.isClosed()){
							conn.rollback();
							conn.setAutoCommit(true);
						}
					}
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}finally{
				try {
					if(st!=null){
						st.clearBatch();
						st.close();
					}
				} catch (SQLException e) {
					e.printStackTrace();
				}
				try {
					if(conn!=null){
						conn.close();
					}
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			return listqcm;
		}
		/**
		 * 获取检化验数据库d表数据用于对比实验是否已经做完
		 * @param spe
		 * @return
		 */
		@Transactional(value="tm",rollbackFor=Exception.class,propagation=Propagation.REQUIRES_NEW)
	    public List<QcmJhySampleConsignDItem> findDInfo(String spe){
			
			Connection conn = null;
			Statement st = null;
			List<QcmJhySampleConsignDItem> listi=new ArrayList<>();
			List<IfJhySampleInfoD> listjs = new ArrayList<>();
			String strSql="select * from jhyuser.IF_JHY_SAMPLE_INFO_D where specimen_no=?";
			try{
				conn = DBUtil.getConnection();
				conn.setAutoCommit(false);	// 更改JDBC事务的默认提交方式 
				st = conn.createStatement();
				 PreparedStatement ps=conn.prepareStatement(strSql);
				 ps.setString(1, spe);
				ResultSet rs = ps.executeQuery();
				//得到数据
				while(rs.next()){
					QcmJhySampleConsignDItem q=new QcmJhySampleConsignDItem();
					q.setSpecimen_no(rs.getString("SPECIMEN_NO"));
					q.setPhy_code_l(rs.getString("phy_code_l"));
					q.setPhy_code_m(rs.getString("phy_code_m"));
					q.setPhy_code_s(rs.getString("phy_code_s"));
					q.setItem_code_d(rs.getString("item_code_d"));
					q.setItem_code_t(rs.getString("item_code_t"));
					q.setItem_code_s(rs.getString("item_code_s"));
					q.setGroup_seq(rs.getString("group_seq"));
					listi.add(q);
				}
				
				// 执行批处理sql 
				st.executeBatch();
				
				conn.commit();//提交JDBC事务 
				conn.setAutoCommit(true);// 恢复JDBC事务的默认提交方式 
				
			}catch(Exception ex){
				System.out.println(ex);
				try {
					if(conn!=null){
						if(!conn.isClosed()){
							conn.rollback();
							conn.setAutoCommit(true);
						}
					}
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}finally{
				try {
					if(st!=null){
						st.clearBatch();
						st.close();
					}
				} catch (SQLException e) {
					e.printStackTrace();
				}
				try {
					if(conn!=null){
						conn.close();
					}
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			
			 return listi;
	    }
		/**
		 * 获取结果实绩信息
		 * @param spe
		 * @return
		 */
		@Transactional(value="tm",rollbackFor=Exception.class,propagation=Propagation.REQUIRES_NEW)
		public List<QcmJhyPhyresult> findResultInfo(String spe){
			Connection conn = null;
			Statement st = null;
			List<QcmJhyPhyresult> listp=new ArrayList<>();
			String strSql="select * from jhyuser.if_jhy_phy_result  where SPECIMEN_NO=?";
			try{
				conn = DBUtil.getConnection();
				conn.setAutoCommit(false);	// 更改JDBC事务的默认提交方式 
				st = conn.createStatement();
				 PreparedStatement ps=conn.prepareStatement(strSql);
				 ps.setString(1, spe);
				ResultSet rs = ps.executeQuery();
				//得到数据
				while(rs.next()){
					QcmJhyPhyresult qcm=new QcmJhyPhyresult();
				    qcm.setSpecimen_no(rs.getString("SPECIMEN_NO"));
				    qcm.setSeq(rs.getLong("SEQ"));
				    qcm.setTest_qty(rs.getLong("TEST_QTY"));
				    qcm.setPhy_code_l(rs.getString("PHY_CODE_L"));
				    qcm.setPhy_name_l(rs.getString("PHY_NAME_L"));
				    qcm.setPhy_code_m(rs.getString("PHY_CODE_M"));
				    qcm.setPhy_name_m(rs.getString("PHY_NAME_M"));
				    qcm.setPhy_code_s(rs.getString("PHY_CODE_S"));
				    qcm.setPhy_name_s(rs.getString("PHY_NAME_S"));
				    qcm.setItem_code_d(rs.getString("ITEM_CODE_D"));
				    qcm.setItem_name_d(rs.getString("ITEM_NAME_D"));
				    qcm.setItem_code_t(rs.getString("ITEM_CODE_T"));
				    qcm.setItem_name_t(rs.getString("ITEM_NAME_T"));
				    qcm.setItem_code_s(rs.getString("ITEM_CODE_S"));
				    qcm.setItem_name_s(rs.getString("ITEM_NAME_S"));
				    qcm.setVal1(rs.getString("VAL1"));
				    qcm.setVal2(rs.getString("VAL2"));
				    qcm.setVal3(rs.getString("VAL3"));
				    qcm.setGuid(rs.getString("GUID"));
				    qcm.setCreate_name(rs.getString("CREATE_NAME"));
				    qcm.setCreate_time(rs.getDate("CREATE_TIME"));
				    listp.add(qcm);
				}
				
				// 执行批处理sql 
				st.executeBatch();
				conn.commit();//提交JDBC事务 
				conn.setAutoCommit(true);// 恢复JDBC事务的默认提交方式 
				
			}catch(Exception ex){
				System.out.println(ex);
				try {
					if(conn!=null){
						if(!conn.isClosed()){
							conn.rollback();
							conn.setAutoCommit(true);
						}
					}
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}finally{
				try {
					if(st!=null){
						st.clearBatch();
						st.close();
					}
				} catch (SQLException e) {
					e.printStackTrace();
				}
				try {
					if(conn!=null){
						conn.close();
					}
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			return listp;
		}
		/**
		 * 查询if_jhy_sample_info_m表数据
		 */
		@Transactional(value="tm",rollbackFor=Exception.class,propagation=Propagation.REQUIRES_NEW)
		public QcmJhySampleConsignD findInfoM(String sta,String smp,String specimen_no){
			QcmJhySampleConsignD qcm=new QcmJhySampleConsignD();
			Connection conn = null;
			Statement st = null;
			String strSql="select * from jhyuser.if_jhy_sample_info_m where status=? and smp_no=? and SPECIMEN_NO=?";
			try{
				conn = DBUtil.getConnection();
				conn.setAutoCommit(false);	// 更改JDBC事务的默认提交方式 
				st = conn.createStatement();
				 PreparedStatement ps=conn.prepareStatement(strSql);
				 ps.setString(1, sta);
				 ps.setString(2, smp);
				 ps.setString(3, specimen_no);
				ResultSet rs = ps.executeQuery();
				//得到数据
				while(rs.next()){
					
					qcm.setSmp_no(rs.getString("SMP_NO"));
					qcm.setStatus(rs.getString("STATUS"));
					qcm.setSpecimen_no(rs.getString("SPECIMEN_NO"));
				}
				
				// 执行批处理sql 
				st.executeBatch();
				
				conn.commit();//提交JDBC事务 
				conn.setAutoCommit(true);// 恢复JDBC事务的默认提交方式 
				
			}catch(Exception ex){
				System.out.println(ex);
				TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
				try {
					if(conn!=null){
						if(!conn.isClosed()){
							conn.rollback();
							conn.setAutoCommit(true);
						}
					}
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}finally{
				try {
					if(st!=null){
						st.clearBatch();
						st.close();
					}
				} catch (SQLException e) {
					e.printStackTrace();
				}
				try {
					if(conn!=null){
						conn.close();
					}
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			
			return qcm;
		}
		/**
		 * 修改if_jhy_sample_info_m表状态
		 */
		@Transactional(value="tm",rollbackFor=Exception.class,propagation=Propagation.REQUIRES_NEW)
		public void updateStatus(String sta,String smp,String spe){
			Connection conn = null;
			Statement st = null;
			List<QcmJhySampleConsignD> listd=new ArrayList<>();
			String strSql="update jhyuser.if_jhy_sample_info_m set status=? where smp_no=? and SPECIMEN_NO=?";
			try{
				conn = DBUtil.getConnection();
				conn.setAutoCommit(false);	// 更改JDBC事务的默认提交方式 
				st = conn.createStatement();
		         PreparedStatement ps=conn.prepareStatement(strSql);
		         ps.setString(1, sta);
		         ps.setString(2, smp);
		         ps.setString(3, spe);
				 ps.executeUpdate();
				// 执行批处理sql 
				st.executeBatch();
				conn.commit();//提交JDBC事务 
				conn.setAutoCommit(true);// 恢复JDBC事务的默认提交方式 
				
			}catch(Exception ex){
				System.out.println(ex);
				try {
					if(conn!=null){
						if(!conn.isClosed()){
							conn.rollback();
							conn.setAutoCommit(true);
						}
					}
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}finally{
				try {
					if(st!=null){
						st.clearBatch();
						st.close();
					}
				} catch (SQLException e) {
					e.printStackTrace();
				}
				try {
					if(conn!=null){
						conn.close();
					}
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}
		/**
		 * 根据取样编号和检验项目代码获取结果表中的值（用于验证是否都已经做完实验了）
		 * @param conn
		 * @return
		 */
		@Transactional(value="tm",rollbackFor=Exception.class,propagation=Propagation.REQUIRES_NEW)
	    public List<IfJhyPhyResult> findinforesult(String connection){
			List<IfJhyPhyResult> listjpr = new ArrayList<>();
			Connection conn = null;
			Statement st = null;
			String strSql="select * from jhyuser.IF_JHY_PHY_RESULT where 1 = 1 "+connection;
			try{
				conn = DBUtil.getConnection();
				conn.setAutoCommit(false);	// 更改JDBC事务的默认提交方式 
				st = conn.createStatement();
				 PreparedStatement ps=conn.prepareStatement(strSql);
				ResultSet rs = ps.executeQuery();
				//得到数据
				while(rs.next()){
					IfJhyPhyResult ipr=new IfJhyPhyResult();
					ipr.setSpecimen_no(rs.getString("specimen_no"));
					ipr.setSeq(Long.parseLong(rs.getString("seq")));
					ipr.setTest_qty(Long.parseLong(rs.getString("test_qty")));
					ipr.setPhy_code_l(rs.getString("phy_code_l"));
					ipr.setPhy_name_l(rs.getString("phy_name_l"));
					ipr.setPhy_code_m(rs.getString("phy_code_m"));
					ipr.setPhy_name_m(rs.getString("phy_name_m"));
					ipr.setPhy_code_s(rs.getString("phy_code_s"));
					ipr.setPhy_name_s(rs.getString("phy_name_s"));
					ipr.setItem_code_d(rs.getString("item_code_d"));
					ipr.setItem_name_d(rs.getString("item_name_d"));
					ipr.setItem_code_t(rs.getString("item_code_t"));
					ipr.setItem_name_t(rs.getString("item_name_t"));
					ipr.setItem_code_s(rs.getString("item_code_s"));
					ipr.setItem_name_s(rs.getString("item_name_s"));
					ipr.setVal1(rs.getString("val1"));
					ipr.setVal2(rs.getString("val2"));
					ipr.setVal3(rs.getString("val3"));
					ipr.setGroup_seq(rs.getString("group_seq"));
					listjpr.add(ipr);
				}
				
				// 执行批处理sql 
				st.executeBatch();
				
				conn.commit();//提交JDBC事务 
				conn.setAutoCommit(true);// 恢复JDBC事务的默认提交方式 
				
			}catch(Exception ex){
				System.out.println(ex);
				try {
					if(conn!=null){
						if(!conn.isClosed()){
							conn.rollback();
							conn.setAutoCommit(true);
						}
					}
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}finally{
				try {
					if(st!=null){
						st.clearBatch();
						st.close();
					}
				} catch (SQLException e) {
					e.printStackTrace();
				}
				try {
					if(conn!=null){
						conn.close();
					}
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			return listjpr;
	    }
		/**
		 * 判断取样编号下面
		 * @param spe
		 * @param group_seq
		 * @return
		 */
		@Transactional(value="tm",rollbackFor=Exception.class,propagation=Propagation.REQUIRES_NEW)
	    public boolean findResultByGroupAndSpecimen_no(String spe,String group_seq){
			boolean flag=false;
			List<IfJhyPhyResult> listjpr = new ArrayList<>();
			Connection conn = null;
			Statement st = null;
			String strSql="select * from jhyuser.IF_JHY_PHY_RESULT where specimen_no=? and  group_seq=?";
			try{
				conn = DBUtil.getConnection();
				conn.setAutoCommit(false);	// 更改JDBC事务的默认提交方式 
				st = conn.createStatement();
				 PreparedStatement ps=conn.prepareStatement(strSql);
				 ps.setString(1, spe);
		         ps.setString(2, group_seq);
				ResultSet rs = ps.executeQuery();
				//得到数据
				while(rs.next()){
					IfJhyPhyResult ipr=new IfJhyPhyResult();
					ipr.setSpecimen_no(rs.getString("specimen_no"));
					ipr.setVal1(rs.getString("val1"));
					ipr.setVal2(rs.getString("val2"));
					ipr.setVal3(rs.getString("val3"));
					ipr.setGroup_seq(rs.getString("group_seq"));
					listjpr.add(ipr);
				}
				
				// 执行批处理sql 
				st.executeBatch();
				
				conn.commit();//提交JDBC事务 
				conn.setAutoCommit(true);// 恢复JDBC事务的默认提交方式 
				
			}catch(Exception ex){
				System.out.println(ex);
				try {
					if(conn!=null){
						if(!conn.isClosed()){
							conn.rollback();
							conn.setAutoCommit(true);
						}
					}
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}finally{
				try {
					if(st!=null){
						st.clearBatch();
						st.close();
					}
				} catch (SQLException e) {
					e.printStackTrace();
				}
				try {
					if(conn!=null){
						conn.close();
					}
				} catch (SQLException e) {
					e.printStackTrace();
				}
			} 
			if (listjpr!=null&&listjpr.size()>0) {
				 for (IfJhyPhyResult q : listjpr) {
					 if (!DataHelper.IsNullOrSpace(q.getVal1())||!DataHelper.IsNullOrSpace(q.getVal2())||!DataHelper.IsNullOrSpace(q.getVal3())) {
							flag=true;
							break;
						}
				}
			}
			return flag;
	    }
		/**
		 * 把信息插入IF_JHY_SAMPLE_INFO_D
		 * 
		 * @param qjr
		 */
		public int insertInfoForD(QcmJhySampleConsignDItem qjr, java.util.Date da) {
			Connection conn = null;
			Statement st = null;
			QcmJhySampleConsignDItem qcm = qjr;
			int a = 0;
			String strSql = "insert into IF_JHY_SAMPLE_INFO_D  values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
			try {
				conn = DBUtil.getConnection();
				conn.setAutoCommit(false); // 更改JDBC事务的默认提交方式
				st = conn.createStatement();
				PreparedStatement ps = conn.prepareStatement(strSql);
				ps.setString(1, qjr.getSpecimen_no());
				ps.setLong(2, qjr.getSeq());
				ps.setString(3, qjr.getPhy_code_l());
				ps.setString(4, qjr.getPhy_name_l());
				ps.setString(5, qjr.getPhy_code_m());
				ps.setString(6, qjr.getPhy_name_m());
				ps.setString(7, qjr.getPhy_code_s());
				ps.setString(8, qjr.getPhy_name_s());
				ps.setString(9, qjr.getItem_code_d());
				ps.setString(10, qjr.getItem_name_d());
				ps.setString(11, qjr.getItem_code_t());
				ps.setString(12, qjr.getItem_name_t());
				ps.setString(13, qjr.getItem_code_s());
				ps.setString(14, qjr.getItem_name_s());
				ps.setString(15, qjr.getUnti());
				ps.setString(16, qjr.getRounding());
				ps.setString(17, qjr.getRounding());
				if (qjr.getRounding_digits()!=null) {
				ps.setLong(18, qjr.getRounding_digits());
			    }else {
//			    ps.setNull(18, Integer.parseInt(String.valueOf(qjr.getRounding_digits())));
				ps.setString(18, null);
			    }
				ps.setString(19, qjr.getCreate_name());
				ps.setTimestamp(20, new Timestamp(da.getTime()));
				ps.setString(21, qjr.getPhy_item_code());
				ps.setString(22, qjr.getPhy_item_code());
				ps.setString(23, qjr.getPhy_item_desc());
				ps.setString(24, qjr.getGroup_seq());
				a = ps.executeUpdate();
				// 执行批处理sql
				st.executeBatch();
				conn.commit();// 提交JDBC事务
				conn.setAutoCommit(true);// 恢复JDBC事务的默认提交方式

			} catch (Exception ex) {
				System.out.println(ex);
				TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
				try {
					if (conn != null) {
						if (!conn.isClosed()) {
							conn.rollback();
							conn.setAutoCommit(true);
						}
					}
				} catch (SQLException e) {
					e.printStackTrace();
				}
			} finally {
				try {
					if (st != null) {
						// st.clearBatch();
						st.close();
					}
				} catch (SQLException e) {
					e.printStackTrace();
				}
				try {
					if (conn != null) {
						conn.close();
					}
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			return a;
		}
}
