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; } }