package com.steering.pss.judge.DAL;

import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;
import CoreFS.SC01.CoreConstantData;
import CoreFS.Util.StringUtils;

import com.google.gson.JsonArray;
import com.steering.comm.DefaultWebServiceRequest;
import com.steering.comm.LoggableStatement;
import com.steering.comm.ServiceToCx;
import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.EntityTool;
import com.steering.pss.sale.order.qualityDesign.QualityDesignTool;
import com.steering.pss.ydm.entity.YdmZcBillCEntity;

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

import net.sf.json.JSONObject;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;

import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;

public class QcmZbsQueryFrm extends DBCommon {

	/***
	 * 查询登陆人对应的销售组织
	 * 
	 * @param areaNo
	 * @return
	 */
	public CoreReturnObject getSaleorg(String areaNo) {
		return this.getDataBySqlID("QcmZbsQueryFrm.getSaleorg",
				new Object[] { areaNo });
	}

	/**
	 * 许可证号
	 */
	public CoreReturnObject querySendPlan(String licesinNo) {
		String sql = "SELECT T.BASECODE,T.BASENAME FROM COM_BASE_INFO T WHERE T.SORTCODE='"
				+ licesinNo + "' AND T.VALIDFLAG='1'";
		return this.getData(sql);
	}

	/**
	 * 通过提单号查询合同信息
	 * 
	 * @param billNo
	 *            提单号
	 * @return CoreReturnObject
	 */
	public CoreReturnObject getOrderInfoByBiltNo(ArrayList<Object> params,
												 String status,String deptId,String strZbs) {
		return getOrderInfoByBiltNo(params,status,deptId,"",strZbs);
	}
	public CoreReturnObject getOrderInfoByBiltNo(ArrayList<Object> params,
			String status,String deptId,String orderCreateName,String strZbs) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("QcmZbsQueryFrm.getOrderInfoByBiltNo");
		if (!status.equals("") && status.equals("0")) {
			sql += "AND T1.ZBS_FLAG='0'";
		} else if (status.equals("1")) {
			sql += "AND T1.ZBS_FLAG IN ('1','2')";
		}
		if (!strZbs.equals("") && strZbs != null) {
			sql += "AND T1.ZBS_TYPE_DESC LIKE '%"+strZbs+"%'";
		} 
		if(deptId.equals("002")){
            
        }else{
              sql += " AND T1.SUPPLY_UNIT = DECODE(SUBSTR('"+deptId+"',1,6),'002001','120501','002023','120504') ";
        }
		sql += " AND (T1.BILL_STATUS >= '4' or T1.BILL_STATUS < '4' and T1.ISPRECLOSE <> '0')";
		if(!StringUtils.isEmpty(orderCreateName)){
			sql += "AND (T4.CREATE_NAME= '" + orderCreateName + "' OR T4.DOCUMENTARY_NAME= '" + orderCreateName + "' OR 'admin' = '" + orderCreateName + "')";
		}
		sql += " ORDER BY T1.BILL_NO ASC,T1.DELETE_TIME ASC";
		return this.getData(sql, params.toArray());
	}
	
	/**
	 * 通过提单号查询合同信息
	 * 打印预览
	 * @param billNo
	 *            提单号
	 * @return CoreReturnObject
	 */
	public CoreReturnObject getOrderInfoByBiltNoYuLan(ArrayList<Object> params,
			String status,String deptId) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("QcmZbsQueryFrm.getOrderInfoByBiltNo");
		if (!status.equals("") && status.equals("0")) {
			sql += "AND T1.ZBS_FLAG='0'";
		} else if (status.equals("1")) {
			sql += "AND T1.ZBS_FLAG IN ('1','2')";
		}
		if(deptId.equals("002")){
            
        }else{
              sql += " AND T1.SUPPLY_UNIT = DECODE(SUBSTR('"+deptId+"',1,6),'002001','120501','002023','120504') ";
        }
		sql += " ORDER BY T1.BILL_NO ASC,T1.DELETE_TIME ASC";
		return this.getData(sql, params.toArray());
	}

	/**
	 * 查询多语言质保书
	 */
	public CoreReturnObject doQuerLanguage(String billNo, String ordLnDlyPk) {
		return this.getDataBySqlID("QcmZbsQueryFrm.doQuerLanguage",
				new Object[] { billNo, ordLnDlyPk });
	}
	/**
	 * 查询多语言质保书
	 */
	public CoreReturnObject doQuerLanguage(String billNo, String ordLnDlyPk,String isValid) {
		return this.getDataBySqlID("QcmZbsQueryFrm.doQuerLanguage2",
				new Object[] { billNo, ordLnDlyPk ,isValid,billNo, ordLnDlyPk ,isValid});
	}

	/**
	 * 查询多语言质保书
	 */
	public CoreReturnObject doQuerLanguage1(String billNo, String ordLnDlyPk) {
		return this.getDataBySqlID("QcmZbsQueryFrm.doQuerLanguage1",
				new Object[] { billNo, ordLnDlyPk });
	}

	public CoreReturnObject doQuerLanguage3(String billNo, String ordLnDlyPk) {
		return this.getDataBySqlID("QcmZbsQueryFrm.doQuerLanguage3",
				new Object[] { billNo, ordLnDlyPk });
	}

	/**
	 * 查询语言要求
	 * 
	 * @param billNo
	 *            提单号
	 * @return CoreReturnObject
	 */
	public CoreReturnObject getOrderAskSub(String askSubNo) {
		Object[] params = new Object[] { askSubNo };
		return this.getDataBySqlID("QcmZbsQueryFrm.getOrderAskSub", params);
	}

	/**
	 * 查询基础数据
	 * 
	 * @param baseCode
	 * @return
	 */
	public CoreReturnObject getBaseInfo(String baseCode,String billNo) {
		Object[] params = new Object[] { baseCode};
		return this.getDataBySqlID("QcmZbsQueryFrm.getBaseInfo", params);
	}

	/**
	 * 通过提单号查询炉信息
	 * 
	 * @param billNo
	 *            提单号
	 * @return CoreReturnObject
	 */
	public CoreReturnObject getJustStoveNoInfoByBiltNo(String billNo) {
		Object[] params = new Object[] { billNo };
		return this.getDataBySqlID("QcmZbsQueryFrm.getJustStoveNoInfoByBiltNo",
				params);
	}

	public static List<String[]> getBiltNoInfoByBillNo(Connection con,
			String billNo) throws SQLException {
		List<String[]> list = new ArrayList<String[]>();
		String sql = CoreXmlSqlParsersFactory
				.getSql("QcmZbsQueryFrm.getBiltNoInfoByBillNo");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, billNo);
		ResultSet rs = ps.executeQuery();
		while (rs.next()) {
			String[] strArray = new String[7];
			strArray[0] = rs.getString("BILL_NO");
			strArray[1] = rs.getString("BILL_STATUS");
			strArray[2] = rs.getString("LOADVEHICLE_TYPE");
			strArray[3] = rs.getString("ISPRECLOSE");
			strArray[4] = rs.getString("BILL_TICKET_STATUS");
			strArray[5] = rs.getString("OUTSTOCK_TICKET_STATUS");
			strArray[6] = rs.getString("TRANSMNY_TICKET_STATUS");
			list.add(strArray);
		}
		rs.close();
		ps.close();
		if (list == null || list.size() == 0) {
			return null;
		}
		return list;
	}

	public static List<YdmZcBillCEntity> getbillCInfo(Connection con,
			String billNo) throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("QcmZbsQueryFrm.getJustStoveInfoByBillNo");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, billNo);
		ResultSet rs = ps.executeQuery();
		List<YdmZcBillCEntity> list = EntityTool.getEntitysByRs(rs,
				YdmZcBillCEntity.class);
		rs.close();
		ps.close();
		if (list != null && list.size() > 0) {
			for (YdmZcBillCEntity ydmZcBillCEntity : list) {
				QualityDesignTool.nullConverNullString(ydmZcBillCEntity);
			}
			return list;
		} else {
			return null;
		}
	}
	/**
	 * 质保书上传
	 */
	public CoreReturnObject ZbsUpload(ArrayList<ArrayList<String>> jslist,
			String userName) throws ParseException {
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = null;
		try {
			conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			conn.setAutoCommit(false);
			for (int i = 0; i < jslist.size(); i++) {
				ArrayList<String> list = (ArrayList<String>) jslist.get(i);
				String zbs = list.get(0);
				String bill_no = list.get(1);
				String order_no = list.get(2);
				JSONObject hm = new JSONObject();
				JSONObject hm1 = new JSONObject();
				hm.put("status", "0");//状态
				hm.put("zbs_name",zbs);//电子质保书名称
				hm.put("zbs_id",zbs);//电子质保书ID
				hm.put("bill_of_lading_no",bill_no);//提单号
				hm.put("order_no_erp",order_no);//合同号
				hm.put("stacking_no","");//码单号    备注：检斤单号代替
				hm.put("sg_sign","");//钢种     备注：用钢级代替
				hm.put("sg_std","");//标准
				hm.put("roll_no","");//轧号或卡片号    备注：批号
				hm.put("heat_no","");//炉号
				hm.put("order_user_name","");//订货用户  测试例子：南通通用钢球有限公司 
		        hm.put("order_user_code","");//订货用户ID
		        hm.put("fin_user_cname","");//收货用户  测试例子：南通通用钢球有限公司 
		        hm.put("fin_user_code","");//收货用户ID
		        hm.put("path",""); //存储路径
		        hm.put("company_code","");//帐套   指的是特钢，固定值。   测试例子：GX
		        hm.put("seal_1","");//产品厚/直径 mm
		        hm.put("seal_2","");//产品宽度 mm
		        hm.put("seal_3","");//产品长度 mm
		        hm.put("seal_4","44");//右下角章ID
		        hm.put("seal_5","55");//备用章ID_1
		        hm.put("seal_6","66");//备用章ID_2
		        hm.put("temp1","temp1");//备用1
		        hm.put("temp2","temp2");//备用1
		        hm.put("temp3","temp3");//备用1
		        hm.put("temp4","temp4");//备用1
		        hm.put("temp5","temp5");//备用1
		        hm1.put("serviceId", "THMESQM100");
		        hm1.put("msgBody", hm.toString());
				String result =  callWebserviceASMX(hm1.toString());
			}
		} catch (SQLException sqle) {
			try {
				if (conn != null) {
					conn.rollback();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
			cro.setV_errCode(-1);
			cro.setV_errMsg(sqle.getMessage());
		} finally {
			try {
				if (conn != null && !conn.isClosed()) {
					conn.close();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return cro;
	}
	public static String callWebserviceASMX(String json){
		System.out.println("Start invoking....");
		String str = "";
		try{
			String method = "receiveMessage";
			String endPoint = "http://192.168.10.24:8191/ReceiverService.asmx";
			String soapaction = "http://tempuri.org/"; 
			Service service = new Service();
			Call call = (Call) service.createCall();
			call.setTargetEndpointAddress(new java.net.URL(endPoint));
			call.setOperation(method);
			call.setUseSOAPAction(true);
			call.setSOAPActionURI(soapaction+method);
			call.setOperationName(new QName(soapaction,method));
			call.addParameter(new QName(soapaction, "strDate"), org.apache.axis.encoding.XMLType.XSD_STRING, ParameterMode.IN); 
			call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
			str = (String) call.invoke(new  Object[]{json});
			System.out.println(str);
		}catch(Exception e){
			e.printStackTrace();}
	   return str;
}
	/**
	 * 修改质保书打印状态
	 * 
	 * @param jslist
	 * @param userName
	 * @return
	 * @throws ParseException
	 */
	public CoreReturnObject doUpdate(ArrayList<ArrayList<String>> jslist,
			String userName) throws ParseException {
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = null;
		try {
			conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			conn.setAutoCommit(false);
			PreparedStatement ps = null;
			// 获取数据库当前时间s
			// String dateTime = FrmSteelMakingPlanChange.getSystemTime(conn);
			for (int i = 0; i < jslist.size(); i++) {
				ArrayList<String> list = (ArrayList<String>) jslist.get(i);
				String zbsFlag = list.get(0);
				String billNoSeq = list.get(1);

				// 修改提单质保书打印状态
				String deleteZgM = "UPDATE YDM_ZC_BILL_M T SET T.ZBS_FLAG=? WHERE T.BILL_NO_SEQ=?";
				ps = conn.prepareStatement(deleteZgM);
				ps.setObject(1, zbsFlag);
				ps.setObject(2, billNoSeq);
				ps.executeUpdate();
				ps.close();
			}
			cro.setV_errMsg("修改成功!");

			conn.commit();
		} catch (SQLException sqle) {
			try {
				if (conn != null) {
					conn.rollback();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
			cro.setV_errCode(-1);
			cro.setV_errMsg(sqle.getMessage());
		} finally {
			try {
				if (conn != null && !conn.isClosed()) {
					conn.close();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return cro;
	}
	
	/**
	 * 发送到规划院
	 * @param billNo
	 * @param ordLnDlyPk
	 * @param languageCode
	 * @param zbsEdition
	 * @param isVlid
	 * @return 
	 * @throws Exception
	 */
	public CoreReturnObject uploadfile(String billNo,String ordLnDlyPk ,String zbsEdition,String isVlid) throws Exception{
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		JSONObject pathjson = new JSONObject();
		//JsonArray baseArray = new JsonArray();
		List<JSONObject> list = new ArrayList<JSONObject>();
		try {
			conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			String sqlPath = CoreXmlSqlParsersFactory
					.getSql("QcmZbsQueryFrm.getZbsPath");
			ps = conn.prepareStatement(sqlPath);
			ps.setObject(1, billNo);
			ps.setObject(2, ordLnDlyPk);
			ps.setObject(3,zbsEdition);
			ps.setObject(4,isVlid);
			rs = ps.executeQuery();
			String zbsName = "";
			if(rs.next()) {
				if(rs.getString("IS_UPLOAD").equals("1") && isVlid.equals("0")) {
					   cro.setV_errMsg("质保书已经上传 ，请勿重复操作！！！");
					   cro.setV_errCode(0);
					   return cro;
				}
				pathjson.put("operatorFlag", isVlid.equals("1")?"I":"D");
				pathjson.put("url", "ftp://ftpuser:1064374183@172.54.10.38/");
				pathjson.put("sourceRemoteFile", rs.getString("ZBS_PATH"));
				pathjson.put("fileName", rs.getString("ZBS_NAME")+".pdf");
				zbsName = rs.getString("ZBS_NAME");
			}
			
			if(!pathjson.get("sourceRemoteFile").equals("")) {
				String sqlBase = CoreXmlSqlParsersFactory
						.getSql("QcmZbsQueryFrm.getZbsBase");
				ps = conn.prepareStatement(sqlBase);
				ps.setString(1, billNo);
				ps.setString(2, ordLnDlyPk);
				ResultSet rsBase = ps.executeQuery();
				while(rsBase.next()) {
					JSONObject jsonBase = new JSONObject();
					jsonBase.put("status", isVlid);
					jsonBase.put("zbsName", zbsName);
					jsonBase.put("zbsId", zbsName);
					jsonBase.put("billOfLadingNo", billNo);
					jsonBase.put("orderNoErp", rsBase.getString("PONDER_NO") != null ? rsBase.getString("PONDER_NO") : "");
					jsonBase.put("stackingNo", rsBase.getString("CUSTM_ORDER_NO") != null ? rsBase.getString("CUSTM_ORDER_NO") : "");
					jsonBase.put("sgSign", rsBase.getString("STEELNAME") != null ? rsBase.getString("STEELNAME") : "");
					jsonBase.put("sgStd", rsBase.getString("STD_NAME") != null ? rsBase.getString("STD_NAME") : "");
					jsonBase.put("rollNo", rsBase.getString("LOT_NO") != null ? rsBase.getString("LOT_NO") : "");
					jsonBase.put("heatNo", rsBase.getString("STOVE_NO") != null ? rsBase.getString("STOVE_NO") : "");
					jsonBase.put("orderUserName", rsBase.getString("CUSTOMER_NM") != null ? rsBase.getString("CUSTOMER_NM") : "");
					jsonBase.put("orderUserCode", rsBase.getString("CUSTOMER_NO") != null ? rsBase.getString("CUSTOMER_NO") : "");
					jsonBase.put("finUserCname", rsBase.getString("RECEIV_NM") != null ? rsBase.getString("RECEIV_NM") : "");
					jsonBase.put("finUserCode", rsBase.getString("RECEIV_NO") != null ? rsBase.getString("RECEIV_NO") : "");
					jsonBase.put("path", "");
					jsonBase.put("sealOne", rsBase.getString("ACT_DIMATER") != null ? rsBase.getString("ACT_DIMATER") : "");
					jsonBase.put("sealTwo", rsBase.getString("ACT_HEIGHT") != null ? rsBase.getString("ACT_HEIGHT") : "");
					jsonBase.put("sealThree", rsBase.getString("ACT_LEN") != null ? rsBase.getString("ACT_LEN") : "");
					jsonBase.put("sealFour", "");
					jsonBase.put("sealFive", "");
					jsonBase.put("sealSix", "");
					jsonBase.put("tempOne", "");
					jsonBase.put("tempTwo", "");
					jsonBase.put("tempThree", "");
					jsonBase.put("tempFour", "");
					jsonBase.put("tempFive", "");
					jsonBase.put("matNo", "");
					list.add(jsonBase);
				}
				pathjson.put("messageBody", list);				
				DefaultWebServiceRequest request = new DefaultWebServiceRequest();
				String result = "";
				String s = pathjson.toString();
				   s = s.replaceAll("&", "' || '&' || '"); 
				   s = "<![CDATA["+s+"]]>";
				   request.setMsgBody(s);
				   request.setServiceId("SHGVB5");
				   if(list.size() > 0) {
					   result  = ServiceToCx.callWebserviceASMX("http://172.54.10.24:8191/ReceiverService.asmx",request,
								"receiveMessage",pathjson.toString());	 
					   if(result.equals("200")) {
						   cro.setV_errMsg("上传成功！");
						   cro.setV_errCode(0);
					   }	
					   else {
							 cro.setV_errMsg("接口信息上传失败！");
							 cro.setResult(1);
					   }
				   }
				   //BILL_NO, ORD_LN_DLY_PK, LANGUAGE_CODE, ZBS_EDITION
				   String updatePath = "UPDATE QCM_ZBS_PATH SET IS_UPLOAD = '1' WHERE bill_No = '"+billNo+"' AND ORD_LN_DLY_PK = '"+ordLnDlyPk+"' AND ZBS_EDITION = '"+zbsEdition+"'";
				   PreparedStatement psp = new LoggableStatement(conn, updatePath);
				   psp.execute();
				   psp.close();
				   saveDbLog(conn,"SHGVB5",pathjson.toString(),"提单： "+billNo+ "合同主键： " +ordLnDlyPk, result);
				   conn.commit();
				   return cro;
			}
		}
		finally {
			try {
				if (conn != null && !conn.isClosed()) {
					conn.close();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		  return cro;
	}
	/**
	 * 修改质保书合同
	 * @param jslist
	 * @param userName
	 * @return
	 * @throws ParseException
	 */
	public CoreReturnObject doUpdateOrderNno(ArrayList<ArrayList<String>> jslist,
			String userName) throws ParseException {
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = null;
		try {
			conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			conn.setAutoCommit(false);
			PreparedStatement ps = null;
			// 获取数据库当前时间
			// String dateTime = FrmSteelMakingPlanChange.getSystemTime(conn);
			for (int i = 0; i < jslist.size(); i++) {
				ArrayList<String> list = (ArrayList<String>) jslist.get(i);
				String zbsOrderNno = list.get(0);
				String billNoSeq = list.get(1);

				// 修改提单质保书合同
				String deleteZgM = "UPDATE YDM_ZC_BILL_M T SET T.ZBS_ORDER_NO=?,T.ZBS_ORDER_NO_NAME = ?,T.ZBS_ORDER_NO_TIME = SYSDATE WHERE T.BILL_NO_SEQ=?";
				ps = conn.prepareStatement(deleteZgM);
				ps.setObject(1, zbsOrderNno);
				ps.setObject(2, userName);
				ps.setObject(3, billNoSeq);
				ps.executeUpdate();
				ps.close();
			}
			cro.setV_errMsg("修改成功!");

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


	/**
	 * 修改质保书许可证号，检验号
	 * 
	 * @param jslist
	 * @param userName
	 * @return
	 * @throws ParseException
	 */
	public CoreReturnObject doUpdateLin(ArrayList<ArrayList<String>> jslist,
			String userName) throws ParseException {
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = null;
		try {
			conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			conn.setAutoCommit(false);
			PreparedStatement ps = null;
			// 获取数据库当前时间
			// String dateTime = FrmSteelMakingPlanChange.getSystemTime(conn);
			for (int i = 0; i < jslist.size(); i++) {
				ArrayList<String> list = (ArrayList<String>) jslist.get(i);
				String licenseNo = list.get(0);
				String checkNo = list.get(1);
				String billNo = list.get(2);
				String billNoSeq = list.get(3);

				// 修改提单质保书打印状态
				String deleteZgM = "UPDATE YDM_ZC_BILL_M T SET T.LICENSE_NO=?,T.CHECK_NO=? WHERE T.BILL_NO=? AND T.BILL_NO_SEQ=?";
				ps = conn.prepareStatement(deleteZgM);
				ps.setObject(1, licenseNo);
				ps.setObject(2, checkNo);
				ps.setObject(3, billNo);
				ps.setObject(4, billNoSeq);
				ps.executeUpdate();
				ps.close();
			}
			cro.setV_errMsg("修改成功!");

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

	/**
	 * 新增质保书
	 * 
	 * @param jslist
	 * @param userName
	 * @return
	 * @throws ParseException
	 */
	public CoreReturnObject doAdd(String zbsName, String zbsPath,
			String billNoSeq, String billNo, String ordLnDlyPk,
			String userName, String askSubItmeValNo, String metricSystemNo,
			String askSubItmeVal) throws ParseException {
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = null;
		try {
			conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			conn.setAutoCommit(false);
			PreparedStatement ps = null;
			ResultSet rs = null;

			int num = 0;
			String judgeStoveNo = "";
			String batchNo = "";
			String orderNo = "";
			String orderSeq = "";
			String ordLnPk = "";
			String zbsflag = "";
			// 查询打印状态
			String sqlM = "SELECT NVL(T.ZBS_FLAG,0) ZBS_FLAG FROM YDM_ZC_BILL_M T WHERE T.BILL_NO_SEQ=? ";
			ps = conn.prepareStatement(sqlM);
			ps.setObject(1, billNoSeq);
			rs = ps.executeQuery();
			if (rs.next()) {
				zbsflag = rs.getString("ZBS_FLAG");
			}
			rs.close();
			ps.close();
			if (!zbsflag.equals("0")) {
				cro.setV_errMsg("当前订单已质保书打印,不能保存!");
				return cro;
			}
			// 查询提单从表表记录
			String sqlC = "SELECT T.ORDER_NO,T.ORDER_SEQ,T.ORD_LN_PK,T.JUDGE_STOVE_NO,T.BATCH_NO,SUM(T.ACT_COUNT) ACT_COUNT FROM YDM_ZC_BILL_C T WHERE T.BILL_NO=? AND T.ORD_LN_DLY_PK=? GROUP BY T.JUDGE_STOVE_NO,T.BATCH_NO,T.ORDER_NO,T.ORDER_SEQ,T.ORD_LN_PK";
			ps = conn.prepareStatement(sqlC);
			ps.setObject(1, billNo);
			ps.setObject(2, ordLnDlyPk);
			rs = ps.executeQuery();
			if (rs.next()) {
				// num = rs.getInt("ACT_COUNT");
				judgeStoveNo = rs.getString("JUDGE_STOVE_NO");
				batchNo = rs.getString("BATCH_NO");
				orderNo = rs.getString("ORDER_NO");
				orderSeq = rs.getString("ORDER_SEQ");
				ordLnPk = rs.getString("ORD_LN_PK");
			}
			rs.close();
			ps.close();

			int count = 0;
			// 判断是否有重复质保书
			String seleteLangZbs = "SELECT  COUNT(*) COUNT FROM QCM_ZBS_PATH T  WHERE T.BILL_NO=? AND T.ZBS_NAME=? AND T.ORD_LN_DLY_PK=?";
			ps = conn.prepareStatement(seleteLangZbs);
			ps.setObject(1, billNo);
			ps.setObject(2, zbsName);
			ps.setObject(3, ordLnDlyPk);
			rs = ps.executeQuery();
			if (rs.next()) {
				count = rs.getInt("COUNT");
			}
			rs.close();
			ps.close();

			if (count != 0) {
				cro.setV_errMsg("存在相同的语言质保书,不能保存!");
				return cro;
			}

			String selectZbsNum = "SELECT  COUNT(*) COUNT FROM QCM_ZBS_PATH T  WHERE T.BILL_NO=? AND T.LANGUAGE_CODE=? AND T.ORD_LN_DLY_PK=?";
			ps = conn.prepareStatement(selectZbsNum);
			ps.setObject(1, billNo);
			ps.setObject(2, askSubItmeValNo);
			ps.setObject(3, ordLnDlyPk);
			rs = ps.executeQuery();
			if (rs.next()) {
				num = rs.getInt("COUNT");
			}
			rs.close();
			ps.close();
			if (num == 0) {
				// 新增多语言质保书
				String sqlLangZbs = CoreXmlSqlParsersFactory
						.getSql("QcmZbsQueryFrm.AddZbsLang");
				ps = conn.prepareStatement(sqlLangZbs);
				ps.setObject(1, billNo);
				ps.setObject(2, askSubItmeValNo);
				ps.setObject(3, askSubItmeVal);
				ps.setObject(4, zbsPath);
				ps.setObject(5, orderNo + "/" + orderSeq);
				ps.setObject(6, ordLnDlyPk);
				ps.setObject(7, zbsName);
				ps.setObject(8, metricSystemNo);
				ps.setObject(9, userName);
				ps.executeUpdate();
				ps.close();
			} else {
				// 修改质保书
				String sqlLangZbs = CoreXmlSqlParsersFactory
						.getSql("QcmZbsQueryFrm.UpdateZbsLang");
				ps = conn.prepareStatement(sqlLangZbs);
				ps.setObject(1, zbsPath);
				ps.setObject(2, zbsName);
				ps.setObject(3, billNo);
				ps.setObject(4, askSubItmeValNo);
				ps.setObject(5, ordLnDlyPk);
				ps.executeUpdate();
				ps.close();
			}

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

	/**
	 * 新增质保书
	 * 
	 * @param zbsName
	 * @param zbsPath
	 * @param billNo
	 * @param ordLnDlyPk
	 * @param userName
	 * @param askSubItmeValNo
	 * @param metricSystemNo
	 * @param askSubItmeVal
	 * @param zbsEdition
	 * @return
	 * @throws ParseException
	 */
	public CoreReturnObject doAddNew(ArrayList<String> list) throws ParseException {
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = null;
		try {
			conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			conn.setAutoCommit(false);
			PreparedStatement ps = null;
			ResultSet rs = null;

			String orderNo = "";
			String orderSeq = "";
			String billNo = list.get(0);
			String askSubItmeValNo = list.get(1);
			String askSubItmeVal = list.get(2);
			String zbsPath = list.get(3);
			String ordLnDlyPk = list.get(4);
			String zbsName = list.get(5);
			String metricSystemNo = list.get(6);
			String userName = list.get(7);
			String zbsTypeCode = list.get(8);
			String zbsTypeDesc = list.get(9);
			String zbsEdition = list.get(10);

			// 查询提单从表表记录
			String sqlC = "SELECT T.ORDER_NO,T.ORDER_SEQ,T.ORD_LN_PK,T.JUDGE_STOVE_NO,T.BATCH_NO,SUM(T.ACT_COUNT) ACT_COUNT FROM YDM_ZC_BILL_C T WHERE T.BILL_NO=? AND T.ORD_LN_DLY_PK=? GROUP BY T.JUDGE_STOVE_NO,T.BATCH_NO,T.ORDER_NO,T.ORDER_SEQ,T.ORD_LN_PK";
			ps = conn.prepareStatement(sqlC);
			ps.setObject(1, billNo);
			ps.setObject(2, ordLnDlyPk);
			rs = ps.executeQuery();
			if (rs.next()) {
				orderNo = rs.getString("ORDER_NO");
				orderSeq = rs.getString("ORDER_SEQ");
			}
			rs.close();
			ps.close();

			String sqlLangZbs = CoreXmlSqlParsersFactory
					.getSql("QcmZbsQueryFrm.AddZbsLangNEW");
			ps = conn.prepareStatement(sqlLangZbs);
			ps.setObject(1, billNo);
			ps.setObject(2, askSubItmeValNo);
			ps.setObject(3, askSubItmeVal);
			ps.setObject(4, zbsPath);
			ps.setObject(5, orderNo + "/" + orderSeq);
			ps.setObject(6, ordLnDlyPk);
			ps.setObject(7, zbsName);
			ps.setObject(8, metricSystemNo);
			ps.setObject(9, userName);
			ps.setObject(10, zbsTypeCode);
			ps.setObject(11, zbsTypeDesc);
			ps.setObject(12, zbsEdition);
			ps.executeUpdate();
			ps.close();

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

	/**
	 * 删除质保书
	 * 
	 * @param jslist
	 * @param userName
	 * @return
	 * @throws ParseException
	 */
	public CoreReturnObject doDelete(String zbsName, String billNoSeq,
			String billNo, String ordLnDlyPk, String askSubItmeValNo)
			throws ParseException {
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = null;
		try {
			conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			conn.setAutoCommit(false);
			PreparedStatement ps = null;
			ResultSet rs = null;

			int num = 0;
			String zbsflag = "";
			// 查询打印状态
			String sqlM = "SELECT NVL(T.ZBS_FLAG,0) ZBS_FLAG FROM YDM_ZC_BILL_M T WHERE T.BILL_NO_SEQ=? ";
			ps = conn.prepareStatement(sqlM);
			ps.setObject(1, billNoSeq);
			rs = ps.executeQuery();
			if (rs.next()) {
				zbsflag = rs.getString("ZBS_FLAG");
			}
			rs.close();
			ps.close();
			

			String selectZbsNum = "SELECT  COUNT(*) COUNT FROM QCM_ZBS_PATH T  WHERE T.BILL_NO=? AND T.LANGUAGE_CODE=? AND T.ORD_LN_DLY_PK=? AND T.ZBS_NAME_JG IS  NULL";
			ps = conn.prepareStatement(selectZbsNum);
			ps.setObject(1, billNo);
			ps.setObject(2, askSubItmeValNo);
			ps.setObject(3, ordLnDlyPk);
			rs = ps.executeQuery();
			if (rs.next()) {
				num = rs.getInt("COUNT");
			}
			rs.close();
			ps.close();
			if (num == 1) {
				// 删除多质保书
				String sqlAddZbsC = "DELETE QCM_ZBS_PATH  WHERE BILL_NO = ? AND ORD_LN_DLY_PK = ? AND LANGUAGE_CODE = ? AND ZBS_NAME=? ";
				ps = conn.prepareStatement(sqlAddZbsC);
				ps.setObject(1, billNo);
				ps.setObject(2, ordLnDlyPk);
				ps.setObject(3, askSubItmeValNo);
				ps.setObject(4, zbsName);
				ps.executeUpdate();
				ps.close();
			} else {
				String sqlAddZbsC = CoreXmlSqlParsersFactory
						.getSql("QcmZbsQueryFrm.UpdateZbsLang");
				ps = conn.prepareStatement(sqlAddZbsC);
				ps.setObject(1, null);
				ps.setObject(2, null);
				ps.setObject(3, billNo);
				ps.setObject(4, askSubItmeValNo);
				ps.setObject(5, ordLnDlyPk);
				ps.executeUpdate();
				ps.close();
			}

			int count = 0;
			// 查詢是否全部刪除
			String sqlPath = "SELECT count(*) count FROM QCM_ZBS_PATH T WHERE  BILL_NO = ? AND ORD_LN_DLY_PK = ? AND ZBS_NUM IS NOT NULL AND ZBS_NUM>0 ";
			ps = conn.prepareStatement(sqlPath);
			ps.setObject(1, billNo);
			ps.setObject(2, ordLnDlyPk);
			rs = ps.executeQuery();
			if (rs.next()) {
				count = rs.getInt("count");
			}
			rs.close();
			ps.close();
			if (count == 0) {
				String deleteZgM = "UPDATE YDM_ZC_BILL_M T SET T.ZBS_FLAG='0',T.ZBS_NUM='',T.ZBS_TIME='' WHERE T.BILL_NO_SEQ=?";
				ps = conn.prepareStatement(deleteZgM);
				ps.setObject(1, billNoSeq);
				ps.executeUpdate();
				ps.close();
			}
			cro.setV_errMsg("删除成功!");
			conn.commit();
		} catch (SQLException sqle) {
			try {
				if (conn != null) {
					conn.rollback();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
			cro.setV_errCode(-1);
			cro.setV_errMsg(sqle.getMessage());
		} finally {
			try {
				if (conn != null && !conn.isClosed()) {
					conn.close();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return cro;
	}

	/**
	 * 打印质保书
	 * 
	 * @param jslist
	 * @param userName
	 * @return
	 * @throws ParseException
	 */
	public CoreReturnObject doUpdatePrintData(String billNoSeq,
			String userName, String zbsName, String billNo, String ordLnDlyPk)
			throws ParseException {
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = null;
		try {
			conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			conn.setAutoCommit(false);
			PreparedStatement ps = null;
			// String dateTime = FrmSteelMakingPlanChange.getSystemTime(conn);
			// 修改质保书路径
			String deleteZgM = "UPDATE YDM_ZC_BILL_M T SET T.ZBS_FLAG='1',T.LOCK_BILL_FLAG='1',T.ZBS_TIME=SYSDATE,T.ZBS_NUM=TO_NUMBER(NVL(T.ZBS_NUM,0))+1 WHERE T.BILL_NO_SEQ=?";
			ps = conn.prepareStatement(deleteZgM);
			ps.setObject(1, billNoSeq);
			ps.executeUpdate();
			ps.close();

			// 修改质保书路径
			String updateLan = "UPDATE QCM_ZBS_PATH SET ZBS_NUM=TO_NUMBER(NVL(ZBS_NUM,0))+1,ZBS_TIME=SYSDATE,PRINT_NAME=?  WHERE BILL_NO = ? AND ORD_LN_DLY_PK = ? AND ZBS_NAME=?";
			ps = conn.prepareStatement(updateLan);
			ps.setObject(1, userName);
			ps.setObject(2, billNo);
			ps.setObject(3, ordLnDlyPk);
			ps.setObject(4, zbsName);
			ps.executeUpdate();
			ps.close();

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

	/**
	 * 打印质保书
	 * 
	 * @param jslist
	 * @param userName
	 * @return
	 * @throws ParseException
	 */
	public CoreReturnObject doUpdatePrintDataAll(String billNoSeq,
			String userName, String billNo, String ordLnDlyPk,
			ArrayList<String> list) throws ParseException {
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = null;
		try {
			conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			conn.setAutoCommit(false);
			PreparedStatement ps = null;
			// String dateTime = FrmSteelMakingPlanChange.getSystemTime(conn);
			int count = 0;
			for (int i = 0; i < list.size(); i++) {
				String zbsName = list.get(i);
				// 修改质保书路径
				String updateLan = "UPDATE QCM_ZBS_PATH SET ZBS_NUM=TO_NUMBER(NVL(ZBS_NUM,0))+1,ZBS_TIME=SYSDATE,PRINT_NAME=?  WHERE BILL_NO = ? AND ORD_LN_DLY_PK = ? AND ZBS_NAME=? AND IS_VALID = '有效'";
				ps = conn.prepareStatement(updateLan);
				ps.setObject(1, userName);
				ps.setObject(2, billNo);
				ps.setObject(3, ordLnDlyPk);
				ps.setObject(4, zbsName);
				ps.executeUpdate();
				ps.close();

				count++;
			}
			// 修改质保书路径
			String deleteZgM = "UPDATE YDM_ZC_BILL_M T SET T.ZBS_FLAG='1',T.LOCK_BILL_FLAG='1',T.ZBS_TIME=SYSDATE,T.ZBS_NUM=TO_NUMBER(NVL(T.ZBS_NUM,0))+'"
					+ count + "' WHERE T.BILL_NO_SEQ=?";
			ps = conn.prepareStatement(deleteZgM);
			ps.setObject(1, billNoSeq);
			ps.executeUpdate();
			ps.close();
			cro.setV_errMsg("打印成功!");
			conn.commit();
		} catch (SQLException sqle) {
			try {
				if (conn != null) {
					conn.rollback();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
			cro.setV_errCode(-1);
			cro.setV_errMsg(sqle.getMessage());
		} finally {
			try {
				if (conn != null && !conn.isClosed()) {
					conn.close();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return cro;
	}
	
	/**
	 * 解锁
	 * @param billNoSeq
	 * @return
	 * @throws ParseException
	 */
	public CoreReturnObject doUnLock(String billNoSeq) throws ParseException {
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = null;
		try {
			conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			conn.setAutoCommit(false);
			PreparedStatement ps = null;
			// 修改质保书路径
			String deleteZgM = "UPDATE YDM_ZC_BILL_M T SET T.LOCK_BILL_FLAG='0' WHERE T.BILL_NO_SEQ=?";
			ps = conn.prepareStatement(deleteZgM);
			ps.setObject(1, billNoSeq);
			ps.executeUpdate();
			ps.close();
			cro.setV_errMsg("解锁成功!");
			conn.commit();
		} catch (SQLException sqle) {
			try {
				if (conn != null) {
					conn.rollback();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
			cro.setV_errCode(-1);
			cro.setV_errMsg(sqle.getMessage());
		} finally {
			try {
				if (conn != null && !conn.isClosed()) {
					conn.close();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return cro;
	}

	/***
	 * 查询接箍情况
	 * 
	 * @param areaNo
	 * @return
	 */
	public CoreReturnObject QueryCoupling(String judgeStoveNo, String batchNo) {
		return this.getDataBySqlID("QcmZbsQueryFrm.QueryCoupling",
				new Object[] { judgeStoveNo, batchNo });
	}

	/**
	 * 查询接箍情况
	 * 
	 * @param BillNo
	 * @return
	 */
	public CoreReturnObject QueryCoupling(String BillNo) {
		return this.getDataBySqlID("QcmZbsQueryFrm.QueryCouplingByBillNo",
				new Object[] { BillNo });
	}

	/**
	 * 新增接箍质保书
	 * 
	 * @param jslist
	 * @param userName
	 * @return
	 * @throws ParseException
	 */
	public CoreReturnObject doAddJG(String zbsNameJG, String zbsPath,
			String billNoSeq, String billNo, String ordLnDlyPk,
			String userName, String askSubItmeValNo, String metricSystemNo,
			String askSubItmeVal) throws ParseException {
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = null;
		try {
			conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			conn.setAutoCommit(false);
			PreparedStatement ps = null;
			ResultSet rs = null;
			int num = 0;
			String orderNo = "";
			String orderSeq = "";
			String zbsflag = "";
			// 查询打印状态
			String sqlM = "SELECT NVL(T.ZBS_FLAG,0) ZBS_FLAG FROM YDM_ZC_BILL_M T WHERE T.BILL_NO_SEQ=? ";
			ps = conn.prepareStatement(sqlM);
			ps.setObject(1, billNoSeq);
			rs = ps.executeQuery();
			if (rs.next()) {
				zbsflag = rs.getString("ZBS_FLAG");
			}
			rs.close();
			ps.close();
			if (!zbsflag.equals("0")) {
				cro.setV_errMsg("当前订单已质保书打印,不能保存!");
				return cro;
			}
			// 查询提单从表表记录
			String sqlC = "SELECT T.ORDER_NO,T.ORDER_SEQ,T.ORD_LN_PK,T.JUDGE_STOVE_NO,T.BATCH_NO,SUM(T.ACT_COUNT) ACT_COUNT FROM YDM_ZC_BILL_C T WHERE T.BILL_NO=? AND T.ORD_LN_DLY_PK=? GROUP BY T.JUDGE_STOVE_NO,T.BATCH_NO,T.ORDER_NO,T.ORDER_SEQ,T.ORD_LN_PK";
			ps = conn.prepareStatement(sqlC);
			ps.setObject(1, billNo);
			ps.setObject(2, ordLnDlyPk);
			rs = ps.executeQuery();
			if (rs.next()) {

				orderNo = rs.getString("ORDER_NO");
				orderSeq = rs.getString("ORDER_SEQ");
			}
			rs.close();
			ps.close();

			int count = 0;
			// 判断是否有重复质保书
			String seleteLangZbs = "SELECT  COUNT(*) COUNT FROM QCM_ZBS_PATH T  WHERE T.BILL_NO=? AND T.ZBS_NAME_JG=? AND T.ORD_LN_DLY_PK=?";
			ps = conn.prepareStatement(seleteLangZbs);
			ps.setObject(1, billNo);
			ps.setObject(2, zbsNameJG);
			ps.setObject(3, ordLnDlyPk);
			rs = ps.executeQuery();
			if (rs.next()) {
				count = rs.getInt("COUNT");
			}
			rs.close();
			ps.close();

			if (count != 0) {
				cro.setV_errMsg("存在相同的语言质保书,不能保存!");
				return cro;
			}

			String selectZbsNum = "SELECT  COUNT(*) COUNT FROM QCM_ZBS_PATH T  WHERE T.BILL_NO=? AND T.LANGUAGE_CODE=? AND T.ORD_LN_DLY_PK=?";
			ps = conn.prepareStatement(selectZbsNum);
			ps.setObject(1, billNo);
			ps.setObject(2, askSubItmeValNo);
			ps.setObject(3, ordLnDlyPk);
			rs = ps.executeQuery();
			if (rs.next()) {
				num = rs.getInt("COUNT");
			}
			rs.close();
			ps.close();

			if (num == 0) {
				// 新增多语言质保书
				String sqlLangZbs = CoreXmlSqlParsersFactory
						.getSql("QcmZbsQueryFrm.AddZbsLangJG");
				ps = conn.prepareStatement(sqlLangZbs);
				ps.setObject(1, billNo);
				ps.setObject(2, askSubItmeValNo);
				ps.setObject(3, askSubItmeVal);
				ps.setObject(4, zbsPath);
				ps.setObject(5, orderNo + "/" + orderSeq);
				ps.setObject(6, ordLnDlyPk);
				ps.setObject(7, zbsNameJG);
				ps.setObject(8, metricSystemNo);
				ps.setObject(9, userName);
				ps.executeUpdate();
				ps.close();
			} else {
				// 修改质保书
				String sqlLangZbs = CoreXmlSqlParsersFactory
						.getSql("QcmZbsQueryFrm.UpdateZbsLangJG");
				ps = conn.prepareStatement(sqlLangZbs);
				ps.setObject(1, zbsPath);
				ps.setObject(2, zbsNameJG);
				ps.setObject(3, billNo);
				ps.setObject(4, askSubItmeValNo);
				ps.setObject(5, ordLnDlyPk);
				ps.executeUpdate();
				ps.close();
			}
			cro.setV_errMsg("保存成功!");
			conn.commit();
		} catch (SQLException sqle) {
			try {
				if (conn != null) {
					conn.rollback();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
			cro.setV_errCode(-1);
			cro.setV_errMsg(sqle.getMessage());
		} finally {
			try {
				if (conn != null && !conn.isClosed()) {
					conn.close();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return cro;
	}

	/**
	 * 删除接箍质保书
	 * 
	 * @param jslist
	 * @param userName
	 * @return
	 * @throws ParseException
	 */
	public CoreReturnObject doDeleteJG(String zbsNameJG, String billNoSeq,
			String billNo, String ordLnDlyPk, String askSubItmeValNo)
			throws ParseException {
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = null;
		try {
			conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			conn.setAutoCommit(false);
			PreparedStatement ps = null;
			ResultSet rs = null;
			int num = 0;

			String selectZbsNum = "SELECT  COUNT(*) COUNT FROM QCM_ZBS_PATH T  WHERE T.BILL_NO=? AND T.LANGUAGE_CODE=? AND T.ORD_LN_DLY_PK=? AND T.ZBS_NAME IS  NULL";
			ps = conn.prepareStatement(selectZbsNum);
			ps.setObject(1, billNo);
			ps.setObject(2, askSubItmeValNo);
			ps.setObject(3, ordLnDlyPk);
			rs = ps.executeQuery();
			if (rs.next()) {
				num = rs.getInt("COUNT");
			}
			rs.close();
			ps.close();
			if (num == 1) {
				// 删除多质保书
				String sqlAddZbsC = "DELETE QCM_ZBS_PATH  WHERE BILL_NO = ? AND ORD_LN_DLY_PK = ? AND LANGUAGE_CODE = ? AND ZBS_NAME_JG=? ";
				ps = conn.prepareStatement(sqlAddZbsC);
				ps.setObject(1, billNo);
				ps.setObject(2, ordLnDlyPk);
				ps.setObject(3, askSubItmeValNo);
				ps.setObject(4, zbsNameJG);
				ps.executeUpdate();
				ps.close();
			} else {
				String sqlAddZbsC = CoreXmlSqlParsersFactory
						.getSql("QcmZbsQueryFrm.UpdateZbsLangJG");
				ps = conn.prepareStatement(sqlAddZbsC);
				ps.setObject(1, null);
				ps.setObject(2, null);
				ps.setObject(3, billNo);
				ps.setObject(4, askSubItmeValNo);
				ps.setObject(5, ordLnDlyPk);
				ps.executeUpdate();
				ps.close();
			}
			int count = 0;
			// 查詢是否全部刪除
			String sqlPath = "SELECT count(*) count FROM QCM_ZBS_PATH T WHERE  BILL_NO = ? AND ORD_LN_DLY_PK = ? AND ZBS_NUM IS NOT NULL AND ZBS_NUM>0 ";
			ps = conn.prepareStatement(sqlPath);
			ps.setObject(1, billNo);
			ps.setObject(2, ordLnDlyPk);
			rs = ps.executeQuery();
			if (rs.next()) {
				count = rs.getInt("count");
			}
			rs.close();
			ps.close();
			if (count == 0) {
				String deleteZgM = "UPDATE YDM_ZC_BILL_M T SET T.ZBS_FLAG='0',T.ZBS_NUM='',T.ZBS_TIME='' WHERE T.BILL_NO_SEQ=?";
				ps = conn.prepareStatement(deleteZgM);
				ps.setObject(1, billNoSeq);
				ps.executeUpdate();
				ps.close();
			}
			cro.setV_errMsg("删除成功!");
			conn.commit();
		} catch (SQLException sqle) {
			try {
				if (conn != null) {
					conn.rollback();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
			cro.setV_errCode(-1);
			cro.setV_errMsg(sqle.getMessage());
		} finally {
			try {
				if (conn != null && !conn.isClosed()) {
					conn.close();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return cro;
	}

	/**
	 * 新增招标质保书
	 * 
	 * @param jslist
	 * @param userName
	 * @return
	 * @throws ParseException
	 */
	public CoreReturnObject doAddZB(String zbsNameZB, String zbsPath,
			String billNoSeq, String billNo, String ordLnDlyPk,
			String userName, String askSubItmeValNo, String metricSystemNo,
			String askSubItmeVal) throws ParseException {
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = null;
		try {
			conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			conn.setAutoCommit(false);
			PreparedStatement ps = null;
			ResultSet rs = null;
			int num = 0;
			String orderNo = "";
			String orderSeq = "";
			int count = 0;
			// 判断是否有重复质保书
			String seleteLangZbs = "SELECT  COUNT(*) COUNT FROM QCM_ZBS_PATH T  WHERE T.BILL_NO=? AND T.ZBS_NAME_ZB=? AND T.ORD_LN_DLY_PK=?";
			ps = conn.prepareStatement(seleteLangZbs);
			ps.setObject(1, billNo);
			ps.setObject(2, zbsNameZB);
			ps.setObject(3, ordLnDlyPk);
			rs = ps.executeQuery();
			if (rs.next()) {
				count = rs.getInt("COUNT");
			}
			rs.close();
			ps.close();

			if (count != 0) {
				cro.setV_errMsg("存在相同的语言质保书,不能保存!");
				return cro;
			}

			String selectZbsNum = "SELECT  COUNT(*) COUNT FROM QCM_ZBS_PATH T  WHERE T.BILL_NO=? AND T.LANGUAGE_CODE=? AND T.ORD_LN_DLY_PK=?";
			ps = conn.prepareStatement(selectZbsNum);
			ps.setObject(1, billNo);
			ps.setObject(2, askSubItmeValNo);
			ps.setObject(3, ordLnDlyPk);
			rs = ps.executeQuery();
			if (rs.next()) {
				num = rs.getInt("COUNT");
			}
			rs.close();
			ps.close();

			if (num == 0) {
				// 新增多语言质保书
				String sqlLangZbs = CoreXmlSqlParsersFactory
						.getSql("QcmZbsQueryFrm.AddZbsLangZB");
				ps = conn.prepareStatement(sqlLangZbs);
				ps.setObject(1, billNo);
				ps.setObject(2, askSubItmeValNo);
				ps.setObject(3, askSubItmeVal);
				ps.setObject(4, zbsPath);
				ps.setObject(5, orderNo + "/" + orderSeq);
				ps.setObject(6, ordLnDlyPk);
				ps.setObject(7, zbsNameZB);
				ps.setObject(8, metricSystemNo);
				ps.setObject(9, userName);
				ps.executeUpdate();
				ps.close();
			} else {
				// 修改质保书
				String sqlLangZbs = CoreXmlSqlParsersFactory
						.getSql("QcmZbsQueryFrm.UpdateZbsLangZB");
				ps = conn.prepareStatement(sqlLangZbs);
				ps.setObject(1, zbsPath);
				ps.setObject(2, zbsNameZB);
				ps.setObject(3, billNo);
				ps.setObject(4, askSubItmeValNo);
				ps.setObject(5, ordLnDlyPk);
				ps.executeUpdate();
				ps.close();
			}
			cro.setV_errMsg("保存成功!");
			conn.commit();
		} catch (SQLException sqle) {
			try {
				if (conn != null) {
					conn.rollback();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
			cro.setV_errCode(-1);
			cro.setV_errMsg(sqle.getMessage());
		} finally {
			try {
				if (conn != null && !conn.isClosed()) {
					conn.close();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return cro;
	}

	/**
	 * 删除招标质保书
	 * 
	 * @param jslist
	 * @param userName
	 * @return
	 * @throws ParseException
	 */
	public CoreReturnObject doDeleteZB(String zbsNameZB, String billNoSeq,
			String billNo, String ordLnDlyPk, String askSubItmeValNo)
			throws ParseException {
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = null;
		try {
			conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			conn.setAutoCommit(false);
			PreparedStatement ps = null;
			ResultSet rs = null;
			int num = 0;

			String selectZbsNum = "SELECT  COUNT(*) COUNT FROM QCM_ZBS_PATH T  WHERE T.BILL_NO=? AND T.LANGUAGE_CODE=? AND T.ORD_LN_DLY_PK=? AND T.ZBS_NAME IS  NULL";
			ps = conn.prepareStatement(selectZbsNum);
			ps.setObject(1, billNo);
			ps.setObject(2, askSubItmeValNo);
			ps.setObject(3, ordLnDlyPk);
			rs = ps.executeQuery();
			if (rs.next()) {
				num = rs.getInt("COUNT");
			}
			rs.close();
			ps.close();
			if (num == 1) {
				// 删除多质保书
				String sqlAddZbsC = "DELETE QCM_ZBS_PATH  WHERE BILL_NO = ? AND ORD_LN_DLY_PK = ? AND LANGUAGE_CODE = ? AND ZBS_NAME_ZB=? ";
				ps = conn.prepareStatement(sqlAddZbsC);
				ps.setObject(1, billNo);
				ps.setObject(2, ordLnDlyPk);
				ps.setObject(3, askSubItmeValNo);
				ps.setObject(4, zbsNameZB);
				ps.executeUpdate();
				ps.close();
			} else {
				String sqlAddZbsC = CoreXmlSqlParsersFactory
						.getSql("QcmZbsQueryFrm.UpdateZbsLangZB");
				ps = conn.prepareStatement(sqlAddZbsC);
				ps.setObject(1, null);
				ps.setObject(2, null);
				ps.setObject(3, billNo);
				ps.setObject(4, askSubItmeValNo);
				ps.setObject(5, ordLnDlyPk);
				ps.executeUpdate();
				ps.close();
			}
			int count = 0;
			// 查詢是否全部刪除
			String sqlPath = "SELECT count(*) count FROM QCM_ZBS_PATH T WHERE  BILL_NO = ? AND ORD_LN_DLY_PK = ? AND ZBS_NUM IS NOT NULL AND ZBS_NUM>0 ";
			ps = conn.prepareStatement(sqlPath);
			ps.setObject(1, billNo);
			ps.setObject(2, ordLnDlyPk);
			rs = ps.executeQuery();
			if (rs.next()) {
				count = rs.getInt("count");
			}
			rs.close();
			ps.close();
			if (count == 0) {
				String deleteZgM = "UPDATE YDM_ZC_BILL_M T SET T.ZBS_FLAG='0',T.ZBS_NUM='',T.ZBS_TIME='' WHERE T.BILL_NO_SEQ=?";
				ps = conn.prepareStatement(deleteZgM);
				ps.setObject(1, billNoSeq);
				ps.executeUpdate();
				ps.close();
			}
			cro.setV_errMsg("删除成功!");
			conn.commit();
		} catch (SQLException sqle) {
			try {
				if (conn != null) {
					conn.rollback();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
			cro.setV_errCode(-1);
			cro.setV_errMsg(sqle.getMessage());
		} finally {
			try {
				if (conn != null && !conn.isClosed()) {
					conn.close();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return cro;
	}

	/**
	 * 质保书版本
	 * 
	 * @param billNo
	 * @param ordLnDlyPk
	 * @return
	 */
	public CoreReturnObject getZbsEdition(String billNo, String ordLnDlyPk) {
		return this.getDataBySqlID("QcmZbsQueryFrm.getZbsEdition",
				new Object[] { billNo, ordLnDlyPk });
	}
	
	/**
	 * 查询合同是否有打印CE标识
	 * @param orderNo
	 * @return
	 */
	public CoreReturnObject getOrderCE(String ordLnPk) {
		return this.getDataBySqlID("QcmZbsQueryFrm.getOrderCE",
				new Object[] { ordLnPk });
	}
	/**
	 * 查询合同是否有打印EAC标识
	 * @param orderNo
	 * @return
	 */
	public CoreReturnObject getOrderEAC(String ordLnPk) {
		return this.getDataBySqlID("QcmZbsQueryFrm.getOrderEAC",
				new Object[] { ordLnPk });
	}
	
	/**
	 * 作废
	 * @param zbsName
	 * @param billNoSeq
	 * @param billNo
	 * @param ordLnDlyPk
	 * @param askSubItmeValNo
	 * @return
	 * @throws ParseException
	 */
	public CoreReturnObject doWaste(String billNo, String ordLnDlyPk, String zbsEdition, String userName)
			throws ParseException {
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = null;
		try {
			conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			conn.setAutoCommit(false);
			PreparedStatement ps = null;
			ResultSet rs = null;

			String sql = "UPDATE QCM_ZBS_PATH  T SET T.IS_VALID = '0',T.WASTE_NAME = ?,T.WASTE_TIME = SYSDATE  WHERE BILL_NO = ? AND ORD_LN_DLY_PK = ? AND ZBS_EDITION = ? ";
			ps = conn.prepareStatement(sql);
			ps.setObject(1, userName);
			ps.setObject(2, billNo);
			ps.setObject(3, ordLnDlyPk);
			ps.setObject(4, zbsEdition);
			ps.executeUpdate();
			ps.close();
			cro.setV_errMsg("作废成功!");
			conn.commit();
//			try {
//				this.uploadfile(billNo, ordLnDlyPk, zbsEdition, "0");
//			} catch (Exception e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}
		} catch (SQLException sqle) {
			try {
				if (conn != null) {
					conn.rollback();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
			cro.setV_errCode(-1);
			cro.setV_errMsg(sqle.getMessage());
		} finally {
			try {
				if (conn != null && !conn.isClosed()) {
					conn.close();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return cro;
	}
	
	public CoreReturnObject UpdateLaguageAndType(ArrayList<ArrayList<String>> list) {
		CoreReturnObject cro = new CoreReturnObject();
		ArrayList<String> sqllist = new ArrayList<String>();
		ArrayList<Object[]> parmlist = new ArrayList<Object[]>();
		for (int i = 0; i < list.size(); i++) {
			String sql = "Update YDM_ZC_BILL_M t SET T.LANGUAGE_NAME = ? ,LANGUAGE_CODE = ? ,ZBS_TYPE_DESC = ?,ZBS_TYPE_CODE =? WHERE BILL_NO_SEQ = ?";
			sqllist.add(sql);
			parmlist.add(list.get(i).toArray());

		}
		cro = this.setData(sqllist, parmlist);
		if(cro.getV_errCode()>=0){
			cro.setV_errMsg("修改成功!");
		}
		return cro;
	}
	
	private void saveDbLog(Connection connection,String name,String params,String key,String result) throws Exception{
		PreparedStatement logPs = new LoggableStatement( connection, LoggableStatement.InsertCxToMesLog);
		logPs.setString(1, name);
		logPs.setString(2, params);
		logPs.setString(3, key);
		logPs.setString(4,result);
		logPs.execute();
		logPs.close();
	}
	
}
