package com.xjrsoft.module.student.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.xjrsoft.module.room.entity.RoomBed;
import com.xjrsoft.module.student.dto.BaseStudentScholarshipReleasePageDto;
import com.xjrsoft.module.student.entity.BaseStudentScholarshipApplicant;
import com.xjrsoft.module.student.entity.BaseStudentScholarshipRelease;
import com.xjrsoft.module.student.mapper.BaseStudentScholarshipApplicantMapper;
import com.xjrsoft.module.student.mapper.BaseStudentScholarshipReleaseMapper;
import com.xjrsoft.module.student.service.IBaseStudentScholarshipReleaseService;
import com.xjrsoft.module.student.vo.BaseStudentScholarshipReleasePageVo;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @title: 奖学金发放记录表
* @Author dzx
* @Date: 2024-07-25
* @Version 1.0
*/
@Service
@AllArgsConstructor
public class BaseStudentScholarshipReleaseServiceImpl extends MPJBaseServiceImpl<BaseStudentScholarshipReleaseMapper, BaseStudentScholarshipRelease> implements IBaseStudentScholarshipReleaseService {
    private BaseStudentScholarshipApplicantMapper applicantMapper;
    @Override
    public Page<BaseStudentScholarshipReleasePageVo> getPage(Page<BaseStudentScholarshipReleasePageVo> page, BaseStudentScholarshipReleasePageDto dto) {
        return this.baseMapper.getPage(page, dto);
    }

    @Override
    public Boolean remove(List<Long> ids) {
        List<BaseStudentScholarshipApplicant> applicantList = applicantMapper.selectBatchIds(ids);
        for (BaseStudentScholarshipApplicant applicant : applicantList) {
            UpdateWrapper<BaseStudentScholarshipApplicant> updateWrapper = new UpdateWrapper<>();
            updateWrapper.eq("id", applicant.getId());
            updateWrapper.setSql("review_status = null");
            applicantMapper.update(applicant, updateWrapper);
        }

        return this.removeBatchByIds(ids);
    }
}
