/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.google.gson.Gson
 *  net.sf.json.JSONObject
 *  org.apache.commons.beanutils.BeanUtils
 *  org.apache.http.HttpEntity
 *  org.apache.http.client.ClientProtocolException
 *  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.springframework.stereotype.Service
 */
package com.hst.taxService.service.imp;

import com.google.gson.Gson;
import com.hst.common.domain.BaseAppServiceDomain;
import com.hst.common.domain.TaxCommonAppServiceDomain;
import com.hst.common.domain.TaxCommonReturnDomain;
import com.hst.common.service.imp.BaseBusinessServiceImp;
import com.hst.common.util.HstJsonUtil;
import com.hst.framework.constants.WebConstants;
import com.hst.framework.dao.BaseDao;
import com.hst.taxService.dao.imp.TaxQttySmzzAppDaoImp;
import com.hst.taxService.dao.imp.TaxWxEmsxxAppDaoImp;
import com.hst.taxService.domain.jhxtDomain.JhxtBsyNsrsbhAppDomain;
import com.hst.taxService.domain.jhxtDomain.JhxtBsyNsrsbhDomain;
import com.hst.taxService.domain.jhxtDomain.JhxtBsyNsrsbhReturnDomain;
import com.hst.taxService.domain.qtty.EmsWlxx;
import com.hst.taxService.domain.qtty.QttyEmsYdgxAppDomain;
import com.hst.taxService.domain.qtty.QttyEmsYdgxReturnDomain;
import com.hst.taxService.domain.qtty.QttyEmsYdxxcxAppDomain;
import com.hst.taxService.domain.qtty.QttyEmscxBackDomain;
import com.hst.taxService.domain.qtty.QttySmzzBsyLoginLogAppDomain;
import com.hst.taxService.domain.qtty.QttySmzzBsyLogoutLogAppDomain;
import com.hst.taxService.domain.qtty.QttySmzzBsyNsrxxAppDomain;
import com.hst.taxService.domain.qtty.QttySmzzSwjgJbxxAppDomain;
import com.hst.taxService.domain.qtty.QttySmzzSwjgYyxtAppDomain;
import com.hst.taxService.domain.qtty.QttyYjxxDomain;
import com.hst.taxService.service.TaxWxQttyCommonAppService;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import net.sf.json.JSONObject;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.http.HttpEntity;
import org.apache.http.client.ClientProtocolException;
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.springframework.stereotype.Service;

