/***文档注释***********************************************
 * 作者            ：
 * 创建日期     ：2018-04-03
 * 描述            ：检验委托明细表
 * 注意事项     ：
 * 遗留BUG   ：
 * 修改日期     ：
 * 修改人员     ：
 * 修改内容     ：
 ***********************************************************/
package market.Qms.qcm.service.impl;

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.impl.PbModelDbServiceImpl;
import market.Com.mapper.ComBaseInfoMapper;
import market.Com.mapper.ComBasePhyMapper;
import market.Com.vo.ComBaseInfo;
import market.Com.vo.ComBasePhy;
import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;
import market.Lms.Warehouse.vo.YdmProductDetail;
import market.Mes.Opr.mapper.MesOprLogMapper;
import market.Mes.Opr.vo.MesOprLog;
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.QcmJhySampleConsignMMapper;
import market.Qms.qcm.mapper.QcmJhySampleROrdMapper;
import market.Qms.qcm.mapper.QcmJudgeChemicalMapper;
import market.Qms.qcm.service.QcmJhySampleConsignDService;
import market.Qms.qcm.vo.QcmJhyPhyresult;
import market.Qms.qcm.vo.QcmJhySampleConsignD;
import market.Qms.qcm.vo.QcmJhySampleConsignDItem;
import market.Qms.qcm.vo.QcmJhySampleConsignDTemp;
import market.Qms.qcm.vo.QcmJhySampleConsignM;
import market.Qms.qcm.vo.QcmJhySampleROrd;
import market.Qms.qcm.vo.QcmJudgeChemical;
import market.Qms.slmord.mapper.SlmOrdDesignMscMapper;
import market.Qms.slmord.mapper.SlmOrdDesignStdMapper;
import market.Qms.slmord.mapper.SlmOrdDesignStdPicMapper;
import market.Qms.slmord.vo.SlmOrdDesignMsc;
import market.Qms.slmord.vo.SlmOrdDesignStd;
import market.Qms.slmord.vo.SlmOrdDesignStdPic;

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;
import com.ibm.icu.text.DecimalFormat;

@RemoteService(path = "QcmJhySampleConsignDService")
public class QcmJhySampleConsignDServiceImpl extends BaseServiceImpl<QcmJhySampleConsignD, Object> implements QcmJhySampleConsignDService {	
	
	/**
	 * 成分重取样
	 * @param consignD
	 * @return
	 */
	public ResultModel AgainChemSendSample(QcmJhySampleConsignD consignD){
		ResultModel rm=new ResultModel("200","重取样成功");
		try{
			//取样编号：试样号+2位流水号
			QcmJhySampleConsignDMapper consignDMapper=this.getMapper(QcmJhySampleConsignDMapper.class);
			List<QcmJhySampleConsignD> listConsignD=consignDMapper.find(consignD, 0, 0);
			DataHelper.CopyEntity(listConsignD.get(0), consignD);
			consignD.setConsign_no(null);
			String username = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
			consignD.setSmp_type_code("409802");
			consignD.setSmp_type_name("复样");
			consignD.setQuote_consign_no(consignD.getSpecimen_no());
			if(DataHelper.IsNullOrSpace(consignD.getOld_consign_no())){
				consignD.setOld_consign_no(consignD.getSpecimen_no());
			}
			int count=0;
//			获取材质结果集编号最大值
			List<QcmJhySampleConsignD> qrlist=consignDMapper
					.findWithCondition(null, "SMP_NO ='"+consignD.getSmp_no()+"'", "SPECIMEN_NO DESC", 0, 1);
			if(qrlist!=null&&qrlist.size()>0){
				String s=qrlist.get(0).getSpecimen_no();
				count=Integer.parseInt(s.substring(s.length()-2, s.length()));
			}
			count++;
			String specimen_no=consignD.getSmp_no()+String.format("%02d",count);
			consignD.setSpecimen_no(specimen_no);
			consignD.setCreate_name(username);
			consignD.setCreate_time(new Date());
			consignD.setUpdate_name(null);
			consignD.setUpdate_time(null);
			consignD.setStatus("0");
			consignD.setValidflag("1");
			consignDMapper.insert(consignD);
			
		}catch(Exception ex){ 
			rm.setState("500");
			rm.setErrorInfo(ex.getMessage());
			rm.setMsgInfo("重取样出错");
		}
		return rm;
	}
	
	/**
	 * 检验委托管理-委托明细-验证选中记录状态是否为待发送 smp_no 试样号 specimen_no 取样编码
	 * */
	public ResultModel judgeInspectCom(CommonPage<QcmJhySampleConsignD> sum) {
		ResultModel rm = new ResultModel();
		try {
			List<QcmJhySampleConsignD> qdlist = sum.getObjectList();
			if (qdlist != null && qdlist.size() == 0) {
				rm.setMsgInfo("请传入参数！");
				rm.setState("500");
				return rm;
			}
			for (QcmJhySampleConsignD qd : qdlist) {
				if (qd == null || qd.getSmp_no().trim().equals("")
						|| qd.getSpecimen_no().trim().equals("")) {
					rm.setMsgInfo("传入的试样号和取样编号都不能为空！");
					rm.setState("500");
					return rm;
				}
				QcmJhySampleConsignD qd1 = this.getMapper(
						QcmJhySampleConsignDMapper.class).findById(
						qd.getSmp_no(), qd.getSpecimen_no());
				if (qd1 == null || qd1.getSmp_no().trim().equals("")) {
					rm.setMsgInfo("不存在对应试样号和取样编号的信息！");
					rm.setState("500");
					return rm;
				}
				if (!qd1.getStatus().equals("0")) {
					rm.setMsgInfo("试样号：" + qd.getSmp_no() + "取样编号："
							+ qd.getSpecimen_no() + "不是待发送信息！");
					rm.setState("500");
					return rm;
				}
			}
			rm.setData("True");
			rm.setState("200");
		} catch (Exception e) {
			rm.setMsgInfo("状态验证失败！");
			rm.setState("500");
			e.printStackTrace();
		}
		return rm;
	}

	/**
	 * 检验委托管理-委托明细-通过取样编号查询检验委托明细项目表获取对应的检验项记录 SPECIMEN_NO 取样编号
	 * */
	public ResultModel getItem(CommonPage<QcmJhySampleConsignDItem> sum) {
		ResultModel rm = new ResultModel();
		try {
			QcmJhySampleConsignDItem qd = sum.getObject();
			if (qd.getSpecimen_no().trim().equals("")) {
				rm.setMsgInfo("请传入参数！");
				rm.setState("500");
				return rm;
			}
			rm.setData(this.getMapper(QcmJhySampleConsignDItemMapper.class)
					.findWithCondition(null,
							"SPECIMEN_NO='" + qd.getSpecimen_no() + "'", null,
							0, 0));
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("获取失败！");
			return rm;
		}
		return rm;
	}

	/**
	 * 检验委托管理-委托明细-新增委托明细信息
	 * */
	@Transactional(value = "tm", rollbackFor = Exception.class)
	public ResultModel doAddEntrustCom(CommonPage<QcmJhySampleConsignDTemp> sum)
			throws Exception {
		ResultModel rm = new ResultModel();
		List<QcmJhySampleConsignDTemp> qtlist = sum.getObjectList();
		if (qtlist == null || qtlist.size() == 0) {
			rm.setState("500");
			rm.setMsgInfo("请传入数据！");
			return rm;
		}
		try {
			String username = (String) this.getSession().getAttribute(
					HomeService.SESSION_USER_NAME);
			QcmJhySampleConsignDTemp qttt = qtlist.get(0);
			// 获取取样编号最大值
			int icount = 0;
			List<QcmJhySampleConsignD> qdlist = this.getMapper(
					QcmJhySampleConsignDMapper.class).findWithCondition(null,
					"SMP_NO='" + qttt.getSmp_no() + "'", "SPECIMEN_NO DESC", 0,
					1);
			if (qdlist != null && qdlist.size() > 0) {
				String s = qdlist.get(0).getSpecimen_no();
				icount = Integer.parseInt(s.substring(s.length() - 2,
						s.length()));
			}
			for (QcmJhySampleConsignDTemp qt : qtlist) {
				icount++;
				// 取样编号
				String qybh = qt.getSmp_no() + String.format("%02d", icount);
				QcmJhySampleConsignD qd = new QcmJhySampleConsignD();
				qd.setSmp_no(qt.getSmp_no());
				qd.setSpecimen_no(qybh);
				qd.setHeat_no(qt.getHeat_no());
				qd.setBatch_no(qt.getBatch_no());
				qd.setInspection_lot(qt.getInspection_lot());
				qd.setPline_code(qt.getPline_code());
				qd.setPline_name(qt.getPline_name());
				qd.setFreq_code(qt.getFreq_code());
				qd.setFreq_name(qt.getFreq_name());
				qd.setMaterial_no(qt.getMaterial_no());
				qd.setSmp_type_code(qt.getSmp_type_code());
				qd.setSmp_type_name(qt.getSmp_type_name());
				qd.setTest_qty(qt.getTest_qty());
				qd.setSmp_qty(qt.getSmp_qty());
				qd.setQuote_consign_no(qt.getQuote_consign_no());
				qd.setOld_consign_no(qt.getOld_consign_no());
				// 插入检验委托明细表
				this.getMapper(QcmJhySampleConsignDMapper.class).insert(qd);
				Long seq = 0L;
				List<QcmJhySampleConsignDItem> qttlist = qt.getObjectList1();
				for (QcmJhySampleConsignDItem qtt : qttlist) {
					seq++;
					qtt.setSpecimen_no(qybh);
					qtt.setSeq(seq);
					qtt.setCreate_name(username);
					qtt.setCreate_time(new Date());
					qtt.setIs_send("0");
					// // 判断数据库中是否存在相同数据:试样号+取样频次+检验项
					// // 试样号+取样频次->取样编号
					// List<QcmJhySampleConsignD> qddd = this.getMapper(
					// QcmJhySampleConsignDMapper.class)
					// .findWithCondition(
					// null,
					// "SMP_NO='" + qt.getSmp_no()
					// + "' and FREQ_CODE='"
					// + qt.getFreq_code() + "'", null, 0,
					// 0);
					// for (QcmJhySampleConsignD qdtt : qddd) {
					// // 取样编号->检验项
					// List<QcmJhySampleConsignDItem> qdddi = this.getMapper(
					// QcmJhySampleConsignDItemMapper.class)
					// .findWithCondition(
					// null,
					// "SPECIMEN_NO='" + qdtt.getSpecimen_no()
					// + "'", null, 0, 0);
					// for (QcmJhySampleConsignDItem qdit : qdddi) {
					// if(qdit.getPhy_code_s().equals(qtt.getPhy_code_s())){
					// rm.setState("500");
					// rm.setMsgInfo("存在相同取样频次和检验项的数据！取样编号："+qdit.getSpecimen_no());
					// return rm;
					// }
					// }
					// }
					//
					// 插入委托明细项目表
					this.getMapper(QcmJhySampleConsignDItemMapper.class)
							.insert(qtt);
				}
			}
			rm.setState("200");
		} catch (Exception e) {
			e.printStackTrace();
			throw new Exception();
		}
		return rm;
	}

