<?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.ematou.wxservice.mapper.MaterialMapper">

    <sql id="Base_Column_List">
        media_id,
        file_name,
        file_size,
        file_path,
        file_type,
        creator_id,
        create_time,
        moder_id,
        mod_time
    </sql>

    <insert id="insertMaterial" >
        insert into mp_material ( <include refid="Base_Column_List"/> )
        values (#{material.mediaId},
                #{material.fileName},
                #{material.fileSize},
                #{material.filePath},
                #{material.fileType},
                #{material.creatorId},
                #{material.createTime},
                #{material.moderId},
                #{material.modTime}
        )
    </insert>


    <update id="updateMaterial">
        update mp_material
        <set>
            <if test="material.mediaId != null">
                media_id=#{material.mediaId},
            </if>
            <if test="material.fileName != null">
                file_name=#{material.fileName},
            </if>
            <if test="material.fileSize != null">
                file_size=#{material.fileSize},
            </if>
            <if test="material.filePath != null">
                file_path=#{material.filePath},
            </if>
            <if test="material.fileType != null">
                file_type=#{material.fileType},
            </if>
            <if test="material.moderId != null">
                moder_id=#{material.moderId},
            </if>
            <if test="material.modTime != null">
                mod_time=#{material.modTime},
            </if>
            <if test="material.tmst != null">
                tmst=#{material.tmst},
            </if>
        </set>
        <if test="material.id">
            where id=#{material.id}
        </if>
    </update>

    <select id="queryMaterialByFileName" resultType="com.ematou.wxservice.entity.pojo.Material">
        select
        <include refid="Base_Column_List"/>
        from mp_material
        where 1=1
        <if test="fileName != null">
            and file_name = #{fileName}
        </if>
    </select>

    <select id="queryMaterialByMediaId" resultType="com.ematou.wxservice.entity.pojo.Material">
        select <include refid="Base_Column_List"/>
            from mp_material
        where media_id=#{mediaId}
    </select>


    <delete id="deleteMaterialByMediaId" >
        delete from mp_material
        where media_id=#{mediaId}
    </delete>

</mapper>
