Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gic-store
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-store
Commits
ca92a471
Commit
ca92a471
authored
Sep 27, 2019
by
guojuxing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
异常类调整
parent
8f75d9b3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
121 deletions
+12
-121
StoreExtendServiceImpl.java
...va/com/gic/store/service/impl/StoreExtendServiceImpl.java
+12
-11
StoreGroupApiServiceImpl.java
...ic/store/service/outer/impl/StoreGroupApiServiceImpl.java
+0
-2
GlobalExceptionHandler.java
...a/com/gic/store/web/exception/GlobalExceptionHandler.java
+0
-108
No files found.
gic-store-service/src/main/java/com/gic/store/service/impl/StoreExtendServiceImpl.java
View file @
ca92a471
package
com
.
gic
.
store
.
service
.
impl
;
import
java.util.Collections
;
import
java.util.Date
;
import
java.util.List
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
com.alibaba.fastjson.JSON
;
import
com.gic.commons.util.EntityUtil
;
import
com.gic.enterprise.error.ErrorCode
;
import
com.gic.enterprise.exception.CommonException
;
import
com.gic.store.dao.mapper.TabStoreExtendMapper
;
import
com.gic.store.dto.StoreExtendDTO
;
import
com.gic.store.entity.TabStoreExtend
;
import
com.gic.store.entity.TabStoreField
;
import
com.gic.store.exception.StoreException
;
import
com.gic.store.service.StoreExtendService
;
import
com.gic.store.service.StoreFieldService
;
import
com.gic.store.utils.field.FieldBase
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.Collections
;
import
java.util.Date
;
import
java.util.List
;
/**
* @author zhiwj
...
...
@@ -48,7 +49,7 @@ public class StoreExtendServiceImpl implements StoreExtendService {
if
(
StringUtils
.
isNotBlank
(
tabStoreExtend
.
getValue
()))
{
int
count
=
tabStoreExtendMapper
.
countExtendByValue
(
field
.
getStoreFieldId
(),
tabStoreExtend
.
getValue
(),
tabStoreExtend
.
getStoreExtendId
());
if
(
count
>
0
)
{
throw
new
Store
Exception
(
ErrorCode
.
OPERATION_FAILED
.
getCode
(),
field
.
getStoreFieldName
()
+
"不允许重复"
);
throw
new
Common
Exception
(
ErrorCode
.
OPERATION_FAILED
.
getCode
(),
field
.
getStoreFieldName
()
+
"不允许重复"
);
}
}
}
...
...
gic-store-service/src/main/java/com/gic/store/service/outer/impl/StoreGroupApiServiceImpl.java
View file @
ca92a471
...
...
@@ -17,10 +17,8 @@ import com.gic.commons.util.EntityUtil;
import
com.gic.enterprise.error.ErrorCode
;
import
com.gic.redis.data.util.RedisUtil
;
import
com.gic.store.constant.StoreGroupConstant
;
import
com.gic.store.constant.StoreGroupErrorEnum
;
import
com.gic.store.dto.StoreGroupDTO
;
import
com.gic.store.entity.TabStoreGroup
;
import
com.gic.store.exception.StoreGroupException
;
import
com.gic.store.service.StoreGroupApiService
;
import
com.gic.store.service.StoreGroupService
;
import
com.gic.store.service.StoreService
;
...
...
gic-store-web/src/main/java/com/gic/store/web/exception/GlobalExceptionHandler.java
deleted
100644 → 0
View file @
8f75d9b3
package
com
.
gic
.
store
.
web
.
exception
;
import
com.gic.commons.webapi.reponse.RestResponse
;
import
com.gic.enterprise.error.ErrorCode
;
import
com.gic.store.constant.StoreGroupErrorEnum
;
import
com.gic.store.exception.StoreException
;
import
com.gic.store.exception.StoreGroupException
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.validation.BindException
;
import
org.springframework.validation.FieldError
;
import
org.springframework.web.bind.annotation.ControllerAdvice
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.validation.ConstraintViolation
;
import
javax.validation.ConstraintViolationException
;
import
java.io.ByteArrayOutputStream
;
import
java.io.PrintWriter
;
import
java.util.List
;
import
java.util.Set
;
/**
* 全局异常处理类
*
* @author hua
*/
@ControllerAdvice
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
);
RestResponse
failureResponse
=
getRestResponse
(
ErrorCode
.
SYSTEM_ERROR
.
getCode
(),
ErrorCode
.
SYSTEM_ERROR
.
getMsg
());
StringBuilder
sb
=
new
StringBuilder
();
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
();
try
(
PrintWriter
printWriter
=
new
PrintWriter
(
baos
))
{
ex
.
printStackTrace
(
printWriter
);
}
try
{
sb
.
append
(
baos
.
toString
());
}
catch
(
Exception
ignored
)
{
}
if
(
sb
.
length
()
==
0
)
{
sb
.
append
(
ex
.
getMessage
());
}
// 输出详细错误信息,便于调试
failureResponse
.
setDetailError
(
sb
.
toString
());
return
failureResponse
;
}
/**
* 参数校验异常统一处理
* @param e
* @return
*/
@ResponseBody
@ExceptionHandler
(
BindException
.
class
)
public
RestResponse
customException
(
BindException
e
)
{
List
<
FieldError
>
fieldErrors
=
e
.
getFieldErrors
();
StringBuilder
errorMessage
=
new
StringBuilder
();
fieldErrors
.
forEach
(
fieldError
->
{
errorMessage
.
append
(
fieldError
.
getDefaultMessage
())
.
append
(
","
);
});
String
error
=
errorMessage
.
toString
();
int
length
=
error
.
length
();
return
getRestResponse
(
ErrorCode
.
PARAMETER_ERROR
.
getCode
(),
error
.
substring
(
0
,
length
-
1
));
}
@ResponseBody
@ExceptionHandler
(
ConstraintViolationException
.
class
)
public
RestResponse
constraintViolationException
(
ConstraintViolationException
e
)
{
Set
<
ConstraintViolation
<?>>
constraintViolations
=
e
.
getConstraintViolations
();
String
paramName
=
constraintViolations
.
iterator
().
next
().
getPropertyPath
().
toString
();
String
paramError
=
constraintViolations
.
iterator
().
next
().
getMessage
();
return
getRestResponse
(
com
.
gic
.
enterprise
.
error
.
ErrorCode
.
PARAMETER_ERROR
.
getCode
(),
getFailFastMsg
(
paramName
,
paramError
));
}
/**
* 自定义异常统一处理
* @param e
* @return
*/
@ResponseBody
@ExceptionHandler
(
StoreGroupException
.
class
)
public
RestResponse
customException
(
StoreGroupException
e
)
{
return
getRestResponse
(
e
.
getErrorCode
(),
e
.
getMessage
());
}
@ResponseBody
@ExceptionHandler
(
StoreException
.
class
)
public
RestResponse
customException
(
StoreException
e
)
{
return
getRestResponse
(
e
.
getErrorCode
(),
e
.
getMessage
());
}
private
RestResponse
getRestResponse
(
String
errorCode
,
String
message
)
{
return
RestResponse
.
failure
(
errorCode
,
message
);
}
private
static
String
getFailFastMsg
(
String
paramName
,
String
paramError
)
{
return
String
.
format
(
"%s:%s"
,
paramName
,
paramError
);
}
}
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