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.mapper.AlumniCategoryMapper;
import com.template.model.pojo.AlumniCategory;
import com.template.model.pojo.AlumniCategoryImage;
import com.template.mapper.AlumniCategoryImageMapper;
import com.template.model.pojo.AlumniCategoryNews;
import com.template.model.result.PageUtils;
import com.template.services.AlumniCategoryImageService;
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-11-25
 */
@Service
public class AlumniCategoryImageServiceImpl extends ServiceImpl<AlumniCategoryImageMapper, AlumniCategoryImage> implements AlumniCategoryImageService {
    @Autowired
    private AlumniCategoryImageMapper alumniCategoryImageMapper;

    @Override
    public int insertAlumniCategoryImage(AlumniCategoryImage au) {
        int result = alumniCategoryImageMapper.insert(au);
        return result;
    }

    @Override
    public int updateAlumniCategoryImage(AlumniCategoryImage au) {
        int result = alumniCategoryImageMapper.updateById(au);
        return result;
    }

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

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

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

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

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