Commit 116efd96 by stylefeng

统一异常,把异常枚举抽象出一个接口

parent ea4b88a4
...@@ -3,7 +3,7 @@ package com.stylefeng.guns.common.constant.dictmap.factory; ...@@ -3,7 +3,7 @@ package com.stylefeng.guns.common.constant.dictmap.factory;
import com.stylefeng.guns.common.constant.factory.ConstantFactory; import com.stylefeng.guns.common.constant.factory.ConstantFactory;
import com.stylefeng.guns.common.constant.factory.IConstantFactory; import com.stylefeng.guns.common.constant.factory.IConstantFactory;
import com.stylefeng.guns.common.exception.BizExceptionEnum; import com.stylefeng.guns.common.exception.BizExceptionEnum;
import com.stylefeng.guns.common.exception.BussinessException; import com.stylefeng.guns.core.exception.GunsException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
...@@ -27,7 +27,7 @@ public class DictFieldWarpperFactory { ...@@ -27,7 +27,7 @@ public class DictFieldWarpperFactory {
Object result = method.invoke(me, Integer.parseInt(field.toString())); Object result = method.invoke(me, Integer.parseInt(field.toString()));
return result; return result;
} catch (Exception e1) { } catch (Exception e1) {
throw new BussinessException(BizExceptionEnum.ERROR_WRAPPER_FIELD); throw new GunsException(BizExceptionEnum.ERROR_WRAPPER_FIELD);
} }
} }
} }
......
package com.stylefeng.guns.common.exception; package com.stylefeng.guns.common.exception;
import com.stylefeng.guns.core.exception.ServiceExceptionEnum;
/** /**
* @Description 所有业务异常的枚举 * @Description 所有业务异常的枚举
* @author fengshuonan * @author fengshuonan
* @date 2016年11月12日 下午5:04:51 * @date 2016年11月12日 下午5:04:51
*/ */
public enum BizExceptionEnum { public enum BizExceptionEnum implements ServiceExceptionEnum{
/** /**
* 字典 * 字典
...@@ -54,44 +56,29 @@ public enum BizExceptionEnum { ...@@ -54,44 +56,29 @@ public enum BizExceptionEnum {
SERVER_ERROR(500, "服务器异常"); SERVER_ERROR(500, "服务器异常");
BizExceptionEnum(int code, String message) { BizExceptionEnum(int code, String message) {
this.friendlyCode = code; this.code = code;
this.friendlyMsg = message; this.message = message;
} }
BizExceptionEnum(int code, String message,String urlPath) { private Integer code;
this.friendlyCode = code;
this.friendlyMsg = message;
this.urlPath = urlPath;
}
private int friendlyCode; private String message;
private String friendlyMsg; @Override
public Integer getCode() {
private String urlPath; return code;
public int getCode() {
return friendlyCode;
} }
public void setCode(int code) { public void setCode(Integer code) {
this.friendlyCode = code; this.code = code;
} }
@Override
public String getMessage() { public String getMessage() {
return friendlyMsg; return message;
} }
public void setMessage(String message) { public void setMessage(String message) {
this.friendlyMsg = message; this.message = message;
} }
public String getUrlPath() {
return urlPath;
}
public void setUrlPath(String urlPath) {
this.urlPath = urlPath;
}
} }
package com.stylefeng.guns.common.exception;
import com.stylefeng.guns.core.exception.GunsException;
/**
* @author fengshuonan
* @Description 业务异常的封装
* @date 2016年11月12日 下午5:05:10
*/
public class BussinessException extends GunsException {
public BussinessException(BizExceptionEnum bizExceptionEnum) {
super(bizExceptionEnum.getCode(), bizExceptionEnum.getMessage(), bizExceptionEnum.getUrlPath());
}
}
package com.stylefeng.guns.core.aop; package com.stylefeng.guns.core.aop;
import com.stylefeng.guns.common.exception.BizExceptionEnum; import com.stylefeng.guns.common.exception.BizExceptionEnum;
import com.stylefeng.guns.common.exception.BussinessException;
import com.stylefeng.guns.common.exception.InvalidKaptchaException; import com.stylefeng.guns.common.exception.InvalidKaptchaException;
import com.stylefeng.guns.core.base.tips.ErrorTip; import com.stylefeng.guns.core.base.tips.ErrorTip;
import com.stylefeng.guns.core.exception.GunsException;
import com.stylefeng.guns.core.log.LogManager; import com.stylefeng.guns.core.log.LogManager;
import com.stylefeng.guns.core.log.factory.LogTaskFactory; import com.stylefeng.guns.core.log.factory.LogTaskFactory;
import com.stylefeng.guns.core.shiro.ShiroKit; import com.stylefeng.guns.core.shiro.ShiroKit;
...@@ -44,10 +44,10 @@ public class GlobalExceptionHandler { ...@@ -44,10 +44,10 @@ public class GlobalExceptionHandler {
* *
* @author fengshuonan * @author fengshuonan
*/ */
@ExceptionHandler(BussinessException.class) @ExceptionHandler(GunsException.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ResponseBody @ResponseBody
public ErrorTip notFount(BussinessException e) { public ErrorTip notFount(GunsException e) {
LogManager.me().executeLog(LogTaskFactory.exceptionLog(ShiroKit.getUser().getId(), e)); LogManager.me().executeLog(LogTaskFactory.exceptionLog(ShiroKit.getUser().getId(), e));
getRequest().setAttribute("tip", e.getMessage()); getRequest().setAttribute("tip", e.getMessage());
log.error("业务异常:", e); log.error("业务异常:", e);
......
...@@ -5,10 +5,10 @@ import com.stylefeng.guns.common.annotion.Permission; ...@@ -5,10 +5,10 @@ import com.stylefeng.guns.common.annotion.Permission;
import com.stylefeng.guns.common.constant.dictmap.DeptDict; import com.stylefeng.guns.common.constant.dictmap.DeptDict;
import com.stylefeng.guns.common.constant.factory.ConstantFactory; import com.stylefeng.guns.common.constant.factory.ConstantFactory;
import com.stylefeng.guns.common.exception.BizExceptionEnum; import com.stylefeng.guns.common.exception.BizExceptionEnum;
import com.stylefeng.guns.common.exception.BussinessException;
import com.stylefeng.guns.common.persistence.dao.DeptMapper; import com.stylefeng.guns.common.persistence.dao.DeptMapper;
import com.stylefeng.guns.common.persistence.model.Dept; import com.stylefeng.guns.common.persistence.model.Dept;
import com.stylefeng.guns.core.base.controller.BaseController; import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.exception.GunsException;
import com.stylefeng.guns.core.log.LogObjectHolder; import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.core.node.ZTreeNode; import com.stylefeng.guns.core.node.ZTreeNode;
import com.stylefeng.guns.core.util.ToolUtil; import com.stylefeng.guns.core.util.ToolUtil;
...@@ -96,7 +96,7 @@ public class DeptController extends BaseController { ...@@ -96,7 +96,7 @@ public class DeptController extends BaseController {
@ResponseBody @ResponseBody
public Object add(Dept dept) { public Object add(Dept dept) {
if (ToolUtil.isOneEmpty(dept, dept.getSimplename())) { if (ToolUtil.isOneEmpty(dept, dept.getSimplename())) {
throw new BussinessException(BizExceptionEnum.REQUEST_NULL); throw new GunsException(BizExceptionEnum.REQUEST_NULL);
} }
//完善pids,根据pid拿到pid的pids //完善pids,根据pid拿到pid的pids
deptSetPids(dept); deptSetPids(dept);
...@@ -133,7 +133,7 @@ public class DeptController extends BaseController { ...@@ -133,7 +133,7 @@ public class DeptController extends BaseController {
@ResponseBody @ResponseBody
public Object update(Dept dept) { public Object update(Dept dept) {
if (ToolUtil.isEmpty(dept) || dept.getId() == null) { if (ToolUtil.isEmpty(dept) || dept.getId() == null) {
throw new BussinessException(BizExceptionEnum.REQUEST_NULL); throw new GunsException(BizExceptionEnum.REQUEST_NULL);
} }
deptSetPids(dept); deptSetPids(dept);
deptMapper.updateById(dept); deptMapper.updateById(dept);
......
...@@ -7,10 +7,10 @@ import com.stylefeng.guns.common.constant.Const; ...@@ -7,10 +7,10 @@ import com.stylefeng.guns.common.constant.Const;
import com.stylefeng.guns.common.constant.dictmap.DictMap; import com.stylefeng.guns.common.constant.dictmap.DictMap;
import com.stylefeng.guns.common.constant.factory.ConstantFactory; import com.stylefeng.guns.common.constant.factory.ConstantFactory;
import com.stylefeng.guns.common.exception.BizExceptionEnum; import com.stylefeng.guns.common.exception.BizExceptionEnum;
import com.stylefeng.guns.common.exception.BussinessException;
import com.stylefeng.guns.common.persistence.dao.DictMapper; import com.stylefeng.guns.common.persistence.dao.DictMapper;
import com.stylefeng.guns.common.persistence.model.Dict; import com.stylefeng.guns.common.persistence.model.Dict;
import com.stylefeng.guns.core.base.controller.BaseController; import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.exception.GunsException;
import com.stylefeng.guns.core.log.LogObjectHolder; import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.core.util.ToolUtil; import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.system.dao.DictDao; import com.stylefeng.guns.modular.system.dao.DictDao;
...@@ -89,7 +89,7 @@ public class DictController extends BaseController { ...@@ -89,7 +89,7 @@ public class DictController extends BaseController {
@ResponseBody @ResponseBody
public Object add(String dictName, String dictValues) { public Object add(String dictName, String dictValues) {
if (ToolUtil.isOneEmpty(dictName, dictValues)) { if (ToolUtil.isOneEmpty(dictName, dictValues)) {
throw new BussinessException(BizExceptionEnum.REQUEST_NULL); throw new GunsException(BizExceptionEnum.REQUEST_NULL);
} }
this.dictService.addDict(dictName, dictValues); this.dictService.addDict(dictName, dictValues);
return SUCCESS_TIP; return SUCCESS_TIP;
...@@ -125,7 +125,7 @@ public class DictController extends BaseController { ...@@ -125,7 +125,7 @@ public class DictController extends BaseController {
@ResponseBody @ResponseBody
public Object update(Integer dictId, String dictName, String dictValues) { public Object update(Integer dictId, String dictName, String dictValues) {
if (ToolUtil.isOneEmpty(dictId, dictName, dictValues)) { if (ToolUtil.isOneEmpty(dictId, dictName, dictValues)) {
throw new BussinessException(BizExceptionEnum.REQUEST_NULL); throw new GunsException(BizExceptionEnum.REQUEST_NULL);
} }
dictService.editDict(dictId, dictName, dictValues); dictService.editDict(dictId, dictName, dictValues);
return super.SUCCESS_TIP; return super.SUCCESS_TIP;
......
...@@ -7,11 +7,11 @@ import com.stylefeng.guns.common.constant.dictmap.MenuDict; ...@@ -7,11 +7,11 @@ import com.stylefeng.guns.common.constant.dictmap.MenuDict;
import com.stylefeng.guns.common.constant.factory.ConstantFactory; import com.stylefeng.guns.common.constant.factory.ConstantFactory;
import com.stylefeng.guns.common.constant.state.MenuStatus; import com.stylefeng.guns.common.constant.state.MenuStatus;
import com.stylefeng.guns.common.exception.BizExceptionEnum; import com.stylefeng.guns.common.exception.BizExceptionEnum;
import com.stylefeng.guns.common.exception.BussinessException;
import com.stylefeng.guns.common.persistence.dao.MenuMapper; import com.stylefeng.guns.common.persistence.dao.MenuMapper;
import com.stylefeng.guns.common.persistence.model.Menu; import com.stylefeng.guns.common.persistence.model.Menu;
import com.stylefeng.guns.core.base.controller.BaseController; import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.base.tips.Tip; import com.stylefeng.guns.core.base.tips.Tip;
import com.stylefeng.guns.core.exception.GunsException;
import com.stylefeng.guns.core.log.LogObjectHolder; import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.core.node.ZTreeNode; import com.stylefeng.guns.core.node.ZTreeNode;
import com.stylefeng.guns.core.support.BeanKit; import com.stylefeng.guns.core.support.BeanKit;
...@@ -76,7 +76,7 @@ public class MenuController extends BaseController { ...@@ -76,7 +76,7 @@ public class MenuController extends BaseController {
@RequestMapping(value = "/menu_edit/{menuId}") @RequestMapping(value = "/menu_edit/{menuId}")
public String menuEdit(@PathVariable Long menuId, Model model) { public String menuEdit(@PathVariable Long menuId, Model model) {
if (ToolUtil.isEmpty(menuId)) { if (ToolUtil.isEmpty(menuId)) {
throw new BussinessException(BizExceptionEnum.REQUEST_NULL); throw new GunsException(BizExceptionEnum.REQUEST_NULL);
} }
Menu menu = this.menuMapper.selectById(menuId); Menu menu = this.menuMapper.selectById(menuId);
...@@ -109,7 +109,7 @@ public class MenuController extends BaseController { ...@@ -109,7 +109,7 @@ public class MenuController extends BaseController {
@ResponseBody @ResponseBody
public Tip edit(@Valid Menu menu, BindingResult result) { public Tip edit(@Valid Menu menu, BindingResult result) {
if (result.hasErrors()) { if (result.hasErrors()) {
throw new BussinessException(BizExceptionEnum.REQUEST_NULL); throw new GunsException(BizExceptionEnum.REQUEST_NULL);
} }
//设置父级菜单编号 //设置父级菜单编号
menuSetPcode(menu); menuSetPcode(menu);
...@@ -138,13 +138,13 @@ public class MenuController extends BaseController { ...@@ -138,13 +138,13 @@ public class MenuController extends BaseController {
@ResponseBody @ResponseBody
public Tip add(@Valid Menu menu, BindingResult result) { public Tip add(@Valid Menu menu, BindingResult result) {
if (result.hasErrors()) { if (result.hasErrors()) {
throw new BussinessException(BizExceptionEnum.REQUEST_NULL); throw new GunsException(BizExceptionEnum.REQUEST_NULL);
} }
//判断是否存在该编号 //判断是否存在该编号
String existedMenuName = ConstantFactory.me().getMenuNameByCode(menu.getCode()); String existedMenuName = ConstantFactory.me().getMenuNameByCode(menu.getCode());
if (ToolUtil.isNotEmpty(existedMenuName)) { if (ToolUtil.isNotEmpty(existedMenuName)) {
throw new BussinessException(BizExceptionEnum.EXISTED_THE_MENU); throw new GunsException(BizExceptionEnum.EXISTED_THE_MENU);
} }
//设置父级菜单编号 //设置父级菜单编号
...@@ -164,7 +164,7 @@ public class MenuController extends BaseController { ...@@ -164,7 +164,7 @@ public class MenuController extends BaseController {
@ResponseBody @ResponseBody
public Tip remove(@RequestParam Long menuId) { public Tip remove(@RequestParam Long menuId) {
if (ToolUtil.isEmpty(menuId)) { if (ToolUtil.isEmpty(menuId)) {
throw new BussinessException(BizExceptionEnum.REQUEST_NULL); throw new GunsException(BizExceptionEnum.REQUEST_NULL);
} }
//缓存菜单的名称 //缓存菜单的名称
...@@ -181,7 +181,7 @@ public class MenuController extends BaseController { ...@@ -181,7 +181,7 @@ public class MenuController extends BaseController {
@ResponseBody @ResponseBody
public Tip view(@PathVariable Long menuId) { public Tip view(@PathVariable Long menuId) {
if (ToolUtil.isEmpty(menuId)) { if (ToolUtil.isEmpty(menuId)) {
throw new BussinessException(BizExceptionEnum.REQUEST_NULL); throw new GunsException(BizExceptionEnum.REQUEST_NULL);
} }
this.menuMapper.selectById(menuId); this.menuMapper.selectById(menuId);
return SUCCESS_TIP; return SUCCESS_TIP;
...@@ -240,7 +240,7 @@ public class MenuController extends BaseController { ...@@ -240,7 +240,7 @@ public class MenuController extends BaseController {
//如果编号和父编号一致会导致无限递归 //如果编号和父编号一致会导致无限递归
if (menu.getCode().equals(menu.getPcode())) { if (menu.getCode().equals(menu.getPcode())) {
throw new BussinessException(BizExceptionEnum.MENU_PCODE_COINCIDENCE); throw new GunsException(BizExceptionEnum.MENU_PCODE_COINCIDENCE);
} }
menu.setLevels(pLevels + 1); menu.setLevels(pLevels + 1);
......
...@@ -4,10 +4,10 @@ import com.stylefeng.guns.common.annotion.BussinessLog; ...@@ -4,10 +4,10 @@ import com.stylefeng.guns.common.annotion.BussinessLog;
import com.stylefeng.guns.common.constant.dictmap.NoticeMap; import com.stylefeng.guns.common.constant.dictmap.NoticeMap;
import com.stylefeng.guns.common.constant.factory.ConstantFactory; import com.stylefeng.guns.common.constant.factory.ConstantFactory;
import com.stylefeng.guns.common.exception.BizExceptionEnum; import com.stylefeng.guns.common.exception.BizExceptionEnum;
import com.stylefeng.guns.common.exception.BussinessException;
import com.stylefeng.guns.common.persistence.dao.NoticeMapper; import com.stylefeng.guns.common.persistence.dao.NoticeMapper;
import com.stylefeng.guns.common.persistence.model.Notice; import com.stylefeng.guns.common.persistence.model.Notice;
import com.stylefeng.guns.core.base.controller.BaseController; import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.exception.GunsException;
import com.stylefeng.guns.core.log.LogObjectHolder; import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.core.shiro.ShiroKit; import com.stylefeng.guns.core.shiro.ShiroKit;
import com.stylefeng.guns.core.util.ToolUtil; import com.stylefeng.guns.core.util.ToolUtil;
...@@ -98,7 +98,7 @@ public class NoticeController extends BaseController { ...@@ -98,7 +98,7 @@ public class NoticeController extends BaseController {
@BussinessLog(value = "新增通知",key = "title",dict = NoticeMap.class) @BussinessLog(value = "新增通知",key = "title",dict = NoticeMap.class)
public Object add(Notice notice) { public Object add(Notice notice) {
if (ToolUtil.isOneEmpty(notice, notice.getTitle(), notice.getContent())) { if (ToolUtil.isOneEmpty(notice, notice.getTitle(), notice.getContent())) {
throw new BussinessException(BizExceptionEnum.REQUEST_NULL); throw new GunsException(BizExceptionEnum.REQUEST_NULL);
} }
notice.setCreater(ShiroKit.getUser().getId()); notice.setCreater(ShiroKit.getUser().getId());
notice.setCreatetime(new Date()); notice.setCreatetime(new Date());
...@@ -130,7 +130,7 @@ public class NoticeController extends BaseController { ...@@ -130,7 +130,7 @@ public class NoticeController extends BaseController {
@BussinessLog(value = "修改通知",key = "title",dict = NoticeMap.class) @BussinessLog(value = "修改通知",key = "title",dict = NoticeMap.class)
public Object update(Notice notice) { public Object update(Notice notice) {
if (ToolUtil.isOneEmpty(notice, notice.getId(), notice.getTitle(), notice.getContent())) { if (ToolUtil.isOneEmpty(notice, notice.getId(), notice.getTitle(), notice.getContent())) {
throw new BussinessException(BizExceptionEnum.REQUEST_NULL); throw new GunsException(BizExceptionEnum.REQUEST_NULL);
} }
Notice old = this.noticeMapper.selectById(notice.getId()); Notice old = this.noticeMapper.selectById(notice.getId());
old.setTitle(notice.getTitle()); old.setTitle(notice.getTitle());
......
...@@ -7,7 +7,6 @@ import com.stylefeng.guns.common.constant.cache.Cache; ...@@ -7,7 +7,6 @@ import com.stylefeng.guns.common.constant.cache.Cache;
import com.stylefeng.guns.common.constant.dictmap.RoleDict; import com.stylefeng.guns.common.constant.dictmap.RoleDict;
import com.stylefeng.guns.common.constant.factory.ConstantFactory; import com.stylefeng.guns.common.constant.factory.ConstantFactory;
import com.stylefeng.guns.common.exception.BizExceptionEnum; import com.stylefeng.guns.common.exception.BizExceptionEnum;
import com.stylefeng.guns.common.exception.BussinessException;
import com.stylefeng.guns.common.persistence.dao.RoleMapper; import com.stylefeng.guns.common.persistence.dao.RoleMapper;
import com.stylefeng.guns.common.persistence.dao.UserMapper; import com.stylefeng.guns.common.persistence.dao.UserMapper;
import com.stylefeng.guns.common.persistence.model.Role; import com.stylefeng.guns.common.persistence.model.Role;
...@@ -15,6 +14,7 @@ import com.stylefeng.guns.common.persistence.model.User; ...@@ -15,6 +14,7 @@ import com.stylefeng.guns.common.persistence.model.User;
import com.stylefeng.guns.core.base.controller.BaseController; import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.base.tips.Tip; import com.stylefeng.guns.core.base.tips.Tip;
import com.stylefeng.guns.core.cache.CacheKit; import com.stylefeng.guns.core.cache.CacheKit;
import com.stylefeng.guns.core.exception.GunsException;
import com.stylefeng.guns.core.log.LogObjectHolder; import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.core.node.ZTreeNode; import com.stylefeng.guns.core.node.ZTreeNode;
import com.stylefeng.guns.core.util.Convert; import com.stylefeng.guns.core.util.Convert;
...@@ -82,7 +82,7 @@ public class RoleController extends BaseController { ...@@ -82,7 +82,7 @@ public class RoleController extends BaseController {
@RequestMapping(value = "/role_edit/{roleId}") @RequestMapping(value = "/role_edit/{roleId}")
public String roleEdit(@PathVariable Integer roleId, Model model) { public String roleEdit(@PathVariable Integer roleId, Model model) {
if (ToolUtil.isEmpty(roleId)) { if (ToolUtil.isEmpty(roleId)) {
throw new BussinessException(BizExceptionEnum.REQUEST_NULL); throw new GunsException(BizExceptionEnum.REQUEST_NULL);
} }
Role role = this.roleMapper.selectById(roleId); Role role = this.roleMapper.selectById(roleId);
model.addAttribute(role); model.addAttribute(role);
...@@ -99,7 +99,7 @@ public class RoleController extends BaseController { ...@@ -99,7 +99,7 @@ public class RoleController extends BaseController {
@RequestMapping(value = "/role_assign/{roleId}") @RequestMapping(value = "/role_assign/{roleId}")
public String roleAssign(@PathVariable("roleId") Integer roleId, Model model) { public String roleAssign(@PathVariable("roleId") Integer roleId, Model model) {
if (ToolUtil.isEmpty(roleId)) { if (ToolUtil.isEmpty(roleId)) {
throw new BussinessException(BizExceptionEnum.REQUEST_NULL); throw new GunsException(BizExceptionEnum.REQUEST_NULL);
} }
model.addAttribute("roleId", roleId); model.addAttribute("roleId", roleId);
model.addAttribute("roleName", ConstantFactory.me().getSingleRoleName(roleId)); model.addAttribute("roleName", ConstantFactory.me().getSingleRoleName(roleId));
...@@ -126,7 +126,7 @@ public class RoleController extends BaseController { ...@@ -126,7 +126,7 @@ public class RoleController extends BaseController {
@ResponseBody @ResponseBody
public Tip add(@Valid Role role, BindingResult result) { public Tip add(@Valid Role role, BindingResult result) {
if (result.hasErrors()) { if (result.hasErrors()) {
throw new BussinessException(BizExceptionEnum.REQUEST_NULL); throw new GunsException(BizExceptionEnum.REQUEST_NULL);
} }
role.setId(null); role.setId(null);
this.roleMapper.insert(role); this.roleMapper.insert(role);
...@@ -142,7 +142,7 @@ public class RoleController extends BaseController { ...@@ -142,7 +142,7 @@ public class RoleController extends BaseController {
@ResponseBody @ResponseBody
public Tip edit(@Valid Role role, BindingResult result) { public Tip edit(@Valid Role role, BindingResult result) {
if (result.hasErrors()) { if (result.hasErrors()) {
throw new BussinessException(BizExceptionEnum.REQUEST_NULL); throw new GunsException(BizExceptionEnum.REQUEST_NULL);
} }
this.roleMapper.updateById(role); this.roleMapper.updateById(role);
...@@ -160,12 +160,12 @@ public class RoleController extends BaseController { ...@@ -160,12 +160,12 @@ public class RoleController extends BaseController {
@ResponseBody @ResponseBody
public Tip remove(@RequestParam Integer roleId) { public Tip remove(@RequestParam Integer roleId) {
if (ToolUtil.isEmpty(roleId)) { if (ToolUtil.isEmpty(roleId)) {
throw new BussinessException(BizExceptionEnum.REQUEST_NULL); throw new GunsException(BizExceptionEnum.REQUEST_NULL);
} }
//不能删除超级管理员角色 //不能删除超级管理员角色
if(roleId.equals(Const.ADMIN_ROLE_ID)){ if(roleId.equals(Const.ADMIN_ROLE_ID)){
throw new BussinessException(BizExceptionEnum.CANT_DELETE_ADMIN); throw new GunsException(BizExceptionEnum.CANT_DELETE_ADMIN);
} }
//缓存被删除的角色名称 //缓存被删除的角色名称
...@@ -185,7 +185,7 @@ public class RoleController extends BaseController { ...@@ -185,7 +185,7 @@ public class RoleController extends BaseController {
@ResponseBody @ResponseBody
public Tip view(@PathVariable Integer roleId) { public Tip view(@PathVariable Integer roleId) {
if (ToolUtil.isEmpty(roleId)) { if (ToolUtil.isEmpty(roleId)) {
throw new BussinessException(BizExceptionEnum.REQUEST_NULL); throw new GunsException(BizExceptionEnum.REQUEST_NULL);
} }
this.roleMapper.selectById(roleId); this.roleMapper.selectById(roleId);
return SUCCESS_TIP; return SUCCESS_TIP;
...@@ -200,7 +200,7 @@ public class RoleController extends BaseController { ...@@ -200,7 +200,7 @@ public class RoleController extends BaseController {
@ResponseBody @ResponseBody
public Tip setAuthority(@RequestParam("roleId") Integer roleId, @RequestParam("ids") String ids) { public Tip setAuthority(@RequestParam("roleId") Integer roleId, @RequestParam("ids") String ids) {
if (ToolUtil.isOneEmpty(roleId)) { if (ToolUtil.isOneEmpty(roleId)) {
throw new BussinessException(BizExceptionEnum.REQUEST_NULL); throw new GunsException(BizExceptionEnum.REQUEST_NULL);
} }
this.roleService.setAuthority(roleId, ids); this.roleService.setAuthority(roleId, ids);
return SUCCESS_TIP; return SUCCESS_TIP;
......
...@@ -7,7 +7,6 @@ import com.stylefeng.guns.common.constant.dictmap.UserDict; ...@@ -7,7 +7,6 @@ import com.stylefeng.guns.common.constant.dictmap.UserDict;
import com.stylefeng.guns.common.constant.factory.ConstantFactory; import com.stylefeng.guns.common.constant.factory.ConstantFactory;
import com.stylefeng.guns.common.constant.state.ManagerStatus; import com.stylefeng.guns.common.constant.state.ManagerStatus;
import com.stylefeng.guns.common.exception.BizExceptionEnum; import com.stylefeng.guns.common.exception.BizExceptionEnum;
import com.stylefeng.guns.common.exception.BussinessException;
import com.stylefeng.guns.common.persistence.dao.UserMapper; import com.stylefeng.guns.common.persistence.dao.UserMapper;
import com.stylefeng.guns.common.persistence.model.User; import com.stylefeng.guns.common.persistence.model.User;
import com.stylefeng.guns.config.properties.GunsProperties; import com.stylefeng.guns.config.properties.GunsProperties;
...@@ -15,6 +14,7 @@ import com.stylefeng.guns.core.base.controller.BaseController; ...@@ -15,6 +14,7 @@ import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.base.tips.Tip; import com.stylefeng.guns.core.base.tips.Tip;
import com.stylefeng.guns.core.datascope.DataScope; import com.stylefeng.guns.core.datascope.DataScope;
import com.stylefeng.guns.core.db.Db; import com.stylefeng.guns.core.db.Db;
import com.stylefeng.guns.core.exception.GunsException;
import com.stylefeng.guns.core.log.LogObjectHolder; import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.core.shiro.ShiroKit; import com.stylefeng.guns.core.shiro.ShiroKit;
import com.stylefeng.guns.core.shiro.ShiroUser; import com.stylefeng.guns.core.shiro.ShiroUser;
...@@ -83,7 +83,7 @@ public class UserMgrController extends BaseController { ...@@ -83,7 +83,7 @@ public class UserMgrController extends BaseController {
@RequestMapping("/role_assign/{userId}") @RequestMapping("/role_assign/{userId}")
public String roleAssign(@PathVariable Integer userId, Model model) { public String roleAssign(@PathVariable Integer userId, Model model) {
if (ToolUtil.isEmpty(userId)) { if (ToolUtil.isEmpty(userId)) {
throw new BussinessException(BizExceptionEnum.REQUEST_NULL); throw new GunsException(BizExceptionEnum.REQUEST_NULL);
} }
User user = (User) Db.create(UserMapper.class).selectOneByCon("id", userId); User user = (User) Db.create(UserMapper.class).selectOneByCon("id", userId);
model.addAttribute("userId", userId); model.addAttribute("userId", userId);
...@@ -98,7 +98,7 @@ public class UserMgrController extends BaseController { ...@@ -98,7 +98,7 @@ public class UserMgrController extends BaseController {
@RequestMapping("/user_edit/{userId}") @RequestMapping("/user_edit/{userId}")
public String userEdit(@PathVariable Integer userId, Model model) { public String userEdit(@PathVariable Integer userId, Model model) {
if (ToolUtil.isEmpty(userId)) { if (ToolUtil.isEmpty(userId)) {
throw new BussinessException(BizExceptionEnum.REQUEST_NULL); throw new GunsException(BizExceptionEnum.REQUEST_NULL);
} }
assertAuth(userId); assertAuth(userId);
User user = this.userMapper.selectById(userId); User user = this.userMapper.selectById(userId);
...@@ -116,7 +116,7 @@ public class UserMgrController extends BaseController { ...@@ -116,7 +116,7 @@ public class UserMgrController extends BaseController {
public String userInfo(Model model) { public String userInfo(Model model) {
Integer userId = ShiroKit.getUser().getId(); Integer userId = ShiroKit.getUser().getId();
if (ToolUtil.isEmpty(userId)) { if (ToolUtil.isEmpty(userId)) {
throw new BussinessException(BizExceptionEnum.REQUEST_NULL); throw new GunsException(BizExceptionEnum.REQUEST_NULL);
} }
User user = this.userMapper.selectById(userId); User user = this.userMapper.selectById(userId);
model.addAttribute(user); model.addAttribute(user);
...@@ -141,7 +141,7 @@ public class UserMgrController extends BaseController { ...@@ -141,7 +141,7 @@ public class UserMgrController extends BaseController {
@ResponseBody @ResponseBody
public Object changePwd(@RequestParam String oldPwd, @RequestParam String newPwd, @RequestParam String rePwd) { public Object changePwd(@RequestParam String oldPwd, @RequestParam String newPwd, @RequestParam String rePwd) {
if (!newPwd.equals(rePwd)) { if (!newPwd.equals(rePwd)) {
throw new BussinessException(BizExceptionEnum.TWO_PWD_NOT_MATCH); throw new GunsException(BizExceptionEnum.TWO_PWD_NOT_MATCH);
} }
Integer userId = ShiroKit.getUser().getId(); Integer userId = ShiroKit.getUser().getId();
User user = userMapper.selectById(userId); User user = userMapper.selectById(userId);
...@@ -152,7 +152,7 @@ public class UserMgrController extends BaseController { ...@@ -152,7 +152,7 @@ public class UserMgrController extends BaseController {
user.updateById(); user.updateById();
return SUCCESS_TIP; return SUCCESS_TIP;
} else { } else {
throw new BussinessException(BizExceptionEnum.OLD_PWD_NOT_RIGHT); throw new GunsException(BizExceptionEnum.OLD_PWD_NOT_RIGHT);
} }
} }
...@@ -182,13 +182,13 @@ public class UserMgrController extends BaseController { ...@@ -182,13 +182,13 @@ public class UserMgrController extends BaseController {
@ResponseBody @ResponseBody
public Tip add(@Valid UserDto user, BindingResult result) { public Tip add(@Valid UserDto user, BindingResult result) {
if (result.hasErrors()) { if (result.hasErrors()) {
throw new BussinessException(BizExceptionEnum.REQUEST_NULL); throw new GunsException(BizExceptionEnum.REQUEST_NULL);
} }
// 判断账号是否重复 // 判断账号是否重复
User theUser = managerDao.getByAccount(user.getAccount()); User theUser = managerDao.getByAccount(user.getAccount());
if (theUser != null) { if (theUser != null) {
throw new BussinessException(BizExceptionEnum.USER_ALREADY_REG); throw new GunsException(BizExceptionEnum.USER_ALREADY_REG);
} }
// 完善账号信息 // 完善账号信息
...@@ -211,7 +211,7 @@ public class UserMgrController extends BaseController { ...@@ -211,7 +211,7 @@ public class UserMgrController extends BaseController {
@ResponseBody @ResponseBody
public Tip edit(@Valid UserDto user, BindingResult result) throws NoPermissionException { public Tip edit(@Valid UserDto user, BindingResult result) throws NoPermissionException {
if (result.hasErrors()) { if (result.hasErrors()) {
throw new BussinessException(BizExceptionEnum.REQUEST_NULL); throw new GunsException(BizExceptionEnum.REQUEST_NULL);
} }
if (ShiroKit.hasRole(Const.ADMIN_NAME)) { if (ShiroKit.hasRole(Const.ADMIN_NAME)) {
this.userMapper.updateById(UserFactory.createUser(user)); this.userMapper.updateById(UserFactory.createUser(user));
...@@ -223,7 +223,7 @@ public class UserMgrController extends BaseController { ...@@ -223,7 +223,7 @@ public class UserMgrController extends BaseController {
this.userMapper.updateById(UserFactory.createUser(user)); this.userMapper.updateById(UserFactory.createUser(user));
return SUCCESS_TIP; return SUCCESS_TIP;
} else { } else {
throw new BussinessException(BizExceptionEnum.NO_PERMITION); throw new GunsException(BizExceptionEnum.NO_PERMITION);
} }
} }
} }
...@@ -237,11 +237,11 @@ public class UserMgrController extends BaseController { ...@@ -237,11 +237,11 @@ public class UserMgrController extends BaseController {
@ResponseBody @ResponseBody
public Tip delete(@RequestParam Integer userId) { public Tip delete(@RequestParam Integer userId) {
if (ToolUtil.isEmpty(userId)) { if (ToolUtil.isEmpty(userId)) {
throw new BussinessException(BizExceptionEnum.REQUEST_NULL); throw new GunsException(BizExceptionEnum.REQUEST_NULL);
} }
//不能删除超级管理员 //不能删除超级管理员
if (userId.equals(Const.ADMIN_ID)) { if (userId.equals(Const.ADMIN_ID)) {
throw new BussinessException(BizExceptionEnum.CANT_DELETE_ADMIN); throw new GunsException(BizExceptionEnum.CANT_DELETE_ADMIN);
} }
assertAuth(userId); assertAuth(userId);
this.managerDao.setStatus(userId, ManagerStatus.DELETED.getCode()); this.managerDao.setStatus(userId, ManagerStatus.DELETED.getCode());
...@@ -255,7 +255,7 @@ public class UserMgrController extends BaseController { ...@@ -255,7 +255,7 @@ public class UserMgrController extends BaseController {
@ResponseBody @ResponseBody
public User view(@PathVariable Integer userId) { public User view(@PathVariable Integer userId) {
if (ToolUtil.isEmpty(userId)) { if (ToolUtil.isEmpty(userId)) {
throw new BussinessException(BizExceptionEnum.REQUEST_NULL); throw new GunsException(BizExceptionEnum.REQUEST_NULL);
} }
assertAuth(userId); assertAuth(userId);
return this.userMapper.selectById(userId); return this.userMapper.selectById(userId);
...@@ -270,7 +270,7 @@ public class UserMgrController extends BaseController { ...@@ -270,7 +270,7 @@ public class UserMgrController extends BaseController {
@ResponseBody @ResponseBody
public Tip reset(@RequestParam Integer userId) { public Tip reset(@RequestParam Integer userId) {
if (ToolUtil.isEmpty(userId)) { if (ToolUtil.isEmpty(userId)) {
throw new BussinessException(BizExceptionEnum.REQUEST_NULL); throw new GunsException(BizExceptionEnum.REQUEST_NULL);
} }
assertAuth(userId); assertAuth(userId);
User user = this.userMapper.selectById(userId); User user = this.userMapper.selectById(userId);
...@@ -289,11 +289,11 @@ public class UserMgrController extends BaseController { ...@@ -289,11 +289,11 @@ public class UserMgrController extends BaseController {
@ResponseBody @ResponseBody
public Tip freeze(@RequestParam Integer userId) { public Tip freeze(@RequestParam Integer userId) {
if (ToolUtil.isEmpty(userId)) { if (ToolUtil.isEmpty(userId)) {
throw new BussinessException(BizExceptionEnum.REQUEST_NULL); throw new GunsException(BizExceptionEnum.REQUEST_NULL);
} }
//不能冻结超级管理员 //不能冻结超级管理员
if (userId.equals(Const.ADMIN_ID)) { if (userId.equals(Const.ADMIN_ID)) {
throw new BussinessException(BizExceptionEnum.CANT_FREEZE_ADMIN); throw new GunsException(BizExceptionEnum.CANT_FREEZE_ADMIN);
} }
assertAuth(userId); assertAuth(userId);
this.managerDao.setStatus(userId, ManagerStatus.FREEZED.getCode()); this.managerDao.setStatus(userId, ManagerStatus.FREEZED.getCode());
...@@ -309,7 +309,7 @@ public class UserMgrController extends BaseController { ...@@ -309,7 +309,7 @@ public class UserMgrController extends BaseController {
@ResponseBody @ResponseBody
public Tip unfreeze(@RequestParam Integer userId) { public Tip unfreeze(@RequestParam Integer userId) {
if (ToolUtil.isEmpty(userId)) { if (ToolUtil.isEmpty(userId)) {
throw new BussinessException(BizExceptionEnum.REQUEST_NULL); throw new GunsException(BizExceptionEnum.REQUEST_NULL);
} }
assertAuth(userId); assertAuth(userId);
this.managerDao.setStatus(userId, ManagerStatus.OK.getCode()); this.managerDao.setStatus(userId, ManagerStatus.OK.getCode());
...@@ -325,11 +325,11 @@ public class UserMgrController extends BaseController { ...@@ -325,11 +325,11 @@ public class UserMgrController extends BaseController {
@ResponseBody @ResponseBody
public Tip setRole(@RequestParam("userId") Integer userId, @RequestParam("roleIds") String roleIds) { public Tip setRole(@RequestParam("userId") Integer userId, @RequestParam("roleIds") String roleIds) {
if (ToolUtil.isOneEmpty(userId, roleIds)) { if (ToolUtil.isOneEmpty(userId, roleIds)) {
throw new BussinessException(BizExceptionEnum.REQUEST_NULL); throw new GunsException(BizExceptionEnum.REQUEST_NULL);
} }
//不能修改超级管理员 //不能修改超级管理员
if (userId.equals(Const.ADMIN_ID)) { if (userId.equals(Const.ADMIN_ID)) {
throw new BussinessException(BizExceptionEnum.CANT_CHANGE_ADMIN); throw new GunsException(BizExceptionEnum.CANT_CHANGE_ADMIN);
} }
assertAuth(userId); assertAuth(userId);
this.managerDao.setRoles(userId, roleIds); this.managerDao.setRoles(userId, roleIds);
...@@ -347,7 +347,7 @@ public class UserMgrController extends BaseController { ...@@ -347,7 +347,7 @@ public class UserMgrController extends BaseController {
String fileSavePath = gunsProperties.getFileUploadPath(); String fileSavePath = gunsProperties.getFileUploadPath();
picture.transferTo(new File(fileSavePath + pictureName)); picture.transferTo(new File(fileSavePath + pictureName));
} catch (Exception e) { } catch (Exception e) {
throw new BussinessException(BizExceptionEnum.UPLOAD_ERROR); throw new GunsException(BizExceptionEnum.UPLOAD_ERROR);
} }
return pictureName; return pictureName;
} }
...@@ -365,7 +365,7 @@ public class UserMgrController extends BaseController { ...@@ -365,7 +365,7 @@ public class UserMgrController extends BaseController {
if (deptDataScope.contains(deptid)) { if (deptDataScope.contains(deptid)) {
return; return;
} else { } else {
throw new BussinessException(BizExceptionEnum.NO_PERMITION); throw new GunsException(BizExceptionEnum.NO_PERMITION);
} }
} }
......
...@@ -3,11 +3,11 @@ package com.stylefeng.guns.modular.system.service.impl; ...@@ -3,11 +3,11 @@ package com.stylefeng.guns.modular.system.service.impl;
import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper; import com.baomidou.mybatisplus.mapper.Wrapper;
import com.stylefeng.guns.common.exception.BizExceptionEnum; import com.stylefeng.guns.common.exception.BizExceptionEnum;
import com.stylefeng.guns.common.exception.BussinessException;
import com.stylefeng.guns.modular.system.dao.DictDao;
import com.stylefeng.guns.modular.system.service.IDictService;
import com.stylefeng.guns.common.persistence.dao.DictMapper; import com.stylefeng.guns.common.persistence.dao.DictMapper;
import com.stylefeng.guns.common.persistence.model.Dict; import com.stylefeng.guns.common.persistence.model.Dict;
import com.stylefeng.guns.core.exception.GunsException;
import com.stylefeng.guns.modular.system.dao.DictDao;
import com.stylefeng.guns.modular.system.service.IDictService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -32,7 +32,7 @@ public class DictServiceImpl implements IDictService { ...@@ -32,7 +32,7 @@ public class DictServiceImpl implements IDictService {
//判断有没有该字典 //判断有没有该字典
List<Dict> dicts = dictMapper.selectList(new EntityWrapper<Dict>().eq("name", dictName).and().eq("pid", 0)); List<Dict> dicts = dictMapper.selectList(new EntityWrapper<Dict>().eq("name", dictName).and().eq("pid", 0));
if(dicts != null && dicts.size() > 0){ if(dicts != null && dicts.size() > 0){
throw new BussinessException(BizExceptionEnum.DICT_EXISTED); throw new GunsException(BizExceptionEnum.DICT_EXISTED);
} }
//解析dictValues //解析dictValues
...@@ -55,7 +55,7 @@ public class DictServiceImpl implements IDictService { ...@@ -55,7 +55,7 @@ public class DictServiceImpl implements IDictService {
try { try {
itemDict.setNum(Integer.valueOf(num)); itemDict.setNum(Integer.valueOf(num));
}catch (NumberFormatException e){ }catch (NumberFormatException e){
throw new BussinessException(BizExceptionEnum.DICT_MUST_BE_NUMBER); throw new GunsException(BizExceptionEnum.DICT_MUST_BE_NUMBER);
} }
this.dictMapper.insert(itemDict); this.dictMapper.insert(itemDict);
} }
......
...@@ -15,7 +15,7 @@ guns: ...@@ -15,7 +15,7 @@ guns:
################### 项目启动端口 ################### ################### 项目启动端口 ###################
server: server:
port: 80 port: 8080
################### beetl配置 ################### ################### beetl配置 ###################
beetl: beetl:
......
package com.stylefeng.guns.core.exception; package com.stylefeng.guns.core.exception;
/** /**
* 封装guns的异常
*
* @author fengshuonan * @author fengshuonan
* @Description 业务异常的封装 * @Date 2017/12/28 下午10:32
* @date 2016年11月12日 下午5:05:10
*/ */
public class GunsException extends RuntimeException { public class GunsException extends RuntimeException {
//友好提示的code码 private Integer code;
protected int friendlyCode;
//友好提示 private String message;
protected String friendlyMsg;
//业务异常跳转的页面 public GunsException(ServiceExceptionEnum serviceExceptionEnum) {
protected String urlPath; this.code = serviceExceptionEnum.getCode();
this.message = serviceExceptionEnum.getMessage();
}
protected GunsException(int friendlyCode, String friendlyMsg, String urlPath) { public Integer getCode() {
this.setValues(friendlyCode, friendlyMsg, urlPath); return code;
} }
public GunsException(GunsExceptionEnum bizExceptionEnum) { public void setCode(Integer code) {
this.setValues(bizExceptionEnum.getCode(), bizExceptionEnum.getMessage(), bizExceptionEnum.getUrlPath()); this.code = code;
} }
private void setValues(int friendlyCode, String friendlyMsg, String urlPath) { @Override
this.friendlyCode = friendlyCode; public String getMessage() {
this.friendlyMsg = friendlyMsg; return message;
this.urlPath = urlPath; }
}
public int getCode() { public void setMessage(String message) {
return friendlyCode; this.message = message;
} }
public void setCode(int code) {
this.friendlyCode = code;
}
public String getMessage() {
return friendlyMsg;
}
public void setMessage(String message) {
this.friendlyMsg = message;
}
public String getUrlPath() {
return urlPath;
}
public void setUrlPath(String urlPath) {
this.urlPath = urlPath;
}
} }
package com.stylefeng.guns.core.exception; package com.stylefeng.guns.core.exception;
/** /**
* @Description 所有业务异常的枚举 * Guns异常枚举
*
* @author fengshuonan * @author fengshuonan
* @date 2016年11月12日 下午5:04:51 * @Date 2017/12/28 下午10:33
*/ */
public enum GunsExceptionEnum { public enum GunsExceptionEnum implements ServiceExceptionEnum{
/** /**
* 其他 * 其他
...@@ -25,44 +26,29 @@ public enum GunsExceptionEnum { ...@@ -25,44 +26,29 @@ public enum GunsExceptionEnum {
SERVER_ERROR(500, "服务器异常"); SERVER_ERROR(500, "服务器异常");
GunsExceptionEnum(int code, String message) { GunsExceptionEnum(int code, String message) {
this.friendlyCode = code; this.code = code;
this.friendlyMsg = message; this.message = message;
} }
GunsExceptionEnum(int code, String message, String urlPath) { private Integer code;
this.friendlyCode = code;
this.friendlyMsg = message;
this.urlPath = urlPath;
}
private int friendlyCode;
private String friendlyMsg; private String message;
private String urlPath; @Override
public Integer getCode() {
public int getCode() { return code;
return friendlyCode;
} }
public void setCode(int code) { public void setCode(Integer code) {
this.friendlyCode = code; this.code = code;
} }
@Override
public String getMessage() { public String getMessage() {
return friendlyMsg; return message;
} }
public void setMessage(String message) { public void setMessage(String message) {
this.friendlyMsg = message; this.message = message;
}
public String getUrlPath() {
return urlPath;
}
public void setUrlPath(String urlPath) {
this.urlPath = urlPath;
} }
} }
package com.stylefeng.guns.core.exception;
/**
* 抽象接口
*
* @author fengshuonan
* @date 2017-12-28-下午10:27
*/
public interface ServiceExceptionEnum {
/**
* 获取异常编码
*/
Integer getCode();
/**
* 获取异常信息
*/
String getMessage();
}
package com.stylefeng.guns.rest.common.exception; package com.stylefeng.guns.rest.common.exception;
import com.stylefeng.guns.core.exception.ServiceExceptionEnum;
/** /**
* 所有业务异常的枚举 * 所有业务异常的枚举
* *
* @author fengshuonan * @author fengshuonan
* @date 2016年11月12日 下午5:04:51 * @date 2016年11月12日 下午5:04:51
*/ */
public enum BizExceptionEnum { public enum BizExceptionEnum implements ServiceExceptionEnum {
/** /**
* token异常 * token异常
...@@ -25,28 +27,29 @@ public enum BizExceptionEnum { ...@@ -25,28 +27,29 @@ public enum BizExceptionEnum {
AUTH_REQUEST_ERROR(400, "账号密码错误"); AUTH_REQUEST_ERROR(400, "账号密码错误");
BizExceptionEnum(int code, String message) { BizExceptionEnum(int code, String message) {
this.friendlyCode = code; this.code = code;
this.friendlyMsg = message; this.message = message;
} }
private int friendlyCode; private Integer code;
private String friendlyMsg; private String message;
public int getCode() { @Override
return friendlyCode; public Integer getCode() {
return code;
} }
public void setCode(int code) { public void setCode(Integer code) {
this.friendlyCode = code; this.code = code;
} }
@Override
public String getMessage() { public String getMessage() {
return friendlyMsg; return message;
} }
public void setMessage(String message) { public void setMessage(String message) {
this.friendlyMsg = message; this.message = message;
} }
} }
package com.stylefeng.guns.rest.common.exception;
import com.stylefeng.guns.core.exception.GunsException;
/**
* @author fengshuonan
* @Description 业务异常的封装
* @date 2016年11月12日 下午5:05:10
*/
public class BussinessException extends GunsException {
public BussinessException(BizExceptionEnum bizExceptionEnum) {
super(bizExceptionEnum.getCode(), bizExceptionEnum.getMessage(),"");
}
}
package com.stylefeng.guns.rest.modular.auth.controller; package com.stylefeng.guns.rest.modular.auth.controller;
import com.stylefeng.guns.core.exception.GunsException;
import com.stylefeng.guns.rest.common.exception.BizExceptionEnum; import com.stylefeng.guns.rest.common.exception.BizExceptionEnum;
import com.stylefeng.guns.rest.common.exception.BussinessException;
import com.stylefeng.guns.rest.modular.auth.controller.dto.AuthRequest; import com.stylefeng.guns.rest.modular.auth.controller.dto.AuthRequest;
import com.stylefeng.guns.rest.modular.auth.controller.dto.AuthResponse; import com.stylefeng.guns.rest.modular.auth.controller.dto.AuthResponse;
import com.stylefeng.guns.rest.modular.auth.util.JwtTokenUtil; import com.stylefeng.guns.rest.modular.auth.util.JwtTokenUtil;
...@@ -38,7 +38,7 @@ public class AuthController { ...@@ -38,7 +38,7 @@ public class AuthController {
final String token = jwtTokenUtil.generateToken(authRequest.getUserName(), randomKey); final String token = jwtTokenUtil.generateToken(authRequest.getUserName(), randomKey);
return ResponseEntity.ok(new AuthResponse(token, randomKey)); return ResponseEntity.ok(new AuthResponse(token, randomKey));
} else { } else {
throw new BussinessException(BizExceptionEnum.AUTH_REQUEST_ERROR); throw new GunsException(BizExceptionEnum.AUTH_REQUEST_ERROR);
} }
} }
} }
...@@ -2,10 +2,10 @@ package com.stylefeng.guns.rest.modular.auth.converter; ...@@ -2,10 +2,10 @@ package com.stylefeng.guns.rest.modular.auth.converter;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter4; import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter4;
import com.stylefeng.guns.core.exception.GunsException;
import com.stylefeng.guns.core.support.HttpKit; import com.stylefeng.guns.core.support.HttpKit;
import com.stylefeng.guns.core.util.MD5Util; import com.stylefeng.guns.core.util.MD5Util;
import com.stylefeng.guns.rest.common.exception.BizExceptionEnum; import com.stylefeng.guns.rest.common.exception.BizExceptionEnum;
import com.stylefeng.guns.rest.common.exception.BussinessException;
import com.stylefeng.guns.rest.config.properties.JwtProperties; import com.stylefeng.guns.rest.config.properties.JwtProperties;
import com.stylefeng.guns.rest.modular.auth.security.DataSecurityAction; import com.stylefeng.guns.rest.modular.auth.security.DataSecurityAction;
import com.stylefeng.guns.rest.modular.auth.util.JwtTokenUtil; import com.stylefeng.guns.rest.modular.auth.util.JwtTokenUtil;
...@@ -55,7 +55,7 @@ public class WithSignMessageConverter extends FastJsonHttpMessageConverter4 { ...@@ -55,7 +55,7 @@ public class WithSignMessageConverter extends FastJsonHttpMessageConverter4 {
System.out.println("签名校验成功!"); System.out.println("签名校验成功!");
} else { } else {
System.out.println("签名校验失败,数据被改动过!"); System.out.println("签名校验失败,数据被改动过!");
throw new BussinessException(BizExceptionEnum.SIGN_ERROR); throw new GunsException(BizExceptionEnum.SIGN_ERROR);
} }
//校验签名后再转化成应该的对象 //校验签名后再转化成应该的对象
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment