<?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.yijia.market.mapper.MarkertPlanMapper">
    
    <resultMap type="MarkertPlan" id="MarkertPlanResult">
        <result property="id"    column="id"    />
        <result property="grade"    column="grade"    />
        <result property="discountTerm"    column="discount_term"    />
        <result property="discountAmt"    column="discount_amt"    />
        <result property="gasoilDiscountAmt"    column="gasoil_discount_amt"    />
        <result property="dieseloilDiscountAmt"    column="dieseloil_discount_amt"    />
        <result property="vipDiscountyPlus"    column="vip_discounty_plus"    />
        <result property="couponPlus"    column="coupon_plus"    />
        <result property="discountPlanType"    column="discount_plan_type"    />
    </resultMap>

    <sql id="selectMarkertPlanVo">
        select id, grade, discount_term, discount_amt, gasoil_discount_amt, dieseloil_discount_amt, vip_discounty_plus, coupon_plus, discount_plan_type from markert_plan
    </sql>

    <select id="selectMarkertPlanList" parameterType="MarkertPlan" resultMap="MarkertPlanResult">
        <include refid="selectMarkertPlanVo"/>
        <where>  
            <if test="grade != null  and grade != ''"> and grade = #{grade}</if>
            <if test="discountTerm != null  and discountTerm != ''"> and discount_term = #{discountTerm}</if>
            <if test="discountAmt != null  and discountAmt != ''"> and discount_amt = #{discountAmt}</if>
            <if test="gasoilDiscountAmt != null  and gasoilDiscountAmt != ''"> and gasoil_discount_amt = #{gasoilDiscountAmt}</if>
            <if test="dieseloilDiscountAmt != null  and dieseloilDiscountAmt != ''"> and dieseloil_discount_amt = #{dieseloilDiscountAmt}</if>
            <if test="vipDiscountyPlus != null  and vipDiscountyPlus != ''"> and vip_discounty_plus = #{vipDiscountyPlus}</if>
            <if test="couponPlus != null  and couponPlus != ''"> and coupon_plus = #{couponPlus}</if>
            <if test="discountPlanType != null  and discountPlanType != ''"> and discount_plan_type = #{discountPlanType}</if>
        </where>
    </select>
    
    <select id="selectMarkertPlanById" parameterType="Long" resultMap="MarkertPlanResult">
        <include refid="selectMarkertPlanVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertMarkertPlan" parameterType="MarkertPlan" useGeneratedKeys="true" keyProperty="id">
        insert into markert_plan
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="grade != null">grade,</if>
            <if test="discountTerm != null">discount_term,</if>
            <if test="discountAmt != null">discount_amt,</if>
            <if test="gasoilDiscountAmt != null">gasoil_discount_amt,</if>
            <if test="dieseloilDiscountAmt != null">dieseloil_discount_amt,</if>
            <if test="vipDiscountyPlus != null">vip_discounty_plus,</if>
            <if test="couponPlus != null">coupon_plus,</if>
            <if test="discountPlanType != null">discount_plan_type,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="grade != null">#{grade},</if>
            <if test="discountTerm != null">#{discountTerm},</if>
            <if test="discountAmt != null">#{discountAmt},</if>
            <if test="gasoilDiscountAmt != null">#{gasoilDiscountAmt},</if>
            <if test="dieseloilDiscountAmt != null">#{dieseloilDiscountAmt},</if>
            <if test="vipDiscountyPlus != null">#{vipDiscountyPlus},</if>
            <if test="couponPlus != null">#{couponPlus},</if>
            <if test="discountPlanType != null">#{discountPlanType},</if>
         </trim>
    </insert>

    <update id="updateMarkertPlan" parameterType="MarkertPlan">
        update markert_plan
        <trim prefix="SET" suffixOverrides=",">
            <if test="grade != null">grade = #{grade},</if>
            <if test="discountTerm != null">discount_term = #{discountTerm},</if>
            <if test="discountAmt != null">discount_amt = #{discountAmt},</if>
            <if test="gasoilDiscountAmt != null">gasoil_discount_amt = #{gasoilDiscountAmt},</if>
            <if test="dieseloilDiscountAmt != null">dieseloil_discount_amt = #{dieseloilDiscountAmt},</if>
            <if test="vipDiscountyPlus != null">vip_discounty_plus = #{vipDiscountyPlus},</if>
            <if test="couponPlus != null">coupon_plus = #{couponPlus},</if>
            <if test="discountPlanType != null">discount_plan_type = #{discountPlanType},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteMarkertPlanById" parameterType="Long">
        delete from markert_plan where id = #{id}
    </delete>

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