package com.steering.pss.ydm.pipemanage;

import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;
import CoreFS.SC01.CoreConstantData;
import CoreFS.Util.StringUtils;
import com.steering.comm.converter.CoreConverter;
import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.EntityTool;
import com.steering.pss.judge.model.MatZcMEntity;
import com.steering.pss.ydm.entity.QcmLkJudgeChangeEntity;
import com.steering.pss.ydm.entity.QcmZgJugdeApplyEntity1;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

public class FrmLikuExamine extends DBCommon{
	
	/***
	 * 无权限查询
	 * @param parmList
	 * @return
	 */
	public CoreReturnObject doQueryApply(ArrayList<String> parmList)
	{
		return doQueryApply(parmList,null);
	}

	/***
	 * 查询成品利库申请信息
	 * @param parmList
	 * @return
	 */
	public CoreReturnObject doQueryApply(ArrayList<String> parmList,String[] arr)
	{
		return doQueryApply(parmList,null,null);
	}

	/**
	 * 查询成品利库申请信息
	 * @param parmList
	 * @param arr
	 * @param supp
	 * @return
	 */
	public CoreReturnObject doQueryApply(ArrayList<String> parmList,String[] arr,String supp)
	{
		String sql = CoreXmlSqlParsersFactory.getSql("FrmLikuExamine.doQueryApply");
		if(!parmList.get(0).equals(""))
		{
			sql += " AND T.CREATE_TIME >= TO_DATE('"+parmList.get(0)+"','YYYY-MM-DD HH24:MI:SS') AND T.CREATE_TIME <= TO_DATE('"+parmList.get(1)+"','YYYY-MM-DD HH24:MI:SS') ";
		}
		if(!parmList.get(2).equals(""))
		{
			sql += " AND T.JUDGE_STOVE_NO = '"+parmList.get(2)+"'";
		}
		if(!parmList.get(3).equals(""))
		{
			sql += " AND T.ORDER_NO LIKE '%"+parmList.get(3)+"%'";
		}
		if(parmList.get(4).equals("0"))
		{
			sql += " AND T.AGREE_FLAG = '0'";
		}else
		{
			sql += " AND T.AGREE_FLAG IN('1','2','3')";
		}
		if(arr != null && arr.length > 0){
			sql += CoreConverter.toSqlConditionString("T.MANAGE_NO", arr);
		}
		if(!StringUtils.isEmpty(supp)){
			sql+=" and T.SUPPLY_UNIT_CODE = '"+supp+"'";
		}
		return this.getData(sql);
	}
	/***
	 * 查询制程号
	 * @return
	 */
	public CoreReturnObject doQueryIndexSeq(String ordLnPk)
	{
		return this.getDataBySqlID("FrmLikuExamine.doQueryIndexSeq", new Object[]{ordLnPk});
	}
	
	/***
	 * 查询CIC
	 * @return
	 */
	public CoreReturnObject doQueryCic(String craftSeq,String ordLnPk,String indexSeq)
	{
		return this.getDataBySqlID("FrmLikuExamine.doQueryCic", new Object[]{craftSeq,ordLnPk,indexSeq});
	}
	
