<?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.StudentHonorsMapper">
    <select id="getPage" parameterType="com.xjrsoft.module.student.dto.StudentHonorsPageDto"
            resultType="com.xjrsoft.module.student.vo.StudentHonorsPageVo">
        SELECT t1.id,t1.sort_code,t2.name AS student_name,t1.student_id,t3.name AS honors_level,t4.name AS honors_type,
        t5.name AS honors_grade,t1.name, t1.award_date,t1.status,t1.file_id FROM student_honors t1
        LEFT JOIN xjr_user t2 ON t1.student_user_id = t2.id
        LEFT JOIN xjr_dictionary_detail t3 ON t1.honors_level = t3.code AND t3.item_id = 1731576278748352514
        LEFT JOIN xjr_dictionary_detail t4 ON t1.honors_type = t4.code AND t4.item_id = 1731577666295418881
        LEFT JOIN xjr_dictionary_detail t5 ON t1.honors_grade = t5.code AND t5.item_id = 1731577201793028098
        WHERE t1.delete_mark = 0
        <if test="dto.classIdList != null">
            and t1.class_id in
            <foreach item="classId" index="index" collection="dto.classIdList" open="(" close=")"
                     separator=",">
                #{classId}
            </foreach>
        </if>
        <if test="dto.classId != null and dto.classId > 0">
            AND t1.class_id = #{dto.classId}
        </if>
        <if test="dto.baseSemesterId != null and dto.baseSemesterId > 0">
            AND t1.base_semester_id = #{dto.baseSemesterId}
        </if>
        <if test="dto.honorsLevel != null and dto.honorsLevel != ''">
            AND t1.honors_level = #{dto.honorsLevel}
        </if>
        <if test="dto.honorsGrade != null and dto.honorsGrade != ''">
            AND t1.honors_grade = #{dto.honorsGrade}
        </if>
        <if test="dto.honorsType != null and dto.honorsType != ''">
            AND t1.honors_type = #{dto.honorsType}
        </if>
        <if test="dto.awardDate != null and dto.awardDate != ''">
            AND t1.award_date > #{dto.awardDate}
        </if>
        <if test="dto.userName != null and dto.userName != ''">
            AND t2.name like concat('%',#{dto.userName},'%')
        </if>
        <if test="dto.studentUserId != null and dto.studentUserId != ''">
            AND t1.student_user_id = #{dto.studentUserId}
        </if>
        and t1.status = 1
        order by t1.id desc
    </select>

    <select id="getSemesterInfo" resultType="com.xjrsoft.module.student.vo.StudentHonorsListVo">
        SELECT DISTINCT t1.base_semester_id as id, t2.name
        FROM student_honors t1
                 INNER JOIN base_semester t2 ON t1.base_semester_id = t2.id
        WHERE t1.delete_mark = 0
    </select>
    <select id="getClassInfo" resultType="com.xjrsoft.module.student.vo.StudentHonorsListVo">
        SELECT DISTINCT t1.class_id as id, t2.name, t1.base_semester_id as parent_id
        FROM student_honors t1
                 INNER JOIN base_class t2 ON t1.class_id = t2.id
        WHERE t1.delete_mark = 0
    </select>

    <select id="getInfo" resultType="com.xjrsoft.module.student.vo.StudentHonorsVo">
        SELECT t1.id,
               t2.name  AS student_name,
               t1.student_id,
               t3.grade_id,
               t4.name  AS grade_name,
               t1.class_id,
               t5.name  AS class_name,
               t1.major_set_id,
               t11.name AS major_set_name,
               t1.applicant_user_id,
               t1.name  AS applicant_user_name,
               t1.award_date,
               t1.name,
               t1.honors_level,
               t8.name  AS honors_level_cn,
               t1.honors_type,
               t9.name  AS honors_type_cn,
               t1.honors_grade,
               t10.name AS honors_grade_cn,
               t1.file_id,
               t1.base_semester_id,
               t1.student_user_id
        FROM student_honors t1
                 LEFT JOIN xjr_user t2 ON t1.student_user_id = t2.id
                 LEFT JOIN base_student_school_roll t3 ON t1.student_user_id = t3.user_id
                 LEFT JOIN base_grade t4 ON t3.grade_id = t4.id
                 LEFT JOIN base_class t5 ON t1.class_id = t5.id
                 LEFT JOIN base_major_set t6 ON t3.major_set_id = t6.id
                 LEFT JOIN xjr_user t7 ON t1.applicant_user_id = t7.id
                 LEFT JOIN xjr_dictionary_detail t8 ON t1.honors_level = t8.code AND t8.item_id = 1731576278748352514
                 LEFT JOIN xjr_dictionary_detail t9 ON t1.honors_type = t9.code AND t9.item_id = 1731577666295418881
                 LEFT JOIN xjr_dictionary_detail t10 ON t1.honors_grade = t10.code AND t10.item_id = 1731577201793028098
                 LEFT JOIN base_major_set t11 ON t1.major_set_id = t11.id
        WHERE t1.id = #{id}
          and t1.delete_mark = 0
    </select>
    <select id="getSortCode" resultType="java.lang.Integer">
        SELECT IFNULL(MAX(IFNULL(sort_code, 0)), 0) + 1
        FROM student_honors
    </select>
</mapper>