/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  net.sf.json.JSONObject
 *  org.apache.commons.logging.Log
 *  org.apache.commons.logging.LogFactory
 *  org.apache.http.HttpEntity
 *  org.apache.http.client.config.RequestConfig
 *  org.apache.http.client.entity.UrlEncodedFormEntity
 *  org.apache.http.client.methods.CloseableHttpResponse
 *  org.apache.http.client.methods.HttpPost
 *  org.apache.http.client.methods.HttpUriRequest
 *  org.apache.http.impl.client.CloseableHttpClient
 *  org.apache.http.impl.client.HttpClients
 *  org.apache.http.message.BasicNameValuePair
 *  org.apache.http.util.EntityUtils
 *  org.apache.struts2.convention.annotation.Action
 *  org.apache.struts2.convention.annotation.Result
 *  org.springframework.context.annotation.Scope
 *  org.springframework.stereotype.Controller
 */
package com.hst.taxService.action;

import com.hst.common.action.ExtendAction;
import com.hst.common.domain.TaxCommonAppServiceDomain;
import com.hst.common.domain.TaxCommonReturnDomain;
import com.hst.common.util.HstJsonUtil;
import com.hst.common.util.HstRandomUtil;
import com.hst.framework.constants.WebConstants;
import com.hst.framework.util.HstToolsUtil;
import com.hst.taxService.action.TaxWxCommonAppAction;
import java.io.IOException;
import java.util.ArrayList;
import net.sf.json.JSONObject;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpEntity;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

@Controller
@Scope(value="prototype")
@Action(value="/service/taxForward", results={@Result(name="doService", type="json")})
public class TaxForwardAction
extends ExtendAction {
    private static final long serialVersionUID = 1L;
    public static Log _logger = LogFactory.getLog(TaxWxCommonAppAction.class);
    private TaxCommonAppServiceDomain domain;

    public String doService() throws Exception {
        block24: {
            String url = "";
            CloseableHttpClient httpClient = HttpClients.createDefault();
            HttpPost httpPost = null;
            CloseableHttpResponse response = null;
            String strResult = "";
            TaxCommonReturnDomain returnDomian = null;
            String random = HstRandomUtil.generateRandomString();
            try {
                String ywId = this.getDomain().getYwId();
                String parmJson = this.getDomain().getParmJson();
                _logger.debug((Object)("random[" + random + "]\u4e1a\u52a1id[" + ywId + "]\u8bf7\u6c42\u6570\u636e[" + parmJson + "]"));
                if (HstToolsUtil.isNullOrEmpty(ywId)) {
                    returnDomian = new TaxCommonReturnDomain();
                    returnDomian.setCode("01");
                    returnDomian.setMess("\u4e1a\u52a1id\u4e3a\u7a7a\uff0c\u8bf7\u68c0\u67e5\uff01");
                    this.domain.setRetJson(HstJsonUtil.beanToJson(returnDomian));
                    return "doService";
                }
                url = WebConstants.TAX_FORWARD_MAP.get(ywId);
                if (HstToolsUtil.isNullOrEmpty(url)) {
                    returnDomian = new TaxCommonReturnDomain();
                    returnDomian.setCode("01");
                    returnDomian.setMess("\u4e1a\u52a1id\u672a\u6307\u5b9a\u8f6c\u53d1\u5730\u5740\uff0c\u8bf7\u8054\u7cfb\u6280\u672f\u4eba\u5458\u3002");
                    this.domain.setRetJson(HstJsonUtil.beanToJson(returnDomian));
                    return "doService";
                }
                try {
                    httpPost = new HttpPost(url);
                    httpPost.addHeader("Content-type", "application/x-www-form-urlencoded;charset=gbk");
                    RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(60000).setConnectTimeout(60000).build();
                    httpPost.setConfig(requestConfig);
                    ArrayList<BasicNameValuePair> par = new ArrayList<BasicNameValuePair>();
                    par.add(new BasicNameValuePair("domain.ywId", this.domain.getYwId()));
                    par.add(new BasicNameValuePair("domain.parmJson", this.domain.getParmJson()));
                    httpPost.setEntity((HttpEntity)new UrlEncodedFormEntity(par, "gbk"));
                    response = httpClient.execute((HttpUriRequest)httpPost);
                    if (response.getStatusLine().getStatusCode() == 200) {
                        strResult = EntityUtils.toString((HttpEntity)response.getEntity());
                        if (!HstToolsUtil.isNullOrEmpty(strResult)) {
                            JSONObject jsonObject = JSONObject.fromObject((Object)strResult);
                            JSONObject retJson = JSONObject.fromObject((Object)jsonObject.getJSONObject("domain"));
                            String resultJson = retJson.getString("retJson");
                            this.domain.setRetJson(resultJson);
                        }
                        break block24;
                    }
                    returnDomian = new TaxCommonReturnDomain();
                    returnDomian.setCode("01");
                    String err = String.valueOf(response.getStatusLine().getStatusCode());
                    strResult = String.valueOf(strResult) + "\u8bf7\u6c42\u5931\u8d25\uff0c\u9519\u8bef\u4ee3\u7801\uff1a" + err;
                    returnDomian.setMess(strResult);
                    this.domain.setRetJson(HstJsonUtil.beanToJson(returnDomian));
                }
                catch (Exception e) {
                    _logger.error((Object)("random[" + random + "]\u5f02\u5e38[" + e + "]"));
                    returnDomian = new TaxCommonReturnDomain();
                    returnDomian.setCode("01");
                    strResult = e.toString().length() > 1000 ? e.toString().substring(0, 999) : e.toString();
                    returnDomian.setMess(strResult);
                    this.domain.setRetJson(HstJsonUtil.beanToJson(returnDomian));
                }
            }
            finally {
                _logger.debug((Object)("random[" + random + "]\u8fd4\u56de\u6570\u636e[" + this.domain.getRetJson() + "]"));
                try {
                    if (response != null) {
                        response.close();
                    }
                    if (httpPost != null) {
                        httpPost.releaseConnection();
                    }
                    if (httpClient != null) {
                        httpClient.close();
                    }
                }
                catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return "doService";
    }

    @Override
    public TaxCommonAppServiceDomain getDomain() {
        if (this.domain == null) {
            this.domain = new TaxCommonAppServiceDomain();
        }
        return this.domain;
    }

    public void setDomain(TaxCommonAppServiceDomain domain) {
        this.domain = domain;
    }
}
