package com.template.services.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.template.model.pojo.SmartNews;
import com.template.mapper.SmartNewsMapper;
import com.template.services.SmartNewsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ceshi
 * @since 2024-06-12
 */
@Service
public class SmartNewsServiceImpl extends ServiceImpl<SmartNewsMapper, SmartNews> implements SmartNewsService {

    @Autowired
    SmartNewsMapper smartNewsMapper;

    @Override
    public List<SmartNews> newsList() {
        LambdaQueryWrapper<SmartNews> wrapper=new LambdaQueryWrapper<>();
        wrapper.last("limit 3")
                        .orderByDesc(SmartNews::getDateTime);
        List<SmartNews> list = this.list(wrapper);
        return list;
    }

    @Override
    public SmartNews getMediaId(String mediaId) {
        LambdaQueryWrapper<SmartNews> wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(SmartNews::getMediaId,mediaId);
        SmartNews smartNews = this.getOne(wrapper);
        return smartNews;
    }


}
