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

正文相关

parent 35360880
package com.tanpu.community.api.constants;
public enum CollectionTypeEnum {
LIKE(1,"点赞"),BOOK(2,"收藏");
private Integer code;
private String type;
CollectionTypeEnum(Integer code, String type) {
this.code = code;
this.type = type;
}
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
package com.tanpu.community.api.constants;
public enum CommentTypeEnum {
TEXT(1,"纯文字");
private Integer code;
private String type;
CommentTypeEnum(Integer code, String type) {
this.code = code;
this.type = type;
}
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
...@@ -2,13 +2,14 @@ package com.tanpu.community.controller; ...@@ -2,13 +2,14 @@ package com.tanpu.community.controller;
import com.tanpu.community.api.beans.ThemeDTO; import com.tanpu.community.api.beans.ThemeDTO;
import com.tanpu.community.dao.entity.community.FansRelEntity;
import com.tanpu.community.dao.entity.community.ThemeEntity; import com.tanpu.community.dao.entity.community.ThemeEntity;
import com.tanpu.community.manager.ThemeManager; import com.tanpu.community.manager.ThemeManager;
import com.tanpu.community.service.FansRelService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List; import java.util.List;
...@@ -20,18 +21,84 @@ public class ThemeController { ...@@ -20,18 +21,84 @@ public class ThemeController {
@Autowired @Autowired
private ThemeManager themeManager; private ThemeManager themeManager;
@Autowired
private FansRelService fansRelService;
@ApiOperation("新增主题")
@RequestMapping(value = "/add") @RequestMapping(value = "/add")
@ResponseBody
public void insertTheme(@RequestBody ThemeDTO themeDTO){ public void insertTheme(@RequestBody ThemeDTO themeDTO){
} }
public List<ThemeEntity> selectList(){ @ApiOperation("系统推荐主题列表")
@RequestMapping(value = "/add")
@ResponseBody
public List<ThemeEntity> selectHotList(){
return null;
}
@ApiOperation("用户关注主题列表")
@RequestMapping(value = "/add")
@ResponseBody
public List<ThemeEntity> selectInterestList(){
String userId="liujm012";
return null; return null;
} }
@ApiOperation("评论")
@RequestMapping(value = "/comment")
@ResponseBody
public String commetOnTheme(String themeId,String commet){ public String commetOnTheme(String themeId,String commet){
String user="liujm"; String user="liujm";
themeManager.comment(themeId,user,commet);
return "success"; return "success";
} }
@ApiOperation("转发主题")
@RequestMapping(value = "/forward")
@ResponseBody
public String forwardTheme(String themeId){
return "success";
}
@ApiOperation("点赞主题")
@RequestMapping(value = "/like")
@ResponseBody
public String likeOnTheme(String themeId){
String user="liujm";
themeManager.like(themeId,user);
return "success";
}
@ApiOperation("分享主题")
@RequestMapping(value = "/share")
@ResponseBody
public String shareTheme(String themeId){
return "success";
}
@ApiOperation("收藏主题")
@RequestMapping(value = "/book")
@ResponseBody
public String bookTheme(String themeId){
String user="liujm";
themeManager.book(themeId,user);
return "success";
}
@ApiOperation("举报主题")
@RequestMapping(value = "/complaint")
@ResponseBody
public String complaintTheme(String themeId){
return "success";
}
@ApiOperation("屏蔽")
@RequestMapping(value = "/conceal")
@ResponseBody
public String concealTheme(String themeId){
return "success";
}
} }
...@@ -2,6 +2,7 @@ package com.tanpu.community.dao.mapper.community; ...@@ -2,6 +2,7 @@ package com.tanpu.community.dao.mapper.community;
import com.tanpu.community.dao.entity.community.ThemeEntity; import com.tanpu.community.dao.entity.community.ThemeEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
/** /**
* <p> * <p>
......
...@@ -2,6 +2,7 @@ package com.tanpu.community.dao.mapper.community; ...@@ -2,6 +2,7 @@ package com.tanpu.community.dao.mapper.community;
import com.tanpu.community.dao.entity.community.TopicEntity; import com.tanpu.community.dao.entity.community.TopicEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
/** /**
* <p> * <p>
...@@ -11,6 +12,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; ...@@ -11,6 +12,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
* @author xudong * @author xudong
* @since 2021-06-10 * @since 2021-06-10
*/ */
@Mapper
public interface TopicMapper extends BaseMapper<TopicEntity> { public interface TopicMapper extends BaseMapper<TopicEntity> {
} }
package com.tanpu.community.manager; package com.tanpu.community.manager;
import com.tanpu.community.api.constants.CollectionTypeEnum;
import com.tanpu.community.api.constants.CommentTypeEnum;
import com.tanpu.community.dao.entity.community.CollectionEntity;
import com.tanpu.community.dao.entity.community.CommentEntity;
import com.tanpu.community.dao.entity.community.FansRelEntity;
import com.tanpu.community.dao.entity.community.ThemeEntity;
import com.tanpu.community.service.CollectionService;
import com.tanpu.community.service.CommentService;
import com.tanpu.community.service.FansRelService;
import com.tanpu.community.service.ThemeService; import com.tanpu.community.service.ThemeService;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.tomcat.jni.Local;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;
@Service @Service
public class ThemeManager { public class ThemeManager {
@Autowired @Resource
private ThemeService themeService; private ThemeService themeService;
@Autowired
private CollectionService collectionService;
@Autowired
private CommentService commentService;
@Autowired
private FansRelService fansRelService;
public List<ThemeEntity> selectHotThemes(){
//TOTO:根据算法计算推荐主题
return null;
}
public List<ThemeEntity> selectInterestThemes(String userId){
List<String> fansRelEntities = fansRelService.queryFansByFollowerId(userId).stream().map(FansRelEntity::getIdolId).collect(Collectors.toList());
return null;
}
//点赞
public void like(String themeId, String userId) {
CollectionEntity collectionEntity = new CollectionEntity();
collectionEntity.setCollectionType(CollectionTypeEnum.LIKE.getCode());
collectionEntity.setAuthorId(userId);
collectionEntity.setTargetId(themeId);
collectionEntity.setCreateBy(userId);
collectionEntity.setCreateTime(LocalDateTime.now());
collectionService.insertCollection(collectionEntity);
}
//评论
public void comment(String themeId, String userId,String comment) {
CommentEntity commentEntity = new CommentEntity();
commentEntity.setTargetId(themeId);
commentEntity.setAuthorId(userId);
commentEntity.setCommentType(CommentTypeEnum.TEXT.getCode());
commentEntity.setContent(comment);
commentService.insertComment(commentEntity);
}
//转发
public void forward(String themeId, String user) {
}
//分享
public void share(String themeId, String user) {
}
//收藏
public void book(String themeId, String userId) {
CollectionEntity collectionEntity = new CollectionEntity();
collectionEntity.setCollectionType(CollectionTypeEnum.BOOK.getCode());
collectionEntity.setAuthorId(userId);
collectionEntity.setTargetId(themeId);
collectionEntity.setCreateBy(userId);
collectionEntity.setCreateTime(LocalDateTime.now());
collectionService.insertCollection(collectionEntity);
}
//投诉
public void complaint(String themeId, String user) {
}
//屏蔽
public void conceal(String themeId, String user) {
}
} }
package com.tanpu.community.service;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@Service
public class BlackListService {
}
package com.tanpu.community.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanpu.community.dao.entity.community.CollectionEntity;
import com.tanpu.community.dao.mapper.community.CollectionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
@Service
public class CollectionService {
@Resource
private CollectionMapper collectionMapper;
public void insertCollection(CollectionEntity collectionEntity){
collectionMapper.insert(collectionEntity);
}
//根据用户id获取点赞列表
public List<CollectionEntity> getLikeListByUser(String userId){
return collectionMapper.selectList(new LambdaQueryWrapper<CollectionEntity>().eq(CollectionEntity::getCollectionType,1));
}
//根据用户id获取收藏列表
public List<CollectionEntity> getBookListByUser(String userId){
return collectionMapper.selectList(new LambdaQueryWrapper<CollectionEntity>().eq(CollectionEntity::getCollectionType,2));
}
}
package com.tanpu.community.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tanpu.community.dao.entity.community.CommentEntity;
import com.tanpu.community.dao.mapper.community.CommentMapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
@Service
public class CommentService {
@Resource
private CommentMapper commentMapper;
public void insertComment(CommentEntity commentEntity){
commentMapper.insert(commentEntity);
}
public List<CommentEntity> selectByUserId(String userId){
return commentMapper.selectList(new LambdaQueryWrapper<CommentEntity>().eq(CommentEntity::getAuthorId,userId));
}
}
package com.tanpu.community.service; package com.tanpu.community.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
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;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
@Service @Service
public class ThemeService { public class ThemeService {
@Autowired @Resource
private ThemeMapper themeMapper; private ThemeMapper themeMapper;
public void insertTheme(ThemeEntity themeEntity){
themeMapper.insert(themeEntity);
}
//根据id返回主题详情
public ThemeEntity selectTheme(String themeId){
return themeMapper.selectById(themeId);
}
//根据话题查询主题
public List<ThemeEntity> selectByTopic(String topidId){
QueryWrapper<ThemeEntity> themeEntityQueryWrapper = new QueryWrapper<>();
themeEntityQueryWrapper.eq("topic_id",topidId);
return themeMapper.selectList(themeEntityQueryWrapper);
}
} }
...@@ -50,7 +50,7 @@ CREATE TABLE `theme` ( ...@@ -50,7 +50,7 @@ CREATE TABLE `theme` (
CREATE TABLE `comment` ( CREATE TABLE `comment` (
`id` varchar(64) PRIMARY KEY COMMENT 'id', `id` varchar(64) PRIMARY KEY COMMENT 'id',
`comment_type` int(4) NOT NULL COMMENT '类型', `comment_type` int(4) NOT NULL COMMENT '类型,目前仅支持1:文字,上限500字',
`content` text COMMENT '文本内容', `content` text COMMENT '文本内容',
`author_id` varchar(64) NOT NULL COMMENT '作者id', `author_id` varchar(64) NOT NULL COMMENT '作者id',
`target_id` varchar(64) NOT NULL COMMENT '评论的目标id', `target_id` varchar(64) NOT NULL COMMENT '评论的目标id',
...@@ -67,7 +67,7 @@ CREATE TABLE `comment` ( ...@@ -67,7 +67,7 @@ CREATE TABLE `comment` (
CREATE TABLE `collection` ( CREATE TABLE `collection` (
`id` varchar(64) PRIMARY KEY COMMENT 'id', `id` varchar(64) PRIMARY KEY COMMENT 'id',
`collection_type` int(4) NOT NULL COMMENT '类型', `collection_type` int(4) NOT NULL COMMENT '类型,1:点赞,2:收藏',
`author_id` varchar(64) NOT NULL COMMENT '作者id', `author_id` varchar(64) NOT NULL COMMENT '作者id',
`target_id` varchar(64) NOT NULL COMMENT '评论的目标id', `target_id` varchar(64) NOT NULL COMMENT '评论的目标id',
`create_by` varchar(64) DEFAULT '', `create_by` varchar(64) DEFAULT '',
......
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