<?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="cn.pluss.platform.mapper.BestNewActivityMapper">

    <insert id="saveBestNewActivity" parameterType="cn.pluss.platform.entity.BestNewActivity">
        insert into tb_pluss_best_new_activity(title, content, updateTime, updateor, seq, status)
        VALUES (#{title}, #{content}, #{updateTime}, #{updateor}, #{seq}, #{status})
    </insert>

    <insert id="saveBestNewActivityBatch">
        insert into tb_pluss_best_new_activity(title,content,updateTime,updateor) VALUES
        <foreach collection="list" item="item" index="index" separator=",">
            (#{title},#{content},#{updateTime},#{updateor} )
        </foreach>
    </insert>

    <select id="queryBestNewActivity" parameterType="cn.pluss.platform.entity.BestNewActivity"
            resultType="cn.pluss.platform.entity.BestNewActivity">
        SELECT * from tb_pluss_best_new_activity
        <where>
            <if test="id!= null">
                and id = #{id}
            </if>
            <if test="title!= null">
                and title = #{title}
            </if>
            <if test="content!= null">
                and content = #{content}
            </if>
            <if test="updateTime!= null">
                and updateTime = #{updateTime}
            </if>
            <if test="updateor!= null">
                and updateor = #{updateor}
            </if>
            <if test="status!= null">
                and status = #{status}
            </if>
        </where>
    </select>

    <select id="queryBestNewActivityList" parameterType="cn.pluss.platform.entity.BestNewActivity"
            resultType="cn.pluss.platform.entity.BestNewActivity">
        SELECT * from tb_pluss_best_new_activity
        <where>
            <if test="id!= null">
                and id = #{id}
            </if>
            <if test="title!= null">
                and title = #{title}
            </if>
            <if test="content!= null">
                and content = #{content}
            </if>
            <if test="updateTime!= null">
                and updateTime = #{updateTime}
            </if>
            <if test="updateor!= null">
                and updateor = #{updateor}
            </if>
            <if test="status!= null">
                and status = #{status}
            </if>
        </where>
    </select>

    <update id="updateBestNewActivity" parameterType="cn.pluss.platform.entity.BestNewActivity">
        update tb_pluss_best_new_activity
        <set>
            <if test="title!= null">
                title = #{title},
            </if>
            <if test="content!= null">
                content = #{content},
            </if>
            <if test="seq!= null">
                seq = #{seq},
            </if>
            <if test="updateTime!= null">
                updateTime = #{updateTime},
            </if>
            <if test="updateor!= null">
                updateor = #{updateor},
            </if>
            <if test="status!= null">
                status = #{status}
            </if>
        </set>
        where id=#{id}
    </update>

    <delete id="deleteBestNewActivity" parameterType="cn.pluss.platform.entity.BestNewActivity">
        DELETE
        FROM tb_pluss_best_new_activity
        where id = #{id}
    </delete>

    <select id="queryBestNewActivityPage" parameterType="java.util.Map"
            resultType="cn.pluss.platform.entity.BestNewActivity">
        SELECT bna.*, IF(nrr.id IS NULL, 0, 1) readStatus from tb_pluss_best_new_activity bna
            LEFT JOIN tb_pluss_notice_read_record nrr ON nrr.noticeId = bna.id AND nrr.type=3
            <if test="userId != null">
                AND nrr.userId = #{userId}
            </if>
        <where>
            <if test="type != null">
                FIND_IN_SET(#{type}, bna.`type`)
            </if>
            <if test="id!= null">
                AND id = #{id}
            </if>
            <if test="seq!= null">
                AND seq = #{seq}
            </if>
            <if test="title!= null">
                AND title LIKE CONCAT("%",#{title},"%")
            </if>
            <if test="content!= null">
                AND content = #{content}
            </if>
            <if test="updateTime!= null">
                AND updateTime = #{updateTime}
            </if>
            <if test="updateor!= null">
                AND updateor = #{updateor}
            </if>
            <if test="status!= null">
                AND status = #{status}
            </if>
        </where>
        ORDER BY seq IS NULL, bna.updateTime DESC LIMIT #{pageSize} OFFSET #{offset}
    </select>

    <select id="queryBestNewActivityPageCount" parameterType="java.util.Map" resultType="java.lang.Integer">
        SELECT count(*) from tb_pluss_best_new_activity
        <where>
            <if test="type != null">
                FIND_IN_SET(#{type}, `type`)
            </if>
            <if test="id!= null">
                and id = #{id}
            </if>
            <if test="seq!= null">
                and seq = #{seq}
            </if>
            <if test="title!= null">
                and title LIKE CONCAT("%",#{title},"%")
            </if>
            <if test="content!= null">
                and content = #{content}
            </if>
            <if test="updateTime!= null">
                and updateTime = #{updateTime}
            </if>
            <if test="updateor!= null">
                and updateor = #{updateor}
            </if>
            <if test="status!= null">
                and status = #{status}
            </if>
        </where>
    </select>

</mapper>