	/**
	 * 检验委托管理-委托明细-修改委托明细信息
	 * 
	 * smp_no 试样号 specimen_no 取样编码
	 * 
	 * freq_code 取样频次代码 freq_name 取样频次名称 material_no 取样材料号 smp_type_code 样品类型代码
	 * smp_type_name 样品类型名称 all_item_code 检验项目代码集合 all_item_name 检验项目名称集合
	 * test_qty 试验次数 smp_qty 取样数量 quote_consign_no 引用取样编号 old_consign_no
	 * 初样取样编号（复样不能为空）
	 * 
	 * phy_code_l 材质检验项代码（大类） phy_name_l 材质检验项名称（大类） phy_code_m 试样组代码 phy_name_m
	 * 试样组描述 phy_code_s 材质检验项代码 phy_name_s 材质检验项名称 item_code_d 试验方向代码
	 * item_name_d 试验方向描述 item_code_t 试验温度代码 item_name_t 试验温度描述 item_code_s
	 * 试样尺寸代码 item_name_s 试样尺寸描述
	 * */
	@Transactional(value = "tm", rollbackFor = Exception.class)
	public ResultModel doUpdateEntrustCom(
			CommonPage<QcmJhySampleConsignDTemp> sum) throws Exception {
		ResultModel rm = new ResultModel();
		String username = (String) this.getSession().getAttribute(
				HomeService.SESSION_USER_NAME);
		List<QcmJhySampleConsignDTemp> qtlist = sum.getObjectList();
		if (qtlist == null || qtlist.size() == 0) {
			rm.setState("500");
			rm.setMsgInfo("请传入参数！");
			return rm;
		}
		try {
			// 更新检验委托明细表
			for (QcmJhySampleConsignDTemp qt : qtlist) {
				QcmJhySampleConsignD qd = this.getMapper(
						QcmJhySampleConsignDMapper.class).findById(
						qt.getSmp_no(), qt.getSpecimen_no());
				qd.setFreq_code(qt.getFreq_code());
				qd.setFreq_name(qt.getFreq_name());
				qd.setMaterial_no(qt.getMaterial_no());
				qd.setSmp_type_code(qt.getSmp_type_code());
				qd.setSmp_type_name(qt.getSmp_type_name());
				qd.setTest_qty(qt.getTest_qty());
				qd.setSmp_qty(qt.getSmp_qty());
				qd.setQuote_consign_no(qt.getQuote_consign_no());
				qd.setOld_consign_no(qt.getOld_consign_no());
				this.getMapper(QcmJhySampleConsignDMapper.class).update(qd);

				// 删除取样编号下的所有明细项目再重新插入
				this.getMapper(QcmJhySampleConsignDItemMapper.class)
						.doDeleteEntrustCom(qt.getSpecimen_no());
				Long seq = 0L;
				List<QcmJhySampleConsignDItem> qttlist = qt.getObjectList1();
				for (QcmJhySampleConsignDItem qtt : qttlist) {
					// 插入委托明细项目表
					seq++;
					QcmJhySampleConsignDItem qdi = new QcmJhySampleConsignDItem();
					qdi.setSpecimen_no(qt.getSpecimen_no());
					qdi.setSeq(seq);
					qdi.setPhy_code_l(qtt.getPhy_code_l());
					qdi.setPhy_code_m(qtt.getPhy_code_m());
					qdi.setPhy_code_s(qtt.getPhy_code_s());
					qdi.setPhy_name_l(qtt.getPhy_name_l());
					qdi.setPhy_name_m(qtt.getPhy_name_m());
					qdi.setPhy_name_s(qtt.getPhy_name_s());
					qdi.setItem_code_d(qtt.getItem_code_d());
					qdi.setItem_code_s(qtt.getItem_code_s());
					qdi.setItem_code_t(qtt.getItem_code_t());
					qdi.setItem_name_d(qtt.getItem_name_d());
					qdi.setItem_name_s(qtt.getItem_name_s());
					qdi.setItem_name_t(qtt.getItem_name_t());
					qdi.setCreate_name(username);
					qdi.setCreate_time(new Date());
					qdi.setIs_send("0");
					this.getMapper(QcmJhySampleConsignDItemMapper.class)
							.insert(qdi);
				}
			}
			rm.setState("200");
		} catch (Exception e) {
			e.printStackTrace();
			throw new Exception();
		}
		return rm;
	}

	/**
	 * 检验委托管理-委托明细-删除委托明细信息 smp_no 试样号 specimen_no 取样编码
	 * */
	@Transactional(value = "tm", rollbackFor = Exception.class)
	public ResultModel doDeleteEntrustCom(CommonPage<QcmJhySampleConsignD> sum)
			throws Exception {
		ResultModel rm = new ResultModel();
		try {
			List<QcmJhySampleConsignD> qdlist = sum.getObjectList();
			if (qdlist == null || qdlist.size() == 0) {
				rm.setState("500");
				rm.setMsgInfo("请传入参数！");
				return rm;
			}
			for (QcmJhySampleConsignD qd : qdlist) {
				// 删除检验委托明细表
				this.getMapper(QcmJhySampleConsignDMapper.class).delete(
						qd.getSmp_no(), qd.getSpecimen_no());
				// 删除检验委托明细项目表
				this.getMapper(QcmJhySampleConsignDItemMapper.class)
						.doDeleteEntrustCom(qd.getSpecimen_no());
			}
			rm.setState("200");
		} catch (Exception e) {
			e.printStackTrace();
			throw new Exception();
		}
		return rm;
	}

	/**
	 * 检验信息管理-查询 smp_no 试样号 heat_no 炉号 batch_no 轧批号 inspection_lot 检验号
	 * cert_inst_name 认证机构 status 状态(0,未发送,1,已发送,2,已接收,3,已完成)
	 * */
	public ResultModel doQueryQcmD(CommonPage<QcmJhySampleConsignD> sum) {
		ResultModel rm = new ResultModel();
		try {
			QcmJhySampleConsignD qd = sum.getObject();
			String Str = "1=1";
			if (qd.getHeat_no() != null && !qd.getHeat_no().trim().equals("")) {
				Str += " and HEAT_NO like '%" + qd.getHeat_no() + "%'";
			}
			if (qd.getBatch_no() != null && !qd.getBatch_no().trim().equals("")) {
				Str += " and BATCH_NO like '%" + qd.getBatch_no() + "%'";
			}
			if (qd.getInspection_lot() != null
					&& !qd.getInspection_lot().trim().equals("")) {
				Str += " and INSPECTION_LOT like '%" + qd.getInspection_lot()
						+ "%'";
			}
			String Str1 = Str;
//			if (qd.getSmp_no() != null && !qd.getSmp_no().trim().equals("")) {
//				Str1 += " and SMP_NO like '%" + qd.getSmp_no() + "%'";
//			}
//			if (qd.getCert_inst_name() != null
//					&& !qd.getCert_inst_name().trim().equals("")) {
//				Str1 += " and CERT_INST_NAME like '%" + qd.getCert_inst_name()
//						+ "%'";
//			}
			// 获取主表信息
			List<QcmJhySampleConsignM> qmlist = this.getMapper(
					QcmJhySampleConsignMMapper.class).getinspection(Str1);
			for (QcmJhySampleConsignM qjsc : qmlist) {
				//根据检验号查询D表数据
//				List<QcmJhySampleConsignD> listd = this.getMapper(QcmJhySampleConsignDMapper.class).findWithCondition(null, "inspection_lot='"+qjsc.getInspection_lot()+"'", null, 0, 0);
//				for (QcmJhySampleConsignD d : listd) {
					//未发送
					QcmJhySampleConsignD qjsd=new QcmJhySampleConsignD();
					qjsd.setStatus("0");
					qjsd.setInspection_lot(qjsc.getInspection_lot());
					int notsand = this.getMapper(QcmJhySampleConsignDMapper.class).count(qjsd);
					//已发送
					QcmJhySampleConsignD qjsd1=new QcmJhySampleConsignD();
					qjsd1.setStatus("1");
					qjsd1.setInspection_lot(qjsc.getInspection_lot());
					int sanded = this.getMapper(QcmJhySampleConsignDMapper.class).sanding(qjsc.getInspection_lot());
					//已取样
					int sampling = this.getMapper(QcmJhySampleConsignDMapper.class).sampling(qjsc.getInspection_lot());
					//未取样
					int notsampling = this.getMapper(QcmJhySampleConsignDMapper.class).notsampling(qjsc.getInspection_lot());
				   qjsc.setSanded(sanded);
				   qjsc.setNotsand(notsand);
				   qjsc.setSampling(sampling);
				   qjsc.setNotsampling(notsampling);
//				}
			}
//			List<QcmJhySampleConsignD> qjsdlist = new ArrayList<>();
//			// 获取委托明细信息
//			for (QcmJhySampleConsignM qm : qmlist) {
//				String Str2 = Str;
//				Str2 += " and SMP_NO='" + qm.getSmp_no() + "'";
//				if (qd.getStatus() != null && !qd.getStatus().trim().equals("")) {
//					Str2 += " and STATUS like '%" + qd.getStatus() + "%'";
//				}
//				List<QcmJhySampleConsignD> qdlist = this.getMapper(
//						QcmJhySampleConsignDMapper.class).findWithCondition(
//						null, Str2, null, 0, 0);
//				for (QcmJhySampleConsignD qdd : qdlist) {
//					qdd.setCert_inst_code(qm.getCert_inst_code());
//					qdd.setCert_inst_name(qm.getCert_inst_name());
//					qdd.setSmp_type_code1(qm.getSmp_type_code());
//					qdd.setSmp_type_name1(qm.getSmp_type_name());
//					qjsdlist.add(qdd);
//				}
//			}
			List<QcmJhySampleConsignM> list=new ArrayList<>();
            for (QcmJhySampleConsignM q : qmlist) {
				if ("0".equals(sum.getMemo1())) {
					if (q.getNotsampling()==0&&q.getNotsand()==0) {
						list.add(q);
					}
				}else {
					if (q.getSampling()==0&&q.getNotsand()==0) {
					}else {
						list.add(q);
					}
				}
			}
			rm.setData(list);
			rm.setState("200");
		} catch (Exception e) {
			rm.setMsgInfo("查询失败！");
			rm.setState("500");
			e.printStackTrace();
		}
		return rm;
	}

