package nc.bs.arap.busireg;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.apache.commons.lang3.StringUtils;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.thoughtworks.xstream.XStream;
import nc.bs.arap.constant.PropertyNCBilltypeConstant;
import nc.bs.arap.util.NCToMyXmlUtil;
import nc.bs.businessevent.BdUpdateEvent;
import nc.bs.businessevent.BusinessEvent;
import nc.bs.businessevent.IBusinessEvent;
import nc.bs.dao.BaseDAO;
import nc.bs.framework.common.NCLocator;
import nc.itf.arap.pay.IArapPayBillQueryService;
import nc.itf.ws.esb.IEsbDAO;
import nc.jdbc.framework.processor.BeanListProcessor;
import nc.jdbc.framework.processor.ColumnProcessor;
import nc.jdbc.framework.processor.MapListProcessor;
import nc.net.pu.utils.PubUtils;
import nc.pubitf.payablebill.yx.ImageCaptureAPI;
import nc.pubitf.payablebill.yx.ImageCommonConstant;
import nc.pubitf.payablebill.yx.ImageStatusVO;
import nc.pubitf.payablebill.yx.ImageTMLogVO;
import nc.vo.arap.pay.AggPayBillVO;
import nc.vo.bd.defdoc.DefdocVO;
import nc.vo.esb.EsbInfoAnnotatioVO;
import nc.vo.esb.ResultEsbMyToNcVO;
import nc.vo.esb.ResultMyToNcVO;
import nc.vo.pub.AggregatedValueObject;
import nc.vo.pub.BusinessException;
import nc.vo.sap.log.SapPurchaseLogVO;
import nccloud.base.exception.ExceptionUtils;
import sun.misc.BASE64Encoder;

public class RetransmissionRejectedUtil {
	String materialClass_url = "";
	String materialClass_token = "";

	public void doAction(AggregatedValueObject classvo, String tradeType, String memo) throws BusinessException {
		if (classvo != null) {
			String BillType = "";
			String BusinessGUID = "";
			String OperatorType = "";
			String URLCode = "MY-NC-PM-003";
			String elementResponse = "DeleteOrderResponse";
			String elementResult = "DeleteOrderResult";
			String biaoqie = "";

			if (tradeType.equals("F3-Cxx-W01")) {
				BusinessGUID = classvo.getParentVO().getAttributeValue("def1").toString();
				BillType = "付款单";
				OperatorType = memo;
				biaoqie = "def63";
			}

			else if (tradeType.equals("F1-Cxx-W02")) {
				BusinessGUID = classvo.getParentVO().getAttributeValue("def1").toString();
				BillType = "应付单";
				OperatorType = memo;
				biaoqie = "def98";
			} else
				return;
			this.doMYStatus(classvo, tradeType, memo);
		}
	}

	protected AggregatedValueObject[] getAggVO(IBusinessEvent event) {

		AggregatedValueObject[] billvos = null;
		Object obj = null;
		if (event instanceof BusinessEvent) {
			BusinessEvent business = (BusinessEvent) event;
			obj = (AggregatedValueObject[]) business.getObject();
		} else if (event instanceof BdUpdateEvent) {
			BdUpdateEvent business = (BdUpdateEvent) event;
			obj = (AggregatedValueObject[]) business.getNewObject();
		}
		if (obj != null) {
			if (obj.getClass().isArray()) {
				billvos = (AggregatedValueObject[]) obj;
			} else {
				billvos = new AggregatedValueObject[] { (AggregatedValueObject) obj };
			}
			if (billvos == null || billvos.length == 0)
				return null;
		}
		return billvos;
	}

	private static IEsbDAO service;
	private static BASE64Encoder base64;

