Commit 154269ef authored by 刘基明's avatar 刘基明

接口修改

parent faced86f
...@@ -2,13 +2,19 @@ package com.tanpu.community.api.beans.qo; ...@@ -2,13 +2,19 @@ package com.tanpu.community.api.beans.qo;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List; import java.util.List;
@Data @Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "转发的主题") @ApiModel(value = "转发的主题")
public class ThemeFormerQo { public class FormerThemeQo {
@ApiModelProperty(value = "被转发的昵称") @ApiModelProperty(value = "被转发的昵称")
private String nickName; private String nickName;
......
...@@ -18,6 +18,9 @@ public class ThemeQo { ...@@ -18,6 +18,9 @@ public class ThemeQo {
@ApiModelProperty(value = "主题ID") @ApiModelProperty(value = "主题ID")
private String themeId; private String themeId;
@ApiModelProperty(value = "被转发的主题")
private String formerThemeId;
@ApiModelProperty(value = "标题") @ApiModelProperty(value = "标题")
private String title; private String title;
...@@ -39,7 +42,7 @@ public class ThemeQo { ...@@ -39,7 +42,7 @@ public class ThemeQo {
@ApiModelProperty(value = "用户头像") @ApiModelProperty(value = "用户头像")
private String userImg; private String userImg;
@ApiModelProperty(value = "是否关注") @ApiModelProperty(value = "当前用户是否关注该作者")
private boolean follow; private boolean follow;
@ApiModelProperty(value = "作者认证") @ApiModelProperty(value = "作者认证")
...@@ -57,14 +60,17 @@ public class ThemeQo { ...@@ -57,14 +60,17 @@ public class ThemeQo {
@ApiModelProperty(value = "点赞量") @ApiModelProperty(value = "点赞量")
private Integer likeCount; private Integer likeCount;
@ApiModelProperty(value = "当前用户是否点赞") @ApiModelProperty(value = "当前用户是否点赞该主题")
private boolean isLiked; private boolean hasLiked;
@ApiModelProperty(value = "当前用户是否转发该主题")
private boolean hasForward;
@ApiModelProperty(value = "图片九宫格") @ApiModelProperty(value = "图片九宫格")
private List<ImagesDTO> imgList; private List<ImagesDTO> imgList;
@ApiModelProperty(value = "转发的主题") @ApiModelProperty(value = "转发的主题")
private ThemeFormerQo formerTheme; private FormerThemeQo formerTheme;
private LocalDateTime createTime; private LocalDateTime createTime;
......
package com.tanpu.community.api.beans.req.theme;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@ApiModel(value = "收藏/取消收藏主题")
@Data
public class CollectThemeReq {
@ApiModelProperty(value = "主题Id")
private String themeId;
@ApiModelProperty(value = "类型,1:收藏 2:取消收藏")
private Integer type;
}
package com.tanpu.community.api.beans.req.theme; package com.tanpu.community.api.beans.req.theme;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;
@Data @Data
@ApiModel(value = "转发主题")
public class ForwardThemeReq { public class ForwardThemeReq {
@NotEmpty(message = "转发对象id不能为空") @NotEmpty(message = "转发对象id不能为空")
@ApiModelProperty(value = "转发的主题Id")
private String formerThemeId; private String formerThemeId;
@NotEmpty(message = "内容不能为空") @NotNull(message = "内容不能为空")
private String content; @ApiModelProperty(value = "转发的讨论内容")
private List<ThemeContentReq> content;
@ApiModelProperty(value = "话题Id")
private String topicId; private String topicId;
} }
...@@ -4,7 +4,7 @@ import io.swagger.annotations.ApiModel; ...@@ -4,7 +4,7 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
@ApiModel(value = "请求") @ApiModel(value = "点赞/取消点赞主题")
@Data @Data
public class LikeThemeReq { public class LikeThemeReq {
......
package com.tanpu.community.api.beans.req.theme;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@ApiModel(value = "举报主题")
@Data
public class ReportThemeReq {
@ApiModelProperty(value = "主题Id")
private String themeId;
@ApiModelProperty(value = "举报理由")
private String reason;
}
...@@ -3,7 +3,7 @@ package com.tanpu.community.api.enums; ...@@ -3,7 +3,7 @@ package com.tanpu.community.api.enums;
public enum CollectionTypeEnum { public enum CollectionTypeEnum {
LIKE_THEME(1,"点赞主题"), LIKE_THEME(1,"点赞主题"),
BOOK_THEME(2,"收藏主题"), COLLECT_THEME(2,"收藏主题"),
LIKE_COMMENT(3,"点赞评论"); LIKE_COMMENT(3,"点赞评论");
private Integer code; private Integer code;
......
...@@ -3,10 +3,7 @@ package com.tanpu.community.controller; ...@@ -3,10 +3,7 @@ package com.tanpu.community.controller;
import com.tanpu.common.api.CommonResp; import com.tanpu.common.api.CommonResp;
import com.tanpu.community.api.beans.qo.ThemeQo; 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.*;
import com.tanpu.community.api.beans.req.theme.ForwardThemeReq;
import com.tanpu.community.api.beans.req.theme.LikeThemeReq;
import com.tanpu.community.api.beans.req.theme.ThemeListReq;
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;
...@@ -35,24 +32,22 @@ public class ThemeController { ...@@ -35,24 +32,22 @@ public class ThemeController {
} }
@ApiOperation("圈子首页-推荐/关注/热门/最新") @ApiOperation("圈子首页-推荐/关注/热门/最新")
@PostMapping(value = "/list") @PostMapping(value = "/list")
@ResponseBody @ResponseBody
public CommonResp<List<ThemeQo>> selectInterestList(@Validated @RequestBody ThemeListReq req) { public CommonResp<List<ThemeQo>> selectInterestList(@Validated @RequestBody ThemeListReq req) {
String userId = "liujm"; String userId = "liujm";
List<ThemeQo> result= themeManager.queryThemes(req,userId); List<ThemeQo> result = themeManager.queryThemes(req, userId);
return CommonResp.success(result); return CommonResp.success(result);
} }
@ApiOperation("主题正文") @ApiOperation("主题正文")
@GetMapping(value = "/detail") @GetMapping(value = "/detail")
@ResponseBody @ResponseBody
public CommonResp<ThemeQo> getThemeMainText(@RequestParam String themeId) { public CommonResp<ThemeQo> getThemeMainText(@RequestParam String themeId) {
String userId = "liujm"; String userId = "liujm";
ThemeQo themeQo = themeManager.getDetail(themeId,userId); ThemeQo themeQo = themeManager.getDetail(themeId, userId);
return CommonResp.success(themeQo); return CommonResp.success(themeQo);
} }
...@@ -65,40 +60,40 @@ public class ThemeController { ...@@ -65,40 +60,40 @@ public class ThemeController {
return CommonResp.success(); return CommonResp.success();
} }
@ApiOperation("点赞/取消点赞主题")
@ApiOperation("点赞主题")
@PostMapping(value = "/like") @PostMapping(value = "/like")
@ResponseBody @ResponseBody
public CommonResp likeOnTheme(@RequestBody LikeThemeReq req) { public CommonResp<Void> likeOnTheme(@RequestBody LikeThemeReq req) {
String user = "liujm"; String user = "liujm";
themeManager.like(req, user); themeManager.like(req, user);
return CommonResp.success(); return CommonResp.success();
} }
@ApiOperation("分享主题")
@GetMapping(value = "/share")
@ResponseBody
public CommonResp shareTheme(String themeId) {
return CommonResp.success();
}
@ApiOperation("收藏主题") @ApiOperation("收藏/取消收藏主题")
@GetMapping(value = "/collect") @GetMapping(value = "/collect")
@ResponseBody @ResponseBody
public CommonResp bookTheme(String themeId) { public CommonResp<Void> bookTheme(@RequestBody CollectThemeReq req) {
String user = "liujm"; String user = "liujm";
// themeManager.book(themeId,user); themeManager.collect(req, user);
return CommonResp.success(); return CommonResp.success();
} }
@ApiOperation("举报主题") @ApiOperation("举报主题")
@GetMapping(value = "/report") @GetMapping(value = "/report")
@ResponseBody @ResponseBody
public CommonResp complaintTheme(@RequestParam String themeId) { public CommonResp complaintTheme(@RequestBody ReportThemeReq req) {
return CommonResp.failed("功能暂未开放"); return CommonResp.failed("功能暂未开放");
} }
@ApiOperation("分享主题")
@GetMapping(value = "/share")
@ResponseBody
public CommonResp<Void> shareTheme(String themeId) {
return CommonResp.success();
}
@ApiOperation("屏蔽") @ApiOperation("屏蔽")
@GetMapping(value = "/block") @GetMapping(value = "/block")
@ResponseBody @ResponseBody
......
...@@ -4,13 +4,11 @@ import com.tanpu.common.api.CommonResp; ...@@ -4,13 +4,11 @@ import com.tanpu.common.api.CommonResp;
import com.tanpu.common.exception.BizException; import com.tanpu.common.exception.BizException;
import com.tanpu.common.util.JsonUtil; import com.tanpu.common.util.JsonUtil;
import com.tanpu.community.api.beans.qo.AttachmentDetailVo; import com.tanpu.community.api.beans.qo.AttachmentDetailVo;
import com.tanpu.community.api.beans.qo.FormerThemeQo;
import com.tanpu.community.api.beans.qo.ThemeContentQo; 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.CreateThemeReq; import com.tanpu.community.api.beans.req.theme.*;
import com.tanpu.community.api.beans.req.theme.ForwardThemeReq;
import com.tanpu.community.api.beans.req.theme.LikeThemeReq;
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.CoursePackageDetail;
import com.tanpu.community.api.beans.vo.feign.ProductInfoVO; import com.tanpu.community.api.beans.vo.feign.ProductInfoVO;
import com.tanpu.community.api.beans.vo.feign.ShortVideoBaseInfoResp; import com.tanpu.community.api.beans.vo.feign.ShortVideoBaseInfoResp;
...@@ -161,15 +159,21 @@ public class ThemeManager { ...@@ -161,15 +159,21 @@ public class ThemeManager {
} }
public void unlike(String themeId, String userId) { //收藏/取消收藏
public void collect(CollectThemeReq req, String userId) {
//todo 枚举值
if (1==req.getType()){
collectionService.addIfNotExist(req.getThemeId(), userId, CollectionTypeEnum.COLLECT_THEME);
}else if (2==req.getType()) {
collectionService.delete(req.getThemeId(), userId, CollectionTypeEnum.COLLECT_THEME);
}
} }
//转发 //转发
public void forward(ForwardThemeReq req, String userId) { public void forward(ForwardThemeReq req, String userId) {
ThemeEntity targetTheme = themeService.queryByThemeId(req.getFormerThemeId()); ThemeEntity targetTheme = themeService.queryByThemeId(req.getFormerThemeId());
ThemeEntity newTheme = ThemeEntity.builder() ThemeEntity newTheme = ThemeEntity.builder()
.content(req.getContent()) .content(JsonUtil.toJson(req.getContent()))
.topicId(req.getTopicId()) .topicId(req.getTopicId())
.formerThemeId(req.getFormerThemeId()) .formerThemeId(req.getFormerThemeId())
.authorId(userId) .authorId(userId)
...@@ -180,14 +184,8 @@ public class ThemeManager { ...@@ -180,14 +184,8 @@ public class ThemeManager {
} }
//收藏
public void favorite(String themeId, String userId) {
collectionService.addIfNotExist(themeId, userId, CollectionTypeEnum.BOOK_THEME);
}
public void unFavorite(String themeId, String userId) {
collectionService.delete(themeId, userId, CollectionTypeEnum.BOOK_THEME);
}
//投诉(主题) //投诉(主题)
public void complaint(String themeId, String user) { public void complaint(String themeId, String user) {
...@@ -233,36 +231,57 @@ public class ThemeManager { ...@@ -233,36 +231,57 @@ public class ThemeManager {
//组装主题列表 //组装主题列表
private void buildThemeQoExtraInfo(String userId, ThemeQo themeQO) { private void buildThemeQoExtraInfo(String userId, ThemeQo themeQo) {
//附件列表 //附件列表
String themeId = themeQO.getThemeId(); String themeId = themeQo.getThemeId();
List<ThemeContentQo> content = themeQO.getContent(); List<ThemeContentQo> content = themeQo.getContent();
if (content != null && content.size() > 2) { if (content != null && content.size() > 2) {
themeQO.setContent(content.subList(0, 2)); themeQo.setContent(content.subList(0, 2));
} }
content = themeQO.getContent(); content = themeQo.getContent();
for (ThemeContentQo themeContentQo : content) { for (ThemeContentQo themeContentQo : content) {
transferAttachment(themeContentQo, userId); transferAttachment(themeContentQo, userId);
} }
//迄今时间 //迄今时间
themeQO.setUpToNowTime(calUpToNowTime(themeQO.getCreateTime())); themeQo.setUpToNowTime(calUpToNowTime(themeQo.getCreateTime()));
//是否关注作者 //是否关注作者
String authorId = themeQO.getAuthorId(); String authorId = themeQo.getAuthorId();
Set<String> fansSet = new HashSet<>(followRelService.queryFansByFollowerId(userId)); Set<String> fansSet = new HashSet<>(followRelService.queryFansByFollowerId(userId));
themeQO.setFollow(fansSet.contains(authorId)); themeQo.setFollow(fansSet.contains(authorId));
//是否点赞
CollectionEntity likeEntity = collectionService.getTargetCollection(themeId, userId, CollectionTypeEnum.LIKE_THEME);
themeQo.setHasLiked(likeEntity!=null);
//是否转发
Integer forwardCountByUser = themeService.getForwardCountByUser(themeId, userId);
themeQo.setHasForward(forwardCountByUser>0);
//转发原文
String formerThemeId = themeQo.getFormerThemeId();
if (formerThemeId!=null){
ThemeQo formerTheme = ConvertUtil.themeEntityToQo(themeService.queryByThemeId(formerThemeId));
if (formerTheme==null){
throw new BizException("转发主题Id错误,id:"+formerThemeId);
}
HomePageEntity formerUser = homePageService.selectByUserId(formerTheme.getAuthorId());
FormerThemeQo f = FormerThemeQo.builder().formerThemeId(formerThemeId)
.forwardContent(formerTheme.getContent())
.userImg(formerUser.getHeadImg())
.nickName(formerUser.getNickName())
.build();
themeQo.setFormerTheme(f);
}
//用户信息:头像、昵称 //用户信息:头像、昵称
HomePageEntity userEntity = homePageService.selectByUserId(userId); HomePageEntity userEntity = homePageService.selectByUserId(userId);
themeQO.setUserImg(userEntity.getHeadImg()); themeQo.setUserImg(userEntity.getHeadImg());
themeQO.setNickName(userEntity.getNickName()); themeQo.setNickName(userEntity.getNickName());
//热点数据:点赞,收藏,转发 //热点数据:点赞,收藏,转发
Integer likeCount = collectionService.getCountByTypeAndId(themeId, CollectionTypeEnum.LIKE_THEME); Integer likeCount = collectionService.getCountByTypeAndId(themeId, CollectionTypeEnum.LIKE_THEME);
Integer bookCount = collectionService.getCountByTypeAndId(themeId, CollectionTypeEnum.BOOK_THEME); Integer bookCount = collectionService.getCountByTypeAndId(themeId, CollectionTypeEnum.COLLECT_THEME);
Integer forwardCount = themeService.getForwardCountById(themeId); Integer forwardCount = themeService.getForwardCountById(themeId);
themeQO.setCommentCount(bookCount); themeQo.setCommentCount(bookCount);
themeQO.setLikeCount(likeCount); themeQo.setLikeCount(likeCount);
themeQO.setForwardCount(forwardCount); themeQo.setForwardCount(forwardCount);
} }
//组装正文详情 //组装正文详情
...@@ -279,6 +298,21 @@ public class ThemeManager { ...@@ -279,6 +298,21 @@ public class ThemeManager {
HomePageEntity author = homePageService.selectByUserId(userId); HomePageEntity author = homePageService.selectByUserId(userId);
themeQo.setUserImg(author.getHeadImg()); themeQo.setUserImg(author.getHeadImg());
themeQo.setNickName(author.getNickName()); themeQo.setNickName(author.getNickName());
//转发原文
String formerThemeId = themeQo.getFormerThemeId();
if (formerThemeId!=null){
ThemeQo formerTheme = ConvertUtil.themeEntityToQo(themeService.queryByThemeId(formerThemeId));
if (formerTheme==null){
throw new BizException("转发主题Id错误,id:"+formerThemeId);
}
HomePageEntity formerUser = homePageService.selectByUserId(formerTheme.getAuthorId());
FormerThemeQo f = FormerThemeQo.builder().formerThemeId(formerThemeId)
.forwardContent(formerTheme.getContent())
.userImg(formerUser.getHeadImg())
.nickName(formerUser.getNickName())
.build();
themeQo.setFormerTheme(f);
}
return; return;
} }
......
...@@ -145,7 +145,7 @@ public class TopicManager { ...@@ -145,7 +145,7 @@ public class TopicManager {
Long viewCountModify = topic.getviewCntAdjust(); Long viewCountModify = topic.getviewCntAdjust();
List<String> themeIds = themeService.queryThemeIdsByTopic(topicId); List<String> themeIds = themeService.queryThemeIdsByTopic(topicId);
Integer likeCountByThemeIds = collectionService.getCountByTypeAndIds(themeIds, CollectionTypeEnum.LIKE_THEME); Integer likeCountByThemeIds = collectionService.getCountByTypeAndIds(themeIds, CollectionTypeEnum.LIKE_THEME);
Integer bookCountByThemeIds = collectionService.getCountByTypeAndIds(themeIds, CollectionTypeEnum.BOOK_THEME); Integer bookCountByThemeIds = collectionService.getCountByTypeAndIds(themeIds, CollectionTypeEnum.COLLECT_THEME);
Long commentCountByThemeIds = (long)commentService.getCommentCountByThemeIds(themeIds); Long commentCountByThemeIds = (long)commentService.getCommentCountByThemeIds(themeIds);
Set<String> postUsers = themeService.getPostUserCount(themeIds); Set<String> postUsers = themeService.getPostUserCount(themeIds);
Set<String> commentUsers = commentService.getCommentUserCount(themeIds); Set<String> commentUsers = commentService.getCommentUserCount(themeIds);
......
...@@ -42,11 +42,11 @@ public class CollectionService { ...@@ -42,11 +42,11 @@ public class CollectionService {
//根据用户、主题、类型查询未删除对象 //根据用户、主题、类型查询未删除对象
public CollectionEntity getTargetCollection(String themeId, String userId, CollectionTypeEnum type) { public CollectionEntity getTargetCollection(String targetId, String userId, CollectionTypeEnum type) {
return collectionMapper.selectOne(new LambdaQueryWrapper<CollectionEntity>() return collectionMapper.selectOne(new LambdaQueryWrapper<CollectionEntity>()
.eq(CollectionEntity::getCollectionType, type.getCode()) .eq(CollectionEntity::getCollectionType, type.getCode())
.eq(CollectionEntity::getUserId, userId) .eq(CollectionEntity::getUserId, userId)
.eq(CollectionEntity::getTargetId, themeId) .eq(CollectionEntity::getTargetId, targetId)
.eq(CollectionEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode())); .eq(CollectionEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode()));
} }
......
...@@ -108,4 +108,11 @@ public class ThemeService { ...@@ -108,4 +108,11 @@ public class ThemeService {
.eq(ThemeEntity::getThemeId, themeId) .eq(ThemeEntity::getThemeId, themeId)
.eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED)); .eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED));
} }
public Integer getForwardCountByUser(String themeId,String userId) {
return themeMapper.selectCount(new LambdaQueryWrapper<ThemeEntity>()
.eq(ThemeEntity::getFormerThemeId, themeId)
.eq(ThemeEntity::getAuthorId, userId)
.eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED));
}
} }
...@@ -19,6 +19,9 @@ import java.util.stream.Collectors; ...@@ -19,6 +19,9 @@ import java.util.stream.Collectors;
public class ConvertUtil { public class ConvertUtil {
public static ThemeQo themeEntityToQo(ThemeEntity themeEntity) { public static ThemeQo themeEntityToQo(ThemeEntity themeEntity) {
if (themeEntity==null){
return null;
}
ThemeQo themeQO = new ThemeQo(); ThemeQo themeQO = new ThemeQo();
BeanUtils.copyProperties(themeEntity, themeQO); BeanUtils.copyProperties(themeEntity, themeQO);
List<ThemeContentQo> themeContentQos = JsonUtil.toBean(themeEntity.getContent(), new TypeReference<List<ThemeContentQo>>() {}); List<ThemeContentQo> themeContentQos = JsonUtil.toBean(themeEntity.getContent(), new TypeReference<List<ThemeContentQo>>() {});
......
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