<?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.ClassHonorsMapper">
    <select id="getPagePC" parameterType="com.xjrsoft.module.student.dto.ClassHonorsPageDto" resultType="com.xjrsoft.module.student.vo.ClassHonorsPageVo">
        SELECT
            t.id,
            t.sort_code,
            t1.name AS honorsLevelCN,
            t2.name AS honorsGradeCN,
            t.name,
            t.award_date
        FROM class_honors t
            LEFT JOIN xjr_dictionary_detail t1 ON t1.code = t.honors_level
            LEFT JOIN xjr_dictionary_detail t2 ON t2.code = t.honors_grade
        WHERE
            t.delete_mark = 0
            <if test="dto.honorsLevel != null and dto.honorsLevel != ''">
                and t.honors_level = #{dto.honorsLevel}
            </if>
            <if test="dto.honorsGrade != null and dto.honorsGrade != ''">
                and t.honors_grade = #{dto.honorsGrade}
            </if>
            <if test="dto.awardDate != null and dto.awardDate != ''">
                and t.award_date = #{dto.awardDate}
            </if>
            <if test="dto.name != null and dto.name != ''">
                and t.name like concat('%',#{dto.name},'%')
            </if>
            <if test="dto.baseSemesterId != null and dto.baseSemesterId > 0">
                and t.base_semester_id = #{dto.baseSemesterId}
            </if>
            <if test="dto.classId != null and dto.classId > 0">
                and t.class_id = #{dto.classId}
            </if>
        ORDER BY
            t.id DESC;
    </select>
    <select id="getInfoById"
            resultType="com.xjrsoft.module.student.vo.ClassHonorsVo">
        SELECT
            t.*,
            t1.name AS honorsLevelCN,
            t2.name AS honorsGradeCN,
            t3.name AS baseSemesterIdCN,
            t4.name AS classIdCN
        FROM class_honors t
            LEFT JOIN xjr_dictionary_detail t1 ON t1.code = t.honors_level
            LEFT JOIN xjr_dictionary_detail t2 ON t2.code = t.honors_grade
            LEFT JOIN base_semester t3 ON t3.id = t.base_semester_id
            LEFT JOIN base_class t4 ON t4.id = t.class_id
        WHERE
            t.id = #{id} AND t.delete_mark = 0;
    </select>
    <select id="getSemester"
            resultType="com.xjrsoft.module.student.vo.ClassHonorsSemesterClassVo">
        select
            distinct
            t.base_semester_id,
            t1.name AS baseSemesterIdCN
        from class_honors t
                 left join base_semester t1 on t1.id = t.base_semester_id
        where
            t.delete_mark = 0;
    </select>
    <select id="getSemesterClass"
            resultType="com.xjrsoft.module.student.vo.ClassHonorsSemesterClassVo">
        select
            distinct
            t.base_semester_id,
            t.class_id,
            t1.name AS semesterName,
            t2.name AS classIdCN
        from class_honors t
                 left join base_semester t1 on t1.id = t.base_semester_id
                 left join base_class t2 on t2.id = t.class_id
        where
            t.delete_mark = 0;
    </select>
</mapper>