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

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

    <select id="getLidarList" parameterType="api.common.pojo.param.model.LidarParam" resultMap="LidarVOMap">
        select
        id,
        sensor_name,
        description,
        share,
        fov_h,
        fov_v,
        far_distance,
        near_distance
        from model_sensor_lidar l
        where l.is_deleted = '0'
        <if test="sensorName != null and sensorName != ''">
            and l.sensor_name like CONCAT('%',#{sensorName,jdbcType=VARCHAR},'%')
        </if>
        <if test="share != null and share != ''">
            and l.create_user_id = #{createUserId,jdbcType=VARCHAR}
            and l.share = '0'
        </if>
        <if test="share == null or share == ''">
            and (l.create_user_id = #{createUserId,jdbcType=VARCHAR} or l.share = '1')
        </if>
        order by share asc
    </select>
    <select id="getLidarListGSy" parameterType="api.common.pojo.param.model.LidarParam" resultMap="LidarVOMap">
        select
        id,
        sensor_name,
        description,
        share,
        fov_h,
        fov_v,
        far_distance,
        near_distance
        from model_sensor_lidar l
        where l.is_deleted = '0'
        <if test="createUserId != null and createUserId != ''">
            and l.create_user_id = #{createUserId,jdbcType=VARCHAR}
        </if>
        <if test="share != null and share != ''">
            and l.share = #{share}
        </if>
        order by l.modify_time desc
    </select>

    <select id="getLidarInfo" parameterType="api.common.pojo.param.model.LidarParam" resultMap="LidarVOMap">
        select
            id,
            sensor_code,
            sensor_name,
            description,
            near_distance,
            far_distance,
            fov_h,
            fov_v,
            line_number,
            frame_rate,
            output_points,
            output_mode,
            share
        from model_sensor_lidar l
        where l.id = #{id,jdbcType=VARCHAR} limit 1
    </select>

    <select id="checkLidarName" parameterType="api.common.pojo.po.model.LidarPO" resultMap="LidarVOMap">
        select
            id
        from model_sensor_lidar
        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.LidarPO">
        insert into model_sensor_lidar(
            id,
            sensor_code,
            sensor_name,
            description,
            near_distance,
            far_distance,
            fov_h,
            fov_v,
            line_number,
            frame_rate,
            output_points,
            output_mode,
            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},
            #{lineNumber,jdbcType=INTEGER},
            #{frameRate,jdbcType=DECIMAL},
            #{outputPoints,jdbcType=INTEGER},
            #{outputMode,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.LidarPO">
        update model_sensor_lidar 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},
            line_number = #{lineNumber,jdbcType=INTEGER},
            frame_rate = #{frameRate,jdbcType=DECIMAL},
            output_points = #{outputPoints,jdbcType=INTEGER},
            output_mode = #{outputMode,jdbcType=VARCHAR},

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

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