	public static ResultEsbMyToNcVO getResultEsbMyToNcVO(String resultXml) throws BusinessException {
		SAXReader saxReader = new SAXReader();
		Document document = null;
		Element resultElement = null;
		try {
			document = saxReader.read(new ByteArrayInputStream(resultXml.getBytes("UTF-8")));

			// 得到根节点对象
			Element rootElements = document.getRootElement();
			// 得到根节点的节点名称
			if (rootElements == null) {
				throw new BusinessException("调用明源接口信息异常,请联系用友顾问查看日志!!日志表名 sap_po_log");
			}
			resultElement = rootElements.element("Body").element("SyncPayStatusToPropertySystemResponse")
					.element("SyncPayStatusToPropertySystemResult");
		} catch (Exception e) {
			throw new BusinessException("调用明源接口信息异常,请联系用友顾问查看日志!!日志表名 sap_po_log");
		}
		if (resultElement == null) {
			throw new BusinessException("调用明源接口信息异常,请联系用友顾问查看日志!!日志表名 sap_po_log");
		}
		XStream xStream = new XStream();
		xStream.alias("SyncPayStatusToPropertySystemResult", ResultEsbMyToNcVO.class);
		xStream.alias("esbInfo", EsbInfoAnnotatioVO.class);
		xStream.alias("resultInfo", ResultMyToNcVO.class);
		return (ResultEsbMyToNcVO) xStream.fromXML(resultElement.asXML());
	}

	/**
	 * 解析逆向接口返回的XML
	 * 
	 * @param resultXml
	 * @return
	 * @throws BusinessException
	 */
	public static ResultEsbMyToNcVO getReverseResultEsbMyToNcVO(String resultXml, String elementResponse,
			String elementResult) throws BusinessException {
		SAXReader saxReader = new SAXReader();
		Document document = null;
		Element resultElement = null;
		try {
			document = saxReader.read(new ByteArrayInputStream(resultXml.getBytes("UTF-8")));

			// 得到根节点对象
			Element rootElements = document.getRootElement();
			// 得到根节点的节点名称
			if (rootElements == null) {
				throw new BusinessException("调用明源接口信息异常,请联系用友顾问查看日志!!日志表名 sap_po_log");
			}

			resultElement = rootElements.element("Body").element(elementResponse).element(elementResult);
		} catch (Exception e) {
			throw new BusinessException("调用明源接口信息异常,请联系用友顾问查看日志!!日志表名 sap_po_log");
		}
		if (resultElement == null) {
			throw new BusinessException("调用明源接口信息异常,请联系用友顾问查看日志!!日志表名 sap_po_log");
		}
		XStream xStream = new XStream();
		xStream.alias(elementResult, ResultEsbMyToNcVO.class);
		xStream.alias("esbInfo", EsbInfoAnnotatioVO.class);
		xStream.alias("resultInfo", ResultMyToNcVO.class);
		return (ResultEsbMyToNcVO) xStream.fromXML(resultElement.asXML());
	}
	// add by zhengyao3@郑瑶 2018年10月24日11:56:24 end

