Commit a257696c authored by 刘基明's avatar 刘基明

topic表添加字段

parent 03101543
package com.tanpu.community.api.constants;
public enum DeleteTagEnum {
NOT_DELETED(0, "未删除"),
DELETED(1, "已删除");
private Integer code;
private String type;
DeleteTagEnum(Integer code, String type) {
this.code = code;
this.type = type;
}
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
......@@ -4,28 +4,28 @@ public class RedisKeyConstant {
//话题页浏览量
public static final String TOPIC_VIEW_AMOUNT_="TOPIC_PAGE_VIEW_AMOUNT_";
//话题总浏览量
//话题总浏览量=总浏览量+带这个话题的帖子量
public static final String TOPIC_TOTAL_VIEW_AMOUNT_="TOPIC_TOTAL_VIEW_AMOUNT_";
//点赞量
public static final String TOPIC_LIKE_AMOUNT_="TOPIC_LIKE_AMOUNT_";
//收藏量
public static final String TOPIC_BOOK_AMOUNT_="TOPIC_BOOK_AMOUNT_";
//评论数
public static final String TOPIC_COMMENT_AMOUNT_="TOPIC_COMMENT_AMOUNT_";
//用户数
public static final String TOPIC_USER_AMOUNT_="TOPIC_USER_AMOUNT_";
//讨论量
//讨论量=发布主题贴数+回复总数
public static final String TOPIC_DISCUSS_AMOUNT_="TOPIC_DISCUSS_AMOUNT_";
//发帖数
public static final String TOPIC_THEME_AMOUNT_="TOPIC_THEME_AMOUNT_";
//回帖数
public static final String TOPIC_COMENT_AMOUNT_="TOPIC_COMENT_AMOUNT_";
//总用户数
public static final String TOPIC_COMMENT_AMOUNT_="TOPIC_COMMENT_AMOUNT_";
//总用户数=访问话题页+发帖+回帖(去重)
public static final String TOPIC_TOTAOL_USER_AMOUNT_="TOPIC_TOTAOL_USER_AMOUNT_";
//访问话题人数
public static final String TOPIC_USER_VIEW_AMOUNT_="TOPIC_USER_VIEW_AMOUNT_";
//发帖人数
public static final String TOPIC_POSTER_AMOUNT_="TOPIC_POSTER_AMOUNT_";
public static final String TOPIC_USER_POST_AMOUNT_ ="TOPIC_USER_POST_AMOUNT_";
//回帖人数
public static final String TOPIC_REPLIER_AMOUNT_="TOPIC_REPLIER_AMOUNT_";
public static final String TOPIC_USER_COMMET_AMOUNT_ ="TOPIC_USER_COMMET_AMOUNT_";
public static final String THEME_VIEW_AMOUNT_="THEME_VIEW_AMOUNT_";
public static final String THEME_LIKE_AMOUNT_="THEME_LIKE_AMOUNT_";
......
......@@ -27,4 +27,6 @@ public enum TopicStatusEnum {
this.code = code;
this.status = status;
}
}
package com.tanpu.community.dao.entity.community;
import com.baomidou.mybatisplus.annotation.TableName;
import java.time.LocalDateTime;
import java.io.Serializable;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* <p>
......@@ -14,6 +18,9 @@ import io.swagger.annotations.ApiModelProperty;
* @author xudong
* @since 2021-06-10
*/
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TableName("collection")
@ApiModel(value="CollectionEntity对象", description="收藏/点赞")
public class CollectionEntity implements Serializable {
......
package com.tanpu.community.dao.entity.community;
import com.baomidou.mybatisplus.annotation.TableName;
import java.time.LocalDateTime;
import java.io.Serializable;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* <p>
......@@ -14,6 +18,9 @@ import io.swagger.annotations.ApiModelProperty;
* @author xudong
* @since 2021-06-10
*/
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TableName("comment")
@ApiModel(value="CommentEntity对象", description="评论")
public class CommentEntity implements Serializable {
......
......@@ -40,9 +40,9 @@ public class ThemeManager {
@Autowired
private RedisService redisService;
//返回推荐主题文章
public List<ThemeDTO> selectHotThemes(){
//TODO:根据算法计算推荐主题
// 返回推荐主题文章
public List<ThemeDTO> selectHotThemes() {
// TODO:根据算法计算推荐主题
List<ThemeEntity> themeEntities = themeService.selectAll();
List<ThemeDTO> themeDTOS = ConvertUtil.themeEntitiesToDTOs(themeEntities);
for (ThemeDTO themeDTO : themeDTOS) {
......@@ -53,8 +53,8 @@ public class ThemeManager {
return themeDTOS;
}
//返回关注主题
public List<ThemeDTO> selectInterestThemes(String userId){
// 返回关注主题
public List<ThemeDTO> selectInterestThemes(String userId) {
List<String> fansList = fansRelService.queryFansByFollowerId(userId).stream().map(FansRelEntity::getIdolId).collect(Collectors.toList());
List<ThemeEntity> themeEntities = themeService.selectByFans(fansList);
List<ThemeDTO> themeDTOS = ConvertUtil.themeEntitiesToDTOs(themeEntities);
......@@ -69,21 +69,21 @@ public class ThemeManager {
private String calUpToNowTime(LocalDateTime start) {
Duration between = Duration.between(LocalDateTime.now(), start);
long duration = between.toMinutes();
if (duration<1){
if (duration < 1) {
return "刚刚";
}else if (duration<60){
return duration+"分钟前";
}else if (duration<60*24){
return duration/60+"小时前";
}else if (start.getYear()==LocalDateTime.now().getYear()){
} else if (duration < 60) {
return duration + "分钟前";
} else if (duration < 60 * 24) {
return duration / 60 + "小时前";
} else if (start.getYear() == LocalDateTime.now().getYear()) {
return start.format(DateTimeFormatter.ofPattern("MM-dd HH:mm:ss"));
}
return start.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
}
//点赞
// 点赞
public void like(String themeId, String userId) {
collectionService.addCollection(themeId, userId, CollectionTypeEnum.LIKE);
collectionService.addIfNotExist(themeId, userId, CollectionTypeEnum.LIKE);
}
public void unlike(String themeId, String userId) {
......@@ -91,11 +91,13 @@ public class ThemeManager {
// 评论(对主题)
public void commentToTheme(String themeId, String userId, String comment) {
CommentEntity commentEntity = new CommentEntity();
commentEntity.setTargetId(themeId);
commentEntity.setAuthorId(userId);
commentEntity.setCommentType(CommentTypeEnum.THEME.getCode());
commentEntity.setContent(comment);
CommentEntity commentEntity = CommentEntity.builder()
.targetId(themeId)
.authorId(userId)
.content(comment)
.commentType(CommentTypeEnum.THEME.getCode())
.build();
commentService.insertComment(commentEntity);
}
......@@ -104,14 +106,10 @@ public class ThemeManager {
//TODO
}
//分享
public void share(String themeId, String user) {
//TODO
}
//收藏
public void favorite(String themeId, String userId) {
collectionService.addCollection(themeId, userId, CollectionTypeEnum.BOOK);
collectionService.addIfNotExist(themeId, userId, CollectionTypeEnum.BOOK);
}
public void unFavorite(String themeId, String userId) {
......@@ -137,7 +135,7 @@ public class ThemeManager {
public void blockTheme(String themeId, String userId) {
blackListService.addBlock(themeId, userId, BlockTypeEnum.THEME);
BlackListEntity selectOne = blackListService.selectOne(userId, BlockTypeEnum.USER.getCode(), themeService.selectTheme(themeId).getAuthorId());
if (selectOne==null){
if (selectOne == null) {
blackListService.addBlock(themeService.selectTheme(themeId).getAuthorId(), userId, BlockTypeEnum.USER);
}
}
......
......@@ -47,12 +47,12 @@ public class TopicManager {
public List<TopicDTO> getAllTopicDetail() {
return ConvertUtil.topicEntitiesToDTOs(topicService.queryTopicList());
return ConvertUtil.topicEntitiesToDTOs(topicService.queryAll());
}
public List<TopicBriefInfoDTO> getAllTopicBriefInfo() {
List<TopicEntity> allTopic = topicService.queryTopicList();
List<TopicEntity> allTopic = topicService.queryAll();
List<TopicBriefInfoDTO> topicDTOS = ConvertUtil.topicEntitiesToBriefDTOs(allTopic);
//讨论数=发布主题贴数+回复总数
for (TopicBriefInfoDTO topicDTO : topicDTOS) {
......@@ -109,8 +109,10 @@ public class TopicManager {
public void refreshRedisCache(){
List<String> topicIds = topicService.queryTopicList().stream().map(TopicEntity::getId).collect(Collectors.toList());
for (String topicId : topicIds) {
List<TopicEntity> topicEntities = topicService.queryAll();
for (TopicEntity topic : topicEntities) {
String topicId = topic.getId();
Long viewAmountModify = topic.getViewAmountModify();
List<ThemeEntity> themeEntities = themeService.selectByTopic(topicId);
List<String> themeIds = themeEntities.stream().map(ThemeEntity::getId).collect(Collectors.toList());
Long likeAmountByThemeIds = collectionService.getLikeAmountByThemeIds(themeIds);
......@@ -119,16 +121,14 @@ public class TopicManager {
redisService.set(RedisKeyConstant.TOPIC_LIKE_AMOUNT_+topicId, likeAmountByThemeIds);
redisService.set(RedisKeyConstant.TOPIC_BOOK_AMOUNT_+topicId, bookAmountByThemeIds);
redisService.set(RedisKeyConstant.TOPIC_COMMENT_AMOUNT_+topicId, commentAmountByThemeIds);
redisService.set(RedisKeyConstant.TOPIC_DISCUSS_AMOUNT_+topicId, commentAmountByThemeIds+themeIds.size());
redisService.set(RedisKeyConstant.TOPIC_TOTAL_VIEW_AMOUNT_+topicId, commentAmountByThemeIds+themeIds.size());
redisService.set(RedisKeyConstant.TOPIC_THEME_AMOUNT_+topicId, commentAmountByThemeIds+themeIds.size());
redisService.set(RedisKeyConstant.TOPIC_COMENT_AMOUNT_+topicId, commentAmountByThemeIds+themeIds.size());
redisService.set(RedisKeyConstant.TOPIC_TOTAOL_USER_AMOUNT_+topicId, commentAmountByThemeIds+themeIds.size());
redisService.set(RedisKeyConstant.TOPIC_DISCUSS_AMOUNT_+topicId, commentAmountByThemeIds+themeIds.size());
redisService.set(RedisKeyConstant.TOPIC_POSTER_AMOUNT_+topicId, commentAmountByThemeIds+themeIds.size());
redisService.set(RedisKeyConstant.TOPIC_REPLIER_AMOUNT_+topicId, commentAmountByThemeIds+themeIds.size());
redisService.set(RedisKeyConstant.TOPIC_USER_POST_AMOUNT_ +topicId, commentAmountByThemeIds+themeIds.size());
redisService.set(RedisKeyConstant.TOPIC_USER_COMMET_AMOUNT_ +topicId, commentAmountByThemeIds+themeIds.size());
}
......
......@@ -18,13 +18,14 @@ public class BlackListService {
blackListEntity.setBlockedId(blockId);
blackListEntity.setBlocker(userId);
blackListEntity.setBlockedType(type.getCode());
blackListMapper.insert(blackListEntity);
}
public BlackListEntity selectOne(String blocker,Integer blockType,String blockId) {
return blackListMapper.selectOne(new LambdaQueryWrapper<BlackListEntity>().eq(BlackListEntity::getBlocker, blocker).
eq(BlackListEntity::getBlockedId, blockId).eq(BlackListEntity::getBlockedType, blockType));
public BlackListEntity selectOne(String blocker, Integer blockType, String blockId) {
return blackListMapper.selectOne(new LambdaQueryWrapper<BlackListEntity>()
.eq(BlackListEntity::getBlocker, blocker)
.eq(BlackListEntity::getBlockedId, blockId)
.eq(BlackListEntity::getBlockedType, blockType));
}
public void removeBlackList(String blocker, String blockId, BlockTypeEnum blockType) {
......
......@@ -2,8 +2,10 @@ package com.tanpu.community.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tanpu.community.api.constants.CollectionTypeEnum;
import com.tanpu.community.api.constants.DeleteTagEnum;
import com.tanpu.community.dao.entity.community.CollectionEntity;
import com.tanpu.community.dao.mapper.community.CollectionMapper;
import com.tanpu.community.util.ConvertUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
......@@ -14,58 +16,83 @@ public class CollectionService {
@Resource
private CollectionMapper collectionMapper;
public void addCollection(String themeId, String userId, CollectionTypeEnum type){
// todo 判断是否存在
// 若不存在则新增,若存在则修改deleteTag
public void addIfNotExist(String themeId, String userId, CollectionTypeEnum type) {
// 判断是否存在
CollectionEntity queryCollection = getTargetCollection(themeId, userId, type);
if (queryCollection != null) {
Integer oldDeleteTag = queryCollection.getDeleteTag();
queryCollection.setDeleteTag(ConvertUtil.deleteTagShift(oldDeleteTag));
collectionMapper.updateById(queryCollection);
} else {
CollectionEntity entity = CollectionEntity.builder()
.collectionType(type.getCode())
.authorId(userId)
.targetId(themeId)
.createBy(userId)
.build();
CollectionEntity collectionEntity = new CollectionEntity();
collectionEntity.setCollectionType(type.getCode());
collectionEntity.setAuthorId(userId);
collectionEntity.setTargetId(themeId);
collectionEntity.setCreateBy(userId);
collectionMapper.insert(collectionEntity);
collectionMapper.insert(entity);
}
}
//根据用户id获取点赞列表
public List<CollectionEntity> getLikeListByUser(String userId){
//根据用户、主题、类型查询
public CollectionEntity getTargetCollection(String themeId, String userId, CollectionTypeEnum type) {
return collectionMapper.selectOne(new LambdaQueryWrapper<CollectionEntity>()
.eq(CollectionEntity::getCollectionType, type)
.eq(CollectionEntity::getAuthorId, userId)
.eq(CollectionEntity::getTargetId, themeId));
}
// 根据用户id获取点赞列表
public List<CollectionEntity> getLikeListByUser(String userId) {
return collectionMapper.selectList(new LambdaQueryWrapper<CollectionEntity>()
.eq(CollectionEntity::getCollectionType, CollectionTypeEnum.LIKE.getCode()));
.eq(CollectionEntity::getCollectionType, CollectionTypeEnum.LIKE.getCode())
.eq(CollectionEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode()));
}
//根据用户id获取收藏列表
public List<CollectionEntity> getBookListByUser(String userId){
// 根据用户id获取收藏列表
public List<CollectionEntity> getBookListByUser(String userId) {
return collectionMapper.selectList(new LambdaQueryWrapper<CollectionEntity>()
.eq(CollectionEntity::getCollectionType,CollectionTypeEnum.BOOK.getCode()));
.eq(CollectionEntity::getCollectionType, CollectionTypeEnum.BOOK.getCode())
.eq(CollectionEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode()));
}
//统计主题的点赞量
public Long getLikeAmountByThemeId(String themeId){
// 统计单个主题的点赞量
public Long getLikeAmountByThemeId(String themeId) {
return (long) collectionMapper.selectList((new LambdaQueryWrapper<CollectionEntity>()
.eq(CollectionEntity::getTargetId, themeId)
.eq(CollectionEntity::getCollectionType, CollectionTypeEnum.LIKE.getCode())))
.eq(CollectionEntity::getCollectionType, CollectionTypeEnum.LIKE.getCode())
.eq(CollectionEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode())))
.size();
}
//统计主题集合的点赞量
public Long getLikeAmountByThemeIds(List<String> themeIds){
// 统计多个主题的点赞量
public Long getLikeAmountByThemeIds(List<String> themeIds) {
return (long) collectionMapper.selectList((new LambdaQueryWrapper<CollectionEntity>()
.in(CollectionEntity::getTargetId, themeIds)
.eq(CollectionEntity::getCollectionType, CollectionTypeEnum.LIKE.getCode())))
.eq(CollectionEntity::getCollectionType, CollectionTypeEnum.LIKE.getCode()))
.eq(CollectionEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode()))
.size();
}
//统计主题的收藏量
public Long getBookAmountByThemeId(String themeId){
//统计单个主题的收藏量
public Long getBookAmountByThemeId(String themeId) {
return (long) collectionMapper.selectList((new LambdaQueryWrapper<CollectionEntity>()
.eq(CollectionEntity::getTargetId, themeId)
.eq(CollectionEntity::getCollectionType, CollectionTypeEnum.BOOK.getCode())))
.eq(CollectionEntity::getCollectionType, CollectionTypeEnum.BOOK.getCode()))
.eq(CollectionEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode()))
.size();
}
//统计主题集合的收藏量
public Long getBookAmountByThemeIds(List<String> themeIds){
//统多个主题的收藏量
public Long getBookAmountByThemeIds(List<String> themeIds) {
return (long) collectionMapper.selectList((new LambdaQueryWrapper<CollectionEntity>()
.in(CollectionEntity::getTargetId, themeIds)
.eq(CollectionEntity::getCollectionType, CollectionTypeEnum.BOOK.getCode())))
.eq(CollectionEntity::getCollectionType, CollectionTypeEnum.BOOK.getCode()))
.eq(CollectionEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode()))
.size();
}
......
......@@ -14,19 +14,17 @@ public class CommentService {
@Resource
private CommentMapper commentMapper;
public void insertComment(CommentEntity commentEntity){
public void insertComment(CommentEntity commentEntity) {
commentMapper.insert(commentEntity);
}
public List<CommentEntity> selectByUserId(String userId){
return commentMapper.selectList(new LambdaQueryWrapper<CommentEntity>().eq(CommentEntity::getAuthorId,userId));
public List<CommentEntity> selectByUserId(String userId) {
return commentMapper.selectList(new LambdaQueryWrapper<CommentEntity>().eq(CommentEntity::getAuthorId, userId));
}
//统计主题集合的评论量
public Long getCommentAmountByThemeIds(List<String> themeIds){
public Long getCommentAmountByThemeIds(List<String> themeIds) {
return (long) commentMapper.selectList((new LambdaQueryWrapper<CommentEntity>()
.in(CommentEntity::getTargetId, themeIds)))
.size();
......
......@@ -54,22 +54,22 @@ public class RedisService {
/**
* incr
*/
public long incr(String key,Long delta){
if (delta<0){
throw new BizException("递增子必须大于0");
public long incr(String key, Long delta) {
if (delta < 0) {
throw new BizException("递增子必须大于0");
}
return redisTemplate.opsForValue().increment(key,delta);
return redisTemplate.opsForValue().increment(key, delta);
}
/**
* incr
*/
public long decr(String key,Long delta){
if (delta<0){
throw new BizException("递减子必须大于0");
public long decr(String key, Long delta) {
if (delta < 0) {
throw new BizException("递减子必须大于0");
}
return redisTemplate.opsForValue().decrement(key,delta);
return redisTemplate.opsForValue().decrement(key, delta);
}
}
......@@ -20,7 +20,7 @@ public class TopicService {
private TopicMapper topicMapper;
public List<TopicEntity> queryTopicList(){
public List<TopicEntity> queryAll(){
return topicMapper.selectList(new LambdaQueryWrapper<TopicEntity>()
.eq(TopicEntity::getDeleteTag,TopicStatusEnum.FALSE.getCode()));
}
......@@ -64,7 +64,10 @@ public class TopicService {
public void modifyViewAmount(String topicId,long amount){
TopicEntity topicEntity = topicMapper.selectById(topicId);
Long oldAmount = topicEntity.getViewAmountModify();
topicEntity.setViewAmountModify(topicEntity.getViewAmountModify() + amount);
topicMapper.update(topicEntity,new LambdaUpdateWrapper<TopicEntity>()
.eq(TopicEntity::getViewAmountModify,oldAmount));
return;
}
}
......@@ -3,6 +3,7 @@ package com.tanpu.community.util;
import com.tanpu.community.api.beans.ThemeDTO;
import com.tanpu.community.api.beans.TopicBriefInfoDTO;
import com.tanpu.community.api.beans.TopicDTO;
import com.tanpu.community.api.constants.DeleteTagEnum;
import com.tanpu.community.dao.entity.community.ThemeEntity;
import com.tanpu.community.dao.entity.community.TopicEntity;
import org.springframework.beans.BeanUtils;
......@@ -54,4 +55,20 @@ public class ConvertUtil {
public static List<TopicBriefInfoDTO> topicEntitiesToBriefDTOs(List<TopicEntity> topicEntities) {
return topicEntities.stream().map(ConvertUtil::topicToBriefInfoDTO).collect(Collectors.toList());
}
public static DeleteTagEnum deleteTagShift(DeleteTagEnum deleteTagEnum) {
if (deleteTagEnum.getCode().equals(DeleteTagEnum.NOT_DELETED.getCode())) {
return DeleteTagEnum.DELETED;
}else {
return DeleteTagEnum.NOT_DELETED;
}
}
public static Integer deleteTagShift(Integer deleteTag) {
if (deleteTag.equals(DeleteTagEnum.NOT_DELETED.getCode())) {
return DeleteTagEnum.DELETED.getCode();
}else {
return DeleteTagEnum.NOT_DELETED.getCode();
}
}
}
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