package com.prolog.cs.biz.inbound.utils;

import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.prolog.common.util.ToolKits;
import com.prolog.cs.biz.inbound.model.SupervisionCode;
import com.prolog.cs.biz.inbound.remote.StrategyClient;
import com.prolog.framework.common.message.RestMessage;
import com.prolog.framework.core.exception.BizException;
import com.prolog.upcloud.base.strategy.model.BusinessControl;
import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;
import com.taobao.api.internal.util.StringUtils;
import com.taobao.api.request.AlibabaAlihealthDrugMscGetentinfoRequest;
import com.taobao.api.request.AlibabaAlihealthDrugMscUploadinoutbillRequest;
import com.taobao.api.response.AlibabaAlihealthDrugMscUploadcircubillResponse;
import com.taobao.api.response.AlibabaAlihealthDrugMscUploadinoutbillResponse;
import lombok.extern.slf4j.Slf4j;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;
import org.springframework.beans.factory.annotation.Value;

import javax.annotation.Resource;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.zip.GZIPOutputStream;

@Slf4j
public class UploadCircubillUtil {

//	@Value("${uploadSupervisionCode.serverUrl}")
//	private static String serverUrl;
//
//	@Value("${uploadSupervisionCode.appKey}")
//	private static String appKey;
//
//	@Value("${uploadSupervisionCode.appSecret}")
//	private static String appSecret;
//
//	@Value("${uploadSupervisionCode.sendEnterpriseId}")
//	private static String sendEnterpriseId;
//
//	@Value("${uploadSupervisionCode.acceptEnterpriseId}")
//	private static String acceptEnterpriseId;


	//使用码上放心-码上传平台
//	public static boolean uploadCircubillForPageMsc(List<SupervisionCode> codes,String rcvLineId,String inType,String outType,
//												 String userName,String sendEnterpriseId,String acceptEnterpriseId,
//												 String serverUrl,String appKey,String appSecret){
//		try {
//			List<String> supervisionCodes = codes.stream().map(SupervisionCode::getSupervisionCode).collect(Collectors.toList());
//			String traceCodes = String.join(",", supervisionCodes);
//
//			Long billType=0L;
//			if(ToolKits.isNotEmpty(outType)){
//				switch (outType) {
//					case "1":
//						billType = 201L;
//						break;
//					case "2":
//						billType = 202L;
//						break;
//					case "3":
//						billType = 203L;
//						break;
//					default:
//						billType = 217L;
//						break;
//				}
//			}
//
//			if(ToolKits.isNotEmpty(inType)){
//				switch (inType) {
//					case "1":
//						billType = 102L;
//						break;
//					case "2":
//						billType = 103L;
//						break;
//					default:
//						billType = 113L;
//						break;
//				}
//			}
//
//			log.info("serverUrl="+serverUrl);
//			log.info("appKey="+appKey);
//			log.info("appSecret="+appSecret);
//			TaobaoClient client = new DefaultTaobaoClient(serverUrl,appKey, appSecret);
//			AlibabaAlihealthDrugMscUploadinoutbillRequest req = new AlibabaAlihealthDrugMscUploadinoutbillRequest();
//			req.setBillCode(rcvLineId);//收货单明细行作为单据编号【同一个企业不能上传相同单据号】
//			req.setBillTime(new Date());
//			req.setBillType(billType);
//			req.setPhysicType(3L);//可任意填写
//			req.setRefUserId(sendEnterpriseId);//货主企业
//			req.setFromUserId(sendEnterpriseId);//发货企业
//			if(ToolKits.isNotEmpty(inType)){
//				log.info("发货企业="+sendEnterpriseId);
//				req.setToUserId(sendEnterpriseId);//如果是入库单类型，收货人为发货企业
//			}else {
//				log.info("收货企业="+acceptEnterpriseId);
//				req.setToUserId(acceptEnterpriseId);//如果是出库单类型，收货人为收货企业
//			}
//			req.setOperIcCode(appKey);//操作人标识（写appkey编号）
//			req.setOperIcName(userName);//操作人名称
//			req.setTraceCodes(traceCodes);
//			req.setClientType("2");//请求端类型【暂定都写2】
//
//			log.info("请求参数："+ JSONObject.toJSONString(req));
//			AlibabaAlihealthDrugMscUploadinoutbillResponse rsp = null;
//
//			rsp = client.execute(req);
//			log.info("返回报文："+rsp.getBody());
//			ObjectMapper mapper = new ObjectMapper();
//			JsonNode node = mapper.readTree(rsp.getBody());
//			String msg_code=node.get("alibaba_alihealth_drug_msc_uploadinoutbill_response").get("msg_code").toString();
//			log.info("是否成功："+msg_code);
//			if(msg_code.equals("\"SUCCESS\"")){
//				return true;
//			}else {
//				throw new BizException(rsp.getBody());
//			}
//		} catch (Exception e) {
//			log.info("catch:"+e);
//			throw new BizException("企业上传出入库信息失败："+e);
//		}
//	}


