<?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.miaxis.app.report.mapper.ReportImagesMapper">
    
    <resultMap type="ReportImages" id="ReportImagesResult">
        <result property="id"    column="id"    />
        <result property="reportId"    column="report_id"    />
        <result property="fileUrl"    column="file_url"    />
        <result property="filePath"    column="file_path"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectReportImagesVo">
        select id, report_id, file_url, file_path, create_time, update_time from report_images
    </sql>

    <select id="selectReportImagesList" parameterType="ReportImages" resultMap="ReportImagesResult">
        <include refid="selectReportImagesVo"/>
        <where>  
            <if test="reportId != null "> and report_id = #{reportId}</if>
            <if test="fileUrl != null  and fileUrl != ''"> and file_url = #{fileUrl}</if>
            <if test="filePath != null  and filePath != ''"> and file_path = #{filePath}</if>
        </where>
    </select>
    
    <select id="selectReportImagesById" parameterType="Long" resultMap="ReportImagesResult">
        <include refid="selectReportImagesVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertReportImages" parameterType="ReportImages" useGeneratedKeys="true" keyProperty="id">
        insert into report_images
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="reportId != null">report_id,</if>
            <if test="fileUrl != null">file_url,</if>
            <if test="filePath != null">file_path,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="reportId != null">#{reportId},</if>
            <if test="fileUrl != null">#{fileUrl},</if>
            <if test="filePath != null">#{filePath},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateReportImages" parameterType="ReportImages">
        update report_images
        <trim prefix="SET" suffixOverrides=",">
            <if test="reportId != null">report_id = #{reportId},</if>
            <if test="fileUrl != null">file_url = #{fileUrl},</if>
            <if test="filePath != null">file_path = #{filePath},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteReportImagesById" parameterType="Long">
        delete from report_images where id = #{id}
    </delete>

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