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.ePassType;
import com.template.model.pojo.AlumniClub;
import com.template.model.pojo.AlumniClubApply;
import com.template.mapper.AlumniClubApplyMapper;
import com.template.model.result.PageUtils;
import com.template.model.vo.ApplyClubVo;
import com.template.services.AlumniClubApplyService;
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-11-22
 */
@Service
public class AlumniClubApplyServiceImpl extends ServiceImpl<AlumniClubApplyMapper, AlumniClubApply> implements AlumniClubApplyService {

    @Autowired
    private AlumniClubApplyMapper alumniClubApplyMapper;

    @Override
    public int insertAlumniClubApply(AlumniClubApply aca) {
        int result = alumniClubApplyMapper.insert(aca);
        return result;
    }

    @Override
    public int updateAlumniClubApply(AlumniClubApply aca) {
        int result = alumniClubApplyMapper.updateById(aca);
        return result;
    }

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

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

    @Override
    public int queryClubMember(Integer clubId) {
        QueryWrapper<AlumniClubApply> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(clubId != null && clubId.intValue() > 0, "club_id", clubId);
        queryWrapper.eq("is_pass", ePassType.Passed.getValue());
        int result = alumniClubApplyMapper.selectCount(queryWrapper);
        return result;
    }

    @Override
    public PageUtils<ApplyClubVo> queryClubApplys(Integer userId, int currentPage, int pageCount, String name, String userName, Integer isPass, Integer collegeId, Integer periodId, Integer majorId, Integer classId, String startTime, String endTime, Integer categoryId) {
        Page<ApplyClubVo> page = new Page<>(currentPage, pageCount);
        IPage<ApplyClubVo> result = alumniClubApplyMapper.queryClubApplys(page, userId, name, userName, isPass, collegeId, periodId, majorId, classId, startTime, endTime, categoryId);
        return new PageUtils(result);
    }

    @Override
    public PageUtils<ApplyClubVo> queryMyClubApplys(int currentPage, int pageCount, Integer userId, String name) {
        Page<ApplyClubVo> page = new Page<>(currentPage, pageCount);
        IPage<ApplyClubVo> result = alumniClubApplyMapper.queryMyClubApplys(page, userId, name);
        return new PageUtils(result);
    }

    @Override
    public List<ApplyClubVo> queryClubExcelApplys(Integer userId, String name, String userName, Integer isPass, Integer collegeId, Integer periodId, Integer majorId, Integer classId, String startTime, String endTime) {

        List<ApplyClubVo> result = alumniClubApplyMapper.queryClubExcelApplys(userId, name, userName, isPass, collegeId, periodId, majorId, classId, startTime, endTime);
        return result;
    }

    @Override
    public PageUtils<ApplyClubVo> queryApproveClubApplys(int currentPage, int pageCount, Integer userId, String name) {
        Page<ApplyClubVo> page = new Page<>(currentPage, pageCount);
        IPage<ApplyClubVo> result = alumniClubApplyMapper.queryMyClubApplys(page, userId, name);
        return new PageUtils(result);
    }

    @Override
    public List<AlumniClubApply> queryClubApplys(Integer userId) {
        QueryWrapper<AlumniClubApply> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("create_user", userId);
        queryWrapper.ne("is_pass", ePassType.Rejected.getValue());
        List<AlumniClubApply> result = alumniClubApplyMapper.selectList(queryWrapper);
        return result;
    }
}