	/**
	 * 检验信息管理-发送 smp_no 试样号 specimen_no 取样编号
	 * 
	 * @throws Exception
	 * */
	@Transactional(value = "tm", rollbackFor = Exception.class)
	public ResultModel doSand(CommonPage<QcmJhySampleConsignD> sum)
			throws Exception {
		ResultModel rm = new ResultModel();
		try {
			List<QcmJhySampleConsignD> qdlist = sum.getObjectList();
			if (qdlist == null || qdlist.size() == 0) {
				rm.setMsgInfo("请传入参数！");
				rm.setState("500");
				return rm;
			}
			for (QcmJhySampleConsignD qd : qdlist) {
				QcmJhySampleConsignD qd1 = this.getMapper(
						QcmJhySampleConsignDMapper.class).findById(
						qd.getSmp_no(), qd.getSpecimen_no());
				if (qd1 == null || qd1.getSmp_no().trim().equals("")
						|| qd.getSpecimen_no().trim().equals("")) {
					rm.setMsgInfo("不存在对应试样号为：" + qd.getSmp_no() + "取样编号为："
							+ qd.getSpecimen_no() + "的信息！");
					rm.setState("500");
					return rm;
				}
				if (!qd1.getStatus().equals("0")) {
					rm.setMsgInfo("不是未发送数据！");
					rm.setState("500");
					return rm;
				}
			}
			// 生成委托编号
			int icount = 0;
			List<QcmJhySampleConsignD> qdtlist = this.getMapper(
					QcmJhySampleConsignDMapper.class).findWithCondition(null,
					"CONSIGN_NO is not null", "CONSIGN_NO DESC", 0, 1);
			if (qdtlist != null && qdtlist.size() > 0) {
				String s = qdtlist.get(0).getConsign_no();
				icount = Integer.parseInt(s.substring(s.length() - 3,
						s.length()));
			}
			SimpleDateFormat sdf = new SimpleDateFormat("yyMMdd");
			String da = sdf.format(new Date());
			for (QcmJhySampleConsignD qd : qdlist) {
				qd = this.getMapper(QcmJhySampleConsignDMapper.class).findById(
						qd.getSmp_no(), qd.getSpecimen_no());
				// 委托编号
				icount++;
				String wtbh = da + String.format("%03d", icount);
				qd.setConsign_no(wtbh);
				qd.setStatus("1");
				this.getMapper(QcmJhySampleConsignDMapper.class).update(qd);
			}
			rm.setState("200");
		} catch (Exception e) {
			e.printStackTrace();
			throw new Exception();
		}
		return rm;
	}

