package com.weaver.seconddev.interfaces.k3;

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.k3.SI_HTOAPurreqAPPROSync_OUTServiceStub.OAPRResultItemIn;
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 ApprovalResultService extends BaseBean {

    private static final org.slf4j.Logger logger_ff0d1f05 = LoggerFactory.getLogger(ApprovalResultService.class);
    @Autowired
    private ConfigProp configProp;
    public String[] returnResult(OAPRResultItemIn in) {
        String[] str = new String[2];
        try {
//            String url = Util.null2String(I18nContextUtilcus.getBean(Environment.class).getProperty("htk3oasync.approval_url")).trim();
            String url = configProp.getApproval_url();
            SI_HTOAPurreqAPPROSync_OUTServiceStub stub = new SI_HTOAPurreqAPPROSync_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());

            stub._getServiceClient().getOptions().setProperty(org.apache.axis2.kernel.http.HTTPConstants.AUTHENTICATE,auth);
            SI_HTOAPurreqAPPROSync_OUTServiceStub.Oa2K3PurchaseRequestResult request = new SI_HTOAPurreqAPPROSync_OUTServiceStub.Oa2K3PurchaseRequestResult();
            SI_HTOAPurreqAPPROSync_OUTServiceStub.OAPRResultIn resultIn = new SI_HTOAPurreqAPPROSync_OUTServiceStub.OAPRResultIn();
            SI_HTOAPurreqAPPROSync_OUTServiceStub.ArrayOfOAPRResultItemIn array = new SI_HTOAPurreqAPPROSync_OUTServiceStub.ArrayOfOAPRResultItemIn();
            SI_HTOAPurreqAPPROSync_OUTServiceStub.OAPRResultItemIn[] item = new SI_HTOAPurreqAPPROSync_OUTServiceStub.OAPRResultItemIn[1];
            item[0] = in;
            array.setOAPRResultItemIn(item);
            resultIn.setSENDID("");
            resultIn.setITFID("HT01KD005");
            resultIn.setItem(array);
            resultIn.setFcompanyCode("G110");
            request.setOAResult(resultIn);
            SI_HTOAPurreqAPPROSync_OUTServiceStub.Oa2K3PurchaseRequestResultResponse response = stub.sI_HTOAPurreqAPPROSync_OUT(request);
            SI_HTOAPurreqAPPROSync_OUTServiceStub.OAPRResultOut result = response.getOa2K3PurchaseRequestResultResult();
            str[0] = result.getSTATUS();
            str[1] = result.getMESSAGE();
            logger_ff0d1f05.error(String.valueOf("调用k3接口返回值：" + str[0] + str[1]));
        } catch (Exception e) {
            str[0] = "0";
            str[1] = e.toString();
            logger_ff0d1f05.error(String.valueOf("调用K3返回审批结果接口出错：" + e.toString()));
        }
        return str;
    }
}
