Commit 3363c847 authored by 张辰's avatar 张辰

添加对埋点的支持

parent 662ac7aa
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 Integer code; private String code;
private String type; private String type;
public Integer getCode() { public String getCode() {
return code; return code;
} }
public void setCode(Integer code) { public void setCode(String code) {
this.code = code; this.code = code;
} }
...@@ -24,7 +24,7 @@ public enum VisitTypeEnum { ...@@ -24,7 +24,7 @@ public enum VisitTypeEnum {
this.type = type; this.type = type;
} }
VisitTypeEnum(Integer code, String type) { VisitTypeEnum(String code, String type) {
this.code = code; this.code = code;
this.type = type; this.type = type;
} }
......
...@@ -23,7 +23,7 @@ public class CodeAutoGenerator { ...@@ -23,7 +23,7 @@ public class CodeAutoGenerator {
String mysqlPassword = "@imeng123"; String mysqlPassword = "@imeng123";
String jdbcUrl = "jdbc:mysql://rm-uf6r22t3d798q4kmkao.mysql.rds.aliyuncs.com:3306/tamp_community"; String jdbcUrl = "jdbc:mysql://rm-uf6r22t3d798q4kmkao.mysql.rds.aliyuncs.com:3306/tamp_community";
// String[] tables = new String[]{"theme"}; // String[] tables = new String[]{"theme"};
String[] tables = new String[]{"comment","follow_rel","theme","visit_log"}; String[] tables = new String[]{"visit_log"};
String basePackage = "com.tanpu.community"; String basePackage = "com.tanpu.community";
String mapperPackage = "dao.mapper.community"; String mapperPackage = "dao.mapper.community";
String entityPackage = "dao.entity.community"; String entityPackage = "dao.entity.community";
......
...@@ -15,7 +15,7 @@ import lombok.NoArgsConstructor; ...@@ -15,7 +15,7 @@ import lombok.NoArgsConstructor;
* </p> * </p>
* *
* @author xudong * @author xudong
* @since 2021-07-28 * @since 2021-08-02
*/ */
@TableName("visit_log") @TableName("visit_log")
@Builder @Builder
...@@ -42,7 +42,7 @@ public class VisitLogEntity implements Serializable { ...@@ -42,7 +42,7 @@ public class VisitLogEntity implements Serializable {
private String refId; private String refId;
@ApiModelProperty(value = "关联目标类型 1:进入话题页 2:进入主题正文 3、用户查看首页-关注") @ApiModelProperty(value = "关联目标类型 1:进入话题页 2:进入主题正文 3、用户查看首页-关注")
private Integer refType; private String refType;
@ApiModelProperty(value = "浏览时间 单位秒") @ApiModelProperty(value = "浏览时间 单位秒")
private Integer duration; private Integer duration;
...@@ -94,11 +94,11 @@ public class VisitLogEntity implements Serializable { ...@@ -94,11 +94,11 @@ public class VisitLogEntity implements Serializable {
this.refId = refId; this.refId = refId;
} }
public Integer getRefType() { public String getRefType() {
return refType; return refType;
} }
public void setRefType(Integer refType) { public void setRefType(String refType) {
this.refType = refType; this.refType = refType;
} }
......
...@@ -27,12 +27,9 @@ public interface VisitLogMapper extends BaseMapper<VisitLogEntity> { ...@@ -27,12 +27,9 @@ public interface VisitLogMapper extends BaseMapper<VisitLogEntity> {
@Update("update visit_log set duration=duration+#{duration} where ident=#{ident}") @Update("update visit_log set duration=duration+#{duration} where ident=#{ident}")
void updateDurByIdent(@Param("duration") Integer dur, @Param("ident") String 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}") @Select("select ref_id as id, count(1) as times from visit_log ${ew.customSqlSegment}")
List<TimesCountEntity> selectCountByThemeIds(@Param(Constants.WRAPPER) LambdaQueryWrapper wrapper); 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}") @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); List<String> selectRefIdByVisitorIdAndCreateBetween(@Param("visitorId") String visitorId, @Param("startDate") Date startDate, @Param("endDate") Date endDate);
} }
...@@ -388,7 +388,7 @@ public class ThemeManager { ...@@ -388,7 +388,7 @@ public class ThemeManager {
// 查询正文 // 查询正文
public ThemeQo getThemeDetail(String themeId, String userId) { public ThemeQo getThemeDetail(String themeId, String userId) {
//TODO 临时埋点,接入新埋点后删除 //TODO 临时埋点,接入新埋点后删除
visitLogService.addPageView(userId, themeId, VisitTypeEnum.THEME_PAGE_VIEW); // visitLogService.addPageView(userId, themeId, VisitTypeEnum.THEME_PAGE_VIEW);
// 查询详情 // 查询详情
ThemeQo themeQo = redisCache.getObject(StringUtils.joinWith("_", CACHE_THEME_ID, themeId), 60, ThemeQo themeQo = redisCache.getObject(StringUtils.joinWith("_", CACHE_THEME_ID, themeId), 60,
() -> this.getDetailCommon(themeId), ThemeQo.class); () -> this.getDetailCommon(themeId), ThemeQo.class);
......
...@@ -26,6 +26,7 @@ public class VisitSummaryManager { ...@@ -26,6 +26,7 @@ public class VisitSummaryManager {
@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"}
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);
// ident在每次进入新页面 & 回退 的时候都会随机生成一个,所以用ident做唯一key即可。 // ident在每次进入新页面 & 回退 的时候都会随机生成一个,所以用ident做唯一key即可。
......
package com.tanpu.community.service; package com.tanpu.community.service;
import com.tanpu.biz.common.enums.clue.PageEnum;
import com.tanpu.biz.common.enums.community.CollectionTypeEnum; import com.tanpu.biz.common.enums.community.CollectionTypeEnum;
import com.tanpu.biz.common.enums.community.TopicStatusEnum; import com.tanpu.biz.common.enums.community.TopicStatusEnum;
import com.tanpu.community.api.beans.qo.ThemeAnalysDO; import com.tanpu.community.api.beans.qo.ThemeAnalysDO;
...@@ -74,7 +75,7 @@ public class RankService { ...@@ -74,7 +75,7 @@ public class RankService {
Map<String, Integer> bookCountMap = collectionService.getCountMapByType(themeIds, CollectionTypeEnum.COLLECT_THEME); Map<String, Integer> bookCountMap = collectionService.getCountMapByType(themeIds, CollectionTypeEnum.COLLECT_THEME);
Map<String, Integer> commentCountMap = commentService.getCountMapByThemeIds(themeIds); Map<String, Integer> commentCountMap = commentService.getCountMapByThemeIds(themeIds);
Map<String, Integer> forwardCountMap = themeService.getForwardCountMap(themeIds); Map<String, Integer> forwardCountMap = themeService.getForwardCountMap(themeIds);
Map<String, Integer> visitCountMap = visitLogService.getCountMapByTargetIds(themeIds, VisitTypeEnum.THEME_PAGE_VIEW); Map<String, Integer> visitCountMap = visitLogService.getCountMapByTargetIds(themeIds, PageEnum.COMM_VISIT_THEME.getId());
for (ThemeAnalysDO theme : themeAnalysDOS) { for (ThemeAnalysDO theme : themeAnalysDOS) {
String themeId = theme.getThemeId(); String themeId = theme.getThemeId();
...@@ -119,7 +120,7 @@ public class RankService { ...@@ -119,7 +120,7 @@ public class RankService {
} }
List<TopicRankQo> topicRankQos = ConvertUtil.topicEntityToHotQos(topicEntities); List<TopicRankQo> topicRankQos = ConvertUtil.topicEntityToHotQos(topicEntities);
List<String> topicIds = topicRankQos.stream().map(TopicRankQo::getTopicId).collect(Collectors.toList()); List<String> topicIds = topicRankQos.stream().map(TopicRankQo::getTopicId).collect(Collectors.toList());
Map<String, Integer> topicViewMap = visitLogService.getCountMapByTargetIds(topicIds, VisitTypeEnum.TOPIC_PAGE_VIEW); Map<String, Integer> topicViewMap = visitLogService.getCountMapByTargetIds(topicIds, VisitTypeEnum.TOPIC_PAGE_VIEW.getType());
for (TopicRankQo topic : topicRankQos) { for (TopicRankQo topic : topicRankQos) {
List<String> themeIds = themeService.queryThemeIdsByTopic(topic.getTopicId()); List<String> themeIds = themeService.queryThemeIdsByTopic(topic.getTopicId());
if (CollectionUtils.isEmpty(themeIds)) { if (CollectionUtils.isEmpty(themeIds)) {
......
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.tanpu.biz.common.enums.clue.PageEnum;
import com.tanpu.community.api.enums.DeleteTagEnum; import com.tanpu.community.api.enums.DeleteTagEnum;
import com.tanpu.community.api.enums.VisitTypeEnum; import com.tanpu.community.api.enums.VisitTypeEnum;
import com.tanpu.community.dao.entity.community.TimesCountEntity; import com.tanpu.community.dao.entity.community.TimesCountEntity;
...@@ -32,7 +33,7 @@ public class VisitLogService { ...@@ -32,7 +33,7 @@ public class VisitLogService {
public List<String> queryUserRecentVisited(String userId) { public List<String> queryUserRecentVisited(String userId) {
Date endDate = new Date(); Date endDate = new Date();
Date startDate = DateUtils.addDays(endDate, -7); Date startDate = DateUtils.addDays(endDate, -7);
List<String> visited = visitLogMapper.selectRefIdByUserIdAndCreateBetween(userId, startDate, endDate); List<String> visited = visitLogMapper.selectRefIdByVisitorIdAndCreateBetween(userId, startDate, endDate);
return visited; return visited;
} }
...@@ -86,7 +87,7 @@ public class VisitLogService { ...@@ -86,7 +87,7 @@ public class VisitLogService {
public Integer queryThemeVisit(String theme) { public Integer queryThemeVisit(String theme) {
return visitLogMapper.selectCount(new LambdaQueryWrapper<VisitLogEntity>() return visitLogMapper.selectCount(new LambdaQueryWrapper<VisitLogEntity>()
.eq(VisitLogEntity::getRefId, theme) .eq(VisitLogEntity::getRefId, theme)
.eq(VisitLogEntity::getRefType, VisitTypeEnum.THEME_PAGE_VIEW.getCode())); .eq(VisitLogEntity::getRefType, PageEnum.COMM_VISIT_THEME.getId()));
} }
// 查询主题 浏览量 // 查询主题 浏览量
...@@ -96,7 +97,7 @@ public class VisitLogService { ...@@ -96,7 +97,7 @@ public class VisitLogService {
} }
return visitLogMapper.selectCount(new LambdaQueryWrapper<VisitLogEntity>() return visitLogMapper.selectCount(new LambdaQueryWrapper<VisitLogEntity>()
.in(VisitLogEntity::getRefId, themes) .in(VisitLogEntity::getRefId, themes)
.eq(VisitLogEntity::getRefType, VisitTypeEnum.THEME_PAGE_VIEW.getCode())); .eq(VisitLogEntity::getRefType, PageEnum.COMM_VISIT_THEME.getId()));
} }
public LocalDateTime queryLatestViewFollow(String userId) { public LocalDateTime queryLatestViewFollow(String userId) {
...@@ -112,14 +113,14 @@ public class VisitLogService { ...@@ -112,14 +113,14 @@ public class VisitLogService {
} }
//统计行为集合的浏览量 //统计行为集合的浏览量
public Map<String, Integer> getCountMapByTargetIds(List<String> refIds, VisitTypeEnum type) { public Map<String, Integer> getCountMapByTargetIds(List<String> refIds, String refType) {
if (CollectionUtils.isEmpty(refIds)){ if (CollectionUtils.isEmpty(refIds)){
return new HashMap<>(); return new HashMap<>();
} }
LambdaQueryWrapper<VisitLogEntity> wrapper = (new LambdaQueryWrapper<VisitLogEntity>() LambdaQueryWrapper<VisitLogEntity> wrapper = (new LambdaQueryWrapper<VisitLogEntity>()
.in(VisitLogEntity::getRefId,refIds)) .in(VisitLogEntity::getRefId,refIds))
.eq(VisitLogEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED) .eq(VisitLogEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED)
.eq(VisitLogEntity::getRefType,type.getCode()) .eq(VisitLogEntity::getRefType, refType)
.groupBy(VisitLogEntity::getRefId); .groupBy(VisitLogEntity::getRefId);
return visitLogMapper.selectCountByThemeIds(wrapper).stream() return visitLogMapper.selectCountByThemeIds(wrapper).stream()
.collect(Collectors.toMap(TimesCountEntity::getId, TimesCountEntity::getTimes)); .collect(Collectors.toMap(TimesCountEntity::getId, TimesCountEntity::getTimes));
......
...@@ -125,11 +125,10 @@ public class ConvertUtil { ...@@ -125,11 +125,10 @@ public class ConvertUtil {
VisitLogEntity vs = new VisitLogEntity(); VisitLogEntity vs = new VisitLogEntity();
vs.setAuthorId(msg.pidUserId); vs.setAuthorId(msg.pidUserId);
vs.setDeleteTag(DeleteTagEnum.NOT_DELETED.ordinal()); vs.setDeleteTag(DeleteTagEnum.NOT_DELETED.ordinal());
vs.setDuration(1); vs.setDuration((int) msg.durMillsInc / 1000);
vs.setIdent(msg.ident); vs.setIdent(msg.ident);
vs.setRefId(msg.refId); vs.setRefId(msg.refId);
// todo vs.setRefType(msg.pageId);
vs.setRefType(-1);
vs.setVisitorId(msg.visitorId); vs.setVisitorId(msg.visitorId);
return vs; return vs;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment