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

    <resultMap type="CustomerCardSetting" id="CustomerCardSettingResult">
        <result property="id"    column="id"    />
        <result property="cardOilsType"    column="card_oils_type"    />
        <result property="discountTimeSetting"    column="discount_time_setting"    />
        <result property="discountTime"    column="discount_time"    />
        <result property="discountTimeType"    column="discount_time_type"    />
        <result property="presentScale"    column="present_scale"    />
        <result property="isDiscountCoupon"    column="is_discount_coupon"    />
        <result property="enjoyIntegralMultiple"    column="enjoy_integral_multiple"    />
        <result property="stationId"    column="station_id"    />
        <result property="stationName"    column="station_name"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="isGradeSetting"    column="is_grade_setting"    />
        <result property="isMarket"    column="is_market"    />
        <result property="cardEnabledFlag"    column="card_enabled_flag"    />
    </resultMap>

    <sql id="selectCustomerCardSettingVo">
        select id, card_oils_type, discount_time_setting, discount_time, present_scale, is_discount_coupon, enjoy_integral_multiple,
        station_id, d.dept_name as station_name, c.create_time,discount_time_type,is_market,is_grade_setting,card_enabled_flag
        from customer_card_setting c join sys_dept d on c.station_id = d.dept_id
    </sql>

    <select id="selectCustomerCardSettingList" parameterType="CustomerCardSetting" resultMap="CustomerCardSettingResult">
        <include refid="selectCustomerCardSettingVo"/>
        <where>
            <if test="cardOilsType != null  and cardOilsType != ''"> and card_oils_type = #{cardOilsType}</if>
            <if test="discountTimeSetting != null  and discountTimeSetting != ''"> and discount_time_setting = #{discountTimeSetting}</if>
            <if test="discountTime != null  and discountTime != ''"> and discount_time = #{discountTime}</if>
            <if test="discountTimeType != null  and discountTimeType != ''"> and discount_time_type = #{discountTimeType}</if>
            <if test="presentScale != null  and presentScale != ''"> and present_scale = #{presentScale}</if>
            <if test="isDiscountCoupon != null  and isDiscountCoupon != ''"> and is_discount_coupon = #{isDiscountCoupon}</if>
            <if test="enjoyIntegralMultiple != null  and enjoyIntegralMultiple != ''"> and enjoy_integral_multiple = #{enjoyIntegralMultiple}</if>
            <if test="isGradeSetting != null   and isGradeSetting != ''"> and is_grade_setting = #{isGradeSetting}</if>
            <if test="isMarket != null   and isMarket != ''"> and is_market = #{isMarket}</if>
            <if test="stationId != null "> and station_id = #{stationId}</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="selectCustomerCardSetting" parameterType="CustomerCardSetting" resultMap="CustomerCardSettingResult">
        <include refid="selectCustomerCardSettingVo"/>
        <where>
            <if test="cardOilsType != null  and cardOilsType != ''"> and card_oils_type = #{cardOilsType}</if>
            <if test="discountTimeSetting != null  and discountTimeSetting != ''"> and discount_time_setting = #{discountTimeSetting}</if>
            <if test="discountTime != null  and discountTime != ''"> and discount_time = #{discountTime}</if>
            <if test="discountTimeType != null  and discountTimeType != ''"> and discount_time_type = #{discountTimeType}</if>
            <if test="presentScale != null  and presentScale != ''"> and present_scale = #{presentScale}</if>
            <if test="isDiscountCoupon != null  and isDiscountCoupon != ''"> and is_discount_coupon = #{isDiscountCoupon}</if>
            <if test="enjoyIntegralMultiple != null  and enjoyIntegralMultiple != ''"> and enjoy_integral_multiple = #{enjoyIntegralMultiple}</if>
            <if test="stationId != null "> and station_id = #{stationId}</if>
            <if test="isGradeSetting != null   and isGradeSetting != ''"> and is_grade_setting = #{isGradeSetting}</if>
            <if test="isMarket != null   and isMarket != ''"> and is_market = #{isMarket}</if>
            <if test="stationIdList != null ">
                and station_id in
                <foreach item="item" index="index" collection="stationIdList"
                         open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
        </where>
         limit 0,1;
    </select>
    <select id="selectCustomerCardSettingById" parameterType="Long" resultMap="CustomerCardSettingResult">
        <include refid="selectCustomerCardSettingVo"/>
        where id = #{id}
    </select>

    <insert id="insertCustomerCardSetting" parameterType="CustomerCardSetting" useGeneratedKeys="true" keyProperty="id">
        insert into customer_card_setting
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="cardOilsType != null">card_oils_type,</if>
            <if test="discountTimeSetting != null">discount_time_setting,</if>
            <if test="discountTime != null">discount_time,</if>
            <if test="discountTimeType != null ">discount_time_type,</if>
            <if test="presentScale != null">present_scale,</if>
            <if test="isDiscountCoupon != null">is_discount_coupon,</if>
            <if test="enjoyIntegralMultiple != null">enjoy_integral_multiple,</if>
            <if test="stationId != null">station_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="isGradeSetting != null">is_grade_setting,</if>
            <if test="isMarket != null">is_market,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="cardOilsType != null">#{cardOilsType},</if>
            <if test="discountTimeSetting != null">#{discountTimeSetting},</if>
            <if test="discountTime != null">#{discountTime},</if>
            <if test="discountTimeType != null">#{discountTimeType},</if>
            <if test="presentScale != null">#{presentScale},</if>
            <if test="isDiscountCoupon != null">#{isDiscountCoupon},</if>
            <if test="enjoyIntegralMultiple != null">#{enjoyIntegralMultiple},</if>
            <if test="stationId != null">#{stationId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="isGradeSetting != null">#{isGradeSetting},</if>
            <if test="isMarket != null">#{isMarket},</if>
         </trim>
    </insert>

    <update id="updateCustomerCardSetting" parameterType="CustomerCardSetting">
        update customer_card_setting
        <trim prefix="SET" suffixOverrides=",">
            <if test="cardOilsType != null">card_oils_type = #{cardOilsType},</if>
            <if test="discountTimeSetting != null">discount_time_setting = #{discountTimeSetting},</if>
            <if test="discountTime != null">discount_time = #{discountTime},</if>
            <if test="discountTimeType != null"> discount_time_type = #{discountTimeType},</if>
            <if test="presentScale != null">present_scale = #{presentScale},</if>
            <if test="isDiscountCoupon != null">is_discount_coupon = #{isDiscountCoupon},</if>
            <if test="enjoyIntegralMultiple != null">enjoy_integral_multiple = #{enjoyIntegralMultiple},</if>
            <if test="stationId != null">station_id = #{stationId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="isMarket != null">is_market = #{isMarket},</if>
            <if test="isGradeSetting != null">is_grade_setting = #{isGradeSetting},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCustomerCardSettingById" parameterType="Long">
        delete from customer_card_setting where id = #{id}
    </delete>

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

</mapper>