	/**
	 * 传输XML至明源接口
	 * 
	 * @param XML数据
	 * @param bgy_esbinfo的Code字段
	 * @return
	 * @throws Exception
	 */
	public static String sendXMLToMy(String URLCode, String guid, String BillType, String BusinessGUID,
			String OperatorType, String uid, String biaoqie) throws BusinessException {
		// add by zhengyao3@郑瑶 增加逆向接口 2018年10月24日12:04:13 begin
		// add by 黄冠华 40331 【联测】无法新增保存部门节点 begin
		// 明源部门接口有更改，xml头需要使用新的
		StringBuilder str = new StringBuilder(
				"<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:tem=\"http://tempuri.org/\"> \n");
		// "<soapenv:Envelope
		// xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"
		// xmlns:tem=\"http://tempuri.org/\"> \n");
//			StringBuilder str = new StringBuilder();
//			if("NC-MY-FY-001".equals(URLCode)){
//				str.append("<soape:Envelope xmlns:soape=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:tem=\"http://tempuri.org/\"> \n");
//			}else {
//				str.append("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:tem=\"http://tempuri.org/\"> \n");
//			}
		// add by 黄冠华 40331 【联测】无法新增保存部门节点 end
		str.append("  <soap:Header/> \n");
		str.append(" <soap:Body> \n");
//			if ("MY-NC-PM-002".equals(URLCode)) {
//				str.append("<tem:DeleteOrder>  \n");
//				str.append( " <tem:requestBaseEntity> \n ");
//				str.append( " <tem:esbInfo>\n   <instId>"+uid+"</instId>\n </esbInfo> \n ");				
//				str.append( " <requestInfo> \n ");
//				str.append("<BillType>"+BillType+"</BillType> \n");
//				str.append("<"+biaoqie+">"+OperatorType +"</"+biaoqie+"> \n ");
//				str.append("<BusinessGUID>"+BusinessGUID+"</BusinessGUID> \n");
//				str.append( " </requestInfo> \n ");
//				str.append( " </requestBaseEntity>  ");
//				str.append("\n </CheckOrder> \n");
//			} else 
		if ("MY-NC-PM-003".equals(URLCode)) {
			str.append("<tem:DeleteOrder> \n");
			str.append(" <tem:requestBaseEntity> \n ");
			str.append(" <tem:esbInfo>\n   <tem:instId>" + uid
					+ "</tem:instId>\n <tem:requestTime>?</tem:requestTime>\n <tem:attr1>?</tem:attr1>\n <tem:attr3>?</tem:attr3>\n <tem:attr2>?</tem:attr2>\n  </tem:esbInfo> \n ");
			str.append("<tem:queryInfo>\r\n" + "               <!--Optional:-->\r\n"
					+ "               <tem:pageSize>?</tem:pageSize>\r\n" + "               <!--Optional:-->\r\n"
					+ "               <tem:currentPage>?</tem:currentPage>\r\n" + "            </tem:queryInfo>");
			str.append(" <tem:requestInfo> \n ");
			str.append("<tem:BusinessGUID>" + BusinessGUID + "</tem:BusinessGUID> \n");
			str.append("<tem:BillType>" + BillType + "</tem:BillType> \n");
			str.append("<tem:" + biaoqie + ">" + OperatorType + "</tem:" + biaoqie + "> \n ");
			str.append(" </tem:requestInfo> \n ");
			str.append(" </tem:requestBaseEntity> \n ");
			str.append(" </tem:DeleteOrder> \n ");
		}
		// add by libx3@李炳雄 增加甲供材_NC财务部门接口转XML对象时requestinfo实体属性 2019年3月27日11:36:24
		// begin
//			} else if("NC-MY-FY-001".equals(URLCode)){
//				str.append("<CheckOrder xmlns=\"http://tempuri.org/\">  \n");
//				str.append( " <requestBaseEntity> \n ");
//				str.append( " <esbInfo>\n   <instId>"+uid+"</instId>\n </esbInfo> \n ");				
//				str.append( " <requestInfo> \n ");
//				str.append("<BillType>"+BillType+"</BillType> \n");
//				str.append("<"+biaoqie+">"+OperatorType +"</"+biaoqie+"> \n ");
//				str.append("<BusinessGUID>"+BusinessGUID+"</BusinessGUID> \n");
//				str.append( " </requestInfo> \n ");
//				str.append( " </requestBaseEntity>  ");
//				str.append("\n </CheckOrder> \n");
//				//add by libx3@李炳雄 增加甲供材_NC财务部门接口转XML对象时requestinfo实体属性  2019年3月27日11:36:24 end
//			} else {
//				str.append("<CheckOrder xmlns=\"http://tempuri.org/\">  \n");
//				str.append( " <requestBaseEntity> \n ");
//				str.append( " <esbInfo>\n   <instId>"+uid+"</instId>\n </esbInfo> \n ");				
//				str.append( " <requestInfo> \n ");
//				str.append("<BillType>"+BillType+"</BillType> \n");
//				str.append("<OperatorType>"+OperatorType +"</OperatorType> \n ");
//				str.append("<BusinessGUID>"+BusinessGUID+"</BusinessGUID> \n");
//				str.append( " </requestInfo> \n ");
//				str.append( " </requestBaseEntity>  ");
//				str.append("\n </CheckOrder> \n");
//			}
		//// add by zhengyao3@郑瑶 增加逆向接口 2018年10月24日12:04:13 end
		str.append(" </soap:Body> \n");
		str.append(" </soap:Envelope> \n");
		String xml = str.toString();
//			IEsbDAO service = NCLocator.getInstance().lookup(IEsbDAO.class);
//			EsbinfoVO[] esbinfos = (EsbinfoVO[]) service.findESB("code='" + URLCode
//					+ "'");
//			if (esbinfos == null || esbinfos.length == 0) {
//				throw new BusinessException("接口安全授权节点未对接口" + URLCode + "授权");
//			}
		String url = "https://mycbtest.bgyfw.com:8055/ESB/WS_ESB_CheckOrderCanDelApply.asmx?WSDL";// esbinfos[0].getUrl();

		String result = "";
		BufferedReader in = null;
		String issuccess_sn = "Y";
		String line = null;
		String exception = "";
		try {
			URL realUrl = new URL(url);
			// 打开和URL之间的连接
			URLConnection connection = realUrl.openConnection();
			// 设置通用的请求属性
			connection.setRequestProperty("accept", "*/*");
			connection.setRequestProperty("connection", "Keep-Alive");
			connection.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
			connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
//				CertificateVO typevo = getService().findByPkCode(
//						esbinfos[0].getCertificate());
//				if (typevo != null) {
//					String basic = typevo.getUsername() + ":"
//							+ typevo.getPassword();
//					connection.setRequestProperty("Authorization", "Basic "
//							+ getBase64().encode(basic.getBytes()));
			connection.setRequestProperty("esbkey", "ervj30ox410Mq14MhU4UKCGgZBeUiaQc");
//				}
			// 建立实际的连接
			connection.setDoOutput(true);
			connection.connect();

			OutputStream out = connection.getOutputStream();

			// 写入请求的字符串
			out.write((xml.toString()).getBytes("utf-8"));
			out.flush();
			out.close();
			// 定义 BufferedReader输入流来读取URL的响应
			in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "utf-8"));
			while ((line = in.readLine()) != null) {
				result += line;
			}
		} catch (Exception e) {
			issuccess_sn = "N";
			exception = e.getMessage();
		}
		// 使用finally块来关闭输入流
		finally {
			try {
				if (in != null) {
					in.close();
				}
				List<SapPurchaseLogVO> logvo_list = new ArrayList<SapPurchaseLogVO>();
				SapPurchaseLogVO log = new SapPurchaseLogVO();
				log.setPk_org(URLCode);
				log.setBillid(guid);
				log.setBillno(guid);
				log.setPk_billtypecode("MY");
				log.setPk_transtypecode("");
				log.setSend_data_sn(xml.toString());
				log.setResultdata_sn(result);
				log.setMsg_sn(exception);
				log.setMsg_ns("");
				log.setIssuccess_sn(issuccess_sn);
				log.setDef1("nc.bs.arap.util.NCToMyXmlUtil.sendXMLToMy");
				log.setDr("0");
				logvo_list.add(log);
				PubUtils.getSaplog().insertPurchaseLog_RequiresNew(logvo_list);
			} catch (Exception e2) {
				e2.printStackTrace();
			}
		}
		return result;
	}

	/**
	 * @return
	 */
	public static IEsbDAO getService() {
		if (service == null)
			service = NCLocator.getInstance().lookup(IEsbDAO.class);
		return service;
	}

	/**
	 * @return
	 */
	public static BASE64Encoder getBase64() {
		if (base64 == null)
			base64 = new BASE64Encoder();
		return base64;
	}

	private String toFileUrl(String tradeType, String pk) throws BusinessException {
		List<Map<String, String>> query = (List<Map<String, String>>) dao.executeQuery(
				"select vdef1,appcode  from  erm_bgyimageconfig where transtype ='" + tradeType + "'",
				new MapListProcessor());
		StringBuffer url = new StringBuffer();
		if (query == null || query.size() <= 0) {
			throw new BusinessException("获取应付审批封面地址失败,交易类型为：" + tradeType + "，请联系用友顾问!");
		}
		url.append(query.get(0).get("vdef1") + "?");
		url.append("appcode=" + query.get(0).get("appcode") + "");
		url.append("&Oids=" + pk);

		String fileUrl = url.toString();
		return fileUrl;
	}

	public void doMYStatus(AggregatedValueObject classvo, String tradeType, String memo) throws BusinessException {// 通过监听获取
		DefdocVO[] mdmservice = getQueryDefdoc("my_service");// 获取自定义档案表头
		if (mdmservice != null) {
			for (DefdocVO doc : mdmservice) {
				if ("status_apikey".equals(doc.getCode())) {
					materialClass_token = doc.getShortname();// 建立自定义档案 toke
				} else if ("status_url".equals(doc.getCode())) {
					materialClass_url = doc.getShortname();// 建立自定义档案 url 地址
				}
			}
		}
		JSONObject datajson = new JSONObject();// 集合
		if (PropertyNCBilltypeConstant.F1W02BILLTYPE.equals(tradeType)) {
			if (classvo.getParentVO().getAttributeValue("def1") != null) {
				String def1 = (String) classvo.getParentVO().getAttributeValue("def1");
				IArapPayBillQueryService serivce = NCLocator.getInstance().lookup(IArapPayBillQueryService.class);
				AggPayBillVO[] aggVOs = serivce.queryBillsByWhereSQL("def1='" + def1 + "' and dr=0");
				if (aggVOs != null && aggVOs.length > 0) {
					String top_billid = aggVOs[0].getItems()[0].getTop_billid();
					if (top_billid == null) {
						datajson.put("BusinessType", 102);
						datajson.put("BillCode", classvo.getParentVO().getAttributeValue("def40")); // 明源系统的主键guid
					} else {
						return;
					}
				} else {
					datajson.put("BusinessType", 101);
					datajson.put("BillCode", def1); // 明源系统的主键guid
				}
				this.updateImageStatus(def1, "4");
			} else {
				return;
			}
			String fileurl = toFileUrl(tradeType, classvo.getParentVO().getPrimaryKey());
			datajson.put("FileUrl", fileurl);
			datajson.put("ApproveStatus", "退回"); // 返回明源的操作状态
			// 调用接口
			try {
				String jiekou = httpURLConnectionPOST(datajson.toString(), materialClass_url);
				com.alibaba.fastjson.JSONObject jsonObj = JSON.parseObject(jiekou);
				if (jsonObj != null) {
					// 调用接口成功或者失败
					Integer code = jsonObj.getInteger("Code");
					if (1 == code) {
						throw new BusinessException(jsonObj.getString("Msg"));
					}
				}
			} catch (Exception e) {
				throw new BusinessException("调用明源失败:" + e.getMessage() + "");
			}
		} else if (PropertyNCBilltypeConstant.F3W01BILLTYPE.equals(tradeType)) {
			if (classvo.getParentVO().getAttributeValue("def1") != null) {
				AggPayBillVO aggVO = (AggPayBillVO) classvo;
				String def1 = (String) classvo.getParentVO().getAttributeValue("def1");
				String top_billid = aggVO.getBodyVOs()[0].getTop_billid();
				if ("N".equals(classvo.getParentVO().getAttributeValue("def3")) && top_billid == null) {
					datajson.put("BusinessType", 101);
					datajson.put("BillCode", def1); // 明源系统的主键guid
				} else {
					return;
				}
				this.updateImageStatus(def1, "4");
			} else {
				return;
			}

			String fileurl = toFileUrl(tradeType, classvo.getParentVO().getPrimaryKey());
			datajson.put("FileUrl", fileurl);
			datajson.put("ApproveStatus", "退回"); // 返回明源的操作状态
			// 调用接口
			try {
				String jiekou = httpURLConnectionPOST(datajson.toString(), materialClass_url);
				com.alibaba.fastjson.JSONObject jsonObj = JSON.parseObject(jiekou);
				if (jsonObj != null) {
					// 调用接口成功或者失败
					Integer code = jsonObj.getInteger("Code");
					if (1 == code) {
						throw new BusinessException(jsonObj.getString("Msg"));
					}
				}
			} catch (Exception e) {
				throw new BusinessException("调用明源失败:" + e.getMessage() + "");
			}
		}

	}
