package com.baosight.sts.st.wl.service;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baosight.iplat4j.common.constant.EPResource;
import com.baosight.iplat4j.core.ei.EiBlock;
import com.baosight.iplat4j.core.ei.EiBlockMeta;
import com.baosight.iplat4j.core.ei.EiColumn;
import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.exception.PlatException;
import com.baosight.iplat4j.core.soa.SoaManager;
import com.baosight.iplat4j.core.threadlocal.UserSession;
import com.baosight.iplat4j.ef.ui.cascade.CascadeSelect;
import com.baosight.iplat4j.ep.util.MethodParamConstants;
import com.baosight.sts.st.wl.domain.STWL030101;
import com.baosight.sts.st.wl.domain.STWL0501;
import com.baosight.sts.st.xt.domain.STXT0902;
import com.baosight.sts.util.BizConstants;
import com.baosight.sts.util.CodeValueUtil;

public class ServiceSTWL0501 extends com.baosight.iplat4j.ee.service.CascadeSelect {

	private CodeValueUtil cvu = new CodeValueUtil();

	public EiInfo initLoad(EiInfo inInfo) {
		StringBuffer buffer = new StringBuffer();
		buffer.append(inInfo.getMsg() == null ? "" : inInfo.getMsg());
		STWL0501 stwl0501 = new STWL0501();
		EiInfo outInfo = super.initLoad(inInfo, stwl0501);
		outInfo.addBlock("result").addRow(stwl0501);
		outInfo.getBlock("result").setBlockMeta(stwl0501.eiMetadata);
		outInfo.addBlock("resultd");
		outInfo.addBlock("resultF");
		outInfo.addBlock("good_id").setRows(null);
		outInfo.addBlock("resultHide").setRows(null);
		outInfo.addBlock("feeType").setRows(null);
		String segNo = (String) UserSession.getInSessionProperty(BizConstants.ORG_ID);
		Map param = new HashMap();
		param.put("segNo", segNo);
		outInfo = CodeValueUtil.procEiInfo(outInfo, "BILL_STATUS", segNo);
		outInfo = CodeValueUtil.procEiInfo(outInfo, "BILL_TYPE", segNo);
		outInfo = CodeValueUtil.procEiInfo(outInfo, "QUALITY_GRADE", segNo);
		outInfo = CodeValueUtil.procEiInfoOther(outInfo, "provider", "providerCode", param);
		outInfo = CodeValueUtil.procEiInfo(outInfo, "FEE_SETTLE_TYPE",segNo);
		outInfo = CodeValueUtil.procEiInfo(outInfo, "FEE_STATUS",segNo);
		outInfo = CodeValueUtil.procEiInfo(outInfo, "FEE_CODE", segNo);
		outInfo = CodeValueUtil.procEiInfo(outInfo, "FEE_SETTLE_TYPE", segNo);
		outInfo = CodeValueUtil.procEiInfo(outInfo, "SETTLE_STYLE", segNo);
		outInfo = CodeValueUtil.procEiInfo(outInfo, "I_SETTLE_TYPE", segNo);
		
		return outInfo;
	}

	// 树节点列表查询方法
	public EiInfo queryEiInfo(List list, Map map) {
		String blockName = list.get(list.size() - 1).toString();
		String segNo = (String) UserSession.getInSessionProperty(BizConstants.ORG_ID);
		int index = list.size() - 1;
		EiInfo info = new EiInfo();
		EiBlockMeta meta = new EiBlockMeta();
		EiColumn eiColumn = null;
		List aa = null;
		int offset = Integer.parseInt(map.get(EiConstant.offsetStr).toString());
		int limit = Integer.parseInt(map.get(EiConstant.limitStr).toString());
		Integer count = null;
		map.put("segNo", segNo);
		if (blockName.equals("inqu_status-0-wproviderOutId")) {// 查询区域的转出仓库树列表
			map.put("providerId", map.get("wproviderOutId"));
			map.put("status", "50");
			aa = dao.query("ST00.provider", map, offset, limit);
			switch (index) {
				case 0 :
					eiColumn = new EiColumn("codeValue");
					eiColumn.setDescName("仓库代码");
					meta.addMeta(eiColumn);
					eiColumn = new EiColumn("codeDesc");
					eiColumn.setDescName("仓库名称");
					meta.addMeta(eiColumn);
					break;
			}
			count = (Integer) (dao.query("ST00.countProvider", map).get(0));
		}
		if (blockName.equals("inqu_status-0-wproviderInId")) {// 查询区域的转入仓库列表
			map.put("providerId", map.get("wproviderInId"));
			map.put("status", "50");
			aa = dao.query("ST00.provider", map, offset, limit);
			switch (0) {
				case 0 :
					eiColumn = new EiColumn("codeValue");
					eiColumn.setDescName("仓库代码");
					meta.addMeta(eiColumn);
					eiColumn = new EiColumn("codeDesc");
					eiColumn.setDescName("仓库名称");
					meta.addMeta(eiColumn);
					break;
			}
			count = (Integer) (dao.query("ST00.countProvider", map).get(0));
		}
		if (blockName.equals("edit_status-0-wproviderOutId")) {// 编辑区域的转出仓库列表
			map.put("providerId", map.get("wproviderOutId"));
			map.put("status", "50");
			aa = dao.query("ST00.provider", map, offset, limit);
			switch (index) {
				case 0 :
					eiColumn = new EiColumn("codeValue");
					eiColumn.setDescName("仓库代码");
					meta.addMeta(eiColumn);
					eiColumn = new EiColumn("codeDesc");
					eiColumn.setDescName("仓库名称");
					meta.addMeta(eiColumn);
					break;
			}
			count = (Integer) (dao.query("ST00.countProvider", map).get(0));
		}
		if (blockName.equals("edit_status-0-wproviderInId")) {// 编辑区域的转入仓库列表
			map.put("providerId", map.get("wproviderInId"));
			map.put("status", "50");
			aa = dao.query("ST00.provider", map, offset, limit);
			switch (index) {
				case 0 :
					eiColumn = new EiColumn("codeValue");
					eiColumn.setDescName("仓库代码");
					meta.addMeta(eiColumn);
					eiColumn = new EiColumn("codeDesc");
					eiColumn.setDescName("仓库名称");
					meta.addMeta(eiColumn);
					break;
			}
			count = (Integer) (dao.query("ST00.countProvider", map).get(0));
		}
		if (blockName.equals("edit_status-0-productId")) {// 编辑区域的资源号列表
			map.put("providerId", map.get("wproviderOutId"));
			aa = dao.query("STWL0501.queryProductId", map, offset, limit);
			switch (0) {
				case 0 :
					eiColumn = new EiColumn("productId");
					eiColumn.setDescName("资源号");
					meta.addMeta(eiColumn);
					eiColumn = new EiColumn("factoryProductId");
					eiColumn.setDescName("钢厂资源号");
					meta.addMeta(eiColumn);
					eiColumn = new EiColumn("providerName");
					eiColumn.setDescName("仓库名称");
					meta.addMeta(eiColumn);
					break;
			}
			count = (Integer) (dao.query("STWL0501.countProduct", map).get(0));
		}
		info.addBlock(blockName);
		EiBlock block = info.getBlock(blockName);
		block.setBlockMeta(meta);
		block.setRows(aa);
		info.set("count", count);
		info.setMsg("查询成功.\n");
		return info;
	}

