<?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.system.mapper.CouponUserMapper">
    
    <resultMap type="CouponUser" id="CouponUserResult">
        <result property="id"    column="id"    />
        <result property="uid"    column="uid"    />
        <result property="couponId"    column="coupon_id"    />
        <result property="couponTitle"    column="coupon_title"    />
        <result property="couponPrice"    column="coupon_price"    />
        <result property="minPrice"    column="min_price"    />
        <result property="addTime"    column="add_time"    />
        <result property="loseTime"    column="lose_time"    />
        <result property="useTime"    column="use_time"    />
        <result property="cateId"    column="cate_id"    />
        <result property="productId"    column="product_id"    />
        <result property="receiveType"    column="receive_type"    />
        <result property="status"    column="status"    />
        <result property="createdAt"    column="created_at"    />
        <result property="updatedAt"    column="updated_at"    />
    </resultMap>

    <sql id="selectCouponUserVo">
        select id, uid, coupon_id, coupon_title, coupon_price, min_price, add_time, lose_time, use_time, cate_id, product_id, receive_type, status, created_at, updated_at from coupon_user
    </sql>

    <select id="selectCountCouponUserbycouponId" parameterType="Long" resultType="Integer">
        select  count(0) from  coupon_user where  coupon_id=#{couponId}
    </select>



    <select id="selectCouponUserList" parameterType="CouponUser" resultMap="CouponUserResult">
        <include refid="selectCouponUserVo"/>
        <where>
            <if test="uid != null "> and uid = #{uid}</if>
            <if test="couponId != null "> and coupon_id = #{couponId}</if>
            <if test="couponTitle != null  and couponTitle != ''"> and coupon_title = #{couponTitle}</if>
            <if test="couponPrice != null "> and coupon_price = #{couponPrice}</if>
            <if test="minPrice != null "> and min_price = #{minPrice}</if>
            <if test="addTime != null "> and add_time = #{addTime}</if>
            <if test="loseTime != null  and loseTime != ''"> and lose_time = #{loseTime}</if>
            <if test="useTime != null "> and use_time = #{useTime}</if>
            <if test="cateId != null "> and cate_id = #{cateId}</if>
            <if test="productId != null "> and product_id = #{productId}</if>
            <if test="receiveType != null  and receiveType != ''"> and receive_type = #{receiveType}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="createdAt != null "> and created_at = #{createdAt}</if>
            <if test="updatedAt != null "> and updated_at = #{updatedAt}</if>
        </where>
    </select>


    <select id="selectCouponUserById" parameterType="Long" resultMap="CouponUserResult">
        <include refid="selectCouponUserVo"/>
        where id = #{id}
    </select>

    <insert id="insertCouponUser" parameterType="CouponUser" useGeneratedKeys="true" keyProperty="id">
        insert into coupon_user
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="uid != null">uid,</if>
            <if test="couponId != null">coupon_id,</if>
            <if test="couponTitle != null and couponTitle != ''">coupon_title,</if>
            <if test="couponPrice != null">coupon_price,</if>
            <if test="minPrice != null">min_price,</if>
            <if test="addTime != null">add_time,</if>
            <if test="loseTime != null">lose_time,</if>
            <if test="useTime != null">use_time,</if>
            <if test="cateId != null">cate_id,</if>
            <if test="productId != null">product_id,</if>
            <if test="receiveType != null and receiveType != ''">receive_type,</if>
            <if test="status != null">status,</if>
            <if test="createdAt != null">created_at,</if>
            <if test="updatedAt != null">updated_at,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="uid != null">#{uid},</if>
            <if test="couponId != null">#{couponId},</if>
            <if test="couponTitle != null and couponTitle != ''">#{couponTitle},</if>
            <if test="couponPrice != null">#{couponPrice},</if>
            <if test="minPrice != null">#{minPrice},</if>
            <if test="addTime != null">#{addTime},</if>
            <if test="loseTime != null">#{loseTime},</if>
            <if test="useTime != null">#{useTime},</if>
            <if test="cateId != null">#{cateId},</if>
            <if test="productId != null">#{productId},</if>
            <if test="receiveType != null and receiveType != ''">#{receiveType},</if>
            <if test="status != null">#{status},</if>
            <if test="createdAt != null">#{createdAt},</if>
            <if test="updatedAt != null">#{updatedAt},</if>
         </trim>
    </insert>

    <update id="updateCouponUser" parameterType="CouponUser">
        update coupon_user
        <trim prefix="SET" suffixOverrides=",">
            <if test="uid != null">uid = #{uid},</if>
            <if test="couponId != null">coupon_id = #{couponId},</if>
            <if test="couponTitle != null and couponTitle != ''">coupon_title = #{couponTitle},</if>
            <if test="couponPrice != null">coupon_price = #{couponPrice},</if>
            <if test="minPrice != null">min_price = #{minPrice},</if>
            <if test="addTime != null">add_time = #{addTime},</if>
            <if test="loseTime != null">lose_time = #{loseTime},</if>
            <if test="useTime != null">use_time = #{useTime},</if>
            <if test="cateId != null">cate_id = #{cateId},</if>
            <if test="productId != null">product_id = #{productId},</if>
            <if test="receiveType != null and receiveType != ''">receive_type = #{receiveType},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createdAt != null">created_at = #{createdAt},</if>
            <if test="updatedAt != null">updated_at = #{updatedAt},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCouponUserById" parameterType="Long">
        delete from coupon_user where id = #{id}
    </delete>

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