/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  org.springframework.beans.factory.annotation.Autowired
 *  org.springframework.stereotype.Service
 *  org.springframework.transaction.annotation.Propagation
 *  org.springframework.transaction.annotation.Transactional
 */
package com.hst.taxService.service.imp;

import com.hst.business.domain.XtGt3LogDomain;
import com.hst.common.service.imp.BaseBusinessServiceImp;
import com.hst.common.util.XmlHelper;
import com.hst.common.util.XmlUtil;
import com.hst.framework.util.HstDateUtil;
import com.hst.taxService.dao.TaxCommonDao;
import com.hst.taxService.domain.gt3.Gt3HeadDomain;
import com.hst.taxService.domain.gt3.Gt3LogDataDomain;
import com.hst.taxService.domain.gt3.Gt3LogDataGridDomain;
import com.hst.taxService.domain.gt3.Gt3LogDataRequestDomain;
import com.hst.taxService.domain.gt3.Gt3RtnMsgDomain;
import com.hst.taxService.domain.gt3.Gt3ServiceDomain;
import com.hst.taxService.domain.gt3.HXZGZS10025ResponseDomain;
import com.hst.taxService.domain.gt3.HXZGZS10025SzmxGridDomain;
import com.hst.taxService.domain.gt3.HXZGZS10025SzmxGridlbDomain;
import com.hst.taxService.domain.gt3.HXZGZS10025YzxxGridDomain;
import com.hst.taxService.domain.gt3.HXZGZS10025YzxxGridlbDomain;
import com.hst.taxService.domain.gt3.HxzgZsYzpzxhGridDomain;
import com.hst.taxService.service.TaxCommonService;
import java.util.HashMap;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
public class TaxCommonServiceImp
extends BaseBusinessServiceImp
implements TaxCommonService {
    @Autowired
    private TaxCommonDao dao;

    @Override
    @Transactional(readOnly=false, propagation=Propagation.REQUIRED)
    public void dealGt3Log() throws Exception {
        String tranId = "'SWZJ.HXZG.ZS.SKYSKJN";
        List<XtGt3LogDomain> dataList = this.dao.queryGt3LogList(tranId, HstDateUtil.getCurrentDate());
        if (dataList == null || dataList.isEmpty()) {
            return;
        }
        Gt3LogDataDomain domain = null;
        for (XtGt3LogDomain dom : dataList) {
            domain = new Gt3LogDataDomain();
            domain.setLogXh(dom.getLogXh());
            domain.setTranId(dom.getTranId());
            domain.setReqTime(dom.getReqTime());
            domain.setResCode(dom.getResCode());
            domain.setResMess(dom.getResMess());
            Gt3ServiceDomain gt3 = this.parseJsbw(dom.getReqData());
            if (gt3 == null) {
                throw new Exception("\u89e3\u6790\u8bf7\u6c42\u62a5\u6587");
            }
            this.parseReq(gt3.getBody(), domain);
            if ("0000".equals(dom.getResCode())) {
                this.parseRes(dom.getResData(), domain);
                domain.setBz(dom.getResData());
            }
            this.dao.saveLogData(domain);
        }
    }

    public void parseReq(String xml, Gt3LogDataDomain domain) throws Exception {
        HashMap<String, Class> mapClass = new HashMap<String, Class>();
        mapClass.put("taxML", Gt3LogDataRequestDomain.class);
        mapClass.put("yzpzxhGrid", Gt3LogDataGridDomain.class);
        mapClass.put("yzpzxhGridlb", HxzgZsYzpzxhGridDomain.class);
        XmlHelper help = new XmlHelper("taxML", mapClass);
        Gt3LogDataRequestDomain ret = (Gt3LogDataRequestDomain)help.xmlStrParser(xml);
        if (ret != null && !ret.getYzpzxhGrid().getYzpzxhGridlb().isEmpty()) {
            HxzgZsYzpzxhGridDomain temp = ret.getYzpzxhGrid().getYzpzxhGridlb().get(0);
            domain.setPzxh(temp.getYzpzxh());
            domain.setDjxh(ret.getDjxh());
        }
    }

    public void parseRes(String xml, Gt3LogDataDomain domain) throws Exception {
        HashMap<String, Class> mapClass = new HashMap<String, Class>();
        mapClass.put("taxML", HXZGZS10025ResponseDomain.class);
        mapClass.put("yzxxGrid", HXZGZS10025YzxxGridDomain.class);
        mapClass.put("yzxxGridlb", HXZGZS10025YzxxGridlbDomain.class);
        mapClass.put("szmxGrid", HXZGZS10025SzmxGridDomain.class);
        mapClass.put("szmxGridlb", HXZGZS10025SzmxGridlbDomain.class);
        XmlHelper help = new XmlHelper("taxML", mapClass);
        HXZGZS10025ResponseDomain ret = (HXZGZS10025ResponseDomain)help.xmlStrParser(xml);
        if (ret != null && !ret.getYzxxGrid().getYzxxGridlb().isEmpty()) {
            HXZGZS10025YzxxGridlbDomain temp = ret.getYzxxGrid().getYzxxGridlb().get(0);
            if (!"000".equals(temp.getKkfhDm())) {
                domain.setResCode("0" + temp.getKkfhDm());
                domain.setResMess(temp.getKkfhmc());
            }
            domain.setDzsphm(temp.getDzsphm());
            domain.setSe(temp.getSjse());
        }
    }

    public Gt3ServiceDomain parseJsbw(String strResult) {
        HashMap<String, Class> mapClass = new HashMap<String, Class>();
        mapClass.put("head", Gt3HeadDomain.class);
        mapClass.put("rtn_msg", Gt3RtnMsgDomain.class);
        Gt3ServiceDomain domain = XmlUtil.xmlStrToBean(strResult, Gt3ServiceDomain.class, "service", mapClass);
        return domain;
    }
}