	// 查询清单
	public EiInfo query(EiInfo inInfo) {
		StringBuffer buffer = new StringBuffer();
		buffer.append(inInfo.getMsg() == null ? "" : inInfo.getMsg());
		STWL0501 stwl0501 = new STWL0501();
		String segNo = (String) UserSession.getInSessionProperty(BizConstants.ORG_ID);
		inInfo.setCell("inqu_status", 0, "segNo", segNo);
		inInfo.setMethodParam(MethodParamConstants.sqlName, "STWL0501.query");
		inInfo.setMethodParam(MethodParamConstants.daoEPBaseBean, stwl0501);
		inInfo.setMethodParam(MethodParamConstants.inDataBlock, "result");
		inInfo.setMethodParam(MethodParamConstants.outDataBlock, "result");
		EiInfo outInfo = super.query(inInfo, true);
		return outInfo;
	}

	// 查询材料库存表捆包明细
	public EiInfo querySBList(EiInfo inInfo) {
		STWL030101 stwl030101 = new STWL030101();
		String segNo = (String) UserSession.getInSessionProperty(BizConstants.ORG_ID);
		inInfo.setCell("inqu_status", 0, "segNo", segNo);
		inInfo.setMethodParam(MethodParamConstants.inDataBlock, "inqu_status");
		inInfo.setBlockInfoValue("inqu_status", EiConstant.limitStr, "1000");
		inInfo.setMethodParam(MethodParamConstants.sqlName, "STWL030101.querySBList");
		inInfo.setMethodParam(MethodParamConstants.daoEPBaseBean, stwl030101);
		inInfo.setMethodParam(MethodParamConstants.outDataBlock, "resultd");
		EiInfo outInfo = super.query(inInfo, true);
		outInfo = CodeValueUtil.procEiInfo(outInfo, "QUALITY_GRADE", segNo);
		return outInfo;
	}

	// 查询转库单明细
	public EiInfo queryList(EiInfo inInfo) {
		String segNo = (String) UserSession.getInSessionProperty(BizConstants.ORG_ID);
		inInfo.setCell("result", 0, "segNo", segNo);
		inInfo.setCell("result", 0, "voucherNum", inInfo.getString("voucherNum"));
		inInfo.addBlock("resultd").setBlockMeta(new STWL030101().eiMetadata);
		List list = dao.query("STWL0501.queryList",inInfo.getBlock("result").getRow(0));
		inInfo.getBlock("resultd").setRows(list);
		inInfo.addBlock("resultF").setBlockMeta(new STXT0902().eiMetadata);
		inInfo.getBlock("resultF").setRows(dao.query("STWL0501.queryFee",inInfo.getBlock("result").getRow(0)));
		inInfo.setMsgByKey(EPResource.EP_2000, new String[]{String.valueOf(list.size())});
		inInfo = CodeValueUtil.procEiInfo(inInfo, "QUALITY_GRADE", segNo);
		
//		//费用明细查询
//		Map map = new HashMap(); 
//		map.put("segNo", segNo);
//		map.put("billId", inInfo.getString("voucherNum"));
//		List rowsF = dao.query("STWL0501.queryFee",map);
//		EiBlock queryBlcokF = inInfo.addBlock("resultF");
//		queryBlcokF.setRows(rowsF);
//		queryBlcokF.addBlockMeta(new STXT0902().eiMetadata);
		
		CodeValueUtil.procEiInfo(inInfo, "FEE_SETTLE_TYPE", segNo);
		CodeValueUtil.procEiInfo(inInfo, "FEE_STATUS", segNo);
//		CodeValueUtil.procEiInfo(inInfo, "FEE_CODE", segNo);
		CodeValueUtil.procEiInfo(inInfo, "FEE_SETTLE_TYPE", segNo);
		CodeValueUtil.procEiInfo(inInfo, "SETTLE_STYLE", segNo);
		CodeValueUtil.procEiInfo(inInfo, "I_SETTLE_TYPE", segNo);
		return inInfo;
	}

	// 捆包类型转换
	public EiInfo change(EiInfo inInfo) {
		EiInfo outInfo = new EiInfo();
		try {
			inInfo.set(EiConstant.serviceName, "STWL0501");
			inInfo.set(EiConstant.methodName, "changeList");
			outInfo = SoaManager.callNewTx(inInfo);
		} catch (Exception e) {
			e.printStackTrace();
			outInfo.set("succeed", "false");
			outInfo.setStatus(-1);
			outInfo.setMsg(e.getMessage().toString());
			return outInfo;
		}
		return outInfo;
	}

	// 捆包类型转换
	public EiInfo changeList(EiInfo inInfo) {
		StringBuffer buffer = new StringBuffer();
		buffer.append(inInfo.getMsg() == null ? "" : inInfo.getMsg());
		EiInfo outInfo = inInfo;
		String segNo = (String) UserSession.getInSessionProperty(BizConstants.ORG_ID);
		String userId = (String) UserSession.getInSessionProperty(BizConstants.USER_ID);
		EiBlock blkResultd;
		try {
			blkResultd = outInfo.getBlock("resultd");
			Map param = new HashMap();
			if (blkResultd != null && blkResultd.getRowCount() > 0) {
				String outResult = "";
				param.put("segNo", segNo);
				param.put("productId", (blkResultd.getRow(0)).get("productId"));
				param.put("packId", (blkResultd.getRow(0)).get("packId"));
				param.put("userId", userId);
				param.put("outResult", "");
				dao.query("STWL0301.packTypeChange", param);
				outResult = String.valueOf(param.get("outResult"));
				if ("1".equals(outResult)) {
					buffer.append("转换成功!\n");
				} else {
					buffer.append("转换失败!!!" + outResult.toString());
					throw new PlatException(buffer.toString());
				}
			}
			outInfo.setMsg(buffer.toString());
			outInfo.set("succeed", "true");
		} catch (Exception e) {
			throw new PlatException(e.getMessage().toString());
		}
		return outInfo;
	}

