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

转发详情

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