package com.weaver.seconddev.interfaces.k3;

import  com.weaver.seconddev.interfaces.k3.TransferBillServiceStub.ArrayOfTransferBillRes;
import  com.weaver.seconddev.interfaces.k3.TransferBillServiceStub.BuildTransferBill;
import  com.weaver.seconddev.interfaces.k3.TransferBillServiceStub.TransferBillReq;
import  com.weaver.seconddev.interfaces.k3.TransferBillServiceStub.TransferBillRes;
import com.weaver.common.i18n.tool.util.I18nContextUtil;
import com.weaver.seconddev.interfaces.prop.ConfigProp;
import org.apache.axis2.kernel.http.HTTPConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import java.lang.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.weaver.verupgrade.general.BaseBean;
import com.weaver.verupgrade.general.Util;
import org.springframework.stereotype.Component;

@Component
public class TransferBillService extends BaseBean {

	private static final org.slf4j.Logger logger_8574e473 = LoggerFactory.getLogger(TransferBillService.class);
	@Autowired
	private ConfigProp configProp;
	public String[] call(TransferBillReq param) {
		String[] str = new String[4];
		try {
			logger_8574e473.error(String.valueOf("TransferBillService--start"));
//			String url = Util.null2String(I18nContextUtilcus.getBean(Environment.class).getProperty("htk3oasync.lplyhtk_url")).trim();
			String url = configProp.getLplysl_url();
			TransferBillServiceStub stub = new TransferBillServiceStub(url);
			stub._getServiceClient().getOptions().setProperty("__CHUNKED__", Boolean.FALSE);
			stub._getServiceClient().getOptions().setTimeOutInMilliSeconds(300000);
			stub._getServiceClient().getOptions().setProperty(HTTPConstants.SO_TIMEOUT,300000);
			stub._getServiceClient().getOptions().setProperty(HTTPConstants.CONNECTION_TIMEOUT,300000);
			BuildTransferBill req = new BuildTransferBill();
			req.setObj(param);
			TransferBillServiceStub.BuildTransferBillResponse res = stub.buildTransferBill(req);
			ArrayOfTransferBillRes arrays = res.getBuildTransferBillResult();
			TransferBillRes[] result = arrays.getTransferBillRes();
			str[0] = "1";
			str[2] = "";
			str[3] = "";
			StringBuilder sb = new StringBuilder();
			for (int i = 0; i < result.length; i++) {
				if ("0".equals(result[i].getCode())) {
					str[0] = "0";
					str[2] += "'" + result[i].getFStockNumber() + "',";
					sb.append(result[i].getFStockNumber() + "：" + result[i].getMessage() + "；");
				} else {
					str[3] += "'" + result[i].getFStockNumber() + "',";
					sb.append(result[i].getFStockNumber() + "：" + result[i].getMessage() + result[i].getResult() + "；");
				}
			}
			str[1] = sb.toString();
			logger_8574e473.error(String.valueOf("TransferBillService--result:[" + str[0] + "|" + str[1] + "|" + str[2] + "|" + str[3] + "]"));
		} catch (Exception e) {
			str[0] = "0";
			str[1] = e.toString();
			str[2] = "";
			str[3] = "";
			logger_8574e473.error(String.valueOf("TransferBillService--error:" + e.toString()));
		}
		return str;
	}
}