	// 转库单撤销
	public EiInfo remove(EiInfo inInfo) {
		EiInfo outInfo = new EiInfo();
		try {
			inInfo.set(EiConstant.serviceName, "STWL0501");
			inInfo.set(EiConstant.methodName, "removeList");
			outInfo = SoaManager.callNewTx(inInfo);
		} catch (Exception e) {
			e.printStackTrace();
			outInfo.set("succeed", "false");
			outInfo.setStatus(-1);
			outInfo.setMsg(e.getMessage().toString());
			return outInfo;
		}
		return outInfo;
	}
	public EiInfo removeList(EiInfo inInfo) {
		StringBuffer buffer = new StringBuffer();
		buffer.append(inInfo.getMsg() == null ? "" : inInfo.getMsg());
		EiBlock blkEditSts;
		blkEditSts = inInfo.getBlock("edit_status");
		EiBlock eiBlockF = inInfo.getBlock("resultF");
		String segNo = (String) UserSession.getInSessionProperty(BizConstants.ORG_ID);
		String userId = (String) UserSession.getInSessionProperty(BizConstants.USER_ID);
		String contractId = "";
		try {
			String billId = String.valueOf(blkEditSts.getRow(0).get("billId"));
			Map paraMap = new HashMap();
			paraMap.put("segNo", segNo);
			paraMap.put("billId", billId);
			paraMap.put("userId", userId);
			paraMap.put("out_result", "");
			dao.query("STWL0501.full_bill_cancel", paraMap);
			String out_result = String.valueOf(paraMap.get("out_result"));
			
			//撤销转库单对应的费用
			if (eiBlockF != null && eiBlockF.getRowCount() > 0) {
				for (int k = 0; k < eiBlockF.getRowCount(); k++) {
					Map paramF = eiBlockF.getRow(k);
					if (!String.valueOf(paramF.get("feeStatus")).equals("00")) {
						paramF.put("segNo", segNo);
						paramF.put("userId", userId);
						paramF.put("billId", billId);
						paramF.put("productId", String.valueOf(paramF.get("productId")));
						paramF.put("feeId", String.valueOf(paramF.get("feeId")));
						dao.update("STWL0501.FeeSubRemove", paramF);		
				
			    List list = dao.query("STWL0501.queryContractId", paramF);
			    if (list != null) {
			       contractId = (String) list.get(0);
				}
				Map map = new HashMap();
				map.put("segNo", segNo);
				map.put("outResult", "");
				map.put("contractId", contractId);
				dao.query("STCG0101.refreshContractM", map);
				dao.update("STCG0101.updateTotalFrght", map);
				String result = (String) map.get("outResult");
				if (!"1".equals(result)) {
					throw new PlatException(result);
				}
			}
		}
	}		
			if (!out_result.equals("1")) {
				throw new PlatException("撤销失败!!!" + out_result);
			}
			buffer.append("撤销成功!\n");
			inInfo.set("succeed", "true");
			inInfo.setMsg(buffer.toString());
		} catch (Exception e) {
			e.printStackTrace();
			throw new PlatException(String.valueOf(e.getMessage()));
		}
		return inInfo;
	}
	
	
//	 转库单子项撤销
	public EiInfo removeSub(EiInfo inInfo) {
		EiInfo outInfo = new EiInfo();
		try {
			inInfo.set(EiConstant.serviceName, "STWL0501");
			inInfo.set(EiConstant.methodName, "removeSubList");
			outInfo = SoaManager.callNewTx(inInfo);
		} catch (Exception e) {
			e.printStackTrace();
			outInfo.setStatus(-1);
			outInfo.setMsg(getCause(e));
			return outInfo;
		}
		return outInfo;
	}
	public EiInfo removeSubList(EiInfo inInfo) {
		EiBlock blkEditSts = inInfo.getBlock("edit_status");
		EiBlock eiBlockD = inInfo.getBlock("resultd");
		String segNo = (String) UserSession.getInSessionProperty(BizConstants.ORG_ID);
		String userId = (String) UserSession.getInSessionProperty(BizConstants.USER_ID);
		try {
			String billId = dnvS(blkEditSts.getRow(0).get("billId"));
			//撤销转库单子项
			for (int k = 0,rowCount=eiBlockD.getRowCount(); k < rowCount; k++) {
				Map map = eiBlockD.getRow(k);
				map.put("segNo", segNo);
				map.put("billId", billId);
				map.put("userId", userId);
				map.put("out_result", "");
				dao.query("STWL0501.zk_bill_subcancel", map);
				String out_result = dnvS(map.get("out_result"));	
				if (!out_result.equals("1")) {
					throw new PlatException("子项撤销失败!!!" + out_result);
				}
			}
			inInfo.setMsg("撤销成功!\n");
		} catch (Exception e) {
			throw new PlatException(e);
		}
		return inInfo;
	}
	
	
	
	
	
//	// 保存
//	public EiInfo save(EiInfo inInfo) {
//		EiInfo outInfo = new EiInfo();
//		try {
//			inInfo.set(EiConstant.serviceName, "STWL0501");
//			inInfo.set(EiConstant.methodName, "savList");
//			outInfo = SoaManager.callNewTx(inInfo);
//		} catch (Exception e) {
//			e.printStackTrace();
//			outInfo.set("succeed", "false");
//			outInfo.setStatus(-1);
//			outInfo.setMsg(e.getMessage().toString());
//			return outInfo;
//		}
//		return outInfo;
//	}
	
	public EiInfo save(EiInfo inInfo) {
		EiInfo outInfo = savList(inInfo);
		return outInfo;
	}

