<?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.FsStoreProductGroupMapper">
    
    <resultMap type="FsStoreProductGroup" id="FsStoreProductGroupResult">
        <result property="groupId"    column="group_id"    />
        <result property="products"    column="products"    />
        <result property="barCode"    column="bar_code"    />
        <result property="groupName"    column="group_name"    />
    </resultMap>

    <sql id="selectFsStoreProductGroupVo">
        select group_id, products, bar_code, group_name from fs_store_product_group
    </sql>

    <select id="selectFsStoreProductGroupList" parameterType="FsStoreProductGroup" resultMap="FsStoreProductGroupResult">
        <include refid="selectFsStoreProductGroupVo"/>
        <where>  
            <if test="barCode != null  and barCode != ''"> and bar_code = #{barCode}</if>
            <if test="groupName != null  and groupName != ''"> and group_name like concat('%', #{groupName}, '%')</if>
        </where>
        order by group_id desc
    </select>
    
    <select id="selectFsStoreProductGroupById" parameterType="Long" resultMap="FsStoreProductGroupResult">
        <include refid="selectFsStoreProductGroupVo"/>
        where group_id = #{groupId}
    </select>
        
    <insert id="insertFsStoreProductGroup" parameterType="FsStoreProductGroup" useGeneratedKeys="true" keyProperty="groupId">
        insert into fs_store_product_group
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="products != null">products,</if>
            <if test="barCode != null">bar_code,</if>
            <if test="groupName != null">group_name,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="products != null">#{products},</if>
            <if test="barCode != null">#{barCode},</if>
            <if test="groupName != null">#{groupName},</if>
         </trim>
    </insert>

    <update id="updateFsStoreProductGroup" parameterType="FsStoreProductGroup">
        update fs_store_product_group
        <trim prefix="SET" suffixOverrides=",">
            <if test="products != null">products = #{products},</if>
            <if test="barCode != null">bar_code = #{barCode},</if>
            <if test="groupName != null">group_name = #{groupName},</if>
        </trim>
        where group_id = #{groupId}
    </update>

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

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