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

    <resultMap type="PostSeries" id="PostSeriesResult">
        <result property="seriesId" column="series_id"/>
        <result property="seriesName" column="series_name"/>
        <result property="collectionCounts" column="collection_counts"/>
        <result property="status" column="status"/>
        <result property="exchangeStatus" column="exchange_status"/>
        <result property="startTime" column="start_time"/>
        <result property="endTime" column="end_time"/>
        <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="selectPostSeriesVo">
        select series_id,
               series_name,
               collection_counts,
               status,
               exchange_status,
               start_time,
               end_time,
               del_flag
        from post_series
        where del_flag = '0'
    </sql>
    <!--查询套系列表-->
    <select id="selectPostSeriesList" parameterType="PostSeries" resultMap="PostSeriesResult">
        <include refid="selectPostSeriesVo"/>
        <where>
            <if test="seriesName != null  and seriesName != ''">and series_name like concat('%', #{seriesName}, '%')
            </if>
            <if test="collectionCounts != null ">and collection_counts = #{collectionCounts}</if>
            <if test="status != null  and status != ''">and status = #{status}</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>
        </where>
    </select>
    <!--套系ID查询-->
    <select id="selectPostSeriesBySeriesId" parameterType="Long" resultMap="PostSeriesResult">
        <include refid="selectPostSeriesVo"/>
        and series_id = #{seriesId}
    </select>
    <!--添加套系信息-->
    <insert id="insertPostSeries" parameterType="PostSeries" useGeneratedKeys="true" keyProperty="seriesId">
        insert into post_series
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="seriesName != null and seriesName != ''">series_name,</if>
            <if test="collectionCounts != null">collection_counts,</if>
            <if test="status != null and status != ''">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="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="seriesName != null and seriesName != ''">#{seriesName},</if>
            <if test="collectionCounts != null">#{collectionCounts},</if>
            <if test="status != null and status != ''">#{status},</if>
            <if test="exchangeStatus != null and exchangeStatus != ''">#{exchangeStatus},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</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="updatePostSeries" parameterType="PostSeries">
        update post_series
        <trim prefix="SET" suffixOverrides=",">
            <if test="seriesName != null and seriesName != ''">series_name = #{seriesName},</if>
            <if test="collectionCounts != null">collection_counts = #{collectionCounts},</if>
            <if test="status != null and status != ''">status = #{status},</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="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 series_id = #{seriesId}
    </update>
    <!--删除套系ID-->
    <update id="deletePostSeriesBySeriesId" parameterType="Long">
        update post_series
        set del_flag = '1'
        where series_id = #{seriesId}
    </update>
    <!--批量删除-->
    <update id="deletePostSeriesBySeriesIds" parameterType="String">
        update post_series set del_flag = '1' where series_id in
        <foreach item="seriesId" collection="array" open="(" separator="," close=")">
            #{seriesId}
        </foreach>
    </update>
</mapper>