<?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.PostCollectionsMapper">

    <resultMap type="PostCollections" id="PostCollectionsResult">
        <result property="id"    column="id"    />
        <result property="systemId"    column="system_id"    />
        <result property="issuerId"    column="issuer_id"    />
        <result property="name"    column="name"    />
        <result property="startTime"    column="start_time"    />
        <result property="endTime"    column="end_time"    />
        <result property="price"    column="price"    />
        <result property="status"    column="status"    />
        <result property="collectionsNumber"    column="collections_number"    />
        <result property="collectionsStory"    column="collections_story"    />
        <result property="image"    column="image"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
        <result property="delFlag"    column="del_flag"    />
    </resultMap>

    <sql id="selectPostCollectionsVo">
        select id, system_id, issuer_id, name, start_time, end_time,price, status, collections_number, collections_story, image, create_time, update_time, create_by, update_by, del_flag from post_collections
    </sql>

    <select id="selectPostCollectionsList" parameterType="PostCollections" resultMap="PostCollectionsResult">
        <include refid="selectPostCollectionsVo"/>
        <where>
            <if test="systemId != null "> and system_id = #{systemId}</if><!--条件套系id等于前端传过来的id-->
            and del_flag = '0'
        </where>
    </select>
    <!--查询藏品详细信息，查发行方名称字段-->
    <select id="selectPostCollectionsById" parameterType="Long" resultType="PostCollectionsVo">
        select  c.image , c.name , c.price , c.start_time, c.end_time ,c.collections_number,c.collections_story , i.Issuer_name issuerName
        from post_collections c
        left join issuer i
        on c.issuer_id = i.id
        where c.id = #{id} and c.del_flag = '0'
    </select>

    <insert id="insertPostCollections" parameterType="PostCollections" useGeneratedKeys="true" keyProperty="id">
        insert into post_collections
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="systemId != null">system_id,</if>
            <if test="issuerId != null">issuer_id,</if>
            <if test="name != null">name,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="price != null">price,</if>
            <if test="status != null">status,</if>
            <if test="collectionsNumber != null">collections_number,</if>
            <if test="collectionsStory != null">collections_story,</if>
            <if test="image != null">image,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="delFlag != null">del_flag,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="systemId != null">#{systemId},</if>
            <if test="issuerId != null">#{issuerId},</if>
            <if test="name != null">#{name},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="price != null">#{price},</if>
            <if test="status != null">#{status},</if>
            <if test="collectionsNumber != null">#{collectionsNumber},</if>
            <if test="collectionsStory != null">#{collectionsStory},</if>
            <if test="image != null">#{image},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="delFlag != null">#{delFlag},</if>
        </trim>
    </insert>

    <update id="updatePostCollections" parameterType="PostCollections">
        update post_collections
        <trim prefix="SET" suffixOverrides=",">
            <if test="systemId != null">system_id = #{systemId},</if>
            <if test="issuerId != null">issuer_id = #{issuerId},</if>
            <if test="name != null">name = #{name},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="price != null">#{price},</if>
            <if test="status != null">status = #{status},</if>
            <if test="collectionsNumber != null">collections_number = #{collectionsNumber},</if>
            <if test="collectionsStory != null">collections_story = #{collectionsStory},</if>
            <if test="image != null">image = #{image},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deletePostCollectionsById" parameterType="Long">
        UPDATE  post_collections SET del_flag = '1'  WHERE del_flag = '0' AND (id = #{id})
    </delete>

    <delete id="deletePostCollectionsByIds" parameterType="String">
        UPDATE post_collections SET del_flag = '1'  WHERE del_flag = '0' AND id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <!--根据藏品名称查询藏品数量-->
    <select id="selectPostCollectionsByName" parameterType="PostCollectionsVo" resultType="int">
        select COUNT(name) FROM post_collections where name =  #{name} and del_flag = '0'
    </select>
    <!--如果套系未上架，批量修改藏品状态status=‘4’-->
    <update id="updatePostCollectionsStatus"  parameterType="PostCollections">
        update post_collections set status = '4',update_time = #{updateTime}, update_by = #{updateBy} where system_id=#{systemId} and del_flag = '0'
    </update>
    <!--如果套系已上架，根据返回值批量修改藏品状态status-->
    <update id="updatePostCollectionsStatus1" parameterType="PostCollections">
        update post_collections set status = #{status},update_time = #{updateTime}, update_by = #{updateBy} where system_id=#{systemId} and id=#{id} and del_flag = '0'
    </update>
    <!--通过套系id 进行批量删除-->
    <delete id="deletePostCollectionsBySystemIds" parameterType="String">
        UPDATE post_collections SET del_flag = '1'  WHERE del_flag = '0' AND system_id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <update id="updatePostCollectionsBySysetmIdAndId"  parameterType="PostCollections">
        update post_collections set status = #{status},update_time = #{updateTime}, update_by = #{updateBy} where id=#{id} and system_id=#{systemId} and del_flag = '0'
    </update>
</mapper>