package com.weaver.seconddev.interfaces.easoa;

import com.weaver.seconddev.interfaces.prop.ConfigProp;
import org.apache.axis2.kernel.http.HTTPConstants;
import org.apache.axis2.transport.http.HttpTransportProperties;
import  com.weaver.seconddev.interfaces.easoa.SI_FiAgncyAssetApplicationSync_OUTServiceStub.*;
import com.weaver.common.i18n.tool.util.I18nContextUtil;
import org.apache.axis2.transport.http.impl.httpclient4.HttpTransportPropertiesImpl;
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 EASIntermediarySyncService extends BaseBean {

	private static final org.slf4j.Logger logger_cd0192cf = LoggerFactory.getLogger(EASIntermediarySyncService.class);

	@Autowired
	private ConfigProp configProp;
	public String[] call(IntermediaryApplication info) {
		String[] str = new String[2];
//		String url = Util.null2String(I18nContextUtilcus.getBean(Environment.class).getProperty("hteasoasync.intermediarysync")).trim();
		String url =configProp.getIntermediarysync();
		try {
			logger_cd0192cf.error(String.valueOf("调用报账系统中介同步接口开始  --- " + url ));
			SI_FiAgncyAssetApplicationSync_OUTServiceStub stub = new SI_FiAgncyAssetApplicationSync_OUTServiceStub(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);
//			HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();
////			auth.setUsername(Util.null2String(I18nContextUtilcus.getBean(Environment.class).getProperty("htportaloaUrl.po_user")).trim());
////			auth.setPassword(Util.null2String(I18nContextUtilcus.getBean(Environment.class).getProperty("htportaloaUrl.po_password")).trim());
//			auth.setUsername(configProp.getPo_user());
//			auth.setPassword(configProp.getPo_password());
			HttpTransportPropertiesImpl.Authenticator auth = new HttpTransportPropertiesImpl.Authenticator();
			auth.setUsername(configProp.getPo_user());
			auth.setPassword(configProp.getPo_password());
//			stub._getServiceClient().getOptions().setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, auth);
			stub._getServiceClient().getOptions().setProperty(org.apache.axis2.kernel.http.HTTPConstants.AUTHENTICATE,auth);
			IntermediaryService req = new IntermediaryService();
			IntermediaryApplicationSynchronization param = new IntermediaryApplicationSynchronization();
			IntermediaryApplication[] arr = new IntermediaryApplication[1];
			arr[0] = info;
			param.setITFID("HT01BZ025");
			param.setSENDID("");
			param.setSYSID("SYS006");
			param.setIntermediaryApplication(arr);
			req.setIntermediaryApplicationSynchronization(param);
			IntermediaryServiceResponse res = stub.sI_FiAgncyAssetApplicationSync_OUT(req);
			str[0] = res.get_return().getISTAT();
			if ("1".equals(str[0])) {
				str[1] = res.get_return().getMESSAGE();
			} else {
				ResultInfoLines[] lines = res.get_return().getResultInfoLinesArr();
				str[1] = lines[0].getMESSAGE();
			}
			logger_cd0192cf.error(String.valueOf("调用报账系统中介同步接口结束"));
		} catch (Exception e) {
			str[0] = "0";
			str[1] = e.toString();
			logger_cd0192cf.error(String.valueOf("调用报账系统中介同步接口出错：" + e.toString()));
		}
		return str;
	}
}
