Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
X
xyqb-user2
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
head_group
xyqb-user2
Commits
13d043f2
Commit
13d043f2
authored
Jun 11, 2018
by
技术部-任文超
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
补充OpenApi文档
parent
97156dcc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
70 additions
and
61 deletions
+70
-61
SyncUserController.java
...oup/xyqb/controller/external/user/SyncUserController.java
+62
-48
UserDetailController.java
...p/xyqb/controller/internal/user/UserDetailController.java
+8
-13
No files found.
src/main/java/cn/quantgroup/xyqb/controller/external/user/SyncUserController.java
View file @
13d043f2
...
@@ -3,32 +3,35 @@ package cn.quantgroup.xyqb.controller.external.user;
...
@@ -3,32 +3,35 @@ package cn.quantgroup.xyqb.controller.external.user;
import
cn.quantgroup.xyqb.entity.User
;
import
cn.quantgroup.xyqb.entity.User
;
import
cn.quantgroup.xyqb.entity.UserDetail
;
import
cn.quantgroup.xyqb.entity.UserDetail
;
import
cn.quantgroup.xyqb.model.IdCardInfo
;
import
cn.quantgroup.xyqb.model.IdCardInfo
;
import
cn.quantgroup.xyqb.model.IdType
;
import
cn.quantgroup.xyqb.model.JsonResult
;
import
cn.quantgroup.xyqb.model.JsonResult
;
import
cn.quantgroup.xyqb.model.UserModel
;
import
cn.quantgroup.xyqb.model.UserModel
;
import
cn.quantgroup.xyqb.service.auth.IIdCardService
;
import
cn.quantgroup.xyqb.service.auth.IIdCardService
;
import
cn.quantgroup.xyqb.service.user.IUserDetailService
;
import
cn.quantgroup.xyqb.service.user.IUserDetailService
;
import
cn.quantgroup.xyqb.service.user.IUserService
;
import
cn.quantgroup.xyqb.service.user.IUserService
;
import
cn.quantgroup.xyqb.util.ValidationUtil
;
import
cn.quantgroup.xyqb.util.ValidationUtil
;
import
cn.quantgroup.xyqb.validator.ChineseName
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.dao.DataIntegrityViolationException
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.sql.Timestamp
;
import
java.util.Objects
;
import
java.util.Objects
;
/**
/**
* 同步用户数据,第三方模块访问时
* 同步用户数据,第三方模块访问时
* Created by Miraculous on 15/12/29.
* Created by Miraculous on 15/12/29.
*/
*/
@Slf4j
@RestController
@RestController
@RequestMapping
(
"/api/sync"
)
@RequestMapping
(
"/api/sync"
)
public
class
SyncUserController
{
public
class
SyncUserController
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
SyncUserController
.
class
);
private
static
final
String
KEY
=
"abc1234"
;
@Autowired
@Autowired
private
IUserService
userService
;
private
IUserService
userService
;
@Autowired
@Autowired
...
@@ -37,57 +40,57 @@ public class SyncUserController {
...
@@ -37,57 +40,57 @@ public class SyncUserController {
private
IIdCardService
idCardService
;
private
IIdCardService
idCardService
;
@RequestMapping
(
"/user"
)
public
JsonResult
fetchUser
(
String
key
,
String
phoneNo
)
{
if
(
StringUtils
.
isEmpty
(
key
)
||
!
"abc1234"
.
equals
(
key
))
{
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
}
if
(
StringUtils
.
isEmpty
(
phoneNo
))
{
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
}
User
user
=
userService
.
findByPhoneInDb
(
phoneNo
);
if
(
null
==
user
)
{
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
}
UserDetail
detail
=
userDetailService
.
findByUserId
(
user
.
getId
());
if
(
null
==
detail
)
{
// FIXME: 16/4/15 前期不对身份证强制要求.后期对修改
// return JsonResult.buildErrorStateResult(null, null);
}
UserModel
userModel
=
new
UserModel
(
user
,
detail
);
return
JsonResult
.
buildSuccessResult
(
null
,
userModel
);
}
@RequestMapping
(
"/save_detail"
)
@RequestMapping
(
"/save_detail"
)
public
JsonResult
saveUserDetail
(
String
key
,
UserDetail
userDetail
)
{
@ApiOperation
(
httpMethod
=
"POST"
,
value
=
"保存/更新用户实名信息"
)
if
(
StringUtils
.
isEmpty
(
key
)
||
!
"abc1234"
.
equals
(
key
)
||
Objects
.
isNull
(
userDetail
)
||
StringUtils
.
isBlank
(
userDetail
.
getPhoneNo
()))
{
public
JsonResult
saveUserDetail
(
String
key
,
String
phoneNo
,
String
idNo
,
@ChineseName
@RequestParam
String
name
)
{
if
(!
Objects
.
equals
(
KEY
,
key
))
{
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
}
}
if
(!
ValidationUtil
.
validateChinese
(
userDetail
.
getName
()))
{
if
(!
ValidationUtil
.
validatePhoneNo
(
phoneNo
))
{
return
JsonResult
.
buildErrorStateResult
(
"姓名错误"
,
null
);
log
.
error
(
"手机号错误,phoneNo:{}"
,
phoneNo
);
return
JsonResult
.
buildErrorStateResult
(
"手机号错误"
,
phoneNo
);
}
if
(!
ValidationUtil
.
validateChinese
(
name
))
{
log
.
error
(
"姓名错误,name:{}"
,
name
);
return
JsonResult
.
buildErrorStateResult
(
"姓名错误"
,
name
);
}
}
IdCardInfo
info
=
idCardService
.
getIdCardInfo
(
userDetail
.
getIdNo
()
);
IdCardInfo
info
=
idCardService
.
getIdCardInfo
(
idNo
);
if
(
Objects
.
isNull
(
info
)
||
!
info
.
isValid
())
{
if
(
Objects
.
isNull
(
info
)
||
!
info
.
isValid
())
{
LOGGER
.
error
(
"身份证号错误,userId:{},idNo: {}"
,
userDetail
.
getUserId
(),
userDetail
.
getIdNo
()
);
log
.
error
(
"身份证号错误,idNo:{}"
,
idNo
);
return
JsonResult
.
buildErrorStateResult
(
"身份证号码错误"
,
null
);
return
JsonResult
.
buildErrorStateResult
(
"身份证号码错误"
,
idNo
);
}
}
String
phoneNo
=
userDetail
.
getPhoneNo
();
User
user
=
userService
.
findByPhoneWithCache
(
phoneNo
);
User
user
=
userService
.
findByPhoneWithCache
(
phoneNo
);
if
(
Objects
.
isNull
(
user
))
{
if
(
Objects
.
isNull
(
user
))
{
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
log
.
error
(
"用户不存在,phoneNo:{}"
,
phoneNo
);
return
JsonResult
.
buildErrorStateResult
(
"用户不存在"
,
phoneNo
);
}
Timestamp
now
=
new
Timestamp
(
System
.
currentTimeMillis
());
/* 保存或更新 */
UserDetail
userDetail
=
userDetailService
.
findByUserId
(
user
.
getId
());
if
(
Objects
.
isNull
(
userDetail
))
{
userDetail
=
new
UserDetail
();
userDetail
.
setCreatedAt
(
now
);
}
}
userDetail
.
setUserId
(
user
.
getId
());
userDetail
.
setUserId
(
user
.
getId
());
userDetail
.
setIdNo
(
userDetail
.
getIdNo
());
userDetail
.
setPhoneNo
(
user
.
getPhoneNo
());
userDetail
.
setUpdatedAt
(
now
);
userDetail
.
setName
(
userDetail
.
getName
());
userDetail
.
setGender
(
info
.
getGender
());
userDetail
.
setIdType
(
IdType
.
ID_CARD
);
userDetail
.
setIsAuthenticated
(
false
);
try
{
userDetailService
.
saveUserDetail
(
userDetail
);
}
catch
(
DataIntegrityViolationException
ex
)
{
return
JsonResult
.
buildSuccessResult
(
""
,
null
);
}
/*
/*
* 如果已存在记录,则更新
* 如果已存在记录,则更新
*/
*/
UserDetail
theUserDetail
=
userDetailService
.
findByUserId
(
user
.
getId
());
UserDetail
theUserDetail
=
userDetailService
.
findByUserId
(
user
.
getId
());
if
(
Objects
.
isNull
(
theUserDetail
))
{
theUserDetail
=
userDetailService
.
findByPhoneNo
(
phoneNo
);
// 按手机号查出记录,如果userId非空,说明是存疑数据或是其他用户的信息,停止修改操作,返回失败
if
(
Objects
.
nonNull
(
theUserDetail
)
&&
Objects
.
nonNull
(
theUserDetail
.
getUserId
()))
{
return
JsonResult
.
buildErrorStateResult
(
"手机号已使用."
,
null
);
}
}
if
(
Objects
.
isNull
(
theUserDetail
))
{
if
(
Objects
.
isNull
(
theUserDetail
))
{
userDetail
.
setId
(
null
);
userDetail
.
setId
(
null
);
}
else
{
}
else
{
...
@@ -97,9 +100,24 @@ public class SyncUserController {
...
@@ -97,9 +100,24 @@ public class SyncUserController {
return
JsonResult
.
buildSuccessResult
(
null
,
null
);
return
JsonResult
.
buildSuccessResult
(
null
,
null
);
}
}
@RequestMapping
(
"/user"
)
@ApiOperation
(
httpMethod
=
"POST"
,
value
=
"查询用户详情"
)
public
JsonResult
fetchUser
(
String
key
,
String
phoneNo
)
{
if
(!
Objects
.
equals
(
KEY
,
key
)
||
!
ValidationUtil
.
validatePhoneNo
(
phoneNo
))
{
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
}
User
user
=
userService
.
findByPhoneInDb
(
phoneNo
);
if
(
Objects
.
isNull
(
user
))
{
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
}
UserDetail
detail
=
userDetailService
.
findByUserId
(
user
.
getId
());
UserModel
userModel
=
new
UserModel
(
user
,
detail
);
return
JsonResult
.
buildSuccessResult
(
null
,
userModel
);
}
@RequestMapping
(
"/user_uuid"
)
@RequestMapping
(
"/user_uuid"
)
public
JsonResult
fetchUserByUuid
(
String
key
,
String
uuid
)
{
public
JsonResult
fetchUserByUuid
(
String
key
,
String
uuid
)
{
if
(
StringUtils
.
isEmpty
(
key
)
||
!
"abc1234"
.
equals
(
key
))
{
if
(
StringUtils
.
isEmpty
(
key
)
||
!
KEY
.
equals
(
key
))
{
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
}
}
if
(
StringUtils
.
isEmpty
(
uuid
))
{
if
(
StringUtils
.
isEmpty
(
uuid
))
{
...
@@ -110,10 +128,6 @@ public class SyncUserController {
...
@@ -110,10 +128,6 @@ public class SyncUserController {
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
}
}
UserDetail
detail
=
userDetailService
.
findByUserId
(
user
.
getId
());
UserDetail
detail
=
userDetailService
.
findByUserId
(
user
.
getId
());
if
(
null
==
detail
)
{
// FIXME: 16/4/15 前期不对身份证强制要求.后期对修改
// return JsonResult.buildErrorStateResult(null, null);
}
UserModel
userModel
=
new
UserModel
(
user
,
detail
);
UserModel
userModel
=
new
UserModel
(
user
,
detail
);
return
JsonResult
.
buildSuccessResult
(
null
,
userModel
);
return
JsonResult
.
buildSuccessResult
(
null
,
userModel
);
}
}
...
...
src/main/java/cn/quantgroup/xyqb/controller/internal/user/UserDetailController.java
View file @
13d043f2
...
@@ -9,11 +9,14 @@ import cn.quantgroup.xyqb.model.JsonResult;
...
@@ -9,11 +9,14 @@ import cn.quantgroup.xyqb.model.JsonResult;
import
cn.quantgroup.xyqb.service.auth.IIdCardService
;
import
cn.quantgroup.xyqb.service.auth.IIdCardService
;
import
cn.quantgroup.xyqb.service.user.IUserDetailService
;
import
cn.quantgroup.xyqb.service.user.IUserDetailService
;
import
cn.quantgroup.xyqb.util.ValidationUtil
;
import
cn.quantgroup.xyqb.util.ValidationUtil
;
import
cn.quantgroup.xyqb.validator.ChineseName
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.dao.DataIntegrityViolationException
;
import
org.springframework.dao.DataIntegrityViolationException
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.sql.Timestamp
;
import
java.sql.Timestamp
;
...
@@ -34,8 +37,11 @@ public class UserDetailController implements IBaseController {
...
@@ -34,8 +37,11 @@ public class UserDetailController implements IBaseController {
private
IIdCardService
idCardService
;
private
IIdCardService
idCardService
;
@RequestMapping
(
"/save"
)
@RequestMapping
(
"/save"
)
public
JsonResult
saveUserdetail
(
String
idNo
,
String
name
)
{
@ApiOperation
(
httpMethod
=
"POST"
,
value
=
"保存/更新用户实名信息"
)
public
JsonResult
saveUserdetail
(
String
idNo
,
@ChineseName
@RequestParam
String
name
)
{
if
(!
ValidationUtil
.
validateChinese
(
name
))
{
if
(!
ValidationUtil
.
validateChinese
(
name
))
{
log
.
error
(
"姓名错误,name:{}"
,
name
);
return
JsonResult
.
buildErrorStateResult
(
"姓名错误"
,
null
);
return
JsonResult
.
buildErrorStateResult
(
"姓名错误"
,
null
);
}
}
User
user
=
getCurrentUserFromRedis
();
User
user
=
getCurrentUserFromRedis
();
...
@@ -48,17 +54,8 @@ public class UserDetailController implements IBaseController {
...
@@ -48,17 +54,8 @@ public class UserDetailController implements IBaseController {
return
JsonResult
.
buildErrorStateResult
(
"身份证号码错误"
,
null
);
return
JsonResult
.
buildErrorStateResult
(
"身份证号码错误"
,
null
);
}
}
Timestamp
now
=
new
Timestamp
(
System
.
currentTimeMillis
());
Timestamp
now
=
new
Timestamp
(
System
.
currentTimeMillis
());
/*
/* 保存或更新 */
* 如果已存在记录,则更新
*/
UserDetail
userDetail
=
userDetailService
.
findByUserId
(
user
.
getId
());
UserDetail
userDetail
=
userDetailService
.
findByUserId
(
user
.
getId
());
if
(
Objects
.
isNull
(
userDetail
))
{
userDetail
=
userDetailService
.
findByPhoneNo
(
user
.
getPhoneNo
());
// 按手机号查出记录,如果userId非空,说明是存疑数据或是其他用户的信息,停止修改操作,返回失败
if
(
Objects
.
nonNull
(
userDetail
)
&&
Objects
.
nonNull
(
userDetail
.
getUserId
()))
{
return
JsonResult
.
buildErrorStateResult
(
"手机号已使用."
,
null
);
}
}
if
(
Objects
.
isNull
(
userDetail
))
{
if
(
Objects
.
isNull
(
userDetail
))
{
userDetail
=
new
UserDetail
();
userDetail
=
new
UserDetail
();
userDetail
.
setCreatedAt
(
now
);
userDetail
.
setCreatedAt
(
now
);
...
@@ -69,10 +66,8 @@ public class UserDetailController implements IBaseController {
...
@@ -69,10 +66,8 @@ public class UserDetailController implements IBaseController {
userDetail
.
setUpdatedAt
(
now
);
userDetail
.
setUpdatedAt
(
now
);
userDetail
.
setName
(
name
);
userDetail
.
setName
(
name
);
userDetail
.
setGender
(
info
.
getGender
());
userDetail
.
setGender
(
info
.
getGender
());
userDetail
.
setEmail
(
""
);
userDetail
.
setIdType
(
IdType
.
ID_CARD
);
userDetail
.
setIdType
(
IdType
.
ID_CARD
);
userDetail
.
setIsAuthenticated
(
false
);
userDetail
.
setIsAuthenticated
(
false
);
userDetail
.
setQq
(
""
);
try
{
try
{
userDetailService
.
saveUserDetail
(
userDetail
);
userDetailService
.
saveUserDetail
(
userDetail
);
}
catch
(
DataIntegrityViolationException
ex
)
{
}
catch
(
DataIntegrityViolationException
ex
)
{
...
...
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