<?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.post.mapper.PostCollectionMapper">

    <resultMap type="PostCollection" id="PostCollectionResult">
        <result property="collectionId" column="collection_id"/>
        <result property="collectionName" column="collection_name"/>
        <result property="collectionPrice" column="collection_price"/>
        <result property="collectionCounts" column="collection_counts"/>
        <result property="collectionStatus" column="collection_status"/>
        <result property="exchangeStatus" column="exchange_status"/>
        <result property="startTime" column="start_time"/>
        <result property="endTime" column="end_time"/>
        <result property="seriesName" column="series_name"/>
        <result property="delFlag" column="del_flag"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <sql id="selectPostCollectionVo">
        select collection_id,
               collection_name,
               collection_price,
               collection_counts,
               collection_status,
               exchange_status,
               start_time,
               end_time,
               series_name,
               del_flag
        from post_collection
        where del_flag = '0'
    </sql>
    <!--查询藏品列表-->
    <select id="selectPostCollectionList" parameterType="PostCollection" resultMap="PostCollectionResult">
        <include refid="selectPostCollectionVo"/>
        <where>
            <if test="collectionName != null  and collectionName != ''">and collection_name like concat('%',
                #{collectionName}, '%')
            </if>
            <if test="collectionPrice != null ">and collection_price = #{collectionPrice}</if>
            <if test="collectionCounts != null ">and collection_counts = #{collectionCounts}</if>
            <if test="collectionStatus != null  and collectionStatus != ''">and collection_status =
                #{collectionStatus}
            </if>
            <if test="exchangeStatus != null  and exchangeStatus != ''">and exchange_status = #{exchangeStatus}</if>
            <if test="startTime != null ">and start_time = #{startTime}</if>
            <if test="endTime != null ">and end_time = #{endTime}</if>
            <if test="seriesName != null  and seriesName != ''">and series_name like concat('%', #{seriesName}, '%')
            </if>
        </where>
    </select>
    <!--    ID查询藏品-->
    <select id="selectPostCollectionByCollectionId" parameterType="Long" resultMap="PostCollectionResult">
        <include refid="selectPostCollectionVo"/>
        and collection_id = #{collectionId}
    </select>
    <!--        添加藏品-->
    <insert id="insertPostCollection" parameterType="PostCollection" useGeneratedKeys="true" keyProperty="collectionId">
        insert into post_collection
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="collectionName != null and collectionName != ''">collection_name,</if>
            <if test="collectionPrice != null">collection_price,</if>
            <if test="collectionCounts != null">collection_counts,</if>
            <if test="collectionStatus != null and collectionStatus != ''">collection_status,</if>
            <if test="exchangeStatus != null and exchangeStatus != ''">exchange_status,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="seriesName != null">series_name,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="collectionName != null and collectionName != ''">#{collectionName},</if>
            <if test="collectionPrice != null">#{collectionPrice},</if>
            <if test="collectionCounts != null">#{collectionCounts},</if>
            <if test="collectionStatus != null and collectionStatus != ''">#{collectionStatus},</if>
            <if test="exchangeStatus != null and exchangeStatus != ''">#{exchangeStatus},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="seriesName != null">#{seriesName},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
        </trim>
    </insert>
    <!--修改藏品-->
    <update id="updatePostCollection" parameterType="PostCollection">
        update post_collection
        <trim prefix="SET" suffixOverrides=",">
            <if test="collectionName != null and collectionName != ''">collection_name = #{collectionName},</if>
            <if test="collectionPrice != null">collection_price = #{collectionPrice},</if>
            <if test="collectionCounts != null">collection_counts = #{collectionCounts},</if>
            <if test="collectionStatus != null and collectionStatus != ''">collection_status = #{collectionStatus},</if>
            <if test="exchangeStatus != null and exchangeStatus != ''">exchange_status = #{exchangeStatus},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="seriesName != null">series_name = #{seriesName},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where collection_id = #{collectionId}
    </update>
    <!--ID删除藏品-->
    <update id="deletePostCollectionByCollectionId" parameterType="Long">
        update
            post_collection
        set del_flag = '1'
        where collection_id = #{collectionId}
    </update>
    <!--批量删除-->
    <update id="deletePostCollectionByCollectionIds" parameterType="String">
        update post_collection set del_flag = '1' where collection_id in
        <foreach item="collectionId" collection="array" open="(" separator="," close=")">
            #{collectionId}
        </foreach>
    </update>
</mapper>