/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  cn.weili.util.http.client.HttpClient
 *  cn.weili.util.http.client.SimpleHttpClient
 *  cn.weili.util.http.param.RequestParams
 *  cn.weili.util.http.result.ResponseResult
 *  org.apache.commons.lang.StringUtils
 *  org.springframework.stereotype.Repository
 */
package com.hst.taxService.dao.imp;

import cn.weili.util.http.client.HttpClient;
import cn.weili.util.http.client.SimpleHttpClient;
import cn.weili.util.http.param.RequestParams;
import cn.weili.util.http.result.ResponseResult;
import com.hst.common.domain.TaxCommonReturnDomain;
import com.hst.framework.constants.WebConstants;
import com.hst.framework.dao.BaseDao;
import com.hst.taxService.domain.FpcyAppDomain;
import com.hst.taxService.domain.FpcyDzfpReturnDomain;
import com.hst.taxService.domain.FpcyFwlfpReturnDomain;
import com.hst.taxService.domain.FpcyKyfpReturnDomain;
import com.hst.taxService.domain.FpcyWlfpReturnDomain;
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;
import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Repository;

@Repository
public class TaxFpcyAppDaoImp
implements BaseDao {
    private final String fpcx_url = "hst.SSSX_FPCX_URL";
    private final String fpcx_cookie_url = "hst.SSSX_FPCX_COOKIEURL";
    private String errorMsg = "\u4f60\u5f55\u5165\u7684\u53d1\u7968\u5185\u5bb9\uff08";
    private static final Map<String, String> statusMap = new HashMap<String, String>();

    static {
        statusMap.put("fplx", "\u53d1\u7968\u79cd\u7c7b");
        statusMap.put("rq", "\u65e5\u671f");
        statusMap.put("fpdm", "\u53d1\u7968\u4ee3\u7801");
        statusMap.put("fphm", "\u53d1\u7968\u53f7\u7801");
        statusMap.put("fpje", "\u53d1\u7968\u91d1\u989d");
        statusMap.put("kprmc", "\u5f00\u7968\u4eba\u540d\u79f0");
        statusMap.put("ghfmc", "\u8d2d\u8d27\u65b9\u540d\u79f0");
        statusMap.put("ghfsbh", "\u8d2d\u8d27\u65b9\u7a0e\u53f7");
        statusMap.put("fpzt", "\u53d1\u7968\u72b6\u6001");
        statusMap.put("hwmc", "\u8d27\u7269\u540d\u79f0");
        statusMap.put("lgfpfmc", "\u9886\u8d2d\u53d1\u7968\u65b9\u540d\u79f0");
        statusMap.put("lgfpfsbh", "\u9886\u8d2d\u53d1\u7968\u65b9\u7a0e\u53f7");
    }

    public TaxCommonReturnDomain queryFpcy(FpcyAppDomain domain) throws Exception {
        TaxCommonReturnDomain returnDomain;
        block19: {
            if (domain == null) {
                return null;
            }
            Map<String, String> mapParam = this.getMap(domain);
            Map<String, String> invoiceMsgMap = this.getInvoiceMsgMap();
            returnDomain = new TaxCommonReturnDomain();
            StringBuilder invoiceMsg = new StringBuilder();
            invoiceMsg.append(this.errorMsg);
            HttpClient hc = null;
            ResponseResult result = null;
            try {
                try {
                    hc = SimpleHttpClient.newHttpClient();
                    result = hc.execute(RequestParams.custom().setUrl(String.valueOf(mapParam.get("cookieUrl"))).setCharset(Charset.forName("GBK")).build());
                    result = hc.execute(RequestParams.custom().setPostMethod().putAllParam(mapParam).setUrl(String.valueOf(mapParam.get("url"))).setCharset(Charset.forName("GBK")).build());
                    if (result.isSuccess()) {
                        Map<String, String> resMap = this.getDO(result.getValue(), domain.getBid());
                        if ("wx.FpcyGetWlfp".equals(domain.getBid())) {
                            returnDomain = (FpcyWlfpReturnDomain)TaxFpcyAppDaoImp.convertMap(FpcyWlfpReturnDomain.class, resMap);
                        } else if ("wx.FpcyGetFwlfp".equals(domain.getBid())) {
                            returnDomain = (FpcyFwlfpReturnDomain)TaxFpcyAppDaoImp.convertMap(FpcyFwlfpReturnDomain.class, resMap);
                        } else if ("wx.FpcyGetDzfp".equals(domain.getBid())) {
                            returnDomain = (FpcyDzfpReturnDomain)TaxFpcyAppDaoImp.convertMap(FpcyDzfpReturnDomain.class, resMap);
                        } else if ("wx.FpcyGetKyfp".equals(domain.getBid())) {
                            returnDomain = (FpcyKyfpReturnDomain)TaxFpcyAppDaoImp.convertMap(FpcyKyfpReturnDomain.class, resMap);
                        }
                        if (StringUtils.isBlank((String)resMap.get("fpdm"))) {
                            for (Map.Entry<String, String> entry : mapParam.entrySet()) {
                                if ("ywlx".equals(entry.getKey()) || "ywlxbf".equals(entry.getKey()) || "anbz".equals(entry.getKey()) || "cxbz".equals(entry.getKey()) || "url".equals(entry.getKey()) || "cookieUrl".equals(entry.getKey())) continue;
                                invoiceMsg.append(String.valueOf(invoiceMsgMap.get(entry.getKey())) + ":'" + entry.getValue() + "',");
                            }
                            invoiceMsg.replace(invoiceMsg.length() - 1, invoiceMsg.length(), "");
                            invoiceMsg.append("\uff09\u65e0\u6cd5\u67e5\u5230\u76f8\u5e94\u7684\u4fe1\u606f\uff0c\u8bf7\u786e\u8ba4\u5f55\u5165\u4fe1\u606f\u662f\u5426\u51c6\u786e\uff01");
                            returnDomain.setCode("01");
                            returnDomain.setMess(invoiceMsg.toString());
                        } else {
                            returnDomain.setCode("00");
                        }
                        break block19;
                    }
                    returnDomain.setCode("01");
                    returnDomain.setMess("\u8bf7\u6c42\u5931\u8d25,\u9519\u8bef\u4ee3\u7801:" + result.getResultCode());
                }
                catch (Exception e) {
                    e.printStackTrace();
                    if (hc != null) {
                        hc.close();
                    }
                }
            }
            finally {
                if (hc != null) {
                    hc.close();
                }
            }
        }
        return returnDomain;
    }

    private Map<String, String> getMap(FpcyAppDomain domain) throws Exception {
        HashMap<String, String> mapParam = new HashMap<String, String>();
        String ywId = domain.getBid();
        String url = WebConstants.HST_PROP_MAP.get("hst.SSSX_FPCX_URL");
        String cookieUrl = WebConstants.HST_PROP_MAP.get("hst.SSSX_FPCX_COOKIEURL");
        mapParam.put("url", url);
        mapParam.put("cookieUrl", cookieUrl);
        mapParam.put("anbz", "wqr");
        mapParam.put("cxbz", "lscx");
        if ("wx.FpcyGetWlfp".equals(ywId)) {
            mapParam.put("ywlx", "FPCX_WLFP");
            mapParam.put("ywlxbf", "FPCX_WLFP");
            mapParam.put("zjlsh", domain.getWlfph());
            mapParam.put("rq_wp", domain.getKprq());
            mapParam.put("je_wp", domain.getKpje());
        } else if ("wx.FpcyGetFwlfp".equals(ywId)) {
            mapParam.put("ywlx", "FPCX_JMFPP");
            mapParam.put("ywlxbf", "FPCX_JMFP");
            mapParam.put("fpdm", domain.getFpdm());
            mapParam.put("fphm", domain.getFphm());
            mapParam.put("kjfsbh_qp", domain.getKpfsbh());
            mapParam.put("rq_qp", domain.getKprq());
            mapParam.put("je_qp", domain.getKpje());
        } else if ("wx.FpcyGetDzfp".equals(ywId)) {
            mapParam.put("ywlx", "FPCX_DZFP");
            mapParam.put("ywlxbf", "FPCX_DZFP");
            mapParam.put("zjlsh_dz", domain.getDzfph());
            mapParam.put("rq_dz", domain.getKprq());
            mapParam.put("je_dz", domain.getKpje());
        } else if ("wx.FpcyGetKyfp".equals(ywId)) {
            mapParam.put("ywlx", "FPCX_CZC");
            mapParam.put("ywlxbf", "FPCX_CZC");
            mapParam.put("fpdm_ky", domain.getFpdm());
            mapParam.put("fphm_ky", domain.getFphm());
            mapParam.put("kprq_ky", domain.getKprq());
        }
        return mapParam;
    }

    private Map<String, String> getDO(String value, String ywId) {
        HashMap<String, String> map = new HashMap<String, String>();
        String valueNow = value.replaceAll(" ", "").replaceAll("\t", "").replaceAll("\n", "").replaceAll("\r", "");
        String regularOne = "\uff1a</td><tdwidth=\"40%\"class=\"black_12\"align=\"left\">";
        String regularTwo = "\uff1a</td><tdclass=\"black_12\"align=\"left\">";
        String regularThree = "\uff1a</td><tdalign=\"left\"class=\"black_12\">";
        for (Map.Entry<String, String> entry : statusMap.entrySet()) {
            String ssTwo;
            String ss = StringUtils.substringBetween((String)valueNow, (String)(String.valueOf(entry.getValue()) + regularOne), (String)"</td>");
            if (ss != null) {
                map.put(entry.getKey(), ss);
                continue;
            }
            String ssOne = StringUtils.substringBetween((String)valueNow, (String)(String.valueOf(entry.getValue()) + regularTwo), (String)"</td>");
            if (ssOne != null) {
                map.put(entry.getKey(), ssOne);
                continue;
            }
            if (entry.getKey().equals("ghfsbh") || entry.getKey().equals("hwmc") || entry.getKey().equals("lgfpfsbh")) {
                ssTwo = StringUtils.substringBetween((String)valueNow, (String)(String.valueOf(entry.getValue()) + regularThree), (String)"</td>");
                map.put(entry.getKey(), ssTwo);
                continue;
            }
            ssTwo = StringUtils.substringBetween((String)valueNow, (String)(String.valueOf(entry.getValue()) + regularThree), (String)"<inputname=");
            if (ssTwo == null) continue;
            map.put(entry.getKey(), ssTwo);
        }
        return map;
    }

    public static Object convertMap(Class type, Map map) {
        Object obj = null;
        try {
            BeanInfo beanInfo = Introspector.getBeanInfo(type);
            obj = type.newInstance();
            PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
            int i = 0;
            while (i < propertyDescriptors.length) {
                PropertyDescriptor descriptor = propertyDescriptors[i];
                String propertyName = descriptor.getName();
                if (map.containsKey(propertyName)) {
                    Object value = map.get(propertyName);
                    Object[] args = new Object[]{value};
                    descriptor.getWriteMethod().invoke(obj, args);
                }
                ++i;
            }
        }
        catch (IntrospectionException introspectionException) {
            _logger.error((Object)"convertMapError: javaBean to Map false !  ");
        }
        catch (InstantiationException instantiationException) {
            _logger.error((Object)"convertMapError: javaBean to Map false! ");
        }
        catch (IllegalAccessException illegalAccessException) {
            _logger.error((Object)"convertMapError: javaBean to Map false!");
        }
        catch (IllegalArgumentException illegalArgumentException) {
            _logger.error((Object)"convertMapError: javaBean to Map false 1");
        }
        catch (InvocationTargetException invocationTargetException) {
            _logger.error((Object)"convertMapError: javaBean to Map false ! ");
        }
        return obj;
    }

    public Map<String, String> getInvoiceMsgMap() {
        HashMap<String, String> invoiceRtMap = new HashMap<String, String>();
        invoiceRtMap.put("zjlsh_dz", "\u7535\u5b50\u53d1\u7968\u53f7");
        invoiceRtMap.put("rq_dz", "\u5f00\u7968\u65e5\u671f");
        invoiceRtMap.put("je_dz", "\u4ef7\u7a0e\u5408\u8ba1\u91d1\u989d");
        invoiceRtMap.put("zjlsh", "\u7f51\u7edc\u53d1\u7968\u53f7");
        invoiceRtMap.put("rq_wp", "\u5f00\u7968\u65e5\u671f");
        invoiceRtMap.put("je_wp", "\u4ef7\u7a0e\u5408\u8ba1\u91d1\u989d");
        invoiceRtMap.put("fpdm", "\u53d1\u7968\u4ee3\u7801");
        invoiceRtMap.put("fphm", "\u53d1\u7968\u53f7\u7801");
        invoiceRtMap.put("kjfsbh_qp", "\u5f00\u7968\u65b9\u8bc6\u522b\u53f7");
        invoiceRtMap.put("rq_qp", "\u5f00\u7968\u65e5\u671f");
        invoiceRtMap.put("je_qp", "\u4ef7\u7a0e\u5408\u8ba1\u91d1\u989d");
        invoiceRtMap.put("fpdm_ky", "\u53d1\u7968\u4ee3\u7801");
        invoiceRtMap.put("fphm_ky", "\u53d1\u7968\u53f7\u7801");
        invoiceRtMap.put("kprq_ky", "\u5f00\u7968\u65e5\u671f");
        invoiceRtMap.put("uid", "\u7528\u6237ID");
        return invoiceRtMap;
    }
}
