<?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.system.mapper.MinioFileMapper">

    <resultMap type="MinioFile" id="MinioFileResult">
        <result property="id"    column="id"    />
        <result property="flightId"    column="flightId"    />
        <result property="url"    column="url"    />
        <result property="filename"    column="filename"    />
        <result property="createdAt"    column="created_at"    />
    </resultMap>

    <sql id="selectMinioFileVo">
        select id, flightId, url, filename, created_at from minio_file
    </sql>

    <select id="selectMinioFileList" parameterType="MinioFile" resultMap="MinioFileResult">
        <include refid="selectMinioFileVo"/>
        <where>
            <if test="flightId != null "> and flightId = #{flightId}</if>
            <if test="url != null  and url != ''"> and url = #{url}</if>
            <if test="filename != null  and filename != ''"> and filename like concat('%', #{filename}, '%')</if>
            <if test="createdAt != null "> and created_at = #{createdAt}</if>
        </where>
    </select>

    <select id="selectMinioFileById" parameterType="Long" resultMap="MinioFileResult">
        <include refid="selectMinioFileVo"/>
        where id = #{id}
    </select>

    <select id="selectMinioFileName" resultMap="MinioFileResult">
        select * from minio_file where filename = #{fileName}
    </select>

    <insert id="insertMinioFile" parameterType="MinioFile">
        insert into minio_file
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="flightId != null">flightId,</if>
            <if test="url != null">url,</if>
            <if test="filename != null">filename,</if>
            <if test="createdAt != null">created_at,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="flightId != null">#{flightId},</if>
            <if test="url != null">#{url},</if>
            <if test="filename != null">#{filename},</if>
            <if test="createdAt != null">#{createdAt},</if>
         </trim>
    </insert>

    <update id="updateMinioFile" parameterType="MinioFile">
        update minio_file
        <trim prefix="SET" suffixOverrides=",">
            <if test="flightId != null">flightId = #{flightId},</if>
            <if test="url != null">url = #{url},</if>
            <if test="filename != null">filename = #{filename},</if>
            <if test="createdAt != null">created_at = #{createdAt},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteMinioFileById" parameterType="Long">
        delete from minio_file where id = #{id}
    </delete>

    <delete id="deleteMinioFileByIds" parameterType="String">
        delete from minio_file where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>
