package com.fs.store.service.impl;

import java.util.Date;
import java.util.List;

import com.fs.store.mapper.FsArticleMapper;
import com.fs.store.param.FsArticleViewListParam;
import com.fs.store.param.FsArticleViewListQueryParam;
import com.fs.store.vo.FsArticleViewListQueryVO;
import com.fs.store.vo.FsArticleViewListVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.fs.store.mapper.FsArticleViewsMapper;
import com.fs.store.domain.FsArticleViews;
import com.fs.store.service.IFsArticleViewsService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 文章阅读Service业务层处理
 *
 * @author fs
 * @date 2022-03-25
 */
@Service
public class FsArticleViewsServiceImpl implements IFsArticleViewsService
{
    @Autowired
    private FsArticleViewsMapper fsArticleViewsMapper;
    @Autowired
    private FsArticleMapper articleMapper;
    /**
     * 查询文章阅读
     *
     * @param viewId 文章阅读ID
     * @return 文章阅读
     */
    @Override
    public FsArticleViews selectFsArticleViewsById(Long viewId)
    {
        return fsArticleViewsMapper.selectFsArticleViewsById(viewId);
    }

    /**
     * 查询文章阅读列表
     *
     * @param fsArticleViews 文章阅读
     * @return 文章阅读
     */
    @Override
    public List<FsArticleViews> selectFsArticleViewsList(FsArticleViews fsArticleViews)
    {
        return fsArticleViewsMapper.selectFsArticleViewsList(fsArticleViews);
    }

    /**
     * 新增文章阅读
     *
     * @param fsArticleViews 文章阅读
     * @return 结果
     */
    @Override
    public int insertFsArticleViews(FsArticleViews fsArticleViews)
    {
        return fsArticleViewsMapper.insertFsArticleViews(fsArticleViews);
    }

    /**
     * 修改文章阅读
     *
     * @param fsArticleViews 文章阅读
     * @return 结果
     */
    @Override
    public int updateFsArticleViews(FsArticleViews fsArticleViews)
    {
        return fsArticleViewsMapper.updateFsArticleViews(fsArticleViews);
    }

    /**
     * 批量删除文章阅读
     *
     * @param viewIds 需要删除的文章阅读ID
     * @return 结果
     */
    @Override
    public int deleteFsArticleViewsByIds(Long[] viewIds)
    {
        return fsArticleViewsMapper.deleteFsArticleViewsByIds(viewIds);
    }

    /**
     * 删除文章阅读信息
     *
     * @param viewId 文章阅读ID
     * @return 结果
     */
    @Override
    public int deleteFsArticleViewsById(Long viewId)
    {
        return fsArticleViewsMapper.deleteFsArticleViewsById(viewId);
    }

    @Override
    public List<FsArticleViewListQueryVO> selectFsArticleViewsTopByArticleId(Integer articleId) {
        return fsArticleViewsMapper.selectFsArticleViewsTopByArticleId(articleId);
    }

    @Override
    @Transactional
    public int updateView(Long articleId, long userId) {
        FsArticleViews map=new FsArticleViews();
        map.setArticleId(articleId);
        map.setUserId(userId);
//        List<FsArticleViews> check=fsArticleViewsMapper.selectFsArticleViewsList(map);
//        if(check!=null&&check.size()>0){
//            return 0;
//        }
        map.setCreateTime(new Date());
        fsArticleViewsMapper.insertFsArticleViews(map);
        //更新文章阅读数
        articleMapper.updateViews(articleId);
        return 1;
    }

    @Override
    public List<FsArticleViewListQueryVO> selectFsArticleViewsListQueryVO(FsArticleViewListQueryParam param) {
        return fsArticleViewsMapper.selectFsArticleViewsListQueryVO(param);
    }

    @Override
    public List<FsArticleViewListVO> selectFsArticleViewsListVO(FsArticleViewListParam param) {
        return fsArticleViewsMapper.selectFsArticleViewsListVO(param);
    }


}
