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