package org.jeecg.modules.database.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.database.entity.DocumentFavorites;
import org.jeecg.modules.database.mapper.DocumentFavoritesMapper;
import org.jeecg.modules.database.service.IDocumentFavoritesService;
import org.jeecg.modules.database.service.IDocumentLibraryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description: 我的收藏文档
 * @Author: jeecg-boot
 * @Date: 2024-08-30
 * @Version: V1.0
 */
@Service
public class DocumentFavoritesServiceImpl extends ServiceImpl<DocumentFavoritesMapper, DocumentFavorites>
        implements IDocumentFavoritesService {
    @Autowired
    private IDocumentLibraryService documentLibraryService;

    @Override
    public List<DocumentFavorites> getTopFavoritesByUserId(String userId) {
        LambdaQueryWrapper<DocumentFavorites> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(DocumentFavorites::getUserId, userId);
        queryWrapper.orderByDesc(DocumentFavorites::getCreateTime);
        Page<DocumentFavorites> page = new Page<>(1, 10);
        List<DocumentFavorites> list = list(page, queryWrapper);
        return list;
    }

    @Override
    public DocumentFavorites getByDocIdAndUserId(String userId, String documentId) {
        LambdaQueryWrapper<DocumentFavorites> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(DocumentFavorites::getUserId, userId);
        queryWrapper.eq(DocumentFavorites::getDocumentId, userId);
        return getOne(queryWrapper, false);
    }

    @Override
    public void removeByDocId(String documentId) {
        LambdaQueryWrapper<DocumentFavorites> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(DocumentFavorites::getDocumentId, documentId);
        remove(queryWrapper);
    }
}
