<?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.BaseStudentScholarshipCategoryMapper">
    <select id="getStatisticsPage" parameterType="com.xjrsoft.module.student.dto.BaseStudentScholarshipReleasePageDto" resultType="com.xjrsoft.module.student.vo.BaseStudentScholarshipCategoryStatisticPageVo">
        SELECT t1.id, t1.name,t2.name AS category_cn,t1.total_amount,(
        SELECT SUM(amount) FROM base_student_scholarship_applicant WHERE base_student_scholarship_category_id = t1.id
        AND STATUS = 1) AS applicant_amonut,(
        SELECT SUM(a1.amount) FROM base_student_scholarship_release a1
        LEFT JOIN base_student_scholarship_applicant a2 ON a1.base_student_scholarship_applicant_id = a2.id
        WHERE a2.base_student_scholarship_category_id = t1.id AND a1.delete_mark = 0 AND a2.delete_mark = 0
        ) AS release_amount,(
        select count(*) from base_student_scholarship_applicant
        where status = 1 and base_student_scholarship_category_id = t1.id
        and delete_mark = 0
        ) as applicant_count,t3.name as semester_name, t1.scholarship_level,t1.base_semester_id as semester_id FROM base_student_scholarship_category t1
        LEFT JOIN xjr_dictionary_detail t2 ON t1.category = t2.code
        left join base_semester t3 on t1.base_semester_id = t3.id
        WHERE t1.delete_mark = 0
        <if test="dto.name != null and dto.name != ''">
            and t1.name like concat('%', #{dto.name},'%')
        </if>
        <if test="dto.semesterId != null">
            and t1.base_semester_id = #{dto.semesterId}
        </if>
    </select>
</mapper>