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
382d8437
Commit
382d8437
authored
Nov 14, 2017
by
技术部-任文超
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CodeReview后优化代码结构
parent
0c6d7eba
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
50 additions
and
43 deletions
+50
-43
MotanUserServiceImpl.java
.../xyqb/controller/external/motan/MotanUserServiceImpl.java
+4
-8
InnerController.java
...tgroup/xyqb/controller/external/user/InnerController.java
+5
-9
UserCenterController.java
...controller/external/user/center/UserCenterController.java
+4
-8
Contact.java
src/main/java/cn/quantgroup/xyqb/entity/Contact.java
+10
-0
PageServiceImpl.java
...cn/quantgroup/xyqb/service/page/impl/PageServiceImpl.java
+1
-1
IContactService.java
...java/cn/quantgroup/xyqb/service/user/IContactService.java
+5
-6
ContactServiceImpl.java
...quantgroup/xyqb/service/user/impl/ContactServiceImpl.java
+21
-11
No files found.
src/main/java/cn/quantgroup/xyqb/controller/external/motan/MotanUserServiceImpl.java
View file @
382d8437
...
@@ -335,7 +335,7 @@ public class MotanUserServiceImpl implements UserMotanService {
...
@@ -335,7 +335,7 @@ public class MotanUserServiceImpl implements UserMotanService {
@Override
@Override
public
UserSysResult
<
List
<
XContact
>>
findContactsByUserId
(
Long
userId
)
{
public
UserSysResult
<
List
<
XContact
>>
findContactsByUserId
(
Long
userId
)
{
List
<
Contact
>
contacts
=
contactService
.
trim
(
contactService
.
findByUserId
(
userId
)
);
List
<
Contact
>
contacts
=
contactService
.
findByUserId
(
userId
,
true
);
List
<
XContact
>
xContacts
=
convertObject
(
JSON
.
toJSONString
(
contacts
),
new
TypeReference
<
List
<
XContact
>>()
{
List
<
XContact
>
xContacts
=
convertObject
(
JSON
.
toJSONString
(
contacts
),
new
TypeReference
<
List
<
XContact
>>()
{
});
});
return
returnSuccessValue
(
xContacts
);
return
returnSuccessValue
(
xContacts
);
...
@@ -359,13 +359,9 @@ public class MotanUserServiceImpl implements UserMotanService {
...
@@ -359,13 +359,9 @@ public class MotanUserServiceImpl implements UserMotanService {
return
returnErrorValue
(
"联系人转换错误"
);
return
returnErrorValue
(
"联系人转换错误"
);
}
}
for
(
Contact
c
:
contactList
)
{
for
(
Contact
c
:
contactList
)
{
if
(!
ValidationUtil
.
validatePhoneNo
(
c
.
getPhoneNo
()))
{
if
(!
c
.
valid
())
{
log
.
info
(
"用户手机号错误, phoneNo:{}"
,
c
.
getPhoneNo
());
log
.
info
(
"用户手机号或姓名错误, phoneNo:{},name:{}"
,
c
.
getPhoneNo
(),
c
.
getName
());
return
returnErrorValue
(
"用户手机号错误"
);
return
returnErrorValue
(
"用户手机号或姓名错误"
);
}
if
(!
ValidationUtil
.
validateChinese
(
c
.
getName
()))
{
log
.
info
(
"用户姓名错误, name:{}"
,
c
.
getName
());
return
returnErrorValue
(
"用户姓名错误"
);
}
}
}
}
List
<
Contact
>
result
=
contactService
.
save
(
userId
,
contactList
);
List
<
Contact
>
result
=
contactService
.
save
(
userId
,
contactList
);
...
...
src/main/java/cn/quantgroup/xyqb/controller/external/user/InnerController.java
View file @
382d8437
...
@@ -362,7 +362,7 @@ public class InnerController implements IBaseController {
...
@@ -362,7 +362,7 @@ public class InnerController implements IBaseController {
if
(
null
==
userId
)
{
if
(
null
==
userId
)
{
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
}
}
List
<
Contact
>
contacts
=
contactService
.
trim
(
contactService
.
findByUserId
(
userId
)
);
List
<
Contact
>
contacts
=
contactService
.
findByUserId
(
userId
,
true
);
if
(
null
==
contacts
||
contacts
.
size
()
==
0
)
{
if
(
null
==
contacts
||
contacts
.
size
()
==
0
)
{
return
JsonResult
.
buildErrorStateResult
(
null
,
Collections
.
emptyList
());
return
JsonResult
.
buildErrorStateResult
(
null
,
Collections
.
emptyList
());
}
}
...
@@ -385,14 +385,10 @@ public class InnerController implements IBaseController {
...
@@ -385,14 +385,10 @@ public class InnerController implements IBaseController {
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
}
}
for
(
Contact
contact
:
contacts
){
for
(
Contact
contact
:
contacts
){
if
(!
ValidationUtil
.
validatePhoneNo
(
contact
.
getPhoneNo
()
))
{
if
(!
contact
.
valid
(
))
{
LOGGER
.
info
(
"用户手机号
错误, phoneNo:{}"
,
contact
.
getPhoneNo
());
LOGGER
.
info
(
"用户手机号
或姓名错误, phoneNo:{},name:{}"
,
contact
.
getPhoneNo
(),
contact
.
getName
());
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
}
}
if
(!
ValidationUtil
.
validateChinese
(
contact
.
getName
()))
{
LOGGER
.
info
(
"用户姓名错误, name:{}"
,
contact
.
getName
());
return
JsonResult
.
buildErrorStateResult
(
"null"
,
null
);
}
}
}
List
<
Contact
>
result
=
contactService
.
save
(
userId
,
contacts
);
List
<
Contact
>
result
=
contactService
.
save
(
userId
,
contacts
);
return
JsonResult
.
buildSuccessResult
(
null
,
ContactRet
.
contacts2ContactRets
(
result
));
return
JsonResult
.
buildSuccessResult
(
null
,
ContactRet
.
contacts2ContactRets
(
result
));
...
@@ -583,7 +579,7 @@ public class InnerController implements IBaseController {
...
@@ -583,7 +579,7 @@ public class InnerController implements IBaseController {
if
(
null
!=
userDetail
)
{
if
(
null
!=
userDetail
)
{
Address
address
=
addressService
.
findByUserId
(
userDetail
.
getUserId
());
Address
address
=
addressService
.
findByUserId
(
userDetail
.
getUserId
());
List
<
Contact
>
contacts
=
contactService
.
trim
(
contactService
.
findByUserId
(
userDetail
.
getUserId
())
);
List
<
Contact
>
contacts
=
contactService
.
findByUserId
(
userDetail
.
getUserId
(),
true
);
UserExtInfo
extInfo
=
userExtInfoService
.
findByUserId
(
userDetail
.
getUserId
());
UserExtInfo
extInfo
=
userExtInfoService
.
findByUserId
(
userDetail
.
getUserId
());
bean
.
setUserId
(
userDetail
.
getUserId
());
bean
.
setUserId
(
userDetail
.
getUserId
());
bean
.
setPhoneNo
(
userDetail
.
getPhoneNo
());
bean
.
setPhoneNo
(
userDetail
.
getPhoneNo
());
...
@@ -635,7 +631,7 @@ public class InnerController implements IBaseController {
...
@@ -635,7 +631,7 @@ public class InnerController implements IBaseController {
if
(
null
!=
userDetail
)
{
if
(
null
!=
userDetail
)
{
Address
address
=
addressService
.
findByUserId
(
userDetail
.
getUserId
());
Address
address
=
addressService
.
findByUserId
(
userDetail
.
getUserId
());
List
<
Contact
>
contacts
=
contactService
.
trim
(
contactService
.
findByUserId
(
userDetail
.
getUserId
())
);
List
<
Contact
>
contacts
=
contactService
.
findByUserId
(
userDetail
.
getUserId
(),
true
);
UserExtInfo
extInfo
=
userExtInfoService
.
findByUserId
(
userDetail
.
getUserId
());
UserExtInfo
extInfo
=
userExtInfoService
.
findByUserId
(
userDetail
.
getUserId
());
bean
.
setUserId
(
userDetail
.
getUserId
());
bean
.
setUserId
(
userDetail
.
getUserId
());
bean
.
setPhoneNo
(
userDetail
.
getPhoneNo
());
bean
.
setPhoneNo
(
userDetail
.
getPhoneNo
());
...
...
src/main/java/cn/quantgroup/xyqb/controller/external/user/center/UserCenterController.java
View file @
382d8437
...
@@ -201,7 +201,7 @@ public class UserCenterController {
...
@@ -201,7 +201,7 @@ public class UserCenterController {
return
JsonResult
.
buildErrorStateResult
(
"该用户不存在"
,
null
);
return
JsonResult
.
buildErrorStateResult
(
"该用户不存在"
,
null
);
}
}
UserExtInfo
userExtInfo
=
userExtInfoService
.
findByUserId
(
userId
);
UserExtInfo
userExtInfo
=
userExtInfoService
.
findByUserId
(
userId
);
List
<
Contact
>
contacts
=
contactService
.
trim
(
contactService
.
findByUserId
(
userId
)
);
List
<
Contact
>
contacts
=
contactService
.
findByUserId
(
userId
,
true
);
Map
<
String
,
Object
>
result
=
new
HashMap
<>();
Map
<
String
,
Object
>
result
=
new
HashMap
<>();
if
(
null
!=
userExtInfo
)
{
if
(
null
!=
userExtInfo
)
{
result
.
put
(
"contacts"
,
null
!=
contacts
&&
contacts
.
size
()
>
0
?
true
:
false
);
result
.
put
(
"contacts"
,
null
!=
contacts
&&
contacts
.
size
()
>
0
?
true
:
false
);
...
@@ -251,14 +251,10 @@ public class UserCenterController {
...
@@ -251,14 +251,10 @@ public class UserCenterController {
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
}
}
for
(
Contact
contact
:
contacts
){
for
(
Contact
contact
:
contacts
){
if
(!
ValidationUtil
.
validatePhoneNo
(
contact
.
getPhoneNo
()
))
{
if
(!
contact
.
valid
(
))
{
LOGGER
.
info
(
"用户手机号
错误, phoneNo:{}"
,
contact
.
getPhoneNo
());
LOGGER
.
info
(
"用户手机号
或姓名错误, phoneNo:{},name:{}"
,
contact
.
getPhoneNo
(),
contact
.
getName
());
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
}
}
if
(!
ValidationUtil
.
validateChinese
(
contact
.
getName
()))
{
LOGGER
.
info
(
"用户姓名错误, name:{}"
,
contact
.
getName
());
return
JsonResult
.
buildErrorStateResult
(
"null"
,
null
);
}
}
}
List
<
Contact
>
result
=
contactService
.
save
(
userId
,
contacts
);
List
<
Contact
>
result
=
contactService
.
save
(
userId
,
contacts
);
return
JsonResult
.
buildSuccessResult
(
null
,
result
);
return
JsonResult
.
buildSuccessResult
(
null
,
result
);
...
@@ -341,7 +337,7 @@ public class UserCenterController {
...
@@ -341,7 +337,7 @@ public class UserCenterController {
LOGGER
.
error
(
"保存联系人,未获取到用户id. userId:{}"
,
userId
);
LOGGER
.
error
(
"保存联系人,未获取到用户id. userId:{}"
,
userId
);
return
JsonResult
.
buildErrorStateResult
(
"该用户不存在"
,
null
);
return
JsonResult
.
buildErrorStateResult
(
"该用户不存在"
,
null
);
}
}
List
<
Contact
>
contacts
=
contactService
.
trim
(
contactService
.
findByUserId
(
userId
)
);
List
<
Contact
>
contacts
=
contactService
.
findByUserId
(
userId
,
true
);
return
JsonResult
.
buildSuccessResult
(
null
,
contacts
);
return
JsonResult
.
buildSuccessResult
(
null
,
contacts
);
}
}
...
...
src/main/java/cn/quantgroup/xyqb/entity/Contact.java
View file @
382d8437
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.util.ValidationUtil
;
import
lombok.Data
;
import
lombok.Data
;
import
javax.persistence.*
;
import
javax.persistence.*
;
...
@@ -32,4 +33,13 @@ public class Contact implements Serializable {
...
@@ -32,4 +33,13 @@ public class Contact implements Serializable {
private
Timestamp
createdAt
;
private
Timestamp
createdAt
;
@Column
(
name
=
"updated_at"
)
@Column
(
name
=
"updated_at"
)
private
Timestamp
updateAt
;
private
Timestamp
updateAt
;
/**
* 数据合法性校验
* @return
*/
public
boolean
valid
(){
return
(
ValidationUtil
.
validatePhoneNo
(
this
.
phoneNo
)
&&
ValidationUtil
.
validateChinese
(
this
.
name
));
}
}
}
src/main/java/cn/quantgroup/xyqb/service/page/impl/PageServiceImpl.java
View file @
382d8437
...
@@ -55,7 +55,7 @@ public class PageServiceImpl implements IPageService {
...
@@ -55,7 +55,7 @@ public class PageServiceImpl implements IPageService {
private
PageType
pageContacts
=
new
PageType
(
"contacts"
,
false
)
{
private
PageType
pageContacts
=
new
PageType
(
"contacts"
,
false
)
{
@Override
@Override
public
boolean
canPass
(
User
user
)
{
public
boolean
canPass
(
User
user
)
{
List
<
Contact
>
contacts
=
contactService
.
trim
(
contactService
.
findByUserId
(
user
.
getId
())
);
List
<
Contact
>
contacts
=
contactService
.
findByUserId
(
user
.
getId
(),
true
);
return
contacts
!=
null
&&
contacts
.
size
()
!=
0
;
return
contacts
!=
null
&&
contacts
.
size
()
!=
0
;
}
}
};
};
...
...
src/main/java/cn/quantgroup/xyqb/service/user/IContactService.java
View file @
382d8437
...
@@ -9,14 +9,13 @@ import java.util.List;
...
@@ -9,14 +9,13 @@ import java.util.List;
* Created by Miraculous on 2017/1/3.
* Created by Miraculous on 2017/1/3.
*/
*/
public
interface
IContactService
{
public
interface
IContactService
{
List
<
Contact
>
findByUserId
(
Long
userId
);
/**
/**
* 清除非法联系人记录
*
* @param contacts - 包含待清除记录的联系人列表
* @param userId - 用户主键
* @return 只包含合法联系人记录的列表
* @param trim - 是否清除非法错误记录,true-清除,false-不清除
* @return
*/
*/
List
<
Contact
>
trim
(
List
<
Contact
>
contacts
);
List
<
Contact
>
findByUserId
(
Long
userId
,
boolean
trim
);
Contact
findById
(
Long
id
);
Contact
findById
(
Long
id
);
...
...
src/main/java/cn/quantgroup/xyqb/service/user/impl/ContactServiceImpl.java
View file @
382d8437
...
@@ -12,9 +12,11 @@ import org.springframework.beans.factory.annotation.Autowired;
...
@@ -12,9 +12,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.cache.annotation.CacheEvict
;
import
org.springframework.cache.annotation.CacheEvict
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.CollectionUtils
;
import
java.sql.Timestamp
;
import
java.sql.Timestamp
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.List
;
/**
/**
...
@@ -27,25 +29,33 @@ public class ContactServiceImpl implements IContactService {
...
@@ -27,25 +29,33 @@ public class ContactServiceImpl implements IContactService {
private
IContactRepository
contactRepository
;
private
IContactRepository
contactRepository
;
@Override
@Override
public
List
<
Contact
>
findByUserId
(
Long
userId
,
boolean
trim
)
{
List
<
Contact
>
contacts
=
findByUserId
(
userId
);
if
(
trim
){
return
trim
(
contacts
);
}
return
contacts
;
}
@Cacheable
(
value
=
"contact"
,
key
=
"'contact' + #userId"
,
unless
=
"#result == null or #result.size() == 0"
,
cacheManager
=
"cacheManager"
)
@Cacheable
(
value
=
"contact"
,
key
=
"'contact' + #userId"
,
unless
=
"#result == null or #result.size() == 0"
,
cacheManager
=
"cacheManager"
)
public
List
<
Contact
>
findByUserId
(
Long
userId
)
{
public
List
<
Contact
>
findByUserId
(
Long
userId
)
{
return
contactRepository
.
findByUserId
(
userId
);
return
contactRepository
.
findByUserId
(
userId
);
}
}
@Override
/**
public
List
<
Contact
>
trim
(
List
<
Contact
>
contacts
){
* 清除非法联系人记录
List
<
Contact
>
trimList
=
new
ArrayList
<
Contact
>();
* @param contacts - 包含待清除记录的联系人列表
if
(
contacts
==
null
){
* @return 只包含合法联系人记录的列表
return
trimList
;
*/
private
List
<
Contact
>
trim
(
List
<
Contact
>
contacts
){
if
(
CollectionUtils
.
isEmpty
(
contacts
)){
return
Collections
.
emptyList
();
}
}
List
<
Contact
>
trimList
=
new
ArrayList
<
Contact
>(
contacts
.
size
());
for
(
Contact
contact
:
contacts
){
for
(
Contact
contact
:
contacts
){
if
(!
ValidationUtil
.
validatePhoneNo
(
contact
.
getPhoneNo
()))
{
if
(
contact
.
valid
())
{
continue
;
trimList
.
add
(
contact
);
}
if
(!
ValidationUtil
.
validateChinese
(
contact
.
getName
()))
{
continue
;
}
}
trimList
.
add
(
contact
);
}
}
return
trimList
;
return
trimList
;
}
}
...
...
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