<?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.store.mapper.FsMaterialMapper">

    <resultMap type="FsMaterial" id="FsMaterialResult">
        <result property="materialId"    column="material_id"    />
        <result property="type"    column="type"    />
        <result property="groupId"    column="group_id"    />
        <result property="name"    column="name"    />
        <result property="url"    column="url"    />
        <result property="isDel"    column="is_del"    />
        <result property="createUserId"    column="create_user_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectFsMaterialVo">
        select material_id, type, group_id, name, url, is_del, create_user_id, create_time, update_time from fs_material
    </sql>

    <select id="selectFsMaterialList" parameterType="FsMaterial" resultMap="FsMaterialResult">
        <include refid="selectFsMaterialVo"/>
        <where>
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="groupId != null "> and group_id = #{groupId}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="url != null  and url != ''"> and url = #{url}</if>
            <if test="isDel != null "> and is_del = #{isDel}</if>
            <if test="createUserId != null "> and create_user_id = #{createUserId}</if>
        </where>
        order by material_id desc
    </select>

    <select id="selectFsMaterialById" parameterType="Long" resultMap="FsMaterialResult">
        <include refid="selectFsMaterialVo"/>
        where material_id = #{materialId}
    </select>

    <insert id="insertFsMaterial" parameterType="FsMaterial" useGeneratedKeys="true" keyProperty="materialId">
        insert into fs_material
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="type != null">type,</if>
            <if test="groupId != null">group_id,</if>
            <if test="name != null and name != ''">name,</if>
            <if test="url != null">url,</if>
            <if test="isDel != null">is_del,</if>
            <if test="createUserId != null">create_user_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="type != null">#{type},</if>
            <if test="groupId != null">#{groupId},</if>
            <if test="name != null and name != ''">#{name},</if>
            <if test="url != null">#{url},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="createUserId != null">#{createUserId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateFsMaterial" parameterType="FsMaterial">
        update fs_material
        <trim prefix="SET" suffixOverrides=",">
            <if test="type != null">type = #{type},</if>
            <if test="groupId != null">group_id = #{groupId},</if>
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="url != null">url = #{url},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
            <if test="createUserId != null">create_user_id = #{createUserId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where material_id = #{materialId}
    </update>

    <delete id="deleteFsMaterialById" parameterType="Long">
        delete from fs_material where material_id = #{materialId}
    </delete>

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

</mapper>
