<?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.css.simulation.resource.server.infra.db.mysql.mapper.CameraMapper">

    <resultMap id="CameraVOMap" type="api.common.pojo.vo.model.CameraVO">
        <id column="ID" property="id" jdbcType="VARCHAR"/>
        <result column="sensor_code" property="sensorCode" jdbcType="VARCHAR"/>
        <result column="sensor_name" property="sensorName" jdbcType="VARCHAR"/>
        <result column="description" property="description" jdbcType="VARCHAR"/>
        <result column="near_distance" property="nearDistance" jdbcType="DECIMAL"/>
        <result column="far_distance" property="farDistance" jdbcType="DECIMAL"/>
        <result column="fov_h" property="fovH" jdbcType="DECIMAL"/>
        <result column="fov_v" property="fovV" jdbcType="DECIMAL"/>
        <result column="resolution" property="resolution" jdbcType="VARCHAR"/>
        <result column="frame_rate" property="frameRate" jdbcType="DECIMAL"/>
        <result column="self_display" property="selfDisplay" jdbcType="VARCHAR"/>
        <result column="share" property="share" jdbcType="VARCHAR"/>

    </resultMap>

    <select id="getCameraList" parameterType="api.common.pojo.param.model.CameraParam" resultMap="CameraVOMap">
        select
        id,
        sensor_name,
        description,
        fov_h,
        fov_v,
        far_distance,
        near_distance,
        share
        from model_sensor_camera c
        where c.is_deleted = '0'
        <if test="sensorName != null and sensorName != ''">
            and c.sensor_name like CONCAT('%',#{sensorName,jdbcType=VARCHAR},'%')
        </if>
        <if test="share != null and share != ''">
            and c.create_user_id = #{createUserId,jdbcType=VARCHAR}
            and c.share = '0'
        </if>
        <if test="share == null or share == ''">
            and (c.create_user_id = #{createUserId,jdbcType=VARCHAR} or c.share = '1')
        </if>
        order by share asc
    </select>


    <select id="getCameraListGy"  resultMap="CameraVOMap">
        select
        id,
        sensor_name,
        description,
        fov_h,
        fov_v,
        far_distance,
        near_distance,
        share
        from model_sensor_camera c
        where c.is_deleted = '0'
       and c.share = '1'
        order by c.modify_time desc
    </select>

    <select id="getCameraListSy" parameterType="api.common.pojo.param.model.CameraParam" resultMap="CameraVOMap">
        select
        id,
        sensor_name,
        description,
        fov_h,
        fov_v,
        far_distance,
        near_distance,
        share
        from model_sensor_camera c
        where c.is_deleted = '0'
        <if test="createUserId != null and createUserId != ''">
            and c.create_user_id = #{createUserId,jdbcType=VARCHAR}
            and c.share = '0'
        </if>
        order by c.modify_time desc
    </select>

    <select id="getCameraInfo" parameterType="api.common.pojo.param.model.CameraParam" resultMap="CameraVOMap">
        select id,
               sensor_code,
               sensor_name,
               description,
               near_distance,
               far_distance,
               fov_h,
               fov_v,
               resolution,
               frame_rate,
               self_display,
               share
        from model_sensor_camera c
        where c.id = #{id,jdbcType=VARCHAR} limit 1
    </select>

    <select id="checkCameraName" parameterType="api.common.pojo.po.model.CameraPO" resultMap="CameraVOMap">
        select
        id
        from model_sensor_camera
        where is_deleted = '0'
        and sensor_name = #{sensorName,jdbcType=VARCHAR}
        <if test="share != null and share != ''">
            and share = #{share,jdbcType=VARCHAR}
        </if>
        <if test="createUserId != null and createUserId != ''">
            and create_user_id = #{createUserId,jdbcType=VARCHAR}
            and id &lt;&gt; #{id,jdbcType=VARCHAR}
        </if>
    </select>

    <insert id="insert" parameterType="api.common.pojo.po.model.CameraPO">
        insert into model_sensor_camera(id,
                                        sensor_code,
                                        sensor_name,
                                        description,
                                        near_distance,
                                        far_distance,
                                        fov_h,
                                        fov_v,
                                        resolution,
                                        frame_rate,
                                        self_display,
                                        share,
                                        create_time,
                                        modify_time,
                                        create_user_id,
                                        modify_user_id,
                                        is_deleted)
        values (#{id,jdbcType=VARCHAR},
                #{sensorCode,jdbcType=VARCHAR},
                #{sensorName,jdbcType=VARCHAR},
                #{description,jdbcType=VARCHAR},
                #{nearDistance,jdbcType=DECIMAL},
                #{farDistance,jdbcType=DECIMAL},
                #{fovH,jdbcType=DECIMAL},
                #{fovV,jdbcType=DECIMAL},
                #{resolution,jdbcType=VARCHAR},
                #{frameRate,jdbcType=DECIMAL},
                #{selfDisplay,jdbcType=VARCHAR},
                #{share,jdbcType=VARCHAR},
                #{createTime,jdbcType=TIMESTAMP},
                #{modifyTime,jdbcType=TIMESTAMP},
                #{createUserId,jdbcType=VARCHAR},
                #{modifyUserId,jdbcType=VARCHAR},
                #{isDeleted,jdbcType=VARCHAR})
    </insert>

    <update id="update" parameterType="api.common.pojo.po.model.CameraPO">
        update model_sensor_camera
        set sensor_name    = #{sensorName,jdbcType=VARCHAR},
            description    = #{description,jdbcType=VARCHAR},
            near_distance  = #{nearDistance,jdbcType=DECIMAL},
            far_distance   = #{farDistance,jdbcType=DECIMAL},
            fov_h          = #{fovH,jdbcType=DECIMAL},
            fov_v          = #{fovV,jdbcType=DECIMAL},
            resolution     = #{resolution,jdbcType=VARCHAR},
            frame_rate     = #{frameRate,jdbcType=DECIMAL},
            self_display   = #{selfDisplay,jdbcType=VARCHAR},

            modify_time    = #{modifyTime,jdbcType=TIMESTAMP},
            modify_user_id = #{modifyUserId,jdbcType=VARCHAR}
        where id = #{id,jdbcType=VARCHAR}
    </update>

    <update id="delCameraById" parameterType="api.common.pojo.po.model.CameraPO">
        update model_sensor_camera
        set modify_time    = #{modifyTime,jdbcType=TIMESTAMP},
            modify_user_id = #{modifyUserId,jdbcType=VARCHAR},
            is_deleted     = #{isDeleted,jdbcType=VARCHAR}
        where id = #{id,jdbcType=VARCHAR}
    </update>
</mapper>
