<?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.customer.mapper.CustomerGradeSettingMapper">
    
    <resultMap type="CustomerGradeSetting" id="CustomerGradeSettingResult">
        <result property="id"    column="id"    />
        <result property="grade"    column="grade"    />
        <result property="discountWay"    column="discount_way"    />
        <result property="gasoilDiscountLitre"    column="gasoil_discount_litre"    />
        <result property="dieseloilDiscountLitre"    column="dieseloil_discount_litre"    />
        <result property="gradeType"    column="grade_type"    />
        <result property="gasoilConsume"    column="gasoil_consume"    />
        <result property="gasoilGrowthValue"    column="gasoil_growth_value"    />
        <result property="dieseloilConsume"    column="dieseloil_consume"    />
        <result property="dieseloilGrowthValue"    column="dieseloil_growth_value"    />
        <result property="memberRecharge"    column="member_recharge"    />
        <result property="memberGrowthValue"    column="member_growth_value"    />
        <result property="growthValue"    column="growth_value"    />
        <result property="date"    column="date"    />
        <result property="deductionGrowthValue"    column="deduction_growth_value"    />
        <result property="memberCondit"    column="member_condit"    />
    </resultMap>

    <sql id="selectCustomerGradeSettingVo">
        select id, grade, discount_way, gasoil_discount_litre, dieseloil_discount_litre, grade_type, gasoil_consume, gasoil_growth_value, dieseloil_consume, dieseloil_growth_value, member_recharge, member_growth_value, growth_value, date, deduction_growth_value, member_condit from customer_grade_setting
    </sql>

    <select id="selectCustomerGradeSettingList" parameterType="CustomerGradeSetting" resultMap="CustomerGradeSettingResult">
        <include refid="selectCustomerGradeSettingVo"/>
        <where>  
            <if test="grade != null  and grade != ''"> and grade = #{grade}</if>
            <if test="discountWay != null  and discountWay != ''"> and discount_way = #{discountWay}</if>
            <if test="gasoilDiscountLitre != null  and gasoilDiscountLitre != ''"> and gasoil_discount_litre = #{gasoilDiscountLitre}</if>
            <if test="dieseloilDiscountLitre != null  and dieseloilDiscountLitre != ''"> and dieseloil_discount_litre = #{dieseloilDiscountLitre}</if>
            <if test="gradeType != null  and gradeType != ''"> and grade_type = #{gradeType}</if>
            <if test="gasoilConsume != null  and gasoilConsume != ''"> and gasoil_consume = #{gasoilConsume}</if>
            <if test="gasoilGrowthValue != null  and gasoilGrowthValue != ''"> and gasoil_growth_value = #{gasoilGrowthValue}</if>
            <if test="dieseloilConsume != null  and dieseloilConsume != ''"> and dieseloil_consume = #{dieseloilConsume}</if>
            <if test="dieseloilGrowthValue != null  and dieseloilGrowthValue != ''"> and dieseloil_growth_value = #{dieseloilGrowthValue}</if>
            <if test="memberRecharge != null  and memberRecharge != ''"> and member_recharge = #{memberRecharge}</if>
            <if test="memberGrowthValue != null  and memberGrowthValue != ''"> and member_growth_value = #{memberGrowthValue}</if>
            <if test="growthValue != null  and growthValue != ''"> and growth_value = #{growthValue}</if>
            <if test="date != null "> and date = #{date}</if>
            <if test="deductionGrowthValue != null  and deductionGrowthValue != ''"> and deduction_growth_value = #{deductionGrowthValue}</if>
            <if test="memberCondit != null  and memberCondit != ''"> and member_condit = #{memberCondit}</if>
        </where>
    </select>
    
    <select id="selectCustomerGradeSettingById" parameterType="Long" resultMap="CustomerGradeSettingResult">
        <include refid="selectCustomerGradeSettingVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertCustomerGradeSetting" parameterType="CustomerGradeSetting" useGeneratedKeys="true" keyProperty="id">
        insert into customer_grade_setting
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="grade != null">grade,</if>
            <if test="discountWay != null">discount_way,</if>
            <if test="gasoilDiscountLitre != null">gasoil_discount_litre,</if>
            <if test="dieseloilDiscountLitre != null">dieseloil_discount_litre,</if>
            <if test="gradeType != null">grade_type,</if>
            <if test="gasoilConsume != null">gasoil_consume,</if>
            <if test="gasoilGrowthValue != null">gasoil_growth_value,</if>
            <if test="dieseloilConsume != null">dieseloil_consume,</if>
            <if test="dieseloilGrowthValue != null">dieseloil_growth_value,</if>
            <if test="memberRecharge != null">member_recharge,</if>
            <if test="memberGrowthValue != null">member_growth_value,</if>
            <if test="growthValue != null">growth_value,</if>
            <if test="date != null">date,</if>
            <if test="deductionGrowthValue != null">deduction_growth_value,</if>
            <if test="memberCondit != null">member_condit,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="grade != null">#{grade},</if>
            <if test="discountWay != null">#{discountWay},</if>
            <if test="gasoilDiscountLitre != null">#{gasoilDiscountLitre},</if>
            <if test="dieseloilDiscountLitre != null">#{dieseloilDiscountLitre},</if>
            <if test="gradeType != null">#{gradeType},</if>
            <if test="gasoilConsume != null">#{gasoilConsume},</if>
            <if test="gasoilGrowthValue != null">#{gasoilGrowthValue},</if>
            <if test="dieseloilConsume != null">#{dieseloilConsume},</if>
            <if test="dieseloilGrowthValue != null">#{dieseloilGrowthValue},</if>
            <if test="memberRecharge != null">#{memberRecharge},</if>
            <if test="memberGrowthValue != null">#{memberGrowthValue},</if>
            <if test="growthValue != null">#{growthValue},</if>
            <if test="date != null">#{date},</if>
            <if test="deductionGrowthValue != null">#{deductionGrowthValue},</if>
            <if test="memberCondit != null">#{memberCondit},</if>
         </trim>
    </insert>

    <update id="updateCustomerGradeSetting" parameterType="CustomerGradeSetting">
        update customer_grade_setting
        <trim prefix="SET" suffixOverrides=",">
            <if test="grade != null">grade = #{grade},</if>
            <if test="discountWay != null">discount_way = #{discountWay},</if>
            <if test="gasoilDiscountLitre != null">gasoil_discount_litre = #{gasoilDiscountLitre},</if>
            <if test="dieseloilDiscountLitre != null">dieseloil_discount_litre = #{dieseloilDiscountLitre},</if>
            <if test="gradeType != null">grade_type = #{gradeType},</if>
            <if test="gasoilConsume != null">gasoil_consume = #{gasoilConsume},</if>
            <if test="gasoilGrowthValue != null">gasoil_growth_value = #{gasoilGrowthValue},</if>
            <if test="dieseloilConsume != null">dieseloil_consume = #{dieseloilConsume},</if>
            <if test="dieseloilGrowthValue != null">dieseloil_growth_value = #{dieseloilGrowthValue},</if>
            <if test="memberRecharge != null">member_recharge = #{memberRecharge},</if>
            <if test="memberGrowthValue != null">member_growth_value = #{memberGrowthValue},</if>
            <if test="growthValue != null">growth_value = #{growthValue},</if>
            <if test="date != null">date = #{date},</if>
            <if test="deductionGrowthValue != null">deduction_growth_value = #{deductionGrowthValue},</if>
            <if test="memberCondit != null">member_condit = #{memberCondit},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCustomerGradeSettingById" parameterType="Long">
        delete from customer_grade_setting where id = #{id}
    </delete>

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