	// 保存2
	public EiInfo savList(EiInfo inInfo) {
		StringBuffer buffer = new StringBuffer();
		buffer.append(inInfo.getMsg() == null ? "" : inInfo.getMsg());
		EiBlock blkEditSts;
		EiBlock blkResultd;
		EiBlock blkResultf;
		Map pEditSts = new HashMap();
		Map pPutoutM = new HashMap();
		Map pPutinM = new HashMap();
		Map pBillM = new HashMap();
		Map pBillD = new HashMap();
		blkEditSts = inInfo.getBlock("edit_status");
		blkResultd = inInfo.getBlock("resultd");
		blkResultf = inInfo.getBlock("resultF");
		String segNo = (String) UserSession.getInSessionProperty(BizConstants.ORG_ID);
		String userId = (String) UserSession.getInSessionProperty(BizConstants.USER_ID);

		try {
			// 转库管理明细-编辑区域
			pEditSts = blkEditSts.getRow(0);
			// 根据edit区域的转出仓库代码查询该转出仓库代码是否存在
			String wproviderOutId = pEditSts.get("wproviderOutId").toString();
			Map pProvId = new HashMap();
			pProvId.put("segNo", segNo);
			pProvId.put("providerId", wproviderOutId);
			List list = dao.query("STWL0101.getProvider", pProvId);
			// 如果转出仓库代码不存在则throw
			if (list.size() == 0) {
				buffer.append("您输入的转出仓库代码不正确，请重新选择输入。");
				throw new PlatException(buffer.toString());
			}
			// 查询转入仓库代码是否存在
			String wproviderInId = pEditSts.get("wproviderInId").toString();
			pProvId = new HashMap();
			pProvId.put("segNo", segNo);
			pProvId.put("providerId", wproviderInId);
			List list2 = dao.query("STWL0101.getProvider", pProvId);
			// 如果转入仓库代码不存在则throw
			if (list2.size() == 0) {
				buffer.append("您输入的转入仓库代码不正确，请重新选择输入。");
				throw new PlatException(buffer.toString());
			}
			String putsftId = String.valueOf(pEditSts.get("billId")); //转库单号
			if(!putsftId.equals("")&&!dnvString(pEditSts.get("vehicle")).equals("")){
//				提单主表update
				HashMap mp = new HashMap();
				mp.put("segNo", segNo);
				mp.put("vehicle", dnvString(pEditSts.get("vehicle")));
				mp.put("billId", putsftId);
				dao.update("STWL0501.updateBill", mp);
			}
			if (blkResultd != null && blkResultd.getRowCount() > 0 && (putsftId.equals(null) || putsftId.equals(""))) {//用于转库单子项新增

				Map pSftId = new HashMap();
				// 根据函数生成转库单号
				pSftId.put("outResult", "");
				pSftId.put("segNo", segNo);
				dao.query("STWL0501.getPutShiftId", pSftId);
				putsftId = (String) pSftId.get("outResult");

				

				// 入库单号
				String putinId = "";
				Map pInId = new HashMap();
				// 根据函数生成入库单号
				pInId.put("outResult", "");
				pInId.put("segNo", segNo);
				dao.query("STWL0101.getPutinId", pInId);
				putinId = (String) pInId.get("outResult");

				// 提单主表
				pBillM.put("segNo", segNo);
				pBillM.put("accsetNo", "1");
				pBillM.put("userSegNo", segNo);
				pBillM.put("userId", userId);
				pBillM.put("billId", putsftId);// 转库单号
				pBillM.put("billStatus", "30");// 30已返单
				pBillM.put("billType", "40");// 40转库提单
				pBillM.put("planDate", pEditSts.get("inputDate"));
				pBillM.put("wproviderId", wproviderOutId);// 转出仓库代码
				pBillM.put("wproviderName", pEditSts.get("wproviderName"));
				pBillM.put("createPerson", userId);
				pBillM.put("modiPerson", userId);
				pBillM.put("vehicle", dnvString(pEditSts.get("vehicle")));//车号
				dao.insert("STWL0501.insertBillM", pBillM);

				

				// 入库主表
				pPutinM.put("segNo", segNo);
				pPutinM.put("accsetNo", "1");
				pPutinM.put("userSegNo", segNo);
				pPutinM.put("userId", userId);
				pPutinM.put("putinId", putinId);
				pPutinM.put("putinStatus", "10");
				pPutinM.put("putinType", "30");
				pPutinM.put("wproviderId", wproviderInId);
				pPutinM.put("voucherNum", putsftId);// 转库单号
				pPutinM.put("putinDate", pEditSts.get("inputDate"));
				pPutinM.put("handler", pEditSts.get("HANDLER"));
				pPutinM.put("modiPerson", userId);
				dao.insert("STWL0101.insertPutinM", pPutinM);
				
//				出库单号
				String putoutId = "";
				Map pOutId = new HashMap();
				// 根据函数生成出库单号
				pOutId.put("outResult", "");
				pOutId.put("segNo", segNo);
				dao.query("STWL0301.getPutoutId", pOutId);
				putoutId = (String) pOutId.get("outResult");
				
				//出库主表
				pPutoutM.put("segNo", segNo);
				pPutoutM.put("accsetNo", "1");
				pPutoutM.put("userSegNo", segNo);
				pPutoutM.put("userId", userId);
				pPutoutM.put("putoutId", putoutId);
				pPutoutM.put("putoutStatus", "10");
				pPutoutM.put("putoutDate", pEditSts.get("inputDate"));
				pPutoutM.put("wproviderId", wproviderOutId);
				pPutoutM.put("putoutType", "30");
				pPutoutM.put("voucherNum", putsftId);// 转库单号
				pPutoutM.put("clientId", wproviderInId);// 目的仓库号 - 转入仓库号
				pPutoutM.put("putoutHandler", pEditSts.get("HANDLER"));
				pPutoutM.put("modiPerson", userId);
				dao.insert("STWL030101.insertPutoutM", pPutoutM);

				// 入库单子项
				String inSubId = "";
				// 资源号
				// String productId = "";
				for (int i = 0,rowCount=blkResultd.getRowCount(); i < rowCount; i++) {
					Map pResultd = new HashMap();
					pResultd = blkResultd.getRow(i);
					String productId = String.valueOf(pResultd.get("productId"));// 资源号
					String packId = String.valueOf(pResultd.get("packId"));// 捆包号
					Map qMap = new HashMap();
					qMap.put("segNo", segNo);
					qMap.put("packId", packId);
					qMap.put("productId", productId);
					List list3 = dao.query("STWL0501.queryWprovider", qMap);
					if (list3 != null && list3.size() > 0) {
						String wid = String.valueOf(((Map) list3.get(0)).get("wproviderId"));
						if (!wid.equals(wproviderOutId)) {
							throw new PlatException(productId + "," + packId + ",该捆包已转入" + wid + ",请刷新!");
						}
					} else {
						throw new PlatException("您输入的转出仓库代码不正确，请重新选择输入。");
					}
					String putinWeight = String.valueOf(pResultd.get("putinWeight"));// 在库重量
					String putoutQty = String.valueOf(pResultd.get("putoutQty")); // 转库件数
					String putoutWeight = String.valueOf(pResultd.get("putoutWeight")); // 转库重量
					String factoryProductId = String.valueOf(pResultd.get("factoryProductId")).replaceAll("null", "").trim();
					String outSubId = "";// 查询返回的子项号
					String putoutSubid = "";
					List listOutSub = null;
					Map pSubId = new HashMap();
					Map mapBSid = new HashMap();
					mapBSid.put("segNo", segNo); 
					mapBSid.put("billId", putsftId);
					mapBSid.put("productId", productId);
					List billsubList = dao.query("STWL0501.getBillSubid", mapBSid);
					// 提单子项
					String billSubid = "";
					// 提单子表查到了数据,就update
					if (billsubList != null && billsubList.size() > 0) {
						billSubid = String.valueOf(((Map) billsubList.get(0)).get("billSubid"));
						Map mapBillD = new HashMap();
						mapBillD.put("segNo", segNo);
						mapBillD.put("billId", putsftId);
						mapBillD.put("billSubid", billSubid);
						mapBillD.put("planWeight", putoutWeight);
						mapBillD.put("actWeight", putoutWeight);
						mapBillD.put("planQty", putoutQty);
						mapBillD.put("actQty", putoutQty);
						// 提单子表的update
						dao.update("STWL0501.updateBillSub", mapBillD);
					} else {
						// 提单子表没拿到数据,就insert
						pSubId.put("segNo", segNo);
						pSubId.put("billId", putsftId);
						listOutSub = dao.query("STWL0501.creatBillSubid", pSubId);
						if (listOutSub != null && listOutSub.size() > 0) {
							outSubId = String.valueOf(((Map) listOutSub.get(0)).get("subId"));
							billSubid = putsftId + outSubId;
						}
						// 提单子表insert
						String goodId = String.valueOf(pResultd.get("goodId"));// 货号
						pBillD.put("segNo", segNo);
						pBillD.put("goodSegNo", segNo);
						pBillD.put("billId", putsftId);// 转库单号
						pBillD.put("billSubid", billSubid);// 提单子项号
						pBillD.put("goodId", goodId);
						pBillD.put("productId", productId);
						pBillD.put("factoryProductId", factoryProductId);// 钢厂资源号
						pBillD.put("planWeight", putoutWeight);
						pBillD.put("actWeight", putoutWeight);
						pBillD.put("planQty", putoutQty);
						pBillD.put("actQty", putoutQty);
						pBillD.put("billSubStatus", "30");
						dao.insert("STWL0501.insertBillD", pBillD);
					}
					
					
					

					
					// 出库单子表
					Map pPutoutD = new HashMap();
					Map mapPd = new HashMap();
					mapPd.put("segNo", segNo);
					mapPd.put("putoutId", putoutId);
					mapPd.put("productId", productId);
					List pdList = dao.query("STWL0501.getPutoutSubid", mapPd);
					// 出库单子表查到了数据,就update,否则insert
					if (pdList != null && pdList.size() > 0) {
						putoutSubid = String.valueOf(((Map) pdList.get(0)).get("putoutSubid"));
						pPutoutD.put("putoutId", putoutId);
						pPutoutD.put("putoutSubid", putoutSubid);
						pPutoutD.put("segNo", segNo);
						pPutoutD.put("putoutWeight", putoutWeight); // 出库量（净重）
						pPutoutD.put("grossWeight", putoutWeight); // 毛重 =出库量
						pPutoutD.put("putoutQty", putoutQty); // 件数(出库数量)
						dao.update("STWL030101.updatePutoutDWeight", pPutoutD);
					} else {
						
						// 创建子项编号
						pSubId.put("segNo", segNo);
						pSubId.put("putoutId", putoutId);
						listOutSub = dao.query("STWL0301.getPutoutSubId", pSubId);
						if (listOutSub != null && listOutSub.size() > 0) {
							outSubId = String.valueOf(((Map) listOutSub.get(0)).get("subId"));
							if (outSubId == null || outSubId.equals("") || outSubId.equals("null")) {
								outSubId = "001";
							}
						} else {
							outSubId = "001";
						}
						putoutSubid = putoutId + outSubId;

						// productId = String.valueOf(pResultd.get("productId"));
						String techStandard = String.valueOf(pResultd.get("techStandard"));
						techStandard = techStandard.equals("{}") ? " " : techStandard;
						techStandard = techStandard.equals("null") ? " " : techStandard;
						pPutoutD.put("segNo", segNo);
						// 出库单号
						pPutoutD.put("putoutId", putoutId);
						pPutoutD.put("putoutSubid", putoutSubid);
						pPutoutD.put("voucherSubnum", billSubid);// 提单子项号
						// 资源号
						pPutoutD.put("productId", productId);
						pPutoutD.put("factoryProductId", factoryProductId);
						pPutoutD.put("productTypeId", pResultd.get("productTypeId"));
						pPutoutD.put("producingAreaCode", pResultd.get("producingAreaCode"));
						pPutoutD.put("techStandard", techStandard); // 技术标准
						pPutoutD.put("shopsign", pResultd.get("shopsign")); // 牌号
						pPutoutD.put("qualityGrade", pResultd.get("qualityGrade")); // 质量等级
						pPutoutD.put("spec", pResultd.get("spec")); // 规格
						pPutoutD.put("putoutWeight", putoutWeight); // 出库量（净重）
						pPutoutD.put("grossWeight", putoutWeight); // 毛重 =出库量
						pPutoutD.put("putoutQty", putoutQty); // 件数(出库数量)
						pPutoutD.put("modiPerson", userId); // 更新人
						dao.insert("STWL030101.insertPutoutD", pPutoutD);
					}
					String packType = String.valueOf(pResultd.get("packType"));// 捆包类型
					String packT;
					if (packType.equals("实捆包")) {
						packT = "1";
					} else {
						packT = "0";
					}
					// 如果捆包类型为虚捆包
					if (packT.equals("0")) {
						// 在库重量
						BigDecimal tPutinW = new BigDecimal(putinWeight);
						// 出库重量
						BigDecimal tPutoutW = new BigDecimal(putoutWeight);
						// 如果在库重量大于本次出库重量 tPutinW - tPutoutW > 0 (未出完,需拆包)
						if (tPutinW.subtract(tPutoutW).doubleValue() > 0) {
							String outPackId = "";
							String outResult = "";
							Map pSplit = new HashMap();
							pSplit.put("segNo", segNo);
							pSplit.put("productId", productId);
							pSplit.put("packId", packId);
							pSplit.put("splitWeight", tPutoutW.doubleValue());
							pSplit.put("splitQty", Integer.valueOf(putoutQty).intValue());
							pSplit.put("userId", userId);
							pSplit.put("outPackId", "");
							pSplit.put("outResult", "");
							dao.query("STWL0301.packSplitChange", pSplit);
							outPackId = String.valueOf(pSplit.get("outPackId"));
							outResult = String.valueOf(pSplit.get("outResult"));
							if ("1".equals(outResult)) {
								packId = outPackId;
							} else {
								buffer.append("保存失败!" + outResult + "\n");
								throw new PlatException(buffer.toString());
							}
						}
					}
					// 校验捆包状态是否为自由
					Map pPack = new HashMap();
					pPack.put("segNo", segNo);
					pPack.put("packId", packId);
					List listStatus = dao.query("STWL0501.checkPackStatus", pPack);
					if (listStatus.size() == 0) {
						buffer.append("资源号为:" + productId + ",捆包号为:" + packId + ",非自由状态。转库失败!\n");
						throw new PlatException(buffer.toString());
					}

					// 出库捆包表
					Map pPpack = new HashMap();
					pPpack.put("segNo", segNo);
					pPpack.put("putoutId", putoutId);
					pPpack.put("putoutSubid", putoutSubid);
					pPpack.put("productId", productId);
					pPpack.put("factoryProductId", factoryProductId);
					pPpack.put("productTypeId", pResultd.get("productTypeId"));
					pPpack.put("putoutWeight", putoutWeight);
					pPpack.put("grossWeight", putoutWeight);
					pPpack.put("putoutQty", putoutQty);
					pPpack.put("modiPerson", userId);
					pPpack.put("putinId", pResultd.get("putinId"));
					pPpack.put("packId", packId);
					pPpack.put("status", "10");
					pPpack.put("actPutoutDate", pEditSts.get("inputDate"));
					pPpack.put("packLocation", String.valueOf(pResultd.get("packLocation")));
					pPpack.put("packType", packT);
					dao.insert("STWL030101.insertPutoutPack", pPpack);

					// PROC_RES_PUTOUT
					Map pResPutout = new HashMap();
					pResPutout.put("segNo", segNo);
					pResPutout.put("putoutId", putoutId);
					pResPutout.put("putoutSubid", putoutSubid);
					pResPutout.put("providerId", wproviderOutId);
					pResPutout.put("packId", packId);
					pResPutout.put("putoutWeight", Double.parseDouble(putoutWeight));
					pResPutout.put("userId", userId);
					pResPutout.put("out_result", "");
					dao.query("STWL0301.PROC_RES_TRANS_PUTOUT", pResPutout);
					String out_result = String.valueOf(pResPutout.get("out_result"));
					if (!"1".equals(out_result)) {
						buffer.append("保存失败!!!" + out_result.toString() + "\n");
						throw new PlatException(buffer.toString());
					}

					// 入库单子项
					pSubId = new HashMap();
					String putinSubid = "";
					// 根据入库单号去查询子项编号
					pSubId.put("segNo", segNo);
					pSubId.put("putinId", putinId);
					List listInSub = dao.query("STWL0101.getPutinSubId", pSubId);
					if (listInSub.size() > 0) {
						if (inSubId != null && !inSubId.equals("") && !inSubId.equals("null")) {
							inSubId = String.valueOf(((Map) listInSub.get(0)).get("subId"));
						} else {
							inSubId = "001";
						}
					} else {
						inSubId = "001";
					}
					putinSubid = putinId + inSubId;

					// 入库子表
					Map pPutinD = new HashMap();
					pPutinD.put("segNo", segNo);
					pPutinD.put("putinId", putinId);
					pPutinD.put("putinSubid", putinSubid);
					pPutinD.put("voucherSubnum", billSubid);// 提单子项号
					pPutinD.put("productId", productId);
					pPutinD.put("factoryProductId", factoryProductId);
					pPutinD.put("packType", packT);// 捆包类型
					pPutinD.put("packId", packId);// 捆包号
					pPutinD.put("location", String.valueOf(pResultd.get("packLocation")));
					pPutinD.put("putinWeight", putoutWeight);
					pPutinD.put("grossWeight", putoutWeight);
					pPutinD.put("putinQty", putoutQty);
					pPutinD.put("productTypeId", String.valueOf(pResultd.get("productTypeId")));
					pPutinD.put("producingAreaCode", String.valueOf(pResultd.get("producingAreaCode")));
					pPutinD.put("techStandard", String.valueOf(pResultd.get("techStandard")));
					pPutinD.put("shopsign", String.valueOf(pResultd.get("shopsign")));
					pPutinD.put("qualityGrade", String.valueOf(pResultd.get("qualityGrade")));
					pPutinD.put("spec", String.valueOf(pResultd.get("spec")));
					pPutinD.put("teleologyFlag", dnvString(pResultd.get("teleologyFlag")));//卷去向
					pPutinD.put("modiPerson", userId);
					pPutinD.put("status", "10");
					pPutinD.put("memo", String.valueOf(pResultd.get("memo")));
					dao.insert("STWL0101.insertPutinD", pPutinD);

					// 更新材料库存表
					Map pSBale = new HashMap();
					pSBale.put("segNo", segNo);
					pSBale.put("packId", packId);
					pSBale.put("productId", pResultd.get("productId"));
					pSBale.put("wproviderId", pEditSts.get("wproviderInId"));// 转入仓库
					pSBale.put("putinDate", pEditSts.get("inputDate"));// 最近入库日期
					pSBale.put("putoutDate", pEditSts.get("inputDate"));// 最近出库日期
					pSBale.put("teleologyFlag", dnvString(pResultd.get("teleologyFlag")));// 卷去向
					pSBale.put("putinId", putinId);// 最近入库单号
					pSBale.put("putoutId", putoutId);// 最近出库单号
					pSBale.put("transforReason", putsftId);// 转库单号
					pSBale.put("modiPerson", userId); // 更新人
					pSBale.put("remark", "库存转库;"); // 备注
					pSBale.put("packLocation", String.valueOf(pResultd.get("packLocation")));
					dao.update("STWL030101.updateStockBale", pSBale);

					// PROC_RES_PUTIN
					Map pResPutin = new HashMap();
					pResPutin.put("segNo", segNo);
					pResPutin.put("productId", productId);
					pResPutin.put("packId", packId);
					pResPutin.put("providerId", pEditSts.get("wproviderInId").toString());
					pResPutin.put("putinType", "30");
					pResPutin.put("putinWeight", Double.parseDouble(putoutWeight));
					pResPutin.put("putinQty", Double.parseDouble(putoutQty));
					pResPutin.put("userId", userId);
					pResPutin.put("out_result", "");
					dao.query("STWL0101.PROC_RES_PUTIN", pResPutin);
					out_result = String.valueOf(pResPutin.get("out_result"));
					if (!"1".equals(out_result)) {
						buffer.append("保存失败!!!" + out_result.toString() + "\n");
						throw new PlatException(buffer.toString());
					}
				}	
			}
			//如果已生成转库单的话则更新库位
			else{
				for (int i = 0,rowCount=blkResultd.getRowCount(); i < rowCount; i++) {
					Map pResultd = new HashMap();
					pResultd = blkResultd.getRow(i);
					pResultd.put("segNo",segNo);
					dao.update("STWL0501.updatePutInD",pResultd);
					dao.update("STWL0501.updateStockBale",pResultd);
				}
			}
			
			
			//新增费用明细
			if (blkResultf != null && blkResultf.getRowCount() > 0){
				// 清空转库单下所有未撤销的费用
				Map feeDele = new HashMap();
				feeDele.put("putsftId", putsftId);
				feeDele.put("segNo", segNo);
				dao.update("STWL0501.contractFeeDelete", feeDele);
				for(int i = 0; i < blkResultf.getRowCount(); i++){
					Map mapfee =  blkResultf.getRow(i);
					mapfee.put("segNo", segNo);
					mapfee.put("productId", mapfee.get("productId"));
					mapfee.put("feeCode", mapfee.get("feeCode"));
					mapfee.put("feeTypeCode", mapfee.get("feeTypeCode"));
					mapfee.put("putsftId", putsftId);
					mapfee.put("feeFrom", "20");
				
					if(!String.valueOf(mapfee.get("feeStatus")).equals("00")){ //非撤销状态的费用
						List feeList = dao.query("STWL0501.FEE_TYPE_CODE", mapfee);
						if(feeList != null && feeList.size() == 1){
							mapfee.put("feeTypeName", ((Map)feeList.get(0)).get("feeTypeName"));
							mapfee.put("feeName", ((Map)feeList.get(0)).get("feeName"));
							mapfee.put("taxRate", ((Map)feeList.get(0)).get("taxRate"));
						}else {
							throw new PlatException("费用明细第"+(i+1)+"行:\n费用大类代码:"+mapfee.get("feeCode")+",\n费用类别代码:"+mapfee.get("feeTypeCode")+",\n费用类别名称:"+mapfee.get("feeTypeName")+",\n输入有误,请重新输入.");
						}
						
						List contractList = dao.query("STWL0501.contractList", mapfee);
						mapfee.put("contractId", ((Map)contractList.get(0)).get("contractId"));
						mapfee.put("contractSubid", ((Map)contractList.get(0)).get("contractSubid"));
						String contractSubid = (String.valueOf(mapfee.get("contractSubid")));
						String subid = contractSubid.substring(10);
						
						Integer count = null;
						count = (Integer) (dao.query("STWL0501.countFee", mapfee).get(0)); //相同采购合同子项对应相同费用名称的条数
						if(count == 0){ //新增费用
							String feeId = "";
							feeId = String.valueOf(dao.query("STCG0101.queryfeeId", mapfee).get(0));
							mapfee.put("feeId", feeId+subid);
							mapfee.put("fee_status", mapfee.get("feeStatus"));
							mapfee.put("contractType", "10");
							mapfee.put("createPerson", userId);
							mapfee.put("createDate", "true");
							mapfee.put("modifyPerson", userId);
							mapfee.put("modifyDate", "true");
							
							double feeQtyd = Double.parseDouble(String.valueOf(mapfee.get("feeQty"))); //费用重量
							double feeAmountd =  Double.parseDouble(String.valueOf(mapfee.get("feeAmountAt"))) / 1.17;
							BigDecimal feeAmount = new BigDecimal(feeAmountd).setScale(2, BigDecimal.ROUND_HALF_UP); //费用金额（不含税）
							double actAmountd = Double.parseDouble(String.valueOf(mapfee.get("actAmountAt"))) / 1.17;
							BigDecimal actAmount = new BigDecimal(actAmountd).setScale(2, BigDecimal.ROUND_HALF_UP); //实际金额（不含税）
							BigDecimal feePrice = new BigDecimal(feeAmountd / feeQtyd ).setScale(6, BigDecimal.ROUND_HALF_UP); //费用单价（不含税）
							BigDecimal actPrice = new BigDecimal(actAmountd / feeQtyd ).setScale(6, BigDecimal.ROUND_HALF_UP); //实际单价（不含税）
							
							mapfee.put("feePrice",feePrice );
							mapfee.put("feeAmount",feeAmount );
							mapfee.put("actPrice",actPrice );
							mapfee.put("actAmount",actAmount );						
							dao.insert("STCG0101.contractFeeInsert", mapfee);
						}else if(count == 1){ //更新费用
							List feeL = dao.query("STWL0501.queryFeeExist", mapfee);
							HashMap feeUpdate = (HashMap)feeL.get(0);
							double feeQtyd = Double.parseDouble(String.valueOf(mapfee.get("feeQty"))) + Double.parseDouble(String.valueOf(feeUpdate.get("feeQty")));
							BigDecimal feeQty = new BigDecimal(feeQtyd).setScale(2, BigDecimal.ROUND_HALF_UP); //费用重量
							double feeAmountAtd = Double.parseDouble(String.valueOf(mapfee.get("feeAmountAt"))) + Double.parseDouble(String.valueOf(feeUpdate.get("feeAmountAt")));
							BigDecimal feeAmountAt = new BigDecimal(feeAmountAtd).setScale(2, BigDecimal.ROUND_HALF_UP); //费用金额(含税)
							double actAmountAtd = Double.parseDouble(String.valueOf(mapfee.get("actAmountAt"))) + Double.parseDouble(String.valueOf(feeUpdate.get("actAmountAt")));
							BigDecimal actAmountAt = new BigDecimal(actAmountAtd).setScale(2, BigDecimal.ROUND_HALF_UP); //实际金额（含税）
							BigDecimal feePriceAt = new BigDecimal(feeAmountAtd/feeQtyd).setScale(6, BigDecimal.ROUND_HALF_UP); //费用单价（含税）
							BigDecimal actPriceAt = new BigDecimal(actAmountAtd/feeQtyd).setScale(6, BigDecimal.ROUND_HALF_UP); //实际单价（含税）
							double feeAmountd = feeAmountAtd / 1.17;
							BigDecimal feeAmount = new BigDecimal(feeAmountd).setScale(2, BigDecimal.ROUND_HALF_UP); //费用金额（不含税）
							double actAmountd = actAmountAtd / 1.17;
							BigDecimal actAmount = new BigDecimal(actAmountd).setScale(2, BigDecimal.ROUND_HALF_UP); //实际金额（不含税）
							BigDecimal feePrice = new BigDecimal(feeAmountAtd / (feeQtyd * 1.17)).setScale(6, BigDecimal.ROUND_HALF_UP); //费用单价（不含税）
							BigDecimal actPrice = new BigDecimal(actAmountAtd / (feeQtyd * 1.17)).setScale(6, BigDecimal.ROUND_HALF_UP); //实际单价（不含税）
							feeUpdate.put("feeQty", feeQty);
							feeUpdate.put("feeAmountAt", feeAmountAt);
							feeUpdate.put("actAmountAt", actAmountAt);
							feeUpdate.put("feePriceAt", feePriceAt);
							feeUpdate.put("actPriceAt", actPriceAt);
							feeUpdate.put("feeAmount", feeAmount);
							feeUpdate.put("actAmount", actAmount);
							feeUpdate.put("feePrice", feePrice);
							feeUpdate.put("actPrice", actPrice);
							feeUpdate.put("userId", userId);
							feeUpdate.put("putsftId", putsftId);
							feeUpdate.put("contractType", "10");
							dao.update("STWL0501.updateFee", feeUpdate);
							
						}else {
							buffer.append("相同转库资源存在2条或2条以上相同费用!");
							throw new PlatException(buffer.toString());
						}
					}

				}
			}
		} catch (Exception e) {
			throw new PlatException(String.valueOf(e.getMessage()));
		}
		buffer.append("保存成功!\n");
		inInfo.set("succeed", "true");
		inInfo.setMsg(buffer.toString());
		return inInfo;
	}
	
