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
08e0f0eb
Commit
08e0f0eb
authored
Dec 10, 2021
by
刘基明
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'bugfix_1208' into 'master'
Bugfix 1208 See merge request
!31
parents
4a3fa523
0552c522
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
65 additions
and
24 deletions
+65
-24
CourseSimpleResp.java
...community/api/beans/vo/feign/course/CourseSimpleResp.java
+3
-0
RedisCache.java
...e/src/main/java/com/tanpu/community/cache/RedisCache.java
+10
-1
TimesCountEntity.java
...anpu/community/dao/entity/community/TimesCountEntity.java
+1
-1
ConJobManager.java
.../main/java/com/tanpu/community/manager/ConJobManager.java
+4
-4
ThemeManager.java
...c/main/java/com/tanpu/community/manager/ThemeManager.java
+35
-12
RankLogService.java
...main/java/com/tanpu/community/service/RankLogService.java
+0
-2
RankService.java
...rc/main/java/com/tanpu/community/service/RankService.java
+10
-2
application-test.yml
community-service/src/main/resources/application-test.yml
+2
-2
No files found.
community-api/src/main/java/com/tanpu/community/api/beans/vo/feign/course/CourseSimpleResp.java
View file @
08e0f0eb
...
@@ -49,4 +49,7 @@ public class CourseSimpleResp {
...
@@ -49,4 +49,7 @@ public class CourseSimpleResp {
@ApiModelProperty
(
"状态 0:待上架 1:上架 2:下架"
)
@ApiModelProperty
(
"状态 0:待上架 1:上架 2:下架"
)
private
Integer
status
;
private
Integer
status
;
@ApiModelProperty
(
"付费模式 1:免费 2:积分 3:现金"
)
private
Integer
modal
;
}
}
community-service/src/main/java/com/tanpu/community/cache/RedisCache.java
View file @
08e0f0eb
...
@@ -14,7 +14,7 @@ public class RedisCache {
...
@@ -14,7 +14,7 @@ public class RedisCache {
private
String
cacheName
;
private
String
cacheName
;
private
RedisHelper
redisHelper
;
private
RedisHelper
redisHelper
;
public
<
T
>
T
getObject
(
String
key
,
Integer
expireSeconds
,
Supplier
<
T
>
func
,
Class
<
T
>
clz
)
{
public
<
T
>
T
getObject
(
String
key
,
Integer
expireSeconds
,
Supplier
<
T
>
func
,
Class
<
T
>
clz
)
{
String
value
=
get
(
key
);
String
value
=
get
(
key
);
// todo 考虑缓存穿透的问题.
// todo 考虑缓存穿透的问题.
if
(
StringUtils
.
isNotBlank
(
value
))
{
if
(
StringUtils
.
isNotBlank
(
value
))
{
...
@@ -80,6 +80,15 @@ public class RedisCache {
...
@@ -80,6 +80,15 @@ public class RedisCache {
}
}
}
}
public
boolean
setIfAbsent
(
String
key
,
String
value
,
Integer
expireSeconds
)
{
key
=
cacheName
+
":"
+
key
;
if
(
expireSeconds
==
0
)
{
return
redisHelper
.
setIfAbsent
(
key
,
value
);
}
else
{
return
redisHelper
.
setIfAbsent
(
key
,
value
,
Duration
.
ofSeconds
(
expireSeconds
));
}
}
private
void
delete
(
String
key
)
{
private
void
delete
(
String
key
)
{
redisHelper
.
delete
(
key
);
redisHelper
.
delete
(
key
);
}
}
...
...
community-service/src/main/java/com/tanpu/community/dao/entity/community/TimesCountEntity.java
View file @
08e0f0eb
...
@@ -11,6 +11,6 @@ public class TimesCountEntity {
...
@@ -11,6 +11,6 @@ public class TimesCountEntity {
@ApiModelProperty
(
value
=
"次数"
)
@ApiModelProperty
(
value
=
"次数"
)
private
Integer
times
;
private
Integer
times
;
@ApiModelProperty
(
value
=
"
目标
id"
)
@ApiModelProperty
(
value
=
"
统计对象
id"
)
private
String
id
;
private
String
id
;
}
}
community-service/src/main/java/com/tanpu/community/manager/ConJobManager.java
View file @
08e0f0eb
...
@@ -30,7 +30,7 @@ public class ConJobManager {
...
@@ -30,7 +30,7 @@ public class ConJobManager {
/**
/**
* 定时统计 话题 访问数据,并刷到redis
* 定时统计 话题 访问数据,并刷到redis
*/
*/
@Scheduled
(
cron
=
"*/10 * * * * ?"
)
//
@Scheduled(cron = "*/10 * * * * ?")
public
void
topicVisitorStats
()
{
public
void
topicVisitorStats
()
{
String
topicId
=
"123"
;
String
topicId
=
"123"
;
Integer
detailVisitTimes
=
visitLogService
.
queryTopicDetailVisit
(
topicId
);
Integer
detailVisitTimes
=
visitLogService
.
queryTopicDetailVisit
(
topicId
);
...
@@ -40,16 +40,16 @@ public class ConJobManager {
...
@@ -40,16 +40,16 @@ public class ConJobManager {
/**
/**
* 定时统计主题、话题排行
* 定时统计主题、话题排行
*/
*/
@Scheduled
(
cron
=
"
*/30 *
* * * ?"
)
@Scheduled
(
cron
=
"
10 0/2
* * * ?"
)
public
void
themeRank
()
{
public
void
themeRank
()
{
rankService
.
rankThemes
();
rankService
.
rankThemes
();
rankService
.
rankTopics
();
rankService
.
rankTopics
();
}
}
/**
/**
* 定时
统计主题、话题排行
* 定时
刷新最新帖子
*/
*/
@Scheduled
(
cron
=
"*/
5
* * * * ?"
)
@Scheduled
(
cron
=
"*/
10
* * * * ?"
)
public
void
getThemeNewest
()
{
public
void
getThemeNewest
()
{
recommendService
.
refreshNewestThemes
();
recommendService
.
refreshNewestThemes
();
}
}
...
...
community-service/src/main/java/com/tanpu/community/manager/ThemeManager.java
View file @
08e0f0eb
...
@@ -555,11 +555,12 @@ public class ThemeManager {
...
@@ -555,11 +555,12 @@ public class ThemeManager {
List
<
ThemeQo
>
themeQos
=
ConvertUtil
.
themeEntitiesToDTOs
(
themeEntities
);
List
<
ThemeQo
>
themeQos
=
ConvertUtil
.
themeEntitiesToDTOs
(
themeEntities
);
// 批量查询附件detail
// 批量查询附件detail
batchFeignCallService
.
getAttachDetailByBatch
(
themeQos
);
batchFeignCallService
.
getAttachDetailByBatch
(
themeQos
);
//其他信息
// 转赞评
for
(
ThemeQo
themeQO
:
themeQos
)
{
batchBuildThemeCountInfo
(
themeQos
);
// 通用信息
buildThemeQoExtraInfo
(
themeQO
);
// 转发对象
for
(
ThemeQo
themeQO
:
themeQos
)
{
buildThemeForwardObj
(
themeQO
);
}
}
// 和用户相关信息
// 和用户相关信息
if
(
StringUtils
.
isNotEmpty
(
userId
))
{
if
(
StringUtils
.
isNotEmpty
(
userId
))
{
...
@@ -568,29 +569,50 @@ public class ThemeManager {
...
@@ -568,29 +569,50 @@ public class ThemeManager {
return
themeQos
;
return
themeQos
;
}
}
// 转发对象
、点赞、收藏、转发数
// 转发对象
private
void
buildTheme
QoExtraInfo
(
ThemeQo
themeQo
)
{
private
void
buildTheme
ForwardObj
(
ThemeQo
themeQo
)
{
String
themeId
=
themeQo
.
getThemeId
();
String
themeId
=
themeQo
.
getThemeId
();
// 封装转发对象
// 封装转发对象
FormerThemeQo
former
=
redisCache
.
getObject
(
StringUtils
.
joinWith
(
"_"
,
CACHE_FORWARD_THEME_ID
,
themeQo
.
getFormerThemeId
()),
60
,
FormerThemeQo
former
=
redisCache
.
getObject
(
StringUtils
.
joinWith
(
"_"
,
CACHE_FORWARD_THEME_ID
,
themeQo
.
getFormerThemeId
()),
60
,
()
->
this
.
getFormerTheme
(
themeQo
.
getFormerThemeId
()),
FormerThemeQo
.
class
);
()
->
this
.
getFormerTheme
(
themeQo
.
getFormerThemeId
()),
FormerThemeQo
.
class
);
themeQo
.
setFormerTheme
(
former
);
themeQo
.
setFormerTheme
(
former
);
}
// 单个查询 点赞、收藏、转发数
private
void
buildThemeCountInfo
(
ThemeQo
themeQo
)
{
String
themeId
=
themeQo
.
getThemeId
();
// 点赞,收藏,转发
// 点赞,收藏,转发
Integer
likeCount
=
redisCache
.
getObject
(
StringUtils
.
joinWith
(
"_"
,
THEME_LIKE_COUNT
,
themeId
),
60
,
Integer
likeCount
=
redisCache
.
getObject
(
StringUtils
.
joinWith
(
"_"
,
THEME_LIKE_COUNT
,
themeId
),
60
*
60
*
24
,
()
->
collectionService
.
getCountByTypeAndId
(
themeId
,
CollectionTypeEnum
.
LIKE_THEME
),
Integer
.
class
);
()
->
collectionService
.
getCountByTypeAndId
(
themeId
,
CollectionTypeEnum
.
LIKE_THEME
),
Integer
.
class
);
Integer
commentCount
=
redisCache
.
getObject
(
StringUtils
.
joinWith
(
"_"
,
THEME_COMMENT_COUNT
,
themeId
),
60
,
Integer
commentCount
=
redisCache
.
getObject
(
StringUtils
.
joinWith
(
"_"
,
THEME_COMMENT_COUNT
,
themeId
),
60
*
60
*
24
,
()
->
commentService
.
getCommentCountByThemeId
(
themeId
),
Integer
.
class
);
()
->
commentService
.
getCommentCountByThemeId
(
themeId
),
Integer
.
class
);
Integer
forwardCount
=
redisCache
.
getObject
(
StringUtils
.
joinWith
(
"_"
,
THEME_FORWARD_COUNT
,
themeId
),
60
,
Integer
forwardCount
=
redisCache
.
getObject
(
StringUtils
.
joinWith
(
"_"
,
THEME_FORWARD_COUNT
,
themeId
),
60
*
60
*
24
,
()
->
themeService
.
getForwardCountById
(
themeId
),
Integer
.
class
);
()
->
themeService
.
getForwardCountById
(
themeId
),
Integer
.
class
);
themeQo
.
setCommentCount
(
commentCount
);
themeQo
.
setCommentCount
(
commentCount
);
themeQo
.
setLikeCount
(
likeCount
);
themeQo
.
setLikeCount
(
likeCount
);
themeQo
.
setForwardCount
(
forwardCount
);
themeQo
.
setForwardCount
(
forwardCount
);
}
}
// 批量-点赞、收藏、转发数
private
void
batchBuildThemeCountInfo
(
List
<
ThemeQo
>
themeQos
)
{
List
<
String
>
themeIds
=
themeQos
.
stream
().
map
(
ThemeQo:
:
getThemeId
).
collect
(
Collectors
.
toList
());
// 点赞,收藏,转发
Map
<
String
,
Integer
>
likeCountMap
=
collectionService
.
getCountMapByType
(
themeIds
,
CollectionTypeEnum
.
LIKE_THEME
);
Map
<
String
,
Integer
>
commentCountMap
=
commentService
.
getCountMapByThemeIds
(
themeIds
);
Map
<
String
,
Integer
>
forwardCountMap
=
themeService
.
getForwardCountMap
(
themeIds
);
themeQos
.
stream
().
forEach
(
o
->
{
o
.
setCommentCount
(
commentCountMap
.
getOrDefault
(
o
.
getThemeId
(),
0
));
o
.
setLikeCount
(
likeCountMap
.
getOrDefault
(
o
.
getThemeId
(),
0
));
o
.
setForwardCount
(
forwardCountMap
.
getOrDefault
(
o
.
getThemeId
(),
0
));
});
}
// 组装和当前用户相关信息(单个查询)
// 组装和当前用户相关信息(单个查询)
private
void
buildThemeExtraInfoByUser
(
String
userId
,
ThemeQo
themeQo
)
{
private
void
buildThemeExtraInfoByUser
(
String
userId
,
ThemeQo
themeQo
)
{
String
themeId
=
themeQo
.
getThemeId
();
String
themeId
=
themeQo
.
getThemeId
();
...
@@ -688,7 +710,8 @@ public class ThemeManager {
...
@@ -688,7 +710,8 @@ public class ThemeManager {
batchFeignCallService
.
getAttachDetail
(
themeQo
);
batchFeignCallService
.
getAttachDetail
(
themeQo
);
//转发、收藏、点赞
//转发、收藏、点赞
buildThemeQoExtraInfo
(
themeQo
);
buildThemeForwardObj
(
themeQo
);
buildThemeCountInfo
(
themeQo
);
// 添加用户相关信息
// 添加用户相关信息
if
(
StringUtils
.
isNotEmpty
(
userId
))
{
if
(
StringUtils
.
isNotEmpty
(
userId
))
{
...
@@ -832,13 +855,13 @@ public class ThemeManager {
...
@@ -832,13 +855,13 @@ public class ThemeManager {
while
(
content
.
length
()
>
5000
)
{
while
(
content
.
length
()
>
5000
)
{
b
=
TencentcloudUtils
.
textModeration
(
content
.
substring
(
0
,
5000
));
b
=
TencentcloudUtils
.
textModeration
(
content
.
substring
(
0
,
5000
));
if
(
StringUtils
.
isNotBlank
(
b
))
{
if
(
StringUtils
.
isNotBlank
(
b
))
{
throw
new
BizException
(
ErrorCodeConstant
.
CONTENT_ILLEGAL
.
getCode
(),
"疑似违规词汇:"
+
b
);
throw
new
BizException
(
ErrorCodeConstant
.
CONTENT_ILLEGAL
.
getCode
(),
"疑似违规词汇:"
+
b
);
}
}
content
=
content
.
substring
(
5000
);
content
=
content
.
substring
(
5000
);
}
}
b
=
TencentcloudUtils
.
textModeration
(
content
);
b
=
TencentcloudUtils
.
textModeration
(
content
);
if
(
StringUtils
.
isNotBlank
(
b
))
{
if
(
StringUtils
.
isNotBlank
(
b
))
{
throw
new
BizException
(
ErrorCodeConstant
.
CONTENT_ILLEGAL
.
getCode
(),
"疑似违规词汇:"
+
b
);
throw
new
BizException
(
ErrorCodeConstant
.
CONTENT_ILLEGAL
.
getCode
(),
"疑似违规词汇:"
+
b
);
}
}
...
...
community-service/src/main/java/com/tanpu/community/service/RankLogService.java
View file @
08e0f0eb
...
@@ -11,7 +11,6 @@ import com.tanpu.community.util.BizUtils;
...
@@ -11,7 +11,6 @@ import com.tanpu.community.util.BizUtils;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.io.IOUtils
;
import
org.apache.commons.io.IOUtils
;
import
org.apache.commons.lang3.time.DateUtils
;
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.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
...
@@ -20,7 +19,6 @@ import javax.annotation.Resource;
...
@@ -20,7 +19,6 @@ import javax.annotation.Resource;
import
java.io.ByteArrayOutputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.time.LocalDateTime
;
import
java.time.LocalDateTime
;
import
java.time.format.DateTimeFormatter
;
import
java.time.format.DateTimeFormatter
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
...
...
community-service/src/main/java/com/tanpu/community/service/RankService.java
View file @
08e0f0eb
...
@@ -135,9 +135,17 @@ public class RankService {
...
@@ -135,9 +135,17 @@ public class RankService {
hotestThemes
=
themeAnalysDOS
.
stream
()
hotestThemes
=
themeAnalysDOS
.
stream
()
.
sorted
(
Comparator
.
comparing
(
ThemeAnalysDO:
:
getScore
).
reversed
())
.
sorted
(
Comparator
.
comparing
(
ThemeAnalysDO:
:
getScore
).
reversed
())
.
collect
(
Collectors
.
toList
());
.
collect
(
Collectors
.
toList
());
//落库
// 落库
try
{
if
(
redisCache
.
setIfAbsent
(
"logThemeRank"
,
"1"
,
15
)){
rankLogService
.
logThemeRank
(
hotestThemes
,
start
,
TimeUtils
.
calMillisTillNow
(
start
));
rankLogService
.
logThemeRank
(
hotestThemes
,
start
,
TimeUtils
.
calMillisTillNow
(
start
));
}
}
}
finally
{
redisCache
.
evict
(
"logThemeRank"
);
}
}
/**
/**
...
...
community-service/src/main/resources/application-test.yml
View file @
08e0f0eb
...
@@ -95,7 +95,7 @@ tmpfile:
...
@@ -95,7 +95,7 @@ tmpfile:
tanpu
:
tanpu
:
fatools
:
fatools
:
svc
:
127.0.0.1:8189
svc
:
https://testtamper.tanpuyun.com
product
:
product
:
svc
:
https://testtamper.tanpuyun.com
svc
:
https://testtamper.tanpuyun.com
jifen
:
jifen
:
...
@@ -118,7 +118,7 @@ tanpu:
...
@@ -118,7 +118,7 @@ tanpu:
#打印SQL语句
#打印SQL语句
logging
:
logging
:
level
:
level
:
com.tanpu.community.dao
:
debug
com.tanpu.community.dao
:
info
org.springframework.jdbc.core.JdbcTemplate
:
debug
org.springframework.jdbc.core.JdbcTemplate
:
debug
pagehelper
:
pagehelper
:
...
...
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