/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  javax.annotation.Resource
 *  org.apache.commons.logging.Log
 *  org.apache.commons.logging.LogFactory
 *  org.apache.struts2.convention.annotation.Action
 *  org.apache.struts2.convention.annotation.Result
 *  org.springframework.context.annotation.Scope
 *  org.springframework.stereotype.Controller
 */
package com.hst.taxService.action;

import com.hst.business.domain.XtTaxServiceLogDomain;
import com.hst.common.action.ExtendAction;
import com.hst.common.domain.BaseAppServiceDomain;
import com.hst.common.domain.TaxCommonAppServiceDomain;
import com.hst.common.domain.TaxCommonReturnDomain;
import com.hst.common.service.BaseBusinessService;
import com.hst.common.util.DomainUtil;
import com.hst.common.util.HstJsonUtil;
import com.hst.framework.constants.AppServiceConstants;
import com.hst.framework.constants.WebConstants;
import com.hst.framework.util.HstToolsUtil;
import com.hst.taxService.service.Gt3CommonAppService;
import com.hst.taxService.service.TaxPublicQueryService;
import javax.annotation.Resource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

@Controller
@Scope(value="prototype")
@Action(value="/service/taxPublicQuery", results={@Result(name="doPriService ", type="json")})
public class TaxPublicQueryAction
extends ExtendAction {
    private static final long serialVersionUID = 1L;
    public static Log _logger = LogFactory.getLog(TaxPublicQueryAction.class);
    private TaxCommonAppServiceDomain domain;

    /*
     * Loose catch block
     */
    public String doPriService() throws Exception {
        block42: {
            TaxPublicQueryService service = (TaxPublicQueryService)this.getService();
            BaseAppServiceDomain appDomain = null;
            TaxCommonReturnDomain returnDomain = null;
            TaxCommonReturnDomain errorDomain = null;
            XtTaxServiceLogDomain taxLogDomain = null;
            Gt3CommonAppService gt3Service = null;
            try {
                gt3Service = this.gt3Service();
                if ("Y".equals(WebConstants.TAX_SERVICE_LOG)) {
                    taxLogDomain = new XtTaxServiceLogDomain();
                    taxLogDomain.setRecvData(this.getDomain().getParmJson());
                    gt3Service.saveTaxLog(taxLogDomain);
                }
                String ywId = this.getDomain().getYwId();
                returnDomain = DomainUtil.getDomain(ywId);
                try {
                    appDomain = DomainUtil.getAppServiceDomain(ywId, this.getDomain().getParmJson());
                    if (appDomain == null) {
                        this.handleException(returnDomain, AppServiceConstants.TAX_JSONPARSE_ERROR);
                        return "doPriService ";
                    }
                }
                catch (Exception exception) {
                    block40: {
                        block41: {
                            this.handleException(returnDomain, AppServiceConstants.TAX_JSONPARSE_ERROR);
                            if (!"Y".equals(WebConstants.TAX_SERVICE_LOG)) break block40;
                            if (errorDomain != null || !"00".equals(returnDomain.getCode())) {
                                taxLogDomain.setClbz("9");
                                if (errorDomain != null) {
                                    taxLogDomain.setErrMess(errorDomain.getMess());
                                } else {
                                    taxLogDomain.setErrMess(returnDomain.getMess());
                                }
                                break block41;
                            }
                            taxLogDomain.setClbz("1");
                            if (!HstToolsUtil.isNullOrEmpty(this.domain.getRetJson())) {
                                taxLogDomain.setBackData(this.domain.getRetJson());
                            }
                        }
                        gt3Service.updateTaxLog(taxLogDomain);
                    }
                    taxLogDomain = null;
                    errorDomain = null;
                    appDomain = null;
                    returnDomain = null;
                    gt3Service = null;
                    return "doPriService ";
                }
                if (AppServiceConstants.YWID_TAX_PRI_PUBLICSQLSELECT.equals(ywId)) {
                    returnDomain = service.publicSqlQuery(appDomain);
                } else if (AppServiceConstants.YWID_TAX_PRI_PUBLICPROCSELECT.equals(ywId)) {
                    returnDomain = service.publiProcQuery(appDomain);
                } else if (AppServiceConstants.YWID_TAX_PRI_PUBLICEXESQL.equals(ywId)) {
                    returnDomain = service.queryDbExeSql(appDomain);
                }
                if (returnDomain == null) {
                    returnDomain = new TaxCommonReturnDomain();
                    this.handleException(returnDomain, AppServiceConstants.TAX_APP_ERROR);
                    return "doPriService ";
                }
                if (AppServiceConstants.TAX_APP_SUCCESS.equals(returnDomain.getCode())) {
                    try {
                        this.domain.setRetJson(HstJsonUtil.beanToJson(returnDomain));
                        break block42;
                    }
                    catch (Exception exception) {
                        this.handleException(returnDomain, AppServiceConstants.TAX_BEAN_TO_JSON_ERROR);
                        if ("Y".equals(WebConstants.TAX_SERVICE_LOG)) {
                            if (errorDomain != null || !"00".equals(returnDomain.getCode())) {
                                taxLogDomain.setClbz("9");
                                if (errorDomain != null) {
                                    taxLogDomain.setErrMess(errorDomain.getMess());
                                } else {
                                    taxLogDomain.setErrMess(returnDomain.getMess());
                                }
                            } else {
                                taxLogDomain.setClbz("1");
                                if (!HstToolsUtil.isNullOrEmpty(this.domain.getRetJson())) {
                                    taxLogDomain.setBackData(this.domain.getRetJson());
                                }
                            }
                            gt3Service.updateTaxLog(taxLogDomain);
                        }
                        taxLogDomain = null;
                        errorDomain = null;
                        appDomain = null;
                        returnDomain = null;
                        gt3Service = null;
                        return "doPriService ";
                    }
                }
                this.handleServiceException(returnDomain, returnDomain.getCode(), returnDomain.getMess());
                return "doPriService ";
                {
                    catch (Exception e) {
                        errorDomain = this.handleException(e);
                        this.handleException(returnDomain, errorDomain.getCode(), errorDomain.getMess());
                        break block42;
                    }
                    catch (Throwable throwable) {
                        throw throwable;
                    }
                }
            }
            finally {
                if ("Y".equals(WebConstants.TAX_SERVICE_LOG)) {
                    if (errorDomain != null || !"00".equals(returnDomain.getCode())) {
                        taxLogDomain.setClbz("9");
                        if (errorDomain != null) {
                            taxLogDomain.setErrMess(errorDomain.getMess());
                        } else {
                            taxLogDomain.setErrMess(returnDomain.getMess());
                        }
                    } else {
                        taxLogDomain.setClbz("1");
                        if (!HstToolsUtil.isNullOrEmpty(this.domain.getRetJson())) {
                            taxLogDomain.setBackData(this.domain.getRetJson());
                        }
                    }
                    gt3Service.updateTaxLog(taxLogDomain);
                }
                taxLogDomain = null;
                errorDomain = null;
                appDomain = null;
                returnDomain = null;
                gt3Service = null;
            }
        }
        return "doPriService ";
    }

    public String commonHandle(BaseAppServiceDomain appDomain) throws Exception {
        return AppServiceConstants.TAX_APP_SUCCESS;
    }

    public void handleException(TaxCommonReturnDomain returnDomain, String code) throws Exception {
        if (returnDomain == null) {
            returnDomain = new TaxCommonReturnDomain();
        }
        returnDomain.setCode(code);
        String message = this.handleExceptionMessage(returnDomain.getCode());
        returnDomain.setMess(message);
        this.domain.setRetJson(HstJsonUtil.beanToJson(returnDomain));
        if (WebConstants.LOG_KZ_ERRORS.equals("Y")) {
            _logger.error((Object)message);
        }
    }

    public void handleException(TaxCommonReturnDomain returnDomain, String code, String error) throws Exception {
        if (returnDomain == null) {
            returnDomain = new TaxCommonReturnDomain();
        }
        returnDomain.setCode(code);
        String message = this.handleExceptionMessage(returnDomain.getCode());
        if (HstToolsUtil.isNullOrEmpty(error)) {
            returnDomain.setMess(message);
        } else {
            returnDomain.setMess(String.valueOf(message) + error);
        }
        this.domain.setRetJson(HstJsonUtil.beanToJson(returnDomain));
    }

    public void handleServiceException(TaxCommonReturnDomain returnDomain, String code, String error) throws Exception {
        returnDomain.setCode(code);
        String message = this.handleExceptionMessage(returnDomain.getCode());
        if (HstToolsUtil.isNullOrEmpty(error)) {
            returnDomain.setMess(message);
        } else {
            returnDomain.setMess(String.valueOf(message) + error);
        }
        if (!HstToolsUtil.isNullOrEmpty(returnDomain.getMess())) {
            returnDomain.setMess(returnDomain.getMess().replaceAll(",", "\uff0c").replaceAll(":", "\uff1a"));
        }
        this.domain.setRetJson(HstJsonUtil.beanToJson(returnDomain));
    }

    public String handleExceptionMessage(String code) throws Exception {
        String message = "";
        if (HstToolsUtil.isNullOrEmpty(code)) {
            return message;
        }
        message = AppServiceConstants.TAX_CODE_MESS_MAP.containsKey(code) ? AppServiceConstants.TAX_CODE_MESS_MAP.get(code) : (code.length() <= 2 ? "" : "\u672a\u5b9a\u4e49\u7684\u9519\u8bef\uff01");
        return message;
    }

    @Override
    @Resource(name="taxPublicQueryServiceImp")
    public void setService(BaseBusinessService service) {
        super.setService(service);
    }

    @Override
    public TaxCommonAppServiceDomain getDomain() {
        if (this.domain == null) {
            this.domain = new TaxCommonAppServiceDomain();
        }
        return this.domain;
    }

    public void setDomain(TaxCommonAppServiceDomain domain) {
        this.domain = domain;
    }

    public Gt3CommonAppService gt3Service() {
        return (Gt3CommonAppService)WebConstants.WEB_APP_CONTEXT.getBean("gt3CommonAppServiceImp");
    }
}