	//使用码上放心-快易通服务（老版本暂时未使用）
//	public static boolean uploadCircubillForPageKyt(List<SupervisionCode> codes,String rcvLineId,String inType,String outType,
//												 String userName,String sendEnterpriseId,String acceptEnterpriseId,
//												 String serverUrl,String appKey,String appSecret){
//	try {
//		//创建Document对象
//		Document document= DocumentHelper.createDocument();
//		//创建元素
//		Element Document = document.addElement("Document");
//		Element events = Document.addElement("Events");
//		Element EventElement=events.addElement("Event");
//		Long billType=0L;
//		if(ToolKits.isNotEmpty(outType)){
//			switch (outType) {
//				case "1":
//					billType = 201L;
//					EventElement.addAttribute("Name", "SalesWareHouseOut");
//					break;
//				case "2":
//					billType = 202L;
//					EventElement.addAttribute("Name", "ReturnWareHouseOut");
//					break;
//				case "3":
//					billType = 203L;
//					EventElement.addAttribute("Name", "AllocateWareHouseOut");
//					break;
//				default:
//					billType = 217L;
//					EventElement.addAttribute("Name", "OtherHouseOut");
//					break;
//			}
//		}
//
//		if(ToolKits.isNotEmpty(inType)){
//			switch (inType) {
//				case "1":
//					billType = 102L;
//					EventElement.addAttribute("Name", "PurchaseWareHouseIn");
//					break;
//				case "2":
//					billType = 103L;
//					EventElement.addAttribute("Name", "ReturnWareHouseIn");
//					break;
//				default:
//					billType = 113L;
//					EventElement.addAttribute("Name", "OtherHouseIn");
//					break;
//			}
//		}
//
//		if(ToolKits.isNotEmpty(inType)){
//			EventElement.addAttribute("MainAction", "WareHouseIn");
//		}else {
//			EventElement.addAttribute("MainAction", "WareHouseOut");
//		}
//		Element dataField = EventElement.addElement("DataField");
//		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//		String Dateformat = sdf.format(new Date());
//
//		//创建子元素并直接添加进根元素
//		for (SupervisionCode code : codes) {
//			Element data = dataField.addElement("Data");
//			data.addAttribute("Code", String.valueOf(code.getSupervisionCode()));
//			data.addAttribute("CorpOrderID", String.valueOf(code.getId()));
//			data.addAttribute("ActDate", Dateformat);
//			data.addAttribute("ToCorpID", "");
//		}
//
//		// 使用 OutputFormat 进行格式化设置
//		OutputFormat format = OutputFormat.createCompactFormat();
//		// 设置是否缩进，默认为 false
//		format.setIndent(false);
//		// 创建 StringWriter 来保存转换后的无格式 XML 字符串
//		java.io.StringWriter stringWriter = new java.io.StringWriter();
//		// 创建 XMLWriter 对象并设置输出流和格式化参数
//		XMLWriter writer = new XMLWriter(stringWriter, format);
//		// 将 Document 对象写入到输出流中，并触发转换操作
//		writer.write(document);
//		String xmlStringWithoutFormatting = stringWriter.toString();
//        log.info("XML格式为："+xmlStringWithoutFormatting);
//
////		String serverUrl = "http://gw.api.taobao.com/router/rest";
////		String appKey= "31829450";
////		String appSecret ="ec698ea2ac4accd88006cd8a390b4567";
////		String sendEnterpriseId = "fa3dfe7f41ce42c1b6b6f9505e530e32";
////			String acceptEnterpriseId ="66677777780507433";//收货企业，暂时不可用
////		String acceptEnterpriseId ="646d79e8e4b09d4f0095a831";//平台的测试收货企业ID，测试时先使用这个
//		log.info("serverUrl="+serverUrl);
//		log.info("appKey="+appKey);
//		log.info("appSecret="+appSecret);
//		TaobaoClient client = new DefaultTaobaoClient(serverUrl,appKey, appSecret);
//		AlibabaAlihealthDrugKytUploadcircubillRequest req = new AlibabaAlihealthDrugKytUploadcircubillRequest();
////		AlibabaAlihealthDrugMscUploadinoutbillRequest req = new AlibabaAlihealthDrugMscUploadinoutbillRequest();
//		req.setBillCode(rcvLineId);//收货单明细行作为单据编号【同一个企业不能上传相同单据号】
//		req.setBillTime(new Date());
//		req.setBillType(billType);
//
//
//		req.setPhysicType(3L);//可任意填写
//		req.setRefUserId(sendEnterpriseId);//货主企业
//		req.setFromUserId(sendEnterpriseId);//发货企业
//		if(ToolKits.isNotEmpty(inType)){
//			log.info("发货企业="+sendEnterpriseId);
//			req.setToUserId(sendEnterpriseId);//如果是入库单类型，收货人为发货企业
//		}else {
//			log.info("收货企业="+acceptEnterpriseId);
//			req.setToUserId(acceptEnterpriseId);//如果是出库单类型，收货人为收货企业
//		}
//		req.setOperIcCode(appKey);//操作人标识（写appkey编号）
//		req.setOperIcName(userName);//操作人名称
//		String fileZipContent = createFileZipContentnew(xmlStringWithoutFormatting);
//		req.setFileContent(fileZipContent);//填写单据文件xml的加密串
//		req.setUploadFileName(rcvLineId+".xml");//单据文件名称不能重复
//		req.setClientType("2");//请求端类型【暂定都写2】
//
//        log.info("请求参数："+ JSONObject.toJSONString(req));
//		AlibabaAlihealthDrugMscUploadinoutbillResponse rsp = null;
//
//		rsp = client.execute(req);
//        log.info("返回报文："+rsp.getBody());
//		ObjectMapper mapper = new ObjectMapper();
//		JsonNode node = mapper.readTree(rsp.getBody());
//		String msg_code=node.get("alibaba_alihealth_drug_kyt_uploadcircubill_response").get("msg_code").toString();
//        log.info("是否成功："+msg_code);
//		if(msg_code.equals("\"SUCCESS\"")){
//			return true;
//		}else {
//			throw new BizException(rsp.getBody());
//		}
//	} catch (Exception e) {
//        log.info("catch:"+e);
//		throw new BizException("上传监管码失败："+e);
//		}
//	}

//	//使用码上放心-码上传平台
//	public static Map uploadCircubillMsc(List<SupervisionCode> codeS,String rcvLineId,String inType, String outType,
//												String userName,String sendEnterpriseId, String eleccode,
//												String serverUrl,String appKey,String appSecret,Integer uploadType) {
//		Map map =new HashMap();
//		String message;
//		try {
//			log.info("rcvLineId=" + rcvLineId);
//			if(ToolKits.isEmpty(eleccode)){
//				message = rcvLineId + "eleccode为空";
//				log.info("eleccode为空");
//				map.put("isSuccess",false);
//				map.put("message",message);
//				return map;
//			}
//			log.info("eleccode=" + eleccode);
//			List<String> supervisionCodes = codeS.stream().map(SupervisionCode::getSupervisionCode).collect(Collectors.toList());
//			String traceCodes = String.join(",", supervisionCodes);
//			Long billType = 0L;
//			log.info("uploadType=" + uploadType);
//			if(uploadType == 1){
//				switch (outType) {
//					case "1":
//						billType = 201L;
//						break;
//					case "2":
//						billType = 202L;
//						break;
//					case "3":
//						billType = 203L;
//						break;
//					default:
//						billType = 217L;
//						break;
//				}
//			}else {
//				switch (inType) {
//					case "1":
//						billType = 102L;
//						break;
//					case "2":
//						billType = 103L;
//						break;
//					default:
//						billType = 113L;
//						break;
//				}
//			}
//
//			TaobaoClient client = new DefaultTaobaoClient(serverUrl, appKey, appSecret);
//			log.info("serverUrl=" + serverUrl);
//			log.info("appKey=" + appKey);
//			log.info("appSecret=" + appSecret);
//			AlibabaAlihealthDrugMscUploadinoutbillRequest req = new AlibabaAlihealthDrugMscUploadinoutbillRequest();
//			req.setBillCode(rcvLineId);//收货单明细行wms_in_rcv_lines.rcv_line_id或者wms_pick_task_d.pick_task_d_id作为单据编号【同一个企业不能上传相同单据号】
//			req.setBillTime(new Date());
//			req.setBillType(billType);
//			req.setPhysicType(3L);//可任意填写
//			req.setRefUserId(sendEnterpriseId);//货主企业
//
//			if(uploadType == 1){//如果是出库单类型,发货企业为江西青牛医药有限公司，收货企业为客户或者供应商对应的监管码企业ID
//				log.info("单据类型出库单，发货企业entId=" + sendEnterpriseId);
//				req.setFromUserId(sendEnterpriseId);//发货企业
//				log.info("单据类型出库单，收货企业entId=" + eleccode);
//				req.setToUserId(eleccode);//收货企业
//			}else { //如果是入库单类型,发货企业为供应商对应的监管码企业ID，收货企业为江西青牛医药有限公司
//				log.info("单据类型入库单，发货企业entId=" + eleccode);
//				req.setFromUserId(eleccode);//发货企业
//				log.info("单据类型入库单，收货企业entId=" + sendEnterpriseId);
//				req.setToUserId(sendEnterpriseId);//收货企业
//			}
//
//			req.setOperIcCode(appKey);//操作人标识（写appkey编号）
//			req.setOperIcName(userName);//操作人名称
//			req.setTraceCodes(traceCodes);
//			req.setClientType("2");//请求端类型【暂定都写2】
//
//			log.info("上传监管码请求参数：" + JSONObject.toJSONString(req));
//			AlibabaAlihealthDrugMscUploadinoutbillResponse rsp = null;
//
//			rsp = client.execute(req);
//			log.info("上传监管码返回报文：" + rsp.getBody());
//			ObjectMapper mapper = new ObjectMapper();
//			JsonNode node = mapper.readTree(rsp.getBody());
//			String msg_code = node.get("alibaba_alihealth_drug_msc_uploadinoutbill_response").get("msg_code").toString();
//			log.info("上传监管码是否成功：" + msg_code);
//			if (msg_code.equals("\"SUCCESS\"")) {
//				message = "上传成功";
//				map.put("isSuccess",true);
//				map.put("message",message);
//				return map;
//			} else {
//				message = "上传失败"+rsp.getBody();
//				map.put("isSuccess",false);
//				map.put("message",message);
//				return map;
//			}
//		} catch (Exception e) {
//			e.printStackTrace();
//			log.info("企业上传出入库信息catch:" + e.getMessage());
//			if(e.getMessage().length() >2000){
//				message = e.getMessage().substring(1,2000);
//			}else {
//				message = e.getMessage();
//			}
//			message = "上传失败" + e.getMessage();
//			map.put("isSuccess",false);
//			map.put("message",message);
//			return map;
//		}
//	}

