<?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.user.mapper.EduUserDeviceMapper">
    <select id="listUserDevicesNotInList" resultType="String">
        select b.type_flag
        from
        (select a.user_id, a.user_type
        from edu_user_device a
        <where>
            device_id in
            <foreach collection="device" open="(" item="item" separator="," close=")">
                #{item}
            </foreach>
            and
            (
            <foreach collection="user" close=")" separator="or" item="item" open="(">
                a.user_id = #{item.userId} and a.user_type = #{item.userType}
            </foreach>
            )
        </where>
        group by a.user_id, a.user_type, a.device_id
        having count(1) = 1)c
        inner join edu_user_device_factory b on c.user_id = b.user_id and c.user_type = b.user_type
        where b.type_name=#{type}
    </select>
</mapper>