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

接口调整

parent 6d214c43
...@@ -17,6 +17,10 @@ ...@@ -17,6 +17,10 @@
<groupId>com.tanpu</groupId> <groupId>com.tanpu</groupId>
<artifactId>common</artifactId> <artifactId>common</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
</dependency>
</dependencies> </dependencies>
</project> </project>
...@@ -25,27 +25,23 @@ public class TopicDTO implements Serializable { ...@@ -25,27 +25,23 @@ public class TopicDTO implements Serializable {
@ApiModelProperty(value = "是否隐藏") @ApiModelProperty(value = "是否隐藏")
private Integer isConceal; private Integer isConceal;
private String createBy;
private LocalDateTime createTime; private LocalDateTime createTime;
private String updateBy;
private LocalDateTime updateTime; private LocalDateTime updateTime;
private Integer deleteTag; private Integer deleteTag;
@ApiModelProperty(value = "帖子量") @ApiModelProperty(value = "帖子量")
private Long themeAmount; private Integer themeCount;
@ApiModelProperty(value = "浏览量") @ApiModelProperty(value = "浏览量")
private Long viewAmount; private Integer viewCount;
@ApiModelProperty(value = "点赞量") @ApiModelProperty(value = "点赞量")
private Long likeAmount; private Integer likeCount;
@ApiModelProperty(value = "总用户数") @ApiModelProperty(value = "总用户数")
private Long UserAmount; private Integer UserCount;
@ApiModelProperty @ApiModelProperty
...@@ -57,9 +53,7 @@ public class TopicDTO implements Serializable { ...@@ -57,9 +53,7 @@ public class TopicDTO implements Serializable {
", topicTitle=" + topicTitle + ", topicTitle=" + topicTitle +
", isTop=" + isTop + ", isTop=" + isTop +
", isConceal=" + isConceal + ", isConceal=" + isConceal +
", createBy=" + createBy +
", createTime=" + createTime + ", createTime=" + createTime +
", updateBy=" + updateBy +
", updateTime=" + updateTime + ", updateTime=" + updateTime +
", deleteTag=" + deleteTag + ", deleteTag=" + deleteTag +
"}"; "}";
......
...@@ -15,17 +15,17 @@ public class TopicDataAnalysDTO { ...@@ -15,17 +15,17 @@ public class TopicDataAnalysDTO {
@ApiModelProperty(value = "话题名称") @ApiModelProperty(value = "话题名称")
private String topicTitle; private String topicTitle;
@ApiModelProperty(value = "总浏览量") @ApiModelProperty(value = "总浏览量")
private Integer viewTotalAmount; private Integer viewTotalCount;
@ApiModelProperty(value = "话题页面浏览量") @ApiModelProperty(value = "话题页面浏览量")
private Integer viewPageAmount; private Integer viewPageCount;
@ApiModelProperty(value = "发帖数") @ApiModelProperty(value = "发帖数")
private Integer themeAmount; private Integer themeCount;
@ApiModelProperty(value = "回帖数") @ApiModelProperty(value = "回帖数")
private Integer commentAmount; private Integer commentCount;
@ApiModelProperty(value = "总用户数") @ApiModelProperty(value = "总用户数")
private Integer userTotalAmount; private Integer userTotalCount;
@ApiModelProperty(value = "发帖人数") @ApiModelProperty(value = "发帖人数")
private Integer posterAmount; private Integer posterCount;
@ApiModelProperty(value = "回帖人数") @ApiModelProperty(value = "回帖人数")
private Integer replIierAmount; private Integer replIierCount;
} }
package com.tanpu.community.api.beans.qo;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class AttachmentQo {
@ApiModelProperty("附件类型,1:产品 2:直播 3:短视频 4:课程")
private Integer type;
@ApiModelProperty("附件对象")
private Object attachment;
}
package com.tanpu.community.api.beans.qo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.time.LocalDateTime;
@Data
public class CommentLv2Qo {
@ApiModelProperty(value = "id")
private Integer id;
@ApiModelProperty(value = "uuid")
private String commentId;
@ApiModelProperty(value = "类型")
private Integer commentType;
@ApiModelProperty(value = "文本内容")
private String content;
@ApiModelProperty(value = "作者id")
private String authorId;
@ApiModelProperty(value = "点赞次数")
private Integer likeCount;
@ApiModelProperty(value = "评论时间")
private LocalDateTime updateTime;
@ApiModelProperty(value = "作者昵称")
private String nickName;
@ApiModelProperty(value = "作者头像")
private String userImg;
@ApiModelProperty(value = "回复用户名")
private String replyName;
@ApiModelProperty(value = "当前用户是否点赞")
private boolean hasLiked;
}
...@@ -4,13 +4,17 @@ import io.swagger.annotations.ApiModelProperty; ...@@ -4,13 +4,17 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List;
@Data @Data
public class CommentQo { public class CommentQo {
@ApiModelProperty(value = "id") @ApiModelProperty(value = "id")
private String id; private Integer id;
@ApiModelProperty(value = "uuid")
private String commentId;
@ApiModelProperty(value = "类型") @ApiModelProperty(value = "类型")
private Integer commentType; private Integer commentType;
...@@ -21,24 +25,21 @@ public class CommentQo { ...@@ -21,24 +25,21 @@ public class CommentQo {
@ApiModelProperty(value = "作者id") @ApiModelProperty(value = "作者id")
private String authorId; private String authorId;
@ApiModelProperty(value = "点赞次数")
private Integer likeCount;
@ApiModelProperty(value = "评论时间")
private LocalDateTime updateTime;
@ApiModelProperty(value = "昵称") @ApiModelProperty(value = "昵称")
private String nickName; private String nickName;
@ApiModelProperty(value = "用户头像") @ApiModelProperty(value = "用户头像")
private String userImg; private String userImg;
@ApiModelProperty(value = "评论的目标id") @ApiModelProperty(value = "当前用户是否点赞")
private String targetId; private boolean isLiked;
@ApiModelProperty(value = "是否屏蔽")
private Integer isBlock;
@ApiModelProperty(value = "点赞次数")
private Long likeAmount;
@ApiModelProperty(value = "评论时间")
private LocalDateTime updateTime;
private Integer deleteTag; @ApiModelProperty(value = "2级评论")
private List<CommentLv2Qo> commentLv2Qos;
} }
...@@ -6,7 +6,6 @@ import lombok.Data; ...@@ -6,7 +6,6 @@ import lombok.Data;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* 正文 * 正文
...@@ -55,13 +54,13 @@ public class MainTextQo { ...@@ -55,13 +54,13 @@ public class MainTextQo {
private Long forwardAomunt; private Long forwardAomunt;
@ApiModelProperty(value = "评论量") @ApiModelProperty(value = "评论量")
private Long commentAmount; private Long commentCount;
@ApiModelProperty(value = "点赞量") @ApiModelProperty(value = "点赞量")
private Long likeAmount; private Integer likeCount;
@ApiModelProperty("附件,key是类型,1:产品 2:直播 3:短视频 4:课程") @ApiModelProperty("附件")
private Map<String, Object> attachment; private List<AttachmentQo> attachment;
@ApiModelProperty(value = "评论") @ApiModelProperty(value = "评论")
private List<CommentQo> comments; private List<CommentQo> comments;
......
...@@ -4,7 +4,6 @@ import io.swagger.annotations.ApiModelProperty; ...@@ -4,7 +4,6 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Map;
@Data @Data
public class ThemeQo { public class ThemeQo {
...@@ -12,7 +11,10 @@ public class ThemeQo { ...@@ -12,7 +11,10 @@ public class ThemeQo {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "id") @ApiModelProperty(value = "id")
private String id; private Integer id;
@ApiModelProperty(value = "UUID")
private String themeId;
@ApiModelProperty(value = "标题") @ApiModelProperty(value = "标题")
private String title; private String title;
...@@ -48,18 +50,17 @@ public class ThemeQo { ...@@ -48,18 +50,17 @@ public class ThemeQo {
private String formerThemeId; private String formerThemeId;
@ApiModelProperty(value = "转发量") @ApiModelProperty(value = "转发量")
private Long forwardAmount; private Integer forwardCount;
@ApiModelProperty(value = "评论量") @ApiModelProperty(value = "评论量")
private Long commentAmount; private Integer commentCount;
@ApiModelProperty(value = "点赞量") @ApiModelProperty(value = "点赞量")
private Long likeAmount; private Integer likeCount;
@ApiModelProperty("附件") @ApiModelProperty("附件")
private Map<String,Object> attachment; private AttachmentQo attachmentQo;
private Object attachmentInfo;
private LocalDateTime createTime; private LocalDateTime createTime;
......
package com.tanpu.community.api.beans.qo;
import io.swagger.annotations.ApiModelProperty;
import java.util.List;
public class TopicDetailQo {
@ApiModelProperty(value = "id")
private String id;
@ApiModelProperty(value = "话题名称")
private String topicTitle;
@ApiModelProperty(value = "阅读量")
private Integer viewCount;
@ApiModelProperty(value = "讨论量")
private Integer disscussCount;
private List<ThemeQo> themes;
}
package com.tanpu.community.api.beans; package com.tanpu.community.api.beans.qo;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
...@@ -7,7 +7,7 @@ import lombok.Data; ...@@ -7,7 +7,7 @@ import lombok.Data;
* APP端话题列表页 * APP端话题列表页
*/ */
@Data @Data
public class TopicBriefInfoDTO { public class TopicTitileQo {
private String topicId; private String topicId;
...@@ -15,5 +15,5 @@ public class TopicBriefInfoDTO { ...@@ -15,5 +15,5 @@ public class TopicBriefInfoDTO {
private String title; private String title;
@ApiModelProperty("讨论数") @ApiModelProperty("讨论数")
private Long discussionAmount; private Integer discussionCount;
} }
package com.tanpu.community.api.beans.req; package com.tanpu.community.api.beans.req;
import io.swagger.annotations.ApiModel; 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;
...@@ -12,6 +13,12 @@ public class CreateCommentReq { ...@@ -12,6 +13,12 @@ public class CreateCommentReq {
@NotEmpty(message = "主题id不能为空") @NotEmpty(message = "主题id不能为空")
private String themeId; private String themeId;
@ApiModelProperty(value = "一级评论id(对主题的一级评论,此项为空)")
private String parentId;
@ApiModelProperty(value = "回复对象的id(非对评论回复时,此项为空)")
private String replyId;
@NotEmpty(message = "评论内容不能为空") @NotEmpty(message = "评论内容不能为空")
private String comment; private String comment;
} }
...@@ -3,6 +3,7 @@ package com.tanpu.community.api.beans.req; ...@@ -3,6 +3,7 @@ package com.tanpu.community.api.beans.req;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.NotEmpty;
import java.util.Map; import java.util.Map;
@Data @Data
...@@ -11,6 +12,7 @@ public class CreateThemeReq { ...@@ -11,6 +12,7 @@ public class CreateThemeReq {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@NotEmpty(message = "类型不能为空")
@ApiModelProperty(value = "类型 1:讨论无标题 2:长文有标题") @ApiModelProperty(value = "类型 1:讨论无标题 2:长文有标题")
private Integer themeType; private Integer themeType;
...@@ -18,6 +20,7 @@ public class CreateThemeReq { ...@@ -18,6 +20,7 @@ public class CreateThemeReq {
@ApiModelProperty(value = "标题") @ApiModelProperty(value = "标题")
private String title; private String title;
@NotEmpty(message = "内容不能为空")
@ApiModelProperty(value = "文本内容") @ApiModelProperty(value = "文本内容")
private String content; private String content;
......
package com.tanpu.community.api.beans.req.page;
import com.github.pagehelper.PageHelper;
import lombok.Data;
import java.util.List;
@Data
public class Page<T> {
private Integer pageNum;
private Integer pageSize;
private Long totalSize;
private Integer totalPages;
private List<T> content;
public Page(Pageable pageable, List<T> content) {
this.pageNum = pageable.getPageNumber();
this.pageSize = content.size();
this.content = content;
}
public Page(Integer pageNum, Integer pageSize) {
com.github.pagehelper.Page page = PageHelper.startPage(pageNum, pageSize);
this.pageNum = page.getPageNum();
this.pageSize = page.getPageSize();
this.totalSize = page.getTotal();
this.content = page.getResult();
}
public Page(Pageable pageable, Long totalSize) {
this.pageNum = pageable.getPageNumber();
this.pageSize = pageable.getPageSize();
this.totalSize = totalSize;
if (totalSize == 0) {
this.totalPages = 1;
} else {
this.totalPages = (int) (totalSize%pageable.getPageSize() == 0 ? totalSize/pageable.getPageSize() : totalSize/pageable.getPageSize() + 1);
}
}
public Page(com.github.pagehelper.Page page) {
this.pageNum = page.getPageNum();
this.pageSize = page.getPageSize();
this.totalSize = page.getTotal();
this.totalPages = page.getPages();
this.content = page.getResult();
}
public Page(com.github.pagehelper.Page page, List<T> content) {
this.pageNum = page.getPageNum();
this.pageSize = page.getPageSize();
this.totalSize = page.getTotal();
this.totalPages = page.getPages();
this.content = content;
}
public Page(Pageable pageable, Long totalSize, List<T> content) {
this.pageNum = pageable.getPageNumber();
this.pageSize = pageable.getPageSize();
this.totalSize = totalSize;
this.content = content;
}
public Page(org.springframework.data.domain.Page page) {
this.pageNum = page.getPageable().getPageNumber();
this.pageSize = page.getPageable().getPageSize();
this.totalSize = (long) page.getSize();
this.totalPages = page.getTotalPages();
this.content = page.getContent();
}
public Page(org.springframework.data.domain.Page page, List<T> content) {
this.pageNum = page.getPageable().getPageNumber() + 1;
this.pageSize = page.getPageable().getPageSize();
this.totalSize = page.getTotalElements();
this.totalPages = page.getTotalPages();
this.content = content;
}
public Page(Integer pageNum, Integer pageSize, Long totalSize) {
this.pageNum = pageNum;
this.pageSize = pageSize;
this.totalSize = totalSize;
if (totalSize == 0) {
this.totalPages = 1;
} else {
this.totalPages = (int) (totalSize%pageSize == 0 ? totalSize/pageSize : totalSize/pageSize + 1);
}
}
public Page() {
}
@Override
public String toString() {
return "Page{" +
"pageNum=" + pageNum +
", pageSize=" + pageSize +
", content=" + "[...]" +
'}';
}
}
package com.tanpu.community.api.beans.req.page;
import lombok.Data;
@Data
public class Pageable {
public static final Integer DEFAULT_PAGE_SIZE = 10;
public static final Integer MAX_PAGE_SIZE = 9999;
public static final Integer DEFAULT_PAGE_NUMBER = 0;
private Integer pageNumber = DEFAULT_PAGE_NUMBER;
private Integer pageSize = DEFAULT_PAGE_SIZE;
public Pageable() {
}
public Pageable(Integer pageNumber, Integer pageSize) {
this.pageNumber = pageNumber;
this.pageSize = pageSize;
}
}
package com.tanpu.community.api.beans.req.theme;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class ThemeListReq {
@ApiModelProperty(value = "当前浏览的最后一个themeId")
private String lastId;
@ApiModelProperty(value = "页面大小")
private Integer PageSize;
}
...@@ -4,7 +4,6 @@ import lombok.Data; ...@@ -4,7 +4,6 @@ import lombok.Data;
@Data @Data
public class TopicConcealReq { public class TopicConcealReq {
private String topicId; private String topicId;
private boolean isConceal; private boolean isConceal;
} }
package com.tanpu.community.api.beans.req.topic;
import com.tanpu.community.api.beans.req.page.Pageable;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class TopicSearchReq {
@ApiModelProperty(value = "搜索关键字")
private String searchKeyword;
@ApiModelProperty(value = "分页")
private Pageable page;
}
package com.tanpu.community.api.beans.vo;
public class CourseVo {
}
package com.tanpu.community.api.beans.vo;
public class ProductVo {
}
package com.tanpu.community.api.beans.vo;
public class ShortVideoVo {
}
package com.tanpu.community.api.beans.vo;
public class ZhiboVo {
}
...@@ -3,31 +3,31 @@ package com.tanpu.community.api.constants; ...@@ -3,31 +3,31 @@ package com.tanpu.community.api.constants;
public class RedisKeyConstant { public class RedisKeyConstant {
//话题页浏览量 //话题页浏览量
public static final String TOPIC_PAGE_VIEW_AMOUNT_ ="TOPIC_PAGE_VIEW_AMOUNT_"; public static final String TOPIC_PAGE_VIEW_COUNT_ ="TOPIC_PAGE_VIEW_COUNT_";
//话题总浏览量=总浏览量+带这个话题的帖子量 //话题总浏览量=总浏览量+带这个话题的帖子量
public static final String TOPIC_TOTAL_VIEW_AMOUNT_="TOPIC_TOTAL_VIEW_AMOUNT_"; public static final String TOPIC_TOTAL_VIEW_COUNT_="TOPIC_TOTAL_VIEW_COUNT_";
//点赞量 //点赞量
public static final String TOPIC_LIKE_AMOUNT_="TOPIC_LIKE_AMOUNT_"; public static final String TOPIC_LIKE_COUNT_="TOPIC_LIKE_COUNT_";
//收藏量 //收藏量
public static final String TOPIC_BOOK_AMOUNT_="TOPIC_BOOK_AMOUNT_"; public static final String TOPIC_BOOK_COUNT_="TOPIC_BOOK_COUNT_";
//用户数 //用户数
public static final String TOPIC_USER_AMOUNT_="TOPIC_USER_AMOUNT_"; public static final String TOPIC_USER_COUNT_="TOPIC_USER_COUNT_";
//讨论量=发布主题贴数+回复总数 //讨论量=发布主题贴数+回复总数
public static final String TOPIC_DISCUSS_AMOUNT_="TOPIC_DISCUSS_AMOUNT_"; public static final String TOPIC_DISCUSS_COUNT_="TOPIC_DISCUSS_COUNT_";
//发帖数 //发帖数
public static final String TOPIC_THEME_AMOUNT_="TOPIC_THEME_AMOUNT_"; public static final String TOPIC_THEME_COUNT_="TOPIC_THEME_COUNT_";
//回帖数 //回帖数
public static final String TOPIC_COMMENT_AMOUNT_="TOPIC_COMMENT_AMOUNT_"; public static final String TOPIC_COMMENT_COUNT_="TOPIC_COMMENT_COUNT_";
//总用户数=访问话题页+发帖+回帖(去重) //总用户数=访问话题页+发帖+回帖(去重)
public static final String TOPIC_TOTAL_USER_AMOUNT_ ="TOPIC_TOTAL_USER_AMOUNT_"; public static final String TOPIC_TOTAL_USER_COUNT_ ="TOPIC_TOTAL_USER_COUNT_";
//访问话题人数 //访问话题人数
public static final String TOPIC_USER_VIEW_AMOUNT_="TOPIC_USER_VIEW_AMOUNT_"; public static final String TOPIC_USER_VIEW_COUNT_="TOPIC_USER_VIEW_COUNT_";
//发帖人数 //发帖人数
public static final String TOPIC_POST_USER_AMOUNT_ ="TOPIC_POST_USER_AMOUNT_"; public static final String TOPIC_POST_USER_COUNT_ ="TOPIC_POST_USER_COUNT_";
//回帖人数 //回帖人数
public static final String TOPIC_COMMENT_USER_AMOUNT_ ="TOPIC_COMMENT_USER_AMOUNT_"; public static final String TOPIC_COMMENT_USER_COUNT_ ="TOPIC_COMMENT_USER_COUNT_";
public static final String THEME_VIEW_AMOUNT_="THEME_VIEW_AMOUNT_"; public static final String THEME_VIEW_COUNT_="THEME_VIEW_COUNT_";
public static final String THEME_LIKE_AMOUNT_="THEME_LIKE_AMOUNT_"; public static final String THEME_LIKE_COUNT_="THEME_LIKE_COUNT_";
public static final String THEME_BOOK_AMOUNT_="THEME_BOOK_AMOUNT_"; public static final String THEME_BOOK_COUNT_="THEME_BOOK_COUNT_";
} }
...@@ -2,8 +2,9 @@ package com.tanpu.community.api.enums; ...@@ -2,8 +2,9 @@ package com.tanpu.community.api.enums;
public enum CollectionTypeEnum { public enum CollectionTypeEnum {
LIKE(1,"点赞"), LIKE_THEME(1,"点赞主题"),
BOOK(2,"收藏"); BOOK_THEME(2,"收藏主题"),
LIKE_COMMENT(3,"点赞评论");
private Integer code; private Integer code;
private String type; private String type;
......
package com.tanpu.community.cache;
import com.tanpu.community.dao.entity.community.HomePageEntity;
import com.tanpu.community.service.HomePageService;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Map;
/**
* 用户信息缓存类
*/
public class HomePageCache {
private Map<String, HomePageEntity> homePageCache;
@Autowired
private HomePageService homePageService;
}
...@@ -2,7 +2,6 @@ package com.tanpu.community.controller; ...@@ -2,7 +2,6 @@ package com.tanpu.community.controller;
import com.tanpu.common.api.CommonResp; import com.tanpu.common.api.CommonResp;
import com.tanpu.common.auth.UserHolder; import com.tanpu.common.auth.UserHolder;
import com.tanpu.community.api.beans.TopicBriefInfoDTO;
import com.tanpu.community.api.beans.TopicDTO; import com.tanpu.community.api.beans.TopicDTO;
import com.tanpu.community.api.beans.TopicDataAnalysDTO; import com.tanpu.community.api.beans.TopicDataAnalysDTO;
import com.tanpu.community.api.beans.req.topic.TopicConcealReq; import com.tanpu.community.api.beans.req.topic.TopicConcealReq;
...@@ -16,8 +15,6 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -16,8 +15,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.MissingServletRequestParameterException; import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController @RestController
@Slf4j @Slf4j
@RequestMapping(value = "/api/admin") @RequestMapping(value = "/api/admin")
...@@ -30,16 +27,7 @@ public class AdminController { ...@@ -30,16 +27,7 @@ public class AdminController {
@Autowired @Autowired
private UserHolder userHolder; private UserHolder userHolder;
@GetMapping(value = "/admin/queryTopicDetailList") @GetMapping(value="/insertTopic")
@ApiOperation("查询所有的话题详情")
@ResponseBody
public CommonResp<List<TopicBriefInfoDTO>> getAllTopicList(){
List<TopicBriefInfoDTO> allTopic = topicManager.getAllTopicBriefInfo();
return CommonResp.success(allTopic);
}
@PostMapping(value="/admin/insertTopic")
@ApiOperation("新增话题") @ApiOperation("新增话题")
@ResponseBody @ResponseBody
public CommonResp<Void> addTopic(@RequestParam String topicTitle){ public CommonResp<Void> addTopic(@RequestParam String topicTitle){
...@@ -79,7 +67,7 @@ public class AdminController { ...@@ -79,7 +67,7 @@ public class AdminController {
@ApiOperation("话题浏览数调整(后台管理)") @ApiOperation("话题浏览数调整(后台管理)")
@ResponseBody @ResponseBody
public CommonResp<Void> modifyViewNum(@RequestBody TopicModifyMountReq req) throws MissingServletRequestParameterException { public CommonResp<Void> modifyViewNum(@RequestBody TopicModifyMountReq req) throws MissingServletRequestParameterException {
topicManager.modifyViewAmount(req.getTopicId(),req.getModifyMount()); topicManager.modifyViewCount(req.getTopicId(),req.getModifyMount());
return CommonResp.success(); return CommonResp.success();
} }
......
package com.tanpu.community.controller;
import com.tanpu.common.api.CommonResp;
import com.tanpu.community.api.beans.qo.CommentQo;
import com.tanpu.community.api.beans.req.CreateCommentReq;
import com.tanpu.community.manager.CommentManager;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@Slf4j
@RequestMapping(value = "/api/theme")
public class CommentController {
@Autowired
private CommentManager commentManager;
@ApiOperation("发表评论")
@PostMapping(value = "/publishComment")
@ResponseBody
public CommonResp<Void> publishCommet(@RequestBody CreateCommentReq req) {
String userId = "liujm";
commentManager.comment(req, userId);
return CommonResp.success();
}
@ApiOperation("查看评论")
@PostMapping(value = "/queryComment")
@ResponseBody
public CommonResp<List<CommentQo>> queryComment(@RequestParam String themeId){
//todo
String userId = "liujm";
List<CommentQo> result = commentManager.queryComments(themeId,userId);
return CommonResp.success(result);
}
@ApiOperation("点赞评论")
@PostMapping(value = "/likeComment")
@ResponseBody
public CommonResp likeComment(@RequestParam String themeId){
//todo
String userId = "liujm";
return CommonResp.success();
}
@ApiOperation("举报评论")
@PostMapping(value = "/reportComment")
@ResponseBody
public CommonResp reportComment(@RequestParam String themeId){
//todo
String userId = "liujm";
return CommonResp.success();
}
}
...@@ -84,7 +84,7 @@ public class HomePageController { ...@@ -84,7 +84,7 @@ public class HomePageController {
return CommonResp.success(); return CommonResp.success();
} }
@PostMapping(value = "/query/queryMyLike") @PostMapping(value = "/queryMyLike")
@ApiOperation("我的点赞帖子列表") @ApiOperation("我的点赞帖子列表")
@ResponseBody @ResponseBody
public CommonResp<List<ThemeQo>> likeList(){ public CommonResp<List<ThemeQo>> likeList(){
......
...@@ -16,7 +16,7 @@ public class MetricsController { ...@@ -16,7 +16,7 @@ public class MetricsController {
@ApiOperation("浏览量埋点") @ApiOperation("浏览量埋点")
@RequestMapping("/pv") @RequestMapping("/pv")
public CommonResp pageView(@RequestParam String themeId){ public CommonResp pageView(@RequestParam String themeId){
redisService.incr(RedisKeyConstant.THEME_VIEW_AMOUNT_ +themeId, 1L); redisService.incr(RedisKeyConstant.THEME_VIEW_COUNT_ +themeId, 1L);
return CommonResp.success(); return CommonResp.success();
} }
......
...@@ -5,8 +5,8 @@ import com.tanpu.common.api.CommonResp; ...@@ -5,8 +5,8 @@ import com.tanpu.common.api.CommonResp;
import com.tanpu.community.api.beans.ForwardThemeReq; import com.tanpu.community.api.beans.ForwardThemeReq;
import com.tanpu.community.api.beans.qo.MainTextQo; import com.tanpu.community.api.beans.qo.MainTextQo;
import com.tanpu.community.api.beans.qo.ThemeQo; import com.tanpu.community.api.beans.qo.ThemeQo;
import com.tanpu.community.api.beans.req.CreateCommentReq;
import com.tanpu.community.api.beans.req.CreateThemeReq; import com.tanpu.community.api.beans.req.CreateThemeReq;
import com.tanpu.community.api.beans.req.theme.ThemeListReq;
import com.tanpu.community.manager.ThemeManager; import com.tanpu.community.manager.ThemeManager;
import com.tanpu.community.service.FollowRelService; import com.tanpu.community.service.FollowRelService;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
...@@ -31,39 +31,31 @@ public class ThemeController { ...@@ -31,39 +31,31 @@ public class ThemeController {
@ApiOperation("发表主题") @ApiOperation("发表主题")
@PostMapping(value = "/publish") @PostMapping(value = "/publish")
@ResponseBody @ResponseBody
public CommonResp<Void> publishTheme(@RequestBody CreateThemeReq req) { public CommonResp<Void> publishTheme(@Validated @RequestBody CreateThemeReq req) {
String userId = "liujm"; String userId = "liujm";
themeManager.publishTheme(req, userId); themeManager.publishTheme(req, userId);
return CommonResp.success(); return CommonResp.success();
} }
@ApiOperation("圈子首页-推荐") @ApiOperation("圈子首页-推荐")
@GetMapping (value = "/recmend_list") @GetMapping (value = "/recommendList")
@ResponseBody @ResponseBody
public List<ThemeQo> selectHotList() { public List<ThemeQo> selectHotList(ThemeListReq req) {
String userId = "liujm"; String userId = "liujm";
return themeManager.selectHotThemes(userId); return themeManager.selectHotThemes(req,userId);
} }
@ApiOperation("圈子首页-关注") @ApiOperation("圈子首页-关注")
@GetMapping(value = "/interest_list") @GetMapping(value = "/followList")
@ResponseBody @ResponseBody
public List<ThemeQo> selectInterestList() { public List<ThemeQo> selectInterestList(ThemeListReq req) {
String userId = "liujm012"; String userId = "liujm012";
return themeManager.selectInterestThemes(userId); return themeManager.selectInterestThemes(req,userId);
} }
@ApiOperation("评论")
@PostMapping(value = "/comment")
@ResponseBody
public CommonResp<Void> commetOnTheme(@RequestBody CreateCommentReq req) {
String userId = "liujm";
themeManager.comment(req, userId);
return CommonResp.success();
}
@ApiOperation("主题正文") @ApiOperation("主题正文")
@GetMapping(value = "/main_text") @GetMapping(value = "/detail")
@ResponseBody @ResponseBody
public CommonResp<MainTextQo> getThemeMainText(@RequestParam String topicId) { public CommonResp<MainTextQo> getThemeMainText(@RequestParam String topicId) {
String userId = "liujm"; String userId = "liujm";
...@@ -98,7 +90,7 @@ public class ThemeController { ...@@ -98,7 +90,7 @@ public class ThemeController {
} }
@ApiOperation("收藏主题") @ApiOperation("收藏主题")
@GetMapping(value = "/book") @GetMapping(value = "/collect")
@ResponseBody @ResponseBody
public CommonResp bookTheme(String themeId) { public CommonResp bookTheme(String themeId) {
String user = "liujm"; String user = "liujm";
...@@ -107,7 +99,7 @@ public class ThemeController { ...@@ -107,7 +99,7 @@ public class ThemeController {
} }
@ApiOperation("举报主题") @ApiOperation("举报主题")
@GetMapping(value = "/complaint") @GetMapping(value = "/report")
@ResponseBody @ResponseBody
public CommonResp complaintTheme(@RequestParam String themeId) { public CommonResp complaintTheme(@RequestParam String themeId) {
...@@ -115,7 +107,7 @@ public class ThemeController { ...@@ -115,7 +107,7 @@ public class ThemeController {
} }
@ApiOperation("屏蔽") @ApiOperation("屏蔽")
@GetMapping(value = "/conceal") @GetMapping(value = "/block")
@ResponseBody @ResponseBody
public CommonResp concealTheme(String themeId) { public CommonResp concealTheme(String themeId) {
String user = "liujm"; String user = "liujm";
......
...@@ -2,18 +2,14 @@ package com.tanpu.community.controller; ...@@ -2,18 +2,14 @@ package com.tanpu.community.controller;
import com.tanpu.common.api.CommonResp; import com.tanpu.common.api.CommonResp;
import com.tanpu.common.auth.UserHolder; import com.tanpu.common.auth.UserHolder;
import com.tanpu.community.api.beans.TopicBriefInfoDTO; import com.tanpu.community.api.beans.qo.ThemeQo;
import com.tanpu.community.api.beans.TopicDTO; import com.tanpu.community.api.beans.qo.TopicTitileQo;
import com.tanpu.community.api.beans.TopicDataAnalysDTO; import com.tanpu.community.api.beans.req.topic.TopicSearchReq;
import com.tanpu.community.api.beans.req.page.Page;
import com.tanpu.community.manager.TopicManager; import com.tanpu.community.manager.TopicManager;
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 io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.List;
...@@ -30,15 +26,31 @@ public class TopicController { ...@@ -30,15 +26,31 @@ public class TopicController {
private UserHolder userHolder; private UserHolder userHolder;
@GetMapping(value = "/queryTopicInfoList") @GetMapping(value = "/list")
@ApiOperation("APP全部话题页面,可搜索") @ApiOperation("APP全部话题页面,可搜索")
@ResponseBody @ResponseBody
public CommonResp<List<TopicDTO>> getTopicBriefInfoList(){ public CommonResp<Page<TopicTitileQo>> getTopicBriefInfoList(TopicSearchReq req){
List<TopicDTO> allTopic = topicManager.getAllTopicDetail(); Page<TopicTitileQo> allTopic = topicManager.getAllTopicBriefInfo(req);
return CommonResp.success(allTopic); return CommonResp.success(allTopic);
} }
@GetMapping(value = "/hotThemes")
@ApiOperation("话题详情页")
@ResponseBody
public CommonResp<List<ThemeQo>> gethotThemes(@RequestParam String topicId){
//todo
return CommonResp.success();
}
@GetMapping(value = "/latestThemes")
@ApiOperation("话题详情页")
@ResponseBody
public CommonResp<List<ThemeQo>> getlatestThemes(@RequestParam String topicId){
//todo
return CommonResp.success();
}
......
...@@ -45,12 +45,6 @@ public class ThemeEntity implements Serializable { ...@@ -45,12 +45,6 @@ public class ThemeEntity implements Serializable {
@ApiModelProperty(value = "文本内容") @ApiModelProperty(value = "文本内容")
private String content; private String content;
@ApiModelProperty(value = "附件类型")
private Integer attachType;
@ApiModelProperty(value = "附件内容")
private String attachment;
@ApiModelProperty(value = "作者id") @ApiModelProperty(value = "作者id")
private String authorId; private String authorId;
...@@ -107,22 +101,6 @@ public class ThemeEntity implements Serializable { ...@@ -107,22 +101,6 @@ public class ThemeEntity implements Serializable {
this.content = content; this.content = content;
} }
public Integer getAttachType() {
return attachType;
}
public void setAttachType(Integer attachType) {
this.attachType = attachType;
}
public String getAttachment() {
return attachment;
}
public void setAttachment(String attachment) {
this.attachment = attachment;
}
public String getAuthorId() { public String getAuthorId() {
return authorId; return authorId;
} }
...@@ -179,8 +157,6 @@ public class ThemeEntity implements Serializable { ...@@ -179,8 +157,6 @@ public class ThemeEntity implements Serializable {
", title=" + title + ", title=" + title +
", themeType=" + themeType + ", themeType=" + themeType +
", content=" + content + ", content=" + content +
", attachType=" + attachType +
", attachment=" + attachment +
", authorId=" + authorId + ", authorId=" + authorId +
", formerThemeId=" + formerThemeId + ", formerThemeId=" + formerThemeId +
", topicId=" + topicId + ", topicId=" + topicId +
......
...@@ -46,7 +46,7 @@ public class TopicEntity implements Serializable { ...@@ -46,7 +46,7 @@ public class TopicEntity implements Serializable {
private Integer isConceal; private Integer isConceal;
@ApiModelProperty(value = "浏览量调整") @ApiModelProperty(value = "浏览量调整")
private Long viewAmountModify; private Long viewCntAdjust;
private LocalDateTime createTime; private LocalDateTime createTime;
...@@ -95,12 +95,12 @@ public class TopicEntity implements Serializable { ...@@ -95,12 +95,12 @@ public class TopicEntity implements Serializable {
this.isConceal = isConceal; this.isConceal = isConceal;
} }
public Long getViewAmountModify() { public Long getviewCntAdjust() {
return viewAmountModify; return viewCntAdjust;
} }
public void setViewAmountModify(Long viewAmountModify) { public void setViewAmountModify(Long viewAmountModify) {
this.viewAmountModify = viewAmountModify; this.viewCntAdjust = viewAmountModify;
} }
public LocalDateTime getCreateTime() { public LocalDateTime getCreateTime() {
...@@ -135,7 +135,7 @@ public class TopicEntity implements Serializable { ...@@ -135,7 +135,7 @@ public class TopicEntity implements Serializable {
", topicTitle=" + topicTitle + ", topicTitle=" + topicTitle +
", isTop=" + isTop + ", isTop=" + isTop +
", isConceal=" + isConceal + ", isConceal=" + isConceal +
", viewAmountModify=" + viewAmountModify + ", viewAmountModify=" + viewCntAdjust +
", createTime=" + createTime + ", createTime=" + createTime +
", updateTime=" + updateTime + ", updateTime=" + updateTime +
", deleteTag=" + deleteTag + ", deleteTag=" + deleteTag +
......
package com.tanpu.community.manager;
import com.tanpu.community.api.beans.qo.CommentQo;
import com.tanpu.community.api.beans.req.CreateCommentReq;
import com.tanpu.community.api.enums.CollectionTypeEnum;
import com.tanpu.community.api.enums.CommentTypeEnum;
import com.tanpu.community.dao.entity.community.CommentEntity;
import com.tanpu.community.dao.entity.community.HomePageEntity;
import com.tanpu.community.service.CollectionService;
import com.tanpu.community.service.CommentService;
import com.tanpu.community.service.HomePageService;
import com.tanpu.community.util.ConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Set;
@Service
public class CommentManager {
@Autowired
private CommentService commentService;
@Autowired
private HomePageService homePageService;
@Autowired
private CollectionService collectionService;
// 评论(对主题)
public void comment(CreateCommentReq req, String userId) {
CommentEntity commentEntity = CommentEntity.builder()
.themeId(req.getThemeId())
.parentId(req.getParentId())
.replyId(req.getReplyId())
.authorId(userId)
.content(req.getComment())
.commentType(CommentTypeEnum.THEME.getCode())
.build();
commentService.insertComment(commentEntity);
}
public List<CommentQo> queryComments(String themeId,String userId) {
List<CommentEntity> commentEntities = commentService.selectByThemeIdAndParentId(themeId, null);
List<CommentQo> commentQos = ConvertUtil.commentEntity2Qos(commentEntities);
Set<String> likeCommentList = collectionService.getListByUser(userId, CollectionTypeEnum.LIKE_COMMENT);
for (CommentQo commentQo : commentQos) {
//用户信息
String authorId = commentQo.getAuthorId();
HomePageEntity homePageEntity = homePageService.selectByUserId(authorId);
commentQo.setUserImg(homePageEntity.getHeadImg());
commentQo.setNickName(homePageEntity.getNickName());
//是否点赞及点赞数
String commentId = commentQo.getCommentId();
if (likeCommentList.contains(commentId)){
commentQo.setLiked(true);
}else {
commentQo.setLiked(false);
}
Integer countByTypeAndId = collectionService.getCountByTypeAndId(commentId,CollectionTypeEnum.LIKE_COMMENT);
commentQo.setLikeCount(countByTypeAndId);
//二级评论,本期不上线
// List<CommentEntity> CommentLv2Entities = commentService.selectByThemeIdAndParentId(themeId, commentId);
// List<CommentLv2Qo> commentLv2Qos = ConvertUtil.commentLv2Entity2Qos(CommentLv2Entities);
// commentQo.setCommentLv2Qos(commentLv2Qos);
}
return commentQos;
}
}
...@@ -3,16 +3,18 @@ package com.tanpu.community.manager; ...@@ -3,16 +3,18 @@ package com.tanpu.community.manager;
import com.tanpu.common.api.CommonResp; import com.tanpu.common.api.CommonResp;
import com.tanpu.common.exception.BizException; import com.tanpu.common.exception.BizException;
import com.tanpu.community.api.beans.ForwardThemeReq; import com.tanpu.community.api.beans.ForwardThemeReq;
import com.tanpu.community.api.beans.qo.CommentQo; import com.tanpu.community.api.beans.qo.AttachmentQo;
import com.tanpu.community.api.beans.qo.MainTextQo; import com.tanpu.community.api.beans.qo.MainTextQo;
import com.tanpu.community.api.beans.qo.ThemeQo; import com.tanpu.community.api.beans.qo.ThemeQo;
import com.tanpu.community.api.beans.req.CreateCommentReq;
import com.tanpu.community.api.beans.req.CreateThemeReq; import com.tanpu.community.api.beans.req.CreateThemeReq;
import com.tanpu.community.api.beans.req.theme.ThemeListReq;
import com.tanpu.community.api.enums.BlockTypeEnum; import com.tanpu.community.api.enums.BlockTypeEnum;
import com.tanpu.community.api.enums.CollectionTypeEnum; import com.tanpu.community.api.enums.CollectionTypeEnum;
import com.tanpu.community.api.enums.CommentTypeEnum;
import com.tanpu.community.api.enums.ThemeTypeEnum; import com.tanpu.community.api.enums.ThemeTypeEnum;
import com.tanpu.community.dao.entity.community.*; import com.tanpu.community.dao.entity.community.BlackListEntity;
import com.tanpu.community.dao.entity.community.HomePageEntity;
import com.tanpu.community.dao.entity.community.ThemeAttachmentEntity;
import com.tanpu.community.dao.entity.community.ThemeEntity;
import com.tanpu.community.feign.course.FeignClientForCourse; import com.tanpu.community.feign.course.FeignClientForCourse;
import com.tanpu.community.feign.course.vo.CourseDetailExt; import com.tanpu.community.feign.course.vo.CourseDetailExt;
import com.tanpu.community.feign.product.FeignClientForProducts; import com.tanpu.community.feign.product.FeignClientForProducts;
...@@ -100,7 +102,7 @@ public class ThemeManager { ...@@ -100,7 +102,7 @@ public class ThemeManager {
} }
// 返回推荐主题文章 // 返回推荐主题文章
public List<ThemeQo> selectHotThemes(String userId) { public List<ThemeQo> selectHotThemes(ThemeListReq req, String userId) {
// TODO:推荐 // TODO:推荐
List<ThemeEntity> themeEntities = themeService.selectAll(); List<ThemeEntity> themeEntities = themeService.selectAll();
List<ThemeQo> themeQos = convertEntityToQo(themeEntities, userId); List<ThemeQo> themeQos = convertEntityToQo(themeEntities, userId);
...@@ -109,7 +111,7 @@ public class ThemeManager { ...@@ -109,7 +111,7 @@ public class ThemeManager {
// 返回关注主题 // 返回关注主题
public List<ThemeQo> selectInterestThemes(String userId) { public List<ThemeQo> selectInterestThemes(ThemeListReq req,String userId) {
List<String> fansList = followRelService.queryFansByFollowerId(userId); List<String> fansList = followRelService.queryFansByFollowerId(userId);
List<ThemeEntity> themeEntities = themeService.selectByFans(fansList); List<ThemeEntity> themeEntities = themeService.selectByFans(fansList);
List<ThemeQo> themeQos = convertEntityToQo(themeEntities, userId); List<ThemeQo> themeQos = convertEntityToQo(themeEntities, userId);
...@@ -131,23 +133,13 @@ public class ThemeManager { ...@@ -131,23 +133,13 @@ public class ThemeManager {
// 点赞 // 点赞
public void like(String themeId, String userId) { public void like(String themeId, String userId) {
collectionService.addIfNotExist(themeId, userId, CollectionTypeEnum.LIKE); collectionService.addIfNotExist(themeId, userId, CollectionTypeEnum.LIKE_THEME);
} }
public void unlike(String themeId, String userId) { public void unlike(String themeId, String userId) {
} }
// 评论(对主题)
public void comment(CreateCommentReq req, String userId) {
CommentEntity commentEntity = CommentEntity.builder()
.themeId(req.getThemeId())
.authorId(userId)
.content(req.getComment())
.commentType(CommentTypeEnum.THEME.getCode())
.build();
commentService.insertComment(commentEntity);
}
//转发 //转发
public void forward(ForwardThemeReq req, String userId) { public void forward(ForwardThemeReq req, String userId) {
...@@ -166,11 +158,11 @@ public class ThemeManager { ...@@ -166,11 +158,11 @@ public class ThemeManager {
//收藏 //收藏
public void favorite(String themeId, String userId) { public void favorite(String themeId, String userId) {
collectionService.addIfNotExist(themeId, userId, CollectionTypeEnum.BOOK); collectionService.addIfNotExist(themeId, userId, CollectionTypeEnum.BOOK_THEME);
} }
public void unFavorite(String themeId, String userId) { public void unFavorite(String themeId, String userId) {
collectionService.delete(themeId, userId, CollectionTypeEnum.BOOK); collectionService.delete(themeId, userId, CollectionTypeEnum.BOOK_THEME);
} }
//投诉(主题) //投诉(主题)
...@@ -219,11 +211,12 @@ public class ThemeManager { ...@@ -219,11 +211,12 @@ public class ThemeManager {
//组装主题列表 //组装主题列表
private void buildThemeQoExtraInfo(String userId, ThemeQo themeQO) { private void buildThemeQoExtraInfo(String userId, ThemeQo themeQO) {
//附件列表 //附件列表
List<ThemeAttachmentEntity> attachments = themeAttachmentService.selectByThemeId(themeQO.getId()); String themeId = themeQO.getThemeId();
List<ThemeAttachmentEntity> attachments = themeAttachmentService.selectByThemeId(themeId);
if (!CollectionUtils.isEmpty(attachments)) { if (!CollectionUtils.isEmpty(attachments)) {
HashMap<String, Object> attachmentQos = new HashMap<>(); ThemeAttachmentEntity attachmentEntity = attachments.get(0);
attachments.forEach(o -> attachmentQos.put(o.getAttachId(), transferAttachment(o, userId))); AttachmentQo attachmentQo = AttachmentQo.builder().type(attachmentEntity.getAttachType()).attachment(transferAttachment(attachmentEntity, userId)).build();
themeQO.setAttachment(attachmentQos); themeQO.setAttachmentQo(attachmentQo);
} }
//迄今时间 //迄今时间
themeQO.setUpToNowTime(calUpToNowTime(themeQO.getCreateTime())); themeQO.setUpToNowTime(calUpToNowTime(themeQO.getCreateTime()));
...@@ -235,10 +228,13 @@ public class ThemeManager { ...@@ -235,10 +228,13 @@ public class ThemeManager {
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());
//热点数据 TODO 点赞量、评论量、转发量 //热点数据:点赞,收藏,转发
themeQO.setCommentAmount(0L); Integer likeCount = collectionService.getCountByTypeAndId(themeId, CollectionTypeEnum.LIKE_THEME);
themeQO.setLikeAmount(0L); Integer bookCount = collectionService.getCountByTypeAndId(themeId, CollectionTypeEnum.BOOK_THEME);
themeQO.setForwardAmount(0L); Integer forwardCount = themeService.getForwardCountById(themeId);
themeQO.setCommentCount(bookCount);
themeQO.setLikeCount(likeCount);
themeQO.setForwardCount(forwardCount);
} }
//组装正文详情 //组装正文详情
...@@ -246,8 +242,11 @@ public class ThemeManager { ...@@ -246,8 +242,11 @@ public class ThemeManager {
//附件列表 //附件列表
List<ThemeAttachmentEntity> attachments = themeAttachmentService.selectByThemeId(maintTextQo.getId()); List<ThemeAttachmentEntity> attachments = themeAttachmentService.selectByThemeId(maintTextQo.getId());
if (!CollectionUtils.isEmpty(attachments)) { if (!CollectionUtils.isEmpty(attachments)) {
HashMap<String, Object> attachmentQos = new HashMap<>(); List<AttachmentQo> attachmentQos = new ArrayList<>();
attachments.forEach(o -> attachmentQos.put(o.getAttachId(), transferAttachment(o, userId))); attachments.forEach(o -> attachmentQos.add(AttachmentQo.builder()
.type(o.getAttachType())
.attachment(transferAttachment(o,userId))
.build()));
maintTextQo.setAttachment(attachmentQos); maintTextQo.setAttachment(attachmentQos);
} }
//迄今时间 //迄今时间
...@@ -256,16 +255,7 @@ public class ThemeManager { ...@@ -256,16 +255,7 @@ public class ThemeManager {
HomePageEntity author = homePageService.selectByUserId(userId); HomePageEntity author = homePageService.selectByUserId(userId);
maintTextQo.setUserImg(author.getHeadImg()); maintTextQo.setUserImg(author.getHeadImg());
maintTextQo.setNickName(author.getNickName()); maintTextQo.setNickName(author.getNickName());
//评论
List<CommentQo> commentQos = ConvertUtil.commentEntity2Qos(commentService.selectByTargetId(maintTextQo.getId()));
for (CommentQo comment : commentQos) {
HomePageEntity commentor = homePageService.selectByUserId(comment.getAuthorId());
comment.setUserImg(commentor.getHeadImg());
comment.setNickName(commentor.getNickName());
//TODO 评论点赞量
comment.setLikeAmount(0L);
}
maintTextQo.setComments(commentQos);
return; return;
} }
......
package com.tanpu.community.manager; package com.tanpu.community.manager;
import com.tanpu.common.exception.BizException; import com.tanpu.common.exception.BizException;
import com.tanpu.community.api.beans.TopicBriefInfoDTO;
import com.tanpu.community.api.beans.TopicDTO; import com.tanpu.community.api.beans.TopicDTO;
import com.tanpu.community.api.beans.TopicDataAnalysDTO; import com.tanpu.community.api.beans.TopicDataAnalysDTO;
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.constants.RedisKeyConstant; 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.ThemeEntity;
import com.tanpu.community.dao.entity.community.TopicEntity; import com.tanpu.community.dao.entity.community.TopicEntity;
import com.tanpu.community.service.*; import com.tanpu.community.service.*;
import com.tanpu.community.util.ConvertUtil; import com.tanpu.community.util.ConvertUtil;
import com.tanpu.community.util.PageUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -37,7 +41,7 @@ public class TopicManager { ...@@ -37,7 +41,7 @@ public class TopicManager {
//新增话题 //新增话题
public void insertTopic(String topicTitle, String userId) { public void insertTopic(String topicTitle, String userId) {
if (topicService.queryByTitile(topicTitle) == null){ if (topicService.queryByTitile(topicTitle) == null) {
topicService.addTopic(topicTitle, userId); topicService.addTopic(topicTitle, userId);
} }
return; return;
...@@ -51,15 +55,17 @@ public class TopicManager { ...@@ -51,15 +55,17 @@ public class TopicManager {
//话题简介列表 //话题简介列表
public List<TopicBriefInfoDTO> getAllTopicBriefInfo() { public Page<TopicTitileQo> getAllTopicBriefInfo(TopicSearchReq req) {
List<TopicEntity> allTopic = topicService.queryAll(); List<TopicEntity> allTopic = topicService.queryByKeyword(req.getSearchKeyword());
List<TopicBriefInfoDTO> topicDTOS = ConvertUtil.topicEntitiesToBriefDTOs(allTopic); List<TopicTitileQo> topicTitileQos = ConvertUtil.topicEntitiesToBriefDTOs(allTopic);
//讨论数=发布主题贴数+回复总数 //讨论数=发布主题贴数+回复总数
for (TopicBriefInfoDTO topicDTO : topicDTOS) { for (TopicTitileQo topicQo : topicTitileQos) {
Long discussAmount = redisService.getLong(RedisKeyConstant.TOPIC_DISCUSS_AMOUNT_ + topicDTO.getTopicId()); // Integer commentCountByThemeIds = commentService.getCommentCountByThemeIds(themeIds);
topicDTO.setDiscussionAmount(discussAmount);
topicQo.setDiscussionCount(0);
} }
return topicDTOS;
return PageUtils.page(req.getPage(),topicTitileQos);
} }
...@@ -93,22 +99,22 @@ public class TopicManager { ...@@ -93,22 +99,22 @@ public class TopicManager {
throw new BizException("找不到话题,id:" + topicId); throw new BizException("找不到话题,id:" + topicId);
} }
TopicDTO topicDTO = ConvertUtil.topicEntityToDTO(topicEntity); TopicDTO topicDTO = ConvertUtil.topicEntityToDTO(topicEntity);
topicDTO.setViewAmount(redisService.getLong(RedisKeyConstant.TOPIC_TOTAL_VIEW_AMOUNT_ + topicId)); topicDTO.setViewCount(redisService.getInteger(RedisKeyConstant.TOPIC_TOTAL_VIEW_COUNT_ + topicId));
topicDTO.setLikeAmount(redisService.getLong(RedisKeyConstant.TOPIC_LIKE_AMOUNT_ + topicId)); topicDTO.setLikeCount(redisService.getInteger(RedisKeyConstant.TOPIC_LIKE_COUNT_ + topicId));
topicDTO.setUserAmount(redisService.getLong(RedisKeyConstant.TOPIC_USER_AMOUNT_ + topicId)); topicDTO.setUserCount(redisService.getInteger(RedisKeyConstant.TOPIC_USER_COUNT_ + topicId));
return topicDTO; return topicDTO;
} }
public void modifyViewAmount(String topicId, Long modifyMount) { public void modifyViewCount(String topicId, Long modifyMount) {
TopicEntity topicEntity = topicService.queryById(topicId); TopicEntity topicEntity = topicService.queryById(topicId);
if (topicEntity == null) { if (topicEntity == null) {
throw new BizException("找不到话题,id:" + topicId); throw new BizException("找不到话题,id:" + topicId);
} }
topicService.modifyViewAmount(topicId, modifyMount); topicService.modifyViewCount(topicId, modifyMount);
if (modifyMount > 0) { if (modifyMount > 0) {
redisService.incr(RedisKeyConstant.TOPIC_TOTAL_VIEW_AMOUNT_ + topicId, modifyMount); redisService.incr(RedisKeyConstant.TOPIC_TOTAL_VIEW_COUNT_ + topicId, modifyMount);
} else { } else {
redisService.decr(RedisKeyConstant.TOPIC_TOTAL_VIEW_AMOUNT_ + topicId, -modifyMount); redisService.decr(RedisKeyConstant.TOPIC_TOTAL_VIEW_COUNT_ + topicId, -modifyMount);
} }
} }
...@@ -118,27 +124,27 @@ public class TopicManager { ...@@ -118,27 +124,27 @@ public class TopicManager {
List<TopicEntity> topicEntities = topicService.queryAll(); List<TopicEntity> topicEntities = topicService.queryAll();
for (TopicEntity topic : topicEntities) { for (TopicEntity topic : topicEntities) {
String topicId = topic.getTopicId(); String topicId = topic.getTopicId();
Long viewAmountModify = topic.getViewAmountModify(); Long viewCountModify = topic.getviewCntAdjust();
List<ThemeEntity> themeEntities = themeService.selectByTopic(topicId); List<ThemeEntity> themeEntities = themeService.selectByTopic(topicId);
List<String> themeIds = themeEntities.stream().map(ThemeEntity::getThemeId).collect(Collectors.toList()); List<String> themeIds = themeEntities.stream().map(ThemeEntity::getThemeId).collect(Collectors.toList());
Long likeAmountByThemeIds = collectionService.getLikeAmountByThemeIds(themeIds); Integer likeCountByThemeIds = collectionService.getCountByTypeAndIds(themeIds, CollectionTypeEnum.LIKE_THEME);
Long bookAmountByThemeIds = collectionService.getBookAmountByThemeIds(themeIds); Integer bookCountByThemeIds = collectionService.getCountByTypeAndIds(themeIds, CollectionTypeEnum.BOOK_THEME);
Long commentAmountByThemeIds = commentService.getCommentAmountByThemeIds(themeIds); Long commentCountByThemeIds = (long)commentService.getCommentCountByThemeIds(themeIds);
Set<String> postUsers = themeService.getPostUserAmount(themeIds); Set<String> postUsers = themeService.getPostUserCount(themeIds);
Set<String> commentUsers = commentService.getCommentUserAmount(themeIds); Set<String> commentUsers = commentService.getCommentUserCount(themeIds);
HashSet<String> totalUsers = new HashSet<>(postUsers); HashSet<String> totalUsers = new HashSet<>(postUsers);
totalUsers.addAll(commentUsers); totalUsers.addAll(commentUsers);
redisService.set(RedisKeyConstant.TOPIC_LIKE_AMOUNT_ + topicId, likeAmountByThemeIds); redisService.set(RedisKeyConstant.TOPIC_LIKE_COUNT_ + topicId, likeCountByThemeIds);
redisService.set(RedisKeyConstant.TOPIC_BOOK_AMOUNT_ + topicId, bookAmountByThemeIds); redisService.set(RedisKeyConstant.TOPIC_BOOK_COUNT_ + topicId, bookCountByThemeIds);
redisService.set(RedisKeyConstant.TOPIC_COMMENT_AMOUNT_ + topicId, commentAmountByThemeIds); redisService.set(RedisKeyConstant.TOPIC_COMMENT_COUNT_ + topicId, commentCountByThemeIds);
redisService.set(RedisKeyConstant.TOPIC_TOTAL_VIEW_AMOUNT_ + topicId, commentAmountByThemeIds + themeIds.size()); redisService.set(RedisKeyConstant.TOPIC_TOTAL_VIEW_COUNT_ + topicId, commentCountByThemeIds + themeIds.size());
redisService.set(RedisKeyConstant.TOPIC_THEME_AMOUNT_ + topicId, commentAmountByThemeIds + themeIds.size()); redisService.set(RedisKeyConstant.TOPIC_THEME_COUNT_ + topicId, commentCountByThemeIds + themeIds.size());
redisService.set(RedisKeyConstant.TOPIC_DISCUSS_AMOUNT_ + topicId, commentAmountByThemeIds + themeIds.size()); redisService.set(RedisKeyConstant.TOPIC_DISCUSS_COUNT_ + topicId, commentCountByThemeIds + themeIds.size());
redisService.set(RedisKeyConstant.TOPIC_POST_USER_AMOUNT_ + topicId, (long) postUsers.size()); redisService.set(RedisKeyConstant.TOPIC_POST_USER_COUNT_ + topicId, (long) postUsers.size());
redisService.set(RedisKeyConstant.TOPIC_COMMENT_USER_AMOUNT_ + topicId, (long) commentUsers.size()); redisService.set(RedisKeyConstant.TOPIC_COMMENT_USER_COUNT_ + topicId, (long) commentUsers.size());
redisService.set(RedisKeyConstant.TOPIC_TOTAL_USER_AMOUNT_ + topicId, (long) totalUsers.size()); redisService.set(RedisKeyConstant.TOPIC_TOTAL_USER_COUNT_ + topicId, (long) totalUsers.size());
} }
...@@ -155,13 +161,13 @@ public class TopicManager { ...@@ -155,13 +161,13 @@ public class TopicManager {
this.refreshRedisCache(); this.refreshRedisCache();
topicDataAnalysDTO.setId(topicId); topicDataAnalysDTO.setId(topicId);
topicDataAnalysDTO.setTopicTitle(topicEntity.getTopicTitle()); topicDataAnalysDTO.setTopicTitle(topicEntity.getTopicTitle());
topicDataAnalysDTO.setCommentAmount(redisService.getInteger(RedisKeyConstant.TOPIC_COMMENT_AMOUNT_ + topicId)); topicDataAnalysDTO.setCommentCount(redisService.getInteger(RedisKeyConstant.TOPIC_COMMENT_COUNT_ + topicId));
topicDataAnalysDTO.setPosterAmount(redisService.getInteger(RedisKeyConstant.TOPIC_POST_USER_AMOUNT_ + topicId)); topicDataAnalysDTO.setPosterCount(redisService.getInteger(RedisKeyConstant.TOPIC_POST_USER_COUNT_ + topicId));
topicDataAnalysDTO.setReplIierAmount(redisService.getInteger(RedisKeyConstant.TOPIC_COMMENT_USER_AMOUNT_ + topicId)); topicDataAnalysDTO.setReplIierCount(redisService.getInteger(RedisKeyConstant.TOPIC_COMMENT_USER_COUNT_ + topicId));
topicDataAnalysDTO.setThemeAmount(redisService.getInteger(RedisKeyConstant.TOPIC_THEME_AMOUNT_ + topicId)); topicDataAnalysDTO.setThemeCount(redisService.getInteger(RedisKeyConstant.TOPIC_THEME_COUNT_ + topicId));
topicDataAnalysDTO.setUserTotalAmount(redisService.getInteger(RedisKeyConstant.TOPIC_TOTAL_USER_AMOUNT_ + topicId)); topicDataAnalysDTO.setUserTotalCount(redisService.getInteger(RedisKeyConstant.TOPIC_TOTAL_USER_COUNT_ + topicId));
topicDataAnalysDTO.setViewTotalAmount(redisService.getInteger(RedisKeyConstant.TOPIC_TOTAL_VIEW_AMOUNT_ + topicId)); topicDataAnalysDTO.setViewTotalCount(redisService.getInteger(RedisKeyConstant.TOPIC_TOTAL_VIEW_COUNT_ + topicId));
topicDataAnalysDTO.setViewPageAmount(redisService.getInteger(RedisKeyConstant.TOPIC_PAGE_VIEW_AMOUNT_ + topicId)); topicDataAnalysDTO.setViewPageCount(redisService.getInteger(RedisKeyConstant.TOPIC_PAGE_VIEW_COUNT_ + topicId));
return topicDataAnalysDTO; return topicDataAnalysDTO;
} }
} }
......
package com.tanpu.community.service; package com.tanpu.community.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tanpu.common.uuid.UuidGenHelper; import com.tanpu.common.exception.BizException;
import com.tanpu.community.api.enums.CollectionTypeEnum; import com.tanpu.community.api.enums.CollectionTypeEnum;
import com.tanpu.community.api.enums.DeleteTagEnum; import com.tanpu.community.api.enums.DeleteTagEnum;
import com.tanpu.community.dao.entity.community.CollectionEntity; import com.tanpu.community.dao.entity.community.CollectionEntity;
import com.tanpu.community.dao.mapper.community.CollectionMapper; import com.tanpu.community.dao.mapper.community.CollectionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
@Service @Service
public class CollectionService { public class CollectionService {
...@@ -46,7 +47,7 @@ public class CollectionService { ...@@ -46,7 +47,7 @@ public class CollectionService {
.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, themeId)
.eq(CollectionEntity::getDeleteTag,DeleteTagEnum.NOT_DELETED.getCode())); .eq(CollectionEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode()));
} }
//根据用户、主题、类型查询已删除对象 //根据用户、主题、类型查询已删除对象
...@@ -55,60 +56,34 @@ public class CollectionService { ...@@ -55,60 +56,34 @@ public class CollectionService {
.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, themeId)
.eq(CollectionEntity::getDeleteTag,DeleteTagEnum.DELETED.getCode())); .eq(CollectionEntity::getDeleteTag, DeleteTagEnum.DELETED.getCode()));
} }
// 根据用户id获取点赞列表 // 根据用户id和行为type获取target_id列表
public List<CollectionEntity> getLikeListByUser(String userId) { public Set<String> getListByUser(String userId, CollectionTypeEnum type) {
return collectionMapper.selectList(new LambdaQueryWrapper<CollectionEntity>() return collectionMapper.selectList(new LambdaQueryWrapper<CollectionEntity>()
.eq(CollectionEntity::getCollectionType, CollectionTypeEnum.LIKE.getCode()) .eq(CollectionEntity::getCollectionType, type.getCode())
.eq(CollectionEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode())); .eq(CollectionEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode()))
.stream().map(CollectionEntity::getTargetId).collect(Collectors.toSet());
} }
// 根据用户id获取收藏列表
public List<CollectionEntity> getBookListByUser(String userId) {
return collectionMapper.selectList(new LambdaQueryWrapper<CollectionEntity>()
.eq(CollectionEntity::getCollectionType, CollectionTypeEnum.BOOK.getCode())
.eq(CollectionEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode()));
}
// 统计单个主题的点赞量 // 统计单个主题的数量
public Long getLikeAmountByThemeId(String themeId) { public Integer getCountByTypeAndId(String targetId, CollectionTypeEnum type) {
return (long) collectionMapper.selectList((new LambdaQueryWrapper<CollectionEntity>() return collectionMapper.selectCount((new LambdaQueryWrapper<CollectionEntity>()
.eq(CollectionEntity::getTargetId, themeId) .eq(CollectionEntity::getTargetId, targetId)
.eq(CollectionEntity::getCollectionType, CollectionTypeEnum.LIKE.getCode()) .eq(CollectionEntity::getCollectionType, type.getCode())
.eq(CollectionEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode()))) .eq(CollectionEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode())));
.size();
} }
// 统计多个主题的点赞量 // 统计多个主题的点赞量
public Long getLikeAmountByThemeIds(List<String> themeIds) { public Integer getCountByTypeAndIds(List<String> themeIds, CollectionTypeEnum type) {
return (long) collectionMapper.selectList((new LambdaQueryWrapper<CollectionEntity>() return collectionMapper.selectCount((new LambdaQueryWrapper<CollectionEntity>()
.in(CollectionEntity::getTargetId, themeIds) .in(CollectionEntity::getTargetId, themeIds)
.eq(CollectionEntity::getCollectionType, CollectionTypeEnum.LIKE.getCode())) .eq(CollectionEntity::getCollectionType, type.getCode()))
.eq(CollectionEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode())) .eq(CollectionEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode()));
.size();
}
//统计单个主题的收藏量
public Long getBookAmountByThemeId(String themeId) {
return (long) collectionMapper.selectList((new LambdaQueryWrapper<CollectionEntity>()
.eq(CollectionEntity::getTargetId, themeId)
.eq(CollectionEntity::getCollectionType, CollectionTypeEnum.BOOK.getCode()))
.eq(CollectionEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode()))
.size();
}
//统计多个主题的收藏量
public Long getBookAmountByThemeIds(List<String> themeIds) {
return (long) collectionMapper.selectList((new LambdaQueryWrapper<CollectionEntity>()
.in(CollectionEntity::getTargetId, themeIds)
.eq(CollectionEntity::getCollectionType, CollectionTypeEnum.BOOK.getCode()))
.eq(CollectionEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode()))
.size();
} }
//逻辑删除,修改delete_tag //逻辑删除,修改delete_tag
public void delete(String themeId, String userId, CollectionTypeEnum type) { public void delete(String themeId, String userId, CollectionTypeEnum type) {
CollectionEntity queryCollection = getTargetCollection(themeId, userId, type); CollectionEntity queryCollection = getTargetCollection(themeId, userId, type);
...@@ -116,6 +91,8 @@ public class CollectionService { ...@@ -116,6 +91,8 @@ public class CollectionService {
queryCollection.setDeleteTag(DeleteTagEnum.DELETED.getCode()); queryCollection.setDeleteTag(DeleteTagEnum.DELETED.getCode());
queryCollection.setUncollectionTime(LocalDateTime.now()); queryCollection.setUncollectionTime(LocalDateTime.now());
collectionMapper.updateById(queryCollection); collectionMapper.updateById(queryCollection);
} else {
throw new BizException("Collection对象未找到,themeId:" + themeId + ",userId:" + userId + ",type:" + type.getCode());
} }
} }
} }
...@@ -34,23 +34,30 @@ public class CommentService { ...@@ -34,23 +34,30 @@ public class CommentService {
} }
//统计主题集合的评论量 //统计主题集合的评论量
public Long getCommentAmountByThemeIds(List<String> themeIds) { public Integer getCommentCountByThemeIds(List<String> themeIds) {
return (long) commentMapper.selectList((new LambdaQueryWrapper<CommentEntity>() return commentMapper.selectList((new LambdaQueryWrapper<CommentEntity>()
.in(CommentEntity::getThemeId, themeIds))) .in(CommentEntity::getThemeId, themeIds)))
.size(); .size();
} }
public Set<String> getCommentUserAmount(List<String> themeIds) { public Set<String> getCommentUserCount(List<String> themeIds) {
return commentMapper.selectList((new LambdaQueryWrapper<CommentEntity>() return commentMapper.selectList((new LambdaQueryWrapper<CommentEntity>()
.in(CommentEntity::getThemeId, themeIds))) .in(CommentEntity::getThemeId, themeIds)))
.stream().map(CommentEntity::getAuthorId).collect(Collectors.toSet()); .stream().map(CommentEntity::getAuthorId).collect(Collectors.toSet());
} }
public List<CommentEntity> selectByTargetId(String id) { public List<CommentEntity> selectByThemeIdAndParentId(String themeId, String parentId) {
return commentMapper.selectList(new LambdaQueryWrapper<CommentEntity>() LambdaQueryWrapper<CommentEntity> queryWrapper = new LambdaQueryWrapper<CommentEntity>()
.eq(CommentEntity::getThemeId, themeId)
.eq(CommentEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode()) .eq(CommentEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode())
.eq(CommentEntity::getIsBlock, TopicStatusEnum.FALSE.getCode()) .eq(CommentEntity::getIsBlock, TopicStatusEnum.FALSE.getCode())
.orderByDesc(CommentEntity::getCreateTime)); .orderByDesc(CommentEntity::getCreateTime);
if (parentId == null) {
queryWrapper.isNull(CommentEntity::getParentId);
} else {
queryWrapper.eq(CommentEntity::getParentId, parentId);
}
return commentMapper.selectList(queryWrapper);
} }
......
package com.tanpu.community.service; package com.tanpu.community.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tanpu.common.uuid.UuidGenHelper; import com.tanpu.community.api.enums.DeleteTagEnum;
import com.tanpu.community.dao.entity.community.HomePageEntity; import com.tanpu.community.dao.entity.community.HomePageEntity;
import com.tanpu.community.dao.mapper.community.HomePageMapper; import com.tanpu.community.dao.mapper.community.HomePageMapper;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
...@@ -20,17 +19,20 @@ public class HomePageService { ...@@ -20,17 +19,20 @@ public class HomePageService {
private HomePageMapper homePageMapper; private HomePageMapper homePageMapper;
public HomePageEntity selectByUserId(String userId){
public HomePageEntity selectByUserId(String userId) {
return homePageMapper.selectOne(new LambdaQueryWrapper<HomePageEntity>() return homePageMapper.selectOne(new LambdaQueryWrapper<HomePageEntity>()
.eq(HomePageEntity::getUserId,userId)); .eq(HomePageEntity::getUserId, userId)
.eq(HomePageEntity::getDeleteTag,DeleteTagEnum.NOT_DELETED.getCode()));
} }
public List<HomePageEntity> selectListByUserIds(List<String> userIds){ public List<HomePageEntity> selectListByUserIds(List<String> userIds) {
if (CollectionUtils.isEmpty(userIds)){ if (CollectionUtils.isEmpty(userIds)) {
return Collections.emptyList(); return Collections.emptyList();
} }
return homePageMapper.selectList(new LambdaQueryWrapper<HomePageEntity>() return homePageMapper.selectList(new LambdaQueryWrapper<HomePageEntity>()
.in(HomePageEntity::getUserId,userIds)); .eq(HomePageEntity::getDeleteTag,DeleteTagEnum.NOT_DELETED.getCode())
.in(HomePageEntity::getUserId, userIds));
} }
public void update(HomePageEntity entity) { public void update(HomePageEntity entity) {
......
...@@ -2,6 +2,7 @@ package com.tanpu.community.service; ...@@ -2,6 +2,7 @@ package com.tanpu.community.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tanpu.common.uuid.UuidGenHelper; import com.tanpu.common.uuid.UuidGenHelper;
import com.tanpu.community.api.enums.DeleteTagEnum;
import com.tanpu.community.dao.entity.community.ThemeEntity; import com.tanpu.community.dao.entity.community.ThemeEntity;
import com.tanpu.community.dao.mapper.community.ThemeMapper; import com.tanpu.community.dao.mapper.community.ThemeMapper;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -51,9 +52,15 @@ public class ThemeService { ...@@ -51,9 +52,15 @@ public class ThemeService {
} }
//查询对应话题的发表用户集合 //查询对应话题的发表用户集合
public Set<String> getPostUserAmount(List<String> themeIds) { public Set<String> getPostUserCount(List<String> themeIds) {
return themeMapper.selectBatchIds(themeIds).stream() return themeMapper.selectBatchIds(themeIds).stream()
.map(ThemeEntity::getAuthorId) .map(ThemeEntity::getAuthorId)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
} }
public Integer getForwardCountById(String themeId) {
return themeMapper.selectCount(new LambdaQueryWrapper<ThemeEntity>()
.eq(ThemeEntity::getThemeId,themeId)
.eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED));
}
} }
...@@ -30,6 +30,12 @@ public class TopicService { ...@@ -30,6 +30,12 @@ public class TopicService {
.eq(TopicEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode())); .eq(TopicEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode()));
} }
public List<TopicEntity> queryByKeyword(String keyword) {
return topicMapper.selectList(new LambdaQueryWrapper<TopicEntity>()
.like(TopicEntity::getTopicTitle,keyword)
.eq(TopicEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode()));
}
public void addTopic(String topicTitle, String userId) { public void addTopic(String topicTitle, String userId) {
TopicEntity entity = TopicEntity.builder() TopicEntity entity = TopicEntity.builder()
...@@ -75,12 +81,12 @@ public class TopicService { ...@@ -75,12 +81,12 @@ public class TopicService {
return topicMapper.selectById(topicId); return topicMapper.selectById(topicId);
} }
public void modifyViewAmount(String topicId, long amount) { public void modifyViewCount(String topicId, long Count) {
TopicEntity topicEntity = topicMapper.selectById(topicId); TopicEntity topicEntity = topicMapper.selectById(topicId);
Long oldAmount = topicEntity.getViewAmountModify(); Long oldCount = topicEntity.getviewCntAdjust();
topicEntity.setViewAmountModify(topicEntity.getViewAmountModify() + amount); topicEntity.setViewAmountModify(topicEntity.getviewCntAdjust() + Count);
topicMapper.update(topicEntity, new LambdaUpdateWrapper<TopicEntity>() topicMapper.update(topicEntity, new LambdaUpdateWrapper<TopicEntity>()
.eq(TopicEntity::getViewAmountModify, oldAmount)); .eq(TopicEntity::getviewCntAdjust, oldCount));
return; return;
} }
......
package com.tanpu.community.util; package com.tanpu.community.util;
import com.tanpu.community.api.beans.TopicBriefInfoDTO; import com.tanpu.community.api.beans.qo.TopicTitileQo;
import com.tanpu.community.api.beans.TopicDTO; import com.tanpu.community.api.beans.TopicDTO;
import com.tanpu.community.api.beans.qo.CommentLv2Qo;
import com.tanpu.community.api.beans.qo.CommentQo; import com.tanpu.community.api.beans.qo.CommentQo;
import com.tanpu.community.api.beans.qo.FollowQo; import com.tanpu.community.api.beans.qo.FollowQo;
import com.tanpu.community.api.beans.qo.ThemeQo; import com.tanpu.community.api.beans.qo.ThemeQo;
...@@ -46,10 +47,10 @@ public class ConvertUtil { ...@@ -46,10 +47,10 @@ public class ConvertUtil {
return topicDTO; return topicDTO;
} }
public static TopicBriefInfoDTO topicToBriefInfoDTO(TopicEntity topicEntity) { public static TopicTitileQo topicToBriefInfoDTO(TopicEntity topicEntity) {
TopicBriefInfoDTO topicBriefInfoDTO = new TopicBriefInfoDTO(); TopicTitileQo topicTitileQo = new TopicTitileQo();
BeanUtils.copyProperties(topicEntity, topicBriefInfoDTO); BeanUtils.copyProperties(topicEntity, topicTitileQo);
return topicBriefInfoDTO; return topicTitileQo;
} }
public static CommentQo commentEntity2Qo(CommentEntity entity) { public static CommentQo commentEntity2Qo(CommentEntity entity) {
CommentQo qo = new CommentQo(); CommentQo qo = new CommentQo();
...@@ -61,16 +62,27 @@ public class ConvertUtil { ...@@ -61,16 +62,27 @@ public class ConvertUtil {
return entities.stream().map(ConvertUtil::commentEntity2Qo).collect(Collectors.toList()); return entities.stream().map(ConvertUtil::commentEntity2Qo).collect(Collectors.toList());
} }
public static CommentLv2Qo commentLv2Entity2Qo(CommentEntity entity) {
CommentLv2Qo qo = new CommentLv2Qo();
BeanUtils.copyProperties(entity, qo);
return qo;
}
public static List<CommentLv2Qo> commentLv2Entity2Qos(List<CommentEntity> entities){
return entities.stream().map(ConvertUtil::commentLv2Entity2Qo).collect(Collectors.toList());
}
public static List<TopicDTO> topicEntitiesToDTOs(List<TopicEntity> topicEntities) { public static List<TopicDTO> topicEntitiesToDTOs(List<TopicEntity> topicEntities) {
return topicEntities.stream().map(ConvertUtil::topicEntityToDTO).collect(Collectors.toList()); return topicEntities.stream().map(ConvertUtil::topicEntityToDTO).collect(Collectors.toList());
} }
public static List<TopicBriefInfoDTO> topicEntitiesToBriefDTOs(List<TopicEntity> topicEntities) { public static List<TopicTitileQo> topicEntitiesToBriefDTOs(List<TopicEntity> topicEntities) {
return topicEntities.stream().map(ConvertUtil::topicToBriefInfoDTO).collect(Collectors.toList()); return topicEntities.stream().map(ConvertUtil::topicToBriefInfoDTO).collect(Collectors.toList());
} }
public static DeleteTagEnum deleteTagShift(DeleteTagEnum deleteTagEnum) { public static DeleteTagEnum deleteTagShift(DeleteTagEnum deleteTagEnum) {
if (deleteTagEnum.getCode().equals(DeleteTagEnum.NOT_DELETED.getCode())) { if (deleteTagEnum.getCode().equals(DeleteTagEnum.NOT_DELETED.getCode())) {
return DeleteTagEnum.DELETED; return DeleteTagEnum.DELETED;
......
package com.tanpu.community.util;
import com.tanpu.community.api.beans.req.page.Page;
import com.tanpu.community.api.beans.req.page.Pageable;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
/**
* @author: zhoupeng
* @email: zhoupeng@wealthgrow.cn
*/
public class PageUtils {
public static <T> Page<T> page(Pageable pageable, List<T> list) {
if (CollectionUtils.isEmpty(list)) {
return new Page<>(pageable, 0L, new ArrayList<>());
} else {
// 记录总数
Integer count = list.size();
// 页数
int pageCount;
if (count % pageable.getPageSize() == 0) {
pageCount = count / pageable.getPageSize();
} else {
pageCount = count / pageable.getPageSize() + 1;
}
// 开始索引
int fromIndex;
// 结束索引
int toIndex;
// 防止索引越界
if (Integer.getInteger("0").equals(pageable.getPageNumber())) {
pageable.setPageNumber(1);
}
if (!pageable.getPageNumber().equals(pageCount)) {
fromIndex = (pageable.getPageNumber() - 1) * pageable.getPageSize();
toIndex = fromIndex + pageable.getPageSize();
} else {
fromIndex = (pageable.getPageNumber() - 1) * pageable.getPageSize();
toIndex = count;
}
if (pageable.getPageSize() * (pageable.getPageNumber() - 1) >= list.size()) {
return new Page<>(pageable, 0L, new ArrayList<>());
} else {
Page<T> tPage = new Page<>(pageable, (long) list.size(), new ArrayList<>(list).subList(fromIndex, toIndex));
int totalPage = list.size() / pageable.getPageSize();
if (list.size() % pageable.getPageSize() == 0) {
tPage.setTotalPages(totalPage);
} else {
tPage.setTotalPages(totalPage + 1);
}
return tPage;
}
}
}
}
...@@ -9,8 +9,6 @@ ...@@ -9,8 +9,6 @@
<result column="title" property="title" /> <result column="title" property="title" />
<result column="theme_type" property="themeType" /> <result column="theme_type" property="themeType" />
<result column="content" property="content" /> <result column="content" property="content" />
<result column="attach_type" property="attachType" />
<result column="attachment" property="attachment" />
<result column="author_id" property="authorId" /> <result column="author_id" property="authorId" />
<result column="former_theme_id" property="formerThemeId" /> <result column="former_theme_id" property="formerThemeId" />
<result column="topic_id" property="topicId" /> <result column="topic_id" property="topicId" />
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
<result column="topic_title" property="topicTitle" /> <result column="topic_title" property="topicTitle" />
<result column="is_top" property="isTop" /> <result column="is_top" property="isTop" />
<result column="is_conceal" property="isConceal" /> <result column="is_conceal" property="isConceal" />
<result column="view_amount_modify" property="viewAmountModify" /> <result column="view_cnt_adjust" property="viewCntAdjust" />
<result column="create_time" property="createTime" /> <result column="create_time" property="createTime" />
<result column="update_time" property="updateTime" /> <result column="update_time" property="updateTime" />
<result column="delete_tag" property="deleteTag" /> <result column="delete_tag" property="deleteTag" />
......
...@@ -80,7 +80,7 @@ CREATE TABLE `comment` ( ...@@ -80,7 +80,7 @@ CREATE TABLE `comment` (
CREATE TABLE `collection` ( CREATE TABLE `collection` (
`id` int(32) auto_increment PRIMARY KEY COMMENT 'id', `id` int(32) auto_increment PRIMARY KEY COMMENT 'id',
`collection_type` int(4) NOT NULL COMMENT '类型,1:点赞,2:收藏', `collection_type` int(4) NOT NULL COMMENT '类型,类型 1:点赞主题,2:收藏主题 3:点赞评论',
`user_id` varchar(64) NOT NULL COMMENT '作者id', `user_id` varchar(64) NOT NULL COMMENT '作者id',
`target_id` varchar(64) NOT NULL COMMENT '评论的目标id', `target_id` varchar(64) NOT NULL COMMENT '评论的目标id',
`collection_time` datetime COMMENT '收藏时间', `collection_time` datetime COMMENT '收藏时间',
...@@ -99,7 +99,7 @@ CREATE TABLE `topic` ( ...@@ -99,7 +99,7 @@ CREATE TABLE `topic` (
`topic_title` varchar(64) NOT NULL COMMENT '话题名称', `topic_title` varchar(64) NOT NULL COMMENT '话题名称',
`is_top` int(4) NOT NULL COMMENT '是否置顶', `is_top` int(4) NOT NULL COMMENT '是否置顶',
`is_conceal` int(4) NOT NULL COMMENT '是否隐藏', `is_conceal` int(4) NOT NULL COMMENT '是否隐藏',
`view_amount_modify` bigint NOT NULL DEFAULT 0 COMMENT '浏览量调整', `view_cnt_adjust` bigint NOT NULL DEFAULT 0 COMMENT '浏览量调整',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`delete_tag` int(3) NOT NULL DEFAULT '0', `delete_tag` int(3) NOT NULL DEFAULT '0',
......
...@@ -169,6 +169,12 @@ ...@@ -169,6 +169,12 @@
<version>1.7.0</version> <version>1.7.0</version>
</dependency> </dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.13</version>
</dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>
......
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