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
38c29f07
Commit
38c29f07
authored
Jul 30, 2021
by
刘基明
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
排序落库
parent
30ed778b
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
207 additions
and
22 deletions
+207
-22
TopicRankQo.java
...in/java/com/tanpu/community/api/beans/qo/TopicRankQo.java
+5
-2
RankLogTypeEnum.java
...n/java/com/tanpu/community/api/enums/RankLogTypeEnum.java
+38
-0
RankLogEntity.java
...m/tanpu/community/dao/entity/community/RankLogEntity.java
+52
-10
RankLogMapper.java
...m/tanpu/community/dao/mapper/community/RankLogMapper.java
+2
-2
RankLogService.java
...main/java/com/tanpu/community/service/RankLogService.java
+68
-0
RankService.java
...rc/main/java/com/tanpu/community/service/RankService.java
+15
-3
ThemeService.java
...c/main/java/com/tanpu/community/service/ThemeService.java
+1
-1
ConvertUtil.java
...e/src/main/java/com/tanpu/community/util/ConvertUtil.java
+1
-0
TimeUtils.java
...ice/src/main/java/com/tanpu/community/util/TimeUtils.java
+19
-1
RankLogEntityMapper.xml
...c/main/resources/mapper/community/RankLogEntityMapper.xml
+6
-3
No files found.
community-api/src/main/java/com/tanpu/community/api/beans/qo/TopicRankQo.java
View file @
38c29f07
...
...
@@ -38,16 +38,19 @@ public class TopicRankQo {
@ApiModelProperty
(
value
=
"话题下的帖子权重"
)
private
Integer
themeWeight
;
private
Integer
hoursTillNow
;
/**
*
TODO
热度计算算法
* 热度计算算法
*
* @return
*/
public
Integer
getRank
()
{
double
g
=
0.3
;
//时间系数
//顶置话题
if
(
isTop
>
0
)
{
return
Integer
.
MAX_VALUE
;
}
return
this
.
disscussCount
*
3
+
viewCount
+
themeWeight
;
return
(
int
)((
disscussCount
*
3
+
viewCount
)/
Math
.
pow
(
hoursTillNow
+
1
,
g
))
+
themeWeight
;
}
}
community-api/src/main/java/com/tanpu/community/api/enums/RankLogTypeEnum.java
0 → 100644
View file @
38c29f07
package
com
.
tanpu
.
community
.
api
.
enums
;
import
org.apache.commons.collections4.SetUtils
;
import
java.util.HashSet
;
public
enum
RankLogTypeEnum
{
TOPIC
(
1
,
"话题排序"
),
THEME
(
2
,
"主题排序"
);
public
static
final
HashSet
<
String
>
imageTypeSet
=
SetUtils
.
hashSet
(
"jpg"
,
"jpeg"
,
"png"
);
private
Integer
code
;
private
String
type
;
RankLogTypeEnum
(
Integer
code
,
String
type
)
{
this
.
code
=
code
;
this
.
type
=
type
;
}
public
Integer
getCode
()
{
return
code
;
}
public
void
setCode
(
Integer
code
)
{
this
.
code
=
code
;
}
public
String
getType
()
{
return
type
;
}
public
void
setType
(
String
type
)
{
this
.
type
=
type
;
}
}
community-service/src/main/java/com/tanpu/community/dao/entity/community/
Topic
RankLogEntity.java
→
community-service/src/main/java/com/tanpu/community/dao/entity/community/RankLogEntity.java
View file @
38c29f07
...
...
@@ -5,6 +5,9 @@ import com.baomidou.mybatisplus.annotation.TableId;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
import
lombok.NoArgsConstructor
;
import
java.io.Serializable
;
import
java.time.LocalDateTime
;
...
...
@@ -17,9 +20,12 @@ import java.time.LocalDateTime;
* @author xudong
* @since 2021-07-30
*/
@TableName
(
"topic_rank_log"
)
@ApiModel
(
value
=
"TopicRankLogEntity对象"
,
description
=
"话题排序日志记录’"
)
public
class
TopicRankLogEntity
implements
Serializable
{
@TableName
(
"rank_log"
)
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ApiModel
(
value
=
"RankLogEntity对象"
,
description
=
"话题排序日志记录’"
)
public
class
RankLogEntity
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
...
...
@@ -27,6 +33,9 @@ public class TopicRankLogEntity implements Serializable {
@TableId
(
value
=
"id"
,
type
=
IdType
.
AUTO
)
private
Long
id
;
@ApiModelProperty
(
value
=
"1:话题 2:主题"
)
private
Integer
type
;
@ApiModelProperty
(
value
=
"总排序数量"
)
private
Integer
totalCount
;
...
...
@@ -37,7 +46,13 @@ public class TopicRankLogEntity implements Serializable {
private
Integer
pageSize
;
@ApiModelProperty
(
value
=
"排序内容"
)
private
String
info
;
private
String
content
;
@ApiModelProperty
(
value
=
"花费间隔,单位毫秒"
)
private
Long
rankCost
;
@ApiModelProperty
(
value
=
"排序时间"
)
private
LocalDateTime
rankTime
;
private
LocalDateTime
createTime
;
...
...
@@ -54,6 +69,14 @@ public class TopicRankLogEntity implements Serializable {
this
.
id
=
id
;
}
public
Integer
getType
()
{
return
type
;
}
public
void
setType
(
Integer
type
)
{
this
.
type
=
type
;
}
public
Integer
getTotalCount
()
{
return
totalCount
;
}
...
...
@@ -78,12 +101,28 @@ public class TopicRankLogEntity implements Serializable {
this
.
pageSize
=
pageSize
;
}
public
String
getInfo
()
{
return
info
;
public
String
getContent
()
{
return
content
;
}
public
void
setContent
(
String
content
)
{
this
.
content
=
content
;
}
public
Long
getRankCost
()
{
return
rankCost
;
}
public
void
setRankCost
(
Long
rankCost
)
{
this
.
rankCost
=
rankCost
;
}
public
LocalDateTime
getRankTime
()
{
return
rankTime
;
}
public
void
set
Info
(
String
info
)
{
this
.
info
=
info
;
public
void
set
RankTime
(
LocalDateTime
rankTime
)
{
this
.
rankTime
=
rankTime
;
}
public
LocalDateTime
getCreateTime
()
{
...
...
@@ -112,12 +151,15 @@ public class TopicRankLogEntity implements Serializable {
@Override
public
String
toString
()
{
return
"
Topic
RankLogEntity{"
+
return
"RankLogEntity{"
+
"id="
+
id
+
", type="
+
type
+
", totalCount="
+
totalCount
+
", pageNumber="
+
pageNumber
+
", pageSize="
+
pageSize
+
", info="
+
info
+
", content="
+
content
+
", rankCost="
+
rankCost
+
", rankTime="
+
rankTime
+
", createTime="
+
createTime
+
", updateTime="
+
updateTime
+
", deleteTag="
+
deleteTag
+
...
...
community-service/src/main/java/com/tanpu/community/dao/mapper/community/
Topic
RankLogMapper.java
→
community-service/src/main/java/com/tanpu/community/dao/mapper/community/RankLogMapper.java
View file @
38c29f07
package
com
.
tanpu
.
community
.
dao
.
mapper
.
community
;
import
com.tanpu.community.dao.entity.community.
Topic
RankLogEntity
;
import
com.tanpu.community.dao.entity.community.RankLogEntity
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
/**
...
...
@@ -11,6 +11,6 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
* @author xudong
* @since 2021-07-30
*/
public
interface
TopicRankLogMapper
extends
BaseMapper
<
Topic
RankLogEntity
>
{
public
interface
RankLogMapper
extends
BaseMapper
<
RankLogEntity
>
{
}
community-service/src/main/java/com/tanpu/community/service/RankLogService.java
0 → 100644
View file @
38c29f07
package
com
.
tanpu
.
community
.
service
;
import
com.tanpu.common.util.JsonUtil
;
import
com.tanpu.community.api.beans.qo.ThemeAnalysDO
;
import
com.tanpu.community.api.beans.qo.TopicRankQo
;
import
com.tanpu.community.api.enums.RankLogTypeEnum
;
import
com.tanpu.community.dao.entity.community.RankLogEntity
;
import
com.tanpu.community.dao.mapper.community.RankLogMapper
;
import
com.tanpu.community.util.BizUtils
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.time.LocalDateTime
;
import
java.util.List
;
@Service
public
class
RankLogService
{
@Resource
private
RankLogMapper
rankLogMapper
;
private
Integer
pageSize
=
50
;
//话题排序日志
public
void
logTopicRank
(
List
<
TopicRankQo
>
rankList
,
LocalDateTime
logTime
,
Long
cost
)
{
if
(
CollectionUtils
.
isEmpty
(
rankList
))
{
return
;
}
//分页插入
for
(
int
i
=
0
;
i
*
pageSize
<
rankList
.
size
();
i
++)
{
int
pageStart
=
i
*
pageSize
;
List
<
TopicRankQo
>
sublist
=
BizUtils
.
subList
(
rankList
,
pageStart
,
pageSize
);
RankLogEntity
entity
=
RankLogEntity
.
builder
().
rankTime
(
logTime
)
.
type
(
RankLogTypeEnum
.
TOPIC
.
getCode
())
.
totalCount
(
rankList
.
size
())
.
rankCost
(
cost
)
.
content
(
JsonUtil
.
toJson
(
sublist
))
.
pageNumber
(
i
+
1
)
.
pageSize
(
sublist
.
size
())
.
build
();
rankLogMapper
.
insert
(
entity
);
}
}
//主题排序日志
public
void
logThemeRank
(
List
<
ThemeAnalysDO
>
themeList
,
LocalDateTime
logTime
,
Long
cost
)
{
if
(
CollectionUtils
.
isEmpty
(
themeList
))
{
return
;
}
//分页插入
for
(
int
i
=
0
;
i
*
pageSize
<
themeList
.
size
();
i
++)
{
int
pageStart
=
i
*
pageSize
;
List
<
ThemeAnalysDO
>
sublist
=
BizUtils
.
subList
(
themeList
,
pageStart
,
pageSize
);
RankLogEntity
entity
=
RankLogEntity
.
builder
().
rankTime
(
logTime
)
.
type
(
RankLogTypeEnum
.
THEME
.
getCode
())
.
totalCount
(
themeList
.
size
())
.
rankCost
(
cost
)
.
content
(
JsonUtil
.
toJson
(
sublist
))
.
pageNumber
(
i
+
1
)
.
pageSize
(
sublist
.
size
())
.
build
();
rankLogMapper
.
insert
(
entity
);
}
}
}
community-service/src/main/java/com/tanpu/community/service/RankService.java
View file @
38c29f07
...
...
@@ -9,16 +9,20 @@ import com.tanpu.community.api.enums.VisitTypeEnum;
import
com.tanpu.community.cache.RedisCache
;
import
com.tanpu.community.dao.entity.community.ThemeEntity
;
import
com.tanpu.community.dao.entity.community.TopicEntity
;
import
com.tanpu.community.feign.fatools.FeignClientForFatools
;
import
com.tanpu.community.util.BizUtils
;
import
com.tanpu.community.util.ConvertUtil
;
import
com.tanpu.community.util.TimeUtils
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.util.*
;
import
java.time.LocalDateTime
;
import
java.util.ArrayList
;
import
java.util.Comparator
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
import
static
com
.
tanpu
.
community
.
api
.
constants
.
RedisKeyConstant
.
CACHE_FEIGN_USER_INFO
;
...
...
@@ -43,7 +47,7 @@ public class RankService {
private
RedisCache
redisCache
;
@Resource
private
FeignClientForFatools
feignClientForFatools
;
private
RankLogService
rankLogService
;
//最热
private
List
<
ThemeAnalysDO
>
hotestThemes
=
new
ArrayList
<>();
...
...
@@ -56,6 +60,8 @@ public class RankService {
* 计算主题热度排行
*/
public
void
rankThemes
()
{
LocalDateTime
start
=
LocalDateTime
.
now
();
//7天内所有主题进行热度值排序
List
<
ThemeEntity
>
themeEntities
=
themeService
.
queryRecentdays
(
7
);
if
(
CollectionUtils
.
isEmpty
(
themeEntities
))
{
...
...
@@ -95,6 +101,8 @@ public class RankService {
hotestThemes
=
map
.
entrySet
().
stream
()
.
sorted
(
Map
.
Entry
.
comparingByValue
(
Comparator
.
reverseOrder
()))
.
map
(
e
->
e
.
getKey
()).
collect
(
Collectors
.
toList
());
//落库
rankLogService
.
logThemeRank
(
hotestThemes
,
start
,
TimeUtils
.
calMillisTillNow
(
start
));
}
...
...
@@ -104,6 +112,7 @@ public class RankService {
* @return
*/
public
void
rankTopics
()
{
LocalDateTime
start
=
LocalDateTime
.
now
();
List
<
TopicEntity
>
topicEntities
=
topicService
.
queryAll
();
if
(
CollectionUtils
.
isEmpty
(
topicEntities
))
{
return
;
...
...
@@ -145,6 +154,9 @@ public class RankService {
rankList
.
get
(
0
).
setType
(
TopicStatusEnum
.
HOTTEST
.
getCode
());
this
.
rankTopicList
=
rankList
;
this
.
rankTopicListTop4
=
rankList
.
stream
().
limit
(
4
).
collect
(
Collectors
.
toList
());
//落库
rankLogService
.
logTopicRank
(
rankList
,
start
,
TimeUtils
.
calMillisTillNow
(
start
));
return
;
}
...
...
community-service/src/main/java/com/tanpu/community/service/ThemeService.java
View file @
38c29f07
...
...
@@ -218,7 +218,7 @@ public class ThemeService {
return
themeMapper
.
selectList
(
queryWrapper
);
}
//根据话题查询所有的主题Id
//根据话题查询所有的主题Id
,包括已删除的主题
public
List
<
String
>
queryThemeIdsByTopic
(
String
topidId
)
{
if
(
StringUtils
.
isEmpty
(
topidId
))
{
return
Collections
.
emptyList
();
...
...
community-service/src/main/java/com/tanpu/community/util/ConvertUtil.java
View file @
38c29f07
...
...
@@ -94,6 +94,7 @@ public class ConvertUtil {
if
(
TimeUtils
.
calMinuteTillNow
(
topicEntity
.
getCreateTime
())<
120
){
topicRankQo
.
setType
(
TopicStatusEnum
.
NEWEST
.
getCode
());
}
topicRankQo
.
setHoursTillNow
((
int
)
TimeUtils
.
calHoursTillNow
(
topicEntity
.
getCreateTime
()));
return
topicRankQo
;
}
...
...
community-service/src/main/java/com/tanpu/community/util/TimeUtils.java
View file @
38c29f07
...
...
@@ -37,12 +37,30 @@ public class TimeUtils {
return
start
.
format
(
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd HH:mm"
));
}
//计算迄今
时间
//计算迄今
分钟
public
static
long
calMinuteTillNow
(
LocalDateTime
start
)
{
Duration
between
=
Duration
.
between
(
start
,
LocalDateTime
.
now
());
return
between
.
toMinutes
();
}
//计算迄今毫秒数
public
static
long
calMillisTillNow
(
LocalDateTime
start
)
{
Duration
between
=
Duration
.
between
(
start
,
LocalDateTime
.
now
());
return
between
.
toMillis
();
}
//计算迄今天数
public
static
long
calDaysTillNow
(
LocalDateTime
start
)
{
Duration
between
=
Duration
.
between
(
start
,
LocalDateTime
.
now
());
return
between
.
toDays
();
}
//计算迄今天数
public
static
long
calHoursTillNow
(
LocalDateTime
start
)
{
Duration
between
=
Duration
.
between
(
start
,
LocalDateTime
.
now
());
return
between
.
toHours
();
}
//计算n天前的时间
public
static
LocalDateTime
getDaysBefore
(
Integer
number
)
{
...
...
community-service/src/main/resources/mapper/community/
Topic
RankLogEntityMapper.xml
→
community-service/src/main/resources/mapper/community/RankLogEntityMapper.xml
View file @
38c29f07
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"com.tanpu.community.dao.mapper.community.
Topic
RankLogMapper"
>
<mapper
namespace=
"com.tanpu.community.dao.mapper.community.RankLogMapper"
>
<!-- 通用查询映射结果 -->
<resultMap
id=
"BaseResultMap"
type=
"com.tanpu.community.dao.entity.community.
Topic
RankLogEntity"
>
<resultMap
id=
"BaseResultMap"
type=
"com.tanpu.community.dao.entity.community.RankLogEntity"
>
<id
column=
"id"
property=
"id"
/>
<result
column=
"type"
property=
"type"
/>
<result
column=
"total_count"
property=
"totalCount"
/>
<result
column=
"page_number"
property=
"pageNumber"
/>
<result
column=
"page_size"
property=
"pageSize"
/>
<result
column=
"info"
property=
"info"
/>
<result
column=
"content"
property=
"content"
/>
<result
column=
"rank_cost"
property=
"rankCost"
/>
<result
column=
"rank_time"
property=
"rankTime"
/>
<result
column=
"create_time"
property=
"createTime"
/>
<result
column=
"update_time"
property=
"updateTime"
/>
<result
column=
"delete_tag"
property=
"deleteTag"
/>
...
...
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