	// 费用子项delete
	public EiInfo FeeDelete(EiInfo inInfo) {
		EiInfo outInfo = new EiInfo();
		try {
			inInfo.set(EiConstant.serviceName, "STWL0501");
			inInfo.set(EiConstant.methodName, "FeeDeleteReal");
			outInfo = SoaManager.callNewTx(inInfo);
			outInfo.setMsg("删除成功!");
		} catch (RuntimeException e) {
			e.printStackTrace();
			outInfo.setStatus(-1);
			outInfo.setMsg("删除失败!原因:\n" + e.getMessage());
		}

		return outInfo;
	}
	public EiInfo FeeDeleteReal(EiInfo inInfo) {
		EiBlock blkEditSts;
		blkEditSts = inInfo.getBlock("edit_status");
		String segNo = String.valueOf(UserSession.getInSessionProperty(BizConstants.ORG_ID));
		String userId = String.valueOf(UserSession.getInSessionProperty(BizConstants.USER_ID));
		String contractId = "";
		try {
			String billId = String.valueOf(blkEditSts.getRow(0).get("billId"));
			EiBlock eiBlockF = inInfo.getBlock("resultF");
			if (eiBlockF != null && eiBlockF.getRowCount() > 0) {
				for (int k = 0; k < eiBlockF.getRowCount(); k++) {
					Map paramF = eiBlockF.getRow(k);
					if (!String.valueOf(paramF.get("feeStatus")).equals("00")) {
						paramF.put("segNo", segNo);
						paramF.put("userId", userId);
						paramF.put("billId", billId);
						paramF.put("productId", String.valueOf(paramF.get("productId")));
						paramF.put("feeId", String.valueOf(paramF.get("feeId")));
						dao.update("STWL0501.FeeSubRemove", paramF);
					}
				
			    List list = dao.query("STWL0501.queryContractId", paramF);
			    if (list != null) {
			    	contractId = (String) list.get(0);
				}
				Map map = new HashMap();
				map.put("segNo", segNo);
				map.put("outResult", "");
				map.put("contractId", contractId);
				dao.query("STCG0101.refreshContractM", map);
				dao.update("STCG0101.updateTotalFrght", map);
				String result = (String) map.get("outResult");
				if (!"1".equals(result)) {
					throw new PlatException(result);
				}
			}
			}
		} catch (Exception e) {
			e.printStackTrace();
			throw new PlatException(String.valueOf(e.getMessage()));
		}
		return inInfo;
	}
	
