Commit 98e0f115 authored by 刘基明's avatar 刘基明

接口设计

parent bb74dfcc
package com.tanpu.community.api.beans;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
@ApiModel
@Data
public class CommentReq {
@NotEmpty(message = "主题id不能为空")
private String themeId;
@NotEmpty(message = "评论内容不能为空")
private String comment;
}
...@@ -15,17 +15,17 @@ public class TopicDataAnalysDTO { ...@@ -15,17 +15,17 @@ public class TopicDataAnalysDTO {
@ApiModelProperty(value = "话题名称") @ApiModelProperty(value = "话题名称")
private String topicTitle; private String topicTitle;
@ApiModelProperty(value = "总浏览量") @ApiModelProperty(value = "总浏览量")
private Long viewTotalAmount; private Integer viewTotalAmount;
@ApiModelProperty(value = "话题页面浏览量") @ApiModelProperty(value = "话题页面浏览量")
private Long viewPageAmount; private Integer viewPageAmount;
@ApiModelProperty(value = "发帖数") @ApiModelProperty(value = "发帖数")
private Long themeAmount; private Integer themeAmount;
@ApiModelProperty(value = "回帖数") @ApiModelProperty(value = "回帖数")
private Long commentAmount; private Integer commentAmount;
@ApiModelProperty(value = "总用户数") @ApiModelProperty(value = "总用户数")
private Long userTotalAmount; private Integer userTotalAmount;
@ApiModelProperty(value = "发帖人数") @ApiModelProperty(value = "发帖人数")
private Long posterAmount; private Integer posterAmount;
@ApiModelProperty(value = "回帖人数") @ApiModelProperty(value = "回帖人数")
private Long replIierAmount; private Integer replIierAmount;
} }
...@@ -3,7 +3,7 @@ package com.tanpu.community.api.constants; ...@@ -3,7 +3,7 @@ package com.tanpu.community.api.constants;
public class RedisKeyConstant { public class RedisKeyConstant {
//话题页浏览量 //话题页浏览量
public static final String TOPIC_VIEW_AMOUNT_="TOPIC_PAGE_VIEW_AMOUNT_"; public static final String TOPIC_PAGE_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_";
//点赞量 //点赞量
...@@ -19,13 +19,13 @@ public class RedisKeyConstant { ...@@ -19,13 +19,13 @@ public class RedisKeyConstant {
//回帖数 //回帖数
public static final String TOPIC_COMMENT_AMOUNT_="TOPIC_COMMENT_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_TOTAL_USER_AMOUNT_ ="TOPIC_TOTAL_USER_AMOUNT_";
//访问话题人数 //访问话题人数
public static final String TOPIC_USER_VIEW_AMOUNT_="TOPIC_USER_VIEW_AMOUNT_"; public static final String TOPIC_USER_VIEW_AMOUNT_="TOPIC_USER_VIEW_AMOUNT_";
//发帖人数 //发帖人数
public static final String TOPIC_USER_POST_AMOUNT_ ="TOPIC_USER_POST_AMOUNT_"; public static final String TOPIC_POST_USER_AMOUNT_ ="TOPIC_POST_USER_AMOUNT_";
//回帖人数 //回帖人数
public static final String TOPIC_USER_COMMET_AMOUNT_ ="TOPIC_USER_COMMET_AMOUNT_"; public static final String TOPIC_COMMENT_USER_AMOUNT_ ="TOPIC_COMMENT_USER_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_";
......
package com.tanpu.community.config; //package com.tanpu.community.config;
//
import org.springframework.beans.factory.annotation.Value; //import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.cache.RedisCacheManagerBuilderCustomizer; //import org.springframework.boot.autoconfigure.cache.RedisCacheManagerBuilderCustomizer;
import org.springframework.cache.annotation.EnableCaching; //import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.interceptor.KeyGenerator; //import org.springframework.cache.interceptor.KeyGenerator;
import org.springframework.context.annotation.Bean; //import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; //import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.cache.RedisCacheConfiguration; //import org.springframework.data.redis.cache.RedisCacheConfiguration;
import org.springframework.data.redis.cache.RedisCacheManager; //import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.connection.RedisConnectionFactory; //import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.RedisPassword; //import org.springframework.data.redis.connection.RedisPassword;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration; //import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.connection.jedis.JedisClientConfiguration; //import org.springframework.data.redis.connection.jedis.JedisClientConfiguration;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; //import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate; //import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.util.StringUtils; //import org.springframework.util.StringUtils;
import redis.clients.jedis.JedisPoolConfig; //import redis.clients.jedis.JedisPoolConfig;
//
import java.lang.reflect.Method; //import java.lang.reflect.Method;
import java.time.Duration; //import java.time.Duration;
//
@Configuration //@Configuration
@EnableCaching //@EnableCaching
public class RedisConfig { //public class RedisConfig {
//
@Value("${spring.redis.host}") // @Value("${spring.redis.host}")
private String host; // private String host;
@Value("${spring.redis.port}") // @Value("${spring.redis.port}")
private int port; // private int port;
@Value("${spring.redis.password}") // @Value("${spring.redis.password}")
private String password; // private String password;
@Value("${spring.redis.timeout}") // @Value("${spring.redis.timeout}")
private int timeout; // private int timeout;
@Value("${spring.redis.max-active}") // @Value("${spring.redis.max-active}")
private int maxActive; // private int maxActive;
@Value("${spring.redis.max-wait}") // @Value("${spring.redis.max-wait}")
private long maxWaitMillis; // private long maxWaitMillis;
@Value("${spring.redis.max-idle}") // @Value("${spring.redis.max-idle}")
private int maxIdle; // private int maxIdle;
//
@Bean // @Bean
public JedisPoolConfig jedisPoolConfig() { // public JedisPoolConfig jedisPoolConfig() {
JedisPoolConfig jedisPoolConfig = new JedisPoolConfig(); // JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
// maximum connection // // maximum connection
jedisPoolConfig.setMaxTotal(maxActive); // jedisPoolConfig.setMaxTotal(maxActive);
// Maximum wait time when no connection is available in the pool // // Maximum wait time when no connection is available in the pool
jedisPoolConfig.setMaxWaitMillis(maxWaitMillis); // jedisPoolConfig.setMaxWaitMillis(maxWaitMillis);
// Maximum number of idle connections // // Maximum number of idle connections
jedisPoolConfig.setMinIdle(maxIdle); // jedisPoolConfig.setMinIdle(maxIdle);
// Other properties can be added by yourself // // Other properties can be added by yourself
return jedisPoolConfig; // return jedisPoolConfig;
} // }
//
@Bean // @Bean
public JedisConnectionFactory jedisConnectionFactory(JedisPoolConfig jedisPoolConfig) { // public JedisConnectionFactory jedisConnectionFactory(JedisPoolConfig jedisPoolConfig) {
JedisClientConfiguration jedisClientConfiguration = JedisClientConfiguration.builder().usePooling() // JedisClientConfiguration jedisClientConfiguration = JedisClientConfiguration.builder().usePooling()
.poolConfig(jedisPoolConfig).and().readTimeout(Duration.ofMillis(timeout)).build(); // .poolConfig(jedisPoolConfig).and().readTimeout(Duration.ofMillis(timeout)).build();
RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration(); // RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration();
redisStandaloneConfiguration.setHostName(host); // redisStandaloneConfiguration.setHostName(host);
redisStandaloneConfiguration.setPort(port); // redisStandaloneConfiguration.setPort(port);
redisStandaloneConfiguration.setPassword(RedisPassword.of(password)); // redisStandaloneConfiguration.setPassword(RedisPassword.of(password));
return new JedisConnectionFactory(redisStandaloneConfiguration, jedisClientConfiguration); // return new JedisConnectionFactory(redisStandaloneConfiguration, jedisClientConfiguration);
} // }
//
@Bean // @Bean
public RedisTemplate<String, Object> redisTemplate() { // public RedisTemplate<String, Object> redisTemplate() {
RedisTemplate<String, Object> template = new RedisTemplate<>(); // RedisTemplate<String, Object> template = new RedisTemplate<>();
template.setConnectionFactory(jedisConnectionFactory(jedisPoolConfig())); // template.setConnectionFactory(jedisConnectionFactory(jedisPoolConfig()));
//
return template; // return template;
} // }
//
/** // /**
* cache // * cache
*/ // */
@Bean // @Bean
public RedisCacheManagerBuilderCustomizer redisCacheManagerBuilderCustomizer() { // public RedisCacheManagerBuilderCustomizer redisCacheManagerBuilderCustomizer() {
return (builder) -> RedisCacheManager.RedisCacheManagerBuilder.fromConnectionFactory(jedisConnectionFactory(jedisPoolConfig())) // return (builder) -> RedisCacheManager.RedisCacheManagerBuilder.fromConnectionFactory(jedisConnectionFactory(jedisPoolConfig()))
.withCacheConfiguration("tempCache", // .withCacheConfiguration("tempCache",
RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofSeconds(10))) // RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofSeconds(10)))
.withCacheConfiguration("longCache", // .withCacheConfiguration("longCache",
RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofDays(7))); // RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofDays(7)));
} // }
//
@Bean("communityKeyGenerator") // @Bean("communityKeyGenerator")
public KeyGenerator keyGenerator() { // public KeyGenerator keyGenerator() {
return new RedisConfig.CommunityKeyGenerator(); // return new RedisConfig.CommunityKeyGenerator();
} // }
//
public static class CommunityKeyGenerator implements KeyGenerator { // public static class CommunityKeyGenerator implements KeyGenerator {
public Object generate(Object target, Method method, Object... params) { // public Object generate(Object target, Method method, Object... params) {
// todo prefix 加到common // // todo prefix 加到common
return "new_community_" + target.getClass().getSimpleName() + "_" // return "new_community_" + target.getClass().getSimpleName() + "_"
+ method.getName() + "_" // + method.getName() + "_"
+ StringUtils.arrayToDelimitedString(params, "_"); // + StringUtils.arrayToDelimitedString(params, "_");
} // }
} // }
} //}
package com.tanpu.community.controller; package com.tanpu.community.controller;
import com.tanpu.community.api.beans.CommentReq;
import com.tanpu.community.api.beans.ForwardThemeDTO; import com.tanpu.community.api.beans.ForwardThemeDTO;
import com.tanpu.community.api.beans.ThemeDTO; import com.tanpu.community.api.beans.ThemeDTO;
import com.tanpu.community.manager.ThemeManager; import com.tanpu.community.manager.ThemeManager;
...@@ -52,9 +53,9 @@ public class ThemeController { ...@@ -52,9 +53,9 @@ public class ThemeController {
@ApiOperation("评论") @ApiOperation("评论")
@RequestMapping(value = "/comment") @RequestMapping(value = "/comment")
@ResponseBody @ResponseBody
public String commetOnTheme(String themeId,String commet){ public String commetOnTheme(@RequestBody CommentReq req){
String user="liujm"; String userId="liujm";
// themeManager.comment(themeId,user,commet); themeManager.comment(req,userId);
return "success"; return "success";
} }
......
package com.tanpu.community.manager; package com.tanpu.community.manager;
import com.tanpu.community.api.beans.CommentReq;
import com.tanpu.community.api.beans.ForwardThemeDTO; import com.tanpu.community.api.beans.ForwardThemeDTO;
import com.tanpu.community.api.beans.ThemeDTO; import com.tanpu.community.api.beans.ThemeDTO;
import com.tanpu.community.api.constants.BlockTypeEnum; import com.tanpu.community.api.constants.BlockTypeEnum;
...@@ -104,11 +105,12 @@ public class ThemeManager { ...@@ -104,11 +105,12 @@ public class ThemeManager {
} }
// 评论(对主题) // 评论(对主题)
public void commentToTheme(String themeId, String userId, String comment) { public void comment(CommentReq req, String userId) {
CommentEntity commentEntity = CommentEntity.builder() CommentEntity commentEntity = CommentEntity.builder()
.targetId(themeId) .targetId(req.getThemeId())
.authorId(userId) .authorId(userId)
.content(comment) .createBy(userId)
.content(req.getComment())
.commentType(CommentTypeEnum.THEME.getCode()) .commentType(CommentTypeEnum.THEME.getCode())
.build(); .build();
......
...@@ -12,7 +12,9 @@ import com.tanpu.community.util.ConvertUtil; ...@@ -12,7 +12,9 @@ import com.tanpu.community.util.ConvertUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Service @Service
...@@ -83,8 +85,11 @@ public class TopicManager { ...@@ -83,8 +85,11 @@ public class TopicManager {
public TopicDTO getDetail(String topicId) { public TopicDTO getDetail(String topicId) {
TopicEntity topicEntity = topicService.queryById(topicId); TopicEntity topicEntity = topicService.queryById(topicId);
if (topicEntity == null) {
throw new BizException("找不到话题,id:" + topicId);
}
TopicDTO topicDTO = ConvertUtil.topicEntityToDTO(topicEntity); TopicDTO topicDTO = ConvertUtil.topicEntityToDTO(topicEntity);
topicDTO.setViewAmount(redisService.getLong(RedisKeyConstant.TOPIC_VIEW_AMOUNT_ + topicId)); topicDTO.setViewAmount(redisService.getLong(RedisKeyConstant.TOPIC_TOTAL_VIEW_AMOUNT_ + topicId));
topicDTO.setLikeAmount(redisService.getLong(RedisKeyConstant.TOPIC_LIKE_AMOUNT_ + topicId)); topicDTO.setLikeAmount(redisService.getLong(RedisKeyConstant.TOPIC_LIKE_AMOUNT_ + topicId));
topicDTO.setUserAmount(redisService.getLong(RedisKeyConstant.TOPIC_USER_AMOUNT_ + topicId)); topicDTO.setUserAmount(redisService.getLong(RedisKeyConstant.TOPIC_USER_AMOUNT_ + topicId));
return topicDTO; return topicDTO;
...@@ -111,6 +116,10 @@ public class TopicManager { ...@@ -111,6 +116,10 @@ public class TopicManager {
Long likeAmountByThemeIds = collectionService.getLikeAmountByThemeIds(themeIds); Long likeAmountByThemeIds = collectionService.getLikeAmountByThemeIds(themeIds);
Long bookAmountByThemeIds = collectionService.getBookAmountByThemeIds(themeIds); Long bookAmountByThemeIds = collectionService.getBookAmountByThemeIds(themeIds);
Long commentAmountByThemeIds = commentService.getCommentAmountByThemeIds(themeIds); Long commentAmountByThemeIds = commentService.getCommentAmountByThemeIds(themeIds);
Set<String> postUsers = themeService.getPostUserAmount(themeIds);
Set<String> commentUsers = commentService.getCommentUserAmount(themeIds);
HashSet<String> totalUsers = new HashSet<>(postUsers);
totalUsers.addAll(commentUsers);
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);
...@@ -118,10 +127,11 @@ public class TopicManager { ...@@ -118,10 +127,11 @@ public class TopicManager {
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_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_USER_POST_AMOUNT_ + topicId, commentAmountByThemeIds + themeIds.size()); redisService.set(RedisKeyConstant.TOPIC_POST_USER_AMOUNT_ + topicId, (long) postUsers.size());
redisService.set(RedisKeyConstant.TOPIC_USER_COMMET_AMOUNT_ + topicId, commentAmountByThemeIds + themeIds.size()); redisService.set(RedisKeyConstant.TOPIC_COMMENT_USER_AMOUNT_ + topicId, (long) commentUsers.size());
redisService.set(RedisKeyConstant.TOPIC_TOTAL_USER_AMOUNT_ + topicId, (long) totalUsers.size());
} }
...@@ -131,17 +141,19 @@ public class TopicManager { ...@@ -131,17 +141,19 @@ public class TopicManager {
public TopicDataAnalysDTO queryDataAnalysis(String topicId) { public TopicDataAnalysDTO queryDataAnalysis(String topicId) {
TopicDataAnalysDTO topicDataAnalysDTO = new TopicDataAnalysDTO(); TopicDataAnalysDTO topicDataAnalysDTO = new TopicDataAnalysDTO();
TopicEntity topicEntity = topicService.queryById(topicId); TopicEntity topicEntity = topicService.queryById(topicId);
if (topicEntity == null) {
throw new BizException("话题未找到,id:" + topicId);
}
this.refreshRedisCache(); this.refreshRedisCache();
topicDataAnalysDTO.setId(topicId); topicDataAnalysDTO.setId(topicId);
topicDataAnalysDTO.setTopicTitle(topicEntity.getTopicTitle()); topicDataAnalysDTO.setTopicTitle(topicEntity.getTopicTitle());
// topicDataAnalysDTO.setCommentAmount(); topicDataAnalysDTO.setCommentAmount(redisService.getInteger(RedisKeyConstant.TOPIC_COMMENT_AMOUNT_ + topicId));
// topicDataAnalysDTO.setPosterAmount(); topicDataAnalysDTO.setPosterAmount(redisService.getInteger(RedisKeyConstant.TOPIC_POST_USER_AMOUNT_ + topicId));
// topicDataAnalysDTO.setReplIierAmount(); topicDataAnalysDTO.setReplIierAmount(redisService.getInteger(RedisKeyConstant.TOPIC_COMMENT_USER_AMOUNT_ + topicId));
// topicDataAnalysDTO.setThemeAmount(); topicDataAnalysDTO.setThemeAmount(redisService.getInteger(RedisKeyConstant.TOPIC_THEME_AMOUNT_ + topicId));
// topicDataAnalysDTO.setUserTotalAmount(); topicDataAnalysDTO.setUserTotalAmount(redisService.getInteger(RedisKeyConstant.TOPIC_TOTAL_USER_AMOUNT_ + topicId));
// topicDataAnalysDTO.setViewTotalAmount(); topicDataAnalysDTO.setViewTotalAmount(redisService.getInteger(RedisKeyConstant.TOPIC_TOTAL_VIEW_AMOUNT_ + topicId));
// topicDataAnalysDTO.setViewPageAmount(); topicDataAnalysDTO.setViewPageAmount(redisService.getInteger(RedisKeyConstant.TOPIC_PAGE_VIEW_AMOUNT_ + topicId));
// topicDataAnalysDTO.setCommentAmount();
return topicDataAnalysDTO; return topicDataAnalysDTO;
} }
} }
......
...@@ -40,7 +40,7 @@ public class CollectionService { ...@@ -40,7 +40,7 @@ public class CollectionService {
//根据用户、主题、类型查询 //根据用户、主题、类型查询
public CollectionEntity getTargetCollection(String themeId, String userId, CollectionTypeEnum type) { public CollectionEntity getTargetCollection(String themeId, String userId, CollectionTypeEnum type) {
return collectionMapper.selectOne(new LambdaQueryWrapper<CollectionEntity>() return collectionMapper.selectOne(new LambdaQueryWrapper<CollectionEntity>()
.eq(CollectionEntity::getCollectionType, type) .eq(CollectionEntity::getCollectionType, type.getCode())
.eq(CollectionEntity::getAuthorId, userId) .eq(CollectionEntity::getAuthorId, userId)
.eq(CollectionEntity::getTargetId, themeId)); .eq(CollectionEntity::getTargetId, themeId));
} }
......
...@@ -7,6 +7,8 @@ import org.springframework.stereotype.Service; ...@@ -7,6 +7,8 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
@Service @Service
public class CommentService { public class CommentService {
...@@ -29,4 +31,10 @@ public class CommentService { ...@@ -29,4 +31,10 @@ public class CommentService {
.in(CommentEntity::getTargetId, themeIds))) .in(CommentEntity::getTargetId, themeIds)))
.size(); .size();
} }
public Set<String> getCommentUserAmount(List<String> themeIds) {
return commentMapper.selectList((new LambdaQueryWrapper<CommentEntity>()
.in(CommentEntity::getTargetId, themeIds)))
.stream().map(CommentEntity::getAuthorId).collect(Collectors.toSet());
}
} }
...@@ -7,6 +7,8 @@ import org.springframework.stereotype.Service; ...@@ -7,6 +7,8 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
@Service @Service
public class ThemeService { public class ThemeService {
...@@ -41,4 +43,11 @@ public class ThemeService { ...@@ -41,4 +43,11 @@ public class ThemeService {
return themeMapper.selectList(new LambdaQueryWrapper<ThemeEntity>() return themeMapper.selectList(new LambdaQueryWrapper<ThemeEntity>()
.orderByDesc(ThemeEntity::getUpdateTime)); .orderByDesc(ThemeEntity::getUpdateTime));
} }
//查询对应话题的发表用户集合
public Set<String> getPostUserAmount(List<String> themeIds) {
return themeMapper.selectBatchIds(themeIds).stream()
.map(ThemeEntity::getAuthorId)
.collect(Collectors.toSet());
}
} }
...@@ -21,13 +21,13 @@ public class TopicService { ...@@ -21,13 +21,13 @@ public class TopicService {
private TopicMapper topicMapper; private TopicMapper topicMapper;
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()));
} }
public void addTopic(String topicTitle,String userId){ public void addTopic(String topicTitle, String userId) {
TopicEntity entity = TopicEntity.builder() TopicEntity entity = TopicEntity.builder()
.topicTitle(topicTitle) .topicTitle(topicTitle)
.createBy(userId) .createBy(userId)
...@@ -40,44 +40,44 @@ public class TopicService { ...@@ -40,44 +40,44 @@ 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(TopicStatusEnum.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(TopicStatusEnum.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(TopicStatusEnum.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(TopicStatusEnum.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.selectById(topicId); return topicMapper.selectById(topicId);
} }
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(); Long oldAmount = topicEntity.getViewAmountModify();
topicEntity.setViewAmountModify(topicEntity.getViewAmountModify() + amount); topicEntity.setViewAmountModify(topicEntity.getViewAmountModify() + amount);
topicMapper.update(topicEntity,new LambdaUpdateWrapper<TopicEntity>() topicMapper.update(topicEntity, new LambdaUpdateWrapper<TopicEntity>()
.eq(TopicEntity::getViewAmountModify,oldAmount)); .eq(TopicEntity::getViewAmountModify, oldAmount));
return; return;
} }
} }
...@@ -54,7 +54,7 @@ CREATE TABLE `comment` ( ...@@ -54,7 +54,7 @@ CREATE TABLE `comment` (
`content` text COMMENT '文本内容', `content` text COMMENT '文本内容',
`author_id` varchar(64) NOT NULL COMMENT '作者id', `author_id` varchar(64) NOT NULL COMMENT '作者id',
`target_id` varchar(64) NOT NULL COMMENT '评论的目标id', `target_id` varchar(64) NOT NULL COMMENT '评论的目标id',
`is_block` int(4) NOT NULL COMMENT '是否屏蔽', `is_block` int(4) NOT NULL DEFAULT '0' COMMENT '是否屏蔽',
`create_by` varchar(64) DEFAULT '', `create_by` varchar(64) DEFAULT '',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`update_by` varchar(64) DEFAULT '', `update_by` varchar(64) DEFAULT '',
......
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