Commit 116efd96 by stylefeng

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

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