<?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.yida.data.device.studentCard.mapper.EduStudentCardAlarmMapper">
  <select id="listAlarmPage" resultType="com.yida.data.device.vo.studentCard.AlarmPageVO">
    select
    a.student_id,
    a.imei,
    a.alarm_type alarmType,
    a.alarm_time alarmTime,
    a.address
    from edu_student_card_alarm a
    <where>
      <if test="dto.alarmType != null">
        and a.alarm_type = #{dto.alarmType}
      </if>
      <if test="dto.schoolId != null">
        and a.school_id = #{dto.schoolId}
      </if>
      <if test="dto.startTime != null and dto.endTime != null">
        and a.alarm_time between #{dto.startTime} and #{dto.endTime}
      </if>
      <if test="dto.keyword != null and dto.keyword != ''">
        and (a.imei like concat('%', #{dto.keyword}, '%')
        <if test="conformStudent != null and conformStudent.size() != 0">
          or a.student_id in
          <foreach collection="conformStudent" item="item" separator="," open="(" close=")">
            #{item}
          </foreach>
        </if>
        )
      </if>
      <choose>
        <when test="studentList != null and studentList.size() != 0">
          and a.student_id in
          <foreach collection="studentList" item="item" separator="," open="(" close=")">
            #{item.id}
          </foreach>
        </when>
        <otherwise>
          and 0 = 1
        </otherwise>
      </choose>
    </where>
    order by a.alarm_time desc
  </select>

  <select id="listStudentAlarmPage" resultType="com.yida.data.device.vo.studentCard.StudentAlarmVO">
    select remark,remark_value,create_date,alarm_type
    from edu_student_card_alarm
    where student_id=#{studetnId}
    order by create_date desc
  </select>
</mapper>
