package com.weaver.seconddev.interfaces.k3;

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 CallPORequestService extends BaseBean {

    private static final org.slf4j.Logger logger_7febacb3 = LoggerFactory.getLogger(CallPORequestService.class);
    @Autowired
    private ConfigProp configProp;
    public PORequestServiceStub.PORequestRes buildPORequest(PORequestServiceStub.PORequestReq req) {

        logger_7febacb3.error(String.valueOf("调用k3采购申请接口开始  "));
        PORequestServiceStub.PORequestRes result = new PORequestServiceStub.PORequestRes();
        try {
//            String url = Util.null2String(I18nContextUtilcus.getBean(Environment.class).getProperty("htk3oasync.porequest_url")).trim();
            String url = configProp.getPorequest_url();
            PORequestServiceStub stub = new PORequestServiceStub(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(getPropValue("htportaloaUrl", "po_user")).trim());
            // auth.setPassword(Util.null2String(getPropValue("htportaloaUrl", "po_password")).trim());
            // stub._getServiceClient().getOptions().setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE,auth);
            PORequestServiceStub.BuildPORequest input = new PORequestServiceStub.BuildPORequest();
            input.setPurReq(req);
            PORequestServiceStub.BuildPORequestResponse response = stub.buildPORequest(input);
            result = response.getBuildPORequestResult();
            logger_7febacb3.error(String.valueOf("调用k3采购申请交接口成功"));
        } catch (Exception e) {
            logger_7febacb3.error(String.valueOf("调用K3采购申请提交接口出错：" + e.toString()));
        }
        return result;
    }
}
