package com.cim.idm.service.Impl;

import com.alibaba.fastjson.JSON;
import com.cim.idm.dao.FgStockInDao;
import com.cim.idm.dao.ToSapDao;
import com.cim.idm.exception.GlobalException;
import com.cim.idm.framework.IDMFrameServiceProxy;
import com.cim.idm.framework.data.EventInfo;
import com.cim.idm.framework.util.time.TimeStampUtil;
import com.cim.idm.model.ToSAPFgStockInDto;
import com.cim.idm.service.FGStockInService;
import com.cim.idm.service.impl.ToSAPServiceImpl;
import com.cim.idm.utils.CommonUtils;
import com.cim.idm.utils.EventInfoUtil;
import com.cim.idm.utils.MapUtils;
import com.cim.idm.wmsextend.generic.GenericServiceProxy;
import com.cim.idm.wmsextend.generic.errorHandler.CustomException;
import com.cim.idm.wmspackage.material.MaterialServiceProxy;
import com.cim.idm.wmspackage.material.management.data.MaterialSpec;
import com.cim.idm.wmspackage.material.management.data.MaterialSpecKey;
import com.cim.idm.wmspackage.materialpacking.MaterialPackingServiceProxy;
import com.cim.idm.wmspackage.materialpacking.management.data.MaterialPacking;
import com.cim.idm.wmspackage.materialpacking.management.data.MaterialPackingKey;
import com.cim.idm.wmspackage.materialpacking.management.info.CreateInfo;
import com.cim.idm.wmspackage.materialpacking.management.info.SetEventInfo;
import com.cim.idm.wmspackage.materialreceiverequestact.MaterialReceiveRequestActServiceProxy;
import com.cim.idm.wmspackage.materialreceiverequestact.management.info.CreateReceiveRequestBatchInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.xml.sax.SAXException;