	public EiInfo queryProductIdGoodId(EiInfo inInfo) {
		String segNo = String.valueOf(UserSession.getInSessionProperty(BizConstants.ORG_ID));
		inInfo.setCell("good_inqu_status", 0, "segNo", segNo);
		String specs = inInfo.getCellStr("good_inqu_status", 0, "spec");
		if (specs != null && !specs.trim().equals("")) {
			String spec[] = specs.replaceAll("'", "").replaceAll("%", "").split(",");
			String strsql = " (spec like '%" + spec[0] + "%'";
			for (int i = 1; i < spec.length; i++) {
				strsql += " or spec like '%" + spec[i] + "%'";
			}
			strsql += ")";
			inInfo.setCell("good_inqu_status", 0, "spec", strsql);
		}
		String shopsigns = inInfo.getCellStr("good_inqu_status", 0, "shopsign");
		if (shopsigns != null && !shopsigns.trim().equals("")) {
			String shopsign[] = shopsigns.replaceAll("'", "").replaceAll("%", "").split(",");
			String strsql = " (shopsign like '%" + shopsign[0] + "%'";
			for (int i = 1; i < shopsign.length; i++) {
				strsql += " or shopsign like '%" + shopsign[i] + "%'";
			}
			strsql += ")";
			inInfo.setCell("good_inqu_status", 0, "shopsign", strsql);
		}
		// if(shopsigns != null && !shopsigns.trim().equals("")){
		// String shopsign[] = shopsigns.replaceAll("'", "").replaceAll("%", "").split(",");
		// inInfo.setCell("good_inqu_status", 0, "shopsign", shopsign);
		// }
		inInfo.setCell("good_inqu_status", 0, "providerId", inInfo.getString("edit_status-0-wproviderOutId"));
		inInfo.setCell("good_inqu_status", 0, "productId", inInfo.getString("edit_status-0-productId"));
		inInfo.setMethodParam(MethodParamConstants.sqlName, "STWL0501.queryProductIdGoodId");
		inInfo.setMethodParam(MethodParamConstants.eiBlockMeta, initMetaData());
		inInfo.setMethodParam(MethodParamConstants.queryBlock, "good_inqu_status");
		inInfo.setMethodParam(MethodParamConstants.inDataBlock, "good_id");
		inInfo.setMethodParam(MethodParamConstants.outDataBlock, "good_id");
		EiInfo outInfo = super.query(inInfo, true);
		return outInfo;
	}

