Commit bffe20c6 authored by 刘基明's avatar 刘基明

主题接口修改

parent 35fdd1b2
......@@ -4,6 +4,8 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotNull;
@Data
@ApiModel(value = "查询历史操作主题列表")
public class QueryRecordThemeReq {
......@@ -13,4 +15,11 @@ public class QueryRecordThemeReq {
@ApiModelProperty(value = "操作类型 1:发布 2:回复 3:点赞 4:收藏")
private Integer recordType;
@ApiModelProperty(value = "当前浏览的最后一个themeId,可以为空")
private String lastId;
@NotNull(message = "PageSize不能为空")
@ApiModelProperty(value = "页面大小")
private Integer pageSize;
}
......@@ -8,6 +8,15 @@ import javax.validation.constraints.NotNull;
@Data
public class ThemeListReq {
@NotNull(message = "主题类型不能为空")
@ApiModelProperty(value = "类型,1:推荐 2:关注 3:话题-热门 4:话题:最新")
private Integer type;
@ApiModelProperty(value = "话题Id")
private String topicId;
@ApiModelProperty(value = "当前浏览的最后一个themeId,可以为空")
private String lastId;
......@@ -15,9 +24,8 @@ public class ThemeListReq {
@ApiModelProperty(value = "页面大小")
private Integer pageSize;
@NotNull(message = "主题类型不能为空")
@ApiModelProperty(value = "类型,1:推荐 2:关注")
private Integer type;
}
......@@ -4,7 +4,9 @@ public enum ThemeListTypeEnum {
RECOMMEND(1,"推荐列表"),
FOLLOW(2,"关注列表");
FOLLOW(2,"关注列表"),
TOPIC_HOT(3,"主题-热门列表"),
TOPIC_LATEST(4,"主题-最新列表");
private Integer code;
private String type;
......
......@@ -9,6 +9,7 @@ import com.tanpu.community.api.beans.req.homepage.QueryFollowReq;
import com.tanpu.community.api.beans.req.homepage.QueryRecordThemeReq;
import com.tanpu.community.api.beans.req.page.Page;
import com.tanpu.community.manager.HomePageManager;
import com.tanpu.community.manager.ThemeManager;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -25,6 +26,9 @@ public class HomePageController {
@Autowired
private HomePageManager homePageManager;
@Autowired
private ThemeManager themeManager;
@PostMapping(value = "/editInfo")
@ApiOperation("编辑圈子个人资料")
@ResponseBody
......@@ -52,11 +56,12 @@ public class HomePageController {
}
@PostMapping(value = "/themeList")
@ApiOperation("我的点赞帖子列表")
@ApiOperation("用户的帖子列表")
@ResponseBody
public CommonResp<List<ThemeQo>> likeList(@RequestBody QueryRecordThemeReq req){
String userId="123";
return CommonResp.success();
return CommonResp.success(themeManager.queryThemesByUser(req,userId));
}
}
......@@ -5,7 +5,6 @@ import com.tanpu.common.api.CommonResp;
import com.tanpu.community.api.beans.qo.ThemeQo;
import com.tanpu.community.api.beans.req.theme.CreateThemeReq;
import com.tanpu.community.api.beans.req.theme.ForwardThemeReq;
import com.tanpu.community.api.beans.req.theme.ThemeListByTopicReq;
import com.tanpu.community.api.beans.req.theme.ThemeListReq;
import com.tanpu.community.manager.ThemeManager;
import io.swagger.annotations.ApiOperation;
......@@ -36,25 +35,16 @@ public class ThemeController {
@ApiOperation("圈子首页-推荐/关注")
@ApiOperation("圈子首页-推荐/关注/热门/最新")
@PostMapping(value = "/list")
@ResponseBody
public CommonResp<List<ThemeQo>> selectInterestList(@Validated @RequestBody ThemeListReq req) {
String userId = "liujm";
List<ThemeQo> result= themeManager.queryThemeList(req,userId);
List<ThemeQo> result= themeManager.queryThemes(req,userId);
return CommonResp.success(result);
}
@ApiOperation("话题详情页-最新/最热")
@PostMapping(value = "/listByTopic")
@ResponseBody
public CommonResp<List<ThemeQo>> getThemeMainText(@RequestBody ThemeListByTopicReq req) {
String userId = "liujm";
List<ThemeQo> result= themeManager.queryByTopic(req,userId);
return CommonResp.success(result);
}
@ApiOperation("主题正文")
@GetMapping(value = "/detail")
......
......@@ -6,9 +6,9 @@ import com.tanpu.common.util.JsonUtil;
import com.tanpu.community.api.beans.qo.AttachmentDetailVo;
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.CreateThemeReq;
import com.tanpu.community.api.beans.req.theme.ForwardThemeReq;
import com.tanpu.community.api.beans.req.theme.ThemeListByTopicReq;
import com.tanpu.community.api.beans.req.theme.ThemeListReq;
import com.tanpu.community.api.beans.vo.feign.CoursePackageDetail;
import com.tanpu.community.api.beans.vo.feign.ProductInfoVO;
......@@ -26,6 +26,7 @@ import com.tanpu.community.feign.zhibo.FeignClientForZhibo;
import com.tanpu.community.service.*;
import com.tanpu.community.service.other.*;
import com.tanpu.community.util.ConvertUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -34,10 +35,7 @@ import javax.annotation.Resource;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.*;
@Service
public class ThemeManager {
......@@ -94,44 +92,50 @@ public class ThemeManager {
//TODO 敏感词过滤
//保存主题表
ThemeEntity themeEntity = new ThemeEntity();
BeanUtils.copyProperties(req, themeEntity);
themeEntity.setAuthorId(userId);
themeEntity.setContent(JsonUtil.toJson(req.getContent()));
themeService.insertTheme(themeEntity);
//保存附件表
List<ThemeAttachmentEntity> themeAttachments = ConvertUtil.themeReqToAttachmentList(req, themeEntity.getThemeId());
themeAttachmentService.insertList(themeAttachments);
}
// 返回推荐主题文章
public List<ThemeQo> queryThemeList(ThemeListReq req, String userId) {
List<ThemeEntity> themeEntities;
public List<ThemeQo> queryThemes(ThemeListReq req, String userId) {
List<ThemeEntity> themeEntities=new ArrayList<>();
if (ThemeListTypeEnum.RECOMMEND.getCode().equals(req.getType())) {
// TODO:推荐
themeEntities = themeService.selectAll(req.getLastId(), req.getPageSize());
} else {
} else if (ThemeListTypeEnum.FOLLOW.getCode().equals(req.getType())){
//根据关注列表查询
List<String> fansList = followRelService.queryFansByFollowerId(userId);
themeEntities = themeService.queryByFans(fansList, req.getLastId(), req.getPageSize());
}else if (ThemeListTypeEnum.TOPIC_HOT.getCode().equals(req.getType())){
//TODO 根据话题查询热门
if (StringUtils.isEmpty(req.getTopicId())) throw new BizException("TopicId为空");
themeEntities = themeService.queryByTopic(req.getTopicId(), req.getLastId(), req.getPageSize());
}else if (ThemeListTypeEnum.TOPIC_LATEST.getCode().equals(req.getType())){
//TODO 根据话题查询最新
if (StringUtils.isEmpty(req.getTopicId())) throw new BizException("TopicId为空");
themeEntities = themeService.queryByTopic(req.getTopicId(), req.getLastId(), req.getPageSize());
}
List<ThemeQo> themeQos = convertEntityToQo(themeEntities, userId);
return themeQos;
return convertEntityToQo(themeEntities, userId);
}
// 返回用户发布、回复、收藏的主题列表
public List<ThemeQo> queryThemesByUser(QueryRecordThemeReq req,String userId) {
public List<ThemeQo> queryByTopic(ThemeListByTopicReq req, String userId) {
List<ThemeEntity> themeEntities = themeService.queryByTopic(req.getTopicId(), req.getLastId(), req.getPageSize());
List<ThemeQo> themeQos = convertEntityToQo(themeEntities, userId);
return themeQos;
// List<ThemeEntity> themeEntities = themeService.queryByUser(req.getUserId(), req.getPageSize(),req.getLastId());
List<ThemeEntity> themeEntities = themeService.selectAll(req.getLastId(), req.getPageSize());
return convertEntityToQo(themeEntities, userId);
}
//查询正文
public ThemeQo getDetail(String themeId, String userId) {
......@@ -317,4 +321,5 @@ public class ThemeManager {
}
}
......@@ -34,6 +34,21 @@ public class ThemeService {
return themeMapper.selectOne(new LambdaQueryWrapper<ThemeEntity>().eq(ThemeEntity::getThemeId,themeId));
}
//分页倒叙lastId之前的主题
public List<ThemeEntity> selectAll(String lastId,Integer pageSize) {
LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>()
.orderByDesc(ThemeEntity::getUpdateTime);
if (StringUtils.isNotEmpty(lastId)) {
ThemeEntity lastEntity = queryByThemeId(lastId);
if (lastEntity==null) throw new BizException("主题未找到,id:"+lastId);
queryWrapper.lt(ThemeEntity::getUpdateTime, lastEntity.getUpdateTime());
}
queryWrapper.last("limit "+pageSize);
queryWrapper.orderByDesc(ThemeEntity::getUpdateTime);
return themeMapper.selectList(queryWrapper);
}
/**
* 根据条件查询主题
* @param topidId 话题Id
......@@ -52,7 +67,6 @@ public class ThemeService {
if (pageSize!=null){
queryWrapper.last("limit "+pageSize);
}
return themeMapper.selectList(queryWrapper);
}
......@@ -81,18 +95,6 @@ public class ThemeService {
}
//查询列表中用户的主题
public List<ThemeEntity> selectAll(String lastId,Integer pageSize) {
LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>()
.orderByDesc(ThemeEntity::getUpdateTime);
if (StringUtils.isNotEmpty(lastId)) {
ThemeEntity lastEntity = queryByThemeId(lastId);
if (lastEntity==null) throw new BizException("主题未找到,id:"+lastId);
queryWrapper.lt(ThemeEntity::getUpdateTime, lastEntity.getUpdateTime());
}
queryWrapper.last("limit "+pageSize);
return themeMapper.selectList(queryWrapper);
}
//查询对应话题的发表用户集合
public Set<String> getPostUserCount(List<String> themeIds) {
......
......@@ -55,6 +55,7 @@ CREATE TABLE `theme_attachment` (
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`delete_tag` int(3) NOT NULL DEFAULT '0',
`ext_info` varchar(100) DEFAULT NULL COMMENT '额外信息',
PRIMARY KEY (`id`),
KEY `theme_id` (`theme_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='主题附件';
......@@ -117,6 +118,7 @@ CREATE TABLE `file_record` (
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`delete_tag` int(3) NOT NULL DEFAULT '0',
`ext_info` varchar(100) DEFAULT NULL COMMENT '额外信息',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_logic` (`file_oss_key`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='上传文件';
......
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