<?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.camera.mapper.EduCameraAreaGroupMapper">

  <select id="listCamera" resultType="com.yida.data.common.core.entity.camera.EduCamera">
    SELECT
    a.*
    FROM
    edu_camera a
    LEFT JOIN edu_camera_area_group_camera b ON a.id = b.camera_id
    LEFT JOIN edu_camera_authority_teacher c ON a.id = c.camera_id
    WHERE
    b.group_id = #{groupId}
    and c.staff_id = #{userId}
    <if test="deptId != null and deptId.size>0">
      or c.dept_id in
      <foreach collection="deptId" separator="," close=")" open="(" item="item">
        #{item}
      </foreach>
    </if>
    <if test="cameraCode !=null and cameraCode != ''">
      and camera_code = #{cameraCode}
    </if>
    AND a.del_flag = 0
  </select>
  <select id="findAreaGroupList" resultType="com.yida.data.common.core.entity.camera.EduCameraAreaGroup">
    SELECT
    *
    FROM
    `edu_camera_area_group`
    WHERE
    del_flag = 0
    <if test="schoolId != null">
      and school_id = #{schoolId}
    </if>
    <if test="parentId != null">
      and parent_id = #{parentId}
    </if>
    <if test="parentId == null">
      and parent_id IS NULL
    </if>
    order by sort

  </select>
  <select id="findGroup" resultType="com.yida.data.common.core.entity.camera.EduCameraAreaGroup">
    select * from edu_camera_area_group
    where del_flag = 0
    <if test="parentId ==null">
      and parent_id is null
    </if>
    <if test="parentId != null">
      and parent_id=#{parentId}
    </if>
    order by sort
  </select>
  <select id="findTreeGroup" resultType="com.yida.data.device.vo.camera.EduCameraAreaGroupVO">
    SELECT
    id,
    parent_id parentId,
    `name` as label,
    sort
    FROM
    `edu_camera_area_group`
    WHERE
    del_flag = 0
    <if test="parentId != null">
      and parent_id = #{parentId}
    </if>
    <if test="parentId == null">
      and parent_id IS NULL
    </if>
    order by sort
  </select>
</mapper>
