package com.ruoyi.web.work.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.web.work.domain.News;
import com.ruoyi.web.work.mapper.NewsMapper;
import com.ruoyi.web.work.service.INewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author lsw
 * @date 2024-05-31
 */
@Service
public class NewsServiceImpl extends ServiceImpl<NewsMapper, News> implements INewsService {
    @Autowired
    private NewsMapper newsMapper;

    @Override
    public List<News> selectList(News news) {
        return newsMapper.selectList(news);
    }

    @Override
    public List<News> homeList() {
        return newsMapper.homeList();
    }

    @Override
    public AjaxResult detail(Long id) {
        News news = getById(id);
        if (news == null || news.getState() != 0) {
            return AjaxResult.error("新闻不存在或停用");
        }
        return AjaxResult.success(news);
    }
}
