package com.template.services.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.template.model.pojo.AlumniCategory;
import com.template.model.pojo.AlumniCategoryNews;
import com.template.model.pojo.AlumniCategoryNews;
import com.template.mapper.AlumniCategoryNewsMapper;
import com.template.model.result.PageUtils;
import com.template.services.AlumniCategoryNewsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ceshi
 * @since 2024-12-02
 */
@Service
public class AlumniCategoryNewsServiceImpl extends ServiceImpl<AlumniCategoryNewsMapper, AlumniCategoryNews> implements AlumniCategoryNewsService {

    @Autowired
    private AlumniCategoryNewsMapper alumniCategoryNewsMapper;

    @Override
    public int insertAlumniCategoryNews(AlumniCategoryNews au) {
        int result = alumniCategoryNewsMapper.insert(au);
        return result;
    }

    @Override
    public int updateAlumniCategoryNews(AlumniCategoryNews au) {
        int result = alumniCategoryNewsMapper.updateById(au);
        return result;
    }

    @Override
    public AlumniCategoryNews queryDataById(Integer id) {
        AlumniCategoryNews result = alumniCategoryNewsMapper.selectById(id);
        return result;
    }

    @Override
    public int deleteDataById(Integer id) {
        int result = alumniCategoryNewsMapper.deleteById(id);
        return result;
    }

    @Override
    public PageUtils<AlumniCategoryNews> queryPageList(int currentPage, int pageCount, String startTime, String endTime) {
        Page<AlumniCategoryNews> page = new Page<>(currentPage,pageCount);
        QueryWrapper<AlumniCategoryNews> queryWrapper = new QueryWrapper<>();
        if(StringUtils.hasText(startTime) && StringUtils.hasText(endTime)){
            queryWrapper.between("create_time",startTime,endTime);
        }
        IPage<AlumniCategoryNews> result = alumniCategoryNewsMapper.selectPage(page, queryWrapper);
        return new PageUtils(result);
    }

    @Override
    public List<AlumniCategoryNews> queryDatas() {
        List<AlumniCategoryNews> result = alumniCategoryNewsMapper.selectList(null);
        return result;
    }

    @Override
    public AlumniCategoryNews queryDataByName(String name) {
        QueryWrapper<AlumniCategoryNews> queryWrapper = new QueryWrapper();
        queryWrapper.eq("name",name);
        AlumniCategoryNews result = alumniCategoryNewsMapper.selectOne(queryWrapper);
        return result;
    }
}
