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.enumModel.eAccountType;
import com.template.model.enumModel.eTopType;
import com.template.model.pojo.AlumniClub;
import com.template.mapper.AlumniClubMapper;
import com.template.model.pojo.AlumniUser;
import com.template.model.result.PageUtils;
import com.template.model.vo.ClubExcelVo;
import com.template.model.vo.OtherClubVo;
import com.template.services.AlumniClubService;
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-20
 */
@Service
public class AlumniClubServiceImpl extends ServiceImpl<AlumniClubMapper, AlumniClub> implements AlumniClubService {
    @Autowired
    private AlumniClubMapper alumniClubMapper;

    @Override
    public int insertAlumniClub(AlumniClub au) {
        int result = alumniClubMapper.insert(au);
        return result;
    }

    @Override
    public int updateAlumniClub(AlumniClub au) {
        int result = alumniClubMapper.updateById(au);
        return result;
    }

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

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

    @Override
    public PageUtils<AlumniClub> queryPageList(int currentPage, int pageCount, String name, String userName, String startTime, String endTime, Integer categoryId) {
        Page<AlumniClub> page = new Page<>(currentPage, pageCount);
        IPage<AlumniClub> result = alumniClubMapper.queryClubPages(page, name, userName, startTime, endTime, categoryId);
        return new PageUtils(result);
    }

    @Override
    public List<ClubExcelVo> queryDataList(String name, String userName, String startTime, String endTime, Integer categoryId) {
        List<ClubExcelVo> result = alumniClubMapper.queryClubDatas(name, userName, startTime, endTime, categoryId);
        return result;
    }

    //寻找置顶数据
    @Override
    public List<AlumniClub> findTopClubs() {
        QueryWrapper<AlumniClub> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("is_top", eTopType.Top.getValue());
        List<AlumniClub> result = alumniClubMapper.selectList(queryWrapper);
        return result;
    }

    @Override
    public List<OtherClubVo> CategoryCountDatas() {
        List<OtherClubVo> result = alumniClubMapper.CategoryCountDatas();
        return result;
    }

    @Override
    public PageUtils<AlumniClub> queryPageByCategory(int currentPage, int pageCount, int categoryId, String keyword) {
        Page<AlumniClub> page = new Page<>(currentPage, pageCount);
        QueryWrapper<AlumniClub> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(StringUtils.hasText(keyword), "name", keyword);//组织名称
        queryWrapper.eq("category_id",categoryId);
        IPage<AlumniClub> result = alumniClubMapper.selectPage(page,queryWrapper );
        return new PageUtils(result);
    }
}
