package com.weaver.seconddev.interfaces.easoa;

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 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.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * oa->eas 报账系统，应收折现发票申请返回接口
 */
@Component
public class EAS_YszxfpApplyResult extends BaseBean {

    private static final org.slf4j.Logger logger_683a4c66 = LoggerFactory.getLogger(EAS_YszxfpApplyResult.class);
    @Autowired
    private ConfigProp configProp;
    public String getApproveResult(JSONObject returnJson, String type) {
        logger_683a4c66.error("EAS_YszxfpApplyResult start  :  returnJson = " + returnJson + "  type = "+ type);
        HttpPost post = null;
        String result = "E";
        try {
            HttpClient client = new DefaultHttpClient();
//            String url = Util.null2String(getPropValue("hteasoasync", type)).trim();
            String url = "";
            if(type.equals("EasYszxfpApplyResult")){
                url = configProp.getEasYszxfpApplyResult();
            }else if(type.equals("SCFAndEASApplyUser")){
                url = configProp.getSCFAndEASApplyUser();
            }
            logger_683a4c66.error("url==" + url);

            post = new HttpPost(url);
            post.setHeader(HTTP.CONTENT_TYPE, "application/json; charset=UTF-8");
            post.setHeader("Accept", "application/json; charset=UTF-8");
            logger_683a4c66.error("Authorization--getUrl_password--"+configProp.getUrl_password());
//            post.setHeader("Authorization", Util.null2String(getPropValue("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_683a4c66.error(String.valueOf("EAS_YszxfpApplyResult:" + rspCode));
            if (rspCode == 200) {
                result = EntityUtils.toString(response.getEntity(), "UTF-8");
            }
        } catch (Exception e) {
            logger_683a4c66.error("调用报账系统接口出错" , e);
        } finally {
            if (post != null) {
                post.releaseConnection();
            }
        }
        return result;
    }
}


