<?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.FsStoreProductRuleMapper">
    
    <resultMap type="FsStoreProductRule" id="FsStoreProductRuleResult">
        <result property="id"    column="id"    />
        <result property="ruleName"    column="rule_name"    />
        <result property="ruleValue"    column="rule_value"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="isDel"    column="is_del"    />
    </resultMap>

    <sql id="selectFsStoreProductRuleVo">
        select id, rule_name, rule_value, create_time, update_time, is_del from fs_store_product_rule
    </sql>

    <select id="selectFsStoreProductRuleList" parameterType="FsStoreProductRule" resultMap="FsStoreProductRuleResult">
        <include refid="selectFsStoreProductRuleVo"/>
        <where>  
            <if test="ruleName != null  and ruleName != ''"> and rule_name like concat('%', #{ruleName}, '%')</if>
            <if test="ruleValue != null  and ruleValue != ''"> and rule_value = #{ruleValue}</if>
            <if test="isDel != null "> and is_del = #{isDel}</if>
        </where>
    </select>
    
    <select id="selectFsStoreProductRuleById" parameterType="Integer" resultMap="FsStoreProductRuleResult">
        <include refid="selectFsStoreProductRuleVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertFsStoreProductRule" parameterType="FsStoreProductRule" useGeneratedKeys="true" keyProperty="id">
        insert into fs_store_product_rule
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="ruleName != null and ruleName != ''">rule_name,</if>
            <if test="ruleValue != null">rule_value,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="isDel != null">is_del,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="ruleName != null and ruleName != ''">#{ruleName},</if>
            <if test="ruleValue != null">#{ruleValue},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="isDel != null">#{isDel},</if>
         </trim>
    </insert>

    <update id="updateFsStoreProductRule" parameterType="FsStoreProductRule">
        update fs_store_product_rule
        <trim prefix="SET" suffixOverrides=",">
            <if test="ruleName != null and ruleName != ''">rule_name = #{ruleName},</if>
            <if test="ruleValue != null">rule_value = #{ruleValue},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="deleteFsStoreProductRuleById" parameterType="Integer">
        update fs_store_product_rule set is_del=1 where id = #{id}
    </update>

    <update id="deleteFsStoreProductRuleByIds" parameterType="String">
        update fs_store_product_rule set is_del=1 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
    
</mapper>