<?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.diaoyun.zion.chinafrica.dao.TbCfCouponUseDao">

    <resultMap type="com.diaoyun.zion.chinafrica.entity.TbCfCouponUseEntity" id="tbCfCouponUseMap">
        <result property="useId" column="use_id"/>
        <result property="userId" column="user_id"/>
        <result property="couponId" column="coupon_id"/>
        <result property="useTime" column="use_time"/>
    </resultMap>

	<select id="queryObject" resultType="com.diaoyun.zion.chinafrica.entity.TbCfCouponUseEntity">
		select
			`use_id`,
			`user_id`,
			`coupon_id`,
			`use_time`
		from tb_cf_coupon_use
		where use_id = #{id}
	</select>

	<select id="queryList" resultType="com.diaoyun.zion.chinafrica.entity.TbCfCouponUseEntity">
		select
    		`use_id`,
    		`user_id`,
    		`coupon_id`,
    		`use_time`
		from tb_cf_coupon_use
		WHERE 1=1
		<if test="name != null and name.trim() != ''">
			AND name LIKE concat('%',#{name},'%')
		</if>
        <choose>
            <when test="sidx != null and sidx.trim() != ''">
                order by ${sidx} ${order}
            </when>
			<otherwise>
                order by use_id desc
			</otherwise>
        </choose>
		<if test="offset != null and limit != null">
			limit #{offset}, #{limit}
		</if>
	</select>
	
 	<select id="queryTotal" resultType="int">
		select count(*) from tb_cf_coupon_use
		WHERE 1=1
        <if test="name != null and name.trim() != ''">
            AND name LIKE concat('%',#{name},'%')
        </if>
	</select>
	 
	<insert id="save" parameterType="com.diaoyun.zion.chinafrica.entity.TbCfCouponUseEntity">
		insert into tb_cf_coupon_use(
			`use_id`,
			`user_id`,
			`coupon_id`,
			`use_time`)
		values(
			#{useId},
			#{userId},
			#{couponId},
			#{useTime})
	</insert>
	 
	<update id="update" parameterType="com.diaoyun.zion.chinafrica.entity.TbCfCouponUseEntity">
		update tb_cf_coupon_use
		<set>
			<if test="userId != null">`user_id` = #{userId}, </if>
			<if test="couponId != null">`coupon_id` = #{couponId}, </if>
			<if test="useTime != null">`use_time` = #{useTime}</if>
		</set>
		where use_id = #{useId}
	</update>
	
	<delete id="delete">
		delete from tb_cf_coupon_use where use_id = #{value}
	</delete>
	
	<delete id="deleteBatch">
		delete from tb_cf_coupon_use where use_id in
		<foreach item="useId" collection="array" open="(" separator="," close=")">
			#{useId}
		</foreach>
	</delete>

</mapper>