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;
@ApiModel("评论对象")
public class CommentQo {
@ApiModelProperty(value = "id")
private Integer id;
@ApiModelProperty(value = "uuid")
private String commentId;
......
......@@ -2,24 +2,23 @@ package com.tanpu.community.api.beans.qo;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ThemeAnalysDO {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "UUID")
@ApiModelProperty(value = "主题Id")
private String themeId;
@ApiModelProperty(value = "标题")
private String title;
@ApiModelProperty(value = "类型")
private Integer themeType;
@ApiModelProperty(value = "文本内容")
private String content;
@ApiModelProperty(value = "作者id")
private String authorId;
......@@ -38,7 +37,21 @@ public class ThemeAnalysDO {
@ApiModelProperty(value = "点赞量")
private Integer likeCount;
@ApiModelProperty(value = "收藏量")
private Integer collectCount;
@ApiModelProperty(value = "收藏量")
private Integer viewCount;
@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 {
* @return
*/
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;
public enum TopicStatusEnum {
TRUE(1,true),FALSE(0,false);
HOTTEST(1,"最热"),
NEWEST(2,"最新");;
private Integer code;
private boolean status;
private String type;
TopicStatusEnum(Integer code, String type) {
this.code = code;
this.type = type;
}
public Integer getCode() {
return code;
......@@ -15,18 +21,11 @@ public enum TopicStatusEnum {
this.code = code;
}
public boolean isStatus() {
return status;
}
public void setStatus(boolean status) {
this.status = status;
public String getType() {
return type;
}
TopicStatusEnum(Integer code, boolean status) {
this.code = code;
this.status = status;
public void setType(String type) {
this.type = type;
}
}
......@@ -145,4 +145,12 @@ public class ThemeController {
return CommonResp.success(themeManager.getFollowUpdateCount(userId));
}
}
@AuthLogin
@ApiOperation("关注主题更新数量")
@GetMapping(value = "/test")
@ResponseBody
public CommonResp<String> test() {
return CommonResp.success("");
}
}
package com.tanpu.community.manager;
import com.tanpu.community.service.RankService;
import com.tanpu.community.service.RedisService;
import com.tanpu.community.service.VisitSummaryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
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.stereotype.Service;
......@@ -21,6 +20,9 @@ public class ConJobManager {
@Autowired
private RedisService redisService;
@Autowired
private RankService rankService;
/**
* 定时统计 话题 访问数据,并刷到redis
*/
......@@ -30,4 +32,12 @@ public class ConJobManager {
Integer detailVisitTimes = visitSummaryService.queryTopicDetailVisit(topicId);
redisService.set("topicVisitorStats", detailVisitTimes);
}
/**
* 定时统计主题排行
*/
@Scheduled(cron = "0 */2 * * * ?")
public void themeRank() {
rankService.rankThemes();
}
}
......@@ -2,27 +2,18 @@ package com.tanpu.community.manager;
import com.tanpu.common.exception.BizException;
import com.tanpu.common.util.JsonUtil;
import com.tanpu.community.api.beans.qo.ESThemeQo;
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.qo.*;
import com.tanpu.community.api.beans.req.homepage.QueryRecordThemeReq;
import com.tanpu.community.api.beans.req.theme.*;
import com.tanpu.community.api.beans.resp.CreateThemeResp;
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.dao.entity.community.*;
import com.tanpu.community.dao.entity.user.UserInfoEntity;
import com.tanpu.community.service.*;
import com.tanpu.community.service.BlackListService;
import com.tanpu.community.service.base.ESService;
import com.tanpu.community.util.ConvertUtil;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.ListUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -63,6 +54,9 @@ public class ThemeManager {
@Autowired
private VisitSummaryService visitSummaryService;
@Autowired
private RankService rankService;
@Autowired
private ESService esService;
......@@ -91,7 +85,6 @@ public class ThemeManager {
themeEntity.setContent(JsonUtil.toJson(req.getContent()));
if (StringUtils.isEmpty(req.getEditThemeId())) {
//新建
themeService.insertTheme(themeEntity);
......@@ -109,12 +102,12 @@ public class ThemeManager {
themeAttachmentService.insertList(themeAttachments);
return CreateThemeResp.builder().themeId(themeEntity.getThemeId()).build();
}
/**
* 返回主题列表
*
* @param req
* @param userId
* @return
......@@ -123,10 +116,10 @@ public class ThemeManager {
List<ThemeEntity> themeEntities = new ArrayList<>();
if (ThemeListTypeEnum.RECOMMEND.getCode().equals(req.getType())) {
// TODO:推荐
themeEntities = themeService.selectExcludeUser(userId,req.getLastId(), req.getPageSize());
Set<String> recomondThemeIds;
Set<String> hotThemeIds;
Set<String> newThemeIds;
// themeEntities = themeService.selectExcludeUser(userId, req.getLastId(), req.getPageSize());
List<String> recommendThemeIds = rankService.getHotAndNewThemes(100, 100);
themeEntities = themeService.queryByThemeIdsExcludeUser( recommendThemeIds,userId, req.getLastId(), req.getPageSize());
} else if (ThemeListTypeEnum.FOLLOW.getCode().equals(req.getType())) {
//根据关注列表查询
List<String> fansList = followRelService.queryFansByFollowerId(userId);
......@@ -147,7 +140,7 @@ public class ThemeManager {
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);
}
......@@ -333,7 +326,7 @@ public class ThemeManager {
Integer forwardCountByUser = themeService.getForwardCountByUser(themeId, userId);
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);
//点赞,收藏,转发
Integer likeCount = collectionService.getCountByTypeAndId(themeId, CollectionTypeEnum.LIKE_THEME);
......@@ -378,4 +371,6 @@ public class ThemeManager {
List<String> fansList = followRelService.queryFansByFollowerId(userId);
return themeService.queryCountFromLastTime(fansList, lastViewTime);
}
}
package com.tanpu.community.manager;
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.TopicHotQo;
import com.tanpu.community.api.beans.qo.TopicTitileQo;
import com.tanpu.community.api.beans.req.page.Page;
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.enums.CollectionTypeEnum;
import com.tanpu.community.dao.entity.community.TopicEntity;
......@@ -22,7 +22,6 @@ import org.springframework.stereotype.Service;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
@Service
public class TopicManager {
......@@ -44,6 +43,8 @@ public class TopicManager {
@Autowired
private VisitSummaryService visitSummaryService;
@Autowired
private RankService rankService;
//新增话题
public void insertTopic(String topicTitle, String userId) {
......@@ -106,25 +107,26 @@ public class TopicManager {
public List<TopicHotQo> getHotTopicTitles() {
List<TopicEntity> topicEntities = topicService.queryAll();
List<TopicHotQo> topicHotQos = ConvertUtil.topicEntityToHotQos(topicEntities);
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);
}
topicHotQos.stream().collect(Collectors.toMap(TopicHotQo::getRank, o->o));
//TODO 添加类型:热 新 顶
topicHotQos.get(0).setType(1);
topicHotQos.get(2).setType(2);
return topicHotQos;
// List<TopicEntity> topicEntities = topicService.queryAll();
// List<TopicHotQo> topicHotQos = ConvertUtil.topicEntityToHotQos(topicEntities);
// 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));
// map.entrySet().stream().sorted(Comparator.)
//
// //TODO 添加类型:热 新 顶
// topicHotQos.get(0).setType(1);
// topicHotQos.get(2).setType(2);
// return topicHotQos;
return rankService.rankTopics();
}
public void setTopTopic(String topicId, boolean setTop) {
......
......@@ -5,7 +5,7 @@ import com.tanpu.common.exception.BizException;
import com.tanpu.common.uuid.UuidGenHelper;
import com.tanpu.community.api.enums.CommentTypeEnum;
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.mapper.community.CommentMapper;
import org.apache.commons.collections4.CollectionUtils;
......@@ -66,7 +66,7 @@ public class CommentService {
LambdaQueryWrapper<CommentEntity> queryWrapper = new LambdaQueryWrapper<CommentEntity>()
.eq(CommentEntity::getThemeId, themeId)
.eq(CommentEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode())
.eq(CommentEntity::getIsBlock, TopicStatusEnum.FALSE.getCode())
.eq(CommentEntity::getIsBlock, StatusEnum.FALSE.getCode())
.orderByDesc(CommentEntity::getCreateTime);
if (parentId == null) {
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 {
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返回主题详情(未删)
public ThemeEntity queryByThemeId(String themeId) {
return themeMapper.selectOne(new LambdaQueryWrapper<ThemeEntity>()
......@@ -72,6 +83,9 @@ public class ThemeService {
//根据ids返回主题详情,带分页
public List<ThemeEntity> queryByThemeIds(List<String> themeIds, String lastId, Integer pageSize) {
if (CollectionUtils.isEmpty(themeIds)){
return Collections.emptyList();
}
LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>()
.in(ThemeEntity::getThemeId, themeIds)
.eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode());
......@@ -86,8 +100,15 @@ public class ThemeService {
return themeMapper.selectList(queryWrapper);
}
//根据ids返回主题详情
/**
* 根据主题Id查询列表
* @param themeIds
* @return
*/
public List<ThemeEntity> queryByThemeIds(List<String> themeIds) {
if (CollectionUtils.isEmpty(themeIds)){
return Collections.emptyList();
}
LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>()
.in(ThemeEntity::getThemeId, themeIds)
.eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode());
......@@ -95,8 +116,10 @@ public class ThemeService {
return themeMapper.selectList(queryWrapper);
}
/**
* 分页查询,非当前用户的主题
* 查询非传入作者的主题(可分页)
* @param lastId
* @param pageSize
* @param userId
......@@ -113,8 +136,10 @@ public class ThemeService {
if (lastEntity == null) throw new BizException("主题未找到,id:" + lastId);
queryWrapper.lt(ThemeEntity::getUpdateTime, lastEntity.getCreateTime());
}
if (pageSize!=null){
queryWrapper.last("limit " + pageSize);
}
queryWrapper.last("limit " + pageSize);
queryWrapper.orderByDesc(ThemeEntity::getId);
queryWrapper.orderByDesc(ThemeEntity::getCreateTime);
queryWrapper.eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode());
......@@ -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 lastId 查询此主题Id之前的主题
......@@ -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) {
LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>()
.in(ThemeEntity::getAuthorId, userIds);
......
......@@ -4,7 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.tanpu.common.uuid.UuidGenHelper;
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.mapper.community.TopicMapper;
import org.apache.commons.collections4.CollectionUtils;
......@@ -30,13 +30,15 @@ public class TopicService {
public List<TopicEntity> queryAll() {
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) {
return topicMapper.selectList(new LambdaQueryWrapper<TopicEntity>()
.like(TopicEntity::getTopicTitle,keyword)
.eq(TopicEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode()));
.like(TopicEntity::getTopicTitle, keyword)
.eq(TopicEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode())
.orderByDesc(TopicEntity::getCreateTime));
}
@Transactional
......@@ -44,8 +46,8 @@ public class TopicService {
TopicEntity entity = TopicEntity.builder()
.topicId(uuidGenHelper.getUuidStr())
.topicTitle(topicTitle)
.isTop(TopicStatusEnum.FALSE.getCode())
.isConceal(TopicStatusEnum.FALSE.getCode())
.isTop(StatusEnum.FALSE.getCode())
.isConceal(StatusEnum.FALSE.getCode())
.build();
topicMapper.insert(entity);
......@@ -54,41 +56,41 @@ public class TopicService {
public void updateTopicToTop(String topicId) {
TopicEntity topicEntity = new TopicEntity();
topicEntity.setIsTop(TopicStatusEnum.TRUE.getCode());
topicEntity.setIsTop(StatusEnum.TRUE.getCode());
topicMapper.update(topicEntity, new LambdaUpdateWrapper<TopicEntity>()
.eq(TopicEntity::getId, topicId));
}
public void updateTopicNotTop(String topicId) {
TopicEntity topicEntity = new TopicEntity();
topicEntity.setIsTop(TopicStatusEnum.FALSE.getCode());
topicEntity.setIsTop(StatusEnum.FALSE.getCode());
topicMapper.update(topicEntity, new LambdaUpdateWrapper<TopicEntity>()
.eq(TopicEntity::getId, topicId));
}
public void updateTopicToConceal(String topicId) {
TopicEntity topicEntity = new TopicEntity();
topicEntity.setIsConceal(TopicStatusEnum.TRUE.getCode());
topicEntity.setIsConceal(StatusEnum.TRUE.getCode());
topicMapper.update(topicEntity, new LambdaUpdateWrapper<TopicEntity>()
.eq(TopicEntity::getId, topicId));
}
public void updateTopicNotConceal(String topicId) {
TopicEntity topicEntity = new TopicEntity();
topicEntity.setIsConceal(TopicStatusEnum.FALSE.getCode());
topicEntity.setIsConceal(StatusEnum.FALSE.getCode());
topicMapper.update(topicEntity, new LambdaUpdateWrapper<TopicEntity>()
.eq(TopicEntity::getId, 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) {
if (CollectionUtils.isEmpty(topicIds)){
if (CollectionUtils.isEmpty(topicIds)) {
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) {
......
......@@ -16,6 +16,7 @@ import org.springframework.beans.BeanUtils;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
......@@ -57,19 +58,20 @@ public class ConvertUtil {
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) {
ThemeEntity themeEntity = new ThemeEntity();
BeanUtils.copyProperties(themeQO, themeEntity);
return themeEntity;
public static List<ThemeAnalysDO> themeEntityToAnalysDOs(List<ThemeEntity> themeEntities) {
return themeEntities.stream().map(ConvertUtil::themeEntityToAnalysDO).collect(Collectors.toList());
}
/**
* 首页主题列表,限制附件个数为1(1文本+1附件)
*
* @param themeEntities
* @return
*/
public static List<ThemeQo> themeEntitiesToDTOs(List<ThemeEntity> themeEntities) {
return themeEntities.stream().map(ConvertUtil::themeEntityToQo2).collect(Collectors.toList());
}
......@@ -88,6 +90,9 @@ public class ConvertUtil {
}
public static List<TopicHotQo> topicEntityToHotQos(List<TopicEntity> topicEntities) {
if (topicEntities==null){
return Collections.emptyList();
}
return topicEntities.stream().map(ConvertUtil::topicEntityToHotQo).collect(Collectors.toList());
}
......
......@@ -35,4 +35,10 @@ public class TimeUtil {
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