package com.steering.pss.ydm.pipemanage;

import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;
import CoreFS.SC01.CoreConstantData;
import com.steering.comm.converter.CoreConverter;
import com.steering.comm.data.ComBaseInfo;
import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.EntityTool;
import com.steering.comm.tools.StringTool;
import com.steering.pss.ydm.base.FrmEndMaterial;
import com.steering.pss.ydm.base.MeanValueCalculation;
import com.steering.pss.ydm.entity.MatZcMEntity;

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

public class FrmPipeEnter extends DBCommon {

	public CoreReturnObject queryEnterInList(ArrayList<String> parm,
			String[] arr, String startTim, String endTim, String custom) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmPipeEnter.queryEnterInList");
		sql += CoreConverter.toSqlConditionString("t.BELONG_CODE", arr);
		sql += " AND T.SUPPLY_UNIT_CODE = '" + custom + "'";
		if (!startTim.equals("")) {
			sql += " AND INSTOCK_TIME>=TO_DATE('" + startTim
					+ "','YYYY-MM-DD HH24:MI:SS') AND INSTOCK_TIME<= TO_DATE('"
					+ endTim + "','YYYY-MM-DD HH24:MI:SS')";
		}
		sql += " group by t.JUDGE_STOVE_NO,t.BATCH_NO,t.INSTOCK_DOC,t.PRODUCCODE,t.PRODUCNAME,t.STD_CODE,t.STD_NAME,t.STEELCODE,t.STEELNAME,t.STD_STYLE,t.STD_STYLE_DESC,t.SPEC_CODE,t.SPEC_NAME,t.JUDGE_STD_CODE,t.JUDGE_STD_NAME,t.GRADECODE,t.GRADENAME,t.BAL_YEAR_MONTH,t.ORD_LN_PK,t.BATCH_GROUD_NO,";
		sql += " t.MODEL_DESC,t.ACT_DIMATER,t.ACT_HEIGHT,t.ACT_LEN_MIN,t.ACT_LEN_MAX,t.BELONG_CODE,t.BELONG_NAME,s.STORAGE_NAME,t.PIPMEMO,t.CREATE_NAME,t.ORDER_NO,t.ORDER_SEQ,t.DELIVERY_NO,t.MODEL_CODE,t.PRODUCT_FLAG,t.ZB_RCDID,t.PLINE_CODE,t.PLINE_NAME,d.SALE_AREA_DESC,d.create_name,t.SUPPLY_UNIT_CODE";
		sql += " order by t.instock_doc desc";
		return this.getData(sql, parm.toArray());
	}

	/***
	 * 查询钢种基础信息
	 * 
	 * @return
	 */
	public CoreReturnObject getGrade() {
		return this.getDataBySqlID("FrmPipeEnter.getGrade");
	}

	/***
	 * 查询规格基础信息
	 * 
	 * @return
	 */
	public CoreReturnObject getSpec() {
		return this.getDataBySqlID("FrmPipeEnter.getSpec");
	}

	/***
	 * 查询扣型基础信息
	 * 
	 * @return
	 */
	public CoreReturnObject getModel() {
		return this.getDataBySqlID("FrmPipeEnter.getModel");
	}

	/***
	 * 查询外径壁厚
	 * 
	 * @param parm
	 * @return
	 */
	public CoreReturnObject getDimHeig(ArrayList<String> parm) {
		return this.getDataBySqlID("FrmPipeEnter.getDimHeig", parm.toArray());
	}

	/***
	 * 查询输入合同是否存在
	 * 
	 * @param parm
	 * @return
	 */
	public CoreReturnObject getOrderPk(ArrayList<String> parm) {
		return this.getDataBySqlID("FrmPipeEnter.getOrderPk", parm.toArray());
	}

	/***
	 * 按炉批查询已有材料号数量
	 * 
	 * @param heatNo
	 * @param bacthNo
	 * @return
	 */
	public CoreReturnObject getCount(String heatNo, String bacthNo) {
		return this.getDataBySqlID("FrmPipeEnter.getCount", new Object[] {
				heatNo, bacthNo, heatNo, bacthNo });
	}

	/***
	 * 手工入库
	 * 
	 * @param parm
	 * @return
	 */
	public CoreReturnObject addPipData(ArrayList<String> parm, String[] parr,
			String custom) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		Date now = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss");
		SimpleDateFormat df = new SimpleDateFormat("yyyyMM");
		// String yearMoth = df.format(now);
		String systime = dateFormat.format(now);
		String inListDoc = "";
		int acount = 0;
		String supplyUnitCode = "";
		String supplyUnit = "";
		String processCode = "";
		String processName = "";

		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			if (custom.equals("120501")) {
				supplyUnitCode = "120501";
				supplyUnit = "天津钢管制造有限公司";
			} else if (custom.equals("120504")) {
				supplyUnitCode = "120504";
				supplyUnit = "江苏天淮钢管有限公司";
			}
			String yearMoth = "120504".equals(supplyUnitCode)? ComBaseInfo.GetBalYear_2416(now): ComBaseInfo.GetBalYear(now);
			String sql = CoreXmlSqlParsersFactory
					.getSql("FrmPipeEnter.selectProcess");
			PreparedStatement ps = connection.prepareStatement(sql);
			ps.setString(1, parm.get(39));
			ResultSet rs = ps.executeQuery();
			if (rs.next()) {
				processCode = rs.getString("PROCESS_CODE");
				processName = rs.getString("PROCESS_DESC");
			}
			rs.close();
			ps.close();
			if (processCode.equals("")) {
				processCode = "D";
				processName = "轧制";
			}

			String insertMatSql = CoreXmlSqlParsersFactory
					.getSql("FrmPipeEnter.insertMat");// 插入材料表
			PreparedStatement insertMatPsta = connection
					.prepareStatement(insertMatSql);
			String insertMatSqlXs = CoreXmlSqlParsersFactory
					.getSql("FrmPipeEnterXs.insertMat");// 插入销售材料表
			PreparedStatement insertMatPstaXs = connection
					.prepareStatement(insertMatSqlXs);
			String insertButressSql = CoreXmlSqlParsersFactory
					.getSql("FrmPipeEnter.insertButress");// 插入位置表
			PreparedStatement insertButressPsta = connection
					.prepareStatement(insertButressSql);
			String insertInListSql = CoreXmlSqlParsersFactory
					.getSql("FrmPipeEnter.insertInList");// 插入入库表
			PreparedStatement insertInListPsta = connection
					.prepareStatement(insertInListSql); 
			String insertInListSqlXs = CoreXmlSqlParsersFactory
					.getSql("FrmPipeEnterXs.insertInList");// 插入销售入库表
			PreparedStatement insertInListPstaXs = connection
					.prepareStatement(insertInListSqlXs); 
			String updatePlanSql = CoreXmlSqlParsersFactory
					.getSql("FrmPipeEnter.updatePlan");// 修改计划表
			PreparedStatement updatePlanPsta = connection
					.prepareStatement(updatePlanSql);
			String updateProcessSql = CoreXmlSqlParsersFactory
					.getSql("FrmPipeEnter.updateProcess");// 写进程表
			PreparedStatement updateProcessPsta = connection
					.prepareStatement(updateProcessSql);
			int numCount = Integer.parseInt(parm.get(2));// 支数
			double numWgt = Double.parseDouble(parm.get(27));// 重量
			double numLen = Double.parseDouble(parm.get(36));// 长度
			String lcode = parm.get(0);// 炉号
			String lotno = parm.get(1);// 批号
			inListDoc = querySendSqlDoc(connection, parm.get(31), parm.get(28));// 入库单号
			String groupNo = queryGroupNo(connection, lcode, lotno);
			String matNo = queryMatNoM(connection, lcode, lotno); // 材料号
			int g = Integer.parseInt(matNo.substring(matNo.length() - 4, matNo
					.length()));
			String inListSeq = querySendSql(connection, inListDoc); // 入库流水号
			int n = Integer.parseInt(inListSeq.substring(
					inListSeq.length() - 4, inListSeq.length()));
			List<double[]> list = MeanValueCalculation.MeanCalculation(numWgt,
					numCount);
			ArrayList<String> materialList = new ArrayList<String>();
			materialList.add(parm.get(3));// 品名
			materialList.add(parm.get(4));
			materialList.add(parm.get(7));// 规格
			materialList.add(parm.get(8));
			materialList.add(parm.get(15));// 标准类别
			materialList.add(parm.get(16));
			materialList.add(parm.get(5));// 钢级
			materialList.add(parm.get(6));
			materialList.add(parm.get(9));// 扣型
			materialList.add(parm.get(10));
			String[] materialS = FrmEndMaterial.formEndMaterial(materialList,
					connection);
			if (materialS == null) {
				cro.setV_errMsg("无产品大类基础信息,需维护产品基础信息!");
				return cro;
			}
			String[] arr = null;
			List<String[]> pKList = FrmPipeEnter.getOrderPk(connection, parm
					.get(17), parm.get(18), parm.get(19), parr);
			if (pKList != null) {
				arr = pKList.get(0);
			}
			ArrayList<String> lengthList = null;
			if (!parm.get(36).equals("") || !parm.equals("0.000")) {
				lengthList = new ArrayList<String>();
				List<double[]> lenList = MeanValueCalculation.MeanCalculation(
						numLen, numCount);
				for (int k = 0; k < lenList.size(); k++) {
					double[] conLen = lenList.get(k);
					if ((int) conLen[0] > 0) {
						for (int x = 0; x < (int) conLen[0]; x++) {
							DecimalFormat dt = new DecimalFormat("0.000");
							lengthList.add(dt.format(conLen[1]));
						}
					}
				}
			}
			for (int j = 0; j < list.size(); j++) {
				double[] conW = list.get(j);
				if ((int) conW[0] >= 0) {
					for (int z = 0; z < (int) conW[0]; z++) {
						insertMatPsta.setString(1, parm.get(0));
						insertMatPsta.setString(2, parm.get(1));
						insertMatPsta.setString(3, groupNo);
						insertMatPsta.setString(4, parm.get(3));
						insertMatPsta.setString(5, parm.get(4));
						insertMatPsta.setString(6, parm.get(5));
						insertMatPsta.setString(7, parm.get(6));
						insertMatPsta.setString(8, parm.get(7));
						insertMatPsta.setString(9, parm.get(8));
						insertMatPsta.setString(10, parm.get(9));
						insertMatPsta.setString(11, parm.get(10));
						insertMatPsta.setString(12, parm.get(11));// 标准
						insertMatPsta.setString(13, parm.get(12));
						insertMatPsta.setString(14, parm.get(34));
						insertMatPsta.setString(15, parm.get(35));
						insertMatPsta.setString(16, parm.get(15));
						insertMatPsta.setString(17, parm.get(16));
						
						insertMatPstaXs.setString(1, parm.get(0));
						insertMatPstaXs.setString(2, parm.get(1));
						insertMatPstaXs.setString(3, groupNo);
						insertMatPstaXs.setString(4, parm.get(3));
						insertMatPstaXs.setString(5, parm.get(4));
						insertMatPstaXs.setString(6, parm.get(5));
						insertMatPstaXs.setString(7, parm.get(6));
						insertMatPstaXs.setString(8, parm.get(7));
						insertMatPstaXs.setString(9, parm.get(8));
						insertMatPstaXs.setString(10, parm.get(9));
						insertMatPstaXs.setString(11, parm.get(10));
						insertMatPstaXs.setString(12, parm.get(11));// 标准
						insertMatPstaXs.setString(13, parm.get(12));
						insertMatPstaXs.setString(14, parm.get(34));
						insertMatPstaXs.setString(15, parm.get(35));
						insertMatPstaXs.setString(16, parm.get(15));
						insertMatPstaXs.setString(17, parm.get(16));
						

						if (pKList != null) {
							if (arr[2] != null && arr[3] != null
									&& arr[4] != null) {
								insertMatPsta.setString(18, parm.get(17));// 合同号
								insertMatPsta.setString(19, parm.get(18));
								insertMatPsta.setString(20, arr[10]);
								insertMatPsta.setString(21, arr[2]);
								insertMatPsta.setString(22, arr[3]);
								insertMatPsta.setString(23, arr[4]);// 交货行键
								
								insertMatPstaXs.setString(18, parm.get(17));// 合同号
								insertMatPstaXs.setString(19, parm.get(18));
								insertMatPstaXs.setString(20, arr[10]);
								insertMatPstaXs.setString(21, arr[2]);
								insertMatPstaXs.setString(22, arr[3]);
								insertMatPstaXs.setString(23, arr[4]);// 交货行键
								
							} else {
								insertMatPsta.setString(18, "");// 合同号
								insertMatPsta.setString(19, "");
								insertMatPsta.setString(20, "");
								insertMatPsta.setString(21, "");
								insertMatPsta.setString(22, "");
								insertMatPsta.setString(23, "");// 交货行键
								
								insertMatPstaXs.setString(18, "");// 合同号
								insertMatPstaXs.setString(19, "");
								insertMatPstaXs.setString(20, "");
								insertMatPstaXs.setString(21, "");
								insertMatPstaXs.setString(22, "");
								insertMatPstaXs.setString(23, "");// 交货行键
								
							}
						} else {
							insertMatPsta.setString(18, "");// 合同号
							insertMatPsta.setString(19, "");
							insertMatPsta.setString(20, "");
							insertMatPsta.setString(21, "");
							insertMatPsta.setString(22, "");
							insertMatPsta.setString(23, "");// 交货行键
							
							insertMatPstaXs.setString(18, "");// 合同号
							insertMatPstaXs.setString(19, "");
							insertMatPstaXs.setString(20, "");
							insertMatPstaXs.setString(21, "");
							insertMatPstaXs.setString(22, "");
							insertMatPstaXs.setString(23, "");// 交货行键
						}
						insertMatPsta.setString(24, parm.get(20));
						insertMatPsta.setString(25, parm.get(21));
						
						insertMatPstaXs.setString(24, parm.get(20));
						insertMatPstaXs.setString(25, parm.get(21));
						if (pKList != null) {
							if (arr[2] != null && arr[3] != null
									&& arr[4] != null) {
								insertMatPsta.setString(26, arr[7]);
								insertMatPsta.setString(27, arr[8]);
								insertMatPsta.setString(28, arr[9]);
								
								insertMatPstaXs.setString(26, arr[7]);
								insertMatPstaXs.setString(27, arr[8]);
								insertMatPstaXs.setString(28, arr[9]);
							} else {
								insertMatPsta.setString(26, "");
								insertMatPsta.setString(27, "");
								insertMatPsta.setString(28, "");
								
								insertMatPstaXs.setString(26, "");
								insertMatPstaXs.setString(27, "");
								insertMatPstaXs.setString(28, "");
							}
						} else {
							insertMatPsta.setString(26, "");
							insertMatPsta.setString(27, "");
							insertMatPsta.setString(28, "");
							
							insertMatPstaXs.setString(26, "");
							insertMatPstaXs.setString(27, "");
							insertMatPstaXs.setString(28, "");
						}
						insertMatPsta.setString(29, new DecimalFormat("0.00")
								.format(Double.parseDouble(parm.get(22))));// 下限
						insertMatPsta.setString(30, new DecimalFormat("0.00")
								.format(Double.parseDouble(parm.get(23))));// 上限
						insertMatPsta.setString(31, parm.get(24));
						insertMatPsta.setString(32, "1");
						insertMatPsta.setString(33, new DecimalFormat("0.000")
								.format(conW[1]));// 重量
						insertMatPsta.setString(34, systime);
						insertMatPsta.setString(35, systime);
						insertMatPsta.setString(36, (lcode + lotno)
								+ StringTool.formatDecimal(g, "0000"));
						insertMatPsta.setString(37, "");
						insertMatPsta.setString(38, parm.get(44));
						insertMatPsta.setString(39, parm.get(45));
						
						insertMatPstaXs.setString(29, new DecimalFormat("0.00")
								.format(Double.parseDouble(parm.get(22))));// 下限
						insertMatPstaXs.setString(30, new DecimalFormat("0.00")
								.format(Double.parseDouble(parm.get(23))));// 上限
						insertMatPstaXs.setString(31, parm.get(24));
						insertMatPstaXs.setString(32, "1");
						insertMatPstaXs.setString(33, new DecimalFormat("0.000")
								.format(conW[1]));// 重量
						insertMatPstaXs.setString(34, systime);
						insertMatPstaXs.setString(35, systime);
						insertMatPstaXs.setString(36, (lcode + lotno)
								+ StringTool.formatDecimal(g, "0000"));
						insertMatPstaXs.setString(37, "");
						insertMatPstaXs.setString(38, parm.get(44));
						insertMatPstaXs.setString(39, parm.get(45));
						if (!parm.get(36).equals("") && !parm.get(36).equals("0.000")) {
							insertMatPsta.setString(40, lengthList.get(acount));
							insertMatPstaXs.setString(40, lengthList.get(acount));
						} else {
							insertMatPsta.setString(40, "0");
							insertMatPstaXs.setString(40, "0");
						}
						insertMatPsta.setString(41, "");
						insertMatPsta.setString(42, yearMoth);
						insertMatPsta.setString(43, parm.get(39));
						insertMatPsta.setString(44, parm.get(40));
						insertMatPsta.setString(45, parm.get(41));
						insertMatPsta.setString(46, parm.get(42));
						insertMatPsta.setString(47, parm.get(43));
						insertMatPsta.setString(48, parm.get(48));// 材料来源
						insertMatPsta.setString(49, parm.get(49));
						insertMatPsta.setString(50, parm.get(39));
						insertMatPsta.setString(51, parm.get(40));
						insertMatPsta.setString(52, materialS[0].toString());
						insertMatPsta.setString(53, materialS[1].toString());
						insertMatPsta.setString(54, parm.get(50));
						insertMatPsta.setString(55, parm.get(51));
						insertMatPsta.setString(56, supplyUnitCode);
						insertMatPsta.setString(57, supplyUnit);
						insertMatPsta.setString(58, parm.get(0));
						insertMatPsta.setString(59, parm.get(52));
						insertMatPsta.setString(60, processCode);
						insertMatPsta.setString(61, processName);
						insertMatPsta.addBatch();
						
						insertMatPstaXs.setString(41, "");
						insertMatPstaXs.setString(42, yearMoth);
						insertMatPstaXs.setString(43, parm.get(39));
						insertMatPstaXs.setString(44, parm.get(40));
						insertMatPstaXs.setString(45, parm.get(41));
						insertMatPstaXs.setString(46, parm.get(42));
						insertMatPstaXs.setString(47, parm.get(43));
						insertMatPstaXs.setString(48, parm.get(48));// 材料来源
						insertMatPstaXs.setString(49, parm.get(49));
						insertMatPstaXs.setString(50, parm.get(39));
						insertMatPstaXs.setString(51, parm.get(40));
						insertMatPstaXs.setString(52, materialS[0].toString());
						insertMatPstaXs.setString(53, materialS[1].toString());
						insertMatPstaXs.setString(54, parm.get(50));
						insertMatPstaXs.setString(55, parm.get(51));
						insertMatPstaXs.setString(56, supplyUnitCode);
						insertMatPstaXs.setString(57, supplyUnit);
						insertMatPstaXs.setString(58, parm.get(0));
						insertMatPstaXs.setString(59, parm.get(52));
						insertMatPstaXs.setString(60, processCode);
						insertMatPstaXs.setString(61, processName);
						insertMatPstaXs.addBatch();

						MatZcMEntity matZcMEntity = new MatZcMEntity();
						matZcMEntity.setMatNo((lcode + lotno)
								+ StringTool.formatDecimal(g, "0000"));
						matZcMEntity.setProductFlag(parm.get(44));
						matZcMEntity.setMatStatus(parm.get(45));
						matZcMEntity.setLotNo("");
						matZcMEntity.setStoveNo("");
						matZcMEntity.setJudgeStoveNo(lcode);
						matZcMEntity.setBatchNo(lotno);
						matZcMEntity.setBatchGroudNo(groupNo);
						matZcMEntity.setMaterialNo(materialS[0].toString());
						matZcMEntity.setMaterialName(materialS[1].toString());
						matZcMEntity.setProduccode(parm.get(3));
						matZcMEntity.setProducname(parm.get(4));
						matZcMEntity.setSteelcode(parm.get(5));
						matZcMEntity.setSteelname(parm.get(6));
						matZcMEntity.setGradecode(parm.get(41));
						matZcMEntity.setGradename(parm.get(42));
						matZcMEntity.setSpecCode(parm.get(7));
						matZcMEntity.setSpecName(parm.get(8));
						matZcMEntity.setModelCode(parm.get(9));
						matZcMEntity.setModelDesc(parm.get(10));
						matZcMEntity.setStdCode(parm.get(11));
						matZcMEntity.setStdName(parm.get(12));
						matZcMEntity.setStdStyle(parm.get(15));
						matZcMEntity.setStdStyleDesc(parm.get(16));
						matZcMEntity.setProOrderNo("");
						if (pKList != null) {
							if (arr[2] != null && arr[3] != null
									&& arr[4] != null) {
								matZcMEntity.setOrderNo(parm.get(17));
								matZcMEntity.setOrderSeq(parm.get(18));
								matZcMEntity.setOrderSeqNo(arr[10]);
								matZcMEntity.setOrdPk(arr[2]);
								matZcMEntity.setOrdLnPk(arr[3]);
								matZcMEntity.setOrdLnDlyPk(arr[4]);
							} else {

								matZcMEntity.setOrderNo("");
								matZcMEntity.setOrderSeq("");
								matZcMEntity.setOrderSeqNo("");
								matZcMEntity.setOrdPk("");
								matZcMEntity.setOrdLnPk("");
								matZcMEntity.setOrdLnDlyPk("");

							}
						} else {
							matZcMEntity.setOrderNo("");
							matZcMEntity.setOrderSeq("");
							matZcMEntity.setOrderSeqNo("");
							matZcMEntity.setOrdPk("");
							matZcMEntity.setOrdLnPk("");
							matZcMEntity.setOrdLnDlyPk("");
						}

						matZcMEntity.setPlineCode(parm.get(39));
						matZcMEntity.setPlineName(parm.get(40));
						matZcMEntity.setActDimater(parm.get(20));
						matZcMEntity.setActHeight(parm.get(21));
						if (parm.get(36).equals("")) {
							matZcMEntity.setActLen(Double
									.parseDouble(lengthList.get(acount)));
						} else {
							matZcMEntity.setActLen(0);
						}

						matZcMEntity.setActLenMin(new DecimalFormat("0.00")
								.format(Double.parseDouble(parm.get(22))));
						matZcMEntity.setActLenMax(new DecimalFormat("0.00")
								.format(Double.parseDouble(parm.get(23))));
						matZcMEntity.setActCount("1");
						matZcMEntity.setActWeight(Double
								.parseDouble(new DecimalFormat("0.000")
										.format(conW[1])));
						matZcMEntity.setBelongCode(parm.get(34));
						matZcMEntity.setBelongName(parm.get(35));
						matZcMEntity.setInMold(parm.get(51));
						matZcMEntity.setInstockTime(systime);
						matZcMEntity.setStorageNo(parm.get(32));
						matZcMEntity.setLocationNo(parm.get(33));
						matZcMEntity.setSupplyUnitCode(supplyUnitCode);
						matZcMEntity.setSupplyUnit(supplyUnit);
						matZcMEntity.setCreateTime(systime);

						String insertCrmMatSql = CoreXmlSqlParsersFactory
								.getSql("FrmPipeEnter.insertCrmMat");
						insertCrmMatSql = EntityTool.fillSqlByEntity(
								insertCrmMatSql, matZcMEntity);
						PreparedStatement pstaCrm = connection
								.prepareStatement(insertCrmMatSql);
						pstaCrm.executeUpdate();
						pstaCrm.close();

						insertButressPsta.setString(1, lcode);
						insertButressPsta.setString(2, lotno);
						insertButressPsta.setString(3, groupNo);
						insertButressPsta.setString(4, parm.get(32));
						insertButressPsta.setString(5, parm.get(33));
						insertButressPsta.setString(6, parm.get(46));
						insertButressPsta.setString(7, parm.get(47));
						insertButressPsta.setString(8, parm.get(24));
						insertButressPsta.setString(9, (lcode + lotno)
								+ StringTool.formatDecimal(g, "0000"));
						insertButressPsta.setString(10, systime);
						insertButressPsta.setString(11, parm.get(29));
						insertButressPsta.setString(12, parm.get(30));
						insertButressPsta.setString(13, parm.get(37));
						insertButressPsta.setString(14, parm.get(38));
						insertButressPsta.addBatch();

						insertInListPsta.setString(1, parm.get(29));
						insertInListPsta.setString(2, parm.get(30));
						insertInListPsta.setString(3, inListDoc
								+ StringTool.formatDecimal(n, "0000"));
						insertInListPsta.setString(4, inListDoc);
						insertInListPsta.setString(5, parm.get(31));
						insertInListPsta.setString(6, "产出入库");
						insertInListPsta.setString(7, (lcode + lotno)
								+ StringTool.formatDecimal(g, "0000"));
						insertInListPsta.setString(8, "");
						insertInListPsta.setString(9, "");
						insertInListPsta.setString(10, lcode);
						insertInListPsta.setString(11, lotno);
						insertInListPsta.setString(12, groupNo);
						insertInListPsta.setString(13, parm.get(3));
						insertInListPsta.setString(14, parm.get(4));
						insertInListPsta.setString(15, parm.get(11));
						insertInListPsta.setString(16, parm.get(12));
						insertInListPsta.setString(17, parm.get(5));
						insertInListPsta.setString(18, parm.get(6));
						insertInListPsta.setString(19, parm.get(15));
						insertInListPsta.setString(20, parm.get(16));
						insertInListPsta.setString(21, parm.get(7));
						insertInListPsta.setString(22, parm.get(8));
						insertInListPsta.setString(23, parm.get(9));
						insertInListPsta.setString(24, parm.get(10));

						insertInListPsta.setString(25, parm.get(20));
						insertInListPsta.setString(26, parm.get(21));
						insertInListPsta.setString(27,
								new DecimalFormat("0.00").format(Double
										.parseDouble(parm.get(22))));
						insertInListPsta.setString(28,
								new DecimalFormat("0.00").format(Double
										.parseDouble(parm.get(23))));
						insertInListPsta.setString(29, "1");
						insertInListPsta.setString(30, new DecimalFormat(
								"0.000").format(conW[1]));// 重量
						insertInListPsta.setString(31, "");
						insertInListPsta.setString(32, parm.get(34));
						insertInListPsta.setString(33, parm.get(35));
						insertInListPsta.setString(34, parm.get(32));
						insertInListPsta.setString(35, "");// 备注
						insertInListPsta.setString(36, "1");
						insertInListPsta.setString(37, parm.get(24));
						insertInListPsta.setString(38, systime);

						insertInListPsta.setString(39, parm.get(17));// 合同号
						insertInListPsta.setString(40, parm.get(18));
						
						insertInListPstaXs.setString(1, parm.get(29));
						insertInListPstaXs.setString(2, parm.get(30));
						insertInListPstaXs.setString(3, inListDoc
								+ StringTool.formatDecimal(n, "0000"));
						insertInListPstaXs.setString(4, inListDoc);
						insertInListPstaXs.setString(5, parm.get(31));
						insertInListPstaXs.setString(6, "产出入库");
						insertInListPstaXs.setString(7, (lcode + lotno)
								+ StringTool.formatDecimal(g, "0000"));
						insertInListPstaXs.setString(8, "");
						insertInListPstaXs.setString(9, "");
						insertInListPstaXs.setString(10, lcode);
						insertInListPstaXs.setString(11, lotno);
						insertInListPstaXs.setString(12, groupNo);
						insertInListPstaXs.setString(13, parm.get(3));
						insertInListPstaXs.setString(14, parm.get(4));
						insertInListPstaXs.setString(15, parm.get(11));
						insertInListPstaXs.setString(16, parm.get(12));
						insertInListPstaXs.setString(17, parm.get(5));
						insertInListPstaXs.setString(18, parm.get(6));
						insertInListPstaXs.setString(19, parm.get(15));
						insertInListPstaXs.setString(20, parm.get(16));
						insertInListPstaXs.setString(21, parm.get(7));
						insertInListPstaXs.setString(22, parm.get(8));
						insertInListPstaXs.setString(23, parm.get(9));
						insertInListPstaXs.setString(24, parm.get(10));

						insertInListPstaXs.setString(25, parm.get(20));
						insertInListPstaXs.setString(26, parm.get(21));
						insertInListPstaXs.setString(27,
								new DecimalFormat("0.00").format(Double
										.parseDouble(parm.get(22))));
						insertInListPstaXs.setString(28,
								new DecimalFormat("0.00").format(Double
										.parseDouble(parm.get(23))));
						insertInListPstaXs.setString(29, "1");
						insertInListPstaXs.setString(30, new DecimalFormat(
								"0.000").format(conW[1]));// 重量
						insertInListPstaXs.setString(31, "");
						insertInListPstaXs.setString(32, parm.get(34));
						insertInListPstaXs.setString(33, parm.get(35));
						insertInListPstaXs.setString(34, parm.get(32));
						insertInListPstaXs.setString(35, "");// 备注
						insertInListPstaXs.setString(36, "1");
						insertInListPstaXs.setString(37, parm.get(24));
						insertInListPstaXs.setString(38, systime);

						insertInListPstaXs.setString(39, parm.get(17));// 合同号
						insertInListPstaXs.setString(40, parm.get(18));
						
						if (pKList != null) {
							if (arr[2] != null && arr[3] != null
									&& arr[4] != null) {
								insertInListPsta.setString(41, arr[10]);
								insertInListPsta.setString(42, arr[2]);
								insertInListPsta.setString(43, arr[3]);
								insertInListPsta.setString(44, arr[4]);// 交货行键
								
                                insertInListPstaXs.setString(41, arr[10]);
								insertInListPstaXs.setString(42, arr[2]);
								insertInListPstaXs.setString(43, arr[3]);
								insertInListPstaXs.setString(44, arr[4]);// 交货行键
							} else {
								insertInListPsta.setString(41, parm.get(19));
								insertInListPsta.setString(42, "");
								insertInListPsta.setString(43, "");
								insertInListPsta.setString(44, "");// 交货行键
								
								insertInListPstaXs.setString(41, parm.get(19));
								insertInListPstaXs.setString(42, "");
								insertInListPstaXs.setString(43, "");
								insertInListPstaXs.setString(44, "");// 交货行键
							}
						} else {
							insertInListPsta.setString(41, parm.get(19));
							insertInListPsta.setString(42, "");
							insertInListPsta.setString(43, "");
							insertInListPsta.setString(44, "");// 交货行键
							
							insertInListPstaXs.setString(41, parm.get(19));
							insertInListPstaXs.setString(42, "");
							insertInListPstaXs.setString(43, "");
							insertInListPstaXs.setString(44, "");// 交货行键
						}
						insertInListPsta.setString(45, parm.get(44));
						insertInListPsta.setString(46, parm.get(45));
						insertInListPsta.setString(47, systime);
						insertInListPsta.setString(48, "");
						
						insertInListPstaXs.setString(45, parm.get(44));
						insertInListPstaXs.setString(46, parm.get(45));
						insertInListPstaXs.setString(47, systime);
						insertInListPstaXs.setString(48, "");
						if (!parm.get(36).equals("")) {
							insertInListPsta.setString(49, lengthList
									.get(acount));
							insertInListPstaXs.setString(49, lengthList
									.get(acount));
						} else {
							insertInListPsta.setString(49, "0");
							insertInListPstaXs.setString(49, "0");
						}

						insertInListPsta.setString(50, parm.get(37));
						insertInListPsta.setString(51, parm.get(38));
						insertInListPsta.setString(52, "");
						insertInListPsta.setString(53, parm.get(39));
						insertInListPsta.setString(54, parm.get(40));
						insertInListPsta.setString(55, parm.get(41));
						insertInListPsta.setString(56, parm.get(42));
						insertInListPsta.setString(57, yearMoth);
						insertInListPsta.setString(58, systime);
						
						insertInListPstaXs.setString(50, parm.get(37));
						insertInListPstaXs.setString(51, parm.get(38));
						insertInListPstaXs.setString(52, "");
						insertInListPstaXs.setString(53, parm.get(39));
						insertInListPstaXs.setString(54, parm.get(40));
						insertInListPstaXs.setString(55, parm.get(41));
						insertInListPstaXs.setString(56, parm.get(42));
						insertInListPstaXs.setString(57, yearMoth);
						insertInListPstaXs.setString(58, systime);
						
						if (pKList != null) {
							if (arr[2] != null && arr[3] != null
									&& arr[4] != null) {
								insertInListPsta.setString(59, arr[7]);
								insertInListPsta.setString(60, arr[8]);
								insertInListPsta.setString(61, arr[9]);
								
								insertInListPstaXs.setString(59, arr[7]);
								insertInListPstaXs.setString(60, arr[8]);
								insertInListPstaXs.setString(61, arr[9]);
							} else {
								insertInListPsta.setString(59, "");
								insertInListPsta.setString(60, "");
								insertInListPsta.setString(61, "");
								
								insertInListPstaXs.setString(59, "");
								insertInListPstaXs.setString(60, "");
								insertInListPstaXs.setString(61, "");
							}
						} else {
							insertInListPsta.setString(59, "");
							insertInListPsta.setString(60, "");
							insertInListPsta.setString(61, "");
							
							insertInListPstaXs.setString(59, "");
							insertInListPstaXs.setString(60, "");
							insertInListPstaXs.setString(61, "");
						}
						insertInListPsta.setString(62, parm.get(43));
						insertInListPsta.setString(63, parm.get(48));
						insertInListPsta.setString(64, parm.get(49));
						insertInListPsta.setString(65, parm.get(39));
						insertInListPsta.setString(66, parm.get(40));
						insertInListPsta.setString(67, materialS[0].toString());
						insertInListPsta.setString(68, materialS[1].toString());
						insertInListPsta.setString(69, parm.get(51));
						insertInListPsta.setString(70, supplyUnitCode);
						insertInListPsta.setString(71, supplyUnit);
						insertInListPsta.setString(72, parm.get(52));
						insertInListPsta.setString(73, processCode);
						insertInListPsta.setString(74, processName);
						insertInListPsta.setString(75, parm.get(33));
						insertInListPsta.addBatch();
						
						insertInListPstaXs.setString(62, parm.get(43));
						insertInListPstaXs.setString(63, parm.get(48));
						insertInListPstaXs.setString(64, parm.get(49));
						insertInListPstaXs.setString(65, parm.get(39));
						insertInListPstaXs.setString(66, parm.get(40));
						insertInListPstaXs.setString(67, materialS[0].toString());
						insertInListPstaXs.setString(68, materialS[1].toString());
						insertInListPstaXs.setString(69, parm.get(51));
						insertInListPstaXs.setString(70, supplyUnitCode);
						insertInListPstaXs.setString(71, supplyUnit);
						insertInListPstaXs.setString(72, parm.get(52));
						insertInListPstaXs.setString(73, processCode);
						insertInListPstaXs.setString(74, processName);
						insertInListPstaXs.setString(75, parm.get(33));
						insertInListPstaXs.addBatch();

						matZcMEntity.setInstockDoc(inListDoc);
						matZcMEntity.setInstockSqe(inListDoc
								+ StringTool.formatDecimal(n, "0000"));
						matZcMEntity.setBalYearMonth(yearMoth);
						String insertCrmInListSql = CoreXmlSqlParsersFactory
								.getSql("FrmPipeEnter.insertCrmInList");
						insertCrmInListSql = EntityTool.fillSqlByEntity(
								insertCrmInListSql, matZcMEntity);
						PreparedStatement psCrmInList = connection
								.prepareStatement(insertCrmInListSql);
						psCrmInList.executeUpdate();
						ps.close();

						g++;
						n++;
						acount++;
					}
				}
			}

			updatePlanPsta.setString(1, parm.get(17).toString());
			updatePlanPsta.setString(2, parm.get(18).toString());
			updatePlanPsta.setString(3, parm.get(19).toString());
			updatePlanPsta.setString(4, parm.get(2).toString());
			updatePlanPsta.setString(5, parm.get(17).toString());
			updatePlanPsta.setString(6, parm.get(18).toString());
			updatePlanPsta.setString(7, parm.get(19).toString());
			updatePlanPsta.setString(8, new DecimalFormat("0.000")
					.format(Double.parseDouble(parm.get(27).toString())));
			// updatePlanPsta.setString(9, parm.get(24).toString());
			updatePlanPsta.setString(9, parm.get(17).toString());
			updatePlanPsta.setString(10, parm.get(18).toString());
			updatePlanPsta.setString(11, parm.get(19).toString());
			updatePlanPsta.addBatch();

			updateProcessPsta.setString(1, parm.get(2));
			updateProcessPsta.setString(2, parm.get(27));
			updateProcessPsta.setString(3, parm.get(36));
			if (pKList != null) {
				if (arr[2] != null) {
					updateProcessPsta.setString(4, arr[2]);// 合同行键
				} else {
					updateProcessPsta.setString(4, "");
				}
			} else {
				updateProcessPsta.setString(4, "");
			}
			updateProcessPsta.addBatch();

			insertMatPsta.executeBatch();
			insertMatPstaXs.executeBatch();
			insertButressPsta.executeBatch();
			insertInListPsta.executeBatch();
			insertInListPstaXs.executeBatch();
			updatePlanPsta.executeBatch();
			updateProcessPsta.executeBatch();
			connection.commit();
			cro.setResult(1);
			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 list
	 * @return
	 */
	public CoreReturnObject cancelPipData(ArrayList<String> list) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		Date now = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss");
		SimpleDateFormat df = new SimpleDateFormat("yyyyMM");
		String yearMoth = df.format(now);
		String systime = dateFormat.format(now);
		String inListDoc = list.get(0);
		PreparedStatement psta = null;
		ResultSet rs = null;
		try {
			connection.setAutoCommit(false);
			String deleteMatSql = CoreXmlSqlParsersFactory
					.getSql("cancelPipData.deleteMat");// 删除物料表
			String deleteMatSqlXs = CoreXmlSqlParsersFactory
					.getSql("FrmPipeInventoryOutXs.deleteMatZcMByMatNo");// 删除物料表
			//删除销售库存表
			PreparedStatement deleteMatPsta = connection
					.prepareStatement(deleteMatSql);
			PreparedStatement deleteMatPstaXs = connection
					.prepareStatement(deleteMatSqlXs);
			
			String deleteButressSql = CoreXmlSqlParsersFactory
					.getSql("cancelPipData.deleteButress");// 删除位置表
			PreparedStatement deleteButressPsta = connection
					.prepareStatement(deleteButressSql);
			
			String deleteInListSql = CoreXmlSqlParsersFactory
					.getSql("cancelPipData.deleteInList");// 删除入库表
			PreparedStatement deleteInListPsta = connection
					.prepareStatement(deleteInListSql);
			
			String deleteInListSqlXs = CoreXmlSqlParsersFactory
					.getSql("cancelPipDataXs.deleteInList");// 删除销售入库表
			PreparedStatement deleteInListPstaXs = connection
					.prepareStatement(deleteInListSqlXs);
			
			String updatePlanSql = CoreXmlSqlParsersFactory
					.getSql("cancelPipData.updatePlan");// 修改计划表
			PreparedStatement updatePlanPsta = connection
					.prepareStatement(updatePlanSql);
			String updateProcessSql = CoreXmlSqlParsersFactory
					.getSql("cancelPipData.updateProcess");// 修改进程表
			PreparedStatement updateProcessPsta = connection
					.prepareStatement(updateProcessSql);
			String insertCrmSql = CoreXmlSqlParsersFactory
					.getSql("cancelPipData.deleteCrm");
			PreparedStatement deleteCrmPsta = connection
					.prepareStatement(insertCrmSql);
			String sql4 = CoreXmlSqlParsersFactory
					.getSql("FrmPipeEnter.deleteFmis");// 删除财务系统接口数据
			PreparedStatement deleteFmis = connection.prepareStatement(sql4);

			ArrayList<String> matNoList = new ArrayList<String>();
			ArrayList<String> matNoS = new ArrayList<String>();
			String strSql = CoreXmlSqlParsersFactory
					.getSql("cancelPipData.selectMat");// 查询材料表状态是否改变
			psta = connection.prepareStatement(strSql);
			psta.setString(1, list.get(9));
			psta.setString(2, list.get(10));
			psta.setString(3, list.get(11));
			rs = psta.executeQuery();
			while (rs.next()) {
				matNoS.add(rs.getString("MAT_NO"));
			}
			rs.close();
			psta.close();
			if (matNoS.size() > 0) {
				cro.setV_errMsg("材料状态已改变,不允许撤销!");
				return cro;
			}

			String sql = CoreXmlSqlParsersFactory
					.getSql("cancelPipData.SelectMatNo");// 查询所有材料号
			psta = connection.prepareStatement(sql);
			psta.setString(1, inListDoc);
			psta.setString(2, list.get(9));
			psta.setString(3, list.get(10));
			psta.setString(4, list.get(11));
			rs = psta.executeQuery();
			while (rs.next()) {
				matNoList.add(rs.getString("MAT_NO"));
			}
			rs.close();
			psta.close();

			String SYNC_FLAG = "0";
			sql = CoreXmlSqlParsersFactory
					.getSql("FrmPipeEnter.SelectSyncFlag");// 查询财务系统同步状态
			psta = connection.prepareStatement(sql);
			psta.setObject(1, inListDoc);
			psta.setObject(2, list.get(9));
			psta.setObject(3, list.get(10));
			psta.setObject(4, list.get(11));
			rs = psta.executeQuery();
			if (rs.next()) {
				SYNC_FLAG = rs.getString("SYNC_FLAG");
			}
			rs.close();
			psta.close();
			if (SYNC_FLAG.equals("1")) {
				cro.setV_errMsg("财务系统同步入库信息，请联系财务撤销同步信息!");
				return cro;
			}
			// 删除财务系统接口数据
			deleteFmis.setObject(1, inListDoc);
			deleteFmis.setObject(2, list.get(9));
			deleteFmis.setObject(3, list.get(10));
			deleteFmis.setObject(4, list.get(11));
			deleteFmis.addBatch();
			deleteFmis.executeBatch();

			for (int i = 0; i < matNoList.size(); i++) {
				deleteMatPsta.setString(1, matNoList.get(i));
				deleteMatPsta.addBatch();
				
				deleteMatPstaXs.setString(1, matNoList.get(i));
				deleteMatPstaXs.addBatch();

				deleteButressPsta.setString(1, matNoList.get(i));
				deleteButressPsta.addBatch();

				deleteCrmPsta.setString(1, matNoList.get(i));
				deleteCrmPsta.setString(2, systime);
				deleteCrmPsta.setString(3, systime);
				deleteCrmPsta.addBatch();

				deleteInListPsta.setString(1, matNoList.get(i));
				deleteInListPstaXs.setString(1, matNoList.get(i));
				deleteInListPsta.addBatch();
				deleteInListPstaXs.addBatch();

			}

			updatePlanPsta.setString(1, list.get(1).toString());
			updatePlanPsta.setString(2, list.get(2).toString());
			updatePlanPsta.setString(3, list.get(3).toString());
			updatePlanPsta.setString(4, list.get(5).toString());
			updatePlanPsta.setString(5, list.get(1).toString());
			updatePlanPsta.setString(6, list.get(2).toString());
			updatePlanPsta.setString(7, list.get(3).toString());
			updatePlanPsta.setString(8, new DecimalFormat("0.000")
					.format(Double.parseDouble(list.get(6).toString())));
			// updatePlanPsta.setString(9, list.get(8).toString());
			updatePlanPsta.setString(9, list.get(1).toString());
			updatePlanPsta.setString(10, list.get(2).toString());
			updatePlanPsta.setString(11, list.get(3).toString());
			updatePlanPsta.addBatch();

			updateProcessPsta.setString(1, list.get(5));
			updateProcessPsta.setString(2, list.get(6));
			updateProcessPsta.setString(3, list.get(7));
			updateProcessPsta.setString(4, list.get(4));
			updateProcessPsta.addBatch();

			deleteMatPsta.executeBatch();
			deleteMatPstaXs.executeBatch();
			deleteButressPsta.executeBatch();
			deleteCrmPsta.executeBatch();
			deleteInListPsta.executeBatch();
			deleteInListPstaXs.executeBatch();
			updatePlanPsta.executeBatch();
			updateProcessPsta.executeBatch();
			cro.setResult(1);
			cro.setV_errMsg("撤销成功!");
			connection.commit();
		} catch (Exception e) {
			System.out.println(e.getMessage());
			if (connection != null) {
				try {
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return cro;
	}

	/**
	 * 每支材料对应的入库单号
	 * 
	 * @param conn
	 *            c
	 * @param strlist
	 *            传递参数
	 * @return obj
	 * @throws Exception
	 *             异常处理
	 */
	public String querySendSqlDoc(Connection conn, String strlist, String memo)
			throws Exception {
		int seq = 0;
		String inListDoc = "";
		PreparedStatement psta = null;
		Date dt = new Date();
		SimpleDateFormat matter1 = new SimpleDateFormat("yyyy-MM-dd");
		SimpleDateFormat matter2 = new SimpleDateFormat("yyMMdd");
		String sqlLovsqe = CoreXmlSqlParsersFactory
				.getSql("CorePipeInTemp.getInListDocNew");
		psta = conn.prepareStatement(sqlLovsqe);
		psta.setString(1, memo);
		psta.setString(2, strlist);
		ResultSet rs = psta.executeQuery();
		if (rs.next()) {
			// String res = rs.getString(1);
			// if (res == null) {
			// res = memo + matter2.format(dt) + "00001";
			// }
			// else {
			// seq = Integer.parseInt(res.substring(8, 13));
			// }
			inListDoc = rs.getString("INSTOCK_DOC");
		}
		rs.close();
		psta.close();
		// return memo + matter2.format(dt) + StringTool.formatDecimal(++seq,
		// "00000");
		return inListDoc;
	}

	/**
	 * 根据炉号、批号自动生成材料号
	 * 
	 * @param conn
	 *            c
	 * @param strLcode
	 *            传递参数
	 * @return obj
	 * @throws Exception
	 *             异常处理
	 */
	public String queryMatNoM(Connection conn, String strLcode, String strBatch)
			throws Exception {
		int count = 0;
		String matNo = "";
		PreparedStatement psta = null;
		String sqlLovsqe = CoreXmlSqlParsersFactory
				.getSql("CorePipeInTemp.QueryMatNoM1");
		psta = conn.prepareStatement(sqlLovsqe);
		psta.setString(1, strLcode);
		psta.setString(2, strBatch);
		psta.setString(3, strLcode);
		psta.setString(4, strBatch);
		psta.setString(5, strLcode);
		psta.setString(6, strBatch);
		psta.setString(7, strLcode);
		psta.setString(8, strBatch);
		ResultSet rs = psta.executeQuery();
		if (rs.next()) {
			// String res = rs.getString(1);
			// if (res == null) {
			// res = strLcode + strBatch + "0001";
			// }
			// else {
			// count = Integer.parseInt(res.substring(res.length() - 4, res
			// .length()));
			// }
			matNo = rs.getString("MAT_NO");
		}
		rs.close();
		psta.close();
		// return (strLcode + strBatch)
		// + StringTool.formatDecimal(++count, "0000");
		return matNo;
	}

	/**
	 * 每支材料对应的入库流水号
	 * 
	 * @param conn
	 *            c
	 * @param strlist
	 *            传递参数
	 * @return obj
	 * @throws Exception
	 *             异常处理
	 */
	public String querySendSql(Connection conn, String strlist)
			throws Exception {
		int seq = 0;
		String inListDocSeq = "";
		PreparedStatement psta = null;
		Date dt = new Date();
		SimpleDateFormat matter1 = new SimpleDateFormat("yyyy-MM-dd");
		String sqlLovsqe = CoreXmlSqlParsersFactory
				.getSql("CorePipeInTemp.getInListDoc1");
		psta = conn.prepareStatement(sqlLovsqe);
		psta.setString(1, strlist);
		psta.setString(2, strlist);
		ResultSet rs = psta.executeQuery();
		if (rs.next()) {
			// String res = rs.getString(1);
			// if (res == null) {
			// res = strlist + "0001";
			// }
			// else {
			// seq = Integer.parseInt(res.substring(13, 17));
			// }
			inListDocSeq = rs.getString("INSTOCK_SQE");
		}
		rs.close();
		psta.close();
		// return strlist + StringTool.formatDecimal(++seq, "0000");
		return inListDocSeq;
	}

	/**
	 * 根据炉号、批号自动组号
	 * 
	 * @param conn
	 *            c
	 * @param strLcode
	 *            传递参数
	 * @return obj
	 * @throws Exception
	 *             异常处理
	 */
	public String queryGroupNo(Connection conn, String strLcode, String strBatch)
			throws Exception {
		int count = 0;
		String groupNo = "";
		PreparedStatement psta = null;
		String sqlLovsqe = CoreXmlSqlParsersFactory
				.getSql("CorePipeInTemp.queryGroupNo");
		psta = conn.prepareStatement(sqlLovsqe);
		psta.setString(1, strLcode);
		psta.setString(2, strBatch);
		psta.setString(3, strLcode);
		psta.setString(4, strBatch);
		ResultSet rs = psta.executeQuery();
		if (rs.next()) {
			// String res = rs.getString(1);
			// if (res == null) {
			// res = "001";
			// }
			// else {
			// count = Integer.parseInt(res.substring(res.length() - 3, res
			// .length()));
			// }
			groupNo = rs.getString("BATCH_GROUD_NO");
		}
		rs.close();
		psta.close();
		// return StringTool.formatDecimal(++count, "000");
		return groupNo;
	}

	/***
	 * 获取合同值
	 * 
	 * @param con
	 * @param orderNo
	 * @param orderSeq
	 * @return
	 * @throws SQLException
	 */
	public static List<String[]> getOrderPk(Connection con, String orderNo,
			String orderSeq, String orderDivNo, String[] arr)
			throws SQLException {
		List<String[]> list = new ArrayList<String[]>();
		String sql = CoreXmlSqlParsersFactory.getSql("FrmPipeEnter.getOrderPk");
		//sql += CoreConverter.toSqlConditionString("T2.SALE_AREA_NO", arr);
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, orderNo);
		ps.setObject(2, orderSeq);
		ps.setObject(3, orderDivNo);
		ResultSet rs = ps.executeQuery();
		while (rs.next()) {
			String[] strArray = new String[11];
			strArray[0] = rs.getString("SALE_ORG");
			strArray[1] = rs.getString("SALE_ORG_DESC");
			strArray[2] = rs.getString("ORD_PK");
			strArray[3] = rs.getString("ORD_LN_PK");
			strArray[4] = rs.getString("ORD_LN_DLY_PK");
			strArray[5] = rs.getString("STD_CODE");
			strArray[6] = rs.getString("STD_NAME");
			strArray[7] = rs.getString("LEN_NO");
			strArray[8] = rs.getString("LEN_DESC");
			strArray[9] = rs.getString("LEN_UNIT");
			strArray[10] = rs.getString("DELIVERY_NO");
			list.add(strArray);
		}
		rs.close();
		ps.close();
		if (list == null || list.size() == 0) {
			return null;
		}
		return list;
	}

	/***
	 * 查询合同信息
	 * 
	 * @param orderNo
	 * @return
	 */
	public CoreReturnObject getOrder(String orderNo) {
		return this.getDataBySqlID("FrmPipeEnter.getOrder",
				new Object[] { orderNo });
	}

	/***
	 * 获取合同行信息
	 * 
	 * @return
	 */
	public CoreReturnObject getOrderNo(String orderNo, String orderSeq,
			String divNo) {
		return this.getDataBySqlID("FrmPipeEnter.getOrderNo", new Object[] {
				orderNo, orderSeq, divNo });
	}

	/***
	 * 查询炉批是否结转
	 * 
	 * @param list
	 * @return
	 */
	public CoreReturnObject selectYearMoth(ArrayList<String> list, String[] arr) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmPipeEnter.selectYearMoth");
		sql += CoreConverter.toSqlConditionString("T.BELONG_CODE", arr);
		return this.getData(sql, list.toArray());
	}

	/***
	 * 修改结转年月
	 * 
	 * @param list
	 * @return
	 */
	public CoreReturnObject updateYear(ArrayList<String> list) {
		return this.setDataBySqlID("FrmPipeEnter.updateYear", list.toArray());
	}
}