package com.cidic.design;

import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.cidic.design.exception.DCException;
import com.cidic.design.exception.DcRedirectException;
import com.cidic.design.exception.ServerException;
import com.cidic.design.model.ResultModel;

public abstract class DcController {

	protected ResultModel resultModel = null;

	@ExceptionHandler(DCException.class)
	public @ResponseBody ResultModel handleDCException(DCException ex) {
		resultModel = new ResultModel();
		resultModel.setResultCode(ex.getErrCode());
		resultModel.setMessage(ex.getErrMsg());
		resultModel.setSuccess(false);
		return resultModel;
	}
	
	/**
	 * 处理权限异常
	 * @param ex
	 * @return
	 */
	@ExceptionHandler(UnauthorizedException.class)
	public @ResponseBody ResultModel handleUnauthorizedException(UnauthorizedException ex) {
		resultModel = new ResultModel();
		resultModel.setResultCode(900);
		resultModel.setMessage("无权限进行操作");
		resultModel.setSuccess(false);
		return resultModel;
	}
	
	@ExceptionHandler(DcRedirectException.class)
	public ModelAndView handlerDcRedirectException(DcRedirectException ex){
		ModelAndView modelView = new ModelAndView();
		resultModel = new ResultModel();
		resultModel.setResultCode(ex.getErrCode());
		resultModel.setMessage(ex.getErrMsg());
		resultModel.setSuccess(false);
		modelView.setViewName("error");
        return modelView;
	}
	
	@ExceptionHandler(ServerException.class)
	public ModelAndView handlerException(ServerException ex){
		ModelAndView modelView = new ModelAndView();
		resultModel = new ResultModel();
		resultModel.setResultCode(ex.getErrCode());
		resultModel.setMessage(ex.getErrMsg());
		resultModel.setSuccess(false);
		modelView.setViewName("error");
        return modelView;
	}
}

@@ -20,16 +20,70 @@
 esign;%0A%0A
+import org.apache.shiro.authz.AuthorizationException;%0A
 import o
@@ -1224,24 +1224,406 @@
 Model;%0A%09%7D%0A%09%0A
+%09%0A%09@ExceptionHandler(AuthorizationException.class)%0A%09public ModelAndView handleAuthorizationException(AuthorizationException ex) %7B%0A%09%09ModelAndView modelView = new ModelAndView();%0A%09%09resultModel = new ResultModel();%0A%09%09resultModel.setResultCode(911);%0A%09%09resultModel.setMessage(%22%E6%B2%A1%E6%9C%89%E8%BF%9B%E8%A1%8C%E8%BA%AB%E4%BB%BD%E8%AE%A4%E8%AF%81%22);%0A%09%09resultModel.setSuccess(false);%0A%09%09modelView.setViewName(%22error%22);%0A        return modelView;%0A%09%7D%0A%09%0A
 %09@ExceptionH

fix bugs