package com.steering.mes.mcp.Mch;

import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;
import CoreFS.SC01.CoreConstantData;
import com.steering.comm.converter.CoreConverter;
import com.steering.comm.converter.EntityTool;
import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.StringTool;
import com.steering.mes.mcp.common.CoupMatCollarShar;
import com.steering.mes.mcp.common.PlanService;
import com.steering.mes.mcp.entity.MchEntity.PlnZyJgxMEntity;
import com.steering.mes.mcp.entity.MchTwistinglyResultDEntity;
import com.steering.mes.mcp.entity.MchTwistinglyResultEntity;

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

/**
 * 拧接实绩
 * 
 * @author SZL
 *
 */
public class FrmCoupMakeupResult extends DBCommon {
	private String perStuts = "";

	/**
	 * 查询拧接实绩
	 */
	public CoreReturnObject getQueryExpandResult(String heatNo ,String BatchNo) {
		return this.getDataBySqlID("FrmCoupMakeupResult.getQueryExpandResult",
				new Object[] { heatNo,BatchNo});
	}

	/**
	 * 查询相同炉计划ID下拧接实绩状态
	 */
	public CoreReturnObject getQueryExpandResultStuts(String heatNo,
			String plinCode) {
//		String sql = CoreXmlSqlParsersFactory.getSql("FrmCoupMakeupResult.getQueryExpandResultStuts");
//		sql += "AND T.HEAT_PLAN_NO = '"+heatNo+"'";
//		sql += CoreConverter.toSqlConditionString("T.PLINE_CODE", plinCode);
//		return this.getData(sql);
		return this.getDataBySqlID(
				"FrmCoupMakeupResult.getQueryExpandResultStuts", new Object[] {
						heatNo, plinCode });
	}

	/**
	 * 查询拧接实绩合格支数的和
	 * 
	 * @param heatNo
	 * @return
	 */
	public CoreReturnObject getQueryExpandResult1(String heatNo) {
		return this.getDataBySqlID("FrmCoupMakeupResult.getQueryExpandResult1",
				new Object[] { heatNo });
	}


	public CoreReturnObject QueryCouplingMatDeal(String OrdlnDlyPK){
		return this.getDataBySqlID("FrmCoupMakeupResult.QueryCouplingMatDeal",
				new Object[] {  });
	}


	public CoreReturnObject doQuerypDetail(
			String[] ResultNo) {

		String sql = "";
		sql = CoreXmlSqlParsersFactory
				.getSql("FrmCoupMakeupResult.QueryDetail");
		sql += CoreConverter.toSqlConditionString("T.RESULT_NO", ResultNo);
		return this.getData(sql);
	}