//}

	/**
	 * post方式调用接口
	 * 
	 * @throws Exception
	 * 
	 */
	public String httpURLConnectionPOST(String parm, String posturl) throws Exception {

		URL url = new URL(posturl);

		HttpURLConnection connection = (HttpURLConnection) url.openConnection();// 此时cnnection只是为一个连接对象,待连接中

		// 设置连接输出流为true,默认false
		connection.setDoOutput(true);

		// 设置连接输入流为true
		connection.setDoInput(true);

		// 设置请求方式为post
		connection.setRequestMethod("POST");

		// post请求缓存设为false
		connection.setUseCaches(false);

		// 设置该HttpURLConnection实例是否自动执行重定向
//	connection.setInstanceFollowRedirects(true);

		connection.setRequestProperty("Content-Type", "application/json;charset=utf-8");

		connection.setRequestProperty("apikey", materialClass_token);// 修改点，token key
//	connection.setRequestProperty("tenantid","tenant");

		// 建立连接 (请求未开始,直到connection.getInputStream()方法调用时才发起,以上各个参数设置需在此方法之前进行)
		connection.connect();

		// 创建输入输出流,用于往连接里面输出携带的参数
		DataOutputStream dataout = new DataOutputStream(connection.getOutputStream());

		dataout.write(parm.getBytes("UTF-8"));
		// 输出完成后刷新并关闭流
		dataout.flush();
		dataout.close();
		BufferedReader bf = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
		String line;
		StringBuilder sb = new StringBuilder(); // 用来存储响应数据

		// 循环读取流,若不到结尾处
		while ((line = bf.readLine()) != null) {
//		sb.append(bf.readLine());
			sb.append(line);// .append(System.getProperty("line.separator"));
		}
		bf.close();
		connection.disconnect(); // 销毁连接
		if (sb != null && !"".equals(sb)) {
			return sb.toString();
		}
		return null;
	}

