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
bfe5c5fb
Commit
bfe5c5fb
authored
Jun 07, 2018
by
xiaoguang.xu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat : 1. 更换validator校验方式, 2. 更换注册时处理为异步化, 3. 删除无用的sleep 1
parent
7899269f
Changes
16
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
406 additions
and
123 deletions
+406
-123
MyWebMvcConfigurer.java
...va/cn/quantgroup/xyqb/config/http/MyWebMvcConfigurer.java
+22
-0
ExceptionHandlingController.java
...antgroup/xyqb/controller/ExceptionHandlingController.java
+16
-0
InnerController.java
...tgroup/xyqb/controller/external/user/InnerController.java
+23
-10
SyncUserController.java
...oup/xyqb/controller/external/user/SyncUserController.java
+5
-15
UserDetailController.java
...p/xyqb/controller/internal/user/UserDetailController.java
+45
-55
Contact.java
src/main/java/cn/quantgroup/xyqb/entity/Contact.java
+13
-0
WechatUserInfo.java
src/main/java/cn/quantgroup/xyqb/entity/WechatUserInfo.java
+14
-0
ContactRegisteredEventListener.java
...quantgroup/xyqb/event/ContactRegisteredEventListener.java
+6
-0
IUserRegisterService.java
...uantgroup/xyqb/service/register/IUserRegisterService.java
+6
-2
UserRegisterServiceImpl.java
...p/xyqb/service/register/impl/UserRegisterServiceImpl.java
+64
-6
UserDetailServiceImpl.java
...ntgroup/xyqb/service/user/impl/UserDetailServiceImpl.java
+4
-6
UserServiceImpl.java
...cn/quantgroup/xyqb/service/user/impl/UserServiceImpl.java
+4
-16
WechatServiceImpl.java
...uantgroup/xyqb/service/wechat/impl/WechatServiceImpl.java
+14
-13
ChineseName.java
src/main/java/cn/quantgroup/xyqb/validator/ChineseName.java
+30
-0
ChineseNameValidator.java
...va/cn/quantgroup/xyqb/validator/ChineseNameValidator.java
+34
-0
Enums.java
src/main/java/springfox/documentation/schema/Enums.java
+106
-0
No files found.
src/main/java/cn/quantgroup/xyqb/config/http/MyWebMvcConfigurer.java
View file @
bfe5c5fb
package
cn
.
quantgroup
.
xyqb
.
config
.
http
;
package
cn
.
quantgroup
.
xyqb
.
config
.
http
;
import
org.hibernate.validator.HibernateValidator
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.format.FormatterRegistry
;
import
org.springframework.format.FormatterRegistry
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
org.springframework.validation.beanvalidation.MethodValidationPostProcessor
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
;
import
javax.validation.Validation
;
import
javax.validation.Validator
;
import
javax.validation.ValidatorFactory
;
@Component
@Component
public
class
MyWebMvcConfigurer
extends
WebMvcConfigurerAdapter
{
public
class
MyWebMvcConfigurer
extends
WebMvcConfigurerAdapter
{
...
@@ -13,4 +20,19 @@ public class MyWebMvcConfigurer extends WebMvcConfigurerAdapter {
...
@@ -13,4 +20,19 @@ public class MyWebMvcConfigurer extends WebMvcConfigurerAdapter {
registry
.
addConverterFactory
(
new
IntegerToEnumConverterFactory
());
registry
.
addConverterFactory
(
new
IntegerToEnumConverterFactory
());
}
}
/**
* 快速校验参数. 第一个出错后面的不用再校验了
* @return
*/
@Bean
public
MethodValidationPostProcessor
methodValidationPostProcessor
()
{
MethodValidationPostProcessor
postProcessor
=
new
MethodValidationPostProcessor
();
ValidatorFactory
validatorFactory
=
Validation
.
byProvider
(
HibernateValidator
.
class
)
.
configure
()
.
addProperty
(
"hibernate.validator.fail_fast"
,
"true"
)
.
buildValidatorFactory
();
Validator
validator
=
validatorFactory
.
getValidator
();
postProcessor
.
setValidator
(
validator
);
return
postProcessor
;
}
}
}
\ No newline at end of file
src/main/java/cn/quantgroup/xyqb/controller/ExceptionHandlingController.java
View file @
bfe5c5fb
...
@@ -15,6 +15,10 @@ import org.springframework.web.bind.annotation.ResponseStatus;
...
@@ -15,6 +15,10 @@ import org.springframework.web.bind.annotation.ResponseStatus;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.validation.ConstraintViolation
;
import
javax.validation.ConstraintViolationException
;
import
javax.validation.ValidationException
;
import
java.util.Set
;
/**
/**
* Created by Miraculous on 15/7/6.
* Created by Miraculous on 15/7/6.
...
@@ -92,4 +96,16 @@ public class ExceptionHandlingController implements IBaseController {
...
@@ -92,4 +96,16 @@ public class ExceptionHandlingController implements IBaseController {
LOGGER
.
error
(
"[exception][global_exception]接口异常 URI:{}, registerFrom:{},error={}"
,
uri
,
registerFrom
,
e
);
LOGGER
.
error
(
"[exception][global_exception]接口异常 URI:{}, registerFrom:{},error={}"
,
uri
,
registerFrom
,
e
);
return
EXCEPTION_RESULT
;
return
EXCEPTION_RESULT
;
}
}
@ExceptionHandler
(
ValidationException
.
class
)
public
JsonResult
validException
(
ValidationException
exception
)
{
ConstraintViolationException
exs
=
(
ConstraintViolationException
)
exception
;
Set
<
ConstraintViolation
<?>>
constraintViolations
=
exs
.
getConstraintViolations
();
if
(
constraintViolations
.
isEmpty
())
{
LOGGER
.
error
(
"这里出了个错...."
,
exception
.
getMessage
());
return
null
;
}
String
message
=
constraintViolations
.
iterator
().
next
().
getMessage
();
return
JsonResult
.
buildErrorStateResult
(
message
,
null
);
}
}
}
src/main/java/cn/quantgroup/xyqb/controller/external/user/InnerController.java
View file @
bfe5c5fb
...
@@ -20,6 +20,7 @@ import cn.quantgroup.xyqb.service.user.vo.UserDetailVO;
...
@@ -20,6 +20,7 @@ import cn.quantgroup.xyqb.service.user.vo.UserDetailVO;
import
cn.quantgroup.xyqb.service.wechat.IWechatService
;
import
cn.quantgroup.xyqb.service.wechat.IWechatService
;
import
cn.quantgroup.xyqb.util.*
;
import
cn.quantgroup.xyqb.util.*
;
import
cn.quantgroup.xyqb.util.encrypt.MD5Util
;
import
cn.quantgroup.xyqb.util.encrypt.MD5Util
;
import
cn.quantgroup.xyqb.validator.ChineseName
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.TypeReference
;
import
com.alibaba.fastjson.TypeReference
;
import
com.google.common.base.MoreObjects
;
import
com.google.common.base.MoreObjects
;
...
@@ -35,9 +36,11 @@ import org.apache.commons.lang3.math.NumberUtils;
...
@@ -35,9 +36,11 @@ import org.apache.commons.lang3.math.NumberUtils;
import
org.apache.http.HttpStatus
;
import
org.apache.http.HttpStatus
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.validation.constraints.Min
;
import
java.io.UnsupportedEncodingException
;
import
java.io.UnsupportedEncodingException
;
import
java.sql.Timestamp
;
import
java.sql.Timestamp
;
import
java.text.ParseException
;
import
java.text.ParseException
;
...
@@ -51,6 +54,7 @@ import java.util.stream.Collectors;
...
@@ -51,6 +54,7 @@ import java.util.stream.Collectors;
@Slf4j
@Slf4j
@RestController
@RestController
@RequestMapping
(
"/innerapi"
)
@RequestMapping
(
"/innerapi"
)
@Validated
public
class
InnerController
implements
IBaseController
{
public
class
InnerController
implements
IBaseController
{
@Autowired
@Autowired
...
@@ -89,7 +93,7 @@ public class InnerController implements IBaseController {
...
@@ -89,7 +93,7 @@ public class InnerController implements IBaseController {
};
};
@RequestMapping
(
"/user/search/phoneNo"
)
@RequestMapping
(
"/user/search/phoneNo"
)
@ApiOperation
(
httpMethod
=
"
POS
T"
,
value
=
"根据手机号查询用户信息"
)
@ApiOperation
(
httpMethod
=
"
GE
T"
,
value
=
"根据手机号查询用户信息"
)
public
JsonResult
findByPhoneNo
(
String
phoneNo
)
{
public
JsonResult
findByPhoneNo
(
String
phoneNo
)
{
User
user
=
userService
.
findByPhoneInDb
(
phoneNo
);
User
user
=
userService
.
findByPhoneInDb
(
phoneNo
);
if
(
user
==
null
)
{
if
(
user
==
null
)
{
...
@@ -222,13 +226,12 @@ public class InnerController implements IBaseController {
...
@@ -222,13 +226,12 @@ public class InnerController implements IBaseController {
*/
*/
@RequestMapping
(
"/user_detail/save"
)
@RequestMapping
(
"/user_detail/save"
)
@ApiOperation
(
httpMethod
=
"POST"
,
value
=
"填写用户详情"
)
@ApiOperation
(
httpMethod
=
"POST"
,
value
=
"填写用户详情"
)
public
JsonResult
saveUserDetail
(
Long
userId
,
String
phoneNo
,
String
name
,
String
idNo
,
public
JsonResult
saveUserDetail
(
@Min
(
value
=
1
,
message
=
"用户id为空"
)
Long
userId
,
String
phoneNo
,
@ChineseName
String
name
,
String
idNo
,
String
email
,
String
qq
)
{
String
email
,
String
qq
)
{
log
.
info
(
"保存用户详细信息,[saveUserDetail] userId:{},phoneNo:{},name:{},idNo:{},email:{},qq:{}"
,
userId
,
phoneNo
,
name
,
idNo
,
email
,
qq
);
log
.
info
(
"保存用户详细信息,[saveUserDetail] userId:{},phoneNo:{},name:{},idNo:{},email:{},qq:{}"
,
userId
,
phoneNo
,
name
,
idNo
,
email
,
qq
);
//参数验证
//参数验证
if
(
userId
==
null
||
userId
==
0L
)
{
return
JsonResult
.
buildErrorStateResult
(
"用户id为空."
,
null
);
}
if
(
StringUtils
.
isBlank
(
phoneNo
))
{
if
(
StringUtils
.
isBlank
(
phoneNo
))
{
return
JsonResult
.
buildErrorStateResult
(
"用户手机号为空."
,
null
);
return
JsonResult
.
buildErrorStateResult
(
"用户手机号为空."
,
null
);
}
}
...
@@ -238,9 +241,6 @@ public class InnerController implements IBaseController {
...
@@ -238,9 +241,6 @@ public class InnerController implements IBaseController {
if
(
StringUtils
.
isBlank
(
idNo
))
{
if
(
StringUtils
.
isBlank
(
idNo
))
{
return
JsonResult
.
buildErrorStateResult
(
"用户身份证为空."
,
null
);
return
JsonResult
.
buildErrorStateResult
(
"用户身份证为空."
,
null
);
}
}
if
(!
ValidationUtil
.
validateChinese
(
name
))
{
return
JsonResult
.
buildErrorStateResult
(
"用户姓名错误"
,
null
);
}
IdCardInfo
info
=
idCardService
.
getIdCardInfo
(
idNo
);
IdCardInfo
info
=
idCardService
.
getIdCardInfo
(
idNo
);
if
(
Objects
.
isNull
(
info
)
||
!
info
.
isValid
())
{
if
(
Objects
.
isNull
(
info
)
||
!
info
.
isValid
())
{
log
.
error
(
"用户身份证号错误,userId:{},idNo: {}"
,
userId
,
idNo
);
log
.
error
(
"用户身份证号错误,userId:{},idNo: {}"
,
userId
,
idNo
);
...
@@ -988,7 +988,7 @@ public class InnerController implements IBaseController {
...
@@ -988,7 +988,7 @@ public class InnerController implements IBaseController {
if
(
StringUtils
.
isBlank
(
name
))
{
if
(
StringUtils
.
isBlank
(
name
))
{
return
JsonResult
.
buildErrorStateResult
(
"用户名异常."
,
null
);
return
JsonResult
.
buildErrorStateResult
(
"用户名异常."
,
null
);
}
}
boolean
isIdCard
=
true
;
boolean
isIdCard
;
try
{
try
{
isIdCard
=
idCardService
.
isIdCardValid
(
idNo
);
isIdCard
=
idCardService
.
isIdCardValid
(
idNo
);
}
catch
(
ParseException
e
)
{
}
catch
(
ParseException
e
)
{
...
@@ -1042,7 +1042,20 @@ public class InnerController implements IBaseController {
...
@@ -1042,7 +1042,20 @@ public class InnerController implements IBaseController {
return
JsonResult
.
buildErrorStateResult
(
"用户已存在,手机号被占用"
,
null
);
return
JsonResult
.
buildErrorStateResult
(
"用户已存在,手机号被占用"
,
null
);
}
}
user
=
userRegisterService
.
register
(
Long
.
valueOf
(
registeredFrom
),
Long
.
valueOf
(
channelId
),
phoneNo
,
name
,
idNo
,
addressObj
,
contacts
,
btRegisterChannelId
);
List
<
Contact
>
contactList
=
null
;
if
(
contacts
!=
null
)
{
contactList
=
JSONObject
.
parseObject
(
contacts
,
new
TypeReference
<
List
<
Contact
>>()
{
});
for
(
Contact
contact
:
contactList
)
{
contact
.
setRelation
(
contact
.
getRelation
()
==
null
?
Relation
.
OTHER
:
contact
.
getRelation
());
Tuple
<
String
,
Boolean
>
stringBooleanTuple
=
contact
.
validAndResult
();
if
(!
stringBooleanTuple
.
getValue
())
{
return
JsonResult
.
buildErrorStateResult
(
stringBooleanTuple
.
getKey
(),
null
);
}
}
}
user
=
userRegisterService
.
register
(
Long
.
valueOf
(
registeredFrom
),
Long
.
valueOf
(
channelId
),
phoneNo
,
name
,
idNo
,
addressObj
,
contacts
,
contactList
,
btRegisterChannelId
);
UserRet
userRet
=
new
UserRet
(
user
);
UserRet
userRet
=
new
UserRet
(
user
);
return
JsonResult
.
buildSuccessResult
(
null
,
userRet
);
return
JsonResult
.
buildSuccessResult
(
null
,
userRet
);
...
...
src/main/java/cn/quantgroup/xyqb/controller/external/user/SyncUserController.java
View file @
bfe5c5fb
...
@@ -18,7 +18,6 @@ import org.springframework.data.redis.core.RedisTemplate;
...
@@ -18,7 +18,6 @@ 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.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.text.ParseException
;
import
java.util.Objects
;
import
java.util.Objects
;
/**
/**
...
@@ -38,10 +37,6 @@ public class SyncUserController {
...
@@ -38,10 +37,6 @@ public class SyncUserController {
private
IIdCardService
idCardService
;
private
IIdCardService
idCardService
;
@Autowired
@Qualifier
(
"stringRedisTemplate"
)
private
RedisTemplate
<
String
,
String
>
stringRedisTemplate
;
@RequestMapping
(
"/user"
)
@RequestMapping
(
"/user"
)
public
JsonResult
fetchUser
(
String
key
,
String
phoneNo
)
{
public
JsonResult
fetchUser
(
String
key
,
String
phoneNo
)
{
if
(
StringUtils
.
isEmpty
(
key
)
||
!
"abc1234"
.
equals
(
key
))
{
if
(
StringUtils
.
isEmpty
(
key
)
||
!
"abc1234"
.
equals
(
key
))
{
...
@@ -71,14 +66,9 @@ public class SyncUserController {
...
@@ -71,14 +66,9 @@ public class SyncUserController {
if
(!
ValidationUtil
.
validateChinese
(
userDetail
.
getName
()))
{
if
(!
ValidationUtil
.
validateChinese
(
userDetail
.
getName
()))
{
return
JsonResult
.
buildErrorStateResult
(
"姓名错误"
,
null
);
return
JsonResult
.
buildErrorStateResult
(
"姓名错误"
,
null
);
}
}
IdCardInfo
info
=
null
;
IdCardInfo
info
=
idCardService
.
getIdCardInfo
(
userDetail
.
getIdNo
());
try
{
info
=
idCardService
.
getIdCardInfo
(
userDetail
.
getIdNo
());
}
catch
(
ParseException
ex
)
{
LOGGER
.
error
(
"身份证号错误, idNo: {}"
,
userDetail
.
getIdNo
());
return
JsonResult
.
buildErrorStateResult
(
"身份证号码错误"
,
null
);
}
if
(
Objects
.
isNull
(
info
)
||
!
info
.
isValid
())
{
if
(
Objects
.
isNull
(
info
)
||
!
info
.
isValid
())
{
LOGGER
.
error
(
"身份证号错误,userId:{},idNo: {}"
,
userDetail
.
getUserId
(),
userDetail
.
getIdNo
());
return
JsonResult
.
buildErrorStateResult
(
"身份证号码错误"
,
null
);
return
JsonResult
.
buildErrorStateResult
(
"身份证号码错误"
,
null
);
}
}
String
phoneNo
=
userDetail
.
getPhoneNo
();
String
phoneNo
=
userDetail
.
getPhoneNo
();
...
@@ -87,9 +77,9 @@ public class SyncUserController {
...
@@ -87,9 +77,9 @@ public class SyncUserController {
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
}
}
userDetail
.
setUserId
(
user
.
getId
());
userDetail
.
setUserId
(
user
.
getId
());
/*
/*
* 如果已存在记录,则更新
* 如果已存在记录,则更新
*/
*/
UserDetail
theUserDetail
=
userDetailService
.
findByUserId
(
user
.
getId
());
UserDetail
theUserDetail
=
userDetailService
.
findByUserId
(
user
.
getId
());
if
(
Objects
.
isNull
(
theUserDetail
))
{
if
(
Objects
.
isNull
(
theUserDetail
))
{
theUserDetail
=
userDetailService
.
findByPhoneNo
(
phoneNo
);
theUserDetail
=
userDetailService
.
findByPhoneNo
(
phoneNo
);
...
...
src/main/java/cn/quantgroup/xyqb/controller/internal/user/UserDetailController.java
View file @
bfe5c5fb
...
@@ -9,86 +9,76 @@ import cn.quantgroup.xyqb.model.JsonResult;
...
@@ -9,86 +9,76 @@ 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
org.slf4j.Logger
;
import
lombok.extern.slf4j.Slf4j
;
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.dao.DataIntegrityViolationException
;
import
org.springframework.
data.redis.core.RedisTemplate
;
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.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.sql.Timestamp
;
import
java.sql.Timestamp
;
import
java.text.ParseException
;
import
java.util.Objects
;
import
java.util.Objects
;
/**
/**
* Created by Miraculous on 2017/1/3.
* Created by Miraculous on 2017/1/3.
*/
*/
@Slf4j
@RestController
@RestController
@RequestMapping
(
"/user_detail"
)
@RequestMapping
(
"/user_detail"
)
@Validated
public
class
UserDetailController
implements
IBaseController
{
public
class
UserDetailController
implements
IBaseController
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
UserDetailController
.
class
);
@Autowired
@Autowired
private
IUserDetailService
userDetailService
;
private
IUserDetailService
userDetailService
;
@Autowired
@Autowired
private
IIdCardService
idCardService
;
private
IIdCardService
idCardService
;
private
static
final
Long
MAX_COUNTER
=
1L
;
@Autowired
@Qualifier
(
"stringRedisTemplate"
)
private
RedisTemplate
<
String
,
String
>
stringRedisTemplate
;
@RequestMapping
(
"/save"
)
@RequestMapping
(
"/save"
)
public
JsonResult
saveUserdetail
(
String
idNo
,
String
name
)
{
public
JsonResult
saveUserdetail
(
String
idNo
,
String
name
)
{
try
{
if
(!
ValidationUtil
.
validateChinese
(
name
))
{
if
(!
ValidationUtil
.
validateChinese
(
name
))
{
return
JsonResult
.
buildErrorStateResult
(
"姓名错误"
,
null
);
return
JsonResult
.
buildErrorStateResult
(
"姓名错误"
,
null
);
}
}
User
user
=
getCurrentUserFromRedis
();
IdCardInfo
info
=
idCardService
.
getIdCardInfo
(
idNo
);
if
(
user
==
null
)
{
if
(!
info
.
isValid
())
{
return
JsonResult
.
buildErrorStateResult
(
"系统错误"
,
null
);
return
JsonResult
.
buildErrorStateResult
(
"身份证号码错误"
,
null
);
}
}
IdCardInfo
info
=
idCardService
.
getIdCardInfo
(
idNo
);
User
user
=
getCurrentUserFromRedis
();
if
(
info
==
null
||
!
info
.
isValid
())
{
if
(
user
==
null
)
{
log
.
error
(
"身份证号错误,userId:{}, idNo: {}"
,
user
.
getId
(),
idNo
);
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
))
{
if
(
Objects
.
isNull
(
userDetail
))
{
userDetail
=
userDetailService
.
findByPhoneNo
(
user
.
getPhoneNo
());
userDetail
=
userDetailService
.
findByPhoneNo
(
user
.
getPhoneNo
());
// 按手机号查出记录,如果userId非空,说明是存疑数据或是其他用户的信息,停止修改操作,返回失败
// 按手机号查出记录,如果userId非空,说明是存疑数据或是其他用户的信息,停止修改操作,返回失败
if
(
Objects
.
nonNull
(
userDetail
)
&&
Objects
.
nonNull
(
userDetail
.
getUserId
()))
{
if
(
Objects
.
nonNull
(
userDetail
)
&&
Objects
.
nonNull
(
userDetail
.
getUserId
()))
{
return
JsonResult
.
buildErrorStateResult
(
"手机号已使用."
,
null
);
return
JsonResult
.
buildErrorStateResult
(
"手机号已使用."
,
null
);
}
}
if
(
Objects
.
isNull
(
userDetail
))
{
userDetail
=
new
UserDetail
();
userDetail
.
setCreatedAt
(
now
);
}
userDetail
.
setIdNo
(
idNo
);
userDetail
.
setPhoneNo
(
user
.
getPhoneNo
());
userDetail
.
setUserId
(
user
.
getId
());
userDetail
.
setUpdatedAt
(
now
);
userDetail
.
setName
(
name
);
userDetail
.
setGender
(
info
.
getGender
());
userDetail
.
setEmail
(
""
);
userDetail
.
setIdType
(
IdType
.
ID_CARD
);
userDetail
.
setIsAuthenticated
(
false
);
userDetail
.
setQq
(
""
);
try
{
userDetailService
.
saveUserDetail
(
userDetail
);
}
catch
(
DataIntegrityViolationException
ex
)
{
return
JsonResult
.
buildSuccessResult
(
""
,
null
);
}
}
}
if
(
Objects
.
isNull
(
userDetail
))
{
userDetail
=
new
UserDetail
();
userDetail
.
setCreatedAt
(
now
);
}
userDetail
.
setIdNo
(
idNo
);
userDetail
.
setPhoneNo
(
user
.
getPhoneNo
());
userDetail
.
setUserId
(
user
.
getId
());
userDetail
.
setUpdatedAt
(
now
);
userDetail
.
setName
(
name
);
userDetail
.
setGender
(
info
.
getGender
());
userDetail
.
setEmail
(
""
);
userDetail
.
setIdType
(
IdType
.
ID_CARD
);
userDetail
.
setIsAuthenticated
(
false
);
userDetail
.
setQq
(
""
);
try
{
userDetailService
.
saveUserDetail
(
userDetail
);
}
catch
(
DataIntegrityViolationException
ex
)
{
return
JsonResult
.
buildSuccessResult
(
""
,
null
);
return
JsonResult
.
buildSuccessResult
(
""
,
null
);
}
catch
(
ParseException
ex
)
{
LOGGER
.
error
(
"身份证号错误, idNo: {}"
,
idNo
);
return
JsonResult
.
buildErrorStateResult
(
"身份证号码错误"
,
null
);
}
}
return
JsonResult
.
buildSuccessResult
(
""
,
null
);
}
}
}
}
src/main/java/cn/quantgroup/xyqb/entity/Contact.java
View file @
bfe5c5fb
package
cn
.
quantgroup
.
xyqb
.
entity
;
package
cn
.
quantgroup
.
xyqb
.
entity
;
import
cn.quantgroup.user.enums.Relation
;
import
cn.quantgroup.user.enums.Relation
;
import
cn.quantgroup.xyqb.model.Tuple
;
import
cn.quantgroup.xyqb.util.ValidationUtil
;
import
cn.quantgroup.xyqb.util.ValidationUtil
;
import
lombok.Data
;
import
lombok.Data
;
...
@@ -43,4 +44,16 @@ public class Contact implements Serializable {
...
@@ -43,4 +44,16 @@ public class Contact implements Serializable {
return
(
ValidationUtil
.
validatePhoneNo
(
this
.
phoneNo
)
&&
ValidationUtil
.
validateChinese
(
this
.
name
));
return
(
ValidationUtil
.
validatePhoneNo
(
this
.
phoneNo
)
&&
ValidationUtil
.
validateChinese
(
this
.
name
));
}
}
public
Tuple
<
String
,
Boolean
>
validAndResult
()
{
boolean
phoneValidRes
=
ValidationUtil
.
validatePhoneNo
(
this
.
phoneNo
);
if
(!
phoneValidRes
)
{
return
new
Tuple
<>(
"手机号错误"
,
false
);
}
boolean
nameValid
=
ValidationUtil
.
validateChinese
(
this
.
name
);
if
(!
nameValid
)
{
return
new
Tuple
<>(
"姓名错误"
,
false
);
}
return
new
Tuple
<>(
""
,
true
);
}
}
}
src/main/java/cn/quantgroup/xyqb/entity/WechatUserInfo.java
View file @
bfe5c5fb
package
cn
.
quantgroup
.
xyqb
.
entity
;
package
cn
.
quantgroup
.
xyqb
.
entity
;
import
cn.quantgroup.xyqb.util.EmojiUtil
;
import
lombok.Data
;
import
lombok.Data
;
import
org.springframework.beans.BeanUtils
;
import
javax.persistence.*
;
import
javax.persistence.*
;
import
java.io.Serializable
;
import
java.io.Serializable
;
...
@@ -44,4 +46,16 @@ public class WechatUserInfo implements Serializable {
...
@@ -44,4 +46,16 @@ public class WechatUserInfo implements Serializable {
private
Timestamp
createdAt
=
new
Timestamp
(
System
.
currentTimeMillis
());
private
Timestamp
createdAt
=
new
Timestamp
(
System
.
currentTimeMillis
());
@Column
(
name
=
"updated_at"
)
@Column
(
name
=
"updated_at"
)
private
Timestamp
updatedAt
=
new
Timestamp
(
System
.
currentTimeMillis
());
private
Timestamp
updatedAt
=
new
Timestamp
(
System
.
currentTimeMillis
());
public
WechatUserInfo
convertEmoji
()
{
WechatUserInfo
wechatUserInfo
=
new
WechatUserInfo
();
BeanUtils
.
copyProperties
(
this
,
wechatUserInfo
);
wechatUserInfo
.
setNickName
(
EmojiUtil
.
filterUnicode4
(
this
.
getNickName
()));
wechatUserInfo
.
setProvince
(
EmojiUtil
.
filterUnicode4
(
this
.
getProvince
()));
wechatUserInfo
.
setCity
(
EmojiUtil
.
filterUnicode4
(
this
.
getCity
()));
wechatUserInfo
.
setCountry
(
EmojiUtil
.
filterUnicode4
(
this
.
getCountry
()));
return
wechatUserInfo
;
}
}
}
src/main/java/cn/quantgroup/xyqb/event/ContactRegisteredEventListener.java
View file @
bfe5c5fb
package
cn
.
quantgroup
.
xyqb
.
event
;
package
cn
.
quantgroup
.
xyqb
.
event
;
import
cn.quantgroup.xyqb.entity.Contact
;
import
cn.quantgroup.xyqb.entity.Contact
;
import
cn.quantgroup.xyqb.entity.User
;
import
cn.quantgroup.xyqb.model.UserRegisterParam
;
import
cn.quantgroup.xyqb.model.UserRegisterParam
;
import
cn.quantgroup.xyqb.repository.IContactRepository
;
import
cn.quantgroup.xyqb.repository.IContactRepository
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.ApplicationListener
;
import
org.springframework.context.ApplicationListener
;
import
org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.CollectionUtils
;
...
@@ -25,9 +27,13 @@ public class ContactRegisteredEventListener implements ApplicationListener<Regis
...
@@ -25,9 +27,13 @@ public class ContactRegisteredEventListener implements ApplicationListener<Regis
public
void
onApplicationEvent
(
RegisterEvent
event
)
{
public
void
onApplicationEvent
(
RegisterEvent
event
)
{
UserRegisterParam
userRegisterParam
=
event
.
getUserRegisterParam
();
UserRegisterParam
userRegisterParam
=
event
.
getUserRegisterParam
();
List
<
Contact
>
contactList
=
userRegisterParam
.
getContactList
();
List
<
Contact
>
contactList
=
userRegisterParam
.
getContactList
();
User
user
=
userRegisterParam
.
getUser
();
if
(
CollectionUtils
.
isEmpty
(
contactList
))
{
if
(
CollectionUtils
.
isEmpty
(
contactList
))
{
return
;
return
;
}
}
contactList
.
forEach
(
contact
->
contact
.
setUserId
(
user
.
getId
()));
contactRepository
.
save
(
contactList
);
contactRepository
.
save
(
contactList
);
}
}
}
}
src/main/java/cn/quantgroup/xyqb/service/register/IUserRegisterService.java
View file @
bfe5c5fb
package
cn
.
quantgroup
.
xyqb
.
service
.
register
;
package
cn
.
quantgroup
.
xyqb
.
service
.
register
;
import
cn.quantgroup.xyqb.entity.Address
;
import
cn.quantgroup.xyqb.entity.Address
;
import
cn.quantgroup.xyqb.entity.Contact
;
import
cn.quantgroup.xyqb.entity.User
;
import
cn.quantgroup.xyqb.entity.User
;
import
cn.quantgroup.xyqb.model.UserRegisterParam
;
import
cn.quantgroup.xyqb.model.UserRegisterParam
;
import
java.util.List
;
/**
/**
* Created by liqing on 2017/12/4 0004.
* @author liqing
* @date 2017/12/4 0004
*/
*/
public
interface
IUserRegisterService
{
public
interface
IUserRegisterService
{
...
@@ -79,7 +83,7 @@ public interface IUserRegisterService {
...
@@ -79,7 +83,7 @@ public interface IUserRegisterService {
* @author jinsong.zhu 2018年05月16日14:22:13
* @author jinsong.zhu 2018年05月16日14:22:13
* 处理对address和contact的非必要兼容
* 处理对address和contact的非必要兼容
*/
*/
User
register
(
Long
registeredFrom
,
Long
channelId
,
String
phoneNo
,
String
name
,
String
idNo
,
Address
addressObj
,
String
contacts
,
Long
btRegisterChannelId
);
User
register
(
Long
registeredFrom
,
Long
channelId
,
String
phoneNo
,
String
name
,
String
idNo
,
Address
addressObj
,
String
contacts
,
L
ist
<
Contact
>
contactList
,
L
ong
btRegisterChannelId
);
}
}
src/main/java/cn/quantgroup/xyqb/service/register/impl/UserRegisterServiceImpl.java
View file @
bfe5c5fb
package
cn
.
quantgroup
.
xyqb
.
service
.
register
.
impl
;
package
cn
.
quantgroup
.
xyqb
.
service
.
register
.
impl
;
import
cn.quantgroup.xyqb.Constants
;
import
cn.quantgroup.xyqb.entity.Address
;
import
cn.quantgroup.xyqb.entity.Address
;
import
cn.quantgroup.xyqb.entity.Contact
;
import
cn.quantgroup.xyqb.entity.User
;
import
cn.quantgroup.xyqb.entity.User
;
import
cn.quantgroup.xyqb.event.RegisterEvent
;
import
cn.quantgroup.xyqb.model.UserRegisterParam
;
import
cn.quantgroup.xyqb.model.UserRegisterParam
;
import
cn.quantgroup.xyqb.service.register.AbstractUserRegisterService
;
import
cn.quantgroup.xyqb.service.register.AbstractUserRegisterService
;
import
cn.quantgroup.xyqb.service.user.IUserService
;
import
cn.quantgroup.xyqb.util.PasswordUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.ApplicationEventPublisher
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.sql.Timestamp
;
import
java.util.List
;
import
java.util.Objects
;
import
java.util.UUID
;
/**
/**
* Created by liqing on 2017/12/4 0004.
* @author liqing
* @date 2017/12/4 0004
*/
*/
@Service
(
"userRegisterService"
)
@Service
(
"userRegisterService"
)
@Slf4j
@Slf4j
public
class
UserRegisterServiceImpl
extends
AbstractUserRegisterService
{
public
class
UserRegisterServiceImpl
extends
AbstractUserRegisterService
{
@Autowired
private
ApplicationEventPublisher
applicationEventPublisher
;
@Autowired
private
IUserService
userService
;
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Override
@Override
public
User
registerDefault
(
UserRegisterParam
userRegisterParam
)
{
public
User
registerDefault
(
UserRegisterParam
userRegisterParam
)
{
...
@@ -36,7 +56,39 @@ public class UserRegisterServiceImpl extends AbstractUserRegisterService {
...
@@ -36,7 +56,39 @@ public class UserRegisterServiceImpl extends AbstractUserRegisterService {
.
generateRandomPwd
(
true
).
sendSuccessSms
(
true
).
sendAppSms
(
true
)
.
generateRandomPwd
(
true
).
sendSuccessSms
(
true
).
sendAppSms
(
true
)
.
sendSuccessMq
(
true
)
.
sendSuccessMq
(
true
)
.
build
();
.
build
();
return
registerDefault
(
userRegisterParam
);
User
user
=
saveUser
(
userRegisterParam
);
applicationEventPublisher
.
publishEvent
(
new
RegisterEvent
(
this
,
userRegisterParam
));
return
user
;
}
private
User
saveUser
(
UserRegisterParam
userRegisterParam
)
{
String
uuid
=
UUID
.
randomUUID
().
toString
();
User
user
=
new
User
();
user
.
setUuid
(
uuid
);
user
.
setEnable
(
true
);
user
.
setPhoneNo
(
userRegisterParam
.
getPhoneNo
());
Long
registerFrom
=
userRegisterParam
.
getRegisterFrom
();
if
(
Objects
.
isNull
(
registerFrom
))
{
registerFrom
=
1L
;
}
Long
channelId
=
userRegisterParam
.
getChannelId
();
if
(
Objects
.
equals
(
channelId
,
222L
))
{
user
.
setRegisteredFrom
(
channelId
);
}
else
{
user
.
setRegisteredFrom
(
registerFrom
);
}
String
password
=
StringUtils
.
defaultString
(
userRegisterParam
.
getPassword
(),
""
);
// 如果需要生成随机密码
if
(
userRegisterParam
.
isGenerateRandomPwd
())
{
password
=
PasswordUtil
.
generateRandomPwd
(
Constants
.
RANDOM_PWD_LEN
);
}
user
.
setPassword
(
PasswordUtil
.
MD5
(
password
.
toLowerCase
()
+
Constants
.
PASSWORD_SALT
));
Timestamp
currentTime
=
new
Timestamp
(
System
.
currentTimeMillis
());
user
.
setUpdatedAt
(
currentTime
);
user
.
setCreatedAt
(
currentTime
);
user
=
userService
.
saveUser
(
user
);
userRegisterParam
.
setUser
(
user
);
return
user
;
}
}
...
@@ -50,7 +102,8 @@ public class UserRegisterServiceImpl extends AbstractUserRegisterService {
...
@@ -50,7 +102,8 @@ public class UserRegisterServiceImpl extends AbstractUserRegisterService {
.
generateRandomPwd
(
false
).
sendSuccessSms
(
true
).
sendAppSms
(
true
)
.
generateRandomPwd
(
false
).
sendSuccessSms
(
true
).
sendAppSms
(
true
)
.
sendSuccessMq
(
true
)
.
sendSuccessMq
(
true
)
.
build
();
.
build
();
User
user
=
registerDefault
(
userRegisterParam
);
User
user
=
saveUser
(
userRegisterParam
);
applicationEventPublisher
.
publishEvent
(
new
RegisterEvent
(
this
,
userRegisterParam
));
return
user
!=
null
;
return
user
!=
null
;
}
}
...
@@ -64,21 +117,26 @@ public class UserRegisterServiceImpl extends AbstractUserRegisterService {
...
@@ -64,21 +117,26 @@ public class UserRegisterServiceImpl extends AbstractUserRegisterService {
.
generateRandomPwd
(
true
).
sendSuccessSms
(
true
).
sendAppSms
(
true
)
.
generateRandomPwd
(
true
).
sendSuccessSms
(
true
).
sendAppSms
(
true
)
.
sendSuccessMq
(
true
)
.
sendSuccessMq
(
true
)
.
build
();
.
build
();
return
registerDefault
(
userRegisterParam
);
User
user
=
saveUser
(
userRegisterParam
);
applicationEventPublisher
.
publishEvent
(
new
RegisterEvent
(
this
,
userRegisterParam
));
return
user
;
}
}
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Override
@Override
public
User
register
(
Long
registeredFrom
,
Long
channelId
,
String
phoneNo
,
String
name
,
String
idNo
,
Address
addressObj
,
String
contacts
,
Long
btRegisterChannelId
)
{
public
User
register
(
Long
registeredFrom
,
Long
channelId
,
String
phoneNo
,
String
name
,
String
idNo
,
Address
addressObj
,
String
contacts
,
L
ist
<
Contact
>
contactList
,
L
ong
btRegisterChannelId
)
{
UserRegisterParam
userRegisterParam
=
UserRegisterParam
.
builder
()
UserRegisterParam
userRegisterParam
=
UserRegisterParam
.
builder
()
.
registerFrom
(
registeredFrom
).
phoneNo
(
phoneNo
).
idNo
(
idNo
).
name
(
name
)
.
registerFrom
(
registeredFrom
).
phoneNo
(
phoneNo
).
idNo
(
idNo
).
name
(
name
)
.
channelId
(
channelId
)
.
channelId
(
channelId
)
.
btRegisterChannelId
(
btRegisterChannelId
)
.
btRegisterChannelId
(
btRegisterChannelId
)
.
address
(
addressObj
).
contacts
(
contacts
)
.
address
(
addressObj
).
contacts
(
contacts
)
.
contactList
(
contactList
)
.
generateRandomPwd
(
true
).
sendSuccessSms
(
true
).
sendAppSms
(
true
)
.
generateRandomPwd
(
true
).
sendSuccessSms
(
true
).
sendAppSms
(
true
)
.
sendSuccessMq
(
true
)
.
sendSuccessMq
(
true
)
.
build
();
.
build
();
return
registerExt
(
userRegisterParam
);
User
user
=
saveUser
(
userRegisterParam
);
applicationEventPublisher
.
publishEvent
(
new
RegisterEvent
(
this
,
userRegisterParam
));
return
user
;
}
}
}
}
src/main/java/cn/quantgroup/xyqb/service/user/impl/UserDetailServiceImpl.java
View file @
bfe5c5fb
...
@@ -25,7 +25,6 @@ import org.springframework.stereotype.Service;
...
@@ -25,7 +25,6 @@ import org.springframework.stereotype.Service;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.CollectionUtils
;
import
javax.persistence.criteria.Predicate
;
import
javax.persistence.criteria.Predicate
;
import
java.text.ParseException
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -183,13 +182,12 @@ public class UserDetailServiceImpl implements IUserDetailService {
...
@@ -183,13 +182,12 @@ public class UserDetailServiceImpl implements IUserDetailService {
UserDetail
userDetail
=
userDetailRepository
.
findByPhoneNo
(
phoneNo
);
UserDetail
userDetail
=
userDetailRepository
.
findByPhoneNo
(
phoneNo
);
if
(
null
!=
userDetail
)
{
if
(
null
!=
userDetail
)
{
if
(
StringUtils
.
isNotBlank
(
idNo
))
{
if
(
StringUtils
.
isNotBlank
(
idNo
))
{
try
{
IdCardInfo
idCardInfo
=
idCardService
.
getIdCardInfo
(
idNo
);
IdCardInfo
idCardInfo
=
idCardService
.
getIdCardInfo
(
idNo
);
if
(
idCardInfo
==
null
||
!
idCardInfo
.
isValid
())
{
return
userDetailRepository
.
updateIdNoByPhoneNo
(
idCardInfo
.
getIdNo
(),
Optional
.
ofNullable
(
idCardInfo
.
getGender
()).
orElse
(
Gender
.
UNKNOWN
).
ordinal
(),
phoneNo
);
LOGGER
.
error
(
"用户的身份证错误,phoneNo:{},idNo:{}"
,
phoneNo
,
idNo
);
}
catch
(
ParseException
e
)
{
LOGGER
.
error
(
"用户的身份证错误,phoneNo:{},e:{}"
,
phoneNo
,
e
);
return
0
;
return
0
;
}
}
return
userDetailRepository
.
updateIdNoByPhoneNo
(
idCardInfo
.
getIdNo
(),
Optional
.
ofNullable
(
idCardInfo
.
getGender
()).
orElse
(
Gender
.
UNKNOWN
).
ordinal
(),
phoneNo
);
}
}
if
(
StringUtils
.
isNotBlank
(
name
)
&&
ValidationUtil
.
validateChinese
(
name
))
{
if
(
StringUtils
.
isNotBlank
(
name
)
&&
ValidationUtil
.
validateChinese
(
name
))
{
return
userDetailRepository
.
updateNameByPhoneNo
(
name
,
phoneNo
);
return
userDetailRepository
.
updateNameByPhoneNo
(
name
,
phoneNo
);
...
...
src/main/java/cn/quantgroup/xyqb/service/user/impl/UserServiceImpl.java
View file @
bfe5c5fb
...
@@ -52,20 +52,8 @@ public class UserServiceImpl implements IUserService {
...
@@ -52,20 +52,8 @@ public class UserServiceImpl implements IUserService {
return
Maps
.
newHashMap
();
return
Maps
.
newHashMap
();
}
}
Map
<
Long
,
String
>
userIdAndPhoneMap
=
Maps
.
newHashMap
();
Map
<
Long
,
String
>
userIdAndPhoneMap
=
Maps
.
newHashMap
();
int
pageSize
=
1000
;
List
<
User
>
users
=
userRepository
.
findByIdIn
(
userIds
);
int
idSize
=
userIds
.
size
();
users
.
forEach
(
user
->
userIdAndPhoneMap
.
put
(
user
.
getId
(),
user
.
getPhoneNo
()));
for
(
int
i
=
0
;
i
<
idSize
;
i
+=
pageSize
)
{
List
<
Long
>
subList
=
userIds
.
subList
(
i
,
Math
.
min
(
idSize
,
i
+
pageSize
));
List
<
User
>
users
=
userRepository
.
findByIdIn
(
subList
);
users
.
stream
().
forEach
(
user
->
userIdAndPhoneMap
.
put
(
user
.
getId
(),
user
.
getPhoneNo
()));
if
(
i
+
pageSize
<
idSize
)
{
try
{
Thread
.
sleep
(
1
);
}
catch
(
InterruptedException
e
)
{
log
.
error
(
"线程sleep失败"
,
e
);
}
}
}
return
userIdAndPhoneMap
;
return
userIdAndPhoneMap
;
}
}
...
@@ -150,11 +138,11 @@ public class UserServiceImpl implements IUserService {
...
@@ -150,11 +138,11 @@ public class UserServiceImpl implements IUserService {
public
List
<
UserInfo
>
findUserInfosByPhones
(
List
<
String
>
phones
)
{
public
List
<
UserInfo
>
findUserInfosByPhones
(
List
<
String
>
phones
)
{
List
<
User
>
users
=
findByPhones
(
phones
);
List
<
User
>
users
=
findByPhones
(
phones
);
if
(
CollectionUtils
.
isEmpty
(
phones
))
{
if
(
CollectionUtils
.
isEmpty
(
phones
))
{
return
Collections
.
emptyList
();
return
Collections
.
emptyList
();
}
}
List
<
UserDetail
>
userDetails
=
userDetailService
.
findByPhones
(
phones
);
List
<
UserDetail
>
userDetails
=
userDetailService
.
findByPhones
(
phones
);
if
(!
CollectionUtils
.
isEmpty
(
users
))
{
if
(!
CollectionUtils
.
isEmpty
(
users
))
{
Map
<
Long
,
User
>
userMap
=
Maps
.
newHashMapWithExpectedSize
(
users
.
size
());
Map
<
Long
,
User
>
userMap
=
Maps
.
newHashMapWithExpectedSize
(
users
.
size
());
...
...
src/main/java/cn/quantgroup/xyqb/service/wechat/impl/WechatServiceImpl.java
View file @
bfe5c5fb
...
@@ -131,19 +131,20 @@ public class WechatServiceImpl implements IWechatService {
...
@@ -131,19 +131,20 @@ public class WechatServiceImpl implements IWechatService {
if
(
null
==
userInfo
.
getPhoneNo
())
{
if
(
null
==
userInfo
.
getPhoneNo
())
{
userInfo
.
setPhoneNo
(
""
);
userInfo
.
setPhoneNo
(
""
);
}
}
// 微信用户首次登录界面, 首先保存userInfo, 跳入到微信注册登录界面
// // 微信用户首次登录界面, 首先保存userInfo, 跳入到微信注册登录界面
// 替换所有,UTF-8编码时4字节的Emoji表情字符
// // 替换所有,UTF-8编码时4字节的Emoji表情字符
String
nickName
=
EmojiUtil
.
filterUnicode4
(
userInfo
.
getNickName
());
// String nickName = EmojiUtil.filterUnicode4(userInfo.getNickName());
userInfo
.
setNickName
(
nickName
);
// userInfo.setNickName(nickName);
// 替换所有,UTF-8编码时4字节的Emoji表情字符
// // 替换所有,UTF-8编码时4字节的Emoji表情字符
String
country
=
EmojiUtil
.
filterUnicode4
(
userInfo
.
getCountry
());
// String country = EmojiUtil.filterUnicode4(userInfo.getCountry());
userInfo
.
setCountry
(
country
);
// userInfo.setCountry(country);
// 替换所有,UTF-8编码时4字节的Emoji表情字符
// // 替换所有,UTF-8编码时4字节的Emoji表情字符
String
prvince
=
EmojiUtil
.
filterUnicode4
(
userInfo
.
getProvince
());
// String prvince = EmojiUtil.filterUnicode4(userInfo.getProvince());
userInfo
.
setProvince
(
prvince
);
// userInfo.setProvince(prvince);
// 替换所有,UTF-8编码时4字节的Emoji表情字符
// // 替换所有,UTF-8编码时4字节的Emoji表情字符
String
city
=
EmojiUtil
.
filterUnicode4
(
userInfo
.
getCity
());
// String city = EmojiUtil.filterUnicode4(userInfo.getCity());
userInfo
.
setCity
(
city
);
// userInfo.setCity(city);
userInfo
=
userInfo
.
convertEmoji
();
return
weChatUserRepository
.
save
(
userInfo
);
return
weChatUserRepository
.
save
(
userInfo
);
}
}
...
...
src/main/java/cn/quantgroup/xyqb/validator/ChineseName.java
0 → 100644
View file @
bfe5c5fb
package
cn
.
quantgroup
.
xyqb
.
validator
;
import
javax.validation.Constraint
;
import
javax.validation.Payload
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.Target
;
@Target
({
ElementType
.
FIELD
,
ElementType
.
PARAMETER
})
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Constraint
(
validatedBy
=
ChineseNameValidator
.
class
)
public
@interface
ChineseName
{
/**
* 出错提示
*
* @return
*/
String
message
()
default
"用户姓名错误"
;
/**
* 啥玩意?
*
* @return
*/
Class
<?>[]
groups
()
default
{};
Class
<?
extends
Payload
>[]
payload
()
default
{};
}
src/main/java/cn/quantgroup/xyqb/validator/ChineseNameValidator.java
0 → 100644
View file @
bfe5c5fb
package
cn
.
quantgroup
.
xyqb
.
validator
;
import
cn.quantgroup.xyqb.util.ValidationUtil
;
import
javax.validation.ConstraintValidator
;
import
javax.validation.ConstraintValidatorContext
;
/**
* 中文姓名验证器, <ChineseName,String> String 对应的是可以对哪些类型校验
*
* @author ag
*/
public
class
ChineseNameValidator
implements
ConstraintValidator
<
ChineseName
,
String
>
{
/**
* 这个方法在初始化的时候调用. 如果配置错了, 你可以抛一个异常. 启动就报错了
*
* @param constraint
*/
@Override
public
void
initialize
(
ChineseName
constraint
)
{
}
/**
* 这....true = 校验通过. false = 校验失败
*
* @param userName 就是那个String
* @param context
* @return
*/
@Override
public
boolean
isValid
(
String
userName
,
ConstraintValidatorContext
context
)
{
return
ValidationUtil
.
validateChinese
(
userName
);
}
}
src/main/java/springfox/documentation/schema/Enums.java
0 → 100644
View file @
bfe5c5fb
/*
*
* Copyright 2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*
*/
package
springfox
.
documentation
.
schema
;
import
com.fasterxml.jackson.annotation.JsonValue
;
import
com.google.common.base.Function
;
import
com.google.common.base.Optional
;
import
org.springframework.core.annotation.AnnotationUtils
;
import
springfox.documentation.service.AllowableListValues
;
import
springfox.documentation.service.AllowableValues
;
import
java.lang.reflect.Method
;
import
java.util.ArrayList
;
import
java.util.LinkedHashSet
;
import
java.util.List
;
import
java.util.Set
;
import
static
com
.
google
.
common
.
base
.
Strings
.
isNullOrEmpty
;
import
static
com
.
google
.
common
.
collect
.
Lists
.
transform
;
import
static
java
.
util
.
Arrays
.
asList
;
/**
* 增加对enum name 的支持
*/
public
class
Enums
{
private
Enums
()
{
throw
new
UnsupportedOperationException
();
}
public
static
AllowableValues
allowableValues
(
Class
<?>
type
)
{
if
(
type
.
isEnum
())
{
List
<
String
>
enumValues
=
getEnumValues
(
type
);
return
new
AllowableListValues
(
enumValues
,
"LIST"
);
}
return
null
;
}
static
List
<
String
>
getEnumValues
(
final
Class
<?>
subject
)
{
return
transformUnique
(
subject
.
getEnumConstants
(),
new
Function
<
Object
,
String
>()
{
@Override
public
String
apply
(
Object
input
)
{
Optional
<
String
>
jsonValue
=
findJsonValueAnnotatedMethod
(
input
)
.
transform
(
evaluateJsonValue
(
input
));
if
(
jsonValue
.
isPresent
()
&&
!
isNullOrEmpty
(
jsonValue
.
get
()))
{
return
jsonValue
.
get
();
}
return
((
Enum
)
input
).
name
();
}
});
}
@SuppressWarnings
(
"PMD"
)
private
static
Function
<
Method
,
String
>
evaluateJsonValue
(
final
Object
enumConstant
)
{
return
new
Function
<
Method
,
String
>()
{
@Override
public
String
apply
(
Method
input
)
{
try
{
return
input
.
invoke
(
enumConstant
).
toString
();
}
catch
(
Exception
ignored
)
{
}
return
""
;
}
};
}
private
static
<
E
>
List
<
String
>
transformUnique
(
E
[]
values
,
Function
<
E
,
String
>
mapper
)
{
List
<
String
>
nonUniqueValues
=
transform
(
asList
(
values
),
mapper
);
Set
<
String
>
uniqueValues
=
new
LinkedHashSet
<
String
>(
nonUniqueValues
);
return
new
ArrayList
<
String
>(
uniqueValues
);
}
private
static
Optional
<
Method
>
findJsonValueAnnotatedMethod
(
Object
enumConstant
)
{
for
(
Method
each
:
enumConstant
.
getClass
().
getMethods
())
{
JsonValue
jsonValue
=
AnnotationUtils
.
findAnnotation
(
each
,
JsonValue
.
class
);
if
(
jsonValue
!=
null
&&
jsonValue
.
value
())
{
return
Optional
.
of
(
each
);
}
}
return
Optional
.
absent
();
}
public
static
AllowableValues
emptyListValuesToNull
(
AllowableListValues
values
)
{
if
(!
values
.
getValues
().
isEmpty
())
{
return
values
;
}
return
null
;
}
}
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