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
3a9b199e
Commit
3a9b199e
authored
Jul 21, 2020
by
牟邦恺
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/feature-20200720' into feature-20200720
parents
4c19a6e9
8b0fe386
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
118 additions
and
39 deletions
+118
-39
api/src/main/java/com/hikcreate/edl/pub/web/mobile/api/controller/BindInfoControlller.java
+23
-12
domain/pom.xml
+6
-0
domain/src/main/java/com/hikcreate/edl/pub/web/mobile/domain/IBindService.java
+17
-6
domain/src/main/java/com/hikcreate/edl/pub/web/mobile/domain/impl/BindServiceImpl.java
+70
-19
infra/src/main/java/com/hikcreate/edl/pub/web/mobile/infra/model/param/request/BindInfoReq.java
+2
-2
No files found.
api/src/main/java/com/hikcreate/edl/pub/web/mobile/api/controller/BindInfoControlller.java
View file @
3a9b199e
package
com
.
hikcreate
.
edl
.
pub
.
web
.
mobile
.
api
.
controller
;
import
com.hikcreate.common.orika.DefaultConverter
;
import
com.hikcreate.common.sdk.response.statuscode.StatusCode
;
import
com.hikcreate.edl.common.distributed.lock.exception.DistributedLockException
;
import
com.hikcreate.edl.pub.web.mobile.domain.IBindService
;
...
...
@@ -8,7 +7,6 @@ import com.hikcreate.edl.pub.web.mobile.infra.core.Result.Result;
import
com.hikcreate.edl.pub.web.mobile.infra.core.Result.ResultGenerator
;
import
com.hikcreate.edl.pub.web.mobile.infra.core.annotatiion.BodyDecryptAnnotation
;
import
com.hikcreate.edl.pub.web.mobile.infra.core.annotatiion.ResponseEncryptAnnotation
;
import
com.hikcreate.edl.pub.web.mobile.infra.model.entity.ParkBindInfo
;
import
com.hikcreate.edl.pub.web.mobile.infra.model.param.request.AdminUnbindReq
;
import
com.hikcreate.edl.pub.web.mobile.infra.model.param.request.AdminUnbindSmsValidReq
;
import
com.hikcreate.edl.pub.web.mobile.infra.model.param.request.BindInfoQueryReq
;
...
...
@@ -40,9 +38,6 @@ public class BindInfoControlller extends BaseController {
@Autowired
IBindService
service
;
@Autowired
DefaultConverter
defaultConverter
;
/**
* 绑定用户信息的接口
...
...
@@ -53,14 +48,12 @@ public class BindInfoControlller extends BaseController {
* @date: 2020/6/19 10:27
*/
@PostMapping
(
"bind"
)
@BodyDecryptAnnotation
@ResponseEncryptAnnotation
//
@BodyDecryptAnnotation
//
@ResponseEncryptAnnotation
public
Result
bindInfo
(
@RequestBody
@Validated
BindInfoReq
req
)
{
ParkBindInfo
bindInfo
=
new
ParkBindInfo
();
defaultConverter
.
getMapperFacade
().
map
(
req
,
bindInfo
);
Result
response
=
null
;
try
{
response
=
service
.
bind
(
bindInfo
);
response
=
service
.
bind
(
req
);
}
catch
(
DistributedLockException
e
)
{
log
.
error
(
"分布式锁超时"
);
return
ResultGenerator
.
fail
(
StatusCode
.
REPEAT_SUBMIT
);
...
...
@@ -113,7 +106,16 @@ public class BindInfoControlller extends BaseController {
*/
@PostMapping
(
"admin/unbind"
)
public
Result
adminUnbind
(
@RequestBody
@Validated
AdminUnbindReq
req
)
{
return
null
;
Result
result
=
null
;
try
{
result
=
service
.
adminUnbind
(
req
);
}
catch
(
DistributedLockException
e
)
{
return
ResultGenerator
.
fail
(
StatusCode
.
REPEAT_SUBMIT
);
}
catch
(
Exception
e
)
{
log
.
error
(
"系统异常:{}"
,
e
);
return
ResultGenerator
.
fail
(
StatusCode
.
SYSTEM_ERROR
);
}
return
result
;
}
/**
...
...
@@ -123,7 +125,16 @@ public class BindInfoControlller extends BaseController {
*/
@PostMapping
(
"admin/unbind/smsValid"
)
public
Result
adminUnbindSmsValid
(
@RequestBody
@Validated
AdminUnbindSmsValidReq
req
)
{
return
null
;
Result
result
=
null
;
try
{
result
=
service
.
adminUnbindSmsValid
(
req
);
}
catch
(
DistributedLockException
e
)
{
return
ResultGenerator
.
fail
(
StatusCode
.
REPEAT_SUBMIT
);
}
catch
(
Exception
e
)
{
log
.
error
(
"系统异常:{}"
,
e
);
return
ResultGenerator
.
fail
(
StatusCode
.
SYSTEM_ERROR
);
}
return
result
;
}
/**
...
...
domain/pom.xml
View file @
3a9b199e
...
...
@@ -28,6 +28,12 @@
</dependency>
<dependency>
<groupId>
com.hikcreate.common
</groupId>
<artifactId>
orika
</artifactId>
<version>
${parent.version}
</version>
</dependency>
<dependency>
<groupId>
com.hikcreate.edl.common
</groupId>
<artifactId>
distributed-lock-starter
</artifactId>
<version>
${parent.version}
</version>
...
...
domain/src/main/java/com/hikcreate/edl/pub/web/mobile/domain/IBindService.java
View file @
3a9b199e
...
...
@@ -3,10 +3,7 @@ package com.hikcreate.edl.pub.web.mobile.domain;
import
com.baomidou.mybatisplus.extension.service.IService
;
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.BindSmsValidReq
;
import
com.hikcreate.edl.pub.web.mobile.infra.model.param.request.H5BindInfoQuery
;
import
com.hikcreate.edl.pub.web.mobile.infra.model.param.request.UnBindReq
;
import
com.hikcreate.edl.pub.web.mobile.infra.model.param.request.*
;
import
com.hikcreate.edl.pub.web.mobile.infra.model.param.response.BindInfoQueryRes
;
import
com.hikcreate.edl.pub.web.mobile.infra.model.param.response.VehicleDrivingLicenseInfoRes
;
...
...
@@ -24,12 +21,12 @@ public interface IBindService extends IService<ParkBindInfo> {
/**
* 信息绑定接口
*
* @param
info
* @param
req
* @return Result
* @author: xsx
* @date: 2020/6/19 10:32
*/
Result
bind
(
ParkBindInfo
info
);
Result
bind
(
BindInfoReq
req
);
/**
* 车辆绑定短信验证接口
...
...
@@ -46,6 +43,20 @@ public interface IBindService extends IService<ParkBindInfo> {
Result
unbindInfo
(
UnBindReq
req
);
/**
* 车辆解绑发送短信(后台操作)
* @param req
* @return
*/
Result
adminUnbind
(
AdminUnbindReq
req
);
/**
* 车辆解绑短信验证(后台操作)
* @param req
* @return
*/
Result
adminUnbindSmsValid
(
AdminUnbindSmsValidReq
req
);
/**
* 查询用户绑定信息
* @param query
* @return
...
...
domain/src/main/java/com/hikcreate/edl/pub/web/mobile/domain/impl/BindServiceImpl.java
View file @
3a9b199e
...
...
@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.hikcreate.common.orika.DefaultConverter
;
import
com.hikcreate.common.sdk.response.apiparam.Response
;
import
com.hikcreate.common.sdk.response.statuscode.StatusCode
;
import
com.hikcreate.edl.common.distributed.lock.annotation.DistributedLock
;
...
...
@@ -37,10 +38,7 @@ import com.hikcreate.edl.pub.web.mobile.infra.data.mapper.BindInfoMapper;
import
com.hikcreate.edl.pub.web.mobile.infra.data.mapper.VerifyInfoMapper
;
import
com.hikcreate.edl.pub.web.mobile.infra.model.entity.ParkBindInfo
;
import
com.hikcreate.edl.pub.web.mobile.infra.model.entity.ParkVerifyInfo
;
import
com.hikcreate.edl.pub.web.mobile.infra.model.param.request.BindInfoQueryReq
;
import
com.hikcreate.edl.pub.web.mobile.infra.model.param.request.BindSmsValidReq
;
import
com.hikcreate.edl.pub.web.mobile.infra.model.param.request.H5BindInfoQuery
;
import
com.hikcreate.edl.pub.web.mobile.infra.model.param.request.UnBindReq
;
import
com.hikcreate.edl.pub.web.mobile.infra.model.param.request.*
;
import
com.hikcreate.edl.pub.web.mobile.infra.model.param.response.BindInfoQueryRes
;
import
com.hikcreate.edl.pub.web.mobile.infra.model.param.response.BindInfoRes
;
import
com.hikcreate.edl.pub.web.mobile.infra.model.param.response.InsuranceInfoRes
;
...
...
@@ -61,6 +59,7 @@ import java.util.ArrayList;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Objects
;
import
java.util.concurrent.TimeUnit
;
import
java.util.stream.Collectors
;
/**
...
...
@@ -91,6 +90,9 @@ public class BindServiceImpl extends ServiceImpl<BindInfoMapper, ParkBindInfo> i
private
DrivingLicenseFeign
drivingLicenseFeign
;
@Autowired
private
SmsFeign
smsFeign
;
@Autowired
DefaultConverter
defaultConverter
;
/**
* 解除绑定时间限制
...
...
@@ -120,9 +122,10 @@ public class BindServiceImpl extends ServiceImpl<BindInfoMapper, ParkBindInfo> i
@Override
@DistributedLock
(
key
=
"'park:extend:lock:bind:userId:'+#
info.userId+':timestamp:'+#info
.timestamp"
,
expireTime
=
@DistributedLock
(
key
=
"'park:extend:lock:bind:userId:'+#
bindInfoReq.userId+':timestamp:'+#bindInfoReq
.timestamp"
,
expireTime
=
3000
,
waitTime
=
2000
,
retryTimes
=
50
)
public
Result
bind
(
ParkBindInfo
info
)
{
public
Result
bind
(
BindInfoReq
bindInfoReq
)
{
ParkBindInfo
info
=
defaultConverter
.
getMapperFacade
().
map
(
bindInfoReq
,
ParkBindInfo
.
class
);
//判断规则1:用户已绑定的车辆不超过3辆,包括已解绑但未过一个月的车辆
QueryWrapper
<
ParkBindInfo
>
boundQuery
=
new
QueryWrapper
();
boundQuery
.
eq
(
"user_id"
,
info
.
getUserId
());
...
...
@@ -192,13 +195,10 @@ public class BindServiceImpl extends ServiceImpl<BindInfoMapper, ParkBindInfo> i
return
ResultGenerator
.
fail
(
ResultCode
.
CAR_HAVE_BIND
);
}
// info.setUnqId(unqIdUtil.getUnqId());
// info.setGmtBindTime(new Date());
// bindCache.insert(info);
//保存至redis
try
{
String
key
=
bindKeyPrefix
.
concat
(
info
.
getPhone
()).
concat
(
"-"
).
concat
(
info
.
getOwnerPhone
());
redisTemplate
.
opsForValue
().
set
(
key
,
objectMapper
.
writeValueAsString
(
info
));
redisTemplate
.
opsForValue
().
set
(
key
,
objectMapper
.
writeValueAsString
(
info
)
,
30
,
TimeUnit
.
MINUTES
);
}
catch
(
Exception
e
)
{
log
.
error
(
"绑定异常:{}"
,
e
.
getMessage
());
return
ResultGenerator
.
fail
(
StatusCode
.
SYSTEM_ERROR
);
...
...
@@ -221,6 +221,7 @@ public class BindServiceImpl extends ServiceImpl<BindInfoMapper, ParkBindInfo> i
*/
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
@DistributedLock
(
key
=
"'park:extend:lock:bind:smsValid:phone:'+#req.phone+':ownerPhone:'+#req.ownerPhone"
,
isSpin
=
false
)
public
Result
bindSmsValid
(
BindSmsValidReq
req
)
{
try
{
//获取缓存信息
...
...
@@ -228,7 +229,7 @@ public class BindServiceImpl extends ServiceImpl<BindInfoMapper, ParkBindInfo> i
String
bindInfoStr
=
redisTemplate
.
opsForValue
().
get
(
key
);
if
(
StrUtil
.
isBlank
(
bindInfoStr
)
)
{
log
.
error
(
"车辆绑定短信验证失败:未发起车辆绑定"
);
return
ResultGenerator
.
fail
(
StatusCode
.
BUSINESS_ERROR
.
getCode
(),
"
请先调车辆绑定接口
"
);
return
ResultGenerator
.
fail
(
StatusCode
.
BUSINESS_ERROR
.
getCode
(),
"
已超时
"
);
}
ParkBindInfo
bindInfo
=
objectMapper
.
readValue
(
bindInfoStr
,
ParkBindInfo
.
class
);
...
...
@@ -236,11 +237,7 @@ public class BindServiceImpl extends ServiceImpl<BindInfoMapper, ParkBindInfo> i
CheckVerifyCodeMicReq
checkVerifyCodeMicReq
=
new
CheckVerifyCodeMicReq
();
checkVerifyCodeMicReq
.
setPhone
(
req
.
getOwnerPhone
())
.
setVerifyCode
(
req
.
getSmsCode
()).
setTemplateCode
(
"PARK_BIND_VEHICLE"
);
long
resultCode
=
smsFeign
.
checkVerifyCode
(
checkVerifyCodeMicReq
).
fallback
().
getCode
();
if
(
StatusCode
.
SUCCESS
.
getCode
()!=
resultCode
)
{
log
.
error
(
"车辆绑定短信验证失败:验证码不正确"
);
return
ResultGenerator
.
fail
(
StatusCode
.
PARAM_ERROR
.
getCode
(),
"验证码不正确"
);
}
smsFeign
.
checkVerifyCode
(
checkVerifyCodeMicReq
).
fallback
();
//绑定信息入库
bindInfo
.
setUnqId
(
unqIdUtil
.
getUnqId
());
...
...
@@ -264,11 +261,10 @@ 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"
,
isSpin
=
false
)
@DistributedLock
(
key
=
"'park:extend:lock:unbind:unqId:'+#req.unqId+':userId:'+#req.userId"
,
isSpin
=
false
)
public
Result
unbindInfo
(
UnBindReq
req
)
{
ParkBindInfo
bindInfo
=
bindCache
.
getById
(
req
.
getUnqId
());
if
(
bindInfo
==
null
||
"0"
.
equals
(
bindInfo
.
getStatus
()))
{
if
(
bindInfo
==
null
||
"0"
.
equals
(
bindInfo
.
getStatus
())
||
!
req
.
getUserId
().
equals
(
bindInfo
.
getUserId
())
)
{
return
ResultGenerator
.
fail
(
ResultCode
.
BIND_INFO_UNKNOWN
);
}
if
(!
bindCache
.
unBind
(
req
.
getUnqId
(),
req
.
getUserId
()))
{
...
...
@@ -280,6 +276,61 @@ public class BindServiceImpl extends ServiceImpl<BindInfoMapper, ParkBindInfo> i
}
/**
* 车辆解绑发送短信(后台操作)
*
* @param req
* @return
*/
@Override
@DistributedLock
(
key
=
"'park:extend:lock:adnmUnbind:unqId:'+#req.unqId"
,
isSpin
=
false
)
public
Result
adminUnbind
(
AdminUnbindReq
req
)
{
//获取绑定信息
ParkBindInfo
parkBindInfo
=
bindCache
.
getById
(
req
.
getUnqId
());
if
(
parkBindInfo
==
null
||
"0"
.
equals
(
parkBindInfo
.
getStatus
())
||
!
parkBindInfo
.
getUserId
().
equals
(
req
.
getUserId
())
)
{
return
ResultGenerator
.
fail
(
ResultCode
.
BIND_INFO_UNKNOWN
);
}
//发送验证码
SendVerifyCodeMicReq
sendMicReq
=
new
SendVerifyCodeMicReq
();
sendMicReq
.
setPhone
(
parkBindInfo
.
getOwnerPhone
());
sendMicReq
.
setVerifyCode
(
VerifyCodeUtil
.
getCode
());
sendMicReq
.
setTemplateCode
(
"PARK_UNBIND_VEHICLE"
);
smsFeign
.
sendVerifyCode
(
sendMicReq
).
fallback
();
return
ResultGenerator
.
success
();
}
/**
* 车辆解绑短信验证(后台操作)
*
* @param req
* @return
*/
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
@DistributedLock
(
key
=
"'park:extend:lock:adminUnbind:smsValid:unqId:'+#req.unqId"
,
isSpin
=
false
)
public
Result
adminUnbindSmsValid
(
AdminUnbindSmsValidReq
req
)
{
//获取绑定信息
ParkBindInfo
parkBindInfo
=
bindCache
.
getById
(
req
.
getUnqId
());
if
(
parkBindInfo
==
null
||
"0"
.
equals
(
parkBindInfo
.
getStatus
())
)
{
return
ResultGenerator
.
fail
(
ResultCode
.
BIND_INFO_UNKNOWN
);
}
//验证短信
CheckVerifyCodeMicReq
checkVerifyCodeMicReq
=
new
CheckVerifyCodeMicReq
();
checkVerifyCodeMicReq
.
setPhone
(
parkBindInfo
.
getOwnerPhone
())
.
setVerifyCode
(
req
.
getSmsCode
()).
setTemplateCode
(
"PARK_UNBIND_VEHICLE"
);
smsFeign
.
checkVerifyCode
(
checkVerifyCodeMicReq
).
fallback
();
//解绑
if
(!
bindCache
.
unBind
(
parkBindInfo
.
getUnqId
(),
parkBindInfo
.
getUserId
()))
{
//手动回滚
TransactionAspectSupport
.
currentTransactionStatus
().
setRollbackOnly
();
return
ResultGenerator
.
fail
(
"解绑失败"
);
}
return
ResultGenerator
.
success
();
}
/**
* 查询用户绑定信息
*
* @param query
...
...
infra/src/main/java/com/hikcreate/edl/pub/web/mobile/infra/model/param/request/BindInfoReq.java
View file @
3a9b199e
...
...
@@ -5,7 +5,6 @@ import lombok.Data;
import
javax.validation.constraints.NotBlank
;
import
javax.validation.constraints.NotNull
;
import
javax.validation.constraints.Pattern
;
import
javax.validation.constraints.Size
;
/**
* @author lixian
...
...
@@ -23,12 +22,13 @@ public class BindInfoReq {
* 客户电话号码
*/
@NotBlank
(
message
=
"客户手机号不能为空"
)
@Pattern
(
regexp
=
"^(1)\\d{10}$"
,
message
=
"客户手机号无效"
)
private
String
phone
;
/**
* 车主手机号码
*/
@NotBlank
(
message
=
"车主手机号不能为空"
)
@
Size
(
max
=
11
,
message
=
"车主手机号无效"
)
@
Pattern
(
regexp
=
"^(1)\\d{10}$"
,
message
=
"车主手机号无效"
)
private
String
ownerPhone
;
/**
* 车牌颜色:A:白,B:灰,C:黄,D:粉,E:红,
...
...
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