/*
 * 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.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.Domain2Util;
import com.hst.common.util.HstJsonUtil;
import com.hst.common.util.HstWxServiceUtil;
import com.hst.framework.constants.AppServiceConstants;
import com.hst.framework.constants.WebConstants;
import com.hst.framework.util.HstToolsUtil;
import com.hst.taxService.action.TaxWxCommonAppAction;
import com.hst.taxService.service.TaxNsfwCommonAppService;
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/taxNsfwCommonApp", results={@Result(name="doService", type="json")})
public class TaxNsfwCommonAppAction
extends ExtendAction {
    private static final long serialVersionUID = 1L;
    public static Log _logger = LogFactory.getLog(TaxWxCommonAppAction.class);
    private TaxCommonAppServiceDomain domain;

    /*
     * Unable to fully structure code
     * Enabled aggressive block sorting
     * Enabled unnecessary exception pruning
     * Enabled aggressive exception aggregation
     */
    public String doService() throws Exception {
        block17: {
            service = (TaxNsfwCommonAppService)this.getService();
            appDomain = new BaseAppServiceDomain();
            returnDomain = new TaxCommonReturnDomain();
            errorDomain = null;
            ywId = this.getDomain().getYwId();
            psrJson = this.getDomain().getParmJson();
            TaxNsfwCommonAppAction._logger.info((Object)(String.valueOf(this.getDomain().getYwId()) + "------" + this.getDomain().getParmJson()));
            if (!WebConstants.TAX_ZFSZ_MAP.containsKey(ywId)) break block17;
            try {
                appDomain = Domain2Util.getAppServiceDomain(ywId, psrJson);
                if (appDomain == null) {
                    this.handleException(returnDomain, AppServiceConstants.TAX_JSONPARSE_ERROR);
                    return "doService";
                }
            }
            catch (Exception v0) {
                this.handleException(returnDomain, AppServiceConstants.TAX_JSONPARSE_ERROR);
                return "doService";
            }
            url = WebConstants.TAX_ZFSZ_MAP.get(ywId);
            returnDomain = Domain2Util.getDomain(ywId);
            returnDomain = HstWxServiceUtil.sendMess(url, appDomain, ywId, returnDomain.getClass());
            ** GOTO lbl54
        }
        try {
            appDomain = Domain2Util.getAppServiceDomain(ywId, psrJson);
            if (appDomain == null) {
                this.handleException(returnDomain, AppServiceConstants.TAX_JSONPARSE_ERROR);
                return "doService";
            }
        }
        catch (Exception v1) {
            this.handleException(returnDomain, AppServiceConstants.TAX_JSONPARSE_ERROR);
            return "doService";
        }
        try {
            serClass = service.getClass();
            methodName = ywId.substring(ywId.indexOf(".") + 1);
            method = serClass.getDeclaredMethod(methodName, new Class[]{appDomain.getClass()});
            returnDomain = (TaxCommonReturnDomain)method.invoke(serClass.newInstance(), new Object[]{appDomain});
            if (returnDomain == null) {
                returnDomain = new TaxCommonReturnDomain();
                this.handleException(returnDomain, AppServiceConstants.TAX_APP_ERROR);
                return "doService";
            }
            ** GOTO lbl54
        }
        catch (Exception e) {
            try {
                if (e.getCause() == null) {
                    e.printStackTrace();
                    errorDomain = this.handleException(e);
                } else {
                    TaxNsfwCommonAppAction._logger.debug((Object)e.getCause());
                    e.getCause().printStackTrace();
                    errorDomain = this.handleException((Exception)e.getCause());
                }
                this.handleServiceException(returnDomain, errorDomain.getCode(), errorDomain.getMess());
                return "doService";
lbl54:
                // 2 sources

                if (!AppServiceConstants.TAX_APP_SUCCESS.equals(returnDomain.getCode())) {
                    this.handleServiceException(returnDomain, returnDomain.getCode(), returnDomain.getMess());
                    return "doService";
                }
                try {
                    this.domain.setRetJson(HstJsonUtil.beanToJson(returnDomain));
                    return "doService";
                }
                catch (Exception v2) {
                    this.handleException(returnDomain, AppServiceConstants.TAX_BEAN_TO_JSON_ERROR);
                    return "doService";
                }
            }
            catch (Exception e) {
                errorDomain = this.handleException(e);
                this.handleException(returnDomain, errorDomain.getCode(), errorDomain.getMess());
            }
        }
        return "doService";
    }

    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);
        }
        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="taxNsfwAppCommonServiceImp")
    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;
    }
}
