<?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="cn.edu.whu.boot.collection.mapper.MultimediaMapper">
    <resultMap id="multimediaItemResultMap" type="cn.edu.whu.boot.collection.domain.MultimediaItem">
        <result column="media_id" property="mediaID"/>
        <result column="id" property="ID"/>
        <result column="file" property="file"/>
        <result column="azimuth" property="azimuth"/>
        <result column="satellites" property="satellites"/>
        <result column="longitude" property="longitude"/>
        <result column="latitude" property="latitude"/>
        <result column="altitude" property="altitude"/>
        <result column="accuracy" property="accuracy"/>
        <result column="camera_angle" property="cameraAngle"/>
        <result column="camera_pitch" property="cameraPitch"/>
        <result column="camera_roll" property="cameraRoll"/>
        <result column="method" property="method"/>
        <result column="time" property="time"/>
        <result column="focal_length" property="focalLength"/>
        <result column="type" property="type"/>
        <result column="version" property="version"/>
        <result column="media_path" property="mediaPath"/>
    </resultMap>

    <!--插入多媒体信息-->
    <insert id="insertMultiMedia" parameterType="cn.edu.whu.boot.collection.domain.MultimediaItem"
            useGeneratedKeys="true" keyProperty="mediaID">
        INSERT INTO ${mediaTableName}(id, file, media_path, azimuth, satellites, longitude, latitude, altitude, accuracy,
        camera_angle, camera_pitch, camera_roll, method, time, focal_length,type,version)
        VALUES (#{ID,jdbcType=INTEGER},
        #{file,jdbcType=VARCHAR},
        #{mediaPath,jdbcType=VARCHAR},
        #{azimuth,jdbcType=NUMERIC},
        #{satellites,jdbcType=INTEGER},
        #{longitude,jdbcType=NUMERIC},
        #{latitude,jdbcType=NUMERIC},
        #{altitude,jdbcType=NUMERIC},
        #{accuracy,jdbcType=NUMERIC},
        #{cameraAngle,jdbcType=NUMERIC},
        #{cameraPitch,jdbcType=NUMERIC},
        #{cameraRoll,jdbcType=NUMERIC},
        #{method,jdbcType=VARCHAR},
        #{time,jdbcType=VARCHAR},
        #{focalLength,jdbcType=NUMERIC},
        #{type,jdbcType=NUMERIC},
        #{version,jdbcType=INTEGER})
    </insert>

    <delete id="deleteMulitMedia">
        DELETE FROM ${mediaTableName}
        WHERE id = #{polygonId}
    </delete>

    <delete id="deleteMulitMediaGreaterThanVersion">
        DELETE FROM ${mediaTableName}
        WHERE id = #{polygonId} AND version >= #{version}
    </delete>

    <select id="selectMultiMedia" resultMap="multimediaItemResultMap">
        SELECT * FROM ${mediaTableName}
        WHERE id = #{polygonId}
    </select>

    <select id="selectHistoryMultiMedia" resultMap="multimediaItemResultMap">
        SELECT * FROM ${mediaTableName}
        WHERE id = #{polygonId} and version = #{version}
    </select>

    <select id="selectByTableName" resultType="cn.edu.whu.boot.collection.domain.ExportMediaRecord">
        SELECT *
        FROM ${tableName}
    </select>
</mapper>