<?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.yice.webadmin.app.dao.PromptTemplateCollectMapper">
    <resultMap id="BaseResultMap" type="com.yice.webadmin.app.model.PromptTemplateCollect">
        <id column="collect_id" jdbcType="BIGINT" property="collectId"/>
        <result column="template_id" jdbcType="BIGINT" property="templateId"/>
        <result column="user_id" jdbcType="BIGINT" property="userId"/>
        <result column="collect_time" jdbcType="TIMESTAMP" property="collectTime"/>
    </resultMap>

    <insert id="insertList">
        INSERT INTO lmp_prompt_template_collect
        (collect_id,
        template_id,
        user_id,
        collect_time)
        VALUES
        <foreach collection="list" index="index" item="item" separator=",">
            (#{item.collectId},
            #{item.templateId},
            #{item.userId},
            #{item.collectTime})
        </foreach>
    </insert>

    <!-- 如果有逻辑删除字段过滤，请写到这里 -->
    <sql id="filterRef">
        <!-- 这里必须加上全包名，否则当filterRef被其他Mapper.xml包含引用的时候，就会调用Mapper.xml中的该SQL片段 -->
        <include refid="com.yice.webadmin.app.dao.PromptTemplateCollectMapper.inputFilterRef"/>
    </sql>

    <!-- 这里仅包含调用接口输入的主表过滤条件 -->
    <sql id="inputFilterRef">
        <if test="promptTemplateCollectFilter != null">
            <if test="promptTemplateCollectFilter.userId != null">
                AND lmp_prompt_template_collect.user_id = #{promptTemplateCollectFilter.userId}
            </if>
        </if>
    </sql>

    <select id="getPromptTemplateCollectList" resultMap="BaseResultMap"
            parameterType="com.yice.webadmin.app.model.PromptTemplateCollect">
        SELECT * FROM lmp_prompt_template_collect
        <where>
            <include refid="filterRef"/>
        </where>
        <if test="orderBy != null and orderBy != ''">
            ORDER BY ${orderBy}
        </if>
    </select>
</mapper>
