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

    <resultMap id="OgtVOMap" type="api.common.pojo.vo.model.OgtVO">
        <id column="ID" property="id" jdbcType="VARCHAR" />
    </resultMap>

    <select id="getOgtList" parameterType="api.common.pojo.param.model.OgtParam" resultMap="OgtVOMap">
        select
        id,
        sensor_name,
        description,
        share,
        fov_h_right,
        fov_h_left,
        fov_v_top,
        fov_v_bottom,
        far_distance,
        near_distance
        from model_sensor_ogt o
        where o.is_deleted = '0'
        <if test="sensorName != null and sensorName != ''">
            and o.sensor_name like CONCAT('%',#{sensorName,jdbcType=VARCHAR},'%')
        </if>
        <if test="share != null and share != ''">
            and o.create_user_id = #{createUserId,jdbcType=VARCHAR}
            and o.share = '0'
        </if>
        <if test="share == null or share == ''">
            and (o.create_user_id = #{createUserId,jdbcType=VARCHAR} or o.share = '1')
        </if>
        order by share asc
    </select>

    <select id="getOgtInfo" parameterType="api.common.pojo.param.model.OgtParam" resultMap="OgtVOMap">
        select
            id,
            sensor_code,
            sensor_name,
            description,
            near_distance,
            far_distance,
            fov_h_left,
            fov_h_right,
            fov_v_top,
            fov_v_bottom,
            range_display,
            max_objects,
            coordinate_system,
            target_filter,
            share
        from model_sensor_ogt o
        where o.id = #{id,jdbcType=VARCHAR} limit 1
    </select>

    <select id="checkOgtName" parameterType="api.common.pojo.po.model.OgtPO" resultMap="OgtVOMap">
        select
            id
        from model_sensor_ogt
        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.OgtPO">
        insert into model_sensor_ogt(
            id,
            sensor_code,
            sensor_name,
            description,
            near_distance,
            far_distance,
            fov_h_left,
            fov_h_right,
            fov_v_top,
            fov_v_bottom,
            range_display,
            max_objects,
            coordinate_system,
            target_filter,
            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},
            #{fovHLeft,jdbcType=DECIMAL},
            #{fovHRight,jdbcType=DECIMAL},
            #{fovVTop,jdbcType=DECIMAL},
            #{fovVBottom,jdbcType=DECIMAL},
            #{rangeDisplay,jdbcType=VARCHAR},
            #{maxObjects,jdbcType=INTEGER},
            #{coordinateSystem,jdbcType=VARCHAR},
            #{targetFilter,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.OgtPO">
        update model_sensor_ogt set
            sensor_name = #{sensorName,jdbcType=VARCHAR},
            description = #{description,jdbcType=VARCHAR},
            near_distance = #{nearDistance,jdbcType=DECIMAL},
            far_distance = #{farDistance,jdbcType=DECIMAL},
            fov_h_left = #{fovHLeft,jdbcType=DECIMAL},
            fov_h_right = #{fovHRight,jdbcType=DECIMAL},
            fov_v_top = #{fovVTop,jdbcType=DECIMAL},
            fov_v_bottom = #{fovVBottom,jdbcType=DECIMAL},
            range_display = #{rangeDisplay,jdbcType=VARCHAR},
            max_objects = #{maxObjects,jdbcType=INTEGER},
            coordinate_system = #{coordinateSystem,jdbcType=VARCHAR},
            target_filter = #{targetFilter,jdbcType=VARCHAR},

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

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