/*
 * 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.Xml;
import com.hst.framework.common.HstSqlMapClientTemplate;
import com.hst.taxService.dao.TaxCtais2AppDao;
import com.hst.taxService.domain.ctais2.FplgbhsAppDomain;
import com.hst.taxService.domain.ctais2.FplgbhsReturnDomain;
import java.util.HashMap;
import org.dom4j.Document;
import org.dom4j.Element;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

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

    public TaxCommonReturnDomain queryEjb(FplgbhsAppDomain domain) throws Exception {
        String reqStr = this.createXml(domain);
        _logger.error((Object)("\u9886\u8d2d\u7c3f\u6253\u5370\u884c\u6570\u67e5\u8be2\u8bf7\u6c42\u62a5\u6587xml \uff1a" + reqStr));
        String resStr = this.doEjbServcie(reqStr);
        _logger.info((Object)("\u9886\u8d2d\u7c3f\u6253\u5370\u884c\u6570\u67e5\u8be2\u63a5\u53e3\u54cd\u5e94\u62a5\u6587xml" + resStr));
        FplgbhsReturnDomain returnDomain = this.parserXml(resStr);
        return returnDomain;
    }

    public TaxCommonReturnDomain query(FplgbhsAppDomain domain) throws Exception {
        FplgbhsReturnDomain returnDomain = new FplgbhsReturnDomain();
        HashMap<String, String> map = new HashMap<String, String>();
        map.put("nsrsbh", domain.getNsrsbh());
        map.put("bz", domain.getBz());
        map.put("fplb", domain.getFplb());
        map.put("hs", null);
        this.sqlMapClientTemplate.queryForObjectByCurr("queryPFplgbdyhs", map, new String[0]);
        returnDomain.setHs((String)map.get("hs"));
        returnDomain.setCode("00");
        return returnDomain;
    }

    public String createXml(FplgbhsAppDomain domain) throws Exception {
        if (domain == null) {
            return null;
        }
        StringBuffer xmlStr = new StringBuffer("<?xml version=\"1.0\" encoding=\"UTF-8\"?>").append("<taxML xmlns=\"http://www.chinatax.gov.cn/dataspec/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"slFpDjbHsQueryRequest\" cnName=\"\u83b7\u53d6\u53d1\u7968\u9886\u8d2d\u7c3f\u5df2\u6253\u5370\u884c\u6570\u63a5\u53e3\u8bf7\u6c42\u62a5\u6587\" name=\"slFpDjbHsQueryRequest\" version=\"SW5001-2006\">").append("\t<nsrsbh>").append(domain.getNsrsbh()).append("</nsrsbh>").append("\t<bz>").append(domain.getBz()).append("</bz>").append("\t<fplb>").append(domain.getFplb()).append("</fplb>").append("\t<czryDm>").append(domain.getCzryDm()).append("</czryDm>").append("\t<swjgDm>").append(domain.getSwjgDm()).append("</swjgDm>");
        xmlStr.append("</taxML>");
        return xmlStr.toString();
    }

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

    public FplgbhsReturnDomain parserXml(String xmlStr) throws Exception {
        FplgbhsReturnDomain domain = new FplgbhsReturnDomain();
        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;
            }
            domain.setHs(resRoot.elementText("hs"));
        }
        return domain;
    }

    public String selectFplbDm(String fpzlDm) {
        HashMap<String, String> map = new HashMap<String, String>();
        map.put("fpzlDm", fpzlDm);
        return (String)this.sqlMapClientTemplate.queryForObject("selectFplbDmByFpzlDm", map);
    }
}
