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.AlumniNewsMapper;
import com.template.model.enumModel.eTopType;
import com.template.model.pojo.AlumniClub;
import com.template.model.pojo.AlumniHeart;
import com.template.mapper.AlumniHeartMapper;
import com.template.model.pojo.AlumniImage;
import com.template.model.result.PageUtils;
import com.template.services.AlumniHeartService;
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 2025-01-13
 */
@Service
public class AlumniHeartServiceImpl extends ServiceImpl<AlumniHeartMapper, AlumniHeart> implements AlumniHeartService {

    @Autowired
    private AlumniHeartMapper alumniHeartMapper;

    @Override
    public int insertAlumniHeart(AlumniHeart au) {
        int result = alumniHeartMapper.insert(au);
        return result;
    }

    @Override
    public int updateAlumniHeart(AlumniHeart au) {
        int result = alumniHeartMapper.updateById(au);
        return result;
    }

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

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

    @Override
    public List<AlumniHeart> findTopHearts() {
        QueryWrapper<AlumniHeart> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("is_top", eTopType.Top.getValue());
        List<AlumniHeart> result = alumniHeartMapper.selectList(queryWrapper);
        return result;
    }

    @Override
    public PageUtils<AlumniHeart> queryPageList(int currentPage, int pageCount, String name, String startTime, String endTime) {
        Page<AlumniHeart> page = new Page<>(currentPage, pageCount);
        QueryWrapper<AlumniHeart> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(StringUtils.hasText(name), "equity_name", name);//权益名称
        if (StringUtils.hasText(startTime) && StringUtils.hasText(endTime)) {
            queryWrapper.between("create_time", startTime, endTime);
        }
        queryWrapper.orderByDesc("is_top", "create_time");
        IPage<AlumniHeart> result = alumniHeartMapper.selectPage(page, queryWrapper);
        return new PageUtils(result);
    }
}
