/***文档注释***********************************************
 * 作者               :                   刘学
 * 创建日期      :                   2017.12.4
 * 描述               :        			质量接口
 * 注意事项      :                   无
 * 遗留BUG :                   无
 * 修改日期      :                   
 * 修改人员      :                   
 * 修改内容      :                   
***********************************************************/
package market.Api.Qms.impl;

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

import market.Api.Qms.service.QmsApiService;
import market.Api.Qms.vo.ComMscStdChem;
import market.Api.Qms.vo.ComMscStdDetectionC;
import market.Api.Qms.vo.ComMscStdPhy;
import market.Api.Qms.vo.ComMscStdSpecC;
import market.Api.Qms.vo.DetailMsc;
import market.Api.Qms.vo.JudgeResult;
import market.Api.Slm.impl.SlmApiServiceImpl;
import market.Com.mapper.ComBaseChemMapper;
import market.Com.mapper.ComBasePhyBMapper;
import market.Com.mapper.ComBasePhyCMapper;
import market.Com.mapper.ComBasePhyMapper;
import market.Com.mapper.ComBasePhyRPosMapper;
import market.Com.mapper.ComBaseStationMapper;
import market.Com.mapper.ComPscMapper;
import market.Com.mapper.ComPscRDeliveryMapper;
import market.Com.mapper.ComPscRSpecMapper;
import market.Com.vo.ComBaseChem;
import market.Com.vo.ComBaseInfo;
import market.Com.vo.ComBasePhy;
import market.Com.vo.ComBasePhyB;
import market.Com.vo.ComBasePhyC;
import market.Com.vo.ComBasePhyRItem;
import market.Com.vo.ComBasePhyRPos;
import market.Com.vo.ComBaseStation;
import market.Com.vo.ComPsc;
import market.Com.vo.ComPscRDelivery;
import market.Com.vo.ComPscROrg;
import market.Com.vo.ComPscRSpec;
import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;
import market.Lms.Warehouse.mapper.YdmProductDetailMapper;
import market.Lms.Warehouse.vo.YdmProductDetail;
import market.Qms.com.mapper.BaseInfoMapper;
import market.Qms.com.service.impl.ComBaseConfigServiceImpl;
import market.Qms.com.vo.BaseInfo;
import market.Qms.common.DataHelper;
import market.Qms.common.ReturnMsg;
import market.Qms.metallurgy.mapper.ComBaseAskRStationMapper;
import market.Qms.metallurgy.mapper.ComBaseStdMapper;
import market.Qms.metallurgy.mapper.ComMscMapper;
import market.Qms.qcm.mapper.JhySampleChemDMapper;
import market.Qms.qcm.mapper.JhySampleChemMMapper;
import market.Qms.qcm.mapper.JhySampleConsignDMapper;
import market.Qms.qcm.mapper.JhySampleConsignMMapper;
import market.Qms.qcm.mapper.QcmJhyElementsMapper;
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.QcmJudgeMeasureMapper;
import market.Qms.qcm.mapper.QcmJudgePhysicalUtmDMapper;
import market.Qms.qcm.mapper.QcmJudgeSurfaceFlawMapper;
import market.Qms.qcm.mapper.QcmJudgeSurfaceMapper;
import market.Qms.qcm.mapper.QcmPhyJudgeResultMapper;
import market.Qms.qcm.mapper.QcmPhyResultMapper;
import market.Qms.qcm.service.impl.QcmJhySampleConsignDItemServiceImpl;
import market.Qms.qcm.service.impl.QcmJudgeMeasureServiceImpl;
import market.Qms.qcm.vo.JhySampleChemD;
import market.Qms.qcm.vo.JhySampleChemM;
import market.Qms.qcm.vo.JhySampleConsignD;
import market.Qms.qcm.vo.JhySampleConsignDItem;
import market.Qms.qcm.vo.JhySampleConsignM;
import market.Qms.qcm.vo.JhySampleROrd;
import market.Qms.qcm.vo.QcmJhyElements;
import market.Qms.qcm.vo.QcmJhyPhyresult;
import market.Qms.qcm.vo.QcmJhySampleConsignD;
import market.Qms.qcm.vo.QcmJhySampleConsignDItem;
import market.Qms.qcm.vo.QcmJhySampleConsignM;
import market.Qms.qcm.vo.QcmJhySampleFromPlan;
import market.Qms.qcm.vo.QcmJhySampleROrd;
import market.Qms.qcm.vo.QcmJudgeMeasure;
import market.Qms.qcm.vo.QcmJudgePhysicalUtmD;
import market.Qms.qcm.vo.QcmJudgeSurface;
import market.Qms.qcm.vo.QcmJudgeSurfaceFlaw;
import market.Qms.qcm.vo.QcmPhyJudgeResult;
import market.Qms.qcm.vo.QcmPhyResult;
import market.Qms.slmord.impl.SlmOrdDesignStdPicServiceImpl;
import market.Qms.slmord.mapper.SlmOrdDesignMscMapper;
import market.Qms.slmord.mapper.SlmOrdDesignMscPlMapper;
import market.Qms.slmord.mapper.SlmOrdDesignMscPlStiMapper;
import market.Qms.slmord.mapper.SlmOrdDesignMscTicItemMapper;
import market.Qms.slmord.mapper.SlmOrdDesignMscTicMapper;
import market.Qms.slmord.mapper.SlmOrdDesignStdMapper;
import market.Qms.slmord.mapper.SlmOrdDesignStdPicSmpMapper;
import market.Qms.slmord.mapper.SlmOrdDesignStsTklgMapper;
import market.Qms.slmord.vo.SlmOrdDesignAdditional;
import market.Qms.slmord.vo.SlmOrdDesignMsc;
import market.Qms.slmord.vo.SlmOrdDesignMscPl;
import market.Qms.slmord.vo.SlmOrdDesignMscPlSti;
import market.Qms.slmord.vo.SlmOrdDesignMscTic;
import market.Qms.slmord.vo.SlmOrdDesignMscTicItem;
import market.Qms.slmord.vo.SlmOrdDesignStd;
import market.Qms.slmord.vo.SlmOrdDesignStdPicSmp;
import market.Qms.slmord.vo.SlmOrdDesignStsTklg;

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.service.support.PageModel;
import com.hnshituo.basic.spring.remoting.annotation.RemoteService;

@RemoteService(path = "QmsApiService")
public class QmsApiServiceImpl extends BaseServiceImpl implements QmsApiService {
	private String PROCESS_POINT_TYPE="403206";
	public ResultModel GetRoundOffRules(){
		ResultModel rm=new ResultModel();
		try{
			BaseInfo info=new BaseInfo();
			info.setSortCode("4108");
			info.setValidflag("1");
			List<BaseInfo> list= this.getMapper(BaseInfoMapper.class).find(info, 0, 0);
			rm.setData(list);
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("获取修约规则出错："+ex.getMessage());
		}
		return rm;
	}
	
	public ResultModel GetProductTypeM(){
		ResultModel rm=new ResultModel();
		try{
			BaseInfo info=new BaseInfo();
			info.setSortCode("4109");
			info.setValidflag("1");
			List<BaseInfo> list= this.getMapper(BaseInfoMapper.class).find(info, 0, 0);
			rm.setData(list);
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("获取产品中类出错："+ex.getMessage());
		}
		return rm;
	}
	
