<?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.qmth.distributed.print.business.mapper.TRExamStudentMapper">

    <select id="listStudentCourseByCultureProgramIdAndStudentCodeAndSemesterId"
            resultType="com.qmth.distributed.print.business.bean.dto.report.StudentCourseInfoDto">
        SELECT
            rbi.culture_program_id,
            bs.name semesterName,
            rbi.course_code,
            rbi.course_name,
            res.result_detail,
            res.score
        FROM
            t_r_exam_student res
                LEFT JOIN
            t_r_basic_info rbi ON res.r_basic_info_id = rbi.id
                LEFT JOIN
            basic_exam be ON rbi.exam_id = be.id
                LEFT JOIN
            basic_semester bs ON be.semester_id = bs.id
        WHERE
            rbi.culture_program_id = #{cultureProgramId}
          AND res.student_code = #{studentCode}
          <if test="semesterId != null">
              AND bs.id = #{semesterId}
          </if>
    </select>
    <select id="requirementStudentPage"
            resultType="com.qmth.distributed.print.business.bean.dto.report.StudentRequirementInfoDto">
        SELECT DISTINCT
            rbi.culture_program_id cultureProgramId,
            res.name studentName,
            res.student_code studentCode,
            es.college_name collegeName,
            es.major_name majorName
        FROM
            t_r_exam_student res
                LEFT JOIN
            t_r_basic_info rbi ON res.r_basic_info_id = rbi.id
                LEFT JOIN
            exam_student es ON rbi.exam_id = es.exam_id
                AND rbi.paper_number = es.paper_number
                AND res.student_code = es.student_code
            where rbi.culture_program_id = #{cultureProgramId}
                <if test="studentCodeOrName != null and studentCodeOrName != ''">
                    AND (res.name LIKE CONCAT('%', #{studentCodeOrName}, '%')
                    OR res.student_code LIKE CONCAT('%', #{studentCodeOrName}, '%'))
                </if>
    </select>
</mapper>
