<?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.ozs.mapper.BaseCameraManagementMapper">


    <select id="selectCameraManagementList" resultType="com.ozs.entity.BaseCameraManagement" parameterType="com.ozs.entity.vo.BaseCameraManagementVo">
        SELECT * FROM base_camera_management
        <where>
            <if test="railwayCode != null and railwayCode != ''">
                and railway_code = #{railwayCode}
            </if>
            <if test="lineDir != null and lineDir != 0">
                and line_dir = #{lineDir}
            </if>
            <if test="deptId != null and deptId != 0">
                and dept_id = #{deptId}
            </if>
            <if test="beginMile != null and beginMile != 0">
                and install_mile &gt;= #{beginMile}
            </if>
            <if test="endMile != null and endMile != 0">
                and install_mile &lt;= #{endMile}
            </if>
            <if test="online != null and online != 0">
                and online = #{online}
            </if>
            <if test="enableOrNot != null and enableOrNot != 0">
                and ENABLE_OR_NOT = #{enableOrNot}
            </if>
            <if test="ids != null and ids.size>0">
                and id in
                <foreach item="items" collection="ids" separator="," open="(" close=")" index="">
                    #{items}
                </foreach>
            </if>
        </where>
    </select>

    <select id="countCamera" parameterType="com.ozs.entity.vo.MsgAlarmVo" resultType="java.lang.Integer">
        select count(id) from base_camera_management
    </select>

    <select id="getMessageStatisticsCamera" resultType="java.util.Map">
        select count(id) countAllCamera,
            SUM(CASE online WHEN '2' THEN 1 ELSE 0 end) AS offlineCamera,
            SUM(CASE online WHEN '1' THEN 1 ELSE 0 end) AS onlineCamera
        from base_camera_management
    </select>

    <select id="selectSkynetHeartbeatLogByCameraCode" resultType="com.ozs.entity.SkynetHeartbeatLog" parameterType="java.lang.String">
        select /*+ GROUP_OPT_FLAG(1)*/ id, camera_code, max(create_time) as createTime from skynet_heartbeat_log where camera_code = #{cameraCode}
    </select>
</mapper>
