ThemeManager.java 3.71 KB
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);
    }
}