<?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.QwMaterialGroupMapper">

    <resultMap type="QwMaterialGroup" id="QwMaterialGroupResult">
        <result property="groupId"    column="group_id"    />
        <result property="name"    column="name"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="createUserId"    column="create_user_id"    />
        <result property="isDel"    column="is_del"    />
    </resultMap>

    <sql id="selectQwMaterialGroupVo">
        select group_id, name, create_time, update_time, create_user_id, is_del from qw_material_group
    </sql>

    <select id="selectQwMaterialGroupList" parameterType="QwMaterialGroup" resultMap="QwMaterialGroupResult">
        <include refid="selectQwMaterialGroupVo"/>
        <where>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="createUserId != null "> and create_user_id = #{createUserId}</if>
            <if test="isDel != null "> and is_del = #{isDel}</if>
        </where>
    </select>

    <select id="selectQwMaterialGroupById" parameterType="Long" resultMap="QwMaterialGroupResult">
        <include refid="selectQwMaterialGroupVo"/>
        where group_id = #{groupId}
    </select>

    <insert id="insertQwMaterialGroup" parameterType="QwMaterialGroup" useGeneratedKeys="true" keyProperty="groupId">
        insert into qw_material_group
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null">name,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createUserId != null">create_user_id,</if>
            <if test="isDel != null">is_del,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null">#{name},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createUserId != null">#{createUserId},</if>
            <if test="isDel != null">#{isDel},</if>
        </trim>
    </insert>

    <update id="updateQwMaterialGroup" parameterType="QwMaterialGroup">
        update qw_material_group
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="createUserId != null">create_user_id = #{createUserId},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
        </trim>
        where group_id = #{groupId}
    </update>

    <delete id="deleteQwMaterialGroupById" parameterType="Long">
        delete from qw_material_group where group_id = #{groupId}
    </delete>

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

</mapper>
