/*
 * 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.FpxsAppDomain;
import com.hst.taxService.domain.ctais2.FpxsDomain;
import com.hst.taxService.domain.ctais2.FpxsReturnDomain;
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 TaxCtais2FpxsAppDaoImp
implements TaxCtais2AppDao {
    @Autowired
    private HstSqlMapClientTemplate sqlMapClientTemplate;

    public TaxCommonReturnDomain queryEjb(FpxsAppDomain domain) throws Exception {
        String reqStr = this.createXml(domain);
        _logger.error((Object)("\u53d1\u7968\u53d1\u552e\u8bf7\u6c42\u62a5\u6587xml \uff1a" + reqStr));
        String resStr = this.doEjbServcie(reqStr);
        _logger.info((Object)("\u53d1\u7968\u53d1\u552e\u63a5\u53e3\u54cd\u5e94\u62a5\u6587xml" + resStr));
        FpxsReturnDomain returnDomain = this.parserXml(resStr);
        return returnDomain;
    }

    public TaxCommonReturnDomain query(FpxsAppDomain domain) throws Exception {
        FpxsReturnDomain returnDomain = new FpxsReturnDomain();
        return returnDomain;
    }

    public String createXml(FpxsAppDomain 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=\"slWebFpfsRequest\" cnName=\"\u53d1\u7968\u53d1\u552e\" name=\"slWebFpfsRequest\" version=\"SW5001-2006\">").append("\t<fpfsxx><nsrsbh>").append(domain.getNsrsbh()).append("</nsrsbh>").append("\t<czryDm>").append(domain.getCzryDm()).append("</czryDm>").append("\t<fpxxs>");
        for (FpxsDomain dom : domain.getDataList()) {
            xmlStr.append("  <fpxx>").append("<fpzl>").append(dom.getFpzl()).append("</fpzl>").append("<fpdm>").append(dom.getFpdm()).append("</fpdm>").append("<sqsl>").append(dom.getSqsl()).append("</sqsl>").append("</fpxx>");
        }
        xmlStr.append("</fpxxs></fpfsxx></taxML>");
        return xmlStr.toString();
    }

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

    public FpxsReturnDomain parserXml(String xmlStr) throws Exception {
        FpxsReturnDomain domain = new FpxsReturnDomain();
        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;
            }
            Element fpfsxxElement = resRoot.element("fpfsxx");
            domain.setBcjg(fpfsxxElement.elementText("bcjg"));
            domain.setJgsm(fpfsxxElement.elementText("jgsm"));
            ArrayList<FpxsDomain> dataList = new ArrayList<FpxsDomain>();
            FpxsDomain fpxsDomain = null;
            List listPzxx = fpfsxxElement.element("fphms").elements("fphm");
            for (Element element : listPzxx) {
                fpxsDomain = new FpxsDomain();
                fpxsDomain.setFpzl(element.elementText("fpzl"));
                fpxsDomain.setFpdm(element.elementText("fpdm"));
                fpxsDomain.setNsrjcczxh(element.elementText("nsrjcczxh"));
                fpxsDomain.setBs(element.elementText("bs"));
                fpxsDomain.setFpqshm(element.elementText("fpqshm"));
                fpxsDomain.setFpzzhm(element.elementText("fpzzhm"));
                dataList.add(fpxsDomain);
            }
            domain.setDataList(dataList);
        }
        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);
    }
}
