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;

/**
 * k3cloud供应商
 */
@Component
public class CallK3SupplierServices extends BaseBean {

    private static final org.slf4j.Logger logger_8469efe0 = LoggerFactory.getLogger(CallK3SupplierServices.class);
    @Autowired
    private ConfigProp configProp;
    /**
     * 校验
     * @return
     */
    public SupplierServiceStub.SupplierSearchRes getSupMsg(SupplierServiceStub.SupplierSearchReq req) {
        // String[] resultArray = new String[2];
        SupplierServiceStub.SupplierSearchRes result = new SupplierServiceStub.SupplierSearchRes();
        try {
//            String url = Util.null2String(I18nContextUtilcus.getBean(Environment.class).getProperty("htk3oasync.supplier_url")).trim();
            String url = configProp.getSupplier_url();
            SupplierServiceStub stub = new SupplierServiceStub(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);
            SupplierServiceStub.GetSupMsg input = new SupplierServiceStub.GetSupMsg();
            input.setSupSearch(req);
            SupplierServiceStub.GetSupMsgResponse response = stub.getSupMsg(input);
            result = response.getGetSupMsgResult();
            logger_8469efe0.error(String.valueOf("调用k3供应商校验接口成功"));
        } catch (Exception e) {
            logger_8469efe0.error(String.valueOf("调用k3供应商校验接口出错：" + e.toString()));
        }
        return result;
    }

    /**
     * 获取供应商详细信息
     * @param req
     * @return
     */
    public SupplierServiceStub.SupplierReturn getSupplier(SupplierServiceStub.SupplierSearchReq req) {
        // //        String[] resultArray = new String[2];
        SupplierServiceStub.SupplierReturn result = new SupplierServiceStub.SupplierReturn();
        try {
//            String url = Util.null2String(I18nContextUtilcus.getBean(Environment.class).getProperty("htk3oasync.supplier_url")).trim();
            String url = configProp.getSupplier_url();
            SupplierServiceStub stub = new SupplierServiceStub(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);
            SupplierServiceStub.GetSupplier input = new SupplierServiceStub.GetSupplier();
            input.setSupSearch(req);
            SupplierServiceStub.GetSupplierResponse response = stub.getSupplier(input);
            result = response.getGetSupplierResult();
            logger_8469efe0.error(String.valueOf("调用k3获取供应商详细信息接口成功"));
        } catch (Exception e) {
            logger_8469efe0.error(String.valueOf("调用K3获取供应商详细信息接口出错：" + e.toString()));
        }
        return result;
    }

    public SupplierServiceStub.SupplierRes buildSupplier(SupplierServiceStub.SupplierReq req) {
        // String[] resultArray = new String[2];
        SupplierServiceStub.SupplierRes result = new SupplierServiceStub.SupplierRes();
        try {
//            String url = Util.null2String(I18nContextUtilcus.getBean(Environment.class).getProperty("htk3oasync.supplier_url")).trim();
            String url = configProp.getSupplier_url();
            SupplierServiceStub stub = new SupplierServiceStub(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);
            SupplierServiceStub.BuildSupplier input = new SupplierServiceStub.BuildSupplier();
            input.setSupSearch(req);
            SupplierServiceStub.BuildSupplierResponse response = stub.buildSupplier(input);
            result = response.getBuildSupplierResult();
            logger_8469efe0.error(String.valueOf("调用k3供应商提交接口成功"));
        } catch (Exception e) {
            logger_8469efe0.error(String.valueOf("调用K3供应商提交接口出错：" + e.toString()));
        }
        return result;
    }
}
