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
62959551
Commit
62959551
authored
Mar 07, 2020
by
段启岩
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
延时发布解析
parent
ed209994
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
28 additions
and
13 deletions
+28
-13
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
-2
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
+5
-4
src/main/java/cn/meteor/beyondclouds/util/TopicUtils.java
+21
-4
No files found.
src/main/java/cn/meteor/beyondclouds/modules/post/api/PostApi.java
View file @
62959551
...
...
@@ -78,7 +78,7 @@ public class PostApi {
//发布动态
try
{
postService
.
publishPost
(
post
,
postForm
.
getPublishTime
()
);
postService
.
publishPost
(
post
);
return
Response
.
success
();
}
catch
(
ProjectServiceException
e
)
{
e
.
printStackTrace
();
...
...
src/main/java/cn/meteor/beyondclouds/modules/post/form/PostForm.java
View file @
62959551
...
...
@@ -27,6 +27,4 @@ public class PostForm {
@NullOrNotBlank
(
message
=
"请传入有效的视频内容"
)
private
String
video
;
@DateTimeFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
)
private
Date
publishTime
;
}
src/main/java/cn/meteor/beyondclouds/modules/post/service/IPostService.java
View file @
62959551
...
...
@@ -23,10 +23,9 @@ public interface IPostService extends IService<Post> {
* 发布动态
*
* @param post
* @param publishTime
* @throws ProjectServiceException
*/
void
publishPost
(
Post
post
,
Date
publishTime
)
throws
ProjectServiceException
;
void
publishPost
(
Post
post
)
throws
ProjectServiceException
;
/**
* 删除动态
...
...
src/main/java/cn/meteor/beyondclouds/modules/post/service/impl/PostServiceImpl.java
View file @
62959551
...
...
@@ -127,7 +127,7 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements IP
* @throws ProjectServiceException
*/
@Override
public
void
publishPost
(
Post
post
,
Date
publishTime
)
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
);
...
...
@@ -153,10 +153,11 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements IP
User
user
=
userService
.
getById
(
post
.
getUserId
());
post
.
setUserNick
(
user
.
getNickName
());
post
.
setUserAvatar
(
user
.
getUserAvatar
());
post
.
setContent
(
TopicUtils
.
encodeTopic
(
post
.
getContent
()
));
if
(
null
!=
publishTime
&&
publishTime
.
getTime
()
>
System
.
currentTimeMillis
()
)
{
post
.
setCreateTime
(
publishTime
);
Integer
delay
=
TopicUtils
.
getDelay
(
post
.
getContent
(
));
if
(
null
!=
delay
&&
delay
>
0
)
{
post
.
setCreateTime
(
new
Date
(
System
.
currentTimeMillis
()
+
delay
*
1000
*
60
)
);
}
post
.
setContent
(
TopicUtils
.
encodeTopic
(
post
.
getContent
()));
//2.保存动态
save
(
post
);
...
...
src/main/java/cn/meteor/beyondclouds/util/TopicUtils.java
View file @
62959551
...
...
@@ -21,6 +21,8 @@ public class TopicUtils {
private
static
final
Pattern
topicPattern
=
Pattern
.
compile
(
"(#([^#]+?)#)"
);
private
static
final
Pattern
delayPattern
=
Pattern
.
compile
(
"(delay\\((\\d+)\\);)$"
);
public
static
String
encodeTopic
(
String
str
)
{
Assert
.
hasText
(
str
,
"str must not be empty"
);
...
...
@@ -37,7 +39,12 @@ public class TopicUtils {
matcher
.
appendReplacement
(
buffer
,
tmp
);
}
matcher
.
appendTail
(
buffer
);
return
buffer
.
toString
().
replace
(
"\n"
,
"<br>"
);
String
result
=
buffer
.
toString
().
replace
(
"\n"
,
"<br>"
);
matcher
=
delayPattern
.
matcher
(
result
);
if
(
matcher
.
find
())
{
result
=
matcher
.
replaceAll
(
""
);
}
return
result
;
}
public
static
List
<
String
>
parseTopics
(
String
str
)
{
...
...
@@ -58,10 +65,20 @@ public class TopicUtils {
return
topicNames
;
}
public
static
Integer
getDelay
(
String
str
)
{
Matcher
matcher
=
delayPattern
.
matcher
(
str
);
if
(
matcher
.
find
())
{
return
Integer
.
valueOf
(
matcher
.
group
(
2
));
}
else
{
return
null
;
}
}
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
TopicUtils
.
parseTopics
(
"#哈哈哈#今#哈哈哈#天你吃饭了吗#吃了#######"
));
System
.
out
.
println
(
TopicUtils
.
encodeTopic
(
"#哈哈哈#今#哈哈哈#天你吃饭了吗#吃了#######哈哈#a#b"
));
System
.
out
.
println
(
TopicUtils
.
clearLockedTopics
(
"#哈哈哈#今#哈哈哈#天你吃饭了吗#吃了#######哈哈#a#b"
,
List
.
of
(
"哈哈哈"
)));
// System.out.println(TopicUtils.parseTopics("#哈哈哈#今#哈哈哈#天你吃饭了吗#吃了#######"));
System
.
out
.
println
(
TopicUtils
.
encodeTopic
(
"#哈哈哈#今#哈哈delay(5);哈#天你吃饭了吗#吃了#######哈哈#a#bdelay(5);"
));
System
.
out
.
println
(
TopicUtils
.
getDelay
(
"#哈哈哈#今#哈哈delay(5);哈#天你吃饭了吗#吃了#######哈哈#a#bdelay(5);"
));
// System.out.println(TopicUtils.clearLockedTopics("#哈哈哈#今#哈哈哈#天你吃饭了吗#吃了#######哈哈#a#b", List.of("哈哈哈")));
}
/**
...
...
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