Commit 0bf55beb authored by 刘基明's avatar 刘基明

话题接口修改

parent 4e1fe397
......@@ -5,7 +5,7 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
import java.time.LocalDateTime;
/**
* 正文
......@@ -60,8 +60,11 @@ public class MainTextQo {
@ApiModelProperty(value = "点赞量")
private Integer likeCount;
@ApiModelProperty("附件,")
private List<AttachmentQo> attachment;
private LocalDateTime createTime;
private LocalDateTime updateTime;
}
......@@ -64,4 +64,9 @@ public class ThemeQo {
@ApiModelProperty(value = "转发的主题")
private ThemeFormerQo formerTheme;
private LocalDateTime createTime;
private LocalDateTime updateTime;
}
......@@ -2,9 +2,15 @@ package com.tanpu.community.api.beans.qo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ApiModel("话题详情对象")
public class TopicDetailQo {
......@@ -20,6 +26,4 @@ public class TopicDetailQo {
@ApiModelProperty(value = "讨论量")
private Integer disscussCount;
@ApiModelProperty(value = "类型 1:热 2:新")
private Integer type;
}
......@@ -15,7 +15,7 @@ public class TopicTitileQo {
private String topicId;
@ApiModelProperty("话题名称")
private String title;
private String topicTitle;
@ApiModelProperty("讨论数")
private Integer discussionCount;
......
......@@ -4,18 +4,18 @@ package com.tanpu.community.api.beans.req.theme;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
@Data
public class ThemeListReq {
@ApiModelProperty(value = "当前浏览的最后一个themeId,可以为空")
private String lastId;
@NotEmpty(message = "PageSize不能为空")
@NotNull(message = "PageSize不能为空")
@ApiModelProperty(value = "页面大小")
private Integer PageSize;
private Integer pageSize;
@NotEmpty(message = "主题类型不能为空")
@NotNull(message = "主题类型不能为空")
@ApiModelProperty(value = "类型,1:推荐 2:关注")
private Integer type;
......
package com.tanpu.community.api.enums;
public enum ThemeListTypeEnum {
RECOMMEND(1,"推荐列表"),
FOLLOW(2,"关注列表");
private Integer code;
private String type;
ThemeListTypeEnum(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;
}
}
......@@ -2,15 +2,11 @@ package com.tanpu.community.controller;
import com.tanpu.common.api.CommonResp;
import com.tanpu.common.auth.UserHolder;
import com.tanpu.community.api.beans.TopicDO;
import com.tanpu.community.api.beans.TopicDataAnalysDTO;
import com.tanpu.community.api.beans.req.topic.TopicConcealReq;
import com.tanpu.community.api.beans.req.topic.TopicModifyMountReq;
import com.tanpu.community.api.beans.req.topic.TopicTopReq;
import com.tanpu.community.manager.TopicManager;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.annotation.*;
......@@ -35,17 +31,17 @@ public class AdminController {
topicManager.insertTopic(topicTitle,userId);
return CommonResp.success();
}
@ApiOperation("单个话题详细数据")
@GetMapping("/detailData")
@ResponseBody
public CommonResp<TopicDO> selectOne(@RequestParam String topicId) throws MissingServletRequestParameterException {
if (StringUtils.isEmpty(topicId)){
throw new MissingServletRequestParameterException("topicId","String");
}
TopicDO topicDO =topicManager.getDetail(topicId);
return CommonResp.success(topicDO);
}
//
// @ApiOperation("单个话题详细数据")
// @GetMapping("/detailData")
// @ResponseBody
// public CommonResp<TopicDO> selectOne(@RequestParam String topicId) throws MissingServletRequestParameterException {
// if (StringUtils.isEmpty(topicId)){
// throw new MissingServletRequestParameterException("topicId","String");
// }
// TopicDO topicDO =topicManager.getDetail(topicId);
// return CommonResp.success(topicDO);
// }
@PostMapping(value = "/setTop")
@ApiOperation("顶置/取消顶置话题")
......@@ -62,20 +58,20 @@ public class AdminController {
topicManager.setTopicConceal(req.getTopicId(),req.isConceal());
return CommonResp.success();
}
@PostMapping(value = "/modifyViewNum")
@ApiOperation("话题浏览数调整(后台管理)")
@ResponseBody
public CommonResp<Void> modifyViewNum(@RequestBody TopicModifyMountReq req) throws MissingServletRequestParameterException {
topicManager.modifyViewCount(req.getTopicId(),req.getModifyMount());
return CommonResp.success();
}
@GetMapping(value = "/dataAnalyse")
@ApiOperation("话题数据分析")
@ResponseBody
public CommonResp<TopicDataAnalysDTO> dataAnalyse(@RequestParam String topicId) throws MissingServletRequestParameterException {
TopicDataAnalysDTO result =topicManager.queryDataAnalysis(topicId);
return CommonResp.success(result);
}
//
// @PostMapping(value = "/modifyViewNum")
// @ApiOperation("话题浏览数调整(后台管理)")
// @ResponseBody
// public CommonResp<Void> modifyViewNum(@RequestBody TopicModifyMountReq req) throws MissingServletRequestParameterException {
// topicManager.modifyViewCount(req.getTopicId(),req.getModifyMount());
// return CommonResp.success();
// }
//
// @GetMapping(value = "/dataAnalyse")
// @ApiOperation("话题数据分析")
// @ResponseBody
// public CommonResp<TopicDataAnalysDTO> dataAnalyse(@RequestParam String topicId) throws MissingServletRequestParameterException {
// TopicDataAnalysDTO result =topicManager.queryDataAnalysis(topicId);
// return CommonResp.success(result);
// }
}
......@@ -40,10 +40,9 @@ public class ThemeController {
@ApiOperation("圈子首页-推荐/关注")
@PostMapping(value = "/list")
@ResponseBody
public CommonResp<List<ThemeQo>> selectInterestList(@RequestBody ThemeListReq req) {
public CommonResp<List<ThemeQo>> selectInterestList(@Validated @RequestBody ThemeListReq req) {
String userId = "liujm";
List<ThemeQo> result= req.getType()==1?themeManager.selectHotThemes(req,userId)
:themeManager.selectInterestThemes(req,userId);
List<ThemeQo> result= themeManager.queryThemeList(req,userId);
return CommonResp.success(result);
}
......
......@@ -30,7 +30,7 @@ public class TopicController {
@PostMapping(value = "/list")
@ApiOperation("APP全部话题页面,可搜索")
@ResponseBody
public CommonResp<Page<TopicTitileQo>> getTopicBriefInfoList(TopicSearchReq req){
public CommonResp<Page<TopicTitileQo>> getTopicBriefInfoList(@RequestBody TopicSearchReq req){
Page<TopicTitileQo> allTopic = topicManager.getAllTopicBriefInfo(req);
return CommonResp.success(allTopic);
}
......@@ -40,8 +40,8 @@ public class TopicController {
@ResponseBody
public CommonResp<TopicDetailQo> gethotThemes(@RequestParam String topicId){
//todo
return CommonResp.success();
TopicDetailQo detail = topicManager.getDetail(topicId);
return CommonResp.success(detail);
}
......@@ -49,8 +49,7 @@ public class TopicController {
@ApiOperation("首页顶部话题标题列")
@ResponseBody
public CommonResp<List<TopicHotQo>> getTitleList(){
//todo
return CommonResp.success();
return CommonResp.success(topicManager.getHotTopicTitles());
}
......
......@@ -11,6 +11,7 @@ import com.tanpu.community.api.beans.req.theme.ThemeListByTopicReq;
import com.tanpu.community.api.beans.req.theme.ThemeListReq;
import com.tanpu.community.api.enums.BlockTypeEnum;
import com.tanpu.community.api.enums.CollectionTypeEnum;
import com.tanpu.community.api.enums.ThemeListTypeEnum;
import com.tanpu.community.api.enums.ThemeTypeEnum;
import com.tanpu.community.dao.entity.community.BlackListEntity;
import com.tanpu.community.dao.entity.community.HomePageEntity;
......@@ -89,7 +90,6 @@ public class ThemeManager {
private FeignClientForCourse feignClientForCourse;
public void publishTheme(CreateThemeReq req, String userId) {
ThemeEntity themeEntity = new ThemeEntity();
BeanUtils.copyProperties(req, themeEntity);
......@@ -103,25 +103,22 @@ public class ThemeManager {
}
// 返回推荐主题文章
public List<ThemeQo> selectHotThemes(ThemeListReq req, String userId) {
// TODO:推荐
List<ThemeEntity> themeEntities = themeService.selectAll(req.getLastId(),req.getPageSize());
public List<ThemeQo> queryThemeList(ThemeListReq req, String userId) {
List<ThemeEntity> themeEntities;
if (ThemeListTypeEnum.RECOMMEND.getCode().equals(req.getType())) {
// TODO:推荐
themeEntities = themeService.selectAll(req.getLastId(), req.getPageSize());
} else {
List<String> fansList = followRelService.queryFansByFollowerId(userId);
themeEntities = themeService.queryByFans(fansList, req.getLastId(), req.getPageSize());
}
List<ThemeQo> themeQos = convertEntityToQo(themeEntities, userId);
return themeQos;
}
// 返回关注主题
public List<ThemeQo> selectInterestThemes(ThemeListReq req,String userId) {
List<String> fansList = followRelService.queryFansByFollowerId(userId);
List<ThemeEntity> themeEntities = themeService.queryByFans(fansList,req.getLastId(),req.getPageSize());
List<ThemeQo> themeQos = convertEntityToQo(themeEntities, userId);
return themeQos;
}
public List<ThemeQo> queryByTopic(ThemeListByTopicReq req, String userId) {
//TODO
List<ThemeEntity> themeEntities = themeService.queryByTopic(req.getTopicId(),req.getLastId(),req.getPageSize());
List<ThemeEntity> themeEntities = themeService.queryByTopic(req.getTopicId(), req.getLastId(), req.getPageSize());
List<ThemeQo> themeQos = convertEntityToQo(themeEntities, userId);
return themeQos;
}
......@@ -129,13 +126,13 @@ public class ThemeManager {
//返回正文
public MainTextQo getMainText(String themeId, String userId) {
ThemeEntity themeEntity = themeService.queryById(themeId);
ThemeEntity themeEntity = themeService.queryByThemeId(themeId);
if (themeEntity == null) {
throw new BizException("找不到帖子id:" + themeId);
}
MainTextQo mainTextQo = new MainTextQo();
BeanUtils.copyProperties(themeEntity, mainTextQo);
buildMainTestExtraInfo(mainTextQo, userId);
buildMainTestExtraInfo(mainTextQo, userId);
return mainTextQo;
}
......@@ -148,10 +145,9 @@ public class ThemeManager {
}
//转发
public void forward(ForwardThemeReq req, String userId) {
ThemeEntity targetTheme = themeService.queryById(req.getFormerThemeId());
ThemeEntity targetTheme = themeService.queryByThemeId(req.getFormerThemeId());
ThemeEntity newTheme = ThemeEntity.builder()
.content(req.getContent())
.topicId(req.getTopicId())
......@@ -194,9 +190,9 @@ public class ThemeManager {
// 屏蔽(主题)
public void blockTheme(String themeId, String userId) {
blackListService.addBlock(themeId, userId, BlockTypeEnum.THEME);
BlackListEntity selectOne = blackListService.selectOne(themeService.queryById(themeId).getAuthorId(), userId, BlockTypeEnum.USER.getCode());
BlackListEntity selectOne = blackListService.selectOne(themeService.queryByThemeId(themeId).getAuthorId(), userId, BlockTypeEnum.USER.getCode());
if (selectOne == null) {
blackListService.addBlock(themeService.queryById(themeId).getAuthorId(), userId, BlockTypeEnum.USER);
blackListService.addBlock(themeService.queryByThemeId(themeId).getAuthorId(), userId, BlockTypeEnum.USER);
}
}
......@@ -253,9 +249,8 @@ public class ThemeManager {
List<AttachmentQo> attachmentQos = new ArrayList<>();
attachments.forEach(o -> attachmentQos.add(AttachmentQo.builder()
.type(o.getAttachType())
.attachment(transferAttachment(o,userId))
.attachment(transferAttachment(o, userId))
.build()));
maintTextQo.setAttachment(attachmentQos);
}
//迄今时间
maintTextQo.setUpToNowTime(calUpToNowTime(maintTextQo.getCreateTime()));
......
......@@ -3,23 +3,24 @@ package com.tanpu.community.manager;
import com.tanpu.common.exception.BizException;
import com.tanpu.community.api.beans.TopicDO;
import com.tanpu.community.api.beans.TopicDataAnalysDTO;
import com.tanpu.community.api.beans.qo.TopicDetailQo;
import com.tanpu.community.api.beans.qo.TopicHotQo;
import com.tanpu.community.api.beans.qo.TopicTitileQo;
import com.tanpu.community.api.beans.req.topic.TopicSearchReq;
import com.tanpu.community.api.beans.req.page.Page;
import com.tanpu.community.api.beans.req.topic.TopicSearchReq;
import com.tanpu.community.api.constants.RedisKeyConstant;
import com.tanpu.community.api.enums.CollectionTypeEnum;
import com.tanpu.community.dao.entity.community.ThemeEntity;
import com.tanpu.community.dao.entity.community.TopicEntity;
import com.tanpu.community.service.*;
import com.tanpu.community.util.ConvertUtil;
import com.tanpu.community.util.PageUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
@Service
public class TopicManager {
......@@ -58,16 +59,43 @@ public class TopicManager {
public Page<TopicTitileQo> getAllTopicBriefInfo(TopicSearchReq req) {
List<TopicEntity> allTopic = topicService.queryByKeyword(req.getSearchKeyword());
List<TopicTitileQo> topicTitileQos = ConvertUtil.topicEntitiesToBriefDTOs(allTopic);
//讨论数=发布主题贴数+回复总数
for (TopicTitileQo topicQo : topicTitileQos) {
//TODO 讨论数=发布主题贴数+回复总数
// Integer commentCountByThemeIds = commentService.getCommentCountByThemeIds(themeIds);
topicQo.setDiscussionCount(0);
}
//TODO 判断顶置
return PageUtils.page(req.getPage(),topicTitileQos);
}
public TopicDetailQo getDetail(String topicId) {
TopicEntity topicEntity = topicService.queryById(topicId);
if (topicEntity == null) {
throw new BizException("找不到话题,id:" + topicId);
}
TopicDetailQo topicDetailQo = new TopicDetailQo();
BeanUtils.copyProperties(topicEntity,topicDetailQo);
List<String> themeIds = themeService.queryThemeIdsByTopic(topicId);
Integer likeCountByThemeIds = collectionService.getCountByTypeAndIds(themeIds, CollectionTypeEnum.LIKE_THEME);
Integer bookCountByThemeIds = collectionService.getCountByTypeAndIds(themeIds, CollectionTypeEnum.BOOK_THEME);
//TODO 浏览量
topicDetailQo.setViewCount(0);
//讨论数=发布主题贴数+回复总数
Integer commentCount = commentService.getCommentCountByThemeIds(themeIds);
topicDetailQo.setDisscussCount(themeIds.size()+commentCount);
return topicDetailQo;
}
public List<TopicHotQo> getHotTopicTitles(){
List<TopicEntity> topicEntities = topicService.queryAll();
List<TopicHotQo> topicHotQos = ConvertUtil.topicEntityToHotQos(topicEntities);
//TODO 添加类型:热 新 顶
return topicHotQos;
}
public void setTopTopic(String topicId, boolean setTop) {
TopicEntity topicEntity = topicService.queryById(topicId);
......@@ -93,17 +121,7 @@ public class TopicManager {
}
}
public TopicDO getDetail(String topicId) {
TopicEntity topicEntity = topicService.queryById(topicId);
if (topicEntity == null) {
throw new BizException("找不到话题,id:" + topicId);
}
TopicDO topicDO = ConvertUtil.topicEntityToDTO(topicEntity);
topicDO.setViewCount(redisService.getInteger(RedisKeyConstant.TOPIC_TOTAL_VIEW_COUNT_ + topicId));
topicDO.setLikeCount(redisService.getInteger(RedisKeyConstant.TOPIC_LIKE_COUNT_ + topicId));
topicDO.setUserCount(redisService.getInteger(RedisKeyConstant.TOPIC_USER_COUNT_ + topicId));
return topicDO;
}
public void modifyViewCount(String topicId, Long modifyMount) {
TopicEntity topicEntity = topicService.queryById(topicId);
......@@ -125,8 +143,7 @@ public class TopicManager {
for (TopicEntity topic : topicEntities) {
String topicId = topic.getTopicId();
Long viewCountModify = topic.getviewCntAdjust();
List<ThemeEntity> themeEntities = themeService.queryByTopic(topicId,null,null);
List<String> themeIds = themeEntities.stream().map(ThemeEntity::getThemeId).collect(Collectors.toList());
List<String> themeIds = themeService.queryThemeIdsByTopic(topicId);
Integer likeCountByThemeIds = collectionService.getCountByTypeAndIds(themeIds, CollectionTypeEnum.LIKE_THEME);
Integer bookCountByThemeIds = collectionService.getCountByTypeAndIds(themeIds, CollectionTypeEnum.BOOK_THEME);
Long commentCountByThemeIds = (long)commentService.getCommentCountByThemeIds(themeIds);
......
......@@ -68,8 +68,7 @@ public class CollectionService {
}
// 统计单个主题的数量
// 统计单个对象(主题、评论)的数量(点赞、收藏)
public Integer getCountByTypeAndId(String targetId, CollectionTypeEnum type) {
return collectionMapper.selectCount((new LambdaQueryWrapper<CollectionEntity>()
.eq(CollectionEntity::getTargetId, targetId)
......@@ -77,10 +76,10 @@ public class CollectionService {
.eq(CollectionEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode())));
}
// 统计多个主题的点赞量
public Integer getCountByTypeAndIds(List<String> themeIds, CollectionTypeEnum type) {
// 统计多个对象(主题、评论)的数量(点赞、收藏)
public Integer getCountByTypeAndIds(List<String> targetIds, CollectionTypeEnum type) {
return collectionMapper.selectCount((new LambdaQueryWrapper<CollectionEntity>()
.in(CollectionEntity::getTargetId, themeIds)
.in(CollectionEntity::getTargetId, targetIds)
.eq(CollectionEntity::getCollectionType, type.getCode()))
.eq(CollectionEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode()));
}
......
......@@ -30,27 +30,40 @@ public class ThemeService {
}
//根据id返回主题详情
public ThemeEntity queryById(String themeId) {
return themeMapper.selectById(themeId);
public ThemeEntity queryByThemeId(String themeId) {
return themeMapper.selectOne(new LambdaQueryWrapper<ThemeEntity>().eq(ThemeEntity::getThemeId,themeId));
}
//根据话题查询主题
/**
* 根据条件查询主题
* @param topidId 话题Id
* @param lastId 查询此主题Id之前的主题
* @param pageSize 查询数量
* @return
*/
public List<ThemeEntity> queryByTopic(String topidId, String lastId,Integer pageSize) {
LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>()
.eq(ThemeEntity::getTopicId, topidId);
if (StringUtils.isNotEmpty(lastId)) {
ThemeEntity lastEntity = queryById(lastId);
ThemeEntity lastEntity = queryByThemeId(lastId);
if (lastEntity==null) throw new BizException("主题未找到,id:"+lastId);
queryWrapper.lt(ThemeEntity::getUpdateTime, lastEntity.getUpdateTime());
}
if (pageSize!=null){
queryWrapper.last("limit "+pageSize);
}
return themeMapper.selectList(queryWrapper);
}
//根据话题查询所有的主题Id
public List<String> queryThemeIdsByTopic(String topidId) {
LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>()
.eq(ThemeEntity::getTopicId, topidId);
queryWrapper.select(ThemeEntity::getThemeId);
return themeMapper.selectList(queryWrapper).stream().map(ThemeEntity::getThemeId).collect(Collectors.toList());
}
//关注的主题列表
public List<ThemeEntity> queryByFans(List<String> fansList, String lastId,Integer pageSize) {
......@@ -58,7 +71,7 @@ public class ThemeService {
.in(ThemeEntity::getAuthorId, fansList)
.orderByDesc(ThemeEntity::getUpdateTime);
if (StringUtils.isNotEmpty(lastId)) {
ThemeEntity lastEntity = queryById(lastId);
ThemeEntity lastEntity = queryByThemeId(lastId);
if (lastEntity==null) throw new BizException("主题未找到,id:"+lastId);
queryWrapper.lt(ThemeEntity::getUpdateTime, lastEntity.getUpdateTime());
}
......@@ -73,7 +86,7 @@ public class ThemeService {
LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>()
.orderByDesc(ThemeEntity::getUpdateTime);
if (StringUtils.isNotEmpty(lastId)) {
ThemeEntity lastEntity = queryById(lastId);
ThemeEntity lastEntity = queryByThemeId(lastId);
if (lastEntity==null) throw new BizException("主题未找到,id:"+lastId);
queryWrapper.lt(ThemeEntity::getUpdateTime, lastEntity.getUpdateTime());
}
......
......@@ -78,7 +78,7 @@ public class TopicService {
}
public TopicEntity queryById(String topicId) {
return topicMapper.selectById(topicId);
return topicMapper.selectOne(new LambdaQueryWrapper<TopicEntity>().eq(TopicEntity::getTopicId,topicId));
}
public void modifyViewCount(String topicId, long Count) {
......
......@@ -33,17 +33,22 @@ public class ConvertUtil {
}
public static List<ThemeEntity> themeDTOSToEntitys(List<ThemeQo> themeQos) {
return themeQos.stream().map(ConvertUtil::themeDTOToEntity).collect(Collectors.toList());
}
public static TopicDO topicEntityToDTO(TopicEntity topicEntity) {
TopicDO topicDO = new TopicDO();
BeanUtils.copyProperties(topicEntity, topicDO);
return topicDO;
}
public static TopicHotQo topicEntityToHotQo(TopicEntity topicEntity) {
TopicHotQo topicHotQo = new TopicHotQo();
BeanUtils.copyProperties(topicEntity, topicHotQo);
return topicHotQo;
}
public static List<TopicHotQo> topicEntityToHotQos(List<TopicEntity> topicEntities){
return topicEntities.stream().map(ConvertUtil::topicEntityToHotQo).collect(Collectors.toList());
}
public static TopicTitileQo topicToBriefInfoDTO(TopicEntity topicEntity) {
TopicTitileQo topicTitileQo = new TopicTitileQo();
BeanUtils.copyProperties(topicEntity, topicTitileQo);
......
......@@ -32,7 +32,7 @@ public class PageUtils {
int toIndex;
// 防止索引越界
if (Integer.getInteger("0").equals(pageable.getPageNumber())) {
if (Integer.valueOf(0).equals(pageable.getPageNumber())) {
pageable.setPageNumber(1);
}
......
apollo.bootstrap.enabled: true
apollo.bootstrap.enabled: false
#app.id: tanpu-community
#apollo:
......
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