/*
 * 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.FpyjAppDomain;
import com.hst.taxService.domain.ctais2.FpyjDomain;
import com.hst.taxService.domain.ctais2.FpyjReturnDomain;
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 TaxCtais2FpyjAppDaoImp
implements TaxCtais2AppDao {
    @Autowired
    private HstSqlMapClientTemplate sqlMapClientTemplate;

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

    public TaxCommonReturnDomain query(FpyjAppDomain domain) throws Exception {
        FpyjReturnDomain returnDomain = new FpyjReturnDomain();
        return returnDomain;
    }

    public String createXml(FpyjAppDomain 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=\"jhJdptfpYjRequest\" cnName=\"\u53d1\u7968\u9a8c\u65e7\" name=\"jhJdptfpYjRequest\" version=\"SW5001-2006\">").append("<yjxx><cllx>").append(domain.getCllx()).append("</cllx>").append("\t<nsrsbh>").append(domain.getNsrsbh()).append("</nsrsbh>");
        for (FpyjDomain dom : domain.getDataList()) {
            xmlStr.append("  <yjFpxx>").append("<fpYjjgDm>").append(dom.getFpYjjgDm()).append("</fpYjjgDm>").append("<fpzlDm>").append(dom.getFpzlDm()).append("</fpzlDm>").append("<fpDm>").append(dom.getFpDm()).append("</fpDm>").append("<yjrq>").append(dom.getYjrq().replace("-", "")).append("</yjrq>").append("<fs>").append(dom.getFs()).append("</fs>").append("<fpqh>").append(dom.getFpqh()).append("</fpqh>").append("<fpzh>").append(dom.getFpzh()).append("</fpzh>").append("<kprq>").append("<rqQ>").append(dom.getRqQ().replace("-", "")).append("</rqQ>").append("<rqZ>").append(dom.getRqZ().replace("-", "")).append("</rqZ>").append("</kprq>").append("<je>").append(dom.getJe()).append("</je>").append("<se>").append(dom.getSe()).append("</se>").append("</yjFpxx>");
        }
        xmlStr.append("</yjxx></taxML>");
        return xmlStr.toString();
    }

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

    public FpyjReturnDomain parserXml(String xmlStr) throws Exception {
        FpyjReturnDomain domain = new FpyjReturnDomain();
        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.setNsrsbh(resRoot.elementText("nsrsbh"));
            domain.setSftbwzxx(resRoot.elementText("sftbwzxx"));
            Element wfwzxx = resRoot.element("wfwzxx");
            if (wfwzxx != null) {
                domain.setZywfwzss(wfwzxx.elementText("zywfwzss"));
                domain.setZywfwzsdDm(wfwzxx.elementText("zywfwzsdDm"));
                ArrayList<FpyjDomain> dataList = new ArrayList<FpyjDomain>();
                FpyjDomain FpyjDomain2 = null;
                List listFpxx = wfwzxx.elements("fpxx");
                for (Element element : listFpxx) {
                    FpyjDomain2 = new FpyjDomain();
                    FpyjDomain2.setFpYjjgDm(element.elementText("fpYjjgDm"));
                    FpyjDomain2.setFpzlDm(element.elementText("fpzlDm"));
                    FpyjDomain2.setFpDm(element.elementText("fpDm"));
                    FpyjDomain2.setYjrq(element.elementText("yjrq"));
                    FpyjDomain2.setFs(element.elementText("fs"));
                    FpyjDomain2.setFpqh(element.elementText("fpqh"));
                    FpyjDomain2.setFpzh(element.elementText("fpzh"));
                    FpyjDomain2.setRqQ(element.element("kprq").elementText("rqQ"));
                    FpyjDomain2.setRqZ(element.element("kprq").elementText("rqZ"));
                    FpyjDomain2.setJe(element.elementText("je"));
                    FpyjDomain2.setSe(element.elementText("se"));
                    dataList.add(FpyjDomain2);
                }
                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);
    }
}
