package com.fs.hisStore.service.impl;

import java.util.List;
import com.fs.common.utils.DateUtils;
import com.fs.hisStore.mapper.FsArticleViewsScrmMapper;
import com.fs.hisStore.param.FsArticleQueryParam;
import com.fs.hisStore.vo.FsArticleListQueryVO;
import com.fs.hisStore.vo.FsArticleVO;
import com.fs.hisStore.vo.FsArticleViewListQueryVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.fs.hisStore.mapper.FsArticleScrmMapper;
import com.fs.hisStore.domain.FsArticleScrm;
import com.fs.hisStore.service.IFsArticleScrmService;

/**
 * 文章Service业务层处理
 *
 * @author fs
 * @date 2022-03-25
 */
@Service
public class FsArticleScrmServiceImpl implements IFsArticleScrmService
{
    @Autowired
    private FsArticleScrmMapper fsArticleMapper;
    @Autowired
    private FsArticleViewsScrmMapper viewsMapper;
    /**
     * 查询文章
     *
     * @param articleId 文章ID
     * @return 文章
     */
    @Override
    public FsArticleScrm selectFsArticleById(Integer articleId)
    {
        return fsArticleMapper.selectFsArticleById(articleId);
    }

    /**
     * 查询文章列表
     *
     * @param fsArticle 文章
     * @return 文章
     */
    @Override
    public List<FsArticleScrm> selectFsArticleList(FsArticleScrm fsArticle)
    {
        return fsArticleMapper.selectFsArticleList(fsArticle);
    }

    /**
     * 新增文章
     *
     * @param fsArticle 文章
     * @return 结果
     */
    @Override
    public int insertFsArticle(FsArticleScrm fsArticle)
    {
        fsArticle.setCreateTime(DateUtils.getNowDate());
        return fsArticleMapper.insertFsArticle(fsArticle);
    }

    /**
     * 修改文章
     *
     * @param fsArticle 文章
     * @return 结果
     */
    @Override
    public int updateFsArticle(FsArticleScrm fsArticle)
    {
        fsArticle.setUpdateTime(DateUtils.getNowDate());
        return fsArticleMapper.updateFsArticle(fsArticle);
    }

    /**
     * 批量删除文章
     *
     * @param articleIds 需要删除的文章ID
     * @return 结果
     */
    @Override
    public int deleteFsArticleByIds(Integer[] articleIds)
    {
        return fsArticleMapper.deleteFsArticleByIds(articleIds);
    }

    /**
     * 删除文章信息
     *
     * @param articleId 文章ID
     * @return 结果
     */
    @Override
    public int deleteFsArticleById(Integer articleId)
    {
        return fsArticleMapper.deleteFsArticleById(articleId);
    }

    @Override
    public List<FsArticleVO> selectFsArticleListVO(FsArticleScrm fsArticle) {
        return fsArticleMapper.selectFsArticleListVO(fsArticle);
    }

    @Override
    public List<FsArticleListQueryVO> selectFsArticleListQuery(FsArticleQueryParam param) {
        List<FsArticleListQueryVO> list=fsArticleMapper.selectFsArticleListQuery(param);
        for(FsArticleListQueryVO vo:list){
            List<FsArticleViewListQueryVO> viewsList=viewsMapper.selectFsArticleViewsTopByArticleId(vo.getArticleId());
            vo.setViewsList(viewsList);
        }
        return list;
    }


}
