package com.weaver.seconddev.interfaces.eipoa;

import com.weaver.common.i18n.tool.util.I18nContextUtil;
import com.weaver.seconddev.interfaces.eipoa.SI_HTPortalUAMGMT2_OUTServiceStub.UserSyncInfo;
import com.weaver.seconddev.interfaces.prop.ConfigProp;
import com.weaver.verupgrade.general.BaseBean;
import com.weaver.verupgrade.general.Util;
import org.apache.axis2.kernel.http.HTTPConstants;
import org.apache.axis2.transport.http.HttpTransportProperties;
import org.apache.axis2.transport.http.impl.httpclient4.HttpTransportPropertiesImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

@Component
public class AccountService extends BaseBean {

    private static final Logger logger_18cc50ce = LoggerFactory.getLogger(AccountService.class);
    @Autowired
    private ConfigProp configProp;
    public String[] account(String sendid, UserSyncInfo[] arr) {
        String[] array = new String[2];
//        String url = Util.null2String(I18nContextUtilcus.getBean(Environment.class).getProperty("htportaloaUrl.accountUrl")).trim();
        String url = configProp.getAccountUrl();

        logger_18cc50ce.error("url == " + url);
        try {
            logger_18cc50ce.error(String.valueOf("开始调用批量开户销户接口"));
            SI_HTPortalUAMGMT2_OUTServiceStub stub = new SI_HTPortalUAMGMT2_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());
            HttpTransportPropertiesImpl.Authenticator auth = new HttpTransportPropertiesImpl.Authenticator();
            auth.setUsername(configProp.getPo_user());
            auth.setPassword(configProp.getPo_password());

            logger_18cc50ce.error("sendid == " + sendid);
            logger_18cc50ce.error("getPo_user == " + configProp.getPo_user());

            logger_18cc50ce.error("getPo_password == " + configProp.getPo_password());

            stub._getServiceClient().getOptions().setProperty(org.apache.axis2.kernel.http.HTTPConstants.AUTHENTICATE,auth);
            SI_HTPortalUAMGMT2_OUTServiceStub.UserAccount request = new SI_HTPortalUAMGMT2_OUTServiceStub.UserAccount();
            request.setSendid(sendid);
            request.setUser(arr);
            logger_18cc50ce.error(String.valueOf(" start stub"));

            SI_HTPortalUAMGMT2_OUTServiceStub.UserAccountResponse response = stub.sI_HTPortalUAMGMT2_OUT(request);
            array[0] = "S";
            array[1] = response.getUserAccountReturn();
            logger_18cc50ce.error(String.valueOf("调用批量开户销户接口成功"));
        } catch (Exception e) {
            logger_18cc50ce.error("调用批量开户销户接口失败：" , e);
            array[0] = "E";
            array[1] = e.toString();
        }
        return array;
    }
}
