/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  org.dom4j.Document
 *  org.dom4j.Element
 *  org.springframework.beans.factory.annotation.Autowired
 *  org.springframework.stereotype.Repository
 */
package com.hst.taxService.dao.imp;

import com.hst.common.domain.TaxCommonReturnDomain;
import com.hst.common.util.EjbExternalFactory;
import com.hst.common.util.External;
import com.hst.common.util.HstWxServiceUtil;
import com.hst.common.util.Xml;
import com.hst.framework.common.HstSqlMapClientTemplate;
import com.hst.framework.constants.WebConstants;
import com.hst.framework.util.HstToolsUtil;
import com.hst.taxService.dao.TaxCtais2AppDao;
import com.hst.taxService.domain.ctais2.FppzjbxxcxAppDomain;
import com.hst.taxService.domain.ctais2.FppzjbxxcxReturnDomain;
import com.hst.taxService.domain.ctais2.FppzxxDomain;
import com.hst.taxService.domain.ctais2.GpyxxDomain;
import com.hst.taxService.domain.gt3.HxzgFpCxnsrpzhdgprxxRequestDomain;
import com.hst.taxService.domain.gt3.HxzgFpCxnsrpzhdgprxxResponseDomain;
import com.hst.taxService.domain.gt3.HxzgFpCxnsrpzhdxxRequestDomain;
import com.hst.taxService.domain.gt3.HxzgFpCxnsrpzhdxxResponseDomain;
import com.hst.taxService.domain.gt3.HxzgFpPzhdgprxxDomain;
import com.hst.taxService.domain.gt3.HxzgFpPzhdxxDomain;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.dom4j.Document;
import org.dom4j.Element;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class TaxCtais2FppzxxcxAppDaoImp
implements TaxCtais2AppDao {
    @Autowired
    private HstSqlMapClientTemplate sqlMapClientTemplate;

    public TaxCommonReturnDomain queryEjb(FppzjbxxcxAppDomain domain) throws Exception {
        String reqStr = this.createXml(domain);
        _logger.error((Object)("\u7968\u79cd\u57fa\u672c\u4fe1\u606f\u67e5\u8be2\u8bf7\u6c42\u62a5\u6587xml \uff1a" + reqStr));
        String resStr = this.doEjbServcie(reqStr);
        _logger.info((Object)("\u7968\u79cd\u57fa\u672c\u4fe1\u606f\u67e5\u8be2\u63a5\u53e3\u54cd\u5e94\u62a5\u6587xml" + resStr));
        FppzjbxxcxReturnDomain returnDomain = this.parserXml(resStr);
        return returnDomain;
    }

    public TaxCommonReturnDomain query(FppzjbxxcxAppDomain domain) throws Exception {
        FppzjbxxcxReturnDomain returnDomain = null;
        HashMap<String, String> map = new HashMap<String, String>();
        map.put("nsrsbh", domain.getNsrsbh());
        map.put("gpyList", null);
        map.put("dataList", null);
        this.sqlMapClientTemplate.queryForObjectByCurr("queryFppzjbxxcx", map, "gpyList", "dataList");
        List gpyxxList = (List)map.get("gpyList");
        List dataList = (List)map.get("dataList");
        returnDomain = new FppzjbxxcxReturnDomain();
        returnDomain.setGpyxxList(gpyxxList);
        returnDomain.setDataList(dataList);
        returnDomain.setCode("00");
        returnDomain.setMess(HstToolsUtil.ISO2GBK((String)map.get("mess")));
        return returnDomain;
    }

    public String createXml(FppzjbxxcxAppDomain domain) throws Exception {
        if (domain == null) {
            return null;
        }
        StringBuffer xmlStr = new StringBuffer("<?xml version=\"1.0\" encoding=\"UTF-8\"?>").append("").append("<taxML xmlns=\"http://www.chinatax.gov.cn/dataspec/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"slCxFppzjbxxRequest\" cnName=\"\u7968\u79cd\u57fa\u672c\u4fe1\u606f\u67e5\u8be2\u63a5\u53e3\u8bf7\u6c42\u62a5\u6587\" name=\"slCxFppzjbxxRequest\" version=\"SW5001-2006\">").append("\t<nsrsbh>").append(domain.getNsrsbh()).append("</nsrsbh>").append("</taxML>");
        return xmlStr.toString();
    }

    public String doEjbServcie(String reqStr) throws Exception {
        External external = new EjbExternalFactory().createInstance();
        String retStr = external.doCommService("TAXML.PZHDXX.Portal.Ctais", reqStr);
        return retStr;
    }

    public FppzjbxxcxReturnDomain parserXml(String xmlStr) throws Exception {
        FppzjbxxcxReturnDomain domain = new FppzjbxxcxReturnDomain();
        Document doc = new Xml().createDocument(xmlStr);
        Element root = doc.getRootElement();
        Element groupElement = root.element("returnState");
        if (groupElement == null) {
            return domain;
        }
        Element returnCodeElement = groupElement.element("returnCode");
        if (returnCodeElement != null) {
            domain.setCode(returnCodeElement.getText());
        }
        Element returnMessageElement = groupElement.element("returnMessage");
        if (returnCodeElement != null) {
            domain.setMess(returnMessageElement.getText());
        }
        if (!"000".equals(domain.getCode())) {
            return domain;
        }
        domain.setCode("00");
        groupElement = root.element("businessContent");
        if (groupElement == null) {
            return domain;
        }
        Element subPackageElement = groupElement.element("subPackage");
        if (subPackageElement == null) {
            return domain;
        }
        Element contentElement = subPackageElement.element("content");
        if (contentElement != null) {
            String resStr = contentElement.getText();
            Document resDoc = new Xml().createDocument(resStr);
            Element resRoot = resDoc.getRootElement();
            if (resRoot == null) {
                return domain;
            }
            ArrayList<GpyxxDomain> gpyxxList = new ArrayList<GpyxxDomain>();
            GpyxxDomain gpyxxDomain = null;
            List listGpyxx = resRoot.elements("gpyxx");
            for (Element element : listGpyxx) {
                gpyxxDomain = new GpyxxDomain();
                gpyxxDomain.setFpjbr(element.elementText("fpjbr"));
                gpyxxDomain.setJbrzjlxDm(element.elementText("jbrzjlxDm"));
                gpyxxDomain.setZjhm(element.elementText("zjhm"));
                gpyxxList.add(gpyxxDomain);
            }
            domain.setGpyxxList(gpyxxList);
            ArrayList<FppzxxDomain> dataList = new ArrayList<FppzxxDomain>();
            FppzxxDomain pzxxDomain = null;
            List listPzxx = resRoot.elements("fppzxx");
            for (Element element : listPzxx) {
                pzxxDomain = new FppzxxDomain();
                pzxxDomain.setFpzlDm(element.elementText("fpzlDm"));
                pzxxDomain.setMygpzgsl(element.elementText("mygpzgsl"));
                pzxxDomain.setZdfpje(element.elementText("zdfpje"));
                pzxxDomain.setLgsl(element.elementText("lgsl"));
                pzxxDomain.setCpzgsl(element.elementText("cpzgsl"));
                pzxxDomain.setLcpbbz(element.elementText("lcpbbz"));
                pzxxDomain.setFpBgfsDm(element.elementText("fpBgfsDm"));
                pzxxDomain.setFpGpfsDm(element.elementText("fpGpfsDm"));
                dataList.add(pzxxDomain);
            }
            domain.setDataList(dataList);
        }
        return domain;
    }

    public TaxCommonReturnDomain queryGt3(FppzjbxxcxAppDomain domain) throws Exception {
        HashMap<String, String> map = new HashMap<String, String>();
        map.put("nsrsbh", domain.getNsrsbh());
        String djxh = (String)this.sqlMapClientTemplate.queryForObject("selectCtais2Nsrdjxh", map);
        FppzjbxxcxReturnDomain returnDomain = new FppzjbxxcxReturnDomain();
        ArrayList<FppzxxDomain> dataList = new ArrayList<FppzxxDomain>();
        ArrayList<GpyxxDomain> gpyxxList = new ArrayList<GpyxxDomain>();
        HxzgFpCxnsrpzhdgprxxRequestDomain request1 = new HxzgFpCxnsrpzhdgprxxRequestDomain();
        request1.setDjxh(djxh);
        request1.setBid("GT3.HxzgFpCxnsrpzhdgprxx");
        HxzgFpCxnsrpzhdgprxxResponseDomain response1 = HstWxServiceUtil.sendMess(WebConstants.GT3JK_SJ_URL, request1, "GT3.HxzgFpCxnsrpzhdgprxx", HxzgFpCxnsrpzhdgprxxResponseDomain.class);
        if ("00".equals(response1.getCode())) {
            for (HxzgFpPzhdgprxxDomain dom : response1.getDataList()) {
                GpyxxDomain tmp = new GpyxxDomain();
                tmp.setFpjbr(dom.getGprxm());
                tmp.setJbrzjlxDm(dom.getSfzjzlDm());
                tmp.setZjhm(dom.getSfzjhm());
                gpyxxList.add(tmp);
            }
            returnDomain.setCode(response1.getCode());
            returnDomain.setMess(response1.getMess());
        } else {
            returnDomain.setCode(response1.getCode());
            returnDomain.setMess(response1.getMess());
        }
        HxzgFpCxnsrpzhdxxRequestDomain request2 = new HxzgFpCxnsrpzhdxxRequestDomain();
        request2.setDjxh(djxh);
        request2.setBid("GT3.HxzgFpCxnsrpzhdxx");
        HxzgFpCxnsrpzhdxxResponseDomain response2 = HstWxServiceUtil.sendMess(WebConstants.GT3JK_SJ_URL, request2, "GT3.HxzgFpCxnsrpzhdxx", HxzgFpCxnsrpzhdxxResponseDomain.class);
        if ("00".equals(response2.getCode())) {
            for (HxzgFpPzhdxxDomain dom : response2.getDataList()) {
                FppzxxDomain pzxxDomain = new FppzxxDomain();
                pzxxDomain.setFpzlDm(dom.getFpzlDm());
                pzxxDomain.setMygpzgsl(dom.getMyzggpsl());
                pzxxDomain.setZdfpje(dom.getDffpzgkpxe());
                pzxxDomain.setLgsl(dom.getMczggpsl());
                pzxxDomain.setCpzgsl(dom.getCpzgsl());
                pzxxDomain.setFpGpfsDm(dom.getFpgpfsDm());
                dataList.add(pzxxDomain);
            }
            returnDomain.setCode(response2.getCode());
            returnDomain.setMess(response2.getMess());
        } else {
            returnDomain.setCode(response2.getCode());
            returnDomain.setMess(response2.getMess());
        }
        returnDomain.setDataList(dataList);
        returnDomain.setGpyxxList(gpyxxList);
        return returnDomain;
    }
}
