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
f9a117e8
Commit
f9a117e8
authored
Feb 11, 2020
by
段启岩
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
发布动态话题自动创建和引用
parent
b1bb9d58
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
62 additions
and
18 deletions
+62
-18
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
+7
-4
src/main/resources/application.yml
+1
-1
No files found.
src/main/java/cn/meteor/beyondclouds/modules/post/api/PostApi.java
View file @
f9a117e8
...
@@ -79,7 +79,7 @@ public class PostApi {
...
@@ -79,7 +79,7 @@ public class PostApi {
//发布动态
//发布动态
try
{
try
{
postService
.
publishPost
(
post
,
postForm
.
getTopicIds
()
);
postService
.
publishPost
(
post
);
return
Response
.
success
();
return
Response
.
success
();
}
catch
(
ProjectServiceException
e
)
{
}
catch
(
ProjectServiceException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
...
...
src/main/java/cn/meteor/beyondclouds/modules/post/form/PostForm.java
View file @
f9a117e8
...
@@ -26,7 +26,4 @@ public class PostForm {
...
@@ -26,7 +26,4 @@ public class PostForm {
@NullOrNotBlank
(
message
=
"请传入有效的视频内容"
)
@NullOrNotBlank
(
message
=
"请传入有效的视频内容"
)
private
String
video
;
private
String
video
;
@ElementNotBlank
(
message
=
"话题Id不可为空"
)
private
List
<
String
>
topicIds
;
}
}
src/main/java/cn/meteor/beyondclouds/modules/post/service/IPostService.java
View file @
f9a117e8
...
@@ -21,10 +21,9 @@ public interface IPostService extends IService<Post> {
...
@@ -21,10 +21,9 @@ public interface IPostService extends IService<Post> {
/**
/**
* 发布动态
* 发布动态
* @param post
* @param post
* @param topicIds
* @throws ProjectServiceException
* @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 @
f9a117e8
...
@@ -16,6 +16,7 @@ import cn.meteor.beyondclouds.modules.topic.service.ITopicReferenceService;
...
@@ -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.topic.service.ITopicService
;
import
cn.meteor.beyondclouds.modules.user.entity.User
;
import
cn.meteor.beyondclouds.modules.user.entity.User
;
import
cn.meteor.beyondclouds.modules.user.service.IUserService
;
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.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper
;
import
com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
...
@@ -24,6 +25,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
...
@@ -24,6 +25,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.StringUtils
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
...
@@ -74,7 +76,7 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements IP
...
@@ -74,7 +76,7 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements IP
* @throws ProjectServiceException
* @throws ProjectServiceException
*/
*/
@Override
@Override
public
void
publishPost
(
Post
post
,
List
<
String
>
topicIds
)
throws
ProjectServiceException
{
public
void
publishPost
(
Post
post
)
throws
ProjectServiceException
{
//1.判断是否视频和图片都传了
//1.判断是否视频和图片都传了
if
(
null
!=
post
.
getPictures
()
&&
null
!=
post
.
getVideo
())
{
if
(
null
!=
post
.
getPictures
()
&&
null
!=
post
.
getVideo
())
{
throw
new
ProjectServiceException
(
PostErrorCode
.
NOT_APPEAR_SAME_TIME
);
throw
new
ProjectServiceException
(
PostErrorCode
.
NOT_APPEAR_SAME_TIME
);
...
@@ -104,12 +106,17 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements IP
...
@@ -104,12 +106,17 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements IP
save
(
post
);
save
(
post
);
//处理话题引用
//处理话题引用
if
(!
CollectionUtils
.
isEmpty
(
topicIds
))
{
String
postContent
=
post
.
getContent
();
// 获取要引用的话题,不正确的话题ID会被自动过滤
if
(!
StringUtils
.
isEmpty
(
postContent
))
{
List
<
String
>
existsTopicIds
=
topicService
.
listByIds
(
topicIds
).
stream
().
map
(
Topic:
:
getTopicId
).
collect
(
Collectors
.
toList
());
// 解析话题,若话题不存在则创建话题
if
(!
CollectionUtils
.
isEmpty
(
existsTopicIds
))
{
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
<>();
List
<
TopicReference
>
topicReferences
=
new
ArrayList
<>();
for
(
String
topicId
:
existsT
opicIds
)
{
for
(
String
topicId
:
t
opicIds
)
{
TopicReference
topicReference
=
new
TopicReference
();
TopicReference
topicReference
=
new
TopicReference
();
topicReference
.
setTopicId
(
topicId
);
topicReference
.
setTopicId
(
topicId
);
topicReference
.
setReferencerId
(
post
.
getPostId
());
topicReference
.
setReferencerId
(
post
.
getPostId
());
...
@@ -119,9 +126,11 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements IP
...
@@ -119,9 +126,11 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements IP
// 批量保存
// 批量保存
topicReferenceService
.
saveBatch
(
topicReferences
);
topicReferenceService
.
saveBatch
(
topicReferences
);
// 新增话题引用次数
// 新增话题引用次数
topicService
.
increaseReferenceCountBatch
(
existsT
opicIds
,
1
);
topicService
.
increaseReferenceCountBatch
(
t
opicIds
,
1
);
}
}
}
}
//发送消息到消息队列
//发送消息到消息队列
messageQueueService
.
sendDataItemChangeMessage
(
DataItemChangeMessage
.
addMessage
(
DataItemType
.
POST
,
post
.
getPostId
(),
post
.
getUserId
()));
messageQueueService
.
sendDataItemChangeMessage
(
DataItemChangeMessage
.
addMessage
(
DataItemType
.
POST
,
post
.
getPostId
(),
post
.
getUserId
()));
...
...
src/main/java/cn/meteor/beyondclouds/modules/topic/service/ITopicService.java
View file @
f9a117e8
...
@@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
...
@@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
java.util.Collection
;
import
java.util.Collection
;
import
java.util.List
;
/**
/**
* <p>
* <p>
...
@@ -139,4 +140,12 @@ public interface ITopicService extends IService<Topic> {
...
@@ -139,4 +140,12 @@ public interface ITopicService extends IService<Topic> {
* @return IPage<Post>
* @return IPage<Post>
*/
*/
IPage
<
Post
>
getPostByTopicName
(
Integer
pageNumber
,
Integer
pageSize
,
String
topicName
)
throws
TopicServiceException
;
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 @
f9a117e8
...
@@ -354,4 +354,31 @@ public class TopicServiceImpl extends ServiceImpl<TopicMapper, Topic> implements
...
@@ -354,4 +354,31 @@ public class TopicServiceImpl extends ServiceImpl<TopicMapper, Topic> implements
return
postIPage
;
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
View file @
f9a117e8
...
@@ -4,6 +4,7 @@ import lombok.extern.slf4j.Slf4j;
...
@@ -4,6 +4,7 @@ import lombok.extern.slf4j.Slf4j;
import
org.springframework.util.Assert
;
import
org.springframework.util.Assert
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.List
;
import
java.util.TreeSet
;
import
java.util.TreeSet
;
import
java.util.regex.Matcher
;
import
java.util.regex.Matcher
;
...
@@ -27,13 +28,15 @@ public class TopicUtils {
...
@@ -27,13 +28,15 @@ public class TopicUtils {
while
(
matcher
.
find
())
{
while
(
matcher
.
find
())
{
topicNames
.
add
(
matcher
.
group
(
2
));
topicNames
.
add
(
matcher
.
group
(
2
));
}
}
// topicNames.stream().
topicNames
=
topicNames
.
stream
().
// collect(Collectors.collectingAndThen(Collectors.toCollection());
collect
(
return
null
;
Collectors
.
collectingAndThen
(
Collectors
.
toCollection
(()
->
new
HashSet
<>()),
ArrayList:
:
new
)
);
return
topicNames
;
}
}
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
TopicUtils
.
parseTopics
(
"#哈哈哈#今天你吃饭了吗#吃了#######"
));
System
.
out
.
println
(
TopicUtils
.
parseTopics
(
"#哈哈哈#今
#哈哈哈#
天你吃饭了吗#吃了#######"
));
}
}
}
}
src/main/resources/application.yml
View file @
f9a117e8
...
@@ -4,7 +4,7 @@ spring:
...
@@ -4,7 +4,7 @@ spring:
driver-class-name
:
com.mysql.cj.jdbc.Driver
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
url
:
jdbc:mysql://127.0.0.1:3306/beyond_clouds?useUnicode=true&characterEncoding=UTF-8&useSSL=false&allowPublicKeyRetrieval=true
username
:
root
username
:
root
password
:
1
97442
password
:
1
00Centa30821%mysql
# 邮箱
# 邮箱
mail
:
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