<?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.EduCameraMapper">

	<!-- 分页查询设备列表 -->
    <select id="listCamera" resultType="com.yida.data.device.vo.camera.ListCameraVO">
    SELECT
        a.*,
        a.camera_code as code,
        c.`name` as area_name,
        c.id as area_group_id
    FROM
	`edu_camera` a
	LEFT JOIN edu_camera_area_group_camera b on a.id = b.camera_id
    LEFT JOIN edu_camera_area_group c ON b.group_id = c.id
    WHERE
		a.del_flag = 0
	AND a.school_id = #{dto.schoolId}
	<if test="dto.openStatus != null">
        AND a.open_status = #{dto.openStatus}
    </if>
	<if test="dto.runStatus != null">
        AND a.run_status = #{dto.runStatus}
    </if>
	<if test="dto.areaGroupId != null">
        AND b.group_id = #{dto.areaGroupId}
    </if>
	<if test="dto.commonType != null">
		AND a.common_type = #{dto.commonType}
	</if>
	<if test="dto.cameraName != null and dto.cameraName != ''">
		and a.camera_name like concat('%',#{dto.cameraName},'%')
	</if>
    <if test="dto.code != null and dto.code != ''">
        and a.camera_code like concat('%',#{dto.code},'%')
    </if>
	order by a.create_date desc
    </select>
	
    <select id="findCamera" resultType="com.yida.data.device.vo.camera.ListCameraVO">
    SELECT
	a.*,
	a.camera_code as code,
	c.name as area_name,
	c.id as area_group_id
    FROM
	edu_camera a
	LEFT JOIN edu_camera_area_group_camera b ON a.id = b.camera_id
	LEFT JOIN edu_camera_area_group c ON b.group_id = c.id
    WHERE
	a.id = #{id}
	and a.del_flag = 0
    </select>
</mapper>
