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

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

    <select id="getGpsList" parameterType="api.common.pojo.param.model.GpsParam" resultMap="GpsVOVOMap">
        select
            id,
            sensor_name,
            description,
            share
        from model_sensor_gps
        where is_deleted = '0'
        <if test="sensorName != null and sensorName != ''">
            and sensor_name like CONCAT('%',#{sensorName,jdbcType=VARCHAR},'%')
        </if>
        <if test="share != null and share != ''">
            and create_user_id = #{createUserId,jdbcType=VARCHAR}
            and share = '0'
        </if>
        <if test="share == null or share == ''">
            and (create_user_id = #{createUserId,jdbcType=VARCHAR} or share = '1')
        </if>
        order by share asc
    </select>
    <select id="getGpsListGSy" parameterType="api.common.pojo.param.model.GpsParam" resultMap="GpsVOVOMap">
        select
        id,
        sensor_name,
        description,
        share
        from model_sensor_gps
        where is_deleted = '0'
        <if test="createUserId != null and createUserId != ''">
            and create_user_id = #{createUserId,jdbcType=VARCHAR}
        </if>
        <if test="share != null and share != ''">
            and share =  #{share}
        </if>
        order by modify_time desc
    </select>

    <select id="getGpsInfo" parameterType="api.common.pojo.param.model.GpsParam" resultMap="GpsVOVOMap">
        select
            id,
            sensor_code,
            sensor_name,
            description,
            longitude_offset,
            latitude_offset,
            frame_rate,
            share
        from model_sensor_gps c
        where c.id = #{id,jdbcType=VARCHAR} limit 1
    </select>

    <select id="checkGpsName" parameterType="api.common.pojo.po.model.GpsPO" resultMap="GpsVOVOMap">
        select
            id
        from model_sensor_gps
        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.GpsPO">
        insert into model_sensor_gps(
            id,
            sensor_code,
            sensor_name,
            description,
            longitude_offset,
            latitude_offset,
            frame_rate,
            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},
            #{longitudeOffset,jdbcType=DECIMAL},
            #{latitudeOffset,jdbcType=DECIMAL},
            #{frameRate,jdbcType=DECIMAL},
            #{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.GpsPO">
        update model_sensor_gps set
            sensor_name = #{sensorName,jdbcType=VARCHAR},
            description = #{description,jdbcType=VARCHAR},
            longitude_offset = #{longitudeOffset,jdbcType=DECIMAL},
            latitude_offset = #{latitudeOffset,jdbcType=DECIMAL},
            frame_rate = #{frameRate,jdbcType=DECIMAL},
            modify_time = #{modifyTime,jdbcType=TIMESTAMP},
            modify_user_id = #{modifyUserId,jdbcType=VARCHAR}
        where id = #{id,jdbcType=VARCHAR}
    </update>

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