@Service
public class TaxWxQttyAppCommonServiceImp
extends BaseBusinessServiceImp
implements TaxWxQttyCommonAppService {
    private BaseDao dao;

    @Override
    public TaxCommonReturnDomain doEmsYdxxcx(BaseAppServiceDomain appDomain) throws Exception {
        QttyEmsYdxxcxAppDomain domain = (QttyEmsYdxxcxAppDomain)appDomain;
        return ((TaxWxEmsxxAppDaoImp)this.getDao("taxWxEmsxxAppDaoImp")).doEmsYdxxCx(domain);
    }

    @Override
    public TaxCommonReturnDomain doEmsYdgx(BaseAppServiceDomain appDomain) throws Exception {
        QttyEmsYdgxAppDomain domain = (QttyEmsYdgxAppDomain)appDomain;
        QttyEmsYdgxReturnDomain returnDomain = new QttyEmsYdgxReturnDomain();
        QttyEmsYdgxReturnDomain gxDomain = new QttyEmsYdgxReturnDomain();
        gxDomain = (QttyEmsYdgxReturnDomain)((TaxWxEmsxxAppDaoImp)this.getDao("taxWxEmsxxAppDaoImp")).doEmsYdgx(domain);
        if ("00".equals(gxDomain.getCode())) {
            QttyEmscxBackDomain backDomain = this.sendMess(domain.getKddbh());
            if ("0".equals(backDomain.getBackCode())) {
                QttyYjxxDomain yjxxDomain = new QttyYjxxDomain();
                yjxxDomain.setKddbh(domain.getKddbh());
                if (!backDomain.getBean().getData().isEmpty()) {
                    ((TaxWxEmsxxAppDaoImp)this.getDao("taxWxEmsxxAppDaoImp")).doSaveWlztMx(backDomain.getBean());
                    List<EmsWlxx> wlxxList = backDomain.getBean().getData();
                    String lastRemark = wlxxList.get(wlxxList.size() - 1).getRemark();
                    if (lastRemark.indexOf("\u9000\u56de") > 0) {
                        yjxxDomain.setWlzt("3");
                        yjxxDomain.setQsthsj(wlxxList.get(wlxxList.size() - 1).getAcceptTime());
                    } else if (lastRemark.indexOf("\u59a5\u6295") > 0 || lastRemark.indexOf("\u7b7e\u6536") > 0) {
                        yjxxDomain.setWlzt("2");
                        yjxxDomain.setQsthsj(wlxxList.get(wlxxList.size() - 1).getAcceptTime());
                    } else {
                        yjxxDomain.setWlzt("1");
                        if (wlxxList.size() == 1) {
                            yjxxDomain.setJjrq(wlxxList.get(wlxxList.size() - 1).getAcceptTime());
                        }
                    }
                    returnDomain = (QttyEmsYdgxReturnDomain)((TaxWxEmsxxAppDaoImp)this.getDao("taxWxEmsxxAppDaoImp")).doEmsYdgxHxcl(yjxxDomain);
                } else {
                    yjxxDomain.setWlzt("0");
                    returnDomain = (QttyEmsYdgxReturnDomain)((TaxWxEmsxxAppDaoImp)this.getDao("taxWxEmsxxAppDaoImp")).doEmsYdgxHxcl(yjxxDomain);
                }
            } else {
                returnDomain.setCode("01");
                returnDomain.setMess("\u8c03\u7528EMS\u67e5\u8be2\u63a5\u53e3\u5931\u8d25");
            }
        } else if ("99".equals(gxDomain.getCode())) {
            returnDomain.setCode("99");
            returnDomain.setMess("\u8be5\u5feb\u9012\u5355\u7684\u72b6\u6001\u662f\u5df2\u7b7e\u6536");
        } else {
            returnDomain.setCode(gxDomain.getCode());
            returnDomain.setMess(gxDomain.getMess());
        }
        return returnDomain;
    }

    public QttyEmscxBackDomain sendMess(String kddbh) {
        String url = String.valueOf(WebConstants.WX_SERVICE_URL) + "/kddcxAjaxAction!queryKddList.htm";
        HttpPost httppost = new HttpPost(url);
        String strResult = "";
        CloseableHttpClient httpClient = HttpClients.createDefault();
        QttyEmscxBackDomain dom = new QttyEmscxBackDomain();
        Gson gson = new Gson();
        try {
            httppost.addHeader("Content-type", "application/x-www-form-urlencoded;charset=gbk");
            ArrayList<BasicNameValuePair> par = new ArrayList<BasicNameValuePair>();
            par.add(new BasicNameValuePair("kddbh", kddbh));
            httppost.setEntity((HttpEntity)new UrlEncodedFormEntity(par));
            CloseableHttpResponse response = httpClient.execute((HttpUriRequest)httppost);
            if (response.getStatusLine().getStatusCode() != 200) {
                String err = String.valueOf(response.getStatusLine().getStatusCode());
                strResult = String.valueOf(strResult) + "\u8bf7\u6c42\u5931\u8d25\uff0c\u9519\u8bef\u4ee3\u7801\uff1a" + err;
                dom.setBackCode("-1");
                dom.setErrorMess(strResult);
                throw new RuntimeException(strResult);
            }
            strResult = EntityUtils.toString((HttpEntity)response.getEntity());
            dom = (QttyEmscxBackDomain)gson.fromJson(strResult, QttyEmscxBackDomain.class);
        }
        catch (ClientProtocolException e) {
            dom.setBackCode("-1");
            dom.setErrorMess(e.toString());
            _logger.error((Object)e.toString());
        }
        catch (IOException e) {
            dom.setBackCode("-1");
            dom.setErrorMess(e.toString());
            _logger.error((Object)e.toString());
        }
        return dom;
    }

    @Override
    public TaxCommonReturnDomain doSmzzSwjgJbxx(BaseAppServiceDomain appDomain) throws Exception {
        QttySmzzSwjgJbxxAppDomain domain = (QttySmzzSwjgJbxxAppDomain)appDomain;
        return ((TaxQttySmzzAppDaoImp)this.getDao("taxQttySmzzAppDaoImp")).doSmzzSwjgJbxx(domain);
    }

    @Override
    public TaxCommonReturnDomain doSmzzSwjgYyxt(BaseAppServiceDomain appDomain) throws Exception {
        QttySmzzSwjgYyxtAppDomain domain = (QttySmzzSwjgYyxtAppDomain)appDomain;
        return ((TaxQttySmzzAppDaoImp)this.getDao("taxQttySmzzAppDaoImp")).doSmzzSwjgYyxt(domain);
    }

    @Override
    public TaxCommonReturnDomain doSmzzBsyNsrxx(BaseAppServiceDomain baseAppDomain, TaxCommonAppServiceDomain domain) throws Exception {
        QttySmzzBsyNsrxxAppDomain appDomain = (QttySmzzBsyNsrxxAppDomain)baseAppDomain;
        String bsdtDjxh = ((TaxQttySmzzAppDaoImp)this.getDao("taxQttySmzzAppDaoImp")).doGetBsdtDjxh(appDomain.getSwjgDm());
        HashSet<String> nsrsbhs = new HashSet<String>();
        if (!"01".equals(bsdtDjxh)) {
            String sendResStr;
            JSONObject jsonObject;
            JSONObject retJson;
            String resultJson;
            Gson gson;
            JhxtBsyNsrsbhReturnDomain jhxtReturnDomain;
            JhxtBsyNsrsbhAppDomain jhxtAppDomain = new JhxtBsyNsrsbhAppDomain();
            BeanUtils.copyProperties((Object)jhxtAppDomain, (Object)appDomain);
            jhxtAppDomain.setBsdtdjXh(bsdtDjxh);
            jhxtAppDomain.setSfzhm(appDomain.getSfzhm());
            Map<String, String> sendResMap = this.sendMess(jhxtAppDomain, "jhxtGetBsyNsrsbh");
            if ("00".equals(sendResMap.get("code")) && "00".equals((jhxtReturnDomain = (JhxtBsyNsrsbhReturnDomain)(gson = new Gson()).fromJson(resultJson = (retJson = JSONObject.fromObject((Object)(jsonObject = JSONObject.fromObject((Object)(sendResStr = sendResMap.get("mess").replace("jhxtGetBsyNsrsbh", domain.getYwId())))).getJSONObject("domain").get("retJson"))).getString("result"), JhxtBsyNsrsbhReturnDomain.class)).getCode())) {
                for (JhxtBsyNsrsbhDomain tmp : jhxtReturnDomain.getDataList()) {
                    nsrsbhs.add(tmp.getNsrsbh());
                }
            }
        }
        List<String> nsrsbh_tm = ((TaxQttySmzzAppDaoImp)this.getDao("taxQttySmzzAppDaoImp")).queryNsrsbhsFromTm(appDomain.getSfzhm());
        nsrsbhs.addAll(nsrsbh_tm);
        return ((TaxQttySmzzAppDaoImp)this.getDao("taxQttySmzzAppDaoImp")).querySmzzBsyNsrxx(nsrsbhs, appDomain.getYyxtdm());
    }

    @Override
    public TaxCommonReturnDomain doSmzzBsyLoginLog(BaseAppServiceDomain appDomain) throws Exception {
        QttySmzzBsyLoginLogAppDomain domain = (QttySmzzBsyLoginLogAppDomain)appDomain;
        return ((TaxQttySmzzAppDaoImp)this.getDao("taxQttySmzzAppDaoImp")).doSmzzBsyLoginLog(domain);
    }

    @Override
    public TaxCommonReturnDomain doSmzzBsyLogoutLog(BaseAppServiceDomain appDomain) throws Exception {
        QttySmzzBsyLogoutLogAppDomain domain = (QttySmzzBsyLogoutLogAppDomain)appDomain;
        return ((TaxQttySmzzAppDaoImp)this.getDao("taxQttySmzzAppDaoImp")).doSmzzBsyLogoutLog(domain);
    }

    public BaseDao getDao(String daoName) {
        this.dao = (BaseDao)WebConstants.WEB_APP_CONTEXT.getBean(daoName);
        return this.dao;
    }

    public Map<String, String> sendMess(BaseAppServiceDomain domain, String ywId) {
        HashMap<String, String> sendResMap = new HashMap<String, String>();
        String url = WebConstants.JHXT_URL;
        HttpPost httppost = new HttpPost(url);
        String strResult = "";
        CloseableHttpClient httpClient = HttpClients.createDefault();
        try {
            httppost.addHeader("Content-type", "application/x-www-form-urlencoded;charset=gbk");
            ArrayList<BasicNameValuePair> par = new ArrayList<BasicNameValuePair>();
            par.add(new BasicNameValuePair("domain.ywId", ywId));
            par.add(new BasicNameValuePair("domain.parmJson", HstJsonUtil.beanCtreatJson(domain).replace(domain.getBid(), ywId)));
            httppost.setEntity((HttpEntity)new UrlEncodedFormEntity(par));
            CloseableHttpResponse response = httpClient.execute((HttpUriRequest)httppost);
            if (response.getStatusLine().getStatusCode() == 200) {
                strResult = EntityUtils.toString((HttpEntity)response.getEntity());
                sendResMap.put("code", "00");
                sendResMap.put("mess", strResult);
            } else {
                String err = String.valueOf(response.getStatusLine().getStatusCode());
                strResult = String.valueOf(strResult) + "\u8bf7\u6c42\u5931\u8d25\uff0c\u9519\u8bef\u4ee3\u7801\uff1a" + err;
                sendResMap.put("code", "01");
                sendResMap.put("mess", strResult);
            }
        }
        catch (ClientProtocolException e) {
            sendResMap.put("code", "01");
            sendResMap.put("mess", e.toString());
            _logger.error((Object)e.toString());
        }
        catch (IOException e) {
            sendResMap.put("code", "01");
            sendResMap.put("mess", e.toString());
            _logger.error((Object)e.toString());
        }
        return sendResMap;
    }
}
