package nc.bs.my.arap;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.apache.commons.lang3.StringUtils;

import com.alibaba.fastjson.JSON;

import nc.bs.arap.constant.PropertyFormularConstant;
import nc.bs.dao.BaseDAO;
import nc.bs.dao.DAOException;
import nc.bs.framework.common.InvocationInfoProxy;
import nc.bs.framework.common.NCLocator;
import nc.bs.logging.Logger;
import nc.bs.trade.business.HYPubBO;
import nc.bs.uap.lock.PKLockFactory;
import nc.itf.sap.log.IExtLogService;
import nc.itf.uap.pf.IPFBusiAction;
import nc.jdbc.framework.SQLParameter;
import nc.jdbc.framework.processor.MapListProcessor;
import nc.net.pu.utils.PubUtils;
import nc.net.servlet.IReturnStatus;
import nc.pub.sap.constant.SapConstants;
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.payable.AggPayableBillVO;
import nc.vo.arap.payable.PayableBillItemVO;
import nc.vo.arap.payable.PayableBillVO;
import nc.vo.baseapp.image.ImageInvoiceBVO;
import nc.vo.baseapp.image.ImageInvoiceHVO;
import nc.vo.baseapp.image.ImageInvoiceVO;
import nc.vo.baseapp.image.ImageMidBillVO;
import nc.vo.baseapp.image.ImageViewVO;
import nc.vo.esb.EsbInfoVO;
import nc.vo.esb.QueryInfoVO;
import nc.vo.esb.ResultEsbVO;
import nc.vo.esb.ResultGuidVO;
import nc.vo.esb.ResultVO;
import nc.vo.pub.BusinessException;
import nc.vo.pub.SuperVO;
import nc.vo.pub.lang.UFDate;
import nc.vo.pub.lang.UFDateTime;
import nc.vo.sap.log.SapPurchaseLogVO;
import nc.wy.baseapp.utils.CheckBillUtils;
import ncc.bs.wy.tools.WyWGPTJsonTools;
import ncc.pub.wywgpt.utils.WyWGPTUtils;
import nccloud.base.exception.ExceptionUtils;
import uap.json.JSONObject;
/**
 * @Description: My->NC F1-Cxx-W02
 * @author 徐刚【碧桂园my】
 * @date 2018-9-14
 * @version with NC V6.3
 */
public class MyArapF1W02WriteReceivablesBS {
	
	private String ITFTYPE = "NCC-MY-PM-002";
	//单据类型主键
	private  String PK_BILLTYPEID = "0000Z3000000000000F0";  
	//单据类型
	private String PK_BILLTYPECODE = "F1";    
	//交易类型主键
	private String PK_TRADETYPEID = "1001H810000003BRY2YA";    
	
	//UUID 生成标识
	private final String GUID = UUID.randomUUID().toString();  
	
	BaseDAO dao=null;
	/**
	 * 交互时间精确到毫秒
	 */
	public static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
	
	public ResultEsbVO myArapF1W02WriteReceivablesBS(String key, String billdata) {
		Logger.error("接口：nc.pubitf.sap.fi.ISapFi");
		Logger.error("业务类名：" + this.getClass().getName());
		Logger.error("业务类函数名：myarapinset");
		Logger.error("传入参数1 key：" + key);
		Logger.error("传入参数2 billdata：" + billdata);
		return doAction(key,billdata);
	}
	
