package com.template.services.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.template.common.utils.TimeExchange;
import com.template.mapper.AlumniEndorseMapper;
import com.template.model.enumModel.eTimeType;
import com.template.model.pojo.AlumniEndorse;
import com.template.model.pojo.AlumniEndorse;
import com.template.mapper.AlumniEndorseMapper;
import com.template.model.result.PageUtils;
import com.template.model.vo.*;
import com.template.services.AlumniEndorseService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author ceshi
 * @since 2024-11-29
 */
@Service
public class AlumniEndorseServiceImpl extends ServiceImpl<AlumniEndorseMapper, AlumniEndorse> implements AlumniEndorseService {

    @Autowired
    private AlumniEndorseMapper alumniEndorseMapper;

    @Override
    public int insertAlumniEndorse(AlumniEndorse au) {
        int result = alumniEndorseMapper.insert(au);
        return result;
    }

    @Override
    public int updateAlumniEndorse(AlumniEndorse au) {
        int result = alumniEndorseMapper.updateById(au);
        return result;
    }

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

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

    @Override
    public PageUtils<AlumniEndorsePageVo> alumniEndorsePageDatas(int currentPage, int pageCount, Integer collegeId, Integer periodId, Integer majorId, Integer classId, String startTime, String endTime, String keyword) {
        Page<AlumniEndorsePageVo> page = new Page<>(currentPage, pageCount);
        IPage<AlumniEndorsePageVo> result = alumniEndorseMapper.alumniEndorsePageDatas(page, collegeId, periodId, majorId, classId, startTime, endTime, keyword);
        return new PageUtils(result);
    }

    @Override
    public PageUtils<AlumniEndorseApplyPageVo> alumniEndorsePageApplyDatas(int currentPage, int pageCount, Integer userId, Integer collegeId, Integer periodId, Integer majorId, Integer classId, String startTime, String endTime, String keyword, String name, Integer isPass) {
        Page<AlumniEndorseApplyPageVo> page = new Page<>(currentPage, pageCount);
        IPage<AlumniEndorseApplyPageVo> result = alumniEndorseMapper.alumniEndorsePageApplyDatas(page, userId, collegeId, periodId, majorId, classId, startTime, endTime, keyword, name, isPass);
        return new PageUtils(result);
    }

    @Override
    public PageUtils<MoblieEndorsePageVo> mobileEndorsePageDatas(int currentPage, int pageCount, String keyword) {
        Page<MoblieEndorsePageVo> page = new Page<>(currentPage, pageCount);
        IPage<MoblieEndorsePageVo> result = alumniEndorseMapper.mobileEndorsePageDatas(page, keyword);
        return new PageUtils(result);
    }

    @Override
    public PageUtils<ApplicationRecordPageVo> applicationRecordDatas(int currentPage, int pageCount, Integer userId, Integer weekType) {
        Page<ApplicationRecordPageVo> page = new Page<>(currentPage, pageCount);
        String weekTypeStr = null;
        if (weekType.intValue() == eTimeType.Week.getValue()) {//本周
            String weekStart = TimeExchange.getCurrentWeekTimeFrame()[0];
            String weekEnd = TimeExchange.getCurrentWeekTimeFrame()[1];
            weekTypeStr = " and ae.create_time between '" + weekStart + "' and '" + weekEnd + "' ";

        } else if (weekType.intValue() == eTimeType.Month.getValue()) {//本月
            String monthStart = TimeExchange.getCurrentMonthTimeFrame(TimeExchange.getDate())[0];
            String monthEnd = TimeExchange.getCurrentMonthTimeFrame(TimeExchange.getDate())[1];
            weekTypeStr = " and ae.create_time between '" + monthStart + "' and '" + monthEnd + "' ";
        }
        IPage<ApplicationRecordPageVo> result = alumniEndorseMapper.applicationRecordDatas(page, userId, weekTypeStr);
        return new PageUtils(result);
    }

    @Override
    public PageUtils<ApplicationRecordPageVo> applicationMyRecordDatas(int currentPage, int pageCount, Integer userId, String name) {
        Page<ApplicationRecordPageVo> page = new Page<>(currentPage, pageCount);

        IPage<ApplicationRecordPageVo> result = alumniEndorseMapper.applicationMyRecordDatas(page, userId, name);
        return new PageUtils(result);
    }

    @Override
    public PageUtils<ApplicationRecordPageVo> applicationApproveRecordDatas(int currentPage, int pageCount, Integer userId, String name) {
        Page<ApplicationRecordPageVo> page = new Page<>(currentPage, pageCount);

        IPage<ApplicationRecordPageVo> result = alumniEndorseMapper.applicationApproveRecordDatas(page, userId, name);
        return new PageUtils(result);
    }
}
