package com.weaver.seconddev.interfaces.k3;

import com.alibaba.csp.sentinel.command.annotation.CommandMapping;
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 CallK3CustomerService extends BaseBean {

    private static final org.slf4j.Logger logger_1a80d0a1 = LoggerFactory.getLogger(CallK3CustomerService.class);
    @Autowired
    private ConfigProp configProp;
    /**
     * 校验
     * @return
     */
    public CustomerServiceStub.CustomerSearchRes getCustMsg(CustomerServiceStub.CustomerSearchReq req) {
        // String[] resultArray = new String[2];
        CustomerServiceStub.CustomerSearchRes result = new CustomerServiceStub.CustomerSearchRes();
        try {
//            String url = Util.null2String(I18nContextUtilcus.getBean(Environment.class).getProperty("htk3oasync.customer_url")).trim();
            String url = configProp.getCustomer_url();
            CustomerServiceStub stub = new CustomerServiceStub(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);
            CustomerServiceStub.GeCustMsg input = new CustomerServiceStub.GeCustMsg();
            input.setCustSearch(req);
            CustomerServiceStub.GeCustMsgResponse response = stub.geCustMsg(input);
            result = response.getGeCustMsgResult();
            logger_1a80d0a1.error(String.valueOf("调用k3客户校验接口成功"));
        } catch (Exception e) {
            logger_1a80d0a1.error("调用k3客户校验接口出错：" , e);
        }
        return result;
    }

    /**
     * 获取客户详细信息
     * @param req
     * @return
     */
    public CustomerServiceStub.CustomerReturn getCustomer(CustomerServiceStub.CustomerSearchReq req) {
        CustomerServiceStub.CustomerReturn result = new CustomerServiceStub.CustomerReturn();
        try {
//            String url = Util.null2String(I18nContextUtilcus.getBean(Environment.class).getProperty("htk3oasync.customer_url")).trim();
            String url = configProp.getCustomer_url();
            CustomerServiceStub stub = new CustomerServiceStub(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);
            CustomerServiceStub.GetCustomer input = new CustomerServiceStub.GetCustomer();
            input.setCustSearch(req);
            CustomerServiceStub.GetCustomerResponse response = stub.getCustomer(input);
            result = response.getGetCustomerResult();
            logger_1a80d0a1.error(String.valueOf("调用k3获取客户详细信息接口成功"));
        } catch (Exception e) {
            logger_1a80d0a1.error(String.valueOf("调用K3获取客户详细信息接口出错：" + e.toString()));
        }
        return result;
    }

    /**
     * 提交客户信息
     * @param req
     * @return
     */
    public CustomerServiceStub.CustomerRes buildCustomer(CustomerServiceStub.CustomerReq req) {
        // String[] resultArray = new String[2];
        CustomerServiceStub.CustomerRes result = new CustomerServiceStub.CustomerRes();
        try {
//            String url = Util.null2String(I18nContextUtilcus.getBean(Environment.class).getProperty("htk3oasync.customer_url")).trim();
            String url = configProp.getCustomer_url();
            CustomerServiceStub stub = new CustomerServiceStub(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);
            CustomerServiceStub.BuildCustomer input = new CustomerServiceStub.BuildCustomer();
            input.setCustReq(req);
            CustomerServiceStub.BuildCustomerResponse response = stub.buildCustomer(input);
            result = response.getBuildCustomerResult();
            logger_1a80d0a1.error(String.valueOf("调用k3客户提交接口成功"));
        } catch (Exception e) {
            logger_1a80d0a1.error(String.valueOf("调用K3客户提交接口出错：" + e.toString()));
        }
        return result;
    }
}
