Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
beyond-clouds
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
4
Issues
4
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
段启岩
beyond-clouds
Commits
c81aca95
Commit
c81aca95
authored
Feb 11, 2020
by
段启岩
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/topic-parser'
# Conflicts: # src/main/resources/application.yml
parents
1c29231d
f9a117e8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
97 additions
and
14 deletions
+97
-14
src/main/java/cn/meteor/beyondclouds/modules/post/api/PostApi.java
+1
-1
src/main/java/cn/meteor/beyondclouds/modules/post/form/PostForm.java
+0
-3
src/main/java/cn/meteor/beyondclouds/modules/post/service/IPostService.java
+1
-2
src/main/java/cn/meteor/beyondclouds/modules/post/service/impl/PostServiceImpl.java
+16
-7
src/main/java/cn/meteor/beyondclouds/modules/topic/service/ITopicService.java
+9
-0
src/main/java/cn/meteor/beyondclouds/modules/topic/service/impl/TopicServiceImpl.java
+27
-0
src/main/java/cn/meteor/beyondclouds/util/TopicUtils.java
+42
-0
src/main/resources/application.yml
+1
-1
No files found.
src/main/java/cn/meteor/beyondclouds/modules/post/api/PostApi.java
View file @
c81aca95
...
...
@@ -79,7 +79,7 @@ public class PostApi {
//发布动态
try
{
postService
.
publishPost
(
post
,
postForm
.
getTopicIds
()
);
postService
.
publishPost
(
post
);
return
Response
.
success
();
}
catch
(
ProjectServiceException
e
)
{
e
.
printStackTrace
();
...
...
src/main/java/cn/meteor/beyondclouds/modules/post/form/PostForm.java
View file @
c81aca95
...
...
@@ -26,7 +26,4 @@ public class PostForm {
@NullOrNotBlank
(
message
=
"请传入有效的视频内容"
)
private
String
video
;
@ElementNotBlank
(
message
=
"话题Id不可为空"
)
private
List
<
String
>
topicIds
;
}
src/main/java/cn/meteor/beyondclouds/modules/post/service/IPostService.java
View file @
c81aca95
...
...
@@ -21,10 +21,9 @@ public interface IPostService extends IService<Post> {
/**
* 发布动态
* @param post
* @param topicIds
* @throws ProjectServiceException
*/
void
publishPost
(
Post
post
,
List
<
String
>
topicIds
)
throws
ProjectServiceException
;
void
publishPost
(
Post
post
)
throws
ProjectServiceException
;
/**
* 删除动态
...
...
src/main/java/cn/meteor/beyondclouds/modules/post/service/impl/PostServiceImpl.java
View file @
c81aca95
...
...
@@ -16,6 +16,7 @@ import cn.meteor.beyondclouds.modules.topic.service.ITopicReferenceService;
import
cn.meteor.beyondclouds.modules.topic.service.ITopicService
;
import
cn.meteor.beyondclouds.modules.user.entity.User
;
import
cn.meteor.beyondclouds.modules.user.service.IUserService
;
import
cn.meteor.beyondclouds.util.TopicUtils
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
...
...
@@ -24,6 +25,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.StringUtils
;
import
java.util.ArrayList
;
import
java.util.List
;
...
...
@@ -74,7 +76,7 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements IP
* @throws ProjectServiceException
*/
@Override
public
void
publishPost
(
Post
post
,
List
<
String
>
topicIds
)
throws
ProjectServiceException
{
public
void
publishPost
(
Post
post
)
throws
ProjectServiceException
{
//1.判断是否视频和图片都传了
if
(
null
!=
post
.
getPictures
()
&&
null
!=
post
.
getVideo
())
{
throw
new
ProjectServiceException
(
PostErrorCode
.
NOT_APPEAR_SAME_TIME
);
...
...
@@ -104,12 +106,17 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements IP
save
(
post
);
//处理话题引用
if
(!
CollectionUtils
.
isEmpty
(
topicIds
))
{
// 获取要引用的话题,不正确的话题ID会被自动过滤
List
<
String
>
existsTopicIds
=
topicService
.
listByIds
(
topicIds
).
stream
().
map
(
Topic:
:
getTopicId
).
collect
(
Collectors
.
toList
());
if
(!
CollectionUtils
.
isEmpty
(
existsTopicIds
))
{
String
postContent
=
post
.
getContent
();
if
(!
StringUtils
.
isEmpty
(
postContent
))
{
// 解析话题,若话题不存在则创建话题
List
<
String
>
topicNames
=
TopicUtils
.
parseTopics
(
post
.
getContent
());
if
(!
CollectionUtils
.
isEmpty
(
topicNames
))
{
List
<
Topic
>
topics
=
topicService
.
queryAndCreateByTopicNames
(
topicNames
,
post
.
getUserId
());
List
<
String
>
topicIds
=
topics
.
stream
().
map
(
Topic:
:
getTopicId
).
collect
(
Collectors
.
toList
());
// 关联话题和动态
List
<
TopicReference
>
topicReferences
=
new
ArrayList
<>();
for
(
String
topicId
:
existsT
opicIds
)
{
for
(
String
topicId
:
t
opicIds
)
{
TopicReference
topicReference
=
new
TopicReference
();
topicReference
.
setTopicId
(
topicId
);
topicReference
.
setReferencerId
(
post
.
getPostId
());
...
...
@@ -119,9 +126,11 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements IP
// 批量保存
topicReferenceService
.
saveBatch
(
topicReferences
);
// 新增话题引用次数
topicService
.
increaseReferenceCountBatch
(
existsT
opicIds
,
1
);
topicService
.
increaseReferenceCountBatch
(
t
opicIds
,
1
);
}
}
//发送消息到消息队列
messageQueueService
.
sendDataItemChangeMessage
(
DataItemChangeMessage
.
addMessage
(
DataItemType
.
POST
,
post
.
getPostId
(),
post
.
getUserId
()));
...
...
src/main/java/cn/meteor/beyondclouds/modules/topic/service/ITopicService.java
View file @
c81aca95
...
...
@@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
java.util.Collection
;
import
java.util.List
;
/**
* <p>
...
...
@@ -139,4 +140,12 @@ public interface ITopicService extends IService<Topic> {
* @return IPage<Post>
*/
IPage
<
Post
>
getPostByTopicName
(
Integer
pageNumber
,
Integer
pageSize
,
String
topicName
)
throws
TopicServiceException
;
/**
* 查找并话题,若话题不存在,则创建话题
* @param topicNames
* @param userId
* @return
*/
List
<
Topic
>
queryAndCreateByTopicNames
(
List
<
String
>
topicNames
,
String
userId
);
}
src/main/java/cn/meteor/beyondclouds/modules/topic/service/impl/TopicServiceImpl.java
View file @
c81aca95
...
...
@@ -354,4 +354,31 @@ public class TopicServiceImpl extends ServiceImpl<TopicMapper, Topic> implements
return
postIPage
;
}
@Override
public
List
<
Topic
>
queryAndCreateByTopicNames
(
List
<
String
>
topicNames
,
String
userId
)
{
QueryWrapper
<
Topic
>
topicQueryWrapper
=
new
QueryWrapper
<>();
topicQueryWrapper
.
in
(
"topic_name"
,
topicNames
);
List
<
Topic
>
topics
=
list
(
topicQueryWrapper
);
// 查询不存在的话题
List
<
String
>
topicNameExists
=
topics
.
stream
()
.
map
(
Topic:
:
getTopicName
)
.
collect
(
Collectors
.
toList
());
List
<
String
>
topicNameNotExists
=
topicNames
.
stream
()
.
filter
(
topicName
->
!
topicNameExists
.
contains
(
topicName
))
.
collect
(
Collectors
.
toList
());
// 创建不存在的话题并添加到topics
topicNameNotExists
.
forEach
(
topicName
->
{
Topic
topic
=
new
Topic
();
topic
.
setTopicName
(
topicName
);
topic
.
setUserId
(
userId
);
save
(
topic
);
topics
.
add
(
topic
);
});
return
topics
;
}
}
src/main/java/cn/meteor/beyondclouds/util/TopicUtils.java
0 → 100644
View file @
c81aca95
package
cn
.
meteor
.
beyondclouds
.
util
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.util.Assert
;
import
java.util.ArrayList
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.TreeSet
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
java.util.stream.Collectors
;
/**
* @author meteor
*/
@Slf4j
public
class
TopicUtils
{
private
static
final
Pattern
topicPattern
=
Pattern
.
compile
(
"(#([^#]+?)#)"
);
public
static
List
<
String
>
parseTopics
(
String
str
)
{
Assert
.
hasText
(
str
,
"str must not be empty"
);
Matcher
matcher
=
topicPattern
.
matcher
(
str
);
List
<
String
>
topicNames
=
new
ArrayList
<>();
while
(
matcher
.
find
())
{
topicNames
.
add
(
matcher
.
group
(
2
));
}
topicNames
=
topicNames
.
stream
().
collect
(
Collectors
.
collectingAndThen
(
Collectors
.
toCollection
(()
->
new
HashSet
<>()),
ArrayList:
:
new
)
);
return
topicNames
;
}
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
TopicUtils
.
parseTopics
(
"#哈哈哈#今#哈哈哈#天你吃饭了吗#吃了#######"
));
}
}
src/main/resources/application.yml
View file @
c81aca95
...
...
@@ -4,7 +4,7 @@ spring:
driver-class-name
:
com.mysql.cj.jdbc.Driver
url
:
jdbc:mysql://127.0.0.1:3306/beyond_clouds?useUnicode=true&characterEncoding=UTF-8&useSSL=false&allowPublicKeyRetrieval=true
username
:
root
password
:
2018006709
password
:
100Centa30821%mysql
# 邮箱
mail
:
...
...
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