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.AlumniReturn;
import com.template.mapper.AlumniReturnMapper;
import com.template.model.result.PageUtils;
import com.template.model.vo.ApplicationRecordPageVo;
import com.template.model.vo.ApplicationReturnPageVo;
import com.template.services.AlumniReturnService;
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-12-03
 */
@Service
public class AlumniReturnServiceImpl extends ServiceImpl<AlumniReturnMapper, AlumniReturn> implements AlumniReturnService {

    @Autowired
    private AlumniReturnMapper alumniReturnMapper;

    @Override
    public int insertAlumniReturn(AlumniReturn au) {
        int result = alumniReturnMapper.insert(au);
        return result;
    }

    @Override
    public int updateAlumniReturn(AlumniReturn au) {
        int result = alumniReturnMapper.updateById(au);
        return result;
    }

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

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

    @Override
    public PageUtils<ApplicationReturnPageVo> applicationReturnDatas(int currentPage, int pageCount, Integer userId, Integer weekType) {
        Page<ApplicationReturnPageVo> 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<ApplicationReturnPageVo> result = alumniReturnMapper.applicationReturnDatas(page, userId, weekTypeStr);
        return new PageUtils(result);
    }
}