	/**
	 * 检验信息管理-取消发送 smp_no 试样号 specimen_no 取样编号
	 * 
	 * @throws Exception
	 * */
	@Transactional(value = "tm", rollbackFor = Exception.class)
	public ResultModel doRevSand(CommonPage<QcmJhySampleConsignD> sum)
			throws Exception {
		ResultModel rm = new ResultModel();
		try {
			List<QcmJhySampleConsignD> qdlist = sum.getObjectList();
			if (qdlist == null || qdlist.size() == 0) {
				rm.setMsgInfo("请传入参数！");
				rm.setState("500");
				return rm;
			}
			for (QcmJhySampleConsignD qd : qdlist) {
				QcmJhySampleConsignD qd1 = this.getMapper(
						QcmJhySampleConsignDMapper.class).findById(
						qd.getSmp_no(), qd.getSpecimen_no());
				if (qd1 == null || qd1.getSmp_no().trim().equals("")
						|| qd.getSpecimen_no().trim().equals("")) {
					rm.setMsgInfo("不存在对应试样号为：" + qd.getSmp_no() + "取样编号为："
							+ qd.getSpecimen_no() + "的信息！");
					rm.setState("500");
					return rm;
				}
				if (!qd1.getStatus().equals("1")) {
					rm.setMsgInfo("不是已发送数据！");
					rm.setState("500");
					return rm;
				}
			}

			for (QcmJhySampleConsignD qd : qdlist) {
				QcmJhySampleConsignD qd1 = this.getMapper(
						QcmJhySampleConsignDMapper.class).findById(
						qd.getSmp_no(), qd.getSpecimen_no());
				qd1.setConsign_no("");
				qd1.setStatus("0");
				this.getMapper(QcmJhySampleConsignDMapper.class).update(qd1);
			}
			rm.setState("200");
		} catch (Exception e) {
			e.printStackTrace();
			throw new Exception();
		}
		return rm;
	}

//	/**
//	 * 质量判定-材质判定管理-获取检验实绩 sum.smp_no 试样号 sum.design_key design_key sum.psc 产品码
//	 * sum.contract_line_no 销售订单号PK码
//	 * */
//	public List<ResultModel> findSampleItem(CommonPage<QcmJhySampleConsignM> sum) {
//		List<ResultModel> listrm = new ArrayList<>();
//		ResultModel rm1=new ResultModel();
//		listrm.add(rm1);
//		ResultModel rm2=new ResultModel();
//		listrm.add(rm2);
//		ResultModel rm3=new ResultModel();
//		listrm.add(rm3);
//		List<String[]> listb=new ArrayList<>();
//		try {
//			QcmJhySampleConsignM qd = sum.getObject();
//			if (qd == null || qd.getSmp_no() == null
//					|| "".equals(qd.getSmp_no())) {
//				rm1.setState("500");
//				rm1.setMsgInfo("请传入参数！");
//				return listrm;
//			}
//
//			List<QcmJhySampleConsignDItem> qjsd = new ArrayList<>();
//			// 试样号对应的所有材质检验项目
//			List<QcmJhySampleConsignD> qjsdt = this.getMapper(
//					QcmJhySampleConsignDMapper.class).getDsample(qd.getSmp_no(), qd.getContract_line_no());
//			rm2.setData(qjsdt);
//			for (QcmJhySampleConsignD qdttt : qjsdt) {
//				List<QcmJhySampleConsignDItem> q = this.getMapper(
//						QcmJhySampleConsignDItemMapper.class)
//						.findWithCondition(null,
//								"SPECIMEN_NO='" + qdttt.getSpecimen_no() + "'",
//								null, 0, 0);
//				for (QcmJhySampleConsignDItem qdii : q) {
//					qdii.setSMP_TYPE_CODE(qdttt.getSmp_type_code());
//					qdii.setSmp_type_name(qdttt.getSmp_type_name());
//					qjsd.add(qdii);
//				}
//			}
//			for (QcmJhySampleConsignDItem qsd : qjsd) {
//				//获取实测值
//				String[] bool=new String[6];
//				boolean min1=true;
//				boolean max1=true;
//				boolean min2=true;
//				boolean max2=true;
//				boolean min3=true;
//				boolean max3=true;
//					List<QcmJhyPhyresult> s = this.getMapper(QcmJhyPhyresultMapper.class).findWithCondition(null, "SPECIMEN_NO='"+qsd.getSpecimen_no()+"'", null, 0, 1);
//					QcmJhyPhyresult qpt=new QcmJhyPhyresult();
//					if (s.size()>0) {
//						qpt=s.get(0);
//					}
//					qsd.setVal1(qpt.getVal1());
//					qsd.setVal2(qpt.getVal2());
//					qsd.setVal3(qpt.getVal3());	
//				
//				// 交付标准
//				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());
//					qsd.setIsjudge(ss.getIsjudge());
//					qsd.setJudge_basis(ss.getJudge_basis());
//				}
////				客户标准
//				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());
//					} 
//				}
//				
//				//判断交付标准是否合格
//                bool[0]=getJudgeColor(qsd.getJf_stdmin_sign(),qsd.getJf_stdmin(),qsd.getVal1(),qsd.getVal2(),qsd.getVal3());
//                bool[1]=getJudgeColor(qsd.getJf_stdmax_sign(),qsd.getJf_stdmax(),qsd.getVal1(),qsd.getVal2(),qsd.getVal3());
//                bool[2]=getJudgeColor(qsd.getKh_stdmin_sign(),qsd.getKh_stdmin(),qsd.getVal1(),qsd.getVal2(),qsd.getVal3());
//                bool[3]=getJudgeColor(qsd.getKh_stdmax_sign(),qsd.getKh_stdmax(),qsd.getVal1(),qsd.getVal2(),qsd.getVal3());
//                bool[4]=getJudgeColor(qsd.getNk_stdmin_sign(),qsd.getNk_stdmin(),qsd.getVal1(),qsd.getVal2(),qsd.getVal3());
//                bool[5]=getJudgeColor(qsd.getNk_stdmax_sign(),qsd.getNk_stdmax(),qsd.getVal1(),qsd.getVal2(),qsd.getVal3());
//			    listb.add(bool);
//			    
//			}
//			rm3.setData(listb);
//			rm1.setData(qjsd);
//			rm1.setState("200");
//		} catch (Exception e) {
//			rm1.setMsgInfo("查询出错！" + e.getMessage());
//			rm1.setState("500");
//			e.printStackTrace();
//		}
//		return listrm;
//	}
	public ResultModel findSampleItem(CommonPage<QcmJhySampleConsignM> sum) {
		ResultModel rm=new ResultModel();
		QcmJhySampleConsignM qm=sum.getObject();
		ResultModel r = querryJudgetItems(qm.getSmp_no(), qm.getDesign_key(), qm.getPsc());
		List<QcmJhySampleConsignDItem> listd=(List<QcmJhySampleConsignDItem>) r.getData();
		try{
			for (QcmJhySampleConsignDItem sod : listd) {
				   String bool0="";
				   String bool1="";
				   String bool2="";
				   String bool3="";
				   String bool4="";
				   String bool5="";
				   //最小值判定
				if (!DataHelper.IsNullOrSpace(sod.getJudge_basis())&&sod.getJudge_basis().equalsIgnoreCase("A")) {
					    String min = compareVal(sod.getVal1(),sod.getVal2(),sod.getVal3(), sod.getJudge_basis());
					    bool0=getJudgeColor(sod.getJf_stdmin_sign(),sod.getJf_stdmin(),min,null,null);
					    bool1=getJudgeColor(sod.getJf_stdmax_sign(),sod.getJf_stdmax(),min,null,null);
					    bool2=getJudgeColor(sod.getKh_stdmin_sign(),sod.getKh_stdmin(),min,null,null);
					    bool3=getJudgeColor(sod.getKh_stdmax_sign(),sod.getKh_stdmax(),min,null,null);
					    bool4=getJudgeColor(sod.getNk_stdmin_sign(),sod.getNk_stdmin(),min,null,null);
					    bool5=getJudgeColor(sod.getNk_stdmax_sign(),sod.getNk_stdmax(),min,null,null);
				}
				//最大值判定
				if (!DataHelper.IsNullOrSpace(sod.getJudge_basis())&&sod.getJudge_basis().equalsIgnoreCase("B")) {
				    String min = compareVal(sod.getVal1(),sod.getVal2(),sod.getVal3(), sod.getJudge_basis());
				    bool0=getJudgeColor(sod.getJf_stdmin_sign(),sod.getJf_stdmin(),min,null,null);
				    bool1=getJudgeColor(sod.getJf_stdmax_sign(),sod.getJf_stdmax(),min,null,null);
				    bool2=getJudgeColor(sod.getKh_stdmin_sign(),sod.getKh_stdmin(),min,null,null);
				    bool3=getJudgeColor(sod.getKh_stdmax_sign(),sod.getKh_stdmax(),min,null,null);
				    bool4=getJudgeColor(sod.getNk_stdmin_sign(),sod.getNk_stdmin(),min,null,null);
				    bool5=getJudgeColor(sod.getNk_stdmax_sign(),sod.getNk_stdmax(),min,null,null);
			    }
				//平均值判定
				if (!DataHelper.IsNullOrSpace(sod.getJudge_basis())&&sod.getJudge_basis().equalsIgnoreCase("C")) {
				    String min = compareVal(sod.getVal1(),sod.getVal2(),sod.getVal3(), sod.getJudge_basis());
				    bool0=getJudgeColor(sod.getJf_stdmin_sign(),sod.getJf_stdmin(),min,null,null);
				    bool1=getJudgeColor(sod.getJf_stdmax_sign(),sod.getJf_stdmax(),min,null,null);
				    bool2=getJudgeColor(sod.getKh_stdmin_sign(),sod.getKh_stdmin(),min,null,null);
				    bool3=getJudgeColor(sod.getKh_stdmax_sign(),sod.getKh_stdmax(),min,null,null);
				    bool4=getJudgeColor(sod.getNk_stdmin_sign(),sod.getNk_stdmin(),min,null,null);
				    bool5=getJudgeColor(sod.getNk_stdmax_sign(),sod.getNk_stdmax(),min,null,null);
			    }
				//逐项值判定
				if (DataHelper.IsNullOrSpace(sod.getJudge_basis())||sod.getJudge_basis().equalsIgnoreCase("D")) {
					bool0=getJudgeColor(sod.getJf_stdmin_sign(),sod.getJf_stdmin(),sod.getVal1(),sod.getVal2(),sod.getVal3());
				    bool1=getJudgeColor(sod.getJf_stdmax_sign(),sod.getJf_stdmax(),sod.getVal1(),sod.getVal2(),sod.getVal3());
				    bool2=getJudgeColor(sod.getKh_stdmin_sign(),sod.getKh_stdmin(),sod.getVal1(),sod.getVal2(),sod.getVal3());
				    bool3=getJudgeColor(sod.getKh_stdmax_sign(),sod.getKh_stdmax(),sod.getVal1(),sod.getVal2(),sod.getVal3());
				    bool4=getJudgeColor(sod.getNk_stdmin_sign(),sod.getNk_stdmin(),sod.getVal1(),sod.getVal2(),sod.getVal3());
				    bool5=getJudgeColor(sod.getNk_stdmax_sign(),sod.getNk_stdmax(),sod.getVal1(),sod.getVal2(),sod.getVal3());
				}
				   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);
				}
			}
			rm.setData(listd);
		     rm.setState("200");
		 } catch (Exception e) {
			// TODO: handle exception
			 rm.setState("500");
			 rm.setErrorInfo(e.getMessage());
		}
		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;
	}
	/**
	 * 为前端获取对比结果好标颜色
	 * 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; 
		}
	/**
	 * 查询Qcm_Jhy_Sample_Consign_M表检验号，炉号，轧批号
	 * @return
	 */
	public ResultModel getConsignMSample(){
		ResultModel rm=new ResultModel();
		try {
			List<QcmJhySampleConsignM> qmlist = this.getMapper(
					QcmJhySampleConsignMMapper.class).getinspection("1=1");
			for (QcmJhySampleConsignM qjsc : qmlist) {
				//根据检验号查询D表数据
//				List<QcmJhySampleConsignD> listd = this.getMapper(QcmJhySampleConsignDMapper.class).findWithCondition(null, "inspection_lot='"+qjsc.getInspection_lot()+"'", null, 0, 0);
//				for (QcmJhySampleConsignD d : listd) {
					//未发送
					QcmJhySampleConsignD qjsd=new QcmJhySampleConsignD();
					qjsd.setStatus("0");
					qjsd.setInspection_lot(qjsc.getInspection_lot());
					int notsand = this.getMapper(QcmJhySampleConsignDMapper.class).count(qjsd);
					//已发送
					QcmJhySampleConsignD qjsd1=new QcmJhySampleConsignD();
					qjsd1.setStatus("1");
					qjsd1.setInspection_lot(qjsc.getInspection_lot());
					int sanded = this.getMapper(QcmJhySampleConsignDMapper.class).sanding(qjsc.getInspection_lot());
					//已取样
					int sampling = this.getMapper(QcmJhySampleConsignDMapper.class).sampling(qjsc.getInspection_lot());
					//未取样
					int notsampling = this.getMapper(QcmJhySampleConsignDMapper.class).notsampling(qjsc.getInspection_lot());
				   qjsc.setSanded(sanded);
				   qjsc.setNotsand(notsand);
				   qjsc.setSampling(sampling);
				   qjsc.setNotsampling(notsampling);
			}
			List<QcmJhySampleConsignM> list=new ArrayList<>();
            for (QcmJhySampleConsignM q : qmlist) {
//				if ("0".equals("0")) {
					if (q.getNotsampling()==0&&q.getNotsand()==0) {
						list.add(q);
					}
//				}
//				else {
//					if (q.getSampling()==0&&q.getNotsand()==0) {
//					}else {
//						list.add(q);
//					}
//				}
			}
		    rm.setData(list);
		    rm.setState("200");
			
		} catch (Exception e) {
			// TODO: handle exception
			rm.setState("500");
			rm.setMsgInfo("查询信息失败");
			rm.setErrorInfo(e.getMessage());
		}
		return rm;
	}
	/**
	 * 查询检验号向下对应的试样号信息
	 * @return
	 */
	/**
	 * 查询检验号向下对应的试样号信息
	 * @return
	 */
	public ResultModel getConsignDSample(CommonPage<QcmJhySampleConsignD> sum){
		ResultModel rm=new ResultModel();
		QcmJhySampleConsignD qsm=sum.getObject();
		try {
			String conn="";
			if (!DataHelper.IsNullOrSpace(qsm.getInspection_lot())) {
				conn+=" and upper(t2.inspection_lot) like upper('%"+qsm.getInspection_lot()+"%')";
			}
			if (!DataHelper.IsNullOrSpace(qsm.getPline_name())) {
				conn+=" and t1.pline_name like '%"+qsm.getPline_name()+"%'";
			}
			if (!DataHelper.IsNullOrSpace(qsm.getBatch_no())) {
				conn+=" and upper(t1.batch_no) like upper('%"+qsm.getBatch_no()+"%')";
			}
			if (!DataHelper.IsNullOrSpace(qsm.getCert_inst_name())) {
				conn+=" and t2.cert_inst_name like '%"+qsm.getCert_inst_name()+"%'";
			}
			if (!DataHelper.IsNullOrSpace(qsm.getSmp_type_code1())) {
				conn+=" and t2.smp_type_code='"+qsm.getSmp_type_code1()+"'";
			}
			if (!DataHelper.IsNullOrSpace(qsm.getStatus())) {
				conn+=" and status='"+qsm.getStatus()+"'";
			}
			if (!DataHelper.IsNullOrSpace(qsm.getValidflag())) {
				conn+=" and T1.validflag='"+qsm.getValidflag()+"'";
			}
			List<QcmJhySampleConsignD> listd = this.getMapper(QcmJhySampleConsignDMapper.class).getConsignDSample(conn);
			for (QcmJhySampleConsignD l : listd) {
				  List<String> liststr=new ArrayList<>();
		    	List<QcmJhySampleConsignDItem> listI = this.getMapper(QcmJhySampleConsignDItemMapper.class).findWithCondition(null, "specimen_no='"+l.getSpecimen_no()+"'", null, 0, 0);
			   String JYDX="";
			   if (listI!=null&&listI.size()>0) {
		    	for (QcmJhySampleConsignDItem i : listI) {
					if (!DataHelper.IsNullOrSpace(i.getPhy_name_l())&&!liststr.contains(i.getPhy_name_l())) {
						JYDX+=i.getPhy_name_l()+",";
						liststr.add(i.getPhy_name_l());
					}
					CommonPage<QcmJhySampleConsignD> su=new CommonPage<>();
					l.setPhy_code_m(i.getPhy_code_m());
					su.setObject(l);
					ResultModel r=this.getBean(QcmJhySampleConsignDItemServiceImpl.class).judgeAndGetQuote(su);
					if (r!=null) {
						List<QcmJhySampleConsignDItem> items=(List<QcmJhySampleConsignDItem>) r.getData();
						if (items!=null && items.size()>0) {
							l.setIs_quote("1");
						}
					}
					
				}
		    	if (!DataHelper.IsNullOrSpace(JYDX)&&",".equals(JYDX.substring(JYDX.length()-1, JYDX.length()))) {
					l.setJYDX(JYDX.substring(0,JYDX.length()-1));
					System.out.println(JYDX.substring(0,JYDX.length()-1));
				}else {
					l.setJYDX(JYDX);
				}
			   }
		    }
			
			rm.setData(listd);
		    rm.setState("200");
		} catch (Exception e) {
			// TODO: handle exception
			rm.setState("500");
			rm.setMsgInfo("查询试样信息失败");
			rm.setErrorInfo(e.getMessage());
		}
		return rm;
	}
	/**
	 * 查询订单信息
	 * @param sum
	 * @return
	 */
	public ResultModel getROrdSampl(CommonPage<QcmJhySampleConsignD> sum){
		ResultModel rm=new ResultModel();
		QcmJhySampleConsignD qsd=sum.getObject();
		try {
			List<QcmJhySampleROrd> listr = this.getMapper(QcmJhySampleROrdMapper.class).findWithCondition(null, "SMP_NO='"+qsd.getSmp_no()+"'", null, 0, 0);
			for (QcmJhySampleROrd q : listr) {
				if (!DataHelper.IsNullOrSpace(q.getDesign_key())) {
					List<SlmOrdDesignMsc> listsodm = this.getMapper(SlmOrdDesignMscMapper.class).findWithCondition(null, "design_key='"+q.getDesign_key()+"' and psc='"+q.getPsc()+"'", null, 0, 0);
				    if (listsodm!=null&&listsodm.size()>0&&listsodm.get(0).getThick()!=null) {
						q.setPro_specification(listsodm.get(0).getThick());
					}
				}
			}
			rm.setData(listr);
			rm.setState("200");
		} catch (Exception e) {
			// TODO: handle exception
			rm.setState("500");
			rm.setMsgInfo("查询订单信息失败");
			rm.setErrorInfo(e.getMessage());
		}
		return rm;
	}
	public ResultModel getConsignDItemSample(CommonPage<QcmJhySampleConsignD> sum){
		ResultModel rm=new ResultModel();
		QcmJhySampleConsignD qsd = sum.getObject();
		try {
			//List<QcmJhySampleConsignDItem> listI = this.getMapper(QcmJhySampleConsignDItemMapper.class).getConsignDItemSample(qsd.getSpecimen_no());
			List<QcmJhySampleConsignDItem> listI = this.getMapper(QcmJhySampleConsignDItemMapper.class).findWithCondition(null, "specimen_no='"+qsd.getSpecimen_no()+"'", null, 0, 0);
			
			//查询检验结果
			if (listI!=null && listI.size()>0) {
				
			//	if (listI.get(0).getQuote_consign_no()!=null && !"".equals(listI.get(0).getQuote_consign_no())) {
					//String quote_specimen_no=listI.get(0).getQuote_consign_no();
					//List<QcmJhyPhyresult> results=this.getMapper(QcmJhyPhyresultMapper.class).findWithCondition(null, "SPECIMEN_NO='"+quote_specimen_no+"'", null, 0, 0);
					for (QcmJhySampleConsignDItem list : listI) {
						//String oldItem=list.getPhy_code_l()+list.getPhy_code_m()+list.getPhy_code_s()+list.getItem_code_d()+
						//		list.getItem_code_s()+list.getItem_code_t();
						/*for (QcmJhyPhyresult qt : results) {
							String newItem=qt.getPhy_code_l()+qt.getPhy_code_m()+qt.getPhy_code_s()+qt.getItem_code_d()+qt.getItem_code_s()+qt.getItem_code_t();
						if (oldItem.equals(newItem)) {
							list.setVal1(qt.getVal1());
							list.setVal2(qt.getVal2());
							list.setVal3(qt.getVal3());
							
						}
						
						}*/
						if (list.getQuote_consign_no()!=null && !"".equals(list.getQuote_consign_no())) {
							
							String condition=createQuoteItemSQl(list);
							List<QcmJhyPhyresult> results=this.getMapper(QcmJhyPhyresultMapper.class).findByCondition(list.getQuote_consign_no(),condition);
							if (results!=null && results.size()>0) {
								list.setVal1(results.get(0).getVal1());
								list.setVal2(results.get(0).getVal2());
								list.setVal3(results.get(0).getVal3());
							}
							
						}
						
						
					}
				//}
			}
			
			/**
			 * 判断是否可以引用
			 */
			List<QcmJhySampleConsignD> detail=this.getMapper(QcmJhySampleConsignDMapper.class).findWithCondition(null, "SPECIMEN_NO='"+qsd.getSpecimen_no()+"'", null, 0, 0);
			for (QcmJhySampleConsignDItem l : listI) {
				detail.get(0).setPhy_code_m(l.getPhy_code_m());
				CommonPage<QcmJhySampleConsignD> su=new CommonPage<>();
				su.setObject(detail.get(0));
				ResultModel r=this.getBean(QcmJhySampleConsignDItemServiceImpl.class).judgeAndGetQuote(su);
				if (r!=null) {
					List<QcmJhySampleConsignDItem> items=(List<QcmJhySampleConsignDItem>) r.getData();
					if (items!=null && items.size()>0) {
						l.setIs_quote("1");
					}
				}
			}
			
			rm.setData(listI);
			rm.setState("200");
		} catch (Exception e) {
			// TODO: handle exception
			rm.setState("500");
			rm.setMsgInfo("查询检验项目信息失败");
			rm.setErrorInfo(e.getMessage());
		}
		return rm;
	}
	private String createQuoteItemSQl(QcmJhySampleConsignDItem tr) {
		String condition="SPECIMEN_NO='"+tr.getQuote_specimen_no()+"'";
		if (tr.getPhy_code_l()!=null && !"".equals(tr.getPhy_code_l())) {
			condition+=" and PHY_CODE_L='"+tr.getQuote_phy_code_l()+"'";
		}
		
		if (tr.getPhy_code_m()!=null && !"".equals(tr.getPhy_code_m())) {
			condition+=" and PHY_CODE_M='"+tr.getQuote_phy_code_m()+"'";
		}
		
		if (tr.getPhy_code_s()!=null && !"".equals(tr.getPhy_code_s())) {
			condition+=" and PHY_CODE_S='"+tr.getQuote_phy_code_s()+"'";
		}
		
		if (tr.getItem_code_d()!=null && !"".equals(tr.getItem_code_d())) {
			condition+=" and ITEM_CODE_D='"+tr.getQuote_item_code_d()+"'";
		}
		
		if (tr.getItem_code_t()!=null && !"".equals(tr.getItem_code_t())) {
			condition+=" and ITEM_CODE_T='"+tr.getQuote_item_code_t()+"'";
		}
		
		if (tr.getItem_code_s()!=null && !"".equals(tr.getItem_code_s())) {
			condition+=" and ITEM_CODE_S='"+tr.getQuote_item_code_s()+"'";
		}
		return condition;
	}

	/**
	 * 检验信息管理-发送 smp_no 试样号 specimen_no 取样编号
	 * 
	 * @throws Exception
	 * */
	@Transactional(value = "tm", rollbackFor = Exception.class)
	public ResultModel doSend(CommonPage<QcmJhySampleConsignDTemp> sum)
			throws Exception {
		ResultModel rm = new ResultModel();
		String username = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		rm.setState("200");
		try {
			List<QcmJhySampleConsignDTemp> qdlist = sum.getObjectList();
			if (qdlist == null || qdlist.size() == 0) {
				rm.setMsgInfo("请传入参数！");
				rm.setState("500");
				throw new Exception();
			}
			for (QcmJhySampleConsignDTemp qd : qdlist) {
				QcmJhySampleConsignD qd1 = this.getMapper(
						QcmJhySampleConsignDMapper.class).findById(
						qd.getSmp_no(), qd.getSpecimen_no());
				if (qd1 == null || qd1.getSmp_no().trim().equals("")
						|| qd.getSpecimen_no().trim().equals("")) {
					rm.setMsgInfo("不存在对应试样号为：" + qd.getSmp_no() + "取样编号为："
							+ qd.getSpecimen_no() + "的信息！");
					rm.setState("500");
					TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
					return rm;
//					throw new Exception();
				}
				if (!qd1.getStatus().equals("0")) {
					rm.setMsgInfo("试样号为"+qd1.getSmp_no()+"取样编号为"+qd.getSpecimen_no()+"的数据不未发送状态，请确认！");
					rm.setState("500");
					TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
					return rm;
//					throw new Exception();
				}
				
				
				if (!qd1.getValidflag().equals("1")) {
					rm.setMsgInfo("试样号为"+qd1.getSmp_no()+"取样编号为"+qd.getSpecimen_no()+"的数据不是有效状态，请确认！");
					rm.setState("500");
					TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
					return rm;
//					throw new Exception();
				}

			}
			// 生成委托编号
			int icount = 0;
			List<QcmJhySampleConsignD> qdtlist = this.getMapper(
					QcmJhySampleConsignDMapper.class).findWithCondition(null,
					"CONSIGN_NO is not null and to_char(SEND_TIME,'yyyy-mm-dd') = to_char(sysdate,'yyyy-mm-dd')", "CONSIGN_NO DESC", 0, 1);
			if (qdtlist != null && qdtlist.size() > 0) {
				String s = qdtlist.get(0).getConsign_no();
				icount = Integer.parseInt(s.substring(s.length() - 3,
						s.length()));
			}
			SimpleDateFormat sdf = new SimpleDateFormat("yyMMdd");
			String da = sdf.format(new Date());
			icount++;
			String wtbh = da + String.format("%03d", icount);
			for (QcmJhySampleConsignDTemp qd : qdlist) {
				QcmJhySampleConsignD qd1 = this.getMapper(QcmJhySampleConsignDMapper.class).findById(
						qd.getSmp_no(), qd.getSpecimen_no());
				QcmJhySampleConsignM qm=this.getMapper(QcmJhySampleConsignMMapper.class).findById(qd.getSmp_no());
				// 委托编号
				qd1.setConsign_no(wtbh);
				qd1.setSend_name((String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME));
				qd1.setSend_time(new Date());
				qd1.setStatus("1");
				qd1.setConsign_no_seq((long)icount);
				Date dat=new Date();
				Date d=new Date();
				//将信息发送到表
//				IfJhySampleInfoM mainInfo=new IfJhySampleInfoM();
//				
//				mainInfo.setSmp_no(qd1.getSmp_no());
//				mainInfo.setHeat_no(qd1.getHeat_no());
//				mainInfo.setBatch_no(qd1.getBatch_no());
//				mainInfo.setInspection_lot(qd1.getInspection_lot());
//				
//				mainInfo.setMaterial_no(qd1.getMaterial_no());
//				mainInfo.setFreq_code(qd1.getFreq_code());
//				mainInfo.setFreq_name(qd1.getFreq_name());
//				mainInfo.setSmp_type_code(qd1.getSmp_type_code());
//				mainInfo.setSmp_type_name(qd1.getSmp_type_name());
//				mainInfo.setConsign_no(qd1.getConsign_no());//String.format("%03d", icount);
//				mainInfo.setConsign_no_seq((long)icount);
//				mainInfo.setTest_qty(qd.getTest_qty());
//				mainInfo.setSmp_qty(qd.getSmp_qty());
//				mainInfo.setBoard_no(qd1.getBoard_no());
//				mainInfo.setOld_consign_no(qd1.getConsign_no());
//				mainInfo.setPline_code(qd1.getPline_code());
//				mainInfo.setPline_name(qd1.getPline_name());
//				mainInfo.setStatus("0");
//				mainInfo.setStd_code("999");
//				mainInfo.setStd_name("测试");
//				mainInfo.setSteel_code(qm.getGrade_code());
//				mainInfo.setSteel_name(qm.getGrade_name());
//				mainInfo.setSend_name(username);
//				mainInfo.setSend_time(new Date());
//				this.getMapper(IfJhySampleInfoMMapper.class).insert(mainInfo);
//				boolean b = this.getBean(PbModelDbServiceImpl.class).findMSample(qd1.getSpecimen_no());
//				boolean b1 = this.getBean(PbModelDbServiceImpl.class).findDSample(qd1.getSpecimen_no());
//				if (b) {
//					rm.setState("403");
//					rm.setMsgInfo("【"+qd1.getSpecimen_no()+"】已存在，不能重复发送");
//					TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
//					return rm;
////					throw new Exception();
//				}
//				if (b1) {
//					rm.setState("403");
//					rm.setMsgInfo("【"+qd1.getSpecimen_no()+"】已存在，不能重复发送");
//					TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
//					return rm;
////					throw new Exception();
//				}
				//项目表添加
				List<QcmJhySampleConsignDItem> items=this.getMapper(QcmJhySampleConsignDItemMapper.class).getitemsample(qd1.getSpecimen_no());
				//遍历集合
				int flag=0;
				for (QcmJhySampleConsignDItem qi : items) {
					if (DataHelper.IsNullOrSpace(qi.getQuote_specimen_no())) {
//						int	s=this.getBean(QcmJhyPhyresultServiceImpl.class).insertInfoForD(qi,d);
					}else {
						flag++;
					}
				}
				if (flag==items.size()) {//试样号对应的取样编号全部引用，无需发送检化验
					QcmJhySampleConsignD qsd=new QcmJhySampleConsignD();
					qsd.setSmp_no(qd1.getSmp_no());
					qsd.setSpecimen_no(qd1.getSpecimen_no());
					qsd.setStatus("3");
					this.getMapper(QcmJhySampleConsignDMapper.class).update(qsd);
				}else {
//					int a=this.getBean(PbModelDbServiceImpl.class).insertInfoForM(qd1, qm.getGrade_code(), qm.getGrade_name(), username, d);
					//更新状态
					this.getMapper(QcmJhySampleConsignDMapper.class).update(qd1);
				}
			}
			rm.setState("200");
		} catch (Exception e) {
			e.printStackTrace();
			throw new Exception();
		}
		return rm;
	}
	/**
	 * 检验信息管理-取消发送 smp_no 试样号 specimen_no 取样编号
	 * 
	 * @throws Exception
	 * */
	@Transactional(value = "tm", rollbackFor = Exception.class)
	public ResultModel doRevSend(CommonPage<QcmJhySampleConsignD> sum)
			throws Exception {
		ResultModel rm = new ResultModel();
		try {
			List<QcmJhySampleConsignD> qdlist = sum.getObjectList();
			if (qdlist == null || qdlist.size() == 0) {
				rm.setMsgInfo("请传入参数！");
				rm.setState("500");
				return rm;
			}
			for (QcmJhySampleConsignD qd : qdlist) {
				QcmJhySampleConsignD qd1 = this.getMapper(
						QcmJhySampleConsignDMapper.class).findById(
						qd.getSmp_no(), qd.getSpecimen_no());
				if (qd1 == null || qd1.getSmp_no().trim().equals("")
						|| qd.getSpecimen_no().trim().equals("")) {
					rm.setMsgInfo("不存在对应试样号为：" + qd.getSmp_no() + "取样编号为："
							+ qd.getSpecimen_no() + "的信息！");
					rm.setState("500");
					return rm;
				}
				if (!qd1.getStatus().equals("1")) {
					rm.setMsgInfo("不是已发送数据！");
					rm.setState("500");
					return rm;
				}
			}

			for (QcmJhySampleConsignD qd : qdlist) {
				QcmJhySampleConsignD qd1 = this.getMapper(
						QcmJhySampleConsignDMapper.class).findById(
						qd.getSmp_no(), qd.getSpecimen_no());
				qd1.setConsign_no("");
				qd1.setStatus("0");
				
				//添加删除功能，删除插入表的内容
				//this.getMapper()
				int a=this.getBean(PbModelDbServiceImpl.class).deleteMSample(qd.getSmp_no(),qd.getSpecimen_no());
				List<QcmJhySampleConsignDItem> items=this.getMapper(QcmJhySampleConsignDItemMapper.class).getitemsample(qd1.getSpecimen_no());
				
				if (items!=null && items.size()>0) {

					for (QcmJhySampleConsignDItem qcmJhySampleConsignDItem : items) {
						
					int	row=this.getBean(PbModelDbServiceImpl.class).deleteDSample(qcmJhySampleConsignDItem.getSpecimen_no(),qcmJhySampleConsignDItem.getSeq());
						
					}
					
				}
				
				this.getMapper(QcmJhySampleConsignDMapper.class).update(qd1);
			}
			rm.setState("200");
		} catch (Exception e) {
			e.printStackTrace();
			throw new Exception();
		}
		return rm;
	}
	/**
	 * 根据取样编号修改明细表中的取样材料号
	 */

	@Transactional(value = "tm", rollbackFor = Exception.class)
	public ResultModel doUpdateD(CommonPage<QcmJhySampleConsignD> sum) {
		ResultModel rm = new ResultModel();

		try {
			QcmJhySampleConsignD qd = sum.getObject();

			if (qd == null || qd.getSpecimen_no() == null || "".equals(qd.getSpecimen_no())) {

				rm.setState("500");
				rm.setMsgInfo("参数不存在");
				return rm;
			}

			// 获取取样材料号
			if (qd.getMaterial_no() == null || "".equals(qd.getMaterial_no())) {

				rm.setState("500");
				rm.setMsgInfo("取样材料号不存在");
				return rm;

			}

			this.getMapper(QcmJhySampleConsignDMapper.class).update(qd);
			//rm.setData(qd);
			rm.setState("200");

		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("修改取样材料号失败");
			rm.setErrorInfo(e.getMessage());

		}

		return rm;

	}
	/**
	 * 修改取样材料号MATERIAL_NO
	 * 
	 * @throws Exception
	 */

	@Transactional(value = "tm", rollbackFor = Exception.class)
	public ResultModel upDateMaterialNo(CommonPage<QcmJhySampleConsignDTemp> sum) throws Exception {
		ResultModel rm = new ResultModel();
		String username = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		List<QcmJhySampleConsignDTemp> listqt = sum.getObjectList();

		try {
			for (QcmJhySampleConsignDTemp qt : listqt) {
			 if (qt == null) {
				rm.setMsgInfo("请传入参数！");
				rm.setState("500");
				return rm;

			 }
			QcmJhySampleConsignD qd = this.getMapper(QcmJhySampleConsignDMapper.class).findById(qt.getSmp_no(),
					qt.getSpecimen_no());

			String material_no = qt.getMaterial_no();
			if (material_no == null) {
				rm.setMsgInfo("取样材料号不能为空！");
				rm.setState("500");
				return rm;

			} else {
				qd.setMaterial_no(qt.getMaterial_no());
				qd.setUpdate_name(username);
				qd.setUpdate_time(new Date());
				this.getMapper(QcmJhySampleConsignDMapper.class).update(qd);
			}
			}
		} catch (Exception e) {
			e.printStackTrace();
			throw new Exception();
		}

		rm.setData(listqt);
		rm.setState("200");

		return rm;
	}


	/*
	 * 获取综合判定-成分模块检验实绩信息
	 * */
	public ResultModel  findUltimateSampleItem(CommonPage<YdmProductDetail> sum){
		ResultModel rm = new ResultModel();
		//从物流接口中成分判定记录号
		try {
			List<QcmJudgeChemical> listcond=new ArrayList<>();
			QcmJudgeChemical qjc=new QcmJudgeChemical();
			YdmProductDetail ydm=sum.getObject();
			qjc.setCic_id(ydm.getChemresult_id());
		    
			 //根据成分判定记录号查询检验实绩信息
		    QcmJudgeChemical qjc1 = this.getMapper(QcmJudgeChemicalMapper.class).findUltimateSampleItem(qjc);
		     rm.setData(qjc1);
		     rm.setState("200");
		} catch (Exception e) {
			// TODO: handle exception
			rm.setState("500");
			rm.setErrorInfo(e.getMessage());
			rm.setMsgInfo("操作失败");
		}
		   return rm;
	}
	/**
	 * 查询轧批号，炉号
	 * @param sum
	 * @return
	 */
   public ResultModel getMInfo(CommonPage<QcmJhySampleConsignD> sum){
	   ResultModel rm=new ResultModel();
	   PageModel<QcmJhySampleConsignM> pm=new PageModel<>(sum.getPageIndex(), sum.getPageSize());
	   try {
		   QcmJhySampleConsignD qd = sum.getObject();
			String Str = "1=1";
			if (qd.getHeat_no() != null && !qd.getHeat_no().trim().equals("")) {
				Str += " and HEAT_NO like '%" + qd.getHeat_no() + "%'";
			}
			if (qd.getBatch_no() != null && !qd.getBatch_no().trim().equals("")) {
				Str += " and BATCH_NO like '%" + qd.getBatch_no() + "%'";
			}
			if (qd.getInspection_lot() != null
					&& !qd.getInspection_lot().trim().equals("")) {
				Str += " and INSPECTION_LOT like '%" + qd.getInspection_lot()
						+ "%'";
			}
			if (qd.getBoard_no() != null
					&& !qd.getBoard_no().trim().equals("")) {
				Str += " and BOARD_NO like '%" + qd.getBoard_no()
						+ "%'";
			}
		List<QcmJhySampleConsignM> listm = this.getMapper(QcmJhySampleConsignMMapper.class).getinspection1(qd.getBatch_no(),qd.getInspection_lot(),qd.getBoard_no(),(pm.getPageNumber()-1)*pm.getPageSize(),(pm.getPageNumber()-1)*pm.getPageSize()+pm.getPageSize());
		int count = this.getMapper(QcmJhySampleConsignMMapper.class).countWithCondition(null, Str);
		pm.setRows(listm);
		pm.setTotal(count);
		rm.setData(pm);
	   } catch (Exception e) {
		// TODO: handle exception
		   rm.setState("500");
		   rm.setErrorInfo(e.getMessage());
	}
	   return rm;
   }
   /**
    * 查询项目结果信息
    * @param spe
    * @return
    */
   public ResultModel getResultInfo(String spe){
	   ResultModel rm=new ResultModel();
	   try {
		List<QcmJhySampleConsignDItem> listp = this.getMapper(QcmJhySampleConsignDItemMapper.class).findWithCondition(null, "specimen_no='"+spe+"'", null, 0, 0);
	     for (QcmJhySampleConsignDItem s : listp) {
	    	 String conn="specimen_no='"+s.getSpecimen_no()+"'";
	    	 if (!DataHelper.IsNullOrSpace(s.getPhy_code_l())) {
				conn+=" and phy_code_l='"+s.getPhy_code_l()+"'";
			 }
	    	 if (!DataHelper.IsNullOrSpace(s.getPhy_code_m())) {
	    		 conn+=" and phy_code_m='"+s.getPhy_code_m()+"'";
			 }
	    	 if (!DataHelper.IsNullOrSpace(s.getPhy_code_s())) {
	    		 conn+=" and phy_code_s='"+s.getPhy_code_s()+"'";
		     }
	    	 if (!DataHelper.IsNullOrSpace(s.getItem_code_d())) {
				conn+="and item_code_d='"+s.getItem_code_d()+"'";	
			}
	    	 if (!DataHelper.IsNullOrSpace(s.getItem_code_s())) {
	    		 conn+="and item_code_s='"+s.getItem_code_s()+"'";	
			}
	    	 if (!DataHelper.IsNullOrSpace(s.getItem_code_t())) {
	    		 conn+="and item_code_t='"+s.getItem_code_t()+"'";	
			}
	    	 List<QcmJhyPhyresult> listresult = this.getMapper(QcmJhyPhyresultMapper.class).findWithCondition(null,conn, null, 0, 0);
		    if (listresult!=null&&listresult.size()>0) {
				s.setVal1(listresult.get(0).getVal1());
				s.setVal2(listresult.get(0).getVal2());
				s.setVal3(listresult.get(0).getVal3());
				s.setAvg_val(listresult.get(0).getAvg_val());
			}
	     }
		 rm.setData(listp);
	     rm.setState("200");
	   } catch (Exception e) {
		// TODO: handle exception
		   rm.setErrorInfo(e.getMessage());
		   rm.setState("500");
	}
	   return rm;
   }
   /**
    * 保存项目结果信息----用于材质检验实绩界面（便于没有联通检化验系统时手动录入值）2019.2.20
    * @return
    * 1.判断状态
    * 1.1如果状态为已完成状态则判断改试样号是否已经判定了，如以判定则返回提示，该试样号已判定不能录入值
    * 1.2如果不为已完成状态则保存对应的值，把试样号对应的取样编号改为已完成
    * 
    */
   @Transactional(value = "tm", rollbackFor = Exception.class)
   public ResultModel saveResultInfo(CommonPage<QcmJhyPhyresult> sum){
	   ResultModel rm=new ResultModel();
	   Date now = new Date();
	   String opr_time = new SimpleDateFormat("yyyyMMddHHmmss").format(now); //操作时间
	   String username = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
	   List<QcmJhyPhyresult> list=sum.getObjectList();
	   if (list==null||list.size()<=0) {
		   rm.setState("403");
		   rm.setMsgInfo("请传入参数");
		return rm;
	  }
	   String conn1 = " SMP_NO = '"+list.get(0).getSmp_no()+"' and SPECIMEN_NO = '"+list.get(0).getSpecimen_no()+"'";
	   List<QcmJhySampleConsignD> qjscList = this.getMapper(QcmJhySampleConsignDMapper.class).findWithCondition(null, conn1, null, 0, 0);
	   if("0".equals(qjscList.get(0).getStatus())){
		   rm.setState("403");
		   rm.setMsgInfo("试样号:"+list.get(0).getSmp_no()+"取样编号:"+list.get(0).getSpecimen_no()+"的委托处于未发送状态，无法保存!");
		   return rm;
	   }
	   DecimalFormat deFormat = new DecimalFormat("######0.000");
	   try {
		for (QcmJhyPhyresult qjp : list) {
			if (!DataHelper.IsNullOrSpace(qjp.getSpecimen_no())&&!DataHelper.IsNullOrSpace(qjp.getSmp_no())) {
				//查询状态
				QcmJhySampleConsignD qjs = this.getMapper(QcmJhySampleConsignDMapper.class).findById(qjp.getSmp_no(),qjp.getSpecimen_no());
			    //判定状态
				String conn="specimen_no='"+qjp.getSpecimen_no()+"'";
		    	 if (!DataHelper.IsNullOrSpace(qjp.getPhy_code_l())) {
					conn+=" and phy_code_l='"+qjp.getPhy_code_l()+"'";
				 }
		    	 if (!DataHelper.IsNullOrSpace(qjp.getPhy_code_m())) {
		    		 conn+=" and phy_code_m='"+qjp.getPhy_code_m()+"'";
				 }
		    	 if (!DataHelper.IsNullOrSpace(qjp.getPhy_code_s())) {
		    		 conn+=" and phy_code_s='"+qjp.getPhy_code_s()+"'";
			     }
		    	 if (!DataHelper.IsNullOrSpace(qjp.getItem_code_d())) {
					conn+="and item_code_d='"+qjp.getItem_code_d()+"'";	
				}
		    	 if (!DataHelper.IsNullOrSpace(qjp.getItem_code_s())) {
		    		 conn+="and item_code_s='"+qjp.getItem_code_s()+"'";	
				}
		    	 if (!DataHelper.IsNullOrSpace(qjp.getItem_code_t())) {
		    		 conn+="and item_code_t='"+qjp.getItem_code_t()+"'";	
				}
				if (!DataHelper.IsNullOrSpace(qjs.getStatus())&&!qjs.getStatus().equals("3")&&!qjs.getStatus().equals("0")) {
			    	 List<QcmJhyPhyresult> listresult = this.getMapper(QcmJhyPhyresultMapper.class).findWithCondition(null,conn, null, 0, 0);
					if (listresult!=null&&listresult.size()>0) {//之前已经录入过，进行更新操作
						
						//平均值
						int count = 0;
					    Double sum1 = 0d;
					    if (!DataHelper.IsNullOrSpace(qjp.getVal1())) {
					    	count++;
					    	sum1 += Double.parseDouble(qjp.getVal1());
					    }
					    if (!DataHelper.IsNullOrSpace(qjp.getVal2())) {
					    	count++;
					    	sum1 += Double.parseDouble(qjp.getVal2());
					    }
					    if (!DataHelper.IsNullOrSpace(qjp.getVal3())) {
					    	count++;
					    	sum1 += Double.parseDouble(qjp.getVal3());
					    }
					    if (count > 1) {
					    	Double avg = (sum1 / count);
					    	qjp.setAvg_val(deFormat.format(avg));
					    }
					    //值一值二值三平均值修约
					    //roundingValForSave(qjp.getPhy_code_s(), qjp);
					    if (DataHelper.IsNullOrSpace(qjp.getVal1())) {
							qjp.setVal1("");
						}
						if (DataHelper.IsNullOrSpace(qjp.getVal2())) {
							qjp.setVal2("");				
						}
						if (DataHelper.IsNullOrSpace(qjp.getVal3())) {
							qjp.setVal3("");
						}
						if (DataHelper.IsNullOrSpace(qjp.getAvg_val())) {
							qjp.setAvg_val("");
						}
						this.getMapper(QcmJhySampleConsignDMapper.class).
						updateResultVal(qjp.getVal1(),qjp.getVal2(),qjp.getVal3(),qjp.getSpecimen_no(),qjp.getPhy_code_l(),qjp.getPhy_code_m(),qjp.getPhy_code_s(),qjp.getItem_code_d(),qjp.getItem_code_t(),qjp.getItem_code_s(),qjp.getAvg_val());
					}else {//进行插入操作
						qjp.setTest_qty((long)1);
						//平均值
						int count = 0;
					    Double sum1 = 0d;
					    if (!DataHelper.IsNullOrSpace(qjp.getVal1())) {
					    	count++;
					    	sum1 += Double.parseDouble(qjp.getVal1());
					    }
					    if (!DataHelper.IsNullOrSpace(qjp.getVal2())) {
					    	count++;
					    	sum1 += Double.parseDouble(qjp.getVal2());
					    }
					    if (!DataHelper.IsNullOrSpace(qjp.getVal3())) {
					    	count++;
					    	sum1 += Double.parseDouble(qjp.getVal3());
					    }
					    if (count > 1) {
					    	Double avg = (sum1 / count);
					    	qjp.setAvg_val(deFormat.format(avg));
					    }
					    //值一值二值三平均值修约
					    //roundingValForSave(qjp.getPhy_code_s(), qjp);
						this.getMapper(QcmJhyPhyresultMapper.class).insert(qjp);
					}
//					 this.getMapper(QcmJhySampleConsignDMapper.class).deleteinfo(qjp.getSpecimen_no());
					//不是已完成状态，直接录入值
					//改变试样号向下取样编号的状态为已完成
					//判断必判项目是否都有值了,如都有值，则把状态改为已完成
					boolean flag=true;
					ResultModel resultInfo = getResultInfo(qjp.getSpecimen_no());
					List<QcmJhySampleConsignDItem> listi=(List<QcmJhySampleConsignDItem>) resultInfo.getData();
					for (QcmJhySampleConsignDItem d : listi) {
						List<QcmJhySampleConsignDItem> qjsList = this.getMapper(QcmJhySampleConsignDItemMapper.class).findWithCondition(null, "and SPECIMEN_NO='"+d.getSpecimen_no()+"' and GROUP_SEQ='"+d.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(d.getVal1())&&DataHelper.IsNullOrSpace(d.getVal2())&&DataHelper.IsNullOrSpace(d.getVal3()) && (DataHelper.IsNullOrSpace(d.getGroup_seq()) || !groupFlag) && !"0".equals(d.getIsjudge())) {
							flag=false;
							break;
						}
					}
					if (flag) {
						QcmJhySampleConsignD qjsd=new QcmJhySampleConsignD();
						qjsd.setSmp_no(qjp.getSmp_no());
						qjsd.setSpecimen_no(qjp.getSpecimen_no());
						qjsd.setMaterial_no(qjp.getMaterial_no());
						qjsd.setStatus("3");
						this.getMapper(QcmJhySampleConsignDMapper.class).update(qjsd);
					}else {
						QcmJhySampleConsignD qjsd=new QcmJhySampleConsignD();
						qjsd.setSmp_no(qjp.getSmp_no());
						qjsd.setSpecimen_no(qjp.getSpecimen_no());
						qjsd.setMaterial_no(qjp.getMaterial_no());
						qjsd.setStatus("2");
						this.getMapper(QcmJhySampleConsignDMapper.class).update(qjsd);
					}
				}else if(!DataHelper.IsNullOrSpace(qjs.getStatus())&&qjs.getStatus().equals("3")){
					//判断试样号是否已经判定，如判定则返回
					List<QcmJhySampleROrd> listord = this.getMapper(QcmJhySampleROrdMapper.class).findWithCondition(null, "smp_no='"+qjp.getSmp_no()+"'", null, 0, 0);
				    if (listord!=null&&listord.size()>0) {
				    	//20201104 材质实绩保存后可以重新修改，但是要求质量人员自己进行手动质量判定 
						//if (!DataHelper.IsNullOrSpace(listord.get(0).getJudge_status())&&"0".equals(listord.get(0).getJudge_status())) {
							//未判定数据，则进行保存操作							
							List<QcmJhyPhyresult> listresult = this.getMapper(QcmJhyPhyresultMapper.class).findWithCondition(null,conn, null, 0, 0);
							if (listresult!=null&&listresult.size()>0) {//之前已经录入过，进行更新操作
								//平均值
								int count = 0;
							    Double sum1 = 0d;
							    if (!DataHelper.IsNullOrSpace(qjp.getVal1())) {
							    	count++;
							    	sum1 += Double.parseDouble(qjp.getVal1());
							    }
							    if (!DataHelper.IsNullOrSpace(qjp.getVal2())) {
							    	count++;
							    	sum1 += Double.parseDouble(qjp.getVal2());
							    }
							    if (!DataHelper.IsNullOrSpace(qjp.getVal3())) {
							    	count++;
							    	sum1 += Double.parseDouble(qjp.getVal3());
							    }
							    if (count > 1) {
							    	Double avg = (sum1 / count);
							    	qjp.setAvg_val(deFormat.format(avg));
							    }
							    //值一值二值三平均值修约
							    //roundingValForSave(qjp.getPhy_code_s(), qjp);
							    if (DataHelper.IsNullOrSpace(qjp.getVal1())) {
									qjp.setVal1("");
								}
								if (DataHelper.IsNullOrSpace(qjp.getVal2())) {
									qjp.setVal2("");				
								}
								if (DataHelper.IsNullOrSpace(qjp.getVal3())) {
									qjp.setVal3("");
								}
								if (DataHelper.IsNullOrSpace(qjp.getAvg_val())) {
									qjp.setAvg_val("");
								}
								this.getMapper(QcmJhySampleConsignDMapper.class).
								updateResultVal(qjp.getVal1(),qjp.getVal2(),qjp.getVal3(),qjp.getSpecimen_no(),qjp.getPhy_code_l(),qjp.getPhy_code_m(),qjp.getPhy_code_s(),qjp.getItem_code_d(),qjp.getItem_code_t(),qjp.getItem_code_s(),qjp.getAvg_val());
							}else {//进行插入操作
								qjp.setTest_qty((long)1);
								//平均值
								int count = 0;
							    Double sum1 = 0d;
							    if (!DataHelper.IsNullOrSpace(qjp.getVal1())) {
							    	count++;
							    	sum1 += Double.parseDouble(qjp.getVal1());
							    }
							    if (!DataHelper.IsNullOrSpace(qjp.getVal2())) {
							    	count++;
							    	sum1 += Double.parseDouble(qjp.getVal2());
							    }
							    if (!DataHelper.IsNullOrSpace(qjp.getVal3())) {
							    	count++;
							    	sum1 += Double.parseDouble(qjp.getVal3());
							    }
							    if (count > 1) {
							    	Double avg = (sum1 / count);
							    	qjp.setAvg_val(deFormat.format(avg));
							    }
							    //值一值二值三平均值修约
							    //roundingValForSave(qjp.getPhy_code_s(), qjp);
								this.getMapper(QcmJhyPhyresultMapper.class).insert(qjp);
							}
							
							
							boolean flag=true;
							ResultModel resultInfo = getResultInfo(qjp.getSpecimen_no());
							List<QcmJhySampleConsignDItem> listi=(List<QcmJhySampleConsignDItem>) resultInfo.getData();
							for (QcmJhySampleConsignDItem d : listi) {
								List<QcmJhySampleConsignDItem> qjsList = this.getMapper(QcmJhySampleConsignDItemMapper.class).findWithCondition(null, "and SPECIMEN_NO='"+d.getSpecimen_no()+"' and GROUP_SEQ='"+d.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(d.getVal1())&&DataHelper.IsNullOrSpace(d.getVal2())&&DataHelper.IsNullOrSpace(d.getVal3()) && (DataHelper.IsNullOrSpace(d.getGroup_seq()) || !groupFlag) && !"0".equals(d.getIsjudge())) {
									flag=false;
									break;
								}
							}
							if (flag) {
								QcmJhySampleConsignD qjsd=new QcmJhySampleConsignD();
								qjsd.setSmp_no(qjp.getSmp_no());
								qjsd.setSpecimen_no(qjp.getSpecimen_no());
								qjsd.setMaterial_no(qjp.getMaterial_no());
								qjsd.setStatus("3");
								this.getMapper(QcmJhySampleConsignDMapper.class).update(qjsd);
							}else {
								QcmJhySampleConsignD qjsd=new QcmJhySampleConsignD();
								qjsd.setSmp_no(qjp.getSmp_no());
								qjsd.setSpecimen_no(qjp.getSpecimen_no());
								qjsd.setMaterial_no(qjp.getMaterial_no());
								qjsd.setStatus("2");
								this.getMapper(QcmJhySampleConsignDMapper.class).update(qjsd);
							}
						/*}else {
							//已判，不能保存值，返回提示信息
							rm.setState("403");
							rm.setMsgInfo(qjp.getSmp_no()+"对应的取样编号已经进行判定，不支持重复录入值");
						   return rm;
						}*/
					}
				}
			}
		}
		// 增加日志记录：20230104 刘侣
		//日志
	    MesOprLog mol = new MesOprLog("质量管理", "检验实绩查询", "材质实绩保存", username, opr_time, list.get(0).getMaterial_no(), null, null, null, "取样产品序号：" + list.get(0).getMaterial_no());
	    this.getMapper(MesOprLogMapper.class).insert(mol);
	    // end
		rm.setState("200");
	} catch (Exception e) {
		rm.setState("500");
		rm.setErrorInfo(e.getMessage());
		TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
	}
	   return rm;
   }
   /**
	 * 查询对应项目实测值，标准值
	 */
	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;
	}
	  /**
	    * 查询已发送数据（检验信息用） 2018.12.20
	    * @param sum
	    * @return
	    */
	  public ResultModel getDSampleInfoByConsin_no(CommonPage<QcmJhySampleConsignD> sum){
		   ResultModel rm=new ResultModel();
		   QcmJhySampleConsignD qjd=sum.getObject();
		   try {
			   String conn="";
			   //产线
			   if (!DataHelper.IsNullOrSpace(qjd.getPline_name())) {
				conn+=" and pline_name like '%"+qjd.getPline_name()+"%'";
			}
			   //委托编号
			   if (!DataHelper.IsNullOrSpace(qjd.getConsign_no())) {
				   conn+=" and consign_no like '%"+qjd.getConsign_no()+"%'";
			}
			   //开始时间
			   if(sum.getStartTime()!=null&&!sum.getStartTime().equals("")){
					conn+=" and send_time>=to_date(concat('"+sum.getStartTime()+"',' 00:00:00'),'yyyy-MM-dd HH24:mi:ss')"; 
				}
			 //结束时间
				if(sum.getEndTime()!=null&&!sum.getEndTime().equals("")){
					conn+=" and send_time<=to_date(concat('"+sum.getEndTime()+"',' 23:59:59'),'yyyy-MM-dd HH24:mi:ss') ";
				}
			List<QcmJhySampleConsignD> listd = this.getMapper(QcmJhySampleConsignDMapper.class).dogetDInfo(conn);
			rm.setState("200");
			rm.setData(listd);
		} catch (Exception e) {
			// TODO: handle exception
			rm.setState("500");
			rm.setErrorInfo(e.getMessage());
		}
		   return rm;
	   }
	   /**
	    * 根据委托编号查询已发送数据（检验信息用）----2018.12.20
	    * @param consing_no
	    * @return
	    */
	   public ResultModel getDInfo(String consing_no){
		   ResultModel rm=new ResultModel();
		   if (DataHelper.IsNullOrSpace(consing_no)) {
			rm.setState("403");
			rm.setMsgInfo("请传入参数");
			return rm;
		   }
		   try {
			List<QcmJhySampleConsignD> getinfo = this.getMapper(QcmJhySampleConsignDMapper.class).getinfo(consing_no);
			for (QcmJhySampleConsignD l : getinfo) {
				  List<String> liststr=new ArrayList<>();
		    	List<QcmJhySampleConsignDItem> listI = this.getMapper(QcmJhySampleConsignDItemMapper.class).findWithCondition(null, "specimen_no='"+l.getSpecimen_no()+"'", null, 0, 0);
			   String JYDX="";
			   if (listI!=null&&listI.size()>0) {
		    	for (QcmJhySampleConsignDItem i : listI) {
					if (!DataHelper.IsNullOrSpace(i.getPhy_name_l())&&!liststr.contains(i.getPhy_name_l())) {
						JYDX+=i.getPhy_name_l()+",";
						liststr.add(i.getPhy_name_l());
					}
				}
		    	if (!DataHelper.IsNullOrSpace(JYDX)&&",".equals(JYDX.substring(JYDX.length()-1, JYDX.length()))) {
					l.setJYDX(JYDX.substring(0,JYDX.length()-1));
					System.out.println(JYDX.substring(0,JYDX.length()-1));
				}else {
					l.setJYDX(JYDX);
				}
			   }
		    }
			rm.setData(getinfo);
		    rm.setState("200");
		   } catch (Exception e) {
			// TODO: handle exception
			   rm.setState("500");
			   rm.setErrorInfo(e.getMessage());
		}
		   return rm;
	   }
	   /**
	    * 查询试样类型下拉信息（检验信息界面用） 2018.12.26
	    * @return
	    */
	   public ResultModel getSampleClass(){
		   ResultModel rm=new ResultModel();
		   try {
			List<ComBaseInfo> listcbi = this.getMapper(ComBaseInfoMapper.class).findWithCondition(null, "sort_code='4094'", null, 0, 0);
		     rm.setState("200");
		     rm.setData(listcbi);
		   } catch (Exception e) {
			// TODO: handle exception
			   rm.setState("500");
			   rm.setErrorInfo(e.getMessage());
		}
		   return rm;
	   }
	   /**
	    * 获取认证机构下拉信息（检验信息界面用） 2018.12.26
	    * @return
	    */
	   public ResultModel getCertificationInfo(){
		   ResultModel rm=new ResultModel();
		   try {
			   List<ComBaseInfo> listcbi = this.getMapper(ComBaseInfoMapper.class).findWithCondition(null, "sort_code='4096'", null, 0, 0);
			     rm.setState("200");
			     rm.setData(listcbi);
		} catch (Exception e) {
			// TODO: handle exception
			 rm.setState("500");
			   rm.setErrorInfo(e.getMessage());
		}
		   return rm;
	   }
	   /**
	    * 检验信息界面模拟发送功能生成检验委托记录
	    * @param smp 试样号
	    * @param spe 取样编号
	    * @return
	    */
	   public ResultModel createConsign_no(String smp,String spe) {
		   ResultModel rm=new ResultModel();
		   if (DataHelper.IsNullOrSpace(smp)||DataHelper.IsNullOrSpace(spe)) {
			 rm.setState("403");
			 rm.setMsgInfo("请传入参数");
			 return rm;
		  }
		   String wtbh="";
		   int icount = 0;
		   try {
			// 生成委托编号
				List<QcmJhySampleConsignD> qdtlist = this.getMapper(
						QcmJhySampleConsignDMapper.class).findWithCondition(null,
						"CONSIGN_NO is not null", "CONSIGN_NO DESC", 0, 1);
				if (qdtlist != null && qdtlist.size() > 0) {
					String s = qdtlist.get(0).getConsign_no();
					icount = Integer.parseInt(s.substring(s.length() - 3,
							s.length()));
				}
				SimpleDateFormat sdf = new SimpleDateFormat("yyMMdd");
				String da = sdf.format(new Date());
				icount++;
				wtbh= da + String.format("%03d", icount);
				QcmJhySampleConsignD qjsd=new QcmJhySampleConsignD();
				qjsd.setSpecimen_no(spe);
				qjsd.setSmp_no(smp);
				qjsd.setConsign_no(wtbh);
				String strseq = spe.substring(spe.length()-1);
				long seq=Long.parseLong(strseq) ;
				qjsd.setConsign_no_seq(seq);
				qjsd.setSend_name((String)this.getSession().getAttribute(HomeService.SESSION_USER_NAME));
				qjsd.setSend_time(new Date());
				this.getMapper(QcmJhySampleConsignDMapper.class).update(qjsd);
				rm.setState("200");
		} catch (Exception e) {
			// TODO: handle exception
			rm.setState("500");
		}
			
			return rm;
	   }
	   
		/**
		 * 保存时进行修约
		 */
		public void roundingValForSave(String phyCodeS,QcmJhyPhyresult qjp){
			ComBasePhy cbp = this.getMapper(ComBasePhyMapper.class).findById(phyCodeS);
			//判断修约位数是否为空，为空则默认保留两位（一般情况是不为空，可能出现为空的情况）
			if (cbp != null && cbp.getRound_off_digits()!= null && !DataHelper.IsNullOrSpace(cbp.getRound_off_digits().toString())) {
				int a=cbp.getRound_off_digits();
				String str="";
				int b=0;
				for (int i = 0; i < a; i++) {
					if (b==0) {
						str+=".";
						str+="0";
						b++;
					}else {
						str+="0";
					}
				}
				DecimalFormat df = new DecimalFormat("#0"+str);
				if (!DataHelper.IsNullOrSpace(qjp.getVal1())) {
					double val1=Double.parseDouble(qjp.getVal1());
					 qjp.setVal1(df.format(val1));
				}
				if (!DataHelper.IsNullOrSpace(qjp.getVal2())) {
					double val2=Double.parseDouble(qjp.getVal2());
					 qjp.setVal2(df.format(val2));
				}
				if (!DataHelper.IsNullOrSpace(qjp.getVal3())) {
					double val3=Double.parseDouble(qjp.getVal3());
					 qjp.setVal3(df.format(val3));
				}
				if (!DataHelper.IsNullOrSpace(qjp.getAvg_val())) {
					double avg=Double.parseDouble(qjp.getAvg_val());
					 qjp.setAvg_val(df.format(avg));
				}
			}else {
//				DecimalFormat df = new DecimalFormat("#0.00");
//				if (!DataHelper.IsNullOrSpace(qjp.getVal1())) {
//					double val1=Double.parseDouble(qjp.getVal1());
//					 qjp.setVal1(df.format(val1));
//				}
//				if (!DataHelper.IsNullOrSpace(qjp.getVal2())) {
//					double val2=Double.parseDouble(qjp.getVal2());
//					 qjp.setVal2(df.format(val2));
//				}
//				if (!DataHelper.IsNullOrSpace(qjp.getVal3())) {
//					double val3=Double.parseDouble(qjp.getVal3());
//					 qjp.setVal3(df.format(val3));
//				}
//				if (!DataHelper.IsNullOrSpace(qjp.getAvg_val())) {
//					double avg=Double.parseDouble(qjp.getAvg_val());
//					 qjp.setAvg_val(df.format(avg));
//				}
		}
	}
}
