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
e38879ab
Commit
e38879ab
authored
Aug 02, 2021
by
张辰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加埋点支持
parent
e888ddc0
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
58 additions
and
47 deletions
+58
-47
RedisKeyConstant.java
...a/com/tanpu/community/api/constants/RedisKeyConstant.java
+3
-0
VisitTypeEnum.java
...ain/java/com/tanpu/community/api/enums/VisitTypeEnum.java
+2
-2
ThemeMapper.java
...com/tanpu/community/dao/mapper/community/ThemeMapper.java
+1
-2
ThemeManager.java
...c/main/java/com/tanpu/community/manager/ThemeManager.java
+10
-6
VisitSummaryManager.java
...java/com/tanpu/community/manager/VisitSummaryManager.java
+1
-5
ThemeService.java
...c/main/java/com/tanpu/community/service/ThemeService.java
+2
-4
VisitLogService.java
...ain/java/com/tanpu/community/service/VisitLogService.java
+11
-11
ESHelper.java
.../main/java/com/tanpu/community/service/base/ESHelper.java
+27
-16
ConvertUtil.java
...e/src/main/java/com/tanpu/community/util/ConvertUtil.java
+1
-1
No files found.
community-api/src/main/java/com/tanpu/community/api/constants/RedisKeyConstant.java
View file @
e38879ab
...
@@ -40,6 +40,9 @@ public class RedisKeyConstant {
...
@@ -40,6 +40,9 @@ public class RedisKeyConstant {
// 转发主题本身
// 转发主题本身
public
static
final
String
CACHE_FORMER_THEME_ID
=
"CACHE_FORMER_THEME_ID_"
;
public
static
final
String
CACHE_FORMER_THEME_ID
=
"CACHE_FORMER_THEME_ID_"
;
// 关注的人,上次浏览的最新主题last id
public
static
final
String
CACHE_IDOL_THEME_LAST_ID
=
"CACHE_IDOL_THEME_LAST_ID_"
;
public
static
final
String
THEME_VIEW_COUNT_
=
"THEME_VIEW_COUNT_"
;
public
static
final
String
THEME_VIEW_COUNT_
=
"THEME_VIEW_COUNT_"
;
public
static
final
String
THEME_LIKE_COUNT_
=
"THEME_LIKE_COUNT_"
;
public
static
final
String
THEME_LIKE_COUNT_
=
"THEME_LIKE_COUNT_"
;
public
static
final
String
THEME_BOOK_COUNT_
=
"THEME_BOOK_COUNT_"
;
public
static
final
String
THEME_BOOK_COUNT_
=
"THEME_BOOK_COUNT_"
;
...
...
community-api/src/main/java/com/tanpu/community/api/enums/VisitTypeEnum.java
View file @
e38879ab
package
com
.
tanpu
.
community
.
api
.
enums
;
package
com
.
tanpu
.
community
.
api
.
enums
;
public
enum
VisitTypeEnum
{
public
enum
VisitTypeEnum
{
TOPIC_PAGE_VIEW
(
"1"
,
"进入话题页"
)
,
TOPIC_PAGE_VIEW
(
"1"
,
"进入话题页"
)
;
// THEME_PAGE_VIEW(2,"进入主题正文"),
// THEME_PAGE_VIEW(2,"进入主题正文"),
FOLLOW_THEME_VIEW
(
"3"
,
"查看关注主题"
);
//
FOLLOW_THEME_VIEW("3","查看关注主题");
private
String
code
;
private
String
code
;
private
String
type
;
private
String
type
;
...
...
community-service/src/main/java/com/tanpu/community/dao/mapper/community/ThemeMapper.java
View file @
e38879ab
...
@@ -20,7 +20,6 @@ import java.util.List;
...
@@ -20,7 +20,6 @@ import java.util.List;
*/
*/
public
interface
ThemeMapper
extends
BaseMapper
<
ThemeEntity
>
{
public
interface
ThemeMapper
extends
BaseMapper
<
ThemeEntity
>
{
@Select
(
"select former_theme_id as id,
count(1) as times from theme ${ew.customSqlSegment}"
)
@Select
(
"select former_theme_id as id, count(1) as times from theme ${ew.customSqlSegment}"
)
List
<
TimesCountEntity
>
selectCountByThemeIds
(
@Param
(
Constants
.
WRAPPER
)
LambdaQueryWrapper
wrapper
);
List
<
TimesCountEntity
>
selectCountByThemeIds
(
@Param
(
Constants
.
WRAPPER
)
LambdaQueryWrapper
wrapper
);
}
}
community-service/src/main/java/com/tanpu/community/manager/ThemeManager.java
View file @
e38879ab
...
@@ -260,14 +260,17 @@ public class ThemeManager {
...
@@ -260,14 +260,17 @@ public class ThemeManager {
}
else
if
(
ThemeListTypeEnum
.
FOLLOW
.
getCode
().
equals
(
req
.
getType
()))
{
}
else
if
(
ThemeListTypeEnum
.
FOLLOW
.
getCode
().
equals
(
req
.
getType
()))
{
// TODO 临时埋点,接入新埋点后删除
if
(
CollectionUtils
.
isEmpty
(
excludeIds
))
{
visitLogService
.
addPageView
(
userId
,
userId
,
VisitTypeEnum
.
FOLLOW_THEME_VIEW
);
}
// 根据关注列表查询,按时间倒序
// 根据关注列表查询,按时间倒序
List
<
String
>
fansList
=
followRelService
.
queryIdolsByFollowerId
(
userId
);
List
<
String
>
fansList
=
followRelService
.
queryIdolsByFollowerId
(
userId
);
themes
=
themeService
.
queryByUserIdsCreateDesc
(
fansList
,
pageStart
,
pageSize
);
themes
=
themeService
.
queryByUserIdsCreateDesc
(
fansList
,
pageStart
,
pageSize
);
if
(
CollectionUtils
.
isEmpty
(
excludeIds
)
&&
!
themes
.
isEmpty
())
{
// 说明是从头开始刷,则直接把最新的lastId放到redis中,保留一个月
Long
lastId
=
themes
.
stream
().
map
(
ThemeEntity:
:
getId
).
max
(
Long:
:
compareTo
).
get
();
redisCache
.
put
(
CACHE_IDOL_THEME_LAST_ID
+
userId
,
lastId
,
60
*
60
*
24
*
7
*
4
);
// visitLogService.addPageView(userId, userId, VisitTypeEnum.FOLLOW_THEME_VIEW);
}
}
else
if
(
ThemeListTypeEnum
.
TOPIC_HOT
.
getCode
().
equals
(
req
.
getType
()))
{
}
else
if
(
ThemeListTypeEnum
.
TOPIC_HOT
.
getCode
().
equals
(
req
.
getType
()))
{
// 根据话题查询热门
// 根据话题查询热门
if
(
StringUtils
.
isEmpty
(
req
.
getTopicId
()))
{
if
(
StringUtils
.
isEmpty
(
req
.
getTopicId
()))
{
...
@@ -451,9 +454,10 @@ public class ThemeManager {
...
@@ -451,9 +454,10 @@ public class ThemeManager {
//关注用户是否有更新
//关注用户是否有更新
public
Integer
getFollowUpdateCount
(
String
userId
)
{
public
Integer
getFollowUpdateCount
(
String
userId
)
{
LocalDateTime
lastViewTime
=
visitLogService
.
queryLatestViewFollow
(
userId
);
String
lastIdStr
=
redisCache
.
get
(
CACHE_IDOL_THEME_LAST_ID
+
userId
);
Long
lastId
=
StringUtils
.
isBlank
(
lastIdStr
)
?
0L
:
Long
.
parseLong
(
lastIdStr
);
List
<
String
>
fansList
=
followRelService
.
queryIdolsByFollowerId
(
userId
);
List
<
String
>
fansList
=
followRelService
.
queryIdolsByFollowerId
(
userId
);
return
themeService
.
queryCountFromLast
Time
(
fansList
,
lastViewTime
);
return
themeService
.
queryCountFromLast
Id
(
fansList
,
lastId
);
}
}
// 屏蔽(用户)
// 屏蔽(用户)
...
...
community-service/src/main/java/com/tanpu/community/manager/VisitSummaryManager.java
View file @
e38879ab
...
@@ -28,16 +28,12 @@ public class VisitSummaryManager {
...
@@ -28,16 +28,12 @@ public class VisitSummaryManager {
private
VisitLogService
visitLogService
;
private
VisitLogService
visitLogService
;
List
<
String
>
PAGEID_NEED_SAVE
=
Arrays
.
asList
(
PageEnum
.
COMM_VISIT_HOME_PAGE
.
getId
(),
PageEnum
.
COMM_VISIT_THEME
.
getId
());
@KafkaListener
(
topics
=
kafakTopic
)
@KafkaListener
(
topics
=
kafakTopic
)
public
void
updateVisitSummary
(
String
message
)
{
public
void
updateVisitSummary
(
String
message
)
{
// {"durMillsInc":10000,"ident":"AD7B8CE8-2DA4-4FB4-907F-C551B926BA5C","localDate":"2021-08-02","pageId":"p13503","refId":"88737580570230824","visitorId":"275321532031467520"}
// {"durMillsInc":10000,"ident":"AD7B8CE8-2DA4-4FB4-907F-C551B926BA5C","localDate":"2021-08-02","pageId":"p13503","refId":"88737580570230824","visitorId":"275321532031467520"}
log
.
info
(
"receive kafka msg: {}"
,
message
);
log
.
info
(
"receive kafka msg: {}"
,
message
);
KafkaDurationUptMsg
msg
=
JSON
.
parseObject
(
message
,
KafkaDurationUptMsg
.
class
);
KafkaDurationUptMsg
msg
=
JSON
.
parseObject
(
message
,
KafkaDurationUptMsg
.
class
);
// 做一个筛选
if
(!
PAGEID_NEED_SAVE
.
contains
(
msg
.
pageId
))
{
return
;
}
// ident在每次进入新页面 & 回退 的时候都会随机生成一个,所以用ident做唯一key即可。
// ident在每次进入新页面 & 回退 的时候都会随机生成一个,所以用ident做唯一key即可。
VisitLogEntity
vs
=
ConvertUtil
.
convertFromKafka
(
msg
);
VisitLogEntity
vs
=
ConvertUtil
.
convertFromKafka
(
msg
);
visitLogService
.
insertOrUpdateDur
(
vs
);
visitLogService
.
insertOrUpdateDur
(
vs
);
...
...
community-service/src/main/java/com/tanpu/community/service/ThemeService.java
View file @
e38879ab
...
@@ -283,16 +283,14 @@ public class ThemeService {
...
@@ -283,16 +283,14 @@ public class ThemeService {
* @param lastViewTime 更新时间节点
* @param lastViewTime 更新时间节点
* @return
* @return
*/
*/
public
Integer
queryCountFromLast
Time
(
List
<
String
>
userIds
,
LocalDateTime
lastViewTime
)
{
public
Integer
queryCountFromLast
Id
(
List
<
String
>
userIds
,
Long
lastId
)
{
if
(
CollectionUtils
.
isEmpty
(
userIds
))
{
if
(
CollectionUtils
.
isEmpty
(
userIds
))
{
return
0
;
return
0
;
}
}
LambdaQueryWrapper
<
ThemeEntity
>
queryWrapper
=
new
LambdaQueryWrapper
<
ThemeEntity
>()
LambdaQueryWrapper
<
ThemeEntity
>
queryWrapper
=
new
LambdaQueryWrapper
<
ThemeEntity
>()
.
in
(
ThemeEntity:
:
getAuthorId
,
userIds
)
.
in
(
ThemeEntity:
:
getAuthorId
,
userIds
)
.
gt
(
ThemeEntity:
:
getId
,
lastId
)
.
eq
(
ThemeEntity:
:
getDeleteTag
,
DeleteTagEnum
.
NOT_DELETED
.
getCode
());
.
eq
(
ThemeEntity:
:
getDeleteTag
,
DeleteTagEnum
.
NOT_DELETED
.
getCode
());
if
(
lastViewTime
!=
null
)
{
queryWrapper
.
gt
(
ThemeEntity:
:
getCreateTime
,
lastViewTime
);
}
return
themeMapper
.
selectCount
(
queryWrapper
);
return
themeMapper
.
selectCount
(
queryWrapper
);
}
}
...
...
community-service/src/main/java/com/tanpu/community/service/VisitLogService.java
View file @
e38879ab
...
@@ -100,17 +100,17 @@ public class VisitLogService {
...
@@ -100,17 +100,17 @@ public class VisitLogService {
.
eq
(
VisitLogEntity:
:
getRefType
,
PageEnum
.
COMM_VISIT_THEME
.
getId
()));
.
eq
(
VisitLogEntity:
:
getRefType
,
PageEnum
.
COMM_VISIT_THEME
.
getId
()));
}
}
public
LocalDateTime
queryLatestViewFollow
(
String
userId
)
{
//
public LocalDateTime queryLatestViewFollow(String userId) {
List
<
VisitLogEntity
>
visitSummaryEntities
=
visitLogMapper
.
selectList
(
new
LambdaQueryWrapper
<
VisitLogEntity
>()
//
List<VisitLogEntity> visitSummaryEntities = visitLogMapper.selectList(new LambdaQueryWrapper<VisitLogEntity>()
.
eq
(
VisitLogEntity:
:
getVisitorId
,
userId
)
//
.eq(VisitLogEntity::getVisitorId, userId)
.
eq
(
VisitLogEntity:
:
getRefType
,
VisitTypeEnum
.
FOLLOW_THEME_VIEW
.
getCode
())
//
.eq(VisitLogEntity::getRefType, VisitTypeEnum.FOLLOW_THEME_VIEW.getCode())
.
orderByDesc
(
VisitLogEntity:
:
getCreateTime
));
//
.orderByDesc(VisitLogEntity::getCreateTime));
if
(
CollectionUtils
.
isEmpty
(
visitSummaryEntities
))
{
//
if (CollectionUtils.isEmpty(visitSummaryEntities)) {
return
null
;
//
return null;
}
else
{
//
} else {
return
visitSummaryEntities
.
get
(
0
).
getCreateTime
();
//
return visitSummaryEntities.get(0).getCreateTime();
}
//
}
}
//
}
//统计行为集合的浏览量
//统计行为集合的浏览量
public
Map
<
String
,
Integer
>
getCountMapByTargetIds
(
List
<
String
>
refIds
,
String
refType
)
{
public
Map
<
String
,
Integer
>
getCountMapByTargetIds
(
List
<
String
>
refIds
,
String
refType
)
{
...
...
community-service/src/main/java/com/tanpu/community/service/base/ESHelper.java
View file @
e38879ab
...
@@ -16,6 +16,7 @@ import org.elasticsearch.action.search.SearchRequest;
...
@@ -16,6 +16,7 @@ import org.elasticsearch.action.search.SearchRequest;
import
org.elasticsearch.action.search.SearchResponse
;
import
org.elasticsearch.action.search.SearchResponse
;
import
org.elasticsearch.common.xcontent.XContentType
;
import
org.elasticsearch.common.xcontent.XContentType
;
import
org.elasticsearch.index.query.BoolQueryBuilder
;
import
org.elasticsearch.index.query.BoolQueryBuilder
;
import
org.elasticsearch.index.query.MatchPhraseQueryBuilder
;
import
org.elasticsearch.index.query.MatchQueryBuilder
;
import
org.elasticsearch.index.query.MatchQueryBuilder
;
import
org.elasticsearch.index.query.QueryBuilders
;
import
org.elasticsearch.index.query.QueryBuilders
;
import
org.elasticsearch.rest.RestStatus
;
import
org.elasticsearch.rest.RestStatus
;
...
@@ -132,33 +133,43 @@ public class ESHelper {
...
@@ -132,33 +133,43 @@ public class ESHelper {
helper
.
client
=
highClient
;
helper
.
client
=
highClient
;
System
.
out
.
println
(
"insert"
);
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"name"
,
"太阳44444444444444"
);
map
.
put
(
"context"
,
"这里有一个小太阳444444444"
);
// helper.insert("test_index", "", "2", map);
SearchSourceBuilder
search
=
new
SearchSourceBuilder
();
SearchSourceBuilder
search
=
new
SearchSourceBuilder
();
BoolQueryBuilder
boolQb
=
QueryBuilders
.
boolQuery
();
BoolQueryBuilder
boolQb
=
QueryBuilders
.
boolQuery
();
MatchQueryBuilder
matchQb
=
QueryBuilders
.
matchQuery
(
"textContent"
,
"小星星"
);
boolQb
.
must
(
matchQb
);
String
[]
ks
=
new
String
[]{
"左侧"
,
"五粮液"
};
for
(
String
k
:
ks
)
{
MatchPhraseQueryBuilder
contentQb
=
QueryBuilders
.
matchPhraseQuery
(
"textContent"
,
k
);
MatchPhraseQueryBuilder
titleQb
=
QueryBuilders
.
matchPhraseQuery
(
"title"
,
k
);
boolQb
.
should
(
contentQb
);
boolQb
.
should
(
titleQb
);
}
// String[] includes = new String[]{"id"};
// String[] includes = new String[]{"id"};
// String[] excludes = new String[]{};
// String[] excludes = new String[]{};
search
.
query
(
boolQb
).
from
(
0
).
size
(
50
);
search
.
query
(
boolQb
).
from
(
0
).
size
(
50
);
SearchHit
[]
hits
=
helper
.
selectLike
(
search
);
System
.
out
.
println
(
hits
.
length
);
try
{
for
(
SearchHit
hit
:
hits
)
{
SearchRequest
req
=
new
SearchRequest
(
"new-community"
);
System
.
out
.
println
(
hit
.
toString
());
req
.
source
(
search
);
System
.
out
.
println
(
hit
.
getFields
());
SearchResponse
resp
=
helper
.
client
.
search
(
req
,
RequestOptions
.
DEFAULT
);
}
System
.
out
.
println
(
"done"
);
SearchHit
[]
hits
=
resp
.
getHits
().
getHits
();
System
.
out
.
println
(
hits
.
length
);
for
(
SearchHit
hit
:
hits
)
{
System
.
out
.
println
(
hit
.
toString
());
System
.
out
.
println
(
hit
.
getFields
());
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
System
.
out
.
println
(
"done"
);
}
}
...
...
community-service/src/main/java/com/tanpu/community/util/ConvertUtil.java
View file @
e38879ab
...
@@ -116,7 +116,7 @@ public class ConvertUtil {
...
@@ -116,7 +116,7 @@ public class ConvertUtil {
public
static
List
<
CommentQo
>
commentEntity2Qos
(
List
<
CommentEntity
>
entities
)
{
public
static
List
<
CommentQo
>
commentEntity2Qos
(
List
<
CommentEntity
>
entities
)
{
return
entities
.
stream
().
map
(
ConvertUtil:
:
commentEntity2Qo
).
collect
(
Collectors
.
toList
());
return
entities
.
stream
().
map
(
ConvertUtil:
:
commentEntity2Qo
).
collect
(
Collectors
.
toList
());
}
}
/**
/**
* VISIT_SUMMARY
* VISIT_SUMMARY
*/
*/
...
...
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