<?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.BaseStudentPunishmentInfoMapper">
    <select id="getPage" parameterType="com.xjrsoft.module.student.dto.BaseStudentPunishmentInfoPageDto"
            resultType="com.xjrsoft.module.student.vo.BaseStudentPunishmentInfoPageVo">
        SELECT t.id,
        t1.name AS baseSemesterName,
        t2.punishment_type AS punishmentType,
        t3.name AS className,
        t.start_time,
        t.end_time,
        t.is_publicity,
        t.push_message_object,
        t.reason
        FROM base_student_punishment_info t
        INNER JOIN base_punishment_type t2 ON (t.delete_mark = 0
        <if test="dto.semesterId != null and dto.semesterId > 0">
            and t.base_semester_id = #{dto.semesterId}
        </if>
        <if test="dto.punishmentTypeId != null and dto.punishmentTypeId > 0">
            and t.punishment_type_id = #{dto.punishmentTypeId}
        </if>
        <if test="dto.startTime != null and dto.startTime != ''">
            and t.start_time = #{dto.startTime}
        </if>
        <if test="dto.endTime != null and dto.endTime != ''">
            and t.end_time = #{dto.endTime}
        </if>
            AND t2.id = t.punishment_type_id)
        LEFT JOIN base_semester t1 ON (t1.id = t.base_semester_id)
        LEFT JOIN base_class t3 ON (t3.id = t.class_id)
        ORDER BY t.id DESC;
    </select>

    <select id="getMobilePage" parameterType="com.xjrsoft.module.student.dto.BaseStudentPunishmentInfoMobilePageDto"
            resultType="com.xjrsoft.module.student.vo.BaseStudentPunishmentInfoMobilePageVo">
        SELECT t.id,t3.name AS student_name,t3.gender,t3.credential_number,t4.punishment_type,t1.reason,t1.start_time
        FROM base_punishment_student_relation t
        INNER JOIN base_student_punishment_info t1 ON t.punishment_info_id = t1.id
        INNER JOIN base_student_school_roll t2 ON t.user_id = t2.user_id
        INNER JOIN xjr_user t3 ON t.user_id = t3.id
        LEFT JOIN base_punishment_type t4 ON t1.punishment_type_id = t4.id
        LEFT JOIN base_class t5 ON t2.class_id = t5.id
        WHERE t1.status = 1 AND t1.delete_mark = 0 AND t3.delete_mark = 0 AND t2.delete_mark = 0
        AND t5.id IN (SELECT id FROM base_class WHERE teacher_id = #{dto.teacherId})
        <if test="dto.punishmentTypeIds != null and dto.punishmentTypeIds.size() > 0">
            AND t4.id in
            <foreach item="punishmentTypeId" index="index" collection="dto.punishmentTypeIds" open="(" close=")"
                     separator=",">
                #{punishmentTypeId}
            </foreach>
        </if>
        <if test="dto.startDate != null and dto.startDate != ''">
            and t1.start_time &gt;= #{dto.startDate}
        </if>
        <if test="dto.endDate != null and dto.endDate != ''">
            and t1.start_time &lt;= #{dto.endDate}
        </if>
        <if test="dto.isHandle != null">
            and t.adjust_type is not null
        </if>
        <if test="dto.studentName != null and dto.studentName != ''">
            and t.name like concat('$',#{dto.studentName},'%')
        </if>
    </select>

    <select id="getMobileInfo" parameterType="com.xjrsoft.module.student.dto.BaseStudentPunishmentInfoMobileDetailDto"
            resultType="com.xjrsoft.module.student.vo.BaseStudentPunishmentInfoMobileDetailVo">
        SELECT t.id,
               t3.name as student_name,
               t3.gender,
               t3.credential_number,
               t4.punishment_type,
               t1.reason,
               t1.start_time,
               t5.student_id,
               t.adjust_date,
               t.adjust_type,
               t.adjust_reason,
               t.modify_date,
               t1.create_date,
               t1.is_publicity,
               t1.end_time,
               t.class_name,
               t.major
        FROM base_punishment_student_relation t
                 INNER JOIN base_student_punishment_info t1 ON t.punishment_info_id = t1.id
                 INNER JOIN base_student_school_roll t2 ON t.user_id = t2.user_id
                 INNER JOIN xjr_user t3 ON t.user_id = t3.id
                 INNER JOIN base_student t5 ON t5.user_id = t.user_id
                 LEFT JOIN base_punishment_type t4 ON t1.punishment_type_id = t4.id
        WHERE t1.status = 1
          AND t1.delete_mark = 0
          AND t3.delete_mark = 0
          AND t2.delete_mark = 0
          and t.id = #{dto.id}
    </select>

    <select id="getInfo"
            resultType="com.xjrsoft.module.student.vo.BaseStudentPunishmentInfoDetailVo">
        SELECT t.id,
               t1.name            AS baseSemesterName,
               t2.punishment_type AS punishmentType,
               t3.name            AS className,
               t.start_time,
               t.end_time,
               t.is_publicity,
               t.push_message_object,
               t.reason,
               t.file_id
        FROM base_student_punishment_info t
                 INNER JOIN base_punishment_type t2 ON (t.id = #{id} AND t.delete_mark = 0 AND t2.id = t.punishment_type_id)
                 LEFT JOIN base_semester t1 ON (t1.id = t.base_semester_id)
                 LEFT JOIN base_class t3 ON (t3.id = t.class_id)
    </select>

</mapper>