<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.xjrsoft.module.student.mapper.BaseStudentScholarshipReleaseMapper">
    <select id="getPage" parameterType="com.xjrsoft.module.student.dto.BaseStudentScholarshipReleasePageDto" resultType="com.xjrsoft.module.student.vo.BaseStudentScholarshipReleasePageVo">
        SELECT t1.id,t2.name AS semester_name,t1.release_status,t3.name,t4.name AS gender_cn,t3.credential_number,t6.name AS class_name,
        t7.name AS scholarship_category,t8.name AS category_cn,t7.scholarship_level,t1.amount,t1.bank_no,t1.bank_type,t1.bank_user_name,
        (SELECT SUM(amount) FROM base_student_scholarship_release WHERE base_student_scholarship_applicant_id = t1.id AND delete_mark = 0) AS release_amount,
        (SELECT release_date FROM base_student_scholarship_release WHERE base_student_scholarship_applicant_id = t1.id
        AND delete_mark = 0 ORDER BY release_date DESC LIMIT 0, 1) AS release_date FROM base_student_scholarship_applicant t1
        LEFT JOIN base_semester t2 ON t1.base_semester_id = t2.id
        LEFT JOIN xjr_user t3 ON t1.applicant_user_id = t3.id
        LEFT JOIN xjr_dictionary_detail t4 ON t3.gender = t4.code AND t4.item_id = 2023000000000000004
        LEFT JOIN base_student_school_roll t5 ON t3.id = t5.user_id
        LEFT JOIN base_class t6 ON t5.class_id = t6.id
        LEFT JOIN base_student_scholarship_category t7 ON t1.base_student_scholarship_category_id = t7.id
        LEFT JOIN xjr_dictionary_detail t8 ON t7.category = t8.code
        WHERE t1.status = 1 AND t1.delete_mark = 0 and t1.review_status = 1
        <if test="dto.name != null and dto.name != ''">
            and t3.name like concat('%', #{dto.name}, '%')
        </if>
        <if test="dto.credentialNumber != null and dto.credentialNumber != ''">
            and t3.credential_number like concat('%', #{dto.credentialNumber}, '%')
        </if>
        <if test="dto.scholarshipCategory != null and dto.scholarshipCategory != ''">
            and t7.name like concat('%', #{dto.scholarshipCategory}, '%')
        </if>
        <if test="dto.semesterId != null">
            and t1.base_semester_id = #{dto.semesterId}
        </if>
        <if test="dto.releaseStatus != null">
            and t1.release_status = #{dto.releaseStatus}
        </if>
        <if test="dto.scholarshipCategoryId != null">
            and t7.id = #{dto.scholarshipCategoryId}
        </if>
    </select>
</mapper>