	public EiBlockMeta initMetaData() {
		EiColumn eiColumn;
		EiBlockMeta eiMetadata = new EiBlockMeta();

		eiColumn = new EiColumn("productId");
		eiColumn.setFieldLength(30);
		eiColumn.setWidth(110);
		eiColumn.setDescName("资源号");
		eiMetadata.addMeta(eiColumn);

		eiColumn = new EiColumn("factoryProductId");
		eiColumn.setFieldLength(30);
		eiColumn.setDescName("钢厂资源号");
		eiMetadata.addMeta(eiColumn);

		eiColumn = new EiColumn("prodTypeDesc");
		eiColumn.setFieldLength(20);
		eiColumn.setDescName("品种名称");
		eiMetadata.addMeta(eiColumn);

		eiColumn = new EiColumn("shopsign");
		eiColumn.setFieldLength(20);
		eiColumn.setDescName("牌号");
		eiMetadata.addMeta(eiColumn);

		eiColumn = new EiColumn("spec");
		eiColumn.setFieldLength(20);
		eiColumn.setDescName("规格");
		eiMetadata.addMeta(eiColumn);

		eiColumn = new EiColumn("producingAreaName");
		eiColumn.setFieldLength(50);
		eiColumn.setDescName("产地名称");
		eiMetadata.addMeta(eiColumn);

		eiColumn = new EiColumn("providerName");
		eiColumn.setFieldLength(50);
		eiColumn.setDescName("仓库");
		eiMetadata.addMeta(eiColumn);

		eiColumn = new EiColumn("goodId");
		eiColumn.setFieldLength(30);
		eiColumn.setDescName("货号");
		eiMetadata.addMeta(eiColumn);
		
		eiColumn = new EiColumn("memo");
		eiColumn.setFieldLength(200);	
		eiColumn.setDescName("入库单备注");
		eiMetadata.addMeta(eiColumn);
		return eiMetadata;
	}
}