package com.weaver.seconddev.interfaces.workflow.action;

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;

/**
 * 投资类合同新增接口返回
 */
@Component
public class EasTzlhtApplyResult extends BaseBean {

    private static final Logger logger_4b97b171 = LoggerFactory.getLogger(EasTzlhtApplyResult.class);
    @Autowired
    private ConfigProp configProp;
    public String getApproveResult(JSONObject returnJson) {

        logger_4b97b171.error("EasTzlhtApplyResult getApproveResult returnJson== " +returnJson);
        HttpPost post = null;
        String result = "E";
        try {
            HttpClient client = new DefaultHttpClient();
//            String url = Util.null2String(I18nContextUtilcus.getBean(Environment.class).getProperty("hteasoasync.getTzlhtApplyResultUrl")).trim();
            String url = configProp.getGetTzlhtApplyResultUrl();
            logger_4b97b171.error(String.valueOf("EasTzlhtApplyResult---url=" + url));
            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(getPropValue("htportaloaUrl", "url_password")).trim());
            // writeLog("EasTzlhtApplyResult---appkey="+Util.null2String(getPropValue("htportaloaUrl","api_appkey")).trim());
            // api平台验证
//            post.setHeader("appKey", Util.null2String(I18nContextUtilcus.getBean(Environment.class).getProperty("htportaloaUrl.api_appkey")).trim());
            post.setHeader("appKey", configProp.getApi_appkey());
            StringEntity entity = new StringEntity(returnJson.toString(), "UTF-8");
            post.setEntity(entity);
            HttpResponse response = client.execute(post);
            int rspCode = response.getStatusLine().getStatusCode();
            if (rspCode == 200) {
                result = EntityUtils.toString(response.getEntity(), "UTF-8");
            }
            logger_4b97b171.error(String.valueOf("EasTzlhtApplyResult---rspCode=" + rspCode));
        } catch (Exception e) {
            logger_4b97b171.error(String.valueOf("调用报账系统接口出错" + e.toString()));

        } finally {
            if (post != null) {
                post.releaseConnection();
            }
        }
        logger_4b97b171.error("EasTzlhtApplyResult getApproveResult result== " +result);
        return result;
    }
}
