<?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.liquidnet.service.goblin.mapper.GoblinNftExActivityMapper">

    <resultMap id="BaseResult" type="com.liquidnet.service.goblin.entity.GoblinNftExActivity">
        <result column="activity_id" property="activityId" jdbcType="VARCHAR"/>
        <result column="uid" property="uid" jdbcType="VARCHAR"/>
        <result column="title" property="title" jdbcType="VARCHAR"/>
        <result column="created_at" property="createdAt" jdbcType="TIMESTAMP"/>
        <result column="updated_at" property="updatedAt" jdbcType="TIMESTAMP"/>
    </resultMap>

    <select id="selectByTitle" resultMap="BaseResult">
        select activity_id, uid, title, created_at
        from goblin_nft_ex_activity
        where title = #{title} and uid = #{uid}
    </select>

    <select id="selectPageList" resultMap="BaseResult">
        select activity_id,uid,title,created_at from goblin_nft_ex_activity
        <where>
            <if test="uid != null and uid != ''">
                and uid = #{uid,jdbcType=VARCHAR}
            </if>
            <if test="title != null and title != ''">
                <bind name="likeTitle" value="'%' + title + '%'"/>
                and title like #{likeTitle}
            </if>
            <if test="startTime != null">
                and created_at &gt; #{startTime,jdbcType=TIMESTAMP}
            </if>
            <if test="endTime != null">
                and created_at &lt; #{endTime,jdbcType=TIMESTAMP}
            </if>
        </where>
        order by created_at desc
    </select>

    <select id="selectByActivityId" resultMap="BaseResult">
        select activity_id, title, created_at
        from goblin_nft_ex_activity
        where activity_id = #{activityId,jdbcType=VARCHAR}
    </select>

    <select id="selectActivityCount" resultType="java.lang.Integer">
        select count(0)
        from goblin_nft_ex_activity
        <where>
            <if test="uid != null and uid != ''">
                and uid = #{uid,jdbcType=VARCHAR}
            </if>
            <if test="title != null and title != ''">
                <bind name="likeTitle" value="'%' + title + '%'"/>
                and title like #{likeTitle}
            </if>
            <if test="startTime != null">
                and created_at &gt; #{startTime,jdbcType=TIMESTAMP}
            </if>
            <if test="endTime != null">
                and created_at &lt; #{endTime,jdbcType=TIMESTAMP}
            </if>
        </where>
    </select>

    <insert id="addGoblinNftExActivity" parameterType="com.liquidnet.service.goblin.entity.GoblinNftExActivity">
        insert into goblin_nft_ex_activity
        (
        <if test="activityId != null and activityId != null">
            activity_id,
        </if>
        <if test="uid != null and uid != ''">
            uid,
        </if>
        <if test="title != null and title != ''">
            title,
        </if>
        <if test="createdAt != null">
            created_at
        </if>
        ) values(
        <if test="activityId != null and activityId != null">
            #{activityId,jdbcType=VARCHAR},
        </if>
        <if test="uid != null and uid != ''">
            #{uid,jdbcType=VARCHAR},
        </if>
        <if test="title != null and title != ''">
            #{title,jdbcType=VARCHAR},
        </if>
        <if test="createdAt != null">
            #{createdAt,jdbcType=TIMESTAMP}
        </if>
        )
    </insert>
</mapper>
