package com.tanpu.community.manager; import com.alibaba.fastjson.JSON; import com.tanpu.common.auth.UserHolder; import com.tanpu.community.api.beans.vo.KafkaDurationUptMsg; import com.tanpu.community.api.enums.VisitTypeEnum; import com.tanpu.community.dao.entity.community.VisitSummaryEntity; import com.tanpu.community.service.VisitSummaryService; import com.tanpu.community.util.ConvertUtil; import lombok.extern.slf4j.Slf4j; import org.elasticsearch.common.recycler.Recycler; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.kafka.annotation.KafkaListener; import org.springframework.kafka.core.KafkaTemplate; import org.springframework.stereotype.Service; import javax.annotation.Resource; @Slf4j @Service public class VisitSummaryManager { private static final String kafakTopic = "tp_new_community_queue_ubr_dur_upd"; @Autowired private KafkaTemplate<String, String> kafkaTemplate; @Autowired private VisitSummaryService visitSummaryService; @Autowired private UserHolder userHolder; @KafkaListener(topics = kafakTopic) public void updateVisitSummary(String message) { KafkaDurationUptMsg msg = JSON.parseObject(message, KafkaDurationUptMsg.class); // ident在每次进入新页面 & 回退 的时候都会随机生成一个,所以用ident做唯一key即可。 VisitSummaryEntity vs = ConvertUtil.convertFromKafka(msg); visitSummaryService.insertOrUpdateDur(vs); } public void addTopicPageView(String topicId) { String userId = userHolder.getUserId(); visitSummaryService.addPageView(userId, topicId, VisitTypeEnum.TOPIC_PAGE_VIEW); } public void addFollowThemeView(String themeId) { String userId = userHolder.getUserId(); visitSummaryService.addPageView(userId, themeId, VisitTypeEnum.THEME_PAGE_VIEW); } public void addFollowThemeView() { String userId = userHolder.getUserId(); visitSummaryService.addPageView(userId, userId, VisitTypeEnum.FOLLOW_THEME_VIEW); } }