<?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.attendance.mapper.AttendanceRecordMapper">


  <select id="listOldDataPage" resultType="com.yida.data.common.core.entity.attendance.EduAttendanceRecord">
    select *
    from edu_attendance_record
    where school_id = #{schoolId}
      and create_time > #{startDateTime}
    order by create_time
  </select>

  <select id="listStaffOldDataPage" resultType="com.yida.data.common.core.entity.attendance.EduAttendanceStaffRecord">
    select *
    from edu_attendance_staff_record
    where school_id = #{schoolId}
      and create_time > #{startDateTime}
    order by create_time
  </select>

  <select id="listRecordPage" resultType="com.yida.data.common.core.entity.attendance.attendance.AttendanceRecord">
    SELECT * FROM attendance_record
    <where>
      <if test="dto.userId != null">
        and user_id = #{dto.userId}
      </if>
      <if test="dto.studentName != null and dto.studentName != ''">
        and user_name like concat('%',#{dto.studentName},'%')
      </if>
      <if test="dto.startDateTime!=null">
        and create_time  <![CDATA[>=]]> #{dto.startDateTime}
      </if>
      <if test="dto.endDateTime!=null">
        and create_time  <![CDATA[<=]]> #{dto.endDateTime}
      </if>
      <if test="dto.userType!=null">
        and user_type = #{dto.userType}
      </if>
      <if test="dto.schoolId!=null">
        and school_id = #{dto.schoolId}
      </if>
      <if test="dto.campusId!=null">
        and campus_id = #{dto.campusId}
      </if>
      <if test="dto.sectionId!=null">
        and section_id = #{dto.sectionId}
      </if>
      <if test="dto.gradeId!=null">
        and grade_id = #{dto.gradeId}
      </if>
      <if test="dto.classId!=null">
        and class_id = #{dto.classId}
      </if>
      <if test="dto.classIdList!=null and dto.classIdList.size()>0">
        AND class_id IN
        <foreach collection="dto.classIdList" item="item" separator="," close=")" open="(">
          #{item}
        </foreach>
      </if>
      <if test="dto.type==0">
        and device_id is not null
      </if>
      <if test="dto.type==1">
        and wifi_id is not null
      </if>
      <if test="dto.userIdList!=null and dto.userIdList.size()>0">
        AND user_id IN
        <foreach collection="dto.userIdList" item="item" separator="," close=")" open="(">
          #{item}
        </foreach>
      </if>
    </where>
    order by create_time desc
  </select>


</mapper>
