Commit 07d7c66a authored by 刘基明's avatar 刘基明

话题相关

parent 3893149c
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;
@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.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.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;
@RestController
@Slf4j
@RequestMapping(value = "/api/topic")
public class TopicController {
@Autowired
private TopicManager topicManager;
@PostMapping(value = "/queryTopicList")
@ApiOperation("查询所有的主题列表")
@ResponseBody
public List<TopicDTO> getAllTopList(@RequestBody String content){
JSONObject params = JSONObject.parseObject(content);
List<TopicEntity> allTopic = topicManager.getAllTopic();
List<TopicDTO> topicDTOS = TopicConverter.convertToDTOs(allTopic);
return topicDTOS;
}
@PostMapping(value="/insertTopic")
@ResponseBody
public String addTopic(@RequestBody String topicTitle){
topicManager.insertTopic(topicTitle);
return "success";
}
@PostMapping(value = "/setTop")
@ResponseBody
public String setTopTopic(@RequestBody String topicId,@RequestBody boolean setTop) throws MissingServletRequestParameterException {
if (StringUtils.isEmpty(topicId)){
throw new MissingServletRequestParameterException("topicId","Long");
}
topicManager.setTopTopic(topicId,setTop);
return "success";
}
@PostMapping(value = "/setConceal")
@ResponseBody
public String setConceal(@RequestBody String topicId,@RequestBody boolean setConceal) throws MissingServletRequestParameterException {
if (StringUtils.isEmpty(topicId)){
throw new MissingServletRequestParameterException("topicId","Long");
}
topicManager.setTopicConceal(topicId,setConceal);
return "success";
}
}
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.manager;
import com.tanpu.common.exception.BizException;
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.util.List;
@Service
public class TopicManager {
@Autowired
private TopicService topicService;
public void insertTopic(String topicTitle){
TopicEntity topicEntity = new TopicEntity();
topicEntity.setTopicTitle(topicTitle);
}
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);
}
}
}
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.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("isTop",true);
topicMapper.update(null,updateWrapper);
}
public void updateTopicNotTop(String topicId){
UpdateWrapper<TopicEntity> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("id",topicId);
updateWrapper.set("isTop",false);
topicMapper.update(null,updateWrapper);
}
public void updateTopicToConceal(String topicId){
UpdateWrapper<TopicEntity> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("id",topicId);
updateWrapper.set("isConceal",true);
topicMapper.update(null,updateWrapper);
}
public void updateTopicNotConceal(String topicId){
UpdateWrapper<TopicEntity> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("id",topicId);
updateWrapper.set("isConceal",false);
topicMapper.update(null,updateWrapper);
}
public TopicEntity queryById(String topicId) {
return topicMapper.selectById(topicId);
}
}
......@@ -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 '',
......
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