Commit 882eec9e authored by 刘基明's avatar 刘基明

builder构造模式

parent a257696c
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("black_list")
@ApiModel(value="BlackListEntity对象", description="黑名单")
public class BlackListEntity implements Serializable {
......
......@@ -3,6 +3,9 @@ package com.tanpu.community.dao.entity.community;
import com.baomidou.mybatisplus.annotation.TableName;
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;
......@@ -15,6 +18,9 @@ import java.time.LocalDateTime;
* @author xudong
* @since 2021-06-18
*/
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TableName("topic")
@ApiModel(value="TopicEntity对象", description="话题")
public class TopicEntity implements Serializable {
......
......@@ -5,7 +5,6 @@ import com.tanpu.community.api.beans.TopicBriefInfoDTO;
import com.tanpu.community.api.beans.TopicDTO;
import com.tanpu.community.api.beans.TopicDataAnalysDTO;
import com.tanpu.community.api.constants.RedisKeyConstant;
import com.tanpu.community.api.constants.TopicStatusEnum;
import com.tanpu.community.dao.entity.community.ThemeEntity;
import com.tanpu.community.dao.entity.community.TopicEntity;
import com.tanpu.community.service.*;
......@@ -34,23 +33,18 @@ public class TopicManager {
@Autowired
private CommentService commentService;
public void insertTopic(String topicTitle,String userId){
TopicEntity topicEntity = new TopicEntity();
topicEntity.setCreateBy(userId);
topicEntity.setUpdateBy(userId);
topicEntity.setTopicTitle(topicTitle);
topicEntity.setIsTop(TopicStatusEnum.FALSE.getCode());
topicEntity.setIsConceal(TopicStatusEnum.FALSE.getCode());
topicEntity.setDeleteTag(TopicStatusEnum.FALSE.getCode());
topicService.addTopic(topicEntity);
public void insertTopic(String topicTitle, String userId) {
topicService.addTopic(topicTitle, userId);
}
//后台管理-话题列表
public List<TopicDTO> getAllTopicDetail() {
return ConvertUtil.topicEntitiesToDTOs(topicService.queryAll());
}
//APP-话题列表
public List<TopicBriefInfoDTO> getAllTopicBriefInfo() {
List<TopicEntity> allTopic = topicService.queryAll();
List<TopicBriefInfoDTO> topicDTOS = ConvertUtil.topicEntitiesToBriefDTOs(allTopic);
......@@ -62,26 +56,27 @@ public class TopicManager {
return topicDTOS;
}
public void setTopTopic(String topicId, boolean setTop) {
TopicEntity topicEntity = topicService.queryById(topicId);
if (topicEntity == null){
throw new BizException("话题id不正确:" + topicId);
if (topicEntity == null) {
throw new BizException("找不到话题,id:" + topicId);
}
if (setTop){
if (setTop) {
topicService.updateTopicToTop(topicId);
}else {
} else {
topicService.updateTopicNotTop(topicId);
}
}
public void setTopicConceal(String topicId, boolean setConceal) {
TopicEntity topicEntity= topicService.queryById(topicId);
if (topicEntity==null){
throw new BizException("话题id不正确:"+topicId);
TopicEntity topicEntity = topicService.queryById(topicId);
if (topicEntity == null) {
throw new BizException("找不到话题,id:" + topicId);
}
if (setConceal){
if (setConceal) {
topicService.updateTopicToConceal(topicId);
}else {
} else {
topicService.updateTopicNotConceal(topicId);
}
}
......@@ -89,26 +84,24 @@ public class TopicManager {
public TopicDTO getDetail(String topicId) {
TopicEntity topicEntity = topicService.queryById(topicId);
TopicDTO topicDTO = ConvertUtil.topicEntityToDTO(topicEntity);
topicDTO.setViewAmount(redisService.getLong(RedisKeyConstant.TOPIC_VIEW_AMOUNT_+topicId));
topicDTO.setLikeAmount(redisService.getLong(RedisKeyConstant.TOPIC_LIKE_AMOUNT_+topicId));
topicDTO.setUserAmount(redisService.getLong(RedisKeyConstant.TOPIC_USER_AMOUNT_+topicId));
topicDTO.setViewAmount(redisService.getLong(RedisKeyConstant.TOPIC_VIEW_AMOUNT_ + topicId));
topicDTO.setLikeAmount(redisService.getLong(RedisKeyConstant.TOPIC_LIKE_AMOUNT_ + topicId));
topicDTO.setUserAmount(redisService.getLong(RedisKeyConstant.TOPIC_USER_AMOUNT_ + topicId));
return topicDTO;
}
public void modifyViewAmount(String topicId, Long modifyMount) {
topicService.modifyViewAmount(topicId,modifyMount);
if (modifyMount>0){
redisService.incr(RedisKeyConstant.TOPIC_TOTAL_VIEW_AMOUNT_+topicId,modifyMount);
}else {
redisService.decr(RedisKeyConstant.TOPIC_TOTAL_VIEW_AMOUNT_+topicId,-modifyMount);
topicService.modifyViewAmount(topicId, modifyMount);
if (modifyMount > 0) {
redisService.incr(RedisKeyConstant.TOPIC_TOTAL_VIEW_AMOUNT_ + topicId, modifyMount);
} else {
redisService.decr(RedisKeyConstant.TOPIC_TOTAL_VIEW_AMOUNT_ + topicId, -modifyMount);
}
}
public void refreshRedisCache(){
public void refreshRedisCache() {
List<TopicEntity> topicEntities = topicService.queryAll();
for (TopicEntity topic : topicEntities) {
String topicId = topic.getId();
......@@ -118,17 +111,17 @@ public class TopicManager {
Long likeAmountByThemeIds = collectionService.getLikeAmountByThemeIds(themeIds);
Long bookAmountByThemeIds = collectionService.getBookAmountByThemeIds(themeIds);
Long commentAmountByThemeIds = commentService.getCommentAmountByThemeIds(themeIds);
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_LIKE_AMOUNT_ + topicId, likeAmountByThemeIds);
redisService.set(RedisKeyConstant.TOPIC_BOOK_AMOUNT_ + topicId, bookAmountByThemeIds);
redisService.set(RedisKeyConstant.TOPIC_COMMENT_AMOUNT_ + topicId, commentAmountByThemeIds);
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_TOTAOL_USER_AMOUNT_+topicId, commentAmountByThemeIds+themeIds.size());
redisService.set(RedisKeyConstant.TOPIC_DISCUSS_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());
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_TOTAOL_USER_AMOUNT_ + topicId, commentAmountByThemeIds + themeIds.size());
redisService.set(RedisKeyConstant.TOPIC_DISCUSS_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());
}
......
......@@ -14,10 +14,12 @@ public class BlackListService {
private BlackListMapper blackListMapper;
public void addBlock(String blockId, String userId, BlockTypeEnum type) {
BlackListEntity blackListEntity = new BlackListEntity();
blackListEntity.setBlockedId(blockId);
blackListEntity.setBlocker(userId);
blackListEntity.setBlockedType(type.getCode());
BlackListEntity blackListEntity = BlackListEntity.builder()
.blocker(userId)
.blockedId(blockId)
.blockedType(type.getCode())
.build();
blackListMapper.insert(blackListEntity);
}
......
......@@ -2,6 +2,7 @@ package com.tanpu.community.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.tanpu.community.api.constants.DeleteTagEnum;
import com.tanpu.community.api.constants.TopicStatusEnum;
import com.tanpu.community.dao.entity.community.TopicEntity;
import com.tanpu.community.dao.mapper.community.TopicMapper;
......@@ -22,11 +23,20 @@ public class TopicService {
public List<TopicEntity> queryAll(){
return topicMapper.selectList(new LambdaQueryWrapper<TopicEntity>()
.eq(TopicEntity::getDeleteTag,TopicStatusEnum.FALSE.getCode()));
.eq(TopicEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode()));
}
public void addTopic(TopicEntity topicEntity){
topicMapper.insert(topicEntity);
public void addTopic(String topicTitle,String userId){
TopicEntity entity = TopicEntity.builder()
.topicTitle(topicTitle)
.createBy(userId)
.updateBy(userId)
.isTop(TopicStatusEnum.FALSE.getCode())
.isConceal(TopicStatusEnum.FALSE.getCode())
.build();
topicMapper.insert(entity);
}
......
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