/*
 * 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.taxService.dao.TaxCtais2AppDao;
import com.hst.taxService.domain.ctais2.FpxxDomain;
import com.hst.taxService.domain.ctais2.NsrFpjcAppDomain;
import com.hst.taxService.domain.ctais2.NsrFpjcReturnDomain;
import com.hst.taxService.domain.gt3.HxzgFpCxnsrfpjcDomain;
import com.hst.taxService.domain.gt3.HxzgFpCxnsrfpjcRequestDomain;
import com.hst.taxService.domain.gt3.HxzgFpCxnsrfpjcResponseDomain;
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 TaxCtais2NsrfpjcAppDaoImp
implements TaxCtais2AppDao {
    @Autowired
    private HstSqlMapClientTemplate sqlMapClientTemplate;

    public TaxCommonReturnDomain query(NsrFpjcAppDomain domain) throws Exception {
        NsrFpjcReturnDomain returnDomain = null;
        HashMap<String, String> map = new HashMap<String, String>();
        map.put("nsrsbh", domain.getNsrsbh());
        map.put("nsrfpjcList", null);
        this.sqlMapClientTemplate.queryForObjectByCurr("queryNsrfpjcList", "nsrfpjcList", map);
        ArrayList<FpxxDomain> dataList = new ArrayList();
        dataList = (List)map.get("nsrfpjcList");
        returnDomain = new NsrFpjcReturnDomain();
        returnDomain.setDataList(dataList);
        returnDomain.setCode("00");
        returnDomain.setMess("");
        return returnDomain;
    }

    public TaxCommonReturnDomain queryEjb(NsrFpjcAppDomain domain) throws Exception {
        String reqStr = this.createXml(domain);
        _logger.error((Object)("\u7eb3\u7a0e\u4eba\u7ed3\u5b58\u67e5\u8be2\u8bf7\u6c42\u62a5\u6587xml \uff1a" + reqStr));
        String resStr = this.doEjbServcie(reqStr);
        _logger.info((Object)("\u7eb3\u7a0e\u4eba\u7ed3\u5b58\u67e5\u8be2\u63a5\u53e3\u54cd\u5e94\u62a5\u6587xml" + resStr));
        NsrFpjcReturnDomain returnDomain = this.parserXml(resStr);
        return returnDomain;
    }

    public TaxCommonReturnDomain queryGt3(NsrFpjcAppDomain domain) throws Exception {
        HashMap<String, String> map = new HashMap<String, String>();
        map.put("nsrsbh", domain.getNsrsbh());
        String djxh = (String)this.sqlMapClientTemplate.queryForObject("selectCtais2Nsrdjxh", map);
        NsrFpjcReturnDomain returnDomain = new NsrFpjcReturnDomain();
        HxzgFpCxnsrfpjcRequestDomain request = new HxzgFpCxnsrfpjcRequestDomain();
        request.setDjxh(djxh);
        request.setBid("GT3.HxzgFpCxnsrfpjc");
        HxzgFpCxnsrfpjcResponseDomain response = HstWxServiceUtil.sendMess(WebConstants.GT3JK_SJ_URL, request, "GT3.HxzgFpCxnsrfpjc", HxzgFpCxnsrfpjcResponseDomain.class);
        if ("00".equals(response.getCode())) {
            ArrayList<FpxxDomain> dataList = new ArrayList<FpxxDomain>();
            for (HxzgFpCxnsrfpjcDomain dom : response.getDataList()) {
                FpxxDomain tmp = new FpxxDomain();
                tmp.setFpzlDm(dom.getFpzlDm());
                tmp.setFpDm(dom.getFpDm());
                tmp.setFpzlMc(dom.getFpzlmc());
                tmp.setFs(dom.getFs());
                tmp.setFpqh(dom.getFpqshm());
                tmp.setFpzh(dom.getFpzzhm());
                tmp.setFpKcztDm(dom.getFpzzhm());
                tmp.setXgrq(dom.getXgrq());
                dataList.add(tmp);
            }
            returnDomain.setCode(response.getCode());
            returnDomain.setMess(response.getMess());
            returnDomain.setDataList(dataList);
        } else {
            returnDomain.setCode(response.getCode());
            returnDomain.setMess(response.getMess());
        }
        return returnDomain;
    }

    public String createXml(NsrFpjcAppDomain domain) throws Exception {
        if (domain == null) {
            return null;
        }
        StringBuffer xmlStr = new StringBuffer("<?xml version=\"1.0\" encoding=\"UTF-8\"?>").append("<business id=\"DHNSRFPJC.CX.PORTAL.CTAIS\" comment=\"\u7eb3\u7a0e\u4eba\u7ed3\u5b58\u7684\u53d1\u7968\u4fe1\u606f\">").append("<group><data name=\"nsrsbh\" value=\"" + domain.getNsrsbh() + "\" />");
        xmlStr.append("</group></business>");
        return xmlStr.toString();
    }

    public String doEjbServcie(String reqStr) throws Exception {
        External external = new EjbExternalFactory().createInstance();
        String retStr = external.doCommService("DHNSRFPJC.CX.PORTAL.CTAIS", reqStr);
        return retStr;
    }

    public NsrFpjcReturnDomain parserXml(String xmlStr) throws Exception {
        NsrFpjcReturnDomain domain = new NsrFpjcReturnDomain();
        Document doc = new Xml().createDocument(xmlStr);
        Element root = doc.getRootElement();
        Element groupLv1 = root.element("group");
        List datasLv1 = groupLv1.elements("data");
        for (Element e : datasLv1) {
            if ("returnCode".equals(e.attributeValue("name"))) {
                domain.setCode(e.attributeValue("value"));
            }
            if (!"returnMessage".equals(e.attributeValue("name"))) continue;
            domain.setMess(e.attributeValue("value"));
        }
        if (!"00".equals(domain.getCode())) {
            return domain;
        }
        ArrayList<FpxxDomain> dataList = new ArrayList<FpxxDomain>();
        Element businessElment = groupLv1.element("business");
        List groupsLv2 = businessElment.elements("group");
        for (Element group : groupsLv2) {
            List datasLv2 = group.elements("data");
            FpxxDomain dom = new FpxxDomain();
            for (Element data : datasLv2) {
                if ("NSRSBH".equals(data.attributeValue("name"))) {
                    dom.setNsrsbh(data.attributeValue("value"));
                }
                if ("FP_KCZT_DM".equals(data.attributeValue("name"))) {
                    dom.setFpKcztDm(data.attributeValue("value"));
                }
                if ("FPZL_DM".equals(data.attributeValue("name"))) {
                    dom.setFpzlDm(data.attributeValue("value"));
                }
                if ("FP_MC".equals(data.attributeValue("name"))) {
                    dom.setFpzlMc(data.attributeValue("value"));
                }
                if ("FP_DM".equals(data.attributeValue("name"))) {
                    dom.setFpDm(data.attributeValue("value"));
                }
                if ("FS".equals(data.attributeValue("name"))) {
                    dom.setFs(data.attributeValue("value"));
                }
                if ("FPQH".equals(data.attributeValue("name"))) {
                    dom.setFpqh(data.attributeValue("value"));
                }
                if ("FPZH".equals(data.attributeValue("name"))) {
                    dom.setFpzh(data.attributeValue("value"));
                }
                if (!"XGRQ".equals(data.attributeValue("name"))) continue;
                dom.setXgrq(data.attributeValue("value"));
            }
            dataList.add(dom);
        }
        domain.setDataList(dataList);
        return domain;
    }
}