	private ResultEsbVO doAction(String key, String billdata) {
		//单据主键
		String billid = "";
		//组织
		String pk_org = "";
		//单据编码
		String billno="";
		//交易类型编码
		String pk_tradetype = "F1-Cxx-W02";
		
		String pk_tradetype_fk = "F3-Cxx-W01";
		String fileUrl="";
		
		// 明源ID
		String guid = null;
		
		// 返回json信息
		ResultEsbVO esbvo = new ResultEsbVO();
		ResultGuidVO sapResultVO = new ResultGuidVO();
		AggPayableBillVO aggVO = null;
		HYPubBO bo =new HYPubBO();
		// 执行保存、提交、审批动作
		IPFBusiAction baService = NCLocator.getInstance().lookup(IPFBusiAction.class);
		try {
			Logger.info("应付单 校验传入的参数");
			if (!SapConstants.CHECK_KEY.equals(key)) {
				throw new Exception("key验证失败 ！");
			}
			// 参数非空校验 a.billdata不能为空校验【为空，则返回错误的json格式数据】
			JSONObject jsonObj = new JSONObject(billdata);
			JSONObject data = (JSONObject) jsonObj.get("requestInfo");
			if (data == null){
				throw new Exception("应付单信息不能为空！");
			}
			try {
				//--------推w02---推付款
				aggVO = WyWGPTJsonTools.jsonToAggVO(data,AggPayableBillVO.class,PayableBillVO.class,PayableBillItemVO.class);
				
				 // XXX 20220506 add by huangzb1: 并发控制
			    guid = aggVO.getHeadVO().getDef1();
			    if(guid == null || guid.trim().length() == 0) {
			    	throw new BusinessException("操作异常：当前待处理单据的GUID为空，请检查");
			    }
			    sapResultVO.setGuid(guid);
			    boolean isLocked = PKLockFactory.getPKLockProxy().addDynamicLock(guid);
			    if(!isLocked) {
			    	throw new BusinessException("操作异常：出现并发操作，请稍后再试，MY-GUID:" + guid);
			    }
			    // END
				
				PayableBillItemVO[]  bvo = (PayableBillItemVO[]) aggVO.getChildrenVO();
				if ("02".equals(aggVO.getHeadVO().getDef39())) {
					for (int i = 0; i < bvo.length; i++) {
						bvo[i].setNotax_de(bvo[i].getMoney_de());
						bvo[i].setLocal_notax_de(bvo[i].getLocal_money_de()); 
					}
				}
//				this.updateImageStatus(aggVO.getHeadVO().getDef1(),"2");
				
			    WyWGPTUtils.notNullCheckAndExFormula(PropertyFormularConstant.F1W02HEAD,PropertyFormularConstant.F1W02BODY, aggVO);
			   
//				String def1=(String) bo.findColValue("ap_payablebill", "def1", " nvl(dr,0)=0 and def1='" + aggVO.getHeadVO().getDef1() + "'");
//				if (def1!=null && !"".equals(def1)) {
//					throw new BusiBeanException("操作异常：MY-GUID重复-" + aggVO.getHeadVO().getDef1());
//				}
			    // XXX 20220506 updated by huangzb1：按业务要求，已生成应付的外系统单据，不需要返回错误信息，直接返回推送成功
			    String strWhere = " nvl(dr,0)=0 and def1='" + guid + "'";
			    SuperVO[] heads = bo.queryByCondition(PayableBillVO.class, strWhere);
				if (heads != null && heads.length >= 1) {
					sapResultVO.setCode(IReturnStatus.ESB_SUCCEED_CODE); // 推送成功标志
					sapResultVO.setMessage("MY系统生成NCC系统 应付单成功");
					sapResultVO.setError("不需要重复推送，MY-GUID:" + guid); // 可以不用设置，不过为了区分是否重复推送，故留个小尾巴
					fileUrl=this.toFileUrl((PayableBillVO) heads[0]);
					sapResultVO.setFileUrl(fileUrl);
					esbvo.setResultInfo(sapResultVO);
					return esbvo;
				}
				// END
				
				// 环境变量初始化
				InvocationInfoProxy.getInstance().setGroupId(aggVO.getHeadVO().getPk_group());
				InvocationInfoProxy.getInstance().setUserId(aggVO.getHeadVO().getCreator());
				//接收发票结构化数据  xuyong 2021-06-19 start
				
				com.alibaba.fastjson.JSONObject invoiceInfoitems = JSON.parseObject(billdata);
				com.alibaba.fastjson.JSONObject invoiceInfoitem =invoiceInfoitems.getJSONObject("requestInfo");
				com.alibaba.fastjson.JSONObject invoce=invoiceInfoitem.getJSONObject("invoiceInfoitem");
				if(null!=invoce) {
					String myid=invoce.getJSONObject("billInfo").getString("billCode");
					aggVO.getHeadVO().setDef40(myid);
				}
				
				//begin wby 20211111  期初单据,单据日期必须在启用日期之前  期初日期是UFDate 类型，所以需要把传进来的单据日期去掉时分秒
				UFDate billDate = (UFDate)aggVO.getHeadVO().getBilldate();
				aggVO.getHeadVO().setBilldate(new UFDate(billDate.toString().substring(0, 10)));
				//end wby 20211111  
				
				// 保存 creator
				baService.processAction("SAVE", pk_tradetype, null, aggVO, null,null);
				baService.processAction("COMMIT", pk_tradetype, null, aggVO, null,null);
				
				pk_tradetype = aggVO.getHeadVO().getPk_tradetype();
				billid=aggVO.getHeadVO().getPk_payablebill();
				billno=aggVO.getHeadVO().getBillno();
				pk_org=aggVO.getHeadVO().getPk_org();
				
				
//				IImageService iImageService = NCLocator.getInstance().lookup(IImageService.class);//发票保存服务
				if(null!=invoce) {
					invoce.getJSONObject("billInfo").put("billCode", billid);
					this.insertImageMidBill(invoce);
				}

				//接收发票结构化数据  xuyong 2021-06-19 end 
				
				//添加部门和收支项目转换 begin
//				BaseDAO dao = new BaseDAO();
//				String def121 = aggVO.getHeadVO().getDef121();
//				String def122 = aggVO.getHeadVO().getDef122();
//				if(def121.equals("Y")){
//					List<PayableBillItemVO> itemVOs = (List<PayableBillItemVO>) dao.executeQuery("select * from ap_payableitem where pk_payablebill = '"+billid+"'", new BeanListProcessor(PayableBillItemVO.class));
//					PayableBillVO billVO = (PayableBillVO) dao.executeQuery("select * from ap_payablebill where pk_payablebill = '"+billid+"'", new BeanProcessor(PayableBillVO.class));
//					String payaccount = (String) bo.findColValue("fip_docview_b", "factorvalue2", "pk_classview = '1001H210000003V6K7QU' and factorvalue1 = '"+def122+"'");
//					billVO.setPayaccount(payaccount);
//					for(int i = 0; i < itemVOs.size(); i++) {
//						PayableBillItemVO itemVO = itemVOs.get(i);
//						itemVO.setPayaccount(payaccount);
//						itemVO.setPk_subjcode("1001H210000000025T8K");
//						itemVO.setBankrollprojet("1001H210000000Y4SHRT");
//						itemVO.setCashitem("1001H210000000025W8C");
//						dao.updateVO(itemVO);
//					}
//				}
				//添加部门和收支项目转换
				//审批
//				baService.processAction("APPROVE",pk_tradetype, null, aggVO, null, null);
				//wby 20211019 明源影像生成NCC应付单后更新影像状态，判断发票不为空更新影像状态
				if(null != invoce) {
					this.updateImageStatus(aggVO.getHeadVO().getDef1(),"2");
				}
			}catch (Exception e) {
				Exception busibeanexception = new Exception("推F1-Cxx-W02蓝字:"+e.getMessage(), e);
				//add by zhengyao3@郑瑶 日志补丁监控 2018年11月27日16:35:04 begin
				List<SapPurchaseLogVO> logvo_list7 = new ArrayList<SapPurchaseLogVO>();
				StringWriter sw = new StringWriter();
		          PrintWriter pw = new PrintWriter(sw);
		          e.printStackTrace(pw);
				SapPurchaseLogVO logvo7 = PubUtils.createSNLog("NCC-MY",
						"","","" , "", "",//
						sw.toString(),
						e.getMessage(),
						"N", getClass().getName());
				logvo_list7.add(logvo7);
				IExtLogService logService=NCLocator.getInstance().lookup(IExtLogService.class);
				try {
					logService.insertLog_RequiresNew(logvo7);
				} catch (BusinessException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				//add by zhengyao3@郑瑶 日志补丁监控 2018年11月27日16:35:04 end
				throw busibeanexception;
			}
			//取消推送付款begin
//			try {
//				//徐钢  2018-11-11 -- 后改 有票不用代码推送付款 ，无票推保存  begin
//				if("Y".equals(aggVO.getHeadVO().getDef95())){ //只有有票付款才会推付款单 
//				//徐钢  2018-11-11 -- 后改 不用代码推送付款 end
//					AggPayableBillVO aggvopay = aggVO;// (AggPayableBillVO) aggVO2[0];
//					//推付款单 F3-Cxx-W01
//					AggPayBillVO aggpaybillvo = (AggPayBillVO) PfUtilTools.runChangeData(pk_tradetype, pk_tradetype_fk, aggvopay);
//					pk_tradetype_fk = aggpaybillvo.getHeadVO().getPk_tradetype();
//					// 保存 creator
//					//徐钢  2018-11-11 -- 后改 有票不用代码推送付款 ，无票推保存  begin
//					baService.processAction("SAVEBASE", pk_tradetype_fk, null, aggpaybillvo, null,null);
//					//徐钢  2018-11-11 -- 后改 不用代码推送付款 end
//					//审批
//	//				baService.processAction("APPROVE",pk_tradetype, null, aggpaybillvo, null, null);
//				}
//			}catch (Exception e) {
//				Exception busibeanexception = new Exception("推F3-Cxx-W01蓝字:"+e.getMessage(), e);
//				throw busibeanexception;
//			}
			//取消付款 end
			sapResultVO.setCode(IReturnStatus.ESB_SUCCEED_CODE);
			sapResultVO.setMessage("MY系统生成NCC系统 应付成功");
			sapResultVO.setError("");
			// XXX updated by huangzb1 at 2022-05-11: 根据最新业务要求，一律返回url地址
			fileUrl=this.toFileUrl(aggVO.getHeadVO());
			sapResultVO.setFileUrl(fileUrl);
		} catch (Exception e) {
			// 组装异常日志信息
			Logger.debug("应付单F1-Cxx-W02同步失败 : " + e.getMessage());
			//日志补丁监控 begin
			List<SapPurchaseLogVO> logvo_list7 = new ArrayList<SapPurchaseLogVO>();
			StringWriter sw = new StringWriter();
	          PrintWriter pw = new PrintWriter(sw);
	          e.printStackTrace(pw);
			SapPurchaseLogVO logvo7 = PubUtils.createSNLog("NCC-MY",
					"","","" , "", "",//
					sw.toString(),
					e.getMessage(),
					"N", getClass().getName());
			logvo_list7.add(logvo7);
			IExtLogService logService=NCLocator.getInstance().lookup(IExtLogService.class);
			try {
				logService.insertLog_RequiresNew(logvo7);
			} catch (BusinessException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			//日志补丁监控end
			sapResultVO.setMessage("MY系统生成NC系统 应付F1-Cxx-W02失败");
			sapResultVO.setCode(IReturnStatus.ESB_FAILING_CODE);
			sapResultVO.setError(e.getMessage());
		}finally {
			// 插入日志
			try {
				//构建日志VO
				esbvo.setResultInfo(sapResultVO);
				createEsbVO(1, esbvo, new JSONObject(billdata), sapResultVO);// 创建响应对象 MDGToNcSupplierServelet.java  发送响应对象
				String issuccess_sn = "";
				if (sapResultVO.getCode().equals(IReturnStatus.ESB_SUCCEED_CODE)) {
					issuccess_sn = "Y";
				} else {
					issuccess_sn = "N";
				}
				List<SapPurchaseLogVO> logvo_list = new ArrayList<SapPurchaseLogVO>();
				SapPurchaseLogVO log = new SapPurchaseLogVO();
				log.setPk_org(ITFTYPE);
		    	log.setBillid(billid);
		    	log.setBillno(billno);
		    	log.setPk_billtypecode("F1");
		    	log.setPk_transtypecode(pk_tradetype);
		    	log.setSend_data_sn(billdata);
		    	log.setResultdata_sn(com.alibaba.fastjson.JSONObject.toJSONString(esbvo));
		    	log.setMsg_sn(sapResultVO.getMessage()+sapResultVO.getError());
		    	log.setIssuccess_sn(issuccess_sn);
		    	log.setDef1(this.getClass().getName());
		    	
		    	// XXX: 记录明源ID，时间戳
		    	log.setDef2(guid); // 记录明源ID
		    	log.setTs(new UFDateTime().toString()); // 时间戳
		    	
				logvo_list.add(log);
				IExtLogService logService=NCLocator.getInstance().lookup(IExtLogService.class);
				logService.insertLog_RequiresNew(log);
			} catch (Exception e) {
				Logger.debug("插入日志失败 : " + e.getMessage());
			}
		}
		return esbvo;
	}
	 public static SapPurchaseLogVO createSNLog(String pk_org,String billid,String billno,String pk_billtypecode,
	    		String pk_transtypecode,String send_data_sn,String resultdata_sn,String msg_sn,String issuccess_sn,String classname){
	    	SapPurchaseLogVO log=new SapPurchaseLogVO();
	    	log.setPk_org(pk_org);
	    	log.setBillid(billid);
	    	log.setBillno(billno);
	    	log.setPk_billtypecode(pk_billtypecode);
	    	log.setPk_transtypecode(pk_transtypecode);
	    	log.setSend_data_sn(send_data_sn);
	    	log.setResultdata_sn(resultdata_sn);
	    	log.setMsg_sn(msg_sn);
	    	log.setIssuccess_sn(issuccess_sn);
	    	log.setDef1(classname);
	    	return log;
	    }
	/**
	 * 创建ESB交互对象
	 * 
	 * @param newi
	 * @param esb
	 *            交互VO
	 * @return newi=0(请求对象)/newi=1(响应对象)
	 */
	@SuppressWarnings("rawtypes")
	public void createEsbVO(int newi, final ResultEsbVO esb,
			uap.json.JSONObject jsonobj, ResultVO resultvo) {
		uap.json.JSONObject esbinfo = jsonobj.getJSONObject("esbInfo");
		Date date = Calendar.getInstance().getTime();// 获取当前时间
		EsbInfoVO esbInfo = new EsbInfoVO();
		esbInfo.setReturnCode(resultvo.getCode());
		esbInfo.setInstId(esbinfo.getString("instId"));
		esbInfo.setReturnMsg(resultvo.getMessage());
		// 获取数据
		QueryInfoVO queryInfo = new QueryInfoVO();
		queryInfo.setTotalPage("");// 默认总页数为 1
		queryInfo.setCurrentPage("");// 默认当前页数为 1
		if (newi == 0) {// 设置请求时间
			esbInfo.setRequestTime(dateFormat.format(date));
		} else {// 设置响应时间
			esbInfo.setRequestTime(dateFormat.format(date));
			esbInfo.setResponseTime(dateFormat.format(date));
			if (resultvo.getCode().equals(IReturnStatus.ESB_SUCCEED_CODE)) {
				esbInfo.setReturnStatus(IReturnStatus.ESB_SUCCEED);// 响应成功
			} else if (resultvo.getCode().equals(IReturnStatus.ESB_ERROR_CODE)) {
				esbInfo.setReturnStatus(IReturnStatus.ESB_ERROR);// 响应异常
			} else {
				esbInfo.setReturnStatus(IReturnStatus.ESB_FAILING);// 响应失败
			}
		}
		esb.setEsbInfo(esbInfo);
		esb.setQueryInfo(queryInfo);
	}
	private String toFileUrl(PayableBillVO vo) throws BusinessException {
		List<Map<String, String>> query = (List<Map<String, String>>) getDAO().executeQuery(
				"select vdef1,appcode  from  erm_bgyimageconfig where transtype ='"+vo.getPk_tradetype()+"'",
				new MapListProcessor());
		StringBuffer url = new StringBuffer();
		if(query==null || query.size()<=0) {
			throw new BusinessException("获取应付审批封面地址失败,交易类型为："+vo.getPk_tradetype()+"，请联系用友顾问!");
		}
		url.append(query.get(0).get("vdef1") + "?");
		url.append("appcode="+query.get(0).get("appcode")+"");
		url.append("&Oids=" + vo.getPk_payablebill());

		String fileUrl = url.toString();
		return fileUrl;
	}
	private BaseDAO getDAO() {
		if(dao==null) {
			dao = new BaseDAO();
		}
		return dao;
		}
	
	public String insertImageMidBill(com.alibaba.fastjson.JSONObject json) throws BusinessException {
		try {
			ImageViewVO view = JSON.parseObject(json.toJSONString(), ImageViewVO.class);
			ImageMidBillVO imageMidBillVO = view.getBillInfo();
			ImageInvoiceVO[] imageInvoiceVOs = view.getInvoiceInfo();
			deleteOldVO(imageMidBillVO);
			// 插入影像信息
			getDAO().insertVO(imageMidBillVO);
			for(ImageInvoiceVO imageInvoiceVO : imageInvoiceVOs) {
				ImageInvoiceHVO imageInvoiceHVO = imageInvoiceVO.getInvoiceMain();
				// 插入发票表头中间表
				imageInvoiceHVO.setDef1(imageMidBillVO.getBillCode());
				String pk_invoice_h = getDAO().insertVO(imageInvoiceHVO);
//				insertErmInvoice(imageMidBillVO.getBillCode(),imageInvoiceHVO);
				CheckBillUtils.checkBill(imageMidBillVO.getBillCode(),imageInvoiceHVO);
				ImageInvoiceBVO[] imageInvoiceBVOs = imageInvoiceVO.getInvoiceDetail();
				if(null != imageInvoiceBVOs && imageInvoiceBVOs.length > 0) {
					for(ImageInvoiceBVO imageInvoiceBVO : imageInvoiceBVOs) {
						imageInvoiceBVO.setPk_invoice_h(pk_invoice_h);
						imageInvoiceBVO.setDef1(imageMidBillVO.getBillCode());
					}
					// 插入发票表体中间表
					getDAO().insertVOArray(imageInvoiceBVOs);
				}
			}
		} catch (Exception e) {
			return e.getMessage();
		}
		return null;
		
	}	
	/**
	 * 删除旧的影像信息
	 * @param imageMidBillVO
	 * @throws DAOException 
	 */
	private void deleteOldVO(ImageMidBillVO imageMidBillVO) throws DAOException {
		String billCode = imageMidBillVO.getBillCode();
		try {
			SQLParameter sqlparm1 = new SQLParameter();
			String sql = "update image_bill set dr = 1 where billcode = ? and dr = 0";
			sqlparm1.addParam(billCode);
			getDAO().executeUpdate(sql, sqlparm1);
			sql = "delete from er_erminvoice where pk_bxdhead = ? ";
			getDAO().executeUpdate(sql, sqlparm1);
			sql = "update image_invoice_h set dr = 1 where def1 = ? and dr = 0";
			getDAO().executeUpdate(sql, sqlparm1);
			sql = "update image_invoice_b set dr = 1 where def1 = ? and dr = 0";
			getDAO().executeUpdate(sql, sqlparm1);
		} catch (DAOException e) {
			throw new DAOException("删除原发票信息单据出错,"+e.getMessage());
		}
		
	}
	/**
	 * 调用影像接口实现
	 * @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");
		}
		// 插入日志表
		getDAO().insertVO(log);
	}
}
