Commit 0d01a7c1 authored by 吴泽佳's avatar 吴泽佳

Merge branch 'dev' of http://47.100.44.39:10001/tp-backend/tanpu-community into dev

# Conflicts:
#	community-service/src/main/java/com/tanpu/community/feign/tanpuroom/FeignClientForTanpuroom.java
parents 4764b0f0 7a705037
...@@ -11,9 +11,6 @@ import java.util.List; ...@@ -11,9 +11,6 @@ import java.util.List;
@ApiModel("评论对象") @ApiModel("评论对象")
public class CommentQo { public class CommentQo {
@ApiModelProperty(value = "id")
private Integer id;
@ApiModelProperty(value = "uuid") @ApiModelProperty(value = "uuid")
private String commentId; private String commentId;
......
...@@ -2,24 +2,23 @@ package com.tanpu.community.api.beans.qo; ...@@ -2,24 +2,23 @@ package com.tanpu.community.api.beans.qo;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ThemeAnalysDO { public class ThemeAnalysDO {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "UUID") @ApiModelProperty(value = "主题Id")
private String themeId; private String themeId;
@ApiModelProperty(value = "标题")
private String title;
@ApiModelProperty(value = "类型")
private Integer themeType;
@ApiModelProperty(value = "文本内容")
private String content;
@ApiModelProperty(value = "作者id") @ApiModelProperty(value = "作者id")
private String authorId; private String authorId;
...@@ -38,7 +37,21 @@ public class ThemeAnalysDO { ...@@ -38,7 +37,21 @@ public class ThemeAnalysDO {
@ApiModelProperty(value = "点赞量") @ApiModelProperty(value = "点赞量")
private Integer likeCount; private Integer likeCount;
@ApiModelProperty(value = "收藏量")
private Integer collectCount;
@ApiModelProperty(value = "收藏量")
private Integer viewCount;
@ApiModelProperty(value = "距今时间") @ApiModelProperty(value = "距今时间")
private Long timeTillNow; private Long minuteTillNow;
public Double getRank(){
double p = (double) (viewCount + forwardCount + commentCount + likeCount + collectCount);
double t = Double.valueOf(minuteTillNow);
double g =1.8;
double rank=(p)/Math.pow(t+2,g);
return rank;
}
} }
...@@ -28,6 +28,6 @@ public class TopicHotQo { ...@@ -28,6 +28,6 @@ public class TopicHotQo {
* @return * @return
*/ */
public Integer getRank(){ public Integer getRank(){
return this.viewCount+this.disscussCount*5; return this.viewCount+this.disscussCount*3;
} }
} }
package com.tanpu.community.api.enums;
public enum StatusEnum {
TRUE(1,true),FALSE(0,false);
private Integer code;
private boolean status;
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public boolean isStatus() {
return status;
}
public void setStatus(boolean status) {
this.status = status;
}
StatusEnum(Integer code, boolean status) {
this.code = code;
this.status = status;
}
}
...@@ -2,10 +2,16 @@ package com.tanpu.community.api.enums; ...@@ -2,10 +2,16 @@ package com.tanpu.community.api.enums;
public enum TopicStatusEnum { public enum TopicStatusEnum {
TRUE(1,true),FALSE(0,false); HOTTEST(1,"最热"),
NEWEST(2,"最新");;
private Integer code; private Integer code;
private boolean status; private String type;
TopicStatusEnum(Integer code, String type) {
this.code = code;
this.type = type;
}
public Integer getCode() { public Integer getCode() {
return code; return code;
...@@ -15,18 +21,11 @@ public enum TopicStatusEnum { ...@@ -15,18 +21,11 @@ public enum TopicStatusEnum {
this.code = code; this.code = code;
} }
public boolean isStatus() { public String getType() {
return status; return type;
}
public void setStatus(boolean status) {
this.status = status;
} }
TopicStatusEnum(Integer code, boolean status) { public void setType(String type) {
this.code = code; this.type = type;
this.status = status;
} }
} }
...@@ -145,4 +145,12 @@ public class ThemeController { ...@@ -145,4 +145,12 @@ public class ThemeController {
return CommonResp.success(themeManager.getFollowUpdateCount(userId)); return CommonResp.success(themeManager.getFollowUpdateCount(userId));
} }
} @AuthLogin
@ApiOperation("关注主题更新数量")
@GetMapping(value = "/test")
@ResponseBody
public CommonResp<String> test() {
return CommonResp.success("");
}
}
package com.tanpu.community.manager; package com.tanpu.community.manager;
import com.tanpu.community.service.RankService;
import com.tanpu.community.service.RedisService; import com.tanpu.community.service.RedisService;
import com.tanpu.community.service.VisitSummaryService; import com.tanpu.community.service.VisitSummaryService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -21,6 +20,9 @@ public class ConJobManager { ...@@ -21,6 +20,9 @@ public class ConJobManager {
@Autowired @Autowired
private RedisService redisService; private RedisService redisService;
@Autowired
private RankService rankService;
/** /**
* 定时统计 话题 访问数据,并刷到redis * 定时统计 话题 访问数据,并刷到redis
*/ */
...@@ -30,4 +32,12 @@ public class ConJobManager { ...@@ -30,4 +32,12 @@ public class ConJobManager {
Integer detailVisitTimes = visitSummaryService.queryTopicDetailVisit(topicId); Integer detailVisitTimes = visitSummaryService.queryTopicDetailVisit(topicId);
redisService.set("topicVisitorStats", detailVisitTimes); redisService.set("topicVisitorStats", detailVisitTimes);
} }
/**
* 定时统计主题排行
*/
@Scheduled(cron = "0 */2 * * * ?")
public void themeRank() {
rankService.rankThemes();
}
} }
...@@ -2,27 +2,18 @@ package com.tanpu.community.manager; ...@@ -2,27 +2,18 @@ package com.tanpu.community.manager;
import com.tanpu.common.exception.BizException; import com.tanpu.common.exception.BizException;
import com.tanpu.common.util.JsonUtil; import com.tanpu.common.util.JsonUtil;
import com.tanpu.community.api.beans.qo.ESThemeQo; import com.tanpu.community.api.beans.qo.*;
import com.tanpu.community.api.beans.qo.FormerThemeQo;
import com.tanpu.community.api.beans.qo.ThemeContentQo;
import com.tanpu.community.api.beans.qo.ThemeQo;
import com.tanpu.community.api.beans.req.homepage.QueryRecordThemeReq; import com.tanpu.community.api.beans.req.homepage.QueryRecordThemeReq;
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.api.enums.*; import com.tanpu.community.api.enums.*;
import com.tanpu.community.api.enums.BlockTypeEnum;
import com.tanpu.community.api.enums.CollectionTypeEnum;
import com.tanpu.community.api.enums.ThemeListTypeEnum;
import com.tanpu.community.api.enums.ThemeTypeEnum;
import com.tanpu.community.cache.CacheGet; import com.tanpu.community.cache.CacheGet;
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.service.*; import com.tanpu.community.service.*;
import com.tanpu.community.service.BlackListService;
import com.tanpu.community.service.base.ESService; import com.tanpu.community.service.base.ESService;
import com.tanpu.community.util.ConvertUtil; import com.tanpu.community.util.ConvertUtil;
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.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -63,6 +54,9 @@ public class ThemeManager { ...@@ -63,6 +54,9 @@ public class ThemeManager {
@Autowired @Autowired
private VisitSummaryService visitSummaryService; private VisitSummaryService visitSummaryService;
@Autowired
private RankService rankService;
@Autowired @Autowired
private ESService esService; private ESService esService;
...@@ -91,7 +85,6 @@ public class ThemeManager { ...@@ -91,7 +85,6 @@ public class ThemeManager {
themeEntity.setContent(JsonUtil.toJson(req.getContent())); themeEntity.setContent(JsonUtil.toJson(req.getContent()));
if (StringUtils.isEmpty(req.getEditThemeId())) { if (StringUtils.isEmpty(req.getEditThemeId())) {
//新建 //新建
themeService.insertTheme(themeEntity); themeService.insertTheme(themeEntity);
...@@ -109,12 +102,12 @@ public class ThemeManager { ...@@ -109,12 +102,12 @@ public class ThemeManager {
themeAttachmentService.insertList(themeAttachments); themeAttachmentService.insertList(themeAttachments);
return CreateThemeResp.builder().themeId(themeEntity.getThemeId()).build(); return CreateThemeResp.builder().themeId(themeEntity.getThemeId()).build();
} }
/** /**
* 返回主题列表 * 返回主题列表
*
* @param req * @param req
* @param userId * @param userId
* @return * @return
...@@ -123,10 +116,10 @@ public class ThemeManager { ...@@ -123,10 +116,10 @@ public class ThemeManager {
List<ThemeEntity> themeEntities = new ArrayList<>(); List<ThemeEntity> themeEntities = new ArrayList<>();
if (ThemeListTypeEnum.RECOMMEND.getCode().equals(req.getType())) { if (ThemeListTypeEnum.RECOMMEND.getCode().equals(req.getType())) {
// TODO:推荐 // TODO:推荐
themeEntities = themeService.selectExcludeUser(userId,req.getLastId(), req.getPageSize()); // themeEntities = themeService.selectExcludeUser(userId, req.getLastId(), req.getPageSize());
Set<String> recomondThemeIds; List<String> recommendThemeIds = rankService.getHotAndNewThemes(100, 100);
Set<String> hotThemeIds; themeEntities = themeService.queryByThemeIdsExcludeUser( recommendThemeIds,userId, req.getLastId(), req.getPageSize());
Set<String> newThemeIds;
} else if (ThemeListTypeEnum.FOLLOW.getCode().equals(req.getType())) { } else if (ThemeListTypeEnum.FOLLOW.getCode().equals(req.getType())) {
//根据关注列表查询 //根据关注列表查询
List<String> fansList = followRelService.queryFansByFollowerId(userId); List<String> fansList = followRelService.queryFansByFollowerId(userId);
...@@ -147,7 +140,7 @@ public class ThemeManager { ...@@ -147,7 +140,7 @@ public class ThemeManager {
public List<ThemeQo> searchThemes(ThemeSearchReq req, String userId) { public List<ThemeQo> searchThemes(ThemeSearchReq req, String userId) {
List<ThemeEntity> themeEntities= themeService.search(req.getKeyword(),req.getLastId(), req.getPageSize()); List<ThemeEntity> themeEntities = themeService.search(req.getKeyword(), req.getLastId(), req.getPageSize());
return convertEntityToQo(themeEntities, userId); return convertEntityToQo(themeEntities, userId);
} }
...@@ -333,7 +326,7 @@ public class ThemeManager { ...@@ -333,7 +326,7 @@ public class ThemeManager {
Integer forwardCountByUser = themeService.getForwardCountByUser(themeId, userId); Integer forwardCountByUser = themeService.getForwardCountByUser(themeId, userId);
themeQo.setHasForward(forwardCountByUser > 0); themeQo.setHasForward(forwardCountByUser > 0);
//是否收藏 //是否收藏
CollectionEntity collectionEntity = collectionService.getNotDeleteTargetCollection(themeId, userId, CollectionTypeEnum.COLLECT_THEME); CollectionEntity collectionEntity = collectionService.getNotDeleteTargetCollection(themeId, userId, CollectionTypeEnum.COLLECT_THEME);
themeQo.setHasCollect(collectionEntity != null); themeQo.setHasCollect(collectionEntity != null);
//点赞,收藏,转发 //点赞,收藏,转发
Integer likeCount = collectionService.getCountByTypeAndId(themeId, CollectionTypeEnum.LIKE_THEME); Integer likeCount = collectionService.getCountByTypeAndId(themeId, CollectionTypeEnum.LIKE_THEME);
...@@ -378,4 +371,6 @@ public class ThemeManager { ...@@ -378,4 +371,6 @@ public class ThemeManager {
List<String> fansList = followRelService.queryFansByFollowerId(userId); List<String> fansList = followRelService.queryFansByFollowerId(userId);
return themeService.queryCountFromLastTime(fansList, lastViewTime); return themeService.queryCountFromLastTime(fansList, lastViewTime);
} }
} }
package com.tanpu.community.manager; package com.tanpu.community.manager;
import com.tanpu.common.exception.BizException; import com.tanpu.common.exception.BizException;
import com.tanpu.community.api.beans.vo.TopicDTO;
import com.tanpu.community.api.beans.vo.TopicDataAnalysDTO;
import com.tanpu.community.api.beans.qo.TopicDetailQo; import com.tanpu.community.api.beans.qo.TopicDetailQo;
import com.tanpu.community.api.beans.qo.TopicHotQo; import com.tanpu.community.api.beans.qo.TopicHotQo;
import com.tanpu.community.api.beans.qo.TopicTitileQo; import com.tanpu.community.api.beans.qo.TopicTitileQo;
import com.tanpu.community.api.beans.req.page.Page; import com.tanpu.community.api.beans.req.page.Page;
import com.tanpu.community.api.beans.req.topic.TopicSearchReq; import com.tanpu.community.api.beans.req.topic.TopicSearchReq;
import com.tanpu.community.api.beans.vo.TopicDTO;
import com.tanpu.community.api.beans.vo.TopicDataAnalysDTO;
import com.tanpu.community.api.constants.RedisKeyConstant; import com.tanpu.community.api.constants.RedisKeyConstant;
import com.tanpu.community.api.enums.CollectionTypeEnum; import com.tanpu.community.api.enums.CollectionTypeEnum;
import com.tanpu.community.dao.entity.community.TopicEntity; import com.tanpu.community.dao.entity.community.TopicEntity;
...@@ -22,7 +22,6 @@ import org.springframework.stereotype.Service; ...@@ -22,7 +22,6 @@ import org.springframework.stereotype.Service;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors;
@Service @Service
public class TopicManager { public class TopicManager {
...@@ -44,6 +43,8 @@ public class TopicManager { ...@@ -44,6 +43,8 @@ public class TopicManager {
@Autowired @Autowired
private VisitSummaryService visitSummaryService; private VisitSummaryService visitSummaryService;
@Autowired
private RankService rankService;
//新增话题 //新增话题
public void insertTopic(String topicTitle, String userId) { public void insertTopic(String topicTitle, String userId) {
...@@ -106,25 +107,26 @@ public class TopicManager { ...@@ -106,25 +107,26 @@ public class TopicManager {
public List<TopicHotQo> getHotTopicTitles() { public List<TopicHotQo> getHotTopicTitles() {
List<TopicEntity> topicEntities = topicService.queryAll(); // List<TopicEntity> topicEntities = topicService.queryAll();
List<TopicHotQo> topicHotQos = ConvertUtil.topicEntityToHotQos(topicEntities); // List<TopicHotQo> topicHotQos = ConvertUtil.topicEntityToHotQos(topicEntities);
for (TopicHotQo topic : topicHotQos) { // for (TopicHotQo topic : topicHotQos) {
List<String> themeIds = themeService.queryThemeIdsByTopic(topic.getTopicId()); // List<String> themeIds = themeService.queryThemeIdsByTopic(topic.getTopicId());
//浏览量 // //浏览量
Integer topicPV = visitSummaryService.queryTopicDetailVisit(topic.getTopicId()); // Integer topicPV = visitSummaryService.queryTopicDetailVisit(topic.getTopicId());
Integer themePV = visitSummaryService.queryThemeVisit(themeIds); // Integer themePV = visitSummaryService.queryThemeVisit(themeIds);
topic.setViewCount(topicPV + themePV); // topic.setViewCount(topicPV + themePV);
//讨论数=发布主题贴数+回复总数 // //讨论数=发布主题贴数+回复总数
Integer commentCount = commentService.getCommentCountByThemeIds(themeIds); // Integer commentCount = commentService.getCommentCountByThemeIds(themeIds);
topic.setDisscussCount(themeIds.size() + commentCount); // topic.setDisscussCount(themeIds.size() + commentCount);
} // }
topicHotQos.stream().collect(Collectors.toMap(TopicHotQo::getRank, o->o)); // Map<TopicHotQo, Integer> map = topicHotQos.stream().collect(Collectors.toMap(o -> o, TopicHotQo::getRank));
// map.entrySet().stream().sorted(Comparator.)
//TODO 添加类型:热 新 顶 //
topicHotQos.get(0).setType(1); // //TODO 添加类型:热 新 顶
topicHotQos.get(2).setType(2); // topicHotQos.get(0).setType(1);
return topicHotQos; // topicHotQos.get(2).setType(2);
// return topicHotQos;
return rankService.rankTopics();
} }
public void setTopTopic(String topicId, boolean setTop) { public void setTopTopic(String topicId, boolean setTop) {
......
...@@ -5,7 +5,7 @@ import com.tanpu.common.exception.BizException; ...@@ -5,7 +5,7 @@ import com.tanpu.common.exception.BizException;
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.TopicStatusEnum; import com.tanpu.community.api.enums.StatusEnum;
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;
...@@ -66,7 +66,7 @@ public class CommentService { ...@@ -66,7 +66,7 @@ public class CommentService {
LambdaQueryWrapper<CommentEntity> queryWrapper = new LambdaQueryWrapper<CommentEntity>() LambdaQueryWrapper<CommentEntity> queryWrapper = new LambdaQueryWrapper<CommentEntity>()
.eq(CommentEntity::getThemeId, themeId) .eq(CommentEntity::getThemeId, themeId)
.eq(CommentEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode()) .eq(CommentEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode())
.eq(CommentEntity::getIsBlock, TopicStatusEnum.FALSE.getCode()) .eq(CommentEntity::getIsBlock, StatusEnum.FALSE.getCode())
.orderByDesc(CommentEntity::getCreateTime); .orderByDesc(CommentEntity::getCreateTime);
if (parentId == null) { if (parentId == null) {
queryWrapper.isNull(CommentEntity::getParentId); queryWrapper.isNull(CommentEntity::getParentId);
......
package com.tanpu.community.service;
import com.tanpu.community.api.beans.qo.ThemeAnalysDO;
import com.tanpu.community.api.beans.qo.TopicHotQo;
import com.tanpu.community.api.enums.CollectionTypeEnum;
import com.tanpu.community.api.enums.TopicStatusEnum;
import com.tanpu.community.dao.entity.community.ThemeEntity;
import com.tanpu.community.dao.entity.community.TopicEntity;
import com.tanpu.community.util.ConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.stream.Collectors;
@Service
public class RankService {
@Autowired
private ThemeService themeService;
@Autowired
private CollectionService collectionService;
@Autowired
private CommentService commentService;
@Autowired
private TopicService topicService;
@Autowired
private VisitSummaryService visitSummaryService;
public List<String> rankThemeList=new ArrayList<>();
public void rankThemes() {
List<ThemeEntity> themeEntities = themeService.queryAll();
List<ThemeAnalysDO> themeAnalysDOS = ConvertUtil.themeEntityToAnalysDOs(themeEntities);
for (ThemeAnalysDO theme : themeAnalysDOS) {
String themeId = theme.getThemeId();
Integer likeCount = collectionService.getCountByTypeAndId(themeId, CollectionTypeEnum.LIKE_THEME);
Integer bookCount = collectionService.getCountByTypeAndId(themeId, CollectionTypeEnum.COLLECT_THEME);
Integer commentCount = commentService.getCommentCountByThemeId(themeId);
Integer forwardCount = themeService.getForwardCountById(themeId);
Integer viewCount = visitSummaryService.queryThemeVisit(themeId);
theme.setCommentCount(commentCount);
theme.setLikeCount(likeCount);
theme.setForwardCount(forwardCount);
theme.setCollectCount(bookCount);
theme.setViewCount(viewCount);
}
Map<ThemeAnalysDO, Double> map = themeAnalysDOS.stream().collect(Collectors.toMap(o -> o, ThemeAnalysDO::getRank));
rankThemeList = map.entrySet().stream().sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())).map(e -> e.getKey().getThemeId()).collect(Collectors.toList());
}
public List<TopicHotQo> rankTopics() {
List<TopicEntity> topicEntities = topicService.queryAll();
List<TopicHotQo> topicHotQos = ConvertUtil.topicEntityToHotQos(topicEntities);
if (topicHotQos.size() == 0) {
return topicHotQos;
}
TopicHotQo lastTopic = topicHotQos.get(0);
lastTopic.setType(TopicStatusEnum.NEWEST.getCode());
for (TopicHotQo topic : topicHotQos) {
List<String> themeIds = themeService.queryThemeIdsByTopic(topic.getTopicId());
//浏览量
Integer topicPV = visitSummaryService.queryTopicDetailVisit(topic.getTopicId());
Integer themePV = visitSummaryService.queryThemeVisit(themeIds);
topic.setViewCount(topicPV + themePV);
//讨论数=发布主题贴数+回复总数
Integer commentCount = commentService.getCommentCountByThemeIds(themeIds);
topic.setDisscussCount(themeIds.size() + commentCount);
}
Map<TopicHotQo, Integer> map = topicHotQos.stream().collect(Collectors.toMap(o -> o, TopicHotQo::getRank));
List<TopicHotQo> rankList = map.entrySet().stream().sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())).map(e -> e.getKey()).collect(Collectors.toList());
rankList.get(0).setType(TopicStatusEnum.HOTTEST.getCode());
Set<TopicHotQo> resultSet = rankList.stream().limit(4).collect(Collectors.toSet());
resultSet.add(lastTopic);
return new ArrayList<>(resultSet);
}
public List<String> getHotAndNewThemes(Integer hotCount,Integer newCount){
Set<String> hotThemeIds=this.rankThemeList.stream().limit(hotCount).collect(Collectors.toSet());
Set<String> newThemeIds = themeService.selectExcludeUser(null, null, newCount)
.stream().map(ThemeEntity::getThemeId).collect(Collectors.toSet());
hotThemeIds.addAll(newThemeIds);
return new ArrayList<>(hotThemeIds);
}
}
...@@ -40,6 +40,17 @@ public class ThemeService { ...@@ -40,6 +40,17 @@ public class ThemeService {
themeMapper.update(themeEntity, new LambdaUpdateWrapper<ThemeEntity>().eq(ThemeEntity::getThemeId, themeId)); themeMapper.update(themeEntity, new LambdaUpdateWrapper<ThemeEntity>().eq(ThemeEntity::getThemeId, themeId));
} }
/**
* 根据主题Id查询列表
* @return
*/
public List<ThemeEntity> queryAll() {
LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>()
.eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode());
return themeMapper.selectList(queryWrapper);
}
//根据id返回主题详情(未删) //根据id返回主题详情(未删)
public ThemeEntity queryByThemeId(String themeId) { public ThemeEntity queryByThemeId(String themeId) {
return themeMapper.selectOne(new LambdaQueryWrapper<ThemeEntity>() return themeMapper.selectOne(new LambdaQueryWrapper<ThemeEntity>()
...@@ -72,6 +83,9 @@ public class ThemeService { ...@@ -72,6 +83,9 @@ public class ThemeService {
//根据ids返回主题详情,带分页 //根据ids返回主题详情,带分页
public List<ThemeEntity> queryByThemeIds(List<String> themeIds, String lastId, Integer pageSize) { public List<ThemeEntity> queryByThemeIds(List<String> themeIds, String lastId, Integer pageSize) {
if (CollectionUtils.isEmpty(themeIds)){
return Collections.emptyList();
}
LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>() LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>()
.in(ThemeEntity::getThemeId, themeIds) .in(ThemeEntity::getThemeId, themeIds)
.eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode()); .eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode());
...@@ -86,8 +100,15 @@ public class ThemeService { ...@@ -86,8 +100,15 @@ public class ThemeService {
return themeMapper.selectList(queryWrapper); return themeMapper.selectList(queryWrapper);
} }
//根据ids返回主题详情 /**
* 根据主题Id查询列表
* @param themeIds
* @return
*/
public List<ThemeEntity> queryByThemeIds(List<String> themeIds) { public List<ThemeEntity> queryByThemeIds(List<String> themeIds) {
if (CollectionUtils.isEmpty(themeIds)){
return Collections.emptyList();
}
LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>() LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>()
.in(ThemeEntity::getThemeId, themeIds) .in(ThemeEntity::getThemeId, themeIds)
.eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode()); .eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode());
...@@ -95,8 +116,10 @@ public class ThemeService { ...@@ -95,8 +116,10 @@ public class ThemeService {
return themeMapper.selectList(queryWrapper); return themeMapper.selectList(queryWrapper);
} }
/** /**
* 分页查询,非当前用户的主题 * 查询非传入作者的主题(可分页)
* @param lastId * @param lastId
* @param pageSize * @param pageSize
* @param userId * @param userId
...@@ -113,8 +136,10 @@ public class ThemeService { ...@@ -113,8 +136,10 @@ public class ThemeService {
if (lastEntity == null) throw new BizException("主题未找到,id:" + lastId); if (lastEntity == null) throw new BizException("主题未找到,id:" + lastId);
queryWrapper.lt(ThemeEntity::getUpdateTime, lastEntity.getCreateTime()); queryWrapper.lt(ThemeEntity::getUpdateTime, lastEntity.getCreateTime());
} }
if (pageSize!=null){
queryWrapper.last("limit " + pageSize);
}
queryWrapper.last("limit " + pageSize);
queryWrapper.orderByDesc(ThemeEntity::getId); queryWrapper.orderByDesc(ThemeEntity::getId);
queryWrapper.orderByDesc(ThemeEntity::getCreateTime); queryWrapper.orderByDesc(ThemeEntity::getCreateTime);
queryWrapper.eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode()); queryWrapper.eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode());
...@@ -122,7 +147,39 @@ public class ThemeService { ...@@ -122,7 +147,39 @@ public class ThemeService {
} }
/** /**
* 根据条件查询最新主题 * 查询非传入作者的主题(可分页)
* @param lastId
* @param pageSize
* @param userId
* @return
*/
public List<ThemeEntity> queryByThemeIdsExcludeUser(List<String> themeIds,String userId,String lastId, Integer pageSize) {
if (CollectionUtils.isEmpty(themeIds)){
return Collections.emptyList();
}
LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>()
.in(ThemeEntity::getThemeId, themeIds);
if (!StringUtils.isEmpty(userId)){
queryWrapper.ne(ThemeEntity::getAuthorId,userId);
}
if (StringUtils.isNotEmpty(lastId)) {
ThemeEntity lastEntity = queryByThemeId(lastId);
if (lastEntity == null) throw new BizException("主题未找到,id:" + lastId);
queryWrapper.lt(ThemeEntity::getUpdateTime, lastEntity.getCreateTime());
}
if (pageSize!=null){
queryWrapper.last("limit " + pageSize);
}
queryWrapper.orderByDesc(ThemeEntity::getId);
queryWrapper.orderByDesc(ThemeEntity::getCreateTime);
queryWrapper.eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode());
return themeMapper.selectList(queryWrapper);
}
/**
* 根据话题查询最新主题(可分页)
* *
* @param topidId 话题Id * @param topidId 话题Id
* @param lastId 查询此主题Id之前的主题 * @param lastId 查询此主题Id之前的主题
...@@ -157,7 +214,13 @@ public class ThemeService { ...@@ -157,7 +214,13 @@ public class ThemeService {
} }
//关注的主题列表 /**
* 根据作者查询主题列表(可分页)
* @param userIds
* @param lastId
* @param pageSize
* @return
*/
public List<ThemeEntity> queryByUserIds(List<String> userIds, String lastId, Integer pageSize) { public List<ThemeEntity> queryByUserIds(List<String> userIds, String lastId, Integer pageSize) {
LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>() LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>()
.in(ThemeEntity::getAuthorId, userIds); .in(ThemeEntity::getAuthorId, userIds);
......
...@@ -4,7 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; ...@@ -4,7 +4,7 @@ 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.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.TopicStatusEnum; import com.tanpu.community.api.enums.StatusEnum;
import com.tanpu.community.dao.entity.community.TopicEntity; import com.tanpu.community.dao.entity.community.TopicEntity;
import com.tanpu.community.dao.mapper.community.TopicMapper; import com.tanpu.community.dao.mapper.community.TopicMapper;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
...@@ -30,13 +30,15 @@ public class TopicService { ...@@ -30,13 +30,15 @@ public class TopicService {
public List<TopicEntity> queryAll() { public List<TopicEntity> queryAll() {
return topicMapper.selectList(new LambdaQueryWrapper<TopicEntity>() return topicMapper.selectList(new LambdaQueryWrapper<TopicEntity>()
.eq(TopicEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode())); .eq(TopicEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode())
.orderByDesc(TopicEntity::getCreateTime));
} }
public List<TopicEntity> queryByKeyword(String keyword) { public List<TopicEntity> queryByKeyword(String keyword) {
return topicMapper.selectList(new LambdaQueryWrapper<TopicEntity>() return topicMapper.selectList(new LambdaQueryWrapper<TopicEntity>()
.like(TopicEntity::getTopicTitle,keyword) .like(TopicEntity::getTopicTitle, keyword)
.eq(TopicEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode())); .eq(TopicEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode())
.orderByDesc(TopicEntity::getCreateTime));
} }
@Transactional @Transactional
...@@ -44,8 +46,8 @@ public class TopicService { ...@@ -44,8 +46,8 @@ public class TopicService {
TopicEntity entity = TopicEntity.builder() TopicEntity entity = TopicEntity.builder()
.topicId(uuidGenHelper.getUuidStr()) .topicId(uuidGenHelper.getUuidStr())
.topicTitle(topicTitle) .topicTitle(topicTitle)
.isTop(TopicStatusEnum.FALSE.getCode()) .isTop(StatusEnum.FALSE.getCode())
.isConceal(TopicStatusEnum.FALSE.getCode()) .isConceal(StatusEnum.FALSE.getCode())
.build(); .build();
topicMapper.insert(entity); topicMapper.insert(entity);
...@@ -54,41 +56,41 @@ public class TopicService { ...@@ -54,41 +56,41 @@ public class TopicService {
public void updateTopicToTop(String topicId) { public void updateTopicToTop(String topicId) {
TopicEntity topicEntity = new TopicEntity(); TopicEntity topicEntity = new TopicEntity();
topicEntity.setIsTop(TopicStatusEnum.TRUE.getCode()); topicEntity.setIsTop(StatusEnum.TRUE.getCode());
topicMapper.update(topicEntity, new LambdaUpdateWrapper<TopicEntity>() topicMapper.update(topicEntity, new LambdaUpdateWrapper<TopicEntity>()
.eq(TopicEntity::getId, topicId)); .eq(TopicEntity::getId, topicId));
} }
public void updateTopicNotTop(String topicId) { public void updateTopicNotTop(String topicId) {
TopicEntity topicEntity = new TopicEntity(); TopicEntity topicEntity = new TopicEntity();
topicEntity.setIsTop(TopicStatusEnum.FALSE.getCode()); topicEntity.setIsTop(StatusEnum.FALSE.getCode());
topicMapper.update(topicEntity, new LambdaUpdateWrapper<TopicEntity>() topicMapper.update(topicEntity, new LambdaUpdateWrapper<TopicEntity>()
.eq(TopicEntity::getId, topicId)); .eq(TopicEntity::getId, topicId));
} }
public void updateTopicToConceal(String topicId) { public void updateTopicToConceal(String topicId) {
TopicEntity topicEntity = new TopicEntity(); TopicEntity topicEntity = new TopicEntity();
topicEntity.setIsConceal(TopicStatusEnum.TRUE.getCode()); topicEntity.setIsConceal(StatusEnum.TRUE.getCode());
topicMapper.update(topicEntity, new LambdaUpdateWrapper<TopicEntity>() topicMapper.update(topicEntity, new LambdaUpdateWrapper<TopicEntity>()
.eq(TopicEntity::getId, topicId)); .eq(TopicEntity::getId, topicId));
} }
public void updateTopicNotConceal(String topicId) { public void updateTopicNotConceal(String topicId) {
TopicEntity topicEntity = new TopicEntity(); TopicEntity topicEntity = new TopicEntity();
topicEntity.setIsConceal(TopicStatusEnum.FALSE.getCode()); topicEntity.setIsConceal(StatusEnum.FALSE.getCode());
topicMapper.update(topicEntity, new LambdaUpdateWrapper<TopicEntity>() topicMapper.update(topicEntity, new LambdaUpdateWrapper<TopicEntity>()
.eq(TopicEntity::getId, topicId)); .eq(TopicEntity::getId, topicId));
} }
public TopicEntity queryById(String topicId) { public TopicEntity queryById(String topicId) {
return topicMapper.selectOne(new LambdaQueryWrapper<TopicEntity>().eq(TopicEntity::getTopicId,topicId)); return topicMapper.selectOne(new LambdaQueryWrapper<TopicEntity>().eq(TopicEntity::getTopicId, topicId));
} }
public List<TopicEntity> queryByIds(List<String> topicIds) { public List<TopicEntity> queryByIds(List<String> topicIds) {
if (CollectionUtils.isEmpty(topicIds)){ if (CollectionUtils.isEmpty(topicIds)) {
return Collections.emptyList(); return Collections.emptyList();
} }
return topicMapper.selectList(new LambdaQueryWrapper<TopicEntity>().in(TopicEntity::getTopicId,topicIds)); return topicMapper.selectList(new LambdaQueryWrapper<TopicEntity>().in(TopicEntity::getTopicId, topicIds));
} }
public void modifyViewCount(String topicId, long Count) { public void modifyViewCount(String topicId, long Count) {
......
...@@ -16,6 +16,7 @@ import org.springframework.beans.BeanUtils; ...@@ -16,6 +16,7 @@ import org.springframework.beans.BeanUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -57,19 +58,20 @@ public class ConvertUtil { ...@@ -57,19 +58,20 @@ public class ConvertUtil {
return themeQO; return themeQO;
} }
public static ThemeAnalysDO themeEntityToAnalysDO(ThemeEntity themeEntity) {
if (themeEntity == null) {
return null;
}
ThemeAnalysDO themeAnalysDO = new ThemeAnalysDO();
BeanUtils.copyProperties(themeEntity, themeAnalysDO);
themeAnalysDO.setMinuteTillNow(TimeUtil.calMinuteTillNow(themeEntity.getCreateTime()));
return themeAnalysDO;
}
public static ThemeEntity themeDTOToEntity(ThemeQo themeQO) { public static List<ThemeAnalysDO> themeEntityToAnalysDOs(List<ThemeEntity> themeEntities) {
ThemeEntity themeEntity = new ThemeEntity(); return themeEntities.stream().map(ConvertUtil::themeEntityToAnalysDO).collect(Collectors.toList());
BeanUtils.copyProperties(themeQO, themeEntity);
return themeEntity;
} }
/**
* 首页主题列表,限制附件个数为1(1文本+1附件)
*
* @param themeEntities
* @return
*/
public static List<ThemeQo> themeEntitiesToDTOs(List<ThemeEntity> themeEntities) { public static List<ThemeQo> themeEntitiesToDTOs(List<ThemeEntity> themeEntities) {
return themeEntities.stream().map(ConvertUtil::themeEntityToQo2).collect(Collectors.toList()); return themeEntities.stream().map(ConvertUtil::themeEntityToQo2).collect(Collectors.toList());
} }
...@@ -88,6 +90,9 @@ public class ConvertUtil { ...@@ -88,6 +90,9 @@ public class ConvertUtil {
} }
public static List<TopicHotQo> topicEntityToHotQos(List<TopicEntity> topicEntities) { public static List<TopicHotQo> topicEntityToHotQos(List<TopicEntity> topicEntities) {
if (topicEntities==null){
return Collections.emptyList();
}
return topicEntities.stream().map(ConvertUtil::topicEntityToHotQo).collect(Collectors.toList()); return topicEntities.stream().map(ConvertUtil::topicEntityToHotQo).collect(Collectors.toList());
} }
......
...@@ -35,4 +35,10 @@ public class TimeUtil { ...@@ -35,4 +35,10 @@ public class TimeUtil {
return start.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); return start.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
} }
//计算迄今时间
public static long calMinuteTillNow(LocalDateTime start) {
Duration between = Duration.between(start, LocalDateTime.now());
return between.toMinutes();
}
} }
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