Commit 06fb196e authored by 张辰's avatar 张辰

添加圈子支持

parent 41c4373d
...@@ -21,8 +21,8 @@ import java.util.List; ...@@ -21,8 +21,8 @@ import java.util.List;
* @since 2021-07-28 * @since 2021-07-28
*/ */
public interface VisitLogMapper extends BaseMapper<VisitLogEntity> { public interface VisitLogMapper extends BaseMapper<VisitLogEntity> {
@Select("select * from visit_log where ident=#{ident}") @Select("select * from visit_log where ident=#{ident} and ref_id=#{refId}")
VisitLogEntity selectByIdent(@Param("ident") String ident); VisitLogEntity selectByIdentAndRefId(@Param("ident") String ident, @Param("refId") String refId);
@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);
......
package com.tanpu.community.manager; package com.tanpu.community.manager;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.tanpu.biz.common.enums.clue.PageEnum;
import com.tanpu.community.api.beans.vo.KafkaDurationUptMsg; import com.tanpu.community.api.beans.vo.KafkaDurationUptMsg;
import com.tanpu.community.dao.entity.community.VisitLogEntity; import com.tanpu.community.dao.entity.community.VisitLogEntity;
import com.tanpu.community.service.VisitLogService; import com.tanpu.community.service.VisitLogService;
...@@ -11,6 +12,9 @@ import org.springframework.kafka.annotation.KafkaListener; ...@@ -11,6 +12,9 @@ import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.core.KafkaTemplate; import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.List;
@Slf4j @Slf4j
@Service @Service
public class VisitSummaryManager { public class VisitSummaryManager {
...@@ -24,11 +28,16 @@ public class VisitSummaryManager { ...@@ -24,11 +28,16 @@ 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);
......
...@@ -58,7 +58,7 @@ public class VisitLogService { ...@@ -58,7 +58,7 @@ public class VisitLogService {
@Transactional @Transactional
public void insertOrUpdateDur(VisitLogEntity vs) { public void insertOrUpdateDur(VisitLogEntity vs) {
if (visitLogMapper.selectByIdent(vs.getIdent()) == null) { if (visitLogMapper.selectByIdentAndRefId(vs.getIdent(), vs.getRefId()) == null) {
visitLogMapper.insert(vs); visitLogMapper.insert(vs);
} else { } else {
visitLogMapper.updateDurByIdent(vs.getDuration(), vs.getIdent()); visitLogMapper.updateDurByIdent(vs.getDuration(), vs.getIdent());
......
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