	public ResultModel GetProductTypeS(){
		ResultModel rm=new ResultModel();
		try{
			BaseInfo info=new BaseInfo();
			info.setSortCode("4110");
			info.setValidflag("1");
			List<BaseInfo> list= this.getMapper(BaseInfoMapper.class).find(info, 0, 0);
			rm.setData(list);
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("获取产品小类出错："+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 获取工序点关联附加要求项
	 * @param com
	 * @return
	 */
//	public ResultModel GetOrdDesignAdditional(CommonPage<SlmOrdDesignMscPlSti> com){
//		ResultModel rm=this.getMapper(SlmOrdDesignAdditionalServiceImpl.class).GetAllByPlan(com);
//		return rm;
//	}
	
	
	/**
	 * 提供给计划模块组坯完成时调用 自动创建材质检验委托处理逻辑
	 * 
	 */
	

	@Transactional(value = "tm", rollbackFor = Exception.class)
	public ResultModel AutoGenerationPhySampleInfo(CommonPage<JhySampleROrd> cp) {

		ResultModel rm = new ResultModel();

		List<JhySampleROrd> OrderPk = cp.getObjectList();
		List<JhySampleConsignM> SmpNo = new ArrayList<JhySampleConsignM>();
		for (JhySampleROrd ord : OrderPk) {
			List<String> bb = new ArrayList<String>(); // 认证机构

			bb.add("123");// 调销售接口 获取认证机构
			// bb.add("456");
			// String DESGIN_KEY =
			// this.getMapper(JhySampleConsignMMapper.class).QuerybyPk(ord.getContractLineNo());

			String Smp = this.getMapper(JhySampleConsignMMapper.class).doSelectSam(ord.getContractLineNo());

			String[] aa = Smp.split("\\,"); // 试样类型

			// 生成主表 合同关联表
			for (String b1 : bb) {
				for (int i = 0; i < aa.length; i++) {
					JhySampleConsignM JhySamp = new JhySampleConsignM();
					JhySampleROrd JhyOrd = new JhySampleROrd();

					String Jhy_no = this.getMapper(JhySampleConsignMMapper.class).GetMaxCode();

					JhySamp.setSmpNo(Jhy_no);
					JhySamp.setBatchNo(cp.getMemo1());
					JhySamp.setHeatNo(cp.getMemo2());
					JhySamp.setCertInstCode(b1);
					JhySamp.setCertInstName(b1);
					JhySamp.setCreateTime(new Date());
					JhySamp.setSmpTypeCode(aa[i].toString());
					JhySamp.setSmpTypeName(aa[i].toString());
					JhySamp.setValidflag("1");

					this.getMapper(JhySampleConsignMMapper.class).insert(JhySamp);

					SmpNo.add(JhySamp);

					JhyOrd.setSmpNo(Jhy_no);
					JhyOrd.setBatchNo(JhySamp.getBatchNo());
					JhyOrd.setCertInstCode(JhySamp.getCertInstCode());
					JhyOrd.setCertInstName(JhySamp.getCertInstName());
					JhyOrd.setContractLineNo(ord.getContractLineNo());
					JhyOrd.setHeatNo(JhySamp.getHeatNo());
					JhyOrd.setIsview("0");
					JhyOrd.setJudgeMemo("");
					JhyOrd.setJudgeName("");
					JhyOrd.setJudgeResult("");

					JhyOrd.setJudgeTime(new Date());
					JhyOrd.setPicId("");
					JhyOrd.setSmpNo(JhySamp.getSmpNo());
					JhyOrd.setSmpTypeCode(JhySamp.getSmpTypeCode());
					JhyOrd.setSmpTypeName(JhySamp.getSmpTypeName());

					this.getMapper(JhySampleConsignMMapper.class).doInsertOrd(JhyOrd);

				}
			}
		}
		int i = 0;
		for (JhySampleConsignM jhyno : SmpNo) {

			// 获取取样频率
			List<JhySampleConsignM> lst1 = this.getMapper(JhySampleConsignMMapper.class)
					.doSelectRATE_A(jhyno.getSmpNo());

			JhySampleConsignD JhySampD = new JhySampleConsignD();
			JhySampleConsignDItem JhySampItem = new JhySampleConsignDItem();

			if (lst1 != null && lst1.size() > 0) {
				for (JhySampleConsignM lst2 : lst1) {

					String specimenNo = this.getMapper(JhySampleConsignDMapper.class).GetMaxCode3Zd(1);
					if (lst2.getCertInstCode().equals("408601")) {

						List<JhySampleConsignD> jhydd = this.getMapper(JhySampleConsignDMapper.class).QuerySpecbySql(
								jhyno.getHeatNo(), jhyno.getCertInstCode(), jhyno.getSmpTypeCode(),
								lst2.getSmpTypeName(), lst2.getCertInstCode());
						if (jhydd != null && jhydd.size() > 0) {
							List<JhySampleConsignD> jhyddit = this.getMapper(JhySampleConsignDMapper.class)
									.QueryItmebySql(jhyno.getSmpNo(), jhydd.get(0).getSpecimenNo());

							if (jhyddit == null || jhyddit.size() == 0) {
								JhySampD.setQuoteConsignNo(jhydd.get(0).getSpecimenNo());

								JhySampleConsignD JhySampDA = new JhySampleConsignD();
								JhySampDA.setSpecimenNo(jhydd.get(0).getSpecimenNo());
								JhySampDA.setStatus("4");
								this.getMapper(JhySampleConsignDMapper.class).update(JhySampDA);
							}
						}

						String CONSIGN_NO = this.getMapper(JhySampleConsignDMapper.class).GetMaxCodeZd(1);
						String Seq = this.getMapper(JhySampleConsignDMapper.class).GetMaxSEQ(jhyno.getSmpNo());
						List<JhySampleConsignD> ddq = this.getMapper(JhySampleConsignDMapper.class)
								.doSelectPhyDitem(jhyno.getSmpNo());
						if (ddq != null && ddq.size() > 0) {
							JhySampD.setAllItemCode(ddq.get(0).getAllItemCode());
							JhySampD.setAllItemName(ddq.get(0).getAllItemName());
						}
						JhySampD.setSmpNo(jhyno.getSmpNo());
						JhySampD.setConsignNo(CONSIGN_NO);
						JhySampD.setSpecimenNo(specimenNo);
						JhySampD.setBatchNo(cp.getMemo1());
						JhySampD.setHeatNo(cp.getMemo2());
						JhySampD.setFreqCode(lst2.getCertInstCode());
						JhySampD.setFreqName(lst2.getCertInstName());

						this.getMapper(JhySampleConsignDMapper.class).insert(JhySampD);

						this.getMapper(JhySampleConsignDMapper.class).doInsertDItem(jhyno.getSmpNo(), Seq, specimenNo);
					} else if (lst2.getCertInstCode().equals("408602")) {
						List<JhySampleConsignD> jhydd = this.getMapper(JhySampleConsignDMapper.class).QuerySpecbySqlP(
								jhyno.getBatchNo(), jhyno.getCertInstCode(), jhyno.getSmpTypeCode(),
								lst2.getSmpTypeName(), lst2.getCertInstCode());
						if (jhydd != null && jhydd.size() > 0) {
							List<JhySampleConsignD> jhyddit = this.getMapper(JhySampleConsignDMapper.class)
									.QueryItmebySql(jhyno.getSmpNo(), jhydd.get(0).getSpecimenNo());

							if (jhyddit == null || jhyddit.size() == 0) {
								JhySampD.setQuoteConsignNo(jhydd.get(0).getSpecimenNo());

								JhySampleConsignD JhySampDA = new JhySampleConsignD();
								JhySampDA.setSpecimenNo(jhydd.get(0).getSpecimenNo());
								JhySampDA.setStatus("4");
								this.getMapper(JhySampleConsignDMapper.class).update(JhySampDA);
							}
						}

						String CONSIGN_NO = this.getMapper(JhySampleConsignDMapper.class).GetMaxCodeZd(1);
						String Seq = this.getMapper(JhySampleConsignDMapper.class).GetMaxSEQ(jhyno.getSmpNo());
						List<JhySampleConsignD> ddq = this.getMapper(JhySampleConsignDMapper.class)
								.doSelectPhyDitem(jhyno.getSmpNo());
						if (ddq != null && ddq.size() > 0) {
							JhySampD.setAllItemCode(ddq.get(0).getAllItemCode());
							JhySampD.setAllItemName(ddq.get(0).getAllItemName());
						}
						JhySampD.setSmpNo(jhyno.getSmpNo());
						JhySampD.setConsignNo(CONSIGN_NO);
						JhySampD.setSpecimenNo(specimenNo);
						JhySampD.setBatchNo(cp.getMemo1());
						JhySampD.setHeatNo(cp.getMemo2());
						JhySampD.setFreqCode(lst2.getCertInstCode());
						JhySampD.setFreqName(lst2.getCertInstName());

						this.getMapper(JhySampleConsignDMapper.class).insert(JhySampD);

						this.getMapper(JhySampleConsignDMapper.class).doInsertDItem(jhyno.getSmpNo(), Seq, specimenNo);

					} else if (lst2.getCertInstCode().equals("408603")) {
						List<JhySampleConsignD> jhydd = this.getMapper(JhySampleConsignDMapper.class).QuerySpecbySqlP(
								jhyno.getBatchNo(), jhyno.getCertInstCode(), jhyno.getSmpTypeCode(),
								lst2.getSmpTypeName(), lst2.getCertInstCode());
						if (jhydd != null && jhydd.size() > 0) {
							List<JhySampleConsignD> jhyddit = this.getMapper(JhySampleConsignDMapper.class)
									.QueryItmebySql(jhyno.getSmpNo(), jhydd.get(0).getSpecimenNo());

							if (jhyddit == null || jhyddit.size() == 0) {
								JhySampD.setQuoteConsignNo(jhydd.get(0).getSpecimenNo());

								JhySampleConsignD JhySampDA = new JhySampleConsignD();
								JhySampDA.setSpecimenNo(jhydd.get(0).getSpecimenNo());
								JhySampDA.setStatus("4");
								this.getMapper(JhySampleConsignDMapper.class).update(JhySampDA);
							}
						}
						List<JhySampleConsignD> getZp = new ArrayList<JhySampleConsignD>();
						getZp.add(JhySampD); // 调用计划提供的接口获取获取子板
						if (getZp != null && getZp.size() > 0) {
							for (JhySampleConsignD ConD : getZp) {
								String specimenNoA = this.getMapper(JhySampleConsignDMapper.class).GetMaxCode3Zd(1);
								String CONSIGN_NO = this.getMapper(JhySampleConsignDMapper.class).GetMaxCodeZd(1);
								String Seq = this.getMapper(JhySampleConsignDMapper.class).GetMaxSEQ(jhyno.getSmpNo());
								List<JhySampleConsignD> ddq = this.getMapper(JhySampleConsignDMapper.class)
										.doSelectPhyDitem(jhyno.getSmpNo());
								if (ddq != null && ddq.size() > 0) {
									JhySampD.setAllItemCode(ddq.get(0).getAllItemCode());
									JhySampD.setAllItemName(ddq.get(0).getAllItemName());
								}
								JhySampD.setSmpNo(jhyno.getSmpNo());
								JhySampD.setConsignNo(CONSIGN_NO);
								JhySampD.setSpecimenNo(specimenNoA);
								JhySampD.setBatchNo(cp.getMemo1());
								JhySampD.setHeatNo(cp.getMemo2());
								JhySampD.setFreqCode(lst2.getCertInstCode());
								JhySampD.setFreqName(lst2.getCertInstName());

								this.getMapper(JhySampleConsignDMapper.class).insert(JhySampD);

								this.getMapper(JhySampleConsignDMapper.class).doInsertDItem(jhyno.getSmpNo(), Seq,
										specimenNoA);

							}

						}

					}

					else if (lst2.getCertInstCode().equals("408604")) {

						List<JhySampleConsignD> getZp = new ArrayList<JhySampleConsignD>();
						getZp.add(JhySampD); // 调用计划提供的接口获取获取子板
						if (getZp != null && getZp.size() > 0) {
							for (JhySampleConsignD ConD : getZp) {

								String CONSIGN_NO = this.getMapper(JhySampleConsignDMapper.class).GetMaxCodeZd(1);
								String Seq = this.getMapper(JhySampleConsignDMapper.class).GetMaxSEQ(jhyno.getSmpNo());
								List<JhySampleConsignD> ddq = this.getMapper(JhySampleConsignDMapper.class)
										.doSelectPhyDitem(jhyno.getSmpNo());
								if (ddq != null && ddq.size() > 0) {
									JhySampD.setAllItemCode(ddq.get(0).getAllItemCode());
									JhySampD.setAllItemName(ddq.get(0).getAllItemName());
								}
								JhySampD.setSmpNo(jhyno.getSmpNo());
								JhySampD.setConsignNo(CONSIGN_NO);
								JhySampD.setSpecimenNo(specimenNo);
								JhySampD.setBatchNo(cp.getMemo1());
								JhySampD.setHeatNo(cp.getMemo2());
								JhySampD.setFreqCode(lst2.getCertInstCode());
								JhySampD.setFreqName(lst2.getCertInstName());

								this.getMapper(JhySampleConsignDMapper.class).insert(JhySampD);

								this.getMapper(JhySampleConsignDMapper.class).doInsertDItem(jhyno.getSmpNo(), Seq,
										specimenNo);

							}

						}
					}

				}
			}
		}

		rm.setState("200");

		return rm;

	}

	/**
	 * 提供给计划模块组坯完成时调用 自动创建成品成分检验委托处理
	 * 
	 */
	@Transactional(value = "tm", rollbackFor = Exception.class)
	public ResultModel doCompositionTest(CommonPage<JhySampleROrd> cp) {
		String BATCH_NO = cp.getObject().getBatchNo();
		String heat_no = cp.getObject().getHeatNo();
		ResultModel rm = new ResultModel();
		List<JhySampleConsignM> OrdPk = new ArrayList<JhySampleConsignM>();

		OrdPk = this.getMapper(JhySampleConsignMMapper.class).doSelectRATE(BATCH_NO);

		try {
			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// 设置日期格式
			java.util.Date time = df.parse(df.format(new Date()));// new
																	// Date()为获取当前系统时间

			for (JhySampleConsignM RATE : OrdPk) {
				List<JhySampleChemD> smp = new ArrayList<JhySampleChemD>();
				JhySampleChemM ChemM = new JhySampleChemM();
				JhySampleChemD ChemD = new JhySampleChemD();
				JhySampleROrd JhyOrd = new JhySampleROrd();
				if (RATE.getHeatNo().equals("408601")) {
					smp = this.getMapper(JhySampleChemDMapper.class).doSelectHEAT(RATE.getHeatNo(), heat_no);

					String smpNo = null;
					if (smp.size() > 0) {
						List<String> pp = this.getMapper(JhySampleConsignMMapper.class)
								.doSelectPkCount(smp.get(0).toString(), RATE.getSmpNo());
						smpNo = smp.get(0).toString();
						if (pp.size() == 0) {
							JhyOrd.setSmpNo(smpNo);
							JhyOrd.setBatchNo(BATCH_NO);
							JhyOrd.setCertInstCode("");
							JhyOrd.setCertInstName("检测中心");
							JhyOrd.setContractLineNo(RATE.getSmpNo());
							JhyOrd.setHeatNo(heat_no);
							JhyOrd.setIsview("0");
							// JhyOrd.setJudgeMemo("");
							// JhyOrd.setJudgeName("");
							// JhyOrd.setJudgeResult("");

							JhyOrd.setSmpTypeCode("");
							JhyOrd.setSmpTypeName("常规");

							this.getMapper(JhySampleConsignMMapper.class).doInsertOrd(JhyOrd);
						}

					} else {

						smpNo = this.getMapper(JhySampleChemMMapper.class).GetMaxCode();
						// ChemM.setBatchNo(batchNo);
						// ChemM.setBoardNo(boardNo);
						ChemM.setCertInstCode("");
						ChemM.setCertInstName("检测中心");
						ChemM.setCreateName("SYSTEM");
						ChemM.setCreateTime(time);
						ChemM.setHeatNo(heat_no);
						// ChemM.setMaterialNo(materialNo);
						ChemM.setPsc("123");
						ChemM.setPscDesc("");
						ChemM.setSmpNo(smpNo);
						ChemM.setSmpTypeCode("");
						ChemM.setSmpTypeName("常规");
						ChemM.setValidflag("1");

						this.getMapper(JhySampleChemMMapper.class).insert(ChemM);

						JhyOrd.setSmpNo(smpNo);
						JhyOrd.setBatchNo(BATCH_NO);
						JhyOrd.setCertInstCode("");
						JhyOrd.setCertInstName("检测中心");
						JhyOrd.setContractLineNo(RATE.getSmpNo());
						JhyOrd.setHeatNo(heat_no);
						JhyOrd.setIsview("0");
						// JhyOrd.setJudgeMemo("");
						// JhyOrd.setJudgeName("");
						// JhyOrd.setJudgeResult("");

						JhyOrd.setSmpTypeCode("");
						JhyOrd.setSmpTypeName("常规");

						this.getMapper(JhySampleConsignMMapper.class).doInsertOrd(JhyOrd);

					}

					String SPECIMENNO = this.getMapper(JhySampleChemDMapper.class).GetMaxCode();

					// ChemD.setBatchNo(batchNo);
					// ChemD.setBoardNo(boardNo);
					ChemD.setSpecimenNo(SPECIMENNO);
					ChemD.setCheckMemo("");
					ChemD.setConsignNo("");
					ChemD.setConsignNoSeq(1);
					ChemD.setCreateName("SYSTEM");
					ChemD.setCreateTime(time);
					ChemD.setDeliveryStateCode("");
					ChemD.setDeliveryStateDesc("");
					ChemD.setFreqCode(RATE.getHeatNo());
					ChemD.setFreqName(RATE.getHeatNo());
					ChemD.setHeatNo(heat_no);
					ChemD.setMaterialNo("");
					ChemD.setOldConsignNo("");
					ChemD.setPlineCode("");
					ChemD.setProdName("");
					ChemD.setQuoteConsignNo("");
					ChemD.setSendName("");
					ChemD.setSendTime(null);
					ChemD.setSmpNo(smpNo);
					ChemD.setSmpQty(1);
					ChemD.setSmpTypeCode("");
					ChemD.setSmpTypeName("");
					ChemD.setSpecCode("");
					ChemD.setSpecName("");
					ChemD.setStatus("0");
					ChemD.setStdCode("");
					ChemD.setStdName("");
					ChemD.setSteelCode("");
					ChemD.setSteelName("");
					ChemD.setTestQty(1);
					ChemD.setValidflag("1");

					this.getMapper(JhySampleChemDMapper.class).insert(ChemD);

				} else if (RATE.getHeatNo().equals("408602")) {
					smp = this.getMapper(JhySampleChemDMapper.class).doSelectHEAT(RATE.getHeatNo(), heat_no);
					String smpNo = null;

					if (smp.size() > 0) {
						List<String> pp = this.getMapper(JhySampleConsignMMapper.class)
								.doSelectPkCount(smp.get(0).toString(), RATE.getSmpNo());
						smpNo = smp.get(0).toString();
						if (pp.size() == 0) {
							JhyOrd.setSmpNo(smpNo);
							JhyOrd.setBatchNo(BATCH_NO);
							JhyOrd.setCertInstCode("");
							JhyOrd.setCertInstName("");
							JhyOrd.setContractLineNo(RATE.getSmpNo());
							JhyOrd.setHeatNo(heat_no);
							JhyOrd.setIsview("0");
							JhyOrd.setJudgeMemo("");
							JhyOrd.setJudgeName("");
							JhyOrd.setJudgeResult("");

							JhyOrd.setSmpTypeCode("");
							JhyOrd.setSmpTypeName("");

							this.getMapper(JhySampleConsignMMapper.class).doInsertOrd(JhyOrd);
						}

					} else {

						smpNo = this.getMapper(JhySampleChemMMapper.class).GetMaxCode();
						// ChemM.setBatchNo(batchNo);
						// ChemM.setBoardNo(boardNo);
						ChemM.setCertInstCode("");
						ChemM.setCertInstName("检测中心");
						ChemM.setCreateName("SYSTEM");
						ChemM.setCreateTime(time);
						ChemM.setHeatNo(heat_no);
						// ChemM.setMaterialNo(materialNo);
						ChemM.setPsc("123");
						ChemM.setPscDesc("");
						ChemM.setSmpNo(smpNo);
						ChemM.setSmpTypeCode("");
						ChemM.setSmpTypeName("常规");
						ChemM.setValidflag("1");

						this.getMapper(JhySampleChemMMapper.class).insert(ChemM);

						JhyOrd.setSmpNo(smpNo);
						JhyOrd.setBatchNo(BATCH_NO);
						JhyOrd.setCertInstCode("");
						JhyOrd.setCertInstName("");
						JhyOrd.setContractLineNo(RATE.getSmpNo());
						JhyOrd.setHeatNo(heat_no);
						JhyOrd.setIsview("0");
						JhyOrd.setJudgeMemo("");
						JhyOrd.setJudgeName("");
						JhyOrd.setJudgeResult("");

						JhyOrd.setSmpTypeCode("");
						JhyOrd.setSmpTypeName("");

						this.getMapper(JhySampleConsignMMapper.class).doInsertOrd(JhyOrd);

					}

					String SPECIMENNO = this.getMapper(JhySampleChemDMapper.class).GetMaxCode();

					// ChemD.setBatchNo(batchNo);
					// ChemD.setBoardNo(boardNo);
					ChemD.setSpecimenNo(SPECIMENNO);
					ChemD.setCheckMemo("");
					ChemD.setConsignNo("");
					ChemD.setConsignNoSeq(1);
					ChemD.setCreateName("SYSTEM");
					ChemD.setCreateTime(time);
					ChemD.setDeliveryStateCode("");
					ChemD.setDeliveryStateDesc("");
					ChemD.setFreqCode(RATE.getHeatNo());
					ChemD.setFreqName(RATE.getHeatNo());
					ChemD.setHeatNo(heat_no);
					ChemD.setMaterialNo("");
					ChemD.setOldConsignNo("");
					ChemD.setPlineCode("");
					ChemD.setProdName("");
					ChemD.setQuoteConsignNo("");
					ChemD.setSendName("");
					ChemD.setSendTime(null);
					ChemD.setSmpNo(smpNo);
					ChemD.setSmpQty(1);
					ChemD.setSmpTypeCode("");
					ChemD.setSmpTypeName("");
					ChemD.setSpecCode("");
					ChemD.setSpecName("");
					ChemD.setStatus("0");
					ChemD.setStdCode("");
					ChemD.setStdName("");
					ChemD.setSteelCode("");
					ChemD.setSteelName("");
					ChemD.setTestQty(1);
					ChemD.setValidflag("1");

					this.getMapper(JhySampleChemDMapper.class).insert(ChemD);
				} else if (RATE.getHeatNo().equals("408603")) {
					smp = this.getMapper(JhySampleChemDMapper.class).doSelectHEAT(RATE.getHeatNo(), heat_no);

					String smpNo = null;
					if (smp.size() > 0) {
						List<String> pp = this.getMapper(JhySampleConsignMMapper.class)
								.doSelectPkCount(smp.get(0).toString(), RATE.getSmpNo());
						smpNo = smp.get(0).toString();
						if (pp.size() == 0) {
							JhyOrd.setSmpNo(smpNo);
							JhyOrd.setBatchNo(BATCH_NO);
							JhyOrd.setCertInstCode("");
							JhyOrd.setCertInstName("");
							JhyOrd.setContractLineNo(RATE.getSmpNo());
							JhyOrd.setHeatNo(heat_no);
							JhyOrd.setIsview("0");
							JhyOrd.setJudgeMemo("");
							JhyOrd.setJudgeName("");
							JhyOrd.setJudgeResult("");

							JhyOrd.setSmpTypeCode("");
							JhyOrd.setSmpTypeName("");

							this.getMapper(JhySampleConsignMMapper.class).doInsertOrd(JhyOrd);
						}

					} else {

						smpNo = this.getMapper(JhySampleChemMMapper.class).GetMaxCode();
						// ChemM.setBatchNo(batchNo);
						// ChemM.setBoardNo(boardNo);
						ChemM.setCertInstCode("");
						ChemM.setCertInstName("检测中心");
						ChemM.setCreateName("SYSTEM");
						ChemM.setCreateTime(time);
						ChemM.setHeatNo(heat_no);
						// ChemM.setMaterialNo(materialNo);
						ChemM.setPsc("123");
						ChemM.setPscDesc("");
						ChemM.setSmpNo(smpNo);
						ChemM.setSmpTypeCode("");
						ChemM.setSmpTypeName("常规");
						ChemM.setValidflag("1");

						this.getMapper(JhySampleChemMMapper.class).insert(ChemM);

						JhyOrd.setSmpNo(smpNo);
						JhyOrd.setBatchNo(BATCH_NO);
						JhyOrd.setCertInstCode("");
						JhyOrd.setCertInstName("");
						JhyOrd.setContractLineNo(RATE.getSmpNo());
						JhyOrd.setHeatNo(heat_no);
						JhyOrd.setIsview("0");
						JhyOrd.setJudgeMemo("");
						JhyOrd.setJudgeName("");
						JhyOrd.setJudgeResult("");

						JhyOrd.setSmpTypeCode("");
						JhyOrd.setSmpTypeName("");

						this.getMapper(JhySampleConsignMMapper.class).doInsertOrd(JhyOrd);

					}

					String SPECIMENNO = this.getMapper(JhySampleChemDMapper.class).GetMaxCode();

					// ChemD.setBatchNo(batchNo);
					// ChemD.setBoardNo(boardNo);
					ChemD.setSpecimenNo(SPECIMENNO);
					ChemD.setCheckMemo("");
					ChemD.setConsignNo("");
					ChemD.setConsignNoSeq(1);
					ChemD.setCreateName("SYSTEM");
					ChemD.setCreateTime(time);
					ChemD.setDeliveryStateCode("");
					ChemD.setDeliveryStateDesc("");
					ChemD.setFreqCode(RATE.getHeatNo());
					ChemD.setFreqName(RATE.getHeatNo());
					ChemD.setHeatNo(heat_no);
					ChemD.setMaterialNo("");
					ChemD.setOldConsignNo("");
					ChemD.setPlineCode("");
					ChemD.setProdName("");
					ChemD.setQuoteConsignNo("");
					ChemD.setSendName("");
					ChemD.setSendTime(null);
					ChemD.setSmpNo(smpNo);
					ChemD.setSmpQty(1);
					ChemD.setSmpTypeCode("");
					ChemD.setSmpTypeName("");
					ChemD.setSpecCode("");
					ChemD.setSpecName("");
					ChemD.setStatus("0");
					ChemD.setStdCode("");
					ChemD.setStdName("");
					ChemD.setSteelCode("");
					ChemD.setSteelName("");
					ChemD.setTestQty(1);
					ChemD.setValidflag("1");

					this.getMapper(JhySampleChemDMapper.class).insert(ChemD);
				} else if (RATE.getHeatNo().equals("408604")) {
					smp = this.getMapper(JhySampleChemDMapper.class).doSelectHEAT(RATE.getHeatNo(), heat_no);

					String smpNo = null;
					if (smp.size() == 0) {

						smpNo = this.getMapper(JhySampleChemMMapper.class).GetMaxCode();
						// ChemM.setBatchNo(batchNo);
						// ChemM.setBoardNo(boardNo);
						ChemM.setCertInstCode("");
						ChemM.setCertInstName("检测中心");
						ChemM.setCreateName("SYSTEM");
						ChemM.setCreateTime(time);
						ChemM.setHeatNo(heat_no);
						// ChemM.setMaterialNo(materialNo);
						ChemM.setPsc("123");
						ChemM.setPscDesc("");
						ChemM.setSmpNo(smpNo);
						ChemM.setSmpTypeCode("");
						ChemM.setSmpTypeName("常规");
						ChemM.setValidflag("1");

						this.getMapper(JhySampleChemMMapper.class).insert(ChemM);

						JhyOrd.setSmpNo(smpNo);
						JhyOrd.setBatchNo(BATCH_NO);
						JhyOrd.setCertInstCode("");
						JhyOrd.setCertInstName("");
						JhyOrd.setContractLineNo(RATE.getSmpNo());
						JhyOrd.setHeatNo(heat_no);
						JhyOrd.setIsview("0");
						JhyOrd.setJudgeMemo("");
						JhyOrd.setJudgeName("");
						JhyOrd.setJudgeResult("");

						JhyOrd.setSmpTypeCode("");
						JhyOrd.setSmpTypeName("");

						this.getMapper(JhySampleConsignMMapper.class).doInsertOrd(JhyOrd);

					}

					String SPECIMENNO = this.getMapper(JhySampleChemDMapper.class).GetMaxCode();

					// ChemD.setBatchNo(batchNo);
					// ChemD.setBoardNo(boardNo);
					ChemD.setSpecimenNo(SPECIMENNO);
					ChemD.setCheckMemo("");
					ChemD.setConsignNo("");
					ChemD.setConsignNoSeq(1);
					ChemD.setCreateName("SYSTEM");
					ChemD.setCreateTime(time);
					ChemD.setDeliveryStateCode("");
					ChemD.setDeliveryStateDesc("");
					ChemD.setFreqCode(RATE.getHeatNo());
					ChemD.setFreqName(RATE.getHeatNo());
					ChemD.setHeatNo(heat_no);
					ChemD.setMaterialNo("");
					ChemD.setOldConsignNo("");
					ChemD.setPlineCode("");
					ChemD.setProdName("");
					ChemD.setQuoteConsignNo("");
					ChemD.setSendName("");
					ChemD.setSendTime(null);
					ChemD.setSmpNo(smpNo);
					ChemD.setSmpQty(1);
					ChemD.setSmpTypeCode("");
					ChemD.setSmpTypeName("");
					ChemD.setSpecCode("");
					ChemD.setSpecName("");
					ChemD.setStatus("0");
					ChemD.setStdCode("");
					ChemD.setStdName("");
					ChemD.setSteelCode("");
					ChemD.setSteelName("");
					ChemD.setTestQty(1);
					ChemD.setValidflag("1");

					this.getMapper(JhySampleChemDMapper.class).insert(ChemD);
				}

			}
			rm.setState("200");
		} catch (Exception e) {
			// TODO: handle exception

			rm.setState("500");
			rm.setMsgInfo("服务端异常，关闭失败!");
		}

		return rm;

	}

	/**
	 * 获取认证机构
	 * 
	 */
	public ResultModel GetPscOrg(CommonPage<ComPscROrg> cp) {

		ResultModel rm = new ResultModel();
		ComPscROrg Org = new ComPscROrg();
		try {
			Org.setPsc(cp.getObject().getPsc());
			rm.setData(this.getMapper(ComBasePhyRPosMapper.class).doselectPosApi(cp.getObject().getPsc()));
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("查询失败!");
		}

		return rm;

	}

	/**
	 * 获取交货状态
	 * 
	 */
	public ResultModel GetPscDelivery(CommonPage<ComPscRDelivery> cp) {

		ResultModel rm = new ResultModel();
		ComPscRDelivery Org = new ComPscRDelivery();
		try {
			Org.setPsc(cp.getObject().getPsc());
			rm.setData(this.getMapper(ComPscRDeliveryMapper.class).find(Org, 0, 0));
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("查询失败!");
		}

		return rm;

	}

	/**
	 * 获取规范信息
	 * 
	 */
	public ResultModel GetPsc(CommonPage<ComPsc> cp) {

		ResultModel rm = new ResultModel();
		try {
			rm.setData(this.getMapper(ComPscMapper.class).findOrder(cp.getObject().getPsc(),	cp.getObject().getSteel_code(), "0"));
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("查询失败!");
		}

		return rm;

	}

	/**
	 * 获取适用规则
	 * 
	 */
	public ResultModel GetPscSpec(CommonPage<ComPsc> cp) {

		ResultModel rm = new ResultModel();
		ComPscRSpec Org = new ComPscRSpec();
		try {
			Org.setValidflag("1");
			Org.setPsc(cp.getObject().getPsc());
			rm.setData(this.getMapper(ComPscRSpecMapper.class).find(Org, 0, 0));
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("查询失败!");
		}

		return rm;

	}

	/**
	 * 获取材质大类信息
	 * 
	 */
	public ResultModel GetPhyItemL() {

		ResultModel rm = new ResultModel();
		ComBasePhyB Org = new ComBasePhyB();
		try {
			Org.setValidflag("1");
			rm.setData(this.getMapper(ComBasePhyBMapper.class).find(Org, 0, 0));
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("查询失败："+e.getMessage());
		}

		return rm;

	}

	/**
	 * 获取材质试样组
	 * 
	 */
	public ResultModel GetPhyItemM(CommonPage<ComBasePhyB> cp) {

		ResultModel rm = new ResultModel();
		ComBasePhyC Org = new ComBasePhyC();
		try {
			Org.setPhy_code_l(cp.getObject().getPhy_code_l());
			Org.setValidflag("1");
			rm.setData(this.getMapper(ComBasePhyCMapper.class).find(Org, 0, 0));
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("查询失败："+e.getMessage());
		}

		return rm;

	}

	/**
	 * 获取材质项目组
	 * 
	 */
	public ResultModel GetPhyItemS(CommonPage<ComBasePhyC> cp) {

		ResultModel rm = new ResultModel();
		ComBasePhy Org = new ComBasePhy();
		try {
			Org.setPhy_code_m(cp.getObject().getPhy_code_m());
			Org.setValidflag("1");
			if(!DataHelper.IsNullOrSpace(cp.getObject().getPhyType())){
				rm.setData(this.getMapper(ComBasePhyMapper.class).GetComBasePhyByType(cp.getObject().getPhyType()));
			}else{
				rm.setData(this.getMapper(ComBasePhyMapper.class).find(Org, 0, 0));
			}
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("查询失败!");
		}

		return rm;

	}

	/**
	 * 获取实验温度
	 * 
	 */
	public ResultModel GetPhyTemp(CommonPage<ComBasePhyRPos> cp) {

		ResultModel rm = new ResultModel();
		try {
			String phy = cp.getObject().getPhyCodeS();
			rm.setData(this.getMapper(ComBasePhyRPosMapper.class).doselectPhyRItemApi(phy));
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("查询失败!");
		}

		return rm;

	}

	/**
	 * 获取实验方向尺寸
	 * 
	 */
	public ResultModel GetDirectionAndSize(CommonPage<ComBasePhyRItem> cp) {

		ResultModel rm = new ResultModel();
		try {
			String phy = cp.getObject().getPhyCodeM();
			rm.setData(this.getMapper(ComBasePhyRPosMapper.class).GetDirectionAndSize(phy));
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("查询失败!");
		}

		return rm;

	}

	/**
	 * 获取成分检验实绩信息
	 * 
	 */
	@Transactional(value = "tm", rollbackFor = Exception.class)
	public ResultModel GetOutsideChemResult(CommonPage<QcmJhyElements> cp) {

		ResultModel rm = new ResultModel();

		String phy = cp.getObject().getAssay_no();
		QcmJhyElements Jhy = this.getMapper(QcmJhyElementsMapper.class).doSelectIfChem(phy);
		//QcmJhyElements jhy1 = this.getMapper(QcmJhyElementsMapper.class).findById(phy);
		QcmJhyElements jhy1 = this.getMapper(QcmJhyElementsMapper.class).findByid(phy);
		if (jhy1 != null) {
			this.getMapper(QcmJhyElementsMapper.class).dodelete(phy);
		}
		if(Jhy.getAssay_type()==null || "".equals(Jhy.getAssay_type())){
			Jhy.setAssay_type("L");
		}
		if(Jhy.getChem_code()==null || "".equals(Jhy.getChem_code())){
			Jhy.setChem_code("无");
		}
		this.getMapper(QcmJhyElementsMapper.class).insert(Jhy);

		rm.setState("200");

		return rm;

	}

	/**
	 * 获取材质结果信息
	 * 
	 */

	@Transactional(value = "tm", rollbackFor = Exception.class)
	public ResultModel GetOutsidePhyResult(CommonPage<QcmPhyResult> cp) throws Exception {

		ResultModel rm = new ResultModel();

		try {

			String phy = cp.getObject().getPhy_id();
			List<QcmPhyResult> Jhy = this.getMapper(QcmPhyResultMapper.class).doSelectIfPfmc(phy);
			QcmPhyResult JhyM = this.getMapper(QcmPhyResultMapper.class).doSelectIfPfmcM(phy);

			QcmPhyJudgeResult res = new QcmPhyJudgeResult();

			res.setPhy_id(phy);

			@SuppressWarnings("unchecked")
			List<QcmPhyJudgeResult> jhy1 = this.getMapper(QcmPhyJudgeResultMapper.class).find(res, 0, 0);

			if (jhy1.size() != 0) {
				this.getMapper(QcmPhyResultMapper.class).dodelete(phy);
			}

//			if (Jhy.get(0).getVal15().equals("0")) {
//
//				List<QcmPhyResult> JhyXg1 = this.getMapper(QcmPhyResultMapper.class).doSelectIfPfmcXg(phy);
//				QcmPhyResult JhyXg = JhyXg1.get(0);
//
//				String gui = this.getMapper(QcmPhyResultMapper.class).findMaxGuid();
//				JhyXg.setGuid(gui);
//				// JhyXg.setBatchNo(JhyM.getBatchNo());
//				JhyXg.setMaterial_no(JhyM.getMaterial_no());
//				JhyXg.setSteel_code(JhyM.getSteel_code());
//				JhyXg.setSteel_name(JhyM.getSteel_name());
//				JhyXg.setCreate_time(new Date());
//				this.getMapper(QcmPhyResultMapper.class).doInsertResultSele(JhyXg);
//
//			} else {
//				Jhy.get(0).setSmp_no(this.getMapper(QcmPhyResultMapper.class).GetMaxCodeWg());
//				String gui = this.getMapper(QcmPhyResultMapper.class).findMaxGuid();
//				Jhy.get(0).setGuid(gui);
//				// Jhy.get(0).setBatchNo(JhyM.getBatchNo());
//				Jhy.get(0).setMaterial_no(JhyM.getMaterial_no());
//				Jhy.get(0).setSteel_code(JhyM.getSteel_code());
//				Jhy.get(0).setSteel_name(JhyM.getSteel_name());
//				Jhy.get(0).setCreate_time(new Date());
//				Jhy.get(0).setVal15(null);
//				this.getMapper(QcmPhyResultMapper.class).doInsertResult(Jhy.get(0));
//			}
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("查询失败!");
			e.printStackTrace();
			throw e;
		}

		return rm;

	}

	/**
	 * 获取最后一道设计工序编号 E0002为分条
	 */
	public String GetWrkPlanCode(String orderNo) {
		return "E0002";
	}

	/**
	 * 获取最后一道工序编号 60001为包装
	 */
	public String GetWrkCode(String orderNo) {
		return "60001";
	}
	// GetMscStd

	public ResultModel GetMscStd(CommonPage<DetailMsc> sum) {
		DetailMsc object = sum.getObject();
		ResultModel rm = new ResultModel();

		PageModel<DetailMsc> pm = new PageModel<DetailMsc>(0, 0);
		try {
			List<ComMscStdChem> dofindchem = this.getMapper(ComBaseStdMapper.class).dofindchem(object);
			List<ComMscStdDetectionC> dofinddetection = this.getMapper(ComBaseStdMapper.class).dofinddetection(object.getMsc(), object.getValidflag());
			List<ComMscStdPhy> dofindphy = this.getMapper(ComBaseStdMapper.class).dofindphy(object);
			List<ComMscStdSpecC> dofindspec = this.getMapper(ComBaseStdMapper.class).dofindspec(object.getMsc(),object.getValidflag());
			DetailMsc detail = new DetailMsc();
			detail.setChemList(dofindchem);
			detail.setDetectionList(dofinddetection);
			detail.setPhyList(dofindphy);
			detail.setSpecList(dofindspec);
			rm.setData(detail);
			rm.setMsgInfo("查询成功！");
			rm.setState("200");
		} catch (Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("查询失败!");
			ex.printStackTrace();
		}
		return rm;
	}

	public ResultModel GetMsc(CommonPage<QcmPhyResult> sum) {
		ResultModel rm = new ResultModel();
		String memo1 = sum.getMemo1();
		PageModel<ComPsc> pm = new PageModel<>(0, 0);
		try {
			List<ComPsc> list = this.getMapper(ComMscMapper.class).dofindmsc(memo1);
			pm.setRows(list);
			pm.setTotal(list.size());
			rm.setData(pm);
			rm.setMsgInfo("查询成功！");
			rm.setState("200");
		} catch (Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("查询失败!");
			ex.printStackTrace();
		}
		return rm;
	}
/**
 * 合同行PK码  查设计状态
 * @param sum
 * @return
 */
	public ResultModel GetTKLG(String sum) {
		ResultModel rm = new ResultModel();

		try {
			SlmOrdDesignStsTklg Tk = new SlmOrdDesignStsTklg();
			Tk.setOrd_ln_pk(sum);
			Tk.setValidflag("1");
			List<SlmOrdDesignStsTklg> list = this.getMapper(SlmOrdDesignStsTklgMapper.class).find(Tk, 0, 0);
			if (list == null || list.size() == 0) {
				Tk.setDesign_sts("W");
				rm.setData(Tk);
			} else {
				rm.setData(list.get(0));
			}

			rm.setMsgInfo("查询成功！");
			rm.setState("200");
		} catch (Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("查询失败!");
			ex.printStackTrace();
		}
		return rm;
	}
	
	
	/**
	 * 查询质量设计制程
	 * @param ord
	 * @return
	 */
	public ResultModel doSelectSlmOrdSti(String ord)
	{
		ResultModel rm = new ResultModel();
		
		try {
			if(!ord.equals("")&&ord !=null)
			{
			rm.setData(this.getMapper(SlmOrdDesignMscPlStiMapper.class).doselectPlSti(ord));
			rm.setMsgInfo("查询成功！");
			rm.setState("200");
			}
			else
			{
				rm.setMsgInfo("传入参数不能为空！");
				rm.setState("500");
			}
		
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("查询失败!");
			e.printStackTrace();
		}
		
		return rm;
		
	}
	
	/**
	 * 根据Design_key和产品规范码获取取样频次代码最大值
	 * design_key design_key
	 * psc 产品规范码
	 * */
	public ResultModel getRATE(CommonPage<SlmOrdDesignStd> sum){
		ResultModel rm=new ResultModel();
		try {
			List<SlmOrdDesignStd> stdlist=sum.getObjectList();
			if(stdlist==null||stdlist.size()==0){
				rm.setState("500");
				rm.setMsgInfo("请传入参数！");
				return rm;
			}
			String rate="";
			String ratedesc="";
//			循环不同design_key+psc
			for(SlmOrdDesignStd std:stdlist){
				List<SlmOrdDesignStd> stdlist2=this.getMapper(SlmOrdDesignStdMapper.class).find(std, 0, 0);
				if(stdlist2!=null&&stdlist2.size()>0){
//					循环相同design_key+psc
					for(SlmOrdDesignStd stdd:stdlist2){
						SlmOrdDesignStdPicSmp spic=new SlmOrdDesignStdPicSmp();
						spic.setDesign_key(stdd.getDesign_key());
						spic.setPic(stdd.getPic());
						List<SlmOrdDesignStdPicSmp> spiclist=this.getMapper(SlmOrdDesignStdPicSmpMapper.class).find(spic, 0, 0);
//						循环不同design_key+pic
						for(SlmOrdDesignStdPicSmp spicc:spiclist){
							if(spicc.getRate()!=null&&spicc.getRate().compareTo(rate)>0){
								rate=spicc.getRate();
								ratedesc=spicc.getDesc_rate();
							}
						}
					}
				}
			}
			SlmOrdDesignStdPicSmp re=new SlmOrdDesignStdPicSmp();
			re.setRate(rate);
			re.setDesc_rate(ratedesc);
			rm.setData(re);
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("获取失败！"+e.getMessage());
		}
		return rm;
	}
	
	//========
	
	/**
	 * 获取附加要求
	 * @param com
	 * @return
	 */
//	public ResultModel GetOrderAddAskInfo(CommonPage<SlmOrdDesignAdditional> com){
//		ResultModel model=new ResultModel();
//		try{
//			if(com.getObject()==null||DataHelper.IsNullOrSpace(com.getObject().getDesign_key())||DataHelper.IsNullOrSpace(com.getObject().getPoint_code())){
//				model.setState("403");
//				model.setMsgInfo("参数不正确");
//			}
//			
//			ComBaseAskRStation _ask=new ComBaseAskRStation();
//			_ask.setProcess_point_code(com.getObject().getPoint_code());
//			_ask.setValidflag("1");
//			List<ComBaseAskRStation> listAddAsk=this.getMapper(ComBaseAskRStationMapper.class).find(_ask, 0, 0); 
//			List<SlmOrdDesignAdditional> listAdd=new ArrayList<>();
//			if(listAddAsk.size()>0){
//				List<String> listStr=new ArrayList<>();
//				for (ComBaseAskRStation slmBaseAddAsk : listAddAsk) {
//					listStr.add(slmBaseAddAsk.getAsk_sub_itme());
//				}
//				String condition=DataHelper.CreateSqlCondition(listStr, "ask_sub_itme");
//				listAdd=this.getMapper(SlmOrdDesignAdditionalMapper.class).findWithCondition(com.getObject(), condition, null, 0, 0);
//			}
//			model.setData(listAdd);
//			model.setMsgInfo("获取数据成功");
//		}catch(Exception ex){
//			model.setState("500");
//			model.setMsgInfo("获取附加要求失败");
//			model.setErrorInfo(ex.getMessage());
//		}
//		return model;
//	}
	
	public ResultModel GetOrderAddAskInfo(CommonPage<SlmOrdDesignAdditional> com){
		String askInfo = "";
		ResultModel model=new ResultModel();
		try{
			String configStr = this.getBean(ComBaseConfigServiceImpl.class).getConfig("ASK0005");
			// 根据动态配置决定从订单备注信息获取或质量设计结果表获取
			if(!"0".equals(configStr)){
				askInfo = this.getBean(SlmApiServiceImpl.class).getOrderMemo(com.getMemo1());
			}else{
				List<SlmOrdDesignAdditional> listAddAsk = this.getMapper(ComBaseAskRStationMapper.class).GetOrderAddAskInfo(com.getObject().getDesign_key()
						, com.getObject().getProcess_point_code());
				
				model.setState("200");
				for(SlmOrdDesignAdditional sod: listAddAsk){
					askInfo += sod.getAsk_itme_desc()+":"+sod.getAsk_sub_itme_val_desc()+";";
				}
			}
			if(DataHelper.IsNullOrSpace(askInfo)){
				askInfo="无附加要求";
			}
			model.setData(askInfo);
			model.setMsgInfo("获取数据成功");
		}catch(Exception ex){
			model.setState("500");
			model.setMsgInfo("获取附加要求失败");
			model.setErrorInfo(ex.getMessage());
		}
		return model;
	}

	
	//========
	
	/**
	 * 通过合同行主键返回DESIGN_KEY\DESIGN_SEQ集合
	 * 2018-09-03 zhangjiao
	 */
	public ResultModel GetAllByDesignKey(CommonPage<SlmOrdDesignMsc> com) {

		ResultModel rm = new ResultModel();

		try {

			if (com.getObject() == null || DataHelper.IsNullOrSpace(com.getObject().getContract_line_no())) {
				rm.setState("500");
				rm.setMsgInfo("参数不正确");
				return rm;
			}
			List<SlmOrdDesignMsc> sms = this.getMapper(SlmOrdDesignMscMapper.class).findWithCondition(null,
					"CONTRACT_LINE_NO='" + com.getObject().getContract_line_no() + "' and DESIGN_RESULT='1' and validflag = '1' ", " create_time desc", 0, 0);
			if (sms == null || sms.size() < 1) {
				rm.setState("500");
				rm.setMsgInfo("未查询到有效数据");
				return rm;

			}
			for (SlmOrdDesignMsc slmOrdDesignMsc : sms) {
				slmOrdDesignMsc.setDesign_seq("第"+slmOrdDesignMsc.getDesign_seq()+"版工艺文件");	
			}
			rm.setData(sms);
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("获取design_key失败!");
			rm.setErrorInfo(e.getMessage());
		}

		return rm;
	}

	
	/**
	 * 给计划模块的接口获取全程产线码以及对应的工艺路径
	 * @param design_key
	 * @return
	 * 2018-09-03 zhangjiao
	 */
	public ResultModel GetMscByDesignKey(String design_key) {
		ResultModel rm = new ResultModel();
		try {
			if (design_key == null || "".equals(design_key)) {
				rm.setState("500");
				rm.setMsgInfo("参数不正确");
				return rm;
			}	
			SlmOrdDesignMscPl _pl=new SlmOrdDesignMscPl();
			_pl.setDesign_key(design_key);
			List<SlmOrdDesignMscPl> listPl=this.getMapper(SlmOrdDesignMscPlMapper.class).find(_pl, 0, 0);
			if (listPl==null || listPl.size()<1) {
				rm.setState("500");
				rm.setMsgInfo("未查询["+design_key+"]到匹配的制程信息!");
				return rm;
			}
			// and (process_code = 'B' OR process_code = 'D')
			List<SlmOrdDesignMscPlSti> listSti=this.getMapper(SlmOrdDesignMscPlStiMapper.class).findWithCondition(null, " design_key = '"+design_key+"'", " BACKLOG_SEQ,PROCESS_POINT_SEQ ", 0, 0);
			if (listSti==null || listSti.size()<1) {
				rm.setState("500");
				rm.setMsgInfo("未查询["+design_key+"]匹配的制程信息!");
				return rm;
			}
			for (SlmOrdDesignMscPl mscPl : listPl) {
				List<SlmOrdDesignMscPlSti> stition=new ArrayList<SlmOrdDesignMscPlSti>();
				StringBuilder sb=new StringBuilder("");
				StringBuilder sb2=new StringBuilder("");
				for (SlmOrdDesignMscPlSti slmOrdDesignMscPlSti : listSti) {
					if(slmOrdDesignMscPlSti.getMsc_pline().equals(mscPl.getMsc_pline())){
						sb2.append("-"+slmOrdDesignMscPlSti.getProcess_point_code());
						sb.append("-"+slmOrdDesignMscPlSti.getProcess_point_desc());
						stition.add(slmOrdDesignMscPlSti);
					}
				}
				mscPl.setStition(stition);
				mscPl.setStations_code(sb2.toString().replaceFirst("-", ""));
				mscPl.setStations_desc(sb.toString().replaceFirst("-", ""));
			}
			rm.setData(listPl);
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("获取全程产线号失败");
			rm.setErrorInfo(e.getMessage());
		}
		return rm;
	}
	/**2018.12.13
	 * 提供给销售的接口-获取工艺要求
	 * */
	public ResultModel getStationWeb(CommonPage<ComBaseInfo> sum){
		ResultModel rm=new ResultModel();
		int pageSize=sum.getPageSize();
		int pageIndex=sum.getPageIndex();
		try {
			PageModel<ComBaseStation> pm=new PageModel<>(pageIndex, pageSize);
			pm.setTotal(this.getMapper(ComBaseStationMapper.class).countWithCondition(null,"PROCESS_POINT_TYPE='"+PROCESS_POINT_TYPE+"' and VALIDFLAG='1'"));
			pm.setRows(this.getMapper(ComBaseStationMapper.class).findWithCondition(null, "PROCESS_POINT_TYPE='"+PROCESS_POINT_TYPE+"' and VALIDFLAG='1'", "PROCESS_POINT_SEQ", (pageIndex-1)*pageSize, pageSize));
			rm.setData(pm);
			rm.setState("200");
			rm.setMsgInfo("查询成功！");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("工艺要求查询失败！"+e.getMessage());
		}
		return rm;
	}

	public String getPROCESS_POINT_TYPE() {
		return PROCESS_POINT_TYPE;
	}
	
	
	/**
	 * 给生产接口--删除相关检验委托
	 */
	@Transactional(propagation = Propagation.REQUIRES_NEW,value = "tm", rollbackFor = Exception.class)
		public ResultModel removeInspection(CommonPage<QcmJhySampleFromPlan> sum) throws Exception {

			ResultModel rm = new ResultModel();

			try {
				QcmJhySampleFromPlan plan = sum.getObject();

				if (plan == null) {
					rm.setState("500");
					rm.setMsgInfo("请传入参数！");
					return rm;

				}

				if (plan.getInspection_lot() == null || "".equals(plan.getInspection_lot())) {
					rm.setState("500");
					rm.setMsgInfo("检验号不能为空，请确认！");
					return rm;
				}

				if (plan.getDesign_key() == null || plan.getDesign_key().equals("")) {
					rm.setState("500");
					rm.setMsgInfo("design_key不能为空，请确认！");
					return rm;
				}

				// 判断检验号向下是否存在已发送数据
				List<QcmJhySampleConsignD> qds = this.getMapper(QcmJhySampleConsignDMapper.class).findWithCondition(null,
						"INSPECTION_LOT='" + plan.getInspection_lot() + "' and STATUS!='0'", null, 0, 0);

				if (qds.size() > 0) {
					rm.setMsgInfo("检验批向下已经存在不属于未发送的数据，不能删除，请确认！");
					rm.setState("500");
					return rm;
				}

				// 根据检验号查询合同表，取出该检验号向下所有的design_key的数据集合
				List<QcmJhySampleROrd> ords = this.getMapper(QcmJhySampleROrdMapper.class).findWithCondition(null,
						"INSPECTION_LOT='" + plan.getInspection_lot() + "'", null, 0, 0);

				List<QcmJhySampleFromPlan> tarPlans = new ArrayList<QcmJhySampleFromPlan>();
				for (QcmJhySampleROrd qd : ords) {

					QcmJhySampleFromPlan tarPlan = new QcmJhySampleFromPlan();
					tarPlan.setInspection_lot(qd.getInspection_lot());
					tarPlan.setBatch_no(qd.getBatch_no());
					tarPlan.setHeat_no(qd.getHeat_no());
					tarPlan.setDesign_key(qd.getDesign_key());
					tarPlan.setContract_line_no(qd.getContract_line_no());
					tarPlan.setOrder_no(qd.getOrder_no());
					tarPlan.setMaterial_no(qd.getMaterial_no());
					tarPlan.setMsc_pline(qd.getMsc_pline());
					tarPlan.setProcess_code(qd.getProcess_code());
					tarPlan.setJudge("0");
					// 根据试样号查询检验委托主表
					QcmJhySampleConsignM qm = this.getMapper(QcmJhySampleConsignMMapper.class).findById(qd.getSmp_no());
					if (qm != null) {
						tarPlan.setMaterial_no(qm.getMaterial_no());
						tarPlan.setGrade_code(qm.getGrade_code());
						tarPlan.setGrade_name(qm.getGrade_name());
						tarPlan.setPline_code(qm.getPline_code());
						tarPlan.setPline_name(qm.getPline_name());
						tarPlan.setBoard_no(qm.getBoard_no());

					} else {
						rm.setState("500");
						rm.setMsgInfo("试样号[" + qd.getSmp_no() + "]在试样信息主表中未查询到相关信息，请确认！");
						return rm;

					}

					tarPlans.add(tarPlan);

				}

				// 去重
				String oldT = null;
				String newT = null;
				// 用来承装生成检验委托胡数据源集合
				List<QcmJhySampleFromPlan> targets = new ArrayList<QcmJhySampleFromPlan>();
				for (int i = 0; i < tarPlans.size(); i++) {

					if (i == 0) {
						targets.add(tarPlans.get(i));
						continue;
					}

					oldT = tarPlans.get(i).getDesign_key() + tarPlans.get(i).getMsc_pline()
							+ tarPlans.get(i).getGrade_code() + tarPlans.get(i).getContract_line_no()
							+ tarPlans.get(i).getOrder_no();
					for (int j = 0; j < targets.size(); j++) {
						newT = targets.get(j).getDesign_key() + targets.get(j).getMsc_pline()
								+ targets.get(j).getGrade_code() + targets.get(j).getContract_line_no()
								+ targets.get(j).getOrder_no();
						if (oldT.equals(newT)) {
							break;

						}

						if (j == targets.size() - 1) {
							targets.add(tarPlans.get(i));
							break;
						}
					}
				}

				// 去除需要删除的design_key;
				for (int i = 0; i < targets.size(); i++) {
					if (targets.get(i).getDesign_key().equals(plan.getDesign_key())) {
						targets.remove(i);
						i--;
					}

				}
				//根据检验号，查询检验委托主表获取试样号
				List<QcmJhySampleConsignM> qms=this.getMapper(QcmJhySampleConsignMMapper.class).findWithCondition(null, "INSPECTION_LOT='"+plan.getInspection_lot()+"'", null, 0, 0);
				// 删除当前检验号向下所有检验号信息
				for (int i = 0; i < qms.size(); i++) {
					// 查询试样信息明细白表，获取取样编号
					List<QcmJhySampleConsignD> qd = this.getMapper(QcmJhySampleConsignDMapper.class).findWithCondition(null,
							"SMP_NO='" + qms.get(i).getSmp_no() + "'", null, 0, 0);
					if (qd == null || qd.size() < 1) {
						throw new Exception("试样号[" + qms.get(i).getSmp_no() + "]下,不存在明细信息,请确认！");
							
					}
					for (QcmJhySampleConsignD q : qd) {
						// 查询项目标，看取样编号向下是否存在项目
						List<QcmJhySampleConsignDItem> items = this.getMapper(QcmJhySampleConsignDItemMapper.class)
								.findWithCondition(null, "SPECIMEN_NO='" + q.getSpecimen_no() + "'", null, 0, 0);
						if (items != null && items.size() > 0) {
							// 删除该取样编号向下的所有明细项目
							this.getMapper(QcmJhySampleConsignDItemMapper.class).doDeleteEntrustCom(q.getSpecimen_no());
						}

					}

					// 删除明细信息
					this.getMapper(QcmJhySampleConsignDMapper.class).deleteBySmpNo(qms.get(i).getSmp_no());

				}

				// 删除主表、合同表
				this.getMapper(QcmJhySampleConsignMMapper.class).deleteByInspection(plan.getInspection_lot());
				this.getMapper(QcmJhySampleROrdMapper.class).deleteByInspection(plan.getInspection_lot());

				if (targets != null && targets.size() > 0) {
					// 调用检验委托接口，重新生成检验委托
					CommonPage<QcmJhySampleFromPlan> comPage = new CommonPage<QcmJhySampleFromPlan>();
					comPage.setObjectList(targets);
					rm=this.getBean(QcmJhySampleConsignDItemServiceImpl.class).AutoGenerationSampleInfo(comPage);
					//rm = this.AutoGenerationSampleInfo(comPage);
					if ("500".equals(rm.getState())) {
						throw new Exception(rm.getMsgInfo());
					}
					
				}
				rm.setState("200");
				rm.setMsgInfo("删除试样信息成功！");

			} catch (Exception e) {
				rm.setState("500");
				rm.setMsgInfo("删除试样信息失败");
				throw new Exception();
			}

			return rm;
		}
	
	
	/**
	 * 获取分页交货状态
	 * 
	 */
	public ResultModel GetPscDeliveryByPage(CommonPage<ComPscRDelivery> cp) {

		ResultModel rm = new ResultModel();
		Integer pageSize= cp.getPageSize()*(cp.getPageIndex()-1);
		Integer pageIndex=cp.getPageSize()*(cp.getPageIndex()-1)+cp.getPageSize();
		ReturnMsg<List<ComPscRDelivery>> msg = new ReturnMsg<>();
		try {
			
			String condition="PSC='"+cp.getObject().getPsc()+"'";
			if (cp.getObject().getDeliveryStateDesc()!=null && !"".equals(cp.getObject().getDeliveryStateDesc())) {
				condition+="  and LOWER(DELIVERY_STATE_DESC) like '%'||LOWER('"+cp.getObject().getDeliveryStateDesc()+"')||'%'";
			}
			List<ComPscRDelivery> org=this.getMapper(ComPscRDeliveryMapper.class).findWithCondition(null, condition, null, pageSize, pageIndex);
			int count=this.getMapper(ComPscRDeliveryMapper.class).countWithCondition(null, condition);
			msg.setTotal(count);
			//msg.setMessage("获取数据成功");
			msg.setSuccess(true);
			msg.setResult(org);
			rm.setData(msg);
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("查询失败!");
		}

		return rm;

	}
	
	
	/**
	 * 给计划查询工艺项目的接口
	 * 2019/4/24
	 * 张姣
	 */

	public ResultModel getGongYi(CommonPage<SlmOrdDesignMscTic> com) {

		ResultModel rm = new ResultModel();

		try {
			if (com == null) {
				rm.setState("500");
				rm.setMsgInfo("请传入参数");
				return rm;
			}
			SlmOrdDesignMscTic tics = com.getObject();

			if (tics == null) {
				rm.setState("500");
				rm.setMsgInfo("请传需要查找的对象");
				return rm;
			}
			if (tics.getDesign_key() == null || "".equals(tics.getDesign_key())) {
				rm.setState("500");
				rm.setMsgInfo("请传入design_key");
				return rm;
			}

			if (tics.getMsc_pline() == null || "".equals(tics.getMsc_pline())) {
				rm.setState("500");
				rm.setMsgInfo("请传入全程产线号");
				return rm;
			}
			if (tics.getProcess_code() == null || "".equals(tics.getProcess_code())) {
				rm.setState("500");
				rm.setMsgInfo("请传入工序代码");
				return rm;
			}
			if (tics.getBacklog_seq() == null || "".equals(tics.getBacklog_seq())) {
				rm.setState("500");
				rm.setMsgInfo("请传入工序顺序号");
				return rm;
			}
			if (tics.getPline_code() == null || "".equals(tics.getPline_code())) {
				rm.setState("500");
				rm.setMsgInfo("请传入产线代码");
				return rm;
			}
			/*if (tics.getProcess_point_code() == null || "".equals(tics.getProcess_point_code())) {
				rm.setState("500");
				rm.setMsgInfo("请传入工序点代码");
				return rm;
			}
			if (tics.getMachine_code() == null || "".equals(tics.getMachine_code())) {
				rm.setState("500");
				rm.setMsgInfo("请传入机台代码");
				return rm;
			}*/
			
			String condition="VALIDFLAG='1'";
			if (tics.getDesign_key() != null && !"".equals(tics.getDesign_key())) {
				condition+=" and DESIGN_KEY='"+tics.getDesign_key()+"'"; 
			}

			if (tics.getMsc_pline() != null && !"".equals(tics.getMsc_pline())) {
				condition+=" and MSC_PLINE='"+tics.getMsc_pline()+"'"; 
			}
			if (tics.getProcess_code() != null && !"".equals(tics.getProcess_code())) {
				condition+=" and PROCESS_CODE='"+tics.getProcess_code()+"'";
			}
			if (tics.getBacklog_seq() != null && !"".equals(tics.getBacklog_seq())) {
				condition+=" and BACKLOG_SEQ='"+tics.getBacklog_seq()+"'";
			}
			if (tics.getPline_code() != null && !"".equals(tics.getPline_code())) {
				condition+=" and PLINE_CODE='"+tics.getPline_code()+"'";
			}
			if (tics.getProcess_point_code() != null && !"".equals(tics.getProcess_point_code())) {
				condition+=" and PROCESS_POINT_CODE='"+tics.getProcess_point_code()+"'";
			}
			if (tics.getMachine_code() != null && !"".equals(tics.getMachine_code())) {
				condition+=" and MACHINE_CODE='"+tics.getMachine_code()+"'";
			}
			List<SlmOrdDesignMscTic> target = new ArrayList<SlmOrdDesignMscTic>();
			target = this.getMapper(SlmOrdDesignMscTicMapper.class).findWithCondition(null, condition, null, 0, 0);

			List<SlmOrdDesignMscTicItem> tarItems = new ArrayList<SlmOrdDesignMscTicItem>();
			for (SlmOrdDesignMscTic tic : target) {
				tarItems.addAll(this.getMapper(SlmOrdDesignMscTicItemMapper.class).findWithCondition(null,
						"TIC='" + tic.getTic() + "'  and DESIGN_KEY='"+tic.getDesign_key()+"' and VALIDFLAG='1'", "INDEX_SEQ", 0, 0));
			}
			rm.setData(tarItems);
			rm.setState("200");

		} catch (Exception e) {
			e.printStackTrace();
			rm.setMsgInfo("查询失败");
			rm.setState("500");
			return rm;
		}

		return rm;

	}
	@Transactional(propagation = Propagation.REQUIRES_NEW,value = "tm", rollbackFor = Exception.class)
	public ResultModel insertJhyPhy(List<QcmJhyPhyresult> qjpList) {
		ResultModel rm = new ResultModel();
		rm.setState("200");
		try {
			if(qjpList != null && qjpList.size()>0){
				int count = 0; // seq
				for(QcmJhyPhyresult qjp: qjpList){
					if(DataHelper.IsNullOrSpace(qjp.getSpecimen_no())){
						rm.setState("403");
						rm.setMsgInfo("传入材质结果ID不能为空!");
						return rm;
					}
					if(DataHelper.IsNullOrSpace(qjp.getPhy_code_l())){
						rm.setState("403");
						rm.setMsgInfo("传入检验大项代码不能为空!");
						return rm;
					}
					if(DataHelper.IsNullOrSpace(qjp.getPhy_name_l())){
						rm.setState("403");
						rm.setMsgInfo("传入检验大项名称不能为空!");
						return rm;
					}
					if(DataHelper.IsNullOrSpace(qjp.getPhy_code_m())){
						rm.setState("403");
						rm.setMsgInfo("传入试样组代码不能为空!");
						return rm;
					}
					if(DataHelper.IsNullOrSpace(qjp.getPhy_name_m())){
						rm.setState("403");
						rm.setMsgInfo("传入试样组名称不能为空!");
						return rm;
					}
					if(DataHelper.IsNullOrSpace(qjp.getPhy_code_s())){
						rm.setState("403");
						rm.setMsgInfo("传入检验项代码不能为空!");
						return rm;
					}
					if(DataHelper.IsNullOrSpace(qjp.getPhy_name_s())){
						rm.setState("403");
						rm.setMsgInfo("传入检验项名称不能为空!");
						return rm;
					}
					if(!DataHelper.IsNullOrSpace(qjp.getItem_code_d()) && DataHelper.IsNullOrSpace(qjp.getItem_name_d())){
						rm.setState("403");
						rm.setMsgInfo("传入了试验方向代码时，试验方向名称不能为空!");
						return rm;
					}
					if(!DataHelper.IsNullOrSpace(qjp.getItem_name_d()) && DataHelper.IsNullOrSpace(qjp.getItem_code_d())){
						rm.setState("403");
						rm.setMsgInfo("传入了试验方向名称时，试验方向代码不能为空!");
						return rm;
					}
					if(!DataHelper.IsNullOrSpace(qjp.getItem_code_t()) && DataHelper.IsNullOrSpace(qjp.getItem_name_t())){
						rm.setState("403");
						rm.setMsgInfo("传入了试验温度代码时，试验温度名称不能为空!");
						return rm;
					}
					if(!DataHelper.IsNullOrSpace(qjp.getItem_name_t()) && DataHelper.IsNullOrSpace(qjp.getItem_code_t())){
						rm.setState("403");
						rm.setMsgInfo("传入了试验温度名称时，试验温度代码不能为空!");
						return rm;
					}
					if(!DataHelper.IsNullOrSpace(qjp.getItem_code_s()) && DataHelper.IsNullOrSpace(qjp.getItem_name_s())){
						rm.setState("403");
						rm.setMsgInfo("传入了试验尺寸代码时，试验尺寸名称不能为空!");
						return rm;
					}
					if(!DataHelper.IsNullOrSpace(qjp.getItem_name_s()) && DataHelper.IsNullOrSpace(qjp.getItem_code_s())){
						rm.setState("403");
						rm.setMsgInfo("传入了试验尺寸名称时，试验尺寸代码不能为空!");
						return rm;
					}
					if(DataHelper.IsNullOrSpace(qjp.getVal1())){
						rm.setState("403");
						rm.setMsgInfo("传入的值1不能为空!");
						return rm;
					}
					// 生成seq
					String conn = " SPECIMEN_NO = '"+qjp.getSpecimen_no()+"'";
					List<QcmJhyPhyresult> qjprList = this.getMapper(QcmJhyPhyresultMapper.class).findWithCondition(null, conn, "seq desc", 0, 0);
					if(qjprList.size()>0){
						count = Integer.parseInt(String.valueOf(qjprList.get(0).getSeq()));
					}
					count++;
					qjp.setSeq((long)count);
					qjp.setTest_qty((long)1);
					qjp.setGuid(DataHelper.getUUID());
					this.getMapper(QcmJhyPhyresultMapper.class).insert(qjp);
				}
			}
		} catch (Exception e) {
			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
			e.printStackTrace();
			rm.setMsgInfo("新增失败");
			rm.setState("500");
			return rm;
		}
		return rm;
	}
	@Transactional(propagation = Propagation.REQUIRES_NEW,value = "tm", rollbackFor = Exception.class)
	public ResultModel insertElement(List<QcmJhyElements> qjeList) {
		ResultModel rm = new ResultModel();
		rm.setState("200");
		try {
			if(qjeList != null && qjeList.size()>0){
				for(QcmJhyElements qje: qjeList){
					if(DataHelper.IsNullOrSpace(qje.getAssay_no())){
						rm.setState("403");
						rm.setMsgInfo("传入成分结果ID不能为空!");
						return rm;
					}
					if(DataHelper.IsNullOrSpace(qje.getMaterial_no())){
						rm.setState("403");
						rm.setMsgInfo("传入取样材料号不能为空!");
						return rm;
					}
					if(DataHelper.IsNullOrSpace(qje.getChem_code())){
						rm.setState("403");
						rm.setMsgInfo("传入化学元素代码不能为空!");
						return rm;
					}
					if(DataHelper.IsNullOrSpace(qje.getChem_name())){
						rm.setState("403");
						rm.setMsgInfo("传入化学元素名称不能为空!");
						return rm;
					}
					if(DataHelper.IsNullOrSpace(qje.getChem_value())){
						rm.setState("403");
						rm.setMsgInfo("传入成分值不能为空!");
						return rm;
					}
					qje.setAssay_type("L");
					qje.setCreate_time(new Date());
					this.getMapper(QcmJhyElementsMapper.class).insert(qje);
				}
			}
		} catch (Exception e) {
			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
			e.printStackTrace();
			rm.setMsgInfo("新增失败");
			rm.setState("500");
			return rm;
		}
		return rm;
	}
	/**
	 * 给物流的接口，根据元素名称查询化学元素信息
	 * @param cp 
	 * memo1  
	 * @return
	 */
	public ResultModel doQueryPhyBWeb(String chemName) {
		ResultModel rm = new ResultModel();
		if(DataHelper.IsNullOrSpace(chemName)){
			rm.setState("403");
			rm.setMsgInfo("请传入参数!");
			return rm;
		}
		try {
			String condition = " 1=1";
			List<ComBaseChem> Org = new ArrayList<>();
			condition += " and validflag = '1' and lower(chem_name) = '" +chemName+ "'";
			Org = this.getMapper(ComBaseChemMapper.class).findWithCondition(null, condition, "CHEM_CODE",0, 0);
			if(Org != null && Org.size()>0){
				rm.setData(Org.get(0));
			} else{
				rm.setData(null);
			}
			rm.setState("200");
		} catch (Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("查询失败!");
			ex.printStackTrace();
		}
		return rm;
	}
	/**
	 * 给生产的根据卷号查询表检公差判定结果
	 * @param cp 
	 * memo1  
	 * @return
	 */
	public ResultModel doQueryJudegeResult(String coilNo) {
		ResultModel rm = new ResultModel();
		if(DataHelper.IsNullOrSpace(coilNo)){
			rm.setState("403");
			rm.setMsgInfo("请传入参数!");
			return rm;
		}
		try {
			JudgeResult jr = new JudgeResult();
			jr.setCoilNo(coilNo);
			String configStr = this.getBean(ComBaseConfigServiceImpl.class).getConfig("QCM0010");
			if(!"1".equals(configStr)){
				jr.setUp_surface_result("40740601");
				jr.setUp_surface_result_desc("合格");
				jr.setUd_surface_result("40740601");
				jr.setUd_surface_result_desc("合格");
				jr.setMarginal_result("40740601");
				jr.setMarginal_result_desc("合格");
				jr.setMeasure_result("40740301");
				jr.setMeasure_result_desc("合格");
			}else{
				// 上表
				List<QcmJudgeSurface> qjsuList = this.getMapper(QcmJudgeSurfaceMapper.class).findWithCondition(null, " MATERIAL_NO='"+coilNo+"' and SF_TYPE='U'", "SURFACE_ID desc", 0, 0);
				if(qjsuList != null && qjsuList.size()>0){
					List<QcmJudgeSurfaceFlaw> qjsfuList = this.getMapper(QcmJudgeSurfaceFlawMapper.class).findWithCondition(null, "SURFACE_ID='"+qjsuList.get(0).getSurface_id()+"' and PRIMARY_FLAG = '1'", null, 0, 0);
					if(qjsfuList!=null && qjsfuList.size()>0){
						jr.setUp_surface_flaw(qjsfuList.get(0).getFlaw_code());
					}
					jr.setUp_surface_result(qjsuList.get(0).getSf_result_code());
					jr.setUp_surface_result_desc(qjsuList.get(0).getSf_result_desc());
					jr.setUp_surface_result_id(qjsuList.get(0).getSurface_id());
					jr.setBatchNo(qjsuList.get(0).getBatch_no());
					// 上表锁定标识
					jr.setSfu_is_lock(qjsuList.get(0).getSfu_is_lock());
				}
				
				// 下表
				List<QcmJudgeSurface> qjsdList = this.getMapper(QcmJudgeSurfaceMapper.class).findWithCondition(null, " MATERIAL_NO='"+coilNo+"' and SF_TYPE='D'", "SURFACE_ID desc", 0, 0);
				if(qjsdList != null && qjsdList.size()>0){
					List<QcmJudgeSurfaceFlaw> qjsfdList = this.getMapper(QcmJudgeSurfaceFlawMapper.class).findWithCondition(null, "SURFACE_ID='"+qjsdList.get(0).getSurface_id()+"' and PRIMARY_FLAG = '1'", null, 0, 0);
					if(qjsfdList!=null && qjsfdList.size()>0){
						jr.setUp_surface_flaw(qjsfdList.get(0).getFlaw_code());
					}
					jr.setUd_surface_result(qjsdList.get(0).getSf_result_code());
					jr.setUd_surface_result_desc(qjsdList.get(0).getSf_result_desc());
					jr.setUd_surface_result_id(qjsdList.get(0).getSurface_id());
					jr.setBatchNo(qjsdList.get(0).getBatch_no());
					// 下表锁定标识
					jr.setSfd_is_lock(qjsdList.get(0).getSfd_is_lock());
				}
				
				// 边部
				List<QcmJudgeSurface> qjseList = this.getMapper(QcmJudgeSurfaceMapper.class).findWithCondition(null, " MATERIAL_NO='"+coilNo+"' and SF_TYPE='E'", "SURFACE_ID desc", 0, 0);
				if(qjseList != null && qjseList.size()>0){
					List<QcmJudgeSurfaceFlaw> qjsfeList = this.getMapper(QcmJudgeSurfaceFlawMapper.class).findWithCondition(null, "SURFACE_ID='"+qjseList.get(0).getSurface_id()+"' and PRIMARY_FLAG = '1'", null, 0, 0);
					if(qjsfeList!=null && qjsfeList.size()>0){
						jr.setUp_surface_flaw(qjsfeList.get(0).getFlaw_code());
					}
					jr.setMarginal_result(qjseList.get(0).getSf_result_code());
					jr.setMarginal_result_desc(qjseList.get(0).getSf_result_desc());
					jr.setMarginal_result_id(qjseList.get(0).getSurface_id());
					jr.setBatchNo(qjseList.get(0).getBatch_no());
					// 边部锁定标识
					jr.setSfe_is_lock(qjseList.get(0).getSfe_is_lock());
				}
				
				// 公差
				List<QcmJudgeMeasure> qjmList = this.getMapper(QcmJudgeMeasureMapper.class).findWithCondition(null, " MATERIAL_NO='"+coilNo+"'", "SIC_ID desc", 0, 0);
				if(qjmList != null && qjmList.size()>0){
					jr.setMeasure_result(qjmList.get(0).getSic_result_code());
					jr.setMeasure_result_desc(qjmList.get(0).getSic_result_desc());
					jr.setSizeResult(qjmList.get(0).getSic_result_code());
					jr.setMeasure_result_id(qjmList.get(0).getSic_id());
					jr.setBatchNo(qjmList.get(0).getBatch_no());
					// 公差锁定标识
					jr.setSic_is_lock(qjmList.get(0).getSic_is_lock());
					jr.setJudge_length(qjmList.get(0).getJudge_length());
					jr.setJudge_width(qjmList.get(0).getJudge_width());
					jr.setJudge_thick(qjmList.get(0).getJudge_thick());
					jr.setJudge_camber(qjmList.get(0).getJudge_camber());
					jr.setJudge_offsquare(qjmList.get(0).getJudge_offsquare());
					jr.setJudge_turriform(qjmList.get(0).getJudge_turriform());
					jr.setJudge_unevenness(qjmList.get(0).getJudge_unevenness());
					jr.setMiddle_h_val(qjmList.get(0).getMiddle_h_val());
					jr.setMiddle_m_val(qjmList.get(0).getMiddle_m_val());
					jr.setMiddle_r_val(qjmList.get(0).getMiddle_r_val());
					jr.setNorth_h_val(qjmList.get(0).getNorth_h_val());
					jr.setNorth_m_val(qjmList.get(0).getNorth_m_val());
					jr.setNorth_r_val(qjmList.get(0).getNorth_r_val());
					jr.setSouth_h_val(qjmList.get(0).getSouth_h_val());
					jr.setSouth_m_val(qjmList.get(0).getSouth_m_val());
					jr.setSouth_r_val(qjmList.get(0).getSouth_r_val());
				}
			}
			rm.setData(jr);
			rm.setState("200");
		} catch (Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("查询失败!");
			ex.printStackTrace();
		}
		return rm;
	}
	/***
	 * 给生产通过原料卷号查询成分实绩信息接口
	 */
	public ResultModel GetElementsInfo(String material_no) {
		ResultModel rm = new ResultModel();
		try {
			if(DataHelper.IsNullOrSpace(material_no)){
				rm.setState("403");
				rm.setMsgInfo("请传入原料卷号!");
			}
			List<QcmJhyElements> qjeList = this.getMapper(QcmJhyElementsMapper.class).findWithCondition(null, "MATERIAL_NO='"+material_no+"'", null, 0, 0);
			rm.setData(qjeList);
			rm.setState("200");
		} catch (Exception e) {
			e.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!");
		}
		return rm;
	}
	/***
	 * 给物流接口根据卷号查询成分材质外观实绩及标准
	 */
	public List<ResultModel> getJudgeAndStdInfo(String coilNo,String design_key,String psc) {
		List<ResultModel> listrm=new ArrayList<>();
		ResultModel rmCic = new ResultModel(); // 成分实绩
		ResultModel rmPicStd = new ResultModel(); // 材质标准
		ResultModel rmPic = new ResultModel(); // 材质实绩
		ResultModel rmSuf = new ResultModel(); // 外观标准
		// 成分实绩
		YdmProductDetail ydm = this.getMapper(YdmProductDetailMapper.class).findById(coilNo);
		List<QcmJhyElements> qjeList = this.getMapper(QcmJhyElementsMapper.class).findWithCondition(null, "MATERIAL_NO='"+ydm.getChemresult_id()+"'", null, 0, 0);
		rmCic.setData(qjeList);
		// 材质标准
		CommonPage<SlmOrdDesignStd> cp = new CommonPage<>();
		SlmOrdDesignStd std = new SlmOrdDesignStd();
		std.setDesign_key(design_key);
		std.setPsc(psc);
		cp.setObject(std);
		rmPicStd=this.getBean(SlmOrdDesignStdPicServiceImpl.class).GetOrdDesignStdPic(cp);
		// 材质实绩
		List<QcmJudgePhysicalUtmD> qjpList = this.getMapper(QcmJudgePhysicalUtmDMapper.class).findWithCondition(null, "pic_id='"+ydm.getPhysresult_id()+"'", null, 0, 0);
		if(qjpList != null && qjpList.size() > 0){
			List<QcmPhyJudgeResult> qpjList = this.getMapper(QcmPhyJudgeResultMapper.class).findWithCondition(null, "phy_id="+qjpList.get(0).getPhy_id()+"'", null, 0, 0);
			rmPic.setData(qpjList);
		}
		// 外观标准
		rmSuf = this.getBean(QcmJudgeMeasureServiceImpl.class).getTolerance(cp);
		// 外观实绩
		listrm.add(rmCic);
		listrm.add(rmPicStd);
		listrm.add(rmPic);
		listrm.add(rmSuf);
		return listrm;
	}
	
	public HashMap<String, Double> doQueryJudegeRule(String design_key){
		HashMap<String, Double> ha=new HashMap<String, Double>();		
		if (design_key!=null && !"".equals(design_key)) {
			SlmOrdDesignMsc msc=this.getMapper(SlmOrdDesignMscMapper.class).findById(design_key);
			if (msc!=null) {
				ha.put("THICK", msc.getThick());
				ha.put("WIDTH", msc.getWidth());
				ha.put("LENGTH", msc.getLength());
			}
		}
		return ha;
	}
	
	
}
