<?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.CustomerCardSettingDetailMapper">

    <resultMap type="CustomerCardSettingDetail" id="CustomerCardSettingDetailResult">
        <result property="id"    column="id"    />
        <result property="parentId"    column="parent_id"    />
        <result property="settingRuleType"    column="setting_rule_type"    />
        <result property="discountAmtStart"    column="discount_amt_start"    />
        <result property="discountAmtEnd"    column="discount_amt_end"    />
        <result property="presentAmt"    column="present_amt"    />
        <result property="cardType"    column="card_type"    />
        <result property="status"    column="status"    />
        <result property="cardOilsType"    column="card_oils_type"    />
        <result property="discountTimeSetting"    column="discount_time_setting"    />
        <result property="discountTimeType"    column="discount_time_type"    />
        <result property="isDiscountCoupon"    column="is_discount_coupon"    />
        <result property="isGradeSetting"    column="is_grade_setting"    />
        <result property="isMarket"    column="is_market"/>
        <result property="presentScale"    column="present_scale"/>
        <result property="enjoyIntegralMultiple"    column="enjoy_integral_multiple"/>
        <result property="delFlag"    column="del_flag"/>
    </resultMap>

    <sql id="selectCustomerCardSettingDetailVo">
        select id, parent_id, setting_rule_type, discount_amt_start,discount_amt_end, present_amt,card_type,status,del_flag
         from customer_card_setting_detail
    </sql>

    <select id="selectCustomerCardSettingDetailList" parameterType="CustomerCardSettingDetail" resultMap="CustomerCardSettingDetailResult">
        <include refid="selectCustomerCardSettingDetailVo"/>
        <where>
            <if test="parentId != null "> and parent_id = #{parentId}</if>
            <if test="settingRuleType != null  and settingRuleType != ''"> and setting_rule_type = #{settingRuleType}</if>
            <if test="discountAmtStart != null "> and discount_amt_start = #{discountAmtStart}</if>
            <if test="discountAmtEnd != null "> and discount_amt_end = #{discountAmtEnd}</if>
            <if test="presentAmt != null "> and present_amt = #{presentAmt}</if>
            <if test="cardType != null "> and card_type = #{cardType}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="delFlag != null "> and del_flag = #{delFlag}</if>
            <if test="stationIdList != null ">
                and station_id in
                <foreach item="item" index="index" collection="stationIdList"
                         open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
        </where>
    </select>

    <select id="listDetailInfo" parameterType="CustomerCardSetting" resultMap="CustomerCardSettingDetailResult">
        SELECT a.setting_rule_type,a.discount_amt_start,a.discount_amt_end,a.present_amt,card_type,b.card_oils_type,
        b.discount_time_setting,b.discount_time_type,b.is_discount_coupon,b.is_market,b.is_grade_setting,b.present_scale,b.enjoy_integral_multiple
        from customer_card_setting_detail a join customer_card_setting b on a.parent_id= b.id
        <where>
<!--            <if test="parentId != null "> and parent_id = #{parentId}</if>-->
<!--            <if test="settingRuleType != null  and settingRuleType != ''"> and setting_rule_type = #{settingRuleType}</if>-->
<!--            <if test="discountAmtStart != null "> and discount_amt_start = #{discountAmtStart}</if>-->
<!--            <if test="discountAmtEnd != null "> and discount_amt_end = #{discountAmtEnd}</if>-->
<!--            <if test="presentAmt != null "> and present_amt = #{presentAmt}</if>-->
<!--            <if test="cardType != null "> and card_type = #{cardType}</if>-->
<!--            <if test="status != null "> and status = #{status}</if>-->
            <if test="delFlag != null "> and a.del_flag = #{delFlag}</if>
            <if test="stationIdList != null ">
                and station_id in
                <foreach item="item" index="index" collection="stationIdList"
                         open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
        </where>
    </select>

    <select id="selectCustomerCardSettingDetailById" parameterType="Long" resultMap="CustomerCardSettingDetailResult">
        <include refid="selectCustomerCardSettingDetailVo"/>
        where id = #{id}
    </select>

    <insert id="insertCustomerCardSettingDetail" parameterType="CustomerCardSettingDetail">
        insert into customer_card_setting_detail
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="parentId != null">parent_id,</if>
            <if test="settingRuleType != null">setting_rule_type,</if>
            <if test="discountAmtStart != null">discount_amt_start,</if>
            <if test="discountAmtEnd != null">discount_amt_end,</if>
            <if test="presentAmt != null">present_amt,</if>
            <if test="cardType != null">card_type,</if>
            <if test="status != null">status,</if>
            <if test="delFlag != null">del_flag,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="parentId != null">#{parentId},</if>
            <if test="settingRuleType != null">#{settingRuleType},</if>
            <if test="discountAmtStart != null">#{discountAmtStart},</if>
            <if test="discountAmtEnd != null">#{discountAmtEnd},</if>
            <if test="presentAmt != null">#{presentAmt},</if>
            <if test="cardType != null">#{cardType},</if>
            <if test="status != null">#{status},</if>
            <if test="delFlag != null">#{delFlag},</if>
         </trim>
    </insert>

    <update id="updateCustomerCardSettingDetail" parameterType="CustomerCardSettingDetail">
        update customer_card_setting_detail
        <trim prefix="SET" suffixOverrides=",">
            <if test="parentId != null">parent_id = #{parentId},</if>
            <if test="settingRuleType != null">setting_rule_type = #{settingRuleType},</if>
            <if test="discountAmtStart != null">discount_amt_start = #{discountAmtStart},</if>
            <if test="discountAmtEnd != null">discount_amt_end = #{discountAmtEnd},</if>
            <if test="presentAmt != null">present_amt = #{presentAmt},</if>
            <if test="cardType != null">card_type = #{cardType},</if>
            <if test="status != null">status = #{status},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="updateDetail" parameterType="CustomerCardSettingDetail">
        update customer_card_setting_detail set del_flag = #{delFlag}
        where parent_id = #{parentId}
    </update>

    <delete id="deleteCustomerCardSettingDetailById" parameterType="Long">
        delete from customer_card_setting_detail where id = #{id}
    </delete>

    <delete id="deleteCustomerCardSettingDetailByIds" parameterType="String">
        delete from customer_card_setting_detail where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <delete id="deleteCustomerCardSettingDetail" parameterType="CustomerCardSettingDetail">
        delete from customer_card_setting_detail
        <where>
            <if test="parentId != null "> and parent_id = #{parentId}</if>
            <if test="settingRuleType != null  and settingRuleType != ''"> and setting_rule_type = #{settingRuleType}</if>
            <if test="discountAmtStart != null "> and discount_amt_start = #{discountAmtStart}</if>
            <if test="discountAmtEnd != null "> and discount_amt_end = #{discountAmtEnd}</if>
            <if test="presentAmt != null "> and present_amt = #{presentAmt}</if>
            <if test="cardType != null"> and card_type = #{cardType}</if>
            <if test="status != null"> and status = #{status}</if>
        </where>
    </delete>
</mapper>
