<?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.EduFaceGroupMapper">
    <resultMap id="pageMap" type="com.yida.data.common.core.entity.user.EduFaceGroup">
        <id property="id" column="id"/>
        <result property="groupName" column="group_name"/>
        <result property="description" column="description"/>
        <result property="issueNum" column="issue_num"/>
        <result property="totalNum" column="total_num"/>
        <result property="type" column="type"/>
        <collection column="id" property="deviceList" ofType="com.yida.data.common.core.entity.user.EduFaceGroupDevice"
                    select="selectDevice">
        </collection>
    </resultMap>
    <select id="selectDevice" resultType="com.yida.data.common.core.entity.user.EduFaceGroupDevice">
        select *
        from edu_face_group_device
        where face_group_id=#{id}
    </select>

    <select id="listFaceGroupPage" resultMap="pageMap">
        select a.id,a.group_name,a.description,a.type,
        sum(if(b.status=1,1,0)) issue_num,
        count(b.id) total_num
        from edu_face_group a
        left join edu_face_group_user b on a.id=b.face_group_id
        where a.del_flag=0
        and a.school_id=#{schoolId}
        <if test="groupName != null and groupName != ''">
            and a.group_name like concat('%',#{groupName},'%')
        </if>
        group by a.id,a.group_name,a.description,a.create_date
        order by a.create_date desc
    </select>
</mapper>
