Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gic-platform-auth
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
base_platform_enterprise
gic-platform-auth
Commits
dacae27d
Commit
dacae27d
authored
Sep 02, 2019
by
guojuxing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增用户添加事务
parent
b69c851c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
12 deletions
+14
-12
UserApiServiceImpl.java
...a/com/gic/auth/service/outer/impl/UserApiServiceImpl.java
+6
-3
GlobalExceptionHandler.java
...va/com/gic/auth/web/exception/GlobalExceptionHandler.java
+8
-9
No files found.
gic-platform-auth-service/src/main/java/com/gic/auth/service/outer/impl/UserApiServiceImpl.java
View file @
dacae27d
...
...
@@ -3,17 +3,18 @@ package com.gic.auth.service.outer.impl;
import
java.util.Date
;
import
java.util.List
;
import
com.gic.enterprise.exception.CommonException
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
com.gic.api.base.commons.ServiceResponse
;
import
com.gic.auth.dto.UserDTO
;
import
com.gic.auth.dto.UserResourceDTO
;
import
com.gic.auth.dto.UserRoleDTO
;
import
com.gic.auth.entity.TabSysUser
;
import
com.gic.auth.exception.AuthException
;
import
com.gic.auth.service.*
;
import
com.gic.commons.util.EntityUtil
;
import
com.gic.enterprise.error.ErrorCode
;
...
...
@@ -36,6 +37,7 @@ public class UserApiServiceImpl implements UserApiService {
@Autowired
private
UserResourceService
userResourceService
;
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Override
public
ServiceResponse
<
Integer
>
saveUser
(
UserDTO
userDTO
)
{
//valid param
...
...
@@ -58,10 +60,11 @@ public class UserApiServiceImpl implements UserApiService {
return
response
;
}
else
{
//事物回滚
throw
new
Common
Exception
(
response
);
throw
new
Auth
Exception
(
response
);
}
}
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Override
public
ServiceResponse
editUser
(
UserDTO
userDTO
)
{
//valid param
...
...
@@ -85,7 +88,7 @@ public class UserApiServiceImpl implements UserApiService {
return
response
;
}
else
{
//事物回滚
throw
new
Common
Exception
(
response
);
throw
new
Auth
Exception
(
response
);
}
}
...
...
gic-platform-auth-web/src/main/java/com/gic/auth/web/exception/GlobalExceptionHandler.java
View file @
dacae27d
...
...
@@ -17,9 +17,9 @@ import org.springframework.web.bind.annotation.ControllerAdvice;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
com.gic.auth.exception.AuthException
;
import
com.gic.commons.webapi.reponse.RestResponse
;
import
com.gic.enterprise.error.ErrorCode
;
import
com.gic.enterprise.exception.CommonException
;
import
com.gic.store.exception.StoreException
;
/**
...
...
@@ -28,10 +28,10 @@ import com.gic.store.exception.StoreException;
* @author hua
*/
@ControllerAdvice
@ResponseBody
public
class
GlobalExceptionHandler
{
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
GlobalExceptionHandler
.
class
);
@ResponseBody
@ExceptionHandler
(
Exception
.
class
)
public
RestResponse
controllerException
(
HttpServletResponse
response
,
Exception
ex
)
{
logger
.
error
(
"err"
,
ex
);
...
...
@@ -58,7 +58,6 @@ public class GlobalExceptionHandler {
* @param e
* @return
*/
@ResponseBody
@ExceptionHandler
(
BindException
.
class
)
public
RestResponse
customException
(
BindException
e
)
{
List
<
FieldError
>
fieldErrors
=
e
.
getFieldErrors
();
...
...
@@ -68,10 +67,10 @@ public class GlobalExceptionHandler {
.
append
(
fieldError
.
getDefaultMessage
())
.
append
(
","
);
});
return
getRestResponse
(
ErrorCode
.
PARAMETER_ERROR
.
getCode
(),
errorMessage
.
toString
());
String
error
=
errorMessage
.
toString
();
return
getRestResponse
(
ErrorCode
.
PARAMETER_ERROR
.
getCode
(),
error
.
substring
(
0
,
error
.
length
()
-
1
));
}
@ResponseBody
@ExceptionHandler
(
ConstraintViolationException
.
class
)
public
RestResponse
constraintViolationException
(
ConstraintViolationException
e
)
{
Set
<
ConstraintViolation
<?>>
constraintViolations
=
e
.
getConstraintViolations
();
...
...
@@ -85,14 +84,14 @@ public class GlobalExceptionHandler {
* @param e
* @return
*/
@ResponseBody
@ExceptionHandler
(
StoreException
.
class
)
public
RestResponse
customException
(
StoreException
e
)
{
return
getRestResponse
(
e
.
getErrorCode
(),
e
.
getMessage
());
}
@ResponseBody
@ExceptionHandler
(
CommonException
.
class
)
public
RestResponse
customException
(
CommonException
e
)
{
@ExceptionHandler
(
AuthException
.
class
)
public
RestResponse
customException
(
AuthException
e
)
{
return
getRestResponse
(
e
.
getErrorCode
(),
e
.
getMessage
());
}
...
...
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