<?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.BomanNewsMapper">
    
    <resultMap type="BomanNews" id="BomanNewsResult">
        <result property="newsId"    column="news_id"    />
        <result property="topicId"    column="topic_id"    />
        <result property="title"    column="title"    />
        <result property="source"    column="source"    />
        <result property="author"    column="author"    />
        <result property="fromUrl"    column="from_url"    />
        <result property="image"    column="image"    />
        <result property="keywords"    column="keywords"    />
        <result property="description"    column="description"    />
        <result property="type"    column="type"    />
        <result property="allowcomments"    column="allowcomments"    />
        <result property="status"    column="status"    />
        <result property="content"    column="content"    />
        <result property="userId"    column="user_id"    />
        <result property="readnumber"    column="readnumber"    />
        <result property="top"    column="top"    />
        <result property="orders"    column="orders"    />
        <result property="releaseTime"    column="release_time"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectBomanNewsVo">
        select news_id, topic_id, title, source, author, from_url, image, keywords, description, type, allowcomments, status, content, user_id, readnumber, top, orders, release_time, create_time, create_by, update_by, update_time from boman_news
    </sql>

    <select id="selectBomanNewsList" parameterType="BomanNews" resultMap="BomanNewsResult">
        <include refid="selectBomanNewsVo"/>
        <where>  
            <if test="topicId != null "> and topic_id = #{topicId}</if>
            <if test="title != null  and title != ''"> and title = #{title}</if>
            <if test="source != null  and source != ''"> and source = #{source}</if>
            <if test="author != null  and author != ''"> and author = #{author}</if>
            <if test="fromUrl != null  and fromUrl != ''"> and from_url = #{fromUrl}</if>
            <if test="image != null  and image != ''"> and image = #{image}</if>
            <if test="keywords != null  and keywords != ''"> and keywords = #{keywords}</if>
            <if test="description != null  and description != ''"> and description = #{description}</if>
            <if test="type != null "> and type = #{type}</if>
            <if test="allowcomments != null  and allowcomments != ''"> and allowcomments = #{allowcomments}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="content != null  and content != ''"> and content = #{content}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="readnumber != null "> and readnumber = #{readnumber}</if>
            <if test="top != null "> and top = #{top}</if>
            <if test="orders != null "> and orders = #{orders}</if>
            <if test="releaseTime != null "> and DATE_FORMAT(release_time,'%Y%m') = DATE_FORMAT(#{releaseTime},'%Y%m')</if>
        </where>
        order by create_time DESC
    </select>
    
    <select id="selectBomanNewsByNewsId" parameterType="Long" resultMap="BomanNewsResult">
        <include refid="selectBomanNewsVo"/>
        where news_id = #{newsId}
    </select>
        
    <insert id="insertBomanNews" parameterType="BomanNews" useGeneratedKeys="true" keyProperty="newsId">
        insert into boman_news
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="topicId != null">topic_id,</if>
            <if test="title != null">title,</if>
            <if test="source != null">source,</if>
            <if test="author != null">author,</if>
            <if test="fromUrl != null">from_url,</if>
            <if test="image != null">image,</if>
            <if test="keywords != null">keywords,</if>
            <if test="description != null">description,</if>
            <if test="type != null">type,</if>
            <if test="allowcomments != null">allowcomments,</if>
            <if test="status != null">status,</if>
            <if test="content != null">content,</if>
            <if test="userId != null">user_id,</if>
            <if test="readnumber != null">readnumber,</if>
            <if test="top != null">top,</if>
            <if test="orders != null">orders,</if>
            <if test="releaseTime != null">release_time,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="topicId != null">#{topicId},</if>
            <if test="title != null">#{title},</if>
            <if test="source != null">#{source},</if>
            <if test="author != null">#{author},</if>
            <if test="fromUrl != null">#{fromUrl},</if>
            <if test="image != null">#{image},</if>
            <if test="keywords != null">#{keywords},</if>
            <if test="description != null">#{description},</if>
            <if test="type != null">#{type},</if>
            <if test="allowcomments != null">#{allowcomments},</if>
            <if test="status != null">#{status},</if>
            <if test="content != null">#{content},</if>
            <if test="userId != null">#{userId},</if>
            <if test="readnumber != null">#{readnumber},</if>
            <if test="top != null">#{top},</if>
            <if test="orders != null">#{orders},</if>
            <if test="releaseTime != null">#{releaseTime},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateBomanNews" parameterType="BomanNews">
        update boman_news
        <trim prefix="SET" suffixOverrides=",">
            <if test="topicId != null">topic_id = #{topicId},</if>
            <if test="title != null">title = #{title},</if>
            <if test="source != null">source = #{source},</if>
            <if test="author != null">author = #{author},</if>
            <if test="fromUrl != null">from_url = #{fromUrl},</if>
            <if test="image != null">image = #{image},</if>
            <if test="keywords != null">keywords = #{keywords},</if>
            <if test="description != null">description = #{description},</if>
            <if test="type != null">type = #{type},</if>
            <if test="allowcomments != null">allowcomments = #{allowcomments},</if>
            <if test="status != null">status = #{status},</if>
            <if test="content != null">content = #{content},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="readnumber != null">readnumber = #{readnumber},</if>
            <if test="top != null">top = #{top},</if>
            <if test="orders != null">orders = #{orders},</if>
            <if test="releaseTime != null">release_time = #{releaseTime},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where news_id = #{newsId}
    </update>

    <delete id="deleteBomanNewsByNewsId" parameterType="Long">
        delete from boman_news where news_id = #{newsId}
    </delete>

    <delete id="deleteBomanNewsByNewsIds" parameterType="String">
        delete from boman_news where news_id in 
        <foreach item="newsId" collection="array" open="(" separator="," close=")">
            #{newsId}
        </foreach>
    </delete>
</mapper>