<?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="materialGroupId"    column="material_group_id"    />
        <result property="materialGroupName"    column="material_group_name"    />
        <result property="companyId"    column="company_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="groupType"    column="group_type"    />
        <result property="createUserId"    column="create_user_id"    />
        <result property="corpId"    column="corp_id"    />
    </resultMap>

    <sql id="selectQwMaterialGroupVo">
        select material_group_id, material_group_name, company_id, create_time, update_time,group_type,create_user_id, corp_id from qw_material_group
    </sql>

    <select id="selectQwMaterialGroupList" parameterType="QwMaterialGroup" resultMap="QwMaterialGroupResult">
        <include refid="selectQwMaterialGroupVo"/>
        <where>
            <if test="materialGroupName != null  and materialGroupName != ''"> and material_group_name like concat('%', #{materialGroupName}, '%')</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="createUserId != null "> and create_user_id = #{createUserId}</if>
            <if test="groupType != null "> and group_type = #{groupType}</if>
            <if test="corpId != null "> and corp_id = #{corpId}</if>
        </where>
    </select>

    <select id="selectQwMaterialGroupByMaterialGroupId" parameterType="Long" resultMap="QwMaterialGroupResult">
        <include refid="selectQwMaterialGroupVo"/>
        where material_group_id = #{materialGroupId}
    </select>

    <insert id="insertQwMaterialGroup" parameterType="QwMaterialGroup">
        insert into qw_material_group
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="materialGroupId != null">material_group_id,</if>
            <if test="materialGroupName != null">material_group_name,</if>
            <if test="companyId != null">company_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="groupType != null">group_type,</if>
            <if test="createUserId != null">create_user_id,</if>
            <if test="corpId != null">corp_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="materialGroupId != null">#{materialGroupId},</if>
            <if test="materialGroupName != null">#{materialGroupName},</if>
            <if test="companyId != null">#{companyId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="groupType != null">#{groupType},</if>
            <if test="createUserId != null">#{createUserId},</if>
            <if test="corpId != null">#{corpId},</if>
         </trim>
    </insert>

    <update id="updateQwMaterialGroup" parameterType="QwMaterialGroup">
        update qw_material_group
        <trim prefix="SET" suffixOverrides=",">
            <if test="materialGroupName != null">material_group_name = #{materialGroupName},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="groupType != null">group_type = #{groupType},</if>
            <if test="createUserId != null">create_user_id = #{createUserId},</if>
            <if test="corpId != null">corp_id = #{corpId},</if>
        </trim>
        where material_group_id = #{materialGroupId}
    </update>

    <delete id="deleteQwMaterialGroupByMaterialGroupId" parameterType="Long">
        delete from qw_material_group where material_group_id = #{materialGroupId}
    </delete>

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