Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
guns-vip
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
chenjunxiong
guns-vip
Commits
116efd96
Commit
116efd96
authored
Dec 28, 2017
by
stylefeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
统一异常,把异常枚举抽象出一个接口
parent
ea4b88a4
Show whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
143 additions
and
197 deletions
+143
-197
guns-admin/src/main/java/com/stylefeng/guns/common/constant/dictmap/factory/DictFieldWarpperFactory.java
+2
-2
guns-admin/src/main/java/com/stylefeng/guns/common/exception/BizExceptionEnum.java
+15
-28
guns-admin/src/main/java/com/stylefeng/guns/common/exception/BussinessException.java
+0
-15
guns-admin/src/main/java/com/stylefeng/guns/core/aop/GlobalExceptionHandler.java
+3
-3
guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/DeptController.java
+3
-3
guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/DictController.java
+3
-3
guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/MenuController.java
+8
-8
guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/NoticeController.java
+3
-3
guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/RoleController.java
+9
-9
guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/UserMgrController.java
+21
-21
guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/DictServiceImpl.java
+5
-5
guns-admin/src/main/resources/application.yml
+1
-1
guns-core/src/main/java/com/stylefeng/guns/core/exception/GunsException.java
+15
-35
guns-core/src/main/java/com/stylefeng/guns/core/exception/GunsExceptionEnum.java
+16
-30
guns-core/src/main/java/com/stylefeng/guns/core/exception/ServiceExceptionEnum.java
+20
-0
guns-rest/src/main/java/com/stylefeng/guns/rest/common/exception/BizExceptionEnum.java
+15
-12
guns-rest/src/main/java/com/stylefeng/guns/rest/common/exception/BussinessException.java
+0
-15
guns-rest/src/main/java/com/stylefeng/guns/rest/modular/auth/controller/AuthController.java
+2
-2
guns-rest/src/main/java/com/stylefeng/guns/rest/modular/auth/converter/WithSignMessageConverter.java
+2
-2
No files found.
guns-admin/src/main/java/com/stylefeng/guns/common/constant/dictmap/factory/DictFieldWarpperFactory.java
View file @
116efd96
...
...
@@ -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.co
mmon.exception.Bussines
sException
;
import
com.stylefeng.guns.co
re.exception.Gun
sException
;
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
Bussines
sException
(
BizExceptionEnum
.
ERROR_WRAPPER_FIELD
);
throw
new
Gun
sException
(
BizExceptionEnum
.
ERROR_WRAPPER_FIELD
);
}
}
}
...
...
guns-admin/src/main/java/com/stylefeng/guns/common/exception/BizExceptionEnum.java
View file @
116efd96
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
friendlyC
ode
;
private
Integer
c
ode
;
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
.
friendlyC
ode
=
code
;
public
void
setCode
(
Integer
code
)
{
this
.
c
ode
=
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
;
}
}
guns-admin/src/main/java/com/stylefeng/guns/common/exception/BussinessException.java
deleted
100644 → 0
View file @
ea4b88a4
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
());
}
}
guns-admin/src/main/java/com/stylefeng/guns/core/aop/GlobalExceptionHandler.java
View file @
116efd96
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
(
Bussines
sException
.
class
)
@ExceptionHandler
(
Gun
sException
.
class
)
@ResponseStatus
(
HttpStatus
.
INTERNAL_SERVER_ERROR
)
@ResponseBody
public
ErrorTip
notFount
(
Bussines
sException
e
)
{
public
ErrorTip
notFount
(
Gun
sException
e
)
{
LogManager
.
me
().
executeLog
(
LogTaskFactory
.
exceptionLog
(
ShiroKit
.
getUser
().
getId
(),
e
));
getRequest
().
setAttribute
(
"tip"
,
e
.
getMessage
());
log
.
error
(
"业务异常:"
,
e
);
...
...
guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/DeptController.java
View file @
116efd96
...
...
@@ -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
Bussines
sException
(
BizExceptionEnum
.
REQUEST_NULL
);
throw
new
Gun
sException
(
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
Bussines
sException
(
BizExceptionEnum
.
REQUEST_NULL
);
throw
new
Gun
sException
(
BizExceptionEnum
.
REQUEST_NULL
);
}
deptSetPids
(
dept
);
deptMapper
.
updateById
(
dept
);
...
...
guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/DictController.java
View file @
116efd96
...
...
@@ -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
Bussines
sException
(
BizExceptionEnum
.
REQUEST_NULL
);
throw
new
Gun
sException
(
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
Bussines
sException
(
BizExceptionEnum
.
REQUEST_NULL
);
throw
new
Gun
sException
(
BizExceptionEnum
.
REQUEST_NULL
);
}
dictService
.
editDict
(
dictId
,
dictName
,
dictValues
);
return
super
.
SUCCESS_TIP
;
...
...
guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/MenuController.java
View file @
116efd96
...
...
@@ -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
Bussines
sException
(
BizExceptionEnum
.
REQUEST_NULL
);
throw
new
Gun
sException
(
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
Bussines
sException
(
BizExceptionEnum
.
REQUEST_NULL
);
throw
new
Gun
sException
(
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
Bussines
sException
(
BizExceptionEnum
.
REQUEST_NULL
);
throw
new
Gun
sException
(
BizExceptionEnum
.
REQUEST_NULL
);
}
//判断是否存在该编号
String
existedMenuName
=
ConstantFactory
.
me
().
getMenuNameByCode
(
menu
.
getCode
());
if
(
ToolUtil
.
isNotEmpty
(
existedMenuName
))
{
throw
new
Bussines
sException
(
BizExceptionEnum
.
EXISTED_THE_MENU
);
throw
new
Gun
sException
(
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
Bussines
sException
(
BizExceptionEnum
.
REQUEST_NULL
);
throw
new
Gun
sException
(
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
Bussines
sException
(
BizExceptionEnum
.
REQUEST_NULL
);
throw
new
Gun
sException
(
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
Bussines
sException
(
BizExceptionEnum
.
MENU_PCODE_COINCIDENCE
);
throw
new
Gun
sException
(
BizExceptionEnum
.
MENU_PCODE_COINCIDENCE
);
}
menu
.
setLevels
(
pLevels
+
1
);
...
...
guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/NoticeController.java
View file @
116efd96
...
...
@@ -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
Bussines
sException
(
BizExceptionEnum
.
REQUEST_NULL
);
throw
new
Gun
sException
(
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
Bussines
sException
(
BizExceptionEnum
.
REQUEST_NULL
);
throw
new
Gun
sException
(
BizExceptionEnum
.
REQUEST_NULL
);
}
Notice
old
=
this
.
noticeMapper
.
selectById
(
notice
.
getId
());
old
.
setTitle
(
notice
.
getTitle
());
...
...
guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/RoleController.java
View file @
116efd96
...
...
@@ -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
Bussines
sException
(
BizExceptionEnum
.
REQUEST_NULL
);
throw
new
Gun
sException
(
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
Bussines
sException
(
BizExceptionEnum
.
REQUEST_NULL
);
throw
new
Gun
sException
(
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
Bussines
sException
(
BizExceptionEnum
.
REQUEST_NULL
);
throw
new
Gun
sException
(
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
Bussines
sException
(
BizExceptionEnum
.
REQUEST_NULL
);
throw
new
Gun
sException
(
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
Bussines
sException
(
BizExceptionEnum
.
REQUEST_NULL
);
throw
new
Gun
sException
(
BizExceptionEnum
.
REQUEST_NULL
);
}
//不能删除超级管理员角色
if
(
roleId
.
equals
(
Const
.
ADMIN_ROLE_ID
)){
throw
new
Bussines
sException
(
BizExceptionEnum
.
CANT_DELETE_ADMIN
);
throw
new
Gun
sException
(
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
Bussines
sException
(
BizExceptionEnum
.
REQUEST_NULL
);
throw
new
Gun
sException
(
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
Bussines
sException
(
BizExceptionEnum
.
REQUEST_NULL
);
throw
new
Gun
sException
(
BizExceptionEnum
.
REQUEST_NULL
);
}
this
.
roleService
.
setAuthority
(
roleId
,
ids
);
return
SUCCESS_TIP
;
...
...
guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/UserMgrController.java
View file @
116efd96
...
...
@@ -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
Bussines
sException
(
BizExceptionEnum
.
REQUEST_NULL
);
throw
new
Gun
sException
(
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
Bussines
sException
(
BizExceptionEnum
.
REQUEST_NULL
);
throw
new
Gun
sException
(
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
Bussines
sException
(
BizExceptionEnum
.
REQUEST_NULL
);
throw
new
Gun
sException
(
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
Bussines
sException
(
BizExceptionEnum
.
TWO_PWD_NOT_MATCH
);
throw
new
Gun
sException
(
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
Bussines
sException
(
BizExceptionEnum
.
OLD_PWD_NOT_RIGHT
);
throw
new
Gun
sException
(
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
Bussines
sException
(
BizExceptionEnum
.
REQUEST_NULL
);
throw
new
Gun
sException
(
BizExceptionEnum
.
REQUEST_NULL
);
}
// 判断账号是否重复
User
theUser
=
managerDao
.
getByAccount
(
user
.
getAccount
());
if
(
theUser
!=
null
)
{
throw
new
Bussines
sException
(
BizExceptionEnum
.
USER_ALREADY_REG
);
throw
new
Gun
sException
(
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
Bussines
sException
(
BizExceptionEnum
.
REQUEST_NULL
);
throw
new
Gun
sException
(
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
Bussines
sException
(
BizExceptionEnum
.
NO_PERMITION
);
throw
new
Gun
sException
(
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
Bussines
sException
(
BizExceptionEnum
.
REQUEST_NULL
);
throw
new
Gun
sException
(
BizExceptionEnum
.
REQUEST_NULL
);
}
//不能删除超级管理员
if
(
userId
.
equals
(
Const
.
ADMIN_ID
))
{
throw
new
Bussines
sException
(
BizExceptionEnum
.
CANT_DELETE_ADMIN
);
throw
new
Gun
sException
(
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
Bussines
sException
(
BizExceptionEnum
.
REQUEST_NULL
);
throw
new
Gun
sException
(
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
Bussines
sException
(
BizExceptionEnum
.
REQUEST_NULL
);
throw
new
Gun
sException
(
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
Bussines
sException
(
BizExceptionEnum
.
REQUEST_NULL
);
throw
new
Gun
sException
(
BizExceptionEnum
.
REQUEST_NULL
);
}
//不能冻结超级管理员
if
(
userId
.
equals
(
Const
.
ADMIN_ID
))
{
throw
new
Bussines
sException
(
BizExceptionEnum
.
CANT_FREEZE_ADMIN
);
throw
new
Gun
sException
(
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
Bussines
sException
(
BizExceptionEnum
.
REQUEST_NULL
);
throw
new
Gun
sException
(
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
Bussines
sException
(
BizExceptionEnum
.
REQUEST_NULL
);
throw
new
Gun
sException
(
BizExceptionEnum
.
REQUEST_NULL
);
}
//不能修改超级管理员
if
(
userId
.
equals
(
Const
.
ADMIN_ID
))
{
throw
new
Bussines
sException
(
BizExceptionEnum
.
CANT_CHANGE_ADMIN
);
throw
new
Gun
sException
(
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
Bussines
sException
(
BizExceptionEnum
.
UPLOAD_ERROR
);
throw
new
Gun
sException
(
BizExceptionEnum
.
UPLOAD_ERROR
);
}
return
pictureName
;
}
...
...
@@ -365,7 +365,7 @@ public class UserMgrController extends BaseController {
if
(
deptDataScope
.
contains
(
deptid
))
{
return
;
}
else
{
throw
new
Bussines
sException
(
BizExceptionEnum
.
NO_PERMITION
);
throw
new
Gun
sException
(
BizExceptionEnum
.
NO_PERMITION
);
}
}
...
...
guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/DictServiceImpl.java
View file @
116efd96
...
...
@@ -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
Bussines
sException
(
BizExceptionEnum
.
DICT_EXISTED
);
throw
new
Gun
sException
(
BizExceptionEnum
.
DICT_EXISTED
);
}
//解析dictValues
...
...
@@ -55,7 +55,7 @@ public class DictServiceImpl implements IDictService {
try
{
itemDict
.
setNum
(
Integer
.
valueOf
(
num
));
}
catch
(
NumberFormatException
e
){
throw
new
Bussines
sException
(
BizExceptionEnum
.
DICT_MUST_BE_NUMBER
);
throw
new
Gun
sException
(
BizExceptionEnum
.
DICT_MUST_BE_NUMBER
);
}
this
.
dictMapper
.
insert
(
itemDict
);
}
...
...
guns-admin/src/main/resources/application.yml
View file @
116efd96
...
...
@@ -15,7 +15,7 @@ guns:
################### 项目启动端口 ###################
server
:
port
:
80
port
:
80
80
################### beetl配置 ###################
beetl
:
...
...
guns-core/src/main/java/com/stylefeng/guns/core/exception/GunsException.java
View file @
116efd96
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
friendlyC
ode
;
public
Integer
getCode
()
{
return
c
ode
;
}
public
void
setCode
(
int
code
)
{
this
.
friendlyC
ode
=
code
;
public
void
setCode
(
Integer
code
)
{
this
.
c
ode
=
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
;
}
}
guns-core/src/main/java/com/stylefeng/guns/core/exception/GunsExceptionEnum.java
View file @
116efd96
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
.
friendlyC
ode
=
code
;
this
.
friendlyMsg
=
message
;
this
.
c
ode
=
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
.
friendlyC
ode
=
code
;
public
void
setCode
(
Integer
code
)
{
this
.
c
ode
=
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
;
}
}
guns-core/src/main/java/com/stylefeng/guns/core/exception/ServiceExceptionEnum.java
0 → 100644
View file @
116efd96
package
com
.
stylefeng
.
guns
.
core
.
exception
;
/**
* 抽象接口
*
* @author fengshuonan
* @date 2017-12-28-下午10:27
*/
public
interface
ServiceExceptionEnum
{
/**
* 获取异常编码
*/
Integer
getCode
();
/**
* 获取异常信息
*/
String
getMessage
();
}
guns-rest/src/main/java/com/stylefeng/guns/rest/common/exception/BizExceptionEnum.java
View file @
116efd96
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
.
friendlyC
ode
=
code
;
this
.
friendlyMsg
=
message
;
this
.
c
ode
=
code
;
this
.
message
=
message
;
}
private
int
friendlyC
ode
;
private
Integer
c
ode
;
private
String
friendlyMsg
;
private
String
message
;
public
int
getCode
()
{
return
friendlyCode
;
@Override
public
Integer
getCode
()
{
return
code
;
}
public
void
setCode
(
int
code
)
{
this
.
friendlyC
ode
=
code
;
public
void
setCode
(
Integer
code
)
{
this
.
c
ode
=
code
;
}
@Override
public
String
getMessage
()
{
return
friendlyMsg
;
return
message
;
}
public
void
setMessage
(
String
message
)
{
this
.
friendlyMsg
=
message
;
this
.
message
=
message
;
}
}
guns-rest/src/main/java/com/stylefeng/guns/rest/common/exception/BussinessException.java
deleted
100644 → 0
View file @
ea4b88a4
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
(),
""
);
}
}
guns-rest/src/main/java/com/stylefeng/guns/rest/modular/auth/controller/AuthController.java
View file @
116efd96
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
Bussines
sException
(
BizExceptionEnum
.
AUTH_REQUEST_ERROR
);
throw
new
Gun
sException
(
BizExceptionEnum
.
AUTH_REQUEST_ERROR
);
}
}
}
guns-rest/src/main/java/com/stylefeng/guns/rest/modular/auth/converter/WithSignMessageConverter.java
View file @
116efd96
...
...
@@ -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
Bussines
sException
(
BizExceptionEnum
.
SIGN_ERROR
);
throw
new
Gun
sException
(
BizExceptionEnum
.
SIGN_ERROR
);
}
//校验签名后再转化成应该的对象
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment