<?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.EduAttendanceDeviceGroupMapper">
    <select id="listDeviceAndGroup" resultType="com.yida.data.attendance.vo.DeviceOrDeviceGroupVO">
        (select id,0 type,concat(name,'-',if(zone_scope=0,'进门','出门')) name
        from edu_attendance_device
        <where>
            school_id=#{schoolId}
            <if test="keyword != null and keyword != ''">
                and (
                (name like concat('%',#{keyword},'%'))
                or (sn like concat('%',#{keyword},'%'))
                )
            </if>
        </where>
        order by name)
        union all
        (select id ,1 type,group_name name
        from edu_attendance_device_group
        <where>
            del_flag = 0
            and school_id=#{schoolId}
            <if test="keyword != null and keyword != ''">
                and group_name like concat('%',#{keyword},'%')
            </if>
        </where>
        order by name)
    </select>

    <select id="listDeviceByGroup"
            resultType="com.yida.data.common.core.entity.attendance.EduAttendanceDevice">
        select b.*
        from edu_device_group a left join edu_attendance_device b on a.device_id=b.id
        where a.del_flag=0 and a.group_id in
        <foreach collection="groupIds" close=")" separator="," item="item" open="(">
            #{item}
        </foreach>
    </select>

    <select id="selectGroup" resultType="com.yida.data.common.core.entity.attendance.EduAttendanceDeviceGroup">
        select * from
        edu_attendance_device_group
        where del_flag=0
        <if test="name != null and name != ''">
            and edu_attendance_device_group.group_name like concat('%',#{name},'%')
        </if>
        and school_id in
        <foreach collection="schoolIds" item="schoolId" open="(" separator="," close=")">
            #{schoolId}
        </foreach>
        order by create_time desc
    </select>
</mapper>
