Commit 1ddb2104 authored by 刘基明's avatar 刘基明

转发详情

parent bd6f25f5
...@@ -18,5 +18,8 @@ public class TopicTitileQo { ...@@ -18,5 +18,8 @@ public class TopicTitileQo {
private String topicTitle; private String topicTitle;
@ApiModelProperty("讨论数") @ApiModelProperty("讨论数")
private Integer discussionCount; private String discussionCount;
@ApiModelProperty("浏览量")
private String viewCount;
} }
...@@ -26,11 +26,11 @@ public class CreateThemeReq { ...@@ -26,11 +26,11 @@ public class CreateThemeReq {
private List<ThemeContentReq> content; private List<ThemeContentReq> content;
@ApiModelProperty(value = "所属的话题id") @ApiModelProperty(value = "所属的话题id")
private String topicId; private String topicId="";
@ApiModelProperty(value = "修改,则传入正在编辑的ThemeId") @ApiModelProperty(value = "修改,则传入正在编辑的ThemeId")
private String editThemeId; private String editThemeId="";
} }
...@@ -21,8 +21,8 @@ public class ForwardThemeReq { ...@@ -21,8 +21,8 @@ public class ForwardThemeReq {
private List<ThemeContentReq> content; private List<ThemeContentReq> content;
@ApiModelProperty(value = "话题Id") @ApiModelProperty(value = "话题Id")
private String topicId; private String topicId="";
@ApiModelProperty(value = "修改,则传入正在编辑的ThemeId") @ApiModelProperty(value = "修改,则传入正在编辑的ThemeId")
private String editThemeId; private String editThemeId="";
} }
...@@ -4,14 +4,22 @@ package com.tanpu.community.api.beans.req.theme; ...@@ -4,14 +4,22 @@ package com.tanpu.community.api.beans.req.theme;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.NotNull;
@Data @Data
public class ThemeListByTopicReq { public class ThemeListByTopicReq {
@ApiModelProperty(value = "当前浏览的最后一个themeId") @ApiModelProperty(value = "当前浏览的最后一个themeId")
private String lastId; private String lastId="";
@NotNull
@ApiModelProperty(value = "页面大小") @ApiModelProperty(value = "页面大小")
private Integer PageSize; private Integer PageSize;
@NotNull
@ApiModelProperty(value = "类型,1:最热 2:最新") @ApiModelProperty(value = "类型,1:最热 2:最新")
private Integer type; private Integer type;
@NotNull
@ApiModelProperty(value = "话题Id") @ApiModelProperty(value = "话题Id")
private String topicId; private String topicId;
......
...@@ -18,7 +18,7 @@ public class ThemeListReq { ...@@ -18,7 +18,7 @@ public class ThemeListReq {
private String topicId; private String topicId;
@ApiModelProperty(value = "当前浏览的最后一个themeId,可以为空") @ApiModelProperty(value = "当前浏览的最后一个themeId,可以为空")
private String lastId; private String lastId="";
@NotNull(message = "PageSize不能为空") @NotNull(message = "PageSize不能为空")
@ApiModelProperty(value = "页面大小") @ApiModelProperty(value = "页面大小")
......
package com.tanpu.community.api.beans.resp;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@ApiModel(value = "创建主题")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CreateThemeResp {
@ApiModelProperty(value = "主题id")
private String themeId;
}
...@@ -25,6 +25,6 @@ public class TestController { ...@@ -25,6 +25,6 @@ public class TestController {
@GetMapping(value = "/1") @GetMapping(value = "/1")
@ResponseBody @ResponseBody
public Object sendKafka() { public Object sendKafka() {
return userInfoService.selectById("USER_INFO15912897523789"); return userInfoService.queryUserById("USER_INFO15912897523789");
} }
} }
...@@ -7,6 +7,7 @@ import com.tanpu.common.auth.UserHolder; ...@@ -7,6 +7,7 @@ import com.tanpu.common.auth.UserHolder;
import com.tanpu.common.exception.BizException; import com.tanpu.common.exception.BizException;
import com.tanpu.community.api.beans.qo.ThemeQo; import com.tanpu.community.api.beans.qo.ThemeQo;
import com.tanpu.community.api.beans.req.theme.*; import com.tanpu.community.api.beans.req.theme.*;
import com.tanpu.community.api.beans.resp.CreateThemeResp;
import com.tanpu.community.manager.ThemeManager; import com.tanpu.community.manager.ThemeManager;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -32,13 +33,12 @@ public class ThemeController { ...@@ -32,13 +33,12 @@ public class ThemeController {
@ApiOperation("发表主题") @ApiOperation("发表主题")
@PostMapping(value = "/publish") @PostMapping(value = "/publish")
@ResponseBody @ResponseBody
public CommonResp<Void> publishTheme(@Validated @RequestBody CreateThemeReq req) { public CommonResp<CreateThemeResp> publishTheme(@Validated @RequestBody CreateThemeReq req) {
String userId = userHolder.getUserId(); String userId = userHolder.getUserId();
if(StringUtils.isEmpty(userId)){ if(StringUtils.isEmpty(userId)){
throw new BizException("用户为空"); throw new BizException("用户为空");
} }
themeManager.publishTheme(req, userId); return CommonResp.success(themeManager.publishTheme(req, userId));
return CommonResp.success();
} }
@AuthLogin @AuthLogin
......
...@@ -61,7 +61,7 @@ public class CommentManager { ...@@ -61,7 +61,7 @@ public class CommentManager {
for (CommentQo commentQo : commentQos) { for (CommentQo commentQo : commentQos) {
//用户信息 //用户信息
String authorId = commentQo.getAuthorId(); String authorId = commentQo.getAuthorId();
UserInfoEntity userInfo = userInfoService.selectById(authorId); UserInfoEntity userInfo = userInfoService.queryUserById(authorId);
if (userInfo != null) { if (userInfo != null) {
commentQo.setUserImg(userInfo.getUiHeadimg()); commentQo.setUserImg(userInfo.getUiHeadimg());
commentQo.setNickName(userInfo.getUiNickname()); commentQo.setNickName(userInfo.getUiNickname());
......
...@@ -34,7 +34,7 @@ public class HomePageManager { ...@@ -34,7 +34,7 @@ public class HomePageManager {
public Page<FollowQo> queryFollow(QueryFollowReq req, String userId) { public Page<FollowQo> queryFollow(QueryFollowReq req, String userId) {
List<String> userIds = QueryFollowTypeEnum.QUERY_FANS.getCode().equals(req.getQueryType()) ? List<String> userIds = QueryFollowTypeEnum.QUERY_FANS.getCode().equals(req.getQueryType()) ?
followRelService.queryFansByIdolId(req.getUserId()) : followRelService.queryFansByFollowerId(req.getUserId()); followRelService.queryFansByIdolId(req.getUserId()) : followRelService.queryFansByFollowerId(req.getUserId());
List<UserInfoEntity> userInfos = userInfoService.selectByIds(userIds); List<UserInfoEntity> userInfos = userInfoService.queryUserByIds(userIds);
List<FollowQo> collect = userInfos.stream().map(ConvertUtil::homePageEntity2FollowQo).collect(Collectors.toList()); List<FollowQo> collect = userInfos.stream().map(ConvertUtil::homePageEntity2FollowQo).collect(Collectors.toList());
List<FollowQo> followQos = judgeFollowed(collect, userId); List<FollowQo> followQos = judgeFollowed(collect, userId);
return PageUtils.page(req.getPage(), followQos); return PageUtils.page(req.getPage(), followQos);
......
...@@ -7,6 +7,7 @@ import com.tanpu.community.api.beans.qo.ThemeContentQo; ...@@ -7,6 +7,7 @@ import com.tanpu.community.api.beans.qo.ThemeContentQo;
import com.tanpu.community.api.beans.qo.ThemeQo; import com.tanpu.community.api.beans.qo.ThemeQo;
import com.tanpu.community.api.beans.req.homepage.QueryRecordThemeReq; import com.tanpu.community.api.beans.req.homepage.QueryRecordThemeReq;
import com.tanpu.community.api.beans.req.theme.*; 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.*;
import com.tanpu.community.dao.entity.community.*; import com.tanpu.community.dao.entity.community.*;
import com.tanpu.community.dao.entity.user.UserInfoEntity; import com.tanpu.community.dao.entity.user.UserInfoEntity;
...@@ -58,7 +59,7 @@ public class ThemeManager { ...@@ -58,7 +59,7 @@ public class ThemeManager {
@Transactional @Transactional
public void publishTheme(CreateThemeReq req, String userId) { public CreateThemeResp publishTheme(CreateThemeReq req, String userId) {
//TODO 敏感词过滤 //TODO 敏感词过滤
...@@ -78,6 +79,7 @@ public class ThemeManager { ...@@ -78,6 +79,7 @@ public class ThemeManager {
//保存附件表 //保存附件表
List<ThemeAttachmentEntity> themeAttachments = ConvertUtil.themeReqToAttachmentList(req, themeEntity.getThemeId()); List<ThemeAttachmentEntity> themeAttachments = ConvertUtil.themeReqToAttachmentList(req, themeEntity.getThemeId());
themeAttachmentService.insertList(themeAttachments); themeAttachmentService.insertList(themeAttachments);
return CreateThemeResp.builder().themeId(themeEntity.getThemeId()).build();
} }
// 返回推荐主题文章 // 返回推荐主题文章
...@@ -111,14 +113,14 @@ public class ThemeManager { ...@@ -111,14 +113,14 @@ public class ThemeManager {
List<ThemeEntity> themeEntities = Collections.emptyList(); List<ThemeEntity> themeEntities = Collections.emptyList();
switch (req.getRecordType()) { switch (req.getRecordType()) {
case 1://发布 case 1://发布
themeEntities = themeService.queryThemeIdsByUserId(req.getUserId(), req.getLastId(), req.getPageSize()); themeEntities = themeService.queryThemesByUserId(req.getUserId(), req.getLastId(), req.getPageSize());
break; break;
case 2://回复 case 2://回复
List<ThemeQo> commentThemeList = new ArrayList<>(); List<ThemeQo> commentThemeList = new ArrayList<>();
//评论列表 //评论列表
List<CommentEntity> commentEntities = commentService.queryThemesByUserId(req.getUserId(), req.getLastId(), req.getPageSize()); List<CommentEntity> commentEntities = commentService.queryThemesByUserId(req.getUserId(), req.getLastId(), req.getPageSize());
//当前用户信息 //当前用户信息
UserInfoEntity userInfoEntity = userInfoService.selectById(req.getUserId()); UserInfoEntity userInfoEntity = userInfoService.queryUserById(req.getUserId());
Set<String> replyThemeIds = commentEntities.stream().map(CommentEntity::getThemeId).collect(Collectors.toSet()); Set<String> replyThemeIds = commentEntities.stream().map(CommentEntity::getThemeId).collect(Collectors.toSet());
if (CollectionUtils.isEmpty(replyThemeIds)) { if (CollectionUtils.isEmpty(replyThemeIds)) {
return commentThemeList; return commentThemeList;
......
...@@ -68,7 +68,11 @@ public class TopicManager { ...@@ -68,7 +68,11 @@ public class TopicManager {
//讨论数=发布主题贴数+回复总数 //讨论数=发布主题贴数+回复总数
List<String> themeIds = themeService.queryThemeIdsByTopic(topicQo.getTopicId()); List<String> themeIds = themeService.queryThemeIdsByTopic(topicQo.getTopicId());
Integer commentCount = commentService.getCommentCountByThemeIds(themeIds); Integer commentCount = commentService.getCommentCountByThemeIds(themeIds);
topicQo.setDiscussionCount(themeIds.size() + commentCount); topicQo.setDiscussionCount(String.valueOf(themeIds.size() + commentCount));
//浏览量
Integer topicPV = visitSummaryService.queryTopicDetailVisit(topicQo.getTopicId());
Integer themePV = visitSummaryService.queryThemeVisit(themeIds);
topicQo.setViewCount(String.valueOf(topicPV + themePV));
} }
//TODO 判断顶置 //TODO 判断顶置
return PageUtils.page(req.getPage(), topicTitileQos); return PageUtils.page(req.getPage(), topicTitileQos);
......
...@@ -116,7 +116,8 @@ public class OSSFileService { ...@@ -116,7 +116,8 @@ public class OSSFileService {
} }
public FileRecordEntity queryById(String fileId) { public FileRecordEntity queryById(String fileId) {
return fileRecordMapper.selectById(fileId); return fileRecordMapper.selectOne(new LambdaQueryWrapper<FileRecordEntity>()
.eq(FileRecordEntity::getFileId,fileId));
} }
public List<FileRecordEntity> queryByIds(List<String> fileIds) { public List<FileRecordEntity> queryByIds(List<String> fileIds) {
......
...@@ -239,7 +239,7 @@ public class ProductService { ...@@ -239,7 +239,7 @@ public class ProductService {
if (!CollectionUtils.isEmpty(userIds)) { if (!CollectionUtils.isEmpty(userIds)) {
// 查询用户信息 // 查询用户信息
List<UserInfoEntity> userInfos = List<UserInfoEntity> userInfos =
userInfoService.selectByIds(setToList(userIds)); userInfoService.queryUserByIds(setToList(userIds));
if (!CollectionUtils.isEmpty(userIds)) { if (!CollectionUtils.isEmpty(userIds)) {
userMap.putAll(userInfos.stream().collect(Collectors userMap.putAll(userInfos.stream().collect(Collectors
.toMap(UserInfoEntity::getId, o -> o))); .toMap(UserInfoEntity::getId, o -> o)));
......
...@@ -44,14 +44,14 @@ public class ThemeService { ...@@ -44,14 +44,14 @@ public class ThemeService {
.eq(ThemeEntity::getThemeId,themeId)); .eq(ThemeEntity::getThemeId,themeId));
} }
public List<ThemeEntity> queryThemeIdsByUserId(String userId) { public List<ThemeEntity> queryThemesByUserId(String userId) {
return themeMapper.selectList(new LambdaQueryWrapper<ThemeEntity>() return themeMapper.selectList(new LambdaQueryWrapper<ThemeEntity>()
.eq(ThemeEntity::getAuthorId,userId) .eq(ThemeEntity::getAuthorId,userId)
.eq(ThemeEntity::getDeleteTag,DeleteTagEnum.NOT_DELETED.getCode()) .eq(ThemeEntity::getDeleteTag,DeleteTagEnum.NOT_DELETED.getCode())
.orderByDesc(ThemeEntity::getId)); .orderByDesc(ThemeEntity::getId));
} }
public List<ThemeEntity> queryThemeIdsByUserId(String userId, String lastId,Integer pageSize) { public List<ThemeEntity> queryThemesByUserId(String userId, String lastId, Integer pageSize) {
LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>() LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>()
.eq(ThemeEntity::getAuthorId, userId) .eq(ThemeEntity::getAuthorId, userId)
.eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode()) .eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode())
...@@ -94,15 +94,19 @@ public class ThemeService { ...@@ -94,15 +94,19 @@ public class ThemeService {
//分页倒叙lastId之前的主题 //分页倒叙lastId之前的主题
public List<ThemeEntity> selectAll(String lastId,Integer pageSize) { public List<ThemeEntity> selectAll(String lastId,Integer pageSize) {
LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>() LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>();
.orderByDesc(ThemeEntity::getUpdateTime);
if (StringUtils.isNotEmpty(lastId)) { if (StringUtils.isNotEmpty(lastId)) {
ThemeEntity lastEntity = queryByThemeId(lastId); ThemeEntity lastEntity = queryByThemeId(lastId);
if (lastEntity==null) throw new BizException("主题未找到,id:"+lastId); if (lastEntity==null) throw new BizException("主题未找到,id:"+lastId);
queryWrapper.lt(ThemeEntity::getUpdateTime, lastEntity.getCreateTime()); queryWrapper.lt(ThemeEntity::getUpdateTime, lastEntity.getCreateTime());
} }
queryWrapper.last("limit "+pageSize); queryWrapper.last("limit "+pageSize);
queryWrapper.orderByDesc(ThemeEntity::getId); queryWrapper.orderByDesc(ThemeEntity::getId);
queryWrapper.orderByDesc(ThemeEntity::getCreateTime);
queryWrapper.eq(ThemeEntity::getDeleteTag,DeleteTagEnum.NOT_DELETED.getCode());
return themeMapper.selectList(queryWrapper); return themeMapper.selectList(queryWrapper);
} }
...@@ -125,7 +129,8 @@ public class ThemeService { ...@@ -125,7 +129,8 @@ public class ThemeService {
if (pageSize!=null){ 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());
return themeMapper.selectList(queryWrapper); return themeMapper.selectList(queryWrapper);
} }
...@@ -144,15 +149,15 @@ public class ThemeService { ...@@ -144,15 +149,15 @@ public class ThemeService {
//关注的主题列表 //关注的主题列表
public List<ThemeEntity> queryByUserIds(List<String> userIds, String lastId, Integer pageSize) { public List<ThemeEntity> queryByUserIds(List<String> userIds, String lastId, Integer pageSize) {
LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>() LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>()
.in(ThemeEntity::getAuthorId, userIds) .in(ThemeEntity::getAuthorId, userIds);
.orderByDesc(ThemeEntity::getUpdateTime);
if (StringUtils.isNotEmpty(lastId)) { if (StringUtils.isNotEmpty(lastId)) {
ThemeEntity lastEntity = queryByThemeId(lastId); ThemeEntity lastEntity = queryByThemeId(lastId);
if (lastEntity==null) throw new BizException("主题未找到,id:"+lastId); if (lastEntity==null) throw new BizException("主题未找到,id:"+lastId);
queryWrapper.lt(ThemeEntity::getUpdateTime, lastEntity.getCreateTime()); queryWrapper.lt(ThemeEntity::getUpdateTime, lastEntity.getCreateTime());
} }
queryWrapper.last("limit "+pageSize); queryWrapper.last("limit "+pageSize);
queryWrapper.orderByDesc(ThemeEntity::getCreateTime);
queryWrapper.eq(ThemeEntity::getDeleteTag,DeleteTagEnum.NOT_DELETED.getCode());
return themeMapper.selectList(queryWrapper); return themeMapper.selectList(queryWrapper);
} }
......
...@@ -7,12 +7,14 @@ import com.tanpu.community.api.enums.DeleteTagEnum; ...@@ -7,12 +7,14 @@ import com.tanpu.community.api.enums.DeleteTagEnum;
import com.tanpu.community.api.enums.TopicStatusEnum; import com.tanpu.community.api.enums.TopicStatusEnum;
import com.tanpu.community.dao.entity.community.TopicEntity; import com.tanpu.community.dao.entity.community.TopicEntity;
import com.tanpu.community.dao.mapper.community.TopicMapper; import com.tanpu.community.dao.mapper.community.TopicMapper;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.annotation.EnableCaching;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Collections;
import java.util.List; import java.util.List;
...@@ -83,11 +85,14 @@ public class TopicService { ...@@ -83,11 +85,14 @@ public class TopicService {
} }
public List<TopicEntity> queryByIds(List<String> topicIds) { public List<TopicEntity> queryByIds(List<String> 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) { public void modifyViewCount(String topicId, long Count) {
TopicEntity topicEntity = topicMapper.selectById(topicId); TopicEntity topicEntity = queryById(topicId);
Long oldCount = topicEntity.getviewCntAdjust(); Long oldCount = topicEntity.getviewCntAdjust();
topicEntity.setViewAmountModify(topicEntity.getviewCntAdjust() + Count); topicEntity.setViewAmountModify(topicEntity.getviewCntAdjust() + Count);
topicMapper.update(topicEntity, new LambdaUpdateWrapper<TopicEntity>() topicMapper.update(topicEntity, new LambdaUpdateWrapper<TopicEntity>()
......
...@@ -14,11 +14,11 @@ public class UserInfoService { ...@@ -14,11 +14,11 @@ public class UserInfoService {
private UserInfoMapper userInfoMapper; private UserInfoMapper userInfoMapper;
public UserInfoEntity selectById(String userId) { public UserInfoEntity queryUserById(String userId) {
return userInfoMapper.selectById(userId); return userInfoMapper.selectById(userId);
} }
public List<UserInfoEntity> selectByIds(List<String> ids) { public List<UserInfoEntity> queryUserByIds(List<String> ids) {
return userInfoMapper.selectBatchIds(ids); return userInfoMapper.selectBatchIds(ids);
} }
} }
...@@ -203,4 +203,5 @@ public class ConvertUtil { ...@@ -203,4 +203,5 @@ public class ConvertUtil {
} }
} }
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