	/***
	 * 审批不通过
	 * @param parmList
	 * @return
	 */
	public CoreReturnObject auditNoCross(ArrayList<String> parmList)
	{
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		String sql = "";
		PreparedStatement psta = null;
		ResultSet rs = null;
		String flag = "";
		try {
			ArrayList<String> sqllist = new ArrayList<String>();
			for(String str : parmList)
			{
				QcmLkJudgeChangeEntity qcmLkEntity = EntityTool.getEntityByJSONStr(str, QcmLkJudgeChangeEntity.class);
				sql = CoreXmlSqlParsersFactory.getSql("FrmLikuExamine.selectLkFlag");
				sql = EntityTool.fillSqlByEntity(sql, qcmLkEntity);
				psta = connection.prepareStatement(sql);
				rs = psta.executeQuery();
				if(rs.next())
				{
					flag = rs.getString("AGREE_FLAG");
				}
				rs.close();
				psta.close();
				if(!flag.equals("0"))
				{
					cro.setV_errMsg("成品利库审批单不是未审批状态，不允许审批!");
					return cro;
				}
				if(qcmLkEntity.getAgreeMemo().equals(""))
				{
					cro.setV_errMsg("审批不通过时请输入审批备注信息!");
					return cro;
				}
				qcmLkEntity.setAgreeFlag("2");
				
				String auditNoSql = CoreXmlSqlParsersFactory.getSql("FrmLikuExamine.auditNoCross");
				auditNoSql = EntityTool.fillSqlByEntity(auditNoSql, qcmLkEntity);
				sqllist.add(auditNoSql);
			}
			cro = this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
			if(cro.getV_errMsg().equals(""))
			{
				cro.setV_errMsg("审批成功!");
			}
			
			
		} catch (Exception e) {
			System.out.println(e.getMessage());
			if (connection != null) {
				try {
					cro.setV_errMsg(e.getMessage());
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return cro;
	}
	/***
	 * 审批通过
	 * @return
	 */
	public CoreReturnObject auditCross(ArrayList<String> parmList)
	{
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		String sql = "";
		PreparedStatement psta = null;
		ResultSet rs = null;
		String flag = "";
		Date now = new Date();
		SimpleDateFormat df = new SimpleDateFormat("yyyyMM");
		String bathYear = df.format(now);
		String applyNo = "";//申请判定单号
		String processCode = "";//工序代码
		String pic = "";
		String sic = "";
		String dic = "";
		String wic = "";
		String gic = "";
		int typeCount = 0;
		try {
			ArrayList<String> sqllist = new ArrayList<String>();
			for(String str : parmList)
			{
				QcmLkJudgeChangeEntity qcmLkEntity = EntityTool.getEntityByJSONStr(str, QcmLkJudgeChangeEntity.class);
				sql = CoreXmlSqlParsersFactory.getSql("FrmLikuExamine.selectLkFlag");
				sql = EntityTool.fillSqlByEntity(sql, qcmLkEntity);
				psta = connection.prepareStatement(sql);
				rs = psta.executeQuery();
				if(rs.next())
				{
					flag = rs.getString("AGREE_FLAG");
				}
				rs.close();
				psta.close();
				if(!flag.equals("0"))
				{
					cro.setV_errMsg("成品利库审批单不是未审批状态，不允许审批!");
					return cro;
				}
				
				//查询物料信息
				sql = CoreXmlSqlParsersFactory.getSql("FrmLikuExamine.selectMatZcInfo");
				sql = EntityTool.fillSqlByEntity(sql, qcmLkEntity);
				psta = connection.prepareStatement(sql);
				rs = psta.executeQuery();
				MatZcMEntity matZcEntity = EntityTool.getEntityByRs(rs, MatZcMEntity.class);
				rs.close();
				psta.close();
				
				//查询是否成品送判过
				sql = CoreXmlSqlParsersFactory.getSql("FrmLikuExamine.selectQcmApply");
				sql = EntityTool.fillSqlByEntity(sql, qcmLkEntity);
				psta = connection.prepareStatement(sql);
				rs = psta.executeQuery();
				QcmZgJugdeApplyEntity1 qcmApplyEntity = EntityTool.getEntityByRs(rs, QcmZgJugdeApplyEntity1.class);
				rs.close();
				psta.close();
				//查询工序代码
				sql = CoreXmlSqlParsersFactory.getSql("FrmLikuExamine.selectProcessCode");
				sql = EntityTool.fillSqlByEntity(sql, qcmLkEntity);
				psta = connection.prepareStatement(sql);
				rs = psta.executeQuery();
				if(rs.next())
				{
					processCode = rs.getString("PROCESS_CODE");
				}
				rs.close();
				psta.close();
				qcmLkEntity.setProcessCode(processCode);
				//查询索引码
				sql = CoreXmlSqlParsersFactory.getSql("FrmLikuExamine.selectPic");
				sql = EntityTool.fillSqlByEntity(sql, qcmLkEntity);
				psta = connection.prepareStatement(sql);
				rs = psta.executeQuery();
				if(rs.next())
				{
					pic = rs.getString("PIC");
				}
				rs.close();
				psta.close();
				if(pic == null)
				{
					pic = "";
				}
				
				sql = CoreXmlSqlParsersFactory.getSql("FrmLikuExamine.selectSic");
				sql = EntityTool.fillSqlByEntity(sql, qcmLkEntity);
				psta = connection.prepareStatement(sql);
				rs = psta.executeQuery();
				if(rs.next())
				{
					sic = rs.getString("SIC");
				}
				rs.close();
				psta.close();
				if(sic == null)
				{
					sic = "";
				}
				
				sql = CoreXmlSqlParsersFactory.getSql("FrmLikuExamine.selectDic");
				sql = EntityTool.fillSqlByEntity(sql, qcmLkEntity);
				psta = connection.prepareStatement(sql);
				rs = psta.executeQuery();
				if(rs.next())
				{
					dic = rs.getString("DIC");
				}
				rs.close();
				psta.close();
				
				if(dic == null)
				{
					dic = "";
				}
				
				sql = CoreXmlSqlParsersFactory.getSql("FrmLikuExamine.selectWic");
				sql = EntityTool.fillSqlByEntity(sql, qcmLkEntity);
				psta = connection.prepareStatement(sql);
				rs = psta.executeQuery();
				if(rs.next())
				{
					wic = rs.getString("WIC");
				}
				rs.close();
				psta.close();
				
				if(wic == null)
				{
					wic = "";
				}
				
				sql = CoreXmlSqlParsersFactory.getSql("FrmLikuExamine.selectGic");
				sql = EntityTool.fillSqlByEntity(sql, qcmLkEntity);
				psta = connection.prepareStatement(sql);
				rs = psta.executeQuery();
				if(rs.next())
				{
					gic = rs.getString("GIC");
				}
				rs.close();
				psta.close();
				if(gic == null)
				{
					gic = "";
				}
				
				
				sql = CoreXmlSqlParsersFactory.getSql("FrmLikuExamine.selectIsType");
				sql = EntityTool.fillSqlByEntity(sql, qcmLkEntity);
				psta = connection.prepareStatement(sql);
				rs = psta.executeQuery();
				if(rs.next())
				{
					typeCount = Integer.parseInt(rs.getString("ACOUNT"));
				}
				rs.close();
				psta.close();
				
				
				applyNo = getApplyNo(connection,qcmLkEntity.getPlineCode());
				
				
				

				QcmZgJugdeApplyEntity1 qcmZgEntity = new QcmZgJugdeApplyEntity1();
				qcmZgEntity.setJugdeApplyCode(applyNo);
				qcmZgEntity.setJugdeApplySequeno("1");
				
				qcmZgEntity.setJudgeStoveNo(qcmLkEntity.getJudgeStoveNo());
				qcmZgEntity.setBatchNo(qcmLkEntity.getBatchNo());
				qcmZgEntity.setBatchGroudNo(qcmLkEntity.getBatchGroudNo());
				qcmZgEntity.setProcessCode(processCode);
				qcmZgEntity.setPlineCode(qcmLkEntity.getPlineCode());
				qcmZgEntity.setPlineName(qcmLkEntity.getPlineName());
				qcmZgEntity.setActCount(qcmLkEntity.getActCount());
				qcmZgEntity.setActWeight(qcmLkEntity.getActWeight());
				qcmZgEntity.setActTheoryWeight(qcmLkEntity.getActWeight());
				qcmZgEntity.setMaterialNo(qcmLkEntity.getMaterialNo());
				qcmZgEntity.setMaterialName(qcmLkEntity.getMaterialName());
				qcmZgEntity.setProduccode(qcmLkEntity.getProduccode());
				qcmZgEntity.setProducname(qcmLkEntity.getProducname());
				qcmZgEntity.setStdStyle(qcmLkEntity.getStdStyle());
				qcmZgEntity.setStdStyleDesc(qcmLkEntity.getStdStyleDesc());
				qcmZgEntity.setSteelcode(qcmLkEntity.getSteelcode());
				qcmZgEntity.setSteelname(qcmLkEntity.getSteelname());
				qcmZgEntity.setSpecCode(qcmLkEntity.getSpecCode());
				qcmZgEntity.setSpecName(qcmLkEntity.getSpecName());
				qcmZgEntity.setModelCode(qcmLkEntity.getModelCode());
				qcmZgEntity.setModelDesc(qcmLkEntity.getModelDesc());
				qcmZgEntity.setStdCode(qcmLkEntity.getStdCode());
				qcmZgEntity.setStdName(qcmLkEntity.getStdName());
				qcmZgEntity.setGradecode(qcmLkEntity.getGradecode());
				qcmZgEntity.setGradename(qcmLkEntity.getGradename());
				qcmZgEntity.setActDimater(qcmLkEntity.getActDimater());
				qcmZgEntity.setActHeight(qcmLkEntity.getActHeight());
				qcmZgEntity.setActLenMin(qcmLkEntity.getActLenMin());
				qcmZgEntity.setActLenMax(qcmLkEntity.getActLenMax());
				qcmZgEntity.setActLen(qcmLkEntity.getActLen());
				qcmZgEntity.setTarget("A");
				qcmZgEntity.setValidflag("20");
				qcmZgEntity.setJudgeResultCode("40740701");
				qcmZgEntity.setJudgeResult("合格");
				qcmZgEntity.setApplyName(qcmLkEntity.getCreateName());
				qcmZgEntity.setProOrderNo(qcmLkEntity.getOrderNo());
				qcmZgEntity.setOrdLnDlyPk(qcmLkEntity.getOrdLnDlyPk());
				qcmZgEntity.setApplyFlag("0");
				qcmZgEntity.setInstockFlag("1");
				qcmZgEntity.setBelongCode(matZcEntity.getBelongCode());
				qcmZgEntity.setBelongName(matZcEntity.getBelongName());
				qcmZgEntity.setBelongCodeJugde(matZcEntity.getBelongCode());
				qcmZgEntity.setBelongNameJugde(matZcEntity.getBelongName());
				qcmZgEntity.setBalYearMonth(bathYear);
				qcmZgEntity.setIsAllScrap("4");
				qcmZgEntity.setSteelStandrad("");
				qcmZgEntity.setLkFlag("3");
				if(matZcEntity.getZbsFlag().equals("") || matZcEntity.getZbsFlag().equals("2"))
				{
					qcmZgEntity.setZbsFlag("2");
				}else
				{
					qcmZgEntity.setZbsFlag("1");
				}
				qcmZgEntity.setCrafNo(qcmLkEntity.getCraftNo());
				qcmZgEntity.setCraftSeq(qcmLkEntity.getCraftSeq());
				qcmZgEntity.setIndexSeq(qcmLkEntity.getIndexSeq());
				qcmZgEntity.setCic(qcmLkEntity.getCic());
				qcmZgEntity.setPic(pic);
				qcmZgEntity.setDic(dic);
				qcmZgEntity.setGic(gic);
				qcmZgEntity.setWic(wic);
				qcmZgEntity.setSic(sic);
				qcmZgEntity.setIsendgx("1");
				qcmZgEntity.setSupplyUnitCode(qcmLkEntity.getSupplyUnitCode());
				qcmZgEntity.setSupplyUnit(qcmLkEntity.getSupplyUnit());
				if(typeCount > 0)
				{
					qcmZgEntity.setSteelStandrad(qcmLkEntity.getCic() + "+"
					+ pic + "+"
					+ sic + "+"
					+ dic + "+"
					+ wic + "+"
					+ gic);
				}else
				{
					qcmZgEntity.setSteelStandrad("+"
							+ pic + "+"
							+ sic + "+"
							+ dic + "+"
							+ wic + "+"
							+ gic);
				}
				if(qcmApplyEntity != null)
				{
					qcmZgEntity.setLotNo(qcmApplyEntity.getLotNo());
					qcmZgEntity.setStoveNo(qcmApplyEntity.getStoveNo());
					qcmZgEntity.setProOrderId(qcmApplyEntity.getProOrderId());
					qcmZgEntity.setFaceResultCode(qcmApplyEntity.getFaceResultCode());
					qcmZgEntity.setSpecResultCode(qcmApplyEntity.getSpecResultCode());
					qcmZgEntity.setChemResultCode(qcmApplyEntity.getChemResultCode());
					qcmZgEntity.setPhyResultCode(qcmApplyEntity.getPhyResultCode());
					qcmZgEntity.setDetectResultCode(qcmApplyEntity.getDetectResultCode());
					qcmZgEntity.setWpressureResultCode(qcmApplyEntity.getWpressureResultCode());
					qcmZgEntity.setProcessResultCode(qcmApplyEntity.getProcessResultCode());
					qcmZgEntity.setFaceResultPath(qcmApplyEntity.getFaceResultPath());
					qcmZgEntity.setSpecResultPath(qcmApplyEntity.getSpecResultPath());
					qcmZgEntity.setChemResultPath(qcmApplyEntity.getChemResultPath());
					qcmZgEntity.setPhyResultPath(qcmApplyEntity.getPhyResultPath());
					qcmZgEntity.setDetectResultPath(qcmApplyEntity.getDetectResultPath());
					qcmZgEntity.setWpressureResultPath(qcmApplyEntity.getWpressureResultPath());
					qcmZgEntity.setProcessResultPath(qcmApplyEntity.getProcessResultPath());
					qcmZgEntity.setMemo(qcmApplyEntity.getMemo());
					qcmZgEntity.setProcessStatus(qcmApplyEntity.getProcessStatus());
					qcmZgEntity.setMatGowhereCode(qcmApplyEntity.getMatGowhereCode());
					qcmZgEntity.setMatGowhereName(qcmApplyEntity.getMatGowhereName());
					qcmZgEntity.setTestingGrade(qcmApplyEntity.getTestingGrade());
					qcmZgEntity.setTestingGrade1(qcmApplyEntity.getTestingGrade1());
					qcmZgEntity.setTestingType(qcmApplyEntity.getTestingType());
					qcmZgEntity.setTestingType1(qcmApplyEntity.getTestingType1());
					qcmZgEntity.setDetectResultCode(qcmApplyEntity.getDetectResultCode());
					qcmZgEntity.setDetectResultCode1(qcmApplyEntity.getDetectResultCode1());
					qcmZgEntity.setExitTemp(qcmApplyEntity.getExitTemp());
					qcmZgEntity.setSampleNews(qcmApplyEntity.getSampleNews());
					qcmZgEntity.setGxPlanNo(qcmApplyEntity.getGxPlanNo());
					qcmZgEntity.setJudgeStoveNoSeq(qcmApplyEntity.getJudgeStoveNoSeq());
					qcmZgEntity.setCheckNo(qcmApplyEntity.getCheckNo());
					qcmZgEntity.setHeatPlanNo(qcmApplyEntity.getHeatPlanNo());
					qcmZgEntity.setDeliveryStateCode(qcmApplyEntity.getDeliveryStateCode());
					qcmZgEntity.setDeliveryStateName(qcmApplyEntity.getDeliveryStateName());
					qcmZgEntity.setLoadJudgeStoveNo(qcmApplyEntity.getLoadJudgeStoveNo());
					qcmZgEntity.setZpMLh(qcmApplyEntity.getZpMLh());
					qcmZgEntity.setZpColl(qcmApplyEntity.getZpColl());
					qcmZgEntity.setHttType(qcmApplyEntity.getHttType());
					qcmZgEntity.setMinTemp(qcmApplyEntity.getMinTemp());
					qcmZgEntity.setHttTechnology(qcmApplyEntity.getHttTechnology());
					qcmZgEntity.setNotchInfo(qcmApplyEntity.getNotchInfo());
					qcmZgEntity.setNotchLength(qcmApplyEntity.getNotchLength());
					qcmZgEntity.setNotchWidth(qcmApplyEntity.getNotchWidth());
					qcmZgEntity.setNotchDepth(qcmApplyEntity.getNotchDepth());
					qcmZgEntity.setLotNoGroup(qcmApplyEntity.getLotNoGroup());
					qcmZgEntity.setTestPressure(qcmApplyEntity.getTestPressure());
					qcmZgEntity.setTestPressureY(qcmApplyEntity.getTestPressureY());
					qcmZgEntity.setMchBevelResult(qcmApplyEntity.getMchBevelResult());
					qcmZgEntity.setMchChamferingResult(qcmApplyEntity.getMchChamferingResult());
					qcmZgEntity.setMchDimensionsResult(qcmApplyEntity.getMchDimensionsResult());
					qcmZgEntity.setMchPathResult(qcmApplyEntity.getMchPathResult());
					qcmZgEntity.setMchRadioactivityResult(qcmApplyEntity.getMchRadioactivityResult());
					qcmZgEntity.setMchRemanenceResult(qcmApplyEntity.getMchRemanenceResult());
					qcmZgEntity.setMchThreadInspectionResult(qcmApplyEntity.getMchThreadInspectionResult());
					qcmZgEntity.setMchTwistinglyResult(qcmApplyEntity.getMchTwistinglyResult());
					qcmZgEntity.setMchVisualResult(qcmApplyEntity.getMchVisualResult());
					qcmZgEntity.setMchWatergageResult(qcmApplyEntity.getMchWatergageResult());
					qcmZgEntity.setAngleVal(qcmApplyEntity.getAngleVal());
					qcmZgEntity.setEdgeVal(qcmApplyEntity.getEdgeVal());
					qcmZgEntity.setTestingStandar(qcmApplyEntity.getTestingStandar());
					qcmZgEntity.setDriftModelMin(qcmApplyEntity.getDriftModelMin());
					qcmZgEntity.setMeasuredEndPart(qcmApplyEntity.getMeasuredEndPart());
					qcmZgEntity.setMeasuredMiddlePart(qcmApplyEntity.getMeasuredMiddlePart());
					qcmZgEntity.setMeasuredTailPart(qcmApplyEntity.getMeasuredTailPart());
					qcmZgEntity.setHoldtimeTime(qcmApplyEntity.getHoldtimeTime());
					qcmZgEntity.setLoadBatchNo(qcmApplyEntity.getLoadBatchNo());
					qcmZgEntity.setSupplyUnitCode(qcmLkEntity.getSupplyUnitCode());
					qcmZgEntity.setSupplyUnit(qcmLkEntity.getSupplyUnit());

				}else
				{
					qcmZgEntity.setLotNo(qcmLkEntity.getLotNo());
					qcmZgEntity.setStoveNo(qcmLkEntity.getStoveNo());
					qcmZgEntity.setProOrderId("");
					qcmZgEntity.setFaceResultCode("");
					qcmZgEntity.setSpecResultCode("");
					qcmZgEntity.setChemResultCode("");
					qcmZgEntity.setPhyResultCode("");
					qcmZgEntity.setDetectResultCode("");
					qcmZgEntity.setWpressureResultCode("");
					qcmZgEntity.setProcessResultCode("");
					qcmZgEntity.setFaceResultPath("");
					qcmZgEntity.setSpecResultPath("");
					qcmZgEntity.setChemResultPath("");
					qcmZgEntity.setPhyResultPath("");
					qcmZgEntity.setDetectResultPath("");
					qcmZgEntity.setWpressureResultPath("");
					qcmZgEntity.setProcessResultPath("");
					qcmZgEntity.setMemo("");
					qcmZgEntity.setProcessStatus("");
					qcmZgEntity.setMatGowhereCode("/");
					qcmZgEntity.setMatGowhereName("/");
					qcmZgEntity.setTestingGrade("");
					qcmZgEntity.setTestingGrade1("");
					qcmZgEntity.setTestingType("");
					qcmZgEntity.setTestingType1("");
					qcmZgEntity.setDetectResultCode("");
					qcmZgEntity.setDetectResultCode1("");
					qcmZgEntity.setExitTemp("");
					qcmZgEntity.setSampleNews("");
					qcmZgEntity.setGxPlanNo("");
					qcmZgEntity.setJudgeStoveNoSeq("");
					qcmZgEntity.setCheckNo("");
					qcmZgEntity.setHeatPlanNo("");
					qcmZgEntity.setDeliveryStateCode("");
					qcmZgEntity.setDeliveryStateName("");
					qcmZgEntity.setLoadJudgeStoveNo("");
					qcmZgEntity.setZpMLh("");
					qcmZgEntity.setZpColl("");
					qcmZgEntity.setHttType("");
					qcmZgEntity.setMinTemp("");
					qcmZgEntity.setHttTechnology("");
					qcmZgEntity.setNotchInfo("");
					qcmZgEntity.setNotchLength("");
					qcmZgEntity.setNotchWidth("");
					qcmZgEntity.setNotchDepth("");
					qcmZgEntity.setLotNoGroup("");
					qcmZgEntity.setTestPressure("");
					qcmZgEntity.setTestPressureY("");
					qcmZgEntity.setMchBevelResult("");
					qcmZgEntity.setMchChamferingResult("");
					qcmZgEntity.setMchDimensionsResult("");
					qcmZgEntity.setMchPathResult("");
					qcmZgEntity.setMchRadioactivityResult("");
					qcmZgEntity.setMchRemanenceResult("");
					qcmZgEntity.setMchThreadInspectionResult("");
					qcmZgEntity.setMchTwistinglyResult("");
					qcmZgEntity.setMchVisualResult("");
					qcmZgEntity.setMchWatergageResult("");
					qcmZgEntity.setAngleVal("");
					qcmZgEntity.setEdgeVal("");
					qcmZgEntity.setTestingStandar("");
					qcmZgEntity.setDriftModelMin("");
					qcmZgEntity.setMeasuredEndPart("");
					qcmZgEntity.setMeasuredMiddlePart("");
					qcmZgEntity.setMeasuredTailPart("");
					qcmZgEntity.setHoldtimeTime("");
					qcmZgEntity.setLoadBatchNo(qcmLkEntity.getBatchNo());
					qcmZgEntity.setSupplyUnitCode(qcmLkEntity.getSupplyUnitCode());
					qcmZgEntity.setSupplyUnit(qcmLkEntity.getSupplyUnit());
				}
				
				qcmLkEntity.setJugdeApplyCode(applyNo+qcmZgEntity.getJugdeApplySequeno());
				qcmLkEntity.setAgreeFlag("1");
				String updateQcmLkSql = CoreXmlSqlParsersFactory.getSql("FrmLikuExamine.updateQcmLk");//修改审批单信息
				updateQcmLkSql = EntityTool.fillSqlByEntity(updateQcmLkSql, qcmLkEntity);
				sqllist.add(updateQcmLkSql);
				
				
				String insertQcmApplySql = CoreXmlSqlParsersFactory.getSql("FrmLikuExamine.insertQcmApply");//插入申请判定信息
				insertQcmApplySql = EntityTool.fillSqlByEntity(insertQcmApplySql, qcmZgEntity);
				sqllist.add(insertQcmApplySql);
			}
			cro = this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
			if(cro.getV_errMsg().equals(""))
			{
				cro.setV_errMsg("审批成功!");
			}
		} catch (Exception e) {
			System.out.println(e.getMessage());
			if (connection != null) {
				try {
					cro.setV_errMsg(e.getMessage());
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return cro;
	}
	/***
	 * 撤销审批
	 * @param parmList
	 * @return
	 */
	public CoreReturnObject cancelAudit(ArrayList<String> parmList)
	{
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		String sql = "";
		PreparedStatement psta = null;
		ResultSet rs = null;
		String flag = "";
		try {
			ArrayList<String> sqllist = new ArrayList<String>();
			for(String str : parmList)
			{
				QcmLkJudgeChangeEntity qcmLkEntity = EntityTool.getEntityByJSONStr(str, QcmLkJudgeChangeEntity.class);
				sql = CoreXmlSqlParsersFactory.getSql("FrmLikuExamine.selectLkFlag");
				sql = EntityTool.fillSqlByEntity(sql, qcmLkEntity);
				psta = connection.prepareStatement(sql);
				rs = psta.executeQuery();
				if(rs.next())
				{
					flag = rs.getString("AGREE_FLAG");
				}
				rs.close();
				psta.close();
				if(!flag.equals("1"))
				{
					cro.setV_errMsg("成品利库审批单不是审批通过状态，不允许撤销审批!");
					return cro;
				}
				
				String updateQcmLkSql = CoreXmlSqlParsersFactory.getSql("FrmLikuExamine.cancelAudit");//撤销审批
				updateQcmLkSql = EntityTool.fillSqlByEntity(updateQcmLkSql,qcmLkEntity);
				sqllist.add(updateQcmLkSql);
			}
			cro = this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
			if(cro.getV_errMsg().equals(""))
			{
				cro.setV_errMsg("撤销成功!");
			}
			
		} catch (Exception e) {
			System.out.println(e.getMessage());
			if (connection != null) {
				try {
					cro.setV_errMsg(e.getMessage());
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return cro;
	}
	

	//生成申请判定单号
	private String getApplyNo(Connection connection,String plineCode) throws SQLException {
		String judgeApplyNo = "";
		String sql = "";
		PreparedStatement psta = null;
		ResultSet rs = null;
		sql = CoreXmlSqlParsersFactory.getSql("FrmLikuExamine.getApplyNo");
		psta = connection.prepareStatement(sql);
		psta.setString(1, plineCode);
		psta.setString(2, plineCode);
		rs = psta.executeQuery();
		if(rs.next())
		{
			judgeApplyNo = rs.getString("JUGDE_APPLY_CODE");
		}
		rs.close();
		psta.close();
		return judgeApplyNo;
	}
}
