/*
 * 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.FplgbdyAppDomain;
import com.hst.taxService.domain.ctais2.FplgbdyReturnDomain;
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 TaxCtais2FplgbdyAppDaoImp
implements TaxCtais2AppDao {
    @Autowired
    private HstSqlMapClientTemplate sqlMapClientTemplate;

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

    public String createXml(FplgbdyAppDomain 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=\"slFpDjbDyRequest\" cnName=\"\u6253\u5370\u53d1\u7968\u9886\u8d2d\u7c3f\u63a5\u53e3\u8bf7\u6c42\u62a5\u6587\" name=\"slFpDjbDyRequest\" 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<hs>").append(domain.getHs()).append("</hs>").append("\t<czryDm>").append(domain.getCzryDm()).append("</czryDm>").append("\t<swjgDm>").append(domain.getSwjgDm()).append("</swjgDm>").append("</taxML>");
        return xmlStr.toString();
    }

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

    public FplgbdyReturnDomain parserXml(String xmlStr) throws Exception {
        FplgbdyReturnDomain domain = new FplgbdyReturnDomain();
        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;
        }
        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);
    }
}
