<?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.fs.qw.mapper.QwMaterialMapper">

    <resultMap type="QwMaterial" id="QwMaterialResult">
        <result property="id"    column="id"    />
        <result property="fileType"    column="file_type"    />
        <result property="groupId"    column="group_id"    />
        <result property="fileName"    column="file_name"    />
        <result property="fileId"    column="file_id"    />
        <result property="aesKey"    column="aes_key"    />
        <result property="md5"    column="md5"    />
        <result property="fileSize"    column="file_size"    />
        <result property="duration"    column="duration"    />
        <result property="thumbnailFileSize"    column="thumbnail_file_size"    />
        <result property="url"    column="url"    />
        <result property="companyUserId"    column="company_user_id"    />
    </resultMap>

    <sql id="selectQwMaterialVo">
        select id, file_type, group_id, file_name, file_id, aes_key, md5, file_size, duration, thumbnail_file_size, url,company_user_id from qw_material
    </sql>

    <select id="selectQwMaterialList" parameterType="QwMaterial" resultMap="QwMaterialResult">
        <include refid="selectQwMaterialVo"/>
        <where>
            <if test="fileType != null "> and file_type = #{fileType}</if>
            <if test="groupId != null "> and group_id = #{groupId}</if>
            <if test="fileName != null  and fileName != ''"> and file_name like concat('%', #{fileName}, '%')</if>
            <if test="fileId != null  and fileId != ''"> and file_id = #{fileId}</if>
            <if test="aesKey != null  and aesKey != ''"> and aes_key = #{aesKey}</if>
            <if test="md5 != null  and md5 != ''"> and md5 = #{md5}</if>
            <if test="fileSize != null "> and file_size = #{fileSize}</if>
            <if test="duration != null "> and duration = #{duration}</if>
            <if test="thumbnailFileSize != null "> and thumbnail_file_size = #{thumbnailFileSize}</if>
            <if test="companyUserId != null "> and company_user_id = #{companyUserId}</if>
            <if test="url != null  and url != ''"> and url = #{url}</if>
        </where>
    </select>

    <select id="selectQwMaterialById" parameterType="Long" resultMap="QwMaterialResult">
        <include refid="selectQwMaterialVo"/>
        where id = #{id}
    </select>

    <insert id="insertQwMaterial" parameterType="QwMaterial">
        insert into qw_material
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="fileType != null">file_type,</if>
            <if test="groupId != null">group_id,</if>
            <if test="fileName != null">file_name,</if>
            <if test="fileId != null">file_id,</if>
            <if test="aesKey != null">aes_key,</if>
            <if test="md5 != null">md5,</if>
            <if test="fileSize != null">file_size,</if>
            <if test="duration != null">duration,</if>
            <if test="thumbnailFileSize != null">thumbnail_file_size,</if>
            <if test="url != null">url,</if>
            <if test="companyUserId != null">company_user_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="fileType != null">#{fileType},</if>
            <if test="groupId != null">#{groupId},</if>
            <if test="fileName != null">#{fileName},</if>
            <if test="fileId != null">#{fileId},</if>
            <if test="aesKey != null">#{aesKey},</if>
            <if test="md5 != null">#{md5},</if>
            <if test="fileSize != null">#{fileSize},</if>
            <if test="duration != null">#{duration},</if>
            <if test="thumbnailFileSize != null">#{thumbnailFileSize},</if>
            <if test="url != null">#{url},</if>
            <if test="companyUserId != null">#{companyUserId},</if>
        </trim>
    </insert>

    <update id="updateQwMaterial" parameterType="QwMaterial">
        update qw_material
        <trim prefix="SET" suffixOverrides=",">
            <if test="fileType != null">file_type = #{fileType},</if>
            <if test="groupId != null">group_id = #{groupId},</if>
            <if test="fileName != null">file_name = #{fileName},</if>
            <if test="fileId != null">file_id = #{fileId},</if>
            <if test="aesKey != null">aes_key = #{aesKey},</if>
            <if test="md5 != null">md5 = #{md5},</if>
            <if test="fileSize != null">file_size = #{fileSize},</if>
            <if test="duration != null">duration = #{duration},</if>
            <if test="thumbnailFileSize != null">thumbnail_file_size = #{thumbnailFileSize},</if>
            <if test="url != null">url = #{url},</if>
            <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteQwMaterialById" parameterType="Long">
        delete from qw_material where id = #{id}
    </delete>

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

</mapper>
