Commit fd84c963 authored by 张辰's avatar 张辰

Merge branch 'feature/liujiming' into 'master'

merge

See merge request !1
parents 3893149c 83a22ac5
package com.tanpu.community.api.beans;
import io.swagger.annotations.ApiModelProperty;
import java.time.LocalDateTime;
public class ThemeDTO {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "id")
private String id;
@ApiModelProperty(value = "标题")
private String title;
@ApiModelProperty(value = "类型")
private Integer themeType;
@ApiModelProperty(value = "文本内容")
private String content;
@ApiModelProperty(value = "附件类型")
private Integer attachType;
@ApiModelProperty(value = "附件内容")
private String attachment;
@ApiModelProperty(value = "作者id")
private String authorId;
@ApiModelProperty(value = "被转发的主题")
private String formerThemeId;
@ApiModelProperty(value = "所属的话题")
private String topicId;
private String createBy;
private LocalDateTime createTime;
private String updateBy;
private LocalDateTime updateTime;
private Integer deleteTag;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public Integer getThemeType() {
return themeType;
}
public void setThemeType(Integer themeType) {
this.themeType = themeType;
}
public String getContent() {
return content;
}
public void setContent(String 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() {
return authorId;
}
public void setAuthorId(String authorId) {
this.authorId = authorId;
}
public String getFormerThemeId() {
return formerThemeId;
}
public void setFormerThemeId(String formerThemeId) {
this.formerThemeId = formerThemeId;
}
public String getTopicId() {
return topicId;
}
public void setTopicId(String topicId) {
this.topicId = topicId;
}
public String getCreateBy() {
return createBy;
}
public void setCreateBy(String createBy) {
this.createBy = createBy;
}
public LocalDateTime getCreateTime() {
return createTime;
}
public void setCreateTime(LocalDateTime createTime) {
this.createTime = createTime;
}
public String getUpdateBy() {
return updateBy;
}
public void setUpdateBy(String updateBy) {
this.updateBy = updateBy;
}
public LocalDateTime getUpdateTime() {
return updateTime;
}
public void setUpdateTime(LocalDateTime updateTime) {
this.updateTime = updateTime;
}
public Integer getDeleteTag() {
return deleteTag;
}
public void setDeleteTag(Integer deleteTag) {
this.deleteTag = deleteTag;
}
@Override
public String toString() {
return "ThemeEntity{" +
"id=" + id +
", title=" + title +
", themeType=" + themeType +
", content=" + content +
", attachType=" + attachType +
", attachment=" + attachment +
", authorId=" + authorId +
", formerThemeId=" + formerThemeId +
", topicId=" + topicId +
", createBy=" + createBy +
", createTime=" + createTime +
", updateBy=" + updateBy +
", updateTime=" + updateTime +
", deleteTag=" + deleteTag +
"}";
}
}
package com.tanpu.community.api.beans;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.time.LocalDateTime;
@Data
@ApiModel(value="TopicDTO对象", description="话题")
public class TopicDTO implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "id")
private String id;
@ApiModelProperty(value = "话题名称")
private String topicTitle;
@ApiModelProperty(value = "是否置顶")
private Integer isTop;
@ApiModelProperty(value = "是否隐藏")
private Integer isConceal;
private String createBy;
private LocalDateTime createTime;
private String updateBy;
private LocalDateTime updateTime;
private Integer deleteTag;
@ApiModelProperty(value = "帖子量")
private Long themeAmount;
@ApiModelProperty(value = "浏览量")
private Long viewAmount;
@ApiModelProperty(value = "点赞量")
private Long likeAmount;
@ApiModelProperty(value = "总用户数")
private Long UserAmount;
@ApiModelProperty
@Override
public String toString() {
return "TopicEntity{" +
"id=" + id +
", topicTitle=" + topicTitle +
", isTop=" + isTop +
", isConceal=" + isConceal +
", createBy=" + createBy +
", createTime=" + createTime +
", updateBy=" + updateBy +
", updateTime=" + updateTime +
", deleteTag=" + deleteTag +
"}";
}
}
package com.tanpu.community.api.constants;
public enum BlockTypeEnum {
USER(1,"屏蔽用户"),CONTENT(2,"屏蔽内容");
private Integer code;
private String 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;
}
BlockTypeEnum(Integer code, String type) {
this.code = code;
this.type = type;
}
}
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;
}
}
......@@ -43,6 +43,13 @@
<artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>
<!-- mybatis-plus自动生成所需包-->
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-engine-core</artifactId>
<version>2.3</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.springframework.cloud</groupId>-->
<!-- <artifactId>spring-cloud-starter-consul-discovery</artifactId>-->
......
package com.tanpu.community.controller;
import com.alibaba.fastjson.JSON;
import com.tanpu.community.dao.entity.community.FansRelEntity;
import com.tanpu.community.manager.HomePageManager;
import com.tanpu.community.model.req.homepage.AddIdolReq;
......@@ -38,4 +37,12 @@ public class HomePageController {
return "11";
}
@PostMapping(value = "/query/likeTheme")
@ApiOperation("我的点赞")
@ResponseBody
public String likeList(){
String userId="123";
return "success";
}
}
package com.tanpu.community.controller;
import com.tanpu.community.service.RedisService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@RequestMapping(value = "/metric")
public class MetricsController {
@Autowired
private RedisService redisService;
@ApiOperation("浏览量埋点")
@RequestMapping("/pv")
public void pageView(@RequestParam String themeId){
redisService.incr("pv"+themeId, 1L);
}
}
package com.tanpu.community.controller;
import com.tanpu.community.api.beans.ThemeDTO;
import com.tanpu.community.controller.convert.ThemeConvert;
import com.tanpu.community.dao.entity.community.ThemeEntity;
import com.tanpu.community.manager.ThemeManager;
import com.tanpu.community.service.FansRelService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@Slf4j
@RequestMapping(value = "/api/theme")
public class ThemeController {
@Autowired
private ThemeManager themeManager;
@Autowired
private FansRelService fansRelService;
@ApiOperation("新增主题")
@RequestMapping(value = "/add")
@ResponseBody
public String insertTheme(@RequestBody ThemeDTO themeDTO){
String userId="liujm";
themeDTO.setAuthorId(userId);
themeManager.insert(ThemeConvert.convertToEntity(themeDTO));
return "success";
}
@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;
}
@ApiOperation("评论")
@RequestMapping(value = "/comment")
@ResponseBody
public String commetOnTheme(String themeId,String commet){
String user="liujm";
themeManager.comment(themeId,user,commet);
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";
}
}
package com.tanpu.community.controller;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.JsonObject;
import com.tanpu.community.api.beans.TopicDTO;
import com.tanpu.community.controller.convert.TopicConverter;
import com.tanpu.community.dao.entity.community.TopicEntity;
import com.tanpu.community.manager.TopicManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Value;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.stream.Collectors;
@RestController
@Slf4j
@RequestMapping(value = "/api/topic")
public class TopicController {
@Autowired
private TopicManager topicManager;
@PostMapping(value = "/queryTopicList")
@ApiOperation("查询所有的主题详情")
@ResponseBody
public List<TopicDTO> getAllTopicList(@RequestBody String content){
JSONObject params = JSONObject.parseObject(content);
List<TopicEntity> allTopic = topicManager.getAllTopic();
List<TopicDTO> topicDTOS = TopicConverter.convertToDTOs(allTopic);
//获取浏览数据:浏览、发帖、回帖
return topicDTOS;
}
@PostMapping(value = "/queryTopicList")
@ApiOperation("查询所有的主题名称列表")
@ResponseBody
public List<String> getTopicNameList(@RequestBody String content){
JSONObject params = JSONObject.parseObject(content);
List<TopicEntity> allTopic = topicManager.getAllTopic();
List<String> topictitiles = allTopic.stream().map(TopicEntity::getTopicTitle).collect(Collectors.toList());
//获取浏览数据:浏览、发帖、回帖
return topictitiles;
}
@PostMapping(value="/insertTopic")
@ApiOperation("新增主题主题")
@ResponseBody
public String addTopic(@RequestParam String topicTitle){
//TODO:获取登录用户信息
String userId = "liujm";
topicManager.insertTopic(topicTitle,userId);
return "success";
}
@ApiOperation("单个话题数据总览")
@PostMapping("/selectOne")
@ResponseBody
public String selectOne(@RequestParam String topicId) throws MissingServletRequestParameterException {
if (StringUtils.isEmpty(topicId)){
throw new MissingServletRequestParameterException("topicId","String");
}
TopicDTO topicDTO=topicManager.getDetail(topicId);
return "success";
}
@PostMapping(value = "/setTop")
@ApiOperation("顶置/取消顶置主题")
@ResponseBody
public String setTopTopic(@RequestParam String topicId,@RequestParam boolean setTop) throws MissingServletRequestParameterException {
if (StringUtils.isEmpty(topicId)){
throw new MissingServletRequestParameterException("topicId","String");
}
topicManager.setTopTopic(topicId,setTop);
return "success";
}
@PostMapping(value = "/setConceal")
@ApiOperation("隐藏/显示主题")
@ResponseBody
public String setConceal(@RequestParam String topicId,@RequestParam boolean setConceal) throws MissingServletRequestParameterException {
if (StringUtils.isEmpty(topicId)){
throw new MissingServletRequestParameterException("topicId","String");
}
topicManager.setTopicConceal(topicId,setConceal);
return "success";
}
@PostMapping(value = "/modifyViewNum")
@ApiOperation("主题浏览数调整")
@ResponseBody
public String modifyViewNum(@RequestParam String topicId,@RequestParam Long modifyMount) throws MissingServletRequestParameterException {
if (StringUtils.isEmpty(topicId)){
throw new MissingServletRequestParameterException("topicId","String");
}
//修改浏览量
return "success";
}
}
package com.tanpu.community.controller.convert;
import com.tanpu.community.api.beans.ThemeDTO;
import com.tanpu.community.dao.entity.community.ThemeEntity;
import java.util.List;
import java.util.stream.Collectors;
public class ThemeConvert {
public static ThemeDTO convertToDTO(ThemeEntity themeEntity){
ThemeDTO themeDTO = new ThemeDTO();
themeDTO.setId(themeEntity.getId());
themeDTO.setContent(themeEntity.getContent());
themeDTO.setThemeType(themeEntity.getThemeType());
themeDTO.setAttachment(themeEntity.getAttachment());
themeDTO.setAttachType(themeEntity.getAttachType());
themeDTO.setFormerThemeId(themeEntity.getFormerThemeId());
themeDTO.setAuthorId(themeEntity.getAuthorId());
themeDTO.setCreateBy(themeEntity.getCreateBy());
themeDTO.setUpdateBy(themeEntity.getUpdateBy());
themeDTO.setCreateTime(themeEntity.getCreateTime());
themeDTO.setUpdateBy(themeEntity.getUpdateBy());
return themeDTO;
}
public static ThemeEntity convertToEntity(ThemeDTO themeDTO){
ThemeEntity themeEntity = new ThemeEntity();
themeEntity.setContent(themeDTO.getContent());
themeEntity.setThemeType(themeDTO.getThemeType());
themeEntity.setAttachment(themeDTO.getAttachment());
themeEntity.setAttachType(themeDTO.getAttachType());
themeEntity.setFormerThemeId(themeDTO.getFormerThemeId());
themeEntity.setAuthorId(themeDTO.getAuthorId());
themeEntity.setCreateBy(themeDTO.getCreateBy());
themeEntity.setUpdateBy(themeDTO.getUpdateBy());
themeEntity.setCreateTime(themeDTO.getCreateTime());
themeEntity.setUpdateBy(themeDTO.getUpdateBy());
return themeEntity;
}
public static List<ThemeDTO> convertToEntitys(List<ThemeEntity> topicEntities){
return topicEntities.stream().map(ThemeConvert::convertToDTO).collect(Collectors.toList());
}
public static List<ThemeDTO> convertToDTOs(List<ThemeEntity> topicEntities){
return topicEntities.stream().map(ThemeConvert::convertToDTO).collect(Collectors.toList());
}
}
package com.tanpu.community.controller.convert;
import com.tanpu.community.api.beans.TopicDTO;
import com.tanpu.community.dao.entity.community.TopicEntity;
import java.util.List;
import java.util.stream.Collectors;
public class TopicConverter {
public static TopicDTO convertToDTO(TopicEntity topicEntity){
TopicDTO topicDTO = new TopicDTO();
topicDTO.setTopicTitle(topicEntity.getTopicTitle());
topicDTO.setId(topicEntity.getId());
topicDTO.setIsTop(topicEntity.getIsTop());
topicDTO.setIsConceal(topicEntity.getIsConceal());
topicDTO.setCreateBy(topicEntity.getCreateBy());
topicDTO.setCreateTime(topicEntity.getCreateTime());
topicDTO.setUpdateTime(topicEntity.getUpdateTime());
topicDTO.setUpdateBy(topicEntity.getUpdateBy());
topicDTO.setDeleteTag(topicEntity.getDeleteTag());
return topicDTO;
}
public static List<TopicDTO> convertToDTOs(List<TopicEntity> topicEntities){
return topicEntities.stream().map(TopicConverter::convertToDTO).collect(Collectors.toList());
}
}
......@@ -24,7 +24,7 @@ public class TopicEntity implements Serializable {
private String id;
@ApiModelProperty(value = "话题名称")
private Integer topicTitle;
private String topicTitle;
@ApiModelProperty(value = "是否置顶")
private Integer isTop;
......@@ -51,11 +51,11 @@ public class TopicEntity implements Serializable {
this.id = id;
}
public Integer getTopicTitle() {
public String getTopicTitle() {
return topicTitle;
}
public void setTopicTitle(Integer topicTitle) {
public void setTopicTitle(String topicTitle) {
this.topicTitle = topicTitle;
}
......
package com.tanpu.community.dao.mapper.community;
import com.tanpu.community.dao.entity.community.BlackListEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* <p>
* 黑名单 Mapper 接口
* </p>
*
* @author xudong
* @since 2021-06-16
*/
public interface BlackListMapper extends BaseMapper<BlackListEntity> {
}
package com.tanpu.community.manager;
import com.tanpu.community.api.constants.BlockTypeEnum;
import com.tanpu.community.api.constants.CollectionTypeEnum;
import com.tanpu.community.api.constants.CommentTypeEnum;
import com.tanpu.community.dao.entity.community.*;
import com.tanpu.community.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class ThemeManager {
@Resource
private ThemeService themeService;
@Autowired
private CollectionService collectionService;
@Autowired
private CommentService commentService;
@Autowired
private FansRelService fansRelService;
@Autowired
private BlackListService blackListService;
//返回推荐主题文章
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 blockUser(String themeId, String userId) {
BlackListEntity blackListEntity = new BlackListEntity();
blackListEntity.setBlockedId(themeService.selectTheme(themeId).getAuthorId());
blackListEntity.setBlocker(userId);
blackListEntity.setBlockedType(BlockTypeEnum.USER.getCode());
blackListService.insertBlackList(blackListEntity);
}
//屏蔽(内容)
public void blockContent(String themeId, String userId) {
BlackListEntity blackListEntity = new BlackListEntity();
blackListEntity.setBlockedId(themeId);
blackListEntity.setBlocker(userId);
blackListEntity.setBlockedType(BlockTypeEnum.CONTENT.getCode());
blackListService.insertBlackList(blackListEntity);
}
public void insert(ThemeEntity themeEntity) {
themeService.insertTheme(themeEntity);
}
}
package com.tanpu.community.manager;
import com.tanpu.common.exception.BizException;
import com.tanpu.community.api.beans.TopicDTO;
import com.tanpu.community.controller.convert.TopicConverter;
import com.tanpu.community.dao.entity.community.TopicEntity;
import com.tanpu.community.service.TopicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.List;
@Service
public class TopicManager {
@Autowired
private TopicService topicService;
public void insertTopic(String topicTitle,String userId){
TopicEntity topicEntity = new TopicEntity();
topicEntity.setCreateBy(userId);
topicEntity.setUpdateBy(userId);
topicEntity.setTopicTitle(topicTitle);
topicEntity.setCreateTime(LocalDateTime.now());
topicEntity.setUpdateTime(LocalDateTime.now());
topicEntity.setIsTop(0);
topicEntity.setIsConceal(0);
topicService.addTopic(topicEntity);
}
public List<TopicEntity> getAllTopic() {
return topicService.queryTopicList();
}
public void setTopTopic(String topicId,boolean setTop) {
TopicEntity topicEntity= topicService.queryById(topicId);
if (topicEntity==null){
throw new BizException("话题id不正确:"+topicId);
}
if (setTop){
topicService.updateTopicToTop(topicId);
}else {
topicService.updateTopicNotTop(topicId);
}
}
public void setTopicConceal(String topicId, boolean setConceal) {
TopicEntity topicEntity= topicService.queryById(topicId);
if (topicEntity==null){
throw new BizException("话题id不正确:"+topicId);
}
if (setConceal){
topicService.updateTopicToConceal(topicId);
}else {
topicService.updateTopicNotConceal(topicId);
}
}
public TopicDTO getDetail(String topicId) {
TopicEntity topicEntity = topicService.queryById(topicId);
TopicDTO topicDTO = TopicConverter.convertToDTO(topicEntity);
//TODO:添加实时数据
return topicDTO;
}
}
package com.tanpu.community.manager.exception;
public class BizException extends Exception{
public BizException(){
super();
}
public BizException(String message){
super(message);
}
public BizException(String message,Throwable cause){
super(message, cause);
}
public BizException(Throwable cause){
super(cause);
}
}
package com.tanpu.community.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tanpu.community.dao.entity.community.BlackListEntity;
import com.tanpu.community.dao.mapper.community.BlackListMapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@Service
public class BlackListService {
@Resource
private BlackListMapper blackListMapper;
public void insertBlackList(BlackListEntity blackListEntity){
blackListMapper.insert(blackListEntity);
}
public void deleteBlackList(String blocker,String blockId,String blockType){
blackListMapper.delete(new LambdaQueryWrapper<BlackListEntity>().eq(BlackListEntity::getBlocker,blocker).
eq(BlackListEntity::getBlockedId,blockId).eq(BlackListEntity::getBlockedType,blockType));
return;
}
}
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;
import com.tanpu.common.exception.BizException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
......@@ -45,4 +45,26 @@ public class RedisService {
Object v = redisTemplate.opsForValue().get(key);
return v == null ? null : (Integer) v;
}
/**
* incr
*/
public long incr(String key,Long delta){
if (delta<0){
throw new BizException("递增银子必须大于0");
}
return redisTemplate.opsForValue().increment(key,delta);
}
/**
* incr
*/
public long decr(String key,Long delta){
if (delta<0){
throw new BizException("递减银子必须大于0");
}
return redisTemplate.opsForValue().decrement(key,delta);
}
}
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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
@Service
public class ThemeService {
@Resource
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);
}
}
package com.tanpu.community.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.tanpu.community.dao.entity.community.TopicEntity;
import com.tanpu.community.dao.mapper.community.TopicMapper;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
@Service
@EnableCaching
public class TopicService {
@Resource
private TopicMapper topicMapper;
public List<TopicEntity> queryTopicList(){
return topicMapper.selectList(new QueryWrapper<>());
}
public void addTopic(TopicEntity topicEntity){
topicMapper.insert(topicEntity);
}
public void updateTopicToTop(String topicId){
UpdateWrapper<TopicEntity> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("id",topicId);
updateWrapper.set("is_top",1);
topicMapper.update(null,updateWrapper);
}
public void updateTopicNotTop(String topicId){
UpdateWrapper<TopicEntity> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("id",topicId);
updateWrapper.set("is_top",0);
topicMapper.update(null,updateWrapper);
}
public void updateTopicToConceal(String topicId){
UpdateWrapper<TopicEntity> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("id",topicId);
updateWrapper.set("is_conceal",1);
topicMapper.update(null,updateWrapper);
}
public void updateTopicNotConceal(String topicId){
UpdateWrapper<TopicEntity> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("id",topicId);
updateWrapper.set("is_conceal",0);
topicMapper.update(null,updateWrapper);
}
public TopicEntity queryById(String topicId) {
return topicMapper.selectById(topicId);
}
}
......@@ -50,7 +50,7 @@ CREATE TABLE `theme` (
CREATE TABLE `comment` (
`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 '文本内容',
`author_id` varchar(64) NOT NULL COMMENT '作者id',
`target_id` varchar(64) NOT NULL COMMENT '评论的目标id',
......@@ -67,7 +67,7 @@ CREATE TABLE `comment` (
CREATE TABLE `collection` (
`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',
`target_id` varchar(64) NOT NULL COMMENT '评论的目标id',
`create_by` varchar(64) DEFAULT '',
......@@ -82,7 +82,7 @@ CREATE TABLE `collection` (
CREATE TABLE `topic` (
`id` varchar(64) PRIMARY KEY COMMENT 'id',
`topic_title` int(4) NOT NULL COMMENT '话题名称',
`topic_title` varchar(64) NOT NULL COMMENT '话题名称',
`is_top` int(4) NOT NULL COMMENT '是否置顶',
`is_conceal` int(4) NOT NULL COMMENT '是否隐藏',
`create_by` varchar(64) DEFAULT '',
......@@ -111,7 +111,7 @@ CREATE TABLE `file_record` (
CREATE TABLE `black_list` (
`id` varchar(64) PRIMARY KEY COMMENT 'id',
`blocker` varchar(64) NOT NULL COMMENT '屏蔽发起人',
`blocked_type` int(4) NOT NULL COMMENT '屏蔽类型',
`blocked_type` int(4) NOT NULL COMMENT '屏蔽类型,1:用户,2:内容',
`blocked_id` varchar(64) NOT NULL COMMENT '被屏蔽的',
`create_by` varchar(64) DEFAULT '',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
......
......@@ -36,7 +36,7 @@
<dependency>
<groupId>com.tanpu</groupId>
<artifactId>common</artifactId>
<version>1.0.3-RELEASE</version>
<version>1.0.4-RELEASE</version>
</dependency>
<dependency>
......
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