package com.weaver.seconddev.interfaces.iuroa;

import com.alibaba.fastjson.JSONObject;
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;

public class SyncDataService extends BaseBean {

    private static final org.slf4j.Logger logger_4014b7c4 = LoggerFactory.getLogger(SyncDataService.class);

    public String[] call(JSONObject data, String link) {
        HttpPost post = null;
        String[] str = new String[2];
        try {
            HttpClient client = new DefaultHttpClient();
//            String url = Util.null2String(getPropValue("htiuroasync", link)).trim();
            String url = "";
            post = new HttpPost(url);
            post.setHeader(HTTP.CONTENT_TYPE, "application/json; charset=UTF-8");
            StringEntity entity = new StringEntity(data.toString(), "UTF-8");
            post.setEntity(entity);
            HttpResponse response = client.execute(post);
            int rspCode = response.getStatusLine().getStatusCode();
            logger_4014b7c4.error(String.valueOf("调用产学研平台接口返回状态码：" + rspCode));
            if (rspCode == 200) {
                String result = EntityUtils.toString(response.getEntity(), "UTF-8");
                JSONObject obj = JSONObject.parseObject(result);
                str[0] = "200".equals(obj.getString("code")) ? "S" : "E";
                str[1] = obj.getString("message");
            } else {
                str[0] = "E";
                str[1] = "同步失败状态码：" + rspCode;
            }
        } catch (Exception e) {
            str[0] = "E";
            str[1] = e.toString();
            logger_4014b7c4.error(String.valueOf("调用产学研平台接口出错" + e.toString()));
        } finally {
            if (post != null) {
                post.releaseConnection();
            }
        }
        return str;
    }
}
