Commit 41c4373d authored by 刘基明's avatar 刘基明

Merge remote-tracking branch 'origin/dev' into dev

parents ca0f49bf 3363c847
package com.tanpu.community.api.enums;
public enum VisitTypeEnum {
TOPIC_PAGE_VIEW(1,"进入话题页"),
THEME_PAGE_VIEW(2,"进入主题正文"),
FOLLOW_THEME_VIEW(3,"查看关注主题");
TOPIC_PAGE_VIEW("1","进入话题页"),
// THEME_PAGE_VIEW(2,"进入主题正文"),
FOLLOW_THEME_VIEW("3","查看关注主题");
private Integer code;
private String code;
private String type;
public Integer getCode() {
public String getCode() {
return code;
}
public void setCode(Integer code) {
public void setCode(String code) {
this.code = code;
}
......@@ -24,7 +24,7 @@ public enum VisitTypeEnum {
this.type = type;
}
VisitTypeEnum(Integer code, String type) {
VisitTypeEnum(String code, String type) {
this.code = code;
this.type = type;
}
......
......@@ -23,7 +23,7 @@ public class CodeAutoGenerator {
String mysqlPassword = "@imeng123";
String jdbcUrl = "jdbc:mysql://rm-uf6r22t3d798q4kmkao.mysql.rds.aliyuncs.com:3306/tamp_community";
// 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 mapperPackage = "dao.mapper.community";
String entityPackage = "dao.entity.community";
......
......@@ -15,7 +15,7 @@ import lombok.NoArgsConstructor;
* </p>
*
* @author xudong
* @since 2021-07-28
* @since 2021-08-02
*/
@TableName("visit_log")
@Builder
......@@ -42,7 +42,7 @@ public class VisitLogEntity implements Serializable {
private String refId;
@ApiModelProperty(value = "关联目标类型 1:进入话题页 2:进入主题正文 3、用户查看首页-关注")
private Integer refType;
private String refType;
@ApiModelProperty(value = "浏览时间 单位秒")
private Integer duration;
......@@ -94,11 +94,11 @@ public class VisitLogEntity implements Serializable {
this.refId = refId;
}
public Integer getRefType() {
public String getRefType() {
return refType;
}
public void setRefType(Integer refType) {
public void setRefType(String refType) {
this.refType = refType;
}
......
......@@ -27,12 +27,9 @@ public interface VisitLogMapper extends BaseMapper<VisitLogEntity> {
@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);
List<String> selectRefIdByVisitorIdAndCreateBetween(@Param("visitorId") String visitorId, @Param("startDate") Date startDate, @Param("endDate") Date endDate);
}
......@@ -395,7 +395,7 @@ public class ThemeManager {
// 查询正文
public ThemeQo getThemeDetail(String themeId, String userId) {
//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,
() -> this.getDetailCommon(themeId), ThemeQo.class);
......
......@@ -26,6 +26,7 @@ public class VisitSummaryManager {
@KafkaListener(topics = kafakTopic)
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);
KafkaDurationUptMsg msg = JSON.parseObject(message, KafkaDurationUptMsg.class);
// ident在每次进入新页面 & 回退 的时候都会随机生成一个,所以用ident做唯一key即可。
......
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.TopicStatusEnum;
import com.tanpu.community.api.beans.qo.ThemeAnalysDO;
......@@ -74,7 +75,7 @@ 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 = visitLogService.getCountMapByTargetIds(themeIds, VisitTypeEnum.THEME_PAGE_VIEW);
Map<String, Integer> visitCountMap = visitLogService.getCountMapByTargetIds(themeIds, PageEnum.COMM_VISIT_THEME.getId());
for (ThemeAnalysDO theme : themeAnalysDOS) {
String themeId = theme.getThemeId();
......@@ -119,7 +120,7 @@ public class RankService {
}
List<TopicRankQo> topicRankQos = ConvertUtil.topicEntityToHotQos(topicEntities);
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) {
List<String> themeIds = themeService.queryThemeIdsByTopic(topic.getTopicId());
if (CollectionUtils.isEmpty(themeIds)) {
......
package com.tanpu.community.service;
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.VisitTypeEnum;
import com.tanpu.community.dao.entity.community.TimesCountEntity;
......@@ -32,7 +33,7 @@ public class VisitLogService {
public List<String> queryUserRecentVisited(String userId) {
Date endDate = new Date();
Date startDate = DateUtils.addDays(endDate, -7);
List<String> visited = visitLogMapper.selectRefIdByUserIdAndCreateBetween(userId, startDate, endDate);
List<String> visited = visitLogMapper.selectRefIdByVisitorIdAndCreateBetween(userId, startDate, endDate);
return visited;
}
......@@ -86,7 +87,7 @@ public class VisitLogService {
public Integer queryThemeVisit(String theme) {
return visitLogMapper.selectCount(new LambdaQueryWrapper<VisitLogEntity>()
.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 {
}
return visitLogMapper.selectCount(new LambdaQueryWrapper<VisitLogEntity>()
.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) {
......@@ -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)){
return new HashMap<>();
}
LambdaQueryWrapper<VisitLogEntity> wrapper = (new LambdaQueryWrapper<VisitLogEntity>()
.in(VisitLogEntity::getRefId,refIds))
.eq(VisitLogEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED)
.eq(VisitLogEntity::getRefType,type.getCode())
.eq(VisitLogEntity::getRefType, refType)
.groupBy(VisitLogEntity::getRefId);
return visitLogMapper.selectCountByThemeIds(wrapper).stream()
.collect(Collectors.toMap(TimesCountEntity::getId, TimesCountEntity::getTimes));
......
......@@ -125,11 +125,10 @@ public class ConvertUtil {
VisitLogEntity vs = new VisitLogEntity();
vs.setAuthorId(msg.pidUserId);
vs.setDeleteTag(DeleteTagEnum.NOT_DELETED.ordinal());
vs.setDuration(1);
vs.setDuration((int) msg.durMillsInc / 1000);
vs.setIdent(msg.ident);
vs.setRefId(msg.refId);
// todo
vs.setRefType(-1);
vs.setRefType(msg.pageId);
vs.setVisitorId(msg.visitorId);
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