Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
extend
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
park
extend
Commits
42af403e
Commit
42af403e
authored
Jun 24, 2020
by
lixian7
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
返回体调整
parent
d06e0fe3
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
68 additions
and
13 deletions
+68
-13
api/src/main/java/com/hikcreate/edl/pub/web/mobile/api/controller/H5Controller.java
+2
-1
api/src/main/java/com/hikcreate/edl/pub/web/mobile/api/exception/GlobalExceptionHandler.java
+53
-5
domain/src/main/java/com/hikcreate/edl/pub/web/mobile/domain/IBindService.java
+2
-1
domain/src/main/java/com/hikcreate/edl/pub/web/mobile/domain/impl/BindServiceImpl.java
+9
-5
infra/src/main/java/com/hikcreate/edl/pub/web/mobile/infra/data/cache/BindCache.java
+1
-0
infra/src/main/resources/mapper/BindInfoMapper.xml
+1
-1
No files found.
api/src/main/java/com/hikcreate/edl/pub/web/mobile/api/controller/H5Controller.java
View file @
42af403e
...
...
@@ -8,6 +8,7 @@ import com.hikcreate.common.sdk.response.apiparam.ResponseGenerator;
import
com.hikcreate.common.sdk.response.statuscode.StatusCode
;
import
com.hikcreate.edl.common.sdk.util.VerifyCodeUtil
;
import
com.hikcreate.edl.pub.web.mobile.domain.IBindService
;
import
com.hikcreate.edl.pub.web.mobile.infra.core.Result.Result
;
import
com.hikcreate.edl.pub.web.mobile.infra.core.annotatiion.HeaderDecryptAnnotation
;
import
com.hikcreate.edl.pub.web.mobile.infra.data.feign.edl_pub_service_sms.SmsFeign
;
import
com.hikcreate.edl.pub.web.mobile.infra.data.feign.edl_pub_service_sms.param.request.CheckVerifyCodeMicReq
;
...
...
@@ -103,7 +104,7 @@ public class H5Controller {
*/
@PostMapping
(
"insuranceInfo"
)
@HeaderDecryptAnnotation
public
Res
ponse
<
InsuranceInfoRes
>
insuranceInfo
(
@RequestBody
@Validated
H5BindInfoQuery
query
)
{
public
Res
ult
<
InsuranceInfoRes
>
insuranceInfo
(
@RequestBody
@Validated
H5BindInfoQuery
query
)
{
return
service
.
insuranceInfo
(
query
);
}
...
...
api/src/main/java/com/hikcreate/edl/pub/web/mobile/api/exception/GlobalExceptionHandler.java
View file @
42af403e
...
...
@@ -4,9 +4,15 @@ import com.hikcreate.common.sdk.exception.DefaultExceptionHandler;
import
com.hikcreate.common.sdk.response.apiparam.Response
;
import
com.hikcreate.common.sdk.response.apiparam.ResponseGenerator
;
import
com.hikcreate.common.sdk.response.statuscode.StatusCode
;
import
com.hikcreate.edl.pub.web.mobile.infra.core.Result.Result
;
import
com.hikcreate.edl.pub.web.mobile.infra.core.Result.ResultCode
;
import
com.hikcreate.edl.pub.web.mobile.infra.core.Result.ResultGenerator
;
import
feign.RetryableException
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.validation.BindingResult
;
import
org.springframework.validation.FieldError
;
import
org.springframework.web.bind.MethodArgumentNotValidException
;
import
org.springframework.web.bind.ServletRequestBindingException
;
import
org.springframework.web.bind.annotation.ControllerAdvice
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
...
...
@@ -16,15 +22,15 @@ import org.springframework.web.bind.annotation.ResponseStatus;
import
javax.servlet.http.HttpServletRequest
;
import
javax.validation.ConstraintViolation
;
import
javax.validation.ConstraintViolationException
;
import
java.util.List
;
/**
* 全局异常处理类 FOR controller层以下的异常,Filter的异常不能捕获
*/
@Slf4j
@ControllerAdvice
public
class
GlobalExceptionHandler
extends
DefaultExceptionHandler
{
public
class
GlobalExceptionHandler
{
@Override
@ExceptionHandler
(
value
=
ServletRequestBindingException
.
class
)
@ResponseBody
@ResponseStatus
(
HttpStatus
.
OK
)
...
...
@@ -34,6 +40,29 @@ public class GlobalExceptionHandler extends DefaultExceptionHandler {
}
/**
* 可能原因:@Validated 注解的对象验证不通过
*
* @param e
* @return
*/
@ExceptionHandler
(
value
=
MethodArgumentNotValidException
.
class
)
@ResponseBody
public
Result
<
Void
>
handle
(
MethodArgumentNotValidException
e
)
{
BindingResult
bindingResult
=
e
.
getBindingResult
();
String
errorMessage
=
buildErrorMessage
(
bindingResult
);
log
.
warn
(
errorMessage
);
List
<
FieldError
>
fieldErrors
=
bindingResult
.
getFieldErrors
();
String
message
=
"参数错误"
;
if
(
null
!=
fieldErrors
&&
fieldErrors
.
size
()
>
0
)
{
FieldError
fieldError
=
fieldErrors
.
get
(
0
);
if
(
null
!=
fieldError
)
{
message
=
fieldError
.
getDefaultMessage
();
}
}
return
ResultGenerator
.
fail
(
ResultCode
.
PARAM_ERROR
.
getCode
(),
message
);
}
/**
* 参数验证失败
* <p>
* GET 方法入口
...
...
@@ -44,12 +73,12 @@ public class GlobalExceptionHandler extends DefaultExceptionHandler {
@ExceptionHandler
(
ConstraintViolationException
.
class
)
@ResponseBody
@ResponseStatus
(
HttpStatus
.
OK
)
public
Res
ponse
handleValidationException
(
ConstraintViolationException
e
)
{
public
Res
ult
handleValidationException
(
ConstraintViolationException
e
)
{
for
(
ConstraintViolation
<?>
s
:
e
.
getConstraintViolations
())
{
log
.
error
(
"Request parameter is invalid {}"
,
s
.
getMessage
());
return
Res
ponseGenerator
.
fail
(
StatusCode
.
PARAM_ERROR
.
getCode
(),
s
.
getMessage
()
);
return
Res
ultGenerator
.
fail
(
ResultCode
.
PARAM_ERROR
);
}
return
Res
ponseGenerator
.
fail
(
Status
Code
.
PARAM_ERROR
);
return
Res
ultGenerator
.
fail
(
Result
Code
.
PARAM_ERROR
);
}
@ExceptionHandler
(
value
=
RetryableException
.
class
)
...
...
@@ -58,4 +87,22 @@ public class GlobalExceptionHandler extends DefaultExceptionHandler {
log
.
error
(
" connect timed out"
,
e
);
return
ResponseGenerator
.
fail
(
StatusCode
.
SYSTEM_ERROR
.
getCode
(),
"服务请求超时或不可用"
,
e
.
getMessage
());
}
/**
* 从{@code @BindingResult}中构建异常信息
* on field 'verifyCode': null];
*
* @param bindingResult 绑定结果
*/
private
String
buildErrorMessage
(
BindingResult
bindingResult
)
{
StringBuilder
sb
=
new
StringBuilder
(
"BindException. "
);
sb
.
append
(
"Field error in object '"
).
append
(
bindingResult
.
getObjectName
()).
append
(
"'. ["
).
append
(
bindingResult
.
getTarget
()).
append
(
"]"
);
bindingResult
.
getFieldErrors
()
.
forEach
(
error
->
{
sb
.
append
(
"\r\n on field '"
).
append
(
error
.
getField
()).
append
(
"': "
);
sb
.
append
(
"rejected value ["
).
append
(
error
.
getRejectedValue
()).
append
(
"]. "
);
sb
.
append
(
"default message ["
).
append
(
error
.
getDefaultMessage
()).
append
(
"]"
);
});
return
sb
.
toString
();
}
}
\ No newline at end of file
domain/src/main/java/com/hikcreate/edl/pub/web/mobile/domain/IBindService.java
View file @
42af403e
...
...
@@ -2,6 +2,7 @@ package com.hikcreate.edl.pub.web.mobile.domain;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.hikcreate.common.sdk.response.apiparam.Response
;
import
com.hikcreate.edl.pub.web.mobile.infra.core.Result.Result
;
import
com.hikcreate.edl.pub.web.mobile.infra.model.entity.ParkBindInfo
;
import
com.hikcreate.edl.pub.web.mobile.infra.model.param.request.BindInfoQueryReq
;
import
com.hikcreate.edl.pub.web.mobile.infra.model.param.request.H5BindInfoQuery
;
...
...
@@ -57,7 +58,7 @@ public interface IBindService extends IService<ParkBindInfo> {
* @param query
* @return
*/
Res
ponse
insuranceInfo
(
H5BindInfoQuery
query
);
Res
ult
insuranceInfo
(
H5BindInfoQuery
query
);
/**
* 违法信息查询接口
...
...
domain/src/main/java/com/hikcreate/edl/pub/web/mobile/domain/impl/BindServiceImpl.java
View file @
42af403e
...
...
@@ -10,6 +10,9 @@ import com.hikcreate.common.sdk.response.apiparam.ResponseGenerator;
import
com.hikcreate.common.sdk.response.statuscode.StatusCode
;
import
com.hikcreate.edl.common.distributed.lock.annotation.DistributedLock
;
import
com.hikcreate.edl.pub.web.mobile.domain.IBindService
;
import
com.hikcreate.edl.pub.web.mobile.infra.core.Result.Result
;
import
com.hikcreate.edl.pub.web.mobile.infra.core.Result.ResultCode
;
import
com.hikcreate.edl.pub.web.mobile.infra.core.Result.ResultGenerator
;
import
com.hikcreate.edl.pub.web.mobile.infra.core.util.UnqIdUtil
;
import
com.hikcreate.edl.pub.web.mobile.infra.data.cache.BindCache
;
import
com.hikcreate.edl.pub.web.mobile.infra.data.cache.DrivingLicenseCache
;
...
...
@@ -89,7 +92,7 @@ public class BindServiceImpl extends ServiceImpl<BindInfoMapper, ParkBindInfo> i
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
@DistributedLock
(
key
=
"'park:extend:
bind:lock
:userId:'+#info.userId+':timestamp:'+#info.timestamp"
,
expireTime
=
3000
,
waitTime
=
2000
,
retryTimes
=
50
)
@DistributedLock
(
key
=
"'park:extend:
lock:bind
:userId:'+#info.userId+':timestamp:'+#info.timestamp"
,
expireTime
=
3000
,
waitTime
=
2000
,
retryTimes
=
50
)
public
Response
bind
(
ParkBindInfo
info
)
{
//判断规则1:用户已绑定的车辆不超过3辆,包括已解绑但未过一个月的车辆
QueryWrapper
<
ParkBindInfo
>
boundQuery
=
new
QueryWrapper
();
...
...
@@ -174,6 +177,7 @@ public class BindServiceImpl extends ServiceImpl<BindInfoMapper, ParkBindInfo> i
*/
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
@DistributedLock
(
key
=
"'park:extend:lock:unbind:unqId:'+#req.unqId+':userId:'+#req.userId+':timestamp:'+#req.timestamp"
,
expireTime
=
3000
,
waitTime
=
2000
,
retryTimes
=
50
)
public
Response
unbindInfo
(
UnBindReq
req
)
{
ParkBindInfo
bindInfo
=
bindCache
.
getById
(
req
.
getUnqId
());
if
(
bindInfo
==
null
||
"0"
.
equals
(
bindInfo
.
getStatus
()))
{
...
...
@@ -240,17 +244,17 @@ public class BindServiceImpl extends ServiceImpl<BindInfoMapper, ParkBindInfo> i
}
@Override
public
Res
ponse
<
InsuranceInfoRes
>
insuranceInfo
(
H5BindInfoQuery
query
)
{
public
Res
ult
<
InsuranceInfoRes
>
insuranceInfo
(
H5BindInfoQuery
query
)
{
ParkBindInfo
bindInfo
=
bindCache
.
getById
(
query
.
getUnqId
());
if
(
bindInfo
==
null
||
"0"
.
equals
(
bindInfo
.
getStatus
()))
{
return
Res
ponseGenerator
.
fail
(
StatusCode
.
DATA_ERROR
,
"绑定信息不存在"
);
return
Res
ultGenerator
.
fail
(
ResultCode
.
BIND_INFO_UNKNOWN
);
}
PlateNumAndTypeQueryReq
req
=
new
PlateNumAndTypeQueryReq
();
req
.
setPlateNum
(
bindInfo
.
getPlateNum
());
req
.
setPlateType
(
bindInfo
.
getPlateType
());
VehicleRes
vehicleRes
=
vechicleCache
.
getByPlateNumAndType
(
req
);
if
(
Objects
.
isNull
(
vehicleRes
))
{
return
Res
ponse
Generator
.
success
();
return
Res
ult
Generator
.
success
();
}
InsuranceInfoRes
insuranceInfoRes
=
new
InsuranceInfoRes
();
insuranceInfoRes
.
setPlateNum
(
bindInfo
.
getPlateNum
());
...
...
@@ -270,7 +274,7 @@ public class BindServiceImpl extends ServiceImpl<BindInfoMapper, ParkBindInfo> i
}
else
{
insuranceInfoRes
.
setStatus
(
"未知"
);
}
return
Res
ponse
Generator
.
success
(
insuranceInfoRes
);
return
Res
ult
Generator
.
success
(
insuranceInfoRes
);
}
...
...
infra/src/main/java/com/hikcreate/edl/pub/web/mobile/infra/data/cache/BindCache.java
View file @
42af403e
...
...
@@ -70,6 +70,7 @@ public class BindCache {
public
boolean
unBind
(
String
unqId
,
String
userId
)
{
ParkBindInfo
bindInfo
=
new
ParkBindInfo
();
bindInfo
.
setUnqId
(
unqId
);
bindInfo
.
setUserId
(
userId
);
bindInfo
.
setStatus
(
"0"
);
bindInfo
.
setUnbindTime
(
new
Date
());
return
mapper
.
unbind
(
bindInfo
)
>
0
;
...
...
infra/src/main/resources/mapper/BindInfoMapper.xml
View file @
42af403e
...
...
@@ -19,7 +19,7 @@
</select>
<update
id=
"unbind"
>
update park_bind_info as b set b.status=
"0",b.unbind_time=#{unbindTime} where b.unq_id=#{unqId}
update park_bind_info as b set b.status=
'0',b.unbind_time=#{unbindTime} where b.unq_id=#{unqId} and b.user_id=#{userId} and b.status='1'
</update>
...
...
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