	//使用码上放心-码上传平台 --按照出库单或者入库单的billno维度来回传
	public static Map uploadCircubillMsc(List<SupervisionCode> codeS,String billno,String inType, String outType,
										 String userName,String sendEnterpriseId, String eleccode,
										 String serverUrl,String appKey,String appSecret,Integer uploadType) {
		Map map =new HashMap();
		String message;
		try {
			log.info("billno=" + billno);
			if(ToolKits.isEmpty(eleccode)){
				message = billno + "eleccode为空";
				log.info("eleccode为空");
				map.put("isSuccess",false);
				map.put("message",message);
				return map;
			}
			log.info("eleccode=" + eleccode);
			List<String> supervisionCodes = codeS.stream().map(SupervisionCode::getSupervisionCode).collect(Collectors.toList());
			String traceCodes = String.join(",", supervisionCodes);
			Long billType = 0L;
			log.info("uploadType=" + uploadType);
			if(uploadType == 1){
				switch (outType) {
					case "1":
						billType = 201L;
						break;
					case "2":
						billType = 202L;
						break;
					case "3":
						billType = 203L;
						break;
					default:
						billType = 217L;
						break;
				}
			}else {
				switch (inType) {
					case "1":
						billType = 102L;
						break;
					case "2":
						billType = 103L;
						break;
					default:
						billType = 113L;
						break;
				}
			}

			TaobaoClient client = new DefaultTaobaoClient(serverUrl, appKey, appSecret);
			log.info("serverUrl=" + serverUrl);
			log.info("appKey=" + appKey);
			log.info("appSecret=" + appSecret);
			AlibabaAlihealthDrugMscUploadinoutbillRequest req = new AlibabaAlihealthDrugMscUploadinoutbillRequest();
			req.setBillCode(billno);//出库单或者入库单asn对应的billno作为单据编号【同一个企业不能上传相同单据号】
			req.setBillTime(new Date());
			req.setBillType(billType);
			req.setPhysicType(3L);//可任意填写
			req.setRefUserId(sendEnterpriseId);//货主企业

			if(uploadType == 1){//如果是出库单类型,发货企业为江西青牛医药有限公司，收货企业为客户或者供应商对应的监管码企业ID
				log.info("单据类型出库单，发货企业entId=" + sendEnterpriseId);
				req.setFromUserId(sendEnterpriseId);//发货企业
				log.info("单据类型出库单，收货企业entId=" + eleccode);
				req.setToUserId(eleccode);//收货企业
			}else { //如果是入库单类型,发货企业为供应商对应的监管码企业ID，收货企业为江西青牛医药有限公司
				log.info("单据类型入库单，发货企业entId=" + eleccode);
				req.setFromUserId(eleccode);//发货企业
				log.info("单据类型入库单，收货企业entId=" + sendEnterpriseId);
				req.setToUserId(sendEnterpriseId);//收货企业
			}

			req.setOperIcCode(appKey);//操作人标识（写appkey编号）
			req.setOperIcName(userName);//操作人名称
			req.setTraceCodes(traceCodes);
			req.setClientType("2");//请求端类型【暂定都写2】

			log.info("上传监管码请求参数：" + JSONObject.toJSONString(req));
			AlibabaAlihealthDrugMscUploadinoutbillResponse rsp = null;

			rsp = client.execute(req);
			log.info("上传监管码返回报文：" + rsp.getBody());
			ObjectMapper mapper = new ObjectMapper();
			JsonNode node = mapper.readTree(rsp.getBody());
			String msg_code = node.get("alibaba_alihealth_drug_msc_uploadinoutbill_response").get("msg_code").toString();
			log.info("上传监管码是否成功：" + msg_code);
			if (msg_code.equals("\"SUCCESS\"")) {
				message = "上传成功";
				map.put("isSuccess",true);
				map.put("message",message);
				return map;
			} else {
				message = "上传失败"+rsp.getBody();
				map.put("isSuccess",false);
				map.put("message",message);
				return map;
			}
		} catch (Exception e) {
			e.printStackTrace();
			log.info("企业上传出入库信息catch:" + e.getMessage());
			if(e.getMessage().length() >2000){
				message = e.getMessage().substring(1,2000);
			}else {
				message = e.getMessage();
			}
			message = "上传失败" + e.getMessage();
			map.put("isSuccess",false);
			map.put("message",message);
			return map;
		}
	}


