<?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.ruoyi.robot.mapper.LdMapProjectMapper">

    <resultMap type="com.ruoyi.robot.domain.LdMapProject" id="LdMapProjectResult">
        <result property="id" column="id"/>
        <result property="mapName" column="map_name"/>
        <result property="displayName" column="display_name"/>
        <result property="status" column="status"/>
        <result property="thumbnailPath" column="thumbnail_path"/>
        <result property="thumbnailUrl" column="thumbnail_url"/>
        <result property="description" column="description"/>
        <result property="fileSize" column="file_size"/>
        <result property="isCurrent" column="is_current"/>
        <result property="deviceId" column="device_id"/>
        <result property="source" column="source"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <resultMap type="com.ruoyi.robot.domain.vo.LdMapListVo" id="LdMapListVoResult">
        <result property="mapName" column="map_name"/>
        <result property="status" column="status"/>
    </resultMap>

    <sql id="selectLdMapProjectVo">
        select id, map_name, display_name, status, thumbnail_path, thumbnail_url,
               description, file_size, is_current, device_id, source,
               create_by, create_time, update_by, update_time, remark
        from ld_map_project
    </sql>
    <insert id="insertLdMapProject" parameterType="com.ruoyi.robot.domain.LdMapProject" useGeneratedKeys="true" keyProperty="id">
        insert into ld_map_project
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="mapName != null and mapName != ''">map_name,</if>
            <if test="displayName != null">display_name,</if>
            <if test="status != null and status != ''">status,</if>
            <if test="thumbnailPath != null">thumbnail_path,</if>
            <if test="thumbnailUrl != null">thumbnail_url,</if>
            <if test="description != null">description,</if>
            <if test="fileSize != null">file_size,</if>
            <if test="isCurrent != null">is_current,</if>
            <if test="deviceId != null">device_id,</if>
            <if test="source != null">source,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="mapName != null and mapName != ''">#{mapName},</if>
            <if test="displayName != null">#{displayName},</if>
            <if test="status != null and status != ''">#{status},</if>
            <if test="thumbnailPath != null">#{thumbnailPath},</if>
            <if test="thumbnailUrl != null">#{thumbnailUrl},</if>
            <if test="description != null">#{description},</if>
            <if test="fileSize != null">#{fileSize},</if>
            <if test="isCurrent != null">#{isCurrent},</if>
            <if test="deviceId != null">#{deviceId},</if>
            <if test="source != null">#{source},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
        </trim>
    </insert>

    <update id="updateLdMapProject" parameterType="com.ruoyi.robot.domain.LdMapProject">
        update ld_map_project
        <trim prefix="SET" suffixOverrides=",">
            <if test="mapName != null and mapName != ''">map_name = #{mapName},</if>
            <if test="displayName != null">display_name = #{displayName},</if>
            <if test="status != null and status != ''">status = #{status},</if>
            <if test="thumbnailPath != null">thumbnail_path = #{thumbnailPath},</if>
            <if test="thumbnailUrl != null">thumbnail_url = #{thumbnailUrl},</if>
            <if test="description != null">description = #{description},</if>
            <if test="fileSize != null">file_size = #{fileSize},</if>
            <if test="isCurrent != null">is_current = #{isCurrent},</if>
            <if test="deviceId != null">device_id = #{deviceId},</if>
            <if test="source != null">source = #{source},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where map_name = #{mapName}
    </update>

    <select id="selectMapListVo" resultMap="LdMapListVoResult">
        select map_name, status
        from ld_map_project
        where status != 'deleted'
        order by is_current desc, update_time desc
    </select>

    <select id="selectCurrentMapByDeviceId" resultMap="LdMapProjectResult">
        <include refid="selectLdMapProjectVo"/>
        where is_current = 1
        <if test="deviceId != null and deviceId != ''">
            and device_id = #{deviceId}
        </if>
        limit 1
    </select>

    <select id="selectByMapName" resultMap="LdMapProjectResult">
        <include refid="selectLdMapProjectVo"/>
        where map_name = #{mapName}
    </select>

</mapper>
