<?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.ruoyi.abuwx.mapper.CardCouponsMapper">
    
    <resultMap type="CardCoupons" id="CardCouponsResult">
        <result property="id"    column="id"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
        <result property="remark"    column="remark"    />
        <result property="title"    column="title"    />
        <result property="type"    column="type"    />
        <result property="description"    column="description"    />
        <result property="quota"    column="quota"    />
        <result property="pic"    column="pic"    />
        <result property="status"    column="status"    />
        <result property="couponNumber"    column="coupon_number"    />
    </resultMap>

    <sql id="selectCardCouponsVo">
        select id, create_time, update_time, create_by, update_by, remark, title, type, description, quota, pic, status, coupon_number from card_coupons
    </sql>

    <select id="selectCardCouponsList" parameterType="CardCoupons" resultMap="CardCouponsResult">
        <include refid="selectCardCouponsVo"/>
        <where>  
            <if test="title != null  and title != ''"> and title = #{title}</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="description != null  and description != ''"> and description = #{description}</if>
            <if test="quota != null  and quota != ''"> and quota = #{quota}</if>
            <if test="pic != null  and pic != ''"> and pic = #{pic}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="couponNumber != null  and couponNumber != ''"> and coupon_number = #{couponNumber}</if>
        </where>
    </select>
    
    <select id="selectCardCouponsById" parameterType="Long" resultMap="CardCouponsResult">
        <include refid="selectCardCouponsVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertCardCoupons" parameterType="CardCoupons" useGeneratedKeys="true" keyProperty="id">
        insert into card_coupons
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="remark != null">remark,</if>
            <if test="title != null">title,</if>
            <if test="type != null">type,</if>
            <if test="description != null">description,</if>
            <if test="quota != null">quota,</if>
            <if test="pic != null">pic,</if>
            <if test="status != null">status,</if>
            <if test="couponNumber != null">coupon_number,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="remark != null">#{remark},</if>
            <if test="title != null">#{title},</if>
            <if test="type != null">#{type},</if>
            <if test="description != null">#{description},</if>
            <if test="quota != null">#{quota},</if>
            <if test="pic != null">#{pic},</if>
            <if test="status != null">#{status},</if>
            <if test="couponNumber != null">#{couponNumber},</if>
         </trim>
    </insert>

    <update id="updateCardCoupons" parameterType="CardCoupons">
        update card_coupons
        <trim prefix="SET" suffixOverrides=",">
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="title != null">title = #{title},</if>
            <if test="type != null">type = #{type},</if>
            <if test="description != null">description = #{description},</if>
            <if test="quota != null">quota = #{quota},</if>
            <if test="pic != null">pic = #{pic},</if>
            <if test="status != null">status = #{status},</if>
            <if test="couponNumber != null">coupon_number = #{couponNumber},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCardCouponsById" parameterType="Long">
        delete from card_coupons where id = #{id}
    </delete>

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