Commit 79e55670 authored by 刘基明's avatar 刘基明

关注更新条数

parent 97d39338
......@@ -2,7 +2,8 @@ package com.tanpu.community.api.enums;
public enum VisitTypeEnum {
TOPIC_PAGE_VIEW(1,"进入话题页"),
THEME_PAGE_VIEW(2,"进入主题正文");
THEME_PAGE_VIEW(2,"进入主题正文"),
FOLLOW_THEME_VIEW(3,"查看关注主题");
private Integer code;
private String type;
......
......@@ -30,10 +30,17 @@ public class MetricsController {
@ApiOperation("浏览主题")
@GetMapping("/view/theme")
public CommonResp pageViewTheme(@RequestParam String themeId){
visitSummaryManager.addThemePageView(themeId);
visitSummaryManager.addFollowThemeView(themeId);
return CommonResp.success();
}
@AuthLogin
@ApiOperation("浏览关注主题")
@GetMapping("/view/follow")
public CommonResp pageViewTheme(){
visitSummaryManager.addFollowThemeView();
return CommonResp.success();
}
}
......@@ -126,4 +126,13 @@ public class ThemeController {
return CommonResp.success();
}
@AuthLogin
@ApiOperation("关注主题更新数量")
@GetMapping(value = "/updateCount")
@ResponseBody
public CommonResp<Integer> updateCount() {
String userId = userHolder.getUserId();
return CommonResp.success(themeManager.getFollowUpdateCount(userId));
}
}
......@@ -16,12 +16,12 @@ import java.time.LocalDateTime;
* </p>
*
* @author xudong
* @since 2021-07-07
* @since 2021-07-19
*/
@TableName("visit_summary")
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Builder
@ApiModel(value="VisitSummaryEntity对象", description="浏览记录")
public class VisitSummaryEntity implements Serializable {
......@@ -42,18 +42,14 @@ public class VisitSummaryEntity implements Serializable {
@ApiModelProperty(value = "关联目标ID")
private String refId;
@ApiModelProperty(value = "关联目标类型")
@ApiModelProperty(value = "关联目标类型 1:进入话题页 2:进入主题正文 3、用户查看首页-关注")
private Integer refType;
@ApiModelProperty(value = "浏览时间 单位秒")
private Integer duration;
private String createBy;
private LocalDateTime createTime;
private String updateBy;
private LocalDateTime updateTime;
private Integer deleteTag;
......@@ -115,14 +111,6 @@ public class VisitSummaryEntity implements Serializable {
this.duration = duration;
}
public String getCreateBy() {
return createBy;
}
public void setCreateBy(String createBy) {
this.createBy = createBy;
}
public LocalDateTime getCreateTime() {
return createTime;
}
......@@ -131,14 +119,6 @@ public class VisitSummaryEntity implements Serializable {
this.createTime = createTime;
}
public String getUpdateBy() {
return updateBy;
}
public void setUpdateBy(String updateBy) {
this.updateBy = updateBy;
}
public LocalDateTime getUpdateTime() {
return updateTime;
}
......@@ -165,9 +145,7 @@ public class VisitSummaryEntity implements Serializable {
", refId=" + refId +
", refType=" + refType +
", duration=" + duration +
", createBy=" + createBy +
", createTime=" + createTime +
", updateBy=" + updateBy +
", updateTime=" + updateTime +
", deleteTag=" + deleteTag +
"}";
......
......@@ -9,7 +9,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
* </p>
*
* @author xudong
* @since 2021-07-07
* @since 2021-07-19
*/
public interface VisitSummaryMapper extends BaseMapper<VisitSummaryEntity> {
......
......@@ -27,6 +27,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
......@@ -53,14 +54,11 @@ public class ThemeManager {
@Autowired
private ThemeAttachmentService themeAttachmentService;
@Autowired
private HomePageService homePageService;
@Resource
private ProductService productService;
@Autowired
private OSSFileService ossFileService;
private VisitSummaryService visitSummaryService;
@Transactional
......@@ -342,4 +340,9 @@ public class ThemeManager {
//TODO
}
public Integer getFollowUpdateCount(String userId) {
LocalDateTime lastViewTime = visitSummaryService.queryLatestViewFollow(userId);
List<String> fansList = followRelService.queryFansByFollowerId(userId);
return themeService.queryCountFromLastTime(fansList, lastViewTime);
}
}
......@@ -22,9 +22,14 @@ public class VisitSummaryManager {
visitSummaryService.addPageView(userId, topicId, VisitTypeEnum.TOPIC_PAGE_VIEW);
}
public void addThemePageView(String themeId) {
public void addFollowThemeView(String themeId) {
String userId = userHolder.getUserId();
visitSummaryService.addPageView(userId, themeId, VisitTypeEnum.TOPIC_PAGE_VIEW);
visitSummaryService.addPageView(userId, themeId, VisitTypeEnum.THEME_PAGE_VIEW);
}
public void addFollowThemeView() {
String userId = userHolder.getUserId();
visitSummaryService.addPageView(userId, userId, VisitTypeEnum.FOLLOW_THEME_VIEW);
}
}
......@@ -7,12 +7,14 @@ import com.tanpu.common.uuid.UuidGenHelper;
import com.tanpu.community.api.enums.DeleteTagEnum;
import com.tanpu.community.dao.entity.community.ThemeEntity;
import com.tanpu.community.dao.mapper.community.ThemeMapper;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List;
import java.util.Set;
......@@ -34,20 +36,21 @@ public class ThemeService {
}
@Transactional
public void update(ThemeEntity themeEntity,String themeId) {
themeMapper.update(themeEntity,new LambdaUpdateWrapper<ThemeEntity>().eq(ThemeEntity::getThemeId,themeId));
public void update(ThemeEntity themeEntity, String themeId) {
themeMapper.update(themeEntity, new LambdaUpdateWrapper<ThemeEntity>().eq(ThemeEntity::getThemeId, themeId));
}
//根据id返回主题详情
//根据id返回主题详情(未删)
public ThemeEntity queryByThemeId(String themeId) {
return themeMapper.selectOne(new LambdaQueryWrapper<ThemeEntity>()
.eq(ThemeEntity::getThemeId,themeId));
.eq(ThemeEntity::getThemeId, themeId)
.eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode()));
}
public List<ThemeEntity> queryThemesByUserId(String userId) {
return themeMapper.selectList(new LambdaQueryWrapper<ThemeEntity>()
.eq(ThemeEntity::getAuthorId,userId)
.eq(ThemeEntity::getDeleteTag,DeleteTagEnum.NOT_DELETED.getCode())
.eq(ThemeEntity::getAuthorId, userId)
.eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode())
.orderByDesc(ThemeEntity::getId));
}
......@@ -58,27 +61,27 @@ public class ThemeService {
.orderByDesc(ThemeEntity::getId);
if (StringUtils.isNotEmpty(lastId)) {
ThemeEntity lastEntity = queryByThemeId(lastId);
if (lastEntity==null) throw new BizException("主题未找到,id:"+lastId);
if (lastEntity == null) throw new BizException("主题未找到,id:" + lastId);
queryWrapper.lt(ThemeEntity::getUpdateTime, lastEntity.getCreateTime());
}
if (pageSize!=null){
queryWrapper.last("limit "+pageSize);
if (pageSize != null) {
queryWrapper.last("limit " + pageSize);
}
return themeMapper.selectList(queryWrapper);
}
//根据ids返回主题详情,带分页
public List<ThemeEntity> queryByThemeIds(List<String> themeIds, String lastId,Integer pageSize) {
public List<ThemeEntity> queryByThemeIds(List<String> themeIds, String lastId, Integer pageSize) {
LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>()
.in(ThemeEntity::getThemeId, themeIds)
.eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode());
if (StringUtils.isNotEmpty(lastId)) {
ThemeEntity lastEntity = queryByThemeId(lastId);
if (lastEntity==null) throw new BizException("主题未找到,id:"+lastId);
if (lastEntity == null) throw new BizException("主题未找到,id:" + lastId);
queryWrapper.lt(ThemeEntity::getUpdateTime, lastEntity.getCreateTime());
}
if (pageSize!=null){
queryWrapper.last("limit "+pageSize);
if (pageSize != null) {
queryWrapper.last("limit " + pageSize);
}
return themeMapper.selectList(queryWrapper);
}
......@@ -93,28 +96,29 @@ public class ThemeService {
}
//分页倒叙lastId之前的主题
public List<ThemeEntity> selectAll(String lastId,Integer pageSize) {
public List<ThemeEntity> selectAll(String lastId, Integer pageSize) {
LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>();
if (StringUtils.isNotEmpty(lastId)) {
ThemeEntity lastEntity = queryByThemeId(lastId);
if (lastEntity==null) throw new BizException("主题未找到,id:"+lastId);
if (lastEntity == null) throw new BizException("主题未找到,id:" + lastId);
queryWrapper.lt(ThemeEntity::getUpdateTime, lastEntity.getCreateTime());
}
queryWrapper.last("limit "+pageSize);
queryWrapper.last("limit " + pageSize);
queryWrapper.orderByDesc(ThemeEntity::getId);
queryWrapper.orderByDesc(ThemeEntity::getCreateTime);
queryWrapper.eq(ThemeEntity::getDeleteTag,DeleteTagEnum.NOT_DELETED.getCode());
queryWrapper.eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode());
return themeMapper.selectList(queryWrapper);
}
/**
* 根据条件查询最新主题
* @param topidId 话题Id
* @param lastId 查询此主题Id之前的主题
*
* @param topidId 话题Id
* @param lastId 查询此主题Id之前的主题
* @param pageSize 查询数量
* @return
*/
......@@ -123,20 +127,20 @@ public class ThemeService {
.eq(ThemeEntity::getTopicId, topidId);
if (StringUtils.isNotEmpty(lastId)) {
ThemeEntity lastEntity = queryByThemeId(lastId);
if (lastEntity==null) throw new BizException("主题未找到,id:"+lastId);
if (lastEntity == null) throw new BizException("主题未找到,id:" + lastId);
queryWrapper.lt(ThemeEntity::getUpdateTime, lastEntity.getCreateTime());
}
if (pageSize!=null){
queryWrapper.last("limit "+pageSize);
if (pageSize != null) {
queryWrapper.last("limit " + pageSize);
}
queryWrapper.orderByDesc(ThemeEntity::getCreateTime);
queryWrapper.eq(ThemeEntity::getDeleteTag,DeleteTagEnum.NOT_DELETED.getCode());
queryWrapper.eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode());
return themeMapper.selectList(queryWrapper);
}
//根据话题查询所有的主题Id
public List<String> queryThemeIdsByTopic(String topidId) {
if(StringUtils.isEmpty(topidId)){
if (StringUtils.isEmpty(topidId)) {
return Collections.emptyList();
}
LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>()
......@@ -152,12 +156,12 @@ public class ThemeService {
.in(ThemeEntity::getAuthorId, userIds);
if (StringUtils.isNotEmpty(lastId)) {
ThemeEntity lastEntity = queryByThemeId(lastId);
if (lastEntity==null) throw new BizException("主题未找到,id:"+lastId);
if (lastEntity == null) throw new BizException("主题未找到,id:" + lastId);
queryWrapper.lt(ThemeEntity::getUpdateTime, lastEntity.getCreateTime());
}
queryWrapper.last("limit "+pageSize);
queryWrapper.last("limit " + pageSize);
queryWrapper.orderByDesc(ThemeEntity::getCreateTime);
queryWrapper.eq(ThemeEntity::getDeleteTag,DeleteTagEnum.NOT_DELETED.getCode());
queryWrapper.eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode());
return themeMapper.selectList(queryWrapper);
}
......@@ -176,7 +180,7 @@ public class ThemeService {
.eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED));
}
public Integer getForwardCountByUser(String themeId,String userId) {
public Integer getForwardCountByUser(String themeId, String userId) {
return themeMapper.selectCount(new LambdaQueryWrapper<ThemeEntity>()
.eq(ThemeEntity::getFormerThemeId, themeId)
.eq(ThemeEntity::getAuthorId, userId)
......@@ -187,12 +191,29 @@ public class ThemeService {
public void deleteById(String themeId) {
ThemeEntity themeEntity = themeMapper.selectOne(new LambdaQueryWrapper<ThemeEntity>()
.eq(ThemeEntity::getThemeId, themeId));
if (themeEntity==null){
throw new BizException("主题未找到,id:"+themeId);
if (themeEntity == null) {
throw new BizException("主题未找到,id:" + themeId);
}
themeEntity.setDeleteTag(DeleteTagEnum.DELETED.getCode());
themeMapper.updateById(themeEntity);
}
/**
* 查询更新节点后的用户新建主题数
* @param userIds 用户ids
* @param lastViewTime 更新时间节点
* @return
*/
public Integer queryCountFromLastTime(List<String> userIds, LocalDateTime lastViewTime) {
if (CollectionUtils.isEmpty(userIds)) {
return 0;
}
LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>()
.in(ThemeEntity::getAuthorId, userIds)
.eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode());
if (lastViewTime != null) {
queryWrapper.gt(ThemeEntity::getCreateTime, lastViewTime);
}
return themeMapper.selectCount(queryWrapper);
}
}
......@@ -5,10 +5,12 @@ import com.tanpu.community.api.enums.VisitTypeEnum;
import com.tanpu.community.dao.entity.community.VisitSummaryEntity;
import com.tanpu.community.dao.mapper.community.VisitSummaryMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;
@Slf4j
......@@ -31,25 +33,37 @@ public class VisitSummaryService {
public Integer queryTopicDetailVisit(String topicId) {
return visitSummaryMapper.selectCount(new LambdaQueryWrapper<VisitSummaryEntity>()
.eq(VisitSummaryEntity::getRefId, topicId)
.eq(VisitSummaryEntity::getRefType,VisitTypeEnum.TOPIC_PAGE_VIEW.getCode()));
.eq(VisitSummaryEntity::getRefType, VisitTypeEnum.TOPIC_PAGE_VIEW.getCode()));
}
// 查询主题 浏览量
public Integer queryThemeVisit(String theme) {
return visitSummaryMapper.selectCount(new LambdaQueryWrapper<VisitSummaryEntity>()
.eq(VisitSummaryEntity::getRefId, theme)
.eq(VisitSummaryEntity::getRefType,VisitTypeEnum.TOPIC_PAGE_VIEW.getCode()));
.eq(VisitSummaryEntity::getRefType, VisitTypeEnum.TOPIC_PAGE_VIEW.getCode()));
}
// 查询主题 浏览量
public Integer queryThemeVisit(List<String> themes) {
return visitSummaryMapper.selectCount(new LambdaQueryWrapper<VisitSummaryEntity>()
.in(VisitSummaryEntity::getRefId, themes)
.eq(VisitSummaryEntity::getRefType,VisitTypeEnum.TOPIC_PAGE_VIEW.getCode()));
.eq(VisitSummaryEntity::getRefType, VisitTypeEnum.TOPIC_PAGE_VIEW.getCode()));
}
// 更新访问时长
public void updateDurByIdent(String ident, Integer dur) {
// visitSummaryMapper.updateDurByIdent(ident, dur);
}
public LocalDateTime queryLatestViewFollow(String userId) {
List<VisitSummaryEntity> visitSummaryEntities = visitSummaryMapper.selectList(new LambdaQueryWrapper<VisitSummaryEntity>()
.eq(VisitSummaryEntity::getVisitorId, userId)
.eq(VisitSummaryEntity::getRefType, VisitTypeEnum.FOLLOW_THEME_VIEW.getCode())
.orderByDesc(VisitSummaryEntity::getCreateTime));
if (CollectionUtils.isEmpty(visitSummaryEntities)) {
return null;
} else {
return visitSummaryEntities.get(0).getCreateTime();
}
}
}
......@@ -11,9 +11,7 @@
<result column="ref_id" property="refId" />
<result column="ref_type" property="refType" />
<result column="duration" property="duration" />
<result column="create_by" property="createBy" />
<result column="create_time" property="createTime" />
<result column="update_by" property="updateBy" />
<result column="update_time" property="updateTime" />
<result column="delete_tag" property="deleteTag" />
</resultMap>
......
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