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

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.xjrsoft.common.enums.GenderEnum;
import com.xjrsoft.module.student.dto.BaseStudentScholarshipApplicantCategoryPageDto;
import com.xjrsoft.module.student.entity.BaseStudentScholarshipApplicant;
import com.xjrsoft.module.student.mapper.BaseStudentMapper;
import com.xjrsoft.module.student.mapper.BaseStudentScholarshipApplicantMapper;
import com.xjrsoft.module.student.service.IBaseStudentScholarshipApplicantService;
import com.xjrsoft.module.student.vo.BaseStudentScholarshipApplicantCategoryPageVo;
import com.xjrsoft.module.student.vo.StudentInfoVo;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * @title: 奖学金申请
 * @Author dzx
 * @Date: 2023-11-23
 * @Version 1.0
 */
@Service
@AllArgsConstructor
public class BaseStudentScholarshipApplicantServiceImpl extends MPJBaseServiceImpl<BaseStudentScholarshipApplicantMapper, BaseStudentScholarshipApplicant> implements IBaseStudentScholarshipApplicantService {
    private final BaseStudentScholarshipApplicantMapper baseStudentScholarshipApplicantMapper;
    @Override
    public Page<BaseStudentScholarshipApplicantCategoryPageVo> getScholarshiPage(Page<BaseStudentScholarshipApplicantCategoryPageDto> page, BaseStudentScholarshipApplicantCategoryPageDto dto) {
        Page<BaseStudentScholarshipApplicantCategoryPageVo> result = baseStudentScholarshipApplicantMapper.getScholarshiPage(page, dto);
        return result;
    }

    private final BaseStudentScholarshipApplicantMapper scholarshipApplicantMapper;

    private final BaseStudentMapper studentMapper;

    @Override
    public Boolean processDataHandler(Long dataId) {
        if (dataId == null) {
            return false;
        }
        // 原始数据
        BaseStudentScholarshipApplicant scholarshipApplicant = scholarshipApplicantMapper.selectById(dataId);
        // 获取学生信息
        StudentInfoVo studentInfo = studentMapper.getStudentInfo(scholarshipApplicant.getApplicantUserId());
        scholarshipApplicant.setGradeName(studentInfo.getGradeName());
        scholarshipApplicant.setClassName(studentInfo.getClassName());
        scholarshipApplicant.setName(studentInfo.getStudentName());
        scholarshipApplicant.setStudentId(studentInfo.getStudentId());
        scholarshipApplicant.setGenderName(GenderEnum.getValue(studentInfo.getGender()));
        scholarshipApplicant.setEnrollTypeCn(studentInfo.getEnrollmentType());
        scholarshipApplicant.setMajorName(studentInfo.getMajorName());

        return updateById(scholarshipApplicant);
    }
}
