package com.weaver.seconddev.interfaces.srmoa;

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.srmoa.SI_GoodsSupplyExpanding_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 OaSrmVenMatExtService extends BaseBean {

    private static final org.slf4j.Logger logger_333d882d = LoggerFactory.getLogger(OaSrmVenMatExtService.class);
    @Autowired
    private ConfigProp configProp;
    public String[] call(SRM_OA_VENMATEXT_RESULT param) {
        String[] str = new String[3];
//        String url = Util.null2String(I18nContextUtilcus.getBean(Environment.class).getProperty("htsrmoasync.SrmVenMatExt")).trim();

        String url  = configProp.getSrmVenMatExtnew();
//        String url = "http://10.6.6.155:8080/srm/services/OaSrmVenMatExtService";
        try {
            logger_333d882d.error(String.valueOf("调用SRM供应商货源关系接口开始"));
            SI_GoodsSupplyExpanding_OUTServiceStub stub = new SI_GoodsSupplyExpanding_OUTServiceStub(url);
            logger_333d882d.error("stub--" + stub);
            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);
            logger_333d882d.error("stub--" + stub);
//            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());
//            auth.setUsername("pouser");
//            auth.setPassword("654321");
            logger_333d882d.error("auth--" + auth);
            stub._getServiceClient().getOptions().setProperty(org.apache.axis2.kernel.http.HTTPConstants.AUTHENTICATE,auth);
            logger_333d882d.error("stub--" + stub);
            SRM_OA_VENMATEXT_RESULTE req = new SRM_OA_VENMATEXT_RESULTE();
            req.setSRM_OA_VENMATEXT_RESULT(param);
            logger_333d882d.error("req--" + req);
            SRM_OA_VENMATEXT_RESULTResponseE res = stub.sI_GoodsSupplyExpanding_OUT(req);
            logger_333d882d .error("res--" + res);
            SRM_OA_VENMATEXT_RESULTResponse result = res.getSRM_OA_VENMATEXT_RESULTResponse();
            logger_333d882d .error("result--" + result);
            VenMatExtResultOut resultOut = result.getOutputTab();
            str[0] = resultOut.getIstat();
            str[1] = resultOut.getMsg();
            str[2] = resultOut.getRequestId();
            logger_333d882d.error(String.valueOf("调用SRM供应商货源关系接口开始结束：" + str[2] + "--" + str[0] + "--" + str[1]));
        } catch (Exception e) {
            str[0] = "-1";
            str[1] = e.toString();
            logger_333d882d.error(String.valueOf("调用SRM供应商货源关系接口开始出错：" + e.toString()));
        }
        return str;
    }

    public String[] sendsrm(VenMatExtHandlerServiceServiceStub.SRM_OA_VENMATEXT_RESULT param, String requestid) {
        String[] str = new String[3];
        try {
            logger_333d882d.error(String.valueOf(requestid + "调用SRM供应商货源关系接口开始"));
//            this(configurationContext, Prop.getPropValue("htsrmoasync","SrmVenMatExtnew") );
            String url = configProp.getSrmVenMatExtnew();
            VenMatExtHandlerServiceServiceStub vhss = new VenMatExtHandlerServiceServiceStub(url);
            VenMatExtHandlerServiceServiceStub.SRM_OA_VENMATEXT_RESULTE srt = new VenMatExtHandlerServiceServiceStub.SRM_OA_VENMATEXT_RESULTE();
            srt.setSRM_OA_VENMATEXT_RESULT(param);
//            VenMatExtHandlerServiceServiceStub.SRM_OA_VENMATEXT_RESULTResponseE res = vhss.SRM_OA_VENMATEXT_RESULT(srt);
            VenMatExtHandlerServiceServiceStub.SRM_OA_VENMATEXT_RESULTResponseE res = vhss.sRM_OA_VENMATEXT_RESULT(srt);
            VenMatExtHandlerServiceServiceStub.VenMatExtResultOut resultOut = res.getSRM_OA_VENMATEXT_RESULTResponse().getOutputTab();
            str[0] = resultOut.getIstat();
            str[1] = resultOut.getMsg();
            str[2] = resultOut.getRequestId();
            logger_333d882d.error(String.valueOf(requestid + "调用SRM供应商货源关系接口开始结束：" + str[2] + "--" + str[0] + "--" + str[1]));
        } catch (Exception e) {
            str[0] = "-1";
            str[1] = e.toString();
            logger_333d882d.error(String.valueOf(e));
            logger_333d882d.error(String.valueOf(requestid + "调用SRM供应商货源关系接口开始出错：" + e.toString()));
        }
        return str;
    }
}
