package com.weaver.seconddev.interfaces.scfoa;

import com.alibaba.fastjson.JSONObject;
import com.weaver.seconddev.interfaces.prop.ConfigProp;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import com.weaver.common.i18n.tool.util.I18nContextUtil;
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;

/**
 * oa审批结果返回 oa->scf
 */
@Component
public class GetApproveResult extends BaseBean {

    private static final org.slf4j.Logger logger_8692c990 = LoggerFactory.getLogger(GetApproveResult.class);
    @Autowired
    private ConfigProp configProp;
    public String getApproveResult(JSONObject returnJson) {
        HttpPost post = null;
        String result = "E";
        try {
            HttpClient client = new DefaultHttpClient();
//            String url = Util.null2String(I18nContextUtilcus.getBean(Environment.class).getProperty("htscfoasync.approvalResult")).trim();
            String url = configProp.getApprovalResult();
            post = new HttpPost(url);
            post.setHeader(HTTP.CONTENT_TYPE, "application/json; charset=UTF-8");
            post.setHeader("Accept", "application/json; charset=UTF-8");
//            post.setHeader("Authorization", Util.null2String(I18nContextUtilcus.getBean(Environment.class).getProperty("htportaloaUrl.url_password")).trim());
            post.setHeader("Authorization", configProp.getUrl_password());
            StringEntity entity = new StringEntity(returnJson.toString(), "UTF-8");
            post.setEntity(entity);
            HttpResponse response = client.execute(post);
            int rspCode = response.getStatusLine().getStatusCode();
            logger_8692c990.error(String.valueOf("getApproveResult:" + rspCode));
            if (rspCode == 200) {
                result = EntityUtils.toString(response.getEntity(), "UTF-8");
            }
        } catch (Exception e) {
            logger_8692c990.error(String.valueOf("调用供应链金融系统返回审批结果接口出错" + e.toString()));
        } finally {
            if (post != null) {
                post.releaseConnection();
            }
        }
        return result;
    }
}
