package com.steering.pss.plnsaleord.planStove;

import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;
import CoreFS.SC01.CoreConstantData;
import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.EntityTool;
import com.steering.pss.plnsaleord.planStove.entity.MatBcTrackEntity;
import com.steering.pss.plnsaleord.planStove.entity.YdmBcOutlistEntity;
import com.steering.pss.plnsaleord.steelMarkingPlan.FrmSteelMakingPlanChange;
import com.steering.pss.plnsaleord.stove.PlanFurnProduction;
import com.steering.pss.plnsaleord.stove.corePlanFurnProM;
import com.steering.pss.plnsaleord.stove.entity.*;

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

/**
 * 管坯材料信息
 * 
 * @author teng 2017.11.21
 */
public class FrmPlanMaterialJgx extends DBCommon {

	/**
	 * 根据轧管投入产出信息waeZ
	 *
	 * @return
	 */
	public CoreReturnObject queryBaseMaterialDPl(String inwlId, String outwlId,
												 String plineCode) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmPlanMaterialJgx.queryBaseMaterialDPl");
		return this.getData(sql, new Object[]{inwlId, outwlId, plineCode});
	}

	/**
	 * 查询管坯库存信息
	 *
	 * @return
	 */
	public CoreReturnObject queryMaterial(String materialNo,
										  String processCode, String proPlanId, String gxPlanNo,
										  String wholeBacklogDesc, String plineCode) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmPlanMaterialJgx.queryMaterial");
		if (wholeBacklogDesc.contains("热处理")) {
			sql += " AND  T.PROCESS_CDOE IN ('F','G')";
		} else if (wholeBacklogDesc.contains("镦拔扩")) {
			sql += "  AND  T.PROCESS_CDOE IN ('E','G')";
		} else if (wholeBacklogDesc.contains("轧制")) {
			sql += "  AND  T.PROCESS_CDOE IN ('D','G')";
		}
		/*if (!plineCode.equals("C072") && !plineCode.equals("C091") && !plineCode.equals("C092")&& !plineCode.equals("C102")) {
			sql += "  AND T.BELONG_CODE = '002001001'";
		} else {
			sql += " AND T.BELONG_CODE = '002023005' ";
		}*/
		sql += "  GROUP BY T.MATERIAL_NO, T.MATERIAL_NAME,T.JUDGE_STOVE_NO, T.BATCH_NO,  T.BATCH_GROUD_NO, T.STOVE_NO,"
				+ " T.PRO_ORDER_ID,  T.GX_PLAN_NO,  T.HEAT_PLAN_NO,T.PRO_PLAN_ID_NEXT,   T.GX_PLAN_NO_NEXT, T.PRODUCNAME,"
				+ " T.GRADENAME,  T.STEELNAME,  T.SPEC_NAME,   T.MODEL_DESC,  T.STD_NAME,  T.STD_STYLE_DESC, T.NEXT_PROCESS_CDOE, "
				+ " T.PLINE_NAME,T.PLINE_CODE, T.ACT_DIMATER,  T.ACT_HEIGHT,T.ACT_LEN_MIN,  T.ACT_LEN_MAX,  T.PRODUCT_FLAG,  T.MAT_STATUS, "
				+ " S.STORAGE_NO,T.BELONG_NAME, T.ORDER_NO,T.ORDER_SEQ, T.PRO_ORDER_NO,T.CRAF_NO,t.cic,T.JUDGE_RESULT_CODE,T.JUDGE_RESULT,T.MEMO";
		return this.getData(sql, new Object[]{proPlanId, gxPlanNo, proPlanId,
				gxPlanNo, materialNo});
	}

	/**
	 * 查询管坯库存信息
	 *
	 * @return
	 */
	public CoreReturnObject queryMaterial1(String materialNo,
										   String processCode, String proPlanId, String gxPlanNo,
										   String wholeBacklogDesc) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmPlanMaterialJgx.queryMaterial1");
		if (wholeBacklogDesc.contains("热处理")) {
			sql += " AND  T.PROCESS_CDOE IN ('F','G')";
		} else if (wholeBacklogDesc.contains("镦拔扩")) {
			sql += "  AND  T.PROCESS_CDOE IN ('E','G')";
		} else if (wholeBacklogDesc.contains("轧制")) {
			sql += "  AND  T.PROCESS_CDOE IN ('D','G')";
		}
		sql += "  GROUP BY T.MATERIAL_NO, T.MATERIAL_NAME,T.JUDGE_STOVE_NO, T.BATCH_NO,  T.BATCH_GROUD_NO, T.STOVE_NO,"
				+ " T.PRO_ORDER_ID,  T.GX_PLAN_NO,  T.HEAT_PLAN_NO,T.PRO_PLAN_ID_NEXT,   T.GX_PLAN_NO_NEXT, T.PRODUCNAME,"
				+ " T.GRADENAME,  T.STEELNAME,  T.SPEC_NAME,   T.MODEL_DESC,  T.STD_NAME,  T.STD_STYLE_DESC, T.NEXT_PROCESS_CDOE, T.PLINE_CODE,"
				+ " T.PLINE_NAME,T.PLINE_CODE, T.ACT_DIMATER,  T.ACT_HEIGHT,T.ACT_LEN,T.ACT_LEN_MIN,  T.ACT_LEN_MAX,  T.PRODUCT_FLAG,  T.MAT_STATUS, "
				+ " S.STORAGE_NO,T.BELONG_NAME, T.ORDER_NO,T.ORDER_SEQ, T.PRO_ORDER_NO,T.CRAF_NO,t.cic,T.JUDGE_RESULT_CODE,T.JUDGE_RESULT,T.MEMO";
		return this.getData(sql, new Object[]{proPlanId, gxPlanNo, proPlanId,
				gxPlanNo, materialNo});
	}

	/***
	 * 短节备料利库
	 * @return
	 */
	public CoreReturnObject doAddLibraryB(ArrayList<ArrayList<String>> jslist,
										  String userName, String proPlanId, String gxPlanNo, String lenFalg, String plnOrderTity) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();

		PreparedStatement ps = null;
		ResultSet rs = null;
		String sql = "";
		String outDoc = "";
		try {
			conn.setAutoCommit(false);
			Date now = new Date();
			SimpleDateFormat dateFormat = new SimpleDateFormat(
					"yyyy-MM-dd HH:mm:ss");
			SimpleDateFormat df = new SimpleDateFormat("yyyyMM");
			String systime = dateFormat.format(now);
			String bathYear = df.format(now);
			ArrayList<String> sqllist = new ArrayList<String>();
			// 获取数据库当前时间
			String dateTime = FrmSteelMakingPlanChange.getSystemTime(conn);
			// 查询热处理信息
			PlnOrderJgxSEntity plnRclS = FrmPlanMaterialDbk.getPlanOrderS(conn,
					proPlanId, gxPlanNo, PlnOrderJgxSEntity.class, "G");
			if (plnRclS == null) {
				cro.setV_errMsg("未找到加工线订单(" + proPlanId + "/" + gxPlanNo
						+ ")信息!");
				return cro;
			}
			PlnOrderJgxSEntity plOrderEntity = EntityTool.getEntityByJSONStr(plnOrderTity, PlnOrderJgxSEntity.class);
			int seq = 1;
			outDoc = queryOutDoc(conn);
			// 循环库存信息
			for (int i = 0; i < jslist.size(); i++) {
				Date now1 = new Date();
				SimpleDateFormat dateFormat1 = new SimpleDateFormat(
						"yyyyMMddHHmmss");
				DecimalFormat df1 = new DecimalFormat("0000000000");
				String judgeApplyCode = "";
				String belongCode = "002001002011";
				String belongName = "加工线01#（管加工1#线）";
				String baseCode = "";
				String baseName = "";//交货状态
				String designKey = "";
				String heatPlanNo = "";//炉计划ID
				judgeApplyCode = doQueryApplyCode(conn, jslist.get(i).get(9));

				ArrayList<String> list = (ArrayList<String>) jslist.get(i);
				String judgeStoveNo = list.get(0);
				String batchNo = list.get(1);
				String batchGroupBy = list.get(2);
				String materialNo = list.get(3);
				int takeCount = Integer.parseInt(list.get(4));// 利库支
				// String proPlanIdNo = list.get(5);// 本工序订单号
				// String UpproPlanIdNo = list.get(6);// 上工序订单号
				String specCic = list.get(7);
				String actLen = list.get(8);
				String plineCode = list.get(9);
				String storageNo = list.get(12);
				List<MatBcMEntityPln> matGpMlist = FrmPlanMaterialDbk
						.getQureyMatGpMB(conn, judgeStoveNo, batchNo,
								batchGroupBy, materialNo, takeCount, "", "G", actLen, lenFalg, storageNo);
				if (matGpMlist == null) {
					cro.setV_errMsg("物料已发生改变/备料短节利库只允许利库备料产出工序的物料!");
					return cro;
				}
				MatBcTrackEntity matTrack = FrmPlanMaterialDbk
						.getQureyMatTrack(conn, judgeStoveNo, batchNo,
								batchGroupBy, takeCount, "0", "",
								MatBcTrackEntity.class, "add", actLen, lenFalg);
				if (matTrack == null) {
					cro.setV_errMsg("物料已发生改变,请刷新!");
					return cro;
				}

				sql = CoreXmlSqlParsersFactory.getSql("FrmPlanMaterialJgx.selectBelong");
				ps = conn.prepareStatement(sql);
				ps.setString(1, plOrderEntity.getPlineCode());
				rs = ps.executeQuery();
				if (rs.next()) {
					belongCode = rs.getString("DEPARTMENT_CODE");
					belongName = rs.getString("DEPARTMENT_DESC");
				}
				rs.close();
				ps.close();

				double actWt = 0;

				int countAppCode = 0;
				String stoveNo = "";
				String upperHeatplanId = "";
				String upProessCode = "";
				String inwlId = "";
				String inwlDesc = "";
				String lengthIn = "";
				String lengthmaxIn = "";
				String lengthminIn = "";
				String outdiameterIn = "";
				String wallthickIn = "";
				int outnumCut = 1;
				String flagStoveNo = "";
				String gradeName = "";
				for (MatBcMEntityPln matGpM : matGpMlist) {
					countAppCode++;
					gradeName = matGpM.getGradename();
					//jugdeApplyCode = matGpM.getJugdeApplyCode();
					flagStoveNo = matGpM.getFlagStoveNoZg();
					stoveNo = matGpM.getStoveNo();
					inwlId = matGpM.getMaterialNo();
					inwlDesc = matGpM.getMaterialName();
					upProessCode = matGpM.getProcessCdoe();
					upperHeatplanId = matGpM.getHeatPlanNo();
					lengthIn = matGpM.getActLen();
					lengthmaxIn = matGpM.getActLenMax();
					lengthminIn = matGpM.getActLenMin();
					outdiameterIn = matGpM.getActDimater();
					wallthickIn = matGpM.getActHeight();
					actWt += Double.parseDouble(matGpM.getActWeight());
					if (!matGpM.getProductFlag().equals("801401")) {
						cro.setV_errMsg("材料类别不是在制品,不能利库!");
						return cro;
					}
					if (!matGpM.getMatStatus().equals("80150102")
							&& !matGpM.getInstancyFlag().equals("1")) {
						cro.setV_errMsg("材料状态不是产出已判定状态并且不是紧急放行状态,不能利库");
						return cro;
					}
					if (!matGpM.getQcmStaus().equals("00")) {
						cro.setV_errMsg("交库状态不是合格状态,不能利库!");
						return cro;
					}

					//短接备料利库时新增产权出库
					YdmBcOutlistEntity ydmOutEntity = new YdmBcOutlistEntity();
					ydmOutEntity.setOutstockDoc(outDoc);
					ydmOutEntity.setMatNo(matGpM.getMatNo());
					ydmOutEntity.setCreateName(userName);
					ydmOutEntity.setCreateTime(systime);
					ydmOutEntity.setLoadPlineCode(plOrderEntity.getPlineCode());
					ydmOutEntity.setLoadPlineName(plOrderEntity.getPlineName());
					String insertOutCqSql = CoreXmlSqlParsersFactory.getSql("FrmPlanMaterialJgx.insertYdmOut");
					insertOutCqSql = EntityTool.fillSqlByEntity(insertOutCqSql, ydmOutEntity);
					ps = conn.prepareStatement(insertOutCqSql);
					ps.executeUpdate();
					ps.close();


					// 修改坯子库存信息
					String sqlUpdateMat = CoreXmlSqlParsersFactory
							.getSql("FrmPlanMaterialDbk.UpdateMatGpB");
					ps = conn.prepareStatement(sqlUpdateMat);
					ps.setObject(1, "80150101");
					ps.setObject(2, "");
					ps.setObject(3, "");
					ps.setObject(4, "0");
					ps.setObject(5, "0");
					ps.setObject(6, "");
					ps.setObject(7, "");
					ps.setObject(8, judgeApplyCode);
					ps.setObject(9, belongCode);
					ps.setObject(10, belongName);
					ps.setObject(11, plOrderEntity.getOrderNo() + "/" + plOrderEntity.getOrderSeq());
					ps.setObject(12, plOrderEntity.getPlineCode());
					ps.setObject(13, plOrderEntity.getPlineName());
					ps.setObject(14, plOrderEntity.getCraftFileNo());
					ps.setObject(15, plOrderEntity.getCraftSeq());
					ps.setObject(16, matGpM.getMatNo());
					ps.executeUpdate();
					ps.close();



				}
				String resumeSeq = dateFormat1.format(now1) + df1.format(seq);
				// 生成利库日志
				matTrack.setResumeSeq(resumeSeq);
				matTrack.setEventId("900102");
				matTrack.setEventDesc("利库");
				matTrack.setFormName("com.steering.pss.plnsaleord.planStove.FrmPlanMaterialJgx");
				matTrack.setCallFuncCoding("doAddLibrary");
				matTrack.setKeyvalue1("List<MatBcMEntityPln> matGpMlist");
				matTrack.setKeyvalue1Desc("物料主表关键字实体类集合");
				matTrack.setKeyvalue2("String userName");
				matTrack.setKeyvalue2Desc2("操作人");
				matTrack.setProcessCdoe("F");
				matTrack.setMemo("");
				matTrack.setCreateName(userName);
				matTrack.setCreateTime(dateTime);
				seq++;
				// 新增利库记录
				String sqlAddTrack = EntityTool.fillSqlByEntity(
						CoreXmlSqlParsersFactory
								.getSql("FrmPlanMaterialDbk.addMatBcTrack"),
						matTrack);
				ps = conn.prepareStatement(sqlAddTrack);
				ps.executeUpdate();
				ps.close();

				sql = CoreXmlSqlParsersFactory
						.getSql("FrmPlanMaterialJgx.SelectDesignKey");// 查询designkey和mscPline
				ps = conn.prepareStatement(sql);
				ps.setString(1, plOrderEntity.getCraftFileNo());
				ps.setString(2, plOrderEntity.getCraftSeq());
				rs = ps.executeQuery();
				if (rs.next()) {
					designKey = rs.getString("DESGIN_KEY");
				}
				rs.close();
				ps.close();

				sql = CoreXmlSqlParsersFactory
						.getSql("FrmPlanMaterialJgx.SelectBaseCode1");// 查询交货状态
				ps = conn.prepareStatement(sql);
				ps.setString(1, designKey);
				ps.setString(2, plOrderEntity.getIndexSeq());
				ps.setString(3, "B");
				rs = ps.executeQuery();
				if (rs.next()) {
					baseCode = rs.getString("BASECODE");
					baseName = rs.getString("BASENAME");
				}
				rs.close();
				ps.close();

				sql = CoreXmlSqlParsersFactory.getSql("FrmPlanMaterialJgx.selectHeatPlanNo");
				ps = conn.prepareStatement(sql);
				ps.setString(1, jslist.get(i).get(0));
				ps.setString(2, jslist.get(i).get(1));
				rs = ps.executeQuery();
				if (rs.next()) {
					heatPlanNo = rs.getString("HEAT_PLAN_NO");
				}
				rs.close();
				ps.close();

				QcmZgJugdeApplyEntity qcmEntity = new QcmZgJugdeApplyEntity();
				qcmEntity.setJugdeApplyCode(judgeApplyCode);
				qcmEntity.setJudgeApplySequeno("1");
				qcmEntity.setJudgeStoveNo(judgeStoveNo);
				qcmEntity.setBatchNo(batchNo);
				qcmEntity.setBatchGroudNo(batchGroupBy);
				qcmEntity.setActCount(String.valueOf(takeCount));
				qcmEntity.setIsAllScrap("5");
				qcmEntity.setApplyName(userName);
				qcmEntity.setApplyTime(systime);
				qcmEntity.setBelongCode(belongCode);
				qcmEntity.setBelongName(belongName);
				qcmEntity.setProOrderNo(plOrderEntity.getOrderNo());
				qcmEntity.setCrafNo(plOrderEntity.getCraftFileNo());
				qcmEntity.setCraftSeq(plOrderEntity.getCraftSeq());
				qcmEntity.setOrdLnDlyPk(plOrderEntity.getOrdLnDlyPk());
				qcmEntity.setProOrderId(plOrderEntity.getProPlanId());
				qcmEntity.setGxPlanNo(plOrderEntity.getGxPlanNo());
				qcmEntity.setSteelStandrad(plOrderEntity.getCic() + "+" + plOrderEntity.getPic() + "+" + plOrderEntity.getSic() + "+" + plOrderEntity.getDic());
				qcmEntity.setDeliveryStateCode(baseCode);
				qcmEntity.setDeliveryStateName(baseName);
				qcmEntity.setCic(list.get(7));
				qcmEntity.setPic(plOrderEntity.getPic());
				qcmEntity.setSic(plOrderEntity.getSic());
				qcmEntity.setDic(plOrderEntity.getDic());
				qcmEntity.setWic(plOrderEntity.getWic());
				qcmEntity.setGic(plOrderEntity.getGic());
				qcmEntity.setIndexSeq(plOrderEntity.getIndexSeq());
				qcmEntity.setHeatPlanNo(heatPlanNo);
				qcmEntity.setPlineCode(plOrderEntity.getPlineCode());
				qcmEntity.setPlineName(plOrderEntity.getPlineName());
				qcmEntity.setOldPlineCode(plOrderEntity.getPlineCode());
				qcmEntity.setActLenMin(list.get(10));
				qcmEntity.setActLenMax(list.get(11));
				qcmEntity.setStorageNo(list.get(12));

				qcmEntity.setMaterialNo(plOrderEntity.getOutwlId());
				qcmEntity.setMaterialNo(plOrderEntity.getOutwlDesc());
				qcmEntity.setProduccode(plOrderEntity.getProduccode());
				qcmEntity.setProducname(plOrderEntity.getProducname());
				qcmEntity.setStdStyle(plOrderEntity.getStdStyle());
				qcmEntity.setStdStyleDesc(plOrderEntity.getStdStyleDesc());
				qcmEntity.setSteelcode(plOrderEntity.getSteelcode());
				qcmEntity.setSteelname(plOrderEntity.getSteelname());
				qcmEntity.setSpecCode(plOrderEntity.getSpecCode());
				qcmEntity.setSpecName(plOrderEntity.getSpecName());
				qcmEntity.setModelCode(plOrderEntity.getModelCode());
				qcmEntity.setModelDesc(plOrderEntity.getModelDesc());
				qcmEntity.setActDimater(plOrderEntity.getOutdiameter());
				qcmEntity.setActHeight(plOrderEntity.getWallthick());
				qcmEntity.setSupplyUnit("120501");
				qcmEntity.setSupplyUnitDesc("天津钢管制造有限公司");


				String insertQcmSql = CoreXmlSqlParsersFactory.getSql("FrmPlanMaterialJgx.insertQcm");
				insertQcmSql = EntityTool.fillSqlByEntity(insertQcmSql, qcmEntity);
				ps = conn.prepareStatement(insertQcmSql);
				ps.executeUpdate();
				ps.close();

			}
			conn.commit();
			cro.setV_errMsg("利库成功!");

		} catch (Exception sqle) {
			try {
				conn.rollback();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			cro.setV_errCode(-1);
			cro.setV_errMsg(sqle.getMessage());
		} finally {
			try {
				if (conn != null && !conn.isClosed()) {
					conn.close();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return cro;
	}

	/***
	 * 生成产权出库单号
	 * @param conn
	 * @return
	 */
	private String queryOutDoc(Connection conn) {
		String outDoc = "";
		String sql = CoreXmlSqlParsersFactory.getSql("FrmPlanMaterialJgx.getOutDocCq");
		PreparedStatement psta = null;
		try {
			psta = conn.prepareStatement(sql);
			ResultSet rs = psta.executeQuery();
			if (rs.next()) {
				outDoc = rs.getString("OUTSTOCK_DOC");
			}
			rs.close();
			psta.close();
		} catch (SQLException e) {

			e.printStackTrace();
		}
		return outDoc;
	}
	/***
	 * 生成申请判定单号
	 * @param conn
	 * @param plineCode
	 * @return
	 * @throws SQLException
	 */
	private String doQueryApplyCode(Connection conn,String plineCode) throws SQLException {
		
		String judgeApplyCode = "";
		PreparedStatement psta = null;
		ResultSet rs = null;
		String _plineCode = "";
		if(plineCode.equals("100101")||plineCode.equals("100102")||plineCode.equals("100103"))
		{
			_plineCode = "C028";
		}
		String sql = CoreXmlSqlParsersFactory.getSql("FrmPlanMaterialJgx.doQueryApplyCode");
		psta = conn.prepareStatement(sql);
		psta.setString(1, _plineCode);
		rs = psta.executeQuery();
		if(rs.next())
		{
			judgeApplyCode = rs.getString("JUGDE_APPLY_CODE");
		}
		rs.close();
		psta.close();
		return judgeApplyCode;
	}

	/**
	 * 坯子利库
	 * 
	 * @param jslist
	 * @param userName
	 *            利库人
	 * @param proPlanId
	 *            订单号
	 * @param gxPlanNo
	 *            排产序号
	 * @return
	 * @throws ParseException
	 */
	public CoreReturnObject doAddLibrary(ArrayList<ArrayList<String>> jslist,
			String userName, String proPlanId, String gxPlanNo,String lenFalg)
			throws ParseException {
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = null;
		try {
			conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			conn.setAutoCommit(false);
			PreparedStatement ps = null;
			ResultSet rs = null;
			// 获取数据库当前时间
			String dateTime = FrmSteelMakingPlanChange.getSystemTime(conn);
			// 查询热处理信息
			PlnOrderJgxSEntity plnRclS = FrmPlanMaterialDbk.getPlanOrderS(conn,
					proPlanId, gxPlanNo, PlnOrderJgxSEntity.class, "G");
			if (plnRclS == null) {
				cro.setV_errMsg("未找到加工线订单(" + proPlanId + "/" + gxPlanNo
						+ ")信息!");
				return cro;
			}

			int seq = 1;
			// 循环库存信息
			for (int i = 0; i < jslist.size(); i++) {
				Date now = new Date();
				SimpleDateFormat dateFormat = new SimpleDateFormat(
						"yyyyMMddHHmmss");
				DecimalFormat df = new DecimalFormat("0000000000");
				ArrayList<String> list = (ArrayList<String>) jslist.get(i);
				String judgeStoveNo = list.get(0);
				String batchNo = list.get(1);
				String batchGroupBy = list.get(2);
				String materialNo = list.get(3);
				int takeCount = Integer.parseInt(list.get(4));// 利库支
				// String proPlanIdNo = list.get(5);// 本工序订单号
				// String UpproPlanIdNo = list.get(6);// 上工序订单号
				String specCic = list.get(7);
				String actLen = list.get(8);
				String storageNo = list.get(9);
				String plineCode = list.get(10);
				List<MatBcMEntityPln> matGpMlist = FrmPlanMaterialDbk
						.getQureyMatGpM(conn, judgeStoveNo, batchNo,
								batchGroupBy, materialNo, takeCount, "", "G",actLen,lenFalg,storageNo,plineCode);
				if (matGpMlist == null) {
					cro.setV_errMsg("管坯物料已发生改变,请刷新!");
					return cro;
				}
				MatBcTrackEntity matTrack = FrmPlanMaterialDbk
						.getQureyMatTrack(conn, judgeStoveNo, batchNo,
								batchGroupBy, takeCount, "0", "",
								MatBcTrackEntity.class, "add",actLen,lenFalg);
				if (matTrack == null) {
					cro.setV_errMsg("管坯物料已发生改变,请刷新!");
					return cro;
				}
				double actWt = 0;
				String jugdeApplyCode = "";// 是否有申请判定单号
				int countAppCode = 0;
				String stoveNo = "";
				String upperHeatplanId = "";
				String upProessCode = "";
				String inwlId = "";
				String inwlDesc = "";
				String lengthIn = "";
				String lengthmaxIn = "";
				String lengthminIn = "";
				String outdiameterIn = "";
				String wallthickIn = "";
				int outnumCut = 1;
				String flagStoveNo = "";
				String gradeName = "";
				for (MatBcMEntityPln matGpM : matGpMlist) {
					countAppCode++;
					gradeName = matGpM.getGradename();
					jugdeApplyCode = matGpM.getJugdeApplyCode();
					flagStoveNo = matGpM.getFlagStoveNoZg();
					stoveNo = matGpM.getStoveNo();
					inwlId = matGpM.getMaterialNo();
					inwlDesc = matGpM.getMaterialName();
					upProessCode = matGpM.getProcessCdoe();
					upperHeatplanId = matGpM.getHeatPlanNo();
					lengthIn = matGpM.getActLen();
					lengthmaxIn = matGpM.getActLenMax();
					lengthminIn = matGpM.getActLenMin();
					outdiameterIn = matGpM.getActDimater();
					wallthickIn = matGpM.getActHeight();
					//actWt += Double.parseDouble(matGpM.getActWeight());
					actWt = Double.parseDouble(matGpM.getActWeight());
					takeCount = 1;
					if (!matGpM.getProductFlag().equals("801401")) {
						cro.setV_errMsg("材料类别不是在制品,不能利库!");
						return cro;
					}
					if (!matGpM.getMatStatus().equals("80150102")
							&& !matGpM.getInstancyFlag().equals("1")) {
						cro.setV_errMsg("材料状态不是产出已判定状态并且不是紧急放行状态,不能利库");
						return cro;
					}
					if (!matGpM.getQcmStaus().equals("00")) {
						cro.setV_errMsg("交库状态不是合格状态,不能利库!");
						return cro;
					}
					// if
					// (matGpM.getMatStatus().equals("80150102")&&!matGpM.getJudgeResultCode().equals("40740701"))
					// {
					// cro.setV_errMsg("判定结果不是合格状态,不能利库!");
					// return cro;
					// }
					// 修改坯子库存信息
					String sqlUpdateMat = CoreXmlSqlParsersFactory
							.getSql("FrmPlanMaterialDbk.UpdateMatGp");
					ps = conn.prepareStatement(sqlUpdateMat);
					ps.setObject(1, "80150103");
					ps.setObject(2, proPlanId);
					ps.setObject(3, gxPlanNo);
					ps.setObject(4, "1");
					ps.setObject(5, "1");
					ps.setObject(6, "G");
					ps.setObject(7, "加工线");
					ps.setObject(8, matGpM.getMatNo());
					ps.executeUpdate();
					ps.close();


					String resumeSeq = dateFormat.format(now) + df.format(seq);
					// 生成利库日志
					matTrack.setResumeSeq(resumeSeq);
					matTrack.setEventId("900102");
					matTrack.setEventDesc("利库");
					matTrack.setFormName("com.steering.pss.plnsaleord.planStove.FrmPlanMaterialJgx");
					matTrack.setCallFuncCoding("doAddLibrary");
					matTrack.setKeyvalue1("List<MatBcMEntityPln> matGpMlist");
					matTrack.setKeyvalue1Desc("物料主表关键字实体类集合");
					matTrack.setKeyvalue2("String userName");
					matTrack.setKeyvalue2Desc2("操作人");
					matTrack.setProcessCdoe("F");
					matTrack.setMemo("");
					matTrack.setCreateName(userName);
					matTrack.setCreateTime(dateTime);
					seq++;
					// 新增利库记录
					String sqlAddTrack = EntityTool.fillSqlByEntity(
							CoreXmlSqlParsersFactory
									.getSql("FrmPlanMaterialDbk.addMatBcTrack"),
							matTrack);
					ps = conn.prepareStatement(sqlAddTrack);
					ps.executeUpdate();
					ps.close();

					int countM = 0;
					String heatPlanNo = "";
					String planStatus = "00";
					// 根据上料炉号，订单号查询是否存在虚拟炉计划
					String sqlQuery = "SELECT COUNT(*) COUNT,T.HEAT_PLAN_NO,T.PLANSTATUS,T.IF_MATCH_ODD FROM PLN_ZY_JGX_M T WHERE T.FEED_HEAT_NO=? "
							+ " AND T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=? GROUP BY T.HEAT_PLAN_NO,T.PLANSTATUS,T.IF_MATCH_ODD";
					ps = conn.prepareStatement(sqlQuery);
					ps.setObject(1, judgeStoveNo);
					ps.setObject(2, proPlanId);
					ps.setObject(3, gxPlanNo);
					rs = ps.executeQuery();
					while (rs.next()) {
						heatPlanNo = rs.getString("HEAT_PLAN_NO");
						planStatus = rs.getString("PLANSTATUS");
						if (rs.getString("IF_MATCH_ODD").equals("1")) {
							countM = rs.getInt("COUNT");
							if (!planStatus.equals("00")
									&& !planStatus.equals("10")) {
								cro.setV_errMsg("该加工线订单(" + proPlanId + "/"
										+ gxPlanNo + "),判定炉号(" + judgeStoveNo
										+ ")已存在炉计划,并已上料,如需利库,请先撤销上料或拆分订单!");
								return cro;
							}
						} else {
							cro.setV_errMsg("该加工线订单(" + proPlanId + "/" + gxPlanNo
									+ "),判定炉号(" + judgeStoveNo
									+ ")已存在不是利库炉计划,如需利库,请先撤销炉计划!");
							return cro;
						}
					}
					rs.close();
					ps.close();

					// 如果存在同炉,同订单号只执行一次新增虚拟炉计划
					if (countM == 0) {
						PlnZyJgxMEntity plnJgxM = new PlnZyJgxMEntity();
						heatPlanNo = corePlanFurnProM
								.getMaxHeatPlanNo(conn, plnRclS.getProPlanId(),
										plnRclS.getProPlanId(), "G");
						// 获取炉计划顺序号
						int gxProSeq = corePlanFurnProM.getMaxGxPlnSeq(conn,
								plnRclS.getPlineCode(), "G");
						plnJgxM.setDecision(plnRclS.getDecision());
						plnJgxM.setStoveNo(stoveNo);
						plnJgxM.setFeedHeatNo(judgeStoveNo);
						if((plineCode.equals("C072") && !plnRclS.getPlineCode().equals("C092")&& !plnRclS.getPlineCode().equals("C102")&& !plnRclS.getPlineCode().equals("C107")&& !plnRclS.getPlineCode().equals("C108")&& !plnRclS.getPlineCode().equals("C109"))|| (plineCode.equals("C091") && !plnRclS.getPlineCode().equals("C092")&& !plnRclS.getPlineCode().equals("C102")&& !plnRclS.getPlineCode().equals("C107")&& !plnRclS.getPlineCode().equals("C108")&& !plnRclS.getPlineCode().equals("C109")))
						{
							plnJgxM.setJudgeStoveNo("");
							plnJgxM.setFlagStoveNo("");
						}else
						{
							plnJgxM.setJudgeStoveNo(judgeStoveNo);
							plnJgxM.setFlagStoveNo(judgeStoveNo);
						}

						plnJgxM.setUpperHeatplanId(upperHeatplanId);
						plnJgxM.setPlanstatus("00");
						plnJgxM.setUpperProcessCode(upProessCode);
						plnJgxM.setPlineCode(plnRclS.getPlineCode());
						plnJgxM.setPlineName(plnRclS.getPlineName());
						plnJgxM.setProcessCodeC(plnRclS.getProcessCodeC());
						plnJgxM.setProcessDescC(plnRclS.getProcessDescC());
						// 通过制程判定是否末工序
						// if (plnRclS.getWholeBacklogDesc().contains("接箍")) {
						// plnJgxM.setNextProcessCode("H");
						// plnJgxM.setIsendgx("0");
						// } else {
						if (plnRclS.getOrdLnDlyPk().contains("ZZBY-J")) {
							plnJgxM.setNextProcessCode("H");
						} else if (plnRclS.getOrdLnDlyPk().contains("ZZBY-D")) {
							plnJgxM.setNextProcessCode("G");
						} else {
							plnJgxM.setNextProcessCode("");
						}
						if (plnRclS.getOrderSource().equals("备料需求")) {
							plnJgxM.setIsendgx("0");
						} else {
							plnJgxM.setIsendgx("1");
						}

						// 通过BOM查询投入产出
						String[] bomMat=null;
						if(plnRclS.getWholeBacklog().equals("G")){
							bomMat= PlanFurnProduction.getQueryBomJgx(conn,
									plnRclS.getOrdLnDlyPk(),inwlId);
							if(bomMat[0] == null)
							{
								cro.setV_errMsg("库存物料码去BOM未找到对应的投入产出,需库存物料码和订单投入物料码一致!");
								return  cro;
							}else
							{

							}
							plnJgxM.setOutwlId(bomMat[2]);
							plnJgxM.setOutwlDesc(bomMat[3]);
							plnJgxM.setBom(bomMat[4]);
						}else{
							// 根据投入物料，制程号，交货行pK,工艺序号查询本工序产出物料
							String sqlBom = CoreXmlSqlParsersFactory
									.getSql("FrmPlanMaterialDbk.queryBaseMaterialGPl");
							sqlBom += " AND T.I_IN_MATERIAL_NO=?";
							ps = conn.prepareStatement(sqlBom);
							ps.setObject(1, plnRclS.getOrdLnDlyPk());
							ps.setObject(2, plnRclS.getIndexSeq());
							ps.setObject(3, plnRclS.getCraftSeq());
							ps.setObject(4, inwlId);
							rs = ps.executeQuery();
							if (rs.next()) {
								plnJgxM.setOutwlId(rs.getString("OUT_MATERIAL_NO"));
								plnJgxM.setOutwlDesc(rs.getString("OUT_MATERIAL_DESC"));
								plnJgxM.setBom(rs.getString("BOM"));
								plnJgxM.setWholeBacklog(rs.getString("WHOLE_BACKLOG"));
							} else {
								plnJgxM.setOutwlId(plnRclS.getOutwlId());
								plnJgxM.setOutwlDesc(plnRclS.getOutwlDesc());
								plnJgxM.setBom(plnRclS.getBom());
								// cro.setV_errMsg("未找到判定炉号(" + judgeStoveNo
								// + ")在加工的产出物料!");
								// return cro;
							}
							rs.close();
							ps.close();
						}

						plnJgxM.setIfMatchOdd("1");
						plnJgxM.setIfDoHeatPlan("1");
						plnJgxM.setProPlanId(plnRclS.getProPlanId());
						plnJgxM.setGxPlanNo(plnRclS.getGxPlanNo());
						plnJgxM.setSpecCode(plnRclS.getSpecCode());
						plnJgxM.setSpecName(plnRclS.getSpecName());
						plnJgxM.setGradecode(matTrack.getGradecode());
						plnJgxM.setGradename(matTrack.getGradename());
						plnJgxM.setSteelcode(plnRclS.getSteelcode());
						plnJgxM.setSteelname(plnRclS.getSteelname());
						plnJgxM.setProduccode(plnRclS.getProduccode());
						plnJgxM.setProducname(plnRclS.getProducname());
						plnJgxM.setInwlId(inwlId);
						plnJgxM.setInwlDesc(inwlDesc);
						plnJgxM.setModelCode(plnRclS.getModelCode());
						plnJgxM.setModelDesc(plnRclS.getModelDesc());
						// 单倍支吨
						plnJgxM.setPlnInsingleNum(String.valueOf(takeCount));
						plnJgxM.setPlnInsingleWt(String.valueOf(actWt));


						// 查询轧管排产信息
						String sqlZg = "";

						sqlZg = CoreXmlSqlParsersFactory
								.getSql("PlanFurnProduction.QueryWgZg");
						ps = conn.prepareStatement(sqlZg);
						ps.setObject(1, plnRclS.getOrdLnDlyPk());
						rs = ps.executeQuery();
						if (rs.next()) {
							plnJgxM.setProdStandard(rs.getString("PROD_STANDARD"));
							plnJgxM.setOutputStandard(rs
									.getString("OUTPUT_STANDARD"));
							plnJgxM.setSecCraftFileNo(rs
									.getString("SEC_CRAFT_FILE_NO"));
							plnJgxM.setZyBatchIdZg(rs.getString("ZY_BATCH_ID"));
						}
						rs.close();
						ps.close();
						// }
						plnJgxM.setStdCode(plnRclS.getStdCode());
						plnJgxM.setStdName(plnRclS.getStdName());
						plnJgxM.setStdStyle(plnRclS.getStdStyle());
						plnJgxM.setStdStyleDesc(plnRclS.getStdStyleDesc());
						plnJgxM.setOutdiameterIn(outdiameterIn);
						plnJgxM.setWallthickIn(wallthickIn);
						plnJgxM.setLengthIn(lengthIn);
						plnJgxM.setLengthmaxIn(lengthmaxIn);
						plnJgxM.setLengthminIn(lengthminIn);
						plnJgxM.setOrderSource(plnRclS.getOrderSource());
						plnJgxM.setOrderNo(plnRclS.getOrderNo());
						plnJgxM.setOrderSeq(plnRclS.getOrderSeq());
						plnJgxM.setDeliveryNo(plnRclS.getDeliveryNo());
						plnJgxM.setOrdLnDlyPk(plnRclS.getOrdLnDlyPk());
						plnJgxM.setReqBlId(plnRclS.getReqBlId());
						plnJgxM.setIfExport(plnRclS.getIfExport());
						plnJgxM.setPriority(plnRclS.getPriority());
						plnJgxM.setPriorityMemo(plnRclS.getPriorityMemo());
						plnJgxM.setProMonth(plnRclS.getProMonth());
						plnJgxM.setIfMonitor(plnRclS.getIfMonitorJgx());
						plnJgxM.setPrdcrNo(plnRclS.getPrdcrNo());
						plnJgxM.setMonitorPoint(plnRclS.getMonitorPoint());
						plnJgxM.setWholeBacklogDesc(plnRclS.getWholeBacklogDesc());
						plnJgxM.setStationRoad(plnRclS.getStationRoad());

						plnJgxM.setCic(specCic);
						if (plnRclS.getSic() == null || plnRclS.getSic().equals("")) {
							plnJgxM.setSic(plnRclS.getSic());
						} else {
							plnJgxM.setSic(plnRclS.getSic().split(",")[0]);
						}
						if (plnRclS.getDic() == null || plnRclS.getDic().equals("")) {
							plnJgxM.setDic(plnRclS.getDic());
						} else {
							plnJgxM.setDic(plnRclS.getDic().split(",")[0]);
						}
						if (plnRclS.getPic() == null || plnRclS.getPic().equals("")) {
							plnJgxM.setPic(plnRclS.getPic());
						} else {
							plnJgxM.setPic(plnRclS.getPic().split(",")[0]);
						}
						if (plnRclS.getWic() == null || plnRclS.getWic().equals("")) {
							plnJgxM.setWic(plnRclS.getWic());
						} else {
							plnJgxM.setWic(plnRclS.getWic().split(",")[0]);
						}
						plnJgxM.setCraftFileMan(plnRclS.getCraftFileMan());
						plnJgxM.setCraftFileNo(plnRclS.getCraftFileNo());
						plnJgxM.setCraftSeq(plnRclS.getCraftSeq());
						plnJgxM.setOutdiameter(plnRclS.getOutdiameter());
						plnJgxM.setWallthick(plnRclS.getWallthick());
						// 查询合同最大最小长度
						double lenMax = 0;
						double lenMin = 0;
						String ordLen = "SELECT T.LENGTHMAX,T.LENGTHMIN FROM PLN_SALEORD T WHERE T.ORD_LN_DLY_PK=?";
						ps = conn.prepareStatement(ordLen);
						ps.setObject(1, plnRclS.getOrdLnDlyPk());
						rs = ps.executeQuery();
						if (rs.next()) {
							lenMax = rs.getDouble("LENGTHMAX");
							lenMin = rs.getDouble("LENGTHMIN");
						}
						rs.close();
						ps.close();

						if (!lengthmaxIn.equals("") && lenMin>0.0) {
							outnumCut = (int) (Double.parseDouble(lengthmaxIn) / lenMin);
						}
						if (outnumCut <= 0) {
							outnumCut = 1;
						}
						plnJgxM.setLengthmax(String.valueOf(lenMax));
						plnJgxM.setLengthmin(String.valueOf(lenMin));
						plnJgxM.setOutnumCut(String.valueOf(outnumCut));
						// 预计成品产出支吨
						plnJgxM.setPlnOutsingleNum(String.valueOf(takeCount
								* outnumCut));
						double burnoutRate = 0;
						// 查询产线烧损
						String sql = "SELECT NVL(T.BURNOUT_RATE,0)/100 BURNOUT_RATE FROM COM_BASE_PLINE T WHERE T.PLINE_CODE='"
								+ plnRclS.getPlineCode() + "'";
						ps = conn.prepareStatement(sql);
						rs = ps.executeQuery();
						if (rs.next()) {
							burnoutRate = rs.getDouble("BURNOUT_RATE");
						}
						rs.close();
						ps.close();
						double yjWt = actWt - actWt * burnoutRate;
						plnJgxM.setPlnOutsingleW(String.valueOf(yjWt));
						plnJgxM.setCreateName(userName);
						plnJgxM.setCreateTime(dateTime);
						plnJgxM.setProDay(dateTime.substring(0, 10)
								.replace("-", ""));
						plnJgxM.setBalYearMonth(dateTime.substring(0, 7).replace(
								"-", ""));
						plnJgxM.setIndexSeq(plnRclS.getIndexSeq());
						plnJgxM.setHeatPlanNo(heatPlanNo);
						plnJgxM.setGxProSeq(String.valueOf(gxProSeq));
						// 订单内炉顺序号
						int lotNo = corePlanFurnProM.getMaxLotNoSqe(conn,
								plnJgxM.getProPlanId(), plnJgxM.getGxPlanNo(), "G");
						plnJgxM.setLotNoSqe(String.valueOf(lotNo));
						// 新增加工线虚拟炉计划
						String addPlnGxZg = EntityTool.fillSqlByEntity(
								CoreXmlSqlParsersFactory
										.getSql("PlanFurnProduction.addPlnZyJgx"),
								plnJgxM);
						ps = conn.prepareStatement(addPlnGxZg);
						ps.executeUpdate();
						ps.close();
						// 新增生产批号
						StoveHelper.updatePlnJgxGroup(conn, plnJgxM.getProPlanId(),
								plnJgxM.getGxPlanNo(), plnJgxM.getPic());
					}
					int countC = 0;
					String heatPlanSqe = "";
					// 判定是否存在判定炉号，判定单号，同炉计划ID数据
					String sqlC = "SELECT COUNT(*) COUNT1,T.HEAT_PLAN_SQE FROM PLN_ZY_JGX_C T WHERE "
							+ "T.HEAT_PLAN_NO=? AND NVL(T.JUGDE_APPLY_CODE,'/') =NVL(?,'/') AND T.FEED_HEAT_NO=? AND T.BATCH_NO=? AND T.BATCH_GROUD_NO=?"
							+ " GROUP BY T.HEAT_PLAN_SQE";
					ps = conn.prepareStatement(sqlC);
					ps.setObject(1, heatPlanNo);
					ps.setObject(2, jugdeApplyCode);
					ps.setObject(3, judgeStoveNo);
					ps.setObject(4, batchNo);
					ps.setObject(5, batchGroupBy);
					rs = ps.executeQuery();
					if (rs.next()) {
						countC = rs.getInt("COUNT1");
						heatPlanSqe = rs.getString("HEAT_PLAN_SQE");
					}
					rs.close();
					ps.close();

					if (countC == 0) {
						PlnZyJgxCEntity plnC = new PlnZyJgxCEntity();
						// 获取炉计划顺序号
						heatPlanSqe = corePlanFurnProM.getHeatPlanSeq(conn,
								heatPlanNo, "G");
						plnC.setHeatPlanNo(heatPlanNo);
						plnC.setJugdeApplyCode(jugdeApplyCode);
						plnC.setFeedHeatNo(judgeStoveNo);
						if((plineCode.equals("C072") && !plnRclS.getPlineCode().equals("C092")&& !plnRclS.getPlineCode().equals("C102")&& !plnRclS.getPlineCode().equals("C107")&& !plnRclS.getPlineCode().equals("C108")&& !plnRclS.getPlineCode().equals("C109"))|| (plineCode.equals("C091") && !plnRclS.getPlineCode().equals("C092")&& !plnRclS.getPlineCode().equals("C102")&& !plnRclS.getPlineCode().equals("C107")&& !plnRclS.getPlineCode().equals("C108")&& !plnRclS.getPlineCode().equals("C109")))
						{
							plnC.setJudgeStoveNo("");
							plnC.setFlagStoveNo("");
						}else
						{
							plnC.setJudgeStoveNo(judgeStoveNo);
							plnC.setFlagStoveNo(judgeStoveNo);
						}

						plnC.setBatchNo(batchNo);
						plnC.setBatchGroudNo(batchGroupBy);
						plnC.setStoveNo(stoveNo);
						plnC.setProPlanId(plnRclS.getProPlanId());
						plnC.setGxPlanNo(plnRclS.getGxPlanNo());
						plnC.setPlineCode(plnRclS.getPlineCode());
						plnC.setPlineName(plnRclS.getPlineName());
						plnC.setOutdiameterIn(outdiameterIn);
						plnC.setWallthickIn(wallthickIn);
						plnC.setOutnumCut(String.valueOf(outnumCut));
						plnC.setLengthIn(lengthIn);
						plnC.setLengthmaxIn(lengthmaxIn);
						plnC.setLengthminIn(lengthminIn);
						plnC.setPlanIndoubleNum(String.valueOf(takeCount));
						plnC.setPlanIndoubleWt(String.valueOf(actWt));

						plnC.setHeatPlanSqe(heatPlanSqe);
						// 新增
						String addPlnGxZg = EntityTool.fillSqlByEntity(
								CoreXmlSqlParsersFactory
										.getSql("PlanFurnProduction.addPlnZyJgxC"),
								plnC);
						ps = conn.prepareStatement(addPlnGxZg);
						ps.executeUpdate();
						ps.close();

					} else {
						// 修改炉计划实表
						String updateC = "UPDATE PLN_ZY_JGX_C T SET T.PLAN_INDOUBLE_NUM=T.PLAN_INDOUBLE_NUM+TO_NUMBER(?),"
								+ "T.PLAN_INDOUBLE_WT=T.PLAN_INDOUBLE_WT+TO_NUMBER(?) ";
						updateC += " WHERE T.HEAT_PLAN_NO=? AND T.HEAT_PLAN_SQE=?";
						ps = conn.prepareStatement(updateC);
						ps.setObject(1, takeCount);
						ps.setObject(2, actWt);
						ps.setObject(3, heatPlanNo);
						ps.setObject(4, heatPlanSqe);
						ps.executeUpdate();
						ps.close();
					}

					if (countM > 0) {
						// 修改炉计划主表量
						String sqlUpdate = CoreXmlSqlParsersFactory
								.getSql("FrmPlanMaterialJgx.updatePlnZgM");
						ps = conn.prepareStatement(sqlUpdate);
						ps.setObject(1, heatPlanNo);
						ps.setObject(2, heatPlanNo);
						ps.executeUpdate();
						ps.close();
					}
					// 修改坯子库存下工序炉计划ID
					String sqlUpdateMat1 = "UPDATE MAT_BC_M T SET T.HEAT_PLAN_NO_NEXT=? WHERE T.PRO_PLAN_ID_NEXT=? AND T.GX_PLAN_NO_NEXT=? AND T.MAT_NO=?";
					ps = conn.prepareStatement(sqlUpdateMat1);
					ps.setObject(1, heatPlanNo);
					ps.setObject(2, proPlanId);
					ps.setObject(3, gxPlanNo);
					ps.setObject(4, matGpM.getMatNo());
					ps.executeUpdate();
					ps.close();


				}
//				String resumeSeq = dateFormat.format(now) + df.format(seq);
//				// 生成利库日志
//				matTrack.setResumeSeq(resumeSeq);
//				matTrack.setEventId("900102");
//				matTrack.setEventDesc("利库");
//				matTrack.setFormName("com.steering.pss.plnsaleord.planStove.FrmPlanMaterialJgx");
//				matTrack.setCallFuncCoding("doAddLibrary");
//				matTrack.setKeyvalue1("List<MatBcMEntityPln> matGpMlist");
//				matTrack.setKeyvalue1Desc("物料主表关键字实体类集合");
//				matTrack.setKeyvalue2("String userName");
//				matTrack.setKeyvalue2Desc2("操作人");
//				matTrack.setProcessCdoe("F");
//				matTrack.setMemo("");
//				matTrack.setCreateName(userName);
//				matTrack.setCreateTime(dateTime);
//				seq++;
//				// 新增利库记录
//				String sqlAddTrack = EntityTool.fillSqlByEntity(
//						CoreXmlSqlParsersFactory
//								.getSql("FrmPlanMaterialDbk.addMatBcTrack"),
//						matTrack);
//				ps = conn.prepareStatement(sqlAddTrack);
//				ps.executeUpdate();
//				ps.close();
//
//				int countM = 0;
//				String heatPlanNo = "";
//				String planStatus = "00";
//				// 根据上料炉号，订单号查询是否存在虚拟炉计划
//				String sqlQuery = "SELECT COUNT(*) COUNT,T.HEAT_PLAN_NO,T.PLANSTATUS,T.IF_MATCH_ODD FROM PLN_ZY_JGX_M T WHERE T.FEED_HEAT_NO=? "
//						+ " AND T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=? GROUP BY T.HEAT_PLAN_NO,T.PLANSTATUS,T.IF_MATCH_ODD";
//				ps = conn.prepareStatement(sqlQuery);
//				ps.setObject(1, judgeStoveNo);
//				ps.setObject(2, proPlanId);
//				ps.setObject(3, gxPlanNo);
//				rs = ps.executeQuery();
//				while (rs.next()) {
//					heatPlanNo = rs.getString("HEAT_PLAN_NO");
//					planStatus = rs.getString("PLANSTATUS");
//					if (rs.getString("IF_MATCH_ODD").equals("1")) {
//						countM = rs.getInt("COUNT");
//						if (!planStatus.equals("00")
//								&& !planStatus.equals("10")) {
//							cro.setV_errMsg("该加工线订单(" + proPlanId + "/"
//									+ gxPlanNo + "),判定炉号(" + judgeStoveNo
//									+ ")已存在炉计划,并已上料,如需利库,请先撤销上料或拆分订单!");
//							return cro;
//						}
//					} else {
//						cro.setV_errMsg("该加工线订单(" + proPlanId + "/" + gxPlanNo
//								+ "),判定炉号(" + judgeStoveNo
//								+ ")已存在不是利库炉计划,如需利库,请先撤销炉计划!");
//						return cro;
//					}
//				}
//				rs.close();
//				ps.close();
//
//				// 如果存在同炉,同订单号只执行一次新增虚拟炉计划
//				if (countM == 0) {
//					PlnZyJgxMEntity plnJgxM = new PlnZyJgxMEntity();
//					heatPlanNo = corePlanFurnProM
//							.getMaxHeatPlanNo(conn, plnRclS.getProPlanId(),
//									plnRclS.getProPlanId(), "G");
//					// 获取炉计划顺序号
//					int gxProSeq = corePlanFurnProM.getMaxGxPlnSeq(conn,
//							plnRclS.getPlineCode(), "G");
//					plnJgxM.setDecision(plnRclS.getDecision());
//					plnJgxM.setStoveNo(stoveNo);
//					plnJgxM.setFeedHeatNo(judgeStoveNo);
//					if((plineCode.equals("C072") && !plnRclS.getPlineCode().equals("C092"))|| (plineCode.equals("C091") && !plnRclS.getPlineCode().equals("C092")))
//					{
//						plnJgxM.setJudgeStoveNo("");
//						plnJgxM.setFlagStoveNo("");
//					}else
//					{
//						plnJgxM.setJudgeStoveNo(judgeStoveNo);
//						plnJgxM.setFlagStoveNo(judgeStoveNo);
//					}
//
//					plnJgxM.setUpperHeatplanId(upperHeatplanId);
//					plnJgxM.setPlanstatus("00");
//					plnJgxM.setUpperProcessCode(upProessCode);
//					plnJgxM.setPlineCode(plnRclS.getPlineCode());
//					plnJgxM.setPlineName(plnRclS.getPlineName());
//					plnJgxM.setProcessCodeC(plnRclS.getProcessCodeC());
//					plnJgxM.setProcessDescC(plnRclS.getProcessDescC());
//					// 通过制程判定是否末工序
//					// if (plnRclS.getWholeBacklogDesc().contains("接箍")) {
//					// plnJgxM.setNextProcessCode("H");
//					// plnJgxM.setIsendgx("0");
//					// } else {
//					if (plnRclS.getOrdLnDlyPk().contains("ZZBY-J")) {
//						plnJgxM.setNextProcessCode("H");
//					} else if (plnRclS.getOrdLnDlyPk().contains("ZZBY-D")) {
//						plnJgxM.setNextProcessCode("G");
//					} else {
//						plnJgxM.setNextProcessCode("");
//					}
//					if (plnRclS.getOrderSource().equals("备料需求")) {
//						plnJgxM.setIsendgx("0");
//					} else {
//						plnJgxM.setIsendgx("1");
//					}
//
//					// 通过BOM查询投入产出
//					String[] bomMat=null;
//					if(plnRclS.getWholeBacklog().equals("G")){
//						bomMat= PlanFurnProduction.getQueryBomJgx(conn,
//								 plnRclS.getOrdLnDlyPk(),inwlId);
//						if(bomMat[0] == null)
//						{
//							cro.setV_errMsg("库存物料码去BOM未找到对应的投入产出,需库存物料码和订单投入物料码一致!");
//							return  cro;
//						}else
//						{
//
//						}
//						plnJgxM.setOutwlId(bomMat[2]);
//						plnJgxM.setOutwlDesc(bomMat[3]);
//						plnJgxM.setBom(bomMat[4]);
//					}else{
//					// 根据投入物料，制程号，交货行pK,工艺序号查询本工序产出物料
//					String sqlBom = CoreXmlSqlParsersFactory
//							.getSql("FrmPlanMaterialDbk.queryBaseMaterialGPl");
//					sqlBom += " AND T.I_IN_MATERIAL_NO=?";
//					ps = conn.prepareStatement(sqlBom);
//					ps.setObject(1, plnRclS.getOrdLnDlyPk());
//					ps.setObject(2, plnRclS.getIndexSeq());
//					ps.setObject(3, plnRclS.getCraftSeq());
//					ps.setObject(4, inwlId);
//					rs = ps.executeQuery();
//					if (rs.next()) {
//						plnJgxM.setOutwlId(rs.getString("OUT_MATERIAL_NO"));
//						plnJgxM.setOutwlDesc(rs.getString("OUT_MATERIAL_DESC"));
//						plnJgxM.setBom(rs.getString("BOM"));
//						plnJgxM.setWholeBacklog(rs.getString("WHOLE_BACKLOG"));
//					} else {
//						plnJgxM.setOutwlId(plnRclS.getOutwlId());
//						plnJgxM.setOutwlDesc(plnRclS.getOutwlDesc());
//						plnJgxM.setBom(plnRclS.getBom());
//						// cro.setV_errMsg("未找到判定炉号(" + judgeStoveNo
//						// + ")在加工的产出物料!");
//						// return cro;
//					}
//					rs.close();
//					ps.close();
//					}
//
//					plnJgxM.setIfMatchOdd("1");
//					plnJgxM.setIfDoHeatPlan("1");
//					plnJgxM.setProPlanId(plnRclS.getProPlanId());
//					plnJgxM.setGxPlanNo(plnRclS.getGxPlanNo());
//					plnJgxM.setSpecCode(plnRclS.getSpecCode());
//					plnJgxM.setSpecName(plnRclS.getSpecName());
//					plnJgxM.setGradecode(matTrack.getGradecode());
//					plnJgxM.setGradename(matTrack.getGradename());
//					plnJgxM.setSteelcode(plnRclS.getSteelcode());
//					plnJgxM.setSteelname(plnRclS.getSteelname());
//					plnJgxM.setProduccode(plnRclS.getProduccode());
//					plnJgxM.setProducname(plnRclS.getProducname());
//					plnJgxM.setInwlId(inwlId);
//					plnJgxM.setInwlDesc(inwlDesc);
//					plnJgxM.setModelCode(plnRclS.getModelCode());
//					plnJgxM.setModelDesc(plnRclS.getModelDesc());
//					// 单倍支吨
//					plnJgxM.setPlnInsingleNum(String.valueOf(takeCount));
//					plnJgxM.setPlnInsingleWt(String.valueOf(actWt));
//
//
//					// 查询轧管排产信息
//					String sqlZg = "";
//
//					sqlZg = CoreXmlSqlParsersFactory
//							.getSql("PlanFurnProduction.QueryWgZg");
//					ps = conn.prepareStatement(sqlZg);
//					ps.setObject(1, plnRclS.getOrdLnDlyPk());
//					rs = ps.executeQuery();
//					if (rs.next()) {
//						plnJgxM.setProdStandard(rs.getString("PROD_STANDARD"));
//						plnJgxM.setOutputStandard(rs
//								.getString("OUTPUT_STANDARD"));
//						plnJgxM.setSecCraftFileNo(rs
//								.getString("SEC_CRAFT_FILE_NO"));
//						plnJgxM.setZyBatchIdZg(rs.getString("ZY_BATCH_ID"));
//					}
//					rs.close();
//					ps.close();
//					// }
//					plnJgxM.setStdCode(plnRclS.getStdCode());
//					plnJgxM.setStdName(plnRclS.getStdName());
//					plnJgxM.setStdStyle(plnRclS.getStdStyle());
//					plnJgxM.setStdStyleDesc(plnRclS.getStdStyleDesc());
//					plnJgxM.setOutdiameterIn(outdiameterIn);
//					plnJgxM.setWallthickIn(wallthickIn);
//					plnJgxM.setLengthIn(lengthIn);
//					plnJgxM.setLengthmaxIn(lengthmaxIn);
//					plnJgxM.setLengthminIn(lengthminIn);
//					plnJgxM.setOrderSource(plnRclS.getOrderSource());
//					plnJgxM.setOrderNo(plnRclS.getOrderNo());
//					plnJgxM.setOrderSeq(plnRclS.getOrderSeq());
//					plnJgxM.setDeliveryNo(plnRclS.getDeliveryNo());
//					plnJgxM.setOrdLnDlyPk(plnRclS.getOrdLnDlyPk());
//					plnJgxM.setReqBlId(plnRclS.getReqBlId());
//					plnJgxM.setIfExport(plnRclS.getIfExport());
//					plnJgxM.setPriority(plnRclS.getPriority());
//					plnJgxM.setPriorityMemo(plnRclS.getPriorityMemo());
//					plnJgxM.setProMonth(plnRclS.getProMonth());
//					plnJgxM.setIfMonitor(plnRclS.getIfMonitorJgx());
//					plnJgxM.setPrdcrNo(plnRclS.getPrdcrNo());
//					plnJgxM.setMonitorPoint(plnRclS.getMonitorPoint());
//					plnJgxM.setWholeBacklogDesc(plnRclS.getWholeBacklogDesc());
//					plnJgxM.setStationRoad(plnRclS.getStationRoad());
//
//					plnJgxM.setCic(specCic);
//					if (plnRclS.getSic() == null || plnRclS.getSic().equals("")) {
//						plnJgxM.setSic(plnRclS.getSic());
//					} else {
//						plnJgxM.setSic(plnRclS.getSic().split(",")[0]);
//					}
//					if (plnRclS.getDic() == null || plnRclS.getDic().equals("")) {
//						plnJgxM.setDic(plnRclS.getDic());
//					} else {
//						plnJgxM.setDic(plnRclS.getDic().split(",")[0]);
//					}
//					if (plnRclS.getPic() == null || plnRclS.getPic().equals("")) {
//						plnJgxM.setPic(plnRclS.getPic());
//					} else {
//						plnJgxM.setPic(plnRclS.getPic().split(",")[0]);
//					}
//					if (plnRclS.getWic() == null || plnRclS.getWic().equals("")) {
//						plnJgxM.setWic(plnRclS.getWic());
//					} else {
//						plnJgxM.setWic(plnRclS.getWic().split(",")[0]);
//					}
//					plnJgxM.setCraftFileMan(plnRclS.getCraftFileMan());
//					plnJgxM.setCraftFileNo(plnRclS.getCraftFileNo());
//					plnJgxM.setCraftSeq(plnRclS.getCraftSeq());
//					plnJgxM.setOutdiameter(plnRclS.getOutdiameter());
//					plnJgxM.setWallthick(plnRclS.getWallthick());
//					// 查询合同最大最小长度
//					double lenMax = 0;
//					double lenMin = 0;
//					String ordLen = "SELECT T.LENGTHMAX,T.LENGTHMIN FROM PLN_SALEORD T WHERE T.ORD_LN_DLY_PK=?";
//					ps = conn.prepareStatement(ordLen);
//					ps.setObject(1, plnRclS.getOrdLnDlyPk());
//					rs = ps.executeQuery();
//					if (rs.next()) {
//						lenMax = rs.getDouble("LENGTHMAX");
//						lenMin = rs.getDouble("LENGTHMIN");
//					}
//					rs.close();
//					ps.close();
//
//					if (!lengthmaxIn.equals("")) {
//						outnumCut = (int) (Double.parseDouble(lengthmaxIn) / lenMin);
//					}
//					if (outnumCut <= 0) {
//						outnumCut = 1;
//					}
//					plnJgxM.setLengthmax(String.valueOf(lenMax));
//					plnJgxM.setLengthmin(String.valueOf(lenMin));
//					plnJgxM.setOutnumCut(String.valueOf(outnumCut));
//					// 预计成品产出支吨
//					plnJgxM.setPlnOutsingleNum(String.valueOf(takeCount
//							* outnumCut));
//					double burnoutRate = 0;
//					// 查询产线烧损
//					String sql = "SELECT NVL(T.BURNOUT_RATE,0)/100 BURNOUT_RATE FROM COM_BASE_PLINE T WHERE T.PLINE_CODE='"
//							+ plnRclS.getPlineCode() + "'";
//					ps = conn.prepareStatement(sql);
//					rs = ps.executeQuery();
//					if (rs.next()) {
//						burnoutRate = rs.getDouble("BURNOUT_RATE");
//					}
//					rs.close();
//					ps.close();
//					double yjWt = actWt - actWt * burnoutRate;
//					plnJgxM.setPlnOutsingleW(String.valueOf(yjWt));
//					plnJgxM.setCreateName(userName);
//					plnJgxM.setCreateTime(dateTime);
//					plnJgxM.setProDay(dateTime.substring(0, 10)
//							.replace("-", ""));
//					plnJgxM.setBalYearMonth(dateTime.substring(0, 7).replace(
//							"-", ""));
//					plnJgxM.setIndexSeq(plnRclS.getIndexSeq());
//					plnJgxM.setHeatPlanNo(heatPlanNo);
//					plnJgxM.setGxProSeq(String.valueOf(gxProSeq));
//					// 订单内炉顺序号
//					int lotNo = corePlanFurnProM.getMaxLotNoSqe(conn,
//							plnJgxM.getProPlanId(), plnJgxM.getGxPlanNo(), "G");
//					plnJgxM.setLotNoSqe(String.valueOf(lotNo));
//					// 新增加工线虚拟炉计划
//					String addPlnGxZg = EntityTool.fillSqlByEntity(
//							CoreXmlSqlParsersFactory
//									.getSql("PlanFurnProduction.addPlnZyJgx"),
//							plnJgxM);
//					ps = conn.prepareStatement(addPlnGxZg);
//					ps.executeUpdate();
//					ps.close();
//					// 新增生产批号
//					StoveHelper.updatePlnJgxGroup(conn, plnJgxM.getProPlanId(),
//							plnJgxM.getGxPlanNo(), plnJgxM.getPic());
//				}
//				int countC = 0;
//				String heatPlanSqe = "";
//				// 判定是否存在判定炉号，判定单号，同炉计划ID数据
//				String sqlC = "SELECT COUNT(*) COUNT1,T.HEAT_PLAN_SQE FROM PLN_ZY_JGX_C T WHERE "
//						+ "T.HEAT_PLAN_NO=? AND NVL(T.JUGDE_APPLY_CODE,'/') =NVL(?,'/') AND T.FEED_HEAT_NO=? AND T.BATCH_NO=? AND T.BATCH_GROUD_NO=?"
//						+ " GROUP BY T.HEAT_PLAN_SQE";
//				ps = conn.prepareStatement(sqlC);
//				ps.setObject(1, heatPlanNo);
//				ps.setObject(2, jugdeApplyCode);
//				ps.setObject(3, judgeStoveNo);
//				ps.setObject(4, batchNo);
//				ps.setObject(5, batchGroupBy);
//				rs = ps.executeQuery();
//				if (rs.next()) {
//					countC = rs.getInt("COUNT1");
//					heatPlanSqe = rs.getString("HEAT_PLAN_SQE");
//				}
//				rs.close();
//				ps.close();
//
//				if (countC == 0) {
//					PlnZyJgxCEntity plnC = new PlnZyJgxCEntity();
//					// 获取炉计划顺序号
//					heatPlanSqe = corePlanFurnProM.getHeatPlanSeq(conn,
//							heatPlanNo, "G");
//					plnC.setHeatPlanNo(heatPlanNo);
//					plnC.setJugdeApplyCode(jugdeApplyCode);
//					plnC.setFeedHeatNo(judgeStoveNo);
//					if((plineCode.equals("C072") && !plnRclS.getPlineCode().equals("C092"))|| (plineCode.equals("C091") && !plnRclS.getPlineCode().equals("C092")))
//					{
//						plnC.setJudgeStoveNo("");
//						plnC.setFlagStoveNo("");
//					}else
//					{
//						plnC.setJudgeStoveNo(judgeStoveNo);
//						plnC.setFlagStoveNo(judgeStoveNo);
//					}
//
//					plnC.setBatchNo(batchNo);
//					plnC.setBatchGroudNo(batchGroupBy);
//					plnC.setStoveNo(stoveNo);
//					plnC.setProPlanId(plnRclS.getProPlanId());
//					plnC.setGxPlanNo(plnRclS.getGxPlanNo());
//					plnC.setPlineCode(plnRclS.getPlineCode());
//					plnC.setPlineName(plnRclS.getPlineName());
//					plnC.setOutdiameterIn(outdiameterIn);
//					plnC.setWallthickIn(wallthickIn);
//					plnC.setOutnumCut(String.valueOf(outnumCut));
//					plnC.setLengthIn(lengthIn);
//					plnC.setLengthmaxIn(lengthmaxIn);
//					plnC.setLengthminIn(lengthminIn);
//					plnC.setPlanIndoubleNum(String.valueOf(takeCount));
//					plnC.setPlanIndoubleWt(String.valueOf(actWt));
//
//					plnC.setHeatPlanSqe(heatPlanSqe);
//					// 新增
//					String addPlnGxZg = EntityTool.fillSqlByEntity(
//							CoreXmlSqlParsersFactory
//									.getSql("PlanFurnProduction.addPlnZyJgxC"),
//							plnC);
//					ps = conn.prepareStatement(addPlnGxZg);
//					ps.executeUpdate();
//					ps.close();
//
//				} else {
//					// 修改炉计划实表
//					String updateC = "UPDATE PLN_ZY_JGX_C T SET T.PLAN_INDOUBLE_NUM=T.PLAN_INDOUBLE_NUM+TO_NUMBER(?),"
//							+ "T.PLAN_INDOUBLE_WT=T.PLAN_INDOUBLE_WT+TO_NUMBER(?) ";
//					updateC += " WHERE T.HEAT_PLAN_NO=? AND T.HEAT_PLAN_SQE=?";
//					ps = conn.prepareStatement(updateC);
//					ps.setObject(1, takeCount);
//					ps.setObject(2, actWt);
//					ps.setObject(3, heatPlanNo);
//					ps.setObject(4, heatPlanSqe);
//					ps.executeUpdate();
//					ps.close();
//				}
//
//				if (countM > 0) {
//					// 修改炉计划主表量
//					String sqlUpdate = CoreXmlSqlParsersFactory
//							.getSql("FrmPlanMaterialJgx.updatePlnZgM");
//					ps = conn.prepareStatement(sqlUpdate);
//					ps.setObject(1, heatPlanNo);
//					ps.setObject(2, heatPlanNo);
//					ps.executeUpdate();
//					ps.close();
//				}
//				// 修改坯子库存下工序炉计划ID
//				String sqlUpdateMat = "UPDATE MAT_BC_M T SET T.HEAT_PLAN_NO_NEXT=? WHERE T.PRO_PLAN_ID_NEXT=? AND T.GX_PLAN_NO_NEXT=? AND T.JUDGE_STOVE_NO=?";
//				ps = conn.prepareStatement(sqlUpdateMat);
//				ps.setObject(1, heatPlanNo);
//				ps.setObject(2, proPlanId);
//				ps.setObject(3, gxPlanNo);
//				ps.setObject(4, judgeStoveNo);
//				ps.executeUpdate();
//				ps.close();
			}
			cro.setV_errMsg("利库成功!");
			conn.commit();
		} catch (SQLException sqle) {
			try {
				conn.rollback();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			cro.setV_errCode(-1);
			cro.setV_errMsg(sqle.getMessage());
		} finally {
			try {
				if (conn != null && !conn.isClosed()) {
					conn.close();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return cro;
	}

	/**
	 * 坯子脱单（删除订单号）
	 * 
	 * @param jslist
	 * @param userName
	 *            脱单人
	 * @return
	 * @throws ParseException
	 */
	public CoreReturnObject doDeleteMonomer(
			ArrayList<ArrayList<String>> jslist, String userName)
			throws ParseException {
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = null;
		try {
			conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			conn.setAutoCommit(false);
			PreparedStatement ps = null;
			// ResultSet rs = null;
			SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
			DecimalFormat df = new DecimalFormat("0000000000");
			// 获取数据库当前时间
			String dateTime = FrmSteelMakingPlanChange.getSystemTime(conn);
			// 循环库存信息
			int seq = 1;
			for (int i = 0; i < jslist.size(); i++) {

				Date now = new Date();
				ArrayList<String> list = (ArrayList<String>) jslist.get(i);
				String judgeStoveNo = list.get(0);
				String batchNo = list.get(1);
				String batchGroupBy = list.get(2);
				String materialNo = list.get(3);
				int takeCount = Integer.parseInt(list.get(4));// 利库支
				String proPlanIdNo = list.get(5);

				String plineCode = list.get(6);
				List<MatBcMEntityPln> matGpMlist = FrmPlanMaterialDbk
						.getQureyMatGpM(conn, judgeStoveNo, batchNo,
								batchGroupBy, materialNo, takeCount,
								proPlanIdNo, "G","","","",plineCode);
				if (matGpMlist == null) {
					cro.setV_errMsg("管坯物料已发生改变,请刷新!");
					return cro;
				}
				MatBcTrackEntity matTrack = FrmPlanMaterialDbk
						.getQureyMatTrack(conn, judgeStoveNo, batchNo,
								batchGroupBy, takeCount, "0", proPlanIdNo,
								MatBcTrackEntity.class, "delete","","");

				for (MatBcMEntityPln matGpM : matGpMlist) {
					// if (!matGpM.getProductFlag().equals("801401")) {
					// cro.setV_errMsg("材料类别不是成品,不能脱单!");
					// return cro;
					// }
					// if (!matStatus.equals("80150103")
					// && !matStatus.equals("80150102")) {
					// cro.setV_errMsg("材料状态不是产出待判或产出已判定状态,不能脱单");
					// return cro;
					// }

					// if (matGpM.getHangingFlag().equals("1")) {
					// cro.setV_errMsg("你选择的管坯物料已生成实际炉计划,不能脱单，如需脱单,请先删除炉计划!");
					// return cro;
					// }
					String proPlanZg = matGpM.getProPlanIdNext() + "/"
							+ matGpM.getGxPlanNoNext();
					if (proPlanZg.equals("/")) {
						cro.setV_errMsg("你选择的管坯物料未分配其他加工线订单,不能脱单!");
						return cro;
					}
					// 修改坯子库存信息
					String sqlUpdateMat = CoreXmlSqlParsersFactory
							.getSql("FrmPlanMaterialDbk.UpdateMatGp");
					ps = conn.prepareStatement(sqlUpdateMat);
					ps.setObject(1, "80150102");
					ps.setObject(2, "");
					ps.setObject(3, "");
					ps.setObject(4, "0");
					ps.setObject(5, "0");
					ps.setObject(6, "");
					ps.setObject(7, "");
					ps.setObject(8, matGpM.getMatNo());
					ps.executeUpdate();
					ps.close();
				}
				String resumeSeq = dateFormat.format(now) + df.format(seq);
				// 生成利库日志
				matTrack.setResumeSeq(resumeSeq);
				matTrack.setEventId("900101");
				matTrack.setEventDesc("热处理脱单");
				matTrack.setFormName("com.steering.pss.plnsaleord.planStove.FrmPlanMaterialJgx");
				matTrack.setCallFuncCoding("doDeleteMonomer");
				matTrack.setKeyvalue1("List<MatBcMEntityPln> matGpMlist");
				matTrack.setKeyvalue1Desc("物料主表关键字实体类集合");
				matTrack.setKeyvalue2("String userName");
				matTrack.setKeyvalue2Desc2("操作人");
				matTrack.setKeyvalue3("doDeleteMonomer");
				matTrack.setKeyvalue3Desc3("删除订单号");

				matTrack.setProcessCdoe("G");
				matTrack.setMemo("");
				matTrack.setCreateName(userName);
				matTrack.setCreateTime(dateTime);
				seq++;
				String sqlAddTrack = EntityTool.fillSqlByEntity(
						CoreXmlSqlParsersFactory
								.getSql("FrmPlanMaterialDbk.addMatBcTrack"),
						matTrack);
				ps = conn.prepareStatement(sqlAddTrack);
				ps.executeUpdate();
				ps.close();
			}
			cro.setV_errMsg("脱单成功!");
			conn.commit();
		} catch (SQLException sqle) {
			try {
				conn.rollback();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			cro.setV_errCode(-1);
			cro.setV_errMsg(sqle.getMessage());
		} finally {
			try {
				if (conn != null && !conn.isClosed()) {
					conn.close();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return cro;
	}
}
