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
f7694f9f
Commit
f7694f9f
authored
Jul 13, 2020
by
董建华
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
邮箱格式校验
parent
78882590
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
73 additions
and
7 deletions
+73
-7
UserDetailServiceImpl.java
...ntgroup/xyqb/service/user/impl/UserDetailServiceImpl.java
+4
-1
AddressFilter.java
src/main/java/cn/quantgroup/xyqb/util/AddressFilter.java
+69
-6
No files found.
src/main/java/cn/quantgroup/xyqb/service/user/impl/UserDetailServiceImpl.java
View file @
f7694f9f
...
...
@@ -12,6 +12,7 @@ import cn.quantgroup.xyqb.repository.IUserRepository;
import
cn.quantgroup.xyqb.service.auth.IIdCardService
;
import
cn.quantgroup.xyqb.service.user.IUserDetailService
;
import
cn.quantgroup.xyqb.service.user.vo.UserDetailVO
;
import
cn.quantgroup.xyqb.util.AddressFilter
;
import
cn.quantgroup.xyqb.util.ValidationUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang.StringUtils
;
...
...
@@ -51,7 +52,9 @@ public class UserDetailServiceImpl implements IUserDetailService {
@Override
public
UserDetail
findByUserId
(
Long
userId
)
{
return
userDetailRepository
.
findByUserId
(
userId
);
UserDetail
userDetail
=
userDetailRepository
.
findByUserId
(
userId
);
userDetail
.
setEmail
(
AddressFilter
.
getEmail
(
userDetail
.
getPhoneNo
(),
userDetail
.
getEmail
()));
return
userDetail
;
}
@Override
...
...
src/main/java/cn/quantgroup/xyqb/util/AddressFilter.java
View file @
f7694f9f
package
cn
.
quantgroup
.
xyqb
.
util
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Maps
;
import
lombok.AllArgsConstructor
;
import
lombok.Getter
;
import
lombok.Setter
;
import
org.apache.commons.lang3.StringUtils
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
/**
* @author :dongjianhua
...
...
@@ -16,23 +21,49 @@ import java.util.List;
* @version: 1.0
*/
public
class
AddressFilter
{
//移动运营商开头
private
static
final
List
<
String
>
MOBILE
=
Lists
.
newArrayList
(
"134"
,
"135"
,
"136"
,
"137"
,
"138"
,
"139"
,
"147"
,
"150"
,
"151"
,
"152"
,
"157"
,
"158"
,
"159"
,
"178"
,
"182"
,
"183"
,
"184"
,
"187"
,
"188"
,
"198"
);
//电信
private
static
final
List
<
String
>
TELECOM
=
Lists
.
newArrayList
(
"133"
,
"153"
,
"180"
,
"181"
,
"189"
,
"177"
);
//联通
private
static
final
List
<
String
>
UNICOM
=
Lists
.
newArrayList
(
"130"
,
"131"
,
"132"
,
"145"
,
"155"
,
"156"
,
"176"
,
"185"
,
"186"
);
//运营商
private
static
final
Map
<
List
<
String
>,
String
>
OPERATO_MAP
=
Maps
.
newConcurrentMap
();
//联通后缀
private
static
final
String
UNICOM_SUFFIX
=
"@wo.cn"
;
private
static
final
List
<
Pattern
>
PATTERN_LIST
=
Lists
.
newArrayList
();
private
static
final
List
<
PatternEntry
>
PATTERN_LIST
=
Lists
.
newArrayList
();
//邮箱正则
private
static
Pattern
EMAIL_PATTERN
=
Pattern
.
compile
(
"^[A-Za-z0-9]+([._\\-]*[A-Za-z0-9])*@[A-Za-z0-9]+((\\.|-)[A-Za-z0-9]+)*\\.[A-Za-z0-9]+$"
);
static
{
PATTERN_LIST
.
add
(
new
Pattern
(
"|"
,
""
));
synchronized
(
AddressFilter
.
class
)
{
if
(
PATTERN_LIST
.
size
()
==
0
)
{
PATTERN_LIST
.
add
(
new
PatternEntry
(
"|"
,
""
));
OPERATO_MAP
.
put
(
MOBILE
,
"@139.com"
);
OPERATO_MAP
.
put
(
TELECOM
,
"@189.cn"
);
// OPERATO_MAP.put(UNICOM,"@wo.cn");
}
}
}
/**
* 是否包含特殊字符
*
* @param address
* @return
*/
public
static
boolean
isIncSpeChar
(
String
address
)
{
if
(!
StringUtils
.
isNotEmpty
(
address
))
{
if
(!
StringUtils
.
isNotEmpty
(
address
))
{
return
false
;
}
for
(
Pattern
pattern
:
PATTERN_LIST
)
{
for
(
Pattern
Entry
pattern
:
PATTERN_LIST
)
{
if
(
address
.
contains
(
pattern
.
getTarget
()))
{
return
true
;
}
...
...
@@ -42,6 +73,7 @@ public class AddressFilter {
/**
* 过滤特殊字符
*
* @param address
* @return
*/
...
...
@@ -51,17 +83,48 @@ public class AddressFilter {
return
address
;
}
for
(
Pattern
pattern
:
PATTERN_LIST
)
{
for
(
Pattern
Entry
pattern
:
PATTERN_LIST
)
{
address
=
StringUtils
.
replace
(
address
,
pattern
.
getTarget
(),
pattern
.
getReplaceMent
());
}
return
address
;
}
//替换email
public
static
String
getEmail
(
String
phone
,
String
email
)
{
//去掉所有的空白
if
(
null
!=
email
){
email
=
email
.
replaceAll
(
"\\s"
,
""
);
}
if
(
isEmail
(
email
)){
return
email
;
}
if
(
null
==
phone
){
return
null
;
}
Set
<
Map
.
Entry
<
List
<
String
>,
String
>>
entries
=
OPERATO_MAP
.
entrySet
();
for
(
Map
.
Entry
<
List
<
String
>,
String
>
entry
:
entries
)
{
boolean
contains
=
entry
.
getKey
().
contains
(
phone
.
substring
(
0
,
3
));
if
(
contains
){
return
phone
.
concat
(
entry
.
getValue
());
}
}
return
phone
.
concat
(
UNICOM_SUFFIX
);
}
//校验是否是邮箱
public
static
boolean
isEmail
(
String
email
){
if
(
null
==
email
){
return
false
;
}
Matcher
matcher
=
EMAIL_PATTERN
.
matcher
(
email
);
return
matcher
.
matches
();
}
@Getter
@Setter
@AllArgsConstructor
public
static
class
Pattern
{
public
static
class
Pattern
Entry
{
private
String
target
;
private
String
replaceMent
;
}
...
...
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