//解耦拼接
	public String getQueryData(String tablename, String querytable, String where) throws BusinessException {
		String sql = "select " + querytable + " from " + tablename + " where " + where + " ";
		Object object = dao.executeQuery(sql, new ColumnProcessor());// 单条结果集
		String data = object == null ? null : object.toString();
		return data;
	}

	public DefdocVO[] getQueryDefdoc(String defdoclistcode) throws BusinessException {
		String sql = "select * from bd_defdoc where pk_defdoclist=(select pk_defdoclist from bd_defdoclist where code='"
				+ defdoclistcode + "') and dr=0";
		java.util.List<DefdocVO> classvo = (List<DefdocVO>) dao.executeQuery(sql,
				new BeanListProcessor(DefdocVO.class));
		if (classvo != null && classvo.size() > 0) {
			return classvo.toArray(new DefdocVO[0]);
		}
		return null;
	}

	/**
	 * 调用影像接口实现
	 * 
	 * @author xuy
	 */
	public void updateImageStatus(String billid, String status) throws BusinessException {
		ImageStatusVO imageStatusVO = new ImageStatusVO();
		imageStatusVO.setBillCode(billid);
		imageStatusVO.setBillCodeType("expensesBill");
		imageStatusVO.setHandleRemark("");
		imageStatusVO.setStatus(status);
		imageStatusVO.setSystemOrig(1);
		com.alibaba.fastjson.JSONObject json = (com.alibaba.fastjson.JSONObject) com.alibaba.fastjson.JSONObject
				.toJSON(imageStatusVO);
		com.alibaba.fastjson.JSONObject result = ImageCaptureAPI.postRequest(json,
				ImageCommonConstant.IMAGE_STATUS_UPDATE);
		this.insertImageLog_RequiresNew(billid, null, json, result, ImageCommonConstant.IMAGE_STATUS_UPDATE);
		String code = result.getString("code");
		if (!"200".equals(code)) {
			ExceptionUtils.wrapBusinessException("调用" + ImageCaptureAPI.map.get(ImageCommonConstant.IMAGE_STATUS_UPDATE)
					+ "接口失败：" + result.get("message").toString());
		}
	}

	/**
	 * 调用影像接口日志写入
	 * 
	 * @author xuy
	 */
	public void insertImageLog_RequiresNew(String billid, String billcode, com.alibaba.fastjson.JSONObject send,
			com.alibaba.fastjson.JSONObject result, String urlcode) throws BusinessException {
		String code = result.getString("code");
		ImageTMLogVO log = new ImageTMLogVO();
		log.setBillid(billid);
		log.setBillno(billcode);
		log.setTm_content(com.alibaba.fastjson.JSONObject.toJSONString(send));
		log.setTm_result(com.alibaba.fastjson.JSONObject.toJSONString(result));
		log.setApicode(urlcode);
		if (!StringUtils.isBlank(code) && "200".equals(code)) {
			log.setTm_status("S");
		} else {
			log.setTm_status("F");
		}
		// 插入日志表
		dao.insertVO(log);
	}

	BaseDAO dao = new BaseDAO();

}