	public CoreReturnObject DoUpdate(String date, ArrayList<String> Details){
		CoreReturnObject core = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		PreparedStatement psta = null;
		try {
			connection.setAutoCommit(false); //
			MchTwistinglyResultEntity entity = EntityTool.getEntityByJSONStr(date,MchTwistinglyResultEntity.class);

			String sql = CoreXmlSqlParsersFactory
					.getSql("FrmMchInOnlineStore.queryApCode");// 查询炉计划是否申请判定
			psta = connection.prepareStatement(sql);
			psta.setObject(1, entity.getJudgeStoveNo());
			psta.setObject(2, entity.getBatchNo());
			ResultSet rs = psta.executeQuery();
			int count = 0;
			if (rs.next()) {
				count = Integer.parseInt(rs.getString("COUNT"));
			}

			if(count > 0){
				core.setV_errMsg("炉号"+entity.getJudgeStoveNo()+",批号"+entity.getBatchNo()+ "已申请判定，不允许修改！");
				return core;
			}

			// 修改接箍个数
			sql = CoreXmlSqlParsersFactory
					.getSql("FrmCoupMakeupResult.doUpdateCouplingNum");
			sql = EntityTool.fillSqlByEntity(sql, entity);
			PreparedStatement doUpdate = connection.prepareStatement(sql);

			String sqlAddD = CoreXmlSqlParsersFactory
					.getSql("FrmCoupMakeupResult.AddDetailResult1");
			sqlAddD = EntityTool.fillSqlByEntity(sqlAddD, entity);

			PreparedStatement patAddD = connection.prepareStatement(sqlAddD);
			String sqlUpdateDeal = CoreXmlSqlParsersFactory
					.getSql("FrmCoupMakeupResult.UpdateCouplingDeal");
			PreparedStatement patUpdateDeal = connection.prepareStatement(sqlUpdateDeal);

			for (int i = 0; i <Details.size() ; i++) {
				MchTwistinglyResultDEntity DEntity = EntityTool.getEntityByJSONStr(Details.get(i),MchTwistinglyResultDEntity.class);

				if(!DEntity.getDealOrde().equals("")) {
					int RemainQty = 0;
					sql = CoreXmlSqlParsersFactory
							.getSql("FrmCoupMakeupResult.QueryRemainQty");
					psta = connection.prepareStatement(sql);
					psta.setObject(1, DEntity.getDealOrde());
					ResultSet rs1 = psta.executeQuery();
					if (rs1.next()) {
						RemainQty = rs1.getInt("REMAIN");
					}
					rs1.close();
					psta.close();

					if (RemainQty <= 0) {
						core.setV_errMsg("处理单号无可用接箍个数,请刷新数据重新录入！");
						return core;
					}

					int Usenum = 0;
					int Failnum = 0;

					if (StringTool.isInteger(DEntity.getCouplingNum())) {
						Usenum += Integer.parseInt(DEntity.getCouplingNum());
					}
					if (StringTool.isInteger(DEntity.getCouplingFailNum())) {
						Failnum = Integer.parseInt(DEntity.getCouplingFailNum());
					}

					if (Usenum + Failnum > RemainQty) {
						core.setV_errMsg("处理单号可用接箍个数为" + RemainQty + ", 录入合格" + Usenum + "个" + "废品" + Failnum + "个,超出可用个数");
						return core;
					}

					patUpdateDeal.setObject(1, DEntity.getCouplingNum());
					patUpdateDeal.setObject(2, DEntity.getCouplingWt());
					patUpdateDeal.setObject(3, DEntity.getCouplingFailNum());
					patUpdateDeal.setObject(4, DEntity.getCouplingFailWt());
					patUpdateDeal.setObject(5, DEntity.getCouplingNum());
					patUpdateDeal.setObject(6, DEntity.getCouplingFailNum());
					patUpdateDeal.setObject(7, DEntity.getDealOrde());
					patUpdateDeal.addBatch();


					if(Failnum>0){
						ArrayList<String> FailData = new ArrayList<String>();
						FailData.add( DEntity.getDealOrde());
						FailData.add(entity.getProUser());
						FailData.add(entity.getProShift());
						FailData.add(entity.getProGroup());
						FailData.add( DEntity.getCouplingFailNum());
						CoupMatCollarShar.addMatFaill(FailData,connection,"0");
					}
				}

//				patAddD.setObject(1,i);
				patAddD.setObject(1,DEntity.getCouplingStoveNo());
				patAddD.setObject(2,DEntity.getLotNo());
				patAddD.setObject(3,DEntity.getCouplingNum());
				patAddD.setObject(4,DEntity.getCouplingWt());
				patAddD.setObject(5,DEntity.getDealOrde());
				patAddD.setObject(6,DEntity.getWoId());
				patAddD.setObject(7,DEntity.getCouplingFailNum());
				patAddD.setObject(8,DEntity.getCouplingFailWt());
				patAddD.addBatch();
			}

			patUpdateDeal.executeBatch();
			patAddD.executeBatch();
			doUpdate.executeUpdate();
			core.setV_errMsg("修改成功！");
			core.setResult(1);
			connection.commit();
		}catch (Exception e) {
			core.setV_errMsg(e.getMessage());
			if (connection != null) {
				try {
					connection.rollback(); // 回滚事务
				}
				catch (Exception e2) {
				}
			}
		}
		finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			}
			catch (Exception e2) {
			}
		}
		return core;
	}

	public CoreReturnObject DoAdd(String loadStr, String gx, ArrayList<String> ScrappedList, ArrayList<String> SuspiciousList, ArrayList<String> Details){
		CoreReturnObject core = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		PreparedStatement psta = null;
		Date now = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss", Locale.CHINA);
		String systime = dateFormat.format(now);

		try {
			connection.setAutoCommit(false); //



			String sqlupdatepln = CoreXmlSqlParsersFactory
					.getSql("FrmMcpLoading.updatePlnZyRclM2");// 修改加工计划表
			PreparedStatement patupdatepln = connection
					.prepareStatement(sqlupdatepln);

			String addPlnInfo = CoreXmlSqlParsersFactory
					.getSql("FrmMcpLoading.AddComInfoResultNew");// 新增公共信息
			PreparedStatement patsPlan = connection
					.prepareStatement(addPlnInfo);


			MchTwistinglyResultEntity Load = EntityTool.getEntityByJSONStr(loadStr,MchTwistinglyResultEntity.class);


			// 获取加工计划实体了
			PlnZyJgxMEntity pln = PlanService.getSendHttPlanCInfo3(connection,
					Load.getHeatPlanNo());


			//region 检查
			if (pln == null){
				core.setV_errMsg("找不到炉计划数据！");
				return core;
			}

			if (!pln.getPlanstatus().equals("20")) {
				core.setV_errMsg("炉计划不处于生产中状态！");
				return core;
			}


			String cutFalg = "";
			String sql = CoreXmlSqlParsersFactory
					.getSql("MchComm.queryComInfo");// 查询 工序是否是结炉状态
			psta = connection.prepareStatement(sql);
			psta.setString(1, Load.getHeatPlanNo());
			psta.setString(2, Load.getBatchNo());
			psta.setString(3, "701311");
			ResultSet rs = psta.executeQuery();
			if (rs.next()) {
				cutFalg = rs.getString("STATION_STATUS");
			}


			if (cutFalg.equals("2")) {
				core.setV_errMsg("下线已结炉,不允许此操作！");
				return core;
			}
			rs.close();
			psta.close();
			//endregion


			String resultNo = "";
			int count = 0;
			int detCount = 0;


			if(StringTool.isInteger(Load.getFailNum())){
				detCount = Integer.parseInt(Load.getFailNum());
			}
			if(StringTool.isInteger(Load.getProNum()) && StringTool.isInteger(Load.getReProNum())){
				count = Integer.parseInt(Load.getProNum()) +Integer.parseInt(Load.getReProNum());
			}


			if(count<=0){
				core.setV_errMsg("请输入正确的作业支数！");
				return core;
			}

			if(count<detCount){
				core.setV_errMsg("废品支数不能大于作业支数！");
				return core;
			}


			//获取最大实绩编号
			sql =   CoreXmlSqlParsersFactory
					.getSql("FrmCoupMakeupResult.queryResultNo");
			psta = connection.prepareStatement(sql);
			psta.setObject(1, pln.getPlineCode() + gx );
			psta.setObject(2, pln.getPlineCode() + gx );
			ResultSet rs1 = psta.executeQuery();
			if (rs1.next()) {
				resultNo = rs1.getString("RESULT_NO");
			}
			rs1.close();
			psta.close();


			Load.setResultNo(resultNo);

			String sqlAdd = CoreXmlSqlParsersFactory
					.getSql("FrmCoupMakeupResult.AddResult");// 新增上料实绩

			sqlAdd = com.steering.common.EntityTool.fillSqlByEntity(sqlAdd, Load);
			PreparedStatement patAdd = connection.prepareStatement(sqlAdd);
			patAdd.addBatch();


			String sqlAddD = CoreXmlSqlParsersFactory
					.getSql("FrmCoupMakeupResult.AddDetailResult");

			sqlAddD = com.steering.common.EntityTool.fillSqlByEntity(sqlAddD, Load);
			PreparedStatement patAddD = connection.prepareStatement(sqlAddD);


			String sqlUpdateDeal = CoreXmlSqlParsersFactory
					.getSql("FrmCoupMakeupResult.UpdateCouplingDeal");

			PreparedStatement patUpdateDeal = connection.prepareStatement(sqlUpdateDeal);




			for (int i = 0; i <Details.size() ; i++) {
				MchTwistinglyResultDEntity DEntity = EntityTool.getEntityByJSONStr(Details.get(i),MchTwistinglyResultDEntity.class);


				if(!DEntity.getDealOrde().equals("")) {

					int RemainQty = 0;
					sql = CoreXmlSqlParsersFactory
							.getSql("FrmCoupMakeupResult.QueryRemainQty");
					psta = connection.prepareStatement(sql);
					psta.setObject(1, DEntity.getDealOrde());
					rs1 = psta.executeQuery();
					if (rs1.next()) {
						RemainQty = rs1.getInt("REMAIN");
					}
					rs1.close();
					psta.close();

					if (RemainQty <= 0) {
						core.setV_errMsg("处理单号无可用接箍个数,请刷新数据重新录入！");
						return core;
					}


					int Usenum = 0;
					int Failnum = 0;

					if (StringTool.isInteger(DEntity.getCouplingNum())) {
						Usenum += Integer.parseInt(DEntity.getCouplingNum());
					}
					if (StringTool.isInteger(DEntity.getCouplingFailNum())) {
						Failnum = Integer.parseInt(DEntity.getCouplingFailNum());
					}

					if (Usenum + Failnum > RemainQty) {
						core.setV_errMsg("处理单号可用接箍个数为" + RemainQty + ", 录入合格" + Usenum + "个" + "废品" + Failnum + "个,超出可用个数");
						return core;
					}


					patUpdateDeal.setObject(1, DEntity.getCouplingNum());
					patUpdateDeal.setObject(2, DEntity.getCouplingWt());
					patUpdateDeal.setObject(3, DEntity.getCouplingFailNum());
					patUpdateDeal.setObject(4, DEntity.getCouplingFailWt());
					patUpdateDeal.setObject(5, DEntity.getCouplingNum());
					patUpdateDeal.setObject(6, DEntity.getCouplingFailNum());
					patUpdateDeal.setObject(7, DEntity.getDealOrde());
					patUpdateDeal.addBatch();


					if(Failnum>0){
						ArrayList<String> FailData = new ArrayList<String>();
						FailData.add( DEntity.getDealOrde());
						FailData.add(Load.getProUser());
						FailData.add(Load.getProShift());
						FailData.add(Load.getProGroup());
						FailData.add( DEntity.getCouplingFailNum());
						CoupMatCollarShar.addMatFaill(FailData,connection,"0");
					}
				}


				patAddD.setObject(1,i);
				patAddD.setObject(2,DEntity.getCouplingStoveNo());
				patAddD.setObject(3,DEntity.getLotNo());
				patAddD.setObject(4,DEntity.getCouplingNum());
				patAddD.setObject(5,DEntity.getCouplingWt());
				patAddD.setObject(6,DEntity.getDealOrde());
				patAddD.setObject(7,DEntity.getWoId());
				patAddD.setObject(8,DEntity.getCouplingFailNum());
				patAddD.setObject(9,DEntity.getCouplingFailWt());
				patAddD.addBatch();







			}



			// 新增加工公共信息
			patsPlan.setObject(1, resultNo);
			patsPlan.setObject(2, Load.getPlineCode());
			patsPlan.setObject(3, Load.getPlineName());
			patsPlan.setObject(4, gx);
			patsPlan.setObject(5, gx);
			patsPlan.setObject(6, Load.getBatchNo());
			patsPlan.setObject(7, Load.getProNum());
			patsPlan.setObject(8, Load.getProWt());
			patsPlan.setObject(9, Load.getFailNum());
			patsPlan.setObject(10, Load.getFailWt());
			patsPlan.setObject(11, Load.getProTime());
			patsPlan.setObject(12, Load.getProShift());
			patsPlan.setObject(13, Load.getProGroup());
			patsPlan.setObject(14, Load.getProUser());
			patsPlan.setObject(15, Load.getProUser());
			patsPlan.setObject(16, Load.getHeatPlanNo());
			patsPlan.addBatch();

            //00-上料开始,10-探伤开始，20-切管开始，30-车丝开始，40-螺纹检验开始，50拧接开始，60-通径开始,70-水压开始，80-倒凌开始，90-测量点开始，11-交库开始
			patupdatepln.setObject(1,"50");
			patupdatepln.setObject(2,Load.getHeatPlanNo());
			patupdatepln.setObject(3,Load.getBatchNo());
			patupdatepln.addBatch();

			patUpdateDeal.executeBatch();
			patAdd.executeBatch();
			patAddD.executeBatch();
			patsPlan.executeBatch();
			patupdatepln.executeBatch();


			FrmMchBugD.AddMchWaste(connection,Load.getHeatPlanNo(),resultNo,Load.getPlineCode(),Load.getProUser(),gx,SuspiciousList, ScrappedList);

			core.setV_errMsg("新增成功！");
			core.setResult(1);
			connection.commit();
		}
		catch (Exception e) {
			core.setV_errMsg(e.getMessage());
			if (connection != null) {
				try {
					connection.rollback(); // 回滚事务
				}
				catch (Exception e2) {
				}
			}
		}
		finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			}
			catch (Exception e2) {
			}
		}
		return core;
	}


	public CoreReturnObject DoDelete(String loadStr,String gx) {
		CoreReturnObject core = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		Date now = new Date();
		SimpleDateFormat dateFormat1 = new SimpleDateFormat(
				"yyyyMM", Locale.CHINA);
		String systime1 = dateFormat1.format(now);
		PreparedStatement psta = null;

		SimpleDateFormat dateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss", Locale.CHINA);
		String systime = dateFormat.format(new Date());

		try {
			connection.setAutoCommit(false); // 取消自动提交事务

			String DeleteComInfoSql = CoreXmlSqlParsersFactory
					.getSql("FrmMcpLoading.deleteVrpResult");// 删除公共信息
			PreparedStatement patsDeleteComInfo = connection
					.prepareStatement(DeleteComInfoSql);

			String DeleteResultSql = CoreXmlSqlParsersFactory
					.getSql("FrmCoupMakeupResult.DeleteResult");// 删除实绩
			PreparedStatement patsDeleteResult = connection
					.prepareStatement(DeleteResultSql);

			String DeleteDetailResultSql = CoreXmlSqlParsersFactory
					.getSql("FrmCoupMakeupResult.DeleteDetailResult");// 删除实绩
			PreparedStatement patsDeleteDetailResult = connection
					.prepareStatement(DeleteDetailResultSql);

			String sqlUpdateDeal = CoreXmlSqlParsersFactory
					.getSql("FrmCoupMakeupResult.UpdateCouplingDeal1");

			PreparedStatement patUpdateDeal = connection.prepareStatement(sqlUpdateDeal);

			MchTwistinglyResultEntity Load = EntityTool.getEntityByJSONStr(loadStr,MchTwistinglyResultEntity.class);

			PlnZyJgxMEntity pln = PlanService.getSendHttPlanCInfo3(connection,
					Load.getHeatPlanNo(),Load.getBatchNo());

			if(!pln.getPlineCode().equals(Load.getPlineCode())){
				core.setV_errMsg("不能删除其他产线生成的实绩！");
				return core;
			}


			//region 检查
			if (pln == null){
				core.setV_errMsg("找不到炉计划数据！");
				return core;
			}

			if (!pln.getPlanstatus().equals("20")) {
				core.setV_errMsg("炉计划不处于生产中状态！");
				return core;
			}


			String cutFalg = "";
			String sql = CoreXmlSqlParsersFactory
					.getSql("MchComm.queryComInfo");// 查询 工序是否是结炉状态
			psta = connection.prepareStatement(sql);
			psta.setString(1, Load.getHeatPlanNo());
			psta.setString(2, Load.getBatchNo());
			psta.setString(3, "701311");
			ResultSet rs = psta.executeQuery();
			if (rs.next()) {
				cutFalg = rs.getString("STATION_STATUS");
			}


			if (cutFalg.equals("2")) {
				core.setV_errMsg("下线已结炉,不允许此操作！");
				return core;
			}
			rs.close();
			psta.close();
			//endregion


			patsDeleteComInfo.setObject(1,Load.getResultNo());
			patsDeleteComInfo.addBatch();
			patsDeleteComInfo.executeBatch();



			patsDeleteResult.setObject(1,Load.getResultNo());
			patsDeleteResult.addBatch();
			patsDeleteResult.executeBatch();

			sql = CoreXmlSqlParsersFactory
					.getSql("FrmCoupMakeupResult.QueryDetail");
			sql += " AND RESULT_NO ='"  +Load.getResultNo() +"' ";
			psta = connection.prepareStatement(sql);
			 rs = psta.executeQuery();
			List<MchTwistinglyResultDEntity> Details = EntityTool.getEntitysByRs(rs,
					MchTwistinglyResultDEntity.class);
			rs.close();
			psta.close();

			for (MchTwistinglyResultDEntity  Detail :Details
				 ) {

				int Failnum =0;

				if(StringTool.isInteger(Detail.getCouplingFailNum())){
					Failnum = Integer.parseInt(Detail.getCouplingFailNum());
				}


				patUpdateDeal.setObject(1, Detail.getCouplingNum());
				patUpdateDeal.setObject(2, Detail.getCouplingWt());
				patUpdateDeal.setObject(3, Detail.getCouplingFailNum());
				patUpdateDeal.setObject(4, Detail.getCouplingFailWt());
				patUpdateDeal.setObject(5, Detail.getCouplingNum());
				patUpdateDeal.setObject(6, Detail.getCouplingFailNum());
				patUpdateDeal.setObject(7, Detail.getDealOrde());
				patUpdateDeal.addBatch();

				if(Failnum>0){
					ArrayList<String> FailData = new ArrayList<String>();
					FailData.add( Detail.getDealOrde());
					FailData.add(Load.getProUser());
					FailData.add(Load.getProShift());
					FailData.add(Load.getProGroup());
					FailData.add( Detail.getCouplingFailNum());
					CoupMatCollarShar.addMatFaill(FailData,connection,"1");
				}

			}
			patUpdateDeal.executeBatch();


			patsDeleteDetailResult.setObject(1,Load.getResultNo());
			patsDeleteDetailResult.addBatch();
			patsDeleteDetailResult.executeBatch();

			int detCount =0;
			if(StringTool.isInteger(Load.getFailNum())){
				detCount = Integer.parseInt(Load.getFailNum());
			}

			FrmMchBugD.DeleteMchWaste(connection, Load.getHeatPlanNo(),Load.getResultNo(), Load.getPlineCode(),gx,detCount);


			core.setV_errMsg("删除成功！");
			core.setResult(1);
			connection.commit();
		}
		catch (Exception e) {
			core.setV_errMsg(e.getMessage());
			if (connection != null) {
				try {
					connection.rollback(); // 回滚事务
				}
				catch (Exception e2) {
				}
			}
		}
		finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			}
			catch (Exception e2) {
			}
		}
		return core;
	}

	public CoreReturnObject UpdatePath(String Path, String ResultNo){
			return	this.setDataBySqlID("FrmCoupMakeupResult.UpdatePath",new Object[]{Path,ResultNo});
	}

	/**
	 * 每支材料对应的入库单号
	 * 
	 * @param conn
	 *            c
	 * @param strlist
	 *            传递参数
	 * @return obj
	 * @throws Exception
	 *             异常处理
	 */
	public String querySendSqlDoc(Connection conn, String strlist, String memo)
			throws Exception {
		String seq = "";
		PreparedStatement psta = null;
		Date dt = new Date();
		SimpleDateFormat matter1 = new SimpleDateFormat("yyyy-MM-dd");
		SimpleDateFormat matter2 = new SimpleDateFormat("yyMMdd");
		String sqlLovsqe = CoreXmlSqlParsersFactory
				.getSql("FrmThreadingResult.getInListDoc");
		psta = conn.prepareStatement(sqlLovsqe);
		psta.setString(1, memo);
		psta.setString(2, matter2.format(dt));
		psta.setString(3, matter1.format(dt));
		psta.setString(4, strlist);
		ResultSet rs = psta.executeQuery();
		if (rs.next()) {
			seq = rs.getString("INSTOCK_DOC");
		}
		rs.close();
		psta.close();
		return seq;
	}

	/**
	 * 每支材料对应的入库流水号
	 * 
	 * @param conn
	 *            c
	 * @param strlist
	 *            传递参数
	 * @return obj
	 * @throws Exception
	 *             异常处理
	 */
	public String querySendSql(Connection conn, String strlist)
			throws Exception {
		String seq = "";
		PreparedStatement psta = null;
		String sqlLovsqe = CoreXmlSqlParsersFactory
				.getSql("FrmThreadingResult.getInListDoc1");
		psta = conn.prepareStatement(sqlLovsqe);
		psta.setString(1, strlist);
		ResultSet rs = psta.executeQuery();
		if (rs.next()) {
			seq = rs.getString("INSTOCK_SQE");
		}
		rs.close();
		psta.close();
		return seq;
	}
}
