package com.fs.store.service.impl;

import com.fs.common.utils.DateUtils;
import com.fs.store.domain.FsHomeArticle;
import com.fs.store.mapper.FsHomeArticleMapper;
import com.fs.store.param.home.HomeArticlePageParam;
import com.fs.store.service.IFsHomeArticleService;
import com.fs.store.vo.home.HomeArticleDetailsVO;
import com.fs.store.vo.home.HomeArticleListVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 期刊Service业务层处理
 *
 * @author fs
 * @date 2025-05-22
 */
@Service
public class FsHomeArticleServiceImpl implements IFsHomeArticleService
{
    @Autowired
    private FsHomeArticleMapper fsHomeArticleMapper;

    /**
     * 查询期刊
     *
     * @param articleId 期刊ID
     * @return 期刊
     */
    @Override
    public FsHomeArticle selectFsHomeArticleById(Long articleId)
    {
        return fsHomeArticleMapper.selectFsHomeArticleById(articleId);
    }

    /**
     * 查询期刊列表
     *
     * @param fsHomeArticle 期刊
     * @return 期刊
     */
    @Override
    public List<FsHomeArticle> selectFsHomeArticleList(FsHomeArticle fsHomeArticle)
    {
        return fsHomeArticleMapper.selectFsHomeArticleList(fsHomeArticle);
    }

    /**
     * 新增期刊
     *
     * @param fsHomeArticle 期刊
     * @return 结果
     */
    @Override
    public int insertFsHomeArticle(FsHomeArticle fsHomeArticle)
    {
        fsHomeArticle.setCreateTime(DateUtils.getNowDate());
        if(fsHomeArticle.getPublicStatus() == 1 ){
            fsHomeArticle.setPublishTime(DateUtils.getNowDate());
        } else {
            fsHomeArticle.setPublishTime(null);
        }
        return fsHomeArticleMapper.insertFsHomeArticle(fsHomeArticle);
    }

    /**
     * 修改期刊
     *
     * @param fsHomeArticle 期刊
     * @return 结果
     */
    @Override
    public int updateFsHomeArticle(FsHomeArticle fsHomeArticle)
    {
        fsHomeArticle.setUpdateTime(DateUtils.getNowDate());
        if(fsHomeArticle.getPublicStatus() == 1 ){
            fsHomeArticle.setPublishTime(DateUtils.getNowDate());
        } else {
            fsHomeArticle.setPublishTime(null);
        }
        return fsHomeArticleMapper.updateFsHomeArticle(fsHomeArticle);
    }

    /**
     * 批量删除期刊
     *
     * @param articleIds 需要删除的期刊ID
     * @return 结果
     */
    @Override
    public int deleteFsHomeArticleByIds(Long[] articleIds)
    {
        return fsHomeArticleMapper.deleteFsHomeArticleByIds(articleIds);
    }

    /**
     * 删除期刊信息
     *
     * @param articleId 期刊ID
     * @return 结果
     */
    @Override
    public int deleteFsHomeArticleById(Long articleId)
    {
        return fsHomeArticleMapper.deleteFsHomeArticleById(articleId);
    }

    @Override
    public List<HomeArticleListVO> selectHomeArticlePageList(HomeArticlePageParam param) {
        return fsHomeArticleMapper.selectHomeArticlePageList(param);
    }

    @Override
    public HomeArticleDetailsVO getHomeArticleDetailsById(Long articleId) {
        return fsHomeArticleMapper.getHomeArticleDetailsById(articleId);
    }
}
