<?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.education.business.mapper.education.StudentInfoMapper">


    <!-- 学员列表 -->
    <select id="selectPageList" resultType="studentInfoDto">
        select student.*, grade.name grade_name from student_info student left join grade_info grade
        on student.grade_info_id = grade.id
        <where>
            <if test="studentInfo.gradeInfoId != null">
                and student.grade_info_id = #{studentInfo.gradeInfoId}
            </if>

            <if test="studentInfo.name != null and studentInfo.name != ''">
                <bind name="name" value="'%' + studentInfo.name + '%'"/>
                and student.name like #{name} or student.mobile like #{name}
            </if>
        </where>
        order by student.id desc
    </select>

    <select id="selectById" resultType="com.education.model.dto.StudentInfoDto">
        SELECT
            si.*,

            CONCAT(
                    ROUND(
                            (
                                SELECT COUNT(DISTINCT sgi.goal_info_id)
                                FROM stu_goal_info sgi
                                WHERE sgi.student_id = si.id AND sgi.correct_status >= 2
                            ) / NULLIF(
                                    (
                                        SELECT COUNT( gi.id)
                                        FROM student_course_collect scc
                                                 JOIN goal_info gi ON scc.course_id = gi.course_id
                                        WHERE scc.student_id = si.id AND gi.publish_flag = 1
                                    ), 0
                                ) * 100, 2
                    ), '%'
            ) AS progress
        FROM
            student_info si
        WHERE
            si.id = #{id}
    </select>

</mapper>