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.AlumniUserMapper;
import com.template.model.enumModel.eAccountType;
import com.template.model.pojo.AlumniCategory;
import com.template.mapper.AlumniCategoryMapper;
import com.template.model.pojo.AlumniUser;
import com.template.model.result.PageUtils;
import com.template.services.AlumniCategoryService;
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;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ceshi
 * @since 2024-11-20
 */
@Service
public class AlumniCategoryServiceImpl extends ServiceImpl<AlumniCategoryMapper, AlumniCategory> implements AlumniCategoryService {
    @Autowired
    private AlumniCategoryMapper alumniCategoryMapper;

    @Override
    public int insertAlumniCategory(AlumniCategory au) {
        int result = alumniCategoryMapper.insert(au);
        return result;
    }

    @Override
    public int updateAlumniCategory(AlumniCategory au) {
        int result = alumniCategoryMapper.updateById(au);
        return result;
    }

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

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

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

    @Override
    public PageUtils<AlumniCategory> queryPageList(int currentPage, int pageCount, String name, Integer userId, String startTime, String endTime) {
        Page<AlumniCategory> page = new Page<>(currentPage,pageCount);
        QueryWrapper<AlumniCategory> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(StringUtils.hasText(name),"name",name);//分类名称
        queryWrapper.like(userId != null && userId.intValue() > 0,"create_user",userId);//创建人
        if(StringUtils.hasText(startTime) && StringUtils.hasText(endTime)){
            queryWrapper.between("create_time",startTime,endTime);
        }
        IPage<AlumniCategory> result = alumniCategoryMapper.selectPage(page, queryWrapper);
        return new PageUtils(result);
    }
}