	//使用码上放心-快易通服务（老版本暂时未使用）
//	public static boolean uploadCircubillNewKyt(List<SupervisionCode> codeS,String rcvLineId,String inType, String outType,
//											 String userName,String sendEnterpriseId, String acceptEnterpriseId,
//											 String serverUrl,String appKey,String appSecret){
//	try {
//		Document document= DocumentHelper.createDocument();
//		//创建元素
//		Element Document = document.addElement("Document");
//		Element events = Document.addElement("Events");
//		Element EventElement=events.addElement("Event");
//		Long billType=0L;
//		if(ToolKits.isNotEmpty(outType)){
//			switch (outType) {
//				case "1":
//					billType = 201L;
//					EventElement.addAttribute("Name", "SalesWareHouseOut");
//					break;
//				case "2":
//					billType = 202L;
//					EventElement.addAttribute("Name", "ReturnWareHouseOut");
//					break;
//				case "3":
//					billType = 203L;
//					EventElement.addAttribute("Name", "AllocateWareHouseOut");
//					break;
//				default:
//					billType = 217L;
//					EventElement.addAttribute("Name", "OtherHouseOut");
//					break;
//			}
//		}
//
//		if(ToolKits.isNotEmpty(inType)){
//			switch (inType) {
//				case "1":
//					billType = 102L;
//					EventElement.addAttribute("Name", "PurchaseWareHouseIn");
//					break;
//				case "2":
//					billType = 103L;
//					EventElement.addAttribute("Name", "ReturnWareHouseIn");
//					break;
//				default:
//					billType = 113L;
//					EventElement.addAttribute("Name", "OtherHouseIn");
//					break;
//			}
//		}
//
//		if(ToolKits.isNotEmpty(inType)){
//			EventElement.addAttribute("MainAction", "WareHouseIn");
//		}else {
//			EventElement.addAttribute("MainAction", "WareHouseOut");
//		}
//		Element dataField = EventElement.addElement("DataField");
//		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//		String Dateformat = sdf.format(new Date());
//
//		for (SupervisionCode code : codeS) {
//			//创建子元素并直接添加进根元素
//			Element data = dataField.addElement("Data");
//			data.addAttribute("Code", String.valueOf(code.getSupervisionCode()));
//			data.addAttribute("CorpOrderID", String.valueOf(code.getId()));
//			data.addAttribute("ActDate", Dateformat);
//			data.addAttribute("ToCorpID", "");
//		}
//
//		// 使用 OutputFormat 进行格式化设置
//		OutputFormat format = OutputFormat.createCompactFormat();
//		// 设置是否缩进，默认为 false
//		format.setIndent(false);
//		// 创建 StringWriter 来保存转换后的无格式 XML 字符串
//		java.io.StringWriter stringWriter = new java.io.StringWriter();
//		// 创建 XMLWriter 对象并设置输出流和格式化参数
//		XMLWriter writer = new XMLWriter(stringWriter, format);
//		// 将 Document 对象写入到输出流中，并触发转换操作
//		writer.write(document);
//		String xmlStringWithoutFormatting = stringWriter.toString();
//        log.info("XML格式为："+xmlStringWithoutFormatting);
////
////		String serverUrl = "http://gw.api.taobao.com/router/rest";
////		String appKey= "31829450";
////		String appSecret ="ec698ea2ac4accd88006cd8a390b4567";
////		String sendEnterpriseId = "fa3dfe7f41ce42c1b6b6f9505e530e32";
//////			String acceptEnterpriseId ="66677777780507433";//收货企业，暂时不可用
////		String acceptEnterpriseId ="646d79e8e4b09d4f0095a831";//平台的测试收货企业ID，测试时先使用这个
//
//		TaobaoClient client = new DefaultTaobaoClient(serverUrl,appKey, appSecret);
//        log.info("serverUrl="+serverUrl);
//        log.info("appKey="+appKey);
//        log.info("appSecret="+appSecret);
////		AlibabaAlihealthDrugMscUploadinoutbillRequest req = new AlibabaAlihealthDrugMscUploadinoutbillRequest();
//		AlibabaAlihealthDrugKytUploadcircubillRequest req1 = new AlibabaAlihealthDrugKytUploadcircubillRequest();
//		req.setBillCode(rcvLineId);//收货单明细行作为单据编号【同一个企业不能上传相同单据号】
//		req.setBillTime(new Date());
//		req.setBillType(billType);
//
//
//		req.setPhysicType(3L);//可任意填写
//		req.setRefUserId(sendEnterpriseId);//货主企业
//		req.setFromUserId(sendEnterpriseId);//发货企业
//		if(ToolKits.isNotEmpty(inType)){
//            log.info("发货企业entId="+sendEnterpriseId);
//			req.setToUserId(sendEnterpriseId);//如果是入库单类型，收货人为发货企业
//		}else {
//            log.info("收货企业entId="+acceptEnterpriseId);
//			req.setToUserId(acceptEnterpriseId);//如果是出库单类型，收货人为收货企业
//		}
//		req.setOperIcCode(appKey);//操作人标识（写appkey编号）
//		req.setOperIcName(userName);//操作人名称
//		String fileZipContent = createFileZipContentnew(xmlStringWithoutFormatting);
//		req.setFileContent(fileZipContent);//填写单据文件xml的加密串
//		req.setUploadFileName(rcvLineId+".xml");//单据文件名称不能重复
//		req.setClientType("2");//请求端类型【暂定都写2】
//
//		log.info("上传监管码请求参数："+ JSONObject.toJSONString(req));
//		AlibabaAlihealthDrugMscUploadinoutbillResponse rsp = null;
//
//		rsp = client.execute(req);
//		log.info("上传监管码返回报文："+rsp.getBody());
//		ObjectMapper mapper = new ObjectMapper();
//		JsonNode node = mapper.readTree(rsp.getBody());
//		String msg_code=node.get("alibaba_alihealth_drug_kyt_uploadcircubill_response").get("msg_code").toString();
//		log.info("上传监管码是否成功："+msg_code);
//		if(msg_code.equals("\"SUCCESS\"")){
//			return true;
//		}else {
//			return false;
//		}
//	} catch (Exception e) {
//		e.printStackTrace();
//		log.info("上传监管码失败catch:"+e.getMessage());
//		return false;
//		}
//	}

//	public static  String createFileZipContentnew(String xmlFileContent) {
//		try {
//			byte[] temp_fileByte = xmlFileContent.getBytes("UTF-8");
//			byte[] fileByte = compressFile(temp_fileByte);
//			String base64Content = "";
//			base64Content = base64EncoderToByte(fileByte);
//			return base64Content;
//		} catch (UnsupportedEncodingException e1) {
//			e1.printStackTrace();
//		}
//		return null;
//	}

//	private static byte[] compressFile(byte abyte0[]) {
//		byte abyte1[] = null;
//		try {
//			ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
//			GZIPOutputStream gzipoutputstream = new GZIPOutputStream(
//					bytearrayoutputstream);
//			gzipoutputstream.write(abyte0);
//			gzipoutputstream.finish();
//			abyte1 = bytearrayoutputstream.toByteArray();
//			gzipoutputstream.close();
//			bytearrayoutputstream.close();
//		} catch (IOException ioexception) {
//			ioexception.printStackTrace();
//		}
//		return abyte1;
//	}

//	private static String base64EncoderToByte(byte[] gzByte) {
//		sun.misc.BASE64Encoder be = new sun.misc.BASE64Encoder();
//		return be.encode(gzByte);
//	}
}

