Commit 9a58c57f authored by 张辰's avatar 张辰

cache

parent 3fdd9bb1
...@@ -26,6 +26,17 @@ public class RedisKeyConstant { ...@@ -26,6 +26,17 @@ public class RedisKeyConstant {
public static final String TOPIC_POST_USER_COUNT_ ="TOPIC_POST_USER_COUNT_"; public static final String TOPIC_POST_USER_COUNT_ ="TOPIC_POST_USER_COUNT_";
//回帖人数 //回帖人数
public static final String TOPIC_COMMENT_USER_COUNT_ ="TOPIC_COMMENT_USER_COUNT_"; public static final String TOPIC_COMMENT_USER_COUNT_ ="TOPIC_COMMENT_USER_COUNT_";
// 出现在用户的搜索列表中的主题id
public static final String THEME_APPEAR_IN_SEARCH_LIST = "THEME_APPEAR_IN_SEARCH_LIST_";
// feign 查询用户信息
public static final String CACGE_FEIGN_USER_INFO = "CACHE_FEIGN_USER_INFO_";
// 主题下的评论
public static final String CACHE_COMMENT_THEMEID = "CACHE_COMMENT_THEMEID_";
// 评论本身
public static final String CAHCE_COMMENT_ID = "CACHE_COMMENT_ID_";
// 主题本身
public static final String CACHE_THEME_ID = "CACHE_THEME_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_";
......
...@@ -45,6 +45,10 @@ public class RedisCache { ...@@ -45,6 +45,10 @@ public class RedisCache {
return ret; return ret;
} }
public void evict(String key) {
delete(key);
}
private String get(String key) { private String get(String key) {
key = cacheName + ":" + key; key = cacheName + ":" + key;
return redisHelper.get(key); return redisHelper.get(key);
...@@ -60,6 +64,10 @@ public class RedisCache { ...@@ -60,6 +64,10 @@ public class RedisCache {
} }
} }
private void delete(String key) {
redisHelper.delete(key);
}
public static class Builder { public static class Builder {
RedisCache cache = new RedisCache(); RedisCache cache = new RedisCache();
......
package com.tanpu.community.config; package com.tanpu.community.config;
import com.tanpu.community.cache.RedisCache; import com.tanpu.community.cache.RedisCache;
import com.tanpu.community.util.SpringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import javax.annotation.Resource;
@Configuration @Configuration
public class CacheConfig { public class CacheConfig {
@Autowired
private SpringUtils springUtils;
@Bean @Bean
public RedisCache redisCache() { public RedisCache redisCache() {
return new RedisCache.Builder().cacheName("community2").build(); return new RedisCache.Builder().cacheName("community2").build();
......
...@@ -8,17 +8,20 @@ import com.tanpu.common.exception.BizException; ...@@ -8,17 +8,20 @@ import com.tanpu.common.exception.BizException;
import com.tanpu.community.api.beans.qo.ThemeQo; import com.tanpu.community.api.beans.qo.ThemeQo;
import com.tanpu.community.api.beans.req.theme.*; import com.tanpu.community.api.beans.req.theme.*;
import com.tanpu.community.api.beans.resp.CreateThemeResp; import com.tanpu.community.api.beans.resp.CreateThemeResp;
import com.tanpu.community.cache.RedisCache;
import com.tanpu.community.manager.ThemeManager; import com.tanpu.community.manager.ThemeManager;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List; import java.util.List;
import static com.tanpu.community.api.constants.RedisKeyConstant.CACHE_THEME_ID;
@RestController @RestController
@Slf4j @Slf4j
@RequestMapping(value = "/api/theme") @RequestMapping(value = "/api/theme")
...@@ -28,6 +31,8 @@ public class ThemeController { ...@@ -28,6 +31,8 @@ public class ThemeController {
private ThemeManager themeManager; private ThemeManager themeManager;
@Resource @Resource
private UserHolder userHolder; private UserHolder userHolder;
@Autowired
private RedisCache redisCache;
@AuthLogin @AuthLogin
@ApiOperation("发表主题") @ApiOperation("发表主题")
...@@ -57,7 +62,8 @@ public class ThemeController { ...@@ -57,7 +62,8 @@ public class ThemeController {
@ResponseBody @ResponseBody
public CommonResp<ThemeQo> getThemeMainText(@RequestParam String themeId) { public CommonResp<ThemeQo> getThemeMainText(@RequestParam String themeId) {
String userId = userHolder.getUserId(); String userId = userHolder.getUserId();
ThemeQo themeQo = themeManager.getDetail(themeId, userId); ThemeQo themeQo = redisCache.getObject(StringUtils.joinWith("_", CACHE_THEME_ID, themeId), 60,
() -> themeManager.getDetail(themeId, userId), ThemeQo.class);
return CommonResp.success(themeQo); return CommonResp.success(themeQo);
} }
......
...@@ -2,6 +2,11 @@ package com.tanpu.community.dao.mapper.community; ...@@ -2,6 +2,11 @@ package com.tanpu.community.dao.mapper.community;
import com.tanpu.community.dao.entity.community.VisitSummaryEntity; import com.tanpu.community.dao.entity.community.VisitSummaryEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import java.util.List;
/** /**
* <p> * <p>
...@@ -12,5 +17,12 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; ...@@ -12,5 +17,12 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
* @since 2021-07-22 * @since 2021-07-22
*/ */
public interface VisitSummaryMapper extends BaseMapper<VisitSummaryEntity> { public interface VisitSummaryMapper extends BaseMapper<VisitSummaryEntity> {
@Select("select * from visit_summary where ident=#{ident}")
VisitSummaryEntity selectByIdent(@Param("ident") String ident);
@Update("update visit_summary set duration=duration+#{duration} where ident=#{ident}")
void updateDurByIdent(@Param("duration") Integer dur, @Param("ident") String ident);
@Select("select ref_id from visit_summary where visitor_id=#{visitorId} and ref_id in (#{refIds})")
List<String> selectRefIdByUserId(@Param("visitorId") String visitorId, @Param("refIds") String refIds);
} }
...@@ -11,12 +11,14 @@ import com.tanpu.community.api.enums.CollectionTypeEnum; ...@@ -11,12 +11,14 @@ import com.tanpu.community.api.enums.CollectionTypeEnum;
import com.tanpu.community.api.enums.CommentTypeEnum; import com.tanpu.community.api.enums.CommentTypeEnum;
import com.tanpu.community.api.enums.OperationTypeEnum; import com.tanpu.community.api.enums.OperationTypeEnum;
import com.tanpu.community.api.enums.ReportTypeEnum; import com.tanpu.community.api.enums.ReportTypeEnum;
import com.tanpu.community.cache.RedisCache;
import com.tanpu.community.dao.entity.community.CommentEntity; import com.tanpu.community.dao.entity.community.CommentEntity;
import com.tanpu.community.feign.fatools.FeignClientForFatools; import com.tanpu.community.feign.fatools.FeignClientForFatools;
import com.tanpu.community.service.CollectionService; import com.tanpu.community.service.CollectionService;
import com.tanpu.community.service.CommentService; import com.tanpu.community.service.CommentService;
import com.tanpu.community.service.ReportLogService; import com.tanpu.community.service.ReportLogService;
import com.tanpu.community.util.ConvertUtil; import com.tanpu.community.util.ConvertUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -26,6 +28,8 @@ import java.util.List; ...@@ -26,6 +28,8 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static com.tanpu.community.api.constants.RedisKeyConstant.CACGE_FEIGN_USER_INFO;
@Service @Service
public class CommentManager { public class CommentManager {
...@@ -41,6 +45,9 @@ public class CommentManager { ...@@ -41,6 +45,9 @@ public class CommentManager {
@Resource @Resource
private ReportLogService reportLogService; private ReportLogService reportLogService;
@Autowired
private RedisCache redisCache;
// 评论(对主题) // 评论(对主题)
public void comment(CreateCommentReq req, String userId) { public void comment(CreateCommentReq req, String userId) {
CommentEntity commentEntity = CommentEntity.builder() CommentEntity commentEntity = CommentEntity.builder()
...@@ -60,13 +67,13 @@ public class CommentManager { ...@@ -60,13 +67,13 @@ public class CommentManager {
List<CommentEntity> commentEntities = commentService.selectByThemeIdAndParentId(themeId, null); List<CommentEntity> commentEntities = commentService.selectByThemeIdAndParentId(themeId, null);
List<CommentQo> commentQos = ConvertUtil.commentEntity2Qos(commentEntities); List<CommentQo> commentQos = ConvertUtil.commentEntity2Qos(commentEntities);
Set<String> likeCommentList = collectionService.getListByUser(userId, CollectionTypeEnum.LIKE_COMMENT); Set<String> likeCommentList = collectionService.getListByUser(userId, CollectionTypeEnum.LIKE_COMMENT);
for (CommentQo commentQo : commentQos) { for (CommentQo commentQo : commentQos) {
//用户信息 //用户信息
String authorId = commentQo.getAuthorId(); String authorId = commentQo.getAuthorId();
CommonResp<UserInfoNew> userInfoNewCommonResp = feignClientForFatools.queryUsersListNew(authorId); CommonResp<UserInfoNew> userInfoNewCommonResp = redisCache.getObject(StringUtils.joinWith(CACGE_FEIGN_USER_INFO, authorId),
60 * 10, () -> feignClientForFatools.queryUsersListNew(authorId), CommonResp.class);
if (userInfoNewCommonResp.isNotSuccess()) { if (userInfoNewCommonResp.isNotSuccess()) {
throw new BizException("内部接口调用失败"); throw new BizException("内部接口调用失败");
} }
......
...@@ -10,6 +10,7 @@ import com.tanpu.community.api.beans.req.theme.*; ...@@ -10,6 +10,7 @@ import com.tanpu.community.api.beans.req.theme.*;
import com.tanpu.community.api.beans.resp.CreateThemeResp; import com.tanpu.community.api.beans.resp.CreateThemeResp;
import com.tanpu.community.api.beans.resp.ThemeFullSearchResp; import com.tanpu.community.api.beans.resp.ThemeFullSearchResp;
import com.tanpu.community.api.enums.*; import com.tanpu.community.api.enums.*;
import com.tanpu.community.cache.RedisCache;
import com.tanpu.community.dao.entity.community.*; import com.tanpu.community.dao.entity.community.*;
import com.tanpu.community.dao.entity.user.UserInfoEntity; import com.tanpu.community.dao.entity.user.UserInfoEntity;
import com.tanpu.community.feign.fatools.FeignClientForFatools; import com.tanpu.community.feign.fatools.FeignClientForFatools;
...@@ -31,6 +32,8 @@ import java.time.LocalDateTime; ...@@ -31,6 +32,8 @@ import java.time.LocalDateTime;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static com.tanpu.community.api.constants.RedisKeyConstant.CACHE_THEME_ID;
@Slf4j @Slf4j
@Service @Service
public class ThemeManager { public class ThemeManager {
...@@ -73,6 +76,9 @@ public class ThemeManager { ...@@ -73,6 +76,9 @@ public class ThemeManager {
@Autowired @Autowired
private FeignClientForFatools feignClientForFatools; private FeignClientForFatools feignClientForFatools;
@Autowired
private RedisCache redisCache;
public ThemeFullSearchResp themeFullSearch(String keyword, Integer pageNo, Integer pageSize, List<String> excludeIds, String userId) { public ThemeFullSearchResp themeFullSearch(String keyword, Integer pageNo, Integer pageSize, List<String> excludeIds, String userId) {
Integer from = (pageNo - 1) * pageSize; Integer from = (pageNo - 1) * pageSize;
ThemeFullSearchResp resp = new ThemeFullSearchResp(); ThemeFullSearchResp resp = new ThemeFullSearchResp();
...@@ -95,10 +101,11 @@ public class ThemeManager { ...@@ -95,10 +101,11 @@ public class ThemeManager {
return resp; return resp;
} }
@Transactional
/** /**
* 发表主题(可修改) * 发表主题(可修改)
*/ */
@Transactional
public CreateThemeResp publishTheme(CreateThemeReq req, String userId) { public CreateThemeResp publishTheme(CreateThemeReq req, String userId) {
//直播类型做转播检查 //直播类型做转播检查
List<ThemeContentReq> contents = req.getContent(); List<ThemeContentReq> contents = req.getContent();
...@@ -135,6 +142,8 @@ public class ThemeManager { ...@@ -135,6 +142,8 @@ public class ThemeManager {
log.error("error in save theme to ES. themeId:{}, error:{}", themeEntity.getThemeId(), ExceptionUtils.getStackTrace(e)); log.error("error in save theme to ES. themeId:{}, error:{}", themeEntity.getThemeId(), ExceptionUtils.getStackTrace(e));
} }
redisCache.evict(StringUtils.joinWith("_", CACHE_THEME_ID, themeEntity.getThemeId()));
return CreateThemeResp.builder().themeId(themeEntity.getThemeId()).build(); return CreateThemeResp.builder().themeId(themeEntity.getThemeId()).build();
} }
......
...@@ -37,13 +37,10 @@ public class VisitSummaryManager { ...@@ -37,13 +37,10 @@ public class VisitSummaryManager {
KafkaDurationUptMsg msg = JSON.parseObject(message, KafkaDurationUptMsg.class); KafkaDurationUptMsg msg = JSON.parseObject(message, KafkaDurationUptMsg.class);
// ident在每次进入新页面 & 回退 的时候都会随机生成一个,所以用ident做唯一key即可。 // ident在每次进入新页面 & 回退 的时候都会随机生成一个,所以用ident做唯一key即可。
VisitSummaryEntity vs = ConvertUtil.convertFromKafka(msg); VisitSummaryEntity vs = ConvertUtil.convertFromKafka(msg);
visitSummaryService.insertOrUpdateDur(vs);
} }
public void addTopicPageView(String topicId) { public void addTopicPageView(String topicId) {
String userId = userHolder.getUserId(); String userId = userHolder.getUserId();
visitSummaryService.addPageView(userId, topicId, VisitTypeEnum.TOPIC_PAGE_VIEW); visitSummaryService.addPageView(userId, topicId, VisitTypeEnum.TOPIC_PAGE_VIEW);
......
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.fasterxml.jackson.core.type.TypeReference;
import com.tanpu.common.exception.BizException; import com.tanpu.common.exception.BizException;
import com.tanpu.common.redis.RedisKeyHelper;
import com.tanpu.common.uuid.UuidGenHelper; import com.tanpu.common.uuid.UuidGenHelper;
import com.tanpu.community.api.enums.CommentTypeEnum; import com.tanpu.community.api.enums.CommentTypeEnum;
import com.tanpu.community.api.enums.DeleteTagEnum; import com.tanpu.community.api.enums.DeleteTagEnum;
import com.tanpu.community.api.enums.ReportStatusEnum; import com.tanpu.community.api.enums.ReportStatusEnum;
import com.tanpu.community.cache.RedisCache;
import com.tanpu.community.dao.entity.community.CommentEntity; import com.tanpu.community.dao.entity.community.CommentEntity;
import com.tanpu.community.dao.mapper.community.CommentMapper; import com.tanpu.community.dao.mapper.community.CommentMapper;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
...@@ -19,6 +22,9 @@ import java.util.List; ...@@ -19,6 +22,9 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static com.tanpu.community.api.constants.RedisKeyConstant.CACHE_COMMENT_THEMEID;
import static com.tanpu.community.api.constants.RedisKeyConstant.CAHCE_COMMENT_ID;
@Service @Service
public class CommentService { public class CommentService {
...@@ -28,6 +34,9 @@ public class CommentService { ...@@ -28,6 +34,9 @@ public class CommentService {
@Autowired @Autowired
private UuidGenHelper uuidGenHelper; private UuidGenHelper uuidGenHelper;
@Autowired
private RedisCache redisCache;
@Transactional @Transactional
public void insertComment(CommentEntity commentEntity) { public void insertComment(CommentEntity commentEntity) {
commentEntity.setCommentId(uuidGenHelper.getUuidStr()); commentEntity.setCommentId(uuidGenHelper.getUuidStr());
...@@ -64,17 +73,14 @@ public class CommentService { ...@@ -64,17 +73,14 @@ public class CommentService {
} }
public List<CommentEntity> selectByThemeIdAndParentId(String themeId, String parentId) { public List<CommentEntity> selectByThemeIdAndParentId(String themeId, String parentId) {
LambdaQueryWrapper<CommentEntity> queryWrapper = new LambdaQueryWrapper<CommentEntity>() return redisCache.getList(StringUtils.joinWith("_", CACHE_COMMENT_THEMEID, themeId, parentId),
.eq(CommentEntity::getThemeId, themeId) 60, () -> {
.eq(CommentEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode()) LambdaQueryWrapper<CommentEntity> queryWrapper = new LambdaQueryWrapper<CommentEntity>()
.orderByDesc(CommentEntity::getCreateTime); .eq(CommentEntity::getThemeId, themeId)
//二级评论,暂未开放,注意“”与null的区别 .eq(CommentEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode())
// if (parentId == null) { .orderByDesc(CommentEntity::getCreateTime);
// queryWrapper.isNull(CommentEntity::getParentId); return commentMapper.selectList(queryWrapper);
// } else { }, new TypeReference<List<CommentEntity>>() {});
// queryWrapper.eq(CommentEntity::getParentId, parentId);
// }
return commentMapper.selectList(queryWrapper);
} }
...@@ -110,5 +116,6 @@ public class CommentService { ...@@ -110,5 +116,6 @@ public class CommentService {
} }
commentEntity.setReportStatus(ReportStatusEnum.REPORTED.getCode()); commentEntity.setReportStatus(ReportStatusEnum.REPORTED.getCode());
commentMapper.updateById(commentEntity); commentMapper.updateById(commentEntity);
redisCache.evict(StringUtils.joinWith("_", CAHCE_COMMENT_ID, commentId));
} }
} }
...@@ -15,7 +15,6 @@ import java.util.List; ...@@ -15,7 +15,6 @@ import java.util.List;
public class HomePageService { public class HomePageService {
@Resource @Resource
private HomePageMapper homePageMapper; private HomePageMapper homePageMapper;
......
...@@ -3,9 +3,11 @@ package com.tanpu.community.service; ...@@ -3,9 +3,11 @@ package com.tanpu.community.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.tanpu.common.exception.BizException; import com.tanpu.common.exception.BizException;
import com.tanpu.common.redis.RedisHelper;
import com.tanpu.common.uuid.UuidGenHelper; import com.tanpu.common.uuid.UuidGenHelper;
import com.tanpu.community.api.enums.DeleteTagEnum; import com.tanpu.community.api.enums.DeleteTagEnum;
import com.tanpu.community.api.enums.ReportStatusEnum; import com.tanpu.community.api.enums.ReportStatusEnum;
import com.tanpu.community.cache.RedisCache;
import com.tanpu.community.dao.entity.community.ThemeEntity; import com.tanpu.community.dao.entity.community.ThemeEntity;
import com.tanpu.community.dao.mapper.community.ThemeMapper; import com.tanpu.community.dao.mapper.community.ThemeMapper;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
...@@ -16,11 +18,14 @@ import org.springframework.transaction.annotation.Transactional; ...@@ -16,11 +18,14 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static com.tanpu.community.api.constants.RedisKeyConstant.THEME_APPEAR_IN_SEARCH_LIST;
@Service @Service
public class ThemeService { public class ThemeService {
...@@ -30,6 +35,9 @@ public class ThemeService { ...@@ -30,6 +35,9 @@ public class ThemeService {
@Autowired @Autowired
private UuidGenHelper uuidGenHelper; private UuidGenHelper uuidGenHelper;
@Autowired
private RedisHelper redisHelper;
@Transactional @Transactional
public void insertTheme(ThemeEntity themeEntity) { public void insertTheme(ThemeEntity themeEntity) {
themeEntity.setThemeId(uuidGenHelper.getUuidStr()); themeEntity.setThemeId(uuidGenHelper.getUuidStr());
......
...@@ -6,6 +6,8 @@ import com.tanpu.community.dao.entity.community.VisitSummaryEntity; ...@@ -6,6 +6,8 @@ import com.tanpu.community.dao.entity.community.VisitSummaryEntity;
import com.tanpu.community.dao.mapper.community.VisitSummaryMapper; import com.tanpu.community.dao.mapper.community.VisitSummaryMapper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.ListUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -20,6 +22,23 @@ public class VisitSummaryService { ...@@ -20,6 +22,23 @@ public class VisitSummaryService {
@Resource @Resource
private VisitSummaryMapper visitSummaryMapper; private VisitSummaryMapper visitSummaryMapper;
public List<String> filterUserNotVisited(String userId, List<String> refIds) {
if (refIds.isEmpty()) {
return refIds;
}
List<String> visited = visitSummaryMapper.selectRefIdByUserId(userId, StringUtils.joinWith(",", refIds));
return ListUtils.subtract(refIds, visited);
}
@Transactional
public void insertOrUpdateDur(VisitSummaryEntity vs) {
if (visitSummaryMapper.selectByIdent(vs.getIdent()) == null) {
visitSummaryMapper.insert(vs);
} else {
visitSummaryMapper.updateDurByIdent(vs.getDuration(), vs.getIdent());
}
}
@Transactional @Transactional
public void addPageView(String userId, String targetId, VisitTypeEnum type) { public void addPageView(String userId, String targetId, VisitTypeEnum type) {
visitSummaryMapper.insert(VisitSummaryEntity.builder() visitSummaryMapper.insert(VisitSummaryEntity.builder()
...@@ -54,11 +73,6 @@ public class VisitSummaryService { ...@@ -54,11 +73,6 @@ public class VisitSummaryService {
.eq(VisitSummaryEntity::getRefType, VisitTypeEnum.THEME_PAGE_VIEW.getCode())); .eq(VisitSummaryEntity::getRefType, VisitTypeEnum.THEME_PAGE_VIEW.getCode()));
} }
// 更新访问时长
public void updateDurByIdent(String ident, Integer dur) {
// visitSummaryMapper.updateDurByIdent(ident, dur);
}
public LocalDateTime queryLatestViewFollow(String userId) { public LocalDateTime queryLatestViewFollow(String userId) {
List<VisitSummaryEntity> visitSummaryEntities = visitSummaryMapper.selectList(new LambdaQueryWrapper<VisitSummaryEntity>() List<VisitSummaryEntity> visitSummaryEntities = visitSummaryMapper.selectList(new LambdaQueryWrapper<VisitSummaryEntity>()
.eq(VisitSummaryEntity::getVisitorId, userId) .eq(VisitSummaryEntity::getVisitorId, userId)
......
package com.tanpu.community.util; package com.tanpu.community.util;
import com.tanpu.common.api.CommonResp; import com.tanpu.common.api.*;
import com.tanpu.common.constant.ErrorCodeConstant; import com.tanpu.common.constant.ErrorCodeConstant;
import com.tencentcloudapi.cms.v20190321.CmsClient; import com.tencentcloudapi.cms.v20190321.CmsClient;
import com.tencentcloudapi.cms.v20190321.models.ImageModerationRequest; import com.tencentcloudapi.cms.v20190321.models.ImageModerationRequest;
......
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