import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.math.BigDecimal;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ProductIntoServiceImpl implements FGStockInService {

	@Autowired
	private ToSAPServiceImpl toSAPService;

	@Autowired
	private FgStockInDao fgStockInDao;

	@Autowired
	private ToSapDao toSapDao;

	CommonUtils untils=new CommonUtils();

	/**
	 *
	 * @param eventInfo
	 * @param siteName
	 * @param receiveRequestName
	 * @param ReceiveRequestDetailName
	 * @param makeDate
	 * @param receiveActNo
	 * @param actType
	 * @param receiveQuantity
	 * @param subMaterialSpecName
	 * @throws CustomException
	 * @throws ParseException
	 */
	public void CreateMaterialReceiveRequestAct(EventInfo eventInfo,
			String siteName, String receiveRequestName,
			String ReceiveRequestDetailName, String makeDate,
			String receiveActNo, String actType, String receiveQuantity,
			String subMaterialSpecName) throws CustomException, ParseException {
		String actType1 = "";


		String sql1 = "SELECT * FROM materialreceiveact "
				+ "WHERE sitename = :sitename AND receiveRequestName = :receiveRequestName  and receiveActNo=:receiveActNo ";

		Map<String, Object> bindMap1 = new HashMap<String, Object>();
		bindMap1.put("sitename", siteName);
		bindMap1.put("receiveRequestName", receiveRequestName);
		bindMap1.put("receiveActNo", receiveActNo);

		List<Map<String, Object>> queryResult1 = IDMFrameServiceProxy
				.getSqlTemplate()
				.queryForList(sql1, bindMap1);
		if (queryResult1.size() != 0) {
			actType1 = queryResult1.get(0).get("ACTTYPE").toString();
		}
		if (queryResult1.size() == 0) {
			CreateReceiveRequestBatchInfo createActBatchInfo = new CreateReceiveRequestBatchInfo();
			List<CreateReceiveRequestBatchInfo> createReceiveRequestBatchInfo = new ArrayList<CreateReceiveRequestBatchInfo>();

			Map<String, Object> bindMap2 = new HashMap<String, Object>();


			createActBatchInfo.setSiteName(siteName);
			createActBatchInfo.setReceiveRequestName(receiveRequestName);
			createActBatchInfo.setReceiveactNO(receiveActNo);
			createActBatchInfo.setReceiveActState("Created");

			bindMap2.put("actType", actType);
			// bindMap2.put("receiveActState", );
			createActBatchInfo.setUserColumns(bindMap2);

			createReceiveRequestBatchInfo.add(createActBatchInfo);

			MaterialReceiveRequestActServiceProxy
					.getReceiveRequestBatchService().create(eventInfo,
							createReceiveRequestBatchInfo);
		}
		//float型计算精度缺失问题
		Map<String, Object> bindMapF = new HashMap<String, Object>();
		Map<String, Object> bindMapFU = new HashMap<String, Object>();
		String receivedQuantiryF="";
		bindMapF.put("receiveRequestName",receiveRequestName);
		bindMapF.put("ReceiveRequestDetailName", ReceiveRequestDetailName);
		bindMapF.put("sitename", siteName);
		String sqlF="SELECT  RECEIVEDQUANTITY FROM MATERIALRECEIVEREQUESTDETAIL WHERE SITENAME=:sitename AND RECEIVEREQUESTNAME=:receiveRequestName AND RECEIVEREQUESTDETAILNAME=:ReceiveRequestDetailName";
		String sqlFU="UPDATE MATERIALRECEIVEREQUESTDETAIL SET RECEIVEDQUANTITY=:receivedQuantity WHERE SITENAME=:sitename AND RECEIVEREQUESTNAME=:receiveRequestName AND RECEIVEREQUESTDETAILNAME=:ReceiveRequestDetailName";
		List<Map<String, Object>> queryResultF = IDMFrameServiceProxy.getSqlTemplate().queryForList(sqlF, bindMapF);
		if(queryResultF.size()!=0){
			 receivedQuantiryF=queryResultF.get(0).get("RECEIVEDQUANTITY").toString();
		}
		BigDecimal receivequantity=new BigDecimal(String.valueOf(receiveQuantity));
		BigDecimal receivedQuantiry=new BigDecimal(receivedQuantiryF);
		bindMapFU.put("receivedQuantity", receivequantity.add(receivedQuantiry).doubleValue());
		bindMapFU.put("sitename", siteName);
		bindMapFU.put("receiveRequestName", receiveRequestName);
		bindMapFU.put("ReceiveRequestDetailName", ReceiveRequestDetailName);
		IDMFrameServiceProxy.getSqlTemplate().update(sqlFU, bindMapFU);
	}
	

	@Transactional
	public void fgStockInNew (List<MaterialPacking> boxList, String user, String ReceiveRequestActNo,
                              String commitDate, String opCode) throws Exception {

		List<MaterialPackingKey> arrayList = new ArrayList<MaterialPackingKey> ();

		String pc = "(";

		for (MaterialPacking materialPacking : boxList) {
			String materialPackingName = materialPacking.getMaterialPackingName();
			pc += "'" +  materialPackingName + "', ";
			String locationName = materialPacking.getLocationName();
			String erpFactory = materialPacking.getErpFactory();
			String erpLocation = materialPacking.getErpLocation();
			String materialspec=materialPacking.getMaterialSpecName();
			String sql2 = "SELECT\r\n" + 
					"	BMS.LOTNAME ,\r\n" + 
					"	BMS.PRODUCTSPECNAME ,\r\n" + 
					"	BMS.PHASE ,\r\n" + 
					"	SS.SPECNAME ,\r\n" + 
					"	m.DESC_CN ,\r\n" + 
					"	BMS.QTY ,\r\n" + 
					"	BMS.SHIPTIME ,\r\n" + 
					"	SS.SDK_ID ,BMS .REQUESTNAME ,\r\n" + 
					"	REGEXP_SUBSTR(BMS.LOTNAME , '[^|]+', 1, 5) AS CHARGE\r\n" + 
					"FROM\r\n" + 
					"	BS_MES_SHIPPED BMS LEFT JOIN MATERIALSPEC m ON m.MATERIALSPECNAME = BMS.PRODUCTSPECNAME \r\n" + 
					"	LEFT JOIN SDK_SPEC SS ON SS.SDK_ID = BMS.SDK_ID \r\n" + 
					"WHERE\r\n" + 
					"	BMS.LOTNAME = :LOTNAME\r\n" + 
					"	AND (BMS.RECEIVE_FLAG IS NULL\r\n" + 
					"		OR BMS.RECEIVE_FLAG <> 'Y')";
			Map<String, Object> bindMap = new HashMap<String, Object>();
			bindMap.put("LOTNAME",materialPackingName); 
			List<Map<String,Object>> list2 = IDMFrameServiceProxy.getSqlTemplate().queryForList(sql2, bindMap);
			if(list2.size() < 1) {
				throw new GlobalException( materialPackingName + "生产未完成入库,请联系生产确认！");
			}
			String phase = (list2.get(0).get("PHASE") == null || "".equals(list2.get(0).get("PHASE"))) ? "" : list2.get(0).get("PHASE").toString();
			String sdk_id = (list2.get(0).get("SDK_ID") == null || "~".equals(list2.get(0).get("SDK_ID"))) ? "" : list2.get(0).get("SDK_ID").toString();
			//根据入库信息获取完工报告
			StringBuffer sql3 = new StringBuffer();
			sql3.append(" ");
			sql3.append(" SELECT ");
			sql3.append(" M.RECEIVEREQUESTNAME, ");
			sql3.append(" (M.REQUESTQUANTITY   - M.RECEIVEDQUANTITY) MINUSQTY, ");
			sql3.append(" M.RECEIVEREQUESTDETAILNAME ");
			sql3.append(" FROM ");
			sql3.append(" MATERIALRECEIVEREQUESTDETAIL M LEFT JOIN  MATERIALRECEIVEREQUEST T ON M.RECEIVEREQUESTNAME = T.RECEIVEREQUESTNAME");
			sql3.append(" WHERE ");
			sql3.append(" (M.RECEIVEREQUESTNAME = :RECEIVEREQUESTNAME ");
			sql3.append(" OR M.PRODUCTORDER = :RECEIVEREQUESTNAME ");
			sql3.append(" OR M.PLANORDER = :RECEIVEREQUESTNAME) ");
			sql3.append(" AND M.MATERIALSPECNAME = :MATERIALSPECNAME AND T.STOCKORGNO IS NOT NULL  ");
			if (!"".equals(sdk_id) && !"~".equals(sdk_id)) {
				sql3.append(" AND M.SDK_ID = :SDK_ID "); 
			} else  {
				sql3.append(" AND M.SDK_ID is null  "); 
			}
			if (!"".equals(phase)) {
				sql3.append(" AND M.PHASE = :PHASE ");
			} else {
				sql3.append(" AND M.PHASE  is null ");
			}
			sql3.append(" AND M.REQUESTQUANTITY   - M.RECEIVEDQUANTITY  > 0  ORDER BY M.RECEIVEREQUESTNAME ASC ,M.RECEIVEREQUESTDETAILNAME ASC ");

			bindMap.put("RECEIVEREQUESTNAME",list2.get(0).get("REQUESTNAME"));
			bindMap.put("MATERIALSPECNAME",list2.get(0).get("PRODUCTSPECNAME"));
			bindMap.put("PHASE",phase);
			bindMap.put("SDK_ID",sdk_id);
			List<Map<String, Object>> queryForList = IDMFrameServiceProxy.getSqlTemplate().queryForList(sql3.toString(), bindMap);
			if (queryForList == null || queryForList.size() < 1) {
				throw new RuntimeException(materialPackingName.split("\\|")[0] + materialPackingName.split("\\|")[4] + "生产报告未完成,请联系生产确认！");
			}
			EventInfo makeEventInfo = new EventInfoUtil().makeEventInfo("createfgBoxInfo", user, "createfgBoxInfo");
				//IDMFrameServiceProxy.getTransactionManager().beginTransaction();
				//更新订单数量
				String qty=list2.get(0).get("QTY").toString();//批次数量
				BigDecimal pcqty = new BigDecimal(qty);
				//	获取订单号，订单行项，剩余数量	
				for (int i =0 ; i < queryForList.size(); ++ i) {
					String rqn = queryForList.get(i).get("RECEIVEREQUESTNAME").toString();  //订单
					String rqdn =queryForList.get(i).get("RECEIVEREQUESTDETAILNAME").toString();  //行项
					String minusQty = queryForList.get(i).get("MINUSQTY").toString();  //剩余数量
//					String rqn = map.get("RECEIVEREQUESTNAME").toString();  //订单
//					String rqdn = map.get("RECEIVEREQUESTDETAILNAME").toString();  //行项
//					String minusQty = map.get("MINUSQTY").toString();  //剩余数量
					BigDecimal mqty = new BigDecimal(minusQty);	
					System.out.println(i + "****" + (queryForList.size() - 1));
					if (i == queryForList.size() - 1 && mqty.compareTo(pcqty) < 0)  {
						throw new RuntimeException(materialPackingName + "报工单数量不足，无法入库 报工单号 : " + rqn  + "数量:" + minusQty + "批次数量: " + pcqty);
					}
					String insertSql = "INSERT INTO MATERIALPACKINGSUB T (T.MATERIALPACKINGNAME,T.RECEIVEREQUESTNAME,T.RECEIVEREQUESTDETAILNAME,T.QTY) "
							+ "VALUES (:MATERIALPACKINGNAME, :RECEIVEREQUESTNAME,:RECEIVEREQUESTDETAILNAME,:QTY)";
					String updateSql = "UPDATE MATERIALRECEIVEREQUESTDETAIL T SET T.RECEIVEDQUANTITY = T.RECEIVEDQUANTITY  + :QTY "
							+ "WHERE T.RECEIVEREQUESTNAME = :RECEIVEREQUESTNAME AND T.RECEIVEREQUESTDETAILNAME  = :RECEIVEREQUESTDETAILNAME";
					//如果当前行项剩余数量满足，则只绑定当前订单和行项
					if(mqty.compareTo(pcqty)>=0) 
					{
						Map<String,Object> bp=new HashMap<>();
						bp.put("RECEIVEREQUESTNAME", rqn);
						bp.put("RECEIVEREQUESTDETAILNAME", rqdn);
						bp.put("QTY", pcqty);
						bp.put("MATERIALPACKINGNAME", materialPackingName);
						IDMFrameServiceProxy.getSqlTemplate().update(insertSql, bp);
						IDMFrameServiceProxy.getSqlTemplate().update(updateSql, bp);
						break;
					}
					//如果当前行项数量不满足
					else 
					{
						pcqty=pcqty.subtract(mqty);
						Map<String,Object> bp=new HashMap<>();
						bp.put("RECEIVEREQUESTNAME", rqn);
						bp.put("RECEIVEREQUESTDETAILNAME", rqdn);
						bp.put("QTY", mqty);
						bp.put("MATERIALPACKINGNAME", materialPackingName);
						IDMFrameServiceProxy.getSqlTemplate().update(insertSql, bp);
						IDMFrameServiceProxy.getSqlTemplate().update(updateSql, bp);
						continue;
					}
				}

			MaterialPackingKey materialPackingKey = new MaterialPackingKey("SDK",materialPackingName);
			arrayList.add(materialPackingKey);

				receiveMesShippInfo(makeEventInfo, "SDK", materialPackingName, "", user, 
						materialPackingName, ReceiveRequestActNo, erpLocation, erpFactory, locationName,queryForList.get(0).get("RECEIVEREQUESTNAME").toString(), "","");
		}
		pc += "'')";
//		boolean fgStockIn = fgStockInBySplitCharge(pc, user,commitDate,opCode);

//		boolean fgStockInBySplitCharge20241118 = fgStockInBySplitCharge20241118(pc, user, commitDate, opCode);
		String aimErpFactory = boxList.get(0).getErpFactory();
		String aimErpLocation = boxList.get(0).getErpLocation();
		String aimLOcationName = boxList.get(0).getLocationName();
		String billCode = toSAPService.NoSourceChangeLocation(arrayList,aimErpFactory,
				aimErpLocation, aimLOcationName, user );
	}

	/**
	 * 手动入库，非自动入库包含转库和自动入库
	 *
	 * @param boxList
	 * @param user
	 * @param receiveRequestActNo
	 * @param commitDate
	 * @param opCode
	 */
	@Override
	@Transactional
	public void fgStockInByManul(List<MaterialPacking> boxList, String user, String receiveRequestActNo, String commitDate, String opCode) throws Exception {
		//调用mybatis查询当前要入库的信息是否是同一类型转库Or入库
		List<MaterialPacking> packingList = fgStockInDao.getBoxList(boxList,boxList.get(0).getErpFactory(),boxList.get(0).getErpLocation(),boxList.get(0).getLocationName());
		if(packingList.size()==0){
			throw new Exception("请选择正确的入库信息");
		}
		EventInfo eventInfo = EventInfoUtil.makeEventInfo("receiveMesShippInfo", user, "receiveMesShippInfo");

		List<MaterialPackingKey> arrayList = new ArrayList<MaterialPackingKey> ();

		//将查询的结果写入MaterialPacking表
		for(int i=0;i<packingList.size();i++){
			//util将实体类中有值的放到map
			Map<String, Object> stringObjectMap = MapUtils.entityToMap(packingList.get(i));
			CreateInfo packingList1 = new CreateInfo();
			packingList1.setSiteName("SDK");
			packingList1.setMaterialPackingName(packingList.get(i).getMaterialPackingName());
			packingList1.setUserColumns(stringObjectMap);

			List<MaterialPacking> mPackingList = fgStockInDao.getBoxPacking(packingList.get(i).getMaterialPackingName());
			if (mPackingList.size() == 0) {
				MaterialPackingServiceProxy.getMaterialPackingService().create(eventInfo, packingList1);
			}

			MaterialPackingKey materialPackingKey = new MaterialPackingKey("SDK",packingList.get(i).getMaterialPackingName());
			arrayList.add(materialPackingKey);
		}
		//调用Sap入库接口
		List<ToSAPFgStockInDto> fgStockInInfo = toSapDao.getFgStockInInfo(boxList);

		String receiveFlag = packingList.get(0).getMesReceiveFlag();
		String undoID = "";
		if(receiveFlag.equals("Z")) {
			//先入到线边仓，从线边再转库
			String aimErpFactory = boxList.get(0).getErpFactory();
			String aimErpLocation = boxList.get(0).getErpLocation();
			String aimLOcationName = boxList.get(0).getLocationName();
			undoID = toSAPService.NoSourceChangeLocation(arrayList,aimErpFactory,
					aimErpLocation, aimLOcationName, user );
		}else {
			// 直接入库
			//封装为Json的字符串
			String json = JSON.toJSONString(fgStockInInfo);
			undoID = toSAPService.FGStockInByManulIn(json, user);
		}





		//更新物料凭证和库存状态
		toSapDao.updateStockState(boxList, "Stocked", undoID);
		//更新过账流水
		toSapDao.saveUnDoInfo(  boxList, undoID,   commitDate);
		//更新接口表的标记和
		fgStockInDao.updateBsMesShipped(boxList);
	}


	/**
	 *>
	 * @param eventInfo
	 * @param siteName
	 * @param materialPackingName
	 * @param durableName
	 * @param user
	 * @param palletName
	 * @param receiveActNo
	 * @param erpLocation
	 * @param erpFactory
	 * @param locationName
	 * @param receiveRequestName
	 * @param receiveRequestDetailName
	 * @param areaName
	 * @return
	 * @throws Exception
	 */
	@Transactional
	public boolean receiveMesShippInfo(EventInfo eventInfo,String siteName,String materialPackingName,
			String durableName,String user,String palletName,String receiveActNo,
			String erpLocation,String erpFactory,String locationName,String receiveRequestName,
			String receiveRequestDetailName,String areaName) throws Exception  {
		StringBuffer sql = new StringBuffer();
		sql.append(" ");
		sql.append(" SELECT ");
		sql.append(" T.LOTNAME MATERIALPACKINGNAME, ");
		sql.append(" T.QTY MATERIALQUANTITY, ");
		sql.append(" T.UNIT,  ");
		sql.append(" M2. RECEIVEREQUESTDETAILNAME,");
		sql.append(" T.REQUESTNAME RECEIVEREQUESTNAME,");
		sql.append(" T.PRODUCTSPECNAME MATERIALSPECNAME,  ");
		sql.append(" SS.SPECNAME , ");
		sql.append(" REPLACE(T.SDK_ID, '~', '') SDK_ID,  ");
		sql.append(" M.ERPLOCATION , ");
		sql.append(" T.AREA ,");
		sql.append(" T.SHIPUSER , ");
		sql.append(" T.PACKINGGRADE , ");
		sql.append(" T.SHIPTIME , ");
		sql.append(" M3.MATERIALTYPE , ");
		sql.append(" T.REMARK,T.PHASE,T.CAREER_ASSISTANCE,T.DURABLETYPE ,T.BUSINESS_UNIT,T.SALESPERSON,T.MJPC ,T.TRUEGG,T.CHARGE,T.MAKEDATE, T.CUSTOMERNO ,"
				+ "T.LK_DURABLENAME,T.LK_AREANAME,T.LK_PRODUCTLINE,T.LK_WIDTH ,T.LK_DEVIATION,T.LK_WEIGHT,T.LK_DIAMETER,T.LK_SHELFNAME ");
		sql.append(" FROM ");
		sql.append(" BS_MES_SHIPPED T ");
		sql.append(" LEFT JOIN MATERIALRECEIVEREQUEST M ON ");
		sql.append(" T.REQUESTNAME = M.RECEIVEREQUESTNAME ");
		sql.append(" LEFT JOIN MATERIALRECEIVEREQUESTDETAIL M2 ON ");
		sql.append(" T.REQUESTNAME = M2.RECEIVEREQUESTNAME  ");
		sql.append(" AND T.PRODUCTSPECNAME = M2.MATERIALSPECNAME  ");
		sql.append(" AND T.SDK_ID = M2.SDK_ID  ");
		sql.append(" LEFT JOIN SDK_SPEC SS ON T.SDK_ID = SS.SDK_ID ");
		sql.append(" LEFT JOIN MATERIALSPEC M3 ON T.PRODUCTSPECNAME  = M3.MATERIALSPECNAME  ");
		sql.append(" WHERE (T.RECEIVE_FLAG IS NULL OR T.RECEIVE_FLAG <> 'Y') ");
		sql.append(" AND T.LOTNAME = :MATERIALPACKINGNAME ");
		//		sql.append(" AND M.SITENAME = :SITENAME ");
		Map<String, Object> hashMap = new HashMap<String,Object> ();
		hashMap.put("MATERIALPACKINGNAME", materialPackingName);
		List<Map<String, Object>> queryForList = IDMFrameServiceProxy.getSqlTemplate().queryForList(sql.toString(), hashMap);
		if(queryForList == null || queryForList.size() < 1) {
			throw new RuntimeException("不存在要入库的信息");
		}
		 String materialSpecName = queryForList.get(0).get("MATERIALSPECNAME") == null ? "" : queryForList.get(0).get("MATERIALSPECNAME").toString();
			MaterialSpec materialSpec = new MaterialSpec();
			MaterialSpecKey materialSpecKey = new MaterialSpecKey();
			materialSpecKey.setMaterialSpecName(materialSpecName);
			materialSpecKey.setSiteName(siteName);
			String is_oven = "N";
			materialSpec = MaterialServiceProxy.getMaterialSpecService()
					.selectByKey(materialSpecKey);
			String maturationflag = materialSpec.getMATURATIONFLAG();//熟化标识
			String is_CON_TEMP = materialSpec.getIS_CON_TEMP();//恒温恒湿
			//判断仓库是否启用了货位，但货位为空
			String sql2 = "SELECT be.USE_LOCATION,be.CONST_TEMP,be.IS_OVEN FROM BS_ERPLOCATION be WHERE be.ERPLOCATIONNAME = :ERPLOCATION";
			Map<String, Object> hashMap2 = new HashMap<String,Object> ();
			hashMap2.put("ERPLOCATION", erpLocation);
			hashMap2.put("LOCATIONNAME", locationName);
			List<Map<String, Object>> queryForList2 = IDMFrameServiceProxy.getSqlTemplate().queryForList(sql2, hashMap2);
			if (queryForList2 == null || queryForList2.size() < 1) {
				throw new RuntimeException("仓库不存在");
			} else {
				String string = queryForList2.get(0).get("USE_LOCATION") == null ? "" : queryForList2.get(0).get("USE_LOCATION").toString();//启用货位
				String const_temp = queryForList2.get(0).get("CONST_TEMP") == null ? "" : queryForList2.get(0).get("CONST_TEMP").toString(); //恒温标识
				is_oven = queryForList2.get(0).get("IS_OVEN") == null ? "" : queryForList2.get(0).get("IS_OVEN").toString(); //熟化标识
				if ("Y".equals(string) && ("".equals(locationName) || locationName == null ))  {
					throw new RuntimeException("仓库启用了货位，但货位为空");
				}
				if ("N".equals(string) && (!"".equals(locationName) &&  locationName != null) )  {
					throw new RuntimeException("仓库未启用货位，但货位不为空");
				}
				if (!"".equals(locationName) &&  locationName != null) {
					String sql3 = "SELECT * FROM STORAGESPEC S WHERE S.STORAGENAME = :LOCATIONNAME AND S.ERPLOCATION = :ERPLOCATION ";
					List<Map<String, Object>> queryForList3 = IDMFrameServiceProxy.getSqlTemplate().queryForList(sql3, hashMap2);
					if (queryForList3 == null || queryForList3.size() < 1) {
						throw new RuntimeException("仓库与货位对应关系不正确");
					}
				}
				String ckhw = "Y".equals(const_temp) ? "恒温恒湿" : "非恒温恒湿";
				String wlhw = "Y".equals(is_CON_TEMP) ? "恒温恒湿" : "非恒温恒湿";
				
				
				String cksh = "Y".equals(is_oven) ? "熟化" : "非熟化";
				String wlsh = "Y".equals(maturationflag) ? "熟化" : "非熟化";
				//物料非熟化 不能进熟化仓
				if ("Y".equals(maturationflag)) {
					
				} else { //非熟化逻辑
					if ("Y".equals(is_oven)) {
						throw new RuntimeException("仓库" + cksh + "; 物料" + wlsh);
					}
				}
				
				//物料恒温   只能进恒温仓或熟化仓 2024.11
				String packingGrade = queryForList.get(0).get("PACKINGGRADE") == null ? "" : queryForList.get(0).get("PACKINGGRADE").toString();
				if (!"NG".equals(packingGrade)) {
					if ("Y".equals(is_CON_TEMP)) {
						if ("Y".equals(const_temp) || "Y".equals(is_oven)) {
							
						} else {
							throw new RuntimeException("仓库" + ckhw + "; 物料" + wlhw);
						}
					} else { //物料非恒温  不能进恒温仓
						if ("Y".equals(const_temp)) {
							throw new RuntimeException("仓库" + ckhw + "; 物料" + wlhw);
						}
					}
				}
//				if (!is_oven.equals(maturationflag)) {
//					throw new RuntimeException("仓库" + cksh + "; 物料" + wlsh);
//				}
//				if (!"Y".equals(maturationflag)) {
//					if (!const_temp.equals(is_CON_TEMP)) {
//						throw new RuntimeException("仓库" + ckhw + "; 物料" + wlhw);
//					}
//				}
			}
		Map<String, Object> bindMap = new HashMap<String, Object>();
		bindMap.put("lkMaterialPackingName", palletName);
		bindMap.put("MaterialType", queryForList.get(0).get("MATERIALTYPE"));
		bindMap.put("MaterialSpecName",materialSpecName);
		
//		if ( materialSpecName.startsWith("4")) {
//			packingGrade = "OK";
//		}
		String packingGrade = queryForList.get(0).get("PACKINGGRADE") == null ? "" : queryForList.get(0).get("PACKINGGRADE").toString();
		if (!"".equals(packingGrade)) {
			bindMap.put("oqaResultState", GenericServiceProxy.getConstantMap().OQA_State_End);
			bindMap.put("oqaResult",packingGrade);
			bindMap.put("packingGrade", packingGrade);
		} else {
			bindMap.put("oqaResultState",GenericServiceProxy.getConstantMap().OQA_State_Pre);
		}
		
		bindMap.put("SubPackingQuantity",queryForList.get(0).get("MATERIALQUANTITY"));
		bindMap.put("MaterialCreateQuantity",
				queryForList.get(0).get("MATERIALQUANTITY"));
		bindMap.put("MaterialQuantity", queryForList.get(0).get("MATERIALQUANTITY"));// 数量
		bindMap.put("PackingState", "Released");
		bindMap.put("OldPackingState", "Released");
		bindMap.put("stockState", "Created");
		bindMap.put("OldStockState", "Created");
		bindMap.put("HoldState", "N");
		bindMap.put("areaName", areaName);
		bindMap.put("durableType", queryForList.get(0).get("DURABLETYPE"));
		bindMap.put("truegg", queryForList.get(0).get("TRUEGG"));
		bindMap.put("unit", queryForList.get(0).get("UNIT"));
		bindMap.put("LocationName", locationName);
		bindMap.put("charge",queryForList.get(0).get("CHARGE"));
		bindMap.put("DurableName", durableName);
		bindMap.put("MaterialProcessGroupName","");
		bindMap.put("LastEventTimeKey",
				TimeStampUtil.getCurrentEventTimeKey());
		bindMap.put("ReceiveRequestName", receiveRequestName);
		bindMap.put("productOrder", receiveRequestName);
		bindMap.put("ReceiveRequestDetailName",receiveRequestDetailName);
		bindMap.put("MakeDate", queryForList.get(0).get("MAKEDATE"));
		bindMap.put("expiringDate", getExpridate(queryForList.get(0).get("MAKEDATE") == null ? "" : queryForList.get(0).get("MAKEDATE").toString(), queryForList.get(0).get("MATERIALSPECNAME").toString()));
		bindMap.put("ReceiveTime", eventInfo.getEventTime());
		bindMap.put("ReceiveUser", eventInfo.getEventUser());
		bindMap.put("ShipTime",queryForList.get(0).get("SHIPTIME"));
		bindMap.put("ShipUser",queryForList.get(0).get("SHIPUSER"));
		bindMap.put("ErpLocation", erpLocation);
		bindMap.put("ErpFactory", erpFactory);
		bindMap.put("receiveActNo", receiveActNo);
		bindMap.put("locationName", locationName);
		bindMap.put("StockInType", "Normal");
		bindMap.put("SDK_ID", queryForList.get(0).get("SDK_ID"));
		bindMap.put("PHASE", queryForList.get(0).get("PHASE"));
		bindMap.put("CUSTOMNO",queryForList.get(0).get("CUSTOMERNO"));//客户
		bindMap.put("CAREER_ASSISTANCE", queryForList.get(0).get("CAREER_ASSISTANCE"));//业助信息
		bindMap.put("BUSINESS_UNIT", queryForList.get(0).get("BUSINESS_UNIT"));//业务
		bindMap.put("SALESPERSON", queryForList.get(0).get("SALESPERSON"));//事业部
		bindMap.put("MJPC", queryForList.get(0).get("MJPC"));//母卷批次
		bindMap.put("remark", queryForList.get(0).get("REMARK"));//备注
		if("Y".equals(is_oven)) {
			bindMap.put("MATURATIONINTIME", eventInfo.getEventTime());//熟化入库时间
		}
		
		//增加立库相关信息T.LK_DURABLENAME,T.LK_AREANAME,T.LK_PRODUCTLINE,T.LK_WIDTH ,T.LK_DEVIATION,T.LK_WEIGHT,T.LK_DIAMETER,T.LK_SHELFNAME
		bindMap.put("durableName", queryForList.get(0).get("LK_DURABLENAME"));
		bindMap.put("areaName", queryForList.get(0).get("LK_AREANAME"));
		bindMap.put("PRODUCTLINE", queryForList.get(0).get("LK_PRODUCTLINE"));
		bindMap.put("WIDTH", queryForList.get(0).get("LK_WIDTH"));
		bindMap.put("DEVIATION", queryForList.get(0).get("LK_DEVIATION"));
		bindMap.put("WEIGHT", queryForList.get(0).get("LK_WEIGHT"));
		bindMap.put("DIAMETER", queryForList.get(0).get("LK_DIAMETER"));
		bindMap.put("shelfName", queryForList.get(0).get("LK_SHELFNAME"));
		
		
		//查询库存是否存在，且状态为创建
		String sql4 =  "SELECT m.STOCKSTATE FROM MATERIALPACKING m WHERE m.MATERIALPACKINGNAME = :MATERIALPACKINGNAME ";
		List<Map<String, Object>> queryForList4 = IDMFrameServiceProxy.getSqlTemplate().queryForList(sql4, hashMap);
		if (queryForList4 != null && queryForList4.size() > 0) {
			String stockState = queryForList4.get(0).get("STOCKSTATE").toString();
			if ("Created".equals(stockState)) {
				SetEventInfo setEventInfo = new SetEventInfo();
				setEventInfo.setUserColumns(bindMap);
				MaterialPackingKey materialPackingKey = new MaterialPackingKey(siteName, materialPackingName);
				MaterialPackingServiceProxy.getMaterialPackingService().setEvent(materialPackingKey, eventInfo, setEventInfo);
				return false;
			}
		} else {
			//入库信息存入库存表
			CreateInfo createInfo = new CreateInfo();
			createInfo.setSiteName(siteName);
			createInfo.setMaterialPackingName(materialPackingName);// 新生成的box id
			createInfo.setMaterialPackingType("Box");
			createInfo.setContentMaterialType("");
			createInfo.setUserColumns(bindMap);
			MaterialPackingServiceProxy.getMaterialPackingService().create(
					eventInfo, createInfo);
		}
		return true;
	}

	
	/**
	 * 成品入库不拆完工报告
	 * @param pc
	 * @param eventUser
	 * @param commitDate
	 * @param opCode
	 * @return
	 * @throws Exception
	 */
	@Transactional
	public boolean fgStockInBySplitCharge20241118 (String pc, String eventUser,String commitDate,String opCode) throws Exception {
		//根据入库单号查询有多少个完工报告，完工报告分开过账
		String wgs = "SELECT DISTINCT  t.ERPLOCATION FROM MATERIALPACKINGSUB m \r\n" + 
				" LEFT JOIN MATERIALPACKING T ON m.MATERIALPACKINGNAME =t.MATERIALPACKINGNAME \r\n" + 
				" WHERE m.MATERIALPACKINGNAME IN " + pc;
		Map<String, Object> hashMap3 = new HashMap<String,Object> ();
		List<Map<String, Object>> queryForList2 = IDMFrameServiceProxy.getSqlTemplate().queryForList(wgs, hashMap3);
		for (int i = 0; i < queryForList2.size(); i++) {
			String erpLocation = queryForList2.get(i).get("ERPLOCATION").toString();
			
			String billCode = toSAPService.FGStockIn(pc, eventUser,commitDate,opCode + i);

			if (billCode == null) {
				throw new GlobalException("报送ERP失败,请联系IT处理！");
			}
			EventInfo makeEventInfo = new EventInfoUtil().makeEventInfo("FGStockIn", eventUser, "FGStockIn");
			//更新抬头文本状态和Box状态
			String sql = " SELECT DISTINCT M2.SITENAME ,M.MATERIALPACKINGNAME FROM MATERIALPACKINGSUB M \r\n" + 
					" LEFT JOIN MATERIALPACKING m2 ON m.MATERIALPACKINGNAME = m2.MATERIALPACKINGNAME \r\n" + 
					" WHERE  1 = 1 \r\n" + 
					" AND m2.ERPLOCATION = :ERPLOCATION   AND m.MATERIALPACKINGNAME IN " + pc;
			Map<String, Object> hashMap = new HashMap<String,Object> ();
			hashMap.put("ERPLOCATION", erpLocation);
			List<Map<String, Object>> queryForList = IDMFrameServiceProxy.getSqlTemplate().queryForList(sql, hashMap);
			for (Map<String, Object> map : queryForList) {
				MaterialPackingKey materialPackingKey = new MaterialPackingKey(map.get("SITENAME").toString(),map.get("MATERIALPACKINGNAME").toString());
				SetEventInfo setEventInfo = new SetEventInfo();
				Map<String, Object> bindMap = new HashMap<String, Object>();
				bindMap.put("unDoID", billCode);
				//bindMap.put("StockState", "Stocked");
				setEventInfo.setUserColumns(bindMap);
				MaterialPackingServiceProxy.getMaterialPackingService().setEvent(materialPackingKey, makeEventInfo, setEventInfo);
				
				//更新MES标识
				String sql2 = "UPDATE BS_MES_SHIPPED T SET T.RECEIVE_FLAG = 'Y', T.RECEIVE_TIME = SYSDATE WHERE T.LOTNAME  = :LOTNAME";
				Map<String, Object> hashMap2 = new HashMap<String,Object> ();
				hashMap2.put("LOTNAME", map.get("MATERIALPACKINGNAME").toString());
				IDMFrameServiceProxy.getSqlTemplate().update(sql2, hashMap2);
			}
			untils.SaveUnDoInfoBySplitCharge(billCode,commitDate);
		}
		//更新Box状态为Stocked
		String sqlu=" UPDATE MATERIALPACKING m SET m.STOCKSTATE =:STOCKSTATE\r\n" + 
				" WHERE m.SITENAME =:SITENAME AND MATERIALPACKINGNAME IN " + pc;
		Map<String, Object> bpu=new HashMap<String, Object>();
		bpu.put("STOCKSTATE", "Stocked");
		bpu.put("SITENAME", "SDK");
		IDMFrameServiceProxy.getSqlTemplate().update(sqlu, bpu);
		
		
		//备份过账条码表的信息，并删除
		String bfSql = "INSERT\r\n" + 
				"	INTO\r\n" + 
				"	MATERIALPACKINGSUBHISTORY T (T.MATERIALPACKINGNAME,\r\n" + 
				"	T.RECEIVEREQUESTNAME,\r\n" + 
				"	T.RECEIVEREQUESTDETAILNAME,\r\n" + 
				"	T.QTY)\r\n" + 
				"SELECT\r\n" + 
				"	M.MATERIALPACKINGNAME,\r\n" + 
				"	M.RECEIVEREQUESTNAME,\r\n" + 
				"	M.RECEIVEREQUESTDETAILNAME,\r\n" + 
				"	M.QTY\r\n" + 
				"FROM\r\n" +
				"	MATERIALPACKINGSUB M\r\n" + 
				"WHERE M.MATERIALPACKINGNAME IN " + pc;
		//删除拆分表MATERIALPACKINGSUB
		String sqld=" DELETE FROM MATERIALPACKINGSUB m WHERE m.MATERIALPACKINGNAME IN " + pc;
		IDMFrameServiceProxy.getSqlTemplate().update(bfSql, bpu);
		IDMFrameServiceProxy.getSqlTemplate().update(sqld, bpu);
		
		return true;
	}

	
	
	/**
	 * 接收ERP返回消息更新WMS凭证
	 * @param undoid
	 */
	public void SaveUnDoInfo( String undoid,String commitDate) {

		String insertUnDOMaterialPackingInfo = "insert into BS_MATERIALPACKINGUNDOINFO (unDoID,preundoid,UNDODETAILNAME,undoidstate,UNDOIDDATE,"
				+ "SITENAME, MATERIALPACKINGNAME, MATERIALPACKINGTYPE, CONTENTMATERIALTYPE,"
				+ "MATERIALTYPE, MATERIALSPECNAME, SUPERMATERIALPACKINGNAME, PACKINGGRADE, SUBPACKINGQUANTITY, MATERIALCREATEQUANTITY,"
				+ "MATERIALQUANTITY, PACKINGSTATE, OLDPACKINGSTATE, STOCKSTATE, OLDSTOCKSTATE, HOLDSTATE, AREANAME, LOCATIONNAME,"
				+ "DURABLENAME, MATERIALPROCESSGROUPNAME, LASTEVENTNAME, LASTEVENTTIMEKEY, LASTEVENTTIME, LASTEVENTUSER,"
				+ "LASTEVENTCOMMENT, CREATETIME, CREATEUSER, RECEIVEREQUESTNAME, RECEIVEREQUESTDETAILNAME,"
				+ "MAKEDATE, RECEIVEACTNO, STOCKINTYPE, RECEIVETIME, RECEIVEUSER, SHIPREQUESTNAME, SHIPREQUESTDETAILNAME, SHIPTIME,"
				+ "SHIPUSER, REASONCODETYPE, OQARESULTSTATE, OQARESULT, ERPLOCATION, ERPFACTORY, REASONCODE, CHARGE, SUPPLIERNAME,ETCSTATE,ERPEVENTTIME,NPFLAG)"
				+ "select unDoID,'' as preundoid,UNDODETAILNAME,'Completed' as undoidstate,:commitDate AS UNDOIDDATE," //
				+ "SITENAME, MATERIALPACKINGNAME, MATERIALPACKINGTYPE, CONTENTMATERIALTYPE,"
				+ "MATERIALTYPE, MATERIALSPECNAME, SUPERMATERIALPACKINGNAME, PACKINGGRADE, SUBPACKINGQUANTITY, MATERIALCREATEQUANTITY,"
				+ "MATERIALQUANTITY, PACKINGSTATE, OLDPACKINGSTATE, STOCKSTATE, OLDSTOCKSTATE, HOLDSTATE, AREANAME, LOCATIONNAME,"
				+ "DURABLENAME, MATERIALPROCESSGROUPNAME, LASTEVENTNAME, LASTEVENTTIMEKEY, LASTEVENTTIME, LASTEVENTUSER,"
				+ "LASTEVENTCOMMENT, CREATETIME, CREATEUSER, RECEIVEREQUESTNAME, RECEIVEREQUESTDETAILNAME,"
				+ "MAKEDATE, RECEIVEACTNO, STOCKINTYPE, RECEIVETIME, RECEIVEUSER, SHIPREQUESTNAME, SHIPREQUESTDETAILNAME, SHIPTIME,"
				+ "SHIPUSER, REASONCODETYPE, OQARESULTSTATE, OQARESULT, ERPLOCATION, ERPFACTORY, REASONCODE, CHARGE, SUPPLIERNAME,ETCSTATE,ERPEVENTTIME,NPFLAG"
				+ " from MATERIALPACKING  "
				+ " where unDoID=:UNDOID";

		Map<String, Object> bindMap_insert = new HashMap<String, Object>();
		bindMap_insert.put("UNDOID", undoid);
		bindMap_insert.put("commitDate", commitDate);
		IDMFrameServiceProxy.getSqlTemplate()
				.update(insertUnDOMaterialPackingInfo, bindMap_insert);

	}


	
	/**
	 * 保质期计算
	 * @param makeDate
	 * @param materialSpecName
	 * @return
	 */
	public static String getExpridate(String makeDate,String materialSpecName) {
		String sql = "SELECT NVL(T.EXPIRATIONDAY,180) +   TO_TIMESTAMP(SUBSTR(:MAKEDATE,0,19),'YYYY-MM-DD HH24:MI:SS') EXP FROM MATERIALSPEC T WHERE T.MATERIALSPECNAME = :MATERIALSPECNAME";
		
		Map<String, Object> hashMap = new HashMap<String,Object> ();
		hashMap.put("MATERIALSPECNAME", materialSpecName);
		hashMap.put("MAKEDATE", makeDate);
		List<Map<String,Object>> queryForList = IDMFrameServiceProxy.getSqlTemplate().queryForList(sql, hashMap);
		
		if (queryForList != null && queryForList.size() > 0) {
			return queryForList.get(0).get("EXP") == null ? "" : queryForList.get(0).get("EXP").toString();
		}
		return "";
	}

	public String fgStockIn (String RECEIVEACTNO, String eventUser) throws Exception {
		//根据抬头文本获取批次集合
//		List<MaterialPacking> boxList = new ArrayList<MaterialPacking>();
//		String sql = "SELECT * FROM MATERIALPACKING WHERE RECEIVEACTNO = :RECEIVEACTNO";
//		Map<String, Object> hashMap = new HashMap<String,Object> ();
//		hashMap.put("RECEIVEACTNO", RECEIVEACTNO);
//		List<Map<String,Object>> queryForList = IDMFrameServiceProxy.getSqlTemplate().queryForList(sql, hashMap);
//		for (Map<String, Object> map : queryForList) {
//			MaterialPackingKey materialPackingKey = new MaterialPackingKey();
//			materialPackingKey.setMaterialPackingName(map.get("MATERIALPACKINGNAME").toString());
//			materialPackingKey.setSiteName(map.get("SITENAME").toString());
//			MaterialPacking materialPacking = MaterialPackingServiceProxy.getMaterialPackingService().selectByKey(materialPackingKey);
//			boxList.add(materialPacking);
//		}
//		fgStockInNew(boxList, eventUser, RECEIVEACTNO, "", "");


		String billCode = toSAPService.FGStockIn2(RECEIVEACTNO, eventUser);
		if (billCode == null) {
			throw new GlobalException("报送ERP失败,请联系IT处理！");
		}
		EventInfo makeEventInfo = EventInfoUtil.makeEventInfo("FGStockIn", eventUser, "FGStockIn", "", "");
		//更新抬头文本状态和Box状态
		String sql = "SELECT M.SITENAME ,M.MATERIALPACKINGNAME FROM MATERIALPACKING M WHERE M.RECEIVEACTNO = :RECEIVEACTNO";
		Map<String, Object> hashMap = new HashMap<String,Object> ();
		hashMap.put("RECEIVEACTNO", RECEIVEACTNO);
		List<Map<String, Object>> queryForList = IDMFrameServiceProxy.getSqlTemplate().queryForList(sql, hashMap);
		for (Map<String, Object> map : queryForList) {
			MaterialPackingKey materialPackingKey = new MaterialPackingKey(map.get("SITENAME").toString(),map.get("MATERIALPACKINGNAME").toString());
			SetEventInfo setEventInfo = new SetEventInfo();
			Map<String, Object> bindMap = new HashMap<String, Object>();
			bindMap.put("unDoID", billCode);
			bindMap.put("stockState", "Stocked");
			setEventInfo.setUserColumns(bindMap);
			MaterialPackingServiceProxy.getMaterialPackingService().setEvent(materialPackingKey, makeEventInfo, setEventInfo);

			String sql2 = "UPDATE BS_MES_SHIPPED T SET T.RECEIVE_FLAG = 'Y', T.RECEIVE_TIME = SYSDATE WHERE T.LOTNAME  = :LOTNAME";
			Map<String, Object> hashMap2 = new HashMap<String,Object> ();
			hashMap2.put("LOTNAME", map.get("MATERIALPACKINGNAME").toString());
			IDMFrameServiceProxy.getSqlTemplate().update(sql2, hashMap2);


			String sql3 = "UPDATE MATERIALRECEIVEACT SET RECEIVEACTSTATE = 'Received' WHERE RECEIVEACTNO = :RECEIVEACTNO";
			IDMFrameServiceProxy.getSqlTemplate().update(sql3, hashMap);

		}
		String commitDate=TimeStampUtil.getCurrentTime("yyyy-MM-dd");
		SaveUnDoInfo( billCode, commitDate);
		//更新MES标识
		return billCode;
	}
	//自动成品入库到现场仓
	public String outoFgStockIn (String RECEIVEACTNO, String eventUser) throws Exception {

		String billCode = toSAPService.FGStockIn2(RECEIVEACTNO, eventUser);
		if (billCode == null) {
			throw new GlobalException("报送ERP失败,请联系IT处理！");
		}
		EventInfo makeEventInfo = EventInfoUtil.makeEventInfo("FGStockIn", eventUser, "FGStockIn", "", "");
		//更新抬头文本状态和Box状态
		String sql = "SELECT M.SITENAME ,M.MATERIALPACKINGNAME FROM MATERIALPACKING M WHERE M.RECEIVEACTNO = :RECEIVEACTNO";
		Map<String, Object> hashMap = new HashMap<String,Object> ();
		hashMap.put("RECEIVEACTNO", RECEIVEACTNO);
		List<Map<String, Object>> queryForList = IDMFrameServiceProxy.getSqlTemplate().queryForList(sql, hashMap);
		for (Map<String, Object> map : queryForList) {
			MaterialPackingKey materialPackingKey = new MaterialPackingKey(map.get("SITENAME").toString(),map.get("MATERIALPACKINGNAME").toString());
			SetEventInfo setEventInfo = new SetEventInfo();
			Map<String, Object> bindMap = new HashMap<String, Object>();
			bindMap.put("unDoID", billCode);
			bindMap.put("stockState", "Stocked");
			setEventInfo.setUserColumns(bindMap);
			MaterialPackingServiceProxy.getMaterialPackingService().setEvent(materialPackingKey, makeEventInfo, setEventInfo);

			String sql2 = "UPDATE BS_MES_SHIPPED T SET T.RECEIVE_FLAG = 'Z', T.RECEIVE_TIME = SYSDATE WHERE T.LOTNAME  = :LOTNAME";
			Map<String, Object> hashMap2 = new HashMap<String,Object> ();
			hashMap2.put("LOTNAME", map.get("MATERIALPACKINGNAME").toString());
			IDMFrameServiceProxy.getSqlTemplate().update(sql2, hashMap2);

			String sql3 = "UPDATE MATERIALRECEIVEACT SET RECEIVEACTSTATE = 'Received' WHERE RECEIVEACTNO = :RECEIVEACTNO";
			IDMFrameServiceProxy.getSqlTemplate().update(sql3, hashMap);

		}
		String commitDate=TimeStampUtil.getCurrentTime("yyyy-MM-dd");
		SaveUnDoInfo( billCode, commitDate);
		//更新MES标识
		return billCode;
	}
}
