Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in
Toggle navigation
T
tanpu-community
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
探普后端
tanpu-community
Commits
2b17e820
Commit
2b17e820
authored
Jun 17, 2021
by
刘基明
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
热点数据相关
parent
754fa8fe
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
220 additions
and
175 deletions
+220
-175
ThemeDTO.java
...src/main/java/com/tanpu/community/api/beans/ThemeDTO.java
+27
-136
RedisKeyConstant.java
...a/com/tanpu/community/api/constants/RedisKeyConstant.java
+14
-0
MetricsController.java
...ava/com/tanpu/community/controller/MetricsController.java
+3
-1
ThemeController.java
.../java/com/tanpu/community/controller/ThemeController.java
+6
-11
TopicController.java
.../java/com/tanpu/community/controller/TopicController.java
+8
-7
ThemeConvert.java
.../com/tanpu/community/controller/convert/ThemeConvert.java
+4
-0
ThemeManager.java
...c/main/java/com/tanpu/community/manager/ThemeManager.java
+49
-6
TopicManager.java
...c/main/java/com/tanpu/community/manager/TopicManager.java
+49
-7
CollectionService.java
...n/java/com/tanpu/community/service/CollectionService.java
+36
-5
CommentService.java
...main/java/com/tanpu/community/service/CommentService.java
+7
-0
RedisService.java
...c/main/java/com/tanpu/community/service/RedisService.java
+5
-0
ThemeService.java
...c/main/java/com/tanpu/community/service/ThemeService.java
+12
-2
No files found.
community-api/src/main/java/com/tanpu/community/api/beans/ThemeDTO.java
View file @
2b17e820
package
com
.
tanpu
.
community
.
api
.
beans
;
package
com
.
tanpu
.
community
.
api
.
beans
;
import
io.swagger.annotations.ApiModelProperty
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
java.time.LocalDateTime
;
import
java.time.LocalDateTime
;
@Data
public
class
ThemeDTO
{
public
class
ThemeDTO
{
private
static
final
long
serialVersionUID
=
1L
;
private
static
final
long
serialVersionUID
=
1L
;
...
@@ -14,13 +16,13 @@ public class ThemeDTO {
...
@@ -14,13 +16,13 @@ public class ThemeDTO {
@ApiModelProperty
(
value
=
"标题"
)
@ApiModelProperty
(
value
=
"标题"
)
private
String
title
;
private
String
title
;
@ApiModelProperty
(
value
=
"类型"
)
@ApiModelProperty
(
value
=
"类型
1:讨论无标题 2:常温有标题
"
)
private
Integer
themeType
;
private
Integer
themeType
;
@ApiModelProperty
(
value
=
"文本内容"
)
@ApiModelProperty
(
value
=
"文本内容"
)
private
String
content
;
private
String
content
;
@ApiModelProperty
(
value
=
"附件类型"
)
@ApiModelProperty
(
value
=
"附件类型
1:产品 2:直播 3:短视频 4:课程
"
)
private
Integer
attachType
;
private
Integer
attachType
;
@ApiModelProperty
(
value
=
"附件内容"
)
@ApiModelProperty
(
value
=
"附件内容"
)
...
@@ -29,152 +31,41 @@ public class ThemeDTO {
...
@@ -29,152 +31,41 @@ public class ThemeDTO {
@ApiModelProperty
(
value
=
"作者id"
)
@ApiModelProperty
(
value
=
"作者id"
)
private
String
authorId
;
private
String
authorId
;
@ApiModelProperty
(
value
=
"被转发的主题"
)
private
String
formerThemeId
;
@ApiModelProperty
(
value
=
"所属的话题"
)
@ApiModelProperty
(
value
=
"所属的话题"
)
private
String
topicId
;
private
String
topicId
;
private
String
createBy
;
@ApiModelProperty
(
value
=
"用户名"
)
private
String
userName
;
private
LocalDateTime
createTime
;
@ApiModelProperty
(
value
=
"用户头像"
)
private
String
userImg
;
private
String
updateBy
;
@ApiModelProperty
(
value
=
"认证"
)
private
String
authLabel
;
private
LocalDateTime
updateTime
;
@ApiModelProperty
(
value
=
"发表时间"
)
private
String
upToNowTime
;
private
Integer
deleteTag
;
@ApiModelProperty
(
value
=
"被转发的主题"
)
private
String
formerThemeId
;
@ApiModelProperty
(
value
=
"转发量"
)
private
Long
forwardAomunt
;
@ApiModelProperty
(
value
=
"评论量"
)
private
Long
commentAmount
;
public
String
getId
()
{
@ApiModelProperty
(
value
=
"点赞量"
)
return
id
;
private
Long
likeAmount
;
}
private
String
createBy
;
public
void
setId
(
String
id
)
{
private
LocalDateTime
createTime
;
this
.
id
=
id
;
}
public
String
getTitle
()
{
private
String
updateBy
;
return
title
;
}
public
void
setTitle
(
String
title
)
{
private
LocalDateTime
updateTime
;
this
.
title
=
title
;
}
public
Integer
getThemeType
()
{
private
Integer
deleteTag
;
return
themeType
;
}
public
void
setThemeType
(
Integer
themeType
)
{
this
.
themeType
=
themeType
;
}
public
String
getContent
()
{
return
content
;
}
public
void
setContent
(
String
content
)
{
this
.
content
=
content
;
}
public
Integer
getAttachType
()
{
return
attachType
;
}
public
void
setAttachType
(
Integer
attachType
)
{
this
.
attachType
=
attachType
;
}
public
String
getAttachment
()
{
return
attachment
;
}
public
void
setAttachment
(
String
attachment
)
{
this
.
attachment
=
attachment
;
}
public
String
getAuthorId
()
{
return
authorId
;
}
public
void
setAuthorId
(
String
authorId
)
{
this
.
authorId
=
authorId
;
}
public
String
getFormerThemeId
()
{
return
formerThemeId
;
}
public
void
setFormerThemeId
(
String
formerThemeId
)
{
this
.
formerThemeId
=
formerThemeId
;
}
public
String
getTopicId
()
{
return
topicId
;
}
public
void
setTopicId
(
String
topicId
)
{
this
.
topicId
=
topicId
;
}
public
String
getCreateBy
()
{
return
createBy
;
}
public
void
setCreateBy
(
String
createBy
)
{
this
.
createBy
=
createBy
;
}
public
LocalDateTime
getCreateTime
()
{
return
createTime
;
}
public
void
setCreateTime
(
LocalDateTime
createTime
)
{
this
.
createTime
=
createTime
;
}
public
String
getUpdateBy
()
{
return
updateBy
;
}
public
void
setUpdateBy
(
String
updateBy
)
{
this
.
updateBy
=
updateBy
;
}
public
LocalDateTime
getUpdateTime
()
{
return
updateTime
;
}
public
void
setUpdateTime
(
LocalDateTime
updateTime
)
{
this
.
updateTime
=
updateTime
;
}
public
Integer
getDeleteTag
()
{
return
deleteTag
;
}
public
void
setDeleteTag
(
Integer
deleteTag
)
{
this
.
deleteTag
=
deleteTag
;
}
@Override
public
String
toString
()
{
return
"ThemeEntity{"
+
"id="
+
id
+
", title="
+
title
+
", themeType="
+
themeType
+
", content="
+
content
+
", attachType="
+
attachType
+
", attachment="
+
attachment
+
", authorId="
+
authorId
+
", formerThemeId="
+
formerThemeId
+
", topicId="
+
topicId
+
", createBy="
+
createBy
+
", createTime="
+
createTime
+
", updateBy="
+
updateBy
+
", updateTime="
+
updateTime
+
", deleteTag="
+
deleteTag
+
"}"
;
}
}
}
community-api/src/main/java/com/tanpu/community/api/constants/RedisKeyConstant.java
0 → 100644
View file @
2b17e820
package
com
.
tanpu
.
community
.
api
.
constants
;
public
class
RedisKeyConstant
{
public
static
final
String
TOPIC_VIEW_AMOUNT_
=
"TOPIC_VIEW_AMOUNT_"
;
public
static
final
String
TOPIC_LIKE_AMOUNT_
=
"TOPIC_LIKE_AMOUNT_"
;
public
static
final
String
TOPIC_BOOK_AMOUNT_
=
"TOPIC_BOOK_AMOUNT_"
;
public
static
final
String
TOPIC_COMMENT_AMOUNT_
=
"TOPIC_COMMENT_AMOUNT_"
;
public
static
final
String
TOPIC_USER_AMOUNT_
=
"TOPIC_USER_AMOUNT_"
;
public
static
final
String
THEME_VIEW_AMOUNT_
=
"THEME_VIEW_AMOUNT_"
;
public
static
final
String
THEME_LIKE_AMOUNT_
=
"THEME_LIKE_AMOUNT_"
;
public
static
final
String
THEME_BOOK_AMOUNT_
=
"THEME_BOOK_AMOUNT_"
;
}
community-service/src/main/java/com/tanpu/community/controller/MetricsController.java
View file @
2b17e820
package
com
.
tanpu
.
community
.
controller
;
package
com
.
tanpu
.
community
.
controller
;
import
com.tanpu.community.api.constants.RedisKeyConstant
;
import
com.tanpu.community.service.RedisService
;
import
com.tanpu.community.service.RedisService
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
@@ -14,9 +15,10 @@ public class MetricsController {
...
@@ -14,9 +15,10 @@ public class MetricsController {
@ApiOperation
(
"浏览量埋点"
)
@ApiOperation
(
"浏览量埋点"
)
@RequestMapping
(
"/pv"
)
@RequestMapping
(
"/pv"
)
public
void
pageView
(
@RequestParam
String
themeId
){
public
void
pageView
(
@RequestParam
String
themeId
){
redisService
.
incr
(
"pv"
+
themeId
,
1L
);
redisService
.
incr
(
RedisKeyConstant
.
THEME_VIEW_AMOUNT_
+
themeId
,
1L
);
}
}
}
}
community-service/src/main/java/com/tanpu/community/controller/ThemeController.java
View file @
2b17e820
...
@@ -2,17 +2,12 @@ package com.tanpu.community.controller;
...
@@ -2,17 +2,12 @@ package com.tanpu.community.controller;
import
com.tanpu.community.api.beans.ThemeDTO
;
import
com.tanpu.community.api.beans.ThemeDTO
;
import
com.tanpu.community.controller.convert.ThemeConvert
;
import
com.tanpu.community.dao.entity.community.ThemeEntity
;
import
com.tanpu.community.manager.ThemeManager
;
import
com.tanpu.community.manager.ThemeManager
;
import
com.tanpu.community.service.FansRelService
;
import
com.tanpu.community.service.FansRelService
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.List
;
import
java.util.List
;
...
@@ -28,7 +23,7 @@ public class ThemeController {
...
@@ -28,7 +23,7 @@ public class ThemeController {
private
FansRelService
fansRelService
;
private
FansRelService
fansRelService
;
@ApiOperation
(
"新增主题"
)
@ApiOperation
(
"新增主题"
)
@
Reque
stMapping
(
value
=
"/add"
)
@
Po
stMapping
(
value
=
"/add"
)
@ResponseBody
@ResponseBody
public
String
insertTheme
(
@RequestBody
ThemeDTO
themeDTO
){
public
String
insertTheme
(
@RequestBody
ThemeDTO
themeDTO
){
String
userId
=
"liujm"
;
String
userId
=
"liujm"
;
...
@@ -37,17 +32,17 @@ public class ThemeController {
...
@@ -37,17 +32,17 @@ public class ThemeController {
return
"success"
;
return
"success"
;
}
}
@ApiOperation
(
"
系统推荐主题列表
"
)
@ApiOperation
(
"
获取推荐的圈文
"
)
@RequestMapping
(
value
=
"/recmend_list"
)
@RequestMapping
(
value
=
"/recmend_list"
)
@ResponseBody
@ResponseBody
public
List
<
Theme
Entity
>
selectHotList
(){
public
List
<
Theme
DTO
>
selectHotList
(){
return
null
;
return
null
;
}
}
@ApiOperation
(
"
用户关注主题列表
"
)
@ApiOperation
(
"
获取关注的圈文
"
)
@RequestMapping
(
value
=
"/interest_list"
)
@RequestMapping
(
value
=
"/interest_list"
)
@ResponseBody
@ResponseBody
public
List
<
Theme
Entity
>
selectInterestList
(){
public
List
<
Theme
DTO
>
selectInterestList
(){
String
userId
=
"liujm012"
;
String
userId
=
"liujm012"
;
return
null
;
return
null
;
}
}
...
...
community-service/src/main/java/com/tanpu/community/controller/TopicController.java
View file @
2b17e820
...
@@ -23,7 +23,7 @@ public class TopicController {
...
@@ -23,7 +23,7 @@ public class TopicController {
@Autowired
@Autowired
private
TopicManager
topicManager
;
private
TopicManager
topicManager
;
@PostMapping
(
value
=
"/queryTopicDetailList"
)
@PostMapping
(
value
=
"/
admin/
queryTopicDetailList"
)
@ApiOperation
(
"查询所有的主题详情"
)
@ApiOperation
(
"查询所有的主题详情"
)
@ResponseBody
@ResponseBody
public
List
<
TopicDTO
>
getAllTopicList
(
@RequestBody
String
content
){
public
List
<
TopicDTO
>
getAllTopicList
(
@RequestBody
String
content
){
...
@@ -34,7 +34,7 @@ public class TopicController {
...
@@ -34,7 +34,7 @@ public class TopicController {
return
topicDTOS
;
return
topicDTOS
;
}
}
@PostMapping
(
value
=
"/queryTopicNameList"
)
@PostMapping
(
value
=
"/
admin/
queryTopicNameList"
)
@ApiOperation
(
"查询所有的主题名称列表"
)
@ApiOperation
(
"查询所有的主题名称列表"
)
@ResponseBody
@ResponseBody
public
List
<
String
>
getTopicNameList
(
@RequestBody
String
content
){
public
List
<
String
>
getTopicNameList
(
@RequestBody
String
content
){
...
@@ -45,7 +45,7 @@ public class TopicController {
...
@@ -45,7 +45,7 @@ public class TopicController {
return
topictitiles
;
return
topictitiles
;
}
}
@PostMapping
(
value
=
"/insertTopic"
)
@PostMapping
(
value
=
"/
admin/
insertTopic"
)
@ApiOperation
(
"新增主题主题"
)
@ApiOperation
(
"新增主题主题"
)
@ResponseBody
@ResponseBody
public
String
addTopic
(
@RequestParam
String
topicTitle
){
public
String
addTopic
(
@RequestParam
String
topicTitle
){
...
@@ -56,7 +56,7 @@ public class TopicController {
...
@@ -56,7 +56,7 @@ public class TopicController {
}
}
@ApiOperation
(
"单个话题数据总览"
)
@ApiOperation
(
"单个话题数据总览"
)
@PostMapping
(
"/selectOne"
)
@PostMapping
(
"/
admin/
selectOne"
)
@ResponseBody
@ResponseBody
public
String
selectOne
(
@RequestParam
String
topicId
)
throws
MissingServletRequestParameterException
{
public
String
selectOne
(
@RequestParam
String
topicId
)
throws
MissingServletRequestParameterException
{
if
(
StringUtils
.
isEmpty
(
topicId
)){
if
(
StringUtils
.
isEmpty
(
topicId
)){
...
@@ -66,7 +66,7 @@ public class TopicController {
...
@@ -66,7 +66,7 @@ public class TopicController {
return
"success"
;
return
"success"
;
}
}
@PostMapping
(
value
=
"/setTop"
)
@PostMapping
(
value
=
"/
admin/
setTop"
)
@ApiOperation
(
"顶置/取消顶置主题"
)
@ApiOperation
(
"顶置/取消顶置主题"
)
@ResponseBody
@ResponseBody
public
String
setTopTopic
(
@RequestParam
String
topicId
,
@RequestParam
boolean
setTop
)
throws
MissingServletRequestParameterException
{
public
String
setTopTopic
(
@RequestParam
String
topicId
,
@RequestParam
boolean
setTop
)
throws
MissingServletRequestParameterException
{
...
@@ -77,7 +77,7 @@ public class TopicController {
...
@@ -77,7 +77,7 @@ public class TopicController {
return
"success"
;
return
"success"
;
}
}
@PostMapping
(
value
=
"/setConceal"
)
@PostMapping
(
value
=
"/
admin/
setConceal"
)
@ApiOperation
(
"隐藏/显示主题"
)
@ApiOperation
(
"隐藏/显示主题"
)
@ResponseBody
@ResponseBody
public
String
setConceal
(
@RequestParam
String
topicId
,
@RequestParam
boolean
setConceal
)
throws
MissingServletRequestParameterException
{
public
String
setConceal
(
@RequestParam
String
topicId
,
@RequestParam
boolean
setConceal
)
throws
MissingServletRequestParameterException
{
...
@@ -88,7 +88,7 @@ public class TopicController {
...
@@ -88,7 +88,7 @@ public class TopicController {
return
"success"
;
return
"success"
;
}
}
@PostMapping
(
value
=
"/modifyViewNum"
)
@PostMapping
(
value
=
"/
admin/
modifyViewNum"
)
@ApiOperation
(
"主题浏览数调整"
)
@ApiOperation
(
"主题浏览数调整"
)
@ResponseBody
@ResponseBody
public
String
modifyViewNum
(
@RequestParam
String
topicId
,
@RequestParam
Long
modifyMount
)
throws
MissingServletRequestParameterException
{
public
String
modifyViewNum
(
@RequestParam
String
topicId
,
@RequestParam
Long
modifyMount
)
throws
MissingServletRequestParameterException
{
...
@@ -96,6 +96,7 @@ public class TopicController {
...
@@ -96,6 +96,7 @@ public class TopicController {
throw
new
MissingServletRequestParameterException
(
"topicId"
,
"String"
);
throw
new
MissingServletRequestParameterException
(
"topicId"
,
"String"
);
}
}
//修改浏览量
//修改浏览量
topicManager
.
modifyPV
(
topicId
,
modifyMount
);
return
"success"
;
return
"success"
;
}
}
...
...
community-service/src/main/java/com/tanpu/community/controller/convert/ThemeConvert.java
View file @
2b17e820
...
@@ -12,6 +12,8 @@ public class ThemeConvert {
...
@@ -12,6 +12,8 @@ public class ThemeConvert {
ThemeDTO
themeDTO
=
new
ThemeDTO
();
ThemeDTO
themeDTO
=
new
ThemeDTO
();
BeanUtils
.
copyProperties
(
themeEntity
,
themeDTO
);
BeanUtils
.
copyProperties
(
themeEntity
,
themeDTO
);
themeDTO
.
setId
(
themeEntity
.
getId
());
themeDTO
.
setId
(
themeEntity
.
getId
());
themeDTO
.
setTitle
(
themeEntity
.
getTitle
());
themeDTO
.
setTopicId
(
themeEntity
.
getTopicId
());
themeDTO
.
setContent
(
themeEntity
.
getContent
());
themeDTO
.
setContent
(
themeEntity
.
getContent
());
themeDTO
.
setThemeType
(
themeEntity
.
getThemeType
());
themeDTO
.
setThemeType
(
themeEntity
.
getThemeType
());
themeDTO
.
setAttachment
(
themeEntity
.
getAttachment
());
themeDTO
.
setAttachment
(
themeEntity
.
getAttachment
());
...
@@ -28,6 +30,8 @@ public class ThemeConvert {
...
@@ -28,6 +30,8 @@ public class ThemeConvert {
public
static
ThemeEntity
convertToEntity
(
ThemeDTO
themeDTO
){
public
static
ThemeEntity
convertToEntity
(
ThemeDTO
themeDTO
){
ThemeEntity
themeEntity
=
new
ThemeEntity
();
ThemeEntity
themeEntity
=
new
ThemeEntity
();
themeEntity
.
setTitle
(
themeDTO
.
getTitle
());
themeEntity
.
setTopicId
(
themeDTO
.
getTopicId
());
themeEntity
.
setContent
(
themeDTO
.
getContent
());
themeEntity
.
setContent
(
themeDTO
.
getContent
());
themeEntity
.
setThemeType
(
themeDTO
.
getThemeType
());
themeEntity
.
setThemeType
(
themeDTO
.
getThemeType
());
themeEntity
.
setAttachment
(
themeDTO
.
getAttachment
());
themeEntity
.
setAttachment
(
themeDTO
.
getAttachment
());
...
...
community-service/src/main/java/com/tanpu/community/manager/ThemeManager.java
View file @
2b17e820
package
com
.
tanpu
.
community
.
manager
;
package
com
.
tanpu
.
community
.
manager
;
import
com.tanpu.community.api.beans.ThemeDTO
;
import
com.tanpu.community.api.constants.BlockTypeEnum
;
import
com.tanpu.community.api.constants.BlockTypeEnum
;
import
com.tanpu.community.api.constants.CollectionTypeEnum
;
import
com.tanpu.community.api.constants.CollectionTypeEnum
;
import
com.tanpu.community.api.constants.CommentTypeEnum
;
import
com.tanpu.community.api.constants.CommentTypeEnum
;
import
com.tanpu.community.dao.entity.community.*
;
import
com.tanpu.community.controller.convert.ThemeConvert
;
import
com.tanpu.community.dao.entity.community.BlackListEntity
;
import
com.tanpu.community.dao.entity.community.CommentEntity
;
import
com.tanpu.community.dao.entity.community.FansRelEntity
;
import
com.tanpu.community.dao.entity.community.ThemeEntity
;
import
com.tanpu.community.service.*
;
import
com.tanpu.community.service.*
;
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
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
java.time.Duration
;
import
java.time.LocalDateTime
;
import
java.time.format.DateTimeFormatter
;
import
java.util.List
;
import
java.util.List
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
...
@@ -29,17 +37,48 @@ public class ThemeManager {
...
@@ -29,17 +37,48 @@ public class ThemeManager {
@Autowired
@Autowired
private
BlackListService
blackListService
;
private
BlackListService
blackListService
;
@Autowired
private
RedisService
redisService
;
//返回推荐主题文章
//返回推荐主题文章
public
List
<
Theme
Entity
>
selectHotThemes
(){
public
List
<
Theme
DTO
>
selectHotThemes
(){
//TODO:根据算法计算推荐主题
//TODO:根据算法计算推荐主题
return
null
;
List
<
ThemeEntity
>
themeEntities
=
themeService
.
selectAll
();
List
<
ThemeDTO
>
themeDTOS
=
ThemeConvert
.
convertToDTOs
(
themeEntities
);
for
(
ThemeDTO
themeDTO
:
themeDTOS
)
{
themeDTO
.
setUpToNowTime
(
calUpToNowTime
(
themeDTO
.
getCreateTime
()));
//TODO 添加用户名、头像、认证
}
return
themeDTOS
;
}
}
//返回关注主题
//返回关注主题
public
List
<
Theme
Entity
>
selectInterestThemes
(
String
userId
){
public
List
<
Theme
DTO
>
selectInterestThemes
(
String
userId
){
List
<
String
>
fansList
=
fansRelService
.
queryFansByFollowerId
(
userId
).
stream
().
map
(
FansRelEntity:
:
getIdolId
).
collect
(
Collectors
.
toList
());
List
<
String
>
fansList
=
fansRelService
.
queryFansByFollowerId
(
userId
).
stream
().
map
(
FansRelEntity:
:
getIdolId
).
collect
(
Collectors
.
toList
());
List
<
ThemeEntity
>
result
=
themeService
.
selectByFans
(
fansList
);
List
<
ThemeEntity
>
themeEntities
=
themeService
.
selectByFans
(
fansList
);
return
null
;
List
<
ThemeDTO
>
themeDTOS
=
ThemeConvert
.
convertToDTOs
(
themeEntities
);
for
(
ThemeDTO
themeDTO
:
themeDTOS
)
{
themeDTO
.
setUpToNowTime
(
calUpToNowTime
(
themeDTO
.
getCreateTime
()));
//TODO 添加用户名、头像、认证
}
return
themeDTOS
;
}
private
String
calUpToNowTime
(
LocalDateTime
start
)
{
Duration
between
=
Duration
.
between
(
LocalDateTime
.
now
(),
start
);
long
duration
=
between
.
toMinutes
();
if
(
duration
<
1
){
return
"刚刚"
;
}
else
if
(
duration
<
60
){
return
duration
+
"分钟前"
;
}
else
if
(
duration
<
60
*
24
){
return
duration
/
60
+
"小时前"
;
}
else
if
(
start
.
getYear
()==
LocalDateTime
.
now
().
getYear
()){
return
start
.
format
(
DateTimeFormatter
.
ofPattern
(
"MM-dd HH:mm:ss"
));
}
return
start
.
format
(
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd HH:mm:ss"
));
}
}
//点赞
//点赞
...
@@ -116,4 +155,8 @@ public class ThemeManager {
...
@@ -116,4 +155,8 @@ public class ThemeManager {
// }
// }
// }
// }
public
void
insert
(
ThemeEntity
themeEntity
)
{
themeService
.
insertTheme
(
themeEntity
);
}
}
}
community-service/src/main/java/com/tanpu/community/manager/TopicManager.java
View file @
2b17e820
...
@@ -2,14 +2,17 @@ package com.tanpu.community.manager;
...
@@ -2,14 +2,17 @@ package com.tanpu.community.manager;
import
com.tanpu.common.exception.BizException
;
import
com.tanpu.common.exception.BizException
;
import
com.tanpu.community.api.beans.TopicDTO
;
import
com.tanpu.community.api.beans.TopicDTO
;
import
com.tanpu.community.api.constants.RedisKeyConstant
;
import
com.tanpu.community.api.constants.TopicStatusEnum
;
import
com.tanpu.community.controller.convert.TopicConverter
;
import
com.tanpu.community.controller.convert.TopicConverter
;
import
com.tanpu.community.dao.entity.community.ThemeEntity
;
import
com.tanpu.community.dao.entity.community.TopicEntity
;
import
com.tanpu.community.dao.entity.community.TopicEntity
;
import
com.tanpu.community.service.
TopicService
;
import
com.tanpu.community.service.
*
;
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
java.time.LocalDateTime
;
import
java.util.List
;
import
java.util.List
;
import
java.util.stream.Collectors
;
@Service
@Service
public
class
TopicManager
{
public
class
TopicManager
{
...
@@ -17,15 +20,25 @@ public class TopicManager {
...
@@ -17,15 +20,25 @@ public class TopicManager {
@Autowired
@Autowired
private
TopicService
topicService
;
private
TopicService
topicService
;
@Autowired
private
RedisService
redisService
;
@Autowired
private
ThemeService
themeService
;
@Autowired
private
CollectionService
collectionService
;
@Autowired
private
CommentService
commentService
;
public
void
insertTopic
(
String
topicTitle
,
String
userId
){
public
void
insertTopic
(
String
topicTitle
,
String
userId
){
TopicEntity
topicEntity
=
new
TopicEntity
();
TopicEntity
topicEntity
=
new
TopicEntity
();
topicEntity
.
setCreateBy
(
userId
);
topicEntity
.
setCreateBy
(
userId
);
topicEntity
.
setUpdateBy
(
userId
);
topicEntity
.
setUpdateBy
(
userId
);
topicEntity
.
setTopicTitle
(
topicTitle
);
topicEntity
.
setTopicTitle
(
topicTitle
);
topicEntity
.
setCreateTime
(
LocalDateTime
.
now
());
topicEntity
.
setIsTop
(
TopicStatusEnum
.
FALSE
.
getCode
());
topicEntity
.
setUpdateTime
(
LocalDateTime
.
now
());
topicEntity
.
setIsConceal
(
TopicStatusEnum
.
FALSE
.
getCode
());
topicEntity
.
setIsTop
(
0
);
topicEntity
.
setIsConceal
(
0
);
topicService
.
addTopic
(
topicEntity
);
topicService
.
addTopic
(
topicEntity
);
}
}
...
@@ -61,7 +74,36 @@ public class TopicManager {
...
@@ -61,7 +74,36 @@ public class TopicManager {
public
TopicDTO
getDetail
(
String
topicId
)
{
public
TopicDTO
getDetail
(
String
topicId
)
{
TopicEntity
topicEntity
=
topicService
.
queryById
(
topicId
);
TopicEntity
topicEntity
=
topicService
.
queryById
(
topicId
);
TopicDTO
topicDTO
=
TopicConverter
.
convertToDTO
(
topicEntity
);
TopicDTO
topicDTO
=
TopicConverter
.
convertToDTO
(
topicEntity
);
//TODO:添加实时数据
//TODO:添加实时数据(浏览量,点赞量,评论量,收藏量)
topicDTO
.
setViewAmount
(
redisService
.
getLong
(
RedisKeyConstant
.
TOPIC_VIEW_AMOUNT_
+
topicId
));
topicDTO
.
setLikeAmount
(
redisService
.
getLong
(
RedisKeyConstant
.
TOPIC_LIKE_AMOUNT_
+
topicId
));
topicDTO
.
setUserAmount
(
redisService
.
getLong
(
RedisKeyConstant
.
TOPIC_USER_AMOUNT_
+
topicId
));
return
topicDTO
;
return
topicDTO
;
}
}
public
void
modifyPV
(
String
topicId
,
Long
modifyMount
)
{
if
(
modifyMount
>
0
){
redisService
.
incr
(
RedisKeyConstant
.
TOPIC_VIEW_AMOUNT_
+
topicId
,
modifyMount
);
}
else
{
redisService
.
decr
(
RedisKeyConstant
.
TOPIC_VIEW_AMOUNT_
+
topicId
,-
modifyMount
);
}
}
public
void
calculate
(){
List
<
String
>
topicIds
=
topicService
.
queryTopicList
().
stream
().
map
(
TopicEntity:
:
getId
).
collect
(
Collectors
.
toList
());
for
(
String
topicId
:
topicIds
)
{
List
<
ThemeEntity
>
themeEntities
=
themeService
.
selectByTopic
(
topicId
);
List
<
String
>
themeIds
=
themeEntities
.
stream
().
map
(
ThemeEntity:
:
getId
).
collect
(
Collectors
.
toList
());
Long
likeAmountByThemeIds
=
collectionService
.
getLikeAmountByThemeIds
(
themeIds
);
Long
bookAmountByThemeIds
=
collectionService
.
getBookAmountByThemeIds
(
themeIds
);
Long
commentAmountByThemeIds
=
commentService
.
getCommentAmountByThemeIds
(
themeIds
);
redisService
.
set
(
RedisKeyConstant
.
TOPIC_LIKE_AMOUNT_
+
topicId
,
likeAmountByThemeIds
);
redisService
.
set
(
RedisKeyConstant
.
TOPIC_BOOK_AMOUNT_
+
topicId
,
bookAmountByThemeIds
);
redisService
.
set
(
RedisKeyConstant
.
TOPIC_COMMENT_AMOUNT_
+
topicId
,
commentAmountByThemeIds
);
}
}
}
}
community-service/src/main/java/com/tanpu/community/service/CollectionService.java
View file @
2b17e820
package
com
.
tanpu
.
community
.
service
;
package
com
.
tanpu
.
community
.
service
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.tanpu.community.api.constants.CollectionTypeEnum
;
import
com.tanpu.community.api.constants.CollectionTypeEnum
;
import
com.tanpu.community.dao.entity.community.CollectionEntity
;
import
com.tanpu.community.dao.entity.community.CollectionEntity
;
import
com.tanpu.community.dao.mapper.community.CollectionMapper
;
import
com.tanpu.community.dao.mapper.community.CollectionMapper
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
java.time.LocalDateTime
;
import
java.util.List
;
import
java.util.List
;
@Service
@Service
...
@@ -30,12 +27,46 @@ public class CollectionService {
...
@@ -30,12 +27,46 @@ public class CollectionService {
//根据用户id获取点赞列表
//根据用户id获取点赞列表
public
List
<
CollectionEntity
>
getLikeListByUser
(
String
userId
){
public
List
<
CollectionEntity
>
getLikeListByUser
(
String
userId
){
return
collectionMapper
.
selectList
(
new
LambdaQueryWrapper
<
CollectionEntity
>().
eq
(
CollectionEntity:
:
getCollectionType
,
1
));
return
collectionMapper
.
selectList
(
new
LambdaQueryWrapper
<
CollectionEntity
>()
.
eq
(
CollectionEntity:
:
getCollectionType
,
CollectionTypeEnum
.
LIKE
.
getCode
()));
}
}
//根据用户id获取收藏列表
//根据用户id获取收藏列表
public
List
<
CollectionEntity
>
getBookListByUser
(
String
userId
){
public
List
<
CollectionEntity
>
getBookListByUser
(
String
userId
){
return
collectionMapper
.
selectList
(
new
LambdaQueryWrapper
<
CollectionEntity
>().
eq
(
CollectionEntity:
:
getCollectionType
,
2
));
return
collectionMapper
.
selectList
(
new
LambdaQueryWrapper
<
CollectionEntity
>()
.
eq
(
CollectionEntity:
:
getCollectionType
,
CollectionTypeEnum
.
BOOK
.
getCode
()));
}
//统计主题的点赞量
public
Long
getLikeAmountByThemeId
(
String
themeId
){
return
(
long
)
collectionMapper
.
selectList
((
new
LambdaQueryWrapper
<
CollectionEntity
>()
.
eq
(
CollectionEntity:
:
getTargetId
,
themeId
)
.
eq
(
CollectionEntity:
:
getCollectionType
,
CollectionTypeEnum
.
LIKE
.
getCode
())))
.
size
();
}
//统计主题集合的点赞量
public
Long
getLikeAmountByThemeIds
(
List
<
String
>
themeIds
){
return
(
long
)
collectionMapper
.
selectList
((
new
LambdaQueryWrapper
<
CollectionEntity
>()
.
in
(
CollectionEntity:
:
getTargetId
,
themeIds
)
.
eq
(
CollectionEntity:
:
getCollectionType
,
CollectionTypeEnum
.
LIKE
.
getCode
())))
.
size
();
}
//统计主题的收藏量
public
Long
getBookAmountByThemeId
(
String
themeId
){
return
(
long
)
collectionMapper
.
selectList
((
new
LambdaQueryWrapper
<
CollectionEntity
>()
.
eq
(
CollectionEntity:
:
getTargetId
,
themeId
)
.
eq
(
CollectionEntity:
:
getCollectionType
,
CollectionTypeEnum
.
BOOK
.
getCode
())))
.
size
();
}
//统计主题集合的收藏量
public
Long
getBookAmountByThemeIds
(
List
<
String
>
themeIds
){
return
(
long
)
collectionMapper
.
selectList
((
new
LambdaQueryWrapper
<
CollectionEntity
>()
.
in
(
CollectionEntity:
:
getTargetId
,
themeIds
)
.
eq
(
CollectionEntity:
:
getCollectionType
,
CollectionTypeEnum
.
BOOK
.
getCode
())))
.
size
();
}
}
}
}
community-service/src/main/java/com/tanpu/community/service/CommentService.java
View file @
2b17e820
...
@@ -24,4 +24,11 @@ public class CommentService {
...
@@ -24,4 +24,11 @@ public class CommentService {
public
List
<
CommentEntity
>
selectByUserId
(
String
userId
){
public
List
<
CommentEntity
>
selectByUserId
(
String
userId
){
return
commentMapper
.
selectList
(
new
LambdaQueryWrapper
<
CommentEntity
>().
eq
(
CommentEntity:
:
getAuthorId
,
userId
));
return
commentMapper
.
selectList
(
new
LambdaQueryWrapper
<
CommentEntity
>().
eq
(
CommentEntity:
:
getAuthorId
,
userId
));
}
}
//统计主题集合的评论量
public
Long
getCommentAmountByThemeIds
(
List
<
String
>
themeIds
){
return
(
long
)
commentMapper
.
selectList
((
new
LambdaQueryWrapper
<
CommentEntity
>()
.
in
(
CommentEntity:
:
getTargetId
,
themeIds
)))
.
size
();
}
}
}
community-service/src/main/java/com/tanpu/community/service/RedisService.java
View file @
2b17e820
...
@@ -46,6 +46,11 @@ public class RedisService {
...
@@ -46,6 +46,11 @@ public class RedisService {
return
v
==
null
?
null
:
(
Integer
)
v
;
return
v
==
null
?
null
:
(
Integer
)
v
;
}
}
public
Long
getLong
(
String
key
)
{
Object
v
=
redisTemplate
.
opsForValue
().
get
(
key
);
return
v
==
null
?
null
:
(
Long
)
v
;
}
/**
/**
* incr
* incr
*/
*/
...
...
community-service/src/main/java/com/tanpu/community/service/ThemeService.java
View file @
2b17e820
...
@@ -25,10 +25,20 @@ public class ThemeService {
...
@@ -25,10 +25,20 @@ public class ThemeService {
//根据话题查询主题
//根据话题查询主题
public
List
<
ThemeEntity
>
selectByTopic
(
String
topidId
){
public
List
<
ThemeEntity
>
selectByTopic
(
String
topidId
){
return
themeMapper
.
selectList
(
new
LambdaQueryWrapper
<
ThemeEntity
>().
eq
(
ThemeEntity:
:
getTopicId
,
topidId
));
return
themeMapper
.
selectList
(
new
LambdaQueryWrapper
<
ThemeEntity
>()
.
eq
(
ThemeEntity:
:
getTopicId
,
topidId
));
}
}
//查询列表中用户的主题
//查询列表中用户的主题
public
List
<
ThemeEntity
>
selectByFans
(
List
<
String
>
fansList
)
{
public
List
<
ThemeEntity
>
selectByFans
(
List
<
String
>
fansList
)
{
return
themeMapper
.
selectList
(
new
LambdaQueryWrapper
<
ThemeEntity
>().
in
(
ThemeEntity:
:
getAuthorId
,
fansList
));
return
themeMapper
.
selectList
(
new
LambdaQueryWrapper
<
ThemeEntity
>()
.
in
(
ThemeEntity:
:
getAuthorId
,
fansList
)
.
orderByDesc
(
ThemeEntity:
:
getUpdateTime
));
}
//查询列表中用户的主题
public
List
<
ThemeEntity
>
selectAll
()
{
return
themeMapper
.
selectList
(
new
LambdaQueryWrapper
<
ThemeEntity
>()
.
orderByDesc
(
ThemeEntity:
:
getUpdateTime
));
}
}
}
}
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