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
7d7f4d03
Commit
7d7f4d03
authored
3 years ago
by
刘基明
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
表名修改
parent
56e2b869
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
94 additions
and
278 deletions
+94
-278
VisitLogEntity.java
.../tanpu/community/dao/entity/community/VisitLogEntity.java
+6
-0
VisitSummaryEntity.java
...pu/community/dao/entity/community/VisitSummaryEntity.java
+0
-152
VisitLogMapper.java
.../tanpu/community/dao/mapper/community/VisitLogMapper.java
+22
-0
VisitSummaryMapper.java
...pu/community/dao/mapper/community/VisitSummaryMapper.java
+0
-39
ConJobManager.java
.../main/java/com/tanpu/community/manager/ConJobManager.java
+3
-3
ThemeManager.java
...c/main/java/com/tanpu/community/manager/ThemeManager.java
+5
-5
TopicManager.java
...c/main/java/com/tanpu/community/manager/TopicManager.java
+3
-5
VisitSummaryManager.java
...java/com/tanpu/community/manager/VisitSummaryManager.java
+5
-5
RankService.java
...rc/main/java/com/tanpu/community/service/RankService.java
+11
-11
RecommendService.java
...in/java/com/tanpu/community/service/RecommendService.java
+1
-1
VisitLogService.java
...ain/java/com/tanpu/community/service/VisitLogService.java
+36
-36
ConvertUtil.java
...e/src/main/java/com/tanpu/community/util/ConvertUtil.java
+2
-2
VisitSummaryEntityMapper.xml
...n/resources/mapper/community/VisitSummaryEntityMapper.xml
+0
-19
No files found.
community-service/src/main/java/com/tanpu/community/dao/entity/community/VisitLogEntity.java
View file @
7d7f4d03
...
...
@@ -5,6 +5,9 @@ import java.time.LocalDateTime;
import
java.io.Serializable
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
import
lombok.NoArgsConstructor
;
/**
* <p>
...
...
@@ -15,6 +18,9 @@ import io.swagger.annotations.ApiModelProperty;
* @since 2021-07-28
*/
@TableName
(
"visit_log"
)
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ApiModel
(
value
=
"VisitLogEntity对象"
,
description
=
"浏览记录"
)
public
class
VisitLogEntity
implements
Serializable
{
...
...
This diff is collapsed.
Click to expand it.
community-service/src/main/java/com/tanpu/community/dao/entity/community/VisitSummaryEntity.java
deleted
100644 → 0
View file @
56e2b869
package
com
.
tanpu
.
community
.
dao
.
entity
.
community
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
java.time.LocalDateTime
;
import
java.io.Serializable
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
import
lombok.NoArgsConstructor
;
/**
* <p>
* 浏览记录
* </p>
*
* @author xudong
* @since 2021-07-22
*/
@TableName
(
"visit_summary"
)
@ApiModel
(
value
=
"VisitSummaryEntity对象"
,
description
=
"浏览记录"
)
@Builder
@AllArgsConstructor
@NoArgsConstructor
public
class
VisitSummaryEntity
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
@ApiModelProperty
(
value
=
"id"
)
private
Long
id
;
@ApiModelProperty
(
value
=
"session_id"
)
private
String
ident
;
@ApiModelProperty
(
value
=
"浏览者id"
)
private
String
visitorId
;
@ApiModelProperty
(
value
=
"作者id"
)
private
String
authorId
;
@ApiModelProperty
(
value
=
"关联目标ID"
)
private
String
refId
;
@ApiModelProperty
(
value
=
"关联目标类型 1:进入话题页 2:进入主题正文 3、用户查看首页-关注"
)
private
Integer
refType
;
@ApiModelProperty
(
value
=
"浏览时间 单位秒"
)
private
Integer
duration
;
private
LocalDateTime
createTime
;
private
LocalDateTime
updateTime
;
private
Integer
deleteTag
;
public
Long
getId
()
{
return
id
;
}
public
void
setId
(
Long
id
)
{
this
.
id
=
id
;
}
public
String
getIdent
()
{
return
ident
;
}
public
void
setIdent
(
String
ident
)
{
this
.
ident
=
ident
;
}
public
String
getVisitorId
()
{
return
visitorId
;
}
public
void
setVisitorId
(
String
visitorId
)
{
this
.
visitorId
=
visitorId
;
}
public
String
getAuthorId
()
{
return
authorId
;
}
public
void
setAuthorId
(
String
authorId
)
{
this
.
authorId
=
authorId
;
}
public
String
getRefId
()
{
return
refId
;
}
public
void
setRefId
(
String
refId
)
{
this
.
refId
=
refId
;
}
public
Integer
getRefType
()
{
return
refType
;
}
public
void
setRefType
(
Integer
refType
)
{
this
.
refType
=
refType
;
}
public
Integer
getDuration
()
{
return
duration
;
}
public
void
setDuration
(
Integer
duration
)
{
this
.
duration
=
duration
;
}
public
LocalDateTime
getCreateTime
()
{
return
createTime
;
}
public
void
setCreateTime
(
LocalDateTime
createTime
)
{
this
.
createTime
=
createTime
;
}
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
"VisitSummaryEntity{"
+
"id="
+
id
+
", ident="
+
ident
+
", visitorId="
+
visitorId
+
", authorId="
+
authorId
+
", refId="
+
refId
+
", refType="
+
refType
+
", duration="
+
duration
+
", createTime="
+
createTime
+
", updateTime="
+
updateTime
+
", deleteTag="
+
deleteTag
+
"}"
;
}
}
This diff is collapsed.
Click to expand it.
community-service/src/main/java/com/tanpu/community/dao/mapper/community/VisitLogMapper.java
View file @
7d7f4d03
package
com
.
tanpu
.
community
.
dao
.
mapper
.
community
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.toolkit.Constants
;
import
com.tanpu.community.dao.entity.community.TimesCountEntity
;
import
com.tanpu.community.dao.entity.community.VisitLogEntity
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
org.apache.ibatis.annotations.Param
;
import
org.apache.ibatis.annotations.Select
;
import
org.apache.ibatis.annotations.Update
;
import
java.util.Date
;
import
java.util.List
;
/**
* <p>
...
...
@@ -12,5 +21,18 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
* @since 2021-07-28
*/
public
interface
VisitLogMapper
extends
BaseMapper
<
VisitLogEntity
>
{
@Select
(
"select * from visit_log where ident=#{ident}"
)
VisitLogEntity
selectByIdent
(
@Param
(
"ident"
)
String
ident
);
@Update
(
"update visit_log set duration=duration+#{duration} where ident=#{ident}"
)
void
updateDurByIdent
(
@Param
(
"duration"
)
Integer
dur
,
@Param
(
"ident"
)
String
ident
);
@Select
(
"select ref_id from visit_log where visitor_id=#{visitorId} and ref_id in (#{refIds})"
)
List
<
String
>
selectRefIdByUserId
(
@Param
(
"visitorId"
)
String
visitorId
,
@Param
(
"refIds"
)
String
refIds
);
@Select
(
"select ref_id as id, count(1) as times from visit_log ${ew.customSqlSegment}"
)
List
<
TimesCountEntity
>
selectCountByThemeIds
(
@Param
(
Constants
.
WRAPPER
)
LambdaQueryWrapper
wrapper
);
@Select
(
"select ref_id from visit_log where visitor_id=#{visitorId} and date(create_time) between #{startDate} and #{endDate}"
)
List
<
String
>
selectRefIdByUserIdAndCreateBetween
(
@Param
(
"visitorId"
)
String
visitorId
,
@Param
(
"startDate"
)
Date
startDate
,
@Param
(
"endDate"
)
Date
endDate
);
}
This diff is collapsed.
Click to expand it.
community-service/src/main/java/com/tanpu/community/dao/mapper/community/VisitSummaryMapper.java
deleted
100644 → 0
View file @
56e2b869
package
com
.
tanpu
.
community
.
dao
.
mapper
.
community
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.toolkit.Constants
;
import
com.tanpu.community.dao.entity.community.TimesCountEntity
;
import
com.tanpu.community.dao.entity.community.VisitSummaryEntity
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
org.apache.ibatis.annotations.Param
;
import
org.apache.ibatis.annotations.Select
;
import
org.apache.ibatis.annotations.Update
;
import
java.time.LocalDateTime
;
import
java.util.Date
;
import
java.util.List
;
/**
* <p>
* 浏览记录 Mapper 接口
* </p>
*
* @author xudong
* @since 2021-07-22
*/
public
interface
VisitSummaryMapper
extends
BaseMapper
<
VisitSummaryEntity
>
{
@Select
(
"select * from visit_summary where ident=#{ident}"
)
VisitSummaryEntity
selectByIdent
(
@Param
(
"ident"
)
String
ident
);
@Update
(
"update visit_summary set duration=duration+#{duration} where ident=#{ident}"
)
void
updateDurByIdent
(
@Param
(
"duration"
)
Integer
dur
,
@Param
(
"ident"
)
String
ident
);
@Select
(
"select ref_id from visit_summary where visitor_id=#{visitorId} and ref_id in (#{refIds})"
)
List
<
String
>
selectRefIdByUserId
(
@Param
(
"visitorId"
)
String
visitorId
,
@Param
(
"refIds"
)
String
refIds
);
@Select
(
"select ref_id as id, count(1) as times from visit_summary ${ew.customSqlSegment}"
)
List
<
TimesCountEntity
>
selectCountByThemeIds
(
@Param
(
Constants
.
WRAPPER
)
LambdaQueryWrapper
wrapper
);
@Select
(
"select ref_id from visit_summary where visitor_id=#{visitorId} and date(create_time) between #{startDate} and #{endDate}"
)
List
<
String
>
selectRefIdByUserIdAndCreateBetween
(
@Param
(
"visitorId"
)
String
visitorId
,
@Param
(
"startDate"
)
Date
startDate
,
@Param
(
"endDate"
)
Date
endDate
);
}
This diff is collapsed.
Click to expand it.
community-service/src/main/java/com/tanpu/community/manager/ConJobManager.java
View file @
7d7f4d03
...
...
@@ -2,7 +2,7 @@ package com.tanpu.community.manager;
import
com.tanpu.community.service.RankService
;
import
com.tanpu.community.service.RedisService
;
import
com.tanpu.community.service.Visit
Summary
Service
;
import
com.tanpu.community.service.Visit
Log
Service
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Configuration
;
...
...
@@ -15,7 +15,7 @@ import org.springframework.stereotype.Service;
public
class
ConJobManager
{
@Autowired
private
Visit
SummaryService
visitSummary
Service
;
private
Visit
LogService
visitLog
Service
;
@Autowired
private
RedisService
redisService
;
...
...
@@ -29,7 +29,7 @@ public class ConJobManager {
@Scheduled
(
cron
=
"*/10 * * * * ?"
)
public
void
topicVisitorStats
()
{
String
topicId
=
"123"
;
Integer
detailVisitTimes
=
visit
Summary
Service
.
queryTopicDetailVisit
(
topicId
);
Integer
detailVisitTimes
=
visit
Log
Service
.
queryTopicDetailVisit
(
topicId
);
redisService
.
set
(
"topicVisitorStats"
,
detailVisitTimes
);
}
...
...
This diff is collapsed.
Click to expand it.
community-service/src/main/java/com/tanpu/community/manager/ThemeManager.java
View file @
7d7f4d03
...
...
@@ -69,7 +69,7 @@ public class ThemeManager {
private
BatchFeignCallService
batchFeignCallService
;
@Autowired
private
Visit
SummaryService
visitSummary
Service
;
private
Visit
LogService
visitLog
Service
;
@Autowired
private
ReportLogService
reportLogService
;
...
...
@@ -201,7 +201,7 @@ public class ThemeManager {
if
(
ThemeListTypeEnum
.
RECOMMEND
.
getCode
().
equals
(
req
.
getType
()))
{
//推荐
// 需要筛掉用户访问过详情的 & 最近出现在列表页过的.
List
<
String
>
visitedIds
=
visit
Summary
Service
.
queryUserRecentVisited
(
userId
);
List
<
String
>
visitedIds
=
visit
Log
Service
.
queryUserRecentVisited
(
userId
);
List
<
String
>
excludes
=
ListUtils
.
union
(
req
.
excludeIds
,
visitedIds
);
List
<
String
>
recmdIds
=
recommendService
.
getRecommendThemes
(
pageStart
,
querySize
,
userId
,
excludes
);
...
...
@@ -212,7 +212,7 @@ public class ThemeManager {
}
else
if
(
ThemeListTypeEnum
.
FOLLOW
.
getCode
().
equals
(
req
.
getType
()))
{
// TODO 临时埋点,接入新埋点后删除
if
(
CollectionUtils
.
isEmpty
(
req
.
getExcludeIds
()))
{
visit
Summary
Service
.
addPageView
(
userId
,
userId
,
VisitTypeEnum
.
FOLLOW_THEME_VIEW
);
visit
Log
Service
.
addPageView
(
userId
,
userId
,
VisitTypeEnum
.
FOLLOW_THEME_VIEW
);
}
// 根据关注列表查询,按时间倒序
List
<
String
>
fansList
=
followRelService
.
queryFansByFollowerId
(
userId
);
...
...
@@ -327,7 +327,7 @@ public class ThemeManager {
// 查询正文
public
ThemeQo
getThemeDetail
(
String
themeId
,
String
userId
)
{
//TODO 临时埋点,接入新埋点后删除
visit
Summary
Service
.
addPageView
(
userId
,
themeId
,
VisitTypeEnum
.
THEME_PAGE_VIEW
);
visit
Log
Service
.
addPageView
(
userId
,
themeId
,
VisitTypeEnum
.
THEME_PAGE_VIEW
);
// 查询详情
ThemeQo
themeQo
=
redisCache
.
getObject
(
StringUtils
.
joinWith
(
"_"
,
CACHE_THEME_ID
,
themeId
),
60
,
()
->
this
.
getDetailCommon
(
themeId
),
ThemeQo
.
class
);
...
...
@@ -384,7 +384,7 @@ public class ThemeManager {
//关注用户是否有更新
public
Integer
getFollowUpdateCount
(
String
userId
)
{
LocalDateTime
lastViewTime
=
visit
Summary
Service
.
queryLatestViewFollow
(
userId
);
LocalDateTime
lastViewTime
=
visit
Log
Service
.
queryLatestViewFollow
(
userId
);
List
<
String
>
fansList
=
followRelService
.
queryFansByFollowerId
(
userId
);
return
themeService
.
queryCountFromLastTime
(
fansList
,
lastViewTime
);
}
...
...
This diff is collapsed.
Click to expand it.
community-service/src/main/java/com/tanpu/community/manager/TopicManager.java
View file @
7d7f4d03
...
...
@@ -7,7 +7,7 @@ import com.tanpu.community.api.beans.req.topic.TopicSearchReq;
import
com.tanpu.community.api.enums.VisitTypeEnum
;
import
com.tanpu.community.service.RankService
;
import
com.tanpu.community.service.TopicService
;
import
com.tanpu.community.service.Visit
Summary
Service
;
import
com.tanpu.community.service.Visit
Log
Service
;
import
com.tanpu.community.util.PageUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
...
...
@@ -18,11 +18,9 @@ import java.util.List;
@Service
public
class
TopicManager
{
@Autowired
private
TopicService
topicService
;
@Autowired
private
Visit
SummaryService
visitSummary
Service
;
private
Visit
LogService
visitLog
Service
;
@Autowired
private
RankService
rankService
;
...
...
@@ -46,7 +44,7 @@ public class TopicManager {
// 话题详情页
public
TopicRankQo
getDetail
(
String
topicId
)
{
//TODO 临时埋点,接入新埋点后删除
visit
Summary
Service
.
addPageView
(
userHolder
.
getUserId
(),
topicId
,
VisitTypeEnum
.
TOPIC_PAGE_VIEW
);
visit
Log
Service
.
addPageView
(
userHolder
.
getUserId
(),
topicId
,
VisitTypeEnum
.
TOPIC_PAGE_VIEW
);
return
rankService
.
getTopicDetail
(
topicId
);
}
...
...
This diff is collapsed.
Click to expand it.
community-service/src/main/java/com/tanpu/community/manager/VisitSummaryManager.java
View file @
7d7f4d03
...
...
@@ -2,8 +2,8 @@ package com.tanpu.community.manager;
import
com.alibaba.fastjson.JSON
;
import
com.tanpu.community.api.beans.vo.KafkaDurationUptMsg
;
import
com.tanpu.community.dao.entity.community.Visit
Summary
Entity
;
import
com.tanpu.community.service.Visit
Summary
Service
;
import
com.tanpu.community.dao.entity.community.Visit
Log
Entity
;
import
com.tanpu.community.service.Visit
Log
Service
;
import
com.tanpu.community.util.ConvertUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -21,7 +21,7 @@ public class VisitSummaryManager {
private
KafkaTemplate
<
String
,
String
>
kafkaTemplate
;
@Autowired
private
Visit
SummaryService
visitSummary
Service
;
private
Visit
LogService
visitLog
Service
;
@KafkaListener
(
topics
=
kafakTopic
)
...
...
@@ -29,7 +29,7 @@ public class VisitSummaryManager {
log
.
info
(
"receive kafka msg: {}"
,
message
);
KafkaDurationUptMsg
msg
=
JSON
.
parseObject
(
message
,
KafkaDurationUptMsg
.
class
);
// ident在每次进入新页面 & 回退 的时候都会随机生成一个,所以用ident做唯一key即可。
Visit
Summary
Entity
vs
=
ConvertUtil
.
convertFromKafka
(
msg
);
visit
Summary
Service
.
insertOrUpdateDur
(
vs
);
Visit
Log
Entity
vs
=
ConvertUtil
.
convertFromKafka
(
msg
);
visit
Log
Service
.
insertOrUpdateDur
(
vs
);
}
}
This diff is collapsed.
Click to expand it.
community-service/src/main/java/com/tanpu/community/service/RankService.java
View file @
7d7f4d03
...
...
@@ -33,7 +33,7 @@ public class RankService {
@Autowired
private
TopicService
topicService
;
@Autowired
private
Visit
SummaryService
visitSummary
Service
;
private
Visit
LogService
visitLog
Service
;
@Autowired
private
FeignService
feignService
;
...
...
@@ -57,7 +57,7 @@ public class RankService {
public
void
rankThemes
()
{
//7天内所有主题进行热度值排序
List
<
ThemeEntity
>
themeEntities
=
themeService
.
queryRecentdays
(
7
);
if
(
CollectionUtils
.
isEmpty
(
themeEntities
)){
if
(
CollectionUtils
.
isEmpty
(
themeEntities
))
{
return
;
}
List
<
ThemeAnalysDO
>
themeAnalysDOS
=
ConvertUtil
.
themeEntityToAnalysDOs
(
themeEntities
);
...
...
@@ -67,15 +67,15 @@ public class RankService {
Map
<
String
,
Integer
>
bookCountMap
=
collectionService
.
getCountMapByType
(
themeIds
,
CollectionTypeEnum
.
COLLECT_THEME
);
Map
<
String
,
Integer
>
commentCountMap
=
commentService
.
getCountMapByThemeIds
(
themeIds
);
Map
<
String
,
Integer
>
forwardCountMap
=
themeService
.
getForwardCountMap
(
themeIds
);
Map
<
String
,
Integer
>
visitCountMap
=
visit
Summary
Service
.
getCountMapByTargetIds
(
themeIds
,
VisitTypeEnum
.
THEME_PAGE_VIEW
);
Map
<
String
,
Integer
>
visitCountMap
=
visit
Log
Service
.
getCountMapByTargetIds
(
themeIds
,
VisitTypeEnum
.
THEME_PAGE_VIEW
);
for
(
ThemeAnalysDO
theme
:
themeAnalysDOS
)
{
String
themeId
=
theme
.
getThemeId
();
theme
.
setCommentCount
(
commentCountMap
.
getOrDefault
(
themeId
,
0
));
theme
.
setCommentCount
(
commentCountMap
.
getOrDefault
(
themeId
,
0
));
theme
.
setLikeCount
(
likeCountMap
.
getOrDefault
(
themeId
,
0
));
theme
.
setForwardCount
(
forwardCountMap
.
getOrDefault
(
themeId
,
0
));
theme
.
setCollectCount
(
bookCountMap
.
getOrDefault
(
themeId
,
0
));
theme
.
setViewCount
(
visitCountMap
.
getOrDefault
(
themeId
,
0
));
theme
.
setForwardCount
(
forwardCountMap
.
getOrDefault
(
themeId
,
0
));
theme
.
setCollectCount
(
bookCountMap
.
getOrDefault
(
themeId
,
0
));
theme
.
setViewCount
(
visitCountMap
.
getOrDefault
(
themeId
,
0
));
//查询用户质量
String
authorId
=
theme
.
getAuthorId
();
UserInfoNew
authorInfo
=
redisCache
.
getObject
(
StringUtils
.
joinWith
(
"_"
,
CACHE_FEIGN_USER_INFO
,
authorId
),
...
...
@@ -109,17 +109,17 @@ public class RankService {
}
List
<
TopicRankQo
>
topicRankQos
=
ConvertUtil
.
topicEntityToHotQos
(
topicEntities
);
List
<
String
>
topicIds
=
topicRankQos
.
stream
().
map
(
TopicRankQo:
:
getTopicId
).
collect
(
Collectors
.
toList
());
Map
<
String
,
Integer
>
countMapByTargetIds
=
visit
Summary
Service
.
getCountMapByTargetIds
(
topicIds
,
VisitTypeEnum
.
TOPIC_PAGE_VIEW
);
Map
<
String
,
Integer
>
countMapByTargetIds
=
visit
Log
Service
.
getCountMapByTargetIds
(
topicIds
,
VisitTypeEnum
.
TOPIC_PAGE_VIEW
);
for
(
TopicRankQo
topic
:
topicRankQos
)
{
List
<
String
>
themeIds
=
themeService
.
queryThemeIdsByTopic
(
topic
.
getTopicId
());
if
(
CollectionUtils
.
isEmpty
(
themeIds
))
{
topic
.
setViewCount
(
countMapByTargetIds
.
getOrDefault
(
topic
.
getTopicId
(),
0
));
topic
.
setViewCount
(
countMapByTargetIds
.
getOrDefault
(
topic
.
getTopicId
(),
0
));
topic
.
setDisscussCount
(
0
);
continue
;
}
// 浏览量
Integer
topicPV
=
countMapByTargetIds
.
getOrDefault
(
topic
.
getTopicId
(),
0
);
Integer
themePV
=
visit
Summary
Service
.
queryThemeVisit
(
themeIds
);
Integer
topicPV
=
countMapByTargetIds
.
getOrDefault
(
topic
.
getTopicId
(),
0
);
Integer
themePV
=
visit
Log
Service
.
queryThemeVisit
(
themeIds
);
topic
.
setViewCount
(
topicPV
+
themePV
);
//讨论数=发布主题贴数+回复总数
Integer
commentCount
=
commentService
.
getTotalCountByThemeIds
(
themeIds
);
...
...
This diff is collapsed.
Click to expand it.
community-service/src/main/java/com/tanpu/community/service/RecommendService.java
View file @
7d7f4d03
...
...
@@ -42,7 +42,7 @@ public class RecommendService {
private
ThemeService
themeService
;
@Autowired
private
Visit
SummaryService
visitSummary
Service
;
private
Visit
LogService
visitLog
Service
;
// 最新
private
List
<
ThemeAnalysDO
>
recentThemeList
=
new
ArrayList
<>();
...
...
This diff is collapsed.
Click to expand it.
community-service/src/main/java/com/tanpu/community/service/Visit
Summary
Service.java
→
community-service/src/main/java/com/tanpu/community/service/Visit
Log
Service.java
View file @
7d7f4d03
...
...
@@ -4,8 +4,8 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import
com.tanpu.community.api.enums.DeleteTagEnum
;
import
com.tanpu.community.api.enums.VisitTypeEnum
;
import
com.tanpu.community.dao.entity.community.TimesCountEntity
;
import
com.tanpu.community.dao.entity.community.Visit
Summary
Entity
;
import
com.tanpu.community.dao.mapper.community.Visit
Summary
Mapper
;
import
com.tanpu.community.dao.entity.community.Visit
Log
Entity
;
import
com.tanpu.community.dao.mapper.community.Visit
Log
Mapper
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.collections4.ListUtils
;
...
...
@@ -23,16 +23,16 @@ import java.util.stream.Collectors;
@Slf4j
@Service
public
class
Visit
Summary
Service
{
public
class
Visit
Log
Service
{
@Resource
private
Visit
SummaryMapper
visitSummary
Mapper
;
private
Visit
LogMapper
visitLog
Mapper
;
// 获取用户7天内访问过的
public
List
<
String
>
queryUserRecentVisited
(
String
userId
)
{
Date
endDate
=
new
Date
();
Date
startDate
=
DateUtils
.
addDays
(
endDate
,
-
7
);
List
<
String
>
visited
=
visit
Summary
Mapper
.
selectRefIdByUserIdAndCreateBetween
(
userId
,
startDate
,
endDate
);
List
<
String
>
visited
=
visit
Log
Mapper
.
selectRefIdByUserIdAndCreateBetween
(
userId
,
startDate
,
endDate
);
return
visited
;
}
...
...
@@ -41,33 +41,33 @@ public class VisitSummaryService {
if
(
refIds
.
isEmpty
())
{
return
refIds
;
}
List
<
String
>
visited
=
visit
SummaryMapper
.
selectList
(
new
LambdaQueryWrapper
<
VisitSummary
Entity
>()
.
eq
(
Visit
Summary
Entity:
:
getVisitorId
,
userId
)
.
in
(
Visit
Summary
Entity:
:
getRefId
,
refIds
))
.
stream
().
map
(
Visit
Summary
Entity:
:
getRefId
).
distinct
().
collect
(
Collectors
.
toList
());
List
<
String
>
visited
=
visit
LogMapper
.
selectList
(
new
LambdaQueryWrapper
<
VisitLog
Entity
>()
.
eq
(
Visit
Log
Entity:
:
getVisitorId
,
userId
)
.
in
(
Visit
Log
Entity:
:
getRefId
,
refIds
))
.
stream
().
map
(
Visit
Log
Entity:
:
getRefId
).
distinct
().
collect
(
Collectors
.
toList
());
return
ListUtils
.
subtract
(
refIds
,
visited
);
}
public
List
<
String
>
queryUserVisited
(
String
userId
)
{
List
<
String
>
visited
=
visit
SummaryMapper
.
selectList
(
new
LambdaQueryWrapper
<
VisitSummary
Entity
>()
.
eq
(
Visit
Summary
Entity:
:
getVisitorId
,
userId
))
.
stream
().
map
(
Visit
Summary
Entity:
:
getRefId
).
distinct
().
collect
(
Collectors
.
toList
());
List
<
String
>
visited
=
visit
LogMapper
.
selectList
(
new
LambdaQueryWrapper
<
VisitLog
Entity
>()
.
eq
(
Visit
Log
Entity:
:
getVisitorId
,
userId
))
.
stream
().
map
(
Visit
Log
Entity:
:
getRefId
).
distinct
().
collect
(
Collectors
.
toList
());
return
visited
;
}
@Transactional
public
void
insertOrUpdateDur
(
Visit
Summary
Entity
vs
)
{
if
(
visit
Summary
Mapper
.
selectByIdent
(
vs
.
getIdent
())
==
null
)
{
visit
Summary
Mapper
.
insert
(
vs
);
public
void
insertOrUpdateDur
(
Visit
Log
Entity
vs
)
{
if
(
visit
Log
Mapper
.
selectByIdent
(
vs
.
getIdent
())
==
null
)
{
visit
Log
Mapper
.
insert
(
vs
);
}
else
{
visit
Summary
Mapper
.
updateDurByIdent
(
vs
.
getDuration
(),
vs
.
getIdent
());
visit
Log
Mapper
.
updateDurByIdent
(
vs
.
getDuration
(),
vs
.
getIdent
());
}
}
@Transactional
//TODO 临时埋点,接入新埋点后删除
public
void
addPageView
(
String
userId
,
String
targetId
,
VisitTypeEnum
type
)
{
visit
SummaryMapper
.
insert
(
VisitSummary
Entity
.
builder
()
visit
LogMapper
.
insert
(
VisitLog
Entity
.
builder
()
.
visitorId
(
userId
)
.
refId
(
targetId
)
.
refType
(
type
.
getCode
())
...
...
@@ -77,16 +77,16 @@ public class VisitSummaryService {
// 查询话题 详细页面 浏览量
public
Integer
queryTopicDetailVisit
(
String
topicId
)
{
return
visit
SummaryMapper
.
selectCount
(
new
LambdaQueryWrapper
<
VisitSummary
Entity
>()
.
eq
(
Visit
Summary
Entity:
:
getRefId
,
topicId
)
.
eq
(
Visit
Summary
Entity:
:
getRefType
,
VisitTypeEnum
.
TOPIC_PAGE_VIEW
.
getCode
()));
return
visit
LogMapper
.
selectCount
(
new
LambdaQueryWrapper
<
VisitLog
Entity
>()
.
eq
(
Visit
Log
Entity:
:
getRefId
,
topicId
)
.
eq
(
Visit
Log
Entity:
:
getRefType
,
VisitTypeEnum
.
TOPIC_PAGE_VIEW
.
getCode
()));
}
// 查询主题 浏览量
public
Integer
queryThemeVisit
(
String
theme
)
{
return
visit
SummaryMapper
.
selectCount
(
new
LambdaQueryWrapper
<
VisitSummary
Entity
>()
.
eq
(
Visit
Summary
Entity:
:
getRefId
,
theme
)
.
eq
(
Visit
Summary
Entity:
:
getRefType
,
VisitTypeEnum
.
THEME_PAGE_VIEW
.
getCode
()));
return
visit
LogMapper
.
selectCount
(
new
LambdaQueryWrapper
<
VisitLog
Entity
>()
.
eq
(
Visit
Log
Entity:
:
getRefId
,
theme
)
.
eq
(
Visit
Log
Entity:
:
getRefType
,
VisitTypeEnum
.
THEME_PAGE_VIEW
.
getCode
()));
}
// 查询主题 浏览量
...
...
@@ -94,16 +94,16 @@ public class VisitSummaryService {
if
(
CollectionUtils
.
isEmpty
(
themes
)){
return
0
;
}
return
visit
SummaryMapper
.
selectCount
(
new
LambdaQueryWrapper
<
VisitSummary
Entity
>()
.
in
(
Visit
Summary
Entity:
:
getRefId
,
themes
)
.
eq
(
Visit
Summary
Entity:
:
getRefType
,
VisitTypeEnum
.
THEME_PAGE_VIEW
.
getCode
()));
return
visit
LogMapper
.
selectCount
(
new
LambdaQueryWrapper
<
VisitLog
Entity
>()
.
in
(
Visit
Log
Entity:
:
getRefId
,
themes
)
.
eq
(
Visit
Log
Entity:
:
getRefType
,
VisitTypeEnum
.
THEME_PAGE_VIEW
.
getCode
()));
}
public
LocalDateTime
queryLatestViewFollow
(
String
userId
)
{
List
<
Visit
SummaryEntity
>
visitSummaryEntities
=
visitSummaryMapper
.
selectList
(
new
LambdaQueryWrapper
<
VisitSummary
Entity
>()
.
eq
(
Visit
Summary
Entity:
:
getVisitorId
,
userId
)
.
eq
(
Visit
Summary
Entity:
:
getRefType
,
VisitTypeEnum
.
FOLLOW_THEME_VIEW
.
getCode
())
.
orderByDesc
(
Visit
Summary
Entity:
:
getCreateTime
));
List
<
Visit
LogEntity
>
visitSummaryEntities
=
visitLogMapper
.
selectList
(
new
LambdaQueryWrapper
<
VisitLog
Entity
>()
.
eq
(
Visit
Log
Entity:
:
getVisitorId
,
userId
)
.
eq
(
Visit
Log
Entity:
:
getRefType
,
VisitTypeEnum
.
FOLLOW_THEME_VIEW
.
getCode
())
.
orderByDesc
(
Visit
Log
Entity:
:
getCreateTime
));
if
(
CollectionUtils
.
isEmpty
(
visitSummaryEntities
))
{
return
null
;
}
else
{
...
...
@@ -116,12 +116,12 @@ public class VisitSummaryService {
if
(
CollectionUtils
.
isEmpty
(
refIds
)){
return
new
HashMap
<>();
}
LambdaQueryWrapper
<
Visit
SummaryEntity
>
wrapper
=
(
new
LambdaQueryWrapper
<
VisitSummary
Entity
>()
.
in
(
Visit
Summary
Entity:
:
getRefId
,
refIds
))
.
eq
(
Visit
Summary
Entity:
:
getDeleteTag
,
DeleteTagEnum
.
NOT_DELETED
)
.
eq
(
Visit
Summary
Entity:
:
getRefType
,
type
.
getCode
())
.
groupBy
(
Visit
Summary
Entity:
:
getRefId
);
return
visit
Summary
Mapper
.
selectCountByThemeIds
(
wrapper
).
stream
()
LambdaQueryWrapper
<
Visit
LogEntity
>
wrapper
=
(
new
LambdaQueryWrapper
<
VisitLog
Entity
>()
.
in
(
Visit
Log
Entity:
:
getRefId
,
refIds
))
.
eq
(
Visit
Log
Entity:
:
getDeleteTag
,
DeleteTagEnum
.
NOT_DELETED
)
.
eq
(
Visit
Log
Entity:
:
getRefType
,
type
.
getCode
())
.
groupBy
(
Visit
Log
Entity:
:
getRefId
);
return
visit
Log
Mapper
.
selectCountByThemeIds
(
wrapper
).
stream
()
.
collect
(
Collectors
.
toMap
(
TimesCountEntity:
:
getId
,
TimesCountEntity:
:
getTimes
));
}
}
This diff is collapsed.
Click to expand it.
community-service/src/main/java/com/tanpu/community/util/ConvertUtil.java
View file @
7d7f4d03
...
...
@@ -120,8 +120,8 @@ public class ConvertUtil {
/**
* VISIT_SUMMARY
*/
public
static
Visit
Summary
Entity
convertFromKafka
(
KafkaDurationUptMsg
msg
)
{
Visit
SummaryEntity
vs
=
new
VisitSummary
Entity
();
public
static
Visit
Log
Entity
convertFromKafka
(
KafkaDurationUptMsg
msg
)
{
Visit
LogEntity
vs
=
new
VisitLog
Entity
();
vs
.
setAuthorId
(
msg
.
pidUserId
);
vs
.
setDeleteTag
(
DeleteTagEnum
.
NOT_DELETED
.
ordinal
());
vs
.
setDuration
(
1
);
...
...
This diff is collapsed.
Click to expand it.
community-service/src/main/resources/mapper/community/VisitSummaryEntityMapper.xml
deleted
100644 → 0
View file @
56e2b869
<?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.VisitSummaryMapper"
>
<!-- 通用查询映射结果 -->
<resultMap
id=
"BaseResultMap"
type=
"com.tanpu.community.dao.entity.community.VisitSummaryEntity"
>
<id
column=
"id"
property=
"id"
/>
<result
column=
"ident"
property=
"ident"
/>
<result
column=
"visitor_id"
property=
"visitorId"
/>
<result
column=
"author_id"
property=
"authorId"
/>
<result
column=
"ref_id"
property=
"refId"
/>
<result
column=
"ref_type"
property=
"refType"
/>
<result
column=
"duration"
property=
"duration"
/>
<result
column=
"create_time"
property=
"createTime"
/>
<result
column=
"update_time"
property=
"updateTime"
/>
<result
column=
"delete_tag"
property=
"deleteTag"
/>
</resultMap>
</mapper>
This diff is collapsed.
Click to expand it.
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